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; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 94 | extern int resetwaittime; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 95 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 96 | |
| 97 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 98 | /** |
| 99 | * megasas_enable_intr_fusion - Enables interrupts |
| 100 | * @regs: MFI register set |
| 101 | */ |
| 102 | void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 103 | megasas_enable_intr_fusion(struct megasas_instance *instance) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 104 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 105 | struct megasas_register_set __iomem *regs; |
| 106 | regs = instance->reg_set; |
Sumit.Saxena@avagotech.com | c2ced17 | 2015-01-05 20:06:13 +0530 | [diff] [blame] | 107 | |
| 108 | instance->mask_interrupts = 0; |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 109 | /* For Thunderbolt/Invader also clear intr on enable */ |
| 110 | writel(~0, ®s->outbound_intr_status); |
| 111 | readl(®s->outbound_intr_status); |
| 112 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 113 | writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 114 | |
| 115 | /* Dummy readl to force pci flush */ |
| 116 | readl(®s->outbound_intr_mask); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * megasas_disable_intr_fusion - Disables interrupt |
| 121 | * @regs: MFI register set |
| 122 | */ |
| 123 | void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 124 | megasas_disable_intr_fusion(struct megasas_instance *instance) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 125 | { |
| 126 | u32 mask = 0xFFFFFFFF; |
| 127 | u32 status; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 128 | struct megasas_register_set __iomem *regs; |
| 129 | regs = instance->reg_set; |
| 130 | instance->mask_interrupts = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 131 | |
| 132 | writel(mask, ®s->outbound_intr_mask); |
| 133 | /* Dummy readl to force pci flush */ |
| 134 | status = readl(®s->outbound_intr_mask); |
| 135 | } |
| 136 | |
| 137 | int |
| 138 | megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs) |
| 139 | { |
| 140 | u32 status; |
| 141 | /* |
| 142 | * Check if it is our interrupt |
| 143 | */ |
| 144 | status = readl(®s->outbound_intr_status); |
| 145 | |
| 146 | if (status & 1) { |
| 147 | writel(status, ®s->outbound_intr_status); |
| 148 | readl(®s->outbound_intr_status); |
| 149 | return 1; |
| 150 | } |
| 151 | if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK)) |
| 152 | return 0; |
| 153 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 154 | return 1; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * megasas_get_cmd_fusion - Get a command from the free pool |
| 159 | * @instance: Adapter soft state |
| 160 | * |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 161 | * Returns a blk_tag indexed mpt frame |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 162 | */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 163 | inline struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance |
| 164 | *instance, u32 blk_tag) |
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 | struct fusion_context *fusion; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 167 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 168 | fusion = instance->ctrl_context; |
| 169 | return fusion->cmd_list[blk_tag]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /** |
| 173 | * megasas_return_cmd_fusion - Return a cmd to free command pool |
| 174 | * @instance: Adapter soft state |
| 175 | * @cmd: Command packet to be returned to free command pool |
| 176 | */ |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 177 | inline void megasas_return_cmd_fusion(struct megasas_instance *instance, |
| 178 | struct megasas_cmd_fusion *cmd) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 179 | { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 180 | cmd->scmd = NULL; |
Sumit.Saxena@avagotech.com | 7497cde | 2015-01-05 20:06:03 +0530 | [diff] [blame] | 181 | memset(cmd->io_request, 0, sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)); |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /** |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 185 | * megasas_fire_cmd_fusion - Sends command to the FW |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 186 | */ |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 187 | static void |
| 188 | megasas_fire_cmd_fusion(struct megasas_instance *instance, |
| 189 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc) |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 190 | { |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 191 | #if defined(writeq) && defined(CONFIG_64BIT) |
| 192 | u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) | |
| 193 | le32_to_cpu(req_desc->u.low)); |
| 194 | |
| 195 | writeq(req_data, &instance->reg_set->inbound_low_queue_port); |
| 196 | #else |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 197 | unsigned long flags; |
| 198 | |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 199 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 200 | writel(le32_to_cpu(req_desc->u.low), |
| 201 | &instance->reg_set->inbound_low_queue_port); |
| 202 | writel(le32_to_cpu(req_desc->u.high), |
| 203 | &instance->reg_set->inbound_high_queue_port); |
| 204 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 205 | #endif |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 208 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 209 | /** |
| 210 | * megasas_teardown_frame_pool_fusion - Destroy the cmd frame DMA pool |
| 211 | * @instance: Adapter soft state |
| 212 | */ |
| 213 | static void megasas_teardown_frame_pool_fusion( |
| 214 | struct megasas_instance *instance) |
| 215 | { |
| 216 | int i; |
| 217 | struct fusion_context *fusion = instance->ctrl_context; |
| 218 | |
| 219 | u16 max_cmd = instance->max_fw_cmds; |
| 220 | |
| 221 | struct megasas_cmd_fusion *cmd; |
| 222 | |
| 223 | if (!fusion->sg_dma_pool || !fusion->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 224 | dev_err(&instance->pdev->dev, "dma pool is null. SG Pool %p, " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 225 | "sense pool : %p\n", fusion->sg_dma_pool, |
| 226 | fusion->sense_dma_pool); |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Return all frames to pool |
| 232 | */ |
| 233 | for (i = 0; i < max_cmd; i++) { |
| 234 | |
| 235 | cmd = fusion->cmd_list[i]; |
| 236 | |
| 237 | if (cmd->sg_frame) |
| 238 | pci_pool_free(fusion->sg_dma_pool, cmd->sg_frame, |
| 239 | cmd->sg_frame_phys_addr); |
| 240 | |
| 241 | if (cmd->sense) |
| 242 | pci_pool_free(fusion->sense_dma_pool, cmd->sense, |
| 243 | cmd->sense_phys_addr); |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * Now destroy the pool itself |
| 248 | */ |
| 249 | pci_pool_destroy(fusion->sg_dma_pool); |
| 250 | pci_pool_destroy(fusion->sense_dma_pool); |
| 251 | |
| 252 | fusion->sg_dma_pool = NULL; |
| 253 | fusion->sense_dma_pool = NULL; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool |
| 258 | * @instance: Adapter soft state |
| 259 | */ |
| 260 | void |
| 261 | megasas_free_cmds_fusion(struct megasas_instance *instance) |
| 262 | { |
| 263 | int i; |
| 264 | struct fusion_context *fusion = instance->ctrl_context; |
| 265 | |
| 266 | u32 max_cmds, req_sz, reply_sz, io_frames_sz; |
| 267 | |
| 268 | |
| 269 | req_sz = fusion->request_alloc_sz; |
| 270 | reply_sz = fusion->reply_alloc_sz; |
| 271 | io_frames_sz = fusion->io_frames_alloc_sz; |
| 272 | |
| 273 | max_cmds = instance->max_fw_cmds; |
| 274 | |
| 275 | /* Free descriptors and request Frames memory */ |
| 276 | if (fusion->req_frames_desc) |
| 277 | dma_free_coherent(&instance->pdev->dev, req_sz, |
| 278 | fusion->req_frames_desc, |
| 279 | fusion->req_frames_desc_phys); |
| 280 | |
| 281 | if (fusion->reply_frames_desc) { |
| 282 | pci_pool_free(fusion->reply_frames_desc_pool, |
| 283 | fusion->reply_frames_desc, |
| 284 | fusion->reply_frames_desc_phys); |
| 285 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 286 | } |
| 287 | |
| 288 | if (fusion->io_request_frames) { |
| 289 | pci_pool_free(fusion->io_request_frames_pool, |
| 290 | fusion->io_request_frames, |
| 291 | fusion->io_request_frames_phys); |
| 292 | pci_pool_destroy(fusion->io_request_frames_pool); |
| 293 | } |
| 294 | |
| 295 | /* Free the Fusion frame pool */ |
| 296 | megasas_teardown_frame_pool_fusion(instance); |
| 297 | |
| 298 | /* Free all the commands in the cmd_list */ |
| 299 | for (i = 0; i < max_cmds; i++) |
| 300 | kfree(fusion->cmd_list[i]); |
| 301 | |
| 302 | /* Free the cmd_list buffer itself */ |
| 303 | kfree(fusion->cmd_list); |
| 304 | fusion->cmd_list = NULL; |
| 305 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /** |
| 309 | * megasas_create_frame_pool_fusion - Creates DMA pool for cmd frames |
| 310 | * @instance: Adapter soft state |
| 311 | * |
| 312 | */ |
| 313 | static int megasas_create_frame_pool_fusion(struct megasas_instance *instance) |
| 314 | { |
| 315 | int i; |
| 316 | u32 max_cmd; |
| 317 | struct fusion_context *fusion; |
| 318 | struct megasas_cmd_fusion *cmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 319 | |
| 320 | fusion = instance->ctrl_context; |
| 321 | max_cmd = instance->max_fw_cmds; |
| 322 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * Use DMA pool facility provided by PCI layer |
| 326 | */ |
| 327 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 328 | fusion->sg_dma_pool = pci_pool_create("sg_pool_fusion", instance->pdev, |
| 329 | instance->max_chain_frame_sz, |
| 330 | 4, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 331 | if (!fusion->sg_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 332 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup request pool fusion\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 333 | return -ENOMEM; |
| 334 | } |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 335 | fusion->sense_dma_pool = pci_pool_create("sense pool fusion", |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 336 | instance->pdev, |
| 337 | SCSI_SENSE_BUFFERSIZE, 64, 0); |
| 338 | |
| 339 | if (!fusion->sense_dma_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 340 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "failed to setup sense pool fusion\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 341 | pci_pool_destroy(fusion->sg_dma_pool); |
| 342 | fusion->sg_dma_pool = NULL; |
| 343 | return -ENOMEM; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Allocate and attach a frame to each of the commands in cmd_list |
| 348 | */ |
| 349 | for (i = 0; i < max_cmd; i++) { |
| 350 | |
| 351 | cmd = fusion->cmd_list[i]; |
| 352 | |
| 353 | cmd->sg_frame = pci_pool_alloc(fusion->sg_dma_pool, |
| 354 | GFP_KERNEL, |
| 355 | &cmd->sg_frame_phys_addr); |
| 356 | |
| 357 | cmd->sense = pci_pool_alloc(fusion->sense_dma_pool, |
| 358 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 359 | /* |
| 360 | * megasas_teardown_frame_pool_fusion() takes care of freeing |
| 361 | * whatever has been allocated |
| 362 | */ |
| 363 | if (!cmd->sg_frame || !cmd->sense) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 364 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "pci_pool_alloc failed\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 365 | megasas_teardown_frame_pool_fusion(instance); |
| 366 | return -ENOMEM; |
| 367 | } |
| 368 | } |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * megasas_alloc_cmds_fusion - Allocates the command packets |
| 374 | * @instance: Adapter soft state |
| 375 | * |
| 376 | * |
| 377 | * Each frame has a 32-bit field called context. This context is used to get |
| 378 | * back the megasas_cmd_fusion from the frame when a frame gets completed |
| 379 | * In this driver, the 32 bit values are the indices into an array cmd_list. |
| 380 | * This array is used only to look up the megasas_cmd_fusion given the context. |
| 381 | * The free commands themselves are maintained in a linked list called cmd_pool. |
| 382 | * |
| 383 | * cmds are formed in the io_request and sg_frame members of the |
| 384 | * megasas_cmd_fusion. The context field is used to get a request descriptor |
| 385 | * and is used as SMID of the cmd. |
| 386 | * SMID value range is from 1 to max_fw_cmds. |
| 387 | */ |
| 388 | int |
| 389 | megasas_alloc_cmds_fusion(struct megasas_instance *instance) |
| 390 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 391 | int i, j, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 392 | u32 max_cmd, io_frames_sz; |
| 393 | struct fusion_context *fusion; |
| 394 | struct megasas_cmd_fusion *cmd; |
| 395 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; |
| 396 | u32 offset; |
| 397 | dma_addr_t io_req_base_phys; |
| 398 | u8 *io_req_base; |
| 399 | |
| 400 | fusion = instance->ctrl_context; |
| 401 | |
| 402 | max_cmd = instance->max_fw_cmds; |
| 403 | |
| 404 | fusion->req_frames_desc = |
| 405 | dma_alloc_coherent(&instance->pdev->dev, |
| 406 | fusion->request_alloc_sz, |
| 407 | &fusion->req_frames_desc_phys, GFP_KERNEL); |
| 408 | |
| 409 | if (!fusion->req_frames_desc) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 410 | dev_err(&instance->pdev->dev, "Could not allocate memory for " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 411 | "request_frames\n"); |
| 412 | goto fail_req_desc; |
| 413 | } |
| 414 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 415 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 416 | fusion->reply_frames_desc_pool = |
| 417 | pci_pool_create("reply_frames pool", instance->pdev, |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 418 | fusion->reply_alloc_sz * count, 16, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 419 | |
| 420 | if (!fusion->reply_frames_desc_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 421 | dev_err(&instance->pdev->dev, "Could not allocate memory for " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 422 | "reply_frame pool\n"); |
| 423 | goto fail_reply_desc; |
| 424 | } |
| 425 | |
| 426 | fusion->reply_frames_desc = |
| 427 | pci_pool_alloc(fusion->reply_frames_desc_pool, GFP_KERNEL, |
| 428 | &fusion->reply_frames_desc_phys); |
| 429 | if (!fusion->reply_frames_desc) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 430 | dev_err(&instance->pdev->dev, "Could not allocate memory for " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 431 | "reply_frame pool\n"); |
| 432 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 433 | goto fail_reply_desc; |
| 434 | } |
| 435 | |
| 436 | reply_desc = fusion->reply_frames_desc; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 437 | for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 438 | reply_desc->Words = cpu_to_le64(ULLONG_MAX); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 439 | |
| 440 | io_frames_sz = fusion->io_frames_alloc_sz; |
| 441 | |
| 442 | fusion->io_request_frames_pool = |
| 443 | pci_pool_create("io_request_frames pool", instance->pdev, |
| 444 | fusion->io_frames_alloc_sz, 16, 0); |
| 445 | |
| 446 | if (!fusion->io_request_frames_pool) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 447 | dev_err(&instance->pdev->dev, "Could not allocate memory for " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 448 | "io_request_frame pool\n"); |
| 449 | goto fail_io_frames; |
| 450 | } |
| 451 | |
| 452 | fusion->io_request_frames = |
| 453 | pci_pool_alloc(fusion->io_request_frames_pool, GFP_KERNEL, |
| 454 | &fusion->io_request_frames_phys); |
| 455 | if (!fusion->io_request_frames) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 456 | dev_err(&instance->pdev->dev, "Could not allocate memory for " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 457 | "io_request_frames frames\n"); |
| 458 | pci_pool_destroy(fusion->io_request_frames_pool); |
| 459 | goto fail_io_frames; |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers. |
| 464 | * Allocate the dynamic array first and then allocate individual |
| 465 | * commands. |
| 466 | */ |
Fengguang Wu | 7731e6b | 2012-08-24 23:27:35 +0800 | [diff] [blame] | 467 | fusion->cmd_list = kzalloc(sizeof(struct megasas_cmd_fusion *) |
| 468 | * max_cmd, GFP_KERNEL); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 469 | |
| 470 | if (!fusion->cmd_list) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 471 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "out of memory. Could not alloc " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 472 | "memory for cmd_list_fusion\n"); |
| 473 | goto fail_cmd_list; |
| 474 | } |
| 475 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 476 | max_cmd = instance->max_fw_cmds; |
| 477 | for (i = 0; i < max_cmd; i++) { |
| 478 | fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion), |
| 479 | GFP_KERNEL); |
| 480 | if (!fusion->cmd_list[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 481 | dev_err(&instance->pdev->dev, "Could not alloc cmd list fusion\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 482 | |
| 483 | for (j = 0; j < i; j++) |
| 484 | kfree(fusion->cmd_list[j]); |
| 485 | |
| 486 | kfree(fusion->cmd_list); |
| 487 | fusion->cmd_list = NULL; |
| 488 | goto fail_cmd_list; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /* The first 256 bytes (SMID 0) is not used. Don't add to cmd list */ |
| 493 | io_req_base = fusion->io_request_frames + |
| 494 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; |
| 495 | io_req_base_phys = fusion->io_request_frames_phys + |
| 496 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; |
| 497 | |
| 498 | /* |
| 499 | * Add all the commands to command pool (fusion->cmd_pool) |
| 500 | */ |
| 501 | |
| 502 | /* SMID 0 is reserved. Set SMID/index from 1 */ |
| 503 | for (i = 0; i < max_cmd; i++) { |
| 504 | cmd = fusion->cmd_list[i]; |
| 505 | offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i; |
| 506 | memset(cmd, 0, sizeof(struct megasas_cmd_fusion)); |
| 507 | cmd->index = i + 1; |
| 508 | cmd->scmd = NULL; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 509 | cmd->sync_cmd_idx = (i >= instance->max_scsi_cmds) ? |
| 510 | (i - instance->max_scsi_cmds) : |
| 511 | (u32)ULONG_MAX; /* Set to Invalid */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 512 | cmd->instance = instance; |
| 513 | cmd->io_request = |
| 514 | (struct MPI2_RAID_SCSI_IO_REQUEST *) |
| 515 | (io_req_base + offset); |
| 516 | memset(cmd->io_request, 0, |
| 517 | sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)); |
| 518 | cmd->io_request_phys_addr = io_req_base_phys + offset; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | /* |
| 522 | * Create a frame pool and assign one frame to each cmd |
| 523 | */ |
| 524 | if (megasas_create_frame_pool_fusion(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 525 | dev_printk(KERN_DEBUG, &instance->pdev->dev, "Error creating frame DMA pool\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 526 | megasas_free_cmds_fusion(instance); |
| 527 | goto fail_req_desc; |
| 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | |
| 532 | fail_cmd_list: |
| 533 | pci_pool_free(fusion->io_request_frames_pool, fusion->io_request_frames, |
| 534 | fusion->io_request_frames_phys); |
| 535 | pci_pool_destroy(fusion->io_request_frames_pool); |
| 536 | fail_io_frames: |
| 537 | dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz, |
| 538 | fusion->reply_frames_desc, |
| 539 | fusion->reply_frames_desc_phys); |
| 540 | pci_pool_free(fusion->reply_frames_desc_pool, |
| 541 | fusion->reply_frames_desc, |
| 542 | fusion->reply_frames_desc_phys); |
| 543 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 544 | |
| 545 | fail_reply_desc: |
| 546 | dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz, |
| 547 | fusion->req_frames_desc, |
| 548 | fusion->req_frames_desc_phys); |
| 549 | fail_req_desc: |
| 550 | return -ENOMEM; |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * wait_and_poll - Issues a polling command |
| 555 | * @instance: Adapter soft state |
| 556 | * @cmd: Command packet to be issued |
| 557 | * |
| 558 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. |
| 559 | */ |
| 560 | int |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 561 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd, |
| 562 | int seconds) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 563 | { |
| 564 | int i; |
| 565 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 566 | struct fusion_context *fusion; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 567 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 568 | u32 msecs = seconds * 1000; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 569 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 570 | fusion = instance->ctrl_context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 571 | /* |
| 572 | * Wait for cmd_status to change |
| 573 | */ |
| 574 | for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) { |
| 575 | rmb(); |
| 576 | msleep(20); |
| 577 | } |
| 578 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 579 | if (frame_hdr->cmd_status == 0xff) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 580 | return -ETIME; |
| 581 | |
Sumit.Saxena@avagotech.com | 2be2a98 | 2015-05-06 19:01:02 +0530 | [diff] [blame] | 582 | return (frame_hdr->cmd_status == MFI_STAT_OK) ? |
| 583 | 0 : 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /** |
| 587 | * megasas_ioc_init_fusion - Initializes the FW |
| 588 | * @instance: Adapter soft state |
| 589 | * |
| 590 | * Issues the IOC Init cmd |
| 591 | */ |
| 592 | int |
| 593 | megasas_ioc_init_fusion(struct megasas_instance *instance) |
| 594 | { |
| 595 | struct megasas_init_frame *init_frame; |
| 596 | struct MPI2_IOC_INIT_REQUEST *IOCInitMessage; |
| 597 | dma_addr_t ioc_init_handle; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 598 | struct megasas_cmd *cmd; |
| 599 | u8 ret; |
| 600 | struct fusion_context *fusion; |
adam radford | c77a9bd | 2014-03-10 02:51:36 -0700 | [diff] [blame] | 601 | union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 602 | int i; |
| 603 | struct megasas_header *frame_hdr; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 604 | const char *sys_info; |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 605 | MFI_CAPABILITIES *drv_ops; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 606 | |
| 607 | fusion = instance->ctrl_context; |
| 608 | |
| 609 | cmd = megasas_get_cmd(instance); |
| 610 | |
| 611 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 612 | 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] | 613 | ret = 1; |
| 614 | goto fail_get_cmd; |
| 615 | } |
| 616 | |
| 617 | IOCInitMessage = |
| 618 | dma_alloc_coherent(&instance->pdev->dev, |
| 619 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 620 | &ioc_init_handle, GFP_KERNEL); |
| 621 | |
| 622 | if (!IOCInitMessage) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 623 | dev_err(&instance->pdev->dev, "Could not allocate memory for " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 624 | "IOCInitMessage\n"); |
| 625 | ret = 1; |
| 626 | goto fail_fw_init; |
| 627 | } |
| 628 | |
| 629 | memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST)); |
| 630 | |
| 631 | IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT; |
| 632 | IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 633 | IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION); |
| 634 | IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); |
| 635 | 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] | 636 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 637 | IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth); |
| 638 | IOCInitMessage->ReplyDescriptorPostQueueAddress = cpu_to_le64(fusion->reply_frames_desc_phys); |
| 639 | IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys); |
adam radford | 5738f99 | 2012-03-19 19:49:53 -0700 | [diff] [blame] | 640 | IOCInitMessage->HostMSIxVectors = instance->msix_vectors; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 641 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 642 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 643 | |
| 644 | frame_hdr = &cmd->frame->hdr; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 645 | frame_hdr->cmd_status = 0xFF; |
Christoph Hellwig | 48433bd | 2015-04-23 16:33:39 +0530 | [diff] [blame] | 646 | frame_hdr->flags = cpu_to_le16( |
| 647 | le16_to_cpu(frame_hdr->flags) | |
| 648 | MFI_FRAME_DONT_POST_IN_REPLY_QUEUE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 649 | |
| 650 | init_frame->cmd = MFI_CMD_INIT; |
| 651 | init_frame->cmd_status = 0xFF; |
| 652 | |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 653 | drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations); |
| 654 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 655 | /* driver support Extended MSIX */ |
| 656 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 657 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 658 | drv_ops->mfi_capabilities.support_additional_msix = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 659 | /* driver supports HA / Remote LUN over Fast Path interface */ |
sumit.saxena@avagotech.com | 4dbbe3c | 2015-08-31 17:23:21 +0530 | [diff] [blame] | 660 | drv_ops->mfi_capabilities.support_fp_remote_lun = 1; |
| 661 | |
| 662 | drv_ops->mfi_capabilities.support_max_255lds = 1; |
| 663 | drv_ops->mfi_capabilities.support_ndrive_r1_lb = 1; |
| 664 | drv_ops->mfi_capabilities.security_protocol_cmds_fw = 1; |
| 665 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 666 | if (instance->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN) |
| 667 | drv_ops->mfi_capabilities.support_ext_io_size = 1; |
| 668 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 669 | /* Convert capability to LE32 */ |
| 670 | cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 671 | |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 672 | sys_info = dmi_get_system_info(DMI_PRODUCT_UUID); |
| 673 | if (instance->system_info_buf && sys_info) { |
| 674 | memcpy(instance->system_info_buf->systemId, sys_info, |
| 675 | strlen(sys_info) > 64 ? 64 : strlen(sys_info)); |
| 676 | instance->system_info_buf->systemIdLength = |
| 677 | strlen(sys_info) > 64 ? 64 : strlen(sys_info); |
| 678 | init_frame->system_info_lo = instance->system_info_h; |
| 679 | init_frame->system_info_hi = 0; |
| 680 | } |
| 681 | |
Hannes Reinecke | fdc5a97 | 2014-01-16 11:25:33 +0100 | [diff] [blame] | 682 | init_frame->queue_info_new_phys_addr_hi = |
| 683 | cpu_to_le32(upper_32_bits(ioc_init_handle)); |
| 684 | init_frame->queue_info_new_phys_addr_lo = |
| 685 | cpu_to_le32(lower_32_bits(ioc_init_handle)); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 686 | 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] | 687 | |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 688 | req_desc.u.low = cpu_to_le32(lower_32_bits(cmd->frame_phys_addr)); |
| 689 | 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] | 690 | req_desc.MFAIo.RequestFlags = |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 691 | (MEGASAS_REQ_DESCRIPT_FLAGS_MFA << |
Sumit.Saxena@avagotech.com | 200aed5 | 2015-01-05 20:05:58 +0530 | [diff] [blame] | 692 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 693 | |
| 694 | /* |
| 695 | * disable the intr before firing the init frame |
| 696 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 697 | instance->instancet->disable_intr(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 698 | |
| 699 | for (i = 0; i < (10 * 1000); i += 20) { |
| 700 | if (readl(&instance->reg_set->doorbell) & 1) |
| 701 | msleep(20); |
| 702 | else |
| 703 | break; |
| 704 | } |
| 705 | |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 706 | megasas_fire_cmd_fusion(instance, &req_desc); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 707 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 708 | wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 709 | |
| 710 | frame_hdr = &cmd->frame->hdr; |
| 711 | if (frame_hdr->cmd_status != 0) { |
| 712 | ret = 1; |
| 713 | goto fail_fw_init; |
| 714 | } |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 715 | dev_err(&instance->pdev->dev, "Init cmd success\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 716 | |
| 717 | ret = 0; |
| 718 | |
| 719 | fail_fw_init: |
| 720 | megasas_return_cmd(instance, cmd); |
| 721 | if (IOCInitMessage) |
| 722 | dma_free_coherent(&instance->pdev->dev, |
| 723 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 724 | IOCInitMessage, ioc_init_handle); |
| 725 | fail_get_cmd: |
| 726 | return ret; |
| 727 | } |
| 728 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 729 | /** |
| 730 | * megasas_sync_pd_seq_num - JBOD SEQ MAP |
| 731 | * @instance: Adapter soft state |
| 732 | * @pend: set to 1, if it is pended jbod map. |
| 733 | * |
| 734 | * Issue Jbod map to the firmware. If it is pended command, |
| 735 | * issue command and return. If it is first instance of jbod map |
| 736 | * issue and receive command. |
| 737 | */ |
| 738 | int |
| 739 | megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) { |
| 740 | int ret = 0; |
| 741 | u32 pd_seq_map_sz; |
| 742 | struct megasas_cmd *cmd; |
| 743 | struct megasas_dcmd_frame *dcmd; |
| 744 | struct fusion_context *fusion = instance->ctrl_context; |
| 745 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
| 746 | dma_addr_t pd_seq_h; |
| 747 | |
| 748 | pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)]; |
| 749 | pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)]; |
| 750 | pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) + |
| 751 | (sizeof(struct MR_PD_CFG_SEQ) * |
| 752 | (MAX_PHYSICAL_DEVICES - 1)); |
| 753 | |
| 754 | cmd = megasas_get_cmd(instance); |
| 755 | if (!cmd) { |
| 756 | dev_err(&instance->pdev->dev, |
| 757 | "Could not get mfi cmd. Fail from %s %d\n", |
| 758 | __func__, __LINE__); |
| 759 | return -ENOMEM; |
| 760 | } |
| 761 | |
| 762 | dcmd = &cmd->frame->dcmd; |
| 763 | |
| 764 | memset(pd_sync, 0, pd_seq_map_sz); |
| 765 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 766 | dcmd->cmd = MFI_CMD_DCMD; |
| 767 | dcmd->cmd_status = 0xFF; |
| 768 | dcmd->sge_count = 1; |
| 769 | dcmd->timeout = 0; |
| 770 | dcmd->pad_0 = 0; |
| 771 | dcmd->data_xfer_len = cpu_to_le32(pd_seq_map_sz); |
| 772 | dcmd->opcode = cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO); |
| 773 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(pd_seq_h); |
| 774 | dcmd->sgl.sge32[0].length = cpu_to_le32(pd_seq_map_sz); |
| 775 | |
| 776 | if (pend) { |
| 777 | dcmd->mbox.b[0] = MEGASAS_DCMD_MBOX_PEND_FLAG; |
| 778 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE); |
| 779 | instance->jbod_seq_cmd = cmd; |
| 780 | instance->instancet->issue_dcmd(instance, cmd); |
| 781 | return 0; |
| 782 | } |
| 783 | |
| 784 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
| 785 | |
| 786 | /* Below code is only for non pended DCMD */ |
| 787 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 788 | ret = megasas_issue_blocked_cmd(instance, cmd, 60); |
| 789 | else |
| 790 | ret = megasas_issue_polled(instance, cmd); |
| 791 | |
| 792 | if (le32_to_cpu(pd_sync->count) > MAX_PHYSICAL_DEVICES) { |
| 793 | dev_warn(&instance->pdev->dev, |
| 794 | "driver supports max %d JBOD, but FW reports %d\n", |
| 795 | MAX_PHYSICAL_DEVICES, le32_to_cpu(pd_sync->count)); |
| 796 | ret = -EINVAL; |
| 797 | } |
| 798 | |
| 799 | if (!ret) |
| 800 | instance->pd_seq_map_id++; |
| 801 | |
| 802 | megasas_return_cmd(instance, cmd); |
| 803 | return ret; |
| 804 | } |
| 805 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 806 | /* |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 807 | * megasas_get_ld_map_info - Returns FW's ld_map structure |
| 808 | * @instance: Adapter soft state |
| 809 | * @pend: Pend the command or not |
| 810 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 811 | * list structure. This information is mainly used to find out SYSTEM |
| 812 | * supported by the FW. |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 813 | * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO |
| 814 | * dcmd.mbox.b[0] - number of LDs being sync'd |
| 815 | * dcmd.mbox.b[1] - 0 - complete command immediately. |
| 816 | * - 1 - pend till config change |
| 817 | * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP |
| 818 | * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and |
| 819 | * uses extended struct MR_FW_RAID_MAP_EXT |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 820 | */ |
| 821 | static int |
| 822 | megasas_get_ld_map_info(struct megasas_instance *instance) |
| 823 | { |
| 824 | int ret = 0; |
| 825 | struct megasas_cmd *cmd; |
| 826 | struct megasas_dcmd_frame *dcmd; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 827 | void *ci; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 828 | dma_addr_t ci_h = 0; |
| 829 | u32 size_map_info; |
| 830 | struct fusion_context *fusion; |
| 831 | |
| 832 | cmd = megasas_get_cmd(instance); |
| 833 | |
| 834 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 835 | 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] | 836 | return -ENOMEM; |
| 837 | } |
| 838 | |
| 839 | fusion = instance->ctrl_context; |
| 840 | |
| 841 | if (!fusion) { |
| 842 | megasas_return_cmd(instance, cmd); |
Hannes Reinecke | 2f8bdfa | 2014-01-16 11:25:35 +0100 | [diff] [blame] | 843 | return -ENXIO; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | dcmd = &cmd->frame->dcmd; |
| 847 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 848 | size_map_info = fusion->current_map_sz; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 849 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 850 | ci = (void *) fusion->ld_map[(instance->map_id & 1)]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 851 | ci_h = fusion->ld_map_phys[(instance->map_id & 1)]; |
| 852 | |
| 853 | if (!ci) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 854 | 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] | 855 | megasas_return_cmd(instance, cmd); |
| 856 | return -ENOMEM; |
| 857 | } |
| 858 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 859 | memset(ci, 0, fusion->max_map_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 860 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 861 | #if VD_EXT_DEBUG |
| 862 | dev_dbg(&instance->pdev->dev, |
| 863 | "%s sending MR_DCMD_LD_MAP_GET_INFO with size %d\n", |
| 864 | __func__, cpu_to_le32(size_map_info)); |
| 865 | #endif |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 866 | dcmd->cmd = MFI_CMD_DCMD; |
| 867 | dcmd->cmd_status = 0xFF; |
| 868 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 869 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 870 | dcmd->timeout = 0; |
| 871 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 872 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
| 873 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); |
| 874 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 875 | dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 876 | |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 877 | if (instance->ctrl_context && !instance->mask_interrupts) |
| 878 | ret = megasas_issue_blocked_cmd(instance, cmd, |
| 879 | MEGASAS_BLOCKED_CMD_TIMEOUT); |
| 880 | else |
| 881 | ret = megasas_issue_polled(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 882 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 883 | megasas_return_cmd(instance, cmd); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 884 | |
| 885 | return ret; |
| 886 | } |
| 887 | |
| 888 | u8 |
| 889 | megasas_get_map_info(struct megasas_instance *instance) |
| 890 | { |
| 891 | struct fusion_context *fusion = instance->ctrl_context; |
| 892 | |
| 893 | fusion->fast_path_io = 0; |
| 894 | if (!megasas_get_ld_map_info(instance)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 895 | if (MR_ValidateMapInfo(instance)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 896 | fusion->fast_path_io = 1; |
| 897 | return 0; |
| 898 | } |
| 899 | } |
| 900 | return 1; |
| 901 | } |
| 902 | |
| 903 | /* |
| 904 | * megasas_sync_map_info - Returns FW's ld_map structure |
| 905 | * @instance: Adapter soft state |
| 906 | * |
| 907 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 908 | * list structure. This information is mainly used to find out SYSTEM |
| 909 | * supported by the FW. |
| 910 | */ |
| 911 | int |
| 912 | megasas_sync_map_info(struct megasas_instance *instance) |
| 913 | { |
| 914 | int ret = 0, i; |
| 915 | struct megasas_cmd *cmd; |
| 916 | struct megasas_dcmd_frame *dcmd; |
| 917 | u32 size_sync_info, num_lds; |
| 918 | struct fusion_context *fusion; |
| 919 | struct MR_LD_TARGET_SYNC *ci = NULL; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 920 | struct MR_DRV_RAID_MAP_ALL *map; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 921 | struct MR_LD_RAID *raid; |
| 922 | struct MR_LD_TARGET_SYNC *ld_sync; |
| 923 | dma_addr_t ci_h = 0; |
| 924 | u32 size_map_info; |
| 925 | |
| 926 | cmd = megasas_get_cmd(instance); |
| 927 | |
| 928 | if (!cmd) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 929 | 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] | 930 | return -ENOMEM; |
| 931 | } |
| 932 | |
| 933 | fusion = instance->ctrl_context; |
| 934 | |
| 935 | if (!fusion) { |
| 936 | megasas_return_cmd(instance, cmd); |
| 937 | return 1; |
| 938 | } |
| 939 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 940 | map = fusion->ld_drv_map[instance->map_id & 1]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 941 | |
Sumit.Saxena@avagotech.com | 6e755dd | 2014-11-17 15:24:28 +0530 | [diff] [blame] | 942 | num_lds = le16_to_cpu(map->raidMap.ldCount); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 943 | |
| 944 | dcmd = &cmd->frame->dcmd; |
| 945 | |
| 946 | size_sync_info = sizeof(struct MR_LD_TARGET_SYNC) *num_lds; |
| 947 | |
| 948 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 949 | |
| 950 | ci = (struct MR_LD_TARGET_SYNC *) |
| 951 | fusion->ld_map[(instance->map_id - 1) & 1]; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 952 | memset(ci, 0, fusion->max_map_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 953 | |
| 954 | ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1]; |
| 955 | |
| 956 | ld_sync = (struct MR_LD_TARGET_SYNC *)ci; |
| 957 | |
| 958 | for (i = 0; i < num_lds; i++, ld_sync++) { |
| 959 | raid = MR_LdRaidGet(i, map); |
| 960 | ld_sync->targetId = MR_GetLDTgtId(i, map); |
| 961 | ld_sync->seqNum = raid->seqNum; |
| 962 | } |
| 963 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 964 | size_map_info = fusion->current_map_sz; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 965 | |
| 966 | dcmd->cmd = MFI_CMD_DCMD; |
| 967 | dcmd->cmd_status = 0xFF; |
| 968 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 969 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 970 | dcmd->timeout = 0; |
| 971 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 972 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 973 | dcmd->mbox.b[0] = num_lds; |
| 974 | dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 975 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); |
| 976 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 977 | dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 978 | |
| 979 | instance->map_update_cmd = cmd; |
| 980 | |
| 981 | instance->instancet->issue_dcmd(instance, cmd); |
| 982 | |
| 983 | return ret; |
| 984 | } |
| 985 | |
Sumit.Saxena@lsi.com | 39b72c3 | 2013-05-22 12:32:43 +0530 | [diff] [blame] | 986 | /* |
| 987 | * meagasas_display_intel_branding - Display branding string |
| 988 | * @instance: per adapter object |
| 989 | * |
| 990 | * Return nothing. |
| 991 | */ |
| 992 | static void |
| 993 | megasas_display_intel_branding(struct megasas_instance *instance) |
| 994 | { |
| 995 | if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) |
| 996 | return; |
| 997 | |
| 998 | switch (instance->pdev->device) { |
| 999 | case PCI_DEVICE_ID_LSI_INVADER: |
| 1000 | switch (instance->pdev->subsystem_device) { |
| 1001 | case MEGARAID_INTEL_RS3DC080_SSDID: |
| 1002 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1003 | instance->host->host_no, |
| 1004 | MEGARAID_INTEL_RS3DC080_BRANDING); |
| 1005 | break; |
| 1006 | case MEGARAID_INTEL_RS3DC040_SSDID: |
| 1007 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1008 | instance->host->host_no, |
| 1009 | MEGARAID_INTEL_RS3DC040_BRANDING); |
| 1010 | break; |
| 1011 | case MEGARAID_INTEL_RS3SC008_SSDID: |
| 1012 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1013 | instance->host->host_no, |
| 1014 | MEGARAID_INTEL_RS3SC008_BRANDING); |
| 1015 | break; |
| 1016 | case MEGARAID_INTEL_RS3MC044_SSDID: |
| 1017 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1018 | instance->host->host_no, |
| 1019 | MEGARAID_INTEL_RS3MC044_BRANDING); |
| 1020 | break; |
| 1021 | default: |
| 1022 | break; |
| 1023 | } |
| 1024 | break; |
| 1025 | case PCI_DEVICE_ID_LSI_FURY: |
| 1026 | switch (instance->pdev->subsystem_device) { |
| 1027 | case MEGARAID_INTEL_RS3WC080_SSDID: |
| 1028 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1029 | instance->host->host_no, |
| 1030 | MEGARAID_INTEL_RS3WC080_BRANDING); |
| 1031 | break; |
| 1032 | case MEGARAID_INTEL_RS3WC040_SSDID: |
| 1033 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 1034 | instance->host->host_no, |
| 1035 | MEGARAID_INTEL_RS3WC040_BRANDING); |
| 1036 | break; |
| 1037 | default: |
| 1038 | break; |
| 1039 | } |
| 1040 | break; |
| 1041 | default: |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1046 | /** |
| 1047 | * megasas_init_adapter_fusion - Initializes the FW |
| 1048 | * @instance: Adapter soft state |
| 1049 | * |
| 1050 | * This is the main function for initializing firmware. |
| 1051 | */ |
| 1052 | u32 |
| 1053 | megasas_init_adapter_fusion(struct megasas_instance *instance) |
| 1054 | { |
| 1055 | struct megasas_register_set __iomem *reg_set; |
| 1056 | struct fusion_context *fusion; |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1057 | u32 max_cmd, scratch_pad_2; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1058 | int i = 0, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1059 | |
| 1060 | fusion = instance->ctrl_context; |
| 1061 | |
| 1062 | reg_set = instance->reg_set; |
| 1063 | |
| 1064 | /* |
| 1065 | * Get various operational parameters from status register |
| 1066 | */ |
| 1067 | instance->max_fw_cmds = |
| 1068 | instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF; |
| 1069 | instance->max_fw_cmds = min(instance->max_fw_cmds, (u16)1008); |
| 1070 | |
| 1071 | /* |
| 1072 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 1073 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 1074 | * does not exceed max cmds that the FW can support |
| 1075 | */ |
| 1076 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
Sumit.Saxena@avagotech.com | ae09a6c | 2015-01-05 20:06:23 +0530 | [diff] [blame] | 1077 | |
| 1078 | /* |
| 1079 | * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames |
| 1080 | */ |
| 1081 | instance->max_mfi_cmds = |
| 1082 | MEGASAS_FUSION_INTERNAL_CMDS + MEGASAS_FUSION_IOCTL_CMDS; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1083 | |
| 1084 | max_cmd = instance->max_fw_cmds; |
| 1085 | |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 1086 | fusion->reply_q_depth = 2 * (((max_cmd + 1 + 15)/16)*16); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1087 | |
| 1088 | fusion->request_alloc_sz = |
| 1089 | sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *max_cmd; |
| 1090 | fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION) |
| 1091 | *(fusion->reply_q_depth); |
| 1092 | fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE + |
| 1093 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * |
| 1094 | (max_cmd + 1)); /* Extra 1 for SMID 0 */ |
| 1095 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1096 | scratch_pad_2 = readl(&instance->reg_set->outbound_scratch_pad_2); |
| 1097 | /* If scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set, |
| 1098 | * Firmware support extended IO chain frame which is 4 times more than |
| 1099 | * legacy Firmware. |
| 1100 | * Legacy Firmware - Frame size is (8 * 128) = 1K |
| 1101 | * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K |
| 1102 | */ |
| 1103 | if (scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK) |
| 1104 | instance->max_chain_frame_sz = |
| 1105 | ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >> |
| 1106 | MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_1MB_IO; |
| 1107 | else |
| 1108 | instance->max_chain_frame_sz = |
| 1109 | ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >> |
| 1110 | MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_256K_IO; |
| 1111 | |
| 1112 | if (instance->max_chain_frame_sz < MEGASAS_CHAIN_FRAME_SZ_MIN) { |
| 1113 | dev_warn(&instance->pdev->dev, "frame size %d invalid, fall back to legacy max frame size %d\n", |
| 1114 | instance->max_chain_frame_sz, |
| 1115 | MEGASAS_CHAIN_FRAME_SZ_MIN); |
| 1116 | instance->max_chain_frame_sz = MEGASAS_CHAIN_FRAME_SZ_MIN; |
| 1117 | } |
| 1118 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1119 | fusion->max_sge_in_main_msg = |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1120 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE |
| 1121 | - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1122 | |
| 1123 | fusion->max_sge_in_chain = |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1124 | instance->max_chain_frame_sz |
| 1125 | / sizeof(union MPI2_SGE_IO_UNION); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1126 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1127 | instance->max_num_sge = |
| 1128 | rounddown_pow_of_two(fusion->max_sge_in_main_msg |
| 1129 | + fusion->max_sge_in_chain - 2); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1130 | |
| 1131 | /* Used for pass thru MFI frame (DCMD) */ |
| 1132 | fusion->chain_offset_mfi_pthru = |
| 1133 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16; |
| 1134 | |
| 1135 | fusion->chain_offset_io_request = |
| 1136 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - |
| 1137 | sizeof(union MPI2_SGE_IO_UNION))/16; |
| 1138 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1139 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 1140 | for (i = 0 ; i < count; i++) |
| 1141 | fusion->last_reply_idx[i] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1142 | |
| 1143 | /* |
Sumit.Saxena@avagotech.com | f26ac3a | 2015-04-23 16:30:54 +0530 | [diff] [blame] | 1144 | * For fusion adapters, 3 commands for IOCTL and 5 commands |
| 1145 | * for driver's internal DCMDs. |
| 1146 | */ |
| 1147 | instance->max_scsi_cmds = instance->max_fw_cmds - |
| 1148 | (MEGASAS_FUSION_INTERNAL_CMDS + |
| 1149 | MEGASAS_FUSION_IOCTL_CMDS); |
| 1150 | sema_init(&instance->ioctl_sem, MEGASAS_FUSION_IOCTL_CMDS); |
| 1151 | |
| 1152 | /* |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1153 | * Allocate memory for descriptors |
| 1154 | * Create a pool of commands |
| 1155 | */ |
| 1156 | if (megasas_alloc_cmds(instance)) |
| 1157 | goto fail_alloc_mfi_cmds; |
| 1158 | if (megasas_alloc_cmds_fusion(instance)) |
| 1159 | goto fail_alloc_cmds; |
| 1160 | |
| 1161 | if (megasas_ioc_init_fusion(instance)) |
| 1162 | goto fail_ioc_init; |
| 1163 | |
Sumit.Saxena@lsi.com | 39b72c3 | 2013-05-22 12:32:43 +0530 | [diff] [blame] | 1164 | megasas_display_intel_branding(instance); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 1165 | if (megasas_get_ctrl_info(instance)) { |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1166 | dev_err(&instance->pdev->dev, |
| 1167 | "Could not get controller info. Fail from %s %d\n", |
| 1168 | __func__, __LINE__); |
| 1169 | goto fail_ioc_init; |
| 1170 | } |
| 1171 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1172 | instance->flag_ieee = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1173 | fusion->fast_path_io = 0; |
| 1174 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1175 | fusion->drv_map_pages = get_order(fusion->drv_map_sz); |
| 1176 | for (i = 0; i < 2; i++) { |
| 1177 | fusion->ld_map[i] = NULL; |
| 1178 | fusion->ld_drv_map[i] = (void *)__get_free_pages(GFP_KERNEL, |
| 1179 | fusion->drv_map_pages); |
| 1180 | if (!fusion->ld_drv_map[i]) { |
| 1181 | dev_err(&instance->pdev->dev, "Could not allocate " |
| 1182 | "memory for local map info for %d pages\n", |
| 1183 | fusion->drv_map_pages); |
| 1184 | if (i == 1) |
| 1185 | free_pages((ulong)fusion->ld_drv_map[0], |
| 1186 | fusion->drv_map_pages); |
| 1187 | goto fail_ioc_init; |
| 1188 | } |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 1189 | memset(fusion->ld_drv_map[i], 0, |
| 1190 | ((1 << PAGE_SHIFT) << fusion->drv_map_pages)); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1191 | } |
| 1192 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1193 | for (i = 0; i < 2; i++) { |
| 1194 | fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1195 | fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1196 | &fusion->ld_map_phys[i], |
| 1197 | GFP_KERNEL); |
| 1198 | if (!fusion->ld_map[i]) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1199 | dev_err(&instance->pdev->dev, "Could not allocate memory " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1200 | "for map info\n"); |
| 1201 | goto fail_map_info; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | if (!megasas_get_map_info(instance)) |
| 1206 | megasas_sync_map_info(instance); |
| 1207 | |
| 1208 | return 0; |
| 1209 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1210 | fail_map_info: |
| 1211 | if (i == 1) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1212 | dma_free_coherent(&instance->pdev->dev, fusion->max_map_sz, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1213 | fusion->ld_map[0], fusion->ld_map_phys[0]); |
| 1214 | fail_ioc_init: |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 1215 | megasas_free_cmds_fusion(instance); |
| 1216 | fail_alloc_cmds: |
| 1217 | megasas_free_cmds(instance); |
| 1218 | fail_alloc_mfi_cmds: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1219 | return 1; |
| 1220 | } |
| 1221 | |
| 1222 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1223 | * map_cmd_status - Maps FW cmd status to OS cmd status |
| 1224 | * @cmd : Pointer to cmd |
| 1225 | * @status : status of cmd returned by FW |
| 1226 | * @ext_status : ext status of cmd returned by FW |
| 1227 | */ |
| 1228 | |
| 1229 | void |
| 1230 | map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status) |
| 1231 | { |
| 1232 | |
| 1233 | switch (status) { |
| 1234 | |
| 1235 | case MFI_STAT_OK: |
| 1236 | cmd->scmd->result = DID_OK << 16; |
| 1237 | break; |
| 1238 | |
| 1239 | case MFI_STAT_SCSI_IO_FAILED: |
| 1240 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 1241 | cmd->scmd->result = (DID_ERROR << 16) | ext_status; |
| 1242 | break; |
| 1243 | |
| 1244 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 1245 | |
| 1246 | cmd->scmd->result = (DID_OK << 16) | ext_status; |
| 1247 | if (ext_status == SAM_STAT_CHECK_CONDITION) { |
| 1248 | memset(cmd->scmd->sense_buffer, 0, |
| 1249 | SCSI_SENSE_BUFFERSIZE); |
| 1250 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 1251 | SCSI_SENSE_BUFFERSIZE); |
| 1252 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 1253 | } |
| 1254 | break; |
| 1255 | |
| 1256 | case MFI_STAT_LD_OFFLINE: |
| 1257 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 1258 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 1259 | break; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1260 | case MFI_STAT_CONFIG_SEQ_MISMATCH: |
| 1261 | cmd->scmd->result = DID_IMM_RETRY << 16; |
| 1262 | break; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1263 | default: |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1264 | dev_printk(KERN_DEBUG, &cmd->instance->pdev->dev, "FW status %#x\n", status); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1265 | cmd->scmd->result = DID_ERROR << 16; |
| 1266 | break; |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | /** |
| 1271 | * megasas_make_sgl_fusion - Prepares 32-bit SGL |
| 1272 | * @instance: Adapter soft state |
| 1273 | * @scp: SCSI command from the mid-layer |
| 1274 | * @sgl_ptr: SGL to be filled in |
| 1275 | * @cmd: cmd we are working on |
| 1276 | * |
| 1277 | * If successful, this function returns the number of SG elements. |
| 1278 | */ |
| 1279 | static int |
| 1280 | megasas_make_sgl_fusion(struct megasas_instance *instance, |
| 1281 | struct scsi_cmnd *scp, |
| 1282 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr, |
| 1283 | struct megasas_cmd_fusion *cmd) |
| 1284 | { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1285 | int i, sg_processed, sge_count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1286 | struct scatterlist *os_sgl; |
| 1287 | struct fusion_context *fusion; |
| 1288 | |
| 1289 | fusion = instance->ctrl_context; |
| 1290 | |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1291 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1292 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1293 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr; |
| 1294 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; |
| 1295 | sgl_ptr_end->Flags = 0; |
| 1296 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1297 | |
| 1298 | sge_count = scsi_dma_map(scp); |
| 1299 | |
| 1300 | BUG_ON(sge_count < 0); |
| 1301 | |
| 1302 | if (sge_count > instance->max_num_sge || !sge_count) |
| 1303 | return sge_count; |
| 1304 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1305 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1306 | sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1307 | sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1308 | sgl_ptr->Flags = 0; |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1309 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1310 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1311 | if (i == sge_count - 1) |
| 1312 | sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST; |
| 1313 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1314 | sgl_ptr++; |
| 1315 | |
| 1316 | sg_processed = i + 1; |
| 1317 | |
| 1318 | if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) && |
| 1319 | (sge_count > fusion->max_sge_in_main_msg)) { |
| 1320 | |
| 1321 | struct MPI25_IEEE_SGE_CHAIN64 *sg_chain; |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1322 | if ((instance->pdev->device == |
| 1323 | PCI_DEVICE_ID_LSI_INVADER) || |
| 1324 | (instance->pdev->device == |
| 1325 | PCI_DEVICE_ID_LSI_FURY)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1326 | if ((le16_to_cpu(cmd->io_request->IoFlags) & |
| 1327 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) != |
| 1328 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1329 | cmd->io_request->ChainOffset = |
| 1330 | fusion-> |
| 1331 | chain_offset_io_request; |
| 1332 | else |
| 1333 | cmd->io_request->ChainOffset = 0; |
| 1334 | } else |
| 1335 | cmd->io_request->ChainOffset = |
| 1336 | fusion->chain_offset_io_request; |
| 1337 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1338 | sg_chain = sgl_ptr; |
| 1339 | /* Prepare chain element */ |
| 1340 | sg_chain->NextChainOffset = 0; |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1341 | if ((instance->pdev->device == |
| 1342 | PCI_DEVICE_ID_LSI_INVADER) || |
| 1343 | (instance->pdev->device == |
| 1344 | PCI_DEVICE_ID_LSI_FURY)) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1345 | sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT; |
| 1346 | else |
| 1347 | sg_chain->Flags = |
| 1348 | (IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 1349 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1350 | sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed))); |
| 1351 | sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1352 | |
| 1353 | sgl_ptr = |
| 1354 | (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame; |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1355 | memset(sgl_ptr, 0, instance->max_chain_frame_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | return sge_count; |
| 1360 | } |
| 1361 | |
| 1362 | /** |
| 1363 | * megasas_set_pd_lba - Sets PD LBA |
| 1364 | * @cdb: CDB |
| 1365 | * @cdb_len: cdb length |
| 1366 | * @start_blk: Start block of IO |
| 1367 | * |
| 1368 | * Used to set the PD LBA in CDB for FP IOs |
| 1369 | */ |
| 1370 | void |
| 1371 | megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len, |
| 1372 | struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp, |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1373 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1374 | { |
| 1375 | struct MR_LD_RAID *raid; |
| 1376 | u32 ld; |
| 1377 | u64 start_blk = io_info->pdBlock; |
| 1378 | u8 *cdb = io_request->CDB.CDB32; |
| 1379 | u32 num_blocks = io_info->numBlocks; |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1380 | u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1381 | |
| 1382 | /* Check if T10 PI (DIF) is enabled for this LD */ |
| 1383 | ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr); |
| 1384 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1385 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) { |
| 1386 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1387 | cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD; |
| 1388 | cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN; |
| 1389 | |
| 1390 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1391 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32; |
| 1392 | else |
| 1393 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32; |
| 1394 | cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL; |
| 1395 | |
| 1396 | /* LBA */ |
| 1397 | cdb[12] = (u8)((start_blk >> 56) & 0xff); |
| 1398 | cdb[13] = (u8)((start_blk >> 48) & 0xff); |
| 1399 | cdb[14] = (u8)((start_blk >> 40) & 0xff); |
| 1400 | cdb[15] = (u8)((start_blk >> 32) & 0xff); |
| 1401 | cdb[16] = (u8)((start_blk >> 24) & 0xff); |
| 1402 | cdb[17] = (u8)((start_blk >> 16) & 0xff); |
| 1403 | cdb[18] = (u8)((start_blk >> 8) & 0xff); |
| 1404 | cdb[19] = (u8)(start_blk & 0xff); |
| 1405 | |
| 1406 | /* Logical block reference tag */ |
| 1407 | io_request->CDB.EEDP32.PrimaryReferenceTag = |
| 1408 | cpu_to_be32(ref_tag); |
Sumit.Saxena@avagotech.com | 6e755dd | 2014-11-17 15:24:28 +0530 | [diff] [blame] | 1409 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = cpu_to_be16(0xffff); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1410 | io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1411 | |
| 1412 | /* Transfer length */ |
| 1413 | cdb[28] = (u8)((num_blocks >> 24) & 0xff); |
| 1414 | cdb[29] = (u8)((num_blocks >> 16) & 0xff); |
| 1415 | cdb[30] = (u8)((num_blocks >> 8) & 0xff); |
| 1416 | cdb[31] = (u8)(num_blocks & 0xff); |
| 1417 | |
| 1418 | /* set SCSI IO EEDPFlags */ |
| 1419 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1420 | io_request->EEDPFlags = cpu_to_le16( |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1421 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
| 1422 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 1423 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP | |
| 1424 | MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1425 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1426 | } else { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1427 | io_request->EEDPFlags = cpu_to_le16( |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1428 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1429 | MPI2_SCSIIO_EEDPFLAGS_INSERT_OP); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1430 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1431 | io_request->Control |= cpu_to_le32((0x4 << 26)); |
| 1432 | io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1433 | } else { |
| 1434 | /* Some drives don't support 16/12 byte CDB's, convert to 10 */ |
| 1435 | if (((cdb_len == 12) || (cdb_len == 16)) && |
| 1436 | (start_blk <= 0xffffffff)) { |
| 1437 | if (cdb_len == 16) { |
| 1438 | opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10; |
| 1439 | flagvals = cdb[1]; |
| 1440 | groupnum = cdb[14]; |
| 1441 | control = cdb[15]; |
| 1442 | } else { |
| 1443 | opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10; |
| 1444 | flagvals = cdb[1]; |
| 1445 | groupnum = cdb[10]; |
| 1446 | control = cdb[11]; |
| 1447 | } |
| 1448 | |
| 1449 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1450 | |
| 1451 | cdb[0] = opcode; |
| 1452 | cdb[1] = flagvals; |
| 1453 | cdb[6] = groupnum; |
| 1454 | cdb[9] = control; |
| 1455 | |
| 1456 | /* Transfer length */ |
| 1457 | cdb[8] = (u8)(num_blocks & 0xff); |
| 1458 | cdb[7] = (u8)((num_blocks >> 8) & 0xff); |
| 1459 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1460 | io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1461 | cdb_len = 10; |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1462 | } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) { |
| 1463 | /* Convert to 16 byte CDB for large LBA's */ |
| 1464 | switch (cdb_len) { |
| 1465 | case 6: |
| 1466 | opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16; |
| 1467 | control = cdb[5]; |
| 1468 | break; |
| 1469 | case 10: |
| 1470 | opcode = |
| 1471 | cdb[0] == READ_10 ? READ_16 : WRITE_16; |
| 1472 | flagvals = cdb[1]; |
| 1473 | groupnum = cdb[6]; |
| 1474 | control = cdb[9]; |
| 1475 | break; |
| 1476 | case 12: |
| 1477 | opcode = |
| 1478 | cdb[0] == READ_12 ? READ_16 : WRITE_16; |
| 1479 | flagvals = cdb[1]; |
| 1480 | groupnum = cdb[10]; |
| 1481 | control = cdb[11]; |
| 1482 | break; |
| 1483 | } |
| 1484 | |
| 1485 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1486 | |
| 1487 | cdb[0] = opcode; |
| 1488 | cdb[1] = flagvals; |
| 1489 | cdb[14] = groupnum; |
| 1490 | cdb[15] = control; |
| 1491 | |
| 1492 | /* Transfer length */ |
| 1493 | cdb[13] = (u8)(num_blocks & 0xff); |
| 1494 | cdb[12] = (u8)((num_blocks >> 8) & 0xff); |
| 1495 | cdb[11] = (u8)((num_blocks >> 16) & 0xff); |
| 1496 | cdb[10] = (u8)((num_blocks >> 24) & 0xff); |
| 1497 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1498 | io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */ |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1499 | cdb_len = 16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /* Normal case, just load LBA here */ |
| 1503 | switch (cdb_len) { |
| 1504 | case 6: |
| 1505 | { |
| 1506 | u8 val = cdb[1] & 0xE0; |
| 1507 | cdb[3] = (u8)(start_blk & 0xff); |
| 1508 | cdb[2] = (u8)((start_blk >> 8) & 0xff); |
| 1509 | cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f); |
| 1510 | break; |
| 1511 | } |
| 1512 | case 10: |
| 1513 | cdb[5] = (u8)(start_blk & 0xff); |
| 1514 | cdb[4] = (u8)((start_blk >> 8) & 0xff); |
| 1515 | cdb[3] = (u8)((start_blk >> 16) & 0xff); |
| 1516 | cdb[2] = (u8)((start_blk >> 24) & 0xff); |
| 1517 | break; |
| 1518 | case 12: |
| 1519 | cdb[5] = (u8)(start_blk & 0xff); |
| 1520 | cdb[4] = (u8)((start_blk >> 8) & 0xff); |
| 1521 | cdb[3] = (u8)((start_blk >> 16) & 0xff); |
| 1522 | cdb[2] = (u8)((start_blk >> 24) & 0xff); |
| 1523 | break; |
| 1524 | case 16: |
| 1525 | cdb[9] = (u8)(start_blk & 0xff); |
| 1526 | cdb[8] = (u8)((start_blk >> 8) & 0xff); |
| 1527 | cdb[7] = (u8)((start_blk >> 16) & 0xff); |
| 1528 | cdb[6] = (u8)((start_blk >> 24) & 0xff); |
| 1529 | cdb[5] = (u8)((start_blk >> 32) & 0xff); |
| 1530 | cdb[4] = (u8)((start_blk >> 40) & 0xff); |
| 1531 | cdb[3] = (u8)((start_blk >> 48) & 0xff); |
| 1532 | cdb[2] = (u8)((start_blk >> 56) & 0xff); |
| 1533 | break; |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | /** |
| 1539 | * megasas_build_ldio_fusion - Prepares IOs to devices |
| 1540 | * @instance: Adapter soft state |
| 1541 | * @scp: SCSI command |
| 1542 | * @cmd: Command to be prepared |
| 1543 | * |
| 1544 | * Prepares the io_request and chain elements (sg_frame) for IO |
| 1545 | * The IO can be for PD (Fast Path) or LD |
| 1546 | */ |
| 1547 | void |
| 1548 | megasas_build_ldio_fusion(struct megasas_instance *instance, |
| 1549 | struct scsi_cmnd *scp, |
| 1550 | struct megasas_cmd_fusion *cmd) |
| 1551 | { |
| 1552 | u8 fp_possible; |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1553 | u32 start_lba_lo, start_lba_hi, device_id, datalength = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1554 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 1555 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 1556 | struct IO_REQUEST_INFO io_info; |
| 1557 | struct fusion_context *fusion; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1558 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1559 | u8 *raidLUN; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1560 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1561 | device_id = MEGASAS_DEV_INDEX(scp); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1562 | |
| 1563 | fusion = instance->ctrl_context; |
| 1564 | |
| 1565 | io_request = cmd->io_request; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1566 | io_request->RaidContext.VirtualDiskTgtId = cpu_to_le16(device_id); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1567 | io_request->RaidContext.status = 0; |
| 1568 | io_request->RaidContext.exStatus = 0; |
| 1569 | |
| 1570 | req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc; |
| 1571 | |
| 1572 | start_lba_lo = 0; |
| 1573 | start_lba_hi = 0; |
| 1574 | fp_possible = 0; |
| 1575 | |
| 1576 | /* |
| 1577 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1578 | */ |
| 1579 | if (scp->cmd_len == 6) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1580 | datalength = (u32) scp->cmnd[4]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1581 | start_lba_lo = ((u32) scp->cmnd[1] << 16) | |
| 1582 | ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3]; |
| 1583 | |
| 1584 | start_lba_lo &= 0x1FFFFF; |
| 1585 | } |
| 1586 | |
| 1587 | /* |
| 1588 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1589 | */ |
| 1590 | else if (scp->cmd_len == 10) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1591 | datalength = (u32) scp->cmnd[8] | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1592 | ((u32) scp->cmnd[7] << 8); |
| 1593 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 1594 | ((u32) scp->cmnd[3] << 16) | |
| 1595 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1596 | } |
| 1597 | |
| 1598 | /* |
| 1599 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1600 | */ |
| 1601 | else if (scp->cmd_len == 12) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1602 | datalength = ((u32) scp->cmnd[6] << 24) | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1603 | ((u32) scp->cmnd[7] << 16) | |
| 1604 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 1605 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 1606 | ((u32) scp->cmnd[3] << 16) | |
| 1607 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1608 | } |
| 1609 | |
| 1610 | /* |
| 1611 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1612 | */ |
| 1613 | else if (scp->cmd_len == 16) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1614 | datalength = ((u32) scp->cmnd[10] << 24) | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1615 | ((u32) scp->cmnd[11] << 16) | |
| 1616 | ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13]; |
| 1617 | start_lba_lo = ((u32) scp->cmnd[6] << 24) | |
| 1618 | ((u32) scp->cmnd[7] << 16) | |
| 1619 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 1620 | |
| 1621 | start_lba_hi = ((u32) scp->cmnd[2] << 24) | |
| 1622 | ((u32) scp->cmnd[3] << 16) | |
| 1623 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1624 | } |
| 1625 | |
| 1626 | memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO)); |
| 1627 | io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo; |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1628 | io_info.numBlocks = datalength; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1629 | io_info.ldTgtId = device_id; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1630 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scp)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1631 | |
| 1632 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1633 | io_info.isRead = 1; |
| 1634 | |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1635 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1636 | |
| 1637 | if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >= |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1638 | instance->fw_supported_vd_count) || (!fusion->fast_path_io)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1639 | io_request->RaidContext.regLockFlags = 0; |
| 1640 | fp_possible = 0; |
| 1641 | } else { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1642 | if (MR_BuildRaidContext(instance, &io_info, |
| 1643 | &io_request->RaidContext, |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1644 | local_map_ptr, &raidLUN)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1645 | fp_possible = io_info.fpOkForIo; |
| 1646 | } |
| 1647 | |
Christoph Hellwig | 16b8528 | 2015-04-15 09:44:37 -0700 | [diff] [blame] | 1648 | /* 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] | 1649 | id by default, not CPU group id, otherwise all MSI-X queues won't |
| 1650 | be utilized */ |
| 1651 | cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ? |
Christoph Hellwig | 16b8528 | 2015-04-15 09:44:37 -0700 | [diff] [blame] | 1652 | raw_smp_processor_id() % instance->msix_vectors : 0; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1653 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1654 | if (fp_possible) { |
| 1655 | megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp, |
| 1656 | local_map_ptr, start_lba_lo); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1657 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 1658 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1659 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY |
| 1660 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1661 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1662 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1663 | if (io_request->RaidContext.regLockFlags == |
| 1664 | REGION_TYPE_UNUSED) |
| 1665 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1666 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << |
| 1667 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1668 | io_request->RaidContext.Type = MPI2_TYPE_CUDA; |
| 1669 | io_request->RaidContext.nseg = 0x1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1670 | io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1671 | io_request->RaidContext.regLockFlags |= |
| 1672 | (MR_RL_FLAGS_GRANT_DESTINATION_CUDA | |
| 1673 | MR_RL_FLAGS_SEQ_NUM_ENABLE); |
| 1674 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1675 | if ((fusion->load_balance_info[device_id].loadBalanceFlag) && |
| 1676 | (io_info.isRead)) { |
| 1677 | io_info.devHandle = |
Sumit.Saxena@avagotech.com | d2552eb | 2014-09-12 18:57:53 +0530 | [diff] [blame] | 1678 | get_updated_dev_handle(instance, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1679 | &fusion->load_balance_info[device_id], |
| 1680 | &io_info); |
| 1681 | scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG; |
Sumit.Saxena@avagotech.com | d2552eb | 2014-09-12 18:57:53 +0530 | [diff] [blame] | 1682 | cmd->pd_r1_lb = io_info.pd_after_lb; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1683 | } else |
| 1684 | scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG; |
Sumit.Saxena@avagotech.com | 5765c5b | 2015-04-23 16:32:09 +0530 | [diff] [blame] | 1685 | |
| 1686 | if ((raidLUN[0] == 1) && |
| 1687 | (local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 2)) { |
| 1688 | instance->dev_handle = !(instance->dev_handle); |
| 1689 | io_info.devHandle = |
| 1690 | local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].devHandle[instance->dev_handle]; |
| 1691 | } |
| 1692 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1693 | cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle; |
| 1694 | io_request->DevHandle = io_info.devHandle; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1695 | /* populate the LUN field */ |
| 1696 | memcpy(io_request->LUN, raidLUN, 8); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1697 | } else { |
| 1698 | io_request->RaidContext.timeoutValue = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1699 | cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1700 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1701 | (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO |
| 1702 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1703 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1704 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1705 | if (io_request->RaidContext.regLockFlags == |
| 1706 | REGION_TYPE_UNUSED) |
| 1707 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1708 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << |
| 1709 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1710 | io_request->RaidContext.Type = MPI2_TYPE_CUDA; |
| 1711 | io_request->RaidContext.regLockFlags |= |
| 1712 | (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 | |
| 1713 | MR_RL_FLAGS_SEQ_NUM_ENABLE); |
| 1714 | io_request->RaidContext.nseg = 0x1; |
| 1715 | } |
| 1716 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1717 | io_request->DevHandle = cpu_to_le16(device_id); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1718 | } /* Not FP */ |
| 1719 | } |
| 1720 | |
| 1721 | /** |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1722 | * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1723 | * @instance: Adapter soft state |
| 1724 | * @scp: SCSI command |
| 1725 | * @cmd: Command to be prepared |
| 1726 | * |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1727 | * Prepares the io_request frame for non-rw io cmds for vd. |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1728 | */ |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1729 | static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance, |
| 1730 | struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1731 | { |
| 1732 | u32 device_id; |
| 1733 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 1734 | u16 pd_index = 0; |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1735 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1736 | struct fusion_context *fusion = instance->ctrl_context; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1737 | u8 span, physArm; |
Christoph Hellwig | 9ab9ed38 | 2015-04-23 16:32:54 +0530 | [diff] [blame] | 1738 | __le16 devHandle; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1739 | u32 ld, arRef, pd; |
| 1740 | struct MR_LD_RAID *raid; |
| 1741 | struct RAID_CONTEXT *pRAID_Context; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1742 | u8 fp_possible = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1743 | |
| 1744 | io_request = cmd->io_request; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1745 | device_id = MEGASAS_DEV_INDEX(scmd); |
| 1746 | pd_index = MEGASAS_PD_INDEX(scmd); |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 1747 | 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] | 1748 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1749 | /* get RAID_Context pointer */ |
| 1750 | pRAID_Context = &io_request->RaidContext; |
| 1751 | /* Check with FW team */ |
| 1752 | pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id); |
| 1753 | pRAID_Context->regLockRowLBA = 0; |
| 1754 | pRAID_Context->regLockLength = 0; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1755 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1756 | if (fusion->fast_path_io && ( |
| 1757 | device_id < instance->fw_supported_vd_count)) { |
Sumit.Saxena@avagotech.com | ab2f060 | 2015-01-05 20:06:08 +0530 | [diff] [blame] | 1758 | |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1759 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
Sumit.Saxena@avagotech.com | ab2f060 | 2015-01-05 20:06:08 +0530 | [diff] [blame] | 1760 | if (ld >= instance->fw_supported_vd_count) |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1761 | fp_possible = 0; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1762 | |
| 1763 | raid = MR_LdRaidGet(ld, local_map_ptr); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1764 | if (!(raid->capability.fpNonRWCapable)) |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1765 | fp_possible = 0; |
| 1766 | } else |
| 1767 | fp_possible = 0; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1768 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1769 | if (!fp_possible) { |
| 1770 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
| 1771 | io_request->DevHandle = cpu_to_le16(device_id); |
| 1772 | io_request->LUN[1] = scmd->device->lun; |
| 1773 | pRAID_Context->timeoutValue = |
| 1774 | cpu_to_le16 (scmd->request->timeout / HZ); |
| 1775 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1776 | (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
| 1777 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1778 | } else { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1779 | |
| 1780 | /* set RAID context values */ |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1781 | pRAID_Context->configSeqNum = raid->seqNum; |
| 1782 | pRAID_Context->regLockFlags = REGION_TYPE_SHARED_READ; |
| 1783 | pRAID_Context->timeoutValue = cpu_to_le16(raid->fpIoTimeoutForLd); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1784 | |
| 1785 | /* get the DevHandle for the PD (since this is |
| 1786 | fpNonRWCapable, this is a single disk RAID0) */ |
| 1787 | span = physArm = 0; |
| 1788 | arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr); |
| 1789 | pd = MR_ArPdGet(arRef, physArm, local_map_ptr); |
| 1790 | devHandle = MR_PdDevHandleGet(pd, local_map_ptr); |
| 1791 | |
| 1792 | /* build request descriptor */ |
| 1793 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1794 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1795 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1796 | cmd->request_desc->SCSIIO.DevHandle = devHandle; |
| 1797 | |
| 1798 | /* populate the LUN field */ |
| 1799 | memcpy(io_request->LUN, raid->LUN, 8); |
| 1800 | |
| 1801 | /* build the raidScsiIO structure */ |
| 1802 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 1803 | io_request->DevHandle = devHandle; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1804 | } |
| 1805 | } |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1806 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1807 | /** |
| 1808 | * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd |
| 1809 | * @instance: Adapter soft state |
| 1810 | * @scp: SCSI command |
| 1811 | * @cmd: Command to be prepared |
| 1812 | * @fp_possible: parameter to detect fast path or firmware path io. |
| 1813 | * |
| 1814 | * Prepares the io_request frame for rw/non-rw io cmds for syspds |
| 1815 | */ |
| 1816 | static void |
| 1817 | megasas_build_syspd_fusion(struct megasas_instance *instance, |
| 1818 | struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd, u8 fp_possible) |
| 1819 | { |
| 1820 | u32 device_id; |
| 1821 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 1822 | u16 pd_index = 0; |
| 1823 | u16 os_timeout_value; |
| 1824 | u16 timeout_limit; |
| 1825 | struct MR_DRV_RAID_MAP_ALL *local_map_ptr; |
| 1826 | struct RAID_CONTEXT *pRAID_Context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 1827 | struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1828 | struct fusion_context *fusion = instance->ctrl_context; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 1829 | 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] | 1830 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1831 | device_id = MEGASAS_DEV_INDEX(scmd); |
| 1832 | pd_index = MEGASAS_PD_INDEX(scmd); |
| 1833 | os_timeout_value = scmd->request->timeout / HZ; |
| 1834 | |
| 1835 | io_request = cmd->io_request; |
| 1836 | /* get RAID_Context pointer */ |
| 1837 | pRAID_Context = &io_request->RaidContext; |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 1838 | pRAID_Context->regLockFlags = 0; |
| 1839 | pRAID_Context->regLockRowLBA = 0; |
| 1840 | pRAID_Context->regLockLength = 0; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1841 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
| 1842 | io_request->LUN[1] = scmd->device->lun; |
| 1843 | pRAID_Context->RAIDFlags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD |
| 1844 | << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT; |
| 1845 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 1846 | /* If FW supports PD sequence number */ |
| 1847 | if (instance->use_seqnum_jbod_fp && |
| 1848 | instance->pd_list[pd_index].driveType == TYPE_DISK) { |
| 1849 | /* TgtId must be incremented by 255 as jbod seq number is index |
| 1850 | * below raid map |
| 1851 | */ |
| 1852 | pRAID_Context->VirtualDiskTgtId = |
| 1853 | cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1)); |
| 1854 | pRAID_Context->configSeqNum = pd_sync->seq[pd_index].seqNum; |
| 1855 | io_request->DevHandle = pd_sync->seq[pd_index].devHandle; |
| 1856 | pRAID_Context->regLockFlags |= |
| 1857 | (MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA); |
| 1858 | } else if (fusion->fast_path_io) { |
| 1859 | pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id); |
| 1860 | pRAID_Context->configSeqNum = 0; |
| 1861 | local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)]; |
| 1862 | io_request->DevHandle = |
| 1863 | local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl; |
| 1864 | } else { |
| 1865 | /* Want to send all IO via FW path */ |
| 1866 | pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id); |
| 1867 | pRAID_Context->configSeqNum = 0; |
| 1868 | io_request->DevHandle = le16_to_cpu(0xFFFF); |
| 1869 | } |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1870 | |
| 1871 | cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle; |
| 1872 | cmd->request_desc->SCSIIO.MSIxIndex = |
| 1873 | instance->msix_vectors ? |
| 1874 | (raw_smp_processor_id() % instance->msix_vectors) : 0; |
| 1875 | |
| 1876 | |
| 1877 | if (!fp_possible) { |
| 1878 | /* system pd firmware path */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1879 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1880 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1881 | (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1882 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1883 | pRAID_Context->timeoutValue = cpu_to_le16(os_timeout_value); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 1884 | pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1885 | } else { |
| 1886 | /* system pd Fast Path */ |
| 1887 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1888 | timeout_limit = (scmd->device->type == TYPE_DISK) ? |
| 1889 | 255 : 0xFFFF; |
| 1890 | pRAID_Context->timeoutValue = |
| 1891 | cpu_to_le16((os_timeout_value > timeout_limit) ? |
| 1892 | timeout_limit : os_timeout_value); |
| 1893 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1894 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1895 | pRAID_Context->Type = MPI2_TYPE_CUDA; |
| 1896 | pRAID_Context->nseg = 0x1; |
| 1897 | io_request->IoFlags |= |
| 1898 | cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH); |
| 1899 | } |
| 1900 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1901 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << |
| 1902 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1903 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | /** |
| 1907 | * megasas_build_io_fusion - Prepares IOs to devices |
| 1908 | * @instance: Adapter soft state |
| 1909 | * @scp: SCSI command |
| 1910 | * @cmd: Command to be prepared |
| 1911 | * |
| 1912 | * Invokes helper functions to prepare request frames |
| 1913 | * and sets flags appropriate for IO/Non-IO cmd |
| 1914 | */ |
| 1915 | int |
| 1916 | megasas_build_io_fusion(struct megasas_instance *instance, |
| 1917 | struct scsi_cmnd *scp, |
| 1918 | struct megasas_cmd_fusion *cmd) |
| 1919 | { |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1920 | u16 sge_count; |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1921 | u8 cmd_type; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1922 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request; |
| 1923 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1924 | /* Zero out some fields so they don't get reused */ |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 1925 | memset(io_request->LUN, 0x0, 8); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1926 | io_request->CDB.EEDP32.PrimaryReferenceTag = 0; |
| 1927 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0; |
| 1928 | io_request->EEDPFlags = 0; |
| 1929 | io_request->Control = 0; |
| 1930 | io_request->EEDPBlockSize = 0; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1931 | io_request->ChainOffset = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1932 | io_request->RaidContext.RAIDFlags = 0; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1933 | io_request->RaidContext.Type = 0; |
| 1934 | io_request->RaidContext.nseg = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1935 | |
| 1936 | memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len); |
| 1937 | /* |
| 1938 | * Just the CDB length,rest of the Flags are zero |
| 1939 | * This will be modified for FP in build_ldio_fusion |
| 1940 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1941 | io_request->IoFlags = cpu_to_le16(scp->cmd_len); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1942 | |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1943 | switch (cmd_type = megasas_cmd_type(scp)) { |
| 1944 | case READ_WRITE_LDIO: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1945 | megasas_build_ldio_fusion(instance, scp, cmd); |
Sumit.Saxena@avagotech.com | 4a5c814 | 2015-04-23 16:30:39 +0530 | [diff] [blame] | 1946 | break; |
| 1947 | case NON_READ_WRITE_LDIO: |
| 1948 | megasas_build_ld_nonrw_fusion(instance, scp, cmd); |
| 1949 | break; |
| 1950 | case READ_WRITE_SYSPDIO: |
| 1951 | case NON_READ_WRITE_SYSPDIO: |
| 1952 | if (instance->secure_jbod_support && |
| 1953 | (cmd_type == NON_READ_WRITE_SYSPDIO)) |
| 1954 | megasas_build_syspd_fusion(instance, scp, cmd, 0); |
| 1955 | else |
| 1956 | megasas_build_syspd_fusion(instance, scp, cmd, 1); |
| 1957 | break; |
| 1958 | default: |
| 1959 | break; |
| 1960 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1961 | |
| 1962 | /* |
| 1963 | * Construct SGL |
| 1964 | */ |
| 1965 | |
| 1966 | sge_count = |
| 1967 | megasas_make_sgl_fusion(instance, scp, |
| 1968 | (struct MPI25_IEEE_SGE_CHAIN64 *) |
| 1969 | &io_request->SGL, cmd); |
| 1970 | |
| 1971 | if (sge_count > instance->max_num_sge) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 1972 | dev_err(&instance->pdev->dev, "Error. sge_count (0x%x) exceeds " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1973 | "max (0x%x) allowed\n", sge_count, |
| 1974 | instance->max_num_sge); |
| 1975 | return 1; |
| 1976 | } |
| 1977 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1978 | /* numSGE store lower 8 bit of sge_count. |
| 1979 | * numSGEExt store higher 8 bit of sge_count |
| 1980 | */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1981 | io_request->RaidContext.numSGE = sge_count; |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 1982 | io_request->RaidContext.numSGEExt = (u8)(sge_count >> 8); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1983 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1984 | io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1985 | |
| 1986 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1987 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1988 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1989 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1990 | |
| 1991 | io_request->SGLOffset0 = |
| 1992 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4; |
| 1993 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1994 | io_request->SenseBufferLowAddress = cpu_to_le32(cmd->sense_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1995 | io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 1996 | |
| 1997 | cmd->scmd = scp; |
| 1998 | scp->SCp.ptr = (char *)cmd; |
| 1999 | |
| 2000 | return 0; |
| 2001 | } |
| 2002 | |
| 2003 | union MEGASAS_REQUEST_DESCRIPTOR_UNION * |
| 2004 | megasas_get_request_descriptor(struct megasas_instance *instance, u16 index) |
| 2005 | { |
| 2006 | u8 *p; |
| 2007 | struct fusion_context *fusion; |
| 2008 | |
| 2009 | if (index >= instance->max_fw_cmds) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2010 | dev_err(&instance->pdev->dev, "Invalid SMID (0x%x)request for " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2011 | "descriptor for scsi%d\n", index, |
| 2012 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2013 | return NULL; |
| 2014 | } |
| 2015 | fusion = instance->ctrl_context; |
| 2016 | p = fusion->req_frames_desc |
| 2017 | +sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *index; |
| 2018 | |
| 2019 | return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p; |
| 2020 | } |
| 2021 | |
| 2022 | /** |
| 2023 | * megasas_build_and_issue_cmd_fusion -Main routine for building and |
| 2024 | * issuing non IOCTL cmd |
| 2025 | * @instance: Adapter soft state |
| 2026 | * @scmd: pointer to scsi cmd from OS |
| 2027 | */ |
| 2028 | static u32 |
| 2029 | megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, |
| 2030 | struct scsi_cmnd *scmd) |
| 2031 | { |
| 2032 | struct megasas_cmd_fusion *cmd; |
| 2033 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2034 | u32 index; |
| 2035 | struct fusion_context *fusion; |
| 2036 | |
| 2037 | fusion = instance->ctrl_context; |
| 2038 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2039 | cmd = megasas_get_cmd_fusion(instance, scmd->request->tag); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2040 | |
| 2041 | index = cmd->index; |
| 2042 | |
| 2043 | req_desc = megasas_get_request_descriptor(instance, index-1); |
| 2044 | if (!req_desc) |
| 2045 | return 1; |
| 2046 | |
| 2047 | req_desc->Words = 0; |
| 2048 | cmd->request_desc = req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2049 | |
| 2050 | if (megasas_build_io_fusion(instance, scmd, cmd)) { |
| 2051 | megasas_return_cmd_fusion(instance, cmd); |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2052 | dev_err(&instance->pdev->dev, "Error building command\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2053 | cmd->request_desc = NULL; |
| 2054 | return 1; |
| 2055 | } |
| 2056 | |
| 2057 | req_desc = cmd->request_desc; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2058 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2059 | |
| 2060 | if (cmd->io_request->ChainOffset != 0 && |
| 2061 | cmd->io_request->ChainOffset != 0xF) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2062 | dev_err(&instance->pdev->dev, "The chain offset value is not " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2063 | "correct : %x\n", cmd->io_request->ChainOffset); |
| 2064 | |
| 2065 | /* |
| 2066 | * Issue the command to the FW |
| 2067 | */ |
| 2068 | atomic_inc(&instance->fw_outstanding); |
| 2069 | |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 2070 | megasas_fire_cmd_fusion(instance, req_desc); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2071 | |
| 2072 | return 0; |
| 2073 | } |
| 2074 | |
| 2075 | /** |
| 2076 | * complete_cmd_fusion - Completes command |
| 2077 | * @instance: Adapter soft state |
| 2078 | * Completes all commands that is in reply descriptor queue |
| 2079 | */ |
| 2080 | int |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2081 | complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2082 | { |
| 2083 | union MPI2_REPLY_DESCRIPTORS_UNION *desc; |
| 2084 | struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc; |
| 2085 | struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req; |
| 2086 | struct fusion_context *fusion; |
| 2087 | struct megasas_cmd *cmd_mfi; |
| 2088 | struct megasas_cmd_fusion *cmd_fusion; |
| 2089 | u16 smid, num_completed; |
Sumit.Saxena@avagotech.com | d2552eb | 2014-09-12 18:57:53 +0530 | [diff] [blame] | 2090 | u8 reply_descript_type; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2091 | u32 status, extStatus, device_id; |
| 2092 | union desc_value d_val; |
| 2093 | struct LD_LOAD_BALANCE_INFO *lbinfo; |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 2094 | int threshold_reply_count = 0; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2095 | struct scsi_cmnd *scmd_local = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2096 | |
| 2097 | fusion = instance->ctrl_context; |
| 2098 | |
| 2099 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 2100 | return IRQ_HANDLED; |
| 2101 | |
| 2102 | desc = fusion->reply_frames_desc; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2103 | desc += ((MSIxIndex * fusion->reply_alloc_sz)/ |
| 2104 | sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)) + |
| 2105 | fusion->last_reply_idx[MSIxIndex]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2106 | |
| 2107 | reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; |
| 2108 | |
| 2109 | d_val.word = desc->Words; |
| 2110 | |
| 2111 | reply_descript_type = reply_desc->ReplyFlags & |
| 2112 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 2113 | |
| 2114 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 2115 | return IRQ_NONE; |
| 2116 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2117 | num_completed = 0; |
| 2118 | |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 2119 | while (d_val.u.low != cpu_to_le32(UINT_MAX) && |
| 2120 | d_val.u.high != cpu_to_le32(UINT_MAX)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2121 | smid = le16_to_cpu(reply_desc->SMID); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2122 | |
| 2123 | cmd_fusion = fusion->cmd_list[smid - 1]; |
| 2124 | |
| 2125 | scsi_io_req = |
| 2126 | (struct MPI2_RAID_SCSI_IO_REQUEST *) |
| 2127 | cmd_fusion->io_request; |
| 2128 | |
| 2129 | if (cmd_fusion->scmd) |
| 2130 | cmd_fusion->scmd->SCp.ptr = NULL; |
| 2131 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2132 | scmd_local = cmd_fusion->scmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2133 | status = scsi_io_req->RaidContext.status; |
| 2134 | extStatus = scsi_io_req->RaidContext.exStatus; |
| 2135 | |
| 2136 | switch (scsi_io_req->Function) { |
| 2137 | case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/ |
| 2138 | /* Update load balancing info */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2139 | device_id = MEGASAS_DEV_INDEX(scmd_local); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2140 | lbinfo = &fusion->load_balance_info[device_id]; |
| 2141 | if (cmd_fusion->scmd->SCp.Status & |
| 2142 | MEGASAS_LOAD_BALANCE_FLAG) { |
Sumit.Saxena@avagotech.com | d2552eb | 2014-09-12 18:57:53 +0530 | [diff] [blame] | 2143 | atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2144 | cmd_fusion->scmd->SCp.Status &= |
| 2145 | ~MEGASAS_LOAD_BALANCE_FLAG; |
| 2146 | } |
| 2147 | if (reply_descript_type == |
| 2148 | MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) { |
| 2149 | if (megasas_dbg_lvl == 5) |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2150 | dev_err(&instance->pdev->dev, "\nFAST Path " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2151 | "IO Success\n"); |
| 2152 | } |
| 2153 | /* Fall thru and complete IO */ |
| 2154 | case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */ |
| 2155 | /* Map the FW Cmd Status */ |
| 2156 | map_cmd_status(cmd_fusion, status, extStatus); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2157 | scsi_io_req->RaidContext.status = 0; |
| 2158 | scsi_io_req->RaidContext.exStatus = 0; |
| 2159 | megasas_return_cmd_fusion(instance, cmd_fusion); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2160 | scsi_dma_unmap(scmd_local); |
| 2161 | scmd_local->scsi_done(scmd_local); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2162 | atomic_dec(&instance->fw_outstanding); |
| 2163 | |
| 2164 | break; |
| 2165 | case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */ |
| 2166 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2167 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2168 | /* Poll mode. Dummy free. |
| 2169 | * In case of Interrupt mode, caller has reverse check. |
| 2170 | */ |
| 2171 | if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) { |
| 2172 | cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE; |
| 2173 | megasas_return_cmd(instance, cmd_mfi); |
| 2174 | } else |
| 2175 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2176 | break; |
| 2177 | } |
| 2178 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2179 | fusion->last_reply_idx[MSIxIndex]++; |
| 2180 | if (fusion->last_reply_idx[MSIxIndex] >= |
| 2181 | fusion->reply_q_depth) |
| 2182 | fusion->last_reply_idx[MSIxIndex] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2183 | |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 2184 | desc->Words = cpu_to_le64(ULLONG_MAX); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2185 | num_completed++; |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 2186 | threshold_reply_count++; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2187 | |
| 2188 | /* Get the next reply descriptor */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2189 | if (!fusion->last_reply_idx[MSIxIndex]) |
| 2190 | desc = fusion->reply_frames_desc + |
| 2191 | ((MSIxIndex * fusion->reply_alloc_sz)/ |
| 2192 | sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2193 | else |
| 2194 | desc++; |
| 2195 | |
| 2196 | reply_desc = |
| 2197 | (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; |
| 2198 | |
| 2199 | d_val.word = desc->Words; |
| 2200 | |
| 2201 | reply_descript_type = reply_desc->ReplyFlags & |
| 2202 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 2203 | |
| 2204 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 2205 | break; |
Sumit.Saxena@avagotech.com | db4fc86 | 2014-09-12 18:57:23 +0530 | [diff] [blame] | 2206 | /* |
| 2207 | * Write to reply post host index register after completing threshold |
| 2208 | * number of reply counts and still there are more replies in reply queue |
| 2209 | * pending to be completed |
| 2210 | */ |
| 2211 | if (threshold_reply_count >= THRESHOLD_REPLY_COUNT) { |
| 2212 | if ((instance->pdev->device == |
| 2213 | PCI_DEVICE_ID_LSI_INVADER) || |
| 2214 | (instance->pdev->device == |
| 2215 | PCI_DEVICE_ID_LSI_FURY)) |
| 2216 | writel(((MSIxIndex & 0x7) << 24) | |
| 2217 | fusion->last_reply_idx[MSIxIndex], |
| 2218 | instance->reply_post_host_index_addr[MSIxIndex/8]); |
| 2219 | else |
| 2220 | writel((MSIxIndex << 24) | |
| 2221 | fusion->last_reply_idx[MSIxIndex], |
| 2222 | instance->reply_post_host_index_addr[0]); |
| 2223 | threshold_reply_count = 0; |
| 2224 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | if (!num_completed) |
| 2228 | return IRQ_NONE; |
| 2229 | |
| 2230 | wmb(); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2231 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 2232 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
| 2233 | writel(((MSIxIndex & 0x7) << 24) | |
| 2234 | fusion->last_reply_idx[MSIxIndex], |
| 2235 | instance->reply_post_host_index_addr[MSIxIndex/8]); |
| 2236 | else |
| 2237 | writel((MSIxIndex << 24) | |
| 2238 | fusion->last_reply_idx[MSIxIndex], |
| 2239 | instance->reply_post_host_index_addr[0]); |
adam radford | 53ef2bb | 2011-02-24 20:56:05 -0800 | [diff] [blame] | 2240 | megasas_check_and_restore_queue_depth(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2241 | return IRQ_HANDLED; |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * megasas_complete_cmd_dpc_fusion - Completes command |
| 2246 | * @instance: Adapter soft state |
| 2247 | * |
| 2248 | * Tasklet to complete cmds |
| 2249 | */ |
| 2250 | void |
| 2251 | megasas_complete_cmd_dpc_fusion(unsigned long instance_addr) |
| 2252 | { |
| 2253 | struct megasas_instance *instance = |
| 2254 | (struct megasas_instance *)instance_addr; |
| 2255 | unsigned long flags; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2256 | u32 count, MSIxIndex; |
| 2257 | |
| 2258 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2259 | |
| 2260 | /* If we have already declared adapter dead, donot complete cmds */ |
| 2261 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2262 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 2263 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2264 | return; |
| 2265 | } |
| 2266 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2267 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2268 | for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++) |
| 2269 | complete_cmd_fusion(instance, MSIxIndex); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * megasas_isr_fusion - isr entry point |
| 2274 | */ |
| 2275 | irqreturn_t megasas_isr_fusion(int irq, void *devp) |
| 2276 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2277 | struct megasas_irq_context *irq_context = devp; |
| 2278 | struct megasas_instance *instance = irq_context->instance; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2279 | u32 mfiStatus, fw_state, dma_state; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2280 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2281 | if (instance->mask_interrupts) |
| 2282 | return IRQ_NONE; |
| 2283 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2284 | if (!instance->msix_vectors) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2285 | mfiStatus = instance->instancet->clear_intr(instance->reg_set); |
| 2286 | if (!mfiStatus) |
| 2287 | return IRQ_NONE; |
| 2288 | } |
| 2289 | |
| 2290 | /* If we are resetting, bail */ |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 2291 | if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) { |
| 2292 | instance->instancet->clear_intr(instance->reg_set); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2293 | return IRQ_HANDLED; |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 2294 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2295 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2296 | if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) { |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 2297 | instance->instancet->clear_intr(instance->reg_set); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2298 | /* If we didn't complete any commands, check for FW fault */ |
| 2299 | fw_state = instance->instancet->read_fw_status_reg( |
| 2300 | instance->reg_set) & MFI_STATE_MASK; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2301 | dma_state = instance->instancet->read_fw_status_reg |
| 2302 | (instance->reg_set) & MFI_STATE_DMADONE; |
| 2303 | if (instance->crash_dump_drv_support && |
| 2304 | instance->crash_dump_app_support) { |
| 2305 | /* Start collecting crash, if DMA bit is done */ |
| 2306 | if ((fw_state == MFI_STATE_FAULT) && dma_state) |
| 2307 | schedule_work(&instance->crash_init); |
| 2308 | else if (fw_state == MFI_STATE_FAULT) |
| 2309 | schedule_work(&instance->work_init); |
| 2310 | } else if (fw_state == MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2311 | dev_warn(&instance->pdev->dev, "Iop2SysDoorbellInt" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2312 | "for scsi%d\n", instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2313 | schedule_work(&instance->work_init); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2314 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | return IRQ_HANDLED; |
| 2318 | } |
| 2319 | |
| 2320 | /** |
| 2321 | * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru |
| 2322 | * @instance: Adapter soft state |
| 2323 | * mfi_cmd: megasas_cmd pointer |
| 2324 | * |
| 2325 | */ |
| 2326 | u8 |
| 2327 | build_mpt_mfi_pass_thru(struct megasas_instance *instance, |
| 2328 | struct megasas_cmd *mfi_cmd) |
| 2329 | { |
| 2330 | struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain; |
| 2331 | struct MPI2_RAID_SCSI_IO_REQUEST *io_req; |
| 2332 | struct megasas_cmd_fusion *cmd; |
| 2333 | struct fusion_context *fusion; |
| 2334 | struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr; |
| 2335 | |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2336 | fusion = instance->ctrl_context; |
| 2337 | |
| 2338 | cmd = megasas_get_cmd_fusion(instance, |
| 2339 | instance->max_scsi_cmds + mfi_cmd->index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2340 | |
| 2341 | /* Save the smid. To be used for returning the cmd */ |
| 2342 | mfi_cmd->context.smid = cmd->index; |
Sumit.Saxena@avagotech.com | 90dc9d9 | 2014-09-12 18:57:58 +0530 | [diff] [blame] | 2343 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2344 | /* |
| 2345 | * For cmds where the flag is set, store the flag and check |
| 2346 | * on completion. For cmds with this flag, don't call |
| 2347 | * megasas_complete_cmd |
| 2348 | */ |
| 2349 | |
Sumit.Saxena@avagotech.com | 6e755dd | 2014-11-17 15:24:28 +0530 | [diff] [blame] | 2350 | 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] | 2351 | mfi_cmd->flags |= DRV_DCMD_POLLED_MODE; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2352 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2353 | io_req = cmd->io_request; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2354 | |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2355 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 2356 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2357 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = |
| 2358 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL; |
| 2359 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; |
| 2360 | sgl_ptr_end->Flags = 0; |
| 2361 | } |
| 2362 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2363 | mpi25_ieee_chain = |
| 2364 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain; |
| 2365 | |
| 2366 | io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST; |
| 2367 | io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, |
| 2368 | SGL) / 4; |
| 2369 | io_req->ChainOffset = fusion->chain_offset_mfi_pthru; |
| 2370 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2371 | mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2372 | |
| 2373 | mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 2374 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR; |
| 2375 | |
sumit.saxena@avagotech.com | bd5f948 | 2015-08-31 17:23:31 +0530 | [diff] [blame^] | 2376 | mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2377 | |
| 2378 | return 0; |
| 2379 | } |
| 2380 | |
| 2381 | /** |
| 2382 | * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd |
| 2383 | * @instance: Adapter soft state |
| 2384 | * @cmd: mfi cmd to build |
| 2385 | * |
| 2386 | */ |
| 2387 | union MEGASAS_REQUEST_DESCRIPTOR_UNION * |
| 2388 | build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2389 | { |
| 2390 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2391 | u16 index; |
| 2392 | |
| 2393 | if (build_mpt_mfi_pass_thru(instance, cmd)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2394 | 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] | 2395 | return NULL; |
| 2396 | } |
| 2397 | |
| 2398 | index = cmd->context.smid; |
| 2399 | |
| 2400 | req_desc = megasas_get_request_descriptor(instance, index - 1); |
| 2401 | |
| 2402 | if (!req_desc) |
| 2403 | return NULL; |
| 2404 | |
| 2405 | req_desc->Words = 0; |
| 2406 | req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
| 2407 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 2408 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2409 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2410 | |
| 2411 | return req_desc; |
| 2412 | } |
| 2413 | |
| 2414 | /** |
| 2415 | * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd |
| 2416 | * @instance: Adapter soft state |
| 2417 | * @cmd: mfi cmd pointer |
| 2418 | * |
| 2419 | */ |
| 2420 | void |
| 2421 | megasas_issue_dcmd_fusion(struct megasas_instance *instance, |
| 2422 | struct megasas_cmd *cmd) |
| 2423 | { |
| 2424 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2425 | |
| 2426 | req_desc = build_mpt_cmd(instance, cmd); |
| 2427 | if (!req_desc) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2428 | dev_err(&instance->pdev->dev, "Couldn't issue MFI pass thru cmd\n"); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2429 | return; |
| 2430 | } |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 2431 | megasas_fire_cmd_fusion(instance, req_desc); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | /** |
| 2435 | * megasas_release_fusion - Reverses the FW initialization |
Geert Uytterhoeven | 4b63b28 | 2015-03-03 11:58:07 +0100 | [diff] [blame] | 2436 | * @instance: Adapter soft state |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2437 | */ |
| 2438 | void |
| 2439 | megasas_release_fusion(struct megasas_instance *instance) |
| 2440 | { |
| 2441 | megasas_free_cmds(instance); |
| 2442 | megasas_free_cmds_fusion(instance); |
| 2443 | |
| 2444 | iounmap(instance->reg_set); |
| 2445 | |
| 2446 | pci_release_selected_regions(instance->pdev, instance->bar); |
| 2447 | } |
| 2448 | |
| 2449 | /** |
| 2450 | * megasas_read_fw_status_reg_fusion - returns the current FW status value |
| 2451 | * @regs: MFI register set |
| 2452 | */ |
| 2453 | static u32 |
| 2454 | megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs) |
| 2455 | { |
| 2456 | return readl(&(regs)->outbound_scratch_pad); |
| 2457 | } |
| 2458 | |
| 2459 | /** |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2460 | * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware |
| 2461 | * @instance: Controller's soft instance |
| 2462 | * return: Number of allocated host crash buffers |
| 2463 | */ |
| 2464 | static void |
| 2465 | megasas_alloc_host_crash_buffer(struct megasas_instance *instance) |
| 2466 | { |
| 2467 | unsigned int i; |
| 2468 | |
| 2469 | instance->crash_buf_pages = get_order(CRASH_DMA_BUF_SIZE); |
| 2470 | for (i = 0; i < MAX_CRASH_DUMP_SIZE; i++) { |
| 2471 | instance->crash_buf[i] = (void *)__get_free_pages(GFP_KERNEL, |
| 2472 | instance->crash_buf_pages); |
| 2473 | if (!instance->crash_buf[i]) { |
| 2474 | dev_info(&instance->pdev->dev, "Firmware crash dump " |
| 2475 | "memory allocation failed at index %d\n", i); |
| 2476 | break; |
| 2477 | } |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 2478 | memset(instance->crash_buf[i], 0, |
| 2479 | ((1 << PAGE_SHIFT) << instance->crash_buf_pages)); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2480 | } |
| 2481 | instance->drv_buf_alloc = i; |
| 2482 | } |
| 2483 | |
| 2484 | /** |
| 2485 | * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware |
| 2486 | * @instance: Controller's soft instance |
| 2487 | */ |
| 2488 | void |
| 2489 | megasas_free_host_crash_buffer(struct megasas_instance *instance) |
| 2490 | { |
| 2491 | unsigned int i |
| 2492 | ; |
| 2493 | for (i = 0; i < instance->drv_buf_alloc; i++) { |
| 2494 | if (instance->crash_buf[i]) |
| 2495 | free_pages((ulong)instance->crash_buf[i], |
| 2496 | instance->crash_buf_pages); |
| 2497 | } |
| 2498 | instance->drv_buf_index = 0; |
| 2499 | instance->drv_buf_alloc = 0; |
| 2500 | instance->fw_crash_state = UNAVAILABLE; |
| 2501 | instance->fw_crash_buffer_size = 0; |
| 2502 | } |
| 2503 | |
| 2504 | /** |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2505 | * megasas_adp_reset_fusion - For controller reset |
| 2506 | * @regs: MFI register set |
| 2507 | */ |
| 2508 | static int |
| 2509 | megasas_adp_reset_fusion(struct megasas_instance *instance, |
| 2510 | struct megasas_register_set __iomem *regs) |
| 2511 | { |
| 2512 | return 0; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
| 2516 | * megasas_check_reset_fusion - For controller reset check |
| 2517 | * @regs: MFI register set |
| 2518 | */ |
| 2519 | static int |
| 2520 | megasas_check_reset_fusion(struct megasas_instance *instance, |
| 2521 | struct megasas_register_set __iomem *regs) |
| 2522 | { |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
| 2526 | /* This function waits for outstanding commands on fusion to complete */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2527 | int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance, |
| 2528 | int iotimeout, int *convert) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2529 | { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2530 | int i, outstanding, retval = 0, hb_seconds_missed = 0; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2531 | u32 fw_state; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2532 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2533 | for (i = 0; i < resetwaittime; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2534 | /* Check if firmware is in fault state */ |
| 2535 | fw_state = instance->instancet->read_fw_status_reg( |
| 2536 | instance->reg_set) & MFI_STATE_MASK; |
| 2537 | if (fw_state == MFI_STATE_FAULT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2538 | dev_warn(&instance->pdev->dev, "Found FW in FAULT state," |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2539 | " will reset adapter scsi%d.\n", |
| 2540 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2541 | retval = 1; |
| 2542 | goto out; |
| 2543 | } |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2544 | /* If SR-IOV VF mode & heartbeat timeout, don't wait */ |
| 2545 | if (instance->requestorId && !iotimeout) { |
| 2546 | retval = 1; |
| 2547 | goto out; |
| 2548 | } |
| 2549 | |
| 2550 | /* If SR-IOV VF mode & I/O timeout, check for HB timeout */ |
| 2551 | if (instance->requestorId && iotimeout) { |
| 2552 | if (instance->hb_host_mem->HB.fwCounter != |
| 2553 | instance->hb_host_mem->HB.driverCounter) { |
| 2554 | instance->hb_host_mem->HB.driverCounter = |
| 2555 | instance->hb_host_mem->HB.fwCounter; |
| 2556 | hb_seconds_missed = 0; |
| 2557 | } else { |
| 2558 | hb_seconds_missed++; |
| 2559 | if (hb_seconds_missed == |
| 2560 | (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF/HZ)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2561 | dev_warn(&instance->pdev->dev, "SR-IOV:" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2562 | " Heartbeat never completed " |
| 2563 | " while polling during I/O " |
| 2564 | " timeout handling for " |
| 2565 | "scsi%d.\n", |
| 2566 | instance->host->host_no); |
| 2567 | *convert = 1; |
| 2568 | retval = 1; |
| 2569 | goto out; |
| 2570 | } |
| 2571 | } |
| 2572 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2573 | |
| 2574 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2575 | if (!outstanding) |
| 2576 | goto out; |
| 2577 | |
| 2578 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2579 | dev_notice(&instance->pdev->dev, "[%2d]waiting for %d " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2580 | "commands to complete for scsi%d\n", i, |
| 2581 | outstanding, instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2582 | megasas_complete_cmd_dpc_fusion( |
| 2583 | (unsigned long)instance); |
| 2584 | } |
| 2585 | msleep(1000); |
| 2586 | } |
| 2587 | |
| 2588 | if (atomic_read(&instance->fw_outstanding)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2589 | dev_err(&instance->pdev->dev, "pending commands remain after waiting, " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2590 | "will reset adapter scsi%d.\n", |
| 2591 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2592 | retval = 1; |
| 2593 | } |
| 2594 | out: |
| 2595 | return retval; |
| 2596 | } |
| 2597 | |
| 2598 | void megasas_reset_reply_desc(struct megasas_instance *instance) |
| 2599 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2600 | int i, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2601 | struct fusion_context *fusion; |
| 2602 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; |
| 2603 | |
| 2604 | fusion = instance->ctrl_context; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2605 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 2606 | for (i = 0 ; i < count ; i++) |
| 2607 | fusion->last_reply_idx[i] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2608 | reply_desc = fusion->reply_frames_desc; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2609 | for (i = 0 ; i < fusion->reply_q_depth * count; i++, reply_desc++) |
Christoph Hellwig | c6f5bf8 | 2015-04-23 16:33:09 +0530 | [diff] [blame] | 2610 | reply_desc->Words = cpu_to_le64(ULLONG_MAX); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2611 | } |
| 2612 | |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 2613 | /* |
| 2614 | * megasas_refire_mgmt_cmd : Re-fire management commands |
| 2615 | * @instance: Controller's soft instance |
| 2616 | */ |
| 2617 | void megasas_refire_mgmt_cmd(struct megasas_instance *instance) |
| 2618 | { |
| 2619 | int j; |
| 2620 | struct megasas_cmd_fusion *cmd_fusion; |
| 2621 | struct fusion_context *fusion; |
| 2622 | struct megasas_cmd *cmd_mfi; |
| 2623 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2624 | u16 smid; |
| 2625 | |
| 2626 | fusion = instance->ctrl_context; |
| 2627 | |
| 2628 | /* Re-fire management commands. |
| 2629 | * Do not traverse complet MPT frame pool. Start from max_scsi_cmds. |
| 2630 | */ |
| 2631 | for (j = instance->max_scsi_cmds ; j < instance->max_fw_cmds; j++) { |
| 2632 | cmd_fusion = fusion->cmd_list[j]; |
| 2633 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 2634 | smid = le16_to_cpu(cmd_mfi->context.smid); |
| 2635 | |
| 2636 | if (!smid) |
| 2637 | continue; |
| 2638 | req_desc = megasas_get_request_descriptor |
| 2639 | (instance, smid - 1); |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2640 | if (req_desc && ((cmd_mfi->frame->dcmd.opcode != |
| 2641 | cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO)) && |
| 2642 | (cmd_mfi->frame->dcmd.opcode != |
| 2643 | cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO)))) |
Christoph Hellwig | 01d7f03 | 2015-04-23 16:34:09 +0530 | [diff] [blame] | 2644 | megasas_fire_cmd_fusion(instance, req_desc); |
| 2645 | else |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 2646 | megasas_return_cmd(instance, cmd_mfi); |
| 2647 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2648 | } |
| 2649 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2650 | /* Check for a second path that is currently UP */ |
| 2651 | int megasas_check_mpio_paths(struct megasas_instance *instance, |
| 2652 | struct scsi_cmnd *scmd) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2653 | { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2654 | int i, j, retval = (DID_RESET << 16); |
| 2655 | |
| 2656 | if (instance->mpio && instance->requestorId) { |
| 2657 | for (i = 0 ; i < MAX_MGMT_ADAPTERS ; i++) |
| 2658 | for (j = 0 ; j < MAX_LOGICAL_DRIVES; j++) |
| 2659 | if (megasas_mgmt_info.instance[i] && |
| 2660 | (megasas_mgmt_info.instance[i] != instance) && |
| 2661 | megasas_mgmt_info.instance[i]->mpio && |
| 2662 | megasas_mgmt_info.instance[i]->requestorId |
| 2663 | && |
| 2664 | (megasas_mgmt_info.instance[i]->ld_ids[j] |
| 2665 | == scmd->device->id)) { |
| 2666 | retval = (DID_NO_CONNECT << 16); |
| 2667 | goto out; |
| 2668 | } |
| 2669 | } |
| 2670 | out: |
| 2671 | return retval; |
| 2672 | } |
| 2673 | |
| 2674 | /* Core fusion reset function */ |
| 2675 | int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout) |
| 2676 | { |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 2677 | int retval = SUCCESS, i, retry = 0, convert = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2678 | struct megasas_instance *instance; |
| 2679 | struct megasas_cmd_fusion *cmd_fusion; |
| 2680 | struct fusion_context *fusion; |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2681 | u32 host_diag, abs_state, status_reg, reset_adapter; |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2682 | u32 io_timeout_in_crash_mode = 0; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2683 | struct scsi_cmnd *scmd_local = NULL; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2684 | |
| 2685 | instance = (struct megasas_instance *)shost->hostdata; |
| 2686 | fusion = instance->ctrl_context; |
| 2687 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2688 | mutex_lock(&instance->reset_mutex); |
| 2689 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2690 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2691 | dev_warn(&instance->pdev->dev, "Hardware critical error, " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2692 | "returning FAILED for scsi%d.\n", |
| 2693 | instance->host->host_no); |
Adam Radford | a2fbcbc | 2014-07-09 15:17:54 -0700 | [diff] [blame] | 2694 | mutex_unlock(&instance->reset_mutex); |
adam radford | d4a759a | 2011-10-08 18:14:39 -0700 | [diff] [blame] | 2695 | return FAILED; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2696 | } |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2697 | status_reg = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 2698 | abs_state = status_reg & MFI_STATE_MASK; |
| 2699 | |
| 2700 | /* IO timeout detected, forcibly put FW in FAULT state */ |
| 2701 | if (abs_state != MFI_STATE_FAULT && instance->crash_dump_buf && |
| 2702 | instance->crash_dump_app_support && iotimeout) { |
| 2703 | dev_info(&instance->pdev->dev, "IO timeout is detected, " |
| 2704 | "forcibly FAULT Firmware\n"); |
| 2705 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
| 2706 | status_reg = readl(&instance->reg_set->doorbell); |
| 2707 | writel(status_reg | MFI_STATE_FORCE_OCR, |
| 2708 | &instance->reg_set->doorbell); |
| 2709 | readl(&instance->reg_set->doorbell); |
| 2710 | mutex_unlock(&instance->reset_mutex); |
| 2711 | do { |
| 2712 | ssleep(3); |
| 2713 | io_timeout_in_crash_mode++; |
| 2714 | dev_dbg(&instance->pdev->dev, "waiting for [%d] " |
| 2715 | "seconds for crash dump collection and OCR " |
| 2716 | "to be done\n", (io_timeout_in_crash_mode * 3)); |
| 2717 | } while ((instance->adprecovery != MEGASAS_HBA_OPERATIONAL) && |
| 2718 | (io_timeout_in_crash_mode < 80)); |
| 2719 | |
| 2720 | if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) { |
| 2721 | dev_info(&instance->pdev->dev, "OCR done for IO " |
| 2722 | "timeout case\n"); |
| 2723 | retval = SUCCESS; |
| 2724 | } else { |
| 2725 | dev_info(&instance->pdev->dev, "Controller is not " |
| 2726 | "operational after 240 seconds wait for IO " |
| 2727 | "timeout case in FW crash dump mode\n do " |
| 2728 | "OCR/kill adapter\n"); |
| 2729 | retval = megasas_reset_fusion(shost, 0); |
| 2730 | } |
| 2731 | return retval; |
| 2732 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2733 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2734 | if (instance->requestorId && !instance->skip_heartbeat_timer_del) |
| 2735 | del_timer_sync(&instance->sriov_heartbeat_timer); |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2736 | set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2737 | instance->adprecovery = MEGASAS_ADPRESET_SM_POLLING; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2738 | instance->instancet->disable_intr(instance); |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2739 | msleep(1000); |
| 2740 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2741 | /* First try waiting for commands to complete */ |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2742 | if (megasas_wait_for_outstanding_fusion(instance, iotimeout, |
| 2743 | &convert)) { |
| 2744 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2745 | dev_warn(&instance->pdev->dev, "resetting fusion " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2746 | "adapter scsi%d.\n", instance->host->host_no); |
| 2747 | if (convert) |
| 2748 | iotimeout = 0; |
| 2749 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2750 | /* Now return commands back to the OS */ |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2751 | for (i = 0 ; i < instance->max_scsi_cmds; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2752 | cmd_fusion = fusion->cmd_list[i]; |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2753 | scmd_local = cmd_fusion->scmd; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2754 | if (cmd_fusion->scmd) { |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2755 | scmd_local->result = |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2756 | megasas_check_mpio_paths(instance, |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2757 | scmd_local); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2758 | megasas_return_cmd_fusion(instance, cmd_fusion); |
Sumit.Saxena@avagotech.com | 4026e9a | 2015-04-23 16:31:24 +0530 | [diff] [blame] | 2759 | scsi_dma_unmap(scmd_local); |
| 2760 | scmd_local->scsi_done(scmd_local); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2761 | atomic_dec(&instance->fw_outstanding); |
| 2762 | } |
| 2763 | } |
| 2764 | |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2765 | status_reg = instance->instancet->read_fw_status_reg( |
| 2766 | instance->reg_set); |
| 2767 | abs_state = status_reg & MFI_STATE_MASK; |
| 2768 | reset_adapter = status_reg & MFI_RESET_ADAPTER; |
| 2769 | if (instance->disableOnlineCtrlReset || |
| 2770 | (abs_state == MFI_STATE_FAULT && !reset_adapter)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2771 | /* Reset not supported, kill adapter */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2772 | dev_warn(&instance->pdev->dev, "Reset not supported" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2773 | ", killing adapter scsi%d.\n", |
| 2774 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2775 | megaraid_sas_kill_hba(instance); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2776 | instance->skip_heartbeat_timer_del = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2777 | retval = FAILED; |
| 2778 | goto out; |
| 2779 | } |
| 2780 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2781 | /* Let SR-IOV VF & PF sync up if there was a HB failure */ |
| 2782 | if (instance->requestorId && !iotimeout) { |
| 2783 | msleep(MEGASAS_OCR_SETTLE_TIME_VF); |
| 2784 | /* Look for a late HB update after VF settle time */ |
| 2785 | if (abs_state == MFI_STATE_OPERATIONAL && |
| 2786 | (instance->hb_host_mem->HB.fwCounter != |
| 2787 | instance->hb_host_mem->HB.driverCounter)) { |
| 2788 | instance->hb_host_mem->HB.driverCounter = |
| 2789 | instance->hb_host_mem->HB.fwCounter; |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2790 | dev_warn(&instance->pdev->dev, "SR-IOV:" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2791 | "Late FW heartbeat update for " |
| 2792 | "scsi%d.\n", |
| 2793 | instance->host->host_no); |
| 2794 | } else { |
| 2795 | /* In VF mode, first poll for FW ready */ |
| 2796 | for (i = 0; |
| 2797 | i < (MEGASAS_RESET_WAIT_TIME * 1000); |
| 2798 | i += 20) { |
| 2799 | status_reg = |
| 2800 | instance->instancet-> |
| 2801 | read_fw_status_reg( |
| 2802 | instance->reg_set); |
| 2803 | abs_state = status_reg & |
| 2804 | MFI_STATE_MASK; |
| 2805 | if (abs_state == MFI_STATE_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2806 | dev_warn(&instance->pdev->dev, |
| 2807 | "SR-IOV: FW was found" |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2808 | "to be in ready state " |
| 2809 | "for scsi%d.\n", |
| 2810 | instance->host->host_no); |
| 2811 | break; |
| 2812 | } |
| 2813 | msleep(20); |
| 2814 | } |
| 2815 | if (abs_state != MFI_STATE_READY) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2816 | dev_warn(&instance->pdev->dev, "SR-IOV: " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2817 | "FW not in ready state after %d" |
| 2818 | " seconds for scsi%d, status_reg = " |
| 2819 | "0x%x.\n", |
| 2820 | MEGASAS_RESET_WAIT_TIME, |
| 2821 | instance->host->host_no, |
| 2822 | status_reg); |
| 2823 | megaraid_sas_kill_hba(instance); |
| 2824 | instance->skip_heartbeat_timer_del = 1; |
| 2825 | instance->adprecovery = |
| 2826 | MEGASAS_HW_CRITICAL_ERROR; |
| 2827 | retval = FAILED; |
| 2828 | goto out; |
| 2829 | } |
| 2830 | } |
| 2831 | } |
| 2832 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2833 | /* Now try to reset the chip */ |
| 2834 | for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) { |
| 2835 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, |
| 2836 | &instance->reg_set->fusion_seq_offset); |
| 2837 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, |
| 2838 | &instance->reg_set->fusion_seq_offset); |
| 2839 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, |
| 2840 | &instance->reg_set->fusion_seq_offset); |
| 2841 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, |
| 2842 | &instance->reg_set->fusion_seq_offset); |
| 2843 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, |
| 2844 | &instance->reg_set->fusion_seq_offset); |
| 2845 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, |
| 2846 | &instance->reg_set->fusion_seq_offset); |
| 2847 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, |
| 2848 | &instance->reg_set->fusion_seq_offset); |
| 2849 | |
| 2850 | /* Check that the diag write enable (DRWE) bit is on */ |
| 2851 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2852 | retry = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2853 | while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) { |
| 2854 | msleep(100); |
| 2855 | host_diag = |
| 2856 | readl(&instance->reg_set->fusion_host_diag); |
| 2857 | if (retry++ == 100) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2858 | dev_warn(&instance->pdev->dev, |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2859 | "Host diag unlock failed! " |
| 2860 | "for scsi%d\n", |
| 2861 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2862 | break; |
| 2863 | } |
| 2864 | } |
| 2865 | if (!(host_diag & HOST_DIAG_WRITE_ENABLE)) |
| 2866 | continue; |
| 2867 | |
| 2868 | /* Send chip reset command */ |
| 2869 | writel(host_diag | HOST_DIAG_RESET_ADAPTER, |
| 2870 | &instance->reg_set->fusion_host_diag); |
| 2871 | msleep(3000); |
| 2872 | |
| 2873 | /* Make sure reset adapter bit is cleared */ |
| 2874 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
| 2875 | retry = 0; |
| 2876 | while (host_diag & HOST_DIAG_RESET_ADAPTER) { |
| 2877 | msleep(100); |
| 2878 | host_diag = |
| 2879 | readl(&instance->reg_set->fusion_host_diag); |
| 2880 | if (retry++ == 1000) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2881 | dev_warn(&instance->pdev->dev, |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2882 | "Diag reset adapter never " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2883 | "cleared for scsi%d!\n", |
| 2884 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2885 | break; |
| 2886 | } |
| 2887 | } |
| 2888 | if (host_diag & HOST_DIAG_RESET_ADAPTER) |
| 2889 | continue; |
| 2890 | |
| 2891 | abs_state = |
| 2892 | instance->instancet->read_fw_status_reg( |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2893 | instance->reg_set) & MFI_STATE_MASK; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2894 | retry = 0; |
| 2895 | |
| 2896 | while ((abs_state <= MFI_STATE_FW_INIT) && |
| 2897 | (retry++ < 1000)) { |
| 2898 | msleep(100); |
| 2899 | abs_state = |
| 2900 | instance->instancet->read_fw_status_reg( |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2901 | instance->reg_set) & MFI_STATE_MASK; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2902 | } |
| 2903 | if (abs_state <= MFI_STATE_FW_INIT) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2904 | dev_warn(&instance->pdev->dev, "firmware " |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2905 | "state < MFI_STATE_FW_INIT, state = " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2906 | "0x%x for scsi%d\n", abs_state, |
| 2907 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2908 | continue; |
| 2909 | } |
| 2910 | |
| 2911 | /* Wait for FW to become ready */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 2912 | if (megasas_transition_to_ready(instance, 1)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2913 | dev_warn(&instance->pdev->dev, "Failed to " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2914 | "transition controller to ready " |
| 2915 | "for scsi%d.\n", |
| 2916 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2917 | continue; |
| 2918 | } |
| 2919 | |
| 2920 | megasas_reset_reply_desc(instance); |
| 2921 | if (megasas_ioc_init_fusion(instance)) { |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2922 | dev_warn(&instance->pdev->dev, |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2923 | "megasas_ioc_init_fusion() failed!" |
| 2924 | " for scsi%d\n", |
| 2925 | instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2926 | continue; |
| 2927 | } |
| 2928 | |
Sumit.Saxena@avagotech.com | 9b82818 | 2015-04-23 16:30:24 +0530 | [diff] [blame] | 2929 | megasas_refire_mgmt_cmd(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2930 | |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 2931 | if (megasas_get_ctrl_info(instance)) { |
| 2932 | dev_info(&instance->pdev->dev, |
| 2933 | "Failed from %s %d\n", |
| 2934 | __func__, __LINE__); |
Sumit.Saxena@avagotech.com | d009b57 | 2014-11-17 15:24:13 +0530 | [diff] [blame] | 2935 | megaraid_sas_kill_hba(instance); |
| 2936 | retval = FAILED; |
| 2937 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2938 | /* Reset load balance info */ |
| 2939 | memset(fusion->load_balance_info, 0, |
| 2940 | sizeof(struct LD_LOAD_BALANCE_INFO) |
Sumit.Saxena@avagotech.com | 51087a8 | 2014-09-12 18:57:33 +0530 | [diff] [blame] | 2941 | *MAX_LOGICAL_DRIVES_EXT); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2942 | |
| 2943 | if (!megasas_get_map_info(instance)) |
| 2944 | megasas_sync_map_info(instance); |
| 2945 | |
sumit.saxena@avagotech.com | 3761cb4 | 2015-08-31 17:23:11 +0530 | [diff] [blame] | 2946 | megasas_setup_jbod_map(instance); |
| 2947 | |
Sumit.Saxena@avagotech.com | ac340c5 | 2014-11-17 15:24:18 +0530 | [diff] [blame] | 2948 | clear_bit(MEGASAS_FUSION_IN_RESET, |
| 2949 | &instance->reset_flags); |
| 2950 | instance->instancet->enable_intr(instance); |
| 2951 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
| 2952 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2953 | /* Restart SR-IOV heartbeat */ |
| 2954 | if (instance->requestorId) { |
| 2955 | if (!megasas_sriov_start_heartbeat(instance, 0)) |
| 2956 | megasas_start_timer(instance, |
| 2957 | &instance->sriov_heartbeat_timer, |
| 2958 | megasas_sriov_heartbeat_handler, |
| 2959 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2960 | else |
| 2961 | instance->skip_heartbeat_timer_del = 1; |
| 2962 | } |
| 2963 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2964 | /* Adapter reset completed successfully */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2965 | dev_warn(&instance->pdev->dev, "Reset " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2966 | "successful for scsi%d.\n", |
| 2967 | instance->host->host_no); |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 2968 | |
Sumit.Saxena@avagotech.com | ac340c5 | 2014-11-17 15:24:18 +0530 | [diff] [blame] | 2969 | if (instance->crash_dump_drv_support && |
| 2970 | instance->crash_dump_app_support) |
| 2971 | megasas_set_crash_dump_params(instance, |
| 2972 | MR_CRASH_BUF_TURN_ON); |
| 2973 | else |
| 2974 | megasas_set_crash_dump_params(instance, |
| 2975 | MR_CRASH_BUF_TURN_OFF); |
| 2976 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2977 | retval = SUCCESS; |
| 2978 | goto out; |
| 2979 | } |
| 2980 | /* Reset failed, kill the adapter */ |
Bjorn Helgaas | 1be1825 | 2015-07-07 15:52:34 -0500 | [diff] [blame] | 2981 | dev_warn(&instance->pdev->dev, "Reset failed, killing " |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2982 | "adapter scsi%d.\n", instance->host->host_no); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2983 | megaraid_sas_kill_hba(instance); |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2984 | instance->skip_heartbeat_timer_del = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2985 | retval = FAILED; |
| 2986 | } else { |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 2987 | /* For VF: Restart HB timer if we didn't OCR */ |
| 2988 | if (instance->requestorId) { |
| 2989 | megasas_start_timer(instance, |
| 2990 | &instance->sriov_heartbeat_timer, |
| 2991 | megasas_sriov_heartbeat_handler, |
| 2992 | MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); |
| 2993 | } |
adam radford | 3f0e58bc | 2011-10-08 18:14:59 -0700 | [diff] [blame] | 2994 | clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2995 | instance->instancet->enable_intr(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2996 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
| 2997 | } |
| 2998 | out: |
| 2999 | clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
| 3000 | mutex_unlock(&instance->reset_mutex); |
| 3001 | return retval; |
| 3002 | } |
| 3003 | |
Sumit.Saxena@avagotech.com | fc62b3f | 2014-09-12 18:57:28 +0530 | [diff] [blame] | 3004 | /* Fusion Crash dump collection work queue */ |
| 3005 | void megasas_fusion_crash_dump_wq(struct work_struct *work) |
| 3006 | { |
| 3007 | struct megasas_instance *instance = |
| 3008 | container_of(work, struct megasas_instance, crash_init); |
| 3009 | u32 status_reg; |
| 3010 | u8 partial_copy = 0; |
| 3011 | |
| 3012 | |
| 3013 | status_reg = instance->instancet->read_fw_status_reg(instance->reg_set); |
| 3014 | |
| 3015 | /* |
| 3016 | * Allocate host crash buffers to copy data from 1 MB DMA crash buffer |
| 3017 | * to host crash buffers |
| 3018 | */ |
| 3019 | if (instance->drv_buf_index == 0) { |
| 3020 | /* Buffer is already allocated for old Crash dump. |
| 3021 | * Do OCR and do not wait for crash dump collection |
| 3022 | */ |
| 3023 | if (instance->drv_buf_alloc) { |
| 3024 | dev_info(&instance->pdev->dev, "earlier crash dump is " |
| 3025 | "not yet copied by application, ignoring this " |
| 3026 | "crash dump and initiating OCR\n"); |
| 3027 | status_reg |= MFI_STATE_CRASH_DUMP_DONE; |
| 3028 | writel(status_reg, |
| 3029 | &instance->reg_set->outbound_scratch_pad); |
| 3030 | readl(&instance->reg_set->outbound_scratch_pad); |
| 3031 | return; |
| 3032 | } |
| 3033 | megasas_alloc_host_crash_buffer(instance); |
| 3034 | dev_info(&instance->pdev->dev, "Number of host crash buffers " |
| 3035 | "allocated: %d\n", instance->drv_buf_alloc); |
| 3036 | } |
| 3037 | |
| 3038 | /* |
| 3039 | * Driver has allocated max buffers, which can be allocated |
| 3040 | * and FW has more crash dump data, then driver will |
| 3041 | * ignore the data. |
| 3042 | */ |
| 3043 | if (instance->drv_buf_index >= (instance->drv_buf_alloc)) { |
| 3044 | dev_info(&instance->pdev->dev, "Driver is done copying " |
| 3045 | "the buffer: %d\n", instance->drv_buf_alloc); |
| 3046 | status_reg |= MFI_STATE_CRASH_DUMP_DONE; |
| 3047 | partial_copy = 1; |
| 3048 | } else { |
| 3049 | memcpy(instance->crash_buf[instance->drv_buf_index], |
| 3050 | instance->crash_dump_buf, CRASH_DMA_BUF_SIZE); |
| 3051 | instance->drv_buf_index++; |
| 3052 | status_reg &= ~MFI_STATE_DMADONE; |
| 3053 | } |
| 3054 | |
| 3055 | if (status_reg & MFI_STATE_CRASH_DUMP_DONE) { |
| 3056 | dev_info(&instance->pdev->dev, "Crash Dump is available,number " |
| 3057 | "of copied buffers: %d\n", instance->drv_buf_index); |
| 3058 | instance->fw_crash_buffer_size = instance->drv_buf_index; |
| 3059 | instance->fw_crash_state = AVAILABLE; |
| 3060 | instance->drv_buf_index = 0; |
| 3061 | writel(status_reg, &instance->reg_set->outbound_scratch_pad); |
| 3062 | readl(&instance->reg_set->outbound_scratch_pad); |
| 3063 | if (!partial_copy) |
| 3064 | megasas_reset_fusion(instance->host, 0); |
| 3065 | } else { |
| 3066 | writel(status_reg, &instance->reg_set->outbound_scratch_pad); |
| 3067 | readl(&instance->reg_set->outbound_scratch_pad); |
| 3068 | } |
| 3069 | } |
| 3070 | |
| 3071 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3072 | /* Fusion OCR work queue */ |
| 3073 | void megasas_fusion_ocr_wq(struct work_struct *work) |
| 3074 | { |
| 3075 | struct megasas_instance *instance = |
| 3076 | container_of(work, struct megasas_instance, work_init); |
| 3077 | |
adam radford | 229fe47 | 2014-03-10 02:51:56 -0700 | [diff] [blame] | 3078 | megasas_reset_fusion(instance->host, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | struct megasas_instance_template megasas_instance_template_fusion = { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 3082 | .enable_intr = megasas_enable_intr_fusion, |
| 3083 | .disable_intr = megasas_disable_intr_fusion, |
| 3084 | .clear_intr = megasas_clear_intr_fusion, |
| 3085 | .read_fw_status_reg = megasas_read_fw_status_reg_fusion, |
| 3086 | .adp_reset = megasas_adp_reset_fusion, |
| 3087 | .check_reset = megasas_check_reset_fusion, |
| 3088 | .service_isr = megasas_isr_fusion, |
| 3089 | .tasklet = megasas_complete_cmd_dpc_fusion, |
| 3090 | .init_adapter = megasas_init_adapter_fusion, |
| 3091 | .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion, |
| 3092 | .issue_dcmd = megasas_issue_dcmd_fusion, |
| 3093 | }; |