1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux MegaRAID driver for SAS based RAID controllers
5 * Copyright (c) 2003-2013 LSI Corporation
6 * Copyright (c) 2013-2016 Avago Technologies
7 * Copyright (c) 2016-2018 Broadcom Inc.
9 * Authors: Broadcom Inc.
14 * Kashyap Desai <kashyap.desai@broadcom.com>
15 * Sumit Saxena <sumit.saxena@broadcom.com>
17 * Send feedback to: megaraidlinux.pdl@broadcom.com
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/list.h>
24 #include <linux/moduleparam.h>
25 #include <linux/module.h>
26 #include <linux/spinlock.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
29 #include <linux/uio.h>
30 #include <linux/slab.h>
31 #include <linux/uaccess.h>
32 #include <asm/unaligned.h>
34 #include <linux/compat.h>
35 #include <linux/blkdev.h>
36 #include <linux/mutex.h>
37 #include <linux/poll.h>
38 #include <linux/vmalloc.h>
40 #include <scsi/scsi.h>
41 #include <scsi/scsi_cmnd.h>
42 #include <scsi/scsi_device.h>
43 #include <scsi/scsi_host.h>
44 #include <scsi/scsi_tcq.h>
45 #include "megaraid_sas_fusion.h"
46 #include "megaraid_sas.h"
49 * Number of sectors per IO command
50 * Will be set in megasas_init_mfi if user does not provide
52 static unsigned int max_sectors
;
53 module_param_named(max_sectors
, max_sectors
, int, 0);
54 MODULE_PARM_DESC(max_sectors
,
55 "Maximum number of sectors per IO command");
57 static int msix_disable
;
58 module_param(msix_disable
, int, S_IRUGO
);
59 MODULE_PARM_DESC(msix_disable
, "Disable MSI-X interrupt handling. Default: 0");
61 static unsigned int msix_vectors
;
62 module_param(msix_vectors
, int, S_IRUGO
);
63 MODULE_PARM_DESC(msix_vectors
, "MSI-X max vector count. Default: Set by FW");
65 static int allow_vf_ioctls
;
66 module_param(allow_vf_ioctls
, int, S_IRUGO
);
67 MODULE_PARM_DESC(allow_vf_ioctls
, "Allow ioctls in SR-IOV VF mode. Default: 0");
69 static unsigned int throttlequeuedepth
= MEGASAS_THROTTLE_QUEUE_DEPTH
;
70 module_param(throttlequeuedepth
, int, S_IRUGO
);
71 MODULE_PARM_DESC(throttlequeuedepth
,
72 "Adapter queue depth when throttled due to I/O timeout. Default: 16");
74 unsigned int resetwaittime
= MEGASAS_RESET_WAIT_TIME
;
75 module_param(resetwaittime
, int, S_IRUGO
);
76 MODULE_PARM_DESC(resetwaittime
, "Wait time in (1-180s) after I/O timeout before resetting adapter. Default: 180s");
78 int smp_affinity_enable
= 1;
79 module_param(smp_affinity_enable
, int, S_IRUGO
);
80 MODULE_PARM_DESC(smp_affinity_enable
, "SMP affinity feature enable/disable Default: enable(1)");
83 module_param(rdpq_enable
, int, S_IRUGO
);
84 MODULE_PARM_DESC(rdpq_enable
, "Allocate reply queue in chunks for large queue depth enable/disable Default: enable(1)");
86 unsigned int dual_qdepth_disable
;
87 module_param(dual_qdepth_disable
, int, S_IRUGO
);
88 MODULE_PARM_DESC(dual_qdepth_disable
, "Disable dual queue depth feature. Default: 0");
90 unsigned int scmd_timeout
= MEGASAS_DEFAULT_CMD_TIMEOUT
;
91 module_param(scmd_timeout
, int, S_IRUGO
);
92 MODULE_PARM_DESC(scmd_timeout
, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer.");
94 MODULE_LICENSE("GPL");
95 MODULE_VERSION(MEGASAS_VERSION
);
96 MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com");
97 MODULE_DESCRIPTION("Broadcom MegaRAID SAS Driver");
99 int megasas_transition_to_ready(struct megasas_instance
*instance
, int ocr
);
100 static int megasas_get_pd_list(struct megasas_instance
*instance
);
101 static int megasas_ld_list_query(struct megasas_instance
*instance
,
103 static int megasas_issue_init_mfi(struct megasas_instance
*instance
);
104 static int megasas_register_aen(struct megasas_instance
*instance
,
105 u32 seq_num
, u32 class_locale_word
);
106 static void megasas_get_pd_info(struct megasas_instance
*instance
,
107 struct scsi_device
*sdev
);
110 * PCI ID table for all supported controllers
112 static struct pci_device_id megasas_pci_table
[] = {
114 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1064R
)},
116 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1078R
)},
118 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1078DE
)},
120 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1078GEN2
)},
122 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS0079GEN2
)},
124 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS0073SKINNY
)},
126 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS0071SKINNY
)},
128 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_VERDE_ZCR
)},
129 /* xscale IOP, vega */
130 {PCI_DEVICE(PCI_VENDOR_ID_DELL
, PCI_DEVICE_ID_DELL_PERC5
)},
132 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_FUSION
)},
134 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_PLASMA
)},
136 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_INVADER
)},
138 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_FURY
)},
140 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_INTRUDER
)},
142 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_INTRUDER_24
)},
143 /* Intruder 24 port*/
144 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CUTLASS_52
)},
145 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CUTLASS_53
)},
147 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_VENTURA
)},
148 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CRUSADER
)},
149 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_HARPOON
)},
150 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_TOMCAT
)},
151 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_VENTURA_4PORT
)},
152 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CRUSADER_4PORT
)},
153 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E1
)},
154 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E2
)},
155 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E5
)},
156 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E6
)},
160 MODULE_DEVICE_TABLE(pci
, megasas_pci_table
);
162 static int megasas_mgmt_majorno
;
163 struct megasas_mgmt_info megasas_mgmt_info
;
164 static struct fasync_struct
*megasas_async_queue
;
165 static DEFINE_MUTEX(megasas_async_queue_mutex
);
167 static int megasas_poll_wait_aen
;
168 static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait
);
169 static u32 support_poll_for_event
;
171 static u32 support_device_change
;
172 static bool support_nvme_encapsulation
;
174 /* define lock for aen poll */
175 spinlock_t poll_aen_lock
;
178 megasas_complete_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
181 megasas_read_fw_status_reg_gen2(struct megasas_instance
*instance
);
183 megasas_adp_reset_gen2(struct megasas_instance
*instance
,
184 struct megasas_register_set __iomem
*reg_set
);
185 static irqreturn_t
megasas_isr(int irq
, void *devp
);
187 megasas_init_adapter_mfi(struct megasas_instance
*instance
);
189 megasas_build_and_issue_cmd(struct megasas_instance
*instance
,
190 struct scsi_cmnd
*scmd
);
191 static void megasas_complete_cmd_dpc(unsigned long instance_addr
);
193 wait_and_poll(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
195 void megasas_fusion_ocr_wq(struct work_struct
*work
);
196 static int megasas_get_ld_vf_affiliation(struct megasas_instance
*instance
,
199 megasas_set_dma_mask(struct megasas_instance
*instance
);
201 megasas_alloc_ctrl_mem(struct megasas_instance
*instance
);
203 megasas_free_ctrl_mem(struct megasas_instance
*instance
);
205 megasas_alloc_ctrl_dma_buffers(struct megasas_instance
*instance
);
207 megasas_free_ctrl_dma_buffers(struct megasas_instance
*instance
);
209 megasas_init_ctrl_params(struct megasas_instance
*instance
);
211 u32
megasas_readl(struct megasas_instance
*instance
,
212 const volatile void __iomem
*addr
)
216 * Due to a HW errata in Aero controllers, reads to certain
217 * Fusion registers could intermittently return all zeroes.
218 * This behavior is transient in nature and subsequent reads will
219 * return valid value. As a workaround in driver, retry readl for
220 * upto three times until a non-zero value is read.
222 if (instance
->adapter_type
== AERO_SERIES
) {
224 ret_val
= readl(addr
);
226 } while (ret_val
== 0 && i
< 3);
234 * megasas_set_dma_settings - Populate DMA address, length and flags for DCMDs
235 * @instance: Adapter soft state
236 * @dcmd: DCMD frame inside MFI command
237 * @dma_addr: DMA address of buffer to be passed to FW
238 * @dma_len: Length of DMA buffer to be passed to FW
241 void megasas_set_dma_settings(struct megasas_instance
*instance
,
242 struct megasas_dcmd_frame
*dcmd
,
243 dma_addr_t dma_addr
, u32 dma_len
)
245 if (instance
->consistent_mask_64bit
) {
246 dcmd
->sgl
.sge64
[0].phys_addr
= cpu_to_le64(dma_addr
);
247 dcmd
->sgl
.sge64
[0].length
= cpu_to_le32(dma_len
);
248 dcmd
->flags
= cpu_to_le16(dcmd
->flags
| MFI_FRAME_SGL64
);
251 dcmd
->sgl
.sge32
[0].phys_addr
=
252 cpu_to_le32(lower_32_bits(dma_addr
));
253 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32(dma_len
);
254 dcmd
->flags
= cpu_to_le16(dcmd
->flags
);
259 megasas_issue_dcmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
261 instance
->instancet
->fire_cmd(instance
,
262 cmd
->frame_phys_addr
, 0, instance
->reg_set
);
267 * megasas_get_cmd - Get a command from the free pool
268 * @instance: Adapter soft state
270 * Returns a free command from the pool
272 struct megasas_cmd
*megasas_get_cmd(struct megasas_instance
276 struct megasas_cmd
*cmd
= NULL
;
278 spin_lock_irqsave(&instance
->mfi_pool_lock
, flags
);
280 if (!list_empty(&instance
->cmd_pool
)) {
281 cmd
= list_entry((&instance
->cmd_pool
)->next
,
282 struct megasas_cmd
, list
);
283 list_del_init(&cmd
->list
);
285 dev_err(&instance
->pdev
->dev
, "Command pool empty!\n");
288 spin_unlock_irqrestore(&instance
->mfi_pool_lock
, flags
);
293 * megasas_return_cmd - Return a cmd to free command pool
294 * @instance: Adapter soft state
295 * @cmd: Command packet to be returned to free command pool
298 megasas_return_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
302 struct megasas_cmd_fusion
*cmd_fusion
;
303 struct fusion_context
*fusion
= instance
->ctrl_context
;
305 /* This flag is used only for fusion adapter.
306 * Wait for Interrupt for Polled mode DCMD
308 if (cmd
->flags
& DRV_DCMD_POLLED_MODE
)
311 spin_lock_irqsave(&instance
->mfi_pool_lock
, flags
);
314 blk_tags
= instance
->max_scsi_cmds
+ cmd
->index
;
315 cmd_fusion
= fusion
->cmd_list
[blk_tags
];
316 megasas_return_cmd_fusion(instance
, cmd_fusion
);
319 cmd
->frame_count
= 0;
321 memset(cmd
->frame
, 0, instance
->mfi_frame_size
);
322 cmd
->frame
->io
.context
= cpu_to_le32(cmd
->index
);
323 if (!fusion
&& reset_devices
)
324 cmd
->frame
->hdr
.cmd
= MFI_CMD_INVALID
;
325 list_add(&cmd
->list
, (&instance
->cmd_pool
)->next
);
327 spin_unlock_irqrestore(&instance
->mfi_pool_lock
, flags
);
332 format_timestamp(uint32_t timestamp
)
334 static char buffer
[32];
336 if ((timestamp
& 0xff000000) == 0xff000000)
337 snprintf(buffer
, sizeof(buffer
), "boot + %us", timestamp
&
340 snprintf(buffer
, sizeof(buffer
), "%us", timestamp
);
345 format_class(int8_t class)
347 static char buffer
[6];
350 case MFI_EVT_CLASS_DEBUG
:
352 case MFI_EVT_CLASS_PROGRESS
:
354 case MFI_EVT_CLASS_INFO
:
356 case MFI_EVT_CLASS_WARNING
:
358 case MFI_EVT_CLASS_CRITICAL
:
360 case MFI_EVT_CLASS_FATAL
:
362 case MFI_EVT_CLASS_DEAD
:
365 snprintf(buffer
, sizeof(buffer
), "%d", class);
371 * megasas_decode_evt: Decode FW AEN event and print critical event
373 * @instance: Adapter soft state
376 megasas_decode_evt(struct megasas_instance
*instance
)
378 struct megasas_evt_detail
*evt_detail
= instance
->evt_detail
;
379 union megasas_evt_class_locale class_locale
;
380 class_locale
.word
= le32_to_cpu(evt_detail
->cl
.word
);
382 if (class_locale
.members
.class >= MFI_EVT_CLASS_CRITICAL
)
383 dev_info(&instance
->pdev
->dev
, "%d (%s/0x%04x/%s) - %s\n",
384 le32_to_cpu(evt_detail
->seq_num
),
385 format_timestamp(le32_to_cpu(evt_detail
->time_stamp
)),
386 (class_locale
.members
.locale
),
387 format_class(class_locale
.members
.class),
388 evt_detail
->description
);
392 * The following functions are defined for xscale
393 * (deviceid : 1064R, PERC5) controllers
397 * megasas_enable_intr_xscale - Enables interrupts
398 * @regs: MFI register set
401 megasas_enable_intr_xscale(struct megasas_instance
*instance
)
403 struct megasas_register_set __iomem
*regs
;
405 regs
= instance
->reg_set
;
406 writel(0, &(regs
)->outbound_intr_mask
);
408 /* Dummy readl to force pci flush */
409 readl(®s
->outbound_intr_mask
);
413 * megasas_disable_intr_xscale -Disables interrupt
414 * @regs: MFI register set
417 megasas_disable_intr_xscale(struct megasas_instance
*instance
)
419 struct megasas_register_set __iomem
*regs
;
422 regs
= instance
->reg_set
;
423 writel(mask
, ®s
->outbound_intr_mask
);
424 /* Dummy readl to force pci flush */
425 readl(®s
->outbound_intr_mask
);
429 * megasas_read_fw_status_reg_xscale - returns the current FW status value
430 * @regs: MFI register set
433 megasas_read_fw_status_reg_xscale(struct megasas_instance
*instance
)
435 return readl(&instance
->reg_set
->outbound_msg_0
);
438 * megasas_clear_interrupt_xscale - Check & clear interrupt
439 * @regs: MFI register set
442 megasas_clear_intr_xscale(struct megasas_instance
*instance
)
446 struct megasas_register_set __iomem
*regs
;
447 regs
= instance
->reg_set
;
450 * Check if it is our interrupt
452 status
= readl(®s
->outbound_intr_status
);
454 if (status
& MFI_OB_INTR_STATUS_MASK
)
455 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
456 if (status
& MFI_XSCALE_OMR0_CHANGE_INTERRUPT
)
457 mfiStatus
|= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
460 * Clear the interrupt by writing back the same value
463 writel(status
, ®s
->outbound_intr_status
);
465 /* Dummy readl to force pci flush */
466 readl(®s
->outbound_intr_status
);
472 * megasas_fire_cmd_xscale - Sends command to the FW
473 * @frame_phys_addr : Physical address of cmd
474 * @frame_count : Number of frames for the command
475 * @regs : MFI register set
478 megasas_fire_cmd_xscale(struct megasas_instance
*instance
,
479 dma_addr_t frame_phys_addr
,
481 struct megasas_register_set __iomem
*regs
)
485 spin_lock_irqsave(&instance
->hba_lock
, flags
);
486 writel((frame_phys_addr
>> 3)|(frame_count
),
487 &(regs
)->inbound_queue_port
);
488 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
492 * megasas_adp_reset_xscale - For controller reset
493 * @regs: MFI register set
496 megasas_adp_reset_xscale(struct megasas_instance
*instance
,
497 struct megasas_register_set __iomem
*regs
)
502 writel(MFI_ADP_RESET
, ®s
->inbound_doorbell
);
504 for (i
= 0; i
< 3; i
++)
505 msleep(1000); /* sleep for 3 secs */
507 pci_read_config_dword(instance
->pdev
, MFI_1068_PCSR_OFFSET
, &pcidata
);
508 dev_notice(&instance
->pdev
->dev
, "pcidata = %x\n", pcidata
);
510 dev_notice(&instance
->pdev
->dev
, "mfi 1068 offset read=%x\n", pcidata
);
512 pci_write_config_dword(instance
->pdev
,
513 MFI_1068_PCSR_OFFSET
, pcidata
);
515 for (i
= 0; i
< 2; i
++)
516 msleep(1000); /* need to wait 2 secs again */
519 pci_read_config_dword(instance
->pdev
,
520 MFI_1068_FW_HANDSHAKE_OFFSET
, &pcidata
);
521 dev_notice(&instance
->pdev
->dev
, "1068 offset handshake read=%x\n", pcidata
);
522 if ((pcidata
& 0xffff0000) == MFI_1068_FW_READY
) {
523 dev_notice(&instance
->pdev
->dev
, "1068 offset pcidt=%x\n", pcidata
);
525 pci_write_config_dword(instance
->pdev
,
526 MFI_1068_FW_HANDSHAKE_OFFSET
, pcidata
);
533 * megasas_check_reset_xscale - For controller reset check
534 * @regs: MFI register set
537 megasas_check_reset_xscale(struct megasas_instance
*instance
,
538 struct megasas_register_set __iomem
*regs
)
540 if ((atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) &&
541 (le32_to_cpu(*instance
->consumer
) ==
542 MEGASAS_ADPRESET_INPROG_SIGN
))
547 static struct megasas_instance_template megasas_instance_template_xscale
= {
549 .fire_cmd
= megasas_fire_cmd_xscale
,
550 .enable_intr
= megasas_enable_intr_xscale
,
551 .disable_intr
= megasas_disable_intr_xscale
,
552 .clear_intr
= megasas_clear_intr_xscale
,
553 .read_fw_status_reg
= megasas_read_fw_status_reg_xscale
,
554 .adp_reset
= megasas_adp_reset_xscale
,
555 .check_reset
= megasas_check_reset_xscale
,
556 .service_isr
= megasas_isr
,
557 .tasklet
= megasas_complete_cmd_dpc
,
558 .init_adapter
= megasas_init_adapter_mfi
,
559 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
560 .issue_dcmd
= megasas_issue_dcmd
,
564 * This is the end of set of functions & definitions specific
565 * to xscale (deviceid : 1064R, PERC5) controllers
569 * The following functions are defined for ppc (deviceid : 0x60)
574 * megasas_enable_intr_ppc - Enables interrupts
575 * @regs: MFI register set
578 megasas_enable_intr_ppc(struct megasas_instance
*instance
)
580 struct megasas_register_set __iomem
*regs
;
582 regs
= instance
->reg_set
;
583 writel(0xFFFFFFFF, &(regs
)->outbound_doorbell_clear
);
585 writel(~0x80000000, &(regs
)->outbound_intr_mask
);
587 /* Dummy readl to force pci flush */
588 readl(®s
->outbound_intr_mask
);
592 * megasas_disable_intr_ppc - Disable interrupt
593 * @regs: MFI register set
596 megasas_disable_intr_ppc(struct megasas_instance
*instance
)
598 struct megasas_register_set __iomem
*regs
;
599 u32 mask
= 0xFFFFFFFF;
601 regs
= instance
->reg_set
;
602 writel(mask
, ®s
->outbound_intr_mask
);
603 /* Dummy readl to force pci flush */
604 readl(®s
->outbound_intr_mask
);
608 * megasas_read_fw_status_reg_ppc - returns the current FW status value
609 * @regs: MFI register set
612 megasas_read_fw_status_reg_ppc(struct megasas_instance
*instance
)
614 return readl(&instance
->reg_set
->outbound_scratch_pad_0
);
618 * megasas_clear_interrupt_ppc - Check & clear interrupt
619 * @regs: MFI register set
622 megasas_clear_intr_ppc(struct megasas_instance
*instance
)
624 u32 status
, mfiStatus
= 0;
625 struct megasas_register_set __iomem
*regs
;
626 regs
= instance
->reg_set
;
629 * Check if it is our interrupt
631 status
= readl(®s
->outbound_intr_status
);
633 if (status
& MFI_REPLY_1078_MESSAGE_INTERRUPT
)
634 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
636 if (status
& MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT
)
637 mfiStatus
|= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
640 * Clear the interrupt by writing back the same value
642 writel(status
, ®s
->outbound_doorbell_clear
);
644 /* Dummy readl to force pci flush */
645 readl(®s
->outbound_doorbell_clear
);
651 * megasas_fire_cmd_ppc - Sends command to the FW
652 * @frame_phys_addr : Physical address of cmd
653 * @frame_count : Number of frames for the command
654 * @regs : MFI register set
657 megasas_fire_cmd_ppc(struct megasas_instance
*instance
,
658 dma_addr_t frame_phys_addr
,
660 struct megasas_register_set __iomem
*regs
)
664 spin_lock_irqsave(&instance
->hba_lock
, flags
);
665 writel((frame_phys_addr
| (frame_count
<<1))|1,
666 &(regs
)->inbound_queue_port
);
667 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
671 * megasas_check_reset_ppc - For controller reset check
672 * @regs: MFI register set
675 megasas_check_reset_ppc(struct megasas_instance
*instance
,
676 struct megasas_register_set __iomem
*regs
)
678 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
684 static struct megasas_instance_template megasas_instance_template_ppc
= {
686 .fire_cmd
= megasas_fire_cmd_ppc
,
687 .enable_intr
= megasas_enable_intr_ppc
,
688 .disable_intr
= megasas_disable_intr_ppc
,
689 .clear_intr
= megasas_clear_intr_ppc
,
690 .read_fw_status_reg
= megasas_read_fw_status_reg_ppc
,
691 .adp_reset
= megasas_adp_reset_xscale
,
692 .check_reset
= megasas_check_reset_ppc
,
693 .service_isr
= megasas_isr
,
694 .tasklet
= megasas_complete_cmd_dpc
,
695 .init_adapter
= megasas_init_adapter_mfi
,
696 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
697 .issue_dcmd
= megasas_issue_dcmd
,
701 * megasas_enable_intr_skinny - Enables interrupts
702 * @regs: MFI register set
705 megasas_enable_intr_skinny(struct megasas_instance
*instance
)
707 struct megasas_register_set __iomem
*regs
;
709 regs
= instance
->reg_set
;
710 writel(0xFFFFFFFF, &(regs
)->outbound_intr_mask
);
712 writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK
, &(regs
)->outbound_intr_mask
);
714 /* Dummy readl to force pci flush */
715 readl(®s
->outbound_intr_mask
);
719 * megasas_disable_intr_skinny - Disables interrupt
720 * @regs: MFI register set
723 megasas_disable_intr_skinny(struct megasas_instance
*instance
)
725 struct megasas_register_set __iomem
*regs
;
726 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_skinny - returns the current FW status value
736 * @regs: MFI register set
739 megasas_read_fw_status_reg_skinny(struct megasas_instance
*instance
)
741 return readl(&instance
->reg_set
->outbound_scratch_pad_0
);
745 * megasas_clear_interrupt_skinny - Check & clear interrupt
746 * @regs: MFI register set
749 megasas_clear_intr_skinny(struct megasas_instance
*instance
)
753 struct megasas_register_set __iomem
*regs
;
754 regs
= instance
->reg_set
;
757 * Check if it is our interrupt
759 status
= readl(®s
->outbound_intr_status
);
761 if (!(status
& MFI_SKINNY_ENABLE_INTERRUPT_MASK
)) {
766 * Check if it is our interrupt
768 if ((megasas_read_fw_status_reg_skinny(instance
) & MFI_STATE_MASK
) ==
770 mfiStatus
= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
772 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
775 * Clear the interrupt by writing back the same value
777 writel(status
, ®s
->outbound_intr_status
);
780 * dummy read to flush PCI
782 readl(®s
->outbound_intr_status
);
788 * megasas_fire_cmd_skinny - Sends command to the FW
789 * @frame_phys_addr : Physical address of cmd
790 * @frame_count : Number of frames for the command
791 * @regs : MFI register set
794 megasas_fire_cmd_skinny(struct megasas_instance
*instance
,
795 dma_addr_t frame_phys_addr
,
797 struct megasas_register_set __iomem
*regs
)
801 spin_lock_irqsave(&instance
->hba_lock
, flags
);
802 writel(upper_32_bits(frame_phys_addr
),
803 &(regs
)->inbound_high_queue_port
);
804 writel((lower_32_bits(frame_phys_addr
) | (frame_count
<<1))|1,
805 &(regs
)->inbound_low_queue_port
);
806 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
810 * megasas_check_reset_skinny - For controller reset check
811 * @regs: MFI register set
814 megasas_check_reset_skinny(struct megasas_instance
*instance
,
815 struct megasas_register_set __iomem
*regs
)
817 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
823 static struct megasas_instance_template megasas_instance_template_skinny
= {
825 .fire_cmd
= megasas_fire_cmd_skinny
,
826 .enable_intr
= megasas_enable_intr_skinny
,
827 .disable_intr
= megasas_disable_intr_skinny
,
828 .clear_intr
= megasas_clear_intr_skinny
,
829 .read_fw_status_reg
= megasas_read_fw_status_reg_skinny
,
830 .adp_reset
= megasas_adp_reset_gen2
,
831 .check_reset
= megasas_check_reset_skinny
,
832 .service_isr
= megasas_isr
,
833 .tasklet
= megasas_complete_cmd_dpc
,
834 .init_adapter
= megasas_init_adapter_mfi
,
835 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
836 .issue_dcmd
= megasas_issue_dcmd
,
841 * The following functions are defined for gen2 (deviceid : 0x78 0x79)
846 * megasas_enable_intr_gen2 - Enables interrupts
847 * @regs: MFI register set
850 megasas_enable_intr_gen2(struct megasas_instance
*instance
)
852 struct megasas_register_set __iomem
*regs
;
854 regs
= instance
->reg_set
;
855 writel(0xFFFFFFFF, &(regs
)->outbound_doorbell_clear
);
857 /* write ~0x00000005 (4 & 1) to the intr mask*/
858 writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK
, &(regs
)->outbound_intr_mask
);
860 /* Dummy readl to force pci flush */
861 readl(®s
->outbound_intr_mask
);
865 * megasas_disable_intr_gen2 - Disables interrupt
866 * @regs: MFI register set
869 megasas_disable_intr_gen2(struct megasas_instance
*instance
)
871 struct megasas_register_set __iomem
*regs
;
872 u32 mask
= 0xFFFFFFFF;
874 regs
= instance
->reg_set
;
875 writel(mask
, ®s
->outbound_intr_mask
);
876 /* Dummy readl to force pci flush */
877 readl(®s
->outbound_intr_mask
);
881 * megasas_read_fw_status_reg_gen2 - returns the current FW status value
882 * @regs: MFI register set
885 megasas_read_fw_status_reg_gen2(struct megasas_instance
*instance
)
887 return readl(&instance
->reg_set
->outbound_scratch_pad_0
);
891 * megasas_clear_interrupt_gen2 - Check & clear interrupt
892 * @regs: MFI register set
895 megasas_clear_intr_gen2(struct megasas_instance
*instance
)
899 struct megasas_register_set __iomem
*regs
;
900 regs
= instance
->reg_set
;
903 * Check if it is our interrupt
905 status
= readl(®s
->outbound_intr_status
);
907 if (status
& MFI_INTR_FLAG_REPLY_MESSAGE
) {
908 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
910 if (status
& MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT
) {
911 mfiStatus
|= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
915 * Clear the interrupt by writing back the same value
918 writel(status
, ®s
->outbound_doorbell_clear
);
920 /* Dummy readl to force pci flush */
921 readl(®s
->outbound_intr_status
);
926 * megasas_fire_cmd_gen2 - Sends command to the FW
927 * @frame_phys_addr : Physical address of cmd
928 * @frame_count : Number of frames for the command
929 * @regs : MFI register set
932 megasas_fire_cmd_gen2(struct megasas_instance
*instance
,
933 dma_addr_t frame_phys_addr
,
935 struct megasas_register_set __iomem
*regs
)
939 spin_lock_irqsave(&instance
->hba_lock
, flags
);
940 writel((frame_phys_addr
| (frame_count
<<1))|1,
941 &(regs
)->inbound_queue_port
);
942 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
946 * megasas_adp_reset_gen2 - For controller reset
947 * @regs: MFI register set
950 megasas_adp_reset_gen2(struct megasas_instance
*instance
,
951 struct megasas_register_set __iomem
*reg_set
)
955 u32 __iomem
*seq_offset
= ®_set
->seq_offset
;
956 u32 __iomem
*hostdiag_offset
= ®_set
->host_diag
;
958 if (instance
->instancet
== &megasas_instance_template_skinny
) {
959 seq_offset
= ®_set
->fusion_seq_offset
;
960 hostdiag_offset
= ®_set
->fusion_host_diag
;
963 writel(0, seq_offset
);
964 writel(4, seq_offset
);
965 writel(0xb, seq_offset
);
966 writel(2, seq_offset
);
967 writel(7, seq_offset
);
968 writel(0xd, seq_offset
);
972 HostDiag
= (u32
)readl(hostdiag_offset
);
974 while (!(HostDiag
& DIAG_WRITE_ENABLE
)) {
976 HostDiag
= (u32
)readl(hostdiag_offset
);
977 dev_notice(&instance
->pdev
->dev
, "RESETGEN2: retry=%x, hostdiag=%x\n",
985 dev_notice(&instance
->pdev
->dev
, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag
);
987 writel((HostDiag
| DIAG_RESET_ADAPTER
), hostdiag_offset
);
991 HostDiag
= (u32
)readl(hostdiag_offset
);
992 while (HostDiag
& DIAG_RESET_ADAPTER
) {
994 HostDiag
= (u32
)readl(hostdiag_offset
);
995 dev_notice(&instance
->pdev
->dev
, "RESET_GEN2: retry=%x, hostdiag=%x\n",
1006 * megasas_check_reset_gen2 - For controller reset check
1007 * @regs: MFI register set
1010 megasas_check_reset_gen2(struct megasas_instance
*instance
,
1011 struct megasas_register_set __iomem
*regs
)
1013 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
1019 static struct megasas_instance_template megasas_instance_template_gen2
= {
1021 .fire_cmd
= megasas_fire_cmd_gen2
,
1022 .enable_intr
= megasas_enable_intr_gen2
,
1023 .disable_intr
= megasas_disable_intr_gen2
,
1024 .clear_intr
= megasas_clear_intr_gen2
,
1025 .read_fw_status_reg
= megasas_read_fw_status_reg_gen2
,
1026 .adp_reset
= megasas_adp_reset_gen2
,
1027 .check_reset
= megasas_check_reset_gen2
,
1028 .service_isr
= megasas_isr
,
1029 .tasklet
= megasas_complete_cmd_dpc
,
1030 .init_adapter
= megasas_init_adapter_mfi
,
1031 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
1032 .issue_dcmd
= megasas_issue_dcmd
,
1036 * This is the end of set of functions & definitions
1037 * specific to gen2 (deviceid : 0x78, 0x79) controllers
1041 * Template added for TB (Fusion)
1043 extern struct megasas_instance_template megasas_instance_template_fusion
;
1046 * megasas_issue_polled - Issues a polling command
1047 * @instance: Adapter soft state
1048 * @cmd: Command packet to be issued
1050 * For polling, MFI requires the cmd_status to be set to MFI_STAT_INVALID_STATUS before posting.
1053 megasas_issue_polled(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
1055 struct megasas_header
*frame_hdr
= &cmd
->frame
->hdr
;
1057 frame_hdr
->cmd_status
= MFI_STAT_INVALID_STATUS
;
1058 frame_hdr
->flags
|= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
);
1060 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1061 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
1062 __func__
, __LINE__
);
1063 return DCMD_NOT_FIRED
;
1066 instance
->instancet
->issue_dcmd(instance
, cmd
);
1068 return wait_and_poll(instance
, cmd
, instance
->requestorId
?
1069 MEGASAS_ROUTINE_WAIT_TIME_VF
: MFI_IO_TIMEOUT_SECS
);
1073 * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds
1074 * @instance: Adapter soft state
1075 * @cmd: Command to be issued
1076 * @timeout: Timeout in seconds
1078 * This function waits on an event for the command to be returned from ISR.
1079 * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs
1080 * Used to issue ioctl commands.
1083 megasas_issue_blocked_cmd(struct megasas_instance
*instance
,
1084 struct megasas_cmd
*cmd
, int timeout
)
1087 cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
1089 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1090 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
1091 __func__
, __LINE__
);
1092 return DCMD_NOT_FIRED
;
1095 instance
->instancet
->issue_dcmd(instance
, cmd
);
1098 ret
= wait_event_timeout(instance
->int_cmd_wait_q
,
1099 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
, timeout
* HZ
);
1101 dev_err(&instance
->pdev
->dev
, "Failed from %s %d DCMD Timed out\n",
1102 __func__
, __LINE__
);
1103 return DCMD_TIMEOUT
;
1106 wait_event(instance
->int_cmd_wait_q
,
1107 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
);
1109 return (cmd
->cmd_status_drv
== MFI_STAT_OK
) ?
1110 DCMD_SUCCESS
: DCMD_FAILED
;
1114 * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd
1115 * @instance: Adapter soft state
1116 * @cmd_to_abort: Previously issued cmd to be aborted
1117 * @timeout: Timeout in seconds
1119 * MFI firmware can abort previously issued AEN comamnd (automatic event
1120 * notification). The megasas_issue_blocked_abort_cmd() issues such abort
1121 * cmd and waits for return status.
1122 * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs
1125 megasas_issue_blocked_abort_cmd(struct megasas_instance
*instance
,
1126 struct megasas_cmd
*cmd_to_abort
, int timeout
)
1128 struct megasas_cmd
*cmd
;
1129 struct megasas_abort_frame
*abort_fr
;
1132 cmd
= megasas_get_cmd(instance
);
1137 abort_fr
= &cmd
->frame
->abort
;
1140 * Prepare and issue the abort frame
1142 abort_fr
->cmd
= MFI_CMD_ABORT
;
1143 abort_fr
->cmd_status
= MFI_STAT_INVALID_STATUS
;
1144 abort_fr
->flags
= cpu_to_le16(0);
1145 abort_fr
->abort_context
= cpu_to_le32(cmd_to_abort
->index
);
1146 abort_fr
->abort_mfi_phys_addr_lo
=
1147 cpu_to_le32(lower_32_bits(cmd_to_abort
->frame_phys_addr
));
1148 abort_fr
->abort_mfi_phys_addr_hi
=
1149 cpu_to_le32(upper_32_bits(cmd_to_abort
->frame_phys_addr
));
1152 cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
1154 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1155 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
1156 __func__
, __LINE__
);
1157 return DCMD_NOT_FIRED
;
1160 instance
->instancet
->issue_dcmd(instance
, cmd
);
1163 ret
= wait_event_timeout(instance
->abort_cmd_wait_q
,
1164 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
, timeout
* HZ
);
1166 dev_err(&instance
->pdev
->dev
, "Failed from %s %d Abort Timed out\n",
1167 __func__
, __LINE__
);
1168 return DCMD_TIMEOUT
;
1171 wait_event(instance
->abort_cmd_wait_q
,
1172 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
);
1176 megasas_return_cmd(instance
, cmd
);
1177 return (cmd
->cmd_status_drv
== MFI_STAT_OK
) ?
1178 DCMD_SUCCESS
: DCMD_FAILED
;
1182 * megasas_make_sgl32 - Prepares 32-bit SGL
1183 * @instance: Adapter soft state
1184 * @scp: SCSI command from the mid-layer
1185 * @mfi_sgl: SGL to be filled in
1187 * If successful, this function returns the number of SG elements. Otherwise,
1191 megasas_make_sgl32(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1192 union megasas_sgl
*mfi_sgl
)
1196 struct scatterlist
*os_sgl
;
1198 sge_count
= scsi_dma_map(scp
);
1199 BUG_ON(sge_count
< 0);
1202 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
1203 mfi_sgl
->sge32
[i
].length
= cpu_to_le32(sg_dma_len(os_sgl
));
1204 mfi_sgl
->sge32
[i
].phys_addr
= cpu_to_le32(sg_dma_address(os_sgl
));
1211 * megasas_make_sgl64 - Prepares 64-bit SGL
1212 * @instance: Adapter soft state
1213 * @scp: SCSI command from the mid-layer
1214 * @mfi_sgl: SGL to be filled in
1216 * If successful, this function returns the number of SG elements. Otherwise,
1220 megasas_make_sgl64(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1221 union megasas_sgl
*mfi_sgl
)
1225 struct scatterlist
*os_sgl
;
1227 sge_count
= scsi_dma_map(scp
);
1228 BUG_ON(sge_count
< 0);
1231 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
1232 mfi_sgl
->sge64
[i
].length
= cpu_to_le32(sg_dma_len(os_sgl
));
1233 mfi_sgl
->sge64
[i
].phys_addr
= cpu_to_le64(sg_dma_address(os_sgl
));
1240 * megasas_make_sgl_skinny - Prepares IEEE SGL
1241 * @instance: Adapter soft state
1242 * @scp: SCSI command from the mid-layer
1243 * @mfi_sgl: SGL to be filled in
1245 * If successful, this function returns the number of SG elements. Otherwise,
1249 megasas_make_sgl_skinny(struct megasas_instance
*instance
,
1250 struct scsi_cmnd
*scp
, union megasas_sgl
*mfi_sgl
)
1254 struct scatterlist
*os_sgl
;
1256 sge_count
= scsi_dma_map(scp
);
1259 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
1260 mfi_sgl
->sge_skinny
[i
].length
=
1261 cpu_to_le32(sg_dma_len(os_sgl
));
1262 mfi_sgl
->sge_skinny
[i
].phys_addr
=
1263 cpu_to_le64(sg_dma_address(os_sgl
));
1264 mfi_sgl
->sge_skinny
[i
].flag
= cpu_to_le32(0);
1271 * megasas_get_frame_count - Computes the number of frames
1272 * @frame_type : type of frame- io or pthru frame
1273 * @sge_count : number of sg elements
1275 * Returns the number of frames required for numnber of sge's (sge_count)
1278 static u32
megasas_get_frame_count(struct megasas_instance
*instance
,
1279 u8 sge_count
, u8 frame_type
)
1284 u32 frame_count
= 0;
1286 sge_sz
= (IS_DMA64
) ? sizeof(struct megasas_sge64
) :
1287 sizeof(struct megasas_sge32
);
1289 if (instance
->flag_ieee
) {
1290 sge_sz
= sizeof(struct megasas_sge_skinny
);
1294 * Main frame can contain 2 SGEs for 64-bit SGLs and
1295 * 3 SGEs for 32-bit SGLs for ldio &
1296 * 1 SGEs for 64-bit SGLs and
1297 * 2 SGEs for 32-bit SGLs for pthru frame
1299 if (unlikely(frame_type
== PTHRU_FRAME
)) {
1300 if (instance
->flag_ieee
== 1) {
1301 num_cnt
= sge_count
- 1;
1302 } else if (IS_DMA64
)
1303 num_cnt
= sge_count
- 1;
1305 num_cnt
= sge_count
- 2;
1307 if (instance
->flag_ieee
== 1) {
1308 num_cnt
= sge_count
- 1;
1309 } else if (IS_DMA64
)
1310 num_cnt
= sge_count
- 2;
1312 num_cnt
= sge_count
- 3;
1316 sge_bytes
= sge_sz
* num_cnt
;
1318 frame_count
= (sge_bytes
/ MEGAMFI_FRAME_SIZE
) +
1319 ((sge_bytes
% MEGAMFI_FRAME_SIZE
) ? 1 : 0) ;
1324 if (frame_count
> 7)
1330 * megasas_build_dcdb - Prepares a direct cdb (DCDB) command
1331 * @instance: Adapter soft state
1332 * @scp: SCSI command
1333 * @cmd: Command to be prepared in
1335 * This function prepares CDB commands. These are typcially pass-through
1336 * commands to the devices.
1339 megasas_build_dcdb(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1340 struct megasas_cmd
*cmd
)
1345 struct megasas_pthru_frame
*pthru
;
1347 is_logical
= MEGASAS_IS_LOGICAL(scp
->device
);
1348 device_id
= MEGASAS_DEV_INDEX(scp
);
1349 pthru
= (struct megasas_pthru_frame
*)cmd
->frame
;
1351 if (scp
->sc_data_direction
== DMA_TO_DEVICE
)
1352 flags
= MFI_FRAME_DIR_WRITE
;
1353 else if (scp
->sc_data_direction
== DMA_FROM_DEVICE
)
1354 flags
= MFI_FRAME_DIR_READ
;
1355 else if (scp
->sc_data_direction
== DMA_NONE
)
1356 flags
= MFI_FRAME_DIR_NONE
;
1358 if (instance
->flag_ieee
== 1) {
1359 flags
|= MFI_FRAME_IEEE
;
1363 * Prepare the DCDB frame
1365 pthru
->cmd
= (is_logical
) ? MFI_CMD_LD_SCSI_IO
: MFI_CMD_PD_SCSI_IO
;
1366 pthru
->cmd_status
= 0x0;
1367 pthru
->scsi_status
= 0x0;
1368 pthru
->target_id
= device_id
;
1369 pthru
->lun
= scp
->device
->lun
;
1370 pthru
->cdb_len
= scp
->cmd_len
;
1373 pthru
->flags
= cpu_to_le16(flags
);
1374 pthru
->data_xfer_len
= cpu_to_le32(scsi_bufflen(scp
));
1376 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1379 * If the command is for the tape device, set the
1380 * pthru timeout to the os layer timeout value.
1382 if (scp
->device
->type
== TYPE_TAPE
) {
1383 if ((scp
->request
->timeout
/ HZ
) > 0xFFFF)
1384 pthru
->timeout
= cpu_to_le16(0xFFFF);
1386 pthru
->timeout
= cpu_to_le16(scp
->request
->timeout
/ HZ
);
1392 if (instance
->flag_ieee
== 1) {
1393 pthru
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1394 pthru
->sge_count
= megasas_make_sgl_skinny(instance
, scp
,
1396 } else if (IS_DMA64
) {
1397 pthru
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1398 pthru
->sge_count
= megasas_make_sgl64(instance
, scp
,
1401 pthru
->sge_count
= megasas_make_sgl32(instance
, scp
,
1404 if (pthru
->sge_count
> instance
->max_num_sge
) {
1405 dev_err(&instance
->pdev
->dev
, "DCDB too many SGE NUM=%x\n",
1411 * Sense info specific
1413 pthru
->sense_len
= SCSI_SENSE_BUFFERSIZE
;
1414 pthru
->sense_buf_phys_addr_hi
=
1415 cpu_to_le32(upper_32_bits(cmd
->sense_phys_addr
));
1416 pthru
->sense_buf_phys_addr_lo
=
1417 cpu_to_le32(lower_32_bits(cmd
->sense_phys_addr
));
1420 * Compute the total number of frames this command consumes. FW uses
1421 * this number to pull sufficient number of frames from host memory.
1423 cmd
->frame_count
= megasas_get_frame_count(instance
, pthru
->sge_count
,
1426 return cmd
->frame_count
;
1430 * megasas_build_ldio - Prepares IOs to logical devices
1431 * @instance: Adapter soft state
1432 * @scp: SCSI command
1433 * @cmd: Command to be prepared
1435 * Frames (and accompanying SGLs) for regular SCSI IOs use this function.
1438 megasas_build_ldio(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1439 struct megasas_cmd
*cmd
)
1442 u8 sc
= scp
->cmnd
[0];
1444 struct megasas_io_frame
*ldio
;
1446 device_id
= MEGASAS_DEV_INDEX(scp
);
1447 ldio
= (struct megasas_io_frame
*)cmd
->frame
;
1449 if (scp
->sc_data_direction
== DMA_TO_DEVICE
)
1450 flags
= MFI_FRAME_DIR_WRITE
;
1451 else if (scp
->sc_data_direction
== DMA_FROM_DEVICE
)
1452 flags
= MFI_FRAME_DIR_READ
;
1454 if (instance
->flag_ieee
== 1) {
1455 flags
|= MFI_FRAME_IEEE
;
1459 * Prepare the Logical IO frame: 2nd bit is zero for all read cmds
1461 ldio
->cmd
= (sc
& 0x02) ? MFI_CMD_LD_WRITE
: MFI_CMD_LD_READ
;
1462 ldio
->cmd_status
= 0x0;
1463 ldio
->scsi_status
= 0x0;
1464 ldio
->target_id
= device_id
;
1466 ldio
->reserved_0
= 0;
1468 ldio
->flags
= cpu_to_le16(flags
);
1469 ldio
->start_lba_hi
= 0;
1470 ldio
->access_byte
= (scp
->cmd_len
!= 6) ? scp
->cmnd
[1] : 0;
1473 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1475 if (scp
->cmd_len
== 6) {
1476 ldio
->lba_count
= cpu_to_le32((u32
) scp
->cmnd
[4]);
1477 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[1] << 16) |
1478 ((u32
) scp
->cmnd
[2] << 8) |
1479 (u32
) scp
->cmnd
[3]);
1481 ldio
->start_lba_lo
&= cpu_to_le32(0x1FFFFF);
1485 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1487 else if (scp
->cmd_len
== 10) {
1488 ldio
->lba_count
= cpu_to_le32((u32
) scp
->cmnd
[8] |
1489 ((u32
) scp
->cmnd
[7] << 8));
1490 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[2] << 24) |
1491 ((u32
) scp
->cmnd
[3] << 16) |
1492 ((u32
) scp
->cmnd
[4] << 8) |
1493 (u32
) scp
->cmnd
[5]);
1497 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1499 else if (scp
->cmd_len
== 12) {
1500 ldio
->lba_count
= cpu_to_le32(((u32
) scp
->cmnd
[6] << 24) |
1501 ((u32
) scp
->cmnd
[7] << 16) |
1502 ((u32
) scp
->cmnd
[8] << 8) |
1503 (u32
) scp
->cmnd
[9]);
1505 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[2] << 24) |
1506 ((u32
) scp
->cmnd
[3] << 16) |
1507 ((u32
) scp
->cmnd
[4] << 8) |
1508 (u32
) scp
->cmnd
[5]);
1512 * 16-byte READ(0x88) or WRITE(0x8A) cdb
1514 else if (scp
->cmd_len
== 16) {
1515 ldio
->lba_count
= cpu_to_le32(((u32
) scp
->cmnd
[10] << 24) |
1516 ((u32
) scp
->cmnd
[11] << 16) |
1517 ((u32
) scp
->cmnd
[12] << 8) |
1518 (u32
) scp
->cmnd
[13]);
1520 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[6] << 24) |
1521 ((u32
) scp
->cmnd
[7] << 16) |
1522 ((u32
) scp
->cmnd
[8] << 8) |
1523 (u32
) scp
->cmnd
[9]);
1525 ldio
->start_lba_hi
= cpu_to_le32(((u32
) scp
->cmnd
[2] << 24) |
1526 ((u32
) scp
->cmnd
[3] << 16) |
1527 ((u32
) scp
->cmnd
[4] << 8) |
1528 (u32
) scp
->cmnd
[5]);
1535 if (instance
->flag_ieee
) {
1536 ldio
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1537 ldio
->sge_count
= megasas_make_sgl_skinny(instance
, scp
,
1539 } else if (IS_DMA64
) {
1540 ldio
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1541 ldio
->sge_count
= megasas_make_sgl64(instance
, scp
, &ldio
->sgl
);
1543 ldio
->sge_count
= megasas_make_sgl32(instance
, scp
, &ldio
->sgl
);
1545 if (ldio
->sge_count
> instance
->max_num_sge
) {
1546 dev_err(&instance
->pdev
->dev
, "build_ld_io: sge_count = %x\n",
1552 * Sense info specific
1554 ldio
->sense_len
= SCSI_SENSE_BUFFERSIZE
;
1555 ldio
->sense_buf_phys_addr_hi
= 0;
1556 ldio
->sense_buf_phys_addr_lo
= cpu_to_le32(cmd
->sense_phys_addr
);
1559 * Compute the total number of frames this command consumes. FW uses
1560 * this number to pull sufficient number of frames from host memory.
1562 cmd
->frame_count
= megasas_get_frame_count(instance
,
1563 ldio
->sge_count
, IO_FRAME
);
1565 return cmd
->frame_count
;
1569 * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD
1570 * and whether it's RW or non RW
1571 * @scmd: SCSI command
1574 inline int megasas_cmd_type(struct scsi_cmnd
*cmd
)
1578 switch (cmd
->cmnd
[0]) {
1587 ret
= (MEGASAS_IS_LOGICAL(cmd
->device
)) ?
1588 READ_WRITE_LDIO
: READ_WRITE_SYSPDIO
;
1591 ret
= (MEGASAS_IS_LOGICAL(cmd
->device
)) ?
1592 NON_READ_WRITE_LDIO
: NON_READ_WRITE_SYSPDIO
;
1598 * megasas_dump_pending_frames - Dumps the frame address of all pending cmds
1600 * @instance: Adapter soft state
1603 megasas_dump_pending_frames(struct megasas_instance
*instance
)
1605 struct megasas_cmd
*cmd
;
1607 union megasas_sgl
*mfi_sgl
;
1608 struct megasas_io_frame
*ldio
;
1609 struct megasas_pthru_frame
*pthru
;
1611 u16 max_cmd
= instance
->max_fw_cmds
;
1613 dev_err(&instance
->pdev
->dev
, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance
->host
->host_no
);
1614 dev_err(&instance
->pdev
->dev
, "[%d]: Total OS Pending cmds : %d\n",instance
->host
->host_no
,atomic_read(&instance
->fw_outstanding
));
1616 dev_err(&instance
->pdev
->dev
, "[%d]: 64 bit SGLs were sent to FW\n",instance
->host
->host_no
);
1618 dev_err(&instance
->pdev
->dev
, "[%d]: 32 bit SGLs were sent to FW\n",instance
->host
->host_no
);
1620 dev_err(&instance
->pdev
->dev
, "[%d]: Pending OS cmds in FW : \n",instance
->host
->host_no
);
1621 for (i
= 0; i
< max_cmd
; i
++) {
1622 cmd
= instance
->cmd_list
[i
];
1625 dev_err(&instance
->pdev
->dev
, "[%d]: Frame addr :0x%08lx : ",instance
->host
->host_no
,(unsigned long)cmd
->frame_phys_addr
);
1626 if (megasas_cmd_type(cmd
->scmd
) == READ_WRITE_LDIO
) {
1627 ldio
= (struct megasas_io_frame
*)cmd
->frame
;
1628 mfi_sgl
= &ldio
->sgl
;
1629 sgcount
= ldio
->sge_count
;
1630 dev_err(&instance
->pdev
->dev
, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x,"
1631 " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
1632 instance
->host
->host_no
, cmd
->frame_count
, ldio
->cmd
, ldio
->target_id
,
1633 le32_to_cpu(ldio
->start_lba_lo
), le32_to_cpu(ldio
->start_lba_hi
),
1634 le32_to_cpu(ldio
->sense_buf_phys_addr_lo
), sgcount
);
1636 pthru
= (struct megasas_pthru_frame
*) cmd
->frame
;
1637 mfi_sgl
= &pthru
->sgl
;
1638 sgcount
= pthru
->sge_count
;
1639 dev_err(&instance
->pdev
->dev
, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, "
1640 "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
1641 instance
->host
->host_no
, cmd
->frame_count
, pthru
->cmd
, pthru
->target_id
,
1642 pthru
->lun
, pthru
->cdb_len
, le32_to_cpu(pthru
->data_xfer_len
),
1643 le32_to_cpu(pthru
->sense_buf_phys_addr_lo
), sgcount
);
1645 if (megasas_dbg_lvl
& MEGASAS_DBG_LVL
) {
1646 for (n
= 0; n
< sgcount
; n
++) {
1648 dev_err(&instance
->pdev
->dev
, "sgl len : 0x%x, sgl addr : 0x%llx\n",
1649 le32_to_cpu(mfi_sgl
->sge64
[n
].length
),
1650 le64_to_cpu(mfi_sgl
->sge64
[n
].phys_addr
));
1652 dev_err(&instance
->pdev
->dev
, "sgl len : 0x%x, sgl addr : 0x%x\n",
1653 le32_to_cpu(mfi_sgl
->sge32
[n
].length
),
1654 le32_to_cpu(mfi_sgl
->sge32
[n
].phys_addr
));
1658 dev_err(&instance
->pdev
->dev
, "[%d]: Pending Internal cmds in FW : \n",instance
->host
->host_no
);
1659 for (i
= 0; i
< max_cmd
; i
++) {
1661 cmd
= instance
->cmd_list
[i
];
1663 if (cmd
->sync_cmd
== 1)
1664 dev_err(&instance
->pdev
->dev
, "0x%08lx : ", (unsigned long)cmd
->frame_phys_addr
);
1666 dev_err(&instance
->pdev
->dev
, "[%d]: Dumping Done\n\n",instance
->host
->host_no
);
1670 megasas_build_and_issue_cmd(struct megasas_instance
*instance
,
1671 struct scsi_cmnd
*scmd
)
1673 struct megasas_cmd
*cmd
;
1676 cmd
= megasas_get_cmd(instance
);
1678 return SCSI_MLQUEUE_HOST_BUSY
;
1681 * Logical drive command
1683 if (megasas_cmd_type(scmd
) == READ_WRITE_LDIO
)
1684 frame_count
= megasas_build_ldio(instance
, scmd
, cmd
);
1686 frame_count
= megasas_build_dcdb(instance
, scmd
, cmd
);
1689 goto out_return_cmd
;
1692 scmd
->SCp
.ptr
= (char *)cmd
;
1695 * Issue the command to the FW
1697 atomic_inc(&instance
->fw_outstanding
);
1699 instance
->instancet
->fire_cmd(instance
, cmd
->frame_phys_addr
,
1700 cmd
->frame_count
-1, instance
->reg_set
);
1704 megasas_return_cmd(instance
, cmd
);
1705 return SCSI_MLQUEUE_HOST_BUSY
;
1710 * megasas_queue_command - Queue entry point
1711 * @scmd: SCSI command to be queued
1712 * @done: Callback entry point
1715 megasas_queue_command(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
1717 struct megasas_instance
*instance
;
1718 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
1720 instance
= (struct megasas_instance
*)
1721 scmd
->device
->host
->hostdata
;
1723 if (instance
->unload
== 1) {
1724 scmd
->result
= DID_NO_CONNECT
<< 16;
1725 scmd
->scsi_done(scmd
);
1729 if (instance
->issuepend_done
== 0)
1730 return SCSI_MLQUEUE_HOST_BUSY
;
1733 /* Check for an mpio path and adjust behavior */
1734 if (atomic_read(&instance
->adprecovery
) == MEGASAS_ADPRESET_SM_INFAULT
) {
1735 if (megasas_check_mpio_paths(instance
, scmd
) ==
1736 (DID_REQUEUE
<< 16)) {
1737 return SCSI_MLQUEUE_HOST_BUSY
;
1739 scmd
->result
= DID_NO_CONNECT
<< 16;
1740 scmd
->scsi_done(scmd
);
1745 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1746 scmd
->result
= DID_NO_CONNECT
<< 16;
1747 scmd
->scsi_done(scmd
);
1751 mr_device_priv_data
= scmd
->device
->hostdata
;
1752 if (!mr_device_priv_data
) {
1753 scmd
->result
= DID_NO_CONNECT
<< 16;
1754 scmd
->scsi_done(scmd
);
1758 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
1759 return SCSI_MLQUEUE_HOST_BUSY
;
1761 if (mr_device_priv_data
->tm_busy
)
1762 return SCSI_MLQUEUE_DEVICE_BUSY
;
1767 if (MEGASAS_IS_LOGICAL(scmd
->device
) &&
1768 (scmd
->device
->id
>= instance
->fw_supported_vd_count
||
1769 scmd
->device
->lun
)) {
1770 scmd
->result
= DID_BAD_TARGET
<< 16;
1774 if ((scmd
->cmnd
[0] == SYNCHRONIZE_CACHE
) &&
1775 MEGASAS_IS_LOGICAL(scmd
->device
) &&
1776 (!instance
->fw_sync_cache_support
)) {
1777 scmd
->result
= DID_OK
<< 16;
1781 return instance
->instancet
->build_and_issue_cmd(instance
, scmd
);
1784 scmd
->scsi_done(scmd
);
1788 static struct megasas_instance
*megasas_lookup_instance(u16 host_no
)
1792 for (i
= 0; i
< megasas_mgmt_info
.max_index
; i
++) {
1794 if ((megasas_mgmt_info
.instance
[i
]) &&
1795 (megasas_mgmt_info
.instance
[i
]->host
->host_no
== host_no
))
1796 return megasas_mgmt_info
.instance
[i
];
1803 * megasas_set_dynamic_target_properties -
1804 * Device property set by driver may not be static and it is required to be
1808 * set dma alignment (only for eedp protection enable vd).
1810 * @sdev: OS provided scsi device
1814 void megasas_set_dynamic_target_properties(struct scsi_device
*sdev
,
1815 bool is_target_prop
)
1817 u16 pd_index
= 0, ld
;
1819 struct megasas_instance
*instance
;
1820 struct fusion_context
*fusion
;
1821 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
1822 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
1823 struct MR_LD_RAID
*raid
;
1824 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
1826 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
1827 fusion
= instance
->ctrl_context
;
1828 mr_device_priv_data
= sdev
->hostdata
;
1830 if (!fusion
|| !mr_device_priv_data
)
1833 if (MEGASAS_IS_LOGICAL(sdev
)) {
1834 device_id
= ((sdev
->channel
% 2) * MEGASAS_MAX_DEV_PER_CHANNEL
)
1836 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
1837 ld
= MR_TargetIdToLdGet(device_id
, local_map_ptr
);
1838 if (ld
>= instance
->fw_supported_vd_count
)
1840 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
1842 if (raid
->capability
.ldPiMode
== MR_PROT_INFO_TYPE_CONTROLLER
)
1843 blk_queue_update_dma_alignment(sdev
->request_queue
, 0x7);
1845 mr_device_priv_data
->is_tm_capable
=
1846 raid
->capability
.tmCapable
;
1847 } else if (instance
->use_seqnum_jbod_fp
) {
1848 pd_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) +
1850 pd_sync
= (void *)fusion
->pd_seq_sync
1851 [(instance
->pd_seq_map_id
- 1) & 1];
1852 mr_device_priv_data
->is_tm_capable
=
1853 pd_sync
->seq
[pd_index
].capability
.tmCapable
;
1856 if (is_target_prop
&& instance
->tgt_prop
->reset_tmo
) {
1858 * If FW provides a target reset timeout value, driver will use
1859 * it. If not set, fallback to default values.
1861 mr_device_priv_data
->target_reset_tmo
=
1862 min_t(u8
, instance
->max_reset_tmo
,
1863 instance
->tgt_prop
->reset_tmo
);
1864 mr_device_priv_data
->task_abort_tmo
= instance
->task_abort_tmo
;
1866 mr_device_priv_data
->target_reset_tmo
=
1867 MEGASAS_DEFAULT_TM_TIMEOUT
;
1868 mr_device_priv_data
->task_abort_tmo
=
1869 MEGASAS_DEFAULT_TM_TIMEOUT
;
1874 * megasas_set_nvme_device_properties -
1876 * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K).
1877 * set maximum io transfer = MDTS of NVME device provided by MR firmware.
1879 * MR firmware provides value in KB. Caller of this function converts
1882 * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size,
1883 * MR firmware provides value 128 as (32 * 4K) = 128K.
1885 * @sdev: scsi device
1886 * @max_io_size: maximum io transfer size
1890 megasas_set_nvme_device_properties(struct scsi_device
*sdev
, u32 max_io_size
)
1892 struct megasas_instance
*instance
;
1893 u32 mr_nvme_pg_size
;
1895 instance
= (struct megasas_instance
*)sdev
->host
->hostdata
;
1896 mr_nvme_pg_size
= max_t(u32
, instance
->nvme_page_size
,
1897 MR_DEFAULT_NVME_PAGE_SIZE
);
1899 blk_queue_max_hw_sectors(sdev
->request_queue
, (max_io_size
/ 512));
1901 blk_queue_flag_set(QUEUE_FLAG_NOMERGES
, sdev
->request_queue
);
1902 blk_queue_virt_boundary(sdev
->request_queue
, mr_nvme_pg_size
- 1);
1907 * megasas_set_static_target_properties -
1908 * Device property set by driver are static and it is not required to be
1909 * updated after OCR.
1912 * set device queue depth
1913 * set nvme device properties. see - megasas_set_nvme_device_properties
1915 * @sdev: scsi device
1916 * @is_target_prop true, if fw provided target properties.
1918 static void megasas_set_static_target_properties(struct scsi_device
*sdev
,
1919 bool is_target_prop
)
1921 u16 target_index
= 0;
1923 u32 device_qd
= MEGASAS_DEFAULT_CMD_PER_LUN
;
1924 u32 max_io_size_kb
= MR_DEFAULT_NVME_MDTS_KB
;
1926 struct megasas_instance
*instance
;
1927 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
1929 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
1930 mr_device_priv_data
= sdev
->hostdata
;
1931 interface_type
= mr_device_priv_data
->interface_type
;
1934 * The RAID firmware may require extended timeouts.
1936 blk_queue_rq_timeout(sdev
->request_queue
, scmd_timeout
* HZ
);
1938 target_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) + sdev
->id
;
1940 switch (interface_type
) {
1942 device_qd
= MEGASAS_SAS_QD
;
1945 device_qd
= MEGASAS_SATA_QD
;
1948 device_qd
= MEGASAS_NVME_QD
;
1952 if (is_target_prop
) {
1953 tgt_device_qd
= le32_to_cpu(instance
->tgt_prop
->device_qdepth
);
1954 if (tgt_device_qd
&&
1955 (tgt_device_qd
<= instance
->host
->can_queue
))
1956 device_qd
= tgt_device_qd
;
1958 /* max_io_size_kb will be set to non zero for
1959 * nvme based vd and syspd.
1961 max_io_size_kb
= le32_to_cpu(instance
->tgt_prop
->max_io_size_kb
);
1964 if (instance
->nvme_page_size
&& max_io_size_kb
)
1965 megasas_set_nvme_device_properties(sdev
, (max_io_size_kb
<< 10));
1967 scsi_change_queue_depth(sdev
, device_qd
);
1972 static int megasas_slave_configure(struct scsi_device
*sdev
)
1975 struct megasas_instance
*instance
;
1976 int ret_target_prop
= DCMD_FAILED
;
1977 bool is_target_prop
= false;
1979 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
1980 if (instance
->pd_list_not_supported
) {
1981 if (!MEGASAS_IS_LOGICAL(sdev
) && sdev
->type
== TYPE_DISK
) {
1982 pd_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) +
1984 if (instance
->pd_list
[pd_index
].driveState
!=
1990 mutex_lock(&instance
->reset_mutex
);
1991 /* Send DCMD to Firmware and cache the information */
1992 if ((instance
->pd_info
) && !MEGASAS_IS_LOGICAL(sdev
))
1993 megasas_get_pd_info(instance
, sdev
);
1995 /* Some ventura firmware may not have instance->nvme_page_size set.
1996 * Do not send MR_DCMD_DRV_GET_TARGET_PROP
1998 if ((instance
->tgt_prop
) && (instance
->nvme_page_size
))
1999 ret_target_prop
= megasas_get_target_prop(instance
, sdev
);
2001 is_target_prop
= (ret_target_prop
== DCMD_SUCCESS
) ? true : false;
2002 megasas_set_static_target_properties(sdev
, is_target_prop
);
2004 /* This sdev property may change post OCR */
2005 megasas_set_dynamic_target_properties(sdev
, is_target_prop
);
2007 mutex_unlock(&instance
->reset_mutex
);
2012 static int megasas_slave_alloc(struct scsi_device
*sdev
)
2015 struct megasas_instance
*instance
;
2016 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
2018 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
2019 if (!MEGASAS_IS_LOGICAL(sdev
)) {
2021 * Open the OS scan to the SYSTEM PD
2024 (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) +
2026 if ((instance
->pd_list_not_supported
||
2027 instance
->pd_list
[pd_index
].driveState
==
2028 MR_PD_STATE_SYSTEM
)) {
2035 mr_device_priv_data
= kzalloc(sizeof(*mr_device_priv_data
),
2037 if (!mr_device_priv_data
)
2039 sdev
->hostdata
= mr_device_priv_data
;
2041 atomic_set(&mr_device_priv_data
->r1_ldio_hint
,
2042 instance
->r1_ldio_hint_default
);
2046 static void megasas_slave_destroy(struct scsi_device
*sdev
)
2048 kfree(sdev
->hostdata
);
2049 sdev
->hostdata
= NULL
;
2053 * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a
2055 * @instance: Adapter soft state
2058 static void megasas_complete_outstanding_ioctls(struct megasas_instance
*instance
)
2061 struct megasas_cmd
*cmd_mfi
;
2062 struct megasas_cmd_fusion
*cmd_fusion
;
2063 struct fusion_context
*fusion
= instance
->ctrl_context
;
2065 /* Find all outstanding ioctls */
2067 for (i
= 0; i
< instance
->max_fw_cmds
; i
++) {
2068 cmd_fusion
= fusion
->cmd_list
[i
];
2069 if (cmd_fusion
->sync_cmd_idx
!= (u32
)ULONG_MAX
) {
2070 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
2071 if (cmd_mfi
->sync_cmd
&&
2072 (cmd_mfi
->frame
->hdr
.cmd
!= MFI_CMD_ABORT
)) {
2073 cmd_mfi
->frame
->hdr
.cmd_status
=
2074 MFI_STAT_WRONG_STATE
;
2075 megasas_complete_cmd(instance
,
2081 for (i
= 0; i
< instance
->max_fw_cmds
; i
++) {
2082 cmd_mfi
= instance
->cmd_list
[i
];
2083 if (cmd_mfi
->sync_cmd
&& cmd_mfi
->frame
->hdr
.cmd
!=
2085 megasas_complete_cmd(instance
, cmd_mfi
, DID_OK
);
2091 void megaraid_sas_kill_hba(struct megasas_instance
*instance
)
2093 /* Set critical error to block I/O & ioctls in case caller didn't */
2094 atomic_set(&instance
->adprecovery
, MEGASAS_HW_CRITICAL_ERROR
);
2095 /* Wait 1 second to ensure IO or ioctls in build have posted */
2097 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
2098 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
2099 (instance
->adapter_type
!= MFI_SERIES
)) {
2100 if (!instance
->requestorId
) {
2101 writel(MFI_STOP_ADP
, &instance
->reg_set
->doorbell
);
2103 readl(&instance
->reg_set
->doorbell
);
2105 if (instance
->requestorId
&& instance
->peerIsPresent
)
2106 memset(instance
->ld_ids
, 0xff, MEGASAS_MAX_LD_IDS
);
2108 writel(MFI_STOP_ADP
,
2109 &instance
->reg_set
->inbound_doorbell
);
2111 /* Complete outstanding ioctls when adapter is killed */
2112 megasas_complete_outstanding_ioctls(instance
);
2116 * megasas_check_and_restore_queue_depth - Check if queue depth needs to be
2117 * restored to max value
2118 * @instance: Adapter soft state
2122 megasas_check_and_restore_queue_depth(struct megasas_instance
*instance
)
2124 unsigned long flags
;
2126 if (instance
->flag
& MEGASAS_FW_BUSY
2127 && time_after(jiffies
, instance
->last_time
+ 5 * HZ
)
2128 && atomic_read(&instance
->fw_outstanding
) <
2129 instance
->throttlequeuedepth
+ 1) {
2131 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
2132 instance
->flag
&= ~MEGASAS_FW_BUSY
;
2134 instance
->host
->can_queue
= instance
->cur_can_queue
;
2135 spin_unlock_irqrestore(instance
->host
->host_lock
, flags
);
2140 * megasas_complete_cmd_dpc - Returns FW's controller structure
2141 * @instance_addr: Address of adapter soft state
2143 * Tasklet to complete cmds
2145 static void megasas_complete_cmd_dpc(unsigned long instance_addr
)
2150 struct megasas_cmd
*cmd
;
2151 struct megasas_instance
*instance
=
2152 (struct megasas_instance
*)instance_addr
;
2153 unsigned long flags
;
2155 /* If we have already declared adapter dead, donot complete cmds */
2156 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
2159 spin_lock_irqsave(&instance
->completion_lock
, flags
);
2161 producer
= le32_to_cpu(*instance
->producer
);
2162 consumer
= le32_to_cpu(*instance
->consumer
);
2164 while (consumer
!= producer
) {
2165 context
= le32_to_cpu(instance
->reply_queue
[consumer
]);
2166 if (context
>= instance
->max_fw_cmds
) {
2167 dev_err(&instance
->pdev
->dev
, "Unexpected context value %x\n",
2172 cmd
= instance
->cmd_list
[context
];
2174 megasas_complete_cmd(instance
, cmd
, DID_OK
);
2177 if (consumer
== (instance
->max_fw_cmds
+ 1)) {
2182 *instance
->consumer
= cpu_to_le32(producer
);
2184 spin_unlock_irqrestore(&instance
->completion_lock
, flags
);
2187 * Check if we can restore can_queue
2189 megasas_check_and_restore_queue_depth(instance
);
2192 static void megasas_sriov_heartbeat_handler(struct timer_list
*t
);
2195 * megasas_start_timer - Initializes sriov heartbeat timer object
2196 * @instance: Adapter soft state
2199 void megasas_start_timer(struct megasas_instance
*instance
)
2201 struct timer_list
*timer
= &instance
->sriov_heartbeat_timer
;
2203 timer_setup(timer
, megasas_sriov_heartbeat_handler
, 0);
2204 timer
->expires
= jiffies
+ MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
;
2209 megasas_internal_reset_defer_cmds(struct megasas_instance
*instance
);
2212 process_fw_state_change_wq(struct work_struct
*work
);
2214 void megasas_do_ocr(struct megasas_instance
*instance
)
2216 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS1064R
) ||
2217 (instance
->pdev
->device
== PCI_DEVICE_ID_DELL_PERC5
) ||
2218 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_VERDE_ZCR
)) {
2219 *instance
->consumer
= cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN
);
2221 instance
->instancet
->disable_intr(instance
);
2222 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
2223 instance
->issuepend_done
= 0;
2225 atomic_set(&instance
->fw_outstanding
, 0);
2226 megasas_internal_reset_defer_cmds(instance
);
2227 process_fw_state_change_wq(&instance
->work_init
);
2230 static int megasas_get_ld_vf_affiliation_111(struct megasas_instance
*instance
,
2233 struct megasas_cmd
*cmd
;
2234 struct megasas_dcmd_frame
*dcmd
;
2235 struct MR_LD_VF_AFFILIATION_111
*new_affiliation_111
= NULL
;
2236 dma_addr_t new_affiliation_111_h
;
2240 cmd
= megasas_get_cmd(instance
);
2243 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_get_ld_vf_affiliation_111:"
2244 "Failed to get cmd for scsi%d\n",
2245 instance
->host
->host_no
);
2249 dcmd
= &cmd
->frame
->dcmd
;
2251 if (!instance
->vf_affiliation_111
) {
2252 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Couldn't get LD/VF "
2253 "affiliation for scsi%d\n", instance
->host
->host_no
);
2254 megasas_return_cmd(instance
, cmd
);
2259 memset(instance
->vf_affiliation_111
, 0,
2260 sizeof(struct MR_LD_VF_AFFILIATION_111
));
2262 new_affiliation_111
=
2263 dma_alloc_coherent(&instance
->pdev
->dev
,
2264 sizeof(struct MR_LD_VF_AFFILIATION_111
),
2265 &new_affiliation_111_h
, GFP_KERNEL
);
2266 if (!new_affiliation_111
) {
2267 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SR-IOV: Couldn't allocate "
2268 "memory for new affiliation for scsi%d\n",
2269 instance
->host
->host_no
);
2270 megasas_return_cmd(instance
, cmd
);
2275 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
2277 dcmd
->cmd
= MFI_CMD_DCMD
;
2278 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
2279 dcmd
->sge_count
= 1;
2280 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_BOTH
);
2283 dcmd
->data_xfer_len
=
2284 cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111
));
2285 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111
);
2288 dcmd
->sgl
.sge32
[0].phys_addr
=
2289 cpu_to_le32(instance
->vf_affiliation_111_h
);
2291 dcmd
->sgl
.sge32
[0].phys_addr
=
2292 cpu_to_le32(new_affiliation_111_h
);
2294 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32(
2295 sizeof(struct MR_LD_VF_AFFILIATION_111
));
2297 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Getting LD/VF affiliation for "
2298 "scsi%d\n", instance
->host
->host_no
);
2300 if (megasas_issue_blocked_cmd(instance
, cmd
, 0) != DCMD_SUCCESS
) {
2301 dev_warn(&instance
->pdev
->dev
, "SR-IOV: LD/VF affiliation DCMD"
2302 " failed with status 0x%x for scsi%d\n",
2303 dcmd
->cmd_status
, instance
->host
->host_no
);
2304 retval
= 1; /* Do a scan if we couldn't get affiliation */
2309 thisVf
= new_affiliation_111
->thisVf
;
2310 for (ld
= 0 ; ld
< new_affiliation_111
->vdCount
; ld
++)
2311 if (instance
->vf_affiliation_111
->map
[ld
].policy
[thisVf
] !=
2312 new_affiliation_111
->map
[ld
].policy
[thisVf
]) {
2313 dev_warn(&instance
->pdev
->dev
, "SR-IOV: "
2314 "Got new LD/VF affiliation for scsi%d\n",
2315 instance
->host
->host_no
);
2316 memcpy(instance
->vf_affiliation_111
,
2317 new_affiliation_111
,
2318 sizeof(struct MR_LD_VF_AFFILIATION_111
));
2324 if (new_affiliation_111
) {
2325 dma_free_coherent(&instance
->pdev
->dev
,
2326 sizeof(struct MR_LD_VF_AFFILIATION_111
),
2327 new_affiliation_111
,
2328 new_affiliation_111_h
);
2331 megasas_return_cmd(instance
, cmd
);
2336 static int megasas_get_ld_vf_affiliation_12(struct megasas_instance
*instance
,
2339 struct megasas_cmd
*cmd
;
2340 struct megasas_dcmd_frame
*dcmd
;
2341 struct MR_LD_VF_AFFILIATION
*new_affiliation
= NULL
;
2342 struct MR_LD_VF_MAP
*newmap
= NULL
, *savedmap
= NULL
;
2343 dma_addr_t new_affiliation_h
;
2344 int i
, j
, retval
= 0, found
= 0, doscan
= 0;
2347 cmd
= megasas_get_cmd(instance
);
2350 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_get_ld_vf_affiliation12: "
2351 "Failed to get cmd for scsi%d\n",
2352 instance
->host
->host_no
);
2356 dcmd
= &cmd
->frame
->dcmd
;
2358 if (!instance
->vf_affiliation
) {
2359 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Couldn't get LD/VF "
2360 "affiliation for scsi%d\n", instance
->host
->host_no
);
2361 megasas_return_cmd(instance
, cmd
);
2366 memset(instance
->vf_affiliation
, 0, (MAX_LOGICAL_DRIVES
+ 1) *
2367 sizeof(struct MR_LD_VF_AFFILIATION
));
2370 dma_alloc_coherent(&instance
->pdev
->dev
,
2371 (MAX_LOGICAL_DRIVES
+ 1) * sizeof(struct MR_LD_VF_AFFILIATION
),
2372 &new_affiliation_h
, GFP_KERNEL
);
2373 if (!new_affiliation
) {
2374 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SR-IOV: Couldn't allocate "
2375 "memory for new affiliation for scsi%d\n",
2376 instance
->host
->host_no
);
2377 megasas_return_cmd(instance
, cmd
);
2382 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
2384 dcmd
->cmd
= MFI_CMD_DCMD
;
2385 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
2386 dcmd
->sge_count
= 1;
2387 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_BOTH
);
2390 dcmd
->data_xfer_len
= cpu_to_le32((MAX_LOGICAL_DRIVES
+ 1) *
2391 sizeof(struct MR_LD_VF_AFFILIATION
));
2392 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS
);
2395 dcmd
->sgl
.sge32
[0].phys_addr
=
2396 cpu_to_le32(instance
->vf_affiliation_h
);
2398 dcmd
->sgl
.sge32
[0].phys_addr
=
2399 cpu_to_le32(new_affiliation_h
);
2401 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32((MAX_LOGICAL_DRIVES
+ 1) *
2402 sizeof(struct MR_LD_VF_AFFILIATION
));
2404 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Getting LD/VF affiliation for "
2405 "scsi%d\n", instance
->host
->host_no
);
2408 if (megasas_issue_blocked_cmd(instance
, cmd
, 0) != DCMD_SUCCESS
) {
2409 dev_warn(&instance
->pdev
->dev
, "SR-IOV: LD/VF affiliation DCMD"
2410 " failed with status 0x%x for scsi%d\n",
2411 dcmd
->cmd_status
, instance
->host
->host_no
);
2412 retval
= 1; /* Do a scan if we couldn't get affiliation */
2417 if (!new_affiliation
->ldCount
) {
2418 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Got new LD/VF "
2419 "affiliation for passive path for scsi%d\n",
2420 instance
->host
->host_no
);
2424 newmap
= new_affiliation
->map
;
2425 savedmap
= instance
->vf_affiliation
->map
;
2426 thisVf
= new_affiliation
->thisVf
;
2427 for (i
= 0 ; i
< new_affiliation
->ldCount
; i
++) {
2429 for (j
= 0; j
< instance
->vf_affiliation
->ldCount
;
2431 if (newmap
->ref
.targetId
==
2432 savedmap
->ref
.targetId
) {
2434 if (newmap
->policy
[thisVf
] !=
2435 savedmap
->policy
[thisVf
]) {
2440 savedmap
= (struct MR_LD_VF_MAP
*)
2441 ((unsigned char *)savedmap
+
2444 if (!found
&& newmap
->policy
[thisVf
] !=
2445 MR_LD_ACCESS_HIDDEN
) {
2449 newmap
= (struct MR_LD_VF_MAP
*)
2450 ((unsigned char *)newmap
+ newmap
->size
);
2453 newmap
= new_affiliation
->map
;
2454 savedmap
= instance
->vf_affiliation
->map
;
2456 for (i
= 0 ; i
< instance
->vf_affiliation
->ldCount
; i
++) {
2458 for (j
= 0 ; j
< new_affiliation
->ldCount
; j
++) {
2459 if (savedmap
->ref
.targetId
==
2460 newmap
->ref
.targetId
) {
2462 if (savedmap
->policy
[thisVf
] !=
2463 newmap
->policy
[thisVf
]) {
2468 newmap
= (struct MR_LD_VF_MAP
*)
2469 ((unsigned char *)newmap
+
2472 if (!found
&& savedmap
->policy
[thisVf
] !=
2473 MR_LD_ACCESS_HIDDEN
) {
2477 savedmap
= (struct MR_LD_VF_MAP
*)
2478 ((unsigned char *)savedmap
+
2484 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Got new LD/VF "
2485 "affiliation for scsi%d\n", instance
->host
->host_no
);
2486 memcpy(instance
->vf_affiliation
, new_affiliation
,
2487 new_affiliation
->size
);
2491 if (new_affiliation
)
2492 dma_free_coherent(&instance
->pdev
->dev
,
2493 (MAX_LOGICAL_DRIVES
+ 1) *
2494 sizeof(struct MR_LD_VF_AFFILIATION
),
2495 new_affiliation
, new_affiliation_h
);
2496 megasas_return_cmd(instance
, cmd
);
2501 /* This function will get the current SR-IOV LD/VF affiliation */
2502 static int megasas_get_ld_vf_affiliation(struct megasas_instance
*instance
,
2507 if (instance
->PlasmaFW111
)
2508 retval
= megasas_get_ld_vf_affiliation_111(instance
, initial
);
2510 retval
= megasas_get_ld_vf_affiliation_12(instance
, initial
);
2514 /* This function will tell FW to start the SR-IOV heartbeat */
2515 int megasas_sriov_start_heartbeat(struct megasas_instance
*instance
,
2518 struct megasas_cmd
*cmd
;
2519 struct megasas_dcmd_frame
*dcmd
;
2522 cmd
= megasas_get_cmd(instance
);
2525 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_sriov_start_heartbeat: "
2526 "Failed to get cmd for scsi%d\n",
2527 instance
->host
->host_no
);
2531 dcmd
= &cmd
->frame
->dcmd
;
2534 instance
->hb_host_mem
=
2535 dma_alloc_coherent(&instance
->pdev
->dev
,
2536 sizeof(struct MR_CTRL_HB_HOST_MEM
),
2537 &instance
->hb_host_mem_h
,
2539 if (!instance
->hb_host_mem
) {
2540 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SR-IOV: Couldn't allocate"
2541 " memory for heartbeat host memory for scsi%d\n",
2542 instance
->host
->host_no
);
2548 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
2550 dcmd
->mbox
.s
[0] = cpu_to_le16(sizeof(struct MR_CTRL_HB_HOST_MEM
));
2551 dcmd
->cmd
= MFI_CMD_DCMD
;
2552 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
2553 dcmd
->sge_count
= 1;
2554 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_BOTH
);
2557 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM
));
2558 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC
);
2560 megasas_set_dma_settings(instance
, dcmd
, instance
->hb_host_mem_h
,
2561 sizeof(struct MR_CTRL_HB_HOST_MEM
));
2563 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Starting heartbeat for scsi%d\n",
2564 instance
->host
->host_no
);
2566 if ((instance
->adapter_type
!= MFI_SERIES
) &&
2567 !instance
->mask_interrupts
)
2568 retval
= megasas_issue_blocked_cmd(instance
, cmd
,
2569 MEGASAS_ROUTINE_WAIT_TIME_VF
);
2571 retval
= megasas_issue_polled(instance
, cmd
);
2574 dev_warn(&instance
->pdev
->dev
, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST"
2575 "_MEM_ALLOC DCMD %s for scsi%d\n",
2576 (dcmd
->cmd_status
== MFI_STAT_INVALID_STATUS
) ?
2577 "timed out" : "failed", instance
->host
->host_no
);
2582 megasas_return_cmd(instance
, cmd
);
2587 /* Handler for SR-IOV heartbeat */
2588 static void megasas_sriov_heartbeat_handler(struct timer_list
*t
)
2590 struct megasas_instance
*instance
=
2591 from_timer(instance
, t
, sriov_heartbeat_timer
);
2593 if (instance
->hb_host_mem
->HB
.fwCounter
!=
2594 instance
->hb_host_mem
->HB
.driverCounter
) {
2595 instance
->hb_host_mem
->HB
.driverCounter
=
2596 instance
->hb_host_mem
->HB
.fwCounter
;
2597 mod_timer(&instance
->sriov_heartbeat_timer
,
2598 jiffies
+ MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
);
2600 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Heartbeat never "
2601 "completed for scsi%d\n", instance
->host
->host_no
);
2602 schedule_work(&instance
->work_init
);
2607 * megasas_wait_for_outstanding - Wait for all outstanding cmds
2608 * @instance: Adapter soft state
2610 * This function waits for up to MEGASAS_RESET_WAIT_TIME seconds for FW to
2611 * complete all its outstanding commands. Returns error if one or more IOs
2612 * are pending after this time period. It also marks the controller dead.
2614 static int megasas_wait_for_outstanding(struct megasas_instance
*instance
)
2616 int i
, sl
, outstanding
;
2618 u32 wait_time
= MEGASAS_RESET_WAIT_TIME
;
2619 unsigned long flags
;
2620 struct list_head clist_local
;
2621 struct megasas_cmd
*reset_cmd
;
2624 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
2625 dev_info(&instance
->pdev
->dev
, "%s:%d HBA is killed.\n",
2626 __func__
, __LINE__
);
2630 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
2632 INIT_LIST_HEAD(&clist_local
);
2633 spin_lock_irqsave(&instance
->hba_lock
, flags
);
2634 list_splice_init(&instance
->internal_reset_pending_q
,
2636 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
2638 dev_notice(&instance
->pdev
->dev
, "HBA reset wait ...\n");
2639 for (i
= 0; i
< wait_time
; i
++) {
2641 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HBA_OPERATIONAL
)
2645 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
2646 dev_notice(&instance
->pdev
->dev
, "reset: Stopping HBA.\n");
2647 atomic_set(&instance
->adprecovery
, MEGASAS_HW_CRITICAL_ERROR
);
2652 while (!list_empty(&clist_local
)) {
2653 reset_cmd
= list_entry((&clist_local
)->next
,
2654 struct megasas_cmd
, list
);
2655 list_del_init(&reset_cmd
->list
);
2656 if (reset_cmd
->scmd
) {
2657 reset_cmd
->scmd
->result
= DID_REQUEUE
<< 16;
2658 dev_notice(&instance
->pdev
->dev
, "%d:%p reset [%02x]\n",
2659 reset_index
, reset_cmd
,
2660 reset_cmd
->scmd
->cmnd
[0]);
2662 reset_cmd
->scmd
->scsi_done(reset_cmd
->scmd
);
2663 megasas_return_cmd(instance
, reset_cmd
);
2664 } else if (reset_cmd
->sync_cmd
) {
2665 dev_notice(&instance
->pdev
->dev
, "%p synch cmds"
2669 reset_cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
2670 instance
->instancet
->fire_cmd(instance
,
2671 reset_cmd
->frame_phys_addr
,
2672 0, instance
->reg_set
);
2674 dev_notice(&instance
->pdev
->dev
, "%p unexpected"
2684 for (i
= 0; i
< resetwaittime
; i
++) {
2685 outstanding
= atomic_read(&instance
->fw_outstanding
);
2690 if (!(i
% MEGASAS_RESET_NOTICE_INTERVAL
)) {
2691 dev_notice(&instance
->pdev
->dev
, "[%2d]waiting for %d "
2692 "commands to complete\n",i
,outstanding
);
2694 * Call cmd completion routine. Cmd to be
2695 * be completed directly without depending on isr.
2697 megasas_complete_cmd_dpc((unsigned long)instance
);
2704 outstanding
= atomic_read(&instance
->fw_outstanding
);
2705 fw_state
= instance
->instancet
->read_fw_status_reg(instance
) & MFI_STATE_MASK
;
2707 if ((!outstanding
&& (fw_state
== MFI_STATE_OPERATIONAL
)))
2708 goto no_outstanding
;
2710 if (instance
->disableOnlineCtrlReset
)
2711 goto kill_hba_and_failed
;
2713 if ((fw_state
== MFI_STATE_FAULT
) || atomic_read(&instance
->fw_outstanding
)) {
2714 dev_info(&instance
->pdev
->dev
,
2715 "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, outstanding 0x%x\n",
2716 __func__
, __LINE__
, fw_state
, atomic_read(&instance
->fw_outstanding
));
2718 goto kill_hba_and_failed
;
2719 megasas_do_ocr(instance
);
2721 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
2722 dev_info(&instance
->pdev
->dev
, "%s:%d OCR failed and HBA is killed.\n",
2723 __func__
, __LINE__
);
2726 dev_info(&instance
->pdev
->dev
, "%s:%d waiting_for_outstanding: after issue OCR.\n",
2727 __func__
, __LINE__
);
2729 for (sl
= 0; sl
< 10; sl
++)
2732 outstanding
= atomic_read(&instance
->fw_outstanding
);
2734 fw_state
= instance
->instancet
->read_fw_status_reg(instance
) & MFI_STATE_MASK
;
2735 if ((!outstanding
&& (fw_state
== MFI_STATE_OPERATIONAL
)))
2736 goto no_outstanding
;
2743 dev_info(&instance
->pdev
->dev
, "%s:%d no more pending commands remain after reset handling.\n",
2744 __func__
, __LINE__
);
2747 kill_hba_and_failed
:
2749 /* Reset not supported, kill adapter */
2750 dev_info(&instance
->pdev
->dev
, "%s:%d killing adapter scsi%d"
2751 " disableOnlineCtrlReset %d fw_outstanding %d \n",
2752 __func__
, __LINE__
, instance
->host
->host_no
, instance
->disableOnlineCtrlReset
,
2753 atomic_read(&instance
->fw_outstanding
));
2754 megasas_dump_pending_frames(instance
);
2755 megaraid_sas_kill_hba(instance
);
2761 * megasas_generic_reset - Generic reset routine
2762 * @scmd: Mid-layer SCSI command
2764 * This routine implements a generic reset handler for device, bus and host
2765 * reset requests. Device, bus and host specific reset handlers can use this
2766 * function after they do their specific tasks.
2768 static int megasas_generic_reset(struct scsi_cmnd
*scmd
)
2771 struct megasas_instance
*instance
;
2773 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2775 scmd_printk(KERN_NOTICE
, scmd
, "megasas: RESET cmd=%x retries=%x\n",
2776 scmd
->cmnd
[0], scmd
->retries
);
2778 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
2779 dev_err(&instance
->pdev
->dev
, "cannot recover from previous reset failures\n");
2783 ret_val
= megasas_wait_for_outstanding(instance
);
2784 if (ret_val
== SUCCESS
)
2785 dev_notice(&instance
->pdev
->dev
, "reset successful\n");
2787 dev_err(&instance
->pdev
->dev
, "failed to do reset\n");
2793 * megasas_reset_timer - quiesce the adapter if required
2796 * Sets the FW busy flag and reduces the host->can_queue if the
2797 * cmd has not been completed within the timeout period.
2800 blk_eh_timer_return
megasas_reset_timer(struct scsi_cmnd
*scmd
)
2802 struct megasas_instance
*instance
;
2803 unsigned long flags
;
2805 if (time_after(jiffies
, scmd
->jiffies_at_alloc
+
2806 (scmd_timeout
* 2) * HZ
)) {
2810 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2811 if (!(instance
->flag
& MEGASAS_FW_BUSY
)) {
2812 /* FW is busy, throttle IO */
2813 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
2815 instance
->host
->can_queue
= instance
->throttlequeuedepth
;
2816 instance
->last_time
= jiffies
;
2817 instance
->flag
|= MEGASAS_FW_BUSY
;
2819 spin_unlock_irqrestore(instance
->host
->host_lock
, flags
);
2821 return BLK_EH_RESET_TIMER
;
2825 * megasas_dump_frame - This function will dump MPT/MFI frame
2828 megasas_dump_frame(void *mpi_request
, int sz
)
2831 __le32
*mfp
= (__le32
*)mpi_request
;
2833 printk(KERN_INFO
"IO request frame:\n\t");
2834 for (i
= 0; i
< sz
/ sizeof(__le32
); i
++) {
2835 if (i
&& ((i
% 8) == 0))
2837 printk("%08x ", le32_to_cpu(mfp
[i
]));
2843 * megasas_reset_bus_host - Bus & host reset handler entry point
2845 static int megasas_reset_bus_host(struct scsi_cmnd
*scmd
)
2848 struct megasas_instance
*instance
;
2850 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2852 scmd_printk(KERN_INFO
, scmd
,
2853 "Controller reset is requested due to IO timeout\n"
2854 "SCSI command pointer: (%p)\t SCSI host state: %d\t"
2855 " SCSI host busy: %d\t FW outstanding: %d\n",
2856 scmd
, scmd
->device
->host
->shost_state
,
2857 scsi_host_busy(scmd
->device
->host
),
2858 atomic_read(&instance
->fw_outstanding
));
2861 * First wait for all commands to complete
2863 if (instance
->adapter_type
== MFI_SERIES
) {
2864 ret
= megasas_generic_reset(scmd
);
2866 struct megasas_cmd_fusion
*cmd
;
2867 cmd
= (struct megasas_cmd_fusion
*)scmd
->SCp
.ptr
;
2869 megasas_dump_frame(cmd
->io_request
,
2870 MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
);
2871 ret
= megasas_reset_fusion(scmd
->device
->host
,
2872 SCSIIO_TIMEOUT_OCR
);
2879 * megasas_task_abort - Issues task abort request to firmware
2880 * (supported only for fusion adapters)
2881 * @scmd: SCSI command pointer
2883 static int megasas_task_abort(struct scsi_cmnd
*scmd
)
2886 struct megasas_instance
*instance
;
2888 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2890 if (instance
->adapter_type
!= MFI_SERIES
)
2891 ret
= megasas_task_abort_fusion(scmd
);
2893 sdev_printk(KERN_NOTICE
, scmd
->device
, "TASK ABORT not supported\n");
2901 * megasas_reset_target: Issues target reset request to firmware
2902 * (supported only for fusion adapters)
2903 * @scmd: SCSI command pointer
2905 static int megasas_reset_target(struct scsi_cmnd
*scmd
)
2908 struct megasas_instance
*instance
;
2910 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2912 if (instance
->adapter_type
!= MFI_SERIES
)
2913 ret
= megasas_reset_target_fusion(scmd
);
2915 sdev_printk(KERN_NOTICE
, scmd
->device
, "TARGET RESET not supported\n");
2923 * megasas_bios_param - Returns disk geometry for a disk
2924 * @sdev: device handle
2925 * @bdev: block device
2926 * @capacity: drive capacity
2927 * @geom: geometry parameters
2930 megasas_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
2931 sector_t capacity
, int geom
[])
2938 /* Default heads (64) & sectors (32) */
2942 tmp
= heads
* sectors
;
2943 cylinders
= capacity
;
2945 sector_div(cylinders
, tmp
);
2948 * Handle extended translation size for logical drives > 1Gb
2951 if (capacity
>= 0x200000) {
2954 tmp
= heads
*sectors
;
2955 cylinders
= capacity
;
2956 sector_div(cylinders
, tmp
);
2961 geom
[2] = cylinders
;
2966 static void megasas_aen_polling(struct work_struct
*work
);
2969 * megasas_service_aen - Processes an event notification
2970 * @instance: Adapter soft state
2971 * @cmd: AEN command completed by the ISR
2973 * For AEN, driver sends a command down to FW that is held by the FW till an
2974 * event occurs. When an event of interest occurs, FW completes the command
2975 * that it was previously holding.
2977 * This routines sends SIGIO signal to processes that have registered with the
2981 megasas_service_aen(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
2983 unsigned long flags
;
2986 * Don't signal app if it is just an aborted previously registered aen
2988 if ((!cmd
->abort_aen
) && (instance
->unload
== 0)) {
2989 spin_lock_irqsave(&poll_aen_lock
, flags
);
2990 megasas_poll_wait_aen
= 1;
2991 spin_unlock_irqrestore(&poll_aen_lock
, flags
);
2992 wake_up(&megasas_poll_wait
);
2993 kill_fasync(&megasas_async_queue
, SIGIO
, POLL_IN
);
2998 instance
->aen_cmd
= NULL
;
3000 megasas_return_cmd(instance
, cmd
);
3002 if ((instance
->unload
== 0) &&
3003 ((instance
->issuepend_done
== 1))) {
3004 struct megasas_aen_event
*ev
;
3006 ev
= kzalloc(sizeof(*ev
), GFP_ATOMIC
);
3008 dev_err(&instance
->pdev
->dev
, "megasas_service_aen: out of memory\n");
3010 ev
->instance
= instance
;
3012 INIT_DELAYED_WORK(&ev
->hotplug_work
,
3013 megasas_aen_polling
);
3014 schedule_delayed_work(&ev
->hotplug_work
, 0);
3020 megasas_fw_crash_buffer_store(struct device
*cdev
,
3021 struct device_attribute
*attr
, const char *buf
, size_t count
)
3023 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3024 struct megasas_instance
*instance
=
3025 (struct megasas_instance
*) shost
->hostdata
;
3027 unsigned long flags
;
3029 if (kstrtoint(buf
, 0, &val
) != 0)
3032 spin_lock_irqsave(&instance
->crashdump_lock
, flags
);
3033 instance
->fw_crash_buffer_offset
= val
;
3034 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3039 megasas_fw_crash_buffer_show(struct device
*cdev
,
3040 struct device_attribute
*attr
, char *buf
)
3042 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3043 struct megasas_instance
*instance
=
3044 (struct megasas_instance
*) shost
->hostdata
;
3046 unsigned long buff_addr
;
3047 unsigned long dmachunk
= CRASH_DMA_BUF_SIZE
;
3048 unsigned long src_addr
;
3049 unsigned long flags
;
3052 spin_lock_irqsave(&instance
->crashdump_lock
, flags
);
3053 buff_offset
= instance
->fw_crash_buffer_offset
;
3054 if (!instance
->crash_dump_buf
&&
3055 !((instance
->fw_crash_state
== AVAILABLE
) ||
3056 (instance
->fw_crash_state
== COPYING
))) {
3057 dev_err(&instance
->pdev
->dev
,
3058 "Firmware crash dump is not available\n");
3059 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3063 buff_addr
= (unsigned long) buf
;
3065 if (buff_offset
> (instance
->fw_crash_buffer_size
* dmachunk
)) {
3066 dev_err(&instance
->pdev
->dev
,
3067 "Firmware crash dump offset is out of range\n");
3068 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3072 size
= (instance
->fw_crash_buffer_size
* dmachunk
) - buff_offset
;
3073 size
= (size
>= PAGE_SIZE
) ? (PAGE_SIZE
- 1) : size
;
3075 src_addr
= (unsigned long)instance
->crash_buf
[buff_offset
/ dmachunk
] +
3076 (buff_offset
% dmachunk
);
3077 memcpy(buf
, (void *)src_addr
, size
);
3078 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3084 megasas_fw_crash_buffer_size_show(struct device
*cdev
,
3085 struct device_attribute
*attr
, char *buf
)
3087 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3088 struct megasas_instance
*instance
=
3089 (struct megasas_instance
*) shost
->hostdata
;
3091 return snprintf(buf
, PAGE_SIZE
, "%ld\n", (unsigned long)
3092 ((instance
->fw_crash_buffer_size
) * 1024 * 1024)/PAGE_SIZE
);
3096 megasas_fw_crash_state_store(struct device
*cdev
,
3097 struct device_attribute
*attr
, const char *buf
, size_t count
)
3099 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3100 struct megasas_instance
*instance
=
3101 (struct megasas_instance
*) shost
->hostdata
;
3103 unsigned long flags
;
3105 if (kstrtoint(buf
, 0, &val
) != 0)
3108 if ((val
<= AVAILABLE
|| val
> COPY_ERROR
)) {
3109 dev_err(&instance
->pdev
->dev
, "application updates invalid "
3110 "firmware crash state\n");
3114 instance
->fw_crash_state
= val
;
3116 if ((val
== COPIED
) || (val
== COPY_ERROR
)) {
3117 spin_lock_irqsave(&instance
->crashdump_lock
, flags
);
3118 megasas_free_host_crash_buffer(instance
);
3119 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3120 if (val
== COPY_ERROR
)
3121 dev_info(&instance
->pdev
->dev
, "application failed to "
3122 "copy Firmware crash dump\n");
3124 dev_info(&instance
->pdev
->dev
, "Firmware crash dump "
3125 "copied successfully\n");
3131 megasas_fw_crash_state_show(struct device
*cdev
,
3132 struct device_attribute
*attr
, char *buf
)
3134 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3135 struct megasas_instance
*instance
=
3136 (struct megasas_instance
*) shost
->hostdata
;
3138 return snprintf(buf
, PAGE_SIZE
, "%d\n", instance
->fw_crash_state
);
3142 megasas_page_size_show(struct device
*cdev
,
3143 struct device_attribute
*attr
, char *buf
)
3145 return snprintf(buf
, PAGE_SIZE
, "%ld\n", (unsigned long)PAGE_SIZE
- 1);
3149 megasas_ldio_outstanding_show(struct device
*cdev
, struct device_attribute
*attr
,
3152 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3153 struct megasas_instance
*instance
= (struct megasas_instance
*)shost
->hostdata
;
3155 return snprintf(buf
, PAGE_SIZE
, "%d\n", atomic_read(&instance
->ldio_outstanding
));
3159 megasas_fw_cmds_outstanding_show(struct device
*cdev
,
3160 struct device_attribute
*attr
, char *buf
)
3162 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3163 struct megasas_instance
*instance
= (struct megasas_instance
*)shost
->hostdata
;
3165 return snprintf(buf
, PAGE_SIZE
, "%d\n", atomic_read(&instance
->fw_outstanding
));
3168 static DEVICE_ATTR(fw_crash_buffer
, S_IRUGO
| S_IWUSR
,
3169 megasas_fw_crash_buffer_show
, megasas_fw_crash_buffer_store
);
3170 static DEVICE_ATTR(fw_crash_buffer_size
, S_IRUGO
,
3171 megasas_fw_crash_buffer_size_show
, NULL
);
3172 static DEVICE_ATTR(fw_crash_state
, S_IRUGO
| S_IWUSR
,
3173 megasas_fw_crash_state_show
, megasas_fw_crash_state_store
);
3174 static DEVICE_ATTR(page_size
, S_IRUGO
,
3175 megasas_page_size_show
, NULL
);
3176 static DEVICE_ATTR(ldio_outstanding
, S_IRUGO
,
3177 megasas_ldio_outstanding_show
, NULL
);
3178 static DEVICE_ATTR(fw_cmds_outstanding
, S_IRUGO
,
3179 megasas_fw_cmds_outstanding_show
, NULL
);
3181 struct device_attribute
*megaraid_host_attrs
[] = {
3182 &dev_attr_fw_crash_buffer_size
,
3183 &dev_attr_fw_crash_buffer
,
3184 &dev_attr_fw_crash_state
,
3185 &dev_attr_page_size
,
3186 &dev_attr_ldio_outstanding
,
3187 &dev_attr_fw_cmds_outstanding
,
3192 * Scsi host template for megaraid_sas driver
3194 static struct scsi_host_template megasas_template
= {
3196 .module
= THIS_MODULE
,
3197 .name
= "Avago SAS based MegaRAID driver",
3198 .proc_name
= "megaraid_sas",
3199 .slave_configure
= megasas_slave_configure
,
3200 .slave_alloc
= megasas_slave_alloc
,
3201 .slave_destroy
= megasas_slave_destroy
,
3202 .queuecommand
= megasas_queue_command
,
3203 .eh_target_reset_handler
= megasas_reset_target
,
3204 .eh_abort_handler
= megasas_task_abort
,
3205 .eh_host_reset_handler
= megasas_reset_bus_host
,
3206 .eh_timed_out
= megasas_reset_timer
,
3207 .shost_attrs
= megaraid_host_attrs
,
3208 .bios_param
= megasas_bios_param
,
3209 .change_queue_depth
= scsi_change_queue_depth
,
3214 * megasas_complete_int_cmd - Completes an internal command
3215 * @instance: Adapter soft state
3216 * @cmd: Command to be completed
3218 * The megasas_issue_blocked_cmd() function waits for a command to complete
3219 * after it issues a command. This function wakes up that waiting routine by
3220 * calling wake_up() on the wait queue.
3223 megasas_complete_int_cmd(struct megasas_instance
*instance
,
3224 struct megasas_cmd
*cmd
)
3226 cmd
->cmd_status_drv
= cmd
->frame
->io
.cmd_status
;
3227 wake_up(&instance
->int_cmd_wait_q
);
3231 * megasas_complete_abort - Completes aborting a command
3232 * @instance: Adapter soft state
3233 * @cmd: Cmd that was issued to abort another cmd
3235 * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q
3236 * after it issues an abort on a previously issued command. This function
3237 * wakes up all functions waiting on the same wait queue.
3240 megasas_complete_abort(struct megasas_instance
*instance
,
3241 struct megasas_cmd
*cmd
)
3243 if (cmd
->sync_cmd
) {
3245 cmd
->cmd_status_drv
= 0;
3246 wake_up(&instance
->abort_cmd_wait_q
);
3251 * megasas_complete_cmd - Completes a command
3252 * @instance: Adapter soft state
3253 * @cmd: Command to be completed
3254 * @alt_status: If non-zero, use this value as status to
3255 * SCSI mid-layer instead of the value returned
3256 * by the FW. This should be used if caller wants
3257 * an alternate status (as in the case of aborted
3261 megasas_complete_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
3265 struct megasas_header
*hdr
= &cmd
->frame
->hdr
;
3266 unsigned long flags
;
3267 struct fusion_context
*fusion
= instance
->ctrl_context
;
3270 /* flag for the retry reset */
3271 cmd
->retry_for_fw_reset
= 0;
3274 cmd
->scmd
->SCp
.ptr
= NULL
;
3277 case MFI_CMD_INVALID
:
3278 /* Some older 1068 controller FW may keep a pended
3279 MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel
3280 when booting the kdump kernel. Ignore this command to
3281 prevent a kernel panic on shutdown of the kdump kernel. */
3282 dev_warn(&instance
->pdev
->dev
, "MFI_CMD_INVALID command "
3284 dev_warn(&instance
->pdev
->dev
, "If you have a controller "
3285 "other than PERC5, please upgrade your firmware\n");
3287 case MFI_CMD_PD_SCSI_IO
:
3288 case MFI_CMD_LD_SCSI_IO
:
3291 * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been
3292 * issued either through an IO path or an IOCTL path. If it
3293 * was via IOCTL, we will send it to internal completion.
3295 if (cmd
->sync_cmd
) {
3297 megasas_complete_int_cmd(instance
, cmd
);
3302 case MFI_CMD_LD_READ
:
3303 case MFI_CMD_LD_WRITE
:
3306 cmd
->scmd
->result
= alt_status
<< 16;
3312 atomic_dec(&instance
->fw_outstanding
);
3314 scsi_dma_unmap(cmd
->scmd
);
3315 cmd
->scmd
->scsi_done(cmd
->scmd
);
3316 megasas_return_cmd(instance
, cmd
);
3321 switch (hdr
->cmd_status
) {
3324 cmd
->scmd
->result
= DID_OK
<< 16;
3327 case MFI_STAT_SCSI_IO_FAILED
:
3328 case MFI_STAT_LD_INIT_IN_PROGRESS
:
3330 (DID_ERROR
<< 16) | hdr
->scsi_status
;
3333 case MFI_STAT_SCSI_DONE_WITH_ERROR
:
3335 cmd
->scmd
->result
= (DID_OK
<< 16) | hdr
->scsi_status
;
3337 if (hdr
->scsi_status
== SAM_STAT_CHECK_CONDITION
) {
3338 memset(cmd
->scmd
->sense_buffer
, 0,
3339 SCSI_SENSE_BUFFERSIZE
);
3340 memcpy(cmd
->scmd
->sense_buffer
, cmd
->sense
,
3343 cmd
->scmd
->result
|= DRIVER_SENSE
<< 24;
3348 case MFI_STAT_LD_OFFLINE
:
3349 case MFI_STAT_DEVICE_NOT_FOUND
:
3350 cmd
->scmd
->result
= DID_BAD_TARGET
<< 16;
3354 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "MFI FW status %#x\n",
3356 cmd
->scmd
->result
= DID_ERROR
<< 16;
3360 atomic_dec(&instance
->fw_outstanding
);
3362 scsi_dma_unmap(cmd
->scmd
);
3363 cmd
->scmd
->scsi_done(cmd
->scmd
);
3364 megasas_return_cmd(instance
, cmd
);
3371 megasas_complete_int_cmd(instance
, cmd
);
3375 opcode
= le32_to_cpu(cmd
->frame
->dcmd
.opcode
);
3376 /* Check for LD map update */
3377 if ((opcode
== MR_DCMD_LD_MAP_GET_INFO
)
3378 && (cmd
->frame
->dcmd
.mbox
.b
[1] == 1)) {
3379 fusion
->fast_path_io
= 0;
3380 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
3381 status
= cmd
->frame
->hdr
.cmd_status
;
3382 instance
->map_update_cmd
= NULL
;
3383 if (status
!= MFI_STAT_OK
) {
3384 if (status
!= MFI_STAT_NOT_FOUND
)
3385 dev_warn(&instance
->pdev
->dev
, "map syncfailed, status = 0x%x\n",
3386 cmd
->frame
->hdr
.cmd_status
);
3388 megasas_return_cmd(instance
, cmd
);
3389 spin_unlock_irqrestore(
3390 instance
->host
->host_lock
,
3396 megasas_return_cmd(instance
, cmd
);
3399 * Set fast path IO to ZERO.
3400 * Validate Map will set proper value.
3401 * Meanwhile all IOs will go as LD IO.
3403 if (status
== MFI_STAT_OK
&&
3404 (MR_ValidateMapInfo(instance
, (instance
->map_id
+ 1)))) {
3406 fusion
->fast_path_io
= 1;
3408 fusion
->fast_path_io
= 0;
3411 megasas_sync_map_info(instance
);
3412 spin_unlock_irqrestore(instance
->host
->host_lock
,
3416 if (opcode
== MR_DCMD_CTRL_EVENT_GET_INFO
||
3417 opcode
== MR_DCMD_CTRL_EVENT_GET
) {
3418 spin_lock_irqsave(&poll_aen_lock
, flags
);
3419 megasas_poll_wait_aen
= 0;
3420 spin_unlock_irqrestore(&poll_aen_lock
, flags
);
3423 /* FW has an updated PD sequence */
3424 if ((opcode
== MR_DCMD_SYSTEM_PD_MAP_GET_INFO
) &&
3425 (cmd
->frame
->dcmd
.mbox
.b
[0] == 1)) {
3427 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
3428 status
= cmd
->frame
->hdr
.cmd_status
;
3429 instance
->jbod_seq_cmd
= NULL
;
3430 megasas_return_cmd(instance
, cmd
);
3432 if (status
== MFI_STAT_OK
) {
3433 instance
->pd_seq_map_id
++;
3434 /* Re-register a pd sync seq num cmd */
3435 if (megasas_sync_pd_seq_num(instance
, true))
3436 instance
->use_seqnum_jbod_fp
= false;
3438 instance
->use_seqnum_jbod_fp
= false;
3440 spin_unlock_irqrestore(instance
->host
->host_lock
, flags
);
3445 * See if got an event notification
3447 if (opcode
== MR_DCMD_CTRL_EVENT_WAIT
)
3448 megasas_service_aen(instance
, cmd
);
3450 megasas_complete_int_cmd(instance
, cmd
);
3456 * Cmd issued to abort another cmd returned
3458 megasas_complete_abort(instance
, cmd
);
3462 dev_info(&instance
->pdev
->dev
, "Unknown command completed! [0x%X]\n",
3464 megasas_complete_int_cmd(instance
, cmd
);
3470 * megasas_issue_pending_cmds_again - issue all pending cmds
3471 * in FW again because of the fw reset
3472 * @instance: Adapter soft state
3475 megasas_issue_pending_cmds_again(struct megasas_instance
*instance
)
3477 struct megasas_cmd
*cmd
;
3478 struct list_head clist_local
;
3479 union megasas_evt_class_locale class_locale
;
3480 unsigned long flags
;
3483 INIT_LIST_HEAD(&clist_local
);
3484 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3485 list_splice_init(&instance
->internal_reset_pending_q
, &clist_local
);
3486 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3488 while (!list_empty(&clist_local
)) {
3489 cmd
= list_entry((&clist_local
)->next
,
3490 struct megasas_cmd
, list
);
3491 list_del_init(&cmd
->list
);
3493 if (cmd
->sync_cmd
|| cmd
->scmd
) {
3494 dev_notice(&instance
->pdev
->dev
, "command %p, %p:%d"
3495 "detected to be pending while HBA reset\n",
3496 cmd
, cmd
->scmd
, cmd
->sync_cmd
);
3498 cmd
->retry_for_fw_reset
++;
3500 if (cmd
->retry_for_fw_reset
== 3) {
3501 dev_notice(&instance
->pdev
->dev
, "cmd %p, %p:%d"
3502 "was tried multiple times during reset."
3503 "Shutting down the HBA\n",
3504 cmd
, cmd
->scmd
, cmd
->sync_cmd
);
3505 instance
->instancet
->disable_intr(instance
);
3506 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
3507 megaraid_sas_kill_hba(instance
);
3512 if (cmd
->sync_cmd
== 1) {
3514 dev_notice(&instance
->pdev
->dev
, "unexpected"
3515 "cmd attached to internal command!\n");
3517 dev_notice(&instance
->pdev
->dev
, "%p synchronous cmd"
3518 "on the internal reset queue,"
3519 "issue it again.\n", cmd
);
3520 cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
3521 instance
->instancet
->fire_cmd(instance
,
3522 cmd
->frame_phys_addr
,
3523 0, instance
->reg_set
);
3524 } else if (cmd
->scmd
) {
3525 dev_notice(&instance
->pdev
->dev
, "%p scsi cmd [%02x]"
3526 "detected on the internal queue, issue again.\n",
3527 cmd
, cmd
->scmd
->cmnd
[0]);
3529 atomic_inc(&instance
->fw_outstanding
);
3530 instance
->instancet
->fire_cmd(instance
,
3531 cmd
->frame_phys_addr
,
3532 cmd
->frame_count
-1, instance
->reg_set
);
3534 dev_notice(&instance
->pdev
->dev
, "%p unexpected cmd on the"
3535 "internal reset defer list while re-issue!!\n",
3540 if (instance
->aen_cmd
) {
3541 dev_notice(&instance
->pdev
->dev
, "aen_cmd in def process\n");
3542 megasas_return_cmd(instance
, instance
->aen_cmd
);
3544 instance
->aen_cmd
= NULL
;
3548 * Initiate AEN (Asynchronous Event Notification)
3550 seq_num
= instance
->last_seq_num
;
3551 class_locale
.members
.reserved
= 0;
3552 class_locale
.members
.locale
= MR_EVT_LOCALE_ALL
;
3553 class_locale
.members
.class = MR_EVT_CLASS_DEBUG
;
3555 megasas_register_aen(instance
, seq_num
, class_locale
.word
);
3559 * Move the internal reset pending commands to a deferred queue.
3561 * We move the commands pending at internal reset time to a
3562 * pending queue. This queue would be flushed after successful
3563 * completion of the internal reset sequence. if the internal reset
3564 * did not complete in time, the kernel reset handler would flush
3568 megasas_internal_reset_defer_cmds(struct megasas_instance
*instance
)
3570 struct megasas_cmd
*cmd
;
3572 u16 max_cmd
= instance
->max_fw_cmds
;
3574 unsigned long flags
;
3577 spin_lock_irqsave(&instance
->mfi_pool_lock
, flags
);
3578 for (i
= 0; i
< max_cmd
; i
++) {
3579 cmd
= instance
->cmd_list
[i
];
3580 if (cmd
->sync_cmd
== 1 || cmd
->scmd
) {
3581 dev_notice(&instance
->pdev
->dev
, "moving cmd[%d]:%p:%d:%p"
3582 "on the defer queue as internal\n",
3583 defer_index
, cmd
, cmd
->sync_cmd
, cmd
->scmd
);
3585 if (!list_empty(&cmd
->list
)) {
3586 dev_notice(&instance
->pdev
->dev
, "ERROR while"
3587 " moving this cmd:%p, %d %p, it was"
3588 "discovered on some list?\n",
3589 cmd
, cmd
->sync_cmd
, cmd
->scmd
);
3591 list_del_init(&cmd
->list
);
3594 list_add_tail(&cmd
->list
,
3595 &instance
->internal_reset_pending_q
);
3598 spin_unlock_irqrestore(&instance
->mfi_pool_lock
, flags
);
3603 process_fw_state_change_wq(struct work_struct
*work
)
3605 struct megasas_instance
*instance
=
3606 container_of(work
, struct megasas_instance
, work_init
);
3608 unsigned long flags
;
3610 if (atomic_read(&instance
->adprecovery
) != MEGASAS_ADPRESET_SM_INFAULT
) {
3611 dev_notice(&instance
->pdev
->dev
, "error, recovery st %x\n",
3612 atomic_read(&instance
->adprecovery
));
3616 if (atomic_read(&instance
->adprecovery
) == MEGASAS_ADPRESET_SM_INFAULT
) {
3617 dev_notice(&instance
->pdev
->dev
, "FW detected to be in fault"
3618 "state, restarting it...\n");
3620 instance
->instancet
->disable_intr(instance
);
3621 atomic_set(&instance
->fw_outstanding
, 0);
3623 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
3624 instance
->instancet
->adp_reset(instance
, instance
->reg_set
);
3625 atomic_set(&instance
->fw_reset_no_pci_access
, 0);
3627 dev_notice(&instance
->pdev
->dev
, "FW restarted successfully,"
3628 "initiating next stage...\n");
3630 dev_notice(&instance
->pdev
->dev
, "HBA recovery state machine,"
3631 "state 2 starting...\n");
3633 /* waiting for about 20 second before start the second init */
3634 for (wait
= 0; wait
< 30; wait
++) {
3638 if (megasas_transition_to_ready(instance
, 1)) {
3639 dev_notice(&instance
->pdev
->dev
, "adapter not ready\n");
3641 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
3642 megaraid_sas_kill_hba(instance
);
3646 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS1064R
) ||
3647 (instance
->pdev
->device
== PCI_DEVICE_ID_DELL_PERC5
) ||
3648 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_VERDE_ZCR
)
3650 *instance
->consumer
= *instance
->producer
;
3652 *instance
->consumer
= 0;
3653 *instance
->producer
= 0;
3656 megasas_issue_init_mfi(instance
);
3658 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3659 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
3660 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3661 instance
->instancet
->enable_intr(instance
);
3663 megasas_issue_pending_cmds_again(instance
);
3664 instance
->issuepend_done
= 1;
3669 * megasas_deplete_reply_queue - Processes all completed commands
3670 * @instance: Adapter soft state
3671 * @alt_status: Alternate status to be returned to
3672 * SCSI mid-layer instead of the status
3673 * returned by the FW
3674 * Note: this must be called with hba lock held
3677 megasas_deplete_reply_queue(struct megasas_instance
*instance
,
3683 if ((mfiStatus
= instance
->instancet
->check_reset(instance
,
3684 instance
->reg_set
)) == 1) {
3688 mfiStatus
= instance
->instancet
->clear_intr(instance
);
3689 if (mfiStatus
== 0) {
3690 /* Hardware may not set outbound_intr_status in MSI-X mode */
3691 if (!instance
->msix_vectors
)
3695 instance
->mfiStatus
= mfiStatus
;
3697 if ((mfiStatus
& MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
)) {
3698 fw_state
= instance
->instancet
->read_fw_status_reg(
3699 instance
) & MFI_STATE_MASK
;
3701 if (fw_state
!= MFI_STATE_FAULT
) {
3702 dev_notice(&instance
->pdev
->dev
, "fw state:%x\n",
3706 if ((fw_state
== MFI_STATE_FAULT
) &&
3707 (instance
->disableOnlineCtrlReset
== 0)) {
3708 dev_notice(&instance
->pdev
->dev
, "wait adp restart\n");
3710 if ((instance
->pdev
->device
==
3711 PCI_DEVICE_ID_LSI_SAS1064R
) ||
3712 (instance
->pdev
->device
==
3713 PCI_DEVICE_ID_DELL_PERC5
) ||
3714 (instance
->pdev
->device
==
3715 PCI_DEVICE_ID_LSI_VERDE_ZCR
)) {
3717 *instance
->consumer
=
3718 cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN
);
3722 instance
->instancet
->disable_intr(instance
);
3723 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
3724 instance
->issuepend_done
= 0;
3726 atomic_set(&instance
->fw_outstanding
, 0);
3727 megasas_internal_reset_defer_cmds(instance
);
3729 dev_notice(&instance
->pdev
->dev
, "fwState=%x, stage:%d\n",
3730 fw_state
, atomic_read(&instance
->adprecovery
));
3732 schedule_work(&instance
->work_init
);
3736 dev_notice(&instance
->pdev
->dev
, "fwstate:%x, dis_OCR=%x\n",
3737 fw_state
, instance
->disableOnlineCtrlReset
);
3741 tasklet_schedule(&instance
->isr_tasklet
);
3745 * megasas_isr - isr entry point
3747 static irqreturn_t
megasas_isr(int irq
, void *devp
)
3749 struct megasas_irq_context
*irq_context
= devp
;
3750 struct megasas_instance
*instance
= irq_context
->instance
;
3751 unsigned long flags
;
3754 if (atomic_read(&instance
->fw_reset_no_pci_access
))
3757 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3758 rc
= megasas_deplete_reply_queue(instance
, DID_OK
);
3759 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3765 * megasas_transition_to_ready - Move the FW to READY state
3766 * @instance: Adapter soft state
3768 * During the initialization, FW passes can potentially be in any one of
3769 * several possible states. If the FW in operational, waiting-for-handshake
3770 * states, driver must take steps to bring it to ready state. Otherwise, it
3771 * has to wait for the ready state.
3774 megasas_transition_to_ready(struct megasas_instance
*instance
, int ocr
)
3780 u32 abs_state
, curr_abs_state
;
3782 abs_state
= instance
->instancet
->read_fw_status_reg(instance
);
3783 fw_state
= abs_state
& MFI_STATE_MASK
;
3785 if (fw_state
!= MFI_STATE_READY
)
3786 dev_info(&instance
->pdev
->dev
, "Waiting for FW to come to ready"
3789 while (fw_state
!= MFI_STATE_READY
) {
3793 case MFI_STATE_FAULT
:
3794 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "FW in FAULT state!!\n");
3796 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3797 cur_state
= MFI_STATE_FAULT
;
3802 case MFI_STATE_WAIT_HANDSHAKE
:
3804 * Set the CLR bit in inbound doorbell
3806 if ((instance
->pdev
->device
==
3807 PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
3808 (instance
->pdev
->device
==
3809 PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
3810 (instance
->adapter_type
!= MFI_SERIES
))
3812 MFI_INIT_CLEAR_HANDSHAKE
|MFI_INIT_HOTPLUG
,
3813 &instance
->reg_set
->doorbell
);
3816 MFI_INIT_CLEAR_HANDSHAKE
|MFI_INIT_HOTPLUG
,
3817 &instance
->reg_set
->inbound_doorbell
);
3819 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3820 cur_state
= MFI_STATE_WAIT_HANDSHAKE
;
3823 case MFI_STATE_BOOT_MESSAGE_PENDING
:
3824 if ((instance
->pdev
->device
==
3825 PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
3826 (instance
->pdev
->device
==
3827 PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
3828 (instance
->adapter_type
!= MFI_SERIES
))
3829 writel(MFI_INIT_HOTPLUG
,
3830 &instance
->reg_set
->doorbell
);
3832 writel(MFI_INIT_HOTPLUG
,
3833 &instance
->reg_set
->inbound_doorbell
);
3835 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3836 cur_state
= MFI_STATE_BOOT_MESSAGE_PENDING
;
3839 case MFI_STATE_OPERATIONAL
:
3841 * Bring it to READY state; assuming max wait 10 secs
3843 instance
->instancet
->disable_intr(instance
);
3844 if ((instance
->pdev
->device
==
3845 PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
3846 (instance
->pdev
->device
==
3847 PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
3848 (instance
->adapter_type
!= MFI_SERIES
)) {
3849 writel(MFI_RESET_FLAGS
,
3850 &instance
->reg_set
->doorbell
);
3852 if (instance
->adapter_type
!= MFI_SERIES
) {
3853 for (i
= 0; i
< (10 * 1000); i
+= 20) {
3865 writel(MFI_RESET_FLAGS
,
3866 &instance
->reg_set
->inbound_doorbell
);
3868 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3869 cur_state
= MFI_STATE_OPERATIONAL
;
3872 case MFI_STATE_UNDEFINED
:
3874 * This state should not last for more than 2 seconds
3876 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3877 cur_state
= MFI_STATE_UNDEFINED
;
3880 case MFI_STATE_BB_INIT
:
3881 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3882 cur_state
= MFI_STATE_BB_INIT
;
3885 case MFI_STATE_FW_INIT
:
3886 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3887 cur_state
= MFI_STATE_FW_INIT
;
3890 case MFI_STATE_FW_INIT_2
:
3891 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3892 cur_state
= MFI_STATE_FW_INIT_2
;
3895 case MFI_STATE_DEVICE_SCAN
:
3896 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3897 cur_state
= MFI_STATE_DEVICE_SCAN
;
3900 case MFI_STATE_FLUSH_CACHE
:
3901 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3902 cur_state
= MFI_STATE_FLUSH_CACHE
;
3906 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Unknown state 0x%x\n",
3912 * The cur_state should not last for more than max_wait secs
3914 for (i
= 0; i
< max_wait
* 50; i
++) {
3915 curr_abs_state
= instance
->instancet
->
3916 read_fw_status_reg(instance
);
3918 if (abs_state
== curr_abs_state
) {
3925 * Return error if fw_state hasn't changed after max_wait
3927 if (curr_abs_state
== abs_state
) {
3928 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "FW state [%d] hasn't changed "
3929 "in %d secs\n", fw_state
, max_wait
);
3933 abs_state
= curr_abs_state
;
3934 fw_state
= curr_abs_state
& MFI_STATE_MASK
;
3936 dev_info(&instance
->pdev
->dev
, "FW now in Ready state\n");
3942 * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool
3943 * @instance: Adapter soft state
3945 static void megasas_teardown_frame_pool(struct megasas_instance
*instance
)
3948 u16 max_cmd
= instance
->max_mfi_cmds
;
3949 struct megasas_cmd
*cmd
;
3951 if (!instance
->frame_dma_pool
)
3955 * Return all frames to pool
3957 for (i
= 0; i
< max_cmd
; i
++) {
3959 cmd
= instance
->cmd_list
[i
];
3962 dma_pool_free(instance
->frame_dma_pool
, cmd
->frame
,
3963 cmd
->frame_phys_addr
);
3966 dma_pool_free(instance
->sense_dma_pool
, cmd
->sense
,
3967 cmd
->sense_phys_addr
);
3971 * Now destroy the pool itself
3973 dma_pool_destroy(instance
->frame_dma_pool
);
3974 dma_pool_destroy(instance
->sense_dma_pool
);
3976 instance
->frame_dma_pool
= NULL
;
3977 instance
->sense_dma_pool
= NULL
;
3981 * megasas_create_frame_pool - Creates DMA pool for cmd frames
3982 * @instance: Adapter soft state
3984 * Each command packet has an embedded DMA memory buffer that is used for
3985 * filling MFI frame and the SG list that immediately follows the frame. This
3986 * function creates those DMA memory buffers for each command packet by using
3987 * PCI pool facility.
3989 static int megasas_create_frame_pool(struct megasas_instance
*instance
)
3995 struct megasas_cmd
*cmd
;
3997 max_cmd
= instance
->max_mfi_cmds
;
4000 * Size of our frame is 64 bytes for MFI frame, followed by max SG
4001 * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer
4003 sge_sz
= (IS_DMA64
) ? sizeof(struct megasas_sge64
) :
4004 sizeof(struct megasas_sge32
);
4006 if (instance
->flag_ieee
)
4007 sge_sz
= sizeof(struct megasas_sge_skinny
);
4010 * For MFI controllers.
4012 * max_sge_sz = 16 byte (sizeof megasas_sge_skinny)
4013 * Total 960 byte (15 MFI frame of 64 byte)
4015 * Fusion adapter require only 3 extra frame.
4016 * max_num_sge = 16 (defined as MAX_IOCTL_SGE)
4017 * max_sge_sz = 12 byte (sizeof megasas_sge64)
4018 * Total 192 byte (3 MFI frame of 64 byte)
4020 frame_count
= (instance
->adapter_type
== MFI_SERIES
) ?
4022 instance
->mfi_frame_size
= MEGAMFI_FRAME_SIZE
* frame_count
;
4024 * Use DMA pool facility provided by PCI layer
4026 instance
->frame_dma_pool
= dma_pool_create("megasas frame pool",
4027 &instance
->pdev
->dev
,
4028 instance
->mfi_frame_size
, 256, 0);
4030 if (!instance
->frame_dma_pool
) {
4031 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "failed to setup frame pool\n");
4035 instance
->sense_dma_pool
= dma_pool_create("megasas sense pool",
4036 &instance
->pdev
->dev
, 128,
4039 if (!instance
->sense_dma_pool
) {
4040 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "failed to setup sense pool\n");
4042 dma_pool_destroy(instance
->frame_dma_pool
);
4043 instance
->frame_dma_pool
= NULL
;
4049 * Allocate and attach a frame to each of the commands in cmd_list.
4050 * By making cmd->index as the context instead of the &cmd, we can
4051 * always use 32bit context regardless of the architecture
4053 for (i
= 0; i
< max_cmd
; i
++) {
4055 cmd
= instance
->cmd_list
[i
];
4057 cmd
->frame
= dma_pool_zalloc(instance
->frame_dma_pool
,
4058 GFP_KERNEL
, &cmd
->frame_phys_addr
);
4060 cmd
->sense
= dma_pool_alloc(instance
->sense_dma_pool
,
4061 GFP_KERNEL
, &cmd
->sense_phys_addr
);
4064 * megasas_teardown_frame_pool() takes care of freeing
4065 * whatever has been allocated
4067 if (!cmd
->frame
|| !cmd
->sense
) {
4068 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "dma_pool_alloc failed\n");
4069 megasas_teardown_frame_pool(instance
);
4073 cmd
->frame
->io
.context
= cpu_to_le32(cmd
->index
);
4074 cmd
->frame
->io
.pad_0
= 0;
4075 if ((instance
->adapter_type
== MFI_SERIES
) && reset_devices
)
4076 cmd
->frame
->hdr
.cmd
= MFI_CMD_INVALID
;
4083 * megasas_free_cmds - Free all the cmds in the free cmd pool
4084 * @instance: Adapter soft state
4086 void megasas_free_cmds(struct megasas_instance
*instance
)
4090 /* First free the MFI frame pool */
4091 megasas_teardown_frame_pool(instance
);
4093 /* Free all the commands in the cmd_list */
4094 for (i
= 0; i
< instance
->max_mfi_cmds
; i
++)
4096 kfree(instance
->cmd_list
[i
]);
4098 /* Free the cmd_list buffer itself */
4099 kfree(instance
->cmd_list
);
4100 instance
->cmd_list
= NULL
;
4102 INIT_LIST_HEAD(&instance
->cmd_pool
);
4106 * megasas_alloc_cmds - Allocates the command packets
4107 * @instance: Adapter soft state
4109 * Each command that is issued to the FW, whether IO commands from the OS or
4110 * internal commands like IOCTLs, are wrapped in local data structure called
4111 * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to
4114 * Each frame has a 32-bit field called context (tag). This context is used
4115 * to get back the megasas_cmd from the frame when a frame gets completed in
4116 * the ISR. Typically the address of the megasas_cmd itself would be used as
4117 * the context. But we wanted to keep the differences between 32 and 64 bit
4118 * systems to the mininum. We always use 32 bit integers for the context. In
4119 * this driver, the 32 bit values are the indices into an array cmd_list.
4120 * This array is used only to look up the megasas_cmd given the context. The
4121 * free commands themselves are maintained in a linked list called cmd_pool.
4123 int megasas_alloc_cmds(struct megasas_instance
*instance
)
4128 struct megasas_cmd
*cmd
;
4130 max_cmd
= instance
->max_mfi_cmds
;
4133 * instance->cmd_list is an array of struct megasas_cmd pointers.
4134 * Allocate the dynamic array first and then allocate individual
4137 instance
->cmd_list
= kcalloc(max_cmd
, sizeof(struct megasas_cmd
*), GFP_KERNEL
);
4139 if (!instance
->cmd_list
) {
4140 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "out of memory\n");
4144 memset(instance
->cmd_list
, 0, sizeof(struct megasas_cmd
*) *max_cmd
);
4146 for (i
= 0; i
< max_cmd
; i
++) {
4147 instance
->cmd_list
[i
] = kmalloc(sizeof(struct megasas_cmd
),
4150 if (!instance
->cmd_list
[i
]) {
4152 for (j
= 0; j
< i
; j
++)
4153 kfree(instance
->cmd_list
[j
]);
4155 kfree(instance
->cmd_list
);
4156 instance
->cmd_list
= NULL
;
4162 for (i
= 0; i
< max_cmd
; i
++) {
4163 cmd
= instance
->cmd_list
[i
];
4164 memset(cmd
, 0, sizeof(struct megasas_cmd
));
4167 cmd
->instance
= instance
;
4169 list_add_tail(&cmd
->list
, &instance
->cmd_pool
);
4173 * Create a frame pool and assign one frame to each cmd
4175 if (megasas_create_frame_pool(instance
)) {
4176 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Error creating frame DMA pool\n");
4177 megasas_free_cmds(instance
);
4185 * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state.
4186 * @instance: Adapter soft state
4188 * Return 0 for only Fusion adapter, if driver load/unload is not in progress
4189 * or FW is not under OCR.
4192 dcmd_timeout_ocr_possible(struct megasas_instance
*instance
) {
4194 if (instance
->adapter_type
== MFI_SERIES
)
4195 return KILL_ADAPTER
;
4196 else if (instance
->unload
||
4197 test_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
))
4198 return IGNORE_TIMEOUT
;
4200 return INITIATE_OCR
;
4204 megasas_get_pd_info(struct megasas_instance
*instance
, struct scsi_device
*sdev
)
4207 struct megasas_cmd
*cmd
;
4208 struct megasas_dcmd_frame
*dcmd
;
4210 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
4213 device_id
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) + sdev
->id
;
4214 cmd
= megasas_get_cmd(instance
);
4217 dev_err(&instance
->pdev
->dev
, "Failed to get cmd %s\n", __func__
);
4221 dcmd
= &cmd
->frame
->dcmd
;
4223 memset(instance
->pd_info
, 0, sizeof(*instance
->pd_info
));
4224 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4226 dcmd
->mbox
.s
[0] = cpu_to_le16(device_id
);
4227 dcmd
->cmd
= MFI_CMD_DCMD
;
4228 dcmd
->cmd_status
= 0xFF;
4229 dcmd
->sge_count
= 1;
4230 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4233 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_PD_INFO
));
4234 dcmd
->opcode
= cpu_to_le32(MR_DCMD_PD_GET_INFO
);
4236 megasas_set_dma_settings(instance
, dcmd
, instance
->pd_info_h
,
4237 sizeof(struct MR_PD_INFO
));
4239 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4240 !instance
->mask_interrupts
)
4241 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
4243 ret
= megasas_issue_polled(instance
, cmd
);
4247 mr_device_priv_data
= sdev
->hostdata
;
4248 le16_to_cpus((u16
*)&instance
->pd_info
->state
.ddf
.pdType
);
4249 mr_device_priv_data
->interface_type
=
4250 instance
->pd_info
->state
.ddf
.pdType
.intf
;
4255 switch (dcmd_timeout_ocr_possible(instance
)) {
4257 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4258 megasas_reset_fusion(instance
->host
,
4259 MFI_IO_TIMEOUT_OCR
);
4262 megaraid_sas_kill_hba(instance
);
4264 case IGNORE_TIMEOUT
:
4265 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4266 __func__
, __LINE__
);
4273 if (ret
!= DCMD_TIMEOUT
)
4274 megasas_return_cmd(instance
, cmd
);
4279 * megasas_get_pd_list_info - Returns FW's pd_list structure
4280 * @instance: Adapter soft state
4281 * @pd_list: pd_list structure
4283 * Issues an internal command (DCMD) to get the FW's controller PD
4284 * list structure. This information is mainly used to find out SYSTEM
4285 * supported by the FW.
4288 megasas_get_pd_list(struct megasas_instance
*instance
)
4290 int ret
= 0, pd_index
= 0;
4291 struct megasas_cmd
*cmd
;
4292 struct megasas_dcmd_frame
*dcmd
;
4293 struct MR_PD_LIST
*ci
;
4294 struct MR_PD_ADDRESS
*pd_addr
;
4295 dma_addr_t ci_h
= 0;
4297 if (instance
->pd_list_not_supported
) {
4298 dev_info(&instance
->pdev
->dev
, "MR_DCMD_PD_LIST_QUERY "
4299 "not supported by firmware\n");
4303 ci
= instance
->pd_list_buf
;
4304 ci_h
= instance
->pd_list_buf_h
;
4306 cmd
= megasas_get_cmd(instance
);
4309 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "(get_pd_list): Failed to get cmd\n");
4313 dcmd
= &cmd
->frame
->dcmd
;
4315 memset(ci
, 0, sizeof(*ci
));
4316 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4318 dcmd
->mbox
.b
[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST
;
4319 dcmd
->mbox
.b
[1] = 0;
4320 dcmd
->cmd
= MFI_CMD_DCMD
;
4321 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4322 dcmd
->sge_count
= 1;
4323 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4326 dcmd
->data_xfer_len
= cpu_to_le32(MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
));
4327 dcmd
->opcode
= cpu_to_le32(MR_DCMD_PD_LIST_QUERY
);
4329 megasas_set_dma_settings(instance
, dcmd
, instance
->pd_list_buf_h
,
4330 (MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
)));
4332 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4333 !instance
->mask_interrupts
)
4334 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
4335 MFI_IO_TIMEOUT_SECS
);
4337 ret
= megasas_issue_polled(instance
, cmd
);
4341 dev_info(&instance
->pdev
->dev
, "MR_DCMD_PD_LIST_QUERY "
4342 "failed/not supported by firmware\n");
4344 if (instance
->adapter_type
!= MFI_SERIES
)
4345 megaraid_sas_kill_hba(instance
);
4347 instance
->pd_list_not_supported
= 1;
4351 switch (dcmd_timeout_ocr_possible(instance
)) {
4353 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4355 * DCMD failed from AEN path.
4356 * AEN path already hold reset_mutex to avoid PCI access
4357 * while OCR is in progress.
4359 mutex_unlock(&instance
->reset_mutex
);
4360 megasas_reset_fusion(instance
->host
,
4361 MFI_IO_TIMEOUT_OCR
);
4362 mutex_lock(&instance
->reset_mutex
);
4365 megaraid_sas_kill_hba(instance
);
4367 case IGNORE_TIMEOUT
:
4368 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d \n",
4369 __func__
, __LINE__
);
4378 if ((le32_to_cpu(ci
->count
) >
4379 (MEGASAS_MAX_PD_CHANNELS
* MEGASAS_MAX_DEV_PER_CHANNEL
)))
4382 memset(instance
->local_pd_list
, 0,
4383 MEGASAS_MAX_PD
* sizeof(struct megasas_pd_list
));
4385 for (pd_index
= 0; pd_index
< le32_to_cpu(ci
->count
); pd_index
++) {
4386 instance
->local_pd_list
[le16_to_cpu(pd_addr
->deviceId
)].tid
=
4387 le16_to_cpu(pd_addr
->deviceId
);
4388 instance
->local_pd_list
[le16_to_cpu(pd_addr
->deviceId
)].driveType
=
4389 pd_addr
->scsiDevType
;
4390 instance
->local_pd_list
[le16_to_cpu(pd_addr
->deviceId
)].driveState
=
4395 memcpy(instance
->pd_list
, instance
->local_pd_list
,
4396 sizeof(instance
->pd_list
));
4401 if (ret
!= DCMD_TIMEOUT
)
4402 megasas_return_cmd(instance
, cmd
);
4408 * megasas_get_ld_list_info - Returns FW's ld_list structure
4409 * @instance: Adapter soft state
4410 * @ld_list: ld_list structure
4412 * Issues an internal command (DCMD) to get the FW's controller PD
4413 * list structure. This information is mainly used to find out SYSTEM
4414 * supported by the FW.
4417 megasas_get_ld_list(struct megasas_instance
*instance
)
4419 int ret
= 0, ld_index
= 0, ids
= 0;
4420 struct megasas_cmd
*cmd
;
4421 struct megasas_dcmd_frame
*dcmd
;
4422 struct MR_LD_LIST
*ci
;
4423 dma_addr_t ci_h
= 0;
4426 ci
= instance
->ld_list_buf
;
4427 ci_h
= instance
->ld_list_buf_h
;
4429 cmd
= megasas_get_cmd(instance
);
4432 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_get_ld_list: Failed to get cmd\n");
4436 dcmd
= &cmd
->frame
->dcmd
;
4438 memset(ci
, 0, sizeof(*ci
));
4439 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4441 if (instance
->supportmax256vd
)
4442 dcmd
->mbox
.b
[0] = 1;
4443 dcmd
->cmd
= MFI_CMD_DCMD
;
4444 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4445 dcmd
->sge_count
= 1;
4446 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4448 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_LD_LIST
));
4449 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_GET_LIST
);
4452 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
4453 sizeof(struct MR_LD_LIST
));
4455 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4456 !instance
->mask_interrupts
)
4457 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
4458 MFI_IO_TIMEOUT_SECS
);
4460 ret
= megasas_issue_polled(instance
, cmd
);
4462 ld_count
= le32_to_cpu(ci
->ldCount
);
4466 megaraid_sas_kill_hba(instance
);
4470 switch (dcmd_timeout_ocr_possible(instance
)) {
4472 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4474 * DCMD failed from AEN path.
4475 * AEN path already hold reset_mutex to avoid PCI access
4476 * while OCR is in progress.
4478 mutex_unlock(&instance
->reset_mutex
);
4479 megasas_reset_fusion(instance
->host
,
4480 MFI_IO_TIMEOUT_OCR
);
4481 mutex_lock(&instance
->reset_mutex
);
4484 megaraid_sas_kill_hba(instance
);
4486 case IGNORE_TIMEOUT
:
4487 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4488 __func__
, __LINE__
);
4495 if (ld_count
> instance
->fw_supported_vd_count
)
4498 memset(instance
->ld_ids
, 0xff, MAX_LOGICAL_DRIVES_EXT
);
4500 for (ld_index
= 0; ld_index
< ld_count
; ld_index
++) {
4501 if (ci
->ldList
[ld_index
].state
!= 0) {
4502 ids
= ci
->ldList
[ld_index
].ref
.targetId
;
4503 instance
->ld_ids
[ids
] = ci
->ldList
[ld_index
].ref
.targetId
;
4510 if (ret
!= DCMD_TIMEOUT
)
4511 megasas_return_cmd(instance
, cmd
);
4517 * megasas_ld_list_query - Returns FW's ld_list structure
4518 * @instance: Adapter soft state
4519 * @ld_list: ld_list structure
4521 * Issues an internal command (DCMD) to get the FW's controller PD
4522 * list structure. This information is mainly used to find out SYSTEM
4523 * supported by the FW.
4526 megasas_ld_list_query(struct megasas_instance
*instance
, u8 query_type
)
4528 int ret
= 0, ld_index
= 0, ids
= 0;
4529 struct megasas_cmd
*cmd
;
4530 struct megasas_dcmd_frame
*dcmd
;
4531 struct MR_LD_TARGETID_LIST
*ci
;
4532 dma_addr_t ci_h
= 0;
4535 ci
= instance
->ld_targetid_list_buf
;
4536 ci_h
= instance
->ld_targetid_list_buf_h
;
4538 cmd
= megasas_get_cmd(instance
);
4541 dev_warn(&instance
->pdev
->dev
,
4542 "megasas_ld_list_query: Failed to get cmd\n");
4546 dcmd
= &cmd
->frame
->dcmd
;
4548 memset(ci
, 0, sizeof(*ci
));
4549 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4551 dcmd
->mbox
.b
[0] = query_type
;
4552 if (instance
->supportmax256vd
)
4553 dcmd
->mbox
.b
[2] = 1;
4555 dcmd
->cmd
= MFI_CMD_DCMD
;
4556 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4557 dcmd
->sge_count
= 1;
4558 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4560 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST
));
4561 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_LIST_QUERY
);
4564 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
4565 sizeof(struct MR_LD_TARGETID_LIST
));
4567 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4568 !instance
->mask_interrupts
)
4569 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
4571 ret
= megasas_issue_polled(instance
, cmd
);
4575 dev_info(&instance
->pdev
->dev
,
4576 "DCMD not supported by firmware - %s %d\n",
4577 __func__
, __LINE__
);
4578 ret
= megasas_get_ld_list(instance
);
4581 switch (dcmd_timeout_ocr_possible(instance
)) {
4583 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4585 * DCMD failed from AEN path.
4586 * AEN path already hold reset_mutex to avoid PCI access
4587 * while OCR is in progress.
4589 mutex_unlock(&instance
->reset_mutex
);
4590 megasas_reset_fusion(instance
->host
,
4591 MFI_IO_TIMEOUT_OCR
);
4592 mutex_lock(&instance
->reset_mutex
);
4595 megaraid_sas_kill_hba(instance
);
4597 case IGNORE_TIMEOUT
:
4598 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4599 __func__
, __LINE__
);
4605 tgtid_count
= le32_to_cpu(ci
->count
);
4607 if ((tgtid_count
> (instance
->fw_supported_vd_count
)))
4610 memset(instance
->ld_ids
, 0xff, MEGASAS_MAX_LD_IDS
);
4611 for (ld_index
= 0; ld_index
< tgtid_count
; ld_index
++) {
4612 ids
= ci
->targetId
[ld_index
];
4613 instance
->ld_ids
[ids
] = ci
->targetId
[ld_index
];
4619 if (ret
!= DCMD_TIMEOUT
)
4620 megasas_return_cmd(instance
, cmd
);
4626 * dcmd.opcode - MR_DCMD_CTRL_DEVICE_LIST_GET
4627 * dcmd.mbox - reserved
4628 * dcmd.sge IN - ptr to return MR_HOST_DEVICE_LIST structure
4629 * Desc: This DCMD will return the combined device list
4630 * Status: MFI_STAT_OK - List returned successfully
4631 * MFI_STAT_INVALID_CMD - Firmware support for the feature has been
4633 * @instance: Adapter soft state
4634 * @is_probe: Driver probe check
4635 * Return: 0 if DCMD succeeded
4636 * non-zero if failed
4639 megasas_host_device_list_query(struct megasas_instance
*instance
,
4642 int ret
, i
, target_id
;
4643 struct megasas_cmd
*cmd
;
4644 struct megasas_dcmd_frame
*dcmd
;
4645 struct MR_HOST_DEVICE_LIST
*ci
;
4649 ci
= instance
->host_device_list_buf
;
4650 ci_h
= instance
->host_device_list_buf_h
;
4652 cmd
= megasas_get_cmd(instance
);
4655 dev_warn(&instance
->pdev
->dev
,
4656 "%s: failed to get cmd\n",
4661 dcmd
= &cmd
->frame
->dcmd
;
4663 memset(ci
, 0, sizeof(*ci
));
4664 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4666 dcmd
->mbox
.b
[0] = is_probe
? 0 : 1;
4667 dcmd
->cmd
= MFI_CMD_DCMD
;
4668 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4669 dcmd
->sge_count
= 1;
4670 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4673 dcmd
->data_xfer_len
= cpu_to_le32(HOST_DEVICE_LIST_SZ
);
4674 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_DEVICE_LIST_GET
);
4676 megasas_set_dma_settings(instance
, dcmd
, ci_h
, HOST_DEVICE_LIST_SZ
);
4678 if (!instance
->mask_interrupts
) {
4679 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
4680 MFI_IO_TIMEOUT_SECS
);
4682 ret
= megasas_issue_polled(instance
, cmd
);
4683 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4688 /* Fill the internal pd_list and ld_ids array based on
4689 * targetIds returned by FW
4691 count
= le32_to_cpu(ci
->count
);
4693 memset(instance
->local_pd_list
, 0,
4694 MEGASAS_MAX_PD
* sizeof(struct megasas_pd_list
));
4695 memset(instance
->ld_ids
, 0xff, MAX_LOGICAL_DRIVES_EXT
);
4696 for (i
= 0; i
< count
; i
++) {
4697 target_id
= le16_to_cpu(ci
->host_device_list
[i
].target_id
);
4698 if (ci
->host_device_list
[i
].flags
.u
.bits
.is_sys_pd
) {
4699 instance
->local_pd_list
[target_id
].tid
= target_id
;
4700 instance
->local_pd_list
[target_id
].driveType
=
4701 ci
->host_device_list
[i
].scsi_type
;
4702 instance
->local_pd_list
[target_id
].driveState
=
4705 instance
->ld_ids
[target_id
] = target_id
;
4709 memcpy(instance
->pd_list
, instance
->local_pd_list
,
4710 sizeof(instance
->pd_list
));
4714 switch (dcmd_timeout_ocr_possible(instance
)) {
4716 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4717 megasas_reset_fusion(instance
->host
,
4718 MFI_IO_TIMEOUT_OCR
);
4721 megaraid_sas_kill_hba(instance
);
4723 case IGNORE_TIMEOUT
:
4724 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4725 __func__
, __LINE__
);
4730 dev_err(&instance
->pdev
->dev
,
4731 "%s: MR_DCMD_CTRL_DEVICE_LIST_GET failed\n",
4736 if (ret
!= DCMD_TIMEOUT
)
4737 megasas_return_cmd(instance
, cmd
);
4743 * megasas_update_ext_vd_details : Update details w.r.t Extended VD
4744 * instance : Controller's instance
4746 static void megasas_update_ext_vd_details(struct megasas_instance
*instance
)
4748 struct fusion_context
*fusion
;
4749 u32 ventura_map_sz
= 0;
4751 fusion
= instance
->ctrl_context
;
4752 /* For MFI based controllers return dummy success */
4756 instance
->supportmax256vd
=
4757 instance
->ctrl_info_buf
->adapterOperations3
.supportMaxExtLDs
;
4758 /* Below is additional check to address future FW enhancement */
4759 if (instance
->ctrl_info_buf
->max_lds
> 64)
4760 instance
->supportmax256vd
= 1;
4762 instance
->drv_supported_vd_count
= MEGASAS_MAX_LD_CHANNELS
4763 * MEGASAS_MAX_DEV_PER_CHANNEL
;
4764 instance
->drv_supported_pd_count
= MEGASAS_MAX_PD_CHANNELS
4765 * MEGASAS_MAX_DEV_PER_CHANNEL
;
4766 if (instance
->supportmax256vd
) {
4767 instance
->fw_supported_vd_count
= MAX_LOGICAL_DRIVES_EXT
;
4768 instance
->fw_supported_pd_count
= MAX_PHYSICAL_DEVICES
;
4770 instance
->fw_supported_vd_count
= MAX_LOGICAL_DRIVES
;
4771 instance
->fw_supported_pd_count
= MAX_PHYSICAL_DEVICES
;
4774 dev_info(&instance
->pdev
->dev
,
4775 "FW provided supportMaxExtLDs: %d\tmax_lds: %d\n",
4776 instance
->ctrl_info_buf
->adapterOperations3
.supportMaxExtLDs
? 1 : 0,
4777 instance
->ctrl_info_buf
->max_lds
);
4779 if (instance
->max_raid_mapsize
) {
4780 ventura_map_sz
= instance
->max_raid_mapsize
*
4781 MR_MIN_MAP_SIZE
; /* 64k */
4782 fusion
->current_map_sz
= ventura_map_sz
;
4783 fusion
->max_map_sz
= ventura_map_sz
;
4785 fusion
->old_map_sz
= sizeof(struct MR_FW_RAID_MAP
) +
4786 (sizeof(struct MR_LD_SPAN_MAP
) *
4787 (instance
->fw_supported_vd_count
- 1));
4788 fusion
->new_map_sz
= sizeof(struct MR_FW_RAID_MAP_EXT
);
4790 fusion
->max_map_sz
=
4791 max(fusion
->old_map_sz
, fusion
->new_map_sz
);
4793 if (instance
->supportmax256vd
)
4794 fusion
->current_map_sz
= fusion
->new_map_sz
;
4796 fusion
->current_map_sz
= fusion
->old_map_sz
;
4798 /* irrespective of FW raid maps, driver raid map is constant */
4799 fusion
->drv_map_sz
= sizeof(struct MR_DRV_RAID_MAP_ALL
);
4803 * dcmd.opcode - MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES
4804 * dcmd.hdr.length - number of bytes to read
4805 * dcmd.sge - Ptr to MR_SNAPDUMP_PROPERTIES
4806 * Desc: Fill in snapdump properties
4807 * Status: MFI_STAT_OK- Command successful
4809 void megasas_get_snapdump_properties(struct megasas_instance
*instance
)
4812 struct megasas_cmd
*cmd
;
4813 struct megasas_dcmd_frame
*dcmd
;
4814 struct MR_SNAPDUMP_PROPERTIES
*ci
;
4815 dma_addr_t ci_h
= 0;
4817 ci
= instance
->snapdump_prop
;
4818 ci_h
= instance
->snapdump_prop_h
;
4823 cmd
= megasas_get_cmd(instance
);
4826 dev_dbg(&instance
->pdev
->dev
, "Failed to get a free cmd\n");
4830 dcmd
= &cmd
->frame
->dcmd
;
4832 memset(ci
, 0, sizeof(*ci
));
4833 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4835 dcmd
->cmd
= MFI_CMD_DCMD
;
4836 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4837 dcmd
->sge_count
= 1;
4838 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4841 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_SNAPDUMP_PROPERTIES
));
4842 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES
);
4844 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
4845 sizeof(struct MR_SNAPDUMP_PROPERTIES
));
4847 if (!instance
->mask_interrupts
) {
4848 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
4849 MFI_IO_TIMEOUT_SECS
);
4851 ret
= megasas_issue_polled(instance
, cmd
);
4852 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4857 instance
->snapdump_wait_time
=
4858 min_t(u8
, ci
->trigger_min_num_sec_before_ocr
,
4859 MEGASAS_MAX_SNAP_DUMP_WAIT_TIME
);
4863 switch (dcmd_timeout_ocr_possible(instance
)) {
4865 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4866 megasas_reset_fusion(instance
->host
,
4867 MFI_IO_TIMEOUT_OCR
);
4870 megaraid_sas_kill_hba(instance
);
4872 case IGNORE_TIMEOUT
:
4873 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4874 __func__
, __LINE__
);
4879 if (ret
!= DCMD_TIMEOUT
)
4880 megasas_return_cmd(instance
, cmd
);
4884 * megasas_get_controller_info - Returns FW's controller structure
4885 * @instance: Adapter soft state
4887 * Issues an internal command (DCMD) to get the FW's controller structure.
4888 * This information is mainly used to find out the maximum IO transfer per
4889 * command supported by the FW.
4892 megasas_get_ctrl_info(struct megasas_instance
*instance
)
4895 struct megasas_cmd
*cmd
;
4896 struct megasas_dcmd_frame
*dcmd
;
4897 struct megasas_ctrl_info
*ci
;
4898 dma_addr_t ci_h
= 0;
4900 ci
= instance
->ctrl_info_buf
;
4901 ci_h
= instance
->ctrl_info_buf_h
;
4903 cmd
= megasas_get_cmd(instance
);
4906 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get a free cmd\n");
4910 dcmd
= &cmd
->frame
->dcmd
;
4912 memset(ci
, 0, sizeof(*ci
));
4913 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4915 dcmd
->cmd
= MFI_CMD_DCMD
;
4916 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4917 dcmd
->sge_count
= 1;
4918 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4921 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_ctrl_info
));
4922 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_GET_INFO
);
4923 dcmd
->mbox
.b
[0] = 1;
4925 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
4926 sizeof(struct megasas_ctrl_info
));
4928 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4929 !instance
->mask_interrupts
) {
4930 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
4932 ret
= megasas_issue_polled(instance
, cmd
);
4933 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4938 /* Save required controller information in
4939 * CPU endianness format.
4941 le32_to_cpus((u32
*)&ci
->properties
.OnOffProperties
);
4942 le16_to_cpus((u16
*)&ci
->properties
.on_off_properties2
);
4943 le32_to_cpus((u32
*)&ci
->adapterOperations2
);
4944 le32_to_cpus((u32
*)&ci
->adapterOperations3
);
4945 le16_to_cpus((u16
*)&ci
->adapter_operations4
);
4947 /* Update the latest Ext VD info.
4948 * From Init path, store current firmware details.
4949 * From OCR path, detect any firmware properties changes.
4950 * in case of Firmware upgrade without system reboot.
4952 megasas_update_ext_vd_details(instance
);
4953 instance
->use_seqnum_jbod_fp
=
4954 ci
->adapterOperations3
.useSeqNumJbodFP
;
4955 instance
->support_morethan256jbod
=
4956 ci
->adapter_operations4
.support_pd_map_target_id
;
4957 instance
->support_nvme_passthru
=
4958 ci
->adapter_operations4
.support_nvme_passthru
;
4959 instance
->task_abort_tmo
= ci
->TaskAbortTO
;
4960 instance
->max_reset_tmo
= ci
->MaxResetTO
;
4962 /*Check whether controller is iMR or MR */
4963 instance
->is_imr
= (ci
->memory_size
? 0 : 1);
4965 instance
->snapdump_wait_time
=
4966 (ci
->properties
.on_off_properties2
.enable_snap_dump
?
4967 MEGASAS_DEFAULT_SNAP_DUMP_WAIT_TIME
: 0);
4969 instance
->enable_fw_dev_list
=
4970 ci
->properties
.on_off_properties2
.enable_fw_dev_list
;
4972 dev_info(&instance
->pdev
->dev
,
4973 "controller type\t: %s(%dMB)\n",
4974 instance
->is_imr
? "iMR" : "MR",
4975 le16_to_cpu(ci
->memory_size
));
4977 instance
->disableOnlineCtrlReset
=
4978 ci
->properties
.OnOffProperties
.disableOnlineCtrlReset
;
4979 instance
->secure_jbod_support
=
4980 ci
->adapterOperations3
.supportSecurityonJBOD
;
4981 dev_info(&instance
->pdev
->dev
, "Online Controller Reset(OCR)\t: %s\n",
4982 instance
->disableOnlineCtrlReset
? "Disabled" : "Enabled");
4983 dev_info(&instance
->pdev
->dev
, "Secure JBOD support\t: %s\n",
4984 instance
->secure_jbod_support
? "Yes" : "No");
4985 dev_info(&instance
->pdev
->dev
, "NVMe passthru support\t: %s\n",
4986 instance
->support_nvme_passthru
? "Yes" : "No");
4987 dev_info(&instance
->pdev
->dev
,
4988 "FW provided TM TaskAbort/Reset timeout\t: %d secs/%d secs\n",
4989 instance
->task_abort_tmo
, instance
->max_reset_tmo
);
4994 switch (dcmd_timeout_ocr_possible(instance
)) {
4996 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4997 megasas_reset_fusion(instance
->host
,
4998 MFI_IO_TIMEOUT_OCR
);
5001 megaraid_sas_kill_hba(instance
);
5003 case IGNORE_TIMEOUT
:
5004 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
5005 __func__
, __LINE__
);
5010 megaraid_sas_kill_hba(instance
);
5015 if (ret
!= DCMD_TIMEOUT
)
5016 megasas_return_cmd(instance
, cmd
);
5022 * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer
5025 * @instance: Adapter soft state
5026 * @crash_buf_state - tell FW to turn ON/OFF crash dump feature
5027 MR_CRASH_BUF_TURN_OFF = 0
5028 MR_CRASH_BUF_TURN_ON = 1
5029 * @return 0 on success non-zero on failure.
5030 * Issues an internal command (DCMD) to set parameters for crash dump feature.
5031 * Driver will send address of crash dump DMA buffer and set mbox to tell FW
5032 * that driver supports crash dump feature. This DCMD will be sent only if
5033 * crash dump feature is supported by the FW.
5036 int megasas_set_crash_dump_params(struct megasas_instance
*instance
,
5040 struct megasas_cmd
*cmd
;
5041 struct megasas_dcmd_frame
*dcmd
;
5043 cmd
= megasas_get_cmd(instance
);
5046 dev_err(&instance
->pdev
->dev
, "Failed to get a free cmd\n");
5051 dcmd
= &cmd
->frame
->dcmd
;
5053 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
5054 dcmd
->mbox
.b
[0] = crash_buf_state
;
5055 dcmd
->cmd
= MFI_CMD_DCMD
;
5056 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
5057 dcmd
->sge_count
= 1;
5058 dcmd
->flags
= MFI_FRAME_DIR_NONE
;
5061 dcmd
->data_xfer_len
= cpu_to_le32(CRASH_DMA_BUF_SIZE
);
5062 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS
);
5064 megasas_set_dma_settings(instance
, dcmd
, instance
->crash_dump_h
,
5065 CRASH_DMA_BUF_SIZE
);
5067 if ((instance
->adapter_type
!= MFI_SERIES
) &&
5068 !instance
->mask_interrupts
)
5069 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
5071 ret
= megasas_issue_polled(instance
, cmd
);
5073 if (ret
== DCMD_TIMEOUT
) {
5074 switch (dcmd_timeout_ocr_possible(instance
)) {
5076 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
5077 megasas_reset_fusion(instance
->host
,
5078 MFI_IO_TIMEOUT_OCR
);
5081 megaraid_sas_kill_hba(instance
);
5083 case IGNORE_TIMEOUT
:
5084 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
5085 __func__
, __LINE__
);
5089 megasas_return_cmd(instance
, cmd
);
5095 * megasas_issue_init_mfi - Initializes the FW
5096 * @instance: Adapter soft state
5098 * Issues the INIT MFI cmd
5101 megasas_issue_init_mfi(struct megasas_instance
*instance
)
5104 struct megasas_cmd
*cmd
;
5105 struct megasas_init_frame
*init_frame
;
5106 struct megasas_init_queue_info
*initq_info
;
5107 dma_addr_t init_frame_h
;
5108 dma_addr_t initq_info_h
;
5111 * Prepare a init frame. Note the init frame points to queue info
5112 * structure. Each frame has SGL allocated after first 64 bytes. For
5113 * this frame - since we don't need any SGL - we use SGL's space as
5114 * queue info structure
5116 * We will not get a NULL command below. We just created the pool.
5118 cmd
= megasas_get_cmd(instance
);
5120 init_frame
= (struct megasas_init_frame
*)cmd
->frame
;
5121 initq_info
= (struct megasas_init_queue_info
*)
5122 ((unsigned long)init_frame
+ 64);
5124 init_frame_h
= cmd
->frame_phys_addr
;
5125 initq_info_h
= init_frame_h
+ 64;
5127 context
= init_frame
->context
;
5128 memset(init_frame
, 0, MEGAMFI_FRAME_SIZE
);
5129 memset(initq_info
, 0, sizeof(struct megasas_init_queue_info
));
5130 init_frame
->context
= context
;
5132 initq_info
->reply_queue_entries
= cpu_to_le32(instance
->max_fw_cmds
+ 1);
5133 initq_info
->reply_queue_start_phys_addr_lo
= cpu_to_le32(instance
->reply_queue_h
);
5135 initq_info
->producer_index_phys_addr_lo
= cpu_to_le32(instance
->producer_h
);
5136 initq_info
->consumer_index_phys_addr_lo
= cpu_to_le32(instance
->consumer_h
);
5138 init_frame
->cmd
= MFI_CMD_INIT
;
5139 init_frame
->cmd_status
= MFI_STAT_INVALID_STATUS
;
5140 init_frame
->queue_info_new_phys_addr_lo
=
5141 cpu_to_le32(lower_32_bits(initq_info_h
));
5142 init_frame
->queue_info_new_phys_addr_hi
=
5143 cpu_to_le32(upper_32_bits(initq_info_h
));
5145 init_frame
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_init_queue_info
));
5148 * disable the intr before firing the init frame to FW
5150 instance
->instancet
->disable_intr(instance
);
5153 * Issue the init frame in polled mode
5156 if (megasas_issue_polled(instance
, cmd
)) {
5157 dev_err(&instance
->pdev
->dev
, "Failed to init firmware\n");
5158 megasas_return_cmd(instance
, cmd
);
5162 megasas_return_cmd(instance
, cmd
);
5171 megasas_init_adapter_mfi(struct megasas_instance
*instance
)
5177 * Get various operational parameters from status register
5179 instance
->max_fw_cmds
= instance
->instancet
->read_fw_status_reg(instance
) & 0x00FFFF;
5181 * Reduce the max supported cmds by 1. This is to ensure that the
5182 * reply_q_sz (1 more than the max cmd that driver may send)
5183 * does not exceed max cmds that the FW can support
5185 instance
->max_fw_cmds
= instance
->max_fw_cmds
-1;
5186 instance
->max_mfi_cmds
= instance
->max_fw_cmds
;
5187 instance
->max_num_sge
= (instance
->instancet
->read_fw_status_reg(instance
) & 0xFF0000) >>
5190 * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands
5191 * are reserved for IOCTL + driver's internal DCMDs.
5193 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
5194 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0071SKINNY
)) {
5195 instance
->max_scsi_cmds
= (instance
->max_fw_cmds
-
5196 MEGASAS_SKINNY_INT_CMDS
);
5197 sema_init(&instance
->ioctl_sem
, MEGASAS_SKINNY_INT_CMDS
);
5199 instance
->max_scsi_cmds
= (instance
->max_fw_cmds
-
5201 sema_init(&instance
->ioctl_sem
, (MEGASAS_MFI_IOCTL_CMDS
));
5204 instance
->cur_can_queue
= instance
->max_scsi_cmds
;
5206 * Create a pool of commands
5208 if (megasas_alloc_cmds(instance
))
5209 goto fail_alloc_cmds
;
5212 * Allocate memory for reply queue. Length of reply queue should
5213 * be _one_ more than the maximum commands handled by the firmware.
5215 * Note: When FW completes commands, it places corresponding contex
5216 * values in this circular reply queue. This circular queue is a fairly
5217 * typical producer-consumer queue. FW is the producer (of completed
5218 * commands) and the driver is the consumer.
5220 context_sz
= sizeof(u32
);
5221 reply_q_sz
= context_sz
* (instance
->max_fw_cmds
+ 1);
5223 instance
->reply_queue
= dma_alloc_coherent(&instance
->pdev
->dev
,
5224 reply_q_sz
, &instance
->reply_queue_h
, GFP_KERNEL
);
5226 if (!instance
->reply_queue
) {
5227 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Out of DMA mem for reply queue\n");
5228 goto fail_reply_queue
;
5231 if (megasas_issue_init_mfi(instance
))
5234 if (megasas_get_ctrl_info(instance
)) {
5235 dev_err(&instance
->pdev
->dev
, "(%d): Could get controller info "
5236 "Fail from %s %d\n", instance
->unique_id
,
5237 __func__
, __LINE__
);
5241 instance
->fw_support_ieee
= 0;
5242 instance
->fw_support_ieee
=
5243 (instance
->instancet
->read_fw_status_reg(instance
) &
5246 dev_notice(&instance
->pdev
->dev
, "megasas_init_mfi: fw_support_ieee=%d",
5247 instance
->fw_support_ieee
);
5249 if (instance
->fw_support_ieee
)
5250 instance
->flag_ieee
= 1;
5256 dma_free_coherent(&instance
->pdev
->dev
, reply_q_sz
,
5257 instance
->reply_queue
, instance
->reply_queue_h
);
5259 megasas_free_cmds(instance
);
5266 * megasas_setup_irqs_ioapic - register legacy interrupts.
5267 * @instance: Adapter soft state
5269 * Do not enable interrupt, only setup ISRs.
5271 * Return 0 on success.
5274 megasas_setup_irqs_ioapic(struct megasas_instance
*instance
)
5276 struct pci_dev
*pdev
;
5278 pdev
= instance
->pdev
;
5279 instance
->irq_context
[0].instance
= instance
;
5280 instance
->irq_context
[0].MSIxIndex
= 0;
5281 if (request_irq(pci_irq_vector(pdev
, 0),
5282 instance
->instancet
->service_isr
, IRQF_SHARED
,
5283 "megasas", &instance
->irq_context
[0])) {
5284 dev_err(&instance
->pdev
->dev
,
5285 "Failed to register IRQ from %s %d\n",
5286 __func__
, __LINE__
);
5293 * megasas_setup_irqs_msix - register MSI-x interrupts.
5294 * @instance: Adapter soft state
5295 * @is_probe: Driver probe check
5297 * Do not enable interrupt, only setup ISRs.
5299 * Return 0 on success.
5302 megasas_setup_irqs_msix(struct megasas_instance
*instance
, u8 is_probe
)
5305 struct pci_dev
*pdev
;
5307 pdev
= instance
->pdev
;
5310 for (i
= 0; i
< instance
->msix_vectors
; i
++) {
5311 instance
->irq_context
[i
].instance
= instance
;
5312 instance
->irq_context
[i
].MSIxIndex
= i
;
5313 if (request_irq(pci_irq_vector(pdev
, i
),
5314 instance
->instancet
->service_isr
, 0, "megasas",
5315 &instance
->irq_context
[i
])) {
5316 dev_err(&instance
->pdev
->dev
,
5317 "Failed to register IRQ for vector %d.\n", i
);
5318 for (j
= 0; j
< i
; j
++)
5319 free_irq(pci_irq_vector(pdev
, j
),
5320 &instance
->irq_context
[j
]);
5321 /* Retry irq register for IO_APIC*/
5322 instance
->msix_vectors
= 0;
5324 pci_free_irq_vectors(instance
->pdev
);
5325 return megasas_setup_irqs_ioapic(instance
);
5335 * megasas_destroy_irqs- unregister interrupts.
5336 * @instance: Adapter soft state
5340 megasas_destroy_irqs(struct megasas_instance
*instance
) {
5344 if (instance
->msix_vectors
)
5345 for (i
= 0; i
< instance
->msix_vectors
; i
++) {
5346 free_irq(pci_irq_vector(instance
->pdev
, i
),
5347 &instance
->irq_context
[i
]);
5350 free_irq(pci_irq_vector(instance
->pdev
, 0),
5351 &instance
->irq_context
[0]);
5355 * megasas_setup_jbod_map - setup jbod map for FP seq_number.
5356 * @instance: Adapter soft state
5357 * @is_probe: Driver probe check
5359 * Return 0 on success.
5362 megasas_setup_jbod_map(struct megasas_instance
*instance
)
5365 struct fusion_context
*fusion
= instance
->ctrl_context
;
5368 pd_seq_map_sz
= sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC
) +
5369 (sizeof(struct MR_PD_CFG_SEQ
) * (MAX_PHYSICAL_DEVICES
- 1));
5371 if (reset_devices
|| !fusion
||
5372 !instance
->ctrl_info_buf
->adapterOperations3
.useSeqNumJbodFP
) {
5373 dev_info(&instance
->pdev
->dev
,
5374 "Jbod map is not supported %s %d\n",
5375 __func__
, __LINE__
);
5376 instance
->use_seqnum_jbod_fp
= false;
5380 if (fusion
->pd_seq_sync
[0])
5383 for (i
= 0; i
< JBOD_MAPS_COUNT
; i
++) {
5384 fusion
->pd_seq_sync
[i
] = dma_alloc_coherent
5385 (&instance
->pdev
->dev
, pd_seq_map_sz
,
5386 &fusion
->pd_seq_phys
[i
], GFP_KERNEL
);
5387 if (!fusion
->pd_seq_sync
[i
]) {
5388 dev_err(&instance
->pdev
->dev
,
5389 "Failed to allocate memory from %s %d\n",
5390 __func__
, __LINE__
);
5392 dma_free_coherent(&instance
->pdev
->dev
,
5393 pd_seq_map_sz
, fusion
->pd_seq_sync
[0],
5394 fusion
->pd_seq_phys
[0]);
5395 fusion
->pd_seq_sync
[0] = NULL
;
5397 instance
->use_seqnum_jbod_fp
= false;
5403 if (!megasas_sync_pd_seq_num(instance
, false) &&
5404 !megasas_sync_pd_seq_num(instance
, true))
5405 instance
->use_seqnum_jbod_fp
= true;
5407 instance
->use_seqnum_jbod_fp
= false;
5410 static void megasas_setup_reply_map(struct megasas_instance
*instance
)
5412 const struct cpumask
*mask
;
5413 unsigned int queue
, cpu
;
5415 for (queue
= 0; queue
< instance
->msix_vectors
; queue
++) {
5416 mask
= pci_irq_get_affinity(instance
->pdev
, queue
);
5420 for_each_cpu(cpu
, mask
)
5421 instance
->reply_map
[cpu
] = queue
;
5426 for_each_possible_cpu(cpu
)
5427 instance
->reply_map
[cpu
] = cpu
% instance
->msix_vectors
;
5431 * megasas_get_device_list - Get the PD and LD device list from FW.
5432 * @instance: Adapter soft state
5433 * @return: Success or failure
5435 * Issue DCMDs to Firmware to get the PD and LD list.
5436 * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
5437 * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
5440 int megasas_get_device_list(struct megasas_instance
*instance
)
5442 memset(instance
->pd_list
, 0,
5443 (MEGASAS_MAX_PD
* sizeof(struct megasas_pd_list
)));
5444 memset(instance
->ld_ids
, 0xff, MEGASAS_MAX_LD_IDS
);
5446 if (instance
->enable_fw_dev_list
) {
5447 if (megasas_host_device_list_query(instance
, true))
5450 if (megasas_get_pd_list(instance
) < 0) {
5451 dev_err(&instance
->pdev
->dev
, "failed to get PD list\n");
5455 if (megasas_ld_list_query(instance
,
5456 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST
)) {
5457 dev_err(&instance
->pdev
->dev
, "failed to get LD list\n");
5465 * megasas_init_fw - Initializes the FW
5466 * @instance: Adapter soft state
5468 * This is the main function for initializing firmware
5471 static int megasas_init_fw(struct megasas_instance
*instance
)
5474 u32 max_sectors_2
, tmp_sectors
, msix_enable
;
5475 u32 scratch_pad_1
, scratch_pad_2
, scratch_pad_3
, status_reg
;
5476 resource_size_t base_addr
;
5477 struct megasas_ctrl_info
*ctrl_info
= NULL
;
5478 unsigned long bar_list
;
5479 int i
, j
, loop
, fw_msix_count
= 0;
5480 struct IOV_111
*iovPtr
;
5481 struct fusion_context
*fusion
;
5482 bool do_adp_reset
= true;
5484 fusion
= instance
->ctrl_context
;
5486 /* Find first memory bar */
5487 bar_list
= pci_select_bars(instance
->pdev
, IORESOURCE_MEM
);
5488 instance
->bar
= find_first_bit(&bar_list
, BITS_PER_LONG
);
5489 if (pci_request_selected_regions(instance
->pdev
, 1<<instance
->bar
,
5491 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "IO memory region busy!\n");
5495 base_addr
= pci_resource_start(instance
->pdev
, instance
->bar
);
5496 instance
->reg_set
= ioremap_nocache(base_addr
, 8192);
5498 if (!instance
->reg_set
) {
5499 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to map IO mem\n");
5503 if (instance
->adapter_type
!= MFI_SERIES
)
5504 instance
->instancet
= &megasas_instance_template_fusion
;
5506 switch (instance
->pdev
->device
) {
5507 case PCI_DEVICE_ID_LSI_SAS1078R
:
5508 case PCI_DEVICE_ID_LSI_SAS1078DE
:
5509 instance
->instancet
= &megasas_instance_template_ppc
;
5511 case PCI_DEVICE_ID_LSI_SAS1078GEN2
:
5512 case PCI_DEVICE_ID_LSI_SAS0079GEN2
:
5513 instance
->instancet
= &megasas_instance_template_gen2
;
5515 case PCI_DEVICE_ID_LSI_SAS0073SKINNY
:
5516 case PCI_DEVICE_ID_LSI_SAS0071SKINNY
:
5517 instance
->instancet
= &megasas_instance_template_skinny
;
5519 case PCI_DEVICE_ID_LSI_SAS1064R
:
5520 case PCI_DEVICE_ID_DELL_PERC5
:
5522 instance
->instancet
= &megasas_instance_template_xscale
;
5523 instance
->pd_list_not_supported
= 1;
5528 if (megasas_transition_to_ready(instance
, 0)) {
5529 if (instance
->adapter_type
>= INVADER_SERIES
) {
5530 status_reg
= instance
->instancet
->read_fw_status_reg(
5532 do_adp_reset
= status_reg
& MFI_RESET_ADAPTER
;
5536 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
5537 instance
->instancet
->adp_reset
5538 (instance
, instance
->reg_set
);
5539 atomic_set(&instance
->fw_reset_no_pci_access
, 0);
5540 dev_info(&instance
->pdev
->dev
,
5541 "FW restarted successfully from %s!\n",
5544 /*waiting for about 30 second before retry*/
5547 if (megasas_transition_to_ready(instance
, 0))
5548 goto fail_ready_state
;
5550 goto fail_ready_state
;
5554 megasas_init_ctrl_params(instance
);
5556 if (megasas_set_dma_mask(instance
))
5557 goto fail_ready_state
;
5559 if (megasas_alloc_ctrl_mem(instance
))
5560 goto fail_alloc_dma_buf
;
5562 if (megasas_alloc_ctrl_dma_buffers(instance
))
5563 goto fail_alloc_dma_buf
;
5565 fusion
= instance
->ctrl_context
;
5567 if (instance
->adapter_type
>= VENTURA_SERIES
) {
5569 megasas_readl(instance
,
5570 &instance
->reg_set
->outbound_scratch_pad_2
);
5571 instance
->max_raid_mapsize
= ((scratch_pad_2
>>
5572 MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT
) &
5573 MR_MAX_RAID_MAP_SIZE_MASK
);
5576 /* Check if MSI-X is supported while in ready state */
5577 msix_enable
= (instance
->instancet
->read_fw_status_reg(instance
) &
5579 if (msix_enable
&& !msix_disable
) {
5580 int irq_flags
= PCI_IRQ_MSIX
;
5582 scratch_pad_1
= megasas_readl
5583 (instance
, &instance
->reg_set
->outbound_scratch_pad_1
);
5584 /* Check max MSI-X vectors */
5586 if (instance
->adapter_type
== THUNDERBOLT_SERIES
) {
5587 /* Thunderbolt Series*/
5588 instance
->msix_vectors
= (scratch_pad_1
5589 & MR_MAX_REPLY_QUEUES_OFFSET
) + 1;
5590 fw_msix_count
= instance
->msix_vectors
;
5592 instance
->msix_vectors
= ((scratch_pad_1
5593 & MR_MAX_REPLY_QUEUES_EXT_OFFSET
)
5594 >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT
) + 1;
5597 * For Invader series, > 8 MSI-x vectors
5598 * supported by FW/HW implies combined
5599 * reply queue mode is enabled.
5600 * For Ventura series, > 16 MSI-x vectors
5601 * supported by FW/HW implies combined
5602 * reply queue mode is enabled.
5604 switch (instance
->adapter_type
) {
5605 case INVADER_SERIES
:
5606 if (instance
->msix_vectors
> 8)
5607 instance
->msix_combined
= true;
5610 case VENTURA_SERIES
:
5611 if (instance
->msix_vectors
> 16)
5612 instance
->msix_combined
= true;
5617 instance
->is_rdpq
= (scratch_pad_1
& MR_RDPQ_MODE_OFFSET
) ?
5619 fw_msix_count
= instance
->msix_vectors
;
5620 /* Save 1-15 reply post index address to local memory
5621 * Index 0 is already saved from reg offset
5622 * MPI2_REPLY_POST_HOST_INDEX_OFFSET
5624 for (loop
= 1; loop
< MR_MAX_MSIX_REG_ARRAY
; loop
++) {
5625 instance
->reply_post_host_index_addr
[loop
] =
5627 ((u8 __iomem
*)instance
->reg_set
+
5628 MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET
5633 instance
->msix_vectors
= min(msix_vectors
,
5634 instance
->msix_vectors
);
5635 } else /* MFI adapters */
5636 instance
->msix_vectors
= 1;
5637 /* Don't bother allocating more MSI-X vectors than cpus */
5638 instance
->msix_vectors
= min(instance
->msix_vectors
,
5639 (unsigned int)num_online_cpus());
5640 if (smp_affinity_enable
)
5641 irq_flags
|= PCI_IRQ_AFFINITY
;
5642 i
= pci_alloc_irq_vectors(instance
->pdev
, 1,
5643 instance
->msix_vectors
, irq_flags
);
5645 instance
->msix_vectors
= i
;
5647 instance
->msix_vectors
= 0;
5650 * MSI-X host index 0 is common for all adapter.
5651 * It is used for all MPT based Adapters.
5653 if (instance
->msix_combined
) {
5654 instance
->reply_post_host_index_addr
[0] =
5655 (u32
*)((u8
*)instance
->reg_set
+
5656 MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET
);
5658 instance
->reply_post_host_index_addr
[0] =
5659 (u32
*)((u8
*)instance
->reg_set
+
5660 MPI2_REPLY_POST_HOST_INDEX_OFFSET
);
5663 if (!instance
->msix_vectors
) {
5664 i
= pci_alloc_irq_vectors(instance
->pdev
, 1, 1, PCI_IRQ_LEGACY
);
5666 goto fail_init_adapter
;
5669 megasas_setup_reply_map(instance
);
5671 dev_info(&instance
->pdev
->dev
,
5672 "firmware supports msix\t: (%d)", fw_msix_count
);
5673 dev_info(&instance
->pdev
->dev
,
5674 "current msix/online cpus\t: (%d/%d)\n",
5675 instance
->msix_vectors
, (unsigned int)num_online_cpus());
5676 dev_info(&instance
->pdev
->dev
,
5677 "RDPQ mode\t: (%s)\n", instance
->is_rdpq
? "enabled" : "disabled");
5679 tasklet_init(&instance
->isr_tasklet
, instance
->instancet
->tasklet
,
5680 (unsigned long)instance
);
5683 * Below are default value for legacy Firmware.
5684 * non-fusion based controllers
5686 instance
->fw_supported_vd_count
= MAX_LOGICAL_DRIVES
;
5687 instance
->fw_supported_pd_count
= MAX_PHYSICAL_DEVICES
;
5688 /* Get operational params, sge flags, send init cmd to controller */
5689 if (instance
->instancet
->init_adapter(instance
))
5690 goto fail_init_adapter
;
5692 if (instance
->adapter_type
>= VENTURA_SERIES
) {
5694 megasas_readl(instance
,
5695 &instance
->reg_set
->outbound_scratch_pad_3
);
5696 if ((scratch_pad_3
& MR_NVME_PAGE_SIZE_MASK
) >=
5697 MR_DEFAULT_NVME_PAGE_SHIFT
)
5698 instance
->nvme_page_size
=
5699 (1 << (scratch_pad_3
& MR_NVME_PAGE_SIZE_MASK
));
5701 dev_info(&instance
->pdev
->dev
,
5702 "NVME page size\t: (%d)\n", instance
->nvme_page_size
);
5705 if (instance
->msix_vectors
?
5706 megasas_setup_irqs_msix(instance
, 1) :
5707 megasas_setup_irqs_ioapic(instance
))
5708 goto fail_init_adapter
;
5710 instance
->instancet
->enable_intr(instance
);
5712 dev_info(&instance
->pdev
->dev
, "INIT adapter done\n");
5714 megasas_setup_jbod_map(instance
);
5716 if (megasas_get_device_list(instance
) != SUCCESS
) {
5717 dev_err(&instance
->pdev
->dev
,
5718 "%s: megasas_get_device_list failed\n",
5720 goto fail_get_ld_pd_list
;
5723 /* stream detection initialization */
5724 if (instance
->adapter_type
>= VENTURA_SERIES
) {
5725 fusion
->stream_detect_by_ld
=
5726 kcalloc(MAX_LOGICAL_DRIVES_EXT
,
5727 sizeof(struct LD_STREAM_DETECT
*),
5729 if (!fusion
->stream_detect_by_ld
) {
5730 dev_err(&instance
->pdev
->dev
,
5731 "unable to allocate stream detection for pool of LDs\n");
5732 goto fail_get_ld_pd_list
;
5734 for (i
= 0; i
< MAX_LOGICAL_DRIVES_EXT
; ++i
) {
5735 fusion
->stream_detect_by_ld
[i
] =
5736 kzalloc(sizeof(struct LD_STREAM_DETECT
),
5738 if (!fusion
->stream_detect_by_ld
[i
]) {
5739 dev_err(&instance
->pdev
->dev
,
5740 "unable to allocate stream detect by LD\n ");
5741 for (j
= 0; j
< i
; ++j
)
5742 kfree(fusion
->stream_detect_by_ld
[j
]);
5743 kfree(fusion
->stream_detect_by_ld
);
5744 fusion
->stream_detect_by_ld
= NULL
;
5745 goto fail_get_ld_pd_list
;
5747 fusion
->stream_detect_by_ld
[i
]->mru_bit_map
5753 * Compute the max allowed sectors per IO: The controller info has two
5754 * limits on max sectors. Driver should use the minimum of these two.
5756 * 1 << stripe_sz_ops.min = max sectors per strip
5758 * Note that older firmwares ( < FW ver 30) didn't report information
5759 * to calculate max_sectors_1. So the number ended up as zero always.
5762 ctrl_info
= instance
->ctrl_info_buf
;
5764 max_sectors_1
= (1 << ctrl_info
->stripe_sz_ops
.min
) *
5765 le16_to_cpu(ctrl_info
->max_strips_per_io
);
5766 max_sectors_2
= le32_to_cpu(ctrl_info
->max_request_size
);
5768 tmp_sectors
= min_t(u32
, max_sectors_1
, max_sectors_2
);
5770 instance
->peerIsPresent
= ctrl_info
->cluster
.peerIsPresent
;
5771 instance
->passive
= ctrl_info
->cluster
.passive
;
5772 memcpy(instance
->clusterId
, ctrl_info
->clusterId
, sizeof(instance
->clusterId
));
5773 instance
->UnevenSpanSupport
=
5774 ctrl_info
->adapterOperations2
.supportUnevenSpans
;
5775 if (instance
->UnevenSpanSupport
) {
5776 struct fusion_context
*fusion
= instance
->ctrl_context
;
5777 if (MR_ValidateMapInfo(instance
, instance
->map_id
))
5778 fusion
->fast_path_io
= 1;
5780 fusion
->fast_path_io
= 0;
5783 if (ctrl_info
->host_interface
.SRIOV
) {
5784 instance
->requestorId
= ctrl_info
->iov
.requestorId
;
5785 if (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_PLASMA
) {
5786 if (!ctrl_info
->adapterOperations2
.activePassive
)
5787 instance
->PlasmaFW111
= 1;
5789 dev_info(&instance
->pdev
->dev
, "SR-IOV: firmware type: %s\n",
5790 instance
->PlasmaFW111
? "1.11" : "new");
5792 if (instance
->PlasmaFW111
) {
5793 iovPtr
= (struct IOV_111
*)
5794 ((unsigned char *)ctrl_info
+ IOV_111_OFFSET
);
5795 instance
->requestorId
= iovPtr
->requestorId
;
5798 dev_info(&instance
->pdev
->dev
, "SRIOV: VF requestorId %d\n",
5799 instance
->requestorId
);
5802 instance
->crash_dump_fw_support
=
5803 ctrl_info
->adapterOperations3
.supportCrashDump
;
5804 instance
->crash_dump_drv_support
=
5805 (instance
->crash_dump_fw_support
&&
5806 instance
->crash_dump_buf
);
5807 if (instance
->crash_dump_drv_support
)
5808 megasas_set_crash_dump_params(instance
,
5809 MR_CRASH_BUF_TURN_OFF
);
5812 if (instance
->crash_dump_buf
)
5813 dma_free_coherent(&instance
->pdev
->dev
,
5815 instance
->crash_dump_buf
,
5816 instance
->crash_dump_h
);
5817 instance
->crash_dump_buf
= NULL
;
5820 if (instance
->snapdump_wait_time
) {
5821 megasas_get_snapdump_properties(instance
);
5822 dev_info(&instance
->pdev
->dev
, "Snap dump wait time\t: %d\n",
5823 instance
->snapdump_wait_time
);
5826 dev_info(&instance
->pdev
->dev
,
5827 "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n",
5828 le16_to_cpu(ctrl_info
->pci
.vendor_id
),
5829 le16_to_cpu(ctrl_info
->pci
.device_id
),
5830 le16_to_cpu(ctrl_info
->pci
.sub_vendor_id
),
5831 le16_to_cpu(ctrl_info
->pci
.sub_device_id
));
5832 dev_info(&instance
->pdev
->dev
, "unevenspan support : %s\n",
5833 instance
->UnevenSpanSupport
? "yes" : "no");
5834 dev_info(&instance
->pdev
->dev
, "firmware crash dump : %s\n",
5835 instance
->crash_dump_drv_support
? "yes" : "no");
5836 dev_info(&instance
->pdev
->dev
, "jbod sync map : %s\n",
5837 instance
->use_seqnum_jbod_fp
? "yes" : "no");
5839 instance
->max_sectors_per_req
= instance
->max_num_sge
*
5840 SGE_BUFFER_SIZE
/ 512;
5841 if (tmp_sectors
&& (instance
->max_sectors_per_req
> tmp_sectors
))
5842 instance
->max_sectors_per_req
= tmp_sectors
;
5844 /* Check for valid throttlequeuedepth module parameter */
5845 if (throttlequeuedepth
&&
5846 throttlequeuedepth
<= instance
->max_scsi_cmds
)
5847 instance
->throttlequeuedepth
= throttlequeuedepth
;
5849 instance
->throttlequeuedepth
=
5850 MEGASAS_THROTTLE_QUEUE_DEPTH
;
5852 if ((resetwaittime
< 1) ||
5853 (resetwaittime
> MEGASAS_RESET_WAIT_TIME
))
5854 resetwaittime
= MEGASAS_RESET_WAIT_TIME
;
5856 if ((scmd_timeout
< 10) || (scmd_timeout
> MEGASAS_DEFAULT_CMD_TIMEOUT
))
5857 scmd_timeout
= MEGASAS_DEFAULT_CMD_TIMEOUT
;
5859 /* Launch SR-IOV heartbeat timer */
5860 if (instance
->requestorId
) {
5861 if (!megasas_sriov_start_heartbeat(instance
, 1)) {
5862 megasas_start_timer(instance
);
5864 instance
->skip_heartbeat_timer_del
= 1;
5865 goto fail_get_ld_pd_list
;
5870 * Create and start watchdog thread which will monitor
5871 * controller state every 1 sec and trigger OCR when
5872 * it enters fault state
5874 if (instance
->adapter_type
!= MFI_SERIES
)
5875 if (megasas_fusion_start_watchdog(instance
) != SUCCESS
)
5876 goto fail_start_watchdog
;
5880 fail_start_watchdog
:
5881 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
5882 del_timer_sync(&instance
->sriov_heartbeat_timer
);
5883 fail_get_ld_pd_list
:
5884 instance
->instancet
->disable_intr(instance
);
5885 megasas_destroy_irqs(instance
);
5887 if (instance
->msix_vectors
)
5888 pci_free_irq_vectors(instance
->pdev
);
5889 instance
->msix_vectors
= 0;
5891 megasas_free_ctrl_dma_buffers(instance
);
5892 megasas_free_ctrl_mem(instance
);
5894 iounmap(instance
->reg_set
);
5897 pci_release_selected_regions(instance
->pdev
, 1<<instance
->bar
);
5899 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
5900 __func__
, __LINE__
);
5905 * megasas_release_mfi - Reverses the FW initialization
5906 * @instance: Adapter soft state
5908 static void megasas_release_mfi(struct megasas_instance
*instance
)
5910 u32 reply_q_sz
= sizeof(u32
) *(instance
->max_mfi_cmds
+ 1);
5912 if (instance
->reply_queue
)
5913 dma_free_coherent(&instance
->pdev
->dev
, reply_q_sz
,
5914 instance
->reply_queue
, instance
->reply_queue_h
);
5916 megasas_free_cmds(instance
);
5918 iounmap(instance
->reg_set
);
5920 pci_release_selected_regions(instance
->pdev
, 1<<instance
->bar
);
5924 * megasas_get_seq_num - Gets latest event sequence numbers
5925 * @instance: Adapter soft state
5926 * @eli: FW event log sequence numbers information
5928 * FW maintains a log of all events in a non-volatile area. Upper layers would
5929 * usually find out the latest sequence number of the events, the seq number at
5930 * the boot etc. They would "read" all the events below the latest seq number
5931 * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq
5932 * number), they would subsribe to AEN (asynchronous event notification) and
5933 * wait for the events to happen.
5936 megasas_get_seq_num(struct megasas_instance
*instance
,
5937 struct megasas_evt_log_info
*eli
)
5939 struct megasas_cmd
*cmd
;
5940 struct megasas_dcmd_frame
*dcmd
;
5941 struct megasas_evt_log_info
*el_info
;
5942 dma_addr_t el_info_h
= 0;
5945 cmd
= megasas_get_cmd(instance
);
5951 dcmd
= &cmd
->frame
->dcmd
;
5952 el_info
= dma_alloc_coherent(&instance
->pdev
->dev
,
5953 sizeof(struct megasas_evt_log_info
),
5954 &el_info_h
, GFP_KERNEL
);
5956 megasas_return_cmd(instance
, cmd
);
5960 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
5962 dcmd
->cmd
= MFI_CMD_DCMD
;
5963 dcmd
->cmd_status
= 0x0;
5964 dcmd
->sge_count
= 1;
5965 dcmd
->flags
= MFI_FRAME_DIR_READ
;
5968 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_evt_log_info
));
5969 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO
);
5971 megasas_set_dma_settings(instance
, dcmd
, el_info_h
,
5972 sizeof(struct megasas_evt_log_info
));
5974 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
5975 if (ret
!= DCMD_SUCCESS
) {
5976 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
5977 __func__
, __LINE__
);
5982 * Copy the data back into callers buffer
5984 eli
->newest_seq_num
= el_info
->newest_seq_num
;
5985 eli
->oldest_seq_num
= el_info
->oldest_seq_num
;
5986 eli
->clear_seq_num
= el_info
->clear_seq_num
;
5987 eli
->shutdown_seq_num
= el_info
->shutdown_seq_num
;
5988 eli
->boot_seq_num
= el_info
->boot_seq_num
;
5991 dma_free_coherent(&instance
->pdev
->dev
,
5992 sizeof(struct megasas_evt_log_info
),
5993 el_info
, el_info_h
);
5995 megasas_return_cmd(instance
, cmd
);
6001 * megasas_register_aen - Registers for asynchronous event notification
6002 * @instance: Adapter soft state
6003 * @seq_num: The starting sequence number
6004 * @class_locale: Class of the event
6006 * This function subscribes for AEN for events beyond the @seq_num. It requests
6007 * to be notified if and only if the event is of type @class_locale
6010 megasas_register_aen(struct megasas_instance
*instance
, u32 seq_num
,
6011 u32 class_locale_word
)
6014 struct megasas_cmd
*cmd
;
6015 struct megasas_dcmd_frame
*dcmd
;
6016 union megasas_evt_class_locale curr_aen
;
6017 union megasas_evt_class_locale prev_aen
;
6020 * If there an AEN pending already (aen_cmd), check if the
6021 * class_locale of that pending AEN is inclusive of the new
6022 * AEN request we currently have. If it is, then we don't have
6023 * to do anything. In other words, whichever events the current
6024 * AEN request is subscribing to, have already been subscribed
6027 * If the old_cmd is _not_ inclusive, then we have to abort
6028 * that command, form a class_locale that is superset of both
6029 * old and current and re-issue to the FW
6032 curr_aen
.word
= class_locale_word
;
6034 if (instance
->aen_cmd
) {
6037 le32_to_cpu(instance
->aen_cmd
->frame
->dcmd
.mbox
.w
[1]);
6039 if ((curr_aen
.members
.class < MFI_EVT_CLASS_DEBUG
) ||
6040 (curr_aen
.members
.class > MFI_EVT_CLASS_DEAD
)) {
6041 dev_info(&instance
->pdev
->dev
,
6042 "%s %d out of range class %d send by application\n",
6043 __func__
, __LINE__
, curr_aen
.members
.class);
6048 * A class whose enum value is smaller is inclusive of all
6049 * higher values. If a PROGRESS (= -1) was previously
6050 * registered, then a new registration requests for higher
6051 * classes need not be sent to FW. They are automatically
6054 * Locale numbers don't have such hierarchy. They are bitmap
6057 if ((prev_aen
.members
.class <= curr_aen
.members
.class) &&
6058 !((prev_aen
.members
.locale
& curr_aen
.members
.locale
) ^
6059 curr_aen
.members
.locale
)) {
6061 * Previously issued event registration includes
6062 * current request. Nothing to do.
6066 curr_aen
.members
.locale
|= prev_aen
.members
.locale
;
6068 if (prev_aen
.members
.class < curr_aen
.members
.class)
6069 curr_aen
.members
.class = prev_aen
.members
.class;
6071 instance
->aen_cmd
->abort_aen
= 1;
6072 ret_val
= megasas_issue_blocked_abort_cmd(instance
,
6077 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to abort "
6078 "previous AEN command\n");
6084 cmd
= megasas_get_cmd(instance
);
6089 dcmd
= &cmd
->frame
->dcmd
;
6091 memset(instance
->evt_detail
, 0, sizeof(struct megasas_evt_detail
));
6094 * Prepare DCMD for aen registration
6096 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
6098 dcmd
->cmd
= MFI_CMD_DCMD
;
6099 dcmd
->cmd_status
= 0x0;
6100 dcmd
->sge_count
= 1;
6101 dcmd
->flags
= MFI_FRAME_DIR_READ
;
6104 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_evt_detail
));
6105 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT
);
6106 dcmd
->mbox
.w
[0] = cpu_to_le32(seq_num
);
6107 instance
->last_seq_num
= seq_num
;
6108 dcmd
->mbox
.w
[1] = cpu_to_le32(curr_aen
.word
);
6110 megasas_set_dma_settings(instance
, dcmd
, instance
->evt_detail_h
,
6111 sizeof(struct megasas_evt_detail
));
6113 if (instance
->aen_cmd
!= NULL
) {
6114 megasas_return_cmd(instance
, cmd
);
6119 * Store reference to the cmd used to register for AEN. When an
6120 * application wants us to register for AEN, we have to abort this
6121 * cmd and re-register with a new EVENT LOCALE supplied by that app
6123 instance
->aen_cmd
= cmd
;
6126 * Issue the aen registration frame
6128 instance
->instancet
->issue_dcmd(instance
, cmd
);
6133 /* megasas_get_target_prop - Send DCMD with below details to firmware.
6135 * This DCMD will fetch few properties of LD/system PD defined
6136 * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value.
6138 * DCMD send by drivers whenever new target is added to the OS.
6140 * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP
6141 * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD.
6142 * 0 = system PD, 1 = LD.
6143 * dcmd.mbox.s[1] - TargetID for LD/system PD.
6144 * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES.
6146 * @instance: Adapter soft state
6147 * @sdev: OS provided scsi device
6149 * Returns 0 on success non-zero on failure.
6152 megasas_get_target_prop(struct megasas_instance
*instance
,
6153 struct scsi_device
*sdev
)
6156 struct megasas_cmd
*cmd
;
6157 struct megasas_dcmd_frame
*dcmd
;
6158 u16 targetId
= (sdev
->channel
% 2) + sdev
->id
;
6160 cmd
= megasas_get_cmd(instance
);
6163 dev_err(&instance
->pdev
->dev
,
6164 "Failed to get cmd %s\n", __func__
);
6168 dcmd
= &cmd
->frame
->dcmd
;
6170 memset(instance
->tgt_prop
, 0, sizeof(*instance
->tgt_prop
));
6171 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
6172 dcmd
->mbox
.b
[0] = MEGASAS_IS_LOGICAL(sdev
);
6174 dcmd
->mbox
.s
[1] = cpu_to_le16(targetId
);
6175 dcmd
->cmd
= MFI_CMD_DCMD
;
6176 dcmd
->cmd_status
= 0xFF;
6177 dcmd
->sge_count
= 1;
6178 dcmd
->flags
= MFI_FRAME_DIR_READ
;
6181 dcmd
->data_xfer_len
=
6182 cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES
));
6183 dcmd
->opcode
= cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP
);
6185 megasas_set_dma_settings(instance
, dcmd
, instance
->tgt_prop_h
,
6186 sizeof(struct MR_TARGET_PROPERTIES
));
6188 if ((instance
->adapter_type
!= MFI_SERIES
) &&
6189 !instance
->mask_interrupts
)
6190 ret
= megasas_issue_blocked_cmd(instance
,
6191 cmd
, MFI_IO_TIMEOUT_SECS
);
6193 ret
= megasas_issue_polled(instance
, cmd
);
6197 switch (dcmd_timeout_ocr_possible(instance
)) {
6199 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
6200 megasas_reset_fusion(instance
->host
,
6201 MFI_IO_TIMEOUT_OCR
);
6204 megaraid_sas_kill_hba(instance
);
6206 case IGNORE_TIMEOUT
:
6207 dev_info(&instance
->pdev
->dev
,
6208 "Ignore DCMD timeout: %s %d\n",
6209 __func__
, __LINE__
);
6215 megasas_return_cmd(instance
, cmd
);
6217 if (ret
!= DCMD_SUCCESS
)
6218 dev_err(&instance
->pdev
->dev
,
6219 "return from %s %d return value %d\n",
6220 __func__
, __LINE__
, ret
);
6226 * megasas_start_aen - Subscribes to AEN during driver load time
6227 * @instance: Adapter soft state
6229 static int megasas_start_aen(struct megasas_instance
*instance
)
6231 struct megasas_evt_log_info eli
;
6232 union megasas_evt_class_locale class_locale
;
6235 * Get the latest sequence number from FW
6237 memset(&eli
, 0, sizeof(eli
));
6239 if (megasas_get_seq_num(instance
, &eli
))
6243 * Register AEN with FW for latest sequence number plus 1
6245 class_locale
.members
.reserved
= 0;
6246 class_locale
.members
.locale
= MR_EVT_LOCALE_ALL
;
6247 class_locale
.members
.class = MR_EVT_CLASS_DEBUG
;
6249 return megasas_register_aen(instance
,
6250 le32_to_cpu(eli
.newest_seq_num
) + 1,
6255 * megasas_io_attach - Attaches this driver to SCSI mid-layer
6256 * @instance: Adapter soft state
6258 static int megasas_io_attach(struct megasas_instance
*instance
)
6260 struct Scsi_Host
*host
= instance
->host
;
6263 * Export parameters required by SCSI mid-layer
6265 host
->unique_id
= instance
->unique_id
;
6266 host
->can_queue
= instance
->max_scsi_cmds
;
6267 host
->this_id
= instance
->init_id
;
6268 host
->sg_tablesize
= instance
->max_num_sge
;
6270 if (instance
->fw_support_ieee
)
6271 instance
->max_sectors_per_req
= MEGASAS_MAX_SECTORS_IEEE
;
6274 * Check if the module parameter value for max_sectors can be used
6276 if (max_sectors
&& max_sectors
< instance
->max_sectors_per_req
)
6277 instance
->max_sectors_per_req
= max_sectors
;
6280 if (((instance
->pdev
->device
==
6281 PCI_DEVICE_ID_LSI_SAS1078GEN2
) ||
6282 (instance
->pdev
->device
==
6283 PCI_DEVICE_ID_LSI_SAS0079GEN2
)) &&
6284 (max_sectors
<= MEGASAS_MAX_SECTORS
)) {
6285 instance
->max_sectors_per_req
= max_sectors
;
6287 dev_info(&instance
->pdev
->dev
, "max_sectors should be > 0"
6288 "and <= %d (or < 1MB for GEN2 controller)\n",
6289 instance
->max_sectors_per_req
);
6294 host
->max_sectors
= instance
->max_sectors_per_req
;
6295 host
->cmd_per_lun
= MEGASAS_DEFAULT_CMD_PER_LUN
;
6296 host
->max_channel
= MEGASAS_MAX_CHANNELS
- 1;
6297 host
->max_id
= MEGASAS_MAX_DEV_PER_CHANNEL
;
6298 host
->max_lun
= MEGASAS_MAX_LUN
;
6299 host
->max_cmd_len
= 16;
6302 * Notify the mid-layer about the new controller
6304 if (scsi_add_host(host
, &instance
->pdev
->dev
)) {
6305 dev_err(&instance
->pdev
->dev
,
6306 "Failed to add host from %s %d\n",
6307 __func__
, __LINE__
);
6315 * megasas_set_dma_mask - Set DMA mask for supported controllers
6317 * @instance: Adapter soft state
6320 * For Ventura, driver/FW will operate in 63bit DMA addresses.
6323 * By default, driver/FW will operate in 32bit DMA addresses
6324 * for consistent DMA mapping but if 32 bit consistent
6325 * DMA mask fails, driver will try with 63 bit consistent
6326 * mask provided FW is true 63bit DMA capable
6328 * For older controllers(Thunderbolt and MFI based adapters)-
6329 * driver/FW will operate in 32 bit consistent DMA addresses.
6332 megasas_set_dma_mask(struct megasas_instance
*instance
)
6334 u64 consistent_mask
;
6335 struct pci_dev
*pdev
;
6338 pdev
= instance
->pdev
;
6339 consistent_mask
= (instance
->adapter_type
>= VENTURA_SERIES
) ?
6340 DMA_BIT_MASK(63) : DMA_BIT_MASK(32);
6343 if (dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(63)) &&
6344 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)))
6345 goto fail_set_dma_mask
;
6347 if ((*pdev
->dev
.dma_mask
== DMA_BIT_MASK(63)) &&
6348 (dma_set_coherent_mask(&pdev
->dev
, consistent_mask
) &&
6349 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)))) {
6351 * If 32 bit DMA mask fails, then try for 64 bit mask
6352 * for FW capable of handling 64 bit DMA.
6354 scratch_pad_1
= megasas_readl
6355 (instance
, &instance
->reg_set
->outbound_scratch_pad_1
);
6357 if (!(scratch_pad_1
& MR_CAN_HANDLE_64_BIT_DMA_OFFSET
))
6358 goto fail_set_dma_mask
;
6359 else if (dma_set_mask_and_coherent(&pdev
->dev
,
6361 goto fail_set_dma_mask
;
6363 } else if (dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)))
6364 goto fail_set_dma_mask
;
6366 if (pdev
->dev
.coherent_dma_mask
== DMA_BIT_MASK(32))
6367 instance
->consistent_mask_64bit
= false;
6369 instance
->consistent_mask_64bit
= true;
6371 dev_info(&pdev
->dev
, "%s bit DMA mask and %s bit consistent mask\n",
6372 ((*pdev
->dev
.dma_mask
== DMA_BIT_MASK(63)) ? "63" : "32"),
6373 (instance
->consistent_mask_64bit
? "63" : "32"));
6378 dev_err(&pdev
->dev
, "Failed to set DMA mask\n");
6384 * megasas_set_adapter_type - Set adapter type.
6385 * Supported controllers can be divided in
6386 * different categories-
6387 * enum MR_ADAPTER_TYPE {
6389 * THUNDERBOLT_SERIES = 2,
6390 * INVADER_SERIES = 3,
6391 * VENTURA_SERIES = 4,
6394 * @instance: Adapter soft state
6397 static inline void megasas_set_adapter_type(struct megasas_instance
*instance
)
6399 if ((instance
->pdev
->vendor
== PCI_VENDOR_ID_DELL
) &&
6400 (instance
->pdev
->device
== PCI_DEVICE_ID_DELL_PERC5
)) {
6401 instance
->adapter_type
= MFI_SERIES
;
6403 switch (instance
->pdev
->device
) {
6404 case PCI_DEVICE_ID_LSI_AERO_10E1
:
6405 case PCI_DEVICE_ID_LSI_AERO_10E2
:
6406 case PCI_DEVICE_ID_LSI_AERO_10E5
:
6407 case PCI_DEVICE_ID_LSI_AERO_10E6
:
6408 instance
->adapter_type
= AERO_SERIES
;
6410 case PCI_DEVICE_ID_LSI_VENTURA
:
6411 case PCI_DEVICE_ID_LSI_CRUSADER
:
6412 case PCI_DEVICE_ID_LSI_HARPOON
:
6413 case PCI_DEVICE_ID_LSI_TOMCAT
:
6414 case PCI_DEVICE_ID_LSI_VENTURA_4PORT
:
6415 case PCI_DEVICE_ID_LSI_CRUSADER_4PORT
:
6416 instance
->adapter_type
= VENTURA_SERIES
;
6418 case PCI_DEVICE_ID_LSI_FUSION
:
6419 case PCI_DEVICE_ID_LSI_PLASMA
:
6420 instance
->adapter_type
= THUNDERBOLT_SERIES
;
6422 case PCI_DEVICE_ID_LSI_INVADER
:
6423 case PCI_DEVICE_ID_LSI_INTRUDER
:
6424 case PCI_DEVICE_ID_LSI_INTRUDER_24
:
6425 case PCI_DEVICE_ID_LSI_CUTLASS_52
:
6426 case PCI_DEVICE_ID_LSI_CUTLASS_53
:
6427 case PCI_DEVICE_ID_LSI_FURY
:
6428 instance
->adapter_type
= INVADER_SERIES
;
6430 default: /* For all other supported controllers */
6431 instance
->adapter_type
= MFI_SERIES
;
6437 static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance
*instance
)
6439 instance
->producer
= dma_alloc_coherent(&instance
->pdev
->dev
,
6440 sizeof(u32
), &instance
->producer_h
, GFP_KERNEL
);
6441 instance
->consumer
= dma_alloc_coherent(&instance
->pdev
->dev
,
6442 sizeof(u32
), &instance
->consumer_h
, GFP_KERNEL
);
6444 if (!instance
->producer
|| !instance
->consumer
) {
6445 dev_err(&instance
->pdev
->dev
,
6446 "Failed to allocate memory for producer, consumer\n");
6450 *instance
->producer
= 0;
6451 *instance
->consumer
= 0;
6456 * megasas_alloc_ctrl_mem - Allocate per controller memory for core data
6457 * structures which are not common across MFI
6458 * adapters and fusion adapters.
6459 * For MFI based adapters, allocate producer and
6460 * consumer buffers. For fusion adapters, allocate
6461 * memory for fusion context.
6462 * @instance: Adapter soft state
6463 * return: 0 for SUCCESS
6465 static int megasas_alloc_ctrl_mem(struct megasas_instance
*instance
)
6467 instance
->reply_map
= kcalloc(nr_cpu_ids
, sizeof(unsigned int),
6469 if (!instance
->reply_map
)
6472 switch (instance
->adapter_type
) {
6474 if (megasas_alloc_mfi_ctrl_mem(instance
))
6478 case VENTURA_SERIES
:
6479 case THUNDERBOLT_SERIES
:
6480 case INVADER_SERIES
:
6481 if (megasas_alloc_fusion_context(instance
))
6488 kfree(instance
->reply_map
);
6489 instance
->reply_map
= NULL
;
6494 * megasas_free_ctrl_mem - Free fusion context for fusion adapters and
6495 * producer, consumer buffers for MFI adapters
6497 * @instance - Adapter soft instance
6500 static inline void megasas_free_ctrl_mem(struct megasas_instance
*instance
)
6502 kfree(instance
->reply_map
);
6503 if (instance
->adapter_type
== MFI_SERIES
) {
6504 if (instance
->producer
)
6505 dma_free_coherent(&instance
->pdev
->dev
, sizeof(u32
),
6507 instance
->producer_h
);
6508 if (instance
->consumer
)
6509 dma_free_coherent(&instance
->pdev
->dev
, sizeof(u32
),
6511 instance
->consumer_h
);
6513 megasas_free_fusion_context(instance
);
6518 * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during
6521 * @instance- Adapter soft instance
6522 * @return- O for SUCCESS
6525 int megasas_alloc_ctrl_dma_buffers(struct megasas_instance
*instance
)
6527 struct pci_dev
*pdev
= instance
->pdev
;
6528 struct fusion_context
*fusion
= instance
->ctrl_context
;
6530 instance
->evt_detail
= dma_alloc_coherent(&pdev
->dev
,
6531 sizeof(struct megasas_evt_detail
),
6532 &instance
->evt_detail_h
, GFP_KERNEL
);
6534 if (!instance
->evt_detail
) {
6535 dev_err(&instance
->pdev
->dev
,
6536 "Failed to allocate event detail buffer\n");
6541 fusion
->ioc_init_request
=
6542 dma_alloc_coherent(&pdev
->dev
,
6543 sizeof(struct MPI2_IOC_INIT_REQUEST
),
6544 &fusion
->ioc_init_request_phys
,
6547 if (!fusion
->ioc_init_request
) {
6549 "Failed to allocate PD list buffer\n");
6553 instance
->snapdump_prop
= dma_alloc_coherent(&pdev
->dev
,
6554 sizeof(struct MR_SNAPDUMP_PROPERTIES
),
6555 &instance
->snapdump_prop_h
, GFP_KERNEL
);
6557 if (!instance
->snapdump_prop
)
6559 "Failed to allocate snapdump properties buffer\n");
6561 instance
->host_device_list_buf
= dma_alloc_coherent(&pdev
->dev
,
6562 HOST_DEVICE_LIST_SZ
,
6563 &instance
->host_device_list_buf_h
,
6566 if (!instance
->host_device_list_buf
) {
6568 "Failed to allocate targetid list buffer\n");
6574 instance
->pd_list_buf
=
6575 dma_alloc_coherent(&pdev
->dev
,
6576 MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
),
6577 &instance
->pd_list_buf_h
, GFP_KERNEL
);
6579 if (!instance
->pd_list_buf
) {
6580 dev_err(&pdev
->dev
, "Failed to allocate PD list buffer\n");
6584 instance
->ctrl_info_buf
=
6585 dma_alloc_coherent(&pdev
->dev
,
6586 sizeof(struct megasas_ctrl_info
),
6587 &instance
->ctrl_info_buf_h
, GFP_KERNEL
);
6589 if (!instance
->ctrl_info_buf
) {
6591 "Failed to allocate controller info buffer\n");
6595 instance
->ld_list_buf
=
6596 dma_alloc_coherent(&pdev
->dev
,
6597 sizeof(struct MR_LD_LIST
),
6598 &instance
->ld_list_buf_h
, GFP_KERNEL
);
6600 if (!instance
->ld_list_buf
) {
6601 dev_err(&pdev
->dev
, "Failed to allocate LD list buffer\n");
6605 instance
->ld_targetid_list_buf
=
6606 dma_alloc_coherent(&pdev
->dev
,
6607 sizeof(struct MR_LD_TARGETID_LIST
),
6608 &instance
->ld_targetid_list_buf_h
, GFP_KERNEL
);
6610 if (!instance
->ld_targetid_list_buf
) {
6612 "Failed to allocate LD targetid list buffer\n");
6616 if (!reset_devices
) {
6617 instance
->system_info_buf
=
6618 dma_alloc_coherent(&pdev
->dev
,
6619 sizeof(struct MR_DRV_SYSTEM_INFO
),
6620 &instance
->system_info_h
, GFP_KERNEL
);
6622 dma_alloc_coherent(&pdev
->dev
,
6623 sizeof(struct MR_PD_INFO
),
6624 &instance
->pd_info_h
, GFP_KERNEL
);
6625 instance
->tgt_prop
=
6626 dma_alloc_coherent(&pdev
->dev
,
6627 sizeof(struct MR_TARGET_PROPERTIES
),
6628 &instance
->tgt_prop_h
, GFP_KERNEL
);
6629 instance
->crash_dump_buf
=
6630 dma_alloc_coherent(&pdev
->dev
, CRASH_DMA_BUF_SIZE
,
6631 &instance
->crash_dump_h
, GFP_KERNEL
);
6633 if (!instance
->system_info_buf
)
6634 dev_err(&instance
->pdev
->dev
,
6635 "Failed to allocate system info buffer\n");
6637 if (!instance
->pd_info
)
6638 dev_err(&instance
->pdev
->dev
,
6639 "Failed to allocate pd_info buffer\n");
6641 if (!instance
->tgt_prop
)
6642 dev_err(&instance
->pdev
->dev
,
6643 "Failed to allocate tgt_prop buffer\n");
6645 if (!instance
->crash_dump_buf
)
6646 dev_err(&instance
->pdev
->dev
,
6647 "Failed to allocate crash dump buffer\n");
6654 * megasas_free_ctrl_dma_buffers - Free consistent DMA buffers allocated
6655 * during driver load time
6657 * @instance- Adapter soft instance
6661 void megasas_free_ctrl_dma_buffers(struct megasas_instance
*instance
)
6663 struct pci_dev
*pdev
= instance
->pdev
;
6664 struct fusion_context
*fusion
= instance
->ctrl_context
;
6666 if (instance
->evt_detail
)
6667 dma_free_coherent(&pdev
->dev
, sizeof(struct megasas_evt_detail
),
6668 instance
->evt_detail
,
6669 instance
->evt_detail_h
);
6671 if (fusion
&& fusion
->ioc_init_request
)
6672 dma_free_coherent(&pdev
->dev
,
6673 sizeof(struct MPI2_IOC_INIT_REQUEST
),
6674 fusion
->ioc_init_request
,
6675 fusion
->ioc_init_request_phys
);
6677 if (instance
->pd_list_buf
)
6678 dma_free_coherent(&pdev
->dev
,
6679 MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
),
6680 instance
->pd_list_buf
,
6681 instance
->pd_list_buf_h
);
6683 if (instance
->ld_list_buf
)
6684 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_LD_LIST
),
6685 instance
->ld_list_buf
,
6686 instance
->ld_list_buf_h
);
6688 if (instance
->ld_targetid_list_buf
)
6689 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_LD_TARGETID_LIST
),
6690 instance
->ld_targetid_list_buf
,
6691 instance
->ld_targetid_list_buf_h
);
6693 if (instance
->ctrl_info_buf
)
6694 dma_free_coherent(&pdev
->dev
, sizeof(struct megasas_ctrl_info
),
6695 instance
->ctrl_info_buf
,
6696 instance
->ctrl_info_buf_h
);
6698 if (instance
->system_info_buf
)
6699 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_DRV_SYSTEM_INFO
),
6700 instance
->system_info_buf
,
6701 instance
->system_info_h
);
6703 if (instance
->pd_info
)
6704 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_PD_INFO
),
6705 instance
->pd_info
, instance
->pd_info_h
);
6707 if (instance
->tgt_prop
)
6708 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_TARGET_PROPERTIES
),
6709 instance
->tgt_prop
, instance
->tgt_prop_h
);
6711 if (instance
->crash_dump_buf
)
6712 dma_free_coherent(&pdev
->dev
, CRASH_DMA_BUF_SIZE
,
6713 instance
->crash_dump_buf
,
6714 instance
->crash_dump_h
);
6716 if (instance
->snapdump_prop
)
6717 dma_free_coherent(&pdev
->dev
,
6718 sizeof(struct MR_SNAPDUMP_PROPERTIES
),
6719 instance
->snapdump_prop
,
6720 instance
->snapdump_prop_h
);
6722 if (instance
->host_device_list_buf
)
6723 dma_free_coherent(&pdev
->dev
,
6724 HOST_DEVICE_LIST_SZ
,
6725 instance
->host_device_list_buf
,
6726 instance
->host_device_list_buf_h
);
6731 * megasas_init_ctrl_params - Initialize controller's instance
6732 * parameters before FW init
6733 * @instance - Adapter soft instance
6736 static inline void megasas_init_ctrl_params(struct megasas_instance
*instance
)
6738 instance
->fw_crash_state
= UNAVAILABLE
;
6740 megasas_poll_wait_aen
= 0;
6741 instance
->issuepend_done
= 1;
6742 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
6745 * Initialize locks and queues
6747 INIT_LIST_HEAD(&instance
->cmd_pool
);
6748 INIT_LIST_HEAD(&instance
->internal_reset_pending_q
);
6750 atomic_set(&instance
->fw_outstanding
, 0);
6752 init_waitqueue_head(&instance
->int_cmd_wait_q
);
6753 init_waitqueue_head(&instance
->abort_cmd_wait_q
);
6755 spin_lock_init(&instance
->crashdump_lock
);
6756 spin_lock_init(&instance
->mfi_pool_lock
);
6757 spin_lock_init(&instance
->hba_lock
);
6758 spin_lock_init(&instance
->stream_lock
);
6759 spin_lock_init(&instance
->completion_lock
);
6761 mutex_init(&instance
->reset_mutex
);
6763 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
6764 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0071SKINNY
))
6765 instance
->flag_ieee
= 1;
6767 megasas_dbg_lvl
= 0;
6769 instance
->unload
= 1;
6770 instance
->last_time
= 0;
6771 instance
->disableOnlineCtrlReset
= 1;
6772 instance
->UnevenSpanSupport
= 0;
6774 if (instance
->adapter_type
!= MFI_SERIES
)
6775 INIT_WORK(&instance
->work_init
, megasas_fusion_ocr_wq
);
6777 INIT_WORK(&instance
->work_init
, process_fw_state_change_wq
);
6781 * megasas_probe_one - PCI hotplug entry point
6782 * @pdev: PCI device structure
6783 * @id: PCI ids of supported hotplugged adapter
6785 static int megasas_probe_one(struct pci_dev
*pdev
,
6786 const struct pci_device_id
*id
)
6789 struct Scsi_Host
*host
;
6790 struct megasas_instance
*instance
;
6793 switch (pdev
->device
) {
6794 case PCI_DEVICE_ID_LSI_AERO_10E1
:
6795 case PCI_DEVICE_ID_LSI_AERO_10E5
:
6796 dev_info(&pdev
->dev
, "Adapter is in configurable secure mode\n");
6800 /* Reset MSI-X in the kdump kernel */
6801 if (reset_devices
) {
6802 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
6804 pci_read_config_word(pdev
, pos
+ PCI_MSIX_FLAGS
,
6806 if (control
& PCI_MSIX_FLAGS_ENABLE
) {
6807 dev_info(&pdev
->dev
, "resetting MSI-X\n");
6808 pci_write_config_word(pdev
,
6809 pos
+ PCI_MSIX_FLAGS
,
6811 ~PCI_MSIX_FLAGS_ENABLE
);
6817 * PCI prepping: enable device set bus mastering and dma mask
6819 rval
= pci_enable_device_mem(pdev
);
6825 pci_set_master(pdev
);
6827 host
= scsi_host_alloc(&megasas_template
,
6828 sizeof(struct megasas_instance
));
6831 dev_printk(KERN_DEBUG
, &pdev
->dev
, "scsi_host_alloc failed\n");
6832 goto fail_alloc_instance
;
6835 instance
= (struct megasas_instance
*)host
->hostdata
;
6836 memset(instance
, 0, sizeof(*instance
));
6837 atomic_set(&instance
->fw_reset_no_pci_access
, 0);
6840 * Initialize PCI related and misc parameters
6842 instance
->pdev
= pdev
;
6843 instance
->host
= host
;
6844 instance
->unique_id
= pdev
->bus
->number
<< 8 | pdev
->devfn
;
6845 instance
->init_id
= MEGASAS_DEFAULT_INIT_ID
;
6847 megasas_set_adapter_type(instance
);
6850 * Initialize MFI Firmware
6852 if (megasas_init_fw(instance
))
6855 if (instance
->requestorId
) {
6856 if (instance
->PlasmaFW111
) {
6857 instance
->vf_affiliation_111
=
6858 dma_alloc_coherent(&pdev
->dev
,
6859 sizeof(struct MR_LD_VF_AFFILIATION_111
),
6860 &instance
->vf_affiliation_111_h
,
6862 if (!instance
->vf_affiliation_111
)
6863 dev_warn(&pdev
->dev
, "Can't allocate "
6864 "memory for VF affiliation buffer\n");
6866 instance
->vf_affiliation
=
6867 dma_alloc_coherent(&pdev
->dev
,
6868 (MAX_LOGICAL_DRIVES
+ 1) *
6869 sizeof(struct MR_LD_VF_AFFILIATION
),
6870 &instance
->vf_affiliation_h
,
6872 if (!instance
->vf_affiliation
)
6873 dev_warn(&pdev
->dev
, "Can't allocate "
6874 "memory for VF affiliation buffer\n");
6879 * Store instance in PCI softstate
6881 pci_set_drvdata(pdev
, instance
);
6884 * Add this controller to megasas_mgmt_info structure so that it
6885 * can be exported to management applications
6887 megasas_mgmt_info
.count
++;
6888 megasas_mgmt_info
.instance
[megasas_mgmt_info
.max_index
] = instance
;
6889 megasas_mgmt_info
.max_index
++;
6892 * Register with SCSI mid-layer
6894 if (megasas_io_attach(instance
))
6895 goto fail_io_attach
;
6897 instance
->unload
= 0;
6899 * Trigger SCSI to scan our drives
6901 if (!instance
->enable_fw_dev_list
||
6902 (instance
->host_device_list_buf
->count
> 0))
6903 scsi_scan_host(host
);
6906 * Initiate AEN (Asynchronous Event Notification)
6908 if (megasas_start_aen(instance
)) {
6909 dev_printk(KERN_DEBUG
, &pdev
->dev
, "start aen failed\n");
6910 goto fail_start_aen
;
6913 /* Get current SR-IOV LD/VF affiliation */
6914 if (instance
->requestorId
)
6915 megasas_get_ld_vf_affiliation(instance
, 1);
6921 megasas_mgmt_info
.count
--;
6922 megasas_mgmt_info
.max_index
--;
6923 megasas_mgmt_info
.instance
[megasas_mgmt_info
.max_index
] = NULL
;
6925 instance
->instancet
->disable_intr(instance
);
6926 megasas_destroy_irqs(instance
);
6928 if (instance
->adapter_type
!= MFI_SERIES
)
6929 megasas_release_fusion(instance
);
6931 megasas_release_mfi(instance
);
6932 if (instance
->msix_vectors
)
6933 pci_free_irq_vectors(instance
->pdev
);
6935 scsi_host_put(host
);
6936 fail_alloc_instance
:
6937 pci_disable_device(pdev
);
6943 * megasas_flush_cache - Requests FW to flush all its caches
6944 * @instance: Adapter soft state
6946 static void megasas_flush_cache(struct megasas_instance
*instance
)
6948 struct megasas_cmd
*cmd
;
6949 struct megasas_dcmd_frame
*dcmd
;
6951 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
6954 cmd
= megasas_get_cmd(instance
);
6959 dcmd
= &cmd
->frame
->dcmd
;
6961 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
6963 dcmd
->cmd
= MFI_CMD_DCMD
;
6964 dcmd
->cmd_status
= 0x0;
6965 dcmd
->sge_count
= 0;
6966 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_NONE
);
6969 dcmd
->data_xfer_len
= 0;
6970 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH
);
6971 dcmd
->mbox
.b
[0] = MR_FLUSH_CTRL_CACHE
| MR_FLUSH_DISK_CACHE
;
6973 if (megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
)
6975 dev_err(&instance
->pdev
->dev
,
6976 "return from %s %d\n", __func__
, __LINE__
);
6980 megasas_return_cmd(instance
, cmd
);
6984 * megasas_shutdown_controller - Instructs FW to shutdown the controller
6985 * @instance: Adapter soft state
6986 * @opcode: Shutdown/Hibernate
6988 static void megasas_shutdown_controller(struct megasas_instance
*instance
,
6991 struct megasas_cmd
*cmd
;
6992 struct megasas_dcmd_frame
*dcmd
;
6994 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
6997 cmd
= megasas_get_cmd(instance
);
7002 if (instance
->aen_cmd
)
7003 megasas_issue_blocked_abort_cmd(instance
,
7004 instance
->aen_cmd
, MFI_IO_TIMEOUT_SECS
);
7005 if (instance
->map_update_cmd
)
7006 megasas_issue_blocked_abort_cmd(instance
,
7007 instance
->map_update_cmd
, MFI_IO_TIMEOUT_SECS
);
7008 if (instance
->jbod_seq_cmd
)
7009 megasas_issue_blocked_abort_cmd(instance
,
7010 instance
->jbod_seq_cmd
, MFI_IO_TIMEOUT_SECS
);
7012 dcmd
= &cmd
->frame
->dcmd
;
7014 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
7016 dcmd
->cmd
= MFI_CMD_DCMD
;
7017 dcmd
->cmd_status
= 0x0;
7018 dcmd
->sge_count
= 0;
7019 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_NONE
);
7022 dcmd
->data_xfer_len
= 0;
7023 dcmd
->opcode
= cpu_to_le32(opcode
);
7025 if (megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
)
7027 dev_err(&instance
->pdev
->dev
,
7028 "return from %s %d\n", __func__
, __LINE__
);
7032 megasas_return_cmd(instance
, cmd
);
7037 * megasas_suspend - driver suspend entry point
7038 * @pdev: PCI device structure
7039 * @state: PCI power state to suspend routine
7042 megasas_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7044 struct Scsi_Host
*host
;
7045 struct megasas_instance
*instance
;
7047 instance
= pci_get_drvdata(pdev
);
7048 host
= instance
->host
;
7049 instance
->unload
= 1;
7051 /* Shutdown SR-IOV heartbeat timer */
7052 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
7053 del_timer_sync(&instance
->sriov_heartbeat_timer
);
7055 /* Stop the FW fault detection watchdog */
7056 if (instance
->adapter_type
!= MFI_SERIES
)
7057 megasas_fusion_stop_watchdog(instance
);
7059 megasas_flush_cache(instance
);
7060 megasas_shutdown_controller(instance
, MR_DCMD_HIBERNATE_SHUTDOWN
);
7062 /* cancel the delayed work if this work still in queue */
7063 if (instance
->ev
!= NULL
) {
7064 struct megasas_aen_event
*ev
= instance
->ev
;
7065 cancel_delayed_work_sync(&ev
->hotplug_work
);
7066 instance
->ev
= NULL
;
7069 tasklet_kill(&instance
->isr_tasklet
);
7071 pci_set_drvdata(instance
->pdev
, instance
);
7072 instance
->instancet
->disable_intr(instance
);
7074 megasas_destroy_irqs(instance
);
7076 if (instance
->msix_vectors
)
7077 pci_free_irq_vectors(instance
->pdev
);
7079 pci_save_state(pdev
);
7080 pci_disable_device(pdev
);
7082 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
7088 * megasas_resume- driver resume entry point
7089 * @pdev: PCI device structure
7092 megasas_resume(struct pci_dev
*pdev
)
7095 struct Scsi_Host
*host
;
7096 struct megasas_instance
*instance
;
7097 int irq_flags
= PCI_IRQ_LEGACY
;
7099 instance
= pci_get_drvdata(pdev
);
7100 host
= instance
->host
;
7101 pci_set_power_state(pdev
, PCI_D0
);
7102 pci_enable_wake(pdev
, PCI_D0
, 0);
7103 pci_restore_state(pdev
);
7106 * PCI prepping: enable device set bus mastering and dma mask
7108 rval
= pci_enable_device_mem(pdev
);
7111 dev_err(&pdev
->dev
, "Enable device failed\n");
7115 pci_set_master(pdev
);
7118 * We expect the FW state to be READY
7120 if (megasas_transition_to_ready(instance
, 0))
7121 goto fail_ready_state
;
7123 if (megasas_set_dma_mask(instance
))
7124 goto fail_set_dma_mask
;
7127 * Initialize MFI Firmware
7130 atomic_set(&instance
->fw_outstanding
, 0);
7131 atomic_set(&instance
->ldio_outstanding
, 0);
7133 /* Now re-enable MSI-X */
7134 if (instance
->msix_vectors
) {
7135 irq_flags
= PCI_IRQ_MSIX
;
7136 if (smp_affinity_enable
)
7137 irq_flags
|= PCI_IRQ_AFFINITY
;
7139 rval
= pci_alloc_irq_vectors(instance
->pdev
, 1,
7140 instance
->msix_vectors
?
7141 instance
->msix_vectors
: 1, irq_flags
);
7143 goto fail_reenable_msix
;
7145 megasas_setup_reply_map(instance
);
7147 if (instance
->adapter_type
!= MFI_SERIES
) {
7148 megasas_reset_reply_desc(instance
);
7149 if (megasas_ioc_init_fusion(instance
)) {
7150 megasas_free_cmds(instance
);
7151 megasas_free_cmds_fusion(instance
);
7154 if (!megasas_get_map_info(instance
))
7155 megasas_sync_map_info(instance
);
7157 *instance
->producer
= 0;
7158 *instance
->consumer
= 0;
7159 if (megasas_issue_init_mfi(instance
))
7163 if (megasas_get_ctrl_info(instance
) != DCMD_SUCCESS
)
7166 tasklet_init(&instance
->isr_tasklet
, instance
->instancet
->tasklet
,
7167 (unsigned long)instance
);
7169 if (instance
->msix_vectors
?
7170 megasas_setup_irqs_msix(instance
, 0) :
7171 megasas_setup_irqs_ioapic(instance
))
7174 /* Re-launch SR-IOV heartbeat timer */
7175 if (instance
->requestorId
) {
7176 if (!megasas_sriov_start_heartbeat(instance
, 0))
7177 megasas_start_timer(instance
);
7179 instance
->skip_heartbeat_timer_del
= 1;
7184 instance
->instancet
->enable_intr(instance
);
7185 megasas_setup_jbod_map(instance
);
7186 instance
->unload
= 0;
7189 * Initiate AEN (Asynchronous Event Notification)
7191 if (megasas_start_aen(instance
))
7192 dev_err(&instance
->pdev
->dev
, "Start AEN failed\n");
7194 /* Re-launch FW fault watchdog */
7195 if (instance
->adapter_type
!= MFI_SERIES
)
7196 if (megasas_fusion_start_watchdog(instance
) != SUCCESS
)
7197 goto fail_start_watchdog
;
7201 fail_start_watchdog
:
7202 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
7203 del_timer_sync(&instance
->sriov_heartbeat_timer
);
7205 megasas_free_ctrl_dma_buffers(instance
);
7206 megasas_free_ctrl_mem(instance
);
7207 scsi_host_put(host
);
7213 pci_disable_device(pdev
);
7218 #define megasas_suspend NULL
7219 #define megasas_resume NULL
7223 megasas_wait_for_adapter_operational(struct megasas_instance
*instance
)
7225 int wait_time
= MEGASAS_RESET_WAIT_TIME
* 2;
7229 for (i
= 0; i
< wait_time
; i
++) {
7230 adp_state
= atomic_read(&instance
->adprecovery
);
7231 if ((adp_state
== MEGASAS_HBA_OPERATIONAL
) ||
7232 (adp_state
== MEGASAS_HW_CRITICAL_ERROR
))
7235 if (!(i
% MEGASAS_RESET_NOTICE_INTERVAL
))
7236 dev_notice(&instance
->pdev
->dev
, "waiting for controller reset to finish\n");
7241 if (adp_state
!= MEGASAS_HBA_OPERATIONAL
) {
7242 dev_info(&instance
->pdev
->dev
,
7243 "%s HBA failed to become operational, adp_state %d\n",
7244 __func__
, adp_state
);
7252 * megasas_detach_one - PCI hot"un"plug entry point
7253 * @pdev: PCI device structure
7255 static void megasas_detach_one(struct pci_dev
*pdev
)
7258 struct Scsi_Host
*host
;
7259 struct megasas_instance
*instance
;
7260 struct fusion_context
*fusion
;
7263 instance
= pci_get_drvdata(pdev
);
7264 host
= instance
->host
;
7265 fusion
= instance
->ctrl_context
;
7267 /* Shutdown SR-IOV heartbeat timer */
7268 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
7269 del_timer_sync(&instance
->sriov_heartbeat_timer
);
7271 /* Stop the FW fault detection watchdog */
7272 if (instance
->adapter_type
!= MFI_SERIES
)
7273 megasas_fusion_stop_watchdog(instance
);
7275 if (instance
->fw_crash_state
!= UNAVAILABLE
)
7276 megasas_free_host_crash_buffer(instance
);
7277 scsi_remove_host(instance
->host
);
7278 instance
->unload
= 1;
7280 if (megasas_wait_for_adapter_operational(instance
))
7281 goto skip_firing_dcmds
;
7283 megasas_flush_cache(instance
);
7284 megasas_shutdown_controller(instance
, MR_DCMD_CTRL_SHUTDOWN
);
7287 /* cancel the delayed work if this work still in queue*/
7288 if (instance
->ev
!= NULL
) {
7289 struct megasas_aen_event
*ev
= instance
->ev
;
7290 cancel_delayed_work_sync(&ev
->hotplug_work
);
7291 instance
->ev
= NULL
;
7294 /* cancel all wait events */
7295 wake_up_all(&instance
->int_cmd_wait_q
);
7297 tasklet_kill(&instance
->isr_tasklet
);
7300 * Take the instance off the instance array. Note that we will not
7301 * decrement the max_index. We let this array be sparse array
7303 for (i
= 0; i
< megasas_mgmt_info
.max_index
; i
++) {
7304 if (megasas_mgmt_info
.instance
[i
] == instance
) {
7305 megasas_mgmt_info
.count
--;
7306 megasas_mgmt_info
.instance
[i
] = NULL
;
7312 instance
->instancet
->disable_intr(instance
);
7314 megasas_destroy_irqs(instance
);
7316 if (instance
->msix_vectors
)
7317 pci_free_irq_vectors(instance
->pdev
);
7319 if (instance
->adapter_type
>= VENTURA_SERIES
) {
7320 for (i
= 0; i
< MAX_LOGICAL_DRIVES_EXT
; ++i
)
7321 kfree(fusion
->stream_detect_by_ld
[i
]);
7322 kfree(fusion
->stream_detect_by_ld
);
7323 fusion
->stream_detect_by_ld
= NULL
;
7327 if (instance
->adapter_type
!= MFI_SERIES
) {
7328 megasas_release_fusion(instance
);
7329 pd_seq_map_sz
= sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC
) +
7330 (sizeof(struct MR_PD_CFG_SEQ
) *
7331 (MAX_PHYSICAL_DEVICES
- 1));
7332 for (i
= 0; i
< 2 ; i
++) {
7333 if (fusion
->ld_map
[i
])
7334 dma_free_coherent(&instance
->pdev
->dev
,
7337 fusion
->ld_map_phys
[i
]);
7338 if (fusion
->ld_drv_map
[i
]) {
7339 if (is_vmalloc_addr(fusion
->ld_drv_map
[i
]))
7340 vfree(fusion
->ld_drv_map
[i
]);
7342 free_pages((ulong
)fusion
->ld_drv_map
[i
],
7343 fusion
->drv_map_pages
);
7346 if (fusion
->pd_seq_sync
[i
])
7347 dma_free_coherent(&instance
->pdev
->dev
,
7349 fusion
->pd_seq_sync
[i
],
7350 fusion
->pd_seq_phys
[i
]);
7353 megasas_release_mfi(instance
);
7356 if (instance
->vf_affiliation
)
7357 dma_free_coherent(&pdev
->dev
, (MAX_LOGICAL_DRIVES
+ 1) *
7358 sizeof(struct MR_LD_VF_AFFILIATION
),
7359 instance
->vf_affiliation
,
7360 instance
->vf_affiliation_h
);
7362 if (instance
->vf_affiliation_111
)
7363 dma_free_coherent(&pdev
->dev
,
7364 sizeof(struct MR_LD_VF_AFFILIATION_111
),
7365 instance
->vf_affiliation_111
,
7366 instance
->vf_affiliation_111_h
);
7368 if (instance
->hb_host_mem
)
7369 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_CTRL_HB_HOST_MEM
),
7370 instance
->hb_host_mem
,
7371 instance
->hb_host_mem_h
);
7373 megasas_free_ctrl_dma_buffers(instance
);
7375 megasas_free_ctrl_mem(instance
);
7377 scsi_host_put(host
);
7379 pci_disable_device(pdev
);
7383 * megasas_shutdown - Shutdown entry point
7384 * @device: Generic device structure
7386 static void megasas_shutdown(struct pci_dev
*pdev
)
7388 struct megasas_instance
*instance
= pci_get_drvdata(pdev
);
7390 instance
->unload
= 1;
7392 if (megasas_wait_for_adapter_operational(instance
))
7393 goto skip_firing_dcmds
;
7395 megasas_flush_cache(instance
);
7396 megasas_shutdown_controller(instance
, MR_DCMD_CTRL_SHUTDOWN
);
7399 instance
->instancet
->disable_intr(instance
);
7400 megasas_destroy_irqs(instance
);
7402 if (instance
->msix_vectors
)
7403 pci_free_irq_vectors(instance
->pdev
);
7407 * megasas_mgmt_open - char node "open" entry point
7409 static int megasas_mgmt_open(struct inode
*inode
, struct file
*filep
)
7412 * Allow only those users with admin rights
7414 if (!capable(CAP_SYS_ADMIN
))
7421 * megasas_mgmt_fasync - Async notifier registration from applications
7423 * This function adds the calling process to a driver global queue. When an
7424 * event occurs, SIGIO will be sent to all processes in this queue.
7426 static int megasas_mgmt_fasync(int fd
, struct file
*filep
, int mode
)
7430 mutex_lock(&megasas_async_queue_mutex
);
7432 rc
= fasync_helper(fd
, filep
, mode
, &megasas_async_queue
);
7434 mutex_unlock(&megasas_async_queue_mutex
);
7437 /* For sanity check when we get ioctl */
7438 filep
->private_data
= filep
;
7442 printk(KERN_DEBUG
"megasas: fasync_helper failed [%d]\n", rc
);
7448 * megasas_mgmt_poll - char node "poll" entry point
7450 static __poll_t
megasas_mgmt_poll(struct file
*file
, poll_table
*wait
)
7453 unsigned long flags
;
7455 poll_wait(file
, &megasas_poll_wait
, wait
);
7456 spin_lock_irqsave(&poll_aen_lock
, flags
);
7457 if (megasas_poll_wait_aen
)
7458 mask
= (EPOLLIN
| EPOLLRDNORM
);
7461 megasas_poll_wait_aen
= 0;
7462 spin_unlock_irqrestore(&poll_aen_lock
, flags
);
7467 * megasas_set_crash_dump_params_ioctl:
7468 * Send CRASH_DUMP_MODE DCMD to all controllers
7469 * @cmd: MFI command frame
7472 static int megasas_set_crash_dump_params_ioctl(struct megasas_cmd
*cmd
)
7474 struct megasas_instance
*local_instance
;
7478 crash_support
= cmd
->frame
->dcmd
.mbox
.w
[0];
7480 for (i
= 0; i
< megasas_mgmt_info
.max_index
; i
++) {
7481 local_instance
= megasas_mgmt_info
.instance
[i
];
7482 if (local_instance
&& local_instance
->crash_dump_drv_support
) {
7483 if ((atomic_read(&local_instance
->adprecovery
) ==
7484 MEGASAS_HBA_OPERATIONAL
) &&
7485 !megasas_set_crash_dump_params(local_instance
,
7487 local_instance
->crash_dump_app_support
=
7489 dev_info(&local_instance
->pdev
->dev
,
7490 "Application firmware crash "
7491 "dump mode set success\n");
7494 dev_info(&local_instance
->pdev
->dev
,
7495 "Application firmware crash "
7496 "dump mode set failed\n");
7505 * megasas_mgmt_fw_ioctl - Issues management ioctls to FW
7506 * @instance: Adapter soft state
7507 * @argp: User's ioctl packet
7510 megasas_mgmt_fw_ioctl(struct megasas_instance
*instance
,
7511 struct megasas_iocpacket __user
* user_ioc
,
7512 struct megasas_iocpacket
*ioc
)
7514 struct megasas_sge64
*kern_sge64
= NULL
;
7515 struct megasas_sge32
*kern_sge32
= NULL
;
7516 struct megasas_cmd
*cmd
;
7517 void *kbuff_arr
[MAX_IOCTL_SGE
];
7518 dma_addr_t buf_handle
= 0;
7521 dma_addr_t sense_handle
;
7522 unsigned long *sense_ptr
;
7525 memset(kbuff_arr
, 0, sizeof(kbuff_arr
));
7527 if (ioc
->sge_count
> MAX_IOCTL_SGE
) {
7528 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SGE count [%d] > max limit [%d]\n",
7529 ioc
->sge_count
, MAX_IOCTL_SGE
);
7533 if ((ioc
->frame
.hdr
.cmd
>= MFI_CMD_OP_COUNT
) ||
7534 ((ioc
->frame
.hdr
.cmd
== MFI_CMD_NVME
) &&
7535 !instance
->support_nvme_passthru
)) {
7536 dev_err(&instance
->pdev
->dev
,
7537 "Received invalid ioctl command 0x%x\n",
7538 ioc
->frame
.hdr
.cmd
);
7542 cmd
= megasas_get_cmd(instance
);
7544 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get a cmd packet\n");
7549 * User's IOCTL packet has 2 frames (maximum). Copy those two
7550 * frames into our cmd's frames. cmd->frame's context will get
7551 * overwritten when we copy from user's frames. So set that value
7554 memcpy(cmd
->frame
, ioc
->frame
.raw
, 2 * MEGAMFI_FRAME_SIZE
);
7555 cmd
->frame
->hdr
.context
= cpu_to_le32(cmd
->index
);
7556 cmd
->frame
->hdr
.pad_0
= 0;
7558 cmd
->frame
->hdr
.flags
&= (~MFI_FRAME_IEEE
);
7560 if (instance
->consistent_mask_64bit
)
7561 cmd
->frame
->hdr
.flags
|= cpu_to_le16((MFI_FRAME_SGL64
|
7562 MFI_FRAME_SENSE64
));
7564 cmd
->frame
->hdr
.flags
&= cpu_to_le16(~(MFI_FRAME_SGL64
|
7565 MFI_FRAME_SENSE64
));
7567 if (cmd
->frame
->hdr
.cmd
== MFI_CMD_DCMD
)
7568 opcode
= le32_to_cpu(cmd
->frame
->dcmd
.opcode
);
7570 if (opcode
== MR_DCMD_CTRL_SHUTDOWN
) {
7571 if (megasas_get_ctrl_info(instance
) != DCMD_SUCCESS
) {
7572 megasas_return_cmd(instance
, cmd
);
7577 if (opcode
== MR_DRIVER_SET_APP_CRASHDUMP_MODE
) {
7578 error
= megasas_set_crash_dump_params_ioctl(cmd
);
7579 megasas_return_cmd(instance
, cmd
);
7584 * The management interface between applications and the fw uses
7585 * MFI frames. E.g, RAID configuration changes, LD property changes
7586 * etc are accomplishes through different kinds of MFI frames. The
7587 * driver needs to care only about substituting user buffers with
7588 * kernel buffers in SGLs. The location of SGL is embedded in the
7589 * struct iocpacket itself.
7591 if (instance
->consistent_mask_64bit
)
7592 kern_sge64
= (struct megasas_sge64
*)
7593 ((unsigned long)cmd
->frame
+ ioc
->sgl_off
);
7595 kern_sge32
= (struct megasas_sge32
*)
7596 ((unsigned long)cmd
->frame
+ ioc
->sgl_off
);
7599 * For each user buffer, create a mirror buffer and copy in
7601 for (i
= 0; i
< ioc
->sge_count
; i
++) {
7602 if (!ioc
->sgl
[i
].iov_len
)
7605 kbuff_arr
[i
] = dma_alloc_coherent(&instance
->pdev
->dev
,
7606 ioc
->sgl
[i
].iov_len
,
7607 &buf_handle
, GFP_KERNEL
);
7608 if (!kbuff_arr
[i
]) {
7609 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to alloc "
7610 "kernel SGL buffer for IOCTL\n");
7616 * We don't change the dma_coherent_mask, so
7617 * dma_alloc_coherent only returns 32bit addresses
7619 if (instance
->consistent_mask_64bit
) {
7620 kern_sge64
[i
].phys_addr
= cpu_to_le64(buf_handle
);
7621 kern_sge64
[i
].length
= cpu_to_le32(ioc
->sgl
[i
].iov_len
);
7623 kern_sge32
[i
].phys_addr
= cpu_to_le32(buf_handle
);
7624 kern_sge32
[i
].length
= cpu_to_le32(ioc
->sgl
[i
].iov_len
);
7628 * We created a kernel buffer corresponding to the
7629 * user buffer. Now copy in from the user buffer
7631 if (copy_from_user(kbuff_arr
[i
], ioc
->sgl
[i
].iov_base
,
7632 (u32
) (ioc
->sgl
[i
].iov_len
))) {
7638 if (ioc
->sense_len
) {
7639 sense
= dma_alloc_coherent(&instance
->pdev
->dev
, ioc
->sense_len
,
7640 &sense_handle
, GFP_KERNEL
);
7647 (unsigned long *) ((unsigned long)cmd
->frame
+ ioc
->sense_off
);
7648 if (instance
->consistent_mask_64bit
)
7649 *sense_ptr
= cpu_to_le64(sense_handle
);
7651 *sense_ptr
= cpu_to_le32(sense_handle
);
7655 * Set the sync_cmd flag so that the ISR knows not to complete this
7656 * cmd to the SCSI mid-layer
7659 if (megasas_issue_blocked_cmd(instance
, cmd
, 0) == DCMD_NOT_FIRED
) {
7661 dev_err(&instance
->pdev
->dev
,
7662 "return -EBUSY from %s %d cmd 0x%x opcode 0x%x cmd->cmd_status_drv 0x%x\n",
7663 __func__
, __LINE__
, cmd
->frame
->hdr
.cmd
, opcode
,
7664 cmd
->cmd_status_drv
);
7670 if (instance
->unload
== 1) {
7671 dev_info(&instance
->pdev
->dev
, "Driver unload is in progress "
7672 "don't submit data to application\n");
7676 * copy out the kernel buffers to user buffers
7678 for (i
= 0; i
< ioc
->sge_count
; i
++) {
7679 if (copy_to_user(ioc
->sgl
[i
].iov_base
, kbuff_arr
[i
],
7680 ioc
->sgl
[i
].iov_len
)) {
7687 * copy out the sense
7689 if (ioc
->sense_len
) {
7691 * sense_ptr points to the location that has the user
7692 * sense buffer address
7694 sense_ptr
= (unsigned long *) ((unsigned long)ioc
->frame
.raw
+
7697 if (copy_to_user((void __user
*)((unsigned long)
7698 get_unaligned((unsigned long *)sense_ptr
)),
7699 sense
, ioc
->sense_len
)) {
7700 dev_err(&instance
->pdev
->dev
, "Failed to copy out to user "
7708 * copy the status codes returned by the fw
7710 if (copy_to_user(&user_ioc
->frame
.hdr
.cmd_status
,
7711 &cmd
->frame
->hdr
.cmd_status
, sizeof(u8
))) {
7712 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Error copying out cmd_status\n");
7718 dma_free_coherent(&instance
->pdev
->dev
, ioc
->sense_len
,
7719 sense
, sense_handle
);
7722 for (i
= 0; i
< ioc
->sge_count
; i
++) {
7724 if (instance
->consistent_mask_64bit
)
7725 dma_free_coherent(&instance
->pdev
->dev
,
7726 le32_to_cpu(kern_sge64
[i
].length
),
7728 le64_to_cpu(kern_sge64
[i
].phys_addr
));
7730 dma_free_coherent(&instance
->pdev
->dev
,
7731 le32_to_cpu(kern_sge32
[i
].length
),
7733 le32_to_cpu(kern_sge32
[i
].phys_addr
));
7734 kbuff_arr
[i
] = NULL
;
7738 megasas_return_cmd(instance
, cmd
);
7742 static int megasas_mgmt_ioctl_fw(struct file
*file
, unsigned long arg
)
7744 struct megasas_iocpacket __user
*user_ioc
=
7745 (struct megasas_iocpacket __user
*)arg
;
7746 struct megasas_iocpacket
*ioc
;
7747 struct megasas_instance
*instance
;
7750 ioc
= memdup_user(user_ioc
, sizeof(*ioc
));
7752 return PTR_ERR(ioc
);
7754 instance
= megasas_lookup_instance(ioc
->host_no
);
7760 /* Block ioctls in VF mode */
7761 if (instance
->requestorId
&& !allow_vf_ioctls
) {
7766 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
7767 dev_err(&instance
->pdev
->dev
, "Controller in crit error\n");
7772 if (instance
->unload
== 1) {
7777 if (down_interruptible(&instance
->ioctl_sem
)) {
7778 error
= -ERESTARTSYS
;
7782 if (megasas_wait_for_adapter_operational(instance
)) {
7787 error
= megasas_mgmt_fw_ioctl(instance
, user_ioc
, ioc
);
7789 up(&instance
->ioctl_sem
);
7796 static int megasas_mgmt_ioctl_aen(struct file
*file
, unsigned long arg
)
7798 struct megasas_instance
*instance
;
7799 struct megasas_aen aen
;
7802 if (file
->private_data
!= file
) {
7803 printk(KERN_DEBUG
"megasas: fasync_helper was not "
7808 if (copy_from_user(&aen
, (void __user
*)arg
, sizeof(aen
)))
7811 instance
= megasas_lookup_instance(aen
.host_no
);
7816 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
7820 if (instance
->unload
== 1) {
7824 if (megasas_wait_for_adapter_operational(instance
))
7827 mutex_lock(&instance
->reset_mutex
);
7828 error
= megasas_register_aen(instance
, aen
.seq_num
,
7829 aen
.class_locale_word
);
7830 mutex_unlock(&instance
->reset_mutex
);
7835 * megasas_mgmt_ioctl - char node ioctl entry point
7838 megasas_mgmt_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
7841 case MEGASAS_IOC_FIRMWARE
:
7842 return megasas_mgmt_ioctl_fw(file
, arg
);
7844 case MEGASAS_IOC_GET_AEN
:
7845 return megasas_mgmt_ioctl_aen(file
, arg
);
7851 #ifdef CONFIG_COMPAT
7852 static int megasas_mgmt_compat_ioctl_fw(struct file
*file
, unsigned long arg
)
7854 struct compat_megasas_iocpacket __user
*cioc
=
7855 (struct compat_megasas_iocpacket __user
*)arg
;
7856 struct megasas_iocpacket __user
*ioc
=
7857 compat_alloc_user_space(sizeof(struct megasas_iocpacket
));
7861 u32 local_sense_off
;
7862 u32 local_sense_len
;
7865 if (clear_user(ioc
, sizeof(*ioc
)))
7868 if (copy_in_user(&ioc
->host_no
, &cioc
->host_no
, sizeof(u16
)) ||
7869 copy_in_user(&ioc
->sgl_off
, &cioc
->sgl_off
, sizeof(u32
)) ||
7870 copy_in_user(&ioc
->sense_off
, &cioc
->sense_off
, sizeof(u32
)) ||
7871 copy_in_user(&ioc
->sense_len
, &cioc
->sense_len
, sizeof(u32
)) ||
7872 copy_in_user(ioc
->frame
.raw
, cioc
->frame
.raw
, 128) ||
7873 copy_in_user(&ioc
->sge_count
, &cioc
->sge_count
, sizeof(u32
)))
7877 * The sense_ptr is used in megasas_mgmt_fw_ioctl only when
7878 * sense_len is not null, so prepare the 64bit value under
7879 * the same condition.
7881 if (get_user(local_sense_off
, &ioc
->sense_off
) ||
7882 get_user(local_sense_len
, &ioc
->sense_len
) ||
7883 get_user(user_sense_off
, &cioc
->sense_off
))
7886 if (local_sense_off
!= user_sense_off
)
7889 if (local_sense_len
) {
7890 void __user
**sense_ioc_ptr
=
7891 (void __user
**)((u8
*)((unsigned long)&ioc
->frame
.raw
) + local_sense_off
);
7892 compat_uptr_t
*sense_cioc_ptr
=
7893 (compat_uptr_t
*)(((unsigned long)&cioc
->frame
.raw
) + user_sense_off
);
7894 if (get_user(ptr
, sense_cioc_ptr
) ||
7895 put_user(compat_ptr(ptr
), sense_ioc_ptr
))
7899 for (i
= 0; i
< MAX_IOCTL_SGE
; i
++) {
7900 if (get_user(ptr
, &cioc
->sgl
[i
].iov_base
) ||
7901 put_user(compat_ptr(ptr
), &ioc
->sgl
[i
].iov_base
) ||
7902 copy_in_user(&ioc
->sgl
[i
].iov_len
,
7903 &cioc
->sgl
[i
].iov_len
, sizeof(compat_size_t
)))
7907 error
= megasas_mgmt_ioctl_fw(file
, (unsigned long)ioc
);
7909 if (copy_in_user(&cioc
->frame
.hdr
.cmd_status
,
7910 &ioc
->frame
.hdr
.cmd_status
, sizeof(u8
))) {
7911 printk(KERN_DEBUG
"megasas: error copy_in_user cmd_status\n");
7918 megasas_mgmt_compat_ioctl(struct file
*file
, unsigned int cmd
,
7922 case MEGASAS_IOC_FIRMWARE32
:
7923 return megasas_mgmt_compat_ioctl_fw(file
, arg
);
7924 case MEGASAS_IOC_GET_AEN
:
7925 return megasas_mgmt_ioctl_aen(file
, arg
);
7933 * File operations structure for management interface
7935 static const struct file_operations megasas_mgmt_fops
= {
7936 .owner
= THIS_MODULE
,
7937 .open
= megasas_mgmt_open
,
7938 .fasync
= megasas_mgmt_fasync
,
7939 .unlocked_ioctl
= megasas_mgmt_ioctl
,
7940 .poll
= megasas_mgmt_poll
,
7941 #ifdef CONFIG_COMPAT
7942 .compat_ioctl
= megasas_mgmt_compat_ioctl
,
7944 .llseek
= noop_llseek
,
7948 * PCI hotplug support registration structure
7950 static struct pci_driver megasas_pci_driver
= {
7952 .name
= "megaraid_sas",
7953 .id_table
= megasas_pci_table
,
7954 .probe
= megasas_probe_one
,
7955 .remove
= megasas_detach_one
,
7956 .suspend
= megasas_suspend
,
7957 .resume
= megasas_resume
,
7958 .shutdown
= megasas_shutdown
,
7962 * Sysfs driver attributes
7964 static ssize_t
version_show(struct device_driver
*dd
, char *buf
)
7966 return snprintf(buf
, strlen(MEGASAS_VERSION
) + 2, "%s\n",
7969 static DRIVER_ATTR_RO(version
);
7971 static ssize_t
release_date_show(struct device_driver
*dd
, char *buf
)
7973 return snprintf(buf
, strlen(MEGASAS_RELDATE
) + 2, "%s\n",
7976 static DRIVER_ATTR_RO(release_date
);
7978 static ssize_t
support_poll_for_event_show(struct device_driver
*dd
, char *buf
)
7980 return sprintf(buf
, "%u\n", support_poll_for_event
);
7982 static DRIVER_ATTR_RO(support_poll_for_event
);
7984 static ssize_t
support_device_change_show(struct device_driver
*dd
, char *buf
)
7986 return sprintf(buf
, "%u\n", support_device_change
);
7988 static DRIVER_ATTR_RO(support_device_change
);
7990 static ssize_t
dbg_lvl_show(struct device_driver
*dd
, char *buf
)
7992 return sprintf(buf
, "%u\n", megasas_dbg_lvl
);
7995 static ssize_t
dbg_lvl_store(struct device_driver
*dd
, const char *buf
,
8000 if (sscanf(buf
, "%u", &megasas_dbg_lvl
) < 1) {
8001 printk(KERN_ERR
"megasas: could not set dbg_lvl\n");
8006 static DRIVER_ATTR_RW(dbg_lvl
);
8009 support_nvme_encapsulation_show(struct device_driver
*dd
, char *buf
)
8011 return sprintf(buf
, "%u\n", support_nvme_encapsulation
);
8014 static DRIVER_ATTR_RO(support_nvme_encapsulation
);
8016 static inline void megasas_remove_scsi_device(struct scsi_device
*sdev
)
8018 sdev_printk(KERN_INFO
, sdev
, "SCSI device is removed\n");
8019 scsi_remove_device(sdev
);
8020 scsi_device_put(sdev
);
8024 * megasas_update_device_list - Update the PD and LD device list from FW
8025 * after an AEN event notification
8026 * @instance: Adapter soft state
8027 * @event_type: Indicates type of event (PD or LD event)
8029 * @return: Success or failure
8031 * Issue DCMDs to Firmware to update the internal device list in driver.
8032 * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
8033 * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
8036 int megasas_update_device_list(struct megasas_instance
*instance
,
8039 int dcmd_ret
= DCMD_SUCCESS
;
8041 if (instance
->enable_fw_dev_list
) {
8042 dcmd_ret
= megasas_host_device_list_query(instance
, false);
8043 if (dcmd_ret
!= DCMD_SUCCESS
)
8046 if (event_type
& SCAN_PD_CHANNEL
) {
8047 dcmd_ret
= megasas_get_pd_list(instance
);
8049 if (dcmd_ret
!= DCMD_SUCCESS
)
8053 if (event_type
& SCAN_VD_CHANNEL
) {
8054 if (!instance
->requestorId
||
8055 (instance
->requestorId
&&
8056 megasas_get_ld_vf_affiliation(instance
, 0))) {
8057 dcmd_ret
= megasas_ld_list_query(instance
,
8058 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST
);
8059 if (dcmd_ret
!= DCMD_SUCCESS
)
8070 * megasas_add_remove_devices - Add/remove devices to SCSI mid-layer
8071 * after an AEN event notification
8072 * @instance: Adapter soft state
8073 * @scan_type: Indicates type of devices (PD/LD) to add
8077 void megasas_add_remove_devices(struct megasas_instance
*instance
,
8083 u16 channel
= 0, id
= 0;
8084 struct Scsi_Host
*host
;
8085 struct scsi_device
*sdev1
;
8086 struct MR_HOST_DEVICE_LIST
*targetid_list
= NULL
;
8087 struct MR_HOST_DEVICE_LIST_ENTRY
*targetid_entry
= NULL
;
8089 host
= instance
->host
;
8091 if (instance
->enable_fw_dev_list
) {
8092 targetid_list
= instance
->host_device_list_buf
;
8093 for (i
= 0; i
< targetid_list
->count
; i
++) {
8094 targetid_entry
= &targetid_list
->host_device_list
[i
];
8095 if (targetid_entry
->flags
.u
.bits
.is_sys_pd
) {
8096 channel
= le16_to_cpu(targetid_entry
->target_id
) /
8097 MEGASAS_MAX_DEV_PER_CHANNEL
;
8098 id
= le16_to_cpu(targetid_entry
->target_id
) %
8099 MEGASAS_MAX_DEV_PER_CHANNEL
;
8101 channel
= MEGASAS_MAX_PD_CHANNELS
+
8102 (le16_to_cpu(targetid_entry
->target_id
) /
8103 MEGASAS_MAX_DEV_PER_CHANNEL
);
8104 id
= le16_to_cpu(targetid_entry
->target_id
) %
8105 MEGASAS_MAX_DEV_PER_CHANNEL
;
8107 sdev1
= scsi_device_lookup(host
, channel
, id
, 0);
8109 scsi_add_device(host
, channel
, id
, 0);
8111 scsi_device_put(sdev1
);
8116 if (scan_type
& SCAN_PD_CHANNEL
) {
8117 for (i
= 0; i
< MEGASAS_MAX_PD_CHANNELS
; i
++) {
8118 for (j
= 0; j
< MEGASAS_MAX_DEV_PER_CHANNEL
; j
++) {
8119 pd_index
= i
* MEGASAS_MAX_DEV_PER_CHANNEL
+ j
;
8120 sdev1
= scsi_device_lookup(host
, i
, j
, 0);
8121 if (instance
->pd_list
[pd_index
].driveState
==
8122 MR_PD_STATE_SYSTEM
) {
8124 scsi_add_device(host
, i
, j
, 0);
8126 scsi_device_put(sdev1
);
8129 megasas_remove_scsi_device(sdev1
);
8135 if (scan_type
& SCAN_VD_CHANNEL
) {
8136 for (i
= 0; i
< MEGASAS_MAX_LD_CHANNELS
; i
++) {
8137 for (j
= 0; j
< MEGASAS_MAX_DEV_PER_CHANNEL
; j
++) {
8138 ld_index
= (i
* MEGASAS_MAX_DEV_PER_CHANNEL
) + j
;
8139 sdev1
= scsi_device_lookup(host
,
8140 MEGASAS_MAX_PD_CHANNELS
+ i
, j
, 0);
8141 if (instance
->ld_ids
[ld_index
] != 0xff) {
8143 scsi_add_device(host
, MEGASAS_MAX_PD_CHANNELS
+ i
, j
, 0);
8145 scsi_device_put(sdev1
);
8148 megasas_remove_scsi_device(sdev1
);
8157 megasas_aen_polling(struct work_struct
*work
)
8159 struct megasas_aen_event
*ev
=
8160 container_of(work
, struct megasas_aen_event
, hotplug_work
.work
);
8161 struct megasas_instance
*instance
= ev
->instance
;
8162 union megasas_evt_class_locale class_locale
;
8164 u32 seq_num
, wait_time
= MEGASAS_RESET_WAIT_TIME
;
8166 u8 dcmd_ret
= DCMD_SUCCESS
;
8169 printk(KERN_ERR
"invalid instance!\n");
8174 /* Adjust event workqueue thread wait time for VF mode */
8175 if (instance
->requestorId
)
8176 wait_time
= MEGASAS_ROUTINE_WAIT_TIME_VF
;
8178 /* Don't run the event workqueue thread if OCR is running */
8179 mutex_lock(&instance
->reset_mutex
);
8181 instance
->ev
= NULL
;
8182 if (instance
->evt_detail
) {
8183 megasas_decode_evt(instance
);
8185 switch (le32_to_cpu(instance
->evt_detail
->code
)) {
8187 case MR_EVT_PD_INSERTED
:
8188 case MR_EVT_PD_REMOVED
:
8189 event_type
= SCAN_PD_CHANNEL
;
8192 case MR_EVT_LD_OFFLINE
:
8193 case MR_EVT_CFG_CLEARED
:
8194 case MR_EVT_LD_DELETED
:
8195 case MR_EVT_LD_CREATED
:
8196 event_type
= SCAN_VD_CHANNEL
;
8199 case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED
:
8200 case MR_EVT_FOREIGN_CFG_IMPORTED
:
8201 case MR_EVT_LD_STATE_CHANGE
:
8202 event_type
= SCAN_PD_CHANNEL
| SCAN_VD_CHANNEL
;
8203 dev_info(&instance
->pdev
->dev
, "scanning for scsi%d...\n",
8204 instance
->host
->host_no
);
8207 case MR_EVT_CTRL_PROP_CHANGED
:
8208 dcmd_ret
= megasas_get_ctrl_info(instance
);
8209 if (dcmd_ret
== DCMD_SUCCESS
&&
8210 instance
->snapdump_wait_time
) {
8211 megasas_get_snapdump_properties(instance
);
8212 dev_info(&instance
->pdev
->dev
,
8213 "Snap dump wait time\t: %d\n",
8214 instance
->snapdump_wait_time
);
8222 dev_err(&instance
->pdev
->dev
, "invalid evt_detail!\n");
8223 mutex_unlock(&instance
->reset_mutex
);
8229 dcmd_ret
= megasas_update_device_list(instance
, event_type
);
8231 mutex_unlock(&instance
->reset_mutex
);
8233 if (event_type
&& dcmd_ret
== DCMD_SUCCESS
)
8234 megasas_add_remove_devices(instance
, event_type
);
8236 if (dcmd_ret
== DCMD_SUCCESS
)
8237 seq_num
= le32_to_cpu(instance
->evt_detail
->seq_num
) + 1;
8239 seq_num
= instance
->last_seq_num
;
8241 /* Register AEN with FW for latest sequence number plus 1 */
8242 class_locale
.members
.reserved
= 0;
8243 class_locale
.members
.locale
= MR_EVT_LOCALE_ALL
;
8244 class_locale
.members
.class = MR_EVT_CLASS_DEBUG
;
8246 if (instance
->aen_cmd
!= NULL
) {
8251 mutex_lock(&instance
->reset_mutex
);
8252 error
= megasas_register_aen(instance
, seq_num
,
8255 dev_err(&instance
->pdev
->dev
,
8256 "register aen failed error %x\n", error
);
8258 mutex_unlock(&instance
->reset_mutex
);
8263 * megasas_init - Driver load entry point
8265 static int __init
megasas_init(void)
8270 * Booted in kdump kernel, minimize memory footprints by
8271 * disabling few features
8273 if (reset_devices
) {
8276 dual_qdepth_disable
= 1;
8280 * Announce driver version and other information
8282 pr_info("megasas: %s\n", MEGASAS_VERSION
);
8284 spin_lock_init(&poll_aen_lock
);
8286 support_poll_for_event
= 2;
8287 support_device_change
= 1;
8288 support_nvme_encapsulation
= true;
8290 memset(&megasas_mgmt_info
, 0, sizeof(megasas_mgmt_info
));
8293 * Register character device node
8295 rval
= register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops
);
8298 printk(KERN_DEBUG
"megasas: failed to open device node\n");
8302 megasas_mgmt_majorno
= rval
;
8305 * Register ourselves as PCI hotplug module
8307 rval
= pci_register_driver(&megasas_pci_driver
);
8310 printk(KERN_DEBUG
"megasas: PCI hotplug registration failed \n");
8314 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8315 &driver_attr_version
);
8317 goto err_dcf_attr_ver
;
8319 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8320 &driver_attr_release_date
);
8322 goto err_dcf_rel_date
;
8324 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8325 &driver_attr_support_poll_for_event
);
8327 goto err_dcf_support_poll_for_event
;
8329 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8330 &driver_attr_dbg_lvl
);
8332 goto err_dcf_dbg_lvl
;
8333 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8334 &driver_attr_support_device_change
);
8336 goto err_dcf_support_device_change
;
8338 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8339 &driver_attr_support_nvme_encapsulation
);
8341 goto err_dcf_support_nvme_encapsulation
;
8345 err_dcf_support_nvme_encapsulation
:
8346 driver_remove_file(&megasas_pci_driver
.driver
,
8347 &driver_attr_support_device_change
);
8349 err_dcf_support_device_change
:
8350 driver_remove_file(&megasas_pci_driver
.driver
,
8351 &driver_attr_dbg_lvl
);
8353 driver_remove_file(&megasas_pci_driver
.driver
,
8354 &driver_attr_support_poll_for_event
);
8355 err_dcf_support_poll_for_event
:
8356 driver_remove_file(&megasas_pci_driver
.driver
,
8357 &driver_attr_release_date
);
8359 driver_remove_file(&megasas_pci_driver
.driver
, &driver_attr_version
);
8361 pci_unregister_driver(&megasas_pci_driver
);
8363 unregister_chrdev(megasas_mgmt_majorno
, "megaraid_sas_ioctl");
8368 * megasas_exit - Driver unload entry point
8370 static void __exit
megasas_exit(void)
8372 driver_remove_file(&megasas_pci_driver
.driver
,
8373 &driver_attr_dbg_lvl
);
8374 driver_remove_file(&megasas_pci_driver
.driver
,
8375 &driver_attr_support_poll_for_event
);
8376 driver_remove_file(&megasas_pci_driver
.driver
,
8377 &driver_attr_support_device_change
);
8378 driver_remove_file(&megasas_pci_driver
.driver
,
8379 &driver_attr_release_date
);
8380 driver_remove_file(&megasas_pci_driver
.driver
, &driver_attr_version
);
8381 driver_remove_file(&megasas_pci_driver
.driver
,
8382 &driver_attr_support_nvme_encapsulation
);
8384 pci_unregister_driver(&megasas_pci_driver
);
8385 unregister_chrdev(megasas_mgmt_majorno
, "megaraid_sas_ioctl");
8388 module_init(megasas_init
);
8389 module_exit(megasas_exit
);