adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Linux MegaRAID driver for SAS based RAID controllers |
| 3 | * |
adam radford | ae59057 | 2012-10-01 19:27:34 -0700 | [diff] [blame] | 4 | * Copyright (c) 2009-2012 LSI Corporation. |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | * FILE: megaraid_sas_fusion.c |
| 21 | * |
| 22 | * Authors: LSI Corporation |
| 23 | * Sumant Patro |
| 24 | * Adam Radford <linuxraid@lsi.com> |
| 25 | * |
| 26 | * Send feedback to: <megaraidlinux@lsi.com> |
| 27 | * |
| 28 | * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 |
| 29 | * ATTN: Linuxraid |
| 30 | */ |
| 31 | |
| 32 | #include <linux/kernel.h> |
| 33 | #include <linux/types.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/list.h> |
| 36 | #include <linux/moduleparam.h> |
| 37 | #include <linux/module.h> |
| 38 | #include <linux/spinlock.h> |
| 39 | #include <linux/interrupt.h> |
| 40 | #include <linux/delay.h> |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 41 | #include <linux/uio.h> |
| 42 | #include <linux/uaccess.h> |
| 43 | #include <linux/fs.h> |
| 44 | #include <linux/compat.h> |
| 45 | #include <linux/blkdev.h> |
| 46 | #include <linux/mutex.h> |
| 47 | #include <linux/poll.h> |
| 48 | |
| 49 | #include <scsi/scsi.h> |
| 50 | #include <scsi/scsi_cmnd.h> |
| 51 | #include <scsi/scsi_device.h> |
| 52 | #include <scsi/scsi_host.h> |
| 53 | |
| 54 | #include "megaraid_sas_fusion.h" |
| 55 | #include "megaraid_sas.h" |
| 56 | |
| 57 | extern void megasas_free_cmds(struct megasas_instance *instance); |
| 58 | extern struct megasas_cmd *megasas_get_cmd(struct megasas_instance |
| 59 | *instance); |
| 60 | extern void |
| 61 | megasas_complete_cmd(struct megasas_instance *instance, |
| 62 | struct megasas_cmd *cmd, u8 alt_status); |
| 63 | int megasas_is_ldio(struct scsi_cmnd *cmd); |
| 64 | int |
| 65 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd); |
| 66 | |
| 67 | void |
| 68 | megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd); |
| 69 | int megasas_alloc_cmds(struct megasas_instance *instance); |
| 70 | int |
| 71 | megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs); |
| 72 | int |
| 73 | megasas_issue_polled(struct megasas_instance *instance, |
| 74 | struct megasas_cmd *cmd); |
adam radford | 53ef2bb | 2011-02-24 20:56:05 -0800 | [diff] [blame] | 75 | void |
| 76 | megasas_check_and_restore_queue_depth(struct megasas_instance *instance); |
| 77 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 78 | u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo, |
| 79 | struct IO_REQUEST_INFO *in_info); |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 80 | int megasas_transition_to_ready(struct megasas_instance *instance, int ocr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 81 | void megaraid_sas_kill_hba(struct megasas_instance *instance); |
| 82 | |
| 83 | extern u32 megasas_dbg_lvl; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 84 | extern int resetwaittime; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * megasas_enable_intr_fusion - Enables interrupts |
| 88 | * @regs: MFI register set |
| 89 | */ |
| 90 | void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 91 | megasas_enable_intr_fusion(struct megasas_instance *instance) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 92 | { |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 93 | struct megasas_register_set __iomem *regs; |
| 94 | regs = instance->reg_set; |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 95 | /* For Thunderbolt/Invader also clear intr on enable */ |
| 96 | writel(~0, ®s->outbound_intr_status); |
| 97 | readl(®s->outbound_intr_status); |
| 98 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 99 | writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask); |
| 100 | |
| 101 | /* Dummy readl to force pci flush */ |
| 102 | readl(®s->outbound_intr_mask); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 103 | instance->mask_interrupts = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
| 107 | * megasas_disable_intr_fusion - Disables interrupt |
| 108 | * @regs: MFI register set |
| 109 | */ |
| 110 | void |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 111 | megasas_disable_intr_fusion(struct megasas_instance *instance) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 112 | { |
| 113 | u32 mask = 0xFFFFFFFF; |
| 114 | u32 status; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 115 | struct megasas_register_set __iomem *regs; |
| 116 | regs = instance->reg_set; |
| 117 | instance->mask_interrupts = 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 118 | |
| 119 | writel(mask, ®s->outbound_intr_mask); |
| 120 | /* Dummy readl to force pci flush */ |
| 121 | status = readl(®s->outbound_intr_mask); |
| 122 | } |
| 123 | |
| 124 | int |
| 125 | megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs) |
| 126 | { |
| 127 | u32 status; |
| 128 | /* |
| 129 | * Check if it is our interrupt |
| 130 | */ |
| 131 | status = readl(®s->outbound_intr_status); |
| 132 | |
| 133 | if (status & 1) { |
| 134 | writel(status, ®s->outbound_intr_status); |
| 135 | readl(®s->outbound_intr_status); |
| 136 | return 1; |
| 137 | } |
| 138 | if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK)) |
| 139 | return 0; |
| 140 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * megasas_get_cmd_fusion - Get a command from the free pool |
| 146 | * @instance: Adapter soft state |
| 147 | * |
| 148 | * Returns a free command from the pool |
| 149 | */ |
| 150 | struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance |
| 151 | *instance) |
| 152 | { |
| 153 | unsigned long flags; |
| 154 | struct fusion_context *fusion = |
| 155 | (struct fusion_context *)instance->ctrl_context; |
| 156 | struct megasas_cmd_fusion *cmd = NULL; |
| 157 | |
| 158 | spin_lock_irqsave(&fusion->cmd_pool_lock, flags); |
| 159 | |
| 160 | if (!list_empty(&fusion->cmd_pool)) { |
| 161 | cmd = list_entry((&fusion->cmd_pool)->next, |
| 162 | struct megasas_cmd_fusion, list); |
| 163 | list_del_init(&cmd->list); |
| 164 | } else { |
| 165 | printk(KERN_ERR "megasas: Command pool (fusion) empty!\n"); |
| 166 | } |
| 167 | |
| 168 | spin_unlock_irqrestore(&fusion->cmd_pool_lock, flags); |
| 169 | return cmd; |
| 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 | */ |
| 177 | static inline void |
| 178 | megasas_return_cmd_fusion(struct megasas_instance *instance, |
| 179 | struct megasas_cmd_fusion *cmd) |
| 180 | { |
| 181 | unsigned long flags; |
| 182 | struct fusion_context *fusion = |
| 183 | (struct fusion_context *)instance->ctrl_context; |
| 184 | |
| 185 | spin_lock_irqsave(&fusion->cmd_pool_lock, flags); |
| 186 | |
| 187 | cmd->scmd = NULL; |
| 188 | cmd->sync_cmd_idx = (u32)ULONG_MAX; |
| 189 | list_add_tail(&cmd->list, &fusion->cmd_pool); |
| 190 | |
| 191 | spin_unlock_irqrestore(&fusion->cmd_pool_lock, flags); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * megasas_teardown_frame_pool_fusion - Destroy the cmd frame DMA pool |
| 196 | * @instance: Adapter soft state |
| 197 | */ |
| 198 | static void megasas_teardown_frame_pool_fusion( |
| 199 | struct megasas_instance *instance) |
| 200 | { |
| 201 | int i; |
| 202 | struct fusion_context *fusion = instance->ctrl_context; |
| 203 | |
| 204 | u16 max_cmd = instance->max_fw_cmds; |
| 205 | |
| 206 | struct megasas_cmd_fusion *cmd; |
| 207 | |
| 208 | if (!fusion->sg_dma_pool || !fusion->sense_dma_pool) { |
| 209 | printk(KERN_ERR "megasas: dma pool is null. SG Pool %p, " |
| 210 | "sense pool : %p\n", fusion->sg_dma_pool, |
| 211 | fusion->sense_dma_pool); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * Return all frames to pool |
| 217 | */ |
| 218 | for (i = 0; i < max_cmd; i++) { |
| 219 | |
| 220 | cmd = fusion->cmd_list[i]; |
| 221 | |
| 222 | if (cmd->sg_frame) |
| 223 | pci_pool_free(fusion->sg_dma_pool, cmd->sg_frame, |
| 224 | cmd->sg_frame_phys_addr); |
| 225 | |
| 226 | if (cmd->sense) |
| 227 | pci_pool_free(fusion->sense_dma_pool, cmd->sense, |
| 228 | cmd->sense_phys_addr); |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Now destroy the pool itself |
| 233 | */ |
| 234 | pci_pool_destroy(fusion->sg_dma_pool); |
| 235 | pci_pool_destroy(fusion->sense_dma_pool); |
| 236 | |
| 237 | fusion->sg_dma_pool = NULL; |
| 238 | fusion->sense_dma_pool = NULL; |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool |
| 243 | * @instance: Adapter soft state |
| 244 | */ |
| 245 | void |
| 246 | megasas_free_cmds_fusion(struct megasas_instance *instance) |
| 247 | { |
| 248 | int i; |
| 249 | struct fusion_context *fusion = instance->ctrl_context; |
| 250 | |
| 251 | u32 max_cmds, req_sz, reply_sz, io_frames_sz; |
| 252 | |
| 253 | |
| 254 | req_sz = fusion->request_alloc_sz; |
| 255 | reply_sz = fusion->reply_alloc_sz; |
| 256 | io_frames_sz = fusion->io_frames_alloc_sz; |
| 257 | |
| 258 | max_cmds = instance->max_fw_cmds; |
| 259 | |
| 260 | /* Free descriptors and request Frames memory */ |
| 261 | if (fusion->req_frames_desc) |
| 262 | dma_free_coherent(&instance->pdev->dev, req_sz, |
| 263 | fusion->req_frames_desc, |
| 264 | fusion->req_frames_desc_phys); |
| 265 | |
| 266 | if (fusion->reply_frames_desc) { |
| 267 | pci_pool_free(fusion->reply_frames_desc_pool, |
| 268 | fusion->reply_frames_desc, |
| 269 | fusion->reply_frames_desc_phys); |
| 270 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 271 | } |
| 272 | |
| 273 | if (fusion->io_request_frames) { |
| 274 | pci_pool_free(fusion->io_request_frames_pool, |
| 275 | fusion->io_request_frames, |
| 276 | fusion->io_request_frames_phys); |
| 277 | pci_pool_destroy(fusion->io_request_frames_pool); |
| 278 | } |
| 279 | |
| 280 | /* Free the Fusion frame pool */ |
| 281 | megasas_teardown_frame_pool_fusion(instance); |
| 282 | |
| 283 | /* Free all the commands in the cmd_list */ |
| 284 | for (i = 0; i < max_cmds; i++) |
| 285 | kfree(fusion->cmd_list[i]); |
| 286 | |
| 287 | /* Free the cmd_list buffer itself */ |
| 288 | kfree(fusion->cmd_list); |
| 289 | fusion->cmd_list = NULL; |
| 290 | |
| 291 | INIT_LIST_HEAD(&fusion->cmd_pool); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * megasas_create_frame_pool_fusion - Creates DMA pool for cmd frames |
| 296 | * @instance: Adapter soft state |
| 297 | * |
| 298 | */ |
| 299 | static int megasas_create_frame_pool_fusion(struct megasas_instance *instance) |
| 300 | { |
| 301 | int i; |
| 302 | u32 max_cmd; |
| 303 | struct fusion_context *fusion; |
| 304 | struct megasas_cmd_fusion *cmd; |
| 305 | u32 total_sz_chain_frame; |
| 306 | |
| 307 | fusion = instance->ctrl_context; |
| 308 | max_cmd = instance->max_fw_cmds; |
| 309 | |
| 310 | total_sz_chain_frame = MEGASAS_MAX_SZ_CHAIN_FRAME; |
| 311 | |
| 312 | /* |
| 313 | * Use DMA pool facility provided by PCI layer |
| 314 | */ |
| 315 | |
| 316 | fusion->sg_dma_pool = pci_pool_create("megasas sg pool fusion", |
| 317 | instance->pdev, |
| 318 | total_sz_chain_frame, 4, |
| 319 | 0); |
| 320 | if (!fusion->sg_dma_pool) { |
| 321 | printk(KERN_DEBUG "megasas: failed to setup request pool " |
| 322 | "fusion\n"); |
| 323 | return -ENOMEM; |
| 324 | } |
| 325 | fusion->sense_dma_pool = pci_pool_create("megasas sense pool fusion", |
| 326 | instance->pdev, |
| 327 | SCSI_SENSE_BUFFERSIZE, 64, 0); |
| 328 | |
| 329 | if (!fusion->sense_dma_pool) { |
| 330 | printk(KERN_DEBUG "megasas: failed to setup sense pool " |
| 331 | "fusion\n"); |
| 332 | pci_pool_destroy(fusion->sg_dma_pool); |
| 333 | fusion->sg_dma_pool = NULL; |
| 334 | return -ENOMEM; |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * Allocate and attach a frame to each of the commands in cmd_list |
| 339 | */ |
| 340 | for (i = 0; i < max_cmd; i++) { |
| 341 | |
| 342 | cmd = fusion->cmd_list[i]; |
| 343 | |
| 344 | cmd->sg_frame = pci_pool_alloc(fusion->sg_dma_pool, |
| 345 | GFP_KERNEL, |
| 346 | &cmd->sg_frame_phys_addr); |
| 347 | |
| 348 | cmd->sense = pci_pool_alloc(fusion->sense_dma_pool, |
| 349 | GFP_KERNEL, &cmd->sense_phys_addr); |
| 350 | /* |
| 351 | * megasas_teardown_frame_pool_fusion() takes care of freeing |
| 352 | * whatever has been allocated |
| 353 | */ |
| 354 | if (!cmd->sg_frame || !cmd->sense) { |
| 355 | printk(KERN_DEBUG "megasas: pci_pool_alloc failed\n"); |
| 356 | megasas_teardown_frame_pool_fusion(instance); |
| 357 | return -ENOMEM; |
| 358 | } |
| 359 | } |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * megasas_alloc_cmds_fusion - Allocates the command packets |
| 365 | * @instance: Adapter soft state |
| 366 | * |
| 367 | * |
| 368 | * Each frame has a 32-bit field called context. This context is used to get |
| 369 | * back the megasas_cmd_fusion from the frame when a frame gets completed |
| 370 | * In this driver, the 32 bit values are the indices into an array cmd_list. |
| 371 | * This array is used only to look up the megasas_cmd_fusion given the context. |
| 372 | * The free commands themselves are maintained in a linked list called cmd_pool. |
| 373 | * |
| 374 | * cmds are formed in the io_request and sg_frame members of the |
| 375 | * megasas_cmd_fusion. The context field is used to get a request descriptor |
| 376 | * and is used as SMID of the cmd. |
| 377 | * SMID value range is from 1 to max_fw_cmds. |
| 378 | */ |
| 379 | int |
| 380 | megasas_alloc_cmds_fusion(struct megasas_instance *instance) |
| 381 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 382 | int i, j, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 383 | u32 max_cmd, io_frames_sz; |
| 384 | struct fusion_context *fusion; |
| 385 | struct megasas_cmd_fusion *cmd; |
| 386 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; |
| 387 | u32 offset; |
| 388 | dma_addr_t io_req_base_phys; |
| 389 | u8 *io_req_base; |
| 390 | |
| 391 | fusion = instance->ctrl_context; |
| 392 | |
| 393 | max_cmd = instance->max_fw_cmds; |
| 394 | |
| 395 | fusion->req_frames_desc = |
| 396 | dma_alloc_coherent(&instance->pdev->dev, |
| 397 | fusion->request_alloc_sz, |
| 398 | &fusion->req_frames_desc_phys, GFP_KERNEL); |
| 399 | |
| 400 | if (!fusion->req_frames_desc) { |
| 401 | printk(KERN_ERR "megasas; Could not allocate memory for " |
| 402 | "request_frames\n"); |
| 403 | goto fail_req_desc; |
| 404 | } |
| 405 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 406 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 407 | fusion->reply_frames_desc_pool = |
| 408 | pci_pool_create("reply_frames pool", instance->pdev, |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 409 | fusion->reply_alloc_sz * count, 16, 0); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 410 | |
| 411 | if (!fusion->reply_frames_desc_pool) { |
| 412 | printk(KERN_ERR "megasas; Could not allocate memory for " |
| 413 | "reply_frame pool\n"); |
| 414 | goto fail_reply_desc; |
| 415 | } |
| 416 | |
| 417 | fusion->reply_frames_desc = |
| 418 | pci_pool_alloc(fusion->reply_frames_desc_pool, GFP_KERNEL, |
| 419 | &fusion->reply_frames_desc_phys); |
| 420 | if (!fusion->reply_frames_desc) { |
| 421 | printk(KERN_ERR "megasas; Could not allocate memory for " |
| 422 | "reply_frame pool\n"); |
| 423 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 424 | goto fail_reply_desc; |
| 425 | } |
| 426 | |
| 427 | reply_desc = fusion->reply_frames_desc; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 428 | for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 429 | reply_desc->Words = ULLONG_MAX; |
| 430 | |
| 431 | io_frames_sz = fusion->io_frames_alloc_sz; |
| 432 | |
| 433 | fusion->io_request_frames_pool = |
| 434 | pci_pool_create("io_request_frames pool", instance->pdev, |
| 435 | fusion->io_frames_alloc_sz, 16, 0); |
| 436 | |
| 437 | if (!fusion->io_request_frames_pool) { |
| 438 | printk(KERN_ERR "megasas: Could not allocate memory for " |
| 439 | "io_request_frame pool\n"); |
| 440 | goto fail_io_frames; |
| 441 | } |
| 442 | |
| 443 | fusion->io_request_frames = |
| 444 | pci_pool_alloc(fusion->io_request_frames_pool, GFP_KERNEL, |
| 445 | &fusion->io_request_frames_phys); |
| 446 | if (!fusion->io_request_frames) { |
| 447 | printk(KERN_ERR "megasas: Could not allocate memory for " |
| 448 | "io_request_frames frames\n"); |
| 449 | pci_pool_destroy(fusion->io_request_frames_pool); |
| 450 | goto fail_io_frames; |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers. |
| 455 | * Allocate the dynamic array first and then allocate individual |
| 456 | * commands. |
| 457 | */ |
Fengguang Wu | 7731e6b | 2012-08-24 23:27:35 +0800 | [diff] [blame] | 458 | fusion->cmd_list = kzalloc(sizeof(struct megasas_cmd_fusion *) |
| 459 | * max_cmd, GFP_KERNEL); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 460 | |
| 461 | if (!fusion->cmd_list) { |
| 462 | printk(KERN_DEBUG "megasas: out of memory. Could not alloc " |
| 463 | "memory for cmd_list_fusion\n"); |
| 464 | goto fail_cmd_list; |
| 465 | } |
| 466 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 467 | max_cmd = instance->max_fw_cmds; |
| 468 | for (i = 0; i < max_cmd; i++) { |
| 469 | fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion), |
| 470 | GFP_KERNEL); |
| 471 | if (!fusion->cmd_list[i]) { |
| 472 | printk(KERN_ERR "Could not alloc cmd list fusion\n"); |
| 473 | |
| 474 | for (j = 0; j < i; j++) |
| 475 | kfree(fusion->cmd_list[j]); |
| 476 | |
| 477 | kfree(fusion->cmd_list); |
| 478 | fusion->cmd_list = NULL; |
| 479 | goto fail_cmd_list; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | /* The first 256 bytes (SMID 0) is not used. Don't add to cmd list */ |
| 484 | io_req_base = fusion->io_request_frames + |
| 485 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; |
| 486 | io_req_base_phys = fusion->io_request_frames_phys + |
| 487 | MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE; |
| 488 | |
| 489 | /* |
| 490 | * Add all the commands to command pool (fusion->cmd_pool) |
| 491 | */ |
| 492 | |
| 493 | /* SMID 0 is reserved. Set SMID/index from 1 */ |
| 494 | for (i = 0; i < max_cmd; i++) { |
| 495 | cmd = fusion->cmd_list[i]; |
| 496 | offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i; |
| 497 | memset(cmd, 0, sizeof(struct megasas_cmd_fusion)); |
| 498 | cmd->index = i + 1; |
| 499 | cmd->scmd = NULL; |
| 500 | cmd->sync_cmd_idx = (u32)ULONG_MAX; /* Set to Invalid */ |
| 501 | cmd->instance = instance; |
| 502 | cmd->io_request = |
| 503 | (struct MPI2_RAID_SCSI_IO_REQUEST *) |
| 504 | (io_req_base + offset); |
| 505 | memset(cmd->io_request, 0, |
| 506 | sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)); |
| 507 | cmd->io_request_phys_addr = io_req_base_phys + offset; |
| 508 | |
| 509 | list_add_tail(&cmd->list, &fusion->cmd_pool); |
| 510 | } |
| 511 | |
| 512 | /* |
| 513 | * Create a frame pool and assign one frame to each cmd |
| 514 | */ |
| 515 | if (megasas_create_frame_pool_fusion(instance)) { |
| 516 | printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n"); |
| 517 | megasas_free_cmds_fusion(instance); |
| 518 | goto fail_req_desc; |
| 519 | } |
| 520 | |
| 521 | return 0; |
| 522 | |
| 523 | fail_cmd_list: |
| 524 | pci_pool_free(fusion->io_request_frames_pool, fusion->io_request_frames, |
| 525 | fusion->io_request_frames_phys); |
| 526 | pci_pool_destroy(fusion->io_request_frames_pool); |
| 527 | fail_io_frames: |
| 528 | dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz, |
| 529 | fusion->reply_frames_desc, |
| 530 | fusion->reply_frames_desc_phys); |
| 531 | pci_pool_free(fusion->reply_frames_desc_pool, |
| 532 | fusion->reply_frames_desc, |
| 533 | fusion->reply_frames_desc_phys); |
| 534 | pci_pool_destroy(fusion->reply_frames_desc_pool); |
| 535 | |
| 536 | fail_reply_desc: |
| 537 | dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz, |
| 538 | fusion->req_frames_desc, |
| 539 | fusion->req_frames_desc_phys); |
| 540 | fail_req_desc: |
| 541 | return -ENOMEM; |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * wait_and_poll - Issues a polling command |
| 546 | * @instance: Adapter soft state |
| 547 | * @cmd: Command packet to be issued |
| 548 | * |
| 549 | * For polling, MFI requires the cmd_status to be set to 0xFF before posting. |
| 550 | */ |
| 551 | int |
| 552 | wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 553 | { |
| 554 | int i; |
| 555 | struct megasas_header *frame_hdr = &cmd->frame->hdr; |
| 556 | |
| 557 | u32 msecs = MFI_POLL_TIMEOUT_SECS * 1000; |
| 558 | |
| 559 | /* |
| 560 | * Wait for cmd_status to change |
| 561 | */ |
| 562 | for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) { |
| 563 | rmb(); |
| 564 | msleep(20); |
| 565 | } |
| 566 | |
| 567 | if (frame_hdr->cmd_status == 0xff) |
| 568 | return -ETIME; |
| 569 | |
| 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * megasas_ioc_init_fusion - Initializes the FW |
| 575 | * @instance: Adapter soft state |
| 576 | * |
| 577 | * Issues the IOC Init cmd |
| 578 | */ |
| 579 | int |
| 580 | megasas_ioc_init_fusion(struct megasas_instance *instance) |
| 581 | { |
| 582 | struct megasas_init_frame *init_frame; |
| 583 | struct MPI2_IOC_INIT_REQUEST *IOCInitMessage; |
| 584 | dma_addr_t ioc_init_handle; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 585 | struct megasas_cmd *cmd; |
| 586 | u8 ret; |
| 587 | struct fusion_context *fusion; |
| 588 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 589 | int i; |
| 590 | struct megasas_header *frame_hdr; |
| 591 | |
| 592 | fusion = instance->ctrl_context; |
| 593 | |
| 594 | cmd = megasas_get_cmd(instance); |
| 595 | |
| 596 | if (!cmd) { |
| 597 | printk(KERN_ERR "Could not allocate cmd for INIT Frame\n"); |
| 598 | ret = 1; |
| 599 | goto fail_get_cmd; |
| 600 | } |
| 601 | |
| 602 | IOCInitMessage = |
| 603 | dma_alloc_coherent(&instance->pdev->dev, |
| 604 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 605 | &ioc_init_handle, GFP_KERNEL); |
| 606 | |
| 607 | if (!IOCInitMessage) { |
| 608 | printk(KERN_ERR "Could not allocate memory for " |
| 609 | "IOCInitMessage\n"); |
| 610 | ret = 1; |
| 611 | goto fail_fw_init; |
| 612 | } |
| 613 | |
| 614 | memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST)); |
| 615 | |
| 616 | IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT; |
| 617 | IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 618 | IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION); |
| 619 | IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); |
| 620 | 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] | 621 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 622 | IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth); |
| 623 | IOCInitMessage->ReplyDescriptorPostQueueAddress = cpu_to_le64(fusion->reply_frames_desc_phys); |
| 624 | IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys); |
adam radford | 5738f99 | 2012-03-19 19:49:53 -0700 | [diff] [blame] | 625 | IOCInitMessage->HostMSIxVectors = instance->msix_vectors; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 626 | init_frame = (struct megasas_init_frame *)cmd->frame; |
| 627 | memset(init_frame, 0, MEGAMFI_FRAME_SIZE); |
| 628 | |
| 629 | frame_hdr = &cmd->frame->hdr; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 630 | frame_hdr->cmd_status = 0xFF; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 631 | frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 632 | |
| 633 | init_frame->cmd = MFI_CMD_INIT; |
| 634 | init_frame->cmd_status = 0xFF; |
| 635 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 636 | /* driver support Extended MSIX */ |
| 637 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 638 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
| 639 | init_frame->driver_operations. |
| 640 | mfi_capabilities.support_additional_msix = 1; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 641 | /* driver supports HA / Remote LUN over Fast Path interface */ |
| 642 | init_frame->driver_operations.mfi_capabilities.support_fp_remote_lun |
| 643 | = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 644 | /* Convert capability to LE32 */ |
| 645 | cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 646 | |
Hannes Reinecke | fdc5a97 | 2014-01-16 11:25:33 +0100 | [diff] [blame] | 647 | init_frame->queue_info_new_phys_addr_hi = |
| 648 | cpu_to_le32(upper_32_bits(ioc_init_handle)); |
| 649 | init_frame->queue_info_new_phys_addr_lo = |
| 650 | cpu_to_le32(lower_32_bits(ioc_init_handle)); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 651 | 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] | 652 | |
| 653 | req_desc = |
| 654 | (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)fusion->req_frames_desc; |
| 655 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 656 | req_desc->Words = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 657 | req_desc->MFAIo.RequestFlags = |
| 658 | (MEGASAS_REQ_DESCRIPT_FLAGS_MFA << |
| 659 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 660 | cpu_to_le32s((u32 *)&req_desc->MFAIo); |
| 661 | req_desc->Words |= cpu_to_le64(cmd->frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * disable the intr before firing the init frame |
| 665 | */ |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 666 | instance->instancet->disable_intr(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 667 | |
| 668 | for (i = 0; i < (10 * 1000); i += 20) { |
| 669 | if (readl(&instance->reg_set->doorbell) & 1) |
| 670 | msleep(20); |
| 671 | else |
| 672 | break; |
| 673 | } |
| 674 | |
| 675 | instance->instancet->fire_cmd(instance, req_desc->u.low, |
| 676 | req_desc->u.high, instance->reg_set); |
| 677 | |
| 678 | wait_and_poll(instance, cmd); |
| 679 | |
| 680 | frame_hdr = &cmd->frame->hdr; |
| 681 | if (frame_hdr->cmd_status != 0) { |
| 682 | ret = 1; |
| 683 | goto fail_fw_init; |
| 684 | } |
| 685 | printk(KERN_ERR "megasas:IOC Init cmd success\n"); |
| 686 | |
| 687 | ret = 0; |
| 688 | |
| 689 | fail_fw_init: |
| 690 | megasas_return_cmd(instance, cmd); |
| 691 | if (IOCInitMessage) |
| 692 | dma_free_coherent(&instance->pdev->dev, |
| 693 | sizeof(struct MPI2_IOC_INIT_REQUEST), |
| 694 | IOCInitMessage, ioc_init_handle); |
| 695 | fail_get_cmd: |
| 696 | return ret; |
| 697 | } |
| 698 | |
| 699 | /* |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 700 | * megasas_get_ld_map_info - Returns FW's ld_map structure |
| 701 | * @instance: Adapter soft state |
| 702 | * @pend: Pend the command or not |
| 703 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 704 | * list structure. This information is mainly used to find out SYSTEM |
| 705 | * supported by the FW. |
| 706 | */ |
| 707 | static int |
| 708 | megasas_get_ld_map_info(struct megasas_instance *instance) |
| 709 | { |
| 710 | int ret = 0; |
| 711 | struct megasas_cmd *cmd; |
| 712 | struct megasas_dcmd_frame *dcmd; |
| 713 | struct MR_FW_RAID_MAP_ALL *ci; |
| 714 | dma_addr_t ci_h = 0; |
| 715 | u32 size_map_info; |
| 716 | struct fusion_context *fusion; |
| 717 | |
| 718 | cmd = megasas_get_cmd(instance); |
| 719 | |
| 720 | if (!cmd) { |
| 721 | printk(KERN_DEBUG "megasas: Failed to get cmd for map info.\n"); |
| 722 | return -ENOMEM; |
| 723 | } |
| 724 | |
| 725 | fusion = instance->ctrl_context; |
| 726 | |
| 727 | if (!fusion) { |
| 728 | megasas_return_cmd(instance, cmd); |
Hannes Reinecke | 2f8bdfa | 2014-01-16 11:25:35 +0100 | [diff] [blame^] | 729 | return -ENXIO; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | dcmd = &cmd->frame->dcmd; |
| 733 | |
| 734 | size_map_info = sizeof(struct MR_FW_RAID_MAP) + |
| 735 | (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1)); |
| 736 | |
| 737 | ci = fusion->ld_map[(instance->map_id & 1)]; |
| 738 | ci_h = fusion->ld_map_phys[(instance->map_id & 1)]; |
| 739 | |
| 740 | if (!ci) { |
| 741 | printk(KERN_DEBUG "Failed to alloc mem for ld_map_info\n"); |
| 742 | megasas_return_cmd(instance, cmd); |
| 743 | return -ENOMEM; |
| 744 | } |
| 745 | |
| 746 | memset(ci, 0, sizeof(*ci)); |
| 747 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 748 | |
| 749 | dcmd->cmd = MFI_CMD_DCMD; |
| 750 | dcmd->cmd_status = 0xFF; |
| 751 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 752 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 753 | dcmd->timeout = 0; |
| 754 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 755 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
| 756 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); |
| 757 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 758 | dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 759 | |
| 760 | if (!megasas_issue_polled(instance, cmd)) |
| 761 | ret = 0; |
| 762 | else { |
| 763 | printk(KERN_ERR "megasas: Get LD Map Info Failed\n"); |
| 764 | ret = -1; |
| 765 | } |
| 766 | |
| 767 | megasas_return_cmd(instance, cmd); |
| 768 | |
| 769 | return ret; |
| 770 | } |
| 771 | |
| 772 | u8 |
| 773 | megasas_get_map_info(struct megasas_instance *instance) |
| 774 | { |
| 775 | struct fusion_context *fusion = instance->ctrl_context; |
| 776 | |
| 777 | fusion->fast_path_io = 0; |
| 778 | if (!megasas_get_ld_map_info(instance)) { |
Sumit.Saxena@lsi.com | bc93d42 | 2013-05-22 12:35:04 +0530 | [diff] [blame] | 779 | if (MR_ValidateMapInfo(instance)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 780 | fusion->fast_path_io = 1; |
| 781 | return 0; |
| 782 | } |
| 783 | } |
| 784 | return 1; |
| 785 | } |
| 786 | |
| 787 | /* |
| 788 | * megasas_sync_map_info - Returns FW's ld_map structure |
| 789 | * @instance: Adapter soft state |
| 790 | * |
| 791 | * Issues an internal command (DCMD) to get the FW's controller PD |
| 792 | * list structure. This information is mainly used to find out SYSTEM |
| 793 | * supported by the FW. |
| 794 | */ |
| 795 | int |
| 796 | megasas_sync_map_info(struct megasas_instance *instance) |
| 797 | { |
| 798 | int ret = 0, i; |
| 799 | struct megasas_cmd *cmd; |
| 800 | struct megasas_dcmd_frame *dcmd; |
| 801 | u32 size_sync_info, num_lds; |
| 802 | struct fusion_context *fusion; |
| 803 | struct MR_LD_TARGET_SYNC *ci = NULL; |
| 804 | struct MR_FW_RAID_MAP_ALL *map; |
| 805 | struct MR_LD_RAID *raid; |
| 806 | struct MR_LD_TARGET_SYNC *ld_sync; |
| 807 | dma_addr_t ci_h = 0; |
| 808 | u32 size_map_info; |
| 809 | |
| 810 | cmd = megasas_get_cmd(instance); |
| 811 | |
| 812 | if (!cmd) { |
| 813 | printk(KERN_DEBUG "megasas: Failed to get cmd for sync" |
| 814 | "info.\n"); |
| 815 | return -ENOMEM; |
| 816 | } |
| 817 | |
| 818 | fusion = instance->ctrl_context; |
| 819 | |
| 820 | if (!fusion) { |
| 821 | megasas_return_cmd(instance, cmd); |
| 822 | return 1; |
| 823 | } |
| 824 | |
| 825 | map = fusion->ld_map[instance->map_id & 1]; |
| 826 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 827 | num_lds = le32_to_cpu(map->raidMap.ldCount); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 828 | |
| 829 | dcmd = &cmd->frame->dcmd; |
| 830 | |
| 831 | size_sync_info = sizeof(struct MR_LD_TARGET_SYNC) *num_lds; |
| 832 | |
| 833 | memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE); |
| 834 | |
| 835 | ci = (struct MR_LD_TARGET_SYNC *) |
| 836 | fusion->ld_map[(instance->map_id - 1) & 1]; |
| 837 | memset(ci, 0, sizeof(struct MR_FW_RAID_MAP_ALL)); |
| 838 | |
| 839 | ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1]; |
| 840 | |
| 841 | ld_sync = (struct MR_LD_TARGET_SYNC *)ci; |
| 842 | |
| 843 | for (i = 0; i < num_lds; i++, ld_sync++) { |
| 844 | raid = MR_LdRaidGet(i, map); |
| 845 | ld_sync->targetId = MR_GetLDTgtId(i, map); |
| 846 | ld_sync->seqNum = raid->seqNum; |
| 847 | } |
| 848 | |
| 849 | size_map_info = sizeof(struct MR_FW_RAID_MAP) + |
| 850 | (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1)); |
| 851 | |
| 852 | dcmd->cmd = MFI_CMD_DCMD; |
| 853 | dcmd->cmd_status = 0xFF; |
| 854 | dcmd->sge_count = 1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 855 | dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 856 | dcmd->timeout = 0; |
| 857 | dcmd->pad_0 = 0; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 858 | dcmd->data_xfer_len = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 859 | dcmd->mbox.b[0] = num_lds; |
| 860 | dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 861 | dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO); |
| 862 | dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h); |
| 863 | dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 864 | |
| 865 | instance->map_update_cmd = cmd; |
| 866 | |
| 867 | instance->instancet->issue_dcmd(instance, cmd); |
| 868 | |
| 869 | return ret; |
| 870 | } |
| 871 | |
Sumit.Saxena@lsi.com | 39b72c3 | 2013-05-22 12:32:43 +0530 | [diff] [blame] | 872 | /* |
| 873 | * meagasas_display_intel_branding - Display branding string |
| 874 | * @instance: per adapter object |
| 875 | * |
| 876 | * Return nothing. |
| 877 | */ |
| 878 | static void |
| 879 | megasas_display_intel_branding(struct megasas_instance *instance) |
| 880 | { |
| 881 | if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) |
| 882 | return; |
| 883 | |
| 884 | switch (instance->pdev->device) { |
| 885 | case PCI_DEVICE_ID_LSI_INVADER: |
| 886 | switch (instance->pdev->subsystem_device) { |
| 887 | case MEGARAID_INTEL_RS3DC080_SSDID: |
| 888 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 889 | instance->host->host_no, |
| 890 | MEGARAID_INTEL_RS3DC080_BRANDING); |
| 891 | break; |
| 892 | case MEGARAID_INTEL_RS3DC040_SSDID: |
| 893 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 894 | instance->host->host_no, |
| 895 | MEGARAID_INTEL_RS3DC040_BRANDING); |
| 896 | break; |
| 897 | case MEGARAID_INTEL_RS3SC008_SSDID: |
| 898 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 899 | instance->host->host_no, |
| 900 | MEGARAID_INTEL_RS3SC008_BRANDING); |
| 901 | break; |
| 902 | case MEGARAID_INTEL_RS3MC044_SSDID: |
| 903 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 904 | instance->host->host_no, |
| 905 | MEGARAID_INTEL_RS3MC044_BRANDING); |
| 906 | break; |
| 907 | default: |
| 908 | break; |
| 909 | } |
| 910 | break; |
| 911 | case PCI_DEVICE_ID_LSI_FURY: |
| 912 | switch (instance->pdev->subsystem_device) { |
| 913 | case MEGARAID_INTEL_RS3WC080_SSDID: |
| 914 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 915 | instance->host->host_no, |
| 916 | MEGARAID_INTEL_RS3WC080_BRANDING); |
| 917 | break; |
| 918 | case MEGARAID_INTEL_RS3WC040_SSDID: |
| 919 | dev_info(&instance->pdev->dev, "scsi host %d: %s\n", |
| 920 | instance->host->host_no, |
| 921 | MEGARAID_INTEL_RS3WC040_BRANDING); |
| 922 | break; |
| 923 | default: |
| 924 | break; |
| 925 | } |
| 926 | break; |
| 927 | default: |
| 928 | break; |
| 929 | } |
| 930 | } |
| 931 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 932 | /** |
| 933 | * megasas_init_adapter_fusion - Initializes the FW |
| 934 | * @instance: Adapter soft state |
| 935 | * |
| 936 | * This is the main function for initializing firmware. |
| 937 | */ |
| 938 | u32 |
| 939 | megasas_init_adapter_fusion(struct megasas_instance *instance) |
| 940 | { |
| 941 | struct megasas_register_set __iomem *reg_set; |
| 942 | struct fusion_context *fusion; |
| 943 | u32 max_cmd; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 944 | int i = 0, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 945 | |
| 946 | fusion = instance->ctrl_context; |
| 947 | |
| 948 | reg_set = instance->reg_set; |
| 949 | |
| 950 | /* |
| 951 | * Get various operational parameters from status register |
| 952 | */ |
| 953 | instance->max_fw_cmds = |
| 954 | instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF; |
| 955 | instance->max_fw_cmds = min(instance->max_fw_cmds, (u16)1008); |
| 956 | |
| 957 | /* |
| 958 | * Reduce the max supported cmds by 1. This is to ensure that the |
| 959 | * reply_q_sz (1 more than the max cmd that driver may send) |
| 960 | * does not exceed max cmds that the FW can support |
| 961 | */ |
| 962 | instance->max_fw_cmds = instance->max_fw_cmds-1; |
| 963 | /* Only internal cmds (DCMD) need to have MFI frames */ |
| 964 | instance->max_mfi_cmds = MEGASAS_INT_CMDS; |
| 965 | |
| 966 | max_cmd = instance->max_fw_cmds; |
| 967 | |
| 968 | fusion->reply_q_depth = ((max_cmd + 1 + 15)/16)*16; |
| 969 | |
| 970 | fusion->request_alloc_sz = |
| 971 | sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *max_cmd; |
| 972 | fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION) |
| 973 | *(fusion->reply_q_depth); |
| 974 | fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE + |
| 975 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * |
| 976 | (max_cmd + 1)); /* Extra 1 for SMID 0 */ |
| 977 | |
| 978 | fusion->max_sge_in_main_msg = |
| 979 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - |
| 980 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16; |
| 981 | |
| 982 | fusion->max_sge_in_chain = |
| 983 | MEGASAS_MAX_SZ_CHAIN_FRAME / sizeof(union MPI2_SGE_IO_UNION); |
| 984 | |
| 985 | instance->max_num_sge = fusion->max_sge_in_main_msg + |
| 986 | fusion->max_sge_in_chain - 2; |
| 987 | |
| 988 | /* Used for pass thru MFI frame (DCMD) */ |
| 989 | fusion->chain_offset_mfi_pthru = |
| 990 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16; |
| 991 | |
| 992 | fusion->chain_offset_io_request = |
| 993 | (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE - |
| 994 | sizeof(union MPI2_SGE_IO_UNION))/16; |
| 995 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 996 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 997 | for (i = 0 ; i < count; i++) |
| 998 | fusion->last_reply_idx[i] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 999 | |
| 1000 | /* |
| 1001 | * Allocate memory for descriptors |
| 1002 | * Create a pool of commands |
| 1003 | */ |
| 1004 | if (megasas_alloc_cmds(instance)) |
| 1005 | goto fail_alloc_mfi_cmds; |
| 1006 | if (megasas_alloc_cmds_fusion(instance)) |
| 1007 | goto fail_alloc_cmds; |
| 1008 | |
| 1009 | if (megasas_ioc_init_fusion(instance)) |
| 1010 | goto fail_ioc_init; |
| 1011 | |
Sumit.Saxena@lsi.com | 39b72c3 | 2013-05-22 12:32:43 +0530 | [diff] [blame] | 1012 | megasas_display_intel_branding(instance); |
| 1013 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1014 | instance->flag_ieee = 1; |
| 1015 | |
| 1016 | fusion->map_sz = sizeof(struct MR_FW_RAID_MAP) + |
| 1017 | (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1)); |
| 1018 | |
| 1019 | fusion->fast_path_io = 0; |
| 1020 | |
| 1021 | for (i = 0; i < 2; i++) { |
| 1022 | fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev, |
| 1023 | fusion->map_sz, |
| 1024 | &fusion->ld_map_phys[i], |
| 1025 | GFP_KERNEL); |
| 1026 | if (!fusion->ld_map[i]) { |
| 1027 | printk(KERN_ERR "megasas: Could not allocate memory " |
| 1028 | "for map info\n"); |
| 1029 | goto fail_map_info; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | if (!megasas_get_map_info(instance)) |
| 1034 | megasas_sync_map_info(instance); |
| 1035 | |
| 1036 | return 0; |
| 1037 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1038 | fail_map_info: |
| 1039 | if (i == 1) |
| 1040 | dma_free_coherent(&instance->pdev->dev, fusion->map_sz, |
| 1041 | fusion->ld_map[0], fusion->ld_map_phys[0]); |
| 1042 | fail_ioc_init: |
adam radford | eb1b123 | 2011-02-24 20:55:56 -0800 | [diff] [blame] | 1043 | megasas_free_cmds_fusion(instance); |
| 1044 | fail_alloc_cmds: |
| 1045 | megasas_free_cmds(instance); |
| 1046 | fail_alloc_mfi_cmds: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1047 | return 1; |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * megasas_fire_cmd_fusion - Sends command to the FW |
| 1052 | * @frame_phys_addr : Physical address of cmd |
| 1053 | * @frame_count : Number of frames for the command |
| 1054 | * @regs : MFI register set |
| 1055 | */ |
| 1056 | void |
| 1057 | megasas_fire_cmd_fusion(struct megasas_instance *instance, |
| 1058 | dma_addr_t req_desc_lo, |
| 1059 | u32 req_desc_hi, |
| 1060 | struct megasas_register_set __iomem *regs) |
| 1061 | { |
| 1062 | unsigned long flags; |
| 1063 | |
| 1064 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 1065 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1066 | writel(le32_to_cpu(req_desc_lo), &(regs)->inbound_low_queue_port); |
| 1067 | writel(le32_to_cpu(req_desc_hi), &(regs)->inbound_high_queue_port); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1068 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * map_cmd_status - Maps FW cmd status to OS cmd status |
| 1073 | * @cmd : Pointer to cmd |
| 1074 | * @status : status of cmd returned by FW |
| 1075 | * @ext_status : ext status of cmd returned by FW |
| 1076 | */ |
| 1077 | |
| 1078 | void |
| 1079 | map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status) |
| 1080 | { |
| 1081 | |
| 1082 | switch (status) { |
| 1083 | |
| 1084 | case MFI_STAT_OK: |
| 1085 | cmd->scmd->result = DID_OK << 16; |
| 1086 | break; |
| 1087 | |
| 1088 | case MFI_STAT_SCSI_IO_FAILED: |
| 1089 | case MFI_STAT_LD_INIT_IN_PROGRESS: |
| 1090 | cmd->scmd->result = (DID_ERROR << 16) | ext_status; |
| 1091 | break; |
| 1092 | |
| 1093 | case MFI_STAT_SCSI_DONE_WITH_ERROR: |
| 1094 | |
| 1095 | cmd->scmd->result = (DID_OK << 16) | ext_status; |
| 1096 | if (ext_status == SAM_STAT_CHECK_CONDITION) { |
| 1097 | memset(cmd->scmd->sense_buffer, 0, |
| 1098 | SCSI_SENSE_BUFFERSIZE); |
| 1099 | memcpy(cmd->scmd->sense_buffer, cmd->sense, |
| 1100 | SCSI_SENSE_BUFFERSIZE); |
| 1101 | cmd->scmd->result |= DRIVER_SENSE << 24; |
| 1102 | } |
| 1103 | break; |
| 1104 | |
| 1105 | case MFI_STAT_LD_OFFLINE: |
| 1106 | case MFI_STAT_DEVICE_NOT_FOUND: |
| 1107 | cmd->scmd->result = DID_BAD_TARGET << 16; |
| 1108 | break; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1109 | case MFI_STAT_CONFIG_SEQ_MISMATCH: |
| 1110 | cmd->scmd->result = DID_IMM_RETRY << 16; |
| 1111 | break; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1112 | default: |
| 1113 | printk(KERN_DEBUG "megasas: FW status %#x\n", status); |
| 1114 | cmd->scmd->result = DID_ERROR << 16; |
| 1115 | break; |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * megasas_make_sgl_fusion - Prepares 32-bit SGL |
| 1121 | * @instance: Adapter soft state |
| 1122 | * @scp: SCSI command from the mid-layer |
| 1123 | * @sgl_ptr: SGL to be filled in |
| 1124 | * @cmd: cmd we are working on |
| 1125 | * |
| 1126 | * If successful, this function returns the number of SG elements. |
| 1127 | */ |
| 1128 | static int |
| 1129 | megasas_make_sgl_fusion(struct megasas_instance *instance, |
| 1130 | struct scsi_cmnd *scp, |
| 1131 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr, |
| 1132 | struct megasas_cmd_fusion *cmd) |
| 1133 | { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1134 | int i, sg_processed, sge_count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1135 | struct scatterlist *os_sgl; |
| 1136 | struct fusion_context *fusion; |
| 1137 | |
| 1138 | fusion = instance->ctrl_context; |
| 1139 | |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1140 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1141 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1142 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr; |
| 1143 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; |
| 1144 | sgl_ptr_end->Flags = 0; |
| 1145 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1146 | |
| 1147 | sge_count = scsi_dma_map(scp); |
| 1148 | |
| 1149 | BUG_ON(sge_count < 0); |
| 1150 | |
| 1151 | if (sge_count > instance->max_num_sge || !sge_count) |
| 1152 | return sge_count; |
| 1153 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1154 | scsi_for_each_sg(scp, os_sgl, sge_count, i) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1155 | sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl)); |
| 1156 | sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1157 | sgl_ptr->Flags = 0; |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1158 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1159 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1160 | if (i == sge_count - 1) |
| 1161 | sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST; |
| 1162 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1163 | sgl_ptr++; |
| 1164 | |
| 1165 | sg_processed = i + 1; |
| 1166 | |
| 1167 | if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) && |
| 1168 | (sge_count > fusion->max_sge_in_main_msg)) { |
| 1169 | |
| 1170 | struct MPI25_IEEE_SGE_CHAIN64 *sg_chain; |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1171 | if ((instance->pdev->device == |
| 1172 | PCI_DEVICE_ID_LSI_INVADER) || |
| 1173 | (instance->pdev->device == |
| 1174 | PCI_DEVICE_ID_LSI_FURY)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1175 | if ((le16_to_cpu(cmd->io_request->IoFlags) & |
| 1176 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) != |
| 1177 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1178 | cmd->io_request->ChainOffset = |
| 1179 | fusion-> |
| 1180 | chain_offset_io_request; |
| 1181 | else |
| 1182 | cmd->io_request->ChainOffset = 0; |
| 1183 | } else |
| 1184 | cmd->io_request->ChainOffset = |
| 1185 | fusion->chain_offset_io_request; |
| 1186 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1187 | sg_chain = sgl_ptr; |
| 1188 | /* Prepare chain element */ |
| 1189 | sg_chain->NextChainOffset = 0; |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1190 | if ((instance->pdev->device == |
| 1191 | PCI_DEVICE_ID_LSI_INVADER) || |
| 1192 | (instance->pdev->device == |
| 1193 | PCI_DEVICE_ID_LSI_FURY)) |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1194 | sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT; |
| 1195 | else |
| 1196 | sg_chain->Flags = |
| 1197 | (IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 1198 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR); |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1199 | sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed))); |
| 1200 | sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1201 | |
| 1202 | sgl_ptr = |
| 1203 | (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | return sge_count; |
| 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * megasas_set_pd_lba - Sets PD LBA |
| 1212 | * @cdb: CDB |
| 1213 | * @cdb_len: cdb length |
| 1214 | * @start_blk: Start block of IO |
| 1215 | * |
| 1216 | * Used to set the PD LBA in CDB for FP IOs |
| 1217 | */ |
| 1218 | void |
| 1219 | megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len, |
| 1220 | struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp, |
| 1221 | struct MR_FW_RAID_MAP_ALL *local_map_ptr, u32 ref_tag) |
| 1222 | { |
| 1223 | struct MR_LD_RAID *raid; |
| 1224 | u32 ld; |
| 1225 | u64 start_blk = io_info->pdBlock; |
| 1226 | u8 *cdb = io_request->CDB.CDB32; |
| 1227 | u32 num_blocks = io_info->numBlocks; |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1228 | u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1229 | |
| 1230 | /* Check if T10 PI (DIF) is enabled for this LD */ |
| 1231 | ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr); |
| 1232 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1233 | if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) { |
| 1234 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1235 | cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD; |
| 1236 | cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN; |
| 1237 | |
| 1238 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1239 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32; |
| 1240 | else |
| 1241 | cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32; |
| 1242 | cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL; |
| 1243 | |
| 1244 | /* LBA */ |
| 1245 | cdb[12] = (u8)((start_blk >> 56) & 0xff); |
| 1246 | cdb[13] = (u8)((start_blk >> 48) & 0xff); |
| 1247 | cdb[14] = (u8)((start_blk >> 40) & 0xff); |
| 1248 | cdb[15] = (u8)((start_blk >> 32) & 0xff); |
| 1249 | cdb[16] = (u8)((start_blk >> 24) & 0xff); |
| 1250 | cdb[17] = (u8)((start_blk >> 16) & 0xff); |
| 1251 | cdb[18] = (u8)((start_blk >> 8) & 0xff); |
| 1252 | cdb[19] = (u8)(start_blk & 0xff); |
| 1253 | |
| 1254 | /* Logical block reference tag */ |
| 1255 | io_request->CDB.EEDP32.PrimaryReferenceTag = |
| 1256 | cpu_to_be32(ref_tag); |
| 1257 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0xffff; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1258 | io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1259 | |
| 1260 | /* Transfer length */ |
| 1261 | cdb[28] = (u8)((num_blocks >> 24) & 0xff); |
| 1262 | cdb[29] = (u8)((num_blocks >> 16) & 0xff); |
| 1263 | cdb[30] = (u8)((num_blocks >> 8) & 0xff); |
| 1264 | cdb[31] = (u8)(num_blocks & 0xff); |
| 1265 | |
| 1266 | /* set SCSI IO EEDPFlags */ |
| 1267 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1268 | io_request->EEDPFlags = cpu_to_le16( |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1269 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
| 1270 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG | |
| 1271 | MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP | |
| 1272 | MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1273 | MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1274 | } else { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1275 | io_request->EEDPFlags = cpu_to_le16( |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1276 | MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1277 | MPI2_SCSIIO_EEDPFLAGS_INSERT_OP); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1278 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1279 | io_request->Control |= cpu_to_le32((0x4 << 26)); |
| 1280 | io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1281 | } else { |
| 1282 | /* Some drives don't support 16/12 byte CDB's, convert to 10 */ |
| 1283 | if (((cdb_len == 12) || (cdb_len == 16)) && |
| 1284 | (start_blk <= 0xffffffff)) { |
| 1285 | if (cdb_len == 16) { |
| 1286 | opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10; |
| 1287 | flagvals = cdb[1]; |
| 1288 | groupnum = cdb[14]; |
| 1289 | control = cdb[15]; |
| 1290 | } else { |
| 1291 | opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10; |
| 1292 | flagvals = cdb[1]; |
| 1293 | groupnum = cdb[10]; |
| 1294 | control = cdb[11]; |
| 1295 | } |
| 1296 | |
| 1297 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1298 | |
| 1299 | cdb[0] = opcode; |
| 1300 | cdb[1] = flagvals; |
| 1301 | cdb[6] = groupnum; |
| 1302 | cdb[9] = control; |
| 1303 | |
| 1304 | /* Transfer length */ |
| 1305 | cdb[8] = (u8)(num_blocks & 0xff); |
| 1306 | cdb[7] = (u8)((num_blocks >> 8) & 0xff); |
| 1307 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1308 | io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */ |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1309 | cdb_len = 10; |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1310 | } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) { |
| 1311 | /* Convert to 16 byte CDB for large LBA's */ |
| 1312 | switch (cdb_len) { |
| 1313 | case 6: |
| 1314 | opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16; |
| 1315 | control = cdb[5]; |
| 1316 | break; |
| 1317 | case 10: |
| 1318 | opcode = |
| 1319 | cdb[0] == READ_10 ? READ_16 : WRITE_16; |
| 1320 | flagvals = cdb[1]; |
| 1321 | groupnum = cdb[6]; |
| 1322 | control = cdb[9]; |
| 1323 | break; |
| 1324 | case 12: |
| 1325 | opcode = |
| 1326 | cdb[0] == READ_12 ? READ_16 : WRITE_16; |
| 1327 | flagvals = cdb[1]; |
| 1328 | groupnum = cdb[10]; |
| 1329 | control = cdb[11]; |
| 1330 | break; |
| 1331 | } |
| 1332 | |
| 1333 | memset(cdb, 0, sizeof(io_request->CDB.CDB32)); |
| 1334 | |
| 1335 | cdb[0] = opcode; |
| 1336 | cdb[1] = flagvals; |
| 1337 | cdb[14] = groupnum; |
| 1338 | cdb[15] = control; |
| 1339 | |
| 1340 | /* Transfer length */ |
| 1341 | cdb[13] = (u8)(num_blocks & 0xff); |
| 1342 | cdb[12] = (u8)((num_blocks >> 8) & 0xff); |
| 1343 | cdb[11] = (u8)((num_blocks >> 16) & 0xff); |
| 1344 | cdb[10] = (u8)((num_blocks >> 24) & 0xff); |
| 1345 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1346 | io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */ |
adam radford | 495c560 | 2011-05-11 18:34:40 -0700 | [diff] [blame] | 1347 | cdb_len = 16; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /* Normal case, just load LBA here */ |
| 1351 | switch (cdb_len) { |
| 1352 | case 6: |
| 1353 | { |
| 1354 | u8 val = cdb[1] & 0xE0; |
| 1355 | cdb[3] = (u8)(start_blk & 0xff); |
| 1356 | cdb[2] = (u8)((start_blk >> 8) & 0xff); |
| 1357 | cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f); |
| 1358 | break; |
| 1359 | } |
| 1360 | case 10: |
| 1361 | cdb[5] = (u8)(start_blk & 0xff); |
| 1362 | cdb[4] = (u8)((start_blk >> 8) & 0xff); |
| 1363 | cdb[3] = (u8)((start_blk >> 16) & 0xff); |
| 1364 | cdb[2] = (u8)((start_blk >> 24) & 0xff); |
| 1365 | break; |
| 1366 | case 12: |
| 1367 | cdb[5] = (u8)(start_blk & 0xff); |
| 1368 | cdb[4] = (u8)((start_blk >> 8) & 0xff); |
| 1369 | cdb[3] = (u8)((start_blk >> 16) & 0xff); |
| 1370 | cdb[2] = (u8)((start_blk >> 24) & 0xff); |
| 1371 | break; |
| 1372 | case 16: |
| 1373 | cdb[9] = (u8)(start_blk & 0xff); |
| 1374 | cdb[8] = (u8)((start_blk >> 8) & 0xff); |
| 1375 | cdb[7] = (u8)((start_blk >> 16) & 0xff); |
| 1376 | cdb[6] = (u8)((start_blk >> 24) & 0xff); |
| 1377 | cdb[5] = (u8)((start_blk >> 32) & 0xff); |
| 1378 | cdb[4] = (u8)((start_blk >> 40) & 0xff); |
| 1379 | cdb[3] = (u8)((start_blk >> 48) & 0xff); |
| 1380 | cdb[2] = (u8)((start_blk >> 56) & 0xff); |
| 1381 | break; |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * megasas_build_ldio_fusion - Prepares IOs to devices |
| 1388 | * @instance: Adapter soft state |
| 1389 | * @scp: SCSI command |
| 1390 | * @cmd: Command to be prepared |
| 1391 | * |
| 1392 | * Prepares the io_request and chain elements (sg_frame) for IO |
| 1393 | * The IO can be for PD (Fast Path) or LD |
| 1394 | */ |
| 1395 | void |
| 1396 | megasas_build_ldio_fusion(struct megasas_instance *instance, |
| 1397 | struct scsi_cmnd *scp, |
| 1398 | struct megasas_cmd_fusion *cmd) |
| 1399 | { |
| 1400 | u8 fp_possible; |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1401 | u32 start_lba_lo, start_lba_hi, device_id, datalength = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1402 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 1403 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 1404 | struct IO_REQUEST_INFO io_info; |
| 1405 | struct fusion_context *fusion; |
| 1406 | struct MR_FW_RAID_MAP_ALL *local_map_ptr; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1407 | u8 *raidLUN; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1408 | |
| 1409 | device_id = MEGASAS_DEV_INDEX(instance, scp); |
| 1410 | |
| 1411 | fusion = instance->ctrl_context; |
| 1412 | |
| 1413 | io_request = cmd->io_request; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1414 | io_request->RaidContext.VirtualDiskTgtId = cpu_to_le16(device_id); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1415 | io_request->RaidContext.status = 0; |
| 1416 | io_request->RaidContext.exStatus = 0; |
| 1417 | |
| 1418 | req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc; |
| 1419 | |
| 1420 | start_lba_lo = 0; |
| 1421 | start_lba_hi = 0; |
| 1422 | fp_possible = 0; |
| 1423 | |
| 1424 | /* |
| 1425 | * 6-byte READ(0x08) or WRITE(0x0A) cdb |
| 1426 | */ |
| 1427 | if (scp->cmd_len == 6) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1428 | datalength = (u32) scp->cmnd[4]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1429 | start_lba_lo = ((u32) scp->cmnd[1] << 16) | |
| 1430 | ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3]; |
| 1431 | |
| 1432 | start_lba_lo &= 0x1FFFFF; |
| 1433 | } |
| 1434 | |
| 1435 | /* |
| 1436 | * 10-byte READ(0x28) or WRITE(0x2A) cdb |
| 1437 | */ |
| 1438 | else if (scp->cmd_len == 10) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1439 | datalength = (u32) scp->cmnd[8] | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1440 | ((u32) scp->cmnd[7] << 8); |
| 1441 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 1442 | ((u32) scp->cmnd[3] << 16) | |
| 1443 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1444 | } |
| 1445 | |
| 1446 | /* |
| 1447 | * 12-byte READ(0xA8) or WRITE(0xAA) cdb |
| 1448 | */ |
| 1449 | else if (scp->cmd_len == 12) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1450 | datalength = ((u32) scp->cmnd[6] << 24) | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1451 | ((u32) scp->cmnd[7] << 16) | |
| 1452 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 1453 | start_lba_lo = ((u32) scp->cmnd[2] << 24) | |
| 1454 | ((u32) scp->cmnd[3] << 16) | |
| 1455 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * 16-byte READ(0x88) or WRITE(0x8A) cdb |
| 1460 | */ |
| 1461 | else if (scp->cmd_len == 16) { |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1462 | datalength = ((u32) scp->cmnd[10] << 24) | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1463 | ((u32) scp->cmnd[11] << 16) | |
| 1464 | ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13]; |
| 1465 | start_lba_lo = ((u32) scp->cmnd[6] << 24) | |
| 1466 | ((u32) scp->cmnd[7] << 16) | |
| 1467 | ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9]; |
| 1468 | |
| 1469 | start_lba_hi = ((u32) scp->cmnd[2] << 24) | |
| 1470 | ((u32) scp->cmnd[3] << 16) | |
| 1471 | ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5]; |
| 1472 | } |
| 1473 | |
| 1474 | memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO)); |
| 1475 | io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo; |
adam radford | f9eff81 | 2012-10-01 19:27:07 -0700 | [diff] [blame] | 1476 | io_info.numBlocks = datalength; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1477 | io_info.ldTgtId = device_id; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1478 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scp)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1479 | |
| 1480 | if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
| 1481 | io_info.isRead = 1; |
| 1482 | |
| 1483 | local_map_ptr = fusion->ld_map[(instance->map_id & 1)]; |
| 1484 | |
| 1485 | if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >= |
| 1486 | MAX_LOGICAL_DRIVES) || (!fusion->fast_path_io)) { |
| 1487 | io_request->RaidContext.regLockFlags = 0; |
| 1488 | fp_possible = 0; |
| 1489 | } else { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1490 | if (MR_BuildRaidContext(instance, &io_info, |
| 1491 | &io_request->RaidContext, |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1492 | local_map_ptr, &raidLUN)) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1493 | fp_possible = io_info.fpOkForIo; |
| 1494 | } |
| 1495 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1496 | /* Use smp_processor_id() for now until cmd->request->cpu is CPU |
| 1497 | id by default, not CPU group id, otherwise all MSI-X queues won't |
| 1498 | be utilized */ |
| 1499 | cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ? |
| 1500 | smp_processor_id() % instance->msix_vectors : 0; |
| 1501 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1502 | if (fp_possible) { |
| 1503 | megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp, |
| 1504 | local_map_ptr, start_lba_lo); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1505 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 1506 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1507 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY |
| 1508 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1509 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1510 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1511 | if (io_request->RaidContext.regLockFlags == |
| 1512 | REGION_TYPE_UNUSED) |
| 1513 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1514 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << |
| 1515 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1516 | io_request->RaidContext.Type = MPI2_TYPE_CUDA; |
| 1517 | io_request->RaidContext.nseg = 0x1; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1518 | 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] | 1519 | io_request->RaidContext.regLockFlags |= |
| 1520 | (MR_RL_FLAGS_GRANT_DESTINATION_CUDA | |
| 1521 | MR_RL_FLAGS_SEQ_NUM_ENABLE); |
| 1522 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1523 | if ((fusion->load_balance_info[device_id].loadBalanceFlag) && |
| 1524 | (io_info.isRead)) { |
| 1525 | io_info.devHandle = |
| 1526 | get_updated_dev_handle( |
| 1527 | &fusion->load_balance_info[device_id], |
| 1528 | &io_info); |
| 1529 | scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG; |
| 1530 | } else |
| 1531 | scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG; |
| 1532 | cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle; |
| 1533 | io_request->DevHandle = io_info.devHandle; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1534 | /* populate the LUN field */ |
| 1535 | memcpy(io_request->LUN, raidLUN, 8); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1536 | } else { |
| 1537 | io_request->RaidContext.timeoutValue = |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1538 | cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1539 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1540 | (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO |
| 1541 | << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 1542 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1543 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1544 | if (io_request->RaidContext.regLockFlags == |
| 1545 | REGION_TYPE_UNUSED) |
| 1546 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1547 | (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK << |
| 1548 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1549 | io_request->RaidContext.Type = MPI2_TYPE_CUDA; |
| 1550 | io_request->RaidContext.regLockFlags |= |
| 1551 | (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 | |
| 1552 | MR_RL_FLAGS_SEQ_NUM_ENABLE); |
| 1553 | io_request->RaidContext.nseg = 0x1; |
| 1554 | } |
| 1555 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1556 | io_request->DevHandle = cpu_to_le16(device_id); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1557 | } /* Not FP */ |
| 1558 | } |
| 1559 | |
| 1560 | /** |
| 1561 | * megasas_build_dcdb_fusion - Prepares IOs to devices |
| 1562 | * @instance: Adapter soft state |
| 1563 | * @scp: SCSI command |
| 1564 | * @cmd: Command to be prepared |
| 1565 | * |
| 1566 | * Prepares the io_request frame for non-io cmds |
| 1567 | */ |
| 1568 | static void |
| 1569 | megasas_build_dcdb_fusion(struct megasas_instance *instance, |
| 1570 | struct scsi_cmnd *scmd, |
| 1571 | struct megasas_cmd_fusion *cmd) |
| 1572 | { |
| 1573 | u32 device_id; |
| 1574 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request; |
| 1575 | u16 pd_index = 0; |
| 1576 | struct MR_FW_RAID_MAP_ALL *local_map_ptr; |
| 1577 | struct fusion_context *fusion = instance->ctrl_context; |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1578 | u8 span, physArm; |
| 1579 | u16 devHandle; |
| 1580 | u32 ld, arRef, pd; |
| 1581 | struct MR_LD_RAID *raid; |
| 1582 | struct RAID_CONTEXT *pRAID_Context; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1583 | |
| 1584 | io_request = cmd->io_request; |
| 1585 | device_id = MEGASAS_DEV_INDEX(instance, scmd); |
| 1586 | pd_index = (scmd->device->channel * MEGASAS_MAX_DEV_PER_CHANNEL) |
| 1587 | +scmd->device->id; |
| 1588 | local_map_ptr = fusion->ld_map[(instance->map_id & 1)]; |
| 1589 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1590 | io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd)); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1591 | |
| 1592 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1593 | /* Check if this is a system PD I/O */ |
adam radford | e187df6 | 2012-10-01 19:27:12 -0700 | [diff] [blame] | 1594 | if (scmd->device->channel < MEGASAS_MAX_PD_CHANNELS && |
| 1595 | instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1596 | io_request->Function = 0; |
adam radford | 9c5ebd0 | 2013-02-09 15:29:20 -0800 | [diff] [blame] | 1597 | if (fusion->fast_path_io) |
| 1598 | io_request->DevHandle = |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1599 | local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl; |
| 1600 | io_request->RaidContext.timeoutValue = |
| 1601 | local_map_ptr->raidMap.fpPdIoTimeoutSec; |
| 1602 | io_request->RaidContext.regLockFlags = 0; |
| 1603 | io_request->RaidContext.regLockRowLBA = 0; |
| 1604 | io_request->RaidContext.regLockLength = 0; |
| 1605 | io_request->RaidContext.RAIDFlags = |
| 1606 | MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD << |
| 1607 | MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT; |
Sumit.Saxena@lsi.com | 5d0d908 | 2013-05-22 12:33:29 +0530 | [diff] [blame] | 1608 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1609 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
| 1610 | io_request->IoFlags |= |
| 1611 | MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1612 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1613 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << |
| 1614 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
adam radford | 8ead581 | 2012-10-01 19:27:20 -0700 | [diff] [blame] | 1615 | cmd->request_desc->SCSIIO.DevHandle = |
| 1616 | local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl; |
Sumit.Saxena@lsi.com | 32d8745 | 2013-05-22 12:31:18 +0530 | [diff] [blame] | 1617 | /* |
| 1618 | * If the command is for the tape device, set the |
| 1619 | * FP timeout to the os layer timeout value. |
| 1620 | */ |
| 1621 | if (scmd->device->type == TYPE_TAPE) { |
| 1622 | if ((scmd->request->timeout / HZ) > 0xFFFF) |
| 1623 | io_request->RaidContext.timeoutValue = |
| 1624 | 0xFFFF; |
| 1625 | else |
| 1626 | io_request->RaidContext.timeoutValue = |
| 1627 | scmd->request->timeout / HZ; |
| 1628 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1629 | } else { |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1630 | if (scmd->device->channel < MEGASAS_MAX_PD_CHANNELS) |
| 1631 | goto NonFastPath; |
| 1632 | |
| 1633 | ld = MR_TargetIdToLdGet(device_id, local_map_ptr); |
| 1634 | if ((ld >= MAX_LOGICAL_DRIVES) || (!fusion->fast_path_io)) |
| 1635 | goto NonFastPath; |
| 1636 | |
| 1637 | raid = MR_LdRaidGet(ld, local_map_ptr); |
| 1638 | |
| 1639 | /* check if this LD is FP capable */ |
| 1640 | if (!(raid->capability.fpNonRWCapable)) |
| 1641 | /* not FP capable, send as non-FP */ |
| 1642 | goto NonFastPath; |
| 1643 | |
| 1644 | /* get RAID_Context pointer */ |
| 1645 | pRAID_Context = &io_request->RaidContext; |
| 1646 | |
| 1647 | /* set RAID context values */ |
| 1648 | pRAID_Context->regLockFlags = REGION_TYPE_SHARED_READ; |
| 1649 | pRAID_Context->timeoutValue = raid->fpIoTimeoutForLd; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1650 | pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id); |
adam radford | 21c9e16 | 2013-09-06 15:27:14 -0700 | [diff] [blame] | 1651 | pRAID_Context->regLockRowLBA = 0; |
| 1652 | pRAID_Context->regLockLength = 0; |
| 1653 | pRAID_Context->configSeqNum = raid->seqNum; |
| 1654 | |
| 1655 | /* get the DevHandle for the PD (since this is |
| 1656 | fpNonRWCapable, this is a single disk RAID0) */ |
| 1657 | span = physArm = 0; |
| 1658 | arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr); |
| 1659 | pd = MR_ArPdGet(arRef, physArm, local_map_ptr); |
| 1660 | devHandle = MR_PdDevHandleGet(pd, local_map_ptr); |
| 1661 | |
| 1662 | /* build request descriptor */ |
| 1663 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1664 | (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY << |
| 1665 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1666 | cmd->request_desc->SCSIIO.DevHandle = devHandle; |
| 1667 | |
| 1668 | /* populate the LUN field */ |
| 1669 | memcpy(io_request->LUN, raid->LUN, 8); |
| 1670 | |
| 1671 | /* build the raidScsiIO structure */ |
| 1672 | io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST; |
| 1673 | io_request->DevHandle = devHandle; |
| 1674 | |
| 1675 | return; |
| 1676 | |
| 1677 | NonFastPath: |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1678 | io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1679 | io_request->DevHandle = cpu_to_le16(device_id); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1680 | cmd->request_desc->SCSIIO.RequestFlags = |
| 1681 | (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
| 1682 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 1683 | } |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1684 | io_request->RaidContext.VirtualDiskTgtId = cpu_to_le16(device_id); |
adam radford | eaa3c24 | 2011-02-24 20:56:49 -0800 | [diff] [blame] | 1685 | io_request->LUN[1] = scmd->device->lun; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | /** |
| 1689 | * megasas_build_io_fusion - Prepares IOs to devices |
| 1690 | * @instance: Adapter soft state |
| 1691 | * @scp: SCSI command |
| 1692 | * @cmd: Command to be prepared |
| 1693 | * |
| 1694 | * Invokes helper functions to prepare request frames |
| 1695 | * and sets flags appropriate for IO/Non-IO cmd |
| 1696 | */ |
| 1697 | int |
| 1698 | megasas_build_io_fusion(struct megasas_instance *instance, |
| 1699 | struct scsi_cmnd *scp, |
| 1700 | struct megasas_cmd_fusion *cmd) |
| 1701 | { |
| 1702 | u32 device_id, sge_count; |
| 1703 | struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request; |
| 1704 | |
| 1705 | device_id = MEGASAS_DEV_INDEX(instance, scp); |
| 1706 | |
| 1707 | /* Zero out some fields so they don't get reused */ |
adam radford | eaa3c24 | 2011-02-24 20:56:49 -0800 | [diff] [blame] | 1708 | io_request->LUN[1] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1709 | io_request->CDB.EEDP32.PrimaryReferenceTag = 0; |
| 1710 | io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0; |
| 1711 | io_request->EEDPFlags = 0; |
| 1712 | io_request->Control = 0; |
| 1713 | io_request->EEDPBlockSize = 0; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1714 | io_request->ChainOffset = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1715 | io_request->RaidContext.RAIDFlags = 0; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 1716 | io_request->RaidContext.Type = 0; |
| 1717 | io_request->RaidContext.nseg = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1718 | |
| 1719 | memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len); |
| 1720 | /* |
| 1721 | * Just the CDB length,rest of the Flags are zero |
| 1722 | * This will be modified for FP in build_ldio_fusion |
| 1723 | */ |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1724 | io_request->IoFlags = cpu_to_le16(scp->cmd_len); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1725 | |
| 1726 | if (megasas_is_ldio(scp)) |
| 1727 | megasas_build_ldio_fusion(instance, scp, cmd); |
| 1728 | else |
| 1729 | megasas_build_dcdb_fusion(instance, scp, cmd); |
| 1730 | |
| 1731 | /* |
| 1732 | * Construct SGL |
| 1733 | */ |
| 1734 | |
| 1735 | sge_count = |
| 1736 | megasas_make_sgl_fusion(instance, scp, |
| 1737 | (struct MPI25_IEEE_SGE_CHAIN64 *) |
| 1738 | &io_request->SGL, cmd); |
| 1739 | |
| 1740 | if (sge_count > instance->max_num_sge) { |
| 1741 | printk(KERN_ERR "megasas: Error. sge_count (0x%x) exceeds " |
| 1742 | "max (0x%x) allowed\n", sge_count, |
| 1743 | instance->max_num_sge); |
| 1744 | return 1; |
| 1745 | } |
| 1746 | |
| 1747 | io_request->RaidContext.numSGE = sge_count; |
| 1748 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1749 | io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1750 | |
| 1751 | if (scp->sc_data_direction == PCI_DMA_TODEVICE) |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1752 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1753 | else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1754 | io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1755 | |
| 1756 | io_request->SGLOffset0 = |
| 1757 | offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4; |
| 1758 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1759 | io_request->SenseBufferLowAddress = cpu_to_le32(cmd->sense_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1760 | io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 1761 | |
| 1762 | cmd->scmd = scp; |
| 1763 | scp->SCp.ptr = (char *)cmd; |
| 1764 | |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
| 1768 | union MEGASAS_REQUEST_DESCRIPTOR_UNION * |
| 1769 | megasas_get_request_descriptor(struct megasas_instance *instance, u16 index) |
| 1770 | { |
| 1771 | u8 *p; |
| 1772 | struct fusion_context *fusion; |
| 1773 | |
| 1774 | if (index >= instance->max_fw_cmds) { |
| 1775 | printk(KERN_ERR "megasas: Invalid SMID (0x%x)request for " |
| 1776 | "descriptor\n", index); |
| 1777 | return NULL; |
| 1778 | } |
| 1779 | fusion = instance->ctrl_context; |
| 1780 | p = fusion->req_frames_desc |
| 1781 | +sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *index; |
| 1782 | |
| 1783 | return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p; |
| 1784 | } |
| 1785 | |
| 1786 | /** |
| 1787 | * megasas_build_and_issue_cmd_fusion -Main routine for building and |
| 1788 | * issuing non IOCTL cmd |
| 1789 | * @instance: Adapter soft state |
| 1790 | * @scmd: pointer to scsi cmd from OS |
| 1791 | */ |
| 1792 | static u32 |
| 1793 | megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance, |
| 1794 | struct scsi_cmnd *scmd) |
| 1795 | { |
| 1796 | struct megasas_cmd_fusion *cmd; |
| 1797 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 1798 | u32 index; |
| 1799 | struct fusion_context *fusion; |
| 1800 | |
| 1801 | fusion = instance->ctrl_context; |
| 1802 | |
| 1803 | cmd = megasas_get_cmd_fusion(instance); |
| 1804 | if (!cmd) |
| 1805 | return SCSI_MLQUEUE_HOST_BUSY; |
| 1806 | |
| 1807 | index = cmd->index; |
| 1808 | |
| 1809 | req_desc = megasas_get_request_descriptor(instance, index-1); |
| 1810 | if (!req_desc) |
| 1811 | return 1; |
| 1812 | |
| 1813 | req_desc->Words = 0; |
| 1814 | cmd->request_desc = req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1815 | |
| 1816 | if (megasas_build_io_fusion(instance, scmd, cmd)) { |
| 1817 | megasas_return_cmd_fusion(instance, cmd); |
| 1818 | printk(KERN_ERR "megasas: Error building command.\n"); |
| 1819 | cmd->request_desc = NULL; |
| 1820 | return 1; |
| 1821 | } |
| 1822 | |
| 1823 | req_desc = cmd->request_desc; |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1824 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1825 | |
| 1826 | if (cmd->io_request->ChainOffset != 0 && |
| 1827 | cmd->io_request->ChainOffset != 0xF) |
| 1828 | printk(KERN_ERR "megasas: The chain offset value is not " |
| 1829 | "correct : %x\n", cmd->io_request->ChainOffset); |
| 1830 | |
| 1831 | /* |
| 1832 | * Issue the command to the FW |
| 1833 | */ |
| 1834 | atomic_inc(&instance->fw_outstanding); |
| 1835 | |
| 1836 | instance->instancet->fire_cmd(instance, |
| 1837 | req_desc->u.low, req_desc->u.high, |
| 1838 | instance->reg_set); |
| 1839 | |
| 1840 | return 0; |
| 1841 | } |
| 1842 | |
| 1843 | /** |
| 1844 | * complete_cmd_fusion - Completes command |
| 1845 | * @instance: Adapter soft state |
| 1846 | * Completes all commands that is in reply descriptor queue |
| 1847 | */ |
| 1848 | int |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1849 | complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1850 | { |
| 1851 | union MPI2_REPLY_DESCRIPTORS_UNION *desc; |
| 1852 | struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc; |
| 1853 | struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req; |
| 1854 | struct fusion_context *fusion; |
| 1855 | struct megasas_cmd *cmd_mfi; |
| 1856 | struct megasas_cmd_fusion *cmd_fusion; |
| 1857 | u16 smid, num_completed; |
| 1858 | u8 reply_descript_type, arm; |
| 1859 | u32 status, extStatus, device_id; |
| 1860 | union desc_value d_val; |
| 1861 | struct LD_LOAD_BALANCE_INFO *lbinfo; |
| 1862 | |
| 1863 | fusion = instance->ctrl_context; |
| 1864 | |
| 1865 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) |
| 1866 | return IRQ_HANDLED; |
| 1867 | |
| 1868 | desc = fusion->reply_frames_desc; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1869 | desc += ((MSIxIndex * fusion->reply_alloc_sz)/ |
| 1870 | sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)) + |
| 1871 | fusion->last_reply_idx[MSIxIndex]; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1872 | |
| 1873 | reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; |
| 1874 | |
| 1875 | d_val.word = desc->Words; |
| 1876 | |
| 1877 | reply_descript_type = reply_desc->ReplyFlags & |
| 1878 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 1879 | |
| 1880 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 1881 | return IRQ_NONE; |
| 1882 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1883 | num_completed = 0; |
| 1884 | |
| 1885 | while ((d_val.u.low != UINT_MAX) && (d_val.u.high != UINT_MAX)) { |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 1886 | smid = le16_to_cpu(reply_desc->SMID); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1887 | |
| 1888 | cmd_fusion = fusion->cmd_list[smid - 1]; |
| 1889 | |
| 1890 | scsi_io_req = |
| 1891 | (struct MPI2_RAID_SCSI_IO_REQUEST *) |
| 1892 | cmd_fusion->io_request; |
| 1893 | |
| 1894 | if (cmd_fusion->scmd) |
| 1895 | cmd_fusion->scmd->SCp.ptr = NULL; |
| 1896 | |
| 1897 | status = scsi_io_req->RaidContext.status; |
| 1898 | extStatus = scsi_io_req->RaidContext.exStatus; |
| 1899 | |
| 1900 | switch (scsi_io_req->Function) { |
| 1901 | case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/ |
| 1902 | /* Update load balancing info */ |
| 1903 | device_id = MEGASAS_DEV_INDEX(instance, |
| 1904 | cmd_fusion->scmd); |
| 1905 | lbinfo = &fusion->load_balance_info[device_id]; |
| 1906 | if (cmd_fusion->scmd->SCp.Status & |
| 1907 | MEGASAS_LOAD_BALANCE_FLAG) { |
| 1908 | arm = lbinfo->raid1DevHandle[0] == |
| 1909 | cmd_fusion->io_request->DevHandle ? 0 : |
| 1910 | 1; |
| 1911 | atomic_dec(&lbinfo->scsi_pending_cmds[arm]); |
| 1912 | cmd_fusion->scmd->SCp.Status &= |
| 1913 | ~MEGASAS_LOAD_BALANCE_FLAG; |
| 1914 | } |
| 1915 | if (reply_descript_type == |
| 1916 | MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) { |
| 1917 | if (megasas_dbg_lvl == 5) |
| 1918 | printk(KERN_ERR "\nmegasas: FAST Path " |
| 1919 | "IO Success\n"); |
| 1920 | } |
| 1921 | /* Fall thru and complete IO */ |
| 1922 | case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */ |
| 1923 | /* Map the FW Cmd Status */ |
| 1924 | map_cmd_status(cmd_fusion, status, extStatus); |
| 1925 | scsi_dma_unmap(cmd_fusion->scmd); |
| 1926 | cmd_fusion->scmd->scsi_done(cmd_fusion->scmd); |
| 1927 | scsi_io_req->RaidContext.status = 0; |
| 1928 | scsi_io_req->RaidContext.exStatus = 0; |
| 1929 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 1930 | atomic_dec(&instance->fw_outstanding); |
| 1931 | |
| 1932 | break; |
| 1933 | case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */ |
| 1934 | cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx]; |
| 1935 | megasas_complete_cmd(instance, cmd_mfi, DID_OK); |
| 1936 | cmd_fusion->flags = 0; |
| 1937 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 1938 | |
| 1939 | break; |
| 1940 | } |
| 1941 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1942 | fusion->last_reply_idx[MSIxIndex]++; |
| 1943 | if (fusion->last_reply_idx[MSIxIndex] >= |
| 1944 | fusion->reply_q_depth) |
| 1945 | fusion->last_reply_idx[MSIxIndex] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1946 | |
| 1947 | desc->Words = ULLONG_MAX; |
| 1948 | num_completed++; |
| 1949 | |
| 1950 | /* Get the next reply descriptor */ |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1951 | if (!fusion->last_reply_idx[MSIxIndex]) |
| 1952 | desc = fusion->reply_frames_desc + |
| 1953 | ((MSIxIndex * fusion->reply_alloc_sz)/ |
| 1954 | sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1955 | else |
| 1956 | desc++; |
| 1957 | |
| 1958 | reply_desc = |
| 1959 | (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc; |
| 1960 | |
| 1961 | d_val.word = desc->Words; |
| 1962 | |
| 1963 | reply_descript_type = reply_desc->ReplyFlags & |
| 1964 | MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 1965 | |
| 1966 | if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 1967 | break; |
| 1968 | } |
| 1969 | |
| 1970 | if (!num_completed) |
| 1971 | return IRQ_NONE; |
| 1972 | |
| 1973 | wmb(); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 1974 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 1975 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) |
| 1976 | writel(((MSIxIndex & 0x7) << 24) | |
| 1977 | fusion->last_reply_idx[MSIxIndex], |
| 1978 | instance->reply_post_host_index_addr[MSIxIndex/8]); |
| 1979 | else |
| 1980 | writel((MSIxIndex << 24) | |
| 1981 | fusion->last_reply_idx[MSIxIndex], |
| 1982 | instance->reply_post_host_index_addr[0]); |
adam radford | 53ef2bb | 2011-02-24 20:56:05 -0800 | [diff] [blame] | 1983 | megasas_check_and_restore_queue_depth(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 1984 | return IRQ_HANDLED; |
| 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * megasas_complete_cmd_dpc_fusion - Completes command |
| 1989 | * @instance: Adapter soft state |
| 1990 | * |
| 1991 | * Tasklet to complete cmds |
| 1992 | */ |
| 1993 | void |
| 1994 | megasas_complete_cmd_dpc_fusion(unsigned long instance_addr) |
| 1995 | { |
| 1996 | struct megasas_instance *instance = |
| 1997 | (struct megasas_instance *)instance_addr; |
| 1998 | unsigned long flags; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 1999 | u32 count, MSIxIndex; |
| 2000 | |
| 2001 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2002 | |
| 2003 | /* If we have already declared adapter dead, donot complete cmds */ |
| 2004 | spin_lock_irqsave(&instance->hba_lock, flags); |
| 2005 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 2006 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2007 | return; |
| 2008 | } |
| 2009 | spin_unlock_irqrestore(&instance->hba_lock, flags); |
| 2010 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2011 | for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++) |
| 2012 | complete_cmd_fusion(instance, MSIxIndex); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | /** |
| 2016 | * megasas_isr_fusion - isr entry point |
| 2017 | */ |
| 2018 | irqreturn_t megasas_isr_fusion(int irq, void *devp) |
| 2019 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2020 | struct megasas_irq_context *irq_context = devp; |
| 2021 | struct megasas_instance *instance = irq_context->instance; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2022 | u32 mfiStatus, fw_state; |
| 2023 | |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2024 | if (instance->mask_interrupts) |
| 2025 | return IRQ_NONE; |
| 2026 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2027 | if (!instance->msix_vectors) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2028 | mfiStatus = instance->instancet->clear_intr(instance->reg_set); |
| 2029 | if (!mfiStatus) |
| 2030 | return IRQ_NONE; |
| 2031 | } |
| 2032 | |
| 2033 | /* If we are resetting, bail */ |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 2034 | if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) { |
| 2035 | instance->instancet->clear_intr(instance->reg_set); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2036 | return IRQ_HANDLED; |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 2037 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2038 | |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2039 | if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) { |
adam radford | 6497b24 | 2011-10-08 18:14:50 -0700 | [diff] [blame] | 2040 | instance->instancet->clear_intr(instance->reg_set); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2041 | /* If we didn't complete any commands, check for FW fault */ |
| 2042 | fw_state = instance->instancet->read_fw_status_reg( |
| 2043 | instance->reg_set) & MFI_STATE_MASK; |
| 2044 | if (fw_state == MFI_STATE_FAULT) |
| 2045 | schedule_work(&instance->work_init); |
| 2046 | } |
| 2047 | |
| 2048 | return IRQ_HANDLED; |
| 2049 | } |
| 2050 | |
| 2051 | /** |
| 2052 | * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru |
| 2053 | * @instance: Adapter soft state |
| 2054 | * mfi_cmd: megasas_cmd pointer |
| 2055 | * |
| 2056 | */ |
| 2057 | u8 |
| 2058 | build_mpt_mfi_pass_thru(struct megasas_instance *instance, |
| 2059 | struct megasas_cmd *mfi_cmd) |
| 2060 | { |
| 2061 | struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain; |
| 2062 | struct MPI2_RAID_SCSI_IO_REQUEST *io_req; |
| 2063 | struct megasas_cmd_fusion *cmd; |
| 2064 | struct fusion_context *fusion; |
| 2065 | struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr; |
| 2066 | |
| 2067 | cmd = megasas_get_cmd_fusion(instance); |
| 2068 | if (!cmd) |
| 2069 | return 1; |
| 2070 | |
| 2071 | /* Save the smid. To be used for returning the cmd */ |
| 2072 | mfi_cmd->context.smid = cmd->index; |
| 2073 | |
| 2074 | cmd->sync_cmd_idx = mfi_cmd->index; |
| 2075 | |
| 2076 | /* |
| 2077 | * For cmds where the flag is set, store the flag and check |
| 2078 | * on completion. For cmds with this flag, don't call |
| 2079 | * megasas_complete_cmd |
| 2080 | */ |
| 2081 | |
| 2082 | if (frame_hdr->flags & MFI_FRAME_DONT_POST_IN_REPLY_QUEUE) |
| 2083 | cmd->flags = MFI_FRAME_DONT_POST_IN_REPLY_QUEUE; |
| 2084 | |
| 2085 | fusion = instance->ctrl_context; |
| 2086 | io_req = cmd->io_request; |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2087 | |
Sumit.Saxena@lsi.com | 21d3c71 | 2013-05-22 12:31:43 +0530 | [diff] [blame] | 2088 | if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) || |
| 2089 | (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) { |
adam radford | 36807e6 | 2011-10-08 18:15:06 -0700 | [diff] [blame] | 2090 | struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = |
| 2091 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL; |
| 2092 | sgl_ptr_end += fusion->max_sge_in_main_msg - 1; |
| 2093 | sgl_ptr_end->Flags = 0; |
| 2094 | } |
| 2095 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2096 | mpi25_ieee_chain = |
| 2097 | (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain; |
| 2098 | |
| 2099 | io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST; |
| 2100 | io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, |
| 2101 | SGL) / 4; |
| 2102 | io_req->ChainOffset = fusion->chain_offset_mfi_pthru; |
| 2103 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2104 | mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2105 | |
| 2106 | mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 2107 | MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR; |
| 2108 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2109 | mpi25_ieee_chain->Length = cpu_to_le32(MEGASAS_MAX_SZ_CHAIN_FRAME); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2110 | |
| 2111 | return 0; |
| 2112 | } |
| 2113 | |
| 2114 | /** |
| 2115 | * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd |
| 2116 | * @instance: Adapter soft state |
| 2117 | * @cmd: mfi cmd to build |
| 2118 | * |
| 2119 | */ |
| 2120 | union MEGASAS_REQUEST_DESCRIPTOR_UNION * |
| 2121 | build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd) |
| 2122 | { |
| 2123 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
| 2124 | u16 index; |
| 2125 | |
| 2126 | if (build_mpt_mfi_pass_thru(instance, cmd)) { |
| 2127 | printk(KERN_ERR "Couldn't build MFI pass thru cmd\n"); |
| 2128 | return NULL; |
| 2129 | } |
| 2130 | |
| 2131 | index = cmd->context.smid; |
| 2132 | |
| 2133 | req_desc = megasas_get_request_descriptor(instance, index - 1); |
| 2134 | |
| 2135 | if (!req_desc) |
| 2136 | return NULL; |
| 2137 | |
| 2138 | req_desc->Words = 0; |
| 2139 | req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << |
| 2140 | MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT); |
| 2141 | |
Sumit.Saxena@lsi.com | 94cd65d | 2013-09-06 15:50:52 +0530 | [diff] [blame] | 2142 | req_desc->SCSIIO.SMID = cpu_to_le16(index); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2143 | |
| 2144 | return req_desc; |
| 2145 | } |
| 2146 | |
| 2147 | /** |
| 2148 | * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd |
| 2149 | * @instance: Adapter soft state |
| 2150 | * @cmd: mfi cmd pointer |
| 2151 | * |
| 2152 | */ |
| 2153 | void |
| 2154 | megasas_issue_dcmd_fusion(struct megasas_instance *instance, |
| 2155 | struct megasas_cmd *cmd) |
| 2156 | { |
| 2157 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2158 | |
| 2159 | req_desc = build_mpt_cmd(instance, cmd); |
| 2160 | if (!req_desc) { |
| 2161 | printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n"); |
| 2162 | return; |
| 2163 | } |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2164 | instance->instancet->fire_cmd(instance, req_desc->u.low, |
| 2165 | req_desc->u.high, instance->reg_set); |
| 2166 | } |
| 2167 | |
| 2168 | /** |
| 2169 | * megasas_release_fusion - Reverses the FW initialization |
| 2170 | * @intance: Adapter soft state |
| 2171 | */ |
| 2172 | void |
| 2173 | megasas_release_fusion(struct megasas_instance *instance) |
| 2174 | { |
| 2175 | megasas_free_cmds(instance); |
| 2176 | megasas_free_cmds_fusion(instance); |
| 2177 | |
| 2178 | iounmap(instance->reg_set); |
| 2179 | |
| 2180 | pci_release_selected_regions(instance->pdev, instance->bar); |
| 2181 | } |
| 2182 | |
| 2183 | /** |
| 2184 | * megasas_read_fw_status_reg_fusion - returns the current FW status value |
| 2185 | * @regs: MFI register set |
| 2186 | */ |
| 2187 | static u32 |
| 2188 | megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs) |
| 2189 | { |
| 2190 | return readl(&(regs)->outbound_scratch_pad); |
| 2191 | } |
| 2192 | |
| 2193 | /** |
| 2194 | * megasas_adp_reset_fusion - For controller reset |
| 2195 | * @regs: MFI register set |
| 2196 | */ |
| 2197 | static int |
| 2198 | megasas_adp_reset_fusion(struct megasas_instance *instance, |
| 2199 | struct megasas_register_set __iomem *regs) |
| 2200 | { |
| 2201 | return 0; |
| 2202 | } |
| 2203 | |
| 2204 | /** |
| 2205 | * megasas_check_reset_fusion - For controller reset check |
| 2206 | * @regs: MFI register set |
| 2207 | */ |
| 2208 | static int |
| 2209 | megasas_check_reset_fusion(struct megasas_instance *instance, |
| 2210 | struct megasas_register_set __iomem *regs) |
| 2211 | { |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
| 2215 | /* This function waits for outstanding commands on fusion to complete */ |
| 2216 | int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance) |
| 2217 | { |
| 2218 | int i, outstanding, retval = 0; |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2219 | u32 fw_state; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2220 | |
adam radford | c007b8b | 2012-07-17 18:20:24 -0700 | [diff] [blame] | 2221 | for (i = 0; i < resetwaittime; i++) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2222 | /* Check if firmware is in fault state */ |
| 2223 | fw_state = instance->instancet->read_fw_status_reg( |
| 2224 | instance->reg_set) & MFI_STATE_MASK; |
| 2225 | if (fw_state == MFI_STATE_FAULT) { |
| 2226 | printk(KERN_WARNING "megasas: Found FW in FAULT state," |
| 2227 | " will reset adapter.\n"); |
| 2228 | retval = 1; |
| 2229 | goto out; |
| 2230 | } |
| 2231 | |
| 2232 | outstanding = atomic_read(&instance->fw_outstanding); |
| 2233 | if (!outstanding) |
| 2234 | goto out; |
| 2235 | |
| 2236 | if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) { |
| 2237 | printk(KERN_NOTICE "megasas: [%2d]waiting for %d " |
| 2238 | "commands to complete\n", i, outstanding); |
| 2239 | megasas_complete_cmd_dpc_fusion( |
| 2240 | (unsigned long)instance); |
| 2241 | } |
| 2242 | msleep(1000); |
| 2243 | } |
| 2244 | |
| 2245 | if (atomic_read(&instance->fw_outstanding)) { |
| 2246 | printk("megaraid_sas: pending commands remain after waiting, " |
| 2247 | "will reset adapter.\n"); |
| 2248 | retval = 1; |
| 2249 | } |
| 2250 | out: |
| 2251 | return retval; |
| 2252 | } |
| 2253 | |
| 2254 | void megasas_reset_reply_desc(struct megasas_instance *instance) |
| 2255 | { |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2256 | int i, count; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2257 | struct fusion_context *fusion; |
| 2258 | union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc; |
| 2259 | |
| 2260 | fusion = instance->ctrl_context; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2261 | count = instance->msix_vectors > 0 ? instance->msix_vectors : 1; |
| 2262 | for (i = 0 ; i < count ; i++) |
| 2263 | fusion->last_reply_idx[i] = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2264 | reply_desc = fusion->reply_frames_desc; |
adam radford | c8e858f | 2011-10-08 18:15:13 -0700 | [diff] [blame] | 2265 | for (i = 0 ; i < fusion->reply_q_depth * count; i++, reply_desc++) |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2266 | reply_desc->Words = ULLONG_MAX; |
| 2267 | } |
| 2268 | |
| 2269 | /* Core fusion reset function */ |
| 2270 | int megasas_reset_fusion(struct Scsi_Host *shost) |
| 2271 | { |
| 2272 | int retval = SUCCESS, i, j, retry = 0; |
| 2273 | struct megasas_instance *instance; |
| 2274 | struct megasas_cmd_fusion *cmd_fusion; |
| 2275 | struct fusion_context *fusion; |
| 2276 | struct megasas_cmd *cmd_mfi; |
| 2277 | union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc; |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2278 | u32 host_diag, abs_state, status_reg, reset_adapter; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2279 | |
| 2280 | instance = (struct megasas_instance *)shost->hostdata; |
| 2281 | fusion = instance->ctrl_context; |
| 2282 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2283 | if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) { |
| 2284 | printk(KERN_WARNING "megaraid_sas: Hardware critical error, " |
| 2285 | "returning FAILED.\n"); |
adam radford | d4a759a | 2011-10-08 18:14:39 -0700 | [diff] [blame] | 2286 | return FAILED; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2287 | } |
| 2288 | |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2289 | mutex_lock(&instance->reset_mutex); |
| 2290 | set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
| 2291 | instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT; |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2292 | instance->instancet->disable_intr(instance); |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2293 | msleep(1000); |
| 2294 | |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2295 | /* First try waiting for commands to complete */ |
| 2296 | if (megasas_wait_for_outstanding_fusion(instance)) { |
| 2297 | printk(KERN_WARNING "megaraid_sas: resetting fusion " |
| 2298 | "adapter.\n"); |
| 2299 | /* Now return commands back to the OS */ |
| 2300 | for (i = 0 ; i < instance->max_fw_cmds; i++) { |
| 2301 | cmd_fusion = fusion->cmd_list[i]; |
| 2302 | if (cmd_fusion->scmd) { |
| 2303 | scsi_dma_unmap(cmd_fusion->scmd); |
| 2304 | cmd_fusion->scmd->result = (DID_RESET << 16); |
| 2305 | cmd_fusion->scmd->scsi_done(cmd_fusion->scmd); |
| 2306 | megasas_return_cmd_fusion(instance, cmd_fusion); |
| 2307 | atomic_dec(&instance->fw_outstanding); |
| 2308 | } |
| 2309 | } |
| 2310 | |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2311 | status_reg = instance->instancet->read_fw_status_reg( |
| 2312 | instance->reg_set); |
| 2313 | abs_state = status_reg & MFI_STATE_MASK; |
| 2314 | reset_adapter = status_reg & MFI_RESET_ADAPTER; |
| 2315 | if (instance->disableOnlineCtrlReset || |
| 2316 | (abs_state == MFI_STATE_FAULT && !reset_adapter)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2317 | /* Reset not supported, kill adapter */ |
| 2318 | printk(KERN_WARNING "megaraid_sas: Reset not supported" |
| 2319 | ", killing adapter.\n"); |
| 2320 | megaraid_sas_kill_hba(instance); |
| 2321 | instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR; |
| 2322 | retval = FAILED; |
| 2323 | goto out; |
| 2324 | } |
| 2325 | |
| 2326 | /* Now try to reset the chip */ |
| 2327 | for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) { |
| 2328 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, |
| 2329 | &instance->reg_set->fusion_seq_offset); |
| 2330 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, |
| 2331 | &instance->reg_set->fusion_seq_offset); |
| 2332 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, |
| 2333 | &instance->reg_set->fusion_seq_offset); |
| 2334 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, |
| 2335 | &instance->reg_set->fusion_seq_offset); |
| 2336 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, |
| 2337 | &instance->reg_set->fusion_seq_offset); |
| 2338 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, |
| 2339 | &instance->reg_set->fusion_seq_offset); |
| 2340 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, |
| 2341 | &instance->reg_set->fusion_seq_offset); |
| 2342 | |
| 2343 | /* Check that the diag write enable (DRWE) bit is on */ |
| 2344 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2345 | retry = 0; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2346 | while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) { |
| 2347 | msleep(100); |
| 2348 | host_diag = |
| 2349 | readl(&instance->reg_set->fusion_host_diag); |
| 2350 | if (retry++ == 100) { |
| 2351 | printk(KERN_WARNING "megaraid_sas: " |
| 2352 | "Host diag unlock failed!\n"); |
| 2353 | break; |
| 2354 | } |
| 2355 | } |
| 2356 | if (!(host_diag & HOST_DIAG_WRITE_ENABLE)) |
| 2357 | continue; |
| 2358 | |
| 2359 | /* Send chip reset command */ |
| 2360 | writel(host_diag | HOST_DIAG_RESET_ADAPTER, |
| 2361 | &instance->reg_set->fusion_host_diag); |
| 2362 | msleep(3000); |
| 2363 | |
| 2364 | /* Make sure reset adapter bit is cleared */ |
| 2365 | host_diag = readl(&instance->reg_set->fusion_host_diag); |
| 2366 | retry = 0; |
| 2367 | while (host_diag & HOST_DIAG_RESET_ADAPTER) { |
| 2368 | msleep(100); |
| 2369 | host_diag = |
| 2370 | readl(&instance->reg_set->fusion_host_diag); |
| 2371 | if (retry++ == 1000) { |
| 2372 | printk(KERN_WARNING "megaraid_sas: " |
| 2373 | "Diag reset adapter never " |
| 2374 | "cleared!\n"); |
| 2375 | break; |
| 2376 | } |
| 2377 | } |
| 2378 | if (host_diag & HOST_DIAG_RESET_ADAPTER) |
| 2379 | continue; |
| 2380 | |
| 2381 | abs_state = |
| 2382 | instance->instancet->read_fw_status_reg( |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2383 | instance->reg_set) & MFI_STATE_MASK; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2384 | retry = 0; |
| 2385 | |
| 2386 | while ((abs_state <= MFI_STATE_FW_INIT) && |
| 2387 | (retry++ < 1000)) { |
| 2388 | msleep(100); |
| 2389 | abs_state = |
| 2390 | instance->instancet->read_fw_status_reg( |
adam radford | 7e70e73 | 2011-05-11 18:34:08 -0700 | [diff] [blame] | 2391 | instance->reg_set) & MFI_STATE_MASK; |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2392 | } |
| 2393 | if (abs_state <= MFI_STATE_FW_INIT) { |
| 2394 | printk(KERN_WARNING "megaraid_sas: firmware " |
| 2395 | "state < MFI_STATE_FW_INIT, state = " |
| 2396 | "0x%x\n", abs_state); |
| 2397 | continue; |
| 2398 | } |
| 2399 | |
| 2400 | /* Wait for FW to become ready */ |
adam radford | 058a8fa | 2011-10-08 18:14:27 -0700 | [diff] [blame] | 2401 | if (megasas_transition_to_ready(instance, 1)) { |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2402 | printk(KERN_WARNING "megaraid_sas: Failed to " |
| 2403 | "transition controller to ready.\n"); |
| 2404 | continue; |
| 2405 | } |
| 2406 | |
| 2407 | megasas_reset_reply_desc(instance); |
| 2408 | if (megasas_ioc_init_fusion(instance)) { |
| 2409 | printk(KERN_WARNING "megaraid_sas: " |
| 2410 | "megasas_ioc_init_fusion() failed!\n"); |
| 2411 | continue; |
| 2412 | } |
| 2413 | |
adam radford | 3f0e58bc | 2011-10-08 18:14:59 -0700 | [diff] [blame] | 2414 | clear_bit(MEGASAS_FUSION_IN_RESET, |
| 2415 | &instance->reset_flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2416 | instance->instancet->enable_intr(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2417 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
| 2418 | |
| 2419 | /* Re-fire management commands */ |
| 2420 | for (j = 0 ; j < instance->max_fw_cmds; j++) { |
| 2421 | cmd_fusion = fusion->cmd_list[j]; |
| 2422 | if (cmd_fusion->sync_cmd_idx != |
| 2423 | (u32)ULONG_MAX) { |
| 2424 | cmd_mfi = |
| 2425 | instance-> |
| 2426 | cmd_list[cmd_fusion->sync_cmd_idx]; |
| 2427 | if (cmd_mfi->frame->dcmd.opcode == |
| 2428 | MR_DCMD_LD_MAP_GET_INFO) { |
| 2429 | megasas_return_cmd(instance, |
| 2430 | cmd_mfi); |
| 2431 | megasas_return_cmd_fusion( |
| 2432 | instance, cmd_fusion); |
| 2433 | } else { |
| 2434 | req_desc = |
| 2435 | megasas_get_request_descriptor( |
| 2436 | instance, |
| 2437 | cmd_mfi->context.smid |
| 2438 | -1); |
| 2439 | if (!req_desc) |
| 2440 | printk(KERN_WARNING |
| 2441 | "req_desc NULL" |
| 2442 | "\n"); |
| 2443 | else { |
| 2444 | instance->instancet-> |
| 2445 | fire_cmd(instance, |
| 2446 | req_desc-> |
| 2447 | u.low, |
| 2448 | req_desc-> |
| 2449 | u.high, |
| 2450 | instance-> |
| 2451 | reg_set); |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | /* Reset load balance info */ |
| 2458 | memset(fusion->load_balance_info, 0, |
| 2459 | sizeof(struct LD_LOAD_BALANCE_INFO) |
| 2460 | *MAX_LOGICAL_DRIVES); |
| 2461 | |
| 2462 | if (!megasas_get_map_info(instance)) |
| 2463 | megasas_sync_map_info(instance); |
| 2464 | |
| 2465 | /* Adapter reset completed successfully */ |
| 2466 | printk(KERN_WARNING "megaraid_sas: Reset " |
| 2467 | "successful.\n"); |
| 2468 | retval = SUCCESS; |
| 2469 | goto out; |
| 2470 | } |
| 2471 | /* Reset failed, kill the adapter */ |
| 2472 | printk(KERN_WARNING "megaraid_sas: Reset failed, killing " |
| 2473 | "adapter.\n"); |
| 2474 | megaraid_sas_kill_hba(instance); |
| 2475 | retval = FAILED; |
| 2476 | } else { |
adam radford | 3f0e58bc | 2011-10-08 18:14:59 -0700 | [diff] [blame] | 2477 | clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
Sumit.Saxena@lsi.com | d46a3ad | 2013-05-22 12:34:14 +0530 | [diff] [blame] | 2478 | instance->instancet->enable_intr(instance); |
adam radford | 9c915a8 | 2010-12-21 13:34:31 -0800 | [diff] [blame] | 2479 | instance->adprecovery = MEGASAS_HBA_OPERATIONAL; |
| 2480 | } |
| 2481 | out: |
| 2482 | clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); |
| 2483 | mutex_unlock(&instance->reset_mutex); |
| 2484 | return retval; |
| 2485 | } |
| 2486 | |
| 2487 | /* Fusion OCR work queue */ |
| 2488 | void megasas_fusion_ocr_wq(struct work_struct *work) |
| 2489 | { |
| 2490 | struct megasas_instance *instance = |
| 2491 | container_of(work, struct megasas_instance, work_init); |
| 2492 | |
| 2493 | megasas_reset_fusion(instance->host); |
| 2494 | } |
| 2495 | |
| 2496 | struct megasas_instance_template megasas_instance_template_fusion = { |
| 2497 | .fire_cmd = megasas_fire_cmd_fusion, |
| 2498 | .enable_intr = megasas_enable_intr_fusion, |
| 2499 | .disable_intr = megasas_disable_intr_fusion, |
| 2500 | .clear_intr = megasas_clear_intr_fusion, |
| 2501 | .read_fw_status_reg = megasas_read_fw_status_reg_fusion, |
| 2502 | .adp_reset = megasas_adp_reset_fusion, |
| 2503 | .check_reset = megasas_check_reset_fusion, |
| 2504 | .service_isr = megasas_isr_fusion, |
| 2505 | .tasklet = megasas_complete_cmd_dpc_fusion, |
| 2506 | .init_adapter = megasas_init_adapter_fusion, |
| 2507 | .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion, |
| 2508 | .issue_dcmd = megasas_issue_dcmd_fusion, |
| 2509 | }; |