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@lsi.com | 7525be5 | 2013-05-22 12:36:17 +0530 | [diff] [blame] | 21 | * Version : 06.600.18.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 | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 78 | static int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 79 | module_param(throttlequeuedepth, int, S_IRUGO); |
| 80 | MODULE_PARM_DESC(throttlequeuedepth, |
| 81 | "Adapter queue depth when throttled due to I/O timeout. Default: 16"); |
| 82 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 83 | int resetwaittime = MEGASAS_RESET_WAIT_TIME; |
| 84 | module_param(resetwaittime, int, S_IRUGO); |
| 85 | MODULE_PARM_DESC(resetwaittime, "Wait time in seconds after I/O timeout " |
| 86 | "before resetting adapter. Default: 180"); |
| 87 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 88 | MODULE_LICENSE("GPL"); |
| 89 | MODULE_VERSION(MEGASAS_VERSION); |
Sumant Patro | 3d6d174 | 2006-12-29 08:13:54 -0800 | [diff] [blame] | 90 | MODULE_AUTHOR("megaraidlinux@lsi.com"); |
bo yang | f28cd7c | 2007-11-09 04:44:56 -0500 | [diff] [blame] | 91 | MODULE_DESCRIPTION("LSI MegaRAID SAS Driver"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 92 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 93 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 94 | static int megasas_get_pd_list(struct megasas_instance *instance); |
| 95 | static int megasas_issue_init_mfi(struct megasas_instance *instance); |
| 96 | static int megasas_register_aen(struct megasas_instance *instance, |
| 97 | u32 seq_num, u32 class_locale_word); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 98 | /* |
| 99 | * PCI ID table for all supported controllers |
| 100 | */ |
| 101 | static struct pci_device_id megasas_pci_table[] = { |
| 102 | |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 103 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)}, |
| 104 | /* xscale IOP */ |
| 105 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)}, |
| 106 | /* ppc IOP */ |
bo yang | af7a564 | 2008-03-17 04:13:07 -0400 | [diff] [blame] | 107 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)}, |
| 108 | /* ppc IOP */ |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 109 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)}, |
| 110 | /* gen2*/ |
| 111 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)}, |
| 112 | /* gen2*/ |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 113 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)}, |
| 114 | /* skinny*/ |
| 115 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)}, |
| 116 | /* skinny*/ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 117 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)}, |
| 118 | /* xscale IOP, vega */ |
| 119 | {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)}, |
| 120 | /* xscale IOP */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 121 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)}, |
| 122 | /* Fusion */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 123 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)}, |
| 124 | /* Invader */ |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 125 | {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)}, |
| 126 | /* Fury */ |
Henrik Kretzschmar | f3d7271 | 2006-08-15 11:17:21 +0200 | [diff] [blame] | 127 | {} |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | MODULE_DEVICE_TABLE(pci, megasas_pci_table); |
| 131 | |
| 132 | static int megasas_mgmt_majorno; |
| 133 | static struct megasas_mgmt_info megasas_mgmt_info; |
| 134 | static struct fasync_struct *megasas_async_queue; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 135 | static DEFINE_MUTEX(megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 136 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 137 | static int megasas_poll_wait_aen; |
| 138 | static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 139 | static u32 support_poll_for_event; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 140 | u32 megasas_dbg_lvl; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 141 | static u32 support_device_change; |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 142 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 143 | /* define lock for aen poll */ |
| 144 | spinlock_t poll_aen_lock; |
| 145 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 146 | void |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 147 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 148 | u8 alt_status); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 149 | static u32 |
| 150 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs); |
| 151 | static int |
| 152 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 153 | struct megasas_register_set __iomem *reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 154 | static irqreturn_t megasas_isr(int irq, void *devp); |
| 155 | static u32 |
| 156 | megasas_init_adapter_mfi(struct megasas_instance *instance); |
| 157 | u32 |
| 158 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 159 | struct scsi_cmnd *scmd); |
| 160 | static void megasas_complete_cmd_dpc(unsigned long instance_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 161 | void |
| 162 | megasas_release_fusion(struct megasas_instance *instance); |
| 163 | int |
| 164 | megasas_ioc_init_fusion(struct megasas_instance *instance); |
| 165 | void |
| 166 | megasas_free_cmds_fusion(struct megasas_instance *instance); |
| 167 | u8 |
| 168 | megasas_get_map_info(struct megasas_instance *instance); |
| 169 | int |
| 170 | megasas_sync_map_info(struct megasas_instance *instance); |
| 171 | int |
| 172 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd); |
| 173 | void megasas_reset_reply_desc(struct megasas_instance *instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 174 | int megasas_reset_fusion(struct Scsi_Host *shost); |
| 175 | void megasas_fusion_ocr_wq(struct work_struct *work); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 176 | |
| 177 | void |
| 178 | megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 179 | { |
| 180 | instance->instancet->fire_cmd(instance, |
| 181 | cmd->frame_phys_addr, 0, instance->reg_set); |
| 182 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 183 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 184 | /** |
| 185 | * megasas_get_cmd - Get a command from the free pool |
| 186 | * @instance: Adapter soft state |
| 187 | * |
| 188 | * Returns a free command from the pool |
| 189 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 190 | struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 191 | *instance) |
| 192 | { |
| 193 | unsigned long flags; |
| 194 | struct megasas_cmd *cmd = NULL; |
| 195 | |
| 196 | spin_lock_irqsave(&instance->cmd_pool_lock, flags); |
| 197 | |
| 198 | if (!list_empty(&instance->cmd_pool)) { |
| 199 | cmd = list_entry((&instance->cmd_pool)->next, |
| 200 | struct megasas_cmd, list); |
| 201 | list_del_init(&cmd->list); |
| 202 | } else { |
| 203 | printk(KERN_ERR "megasas: Command pool empty!\n"); |
| 204 | } |
| 205 | |
| 206 | spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); |
| 207 | return cmd; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * megasas_return_cmd - Return a cmd to free command pool |
| 212 | * @instance: Adapter soft state |
| 213 | * @cmd: Command packet to be returned to free command pool |
| 214 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 215 | inline void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 216 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 217 | { |
| 218 | unsigned long flags; |
| 219 | |
| 220 | spin_lock_irqsave(&instance->cmd_pool_lock, flags); |
| 221 | |
| 222 | cmd->scmd = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 223 | cmd->frame_count = 0; |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 224 | if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) && |
| 225 | (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) && |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 226 | (instance->pdev->device != PCI_DEVICE_ID_LSI_FURY) && |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 227 | (reset_devices)) |
| 228 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 229 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 230 | |
| 231 | spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); |
| 232 | } |
| 233 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 234 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 235 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 236 | * The following functions are defined for xscale |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 237 | * (deviceid : 1064R, PERC5) controllers |
| 238 | */ |
| 239 | |
| 240 | /** |
| 241 | * megasas_enable_intr_xscale - Enables interrupts |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 242 | * @regs: MFI register set |
| 243 | */ |
| 244 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 245 | megasas_enable_intr_xscale(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 246 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 247 | struct megasas_register_set __iomem *regs; |
| 248 | regs = instance->reg_set; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 249 | writel(0, &(regs)->outbound_intr_mask); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 250 | |
| 251 | /* Dummy readl to force pci flush */ |
| 252 | readl(®s->outbound_intr_mask); |
| 253 | } |
| 254 | |
| 255 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 256 | * megasas_disable_intr_xscale -Disables interrupt |
| 257 | * @regs: MFI register set |
| 258 | */ |
| 259 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 260 | megasas_disable_intr_xscale(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 261 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 262 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 263 | u32 mask = 0x1f; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 264 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 265 | writel(mask, ®s->outbound_intr_mask); |
| 266 | /* Dummy readl to force pci flush */ |
| 267 | readl(®s->outbound_intr_mask); |
| 268 | } |
| 269 | |
| 270 | /** |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 271 | * megasas_read_fw_status_reg_xscale - returns the current FW status value |
| 272 | * @regs: MFI register set |
| 273 | */ |
| 274 | static u32 |
| 275 | megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs) |
| 276 | { |
| 277 | return readl(&(regs)->outbound_msg_0); |
| 278 | } |
| 279 | /** |
| 280 | * megasas_clear_interrupt_xscale - Check & clear interrupt |
| 281 | * @regs: MFI register set |
| 282 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 283 | static int |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 284 | megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs) |
| 285 | { |
| 286 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 287 | u32 mfiStatus = 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 288 | /* |
| 289 | * Check if it is our interrupt |
| 290 | */ |
| 291 | status = readl(®s->outbound_intr_status); |
| 292 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 293 | if (status & MFI_OB_INTR_STATUS_MASK) |
| 294 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 295 | if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT) |
| 296 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 297 | |
| 298 | /* |
| 299 | * Clear the interrupt by writing back the same value |
| 300 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 301 | if (mfiStatus) |
| 302 | writel(status, ®s->outbound_intr_status); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 303 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 304 | /* Dummy readl to force pci flush */ |
| 305 | readl(®s->outbound_intr_status); |
| 306 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 307 | return mfiStatus; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * megasas_fire_cmd_xscale - Sends command to the FW |
| 312 | * @frame_phys_addr : Physical address of cmd |
| 313 | * @frame_count : Number of frames for the command |
| 314 | * @regs : MFI register set |
| 315 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 316 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 317 | megasas_fire_cmd_xscale(struct megasas_instance *instance, |
| 318 | dma_addr_t frame_phys_addr, |
| 319 | u32 frame_count, |
| 320 | struct megasas_register_set __iomem *regs) |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 321 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 322 | unsigned long flags; |
| 323 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 324 | writel((frame_phys_addr >> 3)|(frame_count), |
| 325 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 326 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * megasas_adp_reset_xscale - For controller reset |
| 331 | * @regs: MFI register set |
| 332 | */ |
| 333 | static int |
| 334 | megasas_adp_reset_xscale(struct megasas_instance *instance, |
| 335 | struct megasas_register_set __iomem *regs) |
| 336 | { |
| 337 | u32 i; |
| 338 | u32 pcidata; |
| 339 | writel(MFI_ADP_RESET, ®s->inbound_doorbell); |
| 340 | |
| 341 | for (i = 0; i < 3; i++) |
| 342 | msleep(1000); /* sleep for 3 secs */ |
| 343 | pcidata = 0; |
| 344 | pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata); |
| 345 | printk(KERN_NOTICE "pcidata = %x\n", pcidata); |
| 346 | if (pcidata & 0x2) { |
| 347 | printk(KERN_NOTICE "mfi 1068 offset read=%x\n", pcidata); |
| 348 | pcidata &= ~0x2; |
| 349 | pci_write_config_dword(instance->pdev, |
| 350 | MFI_1068_PCSR_OFFSET, pcidata); |
| 351 | |
| 352 | for (i = 0; i < 2; i++) |
| 353 | msleep(1000); /* need to wait 2 secs again */ |
| 354 | |
| 355 | pcidata = 0; |
| 356 | pci_read_config_dword(instance->pdev, |
| 357 | MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata); |
| 358 | printk(KERN_NOTICE "1068 offset handshake read=%x\n", pcidata); |
| 359 | if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) { |
| 360 | printk(KERN_NOTICE "1068 offset pcidt=%x\n", pcidata); |
| 361 | pcidata = 0; |
| 362 | pci_write_config_dword(instance->pdev, |
| 363 | MFI_1068_FW_HANDSHAKE_OFFSET, pcidata); |
| 364 | } |
| 365 | } |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * megasas_check_reset_xscale - For controller reset check |
| 371 | * @regs: MFI register set |
| 372 | */ |
| 373 | static int |
| 374 | megasas_check_reset_xscale(struct megasas_instance *instance, |
| 375 | struct megasas_register_set __iomem *regs) |
| 376 | { |
| 377 | u32 consumer; |
| 378 | consumer = *instance->consumer; |
| 379 | |
| 380 | if ((instance->adprecovery != MEGASAS_HBA_OPERATIONAL) && |
| 381 | (*instance->consumer == MEGASAS_ADPRESET_INPROG_SIGN)) { |
| 382 | return 1; |
| 383 | } |
| 384 | return 0; |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | static struct megasas_instance_template megasas_instance_template_xscale = { |
| 388 | |
| 389 | .fire_cmd = megasas_fire_cmd_xscale, |
| 390 | .enable_intr = megasas_enable_intr_xscale, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 391 | .disable_intr = megasas_disable_intr_xscale, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 392 | .clear_intr = megasas_clear_intr_xscale, |
| 393 | .read_fw_status_reg = megasas_read_fw_status_reg_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 394 | .adp_reset = megasas_adp_reset_xscale, |
| 395 | .check_reset = megasas_check_reset_xscale, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 396 | .service_isr = megasas_isr, |
| 397 | .tasklet = megasas_complete_cmd_dpc, |
| 398 | .init_adapter = megasas_init_adapter_mfi, |
| 399 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 400 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 404 | * This is the end of set of functions & definitions specific |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 405 | * to xscale (deviceid : 1064R, PERC5) controllers |
| 406 | */ |
| 407 | |
| 408 | /** |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 409 | * The following functions are defined for ppc (deviceid : 0x60) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 410 | * controllers |
| 411 | */ |
| 412 | |
| 413 | /** |
| 414 | * megasas_enable_intr_ppc - Enables interrupts |
| 415 | * @regs: MFI register set |
| 416 | */ |
| 417 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 418 | megasas_enable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 419 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 420 | struct megasas_register_set __iomem *regs; |
| 421 | regs = instance->reg_set; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 422 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 423 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 424 | writel(~0x80000000, &(regs)->outbound_intr_mask); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 425 | |
| 426 | /* Dummy readl to force pci flush */ |
| 427 | readl(®s->outbound_intr_mask); |
| 428 | } |
| 429 | |
| 430 | /** |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 431 | * megasas_disable_intr_ppc - Disable interrupt |
| 432 | * @regs: MFI register set |
| 433 | */ |
| 434 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 435 | megasas_disable_intr_ppc(struct megasas_instance *instance) |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 436 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 437 | struct megasas_register_set __iomem *regs; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 438 | u32 mask = 0xFFFFFFFF; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 439 | regs = instance->reg_set; |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 440 | writel(mask, ®s->outbound_intr_mask); |
| 441 | /* Dummy readl to force pci flush */ |
| 442 | readl(®s->outbound_intr_mask); |
| 443 | } |
| 444 | |
| 445 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 446 | * megasas_read_fw_status_reg_ppc - returns the current FW status value |
| 447 | * @regs: MFI register set |
| 448 | */ |
| 449 | static u32 |
| 450 | megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs) |
| 451 | { |
| 452 | return readl(&(regs)->outbound_scratch_pad); |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * megasas_clear_interrupt_ppc - Check & clear interrupt |
| 457 | * @regs: MFI register set |
| 458 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 459 | static int |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 460 | megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs) |
| 461 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 462 | u32 status, mfiStatus = 0; |
| 463 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 464 | /* |
| 465 | * Check if it is our interrupt |
| 466 | */ |
| 467 | status = readl(®s->outbound_intr_status); |
| 468 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 469 | if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT) |
| 470 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 471 | |
| 472 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) |
| 473 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 474 | |
| 475 | /* |
| 476 | * Clear the interrupt by writing back the same value |
| 477 | */ |
| 478 | writel(status, ®s->outbound_doorbell_clear); |
| 479 | |
Yang, Bo | 06f579d | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 480 | /* Dummy readl to force pci flush */ |
| 481 | readl(®s->outbound_doorbell_clear); |
| 482 | |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 483 | return mfiStatus; |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 484 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 485 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 486 | /** |
| 487 | * megasas_fire_cmd_ppc - Sends command to the FW |
| 488 | * @frame_phys_addr : Physical address of cmd |
| 489 | * @frame_count : Number of frames for the command |
| 490 | * @regs : MFI register set |
| 491 | */ |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 492 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 493 | megasas_fire_cmd_ppc(struct megasas_instance *instance, |
| 494 | dma_addr_t frame_phys_addr, |
| 495 | u32 frame_count, |
| 496 | struct megasas_register_set __iomem *regs) |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 497 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 498 | unsigned long flags; |
| 499 | spin_lock_irqsave(&instance->hba_lock, flags); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 500 | writel((frame_phys_addr | (frame_count<<1))|1, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 501 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 502 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 503 | } |
| 504 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 505 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 506 | * megasas_check_reset_ppc - For controller reset check |
| 507 | * @regs: MFI register set |
| 508 | */ |
| 509 | static int |
| 510 | megasas_check_reset_ppc(struct megasas_instance *instance, |
| 511 | struct megasas_register_set __iomem *regs) |
| 512 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 513 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) |
| 514 | return 1; |
| 515 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 516 | return 0; |
| 517 | } |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 518 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 519 | static struct megasas_instance_template megasas_instance_template_ppc = { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 520 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 521 | .fire_cmd = megasas_fire_cmd_ppc, |
| 522 | .enable_intr = megasas_enable_intr_ppc, |
Sumant Patro | b274cab | 2006-10-03 12:52:12 -0700 | [diff] [blame] | 523 | .disable_intr = megasas_disable_intr_ppc, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 524 | .clear_intr = megasas_clear_intr_ppc, |
| 525 | .read_fw_status_reg = megasas_read_fw_status_reg_ppc, |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 526 | .adp_reset = megasas_adp_reset_xscale, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 527 | .check_reset = megasas_check_reset_ppc, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 528 | .service_isr = megasas_isr, |
| 529 | .tasklet = megasas_complete_cmd_dpc, |
| 530 | .init_adapter = megasas_init_adapter_mfi, |
| 531 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 532 | .issue_dcmd = megasas_issue_dcmd, |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 533 | }; |
| 534 | |
| 535 | /** |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 536 | * megasas_enable_intr_skinny - Enables interrupts |
| 537 | * @regs: MFI register set |
| 538 | */ |
| 539 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 540 | megasas_enable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 541 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 542 | struct megasas_register_set __iomem *regs; |
| 543 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 544 | writel(0xFFFFFFFF, &(regs)->outbound_intr_mask); |
| 545 | |
| 546 | writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 547 | |
| 548 | /* Dummy readl to force pci flush */ |
| 549 | readl(®s->outbound_intr_mask); |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * megasas_disable_intr_skinny - Disables interrupt |
| 554 | * @regs: MFI register set |
| 555 | */ |
| 556 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 557 | megasas_disable_intr_skinny(struct megasas_instance *instance) |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 558 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 559 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 560 | u32 mask = 0xFFFFFFFF; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 561 | regs = instance->reg_set; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 562 | writel(mask, ®s->outbound_intr_mask); |
| 563 | /* Dummy readl to force pci flush */ |
| 564 | readl(®s->outbound_intr_mask); |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * megasas_read_fw_status_reg_skinny - returns the current FW status value |
| 569 | * @regs: MFI register set |
| 570 | */ |
| 571 | static u32 |
| 572 | megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs) |
| 573 | { |
| 574 | return readl(&(regs)->outbound_scratch_pad); |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * megasas_clear_interrupt_skinny - Check & clear interrupt |
| 579 | * @regs: MFI register set |
| 580 | */ |
| 581 | static int |
| 582 | megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs) |
| 583 | { |
| 584 | u32 status; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 585 | u32 mfiStatus = 0; |
| 586 | |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 587 | /* |
| 588 | * Check if it is our interrupt |
| 589 | */ |
| 590 | status = readl(®s->outbound_intr_status); |
| 591 | |
| 592 | if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 593 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /* |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 597 | * Check if it is our interrupt |
| 598 | */ |
James Georgas | a3fda7d | 2013-06-26 12:03:19 -0600 | [diff] [blame] | 599 | if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) == |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 600 | MFI_STATE_FAULT) { |
| 601 | mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 602 | } else |
| 603 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 604 | |
| 605 | /* |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 606 | * Clear the interrupt by writing back the same value |
| 607 | */ |
| 608 | writel(status, ®s->outbound_intr_status); |
| 609 | |
| 610 | /* |
| 611 | * dummy read to flush PCI |
| 612 | */ |
| 613 | readl(®s->outbound_intr_status); |
| 614 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 615 | return mfiStatus; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /** |
| 619 | * megasas_fire_cmd_skinny - Sends command to the FW |
| 620 | * @frame_phys_addr : Physical address of cmd |
| 621 | * @frame_count : Number of frames for the command |
| 622 | * @regs : MFI register set |
| 623 | */ |
| 624 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 625 | megasas_fire_cmd_skinny(struct megasas_instance *instance, |
| 626 | dma_addr_t frame_phys_addr, |
| 627 | u32 frame_count, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 628 | struct megasas_register_set __iomem *regs) |
| 629 | { |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 630 | unsigned long flags; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 631 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 632 | writel(0, &(regs)->inbound_high_queue_port); |
| 633 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 634 | &(regs)->inbound_low_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 635 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 636 | } |
| 637 | |
| 638 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 639 | * megasas_check_reset_skinny - For controller reset check |
| 640 | * @regs: MFI register set |
| 641 | */ |
| 642 | static int |
| 643 | megasas_check_reset_skinny(struct megasas_instance *instance, |
| 644 | struct megasas_register_set __iomem *regs) |
| 645 | { |
adam radford | 3cc6851f9 | 2011-05-11 18:34:52 -0700 | [diff] [blame] | 646 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) |
| 647 | return 1; |
| 648 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 649 | return 0; |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | static struct megasas_instance_template megasas_instance_template_skinny = { |
| 653 | |
| 654 | .fire_cmd = megasas_fire_cmd_skinny, |
| 655 | .enable_intr = megasas_enable_intr_skinny, |
| 656 | .disable_intr = megasas_disable_intr_skinny, |
| 657 | .clear_intr = megasas_clear_intr_skinny, |
| 658 | .read_fw_status_reg = megasas_read_fw_status_reg_skinny, |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 659 | .adp_reset = megasas_adp_reset_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 660 | .check_reset = megasas_check_reset_skinny, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 661 | .service_isr = megasas_isr, |
| 662 | .tasklet = megasas_complete_cmd_dpc, |
| 663 | .init_adapter = megasas_init_adapter_mfi, |
| 664 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 665 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 666 | }; |
| 667 | |
| 668 | |
| 669 | /** |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 670 | * The following functions are defined for gen2 (deviceid : 0x78 0x79) |
| 671 | * controllers |
| 672 | */ |
| 673 | |
| 674 | /** |
| 675 | * megasas_enable_intr_gen2 - Enables interrupts |
| 676 | * @regs: MFI register set |
| 677 | */ |
| 678 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 679 | megasas_enable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 680 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 681 | struct megasas_register_set __iomem *regs; |
| 682 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 683 | writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear); |
| 684 | |
| 685 | /* write ~0x00000005 (4 & 1) to the intr mask*/ |
| 686 | writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 687 | |
| 688 | /* Dummy readl to force pci flush */ |
| 689 | readl(®s->outbound_intr_mask); |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * megasas_disable_intr_gen2 - Disables interrupt |
| 694 | * @regs: MFI register set |
| 695 | */ |
| 696 | static inline void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 697 | megasas_disable_intr_gen2(struct megasas_instance *instance) |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 698 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 699 | struct megasas_register_set __iomem *regs; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 700 | u32 mask = 0xFFFFFFFF; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 701 | regs = instance->reg_set; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 702 | writel(mask, ®s->outbound_intr_mask); |
| 703 | /* Dummy readl to force pci flush */ |
| 704 | readl(®s->outbound_intr_mask); |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * megasas_read_fw_status_reg_gen2 - returns the current FW status value |
| 709 | * @regs: MFI register set |
| 710 | */ |
| 711 | static u32 |
| 712 | megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs) |
| 713 | { |
| 714 | return readl(&(regs)->outbound_scratch_pad); |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * megasas_clear_interrupt_gen2 - Check & clear interrupt |
| 719 | * @regs: MFI register set |
| 720 | */ |
| 721 | static int |
| 722 | megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs) |
| 723 | { |
| 724 | u32 status; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 725 | u32 mfiStatus = 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 726 | /* |
| 727 | * Check if it is our interrupt |
| 728 | */ |
| 729 | status = readl(®s->outbound_intr_status); |
| 730 | |
Sumit.Saxena@lsi.com | b5bccad | 2013-05-22 12:29:54 +0530 | [diff] [blame] | 731 | if (status & MFI_INTR_FLAG_REPLY_MESSAGE) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 732 | mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE; |
| 733 | } |
| 734 | if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) { |
| 735 | mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE; |
| 736 | } |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 737 | |
| 738 | /* |
| 739 | * Clear the interrupt by writing back the same value |
| 740 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 741 | if (mfiStatus) |
| 742 | writel(status, ®s->outbound_doorbell_clear); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 743 | |
| 744 | /* Dummy readl to force pci flush */ |
| 745 | readl(®s->outbound_intr_status); |
| 746 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 747 | return mfiStatus; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 748 | } |
| 749 | /** |
| 750 | * megasas_fire_cmd_gen2 - Sends command to the FW |
| 751 | * @frame_phys_addr : Physical address of cmd |
| 752 | * @frame_count : Number of frames for the command |
| 753 | * @regs : MFI register set |
| 754 | */ |
| 755 | static inline void |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 756 | megasas_fire_cmd_gen2(struct megasas_instance *instance, |
| 757 | dma_addr_t frame_phys_addr, |
| 758 | u32 frame_count, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 759 | struct megasas_register_set __iomem *regs) |
| 760 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 761 | unsigned long flags; |
| 762 | spin_lock_irqsave(&instance->hba_lock, flags); |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 763 | writel((frame_phys_addr | (frame_count<<1))|1, |
| 764 | &(regs)->inbound_queue_port); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 765 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * megasas_adp_reset_gen2 - For controller reset |
| 770 | * @regs: MFI register set |
| 771 | */ |
| 772 | static int |
| 773 | megasas_adp_reset_gen2(struct megasas_instance *instance, |
| 774 | struct megasas_register_set __iomem *reg_set) |
| 775 | { |
| 776 | u32 retry = 0 ; |
| 777 | u32 HostDiag; |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 778 | u32 *seq_offset = ®_set->seq_offset; |
| 779 | u32 *hostdiag_offset = ®_set->host_diag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 780 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 781 | if (instance->instancet == &megasas_instance_template_skinny) { |
| 782 | seq_offset = ®_set->fusion_seq_offset; |
| 783 | hostdiag_offset = ®_set->fusion_host_diag; |
| 784 | } |
| 785 | |
| 786 | writel(0, seq_offset); |
| 787 | writel(4, seq_offset); |
| 788 | writel(0xb, seq_offset); |
| 789 | writel(2, seq_offset); |
| 790 | writel(7, seq_offset); |
| 791 | writel(0xd, seq_offset); |
| 792 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 793 | msleep(1000); |
| 794 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 795 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 796 | |
| 797 | while ( !( HostDiag & DIAG_WRITE_ENABLE) ) { |
| 798 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 799 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 800 | printk(KERN_NOTICE "RESETGEN2: retry=%x, hostdiag=%x\n", |
| 801 | retry, HostDiag); |
| 802 | |
| 803 | if (retry++ >= 100) |
| 804 | return 1; |
| 805 | |
| 806 | } |
| 807 | |
| 808 | printk(KERN_NOTICE "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag); |
| 809 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 810 | writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 811 | |
| 812 | ssleep(10); |
| 813 | |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 814 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 815 | while ( ( HostDiag & DIAG_RESET_ADAPTER) ) { |
| 816 | msleep(100); |
adam radford | ebf054b | 2011-02-24 20:57:15 -0800 | [diff] [blame] | 817 | HostDiag = (u32)readl(hostdiag_offset); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 818 | printk(KERN_NOTICE "RESET_GEN2: retry=%x, hostdiag=%x\n", |
| 819 | retry, HostDiag); |
| 820 | |
| 821 | if (retry++ >= 1000) |
| 822 | return 1; |
| 823 | |
| 824 | } |
| 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | /** |
| 829 | * megasas_check_reset_gen2 - For controller reset check |
| 830 | * @regs: MFI register set |
| 831 | */ |
| 832 | static int |
| 833 | megasas_check_reset_gen2(struct megasas_instance *instance, |
| 834 | struct megasas_register_set __iomem *regs) |
| 835 | { |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 836 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 837 | return 1; |
| 838 | } |
| 839 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 840 | return 0; |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | static struct megasas_instance_template megasas_instance_template_gen2 = { |
| 844 | |
| 845 | .fire_cmd = megasas_fire_cmd_gen2, |
| 846 | .enable_intr = megasas_enable_intr_gen2, |
| 847 | .disable_intr = megasas_disable_intr_gen2, |
| 848 | .clear_intr = megasas_clear_intr_gen2, |
| 849 | .read_fw_status_reg = megasas_read_fw_status_reg_gen2, |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 850 | .adp_reset = megasas_adp_reset_gen2, |
| 851 | .check_reset = megasas_check_reset_gen2, |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 852 | .service_isr = megasas_isr, |
| 853 | .tasklet = megasas_complete_cmd_dpc, |
| 854 | .init_adapter = megasas_init_adapter_mfi, |
| 855 | .build_and_issue_cmd = megasas_build_and_issue_cmd, |
| 856 | .issue_dcmd = megasas_issue_dcmd, |
Yang, Bo | 6610a6b | 2008-08-10 12:42:38 -0700 | [diff] [blame] | 857 | }; |
| 858 | |
| 859 | /** |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 860 | * This is the end of set of functions & definitions |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 861 | * specific to gen2 (deviceid : 0x78, 0x79) controllers |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 862 | */ |
| 863 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 864 | /* |
| 865 | * Template added for TB (Fusion) |
| 866 | */ |
| 867 | extern struct megasas_instance_template megasas_instance_template_fusion; |
| 868 | |
Sumant Patro | f9876f0 | 2006-02-03 15:34:35 -0800 | [diff] [blame] | 869 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 870 | * megasas_issue_polled - Issues a polling command |
| 871 | * @instance: Adapter soft state |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 872 | * @cmd: Command packet to be issued |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 873 | * |
| 874 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. |
| 875 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 876 | int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 877 | megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 878 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 879 | |
| 880 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 881 | |
| 882 | frame_hdr->cmd_status = 0xFF; |
| 883 | frame_hdr->flags |= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE; |
| 884 | |
| 885 | /* |
| 886 | * Issue the frame using inbound queue port |
| 887 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 888 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 889 | |
| 890 | /* |
| 891 | * Wait for cmd_status to change |
| 892 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 893 | return wait_and_poll(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | /** |
| 897 | * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds |
| 898 | * @instance: Adapter soft state |
| 899 | * @cmd: Command to be issued |
| 900 | * |
| 901 | * 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] | 902 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 903 | * Used to issue ioctl commands. |
| 904 | */ |
| 905 | static int |
| 906 | megasas_issue_blocked_cmd(struct megasas_instance *instance, |
| 907 | struct megasas_cmd *cmd) |
| 908 | { |
| 909 | cmd->cmd_status = ENODATA; |
| 910 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 911 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 912 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 913 | wait_event(instance->int_cmd_wait_q, cmd->cmd_status != ENODATA); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd |
| 920 | * @instance: Adapter soft state |
| 921 | * @cmd_to_abort: Previously issued cmd to be aborted |
| 922 | * |
Justin P. Mattock | 8e572ba | 2011-02-02 11:31:21 +0100 | [diff] [blame] | 923 | * MFI firmware can abort previously issued AEN command (automatic event |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 924 | * notification). The megasas_issue_blocked_abort_cmd() issues such abort |
Sumant Patro | 2a3681e | 2006-10-03 13:19:21 -0700 | [diff] [blame] | 925 | * cmd and waits for return status. |
| 926 | * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 927 | */ |
| 928 | static int |
| 929 | megasas_issue_blocked_abort_cmd(struct megasas_instance *instance, |
| 930 | struct megasas_cmd *cmd_to_abort) |
| 931 | { |
| 932 | struct megasas_cmd *cmd; |
| 933 | struct megasas_abort_frame *abort_fr; |
| 934 | |
| 935 | cmd = megasas_get_cmd(instance); |
| 936 | |
| 937 | if (!cmd) |
| 938 | return -1; |
| 939 | |
| 940 | abort_fr = &cmd->frame->abort; |
| 941 | |
| 942 | /* |
| 943 | * Prepare and issue the abort frame |
| 944 | */ |
| 945 | abort_fr->cmd = MFI_CMD_ABORT; |
| 946 | abort_fr->cmd_status = 0xFF; |
| 947 | abort_fr->flags = 0; |
| 948 | abort_fr->abort_context = cmd_to_abort->index; |
| 949 | abort_fr->abort_mfi_phys_addr_lo = cmd_to_abort->frame_phys_addr; |
| 950 | abort_fr->abort_mfi_phys_addr_hi = 0; |
| 951 | |
| 952 | cmd->sync_cmd = 1; |
| 953 | cmd->cmd_status = 0xFF; |
| 954 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 955 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 956 | |
| 957 | /* |
| 958 | * Wait for this cmd to complete |
| 959 | */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 960 | wait_event(instance->abort_cmd_wait_q, cmd->cmd_status != 0xFF); |
| 961 | cmd->sync_cmd = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 962 | |
| 963 | megasas_return_cmd(instance, cmd); |
| 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | /** |
| 968 | * megasas_make_sgl32 - Prepares 32-bit SGL |
| 969 | * @instance: Adapter soft state |
| 970 | * @scp: SCSI command from the mid-layer |
| 971 | * @mfi_sgl: SGL to be filled in |
| 972 | * |
| 973 | * If successful, this function returns the number of SG elements. Otherwise, |
| 974 | * it returnes -1. |
| 975 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 976 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 977 | megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 978 | union megasas_sgl *mfi_sgl) |
| 979 | { |
| 980 | int i; |
| 981 | int sge_count; |
| 982 | struct scatterlist *os_sgl; |
| 983 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 984 | sge_count = scsi_dma_map(scp); |
| 985 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 986 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 987 | if (sge_count) { |
| 988 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
| 989 | mfi_sgl->sge32[i].length = sg_dma_len(os_sgl); |
| 990 | mfi_sgl->sge32[i].phys_addr = sg_dma_address(os_sgl); |
| 991 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 992 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 993 | return sge_count; |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * megasas_make_sgl64 - Prepares 64-bit SGL |
| 998 | * @instance: Adapter soft state |
| 999 | * @scp: SCSI command from the mid-layer |
| 1000 | * @mfi_sgl: SGL to be filled in |
| 1001 | * |
| 1002 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1003 | * it returnes -1. |
| 1004 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1005 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1006 | megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1007 | union megasas_sgl *mfi_sgl) |
| 1008 | { |
| 1009 | int i; |
| 1010 | int sge_count; |
| 1011 | struct scatterlist *os_sgl; |
| 1012 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1013 | sge_count = scsi_dma_map(scp); |
| 1014 | BUG_ON(sge_count < 0); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1015 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1016 | if (sge_count) { |
| 1017 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
| 1018 | mfi_sgl->sge64[i].length = sg_dma_len(os_sgl); |
| 1019 | mfi_sgl->sge64[i].phys_addr = sg_dma_address(os_sgl); |
| 1020 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1021 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1022 | return sge_count; |
| 1023 | } |
| 1024 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1025 | /** |
| 1026 | * megasas_make_sgl_skinny - Prepares IEEE SGL |
| 1027 | * @instance: Adapter soft state |
| 1028 | * @scp: SCSI command from the mid-layer |
| 1029 | * @mfi_sgl: SGL to be filled in |
| 1030 | * |
| 1031 | * If successful, this function returns the number of SG elements. Otherwise, |
| 1032 | * it returnes -1. |
| 1033 | */ |
| 1034 | static int |
| 1035 | megasas_make_sgl_skinny(struct megasas_instance *instance, |
| 1036 | struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl) |
| 1037 | { |
| 1038 | int i; |
| 1039 | int sge_count; |
| 1040 | struct scatterlist *os_sgl; |
| 1041 | |
| 1042 | sge_count = scsi_dma_map(scp); |
| 1043 | |
| 1044 | if (sge_count) { |
| 1045 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
| 1046 | mfi_sgl->sge_skinny[i].length = sg_dma_len(os_sgl); |
| 1047 | mfi_sgl->sge_skinny[i].phys_addr = |
| 1048 | sg_dma_address(os_sgl); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1049 | mfi_sgl->sge_skinny[i].flag = 0; |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | return sge_count; |
| 1053 | } |
| 1054 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1055 | /** |
| 1056 | * megasas_get_frame_count - Computes the number of frames |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1057 | * @frame_type : type of frame- io or pthru frame |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1058 | * @sge_count : number of sg elements |
| 1059 | * |
| 1060 | * Returns the number of frames required for numnber of sge's (sge_count) |
| 1061 | */ |
| 1062 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1063 | static u32 megasas_get_frame_count(struct megasas_instance *instance, |
| 1064 | u8 sge_count, u8 frame_type) |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1065 | { |
| 1066 | int num_cnt; |
| 1067 | int sge_bytes; |
| 1068 | u32 sge_sz; |
| 1069 | u32 frame_count=0; |
| 1070 | |
| 1071 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 1072 | sizeof(struct megasas_sge32); |
| 1073 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1074 | if (instance->flag_ieee) { |
| 1075 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 1076 | } |
| 1077 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1078 | /* |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1079 | * Main frame can contain 2 SGEs for 64-bit SGLs and |
| 1080 | * 3 SGEs for 32-bit SGLs for ldio & |
| 1081 | * 1 SGEs for 64-bit SGLs and |
| 1082 | * 2 SGEs for 32-bit SGLs for pthru frame |
| 1083 | */ |
| 1084 | if (unlikely(frame_type == PTHRU_FRAME)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1085 | if (instance->flag_ieee == 1) { |
| 1086 | num_cnt = sge_count - 1; |
| 1087 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1088 | num_cnt = sge_count - 1; |
| 1089 | else |
| 1090 | num_cnt = sge_count - 2; |
| 1091 | } else { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1092 | if (instance->flag_ieee == 1) { |
| 1093 | num_cnt = sge_count - 1; |
| 1094 | } else if (IS_DMA64) |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1095 | num_cnt = sge_count - 2; |
| 1096 | else |
| 1097 | num_cnt = sge_count - 3; |
| 1098 | } |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1099 | |
| 1100 | if(num_cnt>0){ |
| 1101 | sge_bytes = sge_sz * num_cnt; |
| 1102 | |
| 1103 | frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) + |
| 1104 | ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ; |
| 1105 | } |
| 1106 | /* Main frame */ |
| 1107 | frame_count +=1; |
| 1108 | |
| 1109 | if (frame_count > 7) |
| 1110 | frame_count = 8; |
| 1111 | return frame_count; |
| 1112 | } |
| 1113 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1114 | /** |
| 1115 | * megasas_build_dcdb - Prepares a direct cdb (DCDB) command |
| 1116 | * @instance: Adapter soft state |
| 1117 | * @scp: SCSI command |
| 1118 | * @cmd: Command to be prepared in |
| 1119 | * |
| 1120 | * This function prepares CDB commands. These are typcially pass-through |
| 1121 | * commands to the devices. |
| 1122 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1123 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1124 | megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1125 | struct megasas_cmd *cmd) |
| 1126 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1127 | u32 is_logical; |
| 1128 | u32 device_id; |
| 1129 | u16 flags = 0; |
| 1130 | struct megasas_pthru_frame *pthru; |
| 1131 | |
| 1132 | is_logical = MEGASAS_IS_LOGICAL(scp); |
| 1133 | device_id = MEGASAS_DEV_INDEX(instance, scp); |
| 1134 | pthru = (struct megasas_pthru_frame *)cmd->frame; |
| 1135 | |
| 1136 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1137 | flags = MFI_FRAME_DIR_WRITE; |
| 1138 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1139 | flags = MFI_FRAME_DIR_READ; |
| 1140 | else if (scp->sc_data_direction == PCI_DMA_NONE) |
| 1141 | flags = MFI_FRAME_DIR_NONE; |
| 1142 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1143 | if (instance->flag_ieee == 1) { |
| 1144 | flags |= MFI_FRAME_IEEE; |
| 1145 | } |
| 1146 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1147 | /* |
| 1148 | * Prepare the DCDB frame |
| 1149 | */ |
| 1150 | pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO; |
| 1151 | pthru->cmd_status = 0x0; |
| 1152 | pthru->scsi_status = 0x0; |
| 1153 | pthru->target_id = device_id; |
| 1154 | pthru->lun = scp->device->lun; |
| 1155 | pthru->cdb_len = scp->cmd_len; |
| 1156 | pthru->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 1157 | pthru->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1158 | pthru->flags = flags; |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 1159 | pthru->data_xfer_len = scsi_bufflen(scp); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1160 | |
| 1161 | memcpy(pthru->cdb, scp->cmnd, scp->cmd_len); |
| 1162 | |
| 1163 | /* |
Yang, Bo | 8d56825 | 2009-10-06 14:12:21 -0600 | [diff] [blame] | 1164 | * If the command is for the tape device, set the |
| 1165 | * pthru timeout to the os layer timeout value. |
| 1166 | */ |
| 1167 | if (scp->device->type == TYPE_TAPE) { |
| 1168 | if ((scp->request->timeout / HZ) > 0xFFFF) |
| 1169 | pthru->timeout = 0xFFFF; |
| 1170 | else |
| 1171 | pthru->timeout = scp->request->timeout / HZ; |
| 1172 | } |
| 1173 | |
| 1174 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1175 | * Construct SGL |
| 1176 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1177 | if (instance->flag_ieee == 1) { |
| 1178 | pthru->flags |= MFI_FRAME_SGL64; |
| 1179 | pthru->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1180 | &pthru->sgl); |
| 1181 | } else if (IS_DMA64) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1182 | pthru->flags |= MFI_FRAME_SGL64; |
| 1183 | pthru->sge_count = megasas_make_sgl64(instance, scp, |
| 1184 | &pthru->sgl); |
| 1185 | } else |
| 1186 | pthru->sge_count = megasas_make_sgl32(instance, scp, |
| 1187 | &pthru->sgl); |
| 1188 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1189 | if (pthru->sge_count > instance->max_num_sge) { |
| 1190 | printk(KERN_ERR "megasas: DCDB two many SGE NUM=%x\n", |
| 1191 | pthru->sge_count); |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1195 | /* |
| 1196 | * Sense info specific |
| 1197 | */ |
| 1198 | pthru->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1199 | pthru->sense_buf_phys_addr_hi = 0; |
| 1200 | pthru->sense_buf_phys_addr_lo = cmd->sense_phys_addr; |
| 1201 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1202 | /* |
| 1203 | * Compute the total number of frames this command consumes. FW uses |
| 1204 | * this number to pull sufficient number of frames from host memory. |
| 1205 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1206 | cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count, |
bo yang | d532dbe | 2008-03-17 03:36:43 -0400 | [diff] [blame] | 1207 | PTHRU_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1208 | |
| 1209 | return cmd->frame_count; |
| 1210 | } |
| 1211 | |
| 1212 | /** |
| 1213 | * megasas_build_ldio - Prepares IOs to logical devices |
| 1214 | * @instance: Adapter soft state |
| 1215 | * @scp: SCSI command |
Anand Gadiyar | fd589a8 | 2009-07-16 17:13:03 +0200 | [diff] [blame] | 1216 | * @cmd: Command to be prepared |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1217 | * |
| 1218 | * Frames (and accompanying SGLs) for regular SCSI IOs use this function. |
| 1219 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1220 | static int |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1221 | megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1222 | struct megasas_cmd *cmd) |
| 1223 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1224 | u32 device_id; |
| 1225 | u8 sc = scp->cmnd[0]; |
| 1226 | u16 flags = 0; |
| 1227 | struct megasas_io_frame *ldio; |
| 1228 | |
| 1229 | device_id = MEGASAS_DEV_INDEX(instance, scp); |
| 1230 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1231 | |
| 1232 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
| 1233 | flags = MFI_FRAME_DIR_WRITE; |
| 1234 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1235 | flags = MFI_FRAME_DIR_READ; |
| 1236 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1237 | if (instance->flag_ieee == 1) { |
| 1238 | flags |= MFI_FRAME_IEEE; |
| 1239 | } |
| 1240 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1241 | /* |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1242 | * 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] | 1243 | */ |
| 1244 | ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ; |
| 1245 | ldio->cmd_status = 0x0; |
| 1246 | ldio->scsi_status = 0x0; |
| 1247 | ldio->target_id = device_id; |
| 1248 | ldio->timeout = 0; |
| 1249 | ldio->reserved_0 = 0; |
| 1250 | ldio->pad_0 = 0; |
| 1251 | ldio->flags = flags; |
| 1252 | ldio->start_lba_hi = 0; |
| 1253 | ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0; |
| 1254 | |
| 1255 | /* |
| 1256 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1257 | */ |
| 1258 | if (scp->cmd_len == 6) { |
| 1259 | ldio->lba_count = (u32) scp->cmnd[4]; |
| 1260 | ldio->start_lba_lo = ((u32) scp->cmnd[1] << 16) | |
| 1261 | ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3]; |
| 1262 | |
| 1263 | ldio->start_lba_lo &= 0x1FFFFF; |
| 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1268 | */ |
| 1269 | else if (scp->cmd_len == 10) { |
| 1270 | ldio->lba_count = (u32) scp->cmnd[8] | |
| 1271 | ((u32) scp->cmnd[7] << 8); |
| 1272 | ldio->start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 1273 | ((u32) scp->cmnd[3] << 16) | |
| 1274 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1275 | } |
| 1276 | |
| 1277 | /* |
| 1278 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1279 | */ |
| 1280 | else if (scp->cmd_len == 12) { |
| 1281 | ldio->lba_count = ((u32) scp->cmnd[6] << 24) | |
| 1282 | ((u32) scp->cmnd[7] << 16) | |
| 1283 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 1284 | |
| 1285 | ldio->start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 1286 | ((u32) scp->cmnd[3] << 16) | |
| 1287 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1288 | } |
| 1289 | |
| 1290 | /* |
| 1291 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1292 | */ |
| 1293 | else if (scp->cmd_len == 16) { |
| 1294 | ldio->lba_count = ((u32) scp->cmnd[10] << 24) | |
| 1295 | ((u32) scp->cmnd[11] << 16) | |
| 1296 | ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13]; |
| 1297 | |
| 1298 | ldio->start_lba_lo = ((u32) scp->cmnd[6] << 24) | |
| 1299 | ((u32) scp->cmnd[7] << 16) | |
| 1300 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 1301 | |
| 1302 | ldio->start_lba_hi = ((u32) scp->cmnd[2] << 24) | |
| 1303 | ((u32) scp->cmnd[3] << 16) | |
| 1304 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1305 | |
| 1306 | } |
| 1307 | |
| 1308 | /* |
| 1309 | * Construct SGL |
| 1310 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1311 | if (instance->flag_ieee) { |
| 1312 | ldio->flags |= MFI_FRAME_SGL64; |
| 1313 | ldio->sge_count = megasas_make_sgl_skinny(instance, scp, |
| 1314 | &ldio->sgl); |
| 1315 | } else if (IS_DMA64) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1316 | ldio->flags |= MFI_FRAME_SGL64; |
| 1317 | ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl); |
| 1318 | } else |
| 1319 | ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl); |
| 1320 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 1321 | if (ldio->sge_count > instance->max_num_sge) { |
| 1322 | printk(KERN_ERR "megasas: build_ld_io: sge_count = %x\n", |
| 1323 | ldio->sge_count); |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1327 | /* |
| 1328 | * Sense info specific |
| 1329 | */ |
| 1330 | ldio->sense_len = SCSI_SENSE_BUFFERSIZE; |
| 1331 | ldio->sense_buf_phys_addr_hi = 0; |
| 1332 | ldio->sense_buf_phys_addr_lo = cmd->sense_phys_addr; |
| 1333 | |
Sumant Patro | b1df99d | 2006-10-03 12:40:47 -0700 | [diff] [blame] | 1334 | /* |
| 1335 | * Compute the total number of frames this command consumes. FW uses |
| 1336 | * this number to pull sufficient number of frames from host memory. |
| 1337 | */ |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 1338 | cmd->frame_count = megasas_get_frame_count(instance, |
| 1339 | ldio->sge_count, IO_FRAME); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1340 | |
| 1341 | return cmd->frame_count; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1345 | * megasas_is_ldio - Checks if the cmd is for logical drive |
| 1346 | * @scmd: SCSI command |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 1347 | * |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1348 | * 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] | 1349 | * is a logical drive command |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1350 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1351 | inline int megasas_is_ldio(struct scsi_cmnd *cmd) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1352 | { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1353 | if (!MEGASAS_IS_LOGICAL(cmd)) |
| 1354 | return 0; |
| 1355 | switch (cmd->cmnd[0]) { |
| 1356 | case READ_10: |
| 1357 | case WRITE_10: |
| 1358 | case READ_12: |
| 1359 | case WRITE_12: |
| 1360 | case READ_6: |
| 1361 | case WRITE_6: |
| 1362 | case READ_16: |
| 1363 | case WRITE_16: |
| 1364 | return 1; |
| 1365 | default: |
| 1366 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1367 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1368 | } |
| 1369 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1370 | /** |
| 1371 | * megasas_dump_pending_frames - Dumps the frame address of all pending cmds |
| 1372 | * in FW |
| 1373 | * @instance: Adapter soft state |
| 1374 | */ |
| 1375 | static inline void |
| 1376 | megasas_dump_pending_frames(struct megasas_instance *instance) |
| 1377 | { |
| 1378 | struct megasas_cmd *cmd; |
| 1379 | int i,n; |
| 1380 | union megasas_sgl *mfi_sgl; |
| 1381 | struct megasas_io_frame *ldio; |
| 1382 | struct megasas_pthru_frame *pthru; |
| 1383 | u32 sgcount; |
| 1384 | u32 max_cmd = instance->max_fw_cmds; |
| 1385 | |
| 1386 | printk(KERN_ERR "\nmegasas[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no); |
| 1387 | printk(KERN_ERR "megasas[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding)); |
| 1388 | if (IS_DMA64) |
| 1389 | printk(KERN_ERR "\nmegasas[%d]: 64 bit SGLs were sent to FW\n",instance->host->host_no); |
| 1390 | else |
| 1391 | printk(KERN_ERR "\nmegasas[%d]: 32 bit SGLs were sent to FW\n",instance->host->host_no); |
| 1392 | |
| 1393 | printk(KERN_ERR "megasas[%d]: Pending OS cmds in FW : \n",instance->host->host_no); |
| 1394 | for (i = 0; i < max_cmd; i++) { |
| 1395 | cmd = instance->cmd_list[i]; |
| 1396 | if(!cmd->scmd) |
| 1397 | continue; |
| 1398 | printk(KERN_ERR "megasas[%d]: Frame addr :0x%08lx : ",instance->host->host_no,(unsigned long)cmd->frame_phys_addr); |
| 1399 | if (megasas_is_ldio(cmd->scmd)){ |
| 1400 | ldio = (struct megasas_io_frame *)cmd->frame; |
| 1401 | mfi_sgl = &ldio->sgl; |
| 1402 | sgcount = ldio->sge_count; |
| 1403 | printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",instance->host->host_no, cmd->frame_count,ldio->cmd,ldio->target_id, ldio->start_lba_lo,ldio->start_lba_hi,ldio->sense_buf_phys_addr_lo,sgcount); |
| 1404 | } |
| 1405 | else { |
| 1406 | pthru = (struct megasas_pthru_frame *) cmd->frame; |
| 1407 | mfi_sgl = &pthru->sgl; |
| 1408 | sgcount = pthru->sge_count; |
| 1409 | printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",instance->host->host_no,cmd->frame_count,pthru->cmd,pthru->target_id,pthru->lun,pthru->cdb_len , pthru->data_xfer_len,pthru->sense_buf_phys_addr_lo,sgcount); |
| 1410 | } |
| 1411 | if(megasas_dbg_lvl & MEGASAS_DBG_LVL){ |
| 1412 | for (n = 0; n < sgcount; n++){ |
| 1413 | if (IS_DMA64) |
| 1414 | printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%08lx ",mfi_sgl->sge64[n].length , (unsigned long)mfi_sgl->sge64[n].phys_addr) ; |
| 1415 | else |
| 1416 | printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%x ",mfi_sgl->sge32[n].length , mfi_sgl->sge32[n].phys_addr) ; |
| 1417 | } |
| 1418 | } |
| 1419 | printk(KERN_ERR "\n"); |
| 1420 | } /*for max_cmd*/ |
| 1421 | printk(KERN_ERR "\nmegasas[%d]: Pending Internal cmds in FW : \n",instance->host->host_no); |
| 1422 | for (i = 0; i < max_cmd; i++) { |
| 1423 | |
| 1424 | cmd = instance->cmd_list[i]; |
| 1425 | |
| 1426 | if(cmd->sync_cmd == 1){ |
| 1427 | printk(KERN_ERR "0x%08lx : ", (unsigned long)cmd->frame_phys_addr); |
| 1428 | } |
| 1429 | } |
| 1430 | printk(KERN_ERR "megasas[%d]: Dumping Done.\n\n",instance->host->host_no); |
| 1431 | } |
| 1432 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1433 | u32 |
| 1434 | megasas_build_and_issue_cmd(struct megasas_instance *instance, |
| 1435 | struct scsi_cmnd *scmd) |
| 1436 | { |
| 1437 | struct megasas_cmd *cmd; |
| 1438 | u32 frame_count; |
| 1439 | |
| 1440 | cmd = megasas_get_cmd(instance); |
| 1441 | if (!cmd) |
| 1442 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1443 | |
| 1444 | /* |
| 1445 | * Logical drive command |
| 1446 | */ |
| 1447 | if (megasas_is_ldio(scmd)) |
| 1448 | frame_count = megasas_build_ldio(instance, scmd, cmd); |
| 1449 | else |
| 1450 | frame_count = megasas_build_dcdb(instance, scmd, cmd); |
| 1451 | |
| 1452 | if (!frame_count) |
| 1453 | goto out_return_cmd; |
| 1454 | |
| 1455 | cmd->scmd = scmd; |
| 1456 | scmd->SCp.ptr = (char *)cmd; |
| 1457 | |
| 1458 | /* |
| 1459 | * Issue the command to the FW |
| 1460 | */ |
| 1461 | atomic_inc(&instance->fw_outstanding); |
| 1462 | |
| 1463 | instance->instancet->fire_cmd(instance, cmd->frame_phys_addr, |
| 1464 | cmd->frame_count-1, instance->reg_set); |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1465 | |
| 1466 | return 0; |
| 1467 | out_return_cmd: |
| 1468 | megasas_return_cmd(instance, cmd); |
| 1469 | return 1; |
| 1470 | } |
| 1471 | |
| 1472 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1473 | /** |
| 1474 | * megasas_queue_command - Queue entry point |
| 1475 | * @scmd: SCSI command to be queued |
| 1476 | * @done: Callback entry point |
| 1477 | */ |
| 1478 | static int |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 1479 | megasas_queue_command_lck(struct scsi_cmnd *scmd, void (*done) (struct scsi_cmnd *)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1480 | { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1481 | struct megasas_instance *instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1482 | unsigned long flags; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1483 | |
| 1484 | instance = (struct megasas_instance *) |
| 1485 | scmd->device->host->hostdata; |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1486 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1487 | if (instance->issuepend_done == 0) |
Sumant Patro | af37acf | 2007-02-14 12:34:46 -0800 | [diff] [blame] | 1488 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1489 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1490 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | b09e66d | 2013-05-22 12:29:28 +0530 | [diff] [blame] | 1491 | |
| 1492 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 1493 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1494 | scmd->result = DID_ERROR << 16; |
| 1495 | done(scmd); |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1499 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 1500 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1501 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1502 | } |
| 1503 | |
| 1504 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1505 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1506 | scmd->scsi_done = done; |
| 1507 | scmd->result = 0; |
| 1508 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1509 | if (MEGASAS_IS_LOGICAL(scmd) && |
| 1510 | (scmd->device->id >= MEGASAS_MAX_LD || scmd->device->lun)) { |
| 1511 | scmd->result = DID_BAD_TARGET << 16; |
| 1512 | goto out_done; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1513 | } |
| 1514 | |
Sumant Patro | 02b01e0 | 2007-02-14 13:00:55 -0800 | [diff] [blame] | 1515 | switch (scmd->cmnd[0]) { |
| 1516 | case SYNCHRONIZE_CACHE: |
| 1517 | /* |
| 1518 | * FW takes care of flush cache on its own |
| 1519 | * No need to send it down |
| 1520 | */ |
| 1521 | scmd->result = DID_OK << 16; |
| 1522 | goto out_done; |
| 1523 | default: |
| 1524 | break; |
| 1525 | } |
| 1526 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1527 | if (instance->instancet->build_and_issue_cmd(instance, scmd)) { |
| 1528 | printk(KERN_ERR "megasas: Err returned from build_and_issue_cmd\n"); |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1529 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 1530 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1531 | |
| 1532 | return 0; |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1533 | |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 1534 | out_done: |
| 1535 | done(scmd); |
| 1536 | return 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1537 | } |
| 1538 | |
Jeff Garzik | f281233 | 2010-11-16 02:10:29 -0500 | [diff] [blame] | 1539 | static DEF_SCSI_QCMD(megasas_queue_command) |
| 1540 | |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1541 | static struct megasas_instance *megasas_lookup_instance(u16 host_no) |
| 1542 | { |
| 1543 | int i; |
| 1544 | |
| 1545 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 1546 | |
| 1547 | if ((megasas_mgmt_info.instance[i]) && |
| 1548 | (megasas_mgmt_info.instance[i]->host->host_no == host_no)) |
| 1549 | return megasas_mgmt_info.instance[i]; |
| 1550 | } |
| 1551 | |
| 1552 | return NULL; |
| 1553 | } |
| 1554 | |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1555 | static int megasas_slave_configure(struct scsi_device *sdev) |
| 1556 | { |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1557 | u16 pd_index = 0; |
| 1558 | struct megasas_instance *instance ; |
| 1559 | |
| 1560 | instance = megasas_lookup_instance(sdev->host->host_no); |
Christoph Hellwig | e5b3a65 | 2006-03-10 17:08:57 +0100 | [diff] [blame] | 1561 | |
| 1562 | /* |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 1563 | * Don't export physical disk devices to the disk driver. |
| 1564 | * |
| 1565 | * FIXME: Currently we don't export them to the midlayer at all. |
| 1566 | * That will be fixed once LSI engineers have audited the |
| 1567 | * firmware for possible issues. |
| 1568 | */ |
| 1569 | if (sdev->channel < MEGASAS_MAX_PD_CHANNELS && |
| 1570 | sdev->type == TYPE_DISK) { |
| 1571 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1572 | sdev->id; |
| 1573 | if (instance->pd_list[pd_index].driveState == |
| 1574 | MR_PD_STATE_SYSTEM) { |
| 1575 | blk_queue_rq_timeout(sdev->request_queue, |
| 1576 | MEGASAS_DEFAULT_CMD_TIMEOUT * HZ); |
| 1577 | return 0; |
| 1578 | } |
| 1579 | return -ENXIO; |
| 1580 | } |
| 1581 | |
| 1582 | /* |
| 1583 | * The RAID firmware may require extended timeouts. |
| 1584 | */ |
| 1585 | blk_queue_rq_timeout(sdev->request_queue, |
| 1586 | MEGASAS_DEFAULT_CMD_TIMEOUT * HZ); |
| 1587 | return 0; |
| 1588 | } |
| 1589 | |
| 1590 | static int megasas_slave_alloc(struct scsi_device *sdev) |
| 1591 | { |
| 1592 | u16 pd_index = 0; |
| 1593 | struct megasas_instance *instance ; |
| 1594 | instance = megasas_lookup_instance(sdev->host->host_no); |
| 1595 | if ((sdev->channel < MEGASAS_MAX_PD_CHANNELS) && |
| 1596 | (sdev->type == TYPE_DISK)) { |
| 1597 | /* |
| 1598 | * Open the OS scan to the SYSTEM PD |
| 1599 | */ |
| 1600 | pd_index = |
| 1601 | (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) + |
| 1602 | sdev->id; |
| 1603 | if ((instance->pd_list[pd_index].driveState == |
| 1604 | MR_PD_STATE_SYSTEM) && |
| 1605 | (instance->pd_list[pd_index].driveType == |
| 1606 | TYPE_DISK)) { |
| 1607 | return 0; |
| 1608 | } |
| 1609 | return -ENXIO; |
| 1610 | } |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 1611 | return 0; |
| 1612 | } |
| 1613 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1614 | void megaraid_sas_kill_hba(struct megasas_instance *instance) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1615 | { |
| 1616 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1617 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1618 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1619 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1620 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1621 | writel(MFI_STOP_ADP, &instance->reg_set->doorbell); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1622 | } else { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1623 | writel(MFI_STOP_ADP, &instance->reg_set->inbound_doorbell); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | /** |
| 1628 | * megasas_check_and_restore_queue_depth - Check if queue depth needs to be |
| 1629 | * restored to max value |
| 1630 | * @instance: Adapter soft state |
| 1631 | * |
| 1632 | */ |
| 1633 | void |
| 1634 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance) |
| 1635 | { |
| 1636 | unsigned long flags; |
| 1637 | if (instance->flag & MEGASAS_FW_BUSY |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 1638 | && time_after(jiffies, instance->last_time + 5 * HZ) |
| 1639 | && atomic_read(&instance->fw_outstanding) < |
| 1640 | instance->throttlequeuedepth + 1) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1641 | |
| 1642 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 1643 | instance->flag &= ~MEGASAS_FW_BUSY; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 1644 | if (instance->is_imr) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1645 | instance->host->can_queue = |
| 1646 | instance->max_fw_cmds - MEGASAS_SKINNY_INT_CMDS; |
| 1647 | } else |
| 1648 | instance->host->can_queue = |
| 1649 | instance->max_fw_cmds - MEGASAS_INT_CMDS; |
| 1650 | |
| 1651 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1652 | } |
| 1653 | } |
| 1654 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1655 | /** |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1656 | * megasas_complete_cmd_dpc - Returns FW's controller structure |
| 1657 | * @instance_addr: Address of adapter soft state |
| 1658 | * |
| 1659 | * Tasklet to complete cmds |
| 1660 | */ |
| 1661 | static void megasas_complete_cmd_dpc(unsigned long instance_addr) |
| 1662 | { |
| 1663 | u32 producer; |
| 1664 | u32 consumer; |
| 1665 | u32 context; |
| 1666 | struct megasas_cmd *cmd; |
| 1667 | struct megasas_instance *instance = |
| 1668 | (struct megasas_instance *)instance_addr; |
| 1669 | unsigned long flags; |
| 1670 | |
| 1671 | /* If we have already declared adapter dead, donot complete cmds */ |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1672 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR ) |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1673 | return; |
| 1674 | |
| 1675 | spin_lock_irqsave(&instance->completion_lock, flags); |
| 1676 | |
| 1677 | producer = *instance->producer; |
| 1678 | consumer = *instance->consumer; |
| 1679 | |
| 1680 | while (consumer != producer) { |
| 1681 | context = instance->reply_queue[consumer]; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1682 | if (context >= instance->max_fw_cmds) { |
| 1683 | printk(KERN_ERR "Unexpected context value %x\n", |
| 1684 | context); |
| 1685 | BUG(); |
| 1686 | } |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1687 | |
| 1688 | cmd = instance->cmd_list[context]; |
| 1689 | |
| 1690 | megasas_complete_cmd(instance, cmd, DID_OK); |
| 1691 | |
| 1692 | consumer++; |
| 1693 | if (consumer == (instance->max_fw_cmds + 1)) { |
| 1694 | consumer = 0; |
| 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | *instance->consumer = producer; |
| 1699 | |
| 1700 | spin_unlock_irqrestore(&instance->completion_lock, flags); |
| 1701 | |
| 1702 | /* |
| 1703 | * Check if we can restore can_queue |
| 1704 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1705 | megasas_check_and_restore_queue_depth(instance); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1706 | } |
| 1707 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1708 | static void |
| 1709 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance); |
| 1710 | |
| 1711 | static void |
| 1712 | process_fw_state_change_wq(struct work_struct *work); |
| 1713 | |
| 1714 | void megasas_do_ocr(struct megasas_instance *instance) |
| 1715 | { |
| 1716 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 1717 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 1718 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 1719 | *instance->consumer = MEGASAS_ADPRESET_INPROG_SIGN; |
| 1720 | } |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 1721 | instance->instancet->disable_intr(instance); |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1722 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
| 1723 | instance->issuepend_done = 0; |
| 1724 | |
| 1725 | atomic_set(&instance->fw_outstanding, 0); |
| 1726 | megasas_internal_reset_defer_cmds(instance); |
| 1727 | process_fw_state_change_wq(&instance->work_init); |
| 1728 | } |
| 1729 | |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1730 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1731 | * megasas_wait_for_outstanding - Wait for all outstanding cmds |
| 1732 | * @instance: Adapter soft state |
| 1733 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1734 | * 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] | 1735 | * complete all its outstanding commands. Returns error if one or more IOs |
| 1736 | * are pending after this time period. It also marks the controller dead. |
| 1737 | */ |
| 1738 | static int megasas_wait_for_outstanding(struct megasas_instance *instance) |
| 1739 | { |
| 1740 | int i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1741 | u32 reset_index; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1742 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1743 | u8 adprecovery; |
| 1744 | unsigned long flags; |
| 1745 | struct list_head clist_local; |
| 1746 | struct megasas_cmd *reset_cmd; |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1747 | u32 fw_state; |
| 1748 | u8 kill_adapter_flag; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1749 | |
| 1750 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 1751 | adprecovery = instance->adprecovery; |
| 1752 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1753 | |
| 1754 | if (adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 1755 | |
| 1756 | INIT_LIST_HEAD(&clist_local); |
| 1757 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 1758 | list_splice_init(&instance->internal_reset_pending_q, |
| 1759 | &clist_local); |
| 1760 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1761 | |
| 1762 | printk(KERN_NOTICE "megasas: HBA reset wait ...\n"); |
| 1763 | for (i = 0; i < wait_time; i++) { |
| 1764 | msleep(1000); |
| 1765 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 1766 | adprecovery = instance->adprecovery; |
| 1767 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1768 | if (adprecovery == MEGASAS_HBA_OPERATIONAL) |
| 1769 | break; |
| 1770 | } |
| 1771 | |
| 1772 | if (adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 1773 | printk(KERN_NOTICE "megasas: reset: Stopping HBA.\n"); |
| 1774 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 1775 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 1776 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1777 | return FAILED; |
| 1778 | } |
| 1779 | |
| 1780 | reset_index = 0; |
| 1781 | while (!list_empty(&clist_local)) { |
| 1782 | reset_cmd = list_entry((&clist_local)->next, |
| 1783 | struct megasas_cmd, list); |
| 1784 | list_del_init(&reset_cmd->list); |
| 1785 | if (reset_cmd->scmd) { |
| 1786 | reset_cmd->scmd->result = DID_RESET << 16; |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 1787 | printk(KERN_NOTICE "%d:%p reset [%02x]\n", |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1788 | reset_index, reset_cmd, |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 1789 | reset_cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1790 | |
| 1791 | reset_cmd->scmd->scsi_done(reset_cmd->scmd); |
| 1792 | megasas_return_cmd(instance, reset_cmd); |
| 1793 | } else if (reset_cmd->sync_cmd) { |
| 1794 | printk(KERN_NOTICE "megasas:%p synch cmds" |
| 1795 | "reset queue\n", |
| 1796 | reset_cmd); |
| 1797 | |
| 1798 | reset_cmd->cmd_status = ENODATA; |
| 1799 | instance->instancet->fire_cmd(instance, |
| 1800 | reset_cmd->frame_phys_addr, |
| 1801 | 0, instance->reg_set); |
| 1802 | } else { |
| 1803 | printk(KERN_NOTICE "megasas: %p unexpected" |
| 1804 | "cmds lst\n", |
| 1805 | reset_cmd); |
| 1806 | } |
| 1807 | reset_index++; |
| 1808 | } |
| 1809 | |
| 1810 | return SUCCESS; |
| 1811 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1812 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 1813 | for (i = 0; i < resetwaittime; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1814 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 1815 | int outstanding = atomic_read(&instance->fw_outstanding); |
| 1816 | |
| 1817 | if (!outstanding) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1818 | break; |
| 1819 | |
| 1820 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 1821 | printk(KERN_NOTICE "megasas: [%2d]waiting for %d " |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 1822 | "commands to complete\n",i,outstanding); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 1823 | /* |
| 1824 | * Call cmd completion routine. Cmd to be |
| 1825 | * be completed directly without depending on isr. |
| 1826 | */ |
| 1827 | megasas_complete_cmd_dpc((unsigned long)instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | msleep(1000); |
| 1831 | } |
| 1832 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 1833 | i = 0; |
| 1834 | kill_adapter_flag = 0; |
| 1835 | do { |
| 1836 | fw_state = instance->instancet->read_fw_status_reg( |
| 1837 | instance->reg_set) & MFI_STATE_MASK; |
| 1838 | if ((fw_state == MFI_STATE_FAULT) && |
| 1839 | (instance->disableOnlineCtrlReset == 0)) { |
| 1840 | if (i == 3) { |
| 1841 | kill_adapter_flag = 2; |
| 1842 | break; |
| 1843 | } |
| 1844 | megasas_do_ocr(instance); |
| 1845 | kill_adapter_flag = 1; |
| 1846 | |
| 1847 | /* wait for 1 secs to let FW finish the pending cmds */ |
| 1848 | msleep(1000); |
| 1849 | } |
| 1850 | i++; |
| 1851 | } while (i <= 3); |
| 1852 | |
| 1853 | if (atomic_read(&instance->fw_outstanding) && |
| 1854 | !kill_adapter_flag) { |
| 1855 | if (instance->disableOnlineCtrlReset == 0) { |
| 1856 | |
| 1857 | megasas_do_ocr(instance); |
| 1858 | |
| 1859 | /* wait for 5 secs to let FW finish the pending cmds */ |
| 1860 | for (i = 0; i < wait_time; i++) { |
| 1861 | int outstanding = |
| 1862 | atomic_read(&instance->fw_outstanding); |
| 1863 | if (!outstanding) |
| 1864 | return SUCCESS; |
| 1865 | msleep(1000); |
| 1866 | } |
| 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | if (atomic_read(&instance->fw_outstanding) || |
| 1871 | (kill_adapter_flag == 2)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1872 | printk(KERN_NOTICE "megaraid_sas: pending cmds after reset\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 1873 | /* |
| 1874 | * Send signal to FW to stop processing any pending cmds. |
| 1875 | * The controller will be taken offline by the OS now. |
| 1876 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 1877 | if ((instance->pdev->device == |
| 1878 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 1879 | (instance->pdev->device == |
| 1880 | PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
| 1881 | writel(MFI_STOP_ADP, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1882 | &instance->reg_set->doorbell); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 1883 | } else { |
| 1884 | writel(MFI_STOP_ADP, |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 1885 | &instance->reg_set->inbound_doorbell); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 1886 | } |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 1887 | megasas_dump_pending_frames(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1888 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 1889 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 1890 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1891 | return FAILED; |
| 1892 | } |
| 1893 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1894 | printk(KERN_NOTICE "megaraid_sas: no pending cmds after reset\n"); |
| 1895 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1896 | return SUCCESS; |
| 1897 | } |
| 1898 | |
| 1899 | /** |
| 1900 | * megasas_generic_reset - Generic reset routine |
| 1901 | * @scmd: Mid-layer SCSI command |
| 1902 | * |
| 1903 | * This routine implements a generic reset handler for device, bus and host |
| 1904 | * reset requests. Device, bus and host specific reset handlers can use this |
| 1905 | * function after they do their specific tasks. |
| 1906 | */ |
| 1907 | static int megasas_generic_reset(struct scsi_cmnd *scmd) |
| 1908 | { |
| 1909 | int ret_val; |
| 1910 | struct megasas_instance *instance; |
| 1911 | |
| 1912 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 1913 | |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 1914 | scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n", |
| 1915 | scmd->cmnd[0], scmd->retries); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1916 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 1917 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1918 | printk(KERN_ERR "megasas: cannot recover from previous reset " |
| 1919 | "failures\n"); |
| 1920 | return FAILED; |
| 1921 | } |
| 1922 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1923 | ret_val = megasas_wait_for_outstanding(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1924 | if (ret_val == SUCCESS) |
| 1925 | printk(KERN_NOTICE "megasas: reset successful \n"); |
| 1926 | else |
| 1927 | printk(KERN_ERR "megasas: failed to do reset\n"); |
| 1928 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1929 | return ret_val; |
| 1930 | } |
| 1931 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1932 | /** |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 1933 | * megasas_reset_timer - quiesce the adapter if required |
| 1934 | * @scmd: scsi cmnd |
| 1935 | * |
| 1936 | * Sets the FW busy flag and reduces the host->can_queue if the |
| 1937 | * cmd has not been completed within the timeout period. |
| 1938 | */ |
| 1939 | static enum |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1940 | blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd) |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 1941 | { |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 1942 | struct megasas_instance *instance; |
| 1943 | unsigned long flags; |
| 1944 | |
| 1945 | if (time_after(jiffies, scmd->jiffies_at_alloc + |
| 1946 | (MEGASAS_DEFAULT_CMD_TIMEOUT * 2) * HZ)) { |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1947 | return BLK_EH_NOT_HANDLED; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 1948 | } |
| 1949 | |
adam radford | f575c5d | 2011-10-13 16:01:12 -0700 | [diff] [blame] | 1950 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 1951 | if (!(instance->flag & MEGASAS_FW_BUSY)) { |
| 1952 | /* FW is busy, throttle IO */ |
| 1953 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 1954 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 1955 | instance->host->can_queue = instance->throttlequeuedepth; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 1956 | instance->last_time = jiffies; |
| 1957 | instance->flag |= MEGASAS_FW_BUSY; |
| 1958 | |
| 1959 | spin_unlock_irqrestore(instance->host->host_lock, flags); |
| 1960 | } |
Jens Axboe | 242f9dc | 2008-09-14 05:55:09 -0700 | [diff] [blame] | 1961 | return BLK_EH_RESET_TIMER; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1965 | * megasas_reset_device - Device reset handler entry point |
| 1966 | */ |
| 1967 | static int megasas_reset_device(struct scsi_cmnd *scmd) |
| 1968 | { |
| 1969 | int ret; |
| 1970 | |
| 1971 | /* |
| 1972 | * First wait for all commands to complete |
| 1973 | */ |
| 1974 | ret = megasas_generic_reset(scmd); |
| 1975 | |
| 1976 | return ret; |
| 1977 | } |
| 1978 | |
| 1979 | /** |
| 1980 | * megasas_reset_bus_host - Bus & host reset handler entry point |
| 1981 | */ |
| 1982 | static int megasas_reset_bus_host(struct scsi_cmnd *scmd) |
| 1983 | { |
| 1984 | int ret; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1985 | struct megasas_instance *instance; |
| 1986 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1987 | |
| 1988 | /* |
Uwe Zeisberger | 80682fa | 2006-03-22 00:21:33 +0100 | [diff] [blame] | 1989 | * First wait for all commands to complete |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1990 | */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1991 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1992 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1993 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1994 | ret = megasas_reset_fusion(scmd->device->host); |
| 1995 | else |
| 1996 | ret = megasas_generic_reset(scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 1997 | |
| 1998 | return ret; |
| 1999 | } |
| 2000 | |
| 2001 | /** |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2002 | * megasas_bios_param - Returns disk geometry for a disk |
| 2003 | * @sdev: device handle |
| 2004 | * @bdev: block device |
| 2005 | * @capacity: drive capacity |
| 2006 | * @geom: geometry parameters |
| 2007 | */ |
| 2008 | static int |
| 2009 | megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev, |
| 2010 | sector_t capacity, int geom[]) |
| 2011 | { |
| 2012 | int heads; |
| 2013 | int sectors; |
| 2014 | sector_t cylinders; |
| 2015 | unsigned long tmp; |
| 2016 | /* Default heads (64) & sectors (32) */ |
| 2017 | heads = 64; |
| 2018 | sectors = 32; |
| 2019 | |
| 2020 | tmp = heads * sectors; |
| 2021 | cylinders = capacity; |
| 2022 | |
| 2023 | sector_div(cylinders, tmp); |
| 2024 | |
| 2025 | /* |
| 2026 | * Handle extended translation size for logical drives > 1Gb |
| 2027 | */ |
| 2028 | |
| 2029 | if (capacity >= 0x200000) { |
| 2030 | heads = 255; |
| 2031 | sectors = 63; |
| 2032 | tmp = heads*sectors; |
| 2033 | cylinders = capacity; |
| 2034 | sector_div(cylinders, tmp); |
| 2035 | } |
| 2036 | |
| 2037 | geom[0] = heads; |
| 2038 | geom[1] = sectors; |
| 2039 | geom[2] = cylinders; |
| 2040 | |
| 2041 | return 0; |
| 2042 | } |
| 2043 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2044 | static void megasas_aen_polling(struct work_struct *work); |
| 2045 | |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2046 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2047 | * megasas_service_aen - Processes an event notification |
| 2048 | * @instance: Adapter soft state |
| 2049 | * @cmd: AEN command completed by the ISR |
| 2050 | * |
| 2051 | * For AEN, driver sends a command down to FW that is held by the FW till an |
| 2052 | * event occurs. When an event of interest occurs, FW completes the command |
| 2053 | * that it was previously holding. |
| 2054 | * |
| 2055 | * This routines sends SIGIO signal to processes that have registered with the |
| 2056 | * driver for AEN. |
| 2057 | */ |
| 2058 | static void |
| 2059 | megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2060 | { |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2061 | unsigned long flags; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2062 | /* |
| 2063 | * Don't signal app if it is just an aborted previously registered aen |
| 2064 | */ |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2065 | if ((!cmd->abort_aen) && (instance->unload == 0)) { |
| 2066 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2067 | megasas_poll_wait_aen = 1; |
| 2068 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2069 | wake_up(&megasas_poll_wait); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2070 | kill_fasync(&megasas_async_queue, SIGIO, POLL_IN); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2071 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2072 | else |
| 2073 | cmd->abort_aen = 0; |
| 2074 | |
| 2075 | instance->aen_cmd = NULL; |
| 2076 | megasas_return_cmd(instance, cmd); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2077 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2078 | if ((instance->unload == 0) && |
| 2079 | ((instance->issuepend_done == 1))) { |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2080 | struct megasas_aen_event *ev; |
| 2081 | ev = kzalloc(sizeof(*ev), GFP_ATOMIC); |
| 2082 | if (!ev) { |
| 2083 | printk(KERN_ERR "megasas_service_aen: out of memory\n"); |
| 2084 | } else { |
| 2085 | ev->instance = instance; |
| 2086 | instance->ev = ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 2087 | INIT_DELAYED_WORK(&ev->hotplug_work, |
| 2088 | megasas_aen_polling); |
| 2089 | schedule_delayed_work(&ev->hotplug_work, 0); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2090 | } |
| 2091 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2092 | } |
| 2093 | |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 2094 | static int megasas_change_queue_depth(struct scsi_device *sdev, |
| 2095 | int queue_depth, int reason) |
| 2096 | { |
| 2097 | if (reason != SCSI_QDEPTH_DEFAULT) |
| 2098 | return -EOPNOTSUPP; |
| 2099 | |
| 2100 | if (queue_depth > sdev->host->can_queue) |
| 2101 | queue_depth = sdev->host->can_queue; |
| 2102 | scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), |
| 2103 | queue_depth); |
| 2104 | |
| 2105 | return queue_depth; |
| 2106 | } |
| 2107 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2108 | /* |
| 2109 | * Scsi host template for megaraid_sas driver |
| 2110 | */ |
| 2111 | static struct scsi_host_template megasas_template = { |
| 2112 | |
| 2113 | .module = THIS_MODULE, |
bo yang | f28cd7c | 2007-11-09 04:44:56 -0500 | [diff] [blame] | 2114 | .name = "LSI SAS based MegaRAID driver", |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2115 | .proc_name = "megaraid_sas", |
Christoph Hellwig | 147aab6 | 2006-02-17 12:13:48 +0100 | [diff] [blame] | 2116 | .slave_configure = megasas_slave_configure, |
Yang, Bo | 044833b | 2009-10-06 14:33:06 -0600 | [diff] [blame] | 2117 | .slave_alloc = megasas_slave_alloc, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2118 | .queuecommand = megasas_queue_command, |
| 2119 | .eh_device_reset_handler = megasas_reset_device, |
| 2120 | .eh_bus_reset_handler = megasas_reset_bus_host, |
| 2121 | .eh_host_reset_handler = megasas_reset_bus_host, |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2122 | .eh_timed_out = megasas_reset_timer, |
Sumant Patro | cf62a0a | 2007-02-14 12:41:55 -0800 | [diff] [blame] | 2123 | .bios_param = megasas_bios_param, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2124 | .use_clustering = ENABLE_CLUSTERING, |
adam radford | 4bcde50 | 2011-07-26 15:42:52 -0700 | [diff] [blame] | 2125 | .change_queue_depth = megasas_change_queue_depth, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2126 | }; |
| 2127 | |
| 2128 | /** |
| 2129 | * megasas_complete_int_cmd - Completes an internal command |
| 2130 | * @instance: Adapter soft state |
| 2131 | * @cmd: Command to be completed |
| 2132 | * |
| 2133 | * The megasas_issue_blocked_cmd() function waits for a command to complete |
| 2134 | * after it issues a command. This function wakes up that waiting routine by |
| 2135 | * calling wake_up() on the wait queue. |
| 2136 | */ |
| 2137 | static void |
| 2138 | megasas_complete_int_cmd(struct megasas_instance *instance, |
| 2139 | struct megasas_cmd *cmd) |
| 2140 | { |
| 2141 | cmd->cmd_status = cmd->frame->io.cmd_status; |
| 2142 | |
| 2143 | if (cmd->cmd_status == ENODATA) { |
| 2144 | cmd->cmd_status = 0; |
| 2145 | } |
| 2146 | wake_up(&instance->int_cmd_wait_q); |
| 2147 | } |
| 2148 | |
| 2149 | /** |
| 2150 | * megasas_complete_abort - Completes aborting a command |
| 2151 | * @instance: Adapter soft state |
| 2152 | * @cmd: Cmd that was issued to abort another cmd |
| 2153 | * |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2154 | * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q |
| 2155 | * after it issues an abort on a previously issued command. This function |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2156 | * wakes up all functions waiting on the same wait queue. |
| 2157 | */ |
| 2158 | static void |
| 2159 | megasas_complete_abort(struct megasas_instance *instance, |
| 2160 | struct megasas_cmd *cmd) |
| 2161 | { |
| 2162 | if (cmd->sync_cmd) { |
| 2163 | cmd->sync_cmd = 0; |
| 2164 | cmd->cmd_status = 0; |
| 2165 | wake_up(&instance->abort_cmd_wait_q); |
| 2166 | } |
| 2167 | |
| 2168 | return; |
| 2169 | } |
| 2170 | |
| 2171 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2172 | * megasas_complete_cmd - Completes a command |
| 2173 | * @instance: Adapter soft state |
| 2174 | * @cmd: Command to be completed |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2175 | * @alt_status: If non-zero, use this value as status to |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2176 | * SCSI mid-layer instead of the value returned |
| 2177 | * by the FW. This should be used if caller wants |
| 2178 | * an alternate status (as in the case of aborted |
| 2179 | * commands) |
| 2180 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2181 | void |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2182 | megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 2183 | u8 alt_status) |
| 2184 | { |
| 2185 | int exception = 0; |
| 2186 | struct megasas_header *hdr = &cmd->frame->hdr; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2187 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2188 | struct fusion_context *fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2189 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2190 | /* flag for the retry reset */ |
| 2191 | cmd->retry_for_fw_reset = 0; |
| 2192 | |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 2193 | if (cmd->scmd) |
| 2194 | cmd->scmd->SCp.ptr = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2195 | |
| 2196 | switch (hdr->cmd) { |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 2197 | case MFI_CMD_INVALID: |
| 2198 | /* Some older 1068 controller FW may keep a pended |
| 2199 | MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel |
| 2200 | when booting the kdump kernel. Ignore this command to |
| 2201 | prevent a kernel panic on shutdown of the kdump kernel. */ |
| 2202 | printk(KERN_WARNING "megaraid_sas: MFI_CMD_INVALID command " |
| 2203 | "completed.\n"); |
| 2204 | printk(KERN_WARNING "megaraid_sas: If you have a controller " |
| 2205 | "other than PERC5, please upgrade your firmware.\n"); |
| 2206 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2207 | case MFI_CMD_PD_SCSI_IO: |
| 2208 | case MFI_CMD_LD_SCSI_IO: |
| 2209 | |
| 2210 | /* |
| 2211 | * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been |
| 2212 | * issued either through an IO path or an IOCTL path. If it |
| 2213 | * was via IOCTL, we will send it to internal completion. |
| 2214 | */ |
| 2215 | if (cmd->sync_cmd) { |
| 2216 | cmd->sync_cmd = 0; |
| 2217 | megasas_complete_int_cmd(instance, cmd); |
| 2218 | break; |
| 2219 | } |
| 2220 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2221 | case MFI_CMD_LD_READ: |
| 2222 | case MFI_CMD_LD_WRITE: |
| 2223 | |
| 2224 | if (alt_status) { |
| 2225 | cmd->scmd->result = alt_status << 16; |
| 2226 | exception = 1; |
| 2227 | } |
| 2228 | |
| 2229 | if (exception) { |
| 2230 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2231 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2232 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 2233 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2234 | cmd->scmd->scsi_done(cmd->scmd); |
| 2235 | megasas_return_cmd(instance, cmd); |
| 2236 | |
| 2237 | break; |
| 2238 | } |
| 2239 | |
| 2240 | switch (hdr->cmd_status) { |
| 2241 | |
| 2242 | case MFI_STAT_OK: |
| 2243 | cmd->scmd->result = DID_OK << 16; |
| 2244 | break; |
| 2245 | |
| 2246 | case MFI_STAT_SCSI_IO_FAILED: |
| 2247 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 2248 | cmd->scmd->result = |
| 2249 | (DID_ERROR << 16) | hdr->scsi_status; |
| 2250 | break; |
| 2251 | |
| 2252 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 2253 | |
| 2254 | cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status; |
| 2255 | |
| 2256 | if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) { |
| 2257 | memset(cmd->scmd->sense_buffer, 0, |
| 2258 | SCSI_SENSE_BUFFERSIZE); |
| 2259 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 2260 | hdr->sense_len); |
| 2261 | |
| 2262 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 2263 | } |
| 2264 | |
| 2265 | break; |
| 2266 | |
| 2267 | case MFI_STAT_LD_OFFLINE: |
| 2268 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 2269 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 2270 | break; |
| 2271 | |
| 2272 | default: |
| 2273 | printk(KERN_DEBUG "megasas: MFI FW status %#x\n", |
| 2274 | hdr->cmd_status); |
| 2275 | cmd->scmd->result = DID_ERROR << 16; |
| 2276 | break; |
| 2277 | } |
| 2278 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 2279 | atomic_dec(&instance->fw_outstanding); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2280 | |
FUJITA Tomonori | 155d98f | 2007-05-26 05:04:08 +0900 | [diff] [blame] | 2281 | scsi_dma_unmap(cmd->scmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2282 | cmd->scmd->scsi_done(cmd->scmd); |
| 2283 | megasas_return_cmd(instance, cmd); |
| 2284 | |
| 2285 | break; |
| 2286 | |
| 2287 | case MFI_CMD_SMP: |
| 2288 | case MFI_CMD_STP: |
| 2289 | case MFI_CMD_DCMD: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2290 | /* Check for LD map update */ |
| 2291 | if ((cmd->frame->dcmd.opcode == MR_DCMD_LD_MAP_GET_INFO) && |
| 2292 | (cmd->frame->dcmd.mbox.b[1] == 1)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 2293 | fusion->fast_path_io = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2294 | spin_lock_irqsave(instance->host->host_lock, flags); |
| 2295 | if (cmd->frame->hdr.cmd_status != 0) { |
| 2296 | if (cmd->frame->hdr.cmd_status != |
| 2297 | MFI_STAT_NOT_FOUND) |
| 2298 | printk(KERN_WARNING "megasas: map sync" |
| 2299 | "failed, status = 0x%x.\n", |
| 2300 | cmd->frame->hdr.cmd_status); |
| 2301 | else { |
| 2302 | megasas_return_cmd(instance, cmd); |
| 2303 | spin_unlock_irqrestore( |
| 2304 | instance->host->host_lock, |
| 2305 | flags); |
| 2306 | break; |
| 2307 | } |
| 2308 | } else |
| 2309 | instance->map_id++; |
| 2310 | megasas_return_cmd(instance, cmd); |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 2311 | |
| 2312 | /* |
| 2313 | * Set fast path IO to ZERO. |
| 2314 | * Validate Map will set proper value. |
| 2315 | * Meanwhile all IOs will go as LD IO. |
| 2316 | */ |
| 2317 | if (MR_ValidateMapInfo(instance)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2318 | fusion->fast_path_io = 1; |
| 2319 | else |
| 2320 | fusion->fast_path_io = 0; |
| 2321 | megasas_sync_map_info(instance); |
| 2322 | spin_unlock_irqrestore(instance->host->host_lock, |
| 2323 | flags); |
| 2324 | break; |
| 2325 | } |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 2326 | if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET_INFO || |
| 2327 | cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_GET) { |
| 2328 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 2329 | megasas_poll_wait_aen = 0; |
| 2330 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 2331 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2332 | |
| 2333 | /* |
| 2334 | * See if got an event notification |
| 2335 | */ |
| 2336 | if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_WAIT) |
| 2337 | megasas_service_aen(instance, cmd); |
| 2338 | else |
| 2339 | megasas_complete_int_cmd(instance, cmd); |
| 2340 | |
| 2341 | break; |
| 2342 | |
| 2343 | case MFI_CMD_ABORT: |
| 2344 | /* |
| 2345 | * Cmd issued to abort another cmd returned |
| 2346 | */ |
| 2347 | megasas_complete_abort(instance, cmd); |
| 2348 | break; |
| 2349 | |
| 2350 | default: |
| 2351 | printk("megasas: Unknown command completed! [0x%X]\n", |
| 2352 | hdr->cmd); |
| 2353 | break; |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | /** |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2358 | * megasas_issue_pending_cmds_again - issue all pending cmds |
| 2359 | * in FW again because of the fw reset |
| 2360 | * @instance: Adapter soft state |
| 2361 | */ |
| 2362 | static inline void |
| 2363 | megasas_issue_pending_cmds_again(struct megasas_instance *instance) |
| 2364 | { |
| 2365 | struct megasas_cmd *cmd; |
| 2366 | struct list_head clist_local; |
| 2367 | union megasas_evt_class_locale class_locale; |
| 2368 | unsigned long flags; |
| 2369 | u32 seq_num; |
| 2370 | |
| 2371 | INIT_LIST_HEAD(&clist_local); |
| 2372 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2373 | list_splice_init(&instance->internal_reset_pending_q, &clist_local); |
| 2374 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2375 | |
| 2376 | while (!list_empty(&clist_local)) { |
| 2377 | cmd = list_entry((&clist_local)->next, |
| 2378 | struct megasas_cmd, list); |
| 2379 | list_del_init(&cmd->list); |
| 2380 | |
| 2381 | if (cmd->sync_cmd || cmd->scmd) { |
| 2382 | printk(KERN_NOTICE "megaraid_sas: command %p, %p:%d" |
| 2383 | "detected to be pending while HBA reset.\n", |
| 2384 | cmd, cmd->scmd, cmd->sync_cmd); |
| 2385 | |
| 2386 | cmd->retry_for_fw_reset++; |
| 2387 | |
| 2388 | if (cmd->retry_for_fw_reset == 3) { |
| 2389 | printk(KERN_NOTICE "megaraid_sas: cmd %p, %p:%d" |
| 2390 | "was tried multiple times during reset." |
| 2391 | "Shutting down the HBA\n", |
| 2392 | cmd, cmd->scmd, cmd->sync_cmd); |
| 2393 | megaraid_sas_kill_hba(instance); |
| 2394 | |
| 2395 | instance->adprecovery = |
| 2396 | MEGASAS_HW_CRITICAL_ERROR; |
| 2397 | return; |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | if (cmd->sync_cmd == 1) { |
| 2402 | if (cmd->scmd) { |
| 2403 | printk(KERN_NOTICE "megaraid_sas: unexpected" |
| 2404 | "cmd attached to internal command!\n"); |
| 2405 | } |
| 2406 | printk(KERN_NOTICE "megasas: %p synchronous cmd" |
| 2407 | "on the internal reset queue," |
| 2408 | "issue it again.\n", cmd); |
| 2409 | cmd->cmd_status = ENODATA; |
| 2410 | instance->instancet->fire_cmd(instance, |
| 2411 | cmd->frame_phys_addr , |
| 2412 | 0, instance->reg_set); |
| 2413 | } else if (cmd->scmd) { |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2414 | printk(KERN_NOTICE "megasas: %p scsi cmd [%02x]" |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2415 | "detected on the internal queue, issue again.\n", |
Christoph Hellwig | 5cd049a | 2011-04-04 09:42:14 -0400 | [diff] [blame] | 2416 | cmd, cmd->scmd->cmnd[0]); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2417 | |
| 2418 | atomic_inc(&instance->fw_outstanding); |
| 2419 | instance->instancet->fire_cmd(instance, |
| 2420 | cmd->frame_phys_addr, |
| 2421 | cmd->frame_count-1, instance->reg_set); |
| 2422 | } else { |
| 2423 | printk(KERN_NOTICE "megasas: %p unexpected cmd on the" |
| 2424 | "internal reset defer list while re-issue!!\n", |
| 2425 | cmd); |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | if (instance->aen_cmd) { |
| 2430 | printk(KERN_NOTICE "megaraid_sas: aen_cmd in def process\n"); |
| 2431 | megasas_return_cmd(instance, instance->aen_cmd); |
| 2432 | |
| 2433 | instance->aen_cmd = NULL; |
| 2434 | } |
| 2435 | |
| 2436 | /* |
| 2437 | * Initiate AEN (Asynchronous Event Notification) |
| 2438 | */ |
| 2439 | seq_num = instance->last_seq_num; |
| 2440 | class_locale.members.reserved = 0; |
| 2441 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 2442 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 2443 | |
| 2444 | megasas_register_aen(instance, seq_num, class_locale.word); |
| 2445 | } |
| 2446 | |
| 2447 | /** |
| 2448 | * Move the internal reset pending commands to a deferred queue. |
| 2449 | * |
| 2450 | * We move the commands pending at internal reset time to a |
| 2451 | * pending queue. This queue would be flushed after successful |
| 2452 | * completion of the internal reset sequence. if the internal reset |
| 2453 | * did not complete in time, the kernel reset handler would flush |
| 2454 | * these commands. |
| 2455 | **/ |
| 2456 | static void |
| 2457 | megasas_internal_reset_defer_cmds(struct megasas_instance *instance) |
| 2458 | { |
| 2459 | struct megasas_cmd *cmd; |
| 2460 | int i; |
| 2461 | u32 max_cmd = instance->max_fw_cmds; |
| 2462 | u32 defer_index; |
| 2463 | unsigned long flags; |
| 2464 | |
| 2465 | defer_index = 0; |
| 2466 | spin_lock_irqsave(&instance->cmd_pool_lock, flags); |
| 2467 | for (i = 0; i < max_cmd; i++) { |
| 2468 | cmd = instance->cmd_list[i]; |
| 2469 | if (cmd->sync_cmd == 1 || cmd->scmd) { |
| 2470 | printk(KERN_NOTICE "megasas: moving cmd[%d]:%p:%d:%p" |
| 2471 | "on the defer queue as internal\n", |
| 2472 | defer_index, cmd, cmd->sync_cmd, cmd->scmd); |
| 2473 | |
| 2474 | if (!list_empty(&cmd->list)) { |
| 2475 | printk(KERN_NOTICE "megaraid_sas: ERROR while" |
| 2476 | " moving this cmd:%p, %d %p, it was" |
| 2477 | "discovered on some list?\n", |
| 2478 | cmd, cmd->sync_cmd, cmd->scmd); |
| 2479 | |
| 2480 | list_del_init(&cmd->list); |
| 2481 | } |
| 2482 | defer_index++; |
| 2483 | list_add_tail(&cmd->list, |
| 2484 | &instance->internal_reset_pending_q); |
| 2485 | } |
| 2486 | } |
| 2487 | spin_unlock_irqrestore(&instance->cmd_pool_lock, flags); |
| 2488 | } |
| 2489 | |
| 2490 | |
| 2491 | static void |
| 2492 | process_fw_state_change_wq(struct work_struct *work) |
| 2493 | { |
| 2494 | struct megasas_instance *instance = |
| 2495 | container_of(work, struct megasas_instance, work_init); |
| 2496 | u32 wait; |
| 2497 | unsigned long flags; |
| 2498 | |
| 2499 | if (instance->adprecovery != MEGASAS_ADPRESET_SM_INFAULT) { |
| 2500 | printk(KERN_NOTICE "megaraid_sas: error, recovery st %x \n", |
| 2501 | instance->adprecovery); |
| 2502 | return ; |
| 2503 | } |
| 2504 | |
| 2505 | if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) { |
| 2506 | printk(KERN_NOTICE "megaraid_sas: FW detected to be in fault" |
| 2507 | "state, restarting it...\n"); |
| 2508 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2509 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2510 | atomic_set(&instance->fw_outstanding, 0); |
| 2511 | |
| 2512 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 2513 | instance->instancet->adp_reset(instance, instance->reg_set); |
| 2514 | atomic_set(&instance->fw_reset_no_pci_access, 0 ); |
| 2515 | |
| 2516 | printk(KERN_NOTICE "megaraid_sas: FW restarted successfully," |
| 2517 | "initiating next stage...\n"); |
| 2518 | |
| 2519 | printk(KERN_NOTICE "megaraid_sas: HBA recovery state machine," |
| 2520 | "state 2 starting...\n"); |
| 2521 | |
| 2522 | /*waitting for about 20 second before start the second init*/ |
| 2523 | for (wait = 0; wait < 30; wait++) { |
| 2524 | msleep(1000); |
| 2525 | } |
| 2526 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 2527 | if (megasas_transition_to_ready(instance, 1)) { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2528 | printk(KERN_NOTICE "megaraid_sas:adapter not ready\n"); |
| 2529 | |
| 2530 | megaraid_sas_kill_hba(instance); |
| 2531 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 2532 | return ; |
| 2533 | } |
| 2534 | |
| 2535 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2536 | (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) || |
| 2537 | (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR) |
| 2538 | ) { |
| 2539 | *instance->consumer = *instance->producer; |
| 2540 | } else { |
| 2541 | *instance->consumer = 0; |
| 2542 | *instance->producer = 0; |
| 2543 | } |
| 2544 | |
| 2545 | megasas_issue_init_mfi(instance); |
| 2546 | |
| 2547 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2548 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
| 2549 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2550 | instance->instancet->enable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2551 | |
| 2552 | megasas_issue_pending_cmds_again(instance); |
| 2553 | instance->issuepend_done = 1; |
| 2554 | } |
| 2555 | return ; |
| 2556 | } |
| 2557 | |
| 2558 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2559 | * megasas_deplete_reply_queue - Processes all completed commands |
| 2560 | * @instance: Adapter soft state |
| 2561 | * @alt_status: Alternate status to be returned to |
| 2562 | * SCSI mid-layer instead of the status |
| 2563 | * returned by the FW |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2564 | * Note: this must be called with hba lock held |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2565 | */ |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 2566 | static int |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2567 | megasas_deplete_reply_queue(struct megasas_instance *instance, |
| 2568 | u8 alt_status) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2569 | { |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2570 | u32 mfiStatus; |
| 2571 | u32 fw_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2572 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2573 | if ((mfiStatus = instance->instancet->check_reset(instance, |
| 2574 | instance->reg_set)) == 1) { |
| 2575 | return IRQ_HANDLED; |
| 2576 | } |
| 2577 | |
| 2578 | if ((mfiStatus = instance->instancet->clear_intr( |
| 2579 | instance->reg_set) |
| 2580 | ) == 0) { |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 2581 | /* Hardware may not set outbound_intr_status in MSI-X mode */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2582 | if (!instance->msix_vectors) |
adam radford | e141919 | 2011-02-24 20:56:21 -0800 | [diff] [blame] | 2583 | return IRQ_NONE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | instance->mfiStatus = mfiStatus; |
| 2587 | |
| 2588 | if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) { |
| 2589 | fw_state = instance->instancet->read_fw_status_reg( |
| 2590 | instance->reg_set) & MFI_STATE_MASK; |
| 2591 | |
| 2592 | if (fw_state != MFI_STATE_FAULT) { |
| 2593 | printk(KERN_NOTICE "megaraid_sas: fw state:%x\n", |
| 2594 | fw_state); |
| 2595 | } |
| 2596 | |
| 2597 | if ((fw_state == MFI_STATE_FAULT) && |
| 2598 | (instance->disableOnlineCtrlReset == 0)) { |
| 2599 | printk(KERN_NOTICE "megaraid_sas: wait adp restart\n"); |
| 2600 | |
| 2601 | if ((instance->pdev->device == |
| 2602 | PCI_DEVICE_ID_LSI_SAS1064R) || |
| 2603 | (instance->pdev->device == |
| 2604 | PCI_DEVICE_ID_DELL_PERC5) || |
| 2605 | (instance->pdev->device == |
| 2606 | PCI_DEVICE_ID_LSI_VERDE_ZCR)) { |
| 2607 | |
| 2608 | *instance->consumer = |
| 2609 | MEGASAS_ADPRESET_INPROG_SIGN; |
| 2610 | } |
| 2611 | |
| 2612 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2613 | instance->instancet->disable_intr(instance); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2614 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
| 2615 | instance->issuepend_done = 0; |
| 2616 | |
| 2617 | atomic_set(&instance->fw_outstanding, 0); |
| 2618 | megasas_internal_reset_defer_cmds(instance); |
| 2619 | |
| 2620 | printk(KERN_NOTICE "megasas: fwState=%x, stage:%d\n", |
| 2621 | fw_state, instance->adprecovery); |
| 2622 | |
| 2623 | schedule_work(&instance->work_init); |
| 2624 | return IRQ_HANDLED; |
| 2625 | |
| 2626 | } else { |
| 2627 | printk(KERN_NOTICE "megasas: fwstate:%x, dis_OCR=%x\n", |
| 2628 | fw_state, instance->disableOnlineCtrlReset); |
| 2629 | } |
| 2630 | } |
| 2631 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 2632 | tasklet_schedule(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2633 | return IRQ_HANDLED; |
| 2634 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2635 | /** |
| 2636 | * megasas_isr - isr entry point |
| 2637 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2638 | static irqreturn_t megasas_isr(int irq, void *devp) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2639 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2640 | struct megasas_irq_context *irq_context = devp; |
| 2641 | struct megasas_instance *instance = irq_context->instance; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2642 | unsigned long flags; |
| 2643 | irqreturn_t rc; |
| 2644 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2645 | if (atomic_read(&instance->fw_reset_no_pci_access)) |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2646 | return IRQ_HANDLED; |
| 2647 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2648 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2649 | rc = megasas_deplete_reply_queue(instance, DID_OK); |
| 2650 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2651 | |
| 2652 | return rc; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | /** |
| 2656 | * megasas_transition_to_ready - Move the FW to READY state |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 2657 | * @instance: Adapter soft state |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2658 | * |
| 2659 | * During the initialization, FW passes can potentially be in any one of |
| 2660 | * several possible states. If the FW in operational, waiting-for-handshake |
| 2661 | * states, driver must take steps to bring it to ready state. Otherwise, it |
| 2662 | * has to wait for the ready state. |
| 2663 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2664 | int |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 2665 | megasas_transition_to_ready(struct megasas_instance *instance, int ocr) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2666 | { |
| 2667 | int i; |
| 2668 | u8 max_wait; |
| 2669 | u32 fw_state; |
| 2670 | u32 cur_state; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2671 | u32 abs_state, curr_abs_state; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2672 | |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 2673 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2674 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2675 | if (fw_state != MFI_STATE_READY) |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2676 | printk(KERN_INFO "megasas: Waiting for FW to come to ready" |
| 2677 | " state\n"); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2678 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2679 | while (fw_state != MFI_STATE_READY) { |
| 2680 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2681 | abs_state = |
| 2682 | instance->instancet->read_fw_status_reg(instance->reg_set); |
| 2683 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2684 | switch (fw_state) { |
| 2685 | |
| 2686 | case MFI_STATE_FAULT: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2687 | printk(KERN_DEBUG "megasas: FW in FAULT state!!\n"); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 2688 | if (ocr) { |
| 2689 | max_wait = MEGASAS_RESET_WAIT_TIME; |
| 2690 | cur_state = MFI_STATE_FAULT; |
| 2691 | break; |
| 2692 | } else |
| 2693 | return -ENODEV; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2694 | |
| 2695 | case MFI_STATE_WAIT_HANDSHAKE: |
| 2696 | /* |
| 2697 | * Set the CLR bit in inbound doorbell |
| 2698 | */ |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 2699 | if ((instance->pdev->device == |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2700 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 2701 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2702 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
| 2703 | (instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2704 | PCI_DEVICE_ID_LSI_FUSION) || |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2705 | (instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2706 | PCI_DEVICE_ID_LSI_INVADER) || |
| 2707 | (instance->pdev->device == |
| 2708 | PCI_DEVICE_ID_LSI_FURY)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2709 | writel( |
| 2710 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2711 | &instance->reg_set->doorbell); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2712 | } else { |
| 2713 | writel( |
| 2714 | MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG, |
| 2715 | &instance->reg_set->inbound_doorbell); |
| 2716 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2717 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2718 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2719 | cur_state = MFI_STATE_WAIT_HANDSHAKE; |
| 2720 | break; |
| 2721 | |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2722 | case MFI_STATE_BOOT_MESSAGE_PENDING: |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2723 | if ((instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2724 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 2725 | (instance->pdev->device == |
| 2726 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
| 2727 | (instance->pdev->device == |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2728 | PCI_DEVICE_ID_LSI_FUSION) || |
| 2729 | (instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2730 | PCI_DEVICE_ID_LSI_INVADER) || |
| 2731 | (instance->pdev->device == |
| 2732 | PCI_DEVICE_ID_LSI_FURY)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2733 | writel(MFI_INIT_HOTPLUG, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2734 | &instance->reg_set->doorbell); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2735 | } else |
| 2736 | writel(MFI_INIT_HOTPLUG, |
| 2737 | &instance->reg_set->inbound_doorbell); |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2738 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2739 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2740 | cur_state = MFI_STATE_BOOT_MESSAGE_PENDING; |
| 2741 | break; |
| 2742 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2743 | case MFI_STATE_OPERATIONAL: |
| 2744 | /* |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2745 | * Bring it to READY state; assuming max wait 10 secs |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2746 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2747 | instance->instancet->disable_intr(instance); |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2748 | if ((instance->pdev->device == |
| 2749 | PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 2750 | (instance->pdev->device == |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2751 | PCI_DEVICE_ID_LSI_SAS0071SKINNY) || |
| 2752 | (instance->pdev->device |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2753 | == PCI_DEVICE_ID_LSI_FUSION) || |
| 2754 | (instance->pdev->device |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2755 | == PCI_DEVICE_ID_LSI_INVADER) || |
| 2756 | (instance->pdev->device |
| 2757 | == PCI_DEVICE_ID_LSI_FURY)) { |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2758 | writel(MFI_RESET_FLAGS, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2759 | &instance->reg_set->doorbell); |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2760 | if ((instance->pdev->device == |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2761 | PCI_DEVICE_ID_LSI_FUSION) || |
| 2762 | (instance->pdev->device == |
| 2763 | PCI_DEVICE_ID_LSI_INVADER) || |
| 2764 | (instance->pdev->device == |
| 2765 | PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2766 | for (i = 0; i < (10 * 1000); i += 20) { |
| 2767 | if (readl( |
| 2768 | &instance-> |
| 2769 | reg_set-> |
| 2770 | doorbell) & 1) |
| 2771 | msleep(20); |
| 2772 | else |
| 2773 | break; |
| 2774 | } |
| 2775 | } |
Yang, Bo | 8791112 | 2009-10-06 14:31:54 -0600 | [diff] [blame] | 2776 | } else |
| 2777 | writel(MFI_RESET_FLAGS, |
| 2778 | &instance->reg_set->inbound_doorbell); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2779 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2780 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2781 | cur_state = MFI_STATE_OPERATIONAL; |
| 2782 | break; |
| 2783 | |
| 2784 | case MFI_STATE_UNDEFINED: |
| 2785 | /* |
| 2786 | * This state should not last for more than 2 seconds |
| 2787 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2788 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2789 | cur_state = MFI_STATE_UNDEFINED; |
| 2790 | break; |
| 2791 | |
| 2792 | case MFI_STATE_BB_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2793 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2794 | cur_state = MFI_STATE_BB_INIT; |
| 2795 | break; |
| 2796 | |
| 2797 | case MFI_STATE_FW_INIT: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2798 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2799 | cur_state = MFI_STATE_FW_INIT; |
| 2800 | break; |
| 2801 | |
| 2802 | case MFI_STATE_FW_INIT_2: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2803 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2804 | cur_state = MFI_STATE_FW_INIT_2; |
| 2805 | break; |
| 2806 | |
| 2807 | case MFI_STATE_DEVICE_SCAN: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2808 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2809 | cur_state = MFI_STATE_DEVICE_SCAN; |
| 2810 | break; |
| 2811 | |
| 2812 | case MFI_STATE_FLUSH_CACHE: |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2813 | max_wait = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2814 | cur_state = MFI_STATE_FLUSH_CACHE; |
| 2815 | break; |
| 2816 | |
| 2817 | default: |
| 2818 | printk(KERN_DEBUG "megasas: Unknown state 0x%x\n", |
| 2819 | fw_state); |
| 2820 | return -ENODEV; |
| 2821 | } |
| 2822 | |
| 2823 | /* |
| 2824 | * The cur_state should not last for more than max_wait secs |
| 2825 | */ |
| 2826 | for (i = 0; i < (max_wait * 1000); i++) { |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2827 | fw_state = instance->instancet->read_fw_status_reg(instance->reg_set) & |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 2828 | MFI_STATE_MASK ; |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2829 | curr_abs_state = |
| 2830 | instance->instancet->read_fw_status_reg(instance->reg_set); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2831 | |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2832 | if (abs_state == curr_abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2833 | msleep(1); |
| 2834 | } else |
| 2835 | break; |
| 2836 | } |
| 2837 | |
| 2838 | /* |
| 2839 | * Return error if fw_state hasn't changed after max_wait |
| 2840 | */ |
Yang, Bo | 7218df6 | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 2841 | if (curr_abs_state == abs_state) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2842 | printk(KERN_DEBUG "FW state [%d] hasn't changed " |
| 2843 | "in %d secs\n", fw_state, max_wait); |
| 2844 | return -ENODEV; |
| 2845 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2846 | } |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 2847 | printk(KERN_INFO "megasas: FW now in Ready state\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2848 | |
| 2849 | return 0; |
| 2850 | } |
| 2851 | |
| 2852 | /** |
| 2853 | * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool |
| 2854 | * @instance: Adapter soft state |
| 2855 | */ |
| 2856 | static void megasas_teardown_frame_pool(struct megasas_instance *instance) |
| 2857 | { |
| 2858 | int i; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2859 | u32 max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2860 | struct megasas_cmd *cmd; |
| 2861 | |
| 2862 | if (!instance->frame_dma_pool) |
| 2863 | return; |
| 2864 | |
| 2865 | /* |
| 2866 | * Return all frames to pool |
| 2867 | */ |
| 2868 | for (i = 0; i < max_cmd; i++) { |
| 2869 | |
| 2870 | cmd = instance->cmd_list[i]; |
| 2871 | |
| 2872 | if (cmd->frame) |
| 2873 | pci_pool_free(instance->frame_dma_pool, cmd->frame, |
| 2874 | cmd->frame_phys_addr); |
| 2875 | |
| 2876 | if (cmd->sense) |
Sumant Patro | e3bbff9 | 2006-10-03 12:28:49 -0700 | [diff] [blame] | 2877 | pci_pool_free(instance->sense_dma_pool, cmd->sense, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2878 | cmd->sense_phys_addr); |
| 2879 | } |
| 2880 | |
| 2881 | /* |
| 2882 | * Now destroy the pool itself |
| 2883 | */ |
| 2884 | pci_pool_destroy(instance->frame_dma_pool); |
| 2885 | pci_pool_destroy(instance->sense_dma_pool); |
| 2886 | |
| 2887 | instance->frame_dma_pool = NULL; |
| 2888 | instance->sense_dma_pool = NULL; |
| 2889 | } |
| 2890 | |
| 2891 | /** |
| 2892 | * megasas_create_frame_pool - Creates DMA pool for cmd frames |
| 2893 | * @instance: Adapter soft state |
| 2894 | * |
| 2895 | * Each command packet has an embedded DMA memory buffer that is used for |
| 2896 | * filling MFI frame and the SG list that immediately follows the frame. This |
| 2897 | * function creates those DMA memory buffers for each command packet by using |
| 2898 | * PCI pool facility. |
| 2899 | */ |
| 2900 | static int megasas_create_frame_pool(struct megasas_instance *instance) |
| 2901 | { |
| 2902 | int i; |
| 2903 | u32 max_cmd; |
| 2904 | u32 sge_sz; |
| 2905 | u32 sgl_sz; |
| 2906 | u32 total_sz; |
| 2907 | u32 frame_count; |
| 2908 | struct megasas_cmd *cmd; |
| 2909 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2910 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2911 | |
| 2912 | /* |
| 2913 | * Size of our frame is 64 bytes for MFI frame, followed by max SG |
| 2914 | * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer |
| 2915 | */ |
| 2916 | sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) : |
| 2917 | sizeof(struct megasas_sge32); |
| 2918 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 2919 | if (instance->flag_ieee) { |
| 2920 | sge_sz = sizeof(struct megasas_sge_skinny); |
| 2921 | } |
| 2922 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2923 | /* |
| 2924 | * Calculated the number of 64byte frames required for SGL |
| 2925 | */ |
| 2926 | sgl_sz = sge_sz * instance->max_num_sge; |
| 2927 | frame_count = (sgl_sz + MEGAMFI_FRAME_SIZE - 1) / MEGAMFI_FRAME_SIZE; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 2928 | frame_count = 15; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2929 | |
| 2930 | /* |
| 2931 | * We need one extra frame for the MFI command |
| 2932 | */ |
| 2933 | frame_count++; |
| 2934 | |
| 2935 | total_sz = MEGAMFI_FRAME_SIZE * frame_count; |
| 2936 | /* |
| 2937 | * Use DMA pool facility provided by PCI layer |
| 2938 | */ |
| 2939 | instance->frame_dma_pool = pci_pool_create("megasas frame pool", |
| 2940 | instance->pdev, total_sz, 64, |
| 2941 | 0); |
| 2942 | |
| 2943 | if (!instance->frame_dma_pool) { |
| 2944 | printk(KERN_DEBUG "megasas: failed to setup frame pool\n"); |
| 2945 | return -ENOMEM; |
| 2946 | } |
| 2947 | |
| 2948 | instance->sense_dma_pool = pci_pool_create("megasas sense pool", |
| 2949 | instance->pdev, 128, 4, 0); |
| 2950 | |
| 2951 | if (!instance->sense_dma_pool) { |
| 2952 | printk(KERN_DEBUG "megasas: failed to setup sense pool\n"); |
| 2953 | |
| 2954 | pci_pool_destroy(instance->frame_dma_pool); |
| 2955 | instance->frame_dma_pool = NULL; |
| 2956 | |
| 2957 | return -ENOMEM; |
| 2958 | } |
| 2959 | |
| 2960 | /* |
| 2961 | * Allocate and attach a frame to each of the commands in cmd_list. |
| 2962 | * By making cmd->index as the context instead of the &cmd, we can |
| 2963 | * always use 32bit context regardless of the architecture |
| 2964 | */ |
| 2965 | for (i = 0; i < max_cmd; i++) { |
| 2966 | |
| 2967 | cmd = instance->cmd_list[i]; |
| 2968 | |
| 2969 | cmd->frame = pci_pool_alloc(instance->frame_dma_pool, |
| 2970 | GFP_KERNEL, &cmd->frame_phys_addr); |
| 2971 | |
| 2972 | cmd->sense = pci_pool_alloc(instance->sense_dma_pool, |
| 2973 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 2974 | |
| 2975 | /* |
| 2976 | * megasas_teardown_frame_pool() takes care of freeing |
| 2977 | * whatever has been allocated |
| 2978 | */ |
| 2979 | if (!cmd->frame || !cmd->sense) { |
| 2980 | printk(KERN_DEBUG "megasas: pci_pool_alloc failed \n"); |
| 2981 | megasas_teardown_frame_pool(instance); |
| 2982 | return -ENOMEM; |
| 2983 | } |
| 2984 | |
Yang, Bo | 707e09b | 2010-10-12 07:20:27 -0600 | [diff] [blame] | 2985 | memset(cmd->frame, 0, total_sz); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2986 | cmd->frame->io.context = cmd->index; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 2987 | cmd->frame->io.pad_0 = 0; |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 2988 | if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) && |
| 2989 | (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) && |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2990 | (instance->pdev->device != PCI_DEVICE_ID_LSI_FURY) && |
adam radford | e5f93a3 | 2011-10-08 18:15:19 -0700 | [diff] [blame] | 2991 | (reset_devices)) |
| 2992 | cmd->frame->hdr.cmd = MFI_CMD_INVALID; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
| 2998 | /** |
| 2999 | * megasas_free_cmds - Free all the cmds in the free cmd pool |
| 3000 | * @instance: Adapter soft state |
| 3001 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3002 | void megasas_free_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3003 | { |
| 3004 | int i; |
| 3005 | /* First free the MFI frame pool */ |
| 3006 | megasas_teardown_frame_pool(instance); |
| 3007 | |
| 3008 | /* Free all the commands in the cmd_list */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3009 | for (i = 0; i < instance->max_mfi_cmds; i++) |
| 3010 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3011 | kfree(instance->cmd_list[i]); |
| 3012 | |
| 3013 | /* Free the cmd_list buffer itself */ |
| 3014 | kfree(instance->cmd_list); |
| 3015 | instance->cmd_list = NULL; |
| 3016 | |
| 3017 | INIT_LIST_HEAD(&instance->cmd_pool); |
| 3018 | } |
| 3019 | |
| 3020 | /** |
| 3021 | * megasas_alloc_cmds - Allocates the command packets |
| 3022 | * @instance: Adapter soft state |
| 3023 | * |
| 3024 | * Each command that is issued to the FW, whether IO commands from the OS or |
| 3025 | * internal commands like IOCTLs, are wrapped in local data structure called |
| 3026 | * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to |
| 3027 | * the FW. |
| 3028 | * |
| 3029 | * Each frame has a 32-bit field called context (tag). This context is used |
| 3030 | * to get back the megasas_cmd from the frame when a frame gets completed in |
| 3031 | * the ISR. Typically the address of the megasas_cmd itself would be used as |
| 3032 | * the context. But we wanted to keep the differences between 32 and 64 bit |
| 3033 | * systems to the mininum. We always use 32 bit integers for the context. In |
| 3034 | * this driver, the 32 bit values are the indices into an array cmd_list. |
| 3035 | * This array is used only to look up the megasas_cmd given the context. The |
| 3036 | * free commands themselves are maintained in a linked list called cmd_pool. |
| 3037 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3038 | int megasas_alloc_cmds(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3039 | { |
| 3040 | int i; |
| 3041 | int j; |
| 3042 | u32 max_cmd; |
| 3043 | struct megasas_cmd *cmd; |
| 3044 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3045 | max_cmd = instance->max_mfi_cmds; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3046 | |
| 3047 | /* |
| 3048 | * instance->cmd_list is an array of struct megasas_cmd pointers. |
| 3049 | * Allocate the dynamic array first and then allocate individual |
| 3050 | * commands. |
| 3051 | */ |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 3052 | instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3053 | |
| 3054 | if (!instance->cmd_list) { |
| 3055 | printk(KERN_DEBUG "megasas: out of memory\n"); |
| 3056 | return -ENOMEM; |
| 3057 | } |
| 3058 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3059 | memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3060 | |
| 3061 | for (i = 0; i < max_cmd; i++) { |
| 3062 | instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd), |
| 3063 | GFP_KERNEL); |
| 3064 | |
| 3065 | if (!instance->cmd_list[i]) { |
| 3066 | |
| 3067 | for (j = 0; j < i; j++) |
| 3068 | kfree(instance->cmd_list[j]); |
| 3069 | |
| 3070 | kfree(instance->cmd_list); |
| 3071 | instance->cmd_list = NULL; |
| 3072 | |
| 3073 | return -ENOMEM; |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | /* |
| 3078 | * Add all the commands to command pool (instance->cmd_pool) |
| 3079 | */ |
| 3080 | for (i = 0; i < max_cmd; i++) { |
| 3081 | cmd = instance->cmd_list[i]; |
| 3082 | memset(cmd, 0, sizeof(struct megasas_cmd)); |
| 3083 | cmd->index = i; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3084 | cmd->scmd = NULL; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3085 | cmd->instance = instance; |
| 3086 | |
| 3087 | list_add_tail(&cmd->list, &instance->cmd_pool); |
| 3088 | } |
| 3089 | |
| 3090 | /* |
| 3091 | * Create a frame pool and assign one frame to each cmd |
| 3092 | */ |
| 3093 | if (megasas_create_frame_pool(instance)) { |
| 3094 | printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n"); |
| 3095 | megasas_free_cmds(instance); |
| 3096 | } |
| 3097 | |
| 3098 | return 0; |
| 3099 | } |
| 3100 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3101 | /* |
| 3102 | * megasas_get_pd_list_info - Returns FW's pd_list structure |
| 3103 | * @instance: Adapter soft state |
| 3104 | * @pd_list: pd_list structure |
| 3105 | * |
| 3106 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 3107 | * list structure. This information is mainly used to find out SYSTEM |
| 3108 | * supported by the FW. |
| 3109 | */ |
| 3110 | static int |
| 3111 | megasas_get_pd_list(struct megasas_instance *instance) |
| 3112 | { |
| 3113 | int ret = 0, pd_index = 0; |
| 3114 | struct megasas_cmd *cmd; |
| 3115 | struct megasas_dcmd_frame *dcmd; |
| 3116 | struct MR_PD_LIST *ci; |
| 3117 | struct MR_PD_ADDRESS *pd_addr; |
| 3118 | dma_addr_t ci_h = 0; |
| 3119 | |
| 3120 | cmd = megasas_get_cmd(instance); |
| 3121 | |
| 3122 | if (!cmd) { |
| 3123 | printk(KERN_DEBUG "megasas (get_pd_list): Failed to get cmd\n"); |
| 3124 | return -ENOMEM; |
| 3125 | } |
| 3126 | |
| 3127 | dcmd = &cmd->frame->dcmd; |
| 3128 | |
| 3129 | ci = pci_alloc_consistent(instance->pdev, |
| 3130 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h); |
| 3131 | |
| 3132 | if (!ci) { |
| 3133 | printk(KERN_DEBUG "Failed to alloc mem for pd_list\n"); |
| 3134 | megasas_return_cmd(instance, cmd); |
| 3135 | return -ENOMEM; |
| 3136 | } |
| 3137 | |
| 3138 | memset(ci, 0, sizeof(*ci)); |
| 3139 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3140 | |
| 3141 | dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST; |
| 3142 | dcmd->mbox.b[1] = 0; |
| 3143 | dcmd->cmd = MFI_CMD_DCMD; |
| 3144 | dcmd->cmd_status = 0xFF; |
| 3145 | dcmd->sge_count = 1; |
| 3146 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 3147 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 3148 | dcmd->pad_0 = 0; |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3149 | dcmd->data_xfer_len = MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST); |
| 3150 | dcmd->opcode = MR_DCMD_PD_LIST_QUERY; |
| 3151 | dcmd->sgl.sge32[0].phys_addr = ci_h; |
| 3152 | dcmd->sgl.sge32[0].length = MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST); |
| 3153 | |
| 3154 | if (!megasas_issue_polled(instance, cmd)) { |
| 3155 | ret = 0; |
| 3156 | } else { |
| 3157 | ret = -1; |
| 3158 | } |
| 3159 | |
| 3160 | /* |
| 3161 | * the following function will get the instance PD LIST. |
| 3162 | */ |
| 3163 | |
| 3164 | pd_addr = ci->addr; |
| 3165 | |
| 3166 | if ( ret == 0 && |
| 3167 | (ci->count < |
| 3168 | (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) { |
| 3169 | |
| 3170 | memset(instance->pd_list, 0, |
| 3171 | MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)); |
| 3172 | |
| 3173 | for (pd_index = 0; pd_index < ci->count; pd_index++) { |
| 3174 | |
| 3175 | instance->pd_list[pd_addr->deviceId].tid = |
| 3176 | pd_addr->deviceId; |
| 3177 | instance->pd_list[pd_addr->deviceId].driveType = |
| 3178 | pd_addr->scsiDevType; |
| 3179 | instance->pd_list[pd_addr->deviceId].driveState = |
| 3180 | MR_PD_STATE_SYSTEM; |
| 3181 | pd_addr++; |
| 3182 | } |
| 3183 | } |
| 3184 | |
| 3185 | pci_free_consistent(instance->pdev, |
| 3186 | MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), |
| 3187 | ci, ci_h); |
| 3188 | megasas_return_cmd(instance, cmd); |
| 3189 | |
| 3190 | return ret; |
| 3191 | } |
| 3192 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3193 | /* |
| 3194 | * megasas_get_ld_list_info - Returns FW's ld_list structure |
| 3195 | * @instance: Adapter soft state |
| 3196 | * @ld_list: ld_list structure |
| 3197 | * |
| 3198 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 3199 | * list structure. This information is mainly used to find out SYSTEM |
| 3200 | * supported by the FW. |
| 3201 | */ |
| 3202 | static int |
| 3203 | megasas_get_ld_list(struct megasas_instance *instance) |
| 3204 | { |
| 3205 | int ret = 0, ld_index = 0, ids = 0; |
| 3206 | struct megasas_cmd *cmd; |
| 3207 | struct megasas_dcmd_frame *dcmd; |
| 3208 | struct MR_LD_LIST *ci; |
| 3209 | dma_addr_t ci_h = 0; |
| 3210 | |
| 3211 | cmd = megasas_get_cmd(instance); |
| 3212 | |
| 3213 | if (!cmd) { |
| 3214 | printk(KERN_DEBUG "megasas_get_ld_list: Failed to get cmd\n"); |
| 3215 | return -ENOMEM; |
| 3216 | } |
| 3217 | |
| 3218 | dcmd = &cmd->frame->dcmd; |
| 3219 | |
| 3220 | ci = pci_alloc_consistent(instance->pdev, |
| 3221 | sizeof(struct MR_LD_LIST), |
| 3222 | &ci_h); |
| 3223 | |
| 3224 | if (!ci) { |
| 3225 | printk(KERN_DEBUG "Failed to alloc mem in get_ld_list\n"); |
| 3226 | megasas_return_cmd(instance, cmd); |
| 3227 | return -ENOMEM; |
| 3228 | } |
| 3229 | |
| 3230 | memset(ci, 0, sizeof(*ci)); |
| 3231 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3232 | |
| 3233 | dcmd->cmd = MFI_CMD_DCMD; |
| 3234 | dcmd->cmd_status = 0xFF; |
| 3235 | dcmd->sge_count = 1; |
| 3236 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 3237 | dcmd->timeout = 0; |
| 3238 | dcmd->data_xfer_len = sizeof(struct MR_LD_LIST); |
| 3239 | dcmd->opcode = MR_DCMD_LD_GET_LIST; |
| 3240 | dcmd->sgl.sge32[0].phys_addr = ci_h; |
| 3241 | dcmd->sgl.sge32[0].length = sizeof(struct MR_LD_LIST); |
| 3242 | dcmd->pad_0 = 0; |
| 3243 | |
| 3244 | if (!megasas_issue_polled(instance, cmd)) { |
| 3245 | ret = 0; |
| 3246 | } else { |
| 3247 | ret = -1; |
| 3248 | } |
| 3249 | |
| 3250 | /* the following function will get the instance PD LIST */ |
| 3251 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3252 | if ((ret == 0) && (ci->ldCount <= MAX_LOGICAL_DRIVES)) { |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3253 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
| 3254 | |
| 3255 | for (ld_index = 0; ld_index < ci->ldCount; ld_index++) { |
| 3256 | if (ci->ldList[ld_index].state != 0) { |
| 3257 | ids = ci->ldList[ld_index].ref.targetId; |
| 3258 | instance->ld_ids[ids] = |
| 3259 | ci->ldList[ld_index].ref.targetId; |
| 3260 | } |
| 3261 | } |
| 3262 | } |
| 3263 | |
| 3264 | pci_free_consistent(instance->pdev, |
| 3265 | sizeof(struct MR_LD_LIST), |
| 3266 | ci, |
| 3267 | ci_h); |
| 3268 | |
| 3269 | megasas_return_cmd(instance, cmd); |
| 3270 | return ret; |
| 3271 | } |
| 3272 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3273 | /** |
| 3274 | * megasas_get_controller_info - Returns FW's controller structure |
| 3275 | * @instance: Adapter soft state |
| 3276 | * @ctrl_info: Controller information structure |
| 3277 | * |
| 3278 | * Issues an internal command (DCMD) to get the FW's controller structure. |
| 3279 | * This information is mainly used to find out the maximum IO transfer per |
| 3280 | * command supported by the FW. |
| 3281 | */ |
| 3282 | static int |
| 3283 | megasas_get_ctrl_info(struct megasas_instance *instance, |
| 3284 | struct megasas_ctrl_info *ctrl_info) |
| 3285 | { |
| 3286 | int ret = 0; |
| 3287 | struct megasas_cmd *cmd; |
| 3288 | struct megasas_dcmd_frame *dcmd; |
| 3289 | struct megasas_ctrl_info *ci; |
| 3290 | dma_addr_t ci_h = 0; |
| 3291 | |
| 3292 | cmd = megasas_get_cmd(instance); |
| 3293 | |
| 3294 | if (!cmd) { |
| 3295 | printk(KERN_DEBUG "megasas: Failed to get a free cmd\n"); |
| 3296 | return -ENOMEM; |
| 3297 | } |
| 3298 | |
| 3299 | dcmd = &cmd->frame->dcmd; |
| 3300 | |
| 3301 | ci = pci_alloc_consistent(instance->pdev, |
| 3302 | sizeof(struct megasas_ctrl_info), &ci_h); |
| 3303 | |
| 3304 | if (!ci) { |
| 3305 | printk(KERN_DEBUG "Failed to alloc mem for ctrl info\n"); |
| 3306 | megasas_return_cmd(instance, cmd); |
| 3307 | return -ENOMEM; |
| 3308 | } |
| 3309 | |
| 3310 | memset(ci, 0, sizeof(*ci)); |
| 3311 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3312 | |
| 3313 | dcmd->cmd = MFI_CMD_DCMD; |
| 3314 | dcmd->cmd_status = 0xFF; |
| 3315 | dcmd->sge_count = 1; |
| 3316 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 3317 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 3318 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3319 | dcmd->data_xfer_len = sizeof(struct megasas_ctrl_info); |
| 3320 | dcmd->opcode = MR_DCMD_CTRL_GET_INFO; |
| 3321 | dcmd->sgl.sge32[0].phys_addr = ci_h; |
| 3322 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_ctrl_info); |
| 3323 | |
| 3324 | if (!megasas_issue_polled(instance, cmd)) { |
| 3325 | ret = 0; |
| 3326 | memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); |
| 3327 | } else { |
| 3328 | ret = -1; |
| 3329 | } |
| 3330 | |
| 3331 | pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), |
| 3332 | ci, ci_h); |
| 3333 | |
| 3334 | megasas_return_cmd(instance, cmd); |
| 3335 | return ret; |
| 3336 | } |
| 3337 | |
| 3338 | /** |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 3339 | * megasas_issue_init_mfi - Initializes the FW |
| 3340 | * @instance: Adapter soft state |
| 3341 | * |
| 3342 | * Issues the INIT MFI cmd |
| 3343 | */ |
| 3344 | static int |
| 3345 | megasas_issue_init_mfi(struct megasas_instance *instance) |
| 3346 | { |
| 3347 | u32 context; |
| 3348 | |
| 3349 | struct megasas_cmd *cmd; |
| 3350 | |
| 3351 | struct megasas_init_frame *init_frame; |
| 3352 | struct megasas_init_queue_info *initq_info; |
| 3353 | dma_addr_t init_frame_h; |
| 3354 | dma_addr_t initq_info_h; |
| 3355 | |
| 3356 | /* |
| 3357 | * Prepare a init frame. Note the init frame points to queue info |
| 3358 | * structure. Each frame has SGL allocated after first 64 bytes. For |
| 3359 | * this frame - since we don't need any SGL - we use SGL's space as |
| 3360 | * queue info structure |
| 3361 | * |
| 3362 | * We will not get a NULL command below. We just created the pool. |
| 3363 | */ |
| 3364 | cmd = megasas_get_cmd(instance); |
| 3365 | |
| 3366 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 3367 | initq_info = (struct megasas_init_queue_info *) |
| 3368 | ((unsigned long)init_frame + 64); |
| 3369 | |
| 3370 | init_frame_h = cmd->frame_phys_addr; |
| 3371 | initq_info_h = init_frame_h + 64; |
| 3372 | |
| 3373 | context = init_frame->context; |
| 3374 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 3375 | memset(initq_info, 0, sizeof(struct megasas_init_queue_info)); |
| 3376 | init_frame->context = context; |
| 3377 | |
| 3378 | initq_info->reply_queue_entries = instance->max_fw_cmds + 1; |
| 3379 | initq_info->reply_queue_start_phys_addr_lo = instance->reply_queue_h; |
| 3380 | |
| 3381 | initq_info->producer_index_phys_addr_lo = instance->producer_h; |
| 3382 | initq_info->consumer_index_phys_addr_lo = instance->consumer_h; |
| 3383 | |
| 3384 | init_frame->cmd = MFI_CMD_INIT; |
| 3385 | init_frame->cmd_status = 0xFF; |
| 3386 | init_frame->queue_info_new_phys_addr_lo = initq_info_h; |
| 3387 | |
| 3388 | init_frame->data_xfer_len = sizeof(struct megasas_init_queue_info); |
| 3389 | |
| 3390 | /* |
| 3391 | * disable the intr before firing the init frame to FW |
| 3392 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3393 | instance->instancet->disable_intr(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 3394 | |
| 3395 | /* |
| 3396 | * Issue the init frame in polled mode |
| 3397 | */ |
| 3398 | |
| 3399 | if (megasas_issue_polled(instance, cmd)) { |
| 3400 | printk(KERN_ERR "megasas: Failed to init firmware\n"); |
| 3401 | megasas_return_cmd(instance, cmd); |
| 3402 | goto fail_fw_init; |
| 3403 | } |
| 3404 | |
| 3405 | megasas_return_cmd(instance, cmd); |
| 3406 | |
| 3407 | return 0; |
| 3408 | |
| 3409 | fail_fw_init: |
| 3410 | return -EINVAL; |
| 3411 | } |
| 3412 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3413 | static u32 |
| 3414 | megasas_init_adapter_mfi(struct megasas_instance *instance) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3415 | { |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3416 | struct megasas_register_set __iomem *reg_set; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3417 | u32 context_sz; |
| 3418 | u32 reply_q_sz; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3419 | |
| 3420 | reg_set = instance->reg_set; |
| 3421 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3422 | /* |
| 3423 | * Get various operational parameters from status register |
| 3424 | */ |
Sumant Patro | 1341c93 | 2006-01-25 12:02:40 -0800 | [diff] [blame] | 3425 | 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] | 3426 | /* |
| 3427 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 3428 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 3429 | * does not exceed max cmds that the FW can support |
| 3430 | */ |
| 3431 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3432 | instance->max_mfi_cmds = instance->max_fw_cmds; |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 3433 | 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] | 3434 | 0x10; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3435 | /* |
| 3436 | * Create a pool of commands |
| 3437 | */ |
| 3438 | if (megasas_alloc_cmds(instance)) |
| 3439 | goto fail_alloc_cmds; |
| 3440 | |
| 3441 | /* |
| 3442 | * Allocate memory for reply queue. Length of reply queue should |
| 3443 | * be _one_ more than the maximum commands handled by the firmware. |
| 3444 | * |
| 3445 | * Note: When FW completes commands, it places corresponding contex |
| 3446 | * values in this circular reply queue. This circular queue is a fairly |
| 3447 | * typical producer-consumer queue. FW is the producer (of completed |
| 3448 | * commands) and the driver is the consumer. |
| 3449 | */ |
| 3450 | context_sz = sizeof(u32); |
| 3451 | reply_q_sz = context_sz * (instance->max_fw_cmds + 1); |
| 3452 | |
| 3453 | instance->reply_queue = pci_alloc_consistent(instance->pdev, |
| 3454 | reply_q_sz, |
| 3455 | &instance->reply_queue_h); |
| 3456 | |
| 3457 | if (!instance->reply_queue) { |
| 3458 | printk(KERN_DEBUG "megasas: Out of DMA mem for reply queue\n"); |
| 3459 | goto fail_reply_queue; |
| 3460 | } |
| 3461 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 3462 | if (megasas_issue_init_mfi(instance)) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3463 | goto fail_fw_init; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3464 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3465 | instance->fw_support_ieee = 0; |
| 3466 | instance->fw_support_ieee = |
| 3467 | (instance->instancet->read_fw_status_reg(reg_set) & |
| 3468 | 0x04000000); |
| 3469 | |
| 3470 | printk(KERN_NOTICE "megasas_init_mfi: fw_support_ieee=%d", |
| 3471 | instance->fw_support_ieee); |
| 3472 | |
| 3473 | if (instance->fw_support_ieee) |
| 3474 | instance->flag_ieee = 1; |
| 3475 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3476 | return 0; |
| 3477 | |
| 3478 | fail_fw_init: |
| 3479 | |
| 3480 | pci_free_consistent(instance->pdev, reply_q_sz, |
| 3481 | instance->reply_queue, instance->reply_queue_h); |
| 3482 | fail_reply_queue: |
| 3483 | megasas_free_cmds(instance); |
| 3484 | |
| 3485 | fail_alloc_cmds: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3486 | return 1; |
| 3487 | } |
| 3488 | |
| 3489 | /** |
| 3490 | * megasas_init_fw - Initializes the FW |
| 3491 | * @instance: Adapter soft state |
| 3492 | * |
| 3493 | * This is the main function for initializing firmware |
| 3494 | */ |
| 3495 | |
| 3496 | static int megasas_init_fw(struct megasas_instance *instance) |
| 3497 | { |
| 3498 | u32 max_sectors_1; |
| 3499 | u32 max_sectors_2; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3500 | u32 tmp_sectors, msix_enable, scratch_pad_2; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3501 | struct megasas_register_set __iomem *reg_set; |
| 3502 | struct megasas_ctrl_info *ctrl_info; |
| 3503 | unsigned long bar_list; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3504 | int i, loop, fw_msix_count = 0; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3505 | |
| 3506 | /* Find first memory bar */ |
| 3507 | bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM); |
| 3508 | instance->bar = find_first_bit(&bar_list, sizeof(unsigned long)); |
| 3509 | instance->base_addr = pci_resource_start(instance->pdev, instance->bar); |
| 3510 | if (pci_request_selected_regions(instance->pdev, instance->bar, |
| 3511 | "megasas: LSI")) { |
| 3512 | printk(KERN_DEBUG "megasas: IO memory region busy!\n"); |
| 3513 | return -EBUSY; |
| 3514 | } |
| 3515 | |
| 3516 | instance->reg_set = ioremap_nocache(instance->base_addr, 8192); |
| 3517 | |
| 3518 | if (!instance->reg_set) { |
| 3519 | printk(KERN_DEBUG "megasas: Failed to map IO mem\n"); |
| 3520 | goto fail_ioremap; |
| 3521 | } |
| 3522 | |
| 3523 | reg_set = instance->reg_set; |
| 3524 | |
| 3525 | switch (instance->pdev->device) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3526 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 3527 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 3528 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3529 | instance->instancet = &megasas_instance_template_fusion; |
| 3530 | break; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3531 | case PCI_DEVICE_ID_LSI_SAS1078R: |
| 3532 | case PCI_DEVICE_ID_LSI_SAS1078DE: |
| 3533 | instance->instancet = &megasas_instance_template_ppc; |
| 3534 | break; |
| 3535 | case PCI_DEVICE_ID_LSI_SAS1078GEN2: |
| 3536 | case PCI_DEVICE_ID_LSI_SAS0079GEN2: |
| 3537 | instance->instancet = &megasas_instance_template_gen2; |
| 3538 | break; |
| 3539 | case PCI_DEVICE_ID_LSI_SAS0073SKINNY: |
| 3540 | case PCI_DEVICE_ID_LSI_SAS0071SKINNY: |
| 3541 | instance->instancet = &megasas_instance_template_skinny; |
| 3542 | break; |
| 3543 | case PCI_DEVICE_ID_LSI_SAS1064R: |
| 3544 | case PCI_DEVICE_ID_DELL_PERC5: |
| 3545 | default: |
| 3546 | instance->instancet = &megasas_instance_template_xscale; |
| 3547 | break; |
| 3548 | } |
| 3549 | |
Sumit.Saxena@lsi.com | 6431f5d | 2013-07-16 02:26:05 +0530 | [diff] [blame^] | 3550 | if (megasas_transition_to_ready(instance, 0)) { |
| 3551 | atomic_set(&instance->fw_reset_no_pci_access, 1); |
| 3552 | instance->instancet->adp_reset |
| 3553 | (instance, instance->reg_set); |
| 3554 | atomic_set(&instance->fw_reset_no_pci_access, 0); |
| 3555 | dev_info(&instance->pdev->dev, |
| 3556 | "megasas: FW restarted successfully from %s!\n", |
| 3557 | __func__); |
| 3558 | |
| 3559 | /*waitting for about 30 second before retry*/ |
| 3560 | ssleep(30); |
| 3561 | |
| 3562 | if (megasas_transition_to_ready(instance, 0)) |
| 3563 | goto fail_ready_state; |
| 3564 | } |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3565 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3566 | /* |
| 3567 | * MSI-X host index 0 is common for all adapter. |
| 3568 | * It is used for all MPT based Adapters. |
| 3569 | */ |
| 3570 | instance->reply_post_host_index_addr[0] = |
| 3571 | (u32 *)((u8 *)instance->reg_set + |
| 3572 | MPI2_REPLY_POST_HOST_INDEX_OFFSET); |
| 3573 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 3574 | /* Check if MSI-X is supported while in ready state */ |
| 3575 | msix_enable = (instance->instancet->read_fw_status_reg(reg_set) & |
| 3576 | 0x4000000) >> 0x1a; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3577 | if (msix_enable && !msix_disable) { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3578 | scratch_pad_2 = readl |
| 3579 | (&instance->reg_set->outbound_scratch_pad_2); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3580 | /* Check max MSI-X vectors */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3581 | if (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) { |
| 3582 | instance->msix_vectors = (scratch_pad_2 |
| 3583 | & MR_MAX_REPLY_QUEUES_OFFSET) + 1; |
| 3584 | fw_msix_count = instance->msix_vectors; |
adam radford | 079eadd | 2012-10-01 19:26:59 -0700 | [diff] [blame] | 3585 | if (msix_vectors) |
| 3586 | instance->msix_vectors = |
| 3587 | min(msix_vectors, |
| 3588 | instance->msix_vectors); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3589 | } else if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) |
| 3590 | || (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
| 3591 | /* Invader/Fury supports more than 8 MSI-X */ |
| 3592 | instance->msix_vectors = ((scratch_pad_2 |
| 3593 | & MR_MAX_REPLY_QUEUES_EXT_OFFSET) |
| 3594 | >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1; |
| 3595 | fw_msix_count = instance->msix_vectors; |
| 3596 | /* Save 1-15 reply post index address to local memory |
| 3597 | * Index 0 is already saved from reg offset |
| 3598 | * MPI2_REPLY_POST_HOST_INDEX_OFFSET |
| 3599 | */ |
| 3600 | for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) { |
| 3601 | instance->reply_post_host_index_addr[loop] = |
| 3602 | (u32 *)((u8 *)instance->reg_set + |
| 3603 | MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET |
| 3604 | + (loop * 0x10)); |
| 3605 | } |
| 3606 | if (msix_vectors) |
| 3607 | instance->msix_vectors = min(msix_vectors, |
| 3608 | instance->msix_vectors); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3609 | } else |
| 3610 | instance->msix_vectors = 1; |
| 3611 | /* Don't bother allocating more MSI-X vectors than cpus */ |
| 3612 | instance->msix_vectors = min(instance->msix_vectors, |
| 3613 | (unsigned int)num_online_cpus()); |
| 3614 | for (i = 0; i < instance->msix_vectors; i++) |
| 3615 | instance->msixentry[i].entry = i; |
| 3616 | i = pci_enable_msix(instance->pdev, instance->msixentry, |
| 3617 | instance->msix_vectors); |
| 3618 | if (i >= 0) { |
| 3619 | if (i) { |
| 3620 | if (!pci_enable_msix(instance->pdev, |
| 3621 | instance->msixentry, i)) |
| 3622 | instance->msix_vectors = i; |
| 3623 | else |
| 3624 | instance->msix_vectors = 0; |
| 3625 | } |
| 3626 | } else |
| 3627 | instance->msix_vectors = 0; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3628 | |
| 3629 | dev_info(&instance->pdev->dev, "[scsi%d]: FW supports" |
| 3630 | "<%d> MSIX vector,Online CPUs: <%d>," |
| 3631 | "Current MSIX <%d>\n", instance->host->host_no, |
| 3632 | fw_msix_count, (unsigned int)num_online_cpus(), |
| 3633 | instance->msix_vectors); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3634 | } |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 3635 | |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3636 | /* Get operational params, sge flags, send init cmd to controller */ |
| 3637 | if (instance->instancet->init_adapter(instance)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 3638 | goto fail_init_adapter; |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3639 | |
| 3640 | printk(KERN_ERR "megasas: INIT adapter done\n"); |
| 3641 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3642 | /** for passthrough |
| 3643 | * the following function will get the PD LIST. |
| 3644 | */ |
| 3645 | |
Yang, Bo | 81e403c | 2009-10-06 14:27:54 -0600 | [diff] [blame] | 3646 | memset(instance->pd_list, 0 , |
| 3647 | (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list))); |
| 3648 | megasas_get_pd_list(instance); |
| 3649 | |
Yang, Bo | bdc6fb8 | 2009-12-06 08:30:19 -0700 | [diff] [blame] | 3650 | memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS); |
| 3651 | megasas_get_ld_list(instance); |
| 3652 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3653 | ctrl_info = kmalloc(sizeof(struct megasas_ctrl_info), GFP_KERNEL); |
| 3654 | |
| 3655 | /* |
| 3656 | * Compute the max allowed sectors per IO: The controller info has two |
| 3657 | * limits on max sectors. Driver should use the minimum of these two. |
| 3658 | * |
| 3659 | * 1 << stripe_sz_ops.min = max sectors per strip |
| 3660 | * |
| 3661 | * Note that older firmwares ( < FW ver 30) didn't report information |
| 3662 | * to calculate max_sectors_1. So the number ended up as zero always. |
| 3663 | */ |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 3664 | tmp_sectors = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3665 | if (ctrl_info && !megasas_get_ctrl_info(instance, ctrl_info)) { |
| 3666 | |
| 3667 | max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) * |
| 3668 | ctrl_info->max_strips_per_io; |
| 3669 | max_sectors_2 = ctrl_info->max_request_size; |
| 3670 | |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 3671 | 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] | 3672 | |
| 3673 | /*Check whether controller is iMR or MR */ |
| 3674 | if (ctrl_info->memory_size) { |
| 3675 | instance->is_imr = 0; |
| 3676 | dev_info(&instance->pdev->dev, "Controller type: MR," |
| 3677 | "Memory size is: %dMB\n", |
| 3678 | ctrl_info->memory_size); |
| 3679 | } else { |
| 3680 | instance->is_imr = 1; |
| 3681 | dev_info(&instance->pdev->dev, |
| 3682 | "Controller type: iMR\n"); |
| 3683 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3684 | instance->disableOnlineCtrlReset = |
| 3685 | ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 3686 | instance->UnevenSpanSupport = |
| 3687 | ctrl_info->adapterOperations2.supportUnevenSpans; |
| 3688 | if (instance->UnevenSpanSupport) { |
| 3689 | struct fusion_context *fusion = instance->ctrl_context; |
| 3690 | dev_info(&instance->pdev->dev, "FW supports: " |
| 3691 | "UnevenSpanSupport=%x\n", instance->UnevenSpanSupport); |
| 3692 | if (MR_ValidateMapInfo(instance)) |
| 3693 | fusion->fast_path_io = 1; |
| 3694 | else |
| 3695 | fusion->fast_path_io = 0; |
| 3696 | |
| 3697 | } |
bo yang | 14faea9 | 2007-11-09 04:14:00 -0500 | [diff] [blame] | 3698 | } |
| 3699 | |
| 3700 | instance->max_sectors_per_req = instance->max_num_sge * |
| 3701 | PAGE_SIZE / 512; |
| 3702 | if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) |
| 3703 | instance->max_sectors_per_req = tmp_sectors; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3704 | |
| 3705 | kfree(ctrl_info); |
| 3706 | |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 3707 | /* Check for valid throttlequeuedepth module parameter */ |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 3708 | if (instance->is_imr) { |
adam radford | c5daa6a | 2012-07-17 18:20:03 -0700 | [diff] [blame] | 3709 | if (throttlequeuedepth > (instance->max_fw_cmds - |
| 3710 | MEGASAS_SKINNY_INT_CMDS)) |
| 3711 | instance->throttlequeuedepth = |
| 3712 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 3713 | else |
| 3714 | instance->throttlequeuedepth = throttlequeuedepth; |
| 3715 | } else { |
| 3716 | if (throttlequeuedepth > (instance->max_fw_cmds - |
| 3717 | MEGASAS_INT_CMDS)) |
| 3718 | instance->throttlequeuedepth = |
| 3719 | MEGASAS_THROTTLE_QUEUE_DEPTH; |
| 3720 | else |
| 3721 | instance->throttlequeuedepth = throttlequeuedepth; |
| 3722 | } |
| 3723 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 3724 | /* |
| 3725 | * Setup tasklet for cmd completion |
| 3726 | */ |
| 3727 | |
adam radford | f86c5424 | 2011-02-24 20:57:00 -0800 | [diff] [blame] | 3728 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 3729 | (unsigned long)instance); |
| 3730 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3731 | return 0; |
| 3732 | |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 3733 | fail_init_adapter: |
adam radford | cd50ba8 | 2010-12-21 10:23:23 -0800 | [diff] [blame] | 3734 | fail_ready_state: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3735 | iounmap(instance->reg_set); |
| 3736 | |
| 3737 | fail_ioremap: |
adam radford | b6d5d88 | 2010-12-14 18:56:07 -0800 | [diff] [blame] | 3738 | pci_release_selected_regions(instance->pdev, instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3739 | |
| 3740 | return -EINVAL; |
| 3741 | } |
| 3742 | |
| 3743 | /** |
| 3744 | * megasas_release_mfi - Reverses the FW initialization |
| 3745 | * @intance: Adapter soft state |
| 3746 | */ |
| 3747 | static void megasas_release_mfi(struct megasas_instance *instance) |
| 3748 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3749 | u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3750 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3751 | if (instance->reply_queue) |
| 3752 | pci_free_consistent(instance->pdev, reply_q_sz, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3753 | instance->reply_queue, instance->reply_queue_h); |
| 3754 | |
| 3755 | megasas_free_cmds(instance); |
| 3756 | |
| 3757 | iounmap(instance->reg_set); |
| 3758 | |
adam radford | b6d5d88 | 2010-12-14 18:56:07 -0800 | [diff] [blame] | 3759 | pci_release_selected_regions(instance->pdev, instance->bar); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | /** |
| 3763 | * megasas_get_seq_num - Gets latest event sequence numbers |
| 3764 | * @instance: Adapter soft state |
| 3765 | * @eli: FW event log sequence numbers information |
| 3766 | * |
| 3767 | * FW maintains a log of all events in a non-volatile area. Upper layers would |
| 3768 | * usually find out the latest sequence number of the events, the seq number at |
| 3769 | * the boot etc. They would "read" all the events below the latest seq number |
| 3770 | * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq |
| 3771 | * number), they would subsribe to AEN (asynchronous event notification) and |
| 3772 | * wait for the events to happen. |
| 3773 | */ |
| 3774 | static int |
| 3775 | megasas_get_seq_num(struct megasas_instance *instance, |
| 3776 | struct megasas_evt_log_info *eli) |
| 3777 | { |
| 3778 | struct megasas_cmd *cmd; |
| 3779 | struct megasas_dcmd_frame *dcmd; |
| 3780 | struct megasas_evt_log_info *el_info; |
| 3781 | dma_addr_t el_info_h = 0; |
| 3782 | |
| 3783 | cmd = megasas_get_cmd(instance); |
| 3784 | |
| 3785 | if (!cmd) { |
| 3786 | return -ENOMEM; |
| 3787 | } |
| 3788 | |
| 3789 | dcmd = &cmd->frame->dcmd; |
| 3790 | el_info = pci_alloc_consistent(instance->pdev, |
| 3791 | sizeof(struct megasas_evt_log_info), |
| 3792 | &el_info_h); |
| 3793 | |
| 3794 | if (!el_info) { |
| 3795 | megasas_return_cmd(instance, cmd); |
| 3796 | return -ENOMEM; |
| 3797 | } |
| 3798 | |
| 3799 | memset(el_info, 0, sizeof(*el_info)); |
| 3800 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3801 | |
| 3802 | dcmd->cmd = MFI_CMD_DCMD; |
| 3803 | dcmd->cmd_status = 0x0; |
| 3804 | dcmd->sge_count = 1; |
| 3805 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 3806 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 3807 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3808 | dcmd->data_xfer_len = sizeof(struct megasas_evt_log_info); |
| 3809 | dcmd->opcode = MR_DCMD_CTRL_EVENT_GET_INFO; |
| 3810 | dcmd->sgl.sge32[0].phys_addr = el_info_h; |
| 3811 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_evt_log_info); |
| 3812 | |
| 3813 | megasas_issue_blocked_cmd(instance, cmd); |
| 3814 | |
| 3815 | /* |
| 3816 | * Copy the data back into callers buffer |
| 3817 | */ |
| 3818 | memcpy(eli, el_info, sizeof(struct megasas_evt_log_info)); |
| 3819 | |
| 3820 | pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info), |
| 3821 | el_info, el_info_h); |
| 3822 | |
| 3823 | megasas_return_cmd(instance, cmd); |
| 3824 | |
| 3825 | return 0; |
| 3826 | } |
| 3827 | |
| 3828 | /** |
| 3829 | * megasas_register_aen - Registers for asynchronous event notification |
| 3830 | * @instance: Adapter soft state |
| 3831 | * @seq_num: The starting sequence number |
| 3832 | * @class_locale: Class of the event |
| 3833 | * |
| 3834 | * This function subscribes for AEN for events beyond the @seq_num. It requests |
| 3835 | * to be notified if and only if the event is of type @class_locale |
| 3836 | */ |
| 3837 | static int |
| 3838 | megasas_register_aen(struct megasas_instance *instance, u32 seq_num, |
| 3839 | u32 class_locale_word) |
| 3840 | { |
| 3841 | int ret_val; |
| 3842 | struct megasas_cmd *cmd; |
| 3843 | struct megasas_dcmd_frame *dcmd; |
| 3844 | union megasas_evt_class_locale curr_aen; |
| 3845 | union megasas_evt_class_locale prev_aen; |
| 3846 | |
| 3847 | /* |
| 3848 | * If there an AEN pending already (aen_cmd), check if the |
| 3849 | * class_locale of that pending AEN is inclusive of the new |
| 3850 | * AEN request we currently have. If it is, then we don't have |
| 3851 | * to do anything. In other words, whichever events the current |
| 3852 | * AEN request is subscribing to, have already been subscribed |
| 3853 | * to. |
| 3854 | * |
| 3855 | * If the old_cmd is _not_ inclusive, then we have to abort |
| 3856 | * that command, form a class_locale that is superset of both |
| 3857 | * old and current and re-issue to the FW |
| 3858 | */ |
| 3859 | |
| 3860 | curr_aen.word = class_locale_word; |
| 3861 | |
| 3862 | if (instance->aen_cmd) { |
| 3863 | |
| 3864 | prev_aen.word = instance->aen_cmd->frame->dcmd.mbox.w[1]; |
| 3865 | |
| 3866 | /* |
| 3867 | * A class whose enum value is smaller is inclusive of all |
| 3868 | * higher values. If a PROGRESS (= -1) was previously |
| 3869 | * registered, then a new registration requests for higher |
| 3870 | * classes need not be sent to FW. They are automatically |
| 3871 | * included. |
| 3872 | * |
| 3873 | * Locale numbers don't have such hierarchy. They are bitmap |
| 3874 | * values |
| 3875 | */ |
| 3876 | if ((prev_aen.members.class <= curr_aen.members.class) && |
| 3877 | !((prev_aen.members.locale & curr_aen.members.locale) ^ |
| 3878 | curr_aen.members.locale)) { |
| 3879 | /* |
| 3880 | * Previously issued event registration includes |
| 3881 | * current request. Nothing to do. |
| 3882 | */ |
| 3883 | return 0; |
| 3884 | } else { |
| 3885 | curr_aen.members.locale |= prev_aen.members.locale; |
| 3886 | |
| 3887 | if (prev_aen.members.class < curr_aen.members.class) |
| 3888 | curr_aen.members.class = prev_aen.members.class; |
| 3889 | |
| 3890 | instance->aen_cmd->abort_aen = 1; |
| 3891 | ret_val = megasas_issue_blocked_abort_cmd(instance, |
| 3892 | instance-> |
| 3893 | aen_cmd); |
| 3894 | |
| 3895 | if (ret_val) { |
| 3896 | printk(KERN_DEBUG "megasas: Failed to abort " |
| 3897 | "previous AEN command\n"); |
| 3898 | return ret_val; |
| 3899 | } |
| 3900 | } |
| 3901 | } |
| 3902 | |
| 3903 | cmd = megasas_get_cmd(instance); |
| 3904 | |
| 3905 | if (!cmd) |
| 3906 | return -ENOMEM; |
| 3907 | |
| 3908 | dcmd = &cmd->frame->dcmd; |
| 3909 | |
| 3910 | memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail)); |
| 3911 | |
| 3912 | /* |
| 3913 | * Prepare DCMD for aen registration |
| 3914 | */ |
| 3915 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 3916 | |
| 3917 | dcmd->cmd = MFI_CMD_DCMD; |
| 3918 | dcmd->cmd_status = 0x0; |
| 3919 | dcmd->sge_count = 1; |
| 3920 | dcmd->flags = MFI_FRAME_DIR_READ; |
| 3921 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 3922 | dcmd->pad_0 = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 3923 | instance->last_seq_num = seq_num; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3924 | dcmd->data_xfer_len = sizeof(struct megasas_evt_detail); |
| 3925 | dcmd->opcode = MR_DCMD_CTRL_EVENT_WAIT; |
| 3926 | dcmd->mbox.w[0] = seq_num; |
| 3927 | dcmd->mbox.w[1] = curr_aen.word; |
| 3928 | dcmd->sgl.sge32[0].phys_addr = (u32) instance->evt_detail_h; |
| 3929 | dcmd->sgl.sge32[0].length = sizeof(struct megasas_evt_detail); |
| 3930 | |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 3931 | if (instance->aen_cmd != NULL) { |
| 3932 | megasas_return_cmd(instance, cmd); |
| 3933 | return 0; |
| 3934 | } |
| 3935 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3936 | /* |
| 3937 | * Store reference to the cmd used to register for AEN. When an |
| 3938 | * application wants us to register for AEN, we have to abort this |
| 3939 | * cmd and re-register with a new EVENT LOCALE supplied by that app |
| 3940 | */ |
| 3941 | instance->aen_cmd = cmd; |
| 3942 | |
| 3943 | /* |
| 3944 | * Issue the aen registration frame |
| 3945 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3946 | instance->instancet->issue_dcmd(instance, cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3947 | |
| 3948 | return 0; |
| 3949 | } |
| 3950 | |
| 3951 | /** |
| 3952 | * megasas_start_aen - Subscribes to AEN during driver load time |
| 3953 | * @instance: Adapter soft state |
| 3954 | */ |
| 3955 | static int megasas_start_aen(struct megasas_instance *instance) |
| 3956 | { |
| 3957 | struct megasas_evt_log_info eli; |
| 3958 | union megasas_evt_class_locale class_locale; |
| 3959 | |
| 3960 | /* |
| 3961 | * Get the latest sequence number from FW |
| 3962 | */ |
| 3963 | memset(&eli, 0, sizeof(eli)); |
| 3964 | |
| 3965 | if (megasas_get_seq_num(instance, &eli)) |
| 3966 | return -1; |
| 3967 | |
| 3968 | /* |
| 3969 | * Register AEN with FW for latest sequence number plus 1 |
| 3970 | */ |
| 3971 | class_locale.members.reserved = 0; |
| 3972 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 3973 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 3974 | |
| 3975 | return megasas_register_aen(instance, eli.newest_seq_num + 1, |
| 3976 | class_locale.word); |
| 3977 | } |
| 3978 | |
| 3979 | /** |
| 3980 | * megasas_io_attach - Attaches this driver to SCSI mid-layer |
| 3981 | * @instance: Adapter soft state |
| 3982 | */ |
| 3983 | static int megasas_io_attach(struct megasas_instance *instance) |
| 3984 | { |
| 3985 | struct Scsi_Host *host = instance->host; |
| 3986 | |
| 3987 | /* |
| 3988 | * Export parameters required by SCSI mid-layer |
| 3989 | */ |
| 3990 | host->irq = instance->pdev->irq; |
| 3991 | host->unique_id = instance->unique_id; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 3992 | if (instance->is_imr) { |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 3993 | host->can_queue = |
| 3994 | instance->max_fw_cmds - MEGASAS_SKINNY_INT_CMDS; |
| 3995 | } else |
| 3996 | host->can_queue = |
| 3997 | instance->max_fw_cmds - MEGASAS_INT_CMDS; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 3998 | host->this_id = instance->init_id; |
| 3999 | host->sg_tablesize = instance->max_num_sge; |
adam radford | 42a8d2b | 2011-02-24 20:57:09 -0800 | [diff] [blame] | 4000 | |
| 4001 | if (instance->fw_support_ieee) |
| 4002 | instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE; |
| 4003 | |
Yang, Bo | 1fd1068 | 2010-10-12 07:18:50 -0600 | [diff] [blame] | 4004 | /* |
| 4005 | * Check if the module parameter value for max_sectors can be used |
| 4006 | */ |
| 4007 | if (max_sectors && max_sectors < instance->max_sectors_per_req) |
| 4008 | instance->max_sectors_per_req = max_sectors; |
| 4009 | else { |
| 4010 | if (max_sectors) { |
| 4011 | if (((instance->pdev->device == |
| 4012 | PCI_DEVICE_ID_LSI_SAS1078GEN2) || |
| 4013 | (instance->pdev->device == |
| 4014 | PCI_DEVICE_ID_LSI_SAS0079GEN2)) && |
| 4015 | (max_sectors <= MEGASAS_MAX_SECTORS)) { |
| 4016 | instance->max_sectors_per_req = max_sectors; |
| 4017 | } else { |
| 4018 | printk(KERN_INFO "megasas: max_sectors should be > 0" |
| 4019 | "and <= %d (or < 1MB for GEN2 controller)\n", |
| 4020 | instance->max_sectors_per_req); |
| 4021 | } |
| 4022 | } |
| 4023 | } |
| 4024 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4025 | host->max_sectors = instance->max_sectors_per_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4026 | host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4027 | host->max_channel = MEGASAS_MAX_CHANNELS - 1; |
| 4028 | host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL; |
| 4029 | host->max_lun = MEGASAS_MAX_LUN; |
Joshua Giles | 122da30 | 2006-02-03 15:34:17 -0800 | [diff] [blame] | 4030 | host->max_cmd_len = 16; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4031 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4032 | /* Fusion only supports host reset */ |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4033 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4034 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 4035 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4036 | host->hostt->eh_device_reset_handler = NULL; |
| 4037 | host->hostt->eh_bus_reset_handler = NULL; |
| 4038 | } |
| 4039 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4040 | /* |
| 4041 | * Notify the mid-layer about the new controller |
| 4042 | */ |
| 4043 | if (scsi_add_host(host, &instance->pdev->dev)) { |
| 4044 | printk(KERN_DEBUG "megasas: scsi_add_host failed\n"); |
| 4045 | return -ENODEV; |
| 4046 | } |
| 4047 | |
| 4048 | /* |
| 4049 | * Trigger SCSI to scan our drives |
| 4050 | */ |
| 4051 | scsi_scan_host(host); |
| 4052 | return 0; |
| 4053 | } |
| 4054 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4055 | static int |
| 4056 | megasas_set_dma_mask(struct pci_dev *pdev) |
| 4057 | { |
| 4058 | /* |
| 4059 | * All our contollers are capable of performing 64-bit DMA |
| 4060 | */ |
| 4061 | if (IS_DMA64) { |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 4062 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4063 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4064 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4065 | goto fail_set_dma_mask; |
| 4066 | } |
| 4067 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4068 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4069 | goto fail_set_dma_mask; |
| 4070 | } |
| 4071 | return 0; |
| 4072 | |
| 4073 | fail_set_dma_mask: |
| 4074 | return 1; |
| 4075 | } |
| 4076 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4077 | /** |
| 4078 | * megasas_probe_one - PCI hotplug entry point |
| 4079 | * @pdev: PCI device structure |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 4080 | * @id: PCI ids of supported hotplugged adapter |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4081 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 4082 | static int megasas_probe_one(struct pci_dev *pdev, |
| 4083 | const struct pci_device_id *id) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4084 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4085 | int rval, pos, i, j; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4086 | struct Scsi_Host *host; |
| 4087 | struct megasas_instance *instance; |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 4088 | u16 control = 0; |
| 4089 | |
| 4090 | /* Reset MSI-X in the kdump kernel */ |
| 4091 | if (reset_devices) { |
| 4092 | pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX); |
| 4093 | if (pos) { |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 4094 | pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 4095 | &control); |
| 4096 | if (control & PCI_MSIX_FLAGS_ENABLE) { |
| 4097 | dev_info(&pdev->dev, "resetting MSI-X\n"); |
| 4098 | pci_write_config_word(pdev, |
Bjorn Helgaas | 9936906 | 2013-04-17 18:08:44 -0600 | [diff] [blame] | 4099 | pos + PCI_MSIX_FLAGS, |
adam radford | 66192dfe | 2011-02-24 20:56:28 -0800 | [diff] [blame] | 4100 | control & |
| 4101 | ~PCI_MSIX_FLAGS_ENABLE); |
| 4102 | } |
| 4103 | } |
| 4104 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4105 | |
| 4106 | /* |
| 4107 | * Announce PCI information |
| 4108 | */ |
| 4109 | printk(KERN_INFO "megasas: %#4.04x:%#4.04x:%#4.04x:%#4.04x: ", |
| 4110 | pdev->vendor, pdev->device, pdev->subsystem_vendor, |
| 4111 | pdev->subsystem_device); |
| 4112 | |
| 4113 | printk("bus %d:slot %d:func %d\n", |
| 4114 | pdev->bus->number, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); |
| 4115 | |
| 4116 | /* |
| 4117 | * PCI prepping: enable device set bus mastering and dma mask |
| 4118 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 4119 | rval = pci_enable_device_mem(pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4120 | |
| 4121 | if (rval) { |
| 4122 | return rval; |
| 4123 | } |
| 4124 | |
| 4125 | pci_set_master(pdev); |
| 4126 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4127 | if (megasas_set_dma_mask(pdev)) |
| 4128 | goto fail_set_dma_mask; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4129 | |
| 4130 | host = scsi_host_alloc(&megasas_template, |
| 4131 | sizeof(struct megasas_instance)); |
| 4132 | |
| 4133 | if (!host) { |
| 4134 | printk(KERN_DEBUG "megasas: scsi_host_alloc failed\n"); |
| 4135 | goto fail_alloc_instance; |
| 4136 | } |
| 4137 | |
| 4138 | instance = (struct megasas_instance *)host->hostdata; |
| 4139 | memset(instance, 0, sizeof(*instance)); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4140 | atomic_set( &instance->fw_reset_no_pci_access, 0 ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4141 | instance->pdev = pdev; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4142 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4143 | switch (instance->pdev->device) { |
| 4144 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4145 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4146 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4147 | { |
| 4148 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4149 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4150 | instance->ctrl_context = |
| 4151 | kzalloc(sizeof(struct fusion_context), GFP_KERNEL); |
| 4152 | if (!instance->ctrl_context) { |
| 4153 | printk(KERN_DEBUG "megasas: Failed to allocate " |
| 4154 | "memory for Fusion context info\n"); |
| 4155 | goto fail_alloc_dma_buf; |
| 4156 | } |
| 4157 | fusion = instance->ctrl_context; |
| 4158 | INIT_LIST_HEAD(&fusion->cmd_pool); |
| 4159 | spin_lock_init(&fusion->cmd_pool_lock); |
| 4160 | } |
| 4161 | break; |
| 4162 | default: /* For all other supported controllers */ |
| 4163 | |
| 4164 | instance->producer = |
| 4165 | pci_alloc_consistent(pdev, sizeof(u32), |
| 4166 | &instance->producer_h); |
| 4167 | instance->consumer = |
| 4168 | pci_alloc_consistent(pdev, sizeof(u32), |
| 4169 | &instance->consumer_h); |
| 4170 | |
| 4171 | if (!instance->producer || !instance->consumer) { |
| 4172 | printk(KERN_DEBUG "megasas: Failed to allocate" |
| 4173 | "memory for producer, consumer\n"); |
| 4174 | goto fail_alloc_dma_buf; |
| 4175 | } |
| 4176 | |
| 4177 | *instance->producer = 0; |
| 4178 | *instance->consumer = 0; |
| 4179 | break; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4180 | } |
| 4181 | |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 4182 | megasas_poll_wait_aen = 0; |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 4183 | instance->flag_ieee = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4184 | instance->ev = NULL; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4185 | instance->issuepend_done = 1; |
| 4186 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
Sumit.Saxena@lsi.com | 404a8a1 | 2013-05-22 12:35:33 +0530 | [diff] [blame] | 4187 | instance->is_imr = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4188 | megasas_poll_wait_aen = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4189 | |
| 4190 | instance->evt_detail = pci_alloc_consistent(pdev, |
| 4191 | sizeof(struct |
| 4192 | megasas_evt_detail), |
| 4193 | &instance->evt_detail_h); |
| 4194 | |
| 4195 | if (!instance->evt_detail) { |
| 4196 | printk(KERN_DEBUG "megasas: Failed to allocate memory for " |
| 4197 | "event detail structure\n"); |
| 4198 | goto fail_alloc_dma_buf; |
| 4199 | } |
| 4200 | |
| 4201 | /* |
| 4202 | * Initialize locks and queues |
| 4203 | */ |
| 4204 | INIT_LIST_HEAD(&instance->cmd_pool); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4205 | INIT_LIST_HEAD(&instance->internal_reset_pending_q); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4206 | |
Sumant Patro | e4a082c | 2006-05-30 12:03:37 -0700 | [diff] [blame] | 4207 | atomic_set(&instance->fw_outstanding,0); |
| 4208 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4209 | init_waitqueue_head(&instance->int_cmd_wait_q); |
| 4210 | init_waitqueue_head(&instance->abort_cmd_wait_q); |
| 4211 | |
| 4212 | spin_lock_init(&instance->cmd_pool_lock); |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4213 | spin_lock_init(&instance->hba_lock); |
bo yang | 7343eb6 | 2007-11-09 04:35:44 -0500 | [diff] [blame] | 4214 | spin_lock_init(&instance->completion_lock); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4215 | |
Matthias Kaehlcke | e5a69e2 | 2007-10-27 09:48:46 +0200 | [diff] [blame] | 4216 | mutex_init(&instance->aen_mutex); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4217 | mutex_init(&instance->reset_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4218 | |
| 4219 | /* |
| 4220 | * Initialize PCI related and misc parameters |
| 4221 | */ |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4222 | instance->host = host; |
| 4223 | instance->unique_id = pdev->bus->number << 8 | pdev->devfn; |
| 4224 | instance->init_id = MEGASAS_DEFAULT_INIT_ID; |
| 4225 | |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 4226 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) || |
| 4227 | (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) { |
Yang, Bo | f4c9a13 | 2009-10-06 14:43:28 -0600 | [diff] [blame] | 4228 | instance->flag_ieee = 1; |
Yang, Bo | 7bebf5c | 2009-10-06 14:40:58 -0600 | [diff] [blame] | 4229 | sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS); |
| 4230 | } else |
| 4231 | sema_init(&instance->ioctl_sem, MEGASAS_INT_CMDS); |
| 4232 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 4233 | megasas_dbg_lvl = 0; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 4234 | instance->flag = 0; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 4235 | instance->unload = 1; |
Sumant Patro | 05e9ebb | 2007-05-17 05:47:51 -0700 | [diff] [blame] | 4236 | instance->last_time = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4237 | instance->disableOnlineCtrlReset = 1; |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 4238 | instance->UnevenSpanSupport = 0; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4239 | |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4240 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4241 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 4242 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4243 | INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq); |
| 4244 | else |
| 4245 | INIT_WORK(&instance->work_init, process_fw_state_change_wq); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 4246 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4247 | /* |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 4248 | * Initialize MFI Firmware |
| 4249 | */ |
| 4250 | if (megasas_init_fw(instance)) |
| 4251 | goto fail_init_mfi; |
| 4252 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4253 | retry_irq_register: |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 4254 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4255 | * Register IRQ |
| 4256 | */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4257 | if (instance->msix_vectors) { |
| 4258 | for (i = 0 ; i < instance->msix_vectors; i++) { |
| 4259 | instance->irq_context[i].instance = instance; |
| 4260 | instance->irq_context[i].MSIxIndex = i; |
| 4261 | if (request_irq(instance->msixentry[i].vector, |
| 4262 | instance->instancet->service_isr, 0, |
| 4263 | "megasas", |
| 4264 | &instance->irq_context[i])) { |
| 4265 | printk(KERN_DEBUG "megasas: Failed to " |
| 4266 | "register IRQ for vector %d.\n", i); |
| 4267 | for (j = 0 ; j < i ; j++) |
| 4268 | free_irq( |
| 4269 | instance->msixentry[j].vector, |
| 4270 | &instance->irq_context[j]); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4271 | /* Retry irq register for IO_APIC */ |
| 4272 | instance->msix_vectors = 0; |
| 4273 | goto retry_irq_register; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4274 | } |
| 4275 | } |
| 4276 | } else { |
| 4277 | instance->irq_context[0].instance = instance; |
| 4278 | instance->irq_context[0].MSIxIndex = 0; |
| 4279 | if (request_irq(pdev->irq, instance->instancet->service_isr, |
| 4280 | IRQF_SHARED, "megasas", |
| 4281 | &instance->irq_context[0])) { |
| 4282 | printk(KERN_DEBUG "megasas: Failed to register IRQ\n"); |
| 4283 | goto fail_irq; |
| 4284 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4285 | } |
| 4286 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4287 | instance->instancet->enable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4288 | |
| 4289 | /* |
| 4290 | * Store instance in PCI softstate |
| 4291 | */ |
| 4292 | pci_set_drvdata(pdev, instance); |
| 4293 | |
| 4294 | /* |
| 4295 | * Add this controller to megasas_mgmt_info structure so that it |
| 4296 | * can be exported to management applications |
| 4297 | */ |
| 4298 | megasas_mgmt_info.count++; |
| 4299 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance; |
| 4300 | megasas_mgmt_info.max_index++; |
| 4301 | |
| 4302 | /* |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 4303 | * Register with SCSI mid-layer |
| 4304 | */ |
| 4305 | if (megasas_io_attach(instance)) |
| 4306 | goto fail_io_attach; |
| 4307 | |
| 4308 | instance->unload = 0; |
| 4309 | |
| 4310 | /* |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4311 | * Initiate AEN (Asynchronous Event Notification) |
| 4312 | */ |
| 4313 | if (megasas_start_aen(instance)) { |
| 4314 | printk(KERN_DEBUG "megasas: start aen failed\n"); |
| 4315 | goto fail_start_aen; |
| 4316 | } |
| 4317 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4318 | return 0; |
| 4319 | |
| 4320 | fail_start_aen: |
| 4321 | fail_io_attach: |
| 4322 | megasas_mgmt_info.count--; |
| 4323 | megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL; |
| 4324 | megasas_mgmt_info.max_index--; |
| 4325 | |
| 4326 | pci_set_drvdata(pdev, NULL); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4327 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4328 | if (instance->msix_vectors) |
| 4329 | for (i = 0 ; i < instance->msix_vectors; i++) |
| 4330 | free_irq(instance->msixentry[i].vector, |
| 4331 | &instance->irq_context[i]); |
| 4332 | else |
| 4333 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 4334 | fail_irq: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4335 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) || |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4336 | (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 4337 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 4338 | megasas_release_fusion(instance); |
| 4339 | else |
| 4340 | megasas_release_mfi(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4341 | fail_init_mfi: |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4342 | if (instance->msix_vectors) |
adam radford | 0a77066 | 2011-02-24 20:56:12 -0800 | [diff] [blame] | 4343 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4344 | fail_alloc_dma_buf: |
| 4345 | if (instance->evt_detail) |
| 4346 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 4347 | instance->evt_detail, |
| 4348 | instance->evt_detail_h); |
| 4349 | |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 4350 | if (instance->producer) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4351 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 4352 | instance->producer_h); |
| 4353 | if (instance->consumer) |
| 4354 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 4355 | instance->consumer_h); |
| 4356 | scsi_host_put(host); |
| 4357 | |
| 4358 | fail_alloc_instance: |
| 4359 | fail_set_dma_mask: |
| 4360 | pci_disable_device(pdev); |
| 4361 | |
| 4362 | return -ENODEV; |
| 4363 | } |
| 4364 | |
| 4365 | /** |
| 4366 | * megasas_flush_cache - Requests FW to flush all its caches |
| 4367 | * @instance: Adapter soft state |
| 4368 | */ |
| 4369 | static void megasas_flush_cache(struct megasas_instance *instance) |
| 4370 | { |
| 4371 | struct megasas_cmd *cmd; |
| 4372 | struct megasas_dcmd_frame *dcmd; |
| 4373 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4374 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 4375 | return; |
| 4376 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4377 | cmd = megasas_get_cmd(instance); |
| 4378 | |
| 4379 | if (!cmd) |
| 4380 | return; |
| 4381 | |
| 4382 | dcmd = &cmd->frame->dcmd; |
| 4383 | |
| 4384 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4385 | |
| 4386 | dcmd->cmd = MFI_CMD_DCMD; |
| 4387 | dcmd->cmd_status = 0x0; |
| 4388 | dcmd->sge_count = 0; |
| 4389 | dcmd->flags = MFI_FRAME_DIR_NONE; |
| 4390 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4391 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4392 | dcmd->data_xfer_len = 0; |
| 4393 | dcmd->opcode = MR_DCMD_CTRL_CACHE_FLUSH; |
| 4394 | dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE; |
| 4395 | |
| 4396 | megasas_issue_blocked_cmd(instance, cmd); |
| 4397 | |
| 4398 | megasas_return_cmd(instance, cmd); |
| 4399 | |
| 4400 | return; |
| 4401 | } |
| 4402 | |
| 4403 | /** |
| 4404 | * megasas_shutdown_controller - Instructs FW to shutdown the controller |
| 4405 | * @instance: Adapter soft state |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4406 | * @opcode: Shutdown/Hibernate |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4407 | */ |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4408 | static void megasas_shutdown_controller(struct megasas_instance *instance, |
| 4409 | u32 opcode) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4410 | { |
| 4411 | struct megasas_cmd *cmd; |
| 4412 | struct megasas_dcmd_frame *dcmd; |
| 4413 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4414 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 4415 | return; |
| 4416 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4417 | cmd = megasas_get_cmd(instance); |
| 4418 | |
| 4419 | if (!cmd) |
| 4420 | return; |
| 4421 | |
| 4422 | if (instance->aen_cmd) |
| 4423 | megasas_issue_blocked_abort_cmd(instance, instance->aen_cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4424 | if (instance->map_update_cmd) |
| 4425 | megasas_issue_blocked_abort_cmd(instance, |
| 4426 | instance->map_update_cmd); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4427 | dcmd = &cmd->frame->dcmd; |
| 4428 | |
| 4429 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 4430 | |
| 4431 | dcmd->cmd = MFI_CMD_DCMD; |
| 4432 | dcmd->cmd_status = 0x0; |
| 4433 | dcmd->sge_count = 0; |
| 4434 | dcmd->flags = MFI_FRAME_DIR_NONE; |
| 4435 | dcmd->timeout = 0; |
Yang, Bo | 780a376 | 2009-12-06 08:24:21 -0700 | [diff] [blame] | 4436 | dcmd->pad_0 = 0; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4437 | dcmd->data_xfer_len = 0; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4438 | dcmd->opcode = opcode; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4439 | |
| 4440 | megasas_issue_blocked_cmd(instance, cmd); |
| 4441 | |
| 4442 | megasas_return_cmd(instance, cmd); |
| 4443 | |
| 4444 | return; |
| 4445 | } |
| 4446 | |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 4447 | #ifdef CONFIG_PM |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4448 | /** |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 4449 | * megasas_suspend - driver suspend entry point |
| 4450 | * @pdev: PCI device structure |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4451 | * @state: PCI power state to suspend routine |
| 4452 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 4453 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4454 | megasas_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4455 | { |
| 4456 | struct Scsi_Host *host; |
| 4457 | struct megasas_instance *instance; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4458 | int i; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4459 | |
| 4460 | instance = pci_get_drvdata(pdev); |
| 4461 | host = instance->host; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 4462 | instance->unload = 1; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4463 | |
| 4464 | megasas_flush_cache(instance); |
| 4465 | megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4466 | |
| 4467 | /* cancel the delayed work if this work still in queue */ |
| 4468 | if (instance->ev != NULL) { |
| 4469 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 4470 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4471 | instance->ev = NULL; |
| 4472 | } |
| 4473 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4474 | tasklet_kill(&instance->isr_tasklet); |
| 4475 | |
| 4476 | pci_set_drvdata(instance->pdev, instance); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4477 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4478 | |
| 4479 | if (instance->msix_vectors) |
| 4480 | for (i = 0 ; i < instance->msix_vectors; i++) |
| 4481 | free_irq(instance->msixentry[i].vector, |
| 4482 | &instance->irq_context[i]); |
| 4483 | else |
| 4484 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
| 4485 | if (instance->msix_vectors) |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 4486 | pci_disable_msix(instance->pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4487 | |
| 4488 | pci_save_state(pdev); |
| 4489 | pci_disable_device(pdev); |
| 4490 | |
| 4491 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 4492 | |
| 4493 | return 0; |
| 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * megasas_resume- driver resume entry point |
| 4498 | * @pdev: PCI device structure |
| 4499 | */ |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 4500 | static int |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4501 | megasas_resume(struct pci_dev *pdev) |
| 4502 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4503 | int rval, i, j; |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4504 | struct Scsi_Host *host; |
| 4505 | struct megasas_instance *instance; |
| 4506 | |
| 4507 | instance = pci_get_drvdata(pdev); |
| 4508 | host = instance->host; |
| 4509 | pci_set_power_state(pdev, PCI_D0); |
| 4510 | pci_enable_wake(pdev, PCI_D0, 0); |
| 4511 | pci_restore_state(pdev); |
| 4512 | |
| 4513 | /* |
| 4514 | * PCI prepping: enable device set bus mastering and dma mask |
| 4515 | */ |
Noriyuki Fujii | aeab3fd | 2009-11-20 16:27:20 +0900 | [diff] [blame] | 4516 | rval = pci_enable_device_mem(pdev); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4517 | |
| 4518 | if (rval) { |
| 4519 | printk(KERN_ERR "megasas: Enable device failed\n"); |
| 4520 | return rval; |
| 4521 | } |
| 4522 | |
| 4523 | pci_set_master(pdev); |
| 4524 | |
| 4525 | if (megasas_set_dma_mask(pdev)) |
| 4526 | goto fail_set_dma_mask; |
| 4527 | |
| 4528 | /* |
| 4529 | * Initialize MFI Firmware |
| 4530 | */ |
| 4531 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4532 | atomic_set(&instance->fw_outstanding, 0); |
| 4533 | |
| 4534 | /* |
| 4535 | * We expect the FW state to be READY |
| 4536 | */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 4537 | if (megasas_transition_to_ready(instance, 0)) |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4538 | goto fail_ready_state; |
| 4539 | |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 4540 | /* Now re-enable MSI-X */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4541 | if (instance->msix_vectors) |
| 4542 | pci_enable_msix(instance->pdev, instance->msixentry, |
| 4543 | instance->msix_vectors); |
adam radford | 3f1abce | 2011-05-11 18:33:47 -0700 | [diff] [blame] | 4544 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4545 | switch (instance->pdev->device) { |
| 4546 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4547 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4548 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4549 | { |
| 4550 | megasas_reset_reply_desc(instance); |
| 4551 | if (megasas_ioc_init_fusion(instance)) { |
| 4552 | megasas_free_cmds(instance); |
| 4553 | megasas_free_cmds_fusion(instance); |
| 4554 | goto fail_init_mfi; |
| 4555 | } |
| 4556 | if (!megasas_get_map_info(instance)) |
| 4557 | megasas_sync_map_info(instance); |
| 4558 | } |
| 4559 | break; |
| 4560 | default: |
| 4561 | *instance->producer = 0; |
| 4562 | *instance->consumer = 0; |
| 4563 | if (megasas_issue_init_mfi(instance)) |
| 4564 | goto fail_init_mfi; |
| 4565 | break; |
| 4566 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4567 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4568 | tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet, |
| 4569 | (unsigned long)instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4570 | |
| 4571 | /* |
| 4572 | * Register IRQ |
| 4573 | */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4574 | if (instance->msix_vectors) { |
| 4575 | for (i = 0 ; i < instance->msix_vectors; i++) { |
| 4576 | instance->irq_context[i].instance = instance; |
| 4577 | instance->irq_context[i].MSIxIndex = i; |
| 4578 | if (request_irq(instance->msixentry[i].vector, |
| 4579 | instance->instancet->service_isr, 0, |
| 4580 | "megasas", |
| 4581 | &instance->irq_context[i])) { |
| 4582 | printk(KERN_DEBUG "megasas: Failed to " |
| 4583 | "register IRQ for vector %d.\n", i); |
| 4584 | for (j = 0 ; j < i ; j++) |
| 4585 | free_irq( |
| 4586 | instance->msixentry[j].vector, |
| 4587 | &instance->irq_context[j]); |
| 4588 | goto fail_irq; |
| 4589 | } |
| 4590 | } |
| 4591 | } else { |
| 4592 | instance->irq_context[0].instance = instance; |
| 4593 | instance->irq_context[0].MSIxIndex = 0; |
| 4594 | if (request_irq(pdev->irq, instance->instancet->service_isr, |
| 4595 | IRQF_SHARED, "megasas", |
| 4596 | &instance->irq_context[0])) { |
| 4597 | printk(KERN_DEBUG "megasas: Failed to register IRQ\n"); |
| 4598 | goto fail_irq; |
| 4599 | } |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4600 | } |
| 4601 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4602 | instance->instancet->enable_intr(instance); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 4603 | instance->unload = 0; |
| 4604 | |
adam radford | 541f90b | 2011-05-11 18:34:29 -0700 | [diff] [blame] | 4605 | /* |
| 4606 | * Initiate AEN (Asynchronous Event Notification) |
| 4607 | */ |
| 4608 | if (megasas_start_aen(instance)) |
| 4609 | printk(KERN_ERR "megasas: Start AEN failed\n"); |
| 4610 | |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4611 | return 0; |
| 4612 | |
| 4613 | fail_irq: |
| 4614 | fail_init_mfi: |
| 4615 | if (instance->evt_detail) |
| 4616 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 4617 | instance->evt_detail, |
| 4618 | instance->evt_detail_h); |
| 4619 | |
| 4620 | if (instance->producer) |
| 4621 | pci_free_consistent(pdev, sizeof(u32), instance->producer, |
| 4622 | instance->producer_h); |
| 4623 | if (instance->consumer) |
| 4624 | pci_free_consistent(pdev, sizeof(u32), instance->consumer, |
| 4625 | instance->consumer_h); |
| 4626 | scsi_host_put(host); |
| 4627 | |
| 4628 | fail_set_dma_mask: |
| 4629 | fail_ready_state: |
| 4630 | |
| 4631 | pci_disable_device(pdev); |
| 4632 | |
| 4633 | return -ENODEV; |
| 4634 | } |
Jiri Slaby | 33139b2 | 2008-05-01 17:56:02 +0200 | [diff] [blame] | 4635 | #else |
| 4636 | #define megasas_suspend NULL |
| 4637 | #define megasas_resume NULL |
| 4638 | #endif |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4639 | |
| 4640 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4641 | * megasas_detach_one - PCI hot"un"plug entry point |
| 4642 | * @pdev: PCI device structure |
| 4643 | */ |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 4644 | static void megasas_detach_one(struct pci_dev *pdev) |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4645 | { |
| 4646 | int i; |
| 4647 | struct Scsi_Host *host; |
| 4648 | struct megasas_instance *instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4649 | struct fusion_context *fusion; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4650 | |
| 4651 | instance = pci_get_drvdata(pdev); |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 4652 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4653 | host = instance->host; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4654 | fusion = instance->ctrl_context; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4655 | |
| 4656 | scsi_remove_host(instance->host); |
| 4657 | megasas_flush_cache(instance); |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 4658 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4659 | |
| 4660 | /* cancel the delayed work if this work still in queue*/ |
| 4661 | if (instance->ev != NULL) { |
| 4662 | struct megasas_aen_event *ev = instance->ev; |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 4663 | cancel_delayed_work_sync(&ev->hotplug_work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 4664 | instance->ev = NULL; |
| 4665 | } |
| 4666 | |
Sumant Patro | 5d018ad | 2006-10-03 13:13:18 -0700 | [diff] [blame] | 4667 | tasklet_kill(&instance->isr_tasklet); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4668 | |
| 4669 | /* |
| 4670 | * Take the instance off the instance array. Note that we will not |
| 4671 | * decrement the max_index. We let this array be sparse array |
| 4672 | */ |
| 4673 | for (i = 0; i < megasas_mgmt_info.max_index; i++) { |
| 4674 | if (megasas_mgmt_info.instance[i] == instance) { |
| 4675 | megasas_mgmt_info.count--; |
| 4676 | megasas_mgmt_info.instance[i] = NULL; |
| 4677 | |
| 4678 | break; |
| 4679 | } |
| 4680 | } |
| 4681 | |
| 4682 | pci_set_drvdata(instance->pdev, NULL); |
| 4683 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4684 | instance->instancet->disable_intr(instance); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4685 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4686 | if (instance->msix_vectors) |
| 4687 | for (i = 0 ; i < instance->msix_vectors; i++) |
| 4688 | free_irq(instance->msixentry[i].vector, |
| 4689 | &instance->irq_context[i]); |
| 4690 | else |
| 4691 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
| 4692 | if (instance->msix_vectors) |
adam radford | 80d9da9 | 2010-12-21 10:17:40 -0800 | [diff] [blame] | 4693 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4694 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4695 | switch (instance->pdev->device) { |
| 4696 | case PCI_DEVICE_ID_LSI_FUSION: |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 4697 | case PCI_DEVICE_ID_LSI_INVADER: |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 4698 | case PCI_DEVICE_ID_LSI_FURY: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4699 | megasas_release_fusion(instance); |
| 4700 | for (i = 0; i < 2 ; i++) |
| 4701 | if (fusion->ld_map[i]) |
| 4702 | dma_free_coherent(&instance->pdev->dev, |
| 4703 | fusion->map_sz, |
| 4704 | fusion->ld_map[i], |
| 4705 | fusion-> |
| 4706 | ld_map_phys[i]); |
| 4707 | kfree(instance->ctrl_context); |
| 4708 | break; |
| 4709 | default: |
| 4710 | megasas_release_mfi(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4711 | pci_free_consistent(pdev, sizeof(u32), |
| 4712 | instance->producer, |
| 4713 | instance->producer_h); |
| 4714 | pci_free_consistent(pdev, sizeof(u32), |
| 4715 | instance->consumer, |
| 4716 | instance->consumer_h); |
| 4717 | break; |
| 4718 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4719 | |
Sumit.Saxena@lsi.com | 105900d | 2013-05-22 12:30:54 +0530 | [diff] [blame] | 4720 | if (instance->evt_detail) |
| 4721 | pci_free_consistent(pdev, sizeof(struct megasas_evt_detail), |
| 4722 | instance->evt_detail, instance->evt_detail_h); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4723 | scsi_host_put(host); |
| 4724 | |
| 4725 | pci_set_drvdata(pdev, NULL); |
| 4726 | |
| 4727 | pci_disable_device(pdev); |
| 4728 | |
| 4729 | return; |
| 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * megasas_shutdown - Shutdown entry point |
| 4734 | * @device: Generic device structure |
| 4735 | */ |
| 4736 | static void megasas_shutdown(struct pci_dev *pdev) |
| 4737 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4738 | int i; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4739 | struct megasas_instance *instance = pci_get_drvdata(pdev); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4740 | |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 4741 | instance->unload = 1; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4742 | megasas_flush_cache(instance); |
Yang, Bo | 530e6fc | 2008-08-10 12:42:37 -0700 | [diff] [blame] | 4743 | megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4744 | instance->instancet->disable_intr(instance); |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 4745 | if (instance->msix_vectors) |
| 4746 | for (i = 0 ; i < instance->msix_vectors; i++) |
| 4747 | free_irq(instance->msixentry[i].vector, |
| 4748 | &instance->irq_context[i]); |
| 4749 | else |
| 4750 | free_irq(instance->pdev->irq, &instance->irq_context[0]); |
| 4751 | if (instance->msix_vectors) |
adam radford | 46fd256 | 2011-05-11 18:34:17 -0700 | [diff] [blame] | 4752 | pci_disable_msix(instance->pdev); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | /** |
| 4756 | * megasas_mgmt_open - char node "open" entry point |
| 4757 | */ |
| 4758 | static int megasas_mgmt_open(struct inode *inode, struct file *filep) |
| 4759 | { |
| 4760 | /* |
| 4761 | * Allow only those users with admin rights |
| 4762 | */ |
| 4763 | if (!capable(CAP_SYS_ADMIN)) |
| 4764 | return -EACCES; |
| 4765 | |
| 4766 | return 0; |
| 4767 | } |
| 4768 | |
| 4769 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4770 | * megasas_mgmt_fasync - Async notifier registration from applications |
| 4771 | * |
| 4772 | * This function adds the calling process to a driver global queue. When an |
| 4773 | * event occurs, SIGIO will be sent to all processes in this queue. |
| 4774 | */ |
| 4775 | static int megasas_mgmt_fasync(int fd, struct file *filep, int mode) |
| 4776 | { |
| 4777 | int rc; |
| 4778 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 4779 | mutex_lock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4780 | |
| 4781 | rc = fasync_helper(fd, filep, mode, &megasas_async_queue); |
| 4782 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 4783 | mutex_unlock(&megasas_async_queue_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4784 | |
| 4785 | if (rc >= 0) { |
| 4786 | /* For sanity check when we get ioctl */ |
| 4787 | filep->private_data = filep; |
| 4788 | return 0; |
| 4789 | } |
| 4790 | |
| 4791 | printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc); |
| 4792 | |
| 4793 | return rc; |
| 4794 | } |
| 4795 | |
| 4796 | /** |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 4797 | * megasas_mgmt_poll - char node "poll" entry point |
| 4798 | * */ |
| 4799 | static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait) |
| 4800 | { |
| 4801 | unsigned int mask; |
| 4802 | unsigned long flags; |
| 4803 | poll_wait(file, &megasas_poll_wait, wait); |
| 4804 | spin_lock_irqsave(&poll_aen_lock, flags); |
| 4805 | if (megasas_poll_wait_aen) |
| 4806 | mask = (POLLIN | POLLRDNORM); |
| 4807 | else |
| 4808 | mask = 0; |
| 4809 | spin_unlock_irqrestore(&poll_aen_lock, flags); |
| 4810 | return mask; |
| 4811 | } |
| 4812 | |
| 4813 | /** |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4814 | * megasas_mgmt_fw_ioctl - Issues management ioctls to FW |
| 4815 | * @instance: Adapter soft state |
| 4816 | * @argp: User's ioctl packet |
| 4817 | */ |
| 4818 | static int |
| 4819 | megasas_mgmt_fw_ioctl(struct megasas_instance *instance, |
| 4820 | struct megasas_iocpacket __user * user_ioc, |
| 4821 | struct megasas_iocpacket *ioc) |
| 4822 | { |
| 4823 | struct megasas_sge32 *kern_sge32; |
| 4824 | struct megasas_cmd *cmd; |
| 4825 | void *kbuff_arr[MAX_IOCTL_SGE]; |
| 4826 | dma_addr_t buf_handle = 0; |
| 4827 | int error = 0, i; |
| 4828 | void *sense = NULL; |
| 4829 | dma_addr_t sense_handle; |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4830 | unsigned long *sense_ptr; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4831 | |
| 4832 | memset(kbuff_arr, 0, sizeof(kbuff_arr)); |
| 4833 | |
| 4834 | if (ioc->sge_count > MAX_IOCTL_SGE) { |
| 4835 | printk(KERN_DEBUG "megasas: SGE count [%d] > max limit [%d]\n", |
| 4836 | ioc->sge_count, MAX_IOCTL_SGE); |
| 4837 | return -EINVAL; |
| 4838 | } |
| 4839 | |
| 4840 | cmd = megasas_get_cmd(instance); |
| 4841 | if (!cmd) { |
| 4842 | printk(KERN_DEBUG "megasas: Failed to get a cmd packet\n"); |
| 4843 | return -ENOMEM; |
| 4844 | } |
| 4845 | |
| 4846 | /* |
| 4847 | * User's IOCTL packet has 2 frames (maximum). Copy those two |
| 4848 | * frames into our cmd's frames. cmd->frame's context will get |
| 4849 | * overwritten when we copy from user's frames. So set that value |
| 4850 | * alone separately |
| 4851 | */ |
| 4852 | memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE); |
| 4853 | cmd->frame->hdr.context = cmd->index; |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 4854 | cmd->frame->hdr.pad_0 = 0; |
adam radford | 882be7c3 | 2012-01-06 17:02:34 -0800 | [diff] [blame] | 4855 | cmd->frame->hdr.flags &= ~(MFI_FRAME_IEEE | MFI_FRAME_SGL64 | |
| 4856 | MFI_FRAME_SENSE64); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4857 | |
| 4858 | /* |
| 4859 | * The management interface between applications and the fw uses |
| 4860 | * MFI frames. E.g, RAID configuration changes, LD property changes |
| 4861 | * etc are accomplishes through different kinds of MFI frames. The |
| 4862 | * driver needs to care only about substituting user buffers with |
| 4863 | * kernel buffers in SGLs. The location of SGL is embedded in the |
| 4864 | * struct iocpacket itself. |
| 4865 | */ |
| 4866 | kern_sge32 = (struct megasas_sge32 *) |
| 4867 | ((unsigned long)cmd->frame + ioc->sgl_off); |
| 4868 | |
| 4869 | /* |
| 4870 | * For each user buffer, create a mirror buffer and copy in |
| 4871 | */ |
| 4872 | for (i = 0; i < ioc->sge_count; i++) { |
Bjørn Mork | 98cb7e4 | 2011-01-19 10:01:14 +0100 | [diff] [blame] | 4873 | if (!ioc->sgl[i].iov_len) |
| 4874 | continue; |
| 4875 | |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 4876 | kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4877 | ioc->sgl[i].iov_len, |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 4878 | &buf_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4879 | if (!kbuff_arr[i]) { |
| 4880 | printk(KERN_DEBUG "megasas: Failed to alloc " |
| 4881 | "kernel SGL buffer for IOCTL \n"); |
| 4882 | error = -ENOMEM; |
| 4883 | goto out; |
| 4884 | } |
| 4885 | |
| 4886 | /* |
| 4887 | * We don't change the dma_coherent_mask, so |
| 4888 | * pci_alloc_consistent only returns 32bit addresses |
| 4889 | */ |
| 4890 | kern_sge32[i].phys_addr = (u32) buf_handle; |
| 4891 | kern_sge32[i].length = ioc->sgl[i].iov_len; |
| 4892 | |
| 4893 | /* |
| 4894 | * We created a kernel buffer corresponding to the |
| 4895 | * user buffer. Now copy in from the user buffer |
| 4896 | */ |
| 4897 | if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base, |
| 4898 | (u32) (ioc->sgl[i].iov_len))) { |
| 4899 | error = -EFAULT; |
| 4900 | goto out; |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | if (ioc->sense_len) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 4905 | sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len, |
| 4906 | &sense_handle, GFP_KERNEL); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4907 | if (!sense) { |
| 4908 | error = -ENOMEM; |
| 4909 | goto out; |
| 4910 | } |
| 4911 | |
| 4912 | sense_ptr = |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4913 | (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4914 | *sense_ptr = sense_handle; |
| 4915 | } |
| 4916 | |
| 4917 | /* |
| 4918 | * Set the sync_cmd flag so that the ISR knows not to complete this |
| 4919 | * cmd to the SCSI mid-layer |
| 4920 | */ |
| 4921 | cmd->sync_cmd = 1; |
| 4922 | megasas_issue_blocked_cmd(instance, cmd); |
| 4923 | cmd->sync_cmd = 0; |
| 4924 | |
| 4925 | /* |
| 4926 | * copy out the kernel buffers to user buffers |
| 4927 | */ |
| 4928 | for (i = 0; i < ioc->sge_count; i++) { |
| 4929 | if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i], |
| 4930 | ioc->sgl[i].iov_len)) { |
| 4931 | error = -EFAULT; |
| 4932 | goto out; |
| 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | /* |
| 4937 | * copy out the sense |
| 4938 | */ |
| 4939 | if (ioc->sense_len) { |
| 4940 | /* |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 4941 | * sense_ptr points to the location that has the user |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4942 | * sense buffer address |
| 4943 | */ |
Yang, Bo | 7b2519a | 2009-10-06 14:52:20 -0600 | [diff] [blame] | 4944 | sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw + |
| 4945 | ioc->sense_off); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4946 | |
bo yang | b70a41e | 2008-03-18 03:13:06 -0400 | [diff] [blame] | 4947 | if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)), |
| 4948 | sense, ioc->sense_len)) { |
bo yang | b10c36a | 2007-11-09 04:28:47 -0500 | [diff] [blame] | 4949 | printk(KERN_ERR "megasas: Failed to copy out to user " |
| 4950 | "sense data\n"); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4951 | error = -EFAULT; |
| 4952 | goto out; |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | /* |
| 4957 | * copy the status codes returned by the fw |
| 4958 | */ |
| 4959 | if (copy_to_user(&user_ioc->frame.hdr.cmd_status, |
| 4960 | &cmd->frame->hdr.cmd_status, sizeof(u8))) { |
| 4961 | printk(KERN_DEBUG "megasas: Error copying out cmd_status\n"); |
| 4962 | error = -EFAULT; |
| 4963 | } |
| 4964 | |
| 4965 | out: |
| 4966 | if (sense) { |
Sumant Patro | 9f35fa8 | 2007-02-14 12:55:45 -0800 | [diff] [blame] | 4967 | dma_free_coherent(&instance->pdev->dev, ioc->sense_len, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4968 | sense, sense_handle); |
| 4969 | } |
| 4970 | |
Bjørn Mork | 7a6a731 | 2012-11-21 09:54:48 +0100 | [diff] [blame] | 4971 | for (i = 0; i < ioc->sge_count; i++) { |
| 4972 | if (kbuff_arr[i]) |
| 4973 | dma_free_coherent(&instance->pdev->dev, |
| 4974 | kern_sge32[i].length, |
| 4975 | kbuff_arr[i], |
| 4976 | kern_sge32[i].phys_addr); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4977 | } |
| 4978 | |
| 4979 | megasas_return_cmd(instance, cmd); |
| 4980 | return error; |
| 4981 | } |
| 4982 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4983 | static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) |
| 4984 | { |
| 4985 | struct megasas_iocpacket __user *user_ioc = |
| 4986 | (struct megasas_iocpacket __user *)arg; |
| 4987 | struct megasas_iocpacket *ioc; |
| 4988 | struct megasas_instance *instance; |
| 4989 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 4990 | int i; |
| 4991 | unsigned long flags; |
| 4992 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 4993 | |
| 4994 | ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); |
| 4995 | if (!ioc) |
| 4996 | return -ENOMEM; |
| 4997 | |
| 4998 | if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) { |
| 4999 | error = -EFAULT; |
| 5000 | goto out_kfree_ioc; |
| 5001 | } |
| 5002 | |
| 5003 | instance = megasas_lookup_instance(ioc->host_no); |
| 5004 | if (!instance) { |
| 5005 | error = -ENODEV; |
| 5006 | goto out_kfree_ioc; |
| 5007 | } |
| 5008 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5009 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 5010 | printk(KERN_ERR "Controller in crit error\n"); |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5011 | error = -ENODEV; |
| 5012 | goto out_kfree_ioc; |
| 5013 | } |
| 5014 | |
| 5015 | if (instance->unload == 1) { |
| 5016 | error = -ENODEV; |
| 5017 | goto out_kfree_ioc; |
| 5018 | } |
| 5019 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5020 | /* |
| 5021 | * We will allow only MEGASAS_INT_CMDS number of parallel ioctl cmds |
| 5022 | */ |
| 5023 | if (down_interruptible(&instance->ioctl_sem)) { |
| 5024 | error = -ERESTARTSYS; |
| 5025 | goto out_kfree_ioc; |
| 5026 | } |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5027 | |
| 5028 | for (i = 0; i < wait_time; i++) { |
| 5029 | |
| 5030 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 5031 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) { |
| 5032 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 5033 | break; |
| 5034 | } |
| 5035 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 5036 | |
| 5037 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 5038 | printk(KERN_NOTICE "megasas: waiting" |
| 5039 | "for controller reset to finish\n"); |
| 5040 | } |
| 5041 | |
| 5042 | msleep(1000); |
| 5043 | } |
| 5044 | |
| 5045 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 5046 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 5047 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 5048 | |
| 5049 | printk(KERN_ERR "megaraid_sas: timed out while" |
| 5050 | "waiting for HBA to recover\n"); |
| 5051 | error = -ENODEV; |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 5052 | goto out_up; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5053 | } |
| 5054 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 5055 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5056 | error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc); |
Dan Carpenter | c64e483 | 2013-04-16 10:44:19 +0300 | [diff] [blame] | 5057 | out_up: |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5058 | up(&instance->ioctl_sem); |
| 5059 | |
| 5060 | out_kfree_ioc: |
| 5061 | kfree(ioc); |
| 5062 | return error; |
| 5063 | } |
| 5064 | |
| 5065 | static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg) |
| 5066 | { |
| 5067 | struct megasas_instance *instance; |
| 5068 | struct megasas_aen aen; |
| 5069 | int error; |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5070 | int i; |
| 5071 | unsigned long flags; |
| 5072 | u32 wait_time = MEGASAS_RESET_WAIT_TIME; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5073 | |
| 5074 | if (file->private_data != file) { |
| 5075 | printk(KERN_DEBUG "megasas: fasync_helper was not " |
| 5076 | "called first\n"); |
| 5077 | return -EINVAL; |
| 5078 | } |
| 5079 | |
| 5080 | if (copy_from_user(&aen, (void __user *)arg, sizeof(aen))) |
| 5081 | return -EFAULT; |
| 5082 | |
| 5083 | instance = megasas_lookup_instance(aen.host_no); |
| 5084 | |
| 5085 | if (!instance) |
| 5086 | return -ENODEV; |
| 5087 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5088 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 5089 | return -ENODEV; |
Yang, Bo | 0c79e68 | 2009-10-06 14:47:35 -0600 | [diff] [blame] | 5090 | } |
| 5091 | |
| 5092 | if (instance->unload == 1) { |
| 5093 | return -ENODEV; |
| 5094 | } |
| 5095 | |
bo yang | 39a9855 | 2010-09-22 22:36:29 -0400 | [diff] [blame] | 5096 | for (i = 0; i < wait_time; i++) { |
| 5097 | |
| 5098 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 5099 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) { |
| 5100 | spin_unlock_irqrestore(&instance->hba_lock, |
| 5101 | flags); |
| 5102 | break; |
| 5103 | } |
| 5104 | |
| 5105 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 5106 | |
| 5107 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 5108 | printk(KERN_NOTICE "megasas: waiting for" |
| 5109 | "controller reset to finish\n"); |
| 5110 | } |
| 5111 | |
| 5112 | msleep(1000); |
| 5113 | } |
| 5114 | |
| 5115 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 5116 | if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) { |
| 5117 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 5118 | printk(KERN_ERR "megaraid_sas: timed out while waiting" |
| 5119 | "for HBA to recover.\n"); |
| 5120 | return -ENODEV; |
| 5121 | } |
| 5122 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 5123 | |
Matthias Kaehlcke | e5a69e2 | 2007-10-27 09:48:46 +0200 | [diff] [blame] | 5124 | mutex_lock(&instance->aen_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5125 | error = megasas_register_aen(instance, aen.seq_num, |
| 5126 | aen.class_locale_word); |
Matthias Kaehlcke | e5a69e2 | 2007-10-27 09:48:46 +0200 | [diff] [blame] | 5127 | mutex_unlock(&instance->aen_mutex); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5128 | return error; |
| 5129 | } |
| 5130 | |
| 5131 | /** |
| 5132 | * megasas_mgmt_ioctl - char node ioctl entry point |
| 5133 | */ |
| 5134 | static long |
| 5135 | megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 5136 | { |
| 5137 | switch (cmd) { |
| 5138 | case MEGASAS_IOC_FIRMWARE: |
| 5139 | return megasas_mgmt_ioctl_fw(file, arg); |
| 5140 | |
| 5141 | case MEGASAS_IOC_GET_AEN: |
| 5142 | return megasas_mgmt_ioctl_aen(file, arg); |
| 5143 | } |
| 5144 | |
| 5145 | return -ENOTTY; |
| 5146 | } |
| 5147 | |
| 5148 | #ifdef CONFIG_COMPAT |
| 5149 | static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg) |
| 5150 | { |
| 5151 | struct compat_megasas_iocpacket __user *cioc = |
| 5152 | (struct compat_megasas_iocpacket __user *)arg; |
| 5153 | struct megasas_iocpacket __user *ioc = |
| 5154 | compat_alloc_user_space(sizeof(struct megasas_iocpacket)); |
| 5155 | int i; |
| 5156 | int error = 0; |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 5157 | compat_uptr_t ptr; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5158 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5159 | if (clear_user(ioc, sizeof(*ioc))) |
| 5160 | return -EFAULT; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5161 | |
| 5162 | if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) || |
| 5163 | copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) || |
| 5164 | copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) || |
| 5165 | copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) || |
| 5166 | copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) || |
| 5167 | copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32))) |
| 5168 | return -EFAULT; |
| 5169 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 5170 | /* |
| 5171 | * The sense_ptr is used in megasas_mgmt_fw_ioctl only when |
| 5172 | * sense_len is not null, so prepare the 64bit value under |
| 5173 | * the same condition. |
| 5174 | */ |
| 5175 | if (ioc->sense_len) { |
| 5176 | void __user **sense_ioc_ptr = |
| 5177 | (void __user **)(ioc->frame.raw + ioc->sense_off); |
| 5178 | compat_uptr_t *sense_cioc_ptr = |
| 5179 | (compat_uptr_t *)(cioc->frame.raw + cioc->sense_off); |
| 5180 | if (get_user(ptr, sense_cioc_ptr) || |
| 5181 | put_user(compat_ptr(ptr), sense_ioc_ptr)) |
| 5182 | return -EFAULT; |
| 5183 | } |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5184 | |
Tomas Henzl | b3dc1a2 | 2010-02-11 18:01:50 +0100 | [diff] [blame] | 5185 | for (i = 0; i < MAX_IOCTL_SGE; i++) { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5186 | if (get_user(ptr, &cioc->sgl[i].iov_base) || |
| 5187 | put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) || |
| 5188 | copy_in_user(&ioc->sgl[i].iov_len, |
| 5189 | &cioc->sgl[i].iov_len, sizeof(compat_size_t))) |
| 5190 | return -EFAULT; |
| 5191 | } |
| 5192 | |
| 5193 | error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc); |
| 5194 | |
| 5195 | if (copy_in_user(&cioc->frame.hdr.cmd_status, |
| 5196 | &ioc->frame.hdr.cmd_status, sizeof(u8))) { |
| 5197 | printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n"); |
| 5198 | return -EFAULT; |
| 5199 | } |
| 5200 | return error; |
| 5201 | } |
| 5202 | |
| 5203 | static long |
| 5204 | megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd, |
| 5205 | unsigned long arg) |
| 5206 | { |
| 5207 | switch (cmd) { |
Sumant Patro | cb59aa6 | 2006-01-25 11:53:25 -0800 | [diff] [blame] | 5208 | case MEGASAS_IOC_FIRMWARE32: |
| 5209 | return megasas_mgmt_compat_ioctl_fw(file, arg); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5210 | case MEGASAS_IOC_GET_AEN: |
| 5211 | return megasas_mgmt_ioctl_aen(file, arg); |
| 5212 | } |
| 5213 | |
| 5214 | return -ENOTTY; |
| 5215 | } |
| 5216 | #endif |
| 5217 | |
| 5218 | /* |
| 5219 | * File operations structure for management interface |
| 5220 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 5221 | static const struct file_operations megasas_mgmt_fops = { |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5222 | .owner = THIS_MODULE, |
| 5223 | .open = megasas_mgmt_open, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5224 | .fasync = megasas_mgmt_fasync, |
| 5225 | .unlocked_ioctl = megasas_mgmt_ioctl, |
Yang, Bo | c351883 | 2009-10-06 14:18:02 -0600 | [diff] [blame] | 5226 | .poll = megasas_mgmt_poll, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5227 | #ifdef CONFIG_COMPAT |
| 5228 | .compat_ioctl = megasas_mgmt_compat_ioctl, |
| 5229 | #endif |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 5230 | .llseek = noop_llseek, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5231 | }; |
| 5232 | |
| 5233 | /* |
| 5234 | * PCI hotplug support registration structure |
| 5235 | */ |
| 5236 | static struct pci_driver megasas_pci_driver = { |
| 5237 | |
| 5238 | .name = "megaraid_sas", |
| 5239 | .id_table = megasas_pci_table, |
| 5240 | .probe = megasas_probe_one, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 5241 | .remove = megasas_detach_one, |
bo yang | 31ea708 | 2007-11-07 12:09:50 -0500 | [diff] [blame] | 5242 | .suspend = megasas_suspend, |
| 5243 | .resume = megasas_resume, |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5244 | .shutdown = megasas_shutdown, |
| 5245 | }; |
| 5246 | |
| 5247 | /* |
| 5248 | * Sysfs driver attributes |
| 5249 | */ |
| 5250 | static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf) |
| 5251 | { |
| 5252 | return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n", |
| 5253 | MEGASAS_VERSION); |
| 5254 | } |
| 5255 | |
| 5256 | static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); |
| 5257 | |
| 5258 | static ssize_t |
| 5259 | megasas_sysfs_show_release_date(struct device_driver *dd, char *buf) |
| 5260 | { |
| 5261 | return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n", |
| 5262 | MEGASAS_RELDATE); |
| 5263 | } |
| 5264 | |
| 5265 | static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, |
| 5266 | NULL); |
| 5267 | |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5268 | static ssize_t |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 5269 | megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf) |
| 5270 | { |
| 5271 | return sprintf(buf, "%u\n", support_poll_for_event); |
| 5272 | } |
| 5273 | |
| 5274 | static DRIVER_ATTR(support_poll_for_event, S_IRUGO, |
| 5275 | megasas_sysfs_show_support_poll_for_event, NULL); |
| 5276 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 5277 | static ssize_t |
| 5278 | megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf) |
| 5279 | { |
| 5280 | return sprintf(buf, "%u\n", support_device_change); |
| 5281 | } |
| 5282 | |
| 5283 | static DRIVER_ATTR(support_device_change, S_IRUGO, |
| 5284 | megasas_sysfs_show_support_device_change, NULL); |
| 5285 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 5286 | static ssize_t |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5287 | megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf) |
| 5288 | { |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5289 | return sprintf(buf, "%u\n", megasas_dbg_lvl); |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | static ssize_t |
| 5293 | megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count) |
| 5294 | { |
| 5295 | int retval = count; |
| 5296 | if(sscanf(buf,"%u",&megasas_dbg_lvl)<1){ |
| 5297 | printk(KERN_ERR "megasas: could not set dbg_lvl\n"); |
| 5298 | retval = -EINVAL; |
| 5299 | } |
| 5300 | return retval; |
| 5301 | } |
| 5302 | |
Joe Malicki | 66dca9b | 2008-08-14 17:14:48 -0400 | [diff] [blame] | 5303 | 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] | 5304 | megasas_sysfs_set_dbg_lvl); |
| 5305 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5306 | static void |
| 5307 | megasas_aen_polling(struct work_struct *work) |
| 5308 | { |
| 5309 | struct megasas_aen_event *ev = |
Xiaotian Feng | c1d390d8 | 2012-12-04 19:33:54 +0800 | [diff] [blame] | 5310 | container_of(work, struct megasas_aen_event, hotplug_work.work); |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5311 | struct megasas_instance *instance = ev->instance; |
| 5312 | union megasas_evt_class_locale class_locale; |
| 5313 | struct Scsi_Host *host; |
| 5314 | struct scsi_device *sdev1; |
| 5315 | u16 pd_index = 0; |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 5316 | u16 ld_index = 0; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5317 | int i, j, doscan = 0; |
| 5318 | u32 seq_num; |
| 5319 | int error; |
| 5320 | |
| 5321 | if (!instance) { |
| 5322 | printk(KERN_ERR "invalid instance!\n"); |
| 5323 | kfree(ev); |
| 5324 | return; |
| 5325 | } |
| 5326 | instance->ev = NULL; |
| 5327 | host = instance->host; |
| 5328 | if (instance->evt_detail) { |
| 5329 | |
| 5330 | switch (instance->evt_detail->code) { |
| 5331 | case MR_EVT_PD_INSERTED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 5332 | if (megasas_get_pd_list(instance) == 0) { |
| 5333 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 5334 | for (j = 0; |
| 5335 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5336 | j++) { |
| 5337 | |
| 5338 | pd_index = |
| 5339 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 5340 | |
| 5341 | sdev1 = |
| 5342 | scsi_device_lookup(host, i, j, 0); |
| 5343 | |
| 5344 | if (instance->pd_list[pd_index].driveState |
| 5345 | == MR_PD_STATE_SYSTEM) { |
| 5346 | if (!sdev1) { |
| 5347 | scsi_add_device(host, i, j, 0); |
| 5348 | } |
| 5349 | |
| 5350 | if (sdev1) |
| 5351 | scsi_device_put(sdev1); |
| 5352 | } |
| 5353 | } |
| 5354 | } |
| 5355 | } |
| 5356 | doscan = 0; |
| 5357 | break; |
| 5358 | |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5359 | case MR_EVT_PD_REMOVED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 5360 | if (megasas_get_pd_list(instance) == 0) { |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 5361 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 5362 | for (j = 0; |
| 5363 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5364 | j++) { |
| 5365 | |
| 5366 | pd_index = |
| 5367 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 5368 | |
| 5369 | sdev1 = |
| 5370 | scsi_device_lookup(host, i, j, 0); |
| 5371 | |
| 5372 | if (instance->pd_list[pd_index].driveState |
| 5373 | == MR_PD_STATE_SYSTEM) { |
| 5374 | if (sdev1) { |
| 5375 | scsi_device_put(sdev1); |
| 5376 | } |
| 5377 | } else { |
| 5378 | if (sdev1) { |
| 5379 | scsi_remove_device(sdev1); |
| 5380 | scsi_device_put(sdev1); |
| 5381 | } |
| 5382 | } |
| 5383 | } |
| 5384 | } |
| 5385 | } |
| 5386 | doscan = 0; |
| 5387 | break; |
| 5388 | |
| 5389 | case MR_EVT_LD_OFFLINE: |
adam radford | 4c598b2 | 2011-02-24 20:56:53 -0800 | [diff] [blame] | 5390 | case MR_EVT_CFG_CLEARED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 5391 | case MR_EVT_LD_DELETED: |
| 5392 | megasas_get_ld_list(instance); |
| 5393 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 5394 | for (j = 0; |
| 5395 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5396 | j++) { |
| 5397 | |
| 5398 | ld_index = |
| 5399 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 5400 | |
| 5401 | sdev1 = scsi_device_lookup(host, |
| 5402 | i + MEGASAS_MAX_LD_CHANNELS, |
| 5403 | j, |
| 5404 | 0); |
| 5405 | |
| 5406 | if (instance->ld_ids[ld_index] != 0xff) { |
| 5407 | if (sdev1) { |
| 5408 | scsi_device_put(sdev1); |
| 5409 | } |
| 5410 | } else { |
| 5411 | if (sdev1) { |
| 5412 | scsi_remove_device(sdev1); |
| 5413 | scsi_device_put(sdev1); |
| 5414 | } |
| 5415 | } |
| 5416 | } |
| 5417 | } |
| 5418 | doscan = 0; |
| 5419 | break; |
| 5420 | case MR_EVT_LD_CREATED: |
| 5421 | megasas_get_ld_list(instance); |
| 5422 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 5423 | for (j = 0; |
| 5424 | j < MEGASAS_MAX_DEV_PER_CHANNEL; |
| 5425 | j++) { |
| 5426 | ld_index = |
| 5427 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 5428 | |
| 5429 | sdev1 = scsi_device_lookup(host, |
| 5430 | i+MEGASAS_MAX_LD_CHANNELS, |
| 5431 | j, 0); |
| 5432 | |
| 5433 | if (instance->ld_ids[ld_index] != |
| 5434 | 0xff) { |
| 5435 | if (!sdev1) { |
| 5436 | scsi_add_device(host, |
| 5437 | i + 2, |
| 5438 | j, 0); |
| 5439 | } |
| 5440 | } |
| 5441 | if (sdev1) { |
| 5442 | scsi_device_put(sdev1); |
| 5443 | } |
| 5444 | } |
| 5445 | } |
| 5446 | doscan = 0; |
| 5447 | break; |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5448 | case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED: |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 5449 | case MR_EVT_FOREIGN_CFG_IMPORTED: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5450 | case MR_EVT_LD_STATE_CHANGE: |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5451 | doscan = 1; |
| 5452 | break; |
| 5453 | default: |
| 5454 | doscan = 0; |
| 5455 | break; |
| 5456 | } |
| 5457 | } else { |
| 5458 | printk(KERN_ERR "invalid evt_detail!\n"); |
| 5459 | kfree(ev); |
| 5460 | return; |
| 5461 | } |
| 5462 | |
| 5463 | if (doscan) { |
| 5464 | printk(KERN_INFO "scanning ...\n"); |
| 5465 | megasas_get_pd_list(instance); |
| 5466 | for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) { |
| 5467 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 5468 | pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j; |
| 5469 | sdev1 = scsi_device_lookup(host, i, j, 0); |
| 5470 | if (instance->pd_list[pd_index].driveState == |
| 5471 | MR_PD_STATE_SYSTEM) { |
| 5472 | if (!sdev1) { |
| 5473 | scsi_add_device(host, i, j, 0); |
| 5474 | } |
| 5475 | if (sdev1) |
| 5476 | scsi_device_put(sdev1); |
| 5477 | } else { |
| 5478 | if (sdev1) { |
| 5479 | scsi_remove_device(sdev1); |
| 5480 | scsi_device_put(sdev1); |
| 5481 | } |
| 5482 | } |
| 5483 | } |
| 5484 | } |
Yang, Bo | c978684 | 2009-12-06 08:39:25 -0700 | [diff] [blame] | 5485 | |
| 5486 | megasas_get_ld_list(instance); |
| 5487 | for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) { |
| 5488 | for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) { |
| 5489 | ld_index = |
| 5490 | (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j; |
| 5491 | |
| 5492 | sdev1 = scsi_device_lookup(host, |
| 5493 | i+MEGASAS_MAX_LD_CHANNELS, j, 0); |
| 5494 | if (instance->ld_ids[ld_index] != 0xff) { |
| 5495 | if (!sdev1) { |
| 5496 | scsi_add_device(host, |
| 5497 | i+2, |
| 5498 | j, 0); |
| 5499 | } else { |
| 5500 | scsi_device_put(sdev1); |
| 5501 | } |
| 5502 | } else { |
| 5503 | if (sdev1) { |
| 5504 | scsi_remove_device(sdev1); |
| 5505 | scsi_device_put(sdev1); |
| 5506 | } |
| 5507 | } |
| 5508 | } |
| 5509 | } |
Yang, Bo | 7e8a75f | 2009-10-06 14:50:17 -0600 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | if ( instance->aen_cmd != NULL ) { |
| 5513 | kfree(ev); |
| 5514 | return ; |
| 5515 | } |
| 5516 | |
| 5517 | seq_num = instance->evt_detail->seq_num + 1; |
| 5518 | |
| 5519 | /* Register AEN with FW for latest sequence number plus 1 */ |
| 5520 | class_locale.members.reserved = 0; |
| 5521 | class_locale.members.locale = MR_EVT_LOCALE_ALL; |
| 5522 | class_locale.members.class = MR_EVT_CLASS_DEBUG; |
| 5523 | mutex_lock(&instance->aen_mutex); |
| 5524 | error = megasas_register_aen(instance, seq_num, |
| 5525 | class_locale.word); |
| 5526 | mutex_unlock(&instance->aen_mutex); |
| 5527 | |
| 5528 | if (error) |
| 5529 | printk(KERN_ERR "register aen failed error %x\n", error); |
| 5530 | |
| 5531 | kfree(ev); |
| 5532 | } |
| 5533 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5534 | /** |
| 5535 | * megasas_init - Driver load entry point |
| 5536 | */ |
| 5537 | static int __init megasas_init(void) |
| 5538 | { |
| 5539 | int rval; |
| 5540 | |
| 5541 | /* |
| 5542 | * Announce driver version and other information |
| 5543 | */ |
| 5544 | printk(KERN_INFO "megasas: %s %s\n", MEGASAS_VERSION, |
| 5545 | MEGASAS_EXT_VERSION); |
| 5546 | |
Kashyap Desai | bd8d6dd | 2012-07-17 18:20:44 -0700 | [diff] [blame] | 5547 | spin_lock_init(&poll_aen_lock); |
| 5548 | |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 5549 | support_poll_for_event = 2; |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 5550 | support_device_change = 1; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 5551 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5552 | memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info)); |
| 5553 | |
| 5554 | /* |
| 5555 | * Register character device node |
| 5556 | */ |
| 5557 | rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops); |
| 5558 | |
| 5559 | if (rval < 0) { |
| 5560 | printk(KERN_DEBUG "megasas: failed to open device node\n"); |
| 5561 | return rval; |
| 5562 | } |
| 5563 | |
| 5564 | megasas_mgmt_majorno = rval; |
| 5565 | |
| 5566 | /* |
| 5567 | * Register ourselves as PCI hotplug module |
| 5568 | */ |
Michal Piotrowski | 4041b9c | 2006-08-17 13:28:22 +0000 | [diff] [blame] | 5569 | rval = pci_register_driver(&megasas_pci_driver); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5570 | |
| 5571 | if (rval) { |
| 5572 | printk(KERN_DEBUG "megasas: PCI hotplug regisration failed \n"); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5573 | goto err_pcidrv; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5574 | } |
| 5575 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5576 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 5577 | &driver_attr_version); |
| 5578 | if (rval) |
| 5579 | goto err_dcf_attr_ver; |
| 5580 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 5581 | &driver_attr_release_date); |
| 5582 | if (rval) |
| 5583 | goto err_dcf_rel_date; |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 5584 | |
| 5585 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 5586 | &driver_attr_support_poll_for_event); |
| 5587 | if (rval) |
| 5588 | goto err_dcf_support_poll_for_event; |
| 5589 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5590 | rval = driver_create_file(&megasas_pci_driver.driver, |
| 5591 | &driver_attr_dbg_lvl); |
| 5592 | if (rval) |
| 5593 | goto err_dcf_dbg_lvl; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5594 | rval = driver_create_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 5595 | &driver_attr_support_device_change); |
| 5596 | if (rval) |
| 5597 | goto err_dcf_support_device_change; |
| 5598 | |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5599 | return rval; |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5600 | |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 5601 | err_dcf_support_device_change: |
| 5602 | driver_remove_file(&megasas_pci_driver.driver, |
bo yang | ad84db2 | 2007-11-09 04:40:16 -0500 | [diff] [blame] | 5603 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5604 | err_dcf_dbg_lvl: |
| 5605 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 5606 | &driver_attr_support_poll_for_event); |
| 5607 | |
| 5608 | err_dcf_support_poll_for_event: |
| 5609 | driver_remove_file(&megasas_pci_driver.driver, |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5610 | &driver_attr_release_date); |
Yang, Bo | 72c4fd3 | 2009-10-06 14:20:59 -0600 | [diff] [blame] | 5611 | |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5612 | err_dcf_rel_date: |
| 5613 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
| 5614 | err_dcf_attr_ver: |
| 5615 | pci_unregister_driver(&megasas_pci_driver); |
| 5616 | err_pcidrv: |
| 5617 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
adam radford | 0d49016 | 2010-12-14 19:17:17 -0800 | [diff] [blame] | 5618 | return rval; |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | /** |
| 5622 | * megasas_exit - Driver unload entry point |
| 5623 | */ |
| 5624 | static void __exit megasas_exit(void) |
| 5625 | { |
Sumant Patro | 658dced | 2006-10-03 13:09:14 -0700 | [diff] [blame] | 5626 | driver_remove_file(&megasas_pci_driver.driver, |
| 5627 | &driver_attr_dbg_lvl); |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5628 | driver_remove_file(&megasas_pci_driver.driver, |
Yang, Bo | 837f5fe | 2010-10-11 06:59:20 -0600 | [diff] [blame] | 5629 | &driver_attr_support_poll_for_event); |
| 5630 | driver_remove_file(&megasas_pci_driver.driver, |
| 5631 | &driver_attr_support_device_change); |
| 5632 | driver_remove_file(&megasas_pci_driver.driver, |
Jeff Garzik | 83aabc1 | 2006-10-04 06:34:03 -0400 | [diff] [blame] | 5633 | &driver_attr_release_date); |
| 5634 | driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); |
Bagalkote, Sreenivas | c4a3e0a | 2005-09-20 17:46:58 -0400 | [diff] [blame] | 5635 | |
| 5636 | pci_unregister_driver(&megasas_pci_driver); |
| 5637 | unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl"); |
| 5638 | } |
| 5639 | |
| 5640 | module_init(megasas_init); |
| 5641 | module_exit(megasas_exit); |