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 | * |
adam radford | ae59057 | 2012-10-01 19:27:34 -0700 | [diff] [blame] | 4 | * Copyright (c) 2003-2012 LSI Corporation. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 10 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 15 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 19 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 20 | * FILE: megaraid_sas_base.c |
Sumit.Saxena@avagotech.com | 0d9d8b9 | 2014-09-12 18:58:03 +0530 | [diff] [blame] | 21 | * Version : 06.805.06.00-rc1 |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 22 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 23 | * Authors: LSI Corporation |
| 24 | * Sreenivas Bagalkote |
| 25 | * Sumant Patro |
| 26 | * Bo Yang |
adam radford | 00fa2b1 | 2011-02-24 20:57:21 -0800 | [diff] [blame] | 27 | * Adam Radford <linuxraid@lsi.com> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 28 | * |
adam radford | 3f1530c | 2010-12-14 18:51:48 -0800 | [diff] [blame] | 29 | * Send feedback to: <megaraidlinux@lsi.com> |
| 30 | * |
| 31 | * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 |
| 32 | * ATTN: Linuxraid |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 33 | */ |
| 34 | |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/types.h> |
| 37 | #include <linux/pci.h> |
| 38 | #include <linux/list.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 39 | #include <linux/moduleparam.h> |
| 40 | #include <linux/module.h> |
| 41 | #include <linux/spinlock.h> |
| 42 | #include <linux/interrupt.h> |
| 43 | #include <linux/delay.h> |
| 44 | #include <linux/uio.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 45 | #include <linux/slab.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 46 | #include <asm/uaccess.h> |
Al Viro | 4339923 | 2005-10-04 17:36:04 +0100 | [diff] [blame] | 47 | #include <linux/fs.h> |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 48 | #include <linux/compat.h> |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 49 | #include <linux/blkdev.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 50 | #include <linux/mutex.h> |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 51 | #include <linux/poll.h> |
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> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 58 | #include "megaraid_sas_fusion.h" |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 59 | #include "megaraid_sas.h" |
| 60 | |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 61 | /* |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 62 | * Number of sectors per IO command |
| 63 | * Will be set in megasas_init_mfi if user does not provide |
| 64 | */ |
| 65 | static unsigned int max_sectors; |
| 66 | module_param_named(max_sectors, max_sectors, int, 0); |
| 67 | MODULE_PARM_DESC(max_sectors, |
| 68 | "Maximum number of sectors per IO command"); |
| 69 | |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 70 | static int msix_disable; |
| 71 | module_param(msix_disable, int, S_IRUGO); |
| 72 | MODULE_PARM_DESC(msix_disable, "Disable MSI-X interrupt handling. Default: 0"); |
| 73 | |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 74 | static unsigned int msix_vectors; |
| 75 | module_param(msix_vectors, int, S_IRUGO); |
| 76 | MODULE_PARM_DESC(msix_vectors, "MSI-X max vector count. Default: Set by FW"); |
| 77 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 78 | static int allow_vf_ioctls; |
| 79 | module_param(allow_vf_ioctls, int, S_IRUGO); |
| 80 | MODULE_PARM_DESC(allow_vf_ioctls, "Allow ioctls in SR-IOV VF mode. Default: 0"); |
| 81 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 82 | static int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 83 | module_param(throttlequeuedepth, int, S_IRUGO); |
| 84 | MODULE_PARM_DESC(throttlequeuedepth, |
| 85 | "Adapter queue depth when throttled due to I/O timeout. Default: 16"); |
| 86 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 87 | int resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 88 | module_param(resetwaittime, int, S_IRUGO); |
| 89 | MODULE_PARM_DESC(resetwaittime, "Wait time in seconds after I/O timeout " |
| 90 | "before resetting adapter. Default: 180"); |
| 91 | |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 92 | int smp_affinity_enable = 1; |
| 93 | module_param(smp_affinity_enable, int, S_IRUGO); |
| 94 | MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disbale Default: enable(1)"); |
| 95 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 96 | MODULE_LICENSE("GPL"); |
| 97 | MODULE_VERSION(MEGASAS_VERSION); |
Sumant Patro | 3d6d174 | 2006-12-29 08:13:54 -0800 | [diff] [blame] | 98 | MODULE_AUTHOR("megaraidlinux@lsi.com"); |
bo yang | f28cd7c | 2007-11-09 04:44:56 -0500 | [diff] [blame] | 99 | MODULE_DESCRIPTION("LSI MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 100 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 101 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 102 | static int megasas_get_pd_list(struct megasas_instance *instance); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 103 | static int megasas_ld_list_query(struct megasas_instance *instance, |
| 104 | u8 query_type); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 105 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 106 | static int megasas_register_aen(struct megasas_instance *instance, |
| 107 | u32 seq_num, u32 class_locale_word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 108 | /* |
| 109 | * PCI ID table for all supported controllers |
| 110 | */ |
| 111 | static struct pci_device_id megasas_pci_table[] = { |
| 112 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 113 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 114 | /* xscale IOP */ |
| 115 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 116 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 117 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 118 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 119 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 120 | /* gen2*/ |
| 121 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 122 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 123 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 124 | /* skinny*/ |
| 125 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 126 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 127 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 128 | /* xscale IOP, vega */ |
| 129 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 130 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 131 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 132 | /* Fusion */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 133 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)}, |
| 134 | /* Plasma */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 135 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 136 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 137 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 138 | /* Fury */ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 139 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 143 | |
| 144 | static int megasas_mgmt_majorno; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 145 | struct megasas_mgmt_info megasas_mgmt_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 146 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 147 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 148 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 149 | static int megasas_poll_wait_aen; |
| 150 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 151 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 152 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 153 | static u32 support_device_change; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 154 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 155 | /* define lock for aen poll */ |
| 156 | spinlock_t poll_aen_lock; |
| 157 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 158 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 159 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 160 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 161 | static u32 |
| 162 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs); |
| 163 | static int |
| 164 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 165 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 166 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 167 | static u32 |
| 168 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 169 | u32 |
| 170 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 171 | struct scsi_cmnd *scmd); |
| 172 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 173 | void |
| 174 | megasas_release_fusion(struct megasas_instance *instance); |
| 175 | int |
| 176 | megasas_ioc_init_fusion(struct megasas_instance *instance); |
| 177 | void |
| 178 | megasas_free_cmds_fusion(struct megasas_instance *instance); |
| 179 | u8 |
| 180 | megasas_get_map_info(struct megasas_instance *instance); |
| 181 | int |
| 182 | megasas_sync_map_info(struct megasas_instance *instance); |
| 183 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 184 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 185 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 186 | void megasas_reset_reply_desc(struct megasas_instance *instance); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 187 | int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 188 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 189 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 190 | int initial); |
| 191 | int megasas_check_mpio_paths(struct megasas_instance *instance, |
| 192 | struct scsi_cmnd *scmd); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 193 | |
| 194 | void |
| 195 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 196 | { |
| 197 | instance->instancet->fire_cmd(instance, |
| 198 | cmd->frame_phys_addr, 0, instance->reg_set); |
| 199 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 200 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 201 | /** |
| 202 | * megasas_get_cmd - Get a command from the free pool |
| 203 | * @instance: Adapter soft state |
| 204 | * |
| 205 | * Returns a free command from the pool |
| 206 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 207 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 208 | *instance) |
| 209 | { |
| 210 | unsigned long flags; |
| 211 | struct megasas_cmd *cmd = NULL; |
| 212 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 213 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 214 | |
| 215 | if (!list_empty(&instance->cmd_pool)) { |
| 216 | cmd = list_entry((&instance->cmd_pool)->next, |
| 217 | struct megasas_cmd, list); |
| 218 | list_del_init(&cmd->list); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 219 | atomic_set(&cmd->mfi_mpt_pthr, MFI_MPT_DETACHED); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 220 | } else { |
| 221 | printk(KERN_ERR "megasas: Command pool empty!\n"); |
| 222 | } |
| 223 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 224 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 225 | return cmd; |
| 226 | } |
| 227 | |
| 228 | /** |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 229 | * __megasas_return_cmd - Return a cmd to free command pool |
| 230 | * @instance: Adapter soft state |
| 231 | * @cmd: Command packet to be returned to free command pool |
| 232 | */ |
| 233 | inline void |
| 234 | __megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 235 | { |
| 236 | /* |
| 237 | * Don't go ahead and free the MFI frame, if corresponding |
| 238 | * MPT frame is not freed(valid for only fusion adapters). |
| 239 | * In case of MFI adapters, anyways for any allocated MFI |
| 240 | * frame will have cmd->mfi_mpt_mpthr set to MFI_MPT_DETACHED |
| 241 | */ |
| 242 | if (atomic_read(&cmd->mfi_mpt_pthr) != MFI_MPT_DETACHED) |
| 243 | return; |
| 244 | |
| 245 | cmd->scmd = NULL; |
| 246 | cmd->frame_count = 0; |
| 247 | cmd->is_wait_event = 0; |
| 248 | cmd->mpt_pthr_cmd_blocked = NULL; |
| 249 | |
| 250 | if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) && |
| 251 | (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) && |
| 252 | (instance->pdev->device != PCI_DEVICE_ID_LSI_FURY) && |
| 253 | (reset_devices)) |
| 254 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
| 255 | |
| 256 | atomic_set(&cmd->mfi_mpt_pthr, MFI_LIST_ADDED); |
| 257 | list_add(&cmd->list, (&instance->cmd_pool)->next); |
| 258 | } |
| 259 | |
| 260 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 261 | * megasas_return_cmd - Return a cmd to free command pool |
| 262 | * @instance: Adapter soft state |
| 263 | * @cmd: Command packet to be returned to free command pool |
| 264 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 265 | inline void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 266 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 267 | { |
| 268 | unsigned long flags; |
| 269 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 270 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
| 271 | __megasas_return_cmd(instance, cmd); |
| 272 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 273 | } |
| 274 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 275 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 276 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 277 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 278 | * (deviceid : 1064R, PERC5) controllers |
| 279 | */ |
| 280 | |
| 281 | /** |
| 282 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 283 | * @regs: MFI register set |
| 284 | */ |
| 285 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 286 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 287 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 288 | struct megasas_register_set __iomem *regs; |
| 289 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 290 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 291 | |
| 292 | /* Dummy readl to force pci flush */ |
| 293 | readl(®s->outbound_intr_mask); |
| 294 | } |
| 295 | |
| 296 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 297 | * megasas_disable_intr_xscale -Disables interrupt |
| 298 | * @regs: MFI register set |
| 299 | */ |
| 300 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 301 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 302 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 303 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 304 | u32 mask = 0x1f; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 305 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 306 | writel(mask, ®s->outbound_intr_mask); |
| 307 | /* Dummy readl to force pci flush */ |
| 308 | readl(®s->outbound_intr_mask); |
| 309 | } |
| 310 | |
| 311 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 312 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 313 | * @regs: MFI register set |
| 314 | */ |
| 315 | static u32 |
| 316 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) |
| 317 | { |
| 318 | return readl(&(regs)->outbound_msg_0); |
| 319 | } |
| 320 | /** |
| 321 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 322 | * @regs: MFI register set |
| 323 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 324 | static int |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 325 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) |
| 326 | { |
| 327 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 328 | u32 mfiStatus = 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 329 | /* |
| 330 | * Check if it is our interrupt |
| 331 | */ |
| 332 | status = readl(®s->outbound_intr_status); |
| 333 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 334 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 335 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 336 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 337 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 338 | |
| 339 | /* |
| 340 | * Clear the interrupt by writing back the same value |
| 341 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 342 | if (mfiStatus) |
| 343 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 344 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 345 | /* Dummy readl to force pci flush */ |
| 346 | readl(®s->outbound_intr_status); |
| 347 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 348 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /** |
| 352 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 353 | * @frame_phys_addr : Physical address of cmd |
| 354 | * @frame_count : Number of frames for the command |
| 355 | * @regs : MFI register set |
| 356 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 357 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 358 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 359 | dma_addr_t frame_phys_addr, |
| 360 | u32 frame_count, |
| 361 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 362 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 363 | unsigned long flags; |
| 364 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 365 | writel((frame_phys_addr >> 3)|(frame_count), |
| 366 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 367 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * megasas_adp_reset_xscale - For controller reset |
| 372 | * @regs: MFI register set |
| 373 | */ |
| 374 | static int |
| 375 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 376 | struct megasas_register_set __iomem *regs) |
| 377 | { |
| 378 | u32 i; |
| 379 | u32 pcidata; |
| 380 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 381 | |
| 382 | for (i = 0; i < 3; i++) |
| 383 | msleep(1000); /* sleep for 3 secs */ |
| 384 | pcidata = 0; |
| 385 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
| 386 | printk(KERN_NOTICE "pcidata = %x\n", pcidata); |
| 387 | if (pcidata & 0x2) { |
| 388 | printk(KERN_NOTICE "mfi 1068 offset read=%x\n", pcidata); |
| 389 | pcidata &= ~0x2; |
| 390 | pci_write_config_dword(instance->pdev, |
| 391 | MFI_1068_PCSR_OFFSET, pcidata); |
| 392 | |
| 393 | for (i = 0; i < 2; i++) |
| 394 | msleep(1000); /* need to wait 2 secs again */ |
| 395 | |
| 396 | pcidata = 0; |
| 397 | pci_read_config_dword(instance->pdev, |
| 398 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
| 399 | printk(KERN_NOTICE "1068 offset handshake read=%x\n", pcidata); |
| 400 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
| 401 | printk(KERN_NOTICE "1068 offset pcidt=%x\n", pcidata); |
| 402 | pcidata = 0; |
| 403 | pci_write_config_dword(instance->pdev, |
| 404 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 405 | } |
| 406 | } |
| 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * megasas_check_reset_xscale - For controller reset check |
| 412 | * @regs: MFI register set |
| 413 | */ |
| 414 | static int |
| 415 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 416 | struct megasas_register_set __iomem *regs) |
| 417 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 418 | |
| 419 | if ((instance->adprecovery != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 420 | (le32_to_cpu(*instance->consumer) == |
| 421 | MEGASAS_ADPRESET_INPROG_SIGN)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 422 | return 1; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 423 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 427 | |
| 428 | .fire_cmd = megasas_fire_cmd_xscale, |
| 429 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 430 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 431 | .clear_intr = megasas_clear_intr_xscale, |
| 432 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 433 | .adp_reset = megasas_adp_reset_xscale, |
| 434 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 435 | .service_isr = megasas_isr, |
| 436 | .tasklet = megasas_complete_cmd_dpc, |
| 437 | .init_adapter = megasas_init_adapter_mfi, |
| 438 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 439 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 440 | }; |
| 441 | |
| 442 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 443 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 444 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 445 | */ |
| 446 | |
| 447 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 448 | * The following functions are defined for ppc (deviceid : 0x60) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 449 | * controllers |
| 450 | */ |
| 451 | |
| 452 | /** |
| 453 | * megasas_enable_intr_ppc - Enables interrupts |
| 454 | * @regs: MFI register set |
| 455 | */ |
| 456 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 457 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 458 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 459 | struct megasas_register_set __iomem *regs; |
| 460 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 461 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 462 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 463 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 464 | |
| 465 | /* Dummy readl to force pci flush */ |
| 466 | readl(®s->outbound_intr_mask); |
| 467 | } |
| 468 | |
| 469 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 470 | * megasas_disable_intr_ppc - Disable interrupt |
| 471 | * @regs: MFI register set |
| 472 | */ |
| 473 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 474 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 475 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 476 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 477 | u32 mask = 0xFFFFFFFF; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 478 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 479 | writel(mask, ®s->outbound_intr_mask); |
| 480 | /* Dummy readl to force pci flush */ |
| 481 | readl(®s->outbound_intr_mask); |
| 482 | } |
| 483 | |
| 484 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 485 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 486 | * @regs: MFI register set |
| 487 | */ |
| 488 | static u32 |
| 489 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) |
| 490 | { |
| 491 | return readl(&(regs)->outbound_scratch_pad); |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 496 | * @regs: MFI register set |
| 497 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 498 | static int |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 499 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) |
| 500 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 501 | u32 status, mfiStatus = 0; |
| 502 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 503 | /* |
| 504 | * Check if it is our interrupt |
| 505 | */ |
| 506 | status = readl(®s->outbound_intr_status); |
| 507 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 508 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 509 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 510 | |
| 511 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 512 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 513 | |
| 514 | /* |
| 515 | * Clear the interrupt by writing back the same value |
| 516 | */ |
| 517 | writel(status, ®s->outbound_doorbell_clear); |
| 518 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 519 | /* Dummy readl to force pci flush */ |
| 520 | readl(®s->outbound_doorbell_clear); |
| 521 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 522 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 523 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 524 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 525 | /** |
| 526 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 527 | * @frame_phys_addr : Physical address of cmd |
| 528 | * @frame_count : Number of frames for the command |
| 529 | * @regs : MFI register set |
| 530 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 531 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 532 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 533 | dma_addr_t frame_phys_addr, |
| 534 | u32 frame_count, |
| 535 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 536 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 537 | unsigned long flags; |
| 538 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 539 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 540 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 541 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 542 | } |
| 543 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 544 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 545 | * megasas_check_reset_ppc - For controller reset check |
| 546 | * @regs: MFI register set |
| 547 | */ |
| 548 | static int |
| 549 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 550 | struct megasas_register_set __iomem *regs) |
| 551 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 552 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) |
| 553 | return 1; |
| 554 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 555 | return 0; |
| 556 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 557 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 558 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 559 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 560 | .fire_cmd = megasas_fire_cmd_ppc, |
| 561 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 562 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 563 | .clear_intr = megasas_clear_intr_ppc, |
| 564 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 565 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 566 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 567 | .service_isr = megasas_isr, |
| 568 | .tasklet = megasas_complete_cmd_dpc, |
| 569 | .init_adapter = megasas_init_adapter_mfi, |
| 570 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 571 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 572 | }; |
| 573 | |
| 574 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 575 | * megasas_enable_intr_skinny - Enables interrupts |
| 576 | * @regs: MFI register set |
| 577 | */ |
| 578 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 579 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 580 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 581 | struct megasas_register_set __iomem *regs; |
| 582 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 583 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 584 | |
| 585 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 586 | |
| 587 | /* Dummy readl to force pci flush */ |
| 588 | readl(®s->outbound_intr_mask); |
| 589 | } |
| 590 | |
| 591 | /** |
| 592 | * megasas_disable_intr_skinny - Disables interrupt |
| 593 | * @regs: MFI register set |
| 594 | */ |
| 595 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 596 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 597 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 598 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 599 | u32 mask = 0xFFFFFFFF; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 600 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 601 | writel(mask, ®s->outbound_intr_mask); |
| 602 | /* Dummy readl to force pci flush */ |
| 603 | readl(®s->outbound_intr_mask); |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 608 | * @regs: MFI register set |
| 609 | */ |
| 610 | static u32 |
| 611 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) |
| 612 | { |
| 613 | return readl(&(regs)->outbound_scratch_pad); |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 618 | * @regs: MFI register set |
| 619 | */ |
| 620 | static int |
| 621 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) |
| 622 | { |
| 623 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 624 | u32 mfiStatus = 0; |
| 625 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 626 | /* |
| 627 | * Check if it is our interrupt |
| 628 | */ |
| 629 | status = readl(®s->outbound_intr_status); |
| 630 | |
| 631 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 632 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 636 | * Check if it is our interrupt |
| 637 | */ |
James Georgas | a3fda7d | 2013-06-26 12:03:19 -0600 | [diff] [blame] | 638 | if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 639 | MFI_STATE_FAULT) { |
| 640 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 641 | } else |
| 642 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 643 | |
| 644 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 645 | * Clear the interrupt by writing back the same value |
| 646 | */ |
| 647 | writel(status, ®s->outbound_intr_status); |
| 648 | |
| 649 | /* |
| 650 | * dummy read to flush PCI |
| 651 | */ |
| 652 | readl(®s->outbound_intr_status); |
| 653 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 654 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | /** |
| 658 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 659 | * @frame_phys_addr : Physical address of cmd |
| 660 | * @frame_count : Number of frames for the command |
| 661 | * @regs : MFI register set |
| 662 | */ |
| 663 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 664 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 665 | dma_addr_t frame_phys_addr, |
| 666 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 667 | struct megasas_register_set __iomem *regs) |
| 668 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 669 | unsigned long flags; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 670 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 671 | writel(upper_32_bits(frame_phys_addr), |
| 672 | &(regs)->inbound_high_queue_port); |
| 673 | writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1, |
| 674 | &(regs)->inbound_low_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 675 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 676 | } |
| 677 | |
| 678 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 679 | * megasas_check_reset_skinny - For controller reset check |
| 680 | * @regs: MFI register set |
| 681 | */ |
| 682 | static int |
| 683 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 684 | struct megasas_register_set __iomem *regs) |
| 685 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 686 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) |
| 687 | return 1; |
| 688 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 689 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 693 | |
| 694 | .fire_cmd = megasas_fire_cmd_skinny, |
| 695 | .enable_intr = megasas_enable_intr_skinny, |
| 696 | .disable_intr = megasas_disable_intr_skinny, |
| 697 | .clear_intr = megasas_clear_intr_skinny, |
| 698 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 699 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 700 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 701 | .service_isr = megasas_isr, |
| 702 | .tasklet = megasas_complete_cmd_dpc, |
| 703 | .init_adapter = megasas_init_adapter_mfi, |
| 704 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 705 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 706 | }; |
| 707 | |
| 708 | |
| 709 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 710 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 711 | * controllers |
| 712 | */ |
| 713 | |
| 714 | /** |
| 715 | * megasas_enable_intr_gen2 - Enables interrupts |
| 716 | * @regs: MFI register set |
| 717 | */ |
| 718 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 719 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 720 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 721 | struct megasas_register_set __iomem *regs; |
| 722 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 723 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 724 | |
| 725 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 726 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 727 | |
| 728 | /* Dummy readl to force pci flush */ |
| 729 | readl(®s->outbound_intr_mask); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * megasas_disable_intr_gen2 - Disables interrupt |
| 734 | * @regs: MFI register set |
| 735 | */ |
| 736 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 737 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 738 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 739 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 740 | u32 mask = 0xFFFFFFFF; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 741 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 742 | writel(mask, ®s->outbound_intr_mask); |
| 743 | /* Dummy readl to force pci flush */ |
| 744 | readl(®s->outbound_intr_mask); |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 749 | * @regs: MFI register set |
| 750 | */ |
| 751 | static u32 |
| 752 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) |
| 753 | { |
| 754 | return readl(&(regs)->outbound_scratch_pad); |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 759 | * @regs: MFI register set |
| 760 | */ |
| 761 | static int |
| 762 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) |
| 763 | { |
| 764 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 765 | u32 mfiStatus = 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 766 | /* |
| 767 | * Check if it is our interrupt |
| 768 | */ |
| 769 | status = readl(®s->outbound_intr_status); |
| 770 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 771 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 772 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 773 | } |
| 774 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 775 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 776 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 777 | |
| 778 | /* |
| 779 | * Clear the interrupt by writing back the same value |
| 780 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 781 | if (mfiStatus) |
| 782 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 783 | |
| 784 | /* Dummy readl to force pci flush */ |
| 785 | readl(®s->outbound_intr_status); |
| 786 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 787 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 788 | } |
| 789 | /** |
| 790 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 791 | * @frame_phys_addr : Physical address of cmd |
| 792 | * @frame_count : Number of frames for the command |
| 793 | * @regs : MFI register set |
| 794 | */ |
| 795 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 796 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 797 | dma_addr_t frame_phys_addr, |
| 798 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 799 | struct megasas_register_set __iomem *regs) |
| 800 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 801 | unsigned long flags; |
| 802 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 803 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 804 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 805 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * megasas_adp_reset_gen2 - For controller reset |
| 810 | * @regs: MFI register set |
| 811 | */ |
| 812 | static int |
| 813 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 814 | struct megasas_register_set __iomem *reg_set) |
| 815 | { |
| 816 | u32 retry = 0 ; |
| 817 | u32 HostDiag; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 818 | u32 *seq_offset = ®_set->seq_offset; |
| 819 | u32 *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 820 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 821 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 822 | seq_offset = ®_set->fusion_seq_offset; |
| 823 | hostdiag_offset = ®_set->fusion_host_diag; |
| 824 | } |
| 825 | |
| 826 | writel(0, seq_offset); |
| 827 | writel(4, seq_offset); |
| 828 | writel(0xb, seq_offset); |
| 829 | writel(2, seq_offset); |
| 830 | writel(7, seq_offset); |
| 831 | writel(0xd, seq_offset); |
| 832 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 833 | msleep(1000); |
| 834 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 835 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 836 | |
| 837 | while ( !( HostDiag & DIAG_WRITE_ENABLE) ) { |
| 838 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 839 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 840 | printk(KERN_NOTICE "RESETGEN2: retry=%x, hostdiag=%x\n", |
| 841 | retry, HostDiag); |
| 842 | |
| 843 | if (retry++ >= 100) |
| 844 | return 1; |
| 845 | |
| 846 | } |
| 847 | |
| 848 | printk(KERN_NOTICE "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
| 849 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 850 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 851 | |
| 852 | ssleep(10); |
| 853 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 854 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 855 | while ( ( HostDiag & DIAG_RESET_ADAPTER) ) { |
| 856 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 857 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 858 | printk(KERN_NOTICE "RESET_GEN2: retry=%x, hostdiag=%x\n", |
| 859 | retry, HostDiag); |
| 860 | |
| 861 | if (retry++ >= 1000) |
| 862 | return 1; |
| 863 | |
| 864 | } |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | /** |
| 869 | * megasas_check_reset_gen2 - For controller reset check |
| 870 | * @regs: MFI register set |
| 871 | */ |
| 872 | static int |
| 873 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 874 | struct megasas_register_set __iomem *regs) |
| 875 | { |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 876 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 877 | return 1; |
| 878 | } |
| 879 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 880 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 884 | |
| 885 | .fire_cmd = megasas_fire_cmd_gen2, |
| 886 | .enable_intr = megasas_enable_intr_gen2, |
| 887 | .disable_intr = megasas_disable_intr_gen2, |
| 888 | .clear_intr = megasas_clear_intr_gen2, |
| 889 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 890 | .adp_reset = megasas_adp_reset_gen2, |
| 891 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 892 | .service_isr = megasas_isr, |
| 893 | .tasklet = megasas_complete_cmd_dpc, |
| 894 | .init_adapter = megasas_init_adapter_mfi, |
| 895 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 896 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 897 | }; |
| 898 | |
| 899 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 900 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 901 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 902 | */ |
| 903 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 904 | /* |
| 905 | * Template added for TB (Fusion) |
| 906 | */ |
| 907 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 908 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 909 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 910 | * megasas_issue_polled - Issues a polling command |
| 911 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 912 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 913 | * |
| 914 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. |
| 915 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 916 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 917 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 918 | { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 919 | int seconds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 920 | |
| 921 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 922 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 923 | frame_hdr->cmd_status = MFI_CMD_STATUS_POLL_MODE; |
| 924 | 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] | 925 | |
| 926 | /* |
| 927 | * Issue the frame using inbound queue port |
| 928 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 929 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 930 | |
| 931 | /* |
| 932 | * Wait for cmd_status to change |
| 933 | */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 934 | if (instance->requestorId) |
| 935 | seconds = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 936 | else |
| 937 | seconds = MFI_POLL_TIMEOUT_SECS; |
| 938 | return wait_and_poll(instance, cmd, seconds); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /** |
| 942 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 943 | * @instance: Adapter soft state |
| 944 | * @cmd: Command to be issued |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 945 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 946 | * |
| 947 | * 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] | 948 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 949 | * Used to issue ioctl commands. |
| 950 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 951 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 952 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 953 | struct megasas_cmd *cmd, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 954 | { |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 955 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 956 | cmd->cmd_status = ENODATA; |
| 957 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 958 | cmd->is_wait_event = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 959 | instance->instancet->issue_dcmd(instance, cmd); |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 960 | if (timeout) { |
| 961 | ret = wait_event_timeout(instance->int_cmd_wait_q, |
| 962 | cmd->cmd_status != ENODATA, timeout * HZ); |
| 963 | if (!ret) |
| 964 | return 1; |
| 965 | } else |
| 966 | wait_event(instance->int_cmd_wait_q, |
| 967 | cmd->cmd_status != ENODATA); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 974 | * @instance: Adapter soft state |
| 975 | * @cmd_to_abort: Previously issued cmd to be aborted |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 976 | * @timeout: Timeout in seconds |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 977 | * |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 978 | * MFI firmware can abort previously issued AEN comamnd (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 979 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 980 | * cmd and waits for return status. |
| 981 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 982 | */ |
| 983 | static int |
| 984 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 985 | struct megasas_cmd *cmd_to_abort, int timeout) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 986 | { |
| 987 | struct megasas_cmd *cmd; |
| 988 | struct megasas_abort_frame *abort_fr; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 989 | int ret = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 990 | |
| 991 | cmd = megasas_get_cmd(instance); |
| 992 | |
| 993 | if (!cmd) |
| 994 | return -1; |
| 995 | |
| 996 | abort_fr = &cmd->frame->abort; |
| 997 | |
| 998 | /* |
| 999 | * Prepare and issue the abort frame |
| 1000 | */ |
| 1001 | abort_fr->cmd = MFI_CMD_ABORT; |
| 1002 | abort_fr->cmd_status = 0xFF; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1003 | abort_fr->flags = cpu_to_le16(0); |
| 1004 | abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index); |
| 1005 | abort_fr->abort_mfi_phys_addr_lo = |
| 1006 | cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr)); |
| 1007 | abort_fr->abort_mfi_phys_addr_hi = |
| 1008 | cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1009 | |
| 1010 | cmd->sync_cmd = 1; |
| 1011 | cmd->cmd_status = 0xFF; |
| 1012 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1013 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1014 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 1015 | if (timeout) { |
| 1016 | ret = wait_event_timeout(instance->abort_cmd_wait_q, |
| 1017 | cmd->cmd_status != ENODATA, timeout * HZ); |
| 1018 | if (!ret) { |
| 1019 | dev_err(&instance->pdev->dev, "Command timedout" |
| 1020 | "from %s\n", __func__); |
| 1021 | return 1; |
| 1022 | } |
| 1023 | } else |
| 1024 | wait_event(instance->abort_cmd_wait_q, |
| 1025 | cmd->cmd_status != ENODATA); |
| 1026 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1027 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1028 | |
| 1029 | megasas_return_cmd(instance, cmd); |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 1035 | * @instance: Adapter soft state |
| 1036 | * @scp: SCSI command from the mid-layer |
| 1037 | * @mfi_sgl: SGL to be filled in |
| 1038 | * |
| 1039 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1040 | * it returnes -1. |
| 1041 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1042 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1043 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1044 | union megasas_sgl *mfi_sgl) |
| 1045 | { |
| 1046 | int i; |
| 1047 | int sge_count; |
| 1048 | struct scatterlist *os_sgl; |
| 1049 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1050 | sge_count = scsi_dma_map(scp); |
| 1051 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1052 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1053 | if (sge_count) { |
| 1054 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1055 | mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1056 | 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] | 1057 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1058 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1059 | return sge_count; |
| 1060 | } |
| 1061 | |
| 1062 | /** |
| 1063 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 1064 | * @instance: Adapter soft state |
| 1065 | * @scp: SCSI command from the mid-layer |
| 1066 | * @mfi_sgl: SGL to be filled in |
| 1067 | * |
| 1068 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1069 | * it returnes -1. |
| 1070 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1071 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1072 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1073 | union megasas_sgl *mfi_sgl) |
| 1074 | { |
| 1075 | int i; |
| 1076 | int sge_count; |
| 1077 | struct scatterlist *os_sgl; |
| 1078 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1079 | sge_count = scsi_dma_map(scp); |
| 1080 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1081 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1082 | if (sge_count) { |
| 1083 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1084 | mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1085 | 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] | 1086 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1087 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1088 | return sge_count; |
| 1089 | } |
| 1090 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1091 | /** |
| 1092 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1093 | * @instance: Adapter soft state |
| 1094 | * @scp: SCSI command from the mid-layer |
| 1095 | * @mfi_sgl: SGL to be filled in |
| 1096 | * |
| 1097 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1098 | * it returnes -1. |
| 1099 | */ |
| 1100 | static int |
| 1101 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1102 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1103 | { |
| 1104 | int i; |
| 1105 | int sge_count; |
| 1106 | struct scatterlist *os_sgl; |
| 1107 | |
| 1108 | sge_count = scsi_dma_map(scp); |
| 1109 | |
| 1110 | if (sge_count) { |
| 1111 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1112 | mfi_sgl->sge_skinny[i].length = |
| 1113 | cpu_to_le32(sg_dma_len(os_sgl)); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1114 | mfi_sgl->sge_skinny[i].phys_addr = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1115 | cpu_to_le64(sg_dma_address(os_sgl)); |
| 1116 | mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | return sge_count; |
| 1120 | } |
| 1121 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1122 | /** |
| 1123 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1124 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1125 | * @sge_count : number of sg elements |
| 1126 | * |
| 1127 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1128 | */ |
| 1129 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1130 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1131 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1132 | { |
| 1133 | int num_cnt; |
| 1134 | int sge_bytes; |
| 1135 | u32 sge_sz; |
| 1136 | u32 frame_count=0; |
| 1137 | |
| 1138 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1139 | sizeof(struct megasas_sge32); |
| 1140 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1141 | if (instance->flag_ieee) { |
| 1142 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1143 | } |
| 1144 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1145 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1146 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1147 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1148 | * 1 SGEs for 64-bit SGLs and |
| 1149 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1150 | */ |
| 1151 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1152 | if (instance->flag_ieee == 1) { |
| 1153 | num_cnt = sge_count - 1; |
| 1154 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1155 | num_cnt = sge_count - 1; |
| 1156 | else |
| 1157 | num_cnt = sge_count - 2; |
| 1158 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1159 | if (instance->flag_ieee == 1) { |
| 1160 | num_cnt = sge_count - 1; |
| 1161 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1162 | num_cnt = sge_count - 2; |
| 1163 | else |
| 1164 | num_cnt = sge_count - 3; |
| 1165 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1166 | |
| 1167 | if(num_cnt>0){ |
| 1168 | sge_bytes = sge_sz * num_cnt; |
| 1169 | |
| 1170 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1171 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1172 | } |
| 1173 | /* Main frame */ |
| 1174 | frame_count +=1; |
| 1175 | |
| 1176 | if (frame_count > 7) |
| 1177 | frame_count = 8; |
| 1178 | return frame_count; |
| 1179 | } |
| 1180 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1181 | /** |
| 1182 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1183 | * @instance: Adapter soft state |
| 1184 | * @scp: SCSI command |
| 1185 | * @cmd: Command to be prepared in |
| 1186 | * |
| 1187 | * This function prepares CDB commands. These are typcially pass-through |
| 1188 | * commands to the devices. |
| 1189 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1190 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1191 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1192 | struct megasas_cmd *cmd) |
| 1193 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1194 | u32 is_logical; |
| 1195 | u32 device_id; |
| 1196 | u16 flags = 0; |
| 1197 | struct megasas_pthru_frame *pthru; |
| 1198 | |
| 1199 | is_logical = MEGASAS_IS_LOGICAL(scp); |
| 1200 | device_id = MEGASAS_DEV_INDEX(instance, scp); |
| 1201 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1202 | |
| 1203 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1204 | flags = MFI_FRAME_DIR_WRITE; |
| 1205 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1206 | flags = MFI_FRAME_DIR_READ; |
| 1207 | else if (scp->sc_data_direction == PCI_DMA_NONE) |
| 1208 | flags = MFI_FRAME_DIR_NONE; |
| 1209 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1210 | if (instance->flag_ieee == 1) { |
| 1211 | flags |= MFI_FRAME_IEEE; |
| 1212 | } |
| 1213 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1214 | /* |
| 1215 | * Prepare the DCDB frame |
| 1216 | */ |
| 1217 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1218 | pthru->cmd_status = 0x0; |
| 1219 | pthru->scsi_status = 0x0; |
| 1220 | pthru->target_id = device_id; |
| 1221 | pthru->lun = scp->device->lun; |
| 1222 | pthru->cdb_len = scp->cmd_len; |
| 1223 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1224 | pthru->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1225 | pthru->flags = cpu_to_le16(flags); |
| 1226 | pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1227 | |
| 1228 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1229 | |
| 1230 | /* |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1231 | * If the command is for the tape device, set the |
| 1232 | * pthru timeout to the os layer timeout value. |
| 1233 | */ |
| 1234 | if (scp->device->type == TYPE_TAPE) { |
| 1235 | if ((scp->request->timeout / HZ) > 0xFFFF) |
| 1236 | pthru->timeout = 0xFFFF; |
| 1237 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1238 | pthru->timeout = cpu_to_le16(scp->request->timeout / HZ); |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1242 | * Construct SGL |
| 1243 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1244 | if (instance->flag_ieee == 1) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1245 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1246 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1247 | &pthru->sgl); |
| 1248 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1249 | pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1250 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1251 | &pthru->sgl); |
| 1252 | } else |
| 1253 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1254 | &pthru->sgl); |
| 1255 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1256 | if (pthru->sge_count > instance->max_num_sge) { |
| 1257 | printk(KERN_ERR "megasas: DCDB two many SGE NUM=%x\n", |
| 1258 | pthru->sge_count); |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1262 | /* |
| 1263 | * Sense info specific |
| 1264 | */ |
| 1265 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1266 | pthru->sense_buf_phys_addr_hi = |
| 1267 | cpu_to_le32(upper_32_bits(cmd->sense_phys_addr)); |
| 1268 | pthru->sense_buf_phys_addr_lo = |
| 1269 | cpu_to_le32(lower_32_bits(cmd->sense_phys_addr)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1270 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1271 | /* |
| 1272 | * Compute the total number of frames this command consumes. FW uses |
| 1273 | * this number to pull sufficient number of frames from host memory. |
| 1274 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1275 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1276 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1277 | |
| 1278 | return cmd->frame_count; |
| 1279 | } |
| 1280 | |
| 1281 | /** |
| 1282 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1283 | * @instance: Adapter soft state |
| 1284 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1285 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1286 | * |
| 1287 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1288 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1289 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1290 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1291 | struct megasas_cmd *cmd) |
| 1292 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1293 | u32 device_id; |
| 1294 | u8 sc = scp->cmnd[0]; |
| 1295 | u16 flags = 0; |
| 1296 | struct megasas_io_frame *ldio; |
| 1297 | |
| 1298 | device_id = MEGASAS_DEV_INDEX(instance, scp); |
| 1299 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1300 | |
| 1301 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1302 | flags = MFI_FRAME_DIR_WRITE; |
| 1303 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1304 | flags = MFI_FRAME_DIR_READ; |
| 1305 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1306 | if (instance->flag_ieee == 1) { |
| 1307 | flags |= MFI_FRAME_IEEE; |
| 1308 | } |
| 1309 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1310 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1311 | * 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] | 1312 | */ |
| 1313 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1314 | ldio->cmd_status = 0x0; |
| 1315 | ldio->scsi_status = 0x0; |
| 1316 | ldio->target_id = device_id; |
| 1317 | ldio->timeout = 0; |
| 1318 | ldio->reserved_0 = 0; |
| 1319 | ldio->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1320 | ldio->flags = cpu_to_le16(flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1321 | ldio->start_lba_hi = 0; |
| 1322 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1323 | |
| 1324 | /* |
| 1325 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1326 | */ |
| 1327 | if (scp->cmd_len == 6) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1328 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]); |
| 1329 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) | |
| 1330 | ((u32) scp->cmnd[2] << 8) | |
| 1331 | (u32) scp->cmnd[3]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1332 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1333 | ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /* |
| 1337 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1338 | */ |
| 1339 | else if (scp->cmd_len == 10) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1340 | ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] | |
| 1341 | ((u32) scp->cmnd[7] << 8)); |
| 1342 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1343 | ((u32) scp->cmnd[3] << 16) | |
| 1344 | ((u32) scp->cmnd[4] << 8) | |
| 1345 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /* |
| 1349 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1350 | */ |
| 1351 | else if (scp->cmd_len == 12) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1352 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1353 | ((u32) scp->cmnd[7] << 16) | |
| 1354 | ((u32) scp->cmnd[8] << 8) | |
| 1355 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1356 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1357 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1358 | ((u32) scp->cmnd[3] << 16) | |
| 1359 | ((u32) scp->cmnd[4] << 8) | |
| 1360 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | /* |
| 1364 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1365 | */ |
| 1366 | else if (scp->cmd_len == 16) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1367 | ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) | |
| 1368 | ((u32) scp->cmnd[11] << 16) | |
| 1369 | ((u32) scp->cmnd[12] << 8) | |
| 1370 | (u32) scp->cmnd[13]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1371 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1372 | ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) | |
| 1373 | ((u32) scp->cmnd[7] << 16) | |
| 1374 | ((u32) scp->cmnd[8] << 8) | |
| 1375 | (u32) scp->cmnd[9]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1376 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1377 | ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) | |
| 1378 | ((u32) scp->cmnd[3] << 16) | |
| 1379 | ((u32) scp->cmnd[4] << 8) | |
| 1380 | (u32) scp->cmnd[5]); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1381 | |
| 1382 | } |
| 1383 | |
| 1384 | /* |
| 1385 | * Construct SGL |
| 1386 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1387 | if (instance->flag_ieee) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1388 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1389 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1390 | &ldio->sgl); |
| 1391 | } else if (IS_DMA64) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1392 | ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1393 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1394 | } else |
| 1395 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1396 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1397 | if (ldio->sge_count > instance->max_num_sge) { |
| 1398 | printk(KERN_ERR "megasas: build_ld_io: sge_count = %x\n", |
| 1399 | ldio->sge_count); |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1403 | /* |
| 1404 | * Sense info specific |
| 1405 | */ |
| 1406 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1407 | ldio->sense_buf_phys_addr_hi = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1408 | 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] | 1409 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1410 | /* |
| 1411 | * Compute the total number of frames this command consumes. FW uses |
| 1412 | * this number to pull sufficient number of frames from host memory. |
| 1413 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1414 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1415 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1416 | |
| 1417 | return cmd->frame_count; |
| 1418 | } |
| 1419 | |
| 1420 | /** |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1421 | * megasas_is_ldio - Checks if the cmd is for logical drive |
| 1422 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1423 | * |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1424 | * Called by megasas_queue_command to find out if the command to be queued |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1425 | * is a logical drive command |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1426 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1427 | inline int megasas_is_ldio(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1428 | { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1429 | if (!MEGASAS_IS_LOGICAL(cmd)) |
| 1430 | return 0; |
| 1431 | switch (cmd->cmnd[0]) { |
| 1432 | case READ_10: |
| 1433 | case WRITE_10: |
| 1434 | case READ_12: |
| 1435 | case WRITE_12: |
| 1436 | case READ_6: |
| 1437 | case WRITE_6: |
| 1438 | case READ_16: |
| 1439 | case WRITE_16: |
| 1440 | return 1; |
| 1441 | default: |
| 1442 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1443 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1444 | } |
| 1445 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1446 | /** |
| 1447 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
| 1448 | * in FW |
| 1449 | * @instance: Adapter soft state |
| 1450 | */ |
| 1451 | static inline void |
| 1452 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1453 | { |
| 1454 | struct megasas_cmd *cmd; |
| 1455 | int i,n; |
| 1456 | union megasas_sgl *mfi_sgl; |
| 1457 | struct megasas_io_frame *ldio; |
| 1458 | struct megasas_pthru_frame *pthru; |
| 1459 | u32 sgcount; |
| 1460 | u32 max_cmd = instance->max_fw_cmds; |
| 1461 | |
| 1462 | printk(KERN_ERR "\nmegasas[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1463 | printk(KERN_ERR "megasas[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding)); |
| 1464 | if (IS_DMA64) |
| 1465 | printk(KERN_ERR "\nmegasas[%d]: 64 bit SGLs were sent to FW\n",instance->host->host_no); |
| 1466 | else |
| 1467 | printk(KERN_ERR "\nmegasas[%d]: 32 bit SGLs were sent to FW\n",instance->host->host_no); |
| 1468 | |
| 1469 | printk(KERN_ERR "megasas[%d]: Pending OS cmds in FW : \n",instance->host->host_no); |
| 1470 | for (i = 0; i < max_cmd; i++) { |
| 1471 | cmd = instance->cmd_list[i]; |
| 1472 | if(!cmd->scmd) |
| 1473 | continue; |
| 1474 | printk(KERN_ERR "megasas[%d]: Frame addr :0x%08lx : ",instance->host->host_no,(unsigned long)cmd->frame_phys_addr); |
| 1475 | if (megasas_is_ldio(cmd->scmd)){ |
| 1476 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1477 | mfi_sgl = &ldio->sgl; |
| 1478 | sgcount = ldio->sge_count; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1479 | printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x," |
| 1480 | " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1481 | instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id, |
| 1482 | le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi), |
| 1483 | le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1484 | } |
| 1485 | else { |
| 1486 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1487 | mfi_sgl = &pthru->sgl; |
| 1488 | sgcount = pthru->sge_count; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1489 | printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, " |
| 1490 | "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n", |
| 1491 | instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id, |
| 1492 | pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len), |
| 1493 | le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1494 | } |
| 1495 | if(megasas_dbg_lvl & MEGASAS_DBG_LVL){ |
| 1496 | for (n = 0; n < sgcount; n++){ |
| 1497 | if (IS_DMA64) |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1498 | printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%llx ", |
| 1499 | le32_to_cpu(mfi_sgl->sge64[n].length), |
| 1500 | le64_to_cpu(mfi_sgl->sge64[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1501 | else |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1502 | printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%x ", |
| 1503 | le32_to_cpu(mfi_sgl->sge32[n].length), |
| 1504 | le32_to_cpu(mfi_sgl->sge32[n].phys_addr)); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1505 | } |
| 1506 | } |
| 1507 | printk(KERN_ERR "\n"); |
| 1508 | } /*for max_cmd*/ |
| 1509 | printk(KERN_ERR "\nmegasas[%d]: Pending Internal cmds in FW : \n",instance->host->host_no); |
| 1510 | for (i = 0; i < max_cmd; i++) { |
| 1511 | |
| 1512 | cmd = instance->cmd_list[i]; |
| 1513 | |
| 1514 | if(cmd->sync_cmd == 1){ |
| 1515 | printk(KERN_ERR "0x%08lx : ", (unsigned long)cmd->frame_phys_addr); |
| 1516 | } |
| 1517 | } |
| 1518 | printk(KERN_ERR "megasas[%d]: Dumping Done.\n\n",instance->host->host_no); |
| 1519 | } |
| 1520 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1521 | u32 |
| 1522 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1523 | struct scsi_cmnd *scmd) |
| 1524 | { |
| 1525 | struct megasas_cmd *cmd; |
| 1526 | u32 frame_count; |
| 1527 | |
| 1528 | cmd = megasas_get_cmd(instance); |
| 1529 | if (!cmd) |
| 1530 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1531 | |
| 1532 | /* |
| 1533 | * Logical drive command |
| 1534 | */ |
| 1535 | if (megasas_is_ldio(scmd)) |
| 1536 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1537 | else |
| 1538 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1539 | |
| 1540 | if (!frame_count) |
| 1541 | goto out_return_cmd; |
| 1542 | |
| 1543 | cmd->scmd = scmd; |
| 1544 | scmd->SCp.ptr = (char *)cmd; |
| 1545 | |
| 1546 | /* |
| 1547 | * Issue the command to the FW |
| 1548 | */ |
| 1549 | atomic_inc(&instance->fw_outstanding); |
| 1550 | |
| 1551 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1552 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1553 | |
| 1554 | return 0; |
| 1555 | out_return_cmd: |
| 1556 | megasas_return_cmd(instance, cmd); |
| 1557 | return 1; |
| 1558 | } |
| 1559 | |
| 1560 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1561 | /** |
| 1562 | * megasas_queue_command - Queue entry point |
| 1563 | * @scmd: SCSI command to be queued |
| 1564 | * @done: Callback entry point |
| 1565 | */ |
| 1566 | static int |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1567 | megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1568 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1569 | struct megasas_instance *instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1570 | unsigned long flags; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1571 | |
| 1572 | instance = (struct megasas_instance *) |
| 1573 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1574 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1575 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1576 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1577 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1578 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1579 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1580 | /* Check for an mpio path and adjust behavior */ |
| 1581 | if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) { |
| 1582 | if (megasas_check_mpio_paths(instance, scmd) == |
| 1583 | (DID_RESET << 16)) { |
| 1584 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1585 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1586 | } else { |
| 1587 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1588 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1589 | scmd->scsi_done(scmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1590 | return 0; |
| 1591 | } |
| 1592 | } |
| 1593 | |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1594 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 1595 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1596 | scmd->result = DID_NO_CONNECT << 16; |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1597 | scmd->scsi_done(scmd); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1598 | return 0; |
| 1599 | } |
| 1600 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1601 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 1602 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1603 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1604 | } |
| 1605 | |
| 1606 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1607 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1608 | scmd->result = 0; |
| 1609 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1610 | if (MEGASAS_IS_LOGICAL(scmd) && |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1611 | (scmd->device->id >= instance->fw_supported_vd_count || |
| 1612 | scmd->device->lun)) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1613 | scmd->result = DID_BAD_TARGET << 16; |
| 1614 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1615 | } |
| 1616 | |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1617 | switch (scmd->cmnd[0]) { |
| 1618 | case SYNCHRONIZE_CACHE: |
| 1619 | /* |
| 1620 | * FW takes care of flush cache on its own |
| 1621 | * No need to send it down |
| 1622 | */ |
| 1623 | scmd->result = DID_OK << 16; |
| 1624 | goto out_done; |
| 1625 | default: |
| 1626 | break; |
| 1627 | } |
| 1628 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1629 | if (instance->instancet->build_and_issue_cmd(instance, scmd)) { |
| 1630 | printk(KERN_ERR "megasas: Err returned from build_and_issue_cmd\n"); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1631 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1632 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1633 | |
| 1634 | return 0; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1635 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1636 | out_done: |
Sumit.Saxena@avagotech.com | fb1a24f | 2014-09-12 18:57:38 +0530 | [diff] [blame] | 1637 | scmd->scsi_done(scmd); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1638 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1639 | } |
| 1640 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1641 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1642 | { |
| 1643 | int i; |
| 1644 | |
| 1645 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1646 | |
| 1647 | if ((megasas_mgmt_info.instance[i]) && |
| 1648 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1649 | return megasas_mgmt_info.instance[i]; |
| 1650 | } |
| 1651 | |
| 1652 | return NULL; |
| 1653 | } |
| 1654 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1655 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1656 | { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1657 | /* |
| 1658 | * The RAID firmware may require extended timeouts. |
| 1659 | */ |
| 1660 | blk_queue_rq_timeout(sdev->request_queue, |
| 1661 | MEGASAS_DEFAULT_CMD_TIMEOUT * HZ); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1662 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 1667 | { |
| 1668 | u16 pd_index = 0; |
| 1669 | struct megasas_instance *instance ; |
| 1670 | instance = megasas_lookup_instance(sdev->host->host_no); |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1671 | if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1672 | /* |
| 1673 | * Open the OS scan to the SYSTEM PD |
| 1674 | */ |
| 1675 | pd_index = |
| 1676 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1677 | sdev->id; |
Sumit.Saxena@avagotech.com | 07e38d9 | 2014-09-12 18:57:13 +0530 | [diff] [blame] | 1678 | if (instance->pd_list[pd_index].driveState == |
| 1679 | MR_PD_STATE_SYSTEM) { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1680 | return 0; |
| 1681 | } |
| 1682 | return -ENXIO; |
| 1683 | } |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1684 | return 0; |
| 1685 | } |
| 1686 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1687 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1688 | { |
| 1689 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1690 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1691 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1692 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1693 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1694 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1695 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1696 | /* Flush */ |
| 1697 | readl(&instance->reg_set->doorbell); |
| 1698 | if (instance->mpio && instance->requestorId) |
| 1699 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1700 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1701 | writel(MFI_STOP_ADP, &instance->reg_set->inbound_doorbell); |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | /** |
| 1706 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 1707 | * restored to max value |
| 1708 | * @instance: Adapter soft state |
| 1709 | * |
| 1710 | */ |
| 1711 | void |
| 1712 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 1713 | { |
| 1714 | unsigned long flags; |
| 1715 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 1716 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 1717 | && atomic_read(&instance->fw_outstanding) < |
| 1718 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1719 | |
| 1720 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 1721 | instance->flag &= ~MEGASAS_FW_BUSY; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 1722 | if (instance->is_imr) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1723 | instance->host->can_queue = |
| 1724 | instance->max_fw_cmds - MEGASAS_SKINNY_INT_CMDS; |
| 1725 | } else |
| 1726 | instance->host->can_queue = |
| 1727 | instance->max_fw_cmds - MEGASAS_INT_CMDS; |
| 1728 | |
| 1729 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1733 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1734 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 1735 | * @instance_addr: Address of adapter soft state |
| 1736 | * |
| 1737 | * Tasklet to complete cmds |
| 1738 | */ |
| 1739 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 1740 | { |
| 1741 | u32 producer; |
| 1742 | u32 consumer; |
| 1743 | u32 context; |
| 1744 | struct megasas_cmd *cmd; |
| 1745 | struct megasas_instance *instance = |
| 1746 | (struct megasas_instance *)instance_addr; |
| 1747 | unsigned long flags; |
| 1748 | |
| 1749 | /* If we have already declared adapter dead, donot complete cmds */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1750 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR ) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1751 | return; |
| 1752 | |
| 1753 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 1754 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1755 | producer = le32_to_cpu(*instance->producer); |
| 1756 | consumer = le32_to_cpu(*instance->consumer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1757 | |
| 1758 | while (consumer != producer) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1759 | context = le32_to_cpu(instance->reply_queue[consumer]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1760 | if (context >= instance->max_fw_cmds) { |
| 1761 | printk(KERN_ERR "Unexpected context value %x\n", |
| 1762 | context); |
| 1763 | BUG(); |
| 1764 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1765 | |
| 1766 | cmd = instance->cmd_list[context]; |
| 1767 | |
| 1768 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 1769 | |
| 1770 | consumer++; |
| 1771 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 1772 | consumer = 0; |
| 1773 | } |
| 1774 | } |
| 1775 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1776 | *instance->consumer = cpu_to_le32(producer); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1777 | |
| 1778 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 1779 | |
| 1780 | /* |
| 1781 | * Check if we can restore can_queue |
| 1782 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1783 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1784 | } |
| 1785 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1786 | /** |
| 1787 | * megasas_start_timer - Initializes a timer object |
| 1788 | * @instance: Adapter soft state |
| 1789 | * @timer: timer object to be initialized |
| 1790 | * @fn: timer function |
| 1791 | * @interval: time interval between timer function call |
| 1792 | * |
| 1793 | */ |
| 1794 | void megasas_start_timer(struct megasas_instance *instance, |
| 1795 | struct timer_list *timer, |
| 1796 | void *fn, unsigned long interval) |
| 1797 | { |
| 1798 | init_timer(timer); |
| 1799 | timer->expires = jiffies + interval; |
| 1800 | timer->data = (unsigned long)instance; |
| 1801 | timer->function = fn; |
| 1802 | add_timer(timer); |
| 1803 | } |
| 1804 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1805 | static void |
| 1806 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 1807 | |
| 1808 | static void |
| 1809 | process_fw_state_change_wq(struct work_struct *work); |
| 1810 | |
| 1811 | void megasas_do_ocr(struct megasas_instance *instance) |
| 1812 | { |
| 1813 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 1814 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 1815 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1816 | *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1817 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 1818 | instance->instancet->disable_intr(instance); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1819 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
| 1820 | instance->issuepend_done = 0; |
| 1821 | |
| 1822 | atomic_set(&instance->fw_outstanding, 0); |
| 1823 | megasas_internal_reset_defer_cmds(instance); |
| 1824 | process_fw_state_change_wq(&instance->work_init); |
| 1825 | } |
| 1826 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1827 | static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance, |
| 1828 | int initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1829 | { |
| 1830 | struct megasas_cmd *cmd; |
| 1831 | struct megasas_dcmd_frame *dcmd; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1832 | struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1833 | dma_addr_t new_affiliation_111_h; |
| 1834 | int ld, retval = 0; |
| 1835 | u8 thisVf; |
| 1836 | |
| 1837 | cmd = megasas_get_cmd(instance); |
| 1838 | |
| 1839 | if (!cmd) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1840 | printk(KERN_DEBUG "megasas: megasas_get_ld_vf_affiliation_111:" |
| 1841 | "Failed to get cmd for scsi%d.\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1842 | instance->host->host_no); |
| 1843 | return -ENOMEM; |
| 1844 | } |
| 1845 | |
| 1846 | dcmd = &cmd->frame->dcmd; |
| 1847 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1848 | if (!instance->vf_affiliation_111) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1849 | printk(KERN_WARNING "megasas: SR-IOV: Couldn't get LD/VF " |
| 1850 | "affiliation for scsi%d.\n", instance->host->host_no); |
| 1851 | megasas_return_cmd(instance, cmd); |
| 1852 | return -ENOMEM; |
| 1853 | } |
| 1854 | |
| 1855 | if (initial) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1856 | memset(instance->vf_affiliation_111, 0, |
| 1857 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1858 | else { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1859 | new_affiliation_111 = |
| 1860 | pci_alloc_consistent(instance->pdev, |
| 1861 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 1862 | &new_affiliation_111_h); |
| 1863 | if (!new_affiliation_111) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1864 | printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate " |
| 1865 | "memory for new affiliation for scsi%d.\n", |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1866 | instance->host->host_no); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1867 | megasas_return_cmd(instance, cmd); |
| 1868 | return -ENOMEM; |
| 1869 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1870 | memset(new_affiliation_111, 0, |
| 1871 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 1875 | |
| 1876 | dcmd->cmd = MFI_CMD_DCMD; |
| 1877 | dcmd->cmd_status = 0xFF; |
| 1878 | dcmd->sge_count = 1; |
| 1879 | dcmd->flags = MFI_FRAME_DIR_BOTH; |
| 1880 | dcmd->timeout = 0; |
| 1881 | dcmd->pad_0 = 0; |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1882 | dcmd->data_xfer_len = sizeof(struct MR_LD_VF_AFFILIATION_111); |
| 1883 | dcmd->opcode = MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1884 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1885 | if (initial) |
| 1886 | dcmd->sgl.sge32[0].phys_addr = |
| 1887 | instance->vf_affiliation_111_h; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1888 | else |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1889 | dcmd->sgl.sge32[0].phys_addr = new_affiliation_111_h; |
| 1890 | |
| 1891 | dcmd->sgl.sge32[0].length = |
| 1892 | sizeof(struct MR_LD_VF_AFFILIATION_111); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1893 | |
| 1894 | printk(KERN_WARNING "megasas: SR-IOV: Getting LD/VF affiliation for " |
| 1895 | "scsi%d\n", instance->host->host_no); |
| 1896 | |
| 1897 | megasas_issue_blocked_cmd(instance, cmd, 0); |
| 1898 | |
| 1899 | if (dcmd->cmd_status) { |
| 1900 | printk(KERN_WARNING "megasas: SR-IOV: LD/VF affiliation DCMD" |
| 1901 | " failed with status 0x%x for scsi%d.\n", |
| 1902 | dcmd->cmd_status, instance->host->host_no); |
| 1903 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 1904 | goto out; |
| 1905 | } |
| 1906 | |
| 1907 | if (!initial) { |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1908 | thisVf = new_affiliation_111->thisVf; |
| 1909 | for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++) |
| 1910 | if (instance->vf_affiliation_111->map[ld].policy[thisVf] != |
| 1911 | new_affiliation_111->map[ld].policy[thisVf]) { |
| 1912 | printk(KERN_WARNING "megasas: SR-IOV: " |
| 1913 | "Got new LD/VF affiliation " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1914 | "for scsi%d.\n", |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1915 | instance->host->host_no); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1916 | memcpy(instance->vf_affiliation_111, |
| 1917 | new_affiliation_111, |
| 1918 | sizeof(struct MR_LD_VF_AFFILIATION_111)); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 1919 | retval = 1; |
| 1920 | goto out; |
| 1921 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1922 | } |
| 1923 | out: |
| 1924 | if (new_affiliation_111) { |
| 1925 | pci_free_consistent(instance->pdev, |
| 1926 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 1927 | new_affiliation_111, |
| 1928 | new_affiliation_111_h); |
| 1929 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1930 | |
| 1931 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 1932 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 1933 | cmd->mpt_pthr_cmd_blocked); |
| 1934 | else |
| 1935 | megasas_return_cmd(instance, cmd); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 1936 | |
| 1937 | return retval; |
| 1938 | } |
| 1939 | |
| 1940 | static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance, |
| 1941 | int initial) |
| 1942 | { |
| 1943 | struct megasas_cmd *cmd; |
| 1944 | struct megasas_dcmd_frame *dcmd; |
| 1945 | struct MR_LD_VF_AFFILIATION *new_affiliation = NULL; |
| 1946 | struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL; |
| 1947 | dma_addr_t new_affiliation_h; |
| 1948 | int i, j, retval = 0, found = 0, doscan = 0; |
| 1949 | u8 thisVf; |
| 1950 | |
| 1951 | cmd = megasas_get_cmd(instance); |
| 1952 | |
| 1953 | if (!cmd) { |
| 1954 | printk(KERN_DEBUG "megasas: megasas_get_ld_vf_affiliation12: " |
| 1955 | "Failed to get cmd for scsi%d.\n", |
| 1956 | instance->host->host_no); |
| 1957 | return -ENOMEM; |
| 1958 | } |
| 1959 | |
| 1960 | dcmd = &cmd->frame->dcmd; |
| 1961 | |
| 1962 | if (!instance->vf_affiliation) { |
| 1963 | printk(KERN_WARNING "megasas: SR-IOV: Couldn't get LD/VF " |
| 1964 | "affiliation for scsi%d.\n", instance->host->host_no); |
| 1965 | megasas_return_cmd(instance, cmd); |
| 1966 | return -ENOMEM; |
| 1967 | } |
| 1968 | |
| 1969 | if (initial) |
| 1970 | memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 1971 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 1972 | else { |
| 1973 | new_affiliation = |
| 1974 | pci_alloc_consistent(instance->pdev, |
| 1975 | (MAX_LOGICAL_DRIVES + 1) * |
| 1976 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 1977 | &new_affiliation_h); |
| 1978 | if (!new_affiliation) { |
| 1979 | printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate " |
| 1980 | "memory for new affiliation for scsi%d.\n", |
| 1981 | instance->host->host_no); |
| 1982 | megasas_return_cmd(instance, cmd); |
| 1983 | return -ENOMEM; |
| 1984 | } |
| 1985 | memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) * |
| 1986 | sizeof(struct MR_LD_VF_AFFILIATION)); |
| 1987 | } |
| 1988 | |
| 1989 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 1990 | |
| 1991 | dcmd->cmd = MFI_CMD_DCMD; |
| 1992 | dcmd->cmd_status = 0xFF; |
| 1993 | dcmd->sge_count = 1; |
| 1994 | dcmd->flags = MFI_FRAME_DIR_BOTH; |
| 1995 | dcmd->timeout = 0; |
| 1996 | dcmd->pad_0 = 0; |
| 1997 | dcmd->data_xfer_len = (MAX_LOGICAL_DRIVES + 1) * |
| 1998 | sizeof(struct MR_LD_VF_AFFILIATION); |
| 1999 | dcmd->opcode = MR_DCMD_LD_VF_MAP_GET_ALL_LDS; |
| 2000 | |
| 2001 | if (initial) |
| 2002 | dcmd->sgl.sge32[0].phys_addr = instance->vf_affiliation_h; |
| 2003 | else |
| 2004 | dcmd->sgl.sge32[0].phys_addr = new_affiliation_h; |
| 2005 | |
| 2006 | dcmd->sgl.sge32[0].length = (MAX_LOGICAL_DRIVES + 1) * |
| 2007 | sizeof(struct MR_LD_VF_AFFILIATION); |
| 2008 | |
| 2009 | printk(KERN_WARNING "megasas: SR-IOV: Getting LD/VF affiliation for " |
| 2010 | "scsi%d\n", instance->host->host_no); |
| 2011 | |
| 2012 | megasas_issue_blocked_cmd(instance, cmd, 0); |
| 2013 | |
| 2014 | if (dcmd->cmd_status) { |
| 2015 | printk(KERN_WARNING "megasas: SR-IOV: LD/VF affiliation DCMD" |
| 2016 | " failed with status 0x%x for scsi%d.\n", |
| 2017 | dcmd->cmd_status, instance->host->host_no); |
| 2018 | retval = 1; /* Do a scan if we couldn't get affiliation */ |
| 2019 | goto out; |
| 2020 | } |
| 2021 | |
| 2022 | if (!initial) { |
| 2023 | if (!new_affiliation->ldCount) { |
| 2024 | printk(KERN_WARNING "megasas: SR-IOV: Got new LD/VF " |
| 2025 | "affiliation for passive path for scsi%d.\n", |
| 2026 | instance->host->host_no); |
| 2027 | retval = 1; |
| 2028 | goto out; |
| 2029 | } |
| 2030 | newmap = new_affiliation->map; |
| 2031 | savedmap = instance->vf_affiliation->map; |
| 2032 | thisVf = new_affiliation->thisVf; |
| 2033 | for (i = 0 ; i < new_affiliation->ldCount; i++) { |
| 2034 | found = 0; |
| 2035 | for (j = 0; j < instance->vf_affiliation->ldCount; |
| 2036 | j++) { |
| 2037 | if (newmap->ref.targetId == |
| 2038 | savedmap->ref.targetId) { |
| 2039 | found = 1; |
| 2040 | if (newmap->policy[thisVf] != |
| 2041 | savedmap->policy[thisVf]) { |
| 2042 | doscan = 1; |
| 2043 | goto out; |
| 2044 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2045 | } |
| 2046 | savedmap = (struct MR_LD_VF_MAP *) |
| 2047 | ((unsigned char *)savedmap + |
| 2048 | savedmap->size); |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2049 | } |
| 2050 | if (!found && newmap->policy[thisVf] != |
| 2051 | MR_LD_ACCESS_HIDDEN) { |
| 2052 | doscan = 1; |
| 2053 | goto out; |
| 2054 | } |
| 2055 | newmap = (struct MR_LD_VF_MAP *) |
| 2056 | ((unsigned char *)newmap + newmap->size); |
| 2057 | } |
| 2058 | |
| 2059 | newmap = new_affiliation->map; |
| 2060 | savedmap = instance->vf_affiliation->map; |
| 2061 | |
| 2062 | for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) { |
| 2063 | found = 0; |
| 2064 | for (j = 0 ; j < new_affiliation->ldCount; j++) { |
| 2065 | if (savedmap->ref.targetId == |
| 2066 | newmap->ref.targetId) { |
| 2067 | found = 1; |
| 2068 | if (savedmap->policy[thisVf] != |
| 2069 | newmap->policy[thisVf]) { |
| 2070 | doscan = 1; |
| 2071 | goto out; |
| 2072 | } |
| 2073 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2074 | newmap = (struct MR_LD_VF_MAP *) |
| 2075 | ((unsigned char *)newmap + |
| 2076 | newmap->size); |
| 2077 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2078 | if (!found && savedmap->policy[thisVf] != |
| 2079 | MR_LD_ACCESS_HIDDEN) { |
| 2080 | doscan = 1; |
| 2081 | goto out; |
| 2082 | } |
| 2083 | savedmap = (struct MR_LD_VF_MAP *) |
| 2084 | ((unsigned char *)savedmap + |
| 2085 | savedmap->size); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | out: |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2089 | if (doscan) { |
| 2090 | printk(KERN_WARNING "megasas: SR-IOV: Got new LD/VF " |
| 2091 | "affiliation for scsi%d.\n", instance->host->host_no); |
| 2092 | memcpy(instance->vf_affiliation, new_affiliation, |
| 2093 | new_affiliation->size); |
| 2094 | retval = 1; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2095 | } |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2096 | |
| 2097 | if (new_affiliation) |
| 2098 | pci_free_consistent(instance->pdev, |
| 2099 | (MAX_LOGICAL_DRIVES + 1) * |
| 2100 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 2101 | new_affiliation, new_affiliation_h); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2102 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 2103 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 2104 | cmd->mpt_pthr_cmd_blocked); |
| 2105 | else |
| 2106 | megasas_return_cmd(instance, cmd); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2107 | |
| 2108 | return retval; |
| 2109 | } |
| 2110 | |
Adam Radford | 4cbfea8 | 2014-07-09 15:17:56 -0700 | [diff] [blame] | 2111 | /* This function will get the current SR-IOV LD/VF affiliation */ |
| 2112 | static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance, |
| 2113 | int initial) |
| 2114 | { |
| 2115 | int retval; |
| 2116 | |
| 2117 | if (instance->PlasmaFW111) |
| 2118 | retval = megasas_get_ld_vf_affiliation_111(instance, initial); |
| 2119 | else |
| 2120 | retval = megasas_get_ld_vf_affiliation_12(instance, initial); |
| 2121 | return retval; |
| 2122 | } |
| 2123 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2124 | /* This function will tell FW to start the SR-IOV heartbeat */ |
| 2125 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 2126 | int initial) |
| 2127 | { |
| 2128 | struct megasas_cmd *cmd; |
| 2129 | struct megasas_dcmd_frame *dcmd; |
| 2130 | int retval = 0; |
| 2131 | |
| 2132 | cmd = megasas_get_cmd(instance); |
| 2133 | |
| 2134 | if (!cmd) { |
| 2135 | printk(KERN_DEBUG "megasas: megasas_sriov_start_heartbeat: " |
| 2136 | "Failed to get cmd for scsi%d.\n", |
| 2137 | instance->host->host_no); |
| 2138 | return -ENOMEM; |
| 2139 | } |
| 2140 | |
| 2141 | dcmd = &cmd->frame->dcmd; |
| 2142 | |
| 2143 | if (initial) { |
| 2144 | instance->hb_host_mem = |
Joe Perches | 7c845eb | 2014-08-08 14:24:46 -0700 | [diff] [blame] | 2145 | pci_zalloc_consistent(instance->pdev, |
| 2146 | sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 2147 | &instance->hb_host_mem_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2148 | if (!instance->hb_host_mem) { |
| 2149 | printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate" |
| 2150 | " memory for heartbeat host memory for " |
| 2151 | "scsi%d.\n", instance->host->host_no); |
| 2152 | retval = -ENOMEM; |
| 2153 | goto out; |
| 2154 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 2158 | |
| 2159 | dcmd->mbox.s[0] = sizeof(struct MR_CTRL_HB_HOST_MEM); |
| 2160 | dcmd->cmd = MFI_CMD_DCMD; |
| 2161 | dcmd->cmd_status = 0xFF; |
| 2162 | dcmd->sge_count = 1; |
| 2163 | dcmd->flags = MFI_FRAME_DIR_BOTH; |
| 2164 | dcmd->timeout = 0; |
| 2165 | dcmd->pad_0 = 0; |
| 2166 | dcmd->data_xfer_len = sizeof(struct MR_CTRL_HB_HOST_MEM); |
| 2167 | dcmd->opcode = MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC; |
| 2168 | dcmd->sgl.sge32[0].phys_addr = instance->hb_host_mem_h; |
| 2169 | dcmd->sgl.sge32[0].length = sizeof(struct MR_CTRL_HB_HOST_MEM); |
| 2170 | |
| 2171 | printk(KERN_WARNING "megasas: SR-IOV: Starting heartbeat for scsi%d\n", |
| 2172 | instance->host->host_no); |
| 2173 | |
| 2174 | if (!megasas_issue_polled(instance, cmd)) { |
| 2175 | retval = 0; |
| 2176 | } else { |
| 2177 | printk(KERN_WARNING "megasas: SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2178 | "_MEM_ALLOC DCMD timed out for scsi%d\n", |
| 2179 | instance->host->host_no); |
| 2180 | retval = 1; |
| 2181 | goto out; |
| 2182 | } |
| 2183 | |
| 2184 | |
| 2185 | if (dcmd->cmd_status) { |
| 2186 | printk(KERN_WARNING "megasas: SR-IOV: MR_DCMD_CTRL_SHARED_HOST" |
| 2187 | "_MEM_ALLOC DCMD failed with status 0x%x for scsi%d\n", |
| 2188 | dcmd->cmd_status, |
| 2189 | instance->host->host_no); |
| 2190 | retval = 1; |
| 2191 | goto out; |
| 2192 | } |
| 2193 | |
| 2194 | out: |
| 2195 | megasas_return_cmd(instance, cmd); |
| 2196 | |
| 2197 | return retval; |
| 2198 | } |
| 2199 | |
| 2200 | /* Handler for SR-IOV heartbeat */ |
| 2201 | void megasas_sriov_heartbeat_handler(unsigned long instance_addr) |
| 2202 | { |
| 2203 | struct megasas_instance *instance = |
| 2204 | (struct megasas_instance *)instance_addr; |
| 2205 | |
| 2206 | if (instance->hb_host_mem->HB.fwCounter != |
| 2207 | instance->hb_host_mem->HB.driverCounter) { |
| 2208 | instance->hb_host_mem->HB.driverCounter = |
| 2209 | instance->hb_host_mem->HB.fwCounter; |
| 2210 | mod_timer(&instance->sriov_heartbeat_timer, |
| 2211 | jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2212 | } else { |
| 2213 | printk(KERN_WARNING "megasas: SR-IOV: Heartbeat never " |
| 2214 | "completed for scsi%d\n", instance->host->host_no); |
| 2215 | schedule_work(&instance->work_init); |
| 2216 | } |
| 2217 | } |
| 2218 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2219 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2220 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 2221 | * @instance: Adapter soft state |
| 2222 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2223 | * 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] | 2224 | * complete all its outstanding commands. Returns error if one or more IOs |
| 2225 | * are pending after this time period. It also marks the controller dead. |
| 2226 | */ |
| 2227 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 2228 | { |
| 2229 | int i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2230 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2231 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2232 | u8 adprecovery; |
| 2233 | unsigned long flags; |
| 2234 | struct list_head clist_local; |
| 2235 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2236 | u32 fw_state; |
| 2237 | u8 kill_adapter_flag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2238 | |
| 2239 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2240 | adprecovery = instance->adprecovery; |
| 2241 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2242 | |
| 2243 | if (adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 2244 | |
| 2245 | INIT_LIST_HEAD(&clist_local); |
| 2246 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2247 | list_splice_init(&instance->internal_reset_pending_q, |
| 2248 | &clist_local); |
| 2249 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2250 | |
| 2251 | printk(KERN_NOTICE "megasas: HBA reset wait ...\n"); |
| 2252 | for (i = 0; i < wait_time; i++) { |
| 2253 | msleep(1000); |
| 2254 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2255 | adprecovery = instance->adprecovery; |
| 2256 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2257 | if (adprecovery == MEGASAS_HBA_OPERATIONAL) |
| 2258 | break; |
| 2259 | } |
| 2260 | |
| 2261 | if (adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 2262 | printk(KERN_NOTICE "megasas: reset: Stopping HBA.\n"); |
| 2263 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2264 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 2265 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2266 | return FAILED; |
| 2267 | } |
| 2268 | |
| 2269 | reset_index = 0; |
| 2270 | while (!list_empty(&clist_local)) { |
| 2271 | reset_cmd = list_entry((&clist_local)->next, |
| 2272 | struct megasas_cmd, list); |
| 2273 | list_del_init(&reset_cmd->list); |
| 2274 | if (reset_cmd->scmd) { |
| 2275 | reset_cmd->scmd->result = DID_RESET << 16; |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2276 | printk(KERN_NOTICE "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2277 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2278 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2279 | |
| 2280 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 2281 | megasas_return_cmd(instance, reset_cmd); |
| 2282 | } else if (reset_cmd->sync_cmd) { |
| 2283 | printk(KERN_NOTICE "megasas:%p synch cmds" |
| 2284 | "reset queue\n", |
| 2285 | reset_cmd); |
| 2286 | |
| 2287 | reset_cmd->cmd_status = ENODATA; |
| 2288 | instance->instancet->fire_cmd(instance, |
| 2289 | reset_cmd->frame_phys_addr, |
| 2290 | 0, instance->reg_set); |
| 2291 | } else { |
| 2292 | printk(KERN_NOTICE "megasas: %p unexpected" |
| 2293 | "cmds lst\n", |
| 2294 | reset_cmd); |
| 2295 | } |
| 2296 | reset_index++; |
| 2297 | } |
| 2298 | |
| 2299 | return SUCCESS; |
| 2300 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2301 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2302 | for (i = 0; i < resetwaittime; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2303 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2304 | int outstanding = atomic_read(&instance->fw_outstanding); |
| 2305 | |
| 2306 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2307 | break; |
| 2308 | |
| 2309 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 2310 | printk(KERN_NOTICE "megasas: [%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2311 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 2312 | /* |
| 2313 | * Call cmd completion routine. Cmd to be |
| 2314 | * be completed directly without depending on isr. |
| 2315 | */ |
| 2316 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | msleep(1000); |
| 2320 | } |
| 2321 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2322 | i = 0; |
| 2323 | kill_adapter_flag = 0; |
| 2324 | do { |
| 2325 | fw_state = instance->instancet->read_fw_status_reg( |
| 2326 | instance->reg_set) & MFI_STATE_MASK; |
| 2327 | if ((fw_state == MFI_STATE_FAULT) && |
| 2328 | (instance->disableOnlineCtrlReset == 0)) { |
| 2329 | if (i == 3) { |
| 2330 | kill_adapter_flag = 2; |
| 2331 | break; |
| 2332 | } |
| 2333 | megasas_do_ocr(instance); |
| 2334 | kill_adapter_flag = 1; |
| 2335 | |
| 2336 | /* wait for 1 secs to let FW finish the pending cmds */ |
| 2337 | msleep(1000); |
| 2338 | } |
| 2339 | i++; |
| 2340 | } while (i <= 3); |
| 2341 | |
| 2342 | if (atomic_read(&instance->fw_outstanding) && |
| 2343 | !kill_adapter_flag) { |
| 2344 | if (instance->disableOnlineCtrlReset == 0) { |
| 2345 | |
| 2346 | megasas_do_ocr(instance); |
| 2347 | |
| 2348 | /* wait for 5 secs to let FW finish the pending cmds */ |
| 2349 | for (i = 0; i < wait_time; i++) { |
| 2350 | int outstanding = |
| 2351 | atomic_read(&instance->fw_outstanding); |
| 2352 | if (!outstanding) |
| 2353 | return SUCCESS; |
| 2354 | msleep(1000); |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | if (atomic_read(&instance->fw_outstanding) || |
| 2360 | (kill_adapter_flag == 2)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2361 | printk(KERN_NOTICE "megaraid_sas: pending cmds after reset\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2362 | /* |
| 2363 | * Send signal to FW to stop processing any pending cmds. |
| 2364 | * The controller will be taken offline by the OS now. |
| 2365 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 2366 | if ((instance->pdev->device == |
| 2367 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 2368 | (instance->pdev->device == |
| 2369 | PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 2370 | writel(MFI_STOP_ADP, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2371 | &instance->reg_set->doorbell); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 2372 | } else { |
| 2373 | writel(MFI_STOP_ADP, |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2374 | &instance->reg_set->inbound_doorbell); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 2375 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 2376 | megasas_dump_pending_frames(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2377 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2378 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 2379 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2380 | return FAILED; |
| 2381 | } |
| 2382 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2383 | printk(KERN_NOTICE "megaraid_sas: no pending cmds after reset\n"); |
| 2384 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2385 | return SUCCESS; |
| 2386 | } |
| 2387 | |
| 2388 | /** |
| 2389 | * megasas_generic_reset - Generic reset routine |
| 2390 | * @scmd: Mid-layer SCSI command |
| 2391 | * |
| 2392 | * This routine implements a generic reset handler for device, bus and host |
| 2393 | * reset requests. Device, bus and host specific reset handlers can use this |
| 2394 | * function after they do their specific tasks. |
| 2395 | */ |
| 2396 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 2397 | { |
| 2398 | int ret_val; |
| 2399 | struct megasas_instance *instance; |
| 2400 | |
| 2401 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 2402 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2403 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 2404 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2405 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2406 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2407 | printk(KERN_ERR "megasas: cannot recover from previous reset " |
| 2408 | "failures\n"); |
| 2409 | return FAILED; |
| 2410 | } |
| 2411 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2412 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2413 | if (ret_val == SUCCESS) |
| 2414 | printk(KERN_NOTICE "megasas: reset successful \n"); |
| 2415 | else |
| 2416 | printk(KERN_ERR "megasas: failed to do reset\n"); |
| 2417 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2418 | return ret_val; |
| 2419 | } |
| 2420 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2421 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2422 | * megasas_reset_timer - quiesce the adapter if required |
| 2423 | * @scmd: scsi cmnd |
| 2424 | * |
| 2425 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 2426 | * cmd has not been completed within the timeout period. |
| 2427 | */ |
| 2428 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2429 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2430 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2431 | struct megasas_instance *instance; |
| 2432 | unsigned long flags; |
| 2433 | |
| 2434 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
| 2435 | (MEGASAS_DEFAULT_CMD_TIMEOUT * 2) * HZ)) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2436 | return BLK_EH_NOT_HANDLED; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 2439 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2440 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 2441 | /* FW is busy, throttle IO */ |
| 2442 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2443 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 2444 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2445 | instance->last_time = jiffies; |
| 2446 | instance->flag |= MEGASAS_FW_BUSY; |
| 2447 | |
| 2448 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 2449 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 2450 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2454 | * megasas_reset_device - Device reset handler entry point |
| 2455 | */ |
| 2456 | static int megasas_reset_device(struct scsi_cmnd *scmd) |
| 2457 | { |
| 2458 | int ret; |
| 2459 | |
| 2460 | /* |
| 2461 | * First wait for all commands to complete |
| 2462 | */ |
| 2463 | ret = megasas_generic_reset(scmd); |
| 2464 | |
| 2465 | return ret; |
| 2466 | } |
| 2467 | |
| 2468 | /** |
| 2469 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 2470 | */ |
| 2471 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 2472 | { |
| 2473 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2474 | struct megasas_instance *instance; |
| 2475 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2476 | |
| 2477 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 2478 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2479 | */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2480 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2481 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2482 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 2483 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2484 | ret = megasas_reset_fusion(scmd->device->host, 1); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2485 | else |
| 2486 | ret = megasas_generic_reset(scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2487 | |
| 2488 | return ret; |
| 2489 | } |
| 2490 | |
| 2491 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2492 | * megasas_bios_param - Returns disk geometry for a disk |
| 2493 | * @sdev: device handle |
| 2494 | * @bdev: block device |
| 2495 | * @capacity: drive capacity |
| 2496 | * @geom: geometry parameters |
| 2497 | */ |
| 2498 | static int |
| 2499 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2500 | sector_t capacity, int geom[]) |
| 2501 | { |
| 2502 | int heads; |
| 2503 | int sectors; |
| 2504 | sector_t cylinders; |
| 2505 | unsigned long tmp; |
| 2506 | /* Default heads (64) & sectors (32) */ |
| 2507 | heads = 64; |
| 2508 | sectors = 32; |
| 2509 | |
| 2510 | tmp = heads * sectors; |
| 2511 | cylinders = capacity; |
| 2512 | |
| 2513 | sector_div(cylinders, tmp); |
| 2514 | |
| 2515 | /* |
| 2516 | * Handle extended translation size for logical drives > 1Gb |
| 2517 | */ |
| 2518 | |
| 2519 | if (capacity >= 0x200000) { |
| 2520 | heads = 255; |
| 2521 | sectors = 63; |
| 2522 | tmp = heads*sectors; |
| 2523 | cylinders = capacity; |
| 2524 | sector_div(cylinders, tmp); |
| 2525 | } |
| 2526 | |
| 2527 | geom[0] = heads; |
| 2528 | geom[1] = sectors; |
| 2529 | geom[2] = cylinders; |
| 2530 | |
| 2531 | return 0; |
| 2532 | } |
| 2533 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2534 | static void megasas_aen_polling(struct work_struct *work); |
| 2535 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2536 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2537 | * megasas_service_aen - Processes an event notification |
| 2538 | * @instance: Adapter soft state |
| 2539 | * @cmd: AEN command completed by the ISR |
| 2540 | * |
| 2541 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2542 | * event occurs. When an event of interest occurs, FW completes the command |
| 2543 | * that it was previously holding. |
| 2544 | * |
| 2545 | * This routines sends SIGIO signal to processes that have registered with the |
| 2546 | * driver for AEN. |
| 2547 | */ |
| 2548 | static void |
| 2549 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2550 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2551 | unsigned long flags; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2552 | /* |
| 2553 | * Don't signal app if it is just an aborted previously registered aen |
| 2554 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2555 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2556 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2557 | megasas_poll_wait_aen = 1; |
| 2558 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2559 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2560 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2561 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2562 | else |
| 2563 | cmd->abort_aen = 0; |
| 2564 | |
| 2565 | instance->aen_cmd = NULL; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2566 | |
| 2567 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 2568 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 2569 | cmd->mpt_pthr_cmd_blocked); |
| 2570 | else |
| 2571 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2572 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2573 | if ((instance->unload == 0) && |
| 2574 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2575 | struct megasas_aen_event *ev; |
| 2576 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2577 | if (!ev) { |
| 2578 | printk(KERN_ERR "megasas_service_aen: out of memory\n"); |
| 2579 | } else { |
| 2580 | ev->instance = instance; |
| 2581 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 2582 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 2583 | megasas_aen_polling); |
| 2584 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2585 | } |
| 2586 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2587 | } |
| 2588 | |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 2589 | static int megasas_change_queue_depth(struct scsi_device *sdev, |
| 2590 | int queue_depth, int reason) |
| 2591 | { |
| 2592 | if (reason != SCSI_QDEPTH_DEFAULT) |
| 2593 | return -EOPNOTSUPP; |
| 2594 | |
| 2595 | if (queue_depth > sdev->host->can_queue) |
| 2596 | queue_depth = sdev->host->can_queue; |
Christoph Hellwig | c8b09f6 | 2014-11-03 20:15:14 +0100 | [diff] [blame] | 2597 | scsi_adjust_queue_depth(sdev, queue_depth); |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 2598 | |
| 2599 | return queue_depth; |
| 2600 | } |
| 2601 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2602 | static ssize_t |
| 2603 | megasas_fw_crash_buffer_store(struct device *cdev, |
| 2604 | struct device_attribute *attr, const char *buf, size_t count) |
| 2605 | { |
| 2606 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2607 | struct megasas_instance *instance = |
| 2608 | (struct megasas_instance *) shost->hostdata; |
| 2609 | int val = 0; |
| 2610 | unsigned long flags; |
| 2611 | |
| 2612 | if (kstrtoint(buf, 0, &val) != 0) |
| 2613 | return -EINVAL; |
| 2614 | |
| 2615 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2616 | instance->fw_crash_buffer_offset = val; |
| 2617 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2618 | return strlen(buf); |
| 2619 | } |
| 2620 | |
| 2621 | static ssize_t |
| 2622 | megasas_fw_crash_buffer_show(struct device *cdev, |
| 2623 | struct device_attribute *attr, char *buf) |
| 2624 | { |
| 2625 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2626 | struct megasas_instance *instance = |
| 2627 | (struct megasas_instance *) shost->hostdata; |
| 2628 | u32 size; |
| 2629 | unsigned long buff_addr; |
| 2630 | unsigned long dmachunk = CRASH_DMA_BUF_SIZE; |
| 2631 | unsigned long src_addr; |
| 2632 | unsigned long flags; |
| 2633 | u32 buff_offset; |
| 2634 | |
| 2635 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2636 | buff_offset = instance->fw_crash_buffer_offset; |
| 2637 | if (!instance->crash_dump_buf && |
| 2638 | !((instance->fw_crash_state == AVAILABLE) || |
| 2639 | (instance->fw_crash_state == COPYING))) { |
| 2640 | dev_err(&instance->pdev->dev, |
| 2641 | "Firmware crash dump is not available\n"); |
| 2642 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2643 | return -EINVAL; |
| 2644 | } |
| 2645 | |
| 2646 | buff_addr = (unsigned long) buf; |
| 2647 | |
| 2648 | if (buff_offset > |
| 2649 | (instance->fw_crash_buffer_size * dmachunk)) { |
| 2650 | dev_err(&instance->pdev->dev, |
| 2651 | "Firmware crash dump offset is out of range\n"); |
| 2652 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2653 | return 0; |
| 2654 | } |
| 2655 | |
| 2656 | size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset; |
| 2657 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 2658 | |
| 2659 | src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] + |
| 2660 | (buff_offset % dmachunk); |
| 2661 | memcpy(buf, (void *)src_addr, size); |
| 2662 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2663 | |
| 2664 | return size; |
| 2665 | } |
| 2666 | |
| 2667 | static ssize_t |
| 2668 | megasas_fw_crash_buffer_size_show(struct device *cdev, |
| 2669 | struct device_attribute *attr, char *buf) |
| 2670 | { |
| 2671 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2672 | struct megasas_instance *instance = |
| 2673 | (struct megasas_instance *) shost->hostdata; |
| 2674 | |
| 2675 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long) |
| 2676 | ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE); |
| 2677 | } |
| 2678 | |
| 2679 | static ssize_t |
| 2680 | megasas_fw_crash_state_store(struct device *cdev, |
| 2681 | struct device_attribute *attr, const char *buf, size_t count) |
| 2682 | { |
| 2683 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2684 | struct megasas_instance *instance = |
| 2685 | (struct megasas_instance *) shost->hostdata; |
| 2686 | int val = 0; |
| 2687 | unsigned long flags; |
| 2688 | |
| 2689 | if (kstrtoint(buf, 0, &val) != 0) |
| 2690 | return -EINVAL; |
| 2691 | |
| 2692 | if ((val <= AVAILABLE || val > COPY_ERROR)) { |
| 2693 | dev_err(&instance->pdev->dev, "application updates invalid " |
| 2694 | "firmware crash state\n"); |
| 2695 | return -EINVAL; |
| 2696 | } |
| 2697 | |
| 2698 | instance->fw_crash_state = val; |
| 2699 | |
| 2700 | if ((val == COPIED) || (val == COPY_ERROR)) { |
| 2701 | spin_lock_irqsave(&instance->crashdump_lock, flags); |
| 2702 | megasas_free_host_crash_buffer(instance); |
| 2703 | spin_unlock_irqrestore(&instance->crashdump_lock, flags); |
| 2704 | if (val == COPY_ERROR) |
| 2705 | dev_info(&instance->pdev->dev, "application failed to " |
| 2706 | "copy Firmware crash dump\n"); |
| 2707 | else |
| 2708 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 2709 | "copied successfully\n"); |
| 2710 | } |
| 2711 | return strlen(buf); |
| 2712 | } |
| 2713 | |
| 2714 | static ssize_t |
| 2715 | megasas_fw_crash_state_show(struct device *cdev, |
| 2716 | struct device_attribute *attr, char *buf) |
| 2717 | { |
| 2718 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2719 | struct megasas_instance *instance = |
| 2720 | (struct megasas_instance *) shost->hostdata; |
| 2721 | return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state); |
| 2722 | } |
| 2723 | |
| 2724 | static ssize_t |
| 2725 | megasas_page_size_show(struct device *cdev, |
| 2726 | struct device_attribute *attr, char *buf) |
| 2727 | { |
| 2728 | return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1); |
| 2729 | } |
| 2730 | |
| 2731 | static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR, |
| 2732 | megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store); |
| 2733 | static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO, |
| 2734 | megasas_fw_crash_buffer_size_show, NULL); |
| 2735 | static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR, |
| 2736 | megasas_fw_crash_state_show, megasas_fw_crash_state_store); |
| 2737 | static DEVICE_ATTR(page_size, S_IRUGO, |
| 2738 | megasas_page_size_show, NULL); |
| 2739 | |
| 2740 | struct device_attribute *megaraid_host_attrs[] = { |
| 2741 | &dev_attr_fw_crash_buffer_size, |
| 2742 | &dev_attr_fw_crash_buffer, |
| 2743 | &dev_attr_fw_crash_state, |
| 2744 | &dev_attr_page_size, |
| 2745 | NULL, |
| 2746 | }; |
| 2747 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2748 | /* |
| 2749 | * Scsi host template for megaraid_sas driver |
| 2750 | */ |
| 2751 | static struct scsi_host_template megasas_template = { |
| 2752 | |
| 2753 | .module = THIS_MODULE, |
bo yang | f28cd7c | 2007-11-09 04:44:56 -0500 | [diff] [blame] | 2754 | .name = "LSI SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2755 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2756 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2757 | .slave_alloc = megasas_slave_alloc, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2758 | .queuecommand = megasas_queue_command, |
| 2759 | .eh_device_reset_handler = megasas_reset_device, |
| 2760 | .eh_bus_reset_handler = megasas_reset_bus_host, |
| 2761 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2762 | .eh_timed_out = megasas_reset_timer, |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2763 | .shost_attrs = megaraid_host_attrs, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2764 | .bios_param = megasas_bios_param, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2765 | .use_clustering = ENABLE_CLUSTERING, |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 2766 | .change_queue_depth = megasas_change_queue_depth, |
Martin K. Petersen | 54b2b50 | 2013-10-23 06:25:40 -0400 | [diff] [blame] | 2767 | .no_write_same = 1, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2768 | }; |
| 2769 | |
| 2770 | /** |
| 2771 | * megasas_complete_int_cmd - Completes an internal command |
| 2772 | * @instance: Adapter soft state |
| 2773 | * @cmd: Command to be completed |
| 2774 | * |
| 2775 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 2776 | * after it issues a command. This function wakes up that waiting routine by |
| 2777 | * calling wake_up() on the wait queue. |
| 2778 | */ |
| 2779 | static void |
| 2780 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 2781 | struct megasas_cmd *cmd) |
| 2782 | { |
| 2783 | cmd->cmd_status = cmd->frame->io.cmd_status; |
| 2784 | |
| 2785 | if (cmd->cmd_status == ENODATA) { |
| 2786 | cmd->cmd_status = 0; |
| 2787 | } |
| 2788 | wake_up(&instance->int_cmd_wait_q); |
| 2789 | } |
| 2790 | |
| 2791 | /** |
| 2792 | * megasas_complete_abort - Completes aborting a command |
| 2793 | * @instance: Adapter soft state |
| 2794 | * @cmd: Cmd that was issued to abort another cmd |
| 2795 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2796 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 2797 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2798 | * wakes up all functions waiting on the same wait queue. |
| 2799 | */ |
| 2800 | static void |
| 2801 | megasas_complete_abort(struct megasas_instance *instance, |
| 2802 | struct megasas_cmd *cmd) |
| 2803 | { |
| 2804 | if (cmd->sync_cmd) { |
| 2805 | cmd->sync_cmd = 0; |
| 2806 | cmd->cmd_status = 0; |
| 2807 | wake_up(&instance->abort_cmd_wait_q); |
| 2808 | } |
| 2809 | |
| 2810 | return; |
| 2811 | } |
| 2812 | |
| 2813 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2814 | * megasas_complete_cmd - Completes a command |
| 2815 | * @instance: Adapter soft state |
| 2816 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2817 | * @alt_status: If non-zero, use this value as status to |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2818 | * SCSI mid-layer instead of the value returned |
| 2819 | * by the FW. This should be used if caller wants |
| 2820 | * an alternate status (as in the case of aborted |
| 2821 | * commands) |
| 2822 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2823 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2824 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 2825 | u8 alt_status) |
| 2826 | { |
| 2827 | int exception = 0; |
| 2828 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2829 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2830 | struct fusion_context *fusion = instance->ctrl_context; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2831 | u32 opcode; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2832 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2833 | /* flag for the retry reset */ |
| 2834 | cmd->retry_for_fw_reset = 0; |
| 2835 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2836 | if (cmd->scmd) |
| 2837 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2838 | |
| 2839 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 2840 | case MFI_CMD_INVALID: |
| 2841 | /* Some older 1068 controller FW may keep a pended |
| 2842 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 2843 | when booting the kdump kernel. Ignore this command to |
| 2844 | prevent a kernel panic on shutdown of the kdump kernel. */ |
| 2845 | printk(KERN_WARNING "megaraid_sas: MFI_CMD_INVALID command " |
| 2846 | "completed.\n"); |
| 2847 | printk(KERN_WARNING "megaraid_sas: If you have a controller " |
| 2848 | "other than PERC5, please upgrade your firmware.\n"); |
| 2849 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2850 | case MFI_CMD_PD_SCSI_IO: |
| 2851 | case MFI_CMD_LD_SCSI_IO: |
| 2852 | |
| 2853 | /* |
| 2854 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 2855 | * issued either through an IO path or an IOCTL path. If it |
| 2856 | * was via IOCTL, we will send it to internal completion. |
| 2857 | */ |
| 2858 | if (cmd->sync_cmd) { |
| 2859 | cmd->sync_cmd = 0; |
| 2860 | megasas_complete_int_cmd(instance, cmd); |
| 2861 | break; |
| 2862 | } |
| 2863 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2864 | case MFI_CMD_LD_READ: |
| 2865 | case MFI_CMD_LD_WRITE: |
| 2866 | |
| 2867 | if (alt_status) { |
| 2868 | cmd->scmd->result = alt_status << 16; |
| 2869 | exception = 1; |
| 2870 | } |
| 2871 | |
| 2872 | if (exception) { |
| 2873 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2874 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2875 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 2876 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2877 | cmd->scmd->scsi_done(cmd->scmd); |
| 2878 | megasas_return_cmd(instance, cmd); |
| 2879 | |
| 2880 | break; |
| 2881 | } |
| 2882 | |
| 2883 | switch (hdr->cmd_status) { |
| 2884 | |
| 2885 | case MFI_STAT_OK: |
| 2886 | cmd->scmd->result = DID_OK << 16; |
| 2887 | break; |
| 2888 | |
| 2889 | case MFI_STAT_SCSI_IO_FAILED: |
| 2890 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 2891 | cmd->scmd->result = |
| 2892 | (DID_ERROR << 16) | hdr->scsi_status; |
| 2893 | break; |
| 2894 | |
| 2895 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 2896 | |
| 2897 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 2898 | |
| 2899 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 2900 | memset(cmd->scmd->sense_buffer, 0, |
| 2901 | SCSI_SENSE_BUFFERSIZE); |
| 2902 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 2903 | hdr->sense_len); |
| 2904 | |
| 2905 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 2906 | } |
| 2907 | |
| 2908 | break; |
| 2909 | |
| 2910 | case MFI_STAT_LD_OFFLINE: |
| 2911 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 2912 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 2913 | break; |
| 2914 | |
| 2915 | default: |
| 2916 | printk(KERN_DEBUG "megasas: MFI FW status %#x\n", |
| 2917 | hdr->cmd_status); |
| 2918 | cmd->scmd->result = DID_ERROR << 16; |
| 2919 | break; |
| 2920 | } |
| 2921 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2922 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2923 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 2924 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2925 | cmd->scmd->scsi_done(cmd->scmd); |
| 2926 | megasas_return_cmd(instance, cmd); |
| 2927 | |
| 2928 | break; |
| 2929 | |
| 2930 | case MFI_CMD_SMP: |
| 2931 | case MFI_CMD_STP: |
| 2932 | case MFI_CMD_DCMD: |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2933 | opcode = le32_to_cpu(cmd->frame->dcmd.opcode); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2934 | /* Check for LD map update */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2935 | if ((opcode == MR_DCMD_LD_MAP_GET_INFO) |
| 2936 | && (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 2937 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2938 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2939 | if (cmd->frame->hdr.cmd_status != 0) { |
| 2940 | if (cmd->frame->hdr.cmd_status != |
| 2941 | MFI_STAT_NOT_FOUND) |
| 2942 | printk(KERN_WARNING "megasas: map sync" |
| 2943 | "failed, status = 0x%x.\n", |
| 2944 | cmd->frame->hdr.cmd_status); |
| 2945 | else { |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2946 | megasas_return_mfi_mpt_pthr(instance, |
| 2947 | cmd, cmd->mpt_pthr_cmd_blocked); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2948 | spin_unlock_irqrestore( |
| 2949 | instance->host->host_lock, |
| 2950 | flags); |
| 2951 | break; |
| 2952 | } |
| 2953 | } else |
| 2954 | instance->map_id++; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2955 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 2956 | cmd->mpt_pthr_cmd_blocked); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 2957 | |
| 2958 | /* |
| 2959 | * Set fast path IO to ZERO. |
| 2960 | * Validate Map will set proper value. |
| 2961 | * Meanwhile all IOs will go as LD IO. |
| 2962 | */ |
| 2963 | if (MR_ValidateMapInfo(instance)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2964 | fusion->fast_path_io = 1; |
| 2965 | else |
| 2966 | fusion->fast_path_io = 0; |
| 2967 | megasas_sync_map_info(instance); |
| 2968 | spin_unlock_irqrestore(instance->host->host_lock, |
| 2969 | flags); |
| 2970 | break; |
| 2971 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2972 | if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 2973 | opcode == MR_DCMD_CTRL_EVENT_GET) { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2974 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2975 | megasas_poll_wait_aen = 0; |
| 2976 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2977 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2978 | |
| 2979 | /* |
| 2980 | * See if got an event notification |
| 2981 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2982 | if (opcode == MR_DCMD_CTRL_EVENT_WAIT) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2983 | megasas_service_aen(instance, cmd); |
| 2984 | else |
| 2985 | megasas_complete_int_cmd(instance, cmd); |
| 2986 | |
| 2987 | break; |
| 2988 | |
| 2989 | case MFI_CMD_ABORT: |
| 2990 | /* |
| 2991 | * Cmd issued to abort another cmd returned |
| 2992 | */ |
| 2993 | megasas_complete_abort(instance, cmd); |
| 2994 | break; |
| 2995 | |
| 2996 | default: |
| 2997 | printk("megasas: Unknown command completed! [0x%X]\n", |
| 2998 | hdr->cmd); |
| 2999 | break; |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3004 | * megasas_issue_pending_cmds_again - issue all pending cmds |
| 3005 | * in FW again because of the fw reset |
| 3006 | * @instance: Adapter soft state |
| 3007 | */ |
| 3008 | static inline void |
| 3009 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 3010 | { |
| 3011 | struct megasas_cmd *cmd; |
| 3012 | struct list_head clist_local; |
| 3013 | union megasas_evt_class_locale class_locale; |
| 3014 | unsigned long flags; |
| 3015 | u32 seq_num; |
| 3016 | |
| 3017 | INIT_LIST_HEAD(&clist_local); |
| 3018 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3019 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 3020 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3021 | |
| 3022 | while (!list_empty(&clist_local)) { |
| 3023 | cmd = list_entry((&clist_local)->next, |
| 3024 | struct megasas_cmd, list); |
| 3025 | list_del_init(&cmd->list); |
| 3026 | |
| 3027 | if (cmd->sync_cmd || cmd->scmd) { |
| 3028 | printk(KERN_NOTICE "megaraid_sas: command %p, %p:%d" |
| 3029 | "detected to be pending while HBA reset.\n", |
| 3030 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3031 | |
| 3032 | cmd->retry_for_fw_reset++; |
| 3033 | |
| 3034 | if (cmd->retry_for_fw_reset == 3) { |
| 3035 | printk(KERN_NOTICE "megaraid_sas: cmd %p, %p:%d" |
| 3036 | "was tried multiple times during reset." |
| 3037 | "Shutting down the HBA\n", |
| 3038 | cmd, cmd->scmd, cmd->sync_cmd); |
| 3039 | megaraid_sas_kill_hba(instance); |
| 3040 | |
| 3041 | instance->adprecovery = |
| 3042 | MEGASAS_HW_CRITICAL_ERROR; |
| 3043 | return; |
| 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | if (cmd->sync_cmd == 1) { |
| 3048 | if (cmd->scmd) { |
| 3049 | printk(KERN_NOTICE "megaraid_sas: unexpected" |
| 3050 | "cmd attached to internal command!\n"); |
| 3051 | } |
| 3052 | printk(KERN_NOTICE "megasas: %p synchronous cmd" |
| 3053 | "on the internal reset queue," |
| 3054 | "issue it again.\n", cmd); |
| 3055 | cmd->cmd_status = ENODATA; |
| 3056 | instance->instancet->fire_cmd(instance, |
| 3057 | cmd->frame_phys_addr , |
| 3058 | 0, instance->reg_set); |
| 3059 | } else if (cmd->scmd) { |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3060 | printk(KERN_NOTICE "megasas: %p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3061 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 3062 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3063 | |
| 3064 | atomic_inc(&instance->fw_outstanding); |
| 3065 | instance->instancet->fire_cmd(instance, |
| 3066 | cmd->frame_phys_addr, |
| 3067 | cmd->frame_count-1, instance->reg_set); |
| 3068 | } else { |
| 3069 | printk(KERN_NOTICE "megasas: %p unexpected cmd on the" |
| 3070 | "internal reset defer list while re-issue!!\n", |
| 3071 | cmd); |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | if (instance->aen_cmd) { |
| 3076 | printk(KERN_NOTICE "megaraid_sas: aen_cmd in def process\n"); |
| 3077 | megasas_return_cmd(instance, instance->aen_cmd); |
| 3078 | |
| 3079 | instance->aen_cmd = NULL; |
| 3080 | } |
| 3081 | |
| 3082 | /* |
| 3083 | * Initiate AEN (Asynchronous Event Notification) |
| 3084 | */ |
| 3085 | seq_num = instance->last_seq_num; |
| 3086 | class_locale.members.reserved = 0; |
| 3087 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3088 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3089 | |
| 3090 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 3091 | } |
| 3092 | |
| 3093 | /** |
| 3094 | * Move the internal reset pending commands to a deferred queue. |
| 3095 | * |
| 3096 | * We move the commands pending at internal reset time to a |
| 3097 | * pending queue. This queue would be flushed after successful |
| 3098 | * completion of the internal reset sequence. if the internal reset |
| 3099 | * did not complete in time, the kernel reset handler would flush |
| 3100 | * these commands. |
| 3101 | **/ |
| 3102 | static void |
| 3103 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 3104 | { |
| 3105 | struct megasas_cmd *cmd; |
| 3106 | int i; |
| 3107 | u32 max_cmd = instance->max_fw_cmds; |
| 3108 | u32 defer_index; |
| 3109 | unsigned long flags; |
| 3110 | |
| 3111 | defer_index = 0; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3112 | spin_lock_irqsave(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3113 | for (i = 0; i < max_cmd; i++) { |
| 3114 | cmd = instance->cmd_list[i]; |
| 3115 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
| 3116 | printk(KERN_NOTICE "megasas: moving cmd[%d]:%p:%d:%p" |
| 3117 | "on the defer queue as internal\n", |
| 3118 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 3119 | |
| 3120 | if (!list_empty(&cmd->list)) { |
| 3121 | printk(KERN_NOTICE "megaraid_sas: ERROR while" |
| 3122 | " moving this cmd:%p, %d %p, it was" |
| 3123 | "discovered on some list?\n", |
| 3124 | cmd, cmd->sync_cmd, cmd->scmd); |
| 3125 | |
| 3126 | list_del_init(&cmd->list); |
| 3127 | } |
| 3128 | defer_index++; |
| 3129 | list_add_tail(&cmd->list, |
| 3130 | &instance->internal_reset_pending_q); |
| 3131 | } |
| 3132 | } |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3133 | spin_unlock_irqrestore(&instance->mfi_pool_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | |
| 3137 | static void |
| 3138 | process_fw_state_change_wq(struct work_struct *work) |
| 3139 | { |
| 3140 | struct megasas_instance *instance = |
| 3141 | container_of(work, struct megasas_instance, work_init); |
| 3142 | u32 wait; |
| 3143 | unsigned long flags; |
| 3144 | |
| 3145 | if (instance->adprecovery != MEGASAS_ADPRESET_SM_INFAULT) { |
| 3146 | printk(KERN_NOTICE "megaraid_sas: error, recovery st %x \n", |
| 3147 | instance->adprecovery); |
| 3148 | return ; |
| 3149 | } |
| 3150 | |
| 3151 | if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) { |
| 3152 | printk(KERN_NOTICE "megaraid_sas: FW detected to be in fault" |
| 3153 | "state, restarting it...\n"); |
| 3154 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3155 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3156 | atomic_set(&instance->fw_outstanding, 0); |
| 3157 | |
| 3158 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3159 | instance->instancet->adp_reset(instance, instance->reg_set); |
| 3160 | atomic_set(&instance->fw_reset_no_pci_access, 0 ); |
| 3161 | |
| 3162 | printk(KERN_NOTICE "megaraid_sas: FW restarted successfully," |
| 3163 | "initiating next stage...\n"); |
| 3164 | |
| 3165 | printk(KERN_NOTICE "megaraid_sas: HBA recovery state machine," |
| 3166 | "state 2 starting...\n"); |
| 3167 | |
| 3168 | /*waitting for about 20 second before start the second init*/ |
| 3169 | for (wait = 0; wait < 30; wait++) { |
| 3170 | msleep(1000); |
| 3171 | } |
| 3172 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3173 | if (megasas_transition_to_ready(instance, 1)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3174 | printk(KERN_NOTICE "megaraid_sas:adapter not ready\n"); |
| 3175 | |
| 3176 | megaraid_sas_kill_hba(instance); |
| 3177 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 3178 | return ; |
| 3179 | } |
| 3180 | |
| 3181 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3182 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 3183 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 3184 | ) { |
| 3185 | *instance->consumer = *instance->producer; |
| 3186 | } else { |
| 3187 | *instance->consumer = 0; |
| 3188 | *instance->producer = 0; |
| 3189 | } |
| 3190 | |
| 3191 | megasas_issue_init_mfi(instance); |
| 3192 | |
| 3193 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3194 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
| 3195 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3196 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3197 | |
| 3198 | megasas_issue_pending_cmds_again(instance); |
| 3199 | instance->issuepend_done = 1; |
| 3200 | } |
| 3201 | return ; |
| 3202 | } |
| 3203 | |
| 3204 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3205 | * megasas_deplete_reply_queue - Processes all completed commands |
| 3206 | * @instance: Adapter soft state |
| 3207 | * @alt_status: Alternate status to be returned to |
| 3208 | * SCSI mid-layer instead of the status |
| 3209 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3210 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3211 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 3212 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3213 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 3214 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3215 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3216 | u32 mfiStatus; |
| 3217 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3218 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3219 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 3220 | instance->reg_set)) == 1) { |
| 3221 | return IRQ_HANDLED; |
| 3222 | } |
| 3223 | |
| 3224 | if ((mfiStatus = instance->instancet->clear_intr( |
| 3225 | instance->reg_set) |
| 3226 | ) == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3227 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3228 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 3229 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | instance->mfiStatus = mfiStatus; |
| 3233 | |
| 3234 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 3235 | fw_state = instance->instancet->read_fw_status_reg( |
| 3236 | instance->reg_set) & MFI_STATE_MASK; |
| 3237 | |
| 3238 | if (fw_state != MFI_STATE_FAULT) { |
| 3239 | printk(KERN_NOTICE "megaraid_sas: fw state:%x\n", |
| 3240 | fw_state); |
| 3241 | } |
| 3242 | |
| 3243 | if ((fw_state == MFI_STATE_FAULT) && |
| 3244 | (instance->disableOnlineCtrlReset == 0)) { |
| 3245 | printk(KERN_NOTICE "megaraid_sas: wait adp restart\n"); |
| 3246 | |
| 3247 | if ((instance->pdev->device == |
| 3248 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 3249 | (instance->pdev->device == |
| 3250 | PCI_DEVICE_ID_DELL_PERC5) || |
| 3251 | (instance->pdev->device == |
| 3252 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 3253 | |
| 3254 | *instance->consumer = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3255 | cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3259 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3260 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
| 3261 | instance->issuepend_done = 0; |
| 3262 | |
| 3263 | atomic_set(&instance->fw_outstanding, 0); |
| 3264 | megasas_internal_reset_defer_cmds(instance); |
| 3265 | |
| 3266 | printk(KERN_NOTICE "megasas: fwState=%x, stage:%d\n", |
| 3267 | fw_state, instance->adprecovery); |
| 3268 | |
| 3269 | schedule_work(&instance->work_init); |
| 3270 | return IRQ_HANDLED; |
| 3271 | |
| 3272 | } else { |
| 3273 | printk(KERN_NOTICE "megasas: fwstate:%x, dis_OCR=%x\n", |
| 3274 | fw_state, instance->disableOnlineCtrlReset); |
| 3275 | } |
| 3276 | } |
| 3277 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3278 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3279 | return IRQ_HANDLED; |
| 3280 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3281 | /** |
| 3282 | * megasas_isr - isr entry point |
| 3283 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3284 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3285 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3286 | struct megasas_irq_context *irq_context = devp; |
| 3287 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3288 | unsigned long flags; |
| 3289 | irqreturn_t rc; |
| 3290 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3291 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3292 | return IRQ_HANDLED; |
| 3293 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3294 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 3295 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
| 3296 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3297 | |
| 3298 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | /** |
| 3302 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3303 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3304 | * |
| 3305 | * During the initialization, FW passes can potentially be in any one of |
| 3306 | * several possible states. If the FW in operational, waiting-for-handshake |
| 3307 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 3308 | * has to wait for the ready state. |
| 3309 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3310 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3311 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3312 | { |
| 3313 | int i; |
| 3314 | u8 max_wait; |
| 3315 | u32 fw_state; |
| 3316 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3317 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3318 | |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3319 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 3320 | fw_state = abs_state & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3321 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3322 | if (fw_state != MFI_STATE_READY) |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3323 | printk(KERN_INFO "megasas: Waiting for FW to come to ready" |
| 3324 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3325 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3326 | while (fw_state != MFI_STATE_READY) { |
| 3327 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3328 | switch (fw_state) { |
| 3329 | |
| 3330 | case MFI_STATE_FAULT: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3331 | printk(KERN_DEBUG "megasas: FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 3332 | if (ocr) { |
| 3333 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 3334 | cur_state = MFI_STATE_FAULT; |
| 3335 | break; |
| 3336 | } else |
| 3337 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3338 | |
| 3339 | case MFI_STATE_WAIT_HANDSHAKE: |
| 3340 | /* |
| 3341 | * Set the CLR bit in inbound doorbell |
| 3342 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 3343 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3344 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3345 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3346 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
| 3347 | (instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3348 | PCI_DEVICE_ID_LSI_FUSION) || |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 3349 | (instance->pdev->device == |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3350 | PCI_DEVICE_ID_LSI_PLASMA) || |
| 3351 | (instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3352 | PCI_DEVICE_ID_LSI_INVADER) || |
| 3353 | (instance->pdev->device == |
| 3354 | PCI_DEVICE_ID_LSI_FURY)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3355 | writel( |
| 3356 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3357 | &instance->reg_set->doorbell); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3358 | } else { |
| 3359 | writel( |
| 3360 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 3361 | &instance->reg_set->inbound_doorbell); |
| 3362 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3363 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3364 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3365 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 3366 | break; |
| 3367 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3368 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3369 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3370 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3371 | (instance->pdev->device == |
| 3372 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
| 3373 | (instance->pdev->device == |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 3374 | PCI_DEVICE_ID_LSI_FUSION) || |
| 3375 | (instance->pdev->device == |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3376 | PCI_DEVICE_ID_LSI_PLASMA) || |
| 3377 | (instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3378 | PCI_DEVICE_ID_LSI_INVADER) || |
| 3379 | (instance->pdev->device == |
| 3380 | PCI_DEVICE_ID_LSI_FURY)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3381 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3382 | &instance->reg_set->doorbell); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3383 | } else |
| 3384 | writel(MFI_INIT_HOTPLUG, |
| 3385 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3386 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3387 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3388 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 3389 | break; |
| 3390 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3391 | case MFI_STATE_OPERATIONAL: |
| 3392 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3393 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3394 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3395 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3396 | if ((instance->pdev->device == |
| 3397 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 3398 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3399 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
| 3400 | (instance->pdev->device |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 3401 | == PCI_DEVICE_ID_LSI_FUSION) || |
| 3402 | (instance->pdev->device |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3403 | == PCI_DEVICE_ID_LSI_PLASMA) || |
| 3404 | (instance->pdev->device |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3405 | == PCI_DEVICE_ID_LSI_INVADER) || |
| 3406 | (instance->pdev->device |
| 3407 | == PCI_DEVICE_ID_LSI_FURY)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3408 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3409 | &instance->reg_set->doorbell); |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 3410 | if ((instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3411 | PCI_DEVICE_ID_LSI_FUSION) || |
| 3412 | (instance->pdev->device == |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3413 | PCI_DEVICE_ID_LSI_PLASMA) || |
| 3414 | (instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3415 | PCI_DEVICE_ID_LSI_INVADER) || |
| 3416 | (instance->pdev->device == |
| 3417 | PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3418 | for (i = 0; i < (10 * 1000); i += 20) { |
| 3419 | if (readl( |
| 3420 | &instance-> |
| 3421 | reg_set-> |
| 3422 | doorbell) & 1) |
| 3423 | msleep(20); |
| 3424 | else |
| 3425 | break; |
| 3426 | } |
| 3427 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 3428 | } else |
| 3429 | writel(MFI_RESET_FLAGS, |
| 3430 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3431 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3432 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3433 | cur_state = MFI_STATE_OPERATIONAL; |
| 3434 | break; |
| 3435 | |
| 3436 | case MFI_STATE_UNDEFINED: |
| 3437 | /* |
| 3438 | * This state should not last for more than 2 seconds |
| 3439 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3440 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3441 | cur_state = MFI_STATE_UNDEFINED; |
| 3442 | break; |
| 3443 | |
| 3444 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3445 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3446 | cur_state = MFI_STATE_BB_INIT; |
| 3447 | break; |
| 3448 | |
| 3449 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3450 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3451 | cur_state = MFI_STATE_FW_INIT; |
| 3452 | break; |
| 3453 | |
| 3454 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3455 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3456 | cur_state = MFI_STATE_FW_INIT_2; |
| 3457 | break; |
| 3458 | |
| 3459 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3460 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3461 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 3462 | break; |
| 3463 | |
| 3464 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3465 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3466 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 3467 | break; |
| 3468 | |
| 3469 | default: |
| 3470 | printk(KERN_DEBUG "megasas: Unknown state 0x%x\n", |
| 3471 | fw_state); |
| 3472 | return -ENODEV; |
| 3473 | } |
| 3474 | |
| 3475 | /* |
| 3476 | * The cur_state should not last for more than max_wait secs |
| 3477 | */ |
| 3478 | for (i = 0; i < (max_wait * 1000); i++) { |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3479 | curr_abs_state = instance->instancet-> |
| 3480 | read_fw_status_reg(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3481 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3482 | if (abs_state == curr_abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3483 | msleep(1); |
| 3484 | } else |
| 3485 | break; |
| 3486 | } |
| 3487 | |
| 3488 | /* |
| 3489 | * Return error if fw_state hasn't changed after max_wait |
| 3490 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 3491 | if (curr_abs_state == abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3492 | printk(KERN_DEBUG "FW state [%d] hasn't changed " |
| 3493 | "in %d secs\n", fw_state, max_wait); |
| 3494 | return -ENODEV; |
| 3495 | } |
Tomas Henzl | bc6ac5e | 2014-04-01 13:59:50 +0200 | [diff] [blame] | 3496 | |
| 3497 | abs_state = curr_abs_state; |
| 3498 | fw_state = curr_abs_state & MFI_STATE_MASK; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3499 | } |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3500 | printk(KERN_INFO "megasas: FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3501 | |
| 3502 | return 0; |
| 3503 | } |
| 3504 | |
| 3505 | /** |
| 3506 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 3507 | * @instance: Adapter soft state |
| 3508 | */ |
| 3509 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 3510 | { |
| 3511 | int i; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3512 | u32 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3513 | struct megasas_cmd *cmd; |
| 3514 | |
| 3515 | if (!instance->frame_dma_pool) |
| 3516 | return; |
| 3517 | |
| 3518 | /* |
| 3519 | * Return all frames to pool |
| 3520 | */ |
| 3521 | for (i = 0; i < max_cmd; i++) { |
| 3522 | |
| 3523 | cmd = instance->cmd_list[i]; |
| 3524 | |
| 3525 | if (cmd->frame) |
| 3526 | pci_pool_free(instance->frame_dma_pool, cmd->frame, |
| 3527 | cmd->frame_phys_addr); |
| 3528 | |
| 3529 | if (cmd->sense) |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 3530 | pci_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3531 | cmd->sense_phys_addr); |
| 3532 | } |
| 3533 | |
| 3534 | /* |
| 3535 | * Now destroy the pool itself |
| 3536 | */ |
| 3537 | pci_pool_destroy(instance->frame_dma_pool); |
| 3538 | pci_pool_destroy(instance->sense_dma_pool); |
| 3539 | |
| 3540 | instance->frame_dma_pool = NULL; |
| 3541 | instance->sense_dma_pool = NULL; |
| 3542 | } |
| 3543 | |
| 3544 | /** |
| 3545 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 3546 | * @instance: Adapter soft state |
| 3547 | * |
| 3548 | * Each command packet has an embedded DMA memory buffer that is used for |
| 3549 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 3550 | * function creates those DMA memory buffers for each command packet by using |
| 3551 | * PCI pool facility. |
| 3552 | */ |
| 3553 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 3554 | { |
| 3555 | int i; |
| 3556 | u32 max_cmd; |
| 3557 | u32 sge_sz; |
| 3558 | u32 sgl_sz; |
| 3559 | u32 total_sz; |
| 3560 | u32 frame_count; |
| 3561 | struct megasas_cmd *cmd; |
| 3562 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3563 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3564 | |
| 3565 | /* |
| 3566 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 3567 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 3568 | */ |
| 3569 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 3570 | sizeof(struct megasas_sge32); |
| 3571 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3572 | if (instance->flag_ieee) { |
| 3573 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 3574 | } |
| 3575 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3576 | /* |
| 3577 | * Calculated the number of 64byte frames required for SGL |
| 3578 | */ |
| 3579 | sgl_sz = sge_sz * instance->max_num_sge; |
| 3580 | frame_count = (sgl_sz + MEGAMFI_FRAME_SIZE - 1) / MEGAMFI_FRAME_SIZE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3581 | frame_count = 15; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3582 | |
| 3583 | /* |
| 3584 | * We need one extra frame for the MFI command |
| 3585 | */ |
| 3586 | frame_count++; |
| 3587 | |
| 3588 | total_sz = MEGAMFI_FRAME_SIZE * frame_count; |
| 3589 | /* |
| 3590 | * Use DMA pool facility provided by PCI layer |
| 3591 | */ |
| 3592 | instance->frame_dma_pool = pci_pool_create("megasas frame pool", |
| 3593 | instance->pdev, total_sz, 64, |
| 3594 | 0); |
| 3595 | |
| 3596 | if (!instance->frame_dma_pool) { |
| 3597 | printk(KERN_DEBUG "megasas: failed to setup frame pool\n"); |
| 3598 | return -ENOMEM; |
| 3599 | } |
| 3600 | |
| 3601 | instance->sense_dma_pool = pci_pool_create("megasas sense pool", |
| 3602 | instance->pdev, 128, 4, 0); |
| 3603 | |
| 3604 | if (!instance->sense_dma_pool) { |
| 3605 | printk(KERN_DEBUG "megasas: failed to setup sense pool\n"); |
| 3606 | |
| 3607 | pci_pool_destroy(instance->frame_dma_pool); |
| 3608 | instance->frame_dma_pool = NULL; |
| 3609 | |
| 3610 | return -ENOMEM; |
| 3611 | } |
| 3612 | |
| 3613 | /* |
| 3614 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 3615 | * By making cmd->index as the context instead of the &cmd, we can |
| 3616 | * always use 32bit context regardless of the architecture |
| 3617 | */ |
| 3618 | for (i = 0; i < max_cmd; i++) { |
| 3619 | |
| 3620 | cmd = instance->cmd_list[i]; |
| 3621 | |
| 3622 | cmd->frame = pci_pool_alloc(instance->frame_dma_pool, |
| 3623 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 3624 | |
| 3625 | cmd->sense = pci_pool_alloc(instance->sense_dma_pool, |
| 3626 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 3627 | |
| 3628 | /* |
| 3629 | * megasas_teardown_frame_pool() takes care of freeing |
| 3630 | * whatever has been allocated |
| 3631 | */ |
| 3632 | if (!cmd->frame || !cmd->sense) { |
| 3633 | printk(KERN_DEBUG "megasas: pci_pool_alloc failed \n"); |
| 3634 | megasas_teardown_frame_pool(instance); |
| 3635 | return -ENOMEM; |
| 3636 | } |
| 3637 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 3638 | memset(cmd->frame, 0, total_sz); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3639 | cmd->frame->io.context = cpu_to_le32(cmd->index); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 3640 | cmd->frame->io.pad_0 = 0; |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3641 | if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) && |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3642 | (instance->pdev->device != PCI_DEVICE_ID_LSI_PLASMA) && |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3643 | (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) && |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3644 | (instance->pdev->device != PCI_DEVICE_ID_LSI_FURY) && |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 3645 | (reset_devices)) |
| 3646 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | return 0; |
| 3650 | } |
| 3651 | |
| 3652 | /** |
| 3653 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 3654 | * @instance: Adapter soft state |
| 3655 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3656 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3657 | { |
| 3658 | int i; |
| 3659 | /* First free the MFI frame pool */ |
| 3660 | megasas_teardown_frame_pool(instance); |
| 3661 | |
| 3662 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3663 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 3664 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3665 | kfree(instance->cmd_list[i]); |
| 3666 | |
| 3667 | /* Free the cmd_list buffer itself */ |
| 3668 | kfree(instance->cmd_list); |
| 3669 | instance->cmd_list = NULL; |
| 3670 | |
| 3671 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 3672 | } |
| 3673 | |
| 3674 | /** |
| 3675 | * megasas_alloc_cmds - Allocates the command packets |
| 3676 | * @instance: Adapter soft state |
| 3677 | * |
| 3678 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 3679 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 3680 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 3681 | * the FW. |
| 3682 | * |
| 3683 | * Each frame has a 32-bit field called context (tag). This context is used |
| 3684 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 3685 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 3686 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 3687 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 3688 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 3689 | * This array is used only to look up the megasas_cmd given the context. The |
| 3690 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 3691 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3692 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3693 | { |
| 3694 | int i; |
| 3695 | int j; |
| 3696 | u32 max_cmd; |
| 3697 | struct megasas_cmd *cmd; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3698 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3699 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3700 | fusion = instance->ctrl_context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3701 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3702 | |
| 3703 | /* |
| 3704 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 3705 | * Allocate the dynamic array first and then allocate individual |
| 3706 | * commands. |
| 3707 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 3708 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3709 | |
| 3710 | if (!instance->cmd_list) { |
| 3711 | printk(KERN_DEBUG "megasas: out of memory\n"); |
| 3712 | return -ENOMEM; |
| 3713 | } |
| 3714 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3715 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3716 | |
| 3717 | for (i = 0; i < max_cmd; i++) { |
| 3718 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 3719 | GFP_KERNEL); |
| 3720 | |
| 3721 | if (!instance->cmd_list[i]) { |
| 3722 | |
| 3723 | for (j = 0; j < i; j++) |
| 3724 | kfree(instance->cmd_list[j]); |
| 3725 | |
| 3726 | kfree(instance->cmd_list); |
| 3727 | instance->cmd_list = NULL; |
| 3728 | |
| 3729 | return -ENOMEM; |
| 3730 | } |
| 3731 | } |
| 3732 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3733 | for (i = 0; i < max_cmd; i++) { |
| 3734 | cmd = instance->cmd_list[i]; |
| 3735 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 3736 | cmd->index = i; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3737 | atomic_set(&cmd->mfi_mpt_pthr, MFI_LIST_ADDED); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3738 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3739 | cmd->instance = instance; |
| 3740 | |
| 3741 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 3742 | } |
| 3743 | |
| 3744 | /* |
| 3745 | * Create a frame pool and assign one frame to each cmd |
| 3746 | */ |
| 3747 | if (megasas_create_frame_pool(instance)) { |
| 3748 | printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n"); |
| 3749 | megasas_free_cmds(instance); |
| 3750 | } |
| 3751 | |
| 3752 | return 0; |
| 3753 | } |
| 3754 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3755 | /* |
| 3756 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 3757 | * @instance: Adapter soft state |
| 3758 | * @pd_list: pd_list structure |
| 3759 | * |
| 3760 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 3761 | * list structure. This information is mainly used to find out SYSTEM |
| 3762 | * supported by the FW. |
| 3763 | */ |
| 3764 | static int |
| 3765 | megasas_get_pd_list(struct megasas_instance *instance) |
| 3766 | { |
| 3767 | int ret = 0, pd_index = 0; |
| 3768 | struct megasas_cmd *cmd; |
| 3769 | struct megasas_dcmd_frame *dcmd; |
| 3770 | struct MR_PD_LIST *ci; |
| 3771 | struct MR_PD_ADDRESS *pd_addr; |
| 3772 | dma_addr_t ci_h = 0; |
| 3773 | |
| 3774 | cmd = megasas_get_cmd(instance); |
| 3775 | |
| 3776 | if (!cmd) { |
| 3777 | printk(KERN_DEBUG "megasas (get_pd_list): Failed to get cmd\n"); |
| 3778 | return -ENOMEM; |
| 3779 | } |
| 3780 | |
| 3781 | dcmd = &cmd->frame->dcmd; |
| 3782 | |
| 3783 | ci = pci_alloc_consistent(instance->pdev, |
| 3784 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h); |
| 3785 | |
| 3786 | if (!ci) { |
| 3787 | printk(KERN_DEBUG "Failed to alloc mem for pd_list\n"); |
| 3788 | megasas_return_cmd(instance, cmd); |
| 3789 | return -ENOMEM; |
| 3790 | } |
| 3791 | |
| 3792 | memset(ci, 0, sizeof(*ci)); |
| 3793 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3794 | |
| 3795 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 3796 | dcmd->mbox.b[1] = 0; |
| 3797 | dcmd->cmd = MFI_CMD_DCMD; |
| 3798 | dcmd->cmd_status = 0xFF; |
| 3799 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3800 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3801 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 3802 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3803 | dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
| 3804 | dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY); |
| 3805 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 3806 | dcmd->sgl.sge32[0].length = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3807 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3808 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 3809 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 3810 | MEGASAS_BLOCKED_CMD_TIMEOUT); |
| 3811 | else |
| 3812 | ret = megasas_issue_polled(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3813 | |
| 3814 | /* |
| 3815 | * the following function will get the instance PD LIST. |
| 3816 | */ |
| 3817 | |
| 3818 | pd_addr = ci->addr; |
| 3819 | |
| 3820 | if ( ret == 0 && |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3821 | (le32_to_cpu(ci->count) < |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3822 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) { |
| 3823 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 3824 | memset(instance->local_pd_list, 0, |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3825 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
| 3826 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3827 | for (pd_index = 0; pd_index < le32_to_cpu(ci->count); pd_index++) { |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3828 | |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 3829 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3830 | le16_to_cpu(pd_addr->deviceId); |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 3831 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType = |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3832 | pd_addr->scsiDevType; |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 3833 | instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState = |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3834 | MR_PD_STATE_SYSTEM; |
| 3835 | pd_addr++; |
| 3836 | } |
Sumit.Saxena@lsi.com | 999ece0 | 2013-10-18 12:50:37 +0530 | [diff] [blame] | 3837 | memcpy(instance->pd_list, instance->local_pd_list, |
| 3838 | sizeof(instance->pd_list)); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | pci_free_consistent(instance->pdev, |
| 3842 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 3843 | ci, ci_h); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3844 | |
| 3845 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 3846 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 3847 | cmd->mpt_pthr_cmd_blocked); |
| 3848 | else |
| 3849 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3850 | |
| 3851 | return ret; |
| 3852 | } |
| 3853 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3854 | /* |
| 3855 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 3856 | * @instance: Adapter soft state |
| 3857 | * @ld_list: ld_list structure |
| 3858 | * |
| 3859 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 3860 | * list structure. This information is mainly used to find out SYSTEM |
| 3861 | * supported by the FW. |
| 3862 | */ |
| 3863 | static int |
| 3864 | megasas_get_ld_list(struct megasas_instance *instance) |
| 3865 | { |
| 3866 | int ret = 0, ld_index = 0, ids = 0; |
| 3867 | struct megasas_cmd *cmd; |
| 3868 | struct megasas_dcmd_frame *dcmd; |
| 3869 | struct MR_LD_LIST *ci; |
| 3870 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3871 | u32 ld_count; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3872 | |
| 3873 | cmd = megasas_get_cmd(instance); |
| 3874 | |
| 3875 | if (!cmd) { |
| 3876 | printk(KERN_DEBUG "megasas_get_ld_list: Failed to get cmd\n"); |
| 3877 | return -ENOMEM; |
| 3878 | } |
| 3879 | |
| 3880 | dcmd = &cmd->frame->dcmd; |
| 3881 | |
| 3882 | ci = pci_alloc_consistent(instance->pdev, |
| 3883 | sizeof(struct MR_LD_LIST), |
| 3884 | &ci_h); |
| 3885 | |
| 3886 | if (!ci) { |
| 3887 | printk(KERN_DEBUG "Failed to alloc mem in get_ld_list\n"); |
| 3888 | megasas_return_cmd(instance, cmd); |
| 3889 | return -ENOMEM; |
| 3890 | } |
| 3891 | |
| 3892 | memset(ci, 0, sizeof(*ci)); |
| 3893 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3894 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 3895 | if (instance->supportmax256vd) |
| 3896 | dcmd->mbox.b[0] = 1; |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3897 | dcmd->cmd = MFI_CMD_DCMD; |
| 3898 | dcmd->cmd_status = 0xFF; |
| 3899 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3900 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3901 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3902 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
| 3903 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST); |
| 3904 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 3905 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_LIST)); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3906 | dcmd->pad_0 = 0; |
| 3907 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3908 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 3909 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 3910 | MEGASAS_BLOCKED_CMD_TIMEOUT); |
| 3911 | else |
| 3912 | ret = megasas_issue_polled(instance, cmd); |
| 3913 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3914 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3915 | ld_count = le32_to_cpu(ci->ldCount); |
| 3916 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3917 | /* the following function will get the instance PD LIST */ |
| 3918 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 3919 | if ((ret == 0) && (ld_count <= instance->fw_supported_vd_count)) { |
| 3920 | memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3921 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3922 | for (ld_index = 0; ld_index < ld_count; ld_index++) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3923 | if (ci->ldList[ld_index].state != 0) { |
| 3924 | ids = ci->ldList[ld_index].ref.targetId; |
| 3925 | instance->ld_ids[ids] = |
| 3926 | ci->ldList[ld_index].ref.targetId; |
| 3927 | } |
| 3928 | } |
| 3929 | } |
| 3930 | |
| 3931 | pci_free_consistent(instance->pdev, |
| 3932 | sizeof(struct MR_LD_LIST), |
| 3933 | ci, |
| 3934 | ci_h); |
| 3935 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3936 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 3937 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 3938 | cmd->mpt_pthr_cmd_blocked); |
| 3939 | else |
| 3940 | megasas_return_cmd(instance, cmd); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3941 | return ret; |
| 3942 | } |
| 3943 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3944 | /** |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 3945 | * megasas_ld_list_query - Returns FW's ld_list structure |
| 3946 | * @instance: Adapter soft state |
| 3947 | * @ld_list: ld_list structure |
| 3948 | * |
| 3949 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 3950 | * list structure. This information is mainly used to find out SYSTEM |
| 3951 | * supported by the FW. |
| 3952 | */ |
| 3953 | static int |
| 3954 | megasas_ld_list_query(struct megasas_instance *instance, u8 query_type) |
| 3955 | { |
| 3956 | int ret = 0, ld_index = 0, ids = 0; |
| 3957 | struct megasas_cmd *cmd; |
| 3958 | struct megasas_dcmd_frame *dcmd; |
| 3959 | struct MR_LD_TARGETID_LIST *ci; |
| 3960 | dma_addr_t ci_h = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3961 | u32 tgtid_count; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 3962 | |
| 3963 | cmd = megasas_get_cmd(instance); |
| 3964 | |
| 3965 | if (!cmd) { |
| 3966 | printk(KERN_WARNING |
| 3967 | "megasas:(megasas_ld_list_query): Failed to get cmd\n"); |
| 3968 | return -ENOMEM; |
| 3969 | } |
| 3970 | |
| 3971 | dcmd = &cmd->frame->dcmd; |
| 3972 | |
| 3973 | ci = pci_alloc_consistent(instance->pdev, |
| 3974 | sizeof(struct MR_LD_TARGETID_LIST), &ci_h); |
| 3975 | |
| 3976 | if (!ci) { |
| 3977 | printk(KERN_WARNING |
| 3978 | "megasas: Failed to alloc mem for ld_list_query\n"); |
| 3979 | megasas_return_cmd(instance, cmd); |
| 3980 | return -ENOMEM; |
| 3981 | } |
| 3982 | |
| 3983 | memset(ci, 0, sizeof(*ci)); |
| 3984 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3985 | |
| 3986 | dcmd->mbox.b[0] = query_type; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 3987 | if (instance->supportmax256vd) |
| 3988 | dcmd->mbox.b[2] = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 3989 | |
| 3990 | dcmd->cmd = MFI_CMD_DCMD; |
| 3991 | dcmd->cmd_status = 0xFF; |
| 3992 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3993 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 3994 | dcmd->timeout = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3995 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
| 3996 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY); |
| 3997 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 3998 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST)); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 3999 | dcmd->pad_0 = 0; |
| 4000 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4001 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4002 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4003 | MEGASAS_BLOCKED_CMD_TIMEOUT); |
| 4004 | else |
| 4005 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4006 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4007 | tgtid_count = le32_to_cpu(ci->count); |
| 4008 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4009 | if ((ret == 0) && (tgtid_count <= (instance->fw_supported_vd_count))) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4010 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4011 | for (ld_index = 0; ld_index < tgtid_count; ld_index++) { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4012 | ids = ci->targetId[ld_index]; |
| 4013 | instance->ld_ids[ids] = ci->targetId[ld_index]; |
| 4014 | } |
| 4015 | |
| 4016 | } |
| 4017 | |
| 4018 | pci_free_consistent(instance->pdev, sizeof(struct MR_LD_TARGETID_LIST), |
| 4019 | ci, ci_h); |
| 4020 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4021 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 4022 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 4023 | cmd->mpt_pthr_cmd_blocked); |
| 4024 | else |
| 4025 | megasas_return_cmd(instance, cmd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4026 | |
| 4027 | return ret; |
| 4028 | } |
| 4029 | |
| 4030 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4031 | * megasas_get_controller_info - Returns FW's controller structure |
| 4032 | * @instance: Adapter soft state |
| 4033 | * @ctrl_info: Controller information structure |
| 4034 | * |
| 4035 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 4036 | * This information is mainly used to find out the maximum IO transfer per |
| 4037 | * command supported by the FW. |
| 4038 | */ |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4039 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4040 | megasas_get_ctrl_info(struct megasas_instance *instance, |
| 4041 | struct megasas_ctrl_info *ctrl_info) |
| 4042 | { |
| 4043 | int ret = 0; |
| 4044 | struct megasas_cmd *cmd; |
| 4045 | struct megasas_dcmd_frame *dcmd; |
| 4046 | struct megasas_ctrl_info *ci; |
| 4047 | dma_addr_t ci_h = 0; |
| 4048 | |
| 4049 | cmd = megasas_get_cmd(instance); |
| 4050 | |
| 4051 | if (!cmd) { |
| 4052 | printk(KERN_DEBUG "megasas: Failed to get a free cmd\n"); |
| 4053 | return -ENOMEM; |
| 4054 | } |
| 4055 | |
| 4056 | dcmd = &cmd->frame->dcmd; |
| 4057 | |
| 4058 | ci = pci_alloc_consistent(instance->pdev, |
| 4059 | sizeof(struct megasas_ctrl_info), &ci_h); |
| 4060 | |
| 4061 | if (!ci) { |
| 4062 | printk(KERN_DEBUG "Failed to alloc mem for ctrl info\n"); |
| 4063 | megasas_return_cmd(instance, cmd); |
| 4064 | return -ENOMEM; |
| 4065 | } |
| 4066 | |
| 4067 | memset(ci, 0, sizeof(*ci)); |
| 4068 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4069 | |
| 4070 | dcmd->cmd = MFI_CMD_DCMD; |
| 4071 | dcmd->cmd_status = 0xFF; |
| 4072 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4073 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4074 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4075 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4076 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
| 4077 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO); |
| 4078 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 4079 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_ctrl_info)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4080 | dcmd->mbox.b[0] = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4081 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4082 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4083 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4084 | MEGASAS_BLOCKED_CMD_TIMEOUT); |
| 4085 | else |
| 4086 | ret = megasas_issue_polled(instance, cmd); |
| 4087 | |
| 4088 | if (!ret) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4089 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4090 | |
| 4091 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), |
| 4092 | ci, ci_h); |
| 4093 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4094 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 4095 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 4096 | cmd->mpt_pthr_cmd_blocked); |
| 4097 | else |
| 4098 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4099 | return ret; |
| 4100 | } |
| 4101 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4102 | /* |
| 4103 | * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer |
| 4104 | * to firmware |
| 4105 | * |
| 4106 | * @instance: Adapter soft state |
| 4107 | * @crash_buf_state - tell FW to turn ON/OFF crash dump feature |
| 4108 | MR_CRASH_BUF_TURN_OFF = 0 |
| 4109 | MR_CRASH_BUF_TURN_ON = 1 |
| 4110 | * @return 0 on success non-zero on failure. |
| 4111 | * Issues an internal command (DCMD) to set parameters for crash dump feature. |
| 4112 | * Driver will send address of crash dump DMA buffer and set mbox to tell FW |
| 4113 | * that driver supports crash dump feature. This DCMD will be sent only if |
| 4114 | * crash dump feature is supported by the FW. |
| 4115 | * |
| 4116 | */ |
| 4117 | int megasas_set_crash_dump_params(struct megasas_instance *instance, |
| 4118 | u8 crash_buf_state) |
| 4119 | { |
| 4120 | int ret = 0; |
| 4121 | struct megasas_cmd *cmd; |
| 4122 | struct megasas_dcmd_frame *dcmd; |
| 4123 | |
| 4124 | cmd = megasas_get_cmd(instance); |
| 4125 | |
| 4126 | if (!cmd) { |
| 4127 | dev_err(&instance->pdev->dev, "Failed to get a free cmd\n"); |
| 4128 | return -ENOMEM; |
| 4129 | } |
| 4130 | |
| 4131 | |
| 4132 | dcmd = &cmd->frame->dcmd; |
| 4133 | |
| 4134 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4135 | dcmd->mbox.b[0] = crash_buf_state; |
| 4136 | dcmd->cmd = MFI_CMD_DCMD; |
| 4137 | dcmd->cmd_status = 0xFF; |
| 4138 | dcmd->sge_count = 1; |
| 4139 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
| 4140 | dcmd->timeout = 0; |
| 4141 | dcmd->pad_0 = 0; |
| 4142 | dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4143 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS); |
| 4144 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->crash_dump_h); |
| 4145 | dcmd->sgl.sge32[0].length = cpu_to_le32(CRASH_DMA_BUF_SIZE); |
| 4146 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4147 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 4148 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 4149 | MEGASAS_BLOCKED_CMD_TIMEOUT); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4150 | else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4151 | ret = megasas_issue_polled(instance, cmd); |
| 4152 | |
| 4153 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 4154 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 4155 | cmd->mpt_pthr_cmd_blocked); |
| 4156 | else |
| 4157 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4158 | return ret; |
| 4159 | } |
| 4160 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4161 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4162 | * megasas_issue_init_mfi - Initializes the FW |
| 4163 | * @instance: Adapter soft state |
| 4164 | * |
| 4165 | * Issues the INIT MFI cmd |
| 4166 | */ |
| 4167 | static int |
| 4168 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 4169 | { |
| 4170 | u32 context; |
| 4171 | |
| 4172 | struct megasas_cmd *cmd; |
| 4173 | |
| 4174 | struct megasas_init_frame *init_frame; |
| 4175 | struct megasas_init_queue_info *initq_info; |
| 4176 | dma_addr_t init_frame_h; |
| 4177 | dma_addr_t initq_info_h; |
| 4178 | |
| 4179 | /* |
| 4180 | * Prepare a init frame. Note the init frame points to queue info |
| 4181 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 4182 | * this frame - since we don't need any SGL - we use SGL's space as |
| 4183 | * queue info structure |
| 4184 | * |
| 4185 | * We will not get a NULL command below. We just created the pool. |
| 4186 | */ |
| 4187 | cmd = megasas_get_cmd(instance); |
| 4188 | |
| 4189 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 4190 | initq_info = (struct megasas_init_queue_info *) |
| 4191 | ((unsigned long)init_frame + 64); |
| 4192 | |
| 4193 | init_frame_h = cmd->frame_phys_addr; |
| 4194 | initq_info_h = init_frame_h + 64; |
| 4195 | |
| 4196 | context = init_frame->context; |
| 4197 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 4198 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 4199 | init_frame->context = context; |
| 4200 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4201 | initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1); |
| 4202 | 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] | 4203 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4204 | initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h); |
| 4205 | 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] | 4206 | |
| 4207 | init_frame->cmd = MFI_CMD_INIT; |
| 4208 | init_frame->cmd_status = 0xFF; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4209 | init_frame->queue_info_new_phys_addr_lo = |
| 4210 | cpu_to_le32(lower_32_bits(initq_info_h)); |
| 4211 | init_frame->queue_info_new_phys_addr_hi = |
| 4212 | cpu_to_le32(upper_32_bits(initq_info_h)); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4213 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4214 | 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] | 4215 | |
| 4216 | /* |
| 4217 | * disable the intr before firing the init frame to FW |
| 4218 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4219 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4220 | |
| 4221 | /* |
| 4222 | * Issue the init frame in polled mode |
| 4223 | */ |
| 4224 | |
| 4225 | if (megasas_issue_polled(instance, cmd)) { |
| 4226 | printk(KERN_ERR "megasas: Failed to init firmware\n"); |
| 4227 | megasas_return_cmd(instance, cmd); |
| 4228 | goto fail_fw_init; |
| 4229 | } |
| 4230 | |
| 4231 | megasas_return_cmd(instance, cmd); |
| 4232 | |
| 4233 | return 0; |
| 4234 | |
| 4235 | fail_fw_init: |
| 4236 | return -EINVAL; |
| 4237 | } |
| 4238 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4239 | static u32 |
| 4240 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4241 | { |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4242 | struct megasas_register_set __iomem *reg_set; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4243 | u32 context_sz; |
| 4244 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4245 | |
| 4246 | reg_set = instance->reg_set; |
| 4247 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4248 | /* |
| 4249 | * Get various operational parameters from status register |
| 4250 | */ |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4251 | instance->max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 4252 | /* |
| 4253 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 4254 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 4255 | * does not exceed max cmds that the FW can support |
| 4256 | */ |
| 4257 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4258 | instance->max_mfi_cmds = instance->max_fw_cmds; |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 4259 | instance->max_num_sge = (instance->instancet->read_fw_status_reg(reg_set) & 0xFF0000) >> |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 4260 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4261 | /* |
| 4262 | * Create a pool of commands |
| 4263 | */ |
| 4264 | if (megasas_alloc_cmds(instance)) |
| 4265 | goto fail_alloc_cmds; |
| 4266 | |
| 4267 | /* |
| 4268 | * Allocate memory for reply queue. Length of reply queue should |
| 4269 | * be _one_ more than the maximum commands handled by the firmware. |
| 4270 | * |
| 4271 | * Note: When FW completes commands, it places corresponding contex |
| 4272 | * values in this circular reply queue. This circular queue is a fairly |
| 4273 | * typical producer-consumer queue. FW is the producer (of completed |
| 4274 | * commands) and the driver is the consumer. |
| 4275 | */ |
| 4276 | context_sz = sizeof(u32); |
| 4277 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 4278 | |
| 4279 | instance->reply_queue = pci_alloc_consistent(instance->pdev, |
| 4280 | reply_q_sz, |
| 4281 | &instance->reply_queue_h); |
| 4282 | |
| 4283 | if (!instance->reply_queue) { |
| 4284 | printk(KERN_DEBUG "megasas: Out of DMA mem for reply queue\n"); |
| 4285 | goto fail_reply_queue; |
| 4286 | } |
| 4287 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4288 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4289 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4290 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4291 | if (megasas_get_ctrl_info(instance, instance->ctrl_info)) { |
| 4292 | dev_err(&instance->pdev->dev, "(%d): Could get controller info " |
| 4293 | "Fail from %s %d\n", instance->unique_id, |
| 4294 | __func__, __LINE__); |
| 4295 | goto fail_fw_init; |
| 4296 | } |
| 4297 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4298 | instance->fw_support_ieee = 0; |
| 4299 | instance->fw_support_ieee = |
| 4300 | (instance->instancet->read_fw_status_reg(reg_set) & |
| 4301 | 0x04000000); |
| 4302 | |
| 4303 | printk(KERN_NOTICE "megasas_init_mfi: fw_support_ieee=%d", |
| 4304 | instance->fw_support_ieee); |
| 4305 | |
| 4306 | if (instance->fw_support_ieee) |
| 4307 | instance->flag_ieee = 1; |
| 4308 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4309 | return 0; |
| 4310 | |
| 4311 | fail_fw_init: |
| 4312 | |
| 4313 | pci_free_consistent(instance->pdev, reply_q_sz, |
| 4314 | instance->reply_queue, instance->reply_queue_h); |
| 4315 | fail_reply_queue: |
| 4316 | megasas_free_cmds(instance); |
| 4317 | |
| 4318 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4319 | return 1; |
| 4320 | } |
| 4321 | |
| 4322 | /** |
| 4323 | * megasas_init_fw - Initializes the FW |
| 4324 | * @instance: Adapter soft state |
| 4325 | * |
| 4326 | * This is the main function for initializing firmware |
| 4327 | */ |
| 4328 | |
| 4329 | static int megasas_init_fw(struct megasas_instance *instance) |
| 4330 | { |
| 4331 | u32 max_sectors_1; |
| 4332 | u32 max_sectors_2; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4333 | u32 tmp_sectors, msix_enable, scratch_pad_2; |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 4334 | resource_size_t base_addr; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4335 | struct megasas_register_set __iomem *reg_set; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4336 | struct megasas_ctrl_info *ctrl_info = NULL; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4337 | unsigned long bar_list; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4338 | int i, loop, fw_msix_count = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4339 | struct IOV_111 *iovPtr; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4340 | |
| 4341 | /* Find first memory bar */ |
| 4342 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
| 4343 | instance->bar = find_first_bit(&bar_list, sizeof(unsigned long)); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4344 | if (pci_request_selected_regions(instance->pdev, instance->bar, |
| 4345 | "megasas: LSI")) { |
| 4346 | printk(KERN_DEBUG "megasas: IO memory region busy!\n"); |
| 4347 | return -EBUSY; |
| 4348 | } |
| 4349 | |
Ben Collins | 11f8a7b | 2013-09-13 12:46:44 -0400 | [diff] [blame] | 4350 | base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 4351 | instance->reg_set = ioremap_nocache(base_addr, 8192); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4352 | |
| 4353 | if (!instance->reg_set) { |
| 4354 | printk(KERN_DEBUG "megasas: Failed to map IO mem\n"); |
| 4355 | goto fail_ioremap; |
| 4356 | } |
| 4357 | |
| 4358 | reg_set = instance->reg_set; |
| 4359 | |
| 4360 | switch (instance->pdev->device) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4361 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4362 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4363 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4364 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4365 | instance->instancet = &megasas_instance_template_fusion; |
| 4366 | break; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4367 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 4368 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 4369 | instance->instancet = &megasas_instance_template_ppc; |
| 4370 | break; |
| 4371 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 4372 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 4373 | instance->instancet = &megasas_instance_template_gen2; |
| 4374 | break; |
| 4375 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 4376 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 4377 | instance->instancet = &megasas_instance_template_skinny; |
| 4378 | break; |
| 4379 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 4380 | case PCI_DEVICE_ID_DELL_PERC5: |
| 4381 | default: |
| 4382 | instance->instancet = &megasas_instance_template_xscale; |
| 4383 | break; |
| 4384 | } |
| 4385 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame] | 4386 | if (megasas_transition_to_ready(instance, 0)) { |
| 4387 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 4388 | instance->instancet->adp_reset |
| 4389 | (instance, instance->reg_set); |
| 4390 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
| 4391 | dev_info(&instance->pdev->dev, |
| 4392 | "megasas: FW restarted successfully from %s!\n", |
| 4393 | __func__); |
| 4394 | |
| 4395 | /*waitting for about 30 second before retry*/ |
| 4396 | ssleep(30); |
| 4397 | |
| 4398 | if (megasas_transition_to_ready(instance, 0)) |
| 4399 | goto fail_ready_state; |
| 4400 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4401 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4402 | /* |
| 4403 | * MSI-X host index 0 is common for all adapter. |
| 4404 | * It is used for all MPT based Adapters. |
| 4405 | */ |
| 4406 | instance->reply_post_host_index_addr[0] = |
| 4407 | (u32 *)((u8 *)instance->reg_set + |
| 4408 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 4409 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 4410 | /* Check if MSI-X is supported while in ready state */ |
| 4411 | msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & |
| 4412 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4413 | if (msix_enable && !msix_disable) { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4414 | scratch_pad_2 = readl |
| 4415 | (&instance->reg_set->outbound_scratch_pad_2); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4416 | /* Check max MSI-X vectors */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4417 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
| 4418 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA)) { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4419 | instance->msix_vectors = (scratch_pad_2 |
| 4420 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 4421 | fw_msix_count = instance->msix_vectors; |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 4422 | if (msix_vectors) |
| 4423 | instance->msix_vectors = |
| 4424 | min(msix_vectors, |
| 4425 | instance->msix_vectors); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4426 | } else if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) |
| 4427 | || (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
| 4428 | /* Invader/Fury supports more than 8 MSI-X */ |
| 4429 | instance->msix_vectors = ((scratch_pad_2 |
| 4430 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 4431 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
| 4432 | fw_msix_count = instance->msix_vectors; |
| 4433 | /* Save 1-15 reply post index address to local memory |
| 4434 | * Index 0 is already saved from reg offset |
| 4435 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 4436 | */ |
| 4437 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 4438 | instance->reply_post_host_index_addr[loop] = |
| 4439 | (u32 *)((u8 *)instance->reg_set + |
| 4440 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 4441 | + (loop * 0x10)); |
| 4442 | } |
| 4443 | if (msix_vectors) |
| 4444 | instance->msix_vectors = min(msix_vectors, |
| 4445 | instance->msix_vectors); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4446 | } else |
| 4447 | instance->msix_vectors = 1; |
| 4448 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 4449 | instance->msix_vectors = min(instance->msix_vectors, |
| 4450 | (unsigned int)num_online_cpus()); |
| 4451 | for (i = 0; i < instance->msix_vectors; i++) |
| 4452 | instance->msixentry[i].entry = i; |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 4453 | i = pci_enable_msix_range(instance->pdev, instance->msixentry, |
| 4454 | 1, instance->msix_vectors); |
Jiang Liu | c12de88 | 2014-11-03 20:44:20 +0800 | [diff] [blame] | 4455 | if (i > 0) |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 4456 | instance->msix_vectors = i; |
| 4457 | else |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4458 | instance->msix_vectors = 0; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4459 | |
| 4460 | dev_info(&instance->pdev->dev, "[scsi%d]: FW supports" |
| 4461 | "<%d> MSIX vector,Online CPUs: <%d>," |
| 4462 | "Current MSIX <%d>\n", instance->host->host_no, |
| 4463 | fw_msix_count, (unsigned int)num_online_cpus(), |
| 4464 | instance->msix_vectors); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4465 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 4466 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4467 | instance->ctrl_info = kzalloc(sizeof(struct megasas_ctrl_info), |
| 4468 | GFP_KERNEL); |
| 4469 | if (instance->ctrl_info == NULL) |
| 4470 | goto fail_init_adapter; |
| 4471 | |
| 4472 | /* |
| 4473 | * Below are default value for legacy Firmware. |
| 4474 | * non-fusion based controllers |
| 4475 | */ |
| 4476 | instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES; |
| 4477 | instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4478 | /* Get operational params, sge flags, send init cmd to controller */ |
| 4479 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 4480 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4481 | |
| 4482 | printk(KERN_ERR "megasas: INIT adapter done\n"); |
| 4483 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4484 | /** for passthrough |
| 4485 | * the following function will get the PD LIST. |
| 4486 | */ |
| 4487 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4488 | memset(instance->pd_list, 0 , |
| 4489 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 4490 | if (megasas_get_pd_list(instance) < 0) { |
| 4491 | printk(KERN_ERR "megasas: failed to get PD list\n"); |
| 4492 | goto fail_init_adapter; |
| 4493 | } |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 4494 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4495 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 4496 | if (megasas_ld_list_query(instance, |
| 4497 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
| 4498 | megasas_get_ld_list(instance); |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 4499 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4500 | /* |
| 4501 | * Compute the max allowed sectors per IO: The controller info has two |
| 4502 | * limits on max sectors. Driver should use the minimum of these two. |
| 4503 | * |
| 4504 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 4505 | * |
| 4506 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 4507 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 4508 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 4509 | tmp_sectors = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4510 | ctrl_info = instance->ctrl_info; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4511 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4512 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 4513 | le16_to_cpu(ctrl_info->max_strips_per_io); |
| 4514 | max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4515 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4516 | 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] | 4517 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4518 | /*Check whether controller is iMR or MR */ |
| 4519 | if (ctrl_info->memory_size) { |
| 4520 | instance->is_imr = 0; |
| 4521 | dev_info(&instance->pdev->dev, "Controller type: MR," |
| 4522 | "Memory size is: %dMB\n", |
| 4523 | le16_to_cpu(ctrl_info->memory_size)); |
| 4524 | } else { |
| 4525 | instance->is_imr = 1; |
| 4526 | dev_info(&instance->pdev->dev, |
| 4527 | "Controller type: iMR\n"); |
| 4528 | } |
| 4529 | /* OnOffProperties are converted into CPU arch*/ |
| 4530 | le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties); |
| 4531 | instance->disableOnlineCtrlReset = |
| 4532 | ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; |
| 4533 | /* adapterOperations2 are converted into CPU arch*/ |
| 4534 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations2); |
| 4535 | instance->mpio = ctrl_info->adapterOperations2.mpio; |
| 4536 | instance->UnevenSpanSupport = |
| 4537 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 4538 | if (instance->UnevenSpanSupport) { |
| 4539 | struct fusion_context *fusion = instance->ctrl_context; |
| 4540 | |
| 4541 | dev_info(&instance->pdev->dev, "FW supports: " |
| 4542 | "UnevenSpanSupport=%x\n", instance->UnevenSpanSupport); |
| 4543 | if (MR_ValidateMapInfo(instance)) |
| 4544 | fusion->fast_path_io = 1; |
| 4545 | else |
| 4546 | fusion->fast_path_io = 0; |
| 4547 | |
| 4548 | } |
| 4549 | if (ctrl_info->host_interface.SRIOV) { |
| 4550 | if (!ctrl_info->adapterOperations2.activePassive) |
| 4551 | instance->PlasmaFW111 = 1; |
| 4552 | |
| 4553 | if (!instance->PlasmaFW111) |
| 4554 | instance->requestorId = |
| 4555 | ctrl_info->iov.requestorId; |
| 4556 | else { |
| 4557 | iovPtr = (struct IOV_111 *)((unsigned char *)ctrl_info + IOV_111_OFFSET); |
| 4558 | instance->requestorId = iovPtr->requestorId; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 4559 | } |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4560 | dev_warn(&instance->pdev->dev, "I am VF " |
| 4561 | "requestorId %d\n", instance->requestorId); |
| 4562 | } |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 4563 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4564 | le32_to_cpus((u32 *)&ctrl_info->adapterOperations3); |
| 4565 | instance->crash_dump_fw_support = |
| 4566 | ctrl_info->adapterOperations3.supportCrashDump; |
| 4567 | instance->crash_dump_drv_support = |
| 4568 | (instance->crash_dump_fw_support && |
| 4569 | instance->crash_dump_buf); |
| 4570 | if (instance->crash_dump_drv_support) { |
| 4571 | dev_info(&instance->pdev->dev, "Firmware Crash dump " |
| 4572 | "feature is supported\n"); |
| 4573 | megasas_set_crash_dump_params(instance, |
| 4574 | MR_CRASH_BUF_TURN_OFF); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4575 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4576 | } else { |
| 4577 | if (instance->crash_dump_buf) |
| 4578 | pci_free_consistent(instance->pdev, |
| 4579 | CRASH_DMA_BUF_SIZE, |
| 4580 | instance->crash_dump_buf, |
| 4581 | instance->crash_dump_h); |
| 4582 | instance->crash_dump_buf = NULL; |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 4583 | } |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 4584 | instance->max_sectors_per_req = instance->max_num_sge * |
| 4585 | PAGE_SIZE / 512; |
| 4586 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 4587 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4588 | |
| 4589 | kfree(ctrl_info); |
| 4590 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 4591 | /* Check for valid throttlequeuedepth module parameter */ |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 4592 | if (instance->is_imr) { |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 4593 | if (throttlequeuedepth > (instance->max_fw_cmds - |
| 4594 | MEGASAS_SKINNY_INT_CMDS)) |
| 4595 | instance->throttlequeuedepth = |
| 4596 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 4597 | else |
| 4598 | instance->throttlequeuedepth = throttlequeuedepth; |
| 4599 | } else { |
| 4600 | if (throttlequeuedepth > (instance->max_fw_cmds - |
| 4601 | MEGASAS_INT_CMDS)) |
| 4602 | instance->throttlequeuedepth = |
| 4603 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 4604 | else |
| 4605 | instance->throttlequeuedepth = throttlequeuedepth; |
| 4606 | } |
| 4607 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 4608 | /* |
| 4609 | * Setup tasklet for cmd completion |
| 4610 | */ |
| 4611 | |
adam radford | f86c542 | 2011-02-24 20:57:00 -0800 | [diff] [blame] | 4612 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 4613 | (unsigned long)instance); |
| 4614 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4615 | /* Launch SR-IOV heartbeat timer */ |
| 4616 | if (instance->requestorId) { |
| 4617 | if (!megasas_sriov_start_heartbeat(instance, 1)) |
| 4618 | megasas_start_timer(instance, |
| 4619 | &instance->sriov_heartbeat_timer, |
| 4620 | megasas_sriov_heartbeat_handler, |
| 4621 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 4622 | else |
| 4623 | instance->skip_heartbeat_timer_del = 1; |
| 4624 | } |
| 4625 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4626 | return 0; |
| 4627 | |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 4628 | fail_init_adapter: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 4629 | fail_ready_state: |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4630 | kfree(instance->ctrl_info); |
| 4631 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4632 | iounmap(instance->reg_set); |
| 4633 | |
| 4634 | fail_ioremap: |
adam radford | b6d5d88 | 2010-12-14 18:56:07 -0800 | [diff] [blame] | 4635 | pci_release_selected_regions(instance->pdev, instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4636 | |
| 4637 | return -EINVAL; |
| 4638 | } |
| 4639 | |
| 4640 | /** |
| 4641 | * megasas_release_mfi - Reverses the FW initialization |
| 4642 | * @intance: Adapter soft state |
| 4643 | */ |
| 4644 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 4645 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4646 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4647 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4648 | if (instance->reply_queue) |
| 4649 | pci_free_consistent(instance->pdev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4650 | instance->reply_queue, instance->reply_queue_h); |
| 4651 | |
| 4652 | megasas_free_cmds(instance); |
| 4653 | |
| 4654 | iounmap(instance->reg_set); |
| 4655 | |
adam radford | b6d5d88 | 2010-12-14 18:56:07 -0800 | [diff] [blame] | 4656 | pci_release_selected_regions(instance->pdev, instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | /** |
| 4660 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 4661 | * @instance: Adapter soft state |
| 4662 | * @eli: FW event log sequence numbers information |
| 4663 | * |
| 4664 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 4665 | * usually find out the latest sequence number of the events, the seq number at |
| 4666 | * the boot etc. They would "read" all the events below the latest seq number |
| 4667 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 4668 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 4669 | * wait for the events to happen. |
| 4670 | */ |
| 4671 | static int |
| 4672 | megasas_get_seq_num(struct megasas_instance *instance, |
| 4673 | struct megasas_evt_log_info *eli) |
| 4674 | { |
| 4675 | struct megasas_cmd *cmd; |
| 4676 | struct megasas_dcmd_frame *dcmd; |
| 4677 | struct megasas_evt_log_info *el_info; |
| 4678 | dma_addr_t el_info_h = 0; |
| 4679 | |
| 4680 | cmd = megasas_get_cmd(instance); |
| 4681 | |
| 4682 | if (!cmd) { |
| 4683 | return -ENOMEM; |
| 4684 | } |
| 4685 | |
| 4686 | dcmd = &cmd->frame->dcmd; |
| 4687 | el_info = pci_alloc_consistent(instance->pdev, |
| 4688 | sizeof(struct megasas_evt_log_info), |
| 4689 | &el_info_h); |
| 4690 | |
| 4691 | if (!el_info) { |
| 4692 | megasas_return_cmd(instance, cmd); |
| 4693 | return -ENOMEM; |
| 4694 | } |
| 4695 | |
| 4696 | memset(el_info, 0, sizeof(*el_info)); |
| 4697 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4698 | |
| 4699 | dcmd->cmd = MFI_CMD_DCMD; |
| 4700 | dcmd->cmd_status = 0x0; |
| 4701 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4702 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4703 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4704 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4705 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
| 4706 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO); |
| 4707 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(el_info_h); |
| 4708 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_log_info)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4709 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 4710 | if (megasas_issue_blocked_cmd(instance, cmd, 30)) |
| 4711 | dev_err(&instance->pdev->dev, "Command timedout" |
| 4712 | "from %s\n", __func__); |
| 4713 | else { |
| 4714 | /* |
| 4715 | * Copy the data back into callers buffer |
| 4716 | */ |
| 4717 | eli->newest_seq_num = le32_to_cpu(el_info->newest_seq_num); |
| 4718 | eli->oldest_seq_num = le32_to_cpu(el_info->oldest_seq_num); |
| 4719 | eli->clear_seq_num = le32_to_cpu(el_info->clear_seq_num); |
| 4720 | eli->shutdown_seq_num = le32_to_cpu(el_info->shutdown_seq_num); |
| 4721 | eli->boot_seq_num = le32_to_cpu(el_info->boot_seq_num); |
| 4722 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4723 | |
| 4724 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), |
| 4725 | el_info, el_info_h); |
| 4726 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 4727 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 4728 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 4729 | cmd->mpt_pthr_cmd_blocked); |
| 4730 | else |
| 4731 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4732 | |
| 4733 | return 0; |
| 4734 | } |
| 4735 | |
| 4736 | /** |
| 4737 | * megasas_register_aen - Registers for asynchronous event notification |
| 4738 | * @instance: Adapter soft state |
| 4739 | * @seq_num: The starting sequence number |
| 4740 | * @class_locale: Class of the event |
| 4741 | * |
| 4742 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 4743 | * to be notified if and only if the event is of type @class_locale |
| 4744 | */ |
| 4745 | static int |
| 4746 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 4747 | u32 class_locale_word) |
| 4748 | { |
| 4749 | int ret_val; |
| 4750 | struct megasas_cmd *cmd; |
| 4751 | struct megasas_dcmd_frame *dcmd; |
| 4752 | union megasas_evt_class_locale curr_aen; |
| 4753 | union megasas_evt_class_locale prev_aen; |
| 4754 | |
| 4755 | /* |
| 4756 | * If there an AEN pending already (aen_cmd), check if the |
| 4757 | * class_locale of that pending AEN is inclusive of the new |
| 4758 | * AEN request we currently have. If it is, then we don't have |
| 4759 | * to do anything. In other words, whichever events the current |
| 4760 | * AEN request is subscribing to, have already been subscribed |
| 4761 | * to. |
| 4762 | * |
| 4763 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 4764 | * that command, form a class_locale that is superset of both |
| 4765 | * old and current and re-issue to the FW |
| 4766 | */ |
| 4767 | |
| 4768 | curr_aen.word = class_locale_word; |
| 4769 | |
| 4770 | if (instance->aen_cmd) { |
| 4771 | |
| 4772 | prev_aen.word = instance->aen_cmd->frame->dcmd.mbox.w[1]; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4773 | prev_aen.members.locale = le16_to_cpu(prev_aen.members.locale); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4774 | |
| 4775 | /* |
| 4776 | * A class whose enum value is smaller is inclusive of all |
| 4777 | * higher values. If a PROGRESS (= -1) was previously |
| 4778 | * registered, then a new registration requests for higher |
| 4779 | * classes need not be sent to FW. They are automatically |
| 4780 | * included. |
| 4781 | * |
| 4782 | * Locale numbers don't have such hierarchy. They are bitmap |
| 4783 | * values |
| 4784 | */ |
| 4785 | if ((prev_aen.members.class <= curr_aen.members.class) && |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 4786 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4787 | curr_aen.members.locale)) { |
| 4788 | /* |
| 4789 | * Previously issued event registration includes |
| 4790 | * current request. Nothing to do. |
| 4791 | */ |
| 4792 | return 0; |
| 4793 | } else { |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 4794 | curr_aen.members.locale |= prev_aen.members.locale; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4795 | |
| 4796 | if (prev_aen.members.class < curr_aen.members.class) |
| 4797 | curr_aen.members.class = prev_aen.members.class; |
| 4798 | |
| 4799 | instance->aen_cmd->abort_aen = 1; |
| 4800 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 4801 | instance-> |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 4802 | aen_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4803 | |
| 4804 | if (ret_val) { |
| 4805 | printk(KERN_DEBUG "megasas: Failed to abort " |
| 4806 | "previous AEN command\n"); |
| 4807 | return ret_val; |
| 4808 | } |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | cmd = megasas_get_cmd(instance); |
| 4813 | |
| 4814 | if (!cmd) |
| 4815 | return -ENOMEM; |
| 4816 | |
| 4817 | dcmd = &cmd->frame->dcmd; |
| 4818 | |
| 4819 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 4820 | |
| 4821 | /* |
| 4822 | * Prepare DCMD for aen registration |
| 4823 | */ |
| 4824 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4825 | |
| 4826 | dcmd->cmd = MFI_CMD_DCMD; |
| 4827 | dcmd->cmd_status = 0x0; |
| 4828 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4829 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4830 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4831 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4832 | dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
| 4833 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT); |
| 4834 | dcmd->mbox.w[0] = cpu_to_le32(seq_num); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4835 | instance->last_seq_num = seq_num; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4836 | dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word); |
| 4837 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->evt_detail_h); |
| 4838 | dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_detail)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4839 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 4840 | if (instance->aen_cmd != NULL) { |
| 4841 | megasas_return_cmd(instance, cmd); |
| 4842 | return 0; |
| 4843 | } |
| 4844 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4845 | /* |
| 4846 | * Store reference to the cmd used to register for AEN. When an |
| 4847 | * application wants us to register for AEN, we have to abort this |
| 4848 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 4849 | */ |
| 4850 | instance->aen_cmd = cmd; |
| 4851 | |
| 4852 | /* |
| 4853 | * Issue the aen registration frame |
| 4854 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4855 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4856 | |
| 4857 | return 0; |
| 4858 | } |
| 4859 | |
| 4860 | /** |
| 4861 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 4862 | * @instance: Adapter soft state |
| 4863 | */ |
| 4864 | static int megasas_start_aen(struct megasas_instance *instance) |
| 4865 | { |
| 4866 | struct megasas_evt_log_info eli; |
| 4867 | union megasas_evt_class_locale class_locale; |
| 4868 | |
| 4869 | /* |
| 4870 | * Get the latest sequence number from FW |
| 4871 | */ |
| 4872 | memset(&eli, 0, sizeof(eli)); |
| 4873 | |
| 4874 | if (megasas_get_seq_num(instance, &eli)) |
| 4875 | return -1; |
| 4876 | |
| 4877 | /* |
| 4878 | * Register AEN with FW for latest sequence number plus 1 |
| 4879 | */ |
| 4880 | class_locale.members.reserved = 0; |
| 4881 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 4882 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 4883 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4884 | return megasas_register_aen(instance, |
Sumit.Saxena@lsi.com | 3993a86 | 2013-09-16 15:18:06 +0530 | [diff] [blame] | 4885 | eli.newest_seq_num + 1, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4886 | class_locale.word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | /** |
| 4890 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 4891 | * @instance: Adapter soft state |
| 4892 | */ |
| 4893 | static int megasas_io_attach(struct megasas_instance *instance) |
| 4894 | { |
| 4895 | struct Scsi_Host *host = instance->host; |
| 4896 | |
| 4897 | /* |
| 4898 | * Export parameters required by SCSI mid-layer |
| 4899 | */ |
| 4900 | host->irq = instance->pdev->irq; |
| 4901 | host->unique_id = instance->unique_id; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 4902 | if (instance->is_imr) { |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 4903 | host->can_queue = |
| 4904 | instance->max_fw_cmds - MEGASAS_SKINNY_INT_CMDS; |
| 4905 | } else |
| 4906 | host->can_queue = |
| 4907 | instance->max_fw_cmds - MEGASAS_INT_CMDS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4908 | host->this_id = instance->init_id; |
| 4909 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 4910 | |
| 4911 | if (instance->fw_support_ieee) |
| 4912 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 4913 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 4914 | /* |
| 4915 | * Check if the module parameter value for max_sectors can be used |
| 4916 | */ |
| 4917 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 4918 | instance->max_sectors_per_req = max_sectors; |
| 4919 | else { |
| 4920 | if (max_sectors) { |
| 4921 | if (((instance->pdev->device == |
| 4922 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 4923 | (instance->pdev->device == |
| 4924 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 4925 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 4926 | instance->max_sectors_per_req = max_sectors; |
| 4927 | } else { |
| 4928 | printk(KERN_INFO "megasas: max_sectors should be > 0" |
| 4929 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 4930 | instance->max_sectors_per_req); |
| 4931 | } |
| 4932 | } |
| 4933 | } |
| 4934 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4935 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4936 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4937 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 4938 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4939 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 4940 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4941 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4942 | /* Fusion only supports host reset */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4943 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4944 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4945 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 4946 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4947 | host->hostt->eh_device_reset_handler = NULL; |
| 4948 | host->hostt->eh_bus_reset_handler = NULL; |
| 4949 | } |
| 4950 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4951 | /* |
| 4952 | * Notify the mid-layer about the new controller |
| 4953 | */ |
| 4954 | if (scsi_add_host(host, &instance->pdev->dev)) { |
| 4955 | printk(KERN_DEBUG "megasas: scsi_add_host failed\n"); |
| 4956 | return -ENODEV; |
| 4957 | } |
| 4958 | |
| 4959 | /* |
| 4960 | * Trigger SCSI to scan our drives |
| 4961 | */ |
| 4962 | scsi_scan_host(host); |
| 4963 | return 0; |
| 4964 | } |
| 4965 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4966 | static int |
| 4967 | megasas_set_dma_mask(struct pci_dev *pdev) |
| 4968 | { |
| 4969 | /* |
| 4970 | * All our contollers are capable of performing 64-bit DMA |
| 4971 | */ |
| 4972 | if (IS_DMA64) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 4973 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4974 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4975 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4976 | goto fail_set_dma_mask; |
| 4977 | } |
| 4978 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4979 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4980 | goto fail_set_dma_mask; |
| 4981 | } |
Sumit.Saxena@lsi.com | 46de63e2 | 2014-02-12 23:38:44 +0530 | [diff] [blame] | 4982 | /* |
| 4983 | * Ensure that all data structures are allocated in 32-bit |
| 4984 | * memory. |
| 4985 | */ |
| 4986 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { |
| 4987 | /* Try 32bit DMA mask and 32 bit Consistent dma mask */ |
| 4988 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 4989 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 4990 | dev_info(&pdev->dev, "set 32bit DMA mask" |
| 4991 | "and 32 bit consistent mask\n"); |
| 4992 | else |
| 4993 | goto fail_set_dma_mask; |
| 4994 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 4995 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4996 | return 0; |
| 4997 | |
| 4998 | fail_set_dma_mask: |
| 4999 | return 1; |
| 5000 | } |
| 5001 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5002 | /** |
| 5003 | * megasas_probe_one - PCI hotplug entry point |
| 5004 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 5005 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5006 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5007 | static int megasas_probe_one(struct pci_dev *pdev, |
| 5008 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5009 | { |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5010 | int rval, pos, i, j, cpu; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5011 | struct Scsi_Host *host; |
| 5012 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5013 | u16 control = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5014 | struct fusion_context *fusion = NULL; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5015 | |
| 5016 | /* Reset MSI-X in the kdump kernel */ |
| 5017 | if (reset_devices) { |
| 5018 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 5019 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5020 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5021 | &control); |
| 5022 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 5023 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 5024 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 5025 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 5026 | control & |
| 5027 | ~PCI_MSIX_FLAGS_ENABLE); |
| 5028 | } |
| 5029 | } |
| 5030 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5031 | |
| 5032 | /* |
| 5033 | * Announce PCI information |
| 5034 | */ |
| 5035 | printk(KERN_INFO "megasas: %#4.04x:%#4.04x:%#4.04x:%#4.04x: ", |
| 5036 | pdev->vendor, pdev->device, pdev->subsystem_vendor, |
| 5037 | pdev->subsystem_device); |
| 5038 | |
| 5039 | printk("bus %d:slot %d:func %d\n", |
| 5040 | pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); |
| 5041 | |
| 5042 | /* |
| 5043 | * PCI prepping: enable device set bus mastering and dma mask |
| 5044 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 5045 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5046 | |
| 5047 | if (rval) { |
| 5048 | return rval; |
| 5049 | } |
| 5050 | |
| 5051 | pci_set_master(pdev); |
| 5052 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5053 | if (megasas_set_dma_mask(pdev)) |
| 5054 | goto fail_set_dma_mask; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5055 | |
| 5056 | host = scsi_host_alloc(&megasas_template, |
| 5057 | sizeof(struct megasas_instance)); |
| 5058 | |
| 5059 | if (!host) { |
| 5060 | printk(KERN_DEBUG "megasas: scsi_host_alloc failed\n"); |
| 5061 | goto fail_alloc_instance; |
| 5062 | } |
| 5063 | |
| 5064 | instance = (struct megasas_instance *)host->hostdata; |
| 5065 | memset(instance, 0, sizeof(*instance)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5066 | atomic_set( &instance->fw_reset_no_pci_access, 0 ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5067 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5068 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5069 | switch (instance->pdev->device) { |
| 5070 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5071 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 5072 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 5073 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5074 | { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5075 | instance->ctrl_context_pages = |
| 5076 | get_order(sizeof(struct fusion_context)); |
| 5077 | instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL, |
| 5078 | instance->ctrl_context_pages); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5079 | if (!instance->ctrl_context) { |
| 5080 | printk(KERN_DEBUG "megasas: Failed to allocate " |
| 5081 | "memory for Fusion context info\n"); |
| 5082 | goto fail_alloc_dma_buf; |
| 5083 | } |
| 5084 | fusion = instance->ctrl_context; |
| 5085 | INIT_LIST_HEAD(&fusion->cmd_pool); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5086 | spin_lock_init(&fusion->mpt_pool_lock); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5087 | memset(fusion->load_balance_info, 0, |
| 5088 | sizeof(struct LD_LOAD_BALANCE_INFO) * MAX_LOGICAL_DRIVES_EXT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5089 | } |
| 5090 | break; |
| 5091 | default: /* For all other supported controllers */ |
| 5092 | |
| 5093 | instance->producer = |
| 5094 | pci_alloc_consistent(pdev, sizeof(u32), |
| 5095 | &instance->producer_h); |
| 5096 | instance->consumer = |
| 5097 | pci_alloc_consistent(pdev, sizeof(u32), |
| 5098 | &instance->consumer_h); |
| 5099 | |
| 5100 | if (!instance->producer || !instance->consumer) { |
| 5101 | printk(KERN_DEBUG "megasas: Failed to allocate" |
| 5102 | "memory for producer, consumer\n"); |
| 5103 | goto fail_alloc_dma_buf; |
| 5104 | } |
| 5105 | |
| 5106 | *instance->producer = 0; |
| 5107 | *instance->consumer = 0; |
| 5108 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5109 | } |
| 5110 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5111 | /* Crash dump feature related initialisation*/ |
| 5112 | instance->drv_buf_index = 0; |
| 5113 | instance->drv_buf_alloc = 0; |
| 5114 | instance->crash_dump_fw_support = 0; |
| 5115 | instance->crash_dump_app_support = 0; |
| 5116 | instance->fw_crash_state = UNAVAILABLE; |
| 5117 | spin_lock_init(&instance->crashdump_lock); |
| 5118 | instance->crash_dump_buf = NULL; |
| 5119 | |
| 5120 | if (!reset_devices) |
| 5121 | instance->crash_dump_buf = pci_alloc_consistent(pdev, |
| 5122 | CRASH_DMA_BUF_SIZE, |
| 5123 | &instance->crash_dump_h); |
| 5124 | if (!instance->crash_dump_buf) |
| 5125 | dev_err(&instance->pdev->dev, "Can't allocate Firmware " |
| 5126 | "crash dump DMA buffer\n"); |
| 5127 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5128 | megasas_poll_wait_aen = 0; |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5129 | instance->flag_ieee = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5130 | instance->ev = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5131 | instance->issuepend_done = 1; |
| 5132 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 5133 | instance->is_imr = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5134 | |
| 5135 | instance->evt_detail = pci_alloc_consistent(pdev, |
| 5136 | sizeof(struct |
| 5137 | megasas_evt_detail), |
| 5138 | &instance->evt_detail_h); |
| 5139 | |
| 5140 | if (!instance->evt_detail) { |
| 5141 | printk(KERN_DEBUG "megasas: Failed to allocate memory for " |
| 5142 | "event detail structure\n"); |
| 5143 | goto fail_alloc_dma_buf; |
| 5144 | } |
| 5145 | |
| 5146 | /* |
| 5147 | * Initialize locks and queues |
| 5148 | */ |
| 5149 | INIT_LIST_HEAD(&instance->cmd_pool); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5150 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5151 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 5152 | atomic_set(&instance->fw_outstanding,0); |
| 5153 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5154 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 5155 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 5156 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5157 | spin_lock_init(&instance->mfi_pool_lock); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5158 | spin_lock_init(&instance->hba_lock); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 5159 | spin_lock_init(&instance->completion_lock); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5160 | |
Matthias Kaehlcke | e5a69e2 | 2007-10-27 09:48:46 +0200 | [diff] [blame] | 5161 | mutex_init(&instance->aen_mutex); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5162 | mutex_init(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5163 | |
| 5164 | /* |
| 5165 | * Initialize PCI related and misc parameters |
| 5166 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5167 | instance->host = host; |
| 5168 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 5169 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5170 | instance->ctrl_info = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5171 | |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 5172 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 5173 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 5174 | instance->flag_ieee = 1; |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 5175 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 5176 | } else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5177 | sema_init(&instance->ioctl_sem, (MEGASAS_INT_CMDS - 5)); |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 5178 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5179 | megasas_dbg_lvl = 0; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 5180 | instance->flag = 0; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5181 | instance->unload = 1; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 5182 | instance->last_time = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5183 | instance->disableOnlineCtrlReset = 1; |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 5184 | instance->UnevenSpanSupport = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5185 | |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 5186 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5187 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 5188 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5189 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5190 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5191 | INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq); |
| 5192 | } else |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5193 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5194 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5195 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 5196 | * Initialize MFI Firmware |
| 5197 | */ |
| 5198 | if (megasas_init_fw(instance)) |
| 5199 | goto fail_init_mfi; |
| 5200 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5201 | if (instance->requestorId) { |
| 5202 | if (instance->PlasmaFW111) { |
| 5203 | instance->vf_affiliation_111 = |
| 5204 | pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 5205 | &instance->vf_affiliation_111_h); |
| 5206 | if (!instance->vf_affiliation_111) |
| 5207 | printk(KERN_WARNING "megasas: Can't allocate " |
| 5208 | "memory for VF affiliation buffer\n"); |
| 5209 | } else { |
| 5210 | instance->vf_affiliation = |
| 5211 | pci_alloc_consistent(pdev, |
| 5212 | (MAX_LOGICAL_DRIVES + 1) * |
| 5213 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 5214 | &instance->vf_affiliation_h); |
| 5215 | if (!instance->vf_affiliation) |
| 5216 | printk(KERN_WARNING "megasas: Can't allocate " |
| 5217 | "memory for VF affiliation buffer\n"); |
| 5218 | } |
| 5219 | } |
| 5220 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5221 | retry_irq_register: |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 5222 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5223 | * Register IRQ |
| 5224 | */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5225 | if (instance->msix_vectors) { |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5226 | cpu = cpumask_first(cpu_online_mask); |
| 5227 | for (i = 0; i < instance->msix_vectors; i++) { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5228 | instance->irq_context[i].instance = instance; |
| 5229 | instance->irq_context[i].MSIxIndex = i; |
| 5230 | if (request_irq(instance->msixentry[i].vector, |
| 5231 | instance->instancet->service_isr, 0, |
| 5232 | "megasas", |
| 5233 | &instance->irq_context[i])) { |
| 5234 | printk(KERN_DEBUG "megasas: Failed to " |
| 5235 | "register IRQ for vector %d.\n", i); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5236 | for (j = 0; j < i; j++) { |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5237 | if (smp_affinity_enable) |
| 5238 | irq_set_affinity_hint( |
| 5239 | instance->msixentry[j].vector, NULL); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5240 | free_irq( |
| 5241 | instance->msixentry[j].vector, |
| 5242 | &instance->irq_context[j]); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5243 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5244 | /* Retry irq register for IO_APIC */ |
| 5245 | instance->msix_vectors = 0; |
| 5246 | goto retry_irq_register; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5247 | } |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5248 | if (smp_affinity_enable) { |
| 5249 | if (irq_set_affinity_hint(instance->msixentry[i].vector, |
| 5250 | get_cpu_mask(cpu))) |
| 5251 | dev_err(&instance->pdev->dev, |
| 5252 | "Error setting affinity hint " |
| 5253 | "for cpu %d\n", cpu); |
| 5254 | cpu = cpumask_next(cpu, cpu_online_mask); |
| 5255 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5256 | } |
| 5257 | } else { |
| 5258 | instance->irq_context[0].instance = instance; |
| 5259 | instance->irq_context[0].MSIxIndex = 0; |
| 5260 | if (request_irq(pdev->irq, instance->instancet->service_isr, |
| 5261 | IRQF_SHARED, "megasas", |
| 5262 | &instance->irq_context[0])) { |
| 5263 | printk(KERN_DEBUG "megasas: Failed to register IRQ\n"); |
| 5264 | goto fail_irq; |
| 5265 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5266 | } |
| 5267 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5268 | instance->instancet->enable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5269 | |
| 5270 | /* |
| 5271 | * Store instance in PCI softstate |
| 5272 | */ |
| 5273 | pci_set_drvdata(pdev, instance); |
| 5274 | |
| 5275 | /* |
| 5276 | * Add this controller to megasas_mgmt_info structure so that it |
| 5277 | * can be exported to management applications |
| 5278 | */ |
| 5279 | megasas_mgmt_info.count++; |
| 5280 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 5281 | megasas_mgmt_info.max_index++; |
| 5282 | |
| 5283 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 5284 | * Register with SCSI mid-layer |
| 5285 | */ |
| 5286 | if (megasas_io_attach(instance)) |
| 5287 | goto fail_io_attach; |
| 5288 | |
| 5289 | instance->unload = 0; |
| 5290 | |
| 5291 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5292 | * Initiate AEN (Asynchronous Event Notification) |
| 5293 | */ |
| 5294 | if (megasas_start_aen(instance)) { |
| 5295 | printk(KERN_DEBUG "megasas: start aen failed\n"); |
| 5296 | goto fail_start_aen; |
| 5297 | } |
| 5298 | |
Adam Radford | 9ea81f8 | 2014-07-09 15:17:57 -0700 | [diff] [blame] | 5299 | /* Get current SR-IOV LD/VF affiliation */ |
| 5300 | if (instance->requestorId) |
| 5301 | megasas_get_ld_vf_affiliation(instance, 1); |
| 5302 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5303 | return 0; |
| 5304 | |
| 5305 | fail_start_aen: |
| 5306 | fail_io_attach: |
| 5307 | megasas_mgmt_info.count--; |
| 5308 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
| 5309 | megasas_mgmt_info.max_index--; |
| 5310 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5311 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5312 | if (instance->msix_vectors) |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5313 | for (i = 0; i < instance->msix_vectors; i++) { |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5314 | if (smp_affinity_enable) |
| 5315 | irq_set_affinity_hint( |
| 5316 | instance->msixentry[i].vector, NULL); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5317 | free_irq(instance->msixentry[i].vector, |
| 5318 | &instance->irq_context[i]); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5319 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5320 | else |
| 5321 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5322 | fail_irq: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 5323 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5324 | (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 5325 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 5326 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5327 | megasas_release_fusion(instance); |
| 5328 | else |
| 5329 | megasas_release_mfi(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5330 | fail_init_mfi: |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5331 | if (instance->msix_vectors) |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 5332 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5333 | fail_alloc_dma_buf: |
| 5334 | if (instance->evt_detail) |
| 5335 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 5336 | instance->evt_detail, |
| 5337 | instance->evt_detail_h); |
| 5338 | |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 5339 | if (instance->producer) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5340 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 5341 | instance->producer_h); |
| 5342 | if (instance->consumer) |
| 5343 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 5344 | instance->consumer_h); |
| 5345 | scsi_host_put(host); |
| 5346 | |
| 5347 | fail_alloc_instance: |
| 5348 | fail_set_dma_mask: |
| 5349 | pci_disable_device(pdev); |
| 5350 | |
| 5351 | return -ENODEV; |
| 5352 | } |
| 5353 | |
| 5354 | /** |
| 5355 | * megasas_flush_cache - Requests FW to flush all its caches |
| 5356 | * @instance: Adapter soft state |
| 5357 | */ |
| 5358 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 5359 | { |
| 5360 | struct megasas_cmd *cmd; |
| 5361 | struct megasas_dcmd_frame *dcmd; |
| 5362 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5363 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 5364 | return; |
| 5365 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5366 | cmd = megasas_get_cmd(instance); |
| 5367 | |
| 5368 | if (!cmd) |
| 5369 | return; |
| 5370 | |
| 5371 | dcmd = &cmd->frame->dcmd; |
| 5372 | |
| 5373 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5374 | |
| 5375 | dcmd->cmd = MFI_CMD_DCMD; |
| 5376 | dcmd->cmd_status = 0x0; |
| 5377 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5378 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5379 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5380 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5381 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5382 | dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5383 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 5384 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5385 | if (megasas_issue_blocked_cmd(instance, cmd, 30)) |
| 5386 | dev_err(&instance->pdev->dev, "Command timedout" |
| 5387 | " from %s\n", __func__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5388 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5389 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 5390 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 5391 | cmd->mpt_pthr_cmd_blocked); |
| 5392 | else |
| 5393 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5394 | |
| 5395 | return; |
| 5396 | } |
| 5397 | |
| 5398 | /** |
| 5399 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 5400 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5401 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5402 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5403 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 5404 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5405 | { |
| 5406 | struct megasas_cmd *cmd; |
| 5407 | struct megasas_dcmd_frame *dcmd; |
| 5408 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5409 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 5410 | return; |
| 5411 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5412 | cmd = megasas_get_cmd(instance); |
| 5413 | |
| 5414 | if (!cmd) |
| 5415 | return; |
| 5416 | |
| 5417 | if (instance->aen_cmd) |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5418 | megasas_issue_blocked_abort_cmd(instance, |
| 5419 | instance->aen_cmd, 30); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5420 | if (instance->map_update_cmd) |
| 5421 | megasas_issue_blocked_abort_cmd(instance, |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5422 | instance->map_update_cmd, 30); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5423 | dcmd = &cmd->frame->dcmd; |
| 5424 | |
| 5425 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 5426 | |
| 5427 | dcmd->cmd = MFI_CMD_DCMD; |
| 5428 | dcmd->cmd_status = 0x0; |
| 5429 | dcmd->sge_count = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5430 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5431 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 5432 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5433 | dcmd->data_xfer_len = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5434 | dcmd->opcode = cpu_to_le32(opcode); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5435 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5436 | if (megasas_issue_blocked_cmd(instance, cmd, 30)) |
| 5437 | dev_err(&instance->pdev->dev, "Command timedout" |
| 5438 | "from %s\n", __func__); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5439 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 5440 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 5441 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 5442 | cmd->mpt_pthr_cmd_blocked); |
| 5443 | else |
| 5444 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5445 | |
| 5446 | return; |
| 5447 | } |
| 5448 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 5449 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5450 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5451 | * megasas_suspend - driver suspend entry point |
| 5452 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5453 | * @state: PCI power state to suspend routine |
| 5454 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 5455 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5456 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5457 | { |
| 5458 | struct Scsi_Host *host; |
| 5459 | struct megasas_instance *instance; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5460 | int i; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5461 | |
| 5462 | instance = pci_get_drvdata(pdev); |
| 5463 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5464 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5465 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5466 | /* Shutdown SR-IOV heartbeat timer */ |
| 5467 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 5468 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 5469 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5470 | megasas_flush_cache(instance); |
| 5471 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5472 | |
| 5473 | /* cancel the delayed work if this work still in queue */ |
| 5474 | if (instance->ev != NULL) { |
| 5475 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 5476 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5477 | instance->ev = NULL; |
| 5478 | } |
| 5479 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5480 | tasklet_kill(&instance->isr_tasklet); |
| 5481 | |
| 5482 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5483 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5484 | |
| 5485 | if (instance->msix_vectors) |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5486 | for (i = 0; i < instance->msix_vectors; i++) { |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5487 | if (smp_affinity_enable) |
| 5488 | irq_set_affinity_hint( |
| 5489 | instance->msixentry[i].vector, NULL); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5490 | free_irq(instance->msixentry[i].vector, |
| 5491 | &instance->irq_context[i]); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5492 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5493 | else |
| 5494 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
| 5495 | if (instance->msix_vectors) |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 5496 | pci_disable_msix(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5497 | |
| 5498 | pci_save_state(pdev); |
| 5499 | pci_disable_device(pdev); |
| 5500 | |
| 5501 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 5502 | |
| 5503 | return 0; |
| 5504 | } |
| 5505 | |
| 5506 | /** |
| 5507 | * megasas_resume- driver resume entry point |
| 5508 | * @pdev: PCI device structure |
| 5509 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 5510 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5511 | megasas_resume(struct pci_dev *pdev) |
| 5512 | { |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5513 | int rval, i, j, cpu; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5514 | struct Scsi_Host *host; |
| 5515 | struct megasas_instance *instance; |
| 5516 | |
| 5517 | instance = pci_get_drvdata(pdev); |
| 5518 | host = instance->host; |
| 5519 | pci_set_power_state(pdev, PCI_D0); |
| 5520 | pci_enable_wake(pdev, PCI_D0, 0); |
| 5521 | pci_restore_state(pdev); |
| 5522 | |
| 5523 | /* |
| 5524 | * PCI prepping: enable device set bus mastering and dma mask |
| 5525 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 5526 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5527 | |
| 5528 | if (rval) { |
| 5529 | printk(KERN_ERR "megasas: Enable device failed\n"); |
| 5530 | return rval; |
| 5531 | } |
| 5532 | |
| 5533 | pci_set_master(pdev); |
| 5534 | |
| 5535 | if (megasas_set_dma_mask(pdev)) |
| 5536 | goto fail_set_dma_mask; |
| 5537 | |
| 5538 | /* |
| 5539 | * Initialize MFI Firmware |
| 5540 | */ |
| 5541 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5542 | atomic_set(&instance->fw_outstanding, 0); |
| 5543 | |
| 5544 | /* |
| 5545 | * We expect the FW state to be READY |
| 5546 | */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 5547 | if (megasas_transition_to_ready(instance, 0)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5548 | goto fail_ready_state; |
| 5549 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5550 | /* Now re-enable MSI-X */ |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 5551 | if (instance->msix_vectors && |
Alexander Gordeev | 8ae80ed | 2014-08-18 08:01:44 +0200 | [diff] [blame] | 5552 | pci_enable_msix_exact(instance->pdev, instance->msixentry, |
| 5553 | instance->msix_vectors)) |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 5554 | goto fail_reenable_msix; |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 5555 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5556 | switch (instance->pdev->device) { |
| 5557 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5558 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 5559 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 5560 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5561 | { |
| 5562 | megasas_reset_reply_desc(instance); |
| 5563 | if (megasas_ioc_init_fusion(instance)) { |
| 5564 | megasas_free_cmds(instance); |
| 5565 | megasas_free_cmds_fusion(instance); |
| 5566 | goto fail_init_mfi; |
| 5567 | } |
| 5568 | if (!megasas_get_map_info(instance)) |
| 5569 | megasas_sync_map_info(instance); |
| 5570 | } |
| 5571 | break; |
| 5572 | default: |
| 5573 | *instance->producer = 0; |
| 5574 | *instance->consumer = 0; |
| 5575 | if (megasas_issue_init_mfi(instance)) |
| 5576 | goto fail_init_mfi; |
| 5577 | break; |
| 5578 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5579 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5580 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 5581 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5582 | |
| 5583 | /* |
| 5584 | * Register IRQ |
| 5585 | */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5586 | if (instance->msix_vectors) { |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5587 | cpu = cpumask_first(cpu_online_mask); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5588 | for (i = 0 ; i < instance->msix_vectors; i++) { |
| 5589 | instance->irq_context[i].instance = instance; |
| 5590 | instance->irq_context[i].MSIxIndex = i; |
| 5591 | if (request_irq(instance->msixentry[i].vector, |
| 5592 | instance->instancet->service_isr, 0, |
| 5593 | "megasas", |
| 5594 | &instance->irq_context[i])) { |
| 5595 | printk(KERN_DEBUG "megasas: Failed to " |
| 5596 | "register IRQ for vector %d.\n", i); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5597 | for (j = 0; j < i; j++) { |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5598 | if (smp_affinity_enable) |
| 5599 | irq_set_affinity_hint( |
| 5600 | instance->msixentry[j].vector, NULL); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5601 | free_irq( |
| 5602 | instance->msixentry[j].vector, |
| 5603 | &instance->irq_context[j]); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5604 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5605 | goto fail_irq; |
| 5606 | } |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5607 | |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5608 | if (smp_affinity_enable) { |
| 5609 | if (irq_set_affinity_hint(instance->msixentry[i].vector, |
| 5610 | get_cpu_mask(cpu))) |
| 5611 | dev_err(&instance->pdev->dev, "Error " |
| 5612 | "setting affinity hint for cpu " |
| 5613 | "%d\n", cpu); |
| 5614 | cpu = cpumask_next(cpu, cpu_online_mask); |
| 5615 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5616 | } |
| 5617 | } else { |
| 5618 | instance->irq_context[0].instance = instance; |
| 5619 | instance->irq_context[0].MSIxIndex = 0; |
| 5620 | if (request_irq(pdev->irq, instance->instancet->service_isr, |
| 5621 | IRQF_SHARED, "megasas", |
| 5622 | &instance->irq_context[0])) { |
| 5623 | printk(KERN_DEBUG "megasas: Failed to register IRQ\n"); |
| 5624 | goto fail_irq; |
| 5625 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5626 | } |
| 5627 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5628 | /* Re-launch SR-IOV heartbeat timer */ |
| 5629 | if (instance->requestorId) { |
| 5630 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
| 5631 | megasas_start_timer(instance, |
| 5632 | &instance->sriov_heartbeat_timer, |
| 5633 | megasas_sriov_heartbeat_handler, |
| 5634 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 5635 | else |
| 5636 | instance->skip_heartbeat_timer_del = 1; |
| 5637 | } |
| 5638 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5639 | instance->instancet->enable_intr(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5640 | instance->unload = 0; |
| 5641 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 5642 | /* |
| 5643 | * Initiate AEN (Asynchronous Event Notification) |
| 5644 | */ |
| 5645 | if (megasas_start_aen(instance)) |
| 5646 | printk(KERN_ERR "megasas: Start AEN failed\n"); |
| 5647 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5648 | return 0; |
| 5649 | |
| 5650 | fail_irq: |
| 5651 | fail_init_mfi: |
| 5652 | if (instance->evt_detail) |
| 5653 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 5654 | instance->evt_detail, |
| 5655 | instance->evt_detail_h); |
| 5656 | |
| 5657 | if (instance->producer) |
| 5658 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 5659 | instance->producer_h); |
| 5660 | if (instance->consumer) |
| 5661 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 5662 | instance->consumer_h); |
| 5663 | scsi_host_put(host); |
| 5664 | |
| 5665 | fail_set_dma_mask: |
| 5666 | fail_ready_state: |
Alexander Gordeev | dd08812 | 2014-08-18 08:01:43 +0200 | [diff] [blame] | 5667 | fail_reenable_msix: |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5668 | |
| 5669 | pci_disable_device(pdev); |
| 5670 | |
| 5671 | return -ENODEV; |
| 5672 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 5673 | #else |
| 5674 | #define megasas_suspend NULL |
| 5675 | #define megasas_resume NULL |
| 5676 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5677 | |
| 5678 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5679 | * megasas_detach_one - PCI hot"un"plug entry point |
| 5680 | * @pdev: PCI device structure |
| 5681 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5682 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5683 | { |
| 5684 | int i; |
| 5685 | struct Scsi_Host *host; |
| 5686 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5687 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5688 | |
| 5689 | instance = pci_get_drvdata(pdev); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5690 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5691 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5692 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5693 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5694 | /* Shutdown SR-IOV heartbeat timer */ |
| 5695 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 5696 | del_timer_sync(&instance->sriov_heartbeat_timer); |
| 5697 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5698 | if (instance->fw_crash_state != UNAVAILABLE) |
| 5699 | megasas_free_host_crash_buffer(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5700 | scsi_remove_host(instance->host); |
| 5701 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5702 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5703 | |
| 5704 | /* cancel the delayed work if this work still in queue*/ |
| 5705 | if (instance->ev != NULL) { |
| 5706 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 5707 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5708 | instance->ev = NULL; |
| 5709 | } |
| 5710 | |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 5711 | /* cancel all wait events */ |
| 5712 | wake_up_all(&instance->int_cmd_wait_q); |
| 5713 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 5714 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5715 | |
| 5716 | /* |
| 5717 | * Take the instance off the instance array. Note that we will not |
| 5718 | * decrement the max_index. We let this array be sparse array |
| 5719 | */ |
| 5720 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 5721 | if (megasas_mgmt_info.instance[i] == instance) { |
| 5722 | megasas_mgmt_info.count--; |
| 5723 | megasas_mgmt_info.instance[i] = NULL; |
| 5724 | |
| 5725 | break; |
| 5726 | } |
| 5727 | } |
| 5728 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5729 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5730 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5731 | if (instance->msix_vectors) |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5732 | for (i = 0; i < instance->msix_vectors; i++) { |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5733 | if (smp_affinity_enable) |
| 5734 | irq_set_affinity_hint( |
| 5735 | instance->msixentry[i].vector, NULL); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5736 | free_irq(instance->msixentry[i].vector, |
| 5737 | &instance->irq_context[i]); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5738 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5739 | else |
| 5740 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
| 5741 | if (instance->msix_vectors) |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 5742 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5743 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5744 | switch (instance->pdev->device) { |
| 5745 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5746 | case PCI_DEVICE_ID_LSI_PLASMA: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 5747 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 5748 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5749 | megasas_release_fusion(instance); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5750 | for (i = 0; i < 2 ; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5751 | if (fusion->ld_map[i]) |
| 5752 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5753 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5754 | fusion->ld_map[i], |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5755 | fusion->ld_map_phys[i]); |
| 5756 | if (fusion->ld_drv_map[i]) |
| 5757 | free_pages((ulong)fusion->ld_drv_map[i], |
| 5758 | fusion->drv_map_pages); |
| 5759 | } |
| 5760 | free_pages((ulong)instance->ctrl_context, |
| 5761 | instance->ctrl_context_pages); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5762 | break; |
| 5763 | default: |
| 5764 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5765 | pci_free_consistent(pdev, sizeof(u32), |
| 5766 | instance->producer, |
| 5767 | instance->producer_h); |
| 5768 | pci_free_consistent(pdev, sizeof(u32), |
| 5769 | instance->consumer, |
| 5770 | instance->consumer_h); |
| 5771 | break; |
| 5772 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5773 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5774 | kfree(instance->ctrl_info); |
| 5775 | |
Sumit.Saxena@lsi.com | 105900d | 2013-05-22 12:30:54 +0530 | [diff] [blame] | 5776 | if (instance->evt_detail) |
| 5777 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 5778 | instance->evt_detail, instance->evt_detail_h); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 5779 | |
| 5780 | if (instance->vf_affiliation) |
| 5781 | pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) * |
| 5782 | sizeof(struct MR_LD_VF_AFFILIATION), |
| 5783 | instance->vf_affiliation, |
| 5784 | instance->vf_affiliation_h); |
| 5785 | |
| 5786 | if (instance->vf_affiliation_111) |
| 5787 | pci_free_consistent(pdev, |
| 5788 | sizeof(struct MR_LD_VF_AFFILIATION_111), |
| 5789 | instance->vf_affiliation_111, |
| 5790 | instance->vf_affiliation_111_h); |
| 5791 | |
| 5792 | if (instance->hb_host_mem) |
| 5793 | pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM), |
| 5794 | instance->hb_host_mem, |
| 5795 | instance->hb_host_mem_h); |
| 5796 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5797 | if (instance->crash_dump_buf) |
| 5798 | pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE, |
| 5799 | instance->crash_dump_buf, instance->crash_dump_h); |
| 5800 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5801 | scsi_host_put(host); |
| 5802 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5803 | pci_disable_device(pdev); |
| 5804 | |
| 5805 | return; |
| 5806 | } |
| 5807 | |
| 5808 | /** |
| 5809 | * megasas_shutdown - Shutdown entry point |
| 5810 | * @device: Generic device structure |
| 5811 | */ |
| 5812 | static void megasas_shutdown(struct pci_dev *pdev) |
| 5813 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5814 | int i; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5815 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5816 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5817 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5818 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 5819 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 5820 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5821 | if (instance->msix_vectors) |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5822 | for (i = 0; i < instance->msix_vectors; i++) { |
Sumit.Saxena@avagotech.com | ac95136 | 2014-09-12 18:57:48 +0530 | [diff] [blame] | 5823 | if (smp_affinity_enable) |
| 5824 | irq_set_affinity_hint( |
| 5825 | instance->msixentry[i].vector, NULL); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5826 | free_irq(instance->msixentry[i].vector, |
| 5827 | &instance->irq_context[i]); |
Sumit.Saxena@lsi.com | 8058a16 | 2014-03-02 05:28:11 +0530 | [diff] [blame] | 5828 | } |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 5829 | else |
| 5830 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
| 5831 | if (instance->msix_vectors) |
adam radford | 46fd256 | 2011-05-11 18:34:17 -0700 | [diff] [blame] | 5832 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | /** |
| 5836 | * megasas_mgmt_open - char node "open" entry point |
| 5837 | */ |
| 5838 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 5839 | { |
| 5840 | /* |
| 5841 | * Allow only those users with admin rights |
| 5842 | */ |
| 5843 | if (!capable(CAP_SYS_ADMIN)) |
| 5844 | return -EACCES; |
| 5845 | |
| 5846 | return 0; |
| 5847 | } |
| 5848 | |
| 5849 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5850 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 5851 | * |
| 5852 | * This function adds the calling process to a driver global queue. When an |
| 5853 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 5854 | */ |
| 5855 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 5856 | { |
| 5857 | int rc; |
| 5858 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 5859 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5860 | |
| 5861 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 5862 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 5863 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5864 | |
| 5865 | if (rc >= 0) { |
| 5866 | /* For sanity check when we get ioctl */ |
| 5867 | filep->private_data = filep; |
| 5868 | return 0; |
| 5869 | } |
| 5870 | |
| 5871 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 5872 | |
| 5873 | return rc; |
| 5874 | } |
| 5875 | |
| 5876 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5877 | * megasas_mgmt_poll - char node "poll" entry point |
| 5878 | * */ |
| 5879 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) |
| 5880 | { |
| 5881 | unsigned int mask; |
| 5882 | unsigned long flags; |
| 5883 | poll_wait(file, &megasas_poll_wait, wait); |
| 5884 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 5885 | if (megasas_poll_wait_aen) |
| 5886 | mask = (POLLIN | POLLRDNORM); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5887 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5888 | else |
| 5889 | mask = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 5890 | megasas_poll_wait_aen = 0; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5891 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 5892 | return mask; |
| 5893 | } |
| 5894 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5895 | /* |
| 5896 | * megasas_set_crash_dump_params_ioctl: |
| 5897 | * Send CRASH_DUMP_MODE DCMD to all controllers |
| 5898 | * @cmd: MFI command frame |
| 5899 | */ |
| 5900 | |
| 5901 | static int megasas_set_crash_dump_params_ioctl( |
| 5902 | struct megasas_cmd *cmd) |
| 5903 | { |
| 5904 | struct megasas_instance *local_instance; |
| 5905 | int i, error = 0; |
| 5906 | int crash_support; |
| 5907 | |
| 5908 | crash_support = cmd->frame->dcmd.mbox.w[0]; |
| 5909 | |
| 5910 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 5911 | local_instance = megasas_mgmt_info.instance[i]; |
| 5912 | if (local_instance && local_instance->crash_dump_drv_support) { |
| 5913 | if ((local_instance->adprecovery == |
| 5914 | MEGASAS_HBA_OPERATIONAL) && |
| 5915 | !megasas_set_crash_dump_params(local_instance, |
| 5916 | crash_support)) { |
| 5917 | local_instance->crash_dump_app_support = |
| 5918 | crash_support; |
| 5919 | dev_info(&local_instance->pdev->dev, |
| 5920 | "Application firmware crash " |
| 5921 | "dump mode set success\n"); |
| 5922 | error = 0; |
| 5923 | } else { |
| 5924 | dev_info(&local_instance->pdev->dev, |
| 5925 | "Application firmware crash " |
| 5926 | "dump mode set failed\n"); |
| 5927 | error = -1; |
| 5928 | } |
| 5929 | } |
| 5930 | } |
| 5931 | return error; |
| 5932 | } |
| 5933 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5934 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5935 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 5936 | * @instance: Adapter soft state |
| 5937 | * @argp: User's ioctl packet |
| 5938 | */ |
| 5939 | static int |
| 5940 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 5941 | struct megasas_iocpacket __user * user_ioc, |
| 5942 | struct megasas_iocpacket *ioc) |
| 5943 | { |
| 5944 | struct megasas_sge32 *kern_sge32; |
| 5945 | struct megasas_cmd *cmd; |
| 5946 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 5947 | dma_addr_t buf_handle = 0; |
| 5948 | int error = 0, i; |
| 5949 | void *sense = NULL; |
| 5950 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 5951 | unsigned long *sense_ptr; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5952 | |
| 5953 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 5954 | |
| 5955 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
| 5956 | printk(KERN_DEBUG "megasas: SGE count [%d] > max limit [%d]\n", |
| 5957 | ioc->sge_count, MAX_IOCTL_SGE); |
| 5958 | return -EINVAL; |
| 5959 | } |
| 5960 | |
| 5961 | cmd = megasas_get_cmd(instance); |
| 5962 | if (!cmd) { |
| 5963 | printk(KERN_DEBUG "megasas: Failed to get a cmd packet\n"); |
| 5964 | return -ENOMEM; |
| 5965 | } |
| 5966 | |
| 5967 | /* |
| 5968 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 5969 | * frames into our cmd's frames. cmd->frame's context will get |
| 5970 | * overwritten when we copy from user's frames. So set that value |
| 5971 | * alone separately |
| 5972 | */ |
| 5973 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5974 | cmd->frame->hdr.context = cpu_to_le32(cmd->index); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5975 | cmd->frame->hdr.pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 5976 | cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE | |
| 5977 | MFI_FRAME_SGL64 | |
| 5978 | MFI_FRAME_SENSE64)); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5979 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 5980 | if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) { |
| 5981 | error = megasas_set_crash_dump_params_ioctl(cmd); |
| 5982 | megasas_return_cmd(instance, cmd); |
| 5983 | return error; |
| 5984 | } |
| 5985 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5986 | /* |
| 5987 | * The management interface between applications and the fw uses |
| 5988 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 5989 | * etc are accomplishes through different kinds of MFI frames. The |
| 5990 | * driver needs to care only about substituting user buffers with |
| 5991 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 5992 | * struct iocpacket itself. |
| 5993 | */ |
| 5994 | kern_sge32 = (struct megasas_sge32 *) |
| 5995 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 5996 | |
| 5997 | /* |
| 5998 | * For each user buffer, create a mirror buffer and copy in |
| 5999 | */ |
| 6000 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 6001 | if (!ioc->sgl[i].iov_len) |
| 6002 | continue; |
| 6003 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6004 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6005 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6006 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6007 | if (!kbuff_arr[i]) { |
| 6008 | printk(KERN_DEBUG "megasas: Failed to alloc " |
| 6009 | "kernel SGL buffer for IOCTL \n"); |
| 6010 | error = -ENOMEM; |
| 6011 | goto out; |
| 6012 | } |
| 6013 | |
| 6014 | /* |
| 6015 | * We don't change the dma_coherent_mask, so |
| 6016 | * pci_alloc_consistent only returns 32bit addresses |
| 6017 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6018 | kern_sge32[i].phys_addr = cpu_to_le32(buf_handle); |
| 6019 | kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6020 | |
| 6021 | /* |
| 6022 | * We created a kernel buffer corresponding to the |
| 6023 | * user buffer. Now copy in from the user buffer |
| 6024 | */ |
| 6025 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 6026 | (u32) (ioc->sgl[i].iov_len))) { |
| 6027 | error = -EFAULT; |
| 6028 | goto out; |
| 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6033 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 6034 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6035 | if (!sense) { |
| 6036 | error = -ENOMEM; |
| 6037 | goto out; |
| 6038 | } |
| 6039 | |
| 6040 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6041 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6042 | *sense_ptr = cpu_to_le32(sense_handle); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | /* |
| 6046 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 6047 | * cmd to the SCSI mid-layer |
| 6048 | */ |
| 6049 | cmd->sync_cmd = 1; |
Sumit.Saxena@lsi.com | cfbe755 | 2014-02-12 23:36:15 +0530 | [diff] [blame] | 6050 | megasas_issue_blocked_cmd(instance, cmd, 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6051 | cmd->sync_cmd = 0; |
| 6052 | |
| 6053 | /* |
| 6054 | * copy out the kernel buffers to user buffers |
| 6055 | */ |
| 6056 | for (i = 0; i < ioc->sge_count; i++) { |
| 6057 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 6058 | ioc->sgl[i].iov_len)) { |
| 6059 | error = -EFAULT; |
| 6060 | goto out; |
| 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | /* |
| 6065 | * copy out the sense |
| 6066 | */ |
| 6067 | if (ioc->sense_len) { |
| 6068 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 6069 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6070 | * sense buffer address |
| 6071 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 6072 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 6073 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6074 | |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 6075 | if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)), |
| 6076 | sense, ioc->sense_len)) { |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 6077 | printk(KERN_ERR "megasas: Failed to copy out to user " |
| 6078 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6079 | error = -EFAULT; |
| 6080 | goto out; |
| 6081 | } |
| 6082 | } |
| 6083 | |
| 6084 | /* |
| 6085 | * copy the status codes returned by the fw |
| 6086 | */ |
| 6087 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 6088 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
| 6089 | printk(KERN_DEBUG "megasas: Error copying out cmd_status\n"); |
| 6090 | error = -EFAULT; |
| 6091 | } |
| 6092 | |
| 6093 | out: |
| 6094 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 6095 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6096 | sense, sense_handle); |
| 6097 | } |
| 6098 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 6099 | for (i = 0; i < ioc->sge_count; i++) { |
| 6100 | if (kbuff_arr[i]) |
| 6101 | dma_free_coherent(&instance->pdev->dev, |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6102 | le32_to_cpu(kern_sge32[i].length), |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 6103 | kbuff_arr[i], |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6104 | le32_to_cpu(kern_sge32[i].phys_addr)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 6105 | kbuff_arr[i] = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6106 | } |
| 6107 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 6108 | if (instance->ctrl_context && cmd->mpt_pthr_cmd_blocked) |
| 6109 | megasas_return_mfi_mpt_pthr(instance, cmd, |
| 6110 | cmd->mpt_pthr_cmd_blocked); |
| 6111 | else |
| 6112 | megasas_return_cmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6113 | return error; |
| 6114 | } |
| 6115 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6116 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 6117 | { |
| 6118 | struct megasas_iocpacket __user *user_ioc = |
| 6119 | (struct megasas_iocpacket __user *)arg; |
| 6120 | struct megasas_iocpacket *ioc; |
| 6121 | struct megasas_instance *instance; |
| 6122 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6123 | int i; |
| 6124 | unsigned long flags; |
| 6125 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6126 | |
| 6127 | ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); |
| 6128 | if (!ioc) |
| 6129 | return -ENOMEM; |
| 6130 | |
| 6131 | if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) { |
| 6132 | error = -EFAULT; |
| 6133 | goto out_kfree_ioc; |
| 6134 | } |
| 6135 | |
| 6136 | instance = megasas_lookup_instance(ioc->host_no); |
| 6137 | if (!instance) { |
| 6138 | error = -ENODEV; |
| 6139 | goto out_kfree_ioc; |
| 6140 | } |
| 6141 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6142 | /* Adjust ioctl wait time for VF mode */ |
| 6143 | if (instance->requestorId) |
| 6144 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 6145 | |
| 6146 | /* Block ioctls in VF mode */ |
| 6147 | if (instance->requestorId && !allow_vf_ioctls) { |
| 6148 | error = -ENODEV; |
| 6149 | goto out_kfree_ioc; |
| 6150 | } |
| 6151 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6152 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 6153 | printk(KERN_ERR "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6154 | error = -ENODEV; |
| 6155 | goto out_kfree_ioc; |
| 6156 | } |
| 6157 | |
| 6158 | if (instance->unload == 1) { |
| 6159 | error = -ENODEV; |
| 6160 | goto out_kfree_ioc; |
| 6161 | } |
| 6162 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6163 | /* |
| 6164 | * We will allow only MEGASAS_INT_CMDS number of parallel ioctl cmds |
| 6165 | */ |
| 6166 | if (down_interruptible(&instance->ioctl_sem)) { |
| 6167 | error = -ERESTARTSYS; |
| 6168 | goto out_kfree_ioc; |
| 6169 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6170 | |
| 6171 | for (i = 0; i < wait_time; i++) { |
| 6172 | |
| 6173 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6174 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) { |
| 6175 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6176 | break; |
| 6177 | } |
| 6178 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6179 | |
| 6180 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 6181 | printk(KERN_NOTICE "megasas: waiting" |
| 6182 | "for controller reset to finish\n"); |
| 6183 | } |
| 6184 | |
| 6185 | msleep(1000); |
| 6186 | } |
| 6187 | |
| 6188 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6189 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 6190 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6191 | |
| 6192 | printk(KERN_ERR "megaraid_sas: timed out while" |
| 6193 | "waiting for HBA to recover\n"); |
| 6194 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 6195 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6196 | } |
| 6197 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6198 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6199 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 6200 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6201 | up(&instance->ioctl_sem); |
| 6202 | |
| 6203 | out_kfree_ioc: |
| 6204 | kfree(ioc); |
| 6205 | return error; |
| 6206 | } |
| 6207 | |
| 6208 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 6209 | { |
| 6210 | struct megasas_instance *instance; |
| 6211 | struct megasas_aen aen; |
| 6212 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6213 | int i; |
| 6214 | unsigned long flags; |
| 6215 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6216 | |
| 6217 | if (file->private_data != file) { |
| 6218 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 6219 | "called first\n"); |
| 6220 | return -EINVAL; |
| 6221 | } |
| 6222 | |
| 6223 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 6224 | return -EFAULT; |
| 6225 | |
| 6226 | instance = megasas_lookup_instance(aen.host_no); |
| 6227 | |
| 6228 | if (!instance) |
| 6229 | return -ENODEV; |
| 6230 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6231 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 6232 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 6233 | } |
| 6234 | |
| 6235 | if (instance->unload == 1) { |
| 6236 | return -ENODEV; |
| 6237 | } |
| 6238 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 6239 | for (i = 0; i < wait_time; i++) { |
| 6240 | |
| 6241 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6242 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) { |
| 6243 | spin_unlock_irqrestore(&instance->hba_lock, |
| 6244 | flags); |
| 6245 | break; |
| 6246 | } |
| 6247 | |
| 6248 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6249 | |
| 6250 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 6251 | printk(KERN_NOTICE "megasas: waiting for" |
| 6252 | "controller reset to finish\n"); |
| 6253 | } |
| 6254 | |
| 6255 | msleep(1000); |
| 6256 | } |
| 6257 | |
| 6258 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 6259 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 6260 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6261 | printk(KERN_ERR "megaraid_sas: timed out while waiting" |
| 6262 | "for HBA to recover.\n"); |
| 6263 | return -ENODEV; |
| 6264 | } |
| 6265 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 6266 | |
Matthias Kaehlcke | e5a69e2 | 2007-10-27 09:48:46 +0200 | [diff] [blame] | 6267 | mutex_lock(&instance->aen_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6268 | error = megasas_register_aen(instance, aen.seq_num, |
| 6269 | aen.class_locale_word); |
Matthias Kaehlcke | e5a69e2 | 2007-10-27 09:48:46 +0200 | [diff] [blame] | 6270 | mutex_unlock(&instance->aen_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6271 | return error; |
| 6272 | } |
| 6273 | |
| 6274 | /** |
| 6275 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 6276 | */ |
| 6277 | static long |
| 6278 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 6279 | { |
| 6280 | switch (cmd) { |
| 6281 | case MEGASAS_IOC_FIRMWARE: |
| 6282 | return megasas_mgmt_ioctl_fw(file, arg); |
| 6283 | |
| 6284 | case MEGASAS_IOC_GET_AEN: |
| 6285 | return megasas_mgmt_ioctl_aen(file, arg); |
| 6286 | } |
| 6287 | |
| 6288 | return -ENOTTY; |
| 6289 | } |
| 6290 | |
| 6291 | #ifdef CONFIG_COMPAT |
| 6292 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 6293 | { |
| 6294 | struct compat_megasas_iocpacket __user *cioc = |
| 6295 | (struct compat_megasas_iocpacket __user *)arg; |
| 6296 | struct megasas_iocpacket __user *ioc = |
| 6297 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 6298 | int i; |
| 6299 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6300 | compat_uptr_t ptr; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6301 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6302 | if (clear_user(ioc, sizeof(*ioc))) |
| 6303 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6304 | |
| 6305 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 6306 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 6307 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 6308 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 6309 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 6310 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 6311 | return -EFAULT; |
| 6312 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6313 | /* |
| 6314 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 6315 | * sense_len is not null, so prepare the 64bit value under |
| 6316 | * the same condition. |
| 6317 | */ |
| 6318 | if (ioc->sense_len) { |
| 6319 | void __user **sense_ioc_ptr = |
| 6320 | (void __user **)(ioc->frame.raw + ioc->sense_off); |
| 6321 | compat_uptr_t *sense_cioc_ptr = |
| 6322 | (compat_uptr_t *)(cioc->frame.raw + cioc->sense_off); |
| 6323 | if (get_user(ptr, sense_cioc_ptr) || |
| 6324 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 6325 | return -EFAULT; |
| 6326 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6327 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 6328 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6329 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 6330 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 6331 | copy_in_user(&ioc->sgl[i].iov_len, |
| 6332 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 6333 | return -EFAULT; |
| 6334 | } |
| 6335 | |
| 6336 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 6337 | |
| 6338 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 6339 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 6340 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 6341 | return -EFAULT; |
| 6342 | } |
| 6343 | return error; |
| 6344 | } |
| 6345 | |
| 6346 | static long |
| 6347 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 6348 | unsigned long arg) |
| 6349 | { |
| 6350 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 6351 | case MEGASAS_IOC_FIRMWARE32: |
| 6352 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6353 | case MEGASAS_IOC_GET_AEN: |
| 6354 | return megasas_mgmt_ioctl_aen(file, arg); |
| 6355 | } |
| 6356 | |
| 6357 | return -ENOTTY; |
| 6358 | } |
| 6359 | #endif |
| 6360 | |
| 6361 | /* |
| 6362 | * File operations structure for management interface |
| 6363 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 6364 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6365 | .owner = THIS_MODULE, |
| 6366 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6367 | .fasync = megasas_mgmt_fasync, |
| 6368 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 6369 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6370 | #ifdef CONFIG_COMPAT |
| 6371 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 6372 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 6373 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6374 | }; |
| 6375 | |
| 6376 | /* |
| 6377 | * PCI hotplug support registration structure |
| 6378 | */ |
| 6379 | static struct pci_driver megasas_pci_driver = { |
| 6380 | |
| 6381 | .name = "megaraid_sas", |
| 6382 | .id_table = megasas_pci_table, |
| 6383 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 6384 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 6385 | .suspend = megasas_suspend, |
| 6386 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6387 | .shutdown = megasas_shutdown, |
| 6388 | }; |
| 6389 | |
| 6390 | /* |
| 6391 | * Sysfs driver attributes |
| 6392 | */ |
| 6393 | static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf) |
| 6394 | { |
| 6395 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 6396 | MEGASAS_VERSION); |
| 6397 | } |
| 6398 | |
| 6399 | static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); |
| 6400 | |
| 6401 | static ssize_t |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6402 | megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf) |
| 6403 | { |
| 6404 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 6405 | } |
| 6406 | |
| 6407 | static DRIVER_ATTR(support_poll_for_event, S_IRUGO, |
| 6408 | megasas_sysfs_show_support_poll_for_event, NULL); |
| 6409 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 6410 | static ssize_t |
| 6411 | megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf) |
| 6412 | { |
| 6413 | return sprintf(buf, "%u\n", support_device_change); |
| 6414 | } |
| 6415 | |
| 6416 | static DRIVER_ATTR(support_device_change, S_IRUGO, |
| 6417 | megasas_sysfs_show_support_device_change, NULL); |
| 6418 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6419 | static ssize_t |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6420 | megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf) |
| 6421 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6422 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | static ssize_t |
| 6426 | megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count) |
| 6427 | { |
| 6428 | int retval = count; |
| 6429 | if(sscanf(buf,"%u",&megasas_dbg_lvl)<1){ |
| 6430 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 6431 | retval = -EINVAL; |
| 6432 | } |
| 6433 | return retval; |
| 6434 | } |
| 6435 | |
Joe Malicki | 66dca9b | 2008-08-14 17:14:48 -0400 | [diff] [blame] | 6436 | static DRIVER_ATTR(dbg_lvl, S_IRUGO|S_IWUSR, megasas_sysfs_show_dbg_lvl, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6437 | megasas_sysfs_set_dbg_lvl); |
| 6438 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6439 | static void |
| 6440 | megasas_aen_polling(struct work_struct *work) |
| 6441 | { |
| 6442 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 6443 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6444 | struct megasas_instance *instance = ev->instance; |
| 6445 | union megasas_evt_class_locale class_locale; |
| 6446 | struct Scsi_Host *host; |
| 6447 | struct scsi_device *sdev1; |
| 6448 | u16 pd_index = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6449 | u16 ld_index = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6450 | int i, j, doscan = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6451 | u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6452 | int error; |
| 6453 | |
| 6454 | if (!instance) { |
| 6455 | printk(KERN_ERR "invalid instance!\n"); |
| 6456 | kfree(ev); |
| 6457 | return; |
| 6458 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6459 | |
| 6460 | /* Adjust event workqueue thread wait time for VF mode */ |
| 6461 | if (instance->requestorId) |
| 6462 | wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF; |
| 6463 | |
| 6464 | /* Don't run the event workqueue thread if OCR is running */ |
| 6465 | for (i = 0; i < wait_time; i++) { |
| 6466 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) |
| 6467 | break; |
| 6468 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 6469 | printk(KERN_NOTICE "megasas: %s waiting for " |
| 6470 | "controller reset to finish for scsi%d\n", |
| 6471 | __func__, instance->host->host_no); |
| 6472 | } |
| 6473 | msleep(1000); |
| 6474 | } |
| 6475 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6476 | instance->ev = NULL; |
| 6477 | host = instance->host; |
| 6478 | if (instance->evt_detail) { |
| 6479 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6480 | switch (le32_to_cpu(instance->evt_detail->code)) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6481 | case MR_EVT_PD_INSERTED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6482 | if (megasas_get_pd_list(instance) == 0) { |
| 6483 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 6484 | for (j = 0; |
| 6485 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6486 | j++) { |
| 6487 | |
| 6488 | pd_index = |
| 6489 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 6490 | |
| 6491 | sdev1 = |
| 6492 | scsi_device_lookup(host, i, j, 0); |
| 6493 | |
| 6494 | if (instance->pd_list[pd_index].driveState |
| 6495 | == MR_PD_STATE_SYSTEM) { |
| 6496 | if (!sdev1) { |
| 6497 | scsi_add_device(host, i, j, 0); |
| 6498 | } |
| 6499 | |
| 6500 | if (sdev1) |
| 6501 | scsi_device_put(sdev1); |
| 6502 | } |
| 6503 | } |
| 6504 | } |
| 6505 | } |
| 6506 | doscan = 0; |
| 6507 | break; |
| 6508 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6509 | case MR_EVT_PD_REMOVED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6510 | if (megasas_get_pd_list(instance) == 0) { |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6511 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 6512 | for (j = 0; |
| 6513 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6514 | j++) { |
| 6515 | |
| 6516 | pd_index = |
| 6517 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 6518 | |
| 6519 | sdev1 = |
| 6520 | scsi_device_lookup(host, i, j, 0); |
| 6521 | |
| 6522 | if (instance->pd_list[pd_index].driveState |
| 6523 | == MR_PD_STATE_SYSTEM) { |
| 6524 | if (sdev1) { |
| 6525 | scsi_device_put(sdev1); |
| 6526 | } |
| 6527 | } else { |
| 6528 | if (sdev1) { |
| 6529 | scsi_remove_device(sdev1); |
| 6530 | scsi_device_put(sdev1); |
| 6531 | } |
| 6532 | } |
| 6533 | } |
| 6534 | } |
| 6535 | } |
| 6536 | doscan = 0; |
| 6537 | break; |
| 6538 | |
| 6539 | case MR_EVT_LD_OFFLINE: |
adam radford | 4c598b2 | 2011-02-24 20:56:53 -0800 | [diff] [blame] | 6540 | case MR_EVT_CFG_CLEARED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6541 | case MR_EVT_LD_DELETED: |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6542 | if (!instance->requestorId || |
| 6543 | (instance->requestorId && |
| 6544 | megasas_get_ld_vf_affiliation(instance, 0))) { |
| 6545 | if (megasas_ld_list_query(instance, |
| 6546 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
| 6547 | megasas_get_ld_list(instance); |
| 6548 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 6549 | for (j = 0; |
| 6550 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6551 | j++) { |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6552 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6553 | ld_index = |
| 6554 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6555 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6556 | sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6557 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6558 | if (instance->ld_ids[ld_index] |
| 6559 | != 0xff) { |
| 6560 | if (sdev1) |
| 6561 | scsi_device_put(sdev1); |
| 6562 | } else { |
| 6563 | if (sdev1) { |
| 6564 | scsi_remove_device(sdev1); |
| 6565 | scsi_device_put(sdev1); |
| 6566 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6567 | } |
| 6568 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6569 | } |
| 6570 | doscan = 0; |
| 6571 | } |
| 6572 | break; |
| 6573 | case MR_EVT_LD_CREATED: |
| 6574 | if (!instance->requestorId || |
| 6575 | (instance->requestorId && |
| 6576 | megasas_get_ld_vf_affiliation(instance, 0))) { |
| 6577 | if (megasas_ld_list_query(instance, |
| 6578 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
| 6579 | megasas_get_ld_list(instance); |
| 6580 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 6581 | for (j = 0; |
| 6582 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6583 | j++) { |
| 6584 | ld_index = |
| 6585 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 6586 | |
| 6587 | sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 6588 | |
| 6589 | if (instance->ld_ids[ld_index] |
| 6590 | != 0xff) { |
| 6591 | if (!sdev1) |
| 6592 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 6593 | } |
| 6594 | if (sdev1) |
| 6595 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6596 | } |
| 6597 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6598 | doscan = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6599 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6600 | break; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6601 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6602 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6603 | case MR_EVT_LD_STATE_CHANGE: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6604 | doscan = 1; |
| 6605 | break; |
| 6606 | default: |
| 6607 | doscan = 0; |
| 6608 | break; |
| 6609 | } |
| 6610 | } else { |
| 6611 | printk(KERN_ERR "invalid evt_detail!\n"); |
| 6612 | kfree(ev); |
| 6613 | return; |
| 6614 | } |
| 6615 | |
| 6616 | if (doscan) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6617 | printk(KERN_INFO "megaraid_sas: scanning for scsi%d...\n", |
| 6618 | instance->host->host_no); |
Hannes Reinecke | 58968fc | 2014-01-16 11:25:36 +0100 | [diff] [blame] | 6619 | if (megasas_get_pd_list(instance) == 0) { |
| 6620 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 6621 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 6622 | pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j; |
| 6623 | sdev1 = scsi_device_lookup(host, i, j, 0); |
| 6624 | if (instance->pd_list[pd_index].driveState == |
| 6625 | MR_PD_STATE_SYSTEM) { |
| 6626 | if (!sdev1) { |
| 6627 | scsi_add_device(host, i, j, 0); |
| 6628 | } |
| 6629 | if (sdev1) |
| 6630 | scsi_device_put(sdev1); |
| 6631 | } else { |
| 6632 | if (sdev1) { |
| 6633 | scsi_remove_device(sdev1); |
| 6634 | scsi_device_put(sdev1); |
| 6635 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6636 | } |
| 6637 | } |
| 6638 | } |
| 6639 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6640 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6641 | if (!instance->requestorId || |
| 6642 | (instance->requestorId && |
| 6643 | megasas_get_ld_vf_affiliation(instance, 0))) { |
| 6644 | if (megasas_ld_list_query(instance, |
| 6645 | MR_LD_QUERY_TYPE_EXPOSED_TO_HOST)) |
| 6646 | megasas_get_ld_list(instance); |
| 6647 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 6648 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 6649 | j++) { |
| 6650 | ld_index = |
| 6651 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6652 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6653 | sdev1 = scsi_device_lookup(host, |
| 6654 | MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 6655 | if (instance->ld_ids[ld_index] |
| 6656 | != 0xff) { |
| 6657 | if (!sdev1) |
| 6658 | scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0); |
| 6659 | else |
| 6660 | scsi_device_put(sdev1); |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6661 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 6662 | if (sdev1) { |
| 6663 | scsi_remove_device(sdev1); |
| 6664 | scsi_device_put(sdev1); |
| 6665 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 6666 | } |
| 6667 | } |
| 6668 | } |
| 6669 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | if ( instance->aen_cmd != NULL ) { |
| 6673 | kfree(ev); |
| 6674 | return ; |
| 6675 | } |
| 6676 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 6677 | seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 6678 | |
| 6679 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 6680 | class_locale.members.reserved = 0; |
| 6681 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 6682 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 6683 | mutex_lock(&instance->aen_mutex); |
| 6684 | error = megasas_register_aen(instance, seq_num, |
| 6685 | class_locale.word); |
| 6686 | mutex_unlock(&instance->aen_mutex); |
| 6687 | |
| 6688 | if (error) |
| 6689 | printk(KERN_ERR "register aen failed error %x\n", error); |
| 6690 | |
| 6691 | kfree(ev); |
| 6692 | } |
| 6693 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6694 | /** |
| 6695 | * megasas_init - Driver load entry point |
| 6696 | */ |
| 6697 | static int __init megasas_init(void) |
| 6698 | { |
| 6699 | int rval; |
| 6700 | |
| 6701 | /* |
| 6702 | * Announce driver version and other information |
| 6703 | */ |
Sumit.Saxena@avagotech.com | d98a6de | 2014-11-17 15:23:58 +0530 | [diff] [blame^] | 6704 | pr_info("megasas: %s\n", MEGASAS_VERSION); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6705 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 6706 | spin_lock_init(&poll_aen_lock); |
| 6707 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6708 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 6709 | support_device_change = 1; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6710 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6711 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 6712 | |
| 6713 | /* |
| 6714 | * Register character device node |
| 6715 | */ |
| 6716 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 6717 | |
| 6718 | if (rval < 0) { |
| 6719 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 6720 | return rval; |
| 6721 | } |
| 6722 | |
| 6723 | megasas_mgmt_majorno = rval; |
| 6724 | |
| 6725 | /* |
| 6726 | * Register ourselves as PCI hotplug module |
| 6727 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 6728 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6729 | |
| 6730 | if (rval) { |
| 6731 | printk(KERN_DEBUG "megasas: PCI hotplug regisration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6732 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6733 | } |
| 6734 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6735 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 6736 | &driver_attr_version); |
| 6737 | if (rval) |
| 6738 | goto err_dcf_attr_ver; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6739 | |
| 6740 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 6741 | &driver_attr_support_poll_for_event); |
| 6742 | if (rval) |
| 6743 | goto err_dcf_support_poll_for_event; |
| 6744 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6745 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 6746 | &driver_attr_dbg_lvl); |
| 6747 | if (rval) |
| 6748 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6749 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 6750 | &driver_attr_support_device_change); |
| 6751 | if (rval) |
| 6752 | goto err_dcf_support_device_change; |
| 6753 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6754 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6755 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 6756 | err_dcf_support_device_change: |
| 6757 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 6758 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6759 | err_dcf_dbg_lvl: |
| 6760 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6761 | &driver_attr_support_poll_for_event); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 6762 | err_dcf_support_poll_for_event: |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6763 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 6764 | err_dcf_attr_ver: |
| 6765 | pci_unregister_driver(&megasas_pci_driver); |
| 6766 | err_pcidrv: |
| 6767 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 6768 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | /** |
| 6772 | * megasas_exit - Driver unload entry point |
| 6773 | */ |
| 6774 | static void __exit megasas_exit(void) |
| 6775 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 6776 | driver_remove_file(&megasas_pci_driver.driver, |
| 6777 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6778 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 6779 | &driver_attr_support_poll_for_event); |
| 6780 | driver_remove_file(&megasas_pci_driver.driver, |
| 6781 | &driver_attr_support_device_change); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 6782 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 6783 | |
| 6784 | pci_unregister_driver(&megasas_pci_driver); |
| 6785 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 6786 | } |
| 6787 | |
| 6788 | module_init(megasas_init); |
| 6789 | module_exit(megasas_exit); |