2 * Linux MegaRAID driver for SAS based RAID controllers
4 * Copyright (c) 2003-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Authors: Avago Technologies
25 * Kashyap Desai <kashyap.desai@avagotech.com>
26 * Sumit Saxena <sumit.saxena@avagotech.com>
28 * Send feedback to: megaraidlinux.pdl@avagotech.com
30 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
31 * San Jose, California 95131
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/list.h>
38 #include <linux/moduleparam.h>
39 #include <linux/module.h>
40 #include <linux/spinlock.h>
41 #include <linux/interrupt.h>
42 #include <linux/delay.h>
43 #include <linux/uio.h>
44 #include <linux/slab.h>
45 #include <asm/uaccess.h>
47 #include <linux/compat.h>
48 #include <linux/blkdev.h>
49 #include <linux/mutex.h>
50 #include <linux/poll.h>
52 #include <scsi/scsi.h>
53 #include <scsi/scsi_cmnd.h>
54 #include <scsi/scsi_device.h>
55 #include <scsi/scsi_host.h>
56 #include <scsi/scsi_tcq.h>
57 #include "megaraid_sas_fusion.h"
58 #include "megaraid_sas.h"
61 * Number of sectors per IO command
62 * Will be set in megasas_init_mfi if user does not provide
64 static unsigned int max_sectors;
65 module_param_named(max_sectors, max_sectors, int, 0);
66 MODULE_PARM_DESC(max_sectors,
67 "Maximum number of sectors per IO command");
69 static int msix_disable;
70 module_param(msix_disable, int, S_IRUGO);
71 MODULE_PARM_DESC(msix_disable, "Disable MSI-X interrupt handling. Default: 0");
73 static unsigned int msix_vectors;
74 module_param(msix_vectors, int, S_IRUGO);
75 MODULE_PARM_DESC(msix_vectors, "MSI-X max vector count. Default: Set by FW");
77 static int allow_vf_ioctls;
78 module_param(allow_vf_ioctls, int, S_IRUGO);
79 MODULE_PARM_DESC(allow_vf_ioctls, "Allow ioctls in SR-IOV VF mode. Default: 0");
81 static unsigned int throttlequeuedepth = MEGASAS_THROTTLE_QUEUE_DEPTH;
82 module_param(throttlequeuedepth, int, S_IRUGO);
83 MODULE_PARM_DESC(throttlequeuedepth,
84 "Adapter queue depth when throttled due to I/O timeout. Default: 16");
86 int resetwaittime = MEGASAS_RESET_WAIT_TIME;
87 module_param(resetwaittime, int, S_IRUGO);
88 MODULE_PARM_DESC(resetwaittime, "Wait time in seconds after I/O timeout "
89 "before resetting adapter. Default: 180");
91 int smp_affinity_enable = 1;
92 module_param(smp_affinity_enable, int, S_IRUGO);
93 MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disbale Default: enable(1)");
95 MODULE_LICENSE("GPL");
96 MODULE_VERSION(MEGASAS_VERSION);
97 MODULE_AUTHOR("megaraidlinux.pdl@avagotech.com");
98 MODULE_DESCRIPTION("Avago MegaRAID SAS Driver");
100 int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
101 static int megasas_get_pd_list(struct megasas_instance *instance);
102 static int megasas_ld_list_query(struct megasas_instance *instance,
104 static int megasas_issue_init_mfi(struct megasas_instance *instance);
105 static int megasas_register_aen(struct megasas_instance *instance,
106 u32 seq_num, u32 class_locale_word);
108 * PCI ID table for all supported controllers
110 static struct pci_device_id megasas_pci_table[] = {
112 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1064R)},
114 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078R)},
116 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078DE)},
118 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS1078GEN2)},
120 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0079GEN2)},
122 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0073SKINNY)},
124 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_SAS0071SKINNY)},
126 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_VERDE_ZCR)},
127 /* xscale IOP, vega */
128 {PCI_DEVICE(PCI_VENDOR_ID_DELL, PCI_DEVICE_ID_DELL_PERC5)},
130 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FUSION)},
132 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_PLASMA)},
134 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_INVADER)},
136 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FURY)},
141 MODULE_DEVICE_TABLE(pci, megasas_pci_table);
143 static int megasas_mgmt_majorno;
144 struct megasas_mgmt_info megasas_mgmt_info;
145 static struct fasync_struct *megasas_async_queue;
146 static DEFINE_MUTEX(megasas_async_queue_mutex);
148 static int megasas_poll_wait_aen;
149 static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait);
150 static u32 support_poll_for_event;
152 static u32 support_device_change;
154 /* define lock for aen poll */
155 spinlock_t poll_aen_lock;
158 megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
161 megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs);
163 megasas_adp_reset_gen2(struct megasas_instance *instance,
164 struct megasas_register_set __iomem *reg_set);
165 static irqreturn_t megasas_isr(int irq, void *devp);
167 megasas_init_adapter_mfi(struct megasas_instance *instance);
169 megasas_build_and_issue_cmd(struct megasas_instance *instance,
170 struct scsi_cmnd *scmd);
171 static void megasas_complete_cmd_dpc(unsigned long instance_addr);
173 megasas_release_fusion(struct megasas_instance *instance);
175 megasas_ioc_init_fusion(struct megasas_instance *instance);
177 megasas_free_cmds_fusion(struct megasas_instance *instance);
179 megasas_get_map_info(struct megasas_instance *instance);
181 megasas_sync_map_info(struct megasas_instance *instance);
183 wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd,
185 void megasas_reset_reply_desc(struct megasas_instance *instance);
186 int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout);
187 void megasas_fusion_ocr_wq(struct work_struct *work);
188 static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance,
190 int megasas_check_mpio_paths(struct megasas_instance *instance,
191 struct scsi_cmnd *scmd);
194 megasas_issue_dcmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
196 instance->instancet->fire_cmd(instance,
197 cmd->frame_phys_addr, 0, instance->reg_set);
201 * megasas_get_cmd - Get a command from the free pool
202 * @instance: Adapter soft state
204 * Returns a free command from the pool
206 struct megasas_cmd *megasas_get_cmd(struct megasas_instance
210 struct megasas_cmd *cmd = NULL;
212 spin_lock_irqsave(&instance->mfi_pool_lock, flags);
214 if (!list_empty(&instance->cmd_pool)) {
215 cmd = list_entry((&instance->cmd_pool)->next,
216 struct megasas_cmd, list);
217 list_del_init(&cmd->list);
219 printk(KERN_ERR "megasas: Command pool empty!\n");
222 spin_unlock_irqrestore(&instance->mfi_pool_lock, flags);
227 * megasas_return_cmd - Return a cmd to free command pool
228 * @instance: Adapter soft state
229 * @cmd: Command packet to be returned to free command pool
232 megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
236 struct megasas_cmd_fusion *cmd_fusion;
237 struct fusion_context *fusion = instance->ctrl_context;
239 /* This flag is used only for fusion adapter.
240 * Wait for Interrupt for Polled mode DCMD
242 if (cmd->flags & DRV_DCMD_POLLED_MODE)
245 spin_lock_irqsave(&instance->mfi_pool_lock, flags);
248 blk_tags = instance->max_scsi_cmds + cmd->index;
249 cmd_fusion = fusion->cmd_list[blk_tags];
250 megasas_return_cmd_fusion(instance, cmd_fusion);
253 cmd->frame_count = 0;
255 if (!fusion && reset_devices)
256 cmd->frame->hdr.cmd = MFI_CMD_INVALID;
257 list_add(&cmd->list, (&instance->cmd_pool)->next);
259 spin_unlock_irqrestore(&instance->mfi_pool_lock, flags);
264 * The following functions are defined for xscale
265 * (deviceid : 1064R, PERC5) controllers
269 * megasas_enable_intr_xscale - Enables interrupts
270 * @regs: MFI register set
273 megasas_enable_intr_xscale(struct megasas_instance *instance)
275 struct megasas_register_set __iomem *regs;
276 regs = instance->reg_set;
277 writel(0, &(regs)->outbound_intr_mask);
279 /* Dummy readl to force pci flush */
280 readl(®s->outbound_intr_mask);
284 * megasas_disable_intr_xscale -Disables interrupt
285 * @regs: MFI register set
288 megasas_disable_intr_xscale(struct megasas_instance *instance)
290 struct megasas_register_set __iomem *regs;
292 regs = instance->reg_set;
293 writel(mask, ®s->outbound_intr_mask);
294 /* Dummy readl to force pci flush */
295 readl(®s->outbound_intr_mask);
299 * megasas_read_fw_status_reg_xscale - returns the current FW status value
300 * @regs: MFI register set
303 megasas_read_fw_status_reg_xscale(struct megasas_register_set __iomem * regs)
305 return readl(&(regs)->outbound_msg_0);
308 * megasas_clear_interrupt_xscale - Check & clear interrupt
309 * @regs: MFI register set
312 megasas_clear_intr_xscale(struct megasas_register_set __iomem * regs)
317 * Check if it is our interrupt
319 status = readl(®s->outbound_intr_status);
321 if (status & MFI_OB_INTR_STATUS_MASK)
322 mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE;
323 if (status & MFI_XSCALE_OMR0_CHANGE_INTERRUPT)
324 mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE;
327 * Clear the interrupt by writing back the same value
330 writel(status, ®s->outbound_intr_status);
332 /* Dummy readl to force pci flush */
333 readl(®s->outbound_intr_status);
339 * megasas_fire_cmd_xscale - Sends command to the FW
340 * @frame_phys_addr : Physical address of cmd
341 * @frame_count : Number of frames for the command
342 * @regs : MFI register set
345 megasas_fire_cmd_xscale(struct megasas_instance *instance,
346 dma_addr_t frame_phys_addr,
348 struct megasas_register_set __iomem *regs)
351 spin_lock_irqsave(&instance->hba_lock, flags);
352 writel((frame_phys_addr >> 3)|(frame_count),
353 &(regs)->inbound_queue_port);
354 spin_unlock_irqrestore(&instance->hba_lock, flags);
358 * megasas_adp_reset_xscale - For controller reset
359 * @regs: MFI register set
362 megasas_adp_reset_xscale(struct megasas_instance *instance,
363 struct megasas_register_set __iomem *regs)
367 writel(MFI_ADP_RESET, ®s->inbound_doorbell);
369 for (i = 0; i < 3; i++)
370 msleep(1000); /* sleep for 3 secs */
372 pci_read_config_dword(instance->pdev, MFI_1068_PCSR_OFFSET, &pcidata);
373 printk(KERN_NOTICE "pcidata = %x\n", pcidata);
375 printk(KERN_NOTICE "mfi 1068 offset read=%x\n", pcidata);
377 pci_write_config_dword(instance->pdev,
378 MFI_1068_PCSR_OFFSET, pcidata);
380 for (i = 0; i < 2; i++)
381 msleep(1000); /* need to wait 2 secs again */
384 pci_read_config_dword(instance->pdev,
385 MFI_1068_FW_HANDSHAKE_OFFSET, &pcidata);
386 printk(KERN_NOTICE "1068 offset handshake read=%x\n", pcidata);
387 if ((pcidata & 0xffff0000) == MFI_1068_FW_READY) {
388 printk(KERN_NOTICE "1068 offset pcidt=%x\n", pcidata);
390 pci_write_config_dword(instance->pdev,
391 MFI_1068_FW_HANDSHAKE_OFFSET, pcidata);
398 * megasas_check_reset_xscale - For controller reset check
399 * @regs: MFI register set
402 megasas_check_reset_xscale(struct megasas_instance *instance,
403 struct megasas_register_set __iomem *regs)
406 if ((instance->adprecovery != MEGASAS_HBA_OPERATIONAL) &&
407 (le32_to_cpu(*instance->consumer) ==
408 MEGASAS_ADPRESET_INPROG_SIGN))
413 static struct megasas_instance_template megasas_instance_template_xscale = {
415 .fire_cmd = megasas_fire_cmd_xscale,
416 .enable_intr = megasas_enable_intr_xscale,
417 .disable_intr = megasas_disable_intr_xscale,
418 .clear_intr = megasas_clear_intr_xscale,
419 .read_fw_status_reg = megasas_read_fw_status_reg_xscale,
420 .adp_reset = megasas_adp_reset_xscale,
421 .check_reset = megasas_check_reset_xscale,
422 .service_isr = megasas_isr,
423 .tasklet = megasas_complete_cmd_dpc,
424 .init_adapter = megasas_init_adapter_mfi,
425 .build_and_issue_cmd = megasas_build_and_issue_cmd,
426 .issue_dcmd = megasas_issue_dcmd,
430 * This is the end of set of functions & definitions specific
431 * to xscale (deviceid : 1064R, PERC5) controllers
435 * The following functions are defined for ppc (deviceid : 0x60)
440 * megasas_enable_intr_ppc - Enables interrupts
441 * @regs: MFI register set
444 megasas_enable_intr_ppc(struct megasas_instance *instance)
446 struct megasas_register_set __iomem *regs;
447 regs = instance->reg_set;
448 writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear);
450 writel(~0x80000000, &(regs)->outbound_intr_mask);
452 /* Dummy readl to force pci flush */
453 readl(®s->outbound_intr_mask);
457 * megasas_disable_intr_ppc - Disable interrupt
458 * @regs: MFI register set
461 megasas_disable_intr_ppc(struct megasas_instance *instance)
463 struct megasas_register_set __iomem *regs;
464 u32 mask = 0xFFFFFFFF;
465 regs = instance->reg_set;
466 writel(mask, ®s->outbound_intr_mask);
467 /* Dummy readl to force pci flush */
468 readl(®s->outbound_intr_mask);
472 * megasas_read_fw_status_reg_ppc - returns the current FW status value
473 * @regs: MFI register set
476 megasas_read_fw_status_reg_ppc(struct megasas_register_set __iomem * regs)
478 return readl(&(regs)->outbound_scratch_pad);
482 * megasas_clear_interrupt_ppc - Check & clear interrupt
483 * @regs: MFI register set
486 megasas_clear_intr_ppc(struct megasas_register_set __iomem * regs)
488 u32 status, mfiStatus = 0;
491 * Check if it is our interrupt
493 status = readl(®s->outbound_intr_status);
495 if (status & MFI_REPLY_1078_MESSAGE_INTERRUPT)
496 mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE;
498 if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT)
499 mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE;
502 * Clear the interrupt by writing back the same value
504 writel(status, ®s->outbound_doorbell_clear);
506 /* Dummy readl to force pci flush */
507 readl(®s->outbound_doorbell_clear);
513 * megasas_fire_cmd_ppc - Sends command to the FW
514 * @frame_phys_addr : Physical address of cmd
515 * @frame_count : Number of frames for the command
516 * @regs : MFI register set
519 megasas_fire_cmd_ppc(struct megasas_instance *instance,
520 dma_addr_t frame_phys_addr,
522 struct megasas_register_set __iomem *regs)
525 spin_lock_irqsave(&instance->hba_lock, flags);
526 writel((frame_phys_addr | (frame_count<<1))|1,
527 &(regs)->inbound_queue_port);
528 spin_unlock_irqrestore(&instance->hba_lock, flags);
532 * megasas_check_reset_ppc - For controller reset check
533 * @regs: MFI register set
536 megasas_check_reset_ppc(struct megasas_instance *instance,
537 struct megasas_register_set __iomem *regs)
539 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL)
545 static struct megasas_instance_template megasas_instance_template_ppc = {
547 .fire_cmd = megasas_fire_cmd_ppc,
548 .enable_intr = megasas_enable_intr_ppc,
549 .disable_intr = megasas_disable_intr_ppc,
550 .clear_intr = megasas_clear_intr_ppc,
551 .read_fw_status_reg = megasas_read_fw_status_reg_ppc,
552 .adp_reset = megasas_adp_reset_xscale,
553 .check_reset = megasas_check_reset_ppc,
554 .service_isr = megasas_isr,
555 .tasklet = megasas_complete_cmd_dpc,
556 .init_adapter = megasas_init_adapter_mfi,
557 .build_and_issue_cmd = megasas_build_and_issue_cmd,
558 .issue_dcmd = megasas_issue_dcmd,
562 * megasas_enable_intr_skinny - Enables interrupts
563 * @regs: MFI register set
566 megasas_enable_intr_skinny(struct megasas_instance *instance)
568 struct megasas_register_set __iomem *regs;
569 regs = instance->reg_set;
570 writel(0xFFFFFFFF, &(regs)->outbound_intr_mask);
572 writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
574 /* Dummy readl to force pci flush */
575 readl(®s->outbound_intr_mask);
579 * megasas_disable_intr_skinny - Disables interrupt
580 * @regs: MFI register set
583 megasas_disable_intr_skinny(struct megasas_instance *instance)
585 struct megasas_register_set __iomem *regs;
586 u32 mask = 0xFFFFFFFF;
587 regs = instance->reg_set;
588 writel(mask, ®s->outbound_intr_mask);
589 /* Dummy readl to force pci flush */
590 readl(®s->outbound_intr_mask);
594 * megasas_read_fw_status_reg_skinny - returns the current FW status value
595 * @regs: MFI register set
598 megasas_read_fw_status_reg_skinny(struct megasas_register_set __iomem *regs)
600 return readl(&(regs)->outbound_scratch_pad);
604 * megasas_clear_interrupt_skinny - Check & clear interrupt
605 * @regs: MFI register set
608 megasas_clear_intr_skinny(struct megasas_register_set __iomem *regs)
614 * Check if it is our interrupt
616 status = readl(®s->outbound_intr_status);
618 if (!(status & MFI_SKINNY_ENABLE_INTERRUPT_MASK)) {
623 * Check if it is our interrupt
625 if ((megasas_read_fw_status_reg_skinny(regs) & MFI_STATE_MASK) ==
627 mfiStatus = MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE;
629 mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE;
632 * Clear the interrupt by writing back the same value
634 writel(status, ®s->outbound_intr_status);
637 * dummy read to flush PCI
639 readl(®s->outbound_intr_status);
645 * megasas_fire_cmd_skinny - Sends command to the FW
646 * @frame_phys_addr : Physical address of cmd
647 * @frame_count : Number of frames for the command
648 * @regs : MFI register set
651 megasas_fire_cmd_skinny(struct megasas_instance *instance,
652 dma_addr_t frame_phys_addr,
654 struct megasas_register_set __iomem *regs)
657 spin_lock_irqsave(&instance->hba_lock, flags);
658 writel(upper_32_bits(frame_phys_addr),
659 &(regs)->inbound_high_queue_port);
660 writel((lower_32_bits(frame_phys_addr) | (frame_count<<1))|1,
661 &(regs)->inbound_low_queue_port);
662 spin_unlock_irqrestore(&instance->hba_lock, flags);
666 * megasas_check_reset_skinny - For controller reset check
667 * @regs: MFI register set
670 megasas_check_reset_skinny(struct megasas_instance *instance,
671 struct megasas_register_set __iomem *regs)
673 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL)
679 static struct megasas_instance_template megasas_instance_template_skinny = {
681 .fire_cmd = megasas_fire_cmd_skinny,
682 .enable_intr = megasas_enable_intr_skinny,
683 .disable_intr = megasas_disable_intr_skinny,
684 .clear_intr = megasas_clear_intr_skinny,
685 .read_fw_status_reg = megasas_read_fw_status_reg_skinny,
686 .adp_reset = megasas_adp_reset_gen2,
687 .check_reset = megasas_check_reset_skinny,
688 .service_isr = megasas_isr,
689 .tasklet = megasas_complete_cmd_dpc,
690 .init_adapter = megasas_init_adapter_mfi,
691 .build_and_issue_cmd = megasas_build_and_issue_cmd,
692 .issue_dcmd = megasas_issue_dcmd,
697 * The following functions are defined for gen2 (deviceid : 0x78 0x79)
702 * megasas_enable_intr_gen2 - Enables interrupts
703 * @regs: MFI register set
706 megasas_enable_intr_gen2(struct megasas_instance *instance)
708 struct megasas_register_set __iomem *regs;
709 regs = instance->reg_set;
710 writel(0xFFFFFFFF, &(regs)->outbound_doorbell_clear);
712 /* write ~0x00000005 (4 & 1) to the intr mask*/
713 writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
715 /* Dummy readl to force pci flush */
716 readl(®s->outbound_intr_mask);
720 * megasas_disable_intr_gen2 - Disables interrupt
721 * @regs: MFI register set
724 megasas_disable_intr_gen2(struct megasas_instance *instance)
726 struct megasas_register_set __iomem *regs;
727 u32 mask = 0xFFFFFFFF;
728 regs = instance->reg_set;
729 writel(mask, ®s->outbound_intr_mask);
730 /* Dummy readl to force pci flush */
731 readl(®s->outbound_intr_mask);
735 * megasas_read_fw_status_reg_gen2 - returns the current FW status value
736 * @regs: MFI register set
739 megasas_read_fw_status_reg_gen2(struct megasas_register_set __iomem *regs)
741 return readl(&(regs)->outbound_scratch_pad);
745 * megasas_clear_interrupt_gen2 - Check & clear interrupt
746 * @regs: MFI register set
749 megasas_clear_intr_gen2(struct megasas_register_set __iomem *regs)
754 * Check if it is our interrupt
756 status = readl(®s->outbound_intr_status);
758 if (status & MFI_INTR_FLAG_REPLY_MESSAGE) {
759 mfiStatus = MFI_INTR_FLAG_REPLY_MESSAGE;
761 if (status & MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT) {
762 mfiStatus |= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE;
766 * Clear the interrupt by writing back the same value
769 writel(status, ®s->outbound_doorbell_clear);
771 /* Dummy readl to force pci flush */
772 readl(®s->outbound_intr_status);
777 * megasas_fire_cmd_gen2 - Sends command to the FW
778 * @frame_phys_addr : Physical address of cmd
779 * @frame_count : Number of frames for the command
780 * @regs : MFI register set
783 megasas_fire_cmd_gen2(struct megasas_instance *instance,
784 dma_addr_t frame_phys_addr,
786 struct megasas_register_set __iomem *regs)
789 spin_lock_irqsave(&instance->hba_lock, flags);
790 writel((frame_phys_addr | (frame_count<<1))|1,
791 &(regs)->inbound_queue_port);
792 spin_unlock_irqrestore(&instance->hba_lock, flags);
796 * megasas_adp_reset_gen2 - For controller reset
797 * @regs: MFI register set
800 megasas_adp_reset_gen2(struct megasas_instance *instance,
801 struct megasas_register_set __iomem *reg_set)
805 u32 __iomem *seq_offset = ®_set->seq_offset;
806 u32 __iomem *hostdiag_offset = ®_set->host_diag;
808 if (instance->instancet == &megasas_instance_template_skinny) {
809 seq_offset = ®_set->fusion_seq_offset;
810 hostdiag_offset = ®_set->fusion_host_diag;
813 writel(0, seq_offset);
814 writel(4, seq_offset);
815 writel(0xb, seq_offset);
816 writel(2, seq_offset);
817 writel(7, seq_offset);
818 writel(0xd, seq_offset);
822 HostDiag = (u32)readl(hostdiag_offset);
824 while ( !( HostDiag & DIAG_WRITE_ENABLE) ) {
826 HostDiag = (u32)readl(hostdiag_offset);
827 printk(KERN_NOTICE "RESETGEN2: retry=%x, hostdiag=%x\n",
835 printk(KERN_NOTICE "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag);
837 writel((HostDiag | DIAG_RESET_ADAPTER), hostdiag_offset);
841 HostDiag = (u32)readl(hostdiag_offset);
842 while ( ( HostDiag & DIAG_RESET_ADAPTER) ) {
844 HostDiag = (u32)readl(hostdiag_offset);
845 printk(KERN_NOTICE "RESET_GEN2: retry=%x, hostdiag=%x\n",
856 * megasas_check_reset_gen2 - For controller reset check
857 * @regs: MFI register set
860 megasas_check_reset_gen2(struct megasas_instance *instance,
861 struct megasas_register_set __iomem *regs)
863 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) {
870 static struct megasas_instance_template megasas_instance_template_gen2 = {
872 .fire_cmd = megasas_fire_cmd_gen2,
873 .enable_intr = megasas_enable_intr_gen2,
874 .disable_intr = megasas_disable_intr_gen2,
875 .clear_intr = megasas_clear_intr_gen2,
876 .read_fw_status_reg = megasas_read_fw_status_reg_gen2,
877 .adp_reset = megasas_adp_reset_gen2,
878 .check_reset = megasas_check_reset_gen2,
879 .service_isr = megasas_isr,
880 .tasklet = megasas_complete_cmd_dpc,
881 .init_adapter = megasas_init_adapter_mfi,
882 .build_and_issue_cmd = megasas_build_and_issue_cmd,
883 .issue_dcmd = megasas_issue_dcmd,
887 * This is the end of set of functions & definitions
888 * specific to gen2 (deviceid : 0x78, 0x79) controllers
892 * Template added for TB (Fusion)
894 extern struct megasas_instance_template megasas_instance_template_fusion;
897 * megasas_issue_polled - Issues a polling command
898 * @instance: Adapter soft state
899 * @cmd: Command packet to be issued
901 * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
904 megasas_issue_polled(struct megasas_instance *instance, struct megasas_cmd *cmd)
908 struct megasas_header *frame_hdr = &cmd->frame->hdr;
910 frame_hdr->cmd_status = MFI_CMD_STATUS_POLL_MODE;
911 frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE);
914 * Issue the frame using inbound queue port
916 instance->instancet->issue_dcmd(instance, cmd);
919 * Wait for cmd_status to change
921 if (instance->requestorId)
922 seconds = MEGASAS_ROUTINE_WAIT_TIME_VF;
924 seconds = MFI_POLL_TIMEOUT_SECS;
925 return wait_and_poll(instance, cmd, seconds);
929 * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds
930 * @instance: Adapter soft state
931 * @cmd: Command to be issued
932 * @timeout: Timeout in seconds
934 * This function waits on an event for the command to be returned from ISR.
935 * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs
936 * Used to issue ioctl commands.
939 megasas_issue_blocked_cmd(struct megasas_instance *instance,
940 struct megasas_cmd *cmd, int timeout)
943 cmd->cmd_status = ENODATA;
945 instance->instancet->issue_dcmd(instance, cmd);
947 ret = wait_event_timeout(instance->int_cmd_wait_q,
948 cmd->cmd_status != ENODATA, timeout * HZ);
952 wait_event(instance->int_cmd_wait_q,
953 cmd->cmd_status != ENODATA);
959 * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd
960 * @instance: Adapter soft state
961 * @cmd_to_abort: Previously issued cmd to be aborted
962 * @timeout: Timeout in seconds
964 * MFI firmware can abort previously issued AEN comamnd (automatic event
965 * notification). The megasas_issue_blocked_abort_cmd() issues such abort
966 * cmd and waits for return status.
967 * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs
970 megasas_issue_blocked_abort_cmd(struct megasas_instance *instance,
971 struct megasas_cmd *cmd_to_abort, int timeout)
973 struct megasas_cmd *cmd;
974 struct megasas_abort_frame *abort_fr;
977 cmd = megasas_get_cmd(instance);
982 abort_fr = &cmd->frame->abort;
985 * Prepare and issue the abort frame
987 abort_fr->cmd = MFI_CMD_ABORT;
988 abort_fr->cmd_status = 0xFF;
989 abort_fr->flags = cpu_to_le16(0);
990 abort_fr->abort_context = cpu_to_le32(cmd_to_abort->index);
991 abort_fr->abort_mfi_phys_addr_lo =
992 cpu_to_le32(lower_32_bits(cmd_to_abort->frame_phys_addr));
993 abort_fr->abort_mfi_phys_addr_hi =
994 cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr));
997 cmd->cmd_status = ENODATA;
999 instance->instancet->issue_dcmd(instance, cmd);
1002 ret = wait_event_timeout(instance->abort_cmd_wait_q,
1003 cmd->cmd_status != ENODATA, timeout * HZ);
1005 dev_err(&instance->pdev->dev, "Command timedout"
1006 "from %s\n", __func__);
1010 wait_event(instance->abort_cmd_wait_q,
1011 cmd->cmd_status != ENODATA);
1015 megasas_return_cmd(instance, cmd);
1020 * megasas_make_sgl32 - Prepares 32-bit SGL
1021 * @instance: Adapter soft state
1022 * @scp: SCSI command from the mid-layer
1023 * @mfi_sgl: SGL to be filled in
1025 * If successful, this function returns the number of SG elements. Otherwise,
1029 megasas_make_sgl32(struct megasas_instance *instance, struct scsi_cmnd *scp,
1030 union megasas_sgl *mfi_sgl)
1034 struct scatterlist *os_sgl;
1036 sge_count = scsi_dma_map(scp);
1037 BUG_ON(sge_count < 0);
1040 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
1041 mfi_sgl->sge32[i].length = cpu_to_le32(sg_dma_len(os_sgl));
1042 mfi_sgl->sge32[i].phys_addr = cpu_to_le32(sg_dma_address(os_sgl));
1049 * megasas_make_sgl64 - Prepares 64-bit SGL
1050 * @instance: Adapter soft state
1051 * @scp: SCSI command from the mid-layer
1052 * @mfi_sgl: SGL to be filled in
1054 * If successful, this function returns the number of SG elements. Otherwise,
1058 megasas_make_sgl64(struct megasas_instance *instance, struct scsi_cmnd *scp,
1059 union megasas_sgl *mfi_sgl)
1063 struct scatterlist *os_sgl;
1065 sge_count = scsi_dma_map(scp);
1066 BUG_ON(sge_count < 0);
1069 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
1070 mfi_sgl->sge64[i].length = cpu_to_le32(sg_dma_len(os_sgl));
1071 mfi_sgl->sge64[i].phys_addr = cpu_to_le64(sg_dma_address(os_sgl));
1078 * megasas_make_sgl_skinny - Prepares IEEE SGL
1079 * @instance: Adapter soft state
1080 * @scp: SCSI command from the mid-layer
1081 * @mfi_sgl: SGL to be filled in
1083 * If successful, this function returns the number of SG elements. Otherwise,
1087 megasas_make_sgl_skinny(struct megasas_instance *instance,
1088 struct scsi_cmnd *scp, union megasas_sgl *mfi_sgl)
1092 struct scatterlist *os_sgl;
1094 sge_count = scsi_dma_map(scp);
1097 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
1098 mfi_sgl->sge_skinny[i].length =
1099 cpu_to_le32(sg_dma_len(os_sgl));
1100 mfi_sgl->sge_skinny[i].phys_addr =
1101 cpu_to_le64(sg_dma_address(os_sgl));
1102 mfi_sgl->sge_skinny[i].flag = cpu_to_le32(0);
1109 * megasas_get_frame_count - Computes the number of frames
1110 * @frame_type : type of frame- io or pthru frame
1111 * @sge_count : number of sg elements
1113 * Returns the number of frames required for numnber of sge's (sge_count)
1116 static u32 megasas_get_frame_count(struct megasas_instance *instance,
1117 u8 sge_count, u8 frame_type)
1124 sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) :
1125 sizeof(struct megasas_sge32);
1127 if (instance->flag_ieee) {
1128 sge_sz = sizeof(struct megasas_sge_skinny);
1132 * Main frame can contain 2 SGEs for 64-bit SGLs and
1133 * 3 SGEs for 32-bit SGLs for ldio &
1134 * 1 SGEs for 64-bit SGLs and
1135 * 2 SGEs for 32-bit SGLs for pthru frame
1137 if (unlikely(frame_type == PTHRU_FRAME)) {
1138 if (instance->flag_ieee == 1) {
1139 num_cnt = sge_count - 1;
1140 } else if (IS_DMA64)
1141 num_cnt = sge_count - 1;
1143 num_cnt = sge_count - 2;
1145 if (instance->flag_ieee == 1) {
1146 num_cnt = sge_count - 1;
1147 } else if (IS_DMA64)
1148 num_cnt = sge_count - 2;
1150 num_cnt = sge_count - 3;
1154 sge_bytes = sge_sz * num_cnt;
1156 frame_count = (sge_bytes / MEGAMFI_FRAME_SIZE) +
1157 ((sge_bytes % MEGAMFI_FRAME_SIZE) ? 1 : 0) ;
1162 if (frame_count > 7)
1168 * megasas_build_dcdb - Prepares a direct cdb (DCDB) command
1169 * @instance: Adapter soft state
1170 * @scp: SCSI command
1171 * @cmd: Command to be prepared in
1173 * This function prepares CDB commands. These are typcially pass-through
1174 * commands to the devices.
1177 megasas_build_dcdb(struct megasas_instance *instance, struct scsi_cmnd *scp,
1178 struct megasas_cmd *cmd)
1183 struct megasas_pthru_frame *pthru;
1185 is_logical = MEGASAS_IS_LOGICAL(scp);
1186 device_id = MEGASAS_DEV_INDEX(scp);
1187 pthru = (struct megasas_pthru_frame *)cmd->frame;
1189 if (scp->sc_data_direction == PCI_DMA_TODEVICE)
1190 flags = MFI_FRAME_DIR_WRITE;
1191 else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
1192 flags = MFI_FRAME_DIR_READ;
1193 else if (scp->sc_data_direction == PCI_DMA_NONE)
1194 flags = MFI_FRAME_DIR_NONE;
1196 if (instance->flag_ieee == 1) {
1197 flags |= MFI_FRAME_IEEE;
1201 * Prepare the DCDB frame
1203 pthru->cmd = (is_logical) ? MFI_CMD_LD_SCSI_IO : MFI_CMD_PD_SCSI_IO;
1204 pthru->cmd_status = 0x0;
1205 pthru->scsi_status = 0x0;
1206 pthru->target_id = device_id;
1207 pthru->lun = scp->device->lun;
1208 pthru->cdb_len = scp->cmd_len;
1211 pthru->flags = cpu_to_le16(flags);
1212 pthru->data_xfer_len = cpu_to_le32(scsi_bufflen(scp));
1214 memcpy(pthru->cdb, scp->cmnd, scp->cmd_len);
1217 * If the command is for the tape device, set the
1218 * pthru timeout to the os layer timeout value.
1220 if (scp->device->type == TYPE_TAPE) {
1221 if ((scp->request->timeout / HZ) > 0xFFFF)
1222 pthru->timeout = cpu_to_le16(0xFFFF);
1224 pthru->timeout = cpu_to_le16(scp->request->timeout / HZ);
1230 if (instance->flag_ieee == 1) {
1231 pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64);
1232 pthru->sge_count = megasas_make_sgl_skinny(instance, scp,
1234 } else if (IS_DMA64) {
1235 pthru->flags |= cpu_to_le16(MFI_FRAME_SGL64);
1236 pthru->sge_count = megasas_make_sgl64(instance, scp,
1239 pthru->sge_count = megasas_make_sgl32(instance, scp,
1242 if (pthru->sge_count > instance->max_num_sge) {
1243 printk(KERN_ERR "megasas: DCDB two many SGE NUM=%x\n",
1249 * Sense info specific
1251 pthru->sense_len = SCSI_SENSE_BUFFERSIZE;
1252 pthru->sense_buf_phys_addr_hi =
1253 cpu_to_le32(upper_32_bits(cmd->sense_phys_addr));
1254 pthru->sense_buf_phys_addr_lo =
1255 cpu_to_le32(lower_32_bits(cmd->sense_phys_addr));
1258 * Compute the total number of frames this command consumes. FW uses
1259 * this number to pull sufficient number of frames from host memory.
1261 cmd->frame_count = megasas_get_frame_count(instance, pthru->sge_count,
1264 return cmd->frame_count;
1268 * megasas_build_ldio - Prepares IOs to logical devices
1269 * @instance: Adapter soft state
1270 * @scp: SCSI command
1271 * @cmd: Command to be prepared
1273 * Frames (and accompanying SGLs) for regular SCSI IOs use this function.
1276 megasas_build_ldio(struct megasas_instance *instance, struct scsi_cmnd *scp,
1277 struct megasas_cmd *cmd)
1280 u8 sc = scp->cmnd[0];
1282 struct megasas_io_frame *ldio;
1284 device_id = MEGASAS_DEV_INDEX(scp);
1285 ldio = (struct megasas_io_frame *)cmd->frame;
1287 if (scp->sc_data_direction == PCI_DMA_TODEVICE)
1288 flags = MFI_FRAME_DIR_WRITE;
1289 else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
1290 flags = MFI_FRAME_DIR_READ;
1292 if (instance->flag_ieee == 1) {
1293 flags |= MFI_FRAME_IEEE;
1297 * Prepare the Logical IO frame: 2nd bit is zero for all read cmds
1299 ldio->cmd = (sc & 0x02) ? MFI_CMD_LD_WRITE : MFI_CMD_LD_READ;
1300 ldio->cmd_status = 0x0;
1301 ldio->scsi_status = 0x0;
1302 ldio->target_id = device_id;
1304 ldio->reserved_0 = 0;
1306 ldio->flags = cpu_to_le16(flags);
1307 ldio->start_lba_hi = 0;
1308 ldio->access_byte = (scp->cmd_len != 6) ? scp->cmnd[1] : 0;
1311 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1313 if (scp->cmd_len == 6) {
1314 ldio->lba_count = cpu_to_le32((u32) scp->cmnd[4]);
1315 ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[1] << 16) |
1316 ((u32) scp->cmnd[2] << 8) |
1317 (u32) scp->cmnd[3]);
1319 ldio->start_lba_lo &= cpu_to_le32(0x1FFFFF);
1323 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1325 else if (scp->cmd_len == 10) {
1326 ldio->lba_count = cpu_to_le32((u32) scp->cmnd[8] |
1327 ((u32) scp->cmnd[7] << 8));
1328 ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) |
1329 ((u32) scp->cmnd[3] << 16) |
1330 ((u32) scp->cmnd[4] << 8) |
1331 (u32) scp->cmnd[5]);
1335 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1337 else if (scp->cmd_len == 12) {
1338 ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[6] << 24) |
1339 ((u32) scp->cmnd[7] << 16) |
1340 ((u32) scp->cmnd[8] << 8) |
1341 (u32) scp->cmnd[9]);
1343 ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[2] << 24) |
1344 ((u32) scp->cmnd[3] << 16) |
1345 ((u32) scp->cmnd[4] << 8) |
1346 (u32) scp->cmnd[5]);
1350 * 16-byte READ(0x88) or WRITE(0x8A) cdb
1352 else if (scp->cmd_len == 16) {
1353 ldio->lba_count = cpu_to_le32(((u32) scp->cmnd[10] << 24) |
1354 ((u32) scp->cmnd[11] << 16) |
1355 ((u32) scp->cmnd[12] << 8) |
1356 (u32) scp->cmnd[13]);
1358 ldio->start_lba_lo = cpu_to_le32(((u32) scp->cmnd[6] << 24) |
1359 ((u32) scp->cmnd[7] << 16) |
1360 ((u32) scp->cmnd[8] << 8) |
1361 (u32) scp->cmnd[9]);
1363 ldio->start_lba_hi = cpu_to_le32(((u32) scp->cmnd[2] << 24) |
1364 ((u32) scp->cmnd[3] << 16) |
1365 ((u32) scp->cmnd[4] << 8) |
1366 (u32) scp->cmnd[5]);
1373 if (instance->flag_ieee) {
1374 ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64);
1375 ldio->sge_count = megasas_make_sgl_skinny(instance, scp,
1377 } else if (IS_DMA64) {
1378 ldio->flags |= cpu_to_le16(MFI_FRAME_SGL64);
1379 ldio->sge_count = megasas_make_sgl64(instance, scp, &ldio->sgl);
1381 ldio->sge_count = megasas_make_sgl32(instance, scp, &ldio->sgl);
1383 if (ldio->sge_count > instance->max_num_sge) {
1384 printk(KERN_ERR "megasas: build_ld_io: sge_count = %x\n",
1390 * Sense info specific
1392 ldio->sense_len = SCSI_SENSE_BUFFERSIZE;
1393 ldio->sense_buf_phys_addr_hi = 0;
1394 ldio->sense_buf_phys_addr_lo = cpu_to_le32(cmd->sense_phys_addr);
1397 * Compute the total number of frames this command consumes. FW uses
1398 * this number to pull sufficient number of frames from host memory.
1400 cmd->frame_count = megasas_get_frame_count(instance,
1401 ldio->sge_count, IO_FRAME);
1403 return cmd->frame_count;
1407 * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD
1408 * and whether it's RW or non RW
1409 * @scmd: SCSI command
1412 inline int megasas_cmd_type(struct scsi_cmnd *cmd)
1416 switch (cmd->cmnd[0]) {
1425 ret = (MEGASAS_IS_LOGICAL(cmd)) ?
1426 READ_WRITE_LDIO : READ_WRITE_SYSPDIO;
1429 ret = (MEGASAS_IS_LOGICAL(cmd)) ?
1430 NON_READ_WRITE_LDIO : NON_READ_WRITE_SYSPDIO;
1436 * megasas_dump_pending_frames - Dumps the frame address of all pending cmds
1438 * @instance: Adapter soft state
1441 megasas_dump_pending_frames(struct megasas_instance *instance)
1443 struct megasas_cmd *cmd;
1445 union megasas_sgl *mfi_sgl;
1446 struct megasas_io_frame *ldio;
1447 struct megasas_pthru_frame *pthru;
1449 u32 max_cmd = instance->max_fw_cmds;
1451 printk(KERN_ERR "\nmegasas[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance->host->host_no);
1452 printk(KERN_ERR "megasas[%d]: Total OS Pending cmds : %d\n",instance->host->host_no,atomic_read(&instance->fw_outstanding));
1454 printk(KERN_ERR "\nmegasas[%d]: 64 bit SGLs were sent to FW\n",instance->host->host_no);
1456 printk(KERN_ERR "\nmegasas[%d]: 32 bit SGLs were sent to FW\n",instance->host->host_no);
1458 printk(KERN_ERR "megasas[%d]: Pending OS cmds in FW : \n",instance->host->host_no);
1459 for (i = 0; i < max_cmd; i++) {
1460 cmd = instance->cmd_list[i];
1463 printk(KERN_ERR "megasas[%d]: Frame addr :0x%08lx : ",instance->host->host_no,(unsigned long)cmd->frame_phys_addr);
1464 if (megasas_cmd_type(cmd->scmd) == READ_WRITE_LDIO) {
1465 ldio = (struct megasas_io_frame *)cmd->frame;
1466 mfi_sgl = &ldio->sgl;
1467 sgcount = ldio->sge_count;
1468 printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x,"
1469 " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
1470 instance->host->host_no, cmd->frame_count, ldio->cmd, ldio->target_id,
1471 le32_to_cpu(ldio->start_lba_lo), le32_to_cpu(ldio->start_lba_hi),
1472 le32_to_cpu(ldio->sense_buf_phys_addr_lo), sgcount);
1475 pthru = (struct megasas_pthru_frame *) cmd->frame;
1476 mfi_sgl = &pthru->sgl;
1477 sgcount = pthru->sge_count;
1478 printk(KERN_ERR "megasas[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, "
1479 "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
1480 instance->host->host_no, cmd->frame_count, pthru->cmd, pthru->target_id,
1481 pthru->lun, pthru->cdb_len, le32_to_cpu(pthru->data_xfer_len),
1482 le32_to_cpu(pthru->sense_buf_phys_addr_lo), sgcount);
1484 if(megasas_dbg_lvl & MEGASAS_DBG_LVL){
1485 for (n = 0; n < sgcount; n++){
1487 printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%llx ",
1488 le32_to_cpu(mfi_sgl->sge64[n].length),
1489 le64_to_cpu(mfi_sgl->sge64[n].phys_addr));
1491 printk(KERN_ERR "megasas: sgl len : 0x%x, sgl addr : 0x%x ",
1492 le32_to_cpu(mfi_sgl->sge32[n].length),
1493 le32_to_cpu(mfi_sgl->sge32[n].phys_addr));
1496 printk(KERN_ERR "\n");
1498 printk(KERN_ERR "\nmegasas[%d]: Pending Internal cmds in FW : \n",instance->host->host_no);
1499 for (i = 0; i < max_cmd; i++) {
1501 cmd = instance->cmd_list[i];
1503 if(cmd->sync_cmd == 1){
1504 printk(KERN_ERR "0x%08lx : ", (unsigned long)cmd->frame_phys_addr);
1507 printk(KERN_ERR "megasas[%d]: Dumping Done.\n\n",instance->host->host_no);
1511 megasas_build_and_issue_cmd(struct megasas_instance *instance,
1512 struct scsi_cmnd *scmd)
1514 struct megasas_cmd *cmd;
1517 cmd = megasas_get_cmd(instance);
1519 return SCSI_MLQUEUE_HOST_BUSY;
1522 * Logical drive command
1524 if (megasas_cmd_type(scmd) == READ_WRITE_LDIO)
1525 frame_count = megasas_build_ldio(instance, scmd, cmd);
1527 frame_count = megasas_build_dcdb(instance, scmd, cmd);
1530 goto out_return_cmd;
1533 scmd->SCp.ptr = (char *)cmd;
1536 * Issue the command to the FW
1538 atomic_inc(&instance->fw_outstanding);
1540 instance->instancet->fire_cmd(instance, cmd->frame_phys_addr,
1541 cmd->frame_count-1, instance->reg_set);
1545 megasas_return_cmd(instance, cmd);
1551 * megasas_queue_command - Queue entry point
1552 * @scmd: SCSI command to be queued
1553 * @done: Callback entry point
1556 megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
1558 struct megasas_instance *instance;
1559 unsigned long flags;
1561 instance = (struct megasas_instance *)
1562 scmd->device->host->hostdata;
1564 if (instance->unload == 1) {
1565 scmd->result = DID_NO_CONNECT << 16;
1566 scmd->scsi_done(scmd);
1570 if (instance->issuepend_done == 0)
1571 return SCSI_MLQUEUE_HOST_BUSY;
1573 spin_lock_irqsave(&instance->hba_lock, flags);
1575 /* Check for an mpio path and adjust behavior */
1576 if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) {
1577 if (megasas_check_mpio_paths(instance, scmd) ==
1578 (DID_RESET << 16)) {
1579 spin_unlock_irqrestore(&instance->hba_lock, flags);
1580 return SCSI_MLQUEUE_HOST_BUSY;
1582 spin_unlock_irqrestore(&instance->hba_lock, flags);
1583 scmd->result = DID_NO_CONNECT << 16;
1584 scmd->scsi_done(scmd);
1589 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
1590 spin_unlock_irqrestore(&instance->hba_lock, flags);
1591 scmd->result = DID_NO_CONNECT << 16;
1592 scmd->scsi_done(scmd);
1596 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) {
1597 spin_unlock_irqrestore(&instance->hba_lock, flags);
1598 return SCSI_MLQUEUE_HOST_BUSY;
1601 spin_unlock_irqrestore(&instance->hba_lock, flags);
1605 if (MEGASAS_IS_LOGICAL(scmd) &&
1606 (scmd->device->id >= instance->fw_supported_vd_count ||
1607 scmd->device->lun)) {
1608 scmd->result = DID_BAD_TARGET << 16;
1612 switch (scmd->cmnd[0]) {
1613 case SYNCHRONIZE_CACHE:
1615 * FW takes care of flush cache on its own
1616 * No need to send it down
1618 scmd->result = DID_OK << 16;
1624 if (instance->instancet->build_and_issue_cmd(instance, scmd)) {
1625 printk(KERN_ERR "megasas: Err returned from build_and_issue_cmd\n");
1626 return SCSI_MLQUEUE_HOST_BUSY;
1632 scmd->scsi_done(scmd);
1636 static struct megasas_instance *megasas_lookup_instance(u16 host_no)
1640 for (i = 0; i < megasas_mgmt_info.max_index; i++) {
1642 if ((megasas_mgmt_info.instance[i]) &&
1643 (megasas_mgmt_info.instance[i]->host->host_no == host_no))
1644 return megasas_mgmt_info.instance[i];
1650 static int megasas_slave_configure(struct scsi_device *sdev)
1653 * The RAID firmware may require extended timeouts.
1655 blk_queue_rq_timeout(sdev->request_queue,
1656 MEGASAS_DEFAULT_CMD_TIMEOUT * HZ);
1661 static int megasas_slave_alloc(struct scsi_device *sdev)
1664 struct megasas_instance *instance ;
1665 instance = megasas_lookup_instance(sdev->host->host_no);
1666 if (sdev->channel < MEGASAS_MAX_PD_CHANNELS) {
1668 * Open the OS scan to the SYSTEM PD
1671 (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL) +
1673 if (instance->pd_list[pd_index].driveState ==
1674 MR_PD_STATE_SYSTEM) {
1683 * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a
1685 * @instance: Adapter soft state
1688 static void megasas_complete_outstanding_ioctls(struct megasas_instance *instance)
1691 struct megasas_cmd *cmd_mfi;
1692 struct megasas_cmd_fusion *cmd_fusion;
1693 struct fusion_context *fusion = instance->ctrl_context;
1695 /* Find all outstanding ioctls */
1697 for (i = 0; i < instance->max_fw_cmds; i++) {
1698 cmd_fusion = fusion->cmd_list[i];
1699 if (cmd_fusion->sync_cmd_idx != (u32)ULONG_MAX) {
1700 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
1701 if (cmd_mfi->sync_cmd &&
1702 cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT)
1703 megasas_complete_cmd(instance,
1708 for (i = 0; i < instance->max_fw_cmds; i++) {
1709 cmd_mfi = instance->cmd_list[i];
1710 if (cmd_mfi->sync_cmd && cmd_mfi->frame->hdr.cmd !=
1712 megasas_complete_cmd(instance, cmd_mfi, DID_OK);
1718 void megaraid_sas_kill_hba(struct megasas_instance *instance)
1720 /* Set critical error to block I/O & ioctls in case caller didn't */
1721 instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
1722 /* Wait 1 second to ensure IO or ioctls in build have posted */
1724 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
1725 (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
1726 (instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
1727 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) ||
1728 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
1729 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
1730 writel(MFI_STOP_ADP,
1731 &instance->reg_set->doorbell);
1733 readl(&instance->reg_set->doorbell);
1734 if (instance->mpio && instance->requestorId)
1735 memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
1737 writel(MFI_STOP_ADP,
1738 &instance->reg_set->inbound_doorbell);
1740 /* Complete outstanding ioctls when adapter is killed */
1741 megasas_complete_outstanding_ioctls(instance);
1745 * megasas_check_and_restore_queue_depth - Check if queue depth needs to be
1746 * restored to max value
1747 * @instance: Adapter soft state
1751 megasas_check_and_restore_queue_depth(struct megasas_instance *instance)
1753 unsigned long flags;
1755 if (instance->flag & MEGASAS_FW_BUSY
1756 && time_after(jiffies, instance->last_time + 5 * HZ)
1757 && atomic_read(&instance->fw_outstanding) <
1758 instance->throttlequeuedepth + 1) {
1760 spin_lock_irqsave(instance->host->host_lock, flags);
1761 instance->flag &= ~MEGASAS_FW_BUSY;
1763 instance->host->can_queue = instance->max_scsi_cmds;
1764 spin_unlock_irqrestore(instance->host->host_lock, flags);
1769 * megasas_complete_cmd_dpc - Returns FW's controller structure
1770 * @instance_addr: Address of adapter soft state
1772 * Tasklet to complete cmds
1774 static void megasas_complete_cmd_dpc(unsigned long instance_addr)
1779 struct megasas_cmd *cmd;
1780 struct megasas_instance *instance =
1781 (struct megasas_instance *)instance_addr;
1782 unsigned long flags;
1784 /* If we have already declared adapter dead, donot complete cmds */
1785 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR )
1788 spin_lock_irqsave(&instance->completion_lock, flags);
1790 producer = le32_to_cpu(*instance->producer);
1791 consumer = le32_to_cpu(*instance->consumer);
1793 while (consumer != producer) {
1794 context = le32_to_cpu(instance->reply_queue[consumer]);
1795 if (context >= instance->max_fw_cmds) {
1796 printk(KERN_ERR "Unexpected context value %x\n",
1801 cmd = instance->cmd_list[context];
1803 megasas_complete_cmd(instance, cmd, DID_OK);
1806 if (consumer == (instance->max_fw_cmds + 1)) {
1811 *instance->consumer = cpu_to_le32(producer);
1813 spin_unlock_irqrestore(&instance->completion_lock, flags);
1816 * Check if we can restore can_queue
1818 megasas_check_and_restore_queue_depth(instance);
1822 * megasas_start_timer - Initializes a timer object
1823 * @instance: Adapter soft state
1824 * @timer: timer object to be initialized
1825 * @fn: timer function
1826 * @interval: time interval between timer function call
1829 void megasas_start_timer(struct megasas_instance *instance,
1830 struct timer_list *timer,
1831 void *fn, unsigned long interval)
1834 timer->expires = jiffies + interval;
1835 timer->data = (unsigned long)instance;
1836 timer->function = fn;
1841 megasas_internal_reset_defer_cmds(struct megasas_instance *instance);
1844 process_fw_state_change_wq(struct work_struct *work);
1846 void megasas_do_ocr(struct megasas_instance *instance)
1848 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) ||
1849 (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) ||
1850 (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)) {
1851 *instance->consumer = cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN);
1853 instance->instancet->disable_intr(instance);
1854 instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT;
1855 instance->issuepend_done = 0;
1857 atomic_set(&instance->fw_outstanding, 0);
1858 megasas_internal_reset_defer_cmds(instance);
1859 process_fw_state_change_wq(&instance->work_init);
1862 static int megasas_get_ld_vf_affiliation_111(struct megasas_instance *instance,
1865 struct megasas_cmd *cmd;
1866 struct megasas_dcmd_frame *dcmd;
1867 struct MR_LD_VF_AFFILIATION_111 *new_affiliation_111 = NULL;
1868 dma_addr_t new_affiliation_111_h;
1872 cmd = megasas_get_cmd(instance);
1875 printk(KERN_DEBUG "megasas: megasas_get_ld_vf_affiliation_111:"
1876 "Failed to get cmd for scsi%d.\n",
1877 instance->host->host_no);
1881 dcmd = &cmd->frame->dcmd;
1883 if (!instance->vf_affiliation_111) {
1884 printk(KERN_WARNING "megasas: SR-IOV: Couldn't get LD/VF "
1885 "affiliation for scsi%d.\n", instance->host->host_no);
1886 megasas_return_cmd(instance, cmd);
1891 memset(instance->vf_affiliation_111, 0,
1892 sizeof(struct MR_LD_VF_AFFILIATION_111));
1894 new_affiliation_111 =
1895 pci_alloc_consistent(instance->pdev,
1896 sizeof(struct MR_LD_VF_AFFILIATION_111),
1897 &new_affiliation_111_h);
1898 if (!new_affiliation_111) {
1899 printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate "
1900 "memory for new affiliation for scsi%d.\n",
1901 instance->host->host_no);
1902 megasas_return_cmd(instance, cmd);
1905 memset(new_affiliation_111, 0,
1906 sizeof(struct MR_LD_VF_AFFILIATION_111));
1909 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1911 dcmd->cmd = MFI_CMD_DCMD;
1912 dcmd->cmd_status = 0xFF;
1913 dcmd->sge_count = 1;
1914 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH);
1917 dcmd->data_xfer_len =
1918 cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111));
1919 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111);
1922 dcmd->sgl.sge32[0].phys_addr =
1923 cpu_to_le32(instance->vf_affiliation_111_h);
1925 dcmd->sgl.sge32[0].phys_addr =
1926 cpu_to_le32(new_affiliation_111_h);
1928 dcmd->sgl.sge32[0].length = cpu_to_le32(
1929 sizeof(struct MR_LD_VF_AFFILIATION_111));
1931 printk(KERN_WARNING "megasas: SR-IOV: Getting LD/VF affiliation for "
1932 "scsi%d\n", instance->host->host_no);
1934 megasas_issue_blocked_cmd(instance, cmd, 0);
1936 if (dcmd->cmd_status) {
1937 printk(KERN_WARNING "megasas: SR-IOV: LD/VF affiliation DCMD"
1938 " failed with status 0x%x for scsi%d.\n",
1939 dcmd->cmd_status, instance->host->host_no);
1940 retval = 1; /* Do a scan if we couldn't get affiliation */
1945 thisVf = new_affiliation_111->thisVf;
1946 for (ld = 0 ; ld < new_affiliation_111->vdCount; ld++)
1947 if (instance->vf_affiliation_111->map[ld].policy[thisVf] !=
1948 new_affiliation_111->map[ld].policy[thisVf]) {
1949 printk(KERN_WARNING "megasas: SR-IOV: "
1950 "Got new LD/VF affiliation "
1952 instance->host->host_no);
1953 memcpy(instance->vf_affiliation_111,
1954 new_affiliation_111,
1955 sizeof(struct MR_LD_VF_AFFILIATION_111));
1961 if (new_affiliation_111) {
1962 pci_free_consistent(instance->pdev,
1963 sizeof(struct MR_LD_VF_AFFILIATION_111),
1964 new_affiliation_111,
1965 new_affiliation_111_h);
1968 megasas_return_cmd(instance, cmd);
1973 static int megasas_get_ld_vf_affiliation_12(struct megasas_instance *instance,
1976 struct megasas_cmd *cmd;
1977 struct megasas_dcmd_frame *dcmd;
1978 struct MR_LD_VF_AFFILIATION *new_affiliation = NULL;
1979 struct MR_LD_VF_MAP *newmap = NULL, *savedmap = NULL;
1980 dma_addr_t new_affiliation_h;
1981 int i, j, retval = 0, found = 0, doscan = 0;
1984 cmd = megasas_get_cmd(instance);
1987 printk(KERN_DEBUG "megasas: megasas_get_ld_vf_affiliation12: "
1988 "Failed to get cmd for scsi%d.\n",
1989 instance->host->host_no);
1993 dcmd = &cmd->frame->dcmd;
1995 if (!instance->vf_affiliation) {
1996 printk(KERN_WARNING "megasas: SR-IOV: Couldn't get LD/VF "
1997 "affiliation for scsi%d.\n", instance->host->host_no);
1998 megasas_return_cmd(instance, cmd);
2003 memset(instance->vf_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) *
2004 sizeof(struct MR_LD_VF_AFFILIATION));
2007 pci_alloc_consistent(instance->pdev,
2008 (MAX_LOGICAL_DRIVES + 1) *
2009 sizeof(struct MR_LD_VF_AFFILIATION),
2010 &new_affiliation_h);
2011 if (!new_affiliation) {
2012 printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate "
2013 "memory for new affiliation for scsi%d.\n",
2014 instance->host->host_no);
2015 megasas_return_cmd(instance, cmd);
2018 memset(new_affiliation, 0, (MAX_LOGICAL_DRIVES + 1) *
2019 sizeof(struct MR_LD_VF_AFFILIATION));
2022 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
2024 dcmd->cmd = MFI_CMD_DCMD;
2025 dcmd->cmd_status = 0xFF;
2026 dcmd->sge_count = 1;
2027 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH);
2030 dcmd->data_xfer_len = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) *
2031 sizeof(struct MR_LD_VF_AFFILIATION));
2032 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS);
2035 dcmd->sgl.sge32[0].phys_addr =
2036 cpu_to_le32(instance->vf_affiliation_h);
2038 dcmd->sgl.sge32[0].phys_addr =
2039 cpu_to_le32(new_affiliation_h);
2041 dcmd->sgl.sge32[0].length = cpu_to_le32((MAX_LOGICAL_DRIVES + 1) *
2042 sizeof(struct MR_LD_VF_AFFILIATION));
2044 printk(KERN_WARNING "megasas: SR-IOV: Getting LD/VF affiliation for "
2045 "scsi%d\n", instance->host->host_no);
2047 megasas_issue_blocked_cmd(instance, cmd, 0);
2049 if (dcmd->cmd_status) {
2050 printk(KERN_WARNING "megasas: SR-IOV: LD/VF affiliation DCMD"
2051 " failed with status 0x%x for scsi%d.\n",
2052 dcmd->cmd_status, instance->host->host_no);
2053 retval = 1; /* Do a scan if we couldn't get affiliation */
2058 if (!new_affiliation->ldCount) {
2059 printk(KERN_WARNING "megasas: SR-IOV: Got new LD/VF "
2060 "affiliation for passive path for scsi%d.\n",
2061 instance->host->host_no);
2065 newmap = new_affiliation->map;
2066 savedmap = instance->vf_affiliation->map;
2067 thisVf = new_affiliation->thisVf;
2068 for (i = 0 ; i < new_affiliation->ldCount; i++) {
2070 for (j = 0; j < instance->vf_affiliation->ldCount;
2072 if (newmap->ref.targetId ==
2073 savedmap->ref.targetId) {
2075 if (newmap->policy[thisVf] !=
2076 savedmap->policy[thisVf]) {
2081 savedmap = (struct MR_LD_VF_MAP *)
2082 ((unsigned char *)savedmap +
2085 if (!found && newmap->policy[thisVf] !=
2086 MR_LD_ACCESS_HIDDEN) {
2090 newmap = (struct MR_LD_VF_MAP *)
2091 ((unsigned char *)newmap + newmap->size);
2094 newmap = new_affiliation->map;
2095 savedmap = instance->vf_affiliation->map;
2097 for (i = 0 ; i < instance->vf_affiliation->ldCount; i++) {
2099 for (j = 0 ; j < new_affiliation->ldCount; j++) {
2100 if (savedmap->ref.targetId ==
2101 newmap->ref.targetId) {
2103 if (savedmap->policy[thisVf] !=
2104 newmap->policy[thisVf]) {
2109 newmap = (struct MR_LD_VF_MAP *)
2110 ((unsigned char *)newmap +
2113 if (!found && savedmap->policy[thisVf] !=
2114 MR_LD_ACCESS_HIDDEN) {
2118 savedmap = (struct MR_LD_VF_MAP *)
2119 ((unsigned char *)savedmap +
2125 printk(KERN_WARNING "megasas: SR-IOV: Got new LD/VF "
2126 "affiliation for scsi%d.\n", instance->host->host_no);
2127 memcpy(instance->vf_affiliation, new_affiliation,
2128 new_affiliation->size);
2132 if (new_affiliation)
2133 pci_free_consistent(instance->pdev,
2134 (MAX_LOGICAL_DRIVES + 1) *
2135 sizeof(struct MR_LD_VF_AFFILIATION),
2136 new_affiliation, new_affiliation_h);
2137 megasas_return_cmd(instance, cmd);
2142 /* This function will get the current SR-IOV LD/VF affiliation */
2143 static int megasas_get_ld_vf_affiliation(struct megasas_instance *instance,
2148 if (instance->PlasmaFW111)
2149 retval = megasas_get_ld_vf_affiliation_111(instance, initial);
2151 retval = megasas_get_ld_vf_affiliation_12(instance, initial);
2155 /* This function will tell FW to start the SR-IOV heartbeat */
2156 int megasas_sriov_start_heartbeat(struct megasas_instance *instance,
2159 struct megasas_cmd *cmd;
2160 struct megasas_dcmd_frame *dcmd;
2163 cmd = megasas_get_cmd(instance);
2166 printk(KERN_DEBUG "megasas: megasas_sriov_start_heartbeat: "
2167 "Failed to get cmd for scsi%d.\n",
2168 instance->host->host_no);
2172 dcmd = &cmd->frame->dcmd;
2175 instance->hb_host_mem =
2176 pci_zalloc_consistent(instance->pdev,
2177 sizeof(struct MR_CTRL_HB_HOST_MEM),
2178 &instance->hb_host_mem_h);
2179 if (!instance->hb_host_mem) {
2180 printk(KERN_DEBUG "megasas: SR-IOV: Couldn't allocate"
2181 " memory for heartbeat host memory for "
2182 "scsi%d.\n", instance->host->host_no);
2188 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
2190 dcmd->mbox.s[0] = cpu_to_le16(sizeof(struct MR_CTRL_HB_HOST_MEM));
2191 dcmd->cmd = MFI_CMD_DCMD;
2192 dcmd->cmd_status = 0xFF;
2193 dcmd->sge_count = 1;
2194 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_BOTH);
2197 dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM));
2198 dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC);
2199 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->hb_host_mem_h);
2200 dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM));
2202 printk(KERN_WARNING "megasas: SR-IOV: Starting heartbeat for scsi%d\n",
2203 instance->host->host_no);
2205 if (instance->ctrl_context && !instance->mask_interrupts)
2206 retval = megasas_issue_blocked_cmd(instance, cmd,
2207 MEGASAS_ROUTINE_WAIT_TIME_VF);
2209 retval = megasas_issue_polled(instance, cmd);
2212 printk(KERN_WARNING "megasas: SR-IOV: MR_DCMD_CTRL_SHARED_HOST"
2213 "_MEM_ALLOC DCMD timed out for scsi%d\n",
2214 instance->host->host_no);
2220 if (dcmd->cmd_status) {
2221 printk(KERN_WARNING "megasas: SR-IOV: MR_DCMD_CTRL_SHARED_HOST"
2222 "_MEM_ALLOC DCMD failed with status 0x%x for scsi%d\n",
2224 instance->host->host_no);
2230 megasas_return_cmd(instance, cmd);
2235 /* Handler for SR-IOV heartbeat */
2236 void megasas_sriov_heartbeat_handler(unsigned long instance_addr)
2238 struct megasas_instance *instance =
2239 (struct megasas_instance *)instance_addr;
2241 if (instance->hb_host_mem->HB.fwCounter !=
2242 instance->hb_host_mem->HB.driverCounter) {
2243 instance->hb_host_mem->HB.driverCounter =
2244 instance->hb_host_mem->HB.fwCounter;
2245 mod_timer(&instance->sriov_heartbeat_timer,
2246 jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
2248 printk(KERN_WARNING "megasas: SR-IOV: Heartbeat never "
2249 "completed for scsi%d\n", instance->host->host_no);
2250 schedule_work(&instance->work_init);
2255 * megasas_wait_for_outstanding - Wait for all outstanding cmds
2256 * @instance: Adapter soft state
2258 * This function waits for up to MEGASAS_RESET_WAIT_TIME seconds for FW to
2259 * complete all its outstanding commands. Returns error if one or more IOs
2260 * are pending after this time period. It also marks the controller dead.
2262 static int megasas_wait_for_outstanding(struct megasas_instance *instance)
2266 u32 wait_time = MEGASAS_RESET_WAIT_TIME;
2268 unsigned long flags;
2269 struct list_head clist_local;
2270 struct megasas_cmd *reset_cmd;
2272 u8 kill_adapter_flag;
2274 spin_lock_irqsave(&instance->hba_lock, flags);
2275 adprecovery = instance->adprecovery;
2276 spin_unlock_irqrestore(&instance->hba_lock, flags);
2278 if (adprecovery != MEGASAS_HBA_OPERATIONAL) {
2280 INIT_LIST_HEAD(&clist_local);
2281 spin_lock_irqsave(&instance->hba_lock, flags);
2282 list_splice_init(&instance->internal_reset_pending_q,
2284 spin_unlock_irqrestore(&instance->hba_lock, flags);
2286 printk(KERN_NOTICE "megasas: HBA reset wait ...\n");
2287 for (i = 0; i < wait_time; i++) {
2289 spin_lock_irqsave(&instance->hba_lock, flags);
2290 adprecovery = instance->adprecovery;
2291 spin_unlock_irqrestore(&instance->hba_lock, flags);
2292 if (adprecovery == MEGASAS_HBA_OPERATIONAL)
2296 if (adprecovery != MEGASAS_HBA_OPERATIONAL) {
2297 printk(KERN_NOTICE "megasas: reset: Stopping HBA.\n");
2298 spin_lock_irqsave(&instance->hba_lock, flags);
2299 instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
2300 spin_unlock_irqrestore(&instance->hba_lock, flags);
2305 while (!list_empty(&clist_local)) {
2306 reset_cmd = list_entry((&clist_local)->next,
2307 struct megasas_cmd, list);
2308 list_del_init(&reset_cmd->list);
2309 if (reset_cmd->scmd) {
2310 reset_cmd->scmd->result = DID_RESET << 16;
2311 printk(KERN_NOTICE "%d:%p reset [%02x]\n",
2312 reset_index, reset_cmd,
2313 reset_cmd->scmd->cmnd[0]);
2315 reset_cmd->scmd->scsi_done(reset_cmd->scmd);
2316 megasas_return_cmd(instance, reset_cmd);
2317 } else if (reset_cmd->sync_cmd) {
2318 printk(KERN_NOTICE "megasas:%p synch cmds"
2322 reset_cmd->cmd_status = ENODATA;
2323 instance->instancet->fire_cmd(instance,
2324 reset_cmd->frame_phys_addr,
2325 0, instance->reg_set);
2327 printk(KERN_NOTICE "megasas: %p unexpected"
2337 for (i = 0; i < resetwaittime; i++) {
2339 int outstanding = atomic_read(&instance->fw_outstanding);
2344 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
2345 printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
2346 "commands to complete\n",i,outstanding);
2348 * Call cmd completion routine. Cmd to be
2349 * be completed directly without depending on isr.
2351 megasas_complete_cmd_dpc((unsigned long)instance);
2358 kill_adapter_flag = 0;
2360 fw_state = instance->instancet->read_fw_status_reg(
2361 instance->reg_set) & MFI_STATE_MASK;
2362 if ((fw_state == MFI_STATE_FAULT) &&
2363 (instance->disableOnlineCtrlReset == 0)) {
2365 kill_adapter_flag = 2;
2368 megasas_do_ocr(instance);
2369 kill_adapter_flag = 1;
2371 /* wait for 1 secs to let FW finish the pending cmds */
2377 if (atomic_read(&instance->fw_outstanding) &&
2378 !kill_adapter_flag) {
2379 if (instance->disableOnlineCtrlReset == 0) {
2381 megasas_do_ocr(instance);
2383 /* wait for 5 secs to let FW finish the pending cmds */
2384 for (i = 0; i < wait_time; i++) {
2386 atomic_read(&instance->fw_outstanding);
2394 if (atomic_read(&instance->fw_outstanding) ||
2395 (kill_adapter_flag == 2)) {
2396 printk(KERN_NOTICE "megaraid_sas: pending cmds after reset\n");
2398 * Send signal to FW to stop processing any pending cmds.
2399 * The controller will be taken offline by the OS now.
2401 if ((instance->pdev->device ==
2402 PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
2403 (instance->pdev->device ==
2404 PCI_DEVICE_ID_LSI_SAS0071SKINNY)) {
2405 writel(MFI_STOP_ADP,
2406 &instance->reg_set->doorbell);
2408 writel(MFI_STOP_ADP,
2409 &instance->reg_set->inbound_doorbell);
2411 megasas_dump_pending_frames(instance);
2412 spin_lock_irqsave(&instance->hba_lock, flags);
2413 instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
2414 spin_unlock_irqrestore(&instance->hba_lock, flags);
2418 printk(KERN_NOTICE "megaraid_sas: no pending cmds after reset\n");
2424 * megasas_generic_reset - Generic reset routine
2425 * @scmd: Mid-layer SCSI command
2427 * This routine implements a generic reset handler for device, bus and host
2428 * reset requests. Device, bus and host specific reset handlers can use this
2429 * function after they do their specific tasks.
2431 static int megasas_generic_reset(struct scsi_cmnd *scmd)
2434 struct megasas_instance *instance;
2436 instance = (struct megasas_instance *)scmd->device->host->hostdata;
2438 scmd_printk(KERN_NOTICE, scmd, "megasas: RESET cmd=%x retries=%x\n",
2439 scmd->cmnd[0], scmd->retries);
2441 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
2442 printk(KERN_ERR "megasas: cannot recover from previous reset "
2447 ret_val = megasas_wait_for_outstanding(instance);
2448 if (ret_val == SUCCESS)
2449 printk(KERN_NOTICE "megasas: reset successful \n");
2451 printk(KERN_ERR "megasas: failed to do reset\n");
2457 * megasas_reset_timer - quiesce the adapter if required
2460 * Sets the FW busy flag and reduces the host->can_queue if the
2461 * cmd has not been completed within the timeout period.
2464 blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
2466 struct megasas_instance *instance;
2467 unsigned long flags;
2469 if (time_after(jiffies, scmd->jiffies_at_alloc +
2470 (MEGASAS_DEFAULT_CMD_TIMEOUT * 2) * HZ)) {
2471 return BLK_EH_NOT_HANDLED;
2474 instance = (struct megasas_instance *)scmd->device->host->hostdata;
2475 if (!(instance->flag & MEGASAS_FW_BUSY)) {
2476 /* FW is busy, throttle IO */
2477 spin_lock_irqsave(instance->host->host_lock, flags);
2479 instance->host->can_queue = instance->throttlequeuedepth;
2480 instance->last_time = jiffies;
2481 instance->flag |= MEGASAS_FW_BUSY;
2483 spin_unlock_irqrestore(instance->host->host_lock, flags);
2485 return BLK_EH_RESET_TIMER;
2489 * megasas_reset_device - Device reset handler entry point
2491 static int megasas_reset_device(struct scsi_cmnd *scmd)
2496 * First wait for all commands to complete
2498 ret = megasas_generic_reset(scmd);
2504 * megasas_reset_bus_host - Bus & host reset handler entry point
2506 static int megasas_reset_bus_host(struct scsi_cmnd *scmd)
2509 struct megasas_instance *instance;
2510 instance = (struct megasas_instance *)scmd->device->host->hostdata;
2513 * First wait for all commands to complete
2515 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
2516 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) ||
2517 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
2518 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY))
2519 ret = megasas_reset_fusion(scmd->device->host, 1);
2521 ret = megasas_generic_reset(scmd);
2527 * megasas_bios_param - Returns disk geometry for a disk
2528 * @sdev: device handle
2529 * @bdev: block device
2530 * @capacity: drive capacity
2531 * @geom: geometry parameters
2534 megasas_bios_param(struct scsi_device *sdev, struct block_device *bdev,
2535 sector_t capacity, int geom[])
2541 /* Default heads (64) & sectors (32) */
2545 tmp = heads * sectors;
2546 cylinders = capacity;
2548 sector_div(cylinders, tmp);
2551 * Handle extended translation size for logical drives > 1Gb
2554 if (capacity >= 0x200000) {
2557 tmp = heads*sectors;
2558 cylinders = capacity;
2559 sector_div(cylinders, tmp);
2564 geom[2] = cylinders;
2569 static void megasas_aen_polling(struct work_struct *work);
2572 * megasas_service_aen - Processes an event notification
2573 * @instance: Adapter soft state
2574 * @cmd: AEN command completed by the ISR
2576 * For AEN, driver sends a command down to FW that is held by the FW till an
2577 * event occurs. When an event of interest occurs, FW completes the command
2578 * that it was previously holding.
2580 * This routines sends SIGIO signal to processes that have registered with the
2584 megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd)
2586 unsigned long flags;
2588 * Don't signal app if it is just an aborted previously registered aen
2590 if ((!cmd->abort_aen) && (instance->unload == 0)) {
2591 spin_lock_irqsave(&poll_aen_lock, flags);
2592 megasas_poll_wait_aen = 1;
2593 spin_unlock_irqrestore(&poll_aen_lock, flags);
2594 wake_up(&megasas_poll_wait);
2595 kill_fasync(&megasas_async_queue, SIGIO, POLL_IN);
2600 instance->aen_cmd = NULL;
2602 megasas_return_cmd(instance, cmd);
2604 if ((instance->unload == 0) &&
2605 ((instance->issuepend_done == 1))) {
2606 struct megasas_aen_event *ev;
2607 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2609 printk(KERN_ERR "megasas_service_aen: out of memory\n");
2611 ev->instance = instance;
2613 INIT_DELAYED_WORK(&ev->hotplug_work,
2614 megasas_aen_polling);
2615 schedule_delayed_work(&ev->hotplug_work, 0);
2621 megasas_fw_crash_buffer_store(struct device *cdev,
2622 struct device_attribute *attr, const char *buf, size_t count)
2624 struct Scsi_Host *shost = class_to_shost(cdev);
2625 struct megasas_instance *instance =
2626 (struct megasas_instance *) shost->hostdata;
2628 unsigned long flags;
2630 if (kstrtoint(buf, 0, &val) != 0)
2633 spin_lock_irqsave(&instance->crashdump_lock, flags);
2634 instance->fw_crash_buffer_offset = val;
2635 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
2640 megasas_fw_crash_buffer_show(struct device *cdev,
2641 struct device_attribute *attr, char *buf)
2643 struct Scsi_Host *shost = class_to_shost(cdev);
2644 struct megasas_instance *instance =
2645 (struct megasas_instance *) shost->hostdata;
2647 unsigned long buff_addr;
2648 unsigned long dmachunk = CRASH_DMA_BUF_SIZE;
2649 unsigned long src_addr;
2650 unsigned long flags;
2653 spin_lock_irqsave(&instance->crashdump_lock, flags);
2654 buff_offset = instance->fw_crash_buffer_offset;
2655 if (!instance->crash_dump_buf &&
2656 !((instance->fw_crash_state == AVAILABLE) ||
2657 (instance->fw_crash_state == COPYING))) {
2658 dev_err(&instance->pdev->dev,
2659 "Firmware crash dump is not available\n");
2660 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
2664 buff_addr = (unsigned long) buf;
2667 (instance->fw_crash_buffer_size * dmachunk)) {
2668 dev_err(&instance->pdev->dev,
2669 "Firmware crash dump offset is out of range\n");
2670 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
2674 size = (instance->fw_crash_buffer_size * dmachunk) - buff_offset;
2675 size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size;
2677 src_addr = (unsigned long)instance->crash_buf[buff_offset / dmachunk] +
2678 (buff_offset % dmachunk);
2679 memcpy(buf, (void *)src_addr, size);
2680 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
2686 megasas_fw_crash_buffer_size_show(struct device *cdev,
2687 struct device_attribute *attr, char *buf)
2689 struct Scsi_Host *shost = class_to_shost(cdev);
2690 struct megasas_instance *instance =
2691 (struct megasas_instance *) shost->hostdata;
2693 return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)
2694 ((instance->fw_crash_buffer_size) * 1024 * 1024)/PAGE_SIZE);
2698 megasas_fw_crash_state_store(struct device *cdev,
2699 struct device_attribute *attr, const char *buf, size_t count)
2701 struct Scsi_Host *shost = class_to_shost(cdev);
2702 struct megasas_instance *instance =
2703 (struct megasas_instance *) shost->hostdata;
2705 unsigned long flags;
2707 if (kstrtoint(buf, 0, &val) != 0)
2710 if ((val <= AVAILABLE || val > COPY_ERROR)) {
2711 dev_err(&instance->pdev->dev, "application updates invalid "
2712 "firmware crash state\n");
2716 instance->fw_crash_state = val;
2718 if ((val == COPIED) || (val == COPY_ERROR)) {
2719 spin_lock_irqsave(&instance->crashdump_lock, flags);
2720 megasas_free_host_crash_buffer(instance);
2721 spin_unlock_irqrestore(&instance->crashdump_lock, flags);
2722 if (val == COPY_ERROR)
2723 dev_info(&instance->pdev->dev, "application failed to "
2724 "copy Firmware crash dump\n");
2726 dev_info(&instance->pdev->dev, "Firmware crash dump "
2727 "copied successfully\n");
2733 megasas_fw_crash_state_show(struct device *cdev,
2734 struct device_attribute *attr, char *buf)
2736 struct Scsi_Host *shost = class_to_shost(cdev);
2737 struct megasas_instance *instance =
2738 (struct megasas_instance *) shost->hostdata;
2739 return snprintf(buf, PAGE_SIZE, "%d\n", instance->fw_crash_state);
2743 megasas_page_size_show(struct device *cdev,
2744 struct device_attribute *attr, char *buf)
2746 return snprintf(buf, PAGE_SIZE, "%ld\n", (unsigned long)PAGE_SIZE - 1);
2749 static DEVICE_ATTR(fw_crash_buffer, S_IRUGO | S_IWUSR,
2750 megasas_fw_crash_buffer_show, megasas_fw_crash_buffer_store);
2751 static DEVICE_ATTR(fw_crash_buffer_size, S_IRUGO,
2752 megasas_fw_crash_buffer_size_show, NULL);
2753 static DEVICE_ATTR(fw_crash_state, S_IRUGO | S_IWUSR,
2754 megasas_fw_crash_state_show, megasas_fw_crash_state_store);
2755 static DEVICE_ATTR(page_size, S_IRUGO,
2756 megasas_page_size_show, NULL);
2758 struct device_attribute *megaraid_host_attrs[] = {
2759 &dev_attr_fw_crash_buffer_size,
2760 &dev_attr_fw_crash_buffer,
2761 &dev_attr_fw_crash_state,
2762 &dev_attr_page_size,
2767 * Scsi host template for megaraid_sas driver
2769 static struct scsi_host_template megasas_template = {
2771 .module = THIS_MODULE,
2772 .name = "Avago SAS based MegaRAID driver",
2773 .proc_name = "megaraid_sas",
2774 .slave_configure = megasas_slave_configure,
2775 .slave_alloc = megasas_slave_alloc,
2776 .queuecommand = megasas_queue_command,
2777 .eh_device_reset_handler = megasas_reset_device,
2778 .eh_bus_reset_handler = megasas_reset_bus_host,
2779 .eh_host_reset_handler = megasas_reset_bus_host,
2780 .eh_timed_out = megasas_reset_timer,
2781 .shost_attrs = megaraid_host_attrs,
2782 .bios_param = megasas_bios_param,
2783 .use_clustering = ENABLE_CLUSTERING,
2784 .change_queue_depth = scsi_change_queue_depth,
2789 * megasas_complete_int_cmd - Completes an internal command
2790 * @instance: Adapter soft state
2791 * @cmd: Command to be completed
2793 * The megasas_issue_blocked_cmd() function waits for a command to complete
2794 * after it issues a command. This function wakes up that waiting routine by
2795 * calling wake_up() on the wait queue.
2798 megasas_complete_int_cmd(struct megasas_instance *instance,
2799 struct megasas_cmd *cmd)
2801 cmd->cmd_status = cmd->frame->io.cmd_status;
2803 if (cmd->cmd_status == ENODATA) {
2804 cmd->cmd_status = 0;
2806 wake_up(&instance->int_cmd_wait_q);
2810 * megasas_complete_abort - Completes aborting a command
2811 * @instance: Adapter soft state
2812 * @cmd: Cmd that was issued to abort another cmd
2814 * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q
2815 * after it issues an abort on a previously issued command. This function
2816 * wakes up all functions waiting on the same wait queue.
2819 megasas_complete_abort(struct megasas_instance *instance,
2820 struct megasas_cmd *cmd)
2822 if (cmd->sync_cmd) {
2824 cmd->cmd_status = 0;
2825 wake_up(&instance->abort_cmd_wait_q);
2832 * megasas_complete_cmd - Completes a command
2833 * @instance: Adapter soft state
2834 * @cmd: Command to be completed
2835 * @alt_status: If non-zero, use this value as status to
2836 * SCSI mid-layer instead of the value returned
2837 * by the FW. This should be used if caller wants
2838 * an alternate status (as in the case of aborted
2842 megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
2846 struct megasas_header *hdr = &cmd->frame->hdr;
2847 unsigned long flags;
2848 struct fusion_context *fusion = instance->ctrl_context;
2851 /* flag for the retry reset */
2852 cmd->retry_for_fw_reset = 0;
2855 cmd->scmd->SCp.ptr = NULL;
2858 case MFI_CMD_INVALID:
2859 /* Some older 1068 controller FW may keep a pended
2860 MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel
2861 when booting the kdump kernel. Ignore this command to
2862 prevent a kernel panic on shutdown of the kdump kernel. */
2863 printk(KERN_WARNING "megaraid_sas: MFI_CMD_INVALID command "
2865 printk(KERN_WARNING "megaraid_sas: If you have a controller "
2866 "other than PERC5, please upgrade your firmware.\n");
2868 case MFI_CMD_PD_SCSI_IO:
2869 case MFI_CMD_LD_SCSI_IO:
2872 * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been
2873 * issued either through an IO path or an IOCTL path. If it
2874 * was via IOCTL, we will send it to internal completion.
2876 if (cmd->sync_cmd) {
2878 megasas_complete_int_cmd(instance, cmd);
2882 case MFI_CMD_LD_READ:
2883 case MFI_CMD_LD_WRITE:
2886 cmd->scmd->result = alt_status << 16;
2892 atomic_dec(&instance->fw_outstanding);
2894 scsi_dma_unmap(cmd->scmd);
2895 cmd->scmd->scsi_done(cmd->scmd);
2896 megasas_return_cmd(instance, cmd);
2901 switch (hdr->cmd_status) {
2904 cmd->scmd->result = DID_OK << 16;
2907 case MFI_STAT_SCSI_IO_FAILED:
2908 case MFI_STAT_LD_INIT_IN_PROGRESS:
2910 (DID_ERROR << 16) | hdr->scsi_status;
2913 case MFI_STAT_SCSI_DONE_WITH_ERROR:
2915 cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status;
2917 if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) {
2918 memset(cmd->scmd->sense_buffer, 0,
2919 SCSI_SENSE_BUFFERSIZE);
2920 memcpy(cmd->scmd->sense_buffer, cmd->sense,
2923 cmd->scmd->result |= DRIVER_SENSE << 24;
2928 case MFI_STAT_LD_OFFLINE:
2929 case MFI_STAT_DEVICE_NOT_FOUND:
2930 cmd->scmd->result = DID_BAD_TARGET << 16;
2934 printk(KERN_DEBUG "megasas: MFI FW status %#x\n",
2936 cmd->scmd->result = DID_ERROR << 16;
2940 atomic_dec(&instance->fw_outstanding);
2942 scsi_dma_unmap(cmd->scmd);
2943 cmd->scmd->scsi_done(cmd->scmd);
2944 megasas_return_cmd(instance, cmd);
2951 opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
2952 /* Check for LD map update */
2953 if ((opcode == MR_DCMD_LD_MAP_GET_INFO)
2954 && (cmd->frame->dcmd.mbox.b[1] == 1)) {
2955 fusion->fast_path_io = 0;
2956 spin_lock_irqsave(instance->host->host_lock, flags);
2957 if (cmd->frame->hdr.cmd_status != 0) {
2958 if (cmd->frame->hdr.cmd_status !=
2960 printk(KERN_WARNING "megasas: map sync"
2961 "failed, status = 0x%x.\n",
2962 cmd->frame->hdr.cmd_status);
2964 megasas_return_cmd(instance, cmd);
2965 spin_unlock_irqrestore(
2966 instance->host->host_lock,
2972 megasas_return_cmd(instance, cmd);
2975 * Set fast path IO to ZERO.
2976 * Validate Map will set proper value.
2977 * Meanwhile all IOs will go as LD IO.
2979 if (MR_ValidateMapInfo(instance))
2980 fusion->fast_path_io = 1;
2982 fusion->fast_path_io = 0;
2983 megasas_sync_map_info(instance);
2984 spin_unlock_irqrestore(instance->host->host_lock,
2988 if (opcode == MR_DCMD_CTRL_EVENT_GET_INFO ||
2989 opcode == MR_DCMD_CTRL_EVENT_GET) {
2990 spin_lock_irqsave(&poll_aen_lock, flags);
2991 megasas_poll_wait_aen = 0;
2992 spin_unlock_irqrestore(&poll_aen_lock, flags);
2996 * See if got an event notification
2998 if (opcode == MR_DCMD_CTRL_EVENT_WAIT)
2999 megasas_service_aen(instance, cmd);
3001 megasas_complete_int_cmd(instance, cmd);
3007 * Cmd issued to abort another cmd returned
3009 megasas_complete_abort(instance, cmd);
3013 printk("megasas: Unknown command completed! [0x%X]\n",
3020 * megasas_issue_pending_cmds_again - issue all pending cmds
3021 * in FW again because of the fw reset
3022 * @instance: Adapter soft state
3025 megasas_issue_pending_cmds_again(struct megasas_instance *instance)
3027 struct megasas_cmd *cmd;
3028 struct list_head clist_local;
3029 union megasas_evt_class_locale class_locale;
3030 unsigned long flags;
3033 INIT_LIST_HEAD(&clist_local);
3034 spin_lock_irqsave(&instance->hba_lock, flags);
3035 list_splice_init(&instance->internal_reset_pending_q, &clist_local);
3036 spin_unlock_irqrestore(&instance->hba_lock, flags);
3038 while (!list_empty(&clist_local)) {
3039 cmd = list_entry((&clist_local)->next,
3040 struct megasas_cmd, list);
3041 list_del_init(&cmd->list);
3043 if (cmd->sync_cmd || cmd->scmd) {
3044 printk(KERN_NOTICE "megaraid_sas: command %p, %p:%d"
3045 "detected to be pending while HBA reset.\n",
3046 cmd, cmd->scmd, cmd->sync_cmd);
3048 cmd->retry_for_fw_reset++;
3050 if (cmd->retry_for_fw_reset == 3) {
3051 printk(KERN_NOTICE "megaraid_sas: cmd %p, %p:%d"
3052 "was tried multiple times during reset."
3053 "Shutting down the HBA\n",
3054 cmd, cmd->scmd, cmd->sync_cmd);
3055 instance->instancet->disable_intr(instance);
3056 atomic_set(&instance->fw_reset_no_pci_access, 1);
3057 megaraid_sas_kill_hba(instance);
3062 if (cmd->sync_cmd == 1) {
3064 printk(KERN_NOTICE "megaraid_sas: unexpected"
3065 "cmd attached to internal command!\n");
3067 printk(KERN_NOTICE "megasas: %p synchronous cmd"
3068 "on the internal reset queue,"
3069 "issue it again.\n", cmd);
3070 cmd->cmd_status = ENODATA;
3071 instance->instancet->fire_cmd(instance,
3072 cmd->frame_phys_addr ,
3073 0, instance->reg_set);
3074 } else if (cmd->scmd) {
3075 printk(KERN_NOTICE "megasas: %p scsi cmd [%02x]"
3076 "detected on the internal queue, issue again.\n",
3077 cmd, cmd->scmd->cmnd[0]);
3079 atomic_inc(&instance->fw_outstanding);
3080 instance->instancet->fire_cmd(instance,
3081 cmd->frame_phys_addr,
3082 cmd->frame_count-1, instance->reg_set);
3084 printk(KERN_NOTICE "megasas: %p unexpected cmd on the"
3085 "internal reset defer list while re-issue!!\n",
3090 if (instance->aen_cmd) {
3091 printk(KERN_NOTICE "megaraid_sas: aen_cmd in def process\n");
3092 megasas_return_cmd(instance, instance->aen_cmd);
3094 instance->aen_cmd = NULL;
3098 * Initiate AEN (Asynchronous Event Notification)
3100 seq_num = instance->last_seq_num;
3101 class_locale.members.reserved = 0;
3102 class_locale.members.locale = MR_EVT_LOCALE_ALL;
3103 class_locale.members.class = MR_EVT_CLASS_DEBUG;
3105 megasas_register_aen(instance, seq_num, class_locale.word);
3109 * Move the internal reset pending commands to a deferred queue.
3111 * We move the commands pending at internal reset time to a
3112 * pending queue. This queue would be flushed after successful
3113 * completion of the internal reset sequence. if the internal reset
3114 * did not complete in time, the kernel reset handler would flush
3118 megasas_internal_reset_defer_cmds(struct megasas_instance *instance)
3120 struct megasas_cmd *cmd;
3122 u32 max_cmd = instance->max_fw_cmds;
3124 unsigned long flags;
3127 spin_lock_irqsave(&instance->mfi_pool_lock, flags);
3128 for (i = 0; i < max_cmd; i++) {
3129 cmd = instance->cmd_list[i];
3130 if (cmd->sync_cmd == 1 || cmd->scmd) {
3131 printk(KERN_NOTICE "megasas: moving cmd[%d]:%p:%d:%p"
3132 "on the defer queue as internal\n",
3133 defer_index, cmd, cmd->sync_cmd, cmd->scmd);
3135 if (!list_empty(&cmd->list)) {
3136 printk(KERN_NOTICE "megaraid_sas: ERROR while"
3137 " moving this cmd:%p, %d %p, it was"
3138 "discovered on some list?\n",
3139 cmd, cmd->sync_cmd, cmd->scmd);
3141 list_del_init(&cmd->list);
3144 list_add_tail(&cmd->list,
3145 &instance->internal_reset_pending_q);
3148 spin_unlock_irqrestore(&instance->mfi_pool_lock, flags);
3153 process_fw_state_change_wq(struct work_struct *work)
3155 struct megasas_instance *instance =
3156 container_of(work, struct megasas_instance, work_init);
3158 unsigned long flags;
3160 if (instance->adprecovery != MEGASAS_ADPRESET_SM_INFAULT) {
3161 printk(KERN_NOTICE "megaraid_sas: error, recovery st %x \n",
3162 instance->adprecovery);
3166 if (instance->adprecovery == MEGASAS_ADPRESET_SM_INFAULT) {
3167 printk(KERN_NOTICE "megaraid_sas: FW detected to be in fault"
3168 "state, restarting it...\n");
3170 instance->instancet->disable_intr(instance);
3171 atomic_set(&instance->fw_outstanding, 0);
3173 atomic_set(&instance->fw_reset_no_pci_access, 1);
3174 instance->instancet->adp_reset(instance, instance->reg_set);
3175 atomic_set(&instance->fw_reset_no_pci_access, 0 );
3177 printk(KERN_NOTICE "megaraid_sas: FW restarted successfully,"
3178 "initiating next stage...\n");
3180 printk(KERN_NOTICE "megaraid_sas: HBA recovery state machine,"
3181 "state 2 starting...\n");
3183 /*waitting for about 20 second before start the second init*/
3184 for (wait = 0; wait < 30; wait++) {
3188 if (megasas_transition_to_ready(instance, 1)) {
3189 printk(KERN_NOTICE "megaraid_sas:adapter not ready\n");
3191 atomic_set(&instance->fw_reset_no_pci_access, 1);
3192 megaraid_sas_kill_hba(instance);
3196 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS1064R) ||
3197 (instance->pdev->device == PCI_DEVICE_ID_DELL_PERC5) ||
3198 (instance->pdev->device == PCI_DEVICE_ID_LSI_VERDE_ZCR)
3200 *instance->consumer = *instance->producer;
3202 *instance->consumer = 0;
3203 *instance->producer = 0;
3206 megasas_issue_init_mfi(instance);
3208 spin_lock_irqsave(&instance->hba_lock, flags);
3209 instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
3210 spin_unlock_irqrestore(&instance->hba_lock, flags);
3211 instance->instancet->enable_intr(instance);
3213 megasas_issue_pending_cmds_again(instance);
3214 instance->issuepend_done = 1;
3220 * megasas_deplete_reply_queue - Processes all completed commands
3221 * @instance: Adapter soft state
3222 * @alt_status: Alternate status to be returned to
3223 * SCSI mid-layer instead of the status
3224 * returned by the FW
3225 * Note: this must be called with hba lock held
3228 megasas_deplete_reply_queue(struct megasas_instance *instance,
3234 if ((mfiStatus = instance->instancet->check_reset(instance,
3235 instance->reg_set)) == 1) {
3239 if ((mfiStatus = instance->instancet->clear_intr(
3242 /* Hardware may not set outbound_intr_status in MSI-X mode */
3243 if (!instance->msix_vectors)
3247 instance->mfiStatus = mfiStatus;
3249 if ((mfiStatus & MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE)) {
3250 fw_state = instance->instancet->read_fw_status_reg(
3251 instance->reg_set) & MFI_STATE_MASK;
3253 if (fw_state != MFI_STATE_FAULT) {
3254 printk(KERN_NOTICE "megaraid_sas: fw state:%x\n",
3258 if ((fw_state == MFI_STATE_FAULT) &&
3259 (instance->disableOnlineCtrlReset == 0)) {
3260 printk(KERN_NOTICE "megaraid_sas: wait adp restart\n");
3262 if ((instance->pdev->device ==
3263 PCI_DEVICE_ID_LSI_SAS1064R) ||
3264 (instance->pdev->device ==
3265 PCI_DEVICE_ID_DELL_PERC5) ||
3266 (instance->pdev->device ==
3267 PCI_DEVICE_ID_LSI_VERDE_ZCR)) {
3269 *instance->consumer =
3270 cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN);
3274 instance->instancet->disable_intr(instance);
3275 instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT;
3276 instance->issuepend_done = 0;
3278 atomic_set(&instance->fw_outstanding, 0);
3279 megasas_internal_reset_defer_cmds(instance);
3281 printk(KERN_NOTICE "megasas: fwState=%x, stage:%d\n",
3282 fw_state, instance->adprecovery);
3284 schedule_work(&instance->work_init);
3288 printk(KERN_NOTICE "megasas: fwstate:%x, dis_OCR=%x\n",
3289 fw_state, instance->disableOnlineCtrlReset);
3293 tasklet_schedule(&instance->isr_tasklet);
3297 * megasas_isr - isr entry point
3299 static irqreturn_t megasas_isr(int irq, void *devp)
3301 struct megasas_irq_context *irq_context = devp;
3302 struct megasas_instance *instance = irq_context->instance;
3303 unsigned long flags;
3306 if (atomic_read(&instance->fw_reset_no_pci_access))
3309 spin_lock_irqsave(&instance->hba_lock, flags);
3310 rc = megasas_deplete_reply_queue(instance, DID_OK);
3311 spin_unlock_irqrestore(&instance->hba_lock, flags);
3317 * megasas_transition_to_ready - Move the FW to READY state
3318 * @instance: Adapter soft state
3320 * During the initialization, FW passes can potentially be in any one of
3321 * several possible states. If the FW in operational, waiting-for-handshake
3322 * states, driver must take steps to bring it to ready state. Otherwise, it
3323 * has to wait for the ready state.
3326 megasas_transition_to_ready(struct megasas_instance *instance, int ocr)
3332 u32 abs_state, curr_abs_state;
3334 abs_state = instance->instancet->read_fw_status_reg(instance->reg_set);
3335 fw_state = abs_state & MFI_STATE_MASK;
3337 if (fw_state != MFI_STATE_READY)
3338 printk(KERN_INFO "megasas: Waiting for FW to come to ready"
3341 while (fw_state != MFI_STATE_READY) {
3345 case MFI_STATE_FAULT:
3346 printk(KERN_DEBUG "megasas: FW in FAULT state!!\n");
3348 max_wait = MEGASAS_RESET_WAIT_TIME;
3349 cur_state = MFI_STATE_FAULT;
3354 case MFI_STATE_WAIT_HANDSHAKE:
3356 * Set the CLR bit in inbound doorbell
3358 if ((instance->pdev->device ==
3359 PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
3360 (instance->pdev->device ==
3361 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
3362 (instance->pdev->device ==
3363 PCI_DEVICE_ID_LSI_FUSION) ||
3364 (instance->pdev->device ==
3365 PCI_DEVICE_ID_LSI_PLASMA) ||
3366 (instance->pdev->device ==
3367 PCI_DEVICE_ID_LSI_INVADER) ||
3368 (instance->pdev->device ==
3369 PCI_DEVICE_ID_LSI_FURY)) {
3371 MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG,
3372 &instance->reg_set->doorbell);
3375 MFI_INIT_CLEAR_HANDSHAKE|MFI_INIT_HOTPLUG,
3376 &instance->reg_set->inbound_doorbell);
3379 max_wait = MEGASAS_RESET_WAIT_TIME;
3380 cur_state = MFI_STATE_WAIT_HANDSHAKE;
3383 case MFI_STATE_BOOT_MESSAGE_PENDING:
3384 if ((instance->pdev->device ==
3385 PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
3386 (instance->pdev->device ==
3387 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
3388 (instance->pdev->device ==
3389 PCI_DEVICE_ID_LSI_FUSION) ||
3390 (instance->pdev->device ==
3391 PCI_DEVICE_ID_LSI_PLASMA) ||
3392 (instance->pdev->device ==
3393 PCI_DEVICE_ID_LSI_INVADER) ||
3394 (instance->pdev->device ==
3395 PCI_DEVICE_ID_LSI_FURY)) {
3396 writel(MFI_INIT_HOTPLUG,
3397 &instance->reg_set->doorbell);
3399 writel(MFI_INIT_HOTPLUG,
3400 &instance->reg_set->inbound_doorbell);
3402 max_wait = MEGASAS_RESET_WAIT_TIME;
3403 cur_state = MFI_STATE_BOOT_MESSAGE_PENDING;
3406 case MFI_STATE_OPERATIONAL:
3408 * Bring it to READY state; assuming max wait 10 secs
3410 instance->instancet->disable_intr(instance);
3411 if ((instance->pdev->device ==
3412 PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
3413 (instance->pdev->device ==
3414 PCI_DEVICE_ID_LSI_SAS0071SKINNY) ||
3415 (instance->pdev->device
3416 == PCI_DEVICE_ID_LSI_FUSION) ||
3417 (instance->pdev->device
3418 == PCI_DEVICE_ID_LSI_PLASMA) ||
3419 (instance->pdev->device
3420 == PCI_DEVICE_ID_LSI_INVADER) ||
3421 (instance->pdev->device
3422 == PCI_DEVICE_ID_LSI_FURY)) {
3423 writel(MFI_RESET_FLAGS,
3424 &instance->reg_set->doorbell);
3425 if ((instance->pdev->device ==
3426 PCI_DEVICE_ID_LSI_FUSION) ||
3427 (instance->pdev->device ==
3428 PCI_DEVICE_ID_LSI_PLASMA) ||
3429 (instance->pdev->device ==
3430 PCI_DEVICE_ID_LSI_INVADER) ||
3431 (instance->pdev->device ==
3432 PCI_DEVICE_ID_LSI_FURY)) {
3433 for (i = 0; i < (10 * 1000); i += 20) {
3444 writel(MFI_RESET_FLAGS,
3445 &instance->reg_set->inbound_doorbell);
3447 max_wait = MEGASAS_RESET_WAIT_TIME;
3448 cur_state = MFI_STATE_OPERATIONAL;
3451 case MFI_STATE_UNDEFINED:
3453 * This state should not last for more than 2 seconds
3455 max_wait = MEGASAS_RESET_WAIT_TIME;
3456 cur_state = MFI_STATE_UNDEFINED;
3459 case MFI_STATE_BB_INIT:
3460 max_wait = MEGASAS_RESET_WAIT_TIME;
3461 cur_state = MFI_STATE_BB_INIT;
3464 case MFI_STATE_FW_INIT:
3465 max_wait = MEGASAS_RESET_WAIT_TIME;
3466 cur_state = MFI_STATE_FW_INIT;
3469 case MFI_STATE_FW_INIT_2:
3470 max_wait = MEGASAS_RESET_WAIT_TIME;
3471 cur_state = MFI_STATE_FW_INIT_2;
3474 case MFI_STATE_DEVICE_SCAN:
3475 max_wait = MEGASAS_RESET_WAIT_TIME;
3476 cur_state = MFI_STATE_DEVICE_SCAN;
3479 case MFI_STATE_FLUSH_CACHE:
3480 max_wait = MEGASAS_RESET_WAIT_TIME;
3481 cur_state = MFI_STATE_FLUSH_CACHE;
3485 printk(KERN_DEBUG "megasas: Unknown state 0x%x\n",
3491 * The cur_state should not last for more than max_wait secs
3493 for (i = 0; i < (max_wait * 1000); i++) {
3494 curr_abs_state = instance->instancet->
3495 read_fw_status_reg(instance->reg_set);
3497 if (abs_state == curr_abs_state) {
3504 * Return error if fw_state hasn't changed after max_wait
3506 if (curr_abs_state == abs_state) {
3507 printk(KERN_DEBUG "FW state [%d] hasn't changed "
3508 "in %d secs\n", fw_state, max_wait);
3512 abs_state = curr_abs_state;
3513 fw_state = curr_abs_state & MFI_STATE_MASK;
3515 printk(KERN_INFO "megasas: FW now in Ready state\n");
3521 * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool
3522 * @instance: Adapter soft state
3524 static void megasas_teardown_frame_pool(struct megasas_instance *instance)
3527 u32 max_cmd = instance->max_mfi_cmds;
3528 struct megasas_cmd *cmd;
3530 if (!instance->frame_dma_pool)
3534 * Return all frames to pool
3536 for (i = 0; i < max_cmd; i++) {
3538 cmd = instance->cmd_list[i];
3541 pci_pool_free(instance->frame_dma_pool, cmd->frame,
3542 cmd->frame_phys_addr);
3545 pci_pool_free(instance->sense_dma_pool, cmd->sense,
3546 cmd->sense_phys_addr);
3550 * Now destroy the pool itself
3552 pci_pool_destroy(instance->frame_dma_pool);
3553 pci_pool_destroy(instance->sense_dma_pool);
3555 instance->frame_dma_pool = NULL;
3556 instance->sense_dma_pool = NULL;
3560 * megasas_create_frame_pool - Creates DMA pool for cmd frames
3561 * @instance: Adapter soft state
3563 * Each command packet has an embedded DMA memory buffer that is used for
3564 * filling MFI frame and the SG list that immediately follows the frame. This
3565 * function creates those DMA memory buffers for each command packet by using
3566 * PCI pool facility.
3568 static int megasas_create_frame_pool(struct megasas_instance *instance)
3575 struct megasas_cmd *cmd;
3577 max_cmd = instance->max_mfi_cmds;
3580 * Size of our frame is 64 bytes for MFI frame, followed by max SG
3581 * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer
3583 sge_sz = (IS_DMA64) ? sizeof(struct megasas_sge64) :
3584 sizeof(struct megasas_sge32);
3586 if (instance->flag_ieee) {
3587 sge_sz = sizeof(struct megasas_sge_skinny);
3591 * For MFI controllers.
3593 * max_sge_sz = 16 byte (sizeof megasas_sge_skinny)
3594 * Total 960 byte (15 MFI frame of 64 byte)
3596 * Fusion adapter require only 3 extra frame.
3597 * max_num_sge = 16 (defined as MAX_IOCTL_SGE)
3598 * max_sge_sz = 12 byte (sizeof megasas_sge64)
3599 * Total 192 byte (3 MFI frame of 64 byte)
3601 frame_count = instance->ctrl_context ? (3 + 1) : (15 + 1);
3602 total_sz = MEGAMFI_FRAME_SIZE * frame_count;
3604 * Use DMA pool facility provided by PCI layer
3606 instance->frame_dma_pool = pci_pool_create("megasas frame pool",
3607 instance->pdev, total_sz, 256, 0);
3609 if (!instance->frame_dma_pool) {
3610 printk(KERN_DEBUG "megasas: failed to setup frame pool\n");
3614 instance->sense_dma_pool = pci_pool_create("megasas sense pool",
3615 instance->pdev, 128, 4, 0);
3617 if (!instance->sense_dma_pool) {
3618 printk(KERN_DEBUG "megasas: failed to setup sense pool\n");
3620 pci_pool_destroy(instance->frame_dma_pool);
3621 instance->frame_dma_pool = NULL;
3627 * Allocate and attach a frame to each of the commands in cmd_list.
3628 * By making cmd->index as the context instead of the &cmd, we can
3629 * always use 32bit context regardless of the architecture
3631 for (i = 0; i < max_cmd; i++) {
3633 cmd = instance->cmd_list[i];
3635 cmd->frame = pci_pool_alloc(instance->frame_dma_pool,
3636 GFP_KERNEL, &cmd->frame_phys_addr);
3638 cmd->sense = pci_pool_alloc(instance->sense_dma_pool,
3639 GFP_KERNEL, &cmd->sense_phys_addr);
3642 * megasas_teardown_frame_pool() takes care of freeing
3643 * whatever has been allocated
3645 if (!cmd->frame || !cmd->sense) {
3646 printk(KERN_DEBUG "megasas: pci_pool_alloc failed \n");
3647 megasas_teardown_frame_pool(instance);
3651 memset(cmd->frame, 0, total_sz);
3652 cmd->frame->io.context = cpu_to_le32(cmd->index);
3653 cmd->frame->io.pad_0 = 0;
3654 if ((instance->pdev->device != PCI_DEVICE_ID_LSI_FUSION) &&
3655 (instance->pdev->device != PCI_DEVICE_ID_LSI_PLASMA) &&
3656 (instance->pdev->device != PCI_DEVICE_ID_LSI_INVADER) &&
3657 (instance->pdev->device != PCI_DEVICE_ID_LSI_FURY) &&
3659 cmd->frame->hdr.cmd = MFI_CMD_INVALID;
3666 * megasas_free_cmds - Free all the cmds in the free cmd pool
3667 * @instance: Adapter soft state
3669 void megasas_free_cmds(struct megasas_instance *instance)
3672 /* First free the MFI frame pool */
3673 megasas_teardown_frame_pool(instance);
3675 /* Free all the commands in the cmd_list */
3676 for (i = 0; i < instance->max_mfi_cmds; i++)
3678 kfree(instance->cmd_list[i]);
3680 /* Free the cmd_list buffer itself */
3681 kfree(instance->cmd_list);
3682 instance->cmd_list = NULL;
3684 INIT_LIST_HEAD(&instance->cmd_pool);
3688 * megasas_alloc_cmds - Allocates the command packets
3689 * @instance: Adapter soft state
3691 * Each command that is issued to the FW, whether IO commands from the OS or
3692 * internal commands like IOCTLs, are wrapped in local data structure called
3693 * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to
3696 * Each frame has a 32-bit field called context (tag). This context is used
3697 * to get back the megasas_cmd from the frame when a frame gets completed in
3698 * the ISR. Typically the address of the megasas_cmd itself would be used as
3699 * the context. But we wanted to keep the differences between 32 and 64 bit
3700 * systems to the mininum. We always use 32 bit integers for the context. In
3701 * this driver, the 32 bit values are the indices into an array cmd_list.
3702 * This array is used only to look up the megasas_cmd given the context. The
3703 * free commands themselves are maintained in a linked list called cmd_pool.
3705 int megasas_alloc_cmds(struct megasas_instance *instance)
3710 struct megasas_cmd *cmd;
3711 struct fusion_context *fusion;
3713 fusion = instance->ctrl_context;
3714 max_cmd = instance->max_mfi_cmds;
3717 * instance->cmd_list is an array of struct megasas_cmd pointers.
3718 * Allocate the dynamic array first and then allocate individual
3721 instance->cmd_list = kcalloc(max_cmd, sizeof(struct megasas_cmd*), GFP_KERNEL);
3723 if (!instance->cmd_list) {
3724 printk(KERN_DEBUG "megasas: out of memory\n");
3728 memset(instance->cmd_list, 0, sizeof(struct megasas_cmd *) *max_cmd);
3730 for (i = 0; i < max_cmd; i++) {
3731 instance->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd),
3734 if (!instance->cmd_list[i]) {
3736 for (j = 0; j < i; j++)
3737 kfree(instance->cmd_list[j]);
3739 kfree(instance->cmd_list);
3740 instance->cmd_list = NULL;
3746 for (i = 0; i < max_cmd; i++) {
3747 cmd = instance->cmd_list[i];
3748 memset(cmd, 0, sizeof(struct megasas_cmd));
3751 cmd->instance = instance;
3753 list_add_tail(&cmd->list, &instance->cmd_pool);
3757 * Create a frame pool and assign one frame to each cmd
3759 if (megasas_create_frame_pool(instance)) {
3760 printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n");
3761 megasas_free_cmds(instance);
3768 * megasas_get_pd_list_info - Returns FW's pd_list structure
3769 * @instance: Adapter soft state
3770 * @pd_list: pd_list structure
3772 * Issues an internal command (DCMD) to get the FW's controller PD
3773 * list structure. This information is mainly used to find out SYSTEM
3774 * supported by the FW.
3777 megasas_get_pd_list(struct megasas_instance *instance)
3779 int ret = 0, pd_index = 0;
3780 struct megasas_cmd *cmd;
3781 struct megasas_dcmd_frame *dcmd;
3782 struct MR_PD_LIST *ci;
3783 struct MR_PD_ADDRESS *pd_addr;
3784 dma_addr_t ci_h = 0;
3786 cmd = megasas_get_cmd(instance);
3789 printk(KERN_DEBUG "megasas (get_pd_list): Failed to get cmd\n");
3793 dcmd = &cmd->frame->dcmd;
3795 ci = pci_alloc_consistent(instance->pdev,
3796 MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST), &ci_h);
3799 printk(KERN_DEBUG "Failed to alloc mem for pd_list\n");
3800 megasas_return_cmd(instance, cmd);
3804 memset(ci, 0, sizeof(*ci));
3805 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
3807 dcmd->mbox.b[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST;
3808 dcmd->mbox.b[1] = 0;
3809 dcmd->cmd = MFI_CMD_DCMD;
3810 dcmd->cmd_status = 0xFF;
3811 dcmd->sge_count = 1;
3812 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
3815 dcmd->data_xfer_len = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST));
3816 dcmd->opcode = cpu_to_le32(MR_DCMD_PD_LIST_QUERY);
3817 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
3818 dcmd->sgl.sge32[0].length = cpu_to_le32(MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST));
3820 if (instance->ctrl_context && !instance->mask_interrupts)
3821 ret = megasas_issue_blocked_cmd(instance, cmd,
3822 MEGASAS_BLOCKED_CMD_TIMEOUT);
3824 ret = megasas_issue_polled(instance, cmd);
3827 * the following function will get the instance PD LIST.
3833 (le32_to_cpu(ci->count) <
3834 (MEGASAS_MAX_PD_CHANNELS * MEGASAS_MAX_DEV_PER_CHANNEL))) {
3836 memset(instance->local_pd_list, 0,
3837 MEGASAS_MAX_PD * sizeof(struct megasas_pd_list));
3839 for (pd_index = 0; pd_index < le32_to_cpu(ci->count); pd_index++) {
3841 instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].tid =
3842 le16_to_cpu(pd_addr->deviceId);
3843 instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveType =
3844 pd_addr->scsiDevType;
3845 instance->local_pd_list[le16_to_cpu(pd_addr->deviceId)].driveState =
3849 memcpy(instance->pd_list, instance->local_pd_list,
3850 sizeof(instance->pd_list));
3853 pci_free_consistent(instance->pdev,
3854 MEGASAS_MAX_PD * sizeof(struct MR_PD_LIST),
3857 megasas_return_cmd(instance, cmd);
3863 * megasas_get_ld_list_info - Returns FW's ld_list structure
3864 * @instance: Adapter soft state
3865 * @ld_list: ld_list structure
3867 * Issues an internal command (DCMD) to get the FW's controller PD
3868 * list structure. This information is mainly used to find out SYSTEM
3869 * supported by the FW.
3872 megasas_get_ld_list(struct megasas_instance *instance)
3874 int ret = 0, ld_index = 0, ids = 0;
3875 struct megasas_cmd *cmd;
3876 struct megasas_dcmd_frame *dcmd;
3877 struct MR_LD_LIST *ci;
3878 dma_addr_t ci_h = 0;
3881 cmd = megasas_get_cmd(instance);
3884 printk(KERN_DEBUG "megasas_get_ld_list: Failed to get cmd\n");
3888 dcmd = &cmd->frame->dcmd;
3890 ci = pci_alloc_consistent(instance->pdev,
3891 sizeof(struct MR_LD_LIST),
3895 printk(KERN_DEBUG "Failed to alloc mem in get_ld_list\n");
3896 megasas_return_cmd(instance, cmd);
3900 memset(ci, 0, sizeof(*ci));
3901 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
3903 if (instance->supportmax256vd)
3904 dcmd->mbox.b[0] = 1;
3905 dcmd->cmd = MFI_CMD_DCMD;
3906 dcmd->cmd_status = 0xFF;
3907 dcmd->sge_count = 1;
3908 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
3910 dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_LIST));
3911 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_GET_LIST);
3912 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
3913 dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_LIST));
3916 if (instance->ctrl_context && !instance->mask_interrupts)
3917 ret = megasas_issue_blocked_cmd(instance, cmd,
3918 MEGASAS_BLOCKED_CMD_TIMEOUT);
3920 ret = megasas_issue_polled(instance, cmd);
3923 ld_count = le32_to_cpu(ci->ldCount);
3925 /* the following function will get the instance PD LIST */
3927 if ((ret == 0) && (ld_count <= instance->fw_supported_vd_count)) {
3928 memset(instance->ld_ids, 0xff, MAX_LOGICAL_DRIVES_EXT);
3930 for (ld_index = 0; ld_index < ld_count; ld_index++) {
3931 if (ci->ldList[ld_index].state != 0) {
3932 ids = ci->ldList[ld_index].ref.targetId;
3933 instance->ld_ids[ids] =
3934 ci->ldList[ld_index].ref.targetId;
3939 pci_free_consistent(instance->pdev,
3940 sizeof(struct MR_LD_LIST),
3944 megasas_return_cmd(instance, cmd);
3949 * megasas_ld_list_query - Returns FW's ld_list structure
3950 * @instance: Adapter soft state
3951 * @ld_list: ld_list structure
3953 * Issues an internal command (DCMD) to get the FW's controller PD
3954 * list structure. This information is mainly used to find out SYSTEM
3955 * supported by the FW.
3958 megasas_ld_list_query(struct megasas_instance *instance, u8 query_type)
3960 int ret = 0, ld_index = 0, ids = 0;
3961 struct megasas_cmd *cmd;
3962 struct megasas_dcmd_frame *dcmd;
3963 struct MR_LD_TARGETID_LIST *ci;
3964 dma_addr_t ci_h = 0;
3967 cmd = megasas_get_cmd(instance);
3971 "megasas:(megasas_ld_list_query): Failed to get cmd\n");
3975 dcmd = &cmd->frame->dcmd;
3977 ci = pci_alloc_consistent(instance->pdev,
3978 sizeof(struct MR_LD_TARGETID_LIST), &ci_h);
3982 "megasas: Failed to alloc mem for ld_list_query\n");
3983 megasas_return_cmd(instance, cmd);
3987 memset(ci, 0, sizeof(*ci));
3988 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
3990 dcmd->mbox.b[0] = query_type;
3991 if (instance->supportmax256vd)
3992 dcmd->mbox.b[2] = 1;
3994 dcmd->cmd = MFI_CMD_DCMD;
3995 dcmd->cmd_status = 0xFF;
3996 dcmd->sge_count = 1;
3997 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
3999 dcmd->data_xfer_len = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST));
4000 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_LIST_QUERY);
4001 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
4002 dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST));
4005 if (instance->ctrl_context && !instance->mask_interrupts)
4006 ret = megasas_issue_blocked_cmd(instance, cmd,
4007 MEGASAS_BLOCKED_CMD_TIMEOUT);
4009 ret = megasas_issue_polled(instance, cmd);
4011 tgtid_count = le32_to_cpu(ci->count);
4013 if ((ret == 0) && (tgtid_count <= (instance->fw_supported_vd_count))) {
4014 memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
4015 for (ld_index = 0; ld_index < tgtid_count; ld_index++) {
4016 ids = ci->targetId[ld_index];
4017 instance->ld_ids[ids] = ci->targetId[ld_index];
4022 pci_free_consistent(instance->pdev, sizeof(struct MR_LD_TARGETID_LIST),
4025 megasas_return_cmd(instance, cmd);
4031 * megasas_update_ext_vd_details : Update details w.r.t Extended VD
4032 * instance : Controller's instance
4034 static void megasas_update_ext_vd_details(struct megasas_instance *instance)
4036 struct fusion_context *fusion;
4040 fusion = instance->ctrl_context;
4041 /* For MFI based controllers return dummy success */
4045 instance->supportmax256vd =
4046 instance->ctrl_info->adapterOperations3.supportMaxExtLDs;
4047 /* Below is additional check to address future FW enhancement */
4048 if (instance->ctrl_info->max_lds > 64)
4049 instance->supportmax256vd = 1;
4051 instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS
4052 * MEGASAS_MAX_DEV_PER_CHANNEL;
4053 instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS
4054 * MEGASAS_MAX_DEV_PER_CHANNEL;
4055 if (instance->supportmax256vd) {
4056 instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT;
4057 instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
4059 instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES;
4060 instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
4063 dev_info(&instance->pdev->dev,
4064 "firmware type\t: %s\n",
4065 instance->supportmax256vd ? "Extended VD(240 VD)firmware" :
4066 "Legacy(64 VD) firmware");
4068 old_map_sz = sizeof(struct MR_FW_RAID_MAP) +
4069 (sizeof(struct MR_LD_SPAN_MAP) *
4070 (instance->fw_supported_vd_count - 1));
4071 new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT);
4072 fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP) +
4073 (sizeof(struct MR_LD_SPAN_MAP) *
4074 (instance->drv_supported_vd_count - 1));
4076 fusion->max_map_sz = max(old_map_sz, new_map_sz);
4079 if (instance->supportmax256vd)
4080 fusion->current_map_sz = new_map_sz;
4082 fusion->current_map_sz = old_map_sz;
4087 * megasas_get_controller_info - Returns FW's controller structure
4088 * @instance: Adapter soft state
4090 * Issues an internal command (DCMD) to get the FW's controller structure.
4091 * This information is mainly used to find out the maximum IO transfer per
4092 * command supported by the FW.
4095 megasas_get_ctrl_info(struct megasas_instance *instance)
4098 struct megasas_cmd *cmd;
4099 struct megasas_dcmd_frame *dcmd;
4100 struct megasas_ctrl_info *ci;
4101 struct megasas_ctrl_info *ctrl_info;
4102 dma_addr_t ci_h = 0;
4104 ctrl_info = instance->ctrl_info;
4106 cmd = megasas_get_cmd(instance);
4109 printk(KERN_DEBUG "megasas: Failed to get a free cmd\n");
4113 dcmd = &cmd->frame->dcmd;
4115 ci = pci_alloc_consistent(instance->pdev,
4116 sizeof(struct megasas_ctrl_info), &ci_h);
4119 printk(KERN_DEBUG "Failed to alloc mem for ctrl info\n");
4120 megasas_return_cmd(instance, cmd);
4124 memset(ci, 0, sizeof(*ci));
4125 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
4127 dcmd->cmd = MFI_CMD_DCMD;
4128 dcmd->cmd_status = 0xFF;
4129 dcmd->sge_count = 1;
4130 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
4133 dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_ctrl_info));
4134 dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_GET_INFO);
4135 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
4136 dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_ctrl_info));
4137 dcmd->mbox.b[0] = 1;
4139 if (instance->ctrl_context && !instance->mask_interrupts)
4140 ret = megasas_issue_blocked_cmd(instance, cmd,
4141 MEGASAS_BLOCKED_CMD_TIMEOUT);
4143 ret = megasas_issue_polled(instance, cmd);
4146 memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info));
4147 le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties);
4148 le32_to_cpus((u32 *)&ctrl_info->adapterOperations2);
4149 le32_to_cpus((u32 *)&ctrl_info->adapterOperations3);
4150 megasas_update_ext_vd_details(instance);
4151 instance->is_imr = (ctrl_info->memory_size ? 0 : 1);
4152 dev_info(&instance->pdev->dev,
4153 "controller type\t: %s(%dMB)\n",
4154 instance->is_imr ? "iMR" : "MR",
4155 le16_to_cpu(ctrl_info->memory_size));
4158 pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info),
4161 megasas_return_cmd(instance, cmd);
4166 * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer
4169 * @instance: Adapter soft state
4170 * @crash_buf_state - tell FW to turn ON/OFF crash dump feature
4171 MR_CRASH_BUF_TURN_OFF = 0
4172 MR_CRASH_BUF_TURN_ON = 1
4173 * @return 0 on success non-zero on failure.
4174 * Issues an internal command (DCMD) to set parameters for crash dump feature.
4175 * Driver will send address of crash dump DMA buffer and set mbox to tell FW
4176 * that driver supports crash dump feature. This DCMD will be sent only if
4177 * crash dump feature is supported by the FW.
4180 int megasas_set_crash_dump_params(struct megasas_instance *instance,
4184 struct megasas_cmd *cmd;
4185 struct megasas_dcmd_frame *dcmd;
4187 cmd = megasas_get_cmd(instance);
4190 dev_err(&instance->pdev->dev, "Failed to get a free cmd\n");
4195 dcmd = &cmd->frame->dcmd;
4197 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
4198 dcmd->mbox.b[0] = crash_buf_state;
4199 dcmd->cmd = MFI_CMD_DCMD;
4200 dcmd->cmd_status = 0xFF;
4201 dcmd->sge_count = 1;
4202 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE);
4205 dcmd->data_xfer_len = cpu_to_le32(CRASH_DMA_BUF_SIZE);
4206 dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS);
4207 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->crash_dump_h);
4208 dcmd->sgl.sge32[0].length = cpu_to_le32(CRASH_DMA_BUF_SIZE);
4210 if (instance->ctrl_context && !instance->mask_interrupts)
4211 ret = megasas_issue_blocked_cmd(instance, cmd,
4212 MEGASAS_BLOCKED_CMD_TIMEOUT);
4214 ret = megasas_issue_polled(instance, cmd);
4216 megasas_return_cmd(instance, cmd);
4221 * megasas_issue_init_mfi - Initializes the FW
4222 * @instance: Adapter soft state
4224 * Issues the INIT MFI cmd
4227 megasas_issue_init_mfi(struct megasas_instance *instance)
4231 struct megasas_cmd *cmd;
4233 struct megasas_init_frame *init_frame;
4234 struct megasas_init_queue_info *initq_info;
4235 dma_addr_t init_frame_h;
4236 dma_addr_t initq_info_h;
4239 * Prepare a init frame. Note the init frame points to queue info
4240 * structure. Each frame has SGL allocated after first 64 bytes. For
4241 * this frame - since we don't need any SGL - we use SGL's space as
4242 * queue info structure
4244 * We will not get a NULL command below. We just created the pool.
4246 cmd = megasas_get_cmd(instance);
4248 init_frame = (struct megasas_init_frame *)cmd->frame;
4249 initq_info = (struct megasas_init_queue_info *)
4250 ((unsigned long)init_frame + 64);
4252 init_frame_h = cmd->frame_phys_addr;
4253 initq_info_h = init_frame_h + 64;
4255 context = init_frame->context;
4256 memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
4257 memset(initq_info, 0, sizeof(struct megasas_init_queue_info));
4258 init_frame->context = context;
4260 initq_info->reply_queue_entries = cpu_to_le32(instance->max_fw_cmds + 1);
4261 initq_info->reply_queue_start_phys_addr_lo = cpu_to_le32(instance->reply_queue_h);
4263 initq_info->producer_index_phys_addr_lo = cpu_to_le32(instance->producer_h);
4264 initq_info->consumer_index_phys_addr_lo = cpu_to_le32(instance->consumer_h);
4266 init_frame->cmd = MFI_CMD_INIT;
4267 init_frame->cmd_status = 0xFF;
4268 init_frame->queue_info_new_phys_addr_lo =
4269 cpu_to_le32(lower_32_bits(initq_info_h));
4270 init_frame->queue_info_new_phys_addr_hi =
4271 cpu_to_le32(upper_32_bits(initq_info_h));
4273 init_frame->data_xfer_len = cpu_to_le32(sizeof(struct megasas_init_queue_info));
4276 * disable the intr before firing the init frame to FW
4278 instance->instancet->disable_intr(instance);
4281 * Issue the init frame in polled mode
4284 if (megasas_issue_polled(instance, cmd)) {
4285 printk(KERN_ERR "megasas: Failed to init firmware\n");
4286 megasas_return_cmd(instance, cmd);
4290 megasas_return_cmd(instance, cmd);
4299 megasas_init_adapter_mfi(struct megasas_instance *instance)
4301 struct megasas_register_set __iomem *reg_set;
4305 reg_set = instance->reg_set;
4308 * Get various operational parameters from status register
4310 instance->max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
4312 * Reduce the max supported cmds by 1. This is to ensure that the
4313 * reply_q_sz (1 more than the max cmd that driver may send)
4314 * does not exceed max cmds that the FW can support
4316 instance->max_fw_cmds = instance->max_fw_cmds-1;
4317 instance->max_mfi_cmds = instance->max_fw_cmds;
4318 instance->max_num_sge = (instance->instancet->read_fw_status_reg(reg_set) & 0xFF0000) >>
4321 * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands
4322 * are reserved for IOCTL + driver's internal DCMDs.
4324 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
4325 (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY)) {
4326 instance->max_scsi_cmds = (instance->max_fw_cmds -
4327 MEGASAS_SKINNY_INT_CMDS);
4328 sema_init(&instance->ioctl_sem, MEGASAS_SKINNY_INT_CMDS);
4330 instance->max_scsi_cmds = (instance->max_fw_cmds -
4332 sema_init(&instance->ioctl_sem, (MEGASAS_MFI_IOCTL_CMDS));
4336 * Create a pool of commands
4338 if (megasas_alloc_cmds(instance))
4339 goto fail_alloc_cmds;
4342 * Allocate memory for reply queue. Length of reply queue should
4343 * be _one_ more than the maximum commands handled by the firmware.
4345 * Note: When FW completes commands, it places corresponding contex
4346 * values in this circular reply queue. This circular queue is a fairly
4347 * typical producer-consumer queue. FW is the producer (of completed
4348 * commands) and the driver is the consumer.
4350 context_sz = sizeof(u32);
4351 reply_q_sz = context_sz * (instance->max_fw_cmds + 1);
4353 instance->reply_queue = pci_alloc_consistent(instance->pdev,
4355 &instance->reply_queue_h);
4357 if (!instance->reply_queue) {
4358 printk(KERN_DEBUG "megasas: Out of DMA mem for reply queue\n");
4359 goto fail_reply_queue;
4362 if (megasas_issue_init_mfi(instance))
4365 if (megasas_get_ctrl_info(instance)) {
4366 dev_err(&instance->pdev->dev, "(%d): Could get controller info "
4367 "Fail from %s %d\n", instance->unique_id,
4368 __func__, __LINE__);
4372 instance->fw_support_ieee = 0;
4373 instance->fw_support_ieee =
4374 (instance->instancet->read_fw_status_reg(reg_set) &
4377 printk(KERN_NOTICE "megasas_init_mfi: fw_support_ieee=%d",
4378 instance->fw_support_ieee);
4380 if (instance->fw_support_ieee)
4381 instance->flag_ieee = 1;
4387 pci_free_consistent(instance->pdev, reply_q_sz,
4388 instance->reply_queue, instance->reply_queue_h);
4390 megasas_free_cmds(instance);
4397 * megasas_setup_irqs_msix - register legacy interrupts.
4398 * @instance: Adapter soft state
4400 * Do not enable interrupt, only setup ISRs.
4402 * Return 0 on success.
4405 megasas_setup_irqs_ioapic(struct megasas_instance *instance)
4407 struct pci_dev *pdev;
4409 pdev = instance->pdev;
4410 instance->irq_context[0].instance = instance;
4411 instance->irq_context[0].MSIxIndex = 0;
4412 if (request_irq(pdev->irq, instance->instancet->service_isr,
4413 IRQF_SHARED, "megasas", &instance->irq_context[0])) {
4414 dev_err(&instance->pdev->dev,
4415 "Failed to register IRQ from %s %d\n",
4416 __func__, __LINE__);
4423 * megasas_setup_irqs_msix - register MSI-x interrupts.
4424 * @instance: Adapter soft state
4425 * @is_probe: Driver probe check
4427 * Do not enable interrupt, only setup ISRs.
4429 * Return 0 on success.
4432 megasas_setup_irqs_msix(struct megasas_instance *instance, u8 is_probe)
4435 struct pci_dev *pdev;
4437 pdev = instance->pdev;
4440 cpu = cpumask_first(cpu_online_mask);
4441 for (i = 0; i < instance->msix_vectors; i++) {
4442 instance->irq_context[i].instance = instance;
4443 instance->irq_context[i].MSIxIndex = i;
4444 if (request_irq(instance->msixentry[i].vector,
4445 instance->instancet->service_isr, 0, "megasas",
4446 &instance->irq_context[i])) {
4447 dev_err(&instance->pdev->dev,
4448 "Failed to register IRQ for vector %d.\n", i);
4449 for (j = 0; j < i; j++) {
4450 if (smp_affinity_enable)
4451 irq_set_affinity_hint(
4452 instance->msixentry[j].vector, NULL);
4453 free_irq(instance->msixentry[j].vector,
4454 &instance->irq_context[j]);
4456 /* Retry irq register for IO_APIC*/
4457 instance->msix_vectors = 0;
4459 return megasas_setup_irqs_ioapic(instance);
4463 if (smp_affinity_enable) {
4464 if (irq_set_affinity_hint(instance->msixentry[i].vector,
4466 dev_err(&instance->pdev->dev,
4467 "Failed to set affinity hint"
4468 " for cpu %d\n", cpu);
4469 cpu = cpumask_next(cpu, cpu_online_mask);
4476 * megasas_destroy_irqs- unregister interrupts.
4477 * @instance: Adapter soft state
4481 megasas_destroy_irqs(struct megasas_instance *instance) {
4485 if (instance->msix_vectors)
4486 for (i = 0; i < instance->msix_vectors; i++) {
4487 if (smp_affinity_enable)
4488 irq_set_affinity_hint(
4489 instance->msixentry[i].vector, NULL);
4490 free_irq(instance->msixentry[i].vector,
4491 &instance->irq_context[i]);
4494 free_irq(instance->pdev->irq, &instance->irq_context[0]);
4498 * megasas_init_fw - Initializes the FW
4499 * @instance: Adapter soft state
4501 * This is the main function for initializing firmware
4504 static int megasas_init_fw(struct megasas_instance *instance)
4508 u32 tmp_sectors, msix_enable, scratch_pad_2;
4509 resource_size_t base_addr;
4510 struct megasas_register_set __iomem *reg_set;
4511 struct megasas_ctrl_info *ctrl_info = NULL;
4512 unsigned long bar_list;
4513 int i, loop, fw_msix_count = 0;
4514 struct IOV_111 *iovPtr;
4516 /* Find first memory bar */
4517 bar_list = pci_select_bars(instance->pdev, IORESOURCE_MEM);
4518 instance->bar = find_first_bit(&bar_list, sizeof(unsigned long));
4519 if (pci_request_selected_regions(instance->pdev, instance->bar,
4521 printk(KERN_DEBUG "megasas: IO memory region busy!\n");
4525 base_addr = pci_resource_start(instance->pdev, instance->bar);
4526 instance->reg_set = ioremap_nocache(base_addr, 8192);
4528 if (!instance->reg_set) {
4529 printk(KERN_DEBUG "megasas: Failed to map IO mem\n");
4533 reg_set = instance->reg_set;
4535 switch (instance->pdev->device) {
4536 case PCI_DEVICE_ID_LSI_FUSION:
4537 case PCI_DEVICE_ID_LSI_PLASMA:
4538 case PCI_DEVICE_ID_LSI_INVADER:
4539 case PCI_DEVICE_ID_LSI_FURY:
4540 instance->instancet = &megasas_instance_template_fusion;
4542 case PCI_DEVICE_ID_LSI_SAS1078R:
4543 case PCI_DEVICE_ID_LSI_SAS1078DE:
4544 instance->instancet = &megasas_instance_template_ppc;
4546 case PCI_DEVICE_ID_LSI_SAS1078GEN2:
4547 case PCI_DEVICE_ID_LSI_SAS0079GEN2:
4548 instance->instancet = &megasas_instance_template_gen2;
4550 case PCI_DEVICE_ID_LSI_SAS0073SKINNY:
4551 case PCI_DEVICE_ID_LSI_SAS0071SKINNY:
4552 instance->instancet = &megasas_instance_template_skinny;
4554 case PCI_DEVICE_ID_LSI_SAS1064R:
4555 case PCI_DEVICE_ID_DELL_PERC5:
4557 instance->instancet = &megasas_instance_template_xscale;
4561 if (megasas_transition_to_ready(instance, 0)) {
4562 atomic_set(&instance->fw_reset_no_pci_access, 1);
4563 instance->instancet->adp_reset
4564 (instance, instance->reg_set);
4565 atomic_set(&instance->fw_reset_no_pci_access, 0);
4566 dev_info(&instance->pdev->dev,
4567 "megasas: FW restarted successfully from %s!\n",
4570 /*waitting for about 30 second before retry*/
4573 if (megasas_transition_to_ready(instance, 0))
4574 goto fail_ready_state;
4578 * MSI-X host index 0 is common for all adapter.
4579 * It is used for all MPT based Adapters.
4581 instance->reply_post_host_index_addr[0] =
4582 (u32 __iomem *)((u8 __iomem *)instance->reg_set +
4583 MPI2_REPLY_POST_HOST_INDEX_OFFSET);
4585 /* Check if MSI-X is supported while in ready state */
4586 msix_enable = (instance->instancet->read_fw_status_reg(reg_set) &
4588 if (msix_enable && !msix_disable) {
4589 scratch_pad_2 = readl
4590 (&instance->reg_set->outbound_scratch_pad_2);
4591 /* Check max MSI-X vectors */
4592 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
4593 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA)) {
4594 instance->msix_vectors = (scratch_pad_2
4595 & MR_MAX_REPLY_QUEUES_OFFSET) + 1;
4596 fw_msix_count = instance->msix_vectors;
4598 instance->msix_vectors =
4600 instance->msix_vectors);
4601 } else if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER)
4602 || (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
4603 /* Invader/Fury supports more than 8 MSI-X */
4604 instance->msix_vectors = ((scratch_pad_2
4605 & MR_MAX_REPLY_QUEUES_EXT_OFFSET)
4606 >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT) + 1;
4607 fw_msix_count = instance->msix_vectors;
4608 /* Save 1-15 reply post index address to local memory
4609 * Index 0 is already saved from reg offset
4610 * MPI2_REPLY_POST_HOST_INDEX_OFFSET
4612 for (loop = 1; loop < MR_MAX_MSIX_REG_ARRAY; loop++) {
4613 instance->reply_post_host_index_addr[loop] =
4615 ((u8 __iomem *)instance->reg_set +
4616 MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET
4620 instance->msix_vectors = min(msix_vectors,
4621 instance->msix_vectors);
4623 instance->msix_vectors = 1;
4624 /* Don't bother allocating more MSI-X vectors than cpus */
4625 instance->msix_vectors = min(instance->msix_vectors,
4626 (unsigned int)num_online_cpus());
4627 for (i = 0; i < instance->msix_vectors; i++)
4628 instance->msixentry[i].entry = i;
4629 i = pci_enable_msix_range(instance->pdev, instance->msixentry,
4630 1, instance->msix_vectors);
4632 instance->msix_vectors = i;
4634 instance->msix_vectors = 0;
4636 dev_info(&instance->pdev->dev,
4637 "firmware supports msix\t: (%d)", fw_msix_count);
4638 dev_info(&instance->pdev->dev,
4639 "current msix/online cpus\t: (%d/%d)\n",
4640 instance->msix_vectors, (unsigned int)num_online_cpus());
4642 if (instance->msix_vectors ?
4643 megasas_setup_irqs_msix(instance, 1) :
4644 megasas_setup_irqs_ioapic(instance))
4645 goto fail_setup_irqs;
4648 instance->ctrl_info = kzalloc(sizeof(struct megasas_ctrl_info),
4650 if (instance->ctrl_info == NULL)
4651 goto fail_init_adapter;
4654 * Below are default value for legacy Firmware.
4655 * non-fusion based controllers
4657 instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES;
4658 instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
4659 /* Get operational params, sge flags, send init cmd to controller */
4660 if (instance->instancet->init_adapter(instance))
4661 goto fail_init_adapter;
4662 instance->instancet->enable_intr(instance);
4664 printk(KERN_ERR "megasas: INIT adapter done\n");
4667 * the following function will get the PD LIST.
4670 memset(instance->pd_list, 0 ,
4671 (MEGASAS_MAX_PD * sizeof(struct megasas_pd_list)));
4672 if (megasas_get_pd_list(instance) < 0) {
4673 printk(KERN_ERR "megasas: failed to get PD list\n");
4674 goto fail_get_pd_list;
4677 memset(instance->ld_ids, 0xff, MEGASAS_MAX_LD_IDS);
4678 if (megasas_ld_list_query(instance,
4679 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
4680 megasas_get_ld_list(instance);
4683 * Compute the max allowed sectors per IO: The controller info has two
4684 * limits on max sectors. Driver should use the minimum of these two.
4686 * 1 << stripe_sz_ops.min = max sectors per strip
4688 * Note that older firmwares ( < FW ver 30) didn't report information
4689 * to calculate max_sectors_1. So the number ended up as zero always.
4692 ctrl_info = instance->ctrl_info;
4694 max_sectors_1 = (1 << ctrl_info->stripe_sz_ops.min) *
4695 le16_to_cpu(ctrl_info->max_strips_per_io);
4696 max_sectors_2 = le32_to_cpu(ctrl_info->max_request_size);
4698 tmp_sectors = min_t(u32, max_sectors_1 , max_sectors_2);
4700 instance->disableOnlineCtrlReset =
4701 ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset;
4702 instance->mpio = ctrl_info->adapterOperations2.mpio;
4703 instance->UnevenSpanSupport =
4704 ctrl_info->adapterOperations2.supportUnevenSpans;
4705 if (instance->UnevenSpanSupport) {
4706 struct fusion_context *fusion = instance->ctrl_context;
4707 if (MR_ValidateMapInfo(instance))
4708 fusion->fast_path_io = 1;
4710 fusion->fast_path_io = 0;
4713 if (ctrl_info->host_interface.SRIOV) {
4714 if (!ctrl_info->adapterOperations2.activePassive)
4715 instance->PlasmaFW111 = 1;
4717 if (!instance->PlasmaFW111)
4718 instance->requestorId =
4719 ctrl_info->iov.requestorId;
4721 iovPtr = (struct IOV_111 *)((unsigned char *)ctrl_info + IOV_111_OFFSET);
4722 instance->requestorId = iovPtr->requestorId;
4724 dev_warn(&instance->pdev->dev, "I am VF "
4725 "requestorId %d\n", instance->requestorId);
4728 instance->crash_dump_fw_support =
4729 ctrl_info->adapterOperations3.supportCrashDump;
4730 instance->crash_dump_drv_support =
4731 (instance->crash_dump_fw_support &&
4732 instance->crash_dump_buf);
4733 if (instance->crash_dump_drv_support)
4734 megasas_set_crash_dump_params(instance,
4735 MR_CRASH_BUF_TURN_OFF);
4738 if (instance->crash_dump_buf)
4739 pci_free_consistent(instance->pdev,
4741 instance->crash_dump_buf,
4742 instance->crash_dump_h);
4743 instance->crash_dump_buf = NULL;
4746 instance->secure_jbod_support =
4747 ctrl_info->adapterOperations3.supportSecurityonJBOD;
4749 dev_info(&instance->pdev->dev,
4750 "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n",
4751 le16_to_cpu(ctrl_info->pci.vendor_id),
4752 le16_to_cpu(ctrl_info->pci.device_id),
4753 le16_to_cpu(ctrl_info->pci.sub_vendor_id),
4754 le16_to_cpu(ctrl_info->pci.sub_device_id));
4755 dev_info(&instance->pdev->dev, "unevenspan support : %s\n",
4756 instance->UnevenSpanSupport ? "yes" : "no");
4757 dev_info(&instance->pdev->dev, "disable ocr : %s\n",
4758 instance->disableOnlineCtrlReset ? "yes" : "no");
4759 dev_info(&instance->pdev->dev, "firmware crash dump : %s\n",
4760 instance->crash_dump_drv_support ? "yes" : "no");
4761 dev_info(&instance->pdev->dev, "secure jbod : %s\n",
4762 instance->secure_jbod_support ? "yes" : "no");
4765 instance->max_sectors_per_req = instance->max_num_sge *
4767 if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors))
4768 instance->max_sectors_per_req = tmp_sectors;
4770 /* Check for valid throttlequeuedepth module parameter */
4771 if (throttlequeuedepth &&
4772 throttlequeuedepth <= instance->max_scsi_cmds)
4773 instance->throttlequeuedepth = throttlequeuedepth;
4775 instance->throttlequeuedepth =
4776 MEGASAS_THROTTLE_QUEUE_DEPTH;
4779 * Setup tasklet for cmd completion
4782 tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
4783 (unsigned long)instance);
4785 /* Launch SR-IOV heartbeat timer */
4786 if (instance->requestorId) {
4787 if (!megasas_sriov_start_heartbeat(instance, 1))
4788 megasas_start_timer(instance,
4789 &instance->sriov_heartbeat_timer,
4790 megasas_sriov_heartbeat_handler,
4791 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
4793 instance->skip_heartbeat_timer_del = 1;
4799 instance->instancet->disable_intr(instance);
4801 megasas_destroy_irqs(instance);
4803 if (instance->msix_vectors)
4804 pci_disable_msix(instance->pdev);
4805 instance->msix_vectors = 0;
4807 kfree(instance->ctrl_info);
4808 instance->ctrl_info = NULL;
4809 iounmap(instance->reg_set);
4812 pci_release_selected_regions(instance->pdev, instance->bar);
4818 * megasas_release_mfi - Reverses the FW initialization
4819 * @intance: Adapter soft state
4821 static void megasas_release_mfi(struct megasas_instance *instance)
4823 u32 reply_q_sz = sizeof(u32) *(instance->max_mfi_cmds + 1);
4825 if (instance->reply_queue)
4826 pci_free_consistent(instance->pdev, reply_q_sz,
4827 instance->reply_queue, instance->reply_queue_h);
4829 megasas_free_cmds(instance);
4831 iounmap(instance->reg_set);
4833 pci_release_selected_regions(instance->pdev, instance->bar);
4837 * megasas_get_seq_num - Gets latest event sequence numbers
4838 * @instance: Adapter soft state
4839 * @eli: FW event log sequence numbers information
4841 * FW maintains a log of all events in a non-volatile area. Upper layers would
4842 * usually find out the latest sequence number of the events, the seq number at
4843 * the boot etc. They would "read" all the events below the latest seq number
4844 * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq
4845 * number), they would subsribe to AEN (asynchronous event notification) and
4846 * wait for the events to happen.
4849 megasas_get_seq_num(struct megasas_instance *instance,
4850 struct megasas_evt_log_info *eli)
4852 struct megasas_cmd *cmd;
4853 struct megasas_dcmd_frame *dcmd;
4854 struct megasas_evt_log_info *el_info;
4855 dma_addr_t el_info_h = 0;
4857 cmd = megasas_get_cmd(instance);
4863 dcmd = &cmd->frame->dcmd;
4864 el_info = pci_alloc_consistent(instance->pdev,
4865 sizeof(struct megasas_evt_log_info),
4869 megasas_return_cmd(instance, cmd);
4873 memset(el_info, 0, sizeof(*el_info));
4874 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
4876 dcmd->cmd = MFI_CMD_DCMD;
4877 dcmd->cmd_status = 0x0;
4878 dcmd->sge_count = 1;
4879 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
4882 dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_log_info));
4883 dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO);
4884 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(el_info_h);
4885 dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_log_info));
4887 if (megasas_issue_blocked_cmd(instance, cmd, 30))
4888 dev_err(&instance->pdev->dev, "Command timedout"
4889 "from %s\n", __func__);
4892 * Copy the data back into callers buffer
4894 eli->newest_seq_num = el_info->newest_seq_num;
4895 eli->oldest_seq_num = el_info->oldest_seq_num;
4896 eli->clear_seq_num = el_info->clear_seq_num;
4897 eli->shutdown_seq_num = el_info->shutdown_seq_num;
4898 eli->boot_seq_num = el_info->boot_seq_num;
4901 pci_free_consistent(instance->pdev, sizeof(struct megasas_evt_log_info),
4902 el_info, el_info_h);
4904 megasas_return_cmd(instance, cmd);
4910 * megasas_register_aen - Registers for asynchronous event notification
4911 * @instance: Adapter soft state
4912 * @seq_num: The starting sequence number
4913 * @class_locale: Class of the event
4915 * This function subscribes for AEN for events beyond the @seq_num. It requests
4916 * to be notified if and only if the event is of type @class_locale
4919 megasas_register_aen(struct megasas_instance *instance, u32 seq_num,
4920 u32 class_locale_word)
4923 struct megasas_cmd *cmd;
4924 struct megasas_dcmd_frame *dcmd;
4925 union megasas_evt_class_locale curr_aen;
4926 union megasas_evt_class_locale prev_aen;
4929 * If there an AEN pending already (aen_cmd), check if the
4930 * class_locale of that pending AEN is inclusive of the new
4931 * AEN request we currently have. If it is, then we don't have
4932 * to do anything. In other words, whichever events the current
4933 * AEN request is subscribing to, have already been subscribed
4936 * If the old_cmd is _not_ inclusive, then we have to abort
4937 * that command, form a class_locale that is superset of both
4938 * old and current and re-issue to the FW
4941 curr_aen.word = class_locale_word;
4943 if (instance->aen_cmd) {
4946 le32_to_cpu(instance->aen_cmd->frame->dcmd.mbox.w[1]);
4949 * A class whose enum value is smaller is inclusive of all
4950 * higher values. If a PROGRESS (= -1) was previously
4951 * registered, then a new registration requests for higher
4952 * classes need not be sent to FW. They are automatically
4955 * Locale numbers don't have such hierarchy. They are bitmap
4958 if ((prev_aen.members.class <= curr_aen.members.class) &&
4959 !((prev_aen.members.locale & curr_aen.members.locale) ^
4960 curr_aen.members.locale)) {
4962 * Previously issued event registration includes
4963 * current request. Nothing to do.
4967 curr_aen.members.locale |= prev_aen.members.locale;
4969 if (prev_aen.members.class < curr_aen.members.class)
4970 curr_aen.members.class = prev_aen.members.class;
4972 instance->aen_cmd->abort_aen = 1;
4973 ret_val = megasas_issue_blocked_abort_cmd(instance,
4978 printk(KERN_DEBUG "megasas: Failed to abort "
4979 "previous AEN command\n");
4985 cmd = megasas_get_cmd(instance);
4990 dcmd = &cmd->frame->dcmd;
4992 memset(instance->evt_detail, 0, sizeof(struct megasas_evt_detail));
4995 * Prepare DCMD for aen registration
4997 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
4999 dcmd->cmd = MFI_CMD_DCMD;
5000 dcmd->cmd_status = 0x0;
5001 dcmd->sge_count = 1;
5002 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
5005 dcmd->data_xfer_len = cpu_to_le32(sizeof(struct megasas_evt_detail));
5006 dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT);
5007 dcmd->mbox.w[0] = cpu_to_le32(seq_num);
5008 instance->last_seq_num = seq_num;
5009 dcmd->mbox.w[1] = cpu_to_le32(curr_aen.word);
5010 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(instance->evt_detail_h);
5011 dcmd->sgl.sge32[0].length = cpu_to_le32(sizeof(struct megasas_evt_detail));
5013 if (instance->aen_cmd != NULL) {
5014 megasas_return_cmd(instance, cmd);
5019 * Store reference to the cmd used to register for AEN. When an
5020 * application wants us to register for AEN, we have to abort this
5021 * cmd and re-register with a new EVENT LOCALE supplied by that app
5023 instance->aen_cmd = cmd;
5026 * Issue the aen registration frame
5028 instance->instancet->issue_dcmd(instance, cmd);
5034 * megasas_start_aen - Subscribes to AEN during driver load time
5035 * @instance: Adapter soft state
5037 static int megasas_start_aen(struct megasas_instance *instance)
5039 struct megasas_evt_log_info eli;
5040 union megasas_evt_class_locale class_locale;
5043 * Get the latest sequence number from FW
5045 memset(&eli, 0, sizeof(eli));
5047 if (megasas_get_seq_num(instance, &eli))
5051 * Register AEN with FW for latest sequence number plus 1
5053 class_locale.members.reserved = 0;
5054 class_locale.members.locale = MR_EVT_LOCALE_ALL;
5055 class_locale.members.class = MR_EVT_CLASS_DEBUG;
5057 return megasas_register_aen(instance,
5058 le32_to_cpu(eli.newest_seq_num) + 1,
5063 * megasas_io_attach - Attaches this driver to SCSI mid-layer
5064 * @instance: Adapter soft state
5066 static int megasas_io_attach(struct megasas_instance *instance)
5068 struct Scsi_Host *host = instance->host;
5072 * Export parameters required by SCSI mid-layer
5074 host->irq = instance->pdev->irq;
5075 host->unique_id = instance->unique_id;
5076 host->can_queue = instance->max_scsi_cmds;
5077 host->this_id = instance->init_id;
5078 host->sg_tablesize = instance->max_num_sge;
5080 if (instance->fw_support_ieee)
5081 instance->max_sectors_per_req = MEGASAS_MAX_SECTORS_IEEE;
5084 * Check if the module parameter value for max_sectors can be used
5086 if (max_sectors && max_sectors < instance->max_sectors_per_req)
5087 instance->max_sectors_per_req = max_sectors;
5090 if (((instance->pdev->device ==
5091 PCI_DEVICE_ID_LSI_SAS1078GEN2) ||
5092 (instance->pdev->device ==
5093 PCI_DEVICE_ID_LSI_SAS0079GEN2)) &&
5094 (max_sectors <= MEGASAS_MAX_SECTORS)) {
5095 instance->max_sectors_per_req = max_sectors;
5097 printk(KERN_INFO "megasas: max_sectors should be > 0"
5098 "and <= %d (or < 1MB for GEN2 controller)\n",
5099 instance->max_sectors_per_req);
5104 host->max_sectors = instance->max_sectors_per_req;
5105 host->cmd_per_lun = MEGASAS_DEFAULT_CMD_PER_LUN;
5106 host->max_channel = MEGASAS_MAX_CHANNELS - 1;
5107 host->max_id = MEGASAS_MAX_DEV_PER_CHANNEL;
5108 host->max_lun = MEGASAS_MAX_LUN;
5109 host->max_cmd_len = 16;
5111 /* Fusion only supports host reset */
5112 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
5113 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) ||
5114 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
5115 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
5116 host->hostt->eh_device_reset_handler = NULL;
5117 host->hostt->eh_bus_reset_handler = NULL;
5119 error = scsi_init_shared_tag_map(host, host->can_queue);
5121 dev_err(&instance->pdev->dev,
5122 "Failed to shared tag from %s %d\n",
5123 __func__, __LINE__);
5128 * Notify the mid-layer about the new controller
5130 if (scsi_add_host(host, &instance->pdev->dev)) {
5131 dev_err(&instance->pdev->dev,
5132 "Failed to add host from %s %d\n",
5133 __func__, __LINE__);
5141 megasas_set_dma_mask(struct pci_dev *pdev)
5144 * All our contollers are capable of performing 64-bit DMA
5147 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
5149 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
5150 goto fail_set_dma_mask;
5153 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
5154 goto fail_set_dma_mask;
5157 * Ensure that all data structures are allocated in 32-bit
5160 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
5161 /* Try 32bit DMA mask and 32 bit Consistent dma mask */
5162 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
5163 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
5164 dev_info(&pdev->dev, "set 32bit DMA mask"
5165 "and 32 bit consistent mask\n");
5167 goto fail_set_dma_mask;
5177 * megasas_probe_one - PCI hotplug entry point
5178 * @pdev: PCI device structure
5179 * @id: PCI ids of supported hotplugged adapter
5181 static int megasas_probe_one(struct pci_dev *pdev,
5182 const struct pci_device_id *id)
5185 struct Scsi_Host *host;
5186 struct megasas_instance *instance;
5188 struct fusion_context *fusion = NULL;
5190 /* Reset MSI-X in the kdump kernel */
5191 if (reset_devices) {
5192 pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
5194 pci_read_config_word(pdev, pos + PCI_MSIX_FLAGS,
5196 if (control & PCI_MSIX_FLAGS_ENABLE) {
5197 dev_info(&pdev->dev, "resetting MSI-X\n");
5198 pci_write_config_word(pdev,
5199 pos + PCI_MSIX_FLAGS,
5201 ~PCI_MSIX_FLAGS_ENABLE);
5207 * PCI prepping: enable device set bus mastering and dma mask
5209 rval = pci_enable_device_mem(pdev);
5215 pci_set_master(pdev);
5217 if (megasas_set_dma_mask(pdev))
5218 goto fail_set_dma_mask;
5220 host = scsi_host_alloc(&megasas_template,
5221 sizeof(struct megasas_instance));
5224 printk(KERN_DEBUG "megasas: scsi_host_alloc failed\n");
5225 goto fail_alloc_instance;
5228 instance = (struct megasas_instance *)host->hostdata;
5229 memset(instance, 0, sizeof(*instance));
5230 atomic_set( &instance->fw_reset_no_pci_access, 0 );
5231 instance->pdev = pdev;
5233 switch (instance->pdev->device) {
5234 case PCI_DEVICE_ID_LSI_FUSION:
5235 case PCI_DEVICE_ID_LSI_PLASMA:
5236 case PCI_DEVICE_ID_LSI_INVADER:
5237 case PCI_DEVICE_ID_LSI_FURY:
5239 instance->ctrl_context_pages =
5240 get_order(sizeof(struct fusion_context));
5241 instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL,
5242 instance->ctrl_context_pages);
5243 if (!instance->ctrl_context) {
5244 printk(KERN_DEBUG "megasas: Failed to allocate "
5245 "memory for Fusion context info\n");
5246 goto fail_alloc_dma_buf;
5248 fusion = instance->ctrl_context;
5250 ((1 << PAGE_SHIFT) << instance->ctrl_context_pages));
5253 default: /* For all other supported controllers */
5255 instance->producer =
5256 pci_alloc_consistent(pdev, sizeof(u32),
5257 &instance->producer_h);
5258 instance->consumer =
5259 pci_alloc_consistent(pdev, sizeof(u32),
5260 &instance->consumer_h);
5262 if (!instance->producer || !instance->consumer) {
5263 printk(KERN_DEBUG "megasas: Failed to allocate"
5264 "memory for producer, consumer\n");
5265 goto fail_alloc_dma_buf;
5268 *instance->producer = 0;
5269 *instance->consumer = 0;
5273 instance->system_info_buf = pci_zalloc_consistent(pdev,
5274 sizeof(struct MR_DRV_SYSTEM_INFO),
5275 &instance->system_info_h);
5277 if (!instance->system_info_buf)
5278 dev_info(&instance->pdev->dev, "Can't allocate system info buffer\n");
5280 /* Crash dump feature related initialisation*/
5281 instance->drv_buf_index = 0;
5282 instance->drv_buf_alloc = 0;
5283 instance->crash_dump_fw_support = 0;
5284 instance->crash_dump_app_support = 0;
5285 instance->fw_crash_state = UNAVAILABLE;
5286 spin_lock_init(&instance->crashdump_lock);
5287 instance->crash_dump_buf = NULL;
5290 instance->crash_dump_buf = pci_alloc_consistent(pdev,
5292 &instance->crash_dump_h);
5293 if (!instance->crash_dump_buf)
5294 dev_err(&instance->pdev->dev, "Can't allocate Firmware "
5295 "crash dump DMA buffer\n");
5297 megasas_poll_wait_aen = 0;
5298 instance->flag_ieee = 0;
5299 instance->ev = NULL;
5300 instance->issuepend_done = 1;
5301 instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
5302 instance->is_imr = 0;
5304 instance->evt_detail = pci_alloc_consistent(pdev,
5306 megasas_evt_detail),
5307 &instance->evt_detail_h);
5309 if (!instance->evt_detail) {
5310 printk(KERN_DEBUG "megasas: Failed to allocate memory for "
5311 "event detail structure\n");
5312 goto fail_alloc_dma_buf;
5316 * Initialize locks and queues
5318 INIT_LIST_HEAD(&instance->cmd_pool);
5319 INIT_LIST_HEAD(&instance->internal_reset_pending_q);
5321 atomic_set(&instance->fw_outstanding,0);
5323 init_waitqueue_head(&instance->int_cmd_wait_q);
5324 init_waitqueue_head(&instance->abort_cmd_wait_q);
5326 spin_lock_init(&instance->mfi_pool_lock);
5327 spin_lock_init(&instance->hba_lock);
5328 spin_lock_init(&instance->completion_lock);
5330 mutex_init(&instance->aen_mutex);
5331 mutex_init(&instance->reset_mutex);
5334 * Initialize PCI related and misc parameters
5336 instance->host = host;
5337 instance->unique_id = pdev->bus->number << 8 | pdev->devfn;
5338 instance->init_id = MEGASAS_DEFAULT_INIT_ID;
5339 instance->ctrl_info = NULL;
5342 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0073SKINNY) ||
5343 (instance->pdev->device == PCI_DEVICE_ID_LSI_SAS0071SKINNY))
5344 instance->flag_ieee = 1;
5346 megasas_dbg_lvl = 0;
5348 instance->unload = 1;
5349 instance->last_time = 0;
5350 instance->disableOnlineCtrlReset = 1;
5351 instance->UnevenSpanSupport = 0;
5353 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
5354 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) ||
5355 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
5356 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
5357 INIT_WORK(&instance->work_init, megasas_fusion_ocr_wq);
5358 INIT_WORK(&instance->crash_init, megasas_fusion_crash_dump_wq);
5360 INIT_WORK(&instance->work_init, process_fw_state_change_wq);
5363 * Initialize MFI Firmware
5365 if (megasas_init_fw(instance))
5368 if (instance->requestorId) {
5369 if (instance->PlasmaFW111) {
5370 instance->vf_affiliation_111 =
5371 pci_alloc_consistent(pdev, sizeof(struct MR_LD_VF_AFFILIATION_111),
5372 &instance->vf_affiliation_111_h);
5373 if (!instance->vf_affiliation_111)
5374 printk(KERN_WARNING "megasas: Can't allocate "
5375 "memory for VF affiliation buffer\n");
5377 instance->vf_affiliation =
5378 pci_alloc_consistent(pdev,
5379 (MAX_LOGICAL_DRIVES + 1) *
5380 sizeof(struct MR_LD_VF_AFFILIATION),
5381 &instance->vf_affiliation_h);
5382 if (!instance->vf_affiliation)
5383 printk(KERN_WARNING "megasas: Can't allocate "
5384 "memory for VF affiliation buffer\n");
5389 * Store instance in PCI softstate
5391 pci_set_drvdata(pdev, instance);
5394 * Add this controller to megasas_mgmt_info structure so that it
5395 * can be exported to management applications
5397 megasas_mgmt_info.count++;
5398 megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = instance;
5399 megasas_mgmt_info.max_index++;
5402 * Register with SCSI mid-layer
5404 if (megasas_io_attach(instance))
5405 goto fail_io_attach;
5407 instance->unload = 0;
5409 * Trigger SCSI to scan our drives
5411 scsi_scan_host(host);
5414 * Initiate AEN (Asynchronous Event Notification)
5416 if (megasas_start_aen(instance)) {
5417 printk(KERN_DEBUG "megasas: start aen failed\n");
5418 goto fail_start_aen;
5421 /* Get current SR-IOV LD/VF affiliation */
5422 if (instance->requestorId)
5423 megasas_get_ld_vf_affiliation(instance, 1);
5429 megasas_mgmt_info.count--;
5430 megasas_mgmt_info.instance[megasas_mgmt_info.max_index] = NULL;
5431 megasas_mgmt_info.max_index--;
5433 instance->instancet->disable_intr(instance);
5434 megasas_destroy_irqs(instance);
5436 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_FUSION) ||
5437 (instance->pdev->device == PCI_DEVICE_ID_LSI_PLASMA) ||
5438 (instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
5439 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY))
5440 megasas_release_fusion(instance);
5442 megasas_release_mfi(instance);
5443 if (instance->msix_vectors)
5444 pci_disable_msix(instance->pdev);
5447 if (instance->evt_detail)
5448 pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
5449 instance->evt_detail,
5450 instance->evt_detail_h);
5452 if (instance->producer)
5453 pci_free_consistent(pdev, sizeof(u32), instance->producer,
5454 instance->producer_h);
5455 if (instance->consumer)
5456 pci_free_consistent(pdev, sizeof(u32), instance->consumer,
5457 instance->consumer_h);
5458 scsi_host_put(host);
5460 fail_alloc_instance:
5462 pci_disable_device(pdev);
5468 * megasas_flush_cache - Requests FW to flush all its caches
5469 * @instance: Adapter soft state
5471 static void megasas_flush_cache(struct megasas_instance *instance)
5473 struct megasas_cmd *cmd;
5474 struct megasas_dcmd_frame *dcmd;
5476 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR)
5479 cmd = megasas_get_cmd(instance);
5484 dcmd = &cmd->frame->dcmd;
5486 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
5488 dcmd->cmd = MFI_CMD_DCMD;
5489 dcmd->cmd_status = 0x0;
5490 dcmd->sge_count = 0;
5491 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE);
5494 dcmd->data_xfer_len = 0;
5495 dcmd->opcode = cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH);
5496 dcmd->mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE;
5498 if (megasas_issue_blocked_cmd(instance, cmd, 30))
5499 dev_err(&instance->pdev->dev, "Command timedout"
5500 " from %s\n", __func__);
5502 megasas_return_cmd(instance, cmd);
5508 * megasas_shutdown_controller - Instructs FW to shutdown the controller
5509 * @instance: Adapter soft state
5510 * @opcode: Shutdown/Hibernate
5512 static void megasas_shutdown_controller(struct megasas_instance *instance,
5515 struct megasas_cmd *cmd;
5516 struct megasas_dcmd_frame *dcmd;
5518 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR)
5521 cmd = megasas_get_cmd(instance);
5526 if (instance->aen_cmd)
5527 megasas_issue_blocked_abort_cmd(instance,
5528 instance->aen_cmd, 30);
5529 if (instance->map_update_cmd)
5530 megasas_issue_blocked_abort_cmd(instance,
5531 instance->map_update_cmd, 30);
5532 dcmd = &cmd->frame->dcmd;
5534 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
5536 dcmd->cmd = MFI_CMD_DCMD;
5537 dcmd->cmd_status = 0x0;
5538 dcmd->sge_count = 0;
5539 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_NONE);
5542 dcmd->data_xfer_len = 0;
5543 dcmd->opcode = cpu_to_le32(opcode);
5545 if (megasas_issue_blocked_cmd(instance, cmd, 30))
5546 dev_err(&instance->pdev->dev, "Command timedout"
5547 "from %s\n", __func__);
5549 megasas_return_cmd(instance, cmd);
5556 * megasas_suspend - driver suspend entry point
5557 * @pdev: PCI device structure
5558 * @state: PCI power state to suspend routine
5561 megasas_suspend(struct pci_dev *pdev, pm_message_t state)
5563 struct Scsi_Host *host;
5564 struct megasas_instance *instance;
5566 instance = pci_get_drvdata(pdev);
5567 host = instance->host;
5568 instance->unload = 1;
5570 /* Shutdown SR-IOV heartbeat timer */
5571 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
5572 del_timer_sync(&instance->sriov_heartbeat_timer);
5574 megasas_flush_cache(instance);
5575 megasas_shutdown_controller(instance, MR_DCMD_HIBERNATE_SHUTDOWN);
5577 /* cancel the delayed work if this work still in queue */
5578 if (instance->ev != NULL) {
5579 struct megasas_aen_event *ev = instance->ev;
5580 cancel_delayed_work_sync(&ev->hotplug_work);
5581 instance->ev = NULL;
5584 tasklet_kill(&instance->isr_tasklet);
5586 pci_set_drvdata(instance->pdev, instance);
5587 instance->instancet->disable_intr(instance);
5589 megasas_destroy_irqs(instance);
5591 if (instance->msix_vectors)
5592 pci_disable_msix(instance->pdev);
5594 pci_save_state(pdev);
5595 pci_disable_device(pdev);
5597 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5603 * megasas_resume- driver resume entry point
5604 * @pdev: PCI device structure
5607 megasas_resume(struct pci_dev *pdev)
5610 struct Scsi_Host *host;
5611 struct megasas_instance *instance;
5613 instance = pci_get_drvdata(pdev);
5614 host = instance->host;
5615 pci_set_power_state(pdev, PCI_D0);
5616 pci_enable_wake(pdev, PCI_D0, 0);
5617 pci_restore_state(pdev);
5620 * PCI prepping: enable device set bus mastering and dma mask
5622 rval = pci_enable_device_mem(pdev);
5625 printk(KERN_ERR "megasas: Enable device failed\n");
5629 pci_set_master(pdev);
5631 if (megasas_set_dma_mask(pdev))
5632 goto fail_set_dma_mask;
5635 * Initialize MFI Firmware
5638 atomic_set(&instance->fw_outstanding, 0);
5641 * We expect the FW state to be READY
5643 if (megasas_transition_to_ready(instance, 0))
5644 goto fail_ready_state;
5646 /* Now re-enable MSI-X */
5647 if (instance->msix_vectors &&
5648 pci_enable_msix_exact(instance->pdev, instance->msixentry,
5649 instance->msix_vectors))
5650 goto fail_reenable_msix;
5652 switch (instance->pdev->device) {
5653 case PCI_DEVICE_ID_LSI_FUSION:
5654 case PCI_DEVICE_ID_LSI_PLASMA:
5655 case PCI_DEVICE_ID_LSI_INVADER:
5656 case PCI_DEVICE_ID_LSI_FURY:
5658 megasas_reset_reply_desc(instance);
5659 if (megasas_ioc_init_fusion(instance)) {
5660 megasas_free_cmds(instance);
5661 megasas_free_cmds_fusion(instance);
5664 if (!megasas_get_map_info(instance))
5665 megasas_sync_map_info(instance);
5669 *instance->producer = 0;
5670 *instance->consumer = 0;
5671 if (megasas_issue_init_mfi(instance))
5676 tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
5677 (unsigned long)instance);
5679 if (instance->msix_vectors ?
5680 megasas_setup_irqs_msix(instance, 0) :
5681 megasas_setup_irqs_ioapic(instance))
5684 /* Re-launch SR-IOV heartbeat timer */
5685 if (instance->requestorId) {
5686 if (!megasas_sriov_start_heartbeat(instance, 0))
5687 megasas_start_timer(instance,
5688 &instance->sriov_heartbeat_timer,
5689 megasas_sriov_heartbeat_handler,
5690 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
5692 instance->skip_heartbeat_timer_del = 1;
5697 instance->instancet->enable_intr(instance);
5698 instance->unload = 0;
5701 * Initiate AEN (Asynchronous Event Notification)
5703 if (megasas_start_aen(instance))
5704 printk(KERN_ERR "megasas: Start AEN failed\n");
5709 if (instance->evt_detail)
5710 pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
5711 instance->evt_detail,
5712 instance->evt_detail_h);
5714 if (instance->producer)
5715 pci_free_consistent(pdev, sizeof(u32), instance->producer,
5716 instance->producer_h);
5717 if (instance->consumer)
5718 pci_free_consistent(pdev, sizeof(u32), instance->consumer,
5719 instance->consumer_h);
5720 scsi_host_put(host);
5726 pci_disable_device(pdev);
5731 #define megasas_suspend NULL
5732 #define megasas_resume NULL
5736 * megasas_detach_one - PCI hot"un"plug entry point
5737 * @pdev: PCI device structure
5739 static void megasas_detach_one(struct pci_dev *pdev)
5742 struct Scsi_Host *host;
5743 struct megasas_instance *instance;
5744 struct fusion_context *fusion;
5746 instance = pci_get_drvdata(pdev);
5747 instance->unload = 1;
5748 host = instance->host;
5749 fusion = instance->ctrl_context;
5751 /* Shutdown SR-IOV heartbeat timer */
5752 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
5753 del_timer_sync(&instance->sriov_heartbeat_timer);
5755 if (instance->fw_crash_state != UNAVAILABLE)
5756 megasas_free_host_crash_buffer(instance);
5757 scsi_remove_host(instance->host);
5758 megasas_flush_cache(instance);
5759 megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN);
5761 /* cancel the delayed work if this work still in queue*/
5762 if (instance->ev != NULL) {
5763 struct megasas_aen_event *ev = instance->ev;
5764 cancel_delayed_work_sync(&ev->hotplug_work);
5765 instance->ev = NULL;
5768 /* cancel all wait events */
5769 wake_up_all(&instance->int_cmd_wait_q);
5771 tasklet_kill(&instance->isr_tasklet);
5774 * Take the instance off the instance array. Note that we will not
5775 * decrement the max_index. We let this array be sparse array
5777 for (i = 0; i < megasas_mgmt_info.max_index; i++) {
5778 if (megasas_mgmt_info.instance[i] == instance) {
5779 megasas_mgmt_info.count--;
5780 megasas_mgmt_info.instance[i] = NULL;
5786 instance->instancet->disable_intr(instance);
5788 megasas_destroy_irqs(instance);
5790 if (instance->msix_vectors)
5791 pci_disable_msix(instance->pdev);
5793 switch (instance->pdev->device) {
5794 case PCI_DEVICE_ID_LSI_FUSION:
5795 case PCI_DEVICE_ID_LSI_PLASMA:
5796 case PCI_DEVICE_ID_LSI_INVADER:
5797 case PCI_DEVICE_ID_LSI_FURY:
5798 megasas_release_fusion(instance);
5799 for (i = 0; i < 2 ; i++) {
5800 if (fusion->ld_map[i])
5801 dma_free_coherent(&instance->pdev->dev,
5804 fusion->ld_map_phys[i]);
5805 if (fusion->ld_drv_map[i])
5806 free_pages((ulong)fusion->ld_drv_map[i],
5807 fusion->drv_map_pages);
5809 free_pages((ulong)instance->ctrl_context,
5810 instance->ctrl_context_pages);
5813 megasas_release_mfi(instance);
5814 pci_free_consistent(pdev, sizeof(u32),
5816 instance->producer_h);
5817 pci_free_consistent(pdev, sizeof(u32),
5819 instance->consumer_h);
5823 kfree(instance->ctrl_info);
5825 if (instance->evt_detail)
5826 pci_free_consistent(pdev, sizeof(struct megasas_evt_detail),
5827 instance->evt_detail, instance->evt_detail_h);
5829 if (instance->vf_affiliation)
5830 pci_free_consistent(pdev, (MAX_LOGICAL_DRIVES + 1) *
5831 sizeof(struct MR_LD_VF_AFFILIATION),
5832 instance->vf_affiliation,
5833 instance->vf_affiliation_h);
5835 if (instance->vf_affiliation_111)
5836 pci_free_consistent(pdev,
5837 sizeof(struct MR_LD_VF_AFFILIATION_111),
5838 instance->vf_affiliation_111,
5839 instance->vf_affiliation_111_h);
5841 if (instance->hb_host_mem)
5842 pci_free_consistent(pdev, sizeof(struct MR_CTRL_HB_HOST_MEM),
5843 instance->hb_host_mem,
5844 instance->hb_host_mem_h);
5846 if (instance->crash_dump_buf)
5847 pci_free_consistent(pdev, CRASH_DMA_BUF_SIZE,
5848 instance->crash_dump_buf, instance->crash_dump_h);
5850 if (instance->system_info_buf)
5851 pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO),
5852 instance->system_info_buf, instance->system_info_h);
5854 scsi_host_put(host);
5856 pci_disable_device(pdev);
5862 * megasas_shutdown - Shutdown entry point
5863 * @device: Generic device structure
5865 static void megasas_shutdown(struct pci_dev *pdev)
5867 struct megasas_instance *instance = pci_get_drvdata(pdev);
5869 instance->unload = 1;
5870 megasas_flush_cache(instance);
5871 megasas_shutdown_controller(instance, MR_DCMD_CTRL_SHUTDOWN);
5872 instance->instancet->disable_intr(instance);
5873 megasas_destroy_irqs(instance);
5875 if (instance->msix_vectors)
5876 pci_disable_msix(instance->pdev);
5880 * megasas_mgmt_open - char node "open" entry point
5882 static int megasas_mgmt_open(struct inode *inode, struct file *filep)
5885 * Allow only those users with admin rights
5887 if (!capable(CAP_SYS_ADMIN))
5894 * megasas_mgmt_fasync - Async notifier registration from applications
5896 * This function adds the calling process to a driver global queue. When an
5897 * event occurs, SIGIO will be sent to all processes in this queue.
5899 static int megasas_mgmt_fasync(int fd, struct file *filep, int mode)
5903 mutex_lock(&megasas_async_queue_mutex);
5905 rc = fasync_helper(fd, filep, mode, &megasas_async_queue);
5907 mutex_unlock(&megasas_async_queue_mutex);
5910 /* For sanity check when we get ioctl */
5911 filep->private_data = filep;
5915 printk(KERN_DEBUG "megasas: fasync_helper failed [%d]\n", rc);
5921 * megasas_mgmt_poll - char node "poll" entry point
5923 static unsigned int megasas_mgmt_poll(struct file *file, poll_table *wait)
5926 unsigned long flags;
5927 poll_wait(file, &megasas_poll_wait, wait);
5928 spin_lock_irqsave(&poll_aen_lock, flags);
5929 if (megasas_poll_wait_aen)
5930 mask = (POLLIN | POLLRDNORM);
5934 megasas_poll_wait_aen = 0;
5935 spin_unlock_irqrestore(&poll_aen_lock, flags);
5940 * megasas_set_crash_dump_params_ioctl:
5941 * Send CRASH_DUMP_MODE DCMD to all controllers
5942 * @cmd: MFI command frame
5945 static int megasas_set_crash_dump_params_ioctl(
5946 struct megasas_cmd *cmd)
5948 struct megasas_instance *local_instance;
5952 crash_support = cmd->frame->dcmd.mbox.w[0];
5954 for (i = 0; i < megasas_mgmt_info.max_index; i++) {
5955 local_instance = megasas_mgmt_info.instance[i];
5956 if (local_instance && local_instance->crash_dump_drv_support) {
5957 if ((local_instance->adprecovery ==
5958 MEGASAS_HBA_OPERATIONAL) &&
5959 !megasas_set_crash_dump_params(local_instance,
5961 local_instance->crash_dump_app_support =
5963 dev_info(&local_instance->pdev->dev,
5964 "Application firmware crash "
5965 "dump mode set success\n");
5968 dev_info(&local_instance->pdev->dev,
5969 "Application firmware crash "
5970 "dump mode set failed\n");
5979 * megasas_mgmt_fw_ioctl - Issues management ioctls to FW
5980 * @instance: Adapter soft state
5981 * @argp: User's ioctl packet
5984 megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
5985 struct megasas_iocpacket __user * user_ioc,
5986 struct megasas_iocpacket *ioc)
5988 struct megasas_sge32 *kern_sge32;
5989 struct megasas_cmd *cmd;
5990 void *kbuff_arr[MAX_IOCTL_SGE];
5991 dma_addr_t buf_handle = 0;
5994 dma_addr_t sense_handle;
5995 unsigned long *sense_ptr;
5997 memset(kbuff_arr, 0, sizeof(kbuff_arr));
5999 if (ioc->sge_count > MAX_IOCTL_SGE) {
6000 printk(KERN_DEBUG "megasas: SGE count [%d] > max limit [%d]\n",
6001 ioc->sge_count, MAX_IOCTL_SGE);
6005 cmd = megasas_get_cmd(instance);
6007 printk(KERN_DEBUG "megasas: Failed to get a cmd packet\n");
6012 * User's IOCTL packet has 2 frames (maximum). Copy those two
6013 * frames into our cmd's frames. cmd->frame's context will get
6014 * overwritten when we copy from user's frames. So set that value
6017 memcpy(cmd->frame, ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE);
6018 cmd->frame->hdr.context = cpu_to_le32(cmd->index);
6019 cmd->frame->hdr.pad_0 = 0;
6020 cmd->frame->hdr.flags &= cpu_to_le16(~(MFI_FRAME_IEEE |
6022 MFI_FRAME_SENSE64));
6024 if (cmd->frame->dcmd.opcode == MR_DRIVER_SET_APP_CRASHDUMP_MODE) {
6025 error = megasas_set_crash_dump_params_ioctl(cmd);
6026 megasas_return_cmd(instance, cmd);
6031 * The management interface between applications and the fw uses
6032 * MFI frames. E.g, RAID configuration changes, LD property changes
6033 * etc are accomplishes through different kinds of MFI frames. The
6034 * driver needs to care only about substituting user buffers with
6035 * kernel buffers in SGLs. The location of SGL is embedded in the
6036 * struct iocpacket itself.
6038 kern_sge32 = (struct megasas_sge32 *)
6039 ((unsigned long)cmd->frame + ioc->sgl_off);
6042 * For each user buffer, create a mirror buffer and copy in
6044 for (i = 0; i < ioc->sge_count; i++) {
6045 if (!ioc->sgl[i].iov_len)
6048 kbuff_arr[i] = dma_alloc_coherent(&instance->pdev->dev,
6049 ioc->sgl[i].iov_len,
6050 &buf_handle, GFP_KERNEL);
6051 if (!kbuff_arr[i]) {
6052 printk(KERN_DEBUG "megasas: Failed to alloc "
6053 "kernel SGL buffer for IOCTL \n");
6059 * We don't change the dma_coherent_mask, so
6060 * pci_alloc_consistent only returns 32bit addresses
6062 kern_sge32[i].phys_addr = cpu_to_le32(buf_handle);
6063 kern_sge32[i].length = cpu_to_le32(ioc->sgl[i].iov_len);
6066 * We created a kernel buffer corresponding to the
6067 * user buffer. Now copy in from the user buffer
6069 if (copy_from_user(kbuff_arr[i], ioc->sgl[i].iov_base,
6070 (u32) (ioc->sgl[i].iov_len))) {
6076 if (ioc->sense_len) {
6077 sense = dma_alloc_coherent(&instance->pdev->dev, ioc->sense_len,
6078 &sense_handle, GFP_KERNEL);
6085 (unsigned long *) ((unsigned long)cmd->frame + ioc->sense_off);
6086 *sense_ptr = cpu_to_le32(sense_handle);
6090 * Set the sync_cmd flag so that the ISR knows not to complete this
6091 * cmd to the SCSI mid-layer
6094 megasas_issue_blocked_cmd(instance, cmd, 0);
6097 if (instance->unload == 1) {
6098 dev_info(&instance->pdev->dev, "Driver unload is in progress "
6099 "don't submit data to application\n");
6103 * copy out the kernel buffers to user buffers
6105 for (i = 0; i < ioc->sge_count; i++) {
6106 if (copy_to_user(ioc->sgl[i].iov_base, kbuff_arr[i],
6107 ioc->sgl[i].iov_len)) {
6114 * copy out the sense
6116 if (ioc->sense_len) {
6118 * sense_ptr points to the location that has the user
6119 * sense buffer address
6121 sense_ptr = (unsigned long *) ((unsigned long)ioc->frame.raw +
6124 if (copy_to_user((void __user *)((unsigned long)(*sense_ptr)),
6125 sense, ioc->sense_len)) {
6126 printk(KERN_ERR "megasas: Failed to copy out to user "
6134 * copy the status codes returned by the fw
6136 if (copy_to_user(&user_ioc->frame.hdr.cmd_status,
6137 &cmd->frame->hdr.cmd_status, sizeof(u8))) {
6138 printk(KERN_DEBUG "megasas: Error copying out cmd_status\n");
6144 dma_free_coherent(&instance->pdev->dev, ioc->sense_len,
6145 sense, sense_handle);
6148 for (i = 0; i < ioc->sge_count; i++) {
6150 dma_free_coherent(&instance->pdev->dev,
6151 le32_to_cpu(kern_sge32[i].length),
6153 le32_to_cpu(kern_sge32[i].phys_addr));
6154 kbuff_arr[i] = NULL;
6157 megasas_return_cmd(instance, cmd);
6161 static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg)
6163 struct megasas_iocpacket __user *user_ioc =
6164 (struct megasas_iocpacket __user *)arg;
6165 struct megasas_iocpacket *ioc;
6166 struct megasas_instance *instance;
6169 unsigned long flags;
6170 u32 wait_time = MEGASAS_RESET_WAIT_TIME;
6172 ioc = kmalloc(sizeof(*ioc), GFP_KERNEL);
6176 if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) {
6181 instance = megasas_lookup_instance(ioc->host_no);
6187 /* Adjust ioctl wait time for VF mode */
6188 if (instance->requestorId)
6189 wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF;
6191 /* Block ioctls in VF mode */
6192 if (instance->requestorId && !allow_vf_ioctls) {
6197 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
6198 printk(KERN_ERR "Controller in crit error\n");
6203 if (instance->unload == 1) {
6208 if (down_interruptible(&instance->ioctl_sem)) {
6209 error = -ERESTARTSYS;
6213 for (i = 0; i < wait_time; i++) {
6215 spin_lock_irqsave(&instance->hba_lock, flags);
6216 if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) {
6217 spin_unlock_irqrestore(&instance->hba_lock, flags);
6220 spin_unlock_irqrestore(&instance->hba_lock, flags);
6222 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
6223 printk(KERN_NOTICE "megasas: waiting"
6224 "for controller reset to finish\n");
6230 spin_lock_irqsave(&instance->hba_lock, flags);
6231 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) {
6232 spin_unlock_irqrestore(&instance->hba_lock, flags);
6234 printk(KERN_ERR "megaraid_sas: timed out while"
6235 "waiting for HBA to recover\n");
6239 spin_unlock_irqrestore(&instance->hba_lock, flags);
6241 error = megasas_mgmt_fw_ioctl(instance, user_ioc, ioc);
6243 up(&instance->ioctl_sem);
6250 static int megasas_mgmt_ioctl_aen(struct file *file, unsigned long arg)
6252 struct megasas_instance *instance;
6253 struct megasas_aen aen;
6256 unsigned long flags;
6257 u32 wait_time = MEGASAS_RESET_WAIT_TIME;
6259 if (file->private_data != file) {
6260 printk(KERN_DEBUG "megasas: fasync_helper was not "
6265 if (copy_from_user(&aen, (void __user *)arg, sizeof(aen)))
6268 instance = megasas_lookup_instance(aen.host_no);
6273 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
6277 if (instance->unload == 1) {
6281 for (i = 0; i < wait_time; i++) {
6283 spin_lock_irqsave(&instance->hba_lock, flags);
6284 if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL) {
6285 spin_unlock_irqrestore(&instance->hba_lock,
6290 spin_unlock_irqrestore(&instance->hba_lock, flags);
6292 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
6293 printk(KERN_NOTICE "megasas: waiting for"
6294 "controller reset to finish\n");
6300 spin_lock_irqsave(&instance->hba_lock, flags);
6301 if (instance->adprecovery != MEGASAS_HBA_OPERATIONAL) {
6302 spin_unlock_irqrestore(&instance->hba_lock, flags);
6303 printk(KERN_ERR "megaraid_sas: timed out while waiting"
6304 "for HBA to recover.\n");
6307 spin_unlock_irqrestore(&instance->hba_lock, flags);
6309 mutex_lock(&instance->aen_mutex);
6310 error = megasas_register_aen(instance, aen.seq_num,
6311 aen.class_locale_word);
6312 mutex_unlock(&instance->aen_mutex);
6317 * megasas_mgmt_ioctl - char node ioctl entry point
6320 megasas_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
6323 case MEGASAS_IOC_FIRMWARE:
6324 return megasas_mgmt_ioctl_fw(file, arg);
6326 case MEGASAS_IOC_GET_AEN:
6327 return megasas_mgmt_ioctl_aen(file, arg);
6333 #ifdef CONFIG_COMPAT
6334 static int megasas_mgmt_compat_ioctl_fw(struct file *file, unsigned long arg)
6336 struct compat_megasas_iocpacket __user *cioc =
6337 (struct compat_megasas_iocpacket __user *)arg;
6338 struct megasas_iocpacket __user *ioc =
6339 compat_alloc_user_space(sizeof(struct megasas_iocpacket));
6344 if (clear_user(ioc, sizeof(*ioc)))
6347 if (copy_in_user(&ioc->host_no, &cioc->host_no, sizeof(u16)) ||
6348 copy_in_user(&ioc->sgl_off, &cioc->sgl_off, sizeof(u32)) ||
6349 copy_in_user(&ioc->sense_off, &cioc->sense_off, sizeof(u32)) ||
6350 copy_in_user(&ioc->sense_len, &cioc->sense_len, sizeof(u32)) ||
6351 copy_in_user(ioc->frame.raw, cioc->frame.raw, 128) ||
6352 copy_in_user(&ioc->sge_count, &cioc->sge_count, sizeof(u32)))
6356 * The sense_ptr is used in megasas_mgmt_fw_ioctl only when
6357 * sense_len is not null, so prepare the 64bit value under
6358 * the same condition.
6360 if (ioc->sense_len) {
6361 void __user **sense_ioc_ptr =
6362 (void __user **)(ioc->frame.raw + ioc->sense_off);
6363 compat_uptr_t *sense_cioc_ptr =
6364 (compat_uptr_t *)(cioc->frame.raw + cioc->sense_off);
6365 if (get_user(ptr, sense_cioc_ptr) ||
6366 put_user(compat_ptr(ptr), sense_ioc_ptr))
6370 for (i = 0; i < MAX_IOCTL_SGE; i++) {
6371 if (get_user(ptr, &cioc->sgl[i].iov_base) ||
6372 put_user(compat_ptr(ptr), &ioc->sgl[i].iov_base) ||
6373 copy_in_user(&ioc->sgl[i].iov_len,
6374 &cioc->sgl[i].iov_len, sizeof(compat_size_t)))
6378 error = megasas_mgmt_ioctl_fw(file, (unsigned long)ioc);
6380 if (copy_in_user(&cioc->frame.hdr.cmd_status,
6381 &ioc->frame.hdr.cmd_status, sizeof(u8))) {
6382 printk(KERN_DEBUG "megasas: error copy_in_user cmd_status\n");
6389 megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd,
6393 case MEGASAS_IOC_FIRMWARE32:
6394 return megasas_mgmt_compat_ioctl_fw(file, arg);
6395 case MEGASAS_IOC_GET_AEN:
6396 return megasas_mgmt_ioctl_aen(file, arg);
6404 * File operations structure for management interface
6406 static const struct file_operations megasas_mgmt_fops = {
6407 .owner = THIS_MODULE,
6408 .open = megasas_mgmt_open,
6409 .fasync = megasas_mgmt_fasync,
6410 .unlocked_ioctl = megasas_mgmt_ioctl,
6411 .poll = megasas_mgmt_poll,
6412 #ifdef CONFIG_COMPAT
6413 .compat_ioctl = megasas_mgmt_compat_ioctl,
6415 .llseek = noop_llseek,
6419 * PCI hotplug support registration structure
6421 static struct pci_driver megasas_pci_driver = {
6423 .name = "megaraid_sas",
6424 .id_table = megasas_pci_table,
6425 .probe = megasas_probe_one,
6426 .remove = megasas_detach_one,
6427 .suspend = megasas_suspend,
6428 .resume = megasas_resume,
6429 .shutdown = megasas_shutdown,
6433 * Sysfs driver attributes
6435 static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf)
6437 return snprintf(buf, strlen(MEGASAS_VERSION) + 2, "%s\n",
6441 static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL);
6444 megasas_sysfs_show_release_date(struct device_driver *dd, char *buf)
6446 return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n",
6450 static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date, NULL);
6453 megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf)
6455 return sprintf(buf, "%u\n", support_poll_for_event);
6458 static DRIVER_ATTR(support_poll_for_event, S_IRUGO,
6459 megasas_sysfs_show_support_poll_for_event, NULL);
6462 megasas_sysfs_show_support_device_change(struct device_driver *dd, char *buf)
6464 return sprintf(buf, "%u\n", support_device_change);
6467 static DRIVER_ATTR(support_device_change, S_IRUGO,
6468 megasas_sysfs_show_support_device_change, NULL);
6471 megasas_sysfs_show_dbg_lvl(struct device_driver *dd, char *buf)
6473 return sprintf(buf, "%u\n", megasas_dbg_lvl);
6477 megasas_sysfs_set_dbg_lvl(struct device_driver *dd, const char *buf, size_t count)
6480 if(sscanf(buf,"%u",&megasas_dbg_lvl)<1){
6481 printk(KERN_ERR "megasas: could not set dbg_lvl\n");
6487 static DRIVER_ATTR(dbg_lvl, S_IRUGO|S_IWUSR, megasas_sysfs_show_dbg_lvl,
6488 megasas_sysfs_set_dbg_lvl);
6491 megasas_aen_polling(struct work_struct *work)
6493 struct megasas_aen_event *ev =
6494 container_of(work, struct megasas_aen_event, hotplug_work.work);
6495 struct megasas_instance *instance = ev->instance;
6496 union megasas_evt_class_locale class_locale;
6497 struct Scsi_Host *host;
6498 struct scsi_device *sdev1;
6501 int i, j, doscan = 0;
6502 u32 seq_num, wait_time = MEGASAS_RESET_WAIT_TIME;
6506 printk(KERN_ERR "invalid instance!\n");
6511 /* Adjust event workqueue thread wait time for VF mode */
6512 if (instance->requestorId)
6513 wait_time = MEGASAS_ROUTINE_WAIT_TIME_VF;
6515 /* Don't run the event workqueue thread if OCR is running */
6516 for (i = 0; i < wait_time; i++) {
6517 if (instance->adprecovery == MEGASAS_HBA_OPERATIONAL)
6519 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
6520 printk(KERN_NOTICE "megasas: %s waiting for "
6521 "controller reset to finish for scsi%d\n",
6522 __func__, instance->host->host_no);
6527 instance->ev = NULL;
6528 host = instance->host;
6529 if (instance->evt_detail) {
6531 switch (le32_to_cpu(instance->evt_detail->code)) {
6532 case MR_EVT_PD_INSERTED:
6533 if (megasas_get_pd_list(instance) == 0) {
6534 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
6536 j < MEGASAS_MAX_DEV_PER_CHANNEL;
6540 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
6543 scsi_device_lookup(host, i, j, 0);
6545 if (instance->pd_list[pd_index].driveState
6546 == MR_PD_STATE_SYSTEM) {
6548 scsi_add_device(host, i, j, 0);
6552 scsi_device_put(sdev1);
6560 case MR_EVT_PD_REMOVED:
6561 if (megasas_get_pd_list(instance) == 0) {
6562 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
6564 j < MEGASAS_MAX_DEV_PER_CHANNEL;
6568 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
6571 scsi_device_lookup(host, i, j, 0);
6573 if (instance->pd_list[pd_index].driveState
6574 == MR_PD_STATE_SYSTEM) {
6576 scsi_device_put(sdev1);
6580 scsi_remove_device(sdev1);
6581 scsi_device_put(sdev1);
6590 case MR_EVT_LD_OFFLINE:
6591 case MR_EVT_CFG_CLEARED:
6592 case MR_EVT_LD_DELETED:
6593 if (!instance->requestorId ||
6594 (instance->requestorId &&
6595 megasas_get_ld_vf_affiliation(instance, 0))) {
6596 if (megasas_ld_list_query(instance,
6597 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
6598 megasas_get_ld_list(instance);
6599 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
6601 j < MEGASAS_MAX_DEV_PER_CHANNEL;
6605 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
6607 sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
6609 if (instance->ld_ids[ld_index]
6612 scsi_device_put(sdev1);
6615 scsi_remove_device(sdev1);
6616 scsi_device_put(sdev1);
6624 case MR_EVT_LD_CREATED:
6625 if (!instance->requestorId ||
6626 (instance->requestorId &&
6627 megasas_get_ld_vf_affiliation(instance, 0))) {
6628 if (megasas_ld_list_query(instance,
6629 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
6630 megasas_get_ld_list(instance);
6631 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
6633 j < MEGASAS_MAX_DEV_PER_CHANNEL;
6636 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
6638 sdev1 = scsi_device_lookup(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
6640 if (instance->ld_ids[ld_index]
6643 scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
6646 scsi_device_put(sdev1);
6652 case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED:
6653 case MR_EVT_FOREIGN_CFG_IMPORTED:
6654 case MR_EVT_LD_STATE_CHANGE:
6662 printk(KERN_ERR "invalid evt_detail!\n");
6668 printk(KERN_INFO "megaraid_sas: scanning for scsi%d...\n",
6669 instance->host->host_no);
6670 if (megasas_get_pd_list(instance) == 0) {
6671 for (i = 0; i < MEGASAS_MAX_PD_CHANNELS; i++) {
6672 for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL; j++) {
6673 pd_index = i*MEGASAS_MAX_DEV_PER_CHANNEL + j;
6674 sdev1 = scsi_device_lookup(host, i, j, 0);
6675 if (instance->pd_list[pd_index].driveState ==
6676 MR_PD_STATE_SYSTEM) {
6678 scsi_add_device(host, i, j, 0);
6681 scsi_device_put(sdev1);
6684 scsi_remove_device(sdev1);
6685 scsi_device_put(sdev1);
6692 if (!instance->requestorId ||
6693 (instance->requestorId &&
6694 megasas_get_ld_vf_affiliation(instance, 0))) {
6695 if (megasas_ld_list_query(instance,
6696 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST))
6697 megasas_get_ld_list(instance);
6698 for (i = 0; i < MEGASAS_MAX_LD_CHANNELS; i++) {
6699 for (j = 0; j < MEGASAS_MAX_DEV_PER_CHANNEL;
6702 (i * MEGASAS_MAX_DEV_PER_CHANNEL) + j;
6704 sdev1 = scsi_device_lookup(host,
6705 MEGASAS_MAX_PD_CHANNELS + i, j, 0);
6706 if (instance->ld_ids[ld_index]
6709 scsi_add_device(host, MEGASAS_MAX_PD_CHANNELS + i, j, 0);
6711 scsi_device_put(sdev1);
6714 scsi_remove_device(sdev1);
6715 scsi_device_put(sdev1);
6723 if ( instance->aen_cmd != NULL ) {
6728 seq_num = le32_to_cpu(instance->evt_detail->seq_num) + 1;
6730 /* Register AEN with FW for latest sequence number plus 1 */
6731 class_locale.members.reserved = 0;
6732 class_locale.members.locale = MR_EVT_LOCALE_ALL;
6733 class_locale.members.class = MR_EVT_CLASS_DEBUG;
6734 mutex_lock(&instance->aen_mutex);
6735 error = megasas_register_aen(instance, seq_num,
6737 mutex_unlock(&instance->aen_mutex);
6740 printk(KERN_ERR "register aen failed error %x\n", error);
6746 * megasas_init - Driver load entry point
6748 static int __init megasas_init(void)
6753 * Announce driver version and other information
6755 pr_info("megasas: %s\n", MEGASAS_VERSION);
6757 spin_lock_init(&poll_aen_lock);
6759 support_poll_for_event = 2;
6760 support_device_change = 1;
6762 memset(&megasas_mgmt_info, 0, sizeof(megasas_mgmt_info));
6765 * Register character device node
6767 rval = register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops);
6770 printk(KERN_DEBUG "megasas: failed to open device node\n");
6774 megasas_mgmt_majorno = rval;
6777 * Register ourselves as PCI hotplug module
6779 rval = pci_register_driver(&megasas_pci_driver);
6782 printk(KERN_DEBUG "megasas: PCI hotplug registration failed \n");
6786 rval = driver_create_file(&megasas_pci_driver.driver,
6787 &driver_attr_version);
6789 goto err_dcf_attr_ver;
6791 rval = driver_create_file(&megasas_pci_driver.driver,
6792 &driver_attr_release_date);
6794 goto err_dcf_rel_date;
6796 rval = driver_create_file(&megasas_pci_driver.driver,
6797 &driver_attr_support_poll_for_event);
6799 goto err_dcf_support_poll_for_event;
6801 rval = driver_create_file(&megasas_pci_driver.driver,
6802 &driver_attr_dbg_lvl);
6804 goto err_dcf_dbg_lvl;
6805 rval = driver_create_file(&megasas_pci_driver.driver,
6806 &driver_attr_support_device_change);
6808 goto err_dcf_support_device_change;
6812 err_dcf_support_device_change:
6813 driver_remove_file(&megasas_pci_driver.driver,
6814 &driver_attr_dbg_lvl);
6816 driver_remove_file(&megasas_pci_driver.driver,
6817 &driver_attr_support_poll_for_event);
6818 err_dcf_support_poll_for_event:
6819 driver_remove_file(&megasas_pci_driver.driver,
6820 &driver_attr_release_date);
6822 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version);
6824 pci_unregister_driver(&megasas_pci_driver);
6826 unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl");
6831 * megasas_exit - Driver unload entry point
6833 static void __exit megasas_exit(void)
6835 driver_remove_file(&megasas_pci_driver.driver,
6836 &driver_attr_dbg_lvl);
6837 driver_remove_file(&megasas_pci_driver.driver,
6838 &driver_attr_support_poll_for_event);
6839 driver_remove_file(&megasas_pci_driver.driver,
6840 &driver_attr_support_device_change);
6841 driver_remove_file(&megasas_pci_driver.driver,
6842 &driver_attr_release_date);
6843 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version);
6845 pci_unregister_driver(&megasas_pci_driver);
6846 unregister_chrdev(megasas_mgmt_majorno, "megaraid_sas_ioctl");
6849 module_init(megasas_init);
6850 module_exit(megasas_exit);