1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux MegaRAID driver for SAS based RAID controllers
5 * Copyright (c) 2009-2013 LSI Corporation
6 * Copyright (c) 2013-2016 Avago Technologies
7 * Copyright (c) 2016-2018 Broadcom Inc.
9 * FILE: megaraid_sas_fusion.c
11 * Authors: Broadcom Inc.
14 * Kashyap Desai <kashyap.desai@broadcom.com>
15 * Sumit Saxena <sumit.saxena@broadcom.com>
17 * Send feedback to: megaraidlinux.pdl@broadcom.com
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/list.h>
24 #include <linux/moduleparam.h>
25 #include <linux/module.h>
26 #include <linux/spinlock.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
29 #include <linux/uio.h>
30 #include <linux/uaccess.h>
32 #include <linux/compat.h>
33 #include <linux/blkdev.h>
34 #include <linux/mutex.h>
35 #include <linux/poll.h>
36 #include <linux/vmalloc.h>
37 #include <linux/workqueue.h>
38 #include <linux/irq_poll.h>
40 #include <scsi/scsi.h>
41 #include <scsi/scsi_cmnd.h>
42 #include <scsi/scsi_device.h>
43 #include <scsi/scsi_host.h>
44 #include <scsi/scsi_dbg.h>
45 #include <linux/dmi.h>
47 #include "megaraid_sas_fusion.h"
48 #include "megaraid_sas.h"
51 extern void megasas_free_cmds(struct megasas_instance *instance);
52 extern struct megasas_cmd *megasas_get_cmd(struct megasas_instance
55 megasas_complete_cmd(struct megasas_instance *instance,
56 struct megasas_cmd *cmd, u8 alt_status);
58 wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd,
62 megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd);
63 int megasas_alloc_cmds(struct megasas_instance *instance);
65 megasas_clear_intr_fusion(struct megasas_instance *instance);
67 megasas_issue_polled(struct megasas_instance *instance,
68 struct megasas_cmd *cmd);
70 megasas_check_and_restore_queue_depth(struct megasas_instance *instance);
72 int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
73 void megaraid_sas_kill_hba(struct megasas_instance *instance);
75 extern u32 megasas_dbg_lvl;
76 int megasas_sriov_start_heartbeat(struct megasas_instance *instance,
78 void megasas_start_timer(struct megasas_instance *instance);
79 extern struct megasas_mgmt_info megasas_mgmt_info;
80 extern unsigned int resetwaittime;
81 extern unsigned int dual_qdepth_disable;
82 static void megasas_free_rdpq_fusion(struct megasas_instance *instance);
83 static void megasas_free_reply_fusion(struct megasas_instance *instance);
85 void megasas_configure_queue_sizes(struct megasas_instance *instance);
86 static void megasas_fusion_crash_dump(struct megasas_instance *instance);
87 extern u32 megasas_readl(struct megasas_instance *instance,
88 const volatile void __iomem *addr);
91 * megasas_adp_reset_wait_for_ready - initiate chip reset and wait for
92 * controller to come to ready state
93 * @instance - adapter's soft state
94 * @do_adp_reset - If true, do a chip reset
95 * @ocr_context - If called from OCR context this will
98 * This function initates a chip reset followed by a wait for controller to
99 * transition to ready state.
100 * During this, driver will block all access to PCI config space from userspace
103 megasas_adp_reset_wait_for_ready(struct megasas_instance *instance,
110 * Block access to PCI config space from userspace
111 * when diag reset is initiated from driver
113 if (megasas_dbg_lvl & OCR_DEBUG)
114 dev_info(&instance->pdev->dev,
115 "Block access to PCI config space %s %d\n",
118 pci_cfg_access_lock(instance->pdev);
121 if (instance->instancet->adp_reset
122 (instance, instance->reg_set))
126 /* Wait for FW to become ready */
127 if (megasas_transition_to_ready(instance, ocr_context)) {
128 dev_warn(&instance->pdev->dev,
129 "Failed to transition controller to ready for scsi%d.\n",
130 instance->host->host_no);
136 if (megasas_dbg_lvl & OCR_DEBUG)
137 dev_info(&instance->pdev->dev,
138 "Unlock access to PCI config space %s %d\n",
141 pci_cfg_access_unlock(instance->pdev);
147 * megasas_check_same_4gb_region - check if allocation
148 * crosses same 4GB boundary or not
149 * @instance - adapter's soft instance
150 * start_addr - start address of DMA allocation
151 * size - size of allocation in bytes
152 * return - true : allocation does not cross same
154 * false: allocation crosses same
157 static inline bool megasas_check_same_4gb_region
158 (struct megasas_instance *instance, dma_addr_t start_addr, size_t size)
162 end_addr = start_addr + size;
164 if (upper_32_bits(start_addr) != upper_32_bits(end_addr)) {
165 dev_err(&instance->pdev->dev,
166 "Failed to get same 4GB boundary: start_addr: 0x%llx end_addr: 0x%llx\n",
167 (unsigned long long)start_addr,
168 (unsigned long long)end_addr);
176 * megasas_enable_intr_fusion - Enables interrupts
177 * @regs: MFI register set
180 megasas_enable_intr_fusion(struct megasas_instance *instance)
182 struct megasas_register_set __iomem *regs;
183 regs = instance->reg_set;
185 instance->mask_interrupts = 0;
186 /* For Thunderbolt/Invader also clear intr on enable */
187 writel(~0, ®s->outbound_intr_status);
188 readl(®s->outbound_intr_status);
190 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
192 /* Dummy readl to force pci flush */
193 dev_info(&instance->pdev->dev, "%s is called outbound_intr_mask:0x%08x\n",
194 __func__, readl(®s->outbound_intr_mask));
198 * megasas_disable_intr_fusion - Disables interrupt
199 * @regs: MFI register set
202 megasas_disable_intr_fusion(struct megasas_instance *instance)
204 u32 mask = 0xFFFFFFFF;
205 struct megasas_register_set __iomem *regs;
206 regs = instance->reg_set;
207 instance->mask_interrupts = 1;
209 writel(mask, ®s->outbound_intr_mask);
210 /* Dummy readl to force pci flush */
211 dev_info(&instance->pdev->dev, "%s is called outbound_intr_mask:0x%08x\n",
212 __func__, readl(®s->outbound_intr_mask));
216 megasas_clear_intr_fusion(struct megasas_instance *instance)
219 struct megasas_register_set __iomem *regs;
220 regs = instance->reg_set;
222 * Check if it is our interrupt
224 status = megasas_readl(instance,
225 ®s->outbound_intr_status);
228 writel(status, ®s->outbound_intr_status);
229 readl(®s->outbound_intr_status);
232 if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
239 * megasas_get_cmd_fusion - Get a command from the free pool
240 * @instance: Adapter soft state
242 * Returns a blk_tag indexed mpt frame
244 inline struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance
245 *instance, u32 blk_tag)
247 struct fusion_context *fusion;
249 fusion = instance->ctrl_context;
250 return fusion->cmd_list[blk_tag];
254 * megasas_return_cmd_fusion - Return a cmd to free command pool
255 * @instance: Adapter soft state
256 * @cmd: Command packet to be returned to free command pool
258 inline void megasas_return_cmd_fusion(struct megasas_instance *instance,
259 struct megasas_cmd_fusion *cmd)
262 memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
263 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
264 cmd->cmd_completed = false;
268 * megasas_write_64bit_req_desc - PCI writes 64bit request descriptor
269 * @instance: Adapter soft state
270 * @req_desc: 64bit Request descriptor
273 megasas_write_64bit_req_desc(struct megasas_instance *instance,
274 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
276 #if defined(writeq) && defined(CONFIG_64BIT)
277 u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
278 le32_to_cpu(req_desc->u.low));
279 writeq(req_data, &instance->reg_set->inbound_low_queue_port);
282 spin_lock_irqsave(&instance->hba_lock, flags);
283 writel(le32_to_cpu(req_desc->u.low),
284 &instance->reg_set->inbound_low_queue_port);
285 writel(le32_to_cpu(req_desc->u.high),
286 &instance->reg_set->inbound_high_queue_port);
287 spin_unlock_irqrestore(&instance->hba_lock, flags);
292 * megasas_fire_cmd_fusion - Sends command to the FW
293 * @instance: Adapter soft state
294 * @req_desc: 32bit or 64bit Request descriptor
296 * Perform PCI Write. AERO SERIES supports 32 bit Descriptor.
297 * Prior to AERO_SERIES support 64 bit Descriptor.
300 megasas_fire_cmd_fusion(struct megasas_instance *instance,
301 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
303 if (instance->atomic_desc_support)
304 writel(le32_to_cpu(req_desc->u.low),
305 &instance->reg_set->inbound_single_queue_port);
307 megasas_write_64bit_req_desc(instance, req_desc);
311 * megasas_fusion_update_can_queue - Do all Adapter Queue depth related calculations here
312 * @instance: Adapter soft state
313 * fw_boot_context: Whether this function called during probe or after OCR
315 * This function is only for fusion controllers.
316 * Update host can queue, if firmware downgrade max supported firmware commands.
317 * Firmware upgrade case will be skiped because underlying firmware has
318 * more resource than exposed to the OS.
322 megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_context)
324 u16 cur_max_fw_cmds = 0;
325 u16 ldio_threshold = 0;
327 /* ventura FW does not fill outbound_scratch_pad_2 with queue depth */
328 if (instance->adapter_type < VENTURA_SERIES)
330 megasas_readl(instance,
331 &instance->reg_set->outbound_scratch_pad_2) & 0x00FFFF;
333 if (dual_qdepth_disable || !cur_max_fw_cmds)
334 cur_max_fw_cmds = instance->instancet->read_fw_status_reg(instance) & 0x00FFFF;
337 (instance->instancet->read_fw_status_reg(instance) & 0x00FFFF) - MEGASAS_FUSION_IOCTL_CMDS;
339 dev_info(&instance->pdev->dev,
340 "Current firmware supports maximum commands: %d\t LDIO threshold: %d\n",
341 cur_max_fw_cmds, ldio_threshold);
343 if (fw_boot_context == OCR_CONTEXT) {
344 cur_max_fw_cmds = cur_max_fw_cmds - 1;
345 if (cur_max_fw_cmds < instance->max_fw_cmds) {
346 instance->cur_can_queue =
347 cur_max_fw_cmds - (MEGASAS_FUSION_INTERNAL_CMDS +
348 MEGASAS_FUSION_IOCTL_CMDS);
349 instance->host->can_queue = instance->cur_can_queue;
350 instance->ldio_threshold = ldio_threshold;
353 instance->max_fw_cmds = cur_max_fw_cmds;
354 instance->ldio_threshold = ldio_threshold;
357 instance->max_fw_cmds = min(instance->max_fw_cmds,
358 (u16)MEGASAS_KDUMP_QUEUE_DEPTH);
360 * Reduce the max supported cmds by 1. This is to ensure that the
361 * reply_q_sz (1 more than the max cmd that driver may send)
362 * does not exceed max cmds that the FW can support
364 instance->max_fw_cmds = instance->max_fw_cmds-1;
369 megasas_get_msix_index(struct megasas_instance *instance,
370 struct scsi_cmnd *scmd,
371 struct megasas_cmd_fusion *cmd,
376 /* nr_hw_queue = 1 for MegaRAID */
377 struct blk_mq_hw_ctx *hctx =
378 scmd->device->request_queue->queue_hw_ctx[0];
380 sdev_busy = atomic_read(&hctx->nr_active);
382 if (instance->perf_mode == MR_BALANCED_PERF_MODE &&
383 sdev_busy > (data_arms * MR_DEVICE_HIGH_IOPS_DEPTH))
384 cmd->request_desc->SCSIIO.MSIxIndex =
385 mega_mod64((atomic64_add_return(1, &instance->high_iops_outstanding) /
386 MR_HIGH_IOPS_BATCH_COUNT), instance->low_latency_index_start);
387 else if (instance->msix_load_balance)
388 cmd->request_desc->SCSIIO.MSIxIndex =
389 (mega_mod64(atomic64_add_return(1, &instance->total_io_count),
390 instance->msix_vectors));
392 cmd->request_desc->SCSIIO.MSIxIndex =
393 instance->reply_map[raw_smp_processor_id()];
397 * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
398 * @instance: Adapter soft state
401 megasas_free_cmds_fusion(struct megasas_instance *instance)
404 struct fusion_context *fusion = instance->ctrl_context;
405 struct megasas_cmd_fusion *cmd;
408 dma_pool_free(fusion->sense_dma_pool, fusion->sense,
409 fusion->sense_phys_addr);
412 if (fusion->cmd_list) {
413 for (i = 0; i < instance->max_mpt_cmds; i++) {
414 cmd = fusion->cmd_list[i];
417 dma_pool_free(fusion->sg_dma_pool,
419 cmd->sg_frame_phys_addr);
423 kfree(fusion->cmd_list);
426 if (fusion->sg_dma_pool) {
427 dma_pool_destroy(fusion->sg_dma_pool);
428 fusion->sg_dma_pool = NULL;
430 if (fusion->sense_dma_pool) {
431 dma_pool_destroy(fusion->sense_dma_pool);
432 fusion->sense_dma_pool = NULL;
436 /* Reply Frame, Desc*/
437 if (instance->is_rdpq)
438 megasas_free_rdpq_fusion(instance);
440 megasas_free_reply_fusion(instance);
442 /* Request Frame, Desc*/
443 if (fusion->req_frames_desc)
444 dma_free_coherent(&instance->pdev->dev,
445 fusion->request_alloc_sz, fusion->req_frames_desc,
446 fusion->req_frames_desc_phys);
447 if (fusion->io_request_frames)
448 dma_pool_free(fusion->io_request_frames_pool,
449 fusion->io_request_frames,
450 fusion->io_request_frames_phys);
451 if (fusion->io_request_frames_pool) {
452 dma_pool_destroy(fusion->io_request_frames_pool);
453 fusion->io_request_frames_pool = NULL;
458 * megasas_create_sg_sense_fusion - Creates DMA pool for cmd frames
459 * @instance: Adapter soft state
462 static int megasas_create_sg_sense_fusion(struct megasas_instance *instance)
466 struct fusion_context *fusion;
467 struct megasas_cmd_fusion *cmd;
471 fusion = instance->ctrl_context;
472 max_cmd = instance->max_fw_cmds;
473 sense_sz = instance->max_mpt_cmds * SCSI_SENSE_BUFFERSIZE;
475 fusion->sg_dma_pool =
476 dma_pool_create("mr_sg", &instance->pdev->dev,
477 instance->max_chain_frame_sz,
478 MR_DEFAULT_NVME_PAGE_SIZE, 0);
479 /* SCSI_SENSE_BUFFERSIZE = 96 bytes */
480 fusion->sense_dma_pool =
481 dma_pool_create("mr_sense", &instance->pdev->dev,
484 if (!fusion->sense_dma_pool || !fusion->sg_dma_pool) {
485 dev_err(&instance->pdev->dev,
486 "Failed from %s %d\n", __func__, __LINE__);
490 fusion->sense = dma_pool_alloc(fusion->sense_dma_pool,
491 GFP_KERNEL, &fusion->sense_phys_addr);
492 if (!fusion->sense) {
493 dev_err(&instance->pdev->dev,
494 "failed from %s %d\n", __func__, __LINE__);
498 /* sense buffer, request frame and reply desc pool requires to be in
499 * same 4 gb region. Below function will check this.
500 * In case of failure, new pci pool will be created with updated
502 * Older allocation and pool will be destroyed.
503 * Alignment will be used such a way that next allocation if success,
504 * will always meet same 4gb region requirement.
505 * Actual requirement is not alignment, but we need start and end of
506 * DMA address must have same upper 32 bit address.
509 if (!megasas_check_same_4gb_region(instance, fusion->sense_phys_addr,
511 dma_pool_free(fusion->sense_dma_pool, fusion->sense,
512 fusion->sense_phys_addr);
513 fusion->sense = NULL;
514 dma_pool_destroy(fusion->sense_dma_pool);
516 fusion->sense_dma_pool =
517 dma_pool_create("mr_sense_align", &instance->pdev->dev,
518 sense_sz, roundup_pow_of_two(sense_sz),
520 if (!fusion->sense_dma_pool) {
521 dev_err(&instance->pdev->dev,
522 "Failed from %s %d\n", __func__, __LINE__);
525 fusion->sense = dma_pool_alloc(fusion->sense_dma_pool,
527 &fusion->sense_phys_addr);
528 if (!fusion->sense) {
529 dev_err(&instance->pdev->dev,
530 "failed from %s %d\n", __func__, __LINE__);
536 * Allocate and attach a frame to each of the commands in cmd_list
538 for (i = 0; i < max_cmd; i++) {
539 cmd = fusion->cmd_list[i];
540 cmd->sg_frame = dma_pool_alloc(fusion->sg_dma_pool,
541 GFP_KERNEL, &cmd->sg_frame_phys_addr);
543 offset = SCSI_SENSE_BUFFERSIZE * i;
544 cmd->sense = (u8 *)fusion->sense + offset;
545 cmd->sense_phys_addr = fusion->sense_phys_addr + offset;
547 if (!cmd->sg_frame) {
548 dev_err(&instance->pdev->dev,
549 "Failed from %s %d\n", __func__, __LINE__);
554 /* create sense buffer for the raid 1/10 fp */
555 for (i = max_cmd; i < instance->max_mpt_cmds; i++) {
556 cmd = fusion->cmd_list[i];
557 offset = SCSI_SENSE_BUFFERSIZE * i;
558 cmd->sense = (u8 *)fusion->sense + offset;
559 cmd->sense_phys_addr = fusion->sense_phys_addr + offset;
567 megasas_alloc_cmdlist_fusion(struct megasas_instance *instance)
569 u32 max_mpt_cmd, i, j;
570 struct fusion_context *fusion;
572 fusion = instance->ctrl_context;
574 max_mpt_cmd = instance->max_mpt_cmds;
577 * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
578 * Allocate the dynamic array first and then allocate individual
582 kcalloc(max_mpt_cmd, sizeof(struct megasas_cmd_fusion *),
584 if (!fusion->cmd_list) {
585 dev_err(&instance->pdev->dev,
586 "Failed from %s %d\n", __func__, __LINE__);
590 for (i = 0; i < max_mpt_cmd; i++) {
591 fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion),
593 if (!fusion->cmd_list[i]) {
594 for (j = 0; j < i; j++)
595 kfree(fusion->cmd_list[j]);
596 kfree(fusion->cmd_list);
597 dev_err(&instance->pdev->dev,
598 "Failed from %s %d\n", __func__, __LINE__);
607 megasas_alloc_request_fusion(struct megasas_instance *instance)
609 struct fusion_context *fusion;
611 fusion = instance->ctrl_context;
614 fusion->io_request_frames_pool =
615 dma_pool_create("mr_ioreq", &instance->pdev->dev,
616 fusion->io_frames_alloc_sz, 16, 0);
618 if (!fusion->io_request_frames_pool) {
619 dev_err(&instance->pdev->dev,
620 "Failed from %s %d\n", __func__, __LINE__);
624 fusion->io_request_frames =
625 dma_pool_alloc(fusion->io_request_frames_pool,
626 GFP_KERNEL | __GFP_NOWARN,
627 &fusion->io_request_frames_phys);
628 if (!fusion->io_request_frames) {
629 if (instance->max_fw_cmds >= (MEGASAS_REDUCE_QD_COUNT * 2)) {
630 instance->max_fw_cmds -= MEGASAS_REDUCE_QD_COUNT;
631 dma_pool_destroy(fusion->io_request_frames_pool);
632 megasas_configure_queue_sizes(instance);
635 dev_err(&instance->pdev->dev,
636 "Failed from %s %d\n", __func__, __LINE__);
641 if (!megasas_check_same_4gb_region(instance,
642 fusion->io_request_frames_phys,
643 fusion->io_frames_alloc_sz)) {
644 dma_pool_free(fusion->io_request_frames_pool,
645 fusion->io_request_frames,
646 fusion->io_request_frames_phys);
647 fusion->io_request_frames = NULL;
648 dma_pool_destroy(fusion->io_request_frames_pool);
650 fusion->io_request_frames_pool =
651 dma_pool_create("mr_ioreq_align",
652 &instance->pdev->dev,
653 fusion->io_frames_alloc_sz,
654 roundup_pow_of_two(fusion->io_frames_alloc_sz),
657 if (!fusion->io_request_frames_pool) {
658 dev_err(&instance->pdev->dev,
659 "Failed from %s %d\n", __func__, __LINE__);
663 fusion->io_request_frames =
664 dma_pool_alloc(fusion->io_request_frames_pool,
665 GFP_KERNEL | __GFP_NOWARN,
666 &fusion->io_request_frames_phys);
668 if (!fusion->io_request_frames) {
669 dev_err(&instance->pdev->dev,
670 "Failed from %s %d\n", __func__, __LINE__);
675 fusion->req_frames_desc =
676 dma_alloc_coherent(&instance->pdev->dev,
677 fusion->request_alloc_sz,
678 &fusion->req_frames_desc_phys, GFP_KERNEL);
679 if (!fusion->req_frames_desc) {
680 dev_err(&instance->pdev->dev,
681 "Failed from %s %d\n", __func__, __LINE__);
689 megasas_alloc_reply_fusion(struct megasas_instance *instance)
692 struct fusion_context *fusion;
693 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
694 fusion = instance->ctrl_context;
696 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
697 fusion->reply_frames_desc_pool =
698 dma_pool_create("mr_reply", &instance->pdev->dev,
699 fusion->reply_alloc_sz * count, 16, 0);
701 if (!fusion->reply_frames_desc_pool) {
702 dev_err(&instance->pdev->dev,
703 "Failed from %s %d\n", __func__, __LINE__);
707 fusion->reply_frames_desc[0] =
708 dma_pool_alloc(fusion->reply_frames_desc_pool,
709 GFP_KERNEL, &fusion->reply_frames_desc_phys[0]);
710 if (!fusion->reply_frames_desc[0]) {
711 dev_err(&instance->pdev->dev,
712 "Failed from %s %d\n", __func__, __LINE__);
716 if (!megasas_check_same_4gb_region(instance,
717 fusion->reply_frames_desc_phys[0],
718 (fusion->reply_alloc_sz * count))) {
719 dma_pool_free(fusion->reply_frames_desc_pool,
720 fusion->reply_frames_desc[0],
721 fusion->reply_frames_desc_phys[0]);
722 fusion->reply_frames_desc[0] = NULL;
723 dma_pool_destroy(fusion->reply_frames_desc_pool);
725 fusion->reply_frames_desc_pool =
726 dma_pool_create("mr_reply_align",
727 &instance->pdev->dev,
728 fusion->reply_alloc_sz * count,
729 roundup_pow_of_two(fusion->reply_alloc_sz * count),
732 if (!fusion->reply_frames_desc_pool) {
733 dev_err(&instance->pdev->dev,
734 "Failed from %s %d\n", __func__, __LINE__);
738 fusion->reply_frames_desc[0] =
739 dma_pool_alloc(fusion->reply_frames_desc_pool,
741 &fusion->reply_frames_desc_phys[0]);
743 if (!fusion->reply_frames_desc[0]) {
744 dev_err(&instance->pdev->dev,
745 "Failed from %s %d\n", __func__, __LINE__);
750 reply_desc = fusion->reply_frames_desc[0];
751 for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++)
752 reply_desc->Words = cpu_to_le64(ULLONG_MAX);
754 /* This is not a rdpq mode, but driver still populate
755 * reply_frame_desc array to use same msix index in ISR path.
757 for (i = 0; i < (count - 1); i++)
758 fusion->reply_frames_desc[i + 1] =
759 fusion->reply_frames_desc[i] +
760 (fusion->reply_alloc_sz)/sizeof(union MPI2_REPLY_DESCRIPTORS_UNION);
766 megasas_alloc_rdpq_fusion(struct megasas_instance *instance)
768 int i, j, k, msix_count;
769 struct fusion_context *fusion;
770 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
771 union MPI2_REPLY_DESCRIPTORS_UNION *rdpq_chunk_virt[RDPQ_MAX_CHUNK_COUNT];
772 dma_addr_t rdpq_chunk_phys[RDPQ_MAX_CHUNK_COUNT];
773 u8 dma_alloc_count, abs_index;
774 u32 chunk_size, array_size, offset;
776 fusion = instance->ctrl_context;
777 chunk_size = fusion->reply_alloc_sz * RDPQ_MAX_INDEX_IN_ONE_CHUNK;
778 array_size = sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) *
779 MAX_MSIX_QUEUES_FUSION;
781 fusion->rdpq_virt = dma_alloc_coherent(&instance->pdev->dev,
782 array_size, &fusion->rdpq_phys,
784 if (!fusion->rdpq_virt) {
785 dev_err(&instance->pdev->dev,
786 "Failed from %s %d\n", __func__, __LINE__);
790 msix_count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
792 fusion->reply_frames_desc_pool = dma_pool_create("mr_rdpq",
793 &instance->pdev->dev,
795 fusion->reply_frames_desc_pool_align =
796 dma_pool_create("mr_rdpq_align",
797 &instance->pdev->dev,
799 roundup_pow_of_two(chunk_size),
802 if (!fusion->reply_frames_desc_pool ||
803 !fusion->reply_frames_desc_pool_align) {
804 dev_err(&instance->pdev->dev,
805 "Failed from %s %d\n", __func__, __LINE__);
810 * For INVADER_SERIES each set of 8 reply queues(0-7, 8-15, ..) and
811 * VENTURA_SERIES each set of 16 reply queues(0-15, 16-31, ..) should be
812 * within 4GB boundary and also reply queues in a set must have same
813 * upper 32-bits in their memory address. so here driver is allocating the
814 * DMA'able memory for reply queues according. Driver uses limitation of
815 * VENTURA_SERIES to manage INVADER_SERIES as well.
817 dma_alloc_count = DIV_ROUND_UP(msix_count, RDPQ_MAX_INDEX_IN_ONE_CHUNK);
819 for (i = 0; i < dma_alloc_count; i++) {
821 dma_pool_alloc(fusion->reply_frames_desc_pool,
822 GFP_KERNEL, &rdpq_chunk_phys[i]);
823 if (!rdpq_chunk_virt[i]) {
824 dev_err(&instance->pdev->dev,
825 "Failed from %s %d\n", __func__, __LINE__);
828 /* reply desc pool requires to be in same 4 gb region.
829 * Below function will check this.
830 * In case of failure, new pci pool will be created with updated
832 * For RDPQ buffers, driver always allocate two separate pci pool.
833 * Alignment will be used such a way that next allocation if
834 * success, will always meet same 4gb region requirement.
835 * rdpq_tracker keep track of each buffer's physical,
836 * virtual address and pci pool descriptor. It will help driver
837 * while freeing the resources.
840 if (!megasas_check_same_4gb_region(instance, rdpq_chunk_phys[i],
842 dma_pool_free(fusion->reply_frames_desc_pool,
847 dma_pool_alloc(fusion->reply_frames_desc_pool_align,
848 GFP_KERNEL, &rdpq_chunk_phys[i]);
849 if (!rdpq_chunk_virt[i]) {
850 dev_err(&instance->pdev->dev,
851 "Failed from %s %d\n",
855 fusion->rdpq_tracker[i].dma_pool_ptr =
856 fusion->reply_frames_desc_pool_align;
858 fusion->rdpq_tracker[i].dma_pool_ptr =
859 fusion->reply_frames_desc_pool;
862 fusion->rdpq_tracker[i].pool_entry_phys = rdpq_chunk_phys[i];
863 fusion->rdpq_tracker[i].pool_entry_virt = rdpq_chunk_virt[i];
866 for (k = 0; k < dma_alloc_count; k++) {
867 for (i = 0; i < RDPQ_MAX_INDEX_IN_ONE_CHUNK; i++) {
868 abs_index = (k * RDPQ_MAX_INDEX_IN_ONE_CHUNK) + i;
870 if (abs_index == msix_count)
872 offset = fusion->reply_alloc_sz * i;
873 fusion->rdpq_virt[abs_index].RDPQBaseAddress =
874 cpu_to_le64(rdpq_chunk_phys[k] + offset);
875 fusion->reply_frames_desc_phys[abs_index] =
876 rdpq_chunk_phys[k] + offset;
877 fusion->reply_frames_desc[abs_index] =
878 (union MPI2_REPLY_DESCRIPTORS_UNION *)((u8 *)rdpq_chunk_virt[k] + offset);
880 reply_desc = fusion->reply_frames_desc[abs_index];
881 for (j = 0; j < fusion->reply_q_depth; j++, reply_desc++)
882 reply_desc->Words = ULLONG_MAX;
890 megasas_free_rdpq_fusion(struct megasas_instance *instance) {
893 struct fusion_context *fusion;
895 fusion = instance->ctrl_context;
897 for (i = 0; i < RDPQ_MAX_CHUNK_COUNT; i++) {
898 if (fusion->rdpq_tracker[i].pool_entry_virt)
899 dma_pool_free(fusion->rdpq_tracker[i].dma_pool_ptr,
900 fusion->rdpq_tracker[i].pool_entry_virt,
901 fusion->rdpq_tracker[i].pool_entry_phys);
905 dma_pool_destroy(fusion->reply_frames_desc_pool);
906 dma_pool_destroy(fusion->reply_frames_desc_pool_align);
908 if (fusion->rdpq_virt)
909 dma_free_coherent(&instance->pdev->dev,
910 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION,
911 fusion->rdpq_virt, fusion->rdpq_phys);
915 megasas_free_reply_fusion(struct megasas_instance *instance) {
917 struct fusion_context *fusion;
919 fusion = instance->ctrl_context;
921 if (fusion->reply_frames_desc[0])
922 dma_pool_free(fusion->reply_frames_desc_pool,
923 fusion->reply_frames_desc[0],
924 fusion->reply_frames_desc_phys[0]);
926 dma_pool_destroy(fusion->reply_frames_desc_pool);
932 * megasas_alloc_cmds_fusion - Allocates the command packets
933 * @instance: Adapter soft state
936 * Each frame has a 32-bit field called context. This context is used to get
937 * back the megasas_cmd_fusion from the frame when a frame gets completed
938 * In this driver, the 32 bit values are the indices into an array cmd_list.
939 * This array is used only to look up the megasas_cmd_fusion given the context.
940 * The free commands themselves are maintained in a linked list called cmd_pool.
942 * cmds are formed in the io_request and sg_frame members of the
943 * megasas_cmd_fusion. The context field is used to get a request descriptor
944 * and is used as SMID of the cmd.
945 * SMID value range is from 1 to max_fw_cmds.
948 megasas_alloc_cmds_fusion(struct megasas_instance *instance)
951 struct fusion_context *fusion;
952 struct megasas_cmd_fusion *cmd;
954 dma_addr_t io_req_base_phys;
958 fusion = instance->ctrl_context;
960 if (megasas_alloc_request_fusion(instance))
963 if (instance->is_rdpq) {
964 if (megasas_alloc_rdpq_fusion(instance))
967 if (megasas_alloc_reply_fusion(instance))
970 if (megasas_alloc_cmdlist_fusion(instance))
973 dev_info(&instance->pdev->dev, "Configured max firmware commands: %d\n",
974 instance->max_fw_cmds);
976 /* The first 256 bytes (SMID 0) is not used. Don't add to the cmd list */
977 io_req_base = fusion->io_request_frames + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
978 io_req_base_phys = fusion->io_request_frames_phys + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
981 * Add all the commands to command pool (fusion->cmd_pool)
984 /* SMID 0 is reserved. Set SMID/index from 1 */
985 for (i = 0; i < instance->max_mpt_cmds; i++) {
986 cmd = fusion->cmd_list[i];
987 offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i;
988 memset(cmd, 0, sizeof(struct megasas_cmd_fusion));
992 (i >= instance->max_scsi_cmds && i < instance->max_fw_cmds) ?
993 (i - instance->max_scsi_cmds) :
994 (u32)ULONG_MAX; /* Set to Invalid */
995 cmd->instance = instance;
997 (struct MPI2_RAID_SCSI_IO_REQUEST *)
998 (io_req_base + offset);
999 memset(cmd->io_request, 0,
1000 sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
1001 cmd->io_request_phys_addr = io_req_base_phys + offset;
1002 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
1005 if (megasas_create_sg_sense_fusion(instance))
1011 megasas_free_cmds_fusion(instance);
1016 * wait_and_poll - Issues a polling command
1017 * @instance: Adapter soft state
1018 * @cmd: Command packet to be issued
1020 * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
1023 wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd,
1027 struct megasas_header *frame_hdr = &cmd->frame->hdr;
1030 u32 msecs = seconds * 1000;
1033 * Wait for cmd_status to change
1035 for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) {
1039 status_reg = instance->instancet->read_fw_status_reg(instance)
1041 if (status_reg == MFI_STATE_FAULT)
1046 if (frame_hdr->cmd_status == MFI_STAT_INVALID_STATUS)
1047 return DCMD_TIMEOUT;
1048 else if (frame_hdr->cmd_status == MFI_STAT_OK)
1049 return DCMD_SUCCESS;
1055 * megasas_ioc_init_fusion - Initializes the FW
1056 * @instance: Adapter soft state
1058 * Issues the IOC Init cmd
1061 megasas_ioc_init_fusion(struct megasas_instance *instance)
1063 struct megasas_init_frame *init_frame;
1064 struct MPI2_IOC_INIT_REQUEST *IOCInitMessage = NULL;
1065 dma_addr_t ioc_init_handle;
1066 struct megasas_cmd *cmd;
1067 u8 ret, cur_rdpq_mode;
1068 struct fusion_context *fusion;
1069 union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc;
1071 struct megasas_header *frame_hdr;
1072 const char *sys_info;
1073 MFI_CAPABILITIES *drv_ops;
1076 bool cur_fw_64bit_dma_capable;
1077 bool cur_intr_coalescing;
1079 fusion = instance->ctrl_context;
1081 ioc_init_handle = fusion->ioc_init_request_phys;
1082 IOCInitMessage = fusion->ioc_init_request;
1084 cmd = fusion->ioc_init_cmd;
1086 scratch_pad_1 = megasas_readl
1087 (instance, &instance->reg_set->outbound_scratch_pad_1);
1089 cur_rdpq_mode = (scratch_pad_1 & MR_RDPQ_MODE_OFFSET) ? 1 : 0;
1091 if (instance->adapter_type == INVADER_SERIES) {
1092 cur_fw_64bit_dma_capable =
1093 (scratch_pad_1 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET) ? true : false;
1095 if (instance->consistent_mask_64bit && !cur_fw_64bit_dma_capable) {
1096 dev_err(&instance->pdev->dev, "Driver was operating on 64bit "
1097 "DMA mask, but upcoming FW does not support 64bit DMA mask\n");
1098 megaraid_sas_kill_hba(instance);
1104 if (instance->is_rdpq && !cur_rdpq_mode) {
1105 dev_err(&instance->pdev->dev, "Firmware downgrade *NOT SUPPORTED*"
1106 " from RDPQ mode to non RDPQ mode\n");
1111 cur_intr_coalescing = (scratch_pad_1 & MR_INTR_COALESCING_SUPPORT_OFFSET) ?
1114 if ((instance->low_latency_index_start ==
1115 MR_HIGH_IOPS_QUEUE_COUNT) && cur_intr_coalescing)
1116 instance->perf_mode = MR_BALANCED_PERF_MODE;
1118 dev_info(&instance->pdev->dev, "Performance mode :%s\n",
1119 MEGASAS_PERF_MODE_2STR(instance->perf_mode));
1121 instance->fw_sync_cache_support = (scratch_pad_1 &
1122 MR_CAN_HANDLE_SYNC_CACHE_OFFSET) ? 1 : 0;
1123 dev_info(&instance->pdev->dev, "FW supports sync cache\t: %s\n",
1124 instance->fw_sync_cache_support ? "Yes" : "No");
1126 memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST));
1128 IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT;
1129 IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER;
1130 IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION);
1131 IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
1132 IOCInitMessage->SystemRequestFrameSize = cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4);
1134 IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth);
1135 IOCInitMessage->ReplyDescriptorPostQueueAddress = instance->is_rdpq ?
1136 cpu_to_le64(fusion->rdpq_phys) :
1137 cpu_to_le64(fusion->reply_frames_desc_phys[0]);
1138 IOCInitMessage->MsgFlags = instance->is_rdpq ?
1139 MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE : 0;
1140 IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys);
1141 IOCInitMessage->SenseBufferAddressHigh = cpu_to_le32(upper_32_bits(fusion->sense_phys_addr));
1142 IOCInitMessage->HostMSIxVectors = instance->msix_vectors;
1143 IOCInitMessage->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT;
1145 time = ktime_get_real();
1146 /* Convert to milliseconds as per FW requirement */
1147 IOCInitMessage->TimeStamp = cpu_to_le64(ktime_to_ms(time));
1149 init_frame = (struct megasas_init_frame *)cmd->frame;
1150 memset(init_frame, 0, IOC_INIT_FRAME_SIZE);
1152 frame_hdr = &cmd->frame->hdr;
1153 frame_hdr->cmd_status = 0xFF;
1154 frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE);
1156 init_frame->cmd = MFI_CMD_INIT;
1157 init_frame->cmd_status = 0xFF;
1159 drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations);
1161 /* driver support Extended MSIX */
1162 if (instance->adapter_type >= INVADER_SERIES)
1163 drv_ops->mfi_capabilities.support_additional_msix = 1;
1164 /* driver supports HA / Remote LUN over Fast Path interface */
1165 drv_ops->mfi_capabilities.support_fp_remote_lun = 1;
1167 drv_ops->mfi_capabilities.support_max_255lds = 1;
1168 drv_ops->mfi_capabilities.support_ndrive_r1_lb = 1;
1169 drv_ops->mfi_capabilities.security_protocol_cmds_fw = 1;
1171 if (instance->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN)
1172 drv_ops->mfi_capabilities.support_ext_io_size = 1;
1174 drv_ops->mfi_capabilities.support_fp_rlbypass = 1;
1175 if (!dual_qdepth_disable)
1176 drv_ops->mfi_capabilities.support_ext_queue_depth = 1;
1178 drv_ops->mfi_capabilities.support_qd_throttling = 1;
1179 drv_ops->mfi_capabilities.support_pd_map_target_id = 1;
1180 drv_ops->mfi_capabilities.support_nvme_passthru = 1;
1181 drv_ops->mfi_capabilities.support_fw_exposed_dev_list = 1;
1183 if (instance->consistent_mask_64bit)
1184 drv_ops->mfi_capabilities.support_64bit_mode = 1;
1186 /* Convert capability to LE32 */
1187 cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities);
1189 sys_info = dmi_get_system_info(DMI_PRODUCT_UUID);
1190 if (instance->system_info_buf && sys_info) {
1191 memcpy(instance->system_info_buf->systemId, sys_info,
1192 strlen(sys_info) > 64 ? 64 : strlen(sys_info));
1193 instance->system_info_buf->systemIdLength =
1194 strlen(sys_info) > 64 ? 64 : strlen(sys_info);
1195 init_frame->system_info_lo = cpu_to_le32(lower_32_bits(instance->system_info_h));
1196 init_frame->system_info_hi = cpu_to_le32(upper_32_bits(instance->system_info_h));
1199 init_frame->queue_info_new_phys_addr_hi =
1200 cpu_to_le32(upper_32_bits(ioc_init_handle));
1201 init_frame->queue_info_new_phys_addr_lo =
1202 cpu_to_le32(lower_32_bits(ioc_init_handle));
1203 init_frame->data_xfer_len = cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST));
1206 * Each bit in replyqueue_mask represents one group of MSI-x vectors
1207 * (each group has 8 vectors)
1209 switch (instance->perf_mode) {
1210 case MR_BALANCED_PERF_MODE:
1211 init_frame->replyqueue_mask =
1212 cpu_to_le16(~(~0 << instance->low_latency_index_start/8));
1214 case MR_IOPS_PERF_MODE:
1215 init_frame->replyqueue_mask =
1216 cpu_to_le16(~(~0 << instance->msix_vectors/8));
1221 req_desc.u.low = cpu_to_le32(lower_32_bits(cmd->frame_phys_addr));
1222 req_desc.u.high = cpu_to_le32(upper_32_bits(cmd->frame_phys_addr));
1223 req_desc.MFAIo.RequestFlags =
1224 (MEGASAS_REQ_DESCRIPT_FLAGS_MFA <<
1225 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1228 * disable the intr before firing the init frame
1230 instance->instancet->disable_intr(instance);
1232 for (i = 0; i < (10 * 1000); i += 20) {
1233 if (megasas_readl(instance, &instance->reg_set->doorbell) & 1)
1239 /* For AERO also, IOC_INIT requires 64 bit descriptor write */
1240 megasas_write_64bit_req_desc(instance, &req_desc);
1242 wait_and_poll(instance, cmd, MFI_IO_TIMEOUT_SECS);
1244 frame_hdr = &cmd->frame->hdr;
1245 if (frame_hdr->cmd_status != 0) {
1250 if (instance->adapter_type >= AERO_SERIES) {
1251 scratch_pad_1 = megasas_readl
1252 (instance, &instance->reg_set->outbound_scratch_pad_1);
1254 instance->atomic_desc_support =
1255 (scratch_pad_1 & MR_ATOMIC_DESCRIPTOR_SUPPORT_OFFSET) ? 1 : 0;
1257 dev_info(&instance->pdev->dev, "FW supports atomic descriptor\t: %s\n",
1258 instance->atomic_desc_support ? "Yes" : "No");
1264 dev_err(&instance->pdev->dev,
1265 "Init cmd return status FAILED for SCSI host %d\n",
1266 instance->host->host_no);
1272 * megasas_sync_pd_seq_num - JBOD SEQ MAP
1273 * @instance: Adapter soft state
1274 * @pend: set to 1, if it is pended jbod map.
1276 * Issue Jbod map to the firmware. If it is pended command,
1277 * issue command and return. If it is first instance of jbod map
1278 * issue and receive command.
1281 megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) {
1283 size_t pd_seq_map_sz;
1284 struct megasas_cmd *cmd;
1285 struct megasas_dcmd_frame *dcmd;
1286 struct fusion_context *fusion = instance->ctrl_context;
1287 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
1288 dma_addr_t pd_seq_h;
1290 pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)];
1291 pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)];
1292 pd_seq_map_sz = struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES - 1);
1294 cmd = megasas_get_cmd(instance);
1296 dev_err(&instance->pdev->dev,
1297 "Could not get mfi cmd. Fail from %s %d\n",
1298 __func__, __LINE__);
1302 dcmd = &cmd->frame->dcmd;
1304 memset(pd_sync, 0, pd_seq_map_sz);
1305 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1308 dcmd->mbox.b[0] = MEGASAS_DCMD_MBOX_PEND_FLAG;
1309 dcmd->flags = MFI_FRAME_DIR_WRITE;
1310 instance->jbod_seq_cmd = cmd;
1312 dcmd->flags = MFI_FRAME_DIR_READ;
1315 dcmd->cmd = MFI_CMD_DCMD;
1316 dcmd->cmd_status = 0xFF;
1317 dcmd->sge_count = 1;
1320 dcmd->data_xfer_len = cpu_to_le32(pd_seq_map_sz);
1321 dcmd->opcode = cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO);
1323 megasas_set_dma_settings(instance, dcmd, pd_seq_h, pd_seq_map_sz);
1326 instance->instancet->issue_dcmd(instance, cmd);
1330 /* Below code is only for non pended DCMD */
1331 if (!instance->mask_interrupts)
1332 ret = megasas_issue_blocked_cmd(instance, cmd,
1333 MFI_IO_TIMEOUT_SECS);
1335 ret = megasas_issue_polled(instance, cmd);
1337 if (le32_to_cpu(pd_sync->count) > MAX_PHYSICAL_DEVICES) {
1338 dev_warn(&instance->pdev->dev,
1339 "driver supports max %d JBOD, but FW reports %d\n",
1340 MAX_PHYSICAL_DEVICES, le32_to_cpu(pd_sync->count));
1344 if (ret == DCMD_TIMEOUT)
1345 dev_warn(&instance->pdev->dev,
1346 "%s DCMD timed out, continue without JBOD sequence map\n",
1349 if (ret == DCMD_SUCCESS)
1350 instance->pd_seq_map_id++;
1352 megasas_return_cmd(instance, cmd);
1357 * megasas_get_ld_map_info - Returns FW's ld_map structure
1358 * @instance: Adapter soft state
1359 * @pend: Pend the command or not
1360 * Issues an internal command (DCMD) to get the FW's controller PD
1361 * list structure. This information is mainly used to find out SYSTEM
1362 * supported by the FW.
1363 * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO
1364 * dcmd.mbox.b[0] - number of LDs being sync'd
1365 * dcmd.mbox.b[1] - 0 - complete command immediately.
1366 * - 1 - pend till config change
1367 * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP
1368 * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and
1369 * uses extended struct MR_FW_RAID_MAP_EXT
1372 megasas_get_ld_map_info(struct megasas_instance *instance)
1375 struct megasas_cmd *cmd;
1376 struct megasas_dcmd_frame *dcmd;
1378 dma_addr_t ci_h = 0;
1380 struct fusion_context *fusion;
1382 cmd = megasas_get_cmd(instance);
1385 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for map info\n");
1389 fusion = instance->ctrl_context;
1392 megasas_return_cmd(instance, cmd);
1396 dcmd = &cmd->frame->dcmd;
1398 size_map_info = fusion->current_map_sz;
1400 ci = (void *) fusion->ld_map[(instance->map_id & 1)];
1401 ci_h = fusion->ld_map_phys[(instance->map_id & 1)];
1404 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ld_map_info\n");
1405 megasas_return_cmd(instance, cmd);
1409 memset(ci, 0, fusion->max_map_sz);
1410 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1411 dcmd->cmd = MFI_CMD_DCMD;
1412 dcmd->cmd_status = 0xFF;
1413 dcmd->sge_count = 1;
1414 dcmd->flags = MFI_FRAME_DIR_READ;
1417 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
1418 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
1420 megasas_set_dma_settings(instance, dcmd, ci_h, size_map_info);
1422 if (!instance->mask_interrupts)
1423 ret = megasas_issue_blocked_cmd(instance, cmd,
1424 MFI_IO_TIMEOUT_SECS);
1426 ret = megasas_issue_polled(instance, cmd);
1428 if (ret == DCMD_TIMEOUT)
1429 dev_warn(&instance->pdev->dev,
1430 "%s DCMD timed out, RAID map is disabled\n",
1433 megasas_return_cmd(instance, cmd);
1439 megasas_get_map_info(struct megasas_instance *instance)
1441 struct fusion_context *fusion = instance->ctrl_context;
1443 fusion->fast_path_io = 0;
1444 if (!megasas_get_ld_map_info(instance)) {
1445 if (MR_ValidateMapInfo(instance, instance->map_id)) {
1446 fusion->fast_path_io = 1;
1454 * megasas_sync_map_info - Returns FW's ld_map structure
1455 * @instance: Adapter soft state
1457 * Issues an internal command (DCMD) to get the FW's controller PD
1458 * list structure. This information is mainly used to find out SYSTEM
1459 * supported by the FW.
1462 megasas_sync_map_info(struct megasas_instance *instance)
1465 struct megasas_cmd *cmd;
1466 struct megasas_dcmd_frame *dcmd;
1468 struct fusion_context *fusion;
1469 struct MR_LD_TARGET_SYNC *ci = NULL;
1470 struct MR_DRV_RAID_MAP_ALL *map;
1471 struct MR_LD_RAID *raid;
1472 struct MR_LD_TARGET_SYNC *ld_sync;
1473 dma_addr_t ci_h = 0;
1476 cmd = megasas_get_cmd(instance);
1479 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for sync info\n");
1483 fusion = instance->ctrl_context;
1486 megasas_return_cmd(instance, cmd);
1490 map = fusion->ld_drv_map[instance->map_id & 1];
1492 num_lds = le16_to_cpu(map->raidMap.ldCount);
1494 dcmd = &cmd->frame->dcmd;
1496 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1498 ci = (struct MR_LD_TARGET_SYNC *)
1499 fusion->ld_map[(instance->map_id - 1) & 1];
1500 memset(ci, 0, fusion->max_map_sz);
1502 ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1];
1504 ld_sync = (struct MR_LD_TARGET_SYNC *)ci;
1506 for (i = 0; i < num_lds; i++, ld_sync++) {
1507 raid = MR_LdRaidGet(i, map);
1508 ld_sync->targetId = MR_GetLDTgtId(i, map);
1509 ld_sync->seqNum = raid->seqNum;
1512 size_map_info = fusion->current_map_sz;
1514 dcmd->cmd = MFI_CMD_DCMD;
1515 dcmd->cmd_status = 0xFF;
1516 dcmd->sge_count = 1;
1517 dcmd->flags = MFI_FRAME_DIR_WRITE;
1520 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
1521 dcmd->mbox.b[0] = num_lds;
1522 dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG;
1523 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
1525 megasas_set_dma_settings(instance, dcmd, ci_h, size_map_info);
1527 instance->map_update_cmd = cmd;
1529 instance->instancet->issue_dcmd(instance, cmd);
1535 * meagasas_display_intel_branding - Display branding string
1536 * @instance: per adapter object
1541 megasas_display_intel_branding(struct megasas_instance *instance)
1543 if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1546 switch (instance->pdev->device) {
1547 case PCI_DEVICE_ID_LSI_INVADER:
1548 switch (instance->pdev->subsystem_device) {
1549 case MEGARAID_INTEL_RS3DC080_SSDID:
1550 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1551 instance->host->host_no,
1552 MEGARAID_INTEL_RS3DC080_BRANDING);
1554 case MEGARAID_INTEL_RS3DC040_SSDID:
1555 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1556 instance->host->host_no,
1557 MEGARAID_INTEL_RS3DC040_BRANDING);
1559 case MEGARAID_INTEL_RS3SC008_SSDID:
1560 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1561 instance->host->host_no,
1562 MEGARAID_INTEL_RS3SC008_BRANDING);
1564 case MEGARAID_INTEL_RS3MC044_SSDID:
1565 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1566 instance->host->host_no,
1567 MEGARAID_INTEL_RS3MC044_BRANDING);
1573 case PCI_DEVICE_ID_LSI_FURY:
1574 switch (instance->pdev->subsystem_device) {
1575 case MEGARAID_INTEL_RS3WC080_SSDID:
1576 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1577 instance->host->host_no,
1578 MEGARAID_INTEL_RS3WC080_BRANDING);
1580 case MEGARAID_INTEL_RS3WC040_SSDID:
1581 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1582 instance->host->host_no,
1583 MEGARAID_INTEL_RS3WC040_BRANDING);
1589 case PCI_DEVICE_ID_LSI_CUTLASS_52:
1590 case PCI_DEVICE_ID_LSI_CUTLASS_53:
1591 switch (instance->pdev->subsystem_device) {
1592 case MEGARAID_INTEL_RMS3BC160_SSDID:
1593 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1594 instance->host->host_no,
1595 MEGARAID_INTEL_RMS3BC160_BRANDING);
1607 * megasas_allocate_raid_maps - Allocate memory for RAID maps
1608 * @instance: Adapter soft state
1610 * return: if success: return 0
1611 * failed: return -ENOMEM
1613 static inline int megasas_allocate_raid_maps(struct megasas_instance *instance)
1615 struct fusion_context *fusion;
1618 fusion = instance->ctrl_context;
1620 fusion->drv_map_pages = get_order(fusion->drv_map_sz);
1622 for (i = 0; i < 2; i++) {
1623 fusion->ld_map[i] = NULL;
1625 fusion->ld_drv_map[i] = (void *)
1626 __get_free_pages(__GFP_ZERO | GFP_KERNEL,
1627 fusion->drv_map_pages);
1629 if (!fusion->ld_drv_map[i]) {
1630 fusion->ld_drv_map[i] = vzalloc(fusion->drv_map_sz);
1632 if (!fusion->ld_drv_map[i]) {
1633 dev_err(&instance->pdev->dev,
1634 "Could not allocate memory for local map"
1635 " size requested: %d\n",
1636 fusion->drv_map_sz);
1637 goto ld_drv_map_alloc_fail;
1642 for (i = 0; i < 2; i++) {
1643 fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev,
1645 &fusion->ld_map_phys[i],
1647 if (!fusion->ld_map[i]) {
1648 dev_err(&instance->pdev->dev,
1649 "Could not allocate memory for map info %s:%d\n",
1650 __func__, __LINE__);
1651 goto ld_map_alloc_fail;
1658 for (i = 0; i < 2; i++) {
1659 if (fusion->ld_map[i])
1660 dma_free_coherent(&instance->pdev->dev,
1663 fusion->ld_map_phys[i]);
1666 ld_drv_map_alloc_fail:
1667 for (i = 0; i < 2; i++) {
1668 if (fusion->ld_drv_map[i]) {
1669 if (is_vmalloc_addr(fusion->ld_drv_map[i]))
1670 vfree(fusion->ld_drv_map[i]);
1672 free_pages((ulong)fusion->ld_drv_map[i],
1673 fusion->drv_map_pages);
1681 * megasas_configure_queue_sizes - Calculate size of request desc queue,
1683 * IO request frame queue, set can_queue.
1684 * @instance: Adapter soft state
1688 void megasas_configure_queue_sizes(struct megasas_instance *instance)
1690 struct fusion_context *fusion;
1693 fusion = instance->ctrl_context;
1694 max_cmd = instance->max_fw_cmds;
1696 if (instance->adapter_type >= VENTURA_SERIES)
1697 instance->max_mpt_cmds = instance->max_fw_cmds * RAID_1_PEER_CMDS;
1699 instance->max_mpt_cmds = instance->max_fw_cmds;
1701 instance->max_scsi_cmds = instance->max_fw_cmds - instance->max_mfi_cmds;
1702 instance->cur_can_queue = instance->max_scsi_cmds;
1703 instance->host->can_queue = instance->cur_can_queue;
1705 fusion->reply_q_depth = 2 * ((max_cmd + 1 + 15) / 16) * 16;
1707 fusion->request_alloc_sz = sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *
1708 instance->max_mpt_cmds;
1709 fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION) *
1710 (fusion->reply_q_depth);
1711 fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE +
1712 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1713 * (instance->max_mpt_cmds + 1)); /* Extra 1 for SMID 0 */
1716 static int megasas_alloc_ioc_init_frame(struct megasas_instance *instance)
1718 struct fusion_context *fusion;
1719 struct megasas_cmd *cmd;
1721 fusion = instance->ctrl_context;
1723 cmd = kzalloc(sizeof(struct megasas_cmd), GFP_KERNEL);
1726 dev_err(&instance->pdev->dev, "Failed from func: %s line: %d\n",
1727 __func__, __LINE__);
1731 cmd->frame = dma_alloc_coherent(&instance->pdev->dev,
1732 IOC_INIT_FRAME_SIZE,
1733 &cmd->frame_phys_addr, GFP_KERNEL);
1736 dev_err(&instance->pdev->dev, "Failed from func: %s line: %d\n",
1737 __func__, __LINE__);
1742 fusion->ioc_init_cmd = cmd;
1747 * megasas_free_ioc_init_cmd - Free IOC INIT command frame
1748 * @instance: Adapter soft state
1750 static inline void megasas_free_ioc_init_cmd(struct megasas_instance *instance)
1752 struct fusion_context *fusion;
1754 fusion = instance->ctrl_context;
1756 if (fusion->ioc_init_cmd && fusion->ioc_init_cmd->frame)
1757 dma_free_coherent(&instance->pdev->dev,
1758 IOC_INIT_FRAME_SIZE,
1759 fusion->ioc_init_cmd->frame,
1760 fusion->ioc_init_cmd->frame_phys_addr);
1762 kfree(fusion->ioc_init_cmd);
1766 * megasas_init_adapter_fusion - Initializes the FW
1767 * @instance: Adapter soft state
1769 * This is the main function for initializing firmware.
1772 megasas_init_adapter_fusion(struct megasas_instance *instance)
1774 struct fusion_context *fusion;
1779 fusion = instance->ctrl_context;
1781 megasas_fusion_update_can_queue(instance, PROBE_CONTEXT);
1784 * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames
1786 instance->max_mfi_cmds =
1787 MEGASAS_FUSION_INTERNAL_CMDS + MEGASAS_FUSION_IOCTL_CMDS;
1789 megasas_configure_queue_sizes(instance);
1791 scratch_pad_1 = megasas_readl(instance,
1792 &instance->reg_set->outbound_scratch_pad_1);
1793 /* If scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set,
1794 * Firmware support extended IO chain frame which is 4 times more than
1796 * Legacy Firmware - Frame size is (8 * 128) = 1K
1797 * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K
1799 if (scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK)
1800 instance->max_chain_frame_sz =
1801 ((scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_MASK) >>
1802 MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_1MB_IO;
1804 instance->max_chain_frame_sz =
1805 ((scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_MASK) >>
1806 MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_256K_IO;
1808 if (instance->max_chain_frame_sz < MEGASAS_CHAIN_FRAME_SZ_MIN) {
1809 dev_warn(&instance->pdev->dev, "frame size %d invalid, fall back to legacy max frame size %d\n",
1810 instance->max_chain_frame_sz,
1811 MEGASAS_CHAIN_FRAME_SZ_MIN);
1812 instance->max_chain_frame_sz = MEGASAS_CHAIN_FRAME_SZ_MIN;
1815 fusion->max_sge_in_main_msg =
1816 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1817 - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16;
1819 fusion->max_sge_in_chain =
1820 instance->max_chain_frame_sz
1821 / sizeof(union MPI2_SGE_IO_UNION);
1823 instance->max_num_sge =
1824 rounddown_pow_of_two(fusion->max_sge_in_main_msg
1825 + fusion->max_sge_in_chain - 2);
1827 /* Used for pass thru MFI frame (DCMD) */
1828 fusion->chain_offset_mfi_pthru =
1829 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16;
1831 fusion->chain_offset_io_request =
1832 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
1833 sizeof(union MPI2_SGE_IO_UNION))/16;
1835 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
1836 for (i = 0 ; i < count; i++)
1837 fusion->last_reply_idx[i] = 0;
1840 * For fusion adapters, 3 commands for IOCTL and 8 commands
1841 * for driver's internal DCMDs.
1843 instance->max_scsi_cmds = instance->max_fw_cmds -
1844 (MEGASAS_FUSION_INTERNAL_CMDS +
1845 MEGASAS_FUSION_IOCTL_CMDS);
1846 sema_init(&instance->ioctl_sem, MEGASAS_FUSION_IOCTL_CMDS);
1848 if (megasas_alloc_ioc_init_frame(instance))
1852 * Allocate memory for descriptors
1853 * Create a pool of commands
1855 if (megasas_alloc_cmds(instance))
1856 goto fail_alloc_mfi_cmds;
1857 if (megasas_alloc_cmds_fusion(instance))
1858 goto fail_alloc_cmds;
1860 if (megasas_ioc_init_fusion(instance)) {
1861 status_reg = instance->instancet->read_fw_status_reg(instance);
1862 if (((status_reg & MFI_STATE_MASK) == MFI_STATE_FAULT) &&
1863 (status_reg & MFI_RESET_ADAPTER)) {
1864 /* Do a chip reset and then retry IOC INIT once */
1865 if (megasas_adp_reset_wait_for_ready
1866 (instance, true, 0) == FAILED)
1869 if (megasas_ioc_init_fusion(instance))
1876 megasas_display_intel_branding(instance);
1877 if (megasas_get_ctrl_info(instance)) {
1878 dev_err(&instance->pdev->dev,
1879 "Could not get controller info. Fail from %s %d\n",
1880 __func__, __LINE__);
1884 instance->flag_ieee = 1;
1885 instance->r1_ldio_hint_default = MR_R1_LDIO_PIGGYBACK_DEFAULT;
1886 instance->threshold_reply_count = instance->max_fw_cmds / 4;
1887 fusion->fast_path_io = 0;
1889 if (megasas_allocate_raid_maps(instance))
1892 if (!megasas_get_map_info(instance))
1893 megasas_sync_map_info(instance);
1898 megasas_free_cmds_fusion(instance);
1900 megasas_free_cmds(instance);
1901 fail_alloc_mfi_cmds:
1902 megasas_free_ioc_init_cmd(instance);
1907 * megasas_fault_detect_work - Worker function of
1908 * FW fault handling workqueue.
1911 megasas_fault_detect_work(struct work_struct *work)
1913 struct megasas_instance *instance =
1914 container_of(work, struct megasas_instance,
1915 fw_fault_work.work);
1916 u32 fw_state, dma_state, status;
1918 /* Check the fw state */
1919 fw_state = instance->instancet->read_fw_status_reg(instance) &
1922 if (fw_state == MFI_STATE_FAULT) {
1923 dma_state = instance->instancet->read_fw_status_reg(instance) &
1925 /* Start collecting crash, if DMA bit is done */
1926 if (instance->crash_dump_drv_support &&
1927 instance->crash_dump_app_support && dma_state) {
1928 megasas_fusion_crash_dump(instance);
1930 if (instance->unload == 0) {
1931 status = megasas_reset_fusion(instance->host, 0);
1932 if (status != SUCCESS) {
1933 dev_err(&instance->pdev->dev,
1934 "Failed from %s %d, do not re-arm timer\n",
1935 __func__, __LINE__);
1942 if (instance->fw_fault_work_q)
1943 queue_delayed_work(instance->fw_fault_work_q,
1944 &instance->fw_fault_work,
1945 msecs_to_jiffies(MEGASAS_WATCHDOG_THREAD_INTERVAL));
1949 megasas_fusion_start_watchdog(struct megasas_instance *instance)
1951 /* Check if the Fault WQ is already started */
1952 if (instance->fw_fault_work_q)
1955 INIT_DELAYED_WORK(&instance->fw_fault_work, megasas_fault_detect_work);
1957 snprintf(instance->fault_handler_work_q_name,
1958 sizeof(instance->fault_handler_work_q_name),
1959 "poll_megasas%d_status", instance->host->host_no);
1961 instance->fw_fault_work_q =
1962 create_singlethread_workqueue(instance->fault_handler_work_q_name);
1963 if (!instance->fw_fault_work_q) {
1964 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
1965 __func__, __LINE__);
1969 queue_delayed_work(instance->fw_fault_work_q,
1970 &instance->fw_fault_work,
1971 msecs_to_jiffies(MEGASAS_WATCHDOG_THREAD_INTERVAL));
1977 megasas_fusion_stop_watchdog(struct megasas_instance *instance)
1979 struct workqueue_struct *wq;
1981 if (instance->fw_fault_work_q) {
1982 wq = instance->fw_fault_work_q;
1983 instance->fw_fault_work_q = NULL;
1984 if (!cancel_delayed_work_sync(&instance->fw_fault_work))
1985 flush_workqueue(wq);
1986 destroy_workqueue(wq);
1991 * map_cmd_status - Maps FW cmd status to OS cmd status
1992 * @cmd : Pointer to cmd
1993 * @status : status of cmd returned by FW
1994 * @ext_status : ext status of cmd returned by FW
1998 map_cmd_status(struct fusion_context *fusion,
1999 struct scsi_cmnd *scmd, u8 status, u8 ext_status,
2000 u32 data_length, u8 *sense)
2005 cmd_type = megasas_cmd_type(scmd);
2009 scmd->result = DID_OK << 16;
2012 case MFI_STAT_SCSI_IO_FAILED:
2013 case MFI_STAT_LD_INIT_IN_PROGRESS:
2014 scmd->result = (DID_ERROR << 16) | ext_status;
2017 case MFI_STAT_SCSI_DONE_WITH_ERROR:
2019 scmd->result = (DID_OK << 16) | ext_status;
2020 if (ext_status == SAM_STAT_CHECK_CONDITION) {
2021 memset(scmd->sense_buffer, 0,
2022 SCSI_SENSE_BUFFERSIZE);
2023 memcpy(scmd->sense_buffer, sense,
2024 SCSI_SENSE_BUFFERSIZE);
2025 scmd->result |= DRIVER_SENSE << 24;
2029 * If the IO request is partially completed, then MR FW will
2030 * update "io_request->DataLength" field with actual number of
2031 * bytes transferred.Driver will set residual bytes count in
2032 * SCSI command structure.
2034 resid = (scsi_bufflen(scmd) - data_length);
2035 scsi_set_resid(scmd, resid);
2038 ((cmd_type == READ_WRITE_LDIO) ||
2039 (cmd_type == READ_WRITE_SYSPDIO)))
2040 scmd_printk(KERN_INFO, scmd, "BRCM Debug mfi stat 0x%x, data len"
2041 " requested/completed 0x%x/0x%x\n",
2042 status, scsi_bufflen(scmd), data_length);
2045 case MFI_STAT_LD_OFFLINE:
2046 case MFI_STAT_DEVICE_NOT_FOUND:
2047 scmd->result = DID_BAD_TARGET << 16;
2049 case MFI_STAT_CONFIG_SEQ_MISMATCH:
2050 scmd->result = DID_IMM_RETRY << 16;
2053 scmd->result = DID_ERROR << 16;
2059 * megasas_is_prp_possible -
2060 * Checks if native NVMe PRPs can be built for the IO
2062 * @instance: Adapter soft state
2063 * @scmd: SCSI command from the mid-layer
2064 * @sge_count: scatter gather element count.
2066 * Returns: true: PRPs can be built
2067 * false: IEEE SGLs needs to be built
2070 megasas_is_prp_possible(struct megasas_instance *instance,
2071 struct scsi_cmnd *scmd, int sge_count)
2073 u32 data_length = 0;
2074 struct scatterlist *sg_scmd;
2075 bool build_prp = false;
2076 u32 mr_nvme_pg_size;
2078 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
2079 MR_DEFAULT_NVME_PAGE_SIZE);
2080 data_length = scsi_bufflen(scmd);
2081 sg_scmd = scsi_sglist(scmd);
2084 * NVMe uses one PRP for each page (or part of a page)
2085 * look at the data length - if 4 pages or less then IEEE is OK
2086 * if > 5 pages then we need to build a native SGL
2087 * if > 4 and <= 5 pages, then check physical address of 1st SG entry
2088 * if this first size in the page is >= the residual beyond 4 pages
2089 * then use IEEE, otherwise use native SGL
2092 if (data_length > (mr_nvme_pg_size * 5)) {
2094 } else if ((data_length > (mr_nvme_pg_size * 4)) &&
2095 (data_length <= (mr_nvme_pg_size * 5))) {
2096 /* check if 1st SG entry size is < residual beyond 4 pages */
2097 if (sg_dma_len(sg_scmd) < (data_length - (mr_nvme_pg_size * 4)))
2105 * megasas_make_prp_nvme -
2106 * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only
2108 * @instance: Adapter soft state
2109 * @scmd: SCSI command from the mid-layer
2110 * @sgl_ptr: SGL to be filled in
2111 * @cmd: Fusion command frame
2112 * @sge_count: scatter gather element count.
2114 * Returns: true: PRPs are built
2115 * false: IEEE SGLs needs to be built
2118 megasas_make_prp_nvme(struct megasas_instance *instance, struct scsi_cmnd *scmd,
2119 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
2120 struct megasas_cmd_fusion *cmd, int sge_count)
2122 int sge_len, offset, num_prp_in_chain = 0;
2123 struct MPI25_IEEE_SGE_CHAIN64 *main_chain_element, *ptr_first_sgl;
2125 dma_addr_t ptr_sgl_phys;
2127 u32 page_mask, page_mask_result;
2128 struct scatterlist *sg_scmd;
2130 bool build_prp = false;
2131 int data_len = scsi_bufflen(scmd);
2132 u32 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
2133 MR_DEFAULT_NVME_PAGE_SIZE);
2135 build_prp = megasas_is_prp_possible(instance, scmd, sge_count);
2141 * Nvme has a very convoluted prp format. One prp is required
2142 * for each page or partial page. Driver need to split up OS sg_list
2143 * entries if it is longer than one page or cross a page
2144 * boundary. Driver also have to insert a PRP list pointer entry as
2145 * the last entry in each physical page of the PRP list.
2147 * NOTE: The first PRP "entry" is actually placed in the first
2148 * SGL entry in the main message as IEEE 64 format. The 2nd
2149 * entry in the main message is the chain element, and the rest
2150 * of the PRP entries are built in the contiguous pcie buffer.
2152 page_mask = mr_nvme_pg_size - 1;
2153 ptr_sgl = (u64 *)cmd->sg_frame;
2154 ptr_sgl_phys = cmd->sg_frame_phys_addr;
2155 memset(ptr_sgl, 0, instance->max_chain_frame_sz);
2157 /* Build chain frame element which holds all prps except first*/
2158 main_chain_element = (struct MPI25_IEEE_SGE_CHAIN64 *)
2159 ((u8 *)sgl_ptr + sizeof(struct MPI25_IEEE_SGE_CHAIN64));
2161 main_chain_element->Address = cpu_to_le64(ptr_sgl_phys);
2162 main_chain_element->NextChainOffset = 0;
2163 main_chain_element->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
2164 IEEE_SGE_FLAGS_SYSTEM_ADDR |
2165 MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP;
2167 /* Build first prp, sge need not to be page aligned*/
2168 ptr_first_sgl = sgl_ptr;
2169 sg_scmd = scsi_sglist(scmd);
2170 sge_addr = sg_dma_address(sg_scmd);
2171 sge_len = sg_dma_len(sg_scmd);
2173 offset = (u32)(sge_addr & page_mask);
2174 first_prp_len = mr_nvme_pg_size - offset;
2176 ptr_first_sgl->Address = cpu_to_le64(sge_addr);
2177 ptr_first_sgl->Length = cpu_to_le32(first_prp_len);
2179 data_len -= first_prp_len;
2181 if (sge_len > first_prp_len) {
2182 sge_addr += first_prp_len;
2183 sge_len -= first_prp_len;
2184 } else if (sge_len == first_prp_len) {
2185 sg_scmd = sg_next(sg_scmd);
2186 sge_addr = sg_dma_address(sg_scmd);
2187 sge_len = sg_dma_len(sg_scmd);
2191 offset = (u32)(sge_addr & page_mask);
2193 /* Put PRP pointer due to page boundary*/
2194 page_mask_result = (uintptr_t)(ptr_sgl + 1) & page_mask;
2195 if (unlikely(!page_mask_result)) {
2196 scmd_printk(KERN_NOTICE,
2197 scmd, "page boundary ptr_sgl: 0x%p\n",
2200 *ptr_sgl = cpu_to_le64(ptr_sgl_phys);
2205 *ptr_sgl = cpu_to_le64(sge_addr);
2210 sge_addr += mr_nvme_pg_size;
2211 sge_len -= mr_nvme_pg_size;
2212 data_len -= mr_nvme_pg_size;
2220 sg_scmd = sg_next(sg_scmd);
2221 sge_addr = sg_dma_address(sg_scmd);
2222 sge_len = sg_dma_len(sg_scmd);
2225 main_chain_element->Length =
2226 cpu_to_le32(num_prp_in_chain * sizeof(u64));
2232 * megasas_make_sgl_fusion - Prepares 32-bit SGL
2233 * @instance: Adapter soft state
2234 * @scp: SCSI command from the mid-layer
2235 * @sgl_ptr: SGL to be filled in
2236 * @cmd: cmd we are working on
2237 * @sge_count sge count
2241 megasas_make_sgl_fusion(struct megasas_instance *instance,
2242 struct scsi_cmnd *scp,
2243 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
2244 struct megasas_cmd_fusion *cmd, int sge_count)
2246 int i, sg_processed;
2247 struct scatterlist *os_sgl;
2248 struct fusion_context *fusion;
2250 fusion = instance->ctrl_context;
2252 if (instance->adapter_type >= INVADER_SERIES) {
2253 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
2254 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
2255 sgl_ptr_end->Flags = 0;
2258 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
2259 sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl));
2260 sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl));
2262 if (instance->adapter_type >= INVADER_SERIES)
2263 if (i == sge_count - 1)
2264 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
2266 sg_processed = i + 1;
2268 if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) &&
2269 (sge_count > fusion->max_sge_in_main_msg)) {
2271 struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
2272 if (instance->adapter_type >= INVADER_SERIES) {
2273 if ((le16_to_cpu(cmd->io_request->IoFlags) &
2274 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
2275 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
2276 cmd->io_request->ChainOffset =
2278 chain_offset_io_request;
2280 cmd->io_request->ChainOffset = 0;
2282 cmd->io_request->ChainOffset =
2283 fusion->chain_offset_io_request;
2286 /* Prepare chain element */
2287 sg_chain->NextChainOffset = 0;
2288 if (instance->adapter_type >= INVADER_SERIES)
2289 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
2292 (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
2293 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
2294 sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed)));
2295 sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr);
2298 (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame;
2299 memset(sgl_ptr, 0, instance->max_chain_frame_sz);
2305 * megasas_make_sgl - Build Scatter Gather List(SGLs)
2306 * @scp: SCSI command pointer
2307 * @instance: Soft instance of controller
2308 * @cmd: Fusion command pointer
2310 * This function will build sgls based on device type.
2311 * For nvme drives, there is different way of building sgls in nvme native
2312 * format- PRPs(Physical Region Page).
2314 * Returns the number of sg lists actually used, zero if the sg lists
2315 * is NULL, or -ENOMEM if the mapping failed
2318 int megasas_make_sgl(struct megasas_instance *instance, struct scsi_cmnd *scp,
2319 struct megasas_cmd_fusion *cmd)
2322 bool build_prp = false;
2323 struct MPI25_IEEE_SGE_CHAIN64 *sgl_chain64;
2325 sge_count = scsi_dma_map(scp);
2327 if ((sge_count > instance->max_num_sge) || (sge_count <= 0))
2330 sgl_chain64 = (struct MPI25_IEEE_SGE_CHAIN64 *)&cmd->io_request->SGL;
2331 if ((le16_to_cpu(cmd->io_request->IoFlags) &
2332 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) &&
2333 (cmd->pd_interface == NVME_PD))
2334 build_prp = megasas_make_prp_nvme(instance, scp, sgl_chain64,
2338 megasas_make_sgl_fusion(instance, scp, sgl_chain64,
2345 * megasas_set_pd_lba - Sets PD LBA
2347 * @cdb_len: cdb length
2348 * @start_blk: Start block of IO
2350 * Used to set the PD LBA in CDB for FP IOs
2353 megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
2354 struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp,
2355 struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
2357 struct MR_LD_RAID *raid;
2359 u64 start_blk = io_info->pdBlock;
2360 u8 *cdb = io_request->CDB.CDB32;
2361 u32 num_blocks = io_info->numBlocks;
2362 u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0;
2364 /* Check if T10 PI (DIF) is enabled for this LD */
2365 ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr);
2366 raid = MR_LdRaidGet(ld, local_map_ptr);
2367 if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) {
2368 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
2369 cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD;
2370 cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN;
2372 if (scp->sc_data_direction == DMA_FROM_DEVICE)
2373 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32;
2375 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32;
2376 cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL;
2379 cdb[12] = (u8)((start_blk >> 56) & 0xff);
2380 cdb[13] = (u8)((start_blk >> 48) & 0xff);
2381 cdb[14] = (u8)((start_blk >> 40) & 0xff);
2382 cdb[15] = (u8)((start_blk >> 32) & 0xff);
2383 cdb[16] = (u8)((start_blk >> 24) & 0xff);
2384 cdb[17] = (u8)((start_blk >> 16) & 0xff);
2385 cdb[18] = (u8)((start_blk >> 8) & 0xff);
2386 cdb[19] = (u8)(start_blk & 0xff);
2388 /* Logical block reference tag */
2389 io_request->CDB.EEDP32.PrimaryReferenceTag =
2390 cpu_to_be32(ref_tag);
2391 io_request->CDB.EEDP32.PrimaryApplicationTagMask = cpu_to_be16(0xffff);
2392 io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */
2394 /* Transfer length */
2395 cdb[28] = (u8)((num_blocks >> 24) & 0xff);
2396 cdb[29] = (u8)((num_blocks >> 16) & 0xff);
2397 cdb[30] = (u8)((num_blocks >> 8) & 0xff);
2398 cdb[31] = (u8)(num_blocks & 0xff);
2400 /* set SCSI IO EEDPFlags */
2401 if (scp->sc_data_direction == DMA_FROM_DEVICE) {
2402 io_request->EEDPFlags = cpu_to_le16(
2403 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2404 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
2405 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
2406 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
2407 MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE |
2408 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD);
2410 io_request->EEDPFlags = cpu_to_le16(
2411 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2412 MPI2_SCSIIO_EEDPFLAGS_INSERT_OP);
2414 io_request->Control |= cpu_to_le32((0x4 << 26));
2415 io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size);
2417 /* Some drives don't support 16/12 byte CDB's, convert to 10 */
2418 if (((cdb_len == 12) || (cdb_len == 16)) &&
2419 (start_blk <= 0xffffffff)) {
2420 if (cdb_len == 16) {
2421 opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
2426 opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
2432 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
2439 /* Transfer length */
2440 cdb[8] = (u8)(num_blocks & 0xff);
2441 cdb[7] = (u8)((num_blocks >> 8) & 0xff);
2443 io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */
2445 } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) {
2446 /* Convert to 16 byte CDB for large LBA's */
2449 opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16;
2454 cdb[0] == READ_10 ? READ_16 : WRITE_16;
2461 cdb[0] == READ_12 ? READ_16 : WRITE_16;
2468 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
2475 /* Transfer length */
2476 cdb[13] = (u8)(num_blocks & 0xff);
2477 cdb[12] = (u8)((num_blocks >> 8) & 0xff);
2478 cdb[11] = (u8)((num_blocks >> 16) & 0xff);
2479 cdb[10] = (u8)((num_blocks >> 24) & 0xff);
2481 io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */
2485 /* Normal case, just load LBA here */
2489 u8 val = cdb[1] & 0xE0;
2490 cdb[3] = (u8)(start_blk & 0xff);
2491 cdb[2] = (u8)((start_blk >> 8) & 0xff);
2492 cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f);
2496 cdb[5] = (u8)(start_blk & 0xff);
2497 cdb[4] = (u8)((start_blk >> 8) & 0xff);
2498 cdb[3] = (u8)((start_blk >> 16) & 0xff);
2499 cdb[2] = (u8)((start_blk >> 24) & 0xff);
2502 cdb[5] = (u8)(start_blk & 0xff);
2503 cdb[4] = (u8)((start_blk >> 8) & 0xff);
2504 cdb[3] = (u8)((start_blk >> 16) & 0xff);
2505 cdb[2] = (u8)((start_blk >> 24) & 0xff);
2508 cdb[9] = (u8)(start_blk & 0xff);
2509 cdb[8] = (u8)((start_blk >> 8) & 0xff);
2510 cdb[7] = (u8)((start_blk >> 16) & 0xff);
2511 cdb[6] = (u8)((start_blk >> 24) & 0xff);
2512 cdb[5] = (u8)((start_blk >> 32) & 0xff);
2513 cdb[4] = (u8)((start_blk >> 40) & 0xff);
2514 cdb[3] = (u8)((start_blk >> 48) & 0xff);
2515 cdb[2] = (u8)((start_blk >> 56) & 0xff);
2522 * megasas_stream_detect - stream detection on read and and write IOs
2523 * @instance: Adapter soft state
2524 * @cmd: Command to be prepared
2525 * @io_info: IO Request info
2529 /** stream detection on read and and write IOs */
2530 static void megasas_stream_detect(struct megasas_instance *instance,
2531 struct megasas_cmd_fusion *cmd,
2532 struct IO_REQUEST_INFO *io_info)
2534 struct fusion_context *fusion = instance->ctrl_context;
2535 u32 device_id = io_info->ldTgtId;
2536 struct LD_STREAM_DETECT *current_ld_sd
2537 = fusion->stream_detect_by_ld[device_id];
2538 u32 *track_stream = ¤t_ld_sd->mru_bit_map, stream_num;
2539 u32 shifted_values, unshifted_values;
2540 u32 index_value_mask, shifted_values_mask;
2542 bool is_read_ahead = false;
2543 struct STREAM_DETECT *current_sd;
2544 /* find possible stream */
2545 for (i = 0; i < MAX_STREAMS_TRACKED; ++i) {
2546 stream_num = (*track_stream >>
2547 (i * BITS_PER_INDEX_STREAM)) &
2549 current_sd = ¤t_ld_sd->stream_track[stream_num];
2550 /* if we found a stream, update the raid
2551 * context and also update the mruBitMap
2553 /* boundary condition */
2554 if ((current_sd->next_seq_lba) &&
2555 (io_info->ldStartBlock >= current_sd->next_seq_lba) &&
2556 (io_info->ldStartBlock <= (current_sd->next_seq_lba + 32)) &&
2557 (current_sd->is_read == io_info->isRead)) {
2559 if ((io_info->ldStartBlock != current_sd->next_seq_lba) &&
2560 ((!io_info->isRead) || (!is_read_ahead)))
2562 * Once the API availible we need to change this.
2563 * At this point we are not allowing any gap
2567 SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35);
2568 current_sd->next_seq_lba =
2569 io_info->ldStartBlock + io_info->numBlocks;
2571 * update the mruBitMap LRU
2573 shifted_values_mask =
2574 (1 << i * BITS_PER_INDEX_STREAM) - 1;
2575 shifted_values = ((*track_stream & shifted_values_mask)
2576 << BITS_PER_INDEX_STREAM);
2578 STREAM_MASK << i * BITS_PER_INDEX_STREAM;
2580 *track_stream & ~(shifted_values_mask |
2583 unshifted_values | shifted_values | stream_num;
2588 * if we did not find any stream, create a new one
2589 * from the least recently used
2591 stream_num = (*track_stream >>
2592 ((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) &
2594 current_sd = ¤t_ld_sd->stream_track[stream_num];
2595 current_sd->is_read = io_info->isRead;
2596 current_sd->next_seq_lba = io_info->ldStartBlock + io_info->numBlocks;
2597 *track_stream = (((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num);
2602 * megasas_set_raidflag_cpu_affinity - This function sets the cpu
2603 * affinity (cpu of the controller) and raid_flags in the raid context
2606 * @praid_context: IO RAID context
2607 * @raid: LD raid map
2608 * @fp_possible: Is fast path possible?
2609 * @is_read: Is read IO?
2613 megasas_set_raidflag_cpu_affinity(struct fusion_context *fusion,
2614 union RAID_CONTEXT_UNION *praid_context,
2615 struct MR_LD_RAID *raid, bool fp_possible,
2616 u8 is_read, u32 scsi_buff_len)
2618 u8 cpu_sel = MR_RAID_CTX_CPUSEL_0;
2619 struct RAID_CONTEXT_G35 *rctx_g35;
2621 rctx_g35 = &praid_context->raid_context_g35;
2624 if ((raid->cpuAffinity.pdRead.cpu0) &&
2625 (raid->cpuAffinity.pdRead.cpu1))
2626 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2627 else if (raid->cpuAffinity.pdRead.cpu1)
2628 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2630 if ((raid->cpuAffinity.pdWrite.cpu0) &&
2631 (raid->cpuAffinity.pdWrite.cpu1))
2632 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2633 else if (raid->cpuAffinity.pdWrite.cpu1)
2634 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2635 /* Fast path cache by pass capable R0/R1 VD */
2636 if ((raid->level <= 1) &&
2637 (raid->capability.fp_cache_bypass_capable)) {
2638 rctx_g35->routing_flags |=
2639 (1 << MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT);
2640 rctx_g35->raid_flags =
2641 (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
2642 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2647 if ((raid->cpuAffinity.ldRead.cpu0) &&
2648 (raid->cpuAffinity.ldRead.cpu1))
2649 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2650 else if (raid->cpuAffinity.ldRead.cpu1)
2651 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2653 if ((raid->cpuAffinity.ldWrite.cpu0) &&
2654 (raid->cpuAffinity.ldWrite.cpu1))
2655 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2656 else if (raid->cpuAffinity.ldWrite.cpu1)
2657 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2659 if (is_stream_detected(rctx_g35) &&
2660 ((raid->level == 5) || (raid->level == 6)) &&
2661 (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) &&
2662 (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS))
2663 cpu_sel = MR_RAID_CTX_CPUSEL_0;
2667 rctx_g35->routing_flags |=
2668 (cpu_sel << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2670 /* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2671 * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS.
2672 * IO Subtype is not bitmap.
2674 if ((fusion->pcie_bw_limitation) && (raid->level == 1) && (!is_read) &&
2675 (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)) {
2676 praid_context->raid_context_g35.raid_flags =
2677 (MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2678 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2683 * megasas_build_ldio_fusion - Prepares IOs to devices
2684 * @instance: Adapter soft state
2685 * @scp: SCSI command
2686 * @cmd: Command to be prepared
2688 * Prepares the io_request and chain elements (sg_frame) for IO
2689 * The IO can be for PD (Fast Path) or LD
2692 megasas_build_ldio_fusion(struct megasas_instance *instance,
2693 struct scsi_cmnd *scp,
2694 struct megasas_cmd_fusion *cmd)
2698 u32 start_lba_lo, start_lba_hi, device_id, datalength = 0;
2700 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
2701 struct IO_REQUEST_INFO io_info;
2702 struct fusion_context *fusion;
2703 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
2705 unsigned long spinlock_flags;
2706 struct MR_LD_RAID *raid = NULL;
2707 struct MR_PRIV_DEVICE *mrdev_priv;
2708 struct RAID_CONTEXT *rctx;
2709 struct RAID_CONTEXT_G35 *rctx_g35;
2711 device_id = MEGASAS_DEV_INDEX(scp);
2713 fusion = instance->ctrl_context;
2715 io_request = cmd->io_request;
2716 rctx = &io_request->RaidContext.raid_context;
2717 rctx_g35 = &io_request->RaidContext.raid_context_g35;
2719 rctx->virtual_disk_tgt_id = cpu_to_le16(device_id);
2721 rctx->ex_status = 0;
2725 fp_possible = false;
2728 * 6-byte READ(0x08) or WRITE(0x0A) cdb
2730 if (scp->cmd_len == 6) {
2731 datalength = (u32) scp->cmnd[4];
2732 start_lba_lo = ((u32) scp->cmnd[1] << 16) |
2733 ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3];
2735 start_lba_lo &= 0x1FFFFF;
2739 * 10-byte READ(0x28) or WRITE(0x2A) cdb
2741 else if (scp->cmd_len == 10) {
2742 datalength = (u32) scp->cmnd[8] |
2743 ((u32) scp->cmnd[7] << 8);
2744 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
2745 ((u32) scp->cmnd[3] << 16) |
2746 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2750 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
2752 else if (scp->cmd_len == 12) {
2753 datalength = ((u32) scp->cmnd[6] << 24) |
2754 ((u32) scp->cmnd[7] << 16) |
2755 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
2756 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
2757 ((u32) scp->cmnd[3] << 16) |
2758 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2762 * 16-byte READ(0x88) or WRITE(0x8A) cdb
2764 else if (scp->cmd_len == 16) {
2765 datalength = ((u32) scp->cmnd[10] << 24) |
2766 ((u32) scp->cmnd[11] << 16) |
2767 ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13];
2768 start_lba_lo = ((u32) scp->cmnd[6] << 24) |
2769 ((u32) scp->cmnd[7] << 16) |
2770 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
2772 start_lba_hi = ((u32) scp->cmnd[2] << 24) |
2773 ((u32) scp->cmnd[3] << 16) |
2774 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2777 memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO));
2778 io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
2779 io_info.numBlocks = datalength;
2780 io_info.ldTgtId = device_id;
2781 io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2782 scsi_buff_len = scsi_bufflen(scp);
2783 io_request->DataLength = cpu_to_le32(scsi_buff_len);
2784 io_info.data_arms = 1;
2786 if (scp->sc_data_direction == DMA_FROM_DEVICE)
2789 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2790 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
2792 if (ld < instance->fw_supported_vd_count)
2793 raid = MR_LdRaidGet(ld, local_map_ptr);
2795 if (!raid || (!fusion->fast_path_io)) {
2796 rctx->reg_lock_flags = 0;
2797 fp_possible = false;
2799 if (MR_BuildRaidContext(instance, &io_info, rctx,
2800 local_map_ptr, &raidLUN))
2801 fp_possible = (io_info.fpOkForIo > 0) ? true : false;
2804 megasas_get_msix_index(instance, scp, cmd, io_info.data_arms);
2806 if (instance->adapter_type >= VENTURA_SERIES) {
2807 /* FP for Optimal raid level 1.
2808 * All large RAID-1 writes (> 32 KiB, both WT and WB modes)
2809 * are built by the driver as LD I/Os.
2810 * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os
2811 * (there is never a reason to process these as buffered writes)
2812 * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os
2813 * with the SLD bit asserted.
2815 if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
2816 mrdev_priv = scp->device->hostdata;
2818 if (atomic_inc_return(&instance->fw_outstanding) >
2819 (instance->host->can_queue)) {
2820 fp_possible = false;
2821 atomic_dec(&instance->fw_outstanding);
2822 } else if (fusion->pcie_bw_limitation &&
2823 ((scsi_buff_len > MR_LARGE_IO_MIN_SIZE) ||
2824 (atomic_dec_if_positive(&mrdev_priv->r1_ldio_hint) > 0))) {
2825 fp_possible = false;
2826 atomic_dec(&instance->fw_outstanding);
2827 if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
2828 atomic_set(&mrdev_priv->r1_ldio_hint,
2829 instance->r1_ldio_hint_default);
2834 (io_info.isRead && io_info.ra_capable)) {
2835 spin_lock_irqsave(&instance->stream_lock,
2837 megasas_stream_detect(instance, cmd, &io_info);
2838 spin_unlock_irqrestore(&instance->stream_lock,
2840 /* In ventura if stream detected for a read and it is
2841 * read ahead capable make this IO as LDIO
2843 if (is_stream_detected(rctx_g35))
2844 fp_possible = false;
2847 /* If raid is NULL, set CPU affinity to default CPU0 */
2849 megasas_set_raidflag_cpu_affinity(fusion, &io_request->RaidContext,
2850 raid, fp_possible, io_info.isRead,
2853 rctx_g35->routing_flags |=
2854 (MR_RAID_CTX_CPUSEL_0 << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2858 megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
2859 local_map_ptr, start_lba_lo);
2860 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2861 cmd->request_desc->SCSIIO.RequestFlags =
2862 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
2863 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2864 if (instance->adapter_type == INVADER_SERIES) {
2865 rctx->type = MPI2_TYPE_CUDA;
2867 io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
2868 rctx->reg_lock_flags |=
2869 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
2870 MR_RL_FLAGS_SEQ_NUM_ENABLE);
2871 } else if (instance->adapter_type >= VENTURA_SERIES) {
2872 rctx_g35->nseg_type |= (1 << RAID_CONTEXT_NSEG_SHIFT);
2873 rctx_g35->nseg_type |= (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2874 rctx_g35->routing_flags |= (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2875 io_request->IoFlags |=
2876 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
2878 if (fusion->load_balance_info &&
2879 (fusion->load_balance_info[device_id].loadBalanceFlag) &&
2882 get_updated_dev_handle(instance,
2883 &fusion->load_balance_info[device_id],
2884 &io_info, local_map_ptr);
2885 scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
2886 cmd->pd_r1_lb = io_info.pd_after_lb;
2887 if (instance->adapter_type >= VENTURA_SERIES)
2888 rctx_g35->span_arm = io_info.span_arm;
2890 rctx->span_arm = io_info.span_arm;
2893 scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
2895 if (instance->adapter_type >= VENTURA_SERIES)
2896 cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle;
2898 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2900 if ((raidLUN[0] == 1) &&
2901 (local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) {
2902 instance->dev_handle = !(instance->dev_handle);
2904 local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].devHandle[instance->dev_handle];
2907 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
2908 io_request->DevHandle = io_info.devHandle;
2909 cmd->pd_interface = io_info.pd_interface;
2910 /* populate the LUN field */
2911 memcpy(io_request->LUN, raidLUN, 8);
2913 rctx->timeout_value =
2914 cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec);
2915 cmd->request_desc->SCSIIO.RequestFlags =
2916 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
2917 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2918 if (instance->adapter_type == INVADER_SERIES) {
2919 if (io_info.do_fp_rlbypass ||
2920 (rctx->reg_lock_flags == REGION_TYPE_UNUSED))
2921 cmd->request_desc->SCSIIO.RequestFlags =
2922 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
2923 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2924 rctx->type = MPI2_TYPE_CUDA;
2925 rctx->reg_lock_flags |=
2926 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
2927 MR_RL_FLAGS_SEQ_NUM_ENABLE);
2929 } else if (instance->adapter_type >= VENTURA_SERIES) {
2930 rctx_g35->routing_flags |= (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2931 rctx_g35->nseg_type |= (1 << RAID_CONTEXT_NSEG_SHIFT);
2932 rctx_g35->nseg_type |= (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2934 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
2935 io_request->DevHandle = cpu_to_le16(device_id);
2941 * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk
2942 * @instance: Adapter soft state
2943 * @scp: SCSI command
2944 * @cmd: Command to be prepared
2946 * Prepares the io_request frame for non-rw io cmds for vd.
2948 static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
2949 struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd)
2952 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
2954 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
2955 struct fusion_context *fusion = instance->ctrl_context;
2959 struct MR_LD_RAID *raid;
2960 struct RAID_CONTEXT *pRAID_Context;
2963 io_request = cmd->io_request;
2964 device_id = MEGASAS_DEV_INDEX(scmd);
2965 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2966 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2967 /* get RAID_Context pointer */
2968 pRAID_Context = &io_request->RaidContext.raid_context;
2969 /* Check with FW team */
2970 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2971 pRAID_Context->reg_lock_row_lba = 0;
2972 pRAID_Context->reg_lock_length = 0;
2974 if (fusion->fast_path_io && (
2975 device_id < instance->fw_supported_vd_count)) {
2977 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
2978 if (ld >= instance->fw_supported_vd_count - 1)
2981 raid = MR_LdRaidGet(ld, local_map_ptr);
2982 if (!(raid->capability.fpNonRWCapable))
2989 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
2990 io_request->DevHandle = cpu_to_le16(device_id);
2991 io_request->LUN[1] = scmd->device->lun;
2992 pRAID_Context->timeout_value =
2993 cpu_to_le16 (scmd->request->timeout / HZ);
2994 cmd->request_desc->SCSIIO.RequestFlags =
2995 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
2996 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2999 /* set RAID context values */
3000 pRAID_Context->config_seq_num = raid->seqNum;
3001 if (instance->adapter_type < VENTURA_SERIES)
3002 pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ;
3003 pRAID_Context->timeout_value =
3004 cpu_to_le16(raid->fpIoTimeoutForLd);
3006 /* get the DevHandle for the PD (since this is
3007 fpNonRWCapable, this is a single disk RAID0) */
3009 arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr);
3010 pd = MR_ArPdGet(arRef, physArm, local_map_ptr);
3011 devHandle = MR_PdDevHandleGet(pd, local_map_ptr);
3013 /* build request descriptor */
3014 cmd->request_desc->SCSIIO.RequestFlags =
3015 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO <<
3016 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3017 cmd->request_desc->SCSIIO.DevHandle = devHandle;
3019 /* populate the LUN field */
3020 memcpy(io_request->LUN, raid->LUN, 8);
3022 /* build the raidScsiIO structure */
3023 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3024 io_request->DevHandle = devHandle;
3029 * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd
3030 * @instance: Adapter soft state
3031 * @scp: SCSI command
3032 * @cmd: Command to be prepared
3033 * @fp_possible: parameter to detect fast path or firmware path io.
3035 * Prepares the io_request frame for rw/non-rw io cmds for syspds
3038 megasas_build_syspd_fusion(struct megasas_instance *instance,
3039 struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd,
3043 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
3045 u16 os_timeout_value;
3047 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
3048 struct RAID_CONTEXT *pRAID_Context;
3049 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
3050 struct MR_PRIV_DEVICE *mr_device_priv_data;
3051 struct fusion_context *fusion = instance->ctrl_context;
3052 pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id - 1) & 1];
3054 device_id = MEGASAS_DEV_INDEX(scmd);
3055 pd_index = MEGASAS_PD_INDEX(scmd);
3056 os_timeout_value = scmd->request->timeout / HZ;
3057 mr_device_priv_data = scmd->device->hostdata;
3058 cmd->pd_interface = mr_device_priv_data->interface_type;
3060 io_request = cmd->io_request;
3061 /* get RAID_Context pointer */
3062 pRAID_Context = &io_request->RaidContext.raid_context;
3063 pRAID_Context->reg_lock_flags = 0;
3064 pRAID_Context->reg_lock_row_lba = 0;
3065 pRAID_Context->reg_lock_length = 0;
3066 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3067 io_request->LUN[1] = scmd->device->lun;
3068 pRAID_Context->raid_flags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
3069 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
3071 /* If FW supports PD sequence number */
3072 if (instance->support_seqnum_jbod_fp) {
3073 if (instance->use_seqnum_jbod_fp &&
3074 instance->pd_list[pd_index].driveType == TYPE_DISK) {
3076 /* More than 256 PD/JBOD support for Ventura */
3077 if (instance->support_morethan256jbod)
3078 pRAID_Context->virtual_disk_tgt_id =
3079 pd_sync->seq[pd_index].pd_target_id;
3081 pRAID_Context->virtual_disk_tgt_id =
3082 cpu_to_le16(device_id +
3083 (MAX_PHYSICAL_DEVICES - 1));
3084 pRAID_Context->config_seq_num =
3085 pd_sync->seq[pd_index].seqNum;
3086 io_request->DevHandle =
3087 pd_sync->seq[pd_index].devHandle;
3088 if (instance->adapter_type >= VENTURA_SERIES) {
3089 io_request->RaidContext.raid_context_g35.routing_flags |=
3090 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
3091 io_request->RaidContext.raid_context_g35.nseg_type |=
3092 (1 << RAID_CONTEXT_NSEG_SHIFT);
3093 io_request->RaidContext.raid_context_g35.nseg_type |=
3094 (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
3096 pRAID_Context->type = MPI2_TYPE_CUDA;
3097 pRAID_Context->nseg = 0x1;
3098 pRAID_Context->reg_lock_flags |=
3099 (MR_RL_FLAGS_SEQ_NUM_ENABLE |
3100 MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
3103 pRAID_Context->virtual_disk_tgt_id =
3104 cpu_to_le16(device_id +
3105 (MAX_PHYSICAL_DEVICES - 1));
3106 pRAID_Context->config_seq_num = 0;
3107 io_request->DevHandle = cpu_to_le16(0xFFFF);
3110 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
3111 pRAID_Context->config_seq_num = 0;
3113 if (fusion->fast_path_io) {
3115 fusion->ld_drv_map[(instance->map_id & 1)];
3116 io_request->DevHandle =
3117 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
3119 io_request->DevHandle = cpu_to_le16(0xFFFF);
3123 cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle;
3125 megasas_get_msix_index(instance, scmd, cmd, 1);
3128 /* system pd firmware path */
3129 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
3130 cmd->request_desc->SCSIIO.RequestFlags =
3131 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
3132 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3133 pRAID_Context->timeout_value = cpu_to_le16(os_timeout_value);
3134 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
3136 if (os_timeout_value)
3139 /* system pd Fast Path */
3140 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3141 timeout_limit = (scmd->device->type == TYPE_DISK) ?
3143 pRAID_Context->timeout_value =
3144 cpu_to_le16((os_timeout_value > timeout_limit) ?
3145 timeout_limit : os_timeout_value);
3146 if (instance->adapter_type >= INVADER_SERIES)
3147 io_request->IoFlags |=
3148 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
3150 cmd->request_desc->SCSIIO.RequestFlags =
3151 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO <<
3152 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3157 * megasas_build_io_fusion - Prepares IOs to devices
3158 * @instance: Adapter soft state
3159 * @scp: SCSI command
3160 * @cmd: Command to be prepared
3162 * Invokes helper functions to prepare request frames
3163 * and sets flags appropriate for IO/Non-IO cmd
3166 megasas_build_io_fusion(struct megasas_instance *instance,
3167 struct scsi_cmnd *scp,
3168 struct megasas_cmd_fusion *cmd)
3172 struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
3173 struct MR_PRIV_DEVICE *mr_device_priv_data;
3174 mr_device_priv_data = scp->device->hostdata;
3176 /* Zero out some fields so they don't get reused */
3177 memset(io_request->LUN, 0x0, 8);
3178 io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
3179 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
3180 io_request->EEDPFlags = 0;
3181 io_request->Control = 0;
3182 io_request->EEDPBlockSize = 0;
3183 io_request->ChainOffset = 0;
3184 io_request->RaidContext.raid_context.raid_flags = 0;
3185 io_request->RaidContext.raid_context.type = 0;
3186 io_request->RaidContext.raid_context.nseg = 0;
3188 memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
3190 * Just the CDB length,rest of the Flags are zero
3191 * This will be modified for FP in build_ldio_fusion
3193 io_request->IoFlags = cpu_to_le16(scp->cmd_len);
3195 switch (cmd_type = megasas_cmd_type(scp)) {
3196 case READ_WRITE_LDIO:
3197 megasas_build_ldio_fusion(instance, scp, cmd);
3199 case NON_READ_WRITE_LDIO:
3200 megasas_build_ld_nonrw_fusion(instance, scp, cmd);
3202 case READ_WRITE_SYSPDIO:
3203 megasas_build_syspd_fusion(instance, scp, cmd, true);
3205 case NON_READ_WRITE_SYSPDIO:
3206 if (instance->secure_jbod_support ||
3207 mr_device_priv_data->is_tm_capable)
3208 megasas_build_syspd_fusion(instance, scp, cmd, false);
3210 megasas_build_syspd_fusion(instance, scp, cmd, true);
3220 sge_count = megasas_make_sgl(instance, scp, cmd);
3222 if (sge_count > instance->max_num_sge || (sge_count < 0)) {
3223 dev_err(&instance->pdev->dev,
3224 "%s %d sge_count (%d) is out of range. Range is: 0-%d\n",
3225 __func__, __LINE__, sge_count, instance->max_num_sge);
3229 if (instance->adapter_type >= VENTURA_SERIES) {
3230 set_num_sge(&io_request->RaidContext.raid_context_g35, sge_count);
3231 cpu_to_le16s(&io_request->RaidContext.raid_context_g35.routing_flags);
3232 cpu_to_le16s(&io_request->RaidContext.raid_context_g35.nseg_type);
3234 /* numSGE store lower 8 bit of sge_count.
3235 * numSGEExt store higher 8 bit of sge_count
3237 io_request->RaidContext.raid_context.num_sge = sge_count;
3238 io_request->RaidContext.raid_context.num_sge_ext =
3239 (u8)(sge_count >> 8);
3242 io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING);
3244 if (scp->sc_data_direction == DMA_TO_DEVICE)
3245 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE);
3246 else if (scp->sc_data_direction == DMA_FROM_DEVICE)
3247 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ);
3249 io_request->SGLOffset0 =
3250 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4;
3252 io_request->SenseBufferLowAddress =
3253 cpu_to_le32(lower_32_bits(cmd->sense_phys_addr));
3254 io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3257 scp->SCp.ptr = (char *)cmd;
3262 static union MEGASAS_REQUEST_DESCRIPTOR_UNION *
3263 megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
3266 struct fusion_context *fusion;
3268 fusion = instance->ctrl_context;
3269 p = fusion->req_frames_desc +
3270 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * index;
3272 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
3276 /* megasas_prepate_secondRaid1_IO
3277 * It prepares the raid 1 second IO
3279 static void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance,
3280 struct megasas_cmd_fusion *cmd,
3281 struct megasas_cmd_fusion *r1_cmd)
3283 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL;
3284 struct fusion_context *fusion;
3285 fusion = instance->ctrl_context;
3286 req_desc = cmd->request_desc;
3287 /* copy the io request frame as well as 8 SGEs data for r1 command*/
3288 memcpy(r1_cmd->io_request, cmd->io_request,
3289 (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)));
3290 memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
3291 (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION)));
3292 /*sense buffer is different for r1 command*/
3293 r1_cmd->io_request->SenseBufferLowAddress =
3294 cpu_to_le32(lower_32_bits(r1_cmd->sense_phys_addr));
3295 r1_cmd->scmd = cmd->scmd;
3296 req_desc2 = megasas_get_request_descriptor(instance,
3297 (r1_cmd->index - 1));
3298 req_desc2->Words = 0;
3299 r1_cmd->request_desc = req_desc2;
3300 req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index);
3301 req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags;
3302 r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle;
3303 r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
3304 r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle;
3305 cmd->io_request->RaidContext.raid_context_g35.flow_specific.peer_smid =
3306 cpu_to_le16(r1_cmd->index);
3307 r1_cmd->io_request->RaidContext.raid_context_g35.flow_specific.peer_smid =
3308 cpu_to_le16(cmd->index);
3309 /*MSIxIndex of both commands request descriptors should be same*/
3310 r1_cmd->request_desc->SCSIIO.MSIxIndex =
3311 cmd->request_desc->SCSIIO.MSIxIndex;
3312 /*span arm is different for r1 cmd*/
3313 r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
3314 cmd->io_request->RaidContext.raid_context_g35.span_arm + 1;
3318 * megasas_build_and_issue_cmd_fusion -Main routine for building and
3319 * issuing non IOCTL cmd
3320 * @instance: Adapter soft state
3321 * @scmd: pointer to scsi cmd from OS
3324 megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
3325 struct scsi_cmnd *scmd)
3327 struct megasas_cmd_fusion *cmd, *r1_cmd = NULL;
3328 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3331 if ((megasas_cmd_type(scmd) == READ_WRITE_LDIO) &&
3332 instance->ldio_threshold &&
3333 (atomic_inc_return(&instance->ldio_outstanding) >
3334 instance->ldio_threshold)) {
3335 atomic_dec(&instance->ldio_outstanding);
3336 return SCSI_MLQUEUE_DEVICE_BUSY;
3339 if (atomic_inc_return(&instance->fw_outstanding) >
3340 instance->host->can_queue) {
3341 atomic_dec(&instance->fw_outstanding);
3342 return SCSI_MLQUEUE_HOST_BUSY;
3345 cmd = megasas_get_cmd_fusion(instance, scmd->request->tag);
3348 atomic_dec(&instance->fw_outstanding);
3349 return SCSI_MLQUEUE_HOST_BUSY;
3354 req_desc = megasas_get_request_descriptor(instance, index-1);
3356 req_desc->Words = 0;
3357 cmd->request_desc = req_desc;
3359 if (megasas_build_io_fusion(instance, scmd, cmd)) {
3360 megasas_return_cmd_fusion(instance, cmd);
3361 dev_err(&instance->pdev->dev, "Error building command\n");
3362 cmd->request_desc = NULL;
3363 atomic_dec(&instance->fw_outstanding);
3364 return SCSI_MLQUEUE_HOST_BUSY;
3367 req_desc = cmd->request_desc;
3368 req_desc->SCSIIO.SMID = cpu_to_le16(index);
3370 if (cmd->io_request->ChainOffset != 0 &&
3371 cmd->io_request->ChainOffset != 0xF)
3372 dev_err(&instance->pdev->dev, "The chain offset value is not "
3373 "correct : %x\n", cmd->io_request->ChainOffset);
3375 * if it is raid 1/10 fp write capable.
3376 * try to get second command from pool and construct it.
3377 * From FW, it has confirmed that lba values of two PDs
3378 * corresponds to single R1/10 LD are always same
3381 /* driver side count always should be less than max_fw_cmds
3382 * to get new command
3384 if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
3385 r1_cmd = megasas_get_cmd_fusion(instance,
3386 (scmd->request->tag + instance->max_fw_cmds));
3387 megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
3392 * Issue the command to the FW
3395 megasas_fire_cmd_fusion(instance, req_desc);
3398 megasas_fire_cmd_fusion(instance, r1_cmd->request_desc);
3405 * megasas_complete_r1_command -
3406 * completes R1 FP write commands which has valid peer smid
3407 * @instance: Adapter soft state
3408 * @cmd_fusion: MPT command frame
3412 megasas_complete_r1_command(struct megasas_instance *instance,
3413 struct megasas_cmd_fusion *cmd)
3415 u8 *sense, status, ex_status;
3418 struct fusion_context *fusion;
3419 struct megasas_cmd_fusion *r1_cmd = NULL;
3420 struct scsi_cmnd *scmd_local = NULL;
3421 struct RAID_CONTEXT_G35 *rctx_g35;
3423 rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
3424 fusion = instance->ctrl_context;
3425 peer_smid = le16_to_cpu(rctx_g35->flow_specific.peer_smid);
3427 r1_cmd = fusion->cmd_list[peer_smid - 1];
3428 scmd_local = cmd->scmd;
3429 status = rctx_g35->status;
3430 ex_status = rctx_g35->ex_status;
3431 data_length = cmd->io_request->DataLength;
3434 cmd->cmd_completed = true;
3436 /* Check if peer command is completed or not*/
3437 if (r1_cmd->cmd_completed) {
3438 rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35;
3439 if (rctx_g35->status != MFI_STAT_OK) {
3440 status = rctx_g35->status;
3441 ex_status = rctx_g35->ex_status;
3442 data_length = r1_cmd->io_request->DataLength;
3443 sense = r1_cmd->sense;
3446 megasas_return_cmd_fusion(instance, r1_cmd);
3447 map_cmd_status(fusion, scmd_local, status, ex_status,
3448 le32_to_cpu(data_length), sense);
3449 if (instance->ldio_threshold &&
3450 megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
3451 atomic_dec(&instance->ldio_outstanding);
3452 scmd_local->SCp.ptr = NULL;
3453 megasas_return_cmd_fusion(instance, cmd);
3454 scsi_dma_unmap(scmd_local);
3455 scmd_local->scsi_done(scmd_local);
3460 * complete_cmd_fusion - Completes command
3461 * @instance: Adapter soft state
3462 * Completes all commands that is in reply descriptor queue
3465 complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
3466 struct megasas_irq_context *irq_context)
3468 union MPI2_REPLY_DESCRIPTORS_UNION *desc;
3469 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
3470 struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
3471 struct fusion_context *fusion;
3472 struct megasas_cmd *cmd_mfi;
3473 struct megasas_cmd_fusion *cmd_fusion;
3474 u16 smid, num_completed;
3475 u8 reply_descript_type, *sense, status, extStatus;
3476 u32 device_id, data_length;
3477 union desc_value d_val;
3478 struct LD_LOAD_BALANCE_INFO *lbinfo;
3479 int threshold_reply_count = 0;
3480 struct scsi_cmnd *scmd_local = NULL;
3481 struct MR_TASK_MANAGE_REQUEST *mr_tm_req;
3482 struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_tm_req;
3484 fusion = instance->ctrl_context;
3486 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)
3489 desc = fusion->reply_frames_desc[MSIxIndex] +
3490 fusion->last_reply_idx[MSIxIndex];
3492 reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
3494 d_val.word = desc->Words;
3496 reply_descript_type = reply_desc->ReplyFlags &
3497 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
3499 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
3504 while (d_val.u.low != cpu_to_le32(UINT_MAX) &&
3505 d_val.u.high != cpu_to_le32(UINT_MAX)) {
3507 smid = le16_to_cpu(reply_desc->SMID);
3508 cmd_fusion = fusion->cmd_list[smid - 1];
3509 scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *)
3510 cmd_fusion->io_request;
3512 scmd_local = cmd_fusion->scmd;
3513 status = scsi_io_req->RaidContext.raid_context.status;
3514 extStatus = scsi_io_req->RaidContext.raid_context.ex_status;
3515 sense = cmd_fusion->sense;
3516 data_length = scsi_io_req->DataLength;
3518 switch (scsi_io_req->Function) {
3519 case MPI2_FUNCTION_SCSI_TASK_MGMT:
3520 mr_tm_req = (struct MR_TASK_MANAGE_REQUEST *)
3521 cmd_fusion->io_request;
3522 mpi_tm_req = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *)
3523 &mr_tm_req->TmRequest;
3524 dev_dbg(&instance->pdev->dev, "TM completion:"
3525 "type: 0x%x TaskMID: 0x%x\n",
3526 mpi_tm_req->TaskType, mpi_tm_req->TaskMID);
3527 complete(&cmd_fusion->done);
3529 case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/
3530 /* Update load balancing info */
3531 if (fusion->load_balance_info &&
3532 (cmd_fusion->scmd->SCp.Status &
3533 MEGASAS_LOAD_BALANCE_FLAG)) {
3534 device_id = MEGASAS_DEV_INDEX(scmd_local);
3535 lbinfo = &fusion->load_balance_info[device_id];
3536 atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]);
3537 cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
3539 /* Fall through - and complete IO */
3540 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
3541 atomic_dec(&instance->fw_outstanding);
3542 if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) {
3543 map_cmd_status(fusion, scmd_local, status,
3544 extStatus, le32_to_cpu(data_length),
3546 if (instance->ldio_threshold &&
3547 (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO))
3548 atomic_dec(&instance->ldio_outstanding);
3549 scmd_local->SCp.ptr = NULL;
3550 megasas_return_cmd_fusion(instance, cmd_fusion);
3551 scsi_dma_unmap(scmd_local);
3552 scmd_local->scsi_done(scmd_local);
3553 } else /* Optimal VD - R1 FP command completion. */
3554 megasas_complete_r1_command(instance, cmd_fusion);
3556 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
3557 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
3558 /* Poll mode. Dummy free.
3559 * In case of Interrupt mode, caller has reverse check.
3561 if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) {
3562 cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE;
3563 megasas_return_cmd(instance, cmd_mfi);
3565 megasas_complete_cmd(instance, cmd_mfi, DID_OK);
3569 fusion->last_reply_idx[MSIxIndex]++;
3570 if (fusion->last_reply_idx[MSIxIndex] >=
3571 fusion->reply_q_depth)
3572 fusion->last_reply_idx[MSIxIndex] = 0;
3574 desc->Words = cpu_to_le64(ULLONG_MAX);
3576 threshold_reply_count++;
3578 /* Get the next reply descriptor */
3579 if (!fusion->last_reply_idx[MSIxIndex])
3580 desc = fusion->reply_frames_desc[MSIxIndex];
3585 (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
3587 d_val.word = desc->Words;
3589 reply_descript_type = reply_desc->ReplyFlags &
3590 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
3592 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
3595 * Write to reply post host index register after completing threshold
3596 * number of reply counts and still there are more replies in reply queue
3597 * pending to be completed
3599 if (threshold_reply_count >= instance->threshold_reply_count) {
3600 if (instance->msix_combined)
3601 writel(((MSIxIndex & 0x7) << 24) |
3602 fusion->last_reply_idx[MSIxIndex],
3603 instance->reply_post_host_index_addr[MSIxIndex/8]);
3605 writel((MSIxIndex << 24) |
3606 fusion->last_reply_idx[MSIxIndex],
3607 instance->reply_post_host_index_addr[0]);
3608 threshold_reply_count = 0;
3610 if (!irq_context->irq_poll_scheduled) {
3611 irq_context->irq_poll_scheduled = true;
3612 irq_context->irq_line_enable = true;
3613 irq_poll_sched(&irq_context->irqpoll);
3615 return num_completed;
3620 if (num_completed) {
3622 if (instance->msix_combined)
3623 writel(((MSIxIndex & 0x7) << 24) |
3624 fusion->last_reply_idx[MSIxIndex],
3625 instance->reply_post_host_index_addr[MSIxIndex/8]);
3627 writel((MSIxIndex << 24) |
3628 fusion->last_reply_idx[MSIxIndex],
3629 instance->reply_post_host_index_addr[0]);
3630 megasas_check_and_restore_queue_depth(instance);
3632 return num_completed;
3636 * megasas_enable_irq_poll() - enable irqpoll
3638 static void megasas_enable_irq_poll(struct megasas_instance *instance)
3641 struct megasas_irq_context *irq_ctx;
3643 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3645 for (i = 0; i < count; i++) {
3646 irq_ctx = &instance->irq_context[i];
3647 irq_poll_enable(&irq_ctx->irqpoll);
3652 * megasas_sync_irqs - Synchronizes all IRQs owned by adapter
3653 * @instance: Adapter soft state
3655 static void megasas_sync_irqs(unsigned long instance_addr)
3658 struct megasas_instance *instance =
3659 (struct megasas_instance *)instance_addr;
3660 struct megasas_irq_context *irq_ctx;
3662 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3664 for (i = 0; i < count; i++) {
3665 synchronize_irq(pci_irq_vector(instance->pdev, i));
3666 irq_ctx = &instance->irq_context[i];
3667 irq_poll_disable(&irq_ctx->irqpoll);
3668 if (irq_ctx->irq_poll_scheduled) {
3669 irq_ctx->irq_poll_scheduled = false;
3670 enable_irq(irq_ctx->os_irq);
3676 * megasas_irqpoll() - process a queue for completed reply descriptors
3677 * @irqpoll: IRQ poll structure associated with queue to poll.
3678 * @budget: Threshold of reply descriptors to process per poll.
3680 * Return: The number of entries processed.
3683 int megasas_irqpoll(struct irq_poll *irqpoll, int budget)
3685 struct megasas_irq_context *irq_ctx;
3686 struct megasas_instance *instance;
3689 irq_ctx = container_of(irqpoll, struct megasas_irq_context, irqpoll);
3690 instance = irq_ctx->instance;
3692 if (irq_ctx->irq_line_enable) {
3693 disable_irq(irq_ctx->os_irq);
3694 irq_ctx->irq_line_enable = false;
3697 num_entries = complete_cmd_fusion(instance, irq_ctx->MSIxIndex, irq_ctx);
3698 if (num_entries < budget) {
3699 irq_poll_complete(irqpoll);
3700 irq_ctx->irq_poll_scheduled = false;
3701 enable_irq(irq_ctx->os_irq);
3708 * megasas_complete_cmd_dpc_fusion - Completes command
3709 * @instance: Adapter soft state
3711 * Tasklet to complete cmds
3714 megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
3716 struct megasas_instance *instance =
3717 (struct megasas_instance *)instance_addr;
3718 u32 count, MSIxIndex;
3720 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3722 /* If we have already declared adapter dead, donot complete cmds */
3723 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)
3726 for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++)
3727 complete_cmd_fusion(instance, MSIxIndex, NULL);
3731 * megasas_isr_fusion - isr entry point
3733 static irqreturn_t megasas_isr_fusion(int irq, void *devp)
3735 struct megasas_irq_context *irq_context = devp;
3736 struct megasas_instance *instance = irq_context->instance;
3739 if (instance->mask_interrupts)
3742 #if defined(ENABLE_IRQ_POLL)
3743 if (irq_context->irq_poll_scheduled)
3747 if (!instance->msix_vectors) {
3748 mfiStatus = instance->instancet->clear_intr(instance);
3753 /* If we are resetting, bail */
3754 if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) {
3755 instance->instancet->clear_intr(instance);
3759 return complete_cmd_fusion(instance, irq_context->MSIxIndex, irq_context)
3760 ? IRQ_HANDLED : IRQ_NONE;
3764 * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
3765 * @instance: Adapter soft state
3766 * mfi_cmd: megasas_cmd pointer
3770 build_mpt_mfi_pass_thru(struct megasas_instance *instance,
3771 struct megasas_cmd *mfi_cmd)
3773 struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain;
3774 struct MPI2_RAID_SCSI_IO_REQUEST *io_req;
3775 struct megasas_cmd_fusion *cmd;
3776 struct fusion_context *fusion;
3777 struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr;
3779 fusion = instance->ctrl_context;
3781 cmd = megasas_get_cmd_fusion(instance,
3782 instance->max_scsi_cmds + mfi_cmd->index);
3784 /* Save the smid. To be used for returning the cmd */
3785 mfi_cmd->context.smid = cmd->index;
3788 * For cmds where the flag is set, store the flag and check
3789 * on completion. For cmds with this flag, don't call
3790 * megasas_complete_cmd
3793 if (frame_hdr->flags & cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE))
3794 mfi_cmd->flags |= DRV_DCMD_POLLED_MODE;
3796 io_req = cmd->io_request;
3798 if (instance->adapter_type >= INVADER_SERIES) {
3799 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
3800 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
3801 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
3802 sgl_ptr_end->Flags = 0;
3806 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
3808 io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST;
3809 io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST,
3811 io_req->ChainOffset = fusion->chain_offset_mfi_pthru;
3813 mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr);
3815 mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
3816 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
3818 mpi25_ieee_chain->Length = cpu_to_le32(instance->mfi_frame_size);
3822 * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
3823 * @instance: Adapter soft state
3824 * @cmd: mfi cmd to build
3827 static union MEGASAS_REQUEST_DESCRIPTOR_UNION *
3828 build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
3830 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL;
3833 build_mpt_mfi_pass_thru(instance, cmd);
3834 index = cmd->context.smid;
3836 req_desc = megasas_get_request_descriptor(instance, index - 1);
3838 req_desc->Words = 0;
3839 req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
3840 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3842 req_desc->SCSIIO.SMID = cpu_to_le16(index);
3848 * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
3849 * @instance: Adapter soft state
3850 * @cmd: mfi cmd pointer
3854 megasas_issue_dcmd_fusion(struct megasas_instance *instance,
3855 struct megasas_cmd *cmd)
3857 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3859 req_desc = build_mpt_cmd(instance, cmd);
3861 megasas_fire_cmd_fusion(instance, req_desc);
3866 * megasas_release_fusion - Reverses the FW initialization
3867 * @instance: Adapter soft state
3870 megasas_release_fusion(struct megasas_instance *instance)
3872 megasas_free_ioc_init_cmd(instance);
3873 megasas_free_cmds(instance);
3874 megasas_free_cmds_fusion(instance);
3876 iounmap(instance->reg_set);
3878 pci_release_selected_regions(instance->pdev, 1<<instance->bar);
3882 * megasas_read_fw_status_reg_fusion - returns the current FW status value
3883 * @regs: MFI register set
3886 megasas_read_fw_status_reg_fusion(struct megasas_instance *instance)
3888 return megasas_readl(instance, &instance->reg_set->outbound_scratch_pad_0);
3892 * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3893 * @instance: Controller's soft instance
3894 * return: Number of allocated host crash buffers
3897 megasas_alloc_host_crash_buffer(struct megasas_instance *instance)
3901 for (i = 0; i < MAX_CRASH_DUMP_SIZE; i++) {
3902 instance->crash_buf[i] = vzalloc(CRASH_DMA_BUF_SIZE);
3903 if (!instance->crash_buf[i]) {
3904 dev_info(&instance->pdev->dev, "Firmware crash dump "
3905 "memory allocation failed at index %d\n", i);
3909 instance->drv_buf_alloc = i;
3913 * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3914 * @instance: Controller's soft instance
3917 megasas_free_host_crash_buffer(struct megasas_instance *instance)
3920 for (i = 0; i < instance->drv_buf_alloc; i++) {
3921 if (instance->crash_buf[i])
3922 vfree(instance->crash_buf[i]);
3924 instance->drv_buf_index = 0;
3925 instance->drv_buf_alloc = 0;
3926 instance->fw_crash_state = UNAVAILABLE;
3927 instance->fw_crash_buffer_size = 0;
3931 * megasas_adp_reset_fusion - For controller reset
3932 * @regs: MFI register set
3935 megasas_adp_reset_fusion(struct megasas_instance *instance,
3936 struct megasas_register_set __iomem *regs)
3938 u32 host_diag, abs_state, retry;
3940 /* Now try to reset the chip */
3941 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3942 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3943 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3944 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3945 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3946 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3947 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3949 /* Check that the diag write enable (DRWE) bit is on */
3950 host_diag = megasas_readl(instance, &instance->reg_set->fusion_host_diag);
3952 while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) {
3954 host_diag = megasas_readl(instance,
3955 &instance->reg_set->fusion_host_diag);
3956 if (retry++ == 100) {
3957 dev_warn(&instance->pdev->dev,
3958 "Host diag unlock failed from %s %d\n",
3959 __func__, __LINE__);
3963 if (!(host_diag & HOST_DIAG_WRITE_ENABLE))
3966 /* Send chip reset command */
3967 writel(host_diag | HOST_DIAG_RESET_ADAPTER,
3968 &instance->reg_set->fusion_host_diag);
3971 /* Make sure reset adapter bit is cleared */
3972 host_diag = megasas_readl(instance, &instance->reg_set->fusion_host_diag);
3974 while (host_diag & HOST_DIAG_RESET_ADAPTER) {
3976 host_diag = megasas_readl(instance,
3977 &instance->reg_set->fusion_host_diag);
3978 if (retry++ == 1000) {
3979 dev_warn(&instance->pdev->dev,
3980 "Diag reset adapter never cleared %s %d\n",
3981 __func__, __LINE__);
3985 if (host_diag & HOST_DIAG_RESET_ADAPTER)
3988 abs_state = instance->instancet->read_fw_status_reg(instance)
3992 while ((abs_state <= MFI_STATE_FW_INIT) && (retry++ < 1000)) {
3994 abs_state = instance->instancet->
3995 read_fw_status_reg(instance) & MFI_STATE_MASK;
3997 if (abs_state <= MFI_STATE_FW_INIT) {
3998 dev_warn(&instance->pdev->dev,
3999 "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n",
4000 abs_state, __func__, __LINE__);
4008 * megasas_check_reset_fusion - For controller reset check
4009 * @regs: MFI register set
4012 megasas_check_reset_fusion(struct megasas_instance *instance,
4013 struct megasas_register_set __iomem *regs)
4019 * megasas_trigger_snap_dump - Trigger snap dump in FW
4020 * @instance: Soft instance of adapter
4022 static inline void megasas_trigger_snap_dump(struct megasas_instance *instance)
4025 u32 fw_state, abs_state;
4027 if (!instance->disableOnlineCtrlReset) {
4028 dev_info(&instance->pdev->dev, "Trigger snap dump\n");
4029 writel(MFI_ADP_TRIGGER_SNAP_DUMP,
4030 &instance->reg_set->doorbell);
4031 readl(&instance->reg_set->doorbell);
4034 for (j = 0; j < instance->snapdump_wait_time; j++) {
4035 abs_state = instance->instancet->read_fw_status_reg(instance);
4036 fw_state = abs_state & MFI_STATE_MASK;
4037 if (fw_state == MFI_STATE_FAULT) {
4038 dev_printk(KERN_ERR, &instance->pdev->dev,
4039 "FW in FAULT state Fault code:0x%x subcode:0x%x func:%s\n",
4040 abs_state & MFI_STATE_FAULT_CODE,
4041 abs_state & MFI_STATE_FAULT_SUBCODE, __func__);
4048 /* This function waits for outstanding commands on fusion to complete */
4050 megasas_wait_for_outstanding_fusion(struct megasas_instance *instance,
4051 int reason, int *convert)
4053 int i, outstanding, retval = 0, hb_seconds_missed = 0;
4054 u32 fw_state, abs_state;
4055 u32 waittime_for_io_completion;
4057 waittime_for_io_completion =
4058 min_t(u32, resetwaittime,
4059 (resetwaittime - instance->snapdump_wait_time));
4061 if (reason == MFI_IO_TIMEOUT_OCR) {
4062 dev_info(&instance->pdev->dev,
4063 "MFI command is timed out\n");
4064 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
4065 if (instance->snapdump_wait_time)
4066 megasas_trigger_snap_dump(instance);
4071 for (i = 0; i < waittime_for_io_completion; i++) {
4072 /* Check if firmware is in fault state */
4073 abs_state = instance->instancet->read_fw_status_reg(instance);
4074 fw_state = abs_state & MFI_STATE_MASK;
4075 if (fw_state == MFI_STATE_FAULT) {
4076 dev_printk(KERN_ERR, &instance->pdev->dev,
4077 "FW in FAULT state Fault code:0x%x subcode:0x%x func:%s\n",
4078 abs_state & MFI_STATE_FAULT_CODE,
4079 abs_state & MFI_STATE_FAULT_SUBCODE, __func__);
4080 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
4081 if (instance->requestorId && reason) {
4082 dev_warn(&instance->pdev->dev, "SR-IOV Found FW in FAULT"
4083 " state while polling during"
4084 " I/O timeout handling for %d\n",
4085 instance->host->host_no);
4094 /* If SR-IOV VF mode & heartbeat timeout, don't wait */
4095 if (instance->requestorId && !reason) {
4100 /* If SR-IOV VF mode & I/O timeout, check for HB timeout */
4101 if (instance->requestorId && (reason == SCSIIO_TIMEOUT_OCR)) {
4102 if (instance->hb_host_mem->HB.fwCounter !=
4103 instance->hb_host_mem->HB.driverCounter) {
4104 instance->hb_host_mem->HB.driverCounter =
4105 instance->hb_host_mem->HB.fwCounter;
4106 hb_seconds_missed = 0;
4108 hb_seconds_missed++;
4109 if (hb_seconds_missed ==
4110 (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF/HZ)) {
4111 dev_warn(&instance->pdev->dev, "SR-IOV:"
4112 " Heartbeat never completed "
4113 " while polling during I/O "
4114 " timeout handling for "
4116 instance->host->host_no);
4124 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
4125 outstanding = atomic_read(&instance->fw_outstanding);
4129 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
4130 dev_notice(&instance->pdev->dev, "[%2d]waiting for %d "
4131 "commands to complete for scsi%d\n", i,
4132 outstanding, instance->host->host_no);
4137 if (instance->snapdump_wait_time) {
4138 megasas_trigger_snap_dump(instance);
4143 if (atomic_read(&instance->fw_outstanding)) {
4144 dev_err(&instance->pdev->dev, "pending commands remain after waiting, "
4145 "will reset adapter scsi%d.\n",
4146 instance->host->host_no);
4155 void megasas_reset_reply_desc(struct megasas_instance *instance)
4158 struct fusion_context *fusion;
4159 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
4161 fusion = instance->ctrl_context;
4162 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
4163 for (i = 0 ; i < count ; i++) {
4164 fusion->last_reply_idx[i] = 0;
4165 reply_desc = fusion->reply_frames_desc[i];
4166 for (j = 0 ; j < fusion->reply_q_depth; j++, reply_desc++)
4167 reply_desc->Words = cpu_to_le64(ULLONG_MAX);
4172 * megasas_refire_mgmt_cmd : Re-fire management commands
4173 * @instance: Controller's soft instance
4175 static void megasas_refire_mgmt_cmd(struct megasas_instance *instance,
4179 struct megasas_cmd_fusion *cmd_fusion;
4180 struct fusion_context *fusion;
4181 struct megasas_cmd *cmd_mfi;
4182 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
4184 bool refire_cmd = false;
4188 fusion = instance->ctrl_context;
4190 /* Re-fire management commands.
4191 * Do not traverse complet MPT frame pool. Start from max_scsi_cmds.
4193 for (j = instance->max_scsi_cmds ; j < instance->max_fw_cmds; j++) {
4194 cmd_fusion = fusion->cmd_list[j];
4195 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
4196 smid = le16_to_cpu(cmd_mfi->context.smid);
4197 result = REFIRE_CMD;
4202 req_desc = megasas_get_request_descriptor(instance, smid - 1);
4204 switch (cmd_mfi->frame->hdr.cmd) {
4206 opcode = le32_to_cpu(cmd_mfi->frame->dcmd.opcode);
4207 /* Do not refire shutdown command */
4208 if (opcode == MR_DCMD_CTRL_SHUTDOWN) {
4209 cmd_mfi->frame->dcmd.cmd_status = MFI_STAT_OK;
4210 result = COMPLETE_CMD;
4214 refire_cmd = ((opcode != MR_DCMD_LD_MAP_GET_INFO)) &&
4215 (opcode != MR_DCMD_SYSTEM_PD_MAP_GET_INFO) &&
4216 !(cmd_mfi->flags & DRV_DCMD_SKIP_REFIRE);
4219 result = RETURN_CMD;
4223 if (!instance->support_nvme_passthru) {
4224 cmd_mfi->frame->hdr.cmd_status = MFI_STAT_INVALID_CMD;
4225 result = COMPLETE_CMD;
4229 case MFI_CMD_TOOLBOX:
4230 if (!instance->support_pci_lane_margining) {
4231 cmd_mfi->frame->hdr.cmd_status = MFI_STAT_INVALID_CMD;
4232 result = COMPLETE_CMD;
4240 if (return_ioctl && cmd_mfi->sync_cmd &&
4241 cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT) {
4242 dev_err(&instance->pdev->dev,
4243 "return -EBUSY from %s %d cmd 0x%x opcode 0x%x\n",
4244 __func__, __LINE__, cmd_mfi->frame->hdr.cmd,
4245 le32_to_cpu(cmd_mfi->frame->dcmd.opcode));
4246 cmd_mfi->cmd_status_drv = DCMD_BUSY;
4247 result = COMPLETE_CMD;
4252 megasas_fire_cmd_fusion(instance, req_desc);
4255 megasas_return_cmd(instance, cmd_mfi);
4258 megasas_complete_cmd(instance, cmd_mfi, DID_OK);
4265 * megasas_return_polled_cmds: Return polled mode commands back to the pool
4266 * before initiating an OCR.
4267 * @instance: Controller's soft instance
4270 megasas_return_polled_cmds(struct megasas_instance *instance)
4273 struct megasas_cmd_fusion *cmd_fusion;
4274 struct fusion_context *fusion;
4275 struct megasas_cmd *cmd_mfi;
4277 fusion = instance->ctrl_context;
4279 for (i = instance->max_scsi_cmds; i < instance->max_fw_cmds; i++) {
4280 cmd_fusion = fusion->cmd_list[i];
4281 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
4283 if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) {
4284 if (megasas_dbg_lvl & OCR_DEBUG)
4285 dev_info(&instance->pdev->dev,
4286 "%s %d return cmd 0x%x opcode 0x%x\n",
4287 __func__, __LINE__, cmd_mfi->frame->hdr.cmd,
4288 le32_to_cpu(cmd_mfi->frame->dcmd.opcode));
4289 cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE;
4290 megasas_return_cmd(instance, cmd_mfi);
4296 * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device
4297 * @instance: per adapter struct
4298 * @channel: the channel assigned by the OS
4299 * @id: the id assigned by the OS
4301 * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED
4304 static int megasas_track_scsiio(struct megasas_instance *instance,
4305 int id, int channel)
4308 struct megasas_cmd_fusion *cmd_fusion;
4309 struct fusion_context *fusion;
4310 fusion = instance->ctrl_context;
4312 for (i = 0 ; i < instance->max_scsi_cmds; i++) {
4313 cmd_fusion = fusion->cmd_list[i];
4314 if (cmd_fusion->scmd &&
4315 (cmd_fusion->scmd->device->id == id &&
4316 cmd_fusion->scmd->device->channel == channel)) {
4317 dev_info(&instance->pdev->dev,
4318 "SCSI commands pending to target"
4319 "channel %d id %d \tSMID: 0x%x\n",
4320 channel, id, cmd_fusion->index);
4321 scsi_print_command(cmd_fusion->scmd);
4327 return found ? FAILED : SUCCESS;
4331 * megasas_tm_response_code - translation of device response code
4332 * @ioc: per adapter object
4333 * @mpi_reply: MPI reply returned by firmware
4338 megasas_tm_response_code(struct megasas_instance *instance,
4339 struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply)
4343 switch (mpi_reply->ResponseCode) {
4344 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
4345 desc = "task management request completed";
4347 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
4348 desc = "invalid frame";
4350 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
4351 desc = "task management request not supported";
4353 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
4354 desc = "task management request failed";
4356 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
4357 desc = "task management request succeeded";
4359 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
4360 desc = "invalid lun";
4363 desc = "overlapped tag attempted";
4365 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
4366 desc = "task queued, however not sent to target";
4372 dev_dbg(&instance->pdev->dev, "response_code(%01x): %s\n",
4373 mpi_reply->ResponseCode, desc);
4374 dev_dbg(&instance->pdev->dev,
4375 "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo"
4376 " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n",
4377 mpi_reply->TerminationCount, mpi_reply->DevHandle,
4378 mpi_reply->Function, mpi_reply->TaskType,
4379 mpi_reply->IOCStatus, mpi_reply->IOCLogInfo);
4383 * megasas_issue_tm - main routine for sending tm requests
4384 * @instance: per adapter struct
4385 * @device_handle: device handle
4386 * @channel: the channel assigned by the OS
4387 * @id: the id assigned by the OS
4388 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c)
4389 * @smid_task: smid assigned to the task
4390 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
4393 * MegaRaid use MPT interface for Task Magement request.
4394 * A generic API for sending task management requests to firmware.
4396 * Return SUCCESS or FAILED.
4399 megasas_issue_tm(struct megasas_instance *instance, u16 device_handle,
4400 uint channel, uint id, u16 smid_task, u8 type,
4401 struct MR_PRIV_DEVICE *mr_device_priv_data)
4403 struct MR_TASK_MANAGE_REQUEST *mr_request;
4404 struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_request;
4405 unsigned long timeleft;
4406 struct megasas_cmd_fusion *cmd_fusion;
4407 struct megasas_cmd *cmd_mfi;
4408 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
4409 struct fusion_context *fusion = NULL;
4410 struct megasas_cmd_fusion *scsi_lookup;
4412 int timeout = MEGASAS_DEFAULT_TM_TIMEOUT;
4413 struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply;
4415 fusion = instance->ctrl_context;
4417 cmd_mfi = megasas_get_cmd(instance);
4420 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
4421 __func__, __LINE__);
4425 cmd_fusion = megasas_get_cmd_fusion(instance,
4426 instance->max_scsi_cmds + cmd_mfi->index);
4428 /* Save the smid. To be used for returning the cmd */
4429 cmd_mfi->context.smid = cmd_fusion->index;
4431 req_desc = megasas_get_request_descriptor(instance,
4432 (cmd_fusion->index - 1));
4434 cmd_fusion->request_desc = req_desc;
4435 req_desc->Words = 0;
4437 mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request;
4438 memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST));
4439 mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) &mr_request->TmRequest;
4440 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
4441 mpi_request->DevHandle = cpu_to_le16(device_handle);
4442 mpi_request->TaskType = type;
4443 mpi_request->TaskMID = cpu_to_le16(smid_task);
4444 mpi_request->LUN[1] = 0;
4447 req_desc = cmd_fusion->request_desc;
4448 req_desc->HighPriority.SMID = cpu_to_le16(cmd_fusion->index);
4449 req_desc->HighPriority.RequestFlags =
4450 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
4451 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
4452 req_desc->HighPriority.MSIxIndex = 0;
4453 req_desc->HighPriority.LMID = 0;
4454 req_desc->HighPriority.Reserved1 = 0;
4456 if (channel < MEGASAS_MAX_PD_CHANNELS)
4457 mr_request->tmReqFlags.isTMForPD = 1;
4459 mr_request->tmReqFlags.isTMForLD = 1;
4461 init_completion(&cmd_fusion->done);
4462 megasas_fire_cmd_fusion(instance, req_desc);
4465 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
4466 timeout = mr_device_priv_data->task_abort_tmo;
4468 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
4469 timeout = mr_device_priv_data->target_reset_tmo;
4473 timeleft = wait_for_completion_timeout(&cmd_fusion->done, timeout * HZ);
4476 dev_err(&instance->pdev->dev,
4477 "task mgmt type 0x%x timed out\n", type);
4478 cmd_mfi->flags |= DRV_DCMD_SKIP_REFIRE;
4479 mutex_unlock(&instance->reset_mutex);
4480 rc = megasas_reset_fusion(instance->host, MFI_IO_TIMEOUT_OCR);
4481 mutex_lock(&instance->reset_mutex);
4485 mpi_reply = (struct MPI2_SCSI_TASK_MANAGE_REPLY *) &mr_request->TMReply;
4486 megasas_tm_response_code(instance, mpi_reply);
4488 megasas_return_cmd(instance, cmd_mfi);
4491 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
4492 scsi_lookup = fusion->cmd_list[smid_task - 1];
4494 if (scsi_lookup->scmd == NULL)
4497 instance->instancet->disable_intr(instance);
4498 megasas_sync_irqs((unsigned long)instance);
4499 instance->instancet->enable_intr(instance);
4500 megasas_enable_irq_poll(instance);
4501 if (scsi_lookup->scmd == NULL)
4507 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
4508 if ((channel == 0xFFFFFFFF) && (id == 0xFFFFFFFF))
4510 instance->instancet->disable_intr(instance);
4511 megasas_sync_irqs((unsigned long)instance);
4512 rc = megasas_track_scsiio(instance, id, channel);
4513 instance->instancet->enable_intr(instance);
4514 megasas_enable_irq_poll(instance);
4517 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
4518 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
4530 * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI
4531 * @instance: per adapter struct
4533 * Return Non Zero index, if SMID found in outstanding commands
4535 static u16 megasas_fusion_smid_lookup(struct scsi_cmnd *scmd)
4538 struct megasas_instance *instance;
4539 struct megasas_cmd_fusion *cmd_fusion;
4540 struct fusion_context *fusion;
4542 instance = (struct megasas_instance *)scmd->device->host->hostdata;
4544 fusion = instance->ctrl_context;
4546 for (i = 0; i < instance->max_scsi_cmds; i++) {
4547 cmd_fusion = fusion->cmd_list[i];
4548 if (cmd_fusion->scmd && (cmd_fusion->scmd == scmd)) {
4549 scmd_printk(KERN_NOTICE, scmd, "Abort request is for"
4550 " SMID: %d\n", cmd_fusion->index);
4551 ret = cmd_fusion->index;
4560 * megasas_get_tm_devhandle - Get devhandle for TM request
4561 * @sdev- OS provided scsi device
4563 * Returns- devhandle/targetID of SCSI device
4565 static u16 megasas_get_tm_devhandle(struct scsi_device *sdev)
4569 struct megasas_instance *instance;
4570 struct fusion_context *fusion;
4571 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
4572 u16 devhandle = (u16)ULONG_MAX;
4574 instance = (struct megasas_instance *)sdev->host->hostdata;
4575 fusion = instance->ctrl_context;
4577 if (!MEGASAS_IS_LOGICAL(sdev)) {
4578 if (instance->use_seqnum_jbod_fp) {
4579 pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
4581 pd_sync = (void *)fusion->pd_seq_sync
4582 [(instance->pd_seq_map_id - 1) & 1];
4583 devhandle = pd_sync->seq[pd_index].devHandle;
4585 sdev_printk(KERN_ERR, sdev, "Firmware expose tmCapable"
4586 " without JBOD MAP support from %s %d\n", __func__, __LINE__);
4588 device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL)
4590 devhandle = device_id;
4597 * megasas_task_abort_fusion : SCSI task abort function for fusion adapters
4598 * @scmd : pointer to scsi command object
4600 * Return SUCCESS, if command aborted else FAILED
4603 int megasas_task_abort_fusion(struct scsi_cmnd *scmd)
4605 struct megasas_instance *instance;
4606 u16 smid, devhandle;
4608 struct MR_PRIV_DEVICE *mr_device_priv_data;
4609 mr_device_priv_data = scmd->device->hostdata;
4611 instance = (struct megasas_instance *)scmd->device->host->hostdata;
4613 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
4614 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
4615 "SCSI host:%d\n", instance->host->host_no);
4620 if (!mr_device_priv_data) {
4621 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
4622 "scmd(%p)\n", scmd);
4623 scmd->result = DID_NO_CONNECT << 16;
4628 if (!mr_device_priv_data->is_tm_capable) {
4633 mutex_lock(&instance->reset_mutex);
4635 smid = megasas_fusion_smid_lookup(scmd);
4639 scmd_printk(KERN_NOTICE, scmd, "Command for which abort is"
4640 " issued is not found in outstanding commands\n");
4641 mutex_unlock(&instance->reset_mutex);
4645 devhandle = megasas_get_tm_devhandle(scmd->device);
4647 if (devhandle == (u16)ULONG_MAX) {
4649 sdev_printk(KERN_INFO, scmd->device,
4650 "task abort issued for invalid devhandle\n");
4651 mutex_unlock(&instance->reset_mutex);
4654 sdev_printk(KERN_INFO, scmd->device,
4655 "attempting task abort! scmd(0x%p) tm_dev_handle 0x%x\n",
4658 mr_device_priv_data->tm_busy = true;
4659 ret = megasas_issue_tm(instance, devhandle,
4660 scmd->device->channel, scmd->device->id, smid,
4661 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
4662 mr_device_priv_data);
4663 mr_device_priv_data->tm_busy = false;
4665 mutex_unlock(&instance->reset_mutex);
4666 scmd_printk(KERN_INFO, scmd, "task abort %s!! scmd(0x%p)\n",
4667 ((ret == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
4669 scsi_print_command(scmd);
4670 if (megasas_dbg_lvl & TM_DEBUG)
4671 megasas_dump_fusion_io(scmd);
4677 * megasas_reset_target_fusion : target reset function for fusion adapters
4678 * scmd: SCSI command pointer
4680 * Returns SUCCESS if all commands associated with target aborted else FAILED
4683 int megasas_reset_target_fusion(struct scsi_cmnd *scmd)
4686 struct megasas_instance *instance;
4689 struct MR_PRIV_DEVICE *mr_device_priv_data;
4690 mr_device_priv_data = scmd->device->hostdata;
4692 instance = (struct megasas_instance *)scmd->device->host->hostdata;
4694 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
4695 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
4696 "SCSI host:%d\n", instance->host->host_no);
4701 if (!mr_device_priv_data) {
4702 sdev_printk(KERN_INFO, scmd->device,
4703 "device been deleted! scmd: (0x%p)\n", scmd);
4704 scmd->result = DID_NO_CONNECT << 16;
4709 if (!mr_device_priv_data->is_tm_capable) {
4714 mutex_lock(&instance->reset_mutex);
4715 devhandle = megasas_get_tm_devhandle(scmd->device);
4717 if (devhandle == (u16)ULONG_MAX) {
4719 sdev_printk(KERN_INFO, scmd->device,
4720 "target reset issued for invalid devhandle\n");
4721 mutex_unlock(&instance->reset_mutex);
4725 sdev_printk(KERN_INFO, scmd->device,
4726 "attempting target reset! scmd(0x%p) tm_dev_handle: 0x%x\n",
4728 mr_device_priv_data->tm_busy = true;
4729 ret = megasas_issue_tm(instance, devhandle,
4730 scmd->device->channel, scmd->device->id, 0,
4731 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
4732 mr_device_priv_data);
4733 mr_device_priv_data->tm_busy = false;
4734 mutex_unlock(&instance->reset_mutex);
4735 scmd_printk(KERN_NOTICE, scmd, "target reset %s!!\n",
4736 (ret == SUCCESS) ? "SUCCESS" : "FAILED");
4742 /*SRIOV get other instance in cluster if any*/
4744 megasas_instance *megasas_get_peer_instance(struct megasas_instance *instance)
4748 for (i = 0; i < MAX_MGMT_ADAPTERS; i++) {
4749 if (megasas_mgmt_info.instance[i] &&
4750 (megasas_mgmt_info.instance[i] != instance) &&
4751 megasas_mgmt_info.instance[i]->requestorId &&
4752 megasas_mgmt_info.instance[i]->peerIsPresent &&
4753 (memcmp((megasas_mgmt_info.instance[i]->clusterId),
4754 instance->clusterId, MEGASAS_CLUSTER_ID_SIZE) == 0))
4755 return megasas_mgmt_info.instance[i];
4760 /* Check for a second path that is currently UP */
4761 int megasas_check_mpio_paths(struct megasas_instance *instance,
4762 struct scsi_cmnd *scmd)
4764 struct megasas_instance *peer_instance = NULL;
4765 int retval = (DID_REQUEUE << 16);
4767 if (instance->peerIsPresent) {
4768 peer_instance = megasas_get_peer_instance(instance);
4769 if ((peer_instance) &&
4770 (atomic_read(&peer_instance->adprecovery) ==
4771 MEGASAS_HBA_OPERATIONAL))
4772 retval = (DID_NO_CONNECT << 16);
4777 /* Core fusion reset function */
4778 int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
4780 int retval = SUCCESS, i, j, convert = 0;
4781 struct megasas_instance *instance;
4782 struct megasas_cmd_fusion *cmd_fusion, *r1_cmd;
4783 struct fusion_context *fusion;
4784 u32 abs_state, status_reg, reset_adapter, fpio_count = 0;
4785 u32 io_timeout_in_crash_mode = 0;
4786 struct scsi_cmnd *scmd_local = NULL;
4787 struct scsi_device *sdev;
4788 int ret_target_prop = DCMD_FAILED;
4789 bool is_target_prop = false;
4790 bool do_adp_reset = true;
4791 int max_reset_tries = MEGASAS_FUSION_MAX_RESET_TRIES;
4793 instance = (struct megasas_instance *)shost->hostdata;
4794 fusion = instance->ctrl_context;
4796 mutex_lock(&instance->reset_mutex);
4798 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
4799 dev_warn(&instance->pdev->dev, "Hardware critical error, "
4800 "returning FAILED for scsi%d.\n",
4801 instance->host->host_no);
4802 mutex_unlock(&instance->reset_mutex);
4805 status_reg = instance->instancet->read_fw_status_reg(instance);
4806 abs_state = status_reg & MFI_STATE_MASK;
4808 /* IO timeout detected, forcibly put FW in FAULT state */
4809 if (abs_state != MFI_STATE_FAULT && instance->crash_dump_buf &&
4810 instance->crash_dump_app_support && reason) {
4811 dev_info(&instance->pdev->dev, "IO/DCMD timeout is detected, "
4812 "forcibly FAULT Firmware\n");
4813 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT);
4814 status_reg = megasas_readl(instance, &instance->reg_set->doorbell);
4815 writel(status_reg | MFI_STATE_FORCE_OCR,
4816 &instance->reg_set->doorbell);
4817 readl(&instance->reg_set->doorbell);
4818 mutex_unlock(&instance->reset_mutex);
4821 io_timeout_in_crash_mode++;
4822 dev_dbg(&instance->pdev->dev, "waiting for [%d] "
4823 "seconds for crash dump collection and OCR "
4824 "to be done\n", (io_timeout_in_crash_mode * 3));
4825 } while ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) &&
4826 (io_timeout_in_crash_mode < 80));
4828 if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) {
4829 dev_info(&instance->pdev->dev, "OCR done for IO "
4833 dev_info(&instance->pdev->dev, "Controller is not "
4834 "operational after 240 seconds wait for IO "
4835 "timeout case in FW crash dump mode\n do "
4836 "OCR/kill adapter\n");
4837 retval = megasas_reset_fusion(shost, 0);
4842 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
4843 del_timer_sync(&instance->sriov_heartbeat_timer);
4844 set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
4845 set_bit(MEGASAS_FUSION_OCR_NOT_POSSIBLE, &instance->reset_flags);
4846 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_POLLING);
4847 instance->instancet->disable_intr(instance);
4848 megasas_sync_irqs((unsigned long)instance);
4850 /* First try waiting for commands to complete */
4851 if (megasas_wait_for_outstanding_fusion(instance, reason,
4853 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT);
4854 dev_warn(&instance->pdev->dev, "resetting fusion "
4855 "adapter scsi%d.\n", instance->host->host_no);
4859 if (megasas_dbg_lvl & OCR_DEBUG)
4860 dev_info(&instance->pdev->dev, "\nPending SCSI commands:\n");
4862 /* Now return commands back to the OS */
4863 for (i = 0 ; i < instance->max_scsi_cmds; i++) {
4864 cmd_fusion = fusion->cmd_list[i];
4865 /*check for extra commands issued by driver*/
4866 if (instance->adapter_type >= VENTURA_SERIES) {
4867 r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds];
4868 megasas_return_cmd_fusion(instance, r1_cmd);
4870 scmd_local = cmd_fusion->scmd;
4871 if (cmd_fusion->scmd) {
4872 if (megasas_dbg_lvl & OCR_DEBUG) {
4873 sdev_printk(KERN_INFO,
4874 cmd_fusion->scmd->device, "SMID: 0x%x\n",
4876 megasas_dump_fusion_io(cmd_fusion->scmd);
4879 if (cmd_fusion->io_request->Function ==
4880 MPI2_FUNCTION_SCSI_IO_REQUEST)
4883 scmd_local->result =
4884 megasas_check_mpio_paths(instance,
4886 if (instance->ldio_threshold &&
4887 megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
4888 atomic_dec(&instance->ldio_outstanding);
4889 megasas_return_cmd_fusion(instance, cmd_fusion);
4890 scsi_dma_unmap(scmd_local);
4891 scmd_local->scsi_done(scmd_local);
4895 dev_info(&instance->pdev->dev, "Outstanding fastpath IOs: %d\n",
4898 atomic_set(&instance->fw_outstanding, 0);
4900 status_reg = instance->instancet->read_fw_status_reg(instance);
4901 abs_state = status_reg & MFI_STATE_MASK;
4902 reset_adapter = status_reg & MFI_RESET_ADAPTER;
4903 if (instance->disableOnlineCtrlReset ||
4904 (abs_state == MFI_STATE_FAULT && !reset_adapter)) {
4905 /* Reset not supported, kill adapter */
4906 dev_warn(&instance->pdev->dev, "Reset not supported"
4907 ", killing adapter scsi%d.\n",
4908 instance->host->host_no);
4912 /* Let SR-IOV VF & PF sync up if there was a HB failure */
4913 if (instance->requestorId && !reason) {
4914 msleep(MEGASAS_OCR_SETTLE_TIME_VF);
4915 do_adp_reset = false;
4916 max_reset_tries = MEGASAS_SRIOV_MAX_RESET_TRIES_VF;
4919 /* Now try to reset the chip */
4920 for (i = 0; i < max_reset_tries; i++) {
4922 * Do adp reset and wait for
4923 * controller to transition to ready
4925 if (megasas_adp_reset_wait_for_ready(instance,
4926 do_adp_reset, 1) == FAILED)
4929 /* Wait for FW to become ready */
4930 if (megasas_transition_to_ready(instance, 1)) {
4931 dev_warn(&instance->pdev->dev,
4932 "Failed to transition controller to ready for "
4933 "scsi%d.\n", instance->host->host_no);
4936 megasas_reset_reply_desc(instance);
4937 megasas_fusion_update_can_queue(instance, OCR_CONTEXT);
4939 if (megasas_ioc_init_fusion(instance)) {
4943 if (megasas_get_ctrl_info(instance)) {
4944 dev_info(&instance->pdev->dev,
4945 "Failed from %s %d\n",
4946 __func__, __LINE__);
4950 megasas_refire_mgmt_cmd(instance,
4951 (i == (MEGASAS_FUSION_MAX_RESET_TRIES - 1)
4954 /* Reset load balance info */
4955 if (fusion->load_balance_info)
4956 memset(fusion->load_balance_info, 0,
4957 (sizeof(struct LD_LOAD_BALANCE_INFO) *
4958 MAX_LOGICAL_DRIVES_EXT));
4960 if (!megasas_get_map_info(instance)) {
4961 megasas_sync_map_info(instance);
4964 * Return pending polled mode cmds before
4967 megasas_return_polled_cmds(instance);
4971 megasas_setup_jbod_map(instance);
4973 /* reset stream detection array */
4974 if (instance->adapter_type >= VENTURA_SERIES) {
4975 for (j = 0; j < MAX_LOGICAL_DRIVES_EXT; ++j) {
4976 memset(fusion->stream_detect_by_ld[j],
4977 0, sizeof(struct LD_STREAM_DETECT));
4978 fusion->stream_detect_by_ld[j]->mru_bit_map
4983 clear_bit(MEGASAS_FUSION_IN_RESET,
4984 &instance->reset_flags);
4985 instance->instancet->enable_intr(instance);
4986 megasas_enable_irq_poll(instance);
4987 shost_for_each_device(sdev, shost) {
4988 if ((instance->tgt_prop) &&
4989 (instance->nvme_page_size))
4990 ret_target_prop = megasas_get_target_prop(instance, sdev);
4992 is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false;
4993 megasas_set_dynamic_target_properties(sdev, is_target_prop);
4996 status_reg = instance->instancet->read_fw_status_reg
4998 abs_state = status_reg & MFI_STATE_MASK;
4999 if (abs_state != MFI_STATE_OPERATIONAL) {
5000 dev_info(&instance->pdev->dev,
5001 "Adapter is not OPERATIONAL, state 0x%x for scsi:%d\n",
5002 abs_state, instance->host->host_no);
5005 atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL);
5007 dev_info(&instance->pdev->dev,
5008 "Adapter is OPERATIONAL for scsi:%d\n",
5009 instance->host->host_no);
5011 /* Restart SR-IOV heartbeat */
5012 if (instance->requestorId) {
5013 if (!megasas_sriov_start_heartbeat(instance, 0))
5014 megasas_start_timer(instance);
5016 instance->skip_heartbeat_timer_del = 1;
5019 if (instance->crash_dump_drv_support &&
5020 instance->crash_dump_app_support)
5021 megasas_set_crash_dump_params(instance,
5022 MR_CRASH_BUF_TURN_ON);
5024 megasas_set_crash_dump_params(instance,
5025 MR_CRASH_BUF_TURN_OFF);
5027 if (instance->snapdump_wait_time) {
5028 megasas_get_snapdump_properties(instance);
5029 dev_info(&instance->pdev->dev,
5030 "Snap dump wait time\t: %d\n",
5031 instance->snapdump_wait_time);
5036 /* Adapter reset completed successfully */
5037 dev_warn(&instance->pdev->dev,
5038 "Reset successful for scsi%d.\n",
5039 instance->host->host_no);
5043 /* Reset failed, kill the adapter */
5044 dev_warn(&instance->pdev->dev, "Reset failed, killing "
5045 "adapter scsi%d.\n", instance->host->host_no);
5048 /* For VF: Restart HB timer if we didn't OCR */
5049 if (instance->requestorId) {
5050 megasas_start_timer(instance);
5052 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
5053 instance->instancet->enable_intr(instance);
5054 megasas_enable_irq_poll(instance);
5055 atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL);
5059 megaraid_sas_kill_hba(instance);
5060 megasas_enable_irq_poll(instance);
5061 instance->skip_heartbeat_timer_del = 1;
5064 clear_bit(MEGASAS_FUSION_OCR_NOT_POSSIBLE, &instance->reset_flags);
5065 mutex_unlock(&instance->reset_mutex);
5069 /* Fusion Crash dump collection */
5070 static void megasas_fusion_crash_dump(struct megasas_instance *instance)
5073 u8 partial_copy = 0;
5077 status_reg = instance->instancet->read_fw_status_reg(instance);
5080 * Allocate host crash buffers to copy data from 1 MB DMA crash buffer
5081 * to host crash buffers
5083 if (instance->drv_buf_index == 0) {
5084 /* Buffer is already allocated for old Crash dump.
5085 * Do OCR and do not wait for crash dump collection
5087 if (instance->drv_buf_alloc) {
5088 dev_info(&instance->pdev->dev, "earlier crash dump is "
5089 "not yet copied by application, ignoring this "
5090 "crash dump and initiating OCR\n");
5091 status_reg |= MFI_STATE_CRASH_DUMP_DONE;
5093 &instance->reg_set->outbound_scratch_pad_0);
5094 readl(&instance->reg_set->outbound_scratch_pad_0);
5097 megasas_alloc_host_crash_buffer(instance);
5098 dev_info(&instance->pdev->dev, "Number of host crash buffers "
5099 "allocated: %d\n", instance->drv_buf_alloc);
5102 while (!(status_reg & MFI_STATE_CRASH_DUMP_DONE) &&
5103 (wait < MEGASAS_WATCHDOG_WAIT_COUNT)) {
5104 if (!(status_reg & MFI_STATE_DMADONE)) {
5106 * Next crash dump buffer is not yet DMA'd by FW
5107 * Check after 10ms. Wait for 1 second for FW to
5108 * post the next buffer. If not bail out.
5111 msleep(MEGASAS_WAIT_FOR_NEXT_DMA_MSECS);
5112 status_reg = instance->instancet->read_fw_status_reg(
5118 if (instance->drv_buf_index >= instance->drv_buf_alloc) {
5119 dev_info(&instance->pdev->dev,
5120 "Driver is done copying the buffer: %d\n",
5121 instance->drv_buf_alloc);
5122 status_reg |= MFI_STATE_CRASH_DUMP_DONE;
5126 memcpy(instance->crash_buf[instance->drv_buf_index],
5127 instance->crash_dump_buf, CRASH_DMA_BUF_SIZE);
5128 instance->drv_buf_index++;
5129 status_reg &= ~MFI_STATE_DMADONE;
5132 writel(status_reg, &instance->reg_set->outbound_scratch_pad_0);
5133 readl(&instance->reg_set->outbound_scratch_pad_0);
5135 msleep(MEGASAS_WAIT_FOR_NEXT_DMA_MSECS);
5136 status_reg = instance->instancet->read_fw_status_reg(instance);
5139 if (status_reg & MFI_STATE_CRASH_DUMP_DONE) {
5140 dev_info(&instance->pdev->dev, "Crash Dump is available,number "
5141 "of copied buffers: %d\n", instance->drv_buf_index);
5142 instance->fw_crash_buffer_size = instance->drv_buf_index;
5143 instance->fw_crash_state = AVAILABLE;
5144 instance->drv_buf_index = 0;
5145 writel(status_reg, &instance->reg_set->outbound_scratch_pad_0);
5146 readl(&instance->reg_set->outbound_scratch_pad_0);
5148 megasas_reset_fusion(instance->host, 0);
5153 /* Fusion OCR work queue */
5154 void megasas_fusion_ocr_wq(struct work_struct *work)
5156 struct megasas_instance *instance =
5157 container_of(work, struct megasas_instance, work_init);
5159 megasas_reset_fusion(instance->host, 0);
5162 /* Allocate fusion context */
5164 megasas_alloc_fusion_context(struct megasas_instance *instance)
5166 struct fusion_context *fusion;
5168 instance->ctrl_context = kzalloc(sizeof(struct fusion_context),
5170 if (!instance->ctrl_context) {
5171 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
5172 __func__, __LINE__);
5176 fusion = instance->ctrl_context;
5178 fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
5179 sizeof(LD_SPAN_INFO));
5180 fusion->log_to_span =
5181 (PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
5182 fusion->log_to_span_pages);
5183 if (!fusion->log_to_span) {
5184 fusion->log_to_span =
5185 vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
5186 sizeof(LD_SPAN_INFO)));
5187 if (!fusion->log_to_span) {
5188 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
5189 __func__, __LINE__);
5194 fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
5195 sizeof(struct LD_LOAD_BALANCE_INFO));
5196 fusion->load_balance_info =
5197 (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
5198 fusion->load_balance_info_pages);
5199 if (!fusion->load_balance_info) {
5200 fusion->load_balance_info =
5201 vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
5202 sizeof(struct LD_LOAD_BALANCE_INFO)));
5203 if (!fusion->load_balance_info)
5204 dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, "
5205 "continuing without Load Balance support\n");
5212 megasas_free_fusion_context(struct megasas_instance *instance)
5214 struct fusion_context *fusion = instance->ctrl_context;
5217 if (fusion->load_balance_info) {
5218 if (is_vmalloc_addr(fusion->load_balance_info))
5219 vfree(fusion->load_balance_info);
5221 free_pages((ulong)fusion->load_balance_info,
5222 fusion->load_balance_info_pages);
5225 if (fusion->log_to_span) {
5226 if (is_vmalloc_addr(fusion->log_to_span))
5227 vfree(fusion->log_to_span);
5229 free_pages((ulong)fusion->log_to_span,
5230 fusion->log_to_span_pages);
5237 struct megasas_instance_template megasas_instance_template_fusion = {
5238 .enable_intr = megasas_enable_intr_fusion,
5239 .disable_intr = megasas_disable_intr_fusion,
5240 .clear_intr = megasas_clear_intr_fusion,
5241 .read_fw_status_reg = megasas_read_fw_status_reg_fusion,
5242 .adp_reset = megasas_adp_reset_fusion,
5243 .check_reset = megasas_check_reset_fusion,
5244 .service_isr = megasas_isr_fusion,
5245 .tasklet = megasas_complete_cmd_dpc_fusion,
5246 .init_adapter = megasas_init_adapter_fusion,
5247 .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion,
5248 .issue_dcmd = megasas_issue_dcmd_fusion,