2 * Linux MegaRAID driver for SAS based RAID controllers
4 * Copyright (c) 2003-2013 LSI Corporation
5 * Copyright (c) 2013-2016 Avago Technologies
6 * Copyright (c) 2016-2018 Broadcom Inc.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Authors: Broadcom Inc.
26 * Kashyap Desai <kashyap.desai@broadcom.com>
27 * Sumit Saxena <sumit.saxena@broadcom.com>
29 * Send feedback to: megaraidlinux.pdl@broadcom.com
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/pci.h>
35 #include <linux/list.h>
36 #include <linux/moduleparam.h>
37 #include <linux/module.h>
38 #include <linux/spinlock.h>
39 #include <linux/interrupt.h>
40 #include <linux/delay.h>
41 #include <linux/uio.h>
42 #include <linux/slab.h>
43 #include <linux/uaccess.h>
44 #include <asm/unaligned.h>
46 #include <linux/compat.h>
47 #include <linux/blkdev.h>
48 #include <linux/mutex.h>
49 #include <linux/poll.h>
50 #include <linux/vmalloc.h>
51 #include <linux/irq_poll.h>
53 #include <scsi/scsi.h>
54 #include <scsi/scsi_cmnd.h>
55 #include <scsi/scsi_device.h>
56 #include <scsi/scsi_host.h>
57 #include <scsi/scsi_tcq.h>
58 #include <scsi/scsi_dbg.h>
59 #include "megaraid_sas_fusion.h"
60 #include "megaraid_sas.h"
63 * Number of sectors per IO command
64 * Will be set in megasas_init_mfi if user does not provide
66 static unsigned int max_sectors
;
67 module_param_named(max_sectors
, max_sectors
, int, 0);
68 MODULE_PARM_DESC(max_sectors
,
69 "Maximum number of sectors per IO command");
71 static int msix_disable
;
72 module_param(msix_disable
, int, S_IRUGO
);
73 MODULE_PARM_DESC(msix_disable
, "Disable MSI-X interrupt handling. Default: 0");
75 static unsigned int msix_vectors
;
76 module_param(msix_vectors
, int, S_IRUGO
);
77 MODULE_PARM_DESC(msix_vectors
, "MSI-X max vector count. Default: Set by FW");
79 static int allow_vf_ioctls
;
80 module_param(allow_vf_ioctls
, int, S_IRUGO
);
81 MODULE_PARM_DESC(allow_vf_ioctls
, "Allow ioctls in SR-IOV VF mode. Default: 0");
83 static unsigned int throttlequeuedepth
= MEGASAS_THROTTLE_QUEUE_DEPTH
;
84 module_param(throttlequeuedepth
, int, S_IRUGO
);
85 MODULE_PARM_DESC(throttlequeuedepth
,
86 "Adapter queue depth when throttled due to I/O timeout. Default: 16");
88 unsigned int resetwaittime
= MEGASAS_RESET_WAIT_TIME
;
89 module_param(resetwaittime
, int, S_IRUGO
);
90 MODULE_PARM_DESC(resetwaittime
, "Wait time in (1-180s) after I/O timeout before resetting adapter. Default: 180s");
92 int smp_affinity_enable
= 1;
93 module_param(smp_affinity_enable
, int, S_IRUGO
);
94 MODULE_PARM_DESC(smp_affinity_enable
, "SMP affinity feature enable/disable Default: enable(1)");
97 module_param(rdpq_enable
, int, S_IRUGO
);
98 MODULE_PARM_DESC(rdpq_enable
, "Allocate reply queue in chunks for large queue depth enable/disable Default: enable(1)");
100 unsigned int dual_qdepth_disable
;
101 module_param(dual_qdepth_disable
, int, S_IRUGO
);
102 MODULE_PARM_DESC(dual_qdepth_disable
, "Disable dual queue depth feature. Default: 0");
104 unsigned int scmd_timeout
= MEGASAS_DEFAULT_CMD_TIMEOUT
;
105 module_param(scmd_timeout
, int, S_IRUGO
);
106 MODULE_PARM_DESC(scmd_timeout
, "scsi command timeout (10-90s), default 90s. See megasas_reset_timer.");
108 MODULE_LICENSE("GPL");
109 MODULE_VERSION(MEGASAS_VERSION
);
110 MODULE_AUTHOR("megaraidlinux.pdl@broadcom.com");
111 MODULE_DESCRIPTION("Broadcom MegaRAID SAS Driver");
113 int megasas_transition_to_ready(struct megasas_instance
*instance
, int ocr
);
114 static int megasas_get_pd_list(struct megasas_instance
*instance
);
115 static int megasas_ld_list_query(struct megasas_instance
*instance
,
117 static int megasas_issue_init_mfi(struct megasas_instance
*instance
);
118 static int megasas_register_aen(struct megasas_instance
*instance
,
119 u32 seq_num
, u32 class_locale_word
);
120 static void megasas_get_pd_info(struct megasas_instance
*instance
,
121 struct scsi_device
*sdev
);
124 * PCI ID table for all supported controllers
126 static struct pci_device_id megasas_pci_table
[] = {
128 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1064R
)},
130 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1078R
)},
132 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1078DE
)},
134 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS1078GEN2
)},
136 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS0079GEN2
)},
138 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS0073SKINNY
)},
140 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_SAS0071SKINNY
)},
142 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_VERDE_ZCR
)},
143 /* xscale IOP, vega */
144 {PCI_DEVICE(PCI_VENDOR_ID_DELL
, PCI_DEVICE_ID_DELL_PERC5
)},
146 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_FUSION
)},
148 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_PLASMA
)},
150 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_INVADER
)},
152 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_FURY
)},
154 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_INTRUDER
)},
156 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_INTRUDER_24
)},
157 /* Intruder 24 port*/
158 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CUTLASS_52
)},
159 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CUTLASS_53
)},
161 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_VENTURA
)},
162 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CRUSADER
)},
163 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_HARPOON
)},
164 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_TOMCAT
)},
165 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_VENTURA_4PORT
)},
166 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_CRUSADER_4PORT
)},
167 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E1
)},
168 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E2
)},
169 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E5
)},
170 {PCI_DEVICE(PCI_VENDOR_ID_LSI_LOGIC
, PCI_DEVICE_ID_LSI_AERO_10E6
)},
174 MODULE_DEVICE_TABLE(pci
, megasas_pci_table
);
176 static int megasas_mgmt_majorno
;
177 struct megasas_mgmt_info megasas_mgmt_info
;
178 static struct fasync_struct
*megasas_async_queue
;
179 static DEFINE_MUTEX(megasas_async_queue_mutex
);
181 static int megasas_poll_wait_aen
;
182 static DECLARE_WAIT_QUEUE_HEAD(megasas_poll_wait
);
183 static u32 support_poll_for_event
;
185 static u32 support_device_change
;
186 static bool support_nvme_encapsulation
;
188 /* define lock for aen poll */
189 spinlock_t poll_aen_lock
;
191 extern struct dentry
*megasas_debugfs_root
;
192 extern void megasas_init_debugfs(void);
193 extern void megasas_exit_debugfs(void);
194 extern void megasas_setup_debugfs(struct megasas_instance
*instance
);
195 extern void megasas_destroy_debugfs(struct megasas_instance
*instance
);
198 megasas_complete_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
201 megasas_read_fw_status_reg_gen2(struct megasas_instance
*instance
);
203 megasas_adp_reset_gen2(struct megasas_instance
*instance
,
204 struct megasas_register_set __iomem
*reg_set
);
205 static irqreturn_t
megasas_isr(int irq
, void *devp
);
207 megasas_init_adapter_mfi(struct megasas_instance
*instance
);
209 megasas_build_and_issue_cmd(struct megasas_instance
*instance
,
210 struct scsi_cmnd
*scmd
);
211 static void megasas_complete_cmd_dpc(unsigned long instance_addr
);
213 wait_and_poll(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
215 void megasas_fusion_ocr_wq(struct work_struct
*work
);
216 static int megasas_get_ld_vf_affiliation(struct megasas_instance
*instance
,
219 megasas_set_dma_mask(struct megasas_instance
*instance
);
221 megasas_alloc_ctrl_mem(struct megasas_instance
*instance
);
223 megasas_free_ctrl_mem(struct megasas_instance
*instance
);
225 megasas_alloc_ctrl_dma_buffers(struct megasas_instance
*instance
);
227 megasas_free_ctrl_dma_buffers(struct megasas_instance
*instance
);
229 megasas_init_ctrl_params(struct megasas_instance
*instance
);
231 u32
megasas_readl(struct megasas_instance
*instance
,
232 const volatile void __iomem
*addr
)
236 * Due to a HW errata in Aero controllers, reads to certain
237 * Fusion registers could intermittently return all zeroes.
238 * This behavior is transient in nature and subsequent reads will
239 * return valid value. As a workaround in driver, retry readl for
240 * upto three times until a non-zero value is read.
242 if (instance
->adapter_type
== AERO_SERIES
) {
244 ret_val
= readl(addr
);
246 } while (ret_val
== 0 && i
< 3);
254 * megasas_set_dma_settings - Populate DMA address, length and flags for DCMDs
255 * @instance: Adapter soft state
256 * @dcmd: DCMD frame inside MFI command
257 * @dma_addr: DMA address of buffer to be passed to FW
258 * @dma_len: Length of DMA buffer to be passed to FW
261 void megasas_set_dma_settings(struct megasas_instance
*instance
,
262 struct megasas_dcmd_frame
*dcmd
,
263 dma_addr_t dma_addr
, u32 dma_len
)
265 if (instance
->consistent_mask_64bit
) {
266 dcmd
->sgl
.sge64
[0].phys_addr
= cpu_to_le64(dma_addr
);
267 dcmd
->sgl
.sge64
[0].length
= cpu_to_le32(dma_len
);
268 dcmd
->flags
= cpu_to_le16(dcmd
->flags
| MFI_FRAME_SGL64
);
271 dcmd
->sgl
.sge32
[0].phys_addr
=
272 cpu_to_le32(lower_32_bits(dma_addr
));
273 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32(dma_len
);
274 dcmd
->flags
= cpu_to_le16(dcmd
->flags
);
279 megasas_issue_dcmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
281 instance
->instancet
->fire_cmd(instance
,
282 cmd
->frame_phys_addr
, 0, instance
->reg_set
);
287 * megasas_get_cmd - Get a command from the free pool
288 * @instance: Adapter soft state
290 * Returns a free command from the pool
292 struct megasas_cmd
*megasas_get_cmd(struct megasas_instance
296 struct megasas_cmd
*cmd
= NULL
;
298 spin_lock_irqsave(&instance
->mfi_pool_lock
, flags
);
300 if (!list_empty(&instance
->cmd_pool
)) {
301 cmd
= list_entry((&instance
->cmd_pool
)->next
,
302 struct megasas_cmd
, list
);
303 list_del_init(&cmd
->list
);
305 dev_err(&instance
->pdev
->dev
, "Command pool empty!\n");
308 spin_unlock_irqrestore(&instance
->mfi_pool_lock
, flags
);
313 * megasas_return_cmd - Return a cmd to free command pool
314 * @instance: Adapter soft state
315 * @cmd: Command packet to be returned to free command pool
318 megasas_return_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
322 struct megasas_cmd_fusion
*cmd_fusion
;
323 struct fusion_context
*fusion
= instance
->ctrl_context
;
325 /* This flag is used only for fusion adapter.
326 * Wait for Interrupt for Polled mode DCMD
328 if (cmd
->flags
& DRV_DCMD_POLLED_MODE
)
331 spin_lock_irqsave(&instance
->mfi_pool_lock
, flags
);
334 blk_tags
= instance
->max_scsi_cmds
+ cmd
->index
;
335 cmd_fusion
= fusion
->cmd_list
[blk_tags
];
336 megasas_return_cmd_fusion(instance
, cmd_fusion
);
339 cmd
->frame_count
= 0;
341 memset(cmd
->frame
, 0, instance
->mfi_frame_size
);
342 cmd
->frame
->io
.context
= cpu_to_le32(cmd
->index
);
343 if (!fusion
&& reset_devices
)
344 cmd
->frame
->hdr
.cmd
= MFI_CMD_INVALID
;
345 list_add(&cmd
->list
, (&instance
->cmd_pool
)->next
);
347 spin_unlock_irqrestore(&instance
->mfi_pool_lock
, flags
);
352 format_timestamp(uint32_t timestamp
)
354 static char buffer
[32];
356 if ((timestamp
& 0xff000000) == 0xff000000)
357 snprintf(buffer
, sizeof(buffer
), "boot + %us", timestamp
&
360 snprintf(buffer
, sizeof(buffer
), "%us", timestamp
);
365 format_class(int8_t class)
367 static char buffer
[6];
370 case MFI_EVT_CLASS_DEBUG
:
372 case MFI_EVT_CLASS_PROGRESS
:
374 case MFI_EVT_CLASS_INFO
:
376 case MFI_EVT_CLASS_WARNING
:
378 case MFI_EVT_CLASS_CRITICAL
:
380 case MFI_EVT_CLASS_FATAL
:
382 case MFI_EVT_CLASS_DEAD
:
385 snprintf(buffer
, sizeof(buffer
), "%d", class);
391 * megasas_decode_evt: Decode FW AEN event and print critical event
393 * @instance: Adapter soft state
396 megasas_decode_evt(struct megasas_instance
*instance
)
398 struct megasas_evt_detail
*evt_detail
= instance
->evt_detail
;
399 union megasas_evt_class_locale class_locale
;
400 class_locale
.word
= le32_to_cpu(evt_detail
->cl
.word
);
402 if (class_locale
.members
.class >= MFI_EVT_CLASS_CRITICAL
)
403 dev_info(&instance
->pdev
->dev
, "%d (%s/0x%04x/%s) - %s\n",
404 le32_to_cpu(evt_detail
->seq_num
),
405 format_timestamp(le32_to_cpu(evt_detail
->time_stamp
)),
406 (class_locale
.members
.locale
),
407 format_class(class_locale
.members
.class),
408 evt_detail
->description
);
412 * The following functions are defined for xscale
413 * (deviceid : 1064R, PERC5) controllers
417 * megasas_enable_intr_xscale - Enables interrupts
418 * @regs: MFI register set
421 megasas_enable_intr_xscale(struct megasas_instance
*instance
)
423 struct megasas_register_set __iomem
*regs
;
425 regs
= instance
->reg_set
;
426 writel(0, &(regs
)->outbound_intr_mask
);
428 /* Dummy readl to force pci flush */
429 readl(®s
->outbound_intr_mask
);
433 * megasas_disable_intr_xscale -Disables interrupt
434 * @regs: MFI register set
437 megasas_disable_intr_xscale(struct megasas_instance
*instance
)
439 struct megasas_register_set __iomem
*regs
;
442 regs
= instance
->reg_set
;
443 writel(mask
, ®s
->outbound_intr_mask
);
444 /* Dummy readl to force pci flush */
445 readl(®s
->outbound_intr_mask
);
449 * megasas_read_fw_status_reg_xscale - returns the current FW status value
450 * @regs: MFI register set
453 megasas_read_fw_status_reg_xscale(struct megasas_instance
*instance
)
455 return readl(&instance
->reg_set
->outbound_msg_0
);
458 * megasas_clear_interrupt_xscale - Check & clear interrupt
459 * @regs: MFI register set
462 megasas_clear_intr_xscale(struct megasas_instance
*instance
)
466 struct megasas_register_set __iomem
*regs
;
467 regs
= instance
->reg_set
;
470 * Check if it is our interrupt
472 status
= readl(®s
->outbound_intr_status
);
474 if (status
& MFI_OB_INTR_STATUS_MASK
)
475 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
476 if (status
& MFI_XSCALE_OMR0_CHANGE_INTERRUPT
)
477 mfiStatus
|= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
480 * Clear the interrupt by writing back the same value
483 writel(status
, ®s
->outbound_intr_status
);
485 /* Dummy readl to force pci flush */
486 readl(®s
->outbound_intr_status
);
492 * megasas_fire_cmd_xscale - Sends command to the FW
493 * @frame_phys_addr : Physical address of cmd
494 * @frame_count : Number of frames for the command
495 * @regs : MFI register set
498 megasas_fire_cmd_xscale(struct megasas_instance
*instance
,
499 dma_addr_t frame_phys_addr
,
501 struct megasas_register_set __iomem
*regs
)
505 spin_lock_irqsave(&instance
->hba_lock
, flags
);
506 writel((frame_phys_addr
>> 3)|(frame_count
),
507 &(regs
)->inbound_queue_port
);
508 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
512 * megasas_adp_reset_xscale - For controller reset
513 * @regs: MFI register set
516 megasas_adp_reset_xscale(struct megasas_instance
*instance
,
517 struct megasas_register_set __iomem
*regs
)
522 writel(MFI_ADP_RESET
, ®s
->inbound_doorbell
);
524 for (i
= 0; i
< 3; i
++)
525 msleep(1000); /* sleep for 3 secs */
527 pci_read_config_dword(instance
->pdev
, MFI_1068_PCSR_OFFSET
, &pcidata
);
528 dev_notice(&instance
->pdev
->dev
, "pcidata = %x\n", pcidata
);
530 dev_notice(&instance
->pdev
->dev
, "mfi 1068 offset read=%x\n", pcidata
);
532 pci_write_config_dword(instance
->pdev
,
533 MFI_1068_PCSR_OFFSET
, pcidata
);
535 for (i
= 0; i
< 2; i
++)
536 msleep(1000); /* need to wait 2 secs again */
539 pci_read_config_dword(instance
->pdev
,
540 MFI_1068_FW_HANDSHAKE_OFFSET
, &pcidata
);
541 dev_notice(&instance
->pdev
->dev
, "1068 offset handshake read=%x\n", pcidata
);
542 if ((pcidata
& 0xffff0000) == MFI_1068_FW_READY
) {
543 dev_notice(&instance
->pdev
->dev
, "1068 offset pcidt=%x\n", pcidata
);
545 pci_write_config_dword(instance
->pdev
,
546 MFI_1068_FW_HANDSHAKE_OFFSET
, pcidata
);
553 * megasas_check_reset_xscale - For controller reset check
554 * @regs: MFI register set
557 megasas_check_reset_xscale(struct megasas_instance
*instance
,
558 struct megasas_register_set __iomem
*regs
)
560 if ((atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) &&
561 (le32_to_cpu(*instance
->consumer
) ==
562 MEGASAS_ADPRESET_INPROG_SIGN
))
567 static struct megasas_instance_template megasas_instance_template_xscale
= {
569 .fire_cmd
= megasas_fire_cmd_xscale
,
570 .enable_intr
= megasas_enable_intr_xscale
,
571 .disable_intr
= megasas_disable_intr_xscale
,
572 .clear_intr
= megasas_clear_intr_xscale
,
573 .read_fw_status_reg
= megasas_read_fw_status_reg_xscale
,
574 .adp_reset
= megasas_adp_reset_xscale
,
575 .check_reset
= megasas_check_reset_xscale
,
576 .service_isr
= megasas_isr
,
577 .tasklet
= megasas_complete_cmd_dpc
,
578 .init_adapter
= megasas_init_adapter_mfi
,
579 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
580 .issue_dcmd
= megasas_issue_dcmd
,
584 * This is the end of set of functions & definitions specific
585 * to xscale (deviceid : 1064R, PERC5) controllers
589 * The following functions are defined for ppc (deviceid : 0x60)
594 * megasas_enable_intr_ppc - Enables interrupts
595 * @regs: MFI register set
598 megasas_enable_intr_ppc(struct megasas_instance
*instance
)
600 struct megasas_register_set __iomem
*regs
;
602 regs
= instance
->reg_set
;
603 writel(0xFFFFFFFF, &(regs
)->outbound_doorbell_clear
);
605 writel(~0x80000000, &(regs
)->outbound_intr_mask
);
607 /* Dummy readl to force pci flush */
608 readl(®s
->outbound_intr_mask
);
612 * megasas_disable_intr_ppc - Disable interrupt
613 * @regs: MFI register set
616 megasas_disable_intr_ppc(struct megasas_instance
*instance
)
618 struct megasas_register_set __iomem
*regs
;
619 u32 mask
= 0xFFFFFFFF;
621 regs
= instance
->reg_set
;
622 writel(mask
, ®s
->outbound_intr_mask
);
623 /* Dummy readl to force pci flush */
624 readl(®s
->outbound_intr_mask
);
628 * megasas_read_fw_status_reg_ppc - returns the current FW status value
629 * @regs: MFI register set
632 megasas_read_fw_status_reg_ppc(struct megasas_instance
*instance
)
634 return readl(&instance
->reg_set
->outbound_scratch_pad_0
);
638 * megasas_clear_interrupt_ppc - Check & clear interrupt
639 * @regs: MFI register set
642 megasas_clear_intr_ppc(struct megasas_instance
*instance
)
644 u32 status
, mfiStatus
= 0;
645 struct megasas_register_set __iomem
*regs
;
646 regs
= instance
->reg_set
;
649 * Check if it is our interrupt
651 status
= readl(®s
->outbound_intr_status
);
653 if (status
& MFI_REPLY_1078_MESSAGE_INTERRUPT
)
654 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
656 if (status
& MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT
)
657 mfiStatus
|= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
660 * Clear the interrupt by writing back the same value
662 writel(status
, ®s
->outbound_doorbell_clear
);
664 /* Dummy readl to force pci flush */
665 readl(®s
->outbound_doorbell_clear
);
671 * megasas_fire_cmd_ppc - Sends command to the FW
672 * @frame_phys_addr : Physical address of cmd
673 * @frame_count : Number of frames for the command
674 * @regs : MFI register set
677 megasas_fire_cmd_ppc(struct megasas_instance
*instance
,
678 dma_addr_t frame_phys_addr
,
680 struct megasas_register_set __iomem
*regs
)
684 spin_lock_irqsave(&instance
->hba_lock
, flags
);
685 writel((frame_phys_addr
| (frame_count
<<1))|1,
686 &(regs
)->inbound_queue_port
);
687 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
691 * megasas_check_reset_ppc - For controller reset check
692 * @regs: MFI register set
695 megasas_check_reset_ppc(struct megasas_instance
*instance
,
696 struct megasas_register_set __iomem
*regs
)
698 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
704 static struct megasas_instance_template megasas_instance_template_ppc
= {
706 .fire_cmd
= megasas_fire_cmd_ppc
,
707 .enable_intr
= megasas_enable_intr_ppc
,
708 .disable_intr
= megasas_disable_intr_ppc
,
709 .clear_intr
= megasas_clear_intr_ppc
,
710 .read_fw_status_reg
= megasas_read_fw_status_reg_ppc
,
711 .adp_reset
= megasas_adp_reset_xscale
,
712 .check_reset
= megasas_check_reset_ppc
,
713 .service_isr
= megasas_isr
,
714 .tasklet
= megasas_complete_cmd_dpc
,
715 .init_adapter
= megasas_init_adapter_mfi
,
716 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
717 .issue_dcmd
= megasas_issue_dcmd
,
721 * megasas_enable_intr_skinny - Enables interrupts
722 * @regs: MFI register set
725 megasas_enable_intr_skinny(struct megasas_instance
*instance
)
727 struct megasas_register_set __iomem
*regs
;
729 regs
= instance
->reg_set
;
730 writel(0xFFFFFFFF, &(regs
)->outbound_intr_mask
);
732 writel(~MFI_SKINNY_ENABLE_INTERRUPT_MASK
, &(regs
)->outbound_intr_mask
);
734 /* Dummy readl to force pci flush */
735 readl(®s
->outbound_intr_mask
);
739 * megasas_disable_intr_skinny - Disables interrupt
740 * @regs: MFI register set
743 megasas_disable_intr_skinny(struct megasas_instance
*instance
)
745 struct megasas_register_set __iomem
*regs
;
746 u32 mask
= 0xFFFFFFFF;
748 regs
= instance
->reg_set
;
749 writel(mask
, ®s
->outbound_intr_mask
);
750 /* Dummy readl to force pci flush */
751 readl(®s
->outbound_intr_mask
);
755 * megasas_read_fw_status_reg_skinny - returns the current FW status value
756 * @regs: MFI register set
759 megasas_read_fw_status_reg_skinny(struct megasas_instance
*instance
)
761 return readl(&instance
->reg_set
->outbound_scratch_pad_0
);
765 * megasas_clear_interrupt_skinny - Check & clear interrupt
766 * @regs: MFI register set
769 megasas_clear_intr_skinny(struct megasas_instance
*instance
)
773 struct megasas_register_set __iomem
*regs
;
774 regs
= instance
->reg_set
;
777 * Check if it is our interrupt
779 status
= readl(®s
->outbound_intr_status
);
781 if (!(status
& MFI_SKINNY_ENABLE_INTERRUPT_MASK
)) {
786 * Check if it is our interrupt
788 if ((megasas_read_fw_status_reg_skinny(instance
) & MFI_STATE_MASK
) ==
790 mfiStatus
= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
792 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
795 * Clear the interrupt by writing back the same value
797 writel(status
, ®s
->outbound_intr_status
);
800 * dummy read to flush PCI
802 readl(®s
->outbound_intr_status
);
808 * megasas_fire_cmd_skinny - Sends command to the FW
809 * @frame_phys_addr : Physical address of cmd
810 * @frame_count : Number of frames for the command
811 * @regs : MFI register set
814 megasas_fire_cmd_skinny(struct megasas_instance
*instance
,
815 dma_addr_t frame_phys_addr
,
817 struct megasas_register_set __iomem
*regs
)
821 spin_lock_irqsave(&instance
->hba_lock
, flags
);
822 writel(upper_32_bits(frame_phys_addr
),
823 &(regs
)->inbound_high_queue_port
);
824 writel((lower_32_bits(frame_phys_addr
) | (frame_count
<<1))|1,
825 &(regs
)->inbound_low_queue_port
);
826 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
830 * megasas_check_reset_skinny - For controller reset check
831 * @regs: MFI register set
834 megasas_check_reset_skinny(struct megasas_instance
*instance
,
835 struct megasas_register_set __iomem
*regs
)
837 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
843 static struct megasas_instance_template megasas_instance_template_skinny
= {
845 .fire_cmd
= megasas_fire_cmd_skinny
,
846 .enable_intr
= megasas_enable_intr_skinny
,
847 .disable_intr
= megasas_disable_intr_skinny
,
848 .clear_intr
= megasas_clear_intr_skinny
,
849 .read_fw_status_reg
= megasas_read_fw_status_reg_skinny
,
850 .adp_reset
= megasas_adp_reset_gen2
,
851 .check_reset
= megasas_check_reset_skinny
,
852 .service_isr
= megasas_isr
,
853 .tasklet
= megasas_complete_cmd_dpc
,
854 .init_adapter
= megasas_init_adapter_mfi
,
855 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
856 .issue_dcmd
= megasas_issue_dcmd
,
861 * The following functions are defined for gen2 (deviceid : 0x78 0x79)
866 * megasas_enable_intr_gen2 - Enables interrupts
867 * @regs: MFI register set
870 megasas_enable_intr_gen2(struct megasas_instance
*instance
)
872 struct megasas_register_set __iomem
*regs
;
874 regs
= instance
->reg_set
;
875 writel(0xFFFFFFFF, &(regs
)->outbound_doorbell_clear
);
877 /* write ~0x00000005 (4 & 1) to the intr mask*/
878 writel(~MFI_GEN2_ENABLE_INTERRUPT_MASK
, &(regs
)->outbound_intr_mask
);
880 /* Dummy readl to force pci flush */
881 readl(®s
->outbound_intr_mask
);
885 * megasas_disable_intr_gen2 - Disables interrupt
886 * @regs: MFI register set
889 megasas_disable_intr_gen2(struct megasas_instance
*instance
)
891 struct megasas_register_set __iomem
*regs
;
892 u32 mask
= 0xFFFFFFFF;
894 regs
= instance
->reg_set
;
895 writel(mask
, ®s
->outbound_intr_mask
);
896 /* Dummy readl to force pci flush */
897 readl(®s
->outbound_intr_mask
);
901 * megasas_read_fw_status_reg_gen2 - returns the current FW status value
902 * @regs: MFI register set
905 megasas_read_fw_status_reg_gen2(struct megasas_instance
*instance
)
907 return readl(&instance
->reg_set
->outbound_scratch_pad_0
);
911 * megasas_clear_interrupt_gen2 - Check & clear interrupt
912 * @regs: MFI register set
915 megasas_clear_intr_gen2(struct megasas_instance
*instance
)
919 struct megasas_register_set __iomem
*regs
;
920 regs
= instance
->reg_set
;
923 * Check if it is our interrupt
925 status
= readl(®s
->outbound_intr_status
);
927 if (status
& MFI_INTR_FLAG_REPLY_MESSAGE
) {
928 mfiStatus
= MFI_INTR_FLAG_REPLY_MESSAGE
;
930 if (status
& MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT
) {
931 mfiStatus
|= MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
;
935 * Clear the interrupt by writing back the same value
938 writel(status
, ®s
->outbound_doorbell_clear
);
940 /* Dummy readl to force pci flush */
941 readl(®s
->outbound_intr_status
);
946 * megasas_fire_cmd_gen2 - Sends command to the FW
947 * @frame_phys_addr : Physical address of cmd
948 * @frame_count : Number of frames for the command
949 * @regs : MFI register set
952 megasas_fire_cmd_gen2(struct megasas_instance
*instance
,
953 dma_addr_t frame_phys_addr
,
955 struct megasas_register_set __iomem
*regs
)
959 spin_lock_irqsave(&instance
->hba_lock
, flags
);
960 writel((frame_phys_addr
| (frame_count
<<1))|1,
961 &(regs
)->inbound_queue_port
);
962 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
966 * megasas_adp_reset_gen2 - For controller reset
967 * @regs: MFI register set
970 megasas_adp_reset_gen2(struct megasas_instance
*instance
,
971 struct megasas_register_set __iomem
*reg_set
)
975 u32 __iomem
*seq_offset
= ®_set
->seq_offset
;
976 u32 __iomem
*hostdiag_offset
= ®_set
->host_diag
;
978 if (instance
->instancet
== &megasas_instance_template_skinny
) {
979 seq_offset
= ®_set
->fusion_seq_offset
;
980 hostdiag_offset
= ®_set
->fusion_host_diag
;
983 writel(0, seq_offset
);
984 writel(4, seq_offset
);
985 writel(0xb, seq_offset
);
986 writel(2, seq_offset
);
987 writel(7, seq_offset
);
988 writel(0xd, seq_offset
);
992 HostDiag
= (u32
)readl(hostdiag_offset
);
994 while (!(HostDiag
& DIAG_WRITE_ENABLE
)) {
996 HostDiag
= (u32
)readl(hostdiag_offset
);
997 dev_notice(&instance
->pdev
->dev
, "RESETGEN2: retry=%x, hostdiag=%x\n",
1005 dev_notice(&instance
->pdev
->dev
, "ADP_RESET_GEN2: HostDiag=%x\n", HostDiag
);
1007 writel((HostDiag
| DIAG_RESET_ADAPTER
), hostdiag_offset
);
1011 HostDiag
= (u32
)readl(hostdiag_offset
);
1012 while (HostDiag
& DIAG_RESET_ADAPTER
) {
1014 HostDiag
= (u32
)readl(hostdiag_offset
);
1015 dev_notice(&instance
->pdev
->dev
, "RESET_GEN2: retry=%x, hostdiag=%x\n",
1018 if (retry
++ >= 1000)
1026 * megasas_check_reset_gen2 - For controller reset check
1027 * @regs: MFI register set
1030 megasas_check_reset_gen2(struct megasas_instance
*instance
,
1031 struct megasas_register_set __iomem
*regs
)
1033 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
1039 static struct megasas_instance_template megasas_instance_template_gen2
= {
1041 .fire_cmd
= megasas_fire_cmd_gen2
,
1042 .enable_intr
= megasas_enable_intr_gen2
,
1043 .disable_intr
= megasas_disable_intr_gen2
,
1044 .clear_intr
= megasas_clear_intr_gen2
,
1045 .read_fw_status_reg
= megasas_read_fw_status_reg_gen2
,
1046 .adp_reset
= megasas_adp_reset_gen2
,
1047 .check_reset
= megasas_check_reset_gen2
,
1048 .service_isr
= megasas_isr
,
1049 .tasklet
= megasas_complete_cmd_dpc
,
1050 .init_adapter
= megasas_init_adapter_mfi
,
1051 .build_and_issue_cmd
= megasas_build_and_issue_cmd
,
1052 .issue_dcmd
= megasas_issue_dcmd
,
1056 * This is the end of set of functions & definitions
1057 * specific to gen2 (deviceid : 0x78, 0x79) controllers
1061 * Template added for TB (Fusion)
1063 extern struct megasas_instance_template megasas_instance_template_fusion
;
1066 * megasas_issue_polled - Issues a polling command
1067 * @instance: Adapter soft state
1068 * @cmd: Command packet to be issued
1070 * For polling, MFI requires the cmd_status to be set to MFI_STAT_INVALID_STATUS before posting.
1073 megasas_issue_polled(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
1075 struct megasas_header
*frame_hdr
= &cmd
->frame
->hdr
;
1077 frame_hdr
->cmd_status
= MFI_STAT_INVALID_STATUS
;
1078 frame_hdr
->flags
|= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
);
1080 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1081 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
1082 __func__
, __LINE__
);
1083 return DCMD_NOT_FIRED
;
1086 instance
->instancet
->issue_dcmd(instance
, cmd
);
1088 return wait_and_poll(instance
, cmd
, instance
->requestorId
?
1089 MEGASAS_ROUTINE_WAIT_TIME_VF
: MFI_IO_TIMEOUT_SECS
);
1093 * megasas_issue_blocked_cmd - Synchronous wrapper around regular FW cmds
1094 * @instance: Adapter soft state
1095 * @cmd: Command to be issued
1096 * @timeout: Timeout in seconds
1098 * This function waits on an event for the command to be returned from ISR.
1099 * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs
1100 * Used to issue ioctl commands.
1103 megasas_issue_blocked_cmd(struct megasas_instance
*instance
,
1104 struct megasas_cmd
*cmd
, int timeout
)
1107 cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
1109 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1110 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
1111 __func__
, __LINE__
);
1112 return DCMD_NOT_FIRED
;
1115 instance
->instancet
->issue_dcmd(instance
, cmd
);
1118 ret
= wait_event_timeout(instance
->int_cmd_wait_q
,
1119 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
, timeout
* HZ
);
1121 dev_err(&instance
->pdev
->dev
,
1122 "DCMD(opcode: 0x%x) is timed out, func:%s\n",
1123 cmd
->frame
->dcmd
.opcode
, __func__
);
1124 return DCMD_TIMEOUT
;
1127 wait_event(instance
->int_cmd_wait_q
,
1128 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
);
1130 return (cmd
->cmd_status_drv
== MFI_STAT_OK
) ?
1131 DCMD_SUCCESS
: DCMD_FAILED
;
1135 * megasas_issue_blocked_abort_cmd - Aborts previously issued cmd
1136 * @instance: Adapter soft state
1137 * @cmd_to_abort: Previously issued cmd to be aborted
1138 * @timeout: Timeout in seconds
1140 * MFI firmware can abort previously issued AEN comamnd (automatic event
1141 * notification). The megasas_issue_blocked_abort_cmd() issues such abort
1142 * cmd and waits for return status.
1143 * Max wait time is MEGASAS_INTERNAL_CMD_WAIT_TIME secs
1146 megasas_issue_blocked_abort_cmd(struct megasas_instance
*instance
,
1147 struct megasas_cmd
*cmd_to_abort
, int timeout
)
1149 struct megasas_cmd
*cmd
;
1150 struct megasas_abort_frame
*abort_fr
;
1154 cmd
= megasas_get_cmd(instance
);
1159 abort_fr
= &cmd
->frame
->abort
;
1162 * Prepare and issue the abort frame
1164 abort_fr
->cmd
= MFI_CMD_ABORT
;
1165 abort_fr
->cmd_status
= MFI_STAT_INVALID_STATUS
;
1166 abort_fr
->flags
= cpu_to_le16(0);
1167 abort_fr
->abort_context
= cpu_to_le32(cmd_to_abort
->index
);
1168 abort_fr
->abort_mfi_phys_addr_lo
=
1169 cpu_to_le32(lower_32_bits(cmd_to_abort
->frame_phys_addr
));
1170 abort_fr
->abort_mfi_phys_addr_hi
=
1171 cpu_to_le32(upper_32_bits(cmd_to_abort
->frame_phys_addr
));
1174 cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
1176 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1177 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
1178 __func__
, __LINE__
);
1179 return DCMD_NOT_FIRED
;
1182 instance
->instancet
->issue_dcmd(instance
, cmd
);
1185 ret
= wait_event_timeout(instance
->abort_cmd_wait_q
,
1186 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
, timeout
* HZ
);
1188 opcode
= cmd_to_abort
->frame
->dcmd
.opcode
;
1189 dev_err(&instance
->pdev
->dev
,
1190 "Abort(to be aborted DCMD opcode: 0x%x) is timed out func:%s\n",
1192 return DCMD_TIMEOUT
;
1195 wait_event(instance
->abort_cmd_wait_q
,
1196 cmd
->cmd_status_drv
!= MFI_STAT_INVALID_STATUS
);
1200 megasas_return_cmd(instance
, cmd
);
1201 return (cmd
->cmd_status_drv
== MFI_STAT_OK
) ?
1202 DCMD_SUCCESS
: DCMD_FAILED
;
1206 * megasas_make_sgl32 - Prepares 32-bit SGL
1207 * @instance: Adapter soft state
1208 * @scp: SCSI command from the mid-layer
1209 * @mfi_sgl: SGL to be filled in
1211 * If successful, this function returns the number of SG elements. Otherwise,
1215 megasas_make_sgl32(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1216 union megasas_sgl
*mfi_sgl
)
1220 struct scatterlist
*os_sgl
;
1222 sge_count
= scsi_dma_map(scp
);
1223 BUG_ON(sge_count
< 0);
1226 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
1227 mfi_sgl
->sge32
[i
].length
= cpu_to_le32(sg_dma_len(os_sgl
));
1228 mfi_sgl
->sge32
[i
].phys_addr
= cpu_to_le32(sg_dma_address(os_sgl
));
1235 * megasas_make_sgl64 - Prepares 64-bit SGL
1236 * @instance: Adapter soft state
1237 * @scp: SCSI command from the mid-layer
1238 * @mfi_sgl: SGL to be filled in
1240 * If successful, this function returns the number of SG elements. Otherwise,
1244 megasas_make_sgl64(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1245 union megasas_sgl
*mfi_sgl
)
1249 struct scatterlist
*os_sgl
;
1251 sge_count
= scsi_dma_map(scp
);
1252 BUG_ON(sge_count
< 0);
1255 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
1256 mfi_sgl
->sge64
[i
].length
= cpu_to_le32(sg_dma_len(os_sgl
));
1257 mfi_sgl
->sge64
[i
].phys_addr
= cpu_to_le64(sg_dma_address(os_sgl
));
1264 * megasas_make_sgl_skinny - Prepares IEEE SGL
1265 * @instance: Adapter soft state
1266 * @scp: SCSI command from the mid-layer
1267 * @mfi_sgl: SGL to be filled in
1269 * If successful, this function returns the number of SG elements. Otherwise,
1273 megasas_make_sgl_skinny(struct megasas_instance
*instance
,
1274 struct scsi_cmnd
*scp
, union megasas_sgl
*mfi_sgl
)
1278 struct scatterlist
*os_sgl
;
1280 sge_count
= scsi_dma_map(scp
);
1283 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
1284 mfi_sgl
->sge_skinny
[i
].length
=
1285 cpu_to_le32(sg_dma_len(os_sgl
));
1286 mfi_sgl
->sge_skinny
[i
].phys_addr
=
1287 cpu_to_le64(sg_dma_address(os_sgl
));
1288 mfi_sgl
->sge_skinny
[i
].flag
= cpu_to_le32(0);
1295 * megasas_get_frame_count - Computes the number of frames
1296 * @frame_type : type of frame- io or pthru frame
1297 * @sge_count : number of sg elements
1299 * Returns the number of frames required for numnber of sge's (sge_count)
1302 static u32
megasas_get_frame_count(struct megasas_instance
*instance
,
1303 u8 sge_count
, u8 frame_type
)
1308 u32 frame_count
= 0;
1310 sge_sz
= (IS_DMA64
) ? sizeof(struct megasas_sge64
) :
1311 sizeof(struct megasas_sge32
);
1313 if (instance
->flag_ieee
) {
1314 sge_sz
= sizeof(struct megasas_sge_skinny
);
1318 * Main frame can contain 2 SGEs for 64-bit SGLs and
1319 * 3 SGEs for 32-bit SGLs for ldio &
1320 * 1 SGEs for 64-bit SGLs and
1321 * 2 SGEs for 32-bit SGLs for pthru frame
1323 if (unlikely(frame_type
== PTHRU_FRAME
)) {
1324 if (instance
->flag_ieee
== 1) {
1325 num_cnt
= sge_count
- 1;
1326 } else if (IS_DMA64
)
1327 num_cnt
= sge_count
- 1;
1329 num_cnt
= sge_count
- 2;
1331 if (instance
->flag_ieee
== 1) {
1332 num_cnt
= sge_count
- 1;
1333 } else if (IS_DMA64
)
1334 num_cnt
= sge_count
- 2;
1336 num_cnt
= sge_count
- 3;
1340 sge_bytes
= sge_sz
* num_cnt
;
1342 frame_count
= (sge_bytes
/ MEGAMFI_FRAME_SIZE
) +
1343 ((sge_bytes
% MEGAMFI_FRAME_SIZE
) ? 1 : 0) ;
1348 if (frame_count
> 7)
1354 * megasas_build_dcdb - Prepares a direct cdb (DCDB) command
1355 * @instance: Adapter soft state
1356 * @scp: SCSI command
1357 * @cmd: Command to be prepared in
1359 * This function prepares CDB commands. These are typcially pass-through
1360 * commands to the devices.
1363 megasas_build_dcdb(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1364 struct megasas_cmd
*cmd
)
1369 struct megasas_pthru_frame
*pthru
;
1371 is_logical
= MEGASAS_IS_LOGICAL(scp
->device
);
1372 device_id
= MEGASAS_DEV_INDEX(scp
);
1373 pthru
= (struct megasas_pthru_frame
*)cmd
->frame
;
1375 if (scp
->sc_data_direction
== DMA_TO_DEVICE
)
1376 flags
= MFI_FRAME_DIR_WRITE
;
1377 else if (scp
->sc_data_direction
== DMA_FROM_DEVICE
)
1378 flags
= MFI_FRAME_DIR_READ
;
1379 else if (scp
->sc_data_direction
== DMA_NONE
)
1380 flags
= MFI_FRAME_DIR_NONE
;
1382 if (instance
->flag_ieee
== 1) {
1383 flags
|= MFI_FRAME_IEEE
;
1387 * Prepare the DCDB frame
1389 pthru
->cmd
= (is_logical
) ? MFI_CMD_LD_SCSI_IO
: MFI_CMD_PD_SCSI_IO
;
1390 pthru
->cmd_status
= 0x0;
1391 pthru
->scsi_status
= 0x0;
1392 pthru
->target_id
= device_id
;
1393 pthru
->lun
= scp
->device
->lun
;
1394 pthru
->cdb_len
= scp
->cmd_len
;
1397 pthru
->flags
= cpu_to_le16(flags
);
1398 pthru
->data_xfer_len
= cpu_to_le32(scsi_bufflen(scp
));
1400 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1403 * If the command is for the tape device, set the
1404 * pthru timeout to the os layer timeout value.
1406 if (scp
->device
->type
== TYPE_TAPE
) {
1407 if ((scp
->request
->timeout
/ HZ
) > 0xFFFF)
1408 pthru
->timeout
= cpu_to_le16(0xFFFF);
1410 pthru
->timeout
= cpu_to_le16(scp
->request
->timeout
/ HZ
);
1416 if (instance
->flag_ieee
== 1) {
1417 pthru
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1418 pthru
->sge_count
= megasas_make_sgl_skinny(instance
, scp
,
1420 } else if (IS_DMA64
) {
1421 pthru
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1422 pthru
->sge_count
= megasas_make_sgl64(instance
, scp
,
1425 pthru
->sge_count
= megasas_make_sgl32(instance
, scp
,
1428 if (pthru
->sge_count
> instance
->max_num_sge
) {
1429 dev_err(&instance
->pdev
->dev
, "DCDB too many SGE NUM=%x\n",
1435 * Sense info specific
1437 pthru
->sense_len
= SCSI_SENSE_BUFFERSIZE
;
1438 pthru
->sense_buf_phys_addr_hi
=
1439 cpu_to_le32(upper_32_bits(cmd
->sense_phys_addr
));
1440 pthru
->sense_buf_phys_addr_lo
=
1441 cpu_to_le32(lower_32_bits(cmd
->sense_phys_addr
));
1444 * Compute the total number of frames this command consumes. FW uses
1445 * this number to pull sufficient number of frames from host memory.
1447 cmd
->frame_count
= megasas_get_frame_count(instance
, pthru
->sge_count
,
1450 return cmd
->frame_count
;
1454 * megasas_build_ldio - Prepares IOs to logical devices
1455 * @instance: Adapter soft state
1456 * @scp: SCSI command
1457 * @cmd: Command to be prepared
1459 * Frames (and accompanying SGLs) for regular SCSI IOs use this function.
1462 megasas_build_ldio(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
1463 struct megasas_cmd
*cmd
)
1466 u8 sc
= scp
->cmnd
[0];
1468 struct megasas_io_frame
*ldio
;
1470 device_id
= MEGASAS_DEV_INDEX(scp
);
1471 ldio
= (struct megasas_io_frame
*)cmd
->frame
;
1473 if (scp
->sc_data_direction
== DMA_TO_DEVICE
)
1474 flags
= MFI_FRAME_DIR_WRITE
;
1475 else if (scp
->sc_data_direction
== DMA_FROM_DEVICE
)
1476 flags
= MFI_FRAME_DIR_READ
;
1478 if (instance
->flag_ieee
== 1) {
1479 flags
|= MFI_FRAME_IEEE
;
1483 * Prepare the Logical IO frame: 2nd bit is zero for all read cmds
1485 ldio
->cmd
= (sc
& 0x02) ? MFI_CMD_LD_WRITE
: MFI_CMD_LD_READ
;
1486 ldio
->cmd_status
= 0x0;
1487 ldio
->scsi_status
= 0x0;
1488 ldio
->target_id
= device_id
;
1490 ldio
->reserved_0
= 0;
1492 ldio
->flags
= cpu_to_le16(flags
);
1493 ldio
->start_lba_hi
= 0;
1494 ldio
->access_byte
= (scp
->cmd_len
!= 6) ? scp
->cmnd
[1] : 0;
1497 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1499 if (scp
->cmd_len
== 6) {
1500 ldio
->lba_count
= cpu_to_le32((u32
) scp
->cmnd
[4]);
1501 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[1] << 16) |
1502 ((u32
) scp
->cmnd
[2] << 8) |
1503 (u32
) scp
->cmnd
[3]);
1505 ldio
->start_lba_lo
&= cpu_to_le32(0x1FFFFF);
1509 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1511 else if (scp
->cmd_len
== 10) {
1512 ldio
->lba_count
= cpu_to_le32((u32
) scp
->cmnd
[8] |
1513 ((u32
) scp
->cmnd
[7] << 8));
1514 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[2] << 24) |
1515 ((u32
) scp
->cmnd
[3] << 16) |
1516 ((u32
) scp
->cmnd
[4] << 8) |
1517 (u32
) scp
->cmnd
[5]);
1521 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1523 else if (scp
->cmd_len
== 12) {
1524 ldio
->lba_count
= cpu_to_le32(((u32
) scp
->cmnd
[6] << 24) |
1525 ((u32
) scp
->cmnd
[7] << 16) |
1526 ((u32
) scp
->cmnd
[8] << 8) |
1527 (u32
) scp
->cmnd
[9]);
1529 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[2] << 24) |
1530 ((u32
) scp
->cmnd
[3] << 16) |
1531 ((u32
) scp
->cmnd
[4] << 8) |
1532 (u32
) scp
->cmnd
[5]);
1536 * 16-byte READ(0x88) or WRITE(0x8A) cdb
1538 else if (scp
->cmd_len
== 16) {
1539 ldio
->lba_count
= cpu_to_le32(((u32
) scp
->cmnd
[10] << 24) |
1540 ((u32
) scp
->cmnd
[11] << 16) |
1541 ((u32
) scp
->cmnd
[12] << 8) |
1542 (u32
) scp
->cmnd
[13]);
1544 ldio
->start_lba_lo
= cpu_to_le32(((u32
) scp
->cmnd
[6] << 24) |
1545 ((u32
) scp
->cmnd
[7] << 16) |
1546 ((u32
) scp
->cmnd
[8] << 8) |
1547 (u32
) scp
->cmnd
[9]);
1549 ldio
->start_lba_hi
= cpu_to_le32(((u32
) scp
->cmnd
[2] << 24) |
1550 ((u32
) scp
->cmnd
[3] << 16) |
1551 ((u32
) scp
->cmnd
[4] << 8) |
1552 (u32
) scp
->cmnd
[5]);
1559 if (instance
->flag_ieee
) {
1560 ldio
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1561 ldio
->sge_count
= megasas_make_sgl_skinny(instance
, scp
,
1563 } else if (IS_DMA64
) {
1564 ldio
->flags
|= cpu_to_le16(MFI_FRAME_SGL64
);
1565 ldio
->sge_count
= megasas_make_sgl64(instance
, scp
, &ldio
->sgl
);
1567 ldio
->sge_count
= megasas_make_sgl32(instance
, scp
, &ldio
->sgl
);
1569 if (ldio
->sge_count
> instance
->max_num_sge
) {
1570 dev_err(&instance
->pdev
->dev
, "build_ld_io: sge_count = %x\n",
1576 * Sense info specific
1578 ldio
->sense_len
= SCSI_SENSE_BUFFERSIZE
;
1579 ldio
->sense_buf_phys_addr_hi
= 0;
1580 ldio
->sense_buf_phys_addr_lo
= cpu_to_le32(cmd
->sense_phys_addr
);
1583 * Compute the total number of frames this command consumes. FW uses
1584 * this number to pull sufficient number of frames from host memory.
1586 cmd
->frame_count
= megasas_get_frame_count(instance
,
1587 ldio
->sge_count
, IO_FRAME
);
1589 return cmd
->frame_count
;
1593 * megasas_cmd_type - Checks if the cmd is for logical drive/sysPD
1594 * and whether it's RW or non RW
1595 * @scmd: SCSI command
1598 inline int megasas_cmd_type(struct scsi_cmnd
*cmd
)
1602 switch (cmd
->cmnd
[0]) {
1611 ret
= (MEGASAS_IS_LOGICAL(cmd
->device
)) ?
1612 READ_WRITE_LDIO
: READ_WRITE_SYSPDIO
;
1615 ret
= (MEGASAS_IS_LOGICAL(cmd
->device
)) ?
1616 NON_READ_WRITE_LDIO
: NON_READ_WRITE_SYSPDIO
;
1622 * megasas_dump_pending_frames - Dumps the frame address of all pending cmds
1624 * @instance: Adapter soft state
1627 megasas_dump_pending_frames(struct megasas_instance
*instance
)
1629 struct megasas_cmd
*cmd
;
1631 union megasas_sgl
*mfi_sgl
;
1632 struct megasas_io_frame
*ldio
;
1633 struct megasas_pthru_frame
*pthru
;
1635 u16 max_cmd
= instance
->max_fw_cmds
;
1637 dev_err(&instance
->pdev
->dev
, "[%d]: Dumping Frame Phys Address of all pending cmds in FW\n",instance
->host
->host_no
);
1638 dev_err(&instance
->pdev
->dev
, "[%d]: Total OS Pending cmds : %d\n",instance
->host
->host_no
,atomic_read(&instance
->fw_outstanding
));
1640 dev_err(&instance
->pdev
->dev
, "[%d]: 64 bit SGLs were sent to FW\n",instance
->host
->host_no
);
1642 dev_err(&instance
->pdev
->dev
, "[%d]: 32 bit SGLs were sent to FW\n",instance
->host
->host_no
);
1644 dev_err(&instance
->pdev
->dev
, "[%d]: Pending OS cmds in FW : \n",instance
->host
->host_no
);
1645 for (i
= 0; i
< max_cmd
; i
++) {
1646 cmd
= instance
->cmd_list
[i
];
1649 dev_err(&instance
->pdev
->dev
, "[%d]: Frame addr :0x%08lx : ",instance
->host
->host_no
,(unsigned long)cmd
->frame_phys_addr
);
1650 if (megasas_cmd_type(cmd
->scmd
) == READ_WRITE_LDIO
) {
1651 ldio
= (struct megasas_io_frame
*)cmd
->frame
;
1652 mfi_sgl
= &ldio
->sgl
;
1653 sgcount
= ldio
->sge_count
;
1654 dev_err(&instance
->pdev
->dev
, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x,"
1655 " lba lo : 0x%x, lba_hi : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
1656 instance
->host
->host_no
, cmd
->frame_count
, ldio
->cmd
, ldio
->target_id
,
1657 le32_to_cpu(ldio
->start_lba_lo
), le32_to_cpu(ldio
->start_lba_hi
),
1658 le32_to_cpu(ldio
->sense_buf_phys_addr_lo
), sgcount
);
1660 pthru
= (struct megasas_pthru_frame
*) cmd
->frame
;
1661 mfi_sgl
= &pthru
->sgl
;
1662 sgcount
= pthru
->sge_count
;
1663 dev_err(&instance
->pdev
->dev
, "[%d]: frame count : 0x%x, Cmd : 0x%x, Tgt id : 0x%x, "
1664 "lun : 0x%x, cdb_len : 0x%x, data xfer len : 0x%x, sense_buf addr : 0x%x,sge count : 0x%x\n",
1665 instance
->host
->host_no
, cmd
->frame_count
, pthru
->cmd
, pthru
->target_id
,
1666 pthru
->lun
, pthru
->cdb_len
, le32_to_cpu(pthru
->data_xfer_len
),
1667 le32_to_cpu(pthru
->sense_buf_phys_addr_lo
), sgcount
);
1669 if (megasas_dbg_lvl
& MEGASAS_DBG_LVL
) {
1670 for (n
= 0; n
< sgcount
; n
++) {
1672 dev_err(&instance
->pdev
->dev
, "sgl len : 0x%x, sgl addr : 0x%llx\n",
1673 le32_to_cpu(mfi_sgl
->sge64
[n
].length
),
1674 le64_to_cpu(mfi_sgl
->sge64
[n
].phys_addr
));
1676 dev_err(&instance
->pdev
->dev
, "sgl len : 0x%x, sgl addr : 0x%x\n",
1677 le32_to_cpu(mfi_sgl
->sge32
[n
].length
),
1678 le32_to_cpu(mfi_sgl
->sge32
[n
].phys_addr
));
1682 dev_err(&instance
->pdev
->dev
, "[%d]: Pending Internal cmds in FW : \n",instance
->host
->host_no
);
1683 for (i
= 0; i
< max_cmd
; i
++) {
1685 cmd
= instance
->cmd_list
[i
];
1687 if (cmd
->sync_cmd
== 1)
1688 dev_err(&instance
->pdev
->dev
, "0x%08lx : ", (unsigned long)cmd
->frame_phys_addr
);
1690 dev_err(&instance
->pdev
->dev
, "[%d]: Dumping Done\n\n",instance
->host
->host_no
);
1694 megasas_build_and_issue_cmd(struct megasas_instance
*instance
,
1695 struct scsi_cmnd
*scmd
)
1697 struct megasas_cmd
*cmd
;
1700 cmd
= megasas_get_cmd(instance
);
1702 return SCSI_MLQUEUE_HOST_BUSY
;
1705 * Logical drive command
1707 if (megasas_cmd_type(scmd
) == READ_WRITE_LDIO
)
1708 frame_count
= megasas_build_ldio(instance
, scmd
, cmd
);
1710 frame_count
= megasas_build_dcdb(instance
, scmd
, cmd
);
1713 goto out_return_cmd
;
1716 scmd
->SCp
.ptr
= (char *)cmd
;
1719 * Issue the command to the FW
1721 atomic_inc(&instance
->fw_outstanding
);
1723 instance
->instancet
->fire_cmd(instance
, cmd
->frame_phys_addr
,
1724 cmd
->frame_count
-1, instance
->reg_set
);
1728 megasas_return_cmd(instance
, cmd
);
1729 return SCSI_MLQUEUE_HOST_BUSY
;
1734 * megasas_queue_command - Queue entry point
1735 * @scmd: SCSI command to be queued
1736 * @done: Callback entry point
1739 megasas_queue_command(struct Scsi_Host
*shost
, struct scsi_cmnd
*scmd
)
1741 struct megasas_instance
*instance
;
1742 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
1744 instance
= (struct megasas_instance
*)
1745 scmd
->device
->host
->hostdata
;
1747 if (instance
->unload
== 1) {
1748 scmd
->result
= DID_NO_CONNECT
<< 16;
1749 scmd
->scsi_done(scmd
);
1753 if (instance
->issuepend_done
== 0)
1754 return SCSI_MLQUEUE_HOST_BUSY
;
1757 /* Check for an mpio path and adjust behavior */
1758 if (atomic_read(&instance
->adprecovery
) == MEGASAS_ADPRESET_SM_INFAULT
) {
1759 if (megasas_check_mpio_paths(instance
, scmd
) ==
1760 (DID_REQUEUE
<< 16)) {
1761 return SCSI_MLQUEUE_HOST_BUSY
;
1763 scmd
->result
= DID_NO_CONNECT
<< 16;
1764 scmd
->scsi_done(scmd
);
1769 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
1770 scmd
->result
= DID_NO_CONNECT
<< 16;
1771 scmd
->scsi_done(scmd
);
1775 mr_device_priv_data
= scmd
->device
->hostdata
;
1776 if (!mr_device_priv_data
) {
1777 scmd
->result
= DID_NO_CONNECT
<< 16;
1778 scmd
->scsi_done(scmd
);
1782 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
)
1783 return SCSI_MLQUEUE_HOST_BUSY
;
1785 if (mr_device_priv_data
->tm_busy
)
1786 return SCSI_MLQUEUE_DEVICE_BUSY
;
1791 if (MEGASAS_IS_LOGICAL(scmd
->device
) &&
1792 (scmd
->device
->id
>= instance
->fw_supported_vd_count
||
1793 scmd
->device
->lun
)) {
1794 scmd
->result
= DID_BAD_TARGET
<< 16;
1798 if ((scmd
->cmnd
[0] == SYNCHRONIZE_CACHE
) &&
1799 MEGASAS_IS_LOGICAL(scmd
->device
) &&
1800 (!instance
->fw_sync_cache_support
)) {
1801 scmd
->result
= DID_OK
<< 16;
1805 return instance
->instancet
->build_and_issue_cmd(instance
, scmd
);
1808 scmd
->scsi_done(scmd
);
1812 static struct megasas_instance
*megasas_lookup_instance(u16 host_no
)
1816 for (i
= 0; i
< megasas_mgmt_info
.max_index
; i
++) {
1818 if ((megasas_mgmt_info
.instance
[i
]) &&
1819 (megasas_mgmt_info
.instance
[i
]->host
->host_no
== host_no
))
1820 return megasas_mgmt_info
.instance
[i
];
1827 * megasas_set_dynamic_target_properties -
1828 * Device property set by driver may not be static and it is required to be
1832 * set dma alignment (only for eedp protection enable vd).
1834 * @sdev: OS provided scsi device
1838 void megasas_set_dynamic_target_properties(struct scsi_device
*sdev
,
1839 bool is_target_prop
)
1841 u16 pd_index
= 0, ld
;
1843 struct megasas_instance
*instance
;
1844 struct fusion_context
*fusion
;
1845 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
1846 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
1847 struct MR_LD_RAID
*raid
;
1848 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
1850 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
1851 fusion
= instance
->ctrl_context
;
1852 mr_device_priv_data
= sdev
->hostdata
;
1854 if (!fusion
|| !mr_device_priv_data
)
1857 if (MEGASAS_IS_LOGICAL(sdev
)) {
1858 device_id
= ((sdev
->channel
% 2) * MEGASAS_MAX_DEV_PER_CHANNEL
)
1860 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
1861 ld
= MR_TargetIdToLdGet(device_id
, local_map_ptr
);
1862 if (ld
>= instance
->fw_supported_vd_count
)
1864 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
1866 if (raid
->capability
.ldPiMode
== MR_PROT_INFO_TYPE_CONTROLLER
)
1867 blk_queue_update_dma_alignment(sdev
->request_queue
, 0x7);
1869 mr_device_priv_data
->is_tm_capable
=
1870 raid
->capability
.tmCapable
;
1871 } else if (instance
->use_seqnum_jbod_fp
) {
1872 pd_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) +
1874 pd_sync
= (void *)fusion
->pd_seq_sync
1875 [(instance
->pd_seq_map_id
- 1) & 1];
1876 mr_device_priv_data
->is_tm_capable
=
1877 pd_sync
->seq
[pd_index
].capability
.tmCapable
;
1880 if (is_target_prop
&& instance
->tgt_prop
->reset_tmo
) {
1882 * If FW provides a target reset timeout value, driver will use
1883 * it. If not set, fallback to default values.
1885 mr_device_priv_data
->target_reset_tmo
=
1886 min_t(u8
, instance
->max_reset_tmo
,
1887 instance
->tgt_prop
->reset_tmo
);
1888 mr_device_priv_data
->task_abort_tmo
= instance
->task_abort_tmo
;
1890 mr_device_priv_data
->target_reset_tmo
=
1891 MEGASAS_DEFAULT_TM_TIMEOUT
;
1892 mr_device_priv_data
->task_abort_tmo
=
1893 MEGASAS_DEFAULT_TM_TIMEOUT
;
1898 * megasas_set_nvme_device_properties -
1900 * set virtual page boundary = 4K (current mr_nvme_pg_size is 4K).
1901 * set maximum io transfer = MDTS of NVME device provided by MR firmware.
1903 * MR firmware provides value in KB. Caller of this function converts
1906 * e.a MDTS=5 means 2^5 * nvme page size. (In case of 4K page size,
1907 * MR firmware provides value 128 as (32 * 4K) = 128K.
1909 * @sdev: scsi device
1910 * @max_io_size: maximum io transfer size
1914 megasas_set_nvme_device_properties(struct scsi_device
*sdev
, u32 max_io_size
)
1916 struct megasas_instance
*instance
;
1917 u32 mr_nvme_pg_size
;
1919 instance
= (struct megasas_instance
*)sdev
->host
->hostdata
;
1920 mr_nvme_pg_size
= max_t(u32
, instance
->nvme_page_size
,
1921 MR_DEFAULT_NVME_PAGE_SIZE
);
1923 blk_queue_max_hw_sectors(sdev
->request_queue
, (max_io_size
/ 512));
1925 blk_queue_flag_set(QUEUE_FLAG_NOMERGES
, sdev
->request_queue
);
1926 blk_queue_virt_boundary(sdev
->request_queue
, mr_nvme_pg_size
- 1);
1931 * megasas_set_static_target_properties -
1932 * Device property set by driver are static and it is not required to be
1933 * updated after OCR.
1936 * set device queue depth
1937 * set nvme device properties. see - megasas_set_nvme_device_properties
1939 * @sdev: scsi device
1940 * @is_target_prop true, if fw provided target properties.
1942 static void megasas_set_static_target_properties(struct scsi_device
*sdev
,
1943 bool is_target_prop
)
1946 u32 device_qd
= MEGASAS_DEFAULT_CMD_PER_LUN
;
1947 u32 max_io_size_kb
= MR_DEFAULT_NVME_MDTS_KB
;
1949 struct megasas_instance
*instance
;
1950 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
1952 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
1953 mr_device_priv_data
= sdev
->hostdata
;
1954 interface_type
= mr_device_priv_data
->interface_type
;
1957 * The RAID firmware may require extended timeouts.
1959 blk_queue_rq_timeout(sdev
->request_queue
, scmd_timeout
* HZ
);
1961 switch (interface_type
) {
1963 device_qd
= MEGASAS_SAS_QD
;
1966 device_qd
= MEGASAS_SATA_QD
;
1969 device_qd
= MEGASAS_NVME_QD
;
1973 if (is_target_prop
) {
1974 tgt_device_qd
= le32_to_cpu(instance
->tgt_prop
->device_qdepth
);
1975 if (tgt_device_qd
&&
1976 (tgt_device_qd
<= instance
->host
->can_queue
))
1977 device_qd
= tgt_device_qd
;
1979 /* max_io_size_kb will be set to non zero for
1980 * nvme based vd and syspd.
1982 max_io_size_kb
= le32_to_cpu(instance
->tgt_prop
->max_io_size_kb
);
1985 if (instance
->nvme_page_size
&& max_io_size_kb
)
1986 megasas_set_nvme_device_properties(sdev
, (max_io_size_kb
<< 10));
1988 scsi_change_queue_depth(sdev
, device_qd
);
1993 static int megasas_slave_configure(struct scsi_device
*sdev
)
1996 struct megasas_instance
*instance
;
1997 int ret_target_prop
= DCMD_FAILED
;
1998 bool is_target_prop
= false;
2000 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
2001 if (instance
->pd_list_not_supported
) {
2002 if (!MEGASAS_IS_LOGICAL(sdev
) && sdev
->type
== TYPE_DISK
) {
2003 pd_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) +
2005 if (instance
->pd_list
[pd_index
].driveState
!=
2011 mutex_lock(&instance
->reset_mutex
);
2012 /* Send DCMD to Firmware and cache the information */
2013 if ((instance
->pd_info
) && !MEGASAS_IS_LOGICAL(sdev
))
2014 megasas_get_pd_info(instance
, sdev
);
2016 /* Some ventura firmware may not have instance->nvme_page_size set.
2017 * Do not send MR_DCMD_DRV_GET_TARGET_PROP
2019 if ((instance
->tgt_prop
) && (instance
->nvme_page_size
))
2020 ret_target_prop
= megasas_get_target_prop(instance
, sdev
);
2022 is_target_prop
= (ret_target_prop
== DCMD_SUCCESS
) ? true : false;
2023 megasas_set_static_target_properties(sdev
, is_target_prop
);
2025 /* This sdev property may change post OCR */
2026 megasas_set_dynamic_target_properties(sdev
, is_target_prop
);
2028 mutex_unlock(&instance
->reset_mutex
);
2033 static int megasas_slave_alloc(struct scsi_device
*sdev
)
2036 struct megasas_instance
*instance
;
2037 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
2039 instance
= megasas_lookup_instance(sdev
->host
->host_no
);
2040 if (!MEGASAS_IS_LOGICAL(sdev
)) {
2042 * Open the OS scan to the SYSTEM PD
2045 (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) +
2047 if ((instance
->pd_list_not_supported
||
2048 instance
->pd_list
[pd_index
].driveState
==
2049 MR_PD_STATE_SYSTEM
)) {
2056 mr_device_priv_data
= kzalloc(sizeof(*mr_device_priv_data
),
2058 if (!mr_device_priv_data
)
2060 sdev
->hostdata
= mr_device_priv_data
;
2062 atomic_set(&mr_device_priv_data
->r1_ldio_hint
,
2063 instance
->r1_ldio_hint_default
);
2067 static void megasas_slave_destroy(struct scsi_device
*sdev
)
2069 kfree(sdev
->hostdata
);
2070 sdev
->hostdata
= NULL
;
2074 * megasas_complete_outstanding_ioctls - Complete outstanding ioctls after a
2076 * @instance: Adapter soft state
2079 static void megasas_complete_outstanding_ioctls(struct megasas_instance
*instance
)
2082 struct megasas_cmd
*cmd_mfi
;
2083 struct megasas_cmd_fusion
*cmd_fusion
;
2084 struct fusion_context
*fusion
= instance
->ctrl_context
;
2086 /* Find all outstanding ioctls */
2088 for (i
= 0; i
< instance
->max_fw_cmds
; i
++) {
2089 cmd_fusion
= fusion
->cmd_list
[i
];
2090 if (cmd_fusion
->sync_cmd_idx
!= (u32
)ULONG_MAX
) {
2091 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
2092 if (cmd_mfi
->sync_cmd
&&
2093 (cmd_mfi
->frame
->hdr
.cmd
!= MFI_CMD_ABORT
)) {
2094 cmd_mfi
->frame
->hdr
.cmd_status
=
2095 MFI_STAT_WRONG_STATE
;
2096 megasas_complete_cmd(instance
,
2102 for (i
= 0; i
< instance
->max_fw_cmds
; i
++) {
2103 cmd_mfi
= instance
->cmd_list
[i
];
2104 if (cmd_mfi
->sync_cmd
&& cmd_mfi
->frame
->hdr
.cmd
!=
2106 megasas_complete_cmd(instance
, cmd_mfi
, DID_OK
);
2112 void megaraid_sas_kill_hba(struct megasas_instance
*instance
)
2114 /* Set critical error to block I/O & ioctls in case caller didn't */
2115 atomic_set(&instance
->adprecovery
, MEGASAS_HW_CRITICAL_ERROR
);
2116 /* Wait 1 second to ensure IO or ioctls in build have posted */
2118 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
2119 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
2120 (instance
->adapter_type
!= MFI_SERIES
)) {
2121 if (!instance
->requestorId
) {
2122 writel(MFI_STOP_ADP
, &instance
->reg_set
->doorbell
);
2124 readl(&instance
->reg_set
->doorbell
);
2126 if (instance
->requestorId
&& instance
->peerIsPresent
)
2127 memset(instance
->ld_ids
, 0xff, MEGASAS_MAX_LD_IDS
);
2129 writel(MFI_STOP_ADP
,
2130 &instance
->reg_set
->inbound_doorbell
);
2132 /* Complete outstanding ioctls when adapter is killed */
2133 megasas_complete_outstanding_ioctls(instance
);
2137 * megasas_check_and_restore_queue_depth - Check if queue depth needs to be
2138 * restored to max value
2139 * @instance: Adapter soft state
2143 megasas_check_and_restore_queue_depth(struct megasas_instance
*instance
)
2145 unsigned long flags
;
2147 if (instance
->flag
& MEGASAS_FW_BUSY
2148 && time_after(jiffies
, instance
->last_time
+ 5 * HZ
)
2149 && atomic_read(&instance
->fw_outstanding
) <
2150 instance
->throttlequeuedepth
+ 1) {
2152 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
2153 instance
->flag
&= ~MEGASAS_FW_BUSY
;
2155 instance
->host
->can_queue
= instance
->cur_can_queue
;
2156 spin_unlock_irqrestore(instance
->host
->host_lock
, flags
);
2161 * megasas_complete_cmd_dpc - Returns FW's controller structure
2162 * @instance_addr: Address of adapter soft state
2164 * Tasklet to complete cmds
2166 static void megasas_complete_cmd_dpc(unsigned long instance_addr
)
2171 struct megasas_cmd
*cmd
;
2172 struct megasas_instance
*instance
=
2173 (struct megasas_instance
*)instance_addr
;
2174 unsigned long flags
;
2176 /* If we have already declared adapter dead, donot complete cmds */
2177 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
2180 spin_lock_irqsave(&instance
->completion_lock
, flags
);
2182 producer
= le32_to_cpu(*instance
->producer
);
2183 consumer
= le32_to_cpu(*instance
->consumer
);
2185 while (consumer
!= producer
) {
2186 context
= le32_to_cpu(instance
->reply_queue
[consumer
]);
2187 if (context
>= instance
->max_fw_cmds
) {
2188 dev_err(&instance
->pdev
->dev
, "Unexpected context value %x\n",
2193 cmd
= instance
->cmd_list
[context
];
2195 megasas_complete_cmd(instance
, cmd
, DID_OK
);
2198 if (consumer
== (instance
->max_fw_cmds
+ 1)) {
2203 *instance
->consumer
= cpu_to_le32(producer
);
2205 spin_unlock_irqrestore(&instance
->completion_lock
, flags
);
2208 * Check if we can restore can_queue
2210 megasas_check_and_restore_queue_depth(instance
);
2213 static void megasas_sriov_heartbeat_handler(struct timer_list
*t
);
2216 * megasas_start_timer - Initializes sriov heartbeat timer object
2217 * @instance: Adapter soft state
2220 void megasas_start_timer(struct megasas_instance
*instance
)
2222 struct timer_list
*timer
= &instance
->sriov_heartbeat_timer
;
2224 timer_setup(timer
, megasas_sriov_heartbeat_handler
, 0);
2225 timer
->expires
= jiffies
+ MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
;
2230 megasas_internal_reset_defer_cmds(struct megasas_instance
*instance
);
2233 process_fw_state_change_wq(struct work_struct
*work
);
2235 void megasas_do_ocr(struct megasas_instance
*instance
)
2237 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS1064R
) ||
2238 (instance
->pdev
->device
== PCI_DEVICE_ID_DELL_PERC5
) ||
2239 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_VERDE_ZCR
)) {
2240 *instance
->consumer
= cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN
);
2242 instance
->instancet
->disable_intr(instance
);
2243 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
2244 instance
->issuepend_done
= 0;
2246 atomic_set(&instance
->fw_outstanding
, 0);
2247 megasas_internal_reset_defer_cmds(instance
);
2248 process_fw_state_change_wq(&instance
->work_init
);
2251 static int megasas_get_ld_vf_affiliation_111(struct megasas_instance
*instance
,
2254 struct megasas_cmd
*cmd
;
2255 struct megasas_dcmd_frame
*dcmd
;
2256 struct MR_LD_VF_AFFILIATION_111
*new_affiliation_111
= NULL
;
2257 dma_addr_t new_affiliation_111_h
;
2261 cmd
= megasas_get_cmd(instance
);
2264 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_get_ld_vf_affiliation_111:"
2265 "Failed to get cmd for scsi%d\n",
2266 instance
->host
->host_no
);
2270 dcmd
= &cmd
->frame
->dcmd
;
2272 if (!instance
->vf_affiliation_111
) {
2273 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Couldn't get LD/VF "
2274 "affiliation for scsi%d\n", instance
->host
->host_no
);
2275 megasas_return_cmd(instance
, cmd
);
2280 memset(instance
->vf_affiliation_111
, 0,
2281 sizeof(struct MR_LD_VF_AFFILIATION_111
));
2283 new_affiliation_111
=
2284 dma_alloc_coherent(&instance
->pdev
->dev
,
2285 sizeof(struct MR_LD_VF_AFFILIATION_111
),
2286 &new_affiliation_111_h
, GFP_KERNEL
);
2287 if (!new_affiliation_111
) {
2288 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SR-IOV: Couldn't allocate "
2289 "memory for new affiliation for scsi%d\n",
2290 instance
->host
->host_no
);
2291 megasas_return_cmd(instance
, cmd
);
2296 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
2298 dcmd
->cmd
= MFI_CMD_DCMD
;
2299 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
2300 dcmd
->sge_count
= 1;
2301 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_BOTH
);
2304 dcmd
->data_xfer_len
=
2305 cpu_to_le32(sizeof(struct MR_LD_VF_AFFILIATION_111
));
2306 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111
);
2309 dcmd
->sgl
.sge32
[0].phys_addr
=
2310 cpu_to_le32(instance
->vf_affiliation_111_h
);
2312 dcmd
->sgl
.sge32
[0].phys_addr
=
2313 cpu_to_le32(new_affiliation_111_h
);
2315 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32(
2316 sizeof(struct MR_LD_VF_AFFILIATION_111
));
2318 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Getting LD/VF affiliation for "
2319 "scsi%d\n", instance
->host
->host_no
);
2321 if (megasas_issue_blocked_cmd(instance
, cmd
, 0) != DCMD_SUCCESS
) {
2322 dev_warn(&instance
->pdev
->dev
, "SR-IOV: LD/VF affiliation DCMD"
2323 " failed with status 0x%x for scsi%d\n",
2324 dcmd
->cmd_status
, instance
->host
->host_no
);
2325 retval
= 1; /* Do a scan if we couldn't get affiliation */
2330 thisVf
= new_affiliation_111
->thisVf
;
2331 for (ld
= 0 ; ld
< new_affiliation_111
->vdCount
; ld
++)
2332 if (instance
->vf_affiliation_111
->map
[ld
].policy
[thisVf
] !=
2333 new_affiliation_111
->map
[ld
].policy
[thisVf
]) {
2334 dev_warn(&instance
->pdev
->dev
, "SR-IOV: "
2335 "Got new LD/VF affiliation for scsi%d\n",
2336 instance
->host
->host_no
);
2337 memcpy(instance
->vf_affiliation_111
,
2338 new_affiliation_111
,
2339 sizeof(struct MR_LD_VF_AFFILIATION_111
));
2345 if (new_affiliation_111
) {
2346 dma_free_coherent(&instance
->pdev
->dev
,
2347 sizeof(struct MR_LD_VF_AFFILIATION_111
),
2348 new_affiliation_111
,
2349 new_affiliation_111_h
);
2352 megasas_return_cmd(instance
, cmd
);
2357 static int megasas_get_ld_vf_affiliation_12(struct megasas_instance
*instance
,
2360 struct megasas_cmd
*cmd
;
2361 struct megasas_dcmd_frame
*dcmd
;
2362 struct MR_LD_VF_AFFILIATION
*new_affiliation
= NULL
;
2363 struct MR_LD_VF_MAP
*newmap
= NULL
, *savedmap
= NULL
;
2364 dma_addr_t new_affiliation_h
;
2365 int i
, j
, retval
= 0, found
= 0, doscan
= 0;
2368 cmd
= megasas_get_cmd(instance
);
2371 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_get_ld_vf_affiliation12: "
2372 "Failed to get cmd for scsi%d\n",
2373 instance
->host
->host_no
);
2377 dcmd
= &cmd
->frame
->dcmd
;
2379 if (!instance
->vf_affiliation
) {
2380 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Couldn't get LD/VF "
2381 "affiliation for scsi%d\n", instance
->host
->host_no
);
2382 megasas_return_cmd(instance
, cmd
);
2387 memset(instance
->vf_affiliation
, 0, (MAX_LOGICAL_DRIVES
+ 1) *
2388 sizeof(struct MR_LD_VF_AFFILIATION
));
2391 dma_alloc_coherent(&instance
->pdev
->dev
,
2392 (MAX_LOGICAL_DRIVES
+ 1) * sizeof(struct MR_LD_VF_AFFILIATION
),
2393 &new_affiliation_h
, GFP_KERNEL
);
2394 if (!new_affiliation
) {
2395 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SR-IOV: Couldn't allocate "
2396 "memory for new affiliation for scsi%d\n",
2397 instance
->host
->host_no
);
2398 megasas_return_cmd(instance
, cmd
);
2403 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
2405 dcmd
->cmd
= MFI_CMD_DCMD
;
2406 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
2407 dcmd
->sge_count
= 1;
2408 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_BOTH
);
2411 dcmd
->data_xfer_len
= cpu_to_le32((MAX_LOGICAL_DRIVES
+ 1) *
2412 sizeof(struct MR_LD_VF_AFFILIATION
));
2413 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_VF_MAP_GET_ALL_LDS
);
2416 dcmd
->sgl
.sge32
[0].phys_addr
=
2417 cpu_to_le32(instance
->vf_affiliation_h
);
2419 dcmd
->sgl
.sge32
[0].phys_addr
=
2420 cpu_to_le32(new_affiliation_h
);
2422 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32((MAX_LOGICAL_DRIVES
+ 1) *
2423 sizeof(struct MR_LD_VF_AFFILIATION
));
2425 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Getting LD/VF affiliation for "
2426 "scsi%d\n", instance
->host
->host_no
);
2429 if (megasas_issue_blocked_cmd(instance
, cmd
, 0) != DCMD_SUCCESS
) {
2430 dev_warn(&instance
->pdev
->dev
, "SR-IOV: LD/VF affiliation DCMD"
2431 " failed with status 0x%x for scsi%d\n",
2432 dcmd
->cmd_status
, instance
->host
->host_no
);
2433 retval
= 1; /* Do a scan if we couldn't get affiliation */
2438 if (!new_affiliation
->ldCount
) {
2439 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Got new LD/VF "
2440 "affiliation for passive path for scsi%d\n",
2441 instance
->host
->host_no
);
2445 newmap
= new_affiliation
->map
;
2446 savedmap
= instance
->vf_affiliation
->map
;
2447 thisVf
= new_affiliation
->thisVf
;
2448 for (i
= 0 ; i
< new_affiliation
->ldCount
; i
++) {
2450 for (j
= 0; j
< instance
->vf_affiliation
->ldCount
;
2452 if (newmap
->ref
.targetId
==
2453 savedmap
->ref
.targetId
) {
2455 if (newmap
->policy
[thisVf
] !=
2456 savedmap
->policy
[thisVf
]) {
2461 savedmap
= (struct MR_LD_VF_MAP
*)
2462 ((unsigned char *)savedmap
+
2465 if (!found
&& newmap
->policy
[thisVf
] !=
2466 MR_LD_ACCESS_HIDDEN
) {
2470 newmap
= (struct MR_LD_VF_MAP
*)
2471 ((unsigned char *)newmap
+ newmap
->size
);
2474 newmap
= new_affiliation
->map
;
2475 savedmap
= instance
->vf_affiliation
->map
;
2477 for (i
= 0 ; i
< instance
->vf_affiliation
->ldCount
; i
++) {
2479 for (j
= 0 ; j
< new_affiliation
->ldCount
; j
++) {
2480 if (savedmap
->ref
.targetId
==
2481 newmap
->ref
.targetId
) {
2483 if (savedmap
->policy
[thisVf
] !=
2484 newmap
->policy
[thisVf
]) {
2489 newmap
= (struct MR_LD_VF_MAP
*)
2490 ((unsigned char *)newmap
+
2493 if (!found
&& savedmap
->policy
[thisVf
] !=
2494 MR_LD_ACCESS_HIDDEN
) {
2498 savedmap
= (struct MR_LD_VF_MAP
*)
2499 ((unsigned char *)savedmap
+
2505 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Got new LD/VF "
2506 "affiliation for scsi%d\n", instance
->host
->host_no
);
2507 memcpy(instance
->vf_affiliation
, new_affiliation
,
2508 new_affiliation
->size
);
2512 if (new_affiliation
)
2513 dma_free_coherent(&instance
->pdev
->dev
,
2514 (MAX_LOGICAL_DRIVES
+ 1) *
2515 sizeof(struct MR_LD_VF_AFFILIATION
),
2516 new_affiliation
, new_affiliation_h
);
2517 megasas_return_cmd(instance
, cmd
);
2522 /* This function will get the current SR-IOV LD/VF affiliation */
2523 static int megasas_get_ld_vf_affiliation(struct megasas_instance
*instance
,
2528 if (instance
->PlasmaFW111
)
2529 retval
= megasas_get_ld_vf_affiliation_111(instance
, initial
);
2531 retval
= megasas_get_ld_vf_affiliation_12(instance
, initial
);
2535 /* This function will tell FW to start the SR-IOV heartbeat */
2536 int megasas_sriov_start_heartbeat(struct megasas_instance
*instance
,
2539 struct megasas_cmd
*cmd
;
2540 struct megasas_dcmd_frame
*dcmd
;
2543 cmd
= megasas_get_cmd(instance
);
2546 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_sriov_start_heartbeat: "
2547 "Failed to get cmd for scsi%d\n",
2548 instance
->host
->host_no
);
2552 dcmd
= &cmd
->frame
->dcmd
;
2555 instance
->hb_host_mem
=
2556 dma_alloc_coherent(&instance
->pdev
->dev
,
2557 sizeof(struct MR_CTRL_HB_HOST_MEM
),
2558 &instance
->hb_host_mem_h
,
2560 if (!instance
->hb_host_mem
) {
2561 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SR-IOV: Couldn't allocate"
2562 " memory for heartbeat host memory for scsi%d\n",
2563 instance
->host
->host_no
);
2569 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
2571 dcmd
->mbox
.s
[0] = cpu_to_le16(sizeof(struct MR_CTRL_HB_HOST_MEM
));
2572 dcmd
->cmd
= MFI_CMD_DCMD
;
2573 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
2574 dcmd
->sge_count
= 1;
2575 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_BOTH
);
2578 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_CTRL_HB_HOST_MEM
));
2579 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC
);
2581 megasas_set_dma_settings(instance
, dcmd
, instance
->hb_host_mem_h
,
2582 sizeof(struct MR_CTRL_HB_HOST_MEM
));
2584 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Starting heartbeat for scsi%d\n",
2585 instance
->host
->host_no
);
2587 if ((instance
->adapter_type
!= MFI_SERIES
) &&
2588 !instance
->mask_interrupts
)
2589 retval
= megasas_issue_blocked_cmd(instance
, cmd
,
2590 MEGASAS_ROUTINE_WAIT_TIME_VF
);
2592 retval
= megasas_issue_polled(instance
, cmd
);
2595 dev_warn(&instance
->pdev
->dev
, "SR-IOV: MR_DCMD_CTRL_SHARED_HOST"
2596 "_MEM_ALLOC DCMD %s for scsi%d\n",
2597 (dcmd
->cmd_status
== MFI_STAT_INVALID_STATUS
) ?
2598 "timed out" : "failed", instance
->host
->host_no
);
2603 megasas_return_cmd(instance
, cmd
);
2608 /* Handler for SR-IOV heartbeat */
2609 static void megasas_sriov_heartbeat_handler(struct timer_list
*t
)
2611 struct megasas_instance
*instance
=
2612 from_timer(instance
, t
, sriov_heartbeat_timer
);
2614 if (instance
->hb_host_mem
->HB
.fwCounter
!=
2615 instance
->hb_host_mem
->HB
.driverCounter
) {
2616 instance
->hb_host_mem
->HB
.driverCounter
=
2617 instance
->hb_host_mem
->HB
.fwCounter
;
2618 mod_timer(&instance
->sriov_heartbeat_timer
,
2619 jiffies
+ MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
);
2621 dev_warn(&instance
->pdev
->dev
, "SR-IOV: Heartbeat never "
2622 "completed for scsi%d\n", instance
->host
->host_no
);
2623 schedule_work(&instance
->work_init
);
2628 * megasas_wait_for_outstanding - Wait for all outstanding cmds
2629 * @instance: Adapter soft state
2631 * This function waits for up to MEGASAS_RESET_WAIT_TIME seconds for FW to
2632 * complete all its outstanding commands. Returns error if one or more IOs
2633 * are pending after this time period. It also marks the controller dead.
2635 static int megasas_wait_for_outstanding(struct megasas_instance
*instance
)
2637 int i
, sl
, outstanding
;
2639 u32 wait_time
= MEGASAS_RESET_WAIT_TIME
;
2640 unsigned long flags
;
2641 struct list_head clist_local
;
2642 struct megasas_cmd
*reset_cmd
;
2645 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
2646 dev_info(&instance
->pdev
->dev
, "%s:%d HBA is killed.\n",
2647 __func__
, __LINE__
);
2651 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
2653 INIT_LIST_HEAD(&clist_local
);
2654 spin_lock_irqsave(&instance
->hba_lock
, flags
);
2655 list_splice_init(&instance
->internal_reset_pending_q
,
2657 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
2659 dev_notice(&instance
->pdev
->dev
, "HBA reset wait ...\n");
2660 for (i
= 0; i
< wait_time
; i
++) {
2662 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HBA_OPERATIONAL
)
2666 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
2667 dev_notice(&instance
->pdev
->dev
, "reset: Stopping HBA.\n");
2668 atomic_set(&instance
->adprecovery
, MEGASAS_HW_CRITICAL_ERROR
);
2673 while (!list_empty(&clist_local
)) {
2674 reset_cmd
= list_entry((&clist_local
)->next
,
2675 struct megasas_cmd
, list
);
2676 list_del_init(&reset_cmd
->list
);
2677 if (reset_cmd
->scmd
) {
2678 reset_cmd
->scmd
->result
= DID_REQUEUE
<< 16;
2679 dev_notice(&instance
->pdev
->dev
, "%d:%p reset [%02x]\n",
2680 reset_index
, reset_cmd
,
2681 reset_cmd
->scmd
->cmnd
[0]);
2683 reset_cmd
->scmd
->scsi_done(reset_cmd
->scmd
);
2684 megasas_return_cmd(instance
, reset_cmd
);
2685 } else if (reset_cmd
->sync_cmd
) {
2686 dev_notice(&instance
->pdev
->dev
, "%p synch cmds"
2690 reset_cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
2691 instance
->instancet
->fire_cmd(instance
,
2692 reset_cmd
->frame_phys_addr
,
2693 0, instance
->reg_set
);
2695 dev_notice(&instance
->pdev
->dev
, "%p unexpected"
2705 for (i
= 0; i
< resetwaittime
; i
++) {
2706 outstanding
= atomic_read(&instance
->fw_outstanding
);
2711 if (!(i
% MEGASAS_RESET_NOTICE_INTERVAL
)) {
2712 dev_notice(&instance
->pdev
->dev
, "[%2d]waiting for %d "
2713 "commands to complete\n",i
,outstanding
);
2715 * Call cmd completion routine. Cmd to be
2716 * be completed directly without depending on isr.
2718 megasas_complete_cmd_dpc((unsigned long)instance
);
2725 outstanding
= atomic_read(&instance
->fw_outstanding
);
2726 fw_state
= instance
->instancet
->read_fw_status_reg(instance
) & MFI_STATE_MASK
;
2728 if ((!outstanding
&& (fw_state
== MFI_STATE_OPERATIONAL
)))
2729 goto no_outstanding
;
2731 if (instance
->disableOnlineCtrlReset
)
2732 goto kill_hba_and_failed
;
2734 if ((fw_state
== MFI_STATE_FAULT
) || atomic_read(&instance
->fw_outstanding
)) {
2735 dev_info(&instance
->pdev
->dev
,
2736 "%s:%d waiting_for_outstanding: before issue OCR. FW state = 0x%x, outstanding 0x%x\n",
2737 __func__
, __LINE__
, fw_state
, atomic_read(&instance
->fw_outstanding
));
2739 goto kill_hba_and_failed
;
2740 megasas_do_ocr(instance
);
2742 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
2743 dev_info(&instance
->pdev
->dev
, "%s:%d OCR failed and HBA is killed.\n",
2744 __func__
, __LINE__
);
2747 dev_info(&instance
->pdev
->dev
, "%s:%d waiting_for_outstanding: after issue OCR.\n",
2748 __func__
, __LINE__
);
2750 for (sl
= 0; sl
< 10; sl
++)
2753 outstanding
= atomic_read(&instance
->fw_outstanding
);
2755 fw_state
= instance
->instancet
->read_fw_status_reg(instance
) & MFI_STATE_MASK
;
2756 if ((!outstanding
&& (fw_state
== MFI_STATE_OPERATIONAL
)))
2757 goto no_outstanding
;
2764 dev_info(&instance
->pdev
->dev
, "%s:%d no more pending commands remain after reset handling.\n",
2765 __func__
, __LINE__
);
2768 kill_hba_and_failed
:
2770 /* Reset not supported, kill adapter */
2771 dev_info(&instance
->pdev
->dev
, "%s:%d killing adapter scsi%d"
2772 " disableOnlineCtrlReset %d fw_outstanding %d \n",
2773 __func__
, __LINE__
, instance
->host
->host_no
, instance
->disableOnlineCtrlReset
,
2774 atomic_read(&instance
->fw_outstanding
));
2775 megasas_dump_pending_frames(instance
);
2776 megaraid_sas_kill_hba(instance
);
2782 * megasas_generic_reset - Generic reset routine
2783 * @scmd: Mid-layer SCSI command
2785 * This routine implements a generic reset handler for device, bus and host
2786 * reset requests. Device, bus and host specific reset handlers can use this
2787 * function after they do their specific tasks.
2789 static int megasas_generic_reset(struct scsi_cmnd
*scmd
)
2792 struct megasas_instance
*instance
;
2794 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2796 scmd_printk(KERN_NOTICE
, scmd
, "megasas: RESET cmd=%x retries=%x\n",
2797 scmd
->cmnd
[0], scmd
->retries
);
2799 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
2800 dev_err(&instance
->pdev
->dev
, "cannot recover from previous reset failures\n");
2804 ret_val
= megasas_wait_for_outstanding(instance
);
2805 if (ret_val
== SUCCESS
)
2806 dev_notice(&instance
->pdev
->dev
, "reset successful\n");
2808 dev_err(&instance
->pdev
->dev
, "failed to do reset\n");
2814 * megasas_reset_timer - quiesce the adapter if required
2817 * Sets the FW busy flag and reduces the host->can_queue if the
2818 * cmd has not been completed within the timeout period.
2821 blk_eh_timer_return
megasas_reset_timer(struct scsi_cmnd
*scmd
)
2823 struct megasas_instance
*instance
;
2824 unsigned long flags
;
2826 if (time_after(jiffies
, scmd
->jiffies_at_alloc
+
2827 (scmd_timeout
* 2) * HZ
)) {
2831 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2832 if (!(instance
->flag
& MEGASAS_FW_BUSY
)) {
2833 /* FW is busy, throttle IO */
2834 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
2836 instance
->host
->can_queue
= instance
->throttlequeuedepth
;
2837 instance
->last_time
= jiffies
;
2838 instance
->flag
|= MEGASAS_FW_BUSY
;
2840 spin_unlock_irqrestore(instance
->host
->host_lock
, flags
);
2842 return BLK_EH_RESET_TIMER
;
2846 * megasas_dump - This function will print hexdump of provided buffer.
2847 * @buf: Buffer to be dumped
2848 * @sz: Size in bytes
2849 * @format: Different formats of dumping e.g. format=n will
2850 * cause only 'n' 32 bit words to be dumped in a single
2854 megasas_dump(void *buf
, int sz
, int format
)
2857 __le32
*buf_loc
= (__le32
*)buf
;
2859 for (i
= 0; i
< (sz
/ sizeof(__le32
)); i
++) {
2860 if ((i
% format
) == 0) {
2862 printk(KERN_CONT
"\n");
2863 printk(KERN_CONT
"%08x: ", (i
* 4));
2865 printk(KERN_CONT
"%08x ", le32_to_cpu(buf_loc
[i
]));
2867 printk(KERN_CONT
"\n");
2871 * megasas_dump_reg_set - This function will print hexdump of register set
2872 * @buf: Buffer to be dumped
2873 * @sz: Size in bytes
2874 * @format: Different formats of dumping e.g. format=n will
2875 * cause only 'n' 32 bit words to be dumped in a
2879 megasas_dump_reg_set(void __iomem
*reg_set
)
2881 unsigned int i
, sz
= 256;
2882 u32 __iomem
*reg
= (u32 __iomem
*)reg_set
;
2884 for (i
= 0; i
< (sz
/ sizeof(u32
)); i
++)
2885 printk("%08x: %08x\n", (i
* 4), readl(®
[i
]));
2889 * megasas_dump_fusion_io - This function will print key details
2891 * @scmd: SCSI command pointer of SCSI IO
2894 megasas_dump_fusion_io(struct scsi_cmnd
*scmd
)
2896 struct megasas_cmd_fusion
*cmd
;
2897 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
2898 struct megasas_instance
*instance
;
2900 cmd
= (struct megasas_cmd_fusion
*)scmd
->SCp
.ptr
;
2901 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2903 scmd_printk(KERN_INFO
, scmd
,
2904 "scmd: (0x%p) retries: 0x%x allowed: 0x%x\n",
2905 scmd
, scmd
->retries
, scmd
->allowed
);
2906 scsi_print_command(scmd
);
2909 req_desc
= (union MEGASAS_REQUEST_DESCRIPTOR_UNION
*)cmd
->request_desc
;
2910 scmd_printk(KERN_INFO
, scmd
, "Request descriptor details:\n");
2911 scmd_printk(KERN_INFO
, scmd
,
2912 "RequestFlags:0x%x MSIxIndex:0x%x SMID:0x%x LMID:0x%x DevHandle:0x%x\n",
2913 req_desc
->SCSIIO
.RequestFlags
,
2914 req_desc
->SCSIIO
.MSIxIndex
, req_desc
->SCSIIO
.SMID
,
2915 req_desc
->SCSIIO
.LMID
, req_desc
->SCSIIO
.DevHandle
);
2917 printk(KERN_INFO
"IO request frame:\n");
2918 megasas_dump(cmd
->io_request
,
2919 MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
, 8);
2920 printk(KERN_INFO
"Chain frame:\n");
2921 megasas_dump(cmd
->sg_frame
,
2922 instance
->max_chain_frame_sz
, 8);
2928 * megasas_dump_sys_regs - This function will dump system registers through
2930 * @reg_set: Pointer to System register set.
2931 * @buf: Buffer to which output is to be written.
2932 * @return: Number of bytes written to buffer.
2934 static inline ssize_t
2935 megasas_dump_sys_regs(void __iomem
*reg_set
, char *buf
)
2937 unsigned int i
, sz
= 256;
2938 int bytes_wrote
= 0;
2939 char *loc
= (char *)buf
;
2940 u32 __iomem
*reg
= (u32 __iomem
*)reg_set
;
2942 for (i
= 0; i
< sz
/ sizeof(u32
); i
++) {
2943 bytes_wrote
+= snprintf(loc
+ bytes_wrote
, PAGE_SIZE
,
2944 "%08x: %08x\n", (i
* 4),
2951 * megasas_reset_bus_host - Bus & host reset handler entry point
2953 static int megasas_reset_bus_host(struct scsi_cmnd
*scmd
)
2956 struct megasas_instance
*instance
;
2958 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2960 scmd_printk(KERN_INFO
, scmd
,
2961 "OCR is requested due to IO timeout!!\n");
2963 scmd_printk(KERN_INFO
, scmd
,
2964 "SCSI host state: %d SCSI host busy: %d FW outstanding: %d\n",
2965 scmd
->device
->host
->shost_state
,
2966 scsi_host_busy(scmd
->device
->host
),
2967 atomic_read(&instance
->fw_outstanding
));
2969 * First wait for all commands to complete
2971 if (instance
->adapter_type
== MFI_SERIES
) {
2972 ret
= megasas_generic_reset(scmd
);
2974 megasas_dump_fusion_io(scmd
);
2975 ret
= megasas_reset_fusion(scmd
->device
->host
,
2976 SCSIIO_TIMEOUT_OCR
);
2983 * megasas_task_abort - Issues task abort request to firmware
2984 * (supported only for fusion adapters)
2985 * @scmd: SCSI command pointer
2987 static int megasas_task_abort(struct scsi_cmnd
*scmd
)
2990 struct megasas_instance
*instance
;
2992 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
2994 if (instance
->adapter_type
!= MFI_SERIES
)
2995 ret
= megasas_task_abort_fusion(scmd
);
2997 sdev_printk(KERN_NOTICE
, scmd
->device
, "TASK ABORT not supported\n");
3005 * megasas_reset_target: Issues target reset request to firmware
3006 * (supported only for fusion adapters)
3007 * @scmd: SCSI command pointer
3009 static int megasas_reset_target(struct scsi_cmnd
*scmd
)
3012 struct megasas_instance
*instance
;
3014 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
3016 if (instance
->adapter_type
!= MFI_SERIES
)
3017 ret
= megasas_reset_target_fusion(scmd
);
3019 sdev_printk(KERN_NOTICE
, scmd
->device
, "TARGET RESET not supported\n");
3027 * megasas_bios_param - Returns disk geometry for a disk
3028 * @sdev: device handle
3029 * @bdev: block device
3030 * @capacity: drive capacity
3031 * @geom: geometry parameters
3034 megasas_bios_param(struct scsi_device
*sdev
, struct block_device
*bdev
,
3035 sector_t capacity
, int geom
[])
3042 /* Default heads (64) & sectors (32) */
3046 tmp
= heads
* sectors
;
3047 cylinders
= capacity
;
3049 sector_div(cylinders
, tmp
);
3052 * Handle extended translation size for logical drives > 1Gb
3055 if (capacity
>= 0x200000) {
3058 tmp
= heads
*sectors
;
3059 cylinders
= capacity
;
3060 sector_div(cylinders
, tmp
);
3065 geom
[2] = cylinders
;
3070 static void megasas_aen_polling(struct work_struct
*work
);
3073 * megasas_service_aen - Processes an event notification
3074 * @instance: Adapter soft state
3075 * @cmd: AEN command completed by the ISR
3077 * For AEN, driver sends a command down to FW that is held by the FW till an
3078 * event occurs. When an event of interest occurs, FW completes the command
3079 * that it was previously holding.
3081 * This routines sends SIGIO signal to processes that have registered with the
3085 megasas_service_aen(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
3087 unsigned long flags
;
3090 * Don't signal app if it is just an aborted previously registered aen
3092 if ((!cmd
->abort_aen
) && (instance
->unload
== 0)) {
3093 spin_lock_irqsave(&poll_aen_lock
, flags
);
3094 megasas_poll_wait_aen
= 1;
3095 spin_unlock_irqrestore(&poll_aen_lock
, flags
);
3096 wake_up(&megasas_poll_wait
);
3097 kill_fasync(&megasas_async_queue
, SIGIO
, POLL_IN
);
3102 instance
->aen_cmd
= NULL
;
3104 megasas_return_cmd(instance
, cmd
);
3106 if ((instance
->unload
== 0) &&
3107 ((instance
->issuepend_done
== 1))) {
3108 struct megasas_aen_event
*ev
;
3110 ev
= kzalloc(sizeof(*ev
), GFP_ATOMIC
);
3112 dev_err(&instance
->pdev
->dev
, "megasas_service_aen: out of memory\n");
3114 ev
->instance
= instance
;
3116 INIT_DELAYED_WORK(&ev
->hotplug_work
,
3117 megasas_aen_polling
);
3118 schedule_delayed_work(&ev
->hotplug_work
, 0);
3124 megasas_fw_crash_buffer_store(struct device
*cdev
,
3125 struct device_attribute
*attr
, const char *buf
, size_t count
)
3127 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3128 struct megasas_instance
*instance
=
3129 (struct megasas_instance
*) shost
->hostdata
;
3131 unsigned long flags
;
3133 if (kstrtoint(buf
, 0, &val
) != 0)
3136 spin_lock_irqsave(&instance
->crashdump_lock
, flags
);
3137 instance
->fw_crash_buffer_offset
= val
;
3138 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3143 megasas_fw_crash_buffer_show(struct device
*cdev
,
3144 struct device_attribute
*attr
, char *buf
)
3146 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3147 struct megasas_instance
*instance
=
3148 (struct megasas_instance
*) shost
->hostdata
;
3150 unsigned long buff_addr
;
3151 unsigned long dmachunk
= CRASH_DMA_BUF_SIZE
;
3152 unsigned long src_addr
;
3153 unsigned long flags
;
3156 spin_lock_irqsave(&instance
->crashdump_lock
, flags
);
3157 buff_offset
= instance
->fw_crash_buffer_offset
;
3158 if (!instance
->crash_dump_buf
&&
3159 !((instance
->fw_crash_state
== AVAILABLE
) ||
3160 (instance
->fw_crash_state
== COPYING
))) {
3161 dev_err(&instance
->pdev
->dev
,
3162 "Firmware crash dump is not available\n");
3163 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3167 buff_addr
= (unsigned long) buf
;
3169 if (buff_offset
> (instance
->fw_crash_buffer_size
* dmachunk
)) {
3170 dev_err(&instance
->pdev
->dev
,
3171 "Firmware crash dump offset is out of range\n");
3172 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3176 size
= (instance
->fw_crash_buffer_size
* dmachunk
) - buff_offset
;
3177 size
= (size
>= PAGE_SIZE
) ? (PAGE_SIZE
- 1) : size
;
3179 src_addr
= (unsigned long)instance
->crash_buf
[buff_offset
/ dmachunk
] +
3180 (buff_offset
% dmachunk
);
3181 memcpy(buf
, (void *)src_addr
, size
);
3182 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3188 megasas_fw_crash_buffer_size_show(struct device
*cdev
,
3189 struct device_attribute
*attr
, char *buf
)
3191 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3192 struct megasas_instance
*instance
=
3193 (struct megasas_instance
*) shost
->hostdata
;
3195 return snprintf(buf
, PAGE_SIZE
, "%ld\n", (unsigned long)
3196 ((instance
->fw_crash_buffer_size
) * 1024 * 1024)/PAGE_SIZE
);
3200 megasas_fw_crash_state_store(struct device
*cdev
,
3201 struct device_attribute
*attr
, const char *buf
, size_t count
)
3203 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3204 struct megasas_instance
*instance
=
3205 (struct megasas_instance
*) shost
->hostdata
;
3207 unsigned long flags
;
3209 if (kstrtoint(buf
, 0, &val
) != 0)
3212 if ((val
<= AVAILABLE
|| val
> COPY_ERROR
)) {
3213 dev_err(&instance
->pdev
->dev
, "application updates invalid "
3214 "firmware crash state\n");
3218 instance
->fw_crash_state
= val
;
3220 if ((val
== COPIED
) || (val
== COPY_ERROR
)) {
3221 spin_lock_irqsave(&instance
->crashdump_lock
, flags
);
3222 megasas_free_host_crash_buffer(instance
);
3223 spin_unlock_irqrestore(&instance
->crashdump_lock
, flags
);
3224 if (val
== COPY_ERROR
)
3225 dev_info(&instance
->pdev
->dev
, "application failed to "
3226 "copy Firmware crash dump\n");
3228 dev_info(&instance
->pdev
->dev
, "Firmware crash dump "
3229 "copied successfully\n");
3235 megasas_fw_crash_state_show(struct device
*cdev
,
3236 struct device_attribute
*attr
, char *buf
)
3238 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3239 struct megasas_instance
*instance
=
3240 (struct megasas_instance
*) shost
->hostdata
;
3242 return snprintf(buf
, PAGE_SIZE
, "%d\n", instance
->fw_crash_state
);
3246 megasas_page_size_show(struct device
*cdev
,
3247 struct device_attribute
*attr
, char *buf
)
3249 return snprintf(buf
, PAGE_SIZE
, "%ld\n", (unsigned long)PAGE_SIZE
- 1);
3253 megasas_ldio_outstanding_show(struct device
*cdev
, struct device_attribute
*attr
,
3256 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3257 struct megasas_instance
*instance
= (struct megasas_instance
*)shost
->hostdata
;
3259 return snprintf(buf
, PAGE_SIZE
, "%d\n", atomic_read(&instance
->ldio_outstanding
));
3263 megasas_fw_cmds_outstanding_show(struct device
*cdev
,
3264 struct device_attribute
*attr
, char *buf
)
3266 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3267 struct megasas_instance
*instance
= (struct megasas_instance
*)shost
->hostdata
;
3269 return snprintf(buf
, PAGE_SIZE
, "%d\n", atomic_read(&instance
->fw_outstanding
));
3273 megasas_dump_system_regs_show(struct device
*cdev
,
3274 struct device_attribute
*attr
, char *buf
)
3276 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3277 struct megasas_instance
*instance
=
3278 (struct megasas_instance
*)shost
->hostdata
;
3280 return megasas_dump_sys_regs(instance
->reg_set
, buf
);
3284 megasas_raid_map_id_show(struct device
*cdev
, struct device_attribute
*attr
,
3287 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3288 struct megasas_instance
*instance
=
3289 (struct megasas_instance
*)shost
->hostdata
;
3291 return snprintf(buf
, PAGE_SIZE
, "%ld\n",
3292 (unsigned long)instance
->map_id
);
3295 static DEVICE_ATTR(fw_crash_buffer
, S_IRUGO
| S_IWUSR
,
3296 megasas_fw_crash_buffer_show
, megasas_fw_crash_buffer_store
);
3297 static DEVICE_ATTR(fw_crash_buffer_size
, S_IRUGO
,
3298 megasas_fw_crash_buffer_size_show
, NULL
);
3299 static DEVICE_ATTR(fw_crash_state
, S_IRUGO
| S_IWUSR
,
3300 megasas_fw_crash_state_show
, megasas_fw_crash_state_store
);
3301 static DEVICE_ATTR(page_size
, S_IRUGO
,
3302 megasas_page_size_show
, NULL
);
3303 static DEVICE_ATTR(ldio_outstanding
, S_IRUGO
,
3304 megasas_ldio_outstanding_show
, NULL
);
3305 static DEVICE_ATTR(fw_cmds_outstanding
, S_IRUGO
,
3306 megasas_fw_cmds_outstanding_show
, NULL
);
3307 static DEVICE_ATTR(dump_system_regs
, S_IRUGO
,
3308 megasas_dump_system_regs_show
, NULL
);
3309 static DEVICE_ATTR(raid_map_id
, S_IRUGO
,
3310 megasas_raid_map_id_show
, NULL
);
3312 struct device_attribute
*megaraid_host_attrs
[] = {
3313 &dev_attr_fw_crash_buffer_size
,
3314 &dev_attr_fw_crash_buffer
,
3315 &dev_attr_fw_crash_state
,
3316 &dev_attr_page_size
,
3317 &dev_attr_ldio_outstanding
,
3318 &dev_attr_fw_cmds_outstanding
,
3319 &dev_attr_dump_system_regs
,
3320 &dev_attr_raid_map_id
,
3325 * Scsi host template for megaraid_sas driver
3327 static struct scsi_host_template megasas_template
= {
3329 .module
= THIS_MODULE
,
3330 .name
= "Avago SAS based MegaRAID driver",
3331 .proc_name
= "megaraid_sas",
3332 .slave_configure
= megasas_slave_configure
,
3333 .slave_alloc
= megasas_slave_alloc
,
3334 .slave_destroy
= megasas_slave_destroy
,
3335 .queuecommand
= megasas_queue_command
,
3336 .eh_target_reset_handler
= megasas_reset_target
,
3337 .eh_abort_handler
= megasas_task_abort
,
3338 .eh_host_reset_handler
= megasas_reset_bus_host
,
3339 .eh_timed_out
= megasas_reset_timer
,
3340 .shost_attrs
= megaraid_host_attrs
,
3341 .bios_param
= megasas_bios_param
,
3342 .change_queue_depth
= scsi_change_queue_depth
,
3347 * megasas_complete_int_cmd - Completes an internal command
3348 * @instance: Adapter soft state
3349 * @cmd: Command to be completed
3351 * The megasas_issue_blocked_cmd() function waits for a command to complete
3352 * after it issues a command. This function wakes up that waiting routine by
3353 * calling wake_up() on the wait queue.
3356 megasas_complete_int_cmd(struct megasas_instance
*instance
,
3357 struct megasas_cmd
*cmd
)
3359 cmd
->cmd_status_drv
= cmd
->frame
->io
.cmd_status
;
3360 wake_up(&instance
->int_cmd_wait_q
);
3364 * megasas_complete_abort - Completes aborting a command
3365 * @instance: Adapter soft state
3366 * @cmd: Cmd that was issued to abort another cmd
3368 * The megasas_issue_blocked_abort_cmd() function waits on abort_cmd_wait_q
3369 * after it issues an abort on a previously issued command. This function
3370 * wakes up all functions waiting on the same wait queue.
3373 megasas_complete_abort(struct megasas_instance
*instance
,
3374 struct megasas_cmd
*cmd
)
3376 if (cmd
->sync_cmd
) {
3378 cmd
->cmd_status_drv
= 0;
3379 wake_up(&instance
->abort_cmd_wait_q
);
3384 * megasas_complete_cmd - Completes a command
3385 * @instance: Adapter soft state
3386 * @cmd: Command to be completed
3387 * @alt_status: If non-zero, use this value as status to
3388 * SCSI mid-layer instead of the value returned
3389 * by the FW. This should be used if caller wants
3390 * an alternate status (as in the case of aborted
3394 megasas_complete_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
3398 struct megasas_header
*hdr
= &cmd
->frame
->hdr
;
3399 unsigned long flags
;
3400 struct fusion_context
*fusion
= instance
->ctrl_context
;
3403 /* flag for the retry reset */
3404 cmd
->retry_for_fw_reset
= 0;
3407 cmd
->scmd
->SCp
.ptr
= NULL
;
3410 case MFI_CMD_INVALID
:
3411 /* Some older 1068 controller FW may keep a pended
3412 MR_DCMD_CTRL_EVENT_GET_INFO left over from the main kernel
3413 when booting the kdump kernel. Ignore this command to
3414 prevent a kernel panic on shutdown of the kdump kernel. */
3415 dev_warn(&instance
->pdev
->dev
, "MFI_CMD_INVALID command "
3417 dev_warn(&instance
->pdev
->dev
, "If you have a controller "
3418 "other than PERC5, please upgrade your firmware\n");
3420 case MFI_CMD_PD_SCSI_IO
:
3421 case MFI_CMD_LD_SCSI_IO
:
3424 * MFI_CMD_PD_SCSI_IO and MFI_CMD_LD_SCSI_IO could have been
3425 * issued either through an IO path or an IOCTL path. If it
3426 * was via IOCTL, we will send it to internal completion.
3428 if (cmd
->sync_cmd
) {
3430 megasas_complete_int_cmd(instance
, cmd
);
3435 case MFI_CMD_LD_READ
:
3436 case MFI_CMD_LD_WRITE
:
3439 cmd
->scmd
->result
= alt_status
<< 16;
3445 atomic_dec(&instance
->fw_outstanding
);
3447 scsi_dma_unmap(cmd
->scmd
);
3448 cmd
->scmd
->scsi_done(cmd
->scmd
);
3449 megasas_return_cmd(instance
, cmd
);
3454 switch (hdr
->cmd_status
) {
3457 cmd
->scmd
->result
= DID_OK
<< 16;
3460 case MFI_STAT_SCSI_IO_FAILED
:
3461 case MFI_STAT_LD_INIT_IN_PROGRESS
:
3463 (DID_ERROR
<< 16) | hdr
->scsi_status
;
3466 case MFI_STAT_SCSI_DONE_WITH_ERROR
:
3468 cmd
->scmd
->result
= (DID_OK
<< 16) | hdr
->scsi_status
;
3470 if (hdr
->scsi_status
== SAM_STAT_CHECK_CONDITION
) {
3471 memset(cmd
->scmd
->sense_buffer
, 0,
3472 SCSI_SENSE_BUFFERSIZE
);
3473 memcpy(cmd
->scmd
->sense_buffer
, cmd
->sense
,
3476 cmd
->scmd
->result
|= DRIVER_SENSE
<< 24;
3481 case MFI_STAT_LD_OFFLINE
:
3482 case MFI_STAT_DEVICE_NOT_FOUND
:
3483 cmd
->scmd
->result
= DID_BAD_TARGET
<< 16;
3487 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "MFI FW status %#x\n",
3489 cmd
->scmd
->result
= DID_ERROR
<< 16;
3493 atomic_dec(&instance
->fw_outstanding
);
3495 scsi_dma_unmap(cmd
->scmd
);
3496 cmd
->scmd
->scsi_done(cmd
->scmd
);
3497 megasas_return_cmd(instance
, cmd
);
3504 megasas_complete_int_cmd(instance
, cmd
);
3508 opcode
= le32_to_cpu(cmd
->frame
->dcmd
.opcode
);
3509 /* Check for LD map update */
3510 if ((opcode
== MR_DCMD_LD_MAP_GET_INFO
)
3511 && (cmd
->frame
->dcmd
.mbox
.b
[1] == 1)) {
3512 fusion
->fast_path_io
= 0;
3513 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
3514 status
= cmd
->frame
->hdr
.cmd_status
;
3515 instance
->map_update_cmd
= NULL
;
3516 if (status
!= MFI_STAT_OK
) {
3517 if (status
!= MFI_STAT_NOT_FOUND
)
3518 dev_warn(&instance
->pdev
->dev
, "map syncfailed, status = 0x%x\n",
3519 cmd
->frame
->hdr
.cmd_status
);
3521 megasas_return_cmd(instance
, cmd
);
3522 spin_unlock_irqrestore(
3523 instance
->host
->host_lock
,
3529 megasas_return_cmd(instance
, cmd
);
3532 * Set fast path IO to ZERO.
3533 * Validate Map will set proper value.
3534 * Meanwhile all IOs will go as LD IO.
3536 if (status
== MFI_STAT_OK
&&
3537 (MR_ValidateMapInfo(instance
, (instance
->map_id
+ 1)))) {
3539 fusion
->fast_path_io
= 1;
3541 fusion
->fast_path_io
= 0;
3544 megasas_sync_map_info(instance
);
3545 spin_unlock_irqrestore(instance
->host
->host_lock
,
3549 if (opcode
== MR_DCMD_CTRL_EVENT_GET_INFO
||
3550 opcode
== MR_DCMD_CTRL_EVENT_GET
) {
3551 spin_lock_irqsave(&poll_aen_lock
, flags
);
3552 megasas_poll_wait_aen
= 0;
3553 spin_unlock_irqrestore(&poll_aen_lock
, flags
);
3556 /* FW has an updated PD sequence */
3557 if ((opcode
== MR_DCMD_SYSTEM_PD_MAP_GET_INFO
) &&
3558 (cmd
->frame
->dcmd
.mbox
.b
[0] == 1)) {
3560 spin_lock_irqsave(instance
->host
->host_lock
, flags
);
3561 status
= cmd
->frame
->hdr
.cmd_status
;
3562 instance
->jbod_seq_cmd
= NULL
;
3563 megasas_return_cmd(instance
, cmd
);
3565 if (status
== MFI_STAT_OK
) {
3566 instance
->pd_seq_map_id
++;
3567 /* Re-register a pd sync seq num cmd */
3568 if (megasas_sync_pd_seq_num(instance
, true))
3569 instance
->use_seqnum_jbod_fp
= false;
3571 instance
->use_seqnum_jbod_fp
= false;
3573 spin_unlock_irqrestore(instance
->host
->host_lock
, flags
);
3578 * See if got an event notification
3580 if (opcode
== MR_DCMD_CTRL_EVENT_WAIT
)
3581 megasas_service_aen(instance
, cmd
);
3583 megasas_complete_int_cmd(instance
, cmd
);
3589 * Cmd issued to abort another cmd returned
3591 megasas_complete_abort(instance
, cmd
);
3595 dev_info(&instance
->pdev
->dev
, "Unknown command completed! [0x%X]\n",
3597 megasas_complete_int_cmd(instance
, cmd
);
3603 * megasas_issue_pending_cmds_again - issue all pending cmds
3604 * in FW again because of the fw reset
3605 * @instance: Adapter soft state
3608 megasas_issue_pending_cmds_again(struct megasas_instance
*instance
)
3610 struct megasas_cmd
*cmd
;
3611 struct list_head clist_local
;
3612 union megasas_evt_class_locale class_locale
;
3613 unsigned long flags
;
3616 INIT_LIST_HEAD(&clist_local
);
3617 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3618 list_splice_init(&instance
->internal_reset_pending_q
, &clist_local
);
3619 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3621 while (!list_empty(&clist_local
)) {
3622 cmd
= list_entry((&clist_local
)->next
,
3623 struct megasas_cmd
, list
);
3624 list_del_init(&cmd
->list
);
3626 if (cmd
->sync_cmd
|| cmd
->scmd
) {
3627 dev_notice(&instance
->pdev
->dev
, "command %p, %p:%d"
3628 "detected to be pending while HBA reset\n",
3629 cmd
, cmd
->scmd
, cmd
->sync_cmd
);
3631 cmd
->retry_for_fw_reset
++;
3633 if (cmd
->retry_for_fw_reset
== 3) {
3634 dev_notice(&instance
->pdev
->dev
, "cmd %p, %p:%d"
3635 "was tried multiple times during reset."
3636 "Shutting down the HBA\n",
3637 cmd
, cmd
->scmd
, cmd
->sync_cmd
);
3638 instance
->instancet
->disable_intr(instance
);
3639 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
3640 megaraid_sas_kill_hba(instance
);
3645 if (cmd
->sync_cmd
== 1) {
3647 dev_notice(&instance
->pdev
->dev
, "unexpected"
3648 "cmd attached to internal command!\n");
3650 dev_notice(&instance
->pdev
->dev
, "%p synchronous cmd"
3651 "on the internal reset queue,"
3652 "issue it again.\n", cmd
);
3653 cmd
->cmd_status_drv
= MFI_STAT_INVALID_STATUS
;
3654 instance
->instancet
->fire_cmd(instance
,
3655 cmd
->frame_phys_addr
,
3656 0, instance
->reg_set
);
3657 } else if (cmd
->scmd
) {
3658 dev_notice(&instance
->pdev
->dev
, "%p scsi cmd [%02x]"
3659 "detected on the internal queue, issue again.\n",
3660 cmd
, cmd
->scmd
->cmnd
[0]);
3662 atomic_inc(&instance
->fw_outstanding
);
3663 instance
->instancet
->fire_cmd(instance
,
3664 cmd
->frame_phys_addr
,
3665 cmd
->frame_count
-1, instance
->reg_set
);
3667 dev_notice(&instance
->pdev
->dev
, "%p unexpected cmd on the"
3668 "internal reset defer list while re-issue!!\n",
3673 if (instance
->aen_cmd
) {
3674 dev_notice(&instance
->pdev
->dev
, "aen_cmd in def process\n");
3675 megasas_return_cmd(instance
, instance
->aen_cmd
);
3677 instance
->aen_cmd
= NULL
;
3681 * Initiate AEN (Asynchronous Event Notification)
3683 seq_num
= instance
->last_seq_num
;
3684 class_locale
.members
.reserved
= 0;
3685 class_locale
.members
.locale
= MR_EVT_LOCALE_ALL
;
3686 class_locale
.members
.class = MR_EVT_CLASS_DEBUG
;
3688 megasas_register_aen(instance
, seq_num
, class_locale
.word
);
3692 * Move the internal reset pending commands to a deferred queue.
3694 * We move the commands pending at internal reset time to a
3695 * pending queue. This queue would be flushed after successful
3696 * completion of the internal reset sequence. if the internal reset
3697 * did not complete in time, the kernel reset handler would flush
3701 megasas_internal_reset_defer_cmds(struct megasas_instance
*instance
)
3703 struct megasas_cmd
*cmd
;
3705 u16 max_cmd
= instance
->max_fw_cmds
;
3707 unsigned long flags
;
3710 spin_lock_irqsave(&instance
->mfi_pool_lock
, flags
);
3711 for (i
= 0; i
< max_cmd
; i
++) {
3712 cmd
= instance
->cmd_list
[i
];
3713 if (cmd
->sync_cmd
== 1 || cmd
->scmd
) {
3714 dev_notice(&instance
->pdev
->dev
, "moving cmd[%d]:%p:%d:%p"
3715 "on the defer queue as internal\n",
3716 defer_index
, cmd
, cmd
->sync_cmd
, cmd
->scmd
);
3718 if (!list_empty(&cmd
->list
)) {
3719 dev_notice(&instance
->pdev
->dev
, "ERROR while"
3720 " moving this cmd:%p, %d %p, it was"
3721 "discovered on some list?\n",
3722 cmd
, cmd
->sync_cmd
, cmd
->scmd
);
3724 list_del_init(&cmd
->list
);
3727 list_add_tail(&cmd
->list
,
3728 &instance
->internal_reset_pending_q
);
3731 spin_unlock_irqrestore(&instance
->mfi_pool_lock
, flags
);
3736 process_fw_state_change_wq(struct work_struct
*work
)
3738 struct megasas_instance
*instance
=
3739 container_of(work
, struct megasas_instance
, work_init
);
3741 unsigned long flags
;
3743 if (atomic_read(&instance
->adprecovery
) != MEGASAS_ADPRESET_SM_INFAULT
) {
3744 dev_notice(&instance
->pdev
->dev
, "error, recovery st %x\n",
3745 atomic_read(&instance
->adprecovery
));
3749 if (atomic_read(&instance
->adprecovery
) == MEGASAS_ADPRESET_SM_INFAULT
) {
3750 dev_notice(&instance
->pdev
->dev
, "FW detected to be in fault"
3751 "state, restarting it...\n");
3753 instance
->instancet
->disable_intr(instance
);
3754 atomic_set(&instance
->fw_outstanding
, 0);
3756 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
3757 instance
->instancet
->adp_reset(instance
, instance
->reg_set
);
3758 atomic_set(&instance
->fw_reset_no_pci_access
, 0);
3760 dev_notice(&instance
->pdev
->dev
, "FW restarted successfully,"
3761 "initiating next stage...\n");
3763 dev_notice(&instance
->pdev
->dev
, "HBA recovery state machine,"
3764 "state 2 starting...\n");
3766 /* waiting for about 20 second before start the second init */
3767 for (wait
= 0; wait
< 30; wait
++) {
3771 if (megasas_transition_to_ready(instance
, 1)) {
3772 dev_notice(&instance
->pdev
->dev
, "adapter not ready\n");
3774 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
3775 megaraid_sas_kill_hba(instance
);
3779 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS1064R
) ||
3780 (instance
->pdev
->device
== PCI_DEVICE_ID_DELL_PERC5
) ||
3781 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_VERDE_ZCR
)
3783 *instance
->consumer
= *instance
->producer
;
3785 *instance
->consumer
= 0;
3786 *instance
->producer
= 0;
3789 megasas_issue_init_mfi(instance
);
3791 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3792 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
3793 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3794 instance
->instancet
->enable_intr(instance
);
3796 megasas_issue_pending_cmds_again(instance
);
3797 instance
->issuepend_done
= 1;
3802 * megasas_deplete_reply_queue - Processes all completed commands
3803 * @instance: Adapter soft state
3804 * @alt_status: Alternate status to be returned to
3805 * SCSI mid-layer instead of the status
3806 * returned by the FW
3807 * Note: this must be called with hba lock held
3810 megasas_deplete_reply_queue(struct megasas_instance
*instance
,
3816 if ((mfiStatus
= instance
->instancet
->check_reset(instance
,
3817 instance
->reg_set
)) == 1) {
3821 mfiStatus
= instance
->instancet
->clear_intr(instance
);
3822 if (mfiStatus
== 0) {
3823 /* Hardware may not set outbound_intr_status in MSI-X mode */
3824 if (!instance
->msix_vectors
)
3828 instance
->mfiStatus
= mfiStatus
;
3830 if ((mfiStatus
& MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE
)) {
3831 fw_state
= instance
->instancet
->read_fw_status_reg(
3832 instance
) & MFI_STATE_MASK
;
3834 if (fw_state
!= MFI_STATE_FAULT
) {
3835 dev_notice(&instance
->pdev
->dev
, "fw state:%x\n",
3839 if ((fw_state
== MFI_STATE_FAULT
) &&
3840 (instance
->disableOnlineCtrlReset
== 0)) {
3841 dev_notice(&instance
->pdev
->dev
, "wait adp restart\n");
3843 if ((instance
->pdev
->device
==
3844 PCI_DEVICE_ID_LSI_SAS1064R
) ||
3845 (instance
->pdev
->device
==
3846 PCI_DEVICE_ID_DELL_PERC5
) ||
3847 (instance
->pdev
->device
==
3848 PCI_DEVICE_ID_LSI_VERDE_ZCR
)) {
3850 *instance
->consumer
=
3851 cpu_to_le32(MEGASAS_ADPRESET_INPROG_SIGN
);
3855 instance
->instancet
->disable_intr(instance
);
3856 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
3857 instance
->issuepend_done
= 0;
3859 atomic_set(&instance
->fw_outstanding
, 0);
3860 megasas_internal_reset_defer_cmds(instance
);
3862 dev_notice(&instance
->pdev
->dev
, "fwState=%x, stage:%d\n",
3863 fw_state
, atomic_read(&instance
->adprecovery
));
3865 schedule_work(&instance
->work_init
);
3869 dev_notice(&instance
->pdev
->dev
, "fwstate:%x, dis_OCR=%x\n",
3870 fw_state
, instance
->disableOnlineCtrlReset
);
3874 tasklet_schedule(&instance
->isr_tasklet
);
3878 * megasas_isr - isr entry point
3880 static irqreturn_t
megasas_isr(int irq
, void *devp
)
3882 struct megasas_irq_context
*irq_context
= devp
;
3883 struct megasas_instance
*instance
= irq_context
->instance
;
3884 unsigned long flags
;
3887 if (atomic_read(&instance
->fw_reset_no_pci_access
))
3890 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3891 rc
= megasas_deplete_reply_queue(instance
, DID_OK
);
3892 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3898 * megasas_transition_to_ready - Move the FW to READY state
3899 * @instance: Adapter soft state
3901 * During the initialization, FW passes can potentially be in any one of
3902 * several possible states. If the FW in operational, waiting-for-handshake
3903 * states, driver must take steps to bring it to ready state. Otherwise, it
3904 * has to wait for the ready state.
3907 megasas_transition_to_ready(struct megasas_instance
*instance
, int ocr
)
3912 u32 abs_state
, curr_abs_state
;
3914 abs_state
= instance
->instancet
->read_fw_status_reg(instance
);
3915 fw_state
= abs_state
& MFI_STATE_MASK
;
3917 if (fw_state
!= MFI_STATE_READY
)
3918 dev_info(&instance
->pdev
->dev
, "Waiting for FW to come to ready"
3921 while (fw_state
!= MFI_STATE_READY
) {
3925 case MFI_STATE_FAULT
:
3926 dev_printk(KERN_ERR
, &instance
->pdev
->dev
,
3927 "FW in FAULT state, Fault code:0x%x subcode:0x%x func:%s\n",
3928 abs_state
& MFI_STATE_FAULT_CODE
,
3929 abs_state
& MFI_STATE_FAULT_SUBCODE
, __func__
);
3931 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3934 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "System Register set:\n");
3935 megasas_dump_reg_set(instance
->reg_set
);
3939 case MFI_STATE_WAIT_HANDSHAKE
:
3941 * Set the CLR bit in inbound doorbell
3943 if ((instance
->pdev
->device
==
3944 PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
3945 (instance
->pdev
->device
==
3946 PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
3947 (instance
->adapter_type
!= MFI_SERIES
))
3949 MFI_INIT_CLEAR_HANDSHAKE
|MFI_INIT_HOTPLUG
,
3950 &instance
->reg_set
->doorbell
);
3953 MFI_INIT_CLEAR_HANDSHAKE
|MFI_INIT_HOTPLUG
,
3954 &instance
->reg_set
->inbound_doorbell
);
3956 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3959 case MFI_STATE_BOOT_MESSAGE_PENDING
:
3960 if ((instance
->pdev
->device
==
3961 PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
3962 (instance
->pdev
->device
==
3963 PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
3964 (instance
->adapter_type
!= MFI_SERIES
))
3965 writel(MFI_INIT_HOTPLUG
,
3966 &instance
->reg_set
->doorbell
);
3968 writel(MFI_INIT_HOTPLUG
,
3969 &instance
->reg_set
->inbound_doorbell
);
3971 max_wait
= MEGASAS_RESET_WAIT_TIME
;
3974 case MFI_STATE_OPERATIONAL
:
3976 * Bring it to READY state; assuming max wait 10 secs
3978 instance
->instancet
->disable_intr(instance
);
3979 if ((instance
->pdev
->device
==
3980 PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
3981 (instance
->pdev
->device
==
3982 PCI_DEVICE_ID_LSI_SAS0071SKINNY
) ||
3983 (instance
->adapter_type
!= MFI_SERIES
)) {
3984 writel(MFI_RESET_FLAGS
,
3985 &instance
->reg_set
->doorbell
);
3987 if (instance
->adapter_type
!= MFI_SERIES
) {
3988 for (i
= 0; i
< (10 * 1000); i
+= 20) {
4000 writel(MFI_RESET_FLAGS
,
4001 &instance
->reg_set
->inbound_doorbell
);
4003 max_wait
= MEGASAS_RESET_WAIT_TIME
;
4006 case MFI_STATE_UNDEFINED
:
4008 * This state should not last for more than 2 seconds
4010 max_wait
= MEGASAS_RESET_WAIT_TIME
;
4013 case MFI_STATE_BB_INIT
:
4014 max_wait
= MEGASAS_RESET_WAIT_TIME
;
4017 case MFI_STATE_FW_INIT
:
4018 max_wait
= MEGASAS_RESET_WAIT_TIME
;
4021 case MFI_STATE_FW_INIT_2
:
4022 max_wait
= MEGASAS_RESET_WAIT_TIME
;
4025 case MFI_STATE_DEVICE_SCAN
:
4026 max_wait
= MEGASAS_RESET_WAIT_TIME
;
4029 case MFI_STATE_FLUSH_CACHE
:
4030 max_wait
= MEGASAS_RESET_WAIT_TIME
;
4034 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Unknown state 0x%x\n",
4036 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "System Register set:\n");
4037 megasas_dump_reg_set(instance
->reg_set
);
4042 * The cur_state should not last for more than max_wait secs
4044 for (i
= 0; i
< max_wait
* 50; i
++) {
4045 curr_abs_state
= instance
->instancet
->
4046 read_fw_status_reg(instance
);
4048 if (abs_state
== curr_abs_state
) {
4055 * Return error if fw_state hasn't changed after max_wait
4057 if (curr_abs_state
== abs_state
) {
4058 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "FW state [%d] hasn't changed "
4059 "in %d secs\n", fw_state
, max_wait
);
4060 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "System Register set:\n");
4061 megasas_dump_reg_set(instance
->reg_set
);
4065 abs_state
= curr_abs_state
;
4066 fw_state
= curr_abs_state
& MFI_STATE_MASK
;
4068 dev_info(&instance
->pdev
->dev
, "FW now in Ready state\n");
4074 * megasas_teardown_frame_pool - Destroy the cmd frame DMA pool
4075 * @instance: Adapter soft state
4077 static void megasas_teardown_frame_pool(struct megasas_instance
*instance
)
4080 u16 max_cmd
= instance
->max_mfi_cmds
;
4081 struct megasas_cmd
*cmd
;
4083 if (!instance
->frame_dma_pool
)
4087 * Return all frames to pool
4089 for (i
= 0; i
< max_cmd
; i
++) {
4091 cmd
= instance
->cmd_list
[i
];
4094 dma_pool_free(instance
->frame_dma_pool
, cmd
->frame
,
4095 cmd
->frame_phys_addr
);
4098 dma_pool_free(instance
->sense_dma_pool
, cmd
->sense
,
4099 cmd
->sense_phys_addr
);
4103 * Now destroy the pool itself
4105 dma_pool_destroy(instance
->frame_dma_pool
);
4106 dma_pool_destroy(instance
->sense_dma_pool
);
4108 instance
->frame_dma_pool
= NULL
;
4109 instance
->sense_dma_pool
= NULL
;
4113 * megasas_create_frame_pool - Creates DMA pool for cmd frames
4114 * @instance: Adapter soft state
4116 * Each command packet has an embedded DMA memory buffer that is used for
4117 * filling MFI frame and the SG list that immediately follows the frame. This
4118 * function creates those DMA memory buffers for each command packet by using
4119 * PCI pool facility.
4121 static int megasas_create_frame_pool(struct megasas_instance
*instance
)
4127 struct megasas_cmd
*cmd
;
4129 max_cmd
= instance
->max_mfi_cmds
;
4132 * Size of our frame is 64 bytes for MFI frame, followed by max SG
4133 * elements and finally SCSI_SENSE_BUFFERSIZE bytes for sense buffer
4135 sge_sz
= (IS_DMA64
) ? sizeof(struct megasas_sge64
) :
4136 sizeof(struct megasas_sge32
);
4138 if (instance
->flag_ieee
)
4139 sge_sz
= sizeof(struct megasas_sge_skinny
);
4142 * For MFI controllers.
4144 * max_sge_sz = 16 byte (sizeof megasas_sge_skinny)
4145 * Total 960 byte (15 MFI frame of 64 byte)
4147 * Fusion adapter require only 3 extra frame.
4148 * max_num_sge = 16 (defined as MAX_IOCTL_SGE)
4149 * max_sge_sz = 12 byte (sizeof megasas_sge64)
4150 * Total 192 byte (3 MFI frame of 64 byte)
4152 frame_count
= (instance
->adapter_type
== MFI_SERIES
) ?
4154 instance
->mfi_frame_size
= MEGAMFI_FRAME_SIZE
* frame_count
;
4156 * Use DMA pool facility provided by PCI layer
4158 instance
->frame_dma_pool
= dma_pool_create("megasas frame pool",
4159 &instance
->pdev
->dev
,
4160 instance
->mfi_frame_size
, 256, 0);
4162 if (!instance
->frame_dma_pool
) {
4163 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "failed to setup frame pool\n");
4167 instance
->sense_dma_pool
= dma_pool_create("megasas sense pool",
4168 &instance
->pdev
->dev
, 128,
4171 if (!instance
->sense_dma_pool
) {
4172 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "failed to setup sense pool\n");
4174 dma_pool_destroy(instance
->frame_dma_pool
);
4175 instance
->frame_dma_pool
= NULL
;
4181 * Allocate and attach a frame to each of the commands in cmd_list.
4182 * By making cmd->index as the context instead of the &cmd, we can
4183 * always use 32bit context regardless of the architecture
4185 for (i
= 0; i
< max_cmd
; i
++) {
4187 cmd
= instance
->cmd_list
[i
];
4189 cmd
->frame
= dma_pool_zalloc(instance
->frame_dma_pool
,
4190 GFP_KERNEL
, &cmd
->frame_phys_addr
);
4192 cmd
->sense
= dma_pool_alloc(instance
->sense_dma_pool
,
4193 GFP_KERNEL
, &cmd
->sense_phys_addr
);
4196 * megasas_teardown_frame_pool() takes care of freeing
4197 * whatever has been allocated
4199 if (!cmd
->frame
|| !cmd
->sense
) {
4200 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "dma_pool_alloc failed\n");
4201 megasas_teardown_frame_pool(instance
);
4205 cmd
->frame
->io
.context
= cpu_to_le32(cmd
->index
);
4206 cmd
->frame
->io
.pad_0
= 0;
4207 if ((instance
->adapter_type
== MFI_SERIES
) && reset_devices
)
4208 cmd
->frame
->hdr
.cmd
= MFI_CMD_INVALID
;
4215 * megasas_free_cmds - Free all the cmds in the free cmd pool
4216 * @instance: Adapter soft state
4218 void megasas_free_cmds(struct megasas_instance
*instance
)
4222 /* First free the MFI frame pool */
4223 megasas_teardown_frame_pool(instance
);
4225 /* Free all the commands in the cmd_list */
4226 for (i
= 0; i
< instance
->max_mfi_cmds
; i
++)
4228 kfree(instance
->cmd_list
[i
]);
4230 /* Free the cmd_list buffer itself */
4231 kfree(instance
->cmd_list
);
4232 instance
->cmd_list
= NULL
;
4234 INIT_LIST_HEAD(&instance
->cmd_pool
);
4238 * megasas_alloc_cmds - Allocates the command packets
4239 * @instance: Adapter soft state
4241 * Each command that is issued to the FW, whether IO commands from the OS or
4242 * internal commands like IOCTLs, are wrapped in local data structure called
4243 * megasas_cmd. The frame embedded in this megasas_cmd is actually issued to
4246 * Each frame has a 32-bit field called context (tag). This context is used
4247 * to get back the megasas_cmd from the frame when a frame gets completed in
4248 * the ISR. Typically the address of the megasas_cmd itself would be used as
4249 * the context. But we wanted to keep the differences between 32 and 64 bit
4250 * systems to the mininum. We always use 32 bit integers for the context. In
4251 * this driver, the 32 bit values are the indices into an array cmd_list.
4252 * This array is used only to look up the megasas_cmd given the context. The
4253 * free commands themselves are maintained in a linked list called cmd_pool.
4255 int megasas_alloc_cmds(struct megasas_instance
*instance
)
4260 struct megasas_cmd
*cmd
;
4262 max_cmd
= instance
->max_mfi_cmds
;
4265 * instance->cmd_list is an array of struct megasas_cmd pointers.
4266 * Allocate the dynamic array first and then allocate individual
4269 instance
->cmd_list
= kcalloc(max_cmd
, sizeof(struct megasas_cmd
*), GFP_KERNEL
);
4271 if (!instance
->cmd_list
) {
4272 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "out of memory\n");
4276 memset(instance
->cmd_list
, 0, sizeof(struct megasas_cmd
*) *max_cmd
);
4278 for (i
= 0; i
< max_cmd
; i
++) {
4279 instance
->cmd_list
[i
] = kmalloc(sizeof(struct megasas_cmd
),
4282 if (!instance
->cmd_list
[i
]) {
4284 for (j
= 0; j
< i
; j
++)
4285 kfree(instance
->cmd_list
[j
]);
4287 kfree(instance
->cmd_list
);
4288 instance
->cmd_list
= NULL
;
4294 for (i
= 0; i
< max_cmd
; i
++) {
4295 cmd
= instance
->cmd_list
[i
];
4296 memset(cmd
, 0, sizeof(struct megasas_cmd
));
4299 cmd
->instance
= instance
;
4301 list_add_tail(&cmd
->list
, &instance
->cmd_pool
);
4305 * Create a frame pool and assign one frame to each cmd
4307 if (megasas_create_frame_pool(instance
)) {
4308 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Error creating frame DMA pool\n");
4309 megasas_free_cmds(instance
);
4317 * dcmd_timeout_ocr_possible - Check if OCR is possible based on Driver/FW state.
4318 * @instance: Adapter soft state
4320 * Return 0 for only Fusion adapter, if driver load/unload is not in progress
4321 * or FW is not under OCR.
4324 dcmd_timeout_ocr_possible(struct megasas_instance
*instance
) {
4326 if (instance
->adapter_type
== MFI_SERIES
)
4327 return KILL_ADAPTER
;
4328 else if (instance
->unload
||
4329 test_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
))
4330 return IGNORE_TIMEOUT
;
4332 return INITIATE_OCR
;
4336 megasas_get_pd_info(struct megasas_instance
*instance
, struct scsi_device
*sdev
)
4339 struct megasas_cmd
*cmd
;
4340 struct megasas_dcmd_frame
*dcmd
;
4342 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
4345 device_id
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) + sdev
->id
;
4346 cmd
= megasas_get_cmd(instance
);
4349 dev_err(&instance
->pdev
->dev
, "Failed to get cmd %s\n", __func__
);
4353 dcmd
= &cmd
->frame
->dcmd
;
4355 memset(instance
->pd_info
, 0, sizeof(*instance
->pd_info
));
4356 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4358 dcmd
->mbox
.s
[0] = cpu_to_le16(device_id
);
4359 dcmd
->cmd
= MFI_CMD_DCMD
;
4360 dcmd
->cmd_status
= 0xFF;
4361 dcmd
->sge_count
= 1;
4362 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4365 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_PD_INFO
));
4366 dcmd
->opcode
= cpu_to_le32(MR_DCMD_PD_GET_INFO
);
4368 megasas_set_dma_settings(instance
, dcmd
, instance
->pd_info_h
,
4369 sizeof(struct MR_PD_INFO
));
4371 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4372 !instance
->mask_interrupts
)
4373 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
4375 ret
= megasas_issue_polled(instance
, cmd
);
4379 mr_device_priv_data
= sdev
->hostdata
;
4380 le16_to_cpus((u16
*)&instance
->pd_info
->state
.ddf
.pdType
);
4381 mr_device_priv_data
->interface_type
=
4382 instance
->pd_info
->state
.ddf
.pdType
.intf
;
4387 switch (dcmd_timeout_ocr_possible(instance
)) {
4389 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4390 megasas_reset_fusion(instance
->host
,
4391 MFI_IO_TIMEOUT_OCR
);
4394 megaraid_sas_kill_hba(instance
);
4396 case IGNORE_TIMEOUT
:
4397 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4398 __func__
, __LINE__
);
4405 if (ret
!= DCMD_TIMEOUT
)
4406 megasas_return_cmd(instance
, cmd
);
4411 * megasas_get_pd_list_info - Returns FW's pd_list structure
4412 * @instance: Adapter soft state
4413 * @pd_list: pd_list structure
4415 * Issues an internal command (DCMD) to get the FW's controller PD
4416 * list structure. This information is mainly used to find out SYSTEM
4417 * supported by the FW.
4420 megasas_get_pd_list(struct megasas_instance
*instance
)
4422 int ret
= 0, pd_index
= 0;
4423 struct megasas_cmd
*cmd
;
4424 struct megasas_dcmd_frame
*dcmd
;
4425 struct MR_PD_LIST
*ci
;
4426 struct MR_PD_ADDRESS
*pd_addr
;
4427 dma_addr_t ci_h
= 0;
4429 if (instance
->pd_list_not_supported
) {
4430 dev_info(&instance
->pdev
->dev
, "MR_DCMD_PD_LIST_QUERY "
4431 "not supported by firmware\n");
4435 ci
= instance
->pd_list_buf
;
4436 ci_h
= instance
->pd_list_buf_h
;
4438 cmd
= megasas_get_cmd(instance
);
4441 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "(get_pd_list): Failed to get cmd\n");
4445 dcmd
= &cmd
->frame
->dcmd
;
4447 memset(ci
, 0, sizeof(*ci
));
4448 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4450 dcmd
->mbox
.b
[0] = MR_PD_QUERY_TYPE_EXPOSED_TO_HOST
;
4451 dcmd
->mbox
.b
[1] = 0;
4452 dcmd
->cmd
= MFI_CMD_DCMD
;
4453 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4454 dcmd
->sge_count
= 1;
4455 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4458 dcmd
->data_xfer_len
= cpu_to_le32(MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
));
4459 dcmd
->opcode
= cpu_to_le32(MR_DCMD_PD_LIST_QUERY
);
4461 megasas_set_dma_settings(instance
, dcmd
, instance
->pd_list_buf_h
,
4462 (MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
)));
4464 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4465 !instance
->mask_interrupts
)
4466 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
4467 MFI_IO_TIMEOUT_SECS
);
4469 ret
= megasas_issue_polled(instance
, cmd
);
4473 dev_info(&instance
->pdev
->dev
, "MR_DCMD_PD_LIST_QUERY "
4474 "failed/not supported by firmware\n");
4476 if (instance
->adapter_type
!= MFI_SERIES
)
4477 megaraid_sas_kill_hba(instance
);
4479 instance
->pd_list_not_supported
= 1;
4483 switch (dcmd_timeout_ocr_possible(instance
)) {
4485 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4487 * DCMD failed from AEN path.
4488 * AEN path already hold reset_mutex to avoid PCI access
4489 * while OCR is in progress.
4491 mutex_unlock(&instance
->reset_mutex
);
4492 megasas_reset_fusion(instance
->host
,
4493 MFI_IO_TIMEOUT_OCR
);
4494 mutex_lock(&instance
->reset_mutex
);
4497 megaraid_sas_kill_hba(instance
);
4499 case IGNORE_TIMEOUT
:
4500 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d \n",
4501 __func__
, __LINE__
);
4509 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4510 dev_info(&instance
->pdev
->dev
, "%s, sysPD count: 0x%x\n",
4511 __func__
, le32_to_cpu(ci
->count
));
4513 if ((le32_to_cpu(ci
->count
) >
4514 (MEGASAS_MAX_PD_CHANNELS
* MEGASAS_MAX_DEV_PER_CHANNEL
)))
4517 memset(instance
->local_pd_list
, 0,
4518 MEGASAS_MAX_PD
* sizeof(struct megasas_pd_list
));
4520 for (pd_index
= 0; pd_index
< le32_to_cpu(ci
->count
); pd_index
++) {
4521 instance
->local_pd_list
[le16_to_cpu(pd_addr
->deviceId
)].tid
=
4522 le16_to_cpu(pd_addr
->deviceId
);
4523 instance
->local_pd_list
[le16_to_cpu(pd_addr
->deviceId
)].driveType
=
4524 pd_addr
->scsiDevType
;
4525 instance
->local_pd_list
[le16_to_cpu(pd_addr
->deviceId
)].driveState
=
4527 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4528 dev_info(&instance
->pdev
->dev
,
4529 "PD%d: targetID: 0x%03x deviceType:0x%x\n",
4530 pd_index
, le16_to_cpu(pd_addr
->deviceId
),
4531 pd_addr
->scsiDevType
);
4535 memcpy(instance
->pd_list
, instance
->local_pd_list
,
4536 sizeof(instance
->pd_list
));
4541 if (ret
!= DCMD_TIMEOUT
)
4542 megasas_return_cmd(instance
, cmd
);
4548 * megasas_get_ld_list_info - Returns FW's ld_list structure
4549 * @instance: Adapter soft state
4550 * @ld_list: ld_list structure
4552 * Issues an internal command (DCMD) to get the FW's controller PD
4553 * list structure. This information is mainly used to find out SYSTEM
4554 * supported by the FW.
4557 megasas_get_ld_list(struct megasas_instance
*instance
)
4559 int ret
= 0, ld_index
= 0, ids
= 0;
4560 struct megasas_cmd
*cmd
;
4561 struct megasas_dcmd_frame
*dcmd
;
4562 struct MR_LD_LIST
*ci
;
4563 dma_addr_t ci_h
= 0;
4566 ci
= instance
->ld_list_buf
;
4567 ci_h
= instance
->ld_list_buf_h
;
4569 cmd
= megasas_get_cmd(instance
);
4572 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "megasas_get_ld_list: Failed to get cmd\n");
4576 dcmd
= &cmd
->frame
->dcmd
;
4578 memset(ci
, 0, sizeof(*ci
));
4579 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4581 if (instance
->supportmax256vd
)
4582 dcmd
->mbox
.b
[0] = 1;
4583 dcmd
->cmd
= MFI_CMD_DCMD
;
4584 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4585 dcmd
->sge_count
= 1;
4586 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4588 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_LD_LIST
));
4589 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_GET_LIST
);
4592 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
4593 sizeof(struct MR_LD_LIST
));
4595 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4596 !instance
->mask_interrupts
)
4597 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
4598 MFI_IO_TIMEOUT_SECS
);
4600 ret
= megasas_issue_polled(instance
, cmd
);
4602 ld_count
= le32_to_cpu(ci
->ldCount
);
4606 megaraid_sas_kill_hba(instance
);
4610 switch (dcmd_timeout_ocr_possible(instance
)) {
4612 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4614 * DCMD failed from AEN path.
4615 * AEN path already hold reset_mutex to avoid PCI access
4616 * while OCR is in progress.
4618 mutex_unlock(&instance
->reset_mutex
);
4619 megasas_reset_fusion(instance
->host
,
4620 MFI_IO_TIMEOUT_OCR
);
4621 mutex_lock(&instance
->reset_mutex
);
4624 megaraid_sas_kill_hba(instance
);
4626 case IGNORE_TIMEOUT
:
4627 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4628 __func__
, __LINE__
);
4635 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4636 dev_info(&instance
->pdev
->dev
, "%s, LD count: 0x%x\n",
4637 __func__
, ld_count
);
4639 if (ld_count
> instance
->fw_supported_vd_count
)
4642 memset(instance
->ld_ids
, 0xff, MAX_LOGICAL_DRIVES_EXT
);
4644 for (ld_index
= 0; ld_index
< ld_count
; ld_index
++) {
4645 if (ci
->ldList
[ld_index
].state
!= 0) {
4646 ids
= ci
->ldList
[ld_index
].ref
.targetId
;
4647 instance
->ld_ids
[ids
] = ci
->ldList
[ld_index
].ref
.targetId
;
4648 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4649 dev_info(&instance
->pdev
->dev
,
4650 "LD%d: targetID: 0x%03x\n",
4658 if (ret
!= DCMD_TIMEOUT
)
4659 megasas_return_cmd(instance
, cmd
);
4665 * megasas_ld_list_query - Returns FW's ld_list structure
4666 * @instance: Adapter soft state
4667 * @ld_list: ld_list structure
4669 * Issues an internal command (DCMD) to get the FW's controller PD
4670 * list structure. This information is mainly used to find out SYSTEM
4671 * supported by the FW.
4674 megasas_ld_list_query(struct megasas_instance
*instance
, u8 query_type
)
4676 int ret
= 0, ld_index
= 0, ids
= 0;
4677 struct megasas_cmd
*cmd
;
4678 struct megasas_dcmd_frame
*dcmd
;
4679 struct MR_LD_TARGETID_LIST
*ci
;
4680 dma_addr_t ci_h
= 0;
4683 ci
= instance
->ld_targetid_list_buf
;
4684 ci_h
= instance
->ld_targetid_list_buf_h
;
4686 cmd
= megasas_get_cmd(instance
);
4689 dev_warn(&instance
->pdev
->dev
,
4690 "megasas_ld_list_query: Failed to get cmd\n");
4694 dcmd
= &cmd
->frame
->dcmd
;
4696 memset(ci
, 0, sizeof(*ci
));
4697 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4699 dcmd
->mbox
.b
[0] = query_type
;
4700 if (instance
->supportmax256vd
)
4701 dcmd
->mbox
.b
[2] = 1;
4703 dcmd
->cmd
= MFI_CMD_DCMD
;
4704 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4705 dcmd
->sge_count
= 1;
4706 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4708 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_LD_TARGETID_LIST
));
4709 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_LIST_QUERY
);
4712 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
4713 sizeof(struct MR_LD_TARGETID_LIST
));
4715 if ((instance
->adapter_type
!= MFI_SERIES
) &&
4716 !instance
->mask_interrupts
)
4717 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
4719 ret
= megasas_issue_polled(instance
, cmd
);
4723 dev_info(&instance
->pdev
->dev
,
4724 "DCMD not supported by firmware - %s %d\n",
4725 __func__
, __LINE__
);
4726 ret
= megasas_get_ld_list(instance
);
4729 switch (dcmd_timeout_ocr_possible(instance
)) {
4731 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4733 * DCMD failed from AEN path.
4734 * AEN path already hold reset_mutex to avoid PCI access
4735 * while OCR is in progress.
4737 mutex_unlock(&instance
->reset_mutex
);
4738 megasas_reset_fusion(instance
->host
,
4739 MFI_IO_TIMEOUT_OCR
);
4740 mutex_lock(&instance
->reset_mutex
);
4743 megaraid_sas_kill_hba(instance
);
4745 case IGNORE_TIMEOUT
:
4746 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4747 __func__
, __LINE__
);
4753 tgtid_count
= le32_to_cpu(ci
->count
);
4755 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4756 dev_info(&instance
->pdev
->dev
, "%s, LD count: 0x%x\n",
4757 __func__
, tgtid_count
);
4759 if ((tgtid_count
> (instance
->fw_supported_vd_count
)))
4762 memset(instance
->ld_ids
, 0xff, MEGASAS_MAX_LD_IDS
);
4763 for (ld_index
= 0; ld_index
< tgtid_count
; ld_index
++) {
4764 ids
= ci
->targetId
[ld_index
];
4765 instance
->ld_ids
[ids
] = ci
->targetId
[ld_index
];
4766 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4767 dev_info(&instance
->pdev
->dev
, "LD%d: targetID: 0x%03x\n",
4768 ld_index
, ci
->targetId
[ld_index
]);
4774 if (ret
!= DCMD_TIMEOUT
)
4775 megasas_return_cmd(instance
, cmd
);
4781 * dcmd.opcode - MR_DCMD_CTRL_DEVICE_LIST_GET
4782 * dcmd.mbox - reserved
4783 * dcmd.sge IN - ptr to return MR_HOST_DEVICE_LIST structure
4784 * Desc: This DCMD will return the combined device list
4785 * Status: MFI_STAT_OK - List returned successfully
4786 * MFI_STAT_INVALID_CMD - Firmware support for the feature has been
4788 * @instance: Adapter soft state
4789 * @is_probe: Driver probe check
4790 * Return: 0 if DCMD succeeded
4791 * non-zero if failed
4794 megasas_host_device_list_query(struct megasas_instance
*instance
,
4797 int ret
, i
, target_id
;
4798 struct megasas_cmd
*cmd
;
4799 struct megasas_dcmd_frame
*dcmd
;
4800 struct MR_HOST_DEVICE_LIST
*ci
;
4804 ci
= instance
->host_device_list_buf
;
4805 ci_h
= instance
->host_device_list_buf_h
;
4807 cmd
= megasas_get_cmd(instance
);
4810 dev_warn(&instance
->pdev
->dev
,
4811 "%s: failed to get cmd\n",
4816 dcmd
= &cmd
->frame
->dcmd
;
4818 memset(ci
, 0, sizeof(*ci
));
4819 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
4821 dcmd
->mbox
.b
[0] = is_probe
? 0 : 1;
4822 dcmd
->cmd
= MFI_CMD_DCMD
;
4823 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
4824 dcmd
->sge_count
= 1;
4825 dcmd
->flags
= MFI_FRAME_DIR_READ
;
4828 dcmd
->data_xfer_len
= cpu_to_le32(HOST_DEVICE_LIST_SZ
);
4829 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_DEVICE_LIST_GET
);
4831 megasas_set_dma_settings(instance
, dcmd
, ci_h
, HOST_DEVICE_LIST_SZ
);
4833 if (!instance
->mask_interrupts
) {
4834 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
4835 MFI_IO_TIMEOUT_SECS
);
4837 ret
= megasas_issue_polled(instance
, cmd
);
4838 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4843 /* Fill the internal pd_list and ld_ids array based on
4844 * targetIds returned by FW
4846 count
= le32_to_cpu(ci
->count
);
4848 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4849 dev_info(&instance
->pdev
->dev
, "%s, Device count: 0x%x\n",
4852 memset(instance
->local_pd_list
, 0,
4853 MEGASAS_MAX_PD
* sizeof(struct megasas_pd_list
));
4854 memset(instance
->ld_ids
, 0xff, MAX_LOGICAL_DRIVES_EXT
);
4855 for (i
= 0; i
< count
; i
++) {
4856 target_id
= le16_to_cpu(ci
->host_device_list
[i
].target_id
);
4857 if (ci
->host_device_list
[i
].flags
.u
.bits
.is_sys_pd
) {
4858 instance
->local_pd_list
[target_id
].tid
= target_id
;
4859 instance
->local_pd_list
[target_id
].driveType
=
4860 ci
->host_device_list
[i
].scsi_type
;
4861 instance
->local_pd_list
[target_id
].driveState
=
4863 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4864 dev_info(&instance
->pdev
->dev
,
4865 "Device %d: PD targetID: 0x%03x deviceType:0x%x\n",
4866 i
, target_id
, ci
->host_device_list
[i
].scsi_type
);
4868 instance
->ld_ids
[target_id
] = target_id
;
4869 if (megasas_dbg_lvl
& LD_PD_DEBUG
)
4870 dev_info(&instance
->pdev
->dev
,
4871 "Device %d: LD targetID: 0x%03x\n",
4876 memcpy(instance
->pd_list
, instance
->local_pd_list
,
4877 sizeof(instance
->pd_list
));
4881 switch (dcmd_timeout_ocr_possible(instance
)) {
4883 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4884 megasas_reset_fusion(instance
->host
,
4885 MFI_IO_TIMEOUT_OCR
);
4888 megaraid_sas_kill_hba(instance
);
4890 case IGNORE_TIMEOUT
:
4891 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
4892 __func__
, __LINE__
);
4897 dev_err(&instance
->pdev
->dev
,
4898 "%s: MR_DCMD_CTRL_DEVICE_LIST_GET failed\n",
4903 if (ret
!= DCMD_TIMEOUT
)
4904 megasas_return_cmd(instance
, cmd
);
4910 * megasas_update_ext_vd_details : Update details w.r.t Extended VD
4911 * instance : Controller's instance
4913 static void megasas_update_ext_vd_details(struct megasas_instance
*instance
)
4915 struct fusion_context
*fusion
;
4916 u32 ventura_map_sz
= 0;
4918 fusion
= instance
->ctrl_context
;
4919 /* For MFI based controllers return dummy success */
4923 instance
->supportmax256vd
=
4924 instance
->ctrl_info_buf
->adapterOperations3
.supportMaxExtLDs
;
4925 /* Below is additional check to address future FW enhancement */
4926 if (instance
->ctrl_info_buf
->max_lds
> 64)
4927 instance
->supportmax256vd
= 1;
4929 instance
->drv_supported_vd_count
= MEGASAS_MAX_LD_CHANNELS
4930 * MEGASAS_MAX_DEV_PER_CHANNEL
;
4931 instance
->drv_supported_pd_count
= MEGASAS_MAX_PD_CHANNELS
4932 * MEGASAS_MAX_DEV_PER_CHANNEL
;
4933 if (instance
->supportmax256vd
) {
4934 instance
->fw_supported_vd_count
= MAX_LOGICAL_DRIVES_EXT
;
4935 instance
->fw_supported_pd_count
= MAX_PHYSICAL_DEVICES
;
4937 instance
->fw_supported_vd_count
= MAX_LOGICAL_DRIVES
;
4938 instance
->fw_supported_pd_count
= MAX_PHYSICAL_DEVICES
;
4941 dev_info(&instance
->pdev
->dev
,
4942 "FW provided supportMaxExtLDs: %d\tmax_lds: %d\n",
4943 instance
->ctrl_info_buf
->adapterOperations3
.supportMaxExtLDs
? 1 : 0,
4944 instance
->ctrl_info_buf
->max_lds
);
4946 if (instance
->max_raid_mapsize
) {
4947 ventura_map_sz
= instance
->max_raid_mapsize
*
4948 MR_MIN_MAP_SIZE
; /* 64k */
4949 fusion
->current_map_sz
= ventura_map_sz
;
4950 fusion
->max_map_sz
= ventura_map_sz
;
4952 fusion
->old_map_sz
= sizeof(struct MR_FW_RAID_MAP
) +
4953 (sizeof(struct MR_LD_SPAN_MAP
) *
4954 (instance
->fw_supported_vd_count
- 1));
4955 fusion
->new_map_sz
= sizeof(struct MR_FW_RAID_MAP_EXT
);
4957 fusion
->max_map_sz
=
4958 max(fusion
->old_map_sz
, fusion
->new_map_sz
);
4960 if (instance
->supportmax256vd
)
4961 fusion
->current_map_sz
= fusion
->new_map_sz
;
4963 fusion
->current_map_sz
= fusion
->old_map_sz
;
4965 /* irrespective of FW raid maps, driver raid map is constant */
4966 fusion
->drv_map_sz
= sizeof(struct MR_DRV_RAID_MAP_ALL
);
4970 * dcmd.opcode - MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES
4971 * dcmd.hdr.length - number of bytes to read
4972 * dcmd.sge - Ptr to MR_SNAPDUMP_PROPERTIES
4973 * Desc: Fill in snapdump properties
4974 * Status: MFI_STAT_OK- Command successful
4976 void megasas_get_snapdump_properties(struct megasas_instance
*instance
)
4979 struct megasas_cmd
*cmd
;
4980 struct megasas_dcmd_frame
*dcmd
;
4981 struct MR_SNAPDUMP_PROPERTIES
*ci
;
4982 dma_addr_t ci_h
= 0;
4984 ci
= instance
->snapdump_prop
;
4985 ci_h
= instance
->snapdump_prop_h
;
4990 cmd
= megasas_get_cmd(instance
);
4993 dev_dbg(&instance
->pdev
->dev
, "Failed to get a free cmd\n");
4997 dcmd
= &cmd
->frame
->dcmd
;
4999 memset(ci
, 0, sizeof(*ci
));
5000 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
5002 dcmd
->cmd
= MFI_CMD_DCMD
;
5003 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
5004 dcmd
->sge_count
= 1;
5005 dcmd
->flags
= MFI_FRAME_DIR_READ
;
5008 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct MR_SNAPDUMP_PROPERTIES
));
5009 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_SNAPDUMP_GET_PROPERTIES
);
5011 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
5012 sizeof(struct MR_SNAPDUMP_PROPERTIES
));
5014 if (!instance
->mask_interrupts
) {
5015 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
5016 MFI_IO_TIMEOUT_SECS
);
5018 ret
= megasas_issue_polled(instance
, cmd
);
5019 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
5024 instance
->snapdump_wait_time
=
5025 min_t(u8
, ci
->trigger_min_num_sec_before_ocr
,
5026 MEGASAS_MAX_SNAP_DUMP_WAIT_TIME
);
5030 switch (dcmd_timeout_ocr_possible(instance
)) {
5032 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
5033 megasas_reset_fusion(instance
->host
,
5034 MFI_IO_TIMEOUT_OCR
);
5037 megaraid_sas_kill_hba(instance
);
5039 case IGNORE_TIMEOUT
:
5040 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
5041 __func__
, __LINE__
);
5046 if (ret
!= DCMD_TIMEOUT
)
5047 megasas_return_cmd(instance
, cmd
);
5051 * megasas_get_controller_info - Returns FW's controller structure
5052 * @instance: Adapter soft state
5054 * Issues an internal command (DCMD) to get the FW's controller structure.
5055 * This information is mainly used to find out the maximum IO transfer per
5056 * command supported by the FW.
5059 megasas_get_ctrl_info(struct megasas_instance
*instance
)
5062 struct megasas_cmd
*cmd
;
5063 struct megasas_dcmd_frame
*dcmd
;
5064 struct megasas_ctrl_info
*ci
;
5065 dma_addr_t ci_h
= 0;
5067 ci
= instance
->ctrl_info_buf
;
5068 ci_h
= instance
->ctrl_info_buf_h
;
5070 cmd
= megasas_get_cmd(instance
);
5073 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get a free cmd\n");
5077 dcmd
= &cmd
->frame
->dcmd
;
5079 memset(ci
, 0, sizeof(*ci
));
5080 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
5082 dcmd
->cmd
= MFI_CMD_DCMD
;
5083 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
5084 dcmd
->sge_count
= 1;
5085 dcmd
->flags
= MFI_FRAME_DIR_READ
;
5088 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_ctrl_info
));
5089 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_GET_INFO
);
5090 dcmd
->mbox
.b
[0] = 1;
5092 megasas_set_dma_settings(instance
, dcmd
, ci_h
,
5093 sizeof(struct megasas_ctrl_info
));
5095 if ((instance
->adapter_type
!= MFI_SERIES
) &&
5096 !instance
->mask_interrupts
) {
5097 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
5099 ret
= megasas_issue_polled(instance
, cmd
);
5100 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
5105 /* Save required controller information in
5106 * CPU endianness format.
5108 le32_to_cpus((u32
*)&ci
->properties
.OnOffProperties
);
5109 le16_to_cpus((u16
*)&ci
->properties
.on_off_properties2
);
5110 le32_to_cpus((u32
*)&ci
->adapterOperations2
);
5111 le32_to_cpus((u32
*)&ci
->adapterOperations3
);
5112 le16_to_cpus((u16
*)&ci
->adapter_operations4
);
5114 /* Update the latest Ext VD info.
5115 * From Init path, store current firmware details.
5116 * From OCR path, detect any firmware properties changes.
5117 * in case of Firmware upgrade without system reboot.
5119 megasas_update_ext_vd_details(instance
);
5120 instance
->use_seqnum_jbod_fp
=
5121 ci
->adapterOperations3
.useSeqNumJbodFP
;
5122 instance
->support_morethan256jbod
=
5123 ci
->adapter_operations4
.support_pd_map_target_id
;
5124 instance
->support_nvme_passthru
=
5125 ci
->adapter_operations4
.support_nvme_passthru
;
5126 instance
->task_abort_tmo
= ci
->TaskAbortTO
;
5127 instance
->max_reset_tmo
= ci
->MaxResetTO
;
5129 /*Check whether controller is iMR or MR */
5130 instance
->is_imr
= (ci
->memory_size
? 0 : 1);
5132 instance
->snapdump_wait_time
=
5133 (ci
->properties
.on_off_properties2
.enable_snap_dump
?
5134 MEGASAS_DEFAULT_SNAP_DUMP_WAIT_TIME
: 0);
5136 instance
->enable_fw_dev_list
=
5137 ci
->properties
.on_off_properties2
.enable_fw_dev_list
;
5139 dev_info(&instance
->pdev
->dev
,
5140 "controller type\t: %s(%dMB)\n",
5141 instance
->is_imr
? "iMR" : "MR",
5142 le16_to_cpu(ci
->memory_size
));
5144 instance
->disableOnlineCtrlReset
=
5145 ci
->properties
.OnOffProperties
.disableOnlineCtrlReset
;
5146 instance
->secure_jbod_support
=
5147 ci
->adapterOperations3
.supportSecurityonJBOD
;
5148 dev_info(&instance
->pdev
->dev
, "Online Controller Reset(OCR)\t: %s\n",
5149 instance
->disableOnlineCtrlReset
? "Disabled" : "Enabled");
5150 dev_info(&instance
->pdev
->dev
, "Secure JBOD support\t: %s\n",
5151 instance
->secure_jbod_support
? "Yes" : "No");
5152 dev_info(&instance
->pdev
->dev
, "NVMe passthru support\t: %s\n",
5153 instance
->support_nvme_passthru
? "Yes" : "No");
5154 dev_info(&instance
->pdev
->dev
,
5155 "FW provided TM TaskAbort/Reset timeout\t: %d secs/%d secs\n",
5156 instance
->task_abort_tmo
, instance
->max_reset_tmo
);
5161 switch (dcmd_timeout_ocr_possible(instance
)) {
5163 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
5164 megasas_reset_fusion(instance
->host
,
5165 MFI_IO_TIMEOUT_OCR
);
5168 megaraid_sas_kill_hba(instance
);
5170 case IGNORE_TIMEOUT
:
5171 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
5172 __func__
, __LINE__
);
5177 megaraid_sas_kill_hba(instance
);
5182 if (ret
!= DCMD_TIMEOUT
)
5183 megasas_return_cmd(instance
, cmd
);
5189 * megasas_set_crash_dump_params - Sends address of crash dump DMA buffer
5192 * @instance: Adapter soft state
5193 * @crash_buf_state - tell FW to turn ON/OFF crash dump feature
5194 MR_CRASH_BUF_TURN_OFF = 0
5195 MR_CRASH_BUF_TURN_ON = 1
5196 * @return 0 on success non-zero on failure.
5197 * Issues an internal command (DCMD) to set parameters for crash dump feature.
5198 * Driver will send address of crash dump DMA buffer and set mbox to tell FW
5199 * that driver supports crash dump feature. This DCMD will be sent only if
5200 * crash dump feature is supported by the FW.
5203 int megasas_set_crash_dump_params(struct megasas_instance
*instance
,
5207 struct megasas_cmd
*cmd
;
5208 struct megasas_dcmd_frame
*dcmd
;
5210 cmd
= megasas_get_cmd(instance
);
5213 dev_err(&instance
->pdev
->dev
, "Failed to get a free cmd\n");
5218 dcmd
= &cmd
->frame
->dcmd
;
5220 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
5221 dcmd
->mbox
.b
[0] = crash_buf_state
;
5222 dcmd
->cmd
= MFI_CMD_DCMD
;
5223 dcmd
->cmd_status
= MFI_STAT_INVALID_STATUS
;
5224 dcmd
->sge_count
= 1;
5225 dcmd
->flags
= MFI_FRAME_DIR_NONE
;
5228 dcmd
->data_xfer_len
= cpu_to_le32(CRASH_DMA_BUF_SIZE
);
5229 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_SET_CRASH_DUMP_PARAMS
);
5231 megasas_set_dma_settings(instance
, dcmd
, instance
->crash_dump_h
,
5232 CRASH_DMA_BUF_SIZE
);
5234 if ((instance
->adapter_type
!= MFI_SERIES
) &&
5235 !instance
->mask_interrupts
)
5236 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
5238 ret
= megasas_issue_polled(instance
, cmd
);
5240 if (ret
== DCMD_TIMEOUT
) {
5241 switch (dcmd_timeout_ocr_possible(instance
)) {
5243 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
5244 megasas_reset_fusion(instance
->host
,
5245 MFI_IO_TIMEOUT_OCR
);
5248 megaraid_sas_kill_hba(instance
);
5250 case IGNORE_TIMEOUT
:
5251 dev_info(&instance
->pdev
->dev
, "Ignore DCMD timeout: %s %d\n",
5252 __func__
, __LINE__
);
5256 megasas_return_cmd(instance
, cmd
);
5262 * megasas_issue_init_mfi - Initializes the FW
5263 * @instance: Adapter soft state
5265 * Issues the INIT MFI cmd
5268 megasas_issue_init_mfi(struct megasas_instance
*instance
)
5271 struct megasas_cmd
*cmd
;
5272 struct megasas_init_frame
*init_frame
;
5273 struct megasas_init_queue_info
*initq_info
;
5274 dma_addr_t init_frame_h
;
5275 dma_addr_t initq_info_h
;
5278 * Prepare a init frame. Note the init frame points to queue info
5279 * structure. Each frame has SGL allocated after first 64 bytes. For
5280 * this frame - since we don't need any SGL - we use SGL's space as
5281 * queue info structure
5283 * We will not get a NULL command below. We just created the pool.
5285 cmd
= megasas_get_cmd(instance
);
5287 init_frame
= (struct megasas_init_frame
*)cmd
->frame
;
5288 initq_info
= (struct megasas_init_queue_info
*)
5289 ((unsigned long)init_frame
+ 64);
5291 init_frame_h
= cmd
->frame_phys_addr
;
5292 initq_info_h
= init_frame_h
+ 64;
5294 context
= init_frame
->context
;
5295 memset(init_frame
, 0, MEGAMFI_FRAME_SIZE
);
5296 memset(initq_info
, 0, sizeof(struct megasas_init_queue_info
));
5297 init_frame
->context
= context
;
5299 initq_info
->reply_queue_entries
= cpu_to_le32(instance
->max_fw_cmds
+ 1);
5300 initq_info
->reply_queue_start_phys_addr_lo
= cpu_to_le32(instance
->reply_queue_h
);
5302 initq_info
->producer_index_phys_addr_lo
= cpu_to_le32(instance
->producer_h
);
5303 initq_info
->consumer_index_phys_addr_lo
= cpu_to_le32(instance
->consumer_h
);
5305 init_frame
->cmd
= MFI_CMD_INIT
;
5306 init_frame
->cmd_status
= MFI_STAT_INVALID_STATUS
;
5307 init_frame
->queue_info_new_phys_addr_lo
=
5308 cpu_to_le32(lower_32_bits(initq_info_h
));
5309 init_frame
->queue_info_new_phys_addr_hi
=
5310 cpu_to_le32(upper_32_bits(initq_info_h
));
5312 init_frame
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_init_queue_info
));
5315 * disable the intr before firing the init frame to FW
5317 instance
->instancet
->disable_intr(instance
);
5320 * Issue the init frame in polled mode
5323 if (megasas_issue_polled(instance
, cmd
)) {
5324 dev_err(&instance
->pdev
->dev
, "Failed to init firmware\n");
5325 megasas_return_cmd(instance
, cmd
);
5329 megasas_return_cmd(instance
, cmd
);
5338 megasas_init_adapter_mfi(struct megasas_instance
*instance
)
5344 * Get various operational parameters from status register
5346 instance
->max_fw_cmds
= instance
->instancet
->read_fw_status_reg(instance
) & 0x00FFFF;
5348 * Reduce the max supported cmds by 1. This is to ensure that the
5349 * reply_q_sz (1 more than the max cmd that driver may send)
5350 * does not exceed max cmds that the FW can support
5352 instance
->max_fw_cmds
= instance
->max_fw_cmds
-1;
5353 instance
->max_mfi_cmds
= instance
->max_fw_cmds
;
5354 instance
->max_num_sge
= (instance
->instancet
->read_fw_status_reg(instance
) & 0xFF0000) >>
5357 * For MFI skinny adapters, MEGASAS_SKINNY_INT_CMDS commands
5358 * are reserved for IOCTL + driver's internal DCMDs.
5360 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
5361 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0071SKINNY
)) {
5362 instance
->max_scsi_cmds
= (instance
->max_fw_cmds
-
5363 MEGASAS_SKINNY_INT_CMDS
);
5364 sema_init(&instance
->ioctl_sem
, MEGASAS_SKINNY_INT_CMDS
);
5366 instance
->max_scsi_cmds
= (instance
->max_fw_cmds
-
5368 sema_init(&instance
->ioctl_sem
, (MEGASAS_MFI_IOCTL_CMDS
));
5371 instance
->cur_can_queue
= instance
->max_scsi_cmds
;
5373 * Create a pool of commands
5375 if (megasas_alloc_cmds(instance
))
5376 goto fail_alloc_cmds
;
5379 * Allocate memory for reply queue. Length of reply queue should
5380 * be _one_ more than the maximum commands handled by the firmware.
5382 * Note: When FW completes commands, it places corresponding contex
5383 * values in this circular reply queue. This circular queue is a fairly
5384 * typical producer-consumer queue. FW is the producer (of completed
5385 * commands) and the driver is the consumer.
5387 context_sz
= sizeof(u32
);
5388 reply_q_sz
= context_sz
* (instance
->max_fw_cmds
+ 1);
5390 instance
->reply_queue
= dma_alloc_coherent(&instance
->pdev
->dev
,
5391 reply_q_sz
, &instance
->reply_queue_h
, GFP_KERNEL
);
5393 if (!instance
->reply_queue
) {
5394 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Out of DMA mem for reply queue\n");
5395 goto fail_reply_queue
;
5398 if (megasas_issue_init_mfi(instance
))
5401 if (megasas_get_ctrl_info(instance
)) {
5402 dev_err(&instance
->pdev
->dev
, "(%d): Could get controller info "
5403 "Fail from %s %d\n", instance
->unique_id
,
5404 __func__
, __LINE__
);
5408 instance
->fw_support_ieee
= 0;
5409 instance
->fw_support_ieee
=
5410 (instance
->instancet
->read_fw_status_reg(instance
) &
5413 dev_notice(&instance
->pdev
->dev
, "megasas_init_mfi: fw_support_ieee=%d",
5414 instance
->fw_support_ieee
);
5416 if (instance
->fw_support_ieee
)
5417 instance
->flag_ieee
= 1;
5423 dma_free_coherent(&instance
->pdev
->dev
, reply_q_sz
,
5424 instance
->reply_queue
, instance
->reply_queue_h
);
5426 megasas_free_cmds(instance
);
5433 void megasas_setup_irq_poll(struct megasas_instance
*instance
)
5435 struct megasas_irq_context
*irq_ctx
;
5438 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
5440 /* Initialize IRQ poll */
5441 for (i
= 0; i
< count
; i
++) {
5442 irq_ctx
= &instance
->irq_context
[i
];
5443 irq_ctx
->os_irq
= pci_irq_vector(instance
->pdev
, i
);
5444 irq_ctx
->irq_poll_scheduled
= false;
5445 irq_poll_init(&irq_ctx
->irqpoll
,
5446 instance
->threshold_reply_count
,
5452 * megasas_setup_irqs_ioapic - register legacy interrupts.
5453 * @instance: Adapter soft state
5455 * Do not enable interrupt, only setup ISRs.
5457 * Return 0 on success.
5460 megasas_setup_irqs_ioapic(struct megasas_instance
*instance
)
5462 struct pci_dev
*pdev
;
5464 pdev
= instance
->pdev
;
5465 instance
->irq_context
[0].instance
= instance
;
5466 instance
->irq_context
[0].MSIxIndex
= 0;
5467 if (request_irq(pci_irq_vector(pdev
, 0),
5468 instance
->instancet
->service_isr
, IRQF_SHARED
,
5469 "megasas", &instance
->irq_context
[0])) {
5470 dev_err(&instance
->pdev
->dev
,
5471 "Failed to register IRQ from %s %d\n",
5472 __func__
, __LINE__
);
5479 * megasas_setup_irqs_msix - register MSI-x interrupts.
5480 * @instance: Adapter soft state
5481 * @is_probe: Driver probe check
5483 * Do not enable interrupt, only setup ISRs.
5485 * Return 0 on success.
5488 megasas_setup_irqs_msix(struct megasas_instance
*instance
, u8 is_probe
)
5491 struct pci_dev
*pdev
;
5493 pdev
= instance
->pdev
;
5496 for (i
= 0; i
< instance
->msix_vectors
; i
++) {
5497 instance
->irq_context
[i
].instance
= instance
;
5498 instance
->irq_context
[i
].MSIxIndex
= i
;
5499 if (request_irq(pci_irq_vector(pdev
, i
),
5500 instance
->instancet
->service_isr
, 0, "megasas",
5501 &instance
->irq_context
[i
])) {
5502 dev_err(&instance
->pdev
->dev
,
5503 "Failed to register IRQ for vector %d.\n", i
);
5504 for (j
= 0; j
< i
; j
++)
5505 free_irq(pci_irq_vector(pdev
, j
),
5506 &instance
->irq_context
[j
]);
5507 /* Retry irq register for IO_APIC*/
5508 instance
->msix_vectors
= 0;
5509 instance
->msix_load_balance
= false;
5511 pci_free_irq_vectors(instance
->pdev
);
5512 return megasas_setup_irqs_ioapic(instance
);
5523 * megasas_destroy_irqs- unregister interrupts.
5524 * @instance: Adapter soft state
5528 megasas_destroy_irqs(struct megasas_instance
*instance
) {
5532 struct megasas_irq_context
*irq_ctx
;
5534 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
5535 if (instance
->adapter_type
!= MFI_SERIES
) {
5536 for (i
= 0; i
< count
; i
++) {
5537 irq_ctx
= &instance
->irq_context
[i
];
5538 irq_poll_disable(&irq_ctx
->irqpoll
);
5542 if (instance
->msix_vectors
)
5543 for (i
= 0; i
< instance
->msix_vectors
; i
++) {
5544 free_irq(pci_irq_vector(instance
->pdev
, i
),
5545 &instance
->irq_context
[i
]);
5548 free_irq(pci_irq_vector(instance
->pdev
, 0),
5549 &instance
->irq_context
[0]);
5553 * megasas_setup_jbod_map - setup jbod map for FP seq_number.
5554 * @instance: Adapter soft state
5555 * @is_probe: Driver probe check
5557 * Return 0 on success.
5560 megasas_setup_jbod_map(struct megasas_instance
*instance
)
5563 struct fusion_context
*fusion
= instance
->ctrl_context
;
5566 pd_seq_map_sz
= sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC
) +
5567 (sizeof(struct MR_PD_CFG_SEQ
) * (MAX_PHYSICAL_DEVICES
- 1));
5569 if (reset_devices
|| !fusion
||
5570 !instance
->ctrl_info_buf
->adapterOperations3
.useSeqNumJbodFP
) {
5571 dev_info(&instance
->pdev
->dev
,
5572 "Jbod map is not supported %s %d\n",
5573 __func__
, __LINE__
);
5574 instance
->use_seqnum_jbod_fp
= false;
5578 if (fusion
->pd_seq_sync
[0])
5581 for (i
= 0; i
< JBOD_MAPS_COUNT
; i
++) {
5582 fusion
->pd_seq_sync
[i
] = dma_alloc_coherent
5583 (&instance
->pdev
->dev
, pd_seq_map_sz
,
5584 &fusion
->pd_seq_phys
[i
], GFP_KERNEL
);
5585 if (!fusion
->pd_seq_sync
[i
]) {
5586 dev_err(&instance
->pdev
->dev
,
5587 "Failed to allocate memory from %s %d\n",
5588 __func__
, __LINE__
);
5590 dma_free_coherent(&instance
->pdev
->dev
,
5591 pd_seq_map_sz
, fusion
->pd_seq_sync
[0],
5592 fusion
->pd_seq_phys
[0]);
5593 fusion
->pd_seq_sync
[0] = NULL
;
5595 instance
->use_seqnum_jbod_fp
= false;
5601 if (!megasas_sync_pd_seq_num(instance
, false) &&
5602 !megasas_sync_pd_seq_num(instance
, true))
5603 instance
->use_seqnum_jbod_fp
= true;
5605 instance
->use_seqnum_jbod_fp
= false;
5608 static void megasas_setup_reply_map(struct megasas_instance
*instance
)
5610 const struct cpumask
*mask
;
5611 unsigned int queue
, cpu
;
5613 for (queue
= 0; queue
< instance
->msix_vectors
; queue
++) {
5614 mask
= pci_irq_get_affinity(instance
->pdev
, queue
);
5618 for_each_cpu(cpu
, mask
)
5619 instance
->reply_map
[cpu
] = queue
;
5624 for_each_possible_cpu(cpu
)
5625 instance
->reply_map
[cpu
] = cpu
% instance
->msix_vectors
;
5629 * megasas_get_device_list - Get the PD and LD device list from FW.
5630 * @instance: Adapter soft state
5631 * @return: Success or failure
5633 * Issue DCMDs to Firmware to get the PD and LD list.
5634 * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
5635 * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
5638 int megasas_get_device_list(struct megasas_instance
*instance
)
5640 memset(instance
->pd_list
, 0,
5641 (MEGASAS_MAX_PD
* sizeof(struct megasas_pd_list
)));
5642 memset(instance
->ld_ids
, 0xff, MEGASAS_MAX_LD_IDS
);
5644 if (instance
->enable_fw_dev_list
) {
5645 if (megasas_host_device_list_query(instance
, true))
5648 if (megasas_get_pd_list(instance
) < 0) {
5649 dev_err(&instance
->pdev
->dev
, "failed to get PD list\n");
5653 if (megasas_ld_list_query(instance
,
5654 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST
)) {
5655 dev_err(&instance
->pdev
->dev
, "failed to get LD list\n");
5663 * megasas_init_fw - Initializes the FW
5664 * @instance: Adapter soft state
5666 * This is the main function for initializing firmware
5669 static int megasas_init_fw(struct megasas_instance
*instance
)
5672 u32 max_sectors_2
, tmp_sectors
, msix_enable
;
5673 u32 scratch_pad_1
, scratch_pad_2
, scratch_pad_3
, status_reg
;
5674 resource_size_t base_addr
;
5675 void *base_addr_phys
;
5676 struct megasas_ctrl_info
*ctrl_info
= NULL
;
5677 unsigned long bar_list
;
5679 struct IOV_111
*iovPtr
;
5680 struct fusion_context
*fusion
;
5682 fusion
= instance
->ctrl_context
;
5684 /* Find first memory bar */
5685 bar_list
= pci_select_bars(instance
->pdev
, IORESOURCE_MEM
);
5686 instance
->bar
= find_first_bit(&bar_list
, BITS_PER_LONG
);
5687 if (pci_request_selected_regions(instance
->pdev
, 1<<instance
->bar
,
5689 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "IO memory region busy!\n");
5693 base_addr
= pci_resource_start(instance
->pdev
, instance
->bar
);
5694 instance
->reg_set
= ioremap_nocache(base_addr
, 8192);
5696 if (!instance
->reg_set
) {
5697 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to map IO mem\n");
5701 base_addr_phys
= &base_addr
;
5702 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
,
5703 "BAR:0x%lx BAR's base_addr(phys):%pa mapped virt_addr:0x%p\n",
5704 instance
->bar
, base_addr_phys
, instance
->reg_set
);
5706 if (instance
->adapter_type
!= MFI_SERIES
)
5707 instance
->instancet
= &megasas_instance_template_fusion
;
5709 switch (instance
->pdev
->device
) {
5710 case PCI_DEVICE_ID_LSI_SAS1078R
:
5711 case PCI_DEVICE_ID_LSI_SAS1078DE
:
5712 instance
->instancet
= &megasas_instance_template_ppc
;
5714 case PCI_DEVICE_ID_LSI_SAS1078GEN2
:
5715 case PCI_DEVICE_ID_LSI_SAS0079GEN2
:
5716 instance
->instancet
= &megasas_instance_template_gen2
;
5718 case PCI_DEVICE_ID_LSI_SAS0073SKINNY
:
5719 case PCI_DEVICE_ID_LSI_SAS0071SKINNY
:
5720 instance
->instancet
= &megasas_instance_template_skinny
;
5722 case PCI_DEVICE_ID_LSI_SAS1064R
:
5723 case PCI_DEVICE_ID_DELL_PERC5
:
5725 instance
->instancet
= &megasas_instance_template_xscale
;
5726 instance
->pd_list_not_supported
= 1;
5731 if (megasas_transition_to_ready(instance
, 0)) {
5732 dev_info(&instance
->pdev
->dev
,
5733 "Failed to transition controller to ready from %s!\n",
5735 if (instance
->adapter_type
!= MFI_SERIES
) {
5736 status_reg
= instance
->instancet
->read_fw_status_reg(
5738 if (status_reg
& MFI_RESET_ADAPTER
) {
5739 if (megasas_adp_reset_wait_for_ready
5740 (instance
, true, 0) == FAILED
)
5741 goto fail_ready_state
;
5743 goto fail_ready_state
;
5746 atomic_set(&instance
->fw_reset_no_pci_access
, 1);
5747 instance
->instancet
->adp_reset
5748 (instance
, instance
->reg_set
);
5749 atomic_set(&instance
->fw_reset_no_pci_access
, 0);
5751 /*waiting for about 30 second before retry*/
5754 if (megasas_transition_to_ready(instance
, 0))
5755 goto fail_ready_state
;
5758 dev_info(&instance
->pdev
->dev
,
5759 "FW restarted successfully from %s!\n",
5763 megasas_init_ctrl_params(instance
);
5765 if (megasas_set_dma_mask(instance
))
5766 goto fail_ready_state
;
5768 if (megasas_alloc_ctrl_mem(instance
))
5769 goto fail_alloc_dma_buf
;
5771 if (megasas_alloc_ctrl_dma_buffers(instance
))
5772 goto fail_alloc_dma_buf
;
5774 fusion
= instance
->ctrl_context
;
5776 if (instance
->adapter_type
>= VENTURA_SERIES
) {
5778 megasas_readl(instance
,
5779 &instance
->reg_set
->outbound_scratch_pad_2
);
5780 instance
->max_raid_mapsize
= ((scratch_pad_2
>>
5781 MR_MAX_RAID_MAP_SIZE_OFFSET_SHIFT
) &
5782 MR_MAX_RAID_MAP_SIZE_MASK
);
5785 /* Check if MSI-X is supported while in ready state */
5786 msix_enable
= (instance
->instancet
->read_fw_status_reg(instance
) &
5788 if (msix_enable
&& !msix_disable
) {
5789 int irq_flags
= PCI_IRQ_MSIX
;
5791 scratch_pad_1
= megasas_readl
5792 (instance
, &instance
->reg_set
->outbound_scratch_pad_1
);
5793 /* Check max MSI-X vectors */
5795 if (instance
->adapter_type
== THUNDERBOLT_SERIES
) {
5796 /* Thunderbolt Series*/
5797 instance
->msix_vectors
= (scratch_pad_1
5798 & MR_MAX_REPLY_QUEUES_OFFSET
) + 1;
5800 instance
->msix_vectors
= ((scratch_pad_1
5801 & MR_MAX_REPLY_QUEUES_EXT_OFFSET
)
5802 >> MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT
) + 1;
5805 * For Invader series, > 8 MSI-x vectors
5806 * supported by FW/HW implies combined
5807 * reply queue mode is enabled.
5808 * For Ventura series, > 16 MSI-x vectors
5809 * supported by FW/HW implies combined
5810 * reply queue mode is enabled.
5812 switch (instance
->adapter_type
) {
5813 case INVADER_SERIES
:
5814 if (instance
->msix_vectors
> 8)
5815 instance
->msix_combined
= true;
5818 case VENTURA_SERIES
:
5819 if (instance
->msix_vectors
> 16)
5820 instance
->msix_combined
= true;
5825 instance
->is_rdpq
= (scratch_pad_1
& MR_RDPQ_MODE_OFFSET
) ?
5828 if (!instance
->msix_combined
) {
5829 instance
->msix_load_balance
= true;
5830 instance
->smp_affinity_enable
= false;
5833 /* Save 1-15 reply post index address to local memory
5834 * Index 0 is already saved from reg offset
5835 * MPI2_REPLY_POST_HOST_INDEX_OFFSET
5837 for (loop
= 1; loop
< MR_MAX_MSIX_REG_ARRAY
; loop
++) {
5838 instance
->reply_post_host_index_addr
[loop
] =
5840 ((u8 __iomem
*)instance
->reg_set
+
5841 MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET
5846 dev_info(&instance
->pdev
->dev
,
5847 "firmware supports msix\t: (%d)",
5848 instance
->msix_vectors
);
5850 instance
->msix_vectors
= min(msix_vectors
,
5851 instance
->msix_vectors
);
5852 } else /* MFI adapters */
5853 instance
->msix_vectors
= 1;
5855 /* Don't bother allocating more MSI-X vectors than cpus */
5856 instance
->msix_vectors
= min(instance
->msix_vectors
,
5857 (unsigned int)num_online_cpus());
5858 if (instance
->smp_affinity_enable
)
5859 irq_flags
|= PCI_IRQ_AFFINITY
;
5860 i
= pci_alloc_irq_vectors(instance
->pdev
, 1,
5861 instance
->msix_vectors
, irq_flags
);
5863 instance
->msix_vectors
= i
;
5865 instance
->msix_vectors
= 0;
5866 instance
->msix_load_balance
= false;
5870 * MSI-X host index 0 is common for all adapter.
5871 * It is used for all MPT based Adapters.
5873 if (instance
->msix_combined
) {
5874 instance
->reply_post_host_index_addr
[0] =
5875 (u32
*)((u8
*)instance
->reg_set
+
5876 MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET
);
5878 instance
->reply_post_host_index_addr
[0] =
5879 (u32
*)((u8
*)instance
->reg_set
+
5880 MPI2_REPLY_POST_HOST_INDEX_OFFSET
);
5883 if (!instance
->msix_vectors
) {
5884 i
= pci_alloc_irq_vectors(instance
->pdev
, 1, 1, PCI_IRQ_LEGACY
);
5886 goto fail_init_adapter
;
5889 megasas_setup_reply_map(instance
);
5891 dev_info(&instance
->pdev
->dev
,
5892 "current msix/online cpus\t: (%d/%d)\n",
5893 instance
->msix_vectors
, (unsigned int)num_online_cpus());
5894 dev_info(&instance
->pdev
->dev
,
5895 "RDPQ mode\t: (%s)\n", instance
->is_rdpq
? "enabled" : "disabled");
5897 tasklet_init(&instance
->isr_tasklet
, instance
->instancet
->tasklet
,
5898 (unsigned long)instance
);
5901 * Below are default value for legacy Firmware.
5902 * non-fusion based controllers
5904 instance
->fw_supported_vd_count
= MAX_LOGICAL_DRIVES
;
5905 instance
->fw_supported_pd_count
= MAX_PHYSICAL_DEVICES
;
5906 /* Get operational params, sge flags, send init cmd to controller */
5907 if (instance
->instancet
->init_adapter(instance
))
5908 goto fail_init_adapter
;
5910 if (instance
->adapter_type
>= VENTURA_SERIES
) {
5912 megasas_readl(instance
,
5913 &instance
->reg_set
->outbound_scratch_pad_3
);
5914 if ((scratch_pad_3
& MR_NVME_PAGE_SIZE_MASK
) >=
5915 MR_DEFAULT_NVME_PAGE_SHIFT
)
5916 instance
->nvme_page_size
=
5917 (1 << (scratch_pad_3
& MR_NVME_PAGE_SIZE_MASK
));
5919 dev_info(&instance
->pdev
->dev
,
5920 "NVME page size\t: (%d)\n", instance
->nvme_page_size
);
5923 if (instance
->msix_vectors
?
5924 megasas_setup_irqs_msix(instance
, 1) :
5925 megasas_setup_irqs_ioapic(instance
))
5926 goto fail_init_adapter
;
5928 if (instance
->adapter_type
!= MFI_SERIES
)
5929 megasas_setup_irq_poll(instance
);
5931 instance
->instancet
->enable_intr(instance
);
5933 dev_info(&instance
->pdev
->dev
, "INIT adapter done\n");
5935 megasas_setup_jbod_map(instance
);
5937 if (megasas_get_device_list(instance
) != SUCCESS
) {
5938 dev_err(&instance
->pdev
->dev
,
5939 "%s: megasas_get_device_list failed\n",
5941 goto fail_get_ld_pd_list
;
5944 /* stream detection initialization */
5945 if (instance
->adapter_type
>= VENTURA_SERIES
) {
5946 fusion
->stream_detect_by_ld
=
5947 kcalloc(MAX_LOGICAL_DRIVES_EXT
,
5948 sizeof(struct LD_STREAM_DETECT
*),
5950 if (!fusion
->stream_detect_by_ld
) {
5951 dev_err(&instance
->pdev
->dev
,
5952 "unable to allocate stream detection for pool of LDs\n");
5953 goto fail_get_ld_pd_list
;
5955 for (i
= 0; i
< MAX_LOGICAL_DRIVES_EXT
; ++i
) {
5956 fusion
->stream_detect_by_ld
[i
] =
5957 kzalloc(sizeof(struct LD_STREAM_DETECT
),
5959 if (!fusion
->stream_detect_by_ld
[i
]) {
5960 dev_err(&instance
->pdev
->dev
,
5961 "unable to allocate stream detect by LD\n ");
5962 for (j
= 0; j
< i
; ++j
)
5963 kfree(fusion
->stream_detect_by_ld
[j
]);
5964 kfree(fusion
->stream_detect_by_ld
);
5965 fusion
->stream_detect_by_ld
= NULL
;
5966 goto fail_get_ld_pd_list
;
5968 fusion
->stream_detect_by_ld
[i
]->mru_bit_map
5974 * Compute the max allowed sectors per IO: The controller info has two
5975 * limits on max sectors. Driver should use the minimum of these two.
5977 * 1 << stripe_sz_ops.min = max sectors per strip
5979 * Note that older firmwares ( < FW ver 30) didn't report information
5980 * to calculate max_sectors_1. So the number ended up as zero always.
5983 ctrl_info
= instance
->ctrl_info_buf
;
5985 max_sectors_1
= (1 << ctrl_info
->stripe_sz_ops
.min
) *
5986 le16_to_cpu(ctrl_info
->max_strips_per_io
);
5987 max_sectors_2
= le32_to_cpu(ctrl_info
->max_request_size
);
5989 tmp_sectors
= min_t(u32
, max_sectors_1
, max_sectors_2
);
5991 instance
->peerIsPresent
= ctrl_info
->cluster
.peerIsPresent
;
5992 instance
->passive
= ctrl_info
->cluster
.passive
;
5993 memcpy(instance
->clusterId
, ctrl_info
->clusterId
, sizeof(instance
->clusterId
));
5994 instance
->UnevenSpanSupport
=
5995 ctrl_info
->adapterOperations2
.supportUnevenSpans
;
5996 if (instance
->UnevenSpanSupport
) {
5997 struct fusion_context
*fusion
= instance
->ctrl_context
;
5998 if (MR_ValidateMapInfo(instance
, instance
->map_id
))
5999 fusion
->fast_path_io
= 1;
6001 fusion
->fast_path_io
= 0;
6004 if (ctrl_info
->host_interface
.SRIOV
) {
6005 instance
->requestorId
= ctrl_info
->iov
.requestorId
;
6006 if (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_PLASMA
) {
6007 if (!ctrl_info
->adapterOperations2
.activePassive
)
6008 instance
->PlasmaFW111
= 1;
6010 dev_info(&instance
->pdev
->dev
, "SR-IOV: firmware type: %s\n",
6011 instance
->PlasmaFW111
? "1.11" : "new");
6013 if (instance
->PlasmaFW111
) {
6014 iovPtr
= (struct IOV_111
*)
6015 ((unsigned char *)ctrl_info
+ IOV_111_OFFSET
);
6016 instance
->requestorId
= iovPtr
->requestorId
;
6019 dev_info(&instance
->pdev
->dev
, "SRIOV: VF requestorId %d\n",
6020 instance
->requestorId
);
6023 instance
->crash_dump_fw_support
=
6024 ctrl_info
->adapterOperations3
.supportCrashDump
;
6025 instance
->crash_dump_drv_support
=
6026 (instance
->crash_dump_fw_support
&&
6027 instance
->crash_dump_buf
);
6028 if (instance
->crash_dump_drv_support
)
6029 megasas_set_crash_dump_params(instance
,
6030 MR_CRASH_BUF_TURN_OFF
);
6033 if (instance
->crash_dump_buf
)
6034 dma_free_coherent(&instance
->pdev
->dev
,
6036 instance
->crash_dump_buf
,
6037 instance
->crash_dump_h
);
6038 instance
->crash_dump_buf
= NULL
;
6041 if (instance
->snapdump_wait_time
) {
6042 megasas_get_snapdump_properties(instance
);
6043 dev_info(&instance
->pdev
->dev
, "Snap dump wait time\t: %d\n",
6044 instance
->snapdump_wait_time
);
6047 dev_info(&instance
->pdev
->dev
,
6048 "pci id\t\t: (0x%04x)/(0x%04x)/(0x%04x)/(0x%04x)\n",
6049 le16_to_cpu(ctrl_info
->pci
.vendor_id
),
6050 le16_to_cpu(ctrl_info
->pci
.device_id
),
6051 le16_to_cpu(ctrl_info
->pci
.sub_vendor_id
),
6052 le16_to_cpu(ctrl_info
->pci
.sub_device_id
));
6053 dev_info(&instance
->pdev
->dev
, "unevenspan support : %s\n",
6054 instance
->UnevenSpanSupport
? "yes" : "no");
6055 dev_info(&instance
->pdev
->dev
, "firmware crash dump : %s\n",
6056 instance
->crash_dump_drv_support
? "yes" : "no");
6057 dev_info(&instance
->pdev
->dev
, "jbod sync map : %s\n",
6058 instance
->use_seqnum_jbod_fp
? "yes" : "no");
6060 instance
->max_sectors_per_req
= instance
->max_num_sge
*
6061 SGE_BUFFER_SIZE
/ 512;
6062 if (tmp_sectors
&& (instance
->max_sectors_per_req
> tmp_sectors
))
6063 instance
->max_sectors_per_req
= tmp_sectors
;
6065 /* Check for valid throttlequeuedepth module parameter */
6066 if (throttlequeuedepth
&&
6067 throttlequeuedepth
<= instance
->max_scsi_cmds
)
6068 instance
->throttlequeuedepth
= throttlequeuedepth
;
6070 instance
->throttlequeuedepth
=
6071 MEGASAS_THROTTLE_QUEUE_DEPTH
;
6073 if ((resetwaittime
< 1) ||
6074 (resetwaittime
> MEGASAS_RESET_WAIT_TIME
))
6075 resetwaittime
= MEGASAS_RESET_WAIT_TIME
;
6077 if ((scmd_timeout
< 10) || (scmd_timeout
> MEGASAS_DEFAULT_CMD_TIMEOUT
))
6078 scmd_timeout
= MEGASAS_DEFAULT_CMD_TIMEOUT
;
6080 /* Launch SR-IOV heartbeat timer */
6081 if (instance
->requestorId
) {
6082 if (!megasas_sriov_start_heartbeat(instance
, 1)) {
6083 megasas_start_timer(instance
);
6085 instance
->skip_heartbeat_timer_del
= 1;
6086 goto fail_get_ld_pd_list
;
6091 * Create and start watchdog thread which will monitor
6092 * controller state every 1 sec and trigger OCR when
6093 * it enters fault state
6095 if (instance
->adapter_type
!= MFI_SERIES
)
6096 if (megasas_fusion_start_watchdog(instance
) != SUCCESS
)
6097 goto fail_start_watchdog
;
6101 fail_start_watchdog
:
6102 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
6103 del_timer_sync(&instance
->sriov_heartbeat_timer
);
6104 fail_get_ld_pd_list
:
6105 instance
->instancet
->disable_intr(instance
);
6106 megasas_destroy_irqs(instance
);
6108 if (instance
->msix_vectors
)
6109 pci_free_irq_vectors(instance
->pdev
);
6110 instance
->msix_vectors
= 0;
6112 megasas_free_ctrl_dma_buffers(instance
);
6113 megasas_free_ctrl_mem(instance
);
6115 iounmap(instance
->reg_set
);
6118 pci_release_selected_regions(instance
->pdev
, 1<<instance
->bar
);
6120 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
6121 __func__
, __LINE__
);
6126 * megasas_release_mfi - Reverses the FW initialization
6127 * @instance: Adapter soft state
6129 static void megasas_release_mfi(struct megasas_instance
*instance
)
6131 u32 reply_q_sz
= sizeof(u32
) *(instance
->max_mfi_cmds
+ 1);
6133 if (instance
->reply_queue
)
6134 dma_free_coherent(&instance
->pdev
->dev
, reply_q_sz
,
6135 instance
->reply_queue
, instance
->reply_queue_h
);
6137 megasas_free_cmds(instance
);
6139 iounmap(instance
->reg_set
);
6141 pci_release_selected_regions(instance
->pdev
, 1<<instance
->bar
);
6145 * megasas_get_seq_num - Gets latest event sequence numbers
6146 * @instance: Adapter soft state
6147 * @eli: FW event log sequence numbers information
6149 * FW maintains a log of all events in a non-volatile area. Upper layers would
6150 * usually find out the latest sequence number of the events, the seq number at
6151 * the boot etc. They would "read" all the events below the latest seq number
6152 * by issuing a direct fw cmd (DCMD). For the future events (beyond latest seq
6153 * number), they would subsribe to AEN (asynchronous event notification) and
6154 * wait for the events to happen.
6157 megasas_get_seq_num(struct megasas_instance
*instance
,
6158 struct megasas_evt_log_info
*eli
)
6160 struct megasas_cmd
*cmd
;
6161 struct megasas_dcmd_frame
*dcmd
;
6162 struct megasas_evt_log_info
*el_info
;
6163 dma_addr_t el_info_h
= 0;
6166 cmd
= megasas_get_cmd(instance
);
6172 dcmd
= &cmd
->frame
->dcmd
;
6173 el_info
= dma_alloc_coherent(&instance
->pdev
->dev
,
6174 sizeof(struct megasas_evt_log_info
),
6175 &el_info_h
, GFP_KERNEL
);
6177 megasas_return_cmd(instance
, cmd
);
6181 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
6183 dcmd
->cmd
= MFI_CMD_DCMD
;
6184 dcmd
->cmd_status
= 0x0;
6185 dcmd
->sge_count
= 1;
6186 dcmd
->flags
= MFI_FRAME_DIR_READ
;
6189 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_evt_log_info
));
6190 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_EVENT_GET_INFO
);
6192 megasas_set_dma_settings(instance
, dcmd
, el_info_h
,
6193 sizeof(struct megasas_evt_log_info
));
6195 ret
= megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
);
6196 if (ret
!= DCMD_SUCCESS
) {
6197 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
6198 __func__
, __LINE__
);
6203 * Copy the data back into callers buffer
6205 eli
->newest_seq_num
= el_info
->newest_seq_num
;
6206 eli
->oldest_seq_num
= el_info
->oldest_seq_num
;
6207 eli
->clear_seq_num
= el_info
->clear_seq_num
;
6208 eli
->shutdown_seq_num
= el_info
->shutdown_seq_num
;
6209 eli
->boot_seq_num
= el_info
->boot_seq_num
;
6212 dma_free_coherent(&instance
->pdev
->dev
,
6213 sizeof(struct megasas_evt_log_info
),
6214 el_info
, el_info_h
);
6216 megasas_return_cmd(instance
, cmd
);
6222 * megasas_register_aen - Registers for asynchronous event notification
6223 * @instance: Adapter soft state
6224 * @seq_num: The starting sequence number
6225 * @class_locale: Class of the event
6227 * This function subscribes for AEN for events beyond the @seq_num. It requests
6228 * to be notified if and only if the event is of type @class_locale
6231 megasas_register_aen(struct megasas_instance
*instance
, u32 seq_num
,
6232 u32 class_locale_word
)
6235 struct megasas_cmd
*cmd
;
6236 struct megasas_dcmd_frame
*dcmd
;
6237 union megasas_evt_class_locale curr_aen
;
6238 union megasas_evt_class_locale prev_aen
;
6241 * If there an AEN pending already (aen_cmd), check if the
6242 * class_locale of that pending AEN is inclusive of the new
6243 * AEN request we currently have. If it is, then we don't have
6244 * to do anything. In other words, whichever events the current
6245 * AEN request is subscribing to, have already been subscribed
6248 * If the old_cmd is _not_ inclusive, then we have to abort
6249 * that command, form a class_locale that is superset of both
6250 * old and current and re-issue to the FW
6253 curr_aen
.word
= class_locale_word
;
6255 if (instance
->aen_cmd
) {
6258 le32_to_cpu(instance
->aen_cmd
->frame
->dcmd
.mbox
.w
[1]);
6260 if ((curr_aen
.members
.class < MFI_EVT_CLASS_DEBUG
) ||
6261 (curr_aen
.members
.class > MFI_EVT_CLASS_DEAD
)) {
6262 dev_info(&instance
->pdev
->dev
,
6263 "%s %d out of range class %d send by application\n",
6264 __func__
, __LINE__
, curr_aen
.members
.class);
6269 * A class whose enum value is smaller is inclusive of all
6270 * higher values. If a PROGRESS (= -1) was previously
6271 * registered, then a new registration requests for higher
6272 * classes need not be sent to FW. They are automatically
6275 * Locale numbers don't have such hierarchy. They are bitmap
6278 if ((prev_aen
.members
.class <= curr_aen
.members
.class) &&
6279 !((prev_aen
.members
.locale
& curr_aen
.members
.locale
) ^
6280 curr_aen
.members
.locale
)) {
6282 * Previously issued event registration includes
6283 * current request. Nothing to do.
6287 curr_aen
.members
.locale
|= prev_aen
.members
.locale
;
6289 if (prev_aen
.members
.class < curr_aen
.members
.class)
6290 curr_aen
.members
.class = prev_aen
.members
.class;
6292 instance
->aen_cmd
->abort_aen
= 1;
6293 ret_val
= megasas_issue_blocked_abort_cmd(instance
,
6298 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to abort "
6299 "previous AEN command\n");
6305 cmd
= megasas_get_cmd(instance
);
6310 dcmd
= &cmd
->frame
->dcmd
;
6312 memset(instance
->evt_detail
, 0, sizeof(struct megasas_evt_detail
));
6315 * Prepare DCMD for aen registration
6317 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
6319 dcmd
->cmd
= MFI_CMD_DCMD
;
6320 dcmd
->cmd_status
= 0x0;
6321 dcmd
->sge_count
= 1;
6322 dcmd
->flags
= MFI_FRAME_DIR_READ
;
6325 dcmd
->data_xfer_len
= cpu_to_le32(sizeof(struct megasas_evt_detail
));
6326 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_EVENT_WAIT
);
6327 dcmd
->mbox
.w
[0] = cpu_to_le32(seq_num
);
6328 instance
->last_seq_num
= seq_num
;
6329 dcmd
->mbox
.w
[1] = cpu_to_le32(curr_aen
.word
);
6331 megasas_set_dma_settings(instance
, dcmd
, instance
->evt_detail_h
,
6332 sizeof(struct megasas_evt_detail
));
6334 if (instance
->aen_cmd
!= NULL
) {
6335 megasas_return_cmd(instance
, cmd
);
6340 * Store reference to the cmd used to register for AEN. When an
6341 * application wants us to register for AEN, we have to abort this
6342 * cmd and re-register with a new EVENT LOCALE supplied by that app
6344 instance
->aen_cmd
= cmd
;
6347 * Issue the aen registration frame
6349 instance
->instancet
->issue_dcmd(instance
, cmd
);
6354 /* megasas_get_target_prop - Send DCMD with below details to firmware.
6356 * This DCMD will fetch few properties of LD/system PD defined
6357 * in MR_TARGET_DEV_PROPERTIES. eg. Queue Depth, MDTS value.
6359 * DCMD send by drivers whenever new target is added to the OS.
6361 * dcmd.opcode - MR_DCMD_DEV_GET_TARGET_PROP
6362 * dcmd.mbox.b[0] - DCMD is to be fired for LD or system PD.
6363 * 0 = system PD, 1 = LD.
6364 * dcmd.mbox.s[1] - TargetID for LD/system PD.
6365 * dcmd.sge IN - Pointer to return MR_TARGET_DEV_PROPERTIES.
6367 * @instance: Adapter soft state
6368 * @sdev: OS provided scsi device
6370 * Returns 0 on success non-zero on failure.
6373 megasas_get_target_prop(struct megasas_instance
*instance
,
6374 struct scsi_device
*sdev
)
6377 struct megasas_cmd
*cmd
;
6378 struct megasas_dcmd_frame
*dcmd
;
6379 u16 targetId
= (sdev
->channel
% 2) + sdev
->id
;
6381 cmd
= megasas_get_cmd(instance
);
6384 dev_err(&instance
->pdev
->dev
,
6385 "Failed to get cmd %s\n", __func__
);
6389 dcmd
= &cmd
->frame
->dcmd
;
6391 memset(instance
->tgt_prop
, 0, sizeof(*instance
->tgt_prop
));
6392 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
6393 dcmd
->mbox
.b
[0] = MEGASAS_IS_LOGICAL(sdev
);
6395 dcmd
->mbox
.s
[1] = cpu_to_le16(targetId
);
6396 dcmd
->cmd
= MFI_CMD_DCMD
;
6397 dcmd
->cmd_status
= 0xFF;
6398 dcmd
->sge_count
= 1;
6399 dcmd
->flags
= MFI_FRAME_DIR_READ
;
6402 dcmd
->data_xfer_len
=
6403 cpu_to_le32(sizeof(struct MR_TARGET_PROPERTIES
));
6404 dcmd
->opcode
= cpu_to_le32(MR_DCMD_DRV_GET_TARGET_PROP
);
6406 megasas_set_dma_settings(instance
, dcmd
, instance
->tgt_prop_h
,
6407 sizeof(struct MR_TARGET_PROPERTIES
));
6409 if ((instance
->adapter_type
!= MFI_SERIES
) &&
6410 !instance
->mask_interrupts
)
6411 ret
= megasas_issue_blocked_cmd(instance
,
6412 cmd
, MFI_IO_TIMEOUT_SECS
);
6414 ret
= megasas_issue_polled(instance
, cmd
);
6418 switch (dcmd_timeout_ocr_possible(instance
)) {
6420 cmd
->flags
|= DRV_DCMD_SKIP_REFIRE
;
6421 megasas_reset_fusion(instance
->host
,
6422 MFI_IO_TIMEOUT_OCR
);
6425 megaraid_sas_kill_hba(instance
);
6427 case IGNORE_TIMEOUT
:
6428 dev_info(&instance
->pdev
->dev
,
6429 "Ignore DCMD timeout: %s %d\n",
6430 __func__
, __LINE__
);
6436 megasas_return_cmd(instance
, cmd
);
6438 if (ret
!= DCMD_SUCCESS
)
6439 dev_err(&instance
->pdev
->dev
,
6440 "return from %s %d return value %d\n",
6441 __func__
, __LINE__
, ret
);
6447 * megasas_start_aen - Subscribes to AEN during driver load time
6448 * @instance: Adapter soft state
6450 static int megasas_start_aen(struct megasas_instance
*instance
)
6452 struct megasas_evt_log_info eli
;
6453 union megasas_evt_class_locale class_locale
;
6456 * Get the latest sequence number from FW
6458 memset(&eli
, 0, sizeof(eli
));
6460 if (megasas_get_seq_num(instance
, &eli
))
6464 * Register AEN with FW for latest sequence number plus 1
6466 class_locale
.members
.reserved
= 0;
6467 class_locale
.members
.locale
= MR_EVT_LOCALE_ALL
;
6468 class_locale
.members
.class = MR_EVT_CLASS_DEBUG
;
6470 return megasas_register_aen(instance
,
6471 le32_to_cpu(eli
.newest_seq_num
) + 1,
6476 * megasas_io_attach - Attaches this driver to SCSI mid-layer
6477 * @instance: Adapter soft state
6479 static int megasas_io_attach(struct megasas_instance
*instance
)
6481 struct Scsi_Host
*host
= instance
->host
;
6484 * Export parameters required by SCSI mid-layer
6486 host
->unique_id
= instance
->unique_id
;
6487 host
->can_queue
= instance
->max_scsi_cmds
;
6488 host
->this_id
= instance
->init_id
;
6489 host
->sg_tablesize
= instance
->max_num_sge
;
6491 if (instance
->fw_support_ieee
)
6492 instance
->max_sectors_per_req
= MEGASAS_MAX_SECTORS_IEEE
;
6495 * Check if the module parameter value for max_sectors can be used
6497 if (max_sectors
&& max_sectors
< instance
->max_sectors_per_req
)
6498 instance
->max_sectors_per_req
= max_sectors
;
6501 if (((instance
->pdev
->device
==
6502 PCI_DEVICE_ID_LSI_SAS1078GEN2
) ||
6503 (instance
->pdev
->device
==
6504 PCI_DEVICE_ID_LSI_SAS0079GEN2
)) &&
6505 (max_sectors
<= MEGASAS_MAX_SECTORS
)) {
6506 instance
->max_sectors_per_req
= max_sectors
;
6508 dev_info(&instance
->pdev
->dev
, "max_sectors should be > 0"
6509 "and <= %d (or < 1MB for GEN2 controller)\n",
6510 instance
->max_sectors_per_req
);
6515 host
->max_sectors
= instance
->max_sectors_per_req
;
6516 host
->cmd_per_lun
= MEGASAS_DEFAULT_CMD_PER_LUN
;
6517 host
->max_channel
= MEGASAS_MAX_CHANNELS
- 1;
6518 host
->max_id
= MEGASAS_MAX_DEV_PER_CHANNEL
;
6519 host
->max_lun
= MEGASAS_MAX_LUN
;
6520 host
->max_cmd_len
= 16;
6523 * Notify the mid-layer about the new controller
6525 if (scsi_add_host(host
, &instance
->pdev
->dev
)) {
6526 dev_err(&instance
->pdev
->dev
,
6527 "Failed to add host from %s %d\n",
6528 __func__
, __LINE__
);
6536 * megasas_set_dma_mask - Set DMA mask for supported controllers
6538 * @instance: Adapter soft state
6541 * For Ventura, driver/FW will operate in 63bit DMA addresses.
6544 * By default, driver/FW will operate in 32bit DMA addresses
6545 * for consistent DMA mapping but if 32 bit consistent
6546 * DMA mask fails, driver will try with 63 bit consistent
6547 * mask provided FW is true 63bit DMA capable
6549 * For older controllers(Thunderbolt and MFI based adapters)-
6550 * driver/FW will operate in 32 bit consistent DMA addresses.
6553 megasas_set_dma_mask(struct megasas_instance
*instance
)
6555 u64 consistent_mask
;
6556 struct pci_dev
*pdev
;
6559 pdev
= instance
->pdev
;
6560 consistent_mask
= (instance
->adapter_type
>= VENTURA_SERIES
) ?
6561 DMA_BIT_MASK(63) : DMA_BIT_MASK(32);
6564 if (dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(63)) &&
6565 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)))
6566 goto fail_set_dma_mask
;
6568 if ((*pdev
->dev
.dma_mask
== DMA_BIT_MASK(63)) &&
6569 (dma_set_coherent_mask(&pdev
->dev
, consistent_mask
) &&
6570 dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)))) {
6572 * If 32 bit DMA mask fails, then try for 64 bit mask
6573 * for FW capable of handling 64 bit DMA.
6575 scratch_pad_1
= megasas_readl
6576 (instance
, &instance
->reg_set
->outbound_scratch_pad_1
);
6578 if (!(scratch_pad_1
& MR_CAN_HANDLE_64_BIT_DMA_OFFSET
))
6579 goto fail_set_dma_mask
;
6580 else if (dma_set_mask_and_coherent(&pdev
->dev
,
6582 goto fail_set_dma_mask
;
6584 } else if (dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32)))
6585 goto fail_set_dma_mask
;
6587 if (pdev
->dev
.coherent_dma_mask
== DMA_BIT_MASK(32))
6588 instance
->consistent_mask_64bit
= false;
6590 instance
->consistent_mask_64bit
= true;
6592 dev_info(&pdev
->dev
, "%s bit DMA mask and %s bit consistent mask\n",
6593 ((*pdev
->dev
.dma_mask
== DMA_BIT_MASK(63)) ? "63" : "32"),
6594 (instance
->consistent_mask_64bit
? "63" : "32"));
6599 dev_err(&pdev
->dev
, "Failed to set DMA mask\n");
6605 * megasas_set_adapter_type - Set adapter type.
6606 * Supported controllers can be divided in
6607 * different categories-
6608 * enum MR_ADAPTER_TYPE {
6610 * THUNDERBOLT_SERIES = 2,
6611 * INVADER_SERIES = 3,
6612 * VENTURA_SERIES = 4,
6615 * @instance: Adapter soft state
6618 static inline void megasas_set_adapter_type(struct megasas_instance
*instance
)
6620 if ((instance
->pdev
->vendor
== PCI_VENDOR_ID_DELL
) &&
6621 (instance
->pdev
->device
== PCI_DEVICE_ID_DELL_PERC5
)) {
6622 instance
->adapter_type
= MFI_SERIES
;
6624 switch (instance
->pdev
->device
) {
6625 case PCI_DEVICE_ID_LSI_AERO_10E1
:
6626 case PCI_DEVICE_ID_LSI_AERO_10E2
:
6627 case PCI_DEVICE_ID_LSI_AERO_10E5
:
6628 case PCI_DEVICE_ID_LSI_AERO_10E6
:
6629 instance
->adapter_type
= AERO_SERIES
;
6631 case PCI_DEVICE_ID_LSI_VENTURA
:
6632 case PCI_DEVICE_ID_LSI_CRUSADER
:
6633 case PCI_DEVICE_ID_LSI_HARPOON
:
6634 case PCI_DEVICE_ID_LSI_TOMCAT
:
6635 case PCI_DEVICE_ID_LSI_VENTURA_4PORT
:
6636 case PCI_DEVICE_ID_LSI_CRUSADER_4PORT
:
6637 instance
->adapter_type
= VENTURA_SERIES
;
6639 case PCI_DEVICE_ID_LSI_FUSION
:
6640 case PCI_DEVICE_ID_LSI_PLASMA
:
6641 instance
->adapter_type
= THUNDERBOLT_SERIES
;
6643 case PCI_DEVICE_ID_LSI_INVADER
:
6644 case PCI_DEVICE_ID_LSI_INTRUDER
:
6645 case PCI_DEVICE_ID_LSI_INTRUDER_24
:
6646 case PCI_DEVICE_ID_LSI_CUTLASS_52
:
6647 case PCI_DEVICE_ID_LSI_CUTLASS_53
:
6648 case PCI_DEVICE_ID_LSI_FURY
:
6649 instance
->adapter_type
= INVADER_SERIES
;
6651 default: /* For all other supported controllers */
6652 instance
->adapter_type
= MFI_SERIES
;
6658 static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance
*instance
)
6660 instance
->producer
= dma_alloc_coherent(&instance
->pdev
->dev
,
6661 sizeof(u32
), &instance
->producer_h
, GFP_KERNEL
);
6662 instance
->consumer
= dma_alloc_coherent(&instance
->pdev
->dev
,
6663 sizeof(u32
), &instance
->consumer_h
, GFP_KERNEL
);
6665 if (!instance
->producer
|| !instance
->consumer
) {
6666 dev_err(&instance
->pdev
->dev
,
6667 "Failed to allocate memory for producer, consumer\n");
6671 *instance
->producer
= 0;
6672 *instance
->consumer
= 0;
6677 * megasas_alloc_ctrl_mem - Allocate per controller memory for core data
6678 * structures which are not common across MFI
6679 * adapters and fusion adapters.
6680 * For MFI based adapters, allocate producer and
6681 * consumer buffers. For fusion adapters, allocate
6682 * memory for fusion context.
6683 * @instance: Adapter soft state
6684 * return: 0 for SUCCESS
6686 static int megasas_alloc_ctrl_mem(struct megasas_instance
*instance
)
6688 instance
->reply_map
= kcalloc(nr_cpu_ids
, sizeof(unsigned int),
6690 if (!instance
->reply_map
)
6693 switch (instance
->adapter_type
) {
6695 if (megasas_alloc_mfi_ctrl_mem(instance
))
6699 case VENTURA_SERIES
:
6700 case THUNDERBOLT_SERIES
:
6701 case INVADER_SERIES
:
6702 if (megasas_alloc_fusion_context(instance
))
6709 kfree(instance
->reply_map
);
6710 instance
->reply_map
= NULL
;
6715 * megasas_free_ctrl_mem - Free fusion context for fusion adapters and
6716 * producer, consumer buffers for MFI adapters
6718 * @instance - Adapter soft instance
6721 static inline void megasas_free_ctrl_mem(struct megasas_instance
*instance
)
6723 kfree(instance
->reply_map
);
6724 if (instance
->adapter_type
== MFI_SERIES
) {
6725 if (instance
->producer
)
6726 dma_free_coherent(&instance
->pdev
->dev
, sizeof(u32
),
6728 instance
->producer_h
);
6729 if (instance
->consumer
)
6730 dma_free_coherent(&instance
->pdev
->dev
, sizeof(u32
),
6732 instance
->consumer_h
);
6734 megasas_free_fusion_context(instance
);
6739 * megasas_alloc_ctrl_dma_buffers - Allocate consistent DMA buffers during
6742 * @instance- Adapter soft instance
6743 * @return- O for SUCCESS
6746 int megasas_alloc_ctrl_dma_buffers(struct megasas_instance
*instance
)
6748 struct pci_dev
*pdev
= instance
->pdev
;
6749 struct fusion_context
*fusion
= instance
->ctrl_context
;
6751 instance
->evt_detail
= dma_alloc_coherent(&pdev
->dev
,
6752 sizeof(struct megasas_evt_detail
),
6753 &instance
->evt_detail_h
, GFP_KERNEL
);
6755 if (!instance
->evt_detail
) {
6756 dev_err(&instance
->pdev
->dev
,
6757 "Failed to allocate event detail buffer\n");
6762 fusion
->ioc_init_request
=
6763 dma_alloc_coherent(&pdev
->dev
,
6764 sizeof(struct MPI2_IOC_INIT_REQUEST
),
6765 &fusion
->ioc_init_request_phys
,
6768 if (!fusion
->ioc_init_request
) {
6770 "Failed to allocate PD list buffer\n");
6774 instance
->snapdump_prop
= dma_alloc_coherent(&pdev
->dev
,
6775 sizeof(struct MR_SNAPDUMP_PROPERTIES
),
6776 &instance
->snapdump_prop_h
, GFP_KERNEL
);
6778 if (!instance
->snapdump_prop
)
6780 "Failed to allocate snapdump properties buffer\n");
6782 instance
->host_device_list_buf
= dma_alloc_coherent(&pdev
->dev
,
6783 HOST_DEVICE_LIST_SZ
,
6784 &instance
->host_device_list_buf_h
,
6787 if (!instance
->host_device_list_buf
) {
6789 "Failed to allocate targetid list buffer\n");
6795 instance
->pd_list_buf
=
6796 dma_alloc_coherent(&pdev
->dev
,
6797 MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
),
6798 &instance
->pd_list_buf_h
, GFP_KERNEL
);
6800 if (!instance
->pd_list_buf
) {
6801 dev_err(&pdev
->dev
, "Failed to allocate PD list buffer\n");
6805 instance
->ctrl_info_buf
=
6806 dma_alloc_coherent(&pdev
->dev
,
6807 sizeof(struct megasas_ctrl_info
),
6808 &instance
->ctrl_info_buf_h
, GFP_KERNEL
);
6810 if (!instance
->ctrl_info_buf
) {
6812 "Failed to allocate controller info buffer\n");
6816 instance
->ld_list_buf
=
6817 dma_alloc_coherent(&pdev
->dev
,
6818 sizeof(struct MR_LD_LIST
),
6819 &instance
->ld_list_buf_h
, GFP_KERNEL
);
6821 if (!instance
->ld_list_buf
) {
6822 dev_err(&pdev
->dev
, "Failed to allocate LD list buffer\n");
6826 instance
->ld_targetid_list_buf
=
6827 dma_alloc_coherent(&pdev
->dev
,
6828 sizeof(struct MR_LD_TARGETID_LIST
),
6829 &instance
->ld_targetid_list_buf_h
, GFP_KERNEL
);
6831 if (!instance
->ld_targetid_list_buf
) {
6833 "Failed to allocate LD targetid list buffer\n");
6837 if (!reset_devices
) {
6838 instance
->system_info_buf
=
6839 dma_alloc_coherent(&pdev
->dev
,
6840 sizeof(struct MR_DRV_SYSTEM_INFO
),
6841 &instance
->system_info_h
, GFP_KERNEL
);
6843 dma_alloc_coherent(&pdev
->dev
,
6844 sizeof(struct MR_PD_INFO
),
6845 &instance
->pd_info_h
, GFP_KERNEL
);
6846 instance
->tgt_prop
=
6847 dma_alloc_coherent(&pdev
->dev
,
6848 sizeof(struct MR_TARGET_PROPERTIES
),
6849 &instance
->tgt_prop_h
, GFP_KERNEL
);
6850 instance
->crash_dump_buf
=
6851 dma_alloc_coherent(&pdev
->dev
, CRASH_DMA_BUF_SIZE
,
6852 &instance
->crash_dump_h
, GFP_KERNEL
);
6854 if (!instance
->system_info_buf
)
6855 dev_err(&instance
->pdev
->dev
,
6856 "Failed to allocate system info buffer\n");
6858 if (!instance
->pd_info
)
6859 dev_err(&instance
->pdev
->dev
,
6860 "Failed to allocate pd_info buffer\n");
6862 if (!instance
->tgt_prop
)
6863 dev_err(&instance
->pdev
->dev
,
6864 "Failed to allocate tgt_prop buffer\n");
6866 if (!instance
->crash_dump_buf
)
6867 dev_err(&instance
->pdev
->dev
,
6868 "Failed to allocate crash dump buffer\n");
6875 * megasas_free_ctrl_dma_buffers - Free consistent DMA buffers allocated
6876 * during driver load time
6878 * @instance- Adapter soft instance
6882 void megasas_free_ctrl_dma_buffers(struct megasas_instance
*instance
)
6884 struct pci_dev
*pdev
= instance
->pdev
;
6885 struct fusion_context
*fusion
= instance
->ctrl_context
;
6887 if (instance
->evt_detail
)
6888 dma_free_coherent(&pdev
->dev
, sizeof(struct megasas_evt_detail
),
6889 instance
->evt_detail
,
6890 instance
->evt_detail_h
);
6892 if (fusion
&& fusion
->ioc_init_request
)
6893 dma_free_coherent(&pdev
->dev
,
6894 sizeof(struct MPI2_IOC_INIT_REQUEST
),
6895 fusion
->ioc_init_request
,
6896 fusion
->ioc_init_request_phys
);
6898 if (instance
->pd_list_buf
)
6899 dma_free_coherent(&pdev
->dev
,
6900 MEGASAS_MAX_PD
* sizeof(struct MR_PD_LIST
),
6901 instance
->pd_list_buf
,
6902 instance
->pd_list_buf_h
);
6904 if (instance
->ld_list_buf
)
6905 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_LD_LIST
),
6906 instance
->ld_list_buf
,
6907 instance
->ld_list_buf_h
);
6909 if (instance
->ld_targetid_list_buf
)
6910 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_LD_TARGETID_LIST
),
6911 instance
->ld_targetid_list_buf
,
6912 instance
->ld_targetid_list_buf_h
);
6914 if (instance
->ctrl_info_buf
)
6915 dma_free_coherent(&pdev
->dev
, sizeof(struct megasas_ctrl_info
),
6916 instance
->ctrl_info_buf
,
6917 instance
->ctrl_info_buf_h
);
6919 if (instance
->system_info_buf
)
6920 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_DRV_SYSTEM_INFO
),
6921 instance
->system_info_buf
,
6922 instance
->system_info_h
);
6924 if (instance
->pd_info
)
6925 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_PD_INFO
),
6926 instance
->pd_info
, instance
->pd_info_h
);
6928 if (instance
->tgt_prop
)
6929 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_TARGET_PROPERTIES
),
6930 instance
->tgt_prop
, instance
->tgt_prop_h
);
6932 if (instance
->crash_dump_buf
)
6933 dma_free_coherent(&pdev
->dev
, CRASH_DMA_BUF_SIZE
,
6934 instance
->crash_dump_buf
,
6935 instance
->crash_dump_h
);
6937 if (instance
->snapdump_prop
)
6938 dma_free_coherent(&pdev
->dev
,
6939 sizeof(struct MR_SNAPDUMP_PROPERTIES
),
6940 instance
->snapdump_prop
,
6941 instance
->snapdump_prop_h
);
6943 if (instance
->host_device_list_buf
)
6944 dma_free_coherent(&pdev
->dev
,
6945 HOST_DEVICE_LIST_SZ
,
6946 instance
->host_device_list_buf
,
6947 instance
->host_device_list_buf_h
);
6952 * megasas_init_ctrl_params - Initialize controller's instance
6953 * parameters before FW init
6954 * @instance - Adapter soft instance
6957 static inline void megasas_init_ctrl_params(struct megasas_instance
*instance
)
6959 instance
->fw_crash_state
= UNAVAILABLE
;
6961 megasas_poll_wait_aen
= 0;
6962 instance
->issuepend_done
= 1;
6963 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
6966 * Initialize locks and queues
6968 INIT_LIST_HEAD(&instance
->cmd_pool
);
6969 INIT_LIST_HEAD(&instance
->internal_reset_pending_q
);
6971 atomic_set(&instance
->fw_outstanding
, 0);
6972 atomic64_set(&instance
->total_io_count
, 0);
6974 init_waitqueue_head(&instance
->int_cmd_wait_q
);
6975 init_waitqueue_head(&instance
->abort_cmd_wait_q
);
6977 spin_lock_init(&instance
->crashdump_lock
);
6978 spin_lock_init(&instance
->mfi_pool_lock
);
6979 spin_lock_init(&instance
->hba_lock
);
6980 spin_lock_init(&instance
->stream_lock
);
6981 spin_lock_init(&instance
->completion_lock
);
6983 mutex_init(&instance
->reset_mutex
);
6985 if ((instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0073SKINNY
) ||
6986 (instance
->pdev
->device
== PCI_DEVICE_ID_LSI_SAS0071SKINNY
))
6987 instance
->flag_ieee
= 1;
6989 megasas_dbg_lvl
= 0;
6991 instance
->unload
= 1;
6992 instance
->last_time
= 0;
6993 instance
->disableOnlineCtrlReset
= 1;
6994 instance
->UnevenSpanSupport
= 0;
6995 instance
->smp_affinity_enable
= smp_affinity_enable
? true : false;
6996 instance
->msix_load_balance
= false;
6998 if (instance
->adapter_type
!= MFI_SERIES
)
6999 INIT_WORK(&instance
->work_init
, megasas_fusion_ocr_wq
);
7001 INIT_WORK(&instance
->work_init
, process_fw_state_change_wq
);
7005 * megasas_probe_one - PCI hotplug entry point
7006 * @pdev: PCI device structure
7007 * @id: PCI ids of supported hotplugged adapter
7009 static int megasas_probe_one(struct pci_dev
*pdev
,
7010 const struct pci_device_id
*id
)
7013 struct Scsi_Host
*host
;
7014 struct megasas_instance
*instance
;
7017 switch (pdev
->device
) {
7018 case PCI_DEVICE_ID_LSI_AERO_10E1
:
7019 case PCI_DEVICE_ID_LSI_AERO_10E5
:
7020 dev_info(&pdev
->dev
, "Adapter is in configurable secure mode\n");
7024 /* Reset MSI-X in the kdump kernel */
7025 if (reset_devices
) {
7026 pos
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
7028 pci_read_config_word(pdev
, pos
+ PCI_MSIX_FLAGS
,
7030 if (control
& PCI_MSIX_FLAGS_ENABLE
) {
7031 dev_info(&pdev
->dev
, "resetting MSI-X\n");
7032 pci_write_config_word(pdev
,
7033 pos
+ PCI_MSIX_FLAGS
,
7035 ~PCI_MSIX_FLAGS_ENABLE
);
7041 * PCI prepping: enable device set bus mastering and dma mask
7043 rval
= pci_enable_device_mem(pdev
);
7049 pci_set_master(pdev
);
7051 host
= scsi_host_alloc(&megasas_template
,
7052 sizeof(struct megasas_instance
));
7055 dev_printk(KERN_DEBUG
, &pdev
->dev
, "scsi_host_alloc failed\n");
7056 goto fail_alloc_instance
;
7059 instance
= (struct megasas_instance
*)host
->hostdata
;
7060 memset(instance
, 0, sizeof(*instance
));
7061 atomic_set(&instance
->fw_reset_no_pci_access
, 0);
7064 * Initialize PCI related and misc parameters
7066 instance
->pdev
= pdev
;
7067 instance
->host
= host
;
7068 instance
->unique_id
= pdev
->bus
->number
<< 8 | pdev
->devfn
;
7069 instance
->init_id
= MEGASAS_DEFAULT_INIT_ID
;
7071 megasas_set_adapter_type(instance
);
7074 * Initialize MFI Firmware
7076 if (megasas_init_fw(instance
))
7079 if (instance
->requestorId
) {
7080 if (instance
->PlasmaFW111
) {
7081 instance
->vf_affiliation_111
=
7082 dma_alloc_coherent(&pdev
->dev
,
7083 sizeof(struct MR_LD_VF_AFFILIATION_111
),
7084 &instance
->vf_affiliation_111_h
,
7086 if (!instance
->vf_affiliation_111
)
7087 dev_warn(&pdev
->dev
, "Can't allocate "
7088 "memory for VF affiliation buffer\n");
7090 instance
->vf_affiliation
=
7091 dma_alloc_coherent(&pdev
->dev
,
7092 (MAX_LOGICAL_DRIVES
+ 1) *
7093 sizeof(struct MR_LD_VF_AFFILIATION
),
7094 &instance
->vf_affiliation_h
,
7096 if (!instance
->vf_affiliation
)
7097 dev_warn(&pdev
->dev
, "Can't allocate "
7098 "memory for VF affiliation buffer\n");
7103 * Store instance in PCI softstate
7105 pci_set_drvdata(pdev
, instance
);
7108 * Add this controller to megasas_mgmt_info structure so that it
7109 * can be exported to management applications
7111 megasas_mgmt_info
.count
++;
7112 megasas_mgmt_info
.instance
[megasas_mgmt_info
.max_index
] = instance
;
7113 megasas_mgmt_info
.max_index
++;
7116 * Register with SCSI mid-layer
7118 if (megasas_io_attach(instance
))
7119 goto fail_io_attach
;
7121 instance
->unload
= 0;
7123 * Trigger SCSI to scan our drives
7125 if (!instance
->enable_fw_dev_list
||
7126 (instance
->host_device_list_buf
->count
> 0))
7127 scsi_scan_host(host
);
7130 * Initiate AEN (Asynchronous Event Notification)
7132 if (megasas_start_aen(instance
)) {
7133 dev_printk(KERN_DEBUG
, &pdev
->dev
, "start aen failed\n");
7134 goto fail_start_aen
;
7137 megasas_setup_debugfs(instance
);
7139 /* Get current SR-IOV LD/VF affiliation */
7140 if (instance
->requestorId
)
7141 megasas_get_ld_vf_affiliation(instance
, 1);
7147 megasas_mgmt_info
.count
--;
7148 megasas_mgmt_info
.max_index
--;
7149 megasas_mgmt_info
.instance
[megasas_mgmt_info
.max_index
] = NULL
;
7151 instance
->instancet
->disable_intr(instance
);
7152 megasas_destroy_irqs(instance
);
7154 if (instance
->adapter_type
!= MFI_SERIES
)
7155 megasas_release_fusion(instance
);
7157 megasas_release_mfi(instance
);
7158 if (instance
->msix_vectors
)
7159 pci_free_irq_vectors(instance
->pdev
);
7161 scsi_host_put(host
);
7162 fail_alloc_instance
:
7163 pci_disable_device(pdev
);
7169 * megasas_flush_cache - Requests FW to flush all its caches
7170 * @instance: Adapter soft state
7172 static void megasas_flush_cache(struct megasas_instance
*instance
)
7174 struct megasas_cmd
*cmd
;
7175 struct megasas_dcmd_frame
*dcmd
;
7177 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
7180 cmd
= megasas_get_cmd(instance
);
7185 dcmd
= &cmd
->frame
->dcmd
;
7187 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
7189 dcmd
->cmd
= MFI_CMD_DCMD
;
7190 dcmd
->cmd_status
= 0x0;
7191 dcmd
->sge_count
= 0;
7192 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_NONE
);
7195 dcmd
->data_xfer_len
= 0;
7196 dcmd
->opcode
= cpu_to_le32(MR_DCMD_CTRL_CACHE_FLUSH
);
7197 dcmd
->mbox
.b
[0] = MR_FLUSH_CTRL_CACHE
| MR_FLUSH_DISK_CACHE
;
7199 if (megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
)
7201 dev_err(&instance
->pdev
->dev
,
7202 "return from %s %d\n", __func__
, __LINE__
);
7206 megasas_return_cmd(instance
, cmd
);
7210 * megasas_shutdown_controller - Instructs FW to shutdown the controller
7211 * @instance: Adapter soft state
7212 * @opcode: Shutdown/Hibernate
7214 static void megasas_shutdown_controller(struct megasas_instance
*instance
,
7217 struct megasas_cmd
*cmd
;
7218 struct megasas_dcmd_frame
*dcmd
;
7220 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
7223 cmd
= megasas_get_cmd(instance
);
7228 if (instance
->aen_cmd
)
7229 megasas_issue_blocked_abort_cmd(instance
,
7230 instance
->aen_cmd
, MFI_IO_TIMEOUT_SECS
);
7231 if (instance
->map_update_cmd
)
7232 megasas_issue_blocked_abort_cmd(instance
,
7233 instance
->map_update_cmd
, MFI_IO_TIMEOUT_SECS
);
7234 if (instance
->jbod_seq_cmd
)
7235 megasas_issue_blocked_abort_cmd(instance
,
7236 instance
->jbod_seq_cmd
, MFI_IO_TIMEOUT_SECS
);
7238 dcmd
= &cmd
->frame
->dcmd
;
7240 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
7242 dcmd
->cmd
= MFI_CMD_DCMD
;
7243 dcmd
->cmd_status
= 0x0;
7244 dcmd
->sge_count
= 0;
7245 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_NONE
);
7248 dcmd
->data_xfer_len
= 0;
7249 dcmd
->opcode
= cpu_to_le32(opcode
);
7251 if (megasas_issue_blocked_cmd(instance
, cmd
, MFI_IO_TIMEOUT_SECS
)
7253 dev_err(&instance
->pdev
->dev
,
7254 "return from %s %d\n", __func__
, __LINE__
);
7258 megasas_return_cmd(instance
, cmd
);
7263 * megasas_suspend - driver suspend entry point
7264 * @pdev: PCI device structure
7265 * @state: PCI power state to suspend routine
7268 megasas_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7270 struct Scsi_Host
*host
;
7271 struct megasas_instance
*instance
;
7273 instance
= pci_get_drvdata(pdev
);
7274 host
= instance
->host
;
7275 instance
->unload
= 1;
7277 dev_info(&pdev
->dev
, "%s is called\n", __func__
);
7279 /* Shutdown SR-IOV heartbeat timer */
7280 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
7281 del_timer_sync(&instance
->sriov_heartbeat_timer
);
7283 /* Stop the FW fault detection watchdog */
7284 if (instance
->adapter_type
!= MFI_SERIES
)
7285 megasas_fusion_stop_watchdog(instance
);
7287 megasas_flush_cache(instance
);
7288 megasas_shutdown_controller(instance
, MR_DCMD_HIBERNATE_SHUTDOWN
);
7290 /* cancel the delayed work if this work still in queue */
7291 if (instance
->ev
!= NULL
) {
7292 struct megasas_aen_event
*ev
= instance
->ev
;
7293 cancel_delayed_work_sync(&ev
->hotplug_work
);
7294 instance
->ev
= NULL
;
7297 tasklet_kill(&instance
->isr_tasklet
);
7299 pci_set_drvdata(instance
->pdev
, instance
);
7300 instance
->instancet
->disable_intr(instance
);
7302 megasas_destroy_irqs(instance
);
7304 if (instance
->msix_vectors
)
7305 pci_free_irq_vectors(instance
->pdev
);
7307 pci_save_state(pdev
);
7308 pci_disable_device(pdev
);
7310 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
7316 * megasas_resume- driver resume entry point
7317 * @pdev: PCI device structure
7320 megasas_resume(struct pci_dev
*pdev
)
7323 struct Scsi_Host
*host
;
7324 struct megasas_instance
*instance
;
7325 int irq_flags
= PCI_IRQ_LEGACY
;
7327 instance
= pci_get_drvdata(pdev
);
7328 host
= instance
->host
;
7329 pci_set_power_state(pdev
, PCI_D0
);
7330 pci_enable_wake(pdev
, PCI_D0
, 0);
7331 pci_restore_state(pdev
);
7333 dev_info(&pdev
->dev
, "%s is called\n", __func__
);
7335 * PCI prepping: enable device set bus mastering and dma mask
7337 rval
= pci_enable_device_mem(pdev
);
7340 dev_err(&pdev
->dev
, "Enable device failed\n");
7344 pci_set_master(pdev
);
7347 * We expect the FW state to be READY
7349 if (megasas_transition_to_ready(instance
, 0))
7350 goto fail_ready_state
;
7352 if (megasas_set_dma_mask(instance
))
7353 goto fail_set_dma_mask
;
7356 * Initialize MFI Firmware
7359 atomic_set(&instance
->fw_outstanding
, 0);
7360 atomic_set(&instance
->ldio_outstanding
, 0);
7362 /* Now re-enable MSI-X */
7363 if (instance
->msix_vectors
) {
7364 irq_flags
= PCI_IRQ_MSIX
;
7365 if (instance
->smp_affinity_enable
)
7366 irq_flags
|= PCI_IRQ_AFFINITY
;
7368 rval
= pci_alloc_irq_vectors(instance
->pdev
, 1,
7369 instance
->msix_vectors
?
7370 instance
->msix_vectors
: 1, irq_flags
);
7372 goto fail_reenable_msix
;
7374 megasas_setup_reply_map(instance
);
7376 if (instance
->adapter_type
!= MFI_SERIES
) {
7377 megasas_reset_reply_desc(instance
);
7378 if (megasas_ioc_init_fusion(instance
)) {
7379 megasas_free_cmds(instance
);
7380 megasas_free_cmds_fusion(instance
);
7383 if (!megasas_get_map_info(instance
))
7384 megasas_sync_map_info(instance
);
7386 *instance
->producer
= 0;
7387 *instance
->consumer
= 0;
7388 if (megasas_issue_init_mfi(instance
))
7392 if (megasas_get_ctrl_info(instance
) != DCMD_SUCCESS
)
7395 tasklet_init(&instance
->isr_tasklet
, instance
->instancet
->tasklet
,
7396 (unsigned long)instance
);
7398 if (instance
->msix_vectors
?
7399 megasas_setup_irqs_msix(instance
, 0) :
7400 megasas_setup_irqs_ioapic(instance
))
7403 if (instance
->adapter_type
!= MFI_SERIES
)
7404 megasas_setup_irq_poll(instance
);
7406 /* Re-launch SR-IOV heartbeat timer */
7407 if (instance
->requestorId
) {
7408 if (!megasas_sriov_start_heartbeat(instance
, 0))
7409 megasas_start_timer(instance
);
7411 instance
->skip_heartbeat_timer_del
= 1;
7416 instance
->instancet
->enable_intr(instance
);
7417 megasas_setup_jbod_map(instance
);
7418 instance
->unload
= 0;
7421 * Initiate AEN (Asynchronous Event Notification)
7423 if (megasas_start_aen(instance
))
7424 dev_err(&instance
->pdev
->dev
, "Start AEN failed\n");
7426 /* Re-launch FW fault watchdog */
7427 if (instance
->adapter_type
!= MFI_SERIES
)
7428 if (megasas_fusion_start_watchdog(instance
) != SUCCESS
)
7429 goto fail_start_watchdog
;
7433 fail_start_watchdog
:
7434 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
7435 del_timer_sync(&instance
->sriov_heartbeat_timer
);
7437 megasas_free_ctrl_dma_buffers(instance
);
7438 megasas_free_ctrl_mem(instance
);
7439 scsi_host_put(host
);
7445 pci_disable_device(pdev
);
7450 #define megasas_suspend NULL
7451 #define megasas_resume NULL
7455 megasas_wait_for_adapter_operational(struct megasas_instance
*instance
)
7457 int wait_time
= MEGASAS_RESET_WAIT_TIME
* 2;
7461 for (i
= 0; i
< wait_time
; i
++) {
7462 adp_state
= atomic_read(&instance
->adprecovery
);
7463 if ((adp_state
== MEGASAS_HBA_OPERATIONAL
) ||
7464 (adp_state
== MEGASAS_HW_CRITICAL_ERROR
))
7467 if (!(i
% MEGASAS_RESET_NOTICE_INTERVAL
))
7468 dev_notice(&instance
->pdev
->dev
, "waiting for controller reset to finish\n");
7473 if (adp_state
!= MEGASAS_HBA_OPERATIONAL
) {
7474 dev_info(&instance
->pdev
->dev
,
7475 "%s HBA failed to become operational, adp_state %d\n",
7476 __func__
, adp_state
);
7484 * megasas_detach_one - PCI hot"un"plug entry point
7485 * @pdev: PCI device structure
7487 static void megasas_detach_one(struct pci_dev
*pdev
)
7490 struct Scsi_Host
*host
;
7491 struct megasas_instance
*instance
;
7492 struct fusion_context
*fusion
;
7495 instance
= pci_get_drvdata(pdev
);
7496 host
= instance
->host
;
7497 fusion
= instance
->ctrl_context
;
7499 /* Shutdown SR-IOV heartbeat timer */
7500 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
7501 del_timer_sync(&instance
->sriov_heartbeat_timer
);
7503 /* Stop the FW fault detection watchdog */
7504 if (instance
->adapter_type
!= MFI_SERIES
)
7505 megasas_fusion_stop_watchdog(instance
);
7507 if (instance
->fw_crash_state
!= UNAVAILABLE
)
7508 megasas_free_host_crash_buffer(instance
);
7509 scsi_remove_host(instance
->host
);
7510 instance
->unload
= 1;
7512 if (megasas_wait_for_adapter_operational(instance
))
7513 goto skip_firing_dcmds
;
7515 megasas_flush_cache(instance
);
7516 megasas_shutdown_controller(instance
, MR_DCMD_CTRL_SHUTDOWN
);
7519 /* cancel the delayed work if this work still in queue*/
7520 if (instance
->ev
!= NULL
) {
7521 struct megasas_aen_event
*ev
= instance
->ev
;
7522 cancel_delayed_work_sync(&ev
->hotplug_work
);
7523 instance
->ev
= NULL
;
7526 /* cancel all wait events */
7527 wake_up_all(&instance
->int_cmd_wait_q
);
7529 tasklet_kill(&instance
->isr_tasklet
);
7532 * Take the instance off the instance array. Note that we will not
7533 * decrement the max_index. We let this array be sparse array
7535 for (i
= 0; i
< megasas_mgmt_info
.max_index
; i
++) {
7536 if (megasas_mgmt_info
.instance
[i
] == instance
) {
7537 megasas_mgmt_info
.count
--;
7538 megasas_mgmt_info
.instance
[i
] = NULL
;
7544 instance
->instancet
->disable_intr(instance
);
7546 megasas_destroy_irqs(instance
);
7548 if (instance
->msix_vectors
)
7549 pci_free_irq_vectors(instance
->pdev
);
7551 if (instance
->adapter_type
>= VENTURA_SERIES
) {
7552 for (i
= 0; i
< MAX_LOGICAL_DRIVES_EXT
; ++i
)
7553 kfree(fusion
->stream_detect_by_ld
[i
]);
7554 kfree(fusion
->stream_detect_by_ld
);
7555 fusion
->stream_detect_by_ld
= NULL
;
7559 if (instance
->adapter_type
!= MFI_SERIES
) {
7560 megasas_release_fusion(instance
);
7561 pd_seq_map_sz
= sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC
) +
7562 (sizeof(struct MR_PD_CFG_SEQ
) *
7563 (MAX_PHYSICAL_DEVICES
- 1));
7564 for (i
= 0; i
< 2 ; i
++) {
7565 if (fusion
->ld_map
[i
])
7566 dma_free_coherent(&instance
->pdev
->dev
,
7569 fusion
->ld_map_phys
[i
]);
7570 if (fusion
->ld_drv_map
[i
]) {
7571 if (is_vmalloc_addr(fusion
->ld_drv_map
[i
]))
7572 vfree(fusion
->ld_drv_map
[i
]);
7574 free_pages((ulong
)fusion
->ld_drv_map
[i
],
7575 fusion
->drv_map_pages
);
7578 if (fusion
->pd_seq_sync
[i
])
7579 dma_free_coherent(&instance
->pdev
->dev
,
7581 fusion
->pd_seq_sync
[i
],
7582 fusion
->pd_seq_phys
[i
]);
7585 megasas_release_mfi(instance
);
7588 if (instance
->vf_affiliation
)
7589 dma_free_coherent(&pdev
->dev
, (MAX_LOGICAL_DRIVES
+ 1) *
7590 sizeof(struct MR_LD_VF_AFFILIATION
),
7591 instance
->vf_affiliation
,
7592 instance
->vf_affiliation_h
);
7594 if (instance
->vf_affiliation_111
)
7595 dma_free_coherent(&pdev
->dev
,
7596 sizeof(struct MR_LD_VF_AFFILIATION_111
),
7597 instance
->vf_affiliation_111
,
7598 instance
->vf_affiliation_111_h
);
7600 if (instance
->hb_host_mem
)
7601 dma_free_coherent(&pdev
->dev
, sizeof(struct MR_CTRL_HB_HOST_MEM
),
7602 instance
->hb_host_mem
,
7603 instance
->hb_host_mem_h
);
7605 megasas_free_ctrl_dma_buffers(instance
);
7607 megasas_free_ctrl_mem(instance
);
7609 megasas_destroy_debugfs(instance
);
7611 scsi_host_put(host
);
7613 pci_disable_device(pdev
);
7617 * megasas_shutdown - Shutdown entry point
7618 * @device: Generic device structure
7620 static void megasas_shutdown(struct pci_dev
*pdev
)
7622 struct megasas_instance
*instance
= pci_get_drvdata(pdev
);
7624 instance
->unload
= 1;
7626 if (megasas_wait_for_adapter_operational(instance
))
7627 goto skip_firing_dcmds
;
7629 megasas_flush_cache(instance
);
7630 megasas_shutdown_controller(instance
, MR_DCMD_CTRL_SHUTDOWN
);
7633 instance
->instancet
->disable_intr(instance
);
7634 megasas_destroy_irqs(instance
);
7636 if (instance
->msix_vectors
)
7637 pci_free_irq_vectors(instance
->pdev
);
7641 * megasas_mgmt_open - char node "open" entry point
7643 static int megasas_mgmt_open(struct inode
*inode
, struct file
*filep
)
7646 * Allow only those users with admin rights
7648 if (!capable(CAP_SYS_ADMIN
))
7655 * megasas_mgmt_fasync - Async notifier registration from applications
7657 * This function adds the calling process to a driver global queue. When an
7658 * event occurs, SIGIO will be sent to all processes in this queue.
7660 static int megasas_mgmt_fasync(int fd
, struct file
*filep
, int mode
)
7664 mutex_lock(&megasas_async_queue_mutex
);
7666 rc
= fasync_helper(fd
, filep
, mode
, &megasas_async_queue
);
7668 mutex_unlock(&megasas_async_queue_mutex
);
7671 /* For sanity check when we get ioctl */
7672 filep
->private_data
= filep
;
7676 printk(KERN_DEBUG
"megasas: fasync_helper failed [%d]\n", rc
);
7682 * megasas_mgmt_poll - char node "poll" entry point
7684 static __poll_t
megasas_mgmt_poll(struct file
*file
, poll_table
*wait
)
7687 unsigned long flags
;
7689 poll_wait(file
, &megasas_poll_wait
, wait
);
7690 spin_lock_irqsave(&poll_aen_lock
, flags
);
7691 if (megasas_poll_wait_aen
)
7692 mask
= (EPOLLIN
| EPOLLRDNORM
);
7695 megasas_poll_wait_aen
= 0;
7696 spin_unlock_irqrestore(&poll_aen_lock
, flags
);
7701 * megasas_set_crash_dump_params_ioctl:
7702 * Send CRASH_DUMP_MODE DCMD to all controllers
7703 * @cmd: MFI command frame
7706 static int megasas_set_crash_dump_params_ioctl(struct megasas_cmd
*cmd
)
7708 struct megasas_instance
*local_instance
;
7712 crash_support
= cmd
->frame
->dcmd
.mbox
.w
[0];
7714 for (i
= 0; i
< megasas_mgmt_info
.max_index
; i
++) {
7715 local_instance
= megasas_mgmt_info
.instance
[i
];
7716 if (local_instance
&& local_instance
->crash_dump_drv_support
) {
7717 if ((atomic_read(&local_instance
->adprecovery
) ==
7718 MEGASAS_HBA_OPERATIONAL
) &&
7719 !megasas_set_crash_dump_params(local_instance
,
7721 local_instance
->crash_dump_app_support
=
7723 dev_info(&local_instance
->pdev
->dev
,
7724 "Application firmware crash "
7725 "dump mode set success\n");
7728 dev_info(&local_instance
->pdev
->dev
,
7729 "Application firmware crash "
7730 "dump mode set failed\n");
7739 * megasas_mgmt_fw_ioctl - Issues management ioctls to FW
7740 * @instance: Adapter soft state
7741 * @argp: User's ioctl packet
7744 megasas_mgmt_fw_ioctl(struct megasas_instance
*instance
,
7745 struct megasas_iocpacket __user
* user_ioc
,
7746 struct megasas_iocpacket
*ioc
)
7748 struct megasas_sge64
*kern_sge64
= NULL
;
7749 struct megasas_sge32
*kern_sge32
= NULL
;
7750 struct megasas_cmd
*cmd
;
7751 void *kbuff_arr
[MAX_IOCTL_SGE
];
7752 dma_addr_t buf_handle
= 0;
7755 dma_addr_t sense_handle
;
7756 unsigned long *sense_ptr
;
7759 memset(kbuff_arr
, 0, sizeof(kbuff_arr
));
7761 if (ioc
->sge_count
> MAX_IOCTL_SGE
) {
7762 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "SGE count [%d] > max limit [%d]\n",
7763 ioc
->sge_count
, MAX_IOCTL_SGE
);
7767 if ((ioc
->frame
.hdr
.cmd
>= MFI_CMD_OP_COUNT
) ||
7768 ((ioc
->frame
.hdr
.cmd
== MFI_CMD_NVME
) &&
7769 !instance
->support_nvme_passthru
)) {
7770 dev_err(&instance
->pdev
->dev
,
7771 "Received invalid ioctl command 0x%x\n",
7772 ioc
->frame
.hdr
.cmd
);
7776 cmd
= megasas_get_cmd(instance
);
7778 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get a cmd packet\n");
7783 * User's IOCTL packet has 2 frames (maximum). Copy those two
7784 * frames into our cmd's frames. cmd->frame's context will get
7785 * overwritten when we copy from user's frames. So set that value
7788 memcpy(cmd
->frame
, ioc
->frame
.raw
, 2 * MEGAMFI_FRAME_SIZE
);
7789 cmd
->frame
->hdr
.context
= cpu_to_le32(cmd
->index
);
7790 cmd
->frame
->hdr
.pad_0
= 0;
7792 cmd
->frame
->hdr
.flags
&= (~MFI_FRAME_IEEE
);
7794 if (instance
->consistent_mask_64bit
)
7795 cmd
->frame
->hdr
.flags
|= cpu_to_le16((MFI_FRAME_SGL64
|
7796 MFI_FRAME_SENSE64
));
7798 cmd
->frame
->hdr
.flags
&= cpu_to_le16(~(MFI_FRAME_SGL64
|
7799 MFI_FRAME_SENSE64
));
7801 if (cmd
->frame
->hdr
.cmd
== MFI_CMD_DCMD
)
7802 opcode
= le32_to_cpu(cmd
->frame
->dcmd
.opcode
);
7804 if (opcode
== MR_DCMD_CTRL_SHUTDOWN
) {
7805 if (megasas_get_ctrl_info(instance
) != DCMD_SUCCESS
) {
7806 megasas_return_cmd(instance
, cmd
);
7811 if (opcode
== MR_DRIVER_SET_APP_CRASHDUMP_MODE
) {
7812 error
= megasas_set_crash_dump_params_ioctl(cmd
);
7813 megasas_return_cmd(instance
, cmd
);
7818 * The management interface between applications and the fw uses
7819 * MFI frames. E.g, RAID configuration changes, LD property changes
7820 * etc are accomplishes through different kinds of MFI frames. The
7821 * driver needs to care only about substituting user buffers with
7822 * kernel buffers in SGLs. The location of SGL is embedded in the
7823 * struct iocpacket itself.
7825 if (instance
->consistent_mask_64bit
)
7826 kern_sge64
= (struct megasas_sge64
*)
7827 ((unsigned long)cmd
->frame
+ ioc
->sgl_off
);
7829 kern_sge32
= (struct megasas_sge32
*)
7830 ((unsigned long)cmd
->frame
+ ioc
->sgl_off
);
7833 * For each user buffer, create a mirror buffer and copy in
7835 for (i
= 0; i
< ioc
->sge_count
; i
++) {
7836 if (!ioc
->sgl
[i
].iov_len
)
7839 kbuff_arr
[i
] = dma_alloc_coherent(&instance
->pdev
->dev
,
7840 ioc
->sgl
[i
].iov_len
,
7841 &buf_handle
, GFP_KERNEL
);
7842 if (!kbuff_arr
[i
]) {
7843 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to alloc "
7844 "kernel SGL buffer for IOCTL\n");
7850 * We don't change the dma_coherent_mask, so
7851 * dma_alloc_coherent only returns 32bit addresses
7853 if (instance
->consistent_mask_64bit
) {
7854 kern_sge64
[i
].phys_addr
= cpu_to_le64(buf_handle
);
7855 kern_sge64
[i
].length
= cpu_to_le32(ioc
->sgl
[i
].iov_len
);
7857 kern_sge32
[i
].phys_addr
= cpu_to_le32(buf_handle
);
7858 kern_sge32
[i
].length
= cpu_to_le32(ioc
->sgl
[i
].iov_len
);
7862 * We created a kernel buffer corresponding to the
7863 * user buffer. Now copy in from the user buffer
7865 if (copy_from_user(kbuff_arr
[i
], ioc
->sgl
[i
].iov_base
,
7866 (u32
) (ioc
->sgl
[i
].iov_len
))) {
7872 if (ioc
->sense_len
) {
7873 sense
= dma_alloc_coherent(&instance
->pdev
->dev
, ioc
->sense_len
,
7874 &sense_handle
, GFP_KERNEL
);
7881 (unsigned long *) ((unsigned long)cmd
->frame
+ ioc
->sense_off
);
7882 if (instance
->consistent_mask_64bit
)
7883 *sense_ptr
= cpu_to_le64(sense_handle
);
7885 *sense_ptr
= cpu_to_le32(sense_handle
);
7889 * Set the sync_cmd flag so that the ISR knows not to complete this
7890 * cmd to the SCSI mid-layer
7893 if (megasas_issue_blocked_cmd(instance
, cmd
, 0) == DCMD_NOT_FIRED
) {
7895 dev_err(&instance
->pdev
->dev
,
7896 "return -EBUSY from %s %d cmd 0x%x opcode 0x%x cmd->cmd_status_drv 0x%x\n",
7897 __func__
, __LINE__
, cmd
->frame
->hdr
.cmd
, opcode
,
7898 cmd
->cmd_status_drv
);
7904 if (instance
->unload
== 1) {
7905 dev_info(&instance
->pdev
->dev
, "Driver unload is in progress "
7906 "don't submit data to application\n");
7910 * copy out the kernel buffers to user buffers
7912 for (i
= 0; i
< ioc
->sge_count
; i
++) {
7913 if (copy_to_user(ioc
->sgl
[i
].iov_base
, kbuff_arr
[i
],
7914 ioc
->sgl
[i
].iov_len
)) {
7921 * copy out the sense
7923 if (ioc
->sense_len
) {
7925 * sense_ptr points to the location that has the user
7926 * sense buffer address
7928 sense_ptr
= (unsigned long *) ((unsigned long)ioc
->frame
.raw
+
7931 if (copy_to_user((void __user
*)((unsigned long)
7932 get_unaligned((unsigned long *)sense_ptr
)),
7933 sense
, ioc
->sense_len
)) {
7934 dev_err(&instance
->pdev
->dev
, "Failed to copy out to user "
7942 * copy the status codes returned by the fw
7944 if (copy_to_user(&user_ioc
->frame
.hdr
.cmd_status
,
7945 &cmd
->frame
->hdr
.cmd_status
, sizeof(u8
))) {
7946 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Error copying out cmd_status\n");
7952 dma_free_coherent(&instance
->pdev
->dev
, ioc
->sense_len
,
7953 sense
, sense_handle
);
7956 for (i
= 0; i
< ioc
->sge_count
; i
++) {
7958 if (instance
->consistent_mask_64bit
)
7959 dma_free_coherent(&instance
->pdev
->dev
,
7960 le32_to_cpu(kern_sge64
[i
].length
),
7962 le64_to_cpu(kern_sge64
[i
].phys_addr
));
7964 dma_free_coherent(&instance
->pdev
->dev
,
7965 le32_to_cpu(kern_sge32
[i
].length
),
7967 le32_to_cpu(kern_sge32
[i
].phys_addr
));
7968 kbuff_arr
[i
] = NULL
;
7972 megasas_return_cmd(instance
, cmd
);
7976 static int megasas_mgmt_ioctl_fw(struct file
*file
, unsigned long arg
)
7978 struct megasas_iocpacket __user
*user_ioc
=
7979 (struct megasas_iocpacket __user
*)arg
;
7980 struct megasas_iocpacket
*ioc
;
7981 struct megasas_instance
*instance
;
7984 ioc
= memdup_user(user_ioc
, sizeof(*ioc
));
7986 return PTR_ERR(ioc
);
7988 instance
= megasas_lookup_instance(ioc
->host_no
);
7994 /* Block ioctls in VF mode */
7995 if (instance
->requestorId
&& !allow_vf_ioctls
) {
8000 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
8001 dev_err(&instance
->pdev
->dev
, "Controller in crit error\n");
8006 if (instance
->unload
== 1) {
8011 if (down_interruptible(&instance
->ioctl_sem
)) {
8012 error
= -ERESTARTSYS
;
8016 if (megasas_wait_for_adapter_operational(instance
)) {
8021 error
= megasas_mgmt_fw_ioctl(instance
, user_ioc
, ioc
);
8023 up(&instance
->ioctl_sem
);
8030 static int megasas_mgmt_ioctl_aen(struct file
*file
, unsigned long arg
)
8032 struct megasas_instance
*instance
;
8033 struct megasas_aen aen
;
8036 if (file
->private_data
!= file
) {
8037 printk(KERN_DEBUG
"megasas: fasync_helper was not "
8042 if (copy_from_user(&aen
, (void __user
*)arg
, sizeof(aen
)))
8045 instance
= megasas_lookup_instance(aen
.host_no
);
8050 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
8054 if (instance
->unload
== 1) {
8058 if (megasas_wait_for_adapter_operational(instance
))
8061 mutex_lock(&instance
->reset_mutex
);
8062 error
= megasas_register_aen(instance
, aen
.seq_num
,
8063 aen
.class_locale_word
);
8064 mutex_unlock(&instance
->reset_mutex
);
8069 * megasas_mgmt_ioctl - char node ioctl entry point
8072 megasas_mgmt_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
8075 case MEGASAS_IOC_FIRMWARE
:
8076 return megasas_mgmt_ioctl_fw(file
, arg
);
8078 case MEGASAS_IOC_GET_AEN
:
8079 return megasas_mgmt_ioctl_aen(file
, arg
);
8085 #ifdef CONFIG_COMPAT
8086 static int megasas_mgmt_compat_ioctl_fw(struct file
*file
, unsigned long arg
)
8088 struct compat_megasas_iocpacket __user
*cioc
=
8089 (struct compat_megasas_iocpacket __user
*)arg
;
8090 struct megasas_iocpacket __user
*ioc
=
8091 compat_alloc_user_space(sizeof(struct megasas_iocpacket
));
8095 u32 local_sense_off
;
8096 u32 local_sense_len
;
8099 if (clear_user(ioc
, sizeof(*ioc
)))
8102 if (copy_in_user(&ioc
->host_no
, &cioc
->host_no
, sizeof(u16
)) ||
8103 copy_in_user(&ioc
->sgl_off
, &cioc
->sgl_off
, sizeof(u32
)) ||
8104 copy_in_user(&ioc
->sense_off
, &cioc
->sense_off
, sizeof(u32
)) ||
8105 copy_in_user(&ioc
->sense_len
, &cioc
->sense_len
, sizeof(u32
)) ||
8106 copy_in_user(ioc
->frame
.raw
, cioc
->frame
.raw
, 128) ||
8107 copy_in_user(&ioc
->sge_count
, &cioc
->sge_count
, sizeof(u32
)))
8111 * The sense_ptr is used in megasas_mgmt_fw_ioctl only when
8112 * sense_len is not null, so prepare the 64bit value under
8113 * the same condition.
8115 if (get_user(local_sense_off
, &ioc
->sense_off
) ||
8116 get_user(local_sense_len
, &ioc
->sense_len
) ||
8117 get_user(user_sense_off
, &cioc
->sense_off
))
8120 if (local_sense_off
!= user_sense_off
)
8123 if (local_sense_len
) {
8124 void __user
**sense_ioc_ptr
=
8125 (void __user
**)((u8
*)((unsigned long)&ioc
->frame
.raw
) + local_sense_off
);
8126 compat_uptr_t
*sense_cioc_ptr
=
8127 (compat_uptr_t
*)(((unsigned long)&cioc
->frame
.raw
) + user_sense_off
);
8128 if (get_user(ptr
, sense_cioc_ptr
) ||
8129 put_user(compat_ptr(ptr
), sense_ioc_ptr
))
8133 for (i
= 0; i
< MAX_IOCTL_SGE
; i
++) {
8134 if (get_user(ptr
, &cioc
->sgl
[i
].iov_base
) ||
8135 put_user(compat_ptr(ptr
), &ioc
->sgl
[i
].iov_base
) ||
8136 copy_in_user(&ioc
->sgl
[i
].iov_len
,
8137 &cioc
->sgl
[i
].iov_len
, sizeof(compat_size_t
)))
8141 error
= megasas_mgmt_ioctl_fw(file
, (unsigned long)ioc
);
8143 if (copy_in_user(&cioc
->frame
.hdr
.cmd_status
,
8144 &ioc
->frame
.hdr
.cmd_status
, sizeof(u8
))) {
8145 printk(KERN_DEBUG
"megasas: error copy_in_user cmd_status\n");
8152 megasas_mgmt_compat_ioctl(struct file
*file
, unsigned int cmd
,
8156 case MEGASAS_IOC_FIRMWARE32
:
8157 return megasas_mgmt_compat_ioctl_fw(file
, arg
);
8158 case MEGASAS_IOC_GET_AEN
:
8159 return megasas_mgmt_ioctl_aen(file
, arg
);
8167 * File operations structure for management interface
8169 static const struct file_operations megasas_mgmt_fops
= {
8170 .owner
= THIS_MODULE
,
8171 .open
= megasas_mgmt_open
,
8172 .fasync
= megasas_mgmt_fasync
,
8173 .unlocked_ioctl
= megasas_mgmt_ioctl
,
8174 .poll
= megasas_mgmt_poll
,
8175 #ifdef CONFIG_COMPAT
8176 .compat_ioctl
= megasas_mgmt_compat_ioctl
,
8178 .llseek
= noop_llseek
,
8182 * PCI hotplug support registration structure
8184 static struct pci_driver megasas_pci_driver
= {
8186 .name
= "megaraid_sas",
8187 .id_table
= megasas_pci_table
,
8188 .probe
= megasas_probe_one
,
8189 .remove
= megasas_detach_one
,
8190 .suspend
= megasas_suspend
,
8191 .resume
= megasas_resume
,
8192 .shutdown
= megasas_shutdown
,
8196 * Sysfs driver attributes
8198 static ssize_t
version_show(struct device_driver
*dd
, char *buf
)
8200 return snprintf(buf
, strlen(MEGASAS_VERSION
) + 2, "%s\n",
8203 static DRIVER_ATTR_RO(version
);
8205 static ssize_t
release_date_show(struct device_driver
*dd
, char *buf
)
8207 return snprintf(buf
, strlen(MEGASAS_RELDATE
) + 2, "%s\n",
8210 static DRIVER_ATTR_RO(release_date
);
8212 static ssize_t
support_poll_for_event_show(struct device_driver
*dd
, char *buf
)
8214 return sprintf(buf
, "%u\n", support_poll_for_event
);
8216 static DRIVER_ATTR_RO(support_poll_for_event
);
8218 static ssize_t
support_device_change_show(struct device_driver
*dd
, char *buf
)
8220 return sprintf(buf
, "%u\n", support_device_change
);
8222 static DRIVER_ATTR_RO(support_device_change
);
8224 static ssize_t
dbg_lvl_show(struct device_driver
*dd
, char *buf
)
8226 return sprintf(buf
, "%u\n", megasas_dbg_lvl
);
8229 static ssize_t
dbg_lvl_store(struct device_driver
*dd
, const char *buf
,
8234 if (sscanf(buf
, "%u", &megasas_dbg_lvl
) < 1) {
8235 printk(KERN_ERR
"megasas: could not set dbg_lvl\n");
8240 static DRIVER_ATTR_RW(dbg_lvl
);
8243 support_nvme_encapsulation_show(struct device_driver
*dd
, char *buf
)
8245 return sprintf(buf
, "%u\n", support_nvme_encapsulation
);
8248 static DRIVER_ATTR_RO(support_nvme_encapsulation
);
8250 static inline void megasas_remove_scsi_device(struct scsi_device
*sdev
)
8252 sdev_printk(KERN_INFO
, sdev
, "SCSI device is removed\n");
8253 scsi_remove_device(sdev
);
8254 scsi_device_put(sdev
);
8258 * megasas_update_device_list - Update the PD and LD device list from FW
8259 * after an AEN event notification
8260 * @instance: Adapter soft state
8261 * @event_type: Indicates type of event (PD or LD event)
8263 * @return: Success or failure
8265 * Issue DCMDs to Firmware to update the internal device list in driver.
8266 * Based on the FW support, driver sends the HOST_DEVICE_LIST or combination
8267 * of PD_LIST/LD_LIST_QUERY DCMDs to get the device list.
8270 int megasas_update_device_list(struct megasas_instance
*instance
,
8273 int dcmd_ret
= DCMD_SUCCESS
;
8275 if (instance
->enable_fw_dev_list
) {
8276 dcmd_ret
= megasas_host_device_list_query(instance
, false);
8277 if (dcmd_ret
!= DCMD_SUCCESS
)
8280 if (event_type
& SCAN_PD_CHANNEL
) {
8281 dcmd_ret
= megasas_get_pd_list(instance
);
8283 if (dcmd_ret
!= DCMD_SUCCESS
)
8287 if (event_type
& SCAN_VD_CHANNEL
) {
8288 if (!instance
->requestorId
||
8289 (instance
->requestorId
&&
8290 megasas_get_ld_vf_affiliation(instance
, 0))) {
8291 dcmd_ret
= megasas_ld_list_query(instance
,
8292 MR_LD_QUERY_TYPE_EXPOSED_TO_HOST
);
8293 if (dcmd_ret
!= DCMD_SUCCESS
)
8304 * megasas_add_remove_devices - Add/remove devices to SCSI mid-layer
8305 * after an AEN event notification
8306 * @instance: Adapter soft state
8307 * @scan_type: Indicates type of devices (PD/LD) to add
8311 void megasas_add_remove_devices(struct megasas_instance
*instance
,
8317 u16 channel
= 0, id
= 0;
8318 struct Scsi_Host
*host
;
8319 struct scsi_device
*sdev1
;
8320 struct MR_HOST_DEVICE_LIST
*targetid_list
= NULL
;
8321 struct MR_HOST_DEVICE_LIST_ENTRY
*targetid_entry
= NULL
;
8323 host
= instance
->host
;
8325 if (instance
->enable_fw_dev_list
) {
8326 targetid_list
= instance
->host_device_list_buf
;
8327 for (i
= 0; i
< targetid_list
->count
; i
++) {
8328 targetid_entry
= &targetid_list
->host_device_list
[i
];
8329 if (targetid_entry
->flags
.u
.bits
.is_sys_pd
) {
8330 channel
= le16_to_cpu(targetid_entry
->target_id
) /
8331 MEGASAS_MAX_DEV_PER_CHANNEL
;
8332 id
= le16_to_cpu(targetid_entry
->target_id
) %
8333 MEGASAS_MAX_DEV_PER_CHANNEL
;
8335 channel
= MEGASAS_MAX_PD_CHANNELS
+
8336 (le16_to_cpu(targetid_entry
->target_id
) /
8337 MEGASAS_MAX_DEV_PER_CHANNEL
);
8338 id
= le16_to_cpu(targetid_entry
->target_id
) %
8339 MEGASAS_MAX_DEV_PER_CHANNEL
;
8341 sdev1
= scsi_device_lookup(host
, channel
, id
, 0);
8343 scsi_add_device(host
, channel
, id
, 0);
8345 scsi_device_put(sdev1
);
8350 if (scan_type
& SCAN_PD_CHANNEL
) {
8351 for (i
= 0; i
< MEGASAS_MAX_PD_CHANNELS
; i
++) {
8352 for (j
= 0; j
< MEGASAS_MAX_DEV_PER_CHANNEL
; j
++) {
8353 pd_index
= i
* MEGASAS_MAX_DEV_PER_CHANNEL
+ j
;
8354 sdev1
= scsi_device_lookup(host
, i
, j
, 0);
8355 if (instance
->pd_list
[pd_index
].driveState
==
8356 MR_PD_STATE_SYSTEM
) {
8358 scsi_add_device(host
, i
, j
, 0);
8360 scsi_device_put(sdev1
);
8363 megasas_remove_scsi_device(sdev1
);
8369 if (scan_type
& SCAN_VD_CHANNEL
) {
8370 for (i
= 0; i
< MEGASAS_MAX_LD_CHANNELS
; i
++) {
8371 for (j
= 0; j
< MEGASAS_MAX_DEV_PER_CHANNEL
; j
++) {
8372 ld_index
= (i
* MEGASAS_MAX_DEV_PER_CHANNEL
) + j
;
8373 sdev1
= scsi_device_lookup(host
,
8374 MEGASAS_MAX_PD_CHANNELS
+ i
, j
, 0);
8375 if (instance
->ld_ids
[ld_index
] != 0xff) {
8377 scsi_add_device(host
, MEGASAS_MAX_PD_CHANNELS
+ i
, j
, 0);
8379 scsi_device_put(sdev1
);
8382 megasas_remove_scsi_device(sdev1
);
8391 megasas_aen_polling(struct work_struct
*work
)
8393 struct megasas_aen_event
*ev
=
8394 container_of(work
, struct megasas_aen_event
, hotplug_work
.work
);
8395 struct megasas_instance
*instance
= ev
->instance
;
8396 union megasas_evt_class_locale class_locale
;
8398 u32 seq_num
, wait_time
= MEGASAS_RESET_WAIT_TIME
;
8400 u8 dcmd_ret
= DCMD_SUCCESS
;
8403 printk(KERN_ERR
"invalid instance!\n");
8408 /* Adjust event workqueue thread wait time for VF mode */
8409 if (instance
->requestorId
)
8410 wait_time
= MEGASAS_ROUTINE_WAIT_TIME_VF
;
8412 /* Don't run the event workqueue thread if OCR is running */
8413 mutex_lock(&instance
->reset_mutex
);
8415 instance
->ev
= NULL
;
8416 if (instance
->evt_detail
) {
8417 megasas_decode_evt(instance
);
8419 switch (le32_to_cpu(instance
->evt_detail
->code
)) {
8421 case MR_EVT_PD_INSERTED
:
8422 case MR_EVT_PD_REMOVED
:
8423 event_type
= SCAN_PD_CHANNEL
;
8426 case MR_EVT_LD_OFFLINE
:
8427 case MR_EVT_CFG_CLEARED
:
8428 case MR_EVT_LD_DELETED
:
8429 case MR_EVT_LD_CREATED
:
8430 event_type
= SCAN_VD_CHANNEL
;
8433 case MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED
:
8434 case MR_EVT_FOREIGN_CFG_IMPORTED
:
8435 case MR_EVT_LD_STATE_CHANGE
:
8436 event_type
= SCAN_PD_CHANNEL
| SCAN_VD_CHANNEL
;
8437 dev_info(&instance
->pdev
->dev
, "scanning for scsi%d...\n",
8438 instance
->host
->host_no
);
8441 case MR_EVT_CTRL_PROP_CHANGED
:
8442 dcmd_ret
= megasas_get_ctrl_info(instance
);
8443 if (dcmd_ret
== DCMD_SUCCESS
&&
8444 instance
->snapdump_wait_time
) {
8445 megasas_get_snapdump_properties(instance
);
8446 dev_info(&instance
->pdev
->dev
,
8447 "Snap dump wait time\t: %d\n",
8448 instance
->snapdump_wait_time
);
8456 dev_err(&instance
->pdev
->dev
, "invalid evt_detail!\n");
8457 mutex_unlock(&instance
->reset_mutex
);
8463 dcmd_ret
= megasas_update_device_list(instance
, event_type
);
8465 mutex_unlock(&instance
->reset_mutex
);
8467 if (event_type
&& dcmd_ret
== DCMD_SUCCESS
)
8468 megasas_add_remove_devices(instance
, event_type
);
8470 if (dcmd_ret
== DCMD_SUCCESS
)
8471 seq_num
= le32_to_cpu(instance
->evt_detail
->seq_num
) + 1;
8473 seq_num
= instance
->last_seq_num
;
8475 /* Register AEN with FW for latest sequence number plus 1 */
8476 class_locale
.members
.reserved
= 0;
8477 class_locale
.members
.locale
= MR_EVT_LOCALE_ALL
;
8478 class_locale
.members
.class = MR_EVT_CLASS_DEBUG
;
8480 if (instance
->aen_cmd
!= NULL
) {
8485 mutex_lock(&instance
->reset_mutex
);
8486 error
= megasas_register_aen(instance
, seq_num
,
8489 dev_err(&instance
->pdev
->dev
,
8490 "register aen failed error %x\n", error
);
8492 mutex_unlock(&instance
->reset_mutex
);
8497 * megasas_init - Driver load entry point
8499 static int __init
megasas_init(void)
8504 * Booted in kdump kernel, minimize memory footprints by
8505 * disabling few features
8507 if (reset_devices
) {
8510 dual_qdepth_disable
= 1;
8514 * Announce driver version and other information
8516 pr_info("megasas: %s\n", MEGASAS_VERSION
);
8518 spin_lock_init(&poll_aen_lock
);
8520 support_poll_for_event
= 2;
8521 support_device_change
= 1;
8522 support_nvme_encapsulation
= true;
8524 memset(&megasas_mgmt_info
, 0, sizeof(megasas_mgmt_info
));
8527 * Register character device node
8529 rval
= register_chrdev(0, "megaraid_sas_ioctl", &megasas_mgmt_fops
);
8532 printk(KERN_DEBUG
"megasas: failed to open device node\n");
8536 megasas_mgmt_majorno
= rval
;
8538 megasas_init_debugfs();
8541 * Register ourselves as PCI hotplug module
8543 rval
= pci_register_driver(&megasas_pci_driver
);
8546 printk(KERN_DEBUG
"megasas: PCI hotplug registration failed \n");
8550 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8551 &driver_attr_version
);
8553 goto err_dcf_attr_ver
;
8555 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8556 &driver_attr_release_date
);
8558 goto err_dcf_rel_date
;
8560 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8561 &driver_attr_support_poll_for_event
);
8563 goto err_dcf_support_poll_for_event
;
8565 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8566 &driver_attr_dbg_lvl
);
8568 goto err_dcf_dbg_lvl
;
8569 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8570 &driver_attr_support_device_change
);
8572 goto err_dcf_support_device_change
;
8574 rval
= driver_create_file(&megasas_pci_driver
.driver
,
8575 &driver_attr_support_nvme_encapsulation
);
8577 goto err_dcf_support_nvme_encapsulation
;
8581 err_dcf_support_nvme_encapsulation
:
8582 driver_remove_file(&megasas_pci_driver
.driver
,
8583 &driver_attr_support_device_change
);
8585 err_dcf_support_device_change
:
8586 driver_remove_file(&megasas_pci_driver
.driver
,
8587 &driver_attr_dbg_lvl
);
8589 driver_remove_file(&megasas_pci_driver
.driver
,
8590 &driver_attr_support_poll_for_event
);
8591 err_dcf_support_poll_for_event
:
8592 driver_remove_file(&megasas_pci_driver
.driver
,
8593 &driver_attr_release_date
);
8595 driver_remove_file(&megasas_pci_driver
.driver
, &driver_attr_version
);
8597 pci_unregister_driver(&megasas_pci_driver
);
8599 megasas_exit_debugfs();
8600 unregister_chrdev(megasas_mgmt_majorno
, "megaraid_sas_ioctl");
8605 * megasas_exit - Driver unload entry point
8607 static void __exit
megasas_exit(void)
8609 driver_remove_file(&megasas_pci_driver
.driver
,
8610 &driver_attr_dbg_lvl
);
8611 driver_remove_file(&megasas_pci_driver
.driver
,
8612 &driver_attr_support_poll_for_event
);
8613 driver_remove_file(&megasas_pci_driver
.driver
,
8614 &driver_attr_support_device_change
);
8615 driver_remove_file(&megasas_pci_driver
.driver
,
8616 &driver_attr_release_date
);
8617 driver_remove_file(&megasas_pci_driver
.driver
, &driver_attr_version
);
8618 driver_remove_file(&megasas_pci_driver
.driver
,
8619 &driver_attr_support_nvme_encapsulation
);
8621 pci_unregister_driver(&megasas_pci_driver
);
8622 megasas_exit_debugfs();
8623 unregister_chrdev(megasas_mgmt_majorno
, "megaraid_sas_ioctl");
8626 module_init(megasas_init
);
8627 module_exit(megasas_exit
);