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> |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 51 | #include <linux/irq_poll.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 52 | |
| 53 | #include <scsi/scsi.h> |
| 54 | #include <scsi/scsi_cmnd.h> |
| 55 | #include <scsi/scsi_device.h> |
| 56 | #include <scsi/scsi_host.h> |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 57 | #include <scsi/scsi_tcq.h> |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 58 | #include <scsi/scsi_dbg.h> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 59 | #include "megaraid_sas_fusion.h" |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 60 | #include "megaraid_sas.h" |
| 61 | |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 62 | /* |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 63 | * Number of sectors per IO command |
| 64 | * Will be set in megasas_init_mfi if user does not provide |
| 65 | */ |
| 66 | static unsigned int max_sectors; |
| 67 | module_param_named(max_sectors, max_sectors, int, 0); |
| 68 | MODULE_PARM_DESC(max_sectors, |
| 69 | "Maximum number of sectors per IO command"); |
| 70 | |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 71 | static int msix_disable; |
| 72 | module_param(msix_disable, int, S_IRUGO); |
| 73 | MODULE_PARM_DESC(msix_disable, "Disable MSI-X interrupt handling. Default: 0"); |
| 74 | |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 75 | static unsigned int msix_vectors; |
| 76 | module_param(msix_vectors, int, S_IRUGO); |
| 77 | MODULE_PARM_DESC(msix_vectors, "MSI-X max vector count. Default: Set by FW"); |
| 78 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 79 | static int allow_vf_ioctls; |
| 80 | module_param(allow_vf_ioctls, int, S_IRUGO); |
| 81 | MODULE_PARM_DESC(allow_vf_ioctls, "Allow ioctls in SR-IOV VF mode. Default: 0"); |
| 82 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 83 | static unsigned int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH; |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 84 | module_param(throttlequeuedepth, int, S_IRUGO); |
| 85 | MODULE_PARM_DESC(throttlequeuedepth, |
| 86 | "Adapter queue depth when throttled due to I/O timeout. Default: 16"); |
| 87 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 88 | unsigned int resetwaittime = MEGASAS_RESET_WAIT_TIME; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 89 | module_param(resetwaittime, int, S_IRUGO); |
Shivasharan S | 1401371 | 2018-10-16 23:37:45 -0700 | [diff] [blame] | 90 | 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] | 91 | |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 92 | int smp_affinity_enable = 1; |
| 93 | module_param(smp_affinity_enable, int, S_IRUGO); |
Colin Ian King | 55d9a1d | 2018-04-29 13:25:32 +0100 | [diff] [blame] | 94 | 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] | 95 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 96 | int rdpq_enable = 1; |
| 97 | module_param(rdpq_enable, int, S_IRUGO); |
Shivasharan S | 1401371 | 2018-10-16 23:37:45 -0700 | [diff] [blame] | 98 | 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] | 99 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 100 | unsigned int dual_qdepth_disable; |
| 101 | module_param(dual_qdepth_disable, int, S_IRUGO); |
| 102 | MODULE_PARM_DESC(dual_qdepth_disable, "Disable dual queue depth feature. Default: 0"); |
| 103 | |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 104 | unsigned int scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
| 105 | module_param(scmd_timeout, int, S_IRUGO); |
| 106 | MODULE_PARM_DESC(scmd_timeout, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer."); |
| 107 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 108 | MODULE_LICENSE("GPL"); |
| 109 | MODULE_VERSION(MEGASAS_VERSION); |
Shivasharan S | 365597c | 2018-10-16 23:37:43 -0700 | [diff] [blame] | 110 | MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com"); |
| 111 | MODULE_DESCRIPTION("Broadcom MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 112 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 113 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 114 | static int megasas_get_pd_list(struct megasas_instance *instance); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 115 | static int megasas_ld_list_query(struct megasas_instance *instance, |
| 116 | u8 query_type); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 117 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 118 | static int megasas_register_aen(struct megasas_instance *instance, |
| 119 | u32 seq_num, u32 class_locale_word); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 120 | static void megasas_get_pd_info(struct megasas_instance *instance, |
| 121 | struct scsi_device *sdev); |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 122 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 123 | /* |
| 124 | * PCI ID table for all supported controllers |
| 125 | */ |
| 126 | static struct pci_device_id megasas_pci_table[] = { |
| 127 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 128 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 129 | /* xscale IOP */ |
| 130 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 131 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 132 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 133 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 134 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 135 | /* gen2*/ |
| 136 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 137 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 138 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 139 | /* skinny*/ |
| 140 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 141 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 142 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 143 | /* xscale IOP, vega */ |
| 144 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 145 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 146 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 147 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 148 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 149 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 150 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 151 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 152 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 153 | /* Fury */ |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 154 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER)}, |
| 155 | /* Intruder */ |
| 156 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER_24)}, |
| 157 | /* Intruder 24 port*/ |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 158 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)}, |
| 159 | {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] | 160 | /* VENTURA */ |
| 161 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA)}, |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 162 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER)}, |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 163 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_HARPOON)}, |
| 164 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)}, |
| 165 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)}, |
| 166 | {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] | 167 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E1)}, |
| 168 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E2)}, |
| 169 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E5)}, |
| 170 | {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] | 171 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 175 | |
| 176 | static int megasas_mgmt_majorno; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 177 | struct megasas_mgmt_info megasas_mgmt_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 178 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 179 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 180 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 181 | static int megasas_poll_wait_aen; |
| 182 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 183 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 184 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 185 | static u32 support_device_change; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 186 | static bool support_nvme_encapsulation; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 187 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 188 | /* define lock for aen poll */ |
| 189 | spinlock_t poll_aen_lock; |
| 190 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 191 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 192 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 193 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 194 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 195 | megasas_read_fw_status_reg_gen2(struct megasas_instance *instance); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 196 | static int |
| 197 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 198 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 199 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 200 | static u32 |
| 201 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 202 | u32 |
| 203 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 204 | struct scsi_cmnd *scmd); |
| 205 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 206 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 207 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 208 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 209 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 210 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 211 | int initial); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 212 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 213 | megasas_set_dma_mask(struct megasas_instance *instance); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 214 | static int |
| 215 | megasas_alloc_ctrl_mem(struct megasas_instance *instance); |
| 216 | static inline void |
| 217 | megasas_free_ctrl_mem(struct megasas_instance *instance); |
| 218 | static inline int |
| 219 | megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance); |
| 220 | static inline void |
| 221 | megasas_free_ctrl_dma_buffers(struct megasas_instance *instance); |
| 222 | static inline void |
| 223 | megasas_init_ctrl_params(struct megasas_instance *instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 224 | |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 225 | u32 megasas_readl(struct megasas_instance *instance, |
| 226 | const volatile void __iomem *addr) |
| 227 | { |
| 228 | u32 i = 0, ret_val; |
| 229 | /* |
| 230 | * Due to a HW errata in Aero controllers, reads to certain |
| 231 | * Fusion registers could intermittently return all zeroes. |
| 232 | * This behavior is transient in nature and subsequent reads will |
| 233 | * return valid value. As a workaround in driver, retry readl for |
| 234 | * upto three times until a non-zero value is read. |
| 235 | */ |
| 236 | if (instance->adapter_type == AERO_SERIES) { |
| 237 | do { |
| 238 | ret_val = readl(addr); |
| 239 | i++; |
| 240 | } while (ret_val == 0 && i < 3); |
| 241 | return ret_val; |
| 242 | } else { |
| 243 | return readl(addr); |
| 244 | } |
| 245 | } |
| 246 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 247 | /** |
| 248 | * megasas_set_dma_settings - Populate DMA address, length and flags for DCMDs |
| 249 | * @instance: Adapter soft state |
| 250 | * @dcmd: DCMD frame inside MFI command |
| 251 | * @dma_addr: DMA address of buffer to be passed to FW |
| 252 | * @dma_len: Length of DMA buffer to be passed to FW |
| 253 | * @return: void |
| 254 | */ |
| 255 | void megasas_set_dma_settings(struct megasas_instance *instance, |
| 256 | struct megasas_dcmd_frame *dcmd, |
| 257 | dma_addr_t dma_addr, u32 dma_len) |
| 258 | { |
| 259 | if (instance->consistent_mask_64bit) { |
| 260 | dcmd->sgl.sge64[0].phys_addr = cpu_to_le64(dma_addr); |
| 261 | dcmd->sgl.sge64[0].length = cpu_to_le32(dma_len); |
| 262 | dcmd->flags = cpu_to_le16(dcmd->flags | MFI_FRAME_SGL64); |
| 263 | |
| 264 | } else { |
| 265 | dcmd->sgl.sge32[0].phys_addr = |
| 266 | cpu_to_le32(lower_32_bits(dma_addr)); |
| 267 | dcmd->sgl.sge32[0].length = cpu_to_le32(dma_len); |
| 268 | dcmd->flags = cpu_to_le16(dcmd->flags); |
| 269 | } |
| 270 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 271 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 272 | void |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 273 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 274 | { |
| 275 | instance->instancet->fire_cmd(instance, |
| 276 | cmd->frame_phys_addr, 0, instance->reg_set); |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 277 | return; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 278 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 279 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 280 | /** |
| 281 | * megasas_get_cmd - Get a command from the free pool |
| 282 | * @instance: Adapter soft state |
| 283 | * |
| 284 | * Returns a free command from the pool |
| 285 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 286 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 287 | *instance) |
| 288 | { |
| 289 | unsigned long flags; |
| 290 | struct megasas_cmd *cmd = NULL; |
| 291 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 292 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 293 | |
| 294 | if (!list_empty(&instance->cmd_pool)) { |
| 295 | cmd = list_entry((&instance->cmd_pool)->next, |
| 296 | struct megasas_cmd, list); |
| 297 | list_del_init(&cmd->list); |
| 298 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 299 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 300 | } |
| 301 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 302 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 303 | return cmd; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * megasas_return_cmd - Return a cmd to free command pool |
| 308 | * @instance: Adapter soft state |
| 309 | * @cmd: Command packet to be returned to free command pool |
| 310 | */ |
Andi Kleen | 68b4374 | 2017-05-08 15:58:53 -0700 | [diff] [blame] | 311 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 312 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 313 | { |
| 314 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 315 | u32 blk_tags; |
| 316 | struct megasas_cmd_fusion *cmd_fusion; |
| 317 | struct fusion_context *fusion = instance->ctrl_context; |
| 318 | |
| 319 | /* This flag is used only for fusion adapter. |
| 320 | * Wait for Interrupt for Polled mode DCMD |
| 321 | */ |
| 322 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 323 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 324 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 325 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 326 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 327 | if (fusion) { |
| 328 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 329 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 330 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 331 | } |
| 332 | cmd->scmd = NULL; |
| 333 | cmd->frame_count = 0; |
| 334 | cmd->flags = 0; |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 335 | memset(cmd->frame, 0, instance->mfi_frame_size); |
| 336 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 337 | if (!fusion && reset_devices) |
| 338 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 339 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 340 | |
| 341 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 342 | |
| 343 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 344 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 345 | static const char * |
| 346 | format_timestamp(uint32_t timestamp) |
| 347 | { |
| 348 | static char buffer[32]; |
| 349 | |
| 350 | if ((timestamp & 0xff000000) == 0xff000000) |
| 351 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 352 | 0x00ffffff); |
| 353 | else |
| 354 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 355 | return buffer; |
| 356 | } |
| 357 | |
| 358 | static const char * |
| 359 | format_class(int8_t class) |
| 360 | { |
| 361 | static char buffer[6]; |
| 362 | |
| 363 | switch (class) { |
| 364 | case MFI_EVT_CLASS_DEBUG: |
| 365 | return "debug"; |
| 366 | case MFI_EVT_CLASS_PROGRESS: |
| 367 | return "progress"; |
| 368 | case MFI_EVT_CLASS_INFO: |
| 369 | return "info"; |
| 370 | case MFI_EVT_CLASS_WARNING: |
| 371 | return "WARN"; |
| 372 | case MFI_EVT_CLASS_CRITICAL: |
| 373 | return "CRIT"; |
| 374 | case MFI_EVT_CLASS_FATAL: |
| 375 | return "FATAL"; |
| 376 | case MFI_EVT_CLASS_DEAD: |
| 377 | return "DEAD"; |
| 378 | default: |
| 379 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 380 | return buffer; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 386 | * for information. |
| 387 | * @instance: Adapter soft state |
| 388 | */ |
| 389 | static void |
| 390 | megasas_decode_evt(struct megasas_instance *instance) |
| 391 | { |
| 392 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 393 | union megasas_evt_class_locale class_locale; |
| 394 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 395 | |
| 396 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 397 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 398 | le32_to_cpu(evt_detail->seq_num), |
| 399 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 400 | (class_locale.members.locale), |
| 401 | format_class(class_locale.members.class), |
| 402 | evt_detail->description); |
| 403 | } |
| 404 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 405 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 406 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 407 | * (deviceid : 1064R, PERC5) controllers |
| 408 | */ |
| 409 | |
| 410 | /** |
| 411 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 412 | * @regs: MFI register set |
| 413 | */ |
| 414 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 415 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 416 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 417 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 418 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 419 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 420 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 421 | |
| 422 | /* Dummy readl to force pci flush */ |
| 423 | readl(®s->outbound_intr_mask); |
| 424 | } |
| 425 | |
| 426 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 427 | * megasas_disable_intr_xscale -Disables interrupt |
| 428 | * @regs: MFI register set |
| 429 | */ |
| 430 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 431 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 432 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 433 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 434 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 435 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 436 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 437 | writel(mask, ®s->outbound_intr_mask); |
| 438 | /* Dummy readl to force pci flush */ |
| 439 | readl(®s->outbound_intr_mask); |
| 440 | } |
| 441 | |
| 442 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 443 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 444 | * @regs: MFI register set |
| 445 | */ |
| 446 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 447 | megasas_read_fw_status_reg_xscale(struct megasas_instance *instance) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 448 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 449 | return readl(&instance->reg_set->outbound_msg_0); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 450 | } |
| 451 | /** |
| 452 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 453 | * @regs: MFI register set |
| 454 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 455 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 456 | megasas_clear_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 457 | { |
| 458 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 459 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 460 | struct megasas_register_set __iomem *regs; |
| 461 | regs = instance->reg_set; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 462 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 463 | /* |
| 464 | * Check if it is our interrupt |
| 465 | */ |
| 466 | status = readl(®s->outbound_intr_status); |
| 467 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 468 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 469 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 470 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 471 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * Clear the interrupt by writing back the same value |
| 475 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 476 | if (mfiStatus) |
| 477 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 478 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 479 | /* Dummy readl to force pci flush */ |
| 480 | readl(®s->outbound_intr_status); |
| 481 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 482 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | /** |
| 486 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 487 | * @frame_phys_addr : Physical address of cmd |
| 488 | * @frame_count : Number of frames for the command |
| 489 | * @regs : MFI register set |
| 490 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 491 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 492 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 493 | dma_addr_t frame_phys_addr, |
| 494 | u32 frame_count, |
| 495 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 496 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 497 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 498 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 499 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 500 | writel((frame_phys_addr >> 3)|(frame_count), |
| 501 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 502 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * megasas_adp_reset_xscale - For controller reset |
| 507 | * @regs: MFI register set |
| 508 | */ |
| 509 | static int |
| 510 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 511 | struct megasas_register_set __iomem *regs) |
| 512 | { |
| 513 | u32 i; |
| 514 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 515 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 516 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 517 | |
| 518 | for (i = 0; i < 3; i++) |
| 519 | msleep(1000); /* sleep for 3 secs */ |
| 520 | pcidata = 0; |
| 521 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 522 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 523 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 524 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 525 | pcidata &= ~0x2; |
| 526 | pci_write_config_dword(instance->pdev, |
| 527 | MFI_1068_PCSR_OFFSET, pcidata); |
| 528 | |
| 529 | for (i = 0; i < 2; i++) |
| 530 | msleep(1000); /* need to wait 2 secs again */ |
| 531 | |
| 532 | pcidata = 0; |
| 533 | pci_read_config_dword(instance->pdev, |
| 534 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 535 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 536 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 537 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 538 | pcidata = 0; |
| 539 | pci_write_config_dword(instance->pdev, |
| 540 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 541 | } |
| 542 | } |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * megasas_check_reset_xscale - For controller reset check |
| 548 | * @regs: MFI register set |
| 549 | */ |
| 550 | static int |
| 551 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 552 | struct megasas_register_set __iomem *regs) |
| 553 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 554 | if ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 555 | (le32_to_cpu(*instance->consumer) == |
| 556 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 557 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 558 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 562 | |
| 563 | .fire_cmd = megasas_fire_cmd_xscale, |
| 564 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 565 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 566 | .clear_intr = megasas_clear_intr_xscale, |
| 567 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 568 | .adp_reset = megasas_adp_reset_xscale, |
| 569 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 570 | .service_isr = megasas_isr, |
| 571 | .tasklet = megasas_complete_cmd_dpc, |
| 572 | .init_adapter = megasas_init_adapter_mfi, |
| 573 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 574 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 575 | }; |
| 576 | |
| 577 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 578 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 579 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 580 | */ |
| 581 | |
| 582 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 583 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 584 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 585 | */ |
| 586 | |
| 587 | /** |
| 588 | * megasas_enable_intr_ppc - Enables interrupts |
| 589 | * @regs: MFI register set |
| 590 | */ |
| 591 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 592 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 593 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 594 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 595 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 596 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 597 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 598 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 599 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 600 | |
| 601 | /* Dummy readl to force pci flush */ |
| 602 | readl(®s->outbound_intr_mask); |
| 603 | } |
| 604 | |
| 605 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 606 | * megasas_disable_intr_ppc - Disable interrupt |
| 607 | * @regs: MFI register set |
| 608 | */ |
| 609 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 610 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 611 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 612 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 613 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 614 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 615 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 616 | writel(mask, ®s->outbound_intr_mask); |
| 617 | /* Dummy readl to force pci flush */ |
| 618 | readl(®s->outbound_intr_mask); |
| 619 | } |
| 620 | |
| 621 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 622 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 623 | * @regs: MFI register set |
| 624 | */ |
| 625 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 626 | megasas_read_fw_status_reg_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 627 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 628 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | /** |
| 632 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 633 | * @regs: MFI register set |
| 634 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 635 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 636 | megasas_clear_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 637 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 638 | u32 status, mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 639 | struct megasas_register_set __iomem *regs; |
| 640 | regs = instance->reg_set; |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 641 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 642 | /* |
| 643 | * Check if it is our interrupt |
| 644 | */ |
| 645 | status = readl(®s->outbound_intr_status); |
| 646 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 647 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 648 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 649 | |
| 650 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 651 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * Clear the interrupt by writing back the same value |
| 655 | */ |
| 656 | writel(status, ®s->outbound_doorbell_clear); |
| 657 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 658 | /* Dummy readl to force pci flush */ |
| 659 | readl(®s->outbound_doorbell_clear); |
| 660 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 661 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 662 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 663 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 664 | /** |
| 665 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 666 | * @frame_phys_addr : Physical address of cmd |
| 667 | * @frame_count : Number of frames for the command |
| 668 | * @regs : MFI register set |
| 669 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 670 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 671 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 672 | dma_addr_t frame_phys_addr, |
| 673 | u32 frame_count, |
| 674 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 675 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 676 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 677 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 678 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 679 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 680 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 681 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 682 | } |
| 683 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 684 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 685 | * megasas_check_reset_ppc - For controller reset check |
| 686 | * @regs: MFI register set |
| 687 | */ |
| 688 | static int |
| 689 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 690 | struct megasas_register_set __iomem *regs) |
| 691 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 692 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 693 | return 1; |
| 694 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 695 | return 0; |
| 696 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 697 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 698 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 699 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 700 | .fire_cmd = megasas_fire_cmd_ppc, |
| 701 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 702 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 703 | .clear_intr = megasas_clear_intr_ppc, |
| 704 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 705 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 706 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 707 | .service_isr = megasas_isr, |
| 708 | .tasklet = megasas_complete_cmd_dpc, |
| 709 | .init_adapter = megasas_init_adapter_mfi, |
| 710 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 711 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 712 | }; |
| 713 | |
| 714 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 715 | * megasas_enable_intr_skinny - Enables interrupts |
| 716 | * @regs: MFI register set |
| 717 | */ |
| 718 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 719 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 720 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 721 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 722 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 723 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 724 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 725 | |
| 726 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 727 | |
| 728 | /* Dummy readl to force pci flush */ |
| 729 | readl(®s->outbound_intr_mask); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * megasas_disable_intr_skinny - Disables interrupt |
| 734 | * @regs: MFI register set |
| 735 | */ |
| 736 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 737 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 738 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 739 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 740 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 741 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 742 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 743 | writel(mask, ®s->outbound_intr_mask); |
| 744 | /* Dummy readl to force pci flush */ |
| 745 | readl(®s->outbound_intr_mask); |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 750 | * @regs: MFI register set |
| 751 | */ |
| 752 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 753 | megasas_read_fw_status_reg_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 754 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 755 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /** |
| 759 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 760 | * @regs: MFI register set |
| 761 | */ |
| 762 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 763 | megasas_clear_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 764 | { |
| 765 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 766 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 767 | struct megasas_register_set __iomem *regs; |
| 768 | regs = instance->reg_set; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 769 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 770 | /* |
| 771 | * Check if it is our interrupt |
| 772 | */ |
| 773 | status = readl(®s->outbound_intr_status); |
| 774 | |
| 775 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 776 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 780 | * Check if it is our interrupt |
| 781 | */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 782 | if ((megasas_read_fw_status_reg_skinny(instance) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 783 | MFI_STATE_FAULT) { |
| 784 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 785 | } else |
| 786 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 787 | |
| 788 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 789 | * Clear the interrupt by writing back the same value |
| 790 | */ |
| 791 | writel(status, ®s->outbound_intr_status); |
| 792 | |
| 793 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 794 | * dummy read to flush PCI |
| 795 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 796 | readl(®s->outbound_intr_status); |
| 797 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 798 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /** |
| 802 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 803 | * @frame_phys_addr : Physical address of cmd |
| 804 | * @frame_count : Number of frames for the command |
| 805 | * @regs : MFI register set |
| 806 | */ |
| 807 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 808 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 809 | dma_addr_t frame_phys_addr, |
| 810 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 811 | struct megasas_register_set __iomem *regs) |
| 812 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 813 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 814 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 815 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 816 | writel(upper_32_bits(frame_phys_addr), |
| 817 | &(regs)->inbound_high_queue_port); |
| 818 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 819 | &(regs)->inbound_low_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 820 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 821 | } |
| 822 | |
| 823 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 824 | * megasas_check_reset_skinny - For controller reset check |
| 825 | * @regs: MFI register set |
| 826 | */ |
| 827 | static int |
| 828 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 829 | struct megasas_register_set __iomem *regs) |
| 830 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 831 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 832 | return 1; |
| 833 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 834 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 838 | |
| 839 | .fire_cmd = megasas_fire_cmd_skinny, |
| 840 | .enable_intr = megasas_enable_intr_skinny, |
| 841 | .disable_intr = megasas_disable_intr_skinny, |
| 842 | .clear_intr = megasas_clear_intr_skinny, |
| 843 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 844 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 845 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 846 | .service_isr = megasas_isr, |
| 847 | .tasklet = megasas_complete_cmd_dpc, |
| 848 | .init_adapter = megasas_init_adapter_mfi, |
| 849 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 850 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 851 | }; |
| 852 | |
| 853 | |
| 854 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 855 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 856 | * controllers |
| 857 | */ |
| 858 | |
| 859 | /** |
| 860 | * megasas_enable_intr_gen2 - Enables interrupts |
| 861 | * @regs: MFI register set |
| 862 | */ |
| 863 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 864 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 865 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 866 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 867 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 868 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 869 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 870 | |
| 871 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 872 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 873 | |
| 874 | /* Dummy readl to force pci flush */ |
| 875 | readl(®s->outbound_intr_mask); |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * megasas_disable_intr_gen2 - Disables interrupt |
| 880 | * @regs: MFI register set |
| 881 | */ |
| 882 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 883 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 884 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 885 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 886 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 887 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 888 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 889 | writel(mask, ®s->outbound_intr_mask); |
| 890 | /* Dummy readl to force pci flush */ |
| 891 | readl(®s->outbound_intr_mask); |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 896 | * @regs: MFI register set |
| 897 | */ |
| 898 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 899 | megasas_read_fw_status_reg_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 900 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 901 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | /** |
| 905 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 906 | * @regs: MFI register set |
| 907 | */ |
| 908 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 909 | megasas_clear_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 910 | { |
| 911 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 912 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 913 | struct megasas_register_set __iomem *regs; |
| 914 | regs = instance->reg_set; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 915 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 916 | /* |
| 917 | * Check if it is our interrupt |
| 918 | */ |
| 919 | status = readl(®s->outbound_intr_status); |
| 920 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 921 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 922 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 923 | } |
| 924 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 925 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 926 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 927 | |
| 928 | /* |
| 929 | * Clear the interrupt by writing back the same value |
| 930 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 931 | if (mfiStatus) |
| 932 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 933 | |
| 934 | /* Dummy readl to force pci flush */ |
| 935 | readl(®s->outbound_intr_status); |
| 936 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 937 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 938 | } |
| 939 | /** |
| 940 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 941 | * @frame_phys_addr : Physical address of cmd |
| 942 | * @frame_count : Number of frames for the command |
| 943 | * @regs : MFI register set |
| 944 | */ |
| 945 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 946 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 947 | dma_addr_t frame_phys_addr, |
| 948 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 949 | struct megasas_register_set __iomem *regs) |
| 950 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 951 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 952 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 953 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 954 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 955 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 956 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 957 | } |
| 958 | |
| 959 | /** |
| 960 | * megasas_adp_reset_gen2 - For controller reset |
| 961 | * @regs: MFI register set |
| 962 | */ |
| 963 | static int |
| 964 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 965 | struct megasas_register_set __iomem *reg_set) |
| 966 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 967 | u32 retry = 0 ; |
| 968 | u32 HostDiag; |
| 969 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 970 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 971 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 972 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 973 | seq_offset = ®_set->fusion_seq_offset; |
| 974 | hostdiag_offset = ®_set->fusion_host_diag; |
| 975 | } |
| 976 | |
| 977 | writel(0, seq_offset); |
| 978 | writel(4, seq_offset); |
| 979 | writel(0xb, seq_offset); |
| 980 | writel(2, seq_offset); |
| 981 | writel(7, seq_offset); |
| 982 | writel(0xd, seq_offset); |
| 983 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 984 | msleep(1000); |
| 985 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 986 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 987 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 988 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 989 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 990 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 991 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 992 | retry, HostDiag); |
| 993 | |
| 994 | if (retry++ >= 100) |
| 995 | return 1; |
| 996 | |
| 997 | } |
| 998 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 999 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1000 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1001 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1002 | |
| 1003 | ssleep(10); |
| 1004 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1005 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1006 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1007 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1008 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1009 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1010 | retry, HostDiag); |
| 1011 | |
| 1012 | if (retry++ >= 1000) |
| 1013 | return 1; |
| 1014 | |
| 1015 | } |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | /** |
| 1020 | * megasas_check_reset_gen2 - For controller reset check |
| 1021 | * @regs: MFI register set |
| 1022 | */ |
| 1023 | static int |
| 1024 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 1025 | struct megasas_register_set __iomem *regs) |
| 1026 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1027 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1028 | return 1; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1029 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1030 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 1034 | |
| 1035 | .fire_cmd = megasas_fire_cmd_gen2, |
| 1036 | .enable_intr = megasas_enable_intr_gen2, |
| 1037 | .disable_intr = megasas_disable_intr_gen2, |
| 1038 | .clear_intr = megasas_clear_intr_gen2, |
| 1039 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1040 | .adp_reset = megasas_adp_reset_gen2, |
| 1041 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1042 | .service_isr = megasas_isr, |
| 1043 | .tasklet = megasas_complete_cmd_dpc, |
| 1044 | .init_adapter = megasas_init_adapter_mfi, |
| 1045 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 1046 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 1047 | }; |
| 1048 | |
| 1049 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1050 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1051 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1052 | */ |
| 1053 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1054 | /* |
| 1055 | * Template added for TB (Fusion) |
| 1056 | */ |
| 1057 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 1058 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1059 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1060 | * megasas_issue_polled - Issues a polling command |
| 1061 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1062 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1063 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1064 | * 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] | 1065 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1066 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1067 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 1068 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1069 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 1070 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1071 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1072 | 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] | 1073 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1074 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1075 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1076 | __func__, __LINE__); |
| 1077 | return DCMD_NOT_FIRED; |
| 1078 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1079 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1080 | instance->instancet->issue_dcmd(instance, cmd); |
| 1081 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1082 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 1083 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | /** |
| 1087 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1088 | * @instance: Adapter soft state |
| 1089 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1090 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1091 | * |
| 1092 | * 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] | 1093 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1094 | * Used to issue ioctl commands. |
| 1095 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1096 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1097 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1098 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1099 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1100 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1101 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1102 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1103 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1104 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1105 | __func__, __LINE__); |
| 1106 | return DCMD_NOT_FIRED; |
| 1107 | } |
| 1108 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1109 | instance->instancet->issue_dcmd(instance, cmd); |
| 1110 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1111 | if (timeout) { |
| 1112 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1113 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1114 | if (!ret) { |
Shivasharan S | 2ce4350 | 2019-05-07 10:05:38 -0700 | [diff] [blame] | 1115 | dev_err(&instance->pdev->dev, |
| 1116 | "DCMD(opcode: 0x%x) is timed out, func:%s\n", |
| 1117 | cmd->frame->dcmd.opcode, __func__); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1118 | return DCMD_TIMEOUT; |
| 1119 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1120 | } else |
| 1121 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1122 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1123 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1124 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1125 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1130 | * @instance: Adapter soft state |
| 1131 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1132 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1133 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1134 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1135 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1136 | * cmd and waits for return status. |
| 1137 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1138 | */ |
| 1139 | static int |
| 1140 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1141 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1142 | { |
| 1143 | struct megasas_cmd *cmd; |
| 1144 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1145 | int ret = 0; |
Shivasharan S | 2ce4350 | 2019-05-07 10:05:38 -0700 | [diff] [blame] | 1146 | u32 opcode; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1147 | |
| 1148 | cmd = megasas_get_cmd(instance); |
| 1149 | |
| 1150 | if (!cmd) |
| 1151 | return -1; |
| 1152 | |
| 1153 | abort_fr = &cmd->frame->abort; |
| 1154 | |
| 1155 | /* |
| 1156 | * Prepare and issue the abort frame |
| 1157 | */ |
| 1158 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1159 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1160 | abort_fr->flags = cpu_to_le16(0); |
| 1161 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1162 | abort_fr->abort_mfi_phys_addr_lo = |
| 1163 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1164 | abort_fr->abort_mfi_phys_addr_hi = |
| 1165 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1166 | |
| 1167 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1168 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1169 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1170 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1171 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1172 | __func__, __LINE__); |
| 1173 | return DCMD_NOT_FIRED; |
| 1174 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1175 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1176 | instance->instancet->issue_dcmd(instance, cmd); |
| 1177 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1178 | if (timeout) { |
| 1179 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1180 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1181 | if (!ret) { |
Shivasharan S | 2ce4350 | 2019-05-07 10:05:38 -0700 | [diff] [blame] | 1182 | opcode = cmd_to_abort->frame->dcmd.opcode; |
| 1183 | dev_err(&instance->pdev->dev, |
| 1184 | "Abort(to be aborted DCMD opcode: 0x%x) is timed out func:%s\n", |
| 1185 | opcode, __func__); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1186 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1187 | } |
| 1188 | } else |
| 1189 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1190 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1191 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1192 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1193 | |
| 1194 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1195 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1196 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | /** |
| 1200 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1201 | * @instance: Adapter soft state |
| 1202 | * @scp: SCSI command from the mid-layer |
| 1203 | * @mfi_sgl: SGL to be filled in |
| 1204 | * |
| 1205 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1206 | * it returnes -1. |
| 1207 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1208 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1209 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1210 | union megasas_sgl *mfi_sgl) |
| 1211 | { |
| 1212 | int i; |
| 1213 | int sge_count; |
| 1214 | struct scatterlist *os_sgl; |
| 1215 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1216 | sge_count = scsi_dma_map(scp); |
| 1217 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1218 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1219 | if (sge_count) { |
| 1220 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1221 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1222 | 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] | 1223 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1224 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1225 | return sge_count; |
| 1226 | } |
| 1227 | |
| 1228 | /** |
| 1229 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1230 | * @instance: Adapter soft state |
| 1231 | * @scp: SCSI command from the mid-layer |
| 1232 | * @mfi_sgl: SGL to be filled in |
| 1233 | * |
| 1234 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1235 | * it returnes -1. |
| 1236 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1237 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1238 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1239 | union megasas_sgl *mfi_sgl) |
| 1240 | { |
| 1241 | int i; |
| 1242 | int sge_count; |
| 1243 | struct scatterlist *os_sgl; |
| 1244 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1245 | sge_count = scsi_dma_map(scp); |
| 1246 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1247 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1248 | if (sge_count) { |
| 1249 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1250 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1251 | 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] | 1252 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1253 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1254 | return sge_count; |
| 1255 | } |
| 1256 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1257 | /** |
| 1258 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1259 | * @instance: Adapter soft state |
| 1260 | * @scp: SCSI command from the mid-layer |
| 1261 | * @mfi_sgl: SGL to be filled in |
| 1262 | * |
| 1263 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1264 | * it returnes -1. |
| 1265 | */ |
| 1266 | static int |
| 1267 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1268 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1269 | { |
| 1270 | int i; |
| 1271 | int sge_count; |
| 1272 | struct scatterlist *os_sgl; |
| 1273 | |
| 1274 | sge_count = scsi_dma_map(scp); |
| 1275 | |
| 1276 | if (sge_count) { |
| 1277 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1278 | mfi_sgl->sge_skinny[i].length = |
| 1279 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1280 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1281 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1282 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | return sge_count; |
| 1286 | } |
| 1287 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1288 | /** |
| 1289 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1290 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1291 | * @sge_count : number of sg elements |
| 1292 | * |
| 1293 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1294 | */ |
| 1295 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1296 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1297 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1298 | { |
| 1299 | int num_cnt; |
| 1300 | int sge_bytes; |
| 1301 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1302 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1303 | |
| 1304 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1305 | sizeof(struct megasas_sge32); |
| 1306 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1307 | if (instance->flag_ieee) { |
| 1308 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1309 | } |
| 1310 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1311 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1312 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1313 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1314 | * 1 SGEs for 64-bit SGLs and |
| 1315 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1316 | */ |
| 1317 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1318 | if (instance->flag_ieee == 1) { |
| 1319 | num_cnt = sge_count - 1; |
| 1320 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1321 | num_cnt = sge_count - 1; |
| 1322 | else |
| 1323 | num_cnt = sge_count - 2; |
| 1324 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1325 | if (instance->flag_ieee == 1) { |
| 1326 | num_cnt = sge_count - 1; |
| 1327 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1328 | num_cnt = sge_count - 2; |
| 1329 | else |
| 1330 | num_cnt = sge_count - 3; |
| 1331 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1332 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1333 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1334 | sge_bytes = sge_sz * num_cnt; |
| 1335 | |
| 1336 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1337 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1338 | } |
| 1339 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1340 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1341 | |
| 1342 | if (frame_count > 7) |
| 1343 | frame_count = 8; |
| 1344 | return frame_count; |
| 1345 | } |
| 1346 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1347 | /** |
| 1348 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1349 | * @instance: Adapter soft state |
| 1350 | * @scp: SCSI command |
| 1351 | * @cmd: Command to be prepared in |
| 1352 | * |
| 1353 | * This function prepares CDB commands. These are typcially pass-through |
| 1354 | * commands to the devices. |
| 1355 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1356 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1357 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1358 | struct megasas_cmd *cmd) |
| 1359 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1360 | u32 is_logical; |
| 1361 | u32 device_id; |
| 1362 | u16 flags = 0; |
| 1363 | struct megasas_pthru_frame *pthru; |
| 1364 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1365 | is_logical = MEGASAS_IS_LOGICAL(scp->device); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1366 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1367 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1368 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1369 | if (scp->sc_data_direction == DMA_TO_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1370 | flags = MFI_FRAME_DIR_WRITE; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1371 | else if (scp->sc_data_direction == DMA_FROM_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1372 | flags = MFI_FRAME_DIR_READ; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1373 | else if (scp->sc_data_direction == DMA_NONE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1374 | flags = MFI_FRAME_DIR_NONE; |
| 1375 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1376 | if (instance->flag_ieee == 1) { |
| 1377 | flags |= MFI_FRAME_IEEE; |
| 1378 | } |
| 1379 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1380 | /* |
| 1381 | * Prepare the DCDB frame |
| 1382 | */ |
| 1383 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1384 | pthru->cmd_status = 0x0; |
| 1385 | pthru->scsi_status = 0x0; |
| 1386 | pthru->target_id = device_id; |
| 1387 | pthru->lun = scp->device->lun; |
| 1388 | pthru->cdb_len = scp->cmd_len; |
| 1389 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1390 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1391 | pthru->flags = cpu_to_le16(flags); |
| 1392 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1393 | |
| 1394 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1395 | |
| 1396 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1397 | * If the command is for the tape device, set the |
| 1398 | * pthru timeout to the os layer timeout value. |
| 1399 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1400 | if (scp->device->type == TYPE_TAPE) { |
| 1401 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1402 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1403 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1404 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1408 | * Construct SGL |
| 1409 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1410 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1411 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1412 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1413 | &pthru->sgl); |
| 1414 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1415 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1416 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1417 | &pthru->sgl); |
| 1418 | } else |
| 1419 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1420 | &pthru->sgl); |
| 1421 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1422 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1423 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1424 | pthru->sge_count); |
| 1425 | return 0; |
| 1426 | } |
| 1427 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1428 | /* |
| 1429 | * Sense info specific |
| 1430 | */ |
| 1431 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1432 | pthru->sense_buf_phys_addr_hi = |
| 1433 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1434 | pthru->sense_buf_phys_addr_lo = |
| 1435 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1436 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1437 | /* |
| 1438 | * Compute the total number of frames this command consumes. FW uses |
| 1439 | * this number to pull sufficient number of frames from host memory. |
| 1440 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1441 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1442 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1443 | |
| 1444 | return cmd->frame_count; |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1449 | * @instance: Adapter soft state |
| 1450 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1451 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1452 | * |
| 1453 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1454 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1455 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1456 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1457 | struct megasas_cmd *cmd) |
| 1458 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1459 | u32 device_id; |
| 1460 | u8 sc = scp->cmnd[0]; |
| 1461 | u16 flags = 0; |
| 1462 | struct megasas_io_frame *ldio; |
| 1463 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1464 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1465 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1466 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1467 | if (scp->sc_data_direction == DMA_TO_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1468 | flags = MFI_FRAME_DIR_WRITE; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1469 | else if (scp->sc_data_direction == DMA_FROM_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1470 | flags = MFI_FRAME_DIR_READ; |
| 1471 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1472 | if (instance->flag_ieee == 1) { |
| 1473 | flags |= MFI_FRAME_IEEE; |
| 1474 | } |
| 1475 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1476 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1477 | * 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] | 1478 | */ |
| 1479 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1480 | ldio->cmd_status = 0x0; |
| 1481 | ldio->scsi_status = 0x0; |
| 1482 | ldio->target_id = device_id; |
| 1483 | ldio->timeout = 0; |
| 1484 | ldio->reserved_0 = 0; |
| 1485 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1486 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1487 | ldio->start_lba_hi = 0; |
| 1488 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1489 | |
| 1490 | /* |
| 1491 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1492 | */ |
| 1493 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1494 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1495 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1496 | ((u32) scp->cmnd[2] << 8) | |
| 1497 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1498 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1499 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /* |
| 1503 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1504 | */ |
| 1505 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1506 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1507 | ((u32) scp->cmnd[7] << 8)); |
| 1508 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1509 | ((u32) scp->cmnd[3] << 16) | |
| 1510 | ((u32) scp->cmnd[4] << 8) | |
| 1511 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | /* |
| 1515 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1516 | */ |
| 1517 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1518 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1519 | ((u32) scp->cmnd[7] << 16) | |
| 1520 | ((u32) scp->cmnd[8] << 8) | |
| 1521 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1522 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1523 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1524 | ((u32) scp->cmnd[3] << 16) | |
| 1525 | ((u32) scp->cmnd[4] << 8) | |
| 1526 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | /* |
| 1530 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1531 | */ |
| 1532 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1533 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1534 | ((u32) scp->cmnd[11] << 16) | |
| 1535 | ((u32) scp->cmnd[12] << 8) | |
| 1536 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1537 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1538 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1539 | ((u32) scp->cmnd[7] << 16) | |
| 1540 | ((u32) scp->cmnd[8] << 8) | |
| 1541 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1542 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1543 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1544 | ((u32) scp->cmnd[3] << 16) | |
| 1545 | ((u32) scp->cmnd[4] << 8) | |
| 1546 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1547 | |
| 1548 | } |
| 1549 | |
| 1550 | /* |
| 1551 | * Construct SGL |
| 1552 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1553 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1554 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1555 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1556 | &ldio->sgl); |
| 1557 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1558 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1559 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1560 | } else |
| 1561 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1562 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1563 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1564 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1565 | ldio->sge_count); |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1569 | /* |
| 1570 | * Sense info specific |
| 1571 | */ |
| 1572 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1573 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1574 | 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] | 1575 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1576 | /* |
| 1577 | * Compute the total number of frames this command consumes. FW uses |
| 1578 | * this number to pull sufficient number of frames from host memory. |
| 1579 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1580 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1581 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1582 | |
| 1583 | return cmd->frame_count; |
| 1584 | } |
| 1585 | |
| 1586 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1587 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1588 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1589 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1590 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1591 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1592 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1593 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1594 | int ret; |
| 1595 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1596 | switch (cmd->cmnd[0]) { |
| 1597 | case READ_10: |
| 1598 | case WRITE_10: |
| 1599 | case READ_12: |
| 1600 | case WRITE_12: |
| 1601 | case READ_6: |
| 1602 | case WRITE_6: |
| 1603 | case READ_16: |
| 1604 | case WRITE_16: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1605 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1606 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1607 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1608 | default: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1609 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1610 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1611 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1612 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1613 | } |
| 1614 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1615 | /** |
| 1616 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1617 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1618 | * @instance: Adapter soft state |
| 1619 | */ |
| 1620 | static inline void |
| 1621 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1622 | { |
| 1623 | struct megasas_cmd *cmd; |
| 1624 | int i,n; |
| 1625 | union megasas_sgl *mfi_sgl; |
| 1626 | struct megasas_io_frame *ldio; |
| 1627 | struct megasas_pthru_frame *pthru; |
| 1628 | u32 sgcount; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 1629 | u16 max_cmd = instance->max_fw_cmds; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1630 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1631 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1632 | 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] | 1633 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1634 | 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] | 1635 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1636 | 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] | 1637 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1638 | 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] | 1639 | for (i = 0; i < max_cmd; i++) { |
| 1640 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1641 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1642 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1643 | 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] | 1644 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1645 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1646 | mfi_sgl = &ldio->sgl; |
| 1647 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1648 | 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] | 1649 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1650 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1651 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1652 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1653 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1654 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1655 | mfi_sgl = &pthru->sgl; |
| 1656 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1657 | 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] | 1658 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1659 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1660 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1661 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1662 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1663 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1664 | for (n = 0; n < sgcount; n++) { |
| 1665 | if (IS_DMA64) |
| 1666 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1667 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1668 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1669 | else |
| 1670 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1671 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1672 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1673 | } |
| 1674 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1675 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1676 | 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] | 1677 | for (i = 0; i < max_cmd; i++) { |
| 1678 | |
| 1679 | cmd = instance->cmd_list[i]; |
| 1680 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1681 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1682 | 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] | 1683 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1684 | 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] | 1685 | } |
| 1686 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1687 | u32 |
| 1688 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1689 | struct scsi_cmnd *scmd) |
| 1690 | { |
| 1691 | struct megasas_cmd *cmd; |
| 1692 | u32 frame_count; |
| 1693 | |
| 1694 | cmd = megasas_get_cmd(instance); |
| 1695 | if (!cmd) |
| 1696 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1697 | |
| 1698 | /* |
| 1699 | * Logical drive command |
| 1700 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1701 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1702 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1703 | else |
| 1704 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1705 | |
| 1706 | if (!frame_count) |
| 1707 | goto out_return_cmd; |
| 1708 | |
| 1709 | cmd->scmd = scmd; |
| 1710 | scmd->SCp.ptr = (char *)cmd; |
| 1711 | |
| 1712 | /* |
| 1713 | * Issue the command to the FW |
| 1714 | */ |
| 1715 | atomic_inc(&instance->fw_outstanding); |
| 1716 | |
| 1717 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1718 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1719 | |
| 1720 | return 0; |
| 1721 | out_return_cmd: |
| 1722 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1723 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1727 | /** |
| 1728 | * megasas_queue_command - Queue entry point |
| 1729 | * @scmd: SCSI command to be queued |
| 1730 | * @done: Callback entry point |
| 1731 | */ |
| 1732 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1733 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1734 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1735 | struct megasas_instance *instance; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1736 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1737 | |
| 1738 | instance = (struct megasas_instance *) |
| 1739 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1740 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1741 | if (instance->unload == 1) { |
| 1742 | scmd->result = DID_NO_CONNECT << 16; |
| 1743 | scmd->scsi_done(scmd); |
| 1744 | return 0; |
| 1745 | } |
| 1746 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1747 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1748 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1749 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1750 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1751 | /* Check for an mpio path and adjust behavior */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1752 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1753 | if (megasas_check_mpio_paths(instance, scmd) == |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 1754 | (DID_REQUEUE << 16)) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1755 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1756 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1757 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1758 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1759 | return 0; |
| 1760 | } |
| 1761 | } |
| 1762 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1763 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1764 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1765 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1766 | return 0; |
| 1767 | } |
| 1768 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1769 | mr_device_priv_data = scmd->device->hostdata; |
| 1770 | if (!mr_device_priv_data) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1771 | scmd->result = DID_NO_CONNECT << 16; |
| 1772 | scmd->scsi_done(scmd); |
| 1773 | return 0; |
| 1774 | } |
| 1775 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1776 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1777 | return SCSI_MLQUEUE_HOST_BUSY; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1778 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1779 | if (mr_device_priv_data->tm_busy) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1780 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1781 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1782 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1783 | scmd->result = 0; |
| 1784 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1785 | if (MEGASAS_IS_LOGICAL(scmd->device) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1786 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1787 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1788 | scmd->result = DID_BAD_TARGET << 16; |
| 1789 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1790 | } |
| 1791 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1792 | if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && |
| 1793 | MEGASAS_IS_LOGICAL(scmd->device) && |
| 1794 | (!instance->fw_sync_cache_support)) { |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1795 | scmd->result = DID_OK << 16; |
| 1796 | goto out_done; |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1797 | } |
| 1798 | |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1799 | return instance->instancet->build_and_issue_cmd(instance, scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1800 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1801 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1802 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1803 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1804 | } |
| 1805 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1806 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1807 | { |
| 1808 | int i; |
| 1809 | |
| 1810 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1811 | |
| 1812 | if ((megasas_mgmt_info.instance[i]) && |
| 1813 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1814 | return megasas_mgmt_info.instance[i]; |
| 1815 | } |
| 1816 | |
| 1817 | return NULL; |
| 1818 | } |
| 1819 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1820 | /* |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1821 | * megasas_set_dynamic_target_properties - |
| 1822 | * Device property set by driver may not be static and it is required to be |
| 1823 | * updated after OCR |
| 1824 | * |
| 1825 | * set tm_capable. |
| 1826 | * set dma alignment (only for eedp protection enable vd). |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1827 | * |
| 1828 | * @sdev: OS provided scsi device |
| 1829 | * |
| 1830 | * Returns void |
| 1831 | */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 1832 | void megasas_set_dynamic_target_properties(struct scsi_device *sdev, |
| 1833 | bool is_target_prop) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1834 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1835 | u16 pd_index = 0, ld; |
| 1836 | u32 device_id; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1837 | struct megasas_instance *instance; |
| 1838 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1839 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1840 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1841 | struct MR_LD_RAID *raid; |
| 1842 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1843 | |
| 1844 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1845 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1846 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1847 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1848 | if (!fusion || !mr_device_priv_data) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1849 | return; |
| 1850 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1851 | if (MEGASAS_IS_LOGICAL(sdev)) { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1852 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1853 | + sdev->id; |
| 1854 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1855 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1856 | if (ld >= instance->fw_supported_vd_count) |
| 1857 | return; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1858 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1859 | |
| 1860 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1861 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1862 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1863 | mr_device_priv_data->is_tm_capable = |
| 1864 | raid->capability.tmCapable; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1865 | } else if (instance->use_seqnum_jbod_fp) { |
| 1866 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1867 | sdev->id; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1868 | pd_sync = (void *)fusion->pd_seq_sync |
| 1869 | [(instance->pd_seq_map_id - 1) & 1]; |
| 1870 | mr_device_priv_data->is_tm_capable = |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1871 | pd_sync->seq[pd_index].capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1872 | } |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 1873 | |
| 1874 | if (is_target_prop && instance->tgt_prop->reset_tmo) { |
| 1875 | /* |
| 1876 | * If FW provides a target reset timeout value, driver will use |
| 1877 | * it. If not set, fallback to default values. |
| 1878 | */ |
| 1879 | mr_device_priv_data->target_reset_tmo = |
| 1880 | min_t(u8, instance->max_reset_tmo, |
| 1881 | instance->tgt_prop->reset_tmo); |
| 1882 | mr_device_priv_data->task_abort_tmo = instance->task_abort_tmo; |
| 1883 | } else { |
| 1884 | mr_device_priv_data->target_reset_tmo = |
| 1885 | MEGASAS_DEFAULT_TM_TIMEOUT; |
| 1886 | mr_device_priv_data->task_abort_tmo = |
| 1887 | MEGASAS_DEFAULT_TM_TIMEOUT; |
| 1888 | } |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1889 | } |
| 1890 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1891 | /* |
| 1892 | * megasas_set_nvme_device_properties - |
| 1893 | * set nomerges=2 |
| 1894 | * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K). |
| 1895 | * set maximum io transfer = MDTS of NVME device provided by MR firmware. |
| 1896 | * |
| 1897 | * MR firmware provides value in KB. Caller of this function converts |
| 1898 | * kb into bytes. |
| 1899 | * |
| 1900 | * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size, |
| 1901 | * MR firmware provides value 128 as (32 * 4K) = 128K. |
| 1902 | * |
| 1903 | * @sdev: scsi device |
| 1904 | * @max_io_size: maximum io transfer size |
| 1905 | * |
| 1906 | */ |
| 1907 | static inline void |
| 1908 | 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] | 1909 | { |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1910 | struct megasas_instance *instance; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1911 | u32 mr_nvme_pg_size; |
| 1912 | |
| 1913 | instance = (struct megasas_instance *)sdev->host->hostdata; |
| 1914 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1915 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1916 | |
| 1917 | blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512)); |
| 1918 | |
Bart Van Assche | 8b904b5 | 2018-03-07 17:10:10 -0800 | [diff] [blame] | 1919 | blk_queue_flag_set(QUEUE_FLAG_NOMERGES, sdev->request_queue); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1920 | blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1); |
| 1921 | } |
| 1922 | |
| 1923 | |
| 1924 | /* |
| 1925 | * megasas_set_static_target_properties - |
| 1926 | * Device property set by driver are static and it is not required to be |
| 1927 | * updated after OCR. |
| 1928 | * |
| 1929 | * set io timeout |
| 1930 | * set device queue depth |
| 1931 | * set nvme device properties. see - megasas_set_nvme_device_properties |
| 1932 | * |
| 1933 | * @sdev: scsi device |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1934 | * @is_target_prop true, if fw provided target properties. |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1935 | */ |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1936 | static void megasas_set_static_target_properties(struct scsi_device *sdev, |
| 1937 | bool is_target_prop) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1938 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1939 | u8 interface_type; |
| 1940 | u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN; |
| 1941 | u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1942 | u32 tgt_device_qd; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1943 | struct megasas_instance *instance; |
| 1944 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1945 | |
| 1946 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1947 | mr_device_priv_data = sdev->hostdata; |
| 1948 | interface_type = mr_device_priv_data->interface_type; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1949 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1950 | /* |
| 1951 | * The RAID firmware may require extended timeouts. |
| 1952 | */ |
| 1953 | blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1954 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1955 | switch (interface_type) { |
| 1956 | case SAS_PD: |
| 1957 | device_qd = MEGASAS_SAS_QD; |
| 1958 | break; |
| 1959 | case SATA_PD: |
| 1960 | device_qd = MEGASAS_SATA_QD; |
| 1961 | break; |
| 1962 | case NVME_PD: |
| 1963 | device_qd = MEGASAS_NVME_QD; |
| 1964 | break; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1965 | } |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1966 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1967 | if (is_target_prop) { |
| 1968 | tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth); |
| 1969 | if (tgt_device_qd && |
| 1970 | (tgt_device_qd <= instance->host->can_queue)) |
| 1971 | device_qd = tgt_device_qd; |
| 1972 | |
| 1973 | /* max_io_size_kb will be set to non zero for |
| 1974 | * nvme based vd and syspd. |
| 1975 | */ |
| 1976 | max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb); |
| 1977 | } |
| 1978 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1979 | if (instance->nvme_page_size && max_io_size_kb) |
| 1980 | megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10)); |
| 1981 | |
| 1982 | scsi_change_queue_depth(sdev, device_qd); |
| 1983 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1984 | } |
| 1985 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1986 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1987 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1988 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1989 | u16 pd_index = 0; |
| 1990 | struct megasas_instance *instance; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1991 | int ret_target_prop = DCMD_FAILED; |
| 1992 | bool is_target_prop = false; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1993 | |
| 1994 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 1995 | if (instance->pd_list_not_supported) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1996 | if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 1997 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1998 | sdev->id; |
| 1999 | if (instance->pd_list[pd_index].driveState != |
| 2000 | MR_PD_STATE_SYSTEM) |
| 2001 | return -ENXIO; |
| 2002 | } |
| 2003 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2004 | |
Shivasharan S | 149c575 | 2018-01-05 05:27:42 -0800 | [diff] [blame] | 2005 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2006 | /* Send DCMD to Firmware and cache the information */ |
| 2007 | if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev)) |
| 2008 | megasas_get_pd_info(instance, sdev); |
| 2009 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 2010 | /* Some ventura firmware may not have instance->nvme_page_size set. |
| 2011 | * Do not send MR_DCMD_DRV_GET_TARGET_PROP |
| 2012 | */ |
| 2013 | if ((instance->tgt_prop) && (instance->nvme_page_size)) |
| 2014 | ret_target_prop = megasas_get_target_prop(instance, sdev); |
| 2015 | |
| 2016 | is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false; |
| 2017 | megasas_set_static_target_properties(sdev, is_target_prop); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2018 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2019 | /* This sdev property may change post OCR */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 2020 | megasas_set_dynamic_target_properties(sdev, is_target_prop); |
| 2021 | |
| 2022 | mutex_unlock(&instance->reset_mutex); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 2023 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2024 | return 0; |
| 2025 | } |
| 2026 | |
| 2027 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 2028 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2029 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2030 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2031 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2032 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2033 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 2034 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2035 | /* |
| 2036 | * Open the OS scan to the SYSTEM PD |
| 2037 | */ |
| 2038 | pd_index = |
| 2039 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 2040 | sdev->id; |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 2041 | if ((instance->pd_list_not_supported || |
| 2042 | instance->pd_list[pd_index].driveState == |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 2043 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2044 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2045 | } |
| 2046 | return -ENXIO; |
| 2047 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2048 | |
| 2049 | scan_target: |
| 2050 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 2051 | GFP_KERNEL); |
| 2052 | if (!mr_device_priv_data) |
| 2053 | return -ENOMEM; |
| 2054 | sdev->hostdata = mr_device_priv_data; |
Shivasharan S | 49524b3 | 2017-03-10 03:22:13 -0800 | [diff] [blame] | 2055 | |
| 2056 | atomic_set(&mr_device_priv_data->r1_ldio_hint, |
| 2057 | instance->r1_ldio_hint_default); |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2058 | return 0; |
| 2059 | } |
| 2060 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2061 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 2062 | { |
| 2063 | kfree(sdev->hostdata); |
| 2064 | sdev->hostdata = NULL; |
| 2065 | } |
| 2066 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2067 | /* |
| 2068 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 2069 | * kill adapter |
| 2070 | * @instance: Adapter soft state |
| 2071 | * |
| 2072 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 2073 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2074 | { |
| 2075 | int i; |
| 2076 | struct megasas_cmd *cmd_mfi; |
| 2077 | struct megasas_cmd_fusion *cmd_fusion; |
| 2078 | struct fusion_context *fusion = instance->ctrl_context; |
| 2079 | |
| 2080 | /* Find all outstanding ioctls */ |
| 2081 | if (fusion) { |
| 2082 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2083 | cmd_fusion = fusion->cmd_list[i]; |
| 2084 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 2085 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 2086 | if (cmd_mfi->sync_cmd && |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2087 | (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) { |
| 2088 | cmd_mfi->frame->hdr.cmd_status = |
| 2089 | MFI_STAT_WRONG_STATE; |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2090 | megasas_complete_cmd(instance, |
| 2091 | cmd_mfi, DID_OK); |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2092 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2093 | } |
| 2094 | } |
| 2095 | } else { |
| 2096 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2097 | cmd_mfi = instance->cmd_list[i]; |
| 2098 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 2099 | MFI_CMD_ABORT) |
| 2100 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 2101 | } |
| 2102 | } |
| 2103 | } |
| 2104 | |
| 2105 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2106 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2107 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2108 | /* 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] | 2109 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2110 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 2111 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2112 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2113 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2114 | (instance->adapter_type != MFI_SERIES)) { |
Shivasharan S | 5acad9b | 2018-10-16 23:37:47 -0700 | [diff] [blame] | 2115 | if (!instance->requestorId) { |
| 2116 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
| 2117 | /* Flush */ |
| 2118 | readl(&instance->reg_set->doorbell); |
| 2119 | } |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 2120 | if (instance->requestorId && instance->peerIsPresent) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2121 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2122 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2123 | writel(MFI_STOP_ADP, |
| 2124 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2125 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2126 | /* Complete outstanding ioctls when adapter is killed */ |
| 2127 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 2132 | * restored to max value |
| 2133 | * @instance: Adapter soft state |
| 2134 | * |
| 2135 | */ |
| 2136 | void |
| 2137 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 2138 | { |
| 2139 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 2140 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2141 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2142 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 2143 | && atomic_read(&instance->fw_outstanding) < |
| 2144 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2145 | |
| 2146 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2147 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2148 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2149 | instance->host->can_queue = instance->cur_can_queue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2150 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2154 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2155 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 2156 | * @instance_addr: Address of adapter soft state |
| 2157 | * |
| 2158 | * Tasklet to complete cmds |
| 2159 | */ |
| 2160 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 2161 | { |
| 2162 | u32 producer; |
| 2163 | u32 consumer; |
| 2164 | u32 context; |
| 2165 | struct megasas_cmd *cmd; |
| 2166 | struct megasas_instance *instance = |
| 2167 | (struct megasas_instance *)instance_addr; |
| 2168 | unsigned long flags; |
| 2169 | |
| 2170 | /* If we have already declared adapter dead, donot complete cmds */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2171 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2172 | return; |
| 2173 | |
| 2174 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 2175 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2176 | producer = le32_to_cpu(*instance->producer); |
| 2177 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2178 | |
| 2179 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2180 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2181 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2182 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2183 | context); |
| 2184 | BUG(); |
| 2185 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2186 | |
| 2187 | cmd = instance->cmd_list[context]; |
| 2188 | |
| 2189 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 2190 | |
| 2191 | consumer++; |
| 2192 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 2193 | consumer = 0; |
| 2194 | } |
| 2195 | } |
| 2196 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2197 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2198 | |
| 2199 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 2200 | |
| 2201 | /* |
| 2202 | * Check if we can restore can_queue |
| 2203 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2204 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2205 | } |
| 2206 | |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2207 | static void megasas_sriov_heartbeat_handler(struct timer_list *t); |
| 2208 | |
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 | * megasas_start_timer - Initializes sriov heartbeat timer object |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2211 | * @instance: Adapter soft state |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2212 | * |
| 2213 | */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2214 | void megasas_start_timer(struct megasas_instance *instance) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2215 | { |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2216 | struct timer_list *timer = &instance->sriov_heartbeat_timer; |
| 2217 | |
| 2218 | timer_setup(timer, megasas_sriov_heartbeat_handler, 0); |
| 2219 | timer->expires = jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2220 | add_timer(timer); |
| 2221 | } |
| 2222 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2223 | static void |
| 2224 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2225 | |
| 2226 | static void |
| 2227 | process_fw_state_change_wq(struct work_struct *work); |
| 2228 | |
| 2229 | void megasas_do_ocr(struct megasas_instance *instance) |
| 2230 | { |
| 2231 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2232 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2233 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2234 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2235 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2236 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2237 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2238 | instance->issuepend_done = 0; |
| 2239 | |
| 2240 | atomic_set(&instance->fw_outstanding, 0); |
| 2241 | megasas_internal_reset_defer_cmds(instance); |
| 2242 | process_fw_state_change_wq(&instance->work_init); |
| 2243 | } |
| 2244 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2245 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2246 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2247 | { |
| 2248 | struct megasas_cmd *cmd; |
| 2249 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2250 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2251 | dma_addr_t new_affiliation_111_h; |
| 2252 | int ld, retval = 0; |
| 2253 | u8 thisVf; |
| 2254 | |
| 2255 | cmd = megasas_get_cmd(instance); |
| 2256 | |
| 2257 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2258 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2259 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2260 | instance->host->host_no); |
| 2261 | return -ENOMEM; |
| 2262 | } |
| 2263 | |
| 2264 | dcmd = &cmd->frame->dcmd; |
| 2265 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2266 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2267 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2268 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2269 | megasas_return_cmd(instance, cmd); |
| 2270 | return -ENOMEM; |
| 2271 | } |
| 2272 | |
| 2273 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2274 | memset(instance->vf_affiliation_111, 0, |
| 2275 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2276 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2277 | new_affiliation_111 = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2278 | dma_alloc_coherent(&instance->pdev->dev, |
| 2279 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2280 | &new_affiliation_111_h, GFP_KERNEL); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2281 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2282 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2283 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2284 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2285 | megasas_return_cmd(instance, cmd); |
| 2286 | return -ENOMEM; |
| 2287 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2291 | |
| 2292 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2293 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2294 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2295 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2296 | dcmd->timeout = 0; |
| 2297 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2298 | dcmd->data_xfer_len = |
| 2299 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2300 | 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] | 2301 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2302 | if (initial) |
| 2303 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2304 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2305 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2306 | dcmd->sgl.sge32[0].phys_addr = |
| 2307 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2308 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2309 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2310 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2311 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2312 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2313 | "scsi%d\n", instance->host->host_no); |
| 2314 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2315 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2316 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2317 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2318 | dcmd->cmd_status, instance->host->host_no); |
| 2319 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2320 | goto out; |
| 2321 | } |
| 2322 | |
| 2323 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2324 | thisVf = new_affiliation_111->thisVf; |
| 2325 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2326 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2327 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2328 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2329 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2330 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2331 | memcpy(instance->vf_affiliation_111, |
| 2332 | new_affiliation_111, |
| 2333 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2334 | retval = 1; |
| 2335 | goto out; |
| 2336 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2337 | } |
| 2338 | out: |
| 2339 | if (new_affiliation_111) { |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 2340 | dma_free_coherent(&instance->pdev->dev, |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2341 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2342 | new_affiliation_111, |
| 2343 | new_affiliation_111_h); |
| 2344 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2345 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2346 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2347 | |
| 2348 | return retval; |
| 2349 | } |
| 2350 | |
| 2351 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2352 | int initial) |
| 2353 | { |
| 2354 | struct megasas_cmd *cmd; |
| 2355 | struct megasas_dcmd_frame *dcmd; |
| 2356 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2357 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2358 | dma_addr_t new_affiliation_h; |
| 2359 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2360 | u8 thisVf; |
| 2361 | |
| 2362 | cmd = megasas_get_cmd(instance); |
| 2363 | |
| 2364 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2365 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2366 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2367 | instance->host->host_no); |
| 2368 | return -ENOMEM; |
| 2369 | } |
| 2370 | |
| 2371 | dcmd = &cmd->frame->dcmd; |
| 2372 | |
| 2373 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2374 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2375 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2376 | megasas_return_cmd(instance, cmd); |
| 2377 | return -ENOMEM; |
| 2378 | } |
| 2379 | |
| 2380 | if (initial) |
| 2381 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2382 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2383 | else { |
| 2384 | new_affiliation = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2385 | dma_alloc_coherent(&instance->pdev->dev, |
| 2386 | (MAX_LOGICAL_DRIVES + 1) * sizeof(struct MR_LD_VF_AFFILIATION), |
| 2387 | &new_affiliation_h, GFP_KERNEL); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2388 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2389 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2390 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2391 | instance->host->host_no); |
| 2392 | megasas_return_cmd(instance, cmd); |
| 2393 | return -ENOMEM; |
| 2394 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2398 | |
| 2399 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2400 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2401 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2402 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2403 | dcmd->timeout = 0; |
| 2404 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2405 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2406 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2407 | 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] | 2408 | |
| 2409 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2410 | dcmd->sgl.sge32[0].phys_addr = |
| 2411 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2412 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2413 | dcmd->sgl.sge32[0].phys_addr = |
| 2414 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2415 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2416 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2417 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2418 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2419 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2420 | "scsi%d\n", instance->host->host_no); |
| 2421 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2422 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2423 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2424 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2425 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2426 | dcmd->cmd_status, instance->host->host_no); |
| 2427 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2428 | goto out; |
| 2429 | } |
| 2430 | |
| 2431 | if (!initial) { |
| 2432 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2433 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2434 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2435 | instance->host->host_no); |
| 2436 | retval = 1; |
| 2437 | goto out; |
| 2438 | } |
| 2439 | newmap = new_affiliation->map; |
| 2440 | savedmap = instance->vf_affiliation->map; |
| 2441 | thisVf = new_affiliation->thisVf; |
| 2442 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2443 | found = 0; |
| 2444 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2445 | j++) { |
| 2446 | if (newmap->ref.targetId == |
| 2447 | savedmap->ref.targetId) { |
| 2448 | found = 1; |
| 2449 | if (newmap->policy[thisVf] != |
| 2450 | savedmap->policy[thisVf]) { |
| 2451 | doscan = 1; |
| 2452 | goto out; |
| 2453 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2454 | } |
| 2455 | savedmap = (struct MR_LD_VF_MAP *) |
| 2456 | ((unsigned char *)savedmap + |
| 2457 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2458 | } |
| 2459 | if (!found && newmap->policy[thisVf] != |
| 2460 | MR_LD_ACCESS_HIDDEN) { |
| 2461 | doscan = 1; |
| 2462 | goto out; |
| 2463 | } |
| 2464 | newmap = (struct MR_LD_VF_MAP *) |
| 2465 | ((unsigned char *)newmap + newmap->size); |
| 2466 | } |
| 2467 | |
| 2468 | newmap = new_affiliation->map; |
| 2469 | savedmap = instance->vf_affiliation->map; |
| 2470 | |
| 2471 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2472 | found = 0; |
| 2473 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2474 | if (savedmap->ref.targetId == |
| 2475 | newmap->ref.targetId) { |
| 2476 | found = 1; |
| 2477 | if (savedmap->policy[thisVf] != |
| 2478 | newmap->policy[thisVf]) { |
| 2479 | doscan = 1; |
| 2480 | goto out; |
| 2481 | } |
| 2482 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2483 | newmap = (struct MR_LD_VF_MAP *) |
| 2484 | ((unsigned char *)newmap + |
| 2485 | newmap->size); |
| 2486 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2487 | if (!found && savedmap->policy[thisVf] != |
| 2488 | MR_LD_ACCESS_HIDDEN) { |
| 2489 | doscan = 1; |
| 2490 | goto out; |
| 2491 | } |
| 2492 | savedmap = (struct MR_LD_VF_MAP *) |
| 2493 | ((unsigned char *)savedmap + |
| 2494 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2495 | } |
| 2496 | } |
| 2497 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2498 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2499 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2500 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2501 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2502 | new_affiliation->size); |
| 2503 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2504 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2505 | |
| 2506 | if (new_affiliation) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 2507 | dma_free_coherent(&instance->pdev->dev, |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2508 | (MAX_LOGICAL_DRIVES + 1) * |
| 2509 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2510 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2511 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2512 | |
| 2513 | return retval; |
| 2514 | } |
| 2515 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2516 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2517 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2518 | int initial) |
| 2519 | { |
| 2520 | int retval; |
| 2521 | |
| 2522 | if (instance->PlasmaFW111) |
| 2523 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2524 | else |
| 2525 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2526 | return retval; |
| 2527 | } |
| 2528 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2529 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2530 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2531 | int initial) |
| 2532 | { |
| 2533 | struct megasas_cmd *cmd; |
| 2534 | struct megasas_dcmd_frame *dcmd; |
| 2535 | int retval = 0; |
| 2536 | |
| 2537 | cmd = megasas_get_cmd(instance); |
| 2538 | |
| 2539 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2540 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2541 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2542 | instance->host->host_no); |
| 2543 | return -ENOMEM; |
| 2544 | } |
| 2545 | |
| 2546 | dcmd = &cmd->frame->dcmd; |
| 2547 | |
| 2548 | if (initial) { |
| 2549 | instance->hb_host_mem = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2550 | dma_alloc_coherent(&instance->pdev->dev, |
| 2551 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2552 | &instance->hb_host_mem_h, |
| 2553 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2554 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2555 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2556 | " memory for heartbeat host memory for scsi%d\n", |
| 2557 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2558 | retval = -ENOMEM; |
| 2559 | goto out; |
| 2560 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2564 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2565 | 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] | 2566 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2567 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2568 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2569 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2570 | dcmd->timeout = 0; |
| 2571 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2572 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2573 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 2574 | |
| 2575 | megasas_set_dma_settings(instance, dcmd, instance->hb_host_mem_h, |
| 2576 | sizeof(struct MR_CTRL_HB_HOST_MEM)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2577 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2578 | 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] | 2579 | instance->host->host_no); |
| 2580 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2581 | if ((instance->adapter_type != MFI_SERIES) && |
| 2582 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2583 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2584 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2585 | else |
| 2586 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2587 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2588 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2589 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2590 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2591 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2592 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2593 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | out: |
| 2597 | megasas_return_cmd(instance, cmd); |
| 2598 | |
| 2599 | return retval; |
| 2600 | } |
| 2601 | |
| 2602 | /* Handler for SR-IOV heartbeat */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2603 | static void megasas_sriov_heartbeat_handler(struct timer_list *t) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2604 | { |
| 2605 | struct megasas_instance *instance = |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2606 | from_timer(instance, t, sriov_heartbeat_timer); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2607 | |
| 2608 | if (instance->hb_host_mem->HB.fwCounter != |
| 2609 | instance->hb_host_mem->HB.driverCounter) { |
| 2610 | instance->hb_host_mem->HB.driverCounter = |
| 2611 | instance->hb_host_mem->HB.fwCounter; |
| 2612 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2613 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2614 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2615 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2616 | "completed for scsi%d\n", instance->host->host_no); |
| 2617 | schedule_work(&instance->work_init); |
| 2618 | } |
| 2619 | } |
| 2620 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2621 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2622 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2623 | * @instance: Adapter soft state |
| 2624 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2625 | * 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] | 2626 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2627 | * are pending after this time period. It also marks the controller dead. |
| 2628 | */ |
| 2629 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2630 | { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2631 | int i, sl, outstanding; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2632 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2633 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2634 | unsigned long flags; |
| 2635 | struct list_head clist_local; |
| 2636 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2637 | u32 fw_state; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2638 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2639 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2640 | dev_info(&instance->pdev->dev, "%s:%d HBA is killed.\n", |
| 2641 | __func__, __LINE__); |
| 2642 | return FAILED; |
| 2643 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2644 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2645 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2646 | |
| 2647 | INIT_LIST_HEAD(&clist_local); |
| 2648 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2649 | list_splice_init(&instance->internal_reset_pending_q, |
| 2650 | &clist_local); |
| 2651 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2652 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2653 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2654 | for (i = 0; i < wait_time; i++) { |
| 2655 | msleep(1000); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2656 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2657 | break; |
| 2658 | } |
| 2659 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2660 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2661 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2662 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2663 | return FAILED; |
| 2664 | } |
| 2665 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2666 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2667 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2668 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2669 | struct megasas_cmd, list); |
| 2670 | list_del_init(&reset_cmd->list); |
| 2671 | if (reset_cmd->scmd) { |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 2672 | reset_cmd->scmd->result = DID_REQUEUE << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2673 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2674 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2675 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2676 | |
| 2677 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2678 | megasas_return_cmd(instance, reset_cmd); |
| 2679 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2680 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2681 | "reset queue\n", |
| 2682 | reset_cmd); |
| 2683 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2684 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2685 | instance->instancet->fire_cmd(instance, |
| 2686 | reset_cmd->frame_phys_addr, |
| 2687 | 0, instance->reg_set); |
| 2688 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2689 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2690 | "cmds lst\n", |
| 2691 | reset_cmd); |
| 2692 | } |
| 2693 | reset_index++; |
| 2694 | } |
| 2695 | |
| 2696 | return SUCCESS; |
| 2697 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2698 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2699 | for (i = 0; i < resetwaittime; i++) { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2700 | outstanding = atomic_read(&instance->fw_outstanding); |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2701 | |
| 2702 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2703 | break; |
| 2704 | |
| 2705 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2706 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2707 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2708 | /* |
| 2709 | * Call cmd completion routine. Cmd to be |
| 2710 | * be completed directly without depending on isr. |
| 2711 | */ |
| 2712 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | msleep(1000); |
| 2716 | } |
| 2717 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2718 | i = 0; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2719 | outstanding = atomic_read(&instance->fw_outstanding); |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 2720 | fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2721 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2722 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2723 | goto no_outstanding; |
| 2724 | |
| 2725 | if (instance->disableOnlineCtrlReset) |
| 2726 | goto kill_hba_and_failed; |
| 2727 | do { |
| 2728 | if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) { |
| 2729 | dev_info(&instance->pdev->dev, |
Colin Ian King | efc372c | 2019-04-17 14:51:09 +0100 | [diff] [blame] | 2730 | "%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] | 2731 | __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding)); |
| 2732 | if (i == 3) |
| 2733 | goto kill_hba_and_failed; |
| 2734 | megasas_do_ocr(instance); |
| 2735 | |
| 2736 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2737 | dev_info(&instance->pdev->dev, "%s:%d OCR failed and HBA is killed.\n", |
| 2738 | __func__, __LINE__); |
| 2739 | return FAILED; |
| 2740 | } |
| 2741 | dev_info(&instance->pdev->dev, "%s:%d waiting_for_outstanding: after issue OCR.\n", |
| 2742 | __func__, __LINE__); |
| 2743 | |
| 2744 | for (sl = 0; sl < 10; sl++) |
| 2745 | msleep(500); |
| 2746 | |
| 2747 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2748 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 2749 | fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2750 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2751 | goto no_outstanding; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2752 | } |
| 2753 | i++; |
| 2754 | } while (i <= 3); |
| 2755 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2756 | no_outstanding: |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2757 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2758 | dev_info(&instance->pdev->dev, "%s:%d no more pending commands remain after reset handling.\n", |
| 2759 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2760 | return SUCCESS; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2761 | |
| 2762 | kill_hba_and_failed: |
| 2763 | |
| 2764 | /* Reset not supported, kill adapter */ |
| 2765 | dev_info(&instance->pdev->dev, "%s:%d killing adapter scsi%d" |
| 2766 | " disableOnlineCtrlReset %d fw_outstanding %d \n", |
| 2767 | __func__, __LINE__, instance->host->host_no, instance->disableOnlineCtrlReset, |
| 2768 | atomic_read(&instance->fw_outstanding)); |
| 2769 | megasas_dump_pending_frames(instance); |
| 2770 | megaraid_sas_kill_hba(instance); |
| 2771 | |
| 2772 | return FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | /** |
| 2776 | * megasas_generic_reset - Generic reset routine |
| 2777 | * @scmd: Mid-layer SCSI command |
| 2778 | * |
| 2779 | * This routine implements a generic reset handler for device, bus and host |
| 2780 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2781 | * function after they do their specific tasks. |
| 2782 | */ |
| 2783 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2784 | { |
| 2785 | int ret_val; |
| 2786 | struct megasas_instance *instance; |
| 2787 | |
| 2788 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2789 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2790 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2791 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2792 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2793 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2794 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2795 | return FAILED; |
| 2796 | } |
| 2797 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2798 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2799 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2800 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2801 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2802 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2803 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2804 | return ret_val; |
| 2805 | } |
| 2806 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2807 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2808 | * megasas_reset_timer - quiesce the adapter if required |
| 2809 | * @scmd: scsi cmnd |
| 2810 | * |
| 2811 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2812 | * cmd has not been completed within the timeout period. |
| 2813 | */ |
| 2814 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2815 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2816 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2817 | struct megasas_instance *instance; |
| 2818 | unsigned long flags; |
| 2819 | |
| 2820 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 2821 | (scmd_timeout * 2) * HZ)) { |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 2822 | return BLK_EH_DONE; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2825 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2826 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2827 | /* FW is busy, throttle IO */ |
| 2828 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2829 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2830 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2831 | instance->last_time = jiffies; |
| 2832 | instance->flag |= MEGASAS_FW_BUSY; |
| 2833 | |
| 2834 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2835 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2836 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | /** |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2840 | * megasas_dump - This function will print hexdump of provided buffer. |
| 2841 | * @buf: Buffer to be dumped |
| 2842 | * @sz: Size in bytes |
| 2843 | * @format: Different formats of dumping e.g. format=n will |
| 2844 | * cause only 'n' 32 bit words to be dumped in a single |
| 2845 | * line. |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2846 | */ |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2847 | inline void |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2848 | megasas_dump(void *buf, int sz, int format) |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2849 | { |
| 2850 | int i; |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2851 | __le32 *buf_loc = (__le32 *)buf; |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2852 | |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2853 | for (i = 0; i < (sz / sizeof(__le32)); i++) { |
| 2854 | if ((i % format) == 0) { |
| 2855 | if (i != 0) |
| 2856 | printk(KERN_CONT "\n"); |
| 2857 | printk(KERN_CONT "%08x: ", (i * 4)); |
| 2858 | } |
| 2859 | printk(KERN_CONT "%08x ", le32_to_cpu(buf_loc[i])); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2860 | } |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2861 | printk(KERN_CONT "\n"); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2862 | } |
| 2863 | |
| 2864 | /** |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame^] | 2865 | * megasas_dump_reg_set - This function will print hexdump of register set |
| 2866 | * @buf: Buffer to be dumped |
| 2867 | * @sz: Size in bytes |
| 2868 | * @format: Different formats of dumping e.g. format=n will |
| 2869 | * cause only 'n' 32 bit words to be dumped in a |
| 2870 | * single line. |
| 2871 | */ |
| 2872 | inline void |
| 2873 | megasas_dump_reg_set(void __iomem *reg_set) |
| 2874 | { |
| 2875 | unsigned int i, sz = 256; |
| 2876 | u32 __iomem *reg = (u32 __iomem *)reg_set; |
| 2877 | |
| 2878 | for (i = 0; i < (sz / sizeof(u32)); i++) |
| 2879 | printk("%08x: %08x\n", (i * 4), readl(®[i])); |
| 2880 | } |
| 2881 | |
| 2882 | /** |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2883 | * megasas_dump_fusion_io - This function will print key details |
| 2884 | * of SCSI IO |
| 2885 | * @scmd: SCSI command pointer of SCSI IO |
| 2886 | */ |
| 2887 | void |
| 2888 | megasas_dump_fusion_io(struct scsi_cmnd *scmd) |
| 2889 | { |
| 2890 | struct megasas_cmd_fusion *cmd; |
| 2891 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2892 | struct megasas_instance *instance; |
| 2893 | |
| 2894 | cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr; |
| 2895 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2896 | |
| 2897 | scmd_printk(KERN_INFO, scmd, |
| 2898 | "scmd: (0x%p) retries: 0x%x allowed: 0x%x\n", |
| 2899 | scmd, scmd->retries, scmd->allowed); |
| 2900 | scsi_print_command(scmd); |
| 2901 | |
| 2902 | if (cmd) { |
| 2903 | req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc; |
| 2904 | scmd_printk(KERN_INFO, scmd, "Request descriptor details:\n"); |
| 2905 | scmd_printk(KERN_INFO, scmd, |
| 2906 | "RequestFlags:0x%x MSIxIndex:0x%x SMID:0x%x LMID:0x%x DevHandle:0x%x\n", |
| 2907 | req_desc->SCSIIO.RequestFlags, |
| 2908 | req_desc->SCSIIO.MSIxIndex, req_desc->SCSIIO.SMID, |
| 2909 | req_desc->SCSIIO.LMID, req_desc->SCSIIO.DevHandle); |
| 2910 | |
| 2911 | printk(KERN_INFO "IO request frame:\n"); |
| 2912 | megasas_dump(cmd->io_request, |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2913 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE, 8); |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2914 | printk(KERN_INFO "Chain frame:\n"); |
| 2915 | megasas_dump(cmd->sg_frame, |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2916 | instance->max_chain_frame_sz, 8); |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | } |
| 2920 | |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 2921 | /* |
| 2922 | * megasas_dump_sys_regs - This function will dump system registers through |
| 2923 | * sysfs. |
| 2924 | * @reg_set: Pointer to System register set. |
| 2925 | * @buf: Buffer to which output is to be written. |
| 2926 | * @return: Number of bytes written to buffer. |
| 2927 | */ |
| 2928 | static inline ssize_t |
| 2929 | megasas_dump_sys_regs(void __iomem *reg_set, char *buf) |
| 2930 | { |
| 2931 | unsigned int i, sz = 256; |
| 2932 | int bytes_wrote = 0; |
| 2933 | char *loc = (char *)buf; |
| 2934 | u32 __iomem *reg = (u32 __iomem *)reg_set; |
| 2935 | |
| 2936 | for (i = 0; i < sz / sizeof(u32); i++) { |
| 2937 | bytes_wrote += snprintf(loc + bytes_wrote, PAGE_SIZE, |
| 2938 | "%08x: %08x\n", (i * 4), |
| 2939 | readl(®[i])); |
| 2940 | } |
| 2941 | return bytes_wrote; |
| 2942 | } |
| 2943 | |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2944 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2945 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2946 | */ |
| 2947 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2948 | { |
| 2949 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2950 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2951 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2952 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2953 | |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2954 | scmd_printk(KERN_INFO, scmd, |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2955 | "OCR is requested due to IO timeout!!\n"); |
| 2956 | |
| 2957 | scmd_printk(KERN_INFO, scmd, |
| 2958 | "SCSI host state: %d SCSI host busy: %d FW outstanding: %d\n", |
| 2959 | scmd->device->host->shost_state, |
Ming Lei | c84b023 | 2018-06-24 22:03:26 +0800 | [diff] [blame] | 2960 | scsi_host_busy(scmd->device->host), |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2961 | atomic_read(&instance->fw_outstanding)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2962 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2963 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2964 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2965 | if (instance->adapter_type == MFI_SERIES) { |
| 2966 | ret = megasas_generic_reset(scmd); |
| 2967 | } else { |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2968 | megasas_dump_fusion_io(scmd); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2969 | ret = megasas_reset_fusion(scmd->device->host, |
| 2970 | SCSIIO_TIMEOUT_OCR); |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2971 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2972 | |
| 2973 | return ret; |
| 2974 | } |
| 2975 | |
| 2976 | /** |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2977 | * megasas_task_abort - Issues task abort request to firmware |
| 2978 | * (supported only for fusion adapters) |
| 2979 | * @scmd: SCSI command pointer |
| 2980 | */ |
| 2981 | static int megasas_task_abort(struct scsi_cmnd *scmd) |
| 2982 | { |
| 2983 | int ret; |
| 2984 | struct megasas_instance *instance; |
| 2985 | |
| 2986 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2987 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2988 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 2989 | ret = megasas_task_abort_fusion(scmd); |
| 2990 | else { |
| 2991 | sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n"); |
| 2992 | ret = FAILED; |
| 2993 | } |
| 2994 | |
| 2995 | return ret; |
| 2996 | } |
| 2997 | |
| 2998 | /** |
| 2999 | * megasas_reset_target: Issues target reset request to firmware |
| 3000 | * (supported only for fusion adapters) |
| 3001 | * @scmd: SCSI command pointer |
| 3002 | */ |
| 3003 | static int megasas_reset_target(struct scsi_cmnd *scmd) |
| 3004 | { |
| 3005 | int ret; |
| 3006 | struct megasas_instance *instance; |
| 3007 | |
| 3008 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 3009 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3010 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3011 | ret = megasas_reset_target_fusion(scmd); |
| 3012 | else { |
| 3013 | sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n"); |
| 3014 | ret = FAILED; |
| 3015 | } |
| 3016 | |
| 3017 | return ret; |
| 3018 | } |
| 3019 | |
| 3020 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3021 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3022 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3023 | * @bdev: block device |
| 3024 | * @capacity: drive capacity |
| 3025 | * @geom: geometry parameters |
| 3026 | */ |
| 3027 | static int |
| 3028 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 3029 | sector_t capacity, int geom[]) |
| 3030 | { |
| 3031 | int heads; |
| 3032 | int sectors; |
| 3033 | sector_t cylinders; |
| 3034 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3035 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3036 | /* Default heads (64) & sectors (32) */ |
| 3037 | heads = 64; |
| 3038 | sectors = 32; |
| 3039 | |
| 3040 | tmp = heads * sectors; |
| 3041 | cylinders = capacity; |
| 3042 | |
| 3043 | sector_div(cylinders, tmp); |
| 3044 | |
| 3045 | /* |
| 3046 | * Handle extended translation size for logical drives > 1Gb |
| 3047 | */ |
| 3048 | |
| 3049 | if (capacity >= 0x200000) { |
| 3050 | heads = 255; |
| 3051 | sectors = 63; |
| 3052 | tmp = heads*sectors; |
| 3053 | cylinders = capacity; |
| 3054 | sector_div(cylinders, tmp); |
| 3055 | } |
| 3056 | |
| 3057 | geom[0] = heads; |
| 3058 | geom[1] = sectors; |
| 3059 | geom[2] = cylinders; |
| 3060 | |
| 3061 | return 0; |
| 3062 | } |
| 3063 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3064 | static void megasas_aen_polling(struct work_struct *work); |
| 3065 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3066 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3067 | * megasas_service_aen - Processes an event notification |
| 3068 | * @instance: Adapter soft state |
| 3069 | * @cmd: AEN command completed by the ISR |
| 3070 | * |
| 3071 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 3072 | * event occurs. When an event of interest occurs, FW completes the command |
| 3073 | * that it was previously holding. |
| 3074 | * |
| 3075 | * This routines sends SIGIO signal to processes that have registered with the |
| 3076 | * driver for AEN. |
| 3077 | */ |
| 3078 | static void |
| 3079 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 3080 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3081 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3082 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3083 | /* |
| 3084 | * Don't signal app if it is just an aborted previously registered aen |
| 3085 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3086 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 3087 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3088 | megasas_poll_wait_aen = 1; |
| 3089 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3090 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3091 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3092 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3093 | else |
| 3094 | cmd->abort_aen = 0; |
| 3095 | |
| 3096 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3097 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3098 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3099 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3100 | if ((instance->unload == 0) && |
| 3101 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3102 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3103 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3104 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 3105 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3106 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3107 | } else { |
| 3108 | ev->instance = instance; |
| 3109 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 3110 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 3111 | megasas_aen_polling); |
| 3112 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3113 | } |
| 3114 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3115 | } |
| 3116 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3117 | static ssize_t |
| 3118 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 3119 | struct device_attribute *attr, const char *buf, size_t count) |
| 3120 | { |
| 3121 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3122 | struct megasas_instance *instance = |
| 3123 | (struct megasas_instance *) shost->hostdata; |
| 3124 | int val = 0; |
| 3125 | unsigned long flags; |
| 3126 | |
| 3127 | if (kstrtoint(buf, 0, &val) != 0) |
| 3128 | return -EINVAL; |
| 3129 | |
| 3130 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3131 | instance->fw_crash_buffer_offset = val; |
| 3132 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3133 | return strlen(buf); |
| 3134 | } |
| 3135 | |
| 3136 | static ssize_t |
| 3137 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 3138 | struct device_attribute *attr, char *buf) |
| 3139 | { |
| 3140 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3141 | struct megasas_instance *instance = |
| 3142 | (struct megasas_instance *) shost->hostdata; |
| 3143 | u32 size; |
| 3144 | unsigned long buff_addr; |
| 3145 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 3146 | unsigned long src_addr; |
| 3147 | unsigned long flags; |
| 3148 | u32 buff_offset; |
| 3149 | |
| 3150 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3151 | buff_offset = instance->fw_crash_buffer_offset; |
| 3152 | if (!instance->crash_dump_buf && |
| 3153 | !((instance->fw_crash_state == AVAILABLE) || |
| 3154 | (instance->fw_crash_state == COPYING))) { |
| 3155 | dev_err(&instance->pdev->dev, |
| 3156 | "Firmware crash dump is not available\n"); |
| 3157 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3158 | return -EINVAL; |
| 3159 | } |
| 3160 | |
| 3161 | buff_addr = (unsigned long) buf; |
| 3162 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3163 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3164 | dev_err(&instance->pdev->dev, |
| 3165 | "Firmware crash dump offset is out of range\n"); |
| 3166 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3167 | return 0; |
| 3168 | } |
| 3169 | |
| 3170 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 3171 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 3172 | |
| 3173 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 3174 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3175 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3176 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3177 | |
| 3178 | return size; |
| 3179 | } |
| 3180 | |
| 3181 | static ssize_t |
| 3182 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 3183 | struct device_attribute *attr, char *buf) |
| 3184 | { |
| 3185 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3186 | struct megasas_instance *instance = |
| 3187 | (struct megasas_instance *) shost->hostdata; |
| 3188 | |
| 3189 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 3190 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 3191 | } |
| 3192 | |
| 3193 | static ssize_t |
| 3194 | megasas_fw_crash_state_store(struct device *cdev, |
| 3195 | struct device_attribute *attr, const char *buf, size_t count) |
| 3196 | { |
| 3197 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3198 | struct megasas_instance *instance = |
| 3199 | (struct megasas_instance *) shost->hostdata; |
| 3200 | int val = 0; |
| 3201 | unsigned long flags; |
| 3202 | |
| 3203 | if (kstrtoint(buf, 0, &val) != 0) |
| 3204 | return -EINVAL; |
| 3205 | |
| 3206 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 3207 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 3208 | "firmware crash state\n"); |
| 3209 | return -EINVAL; |
| 3210 | } |
| 3211 | |
| 3212 | instance->fw_crash_state = val; |
| 3213 | |
| 3214 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 3215 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3216 | megasas_free_host_crash_buffer(instance); |
| 3217 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3218 | if (val == COPY_ERROR) |
| 3219 | dev_info(&instance->pdev->dev, "application failed to " |
| 3220 | "copy Firmware crash dump\n"); |
| 3221 | else |
| 3222 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 3223 | "copied successfully\n"); |
| 3224 | } |
| 3225 | return strlen(buf); |
| 3226 | } |
| 3227 | |
| 3228 | static ssize_t |
| 3229 | megasas_fw_crash_state_show(struct device *cdev, |
| 3230 | struct device_attribute *attr, char *buf) |
| 3231 | { |
| 3232 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3233 | struct megasas_instance *instance = |
| 3234 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3235 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3236 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 3237 | } |
| 3238 | |
| 3239 | static ssize_t |
| 3240 | megasas_page_size_show(struct device *cdev, |
| 3241 | struct device_attribute *attr, char *buf) |
| 3242 | { |
| 3243 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 3244 | } |
| 3245 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3246 | static ssize_t |
| 3247 | megasas_ldio_outstanding_show(struct device *cdev, struct device_attribute *attr, |
| 3248 | char *buf) |
| 3249 | { |
| 3250 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3251 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3252 | |
| 3253 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding)); |
| 3254 | } |
| 3255 | |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3256 | static ssize_t |
| 3257 | megasas_fw_cmds_outstanding_show(struct device *cdev, |
| 3258 | struct device_attribute *attr, char *buf) |
| 3259 | { |
| 3260 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3261 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3262 | |
| 3263 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->fw_outstanding)); |
| 3264 | } |
| 3265 | |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 3266 | static ssize_t |
| 3267 | megasas_dump_system_regs_show(struct device *cdev, |
| 3268 | struct device_attribute *attr, char *buf) |
| 3269 | { |
| 3270 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3271 | struct megasas_instance *instance = |
| 3272 | (struct megasas_instance *)shost->hostdata; |
| 3273 | |
| 3274 | return megasas_dump_sys_regs(instance->reg_set, buf); |
| 3275 | } |
| 3276 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3277 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 3278 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 3279 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 3280 | megasas_fw_crash_buffer_size_show, NULL); |
| 3281 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 3282 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 3283 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 3284 | megasas_page_size_show, NULL); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3285 | static DEVICE_ATTR(ldio_outstanding, S_IRUGO, |
| 3286 | megasas_ldio_outstanding_show, NULL); |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3287 | static DEVICE_ATTR(fw_cmds_outstanding, S_IRUGO, |
| 3288 | megasas_fw_cmds_outstanding_show, NULL); |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 3289 | static DEVICE_ATTR(dump_system_regs, S_IRUGO, |
| 3290 | megasas_dump_system_regs_show, NULL); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3291 | |
| 3292 | struct device_attribute *megaraid_host_attrs[] = { |
| 3293 | &dev_attr_fw_crash_buffer_size, |
| 3294 | &dev_attr_fw_crash_buffer, |
| 3295 | &dev_attr_fw_crash_state, |
| 3296 | &dev_attr_page_size, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3297 | &dev_attr_ldio_outstanding, |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3298 | &dev_attr_fw_cmds_outstanding, |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 3299 | &dev_attr_dump_system_regs, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3300 | NULL, |
| 3301 | }; |
| 3302 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3303 | /* |
| 3304 | * Scsi host template for megaraid_sas driver |
| 3305 | */ |
| 3306 | static struct scsi_host_template megasas_template = { |
| 3307 | |
| 3308 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 3309 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3310 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 3311 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 3312 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3313 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3314 | .queuecommand = megasas_queue_command, |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3315 | .eh_target_reset_handler = megasas_reset_target, |
| 3316 | .eh_abort_handler = megasas_task_abort, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3317 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3318 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3319 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3320 | .bios_param = megasas_bios_param, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 3321 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 3322 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3323 | }; |
| 3324 | |
| 3325 | /** |
| 3326 | * megasas_complete_int_cmd - Completes an internal command |
| 3327 | * @instance: Adapter soft state |
| 3328 | * @cmd: Command to be completed |
| 3329 | * |
| 3330 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 3331 | * after it issues a command. This function wakes up that waiting routine by |
| 3332 | * calling wake_up() on the wait queue. |
| 3333 | */ |
| 3334 | static void |
| 3335 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 3336 | struct megasas_cmd *cmd) |
| 3337 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3338 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3339 | wake_up(&instance->int_cmd_wait_q); |
| 3340 | } |
| 3341 | |
| 3342 | /** |
| 3343 | * megasas_complete_abort - Completes aborting a command |
| 3344 | * @instance: Adapter soft state |
| 3345 | * @cmd: Cmd that was issued to abort another cmd |
| 3346 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3347 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 3348 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3349 | * wakes up all functions waiting on the same wait queue. |
| 3350 | */ |
| 3351 | static void |
| 3352 | megasas_complete_abort(struct megasas_instance *instance, |
| 3353 | struct megasas_cmd *cmd) |
| 3354 | { |
| 3355 | if (cmd->sync_cmd) { |
| 3356 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3357 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3358 | wake_up(&instance->abort_cmd_wait_q); |
| 3359 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3363 | * megasas_complete_cmd - Completes a command |
| 3364 | * @instance: Adapter soft state |
| 3365 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3366 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3367 | * SCSI mid-layer instead of the value returned |
| 3368 | * by the FW. This should be used if caller wants |
| 3369 | * an alternate status (as in the case of aborted |
| 3370 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3371 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3372 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3373 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 3374 | u8 alt_status) |
| 3375 | { |
| 3376 | int exception = 0; |
| 3377 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3378 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3379 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3380 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3381 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3382 | /* flag for the retry reset */ |
| 3383 | cmd->retry_for_fw_reset = 0; |
| 3384 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3385 | if (cmd->scmd) |
| 3386 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3387 | |
| 3388 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3389 | case MFI_CMD_INVALID: |
| 3390 | /* Some older 1068 controller FW may keep a pended |
| 3391 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3392 | when booting the kdump kernel. Ignore this command to |
| 3393 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3394 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3395 | "completed\n"); |
| 3396 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3397 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3398 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3399 | case MFI_CMD_PD_SCSI_IO: |
| 3400 | case MFI_CMD_LD_SCSI_IO: |
| 3401 | |
| 3402 | /* |
| 3403 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3404 | * issued either through an IO path or an IOCTL path. If it |
| 3405 | * was via IOCTL, we will send it to internal completion. |
| 3406 | */ |
| 3407 | if (cmd->sync_cmd) { |
| 3408 | cmd->sync_cmd = 0; |
| 3409 | megasas_complete_int_cmd(instance, cmd); |
| 3410 | break; |
| 3411 | } |
Gustavo A. R. Silva | 8d07f7d | 2018-11-27 22:32:27 -0600 | [diff] [blame] | 3412 | /* fall through */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3413 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3414 | case MFI_CMD_LD_READ: |
| 3415 | case MFI_CMD_LD_WRITE: |
| 3416 | |
| 3417 | if (alt_status) { |
| 3418 | cmd->scmd->result = alt_status << 16; |
| 3419 | exception = 1; |
| 3420 | } |
| 3421 | |
| 3422 | if (exception) { |
| 3423 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3424 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3425 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3426 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3427 | cmd->scmd->scsi_done(cmd->scmd); |
| 3428 | megasas_return_cmd(instance, cmd); |
| 3429 | |
| 3430 | break; |
| 3431 | } |
| 3432 | |
| 3433 | switch (hdr->cmd_status) { |
| 3434 | |
| 3435 | case MFI_STAT_OK: |
| 3436 | cmd->scmd->result = DID_OK << 16; |
| 3437 | break; |
| 3438 | |
| 3439 | case MFI_STAT_SCSI_IO_FAILED: |
| 3440 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3441 | cmd->scmd->result = |
| 3442 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3443 | break; |
| 3444 | |
| 3445 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3446 | |
| 3447 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3448 | |
| 3449 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3450 | memset(cmd->scmd->sense_buffer, 0, |
| 3451 | SCSI_SENSE_BUFFERSIZE); |
| 3452 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3453 | hdr->sense_len); |
| 3454 | |
| 3455 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3456 | } |
| 3457 | |
| 3458 | break; |
| 3459 | |
| 3460 | case MFI_STAT_LD_OFFLINE: |
| 3461 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3462 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3463 | break; |
| 3464 | |
| 3465 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3466 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3467 | hdr->cmd_status); |
| 3468 | cmd->scmd->result = DID_ERROR << 16; |
| 3469 | break; |
| 3470 | } |
| 3471 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3472 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3473 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3474 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3475 | cmd->scmd->scsi_done(cmd->scmd); |
| 3476 | megasas_return_cmd(instance, cmd); |
| 3477 | |
| 3478 | break; |
| 3479 | |
| 3480 | case MFI_CMD_SMP: |
| 3481 | case MFI_CMD_STP: |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 3482 | case MFI_CMD_NVME: |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3483 | megasas_complete_int_cmd(instance, cmd); |
| 3484 | break; |
| 3485 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3486 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3487 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3488 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3489 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3490 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3491 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3492 | spin_lock_irqsave(instance->host->host_lock, flags); |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3493 | status = cmd->frame->hdr.cmd_status; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3494 | instance->map_update_cmd = NULL; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3495 | if (status != MFI_STAT_OK) { |
| 3496 | if (status != MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3497 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3498 | cmd->frame->hdr.cmd_status); |
| 3499 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3500 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3501 | spin_unlock_irqrestore( |
| 3502 | instance->host->host_lock, |
| 3503 | flags); |
| 3504 | break; |
| 3505 | } |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3506 | } |
| 3507 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3508 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3509 | |
| 3510 | /* |
| 3511 | * Set fast path IO to ZERO. |
| 3512 | * Validate Map will set proper value. |
| 3513 | * Meanwhile all IOs will go as LD IO. |
| 3514 | */ |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3515 | if (status == MFI_STAT_OK && |
| 3516 | (MR_ValidateMapInfo(instance, (instance->map_id + 1)))) { |
| 3517 | instance->map_id++; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3518 | fusion->fast_path_io = 1; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3519 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3520 | fusion->fast_path_io = 0; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3521 | } |
| 3522 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3523 | megasas_sync_map_info(instance); |
| 3524 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3525 | flags); |
| 3526 | break; |
| 3527 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3528 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3529 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3530 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3531 | megasas_poll_wait_aen = 0; |
| 3532 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3533 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3534 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3535 | /* FW has an updated PD sequence */ |
| 3536 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3537 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3538 | |
| 3539 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3540 | status = cmd->frame->hdr.cmd_status; |
| 3541 | instance->jbod_seq_cmd = NULL; |
| 3542 | megasas_return_cmd(instance, cmd); |
| 3543 | |
| 3544 | if (status == MFI_STAT_OK) { |
| 3545 | instance->pd_seq_map_id++; |
| 3546 | /* Re-register a pd sync seq num cmd */ |
| 3547 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3548 | instance->use_seqnum_jbod_fp = false; |
| 3549 | } else |
| 3550 | instance->use_seqnum_jbod_fp = false; |
| 3551 | |
| 3552 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3553 | break; |
| 3554 | } |
| 3555 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3556 | /* |
| 3557 | * See if got an event notification |
| 3558 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3559 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3560 | megasas_service_aen(instance, cmd); |
| 3561 | else |
| 3562 | megasas_complete_int_cmd(instance, cmd); |
| 3563 | |
| 3564 | break; |
| 3565 | |
| 3566 | case MFI_CMD_ABORT: |
| 3567 | /* |
| 3568 | * Cmd issued to abort another cmd returned |
| 3569 | */ |
| 3570 | megasas_complete_abort(instance, cmd); |
| 3571 | break; |
| 3572 | |
| 3573 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3574 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3575 | hdr->cmd); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3576 | megasas_complete_int_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3577 | break; |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3582 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3583 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3584 | * @instance: Adapter soft state |
| 3585 | */ |
| 3586 | static inline void |
| 3587 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3588 | { |
| 3589 | struct megasas_cmd *cmd; |
| 3590 | struct list_head clist_local; |
| 3591 | union megasas_evt_class_locale class_locale; |
| 3592 | unsigned long flags; |
| 3593 | u32 seq_num; |
| 3594 | |
| 3595 | INIT_LIST_HEAD(&clist_local); |
| 3596 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3597 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3598 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3599 | |
| 3600 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3601 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3602 | struct megasas_cmd, list); |
| 3603 | list_del_init(&cmd->list); |
| 3604 | |
| 3605 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3606 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3607 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3608 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3609 | |
| 3610 | cmd->retry_for_fw_reset++; |
| 3611 | |
| 3612 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3613 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3614 | "was tried multiple times during reset." |
| 3615 | "Shutting down the HBA\n", |
| 3616 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3617 | instance->instancet->disable_intr(instance); |
| 3618 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3619 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3620 | return; |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | if (cmd->sync_cmd == 1) { |
| 3625 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3626 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3627 | "cmd attached to internal command!\n"); |
| 3628 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3629 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3630 | "on the internal reset queue," |
| 3631 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3632 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3633 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3634 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3635 | 0, instance->reg_set); |
| 3636 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3637 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3638 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3639 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3640 | |
| 3641 | atomic_inc(&instance->fw_outstanding); |
| 3642 | instance->instancet->fire_cmd(instance, |
| 3643 | cmd->frame_phys_addr, |
| 3644 | cmd->frame_count-1, instance->reg_set); |
| 3645 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3646 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3647 | "internal reset defer list while re-issue!!\n", |
| 3648 | cmd); |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3653 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3654 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3655 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3656 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3660 | * Initiate AEN (Asynchronous Event Notification) |
| 3661 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3662 | seq_num = instance->last_seq_num; |
| 3663 | class_locale.members.reserved = 0; |
| 3664 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3665 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3666 | |
| 3667 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3668 | } |
| 3669 | |
| 3670 | /** |
| 3671 | * Move the internal reset pending commands to a deferred queue. |
| 3672 | * |
| 3673 | * We move the commands pending at internal reset time to a |
| 3674 | * pending queue. This queue would be flushed after successful |
| 3675 | * completion of the internal reset sequence. if the internal reset |
| 3676 | * did not complete in time, the kernel reset handler would flush |
| 3677 | * these commands. |
| 3678 | **/ |
| 3679 | static void |
| 3680 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3681 | { |
| 3682 | struct megasas_cmd *cmd; |
| 3683 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3684 | u16 max_cmd = instance->max_fw_cmds; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3685 | u32 defer_index; |
| 3686 | unsigned long flags; |
| 3687 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3688 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3689 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3690 | for (i = 0; i < max_cmd; i++) { |
| 3691 | cmd = instance->cmd_list[i]; |
| 3692 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3693 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3694 | "on the defer queue as internal\n", |
| 3695 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3696 | |
| 3697 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3698 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3699 | " moving this cmd:%p, %d %p, it was" |
| 3700 | "discovered on some list?\n", |
| 3701 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3702 | |
| 3703 | list_del_init(&cmd->list); |
| 3704 | } |
| 3705 | defer_index++; |
| 3706 | list_add_tail(&cmd->list, |
| 3707 | &instance->internal_reset_pending_q); |
| 3708 | } |
| 3709 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3710 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | |
| 3714 | static void |
| 3715 | process_fw_state_change_wq(struct work_struct *work) |
| 3716 | { |
| 3717 | struct megasas_instance *instance = |
| 3718 | container_of(work, struct megasas_instance, work_init); |
| 3719 | u32 wait; |
| 3720 | unsigned long flags; |
| 3721 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3722 | if (atomic_read(&instance->adprecovery) != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3723 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3724 | atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3725 | return ; |
| 3726 | } |
| 3727 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3728 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3729 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3730 | "state, restarting it...\n"); |
| 3731 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3732 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3733 | atomic_set(&instance->fw_outstanding, 0); |
| 3734 | |
| 3735 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3736 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3737 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3738 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3739 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3740 | "initiating next stage...\n"); |
| 3741 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3742 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3743 | "state 2 starting...\n"); |
| 3744 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3745 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3746 | for (wait = 0; wait < 30; wait++) { |
| 3747 | msleep(1000); |
| 3748 | } |
| 3749 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3750 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3751 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3752 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3753 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3754 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3755 | return ; |
| 3756 | } |
| 3757 | |
| 3758 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3759 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3760 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3761 | ) { |
| 3762 | *instance->consumer = *instance->producer; |
| 3763 | } else { |
| 3764 | *instance->consumer = 0; |
| 3765 | *instance->producer = 0; |
| 3766 | } |
| 3767 | |
| 3768 | megasas_issue_init_mfi(instance); |
| 3769 | |
| 3770 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3771 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3772 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3773 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3774 | |
| 3775 | megasas_issue_pending_cmds_again(instance); |
| 3776 | instance->issuepend_done = 1; |
| 3777 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3781 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3782 | * @instance: Adapter soft state |
| 3783 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3784 | * SCSI mid-layer instead of the status |
| 3785 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3786 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3787 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3788 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3789 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3790 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3791 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3792 | u32 mfiStatus; |
| 3793 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3794 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3795 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3796 | instance->reg_set)) == 1) { |
| 3797 | return IRQ_HANDLED; |
| 3798 | } |
| 3799 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3800 | mfiStatus = instance->instancet->clear_intr(instance); |
| 3801 | if (mfiStatus == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3802 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3803 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3804 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3805 | } |
| 3806 | |
| 3807 | instance->mfiStatus = mfiStatus; |
| 3808 | |
| 3809 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3810 | fw_state = instance->instancet->read_fw_status_reg( |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3811 | instance) & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3812 | |
| 3813 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3814 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3815 | fw_state); |
| 3816 | } |
| 3817 | |
| 3818 | if ((fw_state == MFI_STATE_FAULT) && |
| 3819 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3820 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3821 | |
| 3822 | if ((instance->pdev->device == |
| 3823 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3824 | (instance->pdev->device == |
| 3825 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3826 | (instance->pdev->device == |
| 3827 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3828 | |
| 3829 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3830 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3831 | } |
| 3832 | |
| 3833 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3834 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3835 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3836 | instance->issuepend_done = 0; |
| 3837 | |
| 3838 | atomic_set(&instance->fw_outstanding, 0); |
| 3839 | megasas_internal_reset_defer_cmds(instance); |
| 3840 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3841 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3842 | fw_state, atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3843 | |
| 3844 | schedule_work(&instance->work_init); |
| 3845 | return IRQ_HANDLED; |
| 3846 | |
| 3847 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3848 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3849 | fw_state, instance->disableOnlineCtrlReset); |
| 3850 | } |
| 3851 | } |
| 3852 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3853 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3854 | return IRQ_HANDLED; |
| 3855 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3856 | /** |
| 3857 | * megasas_isr - isr entry point |
| 3858 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3859 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3860 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3861 | struct megasas_irq_context *irq_context = devp; |
| 3862 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3863 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3864 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3865 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3866 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3867 | return IRQ_HANDLED; |
| 3868 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3869 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3870 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3871 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3872 | |
| 3873 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | /** |
| 3877 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3878 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3879 | * |
| 3880 | * During the initialization, FW passes can potentially be in any one of |
| 3881 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3882 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3883 | * has to wait for the ready state. |
| 3884 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3885 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3886 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3887 | { |
| 3888 | int i; |
| 3889 | u8 max_wait; |
| 3890 | u32 fw_state; |
| 3891 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3892 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3893 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3894 | abs_state = instance->instancet->read_fw_status_reg(instance); |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3895 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3896 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3897 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3898 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3899 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3900 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3901 | while (fw_state != MFI_STATE_READY) { |
| 3902 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3903 | switch (fw_state) { |
| 3904 | |
| 3905 | case MFI_STATE_FAULT: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3906 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3907 | if (ocr) { |
| 3908 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3909 | cur_state = MFI_STATE_FAULT; |
| 3910 | break; |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame^] | 3911 | } else { |
| 3912 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n"); |
| 3913 | megasas_dump_reg_set(instance->reg_set); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3914 | return -ENODEV; |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame^] | 3915 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3916 | |
| 3917 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3918 | /* |
| 3919 | * Set the CLR bit in inbound doorbell |
| 3920 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3921 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3922 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3923 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3924 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3925 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3926 | writel( |
| 3927 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3928 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3929 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3930 | writel( |
| 3931 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3932 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3933 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3934 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3935 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3936 | break; |
| 3937 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3938 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3939 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3940 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3941 | (instance->pdev->device == |
| 3942 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3943 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3944 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3945 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3946 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3947 | writel(MFI_INIT_HOTPLUG, |
| 3948 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3949 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3950 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3951 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3952 | break; |
| 3953 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3954 | case MFI_STATE_OPERATIONAL: |
| 3955 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3956 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3957 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3958 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3959 | if ((instance->pdev->device == |
| 3960 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3961 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3962 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3963 | (instance->adapter_type != MFI_SERIES)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3964 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3965 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3966 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3967 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3968 | for (i = 0; i < (10 * 1000); i += 20) { |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 3969 | if (megasas_readl( |
| 3970 | instance, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3971 | &instance-> |
| 3972 | reg_set-> |
| 3973 | doorbell) & 1) |
| 3974 | msleep(20); |
| 3975 | else |
| 3976 | break; |
| 3977 | } |
| 3978 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3979 | } else |
| 3980 | writel(MFI_RESET_FLAGS, |
| 3981 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3982 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3983 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3984 | cur_state = MFI_STATE_OPERATIONAL; |
| 3985 | break; |
| 3986 | |
| 3987 | case MFI_STATE_UNDEFINED: |
| 3988 | /* |
| 3989 | * This state should not last for more than 2 seconds |
| 3990 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3991 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3992 | cur_state = MFI_STATE_UNDEFINED; |
| 3993 | break; |
| 3994 | |
| 3995 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3996 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3997 | cur_state = MFI_STATE_BB_INIT; |
| 3998 | break; |
| 3999 | |
| 4000 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4001 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4002 | cur_state = MFI_STATE_FW_INIT; |
| 4003 | break; |
| 4004 | |
| 4005 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4006 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4007 | cur_state = MFI_STATE_FW_INIT_2; |
| 4008 | break; |
| 4009 | |
| 4010 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4011 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4012 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 4013 | break; |
| 4014 | |
| 4015 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4016 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4017 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 4018 | break; |
| 4019 | |
| 4020 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4021 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4022 | fw_state); |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame^] | 4023 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n"); |
| 4024 | megasas_dump_reg_set(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4025 | return -ENODEV; |
| 4026 | } |
| 4027 | |
| 4028 | /* |
| 4029 | * The cur_state should not last for more than max_wait secs |
| 4030 | */ |
Steve Sistare | 31b6a05 | 2019-03-01 06:46:28 -0800 | [diff] [blame] | 4031 | for (i = 0; i < max_wait * 50; i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 4032 | curr_abs_state = instance->instancet-> |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 4033 | read_fw_status_reg(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4034 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4035 | if (abs_state == curr_abs_state) { |
Steve Sistare | 31b6a05 | 2019-03-01 06:46:28 -0800 | [diff] [blame] | 4036 | msleep(20); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4037 | } else |
| 4038 | break; |
| 4039 | } |
| 4040 | |
| 4041 | /* |
| 4042 | * Return error if fw_state hasn't changed after max_wait |
| 4043 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4044 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4045 | 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] | 4046 | "in %d secs\n", fw_state, max_wait); |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame^] | 4047 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n"); |
| 4048 | megasas_dump_reg_set(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4049 | return -ENODEV; |
| 4050 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 4051 | |
| 4052 | abs_state = curr_abs_state; |
| 4053 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4054 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4055 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4056 | |
| 4057 | return 0; |
| 4058 | } |
| 4059 | |
| 4060 | /** |
| 4061 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 4062 | * @instance: Adapter soft state |
| 4063 | */ |
| 4064 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 4065 | { |
| 4066 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4067 | u16 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4068 | struct megasas_cmd *cmd; |
| 4069 | |
| 4070 | if (!instance->frame_dma_pool) |
| 4071 | return; |
| 4072 | |
| 4073 | /* |
| 4074 | * Return all frames to pool |
| 4075 | */ |
| 4076 | for (i = 0; i < max_cmd; i++) { |
| 4077 | |
| 4078 | cmd = instance->cmd_list[i]; |
| 4079 | |
| 4080 | if (cmd->frame) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4081 | dma_pool_free(instance->frame_dma_pool, cmd->frame, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4082 | cmd->frame_phys_addr); |
| 4083 | |
| 4084 | if (cmd->sense) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4085 | dma_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4086 | cmd->sense_phys_addr); |
| 4087 | } |
| 4088 | |
| 4089 | /* |
| 4090 | * Now destroy the pool itself |
| 4091 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4092 | dma_pool_destroy(instance->frame_dma_pool); |
| 4093 | dma_pool_destroy(instance->sense_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4094 | |
| 4095 | instance->frame_dma_pool = NULL; |
| 4096 | instance->sense_dma_pool = NULL; |
| 4097 | } |
| 4098 | |
| 4099 | /** |
| 4100 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 4101 | * @instance: Adapter soft state |
| 4102 | * |
| 4103 | * Each command packet has an embedded DMA memory buffer that is used for |
| 4104 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 4105 | * function creates those DMA memory buffers for each command packet by using |
| 4106 | * PCI pool facility. |
| 4107 | */ |
| 4108 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 4109 | { |
| 4110 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4111 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4112 | u32 sge_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4113 | u32 frame_count; |
| 4114 | struct megasas_cmd *cmd; |
| 4115 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4116 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4117 | |
| 4118 | /* |
| 4119 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 4120 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 4121 | */ |
| 4122 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 4123 | sizeof(struct megasas_sge32); |
| 4124 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4125 | if (instance->flag_ieee) |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 4126 | sge_sz = sizeof(struct megasas_sge_skinny); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 4127 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4128 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 4129 | * For MFI controllers. |
| 4130 | * max_num_sge = 60 |
| 4131 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 4132 | * Total 960 byte (15 MFI frame of 64 byte) |
| 4133 | * |
| 4134 | * Fusion adapter require only 3 extra frame. |
| 4135 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 4136 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 4137 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4138 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4139 | frame_count = (instance->adapter_type == MFI_SERIES) ? |
| 4140 | (15 + 1) : (3 + 1); |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 4141 | instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4142 | /* |
| 4143 | * Use DMA pool facility provided by PCI layer |
| 4144 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4145 | instance->frame_dma_pool = dma_pool_create("megasas frame pool", |
| 4146 | &instance->pdev->dev, |
| 4147 | instance->mfi_frame_size, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4148 | |
| 4149 | if (!instance->frame_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4150 | 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] | 4151 | return -ENOMEM; |
| 4152 | } |
| 4153 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4154 | instance->sense_dma_pool = dma_pool_create("megasas sense pool", |
| 4155 | &instance->pdev->dev, 128, |
| 4156 | 4, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4157 | |
| 4158 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4159 | 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] | 4160 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4161 | dma_pool_destroy(instance->frame_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4162 | instance->frame_dma_pool = NULL; |
| 4163 | |
| 4164 | return -ENOMEM; |
| 4165 | } |
| 4166 | |
| 4167 | /* |
| 4168 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 4169 | * By making cmd->index as the context instead of the &cmd, we can |
| 4170 | * always use 32bit context regardless of the architecture |
| 4171 | */ |
| 4172 | for (i = 0; i < max_cmd; i++) { |
| 4173 | |
| 4174 | cmd = instance->cmd_list[i]; |
| 4175 | |
Souptick Joarder | 61b142a | 2018-02-15 21:55:06 +0530 | [diff] [blame] | 4176 | cmd->frame = dma_pool_zalloc(instance->frame_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4177 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 4178 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4179 | cmd->sense = dma_pool_alloc(instance->sense_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4180 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 4181 | |
| 4182 | /* |
| 4183 | * megasas_teardown_frame_pool() takes care of freeing |
| 4184 | * whatever has been allocated |
| 4185 | */ |
| 4186 | if (!cmd->frame || !cmd->sense) { |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4187 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "dma_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4188 | megasas_teardown_frame_pool(instance); |
| 4189 | return -ENOMEM; |
| 4190 | } |
| 4191 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4192 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4193 | cmd->frame->io.pad_0 = 0; |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4194 | if ((instance->adapter_type == MFI_SERIES) && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 4195 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | return 0; |
| 4199 | } |
| 4200 | |
| 4201 | /** |
| 4202 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 4203 | * @instance: Adapter soft state |
| 4204 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4205 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4206 | { |
| 4207 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4208 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4209 | /* First free the MFI frame pool */ |
| 4210 | megasas_teardown_frame_pool(instance); |
| 4211 | |
| 4212 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4213 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 4214 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4215 | kfree(instance->cmd_list[i]); |
| 4216 | |
| 4217 | /* Free the cmd_list buffer itself */ |
| 4218 | kfree(instance->cmd_list); |
| 4219 | instance->cmd_list = NULL; |
| 4220 | |
| 4221 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 4222 | } |
| 4223 | |
| 4224 | /** |
| 4225 | * megasas_alloc_cmds - Allocates the command packets |
| 4226 | * @instance: Adapter soft state |
| 4227 | * |
| 4228 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 4229 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 4230 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 4231 | * the FW. |
| 4232 | * |
| 4233 | * Each frame has a 32-bit field called context (tag). This context is used |
| 4234 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 4235 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 4236 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 4237 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 4238 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 4239 | * This array is used only to look up the megasas_cmd given the context. The |
| 4240 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 4241 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4242 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4243 | { |
| 4244 | int i; |
| 4245 | int j; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4246 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4247 | struct megasas_cmd *cmd; |
| 4248 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4249 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4250 | |
| 4251 | /* |
| 4252 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 4253 | * Allocate the dynamic array first and then allocate individual |
| 4254 | * commands. |
| 4255 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 4256 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4257 | |
| 4258 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4259 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4260 | return -ENOMEM; |
| 4261 | } |
| 4262 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4263 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4264 | |
| 4265 | for (i = 0; i < max_cmd; i++) { |
| 4266 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 4267 | GFP_KERNEL); |
| 4268 | |
| 4269 | if (!instance->cmd_list[i]) { |
| 4270 | |
| 4271 | for (j = 0; j < i; j++) |
| 4272 | kfree(instance->cmd_list[j]); |
| 4273 | |
| 4274 | kfree(instance->cmd_list); |
| 4275 | instance->cmd_list = NULL; |
| 4276 | |
| 4277 | return -ENOMEM; |
| 4278 | } |
| 4279 | } |
| 4280 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4281 | for (i = 0; i < max_cmd; i++) { |
| 4282 | cmd = instance->cmd_list[i]; |
| 4283 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 4284 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4285 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4286 | cmd->instance = instance; |
| 4287 | |
| 4288 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 4289 | } |
| 4290 | |
| 4291 | /* |
| 4292 | * Create a frame pool and assign one frame to each cmd |
| 4293 | */ |
| 4294 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4295 | 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] | 4296 | megasas_free_cmds(instance); |
Jason Yan | bcf3b67 | 2019-02-15 19:50:27 +0800 | [diff] [blame] | 4297 | return -ENOMEM; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | return 0; |
| 4301 | } |
| 4302 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4303 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4304 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 4305 | * @instance: Adapter soft state |
| 4306 | * |
| 4307 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 4308 | * or FW is not under OCR. |
| 4309 | */ |
| 4310 | inline int |
| 4311 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 4312 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4313 | if (instance->adapter_type == MFI_SERIES) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4314 | return KILL_ADAPTER; |
| 4315 | else if (instance->unload || |
| 4316 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 4317 | return IGNORE_TIMEOUT; |
| 4318 | else |
| 4319 | return INITIATE_OCR; |
| 4320 | } |
| 4321 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4322 | static void |
| 4323 | megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4324 | { |
| 4325 | int ret; |
| 4326 | struct megasas_cmd *cmd; |
| 4327 | struct megasas_dcmd_frame *dcmd; |
| 4328 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4329 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 4330 | u16 device_id = 0; |
| 4331 | |
| 4332 | device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4333 | cmd = megasas_get_cmd(instance); |
| 4334 | |
| 4335 | if (!cmd) { |
| 4336 | dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4337 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | dcmd = &cmd->frame->dcmd; |
| 4341 | |
| 4342 | memset(instance->pd_info, 0, sizeof(*instance->pd_info)); |
| 4343 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4344 | |
| 4345 | dcmd->mbox.s[0] = cpu_to_le16(device_id); |
| 4346 | dcmd->cmd = MFI_CMD_DCMD; |
| 4347 | dcmd->cmd_status = 0xFF; |
| 4348 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4349 | dcmd->flags = MFI_FRAME_DIR_READ; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4350 | dcmd->timeout = 0; |
| 4351 | dcmd->pad_0 = 0; |
| 4352 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4353 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_GET_INFO); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4354 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4355 | megasas_set_dma_settings(instance, dcmd, instance->pd_info_h, |
| 4356 | sizeof(struct MR_PD_INFO)); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4357 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4358 | if ((instance->adapter_type != MFI_SERIES) && |
| 4359 | !instance->mask_interrupts) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4360 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 4361 | else |
| 4362 | ret = megasas_issue_polled(instance, cmd); |
| 4363 | |
| 4364 | switch (ret) { |
| 4365 | case DCMD_SUCCESS: |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4366 | mr_device_priv_data = sdev->hostdata; |
| 4367 | le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType); |
| 4368 | mr_device_priv_data->interface_type = |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4369 | instance->pd_info->state.ddf.pdType.intf; |
| 4370 | break; |
| 4371 | |
| 4372 | case DCMD_TIMEOUT: |
| 4373 | |
| 4374 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4375 | case INITIATE_OCR: |
| 4376 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4377 | megasas_reset_fusion(instance->host, |
| 4378 | MFI_IO_TIMEOUT_OCR); |
| 4379 | break; |
| 4380 | case KILL_ADAPTER: |
| 4381 | megaraid_sas_kill_hba(instance); |
| 4382 | break; |
| 4383 | case IGNORE_TIMEOUT: |
| 4384 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4385 | __func__, __LINE__); |
| 4386 | break; |
| 4387 | } |
| 4388 | |
| 4389 | break; |
| 4390 | } |
| 4391 | |
| 4392 | if (ret != DCMD_TIMEOUT) |
| 4393 | megasas_return_cmd(instance, cmd); |
| 4394 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4395 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4396 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4397 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4398 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 4399 | * @instance: Adapter soft state |
| 4400 | * @pd_list: pd_list structure |
| 4401 | * |
| 4402 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4403 | * list structure. This information is mainly used to find out SYSTEM |
| 4404 | * supported by the FW. |
| 4405 | */ |
| 4406 | static int |
| 4407 | megasas_get_pd_list(struct megasas_instance *instance) |
| 4408 | { |
| 4409 | int ret = 0, pd_index = 0; |
| 4410 | struct megasas_cmd *cmd; |
| 4411 | struct megasas_dcmd_frame *dcmd; |
| 4412 | struct MR_PD_LIST *ci; |
| 4413 | struct MR_PD_ADDRESS *pd_addr; |
| 4414 | dma_addr_t ci_h = 0; |
| 4415 | |
Sumit Saxena | d908316 | 2016-07-08 03:30:16 -0700 | [diff] [blame] | 4416 | if (instance->pd_list_not_supported) { |
| 4417 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4418 | "not supported by firmware\n"); |
| 4419 | return ret; |
| 4420 | } |
| 4421 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4422 | ci = instance->pd_list_buf; |
| 4423 | ci_h = instance->pd_list_buf_h; |
| 4424 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4425 | cmd = megasas_get_cmd(instance); |
| 4426 | |
| 4427 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4428 | 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] | 4429 | return -ENOMEM; |
| 4430 | } |
| 4431 | |
| 4432 | dcmd = &cmd->frame->dcmd; |
| 4433 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4434 | memset(ci, 0, sizeof(*ci)); |
| 4435 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4436 | |
| 4437 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 4438 | dcmd->mbox.b[1] = 0; |
| 4439 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4440 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4441 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4442 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4443 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4444 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4445 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 4446 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4447 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4448 | megasas_set_dma_settings(instance, dcmd, instance->pd_list_buf_h, |
| 4449 | (MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST))); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4450 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4451 | if ((instance->adapter_type != MFI_SERIES) && |
| 4452 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4453 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4454 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4455 | else |
| 4456 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4457 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4458 | switch (ret) { |
| 4459 | case DCMD_FAILED: |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4460 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4461 | "failed/not supported by firmware\n"); |
| 4462 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4463 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4464 | megaraid_sas_kill_hba(instance); |
| 4465 | else |
| 4466 | instance->pd_list_not_supported = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4467 | break; |
| 4468 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4469 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4470 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4471 | case INITIATE_OCR: |
| 4472 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4473 | /* |
| 4474 | * DCMD failed from AEN path. |
| 4475 | * AEN path already hold reset_mutex to avoid PCI access |
| 4476 | * while OCR is in progress. |
| 4477 | */ |
| 4478 | mutex_unlock(&instance->reset_mutex); |
| 4479 | megasas_reset_fusion(instance->host, |
| 4480 | MFI_IO_TIMEOUT_OCR); |
| 4481 | mutex_lock(&instance->reset_mutex); |
| 4482 | break; |
| 4483 | case KILL_ADAPTER: |
| 4484 | megaraid_sas_kill_hba(instance); |
| 4485 | break; |
| 4486 | case IGNORE_TIMEOUT: |
| 4487 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4488 | __func__, __LINE__); |
| 4489 | break; |
| 4490 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4491 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4492 | break; |
| 4493 | |
| 4494 | case DCMD_SUCCESS: |
| 4495 | pd_addr = ci->addr; |
| 4496 | |
| 4497 | if ((le32_to_cpu(ci->count) > |
| 4498 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4499 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4500 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4501 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4502 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4503 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4504 | 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] | 4505 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4506 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4507 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4508 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4509 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4510 | MR_PD_STATE_SYSTEM; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4511 | pd_addr++; |
| 4512 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4513 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4514 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4515 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4516 | break; |
| 4517 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4518 | } |
| 4519 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4520 | if (ret != DCMD_TIMEOUT) |
| 4521 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4522 | |
| 4523 | return ret; |
| 4524 | } |
| 4525 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4526 | /* |
| 4527 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4528 | * @instance: Adapter soft state |
| 4529 | * @ld_list: ld_list structure |
| 4530 | * |
| 4531 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4532 | * list structure. This information is mainly used to find out SYSTEM |
| 4533 | * supported by the FW. |
| 4534 | */ |
| 4535 | static int |
| 4536 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4537 | { |
| 4538 | int ret = 0, ld_index = 0, ids = 0; |
| 4539 | struct megasas_cmd *cmd; |
| 4540 | struct megasas_dcmd_frame *dcmd; |
| 4541 | struct MR_LD_LIST *ci; |
| 4542 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4543 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4544 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4545 | ci = instance->ld_list_buf; |
| 4546 | ci_h = instance->ld_list_buf_h; |
| 4547 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4548 | cmd = megasas_get_cmd(instance); |
| 4549 | |
| 4550 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4551 | 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] | 4552 | return -ENOMEM; |
| 4553 | } |
| 4554 | |
| 4555 | dcmd = &cmd->frame->dcmd; |
| 4556 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4557 | memset(ci, 0, sizeof(*ci)); |
| 4558 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4559 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4560 | if (instance->supportmax256vd) |
| 4561 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4562 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4563 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4564 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4565 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4566 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4567 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4568 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4569 | dcmd->pad_0 = 0; |
| 4570 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4571 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4572 | sizeof(struct MR_LD_LIST)); |
| 4573 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4574 | if ((instance->adapter_type != MFI_SERIES) && |
| 4575 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4576 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4577 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4578 | else |
| 4579 | ret = megasas_issue_polled(instance, cmd); |
| 4580 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4581 | ld_count = le32_to_cpu(ci->ldCount); |
| 4582 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4583 | switch (ret) { |
| 4584 | case DCMD_FAILED: |
| 4585 | megaraid_sas_kill_hba(instance); |
| 4586 | break; |
| 4587 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4588 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4589 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4590 | case INITIATE_OCR: |
| 4591 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4592 | /* |
| 4593 | * DCMD failed from AEN path. |
| 4594 | * AEN path already hold reset_mutex to avoid PCI access |
| 4595 | * while OCR is in progress. |
| 4596 | */ |
| 4597 | mutex_unlock(&instance->reset_mutex); |
| 4598 | megasas_reset_fusion(instance->host, |
| 4599 | MFI_IO_TIMEOUT_OCR); |
| 4600 | mutex_lock(&instance->reset_mutex); |
| 4601 | break; |
| 4602 | case KILL_ADAPTER: |
| 4603 | megaraid_sas_kill_hba(instance); |
| 4604 | break; |
| 4605 | case IGNORE_TIMEOUT: |
| 4606 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4607 | __func__, __LINE__); |
| 4608 | break; |
| 4609 | } |
| 4610 | |
| 4611 | break; |
| 4612 | |
| 4613 | case DCMD_SUCCESS: |
| 4614 | if (ld_count > instance->fw_supported_vd_count) |
| 4615 | break; |
| 4616 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4617 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4618 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4619 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4620 | if (ci->ldList[ld_index].state != 0) { |
| 4621 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4622 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4623 | } |
| 4624 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4625 | |
| 4626 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4629 | if (ret != DCMD_TIMEOUT) |
| 4630 | megasas_return_cmd(instance, cmd); |
| 4631 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4632 | return ret; |
| 4633 | } |
| 4634 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4635 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4636 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4637 | * @instance: Adapter soft state |
| 4638 | * @ld_list: ld_list structure |
| 4639 | * |
| 4640 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4641 | * list structure. This information is mainly used to find out SYSTEM |
| 4642 | * supported by the FW. |
| 4643 | */ |
| 4644 | static int |
| 4645 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4646 | { |
| 4647 | int ret = 0, ld_index = 0, ids = 0; |
| 4648 | struct megasas_cmd *cmd; |
| 4649 | struct megasas_dcmd_frame *dcmd; |
| 4650 | struct MR_LD_TARGETID_LIST *ci; |
| 4651 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4652 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4653 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4654 | ci = instance->ld_targetid_list_buf; |
| 4655 | ci_h = instance->ld_targetid_list_buf_h; |
| 4656 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4657 | cmd = megasas_get_cmd(instance); |
| 4658 | |
| 4659 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4660 | dev_warn(&instance->pdev->dev, |
| 4661 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4662 | return -ENOMEM; |
| 4663 | } |
| 4664 | |
| 4665 | dcmd = &cmd->frame->dcmd; |
| 4666 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4667 | memset(ci, 0, sizeof(*ci)); |
| 4668 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4669 | |
| 4670 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4671 | if (instance->supportmax256vd) |
| 4672 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4673 | |
| 4674 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4675 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4676 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4677 | dcmd->flags = MFI_FRAME_DIR_READ; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4678 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4679 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4680 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4681 | dcmd->pad_0 = 0; |
| 4682 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4683 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4684 | sizeof(struct MR_LD_TARGETID_LIST)); |
| 4685 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4686 | if ((instance->adapter_type != MFI_SERIES) && |
| 4687 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4688 | 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] | 4689 | else |
| 4690 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4691 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4692 | switch (ret) { |
| 4693 | case DCMD_FAILED: |
| 4694 | dev_info(&instance->pdev->dev, |
| 4695 | "DCMD not supported by firmware - %s %d\n", |
| 4696 | __func__, __LINE__); |
| 4697 | ret = megasas_get_ld_list(instance); |
| 4698 | break; |
| 4699 | case DCMD_TIMEOUT: |
| 4700 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4701 | case INITIATE_OCR: |
| 4702 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4703 | /* |
| 4704 | * DCMD failed from AEN path. |
| 4705 | * AEN path already hold reset_mutex to avoid PCI access |
| 4706 | * while OCR is in progress. |
| 4707 | */ |
| 4708 | mutex_unlock(&instance->reset_mutex); |
| 4709 | megasas_reset_fusion(instance->host, |
| 4710 | MFI_IO_TIMEOUT_OCR); |
| 4711 | mutex_lock(&instance->reset_mutex); |
| 4712 | break; |
| 4713 | case KILL_ADAPTER: |
| 4714 | megaraid_sas_kill_hba(instance); |
| 4715 | break; |
| 4716 | case IGNORE_TIMEOUT: |
| 4717 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4718 | __func__, __LINE__); |
| 4719 | break; |
| 4720 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4721 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4722 | break; |
| 4723 | case DCMD_SUCCESS: |
| 4724 | tgtid_count = le32_to_cpu(ci->count); |
| 4725 | |
| 4726 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4727 | break; |
| 4728 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4729 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4730 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4731 | ids = ci->targetId[ld_index]; |
| 4732 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4733 | } |
| 4734 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4735 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4736 | } |
| 4737 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4738 | if (ret != DCMD_TIMEOUT) |
| 4739 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4740 | |
| 4741 | return ret; |
| 4742 | } |
| 4743 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4744 | /** |
| 4745 | * dcmd.opcode - MR_DCMD_CTRL_DEVICE_LIST_GET |
| 4746 | * dcmd.mbox - reserved |
| 4747 | * dcmd.sge IN - ptr to return MR_HOST_DEVICE_LIST structure |
| 4748 | * Desc: This DCMD will return the combined device list |
| 4749 | * Status: MFI_STAT_OK - List returned successfully |
| 4750 | * MFI_STAT_INVALID_CMD - Firmware support for the feature has been |
| 4751 | * disabled |
| 4752 | * @instance: Adapter soft state |
| 4753 | * @is_probe: Driver probe check |
| 4754 | * Return: 0 if DCMD succeeded |
| 4755 | * non-zero if failed |
| 4756 | */ |
YueHaibing | 7c3f8ca | 2019-04-13 22:21:38 +0800 | [diff] [blame] | 4757 | static int |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4758 | megasas_host_device_list_query(struct megasas_instance *instance, |
| 4759 | bool is_probe) |
| 4760 | { |
| 4761 | int ret, i, target_id; |
| 4762 | struct megasas_cmd *cmd; |
| 4763 | struct megasas_dcmd_frame *dcmd; |
| 4764 | struct MR_HOST_DEVICE_LIST *ci; |
| 4765 | u32 count; |
| 4766 | dma_addr_t ci_h; |
| 4767 | |
| 4768 | ci = instance->host_device_list_buf; |
| 4769 | ci_h = instance->host_device_list_buf_h; |
| 4770 | |
| 4771 | cmd = megasas_get_cmd(instance); |
| 4772 | |
| 4773 | if (!cmd) { |
| 4774 | dev_warn(&instance->pdev->dev, |
| 4775 | "%s: failed to get cmd\n", |
| 4776 | __func__); |
| 4777 | return -ENOMEM; |
| 4778 | } |
| 4779 | |
| 4780 | dcmd = &cmd->frame->dcmd; |
| 4781 | |
| 4782 | memset(ci, 0, sizeof(*ci)); |
| 4783 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4784 | |
| 4785 | dcmd->mbox.b[0] = is_probe ? 0 : 1; |
| 4786 | dcmd->cmd = MFI_CMD_DCMD; |
| 4787 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
| 4788 | dcmd->sge_count = 1; |
| 4789 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 4790 | dcmd->timeout = 0; |
| 4791 | dcmd->pad_0 = 0; |
| 4792 | dcmd->data_xfer_len = cpu_to_le32(HOST_DEVICE_LIST_SZ); |
| 4793 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_DEVICE_LIST_GET); |
| 4794 | |
| 4795 | megasas_set_dma_settings(instance, dcmd, ci_h, HOST_DEVICE_LIST_SZ); |
| 4796 | |
| 4797 | if (!instance->mask_interrupts) { |
| 4798 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4799 | MFI_IO_TIMEOUT_SECS); |
| 4800 | } else { |
| 4801 | ret = megasas_issue_polled(instance, cmd); |
| 4802 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4803 | } |
| 4804 | |
| 4805 | switch (ret) { |
| 4806 | case DCMD_SUCCESS: |
| 4807 | /* Fill the internal pd_list and ld_ids array based on |
| 4808 | * targetIds returned by FW |
| 4809 | */ |
| 4810 | count = le32_to_cpu(ci->count); |
| 4811 | |
| 4812 | memset(instance->local_pd_list, 0, |
| 4813 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
| 4814 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
| 4815 | for (i = 0; i < count; i++) { |
| 4816 | target_id = le16_to_cpu(ci->host_device_list[i].target_id); |
| 4817 | if (ci->host_device_list[i].flags.u.bits.is_sys_pd) { |
| 4818 | instance->local_pd_list[target_id].tid = target_id; |
| 4819 | instance->local_pd_list[target_id].driveType = |
| 4820 | ci->host_device_list[i].scsi_type; |
| 4821 | instance->local_pd_list[target_id].driveState = |
| 4822 | MR_PD_STATE_SYSTEM; |
| 4823 | } else { |
| 4824 | instance->ld_ids[target_id] = target_id; |
| 4825 | } |
| 4826 | } |
| 4827 | |
| 4828 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4829 | sizeof(instance->pd_list)); |
| 4830 | break; |
| 4831 | |
| 4832 | case DCMD_TIMEOUT: |
| 4833 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4834 | case INITIATE_OCR: |
| 4835 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4836 | megasas_reset_fusion(instance->host, |
| 4837 | MFI_IO_TIMEOUT_OCR); |
| 4838 | break; |
| 4839 | case KILL_ADAPTER: |
| 4840 | megaraid_sas_kill_hba(instance); |
| 4841 | break; |
| 4842 | case IGNORE_TIMEOUT: |
| 4843 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4844 | __func__, __LINE__); |
| 4845 | break; |
| 4846 | } |
| 4847 | break; |
| 4848 | case DCMD_FAILED: |
| 4849 | dev_err(&instance->pdev->dev, |
| 4850 | "%s: MR_DCMD_CTRL_DEVICE_LIST_GET failed\n", |
| 4851 | __func__); |
| 4852 | break; |
| 4853 | } |
| 4854 | |
| 4855 | if (ret != DCMD_TIMEOUT) |
| 4856 | megasas_return_cmd(instance, cmd); |
| 4857 | |
| 4858 | return ret; |
| 4859 | } |
| 4860 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4861 | /* |
| 4862 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4863 | * instance : Controller's instance |
| 4864 | */ |
| 4865 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4866 | { |
| 4867 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4868 | u32 ventura_map_sz = 0; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4869 | |
| 4870 | fusion = instance->ctrl_context; |
| 4871 | /* For MFI based controllers return dummy success */ |
| 4872 | if (!fusion) |
| 4873 | return; |
| 4874 | |
| 4875 | instance->supportmax256vd = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4876 | instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4877 | /* Below is additional check to address future FW enhancement */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4878 | if (instance->ctrl_info_buf->max_lds > 64) |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4879 | instance->supportmax256vd = 1; |
| 4880 | |
| 4881 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4882 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4883 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4884 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4885 | if (instance->supportmax256vd) { |
| 4886 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4887 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4888 | } else { |
| 4889 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4890 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4891 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4892 | |
| 4893 | dev_info(&instance->pdev->dev, |
Shivasharan S | cba67d9 | 2018-10-16 23:37:56 -0700 | [diff] [blame] | 4894 | "FW provided supportMaxExtLDs: %d\tmax_lds: %d\n", |
| 4895 | instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs ? 1 : 0, |
| 4896 | instance->ctrl_info_buf->max_lds); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4897 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4898 | if (instance->max_raid_mapsize) { |
| 4899 | ventura_map_sz = instance->max_raid_mapsize * |
| 4900 | MR_MIN_MAP_SIZE; /* 64k */ |
| 4901 | fusion->current_map_sz = ventura_map_sz; |
| 4902 | fusion->max_map_sz = ventura_map_sz; |
| 4903 | } else { |
| 4904 | fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 4905 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4906 | (instance->fw_supported_vd_count - 1)); |
| 4907 | 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] | 4908 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4909 | fusion->max_map_sz = |
| 4910 | max(fusion->old_map_sz, fusion->new_map_sz); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4911 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4912 | if (instance->supportmax256vd) |
| 4913 | fusion->current_map_sz = fusion->new_map_sz; |
| 4914 | else |
| 4915 | fusion->current_map_sz = fusion->old_map_sz; |
| 4916 | } |
| 4917 | /* irrespective of FW raid maps, driver raid map is constant */ |
| 4918 | 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] | 4919 | } |
| 4920 | |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 4921 | /* |
| 4922 | * dcmd.opcode - MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES |
| 4923 | * dcmd.hdr.length - number of bytes to read |
| 4924 | * dcmd.sge - Ptr to MR_SNAPDUMP_PROPERTIES |
| 4925 | * Desc: Fill in snapdump properties |
| 4926 | * Status: MFI_STAT_OK- Command successful |
| 4927 | */ |
| 4928 | void megasas_get_snapdump_properties(struct megasas_instance *instance) |
| 4929 | { |
| 4930 | int ret = 0; |
| 4931 | struct megasas_cmd *cmd; |
| 4932 | struct megasas_dcmd_frame *dcmd; |
| 4933 | struct MR_SNAPDUMP_PROPERTIES *ci; |
| 4934 | dma_addr_t ci_h = 0; |
| 4935 | |
| 4936 | ci = instance->snapdump_prop; |
| 4937 | ci_h = instance->snapdump_prop_h; |
| 4938 | |
| 4939 | if (!ci) |
| 4940 | return; |
| 4941 | |
| 4942 | cmd = megasas_get_cmd(instance); |
| 4943 | |
| 4944 | if (!cmd) { |
| 4945 | dev_dbg(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4946 | return; |
| 4947 | } |
| 4948 | |
| 4949 | dcmd = &cmd->frame->dcmd; |
| 4950 | |
| 4951 | memset(ci, 0, sizeof(*ci)); |
| 4952 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4953 | |
| 4954 | dcmd->cmd = MFI_CMD_DCMD; |
| 4955 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
| 4956 | dcmd->sge_count = 1; |
| 4957 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 4958 | dcmd->timeout = 0; |
| 4959 | dcmd->pad_0 = 0; |
| 4960 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_SNAPDUMP_PROPERTIES)); |
| 4961 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES); |
| 4962 | |
| 4963 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4964 | sizeof(struct MR_SNAPDUMP_PROPERTIES)); |
| 4965 | |
| 4966 | if (!instance->mask_interrupts) { |
| 4967 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4968 | MFI_IO_TIMEOUT_SECS); |
| 4969 | } else { |
| 4970 | ret = megasas_issue_polled(instance, cmd); |
| 4971 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4972 | } |
| 4973 | |
| 4974 | switch (ret) { |
| 4975 | case DCMD_SUCCESS: |
| 4976 | instance->snapdump_wait_time = |
| 4977 | min_t(u8, ci->trigger_min_num_sec_before_ocr, |
| 4978 | MEGASAS_MAX_SNAP_DUMP_WAIT_TIME); |
| 4979 | break; |
| 4980 | |
| 4981 | case DCMD_TIMEOUT: |
| 4982 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4983 | case INITIATE_OCR: |
| 4984 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4985 | megasas_reset_fusion(instance->host, |
| 4986 | MFI_IO_TIMEOUT_OCR); |
| 4987 | break; |
| 4988 | case KILL_ADAPTER: |
| 4989 | megaraid_sas_kill_hba(instance); |
| 4990 | break; |
| 4991 | case IGNORE_TIMEOUT: |
| 4992 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4993 | __func__, __LINE__); |
| 4994 | break; |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | if (ret != DCMD_TIMEOUT) |
| 4999 | megasas_return_cmd(instance, cmd); |
| 5000 | } |
| 5001 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 5002 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5003 | * megasas_get_controller_info - Returns FW's controller structure |
| 5004 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5005 | * |
| 5006 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 5007 | * This information is mainly used to find out the maximum IO transfer per |
| 5008 | * command supported by the FW. |
| 5009 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5010 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5011 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5012 | { |
| 5013 | int ret = 0; |
| 5014 | struct megasas_cmd *cmd; |
| 5015 | struct megasas_dcmd_frame *dcmd; |
| 5016 | struct megasas_ctrl_info *ci; |
| 5017 | dma_addr_t ci_h = 0; |
| 5018 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 5019 | ci = instance->ctrl_info_buf; |
| 5020 | ci_h = instance->ctrl_info_buf_h; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5021 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5022 | cmd = megasas_get_cmd(instance); |
| 5023 | |
| 5024 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5025 | 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] | 5026 | return -ENOMEM; |
| 5027 | } |
| 5028 | |
| 5029 | dcmd = &cmd->frame->dcmd; |
| 5030 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5031 | memset(ci, 0, sizeof(*ci)); |
| 5032 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5033 | |
| 5034 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5035 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5036 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5037 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5038 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5039 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5040 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 5041 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5042 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5043 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5044 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 5045 | sizeof(struct megasas_ctrl_info)); |
| 5046 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5047 | if ((instance->adapter_type != MFI_SERIES) && |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 5048 | !instance->mask_interrupts) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5049 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 5050 | } else { |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5051 | ret = megasas_issue_polled(instance, cmd); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 5052 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5053 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5054 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5055 | switch (ret) { |
| 5056 | case DCMD_SUCCESS: |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5057 | /* Save required controller information in |
| 5058 | * CPU endianness format. |
| 5059 | */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5060 | le32_to_cpus((u32 *)&ci->properties.OnOffProperties); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5061 | le16_to_cpus((u16 *)&ci->properties.on_off_properties2); |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5062 | le32_to_cpus((u32 *)&ci->adapterOperations2); |
| 5063 | le32_to_cpus((u32 *)&ci->adapterOperations3); |
| 5064 | le16_to_cpus((u16 *)&ci->adapter_operations4); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5065 | |
| 5066 | /* Update the latest Ext VD info. |
| 5067 | * From Init path, store current firmware details. |
| 5068 | * From OCR path, detect any firmware properties changes. |
| 5069 | * in case of Firmware upgrade without system reboot. |
| 5070 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5071 | megasas_update_ext_vd_details(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5072 | instance->use_seqnum_jbod_fp = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5073 | ci->adapterOperations3.useSeqNumJbodFP; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 5074 | instance->support_morethan256jbod = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5075 | ci->adapter_operations4.support_pd_map_target_id; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 5076 | instance->support_nvme_passthru = |
| 5077 | ci->adapter_operations4.support_nvme_passthru; |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 5078 | instance->task_abort_tmo = ci->TaskAbortTO; |
| 5079 | instance->max_reset_tmo = ci->MaxResetTO; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5080 | |
| 5081 | /*Check whether controller is iMR or MR */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5082 | instance->is_imr = (ci->memory_size ? 0 : 1); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5083 | |
| 5084 | instance->snapdump_wait_time = |
| 5085 | (ci->properties.on_off_properties2.enable_snap_dump ? |
| 5086 | MEGASAS_DEFAULT_SNAP_DUMP_WAIT_TIME : 0); |
| 5087 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5088 | instance->enable_fw_dev_list = |
| 5089 | ci->properties.on_off_properties2.enable_fw_dev_list; |
| 5090 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5091 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5092 | "controller type\t: %s(%dMB)\n", |
| 5093 | instance->is_imr ? "iMR" : "MR", |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5094 | le16_to_cpu(ci->memory_size)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5095 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 5096 | instance->disableOnlineCtrlReset = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5097 | ci->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 5098 | instance->secure_jbod_support = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5099 | ci->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5100 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 5101 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 5102 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 5103 | instance->secure_jbod_support ? "Yes" : "No"); |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 5104 | dev_info(&instance->pdev->dev, "NVMe passthru support\t: %s\n", |
| 5105 | instance->support_nvme_passthru ? "Yes" : "No"); |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 5106 | dev_info(&instance->pdev->dev, |
| 5107 | "FW provided TM TaskAbort/Reset timeout\t: %d secs/%d secs\n", |
| 5108 | instance->task_abort_tmo, instance->max_reset_tmo); |
| 5109 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5110 | break; |
| 5111 | |
| 5112 | case DCMD_TIMEOUT: |
| 5113 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5114 | case INITIATE_OCR: |
| 5115 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5116 | megasas_reset_fusion(instance->host, |
| 5117 | MFI_IO_TIMEOUT_OCR); |
| 5118 | break; |
| 5119 | case KILL_ADAPTER: |
| 5120 | megaraid_sas_kill_hba(instance); |
| 5121 | break; |
| 5122 | case IGNORE_TIMEOUT: |
| 5123 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 5124 | __func__, __LINE__); |
| 5125 | break; |
| 5126 | } |
Shivasharan S | 2747e6b | 2018-06-04 03:45:09 -0700 | [diff] [blame] | 5127 | break; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5128 | case DCMD_FAILED: |
| 5129 | megaraid_sas_kill_hba(instance); |
| 5130 | break; |
| 5131 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5132 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5133 | |
Shivasharan S | 2747e6b | 2018-06-04 03:45:09 -0700 | [diff] [blame] | 5134 | if (ret != DCMD_TIMEOUT) |
| 5135 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5136 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5137 | return ret; |
| 5138 | } |
| 5139 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5140 | /* |
| 5141 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 5142 | * to firmware |
| 5143 | * |
| 5144 | * @instance: Adapter soft state |
| 5145 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 5146 | MR_CRASH_BUF_TURN_OFF = 0 |
| 5147 | MR_CRASH_BUF_TURN_ON = 1 |
| 5148 | * @return 0 on success non-zero on failure. |
| 5149 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 5150 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 5151 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 5152 | * crash dump feature is supported by the FW. |
| 5153 | * |
| 5154 | */ |
| 5155 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 5156 | u8 crash_buf_state) |
| 5157 | { |
| 5158 | int ret = 0; |
| 5159 | struct megasas_cmd *cmd; |
| 5160 | struct megasas_dcmd_frame *dcmd; |
| 5161 | |
| 5162 | cmd = megasas_get_cmd(instance); |
| 5163 | |
| 5164 | if (!cmd) { |
| 5165 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 5166 | return -ENOMEM; |
| 5167 | } |
| 5168 | |
| 5169 | |
| 5170 | dcmd = &cmd->frame->dcmd; |
| 5171 | |
| 5172 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5173 | dcmd->mbox.b[0] = crash_buf_state; |
| 5174 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5175 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5176 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5177 | dcmd->flags = MFI_FRAME_DIR_NONE; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5178 | dcmd->timeout = 0; |
| 5179 | dcmd->pad_0 = 0; |
| 5180 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 5181 | 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] | 5182 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5183 | megasas_set_dma_settings(instance, dcmd, instance->crash_dump_h, |
| 5184 | CRASH_DMA_BUF_SIZE); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5185 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5186 | if ((instance->adapter_type != MFI_SERIES) && |
| 5187 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5188 | 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] | 5189 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5190 | ret = megasas_issue_polled(instance, cmd); |
| 5191 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5192 | if (ret == DCMD_TIMEOUT) { |
| 5193 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5194 | case INITIATE_OCR: |
| 5195 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5196 | megasas_reset_fusion(instance->host, |
| 5197 | MFI_IO_TIMEOUT_OCR); |
| 5198 | break; |
| 5199 | case KILL_ADAPTER: |
| 5200 | megaraid_sas_kill_hba(instance); |
| 5201 | break; |
| 5202 | case IGNORE_TIMEOUT: |
| 5203 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 5204 | __func__, __LINE__); |
| 5205 | break; |
| 5206 | } |
| 5207 | } else |
| 5208 | megasas_return_cmd(instance, cmd); |
| 5209 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5210 | return ret; |
| 5211 | } |
| 5212 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5213 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5214 | * megasas_issue_init_mfi - Initializes the FW |
| 5215 | * @instance: Adapter soft state |
| 5216 | * |
| 5217 | * Issues the INIT MFI cmd |
| 5218 | */ |
| 5219 | static int |
| 5220 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 5221 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 5222 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5223 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5224 | struct megasas_init_frame *init_frame; |
| 5225 | struct megasas_init_queue_info *initq_info; |
| 5226 | dma_addr_t init_frame_h; |
| 5227 | dma_addr_t initq_info_h; |
| 5228 | |
| 5229 | /* |
| 5230 | * Prepare a init frame. Note the init frame points to queue info |
| 5231 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 5232 | * this frame - since we don't need any SGL - we use SGL's space as |
| 5233 | * queue info structure |
| 5234 | * |
| 5235 | * We will not get a NULL command below. We just created the pool. |
| 5236 | */ |
| 5237 | cmd = megasas_get_cmd(instance); |
| 5238 | |
| 5239 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 5240 | initq_info = (struct megasas_init_queue_info *) |
| 5241 | ((unsigned long)init_frame + 64); |
| 5242 | |
| 5243 | init_frame_h = cmd->frame_phys_addr; |
| 5244 | initq_info_h = init_frame_h + 64; |
| 5245 | |
| 5246 | context = init_frame->context; |
| 5247 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 5248 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 5249 | init_frame->context = context; |
| 5250 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5251 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 5252 | 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] | 5253 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5254 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 5255 | 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] | 5256 | |
| 5257 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5258 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5259 | init_frame->queue_info_new_phys_addr_lo = |
| 5260 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 5261 | init_frame->queue_info_new_phys_addr_hi = |
| 5262 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5263 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5264 | 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] | 5265 | |
| 5266 | /* |
| 5267 | * disable the intr before firing the init frame to FW |
| 5268 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5269 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5270 | |
| 5271 | /* |
| 5272 | * Issue the init frame in polled mode |
| 5273 | */ |
| 5274 | |
| 5275 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5276 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5277 | megasas_return_cmd(instance, cmd); |
| 5278 | goto fail_fw_init; |
| 5279 | } |
| 5280 | |
| 5281 | megasas_return_cmd(instance, cmd); |
| 5282 | |
| 5283 | return 0; |
| 5284 | |
| 5285 | fail_fw_init: |
| 5286 | return -EINVAL; |
| 5287 | } |
| 5288 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5289 | static u32 |
| 5290 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5291 | { |
| 5292 | u32 context_sz; |
| 5293 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5294 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5295 | /* |
| 5296 | * Get various operational parameters from status register |
| 5297 | */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5298 | instance->max_fw_cmds = instance->instancet->read_fw_status_reg(instance) & 0x00FFFF; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 5299 | /* |
| 5300 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 5301 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 5302 | * does not exceed max cmds that the FW can support |
| 5303 | */ |
| 5304 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5305 | instance->max_mfi_cmds = instance->max_fw_cmds; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5306 | instance->max_num_sge = (instance->instancet->read_fw_status_reg(instance) & 0xFF0000) >> |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 5307 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5308 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 5309 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 5310 | * are reserved for IOCTL + driver's internal DCMDs. |
| 5311 | */ |
| 5312 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 5313 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 5314 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 5315 | MEGASAS_SKINNY_INT_CMDS); |
| 5316 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 5317 | } else { |
| 5318 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 5319 | MEGASAS_INT_CMDS); |
| 5320 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 5321 | } |
| 5322 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 5323 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 5324 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5325 | * Create a pool of commands |
| 5326 | */ |
| 5327 | if (megasas_alloc_cmds(instance)) |
| 5328 | goto fail_alloc_cmds; |
| 5329 | |
| 5330 | /* |
| 5331 | * Allocate memory for reply queue. Length of reply queue should |
| 5332 | * be _one_ more than the maximum commands handled by the firmware. |
| 5333 | * |
| 5334 | * Note: When FW completes commands, it places corresponding contex |
| 5335 | * values in this circular reply queue. This circular queue is a fairly |
| 5336 | * typical producer-consumer queue. FW is the producer (of completed |
| 5337 | * commands) and the driver is the consumer. |
| 5338 | */ |
| 5339 | context_sz = sizeof(u32); |
| 5340 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 5341 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5342 | instance->reply_queue = dma_alloc_coherent(&instance->pdev->dev, |
| 5343 | reply_q_sz, &instance->reply_queue_h, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5344 | |
| 5345 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5346 | 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] | 5347 | goto fail_reply_queue; |
| 5348 | } |
| 5349 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5350 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5351 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5352 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5353 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5354 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 5355 | "Fail from %s %d\n", instance->unique_id, |
| 5356 | __func__, __LINE__); |
| 5357 | goto fail_fw_init; |
| 5358 | } |
| 5359 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5360 | instance->fw_support_ieee = 0; |
| 5361 | instance->fw_support_ieee = |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5362 | (instance->instancet->read_fw_status_reg(instance) & |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5363 | 0x04000000); |
| 5364 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5365 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5366 | instance->fw_support_ieee); |
| 5367 | |
| 5368 | if (instance->fw_support_ieee) |
| 5369 | instance->flag_ieee = 1; |
| 5370 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5371 | return 0; |
| 5372 | |
| 5373 | fail_fw_init: |
| 5374 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5375 | dma_free_coherent(&instance->pdev->dev, reply_q_sz, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5376 | instance->reply_queue, instance->reply_queue_h); |
| 5377 | fail_reply_queue: |
| 5378 | megasas_free_cmds(instance); |
| 5379 | |
| 5380 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5381 | return 1; |
| 5382 | } |
| 5383 | |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 5384 | static |
| 5385 | void megasas_setup_irq_poll(struct megasas_instance *instance) |
| 5386 | { |
| 5387 | struct megasas_irq_context *irq_ctx; |
| 5388 | u32 count, i; |
| 5389 | |
| 5390 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 5391 | |
| 5392 | /* Initialize IRQ poll */ |
| 5393 | for (i = 0; i < count; i++) { |
| 5394 | irq_ctx = &instance->irq_context[i]; |
| 5395 | irq_ctx->os_irq = pci_irq_vector(instance->pdev, i); |
| 5396 | irq_ctx->irq_poll_scheduled = false; |
| 5397 | irq_poll_init(&irq_ctx->irqpoll, |
| 5398 | instance->threshold_reply_count, |
| 5399 | megasas_irqpoll); |
| 5400 | } |
| 5401 | } |
| 5402 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5403 | /* |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5404 | * megasas_setup_irqs_ioapic - register legacy interrupts. |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5405 | * @instance: Adapter soft state |
| 5406 | * |
| 5407 | * Do not enable interrupt, only setup ISRs. |
| 5408 | * |
| 5409 | * Return 0 on success. |
| 5410 | */ |
| 5411 | static int |
| 5412 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 5413 | { |
| 5414 | struct pci_dev *pdev; |
| 5415 | |
| 5416 | pdev = instance->pdev; |
| 5417 | instance->irq_context[0].instance = instance; |
| 5418 | instance->irq_context[0].MSIxIndex = 0; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5419 | if (request_irq(pci_irq_vector(pdev, 0), |
| 5420 | instance->instancet->service_isr, IRQF_SHARED, |
| 5421 | "megasas", &instance->irq_context[0])) { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5422 | dev_err(&instance->pdev->dev, |
| 5423 | "Failed to register IRQ from %s %d\n", |
| 5424 | __func__, __LINE__); |
| 5425 | return -1; |
| 5426 | } |
| 5427 | return 0; |
| 5428 | } |
| 5429 | |
| 5430 | /** |
| 5431 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 5432 | * @instance: Adapter soft state |
| 5433 | * @is_probe: Driver probe check |
| 5434 | * |
| 5435 | * Do not enable interrupt, only setup ISRs. |
| 5436 | * |
| 5437 | * Return 0 on success. |
| 5438 | */ |
| 5439 | static int |
| 5440 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 5441 | { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5442 | int i, j; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5443 | struct pci_dev *pdev; |
| 5444 | |
| 5445 | pdev = instance->pdev; |
| 5446 | |
| 5447 | /* Try MSI-x */ |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5448 | for (i = 0; i < instance->msix_vectors; i++) { |
| 5449 | instance->irq_context[i].instance = instance; |
| 5450 | instance->irq_context[i].MSIxIndex = i; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5451 | if (request_irq(pci_irq_vector(pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5452 | instance->instancet->service_isr, 0, "megasas", |
| 5453 | &instance->irq_context[i])) { |
| 5454 | dev_err(&instance->pdev->dev, |
| 5455 | "Failed to register IRQ for vector %d.\n", i); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5456 | for (j = 0; j < i; j++) |
| 5457 | free_irq(pci_irq_vector(pdev, j), |
| 5458 | &instance->irq_context[j]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5459 | /* Retry irq register for IO_APIC*/ |
| 5460 | instance->msix_vectors = 0; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5461 | instance->msix_load_balance = false; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5462 | if (is_probe) { |
| 5463 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5464 | return megasas_setup_irqs_ioapic(instance); |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5465 | } else { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5466 | return -1; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5467 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5468 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5469 | } |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5470 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5471 | return 0; |
| 5472 | } |
| 5473 | |
| 5474 | /* |
| 5475 | * megasas_destroy_irqs- unregister interrupts. |
| 5476 | * @instance: Adapter soft state |
| 5477 | * return: void |
| 5478 | */ |
| 5479 | static void |
| 5480 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 5481 | |
| 5482 | int i; |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 5483 | int count; |
| 5484 | struct megasas_irq_context *irq_ctx; |
| 5485 | |
| 5486 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 5487 | if (instance->adapter_type != MFI_SERIES) { |
| 5488 | for (i = 0; i < count; i++) { |
| 5489 | irq_ctx = &instance->irq_context[i]; |
| 5490 | irq_poll_disable(&irq_ctx->irqpoll); |
| 5491 | } |
| 5492 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5493 | |
| 5494 | if (instance->msix_vectors) |
| 5495 | for (i = 0; i < instance->msix_vectors; i++) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5496 | free_irq(pci_irq_vector(instance->pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5497 | &instance->irq_context[i]); |
| 5498 | } |
| 5499 | else |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5500 | free_irq(pci_irq_vector(instance->pdev, 0), |
| 5501 | &instance->irq_context[0]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5502 | } |
| 5503 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5504 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5505 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 5506 | * @instance: Adapter soft state |
| 5507 | * @is_probe: Driver probe check |
| 5508 | * |
| 5509 | * Return 0 on success. |
| 5510 | */ |
| 5511 | void |
| 5512 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 5513 | { |
| 5514 | int i; |
| 5515 | struct fusion_context *fusion = instance->ctrl_context; |
| 5516 | u32 pd_seq_map_sz; |
| 5517 | |
| 5518 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 5519 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 5520 | |
| 5521 | if (reset_devices || !fusion || |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5522 | !instance->ctrl_info_buf->adapterOperations3.useSeqNumJbodFP) { |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5523 | dev_info(&instance->pdev->dev, |
| 5524 | "Jbod map is not supported %s %d\n", |
| 5525 | __func__, __LINE__); |
| 5526 | instance->use_seqnum_jbod_fp = false; |
| 5527 | return; |
| 5528 | } |
| 5529 | |
| 5530 | if (fusion->pd_seq_sync[0]) |
| 5531 | goto skip_alloc; |
| 5532 | |
| 5533 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 5534 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 5535 | (&instance->pdev->dev, pd_seq_map_sz, |
| 5536 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 5537 | if (!fusion->pd_seq_sync[i]) { |
| 5538 | dev_err(&instance->pdev->dev, |
| 5539 | "Failed to allocate memory from %s %d\n", |
| 5540 | __func__, __LINE__); |
| 5541 | if (i == 1) { |
| 5542 | dma_free_coherent(&instance->pdev->dev, |
| 5543 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 5544 | fusion->pd_seq_phys[0]); |
| 5545 | fusion->pd_seq_sync[0] = NULL; |
| 5546 | } |
| 5547 | instance->use_seqnum_jbod_fp = false; |
| 5548 | return; |
| 5549 | } |
| 5550 | } |
| 5551 | |
| 5552 | skip_alloc: |
| 5553 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 5554 | !megasas_sync_pd_seq_num(instance, true)) |
| 5555 | instance->use_seqnum_jbod_fp = true; |
| 5556 | else |
| 5557 | instance->use_seqnum_jbod_fp = false; |
| 5558 | } |
| 5559 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5560 | static void megasas_setup_reply_map(struct megasas_instance *instance) |
| 5561 | { |
| 5562 | const struct cpumask *mask; |
| 5563 | unsigned int queue, cpu; |
| 5564 | |
| 5565 | for (queue = 0; queue < instance->msix_vectors; queue++) { |
| 5566 | mask = pci_irq_get_affinity(instance->pdev, queue); |
| 5567 | if (!mask) |
| 5568 | goto fallback; |
| 5569 | |
| 5570 | for_each_cpu(cpu, mask) |
| 5571 | instance->reply_map[cpu] = queue; |
| 5572 | } |
| 5573 | return; |
| 5574 | |
| 5575 | fallback: |
| 5576 | for_each_possible_cpu(cpu) |
| 5577 | instance->reply_map[cpu] = cpu % instance->msix_vectors; |
| 5578 | } |
| 5579 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5580 | /** |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5581 | * megasas_get_device_list - Get the PD and LD device list from FW. |
| 5582 | * @instance: Adapter soft state |
| 5583 | * @return: Success or failure |
| 5584 | * |
| 5585 | * Issue DCMDs to Firmware to get the PD and LD list. |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5586 | * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination |
| 5587 | * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list. |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5588 | */ |
| 5589 | static |
| 5590 | int megasas_get_device_list(struct megasas_instance *instance) |
| 5591 | { |
| 5592 | memset(instance->pd_list, 0, |
| 5593 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
| 5594 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
| 5595 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5596 | if (instance->enable_fw_dev_list) { |
| 5597 | if (megasas_host_device_list_query(instance, true)) |
| 5598 | return FAILED; |
| 5599 | } else { |
| 5600 | if (megasas_get_pd_list(instance) < 0) { |
| 5601 | dev_err(&instance->pdev->dev, "failed to get PD list\n"); |
| 5602 | return FAILED; |
| 5603 | } |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5604 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5605 | if (megasas_ld_list_query(instance, |
| 5606 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) { |
| 5607 | dev_err(&instance->pdev->dev, "failed to get LD list\n"); |
| 5608 | return FAILED; |
| 5609 | } |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | return SUCCESS; |
| 5613 | } |
| 5614 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5615 | * megasas_init_fw - Initializes the FW |
| 5616 | * @instance: Adapter soft state |
| 5617 | * |
| 5618 | * This is the main function for initializing firmware |
| 5619 | */ |
| 5620 | |
| 5621 | static int megasas_init_fw(struct megasas_instance *instance) |
| 5622 | { |
| 5623 | u32 max_sectors_1; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5624 | u32 max_sectors_2, tmp_sectors, msix_enable; |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5625 | u32 scratch_pad_1, scratch_pad_2, scratch_pad_3, status_reg; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5626 | resource_size_t base_addr; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5627 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5628 | unsigned long bar_list; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5629 | int i, j, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5630 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5631 | struct fusion_context *fusion; |
| 5632 | |
| 5633 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5634 | |
| 5635 | /* Find first memory bar */ |
| 5636 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
Christophe JAILLET | 51f9039 | 2016-08-21 10:28:25 +0200 | [diff] [blame] | 5637 | instance->bar = find_first_bit(&bar_list, BITS_PER_LONG); |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5638 | if (pci_request_selected_regions(instance->pdev, 1<<instance->bar, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5639 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5640 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5641 | return -EBUSY; |
| 5642 | } |
| 5643 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5644 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 5645 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5646 | |
| 5647 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5648 | 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] | 5649 | goto fail_ioremap; |
| 5650 | } |
| 5651 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5652 | if (instance->adapter_type != MFI_SERIES) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5653 | instance->instancet = &megasas_instance_template_fusion; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5654 | else { |
| 5655 | switch (instance->pdev->device) { |
| 5656 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 5657 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 5658 | instance->instancet = &megasas_instance_template_ppc; |
| 5659 | break; |
| 5660 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 5661 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 5662 | instance->instancet = &megasas_instance_template_gen2; |
| 5663 | break; |
| 5664 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 5665 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 5666 | instance->instancet = &megasas_instance_template_skinny; |
| 5667 | break; |
| 5668 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 5669 | case PCI_DEVICE_ID_DELL_PERC5: |
| 5670 | default: |
| 5671 | instance->instancet = &megasas_instance_template_xscale; |
| 5672 | instance->pd_list_not_supported = 1; |
| 5673 | break; |
| 5674 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5675 | } |
| 5676 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5677 | if (megasas_transition_to_ready(instance, 0)) { |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame] | 5678 | dev_info(&instance->pdev->dev, |
| 5679 | "Failed to transition controller to ready from %s!\n", |
| 5680 | __func__); |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5681 | if (instance->adapter_type != MFI_SERIES) { |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5682 | status_reg = instance->instancet->read_fw_status_reg( |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5683 | instance); |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5684 | if (status_reg & MFI_RESET_ADAPTER) { |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame] | 5685 | if (megasas_adp_reset_wait_for_ready |
| 5686 | (instance, true, 0) == FAILED) |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5687 | goto fail_ready_state; |
| 5688 | } else { |
| 5689 | goto fail_ready_state; |
| 5690 | } |
| 5691 | } else { |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5692 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 5693 | instance->instancet->adp_reset |
| 5694 | (instance, instance->reg_set); |
| 5695 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5696 | |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5697 | /*waiting for about 30 second before retry*/ |
| 5698 | ssleep(30); |
| 5699 | |
| 5700 | if (megasas_transition_to_ready(instance, 0)) |
| 5701 | goto fail_ready_state; |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5702 | } |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame] | 5703 | |
| 5704 | dev_info(&instance->pdev->dev, |
| 5705 | "FW restarted successfully from %s!\n", |
| 5706 | __func__); |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5707 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5708 | |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5709 | megasas_init_ctrl_params(instance); |
| 5710 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5711 | if (megasas_set_dma_mask(instance)) |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5712 | goto fail_ready_state; |
| 5713 | |
| 5714 | if (megasas_alloc_ctrl_mem(instance)) |
| 5715 | goto fail_alloc_dma_buf; |
| 5716 | |
| 5717 | if (megasas_alloc_ctrl_dma_buffers(instance)) |
| 5718 | goto fail_alloc_dma_buf; |
| 5719 | |
| 5720 | fusion = instance->ctrl_context; |
| 5721 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 5722 | if (instance->adapter_type >= VENTURA_SERIES) { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5723 | scratch_pad_2 = |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5724 | megasas_readl(instance, |
| 5725 | &instance->reg_set->outbound_scratch_pad_2); |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5726 | instance->max_raid_mapsize = ((scratch_pad_2 >> |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5727 | MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) & |
| 5728 | MR_MAX_RAID_MAP_SIZE_MASK); |
| 5729 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5730 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5731 | /* Check if MSI-X is supported while in ready state */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5732 | msix_enable = (instance->instancet->read_fw_status_reg(instance) & |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5733 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5734 | if (msix_enable && !msix_disable) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5735 | int irq_flags = PCI_IRQ_MSIX; |
| 5736 | |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5737 | scratch_pad_1 = megasas_readl |
| 5738 | (instance, &instance->reg_set->outbound_scratch_pad_1); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5739 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5740 | if (fusion) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 5741 | if (instance->adapter_type == THUNDERBOLT_SERIES) { |
| 5742 | /* Thunderbolt Series*/ |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5743 | instance->msix_vectors = (scratch_pad_1 |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5744 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 5745 | fw_msix_count = instance->msix_vectors; |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5746 | } else { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5747 | instance->msix_vectors = ((scratch_pad_1 |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5748 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 5749 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5750 | |
| 5751 | /* |
| 5752 | * For Invader series, > 8 MSI-x vectors |
| 5753 | * supported by FW/HW implies combined |
| 5754 | * reply queue mode is enabled. |
| 5755 | * For Ventura series, > 16 MSI-x vectors |
| 5756 | * supported by FW/HW implies combined |
| 5757 | * reply queue mode is enabled. |
| 5758 | */ |
| 5759 | switch (instance->adapter_type) { |
| 5760 | case INVADER_SERIES: |
| 5761 | if (instance->msix_vectors > 8) |
| 5762 | instance->msix_combined = true; |
| 5763 | break; |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 5764 | case AERO_SERIES: |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5765 | case VENTURA_SERIES: |
| 5766 | if (instance->msix_vectors > 16) |
| 5767 | instance->msix_combined = true; |
| 5768 | break; |
| 5769 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5770 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5771 | if (rdpq_enable) |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5772 | instance->is_rdpq = (scratch_pad_1 & MR_RDPQ_MODE_OFFSET) ? |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5773 | 1 : 0; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5774 | |
| 5775 | if (!instance->msix_combined) { |
| 5776 | instance->msix_load_balance = true; |
| 5777 | instance->smp_affinity_enable = false; |
| 5778 | } |
| 5779 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5780 | fw_msix_count = instance->msix_vectors; |
| 5781 | /* Save 1-15 reply post index address to local memory |
| 5782 | * Index 0 is already saved from reg offset |
| 5783 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 5784 | */ |
| 5785 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 5786 | instance->reply_post_host_index_addr[loop] = |
| 5787 | (u32 __iomem *) |
| 5788 | ((u8 __iomem *)instance->reg_set + |
| 5789 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 5790 | + (loop * 0x10)); |
| 5791 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5792 | } |
| 5793 | if (msix_vectors) |
| 5794 | instance->msix_vectors = min(msix_vectors, |
| 5795 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5796 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5797 | instance->msix_vectors = 1; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5798 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5799 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 5800 | instance->msix_vectors = min(instance->msix_vectors, |
| 5801 | (unsigned int)num_online_cpus()); |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5802 | if (instance->smp_affinity_enable) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5803 | irq_flags |= PCI_IRQ_AFFINITY; |
| 5804 | i = pci_alloc_irq_vectors(instance->pdev, 1, |
| 5805 | instance->msix_vectors, irq_flags); |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5806 | if (i > 0) { |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5807 | instance->msix_vectors = i; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5808 | } else { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5809 | instance->msix_vectors = 0; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5810 | instance->msix_load_balance = false; |
| 5811 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5812 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5813 | /* |
| 5814 | * MSI-X host index 0 is common for all adapter. |
| 5815 | * It is used for all MPT based Adapters. |
| 5816 | */ |
| 5817 | if (instance->msix_combined) { |
| 5818 | instance->reply_post_host_index_addr[0] = |
| 5819 | (u32 *)((u8 *)instance->reg_set + |
| 5820 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET); |
| 5821 | } else { |
| 5822 | instance->reply_post_host_index_addr[0] = |
| 5823 | (u32 *)((u8 *)instance->reg_set + |
| 5824 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 5825 | } |
| 5826 | |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5827 | if (!instance->msix_vectors) { |
| 5828 | i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 5829 | if (i < 0) |
Shivasharan S | 8a25fa1 | 2018-10-16 23:37:44 -0700 | [diff] [blame] | 5830 | goto fail_init_adapter; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5831 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5832 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5833 | megasas_setup_reply_map(instance); |
| 5834 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5835 | dev_info(&instance->pdev->dev, |
| 5836 | "firmware supports msix\t: (%d)", fw_msix_count); |
| 5837 | dev_info(&instance->pdev->dev, |
| 5838 | "current msix/online cpus\t: (%d/%d)\n", |
| 5839 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5840 | dev_info(&instance->pdev->dev, |
| 5841 | "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5842 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 5843 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5844 | (unsigned long)instance); |
| 5845 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5846 | /* |
| 5847 | * Below are default value for legacy Firmware. |
| 5848 | * non-fusion based controllers |
| 5849 | */ |
| 5850 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 5851 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5852 | /* Get operational params, sge flags, send init cmd to controller */ |
| 5853 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5854 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5855 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 5856 | if (instance->adapter_type >= VENTURA_SERIES) { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5857 | scratch_pad_3 = |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5858 | megasas_readl(instance, |
| 5859 | &instance->reg_set->outbound_scratch_pad_3); |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5860 | if ((scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK) >= |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5861 | MR_DEFAULT_NVME_PAGE_SHIFT) |
| 5862 | instance->nvme_page_size = |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5863 | (1 << (scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK)); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5864 | |
| 5865 | dev_info(&instance->pdev->dev, |
| 5866 | "NVME page size\t: (%d)\n", instance->nvme_page_size); |
| 5867 | } |
| 5868 | |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 5869 | if (instance->msix_vectors ? |
| 5870 | megasas_setup_irqs_msix(instance, 1) : |
| 5871 | megasas_setup_irqs_ioapic(instance)) |
| 5872 | goto fail_init_adapter; |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 5873 | |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 5874 | if (instance->adapter_type != MFI_SERIES) |
| 5875 | megasas_setup_irq_poll(instance); |
| 5876 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5877 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5878 | |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 5879 | dev_info(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5880 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5881 | megasas_setup_jbod_map(instance); |
| 5882 | |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5883 | if (megasas_get_device_list(instance) != SUCCESS) { |
| 5884 | dev_err(&instance->pdev->dev, |
| 5885 | "%s: megasas_get_device_list failed\n", |
| 5886 | __func__); |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 5887 | goto fail_get_ld_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 5888 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 5889 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5890 | /* stream detection initialization */ |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 5891 | if (instance->adapter_type >= VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5892 | fusion->stream_detect_by_ld = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 5893 | kcalloc(MAX_LOGICAL_DRIVES_EXT, |
| 5894 | sizeof(struct LD_STREAM_DETECT *), |
| 5895 | GFP_KERNEL); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5896 | if (!fusion->stream_detect_by_ld) { |
| 5897 | dev_err(&instance->pdev->dev, |
Shivasharan S | 41064f1 | 2017-02-10 00:59:37 -0800 | [diff] [blame] | 5898 | "unable to allocate stream detection for pool of LDs\n"); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5899 | goto fail_get_ld_pd_list; |
| 5900 | } |
| 5901 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) { |
| 5902 | fusion->stream_detect_by_ld[i] = |
Shivasharan S | e05ee4e | 2018-01-05 05:27:36 -0800 | [diff] [blame] | 5903 | kzalloc(sizeof(struct LD_STREAM_DETECT), |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 5904 | GFP_KERNEL); |
| 5905 | if (!fusion->stream_detect_by_ld[i]) { |
| 5906 | dev_err(&instance->pdev->dev, |
| 5907 | "unable to allocate stream detect by LD\n "); |
| 5908 | for (j = 0; j < i; ++j) |
| 5909 | kfree(fusion->stream_detect_by_ld[j]); |
| 5910 | kfree(fusion->stream_detect_by_ld); |
| 5911 | fusion->stream_detect_by_ld = NULL; |
| 5912 | goto fail_get_ld_pd_list; |
| 5913 | } |
| 5914 | fusion->stream_detect_by_ld[i]->mru_bit_map |
| 5915 | = MR_STREAM_BITMAP; |
| 5916 | } |
| 5917 | } |
| 5918 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5919 | /* |
| 5920 | * Compute the max allowed sectors per IO: The controller info has two |
| 5921 | * limits on max sectors. Driver should use the minimum of these two. |
| 5922 | * |
| 5923 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 5924 | * |
| 5925 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 5926 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 5927 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5928 | tmp_sectors = 0; |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5929 | ctrl_info = instance->ctrl_info_buf; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5930 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5931 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 5932 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 5933 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5934 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 5935 | 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] | 5936 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 5937 | instance->peerIsPresent = ctrl_info->cluster.peerIsPresent; |
| 5938 | instance->passive = ctrl_info->cluster.passive; |
| 5939 | memcpy(instance->clusterId, ctrl_info->clusterId, sizeof(instance->clusterId)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5940 | instance->UnevenSpanSupport = |
| 5941 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 5942 | if (instance->UnevenSpanSupport) { |
| 5943 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 5944 | if (MR_ValidateMapInfo(instance, instance->map_id)) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5945 | fusion->fast_path_io = 1; |
| 5946 | else |
| 5947 | fusion->fast_path_io = 0; |
| 5948 | |
| 5949 | } |
| 5950 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5951 | instance->requestorId = ctrl_info->iov.requestorId; |
| 5952 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 5953 | if (!ctrl_info->adapterOperations2.activePassive) |
| 5954 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5955 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5956 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 5957 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 5958 | |
| 5959 | if (instance->PlasmaFW111) { |
| 5960 | iovPtr = (struct IOV_111 *) |
| 5961 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 5962 | instance->requestorId = iovPtr->requestorId; |
| 5963 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5964 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 5965 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 5966 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5967 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5968 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5969 | instance->crash_dump_fw_support = |
| 5970 | ctrl_info->adapterOperations3.supportCrashDump; |
| 5971 | instance->crash_dump_drv_support = |
| 5972 | (instance->crash_dump_fw_support && |
| 5973 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5974 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5975 | megasas_set_crash_dump_params(instance, |
| 5976 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5977 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5978 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5979 | if (instance->crash_dump_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5980 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5981 | CRASH_DMA_BUF_SIZE, |
| 5982 | instance->crash_dump_buf, |
| 5983 | instance->crash_dump_h); |
| 5984 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 5985 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 5986 | |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5987 | if (instance->snapdump_wait_time) { |
| 5988 | megasas_get_snapdump_properties(instance); |
| 5989 | dev_info(&instance->pdev->dev, "Snap dump wait time\t: %d\n", |
| 5990 | instance->snapdump_wait_time); |
| 5991 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 5992 | |
| 5993 | dev_info(&instance->pdev->dev, |
| 5994 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 5995 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 5996 | le16_to_cpu(ctrl_info->pci.device_id), |
| 5997 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 5998 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 5999 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 6000 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 6001 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 6002 | instance->crash_dump_drv_support ? "yes" : "no"); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6003 | dev_info(&instance->pdev->dev, "jbod sync map : %s\n", |
| 6004 | instance->use_seqnum_jbod_fp ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 6005 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 6006 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 6007 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 6008 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 6009 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6010 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6011 | /* Check for valid throttlequeuedepth module parameter */ |
| 6012 | if (throttlequeuedepth && |
| 6013 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 6014 | instance->throttlequeuedepth = throttlequeuedepth; |
| 6015 | else |
| 6016 | instance->throttlequeuedepth = |
| 6017 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 6018 | |
Shivasharan S | e636a7a | 2017-08-23 04:46:56 -0700 | [diff] [blame] | 6019 | if ((resetwaittime < 1) || |
| 6020 | (resetwaittime > MEGASAS_RESET_WAIT_TIME)) |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 6021 | resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 6022 | |
| 6023 | if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT)) |
| 6024 | scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6025 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6026 | /* Launch SR-IOV heartbeat timer */ |
| 6027 | if (instance->requestorId) { |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 6028 | if (!megasas_sriov_start_heartbeat(instance, 1)) { |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 6029 | megasas_start_timer(instance); |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 6030 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6031 | instance->skip_heartbeat_timer_del = 1; |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 6032 | goto fail_get_ld_pd_list; |
| 6033 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6034 | } |
| 6035 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6036 | /* |
| 6037 | * Create and start watchdog thread which will monitor |
| 6038 | * controller state every 1 sec and trigger OCR when |
| 6039 | * it enters fault state |
| 6040 | */ |
| 6041 | if (instance->adapter_type != MFI_SERIES) |
| 6042 | if (megasas_fusion_start_watchdog(instance) != SUCCESS) |
| 6043 | goto fail_start_watchdog; |
| 6044 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6045 | return 0; |
| 6046 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6047 | fail_start_watchdog: |
| 6048 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6049 | del_timer_sync(&instance->sriov_heartbeat_timer); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6050 | fail_get_ld_pd_list: |
| 6051 | instance->instancet->disable_intr(instance); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6052 | megasas_destroy_irqs(instance); |
Shivasharan S | 8a25fa1 | 2018-10-16 23:37:44 -0700 | [diff] [blame] | 6053 | fail_init_adapter: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6054 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6055 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6056 | instance->msix_vectors = 0; |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 6057 | fail_alloc_dma_buf: |
| 6058 | megasas_free_ctrl_dma_buffers(instance); |
| 6059 | megasas_free_ctrl_mem(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 6060 | fail_ready_state: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6061 | iounmap(instance->reg_set); |
| 6062 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 6063 | fail_ioremap: |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 6064 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6065 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 6066 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 6067 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6068 | return -EINVAL; |
| 6069 | } |
| 6070 | |
| 6071 | /** |
| 6072 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 6073 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6074 | */ |
| 6075 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 6076 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6077 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6078 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6079 | if (instance->reply_queue) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6080 | dma_free_coherent(&instance->pdev->dev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6081 | instance->reply_queue, instance->reply_queue_h); |
| 6082 | |
| 6083 | megasas_free_cmds(instance); |
| 6084 | |
| 6085 | iounmap(instance->reg_set); |
| 6086 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 6087 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6088 | } |
| 6089 | |
| 6090 | /** |
| 6091 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 6092 | * @instance: Adapter soft state |
| 6093 | * @eli: FW event log sequence numbers information |
| 6094 | * |
| 6095 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 6096 | * usually find out the latest sequence number of the events, the seq number at |
| 6097 | * the boot etc. They would "read" all the events below the latest seq number |
| 6098 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 6099 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 6100 | * wait for the events to happen. |
| 6101 | */ |
| 6102 | static int |
| 6103 | megasas_get_seq_num(struct megasas_instance *instance, |
| 6104 | struct megasas_evt_log_info *eli) |
| 6105 | { |
| 6106 | struct megasas_cmd *cmd; |
| 6107 | struct megasas_dcmd_frame *dcmd; |
| 6108 | struct megasas_evt_log_info *el_info; |
| 6109 | dma_addr_t el_info_h = 0; |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6110 | int ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6111 | |
| 6112 | cmd = megasas_get_cmd(instance); |
| 6113 | |
| 6114 | if (!cmd) { |
| 6115 | return -ENOMEM; |
| 6116 | } |
| 6117 | |
| 6118 | dcmd = &cmd->frame->dcmd; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6119 | el_info = dma_alloc_coherent(&instance->pdev->dev, |
| 6120 | sizeof(struct megasas_evt_log_info), |
| 6121 | &el_info_h, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6122 | if (!el_info) { |
| 6123 | megasas_return_cmd(instance, cmd); |
| 6124 | return -ENOMEM; |
| 6125 | } |
| 6126 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6127 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6128 | |
| 6129 | dcmd->cmd = MFI_CMD_DCMD; |
| 6130 | dcmd->cmd_status = 0x0; |
| 6131 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6132 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6133 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6134 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6135 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 6136 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6137 | |
| 6138 | megasas_set_dma_settings(instance, dcmd, el_info_h, |
| 6139 | sizeof(struct megasas_evt_log_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6140 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6141 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 6142 | if (ret != DCMD_SUCCESS) { |
| 6143 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 6144 | __func__, __LINE__); |
| 6145 | goto dcmd_failed; |
| 6146 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6147 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6148 | /* |
| 6149 | * Copy the data back into callers buffer |
| 6150 | */ |
| 6151 | eli->newest_seq_num = el_info->newest_seq_num; |
| 6152 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 6153 | eli->clear_seq_num = el_info->clear_seq_num; |
| 6154 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 6155 | eli->boot_seq_num = el_info->boot_seq_num; |
| 6156 | |
| 6157 | dcmd_failed: |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6158 | dma_free_coherent(&instance->pdev->dev, |
| 6159 | sizeof(struct megasas_evt_log_info), |
| 6160 | el_info, el_info_h); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6161 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6162 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6163 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6164 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | /** |
| 6168 | * megasas_register_aen - Registers for asynchronous event notification |
| 6169 | * @instance: Adapter soft state |
| 6170 | * @seq_num: The starting sequence number |
| 6171 | * @class_locale: Class of the event |
| 6172 | * |
| 6173 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 6174 | * to be notified if and only if the event is of type @class_locale |
| 6175 | */ |
| 6176 | static int |
| 6177 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 6178 | u32 class_locale_word) |
| 6179 | { |
| 6180 | int ret_val; |
| 6181 | struct megasas_cmd *cmd; |
| 6182 | struct megasas_dcmd_frame *dcmd; |
| 6183 | union megasas_evt_class_locale curr_aen; |
| 6184 | union megasas_evt_class_locale prev_aen; |
| 6185 | |
| 6186 | /* |
| 6187 | * If there an AEN pending already (aen_cmd), check if the |
| 6188 | * class_locale of that pending AEN is inclusive of the new |
| 6189 | * AEN request we currently have. If it is, then we don't have |
| 6190 | * to do anything. In other words, whichever events the current |
| 6191 | * AEN request is subscribing to, have already been subscribed |
| 6192 | * to. |
| 6193 | * |
| 6194 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 6195 | * that command, form a class_locale that is superset of both |
| 6196 | * old and current and re-issue to the FW |
| 6197 | */ |
| 6198 | |
| 6199 | curr_aen.word = class_locale_word; |
| 6200 | |
| 6201 | if (instance->aen_cmd) { |
| 6202 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 6203 | prev_aen.word = |
| 6204 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6205 | |
Shivasharan S | 91b3d9f | 2017-08-23 04:47:01 -0700 | [diff] [blame] | 6206 | if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) || |
| 6207 | (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) { |
| 6208 | dev_info(&instance->pdev->dev, |
| 6209 | "%s %d out of range class %d send by application\n", |
| 6210 | __func__, __LINE__, curr_aen.members.class); |
| 6211 | return 0; |
| 6212 | } |
| 6213 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6214 | /* |
| 6215 | * A class whose enum value is smaller is inclusive of all |
| 6216 | * higher values. If a PROGRESS (= -1) was previously |
| 6217 | * registered, then a new registration requests for higher |
| 6218 | * classes need not be sent to FW. They are automatically |
| 6219 | * included. |
| 6220 | * |
| 6221 | * Locale numbers don't have such hierarchy. They are bitmap |
| 6222 | * values |
| 6223 | */ |
| 6224 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 6225 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6226 | curr_aen.members.locale)) { |
| 6227 | /* |
| 6228 | * Previously issued event registration includes |
| 6229 | * current request. Nothing to do. |
| 6230 | */ |
| 6231 | return 0; |
| 6232 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 6233 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6234 | |
| 6235 | if (prev_aen.members.class < curr_aen.members.class) |
| 6236 | curr_aen.members.class = prev_aen.members.class; |
| 6237 | |
| 6238 | instance->aen_cmd->abort_aen = 1; |
| 6239 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 6240 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6241 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6242 | |
| 6243 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6244 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6245 | "previous AEN command\n"); |
| 6246 | return ret_val; |
| 6247 | } |
| 6248 | } |
| 6249 | } |
| 6250 | |
| 6251 | cmd = megasas_get_cmd(instance); |
| 6252 | |
| 6253 | if (!cmd) |
| 6254 | return -ENOMEM; |
| 6255 | |
| 6256 | dcmd = &cmd->frame->dcmd; |
| 6257 | |
| 6258 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 6259 | |
| 6260 | /* |
| 6261 | * Prepare DCMD for aen registration |
| 6262 | */ |
| 6263 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6264 | |
| 6265 | dcmd->cmd = MFI_CMD_DCMD; |
| 6266 | dcmd->cmd_status = 0x0; |
| 6267 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6268 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6269 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6270 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6271 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 6272 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 6273 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6274 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6275 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6276 | |
| 6277 | megasas_set_dma_settings(instance, dcmd, instance->evt_detail_h, |
| 6278 | sizeof(struct megasas_evt_detail)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6279 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 6280 | if (instance->aen_cmd != NULL) { |
| 6281 | megasas_return_cmd(instance, cmd); |
| 6282 | return 0; |
| 6283 | } |
| 6284 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6285 | /* |
| 6286 | * Store reference to the cmd used to register for AEN. When an |
| 6287 | * application wants us to register for AEN, we have to abort this |
| 6288 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 6289 | */ |
| 6290 | instance->aen_cmd = cmd; |
| 6291 | |
| 6292 | /* |
| 6293 | * Issue the aen registration frame |
| 6294 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6295 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6296 | |
| 6297 | return 0; |
| 6298 | } |
| 6299 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6300 | /* megasas_get_target_prop - Send DCMD with below details to firmware. |
| 6301 | * |
| 6302 | * This DCMD will fetch few properties of LD/system PD defined |
| 6303 | * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value. |
| 6304 | * |
| 6305 | * DCMD send by drivers whenever new target is added to the OS. |
| 6306 | * |
| 6307 | * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP |
| 6308 | * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD. |
| 6309 | * 0 = system PD, 1 = LD. |
| 6310 | * dcmd.mbox.s[1] - TargetID for LD/system PD. |
| 6311 | * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES. |
| 6312 | * |
| 6313 | * @instance: Adapter soft state |
| 6314 | * @sdev: OS provided scsi device |
| 6315 | * |
| 6316 | * Returns 0 on success non-zero on failure. |
| 6317 | */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 6318 | int |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6319 | megasas_get_target_prop(struct megasas_instance *instance, |
| 6320 | struct scsi_device *sdev) |
| 6321 | { |
| 6322 | int ret; |
| 6323 | struct megasas_cmd *cmd; |
| 6324 | struct megasas_dcmd_frame *dcmd; |
| 6325 | u16 targetId = (sdev->channel % 2) + sdev->id; |
| 6326 | |
| 6327 | cmd = megasas_get_cmd(instance); |
| 6328 | |
| 6329 | if (!cmd) { |
| 6330 | dev_err(&instance->pdev->dev, |
| 6331 | "Failed to get cmd %s\n", __func__); |
| 6332 | return -ENOMEM; |
| 6333 | } |
| 6334 | |
| 6335 | dcmd = &cmd->frame->dcmd; |
| 6336 | |
| 6337 | memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop)); |
| 6338 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6339 | dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev); |
| 6340 | |
| 6341 | dcmd->mbox.s[1] = cpu_to_le16(targetId); |
| 6342 | dcmd->cmd = MFI_CMD_DCMD; |
| 6343 | dcmd->cmd_status = 0xFF; |
| 6344 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6345 | dcmd->flags = MFI_FRAME_DIR_READ; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6346 | dcmd->timeout = 0; |
| 6347 | dcmd->pad_0 = 0; |
| 6348 | dcmd->data_xfer_len = |
| 6349 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 6350 | dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6351 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6352 | megasas_set_dma_settings(instance, dcmd, instance->tgt_prop_h, |
| 6353 | sizeof(struct MR_TARGET_PROPERTIES)); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6354 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6355 | if ((instance->adapter_type != MFI_SERIES) && |
| 6356 | !instance->mask_interrupts) |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6357 | ret = megasas_issue_blocked_cmd(instance, |
| 6358 | cmd, MFI_IO_TIMEOUT_SECS); |
| 6359 | else |
| 6360 | ret = megasas_issue_polled(instance, cmd); |
| 6361 | |
| 6362 | switch (ret) { |
| 6363 | case DCMD_TIMEOUT: |
| 6364 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 6365 | case INITIATE_OCR: |
| 6366 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 6367 | megasas_reset_fusion(instance->host, |
| 6368 | MFI_IO_TIMEOUT_OCR); |
| 6369 | break; |
| 6370 | case KILL_ADAPTER: |
| 6371 | megaraid_sas_kill_hba(instance); |
| 6372 | break; |
| 6373 | case IGNORE_TIMEOUT: |
| 6374 | dev_info(&instance->pdev->dev, |
| 6375 | "Ignore DCMD timeout: %s %d\n", |
| 6376 | __func__, __LINE__); |
| 6377 | break; |
| 6378 | } |
| 6379 | break; |
| 6380 | |
| 6381 | default: |
| 6382 | megasas_return_cmd(instance, cmd); |
| 6383 | } |
| 6384 | if (ret != DCMD_SUCCESS) |
| 6385 | dev_err(&instance->pdev->dev, |
| 6386 | "return from %s %d return value %d\n", |
| 6387 | __func__, __LINE__, ret); |
| 6388 | |
| 6389 | return ret; |
| 6390 | } |
| 6391 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6392 | /** |
| 6393 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 6394 | * @instance: Adapter soft state |
| 6395 | */ |
| 6396 | static int megasas_start_aen(struct megasas_instance *instance) |
| 6397 | { |
| 6398 | struct megasas_evt_log_info eli; |
| 6399 | union megasas_evt_class_locale class_locale; |
| 6400 | |
| 6401 | /* |
| 6402 | * Get the latest sequence number from FW |
| 6403 | */ |
| 6404 | memset(&eli, 0, sizeof(eli)); |
| 6405 | |
| 6406 | if (megasas_get_seq_num(instance, &eli)) |
| 6407 | return -1; |
| 6408 | |
| 6409 | /* |
| 6410 | * Register AEN with FW for latest sequence number plus 1 |
| 6411 | */ |
| 6412 | class_locale.members.reserved = 0; |
| 6413 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 6414 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 6415 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6416 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 6417 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6418 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6419 | } |
| 6420 | |
| 6421 | /** |
| 6422 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 6423 | * @instance: Adapter soft state |
| 6424 | */ |
| 6425 | static int megasas_io_attach(struct megasas_instance *instance) |
| 6426 | { |
| 6427 | struct Scsi_Host *host = instance->host; |
| 6428 | |
| 6429 | /* |
| 6430 | * Export parameters required by SCSI mid-layer |
| 6431 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6432 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6433 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6434 | host->this_id = instance->init_id; |
| 6435 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 6436 | |
| 6437 | if (instance->fw_support_ieee) |
| 6438 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 6439 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 6440 | /* |
| 6441 | * Check if the module parameter value for max_sectors can be used |
| 6442 | */ |
| 6443 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 6444 | instance->max_sectors_per_req = max_sectors; |
| 6445 | else { |
| 6446 | if (max_sectors) { |
| 6447 | if (((instance->pdev->device == |
| 6448 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 6449 | (instance->pdev->device == |
| 6450 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 6451 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 6452 | instance->max_sectors_per_req = max_sectors; |
| 6453 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6454 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 6455 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 6456 | instance->max_sectors_per_req); |
| 6457 | } |
| 6458 | } |
| 6459 | } |
| 6460 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6461 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6462 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6463 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 6464 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6465 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 6466 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6467 | |
| 6468 | /* |
| 6469 | * Notify the mid-layer about the new controller |
| 6470 | */ |
| 6471 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6472 | dev_err(&instance->pdev->dev, |
| 6473 | "Failed to add host from %s %d\n", |
| 6474 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6475 | return -ENODEV; |
| 6476 | } |
| 6477 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6478 | return 0; |
| 6479 | } |
| 6480 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6481 | /** |
| 6482 | * megasas_set_dma_mask - Set DMA mask for supported controllers |
| 6483 | * |
| 6484 | * @instance: Adapter soft state |
| 6485 | * Description: |
| 6486 | * |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6487 | * For Ventura, driver/FW will operate in 63bit DMA addresses. |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6488 | * |
| 6489 | * For invader- |
| 6490 | * By default, driver/FW will operate in 32bit DMA addresses |
| 6491 | * for consistent DMA mapping but if 32 bit consistent |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6492 | * DMA mask fails, driver will try with 63 bit consistent |
| 6493 | * mask provided FW is true 63bit DMA capable |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6494 | * |
| 6495 | * For older controllers(Thunderbolt and MFI based adapters)- |
| 6496 | * driver/FW will operate in 32 bit consistent DMA addresses. |
| 6497 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6498 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6499 | megasas_set_dma_mask(struct megasas_instance *instance) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6500 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6501 | u64 consistent_mask; |
| 6502 | struct pci_dev *pdev; |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6503 | u32 scratch_pad_1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6504 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6505 | pdev = instance->pdev; |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 6506 | consistent_mask = (instance->adapter_type >= VENTURA_SERIES) ? |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6507 | DMA_BIT_MASK(63) : DMA_BIT_MASK(32); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6508 | |
| 6509 | if (IS_DMA64) { |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6510 | if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(63)) && |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6511 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6512 | goto fail_set_dma_mask; |
| 6513 | |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6514 | if ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) && |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6515 | (dma_set_coherent_mask(&pdev->dev, consistent_mask) && |
| 6516 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))) { |
| 6517 | /* |
| 6518 | * If 32 bit DMA mask fails, then try for 64 bit mask |
| 6519 | * for FW capable of handling 64 bit DMA. |
| 6520 | */ |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 6521 | scratch_pad_1 = megasas_readl |
| 6522 | (instance, &instance->reg_set->outbound_scratch_pad_1); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6523 | |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6524 | if (!(scratch_pad_1 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET)) |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6525 | goto fail_set_dma_mask; |
| 6526 | else if (dma_set_mask_and_coherent(&pdev->dev, |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6527 | DMA_BIT_MASK(63))) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6528 | goto fail_set_dma_mask; |
| 6529 | } |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6530 | } else if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6531 | goto fail_set_dma_mask; |
| 6532 | |
| 6533 | if (pdev->dev.coherent_dma_mask == DMA_BIT_MASK(32)) |
| 6534 | instance->consistent_mask_64bit = false; |
| 6535 | else |
| 6536 | instance->consistent_mask_64bit = true; |
| 6537 | |
| 6538 | 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] | 6539 | ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) ? "63" : "32"), |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6540 | (instance->consistent_mask_64bit ? "63" : "32")); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6541 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6542 | return 0; |
| 6543 | |
| 6544 | fail_set_dma_mask: |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6545 | dev_err(&pdev->dev, "Failed to set DMA mask\n"); |
| 6546 | return -1; |
| 6547 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6548 | } |
| 6549 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6550 | /* |
| 6551 | * megasas_set_adapter_type - Set adapter type. |
| 6552 | * Supported controllers can be divided in |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6553 | * different categories- |
| 6554 | * enum MR_ADAPTER_TYPE { |
| 6555 | * MFI_SERIES = 1, |
| 6556 | * THUNDERBOLT_SERIES = 2, |
| 6557 | * INVADER_SERIES = 3, |
| 6558 | * VENTURA_SERIES = 4, |
| 6559 | * AERO_SERIES = 5, |
| 6560 | * }; |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6561 | * @instance: Adapter soft state |
| 6562 | * return: void |
| 6563 | */ |
| 6564 | static inline void megasas_set_adapter_type(struct megasas_instance *instance) |
| 6565 | { |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6566 | if ((instance->pdev->vendor == PCI_VENDOR_ID_DELL) && |
| 6567 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5)) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6568 | instance->adapter_type = MFI_SERIES; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6569 | } else { |
| 6570 | switch (instance->pdev->device) { |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 6571 | case PCI_DEVICE_ID_LSI_AERO_10E1: |
| 6572 | case PCI_DEVICE_ID_LSI_AERO_10E2: |
| 6573 | case PCI_DEVICE_ID_LSI_AERO_10E5: |
| 6574 | case PCI_DEVICE_ID_LSI_AERO_10E6: |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6575 | instance->adapter_type = AERO_SERIES; |
| 6576 | break; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6577 | case PCI_DEVICE_ID_LSI_VENTURA: |
| 6578 | case PCI_DEVICE_ID_LSI_CRUSADER: |
| 6579 | case PCI_DEVICE_ID_LSI_HARPOON: |
| 6580 | case PCI_DEVICE_ID_LSI_TOMCAT: |
| 6581 | case PCI_DEVICE_ID_LSI_VENTURA_4PORT: |
| 6582 | case PCI_DEVICE_ID_LSI_CRUSADER_4PORT: |
| 6583 | instance->adapter_type = VENTURA_SERIES; |
| 6584 | break; |
| 6585 | case PCI_DEVICE_ID_LSI_FUSION: |
| 6586 | case PCI_DEVICE_ID_LSI_PLASMA: |
| 6587 | instance->adapter_type = THUNDERBOLT_SERIES; |
| 6588 | break; |
| 6589 | case PCI_DEVICE_ID_LSI_INVADER: |
| 6590 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 6591 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
| 6592 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 6593 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
| 6594 | case PCI_DEVICE_ID_LSI_FURY: |
| 6595 | instance->adapter_type = INVADER_SERIES; |
| 6596 | break; |
| 6597 | default: /* For all other supported controllers */ |
| 6598 | instance->adapter_type = MFI_SERIES; |
| 6599 | break; |
| 6600 | } |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6601 | } |
| 6602 | } |
| 6603 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6604 | static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance) |
| 6605 | { |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6606 | instance->producer = dma_alloc_coherent(&instance->pdev->dev, |
| 6607 | sizeof(u32), &instance->producer_h, GFP_KERNEL); |
| 6608 | instance->consumer = dma_alloc_coherent(&instance->pdev->dev, |
| 6609 | sizeof(u32), &instance->consumer_h, GFP_KERNEL); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6610 | |
| 6611 | if (!instance->producer || !instance->consumer) { |
| 6612 | dev_err(&instance->pdev->dev, |
| 6613 | "Failed to allocate memory for producer, consumer\n"); |
| 6614 | return -1; |
| 6615 | } |
| 6616 | |
| 6617 | *instance->producer = 0; |
| 6618 | *instance->consumer = 0; |
| 6619 | return 0; |
| 6620 | } |
| 6621 | |
| 6622 | /** |
| 6623 | * megasas_alloc_ctrl_mem - Allocate per controller memory for core data |
| 6624 | * structures which are not common across MFI |
| 6625 | * adapters and fusion adapters. |
| 6626 | * For MFI based adapters, allocate producer and |
| 6627 | * consumer buffers. For fusion adapters, allocate |
| 6628 | * memory for fusion context. |
| 6629 | * @instance: Adapter soft state |
| 6630 | * return: 0 for SUCCESS |
| 6631 | */ |
| 6632 | static int megasas_alloc_ctrl_mem(struct megasas_instance *instance) |
| 6633 | { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6634 | instance->reply_map = kcalloc(nr_cpu_ids, sizeof(unsigned int), |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6635 | GFP_KERNEL); |
| 6636 | if (!instance->reply_map) |
| 6637 | return -ENOMEM; |
| 6638 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6639 | switch (instance->adapter_type) { |
| 6640 | case MFI_SERIES: |
| 6641 | if (megasas_alloc_mfi_ctrl_mem(instance)) |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6642 | goto fail; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6643 | break; |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6644 | case AERO_SERIES: |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6645 | case VENTURA_SERIES: |
| 6646 | case THUNDERBOLT_SERIES: |
| 6647 | case INVADER_SERIES: |
| 6648 | if (megasas_alloc_fusion_context(instance)) |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6649 | goto fail; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6650 | break; |
| 6651 | } |
| 6652 | |
| 6653 | return 0; |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6654 | fail: |
| 6655 | kfree(instance->reply_map); |
| 6656 | instance->reply_map = NULL; |
| 6657 | return -ENOMEM; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6658 | } |
| 6659 | |
| 6660 | /* |
| 6661 | * megasas_free_ctrl_mem - Free fusion context for fusion adapters and |
| 6662 | * producer, consumer buffers for MFI adapters |
| 6663 | * |
| 6664 | * @instance - Adapter soft instance |
| 6665 | * |
| 6666 | */ |
| 6667 | static inline void megasas_free_ctrl_mem(struct megasas_instance *instance) |
| 6668 | { |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6669 | kfree(instance->reply_map); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6670 | if (instance->adapter_type == MFI_SERIES) { |
| 6671 | if (instance->producer) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6672 | dma_free_coherent(&instance->pdev->dev, sizeof(u32), |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6673 | instance->producer, |
| 6674 | instance->producer_h); |
| 6675 | if (instance->consumer) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6676 | dma_free_coherent(&instance->pdev->dev, sizeof(u32), |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6677 | instance->consumer, |
| 6678 | instance->consumer_h); |
| 6679 | } else { |
| 6680 | megasas_free_fusion_context(instance); |
| 6681 | } |
| 6682 | } |
| 6683 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6684 | /** |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6685 | * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during |
| 6686 | * driver load time |
| 6687 | * |
| 6688 | * @instance- Adapter soft instance |
| 6689 | * @return- O for SUCCESS |
| 6690 | */ |
| 6691 | static inline |
| 6692 | int megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance) |
| 6693 | { |
| 6694 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6695 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6696 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6697 | instance->evt_detail = dma_alloc_coherent(&pdev->dev, |
| 6698 | sizeof(struct megasas_evt_detail), |
| 6699 | &instance->evt_detail_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6700 | |
| 6701 | if (!instance->evt_detail) { |
| 6702 | dev_err(&instance->pdev->dev, |
| 6703 | "Failed to allocate event detail buffer\n"); |
| 6704 | return -ENOMEM; |
| 6705 | } |
| 6706 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6707 | if (fusion) { |
| 6708 | fusion->ioc_init_request = |
| 6709 | dma_alloc_coherent(&pdev->dev, |
| 6710 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 6711 | &fusion->ioc_init_request_phys, |
| 6712 | GFP_KERNEL); |
| 6713 | |
| 6714 | if (!fusion->ioc_init_request) { |
| 6715 | dev_err(&pdev->dev, |
| 6716 | "Failed to allocate PD list buffer\n"); |
| 6717 | return -ENOMEM; |
| 6718 | } |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 6719 | |
| 6720 | instance->snapdump_prop = dma_alloc_coherent(&pdev->dev, |
| 6721 | sizeof(struct MR_SNAPDUMP_PROPERTIES), |
| 6722 | &instance->snapdump_prop_h, GFP_KERNEL); |
| 6723 | |
| 6724 | if (!instance->snapdump_prop) |
| 6725 | dev_err(&pdev->dev, |
| 6726 | "Failed to allocate snapdump properties buffer\n"); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 6727 | |
| 6728 | instance->host_device_list_buf = dma_alloc_coherent(&pdev->dev, |
| 6729 | HOST_DEVICE_LIST_SZ, |
| 6730 | &instance->host_device_list_buf_h, |
| 6731 | GFP_KERNEL); |
| 6732 | |
| 6733 | if (!instance->host_device_list_buf) { |
| 6734 | dev_err(&pdev->dev, |
| 6735 | "Failed to allocate targetid list buffer\n"); |
| 6736 | return -ENOMEM; |
| 6737 | } |
| 6738 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6739 | } |
| 6740 | |
| 6741 | instance->pd_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6742 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6743 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6744 | &instance->pd_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6745 | |
| 6746 | if (!instance->pd_list_buf) { |
| 6747 | dev_err(&pdev->dev, "Failed to allocate PD list buffer\n"); |
| 6748 | return -ENOMEM; |
| 6749 | } |
| 6750 | |
| 6751 | instance->ctrl_info_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6752 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6753 | sizeof(struct megasas_ctrl_info), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6754 | &instance->ctrl_info_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6755 | |
| 6756 | if (!instance->ctrl_info_buf) { |
| 6757 | dev_err(&pdev->dev, |
| 6758 | "Failed to allocate controller info buffer\n"); |
| 6759 | return -ENOMEM; |
| 6760 | } |
| 6761 | |
| 6762 | instance->ld_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6763 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6764 | sizeof(struct MR_LD_LIST), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6765 | &instance->ld_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6766 | |
| 6767 | if (!instance->ld_list_buf) { |
| 6768 | dev_err(&pdev->dev, "Failed to allocate LD list buffer\n"); |
| 6769 | return -ENOMEM; |
| 6770 | } |
| 6771 | |
| 6772 | instance->ld_targetid_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6773 | dma_alloc_coherent(&pdev->dev, |
| 6774 | sizeof(struct MR_LD_TARGETID_LIST), |
| 6775 | &instance->ld_targetid_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6776 | |
| 6777 | if (!instance->ld_targetid_list_buf) { |
| 6778 | dev_err(&pdev->dev, |
| 6779 | "Failed to allocate LD targetid list buffer\n"); |
| 6780 | return -ENOMEM; |
| 6781 | } |
| 6782 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6783 | if (!reset_devices) { |
| 6784 | instance->system_info_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6785 | dma_alloc_coherent(&pdev->dev, |
| 6786 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 6787 | &instance->system_info_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6788 | instance->pd_info = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6789 | dma_alloc_coherent(&pdev->dev, |
| 6790 | sizeof(struct MR_PD_INFO), |
| 6791 | &instance->pd_info_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6792 | instance->tgt_prop = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6793 | dma_alloc_coherent(&pdev->dev, |
| 6794 | sizeof(struct MR_TARGET_PROPERTIES), |
| 6795 | &instance->tgt_prop_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6796 | instance->crash_dump_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6797 | dma_alloc_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE, |
| 6798 | &instance->crash_dump_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6799 | |
| 6800 | if (!instance->system_info_buf) |
| 6801 | dev_err(&instance->pdev->dev, |
| 6802 | "Failed to allocate system info buffer\n"); |
| 6803 | |
| 6804 | if (!instance->pd_info) |
| 6805 | dev_err(&instance->pdev->dev, |
| 6806 | "Failed to allocate pd_info buffer\n"); |
| 6807 | |
| 6808 | if (!instance->tgt_prop) |
| 6809 | dev_err(&instance->pdev->dev, |
| 6810 | "Failed to allocate tgt_prop buffer\n"); |
| 6811 | |
| 6812 | if (!instance->crash_dump_buf) |
| 6813 | dev_err(&instance->pdev->dev, |
| 6814 | "Failed to allocate crash dump buffer\n"); |
| 6815 | } |
| 6816 | |
| 6817 | return 0; |
| 6818 | } |
| 6819 | |
| 6820 | /* |
| 6821 | * megasas_free_ctrl_dma_buffers - Free consistent DMA buffers allocated |
| 6822 | * during driver load time |
| 6823 | * |
| 6824 | * @instance- Adapter soft instance |
| 6825 | * |
| 6826 | */ |
| 6827 | static inline |
| 6828 | void megasas_free_ctrl_dma_buffers(struct megasas_instance *instance) |
| 6829 | { |
| 6830 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6831 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6832 | |
| 6833 | if (instance->evt_detail) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6834 | dma_free_coherent(&pdev->dev, sizeof(struct megasas_evt_detail), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6835 | instance->evt_detail, |
| 6836 | instance->evt_detail_h); |
| 6837 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6838 | if (fusion && fusion->ioc_init_request) |
| 6839 | dma_free_coherent(&pdev->dev, |
| 6840 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 6841 | fusion->ioc_init_request, |
| 6842 | fusion->ioc_init_request_phys); |
| 6843 | |
| 6844 | if (instance->pd_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6845 | dma_free_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6846 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 6847 | instance->pd_list_buf, |
| 6848 | instance->pd_list_buf_h); |
| 6849 | |
| 6850 | if (instance->ld_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6851 | dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_LIST), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6852 | instance->ld_list_buf, |
| 6853 | instance->ld_list_buf_h); |
| 6854 | |
| 6855 | if (instance->ld_targetid_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6856 | dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_TARGETID_LIST), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6857 | instance->ld_targetid_list_buf, |
| 6858 | instance->ld_targetid_list_buf_h); |
| 6859 | |
| 6860 | if (instance->ctrl_info_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6861 | dma_free_coherent(&pdev->dev, sizeof(struct megasas_ctrl_info), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6862 | instance->ctrl_info_buf, |
| 6863 | instance->ctrl_info_buf_h); |
| 6864 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6865 | if (instance->system_info_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6866 | dma_free_coherent(&pdev->dev, sizeof(struct MR_DRV_SYSTEM_INFO), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6867 | instance->system_info_buf, |
| 6868 | instance->system_info_h); |
| 6869 | |
| 6870 | if (instance->pd_info) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6871 | dma_free_coherent(&pdev->dev, sizeof(struct MR_PD_INFO), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6872 | instance->pd_info, instance->pd_info_h); |
| 6873 | |
| 6874 | if (instance->tgt_prop) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6875 | dma_free_coherent(&pdev->dev, sizeof(struct MR_TARGET_PROPERTIES), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6876 | instance->tgt_prop, instance->tgt_prop_h); |
| 6877 | |
| 6878 | if (instance->crash_dump_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6879 | dma_free_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE, |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6880 | instance->crash_dump_buf, |
| 6881 | instance->crash_dump_h); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 6882 | |
| 6883 | if (instance->snapdump_prop) |
| 6884 | dma_free_coherent(&pdev->dev, |
| 6885 | sizeof(struct MR_SNAPDUMP_PROPERTIES), |
| 6886 | instance->snapdump_prop, |
| 6887 | instance->snapdump_prop_h); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 6888 | |
| 6889 | if (instance->host_device_list_buf) |
| 6890 | dma_free_coherent(&pdev->dev, |
| 6891 | HOST_DEVICE_LIST_SZ, |
| 6892 | instance->host_device_list_buf, |
| 6893 | instance->host_device_list_buf_h); |
| 6894 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6895 | } |
| 6896 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6897 | /* |
| 6898 | * megasas_init_ctrl_params - Initialize controller's instance |
| 6899 | * parameters before FW init |
| 6900 | * @instance - Adapter soft instance |
| 6901 | * @return - void |
| 6902 | */ |
| 6903 | static inline void megasas_init_ctrl_params(struct megasas_instance *instance) |
| 6904 | { |
| 6905 | instance->fw_crash_state = UNAVAILABLE; |
| 6906 | |
| 6907 | megasas_poll_wait_aen = 0; |
| 6908 | instance->issuepend_done = 1; |
| 6909 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
| 6910 | |
| 6911 | /* |
| 6912 | * Initialize locks and queues |
| 6913 | */ |
| 6914 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 6915 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
| 6916 | |
| 6917 | atomic_set(&instance->fw_outstanding, 0); |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 6918 | atomic64_set(&instance->total_io_count, 0); |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6919 | |
| 6920 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 6921 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 6922 | |
| 6923 | spin_lock_init(&instance->crashdump_lock); |
| 6924 | spin_lock_init(&instance->mfi_pool_lock); |
| 6925 | spin_lock_init(&instance->hba_lock); |
| 6926 | spin_lock_init(&instance->stream_lock); |
| 6927 | spin_lock_init(&instance->completion_lock); |
| 6928 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6929 | mutex_init(&instance->reset_mutex); |
| 6930 | |
| 6931 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 6932 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
| 6933 | instance->flag_ieee = 1; |
| 6934 | |
| 6935 | megasas_dbg_lvl = 0; |
| 6936 | instance->flag = 0; |
| 6937 | instance->unload = 1; |
| 6938 | instance->last_time = 0; |
| 6939 | instance->disableOnlineCtrlReset = 1; |
| 6940 | instance->UnevenSpanSupport = 0; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 6941 | instance->smp_affinity_enable = smp_affinity_enable ? true : false; |
| 6942 | instance->msix_load_balance = false; |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6943 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6944 | if (instance->adapter_type != MFI_SERIES) |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6945 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6946 | else |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 6947 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6948 | } |
| 6949 | |
| 6950 | /** |
| 6951 | * megasas_probe_one - PCI hotplug entry point |
| 6952 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 6953 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6954 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6955 | static int megasas_probe_one(struct pci_dev *pdev, |
| 6956 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6957 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6958 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6959 | struct Scsi_Host *host; |
| 6960 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6961 | u16 control = 0; |
| 6962 | |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 6963 | switch (pdev->device) { |
| 6964 | case PCI_DEVICE_ID_LSI_AERO_10E1: |
| 6965 | case PCI_DEVICE_ID_LSI_AERO_10E5: |
| 6966 | dev_info(&pdev->dev, "Adapter is in configurable secure mode\n"); |
| 6967 | break; |
| 6968 | } |
| 6969 | |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6970 | /* Reset MSI-X in the kdump kernel */ |
| 6971 | if (reset_devices) { |
| 6972 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 6973 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6974 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6975 | &control); |
| 6976 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 6977 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 6978 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 6979 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 6980 | control & |
| 6981 | ~PCI_MSIX_FLAGS_ENABLE); |
| 6982 | } |
| 6983 | } |
| 6984 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6985 | |
| 6986 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6987 | * PCI prepping: enable device set bus mastering and dma mask |
| 6988 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 6989 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6990 | |
| 6991 | if (rval) { |
| 6992 | return rval; |
| 6993 | } |
| 6994 | |
| 6995 | pci_set_master(pdev); |
| 6996 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6997 | host = scsi_host_alloc(&megasas_template, |
| 6998 | sizeof(struct megasas_instance)); |
| 6999 | |
| 7000 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7001 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7002 | goto fail_alloc_instance; |
| 7003 | } |
| 7004 | |
| 7005 | instance = (struct megasas_instance *)host->hostdata; |
| 7006 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7007 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7008 | |
| 7009 | /* |
| 7010 | * Initialize PCI related and misc parameters |
| 7011 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7012 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7013 | instance->host = host; |
| 7014 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 7015 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
| 7016 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 7017 | megasas_set_adapter_type(instance); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7018 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7019 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 7020 | * Initialize MFI Firmware |
| 7021 | */ |
| 7022 | if (megasas_init_fw(instance)) |
| 7023 | goto fail_init_mfi; |
| 7024 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7025 | if (instance->requestorId) { |
| 7026 | if (instance->PlasmaFW111) { |
| 7027 | instance->vf_affiliation_111 = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7028 | dma_alloc_coherent(&pdev->dev, |
| 7029 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 7030 | &instance->vf_affiliation_111_h, |
| 7031 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7032 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7033 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7034 | "memory for VF affiliation buffer\n"); |
| 7035 | } else { |
| 7036 | instance->vf_affiliation = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7037 | dma_alloc_coherent(&pdev->dev, |
| 7038 | (MAX_LOGICAL_DRIVES + 1) * |
| 7039 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 7040 | &instance->vf_affiliation_h, |
| 7041 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7042 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7043 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7044 | "memory for VF affiliation buffer\n"); |
| 7045 | } |
| 7046 | } |
| 7047 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7048 | /* |
| 7049 | * Store instance in PCI softstate |
| 7050 | */ |
| 7051 | pci_set_drvdata(pdev, instance); |
| 7052 | |
| 7053 | /* |
| 7054 | * Add this controller to megasas_mgmt_info structure so that it |
| 7055 | * can be exported to management applications |
| 7056 | */ |
| 7057 | megasas_mgmt_info.count++; |
| 7058 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 7059 | megasas_mgmt_info.max_index++; |
| 7060 | |
| 7061 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7062 | * Register with SCSI mid-layer |
| 7063 | */ |
| 7064 | if (megasas_io_attach(instance)) |
| 7065 | goto fail_io_attach; |
| 7066 | |
| 7067 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 7068 | /* |
| 7069 | * Trigger SCSI to scan our drives |
| 7070 | */ |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 7071 | if (!instance->enable_fw_dev_list || |
| 7072 | (instance->host_device_list_buf->count > 0)) |
| 7073 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7074 | |
| 7075 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7076 | * Initiate AEN (Asynchronous Event Notification) |
| 7077 | */ |
| 7078 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7079 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7080 | goto fail_start_aen; |
| 7081 | } |
| 7082 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 7083 | /* Get current SR-IOV LD/VF affiliation */ |
| 7084 | if (instance->requestorId) |
| 7085 | megasas_get_ld_vf_affiliation(instance, 1); |
| 7086 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7087 | return 0; |
| 7088 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7089 | fail_start_aen: |
| 7090 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7091 | megasas_mgmt_info.count--; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7092 | megasas_mgmt_info.max_index--; |
weiping zhang | 61f0c3c | 2017-08-08 01:26:57 +0800 | [diff] [blame] | 7093 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7094 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7095 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7096 | megasas_destroy_irqs(instance); |
| 7097 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7098 | if (instance->adapter_type != MFI_SERIES) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 7099 | megasas_release_fusion(instance); |
| 7100 | else |
| 7101 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7102 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7103 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7104 | fail_init_mfi: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7105 | scsi_host_put(host); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7106 | fail_alloc_instance: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7107 | pci_disable_device(pdev); |
| 7108 | |
| 7109 | return -ENODEV; |
| 7110 | } |
| 7111 | |
| 7112 | /** |
| 7113 | * megasas_flush_cache - Requests FW to flush all its caches |
| 7114 | * @instance: Adapter soft state |
| 7115 | */ |
| 7116 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 7117 | { |
| 7118 | struct megasas_cmd *cmd; |
| 7119 | struct megasas_dcmd_frame *dcmd; |
| 7120 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7121 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7122 | return; |
| 7123 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7124 | cmd = megasas_get_cmd(instance); |
| 7125 | |
| 7126 | if (!cmd) |
| 7127 | return; |
| 7128 | |
| 7129 | dcmd = &cmd->frame->dcmd; |
| 7130 | |
| 7131 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 7132 | |
| 7133 | dcmd->cmd = MFI_CMD_DCMD; |
| 7134 | dcmd->cmd_status = 0x0; |
| 7135 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7136 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7137 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 7138 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7139 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7140 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7141 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 7142 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7143 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 7144 | != DCMD_SUCCESS) { |
| 7145 | dev_err(&instance->pdev->dev, |
| 7146 | "return from %s %d\n", __func__, __LINE__); |
| 7147 | return; |
| 7148 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7149 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7150 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7151 | } |
| 7152 | |
| 7153 | /** |
| 7154 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 7155 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7156 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7157 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7158 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 7159 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7160 | { |
| 7161 | struct megasas_cmd *cmd; |
| 7162 | struct megasas_dcmd_frame *dcmd; |
| 7163 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7164 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7165 | return; |
| 7166 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7167 | cmd = megasas_get_cmd(instance); |
| 7168 | |
| 7169 | if (!cmd) |
| 7170 | return; |
| 7171 | |
| 7172 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 7173 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7174 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7175 | if (instance->map_update_cmd) |
| 7176 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7177 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7178 | if (instance->jbod_seq_cmd) |
| 7179 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7180 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7181 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7182 | dcmd = &cmd->frame->dcmd; |
| 7183 | |
| 7184 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 7185 | |
| 7186 | dcmd->cmd = MFI_CMD_DCMD; |
| 7187 | dcmd->cmd_status = 0x0; |
| 7188 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7189 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7190 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 7191 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7192 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7193 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7194 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7195 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 7196 | != DCMD_SUCCESS) { |
| 7197 | dev_err(&instance->pdev->dev, |
| 7198 | "return from %s %d\n", __func__, __LINE__); |
| 7199 | return; |
| 7200 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7201 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7202 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7203 | } |
| 7204 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7205 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7206 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7207 | * megasas_suspend - driver suspend entry point |
| 7208 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7209 | * @state: PCI power state to suspend routine |
| 7210 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7211 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7212 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 7213 | { |
| 7214 | struct Scsi_Host *host; |
| 7215 | struct megasas_instance *instance; |
| 7216 | |
| 7217 | instance = pci_get_drvdata(pdev); |
| 7218 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7219 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7220 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7221 | /* Shutdown SR-IOV heartbeat timer */ |
| 7222 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7223 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 7224 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7225 | /* Stop the FW fault detection watchdog */ |
| 7226 | if (instance->adapter_type != MFI_SERIES) |
| 7227 | megasas_fusion_stop_watchdog(instance); |
| 7228 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7229 | megasas_flush_cache(instance); |
| 7230 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7231 | |
| 7232 | /* cancel the delayed work if this work still in queue */ |
| 7233 | if (instance->ev != NULL) { |
| 7234 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7235 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7236 | instance->ev = NULL; |
| 7237 | } |
| 7238 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7239 | tasklet_kill(&instance->isr_tasklet); |
| 7240 | |
| 7241 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7242 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7243 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7244 | megasas_destroy_irqs(instance); |
| 7245 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7246 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7247 | pci_free_irq_vectors(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7248 | |
| 7249 | pci_save_state(pdev); |
| 7250 | pci_disable_device(pdev); |
| 7251 | |
| 7252 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 7253 | |
| 7254 | return 0; |
| 7255 | } |
| 7256 | |
| 7257 | /** |
| 7258 | * megasas_resume- driver resume entry point |
| 7259 | * @pdev: PCI device structure |
| 7260 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7261 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7262 | megasas_resume(struct pci_dev *pdev) |
| 7263 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7264 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7265 | struct Scsi_Host *host; |
| 7266 | struct megasas_instance *instance; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7267 | int irq_flags = PCI_IRQ_LEGACY; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7268 | |
| 7269 | instance = pci_get_drvdata(pdev); |
| 7270 | host = instance->host; |
| 7271 | pci_set_power_state(pdev, PCI_D0); |
| 7272 | pci_enable_wake(pdev, PCI_D0, 0); |
| 7273 | pci_restore_state(pdev); |
| 7274 | |
| 7275 | /* |
| 7276 | * PCI prepping: enable device set bus mastering and dma mask |
| 7277 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 7278 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7279 | |
| 7280 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7281 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7282 | return rval; |
| 7283 | } |
| 7284 | |
| 7285 | pci_set_master(pdev); |
| 7286 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7287 | /* |
| 7288 | * We expect the FW state to be READY |
| 7289 | */ |
| 7290 | if (megasas_transition_to_ready(instance, 0)) |
| 7291 | goto fail_ready_state; |
| 7292 | |
| 7293 | if (megasas_set_dma_mask(instance)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7294 | goto fail_set_dma_mask; |
| 7295 | |
| 7296 | /* |
| 7297 | * Initialize MFI Firmware |
| 7298 | */ |
| 7299 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7300 | atomic_set(&instance->fw_outstanding, 0); |
Shivasharan S | 41fae9a | 2018-01-05 05:27:39 -0800 | [diff] [blame] | 7301 | atomic_set(&instance->ldio_outstanding, 0); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7302 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 7303 | /* Now re-enable MSI-X */ |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7304 | if (instance->msix_vectors) { |
| 7305 | irq_flags = PCI_IRQ_MSIX; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 7306 | if (instance->smp_affinity_enable) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7307 | irq_flags |= PCI_IRQ_AFFINITY; |
| 7308 | } |
| 7309 | rval = pci_alloc_irq_vectors(instance->pdev, 1, |
| 7310 | instance->msix_vectors ? |
| 7311 | instance->msix_vectors : 1, irq_flags); |
| 7312 | if (rval < 0) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 7313 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 7314 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 7315 | megasas_setup_reply_map(instance); |
| 7316 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7317 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7318 | megasas_reset_reply_desc(instance); |
| 7319 | if (megasas_ioc_init_fusion(instance)) { |
| 7320 | megasas_free_cmds(instance); |
| 7321 | megasas_free_cmds_fusion(instance); |
| 7322 | goto fail_init_mfi; |
| 7323 | } |
| 7324 | if (!megasas_get_map_info(instance)) |
| 7325 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 7326 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7327 | *instance->producer = 0; |
| 7328 | *instance->consumer = 0; |
| 7329 | if (megasas_issue_init_mfi(instance)) |
| 7330 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7331 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7332 | |
Shivasharan S | c3b10a5 | 2018-06-04 03:45:10 -0700 | [diff] [blame] | 7333 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) |
| 7334 | goto fail_init_mfi; |
| 7335 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7336 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 7337 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7338 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7339 | if (instance->msix_vectors ? |
| 7340 | megasas_setup_irqs_msix(instance, 0) : |
| 7341 | megasas_setup_irqs_ioapic(instance)) |
| 7342 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7343 | |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 7344 | if (instance->adapter_type != MFI_SERIES) |
| 7345 | megasas_setup_irq_poll(instance); |
| 7346 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7347 | /* Re-launch SR-IOV heartbeat timer */ |
| 7348 | if (instance->requestorId) { |
| 7349 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 7350 | megasas_start_timer(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7351 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7352 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7353 | goto fail_init_mfi; |
| 7354 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7355 | } |
| 7356 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7357 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7358 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7359 | instance->unload = 0; |
| 7360 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7361 | /* |
| 7362 | * Initiate AEN (Asynchronous Event Notification) |
| 7363 | */ |
| 7364 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7365 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7366 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7367 | /* Re-launch FW fault watchdog */ |
| 7368 | if (instance->adapter_type != MFI_SERIES) |
| 7369 | if (megasas_fusion_start_watchdog(instance) != SUCCESS) |
| 7370 | goto fail_start_watchdog; |
| 7371 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7372 | return 0; |
| 7373 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7374 | fail_start_watchdog: |
| 7375 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7376 | del_timer_sync(&instance->sriov_heartbeat_timer); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7377 | fail_init_mfi: |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7378 | megasas_free_ctrl_dma_buffers(instance); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 7379 | megasas_free_ctrl_mem(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7380 | scsi_host_put(host); |
| 7381 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7382 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7383 | fail_set_dma_mask: |
| 7384 | fail_ready_state: |
| 7385 | |
| 7386 | pci_disable_device(pdev); |
| 7387 | |
| 7388 | return -ENODEV; |
| 7389 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7390 | #else |
| 7391 | #define megasas_suspend NULL |
| 7392 | #define megasas_resume NULL |
| 7393 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7394 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7395 | static inline int |
| 7396 | megasas_wait_for_adapter_operational(struct megasas_instance *instance) |
| 7397 | { |
| 7398 | int wait_time = MEGASAS_RESET_WAIT_TIME * 2; |
| 7399 | int i; |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7400 | u8 adp_state; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7401 | |
| 7402 | for (i = 0; i < wait_time; i++) { |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7403 | adp_state = atomic_read(&instance->adprecovery); |
| 7404 | if ((adp_state == MEGASAS_HBA_OPERATIONAL) || |
| 7405 | (adp_state == MEGASAS_HW_CRITICAL_ERROR)) |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7406 | break; |
| 7407 | |
| 7408 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) |
| 7409 | dev_notice(&instance->pdev->dev, "waiting for controller reset to finish\n"); |
| 7410 | |
| 7411 | msleep(1000); |
| 7412 | } |
| 7413 | |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7414 | if (adp_state != MEGASAS_HBA_OPERATIONAL) { |
| 7415 | dev_info(&instance->pdev->dev, |
| 7416 | "%s HBA failed to become operational, adp_state %d\n", |
| 7417 | __func__, adp_state); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7418 | return 1; |
| 7419 | } |
| 7420 | |
| 7421 | return 0; |
| 7422 | } |
| 7423 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7424 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7425 | * megasas_detach_one - PCI hot"un"plug entry point |
| 7426 | * @pdev: PCI device structure |
| 7427 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7428 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7429 | { |
| 7430 | int i; |
| 7431 | struct Scsi_Host *host; |
| 7432 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7433 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7434 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7435 | |
| 7436 | instance = pci_get_drvdata(pdev); |
| 7437 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7438 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7439 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7440 | /* Shutdown SR-IOV heartbeat timer */ |
| 7441 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7442 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 7443 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7444 | /* Stop the FW fault detection watchdog */ |
| 7445 | if (instance->adapter_type != MFI_SERIES) |
| 7446 | megasas_fusion_stop_watchdog(instance); |
| 7447 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7448 | if (instance->fw_crash_state != UNAVAILABLE) |
| 7449 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7450 | scsi_remove_host(instance->host); |
Shivasharan S | f3f7920 | 2018-01-05 05:27:41 -0800 | [diff] [blame] | 7451 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7452 | |
| 7453 | if (megasas_wait_for_adapter_operational(instance)) |
| 7454 | goto skip_firing_dcmds; |
| 7455 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7456 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7457 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7458 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7459 | skip_firing_dcmds: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7460 | /* cancel the delayed work if this work still in queue*/ |
| 7461 | if (instance->ev != NULL) { |
| 7462 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7463 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7464 | instance->ev = NULL; |
| 7465 | } |
| 7466 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 7467 | /* cancel all wait events */ |
| 7468 | wake_up_all(&instance->int_cmd_wait_q); |
| 7469 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 7470 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7471 | |
| 7472 | /* |
| 7473 | * Take the instance off the instance array. Note that we will not |
| 7474 | * decrement the max_index. We let this array be sparse array |
| 7475 | */ |
| 7476 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 7477 | if (megasas_mgmt_info.instance[i] == instance) { |
| 7478 | megasas_mgmt_info.count--; |
| 7479 | megasas_mgmt_info.instance[i] = NULL; |
| 7480 | |
| 7481 | break; |
| 7482 | } |
| 7483 | } |
| 7484 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7485 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7486 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7487 | megasas_destroy_irqs(instance); |
| 7488 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7489 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7490 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7491 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 7492 | if (instance->adapter_type >= VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 7493 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) |
| 7494 | kfree(fusion->stream_detect_by_ld[i]); |
| 7495 | kfree(fusion->stream_detect_by_ld); |
| 7496 | fusion->stream_detect_by_ld = NULL; |
| 7497 | } |
| 7498 | |
| 7499 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7500 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7501 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7502 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 7503 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 7504 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7505 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7506 | if (fusion->ld_map[i]) |
| 7507 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7508 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7509 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7510 | fusion->ld_map_phys[i]); |
Shivasharan S | def3e8d | 2017-08-23 04:47:03 -0700 | [diff] [blame] | 7511 | if (fusion->ld_drv_map[i]) { |
| 7512 | if (is_vmalloc_addr(fusion->ld_drv_map[i])) |
| 7513 | vfree(fusion->ld_drv_map[i]); |
| 7514 | else |
| 7515 | free_pages((ulong)fusion->ld_drv_map[i], |
| 7516 | fusion->drv_map_pages); |
| 7517 | } |
| 7518 | |
Maurizio Lombardi | 546e559 | 2016-01-22 13:41:42 +0100 | [diff] [blame] | 7519 | if (fusion->pd_seq_sync[i]) |
| 7520 | dma_free_coherent(&instance->pdev->dev, |
| 7521 | pd_seq_map_sz, |
| 7522 | fusion->pd_seq_sync[i], |
| 7523 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7524 | } |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 7525 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7526 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7527 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7528 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7529 | if (instance->vf_affiliation) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7530 | dma_free_coherent(&pdev->dev, (MAX_LOGICAL_DRIVES + 1) * |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7531 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 7532 | instance->vf_affiliation, |
| 7533 | instance->vf_affiliation_h); |
| 7534 | |
| 7535 | if (instance->vf_affiliation_111) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7536 | dma_free_coherent(&pdev->dev, |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7537 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 7538 | instance->vf_affiliation_111, |
| 7539 | instance->vf_affiliation_111_h); |
| 7540 | |
| 7541 | if (instance->hb_host_mem) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7542 | dma_free_coherent(&pdev->dev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7543 | instance->hb_host_mem, |
| 7544 | instance->hb_host_mem_h); |
| 7545 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7546 | megasas_free_ctrl_dma_buffers(instance); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7547 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 7548 | megasas_free_ctrl_mem(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7549 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7550 | scsi_host_put(host); |
| 7551 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7552 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | /** |
| 7556 | * megasas_shutdown - Shutdown entry point |
| 7557 | * @device: Generic device structure |
| 7558 | */ |
| 7559 | static void megasas_shutdown(struct pci_dev *pdev) |
| 7560 | { |
| 7561 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7562 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7563 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7564 | |
| 7565 | if (megasas_wait_for_adapter_operational(instance)) |
| 7566 | goto skip_firing_dcmds; |
| 7567 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7568 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 7569 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7570 | |
| 7571 | skip_firing_dcmds: |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7572 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7573 | megasas_destroy_irqs(instance); |
| 7574 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7575 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7576 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | /** |
| 7580 | * megasas_mgmt_open - char node "open" entry point |
| 7581 | */ |
| 7582 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 7583 | { |
| 7584 | /* |
| 7585 | * Allow only those users with admin rights |
| 7586 | */ |
| 7587 | if (!capable(CAP_SYS_ADMIN)) |
| 7588 | return -EACCES; |
| 7589 | |
| 7590 | return 0; |
| 7591 | } |
| 7592 | |
| 7593 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7594 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 7595 | * |
| 7596 | * This function adds the calling process to a driver global queue. When an |
| 7597 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 7598 | */ |
| 7599 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 7600 | { |
| 7601 | int rc; |
| 7602 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7603 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7604 | |
| 7605 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 7606 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7607 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7608 | |
| 7609 | if (rc >= 0) { |
| 7610 | /* For sanity check when we get ioctl */ |
| 7611 | filep->private_data = filep; |
| 7612 | return 0; |
| 7613 | } |
| 7614 | |
| 7615 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 7616 | |
| 7617 | return rc; |
| 7618 | } |
| 7619 | |
| 7620 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7621 | * megasas_mgmt_poll - char node "poll" entry point |
| 7622 | * */ |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 7623 | static __poll_t megasas_mgmt_poll(struct file *file, poll_table *wait) |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7624 | { |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 7625 | __poll_t mask; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7626 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7627 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7628 | poll_wait(file, &megasas_poll_wait, wait); |
| 7629 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 7630 | if (megasas_poll_wait_aen) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 7631 | mask = (EPOLLIN | EPOLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7632 | else |
| 7633 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7634 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7635 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 7636 | return mask; |
| 7637 | } |
| 7638 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7639 | /* |
| 7640 | * megasas_set_crash_dump_params_ioctl: |
| 7641 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 7642 | * @cmd: MFI command frame |
| 7643 | */ |
| 7644 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7645 | 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] | 7646 | { |
| 7647 | struct megasas_instance *local_instance; |
| 7648 | int i, error = 0; |
| 7649 | int crash_support; |
| 7650 | |
| 7651 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 7652 | |
| 7653 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 7654 | local_instance = megasas_mgmt_info.instance[i]; |
| 7655 | if (local_instance && local_instance->crash_dump_drv_support) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7656 | if ((atomic_read(&local_instance->adprecovery) == |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7657 | MEGASAS_HBA_OPERATIONAL) && |
| 7658 | !megasas_set_crash_dump_params(local_instance, |
| 7659 | crash_support)) { |
| 7660 | local_instance->crash_dump_app_support = |
| 7661 | crash_support; |
| 7662 | dev_info(&local_instance->pdev->dev, |
| 7663 | "Application firmware crash " |
| 7664 | "dump mode set success\n"); |
| 7665 | error = 0; |
| 7666 | } else { |
| 7667 | dev_info(&local_instance->pdev->dev, |
| 7668 | "Application firmware crash " |
| 7669 | "dump mode set failed\n"); |
| 7670 | error = -1; |
| 7671 | } |
| 7672 | } |
| 7673 | } |
| 7674 | return error; |
| 7675 | } |
| 7676 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7677 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7678 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 7679 | * @instance: Adapter soft state |
| 7680 | * @argp: User's ioctl packet |
| 7681 | */ |
| 7682 | static int |
| 7683 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 7684 | struct megasas_iocpacket __user * user_ioc, |
| 7685 | struct megasas_iocpacket *ioc) |
| 7686 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7687 | struct megasas_sge64 *kern_sge64 = NULL; |
| 7688 | struct megasas_sge32 *kern_sge32 = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7689 | struct megasas_cmd *cmd; |
| 7690 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 7691 | dma_addr_t buf_handle = 0; |
| 7692 | int error = 0, i; |
| 7693 | void *sense = NULL; |
| 7694 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7695 | unsigned long *sense_ptr; |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7696 | u32 opcode = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7697 | |
| 7698 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 7699 | |
| 7700 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7701 | 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] | 7702 | ioc->sge_count, MAX_IOCTL_SGE); |
| 7703 | return -EINVAL; |
| 7704 | } |
| 7705 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 7706 | if ((ioc->frame.hdr.cmd >= MFI_CMD_OP_COUNT) || |
| 7707 | ((ioc->frame.hdr.cmd == MFI_CMD_NVME) && |
| 7708 | !instance->support_nvme_passthru)) { |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7709 | dev_err(&instance->pdev->dev, |
| 7710 | "Received invalid ioctl command 0x%x\n", |
| 7711 | ioc->frame.hdr.cmd); |
| 7712 | return -ENOTSUPP; |
| 7713 | } |
| 7714 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7715 | cmd = megasas_get_cmd(instance); |
| 7716 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7717 | 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] | 7718 | return -ENOMEM; |
| 7719 | } |
| 7720 | |
| 7721 | /* |
| 7722 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 7723 | * frames into our cmd's frames. cmd->frame's context will get |
| 7724 | * overwritten when we copy from user's frames. So set that value |
| 7725 | * alone separately |
| 7726 | */ |
| 7727 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7728 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7729 | cmd->frame->hdr.pad_0 = 0; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7730 | |
| 7731 | cmd->frame->hdr.flags &= (~MFI_FRAME_IEEE); |
| 7732 | |
| 7733 | if (instance->consistent_mask_64bit) |
| 7734 | cmd->frame->hdr.flags |= cpu_to_le16((MFI_FRAME_SGL64 | |
| 7735 | MFI_FRAME_SENSE64)); |
| 7736 | else |
| 7737 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_SGL64 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7738 | MFI_FRAME_SENSE64)); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7739 | |
| 7740 | if (cmd->frame->hdr.cmd == MFI_CMD_DCMD) |
| 7741 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7742 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 7743 | if (opcode == MR_DCMD_CTRL_SHUTDOWN) { |
Shivasharan S | 95c0608 | 2017-02-10 00:59:23 -0800 | [diff] [blame] | 7744 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) { |
| 7745 | megasas_return_cmd(instance, cmd); |
| 7746 | return -1; |
| 7747 | } |
| 7748 | } |
| 7749 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 7750 | if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7751 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 7752 | megasas_return_cmd(instance, cmd); |
| 7753 | return error; |
| 7754 | } |
| 7755 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7756 | /* |
| 7757 | * The management interface between applications and the fw uses |
| 7758 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 7759 | * etc are accomplishes through different kinds of MFI frames. The |
| 7760 | * driver needs to care only about substituting user buffers with |
| 7761 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 7762 | * struct iocpacket itself. |
| 7763 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7764 | if (instance->consistent_mask_64bit) |
| 7765 | kern_sge64 = (struct megasas_sge64 *) |
| 7766 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 7767 | else |
| 7768 | kern_sge32 = (struct megasas_sge32 *) |
| 7769 | ((unsigned long)cmd->frame + ioc->sgl_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7770 | |
| 7771 | /* |
| 7772 | * For each user buffer, create a mirror buffer and copy in |
| 7773 | */ |
| 7774 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 7775 | if (!ioc->sgl[i].iov_len) |
| 7776 | continue; |
| 7777 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7778 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7779 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7780 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7781 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7782 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 7783 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7784 | error = -ENOMEM; |
| 7785 | goto out; |
| 7786 | } |
| 7787 | |
| 7788 | /* |
| 7789 | * We don't change the dma_coherent_mask, so |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7790 | * dma_alloc_coherent only returns 32bit addresses |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7791 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7792 | if (instance->consistent_mask_64bit) { |
| 7793 | kern_sge64[i].phys_addr = cpu_to_le64(buf_handle); |
| 7794 | kern_sge64[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 7795 | } else { |
| 7796 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 7797 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 7798 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7799 | |
| 7800 | /* |
| 7801 | * We created a kernel buffer corresponding to the |
| 7802 | * user buffer. Now copy in from the user buffer |
| 7803 | */ |
| 7804 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 7805 | (u32) (ioc->sgl[i].iov_len))) { |
| 7806 | error = -EFAULT; |
| 7807 | goto out; |
| 7808 | } |
| 7809 | } |
| 7810 | |
| 7811 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7812 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 7813 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7814 | if (!sense) { |
| 7815 | error = -ENOMEM; |
| 7816 | goto out; |
| 7817 | } |
| 7818 | |
| 7819 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7820 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7821 | if (instance->consistent_mask_64bit) |
| 7822 | *sense_ptr = cpu_to_le64(sense_handle); |
| 7823 | else |
| 7824 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7825 | } |
| 7826 | |
| 7827 | /* |
| 7828 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 7829 | * cmd to the SCSI mid-layer |
| 7830 | */ |
| 7831 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7832 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 7833 | cmd->sync_cmd = 0; |
| 7834 | dev_err(&instance->pdev->dev, |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7835 | "return -EBUSY from %s %d cmd 0x%x opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
| 7836 | __func__, __LINE__, cmd->frame->hdr.cmd, opcode, |
| 7837 | cmd->cmd_status_drv); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7838 | return -EBUSY; |
| 7839 | } |
| 7840 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7841 | cmd->sync_cmd = 0; |
| 7842 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 7843 | if (instance->unload == 1) { |
| 7844 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 7845 | "don't submit data to application\n"); |
| 7846 | goto out; |
| 7847 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7848 | /* |
| 7849 | * copy out the kernel buffers to user buffers |
| 7850 | */ |
| 7851 | for (i = 0; i < ioc->sge_count; i++) { |
| 7852 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 7853 | ioc->sgl[i].iov_len)) { |
| 7854 | error = -EFAULT; |
| 7855 | goto out; |
| 7856 | } |
| 7857 | } |
| 7858 | |
| 7859 | /* |
| 7860 | * copy out the sense |
| 7861 | */ |
| 7862 | if (ioc->sense_len) { |
| 7863 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7864 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7865 | * sense buffer address |
| 7866 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7867 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 7868 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7869 | |
Shivasharan S | 318aaef | 2017-02-10 00:59:22 -0800 | [diff] [blame] | 7870 | if (copy_to_user((void __user *)((unsigned long) |
| 7871 | get_unaligned((unsigned long *)sense_ptr)), |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 7872 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7873 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 7874 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7875 | error = -EFAULT; |
| 7876 | goto out; |
| 7877 | } |
| 7878 | } |
| 7879 | |
| 7880 | /* |
| 7881 | * copy the status codes returned by the fw |
| 7882 | */ |
| 7883 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 7884 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7885 | 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] | 7886 | error = -EFAULT; |
| 7887 | } |
| 7888 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7889 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7890 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 7891 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7892 | sense, sense_handle); |
| 7893 | } |
| 7894 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 7895 | for (i = 0; i < ioc->sge_count; i++) { |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7896 | if (kbuff_arr[i]) { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7897 | if (instance->consistent_mask_64bit) |
| 7898 | dma_free_coherent(&instance->pdev->dev, |
| 7899 | le32_to_cpu(kern_sge64[i].length), |
| 7900 | kbuff_arr[i], |
| 7901 | le64_to_cpu(kern_sge64[i].phys_addr)); |
| 7902 | else |
| 7903 | dma_free_coherent(&instance->pdev->dev, |
| 7904 | le32_to_cpu(kern_sge32[i].length), |
| 7905 | kbuff_arr[i], |
| 7906 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 7907 | kbuff_arr[i] = NULL; |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 7908 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7909 | } |
| 7910 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7911 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7912 | return error; |
| 7913 | } |
| 7914 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7915 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 7916 | { |
| 7917 | struct megasas_iocpacket __user *user_ioc = |
| 7918 | (struct megasas_iocpacket __user *)arg; |
| 7919 | struct megasas_iocpacket *ioc; |
| 7920 | struct megasas_instance *instance; |
| 7921 | int error; |
| 7922 | |
Markus Elfring | 709ab23 | 2016-08-21 10:39:04 +0200 | [diff] [blame] | 7923 | ioc = memdup_user(user_ioc, sizeof(*ioc)); |
| 7924 | if (IS_ERR(ioc)) |
| 7925 | return PTR_ERR(ioc); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7926 | |
| 7927 | instance = megasas_lookup_instance(ioc->host_no); |
| 7928 | if (!instance) { |
| 7929 | error = -ENODEV; |
| 7930 | goto out_kfree_ioc; |
| 7931 | } |
| 7932 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7933 | /* Block ioctls in VF mode */ |
| 7934 | if (instance->requestorId && !allow_vf_ioctls) { |
| 7935 | error = -ENODEV; |
| 7936 | goto out_kfree_ioc; |
| 7937 | } |
| 7938 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7939 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7940 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7941 | error = -ENODEV; |
| 7942 | goto out_kfree_ioc; |
| 7943 | } |
| 7944 | |
| 7945 | if (instance->unload == 1) { |
| 7946 | error = -ENODEV; |
| 7947 | goto out_kfree_ioc; |
| 7948 | } |
| 7949 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7950 | if (down_interruptible(&instance->ioctl_sem)) { |
| 7951 | error = -ERESTARTSYS; |
| 7952 | goto out_kfree_ioc; |
| 7953 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7954 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 7955 | if (megasas_wait_for_adapter_operational(instance)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7956 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 7957 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7958 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7959 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7960 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7961 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7962 | up(&instance->ioctl_sem); |
| 7963 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7964 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7965 | kfree(ioc); |
| 7966 | return error; |
| 7967 | } |
| 7968 | |
| 7969 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 7970 | { |
| 7971 | struct megasas_instance *instance; |
| 7972 | struct megasas_aen aen; |
| 7973 | int error; |
| 7974 | |
| 7975 | if (file->private_data != file) { |
| 7976 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 7977 | "called first\n"); |
| 7978 | return -EINVAL; |
| 7979 | } |
| 7980 | |
| 7981 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 7982 | return -EFAULT; |
| 7983 | |
| 7984 | instance = megasas_lookup_instance(aen.host_no); |
| 7985 | |
| 7986 | if (!instance) |
| 7987 | return -ENODEV; |
| 7988 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7989 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7990 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7991 | } |
| 7992 | |
| 7993 | if (instance->unload == 1) { |
| 7994 | return -ENODEV; |
| 7995 | } |
| 7996 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 7997 | if (megasas_wait_for_adapter_operational(instance)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7998 | return -ENODEV; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7999 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8000 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8001 | error = megasas_register_aen(instance, aen.seq_num, |
| 8002 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8003 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8004 | return error; |
| 8005 | } |
| 8006 | |
| 8007 | /** |
| 8008 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 8009 | */ |
| 8010 | static long |
| 8011 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 8012 | { |
| 8013 | switch (cmd) { |
| 8014 | case MEGASAS_IOC_FIRMWARE: |
| 8015 | return megasas_mgmt_ioctl_fw(file, arg); |
| 8016 | |
| 8017 | case MEGASAS_IOC_GET_AEN: |
| 8018 | return megasas_mgmt_ioctl_aen(file, arg); |
| 8019 | } |
| 8020 | |
| 8021 | return -ENOTTY; |
| 8022 | } |
| 8023 | |
| 8024 | #ifdef CONFIG_COMPAT |
| 8025 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 8026 | { |
| 8027 | struct compat_megasas_iocpacket __user *cioc = |
| 8028 | (struct compat_megasas_iocpacket __user *)arg; |
| 8029 | struct megasas_iocpacket __user *ioc = |
| 8030 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 8031 | int i; |
| 8032 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8033 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 8034 | u32 local_sense_off; |
| 8035 | u32 local_sense_len; |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8036 | u32 user_sense_off; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8037 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8038 | if (clear_user(ioc, sizeof(*ioc))) |
| 8039 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8040 | |
| 8041 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 8042 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 8043 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 8044 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 8045 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 8046 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 8047 | return -EFAULT; |
| 8048 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8049 | /* |
| 8050 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 8051 | * sense_len is not null, so prepare the 64bit value under |
| 8052 | * the same condition. |
| 8053 | */ |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8054 | if (get_user(local_sense_off, &ioc->sense_off) || |
| 8055 | get_user(local_sense_len, &ioc->sense_len) || |
| 8056 | get_user(user_sense_off, &cioc->sense_off)) |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 8057 | return -EFAULT; |
| 8058 | |
Wenwen Wang | 47db787 | 2018-10-06 13:34:21 -0500 | [diff] [blame] | 8059 | if (local_sense_off != user_sense_off) |
| 8060 | return -EINVAL; |
| 8061 | |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 8062 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8063 | void __user **sense_ioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8064 | (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8065 | compat_uptr_t *sense_cioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8066 | (compat_uptr_t *)(((unsigned long)&cioc->frame.raw) + user_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8067 | if (get_user(ptr, sense_cioc_ptr) || |
| 8068 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 8069 | return -EFAULT; |
| 8070 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8071 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8072 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8073 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 8074 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 8075 | copy_in_user(&ioc->sgl[i].iov_len, |
| 8076 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 8077 | return -EFAULT; |
| 8078 | } |
| 8079 | |
| 8080 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 8081 | |
| 8082 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 8083 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 8084 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 8085 | return -EFAULT; |
| 8086 | } |
| 8087 | return error; |
| 8088 | } |
| 8089 | |
| 8090 | static long |
| 8091 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 8092 | unsigned long arg) |
| 8093 | { |
| 8094 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 8095 | case MEGASAS_IOC_FIRMWARE32: |
| 8096 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8097 | case MEGASAS_IOC_GET_AEN: |
| 8098 | return megasas_mgmt_ioctl_aen(file, arg); |
| 8099 | } |
| 8100 | |
| 8101 | return -ENOTTY; |
| 8102 | } |
| 8103 | #endif |
| 8104 | |
| 8105 | /* |
| 8106 | * File operations structure for management interface |
| 8107 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 8108 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8109 | .owner = THIS_MODULE, |
| 8110 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8111 | .fasync = megasas_mgmt_fasync, |
| 8112 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 8113 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8114 | #ifdef CONFIG_COMPAT |
| 8115 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 8116 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 8117 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8118 | }; |
| 8119 | |
| 8120 | /* |
| 8121 | * PCI hotplug support registration structure |
| 8122 | */ |
| 8123 | static struct pci_driver megasas_pci_driver = { |
| 8124 | |
| 8125 | .name = "megaraid_sas", |
| 8126 | .id_table = megasas_pci_table, |
| 8127 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8128 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 8129 | .suspend = megasas_suspend, |
| 8130 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8131 | .shutdown = megasas_shutdown, |
| 8132 | }; |
| 8133 | |
| 8134 | /* |
| 8135 | * Sysfs driver attributes |
| 8136 | */ |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8137 | static ssize_t version_show(struct device_driver *dd, char *buf) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8138 | { |
| 8139 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 8140 | MEGASAS_VERSION); |
| 8141 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8142 | static DRIVER_ATTR_RO(version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8143 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8144 | 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] | 8145 | { |
| 8146 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 8147 | MEGASAS_RELDATE); |
| 8148 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8149 | static DRIVER_ATTR_RO(release_date); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8150 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8151 | 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] | 8152 | { |
| 8153 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 8154 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8155 | static DRIVER_ATTR_RO(support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8156 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8157 | 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] | 8158 | { |
| 8159 | return sprintf(buf, "%u\n", support_device_change); |
| 8160 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8161 | static DRIVER_ATTR_RO(support_device_change); |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8162 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8163 | static ssize_t dbg_lvl_show(struct device_driver *dd, char *buf) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8164 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8165 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8166 | } |
| 8167 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8168 | static ssize_t dbg_lvl_store(struct device_driver *dd, const char *buf, |
| 8169 | size_t count) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8170 | { |
| 8171 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 8172 | |
| 8173 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8174 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 8175 | retval = -EINVAL; |
| 8176 | } |
| 8177 | return retval; |
| 8178 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8179 | static DRIVER_ATTR_RW(dbg_lvl); |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8180 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8181 | static ssize_t |
| 8182 | support_nvme_encapsulation_show(struct device_driver *dd, char *buf) |
| 8183 | { |
| 8184 | return sprintf(buf, "%u\n", support_nvme_encapsulation); |
| 8185 | } |
| 8186 | |
| 8187 | static DRIVER_ATTR_RO(support_nvme_encapsulation); |
| 8188 | |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 8189 | static inline void megasas_remove_scsi_device(struct scsi_device *sdev) |
| 8190 | { |
| 8191 | sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n"); |
| 8192 | scsi_remove_device(sdev); |
| 8193 | scsi_device_put(sdev); |
| 8194 | } |
| 8195 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8196 | /** |
| 8197 | * megasas_update_device_list - Update the PD and LD device list from FW |
| 8198 | * after an AEN event notification |
| 8199 | * @instance: Adapter soft state |
| 8200 | * @event_type: Indicates type of event (PD or LD event) |
| 8201 | * |
| 8202 | * @return: Success or failure |
| 8203 | * |
| 8204 | * Issue DCMDs to Firmware to update the internal device list in driver. |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8205 | * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination |
| 8206 | * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list. |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8207 | */ |
| 8208 | static |
| 8209 | int megasas_update_device_list(struct megasas_instance *instance, |
| 8210 | int event_type) |
| 8211 | { |
| 8212 | int dcmd_ret = DCMD_SUCCESS; |
| 8213 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8214 | if (instance->enable_fw_dev_list) { |
| 8215 | dcmd_ret = megasas_host_device_list_query(instance, false); |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8216 | if (dcmd_ret != DCMD_SUCCESS) |
| 8217 | goto out; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8218 | } else { |
| 8219 | if (event_type & SCAN_PD_CHANNEL) { |
| 8220 | dcmd_ret = megasas_get_pd_list(instance); |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8221 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8222 | if (dcmd_ret != DCMD_SUCCESS) |
| 8223 | goto out; |
| 8224 | } |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8225 | |
| 8226 | if (event_type & SCAN_VD_CHANNEL) { |
| 8227 | if (!instance->requestorId || |
| 8228 | (instance->requestorId && |
| 8229 | megasas_get_ld_vf_affiliation(instance, 0))) { |
| 8230 | dcmd_ret = megasas_ld_list_query(instance, |
| 8231 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 8232 | if (dcmd_ret != DCMD_SUCCESS) |
| 8233 | goto out; |
| 8234 | } |
| 8235 | } |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8236 | } |
| 8237 | |
| 8238 | out: |
| 8239 | return dcmd_ret; |
| 8240 | } |
| 8241 | |
| 8242 | /** |
| 8243 | * megasas_add_remove_devices - Add/remove devices to SCSI mid-layer |
| 8244 | * after an AEN event notification |
| 8245 | * @instance: Adapter soft state |
| 8246 | * @scan_type: Indicates type of devices (PD/LD) to add |
| 8247 | * @return void |
| 8248 | */ |
| 8249 | static |
| 8250 | void megasas_add_remove_devices(struct megasas_instance *instance, |
| 8251 | int scan_type) |
| 8252 | { |
| 8253 | int i, j; |
| 8254 | u16 pd_index = 0; |
| 8255 | u16 ld_index = 0; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8256 | u16 channel = 0, id = 0; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8257 | struct Scsi_Host *host; |
| 8258 | struct scsi_device *sdev1; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8259 | struct MR_HOST_DEVICE_LIST *targetid_list = NULL; |
| 8260 | struct MR_HOST_DEVICE_LIST_ENTRY *targetid_entry = NULL; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8261 | |
| 8262 | host = instance->host; |
| 8263 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8264 | if (instance->enable_fw_dev_list) { |
| 8265 | targetid_list = instance->host_device_list_buf; |
| 8266 | for (i = 0; i < targetid_list->count; i++) { |
| 8267 | targetid_entry = &targetid_list->host_device_list[i]; |
| 8268 | if (targetid_entry->flags.u.bits.is_sys_pd) { |
| 8269 | channel = le16_to_cpu(targetid_entry->target_id) / |
| 8270 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8271 | id = le16_to_cpu(targetid_entry->target_id) % |
| 8272 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8273 | } else { |
| 8274 | channel = MEGASAS_MAX_PD_CHANNELS + |
| 8275 | (le16_to_cpu(targetid_entry->target_id) / |
| 8276 | MEGASAS_MAX_DEV_PER_CHANNEL); |
| 8277 | id = le16_to_cpu(targetid_entry->target_id) % |
| 8278 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8279 | } |
| 8280 | sdev1 = scsi_device_lookup(host, channel, id, 0); |
| 8281 | if (!sdev1) { |
| 8282 | scsi_add_device(host, channel, id, 0); |
| 8283 | } else { |
| 8284 | scsi_device_put(sdev1); |
| 8285 | } |
| 8286 | } |
| 8287 | } |
| 8288 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8289 | if (scan_type & SCAN_PD_CHANNEL) { |
| 8290 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 8291 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 8292 | pd_index = i * MEGASAS_MAX_DEV_PER_CHANNEL + j; |
| 8293 | sdev1 = scsi_device_lookup(host, i, j, 0); |
| 8294 | if (instance->pd_list[pd_index].driveState == |
| 8295 | MR_PD_STATE_SYSTEM) { |
| 8296 | if (!sdev1) |
| 8297 | scsi_add_device(host, i, j, 0); |
| 8298 | else |
| 8299 | scsi_device_put(sdev1); |
| 8300 | } else { |
| 8301 | if (sdev1) |
| 8302 | megasas_remove_scsi_device(sdev1); |
| 8303 | } |
| 8304 | } |
| 8305 | } |
| 8306 | } |
| 8307 | |
| 8308 | if (scan_type & SCAN_VD_CHANNEL) { |
| 8309 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 8310 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 8311 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 8312 | sdev1 = scsi_device_lookup(host, |
| 8313 | MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 8314 | if (instance->ld_ids[ld_index] != 0xff) { |
| 8315 | if (!sdev1) |
| 8316 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 8317 | else |
| 8318 | scsi_device_put(sdev1); |
| 8319 | } else { |
| 8320 | if (sdev1) |
| 8321 | megasas_remove_scsi_device(sdev1); |
| 8322 | } |
| 8323 | } |
| 8324 | } |
| 8325 | } |
| 8326 | |
| 8327 | } |
| 8328 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8329 | static void |
| 8330 | megasas_aen_polling(struct work_struct *work) |
| 8331 | { |
| 8332 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 8333 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8334 | struct megasas_instance *instance = ev->instance; |
| 8335 | union megasas_evt_class_locale class_locale; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8336 | int event_type = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8337 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8338 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8339 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8340 | |
| 8341 | if (!instance) { |
| 8342 | printk(KERN_ERR "invalid instance!\n"); |
| 8343 | kfree(ev); |
| 8344 | return; |
| 8345 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8346 | |
| 8347 | /* Adjust event workqueue thread wait time for VF mode */ |
| 8348 | if (instance->requestorId) |
| 8349 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 8350 | |
| 8351 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8352 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8353 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8354 | instance->ev = NULL; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8355 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 8356 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8357 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 8358 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8359 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8360 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8361 | case MR_EVT_PD_REMOVED: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8362 | event_type = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 8363 | break; |
| 8364 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8365 | case MR_EVT_LD_OFFLINE: |
| 8366 | case MR_EVT_CFG_CLEARED: |
| 8367 | case MR_EVT_LD_DELETED: |
| 8368 | case MR_EVT_LD_CREATED: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8369 | event_type = SCAN_VD_CHANNEL; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8370 | break; |
| 8371 | |
| 8372 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 8373 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 8374 | case MR_EVT_LD_STATE_CHANGE: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8375 | event_type = SCAN_PD_CHANNEL | SCAN_VD_CHANNEL; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8376 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 8377 | instance->host->host_no); |
| 8378 | break; |
| 8379 | |
| 8380 | case MR_EVT_CTRL_PROP_CHANGED: |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 8381 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 8382 | if (dcmd_ret == DCMD_SUCCESS && |
| 8383 | instance->snapdump_wait_time) { |
| 8384 | megasas_get_snapdump_properties(instance); |
| 8385 | dev_info(&instance->pdev->dev, |
| 8386 | "Snap dump wait time\t: %d\n", |
| 8387 | instance->snapdump_wait_time); |
| 8388 | } |
| 8389 | break; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8390 | default: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8391 | event_type = 0; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8392 | break; |
| 8393 | } |
| 8394 | } else { |
| 8395 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 8396 | mutex_unlock(&instance->reset_mutex); |
| 8397 | kfree(ev); |
| 8398 | return; |
| 8399 | } |
| 8400 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8401 | if (event_type) |
| 8402 | dcmd_ret = megasas_update_device_list(instance, event_type); |
| 8403 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8404 | mutex_unlock(&instance->reset_mutex); |
| 8405 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8406 | if (event_type && dcmd_ret == DCMD_SUCCESS) |
| 8407 | megasas_add_remove_devices(instance, event_type); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8408 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8409 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8410 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 8411 | else |
| 8412 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8413 | |
| 8414 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 8415 | class_locale.members.reserved = 0; |
| 8416 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 8417 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8418 | |
| 8419 | if (instance->aen_cmd != NULL) { |
| 8420 | kfree(ev); |
| 8421 | return; |
| 8422 | } |
| 8423 | |
| 8424 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8425 | error = megasas_register_aen(instance, seq_num, |
| 8426 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8427 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8428 | dev_err(&instance->pdev->dev, |
| 8429 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8430 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8431 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8432 | kfree(ev); |
| 8433 | } |
| 8434 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8435 | /** |
| 8436 | * megasas_init - Driver load entry point |
| 8437 | */ |
| 8438 | static int __init megasas_init(void) |
| 8439 | { |
| 8440 | int rval; |
| 8441 | |
| 8442 | /* |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 8443 | * Booted in kdump kernel, minimize memory footprints by |
| 8444 | * disabling few features |
| 8445 | */ |
| 8446 | if (reset_devices) { |
| 8447 | msix_vectors = 1; |
| 8448 | rdpq_enable = 0; |
| 8449 | dual_qdepth_disable = 1; |
| 8450 | } |
| 8451 | |
| 8452 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8453 | * Announce driver version and other information |
| 8454 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 8455 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8456 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 8457 | spin_lock_init(&poll_aen_lock); |
| 8458 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8459 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8460 | support_device_change = 1; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8461 | support_nvme_encapsulation = true; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8462 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8463 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 8464 | |
| 8465 | /* |
| 8466 | * Register character device node |
| 8467 | */ |
| 8468 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 8469 | |
| 8470 | if (rval < 0) { |
| 8471 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 8472 | return rval; |
| 8473 | } |
| 8474 | |
| 8475 | megasas_mgmt_majorno = rval; |
| 8476 | |
| 8477 | /* |
| 8478 | * Register ourselves as PCI hotplug module |
| 8479 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 8480 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8481 | |
| 8482 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 8483 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8484 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8485 | } |
| 8486 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8487 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8488 | &driver_attr_version); |
| 8489 | if (rval) |
| 8490 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8491 | |
| 8492 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8493 | &driver_attr_release_date); |
| 8494 | if (rval) |
| 8495 | goto err_dcf_rel_date; |
| 8496 | |
| 8497 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8498 | &driver_attr_support_poll_for_event); |
| 8499 | if (rval) |
| 8500 | goto err_dcf_support_poll_for_event; |
| 8501 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8502 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8503 | &driver_attr_dbg_lvl); |
| 8504 | if (rval) |
| 8505 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8506 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8507 | &driver_attr_support_device_change); |
| 8508 | if (rval) |
| 8509 | goto err_dcf_support_device_change; |
| 8510 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8511 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8512 | &driver_attr_support_nvme_encapsulation); |
| 8513 | if (rval) |
| 8514 | goto err_dcf_support_nvme_encapsulation; |
| 8515 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8516 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8517 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8518 | err_dcf_support_nvme_encapsulation: |
| 8519 | driver_remove_file(&megasas_pci_driver.driver, |
| 8520 | &driver_attr_support_device_change); |
| 8521 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8522 | err_dcf_support_device_change: |
| 8523 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8524 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8525 | err_dcf_dbg_lvl: |
| 8526 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8527 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8528 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8529 | driver_remove_file(&megasas_pci_driver.driver, |
| 8530 | &driver_attr_release_date); |
| 8531 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8532 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 8533 | err_dcf_attr_ver: |
| 8534 | pci_unregister_driver(&megasas_pci_driver); |
| 8535 | err_pcidrv: |
| 8536 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 8537 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8538 | } |
| 8539 | |
| 8540 | /** |
| 8541 | * megasas_exit - Driver unload entry point |
| 8542 | */ |
| 8543 | static void __exit megasas_exit(void) |
| 8544 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8545 | driver_remove_file(&megasas_pci_driver.driver, |
| 8546 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8547 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8548 | &driver_attr_support_poll_for_event); |
| 8549 | driver_remove_file(&megasas_pci_driver.driver, |
| 8550 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8551 | driver_remove_file(&megasas_pci_driver.driver, |
| 8552 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8553 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8554 | driver_remove_file(&megasas_pci_driver.driver, |
| 8555 | &driver_attr_support_nvme_encapsulation); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8556 | |
| 8557 | pci_unregister_driver(&megasas_pci_driver); |
| 8558 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 8559 | } |
| 8560 | |
| 8561 | module_init(megasas_init); |
| 8562 | module_exit(megasas_exit); |