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 |
Shivasharan S | 365597c | 2018-10-16 23:37:43 -0700 | [diff] [blame] | 5 | * Copyright (c) 2013-2016 Avago Technologies |
| 6 | * Copyright (c) 2016-2018 Broadcom Inc. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version 2 |
| 11 | * of the License, or (at your option) any later version. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 12 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 17 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 18 | * 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] | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 20 | * |
Shivasharan S | 365597c | 2018-10-16 23:37:43 -0700 | [diff] [blame] | 21 | * Authors: Broadcom Inc. |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 22 | * Sreenivas Bagalkote |
| 23 | * Sumant Patro |
| 24 | * Bo Yang |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 25 | * Adam Radford |
Shivasharan S | 365597c | 2018-10-16 23:37:43 -0700 | [diff] [blame] | 26 | * Kashyap Desai <kashyap.desai@broadcom.com> |
| 27 | * Sumit Saxena <sumit.saxena@broadcom.com> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 28 | * |
Shivasharan S | 365597c | 2018-10-16 23:37:43 -0700 | [diff] [blame] | 29 | * Send feedback to: megaraidlinux.pdl@broadcom.com |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/list.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 36 | #include <linux/moduleparam.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/interrupt.h> |
| 40 | #include <linux/delay.h> |
| 41 | #include <linux/uio.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 43 | #include <linux/uaccess.h> |
Shivasharan S | 318aaef | 2017-02-10 00:59:22 -0800 | [diff] [blame] | 44 | #include <asm/unaligned.h> |
Al Viro | 4339923 | 2005-10-04 17:36:04 +0100 | [diff] [blame] | 45 | #include <linux/fs.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 46 | #include <linux/compat.h> |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 47 | #include <linux/blkdev.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 48 | #include <linux/mutex.h> |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 49 | #include <linux/poll.h> |
Shivasharan S | def3e8d | 2017-08-23 04:47:03 -0700 | [diff] [blame] | 50 | #include <linux/vmalloc.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 51 | |
| 52 | #include <scsi/scsi.h> |
| 53 | #include <scsi/scsi_cmnd.h> |
| 54 | #include <scsi/scsi_device.h> |
| 55 | #include <scsi/scsi_host.h> |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 56 | #include <scsi/scsi_tcq.h> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 57 | #include "megaraid_sas_fusion.h" |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 58 | #include "megaraid_sas.h" |
| 59 | |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 60 | /* |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 61 | * Number of sectors per IO command |
| 62 | * Will be set in megasas_init_mfi if user does not provide |
| 63 | */ |
| 64 | static unsigned int max_sectors; |
| 65 | module_param_named(max_sectors, max_sectors, int, 0); |
| 66 | MODULE_PARM_DESC(max_sectors, |
| 67 | "Maximum number of sectors per IO command"); |
| 68 | |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 69 | static int msix_disable; |
| 70 | module_param(msix_disable, int, S_IRUGO); |
| 71 | MODULE_PARM_DESC(msix_disable, "Disable MSI-X interrupt handling. Default: 0"); |
| 72 | |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 73 | static unsigned int msix_vectors; |
| 74 | module_param(msix_vectors, int, S_IRUGO); |
| 75 | MODULE_PARM_DESC(msix_vectors, "MSI-X max vector count. Default: Set by FW"); |
| 76 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 77 | static int allow_vf_ioctls; |
| 78 | module_param(allow_vf_ioctls, int, S_IRUGO); |
| 79 | MODULE_PARM_DESC(allow_vf_ioctls, "Allow ioctls in SR-IOV VF mode. Default: 0"); |
| 80 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 81 | static unsigned int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH; |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 82 | module_param(throttlequeuedepth, int, S_IRUGO); |
| 83 | MODULE_PARM_DESC(throttlequeuedepth, |
| 84 | "Adapter queue depth when throttled due to I/O timeout. Default: 16"); |
| 85 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 86 | unsigned int resetwaittime = MEGASAS_RESET_WAIT_TIME; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 87 | module_param(resetwaittime, int, S_IRUGO); |
Shivasharan S | 1401371 | 2018-10-16 23:37:45 -0700 | [diff] [blame] | 88 | MODULE_PARM_DESC(resetwaittime, "Wait time in (1-180s) after I/O timeout before resetting adapter. Default: 180s"); |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 89 | |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 90 | int smp_affinity_enable = 1; |
| 91 | module_param(smp_affinity_enable, int, S_IRUGO); |
Colin Ian King | 55d9a1d | 2018-04-29 13:25:32 +0100 | [diff] [blame] | 92 | MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disable Default: enable(1)"); |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 93 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 94 | int rdpq_enable = 1; |
| 95 | module_param(rdpq_enable, int, S_IRUGO); |
Shivasharan S | 1401371 | 2018-10-16 23:37:45 -0700 | [diff] [blame] | 96 | MODULE_PARM_DESC(rdpq_enable, "Allocate reply queue in chunks for large queue depth enable/disable Default: enable(1)"); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 97 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 98 | unsigned int dual_qdepth_disable; |
| 99 | module_param(dual_qdepth_disable, int, S_IRUGO); |
| 100 | MODULE_PARM_DESC(dual_qdepth_disable, "Disable dual queue depth feature. Default: 0"); |
| 101 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 102 | unsigned int scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
| 103 | module_param(scmd_timeout, int, S_IRUGO); |
| 104 | MODULE_PARM_DESC(scmd_timeout, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer."); |
| 105 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 106 | MODULE_LICENSE("GPL"); |
| 107 | MODULE_VERSION(MEGASAS_VERSION); |
Shivasharan S | 365597c | 2018-10-16 23:37:43 -0700 | [diff] [blame] | 108 | MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com"); |
| 109 | MODULE_DESCRIPTION("Broadcom MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 110 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 111 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 112 | static int megasas_get_pd_list(struct megasas_instance *instance); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 113 | static int megasas_ld_list_query(struct megasas_instance *instance, |
| 114 | u8 query_type); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 115 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 116 | static int megasas_register_aen(struct megasas_instance *instance, |
| 117 | u32 seq_num, u32 class_locale_word); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 118 | static void megasas_get_pd_info(struct megasas_instance *instance, |
| 119 | struct scsi_device *sdev); |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 120 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 121 | /* |
| 122 | * PCI ID table for all supported controllers |
| 123 | */ |
| 124 | static struct pci_device_id megasas_pci_table[] = { |
| 125 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 126 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 127 | /* xscale IOP */ |
| 128 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 129 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 130 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 131 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 132 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 133 | /* gen2*/ |
| 134 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 135 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 136 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 137 | /* skinny*/ |
| 138 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 139 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 140 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 141 | /* xscale IOP, vega */ |
| 142 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 143 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 144 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 145 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 146 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 147 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 148 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 149 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 150 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 151 | /* Fury */ |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 152 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER)}, |
| 153 | /* Intruder */ |
| 154 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER_24)}, |
| 155 | /* Intruder 24 port*/ |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 156 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)}, |
| 157 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_53)}, |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 158 | /* VENTURA */ |
| 159 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA)}, |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 160 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER)}, |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 161 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_HARPOON)}, |
| 162 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)}, |
| 163 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)}, |
| 164 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER_4PORT)}, |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 165 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E1)}, |
| 166 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E2)}, |
| 167 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E5)}, |
| 168 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E6)}, |
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; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 184 | static bool support_nvme_encapsulation; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 185 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 186 | /* define lock for aen poll */ |
| 187 | spinlock_t poll_aen_lock; |
| 188 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 189 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 190 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 191 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 192 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 193 | megasas_read_fw_status_reg_gen2(struct megasas_instance *instance); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 194 | static int |
| 195 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 196 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 197 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 198 | static u32 |
| 199 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 200 | u32 |
| 201 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 202 | struct scsi_cmnd *scmd); |
| 203 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 204 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 205 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 206 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 207 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 208 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 209 | int initial); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 210 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 211 | megasas_set_dma_mask(struct megasas_instance *instance); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 212 | static int |
| 213 | megasas_alloc_ctrl_mem(struct megasas_instance *instance); |
| 214 | static inline void |
| 215 | megasas_free_ctrl_mem(struct megasas_instance *instance); |
| 216 | static inline int |
| 217 | megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance); |
| 218 | static inline void |
| 219 | megasas_free_ctrl_dma_buffers(struct megasas_instance *instance); |
| 220 | static inline void |
| 221 | megasas_init_ctrl_params(struct megasas_instance *instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 222 | |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 223 | u32 megasas_readl(struct megasas_instance *instance, |
| 224 | const volatile void __iomem *addr) |
| 225 | { |
| 226 | u32 i = 0, ret_val; |
| 227 | /* |
| 228 | * Due to a HW errata in Aero controllers, reads to certain |
| 229 | * Fusion registers could intermittently return all zeroes. |
| 230 | * This behavior is transient in nature and subsequent reads will |
| 231 | * return valid value. As a workaround in driver, retry readl for |
| 232 | * upto three times until a non-zero value is read. |
| 233 | */ |
| 234 | if (instance->adapter_type == AERO_SERIES) { |
| 235 | do { |
| 236 | ret_val = readl(addr); |
| 237 | i++; |
| 238 | } while (ret_val == 0 && i < 3); |
| 239 | return ret_val; |
| 240 | } else { |
| 241 | return readl(addr); |
| 242 | } |
| 243 | } |
| 244 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 245 | /** |
| 246 | * megasas_set_dma_settings - Populate DMA address, length and flags for DCMDs |
| 247 | * @instance: Adapter soft state |
| 248 | * @dcmd: DCMD frame inside MFI command |
| 249 | * @dma_addr: DMA address of buffer to be passed to FW |
| 250 | * @dma_len: Length of DMA buffer to be passed to FW |
| 251 | * @return: void |
| 252 | */ |
| 253 | void megasas_set_dma_settings(struct megasas_instance *instance, |
| 254 | struct megasas_dcmd_frame *dcmd, |
| 255 | dma_addr_t dma_addr, u32 dma_len) |
| 256 | { |
| 257 | if (instance->consistent_mask_64bit) { |
| 258 | dcmd->sgl.sge64[0].phys_addr = cpu_to_le64(dma_addr); |
| 259 | dcmd->sgl.sge64[0].length = cpu_to_le32(dma_len); |
| 260 | dcmd->flags = cpu_to_le16(dcmd->flags | MFI_FRAME_SGL64); |
| 261 | |
| 262 | } else { |
| 263 | dcmd->sgl.sge32[0].phys_addr = |
| 264 | cpu_to_le32(lower_32_bits(dma_addr)); |
| 265 | dcmd->sgl.sge32[0].length = cpu_to_le32(dma_len); |
| 266 | dcmd->flags = cpu_to_le16(dcmd->flags); |
| 267 | } |
| 268 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 269 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 270 | void |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 271 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 272 | { |
| 273 | instance->instancet->fire_cmd(instance, |
| 274 | cmd->frame_phys_addr, 0, instance->reg_set); |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 275 | return; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 276 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 277 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 278 | /** |
| 279 | * megasas_get_cmd - Get a command from the free pool |
| 280 | * @instance: Adapter soft state |
| 281 | * |
| 282 | * Returns a free command from the pool |
| 283 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 284 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 285 | *instance) |
| 286 | { |
| 287 | unsigned long flags; |
| 288 | struct megasas_cmd *cmd = NULL; |
| 289 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 290 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 291 | |
| 292 | if (!list_empty(&instance->cmd_pool)) { |
| 293 | cmd = list_entry((&instance->cmd_pool)->next, |
| 294 | struct megasas_cmd, list); |
| 295 | list_del_init(&cmd->list); |
| 296 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 297 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 298 | } |
| 299 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 300 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 301 | return cmd; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * megasas_return_cmd - Return a cmd to free command pool |
| 306 | * @instance: Adapter soft state |
| 307 | * @cmd: Command packet to be returned to free command pool |
| 308 | */ |
Andi Kleen | 68b4374 | 2017-05-08 15:58:53 -0700 | [diff] [blame] | 309 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 310 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 311 | { |
| 312 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 313 | u32 blk_tags; |
| 314 | struct megasas_cmd_fusion *cmd_fusion; |
| 315 | struct fusion_context *fusion = instance->ctrl_context; |
| 316 | |
| 317 | /* This flag is used only for fusion adapter. |
| 318 | * Wait for Interrupt for Polled mode DCMD |
| 319 | */ |
| 320 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 321 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 322 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 323 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 324 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 325 | if (fusion) { |
| 326 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 327 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 328 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 329 | } |
| 330 | cmd->scmd = NULL; |
| 331 | cmd->frame_count = 0; |
| 332 | cmd->flags = 0; |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 333 | memset(cmd->frame, 0, instance->mfi_frame_size); |
| 334 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 335 | if (!fusion && reset_devices) |
| 336 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 337 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 338 | |
| 339 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 340 | |
| 341 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 342 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 343 | static const char * |
| 344 | format_timestamp(uint32_t timestamp) |
| 345 | { |
| 346 | static char buffer[32]; |
| 347 | |
| 348 | if ((timestamp & 0xff000000) == 0xff000000) |
| 349 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 350 | 0x00ffffff); |
| 351 | else |
| 352 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 353 | return buffer; |
| 354 | } |
| 355 | |
| 356 | static const char * |
| 357 | format_class(int8_t class) |
| 358 | { |
| 359 | static char buffer[6]; |
| 360 | |
| 361 | switch (class) { |
| 362 | case MFI_EVT_CLASS_DEBUG: |
| 363 | return "debug"; |
| 364 | case MFI_EVT_CLASS_PROGRESS: |
| 365 | return "progress"; |
| 366 | case MFI_EVT_CLASS_INFO: |
| 367 | return "info"; |
| 368 | case MFI_EVT_CLASS_WARNING: |
| 369 | return "WARN"; |
| 370 | case MFI_EVT_CLASS_CRITICAL: |
| 371 | return "CRIT"; |
| 372 | case MFI_EVT_CLASS_FATAL: |
| 373 | return "FATAL"; |
| 374 | case MFI_EVT_CLASS_DEAD: |
| 375 | return "DEAD"; |
| 376 | default: |
| 377 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 378 | return buffer; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 384 | * for information. |
| 385 | * @instance: Adapter soft state |
| 386 | */ |
| 387 | static void |
| 388 | megasas_decode_evt(struct megasas_instance *instance) |
| 389 | { |
| 390 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 391 | union megasas_evt_class_locale class_locale; |
| 392 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 393 | |
| 394 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 395 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 396 | le32_to_cpu(evt_detail->seq_num), |
| 397 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 398 | (class_locale.members.locale), |
| 399 | format_class(class_locale.members.class), |
| 400 | evt_detail->description); |
| 401 | } |
| 402 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 403 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 404 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 405 | * (deviceid : 1064R, PERC5) controllers |
| 406 | */ |
| 407 | |
| 408 | /** |
| 409 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 410 | * @regs: MFI register set |
| 411 | */ |
| 412 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 413 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 414 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 415 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 416 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 417 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 418 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 419 | |
| 420 | /* Dummy readl to force pci flush */ |
| 421 | readl(®s->outbound_intr_mask); |
| 422 | } |
| 423 | |
| 424 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 425 | * megasas_disable_intr_xscale -Disables interrupt |
| 426 | * @regs: MFI register set |
| 427 | */ |
| 428 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 429 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 430 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 431 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 432 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 433 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 434 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 435 | writel(mask, ®s->outbound_intr_mask); |
| 436 | /* Dummy readl to force pci flush */ |
| 437 | readl(®s->outbound_intr_mask); |
| 438 | } |
| 439 | |
| 440 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 441 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 442 | * @regs: MFI register set |
| 443 | */ |
| 444 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 445 | megasas_read_fw_status_reg_xscale(struct megasas_instance *instance) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 446 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 447 | return readl(&instance->reg_set->outbound_msg_0); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 448 | } |
| 449 | /** |
| 450 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 451 | * @regs: MFI register set |
| 452 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 453 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 454 | megasas_clear_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 455 | { |
| 456 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 457 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 458 | struct megasas_register_set __iomem *regs; |
| 459 | regs = instance->reg_set; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 460 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 461 | /* |
| 462 | * Check if it is our interrupt |
| 463 | */ |
| 464 | status = readl(®s->outbound_intr_status); |
| 465 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 466 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 467 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 468 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 469 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 470 | |
| 471 | /* |
| 472 | * Clear the interrupt by writing back the same value |
| 473 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 474 | if (mfiStatus) |
| 475 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 476 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 477 | /* Dummy readl to force pci flush */ |
| 478 | readl(®s->outbound_intr_status); |
| 479 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 480 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /** |
| 484 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 485 | * @frame_phys_addr : Physical address of cmd |
| 486 | * @frame_count : Number of frames for the command |
| 487 | * @regs : MFI register set |
| 488 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 489 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 490 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 491 | dma_addr_t frame_phys_addr, |
| 492 | u32 frame_count, |
| 493 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 494 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 495 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 496 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 497 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 498 | writel((frame_phys_addr >> 3)|(frame_count), |
| 499 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 500 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * megasas_adp_reset_xscale - For controller reset |
| 505 | * @regs: MFI register set |
| 506 | */ |
| 507 | static int |
| 508 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 509 | struct megasas_register_set __iomem *regs) |
| 510 | { |
| 511 | u32 i; |
| 512 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 513 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 514 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 515 | |
| 516 | for (i = 0; i < 3; i++) |
| 517 | msleep(1000); /* sleep for 3 secs */ |
| 518 | pcidata = 0; |
| 519 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 520 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 521 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 522 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 523 | pcidata &= ~0x2; |
| 524 | pci_write_config_dword(instance->pdev, |
| 525 | MFI_1068_PCSR_OFFSET, pcidata); |
| 526 | |
| 527 | for (i = 0; i < 2; i++) |
| 528 | msleep(1000); /* need to wait 2 secs again */ |
| 529 | |
| 530 | pcidata = 0; |
| 531 | pci_read_config_dword(instance->pdev, |
| 532 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 533 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 534 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 535 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 536 | pcidata = 0; |
| 537 | pci_write_config_dword(instance->pdev, |
| 538 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 539 | } |
| 540 | } |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * megasas_check_reset_xscale - For controller reset check |
| 546 | * @regs: MFI register set |
| 547 | */ |
| 548 | static int |
| 549 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 550 | struct megasas_register_set __iomem *regs) |
| 551 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 552 | if ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 553 | (le32_to_cpu(*instance->consumer) == |
| 554 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 555 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 556 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 560 | |
| 561 | .fire_cmd = megasas_fire_cmd_xscale, |
| 562 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 563 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 564 | .clear_intr = megasas_clear_intr_xscale, |
| 565 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 566 | .adp_reset = megasas_adp_reset_xscale, |
| 567 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 568 | .service_isr = megasas_isr, |
| 569 | .tasklet = megasas_complete_cmd_dpc, |
| 570 | .init_adapter = megasas_init_adapter_mfi, |
| 571 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 572 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 573 | }; |
| 574 | |
| 575 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 576 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 577 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 578 | */ |
| 579 | |
| 580 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 581 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 582 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 583 | */ |
| 584 | |
| 585 | /** |
| 586 | * megasas_enable_intr_ppc - Enables interrupts |
| 587 | * @regs: MFI register set |
| 588 | */ |
| 589 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 590 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 591 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 592 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 593 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 594 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 595 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 596 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 597 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 598 | |
| 599 | /* Dummy readl to force pci flush */ |
| 600 | readl(®s->outbound_intr_mask); |
| 601 | } |
| 602 | |
| 603 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 604 | * megasas_disable_intr_ppc - Disable interrupt |
| 605 | * @regs: MFI register set |
| 606 | */ |
| 607 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 608 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 609 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 610 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 611 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 612 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 613 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 614 | writel(mask, ®s->outbound_intr_mask); |
| 615 | /* Dummy readl to force pci flush */ |
| 616 | readl(®s->outbound_intr_mask); |
| 617 | } |
| 618 | |
| 619 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 620 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 621 | * @regs: MFI register set |
| 622 | */ |
| 623 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 624 | megasas_read_fw_status_reg_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 625 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 626 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | /** |
| 630 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 631 | * @regs: MFI register set |
| 632 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 633 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 634 | megasas_clear_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 635 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 636 | u32 status, mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 637 | struct megasas_register_set __iomem *regs; |
| 638 | regs = instance->reg_set; |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 639 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 640 | /* |
| 641 | * Check if it is our interrupt |
| 642 | */ |
| 643 | status = readl(®s->outbound_intr_status); |
| 644 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 645 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 646 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 647 | |
| 648 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 649 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 650 | |
| 651 | /* |
| 652 | * Clear the interrupt by writing back the same value |
| 653 | */ |
| 654 | writel(status, ®s->outbound_doorbell_clear); |
| 655 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 656 | /* Dummy readl to force pci flush */ |
| 657 | readl(®s->outbound_doorbell_clear); |
| 658 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 659 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 660 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 661 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 662 | /** |
| 663 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 664 | * @frame_phys_addr : Physical address of cmd |
| 665 | * @frame_count : Number of frames for the command |
| 666 | * @regs : MFI register set |
| 667 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 668 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 669 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 670 | dma_addr_t frame_phys_addr, |
| 671 | u32 frame_count, |
| 672 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 673 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 674 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 675 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 676 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 677 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 678 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 679 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 680 | } |
| 681 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 682 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 683 | * megasas_check_reset_ppc - For controller reset check |
| 684 | * @regs: MFI register set |
| 685 | */ |
| 686 | static int |
| 687 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 688 | struct megasas_register_set __iomem *regs) |
| 689 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 690 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 691 | return 1; |
| 692 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 693 | return 0; |
| 694 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 695 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 696 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 697 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 698 | .fire_cmd = megasas_fire_cmd_ppc, |
| 699 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 700 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 701 | .clear_intr = megasas_clear_intr_ppc, |
| 702 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 703 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 704 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 705 | .service_isr = megasas_isr, |
| 706 | .tasklet = megasas_complete_cmd_dpc, |
| 707 | .init_adapter = megasas_init_adapter_mfi, |
| 708 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 709 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 710 | }; |
| 711 | |
| 712 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 713 | * megasas_enable_intr_skinny - Enables interrupts |
| 714 | * @regs: MFI register set |
| 715 | */ |
| 716 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 717 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 718 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 719 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 720 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 721 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 722 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 723 | |
| 724 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 725 | |
| 726 | /* Dummy readl to force pci flush */ |
| 727 | readl(®s->outbound_intr_mask); |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * megasas_disable_intr_skinny - Disables interrupt |
| 732 | * @regs: MFI register set |
| 733 | */ |
| 734 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 735 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 736 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 737 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 738 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 739 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 740 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 741 | writel(mask, ®s->outbound_intr_mask); |
| 742 | /* Dummy readl to force pci flush */ |
| 743 | readl(®s->outbound_intr_mask); |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 748 | * @regs: MFI register set |
| 749 | */ |
| 750 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 751 | megasas_read_fw_status_reg_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 752 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 753 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | /** |
| 757 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 758 | * @regs: MFI register set |
| 759 | */ |
| 760 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 761 | megasas_clear_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 762 | { |
| 763 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 764 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 765 | struct megasas_register_set __iomem *regs; |
| 766 | regs = instance->reg_set; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 767 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 768 | /* |
| 769 | * Check if it is our interrupt |
| 770 | */ |
| 771 | status = readl(®s->outbound_intr_status); |
| 772 | |
| 773 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 774 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 778 | * Check if it is our interrupt |
| 779 | */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 780 | if ((megasas_read_fw_status_reg_skinny(instance) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 781 | MFI_STATE_FAULT) { |
| 782 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 783 | } else |
| 784 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 785 | |
| 786 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 787 | * Clear the interrupt by writing back the same value |
| 788 | */ |
| 789 | writel(status, ®s->outbound_intr_status); |
| 790 | |
| 791 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 792 | * dummy read to flush PCI |
| 793 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 794 | readl(®s->outbound_intr_status); |
| 795 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 796 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | /** |
| 800 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 801 | * @frame_phys_addr : Physical address of cmd |
| 802 | * @frame_count : Number of frames for the command |
| 803 | * @regs : MFI register set |
| 804 | */ |
| 805 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 806 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 807 | dma_addr_t frame_phys_addr, |
| 808 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 809 | struct megasas_register_set __iomem *regs) |
| 810 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 811 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 812 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 813 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 814 | writel(upper_32_bits(frame_phys_addr), |
| 815 | &(regs)->inbound_high_queue_port); |
| 816 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 817 | &(regs)->inbound_low_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 818 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 819 | } |
| 820 | |
| 821 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 822 | * megasas_check_reset_skinny - For controller reset check |
| 823 | * @regs: MFI register set |
| 824 | */ |
| 825 | static int |
| 826 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 827 | struct megasas_register_set __iomem *regs) |
| 828 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 829 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 830 | return 1; |
| 831 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 832 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 836 | |
| 837 | .fire_cmd = megasas_fire_cmd_skinny, |
| 838 | .enable_intr = megasas_enable_intr_skinny, |
| 839 | .disable_intr = megasas_disable_intr_skinny, |
| 840 | .clear_intr = megasas_clear_intr_skinny, |
| 841 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 842 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 843 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 844 | .service_isr = megasas_isr, |
| 845 | .tasklet = megasas_complete_cmd_dpc, |
| 846 | .init_adapter = megasas_init_adapter_mfi, |
| 847 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 848 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 849 | }; |
| 850 | |
| 851 | |
| 852 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 853 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 854 | * controllers |
| 855 | */ |
| 856 | |
| 857 | /** |
| 858 | * megasas_enable_intr_gen2 - Enables interrupts |
| 859 | * @regs: MFI register set |
| 860 | */ |
| 861 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 862 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 863 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 864 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 865 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 866 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 867 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 868 | |
| 869 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 870 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 871 | |
| 872 | /* Dummy readl to force pci flush */ |
| 873 | readl(®s->outbound_intr_mask); |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * megasas_disable_intr_gen2 - Disables interrupt |
| 878 | * @regs: MFI register set |
| 879 | */ |
| 880 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 881 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 882 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 883 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 884 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 885 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 886 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 887 | writel(mask, ®s->outbound_intr_mask); |
| 888 | /* Dummy readl to force pci flush */ |
| 889 | readl(®s->outbound_intr_mask); |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 894 | * @regs: MFI register set |
| 895 | */ |
| 896 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 897 | megasas_read_fw_status_reg_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 898 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 899 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | /** |
| 903 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 904 | * @regs: MFI register set |
| 905 | */ |
| 906 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 907 | megasas_clear_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 908 | { |
| 909 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 910 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 911 | struct megasas_register_set __iomem *regs; |
| 912 | regs = instance->reg_set; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 913 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 914 | /* |
| 915 | * Check if it is our interrupt |
| 916 | */ |
| 917 | status = readl(®s->outbound_intr_status); |
| 918 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 919 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 920 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 921 | } |
| 922 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 923 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 924 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 925 | |
| 926 | /* |
| 927 | * Clear the interrupt by writing back the same value |
| 928 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 929 | if (mfiStatus) |
| 930 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 931 | |
| 932 | /* Dummy readl to force pci flush */ |
| 933 | readl(®s->outbound_intr_status); |
| 934 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 935 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 936 | } |
| 937 | /** |
| 938 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 939 | * @frame_phys_addr : Physical address of cmd |
| 940 | * @frame_count : Number of frames for the command |
| 941 | * @regs : MFI register set |
| 942 | */ |
| 943 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 944 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 945 | dma_addr_t frame_phys_addr, |
| 946 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 947 | struct megasas_register_set __iomem *regs) |
| 948 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 949 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 950 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 951 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 952 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 953 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 954 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 955 | } |
| 956 | |
| 957 | /** |
| 958 | * megasas_adp_reset_gen2 - For controller reset |
| 959 | * @regs: MFI register set |
| 960 | */ |
| 961 | static int |
| 962 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 963 | struct megasas_register_set __iomem *reg_set) |
| 964 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 965 | u32 retry = 0 ; |
| 966 | u32 HostDiag; |
| 967 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 968 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 969 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 970 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 971 | seq_offset = ®_set->fusion_seq_offset; |
| 972 | hostdiag_offset = ®_set->fusion_host_diag; |
| 973 | } |
| 974 | |
| 975 | writel(0, seq_offset); |
| 976 | writel(4, seq_offset); |
| 977 | writel(0xb, seq_offset); |
| 978 | writel(2, seq_offset); |
| 979 | writel(7, seq_offset); |
| 980 | writel(0xd, seq_offset); |
| 981 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 982 | msleep(1000); |
| 983 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 984 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 985 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 986 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 987 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 988 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 989 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 990 | retry, HostDiag); |
| 991 | |
| 992 | if (retry++ >= 100) |
| 993 | return 1; |
| 994 | |
| 995 | } |
| 996 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 997 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 998 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 999 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1000 | |
| 1001 | ssleep(10); |
| 1002 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1003 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1004 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1005 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1006 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1007 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1008 | retry, HostDiag); |
| 1009 | |
| 1010 | if (retry++ >= 1000) |
| 1011 | return 1; |
| 1012 | |
| 1013 | } |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * megasas_check_reset_gen2 - For controller reset check |
| 1019 | * @regs: MFI register set |
| 1020 | */ |
| 1021 | static int |
| 1022 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 1023 | struct megasas_register_set __iomem *regs) |
| 1024 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1025 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1026 | return 1; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1027 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1028 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 1032 | |
| 1033 | .fire_cmd = megasas_fire_cmd_gen2, |
| 1034 | .enable_intr = megasas_enable_intr_gen2, |
| 1035 | .disable_intr = megasas_disable_intr_gen2, |
| 1036 | .clear_intr = megasas_clear_intr_gen2, |
| 1037 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1038 | .adp_reset = megasas_adp_reset_gen2, |
| 1039 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1040 | .service_isr = megasas_isr, |
| 1041 | .tasklet = megasas_complete_cmd_dpc, |
| 1042 | .init_adapter = megasas_init_adapter_mfi, |
| 1043 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 1044 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 1045 | }; |
| 1046 | |
| 1047 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1048 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1049 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1050 | */ |
| 1051 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1052 | /* |
| 1053 | * Template added for TB (Fusion) |
| 1054 | */ |
| 1055 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 1056 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1057 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1058 | * megasas_issue_polled - Issues a polling command |
| 1059 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1060 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1061 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1062 | * 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] | 1063 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1064 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1065 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 1066 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1067 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 1068 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1069 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1070 | 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] | 1071 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1072 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1073 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1074 | __func__, __LINE__); |
| 1075 | return DCMD_NOT_FIRED; |
| 1076 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1077 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1078 | instance->instancet->issue_dcmd(instance, cmd); |
| 1079 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1080 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 1081 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1086 | * @instance: Adapter soft state |
| 1087 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1088 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1089 | * |
| 1090 | * 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] | 1091 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1092 | * Used to issue ioctl commands. |
| 1093 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1094 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1095 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1096 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1097 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1098 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1099 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1100 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1101 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1102 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1103 | __func__, __LINE__); |
| 1104 | return DCMD_NOT_FIRED; |
| 1105 | } |
| 1106 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1107 | instance->instancet->issue_dcmd(instance, cmd); |
| 1108 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1109 | if (timeout) { |
| 1110 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1111 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1112 | if (!ret) { |
| 1113 | dev_err(&instance->pdev->dev, "Failed from %s %d DCMD Timed out\n", |
| 1114 | __func__, __LINE__); |
| 1115 | return DCMD_TIMEOUT; |
| 1116 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1117 | } else |
| 1118 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1119 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1120 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1121 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1122 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1127 | * @instance: Adapter soft state |
| 1128 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1129 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1130 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1131 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1132 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1133 | * cmd and waits for return status. |
| 1134 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1135 | */ |
| 1136 | static int |
| 1137 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1138 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1139 | { |
| 1140 | struct megasas_cmd *cmd; |
| 1141 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1142 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1143 | |
| 1144 | cmd = megasas_get_cmd(instance); |
| 1145 | |
| 1146 | if (!cmd) |
| 1147 | return -1; |
| 1148 | |
| 1149 | abort_fr = &cmd->frame->abort; |
| 1150 | |
| 1151 | /* |
| 1152 | * Prepare and issue the abort frame |
| 1153 | */ |
| 1154 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1155 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1156 | abort_fr->flags = cpu_to_le16(0); |
| 1157 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1158 | abort_fr->abort_mfi_phys_addr_lo = |
| 1159 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1160 | abort_fr->abort_mfi_phys_addr_hi = |
| 1161 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1162 | |
| 1163 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1164 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1165 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1166 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1167 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1168 | __func__, __LINE__); |
| 1169 | return DCMD_NOT_FIRED; |
| 1170 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1171 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1172 | instance->instancet->issue_dcmd(instance, cmd); |
| 1173 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1174 | if (timeout) { |
| 1175 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1176 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1177 | if (!ret) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1178 | dev_err(&instance->pdev->dev, "Failed from %s %d Abort Timed out\n", |
| 1179 | __func__, __LINE__); |
| 1180 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1181 | } |
| 1182 | } else |
| 1183 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1184 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1185 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1186 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1187 | |
| 1188 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1189 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1190 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | /** |
| 1194 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1195 | * @instance: Adapter soft state |
| 1196 | * @scp: SCSI command from the mid-layer |
| 1197 | * @mfi_sgl: SGL to be filled in |
| 1198 | * |
| 1199 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1200 | * it returnes -1. |
| 1201 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1202 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1203 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1204 | union megasas_sgl *mfi_sgl) |
| 1205 | { |
| 1206 | int i; |
| 1207 | int sge_count; |
| 1208 | struct scatterlist *os_sgl; |
| 1209 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1210 | sge_count = scsi_dma_map(scp); |
| 1211 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1212 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1213 | if (sge_count) { |
| 1214 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1215 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1216 | 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] | 1217 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1218 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1219 | return sge_count; |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1224 | * @instance: Adapter soft state |
| 1225 | * @scp: SCSI command from the mid-layer |
| 1226 | * @mfi_sgl: SGL to be filled in |
| 1227 | * |
| 1228 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1229 | * it returnes -1. |
| 1230 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1231 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1232 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1233 | union megasas_sgl *mfi_sgl) |
| 1234 | { |
| 1235 | int i; |
| 1236 | int sge_count; |
| 1237 | struct scatterlist *os_sgl; |
| 1238 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1239 | sge_count = scsi_dma_map(scp); |
| 1240 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1241 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1242 | if (sge_count) { |
| 1243 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1244 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1245 | 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] | 1246 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1247 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1248 | return sge_count; |
| 1249 | } |
| 1250 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1251 | /** |
| 1252 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1253 | * @instance: Adapter soft state |
| 1254 | * @scp: SCSI command from the mid-layer |
| 1255 | * @mfi_sgl: SGL to be filled in |
| 1256 | * |
| 1257 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1258 | * it returnes -1. |
| 1259 | */ |
| 1260 | static int |
| 1261 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1262 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1263 | { |
| 1264 | int i; |
| 1265 | int sge_count; |
| 1266 | struct scatterlist *os_sgl; |
| 1267 | |
| 1268 | sge_count = scsi_dma_map(scp); |
| 1269 | |
| 1270 | if (sge_count) { |
| 1271 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1272 | mfi_sgl->sge_skinny[i].length = |
| 1273 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1274 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1275 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1276 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | return sge_count; |
| 1280 | } |
| 1281 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1282 | /** |
| 1283 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1284 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1285 | * @sge_count : number of sg elements |
| 1286 | * |
| 1287 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1288 | */ |
| 1289 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1290 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1291 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1292 | { |
| 1293 | int num_cnt; |
| 1294 | int sge_bytes; |
| 1295 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1296 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1297 | |
| 1298 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1299 | sizeof(struct megasas_sge32); |
| 1300 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1301 | if (instance->flag_ieee) { |
| 1302 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1303 | } |
| 1304 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1305 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1306 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1307 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1308 | * 1 SGEs for 64-bit SGLs and |
| 1309 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1310 | */ |
| 1311 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1312 | if (instance->flag_ieee == 1) { |
| 1313 | num_cnt = sge_count - 1; |
| 1314 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1315 | num_cnt = sge_count - 1; |
| 1316 | else |
| 1317 | num_cnt = sge_count - 2; |
| 1318 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1319 | if (instance->flag_ieee == 1) { |
| 1320 | num_cnt = sge_count - 1; |
| 1321 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1322 | num_cnt = sge_count - 2; |
| 1323 | else |
| 1324 | num_cnt = sge_count - 3; |
| 1325 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1326 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1327 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1328 | sge_bytes = sge_sz * num_cnt; |
| 1329 | |
| 1330 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1331 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1332 | } |
| 1333 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1334 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1335 | |
| 1336 | if (frame_count > 7) |
| 1337 | frame_count = 8; |
| 1338 | return frame_count; |
| 1339 | } |
| 1340 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1341 | /** |
| 1342 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1343 | * @instance: Adapter soft state |
| 1344 | * @scp: SCSI command |
| 1345 | * @cmd: Command to be prepared in |
| 1346 | * |
| 1347 | * This function prepares CDB commands. These are typcially pass-through |
| 1348 | * commands to the devices. |
| 1349 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1350 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1351 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1352 | struct megasas_cmd *cmd) |
| 1353 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1354 | u32 is_logical; |
| 1355 | u32 device_id; |
| 1356 | u16 flags = 0; |
| 1357 | struct megasas_pthru_frame *pthru; |
| 1358 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1359 | is_logical = MEGASAS_IS_LOGICAL(scp->device); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1360 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1361 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1362 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1363 | if (scp->sc_data_direction == DMA_TO_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1364 | flags = MFI_FRAME_DIR_WRITE; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1365 | else if (scp->sc_data_direction == DMA_FROM_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1366 | flags = MFI_FRAME_DIR_READ; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1367 | else if (scp->sc_data_direction == DMA_NONE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1368 | flags = MFI_FRAME_DIR_NONE; |
| 1369 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1370 | if (instance->flag_ieee == 1) { |
| 1371 | flags |= MFI_FRAME_IEEE; |
| 1372 | } |
| 1373 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1374 | /* |
| 1375 | * Prepare the DCDB frame |
| 1376 | */ |
| 1377 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1378 | pthru->cmd_status = 0x0; |
| 1379 | pthru->scsi_status = 0x0; |
| 1380 | pthru->target_id = device_id; |
| 1381 | pthru->lun = scp->device->lun; |
| 1382 | pthru->cdb_len = scp->cmd_len; |
| 1383 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1384 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1385 | pthru->flags = cpu_to_le16(flags); |
| 1386 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1387 | |
| 1388 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1389 | |
| 1390 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1391 | * If the command is for the tape device, set the |
| 1392 | * pthru timeout to the os layer timeout value. |
| 1393 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1394 | if (scp->device->type == TYPE_TAPE) { |
| 1395 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1396 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1397 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1398 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1402 | * Construct SGL |
| 1403 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1404 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1405 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1406 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1407 | &pthru->sgl); |
| 1408 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1409 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1410 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1411 | &pthru->sgl); |
| 1412 | } else |
| 1413 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1414 | &pthru->sgl); |
| 1415 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1416 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1417 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1418 | pthru->sge_count); |
| 1419 | return 0; |
| 1420 | } |
| 1421 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1422 | /* |
| 1423 | * Sense info specific |
| 1424 | */ |
| 1425 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1426 | pthru->sense_buf_phys_addr_hi = |
| 1427 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1428 | pthru->sense_buf_phys_addr_lo = |
| 1429 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1430 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1431 | /* |
| 1432 | * Compute the total number of frames this command consumes. FW uses |
| 1433 | * this number to pull sufficient number of frames from host memory. |
| 1434 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1435 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1436 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1437 | |
| 1438 | return cmd->frame_count; |
| 1439 | } |
| 1440 | |
| 1441 | /** |
| 1442 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1443 | * @instance: Adapter soft state |
| 1444 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1445 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1446 | * |
| 1447 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1448 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1449 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1450 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1451 | struct megasas_cmd *cmd) |
| 1452 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1453 | u32 device_id; |
| 1454 | u8 sc = scp->cmnd[0]; |
| 1455 | u16 flags = 0; |
| 1456 | struct megasas_io_frame *ldio; |
| 1457 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1458 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1459 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1460 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1461 | if (scp->sc_data_direction == DMA_TO_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1462 | flags = MFI_FRAME_DIR_WRITE; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1463 | else if (scp->sc_data_direction == DMA_FROM_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1464 | flags = MFI_FRAME_DIR_READ; |
| 1465 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1466 | if (instance->flag_ieee == 1) { |
| 1467 | flags |= MFI_FRAME_IEEE; |
| 1468 | } |
| 1469 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1470 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1471 | * 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] | 1472 | */ |
| 1473 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1474 | ldio->cmd_status = 0x0; |
| 1475 | ldio->scsi_status = 0x0; |
| 1476 | ldio->target_id = device_id; |
| 1477 | ldio->timeout = 0; |
| 1478 | ldio->reserved_0 = 0; |
| 1479 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1480 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1481 | ldio->start_lba_hi = 0; |
| 1482 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1483 | |
| 1484 | /* |
| 1485 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1486 | */ |
| 1487 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1488 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1489 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1490 | ((u32) scp->cmnd[2] << 8) | |
| 1491 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1492 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1493 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | /* |
| 1497 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1498 | */ |
| 1499 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1500 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1501 | ((u32) scp->cmnd[7] << 8)); |
| 1502 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1503 | ((u32) scp->cmnd[3] << 16) | |
| 1504 | ((u32) scp->cmnd[4] << 8) | |
| 1505 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1506 | } |
| 1507 | |
| 1508 | /* |
| 1509 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1510 | */ |
| 1511 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1512 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1513 | ((u32) scp->cmnd[7] << 16) | |
| 1514 | ((u32) scp->cmnd[8] << 8) | |
| 1515 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1516 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1517 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1518 | ((u32) scp->cmnd[3] << 16) | |
| 1519 | ((u32) scp->cmnd[4] << 8) | |
| 1520 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | /* |
| 1524 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1525 | */ |
| 1526 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1527 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1528 | ((u32) scp->cmnd[11] << 16) | |
| 1529 | ((u32) scp->cmnd[12] << 8) | |
| 1530 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1531 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1532 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1533 | ((u32) scp->cmnd[7] << 16) | |
| 1534 | ((u32) scp->cmnd[8] << 8) | |
| 1535 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1536 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1537 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1538 | ((u32) scp->cmnd[3] << 16) | |
| 1539 | ((u32) scp->cmnd[4] << 8) | |
| 1540 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1541 | |
| 1542 | } |
| 1543 | |
| 1544 | /* |
| 1545 | * Construct SGL |
| 1546 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1547 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1548 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1549 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1550 | &ldio->sgl); |
| 1551 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1552 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1553 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1554 | } else |
| 1555 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1556 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1557 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1558 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1559 | ldio->sge_count); |
| 1560 | return 0; |
| 1561 | } |
| 1562 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1563 | /* |
| 1564 | * Sense info specific |
| 1565 | */ |
| 1566 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1567 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1568 | 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] | 1569 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1570 | /* |
| 1571 | * Compute the total number of frames this command consumes. FW uses |
| 1572 | * this number to pull sufficient number of frames from host memory. |
| 1573 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1574 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1575 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1576 | |
| 1577 | return cmd->frame_count; |
| 1578 | } |
| 1579 | |
| 1580 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1581 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1582 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1583 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1584 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1585 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1586 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1587 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1588 | int ret; |
| 1589 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1590 | switch (cmd->cmnd[0]) { |
| 1591 | case READ_10: |
| 1592 | case WRITE_10: |
| 1593 | case READ_12: |
| 1594 | case WRITE_12: |
| 1595 | case READ_6: |
| 1596 | case WRITE_6: |
| 1597 | case READ_16: |
| 1598 | case WRITE_16: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1599 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1600 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1601 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1602 | default: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1603 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1604 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1605 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1606 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1607 | } |
| 1608 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1609 | /** |
| 1610 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1611 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1612 | * @instance: Adapter soft state |
| 1613 | */ |
| 1614 | static inline void |
| 1615 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1616 | { |
| 1617 | struct megasas_cmd *cmd; |
| 1618 | int i,n; |
| 1619 | union megasas_sgl *mfi_sgl; |
| 1620 | struct megasas_io_frame *ldio; |
| 1621 | struct megasas_pthru_frame *pthru; |
| 1622 | u32 sgcount; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 1623 | u16 max_cmd = instance->max_fw_cmds; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1624 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1625 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1626 | 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] | 1627 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1628 | 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] | 1629 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1630 | 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] | 1631 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1632 | 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] | 1633 | for (i = 0; i < max_cmd; i++) { |
| 1634 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1635 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1636 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1637 | 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] | 1638 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1639 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1640 | mfi_sgl = &ldio->sgl; |
| 1641 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1642 | 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] | 1643 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1644 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1645 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1646 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1647 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1648 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1649 | mfi_sgl = &pthru->sgl; |
| 1650 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1651 | 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] | 1652 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1653 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1654 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1655 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1656 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1657 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1658 | for (n = 0; n < sgcount; n++) { |
| 1659 | if (IS_DMA64) |
| 1660 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1661 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1662 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1663 | else |
| 1664 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1665 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1666 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1667 | } |
| 1668 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1669 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1670 | 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] | 1671 | for (i = 0; i < max_cmd; i++) { |
| 1672 | |
| 1673 | cmd = instance->cmd_list[i]; |
| 1674 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1675 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1676 | 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] | 1677 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1678 | 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] | 1679 | } |
| 1680 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1681 | u32 |
| 1682 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1683 | struct scsi_cmnd *scmd) |
| 1684 | { |
| 1685 | struct megasas_cmd *cmd; |
| 1686 | u32 frame_count; |
| 1687 | |
| 1688 | cmd = megasas_get_cmd(instance); |
| 1689 | if (!cmd) |
| 1690 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1691 | |
| 1692 | /* |
| 1693 | * Logical drive command |
| 1694 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1695 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1696 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1697 | else |
| 1698 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1699 | |
| 1700 | if (!frame_count) |
| 1701 | goto out_return_cmd; |
| 1702 | |
| 1703 | cmd->scmd = scmd; |
| 1704 | scmd->SCp.ptr = (char *)cmd; |
| 1705 | |
| 1706 | /* |
| 1707 | * Issue the command to the FW |
| 1708 | */ |
| 1709 | atomic_inc(&instance->fw_outstanding); |
| 1710 | |
| 1711 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1712 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1713 | |
| 1714 | return 0; |
| 1715 | out_return_cmd: |
| 1716 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1717 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1721 | /** |
| 1722 | * megasas_queue_command - Queue entry point |
| 1723 | * @scmd: SCSI command to be queued |
| 1724 | * @done: Callback entry point |
| 1725 | */ |
| 1726 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1727 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1728 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1729 | struct megasas_instance *instance; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1730 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1731 | |
| 1732 | instance = (struct megasas_instance *) |
| 1733 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1734 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1735 | if (instance->unload == 1) { |
| 1736 | scmd->result = DID_NO_CONNECT << 16; |
| 1737 | scmd->scsi_done(scmd); |
| 1738 | return 0; |
| 1739 | } |
| 1740 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1741 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1742 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1743 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1744 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1745 | /* Check for an mpio path and adjust behavior */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1746 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1747 | if (megasas_check_mpio_paths(instance, scmd) == |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 1748 | (DID_REQUEUE << 16)) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1749 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1750 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1751 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1752 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1753 | return 0; |
| 1754 | } |
| 1755 | } |
| 1756 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1757 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1758 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1759 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1760 | return 0; |
| 1761 | } |
| 1762 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1763 | mr_device_priv_data = scmd->device->hostdata; |
| 1764 | if (!mr_device_priv_data) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1765 | scmd->result = DID_NO_CONNECT << 16; |
| 1766 | scmd->scsi_done(scmd); |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1770 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1771 | return SCSI_MLQUEUE_HOST_BUSY; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1772 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1773 | if (mr_device_priv_data->tm_busy) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1774 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1775 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1776 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1777 | scmd->result = 0; |
| 1778 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1779 | if (MEGASAS_IS_LOGICAL(scmd->device) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1780 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1781 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1782 | scmd->result = DID_BAD_TARGET << 16; |
| 1783 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1784 | } |
| 1785 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1786 | if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && |
| 1787 | MEGASAS_IS_LOGICAL(scmd->device) && |
| 1788 | (!instance->fw_sync_cache_support)) { |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1789 | scmd->result = DID_OK << 16; |
| 1790 | goto out_done; |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1791 | } |
| 1792 | |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1793 | return instance->instancet->build_and_issue_cmd(instance, scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1794 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1795 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1796 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1797 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1798 | } |
| 1799 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1800 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1801 | { |
| 1802 | int i; |
| 1803 | |
| 1804 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1805 | |
| 1806 | if ((megasas_mgmt_info.instance[i]) && |
| 1807 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1808 | return megasas_mgmt_info.instance[i]; |
| 1809 | } |
| 1810 | |
| 1811 | return NULL; |
| 1812 | } |
| 1813 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1814 | /* |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1815 | * megasas_set_dynamic_target_properties - |
| 1816 | * Device property set by driver may not be static and it is required to be |
| 1817 | * updated after OCR |
| 1818 | * |
| 1819 | * set tm_capable. |
| 1820 | * set dma alignment (only for eedp protection enable vd). |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1821 | * |
| 1822 | * @sdev: OS provided scsi device |
| 1823 | * |
| 1824 | * Returns void |
| 1825 | */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 1826 | void megasas_set_dynamic_target_properties(struct scsi_device *sdev, |
| 1827 | bool is_target_prop) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1828 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1829 | u16 pd_index = 0, ld; |
| 1830 | u32 device_id; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1831 | struct megasas_instance *instance; |
| 1832 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1833 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1834 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1835 | struct MR_LD_RAID *raid; |
| 1836 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1837 | |
| 1838 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1839 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1840 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1841 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1842 | if (!fusion || !mr_device_priv_data) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1843 | return; |
| 1844 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1845 | if (MEGASAS_IS_LOGICAL(sdev)) { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1846 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1847 | + sdev->id; |
| 1848 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1849 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1850 | if (ld >= instance->fw_supported_vd_count) |
| 1851 | return; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1852 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1853 | |
| 1854 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1855 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1856 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1857 | mr_device_priv_data->is_tm_capable = |
| 1858 | raid->capability.tmCapable; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1859 | } else if (instance->use_seqnum_jbod_fp) { |
| 1860 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1861 | sdev->id; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1862 | pd_sync = (void *)fusion->pd_seq_sync |
| 1863 | [(instance->pd_seq_map_id - 1) & 1]; |
| 1864 | mr_device_priv_data->is_tm_capable = |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1865 | pd_sync->seq[pd_index].capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1866 | } |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 1867 | |
| 1868 | if (is_target_prop && instance->tgt_prop->reset_tmo) { |
| 1869 | /* |
| 1870 | * If FW provides a target reset timeout value, driver will use |
| 1871 | * it. If not set, fallback to default values. |
| 1872 | */ |
| 1873 | mr_device_priv_data->target_reset_tmo = |
| 1874 | min_t(u8, instance->max_reset_tmo, |
| 1875 | instance->tgt_prop->reset_tmo); |
| 1876 | mr_device_priv_data->task_abort_tmo = instance->task_abort_tmo; |
| 1877 | } else { |
| 1878 | mr_device_priv_data->target_reset_tmo = |
| 1879 | MEGASAS_DEFAULT_TM_TIMEOUT; |
| 1880 | mr_device_priv_data->task_abort_tmo = |
| 1881 | MEGASAS_DEFAULT_TM_TIMEOUT; |
| 1882 | } |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1883 | } |
| 1884 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1885 | /* |
| 1886 | * megasas_set_nvme_device_properties - |
| 1887 | * set nomerges=2 |
| 1888 | * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K). |
| 1889 | * set maximum io transfer = MDTS of NVME device provided by MR firmware. |
| 1890 | * |
| 1891 | * MR firmware provides value in KB. Caller of this function converts |
| 1892 | * kb into bytes. |
| 1893 | * |
| 1894 | * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size, |
| 1895 | * MR firmware provides value 128 as (32 * 4K) = 128K. |
| 1896 | * |
| 1897 | * @sdev: scsi device |
| 1898 | * @max_io_size: maximum io transfer size |
| 1899 | * |
| 1900 | */ |
| 1901 | static inline void |
| 1902 | 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] | 1903 | { |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1904 | struct megasas_instance *instance; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1905 | u32 mr_nvme_pg_size; |
| 1906 | |
| 1907 | instance = (struct megasas_instance *)sdev->host->hostdata; |
| 1908 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1909 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1910 | |
| 1911 | blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512)); |
| 1912 | |
Bart Van Assche | 8b904b5 | 2018-03-07 17:10:10 -0800 | [diff] [blame] | 1913 | blk_queue_flag_set(QUEUE_FLAG_NOMERGES, sdev->request_queue); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1914 | blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1); |
| 1915 | } |
| 1916 | |
| 1917 | |
| 1918 | /* |
| 1919 | * megasas_set_static_target_properties - |
| 1920 | * Device property set by driver are static and it is not required to be |
| 1921 | * updated after OCR. |
| 1922 | * |
| 1923 | * set io timeout |
| 1924 | * set device queue depth |
| 1925 | * set nvme device properties. see - megasas_set_nvme_device_properties |
| 1926 | * |
| 1927 | * @sdev: scsi device |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1928 | * @is_target_prop true, if fw provided target properties. |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1929 | */ |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1930 | static void megasas_set_static_target_properties(struct scsi_device *sdev, |
| 1931 | bool is_target_prop) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1932 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1933 | u8 interface_type; |
| 1934 | u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN; |
| 1935 | u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1936 | u32 tgt_device_qd; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1937 | struct megasas_instance *instance; |
| 1938 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1939 | |
| 1940 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1941 | mr_device_priv_data = sdev->hostdata; |
| 1942 | interface_type = mr_device_priv_data->interface_type; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1943 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1944 | /* |
| 1945 | * The RAID firmware may require extended timeouts. |
| 1946 | */ |
| 1947 | blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1948 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1949 | switch (interface_type) { |
| 1950 | case SAS_PD: |
| 1951 | device_qd = MEGASAS_SAS_QD; |
| 1952 | break; |
| 1953 | case SATA_PD: |
| 1954 | device_qd = MEGASAS_SATA_QD; |
| 1955 | break; |
| 1956 | case NVME_PD: |
| 1957 | device_qd = MEGASAS_NVME_QD; |
| 1958 | break; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1959 | } |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1960 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1961 | if (is_target_prop) { |
| 1962 | tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth); |
| 1963 | if (tgt_device_qd && |
| 1964 | (tgt_device_qd <= instance->host->can_queue)) |
| 1965 | device_qd = tgt_device_qd; |
| 1966 | |
| 1967 | /* max_io_size_kb will be set to non zero for |
| 1968 | * nvme based vd and syspd. |
| 1969 | */ |
| 1970 | max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb); |
| 1971 | } |
| 1972 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1973 | if (instance->nvme_page_size && max_io_size_kb) |
| 1974 | megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10)); |
| 1975 | |
| 1976 | scsi_change_queue_depth(sdev, device_qd); |
| 1977 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1978 | } |
| 1979 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1980 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1981 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1982 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1983 | u16 pd_index = 0; |
| 1984 | struct megasas_instance *instance; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1985 | int ret_target_prop = DCMD_FAILED; |
| 1986 | bool is_target_prop = false; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1987 | |
| 1988 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1989 | if (instance->pd_list_not_supported) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1990 | if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1991 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1992 | sdev->id; |
| 1993 | if (instance->pd_list[pd_index].driveState != |
| 1994 | MR_PD_STATE_SYSTEM) |
| 1995 | return -ENXIO; |
| 1996 | } |
| 1997 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1998 | |
Shivasharan S | 149c575 | 2018-01-05 05:27:42 -0800 | [diff] [blame] | 1999 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2000 | /* Send DCMD to Firmware and cache the information */ |
| 2001 | if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev)) |
| 2002 | megasas_get_pd_info(instance, sdev); |
| 2003 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 2004 | /* Some ventura firmware may not have instance->nvme_page_size set. |
| 2005 | * Do not send MR_DCMD_DRV_GET_TARGET_PROP |
| 2006 | */ |
| 2007 | if ((instance->tgt_prop) && (instance->nvme_page_size)) |
| 2008 | ret_target_prop = megasas_get_target_prop(instance, sdev); |
| 2009 | |
| 2010 | is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false; |
| 2011 | megasas_set_static_target_properties(sdev, is_target_prop); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2012 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2013 | /* This sdev property may change post OCR */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 2014 | megasas_set_dynamic_target_properties(sdev, is_target_prop); |
| 2015 | |
| 2016 | mutex_unlock(&instance->reset_mutex); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 2017 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2018 | return 0; |
| 2019 | } |
| 2020 | |
| 2021 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 2022 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2023 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2024 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2025 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2026 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2027 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 2028 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2029 | /* |
| 2030 | * Open the OS scan to the SYSTEM PD |
| 2031 | */ |
| 2032 | pd_index = |
| 2033 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 2034 | sdev->id; |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 2035 | if ((instance->pd_list_not_supported || |
| 2036 | instance->pd_list[pd_index].driveState == |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 2037 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2038 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2039 | } |
| 2040 | return -ENXIO; |
| 2041 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2042 | |
| 2043 | scan_target: |
| 2044 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 2045 | GFP_KERNEL); |
| 2046 | if (!mr_device_priv_data) |
| 2047 | return -ENOMEM; |
| 2048 | sdev->hostdata = mr_device_priv_data; |
Shivasharan S | 49524b3 | 2017-03-10 03:22:13 -0800 | [diff] [blame] | 2049 | |
| 2050 | atomic_set(&mr_device_priv_data->r1_ldio_hint, |
| 2051 | instance->r1_ldio_hint_default); |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2052 | return 0; |
| 2053 | } |
| 2054 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2055 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 2056 | { |
| 2057 | kfree(sdev->hostdata); |
| 2058 | sdev->hostdata = NULL; |
| 2059 | } |
| 2060 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2061 | /* |
| 2062 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 2063 | * kill adapter |
| 2064 | * @instance: Adapter soft state |
| 2065 | * |
| 2066 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 2067 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2068 | { |
| 2069 | int i; |
| 2070 | struct megasas_cmd *cmd_mfi; |
| 2071 | struct megasas_cmd_fusion *cmd_fusion; |
| 2072 | struct fusion_context *fusion = instance->ctrl_context; |
| 2073 | |
| 2074 | /* Find all outstanding ioctls */ |
| 2075 | if (fusion) { |
| 2076 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2077 | cmd_fusion = fusion->cmd_list[i]; |
| 2078 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 2079 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 2080 | if (cmd_mfi->sync_cmd && |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2081 | (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) { |
| 2082 | cmd_mfi->frame->hdr.cmd_status = |
| 2083 | MFI_STAT_WRONG_STATE; |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2084 | megasas_complete_cmd(instance, |
| 2085 | cmd_mfi, DID_OK); |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2086 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2087 | } |
| 2088 | } |
| 2089 | } else { |
| 2090 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2091 | cmd_mfi = instance->cmd_list[i]; |
| 2092 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 2093 | MFI_CMD_ABORT) |
| 2094 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 2095 | } |
| 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2100 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2101 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2102 | /* 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] | 2103 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2104 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 2105 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2106 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2107 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2108 | (instance->adapter_type != MFI_SERIES)) { |
Shivasharan S | 5acad9b | 2018-10-16 23:37:47 -0700 | [diff] [blame] | 2109 | if (!instance->requestorId) { |
| 2110 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
| 2111 | /* Flush */ |
| 2112 | readl(&instance->reg_set->doorbell); |
| 2113 | } |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 2114 | if (instance->requestorId && instance->peerIsPresent) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2115 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2116 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2117 | writel(MFI_STOP_ADP, |
| 2118 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2119 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2120 | /* Complete outstanding ioctls when adapter is killed */ |
| 2121 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2122 | } |
| 2123 | |
| 2124 | /** |
| 2125 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 2126 | * restored to max value |
| 2127 | * @instance: Adapter soft state |
| 2128 | * |
| 2129 | */ |
| 2130 | void |
| 2131 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 2132 | { |
| 2133 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 2134 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2135 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2136 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 2137 | && atomic_read(&instance->fw_outstanding) < |
| 2138 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2139 | |
| 2140 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2141 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2142 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2143 | instance->host->can_queue = instance->cur_can_queue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2144 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2148 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2149 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 2150 | * @instance_addr: Address of adapter soft state |
| 2151 | * |
| 2152 | * Tasklet to complete cmds |
| 2153 | */ |
| 2154 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 2155 | { |
| 2156 | u32 producer; |
| 2157 | u32 consumer; |
| 2158 | u32 context; |
| 2159 | struct megasas_cmd *cmd; |
| 2160 | struct megasas_instance *instance = |
| 2161 | (struct megasas_instance *)instance_addr; |
| 2162 | unsigned long flags; |
| 2163 | |
| 2164 | /* If we have already declared adapter dead, donot complete cmds */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2165 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2166 | return; |
| 2167 | |
| 2168 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 2169 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2170 | producer = le32_to_cpu(*instance->producer); |
| 2171 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2172 | |
| 2173 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2174 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2175 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2176 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2177 | context); |
| 2178 | BUG(); |
| 2179 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2180 | |
| 2181 | cmd = instance->cmd_list[context]; |
| 2182 | |
| 2183 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 2184 | |
| 2185 | consumer++; |
| 2186 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 2187 | consumer = 0; |
| 2188 | } |
| 2189 | } |
| 2190 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2191 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2192 | |
| 2193 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 2194 | |
| 2195 | /* |
| 2196 | * Check if we can restore can_queue |
| 2197 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2198 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2199 | } |
| 2200 | |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2201 | static void megasas_sriov_heartbeat_handler(struct timer_list *t); |
| 2202 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2203 | /** |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2204 | * megasas_start_timer - Initializes sriov heartbeat timer object |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2205 | * @instance: Adapter soft state |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2206 | * |
| 2207 | */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2208 | void megasas_start_timer(struct megasas_instance *instance) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2209 | { |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2210 | struct timer_list *timer = &instance->sriov_heartbeat_timer; |
| 2211 | |
| 2212 | timer_setup(timer, megasas_sriov_heartbeat_handler, 0); |
| 2213 | timer->expires = jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2214 | add_timer(timer); |
| 2215 | } |
| 2216 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2217 | static void |
| 2218 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2219 | |
| 2220 | static void |
| 2221 | process_fw_state_change_wq(struct work_struct *work); |
| 2222 | |
| 2223 | void megasas_do_ocr(struct megasas_instance *instance) |
| 2224 | { |
| 2225 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2226 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2227 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2228 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2229 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2230 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2231 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2232 | instance->issuepend_done = 0; |
| 2233 | |
| 2234 | atomic_set(&instance->fw_outstanding, 0); |
| 2235 | megasas_internal_reset_defer_cmds(instance); |
| 2236 | process_fw_state_change_wq(&instance->work_init); |
| 2237 | } |
| 2238 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2239 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2240 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2241 | { |
| 2242 | struct megasas_cmd *cmd; |
| 2243 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2244 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2245 | dma_addr_t new_affiliation_111_h; |
| 2246 | int ld, retval = 0; |
| 2247 | u8 thisVf; |
| 2248 | |
| 2249 | cmd = megasas_get_cmd(instance); |
| 2250 | |
| 2251 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2252 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2253 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2254 | instance->host->host_no); |
| 2255 | return -ENOMEM; |
| 2256 | } |
| 2257 | |
| 2258 | dcmd = &cmd->frame->dcmd; |
| 2259 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2260 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2261 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2262 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2263 | megasas_return_cmd(instance, cmd); |
| 2264 | return -ENOMEM; |
| 2265 | } |
| 2266 | |
| 2267 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2268 | memset(instance->vf_affiliation_111, 0, |
| 2269 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2270 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2271 | new_affiliation_111 = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2272 | dma_alloc_coherent(&instance->pdev->dev, |
| 2273 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2274 | &new_affiliation_111_h, GFP_KERNEL); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2275 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2276 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2277 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2278 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2279 | megasas_return_cmd(instance, cmd); |
| 2280 | return -ENOMEM; |
| 2281 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2285 | |
| 2286 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2287 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2288 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2289 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2290 | dcmd->timeout = 0; |
| 2291 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2292 | dcmd->data_xfer_len = |
| 2293 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2294 | 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] | 2295 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2296 | if (initial) |
| 2297 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2298 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2299 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2300 | dcmd->sgl.sge32[0].phys_addr = |
| 2301 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2302 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2303 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2304 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2305 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2306 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2307 | "scsi%d\n", instance->host->host_no); |
| 2308 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2309 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2310 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2311 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2312 | dcmd->cmd_status, instance->host->host_no); |
| 2313 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2314 | goto out; |
| 2315 | } |
| 2316 | |
| 2317 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2318 | thisVf = new_affiliation_111->thisVf; |
| 2319 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2320 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2321 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2322 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2323 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2324 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2325 | memcpy(instance->vf_affiliation_111, |
| 2326 | new_affiliation_111, |
| 2327 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2328 | retval = 1; |
| 2329 | goto out; |
| 2330 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2331 | } |
| 2332 | out: |
| 2333 | if (new_affiliation_111) { |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 2334 | dma_free_coherent(&instance->pdev->dev, |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2335 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2336 | new_affiliation_111, |
| 2337 | new_affiliation_111_h); |
| 2338 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2339 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2340 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2341 | |
| 2342 | return retval; |
| 2343 | } |
| 2344 | |
| 2345 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2346 | int initial) |
| 2347 | { |
| 2348 | struct megasas_cmd *cmd; |
| 2349 | struct megasas_dcmd_frame *dcmd; |
| 2350 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2351 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2352 | dma_addr_t new_affiliation_h; |
| 2353 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2354 | u8 thisVf; |
| 2355 | |
| 2356 | cmd = megasas_get_cmd(instance); |
| 2357 | |
| 2358 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2359 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2360 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2361 | instance->host->host_no); |
| 2362 | return -ENOMEM; |
| 2363 | } |
| 2364 | |
| 2365 | dcmd = &cmd->frame->dcmd; |
| 2366 | |
| 2367 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2368 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2369 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2370 | megasas_return_cmd(instance, cmd); |
| 2371 | return -ENOMEM; |
| 2372 | } |
| 2373 | |
| 2374 | if (initial) |
| 2375 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2376 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2377 | else { |
| 2378 | new_affiliation = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2379 | dma_alloc_coherent(&instance->pdev->dev, |
| 2380 | (MAX_LOGICAL_DRIVES + 1) * sizeof(struct MR_LD_VF_AFFILIATION), |
| 2381 | &new_affiliation_h, GFP_KERNEL); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2382 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2383 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2384 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2385 | instance->host->host_no); |
| 2386 | megasas_return_cmd(instance, cmd); |
| 2387 | return -ENOMEM; |
| 2388 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2392 | |
| 2393 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2394 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2395 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2396 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2397 | dcmd->timeout = 0; |
| 2398 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2399 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2400 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2401 | 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] | 2402 | |
| 2403 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2404 | dcmd->sgl.sge32[0].phys_addr = |
| 2405 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2406 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2407 | dcmd->sgl.sge32[0].phys_addr = |
| 2408 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2409 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2410 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2411 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2412 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2413 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2414 | "scsi%d\n", instance->host->host_no); |
| 2415 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2416 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2417 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2418 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2419 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2420 | dcmd->cmd_status, instance->host->host_no); |
| 2421 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2422 | goto out; |
| 2423 | } |
| 2424 | |
| 2425 | if (!initial) { |
| 2426 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2427 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2428 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2429 | instance->host->host_no); |
| 2430 | retval = 1; |
| 2431 | goto out; |
| 2432 | } |
| 2433 | newmap = new_affiliation->map; |
| 2434 | savedmap = instance->vf_affiliation->map; |
| 2435 | thisVf = new_affiliation->thisVf; |
| 2436 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2437 | found = 0; |
| 2438 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2439 | j++) { |
| 2440 | if (newmap->ref.targetId == |
| 2441 | savedmap->ref.targetId) { |
| 2442 | found = 1; |
| 2443 | if (newmap->policy[thisVf] != |
| 2444 | savedmap->policy[thisVf]) { |
| 2445 | doscan = 1; |
| 2446 | goto out; |
| 2447 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2448 | } |
| 2449 | savedmap = (struct MR_LD_VF_MAP *) |
| 2450 | ((unsigned char *)savedmap + |
| 2451 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2452 | } |
| 2453 | if (!found && newmap->policy[thisVf] != |
| 2454 | MR_LD_ACCESS_HIDDEN) { |
| 2455 | doscan = 1; |
| 2456 | goto out; |
| 2457 | } |
| 2458 | newmap = (struct MR_LD_VF_MAP *) |
| 2459 | ((unsigned char *)newmap + newmap->size); |
| 2460 | } |
| 2461 | |
| 2462 | newmap = new_affiliation->map; |
| 2463 | savedmap = instance->vf_affiliation->map; |
| 2464 | |
| 2465 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2466 | found = 0; |
| 2467 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2468 | if (savedmap->ref.targetId == |
| 2469 | newmap->ref.targetId) { |
| 2470 | found = 1; |
| 2471 | if (savedmap->policy[thisVf] != |
| 2472 | newmap->policy[thisVf]) { |
| 2473 | doscan = 1; |
| 2474 | goto out; |
| 2475 | } |
| 2476 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2477 | newmap = (struct MR_LD_VF_MAP *) |
| 2478 | ((unsigned char *)newmap + |
| 2479 | newmap->size); |
| 2480 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2481 | if (!found && savedmap->policy[thisVf] != |
| 2482 | MR_LD_ACCESS_HIDDEN) { |
| 2483 | doscan = 1; |
| 2484 | goto out; |
| 2485 | } |
| 2486 | savedmap = (struct MR_LD_VF_MAP *) |
| 2487 | ((unsigned char *)savedmap + |
| 2488 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2489 | } |
| 2490 | } |
| 2491 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2492 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2493 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2494 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2495 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2496 | new_affiliation->size); |
| 2497 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2498 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2499 | |
| 2500 | if (new_affiliation) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 2501 | dma_free_coherent(&instance->pdev->dev, |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2502 | (MAX_LOGICAL_DRIVES + 1) * |
| 2503 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2504 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2505 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2506 | |
| 2507 | return retval; |
| 2508 | } |
| 2509 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2510 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2511 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2512 | int initial) |
| 2513 | { |
| 2514 | int retval; |
| 2515 | |
| 2516 | if (instance->PlasmaFW111) |
| 2517 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2518 | else |
| 2519 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2520 | return retval; |
| 2521 | } |
| 2522 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2523 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2524 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2525 | int initial) |
| 2526 | { |
| 2527 | struct megasas_cmd *cmd; |
| 2528 | struct megasas_dcmd_frame *dcmd; |
| 2529 | int retval = 0; |
| 2530 | |
| 2531 | cmd = megasas_get_cmd(instance); |
| 2532 | |
| 2533 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2534 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2535 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2536 | instance->host->host_no); |
| 2537 | return -ENOMEM; |
| 2538 | } |
| 2539 | |
| 2540 | dcmd = &cmd->frame->dcmd; |
| 2541 | |
| 2542 | if (initial) { |
| 2543 | instance->hb_host_mem = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2544 | dma_alloc_coherent(&instance->pdev->dev, |
| 2545 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2546 | &instance->hb_host_mem_h, |
| 2547 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2548 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2549 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2550 | " memory for heartbeat host memory for scsi%d\n", |
| 2551 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2552 | retval = -ENOMEM; |
| 2553 | goto out; |
| 2554 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2558 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2559 | 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] | 2560 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2561 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2562 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2563 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2564 | dcmd->timeout = 0; |
| 2565 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2566 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2567 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 2568 | |
| 2569 | megasas_set_dma_settings(instance, dcmd, instance->hb_host_mem_h, |
| 2570 | sizeof(struct MR_CTRL_HB_HOST_MEM)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2571 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2572 | 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] | 2573 | instance->host->host_no); |
| 2574 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2575 | if ((instance->adapter_type != MFI_SERIES) && |
| 2576 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2577 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2578 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2579 | else |
| 2580 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2581 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2582 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2583 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2584 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2585 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2586 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2587 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | out: |
| 2591 | megasas_return_cmd(instance, cmd); |
| 2592 | |
| 2593 | return retval; |
| 2594 | } |
| 2595 | |
| 2596 | /* Handler for SR-IOV heartbeat */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2597 | static void megasas_sriov_heartbeat_handler(struct timer_list *t) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2598 | { |
| 2599 | struct megasas_instance *instance = |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2600 | from_timer(instance, t, sriov_heartbeat_timer); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2601 | |
| 2602 | if (instance->hb_host_mem->HB.fwCounter != |
| 2603 | instance->hb_host_mem->HB.driverCounter) { |
| 2604 | instance->hb_host_mem->HB.driverCounter = |
| 2605 | instance->hb_host_mem->HB.fwCounter; |
| 2606 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2607 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2608 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2609 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2610 | "completed for scsi%d\n", instance->host->host_no); |
| 2611 | schedule_work(&instance->work_init); |
| 2612 | } |
| 2613 | } |
| 2614 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2615 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2616 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2617 | * @instance: Adapter soft state |
| 2618 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2619 | * 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] | 2620 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2621 | * are pending after this time period. It also marks the controller dead. |
| 2622 | */ |
| 2623 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2624 | { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2625 | int i, sl, outstanding; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2626 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2627 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2628 | unsigned long flags; |
| 2629 | struct list_head clist_local; |
| 2630 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2631 | u32 fw_state; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2632 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2633 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2634 | dev_info(&instance->pdev->dev, "%s:%d HBA is killed.\n", |
| 2635 | __func__, __LINE__); |
| 2636 | return FAILED; |
| 2637 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2638 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2639 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2640 | |
| 2641 | INIT_LIST_HEAD(&clist_local); |
| 2642 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2643 | list_splice_init(&instance->internal_reset_pending_q, |
| 2644 | &clist_local); |
| 2645 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2646 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2647 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2648 | for (i = 0; i < wait_time; i++) { |
| 2649 | msleep(1000); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2650 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2651 | break; |
| 2652 | } |
| 2653 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2654 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2655 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2656 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2657 | return FAILED; |
| 2658 | } |
| 2659 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2660 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2661 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2662 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2663 | struct megasas_cmd, list); |
| 2664 | list_del_init(&reset_cmd->list); |
| 2665 | if (reset_cmd->scmd) { |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 2666 | reset_cmd->scmd->result = DID_REQUEUE << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2667 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2668 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2669 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2670 | |
| 2671 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2672 | megasas_return_cmd(instance, reset_cmd); |
| 2673 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2674 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2675 | "reset queue\n", |
| 2676 | reset_cmd); |
| 2677 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2678 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2679 | instance->instancet->fire_cmd(instance, |
| 2680 | reset_cmd->frame_phys_addr, |
| 2681 | 0, instance->reg_set); |
| 2682 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2683 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2684 | "cmds lst\n", |
| 2685 | reset_cmd); |
| 2686 | } |
| 2687 | reset_index++; |
| 2688 | } |
| 2689 | |
| 2690 | return SUCCESS; |
| 2691 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2692 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2693 | for (i = 0; i < resetwaittime; i++) { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2694 | outstanding = atomic_read(&instance->fw_outstanding); |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2695 | |
| 2696 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2697 | break; |
| 2698 | |
| 2699 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2700 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2701 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2702 | /* |
| 2703 | * Call cmd completion routine. Cmd to be |
| 2704 | * be completed directly without depending on isr. |
| 2705 | */ |
| 2706 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | msleep(1000); |
| 2710 | } |
| 2711 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2712 | i = 0; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2713 | outstanding = atomic_read(&instance->fw_outstanding); |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 2714 | fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2715 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2716 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2717 | goto no_outstanding; |
| 2718 | |
| 2719 | if (instance->disableOnlineCtrlReset) |
| 2720 | goto kill_hba_and_failed; |
| 2721 | do { |
| 2722 | if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) { |
| 2723 | dev_info(&instance->pdev->dev, |
Colin Ian King | efc372c | 2019-04-17 14:51:09 +0100 | [diff] [blame] | 2724 | "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, outstanding 0x%x\n", |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2725 | __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding)); |
| 2726 | if (i == 3) |
| 2727 | goto kill_hba_and_failed; |
| 2728 | megasas_do_ocr(instance); |
| 2729 | |
| 2730 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2731 | dev_info(&instance->pdev->dev, "%s:%d OCR failed and HBA is killed.\n", |
| 2732 | __func__, __LINE__); |
| 2733 | return FAILED; |
| 2734 | } |
| 2735 | dev_info(&instance->pdev->dev, "%s:%d waiting_for_outstanding: after issue OCR.\n", |
| 2736 | __func__, __LINE__); |
| 2737 | |
| 2738 | for (sl = 0; sl < 10; sl++) |
| 2739 | msleep(500); |
| 2740 | |
| 2741 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2742 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 2743 | fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2744 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2745 | goto no_outstanding; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2746 | } |
| 2747 | i++; |
| 2748 | } while (i <= 3); |
| 2749 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2750 | no_outstanding: |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2751 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2752 | dev_info(&instance->pdev->dev, "%s:%d no more pending commands remain after reset handling.\n", |
| 2753 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2754 | return SUCCESS; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2755 | |
| 2756 | kill_hba_and_failed: |
| 2757 | |
| 2758 | /* Reset not supported, kill adapter */ |
| 2759 | dev_info(&instance->pdev->dev, "%s:%d killing adapter scsi%d" |
| 2760 | " disableOnlineCtrlReset %d fw_outstanding %d \n", |
| 2761 | __func__, __LINE__, instance->host->host_no, instance->disableOnlineCtrlReset, |
| 2762 | atomic_read(&instance->fw_outstanding)); |
| 2763 | megasas_dump_pending_frames(instance); |
| 2764 | megaraid_sas_kill_hba(instance); |
| 2765 | |
| 2766 | return FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | /** |
| 2770 | * megasas_generic_reset - Generic reset routine |
| 2771 | * @scmd: Mid-layer SCSI command |
| 2772 | * |
| 2773 | * This routine implements a generic reset handler for device, bus and host |
| 2774 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2775 | * function after they do their specific tasks. |
| 2776 | */ |
| 2777 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2778 | { |
| 2779 | int ret_val; |
| 2780 | struct megasas_instance *instance; |
| 2781 | |
| 2782 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2783 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2784 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2785 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2786 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2787 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2788 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2789 | return FAILED; |
| 2790 | } |
| 2791 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2792 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2793 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2794 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2795 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2796 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2797 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2798 | return ret_val; |
| 2799 | } |
| 2800 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2801 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2802 | * megasas_reset_timer - quiesce the adapter if required |
| 2803 | * @scmd: scsi cmnd |
| 2804 | * |
| 2805 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2806 | * cmd has not been completed within the timeout period. |
| 2807 | */ |
| 2808 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2809 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2810 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2811 | struct megasas_instance *instance; |
| 2812 | unsigned long flags; |
| 2813 | |
| 2814 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 2815 | (scmd_timeout * 2) * HZ)) { |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 2816 | return BLK_EH_DONE; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2819 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2820 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2821 | /* FW is busy, throttle IO */ |
| 2822 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2823 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2824 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2825 | instance->last_time = jiffies; |
| 2826 | instance->flag |= MEGASAS_FW_BUSY; |
| 2827 | |
| 2828 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2829 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2830 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | /** |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2834 | * megasas_dump_frame - This function will dump MPT/MFI frame |
| 2835 | */ |
| 2836 | static inline void |
| 2837 | megasas_dump_frame(void *mpi_request, int sz) |
| 2838 | { |
| 2839 | int i; |
| 2840 | __le32 *mfp = (__le32 *)mpi_request; |
| 2841 | |
| 2842 | printk(KERN_INFO "IO request frame:\n\t"); |
Dan Carpenter | 40a4c2c | 2017-02-14 19:38:55 +0300 | [diff] [blame] | 2843 | for (i = 0; i < sz / sizeof(__le32); i++) { |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2844 | if (i && ((i % 8) == 0)) |
| 2845 | printk("\n\t"); |
| 2846 | printk("%08x ", le32_to_cpu(mfp[i])); |
| 2847 | } |
| 2848 | printk("\n"); |
| 2849 | } |
| 2850 | |
| 2851 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2852 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2853 | */ |
| 2854 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2855 | { |
| 2856 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2857 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2858 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2859 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2860 | |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2861 | scmd_printk(KERN_INFO, scmd, |
| 2862 | "Controller reset is requested due to IO timeout\n" |
| 2863 | "SCSI command pointer: (%p)\t SCSI host state: %d\t" |
| 2864 | " SCSI host busy: %d\t FW outstanding: %d\n", |
| 2865 | scmd, scmd->device->host->shost_state, |
Ming Lei | c84b023 | 2018-06-24 22:03:26 +0800 | [diff] [blame] | 2866 | scsi_host_busy(scmd->device->host), |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2867 | atomic_read(&instance->fw_outstanding)); |
| 2868 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2869 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2870 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2871 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2872 | if (instance->adapter_type == MFI_SERIES) { |
| 2873 | ret = megasas_generic_reset(scmd); |
| 2874 | } else { |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2875 | struct megasas_cmd_fusion *cmd; |
| 2876 | cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr; |
| 2877 | if (cmd) |
| 2878 | megasas_dump_frame(cmd->io_request, |
Shivasharan S | 5dd977e | 2017-08-23 04:47:07 -0700 | [diff] [blame] | 2879 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2880 | ret = megasas_reset_fusion(scmd->device->host, |
| 2881 | SCSIIO_TIMEOUT_OCR); |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2882 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2883 | |
| 2884 | return ret; |
| 2885 | } |
| 2886 | |
| 2887 | /** |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2888 | * megasas_task_abort - Issues task abort request to firmware |
| 2889 | * (supported only for fusion adapters) |
| 2890 | * @scmd: SCSI command pointer |
| 2891 | */ |
| 2892 | static int megasas_task_abort(struct scsi_cmnd *scmd) |
| 2893 | { |
| 2894 | int ret; |
| 2895 | struct megasas_instance *instance; |
| 2896 | |
| 2897 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2898 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2899 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2900 | ret = megasas_task_abort_fusion(scmd); |
| 2901 | else { |
| 2902 | sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n"); |
| 2903 | ret = FAILED; |
| 2904 | } |
| 2905 | |
| 2906 | return ret; |
| 2907 | } |
| 2908 | |
| 2909 | /** |
| 2910 | * megasas_reset_target: Issues target reset request to firmware |
| 2911 | * (supported only for fusion adapters) |
| 2912 | * @scmd: SCSI command pointer |
| 2913 | */ |
| 2914 | static int megasas_reset_target(struct scsi_cmnd *scmd) |
| 2915 | { |
| 2916 | int ret; |
| 2917 | struct megasas_instance *instance; |
| 2918 | |
| 2919 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2920 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2921 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2922 | ret = megasas_reset_target_fusion(scmd); |
| 2923 | else { |
| 2924 | sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n"); |
| 2925 | ret = FAILED; |
| 2926 | } |
| 2927 | |
| 2928 | return ret; |
| 2929 | } |
| 2930 | |
| 2931 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2932 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2933 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2934 | * @bdev: block device |
| 2935 | * @capacity: drive capacity |
| 2936 | * @geom: geometry parameters |
| 2937 | */ |
| 2938 | static int |
| 2939 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2940 | sector_t capacity, int geom[]) |
| 2941 | { |
| 2942 | int heads; |
| 2943 | int sectors; |
| 2944 | sector_t cylinders; |
| 2945 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2946 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2947 | /* Default heads (64) & sectors (32) */ |
| 2948 | heads = 64; |
| 2949 | sectors = 32; |
| 2950 | |
| 2951 | tmp = heads * sectors; |
| 2952 | cylinders = capacity; |
| 2953 | |
| 2954 | sector_div(cylinders, tmp); |
| 2955 | |
| 2956 | /* |
| 2957 | * Handle extended translation size for logical drives > 1Gb |
| 2958 | */ |
| 2959 | |
| 2960 | if (capacity >= 0x200000) { |
| 2961 | heads = 255; |
| 2962 | sectors = 63; |
| 2963 | tmp = heads*sectors; |
| 2964 | cylinders = capacity; |
| 2965 | sector_div(cylinders, tmp); |
| 2966 | } |
| 2967 | |
| 2968 | geom[0] = heads; |
| 2969 | geom[1] = sectors; |
| 2970 | geom[2] = cylinders; |
| 2971 | |
| 2972 | return 0; |
| 2973 | } |
| 2974 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2975 | static void megasas_aen_polling(struct work_struct *work); |
| 2976 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2977 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2978 | * megasas_service_aen - Processes an event notification |
| 2979 | * @instance: Adapter soft state |
| 2980 | * @cmd: AEN command completed by the ISR |
| 2981 | * |
| 2982 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2983 | * event occurs. When an event of interest occurs, FW completes the command |
| 2984 | * that it was previously holding. |
| 2985 | * |
| 2986 | * This routines sends SIGIO signal to processes that have registered with the |
| 2987 | * driver for AEN. |
| 2988 | */ |
| 2989 | static void |
| 2990 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2991 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2992 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2993 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2994 | /* |
| 2995 | * Don't signal app if it is just an aborted previously registered aen |
| 2996 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2997 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2998 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2999 | megasas_poll_wait_aen = 1; |
| 3000 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3001 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3002 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3003 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3004 | else |
| 3005 | cmd->abort_aen = 0; |
| 3006 | |
| 3007 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3008 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3009 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3010 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3011 | if ((instance->unload == 0) && |
| 3012 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3013 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3014 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3015 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 3016 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3017 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3018 | } else { |
| 3019 | ev->instance = instance; |
| 3020 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 3021 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 3022 | megasas_aen_polling); |
| 3023 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3024 | } |
| 3025 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3026 | } |
| 3027 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3028 | static ssize_t |
| 3029 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 3030 | struct device_attribute *attr, const char *buf, size_t count) |
| 3031 | { |
| 3032 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3033 | struct megasas_instance *instance = |
| 3034 | (struct megasas_instance *) shost->hostdata; |
| 3035 | int val = 0; |
| 3036 | unsigned long flags; |
| 3037 | |
| 3038 | if (kstrtoint(buf, 0, &val) != 0) |
| 3039 | return -EINVAL; |
| 3040 | |
| 3041 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3042 | instance->fw_crash_buffer_offset = val; |
| 3043 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3044 | return strlen(buf); |
| 3045 | } |
| 3046 | |
| 3047 | static ssize_t |
| 3048 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 3049 | struct device_attribute *attr, char *buf) |
| 3050 | { |
| 3051 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3052 | struct megasas_instance *instance = |
| 3053 | (struct megasas_instance *) shost->hostdata; |
| 3054 | u32 size; |
| 3055 | unsigned long buff_addr; |
| 3056 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 3057 | unsigned long src_addr; |
| 3058 | unsigned long flags; |
| 3059 | u32 buff_offset; |
| 3060 | |
| 3061 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3062 | buff_offset = instance->fw_crash_buffer_offset; |
| 3063 | if (!instance->crash_dump_buf && |
| 3064 | !((instance->fw_crash_state == AVAILABLE) || |
| 3065 | (instance->fw_crash_state == COPYING))) { |
| 3066 | dev_err(&instance->pdev->dev, |
| 3067 | "Firmware crash dump is not available\n"); |
| 3068 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3069 | return -EINVAL; |
| 3070 | } |
| 3071 | |
| 3072 | buff_addr = (unsigned long) buf; |
| 3073 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3074 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3075 | dev_err(&instance->pdev->dev, |
| 3076 | "Firmware crash dump offset is out of range\n"); |
| 3077 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3078 | return 0; |
| 3079 | } |
| 3080 | |
| 3081 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 3082 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 3083 | |
| 3084 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 3085 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3086 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3087 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3088 | |
| 3089 | return size; |
| 3090 | } |
| 3091 | |
| 3092 | static ssize_t |
| 3093 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 3094 | struct device_attribute *attr, char *buf) |
| 3095 | { |
| 3096 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3097 | struct megasas_instance *instance = |
| 3098 | (struct megasas_instance *) shost->hostdata; |
| 3099 | |
| 3100 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 3101 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 3102 | } |
| 3103 | |
| 3104 | static ssize_t |
| 3105 | megasas_fw_crash_state_store(struct device *cdev, |
| 3106 | struct device_attribute *attr, const char *buf, size_t count) |
| 3107 | { |
| 3108 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3109 | struct megasas_instance *instance = |
| 3110 | (struct megasas_instance *) shost->hostdata; |
| 3111 | int val = 0; |
| 3112 | unsigned long flags; |
| 3113 | |
| 3114 | if (kstrtoint(buf, 0, &val) != 0) |
| 3115 | return -EINVAL; |
| 3116 | |
| 3117 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 3118 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 3119 | "firmware crash state\n"); |
| 3120 | return -EINVAL; |
| 3121 | } |
| 3122 | |
| 3123 | instance->fw_crash_state = val; |
| 3124 | |
| 3125 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 3126 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3127 | megasas_free_host_crash_buffer(instance); |
| 3128 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3129 | if (val == COPY_ERROR) |
| 3130 | dev_info(&instance->pdev->dev, "application failed to " |
| 3131 | "copy Firmware crash dump\n"); |
| 3132 | else |
| 3133 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 3134 | "copied successfully\n"); |
| 3135 | } |
| 3136 | return strlen(buf); |
| 3137 | } |
| 3138 | |
| 3139 | static ssize_t |
| 3140 | megasas_fw_crash_state_show(struct device *cdev, |
| 3141 | struct device_attribute *attr, char *buf) |
| 3142 | { |
| 3143 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3144 | struct megasas_instance *instance = |
| 3145 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3146 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3147 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 3148 | } |
| 3149 | |
| 3150 | static ssize_t |
| 3151 | megasas_page_size_show(struct device *cdev, |
| 3152 | struct device_attribute *attr, char *buf) |
| 3153 | { |
| 3154 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 3155 | } |
| 3156 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3157 | static ssize_t |
| 3158 | megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr, |
| 3159 | char *buf) |
| 3160 | { |
| 3161 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3162 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3163 | |
| 3164 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding)); |
| 3165 | } |
| 3166 | |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3167 | static ssize_t |
| 3168 | megasas_fw_cmds_outstanding_show(struct device *cdev, |
| 3169 | struct device_attribute *attr, char *buf) |
| 3170 | { |
| 3171 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3172 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3173 | |
| 3174 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->fw_outstanding)); |
| 3175 | } |
| 3176 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3177 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 3178 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 3179 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 3180 | megasas_fw_crash_buffer_size_show, NULL); |
| 3181 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 3182 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 3183 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 3184 | megasas_page_size_show, NULL); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3185 | static DEVICE_ATTR(ldio_outstanding, S_IRUGO, |
| 3186 | megasas_ldio_outstanding_show, NULL); |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3187 | static DEVICE_ATTR(fw_cmds_outstanding, S_IRUGO, |
| 3188 | megasas_fw_cmds_outstanding_show, NULL); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3189 | |
| 3190 | struct device_attribute *megaraid_host_attrs[] = { |
| 3191 | &dev_attr_fw_crash_buffer_size, |
| 3192 | &dev_attr_fw_crash_buffer, |
| 3193 | &dev_attr_fw_crash_state, |
| 3194 | &dev_attr_page_size, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3195 | &dev_attr_ldio_outstanding, |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3196 | &dev_attr_fw_cmds_outstanding, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3197 | NULL, |
| 3198 | }; |
| 3199 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3200 | /* |
| 3201 | * Scsi host template for megaraid_sas driver |
| 3202 | */ |
| 3203 | static struct scsi_host_template megasas_template = { |
| 3204 | |
| 3205 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 3206 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3207 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 3208 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 3209 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3210 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3211 | .queuecommand = megasas_queue_command, |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3212 | .eh_target_reset_handler = megasas_reset_target, |
| 3213 | .eh_abort_handler = megasas_task_abort, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3214 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3215 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3216 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3217 | .bios_param = megasas_bios_param, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 3218 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 3219 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3220 | }; |
| 3221 | |
| 3222 | /** |
| 3223 | * megasas_complete_int_cmd - Completes an internal command |
| 3224 | * @instance: Adapter soft state |
| 3225 | * @cmd: Command to be completed |
| 3226 | * |
| 3227 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 3228 | * after it issues a command. This function wakes up that waiting routine by |
| 3229 | * calling wake_up() on the wait queue. |
| 3230 | */ |
| 3231 | static void |
| 3232 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 3233 | struct megasas_cmd *cmd) |
| 3234 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3235 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3236 | wake_up(&instance->int_cmd_wait_q); |
| 3237 | } |
| 3238 | |
| 3239 | /** |
| 3240 | * megasas_complete_abort - Completes aborting a command |
| 3241 | * @instance: Adapter soft state |
| 3242 | * @cmd: Cmd that was issued to abort another cmd |
| 3243 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3244 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 3245 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3246 | * wakes up all functions waiting on the same wait queue. |
| 3247 | */ |
| 3248 | static void |
| 3249 | megasas_complete_abort(struct megasas_instance *instance, |
| 3250 | struct megasas_cmd *cmd) |
| 3251 | { |
| 3252 | if (cmd->sync_cmd) { |
| 3253 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3254 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3255 | wake_up(&instance->abort_cmd_wait_q); |
| 3256 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3260 | * megasas_complete_cmd - Completes a command |
| 3261 | * @instance: Adapter soft state |
| 3262 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3263 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3264 | * SCSI mid-layer instead of the value returned |
| 3265 | * by the FW. This should be used if caller wants |
| 3266 | * an alternate status (as in the case of aborted |
| 3267 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3268 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3269 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3270 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 3271 | u8 alt_status) |
| 3272 | { |
| 3273 | int exception = 0; |
| 3274 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3275 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3276 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3277 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3278 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3279 | /* flag for the retry reset */ |
| 3280 | cmd->retry_for_fw_reset = 0; |
| 3281 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3282 | if (cmd->scmd) |
| 3283 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3284 | |
| 3285 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3286 | case MFI_CMD_INVALID: |
| 3287 | /* Some older 1068 controller FW may keep a pended |
| 3288 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3289 | when booting the kdump kernel. Ignore this command to |
| 3290 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3291 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3292 | "completed\n"); |
| 3293 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3294 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3295 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3296 | case MFI_CMD_PD_SCSI_IO: |
| 3297 | case MFI_CMD_LD_SCSI_IO: |
| 3298 | |
| 3299 | /* |
| 3300 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3301 | * issued either through an IO path or an IOCTL path. If it |
| 3302 | * was via IOCTL, we will send it to internal completion. |
| 3303 | */ |
| 3304 | if (cmd->sync_cmd) { |
| 3305 | cmd->sync_cmd = 0; |
| 3306 | megasas_complete_int_cmd(instance, cmd); |
| 3307 | break; |
| 3308 | } |
Gustavo A. R. Silva | 8d07f7d | 2018-11-27 22:32:27 -0600 | [diff] [blame] | 3309 | /* fall through */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3310 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3311 | case MFI_CMD_LD_READ: |
| 3312 | case MFI_CMD_LD_WRITE: |
| 3313 | |
| 3314 | if (alt_status) { |
| 3315 | cmd->scmd->result = alt_status << 16; |
| 3316 | exception = 1; |
| 3317 | } |
| 3318 | |
| 3319 | if (exception) { |
| 3320 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3321 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3322 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3323 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3324 | cmd->scmd->scsi_done(cmd->scmd); |
| 3325 | megasas_return_cmd(instance, cmd); |
| 3326 | |
| 3327 | break; |
| 3328 | } |
| 3329 | |
| 3330 | switch (hdr->cmd_status) { |
| 3331 | |
| 3332 | case MFI_STAT_OK: |
| 3333 | cmd->scmd->result = DID_OK << 16; |
| 3334 | break; |
| 3335 | |
| 3336 | case MFI_STAT_SCSI_IO_FAILED: |
| 3337 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3338 | cmd->scmd->result = |
| 3339 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3340 | break; |
| 3341 | |
| 3342 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3343 | |
| 3344 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3345 | |
| 3346 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3347 | memset(cmd->scmd->sense_buffer, 0, |
| 3348 | SCSI_SENSE_BUFFERSIZE); |
| 3349 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3350 | hdr->sense_len); |
| 3351 | |
| 3352 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3353 | } |
| 3354 | |
| 3355 | break; |
| 3356 | |
| 3357 | case MFI_STAT_LD_OFFLINE: |
| 3358 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3359 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3360 | break; |
| 3361 | |
| 3362 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3363 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3364 | hdr->cmd_status); |
| 3365 | cmd->scmd->result = DID_ERROR << 16; |
| 3366 | break; |
| 3367 | } |
| 3368 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3369 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3370 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3371 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3372 | cmd->scmd->scsi_done(cmd->scmd); |
| 3373 | megasas_return_cmd(instance, cmd); |
| 3374 | |
| 3375 | break; |
| 3376 | |
| 3377 | case MFI_CMD_SMP: |
| 3378 | case MFI_CMD_STP: |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 3379 | case MFI_CMD_NVME: |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3380 | megasas_complete_int_cmd(instance, cmd); |
| 3381 | break; |
| 3382 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3383 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3384 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3385 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3386 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3387 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3388 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3389 | spin_lock_irqsave(instance->host->host_lock, flags); |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3390 | status = cmd->frame->hdr.cmd_status; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3391 | instance->map_update_cmd = NULL; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3392 | if (status != MFI_STAT_OK) { |
| 3393 | if (status != MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3394 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3395 | cmd->frame->hdr.cmd_status); |
| 3396 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3397 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3398 | spin_unlock_irqrestore( |
| 3399 | instance->host->host_lock, |
| 3400 | flags); |
| 3401 | break; |
| 3402 | } |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3403 | } |
| 3404 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3405 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3406 | |
| 3407 | /* |
| 3408 | * Set fast path IO to ZERO. |
| 3409 | * Validate Map will set proper value. |
| 3410 | * Meanwhile all IOs will go as LD IO. |
| 3411 | */ |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3412 | if (status == MFI_STAT_OK && |
| 3413 | (MR_ValidateMapInfo(instance, (instance->map_id + 1)))) { |
| 3414 | instance->map_id++; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3415 | fusion->fast_path_io = 1; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3416 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3417 | fusion->fast_path_io = 0; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3418 | } |
| 3419 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3420 | megasas_sync_map_info(instance); |
| 3421 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3422 | flags); |
| 3423 | break; |
| 3424 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3425 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3426 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3427 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3428 | megasas_poll_wait_aen = 0; |
| 3429 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3430 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3431 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3432 | /* FW has an updated PD sequence */ |
| 3433 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3434 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3435 | |
| 3436 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3437 | status = cmd->frame->hdr.cmd_status; |
| 3438 | instance->jbod_seq_cmd = NULL; |
| 3439 | megasas_return_cmd(instance, cmd); |
| 3440 | |
| 3441 | if (status == MFI_STAT_OK) { |
| 3442 | instance->pd_seq_map_id++; |
| 3443 | /* Re-register a pd sync seq num cmd */ |
| 3444 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3445 | instance->use_seqnum_jbod_fp = false; |
| 3446 | } else |
| 3447 | instance->use_seqnum_jbod_fp = false; |
| 3448 | |
| 3449 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3450 | break; |
| 3451 | } |
| 3452 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3453 | /* |
| 3454 | * See if got an event notification |
| 3455 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3456 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3457 | megasas_service_aen(instance, cmd); |
| 3458 | else |
| 3459 | megasas_complete_int_cmd(instance, cmd); |
| 3460 | |
| 3461 | break; |
| 3462 | |
| 3463 | case MFI_CMD_ABORT: |
| 3464 | /* |
| 3465 | * Cmd issued to abort another cmd returned |
| 3466 | */ |
| 3467 | megasas_complete_abort(instance, cmd); |
| 3468 | break; |
| 3469 | |
| 3470 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3471 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3472 | hdr->cmd); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3473 | megasas_complete_int_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3474 | break; |
| 3475 | } |
| 3476 | } |
| 3477 | |
| 3478 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3479 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3480 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3481 | * @instance: Adapter soft state |
| 3482 | */ |
| 3483 | static inline void |
| 3484 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3485 | { |
| 3486 | struct megasas_cmd *cmd; |
| 3487 | struct list_head clist_local; |
| 3488 | union megasas_evt_class_locale class_locale; |
| 3489 | unsigned long flags; |
| 3490 | u32 seq_num; |
| 3491 | |
| 3492 | INIT_LIST_HEAD(&clist_local); |
| 3493 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3494 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3495 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3496 | |
| 3497 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3498 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3499 | struct megasas_cmd, list); |
| 3500 | list_del_init(&cmd->list); |
| 3501 | |
| 3502 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3503 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3504 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3505 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3506 | |
| 3507 | cmd->retry_for_fw_reset++; |
| 3508 | |
| 3509 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3510 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3511 | "was tried multiple times during reset." |
| 3512 | "Shutting down the HBA\n", |
| 3513 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3514 | instance->instancet->disable_intr(instance); |
| 3515 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3516 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3517 | return; |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | if (cmd->sync_cmd == 1) { |
| 3522 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3523 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3524 | "cmd attached to internal command!\n"); |
| 3525 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3526 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3527 | "on the internal reset queue," |
| 3528 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3529 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3530 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3531 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3532 | 0, instance->reg_set); |
| 3533 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3534 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3535 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3536 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3537 | |
| 3538 | atomic_inc(&instance->fw_outstanding); |
| 3539 | instance->instancet->fire_cmd(instance, |
| 3540 | cmd->frame_phys_addr, |
| 3541 | cmd->frame_count-1, instance->reg_set); |
| 3542 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3543 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3544 | "internal reset defer list while re-issue!!\n", |
| 3545 | cmd); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3550 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3551 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3552 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3553 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3554 | } |
| 3555 | |
| 3556 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3557 | * Initiate AEN (Asynchronous Event Notification) |
| 3558 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3559 | seq_num = instance->last_seq_num; |
| 3560 | class_locale.members.reserved = 0; |
| 3561 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3562 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3563 | |
| 3564 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3565 | } |
| 3566 | |
| 3567 | /** |
| 3568 | * Move the internal reset pending commands to a deferred queue. |
| 3569 | * |
| 3570 | * We move the commands pending at internal reset time to a |
| 3571 | * pending queue. This queue would be flushed after successful |
| 3572 | * completion of the internal reset sequence. if the internal reset |
| 3573 | * did not complete in time, the kernel reset handler would flush |
| 3574 | * these commands. |
| 3575 | **/ |
| 3576 | static void |
| 3577 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3578 | { |
| 3579 | struct megasas_cmd *cmd; |
| 3580 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3581 | u16 max_cmd = instance->max_fw_cmds; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3582 | u32 defer_index; |
| 3583 | unsigned long flags; |
| 3584 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3585 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3586 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3587 | for (i = 0; i < max_cmd; i++) { |
| 3588 | cmd = instance->cmd_list[i]; |
| 3589 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3590 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3591 | "on the defer queue as internal\n", |
| 3592 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3593 | |
| 3594 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3595 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3596 | " moving this cmd:%p, %d %p, it was" |
| 3597 | "discovered on some list?\n", |
| 3598 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3599 | |
| 3600 | list_del_init(&cmd->list); |
| 3601 | } |
| 3602 | defer_index++; |
| 3603 | list_add_tail(&cmd->list, |
| 3604 | &instance->internal_reset_pending_q); |
| 3605 | } |
| 3606 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3607 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | |
| 3611 | static void |
| 3612 | process_fw_state_change_wq(struct work_struct *work) |
| 3613 | { |
| 3614 | struct megasas_instance *instance = |
| 3615 | container_of(work, struct megasas_instance, work_init); |
| 3616 | u32 wait; |
| 3617 | unsigned long flags; |
| 3618 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3619 | if (atomic_read(&instance->adprecovery) != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3620 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3621 | atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3622 | return ; |
| 3623 | } |
| 3624 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3625 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3626 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3627 | "state, restarting it...\n"); |
| 3628 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3629 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3630 | atomic_set(&instance->fw_outstanding, 0); |
| 3631 | |
| 3632 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3633 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3634 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3635 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3636 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3637 | "initiating next stage...\n"); |
| 3638 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3639 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3640 | "state 2 starting...\n"); |
| 3641 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3642 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3643 | for (wait = 0; wait < 30; wait++) { |
| 3644 | msleep(1000); |
| 3645 | } |
| 3646 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3647 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3648 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3649 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3650 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3651 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3652 | return ; |
| 3653 | } |
| 3654 | |
| 3655 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3656 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3657 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3658 | ) { |
| 3659 | *instance->consumer = *instance->producer; |
| 3660 | } else { |
| 3661 | *instance->consumer = 0; |
| 3662 | *instance->producer = 0; |
| 3663 | } |
| 3664 | |
| 3665 | megasas_issue_init_mfi(instance); |
| 3666 | |
| 3667 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3668 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3669 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3670 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3671 | |
| 3672 | megasas_issue_pending_cmds_again(instance); |
| 3673 | instance->issuepend_done = 1; |
| 3674 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3678 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3679 | * @instance: Adapter soft state |
| 3680 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3681 | * SCSI mid-layer instead of the status |
| 3682 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3683 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3684 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3685 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3686 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3687 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3688 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3689 | u32 mfiStatus; |
| 3690 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3691 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3692 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3693 | instance->reg_set)) == 1) { |
| 3694 | return IRQ_HANDLED; |
| 3695 | } |
| 3696 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3697 | mfiStatus = instance->instancet->clear_intr(instance); |
| 3698 | if (mfiStatus == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3699 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3700 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3701 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | instance->mfiStatus = mfiStatus; |
| 3705 | |
| 3706 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3707 | fw_state = instance->instancet->read_fw_status_reg( |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3708 | instance) & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3709 | |
| 3710 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3711 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3712 | fw_state); |
| 3713 | } |
| 3714 | |
| 3715 | if ((fw_state == MFI_STATE_FAULT) && |
| 3716 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3717 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3718 | |
| 3719 | if ((instance->pdev->device == |
| 3720 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3721 | (instance->pdev->device == |
| 3722 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3723 | (instance->pdev->device == |
| 3724 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3725 | |
| 3726 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3727 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3731 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3732 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3733 | instance->issuepend_done = 0; |
| 3734 | |
| 3735 | atomic_set(&instance->fw_outstanding, 0); |
| 3736 | megasas_internal_reset_defer_cmds(instance); |
| 3737 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3738 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3739 | fw_state, atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3740 | |
| 3741 | schedule_work(&instance->work_init); |
| 3742 | return IRQ_HANDLED; |
| 3743 | |
| 3744 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3745 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3746 | fw_state, instance->disableOnlineCtrlReset); |
| 3747 | } |
| 3748 | } |
| 3749 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3750 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3751 | return IRQ_HANDLED; |
| 3752 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3753 | /** |
| 3754 | * megasas_isr - isr entry point |
| 3755 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3756 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3757 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3758 | struct megasas_irq_context *irq_context = devp; |
| 3759 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3760 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3761 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3762 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3763 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3764 | return IRQ_HANDLED; |
| 3765 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3766 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3767 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3768 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3769 | |
| 3770 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | /** |
| 3774 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3775 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3776 | * |
| 3777 | * During the initialization, FW passes can potentially be in any one of |
| 3778 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3779 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3780 | * has to wait for the ready state. |
| 3781 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3782 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3783 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3784 | { |
| 3785 | int i; |
| 3786 | u8 max_wait; |
| 3787 | u32 fw_state; |
| 3788 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3789 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3790 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3791 | abs_state = instance->instancet->read_fw_status_reg(instance); |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3792 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3793 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3794 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3795 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3796 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3797 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3798 | while (fw_state != MFI_STATE_READY) { |
| 3799 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3800 | switch (fw_state) { |
| 3801 | |
| 3802 | case MFI_STATE_FAULT: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3803 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3804 | if (ocr) { |
| 3805 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3806 | cur_state = MFI_STATE_FAULT; |
| 3807 | break; |
| 3808 | } else |
| 3809 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3810 | |
| 3811 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3812 | /* |
| 3813 | * Set the CLR bit in inbound doorbell |
| 3814 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3815 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3816 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3817 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3818 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3819 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3820 | writel( |
| 3821 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3822 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3823 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3824 | writel( |
| 3825 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3826 | &instance->reg_set->inbound_doorbell); |
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 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3829 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3830 | break; |
| 3831 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3832 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3833 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3834 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3835 | (instance->pdev->device == |
| 3836 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3837 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3838 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3839 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3840 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3841 | writel(MFI_INIT_HOTPLUG, |
| 3842 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3843 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3844 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3845 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3846 | break; |
| 3847 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3848 | case MFI_STATE_OPERATIONAL: |
| 3849 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3850 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3851 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3852 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3853 | if ((instance->pdev->device == |
| 3854 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3855 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3856 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3857 | (instance->adapter_type != MFI_SERIES)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3858 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3859 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3860 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3861 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3862 | for (i = 0; i < (10 * 1000); i += 20) { |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 3863 | if (megasas_readl( |
| 3864 | instance, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3865 | &instance-> |
| 3866 | reg_set-> |
| 3867 | doorbell) & 1) |
| 3868 | msleep(20); |
| 3869 | else |
| 3870 | break; |
| 3871 | } |
| 3872 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3873 | } else |
| 3874 | writel(MFI_RESET_FLAGS, |
| 3875 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3876 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3877 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3878 | cur_state = MFI_STATE_OPERATIONAL; |
| 3879 | break; |
| 3880 | |
| 3881 | case MFI_STATE_UNDEFINED: |
| 3882 | /* |
| 3883 | * This state should not last for more than 2 seconds |
| 3884 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3885 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3886 | cur_state = MFI_STATE_UNDEFINED; |
| 3887 | break; |
| 3888 | |
| 3889 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3890 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3891 | cur_state = MFI_STATE_BB_INIT; |
| 3892 | break; |
| 3893 | |
| 3894 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3895 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3896 | cur_state = MFI_STATE_FW_INIT; |
| 3897 | break; |
| 3898 | |
| 3899 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3900 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3901 | cur_state = MFI_STATE_FW_INIT_2; |
| 3902 | break; |
| 3903 | |
| 3904 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3905 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3906 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 3907 | break; |
| 3908 | |
| 3909 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3910 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3911 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 3912 | break; |
| 3913 | |
| 3914 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3915 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3916 | fw_state); |
| 3917 | return -ENODEV; |
| 3918 | } |
| 3919 | |
| 3920 | /* |
| 3921 | * The cur_state should not last for more than max_wait secs |
| 3922 | */ |
Steve Sistare | 31b6a05 | 2019-03-01 06:46:28 -0800 | [diff] [blame] | 3923 | for (i = 0; i < max_wait * 50; i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3924 | curr_abs_state = instance->instancet-> |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3925 | read_fw_status_reg(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3926 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3927 | if (abs_state == curr_abs_state) { |
Steve Sistare | 31b6a05 | 2019-03-01 06:46:28 -0800 | [diff] [blame] | 3928 | msleep(20); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3929 | } else |
| 3930 | break; |
| 3931 | } |
| 3932 | |
| 3933 | /* |
| 3934 | * Return error if fw_state hasn't changed after max_wait |
| 3935 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3936 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3937 | 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] | 3938 | "in %d secs\n", fw_state, max_wait); |
| 3939 | return -ENODEV; |
| 3940 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3941 | |
| 3942 | abs_state = curr_abs_state; |
| 3943 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3944 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3945 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3946 | |
| 3947 | return 0; |
| 3948 | } |
| 3949 | |
| 3950 | /** |
| 3951 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 3952 | * @instance: Adapter soft state |
| 3953 | */ |
| 3954 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 3955 | { |
| 3956 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3957 | u16 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3958 | struct megasas_cmd *cmd; |
| 3959 | |
| 3960 | if (!instance->frame_dma_pool) |
| 3961 | return; |
| 3962 | |
| 3963 | /* |
| 3964 | * Return all frames to pool |
| 3965 | */ |
| 3966 | for (i = 0; i < max_cmd; i++) { |
| 3967 | |
| 3968 | cmd = instance->cmd_list[i]; |
| 3969 | |
| 3970 | if (cmd->frame) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3971 | dma_pool_free(instance->frame_dma_pool, cmd->frame, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3972 | cmd->frame_phys_addr); |
| 3973 | |
| 3974 | if (cmd->sense) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3975 | dma_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3976 | cmd->sense_phys_addr); |
| 3977 | } |
| 3978 | |
| 3979 | /* |
| 3980 | * Now destroy the pool itself |
| 3981 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 3982 | dma_pool_destroy(instance->frame_dma_pool); |
| 3983 | dma_pool_destroy(instance->sense_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3984 | |
| 3985 | instance->frame_dma_pool = NULL; |
| 3986 | instance->sense_dma_pool = NULL; |
| 3987 | } |
| 3988 | |
| 3989 | /** |
| 3990 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 3991 | * @instance: Adapter soft state |
| 3992 | * |
| 3993 | * Each command packet has an embedded DMA memory buffer that is used for |
| 3994 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 3995 | * function creates those DMA memory buffers for each command packet by using |
| 3996 | * PCI pool facility. |
| 3997 | */ |
| 3998 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 3999 | { |
| 4000 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4001 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4002 | u32 sge_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4003 | u32 frame_count; |
| 4004 | struct megasas_cmd *cmd; |
| 4005 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4006 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4007 | |
| 4008 | /* |
| 4009 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 4010 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 4011 | */ |
| 4012 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 4013 | sizeof(struct megasas_sge32); |
| 4014 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4015 | if (instance->flag_ieee) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 4016 | sge_sz = sizeof(struct megasas_sge_skinny); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 4017 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4018 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 4019 | * For MFI controllers. |
| 4020 | * max_num_sge = 60 |
| 4021 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 4022 | * Total 960 byte (15 MFI frame of 64 byte) |
| 4023 | * |
| 4024 | * Fusion adapter require only 3 extra frame. |
| 4025 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 4026 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 4027 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4028 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4029 | frame_count = (instance->adapter_type == MFI_SERIES) ? |
| 4030 | (15 + 1) : (3 + 1); |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 4031 | instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4032 | /* |
| 4033 | * Use DMA pool facility provided by PCI layer |
| 4034 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4035 | instance->frame_dma_pool = dma_pool_create("megasas frame pool", |
| 4036 | &instance->pdev->dev, |
| 4037 | instance->mfi_frame_size, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4038 | |
| 4039 | if (!instance->frame_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4040 | 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] | 4041 | return -ENOMEM; |
| 4042 | } |
| 4043 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4044 | instance->sense_dma_pool = dma_pool_create("megasas sense pool", |
| 4045 | &instance->pdev->dev, 128, |
| 4046 | 4, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4047 | |
| 4048 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4049 | 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] | 4050 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4051 | dma_pool_destroy(instance->frame_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4052 | instance->frame_dma_pool = NULL; |
| 4053 | |
| 4054 | return -ENOMEM; |
| 4055 | } |
| 4056 | |
| 4057 | /* |
| 4058 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 4059 | * By making cmd->index as the context instead of the &cmd, we can |
| 4060 | * always use 32bit context regardless of the architecture |
| 4061 | */ |
| 4062 | for (i = 0; i < max_cmd; i++) { |
| 4063 | |
| 4064 | cmd = instance->cmd_list[i]; |
| 4065 | |
Souptick Joarder | 61b142a | 2018-02-15 21:55:06 +0530 | [diff] [blame] | 4066 | cmd->frame = dma_pool_zalloc(instance->frame_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4067 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 4068 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4069 | cmd->sense = dma_pool_alloc(instance->sense_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4070 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 4071 | |
| 4072 | /* |
| 4073 | * megasas_teardown_frame_pool() takes care of freeing |
| 4074 | * whatever has been allocated |
| 4075 | */ |
| 4076 | if (!cmd->frame || !cmd->sense) { |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4077 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "dma_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4078 | megasas_teardown_frame_pool(instance); |
| 4079 | return -ENOMEM; |
| 4080 | } |
| 4081 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4082 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4083 | cmd->frame->io.pad_0 = 0; |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4084 | if ((instance->adapter_type == MFI_SERIES) && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 4085 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | return 0; |
| 4089 | } |
| 4090 | |
| 4091 | /** |
| 4092 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 4093 | * @instance: Adapter soft state |
| 4094 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4095 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4096 | { |
| 4097 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4098 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4099 | /* First free the MFI frame pool */ |
| 4100 | megasas_teardown_frame_pool(instance); |
| 4101 | |
| 4102 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4103 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 4104 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4105 | kfree(instance->cmd_list[i]); |
| 4106 | |
| 4107 | /* Free the cmd_list buffer itself */ |
| 4108 | kfree(instance->cmd_list); |
| 4109 | instance->cmd_list = NULL; |
| 4110 | |
| 4111 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 4112 | } |
| 4113 | |
| 4114 | /** |
| 4115 | * megasas_alloc_cmds - Allocates the command packets |
| 4116 | * @instance: Adapter soft state |
| 4117 | * |
| 4118 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 4119 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 4120 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 4121 | * the FW. |
| 4122 | * |
| 4123 | * Each frame has a 32-bit field called context (tag). This context is used |
| 4124 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 4125 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 4126 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 4127 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 4128 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 4129 | * This array is used only to look up the megasas_cmd given the context. The |
| 4130 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 4131 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4132 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4133 | { |
| 4134 | int i; |
| 4135 | int j; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4136 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4137 | struct megasas_cmd *cmd; |
| 4138 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4139 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4140 | |
| 4141 | /* |
| 4142 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 4143 | * Allocate the dynamic array first and then allocate individual |
| 4144 | * commands. |
| 4145 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 4146 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4147 | |
| 4148 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4149 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4150 | return -ENOMEM; |
| 4151 | } |
| 4152 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4153 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4154 | |
| 4155 | for (i = 0; i < max_cmd; i++) { |
| 4156 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 4157 | GFP_KERNEL); |
| 4158 | |
| 4159 | if (!instance->cmd_list[i]) { |
| 4160 | |
| 4161 | for (j = 0; j < i; j++) |
| 4162 | kfree(instance->cmd_list[j]); |
| 4163 | |
| 4164 | kfree(instance->cmd_list); |
| 4165 | instance->cmd_list = NULL; |
| 4166 | |
| 4167 | return -ENOMEM; |
| 4168 | } |
| 4169 | } |
| 4170 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4171 | for (i = 0; i < max_cmd; i++) { |
| 4172 | cmd = instance->cmd_list[i]; |
| 4173 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 4174 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4175 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4176 | cmd->instance = instance; |
| 4177 | |
| 4178 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 4179 | } |
| 4180 | |
| 4181 | /* |
| 4182 | * Create a frame pool and assign one frame to each cmd |
| 4183 | */ |
| 4184 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4185 | 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] | 4186 | megasas_free_cmds(instance); |
Jason Yan | bcf3b67 | 2019-02-15 19:50:27 +0800 | [diff] [blame] | 4187 | return -ENOMEM; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | return 0; |
| 4191 | } |
| 4192 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4193 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4194 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 4195 | * @instance: Adapter soft state |
| 4196 | * |
| 4197 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 4198 | * or FW is not under OCR. |
| 4199 | */ |
| 4200 | inline int |
| 4201 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 4202 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4203 | if (instance->adapter_type == MFI_SERIES) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4204 | return KILL_ADAPTER; |
| 4205 | else if (instance->unload || |
| 4206 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 4207 | return IGNORE_TIMEOUT; |
| 4208 | else |
| 4209 | return INITIATE_OCR; |
| 4210 | } |
| 4211 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4212 | static void |
| 4213 | megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4214 | { |
| 4215 | int ret; |
| 4216 | struct megasas_cmd *cmd; |
| 4217 | struct megasas_dcmd_frame *dcmd; |
| 4218 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4219 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 4220 | u16 device_id = 0; |
| 4221 | |
| 4222 | device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4223 | cmd = megasas_get_cmd(instance); |
| 4224 | |
| 4225 | if (!cmd) { |
| 4226 | dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4227 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | dcmd = &cmd->frame->dcmd; |
| 4231 | |
| 4232 | memset(instance->pd_info, 0, sizeof(*instance->pd_info)); |
| 4233 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4234 | |
| 4235 | dcmd->mbox.s[0] = cpu_to_le16(device_id); |
| 4236 | dcmd->cmd = MFI_CMD_DCMD; |
| 4237 | dcmd->cmd_status = 0xFF; |
| 4238 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4239 | dcmd->flags = MFI_FRAME_DIR_READ; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4240 | dcmd->timeout = 0; |
| 4241 | dcmd->pad_0 = 0; |
| 4242 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4243 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_GET_INFO); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4244 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4245 | megasas_set_dma_settings(instance, dcmd, instance->pd_info_h, |
| 4246 | sizeof(struct MR_PD_INFO)); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [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 | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4250 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 4251 | else |
| 4252 | ret = megasas_issue_polled(instance, cmd); |
| 4253 | |
| 4254 | switch (ret) { |
| 4255 | case DCMD_SUCCESS: |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4256 | mr_device_priv_data = sdev->hostdata; |
| 4257 | le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType); |
| 4258 | mr_device_priv_data->interface_type = |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4259 | instance->pd_info->state.ddf.pdType.intf; |
| 4260 | break; |
| 4261 | |
| 4262 | case DCMD_TIMEOUT: |
| 4263 | |
| 4264 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4265 | case INITIATE_OCR: |
| 4266 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4267 | megasas_reset_fusion(instance->host, |
| 4268 | MFI_IO_TIMEOUT_OCR); |
| 4269 | break; |
| 4270 | case KILL_ADAPTER: |
| 4271 | megaraid_sas_kill_hba(instance); |
| 4272 | break; |
| 4273 | case IGNORE_TIMEOUT: |
| 4274 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4275 | __func__, __LINE__); |
| 4276 | break; |
| 4277 | } |
| 4278 | |
| 4279 | break; |
| 4280 | } |
| 4281 | |
| 4282 | if (ret != DCMD_TIMEOUT) |
| 4283 | megasas_return_cmd(instance, cmd); |
| 4284 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4285 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4286 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4287 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4288 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 4289 | * @instance: Adapter soft state |
| 4290 | * @pd_list: pd_list structure |
| 4291 | * |
| 4292 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4293 | * list structure. This information is mainly used to find out SYSTEM |
| 4294 | * supported by the FW. |
| 4295 | */ |
| 4296 | static int |
| 4297 | megasas_get_pd_list(struct megasas_instance *instance) |
| 4298 | { |
| 4299 | int ret = 0, pd_index = 0; |
| 4300 | struct megasas_cmd *cmd; |
| 4301 | struct megasas_dcmd_frame *dcmd; |
| 4302 | struct MR_PD_LIST *ci; |
| 4303 | struct MR_PD_ADDRESS *pd_addr; |
| 4304 | dma_addr_t ci_h = 0; |
| 4305 | |
Sumit Saxena | d908316 | 2016-07-08 03:30:16 -0700 | [diff] [blame] | 4306 | if (instance->pd_list_not_supported) { |
| 4307 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4308 | "not supported by firmware\n"); |
| 4309 | return ret; |
| 4310 | } |
| 4311 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4312 | ci = instance->pd_list_buf; |
| 4313 | ci_h = instance->pd_list_buf_h; |
| 4314 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4315 | cmd = megasas_get_cmd(instance); |
| 4316 | |
| 4317 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4318 | 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] | 4319 | return -ENOMEM; |
| 4320 | } |
| 4321 | |
| 4322 | dcmd = &cmd->frame->dcmd; |
| 4323 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4324 | memset(ci, 0, sizeof(*ci)); |
| 4325 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4326 | |
| 4327 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 4328 | dcmd->mbox.b[1] = 0; |
| 4329 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4330 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4331 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4332 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4333 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4334 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4335 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 4336 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4337 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4338 | megasas_set_dma_settings(instance, dcmd, instance->pd_list_buf_h, |
| 4339 | (MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST))); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4340 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4341 | if ((instance->adapter_type != MFI_SERIES) && |
| 4342 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4343 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4344 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4345 | else |
| 4346 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4347 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4348 | switch (ret) { |
| 4349 | case DCMD_FAILED: |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4350 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4351 | "failed/not supported by firmware\n"); |
| 4352 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4353 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4354 | megaraid_sas_kill_hba(instance); |
| 4355 | else |
| 4356 | instance->pd_list_not_supported = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4357 | break; |
| 4358 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4359 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4360 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4361 | case INITIATE_OCR: |
| 4362 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4363 | /* |
| 4364 | * DCMD failed from AEN path. |
| 4365 | * AEN path already hold reset_mutex to avoid PCI access |
| 4366 | * while OCR is in progress. |
| 4367 | */ |
| 4368 | mutex_unlock(&instance->reset_mutex); |
| 4369 | megasas_reset_fusion(instance->host, |
| 4370 | MFI_IO_TIMEOUT_OCR); |
| 4371 | mutex_lock(&instance->reset_mutex); |
| 4372 | break; |
| 4373 | case KILL_ADAPTER: |
| 4374 | megaraid_sas_kill_hba(instance); |
| 4375 | break; |
| 4376 | case IGNORE_TIMEOUT: |
| 4377 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4378 | __func__, __LINE__); |
| 4379 | break; |
| 4380 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4381 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4382 | break; |
| 4383 | |
| 4384 | case DCMD_SUCCESS: |
| 4385 | pd_addr = ci->addr; |
| 4386 | |
| 4387 | if ((le32_to_cpu(ci->count) > |
| 4388 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4389 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4390 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4391 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4392 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4393 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4394 | 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] | 4395 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4396 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4397 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4398 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4399 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4400 | MR_PD_STATE_SYSTEM; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4401 | pd_addr++; |
| 4402 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4403 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4404 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4405 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4406 | break; |
| 4407 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4408 | } |
| 4409 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4410 | if (ret != DCMD_TIMEOUT) |
| 4411 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4412 | |
| 4413 | return ret; |
| 4414 | } |
| 4415 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4416 | /* |
| 4417 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4418 | * @instance: Adapter soft state |
| 4419 | * @ld_list: ld_list structure |
| 4420 | * |
| 4421 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4422 | * list structure. This information is mainly used to find out SYSTEM |
| 4423 | * supported by the FW. |
| 4424 | */ |
| 4425 | static int |
| 4426 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4427 | { |
| 4428 | int ret = 0, ld_index = 0, ids = 0; |
| 4429 | struct megasas_cmd *cmd; |
| 4430 | struct megasas_dcmd_frame *dcmd; |
| 4431 | struct MR_LD_LIST *ci; |
| 4432 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4433 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4434 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4435 | ci = instance->ld_list_buf; |
| 4436 | ci_h = instance->ld_list_buf_h; |
| 4437 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4438 | cmd = megasas_get_cmd(instance); |
| 4439 | |
| 4440 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4441 | 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] | 4442 | return -ENOMEM; |
| 4443 | } |
| 4444 | |
| 4445 | dcmd = &cmd->frame->dcmd; |
| 4446 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4447 | memset(ci, 0, sizeof(*ci)); |
| 4448 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4449 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4450 | if (instance->supportmax256vd) |
| 4451 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4452 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4453 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4454 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4455 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4456 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4457 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4458 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4459 | dcmd->pad_0 = 0; |
| 4460 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4461 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4462 | sizeof(struct MR_LD_LIST)); |
| 4463 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4464 | if ((instance->adapter_type != MFI_SERIES) && |
| 4465 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4466 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4467 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4468 | else |
| 4469 | ret = megasas_issue_polled(instance, cmd); |
| 4470 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4471 | ld_count = le32_to_cpu(ci->ldCount); |
| 4472 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4473 | switch (ret) { |
| 4474 | case DCMD_FAILED: |
| 4475 | megaraid_sas_kill_hba(instance); |
| 4476 | break; |
| 4477 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4478 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4479 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4480 | case INITIATE_OCR: |
| 4481 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4482 | /* |
| 4483 | * DCMD failed from AEN path. |
| 4484 | * AEN path already hold reset_mutex to avoid PCI access |
| 4485 | * while OCR is in progress. |
| 4486 | */ |
| 4487 | mutex_unlock(&instance->reset_mutex); |
| 4488 | megasas_reset_fusion(instance->host, |
| 4489 | MFI_IO_TIMEOUT_OCR); |
| 4490 | mutex_lock(&instance->reset_mutex); |
| 4491 | break; |
| 4492 | case KILL_ADAPTER: |
| 4493 | megaraid_sas_kill_hba(instance); |
| 4494 | break; |
| 4495 | case IGNORE_TIMEOUT: |
| 4496 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4497 | __func__, __LINE__); |
| 4498 | break; |
| 4499 | } |
| 4500 | |
| 4501 | break; |
| 4502 | |
| 4503 | case DCMD_SUCCESS: |
| 4504 | if (ld_count > instance->fw_supported_vd_count) |
| 4505 | break; |
| 4506 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4507 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4508 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4509 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4510 | if (ci->ldList[ld_index].state != 0) { |
| 4511 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4512 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4513 | } |
| 4514 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4515 | |
| 4516 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4517 | } |
| 4518 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4519 | if (ret != DCMD_TIMEOUT) |
| 4520 | megasas_return_cmd(instance, cmd); |
| 4521 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4522 | return ret; |
| 4523 | } |
| 4524 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4525 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4526 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4527 | * @instance: Adapter soft state |
| 4528 | * @ld_list: ld_list structure |
| 4529 | * |
| 4530 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4531 | * list structure. This information is mainly used to find out SYSTEM |
| 4532 | * supported by the FW. |
| 4533 | */ |
| 4534 | static int |
| 4535 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4536 | { |
| 4537 | int ret = 0, ld_index = 0, ids = 0; |
| 4538 | struct megasas_cmd *cmd; |
| 4539 | struct megasas_dcmd_frame *dcmd; |
| 4540 | struct MR_LD_TARGETID_LIST *ci; |
| 4541 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4542 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4543 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4544 | ci = instance->ld_targetid_list_buf; |
| 4545 | ci_h = instance->ld_targetid_list_buf_h; |
| 4546 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4547 | cmd = megasas_get_cmd(instance); |
| 4548 | |
| 4549 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4550 | dev_warn(&instance->pdev->dev, |
| 4551 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4552 | return -ENOMEM; |
| 4553 | } |
| 4554 | |
| 4555 | dcmd = &cmd->frame->dcmd; |
| 4556 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4557 | memset(ci, 0, sizeof(*ci)); |
| 4558 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4559 | |
| 4560 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4561 | if (instance->supportmax256vd) |
| 4562 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4563 | |
| 4564 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4565 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4566 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4567 | dcmd->flags = MFI_FRAME_DIR_READ; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4568 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4569 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4570 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4571 | dcmd->pad_0 = 0; |
| 4572 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4573 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4574 | sizeof(struct MR_LD_TARGETID_LIST)); |
| 4575 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4576 | if ((instance->adapter_type != MFI_SERIES) && |
| 4577 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4578 | 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] | 4579 | else |
| 4580 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4581 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4582 | switch (ret) { |
| 4583 | case DCMD_FAILED: |
| 4584 | dev_info(&instance->pdev->dev, |
| 4585 | "DCMD not supported by firmware - %s %d\n", |
| 4586 | __func__, __LINE__); |
| 4587 | ret = megasas_get_ld_list(instance); |
| 4588 | break; |
| 4589 | case DCMD_TIMEOUT: |
| 4590 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4591 | case INITIATE_OCR: |
| 4592 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4593 | /* |
| 4594 | * DCMD failed from AEN path. |
| 4595 | * AEN path already hold reset_mutex to avoid PCI access |
| 4596 | * while OCR is in progress. |
| 4597 | */ |
| 4598 | mutex_unlock(&instance->reset_mutex); |
| 4599 | megasas_reset_fusion(instance->host, |
| 4600 | MFI_IO_TIMEOUT_OCR); |
| 4601 | mutex_lock(&instance->reset_mutex); |
| 4602 | break; |
| 4603 | case KILL_ADAPTER: |
| 4604 | megaraid_sas_kill_hba(instance); |
| 4605 | break; |
| 4606 | case IGNORE_TIMEOUT: |
| 4607 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4608 | __func__, __LINE__); |
| 4609 | break; |
| 4610 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4611 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4612 | break; |
| 4613 | case DCMD_SUCCESS: |
| 4614 | tgtid_count = le32_to_cpu(ci->count); |
| 4615 | |
| 4616 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4617 | break; |
| 4618 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4619 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4620 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4621 | ids = ci->targetId[ld_index]; |
| 4622 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4623 | } |
| 4624 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4625 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4628 | if (ret != DCMD_TIMEOUT) |
| 4629 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4630 | |
| 4631 | return ret; |
| 4632 | } |
| 4633 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4634 | /** |
| 4635 | * dcmd.opcode - MR_DCMD_CTRL_DEVICE_LIST_GET |
| 4636 | * dcmd.mbox - reserved |
| 4637 | * dcmd.sge IN - ptr to return MR_HOST_DEVICE_LIST structure |
| 4638 | * Desc: This DCMD will return the combined device list |
| 4639 | * Status: MFI_STAT_OK - List returned successfully |
| 4640 | * MFI_STAT_INVALID_CMD - Firmware support for the feature has been |
| 4641 | * disabled |
| 4642 | * @instance: Adapter soft state |
| 4643 | * @is_probe: Driver probe check |
| 4644 | * Return: 0 if DCMD succeeded |
| 4645 | * non-zero if failed |
| 4646 | */ |
YueHaibing | 7c3f8ca | 2019-04-13 22:21:38 +0800 | [diff] [blame] | 4647 | static int |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4648 | megasas_host_device_list_query(struct megasas_instance *instance, |
| 4649 | bool is_probe) |
| 4650 | { |
| 4651 | int ret, i, target_id; |
| 4652 | struct megasas_cmd *cmd; |
| 4653 | struct megasas_dcmd_frame *dcmd; |
| 4654 | struct MR_HOST_DEVICE_LIST *ci; |
| 4655 | u32 count; |
| 4656 | dma_addr_t ci_h; |
| 4657 | |
| 4658 | ci = instance->host_device_list_buf; |
| 4659 | ci_h = instance->host_device_list_buf_h; |
| 4660 | |
| 4661 | cmd = megasas_get_cmd(instance); |
| 4662 | |
| 4663 | if (!cmd) { |
| 4664 | dev_warn(&instance->pdev->dev, |
| 4665 | "%s: failed to get cmd\n", |
| 4666 | __func__); |
| 4667 | return -ENOMEM; |
| 4668 | } |
| 4669 | |
| 4670 | dcmd = &cmd->frame->dcmd; |
| 4671 | |
| 4672 | memset(ci, 0, sizeof(*ci)); |
| 4673 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4674 | |
| 4675 | dcmd->mbox.b[0] = is_probe ? 0 : 1; |
| 4676 | dcmd->cmd = MFI_CMD_DCMD; |
| 4677 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
| 4678 | dcmd->sge_count = 1; |
| 4679 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 4680 | dcmd->timeout = 0; |
| 4681 | dcmd->pad_0 = 0; |
| 4682 | dcmd->data_xfer_len = cpu_to_le32(HOST_DEVICE_LIST_SZ); |
| 4683 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_DEVICE_LIST_GET); |
| 4684 | |
| 4685 | megasas_set_dma_settings(instance, dcmd, ci_h, HOST_DEVICE_LIST_SZ); |
| 4686 | |
| 4687 | if (!instance->mask_interrupts) { |
| 4688 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4689 | MFI_IO_TIMEOUT_SECS); |
| 4690 | } else { |
| 4691 | ret = megasas_issue_polled(instance, cmd); |
| 4692 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4693 | } |
| 4694 | |
| 4695 | switch (ret) { |
| 4696 | case DCMD_SUCCESS: |
| 4697 | /* Fill the internal pd_list and ld_ids array based on |
| 4698 | * targetIds returned by FW |
| 4699 | */ |
| 4700 | count = le32_to_cpu(ci->count); |
| 4701 | |
| 4702 | memset(instance->local_pd_list, 0, |
| 4703 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
| 4704 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
| 4705 | for (i = 0; i < count; i++) { |
| 4706 | target_id = le16_to_cpu(ci->host_device_list[i].target_id); |
| 4707 | if (ci->host_device_list[i].flags.u.bits.is_sys_pd) { |
| 4708 | instance->local_pd_list[target_id].tid = target_id; |
| 4709 | instance->local_pd_list[target_id].driveType = |
| 4710 | ci->host_device_list[i].scsi_type; |
| 4711 | instance->local_pd_list[target_id].driveState = |
| 4712 | MR_PD_STATE_SYSTEM; |
| 4713 | } else { |
| 4714 | instance->ld_ids[target_id] = target_id; |
| 4715 | } |
| 4716 | } |
| 4717 | |
| 4718 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4719 | sizeof(instance->pd_list)); |
| 4720 | break; |
| 4721 | |
| 4722 | case DCMD_TIMEOUT: |
| 4723 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4724 | case INITIATE_OCR: |
| 4725 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4726 | megasas_reset_fusion(instance->host, |
| 4727 | MFI_IO_TIMEOUT_OCR); |
| 4728 | break; |
| 4729 | case KILL_ADAPTER: |
| 4730 | megaraid_sas_kill_hba(instance); |
| 4731 | break; |
| 4732 | case IGNORE_TIMEOUT: |
| 4733 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4734 | __func__, __LINE__); |
| 4735 | break; |
| 4736 | } |
| 4737 | break; |
| 4738 | case DCMD_FAILED: |
| 4739 | dev_err(&instance->pdev->dev, |
| 4740 | "%s: MR_DCMD_CTRL_DEVICE_LIST_GET failed\n", |
| 4741 | __func__); |
| 4742 | break; |
| 4743 | } |
| 4744 | |
| 4745 | if (ret != DCMD_TIMEOUT) |
| 4746 | megasas_return_cmd(instance, cmd); |
| 4747 | |
| 4748 | return ret; |
| 4749 | } |
| 4750 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4751 | /* |
| 4752 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4753 | * instance : Controller's instance |
| 4754 | */ |
| 4755 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4756 | { |
| 4757 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4758 | u32 ventura_map_sz = 0; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4759 | |
| 4760 | fusion = instance->ctrl_context; |
| 4761 | /* For MFI based controllers return dummy success */ |
| 4762 | if (!fusion) |
| 4763 | return; |
| 4764 | |
| 4765 | instance->supportmax256vd = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4766 | instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4767 | /* Below is additional check to address future FW enhancement */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4768 | if (instance->ctrl_info_buf->max_lds > 64) |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4769 | instance->supportmax256vd = 1; |
| 4770 | |
| 4771 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4772 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4773 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4774 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4775 | if (instance->supportmax256vd) { |
| 4776 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4777 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4778 | } else { |
| 4779 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4780 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4781 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4782 | |
| 4783 | dev_info(&instance->pdev->dev, |
Shivasharan S | cba67d9 | 2018-10-16 23:37:56 -0700 | [diff] [blame] | 4784 | "FW provided supportMaxExtLDs: %d\tmax_lds: %d\n", |
| 4785 | instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs ? 1 : 0, |
| 4786 | instance->ctrl_info_buf->max_lds); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4787 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4788 | if (instance->max_raid_mapsize) { |
| 4789 | ventura_map_sz = instance->max_raid_mapsize * |
| 4790 | MR_MIN_MAP_SIZE; /* 64k */ |
| 4791 | fusion->current_map_sz = ventura_map_sz; |
| 4792 | fusion->max_map_sz = ventura_map_sz; |
| 4793 | } else { |
| 4794 | fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 4795 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4796 | (instance->fw_supported_vd_count - 1)); |
| 4797 | 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] | 4798 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4799 | fusion->max_map_sz = |
| 4800 | max(fusion->old_map_sz, fusion->new_map_sz); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4801 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4802 | if (instance->supportmax256vd) |
| 4803 | fusion->current_map_sz = fusion->new_map_sz; |
| 4804 | else |
| 4805 | fusion->current_map_sz = fusion->old_map_sz; |
| 4806 | } |
| 4807 | /* irrespective of FW raid maps, driver raid map is constant */ |
| 4808 | 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] | 4809 | } |
| 4810 | |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 4811 | /* |
| 4812 | * dcmd.opcode - MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES |
| 4813 | * dcmd.hdr.length - number of bytes to read |
| 4814 | * dcmd.sge - Ptr to MR_SNAPDUMP_PROPERTIES |
| 4815 | * Desc: Fill in snapdump properties |
| 4816 | * Status: MFI_STAT_OK- Command successful |
| 4817 | */ |
| 4818 | void megasas_get_snapdump_properties(struct megasas_instance *instance) |
| 4819 | { |
| 4820 | int ret = 0; |
| 4821 | struct megasas_cmd *cmd; |
| 4822 | struct megasas_dcmd_frame *dcmd; |
| 4823 | struct MR_SNAPDUMP_PROPERTIES *ci; |
| 4824 | dma_addr_t ci_h = 0; |
| 4825 | |
| 4826 | ci = instance->snapdump_prop; |
| 4827 | ci_h = instance->snapdump_prop_h; |
| 4828 | |
| 4829 | if (!ci) |
| 4830 | return; |
| 4831 | |
| 4832 | cmd = megasas_get_cmd(instance); |
| 4833 | |
| 4834 | if (!cmd) { |
| 4835 | dev_dbg(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4836 | return; |
| 4837 | } |
| 4838 | |
| 4839 | dcmd = &cmd->frame->dcmd; |
| 4840 | |
| 4841 | memset(ci, 0, sizeof(*ci)); |
| 4842 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4843 | |
| 4844 | dcmd->cmd = MFI_CMD_DCMD; |
| 4845 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
| 4846 | dcmd->sge_count = 1; |
| 4847 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 4848 | dcmd->timeout = 0; |
| 4849 | dcmd->pad_0 = 0; |
| 4850 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_SNAPDUMP_PROPERTIES)); |
| 4851 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES); |
| 4852 | |
| 4853 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4854 | sizeof(struct MR_SNAPDUMP_PROPERTIES)); |
| 4855 | |
| 4856 | if (!instance->mask_interrupts) { |
| 4857 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4858 | MFI_IO_TIMEOUT_SECS); |
| 4859 | } else { |
| 4860 | ret = megasas_issue_polled(instance, cmd); |
| 4861 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4862 | } |
| 4863 | |
| 4864 | switch (ret) { |
| 4865 | case DCMD_SUCCESS: |
| 4866 | instance->snapdump_wait_time = |
| 4867 | min_t(u8, ci->trigger_min_num_sec_before_ocr, |
| 4868 | MEGASAS_MAX_SNAP_DUMP_WAIT_TIME); |
| 4869 | break; |
| 4870 | |
| 4871 | case DCMD_TIMEOUT: |
| 4872 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4873 | case INITIATE_OCR: |
| 4874 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4875 | megasas_reset_fusion(instance->host, |
| 4876 | MFI_IO_TIMEOUT_OCR); |
| 4877 | break; |
| 4878 | case KILL_ADAPTER: |
| 4879 | megaraid_sas_kill_hba(instance); |
| 4880 | break; |
| 4881 | case IGNORE_TIMEOUT: |
| 4882 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4883 | __func__, __LINE__); |
| 4884 | break; |
| 4885 | } |
| 4886 | } |
| 4887 | |
| 4888 | if (ret != DCMD_TIMEOUT) |
| 4889 | megasas_return_cmd(instance, cmd); |
| 4890 | } |
| 4891 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4892 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4893 | * megasas_get_controller_info - Returns FW's controller structure |
| 4894 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4895 | * |
| 4896 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 4897 | * This information is mainly used to find out the maximum IO transfer per |
| 4898 | * command supported by the FW. |
| 4899 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4900 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4901 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4902 | { |
| 4903 | int ret = 0; |
| 4904 | struct megasas_cmd *cmd; |
| 4905 | struct megasas_dcmd_frame *dcmd; |
| 4906 | struct megasas_ctrl_info *ci; |
| 4907 | dma_addr_t ci_h = 0; |
| 4908 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4909 | ci = instance->ctrl_info_buf; |
| 4910 | ci_h = instance->ctrl_info_buf_h; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4911 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4912 | cmd = megasas_get_cmd(instance); |
| 4913 | |
| 4914 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4915 | 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] | 4916 | return -ENOMEM; |
| 4917 | } |
| 4918 | |
| 4919 | dcmd = &cmd->frame->dcmd; |
| 4920 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4921 | memset(ci, 0, sizeof(*ci)); |
| 4922 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4923 | |
| 4924 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4925 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4926 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4927 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4928 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4929 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4930 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 4931 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4932 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4933 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4934 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4935 | sizeof(struct megasas_ctrl_info)); |
| 4936 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4937 | if ((instance->adapter_type != MFI_SERIES) && |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 4938 | !instance->mask_interrupts) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4939 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 4940 | } else { |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4941 | ret = megasas_issue_polled(instance, cmd); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 4942 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4943 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4944 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4945 | switch (ret) { |
| 4946 | case DCMD_SUCCESS: |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4947 | /* Save required controller information in |
| 4948 | * CPU endianness format. |
| 4949 | */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4950 | le32_to_cpus((u32 *)&ci->properties.OnOffProperties); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 4951 | le16_to_cpus((u16 *)&ci->properties.on_off_properties2); |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4952 | le32_to_cpus((u32 *)&ci->adapterOperations2); |
| 4953 | le32_to_cpus((u32 *)&ci->adapterOperations3); |
| 4954 | le16_to_cpus((u16 *)&ci->adapter_operations4); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4955 | |
| 4956 | /* Update the latest Ext VD info. |
| 4957 | * From Init path, store current firmware details. |
| 4958 | * From OCR path, detect any firmware properties changes. |
| 4959 | * in case of Firmware upgrade without system reboot. |
| 4960 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4961 | megasas_update_ext_vd_details(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4962 | instance->use_seqnum_jbod_fp = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4963 | ci->adapterOperations3.useSeqNumJbodFP; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 4964 | instance->support_morethan256jbod = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4965 | ci->adapter_operations4.support_pd_map_target_id; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 4966 | instance->support_nvme_passthru = |
| 4967 | ci->adapter_operations4.support_nvme_passthru; |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 4968 | instance->task_abort_tmo = ci->TaskAbortTO; |
| 4969 | instance->max_reset_tmo = ci->MaxResetTO; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4970 | |
| 4971 | /*Check whether controller is iMR or MR */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4972 | instance->is_imr = (ci->memory_size ? 0 : 1); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 4973 | |
| 4974 | instance->snapdump_wait_time = |
| 4975 | (ci->properties.on_off_properties2.enable_snap_dump ? |
| 4976 | MEGASAS_DEFAULT_SNAP_DUMP_WAIT_TIME : 0); |
| 4977 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4978 | instance->enable_fw_dev_list = |
| 4979 | ci->properties.on_off_properties2.enable_fw_dev_list; |
| 4980 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4981 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4982 | "controller type\t: %s(%dMB)\n", |
| 4983 | instance->is_imr ? "iMR" : "MR", |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4984 | le16_to_cpu(ci->memory_size)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4985 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 4986 | instance->disableOnlineCtrlReset = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4987 | ci->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4988 | instance->secure_jbod_support = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4989 | ci->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4990 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 4991 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 4992 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 4993 | instance->secure_jbod_support ? "Yes" : "No"); |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 4994 | dev_info(&instance->pdev->dev, "NVMe passthru support\t: %s\n", |
| 4995 | instance->support_nvme_passthru ? "Yes" : "No"); |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 4996 | dev_info(&instance->pdev->dev, |
| 4997 | "FW provided TM TaskAbort/Reset timeout\t: %d secs/%d secs\n", |
| 4998 | instance->task_abort_tmo, instance->max_reset_tmo); |
| 4999 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5000 | break; |
| 5001 | |
| 5002 | case DCMD_TIMEOUT: |
| 5003 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5004 | case INITIATE_OCR: |
| 5005 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5006 | megasas_reset_fusion(instance->host, |
| 5007 | MFI_IO_TIMEOUT_OCR); |
| 5008 | break; |
| 5009 | case KILL_ADAPTER: |
| 5010 | megaraid_sas_kill_hba(instance); |
| 5011 | break; |
| 5012 | case IGNORE_TIMEOUT: |
| 5013 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 5014 | __func__, __LINE__); |
| 5015 | break; |
| 5016 | } |
Shivasharan S | 2747e6b | 2018-06-04 03:45:09 -0700 | [diff] [blame] | 5017 | break; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5018 | case DCMD_FAILED: |
| 5019 | megaraid_sas_kill_hba(instance); |
| 5020 | break; |
| 5021 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5022 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5023 | |
Shivasharan S | 2747e6b | 2018-06-04 03:45:09 -0700 | [diff] [blame] | 5024 | if (ret != DCMD_TIMEOUT) |
| 5025 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5026 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5027 | return ret; |
| 5028 | } |
| 5029 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5030 | /* |
| 5031 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 5032 | * to firmware |
| 5033 | * |
| 5034 | * @instance: Adapter soft state |
| 5035 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 5036 | MR_CRASH_BUF_TURN_OFF = 0 |
| 5037 | MR_CRASH_BUF_TURN_ON = 1 |
| 5038 | * @return 0 on success non-zero on failure. |
| 5039 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 5040 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 5041 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 5042 | * crash dump feature is supported by the FW. |
| 5043 | * |
| 5044 | */ |
| 5045 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 5046 | u8 crash_buf_state) |
| 5047 | { |
| 5048 | int ret = 0; |
| 5049 | struct megasas_cmd *cmd; |
| 5050 | struct megasas_dcmd_frame *dcmd; |
| 5051 | |
| 5052 | cmd = megasas_get_cmd(instance); |
| 5053 | |
| 5054 | if (!cmd) { |
| 5055 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 5056 | return -ENOMEM; |
| 5057 | } |
| 5058 | |
| 5059 | |
| 5060 | dcmd = &cmd->frame->dcmd; |
| 5061 | |
| 5062 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5063 | dcmd->mbox.b[0] = crash_buf_state; |
| 5064 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5065 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5066 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5067 | dcmd->flags = MFI_FRAME_DIR_NONE; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5068 | dcmd->timeout = 0; |
| 5069 | dcmd->pad_0 = 0; |
| 5070 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 5071 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5072 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5073 | megasas_set_dma_settings(instance, dcmd, instance->crash_dump_h, |
| 5074 | CRASH_DMA_BUF_SIZE); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5075 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5076 | if ((instance->adapter_type != MFI_SERIES) && |
| 5077 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5078 | 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] | 5079 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5080 | ret = megasas_issue_polled(instance, cmd); |
| 5081 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5082 | if (ret == DCMD_TIMEOUT) { |
| 5083 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5084 | case INITIATE_OCR: |
| 5085 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5086 | megasas_reset_fusion(instance->host, |
| 5087 | MFI_IO_TIMEOUT_OCR); |
| 5088 | break; |
| 5089 | case KILL_ADAPTER: |
| 5090 | megaraid_sas_kill_hba(instance); |
| 5091 | break; |
| 5092 | case IGNORE_TIMEOUT: |
| 5093 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 5094 | __func__, __LINE__); |
| 5095 | break; |
| 5096 | } |
| 5097 | } else |
| 5098 | megasas_return_cmd(instance, cmd); |
| 5099 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5100 | return ret; |
| 5101 | } |
| 5102 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5103 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5104 | * megasas_issue_init_mfi - Initializes the FW |
| 5105 | * @instance: Adapter soft state |
| 5106 | * |
| 5107 | * Issues the INIT MFI cmd |
| 5108 | */ |
| 5109 | static int |
| 5110 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 5111 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 5112 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5113 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5114 | struct megasas_init_frame *init_frame; |
| 5115 | struct megasas_init_queue_info *initq_info; |
| 5116 | dma_addr_t init_frame_h; |
| 5117 | dma_addr_t initq_info_h; |
| 5118 | |
| 5119 | /* |
| 5120 | * Prepare a init frame. Note the init frame points to queue info |
| 5121 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 5122 | * this frame - since we don't need any SGL - we use SGL's space as |
| 5123 | * queue info structure |
| 5124 | * |
| 5125 | * We will not get a NULL command below. We just created the pool. |
| 5126 | */ |
| 5127 | cmd = megasas_get_cmd(instance); |
| 5128 | |
| 5129 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 5130 | initq_info = (struct megasas_init_queue_info *) |
| 5131 | ((unsigned long)init_frame + 64); |
| 5132 | |
| 5133 | init_frame_h = cmd->frame_phys_addr; |
| 5134 | initq_info_h = init_frame_h + 64; |
| 5135 | |
| 5136 | context = init_frame->context; |
| 5137 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 5138 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 5139 | init_frame->context = context; |
| 5140 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5141 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 5142 | 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] | 5143 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5144 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 5145 | 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] | 5146 | |
| 5147 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5148 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5149 | init_frame->queue_info_new_phys_addr_lo = |
| 5150 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 5151 | init_frame->queue_info_new_phys_addr_hi = |
| 5152 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5153 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5154 | 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] | 5155 | |
| 5156 | /* |
| 5157 | * disable the intr before firing the init frame to FW |
| 5158 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5159 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5160 | |
| 5161 | /* |
| 5162 | * Issue the init frame in polled mode |
| 5163 | */ |
| 5164 | |
| 5165 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5166 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5167 | megasas_return_cmd(instance, cmd); |
| 5168 | goto fail_fw_init; |
| 5169 | } |
| 5170 | |
| 5171 | megasas_return_cmd(instance, cmd); |
| 5172 | |
| 5173 | return 0; |
| 5174 | |
| 5175 | fail_fw_init: |
| 5176 | return -EINVAL; |
| 5177 | } |
| 5178 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5179 | static u32 |
| 5180 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5181 | { |
| 5182 | u32 context_sz; |
| 5183 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5184 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5185 | /* |
| 5186 | * Get various operational parameters from status register |
| 5187 | */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5188 | instance->max_fw_cmds = instance->instancet->read_fw_status_reg(instance) & 0x00FFFF; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 5189 | /* |
| 5190 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 5191 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 5192 | * does not exceed max cmds that the FW can support |
| 5193 | */ |
| 5194 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5195 | instance->max_mfi_cmds = instance->max_fw_cmds; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5196 | instance->max_num_sge = (instance->instancet->read_fw_status_reg(instance) & 0xFF0000) >> |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 5197 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5198 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 5199 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 5200 | * are reserved for IOCTL + driver's internal DCMDs. |
| 5201 | */ |
| 5202 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 5203 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 5204 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 5205 | MEGASAS_SKINNY_INT_CMDS); |
| 5206 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 5207 | } else { |
| 5208 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 5209 | MEGASAS_INT_CMDS); |
| 5210 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 5211 | } |
| 5212 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 5213 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 5214 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5215 | * Create a pool of commands |
| 5216 | */ |
| 5217 | if (megasas_alloc_cmds(instance)) |
| 5218 | goto fail_alloc_cmds; |
| 5219 | |
| 5220 | /* |
| 5221 | * Allocate memory for reply queue. Length of reply queue should |
| 5222 | * be _one_ more than the maximum commands handled by the firmware. |
| 5223 | * |
| 5224 | * Note: When FW completes commands, it places corresponding contex |
| 5225 | * values in this circular reply queue. This circular queue is a fairly |
| 5226 | * typical producer-consumer queue. FW is the producer (of completed |
| 5227 | * commands) and the driver is the consumer. |
| 5228 | */ |
| 5229 | context_sz = sizeof(u32); |
| 5230 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 5231 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5232 | instance->reply_queue = dma_alloc_coherent(&instance->pdev->dev, |
| 5233 | reply_q_sz, &instance->reply_queue_h, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5234 | |
| 5235 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5236 | 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] | 5237 | goto fail_reply_queue; |
| 5238 | } |
| 5239 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5240 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5241 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5242 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5243 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5244 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 5245 | "Fail from %s %d\n", instance->unique_id, |
| 5246 | __func__, __LINE__); |
| 5247 | goto fail_fw_init; |
| 5248 | } |
| 5249 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5250 | instance->fw_support_ieee = 0; |
| 5251 | instance->fw_support_ieee = |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5252 | (instance->instancet->read_fw_status_reg(instance) & |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5253 | 0x04000000); |
| 5254 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5255 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5256 | instance->fw_support_ieee); |
| 5257 | |
| 5258 | if (instance->fw_support_ieee) |
| 5259 | instance->flag_ieee = 1; |
| 5260 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5261 | return 0; |
| 5262 | |
| 5263 | fail_fw_init: |
| 5264 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5265 | dma_free_coherent(&instance->pdev->dev, reply_q_sz, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5266 | instance->reply_queue, instance->reply_queue_h); |
| 5267 | fail_reply_queue: |
| 5268 | megasas_free_cmds(instance); |
| 5269 | |
| 5270 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5271 | return 1; |
| 5272 | } |
| 5273 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5274 | /* |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5275 | * megasas_setup_irqs_ioapic - register legacy interrupts. |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5276 | * @instance: Adapter soft state |
| 5277 | * |
| 5278 | * Do not enable interrupt, only setup ISRs. |
| 5279 | * |
| 5280 | * Return 0 on success. |
| 5281 | */ |
| 5282 | static int |
| 5283 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 5284 | { |
| 5285 | struct pci_dev *pdev; |
| 5286 | |
| 5287 | pdev = instance->pdev; |
| 5288 | instance->irq_context[0].instance = instance; |
| 5289 | instance->irq_context[0].MSIxIndex = 0; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5290 | if (request_irq(pci_irq_vector(pdev, 0), |
| 5291 | instance->instancet->service_isr, IRQF_SHARED, |
| 5292 | "megasas", &instance->irq_context[0])) { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5293 | dev_err(&instance->pdev->dev, |
| 5294 | "Failed to register IRQ from %s %d\n", |
| 5295 | __func__, __LINE__); |
| 5296 | return -1; |
| 5297 | } |
| 5298 | return 0; |
| 5299 | } |
| 5300 | |
| 5301 | /** |
| 5302 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 5303 | * @instance: Adapter soft state |
| 5304 | * @is_probe: Driver probe check |
| 5305 | * |
| 5306 | * Do not enable interrupt, only setup ISRs. |
| 5307 | * |
| 5308 | * Return 0 on success. |
| 5309 | */ |
| 5310 | static int |
| 5311 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 5312 | { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5313 | int i, j; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5314 | struct pci_dev *pdev; |
| 5315 | |
| 5316 | pdev = instance->pdev; |
| 5317 | |
| 5318 | /* Try MSI-x */ |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5319 | for (i = 0; i < instance->msix_vectors; i++) { |
| 5320 | instance->irq_context[i].instance = instance; |
| 5321 | instance->irq_context[i].MSIxIndex = i; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5322 | if (request_irq(pci_irq_vector(pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5323 | instance->instancet->service_isr, 0, "megasas", |
| 5324 | &instance->irq_context[i])) { |
| 5325 | dev_err(&instance->pdev->dev, |
| 5326 | "Failed to register IRQ for vector %d.\n", i); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5327 | for (j = 0; j < i; j++) |
| 5328 | free_irq(pci_irq_vector(pdev, j), |
| 5329 | &instance->irq_context[j]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5330 | /* Retry irq register for IO_APIC*/ |
| 5331 | instance->msix_vectors = 0; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5332 | if (is_probe) { |
| 5333 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5334 | return megasas_setup_irqs_ioapic(instance); |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5335 | } else { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5336 | return -1; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5337 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5338 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5339 | } |
| 5340 | return 0; |
| 5341 | } |
| 5342 | |
| 5343 | /* |
| 5344 | * megasas_destroy_irqs- unregister interrupts. |
| 5345 | * @instance: Adapter soft state |
| 5346 | * return: void |
| 5347 | */ |
| 5348 | static void |
| 5349 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 5350 | |
| 5351 | int i; |
| 5352 | |
| 5353 | if (instance->msix_vectors) |
| 5354 | for (i = 0; i < instance->msix_vectors; i++) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5355 | free_irq(pci_irq_vector(instance->pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5356 | &instance->irq_context[i]); |
| 5357 | } |
| 5358 | else |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5359 | free_irq(pci_irq_vector(instance->pdev, 0), |
| 5360 | &instance->irq_context[0]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5361 | } |
| 5362 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5363 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5364 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 5365 | * @instance: Adapter soft state |
| 5366 | * @is_probe: Driver probe check |
| 5367 | * |
| 5368 | * Return 0 on success. |
| 5369 | */ |
| 5370 | void |
| 5371 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 5372 | { |
| 5373 | int i; |
| 5374 | struct fusion_context *fusion = instance->ctrl_context; |
| 5375 | u32 pd_seq_map_sz; |
| 5376 | |
| 5377 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 5378 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 5379 | |
| 5380 | if (reset_devices || !fusion || |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5381 | !instance->ctrl_info_buf->adapterOperations3.useSeqNumJbodFP) { |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5382 | dev_info(&instance->pdev->dev, |
| 5383 | "Jbod map is not supported %s %d\n", |
| 5384 | __func__, __LINE__); |
| 5385 | instance->use_seqnum_jbod_fp = false; |
| 5386 | return; |
| 5387 | } |
| 5388 | |
| 5389 | if (fusion->pd_seq_sync[0]) |
| 5390 | goto skip_alloc; |
| 5391 | |
| 5392 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 5393 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 5394 | (&instance->pdev->dev, pd_seq_map_sz, |
| 5395 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 5396 | if (!fusion->pd_seq_sync[i]) { |
| 5397 | dev_err(&instance->pdev->dev, |
| 5398 | "Failed to allocate memory from %s %d\n", |
| 5399 | __func__, __LINE__); |
| 5400 | if (i == 1) { |
| 5401 | dma_free_coherent(&instance->pdev->dev, |
| 5402 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 5403 | fusion->pd_seq_phys[0]); |
| 5404 | fusion->pd_seq_sync[0] = NULL; |
| 5405 | } |
| 5406 | instance->use_seqnum_jbod_fp = false; |
| 5407 | return; |
| 5408 | } |
| 5409 | } |
| 5410 | |
| 5411 | skip_alloc: |
| 5412 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 5413 | !megasas_sync_pd_seq_num(instance, true)) |
| 5414 | instance->use_seqnum_jbod_fp = true; |
| 5415 | else |
| 5416 | instance->use_seqnum_jbod_fp = false; |
| 5417 | } |
| 5418 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5419 | static void megasas_setup_reply_map(struct megasas_instance *instance) |
| 5420 | { |
| 5421 | const struct cpumask *mask; |
| 5422 | unsigned int queue, cpu; |
| 5423 | |
| 5424 | for (queue = 0; queue < instance->msix_vectors; queue++) { |
| 5425 | mask = pci_irq_get_affinity(instance->pdev, queue); |
| 5426 | if (!mask) |
| 5427 | goto fallback; |
| 5428 | |
| 5429 | for_each_cpu(cpu, mask) |
| 5430 | instance->reply_map[cpu] = queue; |
| 5431 | } |
| 5432 | return; |
| 5433 | |
| 5434 | fallback: |
| 5435 | for_each_possible_cpu(cpu) |
| 5436 | instance->reply_map[cpu] = cpu % instance->msix_vectors; |
| 5437 | } |
| 5438 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5439 | /** |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5440 | * megasas_get_device_list - Get the PD and LD device list from FW. |
| 5441 | * @instance: Adapter soft state |
| 5442 | * @return: Success or failure |
| 5443 | * |
| 5444 | * Issue DCMDs to Firmware to get the PD and LD list. |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5445 | * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination |
| 5446 | * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list. |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5447 | */ |
| 5448 | static |
| 5449 | int megasas_get_device_list(struct megasas_instance *instance) |
| 5450 | { |
| 5451 | memset(instance->pd_list, 0, |
| 5452 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
| 5453 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
| 5454 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5455 | if (instance->enable_fw_dev_list) { |
| 5456 | if (megasas_host_device_list_query(instance, true)) |
| 5457 | return FAILED; |
| 5458 | } else { |
| 5459 | if (megasas_get_pd_list(instance) < 0) { |
| 5460 | dev_err(&instance->pdev->dev, "failed to get PD list\n"); |
| 5461 | return FAILED; |
| 5462 | } |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5463 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5464 | if (megasas_ld_list_query(instance, |
| 5465 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) { |
| 5466 | dev_err(&instance->pdev->dev, "failed to get LD list\n"); |
| 5467 | return FAILED; |
| 5468 | } |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | return SUCCESS; |
| 5472 | } |
| 5473 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5474 | * megasas_init_fw - Initializes the FW |
| 5475 | * @instance: Adapter soft state |
| 5476 | * |
| 5477 | * This is the main function for initializing firmware |
| 5478 | */ |
| 5479 | |
| 5480 | static int megasas_init_fw(struct megasas_instance *instance) |
| 5481 | { |
| 5482 | u32 max_sectors_1; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5483 | u32 max_sectors_2, tmp_sectors, msix_enable; |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5484 | u32 scratch_pad_1, scratch_pad_2, scratch_pad_3, status_reg; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5485 | resource_size_t base_addr; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5486 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5487 | unsigned long bar_list; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5488 | int i, j, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5489 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5490 | struct fusion_context *fusion; |
| 5491 | |
| 5492 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5493 | |
| 5494 | /* Find first memory bar */ |
| 5495 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
Christophe JAILLET | 51f9039 | 2016-08-21 10:28:25 +0200 | [diff] [blame] | 5496 | instance->bar = find_first_bit(&bar_list, BITS_PER_LONG); |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5497 | if (pci_request_selected_regions(instance->pdev, 1<<instance->bar, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5498 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5499 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5500 | return -EBUSY; |
| 5501 | } |
| 5502 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5503 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 5504 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5505 | |
| 5506 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5507 | 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] | 5508 | goto fail_ioremap; |
| 5509 | } |
| 5510 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5511 | if (instance->adapter_type != MFI_SERIES) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5512 | instance->instancet = &megasas_instance_template_fusion; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5513 | else { |
| 5514 | switch (instance->pdev->device) { |
| 5515 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 5516 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 5517 | instance->instancet = &megasas_instance_template_ppc; |
| 5518 | break; |
| 5519 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 5520 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 5521 | instance->instancet = &megasas_instance_template_gen2; |
| 5522 | break; |
| 5523 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 5524 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 5525 | instance->instancet = &megasas_instance_template_skinny; |
| 5526 | break; |
| 5527 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 5528 | case PCI_DEVICE_ID_DELL_PERC5: |
| 5529 | default: |
| 5530 | instance->instancet = &megasas_instance_template_xscale; |
| 5531 | instance->pd_list_not_supported = 1; |
| 5532 | break; |
| 5533 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5534 | } |
| 5535 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5536 | if (megasas_transition_to_ready(instance, 0)) { |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame^] | 5537 | dev_info(&instance->pdev->dev, |
| 5538 | "Failed to transition controller to ready from %s!\n", |
| 5539 | __func__); |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5540 | if (instance->adapter_type != MFI_SERIES) { |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5541 | status_reg = instance->instancet->read_fw_status_reg( |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5542 | instance); |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5543 | if (status_reg & MFI_RESET_ADAPTER) { |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame^] | 5544 | if (megasas_adp_reset_wait_for_ready |
| 5545 | (instance, true, 0) == FAILED) |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5546 | goto fail_ready_state; |
| 5547 | } else { |
| 5548 | goto fail_ready_state; |
| 5549 | } |
| 5550 | } else { |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5551 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 5552 | instance->instancet->adp_reset |
| 5553 | (instance, instance->reg_set); |
| 5554 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5555 | |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5556 | /*waiting for about 30 second before retry*/ |
| 5557 | ssleep(30); |
| 5558 | |
| 5559 | if (megasas_transition_to_ready(instance, 0)) |
| 5560 | goto fail_ready_state; |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5561 | } |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame^] | 5562 | |
| 5563 | dev_info(&instance->pdev->dev, |
| 5564 | "FW restarted successfully from %s!\n", |
| 5565 | __func__); |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5566 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5567 | |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5568 | megasas_init_ctrl_params(instance); |
| 5569 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5570 | if (megasas_set_dma_mask(instance)) |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5571 | goto fail_ready_state; |
| 5572 | |
| 5573 | if (megasas_alloc_ctrl_mem(instance)) |
| 5574 | goto fail_alloc_dma_buf; |
| 5575 | |
| 5576 | if (megasas_alloc_ctrl_dma_buffers(instance)) |
| 5577 | goto fail_alloc_dma_buf; |
| 5578 | |
| 5579 | fusion = instance->ctrl_context; |
| 5580 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 5581 | if (instance->adapter_type >= VENTURA_SERIES) { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5582 | scratch_pad_2 = |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5583 | megasas_readl(instance, |
| 5584 | &instance->reg_set->outbound_scratch_pad_2); |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5585 | instance->max_raid_mapsize = ((scratch_pad_2 >> |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5586 | MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) & |
| 5587 | MR_MAX_RAID_MAP_SIZE_MASK); |
| 5588 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5589 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5590 | /* Check if MSI-X is supported while in ready state */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5591 | msix_enable = (instance->instancet->read_fw_status_reg(instance) & |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5592 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5593 | if (msix_enable && !msix_disable) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5594 | int irq_flags = PCI_IRQ_MSIX; |
| 5595 | |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5596 | scratch_pad_1 = megasas_readl |
| 5597 | (instance, &instance->reg_set->outbound_scratch_pad_1); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5598 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5599 | if (fusion) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 5600 | if (instance->adapter_type == THUNDERBOLT_SERIES) { |
| 5601 | /* Thunderbolt Series*/ |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5602 | instance->msix_vectors = (scratch_pad_1 |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5603 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 5604 | fw_msix_count = instance->msix_vectors; |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5605 | } else { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5606 | instance->msix_vectors = ((scratch_pad_1 |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5607 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 5608 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5609 | |
| 5610 | /* |
| 5611 | * For Invader series, > 8 MSI-x vectors |
| 5612 | * supported by FW/HW implies combined |
| 5613 | * reply queue mode is enabled. |
| 5614 | * For Ventura series, > 16 MSI-x vectors |
| 5615 | * supported by FW/HW implies combined |
| 5616 | * reply queue mode is enabled. |
| 5617 | */ |
| 5618 | switch (instance->adapter_type) { |
| 5619 | case INVADER_SERIES: |
| 5620 | if (instance->msix_vectors > 8) |
| 5621 | instance->msix_combined = true; |
| 5622 | break; |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 5623 | case AERO_SERIES: |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5624 | case VENTURA_SERIES: |
| 5625 | if (instance->msix_vectors > 16) |
| 5626 | instance->msix_combined = true; |
| 5627 | break; |
| 5628 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5629 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5630 | if (rdpq_enable) |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5631 | instance->is_rdpq = (scratch_pad_1 & MR_RDPQ_MODE_OFFSET) ? |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5632 | 1 : 0; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5633 | fw_msix_count = instance->msix_vectors; |
| 5634 | /* Save 1-15 reply post index address to local memory |
| 5635 | * Index 0 is already saved from reg offset |
| 5636 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 5637 | */ |
| 5638 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 5639 | instance->reply_post_host_index_addr[loop] = |
| 5640 | (u32 __iomem *) |
| 5641 | ((u8 __iomem *)instance->reg_set + |
| 5642 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 5643 | + (loop * 0x10)); |
| 5644 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5645 | } |
| 5646 | if (msix_vectors) |
| 5647 | instance->msix_vectors = min(msix_vectors, |
| 5648 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5649 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5650 | instance->msix_vectors = 1; |
| 5651 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 5652 | instance->msix_vectors = min(instance->msix_vectors, |
| 5653 | (unsigned int)num_online_cpus()); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5654 | if (smp_affinity_enable) |
| 5655 | irq_flags |= PCI_IRQ_AFFINITY; |
| 5656 | i = pci_alloc_irq_vectors(instance->pdev, 1, |
| 5657 | instance->msix_vectors, irq_flags); |
Jiang Liu | c12de88 | 2014-11-03 20:44:20 +0800 | [diff] [blame] | 5658 | if (i > 0) |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5659 | instance->msix_vectors = i; |
| 5660 | else |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5661 | instance->msix_vectors = 0; |
| 5662 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5663 | /* |
| 5664 | * MSI-X host index 0 is common for all adapter. |
| 5665 | * It is used for all MPT based Adapters. |
| 5666 | */ |
| 5667 | if (instance->msix_combined) { |
| 5668 | instance->reply_post_host_index_addr[0] = |
| 5669 | (u32 *)((u8 *)instance->reg_set + |
| 5670 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET); |
| 5671 | } else { |
| 5672 | instance->reply_post_host_index_addr[0] = |
| 5673 | (u32 *)((u8 *)instance->reg_set + |
| 5674 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 5675 | } |
| 5676 | |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5677 | if (!instance->msix_vectors) { |
| 5678 | i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 5679 | if (i < 0) |
Shivasharan S | 8a25fa1 | 2018-10-16 23:37:44 -0700 | [diff] [blame] | 5680 | goto fail_init_adapter; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5681 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5682 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5683 | megasas_setup_reply_map(instance); |
| 5684 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5685 | dev_info(&instance->pdev->dev, |
| 5686 | "firmware supports msix\t: (%d)", fw_msix_count); |
| 5687 | dev_info(&instance->pdev->dev, |
| 5688 | "current msix/online cpus\t: (%d/%d)\n", |
| 5689 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5690 | dev_info(&instance->pdev->dev, |
| 5691 | "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5692 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 5693 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5694 | (unsigned long)instance); |
| 5695 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5696 | /* |
| 5697 | * Below are default value for legacy Firmware. |
| 5698 | * non-fusion based controllers |
| 5699 | */ |
| 5700 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 5701 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5702 | /* Get operational params, sge flags, send init cmd to controller */ |
| 5703 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5704 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5705 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 5706 | if (instance->adapter_type >= VENTURA_SERIES) { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5707 | scratch_pad_3 = |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5708 | megasas_readl(instance, |
| 5709 | &instance->reg_set->outbound_scratch_pad_3); |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5710 | if ((scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK) >= |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5711 | MR_DEFAULT_NVME_PAGE_SHIFT) |
| 5712 | instance->nvme_page_size = |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5713 | (1 << (scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK)); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5714 | |
| 5715 | dev_info(&instance->pdev->dev, |
| 5716 | "NVME page size\t: (%d)\n", instance->nvme_page_size); |
| 5717 | } |
| 5718 | |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5719 | if (instance->msix_vectors ? |
| 5720 | megasas_setup_irqs_msix(instance, 1) : |
| 5721 | megasas_setup_irqs_ioapic(instance)) |
| 5722 | goto fail_init_adapter; |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5723 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5724 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5725 | |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 5726 | dev_info(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5727 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5728 | megasas_setup_jbod_map(instance); |
| 5729 | |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5730 | if (megasas_get_device_list(instance) != SUCCESS) { |
| 5731 | dev_err(&instance->pdev->dev, |
| 5732 | "%s: megasas_get_device_list failed\n", |
| 5733 | __func__); |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5734 | goto fail_get_ld_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5735 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5736 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5737 | /* stream detection initialization */ |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 5738 | if (instance->adapter_type >= VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5739 | fusion->stream_detect_by_ld = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5740 | kcalloc(MAX_LOGICAL_DRIVES_EXT, |
| 5741 | sizeof(struct LD_STREAM_DETECT *), |
| 5742 | GFP_KERNEL); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5743 | if (!fusion->stream_detect_by_ld) { |
| 5744 | dev_err(&instance->pdev->dev, |
Shivasharan S | 41064f1 | 2017-02-10 00:59:37 -0800 | [diff] [blame] | 5745 | "unable to allocate stream detection for pool of LDs\n"); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5746 | goto fail_get_ld_pd_list; |
| 5747 | } |
| 5748 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) { |
| 5749 | fusion->stream_detect_by_ld[i] = |
Shivasharan S | e05ee4e | 2018-01-05 05:27:36 -0800 | [diff] [blame] | 5750 | kzalloc(sizeof(struct LD_STREAM_DETECT), |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5751 | GFP_KERNEL); |
| 5752 | if (!fusion->stream_detect_by_ld[i]) { |
| 5753 | dev_err(&instance->pdev->dev, |
| 5754 | "unable to allocate stream detect by LD\n "); |
| 5755 | for (j = 0; j < i; ++j) |
| 5756 | kfree(fusion->stream_detect_by_ld[j]); |
| 5757 | kfree(fusion->stream_detect_by_ld); |
| 5758 | fusion->stream_detect_by_ld = NULL; |
| 5759 | goto fail_get_ld_pd_list; |
| 5760 | } |
| 5761 | fusion->stream_detect_by_ld[i]->mru_bit_map |
| 5762 | = MR_STREAM_BITMAP; |
| 5763 | } |
| 5764 | } |
| 5765 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5766 | /* |
| 5767 | * Compute the max allowed sectors per IO: The controller info has two |
| 5768 | * limits on max sectors. Driver should use the minimum of these two. |
| 5769 | * |
| 5770 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 5771 | * |
| 5772 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 5773 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 5774 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5775 | tmp_sectors = 0; |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5776 | ctrl_info = instance->ctrl_info_buf; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5777 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5778 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 5779 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 5780 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5781 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5782 | 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] | 5783 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 5784 | instance->peerIsPresent = ctrl_info->cluster.peerIsPresent; |
| 5785 | instance->passive = ctrl_info->cluster.passive; |
| 5786 | memcpy(instance->clusterId, ctrl_info->clusterId, sizeof(instance->clusterId)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5787 | instance->UnevenSpanSupport = |
| 5788 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 5789 | if (instance->UnevenSpanSupport) { |
| 5790 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 5791 | if (MR_ValidateMapInfo(instance, instance->map_id)) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5792 | fusion->fast_path_io = 1; |
| 5793 | else |
| 5794 | fusion->fast_path_io = 0; |
| 5795 | |
| 5796 | } |
| 5797 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5798 | instance->requestorId = ctrl_info->iov.requestorId; |
| 5799 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 5800 | if (!ctrl_info->adapterOperations2.activePassive) |
| 5801 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5802 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5803 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 5804 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 5805 | |
| 5806 | if (instance->PlasmaFW111) { |
| 5807 | iovPtr = (struct IOV_111 *) |
| 5808 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 5809 | instance->requestorId = iovPtr->requestorId; |
| 5810 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5811 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5812 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 5813 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5814 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5815 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5816 | instance->crash_dump_fw_support = |
| 5817 | ctrl_info->adapterOperations3.supportCrashDump; |
| 5818 | instance->crash_dump_drv_support = |
| 5819 | (instance->crash_dump_fw_support && |
| 5820 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5821 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5822 | megasas_set_crash_dump_params(instance, |
| 5823 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5824 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5825 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5826 | if (instance->crash_dump_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5827 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5828 | CRASH_DMA_BUF_SIZE, |
| 5829 | instance->crash_dump_buf, |
| 5830 | instance->crash_dump_h); |
| 5831 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5832 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 5833 | |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5834 | if (instance->snapdump_wait_time) { |
| 5835 | megasas_get_snapdump_properties(instance); |
| 5836 | dev_info(&instance->pdev->dev, "Snap dump wait time\t: %d\n", |
| 5837 | instance->snapdump_wait_time); |
| 5838 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5839 | |
| 5840 | dev_info(&instance->pdev->dev, |
| 5841 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 5842 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 5843 | le16_to_cpu(ctrl_info->pci.device_id), |
| 5844 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 5845 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 5846 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 5847 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5848 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 5849 | instance->crash_dump_drv_support ? "yes" : "no"); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5850 | dev_info(&instance->pdev->dev, "jbod sync map : %s\n", |
| 5851 | instance->use_seqnum_jbod_fp ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5852 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5853 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 5854 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5855 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 5856 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5857 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 5858 | /* Check for valid throttlequeuedepth module parameter */ |
| 5859 | if (throttlequeuedepth && |
| 5860 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 5861 | instance->throttlequeuedepth = throttlequeuedepth; |
| 5862 | else |
| 5863 | instance->throttlequeuedepth = |
| 5864 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 5865 | |
Shivasharan S | e636a7a | 2017-08-23 04:46:56 -0700 | [diff] [blame] | 5866 | if ((resetwaittime < 1) || |
| 5867 | (resetwaittime > MEGASAS_RESET_WAIT_TIME)) |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 5868 | resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 5869 | |
| 5870 | if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT)) |
| 5871 | scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5872 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5873 | /* Launch SR-IOV heartbeat timer */ |
| 5874 | if (instance->requestorId) { |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 5875 | if (!megasas_sriov_start_heartbeat(instance, 1)) { |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 5876 | megasas_start_timer(instance); |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 5877 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5878 | instance->skip_heartbeat_timer_del = 1; |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 5879 | goto fail_get_ld_pd_list; |
| 5880 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5881 | } |
| 5882 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 5883 | /* |
| 5884 | * Create and start watchdog thread which will monitor |
| 5885 | * controller state every 1 sec and trigger OCR when |
| 5886 | * it enters fault state |
| 5887 | */ |
| 5888 | if (instance->adapter_type != MFI_SERIES) |
| 5889 | if (megasas_fusion_start_watchdog(instance) != SUCCESS) |
| 5890 | goto fail_start_watchdog; |
| 5891 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5892 | return 0; |
| 5893 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 5894 | fail_start_watchdog: |
| 5895 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 5896 | del_timer_sync(&instance->sriov_heartbeat_timer); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5897 | fail_get_ld_pd_list: |
| 5898 | instance->instancet->disable_intr(instance); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5899 | megasas_destroy_irqs(instance); |
Shivasharan S | 8a25fa1 | 2018-10-16 23:37:44 -0700 | [diff] [blame] | 5900 | fail_init_adapter: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5901 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5902 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5903 | instance->msix_vectors = 0; |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5904 | fail_alloc_dma_buf: |
| 5905 | megasas_free_ctrl_dma_buffers(instance); |
| 5906 | megasas_free_ctrl_mem(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5907 | fail_ready_state: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5908 | iounmap(instance->reg_set); |
| 5909 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5910 | fail_ioremap: |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5911 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5912 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5913 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 5914 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5915 | return -EINVAL; |
| 5916 | } |
| 5917 | |
| 5918 | /** |
| 5919 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 5920 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5921 | */ |
| 5922 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 5923 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5924 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5925 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5926 | if (instance->reply_queue) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5927 | dma_free_coherent(&instance->pdev->dev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5928 | instance->reply_queue, instance->reply_queue_h); |
| 5929 | |
| 5930 | megasas_free_cmds(instance); |
| 5931 | |
| 5932 | iounmap(instance->reg_set); |
| 5933 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5934 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | /** |
| 5938 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 5939 | * @instance: Adapter soft state |
| 5940 | * @eli: FW event log sequence numbers information |
| 5941 | * |
| 5942 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 5943 | * usually find out the latest sequence number of the events, the seq number at |
| 5944 | * the boot etc. They would "read" all the events below the latest seq number |
| 5945 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 5946 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 5947 | * wait for the events to happen. |
| 5948 | */ |
| 5949 | static int |
| 5950 | megasas_get_seq_num(struct megasas_instance *instance, |
| 5951 | struct megasas_evt_log_info *eli) |
| 5952 | { |
| 5953 | struct megasas_cmd *cmd; |
| 5954 | struct megasas_dcmd_frame *dcmd; |
| 5955 | struct megasas_evt_log_info *el_info; |
| 5956 | dma_addr_t el_info_h = 0; |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 5957 | int ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5958 | |
| 5959 | cmd = megasas_get_cmd(instance); |
| 5960 | |
| 5961 | if (!cmd) { |
| 5962 | return -ENOMEM; |
| 5963 | } |
| 5964 | |
| 5965 | dcmd = &cmd->frame->dcmd; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 5966 | el_info = dma_alloc_coherent(&instance->pdev->dev, |
| 5967 | sizeof(struct megasas_evt_log_info), |
| 5968 | &el_info_h, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5969 | if (!el_info) { |
| 5970 | megasas_return_cmd(instance, cmd); |
| 5971 | return -ENOMEM; |
| 5972 | } |
| 5973 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5974 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5975 | |
| 5976 | dcmd->cmd = MFI_CMD_DCMD; |
| 5977 | dcmd->cmd_status = 0x0; |
| 5978 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5979 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5980 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5981 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5982 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 5983 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5984 | |
| 5985 | megasas_set_dma_settings(instance, dcmd, el_info_h, |
| 5986 | sizeof(struct megasas_evt_log_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5987 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 5988 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 5989 | if (ret != DCMD_SUCCESS) { |
| 5990 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 5991 | __func__, __LINE__); |
| 5992 | goto dcmd_failed; |
| 5993 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5994 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 5995 | /* |
| 5996 | * Copy the data back into callers buffer |
| 5997 | */ |
| 5998 | eli->newest_seq_num = el_info->newest_seq_num; |
| 5999 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 6000 | eli->clear_seq_num = el_info->clear_seq_num; |
| 6001 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 6002 | eli->boot_seq_num = el_info->boot_seq_num; |
| 6003 | |
| 6004 | dcmd_failed: |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6005 | dma_free_coherent(&instance->pdev->dev, |
| 6006 | sizeof(struct megasas_evt_log_info), |
| 6007 | el_info, el_info_h); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6008 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6009 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6010 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6011 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | /** |
| 6015 | * megasas_register_aen - Registers for asynchronous event notification |
| 6016 | * @instance: Adapter soft state |
| 6017 | * @seq_num: The starting sequence number |
| 6018 | * @class_locale: Class of the event |
| 6019 | * |
| 6020 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 6021 | * to be notified if and only if the event is of type @class_locale |
| 6022 | */ |
| 6023 | static int |
| 6024 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 6025 | u32 class_locale_word) |
| 6026 | { |
| 6027 | int ret_val; |
| 6028 | struct megasas_cmd *cmd; |
| 6029 | struct megasas_dcmd_frame *dcmd; |
| 6030 | union megasas_evt_class_locale curr_aen; |
| 6031 | union megasas_evt_class_locale prev_aen; |
| 6032 | |
| 6033 | /* |
| 6034 | * If there an AEN pending already (aen_cmd), check if the |
| 6035 | * class_locale of that pending AEN is inclusive of the new |
| 6036 | * AEN request we currently have. If it is, then we don't have |
| 6037 | * to do anything. In other words, whichever events the current |
| 6038 | * AEN request is subscribing to, have already been subscribed |
| 6039 | * to. |
| 6040 | * |
| 6041 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 6042 | * that command, form a class_locale that is superset of both |
| 6043 | * old and current and re-issue to the FW |
| 6044 | */ |
| 6045 | |
| 6046 | curr_aen.word = class_locale_word; |
| 6047 | |
| 6048 | if (instance->aen_cmd) { |
| 6049 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 6050 | prev_aen.word = |
| 6051 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6052 | |
Shivasharan S | 91b3d9f | 2017-08-23 04:47:01 -0700 | [diff] [blame] | 6053 | if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) || |
| 6054 | (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) { |
| 6055 | dev_info(&instance->pdev->dev, |
| 6056 | "%s %d out of range class %d send by application\n", |
| 6057 | __func__, __LINE__, curr_aen.members.class); |
| 6058 | return 0; |
| 6059 | } |
| 6060 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6061 | /* |
| 6062 | * A class whose enum value is smaller is inclusive of all |
| 6063 | * higher values. If a PROGRESS (= -1) was previously |
| 6064 | * registered, then a new registration requests for higher |
| 6065 | * classes need not be sent to FW. They are automatically |
| 6066 | * included. |
| 6067 | * |
| 6068 | * Locale numbers don't have such hierarchy. They are bitmap |
| 6069 | * values |
| 6070 | */ |
| 6071 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 6072 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6073 | curr_aen.members.locale)) { |
| 6074 | /* |
| 6075 | * Previously issued event registration includes |
| 6076 | * current request. Nothing to do. |
| 6077 | */ |
| 6078 | return 0; |
| 6079 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 6080 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6081 | |
| 6082 | if (prev_aen.members.class < curr_aen.members.class) |
| 6083 | curr_aen.members.class = prev_aen.members.class; |
| 6084 | |
| 6085 | instance->aen_cmd->abort_aen = 1; |
| 6086 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 6087 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6088 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6089 | |
| 6090 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6091 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6092 | "previous AEN command\n"); |
| 6093 | return ret_val; |
| 6094 | } |
| 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | cmd = megasas_get_cmd(instance); |
| 6099 | |
| 6100 | if (!cmd) |
| 6101 | return -ENOMEM; |
| 6102 | |
| 6103 | dcmd = &cmd->frame->dcmd; |
| 6104 | |
| 6105 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 6106 | |
| 6107 | /* |
| 6108 | * Prepare DCMD for aen registration |
| 6109 | */ |
| 6110 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6111 | |
| 6112 | dcmd->cmd = MFI_CMD_DCMD; |
| 6113 | dcmd->cmd_status = 0x0; |
| 6114 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6115 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6116 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6117 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6118 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 6119 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 6120 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6121 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6122 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6123 | |
| 6124 | megasas_set_dma_settings(instance, dcmd, instance->evt_detail_h, |
| 6125 | sizeof(struct megasas_evt_detail)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6126 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 6127 | if (instance->aen_cmd != NULL) { |
| 6128 | megasas_return_cmd(instance, cmd); |
| 6129 | return 0; |
| 6130 | } |
| 6131 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6132 | /* |
| 6133 | * Store reference to the cmd used to register for AEN. When an |
| 6134 | * application wants us to register for AEN, we have to abort this |
| 6135 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 6136 | */ |
| 6137 | instance->aen_cmd = cmd; |
| 6138 | |
| 6139 | /* |
| 6140 | * Issue the aen registration frame |
| 6141 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6142 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6143 | |
| 6144 | return 0; |
| 6145 | } |
| 6146 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6147 | /* megasas_get_target_prop - Send DCMD with below details to firmware. |
| 6148 | * |
| 6149 | * This DCMD will fetch few properties of LD/system PD defined |
| 6150 | * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value. |
| 6151 | * |
| 6152 | * DCMD send by drivers whenever new target is added to the OS. |
| 6153 | * |
| 6154 | * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP |
| 6155 | * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD. |
| 6156 | * 0 = system PD, 1 = LD. |
| 6157 | * dcmd.mbox.s[1] - TargetID for LD/system PD. |
| 6158 | * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES. |
| 6159 | * |
| 6160 | * @instance: Adapter soft state |
| 6161 | * @sdev: OS provided scsi device |
| 6162 | * |
| 6163 | * Returns 0 on success non-zero on failure. |
| 6164 | */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 6165 | int |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6166 | megasas_get_target_prop(struct megasas_instance *instance, |
| 6167 | struct scsi_device *sdev) |
| 6168 | { |
| 6169 | int ret; |
| 6170 | struct megasas_cmd *cmd; |
| 6171 | struct megasas_dcmd_frame *dcmd; |
| 6172 | u16 targetId = (sdev->channel % 2) + sdev->id; |
| 6173 | |
| 6174 | cmd = megasas_get_cmd(instance); |
| 6175 | |
| 6176 | if (!cmd) { |
| 6177 | dev_err(&instance->pdev->dev, |
| 6178 | "Failed to get cmd %s\n", __func__); |
| 6179 | return -ENOMEM; |
| 6180 | } |
| 6181 | |
| 6182 | dcmd = &cmd->frame->dcmd; |
| 6183 | |
| 6184 | memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop)); |
| 6185 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6186 | dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev); |
| 6187 | |
| 6188 | dcmd->mbox.s[1] = cpu_to_le16(targetId); |
| 6189 | dcmd->cmd = MFI_CMD_DCMD; |
| 6190 | dcmd->cmd_status = 0xFF; |
| 6191 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6192 | dcmd->flags = MFI_FRAME_DIR_READ; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6193 | dcmd->timeout = 0; |
| 6194 | dcmd->pad_0 = 0; |
| 6195 | dcmd->data_xfer_len = |
| 6196 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 6197 | dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6198 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6199 | megasas_set_dma_settings(instance, dcmd, instance->tgt_prop_h, |
| 6200 | sizeof(struct MR_TARGET_PROPERTIES)); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6201 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6202 | if ((instance->adapter_type != MFI_SERIES) && |
| 6203 | !instance->mask_interrupts) |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6204 | ret = megasas_issue_blocked_cmd(instance, |
| 6205 | cmd, MFI_IO_TIMEOUT_SECS); |
| 6206 | else |
| 6207 | ret = megasas_issue_polled(instance, cmd); |
| 6208 | |
| 6209 | switch (ret) { |
| 6210 | case DCMD_TIMEOUT: |
| 6211 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 6212 | case INITIATE_OCR: |
| 6213 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 6214 | megasas_reset_fusion(instance->host, |
| 6215 | MFI_IO_TIMEOUT_OCR); |
| 6216 | break; |
| 6217 | case KILL_ADAPTER: |
| 6218 | megaraid_sas_kill_hba(instance); |
| 6219 | break; |
| 6220 | case IGNORE_TIMEOUT: |
| 6221 | dev_info(&instance->pdev->dev, |
| 6222 | "Ignore DCMD timeout: %s %d\n", |
| 6223 | __func__, __LINE__); |
| 6224 | break; |
| 6225 | } |
| 6226 | break; |
| 6227 | |
| 6228 | default: |
| 6229 | megasas_return_cmd(instance, cmd); |
| 6230 | } |
| 6231 | if (ret != DCMD_SUCCESS) |
| 6232 | dev_err(&instance->pdev->dev, |
| 6233 | "return from %s %d return value %d\n", |
| 6234 | __func__, __LINE__, ret); |
| 6235 | |
| 6236 | return ret; |
| 6237 | } |
| 6238 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6239 | /** |
| 6240 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 6241 | * @instance: Adapter soft state |
| 6242 | */ |
| 6243 | static int megasas_start_aen(struct megasas_instance *instance) |
| 6244 | { |
| 6245 | struct megasas_evt_log_info eli; |
| 6246 | union megasas_evt_class_locale class_locale; |
| 6247 | |
| 6248 | /* |
| 6249 | * Get the latest sequence number from FW |
| 6250 | */ |
| 6251 | memset(&eli, 0, sizeof(eli)); |
| 6252 | |
| 6253 | if (megasas_get_seq_num(instance, &eli)) |
| 6254 | return -1; |
| 6255 | |
| 6256 | /* |
| 6257 | * Register AEN with FW for latest sequence number plus 1 |
| 6258 | */ |
| 6259 | class_locale.members.reserved = 0; |
| 6260 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 6261 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 6262 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6263 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 6264 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6265 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6266 | } |
| 6267 | |
| 6268 | /** |
| 6269 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 6270 | * @instance: Adapter soft state |
| 6271 | */ |
| 6272 | static int megasas_io_attach(struct megasas_instance *instance) |
| 6273 | { |
| 6274 | struct Scsi_Host *host = instance->host; |
| 6275 | |
| 6276 | /* |
| 6277 | * Export parameters required by SCSI mid-layer |
| 6278 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6279 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6280 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6281 | host->this_id = instance->init_id; |
| 6282 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 6283 | |
| 6284 | if (instance->fw_support_ieee) |
| 6285 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 6286 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 6287 | /* |
| 6288 | * Check if the module parameter value for max_sectors can be used |
| 6289 | */ |
| 6290 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 6291 | instance->max_sectors_per_req = max_sectors; |
| 6292 | else { |
| 6293 | if (max_sectors) { |
| 6294 | if (((instance->pdev->device == |
| 6295 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 6296 | (instance->pdev->device == |
| 6297 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 6298 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 6299 | instance->max_sectors_per_req = max_sectors; |
| 6300 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6301 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 6302 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 6303 | instance->max_sectors_per_req); |
| 6304 | } |
| 6305 | } |
| 6306 | } |
| 6307 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6308 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6309 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6310 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 6311 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6312 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 6313 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6314 | |
| 6315 | /* |
| 6316 | * Notify the mid-layer about the new controller |
| 6317 | */ |
| 6318 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6319 | dev_err(&instance->pdev->dev, |
| 6320 | "Failed to add host from %s %d\n", |
| 6321 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6322 | return -ENODEV; |
| 6323 | } |
| 6324 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6325 | return 0; |
| 6326 | } |
| 6327 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6328 | /** |
| 6329 | * megasas_set_dma_mask - Set DMA mask for supported controllers |
| 6330 | * |
| 6331 | * @instance: Adapter soft state |
| 6332 | * Description: |
| 6333 | * |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6334 | * For Ventura, driver/FW will operate in 63bit DMA addresses. |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6335 | * |
| 6336 | * For invader- |
| 6337 | * By default, driver/FW will operate in 32bit DMA addresses |
| 6338 | * for consistent DMA mapping but if 32 bit consistent |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6339 | * DMA mask fails, driver will try with 63 bit consistent |
| 6340 | * mask provided FW is true 63bit DMA capable |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6341 | * |
| 6342 | * For older controllers(Thunderbolt and MFI based adapters)- |
| 6343 | * driver/FW will operate in 32 bit consistent DMA addresses. |
| 6344 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6345 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6346 | megasas_set_dma_mask(struct megasas_instance *instance) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6347 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6348 | u64 consistent_mask; |
| 6349 | struct pci_dev *pdev; |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6350 | u32 scratch_pad_1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6351 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6352 | pdev = instance->pdev; |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 6353 | consistent_mask = (instance->adapter_type >= VENTURA_SERIES) ? |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6354 | DMA_BIT_MASK(63) : DMA_BIT_MASK(32); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6355 | |
| 6356 | if (IS_DMA64) { |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6357 | if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(63)) && |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6358 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6359 | goto fail_set_dma_mask; |
| 6360 | |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6361 | if ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) && |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6362 | (dma_set_coherent_mask(&pdev->dev, consistent_mask) && |
| 6363 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))) { |
| 6364 | /* |
| 6365 | * If 32 bit DMA mask fails, then try for 64 bit mask |
| 6366 | * for FW capable of handling 64 bit DMA. |
| 6367 | */ |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 6368 | scratch_pad_1 = megasas_readl |
| 6369 | (instance, &instance->reg_set->outbound_scratch_pad_1); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6370 | |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6371 | if (!(scratch_pad_1 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET)) |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6372 | goto fail_set_dma_mask; |
| 6373 | else if (dma_set_mask_and_coherent(&pdev->dev, |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6374 | DMA_BIT_MASK(63))) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6375 | goto fail_set_dma_mask; |
| 6376 | } |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6377 | } else if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6378 | goto fail_set_dma_mask; |
| 6379 | |
| 6380 | if (pdev->dev.coherent_dma_mask == DMA_BIT_MASK(32)) |
| 6381 | instance->consistent_mask_64bit = false; |
| 6382 | else |
| 6383 | instance->consistent_mask_64bit = true; |
| 6384 | |
| 6385 | dev_info(&pdev->dev, "%s bit DMA mask and %s bit consistent mask\n", |
Tomas Henzl | d1f38d9 | 2019-01-02 16:07:25 +0100 | [diff] [blame] | 6386 | ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) ? "63" : "32"), |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6387 | (instance->consistent_mask_64bit ? "63" : "32")); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6388 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6389 | return 0; |
| 6390 | |
| 6391 | fail_set_dma_mask: |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6392 | dev_err(&pdev->dev, "Failed to set DMA mask\n"); |
| 6393 | return -1; |
| 6394 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6395 | } |
| 6396 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6397 | /* |
| 6398 | * megasas_set_adapter_type - Set adapter type. |
| 6399 | * Supported controllers can be divided in |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6400 | * different categories- |
| 6401 | * enum MR_ADAPTER_TYPE { |
| 6402 | * MFI_SERIES = 1, |
| 6403 | * THUNDERBOLT_SERIES = 2, |
| 6404 | * INVADER_SERIES = 3, |
| 6405 | * VENTURA_SERIES = 4, |
| 6406 | * AERO_SERIES = 5, |
| 6407 | * }; |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6408 | * @instance: Adapter soft state |
| 6409 | * return: void |
| 6410 | */ |
| 6411 | static inline void megasas_set_adapter_type(struct megasas_instance *instance) |
| 6412 | { |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6413 | if ((instance->pdev->vendor == PCI_VENDOR_ID_DELL) && |
| 6414 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5)) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6415 | instance->adapter_type = MFI_SERIES; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6416 | } else { |
| 6417 | switch (instance->pdev->device) { |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 6418 | case PCI_DEVICE_ID_LSI_AERO_10E1: |
| 6419 | case PCI_DEVICE_ID_LSI_AERO_10E2: |
| 6420 | case PCI_DEVICE_ID_LSI_AERO_10E5: |
| 6421 | case PCI_DEVICE_ID_LSI_AERO_10E6: |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6422 | instance->adapter_type = AERO_SERIES; |
| 6423 | break; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6424 | case PCI_DEVICE_ID_LSI_VENTURA: |
| 6425 | case PCI_DEVICE_ID_LSI_CRUSADER: |
| 6426 | case PCI_DEVICE_ID_LSI_HARPOON: |
| 6427 | case PCI_DEVICE_ID_LSI_TOMCAT: |
| 6428 | case PCI_DEVICE_ID_LSI_VENTURA_4PORT: |
| 6429 | case PCI_DEVICE_ID_LSI_CRUSADER_4PORT: |
| 6430 | instance->adapter_type = VENTURA_SERIES; |
| 6431 | break; |
| 6432 | case PCI_DEVICE_ID_LSI_FUSION: |
| 6433 | case PCI_DEVICE_ID_LSI_PLASMA: |
| 6434 | instance->adapter_type = THUNDERBOLT_SERIES; |
| 6435 | break; |
| 6436 | case PCI_DEVICE_ID_LSI_INVADER: |
| 6437 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 6438 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
| 6439 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 6440 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
| 6441 | case PCI_DEVICE_ID_LSI_FURY: |
| 6442 | instance->adapter_type = INVADER_SERIES; |
| 6443 | break; |
| 6444 | default: /* For all other supported controllers */ |
| 6445 | instance->adapter_type = MFI_SERIES; |
| 6446 | break; |
| 6447 | } |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6448 | } |
| 6449 | } |
| 6450 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6451 | static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance) |
| 6452 | { |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6453 | instance->producer = dma_alloc_coherent(&instance->pdev->dev, |
| 6454 | sizeof(u32), &instance->producer_h, GFP_KERNEL); |
| 6455 | instance->consumer = dma_alloc_coherent(&instance->pdev->dev, |
| 6456 | sizeof(u32), &instance->consumer_h, GFP_KERNEL); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6457 | |
| 6458 | if (!instance->producer || !instance->consumer) { |
| 6459 | dev_err(&instance->pdev->dev, |
| 6460 | "Failed to allocate memory for producer, consumer\n"); |
| 6461 | return -1; |
| 6462 | } |
| 6463 | |
| 6464 | *instance->producer = 0; |
| 6465 | *instance->consumer = 0; |
| 6466 | return 0; |
| 6467 | } |
| 6468 | |
| 6469 | /** |
| 6470 | * megasas_alloc_ctrl_mem - Allocate per controller memory for core data |
| 6471 | * structures which are not common across MFI |
| 6472 | * adapters and fusion adapters. |
| 6473 | * For MFI based adapters, allocate producer and |
| 6474 | * consumer buffers. For fusion adapters, allocate |
| 6475 | * memory for fusion context. |
| 6476 | * @instance: Adapter soft state |
| 6477 | * return: 0 for SUCCESS |
| 6478 | */ |
| 6479 | static int megasas_alloc_ctrl_mem(struct megasas_instance *instance) |
| 6480 | { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6481 | instance->reply_map = kcalloc(nr_cpu_ids, sizeof(unsigned int), |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6482 | GFP_KERNEL); |
| 6483 | if (!instance->reply_map) |
| 6484 | return -ENOMEM; |
| 6485 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6486 | switch (instance->adapter_type) { |
| 6487 | case MFI_SERIES: |
| 6488 | if (megasas_alloc_mfi_ctrl_mem(instance)) |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6489 | goto fail; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6490 | break; |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6491 | case AERO_SERIES: |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6492 | case VENTURA_SERIES: |
| 6493 | case THUNDERBOLT_SERIES: |
| 6494 | case INVADER_SERIES: |
| 6495 | if (megasas_alloc_fusion_context(instance)) |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6496 | goto fail; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6497 | break; |
| 6498 | } |
| 6499 | |
| 6500 | return 0; |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6501 | fail: |
| 6502 | kfree(instance->reply_map); |
| 6503 | instance->reply_map = NULL; |
| 6504 | return -ENOMEM; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6505 | } |
| 6506 | |
| 6507 | /* |
| 6508 | * megasas_free_ctrl_mem - Free fusion context for fusion adapters and |
| 6509 | * producer, consumer buffers for MFI adapters |
| 6510 | * |
| 6511 | * @instance - Adapter soft instance |
| 6512 | * |
| 6513 | */ |
| 6514 | static inline void megasas_free_ctrl_mem(struct megasas_instance *instance) |
| 6515 | { |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6516 | kfree(instance->reply_map); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6517 | if (instance->adapter_type == MFI_SERIES) { |
| 6518 | if (instance->producer) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6519 | dma_free_coherent(&instance->pdev->dev, sizeof(u32), |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6520 | instance->producer, |
| 6521 | instance->producer_h); |
| 6522 | if (instance->consumer) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6523 | dma_free_coherent(&instance->pdev->dev, sizeof(u32), |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6524 | instance->consumer, |
| 6525 | instance->consumer_h); |
| 6526 | } else { |
| 6527 | megasas_free_fusion_context(instance); |
| 6528 | } |
| 6529 | } |
| 6530 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6531 | /** |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6532 | * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during |
| 6533 | * driver load time |
| 6534 | * |
| 6535 | * @instance- Adapter soft instance |
| 6536 | * @return- O for SUCCESS |
| 6537 | */ |
| 6538 | static inline |
| 6539 | int megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance) |
| 6540 | { |
| 6541 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6542 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6543 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6544 | instance->evt_detail = dma_alloc_coherent(&pdev->dev, |
| 6545 | sizeof(struct megasas_evt_detail), |
| 6546 | &instance->evt_detail_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6547 | |
| 6548 | if (!instance->evt_detail) { |
| 6549 | dev_err(&instance->pdev->dev, |
| 6550 | "Failed to allocate event detail buffer\n"); |
| 6551 | return -ENOMEM; |
| 6552 | } |
| 6553 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6554 | if (fusion) { |
| 6555 | fusion->ioc_init_request = |
| 6556 | dma_alloc_coherent(&pdev->dev, |
| 6557 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 6558 | &fusion->ioc_init_request_phys, |
| 6559 | GFP_KERNEL); |
| 6560 | |
| 6561 | if (!fusion->ioc_init_request) { |
| 6562 | dev_err(&pdev->dev, |
| 6563 | "Failed to allocate PD list buffer\n"); |
| 6564 | return -ENOMEM; |
| 6565 | } |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 6566 | |
| 6567 | instance->snapdump_prop = dma_alloc_coherent(&pdev->dev, |
| 6568 | sizeof(struct MR_SNAPDUMP_PROPERTIES), |
| 6569 | &instance->snapdump_prop_h, GFP_KERNEL); |
| 6570 | |
| 6571 | if (!instance->snapdump_prop) |
| 6572 | dev_err(&pdev->dev, |
| 6573 | "Failed to allocate snapdump properties buffer\n"); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 6574 | |
| 6575 | instance->host_device_list_buf = dma_alloc_coherent(&pdev->dev, |
| 6576 | HOST_DEVICE_LIST_SZ, |
| 6577 | &instance->host_device_list_buf_h, |
| 6578 | GFP_KERNEL); |
| 6579 | |
| 6580 | if (!instance->host_device_list_buf) { |
| 6581 | dev_err(&pdev->dev, |
| 6582 | "Failed to allocate targetid list buffer\n"); |
| 6583 | return -ENOMEM; |
| 6584 | } |
| 6585 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | instance->pd_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6589 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6590 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6591 | &instance->pd_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6592 | |
| 6593 | if (!instance->pd_list_buf) { |
| 6594 | dev_err(&pdev->dev, "Failed to allocate PD list buffer\n"); |
| 6595 | return -ENOMEM; |
| 6596 | } |
| 6597 | |
| 6598 | instance->ctrl_info_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6599 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6600 | sizeof(struct megasas_ctrl_info), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6601 | &instance->ctrl_info_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6602 | |
| 6603 | if (!instance->ctrl_info_buf) { |
| 6604 | dev_err(&pdev->dev, |
| 6605 | "Failed to allocate controller info buffer\n"); |
| 6606 | return -ENOMEM; |
| 6607 | } |
| 6608 | |
| 6609 | instance->ld_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6610 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6611 | sizeof(struct MR_LD_LIST), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6612 | &instance->ld_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6613 | |
| 6614 | if (!instance->ld_list_buf) { |
| 6615 | dev_err(&pdev->dev, "Failed to allocate LD list buffer\n"); |
| 6616 | return -ENOMEM; |
| 6617 | } |
| 6618 | |
| 6619 | instance->ld_targetid_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6620 | dma_alloc_coherent(&pdev->dev, |
| 6621 | sizeof(struct MR_LD_TARGETID_LIST), |
| 6622 | &instance->ld_targetid_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6623 | |
| 6624 | if (!instance->ld_targetid_list_buf) { |
| 6625 | dev_err(&pdev->dev, |
| 6626 | "Failed to allocate LD targetid list buffer\n"); |
| 6627 | return -ENOMEM; |
| 6628 | } |
| 6629 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6630 | if (!reset_devices) { |
| 6631 | instance->system_info_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6632 | dma_alloc_coherent(&pdev->dev, |
| 6633 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6634 | &instance->system_info_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6635 | instance->pd_info = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6636 | dma_alloc_coherent(&pdev->dev, |
| 6637 | sizeof(struct MR_PD_INFO), |
| 6638 | &instance->pd_info_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6639 | instance->tgt_prop = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6640 | dma_alloc_coherent(&pdev->dev, |
| 6641 | sizeof(struct MR_TARGET_PROPERTIES), |
| 6642 | &instance->tgt_prop_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6643 | instance->crash_dump_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6644 | dma_alloc_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE, |
| 6645 | &instance->crash_dump_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6646 | |
| 6647 | if (!instance->system_info_buf) |
| 6648 | dev_err(&instance->pdev->dev, |
| 6649 | "Failed to allocate system info buffer\n"); |
| 6650 | |
| 6651 | if (!instance->pd_info) |
| 6652 | dev_err(&instance->pdev->dev, |
| 6653 | "Failed to allocate pd_info buffer\n"); |
| 6654 | |
| 6655 | if (!instance->tgt_prop) |
| 6656 | dev_err(&instance->pdev->dev, |
| 6657 | "Failed to allocate tgt_prop buffer\n"); |
| 6658 | |
| 6659 | if (!instance->crash_dump_buf) |
| 6660 | dev_err(&instance->pdev->dev, |
| 6661 | "Failed to allocate crash dump buffer\n"); |
| 6662 | } |
| 6663 | |
| 6664 | return 0; |
| 6665 | } |
| 6666 | |
| 6667 | /* |
| 6668 | * megasas_free_ctrl_dma_buffers - Free consistent DMA buffers allocated |
| 6669 | * during driver load time |
| 6670 | * |
| 6671 | * @instance- Adapter soft instance |
| 6672 | * |
| 6673 | */ |
| 6674 | static inline |
| 6675 | void megasas_free_ctrl_dma_buffers(struct megasas_instance *instance) |
| 6676 | { |
| 6677 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6678 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6679 | |
| 6680 | if (instance->evt_detail) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6681 | dma_free_coherent(&pdev->dev, sizeof(struct megasas_evt_detail), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6682 | instance->evt_detail, |
| 6683 | instance->evt_detail_h); |
| 6684 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6685 | if (fusion && fusion->ioc_init_request) |
| 6686 | dma_free_coherent(&pdev->dev, |
| 6687 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 6688 | fusion->ioc_init_request, |
| 6689 | fusion->ioc_init_request_phys); |
| 6690 | |
| 6691 | if (instance->pd_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6692 | dma_free_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6693 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 6694 | instance->pd_list_buf, |
| 6695 | instance->pd_list_buf_h); |
| 6696 | |
| 6697 | if (instance->ld_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6698 | dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_LIST), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6699 | instance->ld_list_buf, |
| 6700 | instance->ld_list_buf_h); |
| 6701 | |
| 6702 | if (instance->ld_targetid_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6703 | dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_TARGETID_LIST), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6704 | instance->ld_targetid_list_buf, |
| 6705 | instance->ld_targetid_list_buf_h); |
| 6706 | |
| 6707 | if (instance->ctrl_info_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6708 | dma_free_coherent(&pdev->dev, sizeof(struct megasas_ctrl_info), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6709 | instance->ctrl_info_buf, |
| 6710 | instance->ctrl_info_buf_h); |
| 6711 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6712 | if (instance->system_info_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6713 | dma_free_coherent(&pdev->dev, sizeof(struct MR_DRV_SYSTEM_INFO), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6714 | instance->system_info_buf, |
| 6715 | instance->system_info_h); |
| 6716 | |
| 6717 | if (instance->pd_info) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6718 | dma_free_coherent(&pdev->dev, sizeof(struct MR_PD_INFO), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6719 | instance->pd_info, instance->pd_info_h); |
| 6720 | |
| 6721 | if (instance->tgt_prop) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6722 | dma_free_coherent(&pdev->dev, sizeof(struct MR_TARGET_PROPERTIES), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6723 | instance->tgt_prop, instance->tgt_prop_h); |
| 6724 | |
| 6725 | if (instance->crash_dump_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6726 | dma_free_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE, |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6727 | instance->crash_dump_buf, |
| 6728 | instance->crash_dump_h); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 6729 | |
| 6730 | if (instance->snapdump_prop) |
| 6731 | dma_free_coherent(&pdev->dev, |
| 6732 | sizeof(struct MR_SNAPDUMP_PROPERTIES), |
| 6733 | instance->snapdump_prop, |
| 6734 | instance->snapdump_prop_h); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 6735 | |
| 6736 | if (instance->host_device_list_buf) |
| 6737 | dma_free_coherent(&pdev->dev, |
| 6738 | HOST_DEVICE_LIST_SZ, |
| 6739 | instance->host_device_list_buf, |
| 6740 | instance->host_device_list_buf_h); |
| 6741 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6742 | } |
| 6743 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6744 | /* |
| 6745 | * megasas_init_ctrl_params - Initialize controller's instance |
| 6746 | * parameters before FW init |
| 6747 | * @instance - Adapter soft instance |
| 6748 | * @return - void |
| 6749 | */ |
| 6750 | static inline void megasas_init_ctrl_params(struct megasas_instance *instance) |
| 6751 | { |
| 6752 | instance->fw_crash_state = UNAVAILABLE; |
| 6753 | |
| 6754 | megasas_poll_wait_aen = 0; |
| 6755 | instance->issuepend_done = 1; |
| 6756 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
| 6757 | |
| 6758 | /* |
| 6759 | * Initialize locks and queues |
| 6760 | */ |
| 6761 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 6762 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
| 6763 | |
| 6764 | atomic_set(&instance->fw_outstanding, 0); |
| 6765 | |
| 6766 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 6767 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 6768 | |
| 6769 | spin_lock_init(&instance->crashdump_lock); |
| 6770 | spin_lock_init(&instance->mfi_pool_lock); |
| 6771 | spin_lock_init(&instance->hba_lock); |
| 6772 | spin_lock_init(&instance->stream_lock); |
| 6773 | spin_lock_init(&instance->completion_lock); |
| 6774 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6775 | mutex_init(&instance->reset_mutex); |
| 6776 | |
| 6777 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 6778 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
| 6779 | instance->flag_ieee = 1; |
| 6780 | |
| 6781 | megasas_dbg_lvl = 0; |
| 6782 | instance->flag = 0; |
| 6783 | instance->unload = 1; |
| 6784 | instance->last_time = 0; |
| 6785 | instance->disableOnlineCtrlReset = 1; |
| 6786 | instance->UnevenSpanSupport = 0; |
| 6787 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6788 | if (instance->adapter_type != MFI_SERIES) |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6789 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6790 | else |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6791 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6792 | } |
| 6793 | |
| 6794 | /** |
| 6795 | * megasas_probe_one - PCI hotplug entry point |
| 6796 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 6797 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6798 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6799 | static int megasas_probe_one(struct pci_dev *pdev, |
| 6800 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6801 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6802 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6803 | struct Scsi_Host *host; |
| 6804 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6805 | u16 control = 0; |
| 6806 | |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 6807 | switch (pdev->device) { |
| 6808 | case PCI_DEVICE_ID_LSI_AERO_10E1: |
| 6809 | case PCI_DEVICE_ID_LSI_AERO_10E5: |
| 6810 | dev_info(&pdev->dev, "Adapter is in configurable secure mode\n"); |
| 6811 | break; |
| 6812 | } |
| 6813 | |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6814 | /* Reset MSI-X in the kdump kernel */ |
| 6815 | if (reset_devices) { |
| 6816 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 6817 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6818 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6819 | &control); |
| 6820 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 6821 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 6822 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6823 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6824 | control & |
| 6825 | ~PCI_MSIX_FLAGS_ENABLE); |
| 6826 | } |
| 6827 | } |
| 6828 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6829 | |
| 6830 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6831 | * PCI prepping: enable device set bus mastering and dma mask |
| 6832 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6833 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6834 | |
| 6835 | if (rval) { |
| 6836 | return rval; |
| 6837 | } |
| 6838 | |
| 6839 | pci_set_master(pdev); |
| 6840 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6841 | host = scsi_host_alloc(&megasas_template, |
| 6842 | sizeof(struct megasas_instance)); |
| 6843 | |
| 6844 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6845 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6846 | goto fail_alloc_instance; |
| 6847 | } |
| 6848 | |
| 6849 | instance = (struct megasas_instance *)host->hostdata; |
| 6850 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6851 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6852 | |
| 6853 | /* |
| 6854 | * Initialize PCI related and misc parameters |
| 6855 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6856 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6857 | instance->host = host; |
| 6858 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 6859 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
| 6860 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6861 | megasas_set_adapter_type(instance); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6862 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6863 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 6864 | * Initialize MFI Firmware |
| 6865 | */ |
| 6866 | if (megasas_init_fw(instance)) |
| 6867 | goto fail_init_mfi; |
| 6868 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6869 | if (instance->requestorId) { |
| 6870 | if (instance->PlasmaFW111) { |
| 6871 | instance->vf_affiliation_111 = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6872 | dma_alloc_coherent(&pdev->dev, |
| 6873 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 6874 | &instance->vf_affiliation_111_h, |
| 6875 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6876 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6877 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6878 | "memory for VF affiliation buffer\n"); |
| 6879 | } else { |
| 6880 | instance->vf_affiliation = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6881 | dma_alloc_coherent(&pdev->dev, |
| 6882 | (MAX_LOGICAL_DRIVES + 1) * |
| 6883 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 6884 | &instance->vf_affiliation_h, |
| 6885 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6886 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6887 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6888 | "memory for VF affiliation buffer\n"); |
| 6889 | } |
| 6890 | } |
| 6891 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6892 | /* |
| 6893 | * Store instance in PCI softstate |
| 6894 | */ |
| 6895 | pci_set_drvdata(pdev, instance); |
| 6896 | |
| 6897 | /* |
| 6898 | * Add this controller to megasas_mgmt_info structure so that it |
| 6899 | * can be exported to management applications |
| 6900 | */ |
| 6901 | megasas_mgmt_info.count++; |
| 6902 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 6903 | megasas_mgmt_info.max_index++; |
| 6904 | |
| 6905 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6906 | * Register with SCSI mid-layer |
| 6907 | */ |
| 6908 | if (megasas_io_attach(instance)) |
| 6909 | goto fail_io_attach; |
| 6910 | |
| 6911 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 6912 | /* |
| 6913 | * Trigger SCSI to scan our drives |
| 6914 | */ |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 6915 | if (!instance->enable_fw_dev_list || |
| 6916 | (instance->host_device_list_buf->count > 0)) |
| 6917 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 6918 | |
| 6919 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6920 | * Initiate AEN (Asynchronous Event Notification) |
| 6921 | */ |
| 6922 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6923 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6924 | goto fail_start_aen; |
| 6925 | } |
| 6926 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 6927 | /* Get current SR-IOV LD/VF affiliation */ |
| 6928 | if (instance->requestorId) |
| 6929 | megasas_get_ld_vf_affiliation(instance, 1); |
| 6930 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6931 | return 0; |
| 6932 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6933 | fail_start_aen: |
| 6934 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6935 | megasas_mgmt_info.count--; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6936 | megasas_mgmt_info.max_index--; |
weiping zhang | 61f0c3c | 2017-08-08 01:26:57 +0800 | [diff] [blame] | 6937 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6938 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 6939 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6940 | megasas_destroy_irqs(instance); |
| 6941 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6942 | if (instance->adapter_type != MFI_SERIES) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6943 | megasas_release_fusion(instance); |
| 6944 | else |
| 6945 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6946 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6947 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6948 | fail_init_mfi: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6949 | scsi_host_put(host); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6950 | fail_alloc_instance: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6951 | pci_disable_device(pdev); |
| 6952 | |
| 6953 | return -ENODEV; |
| 6954 | } |
| 6955 | |
| 6956 | /** |
| 6957 | * megasas_flush_cache - Requests FW to flush all its caches |
| 6958 | * @instance: Adapter soft state |
| 6959 | */ |
| 6960 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 6961 | { |
| 6962 | struct megasas_cmd *cmd; |
| 6963 | struct megasas_dcmd_frame *dcmd; |
| 6964 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 6965 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6966 | return; |
| 6967 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6968 | cmd = megasas_get_cmd(instance); |
| 6969 | |
| 6970 | if (!cmd) |
| 6971 | return; |
| 6972 | |
| 6973 | dcmd = &cmd->frame->dcmd; |
| 6974 | |
| 6975 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6976 | |
| 6977 | dcmd->cmd = MFI_CMD_DCMD; |
| 6978 | dcmd->cmd_status = 0x0; |
| 6979 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6980 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6981 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6982 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6983 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6984 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6985 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 6986 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 6987 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 6988 | != DCMD_SUCCESS) { |
| 6989 | dev_err(&instance->pdev->dev, |
| 6990 | "return from %s %d\n", __func__, __LINE__); |
| 6991 | return; |
| 6992 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6993 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6994 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6995 | } |
| 6996 | |
| 6997 | /** |
| 6998 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 6999 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7000 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7001 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7002 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 7003 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7004 | { |
| 7005 | struct megasas_cmd *cmd; |
| 7006 | struct megasas_dcmd_frame *dcmd; |
| 7007 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7008 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7009 | return; |
| 7010 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7011 | cmd = megasas_get_cmd(instance); |
| 7012 | |
| 7013 | if (!cmd) |
| 7014 | return; |
| 7015 | |
| 7016 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 7017 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7018 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7019 | if (instance->map_update_cmd) |
| 7020 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7021 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7022 | if (instance->jbod_seq_cmd) |
| 7023 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7024 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7025 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7026 | dcmd = &cmd->frame->dcmd; |
| 7027 | |
| 7028 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 7029 | |
| 7030 | dcmd->cmd = MFI_CMD_DCMD; |
| 7031 | dcmd->cmd_status = 0x0; |
| 7032 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7033 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7034 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 7035 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7036 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7037 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7038 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7039 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 7040 | != DCMD_SUCCESS) { |
| 7041 | dev_err(&instance->pdev->dev, |
| 7042 | "return from %s %d\n", __func__, __LINE__); |
| 7043 | return; |
| 7044 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7045 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7046 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7047 | } |
| 7048 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7049 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7050 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7051 | * megasas_suspend - driver suspend entry point |
| 7052 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7053 | * @state: PCI power state to suspend routine |
| 7054 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7055 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7056 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 7057 | { |
| 7058 | struct Scsi_Host *host; |
| 7059 | struct megasas_instance *instance; |
| 7060 | |
| 7061 | instance = pci_get_drvdata(pdev); |
| 7062 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7063 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7064 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7065 | /* Shutdown SR-IOV heartbeat timer */ |
| 7066 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7067 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 7068 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7069 | /* Stop the FW fault detection watchdog */ |
| 7070 | if (instance->adapter_type != MFI_SERIES) |
| 7071 | megasas_fusion_stop_watchdog(instance); |
| 7072 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7073 | megasas_flush_cache(instance); |
| 7074 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7075 | |
| 7076 | /* cancel the delayed work if this work still in queue */ |
| 7077 | if (instance->ev != NULL) { |
| 7078 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7079 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7080 | instance->ev = NULL; |
| 7081 | } |
| 7082 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7083 | tasklet_kill(&instance->isr_tasklet); |
| 7084 | |
| 7085 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7086 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7087 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7088 | megasas_destroy_irqs(instance); |
| 7089 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7090 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7091 | pci_free_irq_vectors(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7092 | |
| 7093 | pci_save_state(pdev); |
| 7094 | pci_disable_device(pdev); |
| 7095 | |
| 7096 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 7097 | |
| 7098 | return 0; |
| 7099 | } |
| 7100 | |
| 7101 | /** |
| 7102 | * megasas_resume- driver resume entry point |
| 7103 | * @pdev: PCI device structure |
| 7104 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7105 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7106 | megasas_resume(struct pci_dev *pdev) |
| 7107 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7108 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7109 | struct Scsi_Host *host; |
| 7110 | struct megasas_instance *instance; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7111 | int irq_flags = PCI_IRQ_LEGACY; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7112 | |
| 7113 | instance = pci_get_drvdata(pdev); |
| 7114 | host = instance->host; |
| 7115 | pci_set_power_state(pdev, PCI_D0); |
| 7116 | pci_enable_wake(pdev, PCI_D0, 0); |
| 7117 | pci_restore_state(pdev); |
| 7118 | |
| 7119 | /* |
| 7120 | * PCI prepping: enable device set bus mastering and dma mask |
| 7121 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 7122 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7123 | |
| 7124 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7125 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7126 | return rval; |
| 7127 | } |
| 7128 | |
| 7129 | pci_set_master(pdev); |
| 7130 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7131 | /* |
| 7132 | * We expect the FW state to be READY |
| 7133 | */ |
| 7134 | if (megasas_transition_to_ready(instance, 0)) |
| 7135 | goto fail_ready_state; |
| 7136 | |
| 7137 | if (megasas_set_dma_mask(instance)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7138 | goto fail_set_dma_mask; |
| 7139 | |
| 7140 | /* |
| 7141 | * Initialize MFI Firmware |
| 7142 | */ |
| 7143 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7144 | atomic_set(&instance->fw_outstanding, 0); |
Shivasharan S | 41fae9a | 2018-01-05 05:27:39 -0800 | [diff] [blame] | 7145 | atomic_set(&instance->ldio_outstanding, 0); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7146 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 7147 | /* Now re-enable MSI-X */ |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7148 | if (instance->msix_vectors) { |
| 7149 | irq_flags = PCI_IRQ_MSIX; |
| 7150 | if (smp_affinity_enable) |
| 7151 | irq_flags |= PCI_IRQ_AFFINITY; |
| 7152 | } |
| 7153 | rval = pci_alloc_irq_vectors(instance->pdev, 1, |
| 7154 | instance->msix_vectors ? |
| 7155 | instance->msix_vectors : 1, irq_flags); |
| 7156 | if (rval < 0) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 7157 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 7158 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 7159 | megasas_setup_reply_map(instance); |
| 7160 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7161 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7162 | megasas_reset_reply_desc(instance); |
| 7163 | if (megasas_ioc_init_fusion(instance)) { |
| 7164 | megasas_free_cmds(instance); |
| 7165 | megasas_free_cmds_fusion(instance); |
| 7166 | goto fail_init_mfi; |
| 7167 | } |
| 7168 | if (!megasas_get_map_info(instance)) |
| 7169 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 7170 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7171 | *instance->producer = 0; |
| 7172 | *instance->consumer = 0; |
| 7173 | if (megasas_issue_init_mfi(instance)) |
| 7174 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7175 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7176 | |
Shivasharan S | c3b10a5 | 2018-06-04 03:45:10 -0700 | [diff] [blame] | 7177 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) |
| 7178 | goto fail_init_mfi; |
| 7179 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7180 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 7181 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7182 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7183 | if (instance->msix_vectors ? |
| 7184 | megasas_setup_irqs_msix(instance, 0) : |
| 7185 | megasas_setup_irqs_ioapic(instance)) |
| 7186 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7187 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7188 | /* Re-launch SR-IOV heartbeat timer */ |
| 7189 | if (instance->requestorId) { |
| 7190 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 7191 | megasas_start_timer(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7192 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7193 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7194 | goto fail_init_mfi; |
| 7195 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7196 | } |
| 7197 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7198 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7199 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7200 | instance->unload = 0; |
| 7201 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7202 | /* |
| 7203 | * Initiate AEN (Asynchronous Event Notification) |
| 7204 | */ |
| 7205 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7206 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7207 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7208 | /* Re-launch FW fault watchdog */ |
| 7209 | if (instance->adapter_type != MFI_SERIES) |
| 7210 | if (megasas_fusion_start_watchdog(instance) != SUCCESS) |
| 7211 | goto fail_start_watchdog; |
| 7212 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7213 | return 0; |
| 7214 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7215 | fail_start_watchdog: |
| 7216 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7217 | del_timer_sync(&instance->sriov_heartbeat_timer); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7218 | fail_init_mfi: |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7219 | megasas_free_ctrl_dma_buffers(instance); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 7220 | megasas_free_ctrl_mem(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7221 | scsi_host_put(host); |
| 7222 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7223 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7224 | fail_set_dma_mask: |
| 7225 | fail_ready_state: |
| 7226 | |
| 7227 | pci_disable_device(pdev); |
| 7228 | |
| 7229 | return -ENODEV; |
| 7230 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7231 | #else |
| 7232 | #define megasas_suspend NULL |
| 7233 | #define megasas_resume NULL |
| 7234 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7235 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7236 | static inline int |
| 7237 | megasas_wait_for_adapter_operational(struct megasas_instance *instance) |
| 7238 | { |
| 7239 | int wait_time = MEGASAS_RESET_WAIT_TIME * 2; |
| 7240 | int i; |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7241 | u8 adp_state; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7242 | |
| 7243 | for (i = 0; i < wait_time; i++) { |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7244 | adp_state = atomic_read(&instance->adprecovery); |
| 7245 | if ((adp_state == MEGASAS_HBA_OPERATIONAL) || |
| 7246 | (adp_state == MEGASAS_HW_CRITICAL_ERROR)) |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7247 | break; |
| 7248 | |
| 7249 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) |
| 7250 | dev_notice(&instance->pdev->dev, "waiting for controller reset to finish\n"); |
| 7251 | |
| 7252 | msleep(1000); |
| 7253 | } |
| 7254 | |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7255 | if (adp_state != MEGASAS_HBA_OPERATIONAL) { |
| 7256 | dev_info(&instance->pdev->dev, |
| 7257 | "%s HBA failed to become operational, adp_state %d\n", |
| 7258 | __func__, adp_state); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7259 | return 1; |
| 7260 | } |
| 7261 | |
| 7262 | return 0; |
| 7263 | } |
| 7264 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7265 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7266 | * megasas_detach_one - PCI hot"un"plug entry point |
| 7267 | * @pdev: PCI device structure |
| 7268 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7269 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7270 | { |
| 7271 | int i; |
| 7272 | struct Scsi_Host *host; |
| 7273 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7274 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7275 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7276 | |
| 7277 | instance = pci_get_drvdata(pdev); |
| 7278 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7279 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7280 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7281 | /* Shutdown SR-IOV heartbeat timer */ |
| 7282 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7283 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 7284 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7285 | /* Stop the FW fault detection watchdog */ |
| 7286 | if (instance->adapter_type != MFI_SERIES) |
| 7287 | megasas_fusion_stop_watchdog(instance); |
| 7288 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7289 | if (instance->fw_crash_state != UNAVAILABLE) |
| 7290 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7291 | scsi_remove_host(instance->host); |
Shivasharan S | f3f7920 | 2018-01-05 05:27:41 -0800 | [diff] [blame] | 7292 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7293 | |
| 7294 | if (megasas_wait_for_adapter_operational(instance)) |
| 7295 | goto skip_firing_dcmds; |
| 7296 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7297 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7298 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7299 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7300 | skip_firing_dcmds: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7301 | /* cancel the delayed work if this work still in queue*/ |
| 7302 | if (instance->ev != NULL) { |
| 7303 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7304 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7305 | instance->ev = NULL; |
| 7306 | } |
| 7307 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 7308 | /* cancel all wait events */ |
| 7309 | wake_up_all(&instance->int_cmd_wait_q); |
| 7310 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 7311 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7312 | |
| 7313 | /* |
| 7314 | * Take the instance off the instance array. Note that we will not |
| 7315 | * decrement the max_index. We let this array be sparse array |
| 7316 | */ |
| 7317 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 7318 | if (megasas_mgmt_info.instance[i] == instance) { |
| 7319 | megasas_mgmt_info.count--; |
| 7320 | megasas_mgmt_info.instance[i] = NULL; |
| 7321 | |
| 7322 | break; |
| 7323 | } |
| 7324 | } |
| 7325 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7326 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7327 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7328 | megasas_destroy_irqs(instance); |
| 7329 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7330 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7331 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7332 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 7333 | if (instance->adapter_type >= VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 7334 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) |
| 7335 | kfree(fusion->stream_detect_by_ld[i]); |
| 7336 | kfree(fusion->stream_detect_by_ld); |
| 7337 | fusion->stream_detect_by_ld = NULL; |
| 7338 | } |
| 7339 | |
| 7340 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7341 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7342 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7343 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 7344 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 7345 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7346 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7347 | if (fusion->ld_map[i]) |
| 7348 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7349 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7350 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7351 | fusion->ld_map_phys[i]); |
Shivasharan S | def3e8d | 2017-08-23 04:47:03 -0700 | [diff] [blame] | 7352 | if (fusion->ld_drv_map[i]) { |
| 7353 | if (is_vmalloc_addr(fusion->ld_drv_map[i])) |
| 7354 | vfree(fusion->ld_drv_map[i]); |
| 7355 | else |
| 7356 | free_pages((ulong)fusion->ld_drv_map[i], |
| 7357 | fusion->drv_map_pages); |
| 7358 | } |
| 7359 | |
Maurizio Lombardi | 546e559 | 2016-01-22 13:41:42 +0100 | [diff] [blame] | 7360 | if (fusion->pd_seq_sync[i]) |
| 7361 | dma_free_coherent(&instance->pdev->dev, |
| 7362 | pd_seq_map_sz, |
| 7363 | fusion->pd_seq_sync[i], |
| 7364 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7365 | } |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 7366 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7367 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7368 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7369 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7370 | if (instance->vf_affiliation) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7371 | dma_free_coherent(&pdev->dev, (MAX_LOGICAL_DRIVES + 1) * |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7372 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 7373 | instance->vf_affiliation, |
| 7374 | instance->vf_affiliation_h); |
| 7375 | |
| 7376 | if (instance->vf_affiliation_111) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7377 | dma_free_coherent(&pdev->dev, |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7378 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 7379 | instance->vf_affiliation_111, |
| 7380 | instance->vf_affiliation_111_h); |
| 7381 | |
| 7382 | if (instance->hb_host_mem) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7383 | dma_free_coherent(&pdev->dev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7384 | instance->hb_host_mem, |
| 7385 | instance->hb_host_mem_h); |
| 7386 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7387 | megasas_free_ctrl_dma_buffers(instance); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7388 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 7389 | megasas_free_ctrl_mem(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7390 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7391 | scsi_host_put(host); |
| 7392 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7393 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7394 | } |
| 7395 | |
| 7396 | /** |
| 7397 | * megasas_shutdown - Shutdown entry point |
| 7398 | * @device: Generic device structure |
| 7399 | */ |
| 7400 | static void megasas_shutdown(struct pci_dev *pdev) |
| 7401 | { |
| 7402 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7403 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7404 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7405 | |
| 7406 | if (megasas_wait_for_adapter_operational(instance)) |
| 7407 | goto skip_firing_dcmds; |
| 7408 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7409 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 7410 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7411 | |
| 7412 | skip_firing_dcmds: |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7413 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7414 | megasas_destroy_irqs(instance); |
| 7415 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7416 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7417 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7418 | } |
| 7419 | |
| 7420 | /** |
| 7421 | * megasas_mgmt_open - char node "open" entry point |
| 7422 | */ |
| 7423 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 7424 | { |
| 7425 | /* |
| 7426 | * Allow only those users with admin rights |
| 7427 | */ |
| 7428 | if (!capable(CAP_SYS_ADMIN)) |
| 7429 | return -EACCES; |
| 7430 | |
| 7431 | return 0; |
| 7432 | } |
| 7433 | |
| 7434 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7435 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 7436 | * |
| 7437 | * This function adds the calling process to a driver global queue. When an |
| 7438 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 7439 | */ |
| 7440 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 7441 | { |
| 7442 | int rc; |
| 7443 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7444 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7445 | |
| 7446 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 7447 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7448 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7449 | |
| 7450 | if (rc >= 0) { |
| 7451 | /* For sanity check when we get ioctl */ |
| 7452 | filep->private_data = filep; |
| 7453 | return 0; |
| 7454 | } |
| 7455 | |
| 7456 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 7457 | |
| 7458 | return rc; |
| 7459 | } |
| 7460 | |
| 7461 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7462 | * megasas_mgmt_poll - char node "poll" entry point |
| 7463 | * */ |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 7464 | static __poll_t megasas_mgmt_poll(struct file *file, poll_table *wait) |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7465 | { |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 7466 | __poll_t mask; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7467 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7468 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7469 | poll_wait(file, &megasas_poll_wait, wait); |
| 7470 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 7471 | if (megasas_poll_wait_aen) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 7472 | mask = (EPOLLIN | EPOLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7473 | else |
| 7474 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7475 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7476 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 7477 | return mask; |
| 7478 | } |
| 7479 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7480 | /* |
| 7481 | * megasas_set_crash_dump_params_ioctl: |
| 7482 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 7483 | * @cmd: MFI command frame |
| 7484 | */ |
| 7485 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7486 | 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] | 7487 | { |
| 7488 | struct megasas_instance *local_instance; |
| 7489 | int i, error = 0; |
| 7490 | int crash_support; |
| 7491 | |
| 7492 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 7493 | |
| 7494 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 7495 | local_instance = megasas_mgmt_info.instance[i]; |
| 7496 | if (local_instance && local_instance->crash_dump_drv_support) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7497 | if ((atomic_read(&local_instance->adprecovery) == |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7498 | MEGASAS_HBA_OPERATIONAL) && |
| 7499 | !megasas_set_crash_dump_params(local_instance, |
| 7500 | crash_support)) { |
| 7501 | local_instance->crash_dump_app_support = |
| 7502 | crash_support; |
| 7503 | dev_info(&local_instance->pdev->dev, |
| 7504 | "Application firmware crash " |
| 7505 | "dump mode set success\n"); |
| 7506 | error = 0; |
| 7507 | } else { |
| 7508 | dev_info(&local_instance->pdev->dev, |
| 7509 | "Application firmware crash " |
| 7510 | "dump mode set failed\n"); |
| 7511 | error = -1; |
| 7512 | } |
| 7513 | } |
| 7514 | } |
| 7515 | return error; |
| 7516 | } |
| 7517 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7518 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7519 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 7520 | * @instance: Adapter soft state |
| 7521 | * @argp: User's ioctl packet |
| 7522 | */ |
| 7523 | static int |
| 7524 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 7525 | struct megasas_iocpacket __user * user_ioc, |
| 7526 | struct megasas_iocpacket *ioc) |
| 7527 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7528 | struct megasas_sge64 *kern_sge64 = NULL; |
| 7529 | struct megasas_sge32 *kern_sge32 = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7530 | struct megasas_cmd *cmd; |
| 7531 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 7532 | dma_addr_t buf_handle = 0; |
| 7533 | int error = 0, i; |
| 7534 | void *sense = NULL; |
| 7535 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7536 | unsigned long *sense_ptr; |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7537 | u32 opcode = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7538 | |
| 7539 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 7540 | |
| 7541 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7542 | 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] | 7543 | ioc->sge_count, MAX_IOCTL_SGE); |
| 7544 | return -EINVAL; |
| 7545 | } |
| 7546 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 7547 | if ((ioc->frame.hdr.cmd >= MFI_CMD_OP_COUNT) || |
| 7548 | ((ioc->frame.hdr.cmd == MFI_CMD_NVME) && |
| 7549 | !instance->support_nvme_passthru)) { |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7550 | dev_err(&instance->pdev->dev, |
| 7551 | "Received invalid ioctl command 0x%x\n", |
| 7552 | ioc->frame.hdr.cmd); |
| 7553 | return -ENOTSUPP; |
| 7554 | } |
| 7555 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7556 | cmd = megasas_get_cmd(instance); |
| 7557 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7558 | 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] | 7559 | return -ENOMEM; |
| 7560 | } |
| 7561 | |
| 7562 | /* |
| 7563 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 7564 | * frames into our cmd's frames. cmd->frame's context will get |
| 7565 | * overwritten when we copy from user's frames. So set that value |
| 7566 | * alone separately |
| 7567 | */ |
| 7568 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7569 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7570 | cmd->frame->hdr.pad_0 = 0; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7571 | |
| 7572 | cmd->frame->hdr.flags &= (~MFI_FRAME_IEEE); |
| 7573 | |
| 7574 | if (instance->consistent_mask_64bit) |
| 7575 | cmd->frame->hdr.flags |= cpu_to_le16((MFI_FRAME_SGL64 | |
| 7576 | MFI_FRAME_SENSE64)); |
| 7577 | else |
| 7578 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_SGL64 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7579 | MFI_FRAME_SENSE64)); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7580 | |
| 7581 | if (cmd->frame->hdr.cmd == MFI_CMD_DCMD) |
| 7582 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7583 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 7584 | if (opcode == MR_DCMD_CTRL_SHUTDOWN) { |
Shivasharan S | 95c0608 | 2017-02-10 00:59:23 -0800 | [diff] [blame] | 7585 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) { |
| 7586 | megasas_return_cmd(instance, cmd); |
| 7587 | return -1; |
| 7588 | } |
| 7589 | } |
| 7590 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 7591 | if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7592 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 7593 | megasas_return_cmd(instance, cmd); |
| 7594 | return error; |
| 7595 | } |
| 7596 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7597 | /* |
| 7598 | * The management interface between applications and the fw uses |
| 7599 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 7600 | * etc are accomplishes through different kinds of MFI frames. The |
| 7601 | * driver needs to care only about substituting user buffers with |
| 7602 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 7603 | * struct iocpacket itself. |
| 7604 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7605 | if (instance->consistent_mask_64bit) |
| 7606 | kern_sge64 = (struct megasas_sge64 *) |
| 7607 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 7608 | else |
| 7609 | kern_sge32 = (struct megasas_sge32 *) |
| 7610 | ((unsigned long)cmd->frame + ioc->sgl_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7611 | |
| 7612 | /* |
| 7613 | * For each user buffer, create a mirror buffer and copy in |
| 7614 | */ |
| 7615 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 7616 | if (!ioc->sgl[i].iov_len) |
| 7617 | continue; |
| 7618 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7619 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7620 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7621 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7622 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7623 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 7624 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7625 | error = -ENOMEM; |
| 7626 | goto out; |
| 7627 | } |
| 7628 | |
| 7629 | /* |
| 7630 | * We don't change the dma_coherent_mask, so |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7631 | * dma_alloc_coherent only returns 32bit addresses |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7632 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7633 | if (instance->consistent_mask_64bit) { |
| 7634 | kern_sge64[i].phys_addr = cpu_to_le64(buf_handle); |
| 7635 | kern_sge64[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 7636 | } else { |
| 7637 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 7638 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 7639 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7640 | |
| 7641 | /* |
| 7642 | * We created a kernel buffer corresponding to the |
| 7643 | * user buffer. Now copy in from the user buffer |
| 7644 | */ |
| 7645 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 7646 | (u32) (ioc->sgl[i].iov_len))) { |
| 7647 | error = -EFAULT; |
| 7648 | goto out; |
| 7649 | } |
| 7650 | } |
| 7651 | |
| 7652 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7653 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 7654 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7655 | if (!sense) { |
| 7656 | error = -ENOMEM; |
| 7657 | goto out; |
| 7658 | } |
| 7659 | |
| 7660 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7661 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7662 | if (instance->consistent_mask_64bit) |
| 7663 | *sense_ptr = cpu_to_le64(sense_handle); |
| 7664 | else |
| 7665 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7666 | } |
| 7667 | |
| 7668 | /* |
| 7669 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 7670 | * cmd to the SCSI mid-layer |
| 7671 | */ |
| 7672 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7673 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 7674 | cmd->sync_cmd = 0; |
| 7675 | dev_err(&instance->pdev->dev, |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7676 | "return -EBUSY from %s %d cmd 0x%x opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
| 7677 | __func__, __LINE__, cmd->frame->hdr.cmd, opcode, |
| 7678 | cmd->cmd_status_drv); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7679 | return -EBUSY; |
| 7680 | } |
| 7681 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7682 | cmd->sync_cmd = 0; |
| 7683 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 7684 | if (instance->unload == 1) { |
| 7685 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 7686 | "don't submit data to application\n"); |
| 7687 | goto out; |
| 7688 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7689 | /* |
| 7690 | * copy out the kernel buffers to user buffers |
| 7691 | */ |
| 7692 | for (i = 0; i < ioc->sge_count; i++) { |
| 7693 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 7694 | ioc->sgl[i].iov_len)) { |
| 7695 | error = -EFAULT; |
| 7696 | goto out; |
| 7697 | } |
| 7698 | } |
| 7699 | |
| 7700 | /* |
| 7701 | * copy out the sense |
| 7702 | */ |
| 7703 | if (ioc->sense_len) { |
| 7704 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7705 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7706 | * sense buffer address |
| 7707 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7708 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 7709 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7710 | |
Shivasharan S | 318aaef | 2017-02-10 00:59:22 -0800 | [diff] [blame] | 7711 | if (copy_to_user((void __user *)((unsigned long) |
| 7712 | get_unaligned((unsigned long *)sense_ptr)), |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7713 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7714 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 7715 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7716 | error = -EFAULT; |
| 7717 | goto out; |
| 7718 | } |
| 7719 | } |
| 7720 | |
| 7721 | /* |
| 7722 | * copy the status codes returned by the fw |
| 7723 | */ |
| 7724 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 7725 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7726 | 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] | 7727 | error = -EFAULT; |
| 7728 | } |
| 7729 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7730 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7731 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7732 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7733 | sense, sense_handle); |
| 7734 | } |
| 7735 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7736 | for (i = 0; i < ioc->sge_count; i++) { |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7737 | if (kbuff_arr[i]) { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7738 | if (instance->consistent_mask_64bit) |
| 7739 | dma_free_coherent(&instance->pdev->dev, |
| 7740 | le32_to_cpu(kern_sge64[i].length), |
| 7741 | kbuff_arr[i], |
| 7742 | le64_to_cpu(kern_sge64[i].phys_addr)); |
| 7743 | else |
| 7744 | dma_free_coherent(&instance->pdev->dev, |
| 7745 | le32_to_cpu(kern_sge32[i].length), |
| 7746 | kbuff_arr[i], |
| 7747 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 7748 | kbuff_arr[i] = NULL; |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7749 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7750 | } |
| 7751 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7752 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7753 | return error; |
| 7754 | } |
| 7755 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7756 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 7757 | { |
| 7758 | struct megasas_iocpacket __user *user_ioc = |
| 7759 | (struct megasas_iocpacket __user *)arg; |
| 7760 | struct megasas_iocpacket *ioc; |
| 7761 | struct megasas_instance *instance; |
| 7762 | int error; |
| 7763 | |
Markus Elfring | 709ab23 | 2016-08-21 10:39:04 +0200 | [diff] [blame] | 7764 | ioc = memdup_user(user_ioc, sizeof(*ioc)); |
| 7765 | if (IS_ERR(ioc)) |
| 7766 | return PTR_ERR(ioc); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7767 | |
| 7768 | instance = megasas_lookup_instance(ioc->host_no); |
| 7769 | if (!instance) { |
| 7770 | error = -ENODEV; |
| 7771 | goto out_kfree_ioc; |
| 7772 | } |
| 7773 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7774 | /* Block ioctls in VF mode */ |
| 7775 | if (instance->requestorId && !allow_vf_ioctls) { |
| 7776 | error = -ENODEV; |
| 7777 | goto out_kfree_ioc; |
| 7778 | } |
| 7779 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7780 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7781 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7782 | error = -ENODEV; |
| 7783 | goto out_kfree_ioc; |
| 7784 | } |
| 7785 | |
| 7786 | if (instance->unload == 1) { |
| 7787 | error = -ENODEV; |
| 7788 | goto out_kfree_ioc; |
| 7789 | } |
| 7790 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7791 | if (down_interruptible(&instance->ioctl_sem)) { |
| 7792 | error = -ERESTARTSYS; |
| 7793 | goto out_kfree_ioc; |
| 7794 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7795 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 7796 | if (megasas_wait_for_adapter_operational(instance)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7797 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 7798 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7799 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7800 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7801 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7802 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7803 | up(&instance->ioctl_sem); |
| 7804 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7805 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7806 | kfree(ioc); |
| 7807 | return error; |
| 7808 | } |
| 7809 | |
| 7810 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 7811 | { |
| 7812 | struct megasas_instance *instance; |
| 7813 | struct megasas_aen aen; |
| 7814 | int error; |
| 7815 | |
| 7816 | if (file->private_data != file) { |
| 7817 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 7818 | "called first\n"); |
| 7819 | return -EINVAL; |
| 7820 | } |
| 7821 | |
| 7822 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 7823 | return -EFAULT; |
| 7824 | |
| 7825 | instance = megasas_lookup_instance(aen.host_no); |
| 7826 | |
| 7827 | if (!instance) |
| 7828 | return -ENODEV; |
| 7829 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7830 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7831 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7832 | } |
| 7833 | |
| 7834 | if (instance->unload == 1) { |
| 7835 | return -ENODEV; |
| 7836 | } |
| 7837 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 7838 | if (megasas_wait_for_adapter_operational(instance)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7839 | return -ENODEV; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7840 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7841 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7842 | error = megasas_register_aen(instance, aen.seq_num, |
| 7843 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 7844 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7845 | return error; |
| 7846 | } |
| 7847 | |
| 7848 | /** |
| 7849 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 7850 | */ |
| 7851 | static long |
| 7852 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 7853 | { |
| 7854 | switch (cmd) { |
| 7855 | case MEGASAS_IOC_FIRMWARE: |
| 7856 | return megasas_mgmt_ioctl_fw(file, arg); |
| 7857 | |
| 7858 | case MEGASAS_IOC_GET_AEN: |
| 7859 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7860 | } |
| 7861 | |
| 7862 | return -ENOTTY; |
| 7863 | } |
| 7864 | |
| 7865 | #ifdef CONFIG_COMPAT |
| 7866 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 7867 | { |
| 7868 | struct compat_megasas_iocpacket __user *cioc = |
| 7869 | (struct compat_megasas_iocpacket __user *)arg; |
| 7870 | struct megasas_iocpacket __user *ioc = |
| 7871 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 7872 | int i; |
| 7873 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7874 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7875 | u32 local_sense_off; |
| 7876 | u32 local_sense_len; |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7877 | u32 user_sense_off; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7878 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 7879 | if (clear_user(ioc, sizeof(*ioc))) |
| 7880 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7881 | |
| 7882 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 7883 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 7884 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 7885 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 7886 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 7887 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 7888 | return -EFAULT; |
| 7889 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7890 | /* |
| 7891 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 7892 | * sense_len is not null, so prepare the 64bit value under |
| 7893 | * the same condition. |
| 7894 | */ |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7895 | if (get_user(local_sense_off, &ioc->sense_off) || |
| 7896 | get_user(local_sense_len, &ioc->sense_len) || |
| 7897 | get_user(user_sense_off, &cioc->sense_off)) |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7898 | return -EFAULT; |
| 7899 | |
Wenwen Wang | 47db787 | 2018-10-06 13:34:21 -0500 | [diff] [blame] | 7900 | if (local_sense_off != user_sense_off) |
| 7901 | return -EINVAL; |
| 7902 | |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 7903 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7904 | void __user **sense_ioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7905 | (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7906 | compat_uptr_t *sense_cioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 7907 | (compat_uptr_t *)(((unsigned long)&cioc->frame.raw) + user_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7908 | if (get_user(ptr, sense_cioc_ptr) || |
| 7909 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 7910 | return -EFAULT; |
| 7911 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7912 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 7913 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7914 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 7915 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 7916 | copy_in_user(&ioc->sgl[i].iov_len, |
| 7917 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 7918 | return -EFAULT; |
| 7919 | } |
| 7920 | |
| 7921 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 7922 | |
| 7923 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 7924 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 7925 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 7926 | return -EFAULT; |
| 7927 | } |
| 7928 | return error; |
| 7929 | } |
| 7930 | |
| 7931 | static long |
| 7932 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 7933 | unsigned long arg) |
| 7934 | { |
| 7935 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 7936 | case MEGASAS_IOC_FIRMWARE32: |
| 7937 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7938 | case MEGASAS_IOC_GET_AEN: |
| 7939 | return megasas_mgmt_ioctl_aen(file, arg); |
| 7940 | } |
| 7941 | |
| 7942 | return -ENOTTY; |
| 7943 | } |
| 7944 | #endif |
| 7945 | |
| 7946 | /* |
| 7947 | * File operations structure for management interface |
| 7948 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 7949 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7950 | .owner = THIS_MODULE, |
| 7951 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7952 | .fasync = megasas_mgmt_fasync, |
| 7953 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7954 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7955 | #ifdef CONFIG_COMPAT |
| 7956 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 7957 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 7958 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7959 | }; |
| 7960 | |
| 7961 | /* |
| 7962 | * PCI hotplug support registration structure |
| 7963 | */ |
| 7964 | static struct pci_driver megasas_pci_driver = { |
| 7965 | |
| 7966 | .name = "megaraid_sas", |
| 7967 | .id_table = megasas_pci_table, |
| 7968 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7969 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7970 | .suspend = megasas_suspend, |
| 7971 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7972 | .shutdown = megasas_shutdown, |
| 7973 | }; |
| 7974 | |
| 7975 | /* |
| 7976 | * Sysfs driver attributes |
| 7977 | */ |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7978 | static ssize_t version_show(struct device_driver *dd, char *buf) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7979 | { |
| 7980 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 7981 | MEGASAS_VERSION); |
| 7982 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7983 | static DRIVER_ATTR_RO(version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7984 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7985 | 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] | 7986 | { |
| 7987 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 7988 | MEGASAS_RELDATE); |
| 7989 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7990 | static DRIVER_ATTR_RO(release_date); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 7991 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7992 | 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] | 7993 | { |
| 7994 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 7995 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7996 | static DRIVER_ATTR_RO(support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 7997 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 7998 | 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] | 7999 | { |
| 8000 | return sprintf(buf, "%u\n", support_device_change); |
| 8001 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8002 | static DRIVER_ATTR_RO(support_device_change); |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8003 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8004 | static ssize_t dbg_lvl_show(struct device_driver *dd, char *buf) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8005 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8006 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8007 | } |
| 8008 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8009 | static ssize_t dbg_lvl_store(struct device_driver *dd, const char *buf, |
| 8010 | size_t count) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8011 | { |
| 8012 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 8013 | |
| 8014 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8015 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 8016 | retval = -EINVAL; |
| 8017 | } |
| 8018 | return retval; |
| 8019 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8020 | static DRIVER_ATTR_RW(dbg_lvl); |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8021 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8022 | static ssize_t |
| 8023 | support_nvme_encapsulation_show(struct device_driver *dd, char *buf) |
| 8024 | { |
| 8025 | return sprintf(buf, "%u\n", support_nvme_encapsulation); |
| 8026 | } |
| 8027 | |
| 8028 | static DRIVER_ATTR_RO(support_nvme_encapsulation); |
| 8029 | |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 8030 | static inline void megasas_remove_scsi_device(struct scsi_device *sdev) |
| 8031 | { |
| 8032 | sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n"); |
| 8033 | scsi_remove_device(sdev); |
| 8034 | scsi_device_put(sdev); |
| 8035 | } |
| 8036 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8037 | /** |
| 8038 | * megasas_update_device_list - Update the PD and LD device list from FW |
| 8039 | * after an AEN event notification |
| 8040 | * @instance: Adapter soft state |
| 8041 | * @event_type: Indicates type of event (PD or LD event) |
| 8042 | * |
| 8043 | * @return: Success or failure |
| 8044 | * |
| 8045 | * Issue DCMDs to Firmware to update the internal device list in driver. |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8046 | * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination |
| 8047 | * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list. |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8048 | */ |
| 8049 | static |
| 8050 | int megasas_update_device_list(struct megasas_instance *instance, |
| 8051 | int event_type) |
| 8052 | { |
| 8053 | int dcmd_ret = DCMD_SUCCESS; |
| 8054 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8055 | if (instance->enable_fw_dev_list) { |
| 8056 | dcmd_ret = megasas_host_device_list_query(instance, false); |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8057 | if (dcmd_ret != DCMD_SUCCESS) |
| 8058 | goto out; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8059 | } else { |
| 8060 | if (event_type & SCAN_PD_CHANNEL) { |
| 8061 | dcmd_ret = megasas_get_pd_list(instance); |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8062 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8063 | if (dcmd_ret != DCMD_SUCCESS) |
| 8064 | goto out; |
| 8065 | } |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8066 | |
| 8067 | if (event_type & SCAN_VD_CHANNEL) { |
| 8068 | if (!instance->requestorId || |
| 8069 | (instance->requestorId && |
| 8070 | megasas_get_ld_vf_affiliation(instance, 0))) { |
| 8071 | dcmd_ret = megasas_ld_list_query(instance, |
| 8072 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 8073 | if (dcmd_ret != DCMD_SUCCESS) |
| 8074 | goto out; |
| 8075 | } |
| 8076 | } |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8077 | } |
| 8078 | |
| 8079 | out: |
| 8080 | return dcmd_ret; |
| 8081 | } |
| 8082 | |
| 8083 | /** |
| 8084 | * megasas_add_remove_devices - Add/remove devices to SCSI mid-layer |
| 8085 | * after an AEN event notification |
| 8086 | * @instance: Adapter soft state |
| 8087 | * @scan_type: Indicates type of devices (PD/LD) to add |
| 8088 | * @return void |
| 8089 | */ |
| 8090 | static |
| 8091 | void megasas_add_remove_devices(struct megasas_instance *instance, |
| 8092 | int scan_type) |
| 8093 | { |
| 8094 | int i, j; |
| 8095 | u16 pd_index = 0; |
| 8096 | u16 ld_index = 0; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8097 | u16 channel = 0, id = 0; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8098 | struct Scsi_Host *host; |
| 8099 | struct scsi_device *sdev1; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8100 | struct MR_HOST_DEVICE_LIST *targetid_list = NULL; |
| 8101 | struct MR_HOST_DEVICE_LIST_ENTRY *targetid_entry = NULL; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8102 | |
| 8103 | host = instance->host; |
| 8104 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8105 | if (instance->enable_fw_dev_list) { |
| 8106 | targetid_list = instance->host_device_list_buf; |
| 8107 | for (i = 0; i < targetid_list->count; i++) { |
| 8108 | targetid_entry = &targetid_list->host_device_list[i]; |
| 8109 | if (targetid_entry->flags.u.bits.is_sys_pd) { |
| 8110 | channel = le16_to_cpu(targetid_entry->target_id) / |
| 8111 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8112 | id = le16_to_cpu(targetid_entry->target_id) % |
| 8113 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8114 | } else { |
| 8115 | channel = MEGASAS_MAX_PD_CHANNELS + |
| 8116 | (le16_to_cpu(targetid_entry->target_id) / |
| 8117 | MEGASAS_MAX_DEV_PER_CHANNEL); |
| 8118 | id = le16_to_cpu(targetid_entry->target_id) % |
| 8119 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8120 | } |
| 8121 | sdev1 = scsi_device_lookup(host, channel, id, 0); |
| 8122 | if (!sdev1) { |
| 8123 | scsi_add_device(host, channel, id, 0); |
| 8124 | } else { |
| 8125 | scsi_device_put(sdev1); |
| 8126 | } |
| 8127 | } |
| 8128 | } |
| 8129 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8130 | if (scan_type & SCAN_PD_CHANNEL) { |
| 8131 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 8132 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 8133 | pd_index = i * MEGASAS_MAX_DEV_PER_CHANNEL + j; |
| 8134 | sdev1 = scsi_device_lookup(host, i, j, 0); |
| 8135 | if (instance->pd_list[pd_index].driveState == |
| 8136 | MR_PD_STATE_SYSTEM) { |
| 8137 | if (!sdev1) |
| 8138 | scsi_add_device(host, i, j, 0); |
| 8139 | else |
| 8140 | scsi_device_put(sdev1); |
| 8141 | } else { |
| 8142 | if (sdev1) |
| 8143 | megasas_remove_scsi_device(sdev1); |
| 8144 | } |
| 8145 | } |
| 8146 | } |
| 8147 | } |
| 8148 | |
| 8149 | if (scan_type & SCAN_VD_CHANNEL) { |
| 8150 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 8151 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 8152 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 8153 | sdev1 = scsi_device_lookup(host, |
| 8154 | MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 8155 | if (instance->ld_ids[ld_index] != 0xff) { |
| 8156 | if (!sdev1) |
| 8157 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 8158 | else |
| 8159 | scsi_device_put(sdev1); |
| 8160 | } else { |
| 8161 | if (sdev1) |
| 8162 | megasas_remove_scsi_device(sdev1); |
| 8163 | } |
| 8164 | } |
| 8165 | } |
| 8166 | } |
| 8167 | |
| 8168 | } |
| 8169 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8170 | static void |
| 8171 | megasas_aen_polling(struct work_struct *work) |
| 8172 | { |
| 8173 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 8174 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8175 | struct megasas_instance *instance = ev->instance; |
| 8176 | union megasas_evt_class_locale class_locale; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8177 | int event_type = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8178 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8179 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8180 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8181 | |
| 8182 | if (!instance) { |
| 8183 | printk(KERN_ERR "invalid instance!\n"); |
| 8184 | kfree(ev); |
| 8185 | return; |
| 8186 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8187 | |
| 8188 | /* Adjust event workqueue thread wait time for VF mode */ |
| 8189 | if (instance->requestorId) |
| 8190 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 8191 | |
| 8192 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8193 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8194 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8195 | instance->ev = NULL; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8196 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 8197 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8198 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 8199 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8200 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8201 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8202 | case MR_EVT_PD_REMOVED: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8203 | event_type = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 8204 | break; |
| 8205 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8206 | case MR_EVT_LD_OFFLINE: |
| 8207 | case MR_EVT_CFG_CLEARED: |
| 8208 | case MR_EVT_LD_DELETED: |
| 8209 | case MR_EVT_LD_CREATED: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8210 | event_type = SCAN_VD_CHANNEL; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8211 | break; |
| 8212 | |
| 8213 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 8214 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 8215 | case MR_EVT_LD_STATE_CHANGE: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8216 | event_type = SCAN_PD_CHANNEL | SCAN_VD_CHANNEL; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8217 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 8218 | instance->host->host_no); |
| 8219 | break; |
| 8220 | |
| 8221 | case MR_EVT_CTRL_PROP_CHANGED: |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 8222 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 8223 | if (dcmd_ret == DCMD_SUCCESS && |
| 8224 | instance->snapdump_wait_time) { |
| 8225 | megasas_get_snapdump_properties(instance); |
| 8226 | dev_info(&instance->pdev->dev, |
| 8227 | "Snap dump wait time\t: %d\n", |
| 8228 | instance->snapdump_wait_time); |
| 8229 | } |
| 8230 | break; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8231 | default: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8232 | event_type = 0; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8233 | break; |
| 8234 | } |
| 8235 | } else { |
| 8236 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 8237 | mutex_unlock(&instance->reset_mutex); |
| 8238 | kfree(ev); |
| 8239 | return; |
| 8240 | } |
| 8241 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8242 | if (event_type) |
| 8243 | dcmd_ret = megasas_update_device_list(instance, event_type); |
| 8244 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8245 | mutex_unlock(&instance->reset_mutex); |
| 8246 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8247 | if (event_type && dcmd_ret == DCMD_SUCCESS) |
| 8248 | megasas_add_remove_devices(instance, event_type); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8249 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8250 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8251 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 8252 | else |
| 8253 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8254 | |
| 8255 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 8256 | class_locale.members.reserved = 0; |
| 8257 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 8258 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8259 | |
| 8260 | if (instance->aen_cmd != NULL) { |
| 8261 | kfree(ev); |
| 8262 | return; |
| 8263 | } |
| 8264 | |
| 8265 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8266 | error = megasas_register_aen(instance, seq_num, |
| 8267 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8268 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8269 | dev_err(&instance->pdev->dev, |
| 8270 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8271 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8272 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8273 | kfree(ev); |
| 8274 | } |
| 8275 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8276 | /** |
| 8277 | * megasas_init - Driver load entry point |
| 8278 | */ |
| 8279 | static int __init megasas_init(void) |
| 8280 | { |
| 8281 | int rval; |
| 8282 | |
| 8283 | /* |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 8284 | * Booted in kdump kernel, minimize memory footprints by |
| 8285 | * disabling few features |
| 8286 | */ |
| 8287 | if (reset_devices) { |
| 8288 | msix_vectors = 1; |
| 8289 | rdpq_enable = 0; |
| 8290 | dual_qdepth_disable = 1; |
| 8291 | } |
| 8292 | |
| 8293 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8294 | * Announce driver version and other information |
| 8295 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 8296 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8297 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 8298 | spin_lock_init(&poll_aen_lock); |
| 8299 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8300 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8301 | support_device_change = 1; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8302 | support_nvme_encapsulation = true; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8303 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8304 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 8305 | |
| 8306 | /* |
| 8307 | * Register character device node |
| 8308 | */ |
| 8309 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 8310 | |
| 8311 | if (rval < 0) { |
| 8312 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 8313 | return rval; |
| 8314 | } |
| 8315 | |
| 8316 | megasas_mgmt_majorno = rval; |
| 8317 | |
| 8318 | /* |
| 8319 | * Register ourselves as PCI hotplug module |
| 8320 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 8321 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8322 | |
| 8323 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 8324 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8325 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8326 | } |
| 8327 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8328 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8329 | &driver_attr_version); |
| 8330 | if (rval) |
| 8331 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8332 | |
| 8333 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8334 | &driver_attr_release_date); |
| 8335 | if (rval) |
| 8336 | goto err_dcf_rel_date; |
| 8337 | |
| 8338 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8339 | &driver_attr_support_poll_for_event); |
| 8340 | if (rval) |
| 8341 | goto err_dcf_support_poll_for_event; |
| 8342 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8343 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8344 | &driver_attr_dbg_lvl); |
| 8345 | if (rval) |
| 8346 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8347 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8348 | &driver_attr_support_device_change); |
| 8349 | if (rval) |
| 8350 | goto err_dcf_support_device_change; |
| 8351 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8352 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8353 | &driver_attr_support_nvme_encapsulation); |
| 8354 | if (rval) |
| 8355 | goto err_dcf_support_nvme_encapsulation; |
| 8356 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8357 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8358 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8359 | err_dcf_support_nvme_encapsulation: |
| 8360 | driver_remove_file(&megasas_pci_driver.driver, |
| 8361 | &driver_attr_support_device_change); |
| 8362 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8363 | err_dcf_support_device_change: |
| 8364 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8365 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8366 | err_dcf_dbg_lvl: |
| 8367 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8368 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8369 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8370 | driver_remove_file(&megasas_pci_driver.driver, |
| 8371 | &driver_attr_release_date); |
| 8372 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8373 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 8374 | err_dcf_attr_ver: |
| 8375 | pci_unregister_driver(&megasas_pci_driver); |
| 8376 | err_pcidrv: |
| 8377 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 8378 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8379 | } |
| 8380 | |
| 8381 | /** |
| 8382 | * megasas_exit - Driver unload entry point |
| 8383 | */ |
| 8384 | static void __exit megasas_exit(void) |
| 8385 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8386 | driver_remove_file(&megasas_pci_driver.driver, |
| 8387 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8388 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8389 | &driver_attr_support_poll_for_event); |
| 8390 | driver_remove_file(&megasas_pci_driver.driver, |
| 8391 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8392 | driver_remove_file(&megasas_pci_driver.driver, |
| 8393 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8394 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8395 | driver_remove_file(&megasas_pci_driver.driver, |
| 8396 | &driver_attr_support_nvme_encapsulation); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8397 | |
| 8398 | pci_unregister_driver(&megasas_pci_driver); |
| 8399 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 8400 | } |
| 8401 | |
| 8402 | module_init(megasas_init); |
| 8403 | module_exit(megasas_exit); |