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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 67 | module_param_named(max_sectors, max_sectors, int, 0444); |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 72 | module_param(msix_disable, int, 0444); |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 76 | module_param(msix_vectors, int, 0444); |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 80 | module_param(allow_vf_ioctls, int, 0444); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 84 | module_param(throttlequeuedepth, int, 0444); |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 89 | module_param(resetwaittime, int, 0444); |
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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 93 | module_param(smp_affinity_enable, int, 0444); |
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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 97 | module_param(rdpq_enable, int, 0444); |
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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 101 | module_param(dual_qdepth_disable, int, 0444); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 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; |
Tomas Henzl | ea14e46 | 2019-05-29 18:00:40 +0200 | [diff] [blame] | 105 | module_param(scmd_timeout, int, 0444); |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 106 | MODULE_PARM_DESC(scmd_timeout, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer."); |
| 107 | |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 108 | int perf_mode = -1; |
| 109 | module_param(perf_mode, int, 0444); |
| 110 | MODULE_PARM_DESC(perf_mode, "Performance mode (only for Aero adapters), options:\n\t\t" |
| 111 | "0 - balanced: High iops and low latency queues are allocated &\n\t\t" |
| 112 | "interrupt coalescing is enabled only on high iops queues\n\t\t" |
| 113 | "1 - iops: High iops queues are not allocated &\n\t\t" |
| 114 | "interrupt coalescing is enabled on all queues\n\t\t" |
| 115 | "2 - latency: High iops queues are not allocated &\n\t\t" |
| 116 | "interrupt coalescing is disabled on all queues\n\t\t" |
| 117 | "default mode is 'balanced'" |
| 118 | ); |
| 119 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 120 | MODULE_LICENSE("GPL"); |
| 121 | MODULE_VERSION(MEGASAS_VERSION); |
Shivasharan S | 365597c | 2018-10-16 23:37:43 -0700 | [diff] [blame] | 122 | MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com"); |
| 123 | MODULE_DESCRIPTION("Broadcom MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 124 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 125 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 126 | static int megasas_get_pd_list(struct megasas_instance *instance); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 127 | static int megasas_ld_list_query(struct megasas_instance *instance, |
| 128 | u8 query_type); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 129 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 130 | static int megasas_register_aen(struct megasas_instance *instance, |
| 131 | u32 seq_num, u32 class_locale_word); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 132 | static void megasas_get_pd_info(struct megasas_instance *instance, |
| 133 | struct scsi_device *sdev); |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 134 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 135 | /* |
| 136 | * PCI ID table for all supported controllers |
| 137 | */ |
| 138 | static struct pci_device_id megasas_pci_table[] = { |
| 139 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 140 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 141 | /* xscale IOP */ |
| 142 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 143 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 144 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 145 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 146 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 147 | /* gen2*/ |
| 148 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 149 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 150 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 151 | /* skinny*/ |
| 152 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 153 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 154 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 155 | /* xscale IOP, vega */ |
| 156 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 157 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 158 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 159 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 160 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 161 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 162 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 163 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 164 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 165 | /* Fury */ |
sumit.saxena@avagotech.com | 90c204b | 2015-10-15 13:39:44 +0530 | [diff] [blame] | 166 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER)}, |
| 167 | /* Intruder */ |
| 168 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INTRUDER_24)}, |
| 169 | /* Intruder 24 port*/ |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 170 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CUTLASS_52)}, |
| 171 | {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] | 172 | /* VENTURA */ |
| 173 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA)}, |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 174 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_CRUSADER)}, |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 175 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_HARPOON)}, |
| 176 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_TOMCAT)}, |
| 177 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VENTURA_4PORT)}, |
| 178 | {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] | 179 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E1)}, |
| 180 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E2)}, |
| 181 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E5)}, |
| 182 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E6)}, |
Chandrakanth Patil | dd80769 | 2019-06-25 16:34:20 +0530 | [diff] [blame] | 183 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E0)}, |
| 184 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E3)}, |
| 185 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E4)}, |
| 186 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_AERO_10E7)}, |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 187 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 191 | |
| 192 | static int megasas_mgmt_majorno; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 193 | struct megasas_mgmt_info megasas_mgmt_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 194 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 195 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 196 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 197 | static int megasas_poll_wait_aen; |
| 198 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 199 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 200 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 201 | static u32 support_device_change; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 202 | static bool support_nvme_encapsulation; |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 203 | static bool support_pci_lane_margining; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 204 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 205 | /* define lock for aen poll */ |
| 206 | spinlock_t poll_aen_lock; |
| 207 | |
Shivasharan S | ba53572 | 2019-05-07 10:05:49 -0700 | [diff] [blame] | 208 | extern struct dentry *megasas_debugfs_root; |
| 209 | extern void megasas_init_debugfs(void); |
| 210 | extern void megasas_exit_debugfs(void); |
| 211 | extern void megasas_setup_debugfs(struct megasas_instance *instance); |
| 212 | extern void megasas_destroy_debugfs(struct megasas_instance *instance); |
| 213 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 214 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 215 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 216 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 217 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 218 | megasas_read_fw_status_reg_gen2(struct megasas_instance *instance); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 219 | static int |
| 220 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 221 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 222 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 223 | static u32 |
| 224 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 225 | u32 |
| 226 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 227 | struct scsi_cmnd *scmd); |
| 228 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 229 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 230 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 231 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 232 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 233 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 234 | int initial); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 235 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 236 | megasas_set_dma_mask(struct megasas_instance *instance); |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 237 | static int |
| 238 | megasas_alloc_ctrl_mem(struct megasas_instance *instance); |
| 239 | static inline void |
| 240 | megasas_free_ctrl_mem(struct megasas_instance *instance); |
| 241 | static inline int |
| 242 | megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance); |
| 243 | static inline void |
| 244 | megasas_free_ctrl_dma_buffers(struct megasas_instance *instance); |
| 245 | static inline void |
| 246 | megasas_init_ctrl_params(struct megasas_instance *instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 247 | |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 248 | u32 megasas_readl(struct megasas_instance *instance, |
| 249 | const volatile void __iomem *addr) |
| 250 | { |
| 251 | u32 i = 0, ret_val; |
| 252 | /* |
| 253 | * Due to a HW errata in Aero controllers, reads to certain |
| 254 | * Fusion registers could intermittently return all zeroes. |
| 255 | * This behavior is transient in nature and subsequent reads will |
| 256 | * return valid value. As a workaround in driver, retry readl for |
| 257 | * upto three times until a non-zero value is read. |
| 258 | */ |
| 259 | if (instance->adapter_type == AERO_SERIES) { |
| 260 | do { |
| 261 | ret_val = readl(addr); |
| 262 | i++; |
| 263 | } while (ret_val == 0 && i < 3); |
| 264 | return ret_val; |
| 265 | } else { |
| 266 | return readl(addr); |
| 267 | } |
| 268 | } |
| 269 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 270 | /** |
| 271 | * megasas_set_dma_settings - Populate DMA address, length and flags for DCMDs |
| 272 | * @instance: Adapter soft state |
| 273 | * @dcmd: DCMD frame inside MFI command |
| 274 | * @dma_addr: DMA address of buffer to be passed to FW |
| 275 | * @dma_len: Length of DMA buffer to be passed to FW |
| 276 | * @return: void |
| 277 | */ |
| 278 | void megasas_set_dma_settings(struct megasas_instance *instance, |
| 279 | struct megasas_dcmd_frame *dcmd, |
| 280 | dma_addr_t dma_addr, u32 dma_len) |
| 281 | { |
| 282 | if (instance->consistent_mask_64bit) { |
| 283 | dcmd->sgl.sge64[0].phys_addr = cpu_to_le64(dma_addr); |
| 284 | dcmd->sgl.sge64[0].length = cpu_to_le32(dma_len); |
| 285 | dcmd->flags = cpu_to_le16(dcmd->flags | MFI_FRAME_SGL64); |
| 286 | |
| 287 | } else { |
| 288 | dcmd->sgl.sge32[0].phys_addr = |
| 289 | cpu_to_le32(lower_32_bits(dma_addr)); |
| 290 | dcmd->sgl.sge32[0].length = cpu_to_le32(dma_len); |
| 291 | dcmd->flags = cpu_to_le16(dcmd->flags); |
| 292 | } |
| 293 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 294 | |
YueHaibing | 6764f51 | 2019-07-02 21:01:14 +0800 | [diff] [blame^] | 295 | static void |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 296 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 297 | { |
| 298 | instance->instancet->fire_cmd(instance, |
| 299 | cmd->frame_phys_addr, 0, instance->reg_set); |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 300 | return; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 301 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 302 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 303 | /** |
| 304 | * megasas_get_cmd - Get a command from the free pool |
| 305 | * @instance: Adapter soft state |
| 306 | * |
| 307 | * Returns a free command from the pool |
| 308 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 309 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 310 | *instance) |
| 311 | { |
| 312 | unsigned long flags; |
| 313 | struct megasas_cmd *cmd = NULL; |
| 314 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 315 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 316 | |
| 317 | if (!list_empty(&instance->cmd_pool)) { |
| 318 | cmd = list_entry((&instance->cmd_pool)->next, |
| 319 | struct megasas_cmd, list); |
| 320 | list_del_init(&cmd->list); |
| 321 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 322 | dev_err(&instance->pdev->dev, "Command pool empty!\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 323 | } |
| 324 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 325 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 326 | return cmd; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * megasas_return_cmd - Return a cmd to free command pool |
| 331 | * @instance: Adapter soft state |
| 332 | * @cmd: Command packet to be returned to free command pool |
| 333 | */ |
Andi Kleen | 68b4374 | 2017-05-08 15:58:53 -0700 | [diff] [blame] | 334 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 335 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 336 | { |
| 337 | unsigned long flags; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 338 | u32 blk_tags; |
| 339 | struct megasas_cmd_fusion *cmd_fusion; |
| 340 | struct fusion_context *fusion = instance->ctrl_context; |
| 341 | |
| 342 | /* This flag is used only for fusion adapter. |
| 343 | * Wait for Interrupt for Polled mode DCMD |
| 344 | */ |
| 345 | if (cmd->flags & DRV_DCMD_POLLED_MODE) |
| 346 | return; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 347 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 348 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 349 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 350 | if (fusion) { |
| 351 | blk_tags = instance->max_scsi_cmds + cmd->index; |
| 352 | cmd_fusion = fusion->cmd_list[blk_tags]; |
| 353 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 354 | } |
| 355 | cmd->scmd = NULL; |
| 356 | cmd->frame_count = 0; |
| 357 | cmd->flags = 0; |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 358 | memset(cmd->frame, 0, instance->mfi_frame_size); |
| 359 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 360 | if (!fusion && reset_devices) |
| 361 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 362 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 363 | |
| 364 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
| 365 | |
| 366 | } |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 367 | |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 368 | static const char * |
| 369 | format_timestamp(uint32_t timestamp) |
| 370 | { |
| 371 | static char buffer[32]; |
| 372 | |
| 373 | if ((timestamp & 0xff000000) == 0xff000000) |
| 374 | snprintf(buffer, sizeof(buffer), "boot + %us", timestamp & |
| 375 | 0x00ffffff); |
| 376 | else |
| 377 | snprintf(buffer, sizeof(buffer), "%us", timestamp); |
| 378 | return buffer; |
| 379 | } |
| 380 | |
| 381 | static const char * |
| 382 | format_class(int8_t class) |
| 383 | { |
| 384 | static char buffer[6]; |
| 385 | |
| 386 | switch (class) { |
| 387 | case MFI_EVT_CLASS_DEBUG: |
| 388 | return "debug"; |
| 389 | case MFI_EVT_CLASS_PROGRESS: |
| 390 | return "progress"; |
| 391 | case MFI_EVT_CLASS_INFO: |
| 392 | return "info"; |
| 393 | case MFI_EVT_CLASS_WARNING: |
| 394 | return "WARN"; |
| 395 | case MFI_EVT_CLASS_CRITICAL: |
| 396 | return "CRIT"; |
| 397 | case MFI_EVT_CLASS_FATAL: |
| 398 | return "FATAL"; |
| 399 | case MFI_EVT_CLASS_DEAD: |
| 400 | return "DEAD"; |
| 401 | default: |
| 402 | snprintf(buffer, sizeof(buffer), "%d", class); |
| 403 | return buffer; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * megasas_decode_evt: Decode FW AEN event and print critical event |
| 409 | * for information. |
| 410 | * @instance: Adapter soft state |
| 411 | */ |
| 412 | static void |
| 413 | megasas_decode_evt(struct megasas_instance *instance) |
| 414 | { |
| 415 | struct megasas_evt_detail *evt_detail = instance->evt_detail; |
| 416 | union megasas_evt_class_locale class_locale; |
| 417 | class_locale.word = le32_to_cpu(evt_detail->cl.word); |
| 418 | |
| 419 | if (class_locale.members.class >= MFI_EVT_CLASS_CRITICAL) |
| 420 | dev_info(&instance->pdev->dev, "%d (%s/0x%04x/%s) - %s\n", |
| 421 | le32_to_cpu(evt_detail->seq_num), |
| 422 | format_timestamp(le32_to_cpu(evt_detail->time_stamp)), |
| 423 | (class_locale.members.locale), |
| 424 | format_class(class_locale.members.class), |
| 425 | evt_detail->description); |
| 426 | } |
| 427 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 428 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 429 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 430 | * (deviceid : 1064R, PERC5) controllers |
| 431 | */ |
| 432 | |
| 433 | /** |
| 434 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 435 | * @regs: MFI register set |
| 436 | */ |
| 437 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 438 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 439 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 440 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 441 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 442 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 443 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 444 | |
| 445 | /* Dummy readl to force pci flush */ |
| 446 | readl(®s->outbound_intr_mask); |
| 447 | } |
| 448 | |
| 449 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 450 | * megasas_disable_intr_xscale -Disables interrupt |
| 451 | * @regs: MFI register set |
| 452 | */ |
| 453 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 454 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 455 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 456 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 457 | u32 mask = 0x1f; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 458 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 459 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 460 | writel(mask, ®s->outbound_intr_mask); |
| 461 | /* Dummy readl to force pci flush */ |
| 462 | readl(®s->outbound_intr_mask); |
| 463 | } |
| 464 | |
| 465 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 466 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 467 | * @regs: MFI register set |
| 468 | */ |
| 469 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 470 | megasas_read_fw_status_reg_xscale(struct megasas_instance *instance) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 471 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 472 | return readl(&instance->reg_set->outbound_msg_0); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 473 | } |
| 474 | /** |
| 475 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 476 | * @regs: MFI register set |
| 477 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 478 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 479 | megasas_clear_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 480 | { |
| 481 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 482 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 483 | struct megasas_register_set __iomem *regs; |
| 484 | regs = instance->reg_set; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 485 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 486 | /* |
| 487 | * Check if it is our interrupt |
| 488 | */ |
| 489 | status = readl(®s->outbound_intr_status); |
| 490 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 491 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 492 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 493 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 494 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * Clear the interrupt by writing back the same value |
| 498 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 499 | if (mfiStatus) |
| 500 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 501 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 502 | /* Dummy readl to force pci flush */ |
| 503 | readl(®s->outbound_intr_status); |
| 504 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 505 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /** |
| 509 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 510 | * @frame_phys_addr : Physical address of cmd |
| 511 | * @frame_count : Number of frames for the command |
| 512 | * @regs : MFI register set |
| 513 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 514 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 515 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 516 | dma_addr_t frame_phys_addr, |
| 517 | u32 frame_count, |
| 518 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 519 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 520 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 521 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 522 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 523 | writel((frame_phys_addr >> 3)|(frame_count), |
| 524 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 525 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 526 | } |
| 527 | |
| 528 | /** |
| 529 | * megasas_adp_reset_xscale - For controller reset |
| 530 | * @regs: MFI register set |
| 531 | */ |
| 532 | static int |
| 533 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 534 | struct megasas_register_set __iomem *regs) |
| 535 | { |
| 536 | u32 i; |
| 537 | u32 pcidata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 538 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 539 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 540 | |
| 541 | for (i = 0; i < 3; i++) |
| 542 | msleep(1000); /* sleep for 3 secs */ |
| 543 | pcidata = 0; |
| 544 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 545 | dev_notice(&instance->pdev->dev, "pcidata = %x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 546 | if (pcidata & 0x2) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 547 | dev_notice(&instance->pdev->dev, "mfi 1068 offset read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 548 | pcidata &= ~0x2; |
| 549 | pci_write_config_dword(instance->pdev, |
| 550 | MFI_1068_PCSR_OFFSET, pcidata); |
| 551 | |
| 552 | for (i = 0; i < 2; i++) |
| 553 | msleep(1000); /* need to wait 2 secs again */ |
| 554 | |
| 555 | pcidata = 0; |
| 556 | pci_read_config_dword(instance->pdev, |
| 557 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 558 | dev_notice(&instance->pdev->dev, "1068 offset handshake read=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 559 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 560 | dev_notice(&instance->pdev->dev, "1068 offset pcidt=%x\n", pcidata); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 561 | pcidata = 0; |
| 562 | pci_write_config_dword(instance->pdev, |
| 563 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 564 | } |
| 565 | } |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * megasas_check_reset_xscale - For controller reset check |
| 571 | * @regs: MFI register set |
| 572 | */ |
| 573 | static int |
| 574 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 575 | struct megasas_register_set __iomem *regs) |
| 576 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 577 | if ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 578 | (le32_to_cpu(*instance->consumer) == |
| 579 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 580 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 581 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 585 | |
| 586 | .fire_cmd = megasas_fire_cmd_xscale, |
| 587 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 588 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 589 | .clear_intr = megasas_clear_intr_xscale, |
| 590 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 591 | .adp_reset = megasas_adp_reset_xscale, |
| 592 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 593 | .service_isr = megasas_isr, |
| 594 | .tasklet = megasas_complete_cmd_dpc, |
| 595 | .init_adapter = megasas_init_adapter_mfi, |
| 596 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 597 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 598 | }; |
| 599 | |
| 600 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 601 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 602 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 603 | */ |
| 604 | |
| 605 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 606 | * The following functions are defined for ppc (deviceid : 0x60) |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 607 | * controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 608 | */ |
| 609 | |
| 610 | /** |
| 611 | * megasas_enable_intr_ppc - Enables interrupts |
| 612 | * @regs: MFI register set |
| 613 | */ |
| 614 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 615 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 616 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 617 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 618 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 619 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 620 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 621 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 622 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 623 | |
| 624 | /* Dummy readl to force pci flush */ |
| 625 | readl(®s->outbound_intr_mask); |
| 626 | } |
| 627 | |
| 628 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 629 | * megasas_disable_intr_ppc - Disable interrupt |
| 630 | * @regs: MFI register set |
| 631 | */ |
| 632 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 633 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 634 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 635 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 636 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 637 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 638 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 639 | writel(mask, ®s->outbound_intr_mask); |
| 640 | /* Dummy readl to force pci flush */ |
| 641 | readl(®s->outbound_intr_mask); |
| 642 | } |
| 643 | |
| 644 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 645 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 646 | * @regs: MFI register set |
| 647 | */ |
| 648 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 649 | megasas_read_fw_status_reg_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 650 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 651 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /** |
| 655 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 656 | * @regs: MFI register set |
| 657 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 658 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 659 | megasas_clear_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 660 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 661 | u32 status, mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 662 | struct megasas_register_set __iomem *regs; |
| 663 | regs = instance->reg_set; |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 664 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 665 | /* |
| 666 | * Check if it is our interrupt |
| 667 | */ |
| 668 | status = readl(®s->outbound_intr_status); |
| 669 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 670 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 671 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 672 | |
| 673 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 674 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 675 | |
| 676 | /* |
| 677 | * Clear the interrupt by writing back the same value |
| 678 | */ |
| 679 | writel(status, ®s->outbound_doorbell_clear); |
| 680 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 681 | /* Dummy readl to force pci flush */ |
| 682 | readl(®s->outbound_doorbell_clear); |
| 683 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 684 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 685 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 686 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 687 | /** |
| 688 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 689 | * @frame_phys_addr : Physical address of cmd |
| 690 | * @frame_count : Number of frames for the command |
| 691 | * @regs : MFI register set |
| 692 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 693 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 694 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 695 | dma_addr_t frame_phys_addr, |
| 696 | u32 frame_count, |
| 697 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 698 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 699 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 700 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 701 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 702 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 703 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 704 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 705 | } |
| 706 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 707 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 708 | * megasas_check_reset_ppc - For controller reset check |
| 709 | * @regs: MFI register set |
| 710 | */ |
| 711 | static int |
| 712 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 713 | struct megasas_register_set __iomem *regs) |
| 714 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 715 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 716 | return 1; |
| 717 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 718 | return 0; |
| 719 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 720 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 721 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 722 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 723 | .fire_cmd = megasas_fire_cmd_ppc, |
| 724 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 725 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 726 | .clear_intr = megasas_clear_intr_ppc, |
| 727 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 728 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 729 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 730 | .service_isr = megasas_isr, |
| 731 | .tasklet = megasas_complete_cmd_dpc, |
| 732 | .init_adapter = megasas_init_adapter_mfi, |
| 733 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 734 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 735 | }; |
| 736 | |
| 737 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 738 | * megasas_enable_intr_skinny - Enables interrupts |
| 739 | * @regs: MFI register set |
| 740 | */ |
| 741 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 742 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 743 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 744 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 745 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 746 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 747 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 748 | |
| 749 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 750 | |
| 751 | /* Dummy readl to force pci flush */ |
| 752 | readl(®s->outbound_intr_mask); |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * megasas_disable_intr_skinny - Disables interrupt |
| 757 | * @regs: MFI register set |
| 758 | */ |
| 759 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 760 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 761 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 762 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 763 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 764 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 765 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 766 | writel(mask, ®s->outbound_intr_mask); |
| 767 | /* Dummy readl to force pci flush */ |
| 768 | readl(®s->outbound_intr_mask); |
| 769 | } |
| 770 | |
| 771 | /** |
| 772 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 773 | * @regs: MFI register set |
| 774 | */ |
| 775 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 776 | megasas_read_fw_status_reg_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 777 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 778 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /** |
| 782 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 783 | * @regs: MFI register set |
| 784 | */ |
| 785 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 786 | megasas_clear_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 787 | { |
| 788 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 789 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 790 | struct megasas_register_set __iomem *regs; |
| 791 | regs = instance->reg_set; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 792 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 793 | /* |
| 794 | * Check if it is our interrupt |
| 795 | */ |
| 796 | status = readl(®s->outbound_intr_status); |
| 797 | |
| 798 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 799 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 803 | * Check if it is our interrupt |
| 804 | */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 805 | if ((megasas_read_fw_status_reg_skinny(instance) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 806 | MFI_STATE_FAULT) { |
| 807 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 808 | } else |
| 809 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 810 | |
| 811 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 812 | * Clear the interrupt by writing back the same value |
| 813 | */ |
| 814 | writel(status, ®s->outbound_intr_status); |
| 815 | |
| 816 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 817 | * dummy read to flush PCI |
| 818 | */ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 819 | readl(®s->outbound_intr_status); |
| 820 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 821 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /** |
| 825 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 826 | * @frame_phys_addr : Physical address of cmd |
| 827 | * @frame_count : Number of frames for the command |
| 828 | * @regs : MFI register set |
| 829 | */ |
| 830 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 831 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 832 | dma_addr_t frame_phys_addr, |
| 833 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 834 | struct megasas_register_set __iomem *regs) |
| 835 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 836 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 837 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 838 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 839 | writel(upper_32_bits(frame_phys_addr), |
| 840 | &(regs)->inbound_high_queue_port); |
| 841 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 842 | &(regs)->inbound_low_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 843 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 844 | } |
| 845 | |
| 846 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 847 | * megasas_check_reset_skinny - For controller reset check |
| 848 | * @regs: MFI register set |
| 849 | */ |
| 850 | static int |
| 851 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 852 | struct megasas_register_set __iomem *regs) |
| 853 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 854 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 855 | return 1; |
| 856 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 857 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 861 | |
| 862 | .fire_cmd = megasas_fire_cmd_skinny, |
| 863 | .enable_intr = megasas_enable_intr_skinny, |
| 864 | .disable_intr = megasas_disable_intr_skinny, |
| 865 | .clear_intr = megasas_clear_intr_skinny, |
| 866 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 867 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 868 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 869 | .service_isr = megasas_isr, |
| 870 | .tasklet = megasas_complete_cmd_dpc, |
| 871 | .init_adapter = megasas_init_adapter_mfi, |
| 872 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 873 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 874 | }; |
| 875 | |
| 876 | |
| 877 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 878 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 879 | * controllers |
| 880 | */ |
| 881 | |
| 882 | /** |
| 883 | * megasas_enable_intr_gen2 - Enables interrupts |
| 884 | * @regs: MFI register set |
| 885 | */ |
| 886 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 887 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 888 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 889 | struct megasas_register_set __iomem *regs; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 890 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 891 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 892 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 893 | |
| 894 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 895 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 896 | |
| 897 | /* Dummy readl to force pci flush */ |
| 898 | readl(®s->outbound_intr_mask); |
| 899 | } |
| 900 | |
| 901 | /** |
| 902 | * megasas_disable_intr_gen2 - Disables interrupt |
| 903 | * @regs: MFI register set |
| 904 | */ |
| 905 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 906 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 907 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 908 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 909 | u32 mask = 0xFFFFFFFF; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 910 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 911 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 912 | writel(mask, ®s->outbound_intr_mask); |
| 913 | /* Dummy readl to force pci flush */ |
| 914 | readl(®s->outbound_intr_mask); |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 919 | * @regs: MFI register set |
| 920 | */ |
| 921 | static u32 |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 922 | megasas_read_fw_status_reg_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 923 | { |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 924 | return readl(&instance->reg_set->outbound_scratch_pad_0); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /** |
| 928 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 929 | * @regs: MFI register set |
| 930 | */ |
| 931 | static int |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 932 | megasas_clear_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 933 | { |
| 934 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 935 | u32 mfiStatus = 0; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 936 | struct megasas_register_set __iomem *regs; |
| 937 | regs = instance->reg_set; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 938 | |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 939 | /* |
| 940 | * Check if it is our interrupt |
| 941 | */ |
| 942 | status = readl(®s->outbound_intr_status); |
| 943 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 944 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 945 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 946 | } |
| 947 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 948 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 949 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 950 | |
| 951 | /* |
| 952 | * Clear the interrupt by writing back the same value |
| 953 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 954 | if (mfiStatus) |
| 955 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 956 | |
| 957 | /* Dummy readl to force pci flush */ |
| 958 | readl(®s->outbound_intr_status); |
| 959 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 960 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 961 | } |
| 962 | /** |
| 963 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 964 | * @frame_phys_addr : Physical address of cmd |
| 965 | * @frame_count : Number of frames for the command |
| 966 | * @regs : MFI register set |
| 967 | */ |
| 968 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 969 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 970 | dma_addr_t frame_phys_addr, |
| 971 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 972 | struct megasas_register_set __iomem *regs) |
| 973 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 974 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 975 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 976 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 977 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 978 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 979 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * megasas_adp_reset_gen2 - For controller reset |
| 984 | * @regs: MFI register set |
| 985 | */ |
| 986 | static int |
| 987 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 988 | struct megasas_register_set __iomem *reg_set) |
| 989 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 990 | u32 retry = 0 ; |
| 991 | u32 HostDiag; |
| 992 | u32 __iomem *seq_offset = ®_set->seq_offset; |
| 993 | u32 __iomem *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 994 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 995 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 996 | seq_offset = ®_set->fusion_seq_offset; |
| 997 | hostdiag_offset = ®_set->fusion_host_diag; |
| 998 | } |
| 999 | |
| 1000 | writel(0, seq_offset); |
| 1001 | writel(4, seq_offset); |
| 1002 | writel(0xb, seq_offset); |
| 1003 | writel(2, seq_offset); |
| 1004 | writel(7, seq_offset); |
| 1005 | writel(0xd, seq_offset); |
| 1006 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1007 | msleep(1000); |
| 1008 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1009 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1010 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1011 | while (!(HostDiag & DIAG_WRITE_ENABLE)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1012 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1013 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1014 | dev_notice(&instance->pdev->dev, "RESETGEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1015 | retry, HostDiag); |
| 1016 | |
| 1017 | if (retry++ >= 100) |
| 1018 | return 1; |
| 1019 | |
| 1020 | } |
| 1021 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1022 | dev_notice(&instance->pdev->dev, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1023 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1024 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1025 | |
| 1026 | ssleep(10); |
| 1027 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1028 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1029 | while (HostDiag & DIAG_RESET_ADAPTER) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1030 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 1031 | HostDiag = (u32)readl(hostdiag_offset); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1032 | dev_notice(&instance->pdev->dev, "RESET_GEN2: retry=%x, hostdiag=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1033 | retry, HostDiag); |
| 1034 | |
| 1035 | if (retry++ >= 1000) |
| 1036 | return 1; |
| 1037 | |
| 1038 | } |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | /** |
| 1043 | * megasas_check_reset_gen2 - For controller reset check |
| 1044 | * @regs: MFI register set |
| 1045 | */ |
| 1046 | static int |
| 1047 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 1048 | struct megasas_register_set __iomem *regs) |
| 1049 | { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1050 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1051 | return 1; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1052 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1053 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 1057 | |
| 1058 | .fire_cmd = megasas_fire_cmd_gen2, |
| 1059 | .enable_intr = megasas_enable_intr_gen2, |
| 1060 | .disable_intr = megasas_disable_intr_gen2, |
| 1061 | .clear_intr = megasas_clear_intr_gen2, |
| 1062 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1063 | .adp_reset = megasas_adp_reset_gen2, |
| 1064 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1065 | .service_isr = megasas_isr, |
| 1066 | .tasklet = megasas_complete_cmd_dpc, |
| 1067 | .init_adapter = megasas_init_adapter_mfi, |
| 1068 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 1069 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 1070 | }; |
| 1071 | |
| 1072 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1073 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1074 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1075 | */ |
| 1076 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1077 | /* |
| 1078 | * Template added for TB (Fusion) |
| 1079 | */ |
| 1080 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 1081 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 1082 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1083 | * megasas_issue_polled - Issues a polling command |
| 1084 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1085 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1086 | * |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1087 | * 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] | 1088 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1089 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1090 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 1091 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1092 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 1093 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1094 | frame_hdr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1095 | 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] | 1096 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1097 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1098 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1099 | __func__, __LINE__); |
| 1100 | return DCMD_NOT_FIRED; |
| 1101 | } |
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 | instance->instancet->issue_dcmd(instance, cmd); |
| 1104 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1105 | return wait_and_poll(instance, cmd, instance->requestorId ? |
| 1106 | MEGASAS_ROUTINE_WAIT_TIME_VF : MFI_IO_TIMEOUT_SECS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 1111 | * @instance: Adapter soft state |
| 1112 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1113 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1114 | * |
| 1115 | * 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] | 1116 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1117 | * Used to issue ioctl commands. |
| 1118 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1119 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1120 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1121 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1122 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1123 | int ret = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1124 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1125 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1126 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1127 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1128 | __func__, __LINE__); |
| 1129 | return DCMD_NOT_FIRED; |
| 1130 | } |
| 1131 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1132 | instance->instancet->issue_dcmd(instance, cmd); |
| 1133 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1134 | if (timeout) { |
| 1135 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1136 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1137 | if (!ret) { |
Shivasharan S | 2ce4350 | 2019-05-07 10:05:38 -0700 | [diff] [blame] | 1138 | dev_err(&instance->pdev->dev, |
| 1139 | "DCMD(opcode: 0x%x) is timed out, func:%s\n", |
| 1140 | cmd->frame->dcmd.opcode, __func__); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1141 | return DCMD_TIMEOUT; |
| 1142 | } |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1143 | } else |
| 1144 | wait_event(instance->int_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1145 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1146 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1147 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1148 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 1153 | * @instance: Adapter soft state |
| 1154 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1155 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1156 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1157 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1158 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 1159 | * cmd and waits for return status. |
| 1160 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1161 | */ |
| 1162 | static int |
| 1163 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1164 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1165 | { |
| 1166 | struct megasas_cmd *cmd; |
| 1167 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1168 | int ret = 0; |
Shivasharan S | 2ce4350 | 2019-05-07 10:05:38 -0700 | [diff] [blame] | 1169 | u32 opcode; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1170 | |
| 1171 | cmd = megasas_get_cmd(instance); |
| 1172 | |
| 1173 | if (!cmd) |
| 1174 | return -1; |
| 1175 | |
| 1176 | abort_fr = &cmd->frame->abort; |
| 1177 | |
| 1178 | /* |
| 1179 | * Prepare and issue the abort frame |
| 1180 | */ |
| 1181 | abort_fr->cmd = MFI_CMD_ABORT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1182 | abort_fr->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1183 | abort_fr->flags = cpu_to_le16(0); |
| 1184 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1185 | abort_fr->abort_mfi_phys_addr_lo = |
| 1186 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1187 | abort_fr->abort_mfi_phys_addr_hi = |
| 1188 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1189 | |
| 1190 | cmd->sync_cmd = 1; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1191 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1192 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1193 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1194 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 1195 | __func__, __LINE__); |
| 1196 | return DCMD_NOT_FIRED; |
| 1197 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1198 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1199 | instance->instancet->issue_dcmd(instance, cmd); |
| 1200 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1201 | if (timeout) { |
| 1202 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1203 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS, timeout * HZ); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1204 | if (!ret) { |
Shivasharan S | 2ce4350 | 2019-05-07 10:05:38 -0700 | [diff] [blame] | 1205 | opcode = cmd_to_abort->frame->dcmd.opcode; |
| 1206 | dev_err(&instance->pdev->dev, |
| 1207 | "Abort(to be aborted DCMD opcode: 0x%x) is timed out func:%s\n", |
| 1208 | opcode, __func__); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1209 | return DCMD_TIMEOUT; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1210 | } |
| 1211 | } else |
| 1212 | wait_event(instance->abort_cmd_wait_q, |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 1213 | cmd->cmd_status_drv != MFI_STAT_INVALID_STATUS); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1214 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1215 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1216 | |
| 1217 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1218 | return (cmd->cmd_status_drv == MFI_STAT_OK) ? |
| 1219 | DCMD_SUCCESS : DCMD_FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1224 | * @instance: Adapter soft state |
| 1225 | * @scp: SCSI command from the mid-layer |
| 1226 | * @mfi_sgl: SGL to be filled in |
| 1227 | * |
| 1228 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1229 | * it returnes -1. |
| 1230 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1231 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1232 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1233 | union megasas_sgl *mfi_sgl) |
| 1234 | { |
| 1235 | int i; |
| 1236 | int sge_count; |
| 1237 | struct scatterlist *os_sgl; |
| 1238 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1239 | sge_count = scsi_dma_map(scp); |
| 1240 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1241 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1242 | if (sge_count) { |
| 1243 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1244 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1245 | 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] | 1246 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1247 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1248 | return sge_count; |
| 1249 | } |
| 1250 | |
| 1251 | /** |
| 1252 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1253 | * @instance: Adapter soft state |
| 1254 | * @scp: SCSI command from the mid-layer |
| 1255 | * @mfi_sgl: SGL to be filled in |
| 1256 | * |
| 1257 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1258 | * it returnes -1. |
| 1259 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1260 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1261 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1262 | union megasas_sgl *mfi_sgl) |
| 1263 | { |
| 1264 | int i; |
| 1265 | int sge_count; |
| 1266 | struct scatterlist *os_sgl; |
| 1267 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1268 | sge_count = scsi_dma_map(scp); |
| 1269 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1270 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1271 | if (sge_count) { |
| 1272 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1273 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1274 | 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] | 1275 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1276 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1277 | return sge_count; |
| 1278 | } |
| 1279 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1280 | /** |
| 1281 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1282 | * @instance: Adapter soft state |
| 1283 | * @scp: SCSI command from the mid-layer |
| 1284 | * @mfi_sgl: SGL to be filled in |
| 1285 | * |
| 1286 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1287 | * it returnes -1. |
| 1288 | */ |
| 1289 | static int |
| 1290 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1291 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1292 | { |
| 1293 | int i; |
| 1294 | int sge_count; |
| 1295 | struct scatterlist *os_sgl; |
| 1296 | |
| 1297 | sge_count = scsi_dma_map(scp); |
| 1298 | |
| 1299 | if (sge_count) { |
| 1300 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1301 | mfi_sgl->sge_skinny[i].length = |
| 1302 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1303 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1304 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1305 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | return sge_count; |
| 1309 | } |
| 1310 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1311 | /** |
| 1312 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1313 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1314 | * @sge_count : number of sg elements |
| 1315 | * |
| 1316 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1317 | */ |
| 1318 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1319 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1320 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1321 | { |
| 1322 | int num_cnt; |
| 1323 | int sge_bytes; |
| 1324 | u32 sge_sz; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1325 | u32 frame_count = 0; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1326 | |
| 1327 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1328 | sizeof(struct megasas_sge32); |
| 1329 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1330 | if (instance->flag_ieee) { |
| 1331 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1332 | } |
| 1333 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1334 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1335 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1336 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1337 | * 1 SGEs for 64-bit SGLs and |
| 1338 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1339 | */ |
| 1340 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1341 | if (instance->flag_ieee == 1) { |
| 1342 | num_cnt = sge_count - 1; |
| 1343 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1344 | num_cnt = sge_count - 1; |
| 1345 | else |
| 1346 | num_cnt = sge_count - 2; |
| 1347 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1348 | if (instance->flag_ieee == 1) { |
| 1349 | num_cnt = sge_count - 1; |
| 1350 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1351 | num_cnt = sge_count - 2; |
| 1352 | else |
| 1353 | num_cnt = sge_count - 3; |
| 1354 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1355 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1356 | if (num_cnt > 0) { |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1357 | sge_bytes = sge_sz * num_cnt; |
| 1358 | |
| 1359 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1360 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1361 | } |
| 1362 | /* Main frame */ |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1363 | frame_count += 1; |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1364 | |
| 1365 | if (frame_count > 7) |
| 1366 | frame_count = 8; |
| 1367 | return frame_count; |
| 1368 | } |
| 1369 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1370 | /** |
| 1371 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1372 | * @instance: Adapter soft state |
| 1373 | * @scp: SCSI command |
| 1374 | * @cmd: Command to be prepared in |
| 1375 | * |
| 1376 | * This function prepares CDB commands. These are typcially pass-through |
| 1377 | * commands to the devices. |
| 1378 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1379 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1380 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1381 | struct megasas_cmd *cmd) |
| 1382 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1383 | u32 is_logical; |
| 1384 | u32 device_id; |
| 1385 | u16 flags = 0; |
| 1386 | struct megasas_pthru_frame *pthru; |
| 1387 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1388 | is_logical = MEGASAS_IS_LOGICAL(scp->device); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1389 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1390 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1391 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1392 | if (scp->sc_data_direction == DMA_TO_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1393 | flags = MFI_FRAME_DIR_WRITE; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1394 | else if (scp->sc_data_direction == DMA_FROM_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1395 | flags = MFI_FRAME_DIR_READ; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1396 | else if (scp->sc_data_direction == DMA_NONE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1397 | flags = MFI_FRAME_DIR_NONE; |
| 1398 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1399 | if (instance->flag_ieee == 1) { |
| 1400 | flags |= MFI_FRAME_IEEE; |
| 1401 | } |
| 1402 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1403 | /* |
| 1404 | * Prepare the DCDB frame |
| 1405 | */ |
| 1406 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1407 | pthru->cmd_status = 0x0; |
| 1408 | pthru->scsi_status = 0x0; |
| 1409 | pthru->target_id = device_id; |
| 1410 | pthru->lun = scp->device->lun; |
| 1411 | pthru->cdb_len = scp->cmd_len; |
| 1412 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1413 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1414 | pthru->flags = cpu_to_le16(flags); |
| 1415 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1416 | |
| 1417 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1418 | |
| 1419 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1420 | * If the command is for the tape device, set the |
| 1421 | * pthru timeout to the os layer timeout value. |
| 1422 | */ |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1423 | if (scp->device->type == TYPE_TAPE) { |
| 1424 | if ((scp->request->timeout / HZ) > 0xFFFF) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 1425 | pthru->timeout = cpu_to_le16(0xFFFF); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1426 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1427 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1431 | * Construct SGL |
| 1432 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1433 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1434 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1435 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1436 | &pthru->sgl); |
| 1437 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1438 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1439 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1440 | &pthru->sgl); |
| 1441 | } else |
| 1442 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1443 | &pthru->sgl); |
| 1444 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1445 | if (pthru->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1446 | dev_err(&instance->pdev->dev, "DCDB too many SGE NUM=%x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1447 | pthru->sge_count); |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1451 | /* |
| 1452 | * Sense info specific |
| 1453 | */ |
| 1454 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1455 | pthru->sense_buf_phys_addr_hi = |
| 1456 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1457 | pthru->sense_buf_phys_addr_lo = |
| 1458 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1459 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1460 | /* |
| 1461 | * Compute the total number of frames this command consumes. FW uses |
| 1462 | * this number to pull sufficient number of frames from host memory. |
| 1463 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1464 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1465 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1466 | |
| 1467 | return cmd->frame_count; |
| 1468 | } |
| 1469 | |
| 1470 | /** |
| 1471 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1472 | * @instance: Adapter soft state |
| 1473 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1474 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1475 | * |
| 1476 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1477 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1478 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1479 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1480 | struct megasas_cmd *cmd) |
| 1481 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1482 | u32 device_id; |
| 1483 | u8 sc = scp->cmnd[0]; |
| 1484 | u16 flags = 0; |
| 1485 | struct megasas_io_frame *ldio; |
| 1486 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1487 | device_id = MEGASAS_DEV_INDEX(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1488 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1489 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1490 | if (scp->sc_data_direction == DMA_TO_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1491 | flags = MFI_FRAME_DIR_WRITE; |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 1492 | else if (scp->sc_data_direction == DMA_FROM_DEVICE) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1493 | flags = MFI_FRAME_DIR_READ; |
| 1494 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1495 | if (instance->flag_ieee == 1) { |
| 1496 | flags |= MFI_FRAME_IEEE; |
| 1497 | } |
| 1498 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1499 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1500 | * 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] | 1501 | */ |
| 1502 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1503 | ldio->cmd_status = 0x0; |
| 1504 | ldio->scsi_status = 0x0; |
| 1505 | ldio->target_id = device_id; |
| 1506 | ldio->timeout = 0; |
| 1507 | ldio->reserved_0 = 0; |
| 1508 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1509 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1510 | ldio->start_lba_hi = 0; |
| 1511 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1512 | |
| 1513 | /* |
| 1514 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1515 | */ |
| 1516 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1517 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1518 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1519 | ((u32) scp->cmnd[2] << 8) | |
| 1520 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1521 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1522 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | /* |
| 1526 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1527 | */ |
| 1528 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1529 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1530 | ((u32) scp->cmnd[7] << 8)); |
| 1531 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1532 | ((u32) scp->cmnd[3] << 16) | |
| 1533 | ((u32) scp->cmnd[4] << 8) | |
| 1534 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /* |
| 1538 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1539 | */ |
| 1540 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1541 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1542 | ((u32) scp->cmnd[7] << 16) | |
| 1543 | ((u32) scp->cmnd[8] << 8) | |
| 1544 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1545 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1546 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1547 | ((u32) scp->cmnd[3] << 16) | |
| 1548 | ((u32) scp->cmnd[4] << 8) | |
| 1549 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /* |
| 1553 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1554 | */ |
| 1555 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1556 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1557 | ((u32) scp->cmnd[11] << 16) | |
| 1558 | ((u32) scp->cmnd[12] << 8) | |
| 1559 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1560 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1561 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1562 | ((u32) scp->cmnd[7] << 16) | |
| 1563 | ((u32) scp->cmnd[8] << 8) | |
| 1564 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1565 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1566 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1567 | ((u32) scp->cmnd[3] << 16) | |
| 1568 | ((u32) scp->cmnd[4] << 8) | |
| 1569 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1570 | |
| 1571 | } |
| 1572 | |
| 1573 | /* |
| 1574 | * Construct SGL |
| 1575 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1576 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1577 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1578 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1579 | &ldio->sgl); |
| 1580 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1581 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1582 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1583 | } else |
| 1584 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1585 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1586 | if (ldio->sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1587 | dev_err(&instance->pdev->dev, "build_ld_io: sge_count = %x\n", |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1588 | ldio->sge_count); |
| 1589 | return 0; |
| 1590 | } |
| 1591 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1592 | /* |
| 1593 | * Sense info specific |
| 1594 | */ |
| 1595 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1596 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1597 | 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] | 1598 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1599 | /* |
| 1600 | * Compute the total number of frames this command consumes. FW uses |
| 1601 | * this number to pull sufficient number of frames from host memory. |
| 1602 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1603 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1604 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1605 | |
| 1606 | return cmd->frame_count; |
| 1607 | } |
| 1608 | |
| 1609 | /** |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1610 | * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD |
| 1611 | * and whether it's RW or non RW |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1612 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1613 | * |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1614 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1615 | inline int megasas_cmd_type(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1616 | { |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1617 | int ret; |
| 1618 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1619 | switch (cmd->cmnd[0]) { |
| 1620 | case READ_10: |
| 1621 | case WRITE_10: |
| 1622 | case READ_12: |
| 1623 | case WRITE_12: |
| 1624 | case READ_6: |
| 1625 | case WRITE_6: |
| 1626 | case READ_16: |
| 1627 | case WRITE_16: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1628 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1629 | READ_WRITE_LDIO : READ_WRITE_SYSPDIO; |
| 1630 | break; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1631 | default: |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1632 | ret = (MEGASAS_IS_LOGICAL(cmd->device)) ? |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1633 | NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1634 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1635 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1636 | } |
| 1637 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1638 | /** |
| 1639 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1640 | * in FW |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1641 | * @instance: Adapter soft state |
| 1642 | */ |
| 1643 | static inline void |
| 1644 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1645 | { |
| 1646 | struct megasas_cmd *cmd; |
| 1647 | int i,n; |
| 1648 | union megasas_sgl *mfi_sgl; |
| 1649 | struct megasas_io_frame *ldio; |
| 1650 | struct megasas_pthru_frame *pthru; |
| 1651 | u32 sgcount; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 1652 | u16 max_cmd = instance->max_fw_cmds; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1653 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1654 | dev_err(&instance->pdev->dev, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1655 | 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] | 1656 | if (IS_DMA64) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1657 | 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] | 1658 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1659 | 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] | 1660 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1661 | 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] | 1662 | for (i = 0; i < max_cmd; i++) { |
| 1663 | cmd = instance->cmd_list[i]; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1664 | if (!cmd->scmd) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1665 | continue; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1666 | 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] | 1667 | if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1668 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1669 | mfi_sgl = &ldio->sgl; |
| 1670 | sgcount = ldio->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1671 | 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] | 1672 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1673 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1674 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1675 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1676 | } else { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1677 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1678 | mfi_sgl = &pthru->sgl; |
| 1679 | sgcount = pthru->sge_count; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1680 | 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] | 1681 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1682 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1683 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1684 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1685 | } |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1686 | if (megasas_dbg_lvl & MEGASAS_DBG_LVL) { |
| 1687 | for (n = 0; n < sgcount; n++) { |
| 1688 | if (IS_DMA64) |
| 1689 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%llx\n", |
| 1690 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1691 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
| 1692 | else |
| 1693 | dev_err(&instance->pdev->dev, "sgl len : 0x%x, sgl addr : 0x%x\n", |
| 1694 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1695 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1696 | } |
| 1697 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1698 | } /*for max_cmd*/ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1699 | 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] | 1700 | for (i = 0; i < max_cmd; i++) { |
| 1701 | |
| 1702 | cmd = instance->cmd_list[i]; |
| 1703 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 1704 | if (cmd->sync_cmd == 1) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1705 | 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] | 1706 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1707 | 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] | 1708 | } |
| 1709 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1710 | u32 |
| 1711 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1712 | struct scsi_cmnd *scmd) |
| 1713 | { |
| 1714 | struct megasas_cmd *cmd; |
| 1715 | u32 frame_count; |
| 1716 | |
| 1717 | cmd = megasas_get_cmd(instance); |
| 1718 | if (!cmd) |
| 1719 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1720 | |
| 1721 | /* |
| 1722 | * Logical drive command |
| 1723 | */ |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 1724 | if (megasas_cmd_type(scmd) == READ_WRITE_LDIO) |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1725 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1726 | else |
| 1727 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1728 | |
| 1729 | if (!frame_count) |
| 1730 | goto out_return_cmd; |
| 1731 | |
| 1732 | cmd->scmd = scmd; |
| 1733 | scmd->SCp.ptr = (char *)cmd; |
| 1734 | |
| 1735 | /* |
| 1736 | * Issue the command to the FW |
| 1737 | */ |
| 1738 | atomic_inc(&instance->fw_outstanding); |
| 1739 | |
| 1740 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1741 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1742 | |
| 1743 | return 0; |
| 1744 | out_return_cmd: |
| 1745 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1746 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1750 | /** |
| 1751 | * megasas_queue_command - Queue entry point |
| 1752 | * @scmd: SCSI command to be queued |
| 1753 | * @done: Callback entry point |
| 1754 | */ |
| 1755 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1756 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1757 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1758 | struct megasas_instance *instance; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1759 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1760 | |
| 1761 | instance = (struct megasas_instance *) |
| 1762 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1763 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 1764 | if (instance->unload == 1) { |
| 1765 | scmd->result = DID_NO_CONNECT << 16; |
| 1766 | scmd->scsi_done(scmd); |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1770 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1771 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1772 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1773 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1774 | /* Check for an mpio path and adjust behavior */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1775 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1776 | if (megasas_check_mpio_paths(instance, scmd) == |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 1777 | (DID_REQUEUE << 16)) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1778 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1779 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1780 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1781 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1782 | return 0; |
| 1783 | } |
| 1784 | } |
| 1785 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1786 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1787 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1788 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1789 | return 0; |
| 1790 | } |
| 1791 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1792 | mr_device_priv_data = scmd->device->hostdata; |
| 1793 | if (!mr_device_priv_data) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1794 | scmd->result = DID_NO_CONNECT << 16; |
| 1795 | scmd->scsi_done(scmd); |
| 1796 | return 0; |
| 1797 | } |
| 1798 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1799 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1800 | return SCSI_MLQUEUE_HOST_BUSY; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1801 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 1802 | if (mr_device_priv_data->tm_busy) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1803 | return SCSI_MLQUEUE_DEVICE_BUSY; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1804 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1805 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1806 | scmd->result = 0; |
| 1807 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1808 | if (MEGASAS_IS_LOGICAL(scmd->device) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1809 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1810 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1811 | scmd->result = DID_BAD_TARGET << 16; |
| 1812 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1813 | } |
| 1814 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 1815 | if ((scmd->cmnd[0] == SYNCHRONIZE_CACHE) && |
| 1816 | MEGASAS_IS_LOGICAL(scmd->device) && |
| 1817 | (!instance->fw_sync_cache_support)) { |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1818 | scmd->result = DID_OK << 16; |
| 1819 | goto out_done; |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1820 | } |
| 1821 | |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 1822 | return instance->instancet->build_and_issue_cmd(instance, scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1823 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1824 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1825 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1826 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1827 | } |
| 1828 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1829 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1830 | { |
| 1831 | int i; |
| 1832 | |
| 1833 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1834 | |
| 1835 | if ((megasas_mgmt_info.instance[i]) && |
| 1836 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1837 | return megasas_mgmt_info.instance[i]; |
| 1838 | } |
| 1839 | |
| 1840 | return NULL; |
| 1841 | } |
| 1842 | |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1843 | /* |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1844 | * megasas_set_dynamic_target_properties - |
| 1845 | * Device property set by driver may not be static and it is required to be |
| 1846 | * updated after OCR |
| 1847 | * |
| 1848 | * set tm_capable. |
| 1849 | * set dma alignment (only for eedp protection enable vd). |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1850 | * |
| 1851 | * @sdev: OS provided scsi device |
| 1852 | * |
| 1853 | * Returns void |
| 1854 | */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 1855 | void megasas_set_dynamic_target_properties(struct scsi_device *sdev, |
| 1856 | bool is_target_prop) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1857 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1858 | u16 pd_index = 0, ld; |
| 1859 | u32 device_id; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1860 | struct megasas_instance *instance; |
| 1861 | struct fusion_context *fusion; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1862 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 1863 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1864 | struct MR_LD_RAID *raid; |
| 1865 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1866 | |
| 1867 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1868 | fusion = instance->ctrl_context; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1869 | mr_device_priv_data = sdev->hostdata; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1870 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1871 | if (!fusion || !mr_device_priv_data) |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1872 | return; |
| 1873 | |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1874 | if (MEGASAS_IS_LOGICAL(sdev)) { |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1875 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1876 | + sdev->id; |
| 1877 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1878 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1879 | if (ld >= instance->fw_supported_vd_count) |
| 1880 | return; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1881 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1882 | |
| 1883 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1884 | blk_queue_update_dma_alignment(sdev->request_queue, 0x7); |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1885 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 1886 | mr_device_priv_data->is_tm_capable = |
| 1887 | raid->capability.tmCapable; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1888 | } else if (instance->use_seqnum_jbod_fp) { |
| 1889 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1890 | sdev->id; |
Shivasharan S | ed981b8 | 2017-02-10 00:59:06 -0800 | [diff] [blame] | 1891 | pd_sync = (void *)fusion->pd_seq_sync |
| 1892 | [(instance->pd_seq_map_id - 1) & 1]; |
| 1893 | mr_device_priv_data->is_tm_capable = |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1894 | pd_sync->seq[pd_index].capability.tmCapable; |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1895 | } |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 1896 | |
| 1897 | if (is_target_prop && instance->tgt_prop->reset_tmo) { |
| 1898 | /* |
| 1899 | * If FW provides a target reset timeout value, driver will use |
| 1900 | * it. If not set, fallback to default values. |
| 1901 | */ |
| 1902 | mr_device_priv_data->target_reset_tmo = |
| 1903 | min_t(u8, instance->max_reset_tmo, |
| 1904 | instance->tgt_prop->reset_tmo); |
| 1905 | mr_device_priv_data->task_abort_tmo = instance->task_abort_tmo; |
| 1906 | } else { |
| 1907 | mr_device_priv_data->target_reset_tmo = |
| 1908 | MEGASAS_DEFAULT_TM_TIMEOUT; |
| 1909 | mr_device_priv_data->task_abort_tmo = |
| 1910 | MEGASAS_DEFAULT_TM_TIMEOUT; |
| 1911 | } |
sumit.saxena@avagotech.com | 0b48d12 | 2015-10-15 13:40:44 +0530 | [diff] [blame] | 1912 | } |
| 1913 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1914 | /* |
| 1915 | * megasas_set_nvme_device_properties - |
| 1916 | * set nomerges=2 |
| 1917 | * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K). |
| 1918 | * set maximum io transfer = MDTS of NVME device provided by MR firmware. |
| 1919 | * |
| 1920 | * MR firmware provides value in KB. Caller of this function converts |
| 1921 | * kb into bytes. |
| 1922 | * |
| 1923 | * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size, |
| 1924 | * MR firmware provides value 128 as (32 * 4K) = 128K. |
| 1925 | * |
| 1926 | * @sdev: scsi device |
| 1927 | * @max_io_size: maximum io transfer size |
| 1928 | * |
| 1929 | */ |
| 1930 | static inline void |
| 1931 | 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] | 1932 | { |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1933 | struct megasas_instance *instance; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1934 | u32 mr_nvme_pg_size; |
| 1935 | |
| 1936 | instance = (struct megasas_instance *)sdev->host->hostdata; |
| 1937 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1938 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1939 | |
| 1940 | blk_queue_max_hw_sectors(sdev->request_queue, (max_io_size / 512)); |
| 1941 | |
Bart Van Assche | 8b904b5 | 2018-03-07 17:10:10 -0800 | [diff] [blame] | 1942 | blk_queue_flag_set(QUEUE_FLAG_NOMERGES, sdev->request_queue); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1943 | blk_queue_virt_boundary(sdev->request_queue, mr_nvme_pg_size - 1); |
| 1944 | } |
| 1945 | |
| 1946 | |
| 1947 | /* |
| 1948 | * megasas_set_static_target_properties - |
| 1949 | * Device property set by driver are static and it is not required to be |
| 1950 | * updated after OCR. |
| 1951 | * |
| 1952 | * set io timeout |
| 1953 | * set device queue depth |
| 1954 | * set nvme device properties. see - megasas_set_nvme_device_properties |
| 1955 | * |
| 1956 | * @sdev: scsi device |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1957 | * @is_target_prop true, if fw provided target properties. |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1958 | */ |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1959 | static void megasas_set_static_target_properties(struct scsi_device *sdev, |
| 1960 | bool is_target_prop) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1961 | { |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1962 | u8 interface_type; |
| 1963 | u32 device_qd = MEGASAS_DEFAULT_CMD_PER_LUN; |
| 1964 | u32 max_io_size_kb = MR_DEFAULT_NVME_MDTS_KB; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1965 | u32 tgt_device_qd; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1966 | struct megasas_instance *instance; |
| 1967 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1968 | |
| 1969 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1970 | mr_device_priv_data = sdev->hostdata; |
| 1971 | interface_type = mr_device_priv_data->interface_type; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1972 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1973 | /* |
| 1974 | * The RAID firmware may require extended timeouts. |
| 1975 | */ |
| 1976 | blk_queue_rq_timeout(sdev->request_queue, scmd_timeout * HZ); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1977 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1978 | switch (interface_type) { |
| 1979 | case SAS_PD: |
| 1980 | device_qd = MEGASAS_SAS_QD; |
| 1981 | break; |
| 1982 | case SATA_PD: |
| 1983 | device_qd = MEGASAS_SATA_QD; |
| 1984 | break; |
| 1985 | case NVME_PD: |
| 1986 | device_qd = MEGASAS_NVME_QD; |
| 1987 | break; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 1988 | } |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 1989 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 1990 | if (is_target_prop) { |
| 1991 | tgt_device_qd = le32_to_cpu(instance->tgt_prop->device_qdepth); |
| 1992 | if (tgt_device_qd && |
| 1993 | (tgt_device_qd <= instance->host->can_queue)) |
| 1994 | device_qd = tgt_device_qd; |
| 1995 | |
| 1996 | /* max_io_size_kb will be set to non zero for |
| 1997 | * nvme based vd and syspd. |
| 1998 | */ |
| 1999 | max_io_size_kb = le32_to_cpu(instance->tgt_prop->max_io_size_kb); |
| 2000 | } |
| 2001 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2002 | if (instance->nvme_page_size && max_io_size_kb) |
| 2003 | megasas_set_nvme_device_properties(sdev, (max_io_size_kb << 10)); |
| 2004 | |
| 2005 | scsi_change_queue_depth(sdev, device_qd); |
| 2006 | |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 2007 | } |
| 2008 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2009 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2010 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 2011 | { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 2012 | u16 pd_index = 0; |
| 2013 | struct megasas_instance *instance; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 2014 | int ret_target_prop = DCMD_FAILED; |
| 2015 | bool is_target_prop = false; |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 2016 | |
| 2017 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 2018 | if (instance->pd_list_not_supported) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 2019 | if (!MEGASAS_IS_LOGICAL(sdev) && sdev->type == TYPE_DISK) { |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 2020 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 2021 | sdev->id; |
| 2022 | if (instance->pd_list[pd_index].driveState != |
| 2023 | MR_PD_STATE_SYSTEM) |
| 2024 | return -ENXIO; |
| 2025 | } |
| 2026 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2027 | |
Shivasharan S | 149c575 | 2018-01-05 05:27:42 -0800 | [diff] [blame] | 2028 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2029 | /* Send DCMD to Firmware and cache the information */ |
| 2030 | if ((instance->pd_info) && !MEGASAS_IS_LOGICAL(sdev)) |
| 2031 | megasas_get_pd_info(instance, sdev); |
| 2032 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 2033 | /* Some ventura firmware may not have instance->nvme_page_size set. |
| 2034 | * Do not send MR_DCMD_DRV_GET_TARGET_PROP |
| 2035 | */ |
| 2036 | if ((instance->tgt_prop) && (instance->nvme_page_size)) |
| 2037 | ret_target_prop = megasas_get_target_prop(instance, sdev); |
| 2038 | |
| 2039 | is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false; |
| 2040 | megasas_set_static_target_properties(sdev, is_target_prop); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2041 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 2042 | /* This sdev property may change post OCR */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 2043 | megasas_set_dynamic_target_properties(sdev, is_target_prop); |
| 2044 | |
| 2045 | mutex_unlock(&instance->reset_mutex); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 2046 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2047 | return 0; |
| 2048 | } |
| 2049 | |
| 2050 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 2051 | { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2052 | u16 pd_index = 0; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2053 | struct megasas_instance *instance ; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2054 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2055 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2056 | instance = megasas_lookup_instance(sdev->host->host_no); |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 2057 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2058 | /* |
| 2059 | * Open the OS scan to the SYSTEM PD |
| 2060 | */ |
| 2061 | pd_index = |
| 2062 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 2063 | sdev->id; |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 2064 | if ((instance->pd_list_not_supported || |
| 2065 | instance->pd_list[pd_index].driveState == |
Sumit Saxena | aed335e | 2015-11-05 21:17:37 +0530 | [diff] [blame] | 2066 | MR_PD_STATE_SYSTEM)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2067 | goto scan_target; |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2068 | } |
| 2069 | return -ENXIO; |
| 2070 | } |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2071 | |
| 2072 | scan_target: |
| 2073 | mr_device_priv_data = kzalloc(sizeof(*mr_device_priv_data), |
| 2074 | GFP_KERNEL); |
| 2075 | if (!mr_device_priv_data) |
| 2076 | return -ENOMEM; |
| 2077 | sdev->hostdata = mr_device_priv_data; |
Shivasharan S | 49524b3 | 2017-03-10 03:22:13 -0800 | [diff] [blame] | 2078 | |
| 2079 | atomic_set(&mr_device_priv_data->r1_ldio_hint, |
| 2080 | instance->r1_ldio_hint_default); |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2081 | return 0; |
| 2082 | } |
| 2083 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2084 | static void megasas_slave_destroy(struct scsi_device *sdev) |
| 2085 | { |
| 2086 | kfree(sdev->hostdata); |
| 2087 | sdev->hostdata = NULL; |
| 2088 | } |
| 2089 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2090 | /* |
| 2091 | * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a |
| 2092 | * kill adapter |
| 2093 | * @instance: Adapter soft state |
| 2094 | * |
| 2095 | */ |
kbuild test robot | 6a6981f | 2015-04-23 16:33:23 +0530 | [diff] [blame] | 2096 | static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance) |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2097 | { |
| 2098 | int i; |
| 2099 | struct megasas_cmd *cmd_mfi; |
| 2100 | struct megasas_cmd_fusion *cmd_fusion; |
| 2101 | struct fusion_context *fusion = instance->ctrl_context; |
| 2102 | |
| 2103 | /* Find all outstanding ioctls */ |
| 2104 | if (fusion) { |
| 2105 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2106 | cmd_fusion = fusion->cmd_list[i]; |
| 2107 | if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) { |
| 2108 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 2109 | if (cmd_mfi->sync_cmd && |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2110 | (cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)) { |
| 2111 | cmd_mfi->frame->hdr.cmd_status = |
| 2112 | MFI_STAT_WRONG_STATE; |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2113 | megasas_complete_cmd(instance, |
| 2114 | cmd_mfi, DID_OK); |
Shivasharan S | eb3fe26 | 2017-08-23 04:47:04 -0700 | [diff] [blame] | 2115 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | } else { |
| 2119 | for (i = 0; i < instance->max_fw_cmds; i++) { |
| 2120 | cmd_mfi = instance->cmd_list[i]; |
| 2121 | if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd != |
| 2122 | MFI_CMD_ABORT) |
| 2123 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2129 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2130 | { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2131 | /* 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] | 2132 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2133 | /* Wait 1 second to ensure IO or ioctls in build have posted */ |
| 2134 | msleep(1000); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2135 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2136 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2137 | (instance->adapter_type != MFI_SERIES)) { |
Shivasharan S | 5acad9b | 2018-10-16 23:37:47 -0700 | [diff] [blame] | 2138 | if (!instance->requestorId) { |
| 2139 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
| 2140 | /* Flush */ |
| 2141 | readl(&instance->reg_set->doorbell); |
| 2142 | } |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 2143 | if (instance->requestorId && instance->peerIsPresent) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2144 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2145 | } else { |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2146 | writel(MFI_STOP_ADP, |
| 2147 | &instance->reg_set->inbound_doorbell); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2148 | } |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 2149 | /* Complete outstanding ioctls when adapter is killed */ |
| 2150 | megasas_complete_outstanding_ioctls(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | /** |
| 2154 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 2155 | * restored to max value |
| 2156 | * @instance: Adapter soft state |
| 2157 | * |
| 2158 | */ |
| 2159 | void |
| 2160 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 2161 | { |
| 2162 | unsigned long flags; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 2163 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2164 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2165 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 2166 | && atomic_read(&instance->fw_outstanding) < |
| 2167 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2168 | |
| 2169 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2170 | instance->flag &= ~MEGASAS_FW_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2171 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2172 | instance->host->can_queue = instance->cur_can_queue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2173 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2177 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2178 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 2179 | * @instance_addr: Address of adapter soft state |
| 2180 | * |
| 2181 | * Tasklet to complete cmds |
| 2182 | */ |
| 2183 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 2184 | { |
| 2185 | u32 producer; |
| 2186 | u32 consumer; |
| 2187 | u32 context; |
| 2188 | struct megasas_cmd *cmd; |
| 2189 | struct megasas_instance *instance = |
| 2190 | (struct megasas_instance *)instance_addr; |
| 2191 | unsigned long flags; |
| 2192 | |
| 2193 | /* If we have already declared adapter dead, donot complete cmds */ |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2194 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2195 | return; |
| 2196 | |
| 2197 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 2198 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2199 | producer = le32_to_cpu(*instance->producer); |
| 2200 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2201 | |
| 2202 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2203 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2204 | if (context >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2205 | dev_err(&instance->pdev->dev, "Unexpected context value %x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2206 | context); |
| 2207 | BUG(); |
| 2208 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2209 | |
| 2210 | cmd = instance->cmd_list[context]; |
| 2211 | |
| 2212 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 2213 | |
| 2214 | consumer++; |
| 2215 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 2216 | consumer = 0; |
| 2217 | } |
| 2218 | } |
| 2219 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2220 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2221 | |
| 2222 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 2223 | |
| 2224 | /* |
| 2225 | * Check if we can restore can_queue |
| 2226 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2227 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2228 | } |
| 2229 | |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2230 | static void megasas_sriov_heartbeat_handler(struct timer_list *t); |
| 2231 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2232 | /** |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2233 | * megasas_start_timer - Initializes sriov heartbeat timer object |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2234 | * @instance: Adapter soft state |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2235 | * |
| 2236 | */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2237 | void megasas_start_timer(struct megasas_instance *instance) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2238 | { |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2239 | struct timer_list *timer = &instance->sriov_heartbeat_timer; |
| 2240 | |
| 2241 | timer_setup(timer, megasas_sriov_heartbeat_handler, 0); |
| 2242 | timer->expires = jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2243 | add_timer(timer); |
| 2244 | } |
| 2245 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2246 | static void |
| 2247 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 2248 | |
| 2249 | static void |
| 2250 | process_fw_state_change_wq(struct work_struct *work); |
| 2251 | |
YueHaibing | 6764f51 | 2019-07-02 21:01:14 +0800 | [diff] [blame^] | 2252 | static void megasas_do_ocr(struct megasas_instance *instance) |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2253 | { |
| 2254 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2255 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2256 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2257 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2258 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2259 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2260 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2261 | instance->issuepend_done = 0; |
| 2262 | |
| 2263 | atomic_set(&instance->fw_outstanding, 0); |
| 2264 | megasas_internal_reset_defer_cmds(instance); |
| 2265 | process_fw_state_change_wq(&instance->work_init); |
| 2266 | } |
| 2267 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2268 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 2269 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2270 | { |
| 2271 | struct megasas_cmd *cmd; |
| 2272 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2273 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2274 | dma_addr_t new_affiliation_111_h; |
| 2275 | int ld, retval = 0; |
| 2276 | u8 thisVf; |
| 2277 | |
| 2278 | cmd = megasas_get_cmd(instance); |
| 2279 | |
| 2280 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2281 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation_111:" |
| 2282 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2283 | instance->host->host_no); |
| 2284 | return -ENOMEM; |
| 2285 | } |
| 2286 | |
| 2287 | dcmd = &cmd->frame->dcmd; |
| 2288 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2289 | if (!instance->vf_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2290 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2291 | "affiliation for scsi%d\n", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2292 | megasas_return_cmd(instance, cmd); |
| 2293 | return -ENOMEM; |
| 2294 | } |
| 2295 | |
| 2296 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2297 | memset(instance->vf_affiliation_111, 0, |
| 2298 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2299 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2300 | new_affiliation_111 = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2301 | dma_alloc_coherent(&instance->pdev->dev, |
| 2302 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2303 | &new_affiliation_111_h, GFP_KERNEL); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2304 | if (!new_affiliation_111) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2305 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2306 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2307 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2308 | megasas_return_cmd(instance, cmd); |
| 2309 | return -ENOMEM; |
| 2310 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2314 | |
| 2315 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2316 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2317 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2318 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2319 | dcmd->timeout = 0; |
| 2320 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2321 | dcmd->data_xfer_len = |
| 2322 | cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111)); |
| 2323 | 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] | 2324 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2325 | if (initial) |
| 2326 | dcmd->sgl.sge32[0].phys_addr = |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2327 | cpu_to_le32(instance->vf_affiliation_111_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2328 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2329 | dcmd->sgl.sge32[0].phys_addr = |
| 2330 | cpu_to_le32(new_affiliation_111_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2331 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2332 | dcmd->sgl.sge32[0].length = cpu_to_le32( |
| 2333 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2334 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2335 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2336 | "scsi%d\n", instance->host->host_no); |
| 2337 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2338 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2339 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2340 | " failed with status 0x%x for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2341 | dcmd->cmd_status, instance->host->host_no); |
| 2342 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2343 | goto out; |
| 2344 | } |
| 2345 | |
| 2346 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2347 | thisVf = new_affiliation_111->thisVf; |
| 2348 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 2349 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 2350 | new_affiliation_111->map[ld].policy[thisVf]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2351 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
| 2352 | "Got new LD/VF affiliation for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2353 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2354 | memcpy(instance->vf_affiliation_111, |
| 2355 | new_affiliation_111, |
| 2356 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2357 | retval = 1; |
| 2358 | goto out; |
| 2359 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2360 | } |
| 2361 | out: |
| 2362 | if (new_affiliation_111) { |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 2363 | dma_free_coherent(&instance->pdev->dev, |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2364 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 2365 | new_affiliation_111, |
| 2366 | new_affiliation_111_h); |
| 2367 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2368 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2369 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2370 | |
| 2371 | return retval; |
| 2372 | } |
| 2373 | |
| 2374 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 2375 | int initial) |
| 2376 | { |
| 2377 | struct megasas_cmd *cmd; |
| 2378 | struct megasas_dcmd_frame *dcmd; |
| 2379 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 2380 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 2381 | dma_addr_t new_affiliation_h; |
| 2382 | int i, j, retval = 0, found = 0, doscan = 0; |
| 2383 | u8 thisVf; |
| 2384 | |
| 2385 | cmd = megasas_get_cmd(instance); |
| 2386 | |
| 2387 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2388 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_get_ld_vf_affiliation12: " |
| 2389 | "Failed to get cmd for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2390 | instance->host->host_no); |
| 2391 | return -ENOMEM; |
| 2392 | } |
| 2393 | |
| 2394 | dcmd = &cmd->frame->dcmd; |
| 2395 | |
| 2396 | if (!instance->vf_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2397 | dev_warn(&instance->pdev->dev, "SR-IOV: Couldn't get LD/VF " |
| 2398 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2399 | megasas_return_cmd(instance, cmd); |
| 2400 | return -ENOMEM; |
| 2401 | } |
| 2402 | |
| 2403 | if (initial) |
| 2404 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 2405 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2406 | else { |
| 2407 | new_affiliation = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2408 | dma_alloc_coherent(&instance->pdev->dev, |
| 2409 | (MAX_LOGICAL_DRIVES + 1) * sizeof(struct MR_LD_VF_AFFILIATION), |
| 2410 | &new_affiliation_h, GFP_KERNEL); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2411 | if (!new_affiliation) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2412 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate " |
| 2413 | "memory for new affiliation for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2414 | instance->host->host_no); |
| 2415 | megasas_return_cmd(instance, cmd); |
| 2416 | return -ENOMEM; |
| 2417 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2421 | |
| 2422 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2423 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2424 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2425 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2426 | dcmd->timeout = 0; |
| 2427 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2428 | dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2429 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 2430 | 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] | 2431 | |
| 2432 | if (initial) |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2433 | dcmd->sgl.sge32[0].phys_addr = |
| 2434 | cpu_to_le32(instance->vf_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2435 | else |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2436 | dcmd->sgl.sge32[0].phys_addr = |
| 2437 | cpu_to_le32(new_affiliation_h); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2438 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2439 | dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) * |
| 2440 | sizeof(struct MR_LD_VF_AFFILIATION)); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2441 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2442 | dev_warn(&instance->pdev->dev, "SR-IOV: Getting LD/VF affiliation for " |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2443 | "scsi%d\n", instance->host->host_no); |
| 2444 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2445 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 2446 | if (megasas_issue_blocked_cmd(instance, cmd, 0) != DCMD_SUCCESS) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2447 | dev_warn(&instance->pdev->dev, "SR-IOV: LD/VF affiliation DCMD" |
| 2448 | " failed with status 0x%x for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2449 | dcmd->cmd_status, instance->host->host_no); |
| 2450 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2451 | goto out; |
| 2452 | } |
| 2453 | |
| 2454 | if (!initial) { |
| 2455 | if (!new_affiliation->ldCount) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2456 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2457 | "affiliation for passive path for scsi%d\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2458 | instance->host->host_no); |
| 2459 | retval = 1; |
| 2460 | goto out; |
| 2461 | } |
| 2462 | newmap = new_affiliation->map; |
| 2463 | savedmap = instance->vf_affiliation->map; |
| 2464 | thisVf = new_affiliation->thisVf; |
| 2465 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2466 | found = 0; |
| 2467 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2468 | j++) { |
| 2469 | if (newmap->ref.targetId == |
| 2470 | savedmap->ref.targetId) { |
| 2471 | found = 1; |
| 2472 | if (newmap->policy[thisVf] != |
| 2473 | savedmap->policy[thisVf]) { |
| 2474 | doscan = 1; |
| 2475 | goto out; |
| 2476 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2477 | } |
| 2478 | savedmap = (struct MR_LD_VF_MAP *) |
| 2479 | ((unsigned char *)savedmap + |
| 2480 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2481 | } |
| 2482 | if (!found && newmap->policy[thisVf] != |
| 2483 | MR_LD_ACCESS_HIDDEN) { |
| 2484 | doscan = 1; |
| 2485 | goto out; |
| 2486 | } |
| 2487 | newmap = (struct MR_LD_VF_MAP *) |
| 2488 | ((unsigned char *)newmap + newmap->size); |
| 2489 | } |
| 2490 | |
| 2491 | newmap = new_affiliation->map; |
| 2492 | savedmap = instance->vf_affiliation->map; |
| 2493 | |
| 2494 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2495 | found = 0; |
| 2496 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2497 | if (savedmap->ref.targetId == |
| 2498 | newmap->ref.targetId) { |
| 2499 | found = 1; |
| 2500 | if (savedmap->policy[thisVf] != |
| 2501 | newmap->policy[thisVf]) { |
| 2502 | doscan = 1; |
| 2503 | goto out; |
| 2504 | } |
| 2505 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2506 | newmap = (struct MR_LD_VF_MAP *) |
| 2507 | ((unsigned char *)newmap + |
| 2508 | newmap->size); |
| 2509 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2510 | if (!found && savedmap->policy[thisVf] != |
| 2511 | MR_LD_ACCESS_HIDDEN) { |
| 2512 | doscan = 1; |
| 2513 | goto out; |
| 2514 | } |
| 2515 | savedmap = (struct MR_LD_VF_MAP *) |
| 2516 | ((unsigned char *)savedmap + |
| 2517 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2518 | } |
| 2519 | } |
| 2520 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2521 | if (doscan) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2522 | dev_warn(&instance->pdev->dev, "SR-IOV: Got new LD/VF " |
| 2523 | "affiliation for scsi%d\n", instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2524 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2525 | new_affiliation->size); |
| 2526 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2527 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2528 | |
| 2529 | if (new_affiliation) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 2530 | dma_free_coherent(&instance->pdev->dev, |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2531 | (MAX_LOGICAL_DRIVES + 1) * |
| 2532 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2533 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2534 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2535 | |
| 2536 | return retval; |
| 2537 | } |
| 2538 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2539 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2540 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2541 | int initial) |
| 2542 | { |
| 2543 | int retval; |
| 2544 | |
| 2545 | if (instance->PlasmaFW111) |
| 2546 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2547 | else |
| 2548 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2549 | return retval; |
| 2550 | } |
| 2551 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2552 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2553 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2554 | int initial) |
| 2555 | { |
| 2556 | struct megasas_cmd *cmd; |
| 2557 | struct megasas_dcmd_frame *dcmd; |
| 2558 | int retval = 0; |
| 2559 | |
| 2560 | cmd = megasas_get_cmd(instance); |
| 2561 | |
| 2562 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2563 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "megasas_sriov_start_heartbeat: " |
| 2564 | "Failed to get cmd for scsi%d\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2565 | instance->host->host_no); |
| 2566 | return -ENOMEM; |
| 2567 | } |
| 2568 | |
| 2569 | dcmd = &cmd->frame->dcmd; |
| 2570 | |
| 2571 | if (initial) { |
| 2572 | instance->hb_host_mem = |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 2573 | dma_alloc_coherent(&instance->pdev->dev, |
| 2574 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2575 | &instance->hb_host_mem_h, |
| 2576 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2577 | if (!instance->hb_host_mem) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2578 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "SR-IOV: Couldn't allocate" |
| 2579 | " memory for heartbeat host memory for scsi%d\n", |
| 2580 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2581 | retval = -ENOMEM; |
| 2582 | goto out; |
| 2583 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2587 | |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2588 | 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] | 2589 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2590 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2591 | dcmd->sge_count = 1; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2592 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2593 | dcmd->timeout = 0; |
| 2594 | dcmd->pad_0 = 0; |
Christoph Hellwig | 2213a46 | 2015-04-23 16:33:54 +0530 | [diff] [blame] | 2595 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM)); |
| 2596 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 2597 | |
| 2598 | megasas_set_dma_settings(instance, dcmd, instance->hb_host_mem_h, |
| 2599 | sizeof(struct MR_CTRL_HB_HOST_MEM)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2600 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2601 | 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] | 2602 | instance->host->host_no); |
| 2603 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2604 | if ((instance->adapter_type != MFI_SERIES) && |
| 2605 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2606 | retval = megasas_issue_blocked_cmd(instance, cmd, |
| 2607 | MEGASAS_ROUTINE_WAIT_TIME_VF); |
| 2608 | else |
| 2609 | retval = megasas_issue_polled(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2610 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2611 | if (retval) { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2612 | dev_warn(&instance->pdev->dev, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2613 | "_MEM_ALLOC DCMD %s for scsi%d\n", |
| 2614 | (dcmd->cmd_status == MFI_STAT_INVALID_STATUS) ? |
| 2615 | "timed out" : "failed", instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2616 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | out: |
| 2620 | megasas_return_cmd(instance, cmd); |
| 2621 | |
| 2622 | return retval; |
| 2623 | } |
| 2624 | |
| 2625 | /* Handler for SR-IOV heartbeat */ |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2626 | static void megasas_sriov_heartbeat_handler(struct timer_list *t) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2627 | { |
| 2628 | struct megasas_instance *instance = |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 2629 | from_timer(instance, t, sriov_heartbeat_timer); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2630 | |
| 2631 | if (instance->hb_host_mem->HB.fwCounter != |
| 2632 | instance->hb_host_mem->HB.driverCounter) { |
| 2633 | instance->hb_host_mem->HB.driverCounter = |
| 2634 | instance->hb_host_mem->HB.fwCounter; |
| 2635 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2636 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2637 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2638 | dev_warn(&instance->pdev->dev, "SR-IOV: Heartbeat never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2639 | "completed for scsi%d\n", instance->host->host_no); |
| 2640 | schedule_work(&instance->work_init); |
| 2641 | } |
| 2642 | } |
| 2643 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2644 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2645 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2646 | * @instance: Adapter soft state |
| 2647 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2648 | * 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] | 2649 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2650 | * are pending after this time period. It also marks the controller dead. |
| 2651 | */ |
| 2652 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2653 | { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2654 | int i, sl, outstanding; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2655 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2656 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2657 | unsigned long flags; |
| 2658 | struct list_head clist_local; |
| 2659 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2660 | u32 fw_state; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2661 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2662 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2663 | dev_info(&instance->pdev->dev, "%s:%d HBA is killed.\n", |
| 2664 | __func__, __LINE__); |
| 2665 | return FAILED; |
| 2666 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2667 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2668 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2669 | |
| 2670 | INIT_LIST_HEAD(&clist_local); |
| 2671 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2672 | list_splice_init(&instance->internal_reset_pending_q, |
| 2673 | &clist_local); |
| 2674 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2675 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2676 | dev_notice(&instance->pdev->dev, "HBA reset wait ...\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2677 | for (i = 0; i < wait_time; i++) { |
| 2678 | msleep(1000); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2679 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2680 | break; |
| 2681 | } |
| 2682 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2683 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2684 | dev_notice(&instance->pdev->dev, "reset: Stopping HBA.\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2685 | atomic_set(&instance->adprecovery, MEGASAS_HW_CRITICAL_ERROR); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2686 | return FAILED; |
| 2687 | } |
| 2688 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2689 | reset_index = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2690 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2691 | reset_cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2692 | struct megasas_cmd, list); |
| 2693 | list_del_init(&reset_cmd->list); |
| 2694 | if (reset_cmd->scmd) { |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 2695 | reset_cmd->scmd->result = DID_REQUEUE << 16; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2696 | dev_notice(&instance->pdev->dev, "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2697 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2698 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2699 | |
| 2700 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2701 | megasas_return_cmd(instance, reset_cmd); |
| 2702 | } else if (reset_cmd->sync_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2703 | dev_notice(&instance->pdev->dev, "%p synch cmds" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2704 | "reset queue\n", |
| 2705 | reset_cmd); |
| 2706 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 2707 | reset_cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2708 | instance->instancet->fire_cmd(instance, |
| 2709 | reset_cmd->frame_phys_addr, |
| 2710 | 0, instance->reg_set); |
| 2711 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2712 | dev_notice(&instance->pdev->dev, "%p unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2713 | "cmds lst\n", |
| 2714 | reset_cmd); |
| 2715 | } |
| 2716 | reset_index++; |
| 2717 | } |
| 2718 | |
| 2719 | return SUCCESS; |
| 2720 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2721 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2722 | for (i = 0; i < resetwaittime; i++) { |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2723 | outstanding = atomic_read(&instance->fw_outstanding); |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2724 | |
| 2725 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2726 | break; |
| 2727 | |
| 2728 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2729 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2730 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2731 | /* |
| 2732 | * Call cmd completion routine. Cmd to be |
| 2733 | * be completed directly without depending on isr. |
| 2734 | */ |
| 2735 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | msleep(1000); |
| 2739 | } |
| 2740 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2741 | i = 0; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2742 | outstanding = atomic_read(&instance->fw_outstanding); |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 2743 | fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2744 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2745 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2746 | goto no_outstanding; |
| 2747 | |
| 2748 | if (instance->disableOnlineCtrlReset) |
| 2749 | goto kill_hba_and_failed; |
| 2750 | do { |
| 2751 | if ((fw_state == MFI_STATE_FAULT) || atomic_read(&instance->fw_outstanding)) { |
| 2752 | dev_info(&instance->pdev->dev, |
Colin Ian King | efc372c | 2019-04-17 14:51:09 +0100 | [diff] [blame] | 2753 | "%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] | 2754 | __func__, __LINE__, fw_state, atomic_read(&instance->fw_outstanding)); |
| 2755 | if (i == 3) |
| 2756 | goto kill_hba_and_failed; |
| 2757 | megasas_do_ocr(instance); |
| 2758 | |
| 2759 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
| 2760 | dev_info(&instance->pdev->dev, "%s:%d OCR failed and HBA is killed.\n", |
| 2761 | __func__, __LINE__); |
| 2762 | return FAILED; |
| 2763 | } |
| 2764 | dev_info(&instance->pdev->dev, "%s:%d waiting_for_outstanding: after issue OCR.\n", |
| 2765 | __func__, __LINE__); |
| 2766 | |
| 2767 | for (sl = 0; sl < 10; sl++) |
| 2768 | msleep(500); |
| 2769 | |
| 2770 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2771 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 2772 | fw_state = instance->instancet->read_fw_status_reg(instance) & MFI_STATE_MASK; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2773 | if ((!outstanding && (fw_state == MFI_STATE_OPERATIONAL))) |
| 2774 | goto no_outstanding; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2775 | } |
| 2776 | i++; |
| 2777 | } while (i <= 3); |
| 2778 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2779 | no_outstanding: |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2780 | |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2781 | dev_info(&instance->pdev->dev, "%s:%d no more pending commands remain after reset handling.\n", |
| 2782 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2783 | return SUCCESS; |
Sumit Saxena | ccc7507 | 2016-01-28 21:04:33 +0530 | [diff] [blame] | 2784 | |
| 2785 | kill_hba_and_failed: |
| 2786 | |
| 2787 | /* Reset not supported, kill adapter */ |
| 2788 | dev_info(&instance->pdev->dev, "%s:%d killing adapter scsi%d" |
| 2789 | " disableOnlineCtrlReset %d fw_outstanding %d \n", |
| 2790 | __func__, __LINE__, instance->host->host_no, instance->disableOnlineCtrlReset, |
| 2791 | atomic_read(&instance->fw_outstanding)); |
| 2792 | megasas_dump_pending_frames(instance); |
| 2793 | megaraid_sas_kill_hba(instance); |
| 2794 | |
| 2795 | return FAILED; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | /** |
| 2799 | * megasas_generic_reset - Generic reset routine |
| 2800 | * @scmd: Mid-layer SCSI command |
| 2801 | * |
| 2802 | * This routine implements a generic reset handler for device, bus and host |
| 2803 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2804 | * function after they do their specific tasks. |
| 2805 | */ |
| 2806 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2807 | { |
| 2808 | int ret_val; |
| 2809 | struct megasas_instance *instance; |
| 2810 | |
| 2811 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2812 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2813 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2814 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2815 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2816 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2817 | dev_err(&instance->pdev->dev, "cannot recover from previous reset failures\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2818 | return FAILED; |
| 2819 | } |
| 2820 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2821 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2822 | if (ret_val == SUCCESS) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2823 | dev_notice(&instance->pdev->dev, "reset successful\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2824 | else |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2825 | dev_err(&instance->pdev->dev, "failed to do reset\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2826 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2827 | return ret_val; |
| 2828 | } |
| 2829 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2830 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2831 | * megasas_reset_timer - quiesce the adapter if required |
| 2832 | * @scmd: scsi cmnd |
| 2833 | * |
| 2834 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2835 | * cmd has not been completed within the timeout period. |
| 2836 | */ |
| 2837 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2838 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2839 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2840 | struct megasas_instance *instance; |
| 2841 | unsigned long flags; |
| 2842 | |
| 2843 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 2844 | (scmd_timeout * 2) * HZ)) { |
Christoph Hellwig | 6600593 | 2018-05-29 15:52:29 +0200 | [diff] [blame] | 2845 | return BLK_EH_DONE; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2848 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2849 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2850 | /* FW is busy, throttle IO */ |
| 2851 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2852 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2853 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2854 | instance->last_time = jiffies; |
| 2855 | instance->flag |= MEGASAS_FW_BUSY; |
| 2856 | |
| 2857 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2858 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2859 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | /** |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2863 | * megasas_dump - This function will print hexdump of provided buffer. |
| 2864 | * @buf: Buffer to be dumped |
| 2865 | * @sz: Size in bytes |
| 2866 | * @format: Different formats of dumping e.g. format=n will |
| 2867 | * cause only 'n' 32 bit words to be dumped in a single |
| 2868 | * line. |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2869 | */ |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2870 | inline void |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2871 | megasas_dump(void *buf, int sz, int format) |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2872 | { |
| 2873 | int i; |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2874 | __le32 *buf_loc = (__le32 *)buf; |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2875 | |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2876 | for (i = 0; i < (sz / sizeof(__le32)); i++) { |
| 2877 | if ((i % format) == 0) { |
| 2878 | if (i != 0) |
| 2879 | printk(KERN_CONT "\n"); |
| 2880 | printk(KERN_CONT "%08x: ", (i * 4)); |
| 2881 | } |
| 2882 | printk(KERN_CONT "%08x ", le32_to_cpu(buf_loc[i])); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2883 | } |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2884 | printk(KERN_CONT "\n"); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | /** |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame] | 2888 | * megasas_dump_reg_set - This function will print hexdump of register set |
| 2889 | * @buf: Buffer to be dumped |
| 2890 | * @sz: Size in bytes |
| 2891 | * @format: Different formats of dumping e.g. format=n will |
| 2892 | * cause only 'n' 32 bit words to be dumped in a |
| 2893 | * single line. |
| 2894 | */ |
| 2895 | inline void |
| 2896 | megasas_dump_reg_set(void __iomem *reg_set) |
| 2897 | { |
| 2898 | unsigned int i, sz = 256; |
| 2899 | u32 __iomem *reg = (u32 __iomem *)reg_set; |
| 2900 | |
| 2901 | for (i = 0; i < (sz / sizeof(u32)); i++) |
| 2902 | printk("%08x: %08x\n", (i * 4), readl(®[i])); |
| 2903 | } |
| 2904 | |
| 2905 | /** |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2906 | * megasas_dump_fusion_io - This function will print key details |
| 2907 | * of SCSI IO |
| 2908 | * @scmd: SCSI command pointer of SCSI IO |
| 2909 | */ |
| 2910 | void |
| 2911 | megasas_dump_fusion_io(struct scsi_cmnd *scmd) |
| 2912 | { |
| 2913 | struct megasas_cmd_fusion *cmd; |
| 2914 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2915 | struct megasas_instance *instance; |
| 2916 | |
| 2917 | cmd = (struct megasas_cmd_fusion *)scmd->SCp.ptr; |
| 2918 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2919 | |
| 2920 | scmd_printk(KERN_INFO, scmd, |
| 2921 | "scmd: (0x%p) retries: 0x%x allowed: 0x%x\n", |
| 2922 | scmd, scmd->retries, scmd->allowed); |
| 2923 | scsi_print_command(scmd); |
| 2924 | |
| 2925 | if (cmd) { |
| 2926 | req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc; |
| 2927 | scmd_printk(KERN_INFO, scmd, "Request descriptor details:\n"); |
| 2928 | scmd_printk(KERN_INFO, scmd, |
| 2929 | "RequestFlags:0x%x MSIxIndex:0x%x SMID:0x%x LMID:0x%x DevHandle:0x%x\n", |
| 2930 | req_desc->SCSIIO.RequestFlags, |
| 2931 | req_desc->SCSIIO.MSIxIndex, req_desc->SCSIIO.SMID, |
| 2932 | req_desc->SCSIIO.LMID, req_desc->SCSIIO.DevHandle); |
| 2933 | |
| 2934 | printk(KERN_INFO "IO request frame:\n"); |
| 2935 | megasas_dump(cmd->io_request, |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2936 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE, 8); |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2937 | printk(KERN_INFO "Chain frame:\n"); |
| 2938 | megasas_dump(cmd->sg_frame, |
Shivasharan S | 4fe5503 | 2019-05-07 10:05:39 -0700 | [diff] [blame] | 2939 | instance->max_chain_frame_sz, 8); |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | } |
| 2943 | |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 2944 | /* |
| 2945 | * megasas_dump_sys_regs - This function will dump system registers through |
| 2946 | * sysfs. |
| 2947 | * @reg_set: Pointer to System register set. |
| 2948 | * @buf: Buffer to which output is to be written. |
| 2949 | * @return: Number of bytes written to buffer. |
| 2950 | */ |
| 2951 | static inline ssize_t |
| 2952 | megasas_dump_sys_regs(void __iomem *reg_set, char *buf) |
| 2953 | { |
| 2954 | unsigned int i, sz = 256; |
| 2955 | int bytes_wrote = 0; |
| 2956 | char *loc = (char *)buf; |
| 2957 | u32 __iomem *reg = (u32 __iomem *)reg_set; |
| 2958 | |
| 2959 | for (i = 0; i < sz / sizeof(u32); i++) { |
| 2960 | bytes_wrote += snprintf(loc + bytes_wrote, PAGE_SIZE, |
| 2961 | "%08x: %08x\n", (i * 4), |
| 2962 | readl(®[i])); |
| 2963 | } |
| 2964 | return bytes_wrote; |
| 2965 | } |
| 2966 | |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2967 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2968 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2969 | */ |
| 2970 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2971 | { |
| 2972 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2973 | struct megasas_instance *instance; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 2974 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2975 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2976 | |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2977 | scmd_printk(KERN_INFO, scmd, |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2978 | "OCR is requested due to IO timeout!!\n"); |
| 2979 | |
| 2980 | scmd_printk(KERN_INFO, scmd, |
| 2981 | "SCSI host state: %d SCSI host busy: %d FW outstanding: %d\n", |
| 2982 | scmd->device->host->shost_state, |
Ming Lei | c84b023 | 2018-06-24 22:03:26 +0800 | [diff] [blame] | 2983 | scsi_host_busy(scmd->device->host), |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2984 | atomic_read(&instance->fw_outstanding)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2985 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2986 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2987 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2988 | if (instance->adapter_type == MFI_SERIES) { |
| 2989 | ret = megasas_generic_reset(scmd); |
| 2990 | } else { |
Shivasharan S | 96c9603 | 2019-05-07 10:05:37 -0700 | [diff] [blame] | 2991 | megasas_dump_fusion_io(scmd); |
Shivasharan S | def0eab | 2017-02-10 00:59:15 -0800 | [diff] [blame] | 2992 | ret = megasas_reset_fusion(scmd->device->host, |
| 2993 | SCSIIO_TIMEOUT_OCR); |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 2994 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2995 | |
| 2996 | return ret; |
| 2997 | } |
| 2998 | |
| 2999 | /** |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3000 | * megasas_task_abort - Issues task abort request to firmware |
| 3001 | * (supported only for fusion adapters) |
| 3002 | * @scmd: SCSI command pointer |
| 3003 | */ |
| 3004 | static int megasas_task_abort(struct scsi_cmnd *scmd) |
| 3005 | { |
| 3006 | int ret; |
| 3007 | struct megasas_instance *instance; |
| 3008 | |
| 3009 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 3010 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3011 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3012 | ret = megasas_task_abort_fusion(scmd); |
| 3013 | else { |
| 3014 | sdev_printk(KERN_NOTICE, scmd->device, "TASK ABORT not supported\n"); |
| 3015 | ret = FAILED; |
| 3016 | } |
| 3017 | |
| 3018 | return ret; |
| 3019 | } |
| 3020 | |
| 3021 | /** |
| 3022 | * megasas_reset_target: Issues target reset request to firmware |
| 3023 | * (supported only for fusion adapters) |
| 3024 | * @scmd: SCSI command pointer |
| 3025 | */ |
| 3026 | static int megasas_reset_target(struct scsi_cmnd *scmd) |
| 3027 | { |
| 3028 | int ret; |
| 3029 | struct megasas_instance *instance; |
| 3030 | |
| 3031 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 3032 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3033 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3034 | ret = megasas_reset_target_fusion(scmd); |
| 3035 | else { |
| 3036 | sdev_printk(KERN_NOTICE, scmd->device, "TARGET RESET not supported\n"); |
| 3037 | ret = FAILED; |
| 3038 | } |
| 3039 | |
| 3040 | return ret; |
| 3041 | } |
| 3042 | |
| 3043 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3044 | * megasas_bios_param - Returns disk geometry for a disk |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3045 | * @sdev: device handle |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3046 | * @bdev: block device |
| 3047 | * @capacity: drive capacity |
| 3048 | * @geom: geometry parameters |
| 3049 | */ |
| 3050 | static int |
| 3051 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 3052 | sector_t capacity, int geom[]) |
| 3053 | { |
| 3054 | int heads; |
| 3055 | int sectors; |
| 3056 | sector_t cylinders; |
| 3057 | unsigned long tmp; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3058 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3059 | /* Default heads (64) & sectors (32) */ |
| 3060 | heads = 64; |
| 3061 | sectors = 32; |
| 3062 | |
| 3063 | tmp = heads * sectors; |
| 3064 | cylinders = capacity; |
| 3065 | |
| 3066 | sector_div(cylinders, tmp); |
| 3067 | |
| 3068 | /* |
| 3069 | * Handle extended translation size for logical drives > 1Gb |
| 3070 | */ |
| 3071 | |
| 3072 | if (capacity >= 0x200000) { |
| 3073 | heads = 255; |
| 3074 | sectors = 63; |
| 3075 | tmp = heads*sectors; |
| 3076 | cylinders = capacity; |
| 3077 | sector_div(cylinders, tmp); |
| 3078 | } |
| 3079 | |
| 3080 | geom[0] = heads; |
| 3081 | geom[1] = sectors; |
| 3082 | geom[2] = cylinders; |
| 3083 | |
| 3084 | return 0; |
| 3085 | } |
| 3086 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3087 | static void megasas_aen_polling(struct work_struct *work); |
| 3088 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3089 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3090 | * megasas_service_aen - Processes an event notification |
| 3091 | * @instance: Adapter soft state |
| 3092 | * @cmd: AEN command completed by the ISR |
| 3093 | * |
| 3094 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 3095 | * event occurs. When an event of interest occurs, FW completes the command |
| 3096 | * that it was previously holding. |
| 3097 | * |
| 3098 | * This routines sends SIGIO signal to processes that have registered with the |
| 3099 | * driver for AEN. |
| 3100 | */ |
| 3101 | static void |
| 3102 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 3103 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3104 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3105 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3106 | /* |
| 3107 | * Don't signal app if it is just an aborted previously registered aen |
| 3108 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3109 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 3110 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3111 | megasas_poll_wait_aen = 1; |
| 3112 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3113 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3114 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3115 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3116 | else |
| 3117 | cmd->abort_aen = 0; |
| 3118 | |
| 3119 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3120 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3121 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3122 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3123 | if ((instance->unload == 0) && |
| 3124 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3125 | struct megasas_aen_event *ev; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3126 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3127 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 3128 | if (!ev) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3129 | dev_err(&instance->pdev->dev, "megasas_service_aen: out of memory\n"); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3130 | } else { |
| 3131 | ev->instance = instance; |
| 3132 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 3133 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 3134 | megasas_aen_polling); |
| 3135 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3136 | } |
| 3137 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3138 | } |
| 3139 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3140 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3141 | fw_crash_buffer_store(struct device *cdev, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3142 | struct device_attribute *attr, const char *buf, size_t count) |
| 3143 | { |
| 3144 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3145 | struct megasas_instance *instance = |
| 3146 | (struct megasas_instance *) shost->hostdata; |
| 3147 | int val = 0; |
| 3148 | unsigned long flags; |
| 3149 | |
| 3150 | if (kstrtoint(buf, 0, &val) != 0) |
| 3151 | return -EINVAL; |
| 3152 | |
| 3153 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3154 | instance->fw_crash_buffer_offset = val; |
| 3155 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3156 | return strlen(buf); |
| 3157 | } |
| 3158 | |
| 3159 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3160 | fw_crash_buffer_show(struct device *cdev, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3161 | struct device_attribute *attr, char *buf) |
| 3162 | { |
| 3163 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3164 | struct megasas_instance *instance = |
| 3165 | (struct megasas_instance *) shost->hostdata; |
| 3166 | u32 size; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3167 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 3168 | unsigned long src_addr; |
| 3169 | unsigned long flags; |
| 3170 | u32 buff_offset; |
| 3171 | |
| 3172 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3173 | buff_offset = instance->fw_crash_buffer_offset; |
| 3174 | if (!instance->crash_dump_buf && |
| 3175 | !((instance->fw_crash_state == AVAILABLE) || |
| 3176 | (instance->fw_crash_state == COPYING))) { |
| 3177 | dev_err(&instance->pdev->dev, |
| 3178 | "Firmware crash dump is not available\n"); |
| 3179 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3180 | return -EINVAL; |
| 3181 | } |
| 3182 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3183 | if (buff_offset > (instance->fw_crash_buffer_size * dmachunk)) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3184 | dev_err(&instance->pdev->dev, |
| 3185 | "Firmware crash dump offset is out of range\n"); |
| 3186 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3187 | return 0; |
| 3188 | } |
| 3189 | |
| 3190 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 3191 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 3192 | |
| 3193 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 3194 | (buff_offset % dmachunk); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3195 | memcpy(buf, (void *)src_addr, size); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3196 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3197 | |
| 3198 | return size; |
| 3199 | } |
| 3200 | |
| 3201 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3202 | fw_crash_buffer_size_show(struct device *cdev, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3203 | struct device_attribute *attr, char *buf) |
| 3204 | { |
| 3205 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3206 | struct megasas_instance *instance = |
| 3207 | (struct megasas_instance *) shost->hostdata; |
| 3208 | |
| 3209 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 3210 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 3211 | } |
| 3212 | |
| 3213 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3214 | fw_crash_state_store(struct device *cdev, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3215 | struct device_attribute *attr, const char *buf, size_t count) |
| 3216 | { |
| 3217 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3218 | struct megasas_instance *instance = |
| 3219 | (struct megasas_instance *) shost->hostdata; |
| 3220 | int val = 0; |
| 3221 | unsigned long flags; |
| 3222 | |
| 3223 | if (kstrtoint(buf, 0, &val) != 0) |
| 3224 | return -EINVAL; |
| 3225 | |
| 3226 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 3227 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 3228 | "firmware crash state\n"); |
| 3229 | return -EINVAL; |
| 3230 | } |
| 3231 | |
| 3232 | instance->fw_crash_state = val; |
| 3233 | |
| 3234 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 3235 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 3236 | megasas_free_host_crash_buffer(instance); |
| 3237 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 3238 | if (val == COPY_ERROR) |
| 3239 | dev_info(&instance->pdev->dev, "application failed to " |
| 3240 | "copy Firmware crash dump\n"); |
| 3241 | else |
| 3242 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 3243 | "copied successfully\n"); |
| 3244 | } |
| 3245 | return strlen(buf); |
| 3246 | } |
| 3247 | |
| 3248 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3249 | fw_crash_state_show(struct device *cdev, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3250 | struct device_attribute *attr, char *buf) |
| 3251 | { |
| 3252 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3253 | struct megasas_instance *instance = |
| 3254 | (struct megasas_instance *) shost->hostdata; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3255 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3256 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 3257 | } |
| 3258 | |
| 3259 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3260 | page_size_show(struct device *cdev, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3261 | struct device_attribute *attr, char *buf) |
| 3262 | { |
| 3263 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 3264 | } |
| 3265 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3266 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3267 | ldio_outstanding_show(struct device *cdev, struct device_attribute *attr, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3268 | char *buf) |
| 3269 | { |
| 3270 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3271 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3272 | |
| 3273 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->ldio_outstanding)); |
| 3274 | } |
| 3275 | |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3276 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3277 | fw_cmds_outstanding_show(struct device *cdev, |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3278 | struct device_attribute *attr, char *buf) |
| 3279 | { |
| 3280 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3281 | struct megasas_instance *instance = (struct megasas_instance *)shost->hostdata; |
| 3282 | |
| 3283 | return snprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&instance->fw_outstanding)); |
| 3284 | } |
| 3285 | |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 3286 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3287 | dump_system_regs_show(struct device *cdev, |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 3288 | struct device_attribute *attr, char *buf) |
| 3289 | { |
| 3290 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3291 | struct megasas_instance *instance = |
| 3292 | (struct megasas_instance *)shost->hostdata; |
| 3293 | |
| 3294 | return megasas_dump_sys_regs(instance->reg_set, buf); |
| 3295 | } |
| 3296 | |
Shivasharan S | a6024a9 | 2019-05-07 10:05:43 -0700 | [diff] [blame] | 3297 | static ssize_t |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3298 | raid_map_id_show(struct device *cdev, struct device_attribute *attr, |
Shivasharan S | a6024a9 | 2019-05-07 10:05:43 -0700 | [diff] [blame] | 3299 | char *buf) |
| 3300 | { |
| 3301 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3302 | struct megasas_instance *instance = |
| 3303 | (struct megasas_instance *)shost->hostdata; |
| 3304 | |
| 3305 | return snprintf(buf, PAGE_SIZE, "%ld\n", |
| 3306 | (unsigned long)instance->map_id); |
| 3307 | } |
| 3308 | |
Tomas Henzl | d635468 | 2019-05-29 18:00:41 +0200 | [diff] [blame] | 3309 | static DEVICE_ATTR_RW(fw_crash_buffer); |
| 3310 | static DEVICE_ATTR_RO(fw_crash_buffer_size); |
| 3311 | static DEVICE_ATTR_RW(fw_crash_state); |
| 3312 | static DEVICE_ATTR_RO(page_size); |
| 3313 | static DEVICE_ATTR_RO(ldio_outstanding); |
| 3314 | static DEVICE_ATTR_RO(fw_cmds_outstanding); |
| 3315 | static DEVICE_ATTR_RO(dump_system_regs); |
| 3316 | static DEVICE_ATTR_RO(raid_map_id); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3317 | |
YueHaibing | 6764f51 | 2019-07-02 21:01:14 +0800 | [diff] [blame^] | 3318 | static struct device_attribute *megaraid_host_attrs[] = { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3319 | &dev_attr_fw_crash_buffer_size, |
| 3320 | &dev_attr_fw_crash_buffer, |
| 3321 | &dev_attr_fw_crash_state, |
| 3322 | &dev_attr_page_size, |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 3323 | &dev_attr_ldio_outstanding, |
Shivasharan S | 88d155c | 2018-01-05 05:27:46 -0800 | [diff] [blame] | 3324 | &dev_attr_fw_cmds_outstanding, |
Shivasharan S | cfb9a30 | 2019-05-07 10:05:40 -0700 | [diff] [blame] | 3325 | &dev_attr_dump_system_regs, |
Shivasharan S | a6024a9 | 2019-05-07 10:05:43 -0700 | [diff] [blame] | 3326 | &dev_attr_raid_map_id, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3327 | NULL, |
| 3328 | }; |
| 3329 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3330 | /* |
| 3331 | * Scsi host template for megaraid_sas driver |
| 3332 | */ |
| 3333 | static struct scsi_host_template megasas_template = { |
| 3334 | |
| 3335 | .module = THIS_MODULE, |
Sumit.Saxena@avagotech.com | 43cd7fe | 2015-04-23 16:31:39 +0530 | [diff] [blame] | 3336 | .name = "Avago SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3337 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 3338 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 3339 | .slave_alloc = megasas_slave_alloc, |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3340 | .slave_destroy = megasas_slave_destroy, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3341 | .queuecommand = megasas_queue_command, |
Sumit Saxena | bd23d4a | 2016-04-15 00:23:32 -0700 | [diff] [blame] | 3342 | .eh_target_reset_handler = megasas_reset_target, |
| 3343 | .eh_abort_handler = megasas_task_abort, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3344 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3345 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3346 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 3347 | .bios_param = megasas_bios_param, |
Christoph Hellwig | db5ed4d | 2014-11-13 15:08:42 +0100 | [diff] [blame] | 3348 | .change_queue_depth = scsi_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 3349 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3350 | }; |
| 3351 | |
| 3352 | /** |
| 3353 | * megasas_complete_int_cmd - Completes an internal command |
| 3354 | * @instance: Adapter soft state |
| 3355 | * @cmd: Command to be completed |
| 3356 | * |
| 3357 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 3358 | * after it issues a command. This function wakes up that waiting routine by |
| 3359 | * calling wake_up() on the wait queue. |
| 3360 | */ |
| 3361 | static void |
| 3362 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 3363 | struct megasas_cmd *cmd) |
| 3364 | { |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3365 | cmd->cmd_status_drv = cmd->frame->io.cmd_status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3366 | wake_up(&instance->int_cmd_wait_q); |
| 3367 | } |
| 3368 | |
| 3369 | /** |
| 3370 | * megasas_complete_abort - Completes aborting a command |
| 3371 | * @instance: Adapter soft state |
| 3372 | * @cmd: Cmd that was issued to abort another cmd |
| 3373 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3374 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 3375 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3376 | * wakes up all functions waiting on the same wait queue. |
| 3377 | */ |
| 3378 | static void |
| 3379 | megasas_complete_abort(struct megasas_instance *instance, |
| 3380 | struct megasas_cmd *cmd) |
| 3381 | { |
| 3382 | if (cmd->sync_cmd) { |
| 3383 | cmd->sync_cmd = 0; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3384 | cmd->cmd_status_drv = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3385 | wake_up(&instance->abort_cmd_wait_q); |
| 3386 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3390 | * megasas_complete_cmd - Completes a command |
| 3391 | * @instance: Adapter soft state |
| 3392 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3393 | * @alt_status: If non-zero, use this value as status to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3394 | * SCSI mid-layer instead of the value returned |
| 3395 | * by the FW. This should be used if caller wants |
| 3396 | * an alternate status (as in the case of aborted |
| 3397 | * commands) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3398 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3399 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3400 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 3401 | u8 alt_status) |
| 3402 | { |
| 3403 | int exception = 0; |
| 3404 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3405 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3406 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3407 | u32 opcode, status; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3408 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3409 | /* flag for the retry reset */ |
| 3410 | cmd->retry_for_fw_reset = 0; |
| 3411 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 3412 | if (cmd->scmd) |
| 3413 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3414 | |
| 3415 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3416 | case MFI_CMD_INVALID: |
| 3417 | /* Some older 1068 controller FW may keep a pended |
| 3418 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 3419 | when booting the kdump kernel. Ignore this command to |
| 3420 | prevent a kernel panic on shutdown of the kdump kernel. */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3421 | dev_warn(&instance->pdev->dev, "MFI_CMD_INVALID command " |
| 3422 | "completed\n"); |
| 3423 | dev_warn(&instance->pdev->dev, "If you have a controller " |
| 3424 | "other than PERC5, please upgrade your firmware\n"); |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3425 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3426 | case MFI_CMD_PD_SCSI_IO: |
| 3427 | case MFI_CMD_LD_SCSI_IO: |
| 3428 | |
| 3429 | /* |
| 3430 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 3431 | * issued either through an IO path or an IOCTL path. If it |
| 3432 | * was via IOCTL, we will send it to internal completion. |
| 3433 | */ |
| 3434 | if (cmd->sync_cmd) { |
| 3435 | cmd->sync_cmd = 0; |
| 3436 | megasas_complete_int_cmd(instance, cmd); |
| 3437 | break; |
| 3438 | } |
Gustavo A. R. Silva | 8d07f7d | 2018-11-27 22:32:27 -0600 | [diff] [blame] | 3439 | /* fall through */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3440 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3441 | case MFI_CMD_LD_READ: |
| 3442 | case MFI_CMD_LD_WRITE: |
| 3443 | |
| 3444 | if (alt_status) { |
| 3445 | cmd->scmd->result = alt_status << 16; |
| 3446 | exception = 1; |
| 3447 | } |
| 3448 | |
| 3449 | if (exception) { |
| 3450 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3451 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3452 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3453 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3454 | cmd->scmd->scsi_done(cmd->scmd); |
| 3455 | megasas_return_cmd(instance, cmd); |
| 3456 | |
| 3457 | break; |
| 3458 | } |
| 3459 | |
| 3460 | switch (hdr->cmd_status) { |
| 3461 | |
| 3462 | case MFI_STAT_OK: |
| 3463 | cmd->scmd->result = DID_OK << 16; |
| 3464 | break; |
| 3465 | |
| 3466 | case MFI_STAT_SCSI_IO_FAILED: |
| 3467 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 3468 | cmd->scmd->result = |
| 3469 | (DID_ERROR << 16) | hdr->scsi_status; |
| 3470 | break; |
| 3471 | |
| 3472 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 3473 | |
| 3474 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 3475 | |
| 3476 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 3477 | memset(cmd->scmd->sense_buffer, 0, |
| 3478 | SCSI_SENSE_BUFFERSIZE); |
| 3479 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 3480 | hdr->sense_len); |
| 3481 | |
| 3482 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 3483 | } |
| 3484 | |
| 3485 | break; |
| 3486 | |
| 3487 | case MFI_STAT_LD_OFFLINE: |
| 3488 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 3489 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 3490 | break; |
| 3491 | |
| 3492 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3493 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "MFI FW status %#x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3494 | hdr->cmd_status); |
| 3495 | cmd->scmd->result = DID_ERROR << 16; |
| 3496 | break; |
| 3497 | } |
| 3498 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 3499 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3500 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 3501 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3502 | cmd->scmd->scsi_done(cmd->scmd); |
| 3503 | megasas_return_cmd(instance, cmd); |
| 3504 | |
| 3505 | break; |
| 3506 | |
| 3507 | case MFI_CMD_SMP: |
| 3508 | case MFI_CMD_STP: |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 3509 | case MFI_CMD_NVME: |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 3510 | case MFI_CMD_TOOLBOX: |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3511 | megasas_complete_int_cmd(instance, cmd); |
| 3512 | break; |
| 3513 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3514 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3515 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3516 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3517 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 3518 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3519 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3520 | spin_lock_irqsave(instance->host->host_lock, flags); |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3521 | status = cmd->frame->hdr.cmd_status; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3522 | instance->map_update_cmd = NULL; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3523 | if (status != MFI_STAT_OK) { |
| 3524 | if (status != MFI_STAT_NOT_FOUND) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3525 | dev_warn(&instance->pdev->dev, "map syncfailed, status = 0x%x\n", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3526 | cmd->frame->hdr.cmd_status); |
| 3527 | else { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3528 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3529 | spin_unlock_irqrestore( |
| 3530 | instance->host->host_lock, |
| 3531 | flags); |
| 3532 | break; |
| 3533 | } |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3534 | } |
| 3535 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3536 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3537 | |
| 3538 | /* |
| 3539 | * Set fast path IO to ZERO. |
| 3540 | * Validate Map will set proper value. |
| 3541 | * Meanwhile all IOs will go as LD IO. |
| 3542 | */ |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3543 | if (status == MFI_STAT_OK && |
| 3544 | (MR_ValidateMapInfo(instance, (instance->map_id + 1)))) { |
| 3545 | instance->map_id++; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3546 | fusion->fast_path_io = 1; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3547 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3548 | fusion->fast_path_io = 0; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 3549 | } |
| 3550 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3551 | megasas_sync_map_info(instance); |
| 3552 | spin_unlock_irqrestore(instance->host->host_lock, |
| 3553 | flags); |
| 3554 | break; |
| 3555 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3556 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 3557 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 3558 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 3559 | megasas_poll_wait_aen = 0; |
| 3560 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 3561 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3562 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3563 | /* FW has an updated PD sequence */ |
| 3564 | if ((opcode == MR_DCMD_SYSTEM_PD_MAP_GET_INFO) && |
| 3565 | (cmd->frame->dcmd.mbox.b[0] == 1)) { |
| 3566 | |
| 3567 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 3568 | status = cmd->frame->hdr.cmd_status; |
| 3569 | instance->jbod_seq_cmd = NULL; |
| 3570 | megasas_return_cmd(instance, cmd); |
| 3571 | |
| 3572 | if (status == MFI_STAT_OK) { |
| 3573 | instance->pd_seq_map_id++; |
| 3574 | /* Re-register a pd sync seq num cmd */ |
| 3575 | if (megasas_sync_pd_seq_num(instance, true)) |
| 3576 | instance->use_seqnum_jbod_fp = false; |
| 3577 | } else |
| 3578 | instance->use_seqnum_jbod_fp = false; |
| 3579 | |
| 3580 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 3581 | break; |
| 3582 | } |
| 3583 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3584 | /* |
| 3585 | * See if got an event notification |
| 3586 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3587 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3588 | megasas_service_aen(instance, cmd); |
| 3589 | else |
| 3590 | megasas_complete_int_cmd(instance, cmd); |
| 3591 | |
| 3592 | break; |
| 3593 | |
| 3594 | case MFI_CMD_ABORT: |
| 3595 | /* |
| 3596 | * Cmd issued to abort another cmd returned |
| 3597 | */ |
| 3598 | megasas_complete_abort(instance, cmd); |
| 3599 | break; |
| 3600 | |
| 3601 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3602 | dev_info(&instance->pdev->dev, "Unknown command completed! [0x%X]\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3603 | hdr->cmd); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 3604 | megasas_complete_int_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3605 | break; |
| 3606 | } |
| 3607 | } |
| 3608 | |
| 3609 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3610 | * megasas_issue_pending_cmds_again - issue all pending cmds |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3611 | * in FW again because of the fw reset |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3612 | * @instance: Adapter soft state |
| 3613 | */ |
| 3614 | static inline void |
| 3615 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3616 | { |
| 3617 | struct megasas_cmd *cmd; |
| 3618 | struct list_head clist_local; |
| 3619 | union megasas_evt_class_locale class_locale; |
| 3620 | unsigned long flags; |
| 3621 | u32 seq_num; |
| 3622 | |
| 3623 | INIT_LIST_HEAD(&clist_local); |
| 3624 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3625 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3626 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3627 | |
| 3628 | while (!list_empty(&clist_local)) { |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3629 | cmd = list_entry((&clist_local)->next, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3630 | struct megasas_cmd, list); |
| 3631 | list_del_init(&cmd->list); |
| 3632 | |
| 3633 | if (cmd->sync_cmd || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3634 | dev_notice(&instance->pdev->dev, "command %p, %p:%d" |
| 3635 | "detected to be pending while HBA reset\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3636 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3637 | |
| 3638 | cmd->retry_for_fw_reset++; |
| 3639 | |
| 3640 | if (cmd->retry_for_fw_reset == 3) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3641 | dev_notice(&instance->pdev->dev, "cmd %p, %p:%d" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3642 | "was tried multiple times during reset." |
| 3643 | "Shutting down the HBA\n", |
| 3644 | cmd, cmd->scmd, cmd->sync_cmd); |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3645 | instance->instancet->disable_intr(instance); |
| 3646 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3647 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3648 | return; |
| 3649 | } |
| 3650 | } |
| 3651 | |
| 3652 | if (cmd->sync_cmd == 1) { |
| 3653 | if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3654 | dev_notice(&instance->pdev->dev, "unexpected" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3655 | "cmd attached to internal command!\n"); |
| 3656 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3657 | dev_notice(&instance->pdev->dev, "%p synchronous cmd" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3658 | "on the internal reset queue," |
| 3659 | "issue it again.\n", cmd); |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 3660 | cmd->cmd_status_drv = MFI_STAT_INVALID_STATUS; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3661 | instance->instancet->fire_cmd(instance, |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3662 | cmd->frame_phys_addr, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3663 | 0, instance->reg_set); |
| 3664 | } else if (cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3665 | dev_notice(&instance->pdev->dev, "%p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3666 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3667 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3668 | |
| 3669 | atomic_inc(&instance->fw_outstanding); |
| 3670 | instance->instancet->fire_cmd(instance, |
| 3671 | cmd->frame_phys_addr, |
| 3672 | cmd->frame_count-1, instance->reg_set); |
| 3673 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3674 | dev_notice(&instance->pdev->dev, "%p unexpected cmd on the" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3675 | "internal reset defer list while re-issue!!\n", |
| 3676 | cmd); |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | if (instance->aen_cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3681 | dev_notice(&instance->pdev->dev, "aen_cmd in def process\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3682 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3683 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3684 | instance->aen_cmd = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3685 | } |
| 3686 | |
| 3687 | /* |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3688 | * Initiate AEN (Asynchronous Event Notification) |
| 3689 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3690 | seq_num = instance->last_seq_num; |
| 3691 | class_locale.members.reserved = 0; |
| 3692 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3693 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3694 | |
| 3695 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3696 | } |
| 3697 | |
| 3698 | /** |
| 3699 | * Move the internal reset pending commands to a deferred queue. |
| 3700 | * |
| 3701 | * We move the commands pending at internal reset time to a |
| 3702 | * pending queue. This queue would be flushed after successful |
| 3703 | * completion of the internal reset sequence. if the internal reset |
| 3704 | * did not complete in time, the kernel reset handler would flush |
| 3705 | * these commands. |
| 3706 | **/ |
| 3707 | static void |
| 3708 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3709 | { |
| 3710 | struct megasas_cmd *cmd; |
| 3711 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 3712 | u16 max_cmd = instance->max_fw_cmds; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3713 | u32 defer_index; |
| 3714 | unsigned long flags; |
| 3715 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3716 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3717 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3718 | for (i = 0; i < max_cmd; i++) { |
| 3719 | cmd = instance->cmd_list[i]; |
| 3720 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3721 | dev_notice(&instance->pdev->dev, "moving cmd[%d]:%p:%d:%p" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3722 | "on the defer queue as internal\n", |
| 3723 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3724 | |
| 3725 | if (!list_empty(&cmd->list)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3726 | dev_notice(&instance->pdev->dev, "ERROR while" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3727 | " moving this cmd:%p, %d %p, it was" |
| 3728 | "discovered on some list?\n", |
| 3729 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3730 | |
| 3731 | list_del_init(&cmd->list); |
| 3732 | } |
| 3733 | defer_index++; |
| 3734 | list_add_tail(&cmd->list, |
| 3735 | &instance->internal_reset_pending_q); |
| 3736 | } |
| 3737 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3738 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | |
| 3742 | static void |
| 3743 | process_fw_state_change_wq(struct work_struct *work) |
| 3744 | { |
| 3745 | struct megasas_instance *instance = |
| 3746 | container_of(work, struct megasas_instance, work_init); |
| 3747 | u32 wait; |
| 3748 | unsigned long flags; |
| 3749 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3750 | if (atomic_read(&instance->adprecovery) != MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3751 | dev_notice(&instance->pdev->dev, "error, recovery st %x\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3752 | atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3753 | return ; |
| 3754 | } |
| 3755 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3756 | if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3757 | dev_notice(&instance->pdev->dev, "FW detected to be in fault" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3758 | "state, restarting it...\n"); |
| 3759 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3760 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3761 | atomic_set(&instance->fw_outstanding, 0); |
| 3762 | |
| 3763 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3764 | instance->instancet->adp_reset(instance, instance->reg_set); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3765 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3766 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3767 | dev_notice(&instance->pdev->dev, "FW restarted successfully," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3768 | "initiating next stage...\n"); |
| 3769 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3770 | dev_notice(&instance->pdev->dev, "HBA recovery state machine," |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3771 | "state 2 starting...\n"); |
| 3772 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3773 | /* waiting for about 20 second before start the second init */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3774 | for (wait = 0; wait < 30; wait++) { |
| 3775 | msleep(1000); |
| 3776 | } |
| 3777 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3778 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3779 | dev_notice(&instance->pdev->dev, "adapter not ready\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3780 | |
Sumit.Saxena@avagotech.com | c8dd61e | 2015-01-05 20:06:18 +0530 | [diff] [blame] | 3781 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3782 | megaraid_sas_kill_hba(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3783 | return ; |
| 3784 | } |
| 3785 | |
| 3786 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3787 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3788 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3789 | ) { |
| 3790 | *instance->consumer = *instance->producer; |
| 3791 | } else { |
| 3792 | *instance->consumer = 0; |
| 3793 | *instance->producer = 0; |
| 3794 | } |
| 3795 | |
| 3796 | megasas_issue_init_mfi(instance); |
| 3797 | |
| 3798 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3799 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3800 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3801 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3802 | |
| 3803 | megasas_issue_pending_cmds_again(instance); |
| 3804 | instance->issuepend_done = 1; |
| 3805 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3809 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3810 | * @instance: Adapter soft state |
| 3811 | * @alt_status: Alternate status to be returned to |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3812 | * SCSI mid-layer instead of the status |
| 3813 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3814 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3815 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3816 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3817 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3818 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3819 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3820 | u32 mfiStatus; |
| 3821 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3822 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3823 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3824 | instance->reg_set)) == 1) { |
| 3825 | return IRQ_HANDLED; |
| 3826 | } |
| 3827 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3828 | mfiStatus = instance->instancet->clear_intr(instance); |
| 3829 | if (mfiStatus == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3830 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3831 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3832 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | instance->mfiStatus = mfiStatus; |
| 3836 | |
| 3837 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3838 | fw_state = instance->instancet->read_fw_status_reg( |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3839 | instance) & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3840 | |
| 3841 | if (fw_state != MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3842 | dev_notice(&instance->pdev->dev, "fw state:%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3843 | fw_state); |
| 3844 | } |
| 3845 | |
| 3846 | if ((fw_state == MFI_STATE_FAULT) && |
| 3847 | (instance->disableOnlineCtrlReset == 0)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3848 | dev_notice(&instance->pdev->dev, "wait adp restart\n"); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3849 | |
| 3850 | if ((instance->pdev->device == |
| 3851 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3852 | (instance->pdev->device == |
| 3853 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3854 | (instance->pdev->device == |
| 3855 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3856 | |
| 3857 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3858 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3859 | } |
| 3860 | |
| 3861 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3862 | instance->instancet->disable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3863 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3864 | instance->issuepend_done = 0; |
| 3865 | |
| 3866 | atomic_set(&instance->fw_outstanding, 0); |
| 3867 | megasas_internal_reset_defer_cmds(instance); |
| 3868 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3869 | dev_notice(&instance->pdev->dev, "fwState=%x, stage:%d\n", |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3870 | fw_state, atomic_read(&instance->adprecovery)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3871 | |
| 3872 | schedule_work(&instance->work_init); |
| 3873 | return IRQ_HANDLED; |
| 3874 | |
| 3875 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3876 | dev_notice(&instance->pdev->dev, "fwstate:%x, dis_OCR=%x\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3877 | fw_state, instance->disableOnlineCtrlReset); |
| 3878 | } |
| 3879 | } |
| 3880 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3881 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3882 | return IRQ_HANDLED; |
| 3883 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3884 | /** |
| 3885 | * megasas_isr - isr entry point |
| 3886 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3887 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3888 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3889 | struct megasas_irq_context *irq_context = devp; |
| 3890 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3891 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3892 | irqreturn_t rc; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3893 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3894 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3895 | return IRQ_HANDLED; |
| 3896 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3897 | spin_lock_irqsave(&instance->hba_lock, flags); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 3898 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3899 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3900 | |
| 3901 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | /** |
| 3905 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3906 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3907 | * |
| 3908 | * During the initialization, FW passes can potentially be in any one of |
| 3909 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3910 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3911 | * has to wait for the ready state. |
| 3912 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3913 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3914 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3915 | { |
| 3916 | int i; |
| 3917 | u8 max_wait; |
| 3918 | u32 fw_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3919 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3920 | |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 3921 | abs_state = instance->instancet->read_fw_status_reg(instance); |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3922 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3923 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3924 | if (fw_state != MFI_STATE_READY) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3925 | dev_info(&instance->pdev->dev, "Waiting for FW to come to ready" |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3926 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3927 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3928 | while (fw_state != MFI_STATE_READY) { |
| 3929 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3930 | switch (fw_state) { |
| 3931 | |
| 3932 | case MFI_STATE_FAULT: |
Shivasharan S | b666134 | 2019-05-07 10:05:44 -0700 | [diff] [blame] | 3933 | dev_printk(KERN_ERR, &instance->pdev->dev, |
| 3934 | "FW in FAULT state, Fault code:0x%x subcode:0x%x func:%s\n", |
| 3935 | abs_state & MFI_STATE_FAULT_CODE, |
| 3936 | abs_state & MFI_STATE_FAULT_SUBCODE, __func__); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3937 | if (ocr) { |
| 3938 | max_wait = MEGASAS_RESET_WAIT_TIME; |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3939 | break; |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame] | 3940 | } else { |
| 3941 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n"); |
| 3942 | megasas_dump_reg_set(instance->reg_set); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3943 | return -ENODEV; |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame] | 3944 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3945 | |
| 3946 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3947 | /* |
| 3948 | * Set the CLR bit in inbound doorbell |
| 3949 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3950 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3951 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3952 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3953 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3954 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3955 | writel( |
| 3956 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3957 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3958 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3959 | writel( |
| 3960 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3961 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3962 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3963 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3964 | break; |
| 3965 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3966 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3967 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3968 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3969 | (instance->pdev->device == |
| 3970 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3971 | (instance->adapter_type != MFI_SERIES)) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3972 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3973 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3974 | else |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3975 | writel(MFI_INIT_HOTPLUG, |
| 3976 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3977 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3978 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3979 | break; |
| 3980 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3981 | case MFI_STATE_OPERATIONAL: |
| 3982 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3983 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3984 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3985 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3986 | if ((instance->pdev->device == |
| 3987 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3988 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3989 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3990 | (instance->adapter_type != MFI_SERIES)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3991 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3992 | &instance->reg_set->doorbell); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 3993 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 3994 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3995 | for (i = 0; i < (10 * 1000); i += 20) { |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 3996 | if (megasas_readl( |
| 3997 | instance, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3998 | &instance-> |
| 3999 | reg_set-> |
| 4000 | doorbell) & 1) |
| 4001 | msleep(20); |
| 4002 | else |
| 4003 | break; |
| 4004 | } |
| 4005 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 4006 | } else |
| 4007 | writel(MFI_RESET_FLAGS, |
| 4008 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4009 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4010 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4011 | break; |
| 4012 | |
| 4013 | case MFI_STATE_UNDEFINED: |
| 4014 | /* |
| 4015 | * This state should not last for more than 2 seconds |
| 4016 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4017 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4018 | break; |
| 4019 | |
| 4020 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4021 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4022 | break; |
| 4023 | |
| 4024 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4025 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4026 | break; |
| 4027 | |
| 4028 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4029 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4030 | break; |
| 4031 | |
| 4032 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4033 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4034 | break; |
| 4035 | |
| 4036 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4037 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4038 | break; |
| 4039 | |
| 4040 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4041 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Unknown state 0x%x\n", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4042 | fw_state); |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame] | 4043 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n"); |
| 4044 | megasas_dump_reg_set(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4045 | return -ENODEV; |
| 4046 | } |
| 4047 | |
| 4048 | /* |
| 4049 | * The cur_state should not last for more than max_wait secs |
| 4050 | */ |
Steve Sistare | 31b6a05 | 2019-03-01 06:46:28 -0800 | [diff] [blame] | 4051 | for (i = 0; i < max_wait * 50; i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 4052 | curr_abs_state = instance->instancet-> |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 4053 | read_fw_status_reg(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4054 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4055 | if (abs_state == curr_abs_state) { |
Steve Sistare | 31b6a05 | 2019-03-01 06:46:28 -0800 | [diff] [blame] | 4056 | msleep(20); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4057 | } else |
| 4058 | break; |
| 4059 | } |
| 4060 | |
| 4061 | /* |
| 4062 | * Return error if fw_state hasn't changed after max_wait |
| 4063 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4064 | if (curr_abs_state == abs_state) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4065 | 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] | 4066 | "in %d secs\n", fw_state, max_wait); |
Shivasharan S | 3d1d9eb | 2019-05-07 10:05:41 -0700 | [diff] [blame] | 4067 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "System Register set:\n"); |
| 4068 | megasas_dump_reg_set(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4069 | return -ENODEV; |
| 4070 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 4071 | |
| 4072 | abs_state = curr_abs_state; |
| 4073 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4074 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4075 | dev_info(&instance->pdev->dev, "FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4076 | |
| 4077 | return 0; |
| 4078 | } |
| 4079 | |
| 4080 | /** |
| 4081 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 4082 | * @instance: Adapter soft state |
| 4083 | */ |
| 4084 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 4085 | { |
| 4086 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4087 | u16 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4088 | struct megasas_cmd *cmd; |
| 4089 | |
| 4090 | if (!instance->frame_dma_pool) |
| 4091 | return; |
| 4092 | |
| 4093 | /* |
| 4094 | * Return all frames to pool |
| 4095 | */ |
| 4096 | for (i = 0; i < max_cmd; i++) { |
| 4097 | |
| 4098 | cmd = instance->cmd_list[i]; |
| 4099 | |
| 4100 | if (cmd->frame) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4101 | dma_pool_free(instance->frame_dma_pool, cmd->frame, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4102 | cmd->frame_phys_addr); |
| 4103 | |
| 4104 | if (cmd->sense) |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4105 | dma_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4106 | cmd->sense_phys_addr); |
| 4107 | } |
| 4108 | |
| 4109 | /* |
| 4110 | * Now destroy the pool itself |
| 4111 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4112 | dma_pool_destroy(instance->frame_dma_pool); |
| 4113 | dma_pool_destroy(instance->sense_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4114 | |
| 4115 | instance->frame_dma_pool = NULL; |
| 4116 | instance->sense_dma_pool = NULL; |
| 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 4121 | * @instance: Adapter soft state |
| 4122 | * |
| 4123 | * Each command packet has an embedded DMA memory buffer that is used for |
| 4124 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 4125 | * function creates those DMA memory buffers for each command packet by using |
| 4126 | * PCI pool facility. |
| 4127 | */ |
| 4128 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 4129 | { |
| 4130 | int i; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4131 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4132 | u32 frame_count; |
| 4133 | struct megasas_cmd *cmd; |
| 4134 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4135 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4136 | |
| 4137 | /* |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 4138 | * For MFI controllers. |
| 4139 | * max_num_sge = 60 |
| 4140 | * max_sge_sz = 16 byte (sizeof megasas_sge_skinny) |
| 4141 | * Total 960 byte (15 MFI frame of 64 byte) |
| 4142 | * |
| 4143 | * Fusion adapter require only 3 extra frame. |
| 4144 | * max_num_sge = 16 (defined as MAX_IOCTL_SGE) |
| 4145 | * max_sge_sz = 12 byte (sizeof megasas_sge64) |
| 4146 | * Total 192 byte (3 MFI frame of 64 byte) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4147 | */ |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4148 | frame_count = (instance->adapter_type == MFI_SERIES) ? |
| 4149 | (15 + 1) : (3 + 1); |
Shivasharan S | 21c3400 | 2017-02-10 00:59:28 -0800 | [diff] [blame] | 4150 | instance->mfi_frame_size = MEGAMFI_FRAME_SIZE * frame_count; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4151 | /* |
| 4152 | * Use DMA pool facility provided by PCI layer |
| 4153 | */ |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4154 | instance->frame_dma_pool = dma_pool_create("megasas frame pool", |
| 4155 | &instance->pdev->dev, |
| 4156 | instance->mfi_frame_size, 256, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4157 | |
| 4158 | if (!instance->frame_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 frame pool\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4160 | return -ENOMEM; |
| 4161 | } |
| 4162 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4163 | instance->sense_dma_pool = dma_pool_create("megasas sense pool", |
| 4164 | &instance->pdev->dev, 128, |
| 4165 | 4, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4166 | |
| 4167 | if (!instance->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4168 | 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] | 4169 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4170 | dma_pool_destroy(instance->frame_dma_pool); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4171 | instance->frame_dma_pool = NULL; |
| 4172 | |
| 4173 | return -ENOMEM; |
| 4174 | } |
| 4175 | |
| 4176 | /* |
| 4177 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 4178 | * By making cmd->index as the context instead of the &cmd, we can |
| 4179 | * always use 32bit context regardless of the architecture |
| 4180 | */ |
| 4181 | for (i = 0; i < max_cmd; i++) { |
| 4182 | |
| 4183 | cmd = instance->cmd_list[i]; |
| 4184 | |
Souptick Joarder | 61b142a | 2018-02-15 21:55:06 +0530 | [diff] [blame] | 4185 | cmd->frame = dma_pool_zalloc(instance->frame_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4186 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 4187 | |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4188 | cmd->sense = dma_pool_alloc(instance->sense_dma_pool, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4189 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 4190 | |
| 4191 | /* |
| 4192 | * megasas_teardown_frame_pool() takes care of freeing |
| 4193 | * whatever has been allocated |
| 4194 | */ |
| 4195 | if (!cmd->frame || !cmd->sense) { |
Romain Perier | fc69d86 | 2017-07-06 10:13:06 +0200 | [diff] [blame] | 4196 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "dma_pool_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4197 | megasas_teardown_frame_pool(instance); |
| 4198 | return -ENOMEM; |
| 4199 | } |
| 4200 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4201 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4202 | cmd->frame->io.pad_0 = 0; |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4203 | if ((instance->adapter_type == MFI_SERIES) && reset_devices) |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 4204 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | return 0; |
| 4208 | } |
| 4209 | |
| 4210 | /** |
| 4211 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 4212 | * @instance: Adapter soft state |
| 4213 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4214 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4215 | { |
| 4216 | int i; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 4217 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4218 | /* First free the MFI frame pool */ |
| 4219 | megasas_teardown_frame_pool(instance); |
| 4220 | |
| 4221 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4222 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 4223 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4224 | kfree(instance->cmd_list[i]); |
| 4225 | |
| 4226 | /* Free the cmd_list buffer itself */ |
| 4227 | kfree(instance->cmd_list); |
| 4228 | instance->cmd_list = NULL; |
| 4229 | |
| 4230 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 4231 | } |
| 4232 | |
| 4233 | /** |
| 4234 | * megasas_alloc_cmds - Allocates the command packets |
| 4235 | * @instance: Adapter soft state |
| 4236 | * |
| 4237 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 4238 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 4239 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 4240 | * the FW. |
| 4241 | * |
| 4242 | * Each frame has a 32-bit field called context (tag). This context is used |
| 4243 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 4244 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 4245 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 4246 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 4247 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 4248 | * This array is used only to look up the megasas_cmd given the context. The |
| 4249 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 4250 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4251 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4252 | { |
| 4253 | int i; |
| 4254 | int j; |
Shivasharan S | 50b7f5a | 2017-02-10 00:59:25 -0800 | [diff] [blame] | 4255 | u16 max_cmd; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4256 | struct megasas_cmd *cmd; |
| 4257 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4258 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4259 | |
| 4260 | /* |
| 4261 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 4262 | * Allocate the dynamic array first and then allocate individual |
| 4263 | * commands. |
| 4264 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 4265 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4266 | |
| 4267 | if (!instance->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4268 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4269 | return -ENOMEM; |
| 4270 | } |
| 4271 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4272 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4273 | |
| 4274 | for (i = 0; i < max_cmd; i++) { |
| 4275 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 4276 | GFP_KERNEL); |
| 4277 | |
| 4278 | if (!instance->cmd_list[i]) { |
| 4279 | |
| 4280 | for (j = 0; j < i; j++) |
| 4281 | kfree(instance->cmd_list[j]); |
| 4282 | |
| 4283 | kfree(instance->cmd_list); |
| 4284 | instance->cmd_list = NULL; |
| 4285 | |
| 4286 | return -ENOMEM; |
| 4287 | } |
| 4288 | } |
| 4289 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4290 | for (i = 0; i < max_cmd; i++) { |
| 4291 | cmd = instance->cmd_list[i]; |
| 4292 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 4293 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4294 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4295 | cmd->instance = instance; |
| 4296 | |
| 4297 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 4298 | } |
| 4299 | |
| 4300 | /* |
| 4301 | * Create a frame pool and assign one frame to each cmd |
| 4302 | */ |
| 4303 | if (megasas_create_frame_pool(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4304 | 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] | 4305 | megasas_free_cmds(instance); |
Jason Yan | bcf3b67 | 2019-02-15 19:50:27 +0800 | [diff] [blame] | 4306 | return -ENOMEM; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4307 | } |
| 4308 | |
| 4309 | return 0; |
| 4310 | } |
| 4311 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4312 | /* |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4313 | * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state. |
| 4314 | * @instance: Adapter soft state |
| 4315 | * |
| 4316 | * Return 0 for only Fusion adapter, if driver load/unload is not in progress |
| 4317 | * or FW is not under OCR. |
| 4318 | */ |
| 4319 | inline int |
| 4320 | dcmd_timeout_ocr_possible(struct megasas_instance *instance) { |
| 4321 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4322 | if (instance->adapter_type == MFI_SERIES) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4323 | return KILL_ADAPTER; |
| 4324 | else if (instance->unload || |
| 4325 | test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) |
| 4326 | return IGNORE_TIMEOUT; |
| 4327 | else |
| 4328 | return INITIATE_OCR; |
| 4329 | } |
| 4330 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4331 | static void |
| 4332 | megasas_get_pd_info(struct megasas_instance *instance, struct scsi_device *sdev) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4333 | { |
| 4334 | int ret; |
| 4335 | struct megasas_cmd *cmd; |
| 4336 | struct megasas_dcmd_frame *dcmd; |
| 4337 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4338 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 4339 | u16 device_id = 0; |
| 4340 | |
| 4341 | device_id = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + sdev->id; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4342 | cmd = megasas_get_cmd(instance); |
| 4343 | |
| 4344 | if (!cmd) { |
| 4345 | dev_err(&instance->pdev->dev, "Failed to get cmd %s\n", __func__); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4346 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | dcmd = &cmd->frame->dcmd; |
| 4350 | |
| 4351 | memset(instance->pd_info, 0, sizeof(*instance->pd_info)); |
| 4352 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4353 | |
| 4354 | dcmd->mbox.s[0] = cpu_to_le16(device_id); |
| 4355 | dcmd->cmd = MFI_CMD_DCMD; |
| 4356 | dcmd->cmd_status = 0xFF; |
| 4357 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4358 | dcmd->flags = MFI_FRAME_DIR_READ; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4359 | dcmd->timeout = 0; |
| 4360 | dcmd->pad_0 = 0; |
| 4361 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_PD_INFO)); |
| 4362 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_GET_INFO); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4363 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4364 | megasas_set_dma_settings(instance, dcmd, instance->pd_info_h, |
| 4365 | sizeof(struct MR_PD_INFO)); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4366 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4367 | if ((instance->adapter_type != MFI_SERIES) && |
| 4368 | !instance->mask_interrupts) |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4369 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 4370 | else |
| 4371 | ret = megasas_issue_polled(instance, cmd); |
| 4372 | |
| 4373 | switch (ret) { |
| 4374 | case DCMD_SUCCESS: |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4375 | mr_device_priv_data = sdev->hostdata; |
| 4376 | le16_to_cpus((u16 *)&instance->pd_info->state.ddf.pdType); |
| 4377 | mr_device_priv_data->interface_type = |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4378 | instance->pd_info->state.ddf.pdType.intf; |
| 4379 | break; |
| 4380 | |
| 4381 | case DCMD_TIMEOUT: |
| 4382 | |
| 4383 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4384 | case INITIATE_OCR: |
| 4385 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 4386 | mutex_unlock(&instance->reset_mutex); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4387 | megasas_reset_fusion(instance->host, |
| 4388 | MFI_IO_TIMEOUT_OCR); |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 4389 | mutex_lock(&instance->reset_mutex); |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4390 | break; |
| 4391 | case KILL_ADAPTER: |
| 4392 | megaraid_sas_kill_hba(instance); |
| 4393 | break; |
| 4394 | case IGNORE_TIMEOUT: |
| 4395 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4396 | __func__, __LINE__); |
| 4397 | break; |
| 4398 | } |
| 4399 | |
| 4400 | break; |
| 4401 | } |
| 4402 | |
| 4403 | if (ret != DCMD_TIMEOUT) |
| 4404 | megasas_return_cmd(instance, cmd); |
| 4405 | |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4406 | return; |
Sumit Saxena | 2216c30 | 2016-01-28 21:04:26 +0530 | [diff] [blame] | 4407 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4408 | /* |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4409 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 4410 | * @instance: Adapter soft state |
| 4411 | * @pd_list: pd_list structure |
| 4412 | * |
| 4413 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4414 | * list structure. This information is mainly used to find out SYSTEM |
| 4415 | * supported by the FW. |
| 4416 | */ |
| 4417 | static int |
| 4418 | megasas_get_pd_list(struct megasas_instance *instance) |
| 4419 | { |
| 4420 | int ret = 0, pd_index = 0; |
| 4421 | struct megasas_cmd *cmd; |
| 4422 | struct megasas_dcmd_frame *dcmd; |
| 4423 | struct MR_PD_LIST *ci; |
| 4424 | struct MR_PD_ADDRESS *pd_addr; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4425 | |
Sumit Saxena | d908316 | 2016-07-08 03:30:16 -0700 | [diff] [blame] | 4426 | if (instance->pd_list_not_supported) { |
| 4427 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4428 | "not supported by firmware\n"); |
| 4429 | return ret; |
| 4430 | } |
| 4431 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4432 | ci = instance->pd_list_buf; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4433 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4434 | cmd = megasas_get_cmd(instance); |
| 4435 | |
| 4436 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4437 | 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] | 4438 | return -ENOMEM; |
| 4439 | } |
| 4440 | |
| 4441 | dcmd = &cmd->frame->dcmd; |
| 4442 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4443 | memset(ci, 0, sizeof(*ci)); |
| 4444 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4445 | |
| 4446 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 4447 | dcmd->mbox.b[1] = 0; |
| 4448 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4449 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4450 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4451 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4452 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4453 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4454 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 4455 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4456 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4457 | megasas_set_dma_settings(instance, dcmd, instance->pd_list_buf_h, |
| 4458 | (MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST))); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4459 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4460 | if ((instance->adapter_type != MFI_SERIES) && |
| 4461 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4462 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4463 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4464 | else |
| 4465 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4466 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4467 | switch (ret) { |
| 4468 | case DCMD_FAILED: |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4469 | dev_info(&instance->pdev->dev, "MR_DCMD_PD_LIST_QUERY " |
| 4470 | "failed/not supported by firmware\n"); |
| 4471 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4472 | if (instance->adapter_type != MFI_SERIES) |
Sumit Saxena | 3084558 | 2016-03-10 02:14:37 -0800 | [diff] [blame] | 4473 | megaraid_sas_kill_hba(instance); |
| 4474 | else |
| 4475 | instance->pd_list_not_supported = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4476 | break; |
| 4477 | case DCMD_TIMEOUT: |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4478 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4479 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4480 | case INITIATE_OCR: |
| 4481 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4482 | /* |
| 4483 | * DCMD failed from AEN path. |
| 4484 | * AEN path already hold reset_mutex to avoid PCI access |
| 4485 | * while OCR is in progress. |
| 4486 | */ |
| 4487 | mutex_unlock(&instance->reset_mutex); |
| 4488 | megasas_reset_fusion(instance->host, |
| 4489 | MFI_IO_TIMEOUT_OCR); |
| 4490 | mutex_lock(&instance->reset_mutex); |
| 4491 | break; |
| 4492 | case KILL_ADAPTER: |
| 4493 | megaraid_sas_kill_hba(instance); |
| 4494 | break; |
| 4495 | case IGNORE_TIMEOUT: |
| 4496 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d \n", |
| 4497 | __func__, __LINE__); |
| 4498 | break; |
| 4499 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4500 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4501 | break; |
| 4502 | |
| 4503 | case DCMD_SUCCESS: |
| 4504 | pd_addr = ci->addr; |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4505 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4506 | dev_info(&instance->pdev->dev, "%s, sysPD count: 0x%x\n", |
| 4507 | __func__, le32_to_cpu(ci->count)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4508 | |
| 4509 | if ((le32_to_cpu(ci->count) > |
| 4510 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) |
| 4511 | break; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4512 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4513 | memset(instance->local_pd_list, 0, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4514 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4515 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4516 | 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] | 4517 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4518 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4519 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4520 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4521 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4522 | MR_PD_STATE_SYSTEM; |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4523 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4524 | dev_info(&instance->pdev->dev, |
| 4525 | "PD%d: targetID: 0x%03x deviceType:0x%x\n", |
| 4526 | pd_index, le16_to_cpu(pd_addr->deviceId), |
| 4527 | pd_addr->scsiDevType); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4528 | pd_addr++; |
| 4529 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4530 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 4531 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4532 | sizeof(instance->pd_list)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4533 | break; |
| 4534 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4535 | } |
| 4536 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4537 | if (ret != DCMD_TIMEOUT) |
| 4538 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4539 | |
| 4540 | return ret; |
| 4541 | } |
| 4542 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4543 | /* |
| 4544 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 4545 | * @instance: Adapter soft state |
| 4546 | * @ld_list: ld_list structure |
| 4547 | * |
| 4548 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4549 | * list structure. This information is mainly used to find out SYSTEM |
| 4550 | * supported by the FW. |
| 4551 | */ |
| 4552 | static int |
| 4553 | megasas_get_ld_list(struct megasas_instance *instance) |
| 4554 | { |
| 4555 | int ret = 0, ld_index = 0, ids = 0; |
| 4556 | struct megasas_cmd *cmd; |
| 4557 | struct megasas_dcmd_frame *dcmd; |
| 4558 | struct MR_LD_LIST *ci; |
| 4559 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4560 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4561 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4562 | ci = instance->ld_list_buf; |
| 4563 | ci_h = instance->ld_list_buf_h; |
| 4564 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4565 | cmd = megasas_get_cmd(instance); |
| 4566 | |
| 4567 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4568 | 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] | 4569 | return -ENOMEM; |
| 4570 | } |
| 4571 | |
| 4572 | dcmd = &cmd->frame->dcmd; |
| 4573 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4574 | memset(ci, 0, sizeof(*ci)); |
| 4575 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4576 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4577 | if (instance->supportmax256vd) |
| 4578 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4579 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4580 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4581 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4582 | dcmd->flags = MFI_FRAME_DIR_READ; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4583 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4584 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 4585 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4586 | dcmd->pad_0 = 0; |
| 4587 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4588 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4589 | sizeof(struct MR_LD_LIST)); |
| 4590 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4591 | if ((instance->adapter_type != MFI_SERIES) && |
| 4592 | !instance->mask_interrupts) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4593 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4594 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4595 | else |
| 4596 | ret = megasas_issue_polled(instance, cmd); |
| 4597 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4598 | ld_count = le32_to_cpu(ci->ldCount); |
| 4599 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4600 | switch (ret) { |
| 4601 | case DCMD_FAILED: |
| 4602 | megaraid_sas_kill_hba(instance); |
| 4603 | break; |
| 4604 | case DCMD_TIMEOUT: |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4605 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4606 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4607 | case INITIATE_OCR: |
| 4608 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4609 | /* |
| 4610 | * DCMD failed from AEN path. |
| 4611 | * AEN path already hold reset_mutex to avoid PCI access |
| 4612 | * while OCR is in progress. |
| 4613 | */ |
| 4614 | mutex_unlock(&instance->reset_mutex); |
| 4615 | megasas_reset_fusion(instance->host, |
| 4616 | MFI_IO_TIMEOUT_OCR); |
| 4617 | mutex_lock(&instance->reset_mutex); |
| 4618 | break; |
| 4619 | case KILL_ADAPTER: |
| 4620 | megaraid_sas_kill_hba(instance); |
| 4621 | break; |
| 4622 | case IGNORE_TIMEOUT: |
| 4623 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4624 | __func__, __LINE__); |
| 4625 | break; |
| 4626 | } |
| 4627 | |
| 4628 | break; |
| 4629 | |
| 4630 | case DCMD_SUCCESS: |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4631 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4632 | dev_info(&instance->pdev->dev, "%s, LD count: 0x%x\n", |
| 4633 | __func__, ld_count); |
| 4634 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4635 | if (ld_count > instance->fw_supported_vd_count) |
| 4636 | break; |
| 4637 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4638 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4639 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4640 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4641 | if (ci->ldList[ld_index].state != 0) { |
| 4642 | ids = ci->ldList[ld_index].ref.targetId; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4643 | instance->ld_ids[ids] = ci->ldList[ld_index].ref.targetId; |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4644 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4645 | dev_info(&instance->pdev->dev, |
| 4646 | "LD%d: targetID: 0x%03x\n", |
| 4647 | ld_index, ids); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4648 | } |
| 4649 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4650 | |
| 4651 | break; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4652 | } |
| 4653 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4654 | if (ret != DCMD_TIMEOUT) |
| 4655 | megasas_return_cmd(instance, cmd); |
| 4656 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4657 | return ret; |
| 4658 | } |
| 4659 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4660 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4661 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 4662 | * @instance: Adapter soft state |
| 4663 | * @ld_list: ld_list structure |
| 4664 | * |
| 4665 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 4666 | * list structure. This information is mainly used to find out SYSTEM |
| 4667 | * supported by the FW. |
| 4668 | */ |
| 4669 | static int |
| 4670 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 4671 | { |
| 4672 | int ret = 0, ld_index = 0, ids = 0; |
| 4673 | struct megasas_cmd *cmd; |
| 4674 | struct megasas_dcmd_frame *dcmd; |
| 4675 | struct MR_LD_TARGETID_LIST *ci; |
| 4676 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4677 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4678 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 4679 | ci = instance->ld_targetid_list_buf; |
| 4680 | ci_h = instance->ld_targetid_list_buf_h; |
| 4681 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4682 | cmd = megasas_get_cmd(instance); |
| 4683 | |
| 4684 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4685 | dev_warn(&instance->pdev->dev, |
| 4686 | "megasas_ld_list_query: Failed to get cmd\n"); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4687 | return -ENOMEM; |
| 4688 | } |
| 4689 | |
| 4690 | dcmd = &cmd->frame->dcmd; |
| 4691 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4692 | memset(ci, 0, sizeof(*ci)); |
| 4693 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4694 | |
| 4695 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4696 | if (instance->supportmax256vd) |
| 4697 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4698 | |
| 4699 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 4700 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4701 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4702 | dcmd->flags = MFI_FRAME_DIR_READ; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4703 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4704 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 4705 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4706 | dcmd->pad_0 = 0; |
| 4707 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 4708 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 4709 | sizeof(struct MR_LD_TARGETID_LIST)); |
| 4710 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 4711 | if ((instance->adapter_type != MFI_SERIES) && |
| 4712 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4713 | 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] | 4714 | else |
| 4715 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4716 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4717 | switch (ret) { |
| 4718 | case DCMD_FAILED: |
| 4719 | dev_info(&instance->pdev->dev, |
| 4720 | "DCMD not supported by firmware - %s %d\n", |
| 4721 | __func__, __LINE__); |
| 4722 | ret = megasas_get_ld_list(instance); |
| 4723 | break; |
| 4724 | case DCMD_TIMEOUT: |
| 4725 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4726 | case INITIATE_OCR: |
| 4727 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4728 | /* |
| 4729 | * DCMD failed from AEN path. |
| 4730 | * AEN path already hold reset_mutex to avoid PCI access |
| 4731 | * while OCR is in progress. |
| 4732 | */ |
| 4733 | mutex_unlock(&instance->reset_mutex); |
| 4734 | megasas_reset_fusion(instance->host, |
| 4735 | MFI_IO_TIMEOUT_OCR); |
| 4736 | mutex_lock(&instance->reset_mutex); |
| 4737 | break; |
| 4738 | case KILL_ADAPTER: |
| 4739 | megaraid_sas_kill_hba(instance); |
| 4740 | break; |
| 4741 | case IGNORE_TIMEOUT: |
| 4742 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4743 | __func__, __LINE__); |
| 4744 | break; |
| 4745 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4746 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4747 | break; |
| 4748 | case DCMD_SUCCESS: |
| 4749 | tgtid_count = le32_to_cpu(ci->count); |
| 4750 | |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4751 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4752 | dev_info(&instance->pdev->dev, "%s, LD count: 0x%x\n", |
| 4753 | __func__, tgtid_count); |
| 4754 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4755 | if ((tgtid_count > (instance->fw_supported_vd_count))) |
| 4756 | break; |
| 4757 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4758 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4759 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4760 | ids = ci->targetId[ld_index]; |
| 4761 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4762 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4763 | dev_info(&instance->pdev->dev, "LD%d: targetID: 0x%03x\n", |
| 4764 | ld_index, ci->targetId[ld_index]); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4767 | break; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4768 | } |
| 4769 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 4770 | if (ret != DCMD_TIMEOUT) |
| 4771 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4772 | |
| 4773 | return ret; |
| 4774 | } |
| 4775 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4776 | /** |
| 4777 | * dcmd.opcode - MR_DCMD_CTRL_DEVICE_LIST_GET |
| 4778 | * dcmd.mbox - reserved |
| 4779 | * dcmd.sge IN - ptr to return MR_HOST_DEVICE_LIST structure |
| 4780 | * Desc: This DCMD will return the combined device list |
| 4781 | * Status: MFI_STAT_OK - List returned successfully |
| 4782 | * MFI_STAT_INVALID_CMD - Firmware support for the feature has been |
| 4783 | * disabled |
| 4784 | * @instance: Adapter soft state |
| 4785 | * @is_probe: Driver probe check |
| 4786 | * Return: 0 if DCMD succeeded |
| 4787 | * non-zero if failed |
| 4788 | */ |
YueHaibing | 7c3f8ca | 2019-04-13 22:21:38 +0800 | [diff] [blame] | 4789 | static int |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4790 | megasas_host_device_list_query(struct megasas_instance *instance, |
| 4791 | bool is_probe) |
| 4792 | { |
| 4793 | int ret, i, target_id; |
| 4794 | struct megasas_cmd *cmd; |
| 4795 | struct megasas_dcmd_frame *dcmd; |
| 4796 | struct MR_HOST_DEVICE_LIST *ci; |
| 4797 | u32 count; |
| 4798 | dma_addr_t ci_h; |
| 4799 | |
| 4800 | ci = instance->host_device_list_buf; |
| 4801 | ci_h = instance->host_device_list_buf_h; |
| 4802 | |
| 4803 | cmd = megasas_get_cmd(instance); |
| 4804 | |
| 4805 | if (!cmd) { |
| 4806 | dev_warn(&instance->pdev->dev, |
| 4807 | "%s: failed to get cmd\n", |
| 4808 | __func__); |
| 4809 | return -ENOMEM; |
| 4810 | } |
| 4811 | |
| 4812 | dcmd = &cmd->frame->dcmd; |
| 4813 | |
| 4814 | memset(ci, 0, sizeof(*ci)); |
| 4815 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4816 | |
| 4817 | dcmd->mbox.b[0] = is_probe ? 0 : 1; |
| 4818 | dcmd->cmd = MFI_CMD_DCMD; |
| 4819 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
| 4820 | dcmd->sge_count = 1; |
| 4821 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 4822 | dcmd->timeout = 0; |
| 4823 | dcmd->pad_0 = 0; |
| 4824 | dcmd->data_xfer_len = cpu_to_le32(HOST_DEVICE_LIST_SZ); |
| 4825 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_DEVICE_LIST_GET); |
| 4826 | |
| 4827 | megasas_set_dma_settings(instance, dcmd, ci_h, HOST_DEVICE_LIST_SZ); |
| 4828 | |
| 4829 | if (!instance->mask_interrupts) { |
| 4830 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4831 | MFI_IO_TIMEOUT_SECS); |
| 4832 | } else { |
| 4833 | ret = megasas_issue_polled(instance, cmd); |
| 4834 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 4835 | } |
| 4836 | |
| 4837 | switch (ret) { |
| 4838 | case DCMD_SUCCESS: |
| 4839 | /* Fill the internal pd_list and ld_ids array based on |
| 4840 | * targetIds returned by FW |
| 4841 | */ |
| 4842 | count = le32_to_cpu(ci->count); |
| 4843 | |
Chandrakanth Patil | a4413a5 | 2019-06-25 16:34:27 +0530 | [diff] [blame] | 4844 | if (count > (MEGASAS_MAX_PD + MAX_LOGICAL_DRIVES_EXT)) |
| 4845 | break; |
| 4846 | |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4847 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4848 | dev_info(&instance->pdev->dev, "%s, Device count: 0x%x\n", |
| 4849 | __func__, count); |
| 4850 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4851 | memset(instance->local_pd_list, 0, |
| 4852 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
| 4853 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
| 4854 | for (i = 0; i < count; i++) { |
| 4855 | target_id = le16_to_cpu(ci->host_device_list[i].target_id); |
| 4856 | if (ci->host_device_list[i].flags.u.bits.is_sys_pd) { |
| 4857 | instance->local_pd_list[target_id].tid = target_id; |
| 4858 | instance->local_pd_list[target_id].driveType = |
| 4859 | ci->host_device_list[i].scsi_type; |
| 4860 | instance->local_pd_list[target_id].driveState = |
| 4861 | MR_PD_STATE_SYSTEM; |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4862 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4863 | dev_info(&instance->pdev->dev, |
| 4864 | "Device %d: PD targetID: 0x%03x deviceType:0x%x\n", |
| 4865 | i, target_id, ci->host_device_list[i].scsi_type); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4866 | } else { |
| 4867 | instance->ld_ids[target_id] = target_id; |
Shivasharan S | 0a11c0b | 2019-05-07 10:05:47 -0700 | [diff] [blame] | 4868 | if (megasas_dbg_lvl & LD_PD_DEBUG) |
| 4869 | dev_info(&instance->pdev->dev, |
| 4870 | "Device %d: LD targetID: 0x%03x\n", |
| 4871 | i, target_id); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | memcpy(instance->pd_list, instance->local_pd_list, |
| 4876 | sizeof(instance->pd_list)); |
| 4877 | break; |
| 4878 | |
| 4879 | case DCMD_TIMEOUT: |
| 4880 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 4881 | case INITIATE_OCR: |
| 4882 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 4883 | mutex_unlock(&instance->reset_mutex); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4884 | megasas_reset_fusion(instance->host, |
| 4885 | MFI_IO_TIMEOUT_OCR); |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 4886 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 4887 | break; |
| 4888 | case KILL_ADAPTER: |
| 4889 | megaraid_sas_kill_hba(instance); |
| 4890 | break; |
| 4891 | case IGNORE_TIMEOUT: |
| 4892 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 4893 | __func__, __LINE__); |
| 4894 | break; |
| 4895 | } |
| 4896 | break; |
| 4897 | case DCMD_FAILED: |
| 4898 | dev_err(&instance->pdev->dev, |
| 4899 | "%s: MR_DCMD_CTRL_DEVICE_LIST_GET failed\n", |
| 4900 | __func__); |
| 4901 | break; |
| 4902 | } |
| 4903 | |
| 4904 | if (ret != DCMD_TIMEOUT) |
| 4905 | megasas_return_cmd(instance, cmd); |
| 4906 | |
| 4907 | return ret; |
| 4908 | } |
| 4909 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4910 | /* |
| 4911 | * megasas_update_ext_vd_details : Update details w.r.t Extended VD |
| 4912 | * instance : Controller's instance |
| 4913 | */ |
| 4914 | static void megasas_update_ext_vd_details(struct megasas_instance *instance) |
| 4915 | { |
| 4916 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4917 | u32 ventura_map_sz = 0; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4918 | |
| 4919 | fusion = instance->ctrl_context; |
| 4920 | /* For MFI based controllers return dummy success */ |
| 4921 | if (!fusion) |
| 4922 | return; |
| 4923 | |
| 4924 | instance->supportmax256vd = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4925 | instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4926 | /* Below is additional check to address future FW enhancement */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 4927 | if (instance->ctrl_info_buf->max_lds > 64) |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4928 | instance->supportmax256vd = 1; |
| 4929 | |
| 4930 | instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS |
| 4931 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4932 | instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS |
| 4933 | * MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4934 | if (instance->supportmax256vd) { |
| 4935 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT; |
| 4936 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4937 | } else { |
| 4938 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4939 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
| 4940 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 4941 | |
| 4942 | dev_info(&instance->pdev->dev, |
Shivasharan S | cba67d9 | 2018-10-16 23:37:56 -0700 | [diff] [blame] | 4943 | "FW provided supportMaxExtLDs: %d\tmax_lds: %d\n", |
| 4944 | instance->ctrl_info_buf->adapterOperations3.supportMaxExtLDs ? 1 : 0, |
| 4945 | instance->ctrl_info_buf->max_lds); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4946 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4947 | if (instance->max_raid_mapsize) { |
| 4948 | ventura_map_sz = instance->max_raid_mapsize * |
| 4949 | MR_MIN_MAP_SIZE; /* 64k */ |
| 4950 | fusion->current_map_sz = ventura_map_sz; |
| 4951 | fusion->max_map_sz = ventura_map_sz; |
| 4952 | } else { |
| 4953 | fusion->old_map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 4954 | (sizeof(struct MR_LD_SPAN_MAP) * |
| 4955 | (instance->fw_supported_vd_count - 1)); |
| 4956 | 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] | 4957 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4958 | fusion->max_map_sz = |
| 4959 | max(fusion->old_map_sz, fusion->new_map_sz); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4960 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 4961 | if (instance->supportmax256vd) |
| 4962 | fusion->current_map_sz = fusion->new_map_sz; |
| 4963 | else |
| 4964 | fusion->current_map_sz = fusion->old_map_sz; |
| 4965 | } |
| 4966 | /* irrespective of FW raid maps, driver raid map is constant */ |
| 4967 | 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] | 4968 | } |
| 4969 | |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 4970 | /* |
| 4971 | * dcmd.opcode - MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES |
| 4972 | * dcmd.hdr.length - number of bytes to read |
| 4973 | * dcmd.sge - Ptr to MR_SNAPDUMP_PROPERTIES |
| 4974 | * Desc: Fill in snapdump properties |
| 4975 | * Status: MFI_STAT_OK- Command successful |
| 4976 | */ |
| 4977 | void megasas_get_snapdump_properties(struct megasas_instance *instance) |
| 4978 | { |
| 4979 | int ret = 0; |
| 4980 | struct megasas_cmd *cmd; |
| 4981 | struct megasas_dcmd_frame *dcmd; |
| 4982 | struct MR_SNAPDUMP_PROPERTIES *ci; |
| 4983 | dma_addr_t ci_h = 0; |
| 4984 | |
| 4985 | ci = instance->snapdump_prop; |
| 4986 | ci_h = instance->snapdump_prop_h; |
| 4987 | |
| 4988 | if (!ci) |
| 4989 | return; |
| 4990 | |
| 4991 | cmd = megasas_get_cmd(instance); |
| 4992 | |
| 4993 | if (!cmd) { |
| 4994 | dev_dbg(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4995 | return; |
| 4996 | } |
| 4997 | |
| 4998 | dcmd = &cmd->frame->dcmd; |
| 4999 | |
| 5000 | memset(ci, 0, sizeof(*ci)); |
| 5001 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5002 | |
| 5003 | dcmd->cmd = MFI_CMD_DCMD; |
| 5004 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
| 5005 | dcmd->sge_count = 1; |
| 5006 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 5007 | dcmd->timeout = 0; |
| 5008 | dcmd->pad_0 = 0; |
| 5009 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_SNAPDUMP_PROPERTIES)); |
| 5010 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES); |
| 5011 | |
| 5012 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 5013 | sizeof(struct MR_SNAPDUMP_PROPERTIES)); |
| 5014 | |
| 5015 | if (!instance->mask_interrupts) { |
| 5016 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 5017 | MFI_IO_TIMEOUT_SECS); |
| 5018 | } else { |
| 5019 | ret = megasas_issue_polled(instance, cmd); |
| 5020 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5021 | } |
| 5022 | |
| 5023 | switch (ret) { |
| 5024 | case DCMD_SUCCESS: |
| 5025 | instance->snapdump_wait_time = |
| 5026 | min_t(u8, ci->trigger_min_num_sec_before_ocr, |
| 5027 | MEGASAS_MAX_SNAP_DUMP_WAIT_TIME); |
| 5028 | break; |
| 5029 | |
| 5030 | case DCMD_TIMEOUT: |
| 5031 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5032 | case INITIATE_OCR: |
| 5033 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 5034 | mutex_unlock(&instance->reset_mutex); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5035 | megasas_reset_fusion(instance->host, |
| 5036 | MFI_IO_TIMEOUT_OCR); |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 5037 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5038 | break; |
| 5039 | case KILL_ADAPTER: |
| 5040 | megaraid_sas_kill_hba(instance); |
| 5041 | break; |
| 5042 | case IGNORE_TIMEOUT: |
| 5043 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 5044 | __func__, __LINE__); |
| 5045 | break; |
| 5046 | } |
| 5047 | } |
| 5048 | |
| 5049 | if (ret != DCMD_TIMEOUT) |
| 5050 | megasas_return_cmd(instance, cmd); |
| 5051 | } |
| 5052 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 5053 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5054 | * megasas_get_controller_info - Returns FW's controller structure |
| 5055 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5056 | * |
| 5057 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 5058 | * This information is mainly used to find out the maximum IO transfer per |
| 5059 | * command supported by the FW. |
| 5060 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5061 | int |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5062 | megasas_get_ctrl_info(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5063 | { |
| 5064 | int ret = 0; |
| 5065 | struct megasas_cmd *cmd; |
| 5066 | struct megasas_dcmd_frame *dcmd; |
| 5067 | struct megasas_ctrl_info *ci; |
| 5068 | dma_addr_t ci_h = 0; |
| 5069 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 5070 | ci = instance->ctrl_info_buf; |
| 5071 | ci_h = instance->ctrl_info_buf_h; |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5072 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5073 | cmd = megasas_get_cmd(instance); |
| 5074 | |
| 5075 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5076 | 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] | 5077 | return -ENOMEM; |
| 5078 | } |
| 5079 | |
| 5080 | dcmd = &cmd->frame->dcmd; |
| 5081 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5082 | memset(ci, 0, sizeof(*ci)); |
| 5083 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5084 | |
| 5085 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5086 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5087 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5088 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5089 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5090 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5091 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 5092 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5093 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5094 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5095 | megasas_set_dma_settings(instance, dcmd, ci_h, |
| 5096 | sizeof(struct megasas_ctrl_info)); |
| 5097 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5098 | if ((instance->adapter_type != MFI_SERIES) && |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 5099 | !instance->mask_interrupts) { |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5100 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 5101 | } else { |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5102 | ret = megasas_issue_polled(instance, cmd); |
Shivasharan S | 54b2804 | 2018-01-05 05:27:47 -0800 | [diff] [blame] | 5103 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5104 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5105 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5106 | switch (ret) { |
| 5107 | case DCMD_SUCCESS: |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5108 | /* Save required controller information in |
| 5109 | * CPU endianness format. |
| 5110 | */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5111 | le32_to_cpus((u32 *)&ci->properties.OnOffProperties); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5112 | le16_to_cpus((u16 *)&ci->properties.on_off_properties2); |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5113 | le32_to_cpus((u32 *)&ci->adapterOperations2); |
| 5114 | le32_to_cpus((u32 *)&ci->adapterOperations3); |
| 5115 | le16_to_cpus((u16 *)&ci->adapter_operations4); |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 5116 | le32_to_cpus((u32 *)&ci->adapter_operations5); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5117 | |
| 5118 | /* Update the latest Ext VD info. |
| 5119 | * From Init path, store current firmware details. |
| 5120 | * From OCR path, detect any firmware properties changes. |
| 5121 | * in case of Firmware upgrade without system reboot. |
| 5122 | */ |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5123 | megasas_update_ext_vd_details(instance); |
Chandrakanth Patil | 59db5a9 | 2019-06-25 16:34:26 +0530 | [diff] [blame] | 5124 | instance->support_seqnum_jbod_fp = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5125 | ci->adapterOperations3.useSeqNumJbodFP; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 5126 | instance->support_morethan256jbod = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5127 | ci->adapter_operations4.support_pd_map_target_id; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 5128 | instance->support_nvme_passthru = |
| 5129 | ci->adapter_operations4.support_nvme_passthru; |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 5130 | instance->support_pci_lane_margining = |
| 5131 | ci->adapter_operations5.support_pci_lane_margining; |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 5132 | instance->task_abort_tmo = ci->TaskAbortTO; |
| 5133 | instance->max_reset_tmo = ci->MaxResetTO; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5134 | |
| 5135 | /*Check whether controller is iMR or MR */ |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5136 | instance->is_imr = (ci->memory_size ? 0 : 1); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 5137 | |
| 5138 | instance->snapdump_wait_time = |
| 5139 | (ci->properties.on_off_properties2.enable_snap_dump ? |
| 5140 | MEGASAS_DEFAULT_SNAP_DUMP_WAIT_TIME : 0); |
| 5141 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5142 | instance->enable_fw_dev_list = |
| 5143 | ci->properties.on_off_properties2.enable_fw_dev_list; |
| 5144 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 5145 | dev_info(&instance->pdev->dev, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5146 | "controller type\t: %s(%dMB)\n", |
| 5147 | instance->is_imr ? "iMR" : "MR", |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5148 | le16_to_cpu(ci->memory_size)); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5149 | |
sumit.saxena@avagotech.com | c4bd265 | 2015-10-15 13:40:14 +0530 | [diff] [blame] | 5150 | instance->disableOnlineCtrlReset = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5151 | ci->properties.OnOffProperties.disableOnlineCtrlReset; |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 5152 | instance->secure_jbod_support = |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 5153 | ci->adapterOperations3.supportSecurityonJBOD; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5154 | dev_info(&instance->pdev->dev, "Online Controller Reset(OCR)\t: %s\n", |
| 5155 | instance->disableOnlineCtrlReset ? "Disabled" : "Enabled"); |
sumit.saxena@avagotech.com | 3222251 | 2015-10-15 13:40:24 +0530 | [diff] [blame] | 5156 | dev_info(&instance->pdev->dev, "Secure JBOD support\t: %s\n", |
| 5157 | instance->secure_jbod_support ? "Yes" : "No"); |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 5158 | dev_info(&instance->pdev->dev, "NVMe passthru support\t: %s\n", |
| 5159 | instance->support_nvme_passthru ? "Yes" : "No"); |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 5160 | dev_info(&instance->pdev->dev, |
| 5161 | "FW provided TM TaskAbort/Reset timeout\t: %d secs/%d secs\n", |
| 5162 | instance->task_abort_tmo, instance->max_reset_tmo); |
Chandrakanth Patil | 59db5a9 | 2019-06-25 16:34:26 +0530 | [diff] [blame] | 5163 | dev_info(&instance->pdev->dev, "JBOD sequence map support\t: %s\n", |
| 5164 | instance->support_seqnum_jbod_fp ? "Yes" : "No"); |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 5165 | dev_info(&instance->pdev->dev, "PCI Lane Margining support\t: %s\n", |
| 5166 | instance->support_pci_lane_margining ? "Yes" : "No"); |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 5167 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5168 | break; |
| 5169 | |
| 5170 | case DCMD_TIMEOUT: |
| 5171 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5172 | case INITIATE_OCR: |
| 5173 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 5174 | mutex_unlock(&instance->reset_mutex); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5175 | megasas_reset_fusion(instance->host, |
| 5176 | MFI_IO_TIMEOUT_OCR); |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 5177 | mutex_lock(&instance->reset_mutex); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5178 | break; |
| 5179 | case KILL_ADAPTER: |
| 5180 | megaraid_sas_kill_hba(instance); |
| 5181 | break; |
| 5182 | case IGNORE_TIMEOUT: |
| 5183 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 5184 | __func__, __LINE__); |
| 5185 | break; |
| 5186 | } |
Shivasharan S | 2747e6b | 2018-06-04 03:45:09 -0700 | [diff] [blame] | 5187 | break; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5188 | case DCMD_FAILED: |
| 5189 | megaraid_sas_kill_hba(instance); |
| 5190 | break; |
| 5191 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5192 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5193 | |
Shivasharan S | 2747e6b | 2018-06-04 03:45:09 -0700 | [diff] [blame] | 5194 | if (ret != DCMD_TIMEOUT) |
| 5195 | megasas_return_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5196 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5197 | return ret; |
| 5198 | } |
| 5199 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5200 | /* |
| 5201 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 5202 | * to firmware |
| 5203 | * |
| 5204 | * @instance: Adapter soft state |
| 5205 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 5206 | MR_CRASH_BUF_TURN_OFF = 0 |
| 5207 | MR_CRASH_BUF_TURN_ON = 1 |
| 5208 | * @return 0 on success non-zero on failure. |
| 5209 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 5210 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 5211 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 5212 | * crash dump feature is supported by the FW. |
| 5213 | * |
| 5214 | */ |
| 5215 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 5216 | u8 crash_buf_state) |
| 5217 | { |
| 5218 | int ret = 0; |
| 5219 | struct megasas_cmd *cmd; |
| 5220 | struct megasas_dcmd_frame *dcmd; |
| 5221 | |
| 5222 | cmd = megasas_get_cmd(instance); |
| 5223 | |
| 5224 | if (!cmd) { |
| 5225 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 5226 | return -ENOMEM; |
| 5227 | } |
| 5228 | |
| 5229 | |
| 5230 | dcmd = &cmd->frame->dcmd; |
| 5231 | |
| 5232 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5233 | dcmd->mbox.b[0] = crash_buf_state; |
| 5234 | dcmd->cmd = MFI_CMD_DCMD; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5235 | dcmd->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5236 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5237 | dcmd->flags = MFI_FRAME_DIR_NONE; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5238 | dcmd->timeout = 0; |
| 5239 | dcmd->pad_0 = 0; |
| 5240 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 5241 | 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] | 5242 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5243 | megasas_set_dma_settings(instance, dcmd, instance->crash_dump_h, |
| 5244 | CRASH_DMA_BUF_SIZE); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5245 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5246 | if ((instance->adapter_type != MFI_SERIES) && |
| 5247 | !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5248 | 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] | 5249 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5250 | ret = megasas_issue_polled(instance, cmd); |
| 5251 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 5252 | if (ret == DCMD_TIMEOUT) { |
| 5253 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 5254 | case INITIATE_OCR: |
| 5255 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
| 5256 | megasas_reset_fusion(instance->host, |
| 5257 | MFI_IO_TIMEOUT_OCR); |
| 5258 | break; |
| 5259 | case KILL_ADAPTER: |
| 5260 | megaraid_sas_kill_hba(instance); |
| 5261 | break; |
| 5262 | case IGNORE_TIMEOUT: |
| 5263 | dev_info(&instance->pdev->dev, "Ignore DCMD timeout: %s %d\n", |
| 5264 | __func__, __LINE__); |
| 5265 | break; |
| 5266 | } |
| 5267 | } else |
| 5268 | megasas_return_cmd(instance, cmd); |
| 5269 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5270 | return ret; |
| 5271 | } |
| 5272 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5273 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5274 | * megasas_issue_init_mfi - Initializes the FW |
| 5275 | * @instance: Adapter soft state |
| 5276 | * |
| 5277 | * Issues the INIT MFI cmd |
| 5278 | */ |
| 5279 | static int |
| 5280 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 5281 | { |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 5282 | __le32 context; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5283 | struct megasas_cmd *cmd; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5284 | struct megasas_init_frame *init_frame; |
| 5285 | struct megasas_init_queue_info *initq_info; |
| 5286 | dma_addr_t init_frame_h; |
| 5287 | dma_addr_t initq_info_h; |
| 5288 | |
| 5289 | /* |
| 5290 | * Prepare a init frame. Note the init frame points to queue info |
| 5291 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 5292 | * this frame - since we don't need any SGL - we use SGL's space as |
| 5293 | * queue info structure |
| 5294 | * |
| 5295 | * We will not get a NULL command below. We just created the pool. |
| 5296 | */ |
| 5297 | cmd = megasas_get_cmd(instance); |
| 5298 | |
| 5299 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 5300 | initq_info = (struct megasas_init_queue_info *) |
| 5301 | ((unsigned long)init_frame + 64); |
| 5302 | |
| 5303 | init_frame_h = cmd->frame_phys_addr; |
| 5304 | initq_info_h = init_frame_h + 64; |
| 5305 | |
| 5306 | context = init_frame->context; |
| 5307 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 5308 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 5309 | init_frame->context = context; |
| 5310 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5311 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 5312 | 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] | 5313 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5314 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 5315 | 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] | 5316 | |
| 5317 | init_frame->cmd = MFI_CMD_INIT; |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 5318 | init_frame->cmd_status = MFI_STAT_INVALID_STATUS; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5319 | init_frame->queue_info_new_phys_addr_lo = |
| 5320 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 5321 | init_frame->queue_info_new_phys_addr_hi = |
| 5322 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5323 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5324 | 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] | 5325 | |
| 5326 | /* |
| 5327 | * disable the intr before firing the init frame to FW |
| 5328 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5329 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5330 | |
| 5331 | /* |
| 5332 | * Issue the init frame in polled mode |
| 5333 | */ |
| 5334 | |
| 5335 | if (megasas_issue_polled(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5336 | dev_err(&instance->pdev->dev, "Failed to init firmware\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5337 | megasas_return_cmd(instance, cmd); |
| 5338 | goto fail_fw_init; |
| 5339 | } |
| 5340 | |
| 5341 | megasas_return_cmd(instance, cmd); |
| 5342 | |
| 5343 | return 0; |
| 5344 | |
| 5345 | fail_fw_init: |
| 5346 | return -EINVAL; |
| 5347 | } |
| 5348 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5349 | static u32 |
| 5350 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5351 | { |
| 5352 | u32 context_sz; |
| 5353 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5354 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5355 | /* |
| 5356 | * Get various operational parameters from status register |
| 5357 | */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5358 | instance->max_fw_cmds = instance->instancet->read_fw_status_reg(instance) & 0x00FFFF; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 5359 | /* |
| 5360 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 5361 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 5362 | * does not exceed max cmds that the FW can support |
| 5363 | */ |
| 5364 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5365 | instance->max_mfi_cmds = instance->max_fw_cmds; |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5366 | instance->max_num_sge = (instance->instancet->read_fw_status_reg(instance) & 0xFF0000) >> |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 5367 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5368 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 5369 | * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands |
| 5370 | * are reserved for IOCTL + driver's internal DCMDs. |
| 5371 | */ |
| 5372 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 5373 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 5374 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 5375 | MEGASAS_SKINNY_INT_CMDS); |
| 5376 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 5377 | } else { |
| 5378 | instance->max_scsi_cmds = (instance->max_fw_cmds - |
| 5379 | MEGASAS_INT_CMDS); |
| 5380 | sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS)); |
| 5381 | } |
| 5382 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 5383 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 5384 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5385 | * Create a pool of commands |
| 5386 | */ |
| 5387 | if (megasas_alloc_cmds(instance)) |
| 5388 | goto fail_alloc_cmds; |
| 5389 | |
| 5390 | /* |
| 5391 | * Allocate memory for reply queue. Length of reply queue should |
| 5392 | * be _one_ more than the maximum commands handled by the firmware. |
| 5393 | * |
| 5394 | * Note: When FW completes commands, it places corresponding contex |
| 5395 | * values in this circular reply queue. This circular queue is a fairly |
| 5396 | * typical producer-consumer queue. FW is the producer (of completed |
| 5397 | * commands) and the driver is the consumer. |
| 5398 | */ |
| 5399 | context_sz = sizeof(u32); |
| 5400 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 5401 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5402 | instance->reply_queue = dma_alloc_coherent(&instance->pdev->dev, |
| 5403 | reply_q_sz, &instance->reply_queue_h, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5404 | |
| 5405 | if (!instance->reply_queue) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5406 | 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] | 5407 | goto fail_reply_queue; |
| 5408 | } |
| 5409 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5410 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5411 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5412 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 5413 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5414 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 5415 | "Fail from %s %d\n", instance->unique_id, |
| 5416 | __func__, __LINE__); |
| 5417 | goto fail_fw_init; |
| 5418 | } |
| 5419 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5420 | instance->fw_support_ieee = 0; |
| 5421 | instance->fw_support_ieee = |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5422 | (instance->instancet->read_fw_status_reg(instance) & |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5423 | 0x04000000); |
| 5424 | |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5425 | dev_notice(&instance->pdev->dev, "megasas_init_mfi: fw_support_ieee=%d", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5426 | instance->fw_support_ieee); |
| 5427 | |
| 5428 | if (instance->fw_support_ieee) |
| 5429 | instance->flag_ieee = 1; |
| 5430 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5431 | return 0; |
| 5432 | |
| 5433 | fail_fw_init: |
| 5434 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 5435 | dma_free_coherent(&instance->pdev->dev, reply_q_sz, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5436 | instance->reply_queue, instance->reply_queue_h); |
| 5437 | fail_reply_queue: |
| 5438 | megasas_free_cmds(instance); |
| 5439 | |
| 5440 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5441 | return 1; |
| 5442 | } |
| 5443 | |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 5444 | static |
| 5445 | void megasas_setup_irq_poll(struct megasas_instance *instance) |
| 5446 | { |
| 5447 | struct megasas_irq_context *irq_ctx; |
| 5448 | u32 count, i; |
| 5449 | |
| 5450 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 5451 | |
| 5452 | /* Initialize IRQ poll */ |
| 5453 | for (i = 0; i < count; i++) { |
| 5454 | irq_ctx = &instance->irq_context[i]; |
| 5455 | irq_ctx->os_irq = pci_irq_vector(instance->pdev, i); |
| 5456 | irq_ctx->irq_poll_scheduled = false; |
| 5457 | irq_poll_init(&irq_ctx->irqpoll, |
| 5458 | instance->threshold_reply_count, |
| 5459 | megasas_irqpoll); |
| 5460 | } |
| 5461 | } |
| 5462 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5463 | /* |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5464 | * megasas_setup_irqs_ioapic - register legacy interrupts. |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5465 | * @instance: Adapter soft state |
| 5466 | * |
| 5467 | * Do not enable interrupt, only setup ISRs. |
| 5468 | * |
| 5469 | * Return 0 on success. |
| 5470 | */ |
| 5471 | static int |
| 5472 | megasas_setup_irqs_ioapic(struct megasas_instance *instance) |
| 5473 | { |
| 5474 | struct pci_dev *pdev; |
| 5475 | |
| 5476 | pdev = instance->pdev; |
| 5477 | instance->irq_context[0].instance = instance; |
| 5478 | instance->irq_context[0].MSIxIndex = 0; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5479 | if (request_irq(pci_irq_vector(pdev, 0), |
| 5480 | instance->instancet->service_isr, IRQF_SHARED, |
| 5481 | "megasas", &instance->irq_context[0])) { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5482 | dev_err(&instance->pdev->dev, |
| 5483 | "Failed to register IRQ from %s %d\n", |
| 5484 | __func__, __LINE__); |
| 5485 | return -1; |
| 5486 | } |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 5487 | instance->perf_mode = MR_LATENCY_PERF_MODE; |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5488 | instance->low_latency_index_start = 0; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5489 | return 0; |
| 5490 | } |
| 5491 | |
| 5492 | /** |
| 5493 | * megasas_setup_irqs_msix - register MSI-x interrupts. |
| 5494 | * @instance: Adapter soft state |
| 5495 | * @is_probe: Driver probe check |
| 5496 | * |
| 5497 | * Do not enable interrupt, only setup ISRs. |
| 5498 | * |
| 5499 | * Return 0 on success. |
| 5500 | */ |
| 5501 | static int |
| 5502 | megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe) |
| 5503 | { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5504 | int i, j; |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5505 | struct pci_dev *pdev; |
| 5506 | |
| 5507 | pdev = instance->pdev; |
| 5508 | |
| 5509 | /* Try MSI-x */ |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5510 | for (i = 0; i < instance->msix_vectors; i++) { |
| 5511 | instance->irq_context[i].instance = instance; |
| 5512 | instance->irq_context[i].MSIxIndex = i; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5513 | if (request_irq(pci_irq_vector(pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5514 | instance->instancet->service_isr, 0, "megasas", |
| 5515 | &instance->irq_context[i])) { |
| 5516 | dev_err(&instance->pdev->dev, |
| 5517 | "Failed to register IRQ for vector %d.\n", i); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5518 | for (j = 0; j < i; j++) |
| 5519 | free_irq(pci_irq_vector(pdev, j), |
| 5520 | &instance->irq_context[j]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5521 | /* Retry irq register for IO_APIC*/ |
| 5522 | instance->msix_vectors = 0; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5523 | instance->msix_load_balance = false; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5524 | if (is_probe) { |
| 5525 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5526 | return megasas_setup_irqs_ioapic(instance); |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5527 | } else { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5528 | return -1; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 5529 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5530 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5531 | } |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5532 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5533 | return 0; |
| 5534 | } |
| 5535 | |
| 5536 | /* |
| 5537 | * megasas_destroy_irqs- unregister interrupts. |
| 5538 | * @instance: Adapter soft state |
| 5539 | * return: void |
| 5540 | */ |
| 5541 | static void |
| 5542 | megasas_destroy_irqs(struct megasas_instance *instance) { |
| 5543 | |
| 5544 | int i; |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 5545 | int count; |
| 5546 | struct megasas_irq_context *irq_ctx; |
| 5547 | |
| 5548 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 5549 | if (instance->adapter_type != MFI_SERIES) { |
| 5550 | for (i = 0; i < count; i++) { |
| 5551 | irq_ctx = &instance->irq_context[i]; |
| 5552 | irq_poll_disable(&irq_ctx->irqpoll); |
| 5553 | } |
| 5554 | } |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5555 | |
| 5556 | if (instance->msix_vectors) |
| 5557 | for (i = 0; i < instance->msix_vectors; i++) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5558 | free_irq(pci_irq_vector(instance->pdev, i), |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5559 | &instance->irq_context[i]); |
| 5560 | } |
| 5561 | else |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5562 | free_irq(pci_irq_vector(instance->pdev, 0), |
| 5563 | &instance->irq_context[0]); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 5564 | } |
| 5565 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5566 | /** |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5567 | * megasas_setup_jbod_map - setup jbod map for FP seq_number. |
| 5568 | * @instance: Adapter soft state |
| 5569 | * @is_probe: Driver probe check |
| 5570 | * |
| 5571 | * Return 0 on success. |
| 5572 | */ |
| 5573 | void |
| 5574 | megasas_setup_jbod_map(struct megasas_instance *instance) |
| 5575 | { |
| 5576 | int i; |
| 5577 | struct fusion_context *fusion = instance->ctrl_context; |
| 5578 | u32 pd_seq_map_sz; |
| 5579 | |
| 5580 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 5581 | (sizeof(struct MR_PD_CFG_SEQ) * (MAX_PHYSICAL_DEVICES - 1)); |
| 5582 | |
Chandrakanth Patil | 59db5a9 | 2019-06-25 16:34:26 +0530 | [diff] [blame] | 5583 | instance->use_seqnum_jbod_fp = |
| 5584 | instance->support_seqnum_jbod_fp; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5585 | if (reset_devices || !fusion || |
Chandrakanth Patil | 59db5a9 | 2019-06-25 16:34:26 +0530 | [diff] [blame] | 5586 | !instance->support_seqnum_jbod_fp) { |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5587 | dev_info(&instance->pdev->dev, |
Chandrakanth Patil | 59db5a9 | 2019-06-25 16:34:26 +0530 | [diff] [blame] | 5588 | "JBOD sequence map is disabled %s %d\n", |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5589 | __func__, __LINE__); |
| 5590 | instance->use_seqnum_jbod_fp = false; |
| 5591 | return; |
| 5592 | } |
| 5593 | |
| 5594 | if (fusion->pd_seq_sync[0]) |
| 5595 | goto skip_alloc; |
| 5596 | |
| 5597 | for (i = 0; i < JBOD_MAPS_COUNT; i++) { |
| 5598 | fusion->pd_seq_sync[i] = dma_alloc_coherent |
| 5599 | (&instance->pdev->dev, pd_seq_map_sz, |
| 5600 | &fusion->pd_seq_phys[i], GFP_KERNEL); |
| 5601 | if (!fusion->pd_seq_sync[i]) { |
| 5602 | dev_err(&instance->pdev->dev, |
| 5603 | "Failed to allocate memory from %s %d\n", |
| 5604 | __func__, __LINE__); |
| 5605 | if (i == 1) { |
| 5606 | dma_free_coherent(&instance->pdev->dev, |
| 5607 | pd_seq_map_sz, fusion->pd_seq_sync[0], |
| 5608 | fusion->pd_seq_phys[0]); |
| 5609 | fusion->pd_seq_sync[0] = NULL; |
| 5610 | } |
| 5611 | instance->use_seqnum_jbod_fp = false; |
| 5612 | return; |
| 5613 | } |
| 5614 | } |
| 5615 | |
| 5616 | skip_alloc: |
| 5617 | if (!megasas_sync_pd_seq_num(instance, false) && |
| 5618 | !megasas_sync_pd_seq_num(instance, true)) |
| 5619 | instance->use_seqnum_jbod_fp = true; |
| 5620 | else |
| 5621 | instance->use_seqnum_jbod_fp = false; |
| 5622 | } |
| 5623 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5624 | static void megasas_setup_reply_map(struct megasas_instance *instance) |
| 5625 | { |
| 5626 | const struct cpumask *mask; |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5627 | unsigned int queue, cpu, low_latency_index_start; |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5628 | |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5629 | low_latency_index_start = instance->low_latency_index_start; |
| 5630 | |
| 5631 | for (queue = low_latency_index_start; queue < instance->msix_vectors; queue++) { |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5632 | mask = pci_irq_get_affinity(instance->pdev, queue); |
| 5633 | if (!mask) |
| 5634 | goto fallback; |
| 5635 | |
| 5636 | for_each_cpu(cpu, mask) |
| 5637 | instance->reply_map[cpu] = queue; |
| 5638 | } |
| 5639 | return; |
| 5640 | |
| 5641 | fallback: |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5642 | queue = low_latency_index_start; |
| 5643 | for_each_possible_cpu(cpu) { |
| 5644 | instance->reply_map[cpu] = queue; |
| 5645 | if (queue == (instance->msix_vectors - 1)) |
| 5646 | queue = low_latency_index_start; |
| 5647 | else |
| 5648 | queue++; |
| 5649 | } |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 5650 | } |
| 5651 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 5652 | /** |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5653 | * megasas_get_device_list - Get the PD and LD device list from FW. |
| 5654 | * @instance: Adapter soft state |
| 5655 | * @return: Success or failure |
| 5656 | * |
| 5657 | * Issue DCMDs to Firmware to get the PD and LD list. |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5658 | * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination |
| 5659 | * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list. |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5660 | */ |
| 5661 | static |
| 5662 | int megasas_get_device_list(struct megasas_instance *instance) |
| 5663 | { |
| 5664 | memset(instance->pd_list, 0, |
| 5665 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
| 5666 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
| 5667 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5668 | if (instance->enable_fw_dev_list) { |
| 5669 | if (megasas_host_device_list_query(instance, true)) |
| 5670 | return FAILED; |
| 5671 | } else { |
| 5672 | if (megasas_get_pd_list(instance) < 0) { |
| 5673 | dev_err(&instance->pdev->dev, "failed to get PD list\n"); |
| 5674 | return FAILED; |
| 5675 | } |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5676 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 5677 | if (megasas_ld_list_query(instance, |
| 5678 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) { |
| 5679 | dev_err(&instance->pdev->dev, "failed to get LD list\n"); |
| 5680 | return FAILED; |
| 5681 | } |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | return SUCCESS; |
| 5685 | } |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5686 | |
Chandrakanth Patil | f0b9e7b | 2019-06-25 16:34:33 +0530 | [diff] [blame] | 5687 | /** |
| 5688 | * megasas_set_high_iops_queue_affinity_hint - Set affinity hint for high IOPS queues |
| 5689 | * @instance: Adapter soft state |
| 5690 | * return: void |
| 5691 | */ |
| 5692 | static inline void |
| 5693 | megasas_set_high_iops_queue_affinity_hint(struct megasas_instance *instance) |
| 5694 | { |
| 5695 | int i; |
| 5696 | int local_numa_node; |
| 5697 | |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 5698 | if (instance->perf_mode == MR_BALANCED_PERF_MODE) { |
Chandrakanth Patil | f0b9e7b | 2019-06-25 16:34:33 +0530 | [diff] [blame] | 5699 | local_numa_node = dev_to_node(&instance->pdev->dev); |
| 5700 | |
| 5701 | for (i = 0; i < instance->low_latency_index_start; i++) |
| 5702 | irq_set_affinity_hint(pci_irq_vector(instance->pdev, i), |
| 5703 | cpumask_of_node(local_numa_node)); |
| 5704 | } |
| 5705 | } |
| 5706 | |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5707 | static int |
| 5708 | __megasas_alloc_irq_vectors(struct megasas_instance *instance) |
| 5709 | { |
| 5710 | int i, irq_flags; |
| 5711 | struct irq_affinity desc = { .pre_vectors = instance->low_latency_index_start }; |
| 5712 | struct irq_affinity *descp = &desc; |
| 5713 | |
| 5714 | irq_flags = PCI_IRQ_MSIX; |
| 5715 | |
| 5716 | if (instance->smp_affinity_enable) |
| 5717 | irq_flags |= PCI_IRQ_AFFINITY; |
| 5718 | else |
| 5719 | descp = NULL; |
| 5720 | |
| 5721 | i = pci_alloc_irq_vectors_affinity(instance->pdev, |
| 5722 | instance->low_latency_index_start, |
| 5723 | instance->msix_vectors, irq_flags, descp); |
| 5724 | |
| 5725 | return i; |
| 5726 | } |
| 5727 | |
| 5728 | /** |
| 5729 | * megasas_alloc_irq_vectors - Allocate IRQ vectors/enable MSI-x vectors |
| 5730 | * @instance: Adapter soft state |
| 5731 | * return: void |
| 5732 | */ |
| 5733 | static void |
| 5734 | megasas_alloc_irq_vectors(struct megasas_instance *instance) |
| 5735 | { |
| 5736 | int i; |
| 5737 | unsigned int num_msix_req; |
| 5738 | |
| 5739 | i = __megasas_alloc_irq_vectors(instance); |
| 5740 | |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 5741 | if ((instance->perf_mode == MR_BALANCED_PERF_MODE) && |
| 5742 | (i != instance->msix_vectors)) { |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5743 | if (instance->msix_vectors) |
| 5744 | pci_free_irq_vectors(instance->pdev); |
| 5745 | /* Disable Balanced IOPS mode and try realloc vectors */ |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 5746 | instance->perf_mode = MR_LATENCY_PERF_MODE; |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5747 | instance->low_latency_index_start = 1; |
| 5748 | num_msix_req = num_online_cpus() + instance->low_latency_index_start; |
| 5749 | |
| 5750 | instance->msix_vectors = min(num_msix_req, |
| 5751 | instance->msix_vectors); |
| 5752 | |
| 5753 | i = __megasas_alloc_irq_vectors(instance); |
| 5754 | |
| 5755 | } |
| 5756 | |
| 5757 | dev_info(&instance->pdev->dev, |
| 5758 | "requested/available msix %d/%d\n", instance->msix_vectors, i); |
| 5759 | |
| 5760 | if (i > 0) |
| 5761 | instance->msix_vectors = i; |
| 5762 | else |
| 5763 | instance->msix_vectors = 0; |
| 5764 | |
Chandrakanth Patil | f0b9e7b | 2019-06-25 16:34:33 +0530 | [diff] [blame] | 5765 | if (instance->smp_affinity_enable) |
| 5766 | megasas_set_high_iops_queue_affinity_hint(instance); |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5767 | } |
| 5768 | |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 5769 | /** |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5770 | * megasas_init_fw - Initializes the FW |
| 5771 | * @instance: Adapter soft state |
| 5772 | * |
| 5773 | * This is the main function for initializing firmware |
| 5774 | */ |
| 5775 | |
| 5776 | static int megasas_init_fw(struct megasas_instance *instance) |
| 5777 | { |
| 5778 | u32 max_sectors_1; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 5779 | u32 max_sectors_2, tmp_sectors, msix_enable; |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5780 | u32 scratch_pad_1, scratch_pad_2, scratch_pad_3, status_reg; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5781 | resource_size_t base_addr; |
Shivasharan S | 9a59871 | 2019-05-07 10:05:42 -0700 | [diff] [blame] | 5782 | void *base_addr_phys; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5783 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5784 | unsigned long bar_list; |
Shivasharan S | ce88418 | 2019-05-07 10:05:48 -0700 | [diff] [blame] | 5785 | int i, j, loop; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5786 | struct IOV_111 *iovPtr; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5787 | struct fusion_context *fusion; |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5788 | bool intr_coalescing; |
| 5789 | unsigned int num_msix_req; |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 5790 | u16 lnksta, speed; |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5791 | |
| 5792 | fusion = instance->ctrl_context; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5793 | |
| 5794 | /* Find first memory bar */ |
| 5795 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
Christophe JAILLET | 51f9039 | 2016-08-21 10:28:25 +0200 | [diff] [blame] | 5796 | instance->bar = find_first_bit(&bar_list, BITS_PER_LONG); |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 5797 | if (pci_request_selected_regions(instance->pdev, 1<<instance->bar, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5798 | "megasas: LSI")) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5799 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "IO memory region busy!\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5800 | return -EBUSY; |
| 5801 | } |
| 5802 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 5803 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 5804 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5805 | |
| 5806 | if (!instance->reg_set) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 5807 | 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] | 5808 | goto fail_ioremap; |
| 5809 | } |
| 5810 | |
Shivasharan S | 9a59871 | 2019-05-07 10:05:42 -0700 | [diff] [blame] | 5811 | base_addr_phys = &base_addr; |
| 5812 | dev_printk(KERN_DEBUG, &instance->pdev->dev, |
| 5813 | "BAR:0x%lx BAR's base_addr(phys):%pa mapped virt_addr:0x%p\n", |
| 5814 | instance->bar, base_addr_phys, instance->reg_set); |
| 5815 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 5816 | if (instance->adapter_type != MFI_SERIES) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5817 | instance->instancet = &megasas_instance_template_fusion; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 5818 | else { |
| 5819 | switch (instance->pdev->device) { |
| 5820 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 5821 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 5822 | instance->instancet = &megasas_instance_template_ppc; |
| 5823 | break; |
| 5824 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 5825 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 5826 | instance->instancet = &megasas_instance_template_gen2; |
| 5827 | break; |
| 5828 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 5829 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 5830 | instance->instancet = &megasas_instance_template_skinny; |
| 5831 | break; |
| 5832 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 5833 | case PCI_DEVICE_ID_DELL_PERC5: |
| 5834 | default: |
| 5835 | instance->instancet = &megasas_instance_template_xscale; |
| 5836 | instance->pd_list_not_supported = 1; |
| 5837 | break; |
| 5838 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5839 | } |
| 5840 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5841 | if (megasas_transition_to_ready(instance, 0)) { |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame] | 5842 | dev_info(&instance->pdev->dev, |
| 5843 | "Failed to transition controller to ready from %s!\n", |
| 5844 | __func__); |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5845 | if (instance->adapter_type != MFI_SERIES) { |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5846 | status_reg = instance->instancet->read_fw_status_reg( |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5847 | instance); |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5848 | if (status_reg & MFI_RESET_ADAPTER) { |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame] | 5849 | if (megasas_adp_reset_wait_for_ready |
| 5850 | (instance, true, 0) == FAILED) |
Shivasharan S | f10fb85 | 2019-05-07 10:05:32 -0700 | [diff] [blame] | 5851 | goto fail_ready_state; |
| 5852 | } else { |
| 5853 | goto fail_ready_state; |
| 5854 | } |
| 5855 | } else { |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5856 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 5857 | instance->instancet->adp_reset |
| 5858 | (instance, instance->reg_set); |
| 5859 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5860 | |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5861 | /*waiting for about 30 second before retry*/ |
| 5862 | ssleep(30); |
| 5863 | |
| 5864 | if (megasas_transition_to_ready(instance, 0)) |
| 5865 | goto fail_ready_state; |
Shivasharan S | de93b40 | 2018-10-16 23:37:42 -0700 | [diff] [blame] | 5866 | } |
Shivasharan S | 78409d4 | 2019-05-07 10:05:34 -0700 | [diff] [blame] | 5867 | |
| 5868 | dev_info(&instance->pdev->dev, |
| 5869 | "FW restarted successfully from %s!\n", |
| 5870 | __func__); |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 5871 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 5872 | |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5873 | megasas_init_ctrl_params(instance); |
| 5874 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 5875 | if (megasas_set_dma_mask(instance)) |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 5876 | goto fail_ready_state; |
| 5877 | |
| 5878 | if (megasas_alloc_ctrl_mem(instance)) |
| 5879 | goto fail_alloc_dma_buf; |
| 5880 | |
| 5881 | if (megasas_alloc_ctrl_dma_buffers(instance)) |
| 5882 | goto fail_alloc_dma_buf; |
| 5883 | |
| 5884 | fusion = instance->ctrl_context; |
| 5885 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 5886 | if (instance->adapter_type >= VENTURA_SERIES) { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5887 | scratch_pad_2 = |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5888 | megasas_readl(instance, |
| 5889 | &instance->reg_set->outbound_scratch_pad_2); |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5890 | instance->max_raid_mapsize = ((scratch_pad_2 >> |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 5891 | MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT) & |
| 5892 | MR_MAX_RAID_MAP_SIZE_MASK); |
| 5893 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5894 | |
Chandrakanth Patil | 7fc5570 | 2019-06-25 16:34:29 +0530 | [diff] [blame] | 5895 | switch (instance->adapter_type) { |
| 5896 | case VENTURA_SERIES: |
Chandrakanth Patil | 49f2bf1 | 2019-06-25 16:34:28 +0530 | [diff] [blame] | 5897 | fusion->pcie_bw_limitation = true; |
Chandrakanth Patil | 7fc5570 | 2019-06-25 16:34:29 +0530 | [diff] [blame] | 5898 | break; |
| 5899 | case AERO_SERIES: |
| 5900 | fusion->r56_div_offload = true; |
| 5901 | break; |
| 5902 | default: |
| 5903 | break; |
| 5904 | } |
Chandrakanth Patil | 49f2bf1 | 2019-06-25 16:34:28 +0530 | [diff] [blame] | 5905 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5906 | /* Check if MSI-X is supported while in ready state */ |
Shivasharan S | de51637 | 2018-12-17 00:47:39 -0800 | [diff] [blame] | 5907 | msix_enable = (instance->instancet->read_fw_status_reg(instance) & |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5908 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5909 | if (msix_enable && !msix_disable) { |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 5910 | |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 5911 | scratch_pad_1 = megasas_readl |
| 5912 | (instance, &instance->reg_set->outbound_scratch_pad_1); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5913 | /* Check max MSI-X vectors */ |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5914 | if (fusion) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 5915 | if (instance->adapter_type == THUNDERBOLT_SERIES) { |
| 5916 | /* Thunderbolt Series*/ |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5917 | instance->msix_vectors = (scratch_pad_1 |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5918 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5919 | } else { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5920 | instance->msix_vectors = ((scratch_pad_1 |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5921 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 5922 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5923 | |
| 5924 | /* |
| 5925 | * For Invader series, > 8 MSI-x vectors |
| 5926 | * supported by FW/HW implies combined |
| 5927 | * reply queue mode is enabled. |
| 5928 | * For Ventura series, > 16 MSI-x vectors |
| 5929 | * supported by FW/HW implies combined |
| 5930 | * reply queue mode is enabled. |
| 5931 | */ |
| 5932 | switch (instance->adapter_type) { |
| 5933 | case INVADER_SERIES: |
| 5934 | if (instance->msix_vectors > 8) |
| 5935 | instance->msix_combined = true; |
| 5936 | break; |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 5937 | case AERO_SERIES: |
Shivasharan S | e29c322 | 2018-10-16 23:37:46 -0700 | [diff] [blame] | 5938 | case VENTURA_SERIES: |
| 5939 | if (instance->msix_vectors > 16) |
| 5940 | instance->msix_combined = true; |
| 5941 | break; |
| 5942 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 5943 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5944 | if (rdpq_enable) |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 5945 | instance->is_rdpq = (scratch_pad_1 & MR_RDPQ_MODE_OFFSET) ? |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 5946 | 1 : 0; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5947 | |
| 5948 | if (!instance->msix_combined) { |
| 5949 | instance->msix_load_balance = true; |
| 5950 | instance->smp_affinity_enable = false; |
| 5951 | } |
| 5952 | |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5953 | /* Save 1-15 reply post index address to local memory |
| 5954 | * Index 0 is already saved from reg offset |
| 5955 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 5956 | */ |
| 5957 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 5958 | instance->reply_post_host_index_addr[loop] = |
| 5959 | (u32 __iomem *) |
| 5960 | ((u8 __iomem *)instance->reg_set + |
| 5961 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 5962 | + (loop * 0x10)); |
| 5963 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5964 | } |
Shivasharan S | ce88418 | 2019-05-07 10:05:48 -0700 | [diff] [blame] | 5965 | |
| 5966 | dev_info(&instance->pdev->dev, |
| 5967 | "firmware supports msix\t: (%d)", |
| 5968 | instance->msix_vectors); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5969 | if (msix_vectors) |
| 5970 | instance->msix_vectors = min(msix_vectors, |
| 5971 | instance->msix_vectors); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 5972 | } else /* MFI adapters */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5973 | instance->msix_vectors = 1; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 5974 | |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 5975 | |
| 5976 | /* |
| 5977 | * For Aero (if some conditions are met), driver will configure a |
| 5978 | * few additional reply queues with interrupt coalescing enabled. |
| 5979 | * These queues with interrupt coalescing enabled are called |
| 5980 | * High IOPS queues and rest of reply queues (based on number of |
| 5981 | * logical CPUs) are termed as Low latency queues. |
| 5982 | * |
| 5983 | * Total Number of reply queues = High IOPS queues + low latency queues |
| 5984 | * |
| 5985 | * For rest of fusion adapters, 1 additional reply queue will be |
| 5986 | * reserved for management commands, rest of reply queues |
| 5987 | * (based on number of logical CPUs) will be used for IOs and |
| 5988 | * referenced as IO queues. |
| 5989 | * Total Number of reply queues = 1 + IO queues |
| 5990 | * |
| 5991 | * MFI adapters supports single MSI-x so single reply queue |
| 5992 | * will be used for IO and management commands. |
| 5993 | */ |
| 5994 | |
| 5995 | intr_coalescing = (scratch_pad_1 & MR_INTR_COALESCING_SUPPORT_OFFSET) ? |
| 5996 | true : false; |
| 5997 | if (intr_coalescing && |
| 5998 | (num_online_cpus() >= MR_HIGH_IOPS_QUEUE_COUNT) && |
| 5999 | (instance->msix_vectors == MEGASAS_MAX_MSIX_QUEUES)) |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 6000 | instance->perf_mode = MR_BALANCED_PERF_MODE; |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 6001 | else |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 6002 | instance->perf_mode = MR_LATENCY_PERF_MODE; |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 6003 | |
Chandrakanth Patil | 299ee42 | 2019-06-25 16:34:35 +0530 | [diff] [blame] | 6004 | |
| 6005 | if (instance->adapter_type == AERO_SERIES) { |
| 6006 | pcie_capability_read_word(instance->pdev, PCI_EXP_LNKSTA, &lnksta); |
| 6007 | speed = lnksta & PCI_EXP_LNKSTA_CLS; |
| 6008 | |
| 6009 | /* |
| 6010 | * For Aero, if PCIe link speed is <16 GT/s, then driver should operate |
| 6011 | * in latency perf mode and enable R1 PCI bandwidth algorithm |
| 6012 | */ |
| 6013 | if (speed < 0x4) { |
| 6014 | instance->perf_mode = MR_LATENCY_PERF_MODE; |
| 6015 | fusion->pcie_bw_limitation = true; |
| 6016 | } |
| 6017 | |
| 6018 | /* |
| 6019 | * Performance mode settings provided through module parameter-perf_mode will |
| 6020 | * take affect only for: |
| 6021 | * 1. Aero family of adapters. |
| 6022 | * 2. When user sets module parameter- perf_mode in range of 0-2. |
| 6023 | */ |
| 6024 | if ((perf_mode >= MR_BALANCED_PERF_MODE) && |
| 6025 | (perf_mode <= MR_LATENCY_PERF_MODE)) |
| 6026 | instance->perf_mode = perf_mode; |
| 6027 | /* |
| 6028 | * If intr coalescing is not supported by controller FW, then IOPS |
| 6029 | * and Balanced modes are not feasible. |
| 6030 | */ |
| 6031 | if (!intr_coalescing) |
| 6032 | instance->perf_mode = MR_LATENCY_PERF_MODE; |
| 6033 | |
| 6034 | } |
| 6035 | |
| 6036 | if (instance->perf_mode == MR_BALANCED_PERF_MODE) |
Chandrakanth Patil | 132147d | 2019-06-25 16:34:31 +0530 | [diff] [blame] | 6037 | instance->low_latency_index_start = |
| 6038 | MR_HIGH_IOPS_QUEUE_COUNT; |
| 6039 | else |
| 6040 | instance->low_latency_index_start = 1; |
| 6041 | |
| 6042 | num_msix_req = num_online_cpus() + instance->low_latency_index_start; |
| 6043 | |
| 6044 | instance->msix_vectors = min(num_msix_req, |
| 6045 | instance->msix_vectors); |
| 6046 | |
| 6047 | megasas_alloc_irq_vectors(instance); |
| 6048 | if (!instance->msix_vectors) |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 6049 | instance->msix_load_balance = false; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 6050 | } |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 6051 | /* |
| 6052 | * MSI-X host index 0 is common for all adapter. |
| 6053 | * It is used for all MPT based Adapters. |
| 6054 | */ |
| 6055 | if (instance->msix_combined) { |
| 6056 | instance->reply_post_host_index_addr[0] = |
| 6057 | (u32 *)((u8 *)instance->reg_set + |
| 6058 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET); |
| 6059 | } else { |
| 6060 | instance->reply_post_host_index_addr[0] = |
| 6061 | (u32 *)((u8 *)instance->reg_set + |
| 6062 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 6063 | } |
| 6064 | |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 6065 | if (!instance->msix_vectors) { |
| 6066 | i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY); |
| 6067 | if (i < 0) |
Shivasharan S | 8a25fa1 | 2018-10-16 23:37:44 -0700 | [diff] [blame] | 6068 | goto fail_init_adapter; |
Shivasharan S | 64ff64b | 2017-03-10 03:22:12 -0800 | [diff] [blame] | 6069 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 6070 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6071 | megasas_setup_reply_map(instance); |
| 6072 | |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 6073 | dev_info(&instance->pdev->dev, |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 6074 | "current msix/online cpus\t: (%d/%d)\n", |
| 6075 | instance->msix_vectors, (unsigned int)num_online_cpus()); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 6076 | dev_info(&instance->pdev->dev, |
| 6077 | "RDPQ mode\t: (%s)\n", instance->is_rdpq ? "enabled" : "disabled"); |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 6078 | |
sumit.saxena@avagotech.com | 91626c2 | 2015-10-15 13:40:34 +0530 | [diff] [blame] | 6079 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 6080 | (unsigned long)instance); |
| 6081 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6082 | /* |
| 6083 | * Below are default value for legacy Firmware. |
| 6084 | * non-fusion based controllers |
| 6085 | */ |
| 6086 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 6087 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 6088 | /* Get operational params, sge flags, send init cmd to controller */ |
| 6089 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 6090 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 6091 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 6092 | if (instance->adapter_type >= VENTURA_SERIES) { |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6093 | scratch_pad_3 = |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 6094 | megasas_readl(instance, |
| 6095 | &instance->reg_set->outbound_scratch_pad_3); |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6096 | if ((scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK) >= |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 6097 | MR_DEFAULT_NVME_PAGE_SHIFT) |
| 6098 | instance->nvme_page_size = |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6099 | (1 << (scratch_pad_3 & MR_NVME_PAGE_SIZE_MASK)); |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 6100 | |
| 6101 | dev_info(&instance->pdev->dev, |
| 6102 | "NVME page size\t: (%d)\n", instance->nvme_page_size); |
| 6103 | } |
| 6104 | |
Tomas Henzl | 18103ef | 2016-11-01 17:32:02 +0100 | [diff] [blame] | 6105 | if (instance->msix_vectors ? |
| 6106 | megasas_setup_irqs_msix(instance, 1) : |
| 6107 | megasas_setup_irqs_ioapic(instance)) |
| 6108 | goto fail_init_adapter; |
Tomas Henzl | 258c3af | 2015-06-02 16:09:46 +0530 | [diff] [blame] | 6109 | |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 6110 | if (instance->adapter_type != MFI_SERIES) |
| 6111 | megasas_setup_irq_poll(instance); |
| 6112 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6113 | instance->instancet->enable_intr(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 6114 | |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 6115 | dev_info(&instance->pdev->dev, "INIT adapter done\n"); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 6116 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 6117 | megasas_setup_jbod_map(instance); |
| 6118 | |
Shivasharan S | daa0681 | 2019-01-29 01:38:12 -0800 | [diff] [blame] | 6119 | if (megasas_get_device_list(instance) != SUCCESS) { |
| 6120 | dev_err(&instance->pdev->dev, |
| 6121 | "%s: megasas_get_device_list failed\n", |
| 6122 | __func__); |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 6123 | goto fail_get_ld_pd_list; |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 6124 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 6125 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6126 | /* stream detection initialization */ |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 6127 | if (instance->adapter_type >= VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6128 | fusion->stream_detect_by_ld = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6129 | kcalloc(MAX_LOGICAL_DRIVES_EXT, |
| 6130 | sizeof(struct LD_STREAM_DETECT *), |
| 6131 | GFP_KERNEL); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6132 | if (!fusion->stream_detect_by_ld) { |
| 6133 | dev_err(&instance->pdev->dev, |
Shivasharan S | 41064f1 | 2017-02-10 00:59:37 -0800 | [diff] [blame] | 6134 | "unable to allocate stream detection for pool of LDs\n"); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6135 | goto fail_get_ld_pd_list; |
| 6136 | } |
| 6137 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) { |
| 6138 | fusion->stream_detect_by_ld[i] = |
Shivasharan S | e05ee4e | 2018-01-05 05:27:36 -0800 | [diff] [blame] | 6139 | kzalloc(sizeof(struct LD_STREAM_DETECT), |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6140 | GFP_KERNEL); |
| 6141 | if (!fusion->stream_detect_by_ld[i]) { |
| 6142 | dev_err(&instance->pdev->dev, |
| 6143 | "unable to allocate stream detect by LD\n "); |
| 6144 | for (j = 0; j < i; ++j) |
| 6145 | kfree(fusion->stream_detect_by_ld[j]); |
| 6146 | kfree(fusion->stream_detect_by_ld); |
| 6147 | fusion->stream_detect_by_ld = NULL; |
| 6148 | goto fail_get_ld_pd_list; |
| 6149 | } |
| 6150 | fusion->stream_detect_by_ld[i]->mru_bit_map |
| 6151 | = MR_STREAM_BITMAP; |
| 6152 | } |
| 6153 | } |
| 6154 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6155 | /* |
| 6156 | * Compute the max allowed sectors per IO: The controller info has two |
| 6157 | * limits on max sectors. Driver should use the minimum of these two. |
| 6158 | * |
| 6159 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 6160 | * |
| 6161 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 6162 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 6163 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 6164 | tmp_sectors = 0; |
Shivasharan S | 9ad18a9 | 2017-10-19 02:48:57 -0700 | [diff] [blame] | 6165 | ctrl_info = instance->ctrl_info_buf; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6166 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6167 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 6168 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 6169 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6170 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 6171 | 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] | 6172 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 6173 | instance->peerIsPresent = ctrl_info->cluster.peerIsPresent; |
| 6174 | instance->passive = ctrl_info->cluster.passive; |
| 6175 | memcpy(instance->clusterId, ctrl_info->clusterId, sizeof(instance->clusterId)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6176 | instance->UnevenSpanSupport = |
| 6177 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 6178 | if (instance->UnevenSpanSupport) { |
| 6179 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 5f19f7c | 2018-01-05 05:27:44 -0800 | [diff] [blame] | 6180 | if (MR_ValidateMapInfo(instance, instance->map_id)) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6181 | fusion->fast_path_io = 1; |
| 6182 | else |
| 6183 | fusion->fast_path_io = 0; |
| 6184 | |
| 6185 | } |
| 6186 | if (ctrl_info->host_interface.SRIOV) { |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 6187 | instance->requestorId = ctrl_info->iov.requestorId; |
| 6188 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) { |
| 6189 | if (!ctrl_info->adapterOperations2.activePassive) |
| 6190 | instance->PlasmaFW111 = 1; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6191 | |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 6192 | dev_info(&instance->pdev->dev, "SR-IOV: firmware type: %s\n", |
| 6193 | instance->PlasmaFW111 ? "1.11" : "new"); |
| 6194 | |
| 6195 | if (instance->PlasmaFW111) { |
| 6196 | iovPtr = (struct IOV_111 *) |
| 6197 | ((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 6198 | instance->requestorId = iovPtr->requestorId; |
| 6199 | } |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 6200 | } |
sumit.saxena@avagotech.com | 92bb650 | 2015-08-31 17:24:11 +0530 | [diff] [blame] | 6201 | dev_info(&instance->pdev->dev, "SRIOV: VF requestorId %d\n", |
| 6202 | instance->requestorId); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6203 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 6204 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6205 | instance->crash_dump_fw_support = |
| 6206 | ctrl_info->adapterOperations3.supportCrashDump; |
| 6207 | instance->crash_dump_drv_support = |
| 6208 | (instance->crash_dump_fw_support && |
| 6209 | instance->crash_dump_buf); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 6210 | if (instance->crash_dump_drv_support) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6211 | megasas_set_crash_dump_params(instance, |
| 6212 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6213 | |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 6214 | else { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6215 | if (instance->crash_dump_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6216 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 6217 | CRASH_DMA_BUF_SIZE, |
| 6218 | instance->crash_dump_buf, |
| 6219 | instance->crash_dump_h); |
| 6220 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 6221 | } |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 6222 | |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 6223 | if (instance->snapdump_wait_time) { |
| 6224 | megasas_get_snapdump_properties(instance); |
| 6225 | dev_info(&instance->pdev->dev, "Snap dump wait time\t: %d\n", |
| 6226 | instance->snapdump_wait_time); |
| 6227 | } |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 6228 | |
| 6229 | dev_info(&instance->pdev->dev, |
| 6230 | "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n", |
| 6231 | le16_to_cpu(ctrl_info->pci.vendor_id), |
| 6232 | le16_to_cpu(ctrl_info->pci.device_id), |
| 6233 | le16_to_cpu(ctrl_info->pci.sub_vendor_id), |
| 6234 | le16_to_cpu(ctrl_info->pci.sub_device_id)); |
| 6235 | dev_info(&instance->pdev->dev, "unevenspan support : %s\n", |
| 6236 | instance->UnevenSpanSupport ? "yes" : "no"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 6237 | dev_info(&instance->pdev->dev, "firmware crash dump : %s\n", |
| 6238 | instance->crash_dump_drv_support ? "yes" : "no"); |
Chandrakanth Patil | 59db5a9 | 2019-06-25 16:34:26 +0530 | [diff] [blame] | 6239 | dev_info(&instance->pdev->dev, "JBOD sequence map : %s\n", |
| 6240 | instance->use_seqnum_jbod_fp ? "enabled" : "disabled"); |
Sumit.Saxena@avagotech.com | d88da09 | 2015-04-23 16:31:09 +0530 | [diff] [blame] | 6241 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 6242 | instance->max_sectors_per_req = instance->max_num_sge * |
sumit.saxena@avagotech.com | 357ae96 | 2015-10-15 13:40:04 +0530 | [diff] [blame] | 6243 | SGE_BUFFER_SIZE / 512; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 6244 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 6245 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6246 | |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6247 | /* Check for valid throttlequeuedepth module parameter */ |
| 6248 | if (throttlequeuedepth && |
| 6249 | throttlequeuedepth <= instance->max_scsi_cmds) |
| 6250 | instance->throttlequeuedepth = throttlequeuedepth; |
| 6251 | else |
| 6252 | instance->throttlequeuedepth = |
| 6253 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 6254 | |
Shivasharan S | e636a7a | 2017-08-23 04:46:56 -0700 | [diff] [blame] | 6255 | if ((resetwaittime < 1) || |
| 6256 | (resetwaittime > MEGASAS_RESET_WAIT_TIME)) |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 6257 | resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 6258 | |
| 6259 | if ((scmd_timeout < 10) || (scmd_timeout > MEGASAS_DEFAULT_CMD_TIMEOUT)) |
| 6260 | scmd_timeout = MEGASAS_DEFAULT_CMD_TIMEOUT; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6261 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6262 | /* Launch SR-IOV heartbeat timer */ |
| 6263 | if (instance->requestorId) { |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 6264 | if (!megasas_sriov_start_heartbeat(instance, 1)) { |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 6265 | megasas_start_timer(instance); |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 6266 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6267 | instance->skip_heartbeat_timer_del = 1; |
Shivasharan S | 2e47e4e | 2018-10-16 23:37:48 -0700 | [diff] [blame] | 6268 | goto fail_get_ld_pd_list; |
| 6269 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6270 | } |
| 6271 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6272 | /* |
| 6273 | * Create and start watchdog thread which will monitor |
| 6274 | * controller state every 1 sec and trigger OCR when |
| 6275 | * it enters fault state |
| 6276 | */ |
| 6277 | if (instance->adapter_type != MFI_SERIES) |
| 6278 | if (megasas_fusion_start_watchdog(instance) != SUCCESS) |
| 6279 | goto fail_start_watchdog; |
| 6280 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6281 | return 0; |
| 6282 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 6283 | fail_start_watchdog: |
| 6284 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 6285 | del_timer_sync(&instance->sriov_heartbeat_timer); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 6286 | fail_get_ld_pd_list: |
| 6287 | instance->instancet->disable_intr(instance); |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6288 | megasas_destroy_irqs(instance); |
Shivasharan S | 8a25fa1 | 2018-10-16 23:37:44 -0700 | [diff] [blame] | 6289 | fail_init_adapter: |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6290 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 6291 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 6292 | instance->msix_vectors = 0; |
Shivasharan S | e5d65b4 | 2017-10-19 02:48:59 -0700 | [diff] [blame] | 6293 | fail_alloc_dma_buf: |
| 6294 | megasas_free_ctrl_dma_buffers(instance); |
| 6295 | megasas_free_ctrl_mem(instance); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 6296 | fail_ready_state: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6297 | iounmap(instance->reg_set); |
| 6298 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 6299 | fail_ioremap: |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 6300 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6301 | |
Shivasharan S | 72bff2d | 2017-02-10 00:59:33 -0800 | [diff] [blame] | 6302 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 6303 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6304 | return -EINVAL; |
| 6305 | } |
| 6306 | |
| 6307 | /** |
| 6308 | * megasas_release_mfi - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 6309 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6310 | */ |
| 6311 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 6312 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6313 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6314 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6315 | if (instance->reply_queue) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6316 | dma_free_coherent(&instance->pdev->dev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6317 | instance->reply_queue, instance->reply_queue_h); |
| 6318 | |
| 6319 | megasas_free_cmds(instance); |
| 6320 | |
| 6321 | iounmap(instance->reg_set); |
| 6322 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 6323 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | /** |
| 6327 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 6328 | * @instance: Adapter soft state |
| 6329 | * @eli: FW event log sequence numbers information |
| 6330 | * |
| 6331 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 6332 | * usually find out the latest sequence number of the events, the seq number at |
| 6333 | * the boot etc. They would "read" all the events below the latest seq number |
| 6334 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 6335 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 6336 | * wait for the events to happen. |
| 6337 | */ |
| 6338 | static int |
| 6339 | megasas_get_seq_num(struct megasas_instance *instance, |
| 6340 | struct megasas_evt_log_info *eli) |
| 6341 | { |
| 6342 | struct megasas_cmd *cmd; |
| 6343 | struct megasas_dcmd_frame *dcmd; |
| 6344 | struct megasas_evt_log_info *el_info; |
| 6345 | dma_addr_t el_info_h = 0; |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6346 | int ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6347 | |
| 6348 | cmd = megasas_get_cmd(instance); |
| 6349 | |
| 6350 | if (!cmd) { |
| 6351 | return -ENOMEM; |
| 6352 | } |
| 6353 | |
| 6354 | dcmd = &cmd->frame->dcmd; |
Luis Chamberlain | 750afb0 | 2019-01-04 09:23:09 +0100 | [diff] [blame] | 6355 | el_info = dma_alloc_coherent(&instance->pdev->dev, |
| 6356 | sizeof(struct megasas_evt_log_info), |
| 6357 | &el_info_h, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6358 | if (!el_info) { |
| 6359 | megasas_return_cmd(instance, cmd); |
| 6360 | return -ENOMEM; |
| 6361 | } |
| 6362 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6363 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6364 | |
| 6365 | dcmd->cmd = MFI_CMD_DCMD; |
| 6366 | dcmd->cmd_status = 0x0; |
| 6367 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6368 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6369 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6370 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6371 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 6372 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6373 | |
| 6374 | megasas_set_dma_settings(instance, dcmd, el_info_h, |
| 6375 | sizeof(struct megasas_evt_log_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6376 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6377 | ret = megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS); |
| 6378 | if (ret != DCMD_SUCCESS) { |
| 6379 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 6380 | __func__, __LINE__); |
| 6381 | goto dcmd_failed; |
| 6382 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6383 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6384 | /* |
| 6385 | * Copy the data back into callers buffer |
| 6386 | */ |
| 6387 | eli->newest_seq_num = el_info->newest_seq_num; |
| 6388 | eli->oldest_seq_num = el_info->oldest_seq_num; |
| 6389 | eli->clear_seq_num = el_info->clear_seq_num; |
| 6390 | eli->shutdown_seq_num = el_info->shutdown_seq_num; |
| 6391 | eli->boot_seq_num = el_info->boot_seq_num; |
| 6392 | |
| 6393 | dcmd_failed: |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6394 | dma_free_coherent(&instance->pdev->dev, |
| 6395 | sizeof(struct megasas_evt_log_info), |
| 6396 | el_info, el_info_h); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6397 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6398 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6399 | |
Shivasharan S | b051cc6 | 2018-01-05 05:27:38 -0800 | [diff] [blame] | 6400 | return ret; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6401 | } |
| 6402 | |
| 6403 | /** |
| 6404 | * megasas_register_aen - Registers for asynchronous event notification |
| 6405 | * @instance: Adapter soft state |
| 6406 | * @seq_num: The starting sequence number |
| 6407 | * @class_locale: Class of the event |
| 6408 | * |
| 6409 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 6410 | * to be notified if and only if the event is of type @class_locale |
| 6411 | */ |
| 6412 | static int |
| 6413 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 6414 | u32 class_locale_word) |
| 6415 | { |
| 6416 | int ret_val; |
| 6417 | struct megasas_cmd *cmd; |
| 6418 | struct megasas_dcmd_frame *dcmd; |
| 6419 | union megasas_evt_class_locale curr_aen; |
| 6420 | union megasas_evt_class_locale prev_aen; |
| 6421 | |
| 6422 | /* |
| 6423 | * If there an AEN pending already (aen_cmd), check if the |
| 6424 | * class_locale of that pending AEN is inclusive of the new |
| 6425 | * AEN request we currently have. If it is, then we don't have |
| 6426 | * to do anything. In other words, whichever events the current |
| 6427 | * AEN request is subscribing to, have already been subscribed |
| 6428 | * to. |
| 6429 | * |
| 6430 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 6431 | * that command, form a class_locale that is superset of both |
| 6432 | * old and current and re-issue to the FW |
| 6433 | */ |
| 6434 | |
| 6435 | curr_aen.word = class_locale_word; |
| 6436 | |
| 6437 | if (instance->aen_cmd) { |
| 6438 | |
Christoph Hellwig | a955553 | 2015-04-23 16:34:24 +0530 | [diff] [blame] | 6439 | prev_aen.word = |
| 6440 | le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6441 | |
Shivasharan S | 91b3d9f | 2017-08-23 04:47:01 -0700 | [diff] [blame] | 6442 | if ((curr_aen.members.class < MFI_EVT_CLASS_DEBUG) || |
| 6443 | (curr_aen.members.class > MFI_EVT_CLASS_DEAD)) { |
| 6444 | dev_info(&instance->pdev->dev, |
| 6445 | "%s %d out of range class %d send by application\n", |
| 6446 | __func__, __LINE__, curr_aen.members.class); |
| 6447 | return 0; |
| 6448 | } |
| 6449 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6450 | /* |
| 6451 | * A class whose enum value is smaller is inclusive of all |
| 6452 | * higher values. If a PROGRESS (= -1) was previously |
| 6453 | * registered, then a new registration requests for higher |
| 6454 | * classes need not be sent to FW. They are automatically |
| 6455 | * included. |
| 6456 | * |
| 6457 | * Locale numbers don't have such hierarchy. They are bitmap |
| 6458 | * values |
| 6459 | */ |
| 6460 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 6461 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6462 | curr_aen.members.locale)) { |
| 6463 | /* |
| 6464 | * Previously issued event registration includes |
| 6465 | * current request. Nothing to do. |
| 6466 | */ |
| 6467 | return 0; |
| 6468 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 6469 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6470 | |
| 6471 | if (prev_aen.members.class < curr_aen.members.class) |
| 6472 | curr_aen.members.class = prev_aen.members.class; |
| 6473 | |
| 6474 | instance->aen_cmd->abort_aen = 1; |
| 6475 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 6476 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6477 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6478 | |
| 6479 | if (ret_val) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6480 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to abort " |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6481 | "previous AEN command\n"); |
| 6482 | return ret_val; |
| 6483 | } |
| 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | cmd = megasas_get_cmd(instance); |
| 6488 | |
| 6489 | if (!cmd) |
| 6490 | return -ENOMEM; |
| 6491 | |
| 6492 | dcmd = &cmd->frame->dcmd; |
| 6493 | |
| 6494 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 6495 | |
| 6496 | /* |
| 6497 | * Prepare DCMD for aen registration |
| 6498 | */ |
| 6499 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6500 | |
| 6501 | dcmd->cmd = MFI_CMD_DCMD; |
| 6502 | dcmd->cmd_status = 0x0; |
| 6503 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6504 | dcmd->flags = MFI_FRAME_DIR_READ; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6505 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 6506 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6507 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 6508 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 6509 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6510 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6511 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6512 | |
| 6513 | megasas_set_dma_settings(instance, dcmd, instance->evt_detail_h, |
| 6514 | sizeof(struct megasas_evt_detail)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6515 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 6516 | if (instance->aen_cmd != NULL) { |
| 6517 | megasas_return_cmd(instance, cmd); |
| 6518 | return 0; |
| 6519 | } |
| 6520 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6521 | /* |
| 6522 | * Store reference to the cmd used to register for AEN. When an |
| 6523 | * application wants us to register for AEN, we have to abort this |
| 6524 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 6525 | */ |
| 6526 | instance->aen_cmd = cmd; |
| 6527 | |
| 6528 | /* |
| 6529 | * Issue the aen registration frame |
| 6530 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6531 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6532 | |
| 6533 | return 0; |
| 6534 | } |
| 6535 | |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6536 | /* megasas_get_target_prop - Send DCMD with below details to firmware. |
| 6537 | * |
| 6538 | * This DCMD will fetch few properties of LD/system PD defined |
| 6539 | * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value. |
| 6540 | * |
| 6541 | * DCMD send by drivers whenever new target is added to the OS. |
| 6542 | * |
| 6543 | * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP |
| 6544 | * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD. |
| 6545 | * 0 = system PD, 1 = LD. |
| 6546 | * dcmd.mbox.s[1] - TargetID for LD/system PD. |
| 6547 | * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES. |
| 6548 | * |
| 6549 | * @instance: Adapter soft state |
| 6550 | * @sdev: OS provided scsi device |
| 6551 | * |
| 6552 | * Returns 0 on success non-zero on failure. |
| 6553 | */ |
Shivasharan S | e9495e2 | 2018-06-04 03:45:12 -0700 | [diff] [blame] | 6554 | int |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6555 | megasas_get_target_prop(struct megasas_instance *instance, |
| 6556 | struct scsi_device *sdev) |
| 6557 | { |
| 6558 | int ret; |
| 6559 | struct megasas_cmd *cmd; |
| 6560 | struct megasas_dcmd_frame *dcmd; |
| 6561 | u16 targetId = (sdev->channel % 2) + sdev->id; |
| 6562 | |
| 6563 | cmd = megasas_get_cmd(instance); |
| 6564 | |
| 6565 | if (!cmd) { |
| 6566 | dev_err(&instance->pdev->dev, |
| 6567 | "Failed to get cmd %s\n", __func__); |
| 6568 | return -ENOMEM; |
| 6569 | } |
| 6570 | |
| 6571 | dcmd = &cmd->frame->dcmd; |
| 6572 | |
| 6573 | memset(instance->tgt_prop, 0, sizeof(*instance->tgt_prop)); |
| 6574 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 6575 | dcmd->mbox.b[0] = MEGASAS_IS_LOGICAL(sdev); |
| 6576 | |
| 6577 | dcmd->mbox.s[1] = cpu_to_le16(targetId); |
| 6578 | dcmd->cmd = MFI_CMD_DCMD; |
| 6579 | dcmd->cmd_status = 0xFF; |
| 6580 | dcmd->sge_count = 1; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6581 | dcmd->flags = MFI_FRAME_DIR_READ; |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6582 | dcmd->timeout = 0; |
| 6583 | dcmd->pad_0 = 0; |
| 6584 | dcmd->data_xfer_len = |
| 6585 | cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES)); |
| 6586 | dcmd->opcode = cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6587 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6588 | megasas_set_dma_settings(instance, dcmd, instance->tgt_prop_h, |
| 6589 | sizeof(struct MR_TARGET_PROPERTIES)); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6590 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 6591 | if ((instance->adapter_type != MFI_SERIES) && |
| 6592 | !instance->mask_interrupts) |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6593 | ret = megasas_issue_blocked_cmd(instance, |
| 6594 | cmd, MFI_IO_TIMEOUT_SECS); |
| 6595 | else |
| 6596 | ret = megasas_issue_polled(instance, cmd); |
| 6597 | |
| 6598 | switch (ret) { |
| 6599 | case DCMD_TIMEOUT: |
| 6600 | switch (dcmd_timeout_ocr_possible(instance)) { |
| 6601 | case INITIATE_OCR: |
| 6602 | cmd->flags |= DRV_DCMD_SKIP_REFIRE; |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 6603 | mutex_unlock(&instance->reset_mutex); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6604 | megasas_reset_fusion(instance->host, |
| 6605 | MFI_IO_TIMEOUT_OCR); |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 6606 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | 96188a8 | 2017-02-10 00:59:11 -0800 | [diff] [blame] | 6607 | break; |
| 6608 | case KILL_ADAPTER: |
| 6609 | megaraid_sas_kill_hba(instance); |
| 6610 | break; |
| 6611 | case IGNORE_TIMEOUT: |
| 6612 | dev_info(&instance->pdev->dev, |
| 6613 | "Ignore DCMD timeout: %s %d\n", |
| 6614 | __func__, __LINE__); |
| 6615 | break; |
| 6616 | } |
| 6617 | break; |
| 6618 | |
| 6619 | default: |
| 6620 | megasas_return_cmd(instance, cmd); |
| 6621 | } |
| 6622 | if (ret != DCMD_SUCCESS) |
| 6623 | dev_err(&instance->pdev->dev, |
| 6624 | "return from %s %d return value %d\n", |
| 6625 | __func__, __LINE__, ret); |
| 6626 | |
| 6627 | return ret; |
| 6628 | } |
| 6629 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6630 | /** |
| 6631 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 6632 | * @instance: Adapter soft state |
| 6633 | */ |
| 6634 | static int megasas_start_aen(struct megasas_instance *instance) |
| 6635 | { |
| 6636 | struct megasas_evt_log_info eli; |
| 6637 | union megasas_evt_class_locale class_locale; |
| 6638 | |
| 6639 | /* |
| 6640 | * Get the latest sequence number from FW |
| 6641 | */ |
| 6642 | memset(&eli, 0, sizeof(eli)); |
| 6643 | |
| 6644 | if (megasas_get_seq_num(instance, &eli)) |
| 6645 | return -1; |
| 6646 | |
| 6647 | /* |
| 6648 | * Register AEN with FW for latest sequence number plus 1 |
| 6649 | */ |
| 6650 | class_locale.members.reserved = 0; |
| 6651 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 6652 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 6653 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6654 | return megasas_register_aen(instance, |
Christoph Hellwig | 48100b0 | 2015-04-23 16:33:24 +0530 | [diff] [blame] | 6655 | le32_to_cpu(eli.newest_seq_num) + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6656 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | /** |
| 6660 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 6661 | * @instance: Adapter soft state |
| 6662 | */ |
| 6663 | static int megasas_io_attach(struct megasas_instance *instance) |
| 6664 | { |
| 6665 | struct Scsi_Host *host = instance->host; |
| 6666 | |
| 6667 | /* |
| 6668 | * Export parameters required by SCSI mid-layer |
| 6669 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6670 | host->unique_id = instance->unique_id; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 6671 | host->can_queue = instance->max_scsi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6672 | host->this_id = instance->init_id; |
| 6673 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 6674 | |
| 6675 | if (instance->fw_support_ieee) |
| 6676 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 6677 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 6678 | /* |
| 6679 | * Check if the module parameter value for max_sectors can be used |
| 6680 | */ |
| 6681 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 6682 | instance->max_sectors_per_req = max_sectors; |
| 6683 | else { |
| 6684 | if (max_sectors) { |
| 6685 | if (((instance->pdev->device == |
| 6686 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 6687 | (instance->pdev->device == |
| 6688 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 6689 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 6690 | instance->max_sectors_per_req = max_sectors; |
| 6691 | } else { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 6692 | dev_info(&instance->pdev->dev, "max_sectors should be > 0" |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 6693 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 6694 | instance->max_sectors_per_req); |
| 6695 | } |
| 6696 | } |
| 6697 | } |
| 6698 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6699 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6700 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6701 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 6702 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6703 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 6704 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6705 | |
| 6706 | /* |
| 6707 | * Notify the mid-layer about the new controller |
| 6708 | */ |
| 6709 | if (scsi_add_host(host, &instance->pdev->dev)) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 6710 | dev_err(&instance->pdev->dev, |
| 6711 | "Failed to add host from %s %d\n", |
| 6712 | __func__, __LINE__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6713 | return -ENODEV; |
| 6714 | } |
| 6715 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6716 | return 0; |
| 6717 | } |
| 6718 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6719 | /** |
| 6720 | * megasas_set_dma_mask - Set DMA mask for supported controllers |
| 6721 | * |
| 6722 | * @instance: Adapter soft state |
| 6723 | * Description: |
| 6724 | * |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6725 | * For Ventura, driver/FW will operate in 63bit DMA addresses. |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6726 | * |
| 6727 | * For invader- |
| 6728 | * By default, driver/FW will operate in 32bit DMA addresses |
| 6729 | * for consistent DMA mapping but if 32 bit consistent |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6730 | * DMA mask fails, driver will try with 63 bit consistent |
| 6731 | * mask provided FW is true 63bit DMA capable |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6732 | * |
| 6733 | * For older controllers(Thunderbolt and MFI based adapters)- |
| 6734 | * driver/FW will operate in 32 bit consistent DMA addresses. |
| 6735 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6736 | static int |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6737 | megasas_set_dma_mask(struct megasas_instance *instance) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6738 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6739 | u64 consistent_mask; |
| 6740 | struct pci_dev *pdev; |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6741 | u32 scratch_pad_1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6742 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6743 | pdev = instance->pdev; |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 6744 | consistent_mask = (instance->adapter_type >= VENTURA_SERIES) ? |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6745 | DMA_BIT_MASK(63) : DMA_BIT_MASK(32); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6746 | |
| 6747 | if (IS_DMA64) { |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6748 | if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(63)) && |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6749 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6750 | goto fail_set_dma_mask; |
| 6751 | |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6752 | if ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) && |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6753 | (dma_set_coherent_mask(&pdev->dev, consistent_mask) && |
| 6754 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)))) { |
| 6755 | /* |
| 6756 | * If 32 bit DMA mask fails, then try for 64 bit mask |
| 6757 | * for FW capable of handling 64 bit DMA. |
| 6758 | */ |
Shivasharan S | 272652f | 2018-12-17 00:47:40 -0800 | [diff] [blame] | 6759 | scratch_pad_1 = megasas_readl |
| 6760 | (instance, &instance->reg_set->outbound_scratch_pad_1); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6761 | |
Shivasharan S | 81b7645 | 2018-10-16 23:37:51 -0700 | [diff] [blame] | 6762 | if (!(scratch_pad_1 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET)) |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6763 | goto fail_set_dma_mask; |
| 6764 | else if (dma_set_mask_and_coherent(&pdev->dev, |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6765 | DMA_BIT_MASK(63))) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6766 | goto fail_set_dma_mask; |
| 6767 | } |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6768 | } else if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) |
| 6769 | goto fail_set_dma_mask; |
| 6770 | |
| 6771 | if (pdev->dev.coherent_dma_mask == DMA_BIT_MASK(32)) |
| 6772 | instance->consistent_mask_64bit = false; |
| 6773 | else |
| 6774 | instance->consistent_mask_64bit = true; |
| 6775 | |
| 6776 | 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] | 6777 | ((*pdev->dev.dma_mask == DMA_BIT_MASK(63)) ? "63" : "32"), |
Shivasharan S | 894169d | 2018-12-18 05:59:54 -0800 | [diff] [blame] | 6778 | (instance->consistent_mask_64bit ? "63" : "32")); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6779 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6780 | return 0; |
| 6781 | |
| 6782 | fail_set_dma_mask: |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 6783 | dev_err(&pdev->dev, "Failed to set DMA mask\n"); |
| 6784 | return -1; |
| 6785 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6786 | } |
| 6787 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6788 | /* |
| 6789 | * megasas_set_adapter_type - Set adapter type. |
| 6790 | * Supported controllers can be divided in |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6791 | * different categories- |
| 6792 | * enum MR_ADAPTER_TYPE { |
| 6793 | * MFI_SERIES = 1, |
| 6794 | * THUNDERBOLT_SERIES = 2, |
| 6795 | * INVADER_SERIES = 3, |
| 6796 | * VENTURA_SERIES = 4, |
| 6797 | * AERO_SERIES = 5, |
| 6798 | * }; |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6799 | * @instance: Adapter soft state |
| 6800 | * return: void |
| 6801 | */ |
| 6802 | static inline void megasas_set_adapter_type(struct megasas_instance *instance) |
| 6803 | { |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6804 | if ((instance->pdev->vendor == PCI_VENDOR_ID_DELL) && |
| 6805 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5)) { |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6806 | instance->adapter_type = MFI_SERIES; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6807 | } else { |
| 6808 | switch (instance->pdev->device) { |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 6809 | case PCI_DEVICE_ID_LSI_AERO_10E1: |
| 6810 | case PCI_DEVICE_ID_LSI_AERO_10E2: |
| 6811 | case PCI_DEVICE_ID_LSI_AERO_10E5: |
| 6812 | case PCI_DEVICE_ID_LSI_AERO_10E6: |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6813 | instance->adapter_type = AERO_SERIES; |
| 6814 | break; |
Shivasharan S | 754f1ba | 2017-10-19 02:48:49 -0700 | [diff] [blame] | 6815 | case PCI_DEVICE_ID_LSI_VENTURA: |
| 6816 | case PCI_DEVICE_ID_LSI_CRUSADER: |
| 6817 | case PCI_DEVICE_ID_LSI_HARPOON: |
| 6818 | case PCI_DEVICE_ID_LSI_TOMCAT: |
| 6819 | case PCI_DEVICE_ID_LSI_VENTURA_4PORT: |
| 6820 | case PCI_DEVICE_ID_LSI_CRUSADER_4PORT: |
| 6821 | instance->adapter_type = VENTURA_SERIES; |
| 6822 | break; |
| 6823 | case PCI_DEVICE_ID_LSI_FUSION: |
| 6824 | case PCI_DEVICE_ID_LSI_PLASMA: |
| 6825 | instance->adapter_type = THUNDERBOLT_SERIES; |
| 6826 | break; |
| 6827 | case PCI_DEVICE_ID_LSI_INVADER: |
| 6828 | case PCI_DEVICE_ID_LSI_INTRUDER: |
| 6829 | case PCI_DEVICE_ID_LSI_INTRUDER_24: |
| 6830 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 6831 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
| 6832 | case PCI_DEVICE_ID_LSI_FURY: |
| 6833 | instance->adapter_type = INVADER_SERIES; |
| 6834 | break; |
| 6835 | default: /* For all other supported controllers */ |
| 6836 | instance->adapter_type = MFI_SERIES; |
| 6837 | break; |
| 6838 | } |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 6839 | } |
| 6840 | } |
| 6841 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6842 | static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance) |
| 6843 | { |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6844 | instance->producer = dma_alloc_coherent(&instance->pdev->dev, |
| 6845 | sizeof(u32), &instance->producer_h, GFP_KERNEL); |
| 6846 | instance->consumer = dma_alloc_coherent(&instance->pdev->dev, |
| 6847 | sizeof(u32), &instance->consumer_h, GFP_KERNEL); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6848 | |
| 6849 | if (!instance->producer || !instance->consumer) { |
| 6850 | dev_err(&instance->pdev->dev, |
| 6851 | "Failed to allocate memory for producer, consumer\n"); |
| 6852 | return -1; |
| 6853 | } |
| 6854 | |
| 6855 | *instance->producer = 0; |
| 6856 | *instance->consumer = 0; |
| 6857 | return 0; |
| 6858 | } |
| 6859 | |
| 6860 | /** |
| 6861 | * megasas_alloc_ctrl_mem - Allocate per controller memory for core data |
| 6862 | * structures which are not common across MFI |
| 6863 | * adapters and fusion adapters. |
| 6864 | * For MFI based adapters, allocate producer and |
| 6865 | * consumer buffers. For fusion adapters, allocate |
| 6866 | * memory for fusion context. |
| 6867 | * @instance: Adapter soft state |
| 6868 | * return: 0 for SUCCESS |
| 6869 | */ |
| 6870 | static int megasas_alloc_ctrl_mem(struct megasas_instance *instance) |
| 6871 | { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6872 | instance->reply_map = kcalloc(nr_cpu_ids, sizeof(unsigned int), |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6873 | GFP_KERNEL); |
| 6874 | if (!instance->reply_map) |
| 6875 | return -ENOMEM; |
| 6876 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6877 | switch (instance->adapter_type) { |
| 6878 | case MFI_SERIES: |
| 6879 | if (megasas_alloc_mfi_ctrl_mem(instance)) |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6880 | goto fail; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6881 | break; |
Shivasharan S | 154a7cd | 2018-12-17 00:47:38 -0800 | [diff] [blame] | 6882 | case AERO_SERIES: |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6883 | case VENTURA_SERIES: |
| 6884 | case THUNDERBOLT_SERIES: |
| 6885 | case INVADER_SERIES: |
| 6886 | if (megasas_alloc_fusion_context(instance)) |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6887 | goto fail; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6888 | break; |
| 6889 | } |
| 6890 | |
| 6891 | return 0; |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6892 | fail: |
| 6893 | kfree(instance->reply_map); |
| 6894 | instance->reply_map = NULL; |
| 6895 | return -ENOMEM; |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | /* |
| 6899 | * megasas_free_ctrl_mem - Free fusion context for fusion adapters and |
| 6900 | * producer, consumer buffers for MFI adapters |
| 6901 | * |
| 6902 | * @instance - Adapter soft instance |
| 6903 | * |
| 6904 | */ |
| 6905 | static inline void megasas_free_ctrl_mem(struct megasas_instance *instance) |
| 6906 | { |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 6907 | kfree(instance->reply_map); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6908 | if (instance->adapter_type == MFI_SERIES) { |
| 6909 | if (instance->producer) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6910 | dma_free_coherent(&instance->pdev->dev, sizeof(u32), |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6911 | instance->producer, |
| 6912 | instance->producer_h); |
| 6913 | if (instance->consumer) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6914 | dma_free_coherent(&instance->pdev->dev, sizeof(u32), |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 6915 | instance->consumer, |
| 6916 | instance->consumer_h); |
| 6917 | } else { |
| 6918 | megasas_free_fusion_context(instance); |
| 6919 | } |
| 6920 | } |
| 6921 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6922 | /** |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6923 | * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during |
| 6924 | * driver load time |
| 6925 | * |
| 6926 | * @instance- Adapter soft instance |
| 6927 | * @return- O for SUCCESS |
| 6928 | */ |
| 6929 | static inline |
| 6930 | int megasas_alloc_ctrl_dma_buffers(struct megasas_instance *instance) |
| 6931 | { |
| 6932 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6933 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6934 | |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6935 | instance->evt_detail = dma_alloc_coherent(&pdev->dev, |
| 6936 | sizeof(struct megasas_evt_detail), |
| 6937 | &instance->evt_detail_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 6938 | |
| 6939 | if (!instance->evt_detail) { |
| 6940 | dev_err(&instance->pdev->dev, |
| 6941 | "Failed to allocate event detail buffer\n"); |
| 6942 | return -ENOMEM; |
| 6943 | } |
| 6944 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6945 | if (fusion) { |
| 6946 | fusion->ioc_init_request = |
| 6947 | dma_alloc_coherent(&pdev->dev, |
| 6948 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 6949 | &fusion->ioc_init_request_phys, |
| 6950 | GFP_KERNEL); |
| 6951 | |
| 6952 | if (!fusion->ioc_init_request) { |
| 6953 | dev_err(&pdev->dev, |
| 6954 | "Failed to allocate PD list buffer\n"); |
| 6955 | return -ENOMEM; |
| 6956 | } |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 6957 | |
| 6958 | instance->snapdump_prop = dma_alloc_coherent(&pdev->dev, |
| 6959 | sizeof(struct MR_SNAPDUMP_PROPERTIES), |
| 6960 | &instance->snapdump_prop_h, GFP_KERNEL); |
| 6961 | |
| 6962 | if (!instance->snapdump_prop) |
| 6963 | dev_err(&pdev->dev, |
| 6964 | "Failed to allocate snapdump properties buffer\n"); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 6965 | |
| 6966 | instance->host_device_list_buf = dma_alloc_coherent(&pdev->dev, |
| 6967 | HOST_DEVICE_LIST_SZ, |
| 6968 | &instance->host_device_list_buf_h, |
| 6969 | GFP_KERNEL); |
| 6970 | |
| 6971 | if (!instance->host_device_list_buf) { |
| 6972 | dev_err(&pdev->dev, |
| 6973 | "Failed to allocate targetid list buffer\n"); |
| 6974 | return -ENOMEM; |
| 6975 | } |
| 6976 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6977 | } |
| 6978 | |
| 6979 | instance->pd_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6980 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6981 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6982 | &instance->pd_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6983 | |
| 6984 | if (!instance->pd_list_buf) { |
| 6985 | dev_err(&pdev->dev, "Failed to allocate PD list buffer\n"); |
| 6986 | return -ENOMEM; |
| 6987 | } |
| 6988 | |
| 6989 | instance->ctrl_info_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6990 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6991 | sizeof(struct megasas_ctrl_info), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 6992 | &instance->ctrl_info_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 6993 | |
| 6994 | if (!instance->ctrl_info_buf) { |
| 6995 | dev_err(&pdev->dev, |
| 6996 | "Failed to allocate controller info buffer\n"); |
| 6997 | return -ENOMEM; |
| 6998 | } |
| 6999 | |
| 7000 | instance->ld_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7001 | dma_alloc_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7002 | sizeof(struct MR_LD_LIST), |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7003 | &instance->ld_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7004 | |
| 7005 | if (!instance->ld_list_buf) { |
| 7006 | dev_err(&pdev->dev, "Failed to allocate LD list buffer\n"); |
| 7007 | return -ENOMEM; |
| 7008 | } |
| 7009 | |
| 7010 | instance->ld_targetid_list_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7011 | dma_alloc_coherent(&pdev->dev, |
| 7012 | sizeof(struct MR_LD_TARGETID_LIST), |
| 7013 | &instance->ld_targetid_list_buf_h, GFP_KERNEL); |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7014 | |
| 7015 | if (!instance->ld_targetid_list_buf) { |
| 7016 | dev_err(&pdev->dev, |
| 7017 | "Failed to allocate LD targetid list buffer\n"); |
| 7018 | return -ENOMEM; |
| 7019 | } |
| 7020 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7021 | if (!reset_devices) { |
| 7022 | instance->system_info_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7023 | dma_alloc_coherent(&pdev->dev, |
| 7024 | sizeof(struct MR_DRV_SYSTEM_INFO), |
| 7025 | &instance->system_info_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7026 | instance->pd_info = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7027 | dma_alloc_coherent(&pdev->dev, |
| 7028 | sizeof(struct MR_PD_INFO), |
| 7029 | &instance->pd_info_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7030 | instance->tgt_prop = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7031 | dma_alloc_coherent(&pdev->dev, |
| 7032 | sizeof(struct MR_TARGET_PROPERTIES), |
| 7033 | &instance->tgt_prop_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7034 | instance->crash_dump_buf = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7035 | dma_alloc_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE, |
| 7036 | &instance->crash_dump_h, GFP_KERNEL); |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7037 | |
| 7038 | if (!instance->system_info_buf) |
| 7039 | dev_err(&instance->pdev->dev, |
| 7040 | "Failed to allocate system info buffer\n"); |
| 7041 | |
| 7042 | if (!instance->pd_info) |
| 7043 | dev_err(&instance->pdev->dev, |
| 7044 | "Failed to allocate pd_info buffer\n"); |
| 7045 | |
| 7046 | if (!instance->tgt_prop) |
| 7047 | dev_err(&instance->pdev->dev, |
| 7048 | "Failed to allocate tgt_prop buffer\n"); |
| 7049 | |
| 7050 | if (!instance->crash_dump_buf) |
| 7051 | dev_err(&instance->pdev->dev, |
| 7052 | "Failed to allocate crash dump buffer\n"); |
| 7053 | } |
| 7054 | |
| 7055 | return 0; |
| 7056 | } |
| 7057 | |
| 7058 | /* |
| 7059 | * megasas_free_ctrl_dma_buffers - Free consistent DMA buffers allocated |
| 7060 | * during driver load time |
| 7061 | * |
| 7062 | * @instance- Adapter soft instance |
| 7063 | * |
| 7064 | */ |
| 7065 | static inline |
| 7066 | void megasas_free_ctrl_dma_buffers(struct megasas_instance *instance) |
| 7067 | { |
| 7068 | struct pci_dev *pdev = instance->pdev; |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7069 | struct fusion_context *fusion = instance->ctrl_context; |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7070 | |
| 7071 | if (instance->evt_detail) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7072 | dma_free_coherent(&pdev->dev, sizeof(struct megasas_evt_detail), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7073 | instance->evt_detail, |
| 7074 | instance->evt_detail_h); |
| 7075 | |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7076 | if (fusion && fusion->ioc_init_request) |
| 7077 | dma_free_coherent(&pdev->dev, |
| 7078 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 7079 | fusion->ioc_init_request, |
| 7080 | fusion->ioc_init_request_phys); |
| 7081 | |
| 7082 | if (instance->pd_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7083 | dma_free_coherent(&pdev->dev, |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7084 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 7085 | instance->pd_list_buf, |
| 7086 | instance->pd_list_buf_h); |
| 7087 | |
| 7088 | if (instance->ld_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7089 | dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_LIST), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7090 | instance->ld_list_buf, |
| 7091 | instance->ld_list_buf_h); |
| 7092 | |
| 7093 | if (instance->ld_targetid_list_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7094 | dma_free_coherent(&pdev->dev, sizeof(struct MR_LD_TARGETID_LIST), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7095 | instance->ld_targetid_list_buf, |
| 7096 | instance->ld_targetid_list_buf_h); |
| 7097 | |
| 7098 | if (instance->ctrl_info_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7099 | dma_free_coherent(&pdev->dev, sizeof(struct megasas_ctrl_info), |
Shivasharan S | 9b3d028 | 2017-10-19 02:48:56 -0700 | [diff] [blame] | 7100 | instance->ctrl_info_buf, |
| 7101 | instance->ctrl_info_buf_h); |
| 7102 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7103 | if (instance->system_info_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7104 | dma_free_coherent(&pdev->dev, sizeof(struct MR_DRV_SYSTEM_INFO), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7105 | instance->system_info_buf, |
| 7106 | instance->system_info_h); |
| 7107 | |
| 7108 | if (instance->pd_info) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7109 | dma_free_coherent(&pdev->dev, sizeof(struct MR_PD_INFO), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7110 | instance->pd_info, instance->pd_info_h); |
| 7111 | |
| 7112 | if (instance->tgt_prop) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7113 | dma_free_coherent(&pdev->dev, sizeof(struct MR_TARGET_PROPERTIES), |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7114 | instance->tgt_prop, instance->tgt_prop_h); |
| 7115 | |
| 7116 | if (instance->crash_dump_buf) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7117 | dma_free_coherent(&pdev->dev, CRASH_DMA_BUF_SIZE, |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7118 | instance->crash_dump_buf, |
| 7119 | instance->crash_dump_h); |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 7120 | |
| 7121 | if (instance->snapdump_prop) |
| 7122 | dma_free_coherent(&pdev->dev, |
| 7123 | sizeof(struct MR_SNAPDUMP_PROPERTIES), |
| 7124 | instance->snapdump_prop, |
| 7125 | instance->snapdump_prop_h); |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 7126 | |
| 7127 | if (instance->host_device_list_buf) |
| 7128 | dma_free_coherent(&pdev->dev, |
| 7129 | HOST_DEVICE_LIST_SZ, |
| 7130 | instance->host_device_list_buf, |
| 7131 | instance->host_device_list_buf_h); |
| 7132 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7133 | } |
| 7134 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 7135 | /* |
| 7136 | * megasas_init_ctrl_params - Initialize controller's instance |
| 7137 | * parameters before FW init |
| 7138 | * @instance - Adapter soft instance |
| 7139 | * @return - void |
| 7140 | */ |
| 7141 | static inline void megasas_init_ctrl_params(struct megasas_instance *instance) |
| 7142 | { |
| 7143 | instance->fw_crash_state = UNAVAILABLE; |
| 7144 | |
| 7145 | megasas_poll_wait_aen = 0; |
| 7146 | instance->issuepend_done = 1; |
| 7147 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
| 7148 | |
| 7149 | /* |
| 7150 | * Initialize locks and queues |
| 7151 | */ |
| 7152 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 7153 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
| 7154 | |
| 7155 | atomic_set(&instance->fw_outstanding, 0); |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 7156 | atomic64_set(&instance->total_io_count, 0); |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 7157 | |
| 7158 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 7159 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 7160 | |
| 7161 | spin_lock_init(&instance->crashdump_lock); |
| 7162 | spin_lock_init(&instance->mfi_pool_lock); |
| 7163 | spin_lock_init(&instance->hba_lock); |
| 7164 | spin_lock_init(&instance->stream_lock); |
| 7165 | spin_lock_init(&instance->completion_lock); |
| 7166 | |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 7167 | mutex_init(&instance->reset_mutex); |
| 7168 | |
| 7169 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 7170 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) |
| 7171 | instance->flag_ieee = 1; |
| 7172 | |
| 7173 | megasas_dbg_lvl = 0; |
| 7174 | instance->flag = 0; |
| 7175 | instance->unload = 1; |
| 7176 | instance->last_time = 0; |
| 7177 | instance->disableOnlineCtrlReset = 1; |
| 7178 | instance->UnevenSpanSupport = 0; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 7179 | instance->smp_affinity_enable = smp_affinity_enable ? true : false; |
| 7180 | instance->msix_load_balance = false; |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 7181 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7182 | if (instance->adapter_type != MFI_SERIES) |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 7183 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7184 | else |
Shivasharan S | 7535f27 | 2017-10-19 02:48:58 -0700 | [diff] [blame] | 7185 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | /** |
| 7189 | * megasas_probe_one - PCI hotplug entry point |
| 7190 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 7191 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7192 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7193 | static int megasas_probe_one(struct pci_dev *pdev, |
| 7194 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7195 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7196 | int rval, pos; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7197 | struct Scsi_Host *host; |
| 7198 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 7199 | u16 control = 0; |
| 7200 | |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 7201 | switch (pdev->device) { |
Chandrakanth Patil | dd80769 | 2019-06-25 16:34:20 +0530 | [diff] [blame] | 7202 | case PCI_DEVICE_ID_LSI_AERO_10E0: |
| 7203 | case PCI_DEVICE_ID_LSI_AERO_10E3: |
| 7204 | case PCI_DEVICE_ID_LSI_AERO_10E4: |
| 7205 | case PCI_DEVICE_ID_LSI_AERO_10E7: |
| 7206 | dev_err(&pdev->dev, "Adapter is in non secure mode\n"); |
| 7207 | return 1; |
Shivasharan S | 469f72d | 2018-11-09 09:47:20 -0800 | [diff] [blame] | 7208 | case PCI_DEVICE_ID_LSI_AERO_10E1: |
| 7209 | case PCI_DEVICE_ID_LSI_AERO_10E5: |
| 7210 | dev_info(&pdev->dev, "Adapter is in configurable secure mode\n"); |
| 7211 | break; |
| 7212 | } |
| 7213 | |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 7214 | /* Reset MSI-X in the kdump kernel */ |
| 7215 | if (reset_devices) { |
| 7216 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 7217 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 7218 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 7219 | &control); |
| 7220 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 7221 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 7222 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 7223 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 7224 | control & |
| 7225 | ~PCI_MSIX_FLAGS_ENABLE); |
| 7226 | } |
| 7227 | } |
| 7228 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7229 | |
| 7230 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7231 | * PCI prepping: enable device set bus mastering and dma mask |
| 7232 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 7233 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7234 | |
| 7235 | if (rval) { |
| 7236 | return rval; |
| 7237 | } |
| 7238 | |
| 7239 | pci_set_master(pdev); |
| 7240 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7241 | host = scsi_host_alloc(&megasas_template, |
| 7242 | sizeof(struct megasas_instance)); |
| 7243 | |
| 7244 | if (!host) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7245 | dev_printk(KERN_DEBUG, &pdev->dev, "scsi_host_alloc failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7246 | goto fail_alloc_instance; |
| 7247 | } |
| 7248 | |
| 7249 | instance = (struct megasas_instance *)host->hostdata; |
| 7250 | memset(instance, 0, sizeof(*instance)); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7251 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7252 | |
| 7253 | /* |
| 7254 | * Initialize PCI related and misc parameters |
| 7255 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7256 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7257 | instance->host = host; |
| 7258 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 7259 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
| 7260 | |
Shivasharan S | c365178 | 2017-10-19 02:48:48 -0700 | [diff] [blame] | 7261 | megasas_set_adapter_type(instance); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 7262 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7263 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 7264 | * Initialize MFI Firmware |
| 7265 | */ |
| 7266 | if (megasas_init_fw(instance)) |
| 7267 | goto fail_init_mfi; |
| 7268 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7269 | if (instance->requestorId) { |
| 7270 | if (instance->PlasmaFW111) { |
| 7271 | instance->vf_affiliation_111 = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7272 | dma_alloc_coherent(&pdev->dev, |
| 7273 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 7274 | &instance->vf_affiliation_111_h, |
| 7275 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7276 | if (!instance->vf_affiliation_111) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7277 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7278 | "memory for VF affiliation buffer\n"); |
| 7279 | } else { |
| 7280 | instance->vf_affiliation = |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7281 | dma_alloc_coherent(&pdev->dev, |
| 7282 | (MAX_LOGICAL_DRIVES + 1) * |
| 7283 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 7284 | &instance->vf_affiliation_h, |
| 7285 | GFP_KERNEL); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7286 | if (!instance->vf_affiliation) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7287 | dev_warn(&pdev->dev, "Can't allocate " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7288 | "memory for VF affiliation buffer\n"); |
| 7289 | } |
| 7290 | } |
| 7291 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7292 | /* |
| 7293 | * Store instance in PCI softstate |
| 7294 | */ |
| 7295 | pci_set_drvdata(pdev, instance); |
| 7296 | |
| 7297 | /* |
| 7298 | * Add this controller to megasas_mgmt_info structure so that it |
| 7299 | * can be exported to management applications |
| 7300 | */ |
| 7301 | megasas_mgmt_info.count++; |
| 7302 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 7303 | megasas_mgmt_info.max_index++; |
| 7304 | |
| 7305 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7306 | * Register with SCSI mid-layer |
| 7307 | */ |
| 7308 | if (megasas_io_attach(instance)) |
| 7309 | goto fail_io_attach; |
| 7310 | |
| 7311 | instance->unload = 0; |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 7312 | /* |
| 7313 | * Trigger SCSI to scan our drives |
| 7314 | */ |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 7315 | if (!instance->enable_fw_dev_list || |
| 7316 | (instance->host_device_list_buf->count > 0)) |
| 7317 | scsi_scan_host(host); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7318 | |
| 7319 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7320 | * Initiate AEN (Asynchronous Event Notification) |
| 7321 | */ |
| 7322 | if (megasas_start_aen(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7323 | dev_printk(KERN_DEBUG, &pdev->dev, "start aen failed\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7324 | goto fail_start_aen; |
| 7325 | } |
| 7326 | |
Shivasharan S | ba53572 | 2019-05-07 10:05:49 -0700 | [diff] [blame] | 7327 | megasas_setup_debugfs(instance); |
| 7328 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 7329 | /* Get current SR-IOV LD/VF affiliation */ |
| 7330 | if (instance->requestorId) |
| 7331 | megasas_get_ld_vf_affiliation(instance, 1); |
| 7332 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7333 | return 0; |
| 7334 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7335 | fail_start_aen: |
| 7336 | fail_io_attach: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7337 | megasas_mgmt_info.count--; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7338 | megasas_mgmt_info.max_index--; |
weiping zhang | 61f0c3c | 2017-08-08 01:26:57 +0800 | [diff] [blame] | 7339 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7340 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7341 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7342 | megasas_destroy_irqs(instance); |
| 7343 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7344 | if (instance->adapter_type != MFI_SERIES) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 7345 | megasas_release_fusion(instance); |
| 7346 | else |
| 7347 | megasas_release_mfi(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7348 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7349 | pci_free_irq_vectors(instance->pdev); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7350 | fail_init_mfi: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7351 | scsi_host_put(host); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7352 | fail_alloc_instance: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7353 | pci_disable_device(pdev); |
| 7354 | |
| 7355 | return -ENODEV; |
| 7356 | } |
| 7357 | |
| 7358 | /** |
| 7359 | * megasas_flush_cache - Requests FW to flush all its caches |
| 7360 | * @instance: Adapter soft state |
| 7361 | */ |
| 7362 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 7363 | { |
| 7364 | struct megasas_cmd *cmd; |
| 7365 | struct megasas_dcmd_frame *dcmd; |
| 7366 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7367 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7368 | return; |
| 7369 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7370 | cmd = megasas_get_cmd(instance); |
| 7371 | |
| 7372 | if (!cmd) |
| 7373 | return; |
| 7374 | |
| 7375 | dcmd = &cmd->frame->dcmd; |
| 7376 | |
| 7377 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 7378 | |
| 7379 | dcmd->cmd = MFI_CMD_DCMD; |
| 7380 | dcmd->cmd_status = 0x0; |
| 7381 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7382 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7383 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 7384 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7385 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7386 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7387 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 7388 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7389 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 7390 | != DCMD_SUCCESS) { |
| 7391 | dev_err(&instance->pdev->dev, |
| 7392 | "return from %s %d\n", __func__, __LINE__); |
| 7393 | return; |
| 7394 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7395 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7396 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7397 | } |
| 7398 | |
| 7399 | /** |
| 7400 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 7401 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7402 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7403 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7404 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 7405 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7406 | { |
| 7407 | struct megasas_cmd *cmd; |
| 7408 | struct megasas_dcmd_frame *dcmd; |
| 7409 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7410 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 7411 | return; |
| 7412 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7413 | cmd = megasas_get_cmd(instance); |
| 7414 | |
| 7415 | if (!cmd) |
| 7416 | return; |
| 7417 | |
| 7418 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 7419 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7420 | instance->aen_cmd, MFI_IO_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7421 | if (instance->map_update_cmd) |
| 7422 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7423 | instance->map_update_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7424 | if (instance->jbod_seq_cmd) |
| 7425 | megasas_issue_blocked_abort_cmd(instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7426 | instance->jbod_seq_cmd, MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7427 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7428 | dcmd = &cmd->frame->dcmd; |
| 7429 | |
| 7430 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 7431 | |
| 7432 | dcmd->cmd = MFI_CMD_DCMD; |
| 7433 | dcmd->cmd_status = 0x0; |
| 7434 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7435 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7436 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 7437 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7438 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7439 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7440 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 7441 | if (megasas_issue_blocked_cmd(instance, cmd, MFI_IO_TIMEOUT_SECS) |
| 7442 | != DCMD_SUCCESS) { |
| 7443 | dev_err(&instance->pdev->dev, |
| 7444 | "return from %s %d\n", __func__, __LINE__); |
| 7445 | return; |
| 7446 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7447 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 7448 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7449 | } |
| 7450 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7451 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7452 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 7453 | * megasas_suspend - driver suspend entry point |
| 7454 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7455 | * @state: PCI power state to suspend routine |
| 7456 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7457 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7458 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 7459 | { |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7460 | struct megasas_instance *instance; |
| 7461 | |
| 7462 | instance = pci_get_drvdata(pdev); |
Chandrakanth Patil | dd80769 | 2019-06-25 16:34:20 +0530 | [diff] [blame] | 7463 | |
| 7464 | if (!instance) |
| 7465 | return 0; |
| 7466 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7467 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7468 | |
Shivasharan S | f7331f1 | 2019-05-07 10:05:46 -0700 | [diff] [blame] | 7469 | dev_info(&pdev->dev, "%s is called\n", __func__); |
| 7470 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7471 | /* Shutdown SR-IOV heartbeat timer */ |
| 7472 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7473 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 7474 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7475 | /* Stop the FW fault detection watchdog */ |
| 7476 | if (instance->adapter_type != MFI_SERIES) |
| 7477 | megasas_fusion_stop_watchdog(instance); |
| 7478 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7479 | megasas_flush_cache(instance); |
| 7480 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7481 | |
| 7482 | /* cancel the delayed work if this work still in queue */ |
| 7483 | if (instance->ev != NULL) { |
| 7484 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7485 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7486 | instance->ev = NULL; |
| 7487 | } |
| 7488 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7489 | tasklet_kill(&instance->isr_tasklet); |
| 7490 | |
| 7491 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7492 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7493 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7494 | megasas_destroy_irqs(instance); |
| 7495 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7496 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7497 | pci_free_irq_vectors(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7498 | |
| 7499 | pci_save_state(pdev); |
| 7500 | pci_disable_device(pdev); |
| 7501 | |
| 7502 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 7503 | |
| 7504 | return 0; |
| 7505 | } |
| 7506 | |
| 7507 | /** |
| 7508 | * megasas_resume- driver resume entry point |
| 7509 | * @pdev: PCI device structure |
| 7510 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7511 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7512 | megasas_resume(struct pci_dev *pdev) |
| 7513 | { |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7514 | int rval; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7515 | struct Scsi_Host *host; |
| 7516 | struct megasas_instance *instance; |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7517 | int irq_flags = PCI_IRQ_LEGACY; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7518 | |
| 7519 | instance = pci_get_drvdata(pdev); |
Chandrakanth Patil | dd80769 | 2019-06-25 16:34:20 +0530 | [diff] [blame] | 7520 | |
| 7521 | if (!instance) |
| 7522 | return 0; |
| 7523 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7524 | host = instance->host; |
| 7525 | pci_set_power_state(pdev, PCI_D0); |
| 7526 | pci_enable_wake(pdev, PCI_D0, 0); |
| 7527 | pci_restore_state(pdev); |
| 7528 | |
Shivasharan S | f7331f1 | 2019-05-07 10:05:46 -0700 | [diff] [blame] | 7529 | dev_info(&pdev->dev, "%s is called\n", __func__); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7530 | /* |
| 7531 | * PCI prepping: enable device set bus mastering and dma mask |
| 7532 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 7533 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7534 | |
| 7535 | if (rval) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7536 | dev_err(&pdev->dev, "Enable device failed\n"); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7537 | return rval; |
| 7538 | } |
| 7539 | |
| 7540 | pci_set_master(pdev); |
| 7541 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7542 | /* |
| 7543 | * We expect the FW state to be READY |
| 7544 | */ |
| 7545 | if (megasas_transition_to_ready(instance, 0)) |
| 7546 | goto fail_ready_state; |
| 7547 | |
| 7548 | if (megasas_set_dma_mask(instance)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7549 | goto fail_set_dma_mask; |
| 7550 | |
| 7551 | /* |
| 7552 | * Initialize MFI Firmware |
| 7553 | */ |
| 7554 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7555 | atomic_set(&instance->fw_outstanding, 0); |
Shivasharan S | 41fae9a | 2018-01-05 05:27:39 -0800 | [diff] [blame] | 7556 | atomic_set(&instance->ldio_outstanding, 0); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7557 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 7558 | /* Now re-enable MSI-X */ |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7559 | if (instance->msix_vectors) { |
| 7560 | irq_flags = PCI_IRQ_MSIX; |
Shivasharan S | 1d15d90 | 2019-05-07 10:05:36 -0700 | [diff] [blame] | 7561 | if (instance->smp_affinity_enable) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7562 | irq_flags |= PCI_IRQ_AFFINITY; |
| 7563 | } |
| 7564 | rval = pci_alloc_irq_vectors(instance->pdev, 1, |
| 7565 | instance->msix_vectors ? |
| 7566 | instance->msix_vectors : 1, irq_flags); |
| 7567 | if (rval < 0) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 7568 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 7569 | |
Ming Lei | adbe552 | 2018-03-13 17:42:40 +0800 | [diff] [blame] | 7570 | megasas_setup_reply_map(instance); |
| 7571 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7572 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7573 | megasas_reset_reply_desc(instance); |
| 7574 | if (megasas_ioc_init_fusion(instance)) { |
| 7575 | megasas_free_cmds(instance); |
| 7576 | megasas_free_cmds_fusion(instance); |
| 7577 | goto fail_init_mfi; |
| 7578 | } |
| 7579 | if (!megasas_get_map_info(instance)) |
| 7580 | megasas_sync_map_info(instance); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 7581 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7582 | *instance->producer = 0; |
| 7583 | *instance->consumer = 0; |
| 7584 | if (megasas_issue_init_mfi(instance)) |
| 7585 | goto fail_init_mfi; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7586 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7587 | |
Shivasharan S | c3b10a5 | 2018-06-04 03:45:10 -0700 | [diff] [blame] | 7588 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) |
| 7589 | goto fail_init_mfi; |
| 7590 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7591 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 7592 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7593 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7594 | if (instance->msix_vectors ? |
| 7595 | megasas_setup_irqs_msix(instance, 0) : |
| 7596 | megasas_setup_irqs_ioapic(instance)) |
| 7597 | goto fail_init_mfi; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7598 | |
Shivasharan S | 62a04f8 | 2019-05-07 10:05:35 -0700 | [diff] [blame] | 7599 | if (instance->adapter_type != MFI_SERIES) |
| 7600 | megasas_setup_irq_poll(instance); |
| 7601 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7602 | /* Re-launch SR-IOV heartbeat timer */ |
| 7603 | if (instance->requestorId) { |
| 7604 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
Kees Cook | c251a7b | 2017-10-22 15:30:04 -0700 | [diff] [blame] | 7605 | megasas_start_timer(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7606 | else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7607 | instance->skip_heartbeat_timer_del = 1; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7608 | goto fail_init_mfi; |
| 7609 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7610 | } |
| 7611 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7612 | instance->instancet->enable_intr(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7613 | megasas_setup_jbod_map(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7614 | instance->unload = 0; |
| 7615 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7616 | /* |
| 7617 | * Initiate AEN (Asynchronous Event Notification) |
| 7618 | */ |
| 7619 | if (megasas_start_aen(instance)) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7620 | dev_err(&instance->pdev->dev, "Start AEN failed\n"); |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 7621 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7622 | /* Re-launch FW fault watchdog */ |
| 7623 | if (instance->adapter_type != MFI_SERIES) |
| 7624 | if (megasas_fusion_start_watchdog(instance) != SUCCESS) |
| 7625 | goto fail_start_watchdog; |
| 7626 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7627 | return 0; |
| 7628 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7629 | fail_start_watchdog: |
| 7630 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7631 | del_timer_sync(&instance->sriov_heartbeat_timer); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7632 | fail_init_mfi: |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7633 | megasas_free_ctrl_dma_buffers(instance); |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 7634 | megasas_free_ctrl_mem(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7635 | scsi_host_put(host); |
| 7636 | |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7637 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7638 | fail_set_dma_mask: |
| 7639 | fail_ready_state: |
| 7640 | |
| 7641 | pci_disable_device(pdev); |
| 7642 | |
| 7643 | return -ENODEV; |
| 7644 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 7645 | #else |
| 7646 | #define megasas_suspend NULL |
| 7647 | #define megasas_resume NULL |
| 7648 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7649 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7650 | static inline int |
| 7651 | megasas_wait_for_adapter_operational(struct megasas_instance *instance) |
| 7652 | { |
| 7653 | int wait_time = MEGASAS_RESET_WAIT_TIME * 2; |
| 7654 | int i; |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7655 | u8 adp_state; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7656 | |
| 7657 | for (i = 0; i < wait_time; i++) { |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7658 | adp_state = atomic_read(&instance->adprecovery); |
| 7659 | if ((adp_state == MEGASAS_HBA_OPERATIONAL) || |
| 7660 | (adp_state == MEGASAS_HW_CRITICAL_ERROR)) |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7661 | break; |
| 7662 | |
| 7663 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) |
| 7664 | dev_notice(&instance->pdev->dev, "waiting for controller reset to finish\n"); |
| 7665 | |
| 7666 | msleep(1000); |
| 7667 | } |
| 7668 | |
Shivasharan S | 9c9db8b | 2018-06-04 03:45:11 -0700 | [diff] [blame] | 7669 | if (adp_state != MEGASAS_HBA_OPERATIONAL) { |
| 7670 | dev_info(&instance->pdev->dev, |
| 7671 | "%s HBA failed to become operational, adp_state %d\n", |
| 7672 | __func__, adp_state); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7673 | return 1; |
| 7674 | } |
| 7675 | |
| 7676 | return 0; |
| 7677 | } |
| 7678 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7679 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7680 | * megasas_detach_one - PCI hot"un"plug entry point |
| 7681 | * @pdev: PCI device structure |
| 7682 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 7683 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7684 | { |
| 7685 | int i; |
| 7686 | struct Scsi_Host *host; |
| 7687 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7688 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7689 | u32 pd_seq_map_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7690 | |
| 7691 | instance = pci_get_drvdata(pdev); |
Chandrakanth Patil | dd80769 | 2019-06-25 16:34:20 +0530 | [diff] [blame] | 7692 | |
| 7693 | if (!instance) |
| 7694 | return; |
| 7695 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7696 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7697 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7698 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7699 | /* Shutdown SR-IOV heartbeat timer */ |
| 7700 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 7701 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 7702 | |
Shivasharan S | 3f6194a | 2018-10-16 23:37:39 -0700 | [diff] [blame] | 7703 | /* Stop the FW fault detection watchdog */ |
| 7704 | if (instance->adapter_type != MFI_SERIES) |
| 7705 | megasas_fusion_stop_watchdog(instance); |
| 7706 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7707 | if (instance->fw_crash_state != UNAVAILABLE) |
| 7708 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7709 | scsi_remove_host(instance->host); |
Shivasharan S | f3f7920 | 2018-01-05 05:27:41 -0800 | [diff] [blame] | 7710 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7711 | |
| 7712 | if (megasas_wait_for_adapter_operational(instance)) |
| 7713 | goto skip_firing_dcmds; |
| 7714 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7715 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 7716 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7717 | |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7718 | skip_firing_dcmds: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7719 | /* cancel the delayed work if this work still in queue*/ |
| 7720 | if (instance->ev != NULL) { |
| 7721 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 7722 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 7723 | instance->ev = NULL; |
| 7724 | } |
| 7725 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 7726 | /* cancel all wait events */ |
| 7727 | wake_up_all(&instance->int_cmd_wait_q); |
| 7728 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 7729 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7730 | |
| 7731 | /* |
| 7732 | * Take the instance off the instance array. Note that we will not |
| 7733 | * decrement the max_index. We let this array be sparse array |
| 7734 | */ |
| 7735 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 7736 | if (megasas_mgmt_info.instance[i] == instance) { |
| 7737 | megasas_mgmt_info.count--; |
| 7738 | megasas_mgmt_info.instance[i] = NULL; |
| 7739 | |
| 7740 | break; |
| 7741 | } |
| 7742 | } |
| 7743 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7744 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7745 | |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7746 | megasas_destroy_irqs(instance); |
| 7747 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7748 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7749 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7750 | |
Shivasharan S | 630d42b | 2018-12-17 00:47:37 -0800 | [diff] [blame] | 7751 | if (instance->adapter_type >= VENTURA_SERIES) { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 7752 | for (i = 0; i < MAX_LOGICAL_DRIVES_EXT; ++i) |
| 7753 | kfree(fusion->stream_detect_by_ld[i]); |
| 7754 | kfree(fusion->stream_detect_by_ld); |
| 7755 | fusion->stream_detect_by_ld = NULL; |
| 7756 | } |
| 7757 | |
| 7758 | |
Shivasharan S | e7d36b8 | 2017-10-19 02:48:50 -0700 | [diff] [blame] | 7759 | if (instance->adapter_type != MFI_SERIES) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7760 | megasas_release_fusion(instance); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 7761 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 7762 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 7763 | (MAX_PHYSICAL_DEVICES - 1)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7764 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7765 | if (fusion->ld_map[i]) |
| 7766 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7767 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7768 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7769 | fusion->ld_map_phys[i]); |
Shivasharan S | def3e8d | 2017-08-23 04:47:03 -0700 | [diff] [blame] | 7770 | if (fusion->ld_drv_map[i]) { |
| 7771 | if (is_vmalloc_addr(fusion->ld_drv_map[i])) |
| 7772 | vfree(fusion->ld_drv_map[i]); |
| 7773 | else |
| 7774 | free_pages((ulong)fusion->ld_drv_map[i], |
| 7775 | fusion->drv_map_pages); |
| 7776 | } |
| 7777 | |
Maurizio Lombardi | 546e559 | 2016-01-22 13:41:42 +0100 | [diff] [blame] | 7778 | if (fusion->pd_seq_sync[i]) |
| 7779 | dma_free_coherent(&instance->pdev->dev, |
| 7780 | pd_seq_map_sz, |
| 7781 | fusion->pd_seq_sync[i], |
| 7782 | fusion->pd_seq_phys[i]); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7783 | } |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 7784 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7785 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 7786 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7787 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7788 | if (instance->vf_affiliation) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7789 | dma_free_coherent(&pdev->dev, (MAX_LOGICAL_DRIVES + 1) * |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7790 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 7791 | instance->vf_affiliation, |
| 7792 | instance->vf_affiliation_h); |
| 7793 | |
| 7794 | if (instance->vf_affiliation_111) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7795 | dma_free_coherent(&pdev->dev, |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7796 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 7797 | instance->vf_affiliation_111, |
| 7798 | instance->vf_affiliation_111_h); |
| 7799 | |
| 7800 | if (instance->hb_host_mem) |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 7801 | dma_free_coherent(&pdev->dev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 7802 | instance->hb_host_mem, |
| 7803 | instance->hb_host_mem_h); |
| 7804 | |
Shivasharan S | 1b4bed2 | 2017-10-19 02:48:55 -0700 | [diff] [blame] | 7805 | megasas_free_ctrl_dma_buffers(instance); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7806 | |
Shivasharan S | 49a7a4a | 2017-10-19 02:48:54 -0700 | [diff] [blame] | 7807 | megasas_free_ctrl_mem(instance); |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 7808 | |
Shivasharan S | ba53572 | 2019-05-07 10:05:49 -0700 | [diff] [blame] | 7809 | megasas_destroy_debugfs(instance); |
| 7810 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7811 | scsi_host_put(host); |
| 7812 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7813 | pci_disable_device(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7814 | } |
| 7815 | |
| 7816 | /** |
| 7817 | * megasas_shutdown - Shutdown entry point |
| 7818 | * @device: Generic device structure |
| 7819 | */ |
| 7820 | static void megasas_shutdown(struct pci_dev *pdev) |
| 7821 | { |
| 7822 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7823 | |
Chandrakanth Patil | dd80769 | 2019-06-25 16:34:20 +0530 | [diff] [blame] | 7824 | if (!instance) |
| 7825 | return; |
| 7826 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 7827 | instance->unload = 1; |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7828 | |
| 7829 | if (megasas_wait_for_adapter_operational(instance)) |
| 7830 | goto skip_firing_dcmds; |
| 7831 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7832 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 7833 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 7834 | |
| 7835 | skip_firing_dcmds: |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 7836 | instance->instancet->disable_intr(instance); |
Sumit.Saxena@avagotech.com | d3557fc | 2015-04-23 16:30:09 +0530 | [diff] [blame] | 7837 | megasas_destroy_irqs(instance); |
| 7838 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 7839 | if (instance->msix_vectors) |
Hannes Reinecke | fad119b | 2016-12-02 12:52:23 +0100 | [diff] [blame] | 7840 | pci_free_irq_vectors(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7841 | } |
| 7842 | |
| 7843 | /** |
| 7844 | * megasas_mgmt_open - char node "open" entry point |
| 7845 | */ |
| 7846 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 7847 | { |
| 7848 | /* |
| 7849 | * Allow only those users with admin rights |
| 7850 | */ |
| 7851 | if (!capable(CAP_SYS_ADMIN)) |
| 7852 | return -EACCES; |
| 7853 | |
| 7854 | return 0; |
| 7855 | } |
| 7856 | |
| 7857 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7858 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 7859 | * |
| 7860 | * This function adds the calling process to a driver global queue. When an |
| 7861 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 7862 | */ |
| 7863 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 7864 | { |
| 7865 | int rc; |
| 7866 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7867 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7868 | |
| 7869 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 7870 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 7871 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7872 | |
| 7873 | if (rc >= 0) { |
| 7874 | /* For sanity check when we get ioctl */ |
| 7875 | filep->private_data = filep; |
| 7876 | return 0; |
| 7877 | } |
| 7878 | |
| 7879 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 7880 | |
| 7881 | return rc; |
| 7882 | } |
| 7883 | |
| 7884 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7885 | * megasas_mgmt_poll - char node "poll" entry point |
| 7886 | * */ |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 7887 | static __poll_t megasas_mgmt_poll(struct file *file, poll_table *wait) |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7888 | { |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 7889 | __poll_t mask; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7890 | unsigned long flags; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7891 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7892 | poll_wait(file, &megasas_poll_wait, wait); |
| 7893 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 7894 | if (megasas_poll_wait_aen) |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 7895 | mask = (EPOLLIN | EPOLLRDNORM); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7896 | else |
| 7897 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 7898 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7899 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 7900 | return mask; |
| 7901 | } |
| 7902 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7903 | /* |
| 7904 | * megasas_set_crash_dump_params_ioctl: |
| 7905 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 7906 | * @cmd: MFI command frame |
| 7907 | */ |
| 7908 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 7909 | 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] | 7910 | { |
| 7911 | struct megasas_instance *local_instance; |
| 7912 | int i, error = 0; |
| 7913 | int crash_support; |
| 7914 | |
| 7915 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 7916 | |
| 7917 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 7918 | local_instance = megasas_mgmt_info.instance[i]; |
| 7919 | if (local_instance && local_instance->crash_dump_drv_support) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 7920 | if ((atomic_read(&local_instance->adprecovery) == |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 7921 | MEGASAS_HBA_OPERATIONAL) && |
| 7922 | !megasas_set_crash_dump_params(local_instance, |
| 7923 | crash_support)) { |
| 7924 | local_instance->crash_dump_app_support = |
| 7925 | crash_support; |
| 7926 | dev_info(&local_instance->pdev->dev, |
| 7927 | "Application firmware crash " |
| 7928 | "dump mode set success\n"); |
| 7929 | error = 0; |
| 7930 | } else { |
| 7931 | dev_info(&local_instance->pdev->dev, |
| 7932 | "Application firmware crash " |
| 7933 | "dump mode set failed\n"); |
| 7934 | error = -1; |
| 7935 | } |
| 7936 | } |
| 7937 | } |
| 7938 | return error; |
| 7939 | } |
| 7940 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7941 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7942 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 7943 | * @instance: Adapter soft state |
| 7944 | * @argp: User's ioctl packet |
| 7945 | */ |
| 7946 | static int |
| 7947 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 7948 | struct megasas_iocpacket __user * user_ioc, |
| 7949 | struct megasas_iocpacket *ioc) |
| 7950 | { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7951 | struct megasas_sge64 *kern_sge64 = NULL; |
| 7952 | struct megasas_sge32 *kern_sge32 = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7953 | struct megasas_cmd *cmd; |
| 7954 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 7955 | dma_addr_t buf_handle = 0; |
| 7956 | int error = 0, i; |
| 7957 | void *sense = NULL; |
| 7958 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 7959 | unsigned long *sense_ptr; |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7960 | u32 opcode = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7961 | |
| 7962 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 7963 | |
| 7964 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7965 | 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] | 7966 | ioc->sge_count, MAX_IOCTL_SGE); |
| 7967 | return -EINVAL; |
| 7968 | } |
| 7969 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 7970 | if ((ioc->frame.hdr.cmd >= MFI_CMD_OP_COUNT) || |
| 7971 | ((ioc->frame.hdr.cmd == MFI_CMD_NVME) && |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 7972 | !instance->support_nvme_passthru) || |
| 7973 | ((ioc->frame.hdr.cmd == MFI_CMD_TOOLBOX) && |
| 7974 | !instance->support_pci_lane_margining)) { |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 7975 | dev_err(&instance->pdev->dev, |
| 7976 | "Received invalid ioctl command 0x%x\n", |
| 7977 | ioc->frame.hdr.cmd); |
| 7978 | return -ENOTSUPP; |
| 7979 | } |
| 7980 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 7981 | cmd = megasas_get_cmd(instance); |
| 7982 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 7983 | 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] | 7984 | return -ENOMEM; |
| 7985 | } |
| 7986 | |
| 7987 | /* |
| 7988 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 7989 | * frames into our cmd's frames. cmd->frame's context will get |
| 7990 | * overwritten when we copy from user's frames. So set that value |
| 7991 | * alone separately |
| 7992 | */ |
| 7993 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 7994 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 7995 | cmd->frame->hdr.pad_0 = 0; |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 7996 | |
| 7997 | cmd->frame->hdr.flags &= (~MFI_FRAME_IEEE); |
| 7998 | |
| 7999 | if (instance->consistent_mask_64bit) |
| 8000 | cmd->frame->hdr.flags |= cpu_to_le16((MFI_FRAME_SGL64 | |
| 8001 | MFI_FRAME_SENSE64)); |
| 8002 | else |
| 8003 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_SGL64 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 8004 | MFI_FRAME_SENSE64)); |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 8005 | |
| 8006 | if (cmd->frame->hdr.cmd == MFI_CMD_DCMD) |
| 8007 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8008 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 8009 | if (opcode == MR_DCMD_CTRL_SHUTDOWN) { |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 8010 | mutex_lock(&instance->reset_mutex); |
Shivasharan S | 95c0608 | 2017-02-10 00:59:23 -0800 | [diff] [blame] | 8011 | if (megasas_get_ctrl_info(instance) != DCMD_SUCCESS) { |
| 8012 | megasas_return_cmd(instance, cmd); |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 8013 | mutex_unlock(&instance->reset_mutex); |
Shivasharan S | 95c0608 | 2017-02-10 00:59:23 -0800 | [diff] [blame] | 8014 | return -1; |
| 8015 | } |
Chandrakanth Patil | 7fa3174 | 2019-06-25 16:34:23 +0530 | [diff] [blame] | 8016 | mutex_unlock(&instance->reset_mutex); |
Shivasharan S | 95c0608 | 2017-02-10 00:59:23 -0800 | [diff] [blame] | 8017 | } |
| 8018 | |
Shivasharan S | 8823abe | 2017-08-23 04:47:00 -0700 | [diff] [blame] | 8019 | if (opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 8020 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 8021 | megasas_return_cmd(instance, cmd); |
| 8022 | return error; |
| 8023 | } |
| 8024 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8025 | /* |
| 8026 | * The management interface between applications and the fw uses |
| 8027 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 8028 | * etc are accomplishes through different kinds of MFI frames. The |
| 8029 | * driver needs to care only about substituting user buffers with |
| 8030 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 8031 | * struct iocpacket itself. |
| 8032 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 8033 | if (instance->consistent_mask_64bit) |
| 8034 | kern_sge64 = (struct megasas_sge64 *) |
| 8035 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 8036 | else |
| 8037 | kern_sge32 = (struct megasas_sge32 *) |
| 8038 | ((unsigned long)cmd->frame + ioc->sgl_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8039 | |
| 8040 | /* |
| 8041 | * For each user buffer, create a mirror buffer and copy in |
| 8042 | */ |
| 8043 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 8044 | if (!ioc->sgl[i].iov_len) |
| 8045 | continue; |
| 8046 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 8047 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8048 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 8049 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8050 | if (!kbuff_arr[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 8051 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc " |
| 8052 | "kernel SGL buffer for IOCTL\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8053 | error = -ENOMEM; |
| 8054 | goto out; |
| 8055 | } |
| 8056 | |
| 8057 | /* |
| 8058 | * We don't change the dma_coherent_mask, so |
Christoph Hellwig | 60ee652 | 2018-10-10 19:31:25 +0200 | [diff] [blame] | 8059 | * dma_alloc_coherent only returns 32bit addresses |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8060 | */ |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 8061 | if (instance->consistent_mask_64bit) { |
| 8062 | kern_sge64[i].phys_addr = cpu_to_le64(buf_handle); |
| 8063 | kern_sge64[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 8064 | } else { |
| 8065 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 8066 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
| 8067 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8068 | |
| 8069 | /* |
| 8070 | * We created a kernel buffer corresponding to the |
| 8071 | * user buffer. Now copy in from the user buffer |
| 8072 | */ |
| 8073 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 8074 | (u32) (ioc->sgl[i].iov_len))) { |
| 8075 | error = -EFAULT; |
| 8076 | goto out; |
| 8077 | } |
| 8078 | } |
| 8079 | |
| 8080 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 8081 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 8082 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8083 | if (!sense) { |
| 8084 | error = -ENOMEM; |
| 8085 | goto out; |
| 8086 | } |
| 8087 | |
| 8088 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 8089 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 8090 | if (instance->consistent_mask_64bit) |
| 8091 | *sense_ptr = cpu_to_le64(sense_handle); |
| 8092 | else |
| 8093 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8094 | } |
| 8095 | |
| 8096 | /* |
| 8097 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 8098 | * cmd to the SCSI mid-layer |
| 8099 | */ |
| 8100 | cmd->sync_cmd = 1; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8101 | if (megasas_issue_blocked_cmd(instance, cmd, 0) == DCMD_NOT_FIRED) { |
| 8102 | cmd->sync_cmd = 0; |
| 8103 | dev_err(&instance->pdev->dev, |
Shivasharan S | 82add4e | 2017-10-19 02:49:02 -0700 | [diff] [blame] | 8104 | "return -EBUSY from %s %d cmd 0x%x opcode 0x%x cmd->cmd_status_drv 0x%x\n", |
| 8105 | __func__, __LINE__, cmd->frame->hdr.cmd, opcode, |
| 8106 | cmd->cmd_status_drv); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8107 | return -EBUSY; |
| 8108 | } |
| 8109 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8110 | cmd->sync_cmd = 0; |
| 8111 | |
Sumit.Saxena@avagotech.com | aa00832 | 2014-11-17 15:24:08 +0530 | [diff] [blame] | 8112 | if (instance->unload == 1) { |
| 8113 | dev_info(&instance->pdev->dev, "Driver unload is in progress " |
| 8114 | "don't submit data to application\n"); |
| 8115 | goto out; |
| 8116 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8117 | /* |
| 8118 | * copy out the kernel buffers to user buffers |
| 8119 | */ |
| 8120 | for (i = 0; i < ioc->sge_count; i++) { |
| 8121 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 8122 | ioc->sgl[i].iov_len)) { |
| 8123 | error = -EFAULT; |
| 8124 | goto out; |
| 8125 | } |
| 8126 | } |
| 8127 | |
| 8128 | /* |
| 8129 | * copy out the sense |
| 8130 | */ |
| 8131 | if (ioc->sense_len) { |
| 8132 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 8133 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8134 | * sense buffer address |
| 8135 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 8136 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 8137 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8138 | |
Shivasharan S | 318aaef | 2017-02-10 00:59:22 -0800 | [diff] [blame] | 8139 | if (copy_to_user((void __user *)((unsigned long) |
| 8140 | get_unaligned((unsigned long *)sense_ptr)), |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 8141 | sense, ioc->sense_len)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 8142 | dev_err(&instance->pdev->dev, "Failed to copy out to user " |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 8143 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8144 | error = -EFAULT; |
| 8145 | goto out; |
| 8146 | } |
| 8147 | } |
| 8148 | |
| 8149 | /* |
| 8150 | * copy the status codes returned by the fw |
| 8151 | */ |
| 8152 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 8153 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 8154 | 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] | 8155 | error = -EFAULT; |
| 8156 | } |
| 8157 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 8158 | out: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8159 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 8160 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8161 | sense, sense_handle); |
| 8162 | } |
| 8163 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 8164 | for (i = 0; i < ioc->sge_count; i++) { |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 8165 | if (kbuff_arr[i]) { |
Shivasharan S | 107a60d | 2017-10-19 02:49:05 -0700 | [diff] [blame] | 8166 | if (instance->consistent_mask_64bit) |
| 8167 | dma_free_coherent(&instance->pdev->dev, |
| 8168 | le32_to_cpu(kern_sge64[i].length), |
| 8169 | kbuff_arr[i], |
| 8170 | le64_to_cpu(kern_sge64[i].phys_addr)); |
| 8171 | else |
| 8172 | dma_free_coherent(&instance->pdev->dev, |
| 8173 | le32_to_cpu(kern_sge32[i].length), |
| 8174 | kbuff_arr[i], |
| 8175 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 8176 | kbuff_arr[i] = NULL; |
Arnd Bergmann | 3deb943 | 2016-03-14 15:29:45 +0100 | [diff] [blame] | 8177 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8178 | } |
| 8179 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 8180 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8181 | return error; |
| 8182 | } |
| 8183 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8184 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 8185 | { |
| 8186 | struct megasas_iocpacket __user *user_ioc = |
| 8187 | (struct megasas_iocpacket __user *)arg; |
| 8188 | struct megasas_iocpacket *ioc; |
| 8189 | struct megasas_instance *instance; |
| 8190 | int error; |
| 8191 | |
Markus Elfring | 709ab23 | 2016-08-21 10:39:04 +0200 | [diff] [blame] | 8192 | ioc = memdup_user(user_ioc, sizeof(*ioc)); |
| 8193 | if (IS_ERR(ioc)) |
| 8194 | return PTR_ERR(ioc); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8195 | |
| 8196 | instance = megasas_lookup_instance(ioc->host_no); |
| 8197 | if (!instance) { |
| 8198 | error = -ENODEV; |
| 8199 | goto out_kfree_ioc; |
| 8200 | } |
| 8201 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8202 | /* Block ioctls in VF mode */ |
| 8203 | if (instance->requestorId && !allow_vf_ioctls) { |
| 8204 | error = -ENODEV; |
| 8205 | goto out_kfree_ioc; |
| 8206 | } |
| 8207 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 8208 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 8209 | dev_err(&instance->pdev->dev, "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 8210 | error = -ENODEV; |
| 8211 | goto out_kfree_ioc; |
| 8212 | } |
| 8213 | |
| 8214 | if (instance->unload == 1) { |
| 8215 | error = -ENODEV; |
| 8216 | goto out_kfree_ioc; |
| 8217 | } |
| 8218 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8219 | if (down_interruptible(&instance->ioctl_sem)) { |
| 8220 | error = -ERESTARTSYS; |
| 8221 | goto out_kfree_ioc; |
| 8222 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 8223 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 8224 | if (megasas_wait_for_adapter_operational(instance)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 8225 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 8226 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 8227 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 8228 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8229 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 8230 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8231 | up(&instance->ioctl_sem); |
| 8232 | |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 8233 | out_kfree_ioc: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8234 | kfree(ioc); |
| 8235 | return error; |
| 8236 | } |
| 8237 | |
| 8238 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 8239 | { |
| 8240 | struct megasas_instance *instance; |
| 8241 | struct megasas_aen aen; |
| 8242 | int error; |
| 8243 | |
| 8244 | if (file->private_data != file) { |
| 8245 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 8246 | "called first\n"); |
| 8247 | return -EINVAL; |
| 8248 | } |
| 8249 | |
| 8250 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 8251 | return -EFAULT; |
| 8252 | |
| 8253 | instance = megasas_lookup_instance(aen.host_no); |
| 8254 | |
| 8255 | if (!instance) |
| 8256 | return -ENODEV; |
| 8257 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 8258 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 8259 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 8260 | } |
| 8261 | |
| 8262 | if (instance->unload == 1) { |
| 8263 | return -ENODEV; |
| 8264 | } |
| 8265 | |
Shivasharan S | 619831f | 2018-01-05 05:27:43 -0800 | [diff] [blame] | 8266 | if (megasas_wait_for_adapter_operational(instance)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 8267 | return -ENODEV; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 8268 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8269 | mutex_lock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8270 | error = megasas_register_aen(instance, aen.seq_num, |
| 8271 | aen.class_locale_word); |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8272 | mutex_unlock(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8273 | return error; |
| 8274 | } |
| 8275 | |
| 8276 | /** |
| 8277 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 8278 | */ |
| 8279 | static long |
| 8280 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 8281 | { |
| 8282 | switch (cmd) { |
| 8283 | case MEGASAS_IOC_FIRMWARE: |
| 8284 | return megasas_mgmt_ioctl_fw(file, arg); |
| 8285 | |
| 8286 | case MEGASAS_IOC_GET_AEN: |
| 8287 | return megasas_mgmt_ioctl_aen(file, arg); |
| 8288 | } |
| 8289 | |
| 8290 | return -ENOTTY; |
| 8291 | } |
| 8292 | |
| 8293 | #ifdef CONFIG_COMPAT |
| 8294 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 8295 | { |
| 8296 | struct compat_megasas_iocpacket __user *cioc = |
| 8297 | (struct compat_megasas_iocpacket __user *)arg; |
| 8298 | struct megasas_iocpacket __user *ioc = |
| 8299 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 8300 | int i; |
| 8301 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8302 | compat_uptr_t ptr; |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 8303 | u32 local_sense_off; |
| 8304 | u32 local_sense_len; |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8305 | u32 user_sense_off; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8306 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8307 | if (clear_user(ioc, sizeof(*ioc))) |
| 8308 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8309 | |
| 8310 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 8311 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 8312 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 8313 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 8314 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 8315 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 8316 | return -EFAULT; |
| 8317 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8318 | /* |
| 8319 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 8320 | * sense_len is not null, so prepare the 64bit value under |
| 8321 | * the same condition. |
| 8322 | */ |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8323 | if (get_user(local_sense_off, &ioc->sense_off) || |
| 8324 | get_user(local_sense_len, &ioc->sense_len) || |
| 8325 | get_user(user_sense_off, &cioc->sense_off)) |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 8326 | return -EFAULT; |
| 8327 | |
Wenwen Wang | 47db787 | 2018-10-06 13:34:21 -0500 | [diff] [blame] | 8328 | if (local_sense_off != user_sense_off) |
| 8329 | return -EINVAL; |
| 8330 | |
sumit.saxena@avagotech.com | 323c4a0 | 2015-10-15 13:40:54 +0530 | [diff] [blame] | 8331 | if (local_sense_len) { |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8332 | void __user **sense_ioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8333 | (void __user **)((u8 *)((unsigned long)&ioc->frame.raw) + local_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8334 | compat_uptr_t *sense_cioc_ptr = |
Sumit Saxena | ea1c928 | 2016-01-28 21:14:26 +0530 | [diff] [blame] | 8335 | (compat_uptr_t *)(((unsigned long)&cioc->frame.raw) + user_sense_off); |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8336 | if (get_user(ptr, sense_cioc_ptr) || |
| 8337 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 8338 | return -EFAULT; |
| 8339 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8340 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 8341 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8342 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 8343 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 8344 | copy_in_user(&ioc->sgl[i].iov_len, |
| 8345 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 8346 | return -EFAULT; |
| 8347 | } |
| 8348 | |
| 8349 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 8350 | |
| 8351 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 8352 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 8353 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 8354 | return -EFAULT; |
| 8355 | } |
| 8356 | return error; |
| 8357 | } |
| 8358 | |
| 8359 | static long |
| 8360 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 8361 | unsigned long arg) |
| 8362 | { |
| 8363 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 8364 | case MEGASAS_IOC_FIRMWARE32: |
| 8365 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8366 | case MEGASAS_IOC_GET_AEN: |
| 8367 | return megasas_mgmt_ioctl_aen(file, arg); |
| 8368 | } |
| 8369 | |
| 8370 | return -ENOTTY; |
| 8371 | } |
| 8372 | #endif |
| 8373 | |
| 8374 | /* |
| 8375 | * File operations structure for management interface |
| 8376 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 8377 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8378 | .owner = THIS_MODULE, |
| 8379 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8380 | .fasync = megasas_mgmt_fasync, |
| 8381 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 8382 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8383 | #ifdef CONFIG_COMPAT |
| 8384 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 8385 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 8386 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8387 | }; |
| 8388 | |
| 8389 | /* |
| 8390 | * PCI hotplug support registration structure |
| 8391 | */ |
| 8392 | static struct pci_driver megasas_pci_driver = { |
| 8393 | |
| 8394 | .name = "megaraid_sas", |
| 8395 | .id_table = megasas_pci_table, |
| 8396 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 8397 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 8398 | .suspend = megasas_suspend, |
| 8399 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8400 | .shutdown = megasas_shutdown, |
| 8401 | }; |
| 8402 | |
| 8403 | /* |
| 8404 | * Sysfs driver attributes |
| 8405 | */ |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8406 | static ssize_t version_show(struct device_driver *dd, char *buf) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8407 | { |
| 8408 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 8409 | MEGASAS_VERSION); |
| 8410 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8411 | static DRIVER_ATTR_RO(version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8412 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8413 | 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] | 8414 | { |
| 8415 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 8416 | MEGASAS_RELDATE); |
| 8417 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8418 | static DRIVER_ATTR_RO(release_date); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8419 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8420 | 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] | 8421 | { |
| 8422 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 8423 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8424 | static DRIVER_ATTR_RO(support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8425 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8426 | 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] | 8427 | { |
| 8428 | return sprintf(buf, "%u\n", support_device_change); |
| 8429 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8430 | static DRIVER_ATTR_RO(support_device_change); |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8431 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8432 | static ssize_t dbg_lvl_show(struct device_driver *dd, char *buf) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8433 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8434 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8435 | } |
| 8436 | |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8437 | static ssize_t dbg_lvl_store(struct device_driver *dd, const char *buf, |
| 8438 | size_t count) |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8439 | { |
| 8440 | int retval = count; |
Bjorn Helgaas | da0dc9f | 2015-07-07 15:52:45 -0500 | [diff] [blame] | 8441 | |
| 8442 | if (sscanf(buf, "%u", &megasas_dbg_lvl) < 1) { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8443 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 8444 | retval = -EINVAL; |
| 8445 | } |
| 8446 | return retval; |
| 8447 | } |
Greg Kroah-Hartman | e14a396 | 2017-07-19 14:50:06 +0200 | [diff] [blame] | 8448 | static DRIVER_ATTR_RW(dbg_lvl); |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8449 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8450 | static ssize_t |
| 8451 | support_nvme_encapsulation_show(struct device_driver *dd, char *buf) |
| 8452 | { |
| 8453 | return sprintf(buf, "%u\n", support_nvme_encapsulation); |
| 8454 | } |
| 8455 | |
| 8456 | static DRIVER_ATTR_RO(support_nvme_encapsulation); |
| 8457 | |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 8458 | static ssize_t |
| 8459 | support_pci_lane_margining_show(struct device_driver *dd, char *buf) |
| 8460 | { |
| 8461 | return sprintf(buf, "%u\n", support_pci_lane_margining); |
| 8462 | } |
| 8463 | |
| 8464 | static DRIVER_ATTR_RO(support_pci_lane_margining); |
| 8465 | |
Shivasharan S | b4a4221 | 2017-02-10 00:59:16 -0800 | [diff] [blame] | 8466 | static inline void megasas_remove_scsi_device(struct scsi_device *sdev) |
| 8467 | { |
| 8468 | sdev_printk(KERN_INFO, sdev, "SCSI device is removed\n"); |
| 8469 | scsi_remove_device(sdev); |
| 8470 | scsi_device_put(sdev); |
| 8471 | } |
| 8472 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8473 | /** |
| 8474 | * megasas_update_device_list - Update the PD and LD device list from FW |
| 8475 | * after an AEN event notification |
| 8476 | * @instance: Adapter soft state |
| 8477 | * @event_type: Indicates type of event (PD or LD event) |
| 8478 | * |
| 8479 | * @return: Success or failure |
| 8480 | * |
| 8481 | * Issue DCMDs to Firmware to update the internal device list in driver. |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8482 | * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination |
| 8483 | * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list. |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8484 | */ |
| 8485 | static |
| 8486 | int megasas_update_device_list(struct megasas_instance *instance, |
| 8487 | int event_type) |
| 8488 | { |
| 8489 | int dcmd_ret = DCMD_SUCCESS; |
| 8490 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8491 | if (instance->enable_fw_dev_list) { |
| 8492 | dcmd_ret = megasas_host_device_list_query(instance, false); |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8493 | if (dcmd_ret != DCMD_SUCCESS) |
| 8494 | goto out; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8495 | } else { |
| 8496 | if (event_type & SCAN_PD_CHANNEL) { |
| 8497 | dcmd_ret = megasas_get_pd_list(instance); |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8498 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8499 | if (dcmd_ret != DCMD_SUCCESS) |
| 8500 | goto out; |
| 8501 | } |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8502 | |
| 8503 | if (event_type & SCAN_VD_CHANNEL) { |
| 8504 | if (!instance->requestorId || |
| 8505 | (instance->requestorId && |
| 8506 | megasas_get_ld_vf_affiliation(instance, 0))) { |
| 8507 | dcmd_ret = megasas_ld_list_query(instance, |
| 8508 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST); |
| 8509 | if (dcmd_ret != DCMD_SUCCESS) |
| 8510 | goto out; |
| 8511 | } |
| 8512 | } |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8513 | } |
| 8514 | |
| 8515 | out: |
| 8516 | return dcmd_ret; |
| 8517 | } |
| 8518 | |
| 8519 | /** |
| 8520 | * megasas_add_remove_devices - Add/remove devices to SCSI mid-layer |
| 8521 | * after an AEN event notification |
| 8522 | * @instance: Adapter soft state |
| 8523 | * @scan_type: Indicates type of devices (PD/LD) to add |
| 8524 | * @return void |
| 8525 | */ |
| 8526 | static |
| 8527 | void megasas_add_remove_devices(struct megasas_instance *instance, |
| 8528 | int scan_type) |
| 8529 | { |
| 8530 | int i, j; |
| 8531 | u16 pd_index = 0; |
| 8532 | u16 ld_index = 0; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8533 | u16 channel = 0, id = 0; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8534 | struct Scsi_Host *host; |
| 8535 | struct scsi_device *sdev1; |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8536 | struct MR_HOST_DEVICE_LIST *targetid_list = NULL; |
| 8537 | struct MR_HOST_DEVICE_LIST_ENTRY *targetid_entry = NULL; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8538 | |
| 8539 | host = instance->host; |
| 8540 | |
Shivasharan S | f6fe573 | 2019-01-29 01:38:14 -0800 | [diff] [blame] | 8541 | if (instance->enable_fw_dev_list) { |
| 8542 | targetid_list = instance->host_device_list_buf; |
| 8543 | for (i = 0; i < targetid_list->count; i++) { |
| 8544 | targetid_entry = &targetid_list->host_device_list[i]; |
| 8545 | if (targetid_entry->flags.u.bits.is_sys_pd) { |
| 8546 | channel = le16_to_cpu(targetid_entry->target_id) / |
| 8547 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8548 | id = le16_to_cpu(targetid_entry->target_id) % |
| 8549 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8550 | } else { |
| 8551 | channel = MEGASAS_MAX_PD_CHANNELS + |
| 8552 | (le16_to_cpu(targetid_entry->target_id) / |
| 8553 | MEGASAS_MAX_DEV_PER_CHANNEL); |
| 8554 | id = le16_to_cpu(targetid_entry->target_id) % |
| 8555 | MEGASAS_MAX_DEV_PER_CHANNEL; |
| 8556 | } |
| 8557 | sdev1 = scsi_device_lookup(host, channel, id, 0); |
| 8558 | if (!sdev1) { |
| 8559 | scsi_add_device(host, channel, id, 0); |
| 8560 | } else { |
| 8561 | scsi_device_put(sdev1); |
| 8562 | } |
| 8563 | } |
| 8564 | } |
| 8565 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8566 | if (scan_type & SCAN_PD_CHANNEL) { |
| 8567 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 8568 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 8569 | pd_index = i * MEGASAS_MAX_DEV_PER_CHANNEL + j; |
| 8570 | sdev1 = scsi_device_lookup(host, i, j, 0); |
| 8571 | if (instance->pd_list[pd_index].driveState == |
| 8572 | MR_PD_STATE_SYSTEM) { |
| 8573 | if (!sdev1) |
| 8574 | scsi_add_device(host, i, j, 0); |
| 8575 | else |
| 8576 | scsi_device_put(sdev1); |
| 8577 | } else { |
| 8578 | if (sdev1) |
| 8579 | megasas_remove_scsi_device(sdev1); |
| 8580 | } |
| 8581 | } |
| 8582 | } |
| 8583 | } |
| 8584 | |
| 8585 | if (scan_type & SCAN_VD_CHANNEL) { |
| 8586 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 8587 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 8588 | ld_index = (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 8589 | sdev1 = scsi_device_lookup(host, |
| 8590 | MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 8591 | if (instance->ld_ids[ld_index] != 0xff) { |
| 8592 | if (!sdev1) |
| 8593 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 8594 | else |
| 8595 | scsi_device_put(sdev1); |
| 8596 | } else { |
| 8597 | if (sdev1) |
| 8598 | megasas_remove_scsi_device(sdev1); |
| 8599 | } |
| 8600 | } |
| 8601 | } |
| 8602 | } |
| 8603 | |
| 8604 | } |
| 8605 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8606 | static void |
| 8607 | megasas_aen_polling(struct work_struct *work) |
| 8608 | { |
| 8609 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 8610 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8611 | struct megasas_instance *instance = ev->instance; |
| 8612 | union megasas_evt_class_locale class_locale; |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8613 | int event_type = 0; |
YueHaibing | de19212 | 2019-05-25 20:42:02 +0800 | [diff] [blame] | 8614 | u32 seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8615 | int error; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8616 | u8 dcmd_ret = DCMD_SUCCESS; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8617 | |
| 8618 | if (!instance) { |
| 8619 | printk(KERN_ERR "invalid instance!\n"); |
| 8620 | kfree(ev); |
| 8621 | return; |
| 8622 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8623 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8624 | /* Don't run the event workqueue thread if OCR is running */ |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8625 | mutex_lock(&instance->reset_mutex); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 8626 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8627 | instance->ev = NULL; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8628 | if (instance->evt_detail) { |
sumit.saxena@avagotech.com | 714f517 | 2015-08-31 17:23:51 +0530 | [diff] [blame] | 8629 | megasas_decode_evt(instance); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8630 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 8631 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8632 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8633 | case MR_EVT_PD_INSERTED: |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8634 | case MR_EVT_PD_REMOVED: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8635 | event_type = SCAN_PD_CHANNEL; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 8636 | break; |
| 8637 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8638 | case MR_EVT_LD_OFFLINE: |
| 8639 | case MR_EVT_CFG_CLEARED: |
| 8640 | case MR_EVT_LD_DELETED: |
| 8641 | case MR_EVT_LD_CREATED: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8642 | event_type = SCAN_VD_CHANNEL; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8643 | break; |
| 8644 | |
| 8645 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
| 8646 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
| 8647 | case MR_EVT_LD_STATE_CHANGE: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8648 | event_type = SCAN_PD_CHANNEL | SCAN_VD_CHANNEL; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8649 | dev_info(&instance->pdev->dev, "scanning for scsi%d...\n", |
| 8650 | instance->host->host_no); |
| 8651 | break; |
| 8652 | |
| 8653 | case MR_EVT_CTRL_PROP_CHANGED: |
Shivasharan S | f0c21df | 2018-10-16 23:37:40 -0700 | [diff] [blame] | 8654 | dcmd_ret = megasas_get_ctrl_info(instance); |
| 8655 | if (dcmd_ret == DCMD_SUCCESS && |
| 8656 | instance->snapdump_wait_time) { |
| 8657 | megasas_get_snapdump_properties(instance); |
| 8658 | dev_info(&instance->pdev->dev, |
| 8659 | "Snap dump wait time\t: %d\n", |
| 8660 | instance->snapdump_wait_time); |
| 8661 | } |
| 8662 | break; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8663 | default: |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8664 | event_type = 0; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8665 | break; |
| 8666 | } |
| 8667 | } else { |
| 8668 | dev_err(&instance->pdev->dev, "invalid evt_detail!\n"); |
| 8669 | mutex_unlock(&instance->reset_mutex); |
| 8670 | kfree(ev); |
| 8671 | return; |
| 8672 | } |
| 8673 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8674 | if (event_type) |
| 8675 | dcmd_ret = megasas_update_device_list(instance, event_type); |
| 8676 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8677 | mutex_unlock(&instance->reset_mutex); |
| 8678 | |
Shivasharan S | 44abbaf | 2019-01-29 01:38:13 -0800 | [diff] [blame] | 8679 | if (event_type && dcmd_ret == DCMD_SUCCESS) |
| 8680 | megasas_add_remove_devices(instance, event_type); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8681 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 8682 | if (dcmd_ret == DCMD_SUCCESS) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8683 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
| 8684 | else |
| 8685 | seq_num = instance->last_seq_num; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8686 | |
| 8687 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 8688 | class_locale.members.reserved = 0; |
| 8689 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 8690 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8691 | |
| 8692 | if (instance->aen_cmd != NULL) { |
| 8693 | kfree(ev); |
| 8694 | return; |
| 8695 | } |
| 8696 | |
| 8697 | mutex_lock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8698 | error = megasas_register_aen(instance, seq_num, |
| 8699 | class_locale.word); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8700 | if (error) |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8701 | dev_err(&instance->pdev->dev, |
| 8702 | "register aen failed error %x\n", error); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8703 | |
Sumit Saxena | 11c71cb | 2016-01-28 21:04:22 +0530 | [diff] [blame] | 8704 | mutex_unlock(&instance->reset_mutex); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 8705 | kfree(ev); |
| 8706 | } |
| 8707 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8708 | /** |
| 8709 | * megasas_init - Driver load entry point |
| 8710 | */ |
| 8711 | static int __init megasas_init(void) |
| 8712 | { |
| 8713 | int rval; |
| 8714 | |
| 8715 | /* |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 8716 | * Booted in kdump kernel, minimize memory footprints by |
| 8717 | * disabling few features |
| 8718 | */ |
| 8719 | if (reset_devices) { |
| 8720 | msix_vectors = 1; |
| 8721 | rdpq_enable = 0; |
| 8722 | dual_qdepth_disable = 1; |
| 8723 | } |
| 8724 | |
| 8725 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8726 | * Announce driver version and other information |
| 8727 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame] | 8728 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8729 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 8730 | spin_lock_init(&poll_aen_lock); |
| 8731 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8732 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8733 | support_device_change = 1; |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8734 | support_nvme_encapsulation = true; |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 8735 | support_pci_lane_margining = true; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8736 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8737 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 8738 | |
| 8739 | /* |
| 8740 | * Register character device node |
| 8741 | */ |
| 8742 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 8743 | |
| 8744 | if (rval < 0) { |
| 8745 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 8746 | return rval; |
| 8747 | } |
| 8748 | |
| 8749 | megasas_mgmt_majorno = rval; |
| 8750 | |
Shivasharan S | ba53572 | 2019-05-07 10:05:49 -0700 | [diff] [blame] | 8751 | megasas_init_debugfs(); |
| 8752 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8753 | /* |
| 8754 | * Register ourselves as PCI hotplug module |
| 8755 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 8756 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8757 | |
| 8758 | if (rval) { |
Masanari Iida | 6774def | 2014-11-05 22:26:48 +0900 | [diff] [blame] | 8759 | printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8760 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8761 | } |
| 8762 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8763 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8764 | &driver_attr_version); |
| 8765 | if (rval) |
| 8766 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8767 | |
| 8768 | rval = driver_create_file(&megasas_pci_driver.driver, |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8769 | &driver_attr_release_date); |
| 8770 | if (rval) |
| 8771 | goto err_dcf_rel_date; |
| 8772 | |
| 8773 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8774 | &driver_attr_support_poll_for_event); |
| 8775 | if (rval) |
| 8776 | goto err_dcf_support_poll_for_event; |
| 8777 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8778 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8779 | &driver_attr_dbg_lvl); |
| 8780 | if (rval) |
| 8781 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8782 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8783 | &driver_attr_support_device_change); |
| 8784 | if (rval) |
| 8785 | goto err_dcf_support_device_change; |
| 8786 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8787 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8788 | &driver_attr_support_nvme_encapsulation); |
| 8789 | if (rval) |
| 8790 | goto err_dcf_support_nvme_encapsulation; |
| 8791 | |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 8792 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 8793 | &driver_attr_support_pci_lane_margining); |
| 8794 | if (rval) |
| 8795 | goto err_dcf_support_pci_lane_margining; |
| 8796 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8797 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8798 | |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 8799 | err_dcf_support_pci_lane_margining: |
| 8800 | driver_remove_file(&megasas_pci_driver.driver, |
| 8801 | &driver_attr_support_nvme_encapsulation); |
| 8802 | |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8803 | err_dcf_support_nvme_encapsulation: |
| 8804 | driver_remove_file(&megasas_pci_driver.driver, |
| 8805 | &driver_attr_support_device_change); |
| 8806 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8807 | err_dcf_support_device_change: |
| 8808 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 8809 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8810 | err_dcf_dbg_lvl: |
| 8811 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8812 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 8813 | err_dcf_support_poll_for_event: |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8814 | driver_remove_file(&megasas_pci_driver.driver, |
| 8815 | &driver_attr_release_date); |
| 8816 | err_dcf_rel_date: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8817 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 8818 | err_dcf_attr_ver: |
| 8819 | pci_unregister_driver(&megasas_pci_driver); |
| 8820 | err_pcidrv: |
Shivasharan S | ba53572 | 2019-05-07 10:05:49 -0700 | [diff] [blame] | 8821 | megasas_exit_debugfs(); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8822 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 8823 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8824 | } |
| 8825 | |
| 8826 | /** |
| 8827 | * megasas_exit - Driver unload entry point |
| 8828 | */ |
| 8829 | static void __exit megasas_exit(void) |
| 8830 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 8831 | driver_remove_file(&megasas_pci_driver.driver, |
| 8832 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8833 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 8834 | &driver_attr_support_poll_for_event); |
| 8835 | driver_remove_file(&megasas_pci_driver.driver, |
| 8836 | &driver_attr_support_device_change); |
Sumit.Saxena@avagotech.com | 09fced1 | 2015-04-23 16:31:54 +0530 | [diff] [blame] | 8837 | driver_remove_file(&megasas_pci_driver.driver, |
| 8838 | &driver_attr_release_date); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 8839 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Shivasharan S | f870bcb | 2018-01-05 05:33:04 -0800 | [diff] [blame] | 8840 | driver_remove_file(&megasas_pci_driver.driver, |
| 8841 | &driver_attr_support_nvme_encapsulation); |
Chandrakanth Patil | 5813685 | 2019-06-25 16:34:30 +0530 | [diff] [blame] | 8842 | driver_remove_file(&megasas_pci_driver.driver, |
| 8843 | &driver_attr_support_pci_lane_margining); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8844 | |
| 8845 | pci_unregister_driver(&megasas_pci_driver); |
Shivasharan S | ba53572 | 2019-05-07 10:05:49 -0700 | [diff] [blame] | 8846 | megasas_exit_debugfs(); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 8847 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 8848 | } |
| 8849 | |
| 8850 | module_init(megasas_init); |
| 8851 | module_exit(megasas_exit); |