adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Linux MegaRAID driver for SAS based RAID controllers |
| 3 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 4 | * Copyright (c) 2009-2013 LSI Corporation |
| 5 | * Copyright (c) 2013-2014 Avago Technologies |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 19 | * |
| 20 | * FILE: megaraid_sas_fusion.c |
| 21 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 22 | * Authors: Avago Technologies |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 23 | * Sumant Patro |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 24 | * Adam Radford |
| 25 | * Kashyap Desai <kashyap.desai@avagotech.com> |
| 26 | * Sumit Saxena <sumit.saxena@avagotech.com> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 27 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 28 | * Send feedback to: megaraidlinux.pdl@avagotech.com |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 29 | * |
Sumit.Saxena@avagotech.com | e399065 | 2014-11-17 15:24:03 +0530 | [diff] [blame] | 30 | * Mail to: Avago Technologies, 350 West Trimble Road, Building 90, |
| 31 | * San Jose, California 95131 |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include <linux/kernel.h> |
| 35 | #include <linux/types.h> |
| 36 | #include <linux/pci.h> |
| 37 | #include <linux/list.h> |
| 38 | #include <linux/moduleparam.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/spinlock.h> |
| 41 | #include <linux/interrupt.h> |
| 42 | #include <linux/delay.h> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 43 | #include <linux/uio.h> |
| 44 | #include <linux/uaccess.h> |
| 45 | #include <linux/fs.h> |
| 46 | #include <linux/compat.h> |
| 47 | #include <linux/blkdev.h> |
| 48 | #include <linux/mutex.h> |
| 49 | #include <linux/poll.h> |
| 50 | |
| 51 | #include <scsi/scsi.h> |
| 52 | #include <scsi/scsi_cmnd.h> |
| 53 | #include <scsi/scsi_device.h> |
| 54 | #include <scsi/scsi_host.h> |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 55 | #include <scsi/scsi_dbg.h> |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 56 | #include <linux/dmi.h> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 57 | |
| 58 | #include "megaraid_sas_fusion.h" |
| 59 | #include "megaraid_sas.h" |
| 60 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 61 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 62 | extern void megasas_free_cmds(struct megasas_instance *instance); |
| 63 | extern struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
| 64 | *instance); |
| 65 | extern void |
| 66 | megasas_complete_cmd(struct megasas_instance *instance, |
| 67 | struct megasas_cmd *cmd, u8 alt_status); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 68 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 69 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 70 | int seconds); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 71 | |
| 72 | void |
| 73 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd); |
| 74 | int megasas_alloc_cmds(struct megasas_instance *instance); |
| 75 | int |
| 76 | megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs); |
| 77 | int |
| 78 | megasas_issue_polled(struct megasas_instance *instance, |
| 79 | struct megasas_cmd *cmd); |
adam radford | 53ef2bb | 2011-02-24 20:56:05 -0800 | [diff] [blame] | 80 | void |
| 81 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance); |
| 82 | |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 83 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 84 | void megaraid_sas_kill_hba(struct megasas_instance *instance); |
| 85 | |
| 86 | extern u32 megasas_dbg_lvl; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 87 | void megasas_sriov_heartbeat_handler(unsigned long instance_addr); |
| 88 | int megasas_sriov_start_heartbeat(struct megasas_instance *instance, |
| 89 | int initial); |
| 90 | void megasas_start_timer(struct megasas_instance *instance, |
| 91 | struct timer_list *timer, |
| 92 | void *fn, unsigned long interval); |
| 93 | extern struct megasas_mgmt_info megasas_mgmt_info; |
Sumit Saxena | e3d178c | 2016-01-28 21:04:34 +0530 | [diff] [blame] | 94 | extern unsigned int resetwaittime; |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 95 | extern unsigned int dual_qdepth_disable; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 96 | static void megasas_free_rdpq_fusion(struct megasas_instance *instance); |
| 97 | static void megasas_free_reply_fusion(struct megasas_instance *instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 98 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 99 | |
| 100 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 101 | /** |
| 102 | * megasas_enable_intr_fusion - Enables interrupts |
| 103 | * @regs: MFI register set |
| 104 | */ |
| 105 | void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 106 | megasas_enable_intr_fusion(struct megasas_instance *instance) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 107 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 108 | struct megasas_register_set __iomem *regs; |
| 109 | regs = instance->reg_set; |
Sumit.Saxena@avagotech.com | c2ced17 | 2015-01-05 20:06:13 +0530 | [diff] [blame] | 110 | |
| 111 | instance->mask_interrupts = 0; |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 112 | /* For Thunderbolt/Invader also clear intr on enable */ |
| 113 | writel(~0, ®s->outbound_intr_status); |
| 114 | readl(®s->outbound_intr_status); |
| 115 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 116 | writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 117 | |
| 118 | /* Dummy readl to force pci flush */ |
| 119 | readl(®s->outbound_intr_mask); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * megasas_disable_intr_fusion - Disables interrupt |
| 124 | * @regs: MFI register set |
| 125 | */ |
| 126 | void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 127 | megasas_disable_intr_fusion(struct megasas_instance *instance) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 128 | { |
| 129 | u32 mask = 0xFFFFFFFF; |
| 130 | u32 status; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 131 | struct megasas_register_set __iomem *regs; |
| 132 | regs = instance->reg_set; |
| 133 | instance->mask_interrupts = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 134 | |
| 135 | writel(mask, ®s->outbound_intr_mask); |
| 136 | /* Dummy readl to force pci flush */ |
| 137 | status = readl(®s->outbound_intr_mask); |
| 138 | } |
| 139 | |
| 140 | int |
| 141 | megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs) |
| 142 | { |
| 143 | u32 status; |
| 144 | /* |
| 145 | * Check if it is our interrupt |
| 146 | */ |
| 147 | status = readl(®s->outbound_intr_status); |
| 148 | |
| 149 | if (status & 1) { |
| 150 | writel(status, ®s->outbound_intr_status); |
| 151 | readl(®s->outbound_intr_status); |
| 152 | return 1; |
| 153 | } |
| 154 | if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK)) |
| 155 | return 0; |
| 156 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 157 | return 1; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * megasas_get_cmd_fusion - Get a command from the free pool |
| 162 | * @instance: Adapter soft state |
| 163 | * |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 164 | * Returns a blk_tag indexed mpt frame |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 165 | */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 166 | inline struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance |
| 167 | *instance, u32 blk_tag) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 168 | { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 169 | struct fusion_context *fusion; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 170 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 171 | fusion = instance->ctrl_context; |
| 172 | return fusion->cmd_list[blk_tag]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | /** |
| 176 | * megasas_return_cmd_fusion - Return a cmd to free command pool |
| 177 | * @instance: Adapter soft state |
| 178 | * @cmd: Command packet to be returned to free command pool |
| 179 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 180 | inline void megasas_return_cmd_fusion(struct megasas_instance *instance, |
| 181 | struct megasas_cmd_fusion *cmd) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 182 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 183 | cmd->scmd = NULL; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 184 | memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE); |
| 185 | cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID; |
| 186 | cmd->cmd_completed = false; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /** |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 190 | * megasas_fire_cmd_fusion - Sends command to the FW |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 191 | * @instance: Adapter soft state |
| 192 | * @req_desc: 32bit or 64bit Request descriptor |
| 193 | * |
| 194 | * Perform PCI Write. Ventura supports 32 bit Descriptor. |
| 195 | * Prior to Ventura (12G) MR controller supports 64 bit Descriptor. |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 196 | */ |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 197 | |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 198 | static void |
| 199 | megasas_fire_cmd_fusion(struct megasas_instance *instance, |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 200 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 201 | { |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 202 | if (instance->is_ventura) |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 203 | writel(le32_to_cpu(req_desc->u.low), |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 204 | &instance->reg_set->inbound_single_queue_port); |
| 205 | else { |
| 206 | #if defined(writeq) && defined(CONFIG_64BIT) |
| 207 | u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) | |
| 208 | le32_to_cpu(req_desc->u.low)); |
| 209 | |
| 210 | writeq(req_data, &instance->reg_set->inbound_low_queue_port); |
| 211 | #else |
| 212 | unsigned long flags; |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 213 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 214 | writel(le32_to_cpu(req_desc->u.low), |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 215 | &instance->reg_set->inbound_low_queue_port); |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 216 | writel(le32_to_cpu(req_desc->u.high), |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 217 | &instance->reg_set->inbound_high_queue_port); |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 218 | mmiowb(); |
| 219 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 220 | #endif |
Sasikumar Chandrasekaran | 45f4f2e | 2017-01-10 18:20:43 -0500 | [diff] [blame] | 221 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 222 | } |
| 223 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 224 | /** |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 225 | * megasas_fusion_update_can_queue - Do all Adapter Queue depth related calculations here |
| 226 | * @instance: Adapter soft state |
| 227 | * fw_boot_context: Whether this function called during probe or after OCR |
| 228 | * |
| 229 | * This function is only for fusion controllers. |
| 230 | * Update host can queue, if firmware downgrade max supported firmware commands. |
| 231 | * Firmware upgrade case will be skiped because underlying firmware has |
| 232 | * more resource than exposed to the OS. |
| 233 | * |
| 234 | */ |
| 235 | static void |
| 236 | megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_context) |
| 237 | { |
| 238 | u16 cur_max_fw_cmds = 0; |
| 239 | u16 ldio_threshold = 0; |
| 240 | struct megasas_register_set __iomem *reg_set; |
| 241 | |
| 242 | reg_set = instance->reg_set; |
| 243 | |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 244 | /* ventura FW does not fill outbound_scratch_pad_3 with queue depth */ |
| 245 | if (!instance->is_ventura) |
| 246 | cur_max_fw_cmds = |
| 247 | readl(&instance->reg_set->outbound_scratch_pad_3) & 0x00FFFF; |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 248 | |
| 249 | if (dual_qdepth_disable || !cur_max_fw_cmds) |
| 250 | cur_max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF; |
| 251 | else |
| 252 | ldio_threshold = |
| 253 | (instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF) - MEGASAS_FUSION_IOCTL_CMDS; |
| 254 | |
| 255 | dev_info(&instance->pdev->dev, |
| 256 | "Current firmware maximum commands: %d\t LDIO threshold: %d\n", |
| 257 | cur_max_fw_cmds, ldio_threshold); |
| 258 | |
| 259 | if (fw_boot_context == OCR_CONTEXT) { |
| 260 | cur_max_fw_cmds = cur_max_fw_cmds - 1; |
| 261 | if (cur_max_fw_cmds <= instance->max_fw_cmds) { |
| 262 | instance->cur_can_queue = |
| 263 | cur_max_fw_cmds - (MEGASAS_FUSION_INTERNAL_CMDS + |
| 264 | MEGASAS_FUSION_IOCTL_CMDS); |
| 265 | instance->host->can_queue = instance->cur_can_queue; |
| 266 | instance->ldio_threshold = ldio_threshold; |
| 267 | } |
| 268 | } else { |
| 269 | instance->max_fw_cmds = cur_max_fw_cmds; |
| 270 | instance->ldio_threshold = ldio_threshold; |
| 271 | |
| 272 | if (!instance->is_rdpq) |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 273 | instance->max_fw_cmds = |
| 274 | min_t(u16, instance->max_fw_cmds, 1024); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 275 | |
Sumit Saxena | c3e385a | 2016-04-15 00:23:30 -0700 | [diff] [blame] | 276 | if (reset_devices) |
| 277 | instance->max_fw_cmds = min(instance->max_fw_cmds, |
| 278 | (u16)MEGASAS_KDUMP_QUEUE_DEPTH); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 279 | /* |
| 280 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 281 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 282 | * does not exceed max cmds that the FW can support |
| 283 | */ |
| 284 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
| 285 | |
| 286 | instance->max_scsi_cmds = instance->max_fw_cmds - |
| 287 | (MEGASAS_FUSION_INTERNAL_CMDS + |
| 288 | MEGASAS_FUSION_IOCTL_CMDS); |
| 289 | instance->cur_can_queue = instance->max_scsi_cmds; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 290 | instance->host->can_queue = instance->cur_can_queue; |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 291 | } |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 292 | |
| 293 | if (instance->is_ventura) |
| 294 | instance->max_mpt_cmds = |
| 295 | instance->max_fw_cmds * RAID_1_10_RMW_CMDS; |
| 296 | else |
| 297 | instance->max_mpt_cmds = instance->max_fw_cmds; |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 298 | } |
| 299 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 300 | * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool |
| 301 | * @instance: Adapter soft state |
| 302 | */ |
| 303 | void |
| 304 | megasas_free_cmds_fusion(struct megasas_instance *instance) |
| 305 | { |
| 306 | int i; |
| 307 | struct fusion_context *fusion = instance->ctrl_context; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 308 | struct megasas_cmd_fusion *cmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 309 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 310 | /* SG, Sense */ |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 311 | for (i = 0; i < instance->max_mpt_cmds; i++) { |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 312 | cmd = fusion->cmd_list[i]; |
| 313 | if (cmd) { |
| 314 | if (cmd->sg_frame) |
| 315 | pci_pool_free(fusion->sg_dma_pool, cmd->sg_frame, |
| 316 | cmd->sg_frame_phys_addr); |
| 317 | if (cmd->sense) |
| 318 | pci_pool_free(fusion->sense_dma_pool, cmd->sense, |
| 319 | cmd->sense_phys_addr); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | if (fusion->sg_dma_pool) { |
| 324 | pci_pool_destroy(fusion->sg_dma_pool); |
| 325 | fusion->sg_dma_pool = NULL; |
| 326 | } |
| 327 | if (fusion->sense_dma_pool) { |
| 328 | pci_pool_destroy(fusion->sense_dma_pool); |
| 329 | fusion->sense_dma_pool = NULL; |
| 330 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 331 | |
| 332 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 333 | /* Reply Frame, Desc*/ |
| 334 | if (instance->is_rdpq) |
| 335 | megasas_free_rdpq_fusion(instance); |
| 336 | else |
| 337 | megasas_free_reply_fusion(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 338 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 339 | /* Request Frame, Desc*/ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 340 | if (fusion->req_frames_desc) |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 341 | dma_free_coherent(&instance->pdev->dev, |
| 342 | fusion->request_alloc_sz, fusion->req_frames_desc, |
| 343 | fusion->req_frames_desc_phys); |
| 344 | if (fusion->io_request_frames) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 345 | pci_pool_free(fusion->io_request_frames_pool, |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 346 | fusion->io_request_frames, |
| 347 | fusion->io_request_frames_phys); |
| 348 | if (fusion->io_request_frames_pool) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 349 | pci_pool_destroy(fusion->io_request_frames_pool); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 350 | fusion->io_request_frames_pool = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 351 | } |
| 352 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 353 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 354 | /* cmd_list */ |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 355 | for (i = 0; i < instance->max_mpt_cmds; i++) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 356 | kfree(fusion->cmd_list[i]); |
| 357 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 358 | kfree(fusion->cmd_list); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | /** |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 362 | * megasas_create_sg_sense_fusion - Creates DMA pool for cmd frames |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 363 | * @instance: Adapter soft state |
| 364 | * |
| 365 | */ |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 366 | static int megasas_create_sg_sense_fusion(struct megasas_instance *instance) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 367 | { |
| 368 | int i; |
| 369 | u32 max_cmd; |
| 370 | struct fusion_context *fusion; |
| 371 | struct megasas_cmd_fusion *cmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 372 | |
| 373 | fusion = instance->ctrl_context; |
| 374 | max_cmd = instance->max_fw_cmds; |
| 375 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 376 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 377 | fusion->sg_dma_pool = |
| 378 | pci_pool_create("mr_sg", instance->pdev, |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 379 | instance->max_chain_frame_sz, |
| 380 | MR_DEFAULT_NVME_PAGE_SIZE, 0); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 381 | /* SCSI_SENSE_BUFFERSIZE = 96 bytes */ |
| 382 | fusion->sense_dma_pool = |
| 383 | pci_pool_create("mr_sense", instance->pdev, |
| 384 | SCSI_SENSE_BUFFERSIZE, 64, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 385 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 386 | if (!fusion->sense_dma_pool || !fusion->sg_dma_pool) { |
| 387 | dev_err(&instance->pdev->dev, |
| 388 | "Failed from %s %d\n", __func__, __LINE__); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 389 | return -ENOMEM; |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Allocate and attach a frame to each of the commands in cmd_list |
| 394 | */ |
| 395 | for (i = 0; i < max_cmd; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 396 | cmd = fusion->cmd_list[i]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 397 | cmd->sg_frame = pci_pool_alloc(fusion->sg_dma_pool, |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 398 | GFP_KERNEL, &cmd->sg_frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 399 | |
| 400 | cmd->sense = pci_pool_alloc(fusion->sense_dma_pool, |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 401 | GFP_KERNEL, &cmd->sense_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 402 | if (!cmd->sg_frame || !cmd->sense) { |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 403 | dev_err(&instance->pdev->dev, |
| 404 | "Failed from %s %d\n", __func__, __LINE__); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 405 | return -ENOMEM; |
| 406 | } |
| 407 | } |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 408 | |
| 409 | /* create sense buffer for the raid 1/10 fp */ |
| 410 | for (i = max_cmd; i < instance->max_mpt_cmds; i++) { |
| 411 | cmd = fusion->cmd_list[i]; |
| 412 | cmd->sense = pci_pool_alloc(fusion->sense_dma_pool, |
| 413 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 414 | if (!cmd->sense) { |
| 415 | dev_err(&instance->pdev->dev, |
| 416 | "Failed from %s %d\n", __func__, __LINE__); |
| 417 | return -ENOMEM; |
| 418 | } |
| 419 | } |
| 420 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 421 | return 0; |
| 422 | } |
| 423 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 424 | int |
| 425 | megasas_alloc_cmdlist_fusion(struct megasas_instance *instance) |
| 426 | { |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 427 | u32 max_mpt_cmd, i; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 428 | struct fusion_context *fusion; |
| 429 | |
| 430 | fusion = instance->ctrl_context; |
| 431 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 432 | max_mpt_cmd = instance->max_mpt_cmds; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 433 | |
| 434 | /* |
| 435 | * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers. |
| 436 | * Allocate the dynamic array first and then allocate individual |
| 437 | * commands. |
| 438 | */ |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 439 | fusion->cmd_list = |
| 440 | kzalloc(sizeof(struct megasas_cmd_fusion *) * max_mpt_cmd, |
| 441 | GFP_KERNEL); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 442 | if (!fusion->cmd_list) { |
| 443 | dev_err(&instance->pdev->dev, |
| 444 | "Failed from %s %d\n", __func__, __LINE__); |
| 445 | return -ENOMEM; |
| 446 | } |
| 447 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 448 | |
| 449 | |
| 450 | for (i = 0; i < max_mpt_cmd; i++) { |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 451 | fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion), |
| 452 | GFP_KERNEL); |
| 453 | if (!fusion->cmd_list[i]) { |
| 454 | dev_err(&instance->pdev->dev, |
| 455 | "Failed from %s %d\n", __func__, __LINE__); |
| 456 | return -ENOMEM; |
| 457 | } |
| 458 | } |
| 459 | return 0; |
| 460 | } |
| 461 | int |
| 462 | megasas_alloc_request_fusion(struct megasas_instance *instance) |
| 463 | { |
| 464 | struct fusion_context *fusion; |
| 465 | |
| 466 | fusion = instance->ctrl_context; |
| 467 | |
| 468 | fusion->req_frames_desc = |
| 469 | dma_alloc_coherent(&instance->pdev->dev, |
| 470 | fusion->request_alloc_sz, |
| 471 | &fusion->req_frames_desc_phys, GFP_KERNEL); |
| 472 | if (!fusion->req_frames_desc) { |
| 473 | dev_err(&instance->pdev->dev, |
| 474 | "Failed from %s %d\n", __func__, __LINE__); |
| 475 | return -ENOMEM; |
| 476 | } |
| 477 | |
| 478 | fusion->io_request_frames_pool = |
| 479 | pci_pool_create("mr_ioreq", instance->pdev, |
| 480 | fusion->io_frames_alloc_sz, 16, 0); |
| 481 | |
| 482 | if (!fusion->io_request_frames_pool) { |
| 483 | dev_err(&instance->pdev->dev, |
| 484 | "Failed from %s %d\n", __func__, __LINE__); |
| 485 | return -ENOMEM; |
| 486 | } |
| 487 | |
| 488 | fusion->io_request_frames = |
| 489 | pci_pool_alloc(fusion->io_request_frames_pool, |
| 490 | GFP_KERNEL, &fusion->io_request_frames_phys); |
| 491 | if (!fusion->io_request_frames) { |
| 492 | dev_err(&instance->pdev->dev, |
| 493 | "Failed from %s %d\n", __func__, __LINE__); |
| 494 | return -ENOMEM; |
| 495 | } |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | int |
| 500 | megasas_alloc_reply_fusion(struct megasas_instance *instance) |
| 501 | { |
| 502 | int i, count; |
| 503 | struct fusion_context *fusion; |
| 504 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; |
| 505 | fusion = instance->ctrl_context; |
| 506 | |
| 507 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 508 | fusion->reply_frames_desc_pool = |
| 509 | pci_pool_create("mr_reply", instance->pdev, |
| 510 | fusion->reply_alloc_sz * count, 16, 0); |
| 511 | |
| 512 | if (!fusion->reply_frames_desc_pool) { |
| 513 | dev_err(&instance->pdev->dev, |
| 514 | "Failed from %s %d\n", __func__, __LINE__); |
| 515 | return -ENOMEM; |
| 516 | } |
| 517 | |
| 518 | fusion->reply_frames_desc[0] = |
| 519 | pci_pool_alloc(fusion->reply_frames_desc_pool, |
| 520 | GFP_KERNEL, &fusion->reply_frames_desc_phys[0]); |
| 521 | if (!fusion->reply_frames_desc[0]) { |
| 522 | dev_err(&instance->pdev->dev, |
| 523 | "Failed from %s %d\n", __func__, __LINE__); |
| 524 | return -ENOMEM; |
| 525 | } |
| 526 | reply_desc = fusion->reply_frames_desc[0]; |
| 527 | for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++) |
| 528 | reply_desc->Words = cpu_to_le64(ULLONG_MAX); |
| 529 | |
| 530 | /* This is not a rdpq mode, but driver still populate |
| 531 | * reply_frame_desc array to use same msix index in ISR path. |
| 532 | */ |
| 533 | for (i = 0; i < (count - 1); i++) |
| 534 | fusion->reply_frames_desc[i + 1] = |
| 535 | fusion->reply_frames_desc[i] + |
| 536 | (fusion->reply_alloc_sz)/sizeof(union MPI2_REPLY_DESCRIPTORS_UNION); |
| 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | int |
| 542 | megasas_alloc_rdpq_fusion(struct megasas_instance *instance) |
| 543 | { |
| 544 | int i, j, count; |
| 545 | struct fusion_context *fusion; |
| 546 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; |
| 547 | |
| 548 | fusion = instance->ctrl_context; |
| 549 | |
| 550 | fusion->rdpq_virt = pci_alloc_consistent(instance->pdev, |
| 551 | sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION, |
| 552 | &fusion->rdpq_phys); |
| 553 | if (!fusion->rdpq_virt) { |
| 554 | dev_err(&instance->pdev->dev, |
| 555 | "Failed from %s %d\n", __func__, __LINE__); |
| 556 | return -ENOMEM; |
| 557 | } |
| 558 | |
| 559 | memset(fusion->rdpq_virt, 0, |
| 560 | sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION); |
| 561 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 562 | fusion->reply_frames_desc_pool = pci_pool_create("mr_rdpq", |
| 563 | instance->pdev, fusion->reply_alloc_sz, 16, 0); |
| 564 | |
| 565 | if (!fusion->reply_frames_desc_pool) { |
| 566 | dev_err(&instance->pdev->dev, |
| 567 | "Failed from %s %d\n", __func__, __LINE__); |
| 568 | return -ENOMEM; |
| 569 | } |
| 570 | |
| 571 | for (i = 0; i < count; i++) { |
| 572 | fusion->reply_frames_desc[i] = |
| 573 | pci_pool_alloc(fusion->reply_frames_desc_pool, |
| 574 | GFP_KERNEL, &fusion->reply_frames_desc_phys[i]); |
| 575 | if (!fusion->reply_frames_desc[i]) { |
| 576 | dev_err(&instance->pdev->dev, |
| 577 | "Failed from %s %d\n", __func__, __LINE__); |
| 578 | return -ENOMEM; |
| 579 | } |
| 580 | |
| 581 | fusion->rdpq_virt[i].RDPQBaseAddress = |
| 582 | fusion->reply_frames_desc_phys[i]; |
| 583 | |
| 584 | reply_desc = fusion->reply_frames_desc[i]; |
| 585 | for (j = 0; j < fusion->reply_q_depth; j++, reply_desc++) |
| 586 | reply_desc->Words = cpu_to_le64(ULLONG_MAX); |
| 587 | } |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | static void |
| 592 | megasas_free_rdpq_fusion(struct megasas_instance *instance) { |
| 593 | |
| 594 | int i; |
| 595 | struct fusion_context *fusion; |
| 596 | |
| 597 | fusion = instance->ctrl_context; |
| 598 | |
| 599 | for (i = 0; i < MAX_MSIX_QUEUES_FUSION; i++) { |
| 600 | if (fusion->reply_frames_desc[i]) |
| 601 | pci_pool_free(fusion->reply_frames_desc_pool, |
| 602 | fusion->reply_frames_desc[i], |
| 603 | fusion->reply_frames_desc_phys[i]); |
| 604 | } |
| 605 | |
| 606 | if (fusion->reply_frames_desc_pool) |
| 607 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 608 | |
| 609 | if (fusion->rdpq_virt) |
| 610 | pci_free_consistent(instance->pdev, |
| 611 | sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION, |
| 612 | fusion->rdpq_virt, fusion->rdpq_phys); |
| 613 | } |
| 614 | |
| 615 | static void |
| 616 | megasas_free_reply_fusion(struct megasas_instance *instance) { |
| 617 | |
| 618 | struct fusion_context *fusion; |
| 619 | |
| 620 | fusion = instance->ctrl_context; |
| 621 | |
| 622 | if (fusion->reply_frames_desc[0]) |
| 623 | pci_pool_free(fusion->reply_frames_desc_pool, |
| 624 | fusion->reply_frames_desc[0], |
| 625 | fusion->reply_frames_desc_phys[0]); |
| 626 | |
| 627 | if (fusion->reply_frames_desc_pool) |
| 628 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 629 | |
| 630 | } |
| 631 | |
| 632 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 633 | /** |
| 634 | * megasas_alloc_cmds_fusion - Allocates the command packets |
| 635 | * @instance: Adapter soft state |
| 636 | * |
| 637 | * |
| 638 | * Each frame has a 32-bit field called context. This context is used to get |
| 639 | * back the megasas_cmd_fusion from the frame when a frame gets completed |
| 640 | * In this driver, the 32 bit values are the indices into an array cmd_list. |
| 641 | * This array is used only to look up the megasas_cmd_fusion given the context. |
| 642 | * The free commands themselves are maintained in a linked list called cmd_pool. |
| 643 | * |
| 644 | * cmds are formed in the io_request and sg_frame members of the |
| 645 | * megasas_cmd_fusion. The context field is used to get a request descriptor |
| 646 | * and is used as SMID of the cmd. |
| 647 | * SMID value range is from 1 to max_fw_cmds. |
| 648 | */ |
| 649 | int |
| 650 | megasas_alloc_cmds_fusion(struct megasas_instance *instance) |
| 651 | { |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 652 | int i; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 653 | struct fusion_context *fusion; |
| 654 | struct megasas_cmd_fusion *cmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 655 | u32 offset; |
| 656 | dma_addr_t io_req_base_phys; |
| 657 | u8 *io_req_base; |
| 658 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 659 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 660 | fusion = instance->ctrl_context; |
| 661 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 662 | if (megasas_alloc_cmdlist_fusion(instance)) |
| 663 | goto fail_exit; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 664 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 665 | if (megasas_alloc_request_fusion(instance)) |
| 666 | goto fail_exit; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 667 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 668 | if (instance->is_rdpq) { |
| 669 | if (megasas_alloc_rdpq_fusion(instance)) |
| 670 | goto fail_exit; |
| 671 | } else |
| 672 | if (megasas_alloc_reply_fusion(instance)) |
| 673 | goto fail_exit; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 674 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 675 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 676 | /* The first 256 bytes (SMID 0) is not used. Don't add to the cmd list */ |
| 677 | io_req_base = fusion->io_request_frames + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; |
| 678 | io_req_base_phys = fusion->io_request_frames_phys + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 679 | |
| 680 | /* |
| 681 | * Add all the commands to command pool (fusion->cmd_pool) |
| 682 | */ |
| 683 | |
| 684 | /* SMID 0 is reserved. Set SMID/index from 1 */ |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 685 | for (i = 0; i < instance->max_mpt_cmds; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 686 | cmd = fusion->cmd_list[i]; |
| 687 | offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i; |
| 688 | memset(cmd, 0, sizeof(struct megasas_cmd_fusion)); |
| 689 | cmd->index = i + 1; |
| 690 | cmd->scmd = NULL; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 691 | cmd->sync_cmd_idx = |
| 692 | (i >= instance->max_scsi_cmds && i < instance->max_fw_cmds) ? |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 693 | (i - instance->max_scsi_cmds) : |
| 694 | (u32)ULONG_MAX; /* Set to Invalid */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 695 | cmd->instance = instance; |
| 696 | cmd->io_request = |
| 697 | (struct MPI2_RAID_SCSI_IO_REQUEST *) |
| 698 | (io_req_base + offset); |
| 699 | memset(cmd->io_request, 0, |
| 700 | sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)); |
| 701 | cmd->io_request_phys_addr = io_req_base_phys + offset; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 702 | cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 705 | if (megasas_create_sg_sense_fusion(instance)) |
| 706 | goto fail_exit; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 707 | |
| 708 | return 0; |
| 709 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 710 | fail_exit: |
| 711 | megasas_free_cmds_fusion(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 712 | return -ENOMEM; |
| 713 | } |
| 714 | |
| 715 | /** |
| 716 | * wait_and_poll - Issues a polling command |
| 717 | * @instance: Adapter soft state |
| 718 | * @cmd: Command packet to be issued |
| 719 | * |
| 720 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. |
| 721 | */ |
| 722 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 723 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 724 | int seconds) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 725 | { |
| 726 | int i; |
| 727 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 728 | struct fusion_context *fusion; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 729 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 730 | u32 msecs = seconds * 1000; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 731 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 732 | fusion = instance->ctrl_context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 733 | /* |
| 734 | * Wait for cmd_status to change |
| 735 | */ |
| 736 | for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) { |
| 737 | rmb(); |
| 738 | msleep(20); |
| 739 | } |
| 740 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 741 | if (frame_hdr->cmd_status == MFI_STAT_INVALID_STATUS) |
| 742 | return DCMD_TIMEOUT; |
| 743 | else if (frame_hdr->cmd_status == MFI_STAT_OK) |
| 744 | return DCMD_SUCCESS; |
| 745 | else |
| 746 | return DCMD_FAILED; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /** |
| 750 | * megasas_ioc_init_fusion - Initializes the FW |
| 751 | * @instance: Adapter soft state |
| 752 | * |
| 753 | * Issues the IOC Init cmd |
| 754 | */ |
| 755 | int |
| 756 | megasas_ioc_init_fusion(struct megasas_instance *instance) |
| 757 | { |
| 758 | struct megasas_init_frame *init_frame; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 759 | struct MPI2_IOC_INIT_REQUEST *IOCInitMessage = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 760 | dma_addr_t ioc_init_handle; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 761 | struct megasas_cmd *cmd; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 762 | u8 ret, cur_rdpq_mode; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 763 | struct fusion_context *fusion; |
adam radford | c77a9bd | 2014-03-10 02:51:36 -0700 | [diff] [blame] | 764 | union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 765 | int i; |
| 766 | struct megasas_header *frame_hdr; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 767 | const char *sys_info; |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 768 | MFI_CAPABILITIES *drv_ops; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 769 | u32 scratch_pad_2; |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 770 | unsigned long flags; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 771 | |
| 772 | fusion = instance->ctrl_context; |
| 773 | |
| 774 | cmd = megasas_get_cmd(instance); |
| 775 | |
| 776 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 777 | dev_err(&instance->pdev->dev, "Could not allocate cmd for INIT Frame\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 778 | ret = 1; |
| 779 | goto fail_get_cmd; |
| 780 | } |
| 781 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 782 | scratch_pad_2 = readl |
| 783 | (&instance->reg_set->outbound_scratch_pad_2); |
| 784 | |
| 785 | cur_rdpq_mode = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ? 1 : 0; |
| 786 | |
| 787 | if (instance->is_rdpq && !cur_rdpq_mode) { |
| 788 | dev_err(&instance->pdev->dev, "Firmware downgrade *NOT SUPPORTED*" |
| 789 | " from RDPQ mode to non RDPQ mode\n"); |
| 790 | ret = 1; |
| 791 | goto fail_fw_init; |
| 792 | } |
| 793 | |
Kashyap Desai | d0fc91d | 2016-10-21 06:33:33 -0700 | [diff] [blame] | 794 | instance->fw_sync_cache_support = (scratch_pad_2 & |
| 795 | MR_CAN_HANDLE_SYNC_CACHE_OFFSET) ? 1 : 0; |
| 796 | dev_info(&instance->pdev->dev, "FW supports sync cache\t: %s\n", |
| 797 | instance->fw_sync_cache_support ? "Yes" : "No"); |
| 798 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 799 | IOCInitMessage = |
| 800 | dma_alloc_coherent(&instance->pdev->dev, |
| 801 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 802 | &ioc_init_handle, GFP_KERNEL); |
| 803 | |
| 804 | if (!IOCInitMessage) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 805 | dev_err(&instance->pdev->dev, "Could not allocate memory for " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 806 | "IOCInitMessage\n"); |
| 807 | ret = 1; |
| 808 | goto fail_fw_init; |
| 809 | } |
| 810 | |
| 811 | memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST)); |
| 812 | |
| 813 | IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT; |
| 814 | IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 815 | IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION); |
| 816 | IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); |
| 817 | IOCInitMessage->SystemRequestFrameSize = cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 818 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 819 | IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth); |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 820 | IOCInitMessage->ReplyDescriptorPostQueueAddress = instance->is_rdpq ? |
| 821 | cpu_to_le64(fusion->rdpq_phys) : |
| 822 | cpu_to_le64(fusion->reply_frames_desc_phys[0]); |
| 823 | IOCInitMessage->MsgFlags = instance->is_rdpq ? |
| 824 | MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE : 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 825 | IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys); |
adam radford | 5738f99 | 2012-03-19 19:49:53 -0700 | [diff] [blame] | 826 | IOCInitMessage->HostMSIxVectors = instance->msix_vectors; |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 827 | IOCInitMessage->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 828 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 829 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 830 | |
| 831 | frame_hdr = &cmd->frame->hdr; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 832 | frame_hdr->cmd_status = 0xFF; |
Christoph Hellwig | 48433bd | 2015-04-23 16:33:39 +0530 | [diff] [blame] | 833 | frame_hdr->flags = cpu_to_le16( |
| 834 | le16_to_cpu(frame_hdr->flags) | |
| 835 | MFI_FRAME_DONT_POST_IN_REPLY_QUEUE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 836 | |
| 837 | init_frame->cmd = MFI_CMD_INIT; |
| 838 | init_frame->cmd_status = 0xFF; |
| 839 | |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 840 | drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations); |
| 841 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 842 | /* driver support Extended MSIX */ |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 843 | if (fusion->adapter_type >= INVADER_SERIES) |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 844 | drv_ops->mfi_capabilities.support_additional_msix = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 845 | /* driver supports HA / Remote LUN over Fast Path interface */ |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 846 | drv_ops->mfi_capabilities.support_fp_remote_lun = 1; |
| 847 | |
| 848 | drv_ops->mfi_capabilities.support_max_255lds = 1; |
| 849 | drv_ops->mfi_capabilities.support_ndrive_r1_lb = 1; |
| 850 | drv_ops->mfi_capabilities.security_protocol_cmds_fw = 1; |
| 851 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 852 | if (instance->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN) |
| 853 | drv_ops->mfi_capabilities.support_ext_io_size = 1; |
| 854 | |
Sumit Saxena | 8f05024 | 2016-01-28 21:04:27 +0530 | [diff] [blame] | 855 | drv_ops->mfi_capabilities.support_fp_rlbypass = 1; |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 856 | if (!dual_qdepth_disable) |
| 857 | drv_ops->mfi_capabilities.support_ext_queue_depth = 1; |
Sumit Saxena | 8f05024 | 2016-01-28 21:04:27 +0530 | [diff] [blame] | 858 | |
Sumit Saxena | 52b62ac | 2016-01-28 21:04:31 +0530 | [diff] [blame] | 859 | drv_ops->mfi_capabilities.support_qd_throttling = 1; |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 860 | drv_ops->mfi_capabilities.support_pd_map_target_id = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 861 | /* Convert capability to LE32 */ |
| 862 | cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 863 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 864 | sys_info = dmi_get_system_info(DMI_PRODUCT_UUID); |
| 865 | if (instance->system_info_buf && sys_info) { |
| 866 | memcpy(instance->system_info_buf->systemId, sys_info, |
| 867 | strlen(sys_info) > 64 ? 64 : strlen(sys_info)); |
| 868 | instance->system_info_buf->systemIdLength = |
| 869 | strlen(sys_info) > 64 ? 64 : strlen(sys_info); |
| 870 | init_frame->system_info_lo = instance->system_info_h; |
| 871 | init_frame->system_info_hi = 0; |
| 872 | } |
| 873 | |
Hannes Reinecke | fdc5a97 | 2014-01-16 11:25:33 +0100 | [diff] [blame] | 874 | init_frame->queue_info_new_phys_addr_hi = |
| 875 | cpu_to_le32(upper_32_bits(ioc_init_handle)); |
| 876 | init_frame->queue_info_new_phys_addr_lo = |
| 877 | cpu_to_le32(lower_32_bits(ioc_init_handle)); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 878 | init_frame->data_xfer_len = cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 879 | |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 880 | req_desc.u.low = cpu_to_le32(lower_32_bits(cmd->frame_phys_addr)); |
| 881 | req_desc.u.high = cpu_to_le32(upper_32_bits(cmd->frame_phys_addr)); |
adam radford | c77a9bd | 2014-03-10 02:51:36 -0700 | [diff] [blame] | 882 | req_desc.MFAIo.RequestFlags = |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 883 | (MEGASAS_REQ_DESCRIPT_FLAGS_MFA << |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 884 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 885 | |
| 886 | /* |
| 887 | * disable the intr before firing the init frame |
| 888 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 889 | instance->instancet->disable_intr(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 890 | |
| 891 | for (i = 0; i < (10 * 1000); i += 20) { |
| 892 | if (readl(&instance->reg_set->doorbell) & 1) |
| 893 | msleep(20); |
| 894 | else |
| 895 | break; |
| 896 | } |
| 897 | |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 898 | /* For Ventura also IOC INIT required 64 bit Descriptor write. */ |
| 899 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 900 | writel(le32_to_cpu(req_desc.u.low), |
| 901 | &instance->reg_set->inbound_low_queue_port); |
| 902 | writel(le32_to_cpu(req_desc.u.high), |
| 903 | &instance->reg_set->inbound_high_queue_port); |
| 904 | mmiowb(); |
| 905 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 906 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 907 | wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 908 | |
| 909 | frame_hdr = &cmd->frame->hdr; |
| 910 | if (frame_hdr->cmd_status != 0) { |
| 911 | ret = 1; |
| 912 | goto fail_fw_init; |
| 913 | } |
Andy Lutomirski | 13f3077 | 2016-05-03 10:24:31 -0700 | [diff] [blame] | 914 | dev_info(&instance->pdev->dev, "Init cmd success\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 915 | |
| 916 | ret = 0; |
| 917 | |
| 918 | fail_fw_init: |
| 919 | megasas_return_cmd(instance, cmd); |
| 920 | if (IOCInitMessage) |
| 921 | dma_free_coherent(&instance->pdev->dev, |
| 922 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 923 | IOCInitMessage, ioc_init_handle); |
| 924 | fail_get_cmd: |
| 925 | return ret; |
| 926 | } |
| 927 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 928 | /** |
| 929 | * megasas_sync_pd_seq_num - JBOD SEQ MAP |
| 930 | * @instance: Adapter soft state |
| 931 | * @pend: set to 1, if it is pended jbod map. |
| 932 | * |
| 933 | * Issue Jbod map to the firmware. If it is pended command, |
| 934 | * issue command and return. If it is first instance of jbod map |
| 935 | * issue and receive command. |
| 936 | */ |
| 937 | int |
| 938 | megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) { |
| 939 | int ret = 0; |
| 940 | u32 pd_seq_map_sz; |
| 941 | struct megasas_cmd *cmd; |
| 942 | struct megasas_dcmd_frame *dcmd; |
| 943 | struct fusion_context *fusion = instance->ctrl_context; |
| 944 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
| 945 | dma_addr_t pd_seq_h; |
| 946 | |
| 947 | pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)]; |
| 948 | pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)]; |
| 949 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 950 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 951 | (MAX_PHYSICAL_DEVICES - 1)); |
| 952 | |
| 953 | cmd = megasas_get_cmd(instance); |
| 954 | if (!cmd) { |
| 955 | dev_err(&instance->pdev->dev, |
| 956 | "Could not get mfi cmd. Fail from %s %d\n", |
| 957 | __func__, __LINE__); |
| 958 | return -ENOMEM; |
| 959 | } |
| 960 | |
| 961 | dcmd = &cmd->frame->dcmd; |
| 962 | |
| 963 | memset(pd_sync, 0, pd_seq_map_sz); |
| 964 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 965 | dcmd->cmd = MFI_CMD_DCMD; |
| 966 | dcmd->cmd_status = 0xFF; |
| 967 | dcmd->sge_count = 1; |
| 968 | dcmd->timeout = 0; |
| 969 | dcmd->pad_0 = 0; |
| 970 | dcmd->data_xfer_len = cpu_to_le32(pd_seq_map_sz); |
| 971 | dcmd->opcode = cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO); |
| 972 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(pd_seq_h); |
| 973 | dcmd->sgl.sge32[0].length = cpu_to_le32(pd_seq_map_sz); |
| 974 | |
| 975 | if (pend) { |
| 976 | dcmd->mbox.b[0] = MEGASAS_DCMD_MBOX_PEND_FLAG; |
| 977 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE); |
| 978 | instance->jbod_seq_cmd = cmd; |
| 979 | instance->instancet->issue_dcmd(instance, cmd); |
| 980 | return 0; |
| 981 | } |
| 982 | |
| 983 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
| 984 | |
| 985 | /* Below code is only for non pended DCMD */ |
| 986 | if (instance->ctrl_context && !instance->mask_interrupts) |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 987 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 988 | MFI_IO_TIMEOUT_SECS); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 989 | else |
| 990 | ret = megasas_issue_polled(instance, cmd); |
| 991 | |
| 992 | if (le32_to_cpu(pd_sync->count) > MAX_PHYSICAL_DEVICES) { |
| 993 | dev_warn(&instance->pdev->dev, |
| 994 | "driver supports max %d JBOD, but FW reports %d\n", |
| 995 | MAX_PHYSICAL_DEVICES, le32_to_cpu(pd_sync->count)); |
| 996 | ret = -EINVAL; |
| 997 | } |
| 998 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 999 | if (ret == DCMD_TIMEOUT && instance->ctrl_context) |
| 1000 | megaraid_sas_kill_hba(instance); |
| 1001 | |
| 1002 | if (ret == DCMD_SUCCESS) |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 1003 | instance->pd_seq_map_id++; |
| 1004 | |
| 1005 | megasas_return_cmd(instance, cmd); |
| 1006 | return ret; |
| 1007 | } |
| 1008 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1009 | /* |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1010 | * megasas_get_ld_map_info - Returns FW's ld_map structure |
| 1011 | * @instance: Adapter soft state |
| 1012 | * @pend: Pend the command or not |
| 1013 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 1014 | * list structure. This information is mainly used to find out SYSTEM |
| 1015 | * supported by the FW. |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1016 | * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO |
| 1017 | * dcmd.mbox.b[0] - number of LDs being sync'd |
| 1018 | * dcmd.mbox.b[1] - 0 - complete command immediately. |
| 1019 | * - 1 - pend till config change |
| 1020 | * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP |
| 1021 | * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and |
| 1022 | * uses extended struct MR_FW_RAID_MAP_EXT |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1023 | */ |
| 1024 | static int |
| 1025 | megasas_get_ld_map_info(struct megasas_instance *instance) |
| 1026 | { |
| 1027 | int ret = 0; |
| 1028 | struct megasas_cmd *cmd; |
| 1029 | struct megasas_dcmd_frame *dcmd; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1030 | void *ci; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1031 | dma_addr_t ci_h = 0; |
| 1032 | u32 size_map_info; |
| 1033 | struct fusion_context *fusion; |
| 1034 | |
| 1035 | cmd = megasas_get_cmd(instance); |
| 1036 | |
| 1037 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1038 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for map info\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1039 | return -ENOMEM; |
| 1040 | } |
| 1041 | |
| 1042 | fusion = instance->ctrl_context; |
| 1043 | |
| 1044 | if (!fusion) { |
| 1045 | megasas_return_cmd(instance, cmd); |
Hannes Reinecke | 2f8bdfa | 2014-01-16 11:25:35 +0100 | [diff] [blame] | 1046 | return -ENXIO; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | dcmd = &cmd->frame->dcmd; |
| 1050 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1051 | size_map_info = fusion->current_map_sz; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1052 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1053 | ci = (void *) fusion->ld_map[(instance->map_id & 1)]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1054 | ci_h = fusion->ld_map_phys[(instance->map_id & 1)]; |
| 1055 | |
| 1056 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1057 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ld_map_info\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1058 | megasas_return_cmd(instance, cmd); |
| 1059 | return -ENOMEM; |
| 1060 | } |
| 1061 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1062 | memset(ci, 0, fusion->max_map_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1063 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1064 | #if VD_EXT_DEBUG |
| 1065 | dev_dbg(&instance->pdev->dev, |
| 1066 | "%s sending MR_DCMD_LD_MAP_GET_INFO with size %d\n", |
| 1067 | __func__, cpu_to_le32(size_map_info)); |
| 1068 | #endif |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1069 | dcmd->cmd = MFI_CMD_DCMD; |
| 1070 | dcmd->cmd_status = 0xFF; |
| 1071 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1072 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1073 | dcmd->timeout = 0; |
| 1074 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1075 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
| 1076 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); |
| 1077 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 1078 | dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1079 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1080 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 1081 | ret = megasas_issue_blocked_cmd(instance, cmd, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1082 | MFI_IO_TIMEOUT_SECS); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 1083 | else |
| 1084 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1085 | |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 1086 | if (ret == DCMD_TIMEOUT && instance->ctrl_context) |
| 1087 | megaraid_sas_kill_hba(instance); |
| 1088 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 1089 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1090 | |
| 1091 | return ret; |
| 1092 | } |
| 1093 | |
| 1094 | u8 |
| 1095 | megasas_get_map_info(struct megasas_instance *instance) |
| 1096 | { |
| 1097 | struct fusion_context *fusion = instance->ctrl_context; |
| 1098 | |
| 1099 | fusion->fast_path_io = 0; |
| 1100 | if (!megasas_get_ld_map_info(instance)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 1101 | if (MR_ValidateMapInfo(instance)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1102 | fusion->fast_path_io = 1; |
| 1103 | return 0; |
| 1104 | } |
| 1105 | } |
| 1106 | return 1; |
| 1107 | } |
| 1108 | |
| 1109 | /* |
| 1110 | * megasas_sync_map_info - Returns FW's ld_map structure |
| 1111 | * @instance: Adapter soft state |
| 1112 | * |
| 1113 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 1114 | * list structure. This information is mainly used to find out SYSTEM |
| 1115 | * supported by the FW. |
| 1116 | */ |
| 1117 | int |
| 1118 | megasas_sync_map_info(struct megasas_instance *instance) |
| 1119 | { |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1120 | int i; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1121 | struct megasas_cmd *cmd; |
| 1122 | struct megasas_dcmd_frame *dcmd; |
| 1123 | u32 size_sync_info, num_lds; |
| 1124 | struct fusion_context *fusion; |
| 1125 | struct MR_LD_TARGET_SYNC *ci = NULL; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1126 | struct MR_DRV_RAID_MAP_ALL *map; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1127 | struct MR_LD_RAID *raid; |
| 1128 | struct MR_LD_TARGET_SYNC *ld_sync; |
| 1129 | dma_addr_t ci_h = 0; |
| 1130 | u32 size_map_info; |
| 1131 | |
| 1132 | cmd = megasas_get_cmd(instance); |
| 1133 | |
| 1134 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1135 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for sync info\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1136 | return -ENOMEM; |
| 1137 | } |
| 1138 | |
| 1139 | fusion = instance->ctrl_context; |
| 1140 | |
| 1141 | if (!fusion) { |
| 1142 | megasas_return_cmd(instance, cmd); |
| 1143 | return 1; |
| 1144 | } |
| 1145 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1146 | map = fusion->ld_drv_map[instance->map_id & 1]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1147 | |
Sumit.Saxena@avagotech.com | 6e755dd | 2014-11-17 15:24:28 +0530 | [diff] [blame] | 1148 | num_lds = le16_to_cpu(map->raidMap.ldCount); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1149 | |
| 1150 | dcmd = &cmd->frame->dcmd; |
| 1151 | |
| 1152 | size_sync_info = sizeof(struct MR_LD_TARGET_SYNC) *num_lds; |
| 1153 | |
| 1154 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 1155 | |
| 1156 | ci = (struct MR_LD_TARGET_SYNC *) |
| 1157 | fusion->ld_map[(instance->map_id - 1) & 1]; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1158 | memset(ci, 0, fusion->max_map_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1159 | |
| 1160 | ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1]; |
| 1161 | |
| 1162 | ld_sync = (struct MR_LD_TARGET_SYNC *)ci; |
| 1163 | |
| 1164 | for (i = 0; i < num_lds; i++, ld_sync++) { |
| 1165 | raid = MR_LdRaidGet(i, map); |
| 1166 | ld_sync->targetId = MR_GetLDTgtId(i, map); |
| 1167 | ld_sync->seqNum = raid->seqNum; |
| 1168 | } |
| 1169 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1170 | size_map_info = fusion->current_map_sz; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1171 | |
| 1172 | dcmd->cmd = MFI_CMD_DCMD; |
| 1173 | dcmd->cmd_status = 0xFF; |
| 1174 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1175 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1176 | dcmd->timeout = 0; |
| 1177 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1178 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1179 | dcmd->mbox.b[0] = num_lds; |
| 1180 | dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1181 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); |
| 1182 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 1183 | dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1184 | |
| 1185 | instance->map_update_cmd = cmd; |
| 1186 | |
| 1187 | instance->instancet->issue_dcmd(instance, cmd); |
| 1188 | |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 1189 | return 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1190 | } |
| 1191 | |
Sumit.Saxena@lsi.com | 39b72c3 | 2013-05-22 12:32:43 +0530 | [diff] [blame] | 1192 | /* |
| 1193 | * meagasas_display_intel_branding - Display branding string |
| 1194 | * @instance: per adapter object |
| 1195 | * |
| 1196 | * Return nothing. |
| 1197 | */ |
| 1198 | static void |
| 1199 | megasas_display_intel_branding(struct megasas_instance *instance) |
| 1200 | { |
| 1201 | if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) |
| 1202 | return; |
| 1203 | |
| 1204 | switch (instance->pdev->device) { |
| 1205 | case PCI_DEVICE_ID_LSI_INVADER: |
| 1206 | switch (instance->pdev->subsystem_device) { |
| 1207 | case MEGARAID_INTEL_RS3DC080_SSDID: |
| 1208 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1209 | instance->host->host_no, |
| 1210 | MEGARAID_INTEL_RS3DC080_BRANDING); |
| 1211 | break; |
| 1212 | case MEGARAID_INTEL_RS3DC040_SSDID: |
| 1213 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1214 | instance->host->host_no, |
| 1215 | MEGARAID_INTEL_RS3DC040_BRANDING); |
| 1216 | break; |
| 1217 | case MEGARAID_INTEL_RS3SC008_SSDID: |
| 1218 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1219 | instance->host->host_no, |
| 1220 | MEGARAID_INTEL_RS3SC008_BRANDING); |
| 1221 | break; |
| 1222 | case MEGARAID_INTEL_RS3MC044_SSDID: |
| 1223 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1224 | instance->host->host_no, |
| 1225 | MEGARAID_INTEL_RS3MC044_BRANDING); |
| 1226 | break; |
| 1227 | default: |
| 1228 | break; |
| 1229 | } |
| 1230 | break; |
| 1231 | case PCI_DEVICE_ID_LSI_FURY: |
| 1232 | switch (instance->pdev->subsystem_device) { |
| 1233 | case MEGARAID_INTEL_RS3WC080_SSDID: |
| 1234 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1235 | instance->host->host_no, |
| 1236 | MEGARAID_INTEL_RS3WC080_BRANDING); |
| 1237 | break; |
| 1238 | case MEGARAID_INTEL_RS3WC040_SSDID: |
| 1239 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1240 | instance->host->host_no, |
| 1241 | MEGARAID_INTEL_RS3WC040_BRANDING); |
| 1242 | break; |
| 1243 | default: |
| 1244 | break; |
| 1245 | } |
| 1246 | break; |
sumit.saxena@avagotech.com | 7364d34 | 2015-10-15 13:39:54 +0530 | [diff] [blame] | 1247 | case PCI_DEVICE_ID_LSI_CUTLASS_52: |
| 1248 | case PCI_DEVICE_ID_LSI_CUTLASS_53: |
| 1249 | switch (instance->pdev->subsystem_device) { |
| 1250 | case MEGARAID_INTEL_RMS3BC160_SSDID: |
| 1251 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1252 | instance->host->host_no, |
| 1253 | MEGARAID_INTEL_RMS3BC160_BRANDING); |
| 1254 | break; |
| 1255 | default: |
| 1256 | break; |
| 1257 | } |
| 1258 | break; |
Sumit.Saxena@lsi.com | 39b72c3 | 2013-05-22 12:32:43 +0530 | [diff] [blame] | 1259 | default: |
| 1260 | break; |
| 1261 | } |
| 1262 | } |
| 1263 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1264 | /** |
| 1265 | * megasas_init_adapter_fusion - Initializes the FW |
| 1266 | * @instance: Adapter soft state |
| 1267 | * |
| 1268 | * This is the main function for initializing firmware. |
| 1269 | */ |
| 1270 | u32 |
| 1271 | megasas_init_adapter_fusion(struct megasas_instance *instance) |
| 1272 | { |
| 1273 | struct megasas_register_set __iomem *reg_set; |
| 1274 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 1275 | u32 max_cmd, scratch_pad_2; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1276 | int i = 0, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1277 | |
| 1278 | fusion = instance->ctrl_context; |
| 1279 | |
| 1280 | reg_set = instance->reg_set; |
| 1281 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 1282 | megasas_fusion_update_can_queue(instance, PROBE_CONTEXT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1283 | |
| 1284 | /* |
| 1285 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 1286 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 1287 | * does not exceed max cmds that the FW can support |
| 1288 | */ |
| 1289 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 1290 | |
| 1291 | /* |
| 1292 | * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames |
| 1293 | */ |
| 1294 | instance->max_mfi_cmds = |
| 1295 | MEGASAS_FUSION_INTERNAL_CMDS + MEGASAS_FUSION_IOCTL_CMDS; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1296 | |
| 1297 | max_cmd = instance->max_fw_cmds; |
| 1298 | |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 1299 | fusion->reply_q_depth = 2 * (((max_cmd + 1 + 15)/16)*16); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1300 | |
| 1301 | fusion->request_alloc_sz = |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1302 | sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * instance->max_mpt_cmds; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1303 | fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION) |
| 1304 | *(fusion->reply_q_depth); |
| 1305 | fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE + |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1306 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE |
| 1307 | * (instance->max_mpt_cmds + 1)); /* Extra 1 for SMID 0 */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1308 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 1309 | scratch_pad_2 = readl(&instance->reg_set->outbound_scratch_pad_2); |
| 1310 | /* If scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set, |
| 1311 | * Firmware support extended IO chain frame which is 4 times more than |
| 1312 | * legacy Firmware. |
| 1313 | * Legacy Firmware - Frame size is (8 * 128) = 1K |
| 1314 | * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K |
| 1315 | */ |
| 1316 | if (scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK) |
| 1317 | instance->max_chain_frame_sz = |
| 1318 | ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >> |
| 1319 | MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_1MB_IO; |
| 1320 | else |
| 1321 | instance->max_chain_frame_sz = |
| 1322 | ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >> |
| 1323 | MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_256K_IO; |
| 1324 | |
| 1325 | if (instance->max_chain_frame_sz < MEGASAS_CHAIN_FRAME_SZ_MIN) { |
| 1326 | dev_warn(&instance->pdev->dev, "frame size %d invalid, fall back to legacy max frame size %d\n", |
| 1327 | instance->max_chain_frame_sz, |
| 1328 | MEGASAS_CHAIN_FRAME_SZ_MIN); |
| 1329 | instance->max_chain_frame_sz = MEGASAS_CHAIN_FRAME_SZ_MIN; |
| 1330 | } |
| 1331 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1332 | fusion->max_sge_in_main_msg = |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 1333 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE |
| 1334 | - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1335 | |
| 1336 | fusion->max_sge_in_chain = |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 1337 | instance->max_chain_frame_sz |
| 1338 | / sizeof(union MPI2_SGE_IO_UNION); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1339 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 1340 | instance->max_num_sge = |
| 1341 | rounddown_pow_of_two(fusion->max_sge_in_main_msg |
| 1342 | + fusion->max_sge_in_chain - 2); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1343 | |
| 1344 | /* Used for pass thru MFI frame (DCMD) */ |
| 1345 | fusion->chain_offset_mfi_pthru = |
| 1346 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16; |
| 1347 | |
| 1348 | fusion->chain_offset_io_request = |
| 1349 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - |
| 1350 | sizeof(union MPI2_SGE_IO_UNION))/16; |
| 1351 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1352 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 1353 | for (i = 0 ; i < count; i++) |
| 1354 | fusion->last_reply_idx[i] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1355 | |
| 1356 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 1357 | * For fusion adapters, 3 commands for IOCTL and 5 commands |
| 1358 | * for driver's internal DCMDs. |
| 1359 | */ |
| 1360 | instance->max_scsi_cmds = instance->max_fw_cmds - |
| 1361 | (MEGASAS_FUSION_INTERNAL_CMDS + |
| 1362 | MEGASAS_FUSION_IOCTL_CMDS); |
| 1363 | sema_init(&instance->ioctl_sem, MEGASAS_FUSION_IOCTL_CMDS); |
| 1364 | |
| 1365 | /* |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1366 | * Allocate memory for descriptors |
| 1367 | * Create a pool of commands |
| 1368 | */ |
| 1369 | if (megasas_alloc_cmds(instance)) |
| 1370 | goto fail_alloc_mfi_cmds; |
| 1371 | if (megasas_alloc_cmds_fusion(instance)) |
| 1372 | goto fail_alloc_cmds; |
| 1373 | |
| 1374 | if (megasas_ioc_init_fusion(instance)) |
| 1375 | goto fail_ioc_init; |
| 1376 | |
Sumit.Saxena@lsi.com | 39b72c3 | 2013-05-22 12:32:43 +0530 | [diff] [blame] | 1377 | megasas_display_intel_branding(instance); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 1378 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1379 | dev_err(&instance->pdev->dev, |
| 1380 | "Could not get controller info. Fail from %s %d\n", |
| 1381 | __func__, __LINE__); |
| 1382 | goto fail_ioc_init; |
| 1383 | } |
| 1384 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1385 | instance->flag_ieee = 1; |
Shivasharan S | a48ba0e | 2017-02-10 00:59:13 -0800 | [diff] [blame] | 1386 | instance->r1_ldio_hint_default = MR_R1_LDIO_PIGGYBACK_DEFAULT; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1387 | fusion->fast_path_io = 0; |
| 1388 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1389 | fusion->drv_map_pages = get_order(fusion->drv_map_sz); |
| 1390 | for (i = 0; i < 2; i++) { |
| 1391 | fusion->ld_map[i] = NULL; |
| 1392 | fusion->ld_drv_map[i] = (void *)__get_free_pages(GFP_KERNEL, |
| 1393 | fusion->drv_map_pages); |
| 1394 | if (!fusion->ld_drv_map[i]) { |
| 1395 | dev_err(&instance->pdev->dev, "Could not allocate " |
| 1396 | "memory for local map info for %d pages\n", |
| 1397 | fusion->drv_map_pages); |
| 1398 | if (i == 1) |
| 1399 | free_pages((ulong)fusion->ld_drv_map[0], |
| 1400 | fusion->drv_map_pages); |
| 1401 | goto fail_ioc_init; |
| 1402 | } |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 1403 | memset(fusion->ld_drv_map[i], 0, |
| 1404 | ((1 << PAGE_SHIFT) << fusion->drv_map_pages)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1405 | } |
| 1406 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1407 | for (i = 0; i < 2; i++) { |
| 1408 | fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1409 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1410 | &fusion->ld_map_phys[i], |
| 1411 | GFP_KERNEL); |
| 1412 | if (!fusion->ld_map[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1413 | dev_err(&instance->pdev->dev, "Could not allocate memory " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1414 | "for map info\n"); |
| 1415 | goto fail_map_info; |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | if (!megasas_get_map_info(instance)) |
| 1420 | megasas_sync_map_info(instance); |
| 1421 | |
| 1422 | return 0; |
| 1423 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1424 | fail_map_info: |
| 1425 | if (i == 1) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1426 | dma_free_coherent(&instance->pdev->dev, fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1427 | fusion->ld_map[0], fusion->ld_map_phys[0]); |
| 1428 | fail_ioc_init: |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 1429 | megasas_free_cmds_fusion(instance); |
| 1430 | fail_alloc_cmds: |
| 1431 | megasas_free_cmds(instance); |
| 1432 | fail_alloc_mfi_cmds: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1433 | return 1; |
| 1434 | } |
| 1435 | |
| 1436 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1437 | * map_cmd_status - Maps FW cmd status to OS cmd status |
| 1438 | * @cmd : Pointer to cmd |
| 1439 | * @status : status of cmd returned by FW |
| 1440 | * @ext_status : ext status of cmd returned by FW |
| 1441 | */ |
| 1442 | |
| 1443 | void |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1444 | map_cmd_status(struct fusion_context *fusion, |
| 1445 | struct scsi_cmnd *scmd, u8 status, u8 ext_status, |
| 1446 | u32 data_length, u8 *sense) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1447 | { |
Shivasharan S | 31d9a57 | 2017-02-10 00:59:14 -0800 | [diff] [blame^] | 1448 | int resid; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1449 | |
| 1450 | switch (status) { |
| 1451 | |
| 1452 | case MFI_STAT_OK: |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1453 | scmd->result = DID_OK << 16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1454 | break; |
| 1455 | |
| 1456 | case MFI_STAT_SCSI_IO_FAILED: |
| 1457 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1458 | scmd->result = (DID_ERROR << 16) | ext_status; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1459 | break; |
| 1460 | |
| 1461 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 1462 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1463 | scmd->result = (DID_OK << 16) | ext_status; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1464 | if (ext_status == SAM_STAT_CHECK_CONDITION) { |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1465 | memset(scmd->sense_buffer, 0, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1466 | SCSI_SENSE_BUFFERSIZE); |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1467 | memcpy(scmd->sense_buffer, sense, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1468 | SCSI_SENSE_BUFFERSIZE); |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1469 | scmd->result |= DRIVER_SENSE << 24; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1470 | } |
Shivasharan S | 31d9a57 | 2017-02-10 00:59:14 -0800 | [diff] [blame^] | 1471 | |
| 1472 | /* |
| 1473 | * If the IO request is partially completed, then MR FW will |
| 1474 | * update "io_request->DataLength" field with actual number of |
| 1475 | * bytes transferred.Driver will set residual bytes count in |
| 1476 | * SCSI command structure. |
| 1477 | */ |
| 1478 | resid = (scsi_bufflen(scmd) - data_length); |
| 1479 | scsi_set_resid(scmd, resid); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1480 | break; |
| 1481 | |
| 1482 | case MFI_STAT_LD_OFFLINE: |
| 1483 | case MFI_STAT_DEVICE_NOT_FOUND: |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1484 | scmd->result = DID_BAD_TARGET << 16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1485 | break; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1486 | case MFI_STAT_CONFIG_SEQ_MISMATCH: |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1487 | scmd->result = DID_IMM_RETRY << 16; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1488 | break; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1489 | default: |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 1490 | scmd->result = DID_ERROR << 16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1491 | break; |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | /** |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 1496 | * megasas_is_prp_possible - |
| 1497 | * Checks if native NVMe PRPs can be built for the IO |
| 1498 | * |
| 1499 | * @instance: Adapter soft state |
| 1500 | * @scmd: SCSI command from the mid-layer |
| 1501 | * @sge_count: scatter gather element count. |
| 1502 | * |
| 1503 | * Returns: true: PRPs can be built |
| 1504 | * false: IEEE SGLs needs to be built |
| 1505 | */ |
| 1506 | static bool |
| 1507 | megasas_is_prp_possible(struct megasas_instance *instance, |
| 1508 | struct scsi_cmnd *scmd, int sge_count) |
| 1509 | { |
| 1510 | struct fusion_context *fusion; |
| 1511 | int i; |
| 1512 | u32 data_length = 0; |
| 1513 | struct scatterlist *sg_scmd; |
| 1514 | bool build_prp = false; |
| 1515 | u32 mr_nvme_pg_size; |
| 1516 | |
| 1517 | mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1518 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1519 | fusion = instance->ctrl_context; |
| 1520 | data_length = scsi_bufflen(scmd); |
| 1521 | sg_scmd = scsi_sglist(scmd); |
| 1522 | |
| 1523 | /* |
| 1524 | * NVMe uses one PRP for each page (or part of a page) |
| 1525 | * look at the data length - if 4 pages or less then IEEE is OK |
| 1526 | * if > 5 pages then we need to build a native SGL |
| 1527 | * if > 4 and <= 5 pages, then check physical address of 1st SG entry |
| 1528 | * if this first size in the page is >= the residual beyond 4 pages |
| 1529 | * then use IEEE, otherwise use native SGL |
| 1530 | */ |
| 1531 | |
| 1532 | if (data_length > (mr_nvme_pg_size * 5)) { |
| 1533 | build_prp = true; |
| 1534 | } else if ((data_length > (mr_nvme_pg_size * 4)) && |
| 1535 | (data_length <= (mr_nvme_pg_size * 5))) { |
| 1536 | /* check if 1st SG entry size is < residual beyond 4 pages */ |
| 1537 | if (sg_dma_len(sg_scmd) < (data_length - (mr_nvme_pg_size * 4))) |
| 1538 | build_prp = true; |
| 1539 | } |
| 1540 | |
| 1541 | /* |
| 1542 | * Below code detects gaps/holes in IO data buffers. |
| 1543 | * What does holes/gaps mean? |
| 1544 | * Any SGE except first one in a SGL starts at non NVME page size |
| 1545 | * aligned address OR Any SGE except last one in a SGL ends at |
| 1546 | * non NVME page size boundary. |
| 1547 | * |
| 1548 | * Driver has already informed block layer by setting boundary rules for |
| 1549 | * bio merging done at NVME page size boundary calling kernel API |
| 1550 | * blk_queue_virt_boundary inside slave_config. |
| 1551 | * Still there is possibility of IO coming with holes to driver because of |
| 1552 | * IO merging done by IO scheduler. |
| 1553 | * |
| 1554 | * With SCSI BLK MQ enabled, there will be no IO with holes as there is no |
| 1555 | * IO scheduling so no IO merging. |
| 1556 | * |
| 1557 | * With SCSI BLK MQ disabled, IO scheduler may attempt to merge IOs and |
| 1558 | * then sending IOs with holes. |
| 1559 | * |
| 1560 | * Though driver can request block layer to disable IO merging by calling- |
| 1561 | * queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue) but |
| 1562 | * user may tune sysfs parameter- nomerges again to 0 or 1. |
| 1563 | * |
| 1564 | * If in future IO scheduling is enabled with SCSI BLK MQ, |
| 1565 | * this algorithm to detect holes will be required in driver |
| 1566 | * for SCSI BLK MQ enabled case as well. |
| 1567 | * |
| 1568 | * |
| 1569 | */ |
| 1570 | scsi_for_each_sg(scmd, sg_scmd, sge_count, i) { |
| 1571 | if ((i != 0) && (i != (sge_count - 1))) { |
| 1572 | if (mega_mod64(sg_dma_len(sg_scmd), mr_nvme_pg_size) || |
| 1573 | mega_mod64(sg_dma_address(sg_scmd), |
| 1574 | mr_nvme_pg_size)) { |
| 1575 | build_prp = false; |
| 1576 | atomic_inc(&instance->sge_holes_type1); |
| 1577 | break; |
| 1578 | } |
| 1579 | } |
| 1580 | |
| 1581 | if ((sge_count > 1) && (i == 0)) { |
| 1582 | if ((mega_mod64((sg_dma_address(sg_scmd) + |
| 1583 | sg_dma_len(sg_scmd)), |
| 1584 | mr_nvme_pg_size))) { |
| 1585 | build_prp = false; |
| 1586 | atomic_inc(&instance->sge_holes_type2); |
| 1587 | break; |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | if ((sge_count > 1) && (i == (sge_count - 1))) { |
| 1592 | if (mega_mod64(sg_dma_address(sg_scmd), |
| 1593 | mr_nvme_pg_size)) { |
| 1594 | build_prp = false; |
| 1595 | atomic_inc(&instance->sge_holes_type3); |
| 1596 | break; |
| 1597 | } |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | return build_prp; |
| 1602 | } |
| 1603 | |
| 1604 | /** |
| 1605 | * megasas_make_prp_nvme - |
| 1606 | * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only |
| 1607 | * |
| 1608 | * @instance: Adapter soft state |
| 1609 | * @scmd: SCSI command from the mid-layer |
| 1610 | * @sgl_ptr: SGL to be filled in |
| 1611 | * @cmd: Fusion command frame |
| 1612 | * @sge_count: scatter gather element count. |
| 1613 | * |
| 1614 | * Returns: true: PRPs are built |
| 1615 | * false: IEEE SGLs needs to be built |
| 1616 | */ |
| 1617 | static bool |
| 1618 | megasas_make_prp_nvme(struct megasas_instance *instance, struct scsi_cmnd *scmd, |
| 1619 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr, |
| 1620 | struct megasas_cmd_fusion *cmd, int sge_count) |
| 1621 | { |
| 1622 | int sge_len, offset, num_prp_in_chain = 0; |
| 1623 | struct MPI25_IEEE_SGE_CHAIN64 *main_chain_element, *ptr_first_sgl; |
| 1624 | u64 *ptr_sgl, *ptr_sgl_phys; |
| 1625 | u64 sge_addr; |
| 1626 | u32 page_mask, page_mask_result; |
| 1627 | struct scatterlist *sg_scmd; |
| 1628 | u32 first_prp_len; |
| 1629 | bool build_prp = false; |
| 1630 | int data_len = scsi_bufflen(scmd); |
| 1631 | struct fusion_context *fusion; |
| 1632 | u32 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size, |
| 1633 | MR_DEFAULT_NVME_PAGE_SIZE); |
| 1634 | |
| 1635 | fusion = instance->ctrl_context; |
| 1636 | |
| 1637 | build_prp = megasas_is_prp_possible(instance, scmd, sge_count); |
| 1638 | |
| 1639 | if (!build_prp) |
| 1640 | return false; |
| 1641 | |
| 1642 | /* |
| 1643 | * Nvme has a very convoluted prp format. One prp is required |
| 1644 | * for each page or partial page. Driver need to split up OS sg_list |
| 1645 | * entries if it is longer than one page or cross a page |
| 1646 | * boundary. Driver also have to insert a PRP list pointer entry as |
| 1647 | * the last entry in each physical page of the PRP list. |
| 1648 | * |
| 1649 | * NOTE: The first PRP "entry" is actually placed in the first |
| 1650 | * SGL entry in the main message as IEEE 64 format. The 2nd |
| 1651 | * entry in the main message is the chain element, and the rest |
| 1652 | * of the PRP entries are built in the contiguous pcie buffer. |
| 1653 | */ |
| 1654 | page_mask = mr_nvme_pg_size - 1; |
| 1655 | ptr_sgl = (u64 *)cmd->sg_frame; |
| 1656 | ptr_sgl_phys = (u64 *)cmd->sg_frame_phys_addr; |
| 1657 | memset(ptr_sgl, 0, instance->max_chain_frame_sz); |
| 1658 | |
| 1659 | /* Build chain frame element which holds all prps except first*/ |
| 1660 | main_chain_element = (struct MPI25_IEEE_SGE_CHAIN64 *) |
| 1661 | ((u8 *)sgl_ptr + sizeof(struct MPI25_IEEE_SGE_CHAIN64)); |
| 1662 | |
| 1663 | main_chain_element->Address = cpu_to_le64((uintptr_t)ptr_sgl_phys); |
| 1664 | main_chain_element->NextChainOffset = 0; |
| 1665 | main_chain_element->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 1666 | IEEE_SGE_FLAGS_SYSTEM_ADDR | |
| 1667 | MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP; |
| 1668 | |
| 1669 | /* Build first prp, sge need not to be page aligned*/ |
| 1670 | ptr_first_sgl = sgl_ptr; |
| 1671 | sg_scmd = scsi_sglist(scmd); |
| 1672 | sge_addr = sg_dma_address(sg_scmd); |
| 1673 | sge_len = sg_dma_len(sg_scmd); |
| 1674 | |
| 1675 | offset = (u32)(sge_addr & page_mask); |
| 1676 | first_prp_len = mr_nvme_pg_size - offset; |
| 1677 | |
| 1678 | ptr_first_sgl->Address = cpu_to_le64(sge_addr); |
| 1679 | ptr_first_sgl->Length = cpu_to_le32(first_prp_len); |
| 1680 | |
| 1681 | data_len -= first_prp_len; |
| 1682 | |
| 1683 | if (sge_len > first_prp_len) { |
| 1684 | sge_addr += first_prp_len; |
| 1685 | sge_len -= first_prp_len; |
| 1686 | } else if (sge_len == first_prp_len) { |
| 1687 | sg_scmd = sg_next(sg_scmd); |
| 1688 | sge_addr = sg_dma_address(sg_scmd); |
| 1689 | sge_len = sg_dma_len(sg_scmd); |
| 1690 | } |
| 1691 | |
| 1692 | for (;;) { |
| 1693 | offset = (u32)(sge_addr & page_mask); |
| 1694 | |
| 1695 | /* Put PRP pointer due to page boundary*/ |
| 1696 | page_mask_result = (uintptr_t)(ptr_sgl + 1) & page_mask; |
| 1697 | if (unlikely(!page_mask_result)) { |
| 1698 | scmd_printk(KERN_NOTICE, |
| 1699 | scmd, "page boundary ptr_sgl: 0x%p\n", |
| 1700 | ptr_sgl); |
| 1701 | ptr_sgl_phys++; |
| 1702 | *ptr_sgl = |
| 1703 | cpu_to_le64((uintptr_t)ptr_sgl_phys); |
| 1704 | ptr_sgl++; |
| 1705 | num_prp_in_chain++; |
| 1706 | } |
| 1707 | |
| 1708 | *ptr_sgl = cpu_to_le64(sge_addr); |
| 1709 | ptr_sgl++; |
| 1710 | ptr_sgl_phys++; |
| 1711 | num_prp_in_chain++; |
| 1712 | |
| 1713 | sge_addr += mr_nvme_pg_size; |
| 1714 | sge_len -= mr_nvme_pg_size; |
| 1715 | data_len -= mr_nvme_pg_size; |
| 1716 | |
| 1717 | if (data_len <= 0) |
| 1718 | break; |
| 1719 | |
| 1720 | if (sge_len > 0) |
| 1721 | continue; |
| 1722 | |
| 1723 | sg_scmd = sg_next(sg_scmd); |
| 1724 | sge_addr = sg_dma_address(sg_scmd); |
| 1725 | sge_len = sg_dma_len(sg_scmd); |
| 1726 | } |
| 1727 | |
| 1728 | main_chain_element->Length = |
| 1729 | cpu_to_le32(num_prp_in_chain * sizeof(u64)); |
| 1730 | |
| 1731 | atomic_inc(&instance->prp_sgl); |
| 1732 | return build_prp; |
| 1733 | } |
| 1734 | |
| 1735 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1736 | * megasas_make_sgl_fusion - Prepares 32-bit SGL |
| 1737 | * @instance: Adapter soft state |
| 1738 | * @scp: SCSI command from the mid-layer |
| 1739 | * @sgl_ptr: SGL to be filled in |
| 1740 | * @cmd: cmd we are working on |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 1741 | * @sge_count sge count |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1742 | * |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1743 | */ |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 1744 | static void |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1745 | megasas_make_sgl_fusion(struct megasas_instance *instance, |
| 1746 | struct scsi_cmnd *scp, |
| 1747 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr, |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 1748 | struct megasas_cmd_fusion *cmd, int sge_count) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1749 | { |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 1750 | int i, sg_processed; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1751 | struct scatterlist *os_sgl; |
| 1752 | struct fusion_context *fusion; |
| 1753 | |
| 1754 | fusion = instance->ctrl_context; |
| 1755 | |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 1756 | if (fusion->adapter_type >= INVADER_SERIES) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1757 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr; |
| 1758 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; |
| 1759 | sgl_ptr_end->Flags = 0; |
| 1760 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1761 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1762 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1763 | sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1764 | sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1765 | sgl_ptr->Flags = 0; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 1766 | if (fusion->adapter_type >= INVADER_SERIES) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1767 | if (i == sge_count - 1) |
| 1768 | sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1769 | sgl_ptr++; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1770 | sg_processed = i + 1; |
| 1771 | |
| 1772 | if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) && |
| 1773 | (sge_count > fusion->max_sge_in_main_msg)) { |
| 1774 | |
| 1775 | struct MPI25_IEEE_SGE_CHAIN64 *sg_chain; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 1776 | if (fusion->adapter_type >= INVADER_SERIES) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1777 | if ((le16_to_cpu(cmd->io_request->IoFlags) & |
| 1778 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) != |
| 1779 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1780 | cmd->io_request->ChainOffset = |
| 1781 | fusion-> |
| 1782 | chain_offset_io_request; |
| 1783 | else |
| 1784 | cmd->io_request->ChainOffset = 0; |
| 1785 | } else |
| 1786 | cmd->io_request->ChainOffset = |
| 1787 | fusion->chain_offset_io_request; |
| 1788 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1789 | sg_chain = sgl_ptr; |
| 1790 | /* Prepare chain element */ |
| 1791 | sg_chain->NextChainOffset = 0; |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 1792 | if (fusion->adapter_type >= INVADER_SERIES) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1793 | sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT; |
| 1794 | else |
| 1795 | sg_chain->Flags = |
| 1796 | (IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 1797 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1798 | sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed))); |
| 1799 | sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1800 | |
| 1801 | sgl_ptr = |
| 1802 | (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame; |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 1803 | memset(sgl_ptr, 0, instance->max_chain_frame_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1804 | } |
| 1805 | } |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 1806 | atomic_inc(&instance->ieee_sgl); |
| 1807 | } |
| 1808 | |
| 1809 | /** |
| 1810 | * megasas_make_sgl - Build Scatter Gather List(SGLs) |
| 1811 | * @scp: SCSI command pointer |
| 1812 | * @instance: Soft instance of controller |
| 1813 | * @cmd: Fusion command pointer |
| 1814 | * |
| 1815 | * This function will build sgls based on device type. |
| 1816 | * For nvme drives, there is different way of building sgls in nvme native |
| 1817 | * format- PRPs(Physical Region Page). |
| 1818 | * |
| 1819 | * Returns the number of sg lists actually used, zero if the sg lists |
| 1820 | * is NULL, or -ENOMEM if the mapping failed |
| 1821 | */ |
| 1822 | static |
| 1823 | int megasas_make_sgl(struct megasas_instance *instance, struct scsi_cmnd *scp, |
| 1824 | struct megasas_cmd_fusion *cmd) |
| 1825 | { |
| 1826 | int sge_count; |
| 1827 | bool build_prp = false; |
| 1828 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_chain64; |
| 1829 | |
| 1830 | sge_count = scsi_dma_map(scp); |
| 1831 | |
| 1832 | if ((sge_count > instance->max_num_sge) || (sge_count <= 0)) |
| 1833 | return sge_count; |
| 1834 | |
| 1835 | sgl_chain64 = (struct MPI25_IEEE_SGE_CHAIN64 *)&cmd->io_request->SGL; |
| 1836 | if ((le16_to_cpu(cmd->io_request->IoFlags) & |
| 1837 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) && |
| 1838 | (cmd->pd_interface == NVME_PD)) |
| 1839 | build_prp = megasas_make_prp_nvme(instance, scp, sgl_chain64, |
| 1840 | cmd, sge_count); |
| 1841 | |
| 1842 | if (!build_prp) |
| 1843 | megasas_make_sgl_fusion(instance, scp, sgl_chain64, |
| 1844 | cmd, sge_count); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1845 | |
| 1846 | return sge_count; |
| 1847 | } |
| 1848 | |
| 1849 | /** |
| 1850 | * megasas_set_pd_lba - Sets PD LBA |
| 1851 | * @cdb: CDB |
| 1852 | * @cdb_len: cdb length |
| 1853 | * @start_blk: Start block of IO |
| 1854 | * |
| 1855 | * Used to set the PD LBA in CDB for FP IOs |
| 1856 | */ |
| 1857 | void |
| 1858 | megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len, |
| 1859 | struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1860 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1861 | { |
| 1862 | struct MR_LD_RAID *raid; |
| 1863 | u32 ld; |
| 1864 | u64 start_blk = io_info->pdBlock; |
| 1865 | u8 *cdb = io_request->CDB.CDB32; |
| 1866 | u32 num_blocks = io_info->numBlocks; |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1867 | u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1868 | |
| 1869 | /* Check if T10 PI (DIF) is enabled for this LD */ |
| 1870 | ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr); |
| 1871 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1872 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) { |
| 1873 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1874 | cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD; |
| 1875 | cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN; |
| 1876 | |
| 1877 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1878 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32; |
| 1879 | else |
| 1880 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32; |
| 1881 | cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL; |
| 1882 | |
| 1883 | /* LBA */ |
| 1884 | cdb[12] = (u8)((start_blk >> 56) & 0xff); |
| 1885 | cdb[13] = (u8)((start_blk >> 48) & 0xff); |
| 1886 | cdb[14] = (u8)((start_blk >> 40) & 0xff); |
| 1887 | cdb[15] = (u8)((start_blk >> 32) & 0xff); |
| 1888 | cdb[16] = (u8)((start_blk >> 24) & 0xff); |
| 1889 | cdb[17] = (u8)((start_blk >> 16) & 0xff); |
| 1890 | cdb[18] = (u8)((start_blk >> 8) & 0xff); |
| 1891 | cdb[19] = (u8)(start_blk & 0xff); |
| 1892 | |
| 1893 | /* Logical block reference tag */ |
| 1894 | io_request->CDB.EEDP32.PrimaryReferenceTag = |
| 1895 | cpu_to_be32(ref_tag); |
Sumit.Saxena@avagotech.com | 6e755dd | 2014-11-17 15:24:28 +0530 | [diff] [blame] | 1896 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = cpu_to_be16(0xffff); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1897 | io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1898 | |
| 1899 | /* Transfer length */ |
| 1900 | cdb[28] = (u8)((num_blocks >> 24) & 0xff); |
| 1901 | cdb[29] = (u8)((num_blocks >> 16) & 0xff); |
| 1902 | cdb[30] = (u8)((num_blocks >> 8) & 0xff); |
| 1903 | cdb[31] = (u8)(num_blocks & 0xff); |
| 1904 | |
| 1905 | /* set SCSI IO EEDPFlags */ |
| 1906 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1907 | io_request->EEDPFlags = cpu_to_le16( |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1908 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
| 1909 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 1910 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP | |
| 1911 | MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG | |
Sasikumar Chandrasekaran | 45d4460 | 2017-01-10 18:20:45 -0500 | [diff] [blame] | 1912 | MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1913 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1914 | } else { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1915 | io_request->EEDPFlags = cpu_to_le16( |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1916 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1917 | MPI2_SCSIIO_EEDPFLAGS_INSERT_OP); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1918 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1919 | io_request->Control |= cpu_to_le32((0x4 << 26)); |
| 1920 | io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1921 | } else { |
| 1922 | /* Some drives don't support 16/12 byte CDB's, convert to 10 */ |
| 1923 | if (((cdb_len == 12) || (cdb_len == 16)) && |
| 1924 | (start_blk <= 0xffffffff)) { |
| 1925 | if (cdb_len == 16) { |
| 1926 | opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10; |
| 1927 | flagvals = cdb[1]; |
| 1928 | groupnum = cdb[14]; |
| 1929 | control = cdb[15]; |
| 1930 | } else { |
| 1931 | opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10; |
| 1932 | flagvals = cdb[1]; |
| 1933 | groupnum = cdb[10]; |
| 1934 | control = cdb[11]; |
| 1935 | } |
| 1936 | |
| 1937 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1938 | |
| 1939 | cdb[0] = opcode; |
| 1940 | cdb[1] = flagvals; |
| 1941 | cdb[6] = groupnum; |
| 1942 | cdb[9] = control; |
| 1943 | |
| 1944 | /* Transfer length */ |
| 1945 | cdb[8] = (u8)(num_blocks & 0xff); |
| 1946 | cdb[7] = (u8)((num_blocks >> 8) & 0xff); |
| 1947 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1948 | io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1949 | cdb_len = 10; |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1950 | } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) { |
| 1951 | /* Convert to 16 byte CDB for large LBA's */ |
| 1952 | switch (cdb_len) { |
| 1953 | case 6: |
| 1954 | opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16; |
| 1955 | control = cdb[5]; |
| 1956 | break; |
| 1957 | case 10: |
| 1958 | opcode = |
| 1959 | cdb[0] == READ_10 ? READ_16 : WRITE_16; |
| 1960 | flagvals = cdb[1]; |
| 1961 | groupnum = cdb[6]; |
| 1962 | control = cdb[9]; |
| 1963 | break; |
| 1964 | case 12: |
| 1965 | opcode = |
| 1966 | cdb[0] == READ_12 ? READ_16 : WRITE_16; |
| 1967 | flagvals = cdb[1]; |
| 1968 | groupnum = cdb[10]; |
| 1969 | control = cdb[11]; |
| 1970 | break; |
| 1971 | } |
| 1972 | |
| 1973 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1974 | |
| 1975 | cdb[0] = opcode; |
| 1976 | cdb[1] = flagvals; |
| 1977 | cdb[14] = groupnum; |
| 1978 | cdb[15] = control; |
| 1979 | |
| 1980 | /* Transfer length */ |
| 1981 | cdb[13] = (u8)(num_blocks & 0xff); |
| 1982 | cdb[12] = (u8)((num_blocks >> 8) & 0xff); |
| 1983 | cdb[11] = (u8)((num_blocks >> 16) & 0xff); |
| 1984 | cdb[10] = (u8)((num_blocks >> 24) & 0xff); |
| 1985 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1986 | io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */ |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1987 | cdb_len = 16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | /* Normal case, just load LBA here */ |
| 1991 | switch (cdb_len) { |
| 1992 | case 6: |
| 1993 | { |
| 1994 | u8 val = cdb[1] & 0xE0; |
| 1995 | cdb[3] = (u8)(start_blk & 0xff); |
| 1996 | cdb[2] = (u8)((start_blk >> 8) & 0xff); |
| 1997 | cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f); |
| 1998 | break; |
| 1999 | } |
| 2000 | case 10: |
| 2001 | cdb[5] = (u8)(start_blk & 0xff); |
| 2002 | cdb[4] = (u8)((start_blk >> 8) & 0xff); |
| 2003 | cdb[3] = (u8)((start_blk >> 16) & 0xff); |
| 2004 | cdb[2] = (u8)((start_blk >> 24) & 0xff); |
| 2005 | break; |
| 2006 | case 12: |
| 2007 | cdb[5] = (u8)(start_blk & 0xff); |
| 2008 | cdb[4] = (u8)((start_blk >> 8) & 0xff); |
| 2009 | cdb[3] = (u8)((start_blk >> 16) & 0xff); |
| 2010 | cdb[2] = (u8)((start_blk >> 24) & 0xff); |
| 2011 | break; |
| 2012 | case 16: |
| 2013 | cdb[9] = (u8)(start_blk & 0xff); |
| 2014 | cdb[8] = (u8)((start_blk >> 8) & 0xff); |
| 2015 | cdb[7] = (u8)((start_blk >> 16) & 0xff); |
| 2016 | cdb[6] = (u8)((start_blk >> 24) & 0xff); |
| 2017 | cdb[5] = (u8)((start_blk >> 32) & 0xff); |
| 2018 | cdb[4] = (u8)((start_blk >> 40) & 0xff); |
| 2019 | cdb[3] = (u8)((start_blk >> 48) & 0xff); |
| 2020 | cdb[2] = (u8)((start_blk >> 56) & 0xff); |
| 2021 | break; |
| 2022 | } |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | /** |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2027 | * megasas_stream_detect - stream detection on read and and write IOs |
| 2028 | * @instance: Adapter soft state |
| 2029 | * @cmd: Command to be prepared |
| 2030 | * @io_info: IO Request info |
| 2031 | * |
| 2032 | */ |
| 2033 | |
| 2034 | /** stream detection on read and and write IOs */ |
| 2035 | static void megasas_stream_detect(struct megasas_instance *instance, |
| 2036 | struct megasas_cmd_fusion *cmd, |
| 2037 | struct IO_REQUEST_INFO *io_info) |
| 2038 | { |
| 2039 | struct fusion_context *fusion = instance->ctrl_context; |
| 2040 | u32 device_id = io_info->ldTgtId; |
| 2041 | struct LD_STREAM_DETECT *current_ld_sd |
| 2042 | = fusion->stream_detect_by_ld[device_id]; |
| 2043 | u32 *track_stream = ¤t_ld_sd->mru_bit_map, stream_num; |
| 2044 | u32 shifted_values, unshifted_values; |
| 2045 | u32 index_value_mask, shifted_values_mask; |
| 2046 | int i; |
| 2047 | bool is_read_ahead = false; |
| 2048 | struct STREAM_DETECT *current_sd; |
| 2049 | /* find possible stream */ |
| 2050 | for (i = 0; i < MAX_STREAMS_TRACKED; ++i) { |
| 2051 | stream_num = |
| 2052 | (*track_stream >> (i * BITS_PER_INDEX_STREAM)) & |
| 2053 | STREAM_MASK; |
| 2054 | current_sd = ¤t_ld_sd->stream_track[stream_num]; |
| 2055 | /* if we found a stream, update the raid |
| 2056 | * context and also update the mruBitMap |
| 2057 | */ |
| 2058 | /* boundary condition */ |
| 2059 | if ((current_sd->next_seq_lba) && |
| 2060 | (io_info->ldStartBlock >= current_sd->next_seq_lba) && |
| 2061 | (io_info->ldStartBlock <= (current_sd->next_seq_lba+32)) && |
| 2062 | (current_sd->is_read == io_info->isRead)) { |
| 2063 | |
| 2064 | if ((io_info->ldStartBlock != current_sd->next_seq_lba) |
| 2065 | && ((!io_info->isRead) || (!is_read_ahead))) |
| 2066 | /* |
| 2067 | * Once the API availible we need to change this. |
| 2068 | * At this point we are not allowing any gap |
| 2069 | */ |
| 2070 | continue; |
| 2071 | |
| 2072 | cmd->io_request->RaidContext.raid_context_g35.stream_detected = true; |
| 2073 | current_sd->next_seq_lba = |
| 2074 | io_info->ldStartBlock + io_info->numBlocks; |
| 2075 | /* |
| 2076 | * update the mruBitMap LRU |
| 2077 | */ |
| 2078 | shifted_values_mask = |
| 2079 | (1 << i * BITS_PER_INDEX_STREAM) - 1; |
| 2080 | shifted_values = ((*track_stream & shifted_values_mask) |
| 2081 | << BITS_PER_INDEX_STREAM); |
| 2082 | index_value_mask = |
| 2083 | STREAM_MASK << i * BITS_PER_INDEX_STREAM; |
| 2084 | unshifted_values = |
| 2085 | *track_stream & ~(shifted_values_mask | |
| 2086 | index_value_mask); |
| 2087 | *track_stream = |
| 2088 | unshifted_values | shifted_values | stream_num; |
| 2089 | return; |
| 2090 | |
| 2091 | } |
| 2092 | |
| 2093 | } |
| 2094 | /* |
| 2095 | * if we did not find any stream, create a new one |
| 2096 | * from the least recently used |
| 2097 | */ |
| 2098 | stream_num = |
| 2099 | (*track_stream >> ((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) & |
| 2100 | STREAM_MASK; |
| 2101 | current_sd = ¤t_ld_sd->stream_track[stream_num]; |
| 2102 | current_sd->is_read = io_info->isRead; |
| 2103 | current_sd->next_seq_lba = io_info->ldStartBlock + io_info->numBlocks; |
| 2104 | *track_stream = |
| 2105 | (((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num); |
| 2106 | return; |
| 2107 | |
| 2108 | } |
| 2109 | |
| 2110 | /** |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2111 | * megasas_set_raidflag_cpu_affinity - This function sets the cpu |
| 2112 | * affinity (cpu of the controller) and raid_flags in the raid context |
| 2113 | * based on IO type. |
| 2114 | * |
| 2115 | * @praid_context: IO RAID context |
| 2116 | * @raid: LD raid map |
| 2117 | * @fp_possible: Is fast path possible? |
| 2118 | * @is_read: Is read IO? |
| 2119 | * |
| 2120 | */ |
| 2121 | static void |
| 2122 | megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context, |
| 2123 | struct MR_LD_RAID *raid, bool fp_possible, |
Shivasharan S | a48ba0e | 2017-02-10 00:59:13 -0800 | [diff] [blame] | 2124 | u8 is_read, u32 scsi_buff_len) |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2125 | { |
| 2126 | u8 cpu_sel = MR_RAID_CTX_CPUSEL_0; |
| 2127 | struct RAID_CONTEXT_G35 *rctx_g35; |
| 2128 | |
| 2129 | rctx_g35 = &praid_context->raid_context_g35; |
| 2130 | if (fp_possible) { |
| 2131 | if (is_read) { |
| 2132 | if ((raid->cpuAffinity.pdRead.cpu0) && |
| 2133 | (raid->cpuAffinity.pdRead.cpu1)) |
| 2134 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; |
| 2135 | else if (raid->cpuAffinity.pdRead.cpu1) |
| 2136 | cpu_sel = MR_RAID_CTX_CPUSEL_1; |
| 2137 | } else { |
| 2138 | if ((raid->cpuAffinity.pdWrite.cpu0) && |
| 2139 | (raid->cpuAffinity.pdWrite.cpu1)) |
| 2140 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; |
| 2141 | else if (raid->cpuAffinity.pdWrite.cpu1) |
| 2142 | cpu_sel = MR_RAID_CTX_CPUSEL_1; |
| 2143 | /* Fast path cache by pass capable R0/R1 VD */ |
| 2144 | if ((raid->level <= 1) && |
| 2145 | (raid->capability.fp_cache_bypass_capable)) { |
| 2146 | rctx_g35->routing_flags.bits.sld = 1; |
| 2147 | rctx_g35->raid_flags = |
| 2148 | (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS |
| 2149 | << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT); |
| 2150 | } |
| 2151 | } |
| 2152 | } else { |
| 2153 | if (is_read) { |
| 2154 | if ((raid->cpuAffinity.ldRead.cpu0) && |
| 2155 | (raid->cpuAffinity.ldRead.cpu1)) |
| 2156 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; |
| 2157 | else if (raid->cpuAffinity.ldRead.cpu1) |
| 2158 | cpu_sel = MR_RAID_CTX_CPUSEL_1; |
| 2159 | } else { |
| 2160 | if ((raid->cpuAffinity.ldWrite.cpu0) && |
| 2161 | (raid->cpuAffinity.ldWrite.cpu1)) |
| 2162 | cpu_sel = MR_RAID_CTX_CPUSEL_FCFS; |
| 2163 | else if (raid->cpuAffinity.ldWrite.cpu1) |
| 2164 | cpu_sel = MR_RAID_CTX_CPUSEL_1; |
| 2165 | |
| 2166 | if (rctx_g35->stream_detected && |
| 2167 | (raid->level == 5) && |
| 2168 | (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) && |
| 2169 | (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS)) |
| 2170 | cpu_sel = MR_RAID_CTX_CPUSEL_0; |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | rctx_g35->routing_flags.bits.cpu_sel = cpu_sel; |
Shivasharan S | a48ba0e | 2017-02-10 00:59:13 -0800 | [diff] [blame] | 2175 | |
| 2176 | /* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT |
| 2177 | * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS. |
| 2178 | * IO Subtype is not bitmap. |
| 2179 | */ |
| 2180 | if ((raid->level == 1) && (!is_read)) { |
| 2181 | if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE) |
| 2182 | praid_context->raid_context_g35.raid_flags = |
| 2183 | (MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT |
| 2184 | << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT); |
| 2185 | } |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2189 | * megasas_build_ldio_fusion - Prepares IOs to devices |
| 2190 | * @instance: Adapter soft state |
| 2191 | * @scp: SCSI command |
| 2192 | * @cmd: Command to be prepared |
| 2193 | * |
| 2194 | * Prepares the io_request and chain elements (sg_frame) for IO |
| 2195 | * The IO can be for PD (Fast Path) or LD |
| 2196 | */ |
| 2197 | void |
| 2198 | megasas_build_ldio_fusion(struct megasas_instance *instance, |
| 2199 | struct scsi_cmnd *scp, |
| 2200 | struct megasas_cmd_fusion *cmd) |
| 2201 | { |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2202 | bool fp_possible; |
| 2203 | u16 ld; |
| 2204 | u32 start_lba_lo, start_lba_hi, device_id, datalength = 0; |
| 2205 | u32 scsi_buff_len; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2206 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 2207 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2208 | struct IO_REQUEST_INFO io_info; |
| 2209 | struct fusion_context *fusion; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 2210 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2211 | u8 *raidLUN; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2212 | unsigned long spinlock_flags; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2213 | union RAID_CONTEXT_UNION *praid_context; |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2214 | struct MR_LD_RAID *raid = NULL; |
| 2215 | struct MR_PRIV_DEVICE *mrdev_priv; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2216 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2217 | device_id = MEGASAS_DEV_INDEX(scp); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2218 | |
| 2219 | fusion = instance->ctrl_context; |
| 2220 | |
| 2221 | io_request = cmd->io_request; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2222 | io_request->RaidContext.raid_context.virtual_disk_tgt_id = |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2223 | cpu_to_le16(device_id); |
| 2224 | io_request->RaidContext.raid_context.status = 0; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2225 | io_request->RaidContext.raid_context.ex_status = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2226 | |
| 2227 | req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc; |
| 2228 | |
| 2229 | start_lba_lo = 0; |
| 2230 | start_lba_hi = 0; |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2231 | fp_possible = false; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2232 | |
| 2233 | /* |
| 2234 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 2235 | */ |
| 2236 | if (scp->cmd_len == 6) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 2237 | datalength = (u32) scp->cmnd[4]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2238 | start_lba_lo = ((u32) scp->cmnd[1] << 16) | |
| 2239 | ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3]; |
| 2240 | |
| 2241 | start_lba_lo &= 0x1FFFFF; |
| 2242 | } |
| 2243 | |
| 2244 | /* |
| 2245 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 2246 | */ |
| 2247 | else if (scp->cmd_len == 10) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 2248 | datalength = (u32) scp->cmnd[8] | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2249 | ((u32) scp->cmnd[7] << 8); |
| 2250 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 2251 | ((u32) scp->cmnd[3] << 16) | |
| 2252 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 2253 | } |
| 2254 | |
| 2255 | /* |
| 2256 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 2257 | */ |
| 2258 | else if (scp->cmd_len == 12) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 2259 | datalength = ((u32) scp->cmnd[6] << 24) | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2260 | ((u32) scp->cmnd[7] << 16) | |
| 2261 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 2262 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 2263 | ((u32) scp->cmnd[3] << 16) | |
| 2264 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 2265 | } |
| 2266 | |
| 2267 | /* |
| 2268 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 2269 | */ |
| 2270 | else if (scp->cmd_len == 16) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 2271 | datalength = ((u32) scp->cmnd[10] << 24) | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2272 | ((u32) scp->cmnd[11] << 16) | |
| 2273 | ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13]; |
| 2274 | start_lba_lo = ((u32) scp->cmnd[6] << 24) | |
| 2275 | ((u32) scp->cmnd[7] << 16) | |
| 2276 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 2277 | |
| 2278 | start_lba_hi = ((u32) scp->cmnd[2] << 24) | |
| 2279 | ((u32) scp->cmnd[3] << 16) | |
| 2280 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 2281 | } |
| 2282 | |
| 2283 | memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO)); |
| 2284 | io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo; |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 2285 | io_info.numBlocks = datalength; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2286 | io_info.ldTgtId = device_id; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2287 | io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID; |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2288 | scsi_buff_len = scsi_bufflen(scp); |
| 2289 | io_request->DataLength = cpu_to_le32(scsi_buff_len); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2290 | |
| 2291 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 2292 | io_info.isRead = 1; |
| 2293 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 2294 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2295 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
| 2296 | raid = MR_LdRaidGet(ld, local_map_ptr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2297 | |
| 2298 | if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >= |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 2299 | instance->fw_supported_vd_count) || (!fusion->fast_path_io)) { |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2300 | io_request->RaidContext.raid_context.reg_lock_flags = 0; |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2301 | fp_possible = false; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2302 | } else { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2303 | if (MR_BuildRaidContext(instance, &io_info, |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2304 | &io_request->RaidContext.raid_context, |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2305 | local_map_ptr, &raidLUN)) |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2306 | fp_possible = (io_info.fpOkForIo > 0) ? true : false; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2307 | } |
| 2308 | |
Christoph Hellwig | 16b8528 | 2015-04-15 09:44:37 -0700 | [diff] [blame] | 2309 | /* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2310 | id by default, not CPU group id, otherwise all MSI-X queues won't |
| 2311 | be utilized */ |
| 2312 | cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ? |
Christoph Hellwig | 16b8528 | 2015-04-15 09:44:37 -0700 | [diff] [blame] | 2313 | raw_smp_processor_id() % instance->msix_vectors : 0; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2314 | |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2315 | praid_context = &io_request->RaidContext; |
| 2316 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2317 | if (instance->is_ventura) { |
| 2318 | spin_lock_irqsave(&instance->stream_lock, spinlock_flags); |
| 2319 | megasas_stream_detect(instance, cmd, &io_info); |
| 2320 | spin_unlock_irqrestore(&instance->stream_lock, spinlock_flags); |
| 2321 | /* In ventura if stream detected for a read and it is read ahead |
| 2322 | * capable make this IO as LDIO |
| 2323 | */ |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2324 | if (praid_context->raid_context_g35.stream_detected && |
| 2325 | io_info.isRead && io_info.ra_capable) |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2326 | fp_possible = false; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2327 | |
Shivasharan S | a48ba0e | 2017-02-10 00:59:13 -0800 | [diff] [blame] | 2328 | /* FP for Optimal raid level 1. |
| 2329 | * All large RAID-1 writes (> 32 KiB, both WT and WB modes) |
| 2330 | * are built by the driver as LD I/Os. |
| 2331 | * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os |
| 2332 | * (there is never a reason to process these as buffered writes) |
| 2333 | * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os |
| 2334 | * with the SLD bit asserted. |
| 2335 | */ |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2336 | if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) { |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2337 | mrdev_priv = scp->device->hostdata; |
| 2338 | |
| 2339 | if (atomic_inc_return(&instance->fw_outstanding) > |
| 2340 | (instance->host->can_queue)) { |
| 2341 | fp_possible = false; |
| 2342 | atomic_dec(&instance->fw_outstanding); |
Shivasharan S | a48ba0e | 2017-02-10 00:59:13 -0800 | [diff] [blame] | 2343 | } else if ((scsi_buff_len > MR_LARGE_IO_MIN_SIZE) || |
| 2344 | atomic_dec_if_positive(&mrdev_priv->r1_ldio_hint)) { |
| 2345 | fp_possible = false; |
| 2346 | atomic_dec(&instance->fw_outstanding); |
| 2347 | if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE) |
| 2348 | atomic_set(&mrdev_priv->r1_ldio_hint, |
| 2349 | instance->r1_ldio_hint_default); |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | /* If raid is NULL, set CPU affinity to default CPU0 */ |
| 2354 | if (raid) |
| 2355 | megasas_set_raidflag_cpu_affinity(praid_context, |
Shivasharan S | a48ba0e | 2017-02-10 00:59:13 -0800 | [diff] [blame] | 2356 | raid, fp_possible, io_info.isRead, |
| 2357 | scsi_buff_len); |
Shivasharan S | f6c0d55 | 2017-02-10 00:59:02 -0800 | [diff] [blame] | 2358 | else |
| 2359 | praid_context->raid_context_g35.routing_flags.bits.cpu_sel = |
| 2360 | MR_RAID_CTX_CPUSEL_0; |
| 2361 | } |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2362 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2363 | if (fp_possible) { |
| 2364 | megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp, |
| 2365 | local_map_ptr, start_lba_lo); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2366 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 2367 | cmd->request_desc->SCSIIO.RequestFlags = |
Sumit Saxena | 2c04835 | 2016-01-28 21:04:24 +0530 | [diff] [blame] | 2368 | (MPI2_REQ_DESCRIPT_FLAGS_FP_IO |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2369 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 2370 | if (fusion->adapter_type == INVADER_SERIES) { |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2371 | if (io_request->RaidContext.raid_context.reg_lock_flags == |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2372 | REGION_TYPE_UNUSED) |
| 2373 | cmd->request_desc->SCSIIO.RequestFlags = |
| 2374 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << |
| 2375 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2376 | io_request->RaidContext.raid_context.type |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2377 | = MPI2_TYPE_CUDA; |
| 2378 | io_request->RaidContext.raid_context.nseg = 0x1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2379 | io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2380 | io_request->RaidContext.raid_context.reg_lock_flags |= |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2381 | (MR_RL_FLAGS_GRANT_DESTINATION_CUDA | |
| 2382 | MR_RL_FLAGS_SEQ_NUM_ENABLE); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2383 | } else if (instance->is_ventura) { |
| 2384 | io_request->RaidContext.raid_context_g35.type |
| 2385 | = MPI2_TYPE_CUDA; |
| 2386 | io_request->RaidContext.raid_context_g35.nseg = 0x1; |
| 2387 | io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1; |
| 2388 | io_request->IoFlags |= |
| 2389 | cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2390 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2391 | if ((fusion->load_balance_info[device_id].loadBalanceFlag) && |
| 2392 | (io_info.isRead)) { |
| 2393 | io_info.devHandle = |
Sumit.Saxena@avagotech.com | d2552eb | 2014-09-12 18:57:53 +0530 | [diff] [blame] | 2394 | get_updated_dev_handle(instance, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2395 | &fusion->load_balance_info[device_id], |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 2396 | &io_info, local_map_ptr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2397 | scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG; |
Sumit.Saxena@avagotech.com | d2552eb | 2014-09-12 18:57:53 +0530 | [diff] [blame] | 2398 | cmd->pd_r1_lb = io_info.pd_after_lb; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2399 | if (instance->is_ventura) |
| 2400 | io_request->RaidContext.raid_context_g35.span_arm |
| 2401 | = io_info.span_arm; |
| 2402 | else |
| 2403 | io_request->RaidContext.raid_context.span_arm |
| 2404 | = io_info.span_arm; |
| 2405 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2406 | } else |
| 2407 | scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 2408 | |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2409 | if (instance->is_ventura) |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2410 | cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2411 | else |
| 2412 | cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2413 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 2414 | if ((raidLUN[0] == 1) && |
sumit.saxena@avagotech.com | 75b96061e | 2015-08-31 17:24:01 +0530 | [diff] [blame] | 2415 | (local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) { |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 2416 | instance->dev_handle = !(instance->dev_handle); |
| 2417 | io_info.devHandle = |
| 2418 | local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].devHandle[instance->dev_handle]; |
| 2419 | } |
| 2420 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2421 | cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle; |
| 2422 | io_request->DevHandle = io_info.devHandle; |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 2423 | cmd->pd_interface = io_info.pd_interface; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2424 | /* populate the LUN field */ |
| 2425 | memcpy(io_request->LUN, raidLUN, 8); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2426 | } else { |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2427 | io_request->RaidContext.raid_context.timeout_value = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2428 | cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2429 | cmd->request_desc->SCSIIO.RequestFlags = |
| 2430 | (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO |
| 2431 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
sumit.saxena@avagotech.com | 5a8cb85 | 2015-10-15 13:39:34 +0530 | [diff] [blame] | 2432 | if (fusion->adapter_type == INVADER_SERIES) { |
Sumit Saxena | 8f05024 | 2016-01-28 21:04:27 +0530 | [diff] [blame] | 2433 | if (io_info.do_fp_rlbypass || |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2434 | (io_request->RaidContext.raid_context.reg_lock_flags |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2435 | == REGION_TYPE_UNUSED)) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2436 | cmd->request_desc->SCSIIO.RequestFlags = |
| 2437 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << |
| 2438 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2439 | io_request->RaidContext.raid_context.type |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2440 | = MPI2_TYPE_CUDA; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2441 | io_request->RaidContext.raid_context.reg_lock_flags |= |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2442 | (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 | |
| 2443 | MR_RL_FLAGS_SEQ_NUM_ENABLE); |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2444 | io_request->RaidContext.raid_context.nseg = 0x1; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2445 | } else if (instance->is_ventura) { |
| 2446 | io_request->RaidContext.raid_context_g35.type |
| 2447 | = MPI2_TYPE_CUDA; |
| 2448 | io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1; |
| 2449 | io_request->RaidContext.raid_context_g35.nseg = 0x1; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2450 | } |
| 2451 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2452 | io_request->DevHandle = cpu_to_le16(device_id); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2453 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2454 | } /* Not FP */ |
| 2455 | } |
| 2456 | |
| 2457 | /** |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2458 | * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2459 | * @instance: Adapter soft state |
| 2460 | * @scp: SCSI command |
| 2461 | * @cmd: Command to be prepared |
| 2462 | * |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2463 | * Prepares the io_request frame for non-rw io cmds for vd. |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2464 | */ |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2465 | static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, |
| 2466 | struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2467 | { |
| 2468 | u32 device_id; |
| 2469 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 2470 | u16 pd_index = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 2471 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2472 | struct fusion_context *fusion = instance->ctrl_context; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2473 | u8 span, physArm; |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 2474 | __le16 devHandle; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2475 | u32 ld, arRef, pd; |
| 2476 | struct MR_LD_RAID *raid; |
| 2477 | struct RAID_CONTEXT *pRAID_Context; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2478 | u8 fp_possible = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2479 | |
| 2480 | io_request = cmd->io_request; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2481 | device_id = MEGASAS_DEV_INDEX(scmd); |
| 2482 | pd_index = MEGASAS_PD_INDEX(scmd); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 2483 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2484 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2485 | /* get RAID_Context pointer */ |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2486 | pRAID_Context = &io_request->RaidContext.raid_context; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2487 | /* Check with FW team */ |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2488 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); |
| 2489 | pRAID_Context->reg_lock_row_lba = 0; |
| 2490 | pRAID_Context->reg_lock_length = 0; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2491 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2492 | if (fusion->fast_path_io && ( |
| 2493 | device_id < instance->fw_supported_vd_count)) { |
Sumit.Saxena@avagotech.com | ab2f060 | 2015-01-05 20:06:08 +0530 | [diff] [blame] | 2494 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2495 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Sumit.Saxena@avagotech.com | ab2f060 | 2015-01-05 20:06:08 +0530 | [diff] [blame] | 2496 | if (ld >= instance->fw_supported_vd_count) |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2497 | fp_possible = 0; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2498 | |
| 2499 | raid = MR_LdRaidGet(ld, local_map_ptr); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2500 | if (!(raid->capability.fpNonRWCapable)) |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2501 | fp_possible = 0; |
| 2502 | } else |
| 2503 | fp_possible = 0; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2504 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2505 | if (!fp_possible) { |
| 2506 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
| 2507 | io_request->DevHandle = cpu_to_le16(device_id); |
| 2508 | io_request->LUN[1] = scmd->device->lun; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2509 | pRAID_Context->timeout_value = |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2510 | cpu_to_le16 (scmd->request->timeout / HZ); |
| 2511 | cmd->request_desc->SCSIIO.RequestFlags = |
| 2512 | (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
| 2513 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 2514 | } else { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2515 | |
| 2516 | /* set RAID context values */ |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2517 | pRAID_Context->config_seq_num = raid->seqNum; |
| 2518 | if (!instance->is_ventura) |
| 2519 | pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ; |
| 2520 | pRAID_Context->timeout_value = |
| 2521 | cpu_to_le16(raid->fpIoTimeoutForLd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2522 | |
| 2523 | /* get the DevHandle for the PD (since this is |
| 2524 | fpNonRWCapable, this is a single disk RAID0) */ |
| 2525 | span = physArm = 0; |
| 2526 | arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr); |
| 2527 | pd = MR_ArPdGet(arRef, physArm, local_map_ptr); |
| 2528 | devHandle = MR_PdDevHandleGet(pd, local_map_ptr); |
| 2529 | |
| 2530 | /* build request descriptor */ |
| 2531 | cmd->request_desc->SCSIIO.RequestFlags = |
Sumit Saxena | 2c04835 | 2016-01-28 21:04:24 +0530 | [diff] [blame] | 2532 | (MPI2_REQ_DESCRIPT_FLAGS_FP_IO << |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2533 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2534 | cmd->request_desc->SCSIIO.DevHandle = devHandle; |
| 2535 | |
| 2536 | /* populate the LUN field */ |
| 2537 | memcpy(io_request->LUN, raid->LUN, 8); |
| 2538 | |
| 2539 | /* build the raidScsiIO structure */ |
| 2540 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 2541 | io_request->DevHandle = devHandle; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2542 | } |
| 2543 | } |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2544 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2545 | /** |
| 2546 | * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd |
| 2547 | * @instance: Adapter soft state |
| 2548 | * @scp: SCSI command |
| 2549 | * @cmd: Command to be prepared |
| 2550 | * @fp_possible: parameter to detect fast path or firmware path io. |
| 2551 | * |
| 2552 | * Prepares the io_request frame for rw/non-rw io cmds for syspds |
| 2553 | */ |
| 2554 | static void |
| 2555 | megasas_build_syspd_fusion(struct megasas_instance *instance, |
| 2556 | struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd, u8 fp_possible) |
| 2557 | { |
| 2558 | u32 device_id; |
| 2559 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 2560 | u16 pd_index = 0; |
| 2561 | u16 os_timeout_value; |
| 2562 | u16 timeout_limit; |
| 2563 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 2564 | struct RAID_CONTEXT *pRAID_Context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2565 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 2566 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2567 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2568 | pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id - 1) & 1]; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 2569 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2570 | device_id = MEGASAS_DEV_INDEX(scmd); |
| 2571 | pd_index = MEGASAS_PD_INDEX(scmd); |
| 2572 | os_timeout_value = scmd->request->timeout / HZ; |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 2573 | mr_device_priv_data = scmd->device->hostdata; |
| 2574 | cmd->pd_interface = mr_device_priv_data->interface_type; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2575 | |
| 2576 | io_request = cmd->io_request; |
| 2577 | /* get RAID_Context pointer */ |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2578 | pRAID_Context = &io_request->RaidContext.raid_context; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2579 | pRAID_Context->reg_lock_flags = 0; |
| 2580 | pRAID_Context->reg_lock_row_lba = 0; |
| 2581 | pRAID_Context->reg_lock_length = 0; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2582 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 2583 | io_request->LUN[1] = scmd->device->lun; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2584 | pRAID_Context->raid_flags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2585 | << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT; |
| 2586 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2587 | /* If FW supports PD sequence number */ |
| 2588 | if (instance->use_seqnum_jbod_fp && |
| 2589 | instance->pd_list[pd_index].driveType == TYPE_DISK) { |
| 2590 | /* TgtId must be incremented by 255 as jbod seq number is index |
| 2591 | * below raid map |
| 2592 | */ |
Sasikumar Chandrasekaran | ede7c3c | 2017-01-10 18:20:52 -0500 | [diff] [blame] | 2593 | /* More than 256 PD/JBOD support for Ventura */ |
| 2594 | if (instance->support_morethan256jbod) |
| 2595 | pRAID_Context->virtual_disk_tgt_id = |
| 2596 | pd_sync->seq[pd_index].pd_target_id; |
| 2597 | else |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2598 | pRAID_Context->virtual_disk_tgt_id = |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2599 | cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1)); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2600 | pRAID_Context->config_seq_num = pd_sync->seq[pd_index].seqNum; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2601 | io_request->DevHandle = pd_sync->seq[pd_index].devHandle; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2602 | if (instance->is_ventura) |
| 2603 | io_request->RaidContext.raid_context_g35.routing_flags.bits.sqn = 1; |
| 2604 | else |
| 2605 | pRAID_Context->reg_lock_flags |= |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2606 | (MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2607 | pRAID_Context->type = MPI2_TYPE_CUDA; |
Kashyap Desai | d557358 | 2016-10-21 06:33:35 -0700 | [diff] [blame] | 2608 | pRAID_Context->nseg = 0x1; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2609 | } else if (fusion->fast_path_io) { |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2610 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); |
| 2611 | pRAID_Context->config_seq_num = 0; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2612 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 2613 | io_request->DevHandle = |
| 2614 | local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl; |
| 2615 | } else { |
| 2616 | /* Want to send all IO via FW path */ |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2617 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); |
| 2618 | pRAID_Context->config_seq_num = 0; |
Sumit Saxena | 9fb74c4 | 2015-11-05 21:17:38 +0530 | [diff] [blame] | 2619 | io_request->DevHandle = cpu_to_le16(0xFFFF); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2620 | } |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2621 | |
| 2622 | cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle; |
| 2623 | cmd->request_desc->SCSIIO.MSIxIndex = |
| 2624 | instance->msix_vectors ? |
| 2625 | (raw_smp_processor_id() % instance->msix_vectors) : 0; |
| 2626 | |
| 2627 | |
| 2628 | if (!fp_possible) { |
| 2629 | /* system pd firmware path */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2630 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2631 | cmd->request_desc->SCSIIO.RequestFlags = |
| 2632 | (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2633 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2634 | pRAID_Context->timeout_value = cpu_to_le16(os_timeout_value); |
| 2635 | pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2636 | } else { |
| 2637 | /* system pd Fast Path */ |
| 2638 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2639 | timeout_limit = (scmd->device->type == TYPE_DISK) ? |
| 2640 | 255 : 0xFFFF; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2641 | pRAID_Context->timeout_value = |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2642 | cpu_to_le16((os_timeout_value > timeout_limit) ? |
| 2643 | timeout_limit : os_timeout_value); |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 2644 | if (fusion->adapter_type >= INVADER_SERIES) |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2645 | io_request->IoFlags |= |
| 2646 | cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); |
Kashyap Desai | d557358 | 2016-10-21 06:33:35 -0700 | [diff] [blame] | 2647 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2648 | cmd->request_desc->SCSIIO.RequestFlags = |
Sumit Saxena | 2c04835 | 2016-01-28 21:04:24 +0530 | [diff] [blame] | 2649 | (MPI2_REQ_DESCRIPT_FLAGS_FP_IO << |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2650 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2651 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | /** |
| 2655 | * megasas_build_io_fusion - Prepares IOs to devices |
| 2656 | * @instance: Adapter soft state |
| 2657 | * @scp: SCSI command |
| 2658 | * @cmd: Command to be prepared |
| 2659 | * |
| 2660 | * Invokes helper functions to prepare request frames |
| 2661 | * and sets flags appropriate for IO/Non-IO cmd |
| 2662 | */ |
| 2663 | int |
| 2664 | megasas_build_io_fusion(struct megasas_instance *instance, |
| 2665 | struct scsi_cmnd *scp, |
| 2666 | struct megasas_cmd_fusion *cmd) |
| 2667 | { |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 2668 | int sge_count; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2669 | u8 cmd_type; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2670 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request; |
| 2671 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2672 | /* Zero out some fields so they don't get reused */ |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2673 | memset(io_request->LUN, 0x0, 8); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2674 | io_request->CDB.EEDP32.PrimaryReferenceTag = 0; |
| 2675 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0; |
| 2676 | io_request->EEDPFlags = 0; |
| 2677 | io_request->Control = 0; |
| 2678 | io_request->EEDPBlockSize = 0; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2679 | io_request->ChainOffset = 0; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2680 | io_request->RaidContext.raid_context.raid_flags = 0; |
| 2681 | io_request->RaidContext.raid_context.type = 0; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 2682 | io_request->RaidContext.raid_context.nseg = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2683 | |
| 2684 | memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len); |
| 2685 | /* |
| 2686 | * Just the CDB length,rest of the Flags are zero |
| 2687 | * This will be modified for FP in build_ldio_fusion |
| 2688 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2689 | io_request->IoFlags = cpu_to_le16(scp->cmd_len); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2690 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2691 | switch (cmd_type = megasas_cmd_type(scp)) { |
| 2692 | case READ_WRITE_LDIO: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2693 | megasas_build_ldio_fusion(instance, scp, cmd); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 2694 | break; |
| 2695 | case NON_READ_WRITE_LDIO: |
| 2696 | megasas_build_ld_nonrw_fusion(instance, scp, cmd); |
| 2697 | break; |
| 2698 | case READ_WRITE_SYSPDIO: |
| 2699 | case NON_READ_WRITE_SYSPDIO: |
| 2700 | if (instance->secure_jbod_support && |
| 2701 | (cmd_type == NON_READ_WRITE_SYSPDIO)) |
| 2702 | megasas_build_syspd_fusion(instance, scp, cmd, 0); |
| 2703 | else |
| 2704 | megasas_build_syspd_fusion(instance, scp, cmd, 1); |
| 2705 | break; |
| 2706 | default: |
| 2707 | break; |
| 2708 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2709 | |
| 2710 | /* |
| 2711 | * Construct SGL |
| 2712 | */ |
| 2713 | |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 2714 | sge_count = megasas_make_sgl(instance, scp, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2715 | |
Shivasharan S | 33203bc | 2017-02-10 00:59:12 -0800 | [diff] [blame] | 2716 | if (sge_count > instance->max_num_sge || (sge_count < 0)) { |
| 2717 | dev_err(&instance->pdev->dev, |
| 2718 | "%s %d sge_count (%d) is out of range. Range is: 0-%d\n", |
| 2719 | __func__, __LINE__, sge_count, instance->max_num_sge); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2720 | return 1; |
| 2721 | } |
| 2722 | |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 2723 | if (instance->is_ventura) |
| 2724 | io_request->RaidContext.raid_context_g35.num_sge = sge_count; |
| 2725 | else { |
| 2726 | /* numSGE store lower 8 bit of sge_count. |
| 2727 | * numSGEExt store higher 8 bit of sge_count |
| 2728 | */ |
| 2729 | io_request->RaidContext.raid_context.num_sge = sge_count; |
| 2730 | io_request->RaidContext.raid_context.num_sge_ext = |
| 2731 | (u8)(sge_count >> 8); |
| 2732 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2733 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2734 | io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2735 | |
| 2736 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2737 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2738 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2739 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2740 | |
| 2741 | io_request->SGLOffset0 = |
| 2742 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4; |
| 2743 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2744 | io_request->SenseBufferLowAddress = cpu_to_le32(cmd->sense_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2745 | io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 2746 | |
| 2747 | cmd->scmd = scp; |
| 2748 | scp->SCp.ptr = (char *)cmd; |
| 2749 | |
| 2750 | return 0; |
| 2751 | } |
| 2752 | |
Shivasharan S | 52205ac | 2017-02-10 00:59:08 -0800 | [diff] [blame] | 2753 | static union MEGASAS_REQUEST_DESCRIPTOR_UNION * |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2754 | megasas_get_request_descriptor(struct megasas_instance *instance, u16 index) |
| 2755 | { |
| 2756 | u8 *p; |
| 2757 | struct fusion_context *fusion; |
| 2758 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2759 | fusion = instance->ctrl_context; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2760 | p = fusion->req_frames_desc + |
| 2761 | sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * index; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2762 | |
| 2763 | return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p; |
| 2764 | } |
| 2765 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2766 | |
| 2767 | /* megasas_prepate_secondRaid1_IO |
| 2768 | * It prepares the raid 1 second IO |
| 2769 | */ |
| 2770 | void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance, |
| 2771 | struct megasas_cmd_fusion *cmd, |
| 2772 | struct megasas_cmd_fusion *r1_cmd) |
| 2773 | { |
| 2774 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL; |
| 2775 | struct fusion_context *fusion; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2776 | fusion = instance->ctrl_context; |
| 2777 | req_desc = cmd->request_desc; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2778 | /* copy the io request frame as well as 8 SGEs data for r1 command*/ |
| 2779 | memcpy(r1_cmd->io_request, cmd->io_request, |
| 2780 | (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST))); |
| 2781 | memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL, |
| 2782 | (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION))); |
| 2783 | /*sense buffer is different for r1 command*/ |
| 2784 | r1_cmd->io_request->SenseBufferLowAddress = |
| 2785 | cpu_to_le32(r1_cmd->sense_phys_addr); |
| 2786 | r1_cmd->scmd = cmd->scmd; |
| 2787 | req_desc2 = megasas_get_request_descriptor(instance, |
| 2788 | (r1_cmd->index - 1)); |
| 2789 | req_desc2->Words = 0; |
| 2790 | r1_cmd->request_desc = req_desc2; |
| 2791 | req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index); |
| 2792 | req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags; |
| 2793 | r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle; |
| 2794 | r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle; |
| 2795 | r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle; |
| 2796 | cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid = |
| 2797 | cpu_to_le16(r1_cmd->index); |
| 2798 | r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid = |
| 2799 | cpu_to_le16(cmd->index); |
| 2800 | /*MSIxIndex of both commands request descriptors should be same*/ |
| 2801 | r1_cmd->request_desc->SCSIIO.MSIxIndex = |
| 2802 | cmd->request_desc->SCSIIO.MSIxIndex; |
| 2803 | /*span arm is different for r1 cmd*/ |
| 2804 | r1_cmd->io_request->RaidContext.raid_context_g35.span_arm = |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2805 | cmd->io_request->RaidContext.raid_context_g35.span_arm + 1; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2806 | } |
| 2807 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2808 | /** |
| 2809 | * megasas_build_and_issue_cmd_fusion -Main routine for building and |
| 2810 | * issuing non IOCTL cmd |
| 2811 | * @instance: Adapter soft state |
| 2812 | * @scmd: pointer to scsi cmd from OS |
| 2813 | */ |
| 2814 | static u32 |
| 2815 | megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, |
| 2816 | struct scsi_cmnd *scmd) |
| 2817 | { |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2818 | struct megasas_cmd_fusion *cmd, *r1_cmd = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2819 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2820 | u32 index; |
| 2821 | struct fusion_context *fusion; |
| 2822 | |
| 2823 | fusion = instance->ctrl_context; |
| 2824 | |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 2825 | if ((megasas_cmd_type(scmd) == READ_WRITE_LDIO) && |
| 2826 | instance->ldio_threshold && |
| 2827 | (atomic_inc_return(&instance->ldio_outstanding) > |
| 2828 | instance->ldio_threshold)) { |
| 2829 | atomic_dec(&instance->ldio_outstanding); |
| 2830 | return SCSI_MLQUEUE_DEVICE_BUSY; |
| 2831 | } |
| 2832 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2833 | if (atomic_inc_return(&instance->fw_outstanding) > |
| 2834 | instance->host->can_queue) { |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2835 | atomic_dec(&instance->fw_outstanding); |
| 2836 | return SCSI_MLQUEUE_HOST_BUSY; |
| 2837 | } |
| 2838 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2839 | cmd = megasas_get_cmd_fusion(instance, scmd->request->tag); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2840 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2841 | if (!cmd) { |
| 2842 | atomic_dec(&instance->fw_outstanding); |
| 2843 | return SCSI_MLQUEUE_HOST_BUSY; |
| 2844 | } |
| 2845 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2846 | index = cmd->index; |
| 2847 | |
| 2848 | req_desc = megasas_get_request_descriptor(instance, index-1); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2849 | |
| 2850 | req_desc->Words = 0; |
| 2851 | cmd->request_desc = req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2852 | |
| 2853 | if (megasas_build_io_fusion(instance, scmd, cmd)) { |
| 2854 | megasas_return_cmd_fusion(instance, cmd); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2855 | dev_err(&instance->pdev->dev, "Error building command\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2856 | cmd->request_desc = NULL; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2857 | atomic_dec(&instance->fw_outstanding); |
Sumit Saxena | f9a9dee | 2016-01-28 21:04:29 +0530 | [diff] [blame] | 2858 | return SCSI_MLQUEUE_HOST_BUSY; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | req_desc = cmd->request_desc; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2862 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2863 | |
| 2864 | if (cmd->io_request->ChainOffset != 0 && |
| 2865 | cmd->io_request->ChainOffset != 0xF) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2866 | dev_err(&instance->pdev->dev, "The chain offset value is not " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2867 | "correct : %x\n", cmd->io_request->ChainOffset); |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2868 | /* |
| 2869 | * if it is raid 1/10 fp write capable. |
| 2870 | * try to get second command from pool and construct it. |
| 2871 | * From FW, it has confirmed that lba values of two PDs |
| 2872 | * corresponds to single R1/10 LD are always same |
| 2873 | * |
| 2874 | */ |
| 2875 | /* driver side count always should be less than max_fw_cmds |
| 2876 | * to get new command |
| 2877 | */ |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2878 | if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) { |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2879 | r1_cmd = megasas_get_cmd_fusion(instance, |
| 2880 | (scmd->request->tag + instance->max_fw_cmds)); |
| 2881 | megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd); |
| 2882 | } |
| 2883 | |
Shivasharan S | 18bbcab | 2017-02-10 00:59:01 -0800 | [diff] [blame] | 2884 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2885 | /* |
| 2886 | * Issue the command to the FW |
| 2887 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2888 | |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 2889 | megasas_fire_cmd_fusion(instance, req_desc); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2890 | |
Shivasharan S | 18bbcab | 2017-02-10 00:59:01 -0800 | [diff] [blame] | 2891 | if (r1_cmd) |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 2892 | megasas_fire_cmd_fusion(instance, r1_cmd->request_desc); |
Shivasharan S | 18bbcab | 2017-02-10 00:59:01 -0800 | [diff] [blame] | 2893 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2894 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2895 | return 0; |
| 2896 | } |
| 2897 | |
| 2898 | /** |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2899 | * megasas_complete_r1_command - |
| 2900 | * completes R1 FP write commands which has valid peer smid |
| 2901 | * @instance: Adapter soft state |
| 2902 | * @cmd_fusion: MPT command frame |
| 2903 | * |
| 2904 | */ |
| 2905 | static inline void |
| 2906 | megasas_complete_r1_command(struct megasas_instance *instance, |
| 2907 | struct megasas_cmd_fusion *cmd) |
| 2908 | { |
| 2909 | u8 *sense, status, ex_status; |
| 2910 | u32 data_length; |
| 2911 | u16 peer_smid; |
| 2912 | struct fusion_context *fusion; |
| 2913 | struct megasas_cmd_fusion *r1_cmd = NULL; |
| 2914 | struct scsi_cmnd *scmd_local = NULL; |
| 2915 | struct RAID_CONTEXT_G35 *rctx_g35; |
| 2916 | |
| 2917 | rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35; |
| 2918 | fusion = instance->ctrl_context; |
| 2919 | peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid); |
| 2920 | |
| 2921 | r1_cmd = fusion->cmd_list[peer_smid - 1]; |
| 2922 | scmd_local = cmd->scmd; |
| 2923 | status = rctx_g35->status; |
| 2924 | ex_status = rctx_g35->ex_status; |
| 2925 | data_length = cmd->io_request->DataLength; |
| 2926 | sense = cmd->sense; |
| 2927 | |
| 2928 | cmd->cmd_completed = true; |
| 2929 | |
| 2930 | /* Check if peer command is completed or not*/ |
| 2931 | if (r1_cmd->cmd_completed) { |
| 2932 | rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35; |
| 2933 | if (rctx_g35->status != MFI_STAT_OK) { |
| 2934 | status = rctx_g35->status; |
| 2935 | ex_status = rctx_g35->ex_status; |
| 2936 | data_length = r1_cmd->io_request->DataLength; |
| 2937 | sense = r1_cmd->sense; |
| 2938 | } |
| 2939 | |
| 2940 | megasas_return_cmd_fusion(instance, r1_cmd); |
| 2941 | map_cmd_status(fusion, scmd_local, status, ex_status, |
| 2942 | le32_to_cpu(data_length), sense); |
| 2943 | if (instance->ldio_threshold && |
| 2944 | megasas_cmd_type(scmd_local) == READ_WRITE_LDIO) |
| 2945 | atomic_dec(&instance->ldio_outstanding); |
| 2946 | scmd_local->SCp.ptr = NULL; |
| 2947 | megasas_return_cmd_fusion(instance, cmd); |
| 2948 | scsi_dma_unmap(scmd_local); |
| 2949 | scmd_local->scsi_done(scmd_local); |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2954 | * complete_cmd_fusion - Completes command |
| 2955 | * @instance: Adapter soft state |
| 2956 | * Completes all commands that is in reply descriptor queue |
| 2957 | */ |
| 2958 | int |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2959 | complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2960 | { |
| 2961 | union MPI2_REPLY_DESCRIPTORS_UNION *desc; |
| 2962 | struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc; |
| 2963 | struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req; |
| 2964 | struct fusion_context *fusion; |
| 2965 | struct megasas_cmd *cmd_mfi; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2966 | struct megasas_cmd_fusion *cmd_fusion; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2967 | u16 smid, num_completed; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 2968 | u8 reply_descript_type, *sense, status, extStatus; |
| 2969 | u32 device_id, data_length; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2970 | union desc_value d_val; |
| 2971 | struct LD_LOAD_BALANCE_INFO *lbinfo; |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 2972 | int threshold_reply_count = 0; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2973 | struct scsi_cmnd *scmd_local = NULL; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 2974 | struct MR_TASK_MANAGE_REQUEST *mr_tm_req; |
| 2975 | struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_tm_req; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2976 | |
| 2977 | fusion = instance->ctrl_context; |
| 2978 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 2979 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2980 | return IRQ_HANDLED; |
| 2981 | |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 2982 | desc = fusion->reply_frames_desc[MSIxIndex] + |
| 2983 | fusion->last_reply_idx[MSIxIndex]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2984 | |
| 2985 | reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; |
| 2986 | |
| 2987 | d_val.word = desc->Words; |
| 2988 | |
| 2989 | reply_descript_type = reply_desc->ReplyFlags & |
| 2990 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 2991 | |
| 2992 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 2993 | return IRQ_NONE; |
| 2994 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2995 | num_completed = 0; |
| 2996 | |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 2997 | while (d_val.u.low != cpu_to_le32(UINT_MAX) && |
| 2998 | d_val.u.high != cpu_to_le32(UINT_MAX)) { |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 2999 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3000 | smid = le16_to_cpu(reply_desc->SMID); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3001 | cmd_fusion = fusion->cmd_list[smid - 1]; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3002 | scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *) |
| 3003 | cmd_fusion->io_request; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3004 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3005 | scmd_local = cmd_fusion->scmd; |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 3006 | status = scsi_io_req->RaidContext.raid_context.status; |
Sasikumar Chandrasekaran | d889344 | 2017-01-10 18:20:48 -0500 | [diff] [blame] | 3007 | extStatus = scsi_io_req->RaidContext.raid_context.ex_status; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 3008 | sense = cmd_fusion->sense; |
| 3009 | data_length = scsi_io_req->DataLength; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3010 | |
| 3011 | switch (scsi_io_req->Function) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3012 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 3013 | mr_tm_req = (struct MR_TASK_MANAGE_REQUEST *) |
| 3014 | cmd_fusion->io_request; |
| 3015 | mpi_tm_req = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) |
| 3016 | &mr_tm_req->TmRequest; |
| 3017 | dev_dbg(&instance->pdev->dev, "TM completion:" |
| 3018 | "type: 0x%x TaskMID: 0x%x\n", |
| 3019 | mpi_tm_req->TaskType, mpi_tm_req->TaskMID); |
| 3020 | complete(&cmd_fusion->done); |
| 3021 | break; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3022 | case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/ |
| 3023 | /* Update load balancing info */ |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3024 | if (fusion->load_balance_info && |
| 3025 | (cmd_fusion->scmd->SCp.Status & |
| 3026 | MEGASAS_LOAD_BALANCE_FLAG)) { |
| 3027 | device_id = MEGASAS_DEV_INDEX(scmd_local); |
| 3028 | lbinfo = &fusion->load_balance_info[device_id]; |
Sumit.Saxena@avagotech.com | d2552eb | 2014-09-12 18:57:53 +0530 | [diff] [blame] | 3029 | atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]); |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3030 | cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3031 | } |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3032 | //Fall thru and complete IO |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3033 | case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */ |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3034 | atomic_dec(&instance->fw_outstanding); |
| 3035 | if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) { |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 3036 | map_cmd_status(fusion, scmd_local, status, |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3037 | extStatus, le32_to_cpu(data_length), |
| 3038 | sense); |
| 3039 | if (instance->ldio_threshold && |
| 3040 | (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)) |
Sasikumar Chandrasekaran | b71b49c | 2017-01-10 18:20:51 -0500 | [diff] [blame] | 3041 | atomic_dec(&instance->ldio_outstanding); |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3042 | scmd_local->SCp.ptr = NULL; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 3043 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 3044 | scsi_dma_unmap(scmd_local); |
| 3045 | scmd_local->scsi_done(scmd_local); |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 3046 | } else /* Optimal VD - R1 FP command completion. */ |
| 3047 | megasas_complete_r1_command(instance, cmd_fusion); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3048 | break; |
| 3049 | case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */ |
| 3050 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3051 | /* Poll mode. Dummy free. |
| 3052 | * In case of Interrupt mode, caller has reverse check. |
| 3053 | */ |
| 3054 | if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) { |
| 3055 | cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE; |
| 3056 | megasas_return_cmd(instance, cmd_mfi); |
| 3057 | } else |
| 3058 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3059 | break; |
| 3060 | } |
| 3061 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3062 | fusion->last_reply_idx[MSIxIndex]++; |
| 3063 | if (fusion->last_reply_idx[MSIxIndex] >= |
| 3064 | fusion->reply_q_depth) |
| 3065 | fusion->last_reply_idx[MSIxIndex] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3066 | |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 3067 | desc->Words = cpu_to_le64(ULLONG_MAX); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3068 | num_completed++; |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 3069 | threshold_reply_count++; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3070 | |
| 3071 | /* Get the next reply descriptor */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3072 | if (!fusion->last_reply_idx[MSIxIndex]) |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 3073 | desc = fusion->reply_frames_desc[MSIxIndex]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3074 | else |
| 3075 | desc++; |
| 3076 | |
| 3077 | reply_desc = |
| 3078 | (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; |
| 3079 | |
| 3080 | d_val.word = desc->Words; |
| 3081 | |
| 3082 | reply_descript_type = reply_desc->ReplyFlags & |
| 3083 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 3084 | |
| 3085 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 3086 | break; |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 3087 | /* |
| 3088 | * Write to reply post host index register after completing threshold |
| 3089 | * number of reply counts and still there are more replies in reply queue |
| 3090 | * pending to be completed |
| 3091 | */ |
| 3092 | if (threshold_reply_count >= THRESHOLD_REPLY_COUNT) { |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 3093 | if (instance->msix_combined) |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 3094 | writel(((MSIxIndex & 0x7) << 24) | |
| 3095 | fusion->last_reply_idx[MSIxIndex], |
| 3096 | instance->reply_post_host_index_addr[MSIxIndex/8]); |
| 3097 | else |
| 3098 | writel((MSIxIndex << 24) | |
| 3099 | fusion->last_reply_idx[MSIxIndex], |
| 3100 | instance->reply_post_host_index_addr[0]); |
| 3101 | threshold_reply_count = 0; |
| 3102 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | if (!num_completed) |
| 3106 | return IRQ_NONE; |
| 3107 | |
| 3108 | wmb(); |
Sasikumar Chandrasekaran | 2493c67 | 2017-01-10 18:20:44 -0500 | [diff] [blame] | 3109 | if (instance->msix_combined) |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3110 | writel(((MSIxIndex & 0x7) << 24) | |
| 3111 | fusion->last_reply_idx[MSIxIndex], |
| 3112 | instance->reply_post_host_index_addr[MSIxIndex/8]); |
| 3113 | else |
| 3114 | writel((MSIxIndex << 24) | |
| 3115 | fusion->last_reply_idx[MSIxIndex], |
| 3116 | instance->reply_post_host_index_addr[0]); |
adam radford | 53ef2bb | 2011-02-24 20:56:05 -0800 | [diff] [blame] | 3117 | megasas_check_and_restore_queue_depth(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3118 | return IRQ_HANDLED; |
| 3119 | } |
| 3120 | |
| 3121 | /** |
| 3122 | * megasas_complete_cmd_dpc_fusion - Completes command |
| 3123 | * @instance: Adapter soft state |
| 3124 | * |
| 3125 | * Tasklet to complete cmds |
| 3126 | */ |
| 3127 | void |
| 3128 | megasas_complete_cmd_dpc_fusion(unsigned long instance_addr) |
| 3129 | { |
| 3130 | struct megasas_instance *instance = |
| 3131 | (struct megasas_instance *)instance_addr; |
| 3132 | unsigned long flags; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3133 | u32 count, MSIxIndex; |
| 3134 | |
| 3135 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3136 | |
| 3137 | /* If we have already declared adapter dead, donot complete cmds */ |
| 3138 | spin_lock_irqsave(&instance->hba_lock, flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3139 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3140 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3141 | return; |
| 3142 | } |
| 3143 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 3144 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3145 | for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++) |
| 3146 | complete_cmd_fusion(instance, MSIxIndex); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | /** |
| 3150 | * megasas_isr_fusion - isr entry point |
| 3151 | */ |
| 3152 | irqreturn_t megasas_isr_fusion(int irq, void *devp) |
| 3153 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3154 | struct megasas_irq_context *irq_context = devp; |
| 3155 | struct megasas_instance *instance = irq_context->instance; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3156 | u32 mfiStatus, fw_state, dma_state; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3157 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 3158 | if (instance->mask_interrupts) |
| 3159 | return IRQ_NONE; |
| 3160 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3161 | if (!instance->msix_vectors) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3162 | mfiStatus = instance->instancet->clear_intr(instance->reg_set); |
| 3163 | if (!mfiStatus) |
| 3164 | return IRQ_NONE; |
| 3165 | } |
| 3166 | |
| 3167 | /* If we are resetting, bail */ |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 3168 | if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) { |
| 3169 | instance->instancet->clear_intr(instance->reg_set); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3170 | return IRQ_HANDLED; |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 3171 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3172 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3173 | if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) { |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 3174 | instance->instancet->clear_intr(instance->reg_set); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3175 | /* If we didn't complete any commands, check for FW fault */ |
| 3176 | fw_state = instance->instancet->read_fw_status_reg( |
| 3177 | instance->reg_set) & MFI_STATE_MASK; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3178 | dma_state = instance->instancet->read_fw_status_reg |
| 3179 | (instance->reg_set) & MFI_STATE_DMADONE; |
| 3180 | if (instance->crash_dump_drv_support && |
| 3181 | instance->crash_dump_app_support) { |
| 3182 | /* Start collecting crash, if DMA bit is done */ |
| 3183 | if ((fw_state == MFI_STATE_FAULT) && dma_state) |
| 3184 | schedule_work(&instance->crash_init); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 3185 | else if (fw_state == MFI_STATE_FAULT) { |
| 3186 | if (instance->unload == 0) |
| 3187 | schedule_work(&instance->work_init); |
| 3188 | } |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3189 | } else if (fw_state == MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3190 | dev_warn(&instance->pdev->dev, "Iop2SysDoorbellInt" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3191 | "for scsi%d\n", instance->host->host_no); |
Kashyap Desai | a1dfd62 | 2016-10-21 06:33:31 -0700 | [diff] [blame] | 3192 | if (instance->unload == 0) |
| 3193 | schedule_work(&instance->work_init); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3194 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | return IRQ_HANDLED; |
| 3198 | } |
| 3199 | |
| 3200 | /** |
| 3201 | * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru |
| 3202 | * @instance: Adapter soft state |
| 3203 | * mfi_cmd: megasas_cmd pointer |
| 3204 | * |
| 3205 | */ |
| 3206 | u8 |
| 3207 | build_mpt_mfi_pass_thru(struct megasas_instance *instance, |
| 3208 | struct megasas_cmd *mfi_cmd) |
| 3209 | { |
| 3210 | struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain; |
| 3211 | struct MPI2_RAID_SCSI_IO_REQUEST *io_req; |
| 3212 | struct megasas_cmd_fusion *cmd; |
| 3213 | struct fusion_context *fusion; |
| 3214 | struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr; |
| 3215 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3216 | fusion = instance->ctrl_context; |
| 3217 | |
| 3218 | cmd = megasas_get_cmd_fusion(instance, |
| 3219 | instance->max_scsi_cmds + mfi_cmd->index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3220 | |
| 3221 | /* Save the smid. To be used for returning the cmd */ |
| 3222 | mfi_cmd->context.smid = cmd->index; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 3223 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3224 | /* |
| 3225 | * For cmds where the flag is set, store the flag and check |
| 3226 | * on completion. For cmds with this flag, don't call |
| 3227 | * megasas_complete_cmd |
| 3228 | */ |
| 3229 | |
Sumit.Saxena@avagotech.com | 6e755dd | 2014-11-17 15:24:28 +0530 | [diff] [blame] | 3230 | if (frame_hdr->flags & cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE)) |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 3231 | mfi_cmd->flags |= DRV_DCMD_POLLED_MODE; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3232 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3233 | io_req = cmd->io_request; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 3234 | |
Sasikumar Chandrasekaran | 9581ebe | 2017-01-10 18:20:49 -0500 | [diff] [blame] | 3235 | if (fusion->adapter_type >= INVADER_SERIES) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 3236 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = |
| 3237 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL; |
| 3238 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; |
| 3239 | sgl_ptr_end->Flags = 0; |
| 3240 | } |
| 3241 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3242 | mpi25_ieee_chain = |
| 3243 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain; |
| 3244 | |
| 3245 | io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST; |
| 3246 | io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, |
| 3247 | SGL) / 4; |
| 3248 | io_req->ChainOffset = fusion->chain_offset_mfi_pthru; |
| 3249 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3250 | mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3251 | |
| 3252 | mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 3253 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR; |
| 3254 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame] | 3255 | mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3256 | |
| 3257 | return 0; |
| 3258 | } |
| 3259 | |
| 3260 | /** |
| 3261 | * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd |
| 3262 | * @instance: Adapter soft state |
| 3263 | * @cmd: mfi cmd to build |
| 3264 | * |
| 3265 | */ |
| 3266 | union MEGASAS_REQUEST_DESCRIPTOR_UNION * |
| 3267 | build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 3268 | { |
Shivasharan S | 52205ac | 2017-02-10 00:59:08 -0800 | [diff] [blame] | 3269 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3270 | u16 index; |
| 3271 | |
| 3272 | if (build_mpt_mfi_pass_thru(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3273 | dev_err(&instance->pdev->dev, "Couldn't build MFI pass thru cmd\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3274 | return NULL; |
| 3275 | } |
| 3276 | |
| 3277 | index = cmd->context.smid; |
| 3278 | |
| 3279 | req_desc = megasas_get_request_descriptor(instance, index - 1); |
| 3280 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3281 | req_desc->Words = 0; |
| 3282 | req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
| 3283 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 3284 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 3285 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3286 | |
| 3287 | return req_desc; |
| 3288 | } |
| 3289 | |
| 3290 | /** |
| 3291 | * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd |
| 3292 | * @instance: Adapter soft state |
| 3293 | * @cmd: mfi cmd pointer |
| 3294 | * |
| 3295 | */ |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 3296 | void |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3297 | megasas_issue_dcmd_fusion(struct megasas_instance *instance, |
| 3298 | struct megasas_cmd *cmd) |
| 3299 | { |
| 3300 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3301 | |
| 3302 | req_desc = build_mpt_cmd(instance, cmd); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3303 | |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 3304 | megasas_fire_cmd_fusion(instance, req_desc); |
Shivasharan S | f4fc209 | 2017-02-10 00:59:09 -0800 | [diff] [blame] | 3305 | return; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | /** |
| 3309 | * megasas_release_fusion - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 3310 | * @instance: Adapter soft state |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3311 | */ |
| 3312 | void |
| 3313 | megasas_release_fusion(struct megasas_instance *instance) |
| 3314 | { |
| 3315 | megasas_free_cmds(instance); |
| 3316 | megasas_free_cmds_fusion(instance); |
| 3317 | |
| 3318 | iounmap(instance->reg_set); |
| 3319 | |
Yinghai Lu | e7f8516 | 2016-08-05 23:37:34 -0700 | [diff] [blame] | 3320 | pci_release_selected_regions(instance->pdev, 1<<instance->bar); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | /** |
| 3324 | * megasas_read_fw_status_reg_fusion - returns the current FW status value |
| 3325 | * @regs: MFI register set |
| 3326 | */ |
| 3327 | static u32 |
| 3328 | megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs) |
| 3329 | { |
| 3330 | return readl(&(regs)->outbound_scratch_pad); |
| 3331 | } |
| 3332 | |
| 3333 | /** |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3334 | * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware |
| 3335 | * @instance: Controller's soft instance |
| 3336 | * return: Number of allocated host crash buffers |
| 3337 | */ |
| 3338 | static void |
| 3339 | megasas_alloc_host_crash_buffer(struct megasas_instance *instance) |
| 3340 | { |
| 3341 | unsigned int i; |
| 3342 | |
| 3343 | instance->crash_buf_pages = get_order(CRASH_DMA_BUF_SIZE); |
| 3344 | for (i = 0; i < MAX_CRASH_DUMP_SIZE; i++) { |
| 3345 | instance->crash_buf[i] = (void *)__get_free_pages(GFP_KERNEL, |
| 3346 | instance->crash_buf_pages); |
| 3347 | if (!instance->crash_buf[i]) { |
| 3348 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 3349 | "memory allocation failed at index %d\n", i); |
| 3350 | break; |
| 3351 | } |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 3352 | memset(instance->crash_buf[i], 0, |
| 3353 | ((1 << PAGE_SHIFT) << instance->crash_buf_pages)); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3354 | } |
| 3355 | instance->drv_buf_alloc = i; |
| 3356 | } |
| 3357 | |
| 3358 | /** |
| 3359 | * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware |
| 3360 | * @instance: Controller's soft instance |
| 3361 | */ |
| 3362 | void |
| 3363 | megasas_free_host_crash_buffer(struct megasas_instance *instance) |
| 3364 | { |
| 3365 | unsigned int i |
| 3366 | ; |
| 3367 | for (i = 0; i < instance->drv_buf_alloc; i++) { |
| 3368 | if (instance->crash_buf[i]) |
| 3369 | free_pages((ulong)instance->crash_buf[i], |
| 3370 | instance->crash_buf_pages); |
| 3371 | } |
| 3372 | instance->drv_buf_index = 0; |
| 3373 | instance->drv_buf_alloc = 0; |
| 3374 | instance->fw_crash_state = UNAVAILABLE; |
| 3375 | instance->fw_crash_buffer_size = 0; |
| 3376 | } |
| 3377 | |
| 3378 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3379 | * megasas_adp_reset_fusion - For controller reset |
| 3380 | * @regs: MFI register set |
| 3381 | */ |
| 3382 | static int |
| 3383 | megasas_adp_reset_fusion(struct megasas_instance *instance, |
| 3384 | struct megasas_register_set __iomem *regs) |
| 3385 | { |
sumit.saxena@avagotech.com | 79b82c2 | 2015-08-31 17:23:41 +0530 | [diff] [blame] | 3386 | u32 host_diag, abs_state, retry; |
| 3387 | |
| 3388 | /* Now try to reset the chip */ |
| 3389 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); |
| 3390 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, &instance->reg_set->fusion_seq_offset); |
| 3391 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, &instance->reg_set->fusion_seq_offset); |
| 3392 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, &instance->reg_set->fusion_seq_offset); |
| 3393 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); |
| 3394 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); |
| 3395 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset); |
| 3396 | |
| 3397 | /* Check that the diag write enable (DRWE) bit is on */ |
| 3398 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
| 3399 | retry = 0; |
| 3400 | while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) { |
| 3401 | msleep(100); |
| 3402 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
| 3403 | if (retry++ == 100) { |
| 3404 | dev_warn(&instance->pdev->dev, |
| 3405 | "Host diag unlock failed from %s %d\n", |
| 3406 | __func__, __LINE__); |
| 3407 | break; |
| 3408 | } |
| 3409 | } |
| 3410 | if (!(host_diag & HOST_DIAG_WRITE_ENABLE)) |
| 3411 | return -1; |
| 3412 | |
| 3413 | /* Send chip reset command */ |
| 3414 | writel(host_diag | HOST_DIAG_RESET_ADAPTER, |
| 3415 | &instance->reg_set->fusion_host_diag); |
| 3416 | msleep(3000); |
| 3417 | |
| 3418 | /* Make sure reset adapter bit is cleared */ |
| 3419 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
| 3420 | retry = 0; |
| 3421 | while (host_diag & HOST_DIAG_RESET_ADAPTER) { |
| 3422 | msleep(100); |
| 3423 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
| 3424 | if (retry++ == 1000) { |
| 3425 | dev_warn(&instance->pdev->dev, |
| 3426 | "Diag reset adapter never cleared %s %d\n", |
| 3427 | __func__, __LINE__); |
| 3428 | break; |
| 3429 | } |
| 3430 | } |
| 3431 | if (host_diag & HOST_DIAG_RESET_ADAPTER) |
| 3432 | return -1; |
| 3433 | |
| 3434 | abs_state = instance->instancet->read_fw_status_reg(instance->reg_set) |
| 3435 | & MFI_STATE_MASK; |
| 3436 | retry = 0; |
| 3437 | |
| 3438 | while ((abs_state <= MFI_STATE_FW_INIT) && (retry++ < 1000)) { |
| 3439 | msleep(100); |
| 3440 | abs_state = instance->instancet-> |
| 3441 | read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK; |
| 3442 | } |
| 3443 | if (abs_state <= MFI_STATE_FW_INIT) { |
| 3444 | dev_warn(&instance->pdev->dev, |
| 3445 | "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n", |
| 3446 | abs_state, __func__, __LINE__); |
| 3447 | return -1; |
| 3448 | } |
| 3449 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3450 | return 0; |
| 3451 | } |
| 3452 | |
| 3453 | /** |
| 3454 | * megasas_check_reset_fusion - For controller reset check |
| 3455 | * @regs: MFI register set |
| 3456 | */ |
| 3457 | static int |
| 3458 | megasas_check_reset_fusion(struct megasas_instance *instance, |
| 3459 | struct megasas_register_set __iomem *regs) |
| 3460 | { |
| 3461 | return 0; |
| 3462 | } |
| 3463 | |
| 3464 | /* This function waits for outstanding commands on fusion to complete */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3465 | int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3466 | int reason, int *convert) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3467 | { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3468 | int i, outstanding, retval = 0, hb_seconds_missed = 0; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 3469 | u32 fw_state; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3470 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 3471 | for (i = 0; i < resetwaittime; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3472 | /* Check if firmware is in fault state */ |
| 3473 | fw_state = instance->instancet->read_fw_status_reg( |
| 3474 | instance->reg_set) & MFI_STATE_MASK; |
| 3475 | if (fw_state == MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3476 | dev_warn(&instance->pdev->dev, "Found FW in FAULT state," |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3477 | " will reset adapter scsi%d.\n", |
| 3478 | instance->host->host_no); |
Sumit Saxena | 64d0b8e | 2016-04-15 00:23:31 -0700 | [diff] [blame] | 3479 | megasas_complete_cmd_dpc_fusion((unsigned long)instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3480 | retval = 1; |
| 3481 | goto out; |
| 3482 | } |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3483 | |
| 3484 | if (reason == MFI_IO_TIMEOUT_OCR) { |
| 3485 | dev_info(&instance->pdev->dev, |
| 3486 | "MFI IO is timed out, initiating OCR\n"); |
Sumit Saxena | 64d0b8e | 2016-04-15 00:23:31 -0700 | [diff] [blame] | 3487 | megasas_complete_cmd_dpc_fusion((unsigned long)instance); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3488 | retval = 1; |
| 3489 | goto out; |
| 3490 | } |
| 3491 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3492 | /* If SR-IOV VF mode & heartbeat timeout, don't wait */ |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3493 | if (instance->requestorId && !reason) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3494 | retval = 1; |
| 3495 | goto out; |
| 3496 | } |
| 3497 | |
| 3498 | /* If SR-IOV VF mode & I/O timeout, check for HB timeout */ |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3499 | if (instance->requestorId && reason) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3500 | if (instance->hb_host_mem->HB.fwCounter != |
| 3501 | instance->hb_host_mem->HB.driverCounter) { |
| 3502 | instance->hb_host_mem->HB.driverCounter = |
| 3503 | instance->hb_host_mem->HB.fwCounter; |
| 3504 | hb_seconds_missed = 0; |
| 3505 | } else { |
| 3506 | hb_seconds_missed++; |
| 3507 | if (hb_seconds_missed == |
| 3508 | (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF/HZ)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3509 | dev_warn(&instance->pdev->dev, "SR-IOV:" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3510 | " Heartbeat never completed " |
| 3511 | " while polling during I/O " |
| 3512 | " timeout handling for " |
| 3513 | "scsi%d.\n", |
| 3514 | instance->host->host_no); |
| 3515 | *convert = 1; |
| 3516 | retval = 1; |
| 3517 | goto out; |
| 3518 | } |
| 3519 | } |
| 3520 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3521 | |
| 3522 | outstanding = atomic_read(&instance->fw_outstanding); |
| 3523 | if (!outstanding) |
| 3524 | goto out; |
| 3525 | |
| 3526 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3527 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3528 | "commands to complete for scsi%d\n", i, |
| 3529 | outstanding, instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3530 | megasas_complete_cmd_dpc_fusion( |
| 3531 | (unsigned long)instance); |
| 3532 | } |
| 3533 | msleep(1000); |
| 3534 | } |
| 3535 | |
| 3536 | if (atomic_read(&instance->fw_outstanding)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 3537 | dev_err(&instance->pdev->dev, "pending commands remain after waiting, " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3538 | "will reset adapter scsi%d.\n", |
| 3539 | instance->host->host_no); |
Kashyap Desai | 18e1c7f | 2016-10-21 06:33:29 -0700 | [diff] [blame] | 3540 | *convert = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3541 | retval = 1; |
| 3542 | } |
| 3543 | out: |
| 3544 | return retval; |
| 3545 | } |
| 3546 | |
| 3547 | void megasas_reset_reply_desc(struct megasas_instance *instance) |
| 3548 | { |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 3549 | int i, j, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3550 | struct fusion_context *fusion; |
| 3551 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; |
| 3552 | |
| 3553 | fusion = instance->ctrl_context; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3554 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 3555 | for (i = 0 ; i < count ; i++) { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 3556 | fusion->last_reply_idx[i] = 0; |
Sumit Saxena | 179ac14 | 2016-01-28 21:04:28 +0530 | [diff] [blame] | 3557 | reply_desc = fusion->reply_frames_desc[i]; |
| 3558 | for (j = 0 ; j < fusion->reply_q_depth; j++, reply_desc++) |
| 3559 | reply_desc->Words = cpu_to_le64(ULLONG_MAX); |
| 3560 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3561 | } |
| 3562 | |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 3563 | /* |
| 3564 | * megasas_refire_mgmt_cmd : Re-fire management commands |
| 3565 | * @instance: Controller's soft instance |
| 3566 | */ |
| 3567 | void megasas_refire_mgmt_cmd(struct megasas_instance *instance) |
| 3568 | { |
| 3569 | int j; |
| 3570 | struct megasas_cmd_fusion *cmd_fusion; |
| 3571 | struct fusion_context *fusion; |
| 3572 | struct megasas_cmd *cmd_mfi; |
| 3573 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 3574 | u16 smid; |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3575 | bool refire_cmd = 0; |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 3576 | |
| 3577 | fusion = instance->ctrl_context; |
| 3578 | |
| 3579 | /* Re-fire management commands. |
| 3580 | * Do not traverse complet MPT frame pool. Start from max_scsi_cmds. |
| 3581 | */ |
| 3582 | for (j = instance->max_scsi_cmds ; j < instance->max_fw_cmds; j++) { |
| 3583 | cmd_fusion = fusion->cmd_list[j]; |
| 3584 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 3585 | smid = le16_to_cpu(cmd_mfi->context.smid); |
| 3586 | |
| 3587 | if (!smid) |
| 3588 | continue; |
| 3589 | req_desc = megasas_get_request_descriptor |
| 3590 | (instance, smid - 1); |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3591 | refire_cmd = req_desc && ((cmd_mfi->frame->dcmd.opcode != |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 3592 | cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO)) && |
| 3593 | (cmd_mfi->frame->dcmd.opcode != |
Sumit Saxena | 6d40afb | 2016-01-28 21:04:23 +0530 | [diff] [blame] | 3594 | cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO))) |
| 3595 | && !(cmd_mfi->flags & DRV_DCMD_SKIP_REFIRE); |
| 3596 | if (refire_cmd) |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 3597 | megasas_fire_cmd_fusion(instance, req_desc); |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 3598 | else |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 3599 | megasas_return_cmd(instance, cmd_mfi); |
| 3600 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3601 | } |
| 3602 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3603 | /* |
| 3604 | * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device |
| 3605 | * @instance: per adapter struct |
| 3606 | * @channel: the channel assigned by the OS |
| 3607 | * @id: the id assigned by the OS |
| 3608 | * |
| 3609 | * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED |
| 3610 | */ |
| 3611 | |
| 3612 | static int megasas_track_scsiio(struct megasas_instance *instance, |
| 3613 | int id, int channel) |
| 3614 | { |
| 3615 | int i, found = 0; |
| 3616 | struct megasas_cmd_fusion *cmd_fusion; |
| 3617 | struct fusion_context *fusion; |
| 3618 | fusion = instance->ctrl_context; |
| 3619 | |
| 3620 | for (i = 0 ; i < instance->max_scsi_cmds; i++) { |
| 3621 | cmd_fusion = fusion->cmd_list[i]; |
| 3622 | if (cmd_fusion->scmd && |
| 3623 | (cmd_fusion->scmd->device->id == id && |
| 3624 | cmd_fusion->scmd->device->channel == channel)) { |
| 3625 | dev_info(&instance->pdev->dev, |
| 3626 | "SCSI commands pending to target" |
| 3627 | "channel %d id %d \tSMID: 0x%x\n", |
| 3628 | channel, id, cmd_fusion->index); |
| 3629 | scsi_print_command(cmd_fusion->scmd); |
| 3630 | found = 1; |
| 3631 | break; |
| 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | return found ? FAILED : SUCCESS; |
| 3636 | } |
| 3637 | |
| 3638 | /** |
| 3639 | * megasas_tm_response_code - translation of device response code |
| 3640 | * @ioc: per adapter object |
| 3641 | * @mpi_reply: MPI reply returned by firmware |
| 3642 | * |
| 3643 | * Return nothing. |
| 3644 | */ |
| 3645 | static void |
| 3646 | megasas_tm_response_code(struct megasas_instance *instance, |
| 3647 | struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply) |
| 3648 | { |
| 3649 | char *desc; |
| 3650 | |
| 3651 | switch (mpi_reply->ResponseCode) { |
| 3652 | case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE: |
| 3653 | desc = "task management request completed"; |
| 3654 | break; |
| 3655 | case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME: |
| 3656 | desc = "invalid frame"; |
| 3657 | break; |
| 3658 | case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED: |
| 3659 | desc = "task management request not supported"; |
| 3660 | break; |
| 3661 | case MPI2_SCSITASKMGMT_RSP_TM_FAILED: |
| 3662 | desc = "task management request failed"; |
| 3663 | break; |
| 3664 | case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED: |
| 3665 | desc = "task management request succeeded"; |
| 3666 | break; |
| 3667 | case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN: |
| 3668 | desc = "invalid lun"; |
| 3669 | break; |
| 3670 | case 0xA: |
| 3671 | desc = "overlapped tag attempted"; |
| 3672 | break; |
| 3673 | case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC: |
| 3674 | desc = "task queued, however not sent to target"; |
| 3675 | break; |
| 3676 | default: |
| 3677 | desc = "unknown"; |
| 3678 | break; |
| 3679 | } |
| 3680 | dev_dbg(&instance->pdev->dev, "response_code(%01x): %s\n", |
| 3681 | mpi_reply->ResponseCode, desc); |
| 3682 | dev_dbg(&instance->pdev->dev, |
| 3683 | "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo" |
| 3684 | " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n", |
| 3685 | mpi_reply->TerminationCount, mpi_reply->DevHandle, |
| 3686 | mpi_reply->Function, mpi_reply->TaskType, |
| 3687 | mpi_reply->IOCStatus, mpi_reply->IOCLogInfo); |
| 3688 | } |
| 3689 | |
| 3690 | /** |
| 3691 | * megasas_issue_tm - main routine for sending tm requests |
| 3692 | * @instance: per adapter struct |
| 3693 | * @device_handle: device handle |
| 3694 | * @channel: the channel assigned by the OS |
| 3695 | * @id: the id assigned by the OS |
| 3696 | * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c) |
| 3697 | * @smid_task: smid assigned to the task |
| 3698 | * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF |
| 3699 | * Context: user |
| 3700 | * |
| 3701 | * MegaRaid use MPT interface for Task Magement request. |
| 3702 | * A generic API for sending task management requests to firmware. |
| 3703 | * |
| 3704 | * Return SUCCESS or FAILED. |
| 3705 | */ |
| 3706 | static int |
| 3707 | megasas_issue_tm(struct megasas_instance *instance, u16 device_handle, |
| 3708 | uint channel, uint id, u16 smid_task, u8 type) |
| 3709 | { |
| 3710 | struct MR_TASK_MANAGE_REQUEST *mr_request; |
| 3711 | struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_request; |
| 3712 | unsigned long timeleft; |
| 3713 | struct megasas_cmd_fusion *cmd_fusion; |
| 3714 | struct megasas_cmd *cmd_mfi; |
| 3715 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 3716 | struct fusion_context *fusion; |
| 3717 | struct megasas_cmd_fusion *scsi_lookup; |
| 3718 | int rc; |
| 3719 | struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply; |
| 3720 | |
| 3721 | fusion = instance->ctrl_context; |
| 3722 | |
| 3723 | cmd_mfi = megasas_get_cmd(instance); |
| 3724 | |
| 3725 | if (!cmd_mfi) { |
| 3726 | dev_err(&instance->pdev->dev, "Failed from %s %d\n", |
| 3727 | __func__, __LINE__); |
| 3728 | return -ENOMEM; |
| 3729 | } |
| 3730 | |
| 3731 | cmd_fusion = megasas_get_cmd_fusion(instance, |
| 3732 | instance->max_scsi_cmds + cmd_mfi->index); |
| 3733 | |
| 3734 | /* Save the smid. To be used for returning the cmd */ |
| 3735 | cmd_mfi->context.smid = cmd_fusion->index; |
| 3736 | |
| 3737 | req_desc = megasas_get_request_descriptor(instance, |
| 3738 | (cmd_fusion->index - 1)); |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3739 | |
| 3740 | cmd_fusion->request_desc = req_desc; |
| 3741 | req_desc->Words = 0; |
| 3742 | |
| 3743 | scsi_lookup = fusion->cmd_list[smid_task - 1]; |
| 3744 | |
| 3745 | mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request; |
| 3746 | memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST)); |
| 3747 | mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) &mr_request->TmRequest; |
| 3748 | mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 3749 | mpi_request->DevHandle = cpu_to_le16(device_handle); |
| 3750 | mpi_request->TaskType = type; |
| 3751 | mpi_request->TaskMID = cpu_to_le16(smid_task); |
| 3752 | mpi_request->LUN[1] = 0; |
| 3753 | |
| 3754 | |
| 3755 | req_desc = cmd_fusion->request_desc; |
| 3756 | req_desc->HighPriority.SMID = cpu_to_le16(cmd_fusion->index); |
| 3757 | req_desc->HighPriority.RequestFlags = |
| 3758 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << |
| 3759 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 3760 | req_desc->HighPriority.MSIxIndex = 0; |
| 3761 | req_desc->HighPriority.LMID = 0; |
| 3762 | req_desc->HighPriority.Reserved1 = 0; |
| 3763 | |
| 3764 | if (channel < MEGASAS_MAX_PD_CHANNELS) |
| 3765 | mr_request->tmReqFlags.isTMForPD = 1; |
| 3766 | else |
| 3767 | mr_request->tmReqFlags.isTMForLD = 1; |
| 3768 | |
| 3769 | init_completion(&cmd_fusion->done); |
Shivasharan S | 45b8a35 | 2017-02-10 00:59:04 -0800 | [diff] [blame] | 3770 | megasas_fire_cmd_fusion(instance, req_desc); |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3771 | |
| 3772 | timeleft = wait_for_completion_timeout(&cmd_fusion->done, 50 * HZ); |
| 3773 | |
| 3774 | if (!timeleft) { |
| 3775 | dev_err(&instance->pdev->dev, |
| 3776 | "task mgmt type 0x%x timed out\n", type); |
| 3777 | cmd_mfi->flags |= DRV_DCMD_SKIP_REFIRE; |
| 3778 | mutex_unlock(&instance->reset_mutex); |
| 3779 | rc = megasas_reset_fusion(instance->host, MFI_IO_TIMEOUT_OCR); |
| 3780 | mutex_lock(&instance->reset_mutex); |
| 3781 | return rc; |
| 3782 | } |
| 3783 | |
| 3784 | mpi_reply = (struct MPI2_SCSI_TASK_MANAGE_REPLY *) &mr_request->TMReply; |
| 3785 | megasas_tm_response_code(instance, mpi_reply); |
| 3786 | |
| 3787 | megasas_return_cmd(instance, cmd_mfi); |
| 3788 | rc = SUCCESS; |
| 3789 | switch (type) { |
| 3790 | case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK: |
| 3791 | if (scsi_lookup->scmd == NULL) |
| 3792 | break; |
| 3793 | else { |
| 3794 | instance->instancet->disable_intr(instance); |
| 3795 | msleep(1000); |
| 3796 | megasas_complete_cmd_dpc_fusion |
| 3797 | ((unsigned long)instance); |
| 3798 | instance->instancet->enable_intr(instance); |
| 3799 | if (scsi_lookup->scmd == NULL) |
| 3800 | break; |
| 3801 | } |
| 3802 | rc = FAILED; |
| 3803 | break; |
| 3804 | |
| 3805 | case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET: |
| 3806 | if ((channel == 0xFFFFFFFF) && (id == 0xFFFFFFFF)) |
| 3807 | break; |
| 3808 | instance->instancet->disable_intr(instance); |
| 3809 | msleep(1000); |
| 3810 | megasas_complete_cmd_dpc_fusion |
| 3811 | ((unsigned long)instance); |
| 3812 | rc = megasas_track_scsiio(instance, id, channel); |
| 3813 | instance->instancet->enable_intr(instance); |
| 3814 | |
| 3815 | break; |
| 3816 | case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET: |
| 3817 | case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK: |
| 3818 | break; |
| 3819 | default: |
| 3820 | rc = FAILED; |
| 3821 | break; |
| 3822 | } |
| 3823 | |
| 3824 | return rc; |
| 3825 | |
| 3826 | } |
| 3827 | |
| 3828 | /* |
| 3829 | * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI |
| 3830 | * @instance: per adapter struct |
| 3831 | * |
| 3832 | * Return Non Zero index, if SMID found in outstanding commands |
| 3833 | */ |
| 3834 | static u16 megasas_fusion_smid_lookup(struct scsi_cmnd *scmd) |
| 3835 | { |
| 3836 | int i, ret = 0; |
| 3837 | struct megasas_instance *instance; |
| 3838 | struct megasas_cmd_fusion *cmd_fusion; |
| 3839 | struct fusion_context *fusion; |
| 3840 | |
| 3841 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 3842 | |
| 3843 | fusion = instance->ctrl_context; |
| 3844 | |
| 3845 | for (i = 0; i < instance->max_scsi_cmds; i++) { |
| 3846 | cmd_fusion = fusion->cmd_list[i]; |
| 3847 | if (cmd_fusion->scmd && (cmd_fusion->scmd == scmd)) { |
| 3848 | scmd_printk(KERN_NOTICE, scmd, "Abort request is for" |
| 3849 | " SMID: %d\n", cmd_fusion->index); |
| 3850 | ret = cmd_fusion->index; |
| 3851 | break; |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | return ret; |
| 3856 | } |
| 3857 | |
| 3858 | /* |
| 3859 | * megasas_get_tm_devhandle - Get devhandle for TM request |
| 3860 | * @sdev- OS provided scsi device |
| 3861 | * |
| 3862 | * Returns- devhandle/targetID of SCSI device |
| 3863 | */ |
| 3864 | static u16 megasas_get_tm_devhandle(struct scsi_device *sdev) |
| 3865 | { |
| 3866 | u16 pd_index = 0; |
| 3867 | u32 device_id; |
| 3868 | struct megasas_instance *instance; |
| 3869 | struct fusion_context *fusion; |
| 3870 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
| 3871 | u16 devhandle = (u16)ULONG_MAX; |
| 3872 | |
| 3873 | instance = (struct megasas_instance *)sdev->host->hostdata; |
| 3874 | fusion = instance->ctrl_context; |
| 3875 | |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 3876 | if (!MEGASAS_IS_LOGICAL(sdev)) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3877 | if (instance->use_seqnum_jbod_fp) { |
Shivasharan S | 3cabd16 | 2017-02-10 00:59:05 -0800 | [diff] [blame] | 3878 | pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 3879 | + sdev->id; |
| 3880 | pd_sync = (void *)fusion->pd_seq_sync |
| 3881 | [(instance->pd_seq_map_id - 1) & 1]; |
| 3882 | devhandle = pd_sync->seq[pd_index].devHandle; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3883 | } else |
| 3884 | sdev_printk(KERN_ERR, sdev, "Firmware expose tmCapable" |
| 3885 | " without JBOD MAP support from %s %d\n", __func__, __LINE__); |
| 3886 | } else { |
| 3887 | device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 3888 | + sdev->id; |
| 3889 | devhandle = device_id; |
| 3890 | } |
| 3891 | |
| 3892 | return devhandle; |
| 3893 | } |
| 3894 | |
| 3895 | /* |
| 3896 | * megasas_task_abort_fusion : SCSI task abort function for fusion adapters |
| 3897 | * @scmd : pointer to scsi command object |
| 3898 | * |
| 3899 | * Return SUCCESS, if command aborted else FAILED |
| 3900 | */ |
| 3901 | |
| 3902 | int megasas_task_abort_fusion(struct scsi_cmnd *scmd) |
| 3903 | { |
| 3904 | struct megasas_instance *instance; |
| 3905 | u16 smid, devhandle; |
| 3906 | struct fusion_context *fusion; |
| 3907 | int ret; |
| 3908 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 3909 | mr_device_priv_data = scmd->device->hostdata; |
| 3910 | |
| 3911 | |
| 3912 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 3913 | fusion = instance->ctrl_context; |
| 3914 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3915 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3916 | dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL," |
| 3917 | "SCSI host:%d\n", instance->host->host_no); |
| 3918 | ret = FAILED; |
| 3919 | return ret; |
| 3920 | } |
| 3921 | |
| 3922 | if (!mr_device_priv_data) { |
| 3923 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 3924 | "scmd(%p)\n", scmd); |
| 3925 | scmd->result = DID_NO_CONNECT << 16; |
| 3926 | ret = SUCCESS; |
| 3927 | goto out; |
| 3928 | } |
| 3929 | |
| 3930 | |
| 3931 | if (!mr_device_priv_data->is_tm_capable) { |
| 3932 | ret = FAILED; |
| 3933 | goto out; |
| 3934 | } |
| 3935 | |
| 3936 | mutex_lock(&instance->reset_mutex); |
| 3937 | |
| 3938 | smid = megasas_fusion_smid_lookup(scmd); |
| 3939 | |
| 3940 | if (!smid) { |
| 3941 | ret = SUCCESS; |
| 3942 | scmd_printk(KERN_NOTICE, scmd, "Command for which abort is" |
| 3943 | " issued is not found in oustanding commands\n"); |
| 3944 | mutex_unlock(&instance->reset_mutex); |
| 3945 | goto out; |
| 3946 | } |
| 3947 | |
| 3948 | devhandle = megasas_get_tm_devhandle(scmd->device); |
| 3949 | |
| 3950 | if (devhandle == (u16)ULONG_MAX) { |
| 3951 | ret = SUCCESS; |
| 3952 | sdev_printk(KERN_INFO, scmd->device, |
| 3953 | "task abort issued for invalid devhandle\n"); |
| 3954 | mutex_unlock(&instance->reset_mutex); |
| 3955 | goto out; |
| 3956 | } |
| 3957 | sdev_printk(KERN_INFO, scmd->device, |
| 3958 | "attempting task abort! scmd(%p) tm_dev_handle 0x%x\n", |
| 3959 | scmd, devhandle); |
| 3960 | |
| 3961 | mr_device_priv_data->tm_busy = 1; |
| 3962 | ret = megasas_issue_tm(instance, devhandle, |
| 3963 | scmd->device->channel, scmd->device->id, smid, |
| 3964 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK); |
| 3965 | mr_device_priv_data->tm_busy = 0; |
| 3966 | |
| 3967 | mutex_unlock(&instance->reset_mutex); |
| 3968 | out: |
| 3969 | sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n", |
| 3970 | ((ret == SUCCESS) ? "SUCCESS" : "FAILED"), scmd); |
| 3971 | |
| 3972 | return ret; |
| 3973 | } |
| 3974 | |
| 3975 | /* |
| 3976 | * megasas_reset_target_fusion : target reset function for fusion adapters |
| 3977 | * scmd: SCSI command pointer |
| 3978 | * |
| 3979 | * Returns SUCCESS if all commands associated with target aborted else FAILED |
| 3980 | */ |
| 3981 | |
| 3982 | int megasas_reset_target_fusion(struct scsi_cmnd *scmd) |
| 3983 | { |
| 3984 | |
| 3985 | struct megasas_instance *instance; |
| 3986 | int ret = FAILED; |
| 3987 | u16 devhandle; |
| 3988 | struct fusion_context *fusion; |
| 3989 | struct MR_PRIV_DEVICE *mr_device_priv_data; |
| 3990 | mr_device_priv_data = scmd->device->hostdata; |
| 3991 | |
| 3992 | instance = (struct megasas_instance *)scmd->device->host->hostdata; |
| 3993 | fusion = instance->ctrl_context; |
| 3994 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 3995 | if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) { |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 3996 | dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL," |
| 3997 | "SCSI host:%d\n", instance->host->host_no); |
| 3998 | ret = FAILED; |
| 3999 | return ret; |
| 4000 | } |
| 4001 | |
| 4002 | if (!mr_device_priv_data) { |
| 4003 | sdev_printk(KERN_INFO, scmd->device, "device been deleted! " |
| 4004 | "scmd(%p)\n", scmd); |
| 4005 | scmd->result = DID_NO_CONNECT << 16; |
| 4006 | ret = SUCCESS; |
| 4007 | goto out; |
| 4008 | } |
| 4009 | |
| 4010 | |
| 4011 | if (!mr_device_priv_data->is_tm_capable) { |
| 4012 | ret = FAILED; |
| 4013 | goto out; |
| 4014 | } |
| 4015 | |
| 4016 | mutex_lock(&instance->reset_mutex); |
| 4017 | devhandle = megasas_get_tm_devhandle(scmd->device); |
| 4018 | |
| 4019 | if (devhandle == (u16)ULONG_MAX) { |
| 4020 | ret = SUCCESS; |
| 4021 | sdev_printk(KERN_INFO, scmd->device, |
| 4022 | "target reset issued for invalid devhandle\n"); |
| 4023 | mutex_unlock(&instance->reset_mutex); |
| 4024 | goto out; |
| 4025 | } |
| 4026 | |
| 4027 | sdev_printk(KERN_INFO, scmd->device, |
| 4028 | "attempting target reset! scmd(%p) tm_dev_handle 0x%x\n", |
| 4029 | scmd, devhandle); |
| 4030 | mr_device_priv_data->tm_busy = 1; |
| 4031 | ret = megasas_issue_tm(instance, devhandle, |
| 4032 | scmd->device->channel, scmd->device->id, 0, |
| 4033 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET); |
| 4034 | mr_device_priv_data->tm_busy = 0; |
| 4035 | mutex_unlock(&instance->reset_mutex); |
| 4036 | out: |
| 4037 | scmd_printk(KERN_NOTICE, scmd, "megasas: target reset %s!!\n", |
| 4038 | (ret == SUCCESS) ? "SUCCESS" : "FAILED"); |
| 4039 | |
| 4040 | return ret; |
| 4041 | } |
| 4042 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 4043 | /*SRIOV get other instance in cluster if any*/ |
| 4044 | struct megasas_instance *megasas_get_peer_instance(struct megasas_instance *instance) |
| 4045 | { |
| 4046 | int i; |
| 4047 | |
| 4048 | for (i = 0; i < MAX_MGMT_ADAPTERS; i++) { |
| 4049 | if (megasas_mgmt_info.instance[i] && |
| 4050 | (megasas_mgmt_info.instance[i] != instance) && |
| 4051 | megasas_mgmt_info.instance[i]->requestorId && |
| 4052 | megasas_mgmt_info.instance[i]->peerIsPresent && |
| 4053 | (memcmp((megasas_mgmt_info.instance[i]->clusterId), |
| 4054 | instance->clusterId, MEGASAS_CLUSTER_ID_SIZE) == 0)) |
| 4055 | return megasas_mgmt_info.instance[i]; |
| 4056 | } |
| 4057 | return NULL; |
| 4058 | } |
| 4059 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4060 | /* Check for a second path that is currently UP */ |
| 4061 | int megasas_check_mpio_paths(struct megasas_instance *instance, |
| 4062 | struct scsi_cmnd *scmd) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4063 | { |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 4064 | struct megasas_instance *peer_instance = NULL; |
Shivasharan S | f55cf47 | 2017-02-10 00:59:07 -0800 | [diff] [blame] | 4065 | int retval = (DID_REQUEUE << 16); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4066 | |
Sumit Saxena | 8f67c8c | 2016-01-28 21:14:25 +0530 | [diff] [blame] | 4067 | if (instance->peerIsPresent) { |
| 4068 | peer_instance = megasas_get_peer_instance(instance); |
| 4069 | if ((peer_instance) && |
| 4070 | (atomic_read(&peer_instance->adprecovery) == |
| 4071 | MEGASAS_HBA_OPERATIONAL)) |
| 4072 | retval = (DID_NO_CONNECT << 16); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4073 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4074 | return retval; |
| 4075 | } |
| 4076 | |
| 4077 | /* Core fusion reset function */ |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4078 | int megasas_reset_fusion(struct Scsi_Host *shost, int reason) |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4079 | { |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 4080 | int retval = SUCCESS, i, j, convert = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4081 | struct megasas_instance *instance; |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 4082 | struct megasas_cmd_fusion *cmd_fusion, *r1_cmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4083 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | 79b82c2 | 2015-08-31 17:23:41 +0530 | [diff] [blame] | 4084 | u32 abs_state, status_reg, reset_adapter; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4085 | u32 io_timeout_in_crash_mode = 0; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4086 | struct scsi_cmnd *scmd_local = NULL; |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4087 | struct scsi_device *sdev; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4088 | |
| 4089 | instance = (struct megasas_instance *)shost->hostdata; |
| 4090 | fusion = instance->ctrl_context; |
| 4091 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4092 | mutex_lock(&instance->reset_mutex); |
| 4093 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4094 | if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4095 | dev_warn(&instance->pdev->dev, "Hardware critical error, " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4096 | "returning FAILED for scsi%d.\n", |
| 4097 | instance->host->host_no); |
Adam Radford | a2fbcbc | 2014-07-09 15:17:54 -0700 | [diff] [blame] | 4098 | mutex_unlock(&instance->reset_mutex); |
adam radford | d4a759a | 2011-10-08 18:14:39 -0700 | [diff] [blame] | 4099 | return FAILED; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4100 | } |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4101 | status_reg = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 4102 | abs_state = status_reg & MFI_STATE_MASK; |
| 4103 | |
| 4104 | /* IO timeout detected, forcibly put FW in FAULT state */ |
| 4105 | if (abs_state != MFI_STATE_FAULT && instance->crash_dump_buf && |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4106 | instance->crash_dump_app_support && reason) { |
| 4107 | dev_info(&instance->pdev->dev, "IO/DCMD timeout is detected, " |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4108 | "forcibly FAULT Firmware\n"); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4109 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4110 | status_reg = readl(&instance->reg_set->doorbell); |
| 4111 | writel(status_reg | MFI_STATE_FORCE_OCR, |
| 4112 | &instance->reg_set->doorbell); |
| 4113 | readl(&instance->reg_set->doorbell); |
| 4114 | mutex_unlock(&instance->reset_mutex); |
| 4115 | do { |
| 4116 | ssleep(3); |
| 4117 | io_timeout_in_crash_mode++; |
| 4118 | dev_dbg(&instance->pdev->dev, "waiting for [%d] " |
| 4119 | "seconds for crash dump collection and OCR " |
| 4120 | "to be done\n", (io_timeout_in_crash_mode * 3)); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4121 | } while ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) && |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4122 | (io_timeout_in_crash_mode < 80)); |
| 4123 | |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4124 | if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) { |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4125 | dev_info(&instance->pdev->dev, "OCR done for IO " |
| 4126 | "timeout case\n"); |
| 4127 | retval = SUCCESS; |
| 4128 | } else { |
| 4129 | dev_info(&instance->pdev->dev, "Controller is not " |
| 4130 | "operational after 240 seconds wait for IO " |
| 4131 | "timeout case in FW crash dump mode\n do " |
| 4132 | "OCR/kill adapter\n"); |
| 4133 | retval = megasas_reset_fusion(shost, 0); |
| 4134 | } |
| 4135 | return retval; |
| 4136 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4137 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4138 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 4139 | del_timer_sync(&instance->sriov_heartbeat_timer); |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 4140 | set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4141 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_POLLING); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4142 | instance->instancet->disable_intr(instance); |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 4143 | msleep(1000); |
| 4144 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4145 | /* First try waiting for commands to complete */ |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4146 | if (megasas_wait_for_outstanding_fusion(instance, reason, |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4147 | &convert)) { |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4148 | atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4149 | dev_warn(&instance->pdev->dev, "resetting fusion " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4150 | "adapter scsi%d.\n", instance->host->host_no); |
| 4151 | if (convert) |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4152 | reason = 0; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4153 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4154 | /* Now return commands back to the OS */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4155 | for (i = 0 ; i < instance->max_scsi_cmds; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4156 | cmd_fusion = fusion->cmd_list[i]; |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 4157 | /*check for extra commands issued by driver*/ |
| 4158 | if (instance->is_ventura) { |
Shivasharan S | 8bf7c65 | 2017-02-10 00:59:03 -0800 | [diff] [blame] | 4159 | r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds]; |
| 4160 | megasas_return_cmd_fusion(instance, r1_cmd); |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 4161 | } |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4162 | scmd_local = cmd_fusion->scmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4163 | if (cmd_fusion->scmd) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4164 | scmd_local->result = |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4165 | megasas_check_mpio_paths(instance, |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4166 | scmd_local); |
Sasikumar Chandrasekaran | b71b49c | 2017-01-10 18:20:51 -0500 | [diff] [blame] | 4167 | if (instance->ldio_threshold && |
| 4168 | megasas_cmd_type(scmd_local) == READ_WRITE_LDIO) |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 4169 | atomic_dec(&instance->ldio_outstanding); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4170 | megasas_return_cmd_fusion(instance, cmd_fusion); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 4171 | scsi_dma_unmap(scmd_local); |
| 4172 | scmd_local->scsi_done(scmd_local); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4173 | } |
| 4174 | } |
| 4175 | |
Sasikumar Chandrasekaran | 69c337c | 2017-01-10 18:20:47 -0500 | [diff] [blame] | 4176 | atomic_set(&instance->fw_outstanding, 0); |
| 4177 | |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 4178 | status_reg = instance->instancet->read_fw_status_reg( |
| 4179 | instance->reg_set); |
| 4180 | abs_state = status_reg & MFI_STATE_MASK; |
| 4181 | reset_adapter = status_reg & MFI_RESET_ADAPTER; |
| 4182 | if (instance->disableOnlineCtrlReset || |
| 4183 | (abs_state == MFI_STATE_FAULT && !reset_adapter)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4184 | /* Reset not supported, kill adapter */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4185 | dev_warn(&instance->pdev->dev, "Reset not supported" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4186 | ", killing adapter scsi%d.\n", |
| 4187 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4188 | megaraid_sas_kill_hba(instance); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4189 | instance->skip_heartbeat_timer_del = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4190 | retval = FAILED; |
| 4191 | goto out; |
| 4192 | } |
| 4193 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4194 | /* Let SR-IOV VF & PF sync up if there was a HB failure */ |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4195 | if (instance->requestorId && !reason) { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4196 | msleep(MEGASAS_OCR_SETTLE_TIME_VF); |
Sumit Saxena | 3885c26 | 2016-01-28 21:04:35 +0530 | [diff] [blame] | 4197 | goto transition_to_ready; |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4198 | } |
| 4199 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4200 | /* Now try to reset the chip */ |
| 4201 | for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4202 | |
sumit.saxena@avagotech.com | 79b82c2 | 2015-08-31 17:23:41 +0530 | [diff] [blame] | 4203 | if (instance->instancet->adp_reset |
| 4204 | (instance, instance->reg_set)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4205 | continue; |
Sumit Saxena | 3885c26 | 2016-01-28 21:04:35 +0530 | [diff] [blame] | 4206 | transition_to_ready: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4207 | /* Wait for FW to become ready */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 4208 | if (megasas_transition_to_ready(instance, 1)) { |
Sumit Saxena | 3885c26 | 2016-01-28 21:04:35 +0530 | [diff] [blame] | 4209 | dev_warn(&instance->pdev->dev, |
| 4210 | "Failed to transition controller to ready for " |
| 4211 | "scsi%d.\n", instance->host->host_no); |
| 4212 | if (instance->requestorId && !reason) |
| 4213 | goto fail_kill_adapter; |
| 4214 | else |
| 4215 | continue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4216 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4217 | megasas_reset_reply_desc(instance); |
Sumit Saxena | 308ec45 | 2016-01-28 21:04:30 +0530 | [diff] [blame] | 4218 | megasas_fusion_update_can_queue(instance, OCR_CONTEXT); |
| 4219 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4220 | if (megasas_ioc_init_fusion(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4221 | dev_warn(&instance->pdev->dev, |
Sumit Saxena | 3885c26 | 2016-01-28 21:04:35 +0530 | [diff] [blame] | 4222 | "megasas_ioc_init_fusion() failed! for " |
| 4223 | "scsi%d\n", instance->host->host_no); |
| 4224 | if (instance->requestorId && !reason) |
| 4225 | goto fail_kill_adapter; |
| 4226 | else |
| 4227 | continue; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4228 | } |
| 4229 | |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 4230 | megasas_refire_mgmt_cmd(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4231 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4232 | if (megasas_get_ctrl_info(instance)) { |
| 4233 | dev_info(&instance->pdev->dev, |
| 4234 | "Failed from %s %d\n", |
| 4235 | __func__, __LINE__); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 4236 | megaraid_sas_kill_hba(instance); |
| 4237 | retval = FAILED; |
| 4238 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4239 | /* Reset load balance info */ |
| 4240 | memset(fusion->load_balance_info, 0, |
| 4241 | sizeof(struct LD_LOAD_BALANCE_INFO) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 4242 | *MAX_LOGICAL_DRIVES_EXT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4243 | |
| 4244 | if (!megasas_get_map_info(instance)) |
| 4245 | megasas_sync_map_info(instance); |
| 4246 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 4247 | megasas_setup_jbod_map(instance); |
| 4248 | |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4249 | shost_for_each_device(sdev, shost) |
Shivasharan S | 15dd038 | 2017-02-10 00:59:10 -0800 | [diff] [blame] | 4250 | megasas_set_dynamic_target_properties(sdev); |
Sumit Saxena | 18365b1 | 2016-01-28 21:04:25 +0530 | [diff] [blame] | 4251 | |
Sasikumar Chandrasekaran | fdd84e2 | 2017-01-10 18:20:46 -0500 | [diff] [blame] | 4252 | /* reset stream detection array */ |
| 4253 | if (instance->is_ventura) { |
| 4254 | for (j = 0; j < MAX_LOGICAL_DRIVES_EXT; ++j) { |
| 4255 | memset(fusion->stream_detect_by_ld[j], |
| 4256 | 0, sizeof(struct LD_STREAM_DETECT)); |
| 4257 | fusion->stream_detect_by_ld[j]->mru_bit_map |
| 4258 | = MR_STREAM_BITMAP; |
| 4259 | } |
| 4260 | } |
| 4261 | |
Sumit.Saxena@avagotech.com | ac340c5 | 2014-11-17 15:24:18 +0530 | [diff] [blame] | 4262 | clear_bit(MEGASAS_FUSION_IN_RESET, |
| 4263 | &instance->reset_flags); |
| 4264 | instance->instancet->enable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4265 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
Sumit.Saxena@avagotech.com | ac340c5 | 2014-11-17 15:24:18 +0530 | [diff] [blame] | 4266 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4267 | /* Restart SR-IOV heartbeat */ |
| 4268 | if (instance->requestorId) { |
| 4269 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
| 4270 | megasas_start_timer(instance, |
| 4271 | &instance->sriov_heartbeat_timer, |
| 4272 | megasas_sriov_heartbeat_handler, |
| 4273 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 4274 | else |
| 4275 | instance->skip_heartbeat_timer_del = 1; |
| 4276 | } |
| 4277 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4278 | /* Adapter reset completed successfully */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4279 | dev_warn(&instance->pdev->dev, "Reset " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4280 | "successful for scsi%d.\n", |
| 4281 | instance->host->host_no); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4282 | |
Sumit.Saxena@avagotech.com | ac340c5 | 2014-11-17 15:24:18 +0530 | [diff] [blame] | 4283 | if (instance->crash_dump_drv_support && |
| 4284 | instance->crash_dump_app_support) |
| 4285 | megasas_set_crash_dump_params(instance, |
| 4286 | MR_CRASH_BUF_TURN_ON); |
| 4287 | else |
| 4288 | megasas_set_crash_dump_params(instance, |
| 4289 | MR_CRASH_BUF_TURN_OFF); |
| 4290 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4291 | retval = SUCCESS; |
| 4292 | goto out; |
| 4293 | } |
Sumit Saxena | 3885c26 | 2016-01-28 21:04:35 +0530 | [diff] [blame] | 4294 | fail_kill_adapter: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4295 | /* Reset failed, kill the adapter */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 4296 | dev_warn(&instance->pdev->dev, "Reset failed, killing " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4297 | "adapter scsi%d.\n", instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4298 | megaraid_sas_kill_hba(instance); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4299 | instance->skip_heartbeat_timer_del = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4300 | retval = FAILED; |
| 4301 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4302 | /* For VF: Restart HB timer if we didn't OCR */ |
| 4303 | if (instance->requestorId) { |
| 4304 | megasas_start_timer(instance, |
| 4305 | &instance->sriov_heartbeat_timer, |
| 4306 | megasas_sriov_heartbeat_handler, |
| 4307 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 4308 | } |
adam radford | 3f0e58bc | 2011-10-08 18:14:59 -0700 | [diff] [blame] | 4309 | clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 4310 | instance->instancet->enable_intr(instance); |
Sumit Saxena | 8a01a41 | 2016-01-28 21:04:32 +0530 | [diff] [blame] | 4311 | atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4312 | } |
| 4313 | out: |
| 4314 | clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
| 4315 | mutex_unlock(&instance->reset_mutex); |
| 4316 | return retval; |
| 4317 | } |
| 4318 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 4319 | /* Fusion Crash dump collection work queue */ |
| 4320 | void megasas_fusion_crash_dump_wq(struct work_struct *work) |
| 4321 | { |
| 4322 | struct megasas_instance *instance = |
| 4323 | container_of(work, struct megasas_instance, crash_init); |
| 4324 | u32 status_reg; |
| 4325 | u8 partial_copy = 0; |
| 4326 | |
| 4327 | |
| 4328 | status_reg = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 4329 | |
| 4330 | /* |
| 4331 | * Allocate host crash buffers to copy data from 1 MB DMA crash buffer |
| 4332 | * to host crash buffers |
| 4333 | */ |
| 4334 | if (instance->drv_buf_index == 0) { |
| 4335 | /* Buffer is already allocated for old Crash dump. |
| 4336 | * Do OCR and do not wait for crash dump collection |
| 4337 | */ |
| 4338 | if (instance->drv_buf_alloc) { |
| 4339 | dev_info(&instance->pdev->dev, "earlier crash dump is " |
| 4340 | "not yet copied by application, ignoring this " |
| 4341 | "crash dump and initiating OCR\n"); |
| 4342 | status_reg |= MFI_STATE_CRASH_DUMP_DONE; |
| 4343 | writel(status_reg, |
| 4344 | &instance->reg_set->outbound_scratch_pad); |
| 4345 | readl(&instance->reg_set->outbound_scratch_pad); |
| 4346 | return; |
| 4347 | } |
| 4348 | megasas_alloc_host_crash_buffer(instance); |
| 4349 | dev_info(&instance->pdev->dev, "Number of host crash buffers " |
| 4350 | "allocated: %d\n", instance->drv_buf_alloc); |
| 4351 | } |
| 4352 | |
| 4353 | /* |
| 4354 | * Driver has allocated max buffers, which can be allocated |
| 4355 | * and FW has more crash dump data, then driver will |
| 4356 | * ignore the data. |
| 4357 | */ |
| 4358 | if (instance->drv_buf_index >= (instance->drv_buf_alloc)) { |
| 4359 | dev_info(&instance->pdev->dev, "Driver is done copying " |
| 4360 | "the buffer: %d\n", instance->drv_buf_alloc); |
| 4361 | status_reg |= MFI_STATE_CRASH_DUMP_DONE; |
| 4362 | partial_copy = 1; |
| 4363 | } else { |
| 4364 | memcpy(instance->crash_buf[instance->drv_buf_index], |
| 4365 | instance->crash_dump_buf, CRASH_DMA_BUF_SIZE); |
| 4366 | instance->drv_buf_index++; |
| 4367 | status_reg &= ~MFI_STATE_DMADONE; |
| 4368 | } |
| 4369 | |
| 4370 | if (status_reg & MFI_STATE_CRASH_DUMP_DONE) { |
| 4371 | dev_info(&instance->pdev->dev, "Crash Dump is available,number " |
| 4372 | "of copied buffers: %d\n", instance->drv_buf_index); |
| 4373 | instance->fw_crash_buffer_size = instance->drv_buf_index; |
| 4374 | instance->fw_crash_state = AVAILABLE; |
| 4375 | instance->drv_buf_index = 0; |
| 4376 | writel(status_reg, &instance->reg_set->outbound_scratch_pad); |
| 4377 | readl(&instance->reg_set->outbound_scratch_pad); |
| 4378 | if (!partial_copy) |
| 4379 | megasas_reset_fusion(instance->host, 0); |
| 4380 | } else { |
| 4381 | writel(status_reg, &instance->reg_set->outbound_scratch_pad); |
| 4382 | readl(&instance->reg_set->outbound_scratch_pad); |
| 4383 | } |
| 4384 | } |
| 4385 | |
| 4386 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4387 | /* Fusion OCR work queue */ |
| 4388 | void megasas_fusion_ocr_wq(struct work_struct *work) |
| 4389 | { |
| 4390 | struct megasas_instance *instance = |
| 4391 | container_of(work, struct megasas_instance, work_init); |
| 4392 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 4393 | megasas_reset_fusion(instance->host, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | struct megasas_instance_template megasas_instance_template_fusion = { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 4397 | .enable_intr = megasas_enable_intr_fusion, |
| 4398 | .disable_intr = megasas_disable_intr_fusion, |
| 4399 | .clear_intr = megasas_clear_intr_fusion, |
| 4400 | .read_fw_status_reg = megasas_read_fw_status_reg_fusion, |
| 4401 | .adp_reset = megasas_adp_reset_fusion, |
| 4402 | .check_reset = megasas_check_reset_fusion, |
| 4403 | .service_isr = megasas_isr_fusion, |
| 4404 | .tasklet = megasas_complete_cmd_dpc_fusion, |
| 4405 | .init_adapter = megasas_init_adapter_fusion, |
| 4406 | .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion, |
| 4407 | .issue_dcmd = megasas_issue_dcmd_fusion, |
| 4408 | }; |