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