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); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 209 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 210 | void |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 211 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 212 | { |
| 213 | instance->instancet->fire_cmd(instance, |
| 214 | cmd->frame_phys_addr, 0, instance->reg_set); |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 215 | return; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 216 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 217 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 218 | /** |
| 219 | * megasas_get_cmd - Get a command from the free pool |
| 220 | * @instance: Adapter soft state |
| 221 | * |
| 222 | * Returns a free command from the pool |
| 223 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 224 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 225 | *instance) |
| 226 | { |
| 227 | unsigned long flags; |
| 228 | struct megasas_cmd *cmd = NULL; |
| 229 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 230 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 231 | |
| 232 | if (!list_empty(&instance->cmd_pool)) { |
| 233 | cmd = list_entry((&instance->cmd_pool)->next, |
| 234 | struct megasas_cmd, list); |
| 235 | list_del_init(&cmd->list); |
| 236 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 237 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 238 | } |
| 239 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 240 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 241 | return cmd; |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * megasas_return_cmd - Return a cmd to free command pool |
| 246 | * @instance: Adapter soft state |
| 247 | * @cmd: Command packet to be returned to free command pool |
| 248 | */ |
Andi Kleen | 68b4374 | 2017-05-08 15:58:53 -0700 | [diff] [blame] | 249 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 250 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 251 | { |
| 252 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 253 | u32 blk_tags; |
| 254 | struct megasas_cmd_fusion *cmd_fusion; |
| 255 | struct fusion_context *fusion = instance->ctrl_context; |
| 256 | |
| 257 | /* This flag is used only for fusion adapter. |
| 258 | * Wait for Interrupt for Polled mode DCMD |
| 259 | */ |
| 260 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 261 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 262 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 263 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 264 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 265 | if (fusion) { |
| 266 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 267 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 268 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 269 | } |
| 270 | cmd->scmd = NULL; |
| 271 | cmd->frame_count = 0; |
| 272 | cmd->flags = 0; |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 273 | memset(cmd->frame, 0, instance->mfi_frame_size); |
| 274 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 275 | if (!fusion && reset_devices) |
| 276 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 277 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 278 | |
| 279 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 280 | |
| 281 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 282 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 283 | static const char * |
| 284 | format_timestamp(uint32_t timestamp) |
| 285 | { |
| 286 | static char buffer[32]; |
| 287 | |
| 288 | if ((timestamp & 0xff000000) == 0xff000000) |
| 289 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 290 | 0x00ffffff); |
| 291 | else |
| 292 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 293 | return buffer; |
| 294 | } |
| 295 | |
| 296 | static const char * |
| 297 | format_class(int8_t class) |
| 298 | { |
| 299 | static char buffer[6]; |
| 300 | |
| 301 | switch (class) { |
| 302 | case MFI_EVT_CLASS_DEBUG: |
| 303 | return "debug"; |
| 304 | case MFI_EVT_CLASS_PROGRESS: |
| 305 | return "progress"; |
| 306 | case MFI_EVT_CLASS_INFO: |
| 307 | return "info"; |
| 308 | case MFI_EVT_CLASS_WARNING: |
| 309 | return "WARN"; |
| 310 | case MFI_EVT_CLASS_CRITICAL: |
| 311 | return "CRIT"; |
| 312 | case MFI_EVT_CLASS_FATAL: |
| 313 | return "FATAL"; |
| 314 | case MFI_EVT_CLASS_DEAD: |
| 315 | return "DEAD"; |
| 316 | default: |
| 317 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 318 | return buffer; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 324 | * for information. |
| 325 | * @instance: Adapter soft state |
| 326 | */ |
| 327 | static void |
| 328 | megasas_decode_evt(struct megasas_instance *instance) |
| 329 | { |
| 330 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 331 | union megasas_evt_class_locale class_locale; |
| 332 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 333 | |
| 334 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 335 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 336 | le32_to_cpu(evt_detail->seq_num), |
| 337 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 338 | (class_locale.members.locale), |
| 339 | format_class(class_locale.members.class), |
| 340 | evt_detail->description); |
| 341 | } |
| 342 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 343 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 344 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 345 | * (deviceid : 1064R, PERC5) controllers |
| 346 | */ |
| 347 | |
| 348 | /** |
| 349 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 350 | * @regs: MFI register set |
| 351 | */ |
| 352 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 353 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 354 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 355 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 356 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 357 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 358 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 359 | |
| 360 | /* Dummy readl to force pci flush */ |
| 361 | readl(®s->outbound_intr_mask); |
| 362 | } |
| 363 | |
| 364 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 365 | * megasas_disable_intr_xscale -Disables interrupt |
| 366 | * @regs: MFI register set |
| 367 | */ |
| 368 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 369 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 370 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 371 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 372 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 373 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 374 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 375 | writel(mask, ®s->outbound_intr_mask); |
| 376 | /* Dummy readl to force pci flush */ |
| 377 | readl(®s->outbound_intr_mask); |
| 378 | } |
| 379 | |
| 380 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 381 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 382 | * @regs: MFI register set |
| 383 | */ |
| 384 | static u32 |
| 385 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) |
| 386 | { |
| 387 | return readl(&(regs)->outbound_msg_0); |
| 388 | } |
| 389 | /** |
| 390 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 391 | * @regs: MFI register set |
| 392 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 393 | static int |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 394 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) |
| 395 | { |
| 396 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 397 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 398 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 399 | /* |
| 400 | * Check if it is our interrupt |
| 401 | */ |
| 402 | status = readl(®s->outbound_intr_status); |
| 403 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 404 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 405 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 406 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 407 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 408 | |
| 409 | /* |
| 410 | * Clear the interrupt by writing back the same value |
| 411 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 412 | if (mfiStatus) |
| 413 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 414 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 415 | /* Dummy readl to force pci flush */ |
| 416 | readl(®s->outbound_intr_status); |
| 417 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 418 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | /** |
| 422 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 423 | * @frame_phys_addr : Physical address of cmd |
| 424 | * @frame_count : Number of frames for the command |
| 425 | * @regs : MFI register set |
| 426 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 427 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 428 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 429 | dma_addr_t frame_phys_addr, |
| 430 | u32 frame_count, |
| 431 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 432 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 433 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 434 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 435 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 436 | writel((frame_phys_addr >> 3)|(frame_count), |
| 437 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 438 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * megasas_adp_reset_xscale - For controller reset |
| 443 | * @regs: MFI register set |
| 444 | */ |
| 445 | static int |
| 446 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 447 | struct megasas_register_set __iomem *regs) |
| 448 | { |
| 449 | u32 i; |
| 450 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 451 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 452 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 453 | |
| 454 | for (i = 0; i < 3; i++) |
| 455 | msleep(1000); /* sleep for 3 secs */ |
| 456 | pcidata = 0; |
| 457 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 458 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 459 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 460 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 461 | pcidata &= ~0x2; |
| 462 | pci_write_config_dword(instance->pdev, |
| 463 | MFI_1068_PCSR_OFFSET, pcidata); |
| 464 | |
| 465 | for (i = 0; i < 2; i++) |
| 466 | msleep(1000); /* need to wait 2 secs again */ |
| 467 | |
| 468 | pcidata = 0; |
| 469 | pci_read_config_dword(instance->pdev, |
| 470 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 471 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 472 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 473 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 474 | pcidata = 0; |
| 475 | pci_write_config_dword(instance->pdev, |
| 476 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 477 | } |
| 478 | } |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * megasas_check_reset_xscale - For controller reset check |
| 484 | * @regs: MFI register set |
| 485 | */ |
| 486 | static int |
| 487 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 488 | struct megasas_register_set __iomem *regs) |
| 489 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 490 | if ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 491 | (le32_to_cpu(*instance->consumer) == |
| 492 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 493 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 494 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 498 | |
| 499 | .fire_cmd = megasas_fire_cmd_xscale, |
| 500 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 501 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 502 | .clear_intr = megasas_clear_intr_xscale, |
| 503 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 504 | .adp_reset = megasas_adp_reset_xscale, |
| 505 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 506 | .service_isr = megasas_isr, |
| 507 | .tasklet = megasas_complete_cmd_dpc, |
| 508 | .init_adapter = megasas_init_adapter_mfi, |
| 509 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 510 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 511 | }; |
| 512 | |
| 513 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 514 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 515 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 516 | */ |
| 517 | |
| 518 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 519 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 520 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 521 | */ |
| 522 | |
| 523 | /** |
| 524 | * megasas_enable_intr_ppc - Enables interrupts |
| 525 | * @regs: MFI register set |
| 526 | */ |
| 527 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 528 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 529 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 530 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 531 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 532 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 533 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 534 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 535 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 536 | |
| 537 | /* Dummy readl to force pci flush */ |
| 538 | readl(®s->outbound_intr_mask); |
| 539 | } |
| 540 | |
| 541 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 542 | * megasas_disable_intr_ppc - Disable interrupt |
| 543 | * @regs: MFI register set |
| 544 | */ |
| 545 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 546 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 547 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 548 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 549 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 550 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 551 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 552 | writel(mask, ®s->outbound_intr_mask); |
| 553 | /* Dummy readl to force pci flush */ |
| 554 | readl(®s->outbound_intr_mask); |
| 555 | } |
| 556 | |
| 557 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 558 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 559 | * @regs: MFI register set |
| 560 | */ |
| 561 | static u32 |
| 562 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) |
| 563 | { |
| 564 | return readl(&(regs)->outbound_scratch_pad); |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 569 | * @regs: MFI register set |
| 570 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 571 | static int |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 572 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) |
| 573 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 574 | u32 status, mfiStatus = 0; |
| 575 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 576 | /* |
| 577 | * Check if it is our interrupt |
| 578 | */ |
| 579 | status = readl(®s->outbound_intr_status); |
| 580 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 581 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 582 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 583 | |
| 584 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 585 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 586 | |
| 587 | /* |
| 588 | * Clear the interrupt by writing back the same value |
| 589 | */ |
| 590 | writel(status, ®s->outbound_doorbell_clear); |
| 591 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 592 | /* Dummy readl to force pci flush */ |
| 593 | readl(®s->outbound_doorbell_clear); |
| 594 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 595 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 596 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 597 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 598 | /** |
| 599 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 600 | * @frame_phys_addr : Physical address of cmd |
| 601 | * @frame_count : Number of frames for the command |
| 602 | * @regs : MFI register set |
| 603 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 604 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 605 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 606 | dma_addr_t frame_phys_addr, |
| 607 | u32 frame_count, |
| 608 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 609 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 610 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 611 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 612 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 613 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 614 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 615 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 616 | } |
| 617 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 618 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 619 | * megasas_check_reset_ppc - For controller reset check |
| 620 | * @regs: MFI register set |
| 621 | */ |
| 622 | static int |
| 623 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 624 | struct megasas_register_set __iomem *regs) |
| 625 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 626 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 627 | return 1; |
| 628 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 629 | return 0; |
| 630 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 631 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 632 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 633 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 634 | .fire_cmd = megasas_fire_cmd_ppc, |
| 635 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 636 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 637 | .clear_intr = megasas_clear_intr_ppc, |
| 638 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 639 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 640 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 641 | .service_isr = megasas_isr, |
| 642 | .tasklet = megasas_complete_cmd_dpc, |
| 643 | .init_adapter = megasas_init_adapter_mfi, |
| 644 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 645 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 646 | }; |
| 647 | |
| 648 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 649 | * megasas_enable_intr_skinny - Enables interrupts |
| 650 | * @regs: MFI register set |
| 651 | */ |
| 652 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 653 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 654 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 655 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 656 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 657 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 658 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 659 | |
| 660 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 661 | |
| 662 | /* Dummy readl to force pci flush */ |
| 663 | readl(®s->outbound_intr_mask); |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * megasas_disable_intr_skinny - Disables interrupt |
| 668 | * @regs: MFI register set |
| 669 | */ |
| 670 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 671 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 672 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 673 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 674 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 675 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 676 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 677 | writel(mask, ®s->outbound_intr_mask); |
| 678 | /* Dummy readl to force pci flush */ |
| 679 | readl(®s->outbound_intr_mask); |
| 680 | } |
| 681 | |
| 682 | /** |
| 683 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 684 | * @regs: MFI register set |
| 685 | */ |
| 686 | static u32 |
| 687 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) |
| 688 | { |
| 689 | return readl(&(regs)->outbound_scratch_pad); |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 694 | * @regs: MFI register set |
| 695 | */ |
| 696 | static int |
| 697 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) |
| 698 | { |
| 699 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 700 | u32 mfiStatus = 0; |
| 701 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 702 | /* |
| 703 | * Check if it is our interrupt |
| 704 | */ |
| 705 | status = readl(®s->outbound_intr_status); |
| 706 | |
| 707 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 708 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 712 | * Check if it is our interrupt |
| 713 | */ |
James Georgas | a3fda7d | 2013-06-26 12:03:19 -0600 | [diff] [blame] | 714 | if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 715 | MFI_STATE_FAULT) { |
| 716 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 717 | } else |
| 718 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 719 | |
| 720 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 721 | * Clear the interrupt by writing back the same value |
| 722 | */ |
| 723 | writel(status, ®s->outbound_intr_status); |
| 724 | |
| 725 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 726 | * dummy read to flush PCI |
| 727 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 728 | readl(®s->outbound_intr_status); |
| 729 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 730 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | /** |
| 734 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 735 | * @frame_phys_addr : Physical address of cmd |
| 736 | * @frame_count : Number of frames for the command |
| 737 | * @regs : MFI register set |
| 738 | */ |
| 739 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 740 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 741 | dma_addr_t frame_phys_addr, |
| 742 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 743 | struct megasas_register_set __iomem *regs) |
| 744 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 745 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 746 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 747 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 748 | writel(upper_32_bits(frame_phys_addr), |
| 749 | &(regs)->inbound_high_queue_port); |
| 750 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 751 | &(regs)->inbound_low_queue_port); |
Tomas Henzl | b99dbe5 | 2016-02-01 15:12:04 +0100 | [diff] [blame] | 752 | mmiowb(); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 753 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 754 | } |
| 755 | |
| 756 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 757 | * megasas_check_reset_skinny - For controller reset check |
| 758 | * @regs: MFI register set |
| 759 | */ |
| 760 | static int |
| 761 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 762 | struct megasas_register_set __iomem *regs) |
| 763 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 764 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 765 | return 1; |
| 766 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 767 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 771 | |
| 772 | .fire_cmd = megasas_fire_cmd_skinny, |
| 773 | .enable_intr = megasas_enable_intr_skinny, |
| 774 | .disable_intr = megasas_disable_intr_skinny, |
| 775 | .clear_intr = megasas_clear_intr_skinny, |
| 776 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 777 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 778 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 779 | .service_isr = megasas_isr, |
| 780 | .tasklet = megasas_complete_cmd_dpc, |
| 781 | .init_adapter = megasas_init_adapter_mfi, |
| 782 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 783 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 784 | }; |
| 785 | |
| 786 | |
| 787 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 788 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 789 | * controllers |
| 790 | */ |
| 791 | |
| 792 | /** |
| 793 | * megasas_enable_intr_gen2 - Enables interrupts |
| 794 | * @regs: MFI register set |
| 795 | */ |
| 796 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 797 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 798 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 799 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 800 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 801 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 802 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 803 | |
| 804 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 805 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 806 | |
| 807 | /* Dummy readl to force pci flush */ |
| 808 | readl(®s->outbound_intr_mask); |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * megasas_disable_intr_gen2 - Disables interrupt |
| 813 | * @regs: MFI register set |
| 814 | */ |
| 815 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 816 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 817 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 818 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 819 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 820 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 821 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 822 | writel(mask, ®s->outbound_intr_mask); |
| 823 | /* Dummy readl to force pci flush */ |
| 824 | readl(®s->outbound_intr_mask); |
| 825 | } |
| 826 | |
| 827 | /** |
| 828 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 829 | * @regs: MFI register set |
| 830 | */ |
| 831 | static u32 |
| 832 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) |
| 833 | { |
| 834 | return readl(&(regs)->outbound_scratch_pad); |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 839 | * @regs: MFI register set |
| 840 | */ |
| 841 | static int |
| 842 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) |
| 843 | { |
| 844 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 845 | u32 mfiStatus = 0; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 846 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 847 | /* |
| 848 | * Check if it is our interrupt |
| 849 | */ |
| 850 | status = readl(®s->outbound_intr_status); |
| 851 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 852 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 853 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 854 | } |
| 855 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 856 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 857 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 858 | |
| 859 | /* |
| 860 | * Clear the interrupt by writing back the same value |
| 861 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 862 | if (mfiStatus) |
| 863 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 864 | |
| 865 | /* Dummy readl to force pci flush */ |
| 866 | readl(®s->outbound_intr_status); |
| 867 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 868 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 869 | } |
| 870 | /** |
| 871 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 872 | * @frame_phys_addr : Physical address of cmd |
| 873 | * @frame_count : Number of frames for the command |
| 874 | * @regs : MFI register set |
| 875 | */ |
| 876 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 877 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 878 | dma_addr_t frame_phys_addr, |
| 879 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 880 | struct megasas_register_set __iomem *regs) |
| 881 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 882 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 883 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 884 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 885 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 886 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 887 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * megasas_adp_reset_gen2 - For controller reset |
| 892 | * @regs: MFI register set |
| 893 | */ |
| 894 | static int |
| 895 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 896 | struct megasas_register_set __iomem *reg_set) |
| 897 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 898 | u32 retry = 0 ; |
| 899 | u32 HostDiag; |
| 900 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 901 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 902 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 903 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 904 | seq_offset = ®_set->fusion_seq_offset; |
| 905 | hostdiag_offset = ®_set->fusion_host_diag; |
| 906 | } |
| 907 | |
| 908 | writel(0, seq_offset); |
| 909 | writel(4, seq_offset); |
| 910 | writel(0xb, seq_offset); |
| 911 | writel(2, seq_offset); |
| 912 | writel(7, seq_offset); |
| 913 | writel(0xd, seq_offset); |
| 914 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 915 | msleep(1000); |
| 916 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 917 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 918 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 919 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 920 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 921 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 922 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 923 | retry, HostDiag); |
| 924 | |
| 925 | if (retry++ >= 100) |
| 926 | return 1; |
| 927 | |
| 928 | } |
| 929 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 930 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 931 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 932 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 933 | |
| 934 | ssleep(10); |
| 935 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 936 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 937 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 938 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 939 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 940 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 941 | retry, HostDiag); |
| 942 | |
| 943 | if (retry++ >= 1000) |
| 944 | return 1; |
| 945 | |
| 946 | } |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * megasas_check_reset_gen2 - For controller reset check |
| 952 | * @regs: MFI register set |
| 953 | */ |
| 954 | static int |
| 955 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 956 | struct megasas_register_set __iomem *regs) |
| 957 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 958 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 959 | return 1; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 960 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 961 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 965 | |
| 966 | .fire_cmd = megasas_fire_cmd_gen2, |
| 967 | .enable_intr = megasas_enable_intr_gen2, |
| 968 | .disable_intr = megasas_disable_intr_gen2, |
| 969 | .clear_intr = megasas_clear_intr_gen2, |
| 970 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 971 | .adp_reset = megasas_adp_reset_gen2, |
| 972 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 973 | .service_isr = megasas_isr, |
| 974 | .tasklet = megasas_complete_cmd_dpc, |
| 975 | .init_adapter = megasas_init_adapter_mfi, |
| 976 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 977 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 978 | }; |
| 979 | |
| 980 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 981 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 982 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 983 | */ |
| 984 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 985 | /* |
| 986 | * Template added for TB (Fusion) |
| 987 | */ |
| 988 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 989 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 990 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 991 | * megasas_issue_polled - Issues a polling command |
| 992 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 993 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 994 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 995 | * 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] | 996 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 997 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 998 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 999 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1000 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 1001 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1002 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1003 | 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] | 1004 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1005 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1006 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1007 | __func__, __LINE__); |
| 1008 | return DCMD_NOT_FIRED; |
| 1009 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1010 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1011 | instance->instancet->issue_dcmd(instance, cmd); |
| 1012 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1013 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 1014 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1019 | * @instance: Adapter soft state |
| 1020 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1021 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1022 | * |
| 1023 | * 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] | 1024 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1025 | * Used to issue ioctl commands. |
| 1026 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1027 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1028 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1029 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1030 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1031 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1032 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1033 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1034 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1035 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1036 | __func__, __LINE__); |
| 1037 | return DCMD_NOT_FIRED; |
| 1038 | } |
| 1039 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1040 | instance->instancet->issue_dcmd(instance, cmd); |
| 1041 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1042 | if (timeout) { |
| 1043 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1044 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1045 | if (!ret) { |
| 1046 | dev_err(&instance->pdev->dev, "Failed from %s %d DCMD Timed out\n", |
| 1047 | __func__, __LINE__); |
| 1048 | return DCMD_TIMEOUT; |
| 1049 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1050 | } else |
| 1051 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1052 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1053 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1054 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1055 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1060 | * @instance: Adapter soft state |
| 1061 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1062 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1063 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1064 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1065 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1066 | * cmd and waits for return status. |
| 1067 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1068 | */ |
| 1069 | static int |
| 1070 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1071 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1072 | { |
| 1073 | struct megasas_cmd *cmd; |
| 1074 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1075 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1076 | |
| 1077 | cmd = megasas_get_cmd(instance); |
| 1078 | |
| 1079 | if (!cmd) |
| 1080 | return -1; |
| 1081 | |
| 1082 | abort_fr = &cmd->frame->abort; |
| 1083 | |
| 1084 | /* |
| 1085 | * Prepare and issue the abort frame |
| 1086 | */ |
| 1087 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1088 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1089 | abort_fr->flags = cpu_to_le16(0); |
| 1090 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1091 | abort_fr->abort_mfi_phys_addr_lo = |
| 1092 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1093 | abort_fr->abort_mfi_phys_addr_hi = |
| 1094 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1095 | |
| 1096 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1097 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1098 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1099 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1100 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1101 | __func__, __LINE__); |
| 1102 | return DCMD_NOT_FIRED; |
| 1103 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1104 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1105 | instance->instancet->issue_dcmd(instance, cmd); |
| 1106 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1107 | if (timeout) { |
| 1108 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1109 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1110 | if (!ret) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1111 | dev_err(&instance->pdev->dev, "Failed from %s %d Abort Timed out\n", |
| 1112 | __func__, __LINE__); |
| 1113 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1114 | } |
| 1115 | } else |
| 1116 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1117 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1118 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1119 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1120 | |
| 1121 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1122 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1123 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1128 | * @instance: Adapter soft state |
| 1129 | * @scp: SCSI command from the mid-layer |
| 1130 | * @mfi_sgl: SGL to be filled in |
| 1131 | * |
| 1132 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1133 | * it returnes -1. |
| 1134 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1135 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1136 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1137 | union megasas_sgl *mfi_sgl) |
| 1138 | { |
| 1139 | int i; |
| 1140 | int sge_count; |
| 1141 | struct scatterlist *os_sgl; |
| 1142 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1143 | sge_count = scsi_dma_map(scp); |
| 1144 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1145 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1146 | if (sge_count) { |
| 1147 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1148 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1149 | 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] | 1150 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1151 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1152 | return sge_count; |
| 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1157 | * @instance: Adapter soft state |
| 1158 | * @scp: SCSI command from the mid-layer |
| 1159 | * @mfi_sgl: SGL to be filled in |
| 1160 | * |
| 1161 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1162 | * it returnes -1. |
| 1163 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1164 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1165 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1166 | union megasas_sgl *mfi_sgl) |
| 1167 | { |
| 1168 | int i; |
| 1169 | int sge_count; |
| 1170 | struct scatterlist *os_sgl; |
| 1171 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1172 | sge_count = scsi_dma_map(scp); |
| 1173 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1174 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1175 | if (sge_count) { |
| 1176 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1177 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1178 | 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] | 1179 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1180 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1181 | return sge_count; |
| 1182 | } |
| 1183 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1184 | /** |
| 1185 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1186 | * @instance: Adapter soft state |
| 1187 | * @scp: SCSI command from the mid-layer |
| 1188 | * @mfi_sgl: SGL to be filled in |
| 1189 | * |
| 1190 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1191 | * it returnes -1. |
| 1192 | */ |
| 1193 | static int |
| 1194 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1195 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1196 | { |
| 1197 | int i; |
| 1198 | int sge_count; |
| 1199 | struct scatterlist *os_sgl; |
| 1200 | |
| 1201 | sge_count = scsi_dma_map(scp); |
| 1202 | |
| 1203 | if (sge_count) { |
| 1204 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1205 | mfi_sgl->sge_skinny[i].length = |
| 1206 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1207 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1208 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1209 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | return sge_count; |
| 1213 | } |
| 1214 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1215 | /** |
| 1216 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1217 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1218 | * @sge_count : number of sg elements |
| 1219 | * |
| 1220 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1221 | */ |
| 1222 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1223 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1224 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1225 | { |
| 1226 | int num_cnt; |
| 1227 | int sge_bytes; |
| 1228 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1229 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1230 | |
| 1231 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1232 | sizeof(struct megasas_sge32); |
| 1233 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1234 | if (instance->flag_ieee) { |
| 1235 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1236 | } |
| 1237 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1238 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1239 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1240 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1241 | * 1 SGEs for 64-bit SGLs and |
| 1242 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1243 | */ |
| 1244 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1245 | if (instance->flag_ieee == 1) { |
| 1246 | num_cnt = sge_count - 1; |
| 1247 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1248 | num_cnt = sge_count - 1; |
| 1249 | else |
| 1250 | num_cnt = sge_count - 2; |
| 1251 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1252 | if (instance->flag_ieee == 1) { |
| 1253 | num_cnt = sge_count - 1; |
| 1254 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1255 | num_cnt = sge_count - 2; |
| 1256 | else |
| 1257 | num_cnt = sge_count - 3; |
| 1258 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1259 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1260 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1261 | sge_bytes = sge_sz * num_cnt; |
| 1262 | |
| 1263 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1264 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1265 | } |
| 1266 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1267 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1268 | |
| 1269 | if (frame_count > 7) |
| 1270 | frame_count = 8; |
| 1271 | return frame_count; |
| 1272 | } |
| 1273 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1274 | /** |
| 1275 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1276 | * @instance: Adapter soft state |
| 1277 | * @scp: SCSI command |
| 1278 | * @cmd: Command to be prepared in |
| 1279 | * |
| 1280 | * This function prepares CDB commands. These are typcially pass-through |
| 1281 | * commands to the devices. |
| 1282 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1283 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1284 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1285 | struct megasas_cmd *cmd) |
| 1286 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1287 | u32 is_logical; |
| 1288 | u32 device_id; |
| 1289 | u16 flags = 0; |
| 1290 | struct megasas_pthru_frame *pthru; |
| 1291 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1292 | is_logical = MEGASAS_IS_LOGICAL(scp->device); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1293 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1294 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1295 | |
| 1296 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1297 | flags = MFI_FRAME_DIR_WRITE; |
| 1298 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1299 | flags = MFI_FRAME_DIR_READ; |
| 1300 | else if (scp->sc_data_direction == PCI_DMA_NONE) |
| 1301 | flags = MFI_FRAME_DIR_NONE; |
| 1302 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1303 | if (instance->flag_ieee == 1) { |
| 1304 | flags |= MFI_FRAME_IEEE; |
| 1305 | } |
| 1306 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1307 | /* |
| 1308 | * Prepare the DCDB frame |
| 1309 | */ |
| 1310 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1311 | pthru->cmd_status = 0x0; |
| 1312 | pthru->scsi_status = 0x0; |
| 1313 | pthru->target_id = device_id; |
| 1314 | pthru->lun = scp->device->lun; |
| 1315 | pthru->cdb_len = scp->cmd_len; |
| 1316 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1317 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1318 | pthru->flags = cpu_to_le16(flags); |
| 1319 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1320 | |
| 1321 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1322 | |
| 1323 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1324 | * If the command is for the tape device, set the |
| 1325 | * pthru timeout to the os layer timeout value. |
| 1326 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1327 | if (scp->device->type == TYPE_TAPE) { |
| 1328 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1329 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1330 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1331 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1335 | * Construct SGL |
| 1336 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1337 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1338 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1339 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1340 | &pthru->sgl); |
| 1341 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1342 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1343 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1344 | &pthru->sgl); |
| 1345 | } else |
| 1346 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1347 | &pthru->sgl); |
| 1348 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1349 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1350 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1351 | pthru->sge_count); |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1355 | /* |
| 1356 | * Sense info specific |
| 1357 | */ |
| 1358 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1359 | pthru->sense_buf_phys_addr_hi = |
| 1360 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1361 | pthru->sense_buf_phys_addr_lo = |
| 1362 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1363 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1364 | /* |
| 1365 | * Compute the total number of frames this command consumes. FW uses |
| 1366 | * this number to pull sufficient number of frames from host memory. |
| 1367 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1368 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1369 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1370 | |
| 1371 | return cmd->frame_count; |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1376 | * @instance: Adapter soft state |
| 1377 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1378 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1379 | * |
| 1380 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1381 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1382 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1383 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1384 | struct megasas_cmd *cmd) |
| 1385 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1386 | u32 device_id; |
| 1387 | u8 sc = scp->cmnd[0]; |
| 1388 | u16 flags = 0; |
| 1389 | struct megasas_io_frame *ldio; |
| 1390 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1391 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1392 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1393 | |
| 1394 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1395 | flags = MFI_FRAME_DIR_WRITE; |
| 1396 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1397 | flags = MFI_FRAME_DIR_READ; |
| 1398 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1399 | if (instance->flag_ieee == 1) { |
| 1400 | flags |= MFI_FRAME_IEEE; |
| 1401 | } |
| 1402 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1403 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1404 | * 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] | 1405 | */ |
| 1406 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1407 | ldio->cmd_status = 0x0; |
| 1408 | ldio->scsi_status = 0x0; |
| 1409 | ldio->target_id = device_id; |
| 1410 | ldio->timeout = 0; |
| 1411 | ldio->reserved_0 = 0; |
| 1412 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1413 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1414 | ldio->start_lba_hi = 0; |
| 1415 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1416 | |
| 1417 | /* |
| 1418 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1419 | */ |
| 1420 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1421 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1422 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1423 | ((u32) scp->cmnd[2] << 8) | |
| 1424 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1425 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1426 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | /* |
| 1430 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1431 | */ |
| 1432 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1433 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1434 | ((u32) scp->cmnd[7] << 8)); |
| 1435 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1436 | ((u32) scp->cmnd[3] << 16) | |
| 1437 | ((u32) scp->cmnd[4] << 8) | |
| 1438 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /* |
| 1442 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1443 | */ |
| 1444 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1445 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1446 | ((u32) scp->cmnd[7] << 16) | |
| 1447 | ((u32) scp->cmnd[8] << 8) | |
| 1448 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1449 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1450 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1451 | ((u32) scp->cmnd[3] << 16) | |
| 1452 | ((u32) scp->cmnd[4] << 8) | |
| 1453 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1454 | } |
| 1455 | |
| 1456 | /* |
| 1457 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1458 | */ |
| 1459 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1460 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1461 | ((u32) scp->cmnd[11] << 16) | |
| 1462 | ((u32) scp->cmnd[12] << 8) | |
| 1463 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1464 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1465 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1466 | ((u32) scp->cmnd[7] << 16) | |
| 1467 | ((u32) scp->cmnd[8] << 8) | |
| 1468 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1469 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1470 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1471 | ((u32) scp->cmnd[3] << 16) | |
| 1472 | ((u32) scp->cmnd[4] << 8) | |
| 1473 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1474 | |
| 1475 | } |
| 1476 | |
| 1477 | /* |
| 1478 | * Construct SGL |
| 1479 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1480 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1481 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1482 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1483 | &ldio->sgl); |
| 1484 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1485 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1486 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1487 | } else |
| 1488 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1489 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1490 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1491 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1492 | ldio->sge_count); |
| 1493 | return 0; |
| 1494 | } |
| 1495 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1496 | /* |
| 1497 | * Sense info specific |
| 1498 | */ |
| 1499 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1500 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1501 | 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] | 1502 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1503 | /* |
| 1504 | * Compute the total number of frames this command consumes. FW uses |
| 1505 | * this number to pull sufficient number of frames from host memory. |
| 1506 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1507 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1508 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1509 | |
| 1510 | return cmd->frame_count; |
| 1511 | } |
| 1512 | |
| 1513 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1514 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1515 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1516 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1517 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1518 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1519 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1520 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1521 | int ret; |
| 1522 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1523 | switch (cmd->cmnd[0]) { |
| 1524 | case READ_10: |
| 1525 | case WRITE_10: |
| 1526 | case READ_12: |
| 1527 | case WRITE_12: |
| 1528 | case READ_6: |
| 1529 | case WRITE_6: |
| 1530 | case READ_16: |
| 1531 | case WRITE_16: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1532 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1533 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1534 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1535 | default: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1536 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1537 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1538 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1539 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1540 | } |
| 1541 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1542 | /** |
| 1543 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1544 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1545 | * @instance: Adapter soft state |
| 1546 | */ |
| 1547 | static inline void |
| 1548 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1549 | { |
| 1550 | struct megasas_cmd *cmd; |
| 1551 | int i,n; |
| 1552 | union megasas_sgl *mfi_sgl; |
| 1553 | struct megasas_io_frame *ldio; |
| 1554 | struct megasas_pthru_frame *pthru; |
| 1555 | u32 sgcount; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 1556 | u16 max_cmd = instance->max_fw_cmds; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1557 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1558 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1559 | 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] | 1560 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1561 | 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] | 1562 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1563 | 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] | 1564 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1565 | 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] | 1566 | for (i = 0; i < max_cmd; i++) { |
| 1567 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1568 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1569 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1570 | 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] | 1571 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1572 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1573 | mfi_sgl = &ldio->sgl; |
| 1574 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1575 | 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] | 1576 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1577 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1578 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1579 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1580 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1581 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1582 | mfi_sgl = &pthru->sgl; |
| 1583 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1584 | 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] | 1585 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1586 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1587 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1588 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1589 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1590 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1591 | for (n = 0; n < sgcount; n++) { |
| 1592 | if (IS_DMA64) |
| 1593 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1594 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1595 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1596 | else |
| 1597 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1598 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1599 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1600 | } |
| 1601 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1602 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1603 | 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] | 1604 | for (i = 0; i < max_cmd; i++) { |
| 1605 | |
| 1606 | cmd = instance->cmd_list[i]; |
| 1607 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1608 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1609 | 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] | 1610 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1611 | 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] | 1612 | } |
| 1613 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1614 | u32 |
| 1615 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1616 | struct scsi_cmnd *scmd) |
| 1617 | { |
| 1618 | struct megasas_cmd *cmd; |
| 1619 | u32 frame_count; |
| 1620 | |
| 1621 | cmd = megasas_get_cmd(instance); |
| 1622 | if (!cmd) |
| 1623 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1624 | |
| 1625 | /* |
| 1626 | * Logical drive command |
| 1627 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1628 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1629 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1630 | else |
| 1631 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1632 | |
| 1633 | if (!frame_count) |
| 1634 | goto out_return_cmd; |
| 1635 | |
| 1636 | cmd->scmd = scmd; |
| 1637 | scmd->SCp.ptr = (char *)cmd; |
| 1638 | |
| 1639 | /* |
| 1640 | * Issue the command to the FW |
| 1641 | */ |
| 1642 | atomic_inc(&instance->fw_outstanding); |
| 1643 | |
| 1644 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1645 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1646 | |
| 1647 | return 0; |
| 1648 | out_return_cmd: |
| 1649 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1650 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1651 | } |
| 1652 | |
| 1653 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1654 | /** |
| 1655 | * megasas_queue_command - Queue entry point |
| 1656 | * @scmd: SCSI command to be queued |
| 1657 | * @done: Callback entry point |
| 1658 | */ |
| 1659 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1660 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1661 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1662 | struct megasas_instance *instance; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1663 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1664 | |
| 1665 | instance = (struct megasas_instance *) |
| 1666 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1667 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1668 | if (instance->unload == 1) { |
| 1669 | scmd->result = DID_NO_CONNECT << 16; |
| 1670 | scmd->scsi_done(scmd); |
| 1671 | return 0; |
| 1672 | } |
| 1673 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1674 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1675 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1676 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1677 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1678 | /* Check for an mpio path and adjust behavior */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1679 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1680 | if (megasas_check_mpio_paths(instance, scmd) == |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 1681 | (DID_REQUEUE << 16)) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1682 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1683 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1684 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1685 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1686 | return 0; |
| 1687 | } |
| 1688 | } |
| 1689 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1690 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1691 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1692 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1693 | return 0; |
| 1694 | } |
| 1695 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1696 | mr_device_priv_data = scmd->device->hostdata; |
| 1697 | if (!mr_device_priv_data) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1698 | scmd->result = DID_NO_CONNECT << 16; |
| 1699 | scmd->scsi_done(scmd); |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1703 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1704 | return SCSI_MLQUEUE_HOST_BUSY; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1705 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1706 | if (mr_device_priv_data->tm_busy) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1707 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1708 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1709 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1710 | scmd->result = 0; |
| 1711 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1712 | if (MEGASAS_IS_LOGICAL(scmd->device) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1713 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1714 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1715 | scmd->result = DID_BAD_TARGET << 16; |
| 1716 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1717 | } |
| 1718 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1719 | if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && |
| 1720 | MEGASAS_IS_LOGICAL(scmd->device) && |
| 1721 | (!instance->fw_sync_cache_support)) { |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1722 | scmd->result = DID_OK << 16; |
| 1723 | goto out_done; |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1724 | } |
| 1725 | |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1726 | return instance->instancet->build_and_issue_cmd(instance, scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1727 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1728 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1729 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1730 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1731 | } |
| 1732 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1733 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1734 | { |
| 1735 | int i; |
| 1736 | |
| 1737 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1738 | |
| 1739 | if ((megasas_mgmt_info.instance[i]) && |
| 1740 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1741 | return megasas_mgmt_info.instance[i]; |
| 1742 | } |
| 1743 | |
| 1744 | return NULL; |
| 1745 | } |
| 1746 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1747 | /* |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1748 | * megasas_set_dynamic_target_properties - |
| 1749 | * Device property set by driver may not be static and it is required to be |
| 1750 | * updated after OCR |
| 1751 | * |
| 1752 | * set tm_capable. |
| 1753 | * set dma alignment (only for eedp protection enable vd). |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1754 | * |
| 1755 | * @sdev: OS provided scsi device |
| 1756 | * |
| 1757 | * Returns void |
| 1758 | */ |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1759 | void megasas_set_dynamic_target_properties(struct scsi_device *sdev) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1760 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1761 | u16 pd_index = 0, ld; |
| 1762 | u32 device_id; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1763 | struct megasas_instance *instance; |
| 1764 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1765 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1766 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1767 | struct MR_LD_RAID *raid; |
| 1768 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1769 | |
| 1770 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1771 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1772 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1773 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1774 | if (!fusion || !mr_device_priv_data) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1775 | return; |
| 1776 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1777 | if (MEGASAS_IS_LOGICAL(sdev)) { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1778 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1779 | + sdev->id; |
| 1780 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1781 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1782 | if (ld >= instance->fw_supported_vd_count) |
| 1783 | return; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1784 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1785 | |
| 1786 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1787 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1788 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1789 | mr_device_priv_data->is_tm_capable = |
| 1790 | raid->capability.tmCapable; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1791 | } else if (instance->use_seqnum_jbod_fp) { |
| 1792 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1793 | sdev->id; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1794 | pd_sync = (void *)fusion->pd_seq_sync |
| 1795 | [(instance->pd_seq_map_id - 1) & 1]; |
| 1796 | mr_device_priv_data->is_tm_capable = |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1797 | pd_sync->seq[pd_index].capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1798 | } |
| 1799 | } |
| 1800 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1801 | /* |
| 1802 | * megasas_set_nvme_device_properties - |
| 1803 | * set nomerges=2 |
| 1804 | * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K). |
| 1805 | * set maximum io transfer = MDTS of NVME device provided by MR firmware. |
| 1806 | * |
| 1807 | * MR firmware provides value in KB. Caller of this function converts |
| 1808 | * kb into bytes. |
| 1809 | * |
| 1810 | * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size, |
| 1811 | * MR firmware provides value 128 as (32 * 4K) = 128K. |
| 1812 | * |
| 1813 | * @sdev: scsi device |
| 1814 | * @max_io_size: maximum io transfer size |
| 1815 | * |
| 1816 | */ |
| 1817 | static inline void |
| 1818 | 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] | 1819 | { |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1820 | struct megasas_instance *instance; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1821 | u32 mr_nvme_pg_size; |
| 1822 | |
| 1823 | instance = (struct megasas_instance *)sdev->host->hostdata; |
| 1824 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1825 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1826 | |
| 1827 | blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512)); |
| 1828 | |
| 1829 | queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue); |
| 1830 | blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1); |
| 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | /* |
| 1835 | * megasas_set_static_target_properties - |
| 1836 | * Device property set by driver are static and it is not required to be |
| 1837 | * updated after OCR. |
| 1838 | * |
| 1839 | * set io timeout |
| 1840 | * set device queue depth |
| 1841 | * set nvme device properties. see - megasas_set_nvme_device_properties |
| 1842 | * |
| 1843 | * @sdev: scsi device |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1844 | * @is_target_prop true, if fw provided target properties. |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1845 | */ |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1846 | static void megasas_set_static_target_properties(struct scsi_device *sdev, |
| 1847 | bool is_target_prop) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1848 | { |
| 1849 | u16 target_index = 0; |
| 1850 | u8 interface_type; |
| 1851 | u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN; |
| 1852 | u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1853 | u32 tgt_device_qd; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1854 | struct megasas_instance *instance; |
| 1855 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1856 | |
| 1857 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1858 | mr_device_priv_data = sdev->hostdata; |
| 1859 | interface_type = mr_device_priv_data->interface_type; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1860 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1861 | /* |
| 1862 | * The RAID firmware may require extended timeouts. |
| 1863 | */ |
| 1864 | blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1865 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1866 | target_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1867 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1868 | switch (interface_type) { |
| 1869 | case SAS_PD: |
| 1870 | device_qd = MEGASAS_SAS_QD; |
| 1871 | break; |
| 1872 | case SATA_PD: |
| 1873 | device_qd = MEGASAS_SATA_QD; |
| 1874 | break; |
| 1875 | case NVME_PD: |
| 1876 | device_qd = MEGASAS_NVME_QD; |
| 1877 | break; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1878 | } |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1879 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1880 | if (is_target_prop) { |
| 1881 | tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth); |
| 1882 | if (tgt_device_qd && |
| 1883 | (tgt_device_qd <= instance->host->can_queue)) |
| 1884 | device_qd = tgt_device_qd; |
| 1885 | |
| 1886 | /* max_io_size_kb will be set to non zero for |
| 1887 | * nvme based vd and syspd. |
| 1888 | */ |
| 1889 | max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb); |
| 1890 | } |
| 1891 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1892 | if (instance->nvme_page_size && max_io_size_kb) |
| 1893 | megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10)); |
| 1894 | |
| 1895 | scsi_change_queue_depth(sdev, device_qd); |
| 1896 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1897 | } |
| 1898 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1899 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1900 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1901 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1902 | u16 pd_index = 0; |
| 1903 | struct megasas_instance *instance; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1904 | int ret_target_prop = DCMD_FAILED; |
| 1905 | bool is_target_prop = false; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1906 | |
| 1907 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1908 | if (instance->pd_list_not_supported) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1909 | if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1910 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1911 | sdev->id; |
| 1912 | if (instance->pd_list[pd_index].driveState != |
| 1913 | MR_PD_STATE_SYSTEM) |
| 1914 | return -ENXIO; |
| 1915 | } |
| 1916 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1917 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1918 | mutex_lock(&instance->hba_mutex); |
| 1919 | /* Send DCMD to Firmware and cache the information */ |
| 1920 | if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev)) |
| 1921 | megasas_get_pd_info(instance, sdev); |
| 1922 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1923 | /* Some ventura firmware may not have instance->nvme_page_size set. |
| 1924 | * Do not send MR_DCMD_DRV_GET_TARGET_PROP |
| 1925 | */ |
| 1926 | if ((instance->tgt_prop) && (instance->nvme_page_size)) |
| 1927 | ret_target_prop = megasas_get_target_prop(instance, sdev); |
| 1928 | |
| 1929 | is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false; |
| 1930 | megasas_set_static_target_properties(sdev, is_target_prop); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1931 | |
| 1932 | mutex_unlock(&instance->hba_mutex); |
| 1933 | |
| 1934 | /* This sdev property may change post OCR */ |
| 1935 | megasas_set_dynamic_target_properties(sdev); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1936 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1937 | return 0; |
| 1938 | } |
| 1939 | |
| 1940 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 1941 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1942 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1943 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1944 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1945 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1946 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1947 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1948 | /* |
| 1949 | * Open the OS scan to the SYSTEM PD |
| 1950 | */ |
| 1951 | pd_index = |
| 1952 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1953 | sdev->id; |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1954 | if ((instance->pd_list_not_supported || |
| 1955 | instance->pd_list[pd_index].driveState == |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1956 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1957 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1958 | } |
| 1959 | return -ENXIO; |
| 1960 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1961 | |
| 1962 | scan_target: |
| 1963 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 1964 | GFP_KERNEL); |
| 1965 | if (!mr_device_priv_data) |
| 1966 | return -ENOMEM; |
| 1967 | sdev->hostdata = mr_device_priv_data; |
Shivasharan S | 49524b3 | 2017-03-10 03:22:13 -0800 | [diff] [blame] | 1968 | |
| 1969 | atomic_set(&mr_device_priv_data->r1_ldio_hint, |
| 1970 | instance->r1_ldio_hint_default); |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1971 | return 0; |
| 1972 | } |
| 1973 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1974 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 1975 | { |
| 1976 | kfree(sdev->hostdata); |
| 1977 | sdev->hostdata = NULL; |
| 1978 | } |
| 1979 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1980 | /* |
| 1981 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 1982 | * kill adapter |
| 1983 | * @instance: Adapter soft state |
| 1984 | * |
| 1985 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 1986 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 1987 | { |
| 1988 | int i; |
| 1989 | struct megasas_cmd *cmd_mfi; |
| 1990 | struct megasas_cmd_fusion *cmd_fusion; |
| 1991 | struct fusion_context *fusion = instance->ctrl_context; |
| 1992 | |
| 1993 | /* Find all outstanding ioctls */ |
| 1994 | if (fusion) { |
| 1995 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 1996 | cmd_fusion = fusion->cmd_list[i]; |
| 1997 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 1998 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 1999 | if (cmd_mfi->sync_cmd && |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2000 | (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) { |
| 2001 | cmd_mfi->frame->hdr.cmd_status = |
| 2002 | MFI_STAT_WRONG_STATE; |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2003 | megasas_complete_cmd(instance, |
| 2004 | cmd_mfi, DID_OK); |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2005 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2006 | } |
| 2007 | } |
| 2008 | } else { |
| 2009 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2010 | cmd_mfi = instance->cmd_list[i]; |
| 2011 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 2012 | MFI_CMD_ABORT) |
| 2013 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 2014 | } |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2019 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2020 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2021 | /* 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] | 2022 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2023 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 2024 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2025 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2026 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2027 | (instance->adapter_type != MFI_SERIES)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2028 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2029 | /* Flush */ |
| 2030 | readl(&instance->reg_set->doorbell); |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 2031 | if (instance->requestorId && instance->peerIsPresent) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2032 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2033 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2034 | writel(MFI_STOP_ADP, |
| 2035 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2036 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2037 | /* Complete outstanding ioctls when adapter is killed */ |
| 2038 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | /** |
| 2042 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 2043 | * restored to max value |
| 2044 | * @instance: Adapter soft state |
| 2045 | * |
| 2046 | */ |
| 2047 | void |
| 2048 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 2049 | { |
| 2050 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 2051 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2052 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2053 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 2054 | && atomic_read(&instance->fw_outstanding) < |
| 2055 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2056 | |
| 2057 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2058 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2059 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2060 | instance->host->can_queue = instance->cur_can_queue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2061 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2062 | } |
| 2063 | } |
| 2064 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2065 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2066 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 2067 | * @instance_addr: Address of adapter soft state |
| 2068 | * |
| 2069 | * Tasklet to complete cmds |
| 2070 | */ |
| 2071 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 2072 | { |
| 2073 | u32 producer; |
| 2074 | u32 consumer; |
| 2075 | u32 context; |
| 2076 | struct megasas_cmd *cmd; |
| 2077 | struct megasas_instance *instance = |
| 2078 | (struct megasas_instance *)instance_addr; |
| 2079 | unsigned long flags; |
| 2080 | |
| 2081 | /* If we have already declared adapter dead, donot complete cmds */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2082 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2083 | return; |
| 2084 | |
| 2085 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 2086 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2087 | producer = le32_to_cpu(*instance->producer); |
| 2088 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2089 | |
| 2090 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2091 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2092 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2093 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2094 | context); |
| 2095 | BUG(); |
| 2096 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2097 | |
| 2098 | cmd = instance->cmd_list[context]; |
| 2099 | |
| 2100 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 2101 | |
| 2102 | consumer++; |
| 2103 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 2104 | consumer = 0; |
| 2105 | } |
| 2106 | } |
| 2107 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2108 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2109 | |
| 2110 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 2111 | |
| 2112 | /* |
| 2113 | * Check if we can restore can_queue |
| 2114 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2115 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2116 | } |
| 2117 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2118 | /** |
| 2119 | * megasas_start_timer - Initializes a timer object |
| 2120 | * @instance: Adapter soft state |
| 2121 | * @timer: timer object to be initialized |
| 2122 | * @fn: timer function |
| 2123 | * @interval: time interval between timer function call |
| 2124 | * |
| 2125 | */ |
| 2126 | void megasas_start_timer(struct megasas_instance *instance, |
| 2127 | struct timer_list *timer, |
| 2128 | void *fn, unsigned long interval) |
| 2129 | { |
| 2130 | init_timer(timer); |
| 2131 | timer->expires = jiffies + interval; |
| 2132 | timer->data = (unsigned long)instance; |
| 2133 | timer->function = fn; |
| 2134 | add_timer(timer); |
| 2135 | } |
| 2136 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2137 | static void |
| 2138 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2139 | |
| 2140 | static void |
| 2141 | process_fw_state_change_wq(struct work_struct *work); |
| 2142 | |
| 2143 | void megasas_do_ocr(struct megasas_instance *instance) |
| 2144 | { |
| 2145 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2146 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2147 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2148 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2149 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2150 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2151 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2152 | instance->issuepend_done = 0; |
| 2153 | |
| 2154 | atomic_set(&instance->fw_outstanding, 0); |
| 2155 | megasas_internal_reset_defer_cmds(instance); |
| 2156 | process_fw_state_change_wq(&instance->work_init); |
| 2157 | } |
| 2158 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2159 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2160 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2161 | { |
| 2162 | struct megasas_cmd *cmd; |
| 2163 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2164 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2165 | dma_addr_t new_affiliation_111_h; |
| 2166 | int ld, retval = 0; |
| 2167 | u8 thisVf; |
| 2168 | |
| 2169 | cmd = megasas_get_cmd(instance); |
| 2170 | |
| 2171 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2172 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2173 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2174 | instance->host->host_no); |
| 2175 | return -ENOMEM; |
| 2176 | } |
| 2177 | |
| 2178 | dcmd = &cmd->frame->dcmd; |
| 2179 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2180 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2181 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2182 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2183 | megasas_return_cmd(instance, cmd); |
| 2184 | return -ENOMEM; |
| 2185 | } |
| 2186 | |
| 2187 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2188 | memset(instance->vf_affiliation_111, 0, |
| 2189 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2190 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2191 | new_affiliation_111 = |
| 2192 | pci_alloc_consistent(instance->pdev, |
| 2193 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2194 | &new_affiliation_111_h); |
| 2195 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2196 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2197 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2198 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2199 | megasas_return_cmd(instance, cmd); |
| 2200 | return -ENOMEM; |
| 2201 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2202 | memset(new_affiliation_111, 0, |
| 2203 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2207 | |
| 2208 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2209 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2210 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2211 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2212 | dcmd->timeout = 0; |
| 2213 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2214 | dcmd->data_xfer_len = |
| 2215 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2216 | 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] | 2217 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2218 | if (initial) |
| 2219 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2220 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2221 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2222 | dcmd->sgl.sge32[0].phys_addr = |
| 2223 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2224 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2225 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2226 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2227 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2228 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2229 | "scsi%d\n", instance->host->host_no); |
| 2230 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2231 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2232 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2233 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2234 | dcmd->cmd_status, instance->host->host_no); |
| 2235 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2236 | goto out; |
| 2237 | } |
| 2238 | |
| 2239 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2240 | thisVf = new_affiliation_111->thisVf; |
| 2241 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2242 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2243 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2244 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2245 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2246 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2247 | memcpy(instance->vf_affiliation_111, |
| 2248 | new_affiliation_111, |
| 2249 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2250 | retval = 1; |
| 2251 | goto out; |
| 2252 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2253 | } |
| 2254 | out: |
| 2255 | if (new_affiliation_111) { |
| 2256 | pci_free_consistent(instance->pdev, |
| 2257 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2258 | new_affiliation_111, |
| 2259 | new_affiliation_111_h); |
| 2260 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2261 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2262 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2263 | |
| 2264 | return retval; |
| 2265 | } |
| 2266 | |
| 2267 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2268 | int initial) |
| 2269 | { |
| 2270 | struct megasas_cmd *cmd; |
| 2271 | struct megasas_dcmd_frame *dcmd; |
| 2272 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2273 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2274 | dma_addr_t new_affiliation_h; |
| 2275 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2276 | u8 thisVf; |
| 2277 | |
| 2278 | cmd = megasas_get_cmd(instance); |
| 2279 | |
| 2280 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2281 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2282 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2283 | instance->host->host_no); |
| 2284 | return -ENOMEM; |
| 2285 | } |
| 2286 | |
| 2287 | dcmd = &cmd->frame->dcmd; |
| 2288 | |
| 2289 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2290 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2291 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2292 | megasas_return_cmd(instance, cmd); |
| 2293 | return -ENOMEM; |
| 2294 | } |
| 2295 | |
| 2296 | if (initial) |
| 2297 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2298 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2299 | else { |
| 2300 | new_affiliation = |
| 2301 | pci_alloc_consistent(instance->pdev, |
| 2302 | (MAX_LOGICAL_DRIVES + 1) * |
| 2303 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2304 | &new_affiliation_h); |
| 2305 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2306 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2307 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2308 | instance->host->host_no); |
| 2309 | megasas_return_cmd(instance, cmd); |
| 2310 | return -ENOMEM; |
| 2311 | } |
| 2312 | memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2313 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2314 | } |
| 2315 | |
| 2316 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2317 | |
| 2318 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2319 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2320 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2321 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2322 | dcmd->timeout = 0; |
| 2323 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2324 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2325 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2326 | 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] | 2327 | |
| 2328 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2329 | dcmd->sgl.sge32[0].phys_addr = |
| 2330 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2331 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2332 | dcmd->sgl.sge32[0].phys_addr = |
| 2333 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2334 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2335 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2336 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2337 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2338 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2339 | "scsi%d\n", instance->host->host_no); |
| 2340 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2341 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2342 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2343 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2344 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2345 | dcmd->cmd_status, instance->host->host_no); |
| 2346 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2347 | goto out; |
| 2348 | } |
| 2349 | |
| 2350 | if (!initial) { |
| 2351 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2352 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2353 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2354 | instance->host->host_no); |
| 2355 | retval = 1; |
| 2356 | goto out; |
| 2357 | } |
| 2358 | newmap = new_affiliation->map; |
| 2359 | savedmap = instance->vf_affiliation->map; |
| 2360 | thisVf = new_affiliation->thisVf; |
| 2361 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2362 | found = 0; |
| 2363 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2364 | j++) { |
| 2365 | if (newmap->ref.targetId == |
| 2366 | savedmap->ref.targetId) { |
| 2367 | found = 1; |
| 2368 | if (newmap->policy[thisVf] != |
| 2369 | savedmap->policy[thisVf]) { |
| 2370 | doscan = 1; |
| 2371 | goto out; |
| 2372 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2373 | } |
| 2374 | savedmap = (struct MR_LD_VF_MAP *) |
| 2375 | ((unsigned char *)savedmap + |
| 2376 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2377 | } |
| 2378 | if (!found && newmap->policy[thisVf] != |
| 2379 | MR_LD_ACCESS_HIDDEN) { |
| 2380 | doscan = 1; |
| 2381 | goto out; |
| 2382 | } |
| 2383 | newmap = (struct MR_LD_VF_MAP *) |
| 2384 | ((unsigned char *)newmap + newmap->size); |
| 2385 | } |
| 2386 | |
| 2387 | newmap = new_affiliation->map; |
| 2388 | savedmap = instance->vf_affiliation->map; |
| 2389 | |
| 2390 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2391 | found = 0; |
| 2392 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2393 | if (savedmap->ref.targetId == |
| 2394 | newmap->ref.targetId) { |
| 2395 | found = 1; |
| 2396 | if (savedmap->policy[thisVf] != |
| 2397 | newmap->policy[thisVf]) { |
| 2398 | doscan = 1; |
| 2399 | goto out; |
| 2400 | } |
| 2401 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2402 | newmap = (struct MR_LD_VF_MAP *) |
| 2403 | ((unsigned char *)newmap + |
| 2404 | newmap->size); |
| 2405 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2406 | if (!found && savedmap->policy[thisVf] != |
| 2407 | MR_LD_ACCESS_HIDDEN) { |
| 2408 | doscan = 1; |
| 2409 | goto out; |
| 2410 | } |
| 2411 | savedmap = (struct MR_LD_VF_MAP *) |
| 2412 | ((unsigned char *)savedmap + |
| 2413 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2414 | } |
| 2415 | } |
| 2416 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2417 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2418 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2419 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2420 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2421 | new_affiliation->size); |
| 2422 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2423 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2424 | |
| 2425 | if (new_affiliation) |
| 2426 | pci_free_consistent(instance->pdev, |
| 2427 | (MAX_LOGICAL_DRIVES + 1) * |
| 2428 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2429 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2430 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2431 | |
| 2432 | return retval; |
| 2433 | } |
| 2434 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2435 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2436 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2437 | int initial) |
| 2438 | { |
| 2439 | int retval; |
| 2440 | |
| 2441 | if (instance->PlasmaFW111) |
| 2442 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2443 | else |
| 2444 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2445 | return retval; |
| 2446 | } |
| 2447 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2448 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2449 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2450 | int initial) |
| 2451 | { |
| 2452 | struct megasas_cmd *cmd; |
| 2453 | struct megasas_dcmd_frame *dcmd; |
| 2454 | int retval = 0; |
| 2455 | |
| 2456 | cmd = megasas_get_cmd(instance); |
| 2457 | |
| 2458 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2459 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2460 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2461 | instance->host->host_no); |
| 2462 | return -ENOMEM; |
| 2463 | } |
| 2464 | |
| 2465 | dcmd = &cmd->frame->dcmd; |
| 2466 | |
| 2467 | if (initial) { |
| 2468 | instance->hb_host_mem = |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 2469 | pci_zalloc_consistent(instance->pdev, |
| 2470 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2471 | &instance->hb_host_mem_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2472 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2473 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2474 | " memory for heartbeat host memory for scsi%d\n", |
| 2475 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2476 | retval = -ENOMEM; |
| 2477 | goto out; |
| 2478 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2482 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2483 | 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] | 2484 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2485 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2486 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2487 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2488 | dcmd->timeout = 0; |
| 2489 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2490 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2491 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
| 2492 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->hb_host_mem_h); |
| 2493 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2494 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2495 | 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] | 2496 | instance->host->host_no); |
| 2497 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2498 | if ((instance->adapter_type != MFI_SERIES) && |
| 2499 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2500 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2501 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2502 | else |
| 2503 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2504 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2505 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2506 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2507 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2508 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2509 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2510 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | out: |
| 2514 | megasas_return_cmd(instance, cmd); |
| 2515 | |
| 2516 | return retval; |
| 2517 | } |
| 2518 | |
| 2519 | /* Handler for SR-IOV heartbeat */ |
| 2520 | void megasas_sriov_heartbeat_handler(unsigned long instance_addr) |
| 2521 | { |
| 2522 | struct megasas_instance *instance = |
| 2523 | (struct megasas_instance *)instance_addr; |
| 2524 | |
| 2525 | if (instance->hb_host_mem->HB.fwCounter != |
| 2526 | instance->hb_host_mem->HB.driverCounter) { |
| 2527 | instance->hb_host_mem->HB.driverCounter = |
| 2528 | instance->hb_host_mem->HB.fwCounter; |
| 2529 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2530 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2531 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2532 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2533 | "completed for scsi%d\n", instance->host->host_no); |
| 2534 | schedule_work(&instance->work_init); |
| 2535 | } |
| 2536 | } |
| 2537 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2538 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2539 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2540 | * @instance: Adapter soft state |
| 2541 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2542 | * 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] | 2543 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2544 | * are pending after this time period. It also marks the controller dead. |
| 2545 | */ |
| 2546 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2547 | { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2548 | int i, sl, outstanding; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2549 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2550 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2551 | unsigned long flags; |
| 2552 | struct list_head clist_local; |
| 2553 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2554 | u32 fw_state; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2555 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2556 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2557 | dev_info(&instance->pdev->dev, "%s:%d HBA is killed.\n", |
| 2558 | __func__, __LINE__); |
| 2559 | return FAILED; |
| 2560 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2561 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2562 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2563 | |
| 2564 | INIT_LIST_HEAD(&clist_local); |
| 2565 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2566 | list_splice_init(&instance->internal_reset_pending_q, |
| 2567 | &clist_local); |
| 2568 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2569 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2570 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2571 | for (i = 0; i < wait_time; i++) { |
| 2572 | msleep(1000); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2573 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2574 | break; |
| 2575 | } |
| 2576 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2577 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2578 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2579 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2580 | return FAILED; |
| 2581 | } |
| 2582 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2583 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2584 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2585 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2586 | struct megasas_cmd, list); |
| 2587 | list_del_init(&reset_cmd->list); |
| 2588 | if (reset_cmd->scmd) { |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 2589 | reset_cmd->scmd->result = DID_REQUEUE << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2590 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2591 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2592 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2593 | |
| 2594 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2595 | megasas_return_cmd(instance, reset_cmd); |
| 2596 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2597 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2598 | "reset queue\n", |
| 2599 | reset_cmd); |
| 2600 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2601 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2602 | instance->instancet->fire_cmd(instance, |
| 2603 | reset_cmd->frame_phys_addr, |
| 2604 | 0, instance->reg_set); |
| 2605 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2606 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2607 | "cmds lst\n", |
| 2608 | reset_cmd); |
| 2609 | } |
| 2610 | reset_index++; |
| 2611 | } |
| 2612 | |
| 2613 | return SUCCESS; |
| 2614 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2615 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2616 | for (i = 0; i < resetwaittime; i++) { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2617 | outstanding = atomic_read(&instance->fw_outstanding); |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2618 | |
| 2619 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2620 | break; |
| 2621 | |
| 2622 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2623 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2624 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2625 | /* |
| 2626 | * Call cmd completion routine. Cmd to be |
| 2627 | * be completed directly without depending on isr. |
| 2628 | */ |
| 2629 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | msleep(1000); |
| 2633 | } |
| 2634 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2635 | i = 0; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2636 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2637 | 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] | 2638 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2639 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2640 | goto no_outstanding; |
| 2641 | |
| 2642 | if (instance->disableOnlineCtrlReset) |
| 2643 | goto kill_hba_and_failed; |
| 2644 | do { |
| 2645 | if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) { |
| 2646 | dev_info(&instance->pdev->dev, |
| 2647 | "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, oustanding 0x%x\n", |
| 2648 | __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding)); |
| 2649 | if (i == 3) |
| 2650 | goto kill_hba_and_failed; |
| 2651 | megasas_do_ocr(instance); |
| 2652 | |
| 2653 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2654 | dev_info(&instance->pdev->dev, "%s:%d OCR failed and HBA is killed.\n", |
| 2655 | __func__, __LINE__); |
| 2656 | return FAILED; |
| 2657 | } |
| 2658 | dev_info(&instance->pdev->dev, "%s:%d waiting_for_outstanding: after issue OCR.\n", |
| 2659 | __func__, __LINE__); |
| 2660 | |
| 2661 | for (sl = 0; sl < 10; sl++) |
| 2662 | msleep(500); |
| 2663 | |
| 2664 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2665 | |
| 2666 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
| 2667 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2668 | goto no_outstanding; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2669 | } |
| 2670 | i++; |
| 2671 | } while (i <= 3); |
| 2672 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2673 | no_outstanding: |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2674 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2675 | dev_info(&instance->pdev->dev, "%s:%d no more pending commands remain after reset handling.\n", |
| 2676 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2677 | return SUCCESS; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2678 | |
| 2679 | kill_hba_and_failed: |
| 2680 | |
| 2681 | /* Reset not supported, kill adapter */ |
| 2682 | dev_info(&instance->pdev->dev, "%s:%d killing adapter scsi%d" |
| 2683 | " disableOnlineCtrlReset %d fw_outstanding %d \n", |
| 2684 | __func__, __LINE__, instance->host->host_no, instance->disableOnlineCtrlReset, |
| 2685 | atomic_read(&instance->fw_outstanding)); |
| 2686 | megasas_dump_pending_frames(instance); |
| 2687 | megaraid_sas_kill_hba(instance); |
| 2688 | |
| 2689 | return FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | /** |
| 2693 | * megasas_generic_reset - Generic reset routine |
| 2694 | * @scmd: Mid-layer SCSI command |
| 2695 | * |
| 2696 | * This routine implements a generic reset handler for device, bus and host |
| 2697 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2698 | * function after they do their specific tasks. |
| 2699 | */ |
| 2700 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2701 | { |
| 2702 | int ret_val; |
| 2703 | struct megasas_instance *instance; |
| 2704 | |
| 2705 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2706 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2707 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2708 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2709 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2710 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2711 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2712 | return FAILED; |
| 2713 | } |
| 2714 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2715 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2716 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2717 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2718 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2719 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2720 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2721 | return ret_val; |
| 2722 | } |
| 2723 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2724 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2725 | * megasas_reset_timer - quiesce the adapter if required |
| 2726 | * @scmd: scsi cmnd |
| 2727 | * |
| 2728 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2729 | * cmd has not been completed within the timeout period. |
| 2730 | */ |
| 2731 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2732 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2733 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2734 | struct megasas_instance *instance; |
| 2735 | unsigned long flags; |
| 2736 | |
| 2737 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 2738 | (scmd_timeout * 2) * HZ)) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2739 | return BLK_EH_NOT_HANDLED; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2742 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2743 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2744 | /* FW is busy, throttle IO */ |
| 2745 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2746 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2747 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2748 | instance->last_time = jiffies; |
| 2749 | instance->flag |= MEGASAS_FW_BUSY; |
| 2750 | |
| 2751 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2752 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2753 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | /** |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2757 | * megasas_dump_frame - This function will dump MPT/MFI frame |
| 2758 | */ |
| 2759 | static inline void |
| 2760 | megasas_dump_frame(void *mpi_request, int sz) |
| 2761 | { |
| 2762 | int i; |
| 2763 | __le32 *mfp = (__le32 *)mpi_request; |
| 2764 | |
| 2765 | printk(KERN_INFO "IO request frame:\n\t"); |
Dan Carpenter | 40a4c2c | 2017-02-14 19:38:55 +0300 | [diff] [blame] | 2766 | for (i = 0; i < sz / sizeof(__le32); i++) { |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2767 | if (i && ((i % 8) == 0)) |
| 2768 | printk("\n\t"); |
| 2769 | printk("%08x ", le32_to_cpu(mfp[i])); |
| 2770 | } |
| 2771 | printk("\n"); |
| 2772 | } |
| 2773 | |
| 2774 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2775 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2776 | */ |
| 2777 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2778 | { |
| 2779 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2780 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2781 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2782 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2783 | |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2784 | scmd_printk(KERN_INFO, scmd, |
| 2785 | "Controller reset is requested due to IO timeout\n" |
| 2786 | "SCSI command pointer: (%p)\t SCSI host state: %d\t" |
| 2787 | " SCSI host busy: %d\t FW outstanding: %d\n", |
| 2788 | scmd, scmd->device->host->shost_state, |
| 2789 | atomic_read((atomic_t *)&scmd->device->host->host_busy), |
| 2790 | atomic_read(&instance->fw_outstanding)); |
| 2791 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2792 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2793 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2794 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2795 | if (instance->adapter_type == MFI_SERIES) { |
| 2796 | ret = megasas_generic_reset(scmd); |
| 2797 | } else { |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2798 | struct megasas_cmd_fusion *cmd; |
| 2799 | cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr; |
| 2800 | if (cmd) |
| 2801 | megasas_dump_frame(cmd->io_request, |
Shivasharan S | 5dd977e | 2017-08-23 04:47:07 -0700 | [diff] [blame] | 2802 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2803 | ret = megasas_reset_fusion(scmd->device->host, |
| 2804 | SCSIIO_TIMEOUT_OCR); |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2805 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2806 | |
| 2807 | return ret; |
| 2808 | } |
| 2809 | |
| 2810 | /** |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2811 | * megasas_task_abort - Issues task abort request to firmware |
| 2812 | * (supported only for fusion adapters) |
| 2813 | * @scmd: SCSI command pointer |
| 2814 | */ |
| 2815 | static int megasas_task_abort(struct scsi_cmnd *scmd) |
| 2816 | { |
| 2817 | int ret; |
| 2818 | struct megasas_instance *instance; |
| 2819 | |
| 2820 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2821 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2822 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2823 | ret = megasas_task_abort_fusion(scmd); |
| 2824 | else { |
| 2825 | sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n"); |
| 2826 | ret = FAILED; |
| 2827 | } |
| 2828 | |
| 2829 | return ret; |
| 2830 | } |
| 2831 | |
| 2832 | /** |
| 2833 | * megasas_reset_target: Issues target reset request to firmware |
| 2834 | * (supported only for fusion adapters) |
| 2835 | * @scmd: SCSI command pointer |
| 2836 | */ |
| 2837 | static int megasas_reset_target(struct scsi_cmnd *scmd) |
| 2838 | { |
| 2839 | int ret; |
| 2840 | struct megasas_instance *instance; |
| 2841 | |
| 2842 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2843 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2844 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2845 | ret = megasas_reset_target_fusion(scmd); |
| 2846 | else { |
| 2847 | sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n"); |
| 2848 | ret = FAILED; |
| 2849 | } |
| 2850 | |
| 2851 | return ret; |
| 2852 | } |
| 2853 | |
| 2854 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2855 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2856 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2857 | * @bdev: block device |
| 2858 | * @capacity: drive capacity |
| 2859 | * @geom: geometry parameters |
| 2860 | */ |
| 2861 | static int |
| 2862 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2863 | sector_t capacity, int geom[]) |
| 2864 | { |
| 2865 | int heads; |
| 2866 | int sectors; |
| 2867 | sector_t cylinders; |
| 2868 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2869 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2870 | /* Default heads (64) & sectors (32) */ |
| 2871 | heads = 64; |
| 2872 | sectors = 32; |
| 2873 | |
| 2874 | tmp = heads * sectors; |
| 2875 | cylinders = capacity; |
| 2876 | |
| 2877 | sector_div(cylinders, tmp); |
| 2878 | |
| 2879 | /* |
| 2880 | * Handle extended translation size for logical drives > 1Gb |
| 2881 | */ |
| 2882 | |
| 2883 | if (capacity >= 0x200000) { |
| 2884 | heads = 255; |
| 2885 | sectors = 63; |
| 2886 | tmp = heads*sectors; |
| 2887 | cylinders = capacity; |
| 2888 | sector_div(cylinders, tmp); |
| 2889 | } |
| 2890 | |
| 2891 | geom[0] = heads; |
| 2892 | geom[1] = sectors; |
| 2893 | geom[2] = cylinders; |
| 2894 | |
| 2895 | return 0; |
| 2896 | } |
| 2897 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2898 | static void megasas_aen_polling(struct work_struct *work); |
| 2899 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2900 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2901 | * megasas_service_aen - Processes an event notification |
| 2902 | * @instance: Adapter soft state |
| 2903 | * @cmd: AEN command completed by the ISR |
| 2904 | * |
| 2905 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2906 | * event occurs. When an event of interest occurs, FW completes the command |
| 2907 | * that it was previously holding. |
| 2908 | * |
| 2909 | * This routines sends SIGIO signal to processes that have registered with the |
| 2910 | * driver for AEN. |
| 2911 | */ |
| 2912 | static void |
| 2913 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2914 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2915 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2916 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2917 | /* |
| 2918 | * Don't signal app if it is just an aborted previously registered aen |
| 2919 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2920 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2921 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2922 | megasas_poll_wait_aen = 1; |
| 2923 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2924 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2925 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2926 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2927 | else |
| 2928 | cmd->abort_aen = 0; |
| 2929 | |
| 2930 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2931 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2932 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2933 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2934 | if ((instance->unload == 0) && |
| 2935 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2936 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2937 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2938 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2939 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2940 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2941 | } else { |
| 2942 | ev->instance = instance; |
| 2943 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 2944 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 2945 | megasas_aen_polling); |
| 2946 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2947 | } |
| 2948 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2949 | } |
| 2950 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2951 | static ssize_t |
| 2952 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 2953 | struct device_attribute *attr, const char *buf, size_t count) |
| 2954 | { |
| 2955 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2956 | struct megasas_instance *instance = |
| 2957 | (struct megasas_instance *) shost->hostdata; |
| 2958 | int val = 0; |
| 2959 | unsigned long flags; |
| 2960 | |
| 2961 | if (kstrtoint(buf, 0, &val) != 0) |
| 2962 | return -EINVAL; |
| 2963 | |
| 2964 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2965 | instance->fw_crash_buffer_offset = val; |
| 2966 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2967 | return strlen(buf); |
| 2968 | } |
| 2969 | |
| 2970 | static ssize_t |
| 2971 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 2972 | struct device_attribute *attr, char *buf) |
| 2973 | { |
| 2974 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2975 | struct megasas_instance *instance = |
| 2976 | (struct megasas_instance *) shost->hostdata; |
| 2977 | u32 size; |
| 2978 | unsigned long buff_addr; |
| 2979 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 2980 | unsigned long src_addr; |
| 2981 | unsigned long flags; |
| 2982 | u32 buff_offset; |
| 2983 | |
| 2984 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2985 | buff_offset = instance->fw_crash_buffer_offset; |
| 2986 | if (!instance->crash_dump_buf && |
| 2987 | !((instance->fw_crash_state == AVAILABLE) || |
| 2988 | (instance->fw_crash_state == COPYING))) { |
| 2989 | dev_err(&instance->pdev->dev, |
| 2990 | "Firmware crash dump is not available\n"); |
| 2991 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2992 | return -EINVAL; |
| 2993 | } |
| 2994 | |
| 2995 | buff_addr = (unsigned long) buf; |
| 2996 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2997 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2998 | dev_err(&instance->pdev->dev, |
| 2999 | "Firmware crash dump offset is out of range\n"); |
| 3000 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3001 | return 0; |
| 3002 | } |
| 3003 | |
| 3004 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 3005 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 3006 | |
| 3007 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 3008 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3009 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3010 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3011 | |
| 3012 | return size; |
| 3013 | } |
| 3014 | |
| 3015 | static ssize_t |
| 3016 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 3017 | struct device_attribute *attr, char *buf) |
| 3018 | { |
| 3019 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3020 | struct megasas_instance *instance = |
| 3021 | (struct megasas_instance *) shost->hostdata; |
| 3022 | |
| 3023 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 3024 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 3025 | } |
| 3026 | |
| 3027 | static ssize_t |
| 3028 | megasas_fw_crash_state_store(struct device *cdev, |
| 3029 | struct device_attribute *attr, const char *buf, size_t count) |
| 3030 | { |
| 3031 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3032 | struct megasas_instance *instance = |
| 3033 | (struct megasas_instance *) shost->hostdata; |
| 3034 | int val = 0; |
| 3035 | unsigned long flags; |
| 3036 | |
| 3037 | if (kstrtoint(buf, 0, &val) != 0) |
| 3038 | return -EINVAL; |
| 3039 | |
| 3040 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 3041 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 3042 | "firmware crash state\n"); |
| 3043 | return -EINVAL; |
| 3044 | } |
| 3045 | |
| 3046 | instance->fw_crash_state = val; |
| 3047 | |
| 3048 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 3049 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3050 | megasas_free_host_crash_buffer(instance); |
| 3051 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3052 | if (val == COPY_ERROR) |
| 3053 | dev_info(&instance->pdev->dev, "application failed to " |
| 3054 | "copy Firmware crash dump\n"); |
| 3055 | else |
| 3056 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 3057 | "copied successfully\n"); |
| 3058 | } |
| 3059 | return strlen(buf); |
| 3060 | } |
| 3061 | |
| 3062 | static ssize_t |
| 3063 | megasas_fw_crash_state_show(struct device *cdev, |
| 3064 | struct device_attribute *attr, char *buf) |
| 3065 | { |
| 3066 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3067 | struct megasas_instance *instance = |
| 3068 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3069 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3070 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 3071 | } |
| 3072 | |
| 3073 | static ssize_t |
| 3074 | megasas_page_size_show(struct device *cdev, |
| 3075 | struct device_attribute *attr, char *buf) |
| 3076 | { |
| 3077 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 3078 | } |
| 3079 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3080 | static ssize_t |
| 3081 | megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr, |
| 3082 | char *buf) |
| 3083 | { |
| 3084 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3085 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3086 | |
| 3087 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding)); |
| 3088 | } |
| 3089 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3090 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 3091 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 3092 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 3093 | megasas_fw_crash_buffer_size_show, NULL); |
| 3094 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 3095 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 3096 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 3097 | megasas_page_size_show, NULL); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3098 | static DEVICE_ATTR(ldio_outstanding, S_IRUGO, |
| 3099 | megasas_ldio_outstanding_show, NULL); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3100 | |
| 3101 | struct device_attribute *megaraid_host_attrs[] = { |
| 3102 | &dev_attr_fw_crash_buffer_size, |
| 3103 | &dev_attr_fw_crash_buffer, |
| 3104 | &dev_attr_fw_crash_state, |
| 3105 | &dev_attr_page_size, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3106 | &dev_attr_ldio_outstanding, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3107 | NULL, |
| 3108 | }; |
| 3109 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3110 | /* |
| 3111 | * Scsi host template for megaraid_sas driver |
| 3112 | */ |
| 3113 | static struct scsi_host_template megasas_template = { |
| 3114 | |
| 3115 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 3116 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3117 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 3118 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 3119 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3120 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3121 | .queuecommand = megasas_queue_command, |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3122 | .eh_target_reset_handler = megasas_reset_target, |
| 3123 | .eh_abort_handler = megasas_task_abort, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3124 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3125 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3126 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3127 | .bios_param = megasas_bios_param, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3128 | .use_clustering = ENABLE_CLUSTERING, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 3129 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 3130 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3131 | }; |
| 3132 | |
| 3133 | /** |
| 3134 | * megasas_complete_int_cmd - Completes an internal command |
| 3135 | * @instance: Adapter soft state |
| 3136 | * @cmd: Command to be completed |
| 3137 | * |
| 3138 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 3139 | * after it issues a command. This function wakes up that waiting routine by |
| 3140 | * calling wake_up() on the wait queue. |
| 3141 | */ |
| 3142 | static void |
| 3143 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 3144 | struct megasas_cmd *cmd) |
| 3145 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3146 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3147 | wake_up(&instance->int_cmd_wait_q); |
| 3148 | } |
| 3149 | |
| 3150 | /** |
| 3151 | * megasas_complete_abort - Completes aborting a command |
| 3152 | * @instance: Adapter soft state |
| 3153 | * @cmd: Cmd that was issued to abort another cmd |
| 3154 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3155 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 3156 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3157 | * wakes up all functions waiting on the same wait queue. |
| 3158 | */ |
| 3159 | static void |
| 3160 | megasas_complete_abort(struct megasas_instance *instance, |
| 3161 | struct megasas_cmd *cmd) |
| 3162 | { |
| 3163 | if (cmd->sync_cmd) { |
| 3164 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3165 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3166 | wake_up(&instance->abort_cmd_wait_q); |
| 3167 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3171 | * megasas_complete_cmd - Completes a command |
| 3172 | * @instance: Adapter soft state |
| 3173 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3174 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3175 | * SCSI mid-layer instead of the value returned |
| 3176 | * by the FW. This should be used if caller wants |
| 3177 | * an alternate status (as in the case of aborted |
| 3178 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3179 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3180 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3181 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 3182 | u8 alt_status) |
| 3183 | { |
| 3184 | int exception = 0; |
| 3185 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3186 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3187 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3188 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3189 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3190 | /* flag for the retry reset */ |
| 3191 | cmd->retry_for_fw_reset = 0; |
| 3192 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3193 | if (cmd->scmd) |
| 3194 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3195 | |
| 3196 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3197 | case MFI_CMD_INVALID: |
| 3198 | /* Some older 1068 controller FW may keep a pended |
| 3199 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3200 | when booting the kdump kernel. Ignore this command to |
| 3201 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3202 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3203 | "completed\n"); |
| 3204 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3205 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3206 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3207 | case MFI_CMD_PD_SCSI_IO: |
| 3208 | case MFI_CMD_LD_SCSI_IO: |
| 3209 | |
| 3210 | /* |
| 3211 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3212 | * issued either through an IO path or an IOCTL path. If it |
| 3213 | * was via IOCTL, we will send it to internal completion. |
| 3214 | */ |
| 3215 | if (cmd->sync_cmd) { |
| 3216 | cmd->sync_cmd = 0; |
| 3217 | megasas_complete_int_cmd(instance, cmd); |
| 3218 | break; |
| 3219 | } |
| 3220 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3221 | case MFI_CMD_LD_READ: |
| 3222 | case MFI_CMD_LD_WRITE: |
| 3223 | |
| 3224 | if (alt_status) { |
| 3225 | cmd->scmd->result = alt_status << 16; |
| 3226 | exception = 1; |
| 3227 | } |
| 3228 | |
| 3229 | if (exception) { |
| 3230 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3231 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3232 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3233 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3234 | cmd->scmd->scsi_done(cmd->scmd); |
| 3235 | megasas_return_cmd(instance, cmd); |
| 3236 | |
| 3237 | break; |
| 3238 | } |
| 3239 | |
| 3240 | switch (hdr->cmd_status) { |
| 3241 | |
| 3242 | case MFI_STAT_OK: |
| 3243 | cmd->scmd->result = DID_OK << 16; |
| 3244 | break; |
| 3245 | |
| 3246 | case MFI_STAT_SCSI_IO_FAILED: |
| 3247 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3248 | cmd->scmd->result = |
| 3249 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3250 | break; |
| 3251 | |
| 3252 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3253 | |
| 3254 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3255 | |
| 3256 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3257 | memset(cmd->scmd->sense_buffer, 0, |
| 3258 | SCSI_SENSE_BUFFERSIZE); |
| 3259 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3260 | hdr->sense_len); |
| 3261 | |
| 3262 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3263 | } |
| 3264 | |
| 3265 | break; |
| 3266 | |
| 3267 | case MFI_STAT_LD_OFFLINE: |
| 3268 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3269 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3270 | break; |
| 3271 | |
| 3272 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3273 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3274 | hdr->cmd_status); |
| 3275 | cmd->scmd->result = DID_ERROR << 16; |
| 3276 | break; |
| 3277 | } |
| 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 | case MFI_CMD_SMP: |
| 3288 | case MFI_CMD_STP: |
| 3289 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3290 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3291 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3292 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3293 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3294 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3295 | spin_lock_irqsave(instance->host->host_lock, flags); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3296 | instance->map_update_cmd = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3297 | if (cmd->frame->hdr.cmd_status != 0) { |
| 3298 | if (cmd->frame->hdr.cmd_status != |
| 3299 | MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3300 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3301 | cmd->frame->hdr.cmd_status); |
| 3302 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3303 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3304 | spin_unlock_irqrestore( |
| 3305 | instance->host->host_lock, |
| 3306 | flags); |
| 3307 | break; |
| 3308 | } |
| 3309 | } else |
| 3310 | instance->map_id++; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3311 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3312 | |
| 3313 | /* |
| 3314 | * Set fast path IO to ZERO. |
| 3315 | * Validate Map will set proper value. |
| 3316 | * Meanwhile all IOs will go as LD IO. |
| 3317 | */ |
| 3318 | if (MR_ValidateMapInfo(instance)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3319 | fusion->fast_path_io = 1; |
| 3320 | else |
| 3321 | fusion->fast_path_io = 0; |
| 3322 | megasas_sync_map_info(instance); |
| 3323 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3324 | flags); |
| 3325 | break; |
| 3326 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3327 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3328 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3329 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3330 | megasas_poll_wait_aen = 0; |
| 3331 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3332 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3333 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3334 | /* FW has an updated PD sequence */ |
| 3335 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3336 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3337 | |
| 3338 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3339 | status = cmd->frame->hdr.cmd_status; |
| 3340 | instance->jbod_seq_cmd = NULL; |
| 3341 | megasas_return_cmd(instance, cmd); |
| 3342 | |
| 3343 | if (status == MFI_STAT_OK) { |
| 3344 | instance->pd_seq_map_id++; |
| 3345 | /* Re-register a pd sync seq num cmd */ |
| 3346 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3347 | instance->use_seqnum_jbod_fp = false; |
| 3348 | } else |
| 3349 | instance->use_seqnum_jbod_fp = false; |
| 3350 | |
| 3351 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3352 | break; |
| 3353 | } |
| 3354 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3355 | /* |
| 3356 | * See if got an event notification |
| 3357 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3358 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3359 | megasas_service_aen(instance, cmd); |
| 3360 | else |
| 3361 | megasas_complete_int_cmd(instance, cmd); |
| 3362 | |
| 3363 | break; |
| 3364 | |
| 3365 | case MFI_CMD_ABORT: |
| 3366 | /* |
| 3367 | * Cmd issued to abort another cmd returned |
| 3368 | */ |
| 3369 | megasas_complete_abort(instance, cmd); |
| 3370 | break; |
| 3371 | |
| 3372 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3373 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3374 | hdr->cmd); |
| 3375 | break; |
| 3376 | } |
| 3377 | } |
| 3378 | |
| 3379 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3380 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3381 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3382 | * @instance: Adapter soft state |
| 3383 | */ |
| 3384 | static inline void |
| 3385 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3386 | { |
| 3387 | struct megasas_cmd *cmd; |
| 3388 | struct list_head clist_local; |
| 3389 | union megasas_evt_class_locale class_locale; |
| 3390 | unsigned long flags; |
| 3391 | u32 seq_num; |
| 3392 | |
| 3393 | INIT_LIST_HEAD(&clist_local); |
| 3394 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3395 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3396 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3397 | |
| 3398 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3399 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3400 | struct megasas_cmd, list); |
| 3401 | list_del_init(&cmd->list); |
| 3402 | |
| 3403 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3404 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3405 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3406 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3407 | |
| 3408 | cmd->retry_for_fw_reset++; |
| 3409 | |
| 3410 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3411 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3412 | "was tried multiple times during reset." |
| 3413 | "Shutting down the HBA\n", |
| 3414 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3415 | instance->instancet->disable_intr(instance); |
| 3416 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3417 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3418 | return; |
| 3419 | } |
| 3420 | } |
| 3421 | |
| 3422 | if (cmd->sync_cmd == 1) { |
| 3423 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3424 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3425 | "cmd attached to internal command!\n"); |
| 3426 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3427 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3428 | "on the internal reset queue," |
| 3429 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3430 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3431 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3432 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3433 | 0, instance->reg_set); |
| 3434 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3435 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3436 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3437 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3438 | |
| 3439 | atomic_inc(&instance->fw_outstanding); |
| 3440 | instance->instancet->fire_cmd(instance, |
| 3441 | cmd->frame_phys_addr, |
| 3442 | cmd->frame_count-1, instance->reg_set); |
| 3443 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3444 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3445 | "internal reset defer list while re-issue!!\n", |
| 3446 | cmd); |
| 3447 | } |
| 3448 | } |
| 3449 | |
| 3450 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3451 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3452 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3453 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3454 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3458 | * Initiate AEN (Asynchronous Event Notification) |
| 3459 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3460 | seq_num = instance->last_seq_num; |
| 3461 | class_locale.members.reserved = 0; |
| 3462 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3463 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3464 | |
| 3465 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3466 | } |
| 3467 | |
| 3468 | /** |
| 3469 | * Move the internal reset pending commands to a deferred queue. |
| 3470 | * |
| 3471 | * We move the commands pending at internal reset time to a |
| 3472 | * pending queue. This queue would be flushed after successful |
| 3473 | * completion of the internal reset sequence. if the internal reset |
| 3474 | * did not complete in time, the kernel reset handler would flush |
| 3475 | * these commands. |
| 3476 | **/ |
| 3477 | static void |
| 3478 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3479 | { |
| 3480 | struct megasas_cmd *cmd; |
| 3481 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3482 | u16 max_cmd = instance->max_fw_cmds; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3483 | u32 defer_index; |
| 3484 | unsigned long flags; |
| 3485 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3486 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3487 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3488 | for (i = 0; i < max_cmd; i++) { |
| 3489 | cmd = instance->cmd_list[i]; |
| 3490 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3491 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3492 | "on the defer queue as internal\n", |
| 3493 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3494 | |
| 3495 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3496 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3497 | " moving this cmd:%p, %d %p, it was" |
| 3498 | "discovered on some list?\n", |
| 3499 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3500 | |
| 3501 | list_del_init(&cmd->list); |
| 3502 | } |
| 3503 | defer_index++; |
| 3504 | list_add_tail(&cmd->list, |
| 3505 | &instance->internal_reset_pending_q); |
| 3506 | } |
| 3507 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3508 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | |
| 3512 | static void |
| 3513 | process_fw_state_change_wq(struct work_struct *work) |
| 3514 | { |
| 3515 | struct megasas_instance *instance = |
| 3516 | container_of(work, struct megasas_instance, work_init); |
| 3517 | u32 wait; |
| 3518 | unsigned long flags; |
| 3519 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3520 | if (atomic_read(&instance->adprecovery) != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3521 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3522 | atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3523 | return ; |
| 3524 | } |
| 3525 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3526 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3527 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3528 | "state, restarting it...\n"); |
| 3529 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3530 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3531 | atomic_set(&instance->fw_outstanding, 0); |
| 3532 | |
| 3533 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3534 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3535 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3536 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3537 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3538 | "initiating next stage...\n"); |
| 3539 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3540 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3541 | "state 2 starting...\n"); |
| 3542 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3543 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3544 | for (wait = 0; wait < 30; wait++) { |
| 3545 | msleep(1000); |
| 3546 | } |
| 3547 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3548 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3549 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3550 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3551 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3552 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3553 | return ; |
| 3554 | } |
| 3555 | |
| 3556 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3557 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3558 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3559 | ) { |
| 3560 | *instance->consumer = *instance->producer; |
| 3561 | } else { |
| 3562 | *instance->consumer = 0; |
| 3563 | *instance->producer = 0; |
| 3564 | } |
| 3565 | |
| 3566 | megasas_issue_init_mfi(instance); |
| 3567 | |
| 3568 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3569 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3570 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3571 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3572 | |
| 3573 | megasas_issue_pending_cmds_again(instance); |
| 3574 | instance->issuepend_done = 1; |
| 3575 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3579 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3580 | * @instance: Adapter soft state |
| 3581 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3582 | * SCSI mid-layer instead of the status |
| 3583 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3584 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3585 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3586 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3587 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3588 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3589 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3590 | u32 mfiStatus; |
| 3591 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3592 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3593 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3594 | instance->reg_set)) == 1) { |
| 3595 | return IRQ_HANDLED; |
| 3596 | } |
| 3597 | |
| 3598 | if ((mfiStatus = instance->instancet->clear_intr( |
| 3599 | instance->reg_set) |
| 3600 | ) == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3601 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3602 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3603 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | instance->mfiStatus = mfiStatus; |
| 3607 | |
| 3608 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3609 | fw_state = instance->instancet->read_fw_status_reg( |
| 3610 | instance->reg_set) & MFI_STATE_MASK; |
| 3611 | |
| 3612 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3613 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3614 | fw_state); |
| 3615 | } |
| 3616 | |
| 3617 | if ((fw_state == MFI_STATE_FAULT) && |
| 3618 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3619 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3620 | |
| 3621 | if ((instance->pdev->device == |
| 3622 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3623 | (instance->pdev->device == |
| 3624 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3625 | (instance->pdev->device == |
| 3626 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3627 | |
| 3628 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3629 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3630 | } |
| 3631 | |
| 3632 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3633 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3634 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3635 | instance->issuepend_done = 0; |
| 3636 | |
| 3637 | atomic_set(&instance->fw_outstanding, 0); |
| 3638 | megasas_internal_reset_defer_cmds(instance); |
| 3639 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3640 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3641 | fw_state, atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3642 | |
| 3643 | schedule_work(&instance->work_init); |
| 3644 | return IRQ_HANDLED; |
| 3645 | |
| 3646 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3647 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3648 | fw_state, instance->disableOnlineCtrlReset); |
| 3649 | } |
| 3650 | } |
| 3651 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3652 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3653 | return IRQ_HANDLED; |
| 3654 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3655 | /** |
| 3656 | * megasas_isr - isr entry point |
| 3657 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3658 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3659 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3660 | struct megasas_irq_context *irq_context = devp; |
| 3661 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3662 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3663 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3664 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3665 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3666 | return IRQ_HANDLED; |
| 3667 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3668 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3669 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3670 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3671 | |
| 3672 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3673 | } |
| 3674 | |
| 3675 | /** |
| 3676 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3677 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3678 | * |
| 3679 | * During the initialization, FW passes can potentially be in any one of |
| 3680 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3681 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3682 | * has to wait for the ready state. |
| 3683 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3684 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3685 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3686 | { |
| 3687 | int i; |
| 3688 | u8 max_wait; |
| 3689 | u32 fw_state; |
| 3690 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3691 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3692 | |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3693 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 3694 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3695 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3696 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3697 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3698 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3699 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3700 | while (fw_state != MFI_STATE_READY) { |
| 3701 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3702 | switch (fw_state) { |
| 3703 | |
| 3704 | case MFI_STATE_FAULT: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3705 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3706 | if (ocr) { |
| 3707 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3708 | cur_state = MFI_STATE_FAULT; |
| 3709 | break; |
| 3710 | } else |
| 3711 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3712 | |
| 3713 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3714 | /* |
| 3715 | * Set the CLR bit in inbound doorbell |
| 3716 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3717 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3718 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3719 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3720 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3721 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3722 | writel( |
| 3723 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3724 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3725 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3726 | writel( |
| 3727 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3728 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3729 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3730 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3731 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3732 | break; |
| 3733 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3734 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3735 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3736 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3737 | (instance->pdev->device == |
| 3738 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3739 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3740 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3741 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3742 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3743 | writel(MFI_INIT_HOTPLUG, |
| 3744 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3745 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3746 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3747 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3748 | break; |
| 3749 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3750 | case MFI_STATE_OPERATIONAL: |
| 3751 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3752 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3753 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3754 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3755 | if ((instance->pdev->device == |
| 3756 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3757 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3758 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3759 | (instance->adapter_type != MFI_SERIES)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3760 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3761 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3762 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3763 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3764 | for (i = 0; i < (10 * 1000); i += 20) { |
| 3765 | if (readl( |
| 3766 | &instance-> |
| 3767 | reg_set-> |
| 3768 | doorbell) & 1) |
| 3769 | msleep(20); |
| 3770 | else |
| 3771 | break; |
| 3772 | } |
| 3773 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3774 | } else |
| 3775 | writel(MFI_RESET_FLAGS, |
| 3776 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3777 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3778 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3779 | cur_state = MFI_STATE_OPERATIONAL; |
| 3780 | break; |
| 3781 | |
| 3782 | case MFI_STATE_UNDEFINED: |
| 3783 | /* |
| 3784 | * This state should not last for more than 2 seconds |
| 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_UNDEFINED; |
| 3788 | break; |
| 3789 | |
| 3790 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3791 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3792 | cur_state = MFI_STATE_BB_INIT; |
| 3793 | break; |
| 3794 | |
| 3795 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3796 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3797 | cur_state = MFI_STATE_FW_INIT; |
| 3798 | break; |
| 3799 | |
| 3800 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3801 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3802 | cur_state = MFI_STATE_FW_INIT_2; |
| 3803 | break; |
| 3804 | |
| 3805 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3806 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3807 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 3808 | break; |
| 3809 | |
| 3810 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3811 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3812 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 3813 | break; |
| 3814 | |
| 3815 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3816 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3817 | fw_state); |
| 3818 | return -ENODEV; |
| 3819 | } |
| 3820 | |
| 3821 | /* |
| 3822 | * The cur_state should not last for more than max_wait secs |
| 3823 | */ |
| 3824 | for (i = 0; i < (max_wait * 1000); i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3825 | curr_abs_state = instance->instancet-> |
| 3826 | read_fw_status_reg(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3827 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3828 | if (abs_state == curr_abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3829 | msleep(1); |
| 3830 | } else |
| 3831 | break; |
| 3832 | } |
| 3833 | |
| 3834 | /* |
| 3835 | * Return error if fw_state hasn't changed after max_wait |
| 3836 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3837 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3838 | 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] | 3839 | "in %d secs\n", fw_state, max_wait); |
| 3840 | return -ENODEV; |
| 3841 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3842 | |
| 3843 | abs_state = curr_abs_state; |
| 3844 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3845 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3846 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3847 | |
| 3848 | return 0; |
| 3849 | } |
| 3850 | |
| 3851 | /** |
| 3852 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 3853 | * @instance: Adapter soft state |
| 3854 | */ |
| 3855 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 3856 | { |
| 3857 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3858 | u16 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3859 | struct megasas_cmd *cmd; |
| 3860 | |
| 3861 | if (!instance->frame_dma_pool) |
| 3862 | return; |
| 3863 | |
| 3864 | /* |
| 3865 | * Return all frames to pool |
| 3866 | */ |
| 3867 | for (i = 0; i < max_cmd; i++) { |
| 3868 | |
| 3869 | cmd = instance->cmd_list[i]; |
| 3870 | |
| 3871 | if (cmd->frame) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3872 | dma_pool_free(instance->frame_dma_pool, cmd->frame, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3873 | cmd->frame_phys_addr); |
| 3874 | |
| 3875 | if (cmd->sense) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3876 | dma_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3877 | cmd->sense_phys_addr); |
| 3878 | } |
| 3879 | |
| 3880 | /* |
| 3881 | * Now destroy the pool itself |
| 3882 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3883 | dma_pool_destroy(instance->frame_dma_pool); |
| 3884 | dma_pool_destroy(instance->sense_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3885 | |
| 3886 | instance->frame_dma_pool = NULL; |
| 3887 | instance->sense_dma_pool = NULL; |
| 3888 | } |
| 3889 | |
| 3890 | /** |
| 3891 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 3892 | * @instance: Adapter soft state |
| 3893 | * |
| 3894 | * Each command packet has an embedded DMA memory buffer that is used for |
| 3895 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 3896 | * function creates those DMA memory buffers for each command packet by using |
| 3897 | * PCI pool facility. |
| 3898 | */ |
| 3899 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 3900 | { |
| 3901 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3902 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3903 | u32 sge_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3904 | u32 frame_count; |
| 3905 | struct megasas_cmd *cmd; |
| 3906 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3907 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3908 | |
| 3909 | /* |
| 3910 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 3911 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 3912 | */ |
| 3913 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 3914 | sizeof(struct megasas_sge32); |
| 3915 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3916 | if (instance->flag_ieee) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3917 | sge_sz = sizeof(struct megasas_sge_skinny); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3918 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3919 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 3920 | * For MFI controllers. |
| 3921 | * max_num_sge = 60 |
| 3922 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 3923 | * Total 960 byte (15 MFI frame of 64 byte) |
| 3924 | * |
| 3925 | * Fusion adapter require only 3 extra frame. |
| 3926 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 3927 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 3928 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3929 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3930 | frame_count = (instance->adapter_type == MFI_SERIES) ? |
| 3931 | (15 + 1) : (3 + 1); |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 3932 | instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3933 | /* |
| 3934 | * Use DMA pool facility provided by PCI layer |
| 3935 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3936 | instance->frame_dma_pool = dma_pool_create("megasas frame pool", |
| 3937 | &instance->pdev->dev, |
| 3938 | instance->mfi_frame_size, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3939 | |
| 3940 | if (!instance->frame_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3941 | 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] | 3942 | return -ENOMEM; |
| 3943 | } |
| 3944 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3945 | instance->sense_dma_pool = dma_pool_create("megasas sense pool", |
| 3946 | &instance->pdev->dev, 128, |
| 3947 | 4, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3948 | |
| 3949 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3950 | 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] | 3951 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3952 | dma_pool_destroy(instance->frame_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3953 | instance->frame_dma_pool = NULL; |
| 3954 | |
| 3955 | return -ENOMEM; |
| 3956 | } |
| 3957 | |
| 3958 | /* |
| 3959 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 3960 | * By making cmd->index as the context instead of the &cmd, we can |
| 3961 | * always use 32bit context regardless of the architecture |
| 3962 | */ |
| 3963 | for (i = 0; i < max_cmd; i++) { |
| 3964 | |
| 3965 | cmd = instance->cmd_list[i]; |
| 3966 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3967 | cmd->frame = dma_pool_alloc(instance->frame_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3968 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 3969 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3970 | cmd->sense = dma_pool_alloc(instance->sense_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3971 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 3972 | |
| 3973 | /* |
| 3974 | * megasas_teardown_frame_pool() takes care of freeing |
| 3975 | * whatever has been allocated |
| 3976 | */ |
| 3977 | if (!cmd->frame || !cmd->sense) { |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3978 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "dma_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3979 | megasas_teardown_frame_pool(instance); |
| 3980 | return -ENOMEM; |
| 3981 | } |
| 3982 | |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 3983 | memset(cmd->frame, 0, instance->mfi_frame_size); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3984 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3985 | cmd->frame->io.pad_0 = 0; |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3986 | if ((instance->adapter_type == MFI_SERIES) && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3987 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | return 0; |
| 3991 | } |
| 3992 | |
| 3993 | /** |
| 3994 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 3995 | * @instance: Adapter soft state |
| 3996 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3997 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3998 | { |
| 3999 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4000 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4001 | /* First free the MFI frame pool */ |
| 4002 | megasas_teardown_frame_pool(instance); |
| 4003 | |
| 4004 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4005 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 4006 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4007 | kfree(instance->cmd_list[i]); |
| 4008 | |
| 4009 | /* Free the cmd_list buffer itself */ |
| 4010 | kfree(instance->cmd_list); |
| 4011 | instance->cmd_list = NULL; |
| 4012 | |
| 4013 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 4014 | } |
| 4015 | |
| 4016 | /** |
| 4017 | * megasas_alloc_cmds - Allocates the command packets |
| 4018 | * @instance: Adapter soft state |
| 4019 | * |
| 4020 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 4021 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 4022 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 4023 | * the FW. |
| 4024 | * |
| 4025 | * Each frame has a 32-bit field called context (tag). This context is used |
| 4026 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 4027 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 4028 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 4029 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 4030 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 4031 | * This array is used only to look up the megasas_cmd given the context. The |
| 4032 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 4033 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4034 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4035 | { |
| 4036 | int i; |
| 4037 | int j; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4038 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4039 | struct megasas_cmd *cmd; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4040 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4041 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4042 | fusion = instance->ctrl_context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4043 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4044 | |
| 4045 | /* |
| 4046 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 4047 | * Allocate the dynamic array first and then allocate individual |
| 4048 | * commands. |
| 4049 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 4050 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4051 | |
| 4052 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4053 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4054 | return -ENOMEM; |
| 4055 | } |
| 4056 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4057 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4058 | |
| 4059 | for (i = 0; i < max_cmd; i++) { |
| 4060 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 4061 | GFP_KERNEL); |
| 4062 | |
| 4063 | if (!instance->cmd_list[i]) { |
| 4064 | |
| 4065 | for (j = 0; j < i; j++) |
| 4066 | kfree(instance->cmd_list[j]); |
| 4067 | |
| 4068 | kfree(instance->cmd_list); |
| 4069 | instance->cmd_list = NULL; |
| 4070 | |
| 4071 | return -ENOMEM; |
| 4072 | } |
| 4073 | } |
| 4074 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4075 | for (i = 0; i < max_cmd; i++) { |
| 4076 | cmd = instance->cmd_list[i]; |
| 4077 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 4078 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4079 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4080 | cmd->instance = instance; |
| 4081 | |
| 4082 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 4083 | } |
| 4084 | |
| 4085 | /* |
| 4086 | * Create a frame pool and assign one frame to each cmd |
| 4087 | */ |
| 4088 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4089 | 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] | 4090 | megasas_free_cmds(instance); |
| 4091 | } |
| 4092 | |
| 4093 | return 0; |
| 4094 | } |
| 4095 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4096 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4097 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 4098 | * @instance: Adapter soft state |
| 4099 | * |
| 4100 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 4101 | * or FW is not under OCR. |
| 4102 | */ |
| 4103 | inline int |
| 4104 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 4105 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4106 | if (instance->adapter_type == MFI_SERIES) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4107 | return KILL_ADAPTER; |
| 4108 | else if (instance->unload || |
| 4109 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 4110 | return IGNORE_TIMEOUT; |
| 4111 | else |
| 4112 | return INITIATE_OCR; |
| 4113 | } |
| 4114 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4115 | static void |
| 4116 | megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4117 | { |
| 4118 | int ret; |
| 4119 | struct megasas_cmd *cmd; |
| 4120 | struct megasas_dcmd_frame *dcmd; |
| 4121 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4122 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 4123 | u16 device_id = 0; |
| 4124 | |
| 4125 | device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4126 | cmd = megasas_get_cmd(instance); |
| 4127 | |
| 4128 | if (!cmd) { |
| 4129 | dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4130 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4131 | } |
| 4132 | |
| 4133 | dcmd = &cmd->frame->dcmd; |
| 4134 | |
| 4135 | memset(instance->pd_info, 0, sizeof(*instance->pd_info)); |
| 4136 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4137 | |
| 4138 | dcmd->mbox.s[0] = cpu_to_le16(device_id); |
| 4139 | dcmd->cmd = MFI_CMD_DCMD; |
| 4140 | dcmd->cmd_status = 0xFF; |
| 4141 | dcmd->sge_count = 1; |
| 4142 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
| 4143 | dcmd->timeout = 0; |
| 4144 | dcmd->pad_0 = 0; |
| 4145 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4146 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_GET_INFO); |
| 4147 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->pd_info_h); |
| 4148 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4149 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4150 | if ((instance->adapter_type != MFI_SERIES) && |
| 4151 | !instance->mask_interrupts) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4152 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 4153 | else |
| 4154 | ret = megasas_issue_polled(instance, cmd); |
| 4155 | |
| 4156 | switch (ret) { |
| 4157 | case DCMD_SUCCESS: |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4158 | mr_device_priv_data = sdev->hostdata; |
| 4159 | le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType); |
| 4160 | mr_device_priv_data->interface_type = |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4161 | instance->pd_info->state.ddf.pdType.intf; |
| 4162 | break; |
| 4163 | |
| 4164 | case DCMD_TIMEOUT: |
| 4165 | |
| 4166 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4167 | case INITIATE_OCR: |
| 4168 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4169 | megasas_reset_fusion(instance->host, |
| 4170 | MFI_IO_TIMEOUT_OCR); |
| 4171 | break; |
| 4172 | case KILL_ADAPTER: |
| 4173 | megaraid_sas_kill_hba(instance); |
| 4174 | break; |
| 4175 | case IGNORE_TIMEOUT: |
| 4176 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4177 | __func__, __LINE__); |
| 4178 | break; |
| 4179 | } |
| 4180 | |
| 4181 | break; |
| 4182 | } |
| 4183 | |
| 4184 | if (ret != DCMD_TIMEOUT) |
| 4185 | megasas_return_cmd(instance, cmd); |
| 4186 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4187 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4188 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4189 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4190 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 4191 | * @instance: Adapter soft state |
| 4192 | * @pd_list: pd_list structure |
| 4193 | * |
| 4194 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4195 | * list structure. This information is mainly used to find out SYSTEM |
| 4196 | * supported by the FW. |
| 4197 | */ |
| 4198 | static int |
| 4199 | megasas_get_pd_list(struct megasas_instance *instance) |
| 4200 | { |
| 4201 | int ret = 0, pd_index = 0; |
| 4202 | struct megasas_cmd *cmd; |
| 4203 | struct megasas_dcmd_frame *dcmd; |
| 4204 | struct MR_PD_LIST *ci; |
| 4205 | struct MR_PD_ADDRESS *pd_addr; |
| 4206 | dma_addr_t ci_h = 0; |
| 4207 | |
Sumit Saxena | d908316 | 2016-07-08 03:30:16 -0700 | [diff] [blame] | 4208 | if (instance->pd_list_not_supported) { |
| 4209 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4210 | "not supported by firmware\n"); |
| 4211 | return ret; |
| 4212 | } |
| 4213 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4214 | cmd = megasas_get_cmd(instance); |
| 4215 | |
| 4216 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4217 | 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] | 4218 | return -ENOMEM; |
| 4219 | } |
| 4220 | |
| 4221 | dcmd = &cmd->frame->dcmd; |
| 4222 | |
| 4223 | ci = pci_alloc_consistent(instance->pdev, |
| 4224 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h); |
| 4225 | |
| 4226 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4227 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for pd_list\n"); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4228 | megasas_return_cmd(instance, cmd); |
| 4229 | return -ENOMEM; |
| 4230 | } |
| 4231 | |
| 4232 | memset(ci, 0, sizeof(*ci)); |
| 4233 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4234 | |
| 4235 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 4236 | dcmd->mbox.b[1] = 0; |
| 4237 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4238 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4239 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4240 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4241 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4242 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4243 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 4244 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
| 4245 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4246 | dcmd->sgl.sge32[0].length = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4247 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4248 | if ((instance->adapter_type != MFI_SERIES) && |
| 4249 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4250 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4251 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4252 | else |
| 4253 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4254 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4255 | switch (ret) { |
| 4256 | case DCMD_FAILED: |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4257 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4258 | "failed/not supported by firmware\n"); |
| 4259 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4260 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4261 | megaraid_sas_kill_hba(instance); |
| 4262 | else |
| 4263 | instance->pd_list_not_supported = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4264 | break; |
| 4265 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4266 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4267 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4268 | case INITIATE_OCR: |
| 4269 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4270 | /* |
| 4271 | * DCMD failed from AEN path. |
| 4272 | * AEN path already hold reset_mutex to avoid PCI access |
| 4273 | * while OCR is in progress. |
| 4274 | */ |
| 4275 | mutex_unlock(&instance->reset_mutex); |
| 4276 | megasas_reset_fusion(instance->host, |
| 4277 | MFI_IO_TIMEOUT_OCR); |
| 4278 | mutex_lock(&instance->reset_mutex); |
| 4279 | break; |
| 4280 | case KILL_ADAPTER: |
| 4281 | megaraid_sas_kill_hba(instance); |
| 4282 | break; |
| 4283 | case IGNORE_TIMEOUT: |
| 4284 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4285 | __func__, __LINE__); |
| 4286 | break; |
| 4287 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4288 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4289 | break; |
| 4290 | |
| 4291 | case DCMD_SUCCESS: |
| 4292 | pd_addr = ci->addr; |
| 4293 | |
| 4294 | if ((le32_to_cpu(ci->count) > |
| 4295 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4296 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4297 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4298 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4299 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4300 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4301 | 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] | 4302 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4303 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4304 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4305 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4306 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4307 | MR_PD_STATE_SYSTEM; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4308 | pd_addr++; |
| 4309 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4310 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4311 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4312 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4313 | break; |
| 4314 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | pci_free_consistent(instance->pdev, |
| 4318 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 4319 | ci, ci_h); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4320 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4321 | if (ret != DCMD_TIMEOUT) |
| 4322 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4323 | |
| 4324 | return ret; |
| 4325 | } |
| 4326 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4327 | /* |
| 4328 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4329 | * @instance: Adapter soft state |
| 4330 | * @ld_list: ld_list structure |
| 4331 | * |
| 4332 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4333 | * list structure. This information is mainly used to find out SYSTEM |
| 4334 | * supported by the FW. |
| 4335 | */ |
| 4336 | static int |
| 4337 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4338 | { |
| 4339 | int ret = 0, ld_index = 0, ids = 0; |
| 4340 | struct megasas_cmd *cmd; |
| 4341 | struct megasas_dcmd_frame *dcmd; |
| 4342 | struct MR_LD_LIST *ci; |
| 4343 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4344 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4345 | |
| 4346 | cmd = megasas_get_cmd(instance); |
| 4347 | |
| 4348 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4349 | 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] | 4350 | return -ENOMEM; |
| 4351 | } |
| 4352 | |
| 4353 | dcmd = &cmd->frame->dcmd; |
| 4354 | |
| 4355 | ci = pci_alloc_consistent(instance->pdev, |
| 4356 | sizeof(struct MR_LD_LIST), |
| 4357 | &ci_h); |
| 4358 | |
| 4359 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4360 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem in get_ld_list\n"); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4361 | megasas_return_cmd(instance, cmd); |
| 4362 | return -ENOMEM; |
| 4363 | } |
| 4364 | |
| 4365 | memset(ci, 0, sizeof(*ci)); |
| 4366 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4367 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4368 | if (instance->supportmax256vd) |
| 4369 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4370 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4371 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4372 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4373 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4374 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4375 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4376 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
| 4377 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4378 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4379 | dcmd->pad_0 = 0; |
| 4380 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4381 | if ((instance->adapter_type != MFI_SERIES) && |
| 4382 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4383 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4384 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4385 | else |
| 4386 | ret = megasas_issue_polled(instance, cmd); |
| 4387 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4388 | ld_count = le32_to_cpu(ci->ldCount); |
| 4389 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4390 | switch (ret) { |
| 4391 | case DCMD_FAILED: |
| 4392 | megaraid_sas_kill_hba(instance); |
| 4393 | break; |
| 4394 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4395 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4396 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4397 | case INITIATE_OCR: |
| 4398 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4399 | /* |
| 4400 | * DCMD failed from AEN path. |
| 4401 | * AEN path already hold reset_mutex to avoid PCI access |
| 4402 | * while OCR is in progress. |
| 4403 | */ |
| 4404 | mutex_unlock(&instance->reset_mutex); |
| 4405 | megasas_reset_fusion(instance->host, |
| 4406 | MFI_IO_TIMEOUT_OCR); |
| 4407 | mutex_lock(&instance->reset_mutex); |
| 4408 | break; |
| 4409 | case KILL_ADAPTER: |
| 4410 | megaraid_sas_kill_hba(instance); |
| 4411 | break; |
| 4412 | case IGNORE_TIMEOUT: |
| 4413 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4414 | __func__, __LINE__); |
| 4415 | break; |
| 4416 | } |
| 4417 | |
| 4418 | break; |
| 4419 | |
| 4420 | case DCMD_SUCCESS: |
| 4421 | if (ld_count > instance->fw_supported_vd_count) |
| 4422 | break; |
| 4423 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4424 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4425 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4426 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4427 | if (ci->ldList[ld_index].state != 0) { |
| 4428 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4429 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4430 | } |
| 4431 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4432 | |
| 4433 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4434 | } |
| 4435 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4436 | pci_free_consistent(instance->pdev, sizeof(struct MR_LD_LIST), ci, ci_h); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4437 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4438 | if (ret != DCMD_TIMEOUT) |
| 4439 | megasas_return_cmd(instance, cmd); |
| 4440 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4441 | return ret; |
| 4442 | } |
| 4443 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4444 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4445 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4446 | * @instance: Adapter soft state |
| 4447 | * @ld_list: ld_list structure |
| 4448 | * |
| 4449 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4450 | * list structure. This information is mainly used to find out SYSTEM |
| 4451 | * supported by the FW. |
| 4452 | */ |
| 4453 | static int |
| 4454 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4455 | { |
| 4456 | int ret = 0, ld_index = 0, ids = 0; |
| 4457 | struct megasas_cmd *cmd; |
| 4458 | struct megasas_dcmd_frame *dcmd; |
| 4459 | struct MR_LD_TARGETID_LIST *ci; |
| 4460 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4461 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4462 | |
| 4463 | cmd = megasas_get_cmd(instance); |
| 4464 | |
| 4465 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4466 | dev_warn(&instance->pdev->dev, |
| 4467 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4468 | return -ENOMEM; |
| 4469 | } |
| 4470 | |
| 4471 | dcmd = &cmd->frame->dcmd; |
| 4472 | |
| 4473 | ci = pci_alloc_consistent(instance->pdev, |
| 4474 | sizeof(struct MR_LD_TARGETID_LIST), &ci_h); |
| 4475 | |
| 4476 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4477 | dev_warn(&instance->pdev->dev, |
| 4478 | "Failed to alloc mem for ld_list_query\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4479 | megasas_return_cmd(instance, cmd); |
| 4480 | return -ENOMEM; |
| 4481 | } |
| 4482 | |
| 4483 | memset(ci, 0, sizeof(*ci)); |
| 4484 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4485 | |
| 4486 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4487 | if (instance->supportmax256vd) |
| 4488 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4489 | |
| 4490 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4491 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4492 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4493 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4494 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4495 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4496 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
| 4497 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4498 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4499 | dcmd->pad_0 = 0; |
| 4500 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4501 | if ((instance->adapter_type != MFI_SERIES) && |
| 4502 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4503 | 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] | 4504 | else |
| 4505 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4506 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4507 | switch (ret) { |
| 4508 | case DCMD_FAILED: |
| 4509 | dev_info(&instance->pdev->dev, |
| 4510 | "DCMD not supported by firmware - %s %d\n", |
| 4511 | __func__, __LINE__); |
| 4512 | ret = megasas_get_ld_list(instance); |
| 4513 | break; |
| 4514 | case DCMD_TIMEOUT: |
| 4515 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4516 | case INITIATE_OCR: |
| 4517 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4518 | /* |
| 4519 | * DCMD failed from AEN path. |
| 4520 | * AEN path already hold reset_mutex to avoid PCI access |
| 4521 | * while OCR is in progress. |
| 4522 | */ |
| 4523 | mutex_unlock(&instance->reset_mutex); |
| 4524 | megasas_reset_fusion(instance->host, |
| 4525 | MFI_IO_TIMEOUT_OCR); |
| 4526 | mutex_lock(&instance->reset_mutex); |
| 4527 | break; |
| 4528 | case KILL_ADAPTER: |
| 4529 | megaraid_sas_kill_hba(instance); |
| 4530 | break; |
| 4531 | case IGNORE_TIMEOUT: |
| 4532 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4533 | __func__, __LINE__); |
| 4534 | break; |
| 4535 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4536 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4537 | break; |
| 4538 | case DCMD_SUCCESS: |
| 4539 | tgtid_count = le32_to_cpu(ci->count); |
| 4540 | |
| 4541 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4542 | break; |
| 4543 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4544 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4545 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4546 | ids = ci->targetId[ld_index]; |
| 4547 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4548 | } |
| 4549 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4550 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | pci_free_consistent(instance->pdev, sizeof(struct MR_LD_TARGETID_LIST), |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4554 | ci, ci_h); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4555 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4556 | if (ret != DCMD_TIMEOUT) |
| 4557 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4558 | |
| 4559 | return ret; |
| 4560 | } |
| 4561 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4562 | /* |
| 4563 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4564 | * instance : Controller's instance |
| 4565 | */ |
| 4566 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4567 | { |
| 4568 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4569 | u32 ventura_map_sz = 0; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4570 | |
| 4571 | fusion = instance->ctrl_context; |
| 4572 | /* For MFI based controllers return dummy success */ |
| 4573 | if (!fusion) |
| 4574 | return; |
| 4575 | |
| 4576 | instance->supportmax256vd = |
| 4577 | instance->ctrl_info->adapterOperations3.supportMaxExtLDs; |
| 4578 | /* Below is additional check to address future FW enhancement */ |
| 4579 | if (instance->ctrl_info->max_lds > 64) |
| 4580 | instance->supportmax256vd = 1; |
| 4581 | |
| 4582 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4583 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4584 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4585 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4586 | if (instance->supportmax256vd) { |
| 4587 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4588 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4589 | } else { |
| 4590 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4591 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4592 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4593 | |
| 4594 | dev_info(&instance->pdev->dev, |
| 4595 | "firmware type\t: %s\n", |
| 4596 | instance->supportmax256vd ? "Extended VD(240 VD)firmware" : |
| 4597 | "Legacy(64 VD) firmware"); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4598 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4599 | if (instance->max_raid_mapsize) { |
| 4600 | ventura_map_sz = instance->max_raid_mapsize * |
| 4601 | MR_MIN_MAP_SIZE; /* 64k */ |
| 4602 | fusion->current_map_sz = ventura_map_sz; |
| 4603 | fusion->max_map_sz = ventura_map_sz; |
| 4604 | } else { |
| 4605 | fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 4606 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4607 | (instance->fw_supported_vd_count - 1)); |
| 4608 | 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] | 4609 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4610 | fusion->max_map_sz = |
| 4611 | max(fusion->old_map_sz, fusion->new_map_sz); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4612 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4613 | if (instance->supportmax256vd) |
| 4614 | fusion->current_map_sz = fusion->new_map_sz; |
| 4615 | else |
| 4616 | fusion->current_map_sz = fusion->old_map_sz; |
| 4617 | } |
| 4618 | /* irrespective of FW raid maps, driver raid map is constant */ |
| 4619 | 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] | 4620 | } |
| 4621 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4622 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4623 | * megasas_get_controller_info - Returns FW's controller structure |
| 4624 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4625 | * |
| 4626 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 4627 | * This information is mainly used to find out the maximum IO transfer per |
| 4628 | * command supported by the FW. |
| 4629 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4630 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4631 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4632 | { |
| 4633 | int ret = 0; |
| 4634 | struct megasas_cmd *cmd; |
| 4635 | struct megasas_dcmd_frame *dcmd; |
| 4636 | struct megasas_ctrl_info *ci; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4637 | struct megasas_ctrl_info *ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4638 | dma_addr_t ci_h = 0; |
| 4639 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4640 | ctrl_info = instance->ctrl_info; |
| 4641 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4642 | cmd = megasas_get_cmd(instance); |
| 4643 | |
| 4644 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4645 | 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] | 4646 | return -ENOMEM; |
| 4647 | } |
| 4648 | |
| 4649 | dcmd = &cmd->frame->dcmd; |
| 4650 | |
| 4651 | ci = pci_alloc_consistent(instance->pdev, |
| 4652 | sizeof(struct megasas_ctrl_info), &ci_h); |
| 4653 | |
| 4654 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4655 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ctrl info\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4656 | megasas_return_cmd(instance, cmd); |
| 4657 | return -ENOMEM; |
| 4658 | } |
| 4659 | |
| 4660 | memset(ci, 0, sizeof(*ci)); |
| 4661 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4662 | |
| 4663 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4664 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4665 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4666 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4667 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4668 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4669 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 4670 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
| 4671 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4672 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4673 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4674 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4675 | if ((instance->adapter_type != MFI_SERIES) && |
| 4676 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4677 | 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] | 4678 | else |
| 4679 | ret = megasas_issue_polled(instance, cmd); |
| 4680 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4681 | switch (ret) { |
| 4682 | case DCMD_SUCCESS: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4683 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4684 | /* Save required controller information in |
| 4685 | * CPU endianness format. |
| 4686 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4687 | le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties); |
| 4688 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations2); |
| 4689 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations3); |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4690 | le16_to_cpus((u16 *)&ctrl_info->adapter_operations4); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4691 | |
| 4692 | /* Update the latest Ext VD info. |
| 4693 | * From Init path, store current firmware details. |
| 4694 | * From OCR path, detect any firmware properties changes. |
| 4695 | * in case of Firmware upgrade without system reboot. |
| 4696 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4697 | megasas_update_ext_vd_details(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4698 | instance->use_seqnum_jbod_fp = |
| 4699 | ctrl_info->adapterOperations3.useSeqNumJbodFP; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4700 | instance->support_morethan256jbod = |
| 4701 | ctrl_info->adapter_operations4.support_pd_map_target_id; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4702 | |
| 4703 | /*Check whether controller is iMR or MR */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4704 | instance->is_imr = (ctrl_info->memory_size ? 0 : 1); |
| 4705 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4706 | "controller type\t: %s(%dMB)\n", |
| 4707 | instance->is_imr ? "iMR" : "MR", |
| 4708 | le16_to_cpu(ctrl_info->memory_size)); |
| 4709 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 4710 | instance->disableOnlineCtrlReset = |
| 4711 | ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4712 | instance->secure_jbod_support = |
| 4713 | ctrl_info->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4714 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 4715 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4716 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 4717 | instance->secure_jbod_support ? "Yes" : "No"); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4718 | break; |
| 4719 | |
| 4720 | case DCMD_TIMEOUT: |
| 4721 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4722 | case INITIATE_OCR: |
| 4723 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4724 | megasas_reset_fusion(instance->host, |
| 4725 | MFI_IO_TIMEOUT_OCR); |
| 4726 | break; |
| 4727 | case KILL_ADAPTER: |
| 4728 | megaraid_sas_kill_hba(instance); |
| 4729 | break; |
| 4730 | case IGNORE_TIMEOUT: |
| 4731 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4732 | __func__, __LINE__); |
| 4733 | break; |
| 4734 | } |
| 4735 | case DCMD_FAILED: |
| 4736 | megaraid_sas_kill_hba(instance); |
| 4737 | break; |
| 4738 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4739 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4740 | |
| 4741 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), |
| 4742 | ci, ci_h); |
| 4743 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4744 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4745 | |
| 4746 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4747 | return ret; |
| 4748 | } |
| 4749 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4750 | /* |
| 4751 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 4752 | * to firmware |
| 4753 | * |
| 4754 | * @instance: Adapter soft state |
| 4755 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 4756 | MR_CRASH_BUF_TURN_OFF = 0 |
| 4757 | MR_CRASH_BUF_TURN_ON = 1 |
| 4758 | * @return 0 on success non-zero on failure. |
| 4759 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 4760 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 4761 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 4762 | * crash dump feature is supported by the FW. |
| 4763 | * |
| 4764 | */ |
| 4765 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 4766 | u8 crash_buf_state) |
| 4767 | { |
| 4768 | int ret = 0; |
| 4769 | struct megasas_cmd *cmd; |
| 4770 | struct megasas_dcmd_frame *dcmd; |
| 4771 | |
| 4772 | cmd = megasas_get_cmd(instance); |
| 4773 | |
| 4774 | if (!cmd) { |
| 4775 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4776 | return -ENOMEM; |
| 4777 | } |
| 4778 | |
| 4779 | |
| 4780 | dcmd = &cmd->frame->dcmd; |
| 4781 | |
| 4782 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4783 | dcmd->mbox.b[0] = crash_buf_state; |
| 4784 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4785 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4786 | dcmd->sge_count = 1; |
| 4787 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
| 4788 | dcmd->timeout = 0; |
| 4789 | dcmd->pad_0 = 0; |
| 4790 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4791 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS); |
| 4792 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->crash_dump_h); |
| 4793 | dcmd->sgl.sge32[0].length = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4794 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4795 | if ((instance->adapter_type != MFI_SERIES) && |
| 4796 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4797 | 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] | 4798 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4799 | ret = megasas_issue_polled(instance, cmd); |
| 4800 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4801 | if (ret == DCMD_TIMEOUT) { |
| 4802 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4803 | case INITIATE_OCR: |
| 4804 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4805 | megasas_reset_fusion(instance->host, |
| 4806 | MFI_IO_TIMEOUT_OCR); |
| 4807 | break; |
| 4808 | case KILL_ADAPTER: |
| 4809 | megaraid_sas_kill_hba(instance); |
| 4810 | break; |
| 4811 | case IGNORE_TIMEOUT: |
| 4812 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4813 | __func__, __LINE__); |
| 4814 | break; |
| 4815 | } |
| 4816 | } else |
| 4817 | megasas_return_cmd(instance, cmd); |
| 4818 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4819 | return ret; |
| 4820 | } |
| 4821 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4822 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4823 | * megasas_issue_init_mfi - Initializes the FW |
| 4824 | * @instance: Adapter soft state |
| 4825 | * |
| 4826 | * Issues the INIT MFI cmd |
| 4827 | */ |
| 4828 | static int |
| 4829 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 4830 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 4831 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4832 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4833 | struct megasas_init_frame *init_frame; |
| 4834 | struct megasas_init_queue_info *initq_info; |
| 4835 | dma_addr_t init_frame_h; |
| 4836 | dma_addr_t initq_info_h; |
| 4837 | |
| 4838 | /* |
| 4839 | * Prepare a init frame. Note the init frame points to queue info |
| 4840 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 4841 | * this frame - since we don't need any SGL - we use SGL's space as |
| 4842 | * queue info structure |
| 4843 | * |
| 4844 | * We will not get a NULL command below. We just created the pool. |
| 4845 | */ |
| 4846 | cmd = megasas_get_cmd(instance); |
| 4847 | |
| 4848 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 4849 | initq_info = (struct megasas_init_queue_info *) |
| 4850 | ((unsigned long)init_frame + 64); |
| 4851 | |
| 4852 | init_frame_h = cmd->frame_phys_addr; |
| 4853 | initq_info_h = init_frame_h + 64; |
| 4854 | |
| 4855 | context = init_frame->context; |
| 4856 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 4857 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 4858 | init_frame->context = context; |
| 4859 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4860 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 4861 | 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] | 4862 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4863 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 4864 | 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] | 4865 | |
| 4866 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4867 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4868 | init_frame->queue_info_new_phys_addr_lo = |
| 4869 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 4870 | init_frame->queue_info_new_phys_addr_hi = |
| 4871 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4872 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4873 | 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] | 4874 | |
| 4875 | /* |
| 4876 | * disable the intr before firing the init frame to FW |
| 4877 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4878 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4879 | |
| 4880 | /* |
| 4881 | * Issue the init frame in polled mode |
| 4882 | */ |
| 4883 | |
| 4884 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4885 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4886 | megasas_return_cmd(instance, cmd); |
| 4887 | goto fail_fw_init; |
| 4888 | } |
| 4889 | |
| 4890 | megasas_return_cmd(instance, cmd); |
| 4891 | |
| 4892 | return 0; |
| 4893 | |
| 4894 | fail_fw_init: |
| 4895 | return -EINVAL; |
| 4896 | } |
| 4897 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4898 | static u32 |
| 4899 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4900 | { |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4901 | struct megasas_register_set __iomem *reg_set; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4902 | u32 context_sz; |
| 4903 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4904 | |
| 4905 | reg_set = instance->reg_set; |
| 4906 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4907 | /* |
| 4908 | * Get various operational parameters from status register |
| 4909 | */ |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4910 | 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] | 4911 | /* |
| 4912 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 4913 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 4914 | * does not exceed max cmds that the FW can support |
| 4915 | */ |
| 4916 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4917 | instance->max_mfi_cmds = instance->max_fw_cmds; |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 4918 | 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] | 4919 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4920 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4921 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 4922 | * are reserved for IOCTL + driver's internal DCMDs. |
| 4923 | */ |
| 4924 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 4925 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 4926 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4927 | MEGASAS_SKINNY_INT_CMDS); |
| 4928 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 4929 | } else { |
| 4930 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 4931 | MEGASAS_INT_CMDS); |
| 4932 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 4933 | } |
| 4934 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 4935 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 4936 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4937 | * Create a pool of commands |
| 4938 | */ |
| 4939 | if (megasas_alloc_cmds(instance)) |
| 4940 | goto fail_alloc_cmds; |
| 4941 | |
| 4942 | /* |
| 4943 | * Allocate memory for reply queue. Length of reply queue should |
| 4944 | * be _one_ more than the maximum commands handled by the firmware. |
| 4945 | * |
| 4946 | * Note: When FW completes commands, it places corresponding contex |
| 4947 | * values in this circular reply queue. This circular queue is a fairly |
| 4948 | * typical producer-consumer queue. FW is the producer (of completed |
| 4949 | * commands) and the driver is the consumer. |
| 4950 | */ |
| 4951 | context_sz = sizeof(u32); |
| 4952 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 4953 | |
| 4954 | instance->reply_queue = pci_alloc_consistent(instance->pdev, |
| 4955 | reply_q_sz, |
| 4956 | &instance->reply_queue_h); |
| 4957 | |
| 4958 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4959 | 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] | 4960 | goto fail_reply_queue; |
| 4961 | } |
| 4962 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4963 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4964 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4965 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4966 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4967 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 4968 | "Fail from %s %d\n", instance->unique_id, |
| 4969 | __func__, __LINE__); |
| 4970 | goto fail_fw_init; |
| 4971 | } |
| 4972 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4973 | instance->fw_support_ieee = 0; |
| 4974 | instance->fw_support_ieee = |
| 4975 | (instance->instancet->read_fw_status_reg(reg_set) & |
| 4976 | 0x04000000); |
| 4977 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4978 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4979 | instance->fw_support_ieee); |
| 4980 | |
| 4981 | if (instance->fw_support_ieee) |
| 4982 | instance->flag_ieee = 1; |
| 4983 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4984 | return 0; |
| 4985 | |
| 4986 | fail_fw_init: |
| 4987 | |
| 4988 | pci_free_consistent(instance->pdev, reply_q_sz, |
| 4989 | instance->reply_queue, instance->reply_queue_h); |
| 4990 | fail_reply_queue: |
| 4991 | megasas_free_cmds(instance); |
| 4992 | |
| 4993 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4994 | return 1; |
| 4995 | } |
| 4996 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4997 | /* |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 4998 | * megasas_setup_irqs_ioapic - register legacy interrupts. |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 4999 | * @instance: Adapter soft state |
| 5000 | * |
| 5001 | * Do not enable interrupt, only setup ISRs. |
| 5002 | * |
| 5003 | * Return 0 on success. |
| 5004 | */ |
| 5005 | static int |
| 5006 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 5007 | { |
| 5008 | struct pci_dev *pdev; |
| 5009 | |
| 5010 | pdev = instance->pdev; |
| 5011 | instance->irq_context[0].instance = instance; |
| 5012 | instance->irq_context[0].MSIxIndex = 0; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5013 | if (request_irq(pci_irq_vector(pdev, 0), |
| 5014 | instance->instancet->service_isr, IRQF_SHARED, |
| 5015 | "megasas", &instance->irq_context[0])) { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5016 | dev_err(&instance->pdev->dev, |
| 5017 | "Failed to register IRQ from %s %d\n", |
| 5018 | __func__, __LINE__); |
| 5019 | return -1; |
| 5020 | } |
| 5021 | return 0; |
| 5022 | } |
| 5023 | |
| 5024 | /** |
| 5025 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 5026 | * @instance: Adapter soft state |
| 5027 | * @is_probe: Driver probe check |
| 5028 | * |
| 5029 | * Do not enable interrupt, only setup ISRs. |
| 5030 | * |
| 5031 | * Return 0 on success. |
| 5032 | */ |
| 5033 | static int |
| 5034 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 5035 | { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5036 | int i, j; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5037 | struct pci_dev *pdev; |
| 5038 | |
| 5039 | pdev = instance->pdev; |
| 5040 | |
| 5041 | /* Try MSI-x */ |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5042 | for (i = 0; i < instance->msix_vectors; i++) { |
| 5043 | instance->irq_context[i].instance = instance; |
| 5044 | instance->irq_context[i].MSIxIndex = i; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5045 | if (request_irq(pci_irq_vector(pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5046 | instance->instancet->service_isr, 0, "megasas", |
| 5047 | &instance->irq_context[i])) { |
| 5048 | dev_err(&instance->pdev->dev, |
| 5049 | "Failed to register IRQ for vector %d.\n", i); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5050 | for (j = 0; j < i; j++) |
| 5051 | free_irq(pci_irq_vector(pdev, j), |
| 5052 | &instance->irq_context[j]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5053 | /* Retry irq register for IO_APIC*/ |
| 5054 | instance->msix_vectors = 0; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5055 | if (is_probe) { |
| 5056 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5057 | return megasas_setup_irqs_ioapic(instance); |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5058 | } else { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5059 | return -1; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5060 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5061 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5062 | } |
| 5063 | return 0; |
| 5064 | } |
| 5065 | |
| 5066 | /* |
| 5067 | * megasas_destroy_irqs- unregister interrupts. |
| 5068 | * @instance: Adapter soft state |
| 5069 | * return: void |
| 5070 | */ |
| 5071 | static void |
| 5072 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 5073 | |
| 5074 | int i; |
| 5075 | |
| 5076 | if (instance->msix_vectors) |
| 5077 | for (i = 0; i < instance->msix_vectors; i++) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5078 | free_irq(pci_irq_vector(instance->pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5079 | &instance->irq_context[i]); |
| 5080 | } |
| 5081 | else |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5082 | free_irq(pci_irq_vector(instance->pdev, 0), |
| 5083 | &instance->irq_context[0]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5084 | } |
| 5085 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5086 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5087 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 5088 | * @instance: Adapter soft state |
| 5089 | * @is_probe: Driver probe check |
| 5090 | * |
| 5091 | * Return 0 on success. |
| 5092 | */ |
| 5093 | void |
| 5094 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 5095 | { |
| 5096 | int i; |
| 5097 | struct fusion_context *fusion = instance->ctrl_context; |
| 5098 | u32 pd_seq_map_sz; |
| 5099 | |
| 5100 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 5101 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 5102 | |
| 5103 | if (reset_devices || !fusion || |
| 5104 | !instance->ctrl_info->adapterOperations3.useSeqNumJbodFP) { |
| 5105 | dev_info(&instance->pdev->dev, |
| 5106 | "Jbod map is not supported %s %d\n", |
| 5107 | __func__, __LINE__); |
| 5108 | instance->use_seqnum_jbod_fp = false; |
| 5109 | return; |
| 5110 | } |
| 5111 | |
| 5112 | if (fusion->pd_seq_sync[0]) |
| 5113 | goto skip_alloc; |
| 5114 | |
| 5115 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 5116 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 5117 | (&instance->pdev->dev, pd_seq_map_sz, |
| 5118 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 5119 | if (!fusion->pd_seq_sync[i]) { |
| 5120 | dev_err(&instance->pdev->dev, |
| 5121 | "Failed to allocate memory from %s %d\n", |
| 5122 | __func__, __LINE__); |
| 5123 | if (i == 1) { |
| 5124 | dma_free_coherent(&instance->pdev->dev, |
| 5125 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 5126 | fusion->pd_seq_phys[0]); |
| 5127 | fusion->pd_seq_sync[0] = NULL; |
| 5128 | } |
| 5129 | instance->use_seqnum_jbod_fp = false; |
| 5130 | return; |
| 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | skip_alloc: |
| 5135 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 5136 | !megasas_sync_pd_seq_num(instance, true)) |
| 5137 | instance->use_seqnum_jbod_fp = true; |
| 5138 | else |
| 5139 | instance->use_seqnum_jbod_fp = false; |
| 5140 | } |
| 5141 | |
| 5142 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5143 | * megasas_init_fw - Initializes the FW |
| 5144 | * @instance: Adapter soft state |
| 5145 | * |
| 5146 | * This is the main function for initializing firmware |
| 5147 | */ |
| 5148 | |
| 5149 | static int megasas_init_fw(struct megasas_instance *instance) |
| 5150 | { |
| 5151 | u32 max_sectors_1; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5152 | u32 max_sectors_2, tmp_sectors, msix_enable; |
| 5153 | u32 scratch_pad_2, scratch_pad_3, scratch_pad_4; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5154 | resource_size_t base_addr; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5155 | struct megasas_register_set __iomem *reg_set; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5156 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5157 | unsigned long bar_list; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5158 | int i, j, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5159 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5160 | struct fusion_context *fusion; |
| 5161 | |
| 5162 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5163 | |
| 5164 | /* Find first memory bar */ |
| 5165 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
Christophe JAILLET | 51f9039 | 2016-08-21 10:28:25 +0200 | [diff] [blame] | 5166 | instance->bar = find_first_bit(&bar_list, BITS_PER_LONG); |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5167 | if (pci_request_selected_regions(instance->pdev, 1<<instance->bar, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5168 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5169 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5170 | return -EBUSY; |
| 5171 | } |
| 5172 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5173 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 5174 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5175 | |
| 5176 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5177 | 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] | 5178 | goto fail_ioremap; |
| 5179 | } |
| 5180 | |
| 5181 | reg_set = instance->reg_set; |
| 5182 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5183 | if (instance->adapter_type != MFI_SERIES) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5184 | instance->instancet = &megasas_instance_template_fusion; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5185 | else { |
| 5186 | switch (instance->pdev->device) { |
| 5187 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 5188 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 5189 | instance->instancet = &megasas_instance_template_ppc; |
| 5190 | break; |
| 5191 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 5192 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 5193 | instance->instancet = &megasas_instance_template_gen2; |
| 5194 | break; |
| 5195 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 5196 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 5197 | instance->instancet = &megasas_instance_template_skinny; |
| 5198 | break; |
| 5199 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 5200 | case PCI_DEVICE_ID_DELL_PERC5: |
| 5201 | default: |
| 5202 | instance->instancet = &megasas_instance_template_xscale; |
| 5203 | instance->pd_list_not_supported = 1; |
| 5204 | break; |
| 5205 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5206 | } |
| 5207 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5208 | if (megasas_transition_to_ready(instance, 0)) { |
| 5209 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 5210 | instance->instancet->adp_reset |
| 5211 | (instance, instance->reg_set); |
| 5212 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
| 5213 | dev_info(&instance->pdev->dev, |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5214 | "FW restarted successfully from %s!\n", |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5215 | __func__); |
| 5216 | |
| 5217 | /*waitting for about 30 second before retry*/ |
| 5218 | ssleep(30); |
| 5219 | |
| 5220 | if (megasas_transition_to_ready(instance, 0)) |
| 5221 | goto fail_ready_state; |
| 5222 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5223 | |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame^] | 5224 | if (instance->adapter_type == VENTURA_SERIES) { |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5225 | scratch_pad_3 = |
| 5226 | readl(&instance->reg_set->outbound_scratch_pad_3); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5227 | instance->max_raid_mapsize = ((scratch_pad_3 >> |
| 5228 | MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) & |
| 5229 | MR_MAX_RAID_MAP_SIZE_MASK); |
| 5230 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5231 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5232 | /* Check if MSI-X is supported while in ready state */ |
| 5233 | msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & |
| 5234 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5235 | if (msix_enable && !msix_disable) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5236 | int irq_flags = PCI_IRQ_MSIX; |
| 5237 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5238 | scratch_pad_2 = readl |
| 5239 | (&instance->reg_set->outbound_scratch_pad_2); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5240 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5241 | if (fusion) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 5242 | if (instance->adapter_type == THUNDERBOLT_SERIES) { |
| 5243 | /* Thunderbolt Series*/ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5244 | instance->msix_vectors = (scratch_pad_2 |
| 5245 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 5246 | fw_msix_count = instance->msix_vectors; |
| 5247 | } else { /* Invader series supports more than 8 MSI-x vectors*/ |
| 5248 | instance->msix_vectors = ((scratch_pad_2 |
| 5249 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 5250 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5251 | if (instance->msix_vectors > 16) |
| 5252 | instance->msix_combined = true; |
| 5253 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5254 | if (rdpq_enable) |
| 5255 | instance->is_rdpq = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ? |
| 5256 | 1 : 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5257 | fw_msix_count = instance->msix_vectors; |
| 5258 | /* Save 1-15 reply post index address to local memory |
| 5259 | * Index 0 is already saved from reg offset |
| 5260 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 5261 | */ |
| 5262 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 5263 | instance->reply_post_host_index_addr[loop] = |
| 5264 | (u32 __iomem *) |
| 5265 | ((u8 __iomem *)instance->reg_set + |
| 5266 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 5267 | + (loop * 0x10)); |
| 5268 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5269 | } |
| 5270 | if (msix_vectors) |
| 5271 | instance->msix_vectors = min(msix_vectors, |
| 5272 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5273 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5274 | instance->msix_vectors = 1; |
| 5275 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 5276 | instance->msix_vectors = min(instance->msix_vectors, |
| 5277 | (unsigned int)num_online_cpus()); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5278 | if (smp_affinity_enable) |
| 5279 | irq_flags |= PCI_IRQ_AFFINITY; |
| 5280 | i = pci_alloc_irq_vectors(instance->pdev, 1, |
| 5281 | instance->msix_vectors, irq_flags); |
Jiang Liu | c12de88 | 2014-11-03 20:44:20 +0800 | [diff] [blame] | 5282 | if (i > 0) |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5283 | instance->msix_vectors = i; |
| 5284 | else |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5285 | instance->msix_vectors = 0; |
| 5286 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5287 | /* |
| 5288 | * MSI-X host index 0 is common for all adapter. |
| 5289 | * It is used for all MPT based Adapters. |
| 5290 | */ |
| 5291 | if (instance->msix_combined) { |
| 5292 | instance->reply_post_host_index_addr[0] = |
| 5293 | (u32 *)((u8 *)instance->reg_set + |
| 5294 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET); |
| 5295 | } else { |
| 5296 | instance->reply_post_host_index_addr[0] = |
| 5297 | (u32 *)((u8 *)instance->reg_set + |
| 5298 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 5299 | } |
| 5300 | |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5301 | if (!instance->msix_vectors) { |
| 5302 | i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 5303 | if (i < 0) |
| 5304 | goto fail_setup_irqs; |
| 5305 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5306 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5307 | dev_info(&instance->pdev->dev, |
| 5308 | "firmware supports msix\t: (%d)", fw_msix_count); |
| 5309 | dev_info(&instance->pdev->dev, |
| 5310 | "current msix/online cpus\t: (%d/%d)\n", |
| 5311 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5312 | dev_info(&instance->pdev->dev, |
| 5313 | "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5314 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 5315 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5316 | (unsigned long)instance); |
| 5317 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5318 | instance->ctrl_info = kzalloc(sizeof(struct megasas_ctrl_info), |
| 5319 | GFP_KERNEL); |
| 5320 | if (instance->ctrl_info == NULL) |
| 5321 | goto fail_init_adapter; |
| 5322 | |
| 5323 | /* |
| 5324 | * Below are default value for legacy Firmware. |
| 5325 | * non-fusion based controllers |
| 5326 | */ |
| 5327 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 5328 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5329 | /* Get operational params, sge flags, send init cmd to controller */ |
| 5330 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5331 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5332 | |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame^] | 5333 | if (instance->adapter_type == VENTURA_SERIES) { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5334 | scratch_pad_4 = |
| 5335 | readl(&instance->reg_set->outbound_scratch_pad_4); |
| 5336 | if ((scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK) >= |
| 5337 | MR_DEFAULT_NVME_PAGE_SHIFT) |
| 5338 | instance->nvme_page_size = |
| 5339 | (1 << (scratch_pad_4 & MR_NVME_PAGE_SIZE_MASK)); |
| 5340 | |
| 5341 | dev_info(&instance->pdev->dev, |
| 5342 | "NVME page size\t: (%d)\n", instance->nvme_page_size); |
| 5343 | } |
| 5344 | |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5345 | if (instance->msix_vectors ? |
| 5346 | megasas_setup_irqs_msix(instance, 1) : |
| 5347 | megasas_setup_irqs_ioapic(instance)) |
| 5348 | goto fail_init_adapter; |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5349 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5350 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5351 | |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 5352 | dev_info(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5353 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5354 | megasas_setup_jbod_map(instance); |
| 5355 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5356 | /** for passthrough |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5357 | * the following function will get the PD LIST. |
| 5358 | */ |
| 5359 | memset(instance->pd_list, 0, |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5360 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5361 | if (megasas_get_pd_list(instance) < 0) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5362 | dev_err(&instance->pdev->dev, "failed to get PD list\n"); |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5363 | goto fail_get_ld_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5364 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5365 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5366 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5367 | |
| 5368 | /* stream detection initialization */ |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame^] | 5369 | if (instance->adapter_type == VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5370 | fusion->stream_detect_by_ld = |
Shivasharan S | 41064f1 | 2017-02-10 00:59:37 -0800 | [diff] [blame] | 5371 | kzalloc(sizeof(struct LD_STREAM_DETECT *) |
| 5372 | * MAX_LOGICAL_DRIVES_EXT, |
| 5373 | GFP_KERNEL); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5374 | if (!fusion->stream_detect_by_ld) { |
| 5375 | dev_err(&instance->pdev->dev, |
Shivasharan S | 41064f1 | 2017-02-10 00:59:37 -0800 | [diff] [blame] | 5376 | "unable to allocate stream detection for pool of LDs\n"); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5377 | goto fail_get_ld_pd_list; |
| 5378 | } |
| 5379 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) { |
| 5380 | fusion->stream_detect_by_ld[i] = |
| 5381 | kmalloc(sizeof(struct LD_STREAM_DETECT), |
| 5382 | GFP_KERNEL); |
| 5383 | if (!fusion->stream_detect_by_ld[i]) { |
| 5384 | dev_err(&instance->pdev->dev, |
| 5385 | "unable to allocate stream detect by LD\n "); |
| 5386 | for (j = 0; j < i; ++j) |
| 5387 | kfree(fusion->stream_detect_by_ld[j]); |
| 5388 | kfree(fusion->stream_detect_by_ld); |
| 5389 | fusion->stream_detect_by_ld = NULL; |
| 5390 | goto fail_get_ld_pd_list; |
| 5391 | } |
| 5392 | fusion->stream_detect_by_ld[i]->mru_bit_map |
| 5393 | = MR_STREAM_BITMAP; |
| 5394 | } |
| 5395 | } |
| 5396 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 5397 | if (megasas_ld_list_query(instance, |
| 5398 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5399 | goto fail_get_ld_pd_list; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 5400 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5401 | /* |
| 5402 | * Compute the max allowed sectors per IO: The controller info has two |
| 5403 | * limits on max sectors. Driver should use the minimum of these two. |
| 5404 | * |
| 5405 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 5406 | * |
| 5407 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 5408 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 5409 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5410 | tmp_sectors = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5411 | ctrl_info = instance->ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5412 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5413 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 5414 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 5415 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5416 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5417 | 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] | 5418 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 5419 | instance->peerIsPresent = ctrl_info->cluster.peerIsPresent; |
| 5420 | instance->passive = ctrl_info->cluster.passive; |
| 5421 | memcpy(instance->clusterId, ctrl_info->clusterId, sizeof(instance->clusterId)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5422 | instance->UnevenSpanSupport = |
| 5423 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 5424 | if (instance->UnevenSpanSupport) { |
| 5425 | struct fusion_context *fusion = instance->ctrl_context; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5426 | if (MR_ValidateMapInfo(instance)) |
| 5427 | fusion->fast_path_io = 1; |
| 5428 | else |
| 5429 | fusion->fast_path_io = 0; |
| 5430 | |
| 5431 | } |
| 5432 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5433 | instance->requestorId = ctrl_info->iov.requestorId; |
| 5434 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 5435 | if (!ctrl_info->adapterOperations2.activePassive) |
| 5436 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5437 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5438 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 5439 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 5440 | |
| 5441 | if (instance->PlasmaFW111) { |
| 5442 | iovPtr = (struct IOV_111 *) |
| 5443 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 5444 | instance->requestorId = iovPtr->requestorId; |
| 5445 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5446 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5447 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 5448 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5449 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5450 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5451 | instance->crash_dump_fw_support = |
| 5452 | ctrl_info->adapterOperations3.supportCrashDump; |
| 5453 | instance->crash_dump_drv_support = |
| 5454 | (instance->crash_dump_fw_support && |
| 5455 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5456 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5457 | megasas_set_crash_dump_params(instance, |
| 5458 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5459 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5460 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5461 | if (instance->crash_dump_buf) |
| 5462 | pci_free_consistent(instance->pdev, |
| 5463 | CRASH_DMA_BUF_SIZE, |
| 5464 | instance->crash_dump_buf, |
| 5465 | instance->crash_dump_h); |
| 5466 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5467 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 5468 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5469 | |
| 5470 | dev_info(&instance->pdev->dev, |
| 5471 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 5472 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 5473 | le16_to_cpu(ctrl_info->pci.device_id), |
| 5474 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 5475 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 5476 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 5477 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5478 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 5479 | instance->crash_dump_drv_support ? "yes" : "no"); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5480 | dev_info(&instance->pdev->dev, "jbod sync map : %s\n", |
| 5481 | instance->use_seqnum_jbod_fp ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5482 | |
| 5483 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5484 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 5485 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5486 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 5487 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5488 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5489 | /* Check for valid throttlequeuedepth module parameter */ |
| 5490 | if (throttlequeuedepth && |
| 5491 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 5492 | instance->throttlequeuedepth = throttlequeuedepth; |
| 5493 | else |
| 5494 | instance->throttlequeuedepth = |
| 5495 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 5496 | |
Shivasharan S | e636a7a | 2017-08-23 04:46:56 -0700 | [diff] [blame] | 5497 | if ((resetwaittime < 1) || |
| 5498 | (resetwaittime > MEGASAS_RESET_WAIT_TIME)) |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 5499 | resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 5500 | |
| 5501 | if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT)) |
| 5502 | scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5503 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5504 | /* Launch SR-IOV heartbeat timer */ |
| 5505 | if (instance->requestorId) { |
| 5506 | if (!megasas_sriov_start_heartbeat(instance, 1)) |
| 5507 | megasas_start_timer(instance, |
| 5508 | &instance->sriov_heartbeat_timer, |
| 5509 | megasas_sriov_heartbeat_handler, |
| 5510 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 5511 | else |
| 5512 | instance->skip_heartbeat_timer_del = 1; |
| 5513 | } |
| 5514 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5515 | return 0; |
| 5516 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5517 | fail_get_ld_pd_list: |
| 5518 | instance->instancet->disable_intr(instance); |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5519 | fail_init_adapter: |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5520 | megasas_destroy_irqs(instance); |
| 5521 | fail_setup_irqs: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5522 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5523 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5524 | instance->msix_vectors = 0; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5525 | fail_ready_state: |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5526 | kfree(instance->ctrl_info); |
| 5527 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5528 | iounmap(instance->reg_set); |
| 5529 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5530 | fail_ioremap: |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5531 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5532 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5533 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 5534 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5535 | return -EINVAL; |
| 5536 | } |
| 5537 | |
| 5538 | /** |
| 5539 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 5540 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5541 | */ |
| 5542 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 5543 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5544 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5545 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5546 | if (instance->reply_queue) |
| 5547 | pci_free_consistent(instance->pdev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5548 | instance->reply_queue, instance->reply_queue_h); |
| 5549 | |
| 5550 | megasas_free_cmds(instance); |
| 5551 | |
| 5552 | iounmap(instance->reg_set); |
| 5553 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5554 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5555 | } |
| 5556 | |
| 5557 | /** |
| 5558 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 5559 | * @instance: Adapter soft state |
| 5560 | * @eli: FW event log sequence numbers information |
| 5561 | * |
| 5562 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 5563 | * usually find out the latest sequence number of the events, the seq number at |
| 5564 | * the boot etc. They would "read" all the events below the latest seq number |
| 5565 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 5566 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 5567 | * wait for the events to happen. |
| 5568 | */ |
| 5569 | static int |
| 5570 | megasas_get_seq_num(struct megasas_instance *instance, |
| 5571 | struct megasas_evt_log_info *eli) |
| 5572 | { |
| 5573 | struct megasas_cmd *cmd; |
| 5574 | struct megasas_dcmd_frame *dcmd; |
| 5575 | struct megasas_evt_log_info *el_info; |
| 5576 | dma_addr_t el_info_h = 0; |
| 5577 | |
| 5578 | cmd = megasas_get_cmd(instance); |
| 5579 | |
| 5580 | if (!cmd) { |
| 5581 | return -ENOMEM; |
| 5582 | } |
| 5583 | |
| 5584 | dcmd = &cmd->frame->dcmd; |
| 5585 | el_info = pci_alloc_consistent(instance->pdev, |
| 5586 | sizeof(struct megasas_evt_log_info), |
| 5587 | &el_info_h); |
| 5588 | |
| 5589 | if (!el_info) { |
| 5590 | megasas_return_cmd(instance, cmd); |
| 5591 | return -ENOMEM; |
| 5592 | } |
| 5593 | |
| 5594 | memset(el_info, 0, sizeof(*el_info)); |
| 5595 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5596 | |
| 5597 | dcmd->cmd = MFI_CMD_DCMD; |
| 5598 | dcmd->cmd_status = 0x0; |
| 5599 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5600 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5601 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5602 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5603 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 5604 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
| 5605 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(el_info_h); |
| 5606 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5607 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5608 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) == |
| 5609 | DCMD_SUCCESS) { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5610 | /* |
| 5611 | * Copy the data back into callers buffer |
| 5612 | */ |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5613 | eli->newest_seq_num = el_info->newest_seq_num; |
| 5614 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 5615 | eli->clear_seq_num = el_info->clear_seq_num; |
| 5616 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 5617 | eli->boot_seq_num = el_info->boot_seq_num; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5618 | } else |
| 5619 | dev_err(&instance->pdev->dev, "DCMD failed " |
| 5620 | "from %s\n", __func__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5621 | |
| 5622 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), |
| 5623 | el_info, el_info_h); |
| 5624 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5625 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5626 | |
| 5627 | return 0; |
| 5628 | } |
| 5629 | |
| 5630 | /** |
| 5631 | * megasas_register_aen - Registers for asynchronous event notification |
| 5632 | * @instance: Adapter soft state |
| 5633 | * @seq_num: The starting sequence number |
| 5634 | * @class_locale: Class of the event |
| 5635 | * |
| 5636 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 5637 | * to be notified if and only if the event is of type @class_locale |
| 5638 | */ |
| 5639 | static int |
| 5640 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 5641 | u32 class_locale_word) |
| 5642 | { |
| 5643 | int ret_val; |
| 5644 | struct megasas_cmd *cmd; |
| 5645 | struct megasas_dcmd_frame *dcmd; |
| 5646 | union megasas_evt_class_locale curr_aen; |
| 5647 | union megasas_evt_class_locale prev_aen; |
| 5648 | |
| 5649 | /* |
| 5650 | * If there an AEN pending already (aen_cmd), check if the |
| 5651 | * class_locale of that pending AEN is inclusive of the new |
| 5652 | * AEN request we currently have. If it is, then we don't have |
| 5653 | * to do anything. In other words, whichever events the current |
| 5654 | * AEN request is subscribing to, have already been subscribed |
| 5655 | * to. |
| 5656 | * |
| 5657 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 5658 | * that command, form a class_locale that is superset of both |
| 5659 | * old and current and re-issue to the FW |
| 5660 | */ |
| 5661 | |
| 5662 | curr_aen.word = class_locale_word; |
| 5663 | |
| 5664 | if (instance->aen_cmd) { |
| 5665 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 5666 | prev_aen.word = |
| 5667 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5668 | |
Shivasharan S | 91b3d9f | 2017-08-23 04:47:01 -0700 | [diff] [blame] | 5669 | if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) || |
| 5670 | (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) { |
| 5671 | dev_info(&instance->pdev->dev, |
| 5672 | "%s %d out of range class %d send by application\n", |
| 5673 | __func__, __LINE__, curr_aen.members.class); |
| 5674 | return 0; |
| 5675 | } |
| 5676 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5677 | /* |
| 5678 | * A class whose enum value is smaller is inclusive of all |
| 5679 | * higher values. If a PROGRESS (= -1) was previously |
| 5680 | * registered, then a new registration requests for higher |
| 5681 | * classes need not be sent to FW. They are automatically |
| 5682 | * included. |
| 5683 | * |
| 5684 | * Locale numbers don't have such hierarchy. They are bitmap |
| 5685 | * values |
| 5686 | */ |
| 5687 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5688 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5689 | curr_aen.members.locale)) { |
| 5690 | /* |
| 5691 | * Previously issued event registration includes |
| 5692 | * current request. Nothing to do. |
| 5693 | */ |
| 5694 | return 0; |
| 5695 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 5696 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5697 | |
| 5698 | if (prev_aen.members.class < curr_aen.members.class) |
| 5699 | curr_aen.members.class = prev_aen.members.class; |
| 5700 | |
| 5701 | instance->aen_cmd->abort_aen = 1; |
| 5702 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 5703 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5704 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5705 | |
| 5706 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5707 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5708 | "previous AEN command\n"); |
| 5709 | return ret_val; |
| 5710 | } |
| 5711 | } |
| 5712 | } |
| 5713 | |
| 5714 | cmd = megasas_get_cmd(instance); |
| 5715 | |
| 5716 | if (!cmd) |
| 5717 | return -ENOMEM; |
| 5718 | |
| 5719 | dcmd = &cmd->frame->dcmd; |
| 5720 | |
| 5721 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 5722 | |
| 5723 | /* |
| 5724 | * Prepare DCMD for aen registration |
| 5725 | */ |
| 5726 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5727 | |
| 5728 | dcmd->cmd = MFI_CMD_DCMD; |
| 5729 | dcmd->cmd_status = 0x0; |
| 5730 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5731 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5732 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5733 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5734 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 5735 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 5736 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5737 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5738 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
| 5739 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->evt_detail_h); |
| 5740 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5741 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5742 | if (instance->aen_cmd != NULL) { |
| 5743 | megasas_return_cmd(instance, cmd); |
| 5744 | return 0; |
| 5745 | } |
| 5746 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5747 | /* |
| 5748 | * Store reference to the cmd used to register for AEN. When an |
| 5749 | * application wants us to register for AEN, we have to abort this |
| 5750 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 5751 | */ |
| 5752 | instance->aen_cmd = cmd; |
| 5753 | |
| 5754 | /* |
| 5755 | * Issue the aen registration frame |
| 5756 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5757 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5758 | |
| 5759 | return 0; |
| 5760 | } |
| 5761 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5762 | /* megasas_get_target_prop - Send DCMD with below details to firmware. |
| 5763 | * |
| 5764 | * This DCMD will fetch few properties of LD/system PD defined |
| 5765 | * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value. |
| 5766 | * |
| 5767 | * DCMD send by drivers whenever new target is added to the OS. |
| 5768 | * |
| 5769 | * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP |
| 5770 | * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD. |
| 5771 | * 0 = system PD, 1 = LD. |
| 5772 | * dcmd.mbox.s[1] - TargetID for LD/system PD. |
| 5773 | * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES. |
| 5774 | * |
| 5775 | * @instance: Adapter soft state |
| 5776 | * @sdev: OS provided scsi device |
| 5777 | * |
| 5778 | * Returns 0 on success non-zero on failure. |
| 5779 | */ |
| 5780 | static int |
| 5781 | megasas_get_target_prop(struct megasas_instance *instance, |
| 5782 | struct scsi_device *sdev) |
| 5783 | { |
| 5784 | int ret; |
| 5785 | struct megasas_cmd *cmd; |
| 5786 | struct megasas_dcmd_frame *dcmd; |
| 5787 | u16 targetId = (sdev->channel % 2) + sdev->id; |
| 5788 | |
| 5789 | cmd = megasas_get_cmd(instance); |
| 5790 | |
| 5791 | if (!cmd) { |
| 5792 | dev_err(&instance->pdev->dev, |
| 5793 | "Failed to get cmd %s\n", __func__); |
| 5794 | return -ENOMEM; |
| 5795 | } |
| 5796 | |
| 5797 | dcmd = &cmd->frame->dcmd; |
| 5798 | |
| 5799 | memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop)); |
| 5800 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5801 | dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev); |
| 5802 | |
| 5803 | dcmd->mbox.s[1] = cpu_to_le16(targetId); |
| 5804 | dcmd->cmd = MFI_CMD_DCMD; |
| 5805 | dcmd->cmd_status = 0xFF; |
| 5806 | dcmd->sge_count = 1; |
| 5807 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
| 5808 | dcmd->timeout = 0; |
| 5809 | dcmd->pad_0 = 0; |
| 5810 | dcmd->data_xfer_len = |
| 5811 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 5812 | dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP); |
| 5813 | dcmd->sgl.sge32[0].phys_addr = |
| 5814 | cpu_to_le32(instance->tgt_prop_h); |
| 5815 | dcmd->sgl.sge32[0].length = |
| 5816 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 5817 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5818 | if ((instance->adapter_type != MFI_SERIES) && |
| 5819 | !instance->mask_interrupts) |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 5820 | ret = megasas_issue_blocked_cmd(instance, |
| 5821 | cmd, MFI_IO_TIMEOUT_SECS); |
| 5822 | else |
| 5823 | ret = megasas_issue_polled(instance, cmd); |
| 5824 | |
| 5825 | switch (ret) { |
| 5826 | case DCMD_TIMEOUT: |
| 5827 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5828 | case INITIATE_OCR: |
| 5829 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5830 | megasas_reset_fusion(instance->host, |
| 5831 | MFI_IO_TIMEOUT_OCR); |
| 5832 | break; |
| 5833 | case KILL_ADAPTER: |
| 5834 | megaraid_sas_kill_hba(instance); |
| 5835 | break; |
| 5836 | case IGNORE_TIMEOUT: |
| 5837 | dev_info(&instance->pdev->dev, |
| 5838 | "Ignore DCMD timeout: %s %d\n", |
| 5839 | __func__, __LINE__); |
| 5840 | break; |
| 5841 | } |
| 5842 | break; |
| 5843 | |
| 5844 | default: |
| 5845 | megasas_return_cmd(instance, cmd); |
| 5846 | } |
| 5847 | if (ret != DCMD_SUCCESS) |
| 5848 | dev_err(&instance->pdev->dev, |
| 5849 | "return from %s %d return value %d\n", |
| 5850 | __func__, __LINE__, ret); |
| 5851 | |
| 5852 | return ret; |
| 5853 | } |
| 5854 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5855 | /** |
| 5856 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 5857 | * @instance: Adapter soft state |
| 5858 | */ |
| 5859 | static int megasas_start_aen(struct megasas_instance *instance) |
| 5860 | { |
| 5861 | struct megasas_evt_log_info eli; |
| 5862 | union megasas_evt_class_locale class_locale; |
| 5863 | |
| 5864 | /* |
| 5865 | * Get the latest sequence number from FW |
| 5866 | */ |
| 5867 | memset(&eli, 0, sizeof(eli)); |
| 5868 | |
| 5869 | if (megasas_get_seq_num(instance, &eli)) |
| 5870 | return -1; |
| 5871 | |
| 5872 | /* |
| 5873 | * Register AEN with FW for latest sequence number plus 1 |
| 5874 | */ |
| 5875 | class_locale.members.reserved = 0; |
| 5876 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 5877 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 5878 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5879 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 5880 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5881 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5882 | } |
| 5883 | |
| 5884 | /** |
| 5885 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 5886 | * @instance: Adapter soft state |
| 5887 | */ |
| 5888 | static int megasas_io_attach(struct megasas_instance *instance) |
| 5889 | { |
| 5890 | struct Scsi_Host *host = instance->host; |
| 5891 | |
| 5892 | /* |
| 5893 | * Export parameters required by SCSI mid-layer |
| 5894 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5895 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5896 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5897 | host->this_id = instance->init_id; |
| 5898 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 5899 | |
| 5900 | if (instance->fw_support_ieee) |
| 5901 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 5902 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5903 | /* |
| 5904 | * Check if the module parameter value for max_sectors can be used |
| 5905 | */ |
| 5906 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 5907 | instance->max_sectors_per_req = max_sectors; |
| 5908 | else { |
| 5909 | if (max_sectors) { |
| 5910 | if (((instance->pdev->device == |
| 5911 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 5912 | (instance->pdev->device == |
| 5913 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 5914 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 5915 | instance->max_sectors_per_req = max_sectors; |
| 5916 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5917 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 5918 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 5919 | instance->max_sectors_per_req); |
| 5920 | } |
| 5921 | } |
| 5922 | } |
| 5923 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5924 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5925 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5926 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 5927 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5928 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 5929 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5930 | |
| 5931 | /* |
| 5932 | * Notify the mid-layer about the new controller |
| 5933 | */ |
| 5934 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5935 | dev_err(&instance->pdev->dev, |
| 5936 | "Failed to add host from %s %d\n", |
| 5937 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5938 | return -ENODEV; |
| 5939 | } |
| 5940 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5941 | return 0; |
| 5942 | } |
| 5943 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5944 | static int |
| 5945 | megasas_set_dma_mask(struct pci_dev *pdev) |
| 5946 | { |
| 5947 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5948 | * All our controllers are capable of performing 64-bit DMA |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5949 | */ |
| 5950 | if (IS_DMA64) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5951 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5952 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5953 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5954 | goto fail_set_dma_mask; |
| 5955 | } |
| 5956 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5957 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5958 | goto fail_set_dma_mask; |
| 5959 | } |
Sumit.Saxena@lsi.com | 46de63e2 | 2014-02-12 23:38:44 +0530 | [diff] [blame] | 5960 | /* |
| 5961 | * Ensure that all data structures are allocated in 32-bit |
| 5962 | * memory. |
| 5963 | */ |
| 5964 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { |
| 5965 | /* Try 32bit DMA mask and 32 bit Consistent dma mask */ |
| 5966 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 5967 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 5968 | dev_info(&pdev->dev, "set 32bit DMA mask" |
| 5969 | "and 32 bit consistent mask\n"); |
| 5970 | else |
| 5971 | goto fail_set_dma_mask; |
| 5972 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5973 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5974 | return 0; |
| 5975 | |
| 5976 | fail_set_dma_mask: |
| 5977 | return 1; |
| 5978 | } |
| 5979 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 5980 | /* |
| 5981 | * megasas_set_adapter_type - Set adapter type. |
| 5982 | * Supported controllers can be divided in |
| 5983 | * 4 categories- enum MR_ADAPTER_TYPE { |
| 5984 | * MFI_SERIES = 1, |
| 5985 | * THUNDERBOLT_SERIES = 2, |
| 5986 | * INVADER_SERIES = 3, |
| 5987 | * VENTURA_SERIES = 4, |
| 5988 | * }; |
| 5989 | * @instance: Adapter soft state |
| 5990 | * return: void |
| 5991 | */ |
| 5992 | static inline void megasas_set_adapter_type(struct megasas_instance *instance) |
| 5993 | { |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 5994 | if ((instance->pdev->vendor == PCI_VENDOR_ID_DELL) && |
| 5995 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5)) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 5996 | instance->adapter_type = MFI_SERIES; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 5997 | } else { |
| 5998 | switch (instance->pdev->device) { |
| 5999 | case PCI_DEVICE_ID_LSI_VENTURA: |
| 6000 | case PCI_DEVICE_ID_LSI_CRUSADER: |
| 6001 | case PCI_DEVICE_ID_LSI_HARPOON: |
| 6002 | case PCI_DEVICE_ID_LSI_TOMCAT: |
| 6003 | case PCI_DEVICE_ID_LSI_VENTURA_4PORT: |
| 6004 | case PCI_DEVICE_ID_LSI_CRUSADER_4PORT: |
| 6005 | instance->adapter_type = VENTURA_SERIES; |
| 6006 | break; |
| 6007 | case PCI_DEVICE_ID_LSI_FUSION: |
| 6008 | case PCI_DEVICE_ID_LSI_PLASMA: |
| 6009 | instance->adapter_type = THUNDERBOLT_SERIES; |
| 6010 | break; |
| 6011 | case PCI_DEVICE_ID_LSI_INVADER: |
| 6012 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 6013 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
| 6014 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 6015 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
| 6016 | case PCI_DEVICE_ID_LSI_FURY: |
| 6017 | instance->adapter_type = INVADER_SERIES; |
| 6018 | break; |
| 6019 | default: /* For all other supported controllers */ |
| 6020 | instance->adapter_type = MFI_SERIES; |
| 6021 | break; |
| 6022 | } |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6023 | } |
| 6024 | } |
| 6025 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6026 | /** |
| 6027 | * megasas_probe_one - PCI hotplug entry point |
| 6028 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 6029 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6030 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6031 | static int megasas_probe_one(struct pci_dev *pdev, |
| 6032 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6033 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6034 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6035 | struct Scsi_Host *host; |
| 6036 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6037 | u16 control = 0; |
| 6038 | |
| 6039 | /* Reset MSI-X in the kdump kernel */ |
| 6040 | if (reset_devices) { |
| 6041 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 6042 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6043 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6044 | &control); |
| 6045 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 6046 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 6047 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6048 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6049 | control & |
| 6050 | ~PCI_MSIX_FLAGS_ENABLE); |
| 6051 | } |
| 6052 | } |
| 6053 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6054 | |
| 6055 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6056 | * PCI prepping: enable device set bus mastering and dma mask |
| 6057 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6058 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6059 | |
| 6060 | if (rval) { |
| 6061 | return rval; |
| 6062 | } |
| 6063 | |
| 6064 | pci_set_master(pdev); |
| 6065 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6066 | if (megasas_set_dma_mask(pdev)) |
| 6067 | goto fail_set_dma_mask; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6068 | |
| 6069 | host = scsi_host_alloc(&megasas_template, |
| 6070 | sizeof(struct megasas_instance)); |
| 6071 | |
| 6072 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6073 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6074 | goto fail_alloc_instance; |
| 6075 | } |
| 6076 | |
| 6077 | instance = (struct megasas_instance *)host->hostdata; |
| 6078 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6079 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6080 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6081 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6082 | megasas_set_adapter_type(instance); |
Shivasharan S | 5fc499b | 2017-02-10 00:59:17 -0800 | [diff] [blame] | 6083 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6084 | switch (instance->adapter_type) { |
| 6085 | case MFI_SERIES: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6086 | instance->producer = |
| 6087 | pci_alloc_consistent(pdev, sizeof(u32), |
| 6088 | &instance->producer_h); |
| 6089 | instance->consumer = |
| 6090 | pci_alloc_consistent(pdev, sizeof(u32), |
| 6091 | &instance->consumer_h); |
| 6092 | |
| 6093 | if (!instance->producer || !instance->consumer) { |
Colin Ian King | 4086eae5 | 2016-09-12 13:42:12 +0100 | [diff] [blame] | 6094 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6095 | "memory for producer, consumer\n"); |
| 6096 | goto fail_alloc_dma_buf; |
| 6097 | } |
| 6098 | |
| 6099 | *instance->producer = 0; |
| 6100 | *instance->consumer = 0; |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6101 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6102 | break; |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6103 | case VENTURA_SERIES: |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6104 | case THUNDERBOLT_SERIES: |
| 6105 | case INVADER_SERIES: |
| 6106 | if (megasas_alloc_fusion_context(instance)) { |
| 6107 | megasas_free_fusion_context(instance); |
| 6108 | goto fail_alloc_dma_buf; |
| 6109 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6110 | } |
| 6111 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6112 | /* Crash dump feature related initialisation*/ |
| 6113 | instance->drv_buf_index = 0; |
| 6114 | instance->drv_buf_alloc = 0; |
| 6115 | instance->crash_dump_fw_support = 0; |
| 6116 | instance->crash_dump_app_support = 0; |
| 6117 | instance->fw_crash_state = UNAVAILABLE; |
| 6118 | spin_lock_init(&instance->crashdump_lock); |
| 6119 | instance->crash_dump_buf = NULL; |
| 6120 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6121 | megasas_poll_wait_aen = 0; |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 6122 | instance->flag_ieee = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6123 | instance->ev = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6124 | instance->issuepend_done = 1; |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6125 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 6126 | instance->is_imr = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6127 | |
| 6128 | instance->evt_detail = pci_alloc_consistent(pdev, |
| 6129 | sizeof(struct |
| 6130 | megasas_evt_detail), |
| 6131 | &instance->evt_detail_h); |
| 6132 | |
| 6133 | if (!instance->evt_detail) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6134 | dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate memory for " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6135 | "event detail structure\n"); |
| 6136 | goto fail_alloc_dma_buf; |
| 6137 | } |
| 6138 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 6139 | if (!reset_devices) { |
| 6140 | instance->system_info_buf = pci_zalloc_consistent(pdev, |
| 6141 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6142 | &instance->system_info_h); |
| 6143 | if (!instance->system_info_buf) |
| 6144 | dev_info(&instance->pdev->dev, "Can't allocate system info buffer\n"); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6145 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 6146 | instance->pd_info = pci_alloc_consistent(pdev, |
| 6147 | sizeof(struct MR_PD_INFO), &instance->pd_info_h); |
| 6148 | |
| 6149 | if (!instance->pd_info) |
| 6150 | dev_err(&instance->pdev->dev, "Failed to alloc mem for pd_info\n"); |
| 6151 | |
weiping | 3b8328e | 2017-08-08 13:15:55 +0800 | [diff] [blame] | 6152 | instance->tgt_prop = pci_alloc_consistent(pdev, |
| 6153 | sizeof(struct MR_TARGET_PROPERTIES), &instance->tgt_prop_h); |
| 6154 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6155 | if (!instance->tgt_prop) |
| 6156 | dev_err(&instance->pdev->dev, "Failed to alloc mem for tgt_prop\n"); |
| 6157 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 6158 | instance->crash_dump_buf = pci_alloc_consistent(pdev, |
| 6159 | CRASH_DMA_BUF_SIZE, |
| 6160 | &instance->crash_dump_h); |
| 6161 | if (!instance->crash_dump_buf) |
| 6162 | dev_err(&pdev->dev, "Can't allocate Firmware " |
| 6163 | "crash dump DMA buffer\n"); |
| 6164 | } |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6165 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6166 | /* |
| 6167 | * Initialize locks and queues |
| 6168 | */ |
| 6169 | INIT_LIST_HEAD(&instance->cmd_pool); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6170 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6171 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 6172 | atomic_set(&instance->fw_outstanding,0); |
| 6173 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6174 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 6175 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 6176 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 6177 | spin_lock_init(&instance->mfi_pool_lock); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6178 | spin_lock_init(&instance->hba_lock); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6179 | spin_lock_init(&instance->stream_lock); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 6180 | spin_lock_init(&instance->completion_lock); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6181 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6182 | mutex_init(&instance->reset_mutex); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6183 | mutex_init(&instance->hba_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6184 | |
| 6185 | /* |
| 6186 | * Initialize PCI related and misc parameters |
| 6187 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6188 | instance->host = host; |
| 6189 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 6190 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6191 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6192 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6193 | |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 6194 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6195 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 6196 | instance->flag_ieee = 1; |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 6197 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6198 | megasas_dbg_lvl = 0; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 6199 | instance->flag = 0; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6200 | instance->unload = 1; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 6201 | instance->last_time = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6202 | instance->disableOnlineCtrlReset = 1; |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 6203 | instance->UnevenSpanSupport = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6204 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6205 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6206 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6207 | INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq); |
| 6208 | } else |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6209 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6210 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6211 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 6212 | * Initialize MFI Firmware |
| 6213 | */ |
| 6214 | if (megasas_init_fw(instance)) |
| 6215 | goto fail_init_mfi; |
| 6216 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6217 | if (instance->requestorId) { |
| 6218 | if (instance->PlasmaFW111) { |
| 6219 | instance->vf_affiliation_111 = |
| 6220 | pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6221 | &instance->vf_affiliation_111_h); |
| 6222 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6223 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6224 | "memory for VF affiliation buffer\n"); |
| 6225 | } else { |
| 6226 | instance->vf_affiliation = |
| 6227 | pci_alloc_consistent(pdev, |
| 6228 | (MAX_LOGICAL_DRIVES + 1) * |
| 6229 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6230 | &instance->vf_affiliation_h); |
| 6231 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6232 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6233 | "memory for VF affiliation buffer\n"); |
| 6234 | } |
| 6235 | } |
| 6236 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6237 | /* |
| 6238 | * Store instance in PCI softstate |
| 6239 | */ |
| 6240 | pci_set_drvdata(pdev, instance); |
| 6241 | |
| 6242 | /* |
| 6243 | * Add this controller to megasas_mgmt_info structure so that it |
| 6244 | * can be exported to management applications |
| 6245 | */ |
| 6246 | megasas_mgmt_info.count++; |
| 6247 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 6248 | megasas_mgmt_info.max_index++; |
| 6249 | |
| 6250 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6251 | * Register with SCSI mid-layer |
| 6252 | */ |
| 6253 | if (megasas_io_attach(instance)) |
| 6254 | goto fail_io_attach; |
| 6255 | |
| 6256 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 6257 | /* |
| 6258 | * Trigger SCSI to scan our drives |
| 6259 | */ |
| 6260 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6261 | |
| 6262 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6263 | * Initiate AEN (Asynchronous Event Notification) |
| 6264 | */ |
| 6265 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6266 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6267 | goto fail_start_aen; |
| 6268 | } |
| 6269 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 6270 | /* Get current SR-IOV LD/VF affiliation */ |
| 6271 | if (instance->requestorId) |
| 6272 | megasas_get_ld_vf_affiliation(instance, 1); |
| 6273 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6274 | return 0; |
| 6275 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6276 | fail_start_aen: |
| 6277 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6278 | megasas_mgmt_info.count--; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6279 | megasas_mgmt_info.max_index--; |
weiping zhang | 61f0c3c | 2017-08-08 01:26:57 +0800 | [diff] [blame] | 6280 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6281 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6282 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6283 | megasas_destroy_irqs(instance); |
| 6284 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6285 | if (instance->adapter_type != MFI_SERIES) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6286 | megasas_release_fusion(instance); |
| 6287 | else |
| 6288 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6289 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6290 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6291 | fail_init_mfi: |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6292 | fail_alloc_dma_buf: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6293 | if (instance->evt_detail) |
| 6294 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6295 | instance->evt_detail, |
| 6296 | instance->evt_detail_h); |
| 6297 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6298 | if (instance->pd_info) |
| 6299 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6300 | instance->pd_info, |
| 6301 | instance->pd_info_h); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6302 | if (instance->tgt_prop) |
| 6303 | pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES), |
| 6304 | instance->tgt_prop, |
| 6305 | instance->tgt_prop_h); |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6306 | if (instance->producer) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6307 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 6308 | instance->producer_h); |
| 6309 | if (instance->consumer) |
| 6310 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 6311 | instance->consumer_h); |
| 6312 | scsi_host_put(host); |
| 6313 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6314 | fail_alloc_instance: |
| 6315 | fail_set_dma_mask: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6316 | pci_disable_device(pdev); |
| 6317 | |
| 6318 | return -ENODEV; |
| 6319 | } |
| 6320 | |
| 6321 | /** |
| 6322 | * megasas_flush_cache - Requests FW to flush all its caches |
| 6323 | * @instance: Adapter soft state |
| 6324 | */ |
| 6325 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 6326 | { |
| 6327 | struct megasas_cmd *cmd; |
| 6328 | struct megasas_dcmd_frame *dcmd; |
| 6329 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6330 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6331 | return; |
| 6332 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6333 | cmd = megasas_get_cmd(instance); |
| 6334 | |
| 6335 | if (!cmd) |
| 6336 | return; |
| 6337 | |
| 6338 | dcmd = &cmd->frame->dcmd; |
| 6339 | |
| 6340 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6341 | |
| 6342 | dcmd->cmd = MFI_CMD_DCMD; |
| 6343 | dcmd->cmd_status = 0x0; |
| 6344 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6345 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6346 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6347 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6348 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6349 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6350 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 6351 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6352 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6353 | != DCMD_SUCCESS) { |
| 6354 | dev_err(&instance->pdev->dev, |
| 6355 | "return from %s %d\n", __func__, __LINE__); |
| 6356 | return; |
| 6357 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6358 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6359 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6360 | } |
| 6361 | |
| 6362 | /** |
| 6363 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 6364 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6365 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6366 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6367 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 6368 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6369 | { |
| 6370 | struct megasas_cmd *cmd; |
| 6371 | struct megasas_dcmd_frame *dcmd; |
| 6372 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6373 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6374 | return; |
| 6375 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6376 | cmd = megasas_get_cmd(instance); |
| 6377 | |
| 6378 | if (!cmd) |
| 6379 | return; |
| 6380 | |
| 6381 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6382 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6383 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6384 | if (instance->map_update_cmd) |
| 6385 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6386 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6387 | if (instance->jbod_seq_cmd) |
| 6388 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6389 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6390 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6391 | dcmd = &cmd->frame->dcmd; |
| 6392 | |
| 6393 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6394 | |
| 6395 | dcmd->cmd = MFI_CMD_DCMD; |
| 6396 | dcmd->cmd_status = 0x0; |
| 6397 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6398 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6399 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6400 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6401 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6402 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6403 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6404 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6405 | != DCMD_SUCCESS) { |
| 6406 | dev_err(&instance->pdev->dev, |
| 6407 | "return from %s %d\n", __func__, __LINE__); |
| 6408 | return; |
| 6409 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6410 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6411 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6412 | } |
| 6413 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6414 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6415 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6416 | * megasas_suspend - driver suspend entry point |
| 6417 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6418 | * @state: PCI power state to suspend routine |
| 6419 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6420 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6421 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6422 | { |
| 6423 | struct Scsi_Host *host; |
| 6424 | struct megasas_instance *instance; |
| 6425 | |
| 6426 | instance = pci_get_drvdata(pdev); |
| 6427 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6428 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6429 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6430 | /* Shutdown SR-IOV heartbeat timer */ |
| 6431 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6432 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6433 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6434 | megasas_flush_cache(instance); |
| 6435 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6436 | |
| 6437 | /* cancel the delayed work if this work still in queue */ |
| 6438 | if (instance->ev != NULL) { |
| 6439 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6440 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6441 | instance->ev = NULL; |
| 6442 | } |
| 6443 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6444 | tasklet_kill(&instance->isr_tasklet); |
| 6445 | |
| 6446 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6447 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6448 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6449 | megasas_destroy_irqs(instance); |
| 6450 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6451 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6452 | pci_free_irq_vectors(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6453 | |
| 6454 | pci_save_state(pdev); |
| 6455 | pci_disable_device(pdev); |
| 6456 | |
| 6457 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 6458 | |
| 6459 | return 0; |
| 6460 | } |
| 6461 | |
| 6462 | /** |
| 6463 | * megasas_resume- driver resume entry point |
| 6464 | * @pdev: PCI device structure |
| 6465 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6466 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6467 | megasas_resume(struct pci_dev *pdev) |
| 6468 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6469 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6470 | struct Scsi_Host *host; |
| 6471 | struct megasas_instance *instance; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6472 | int irq_flags = PCI_IRQ_LEGACY; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6473 | |
| 6474 | instance = pci_get_drvdata(pdev); |
| 6475 | host = instance->host; |
| 6476 | pci_set_power_state(pdev, PCI_D0); |
| 6477 | pci_enable_wake(pdev, PCI_D0, 0); |
| 6478 | pci_restore_state(pdev); |
| 6479 | |
| 6480 | /* |
| 6481 | * PCI prepping: enable device set bus mastering and dma mask |
| 6482 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6483 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6484 | |
| 6485 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6486 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6487 | return rval; |
| 6488 | } |
| 6489 | |
| 6490 | pci_set_master(pdev); |
| 6491 | |
| 6492 | if (megasas_set_dma_mask(pdev)) |
| 6493 | goto fail_set_dma_mask; |
| 6494 | |
| 6495 | /* |
| 6496 | * Initialize MFI Firmware |
| 6497 | */ |
| 6498 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6499 | atomic_set(&instance->fw_outstanding, 0); |
| 6500 | |
| 6501 | /* |
| 6502 | * We expect the FW state to be READY |
| 6503 | */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 6504 | if (megasas_transition_to_ready(instance, 0)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6505 | goto fail_ready_state; |
| 6506 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6507 | /* Now re-enable MSI-X */ |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6508 | if (instance->msix_vectors) { |
| 6509 | irq_flags = PCI_IRQ_MSIX; |
| 6510 | if (smp_affinity_enable) |
| 6511 | irq_flags |= PCI_IRQ_AFFINITY; |
| 6512 | } |
| 6513 | rval = pci_alloc_irq_vectors(instance->pdev, 1, |
| 6514 | instance->msix_vectors ? |
| 6515 | instance->msix_vectors : 1, irq_flags); |
| 6516 | if (rval < 0) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6517 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6518 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6519 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6520 | megasas_reset_reply_desc(instance); |
| 6521 | if (megasas_ioc_init_fusion(instance)) { |
| 6522 | megasas_free_cmds(instance); |
| 6523 | megasas_free_cmds_fusion(instance); |
| 6524 | goto fail_init_mfi; |
| 6525 | } |
| 6526 | if (!megasas_get_map_info(instance)) |
| 6527 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6528 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6529 | *instance->producer = 0; |
| 6530 | *instance->consumer = 0; |
| 6531 | if (megasas_issue_init_mfi(instance)) |
| 6532 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6533 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6534 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6535 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 6536 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6537 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6538 | if (instance->msix_vectors ? |
| 6539 | megasas_setup_irqs_msix(instance, 0) : |
| 6540 | megasas_setup_irqs_ioapic(instance)) |
| 6541 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6542 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6543 | /* Re-launch SR-IOV heartbeat timer */ |
| 6544 | if (instance->requestorId) { |
| 6545 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
| 6546 | megasas_start_timer(instance, |
| 6547 | &instance->sriov_heartbeat_timer, |
| 6548 | megasas_sriov_heartbeat_handler, |
| 6549 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6550 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6551 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6552 | goto fail_init_mfi; |
| 6553 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6554 | } |
| 6555 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6556 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6557 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6558 | instance->unload = 0; |
| 6559 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6560 | /* |
| 6561 | * Initiate AEN (Asynchronous Event Notification) |
| 6562 | */ |
| 6563 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6564 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6565 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6566 | return 0; |
| 6567 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6568 | fail_init_mfi: |
| 6569 | if (instance->evt_detail) |
| 6570 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6571 | instance->evt_detail, |
| 6572 | instance->evt_detail_h); |
| 6573 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6574 | if (instance->pd_info) |
| 6575 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6576 | instance->pd_info, |
| 6577 | instance->pd_info_h); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6578 | if (instance->tgt_prop) |
| 6579 | pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES), |
| 6580 | instance->tgt_prop, |
| 6581 | instance->tgt_prop_h); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6582 | if (instance->producer) |
| 6583 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 6584 | instance->producer_h); |
| 6585 | if (instance->consumer) |
| 6586 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 6587 | instance->consumer_h); |
| 6588 | scsi_host_put(host); |
| 6589 | |
| 6590 | fail_set_dma_mask: |
| 6591 | fail_ready_state: |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 6592 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6593 | |
| 6594 | pci_disable_device(pdev); |
| 6595 | |
| 6596 | return -ENODEV; |
| 6597 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 6598 | #else |
| 6599 | #define megasas_suspend NULL |
| 6600 | #define megasas_resume NULL |
| 6601 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6602 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6603 | static inline int |
| 6604 | megasas_wait_for_adapter_operational(struct megasas_instance *instance) |
| 6605 | { |
| 6606 | int wait_time = MEGASAS_RESET_WAIT_TIME * 2; |
| 6607 | int i; |
| 6608 | |
| 6609 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
| 6610 | return 1; |
| 6611 | |
| 6612 | for (i = 0; i < wait_time; i++) { |
| 6613 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
| 6614 | break; |
| 6615 | |
| 6616 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) |
| 6617 | dev_notice(&instance->pdev->dev, "waiting for controller reset to finish\n"); |
| 6618 | |
| 6619 | msleep(1000); |
| 6620 | } |
| 6621 | |
| 6622 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
| 6623 | dev_info(&instance->pdev->dev, "%s timed out while waiting for HBA to recover.\n", |
| 6624 | __func__); |
| 6625 | return 1; |
| 6626 | } |
| 6627 | |
| 6628 | return 0; |
| 6629 | } |
| 6630 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6631 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6632 | * megasas_detach_one - PCI hot"un"plug entry point |
| 6633 | * @pdev: PCI device structure |
| 6634 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6635 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6636 | { |
| 6637 | int i; |
| 6638 | struct Scsi_Host *host; |
| 6639 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6640 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6641 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6642 | |
| 6643 | instance = pci_get_drvdata(pdev); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6644 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6645 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6646 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6647 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6648 | /* Shutdown SR-IOV heartbeat timer */ |
| 6649 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6650 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 6651 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6652 | if (instance->fw_crash_state != UNAVAILABLE) |
| 6653 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6654 | scsi_remove_host(instance->host); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6655 | |
| 6656 | if (megasas_wait_for_adapter_operational(instance)) |
| 6657 | goto skip_firing_dcmds; |
| 6658 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6659 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6660 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6661 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6662 | skip_firing_dcmds: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6663 | /* cancel the delayed work if this work still in queue*/ |
| 6664 | if (instance->ev != NULL) { |
| 6665 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6666 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6667 | instance->ev = NULL; |
| 6668 | } |
| 6669 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6670 | /* cancel all wait events */ |
| 6671 | wake_up_all(&instance->int_cmd_wait_q); |
| 6672 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 6673 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6674 | |
| 6675 | /* |
| 6676 | * Take the instance off the instance array. Note that we will not |
| 6677 | * decrement the max_index. We let this array be sparse array |
| 6678 | */ |
| 6679 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6680 | if (megasas_mgmt_info.instance[i] == instance) { |
| 6681 | megasas_mgmt_info.count--; |
| 6682 | megasas_mgmt_info.instance[i] = NULL; |
| 6683 | |
| 6684 | break; |
| 6685 | } |
| 6686 | } |
| 6687 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6688 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6689 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6690 | megasas_destroy_irqs(instance); |
| 6691 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6692 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6693 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6694 | |
Shivasharan S | f369a31 | 2017-10-19 02:48:52 -0700 | [diff] [blame^] | 6695 | if (instance->adapter_type == VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6696 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) |
| 6697 | kfree(fusion->stream_detect_by_ld[i]); |
| 6698 | kfree(fusion->stream_detect_by_ld); |
| 6699 | fusion->stream_detect_by_ld = NULL; |
| 6700 | } |
| 6701 | |
| 6702 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6703 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6704 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6705 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 6706 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 6707 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6708 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6709 | if (fusion->ld_map[i]) |
| 6710 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6711 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6712 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6713 | fusion->ld_map_phys[i]); |
Shivasharan S | def3e8d | 2017-08-23 04:47:03 -0700 | [diff] [blame] | 6714 | if (fusion->ld_drv_map[i]) { |
| 6715 | if (is_vmalloc_addr(fusion->ld_drv_map[i])) |
| 6716 | vfree(fusion->ld_drv_map[i]); |
| 6717 | else |
| 6718 | free_pages((ulong)fusion->ld_drv_map[i], |
| 6719 | fusion->drv_map_pages); |
| 6720 | } |
| 6721 | |
Maurizio Lombardi | 546e559 | 2016-01-22 13:41:42 +0100 | [diff] [blame] | 6722 | if (fusion->pd_seq_sync[i]) |
| 6723 | dma_free_coherent(&instance->pdev->dev, |
| 6724 | pd_seq_map_sz, |
| 6725 | fusion->pd_seq_sync[i], |
| 6726 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6727 | } |
Shivasharan S | 5fc499b | 2017-02-10 00:59:17 -0800 | [diff] [blame] | 6728 | megasas_free_fusion_context(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 6729 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6730 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6731 | pci_free_consistent(pdev, sizeof(u32), |
| 6732 | instance->producer, |
| 6733 | instance->producer_h); |
| 6734 | pci_free_consistent(pdev, sizeof(u32), |
| 6735 | instance->consumer, |
| 6736 | instance->consumer_h); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6737 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6738 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6739 | kfree(instance->ctrl_info); |
| 6740 | |
Sumit.Saxena@lsi.com | 105900d | 2013-05-22 12:30:54 +0530 | [diff] [blame] | 6741 | if (instance->evt_detail) |
| 6742 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 6743 | instance->evt_detail, instance->evt_detail_h); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 6744 | if (instance->pd_info) |
| 6745 | pci_free_consistent(pdev, sizeof(struct MR_PD_INFO), |
| 6746 | instance->pd_info, |
| 6747 | instance->pd_info_h); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6748 | if (instance->tgt_prop) |
| 6749 | pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES), |
| 6750 | instance->tgt_prop, |
| 6751 | instance->tgt_prop_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6752 | if (instance->vf_affiliation) |
| 6753 | pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) * |
| 6754 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6755 | instance->vf_affiliation, |
| 6756 | instance->vf_affiliation_h); |
| 6757 | |
| 6758 | if (instance->vf_affiliation_111) |
| 6759 | pci_free_consistent(pdev, |
| 6760 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6761 | instance->vf_affiliation_111, |
| 6762 | instance->vf_affiliation_111_h); |
| 6763 | |
| 6764 | if (instance->hb_host_mem) |
| 6765 | pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 6766 | instance->hb_host_mem, |
| 6767 | instance->hb_host_mem_h); |
| 6768 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6769 | if (instance->crash_dump_buf) |
| 6770 | pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE, |
| 6771 | instance->crash_dump_buf, instance->crash_dump_h); |
| 6772 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 6773 | if (instance->system_info_buf) |
| 6774 | pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6775 | instance->system_info_buf, instance->system_info_h); |
| 6776 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6777 | scsi_host_put(host); |
| 6778 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6779 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | /** |
| 6783 | * megasas_shutdown - Shutdown entry point |
| 6784 | * @device: Generic device structure |
| 6785 | */ |
| 6786 | static void megasas_shutdown(struct pci_dev *pdev) |
| 6787 | { |
| 6788 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6789 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6790 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6791 | |
| 6792 | if (megasas_wait_for_adapter_operational(instance)) |
| 6793 | goto skip_firing_dcmds; |
| 6794 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6795 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 6796 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 6797 | |
| 6798 | skip_firing_dcmds: |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6799 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6800 | megasas_destroy_irqs(instance); |
| 6801 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6802 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6803 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6804 | } |
| 6805 | |
| 6806 | /** |
| 6807 | * megasas_mgmt_open - char node "open" entry point |
| 6808 | */ |
| 6809 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 6810 | { |
| 6811 | /* |
| 6812 | * Allow only those users with admin rights |
| 6813 | */ |
| 6814 | if (!capable(CAP_SYS_ADMIN)) |
| 6815 | return -EACCES; |
| 6816 | |
| 6817 | return 0; |
| 6818 | } |
| 6819 | |
| 6820 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6821 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 6822 | * |
| 6823 | * This function adds the calling process to a driver global queue. When an |
| 6824 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 6825 | */ |
| 6826 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 6827 | { |
| 6828 | int rc; |
| 6829 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6830 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6831 | |
| 6832 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 6833 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 6834 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6835 | |
| 6836 | if (rc >= 0) { |
| 6837 | /* For sanity check when we get ioctl */ |
| 6838 | filep->private_data = filep; |
| 6839 | return 0; |
| 6840 | } |
| 6841 | |
| 6842 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 6843 | |
| 6844 | return rc; |
| 6845 | } |
| 6846 | |
| 6847 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6848 | * megasas_mgmt_poll - char node "poll" entry point |
| 6849 | * */ |
| 6850 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) |
| 6851 | { |
| 6852 | unsigned int mask; |
| 6853 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6854 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6855 | poll_wait(file, &megasas_poll_wait, wait); |
| 6856 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 6857 | if (megasas_poll_wait_aen) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6858 | mask = (POLLIN | POLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6859 | else |
| 6860 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6861 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6862 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 6863 | return mask; |
| 6864 | } |
| 6865 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6866 | /* |
| 6867 | * megasas_set_crash_dump_params_ioctl: |
| 6868 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 6869 | * @cmd: MFI command frame |
| 6870 | */ |
| 6871 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6872 | 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] | 6873 | { |
| 6874 | struct megasas_instance *local_instance; |
| 6875 | int i, error = 0; |
| 6876 | int crash_support; |
| 6877 | |
| 6878 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 6879 | |
| 6880 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 6881 | local_instance = megasas_mgmt_info.instance[i]; |
| 6882 | if (local_instance && local_instance->crash_dump_drv_support) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6883 | if ((atomic_read(&local_instance->adprecovery) == |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6884 | MEGASAS_HBA_OPERATIONAL) && |
| 6885 | !megasas_set_crash_dump_params(local_instance, |
| 6886 | crash_support)) { |
| 6887 | local_instance->crash_dump_app_support = |
| 6888 | crash_support; |
| 6889 | dev_info(&local_instance->pdev->dev, |
| 6890 | "Application firmware crash " |
| 6891 | "dump mode set success\n"); |
| 6892 | error = 0; |
| 6893 | } else { |
| 6894 | dev_info(&local_instance->pdev->dev, |
| 6895 | "Application firmware crash " |
| 6896 | "dump mode set failed\n"); |
| 6897 | error = -1; |
| 6898 | } |
| 6899 | } |
| 6900 | } |
| 6901 | return error; |
| 6902 | } |
| 6903 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6904 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6905 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 6906 | * @instance: Adapter soft state |
| 6907 | * @argp: User's ioctl packet |
| 6908 | */ |
| 6909 | static int |
| 6910 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 6911 | struct megasas_iocpacket __user * user_ioc, |
| 6912 | struct megasas_iocpacket *ioc) |
| 6913 | { |
| 6914 | struct megasas_sge32 *kern_sge32; |
| 6915 | struct megasas_cmd *cmd; |
| 6916 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 6917 | dma_addr_t buf_handle = 0; |
| 6918 | int error = 0, i; |
| 6919 | void *sense = NULL; |
| 6920 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6921 | unsigned long *sense_ptr; |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 6922 | u32 opcode; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6923 | |
| 6924 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 6925 | |
| 6926 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6927 | 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] | 6928 | ioc->sge_count, MAX_IOCTL_SGE); |
| 6929 | return -EINVAL; |
| 6930 | } |
| 6931 | |
| 6932 | cmd = megasas_get_cmd(instance); |
| 6933 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6934 | 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] | 6935 | return -ENOMEM; |
| 6936 | } |
| 6937 | |
| 6938 | /* |
| 6939 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 6940 | * frames into our cmd's frames. cmd->frame's context will get |
| 6941 | * overwritten when we copy from user's frames. So set that value |
| 6942 | * alone separately |
| 6943 | */ |
| 6944 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6945 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6946 | cmd->frame->hdr.pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6947 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE | |
| 6948 | MFI_FRAME_SGL64 | |
| 6949 | MFI_FRAME_SENSE64)); |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 6950 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6951 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 6952 | if (opcode == MR_DCMD_CTRL_SHUTDOWN) { |
Shivasharan S | 95c0608 | 2017-02-10 00:59:23 -0800 | [diff] [blame] | 6953 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) { |
| 6954 | megasas_return_cmd(instance, cmd); |
| 6955 | return -1; |
| 6956 | } |
| 6957 | } |
| 6958 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 6959 | if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 6960 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 6961 | megasas_return_cmd(instance, cmd); |
| 6962 | return error; |
| 6963 | } |
| 6964 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6965 | /* |
| 6966 | * The management interface between applications and the fw uses |
| 6967 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 6968 | * etc are accomplishes through different kinds of MFI frames. The |
| 6969 | * driver needs to care only about substituting user buffers with |
| 6970 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 6971 | * struct iocpacket itself. |
| 6972 | */ |
| 6973 | kern_sge32 = (struct megasas_sge32 *) |
| 6974 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 6975 | |
| 6976 | /* |
| 6977 | * For each user buffer, create a mirror buffer and copy in |
| 6978 | */ |
| 6979 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 6980 | if (!ioc->sgl[i].iov_len) |
| 6981 | continue; |
| 6982 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6983 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6984 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6985 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6986 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6987 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 6988 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6989 | error = -ENOMEM; |
| 6990 | goto out; |
| 6991 | } |
| 6992 | |
| 6993 | /* |
| 6994 | * We don't change the dma_coherent_mask, so |
| 6995 | * pci_alloc_consistent only returns 32bit addresses |
| 6996 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6997 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 6998 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6999 | |
| 7000 | /* |
| 7001 | * We created a kernel buffer corresponding to the |
| 7002 | * user buffer. Now copy in from the user buffer |
| 7003 | */ |
| 7004 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 7005 | (u32) (ioc->sgl[i].iov_len))) { |
| 7006 | error = -EFAULT; |
| 7007 | goto out; |
| 7008 | } |
| 7009 | } |
| 7010 | |
| 7011 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7012 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 7013 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7014 | if (!sense) { |
| 7015 | error = -ENOMEM; |
| 7016 | goto out; |
| 7017 | } |
| 7018 | |
| 7019 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7020 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7021 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7022 | } |
| 7023 | |
| 7024 | /* |
| 7025 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 7026 | * cmd to the SCSI mid-layer |
| 7027 | */ |
| 7028 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7029 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 7030 | cmd->sync_cmd = 0; |
| 7031 | dev_err(&instance->pdev->dev, |
| 7032 | "return -EBUSY from %s %d opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 7033 | __func__, __LINE__, opcode, cmd->cmd_status_drv); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7034 | return -EBUSY; |
| 7035 | } |
| 7036 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7037 | cmd->sync_cmd = 0; |
| 7038 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 7039 | if (instance->unload == 1) { |
| 7040 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 7041 | "don't submit data to application\n"); |
| 7042 | goto out; |
| 7043 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7044 | /* |
| 7045 | * copy out the kernel buffers to user buffers |
| 7046 | */ |
| 7047 | for (i = 0; i < ioc->sge_count; i++) { |
| 7048 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 7049 | ioc->sgl[i].iov_len)) { |
| 7050 | error = -EFAULT; |
| 7051 | goto out; |
| 7052 | } |
| 7053 | } |
| 7054 | |
| 7055 | /* |
| 7056 | * copy out the sense |
| 7057 | */ |
| 7058 | if (ioc->sense_len) { |
| 7059 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7060 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7061 | * sense buffer address |
| 7062 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7063 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 7064 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7065 | |
Shivasharan S | 318aaef | 2017-02-10 00:59:22 -0800 | [diff] [blame] | 7066 | if (copy_to_user((void __user *)((unsigned long) |
| 7067 | get_unaligned((unsigned long *)sense_ptr)), |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7068 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7069 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 7070 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7071 | error = -EFAULT; |
| 7072 | goto out; |
| 7073 | } |
| 7074 | } |
| 7075 | |
| 7076 | /* |
| 7077 | * copy the status codes returned by the fw |
| 7078 | */ |
| 7079 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 7080 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7081 | 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] | 7082 | error = -EFAULT; |
| 7083 | } |
| 7084 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7085 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7086 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7087 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7088 | sense, sense_handle); |
| 7089 | } |
| 7090 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7091 | for (i = 0; i < ioc->sge_count; i++) { |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7092 | if (kbuff_arr[i]) { |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7093 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7094 | le32_to_cpu(kern_sge32[i].length), |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7095 | kbuff_arr[i], |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7096 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 7097 | kbuff_arr[i] = NULL; |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7098 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7099 | } |
| 7100 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7101 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7102 | return error; |
| 7103 | } |
| 7104 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7105 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 7106 | { |
| 7107 | struct megasas_iocpacket __user *user_ioc = |
| 7108 | (struct megasas_iocpacket __user *)arg; |
| 7109 | struct megasas_iocpacket *ioc; |
| 7110 | struct megasas_instance *instance; |
| 7111 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7112 | int i; |
| 7113 | unsigned long flags; |
| 7114 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7115 | |
Markus Elfring | 709ab23 | 2016-08-21 10:39:04 +0200 | [diff] [blame] | 7116 | ioc = memdup_user(user_ioc, sizeof(*ioc)); |
| 7117 | if (IS_ERR(ioc)) |
| 7118 | return PTR_ERR(ioc); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7119 | |
| 7120 | instance = megasas_lookup_instance(ioc->host_no); |
| 7121 | if (!instance) { |
| 7122 | error = -ENODEV; |
| 7123 | goto out_kfree_ioc; |
| 7124 | } |
| 7125 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7126 | /* Adjust ioctl wait time for VF mode */ |
| 7127 | if (instance->requestorId) |
| 7128 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 7129 | |
| 7130 | /* Block ioctls in VF mode */ |
| 7131 | if (instance->requestorId && !allow_vf_ioctls) { |
| 7132 | error = -ENODEV; |
| 7133 | goto out_kfree_ioc; |
| 7134 | } |
| 7135 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7136 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7137 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7138 | error = -ENODEV; |
| 7139 | goto out_kfree_ioc; |
| 7140 | } |
| 7141 | |
| 7142 | if (instance->unload == 1) { |
| 7143 | error = -ENODEV; |
| 7144 | goto out_kfree_ioc; |
| 7145 | } |
| 7146 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7147 | if (down_interruptible(&instance->ioctl_sem)) { |
| 7148 | error = -ERESTARTSYS; |
| 7149 | goto out_kfree_ioc; |
| 7150 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7151 | |
| 7152 | for (i = 0; i < wait_time; i++) { |
| 7153 | |
| 7154 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7155 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7156 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7157 | break; |
| 7158 | } |
| 7159 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7160 | |
| 7161 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7162 | dev_notice(&instance->pdev->dev, "waiting" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7163 | "for controller reset to finish\n"); |
| 7164 | } |
| 7165 | |
| 7166 | msleep(1000); |
| 7167 | } |
| 7168 | |
| 7169 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7170 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7171 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7172 | |
Colin Ian King | 644da3c | 2016-11-12 16:25:24 +0000 | [diff] [blame] | 7173 | dev_err(&instance->pdev->dev, "timed out while waiting for HBA to recover\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7174 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 7175 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7176 | } |
| 7177 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7178 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7179 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7180 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7181 | up(&instance->ioctl_sem); |
| 7182 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7183 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7184 | kfree(ioc); |
| 7185 | return error; |
| 7186 | } |
| 7187 | |
| 7188 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 7189 | { |
| 7190 | struct megasas_instance *instance; |
| 7191 | struct megasas_aen aen; |
| 7192 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7193 | int i; |
| 7194 | unsigned long flags; |
| 7195 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7196 | |
| 7197 | if (file->private_data != file) { |
| 7198 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 7199 | "called first\n"); |
| 7200 | return -EINVAL; |
| 7201 | } |
| 7202 | |
| 7203 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 7204 | return -EFAULT; |
| 7205 | |
| 7206 | instance = megasas_lookup_instance(aen.host_no); |
| 7207 | |
| 7208 | if (!instance) |
| 7209 | return -ENODEV; |
| 7210 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7211 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7212 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7213 | } |
| 7214 | |
| 7215 | if (instance->unload == 1) { |
| 7216 | return -ENODEV; |
| 7217 | } |
| 7218 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7219 | for (i = 0; i < wait_time; i++) { |
| 7220 | |
| 7221 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7222 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7223 | spin_unlock_irqrestore(&instance->hba_lock, |
| 7224 | flags); |
| 7225 | break; |
| 7226 | } |
| 7227 | |
| 7228 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7229 | |
| 7230 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7231 | dev_notice(&instance->pdev->dev, "waiting for" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7232 | "controller reset to finish\n"); |
| 7233 | } |
| 7234 | |
| 7235 | msleep(1000); |
| 7236 | } |
| 7237 | |
| 7238 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7239 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7240 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Colin Ian King | 644da3c | 2016-11-12 16:25:24 +0000 | [diff] [blame] | 7241 | dev_err(&instance->pdev->dev, "timed out while waiting for HBA to recover\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7242 | return -ENODEV; |
| 7243 | } |
| 7244 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 7245 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7246 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7247 | error = megasas_register_aen(instance, aen.seq_num, |
| 7248 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7249 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7250 | return error; |
| 7251 | } |
| 7252 | |
| 7253 | /** |
| 7254 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 7255 | */ |
| 7256 | static long |
| 7257 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 7258 | { |
| 7259 | switch (cmd) { |
| 7260 | case MEGASAS_IOC_FIRMWARE: |
| 7261 | return megasas_mgmt_ioctl_fw(file, arg); |
| 7262 | |
| 7263 | case MEGASAS_IOC_GET_AEN: |
| 7264 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7265 | } |
| 7266 | |
| 7267 | return -ENOTTY; |
| 7268 | } |
| 7269 | |
| 7270 | #ifdef CONFIG_COMPAT |
| 7271 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 7272 | { |
| 7273 | struct compat_megasas_iocpacket __user *cioc = |
| 7274 | (struct compat_megasas_iocpacket __user *)arg; |
| 7275 | struct megasas_iocpacket __user *ioc = |
| 7276 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 7277 | int i; |
| 7278 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7279 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7280 | u32 local_sense_off; |
| 7281 | u32 local_sense_len; |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7282 | u32 user_sense_off; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7283 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7284 | if (clear_user(ioc, sizeof(*ioc))) |
| 7285 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7286 | |
| 7287 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 7288 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 7289 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 7290 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 7291 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 7292 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 7293 | return -EFAULT; |
| 7294 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7295 | /* |
| 7296 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 7297 | * sense_len is not null, so prepare the 64bit value under |
| 7298 | * the same condition. |
| 7299 | */ |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7300 | if (get_user(local_sense_off, &ioc->sense_off) || |
| 7301 | get_user(local_sense_len, &ioc->sense_len) || |
| 7302 | get_user(user_sense_off, &cioc->sense_off)) |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7303 | return -EFAULT; |
| 7304 | |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7305 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7306 | void __user **sense_ioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7307 | (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7308 | compat_uptr_t *sense_cioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7309 | (compat_uptr_t *)(((unsigned long)&cioc->frame.raw) + user_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7310 | if (get_user(ptr, sense_cioc_ptr) || |
| 7311 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 7312 | return -EFAULT; |
| 7313 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7314 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7315 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7316 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 7317 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 7318 | copy_in_user(&ioc->sgl[i].iov_len, |
| 7319 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 7320 | return -EFAULT; |
| 7321 | } |
| 7322 | |
| 7323 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 7324 | |
| 7325 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 7326 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 7327 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 7328 | return -EFAULT; |
| 7329 | } |
| 7330 | return error; |
| 7331 | } |
| 7332 | |
| 7333 | static long |
| 7334 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 7335 | unsigned long arg) |
| 7336 | { |
| 7337 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 7338 | case MEGASAS_IOC_FIRMWARE32: |
| 7339 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7340 | case MEGASAS_IOC_GET_AEN: |
| 7341 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7342 | } |
| 7343 | |
| 7344 | return -ENOTTY; |
| 7345 | } |
| 7346 | #endif |
| 7347 | |
| 7348 | /* |
| 7349 | * File operations structure for management interface |
| 7350 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 7351 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7352 | .owner = THIS_MODULE, |
| 7353 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7354 | .fasync = megasas_mgmt_fasync, |
| 7355 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7356 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7357 | #ifdef CONFIG_COMPAT |
| 7358 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 7359 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 7360 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7361 | }; |
| 7362 | |
| 7363 | /* |
| 7364 | * PCI hotplug support registration structure |
| 7365 | */ |
| 7366 | static struct pci_driver megasas_pci_driver = { |
| 7367 | |
| 7368 | .name = "megaraid_sas", |
| 7369 | .id_table = megasas_pci_table, |
| 7370 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7371 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7372 | .suspend = megasas_suspend, |
| 7373 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7374 | .shutdown = megasas_shutdown, |
| 7375 | }; |
| 7376 | |
| 7377 | /* |
| 7378 | * Sysfs driver attributes |
| 7379 | */ |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7380 | static ssize_t version_show(struct device_driver *dd, char *buf) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7381 | { |
| 7382 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 7383 | MEGASAS_VERSION); |
| 7384 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7385 | static DRIVER_ATTR_RO(version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7386 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7387 | 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] | 7388 | { |
| 7389 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 7390 | MEGASAS_RELDATE); |
| 7391 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7392 | static DRIVER_ATTR_RO(release_date); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7393 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7394 | 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] | 7395 | { |
| 7396 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 7397 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7398 | static DRIVER_ATTR_RO(support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7399 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7400 | 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] | 7401 | { |
| 7402 | return sprintf(buf, "%u\n", support_device_change); |
| 7403 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7404 | static DRIVER_ATTR_RO(support_device_change); |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7405 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7406 | static ssize_t dbg_lvl_show(struct device_driver *dd, char *buf) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7407 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7408 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7409 | } |
| 7410 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7411 | static ssize_t dbg_lvl_store(struct device_driver *dd, const char *buf, |
| 7412 | size_t count) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7413 | { |
| 7414 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7415 | |
| 7416 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7417 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 7418 | retval = -EINVAL; |
| 7419 | } |
| 7420 | return retval; |
| 7421 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7422 | static DRIVER_ATTR_RW(dbg_lvl); |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7423 | |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 7424 | static inline void megasas_remove_scsi_device(struct scsi_device *sdev) |
| 7425 | { |
| 7426 | sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n"); |
| 7427 | scsi_remove_device(sdev); |
| 7428 | scsi_device_put(sdev); |
| 7429 | } |
| 7430 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7431 | static void |
| 7432 | megasas_aen_polling(struct work_struct *work) |
| 7433 | { |
| 7434 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7435 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7436 | struct megasas_instance *instance = ev->instance; |
| 7437 | union megasas_evt_class_locale class_locale; |
| 7438 | struct Scsi_Host *host; |
| 7439 | struct scsi_device *sdev1; |
| 7440 | u16 pd_index = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7441 | u16 ld_index = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7442 | int i, j, doscan = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7443 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7444 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7445 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7446 | |
| 7447 | if (!instance) { |
| 7448 | printk(KERN_ERR "invalid instance!\n"); |
| 7449 | kfree(ev); |
| 7450 | return; |
| 7451 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7452 | |
| 7453 | /* Adjust event workqueue thread wait time for VF mode */ |
| 7454 | if (instance->requestorId) |
| 7455 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 7456 | |
| 7457 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7458 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7459 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7460 | instance->ev = NULL; |
| 7461 | host = instance->host; |
| 7462 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 7463 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7464 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7465 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7466 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7467 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7468 | case MR_EVT_PD_REMOVED: |
| 7469 | dcmd_ret = megasas_get_pd_list(instance); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7470 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7471 | doscan = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7472 | break; |
| 7473 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7474 | case MR_EVT_LD_OFFLINE: |
| 7475 | case MR_EVT_CFG_CLEARED: |
| 7476 | case MR_EVT_LD_DELETED: |
| 7477 | case MR_EVT_LD_CREATED: |
| 7478 | if (!instance->requestorId || |
| 7479 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7480 | 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] | 7481 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7482 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7483 | doscan = SCAN_VD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7484 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7485 | break; |
| 7486 | |
| 7487 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 7488 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 7489 | case MR_EVT_LD_STATE_CHANGE: |
| 7490 | dcmd_ret = megasas_get_pd_list(instance); |
| 7491 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7492 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7493 | break; |
| 7494 | |
| 7495 | if (!instance->requestorId || |
| 7496 | (instance->requestorId && megasas_get_ld_vf_affiliation(instance, 0))) |
| 7497 | dcmd_ret = megasas_ld_list_query(instance, MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 7498 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7499 | if (dcmd_ret != DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7500 | break; |
| 7501 | |
| 7502 | doscan = SCAN_VD_CHANNEL | SCAN_PD_CHANNEL; |
| 7503 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 7504 | instance->host->host_no); |
| 7505 | break; |
| 7506 | |
| 7507 | case MR_EVT_CTRL_PROP_CHANGED: |
| 7508 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 7509 | break; |
| 7510 | default: |
| 7511 | doscan = 0; |
| 7512 | break; |
| 7513 | } |
| 7514 | } else { |
| 7515 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 7516 | mutex_unlock(&instance->reset_mutex); |
| 7517 | kfree(ev); |
| 7518 | return; |
| 7519 | } |
| 7520 | |
| 7521 | mutex_unlock(&instance->reset_mutex); |
| 7522 | |
| 7523 | if (doscan & SCAN_PD_CHANNEL) { |
| 7524 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 7525 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7526 | pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7527 | sdev1 = scsi_device_lookup(host, i, j, 0); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7528 | if (instance->pd_list[pd_index].driveState == |
| 7529 | MR_PD_STATE_SYSTEM) { |
| 7530 | if (!sdev1) |
| 7531 | scsi_add_device(host, i, j, 0); |
| 7532 | else |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7533 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7534 | } else { |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 7535 | if (sdev1) |
| 7536 | megasas_remove_scsi_device(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7537 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7538 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7539 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7540 | } |
| 7541 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7542 | if (doscan & SCAN_VD_CHANNEL) { |
| 7543 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 7544 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 7545 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 7546 | sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7547 | if (instance->ld_ids[ld_index] != 0xff) { |
| 7548 | if (!sdev1) |
| 7549 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 7550 | else |
| 7551 | scsi_device_put(sdev1); |
| 7552 | } else { |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 7553 | if (sdev1) |
| 7554 | megasas_remove_scsi_device(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 7555 | } |
| 7556 | } |
| 7557 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7558 | } |
| 7559 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7560 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7561 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 7562 | else |
| 7563 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7564 | |
| 7565 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 7566 | class_locale.members.reserved = 0; |
| 7567 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 7568 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7569 | |
| 7570 | if (instance->aen_cmd != NULL) { |
| 7571 | kfree(ev); |
| 7572 | return; |
| 7573 | } |
| 7574 | |
| 7575 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7576 | error = megasas_register_aen(instance, seq_num, |
| 7577 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7578 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7579 | dev_err(&instance->pdev->dev, |
| 7580 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7581 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7582 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7583 | kfree(ev); |
| 7584 | } |
| 7585 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7586 | /** |
| 7587 | * megasas_init - Driver load entry point |
| 7588 | */ |
| 7589 | static int __init megasas_init(void) |
| 7590 | { |
| 7591 | int rval; |
| 7592 | |
| 7593 | /* |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 7594 | * Booted in kdump kernel, minimize memory footprints by |
| 7595 | * disabling few features |
| 7596 | */ |
| 7597 | if (reset_devices) { |
| 7598 | msix_vectors = 1; |
| 7599 | rdpq_enable = 0; |
| 7600 | dual_qdepth_disable = 1; |
| 7601 | } |
| 7602 | |
| 7603 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7604 | * Announce driver version and other information |
| 7605 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 7606 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7607 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 7608 | spin_lock_init(&poll_aen_lock); |
| 7609 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7610 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7611 | support_device_change = 1; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7612 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7613 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 7614 | |
| 7615 | /* |
| 7616 | * Register character device node |
| 7617 | */ |
| 7618 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 7619 | |
| 7620 | if (rval < 0) { |
| 7621 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 7622 | return rval; |
| 7623 | } |
| 7624 | |
| 7625 | megasas_mgmt_majorno = rval; |
| 7626 | |
| 7627 | /* |
| 7628 | * Register ourselves as PCI hotplug module |
| 7629 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 7630 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7631 | |
| 7632 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 7633 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7634 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7635 | } |
| 7636 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7637 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7638 | &driver_attr_version); |
| 7639 | if (rval) |
| 7640 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7641 | |
| 7642 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7643 | &driver_attr_release_date); |
| 7644 | if (rval) |
| 7645 | goto err_dcf_rel_date; |
| 7646 | |
| 7647 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7648 | &driver_attr_support_poll_for_event); |
| 7649 | if (rval) |
| 7650 | goto err_dcf_support_poll_for_event; |
| 7651 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7652 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 7653 | &driver_attr_dbg_lvl); |
| 7654 | if (rval) |
| 7655 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7656 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7657 | &driver_attr_support_device_change); |
| 7658 | if (rval) |
| 7659 | goto err_dcf_support_device_change; |
| 7660 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7661 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7662 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7663 | err_dcf_support_device_change: |
| 7664 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7665 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7666 | err_dcf_dbg_lvl: |
| 7667 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7668 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7669 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7670 | driver_remove_file(&megasas_pci_driver.driver, |
| 7671 | &driver_attr_release_date); |
| 7672 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7673 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 7674 | err_dcf_attr_ver: |
| 7675 | pci_unregister_driver(&megasas_pci_driver); |
| 7676 | err_pcidrv: |
| 7677 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 7678 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7679 | } |
| 7680 | |
| 7681 | /** |
| 7682 | * megasas_exit - Driver unload entry point |
| 7683 | */ |
| 7684 | static void __exit megasas_exit(void) |
| 7685 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7686 | driver_remove_file(&megasas_pci_driver.driver, |
| 7687 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7688 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 7689 | &driver_attr_support_poll_for_event); |
| 7690 | driver_remove_file(&megasas_pci_driver.driver, |
| 7691 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7692 | driver_remove_file(&megasas_pci_driver.driver, |
| 7693 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7694 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7695 | |
| 7696 | pci_unregister_driver(&megasas_pci_driver); |
| 7697 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 7698 | } |
| 7699 | |
| 7700 | module_init(megasas_init); |
| 7701 | module_exit(megasas_exit); |