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