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"
52 megasas_complete_cmd(struct megasas_instance *instance,
53 struct megasas_cmd *cmd, u8 alt_status);
55 wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd,
59 megasas_clear_intr_fusion(struct megasas_instance *instance);
61 int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
63 extern u32 megasas_dbg_lvl;
64 int megasas_sriov_start_heartbeat(struct megasas_instance *instance,
66 extern struct megasas_mgmt_info megasas_mgmt_info;
67 extern unsigned int resetwaittime;
68 extern unsigned int dual_qdepth_disable;
69 static void megasas_free_rdpq_fusion(struct megasas_instance *instance);
70 static void megasas_free_reply_fusion(struct megasas_instance *instance);
72 void megasas_configure_queue_sizes(struct megasas_instance *instance);
73 static void megasas_fusion_crash_dump(struct megasas_instance *instance);
76 * megasas_adp_reset_wait_for_ready - initiate chip reset and wait for
77 * controller to come to ready state
78 * @instance: adapter's soft state
79 * @do_adp_reset: If true, do a chip reset
80 * @ocr_context: If called from OCR context this will
83 * This function initates a chip reset followed by a wait for controller to
84 * transition to ready state.
85 * During this, driver will block all access to PCI config space from userspace
88 megasas_adp_reset_wait_for_ready(struct megasas_instance *instance,
95 * Block access to PCI config space from userspace
96 * when diag reset is initiated from driver
98 if (megasas_dbg_lvl & OCR_DEBUG)
99 dev_info(&instance->pdev->dev,
100 "Block access to PCI config space %s %d\n",
103 pci_cfg_access_lock(instance->pdev);
106 if (instance->instancet->adp_reset
107 (instance, instance->reg_set))
111 /* Wait for FW to become ready */
112 if (megasas_transition_to_ready(instance, ocr_context)) {
113 dev_warn(&instance->pdev->dev,
114 "Failed to transition controller to ready for scsi%d.\n",
115 instance->host->host_no);
121 if (megasas_dbg_lvl & OCR_DEBUG)
122 dev_info(&instance->pdev->dev,
123 "Unlock access to PCI config space %s %d\n",
126 pci_cfg_access_unlock(instance->pdev);
132 * megasas_check_same_4gb_region - check if allocation
133 * crosses same 4GB boundary or not
134 * @instance: adapter's soft instance
135 * @start_addr: start address of DMA allocation
136 * @size: size of allocation in bytes
137 * @return: true : allocation does not cross same
139 * false: allocation crosses same
142 static inline bool megasas_check_same_4gb_region
143 (struct megasas_instance *instance, dma_addr_t start_addr, size_t size)
147 end_addr = start_addr + size;
149 if (upper_32_bits(start_addr) != upper_32_bits(end_addr)) {
150 dev_err(&instance->pdev->dev,
151 "Failed to get same 4GB boundary: start_addr: 0x%llx end_addr: 0x%llx\n",
152 (unsigned long long)start_addr,
153 (unsigned long long)end_addr);
161 * megasas_enable_intr_fusion - Enables interrupts
162 * @instance: adapter's soft instance
165 megasas_enable_intr_fusion(struct megasas_instance *instance)
167 struct megasas_register_set __iomem *regs;
168 regs = instance->reg_set;
170 instance->mask_interrupts = 0;
171 /* For Thunderbolt/Invader also clear intr on enable */
172 writel(~0, ®s->outbound_intr_status);
173 readl(®s->outbound_intr_status);
175 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
177 /* Dummy readl to force pci flush */
178 dev_info(&instance->pdev->dev, "%s is called outbound_intr_mask:0x%08x\n",
179 __func__, readl(®s->outbound_intr_mask));
183 * megasas_disable_intr_fusion - Disables interrupt
184 * @instance: adapter's soft instance
187 megasas_disable_intr_fusion(struct megasas_instance *instance)
189 u32 mask = 0xFFFFFFFF;
190 struct megasas_register_set __iomem *regs;
191 regs = instance->reg_set;
192 instance->mask_interrupts = 1;
194 writel(mask, ®s->outbound_intr_mask);
195 /* Dummy readl to force pci flush */
196 dev_info(&instance->pdev->dev, "%s is called outbound_intr_mask:0x%08x\n",
197 __func__, readl(®s->outbound_intr_mask));
201 megasas_clear_intr_fusion(struct megasas_instance *instance)
204 struct megasas_register_set __iomem *regs;
205 regs = instance->reg_set;
207 * Check if it is our interrupt
209 status = megasas_readl(instance,
210 ®s->outbound_intr_status);
213 writel(status, ®s->outbound_intr_status);
214 readl(®s->outbound_intr_status);
217 if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
224 * megasas_get_cmd_fusion - Get a command from the free pool
225 * @instance: Adapter soft state
226 * @blk_tag: Command tag
228 * Returns a blk_tag indexed mpt frame
230 inline struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance
231 *instance, u32 blk_tag)
233 struct fusion_context *fusion;
235 fusion = instance->ctrl_context;
236 return fusion->cmd_list[blk_tag];
240 * megasas_return_cmd_fusion - Return a cmd to free command pool
241 * @instance: Adapter soft state
242 * @cmd: Command packet to be returned to free command pool
244 inline void megasas_return_cmd_fusion(struct megasas_instance *instance,
245 struct megasas_cmd_fusion *cmd)
248 memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
249 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
250 cmd->cmd_completed = false;
254 * megasas_write_64bit_req_desc - PCI writes 64bit request descriptor
255 * @instance: Adapter soft state
256 * @req_desc: 64bit Request descriptor
259 megasas_write_64bit_req_desc(struct megasas_instance *instance,
260 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
262 #if defined(writeq) && defined(CONFIG_64BIT)
263 u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
264 le32_to_cpu(req_desc->u.low));
265 writeq(req_data, &instance->reg_set->inbound_low_queue_port);
268 spin_lock_irqsave(&instance->hba_lock, flags);
269 writel(le32_to_cpu(req_desc->u.low),
270 &instance->reg_set->inbound_low_queue_port);
271 writel(le32_to_cpu(req_desc->u.high),
272 &instance->reg_set->inbound_high_queue_port);
273 spin_unlock_irqrestore(&instance->hba_lock, flags);
278 * megasas_fire_cmd_fusion - Sends command to the FW
279 * @instance: Adapter soft state
280 * @req_desc: 32bit or 64bit Request descriptor
282 * Perform PCI Write. AERO SERIES supports 32 bit Descriptor.
283 * Prior to AERO_SERIES support 64 bit Descriptor.
286 megasas_fire_cmd_fusion(struct megasas_instance *instance,
287 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
289 if (instance->atomic_desc_support)
290 writel(le32_to_cpu(req_desc->u.low),
291 &instance->reg_set->inbound_single_queue_port);
293 megasas_write_64bit_req_desc(instance, req_desc);
297 * megasas_fusion_update_can_queue - Do all Adapter Queue depth related calculations here
298 * @instance: Adapter soft state
299 * @fw_boot_context: Whether this function called during probe or after OCR
301 * This function is only for fusion controllers.
302 * Update host can queue, if firmware downgrade max supported firmware commands.
303 * Firmware upgrade case will be skiped because underlying firmware has
304 * more resource than exposed to the OS.
308 megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_context)
310 u16 cur_max_fw_cmds = 0;
311 u16 ldio_threshold = 0;
313 /* ventura FW does not fill outbound_scratch_pad_2 with queue depth */
314 if (instance->adapter_type < VENTURA_SERIES)
316 megasas_readl(instance,
317 &instance->reg_set->outbound_scratch_pad_2) & 0x00FFFF;
319 if (dual_qdepth_disable || !cur_max_fw_cmds)
320 cur_max_fw_cmds = instance->instancet->read_fw_status_reg(instance) & 0x00FFFF;
323 (instance->instancet->read_fw_status_reg(instance) & 0x00FFFF) - MEGASAS_FUSION_IOCTL_CMDS;
325 dev_info(&instance->pdev->dev,
326 "Current firmware supports maximum commands: %d\t LDIO threshold: %d\n",
327 cur_max_fw_cmds, ldio_threshold);
329 if (fw_boot_context == OCR_CONTEXT) {
330 cur_max_fw_cmds = cur_max_fw_cmds - 1;
331 if (cur_max_fw_cmds < instance->max_fw_cmds) {
332 instance->cur_can_queue =
333 cur_max_fw_cmds - (MEGASAS_FUSION_INTERNAL_CMDS +
334 MEGASAS_FUSION_IOCTL_CMDS);
335 instance->host->can_queue = instance->cur_can_queue;
336 instance->ldio_threshold = ldio_threshold;
339 instance->max_fw_cmds = cur_max_fw_cmds;
340 instance->ldio_threshold = ldio_threshold;
343 instance->max_fw_cmds = min(instance->max_fw_cmds,
344 (u16)MEGASAS_KDUMP_QUEUE_DEPTH);
346 * Reduce the max supported cmds by 1. This is to ensure that the
347 * reply_q_sz (1 more than the max cmd that driver may send)
348 * does not exceed max cmds that the FW can support
350 instance->max_fw_cmds = instance->max_fw_cmds-1;
355 megasas_get_msix_index(struct megasas_instance *instance,
356 struct scsi_cmnd *scmd,
357 struct megasas_cmd_fusion *cmd,
362 /* TBD - if sml remove device_busy in future, driver
363 * should track counter in internal structure.
365 sdev_busy = atomic_read(&scmd->device->device_busy);
367 if (instance->perf_mode == MR_BALANCED_PERF_MODE &&
368 sdev_busy > (data_arms * MR_DEVICE_HIGH_IOPS_DEPTH)) {
369 cmd->request_desc->SCSIIO.MSIxIndex =
370 mega_mod64((atomic64_add_return(1, &instance->high_iops_outstanding) /
371 MR_HIGH_IOPS_BATCH_COUNT), instance->low_latency_index_start);
372 } else if (instance->msix_load_balance) {
373 cmd->request_desc->SCSIIO.MSIxIndex =
374 (mega_mod64(atomic64_add_return(1, &instance->total_io_count),
375 instance->msix_vectors));
376 } else if (instance->host->nr_hw_queues > 1) {
377 u32 tag = blk_mq_unique_tag(scmd->request);
379 cmd->request_desc->SCSIIO.MSIxIndex = blk_mq_unique_tag_to_hwq(tag) +
380 instance->low_latency_index_start;
382 cmd->request_desc->SCSIIO.MSIxIndex =
383 instance->reply_map[raw_smp_processor_id()];
388 * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
389 * @instance: Adapter soft state
392 megasas_free_cmds_fusion(struct megasas_instance *instance)
395 struct fusion_context *fusion = instance->ctrl_context;
396 struct megasas_cmd_fusion *cmd;
399 dma_pool_free(fusion->sense_dma_pool, fusion->sense,
400 fusion->sense_phys_addr);
403 if (fusion->cmd_list) {
404 for (i = 0; i < instance->max_mpt_cmds; i++) {
405 cmd = fusion->cmd_list[i];
408 dma_pool_free(fusion->sg_dma_pool,
410 cmd->sg_frame_phys_addr);
414 kfree(fusion->cmd_list);
417 if (fusion->sg_dma_pool) {
418 dma_pool_destroy(fusion->sg_dma_pool);
419 fusion->sg_dma_pool = NULL;
421 if (fusion->sense_dma_pool) {
422 dma_pool_destroy(fusion->sense_dma_pool);
423 fusion->sense_dma_pool = NULL;
427 /* Reply Frame, Desc*/
428 if (instance->is_rdpq)
429 megasas_free_rdpq_fusion(instance);
431 megasas_free_reply_fusion(instance);
433 /* Request Frame, Desc*/
434 if (fusion->req_frames_desc)
435 dma_free_coherent(&instance->pdev->dev,
436 fusion->request_alloc_sz, fusion->req_frames_desc,
437 fusion->req_frames_desc_phys);
438 if (fusion->io_request_frames)
439 dma_pool_free(fusion->io_request_frames_pool,
440 fusion->io_request_frames,
441 fusion->io_request_frames_phys);
442 if (fusion->io_request_frames_pool) {
443 dma_pool_destroy(fusion->io_request_frames_pool);
444 fusion->io_request_frames_pool = NULL;
449 * megasas_create_sg_sense_fusion - Creates DMA pool for cmd frames
450 * @instance: Adapter soft state
453 static int megasas_create_sg_sense_fusion(struct megasas_instance *instance)
457 struct fusion_context *fusion;
458 struct megasas_cmd_fusion *cmd;
462 fusion = instance->ctrl_context;
463 max_cmd = instance->max_fw_cmds;
464 sense_sz = instance->max_mpt_cmds * SCSI_SENSE_BUFFERSIZE;
466 fusion->sg_dma_pool =
467 dma_pool_create("mr_sg", &instance->pdev->dev,
468 instance->max_chain_frame_sz,
469 MR_DEFAULT_NVME_PAGE_SIZE, 0);
470 /* SCSI_SENSE_BUFFERSIZE = 96 bytes */
471 fusion->sense_dma_pool =
472 dma_pool_create("mr_sense", &instance->pdev->dev,
475 if (!fusion->sense_dma_pool || !fusion->sg_dma_pool) {
476 dev_err(&instance->pdev->dev,
477 "Failed from %s %d\n", __func__, __LINE__);
481 fusion->sense = dma_pool_alloc(fusion->sense_dma_pool,
482 GFP_KERNEL, &fusion->sense_phys_addr);
483 if (!fusion->sense) {
484 dev_err(&instance->pdev->dev,
485 "failed from %s %d\n", __func__, __LINE__);
489 /* sense buffer, request frame and reply desc pool requires to be in
490 * same 4 gb region. Below function will check this.
491 * In case of failure, new pci pool will be created with updated
493 * Older allocation and pool will be destroyed.
494 * Alignment will be used such a way that next allocation if success,
495 * will always meet same 4gb region requirement.
496 * Actual requirement is not alignment, but we need start and end of
497 * DMA address must have same upper 32 bit address.
500 if (!megasas_check_same_4gb_region(instance, fusion->sense_phys_addr,
502 dma_pool_free(fusion->sense_dma_pool, fusion->sense,
503 fusion->sense_phys_addr);
504 fusion->sense = NULL;
505 dma_pool_destroy(fusion->sense_dma_pool);
507 fusion->sense_dma_pool =
508 dma_pool_create("mr_sense_align", &instance->pdev->dev,
509 sense_sz, roundup_pow_of_two(sense_sz),
511 if (!fusion->sense_dma_pool) {
512 dev_err(&instance->pdev->dev,
513 "Failed from %s %d\n", __func__, __LINE__);
516 fusion->sense = dma_pool_alloc(fusion->sense_dma_pool,
518 &fusion->sense_phys_addr);
519 if (!fusion->sense) {
520 dev_err(&instance->pdev->dev,
521 "failed from %s %d\n", __func__, __LINE__);
527 * Allocate and attach a frame to each of the commands in cmd_list
529 for (i = 0; i < max_cmd; i++) {
530 cmd = fusion->cmd_list[i];
531 cmd->sg_frame = dma_pool_alloc(fusion->sg_dma_pool,
532 GFP_KERNEL, &cmd->sg_frame_phys_addr);
534 offset = SCSI_SENSE_BUFFERSIZE * i;
535 cmd->sense = (u8 *)fusion->sense + offset;
536 cmd->sense_phys_addr = fusion->sense_phys_addr + offset;
538 if (!cmd->sg_frame) {
539 dev_err(&instance->pdev->dev,
540 "Failed from %s %d\n", __func__, __LINE__);
545 /* create sense buffer for the raid 1/10 fp */
546 for (i = max_cmd; i < instance->max_mpt_cmds; i++) {
547 cmd = fusion->cmd_list[i];
548 offset = SCSI_SENSE_BUFFERSIZE * i;
549 cmd->sense = (u8 *)fusion->sense + offset;
550 cmd->sense_phys_addr = fusion->sense_phys_addr + offset;
558 megasas_alloc_cmdlist_fusion(struct megasas_instance *instance)
560 u32 max_mpt_cmd, i, j;
561 struct fusion_context *fusion;
563 fusion = instance->ctrl_context;
565 max_mpt_cmd = instance->max_mpt_cmds;
568 * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
569 * Allocate the dynamic array first and then allocate individual
573 kcalloc(max_mpt_cmd, sizeof(struct megasas_cmd_fusion *),
575 if (!fusion->cmd_list) {
576 dev_err(&instance->pdev->dev,
577 "Failed from %s %d\n", __func__, __LINE__);
581 for (i = 0; i < max_mpt_cmd; i++) {
582 fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion),
584 if (!fusion->cmd_list[i]) {
585 for (j = 0; j < i; j++)
586 kfree(fusion->cmd_list[j]);
587 kfree(fusion->cmd_list);
588 dev_err(&instance->pdev->dev,
589 "Failed from %s %d\n", __func__, __LINE__);
598 megasas_alloc_request_fusion(struct megasas_instance *instance)
600 struct fusion_context *fusion;
602 fusion = instance->ctrl_context;
605 fusion->io_request_frames_pool =
606 dma_pool_create("mr_ioreq", &instance->pdev->dev,
607 fusion->io_frames_alloc_sz, 16, 0);
609 if (!fusion->io_request_frames_pool) {
610 dev_err(&instance->pdev->dev,
611 "Failed from %s %d\n", __func__, __LINE__);
615 fusion->io_request_frames =
616 dma_pool_alloc(fusion->io_request_frames_pool,
617 GFP_KERNEL | __GFP_NOWARN,
618 &fusion->io_request_frames_phys);
619 if (!fusion->io_request_frames) {
620 if (instance->max_fw_cmds >= (MEGASAS_REDUCE_QD_COUNT * 2)) {
621 instance->max_fw_cmds -= MEGASAS_REDUCE_QD_COUNT;
622 dma_pool_destroy(fusion->io_request_frames_pool);
623 megasas_configure_queue_sizes(instance);
626 dev_err(&instance->pdev->dev,
627 "Failed from %s %d\n", __func__, __LINE__);
632 if (!megasas_check_same_4gb_region(instance,
633 fusion->io_request_frames_phys,
634 fusion->io_frames_alloc_sz)) {
635 dma_pool_free(fusion->io_request_frames_pool,
636 fusion->io_request_frames,
637 fusion->io_request_frames_phys);
638 fusion->io_request_frames = NULL;
639 dma_pool_destroy(fusion->io_request_frames_pool);
641 fusion->io_request_frames_pool =
642 dma_pool_create("mr_ioreq_align",
643 &instance->pdev->dev,
644 fusion->io_frames_alloc_sz,
645 roundup_pow_of_two(fusion->io_frames_alloc_sz),
648 if (!fusion->io_request_frames_pool) {
649 dev_err(&instance->pdev->dev,
650 "Failed from %s %d\n", __func__, __LINE__);
654 fusion->io_request_frames =
655 dma_pool_alloc(fusion->io_request_frames_pool,
656 GFP_KERNEL | __GFP_NOWARN,
657 &fusion->io_request_frames_phys);
659 if (!fusion->io_request_frames) {
660 dev_err(&instance->pdev->dev,
661 "Failed from %s %d\n", __func__, __LINE__);
666 fusion->req_frames_desc =
667 dma_alloc_coherent(&instance->pdev->dev,
668 fusion->request_alloc_sz,
669 &fusion->req_frames_desc_phys, GFP_KERNEL);
670 if (!fusion->req_frames_desc) {
671 dev_err(&instance->pdev->dev,
672 "Failed from %s %d\n", __func__, __LINE__);
680 megasas_alloc_reply_fusion(struct megasas_instance *instance)
683 struct fusion_context *fusion;
684 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
685 fusion = instance->ctrl_context;
687 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
688 fusion->reply_frames_desc_pool =
689 dma_pool_create("mr_reply", &instance->pdev->dev,
690 fusion->reply_alloc_sz * count, 16, 0);
692 if (!fusion->reply_frames_desc_pool) {
693 dev_err(&instance->pdev->dev,
694 "Failed from %s %d\n", __func__, __LINE__);
698 fusion->reply_frames_desc[0] =
699 dma_pool_alloc(fusion->reply_frames_desc_pool,
700 GFP_KERNEL, &fusion->reply_frames_desc_phys[0]);
701 if (!fusion->reply_frames_desc[0]) {
702 dev_err(&instance->pdev->dev,
703 "Failed from %s %d\n", __func__, __LINE__);
707 if (!megasas_check_same_4gb_region(instance,
708 fusion->reply_frames_desc_phys[0],
709 (fusion->reply_alloc_sz * count))) {
710 dma_pool_free(fusion->reply_frames_desc_pool,
711 fusion->reply_frames_desc[0],
712 fusion->reply_frames_desc_phys[0]);
713 fusion->reply_frames_desc[0] = NULL;
714 dma_pool_destroy(fusion->reply_frames_desc_pool);
716 fusion->reply_frames_desc_pool =
717 dma_pool_create("mr_reply_align",
718 &instance->pdev->dev,
719 fusion->reply_alloc_sz * count,
720 roundup_pow_of_two(fusion->reply_alloc_sz * count),
723 if (!fusion->reply_frames_desc_pool) {
724 dev_err(&instance->pdev->dev,
725 "Failed from %s %d\n", __func__, __LINE__);
729 fusion->reply_frames_desc[0] =
730 dma_pool_alloc(fusion->reply_frames_desc_pool,
732 &fusion->reply_frames_desc_phys[0]);
734 if (!fusion->reply_frames_desc[0]) {
735 dev_err(&instance->pdev->dev,
736 "Failed from %s %d\n", __func__, __LINE__);
741 reply_desc = fusion->reply_frames_desc[0];
742 for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++)
743 reply_desc->Words = cpu_to_le64(ULLONG_MAX);
745 /* This is not a rdpq mode, but driver still populate
746 * reply_frame_desc array to use same msix index in ISR path.
748 for (i = 0; i < (count - 1); i++)
749 fusion->reply_frames_desc[i + 1] =
750 fusion->reply_frames_desc[i] +
751 (fusion->reply_alloc_sz)/sizeof(union MPI2_REPLY_DESCRIPTORS_UNION);
757 megasas_alloc_rdpq_fusion(struct megasas_instance *instance)
759 int i, j, k, msix_count;
760 struct fusion_context *fusion;
761 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
762 union MPI2_REPLY_DESCRIPTORS_UNION *rdpq_chunk_virt[RDPQ_MAX_CHUNK_COUNT];
763 dma_addr_t rdpq_chunk_phys[RDPQ_MAX_CHUNK_COUNT];
764 u8 dma_alloc_count, abs_index;
765 u32 chunk_size, array_size, offset;
767 fusion = instance->ctrl_context;
768 chunk_size = fusion->reply_alloc_sz * RDPQ_MAX_INDEX_IN_ONE_CHUNK;
769 array_size = sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) *
770 MAX_MSIX_QUEUES_FUSION;
772 fusion->rdpq_virt = dma_alloc_coherent(&instance->pdev->dev,
773 array_size, &fusion->rdpq_phys,
775 if (!fusion->rdpq_virt) {
776 dev_err(&instance->pdev->dev,
777 "Failed from %s %d\n", __func__, __LINE__);
781 msix_count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
783 fusion->reply_frames_desc_pool = dma_pool_create("mr_rdpq",
784 &instance->pdev->dev,
786 fusion->reply_frames_desc_pool_align =
787 dma_pool_create("mr_rdpq_align",
788 &instance->pdev->dev,
790 roundup_pow_of_two(chunk_size),
793 if (!fusion->reply_frames_desc_pool ||
794 !fusion->reply_frames_desc_pool_align) {
795 dev_err(&instance->pdev->dev,
796 "Failed from %s %d\n", __func__, __LINE__);
801 * For INVADER_SERIES each set of 8 reply queues(0-7, 8-15, ..) and
802 * VENTURA_SERIES each set of 16 reply queues(0-15, 16-31, ..) should be
803 * within 4GB boundary and also reply queues in a set must have same
804 * upper 32-bits in their memory address. so here driver is allocating the
805 * DMA'able memory for reply queues according. Driver uses limitation of
806 * VENTURA_SERIES to manage INVADER_SERIES as well.
808 dma_alloc_count = DIV_ROUND_UP(msix_count, RDPQ_MAX_INDEX_IN_ONE_CHUNK);
810 for (i = 0; i < dma_alloc_count; i++) {
812 dma_pool_alloc(fusion->reply_frames_desc_pool,
813 GFP_KERNEL, &rdpq_chunk_phys[i]);
814 if (!rdpq_chunk_virt[i]) {
815 dev_err(&instance->pdev->dev,
816 "Failed from %s %d\n", __func__, __LINE__);
819 /* reply desc pool requires to be in same 4 gb region.
820 * Below function will check this.
821 * In case of failure, new pci pool will be created with updated
823 * For RDPQ buffers, driver always allocate two separate pci pool.
824 * Alignment will be used such a way that next allocation if
825 * success, will always meet same 4gb region requirement.
826 * rdpq_tracker keep track of each buffer's physical,
827 * virtual address and pci pool descriptor. It will help driver
828 * while freeing the resources.
831 if (!megasas_check_same_4gb_region(instance, rdpq_chunk_phys[i],
833 dma_pool_free(fusion->reply_frames_desc_pool,
838 dma_pool_alloc(fusion->reply_frames_desc_pool_align,
839 GFP_KERNEL, &rdpq_chunk_phys[i]);
840 if (!rdpq_chunk_virt[i]) {
841 dev_err(&instance->pdev->dev,
842 "Failed from %s %d\n",
846 fusion->rdpq_tracker[i].dma_pool_ptr =
847 fusion->reply_frames_desc_pool_align;
849 fusion->rdpq_tracker[i].dma_pool_ptr =
850 fusion->reply_frames_desc_pool;
853 fusion->rdpq_tracker[i].pool_entry_phys = rdpq_chunk_phys[i];
854 fusion->rdpq_tracker[i].pool_entry_virt = rdpq_chunk_virt[i];
857 for (k = 0; k < dma_alloc_count; k++) {
858 for (i = 0; i < RDPQ_MAX_INDEX_IN_ONE_CHUNK; i++) {
859 abs_index = (k * RDPQ_MAX_INDEX_IN_ONE_CHUNK) + i;
861 if (abs_index == msix_count)
863 offset = fusion->reply_alloc_sz * i;
864 fusion->rdpq_virt[abs_index].RDPQBaseAddress =
865 cpu_to_le64(rdpq_chunk_phys[k] + offset);
866 fusion->reply_frames_desc_phys[abs_index] =
867 rdpq_chunk_phys[k] + offset;
868 fusion->reply_frames_desc[abs_index] =
869 (union MPI2_REPLY_DESCRIPTORS_UNION *)((u8 *)rdpq_chunk_virt[k] + offset);
871 reply_desc = fusion->reply_frames_desc[abs_index];
872 for (j = 0; j < fusion->reply_q_depth; j++, reply_desc++)
873 reply_desc->Words = ULLONG_MAX;
881 megasas_free_rdpq_fusion(struct megasas_instance *instance) {
884 struct fusion_context *fusion;
886 fusion = instance->ctrl_context;
888 for (i = 0; i < RDPQ_MAX_CHUNK_COUNT; i++) {
889 if (fusion->rdpq_tracker[i].pool_entry_virt)
890 dma_pool_free(fusion->rdpq_tracker[i].dma_pool_ptr,
891 fusion->rdpq_tracker[i].pool_entry_virt,
892 fusion->rdpq_tracker[i].pool_entry_phys);
896 dma_pool_destroy(fusion->reply_frames_desc_pool);
897 dma_pool_destroy(fusion->reply_frames_desc_pool_align);
899 if (fusion->rdpq_virt)
900 dma_free_coherent(&instance->pdev->dev,
901 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION,
902 fusion->rdpq_virt, fusion->rdpq_phys);
906 megasas_free_reply_fusion(struct megasas_instance *instance) {
908 struct fusion_context *fusion;
910 fusion = instance->ctrl_context;
912 if (fusion->reply_frames_desc[0])
913 dma_pool_free(fusion->reply_frames_desc_pool,
914 fusion->reply_frames_desc[0],
915 fusion->reply_frames_desc_phys[0]);
917 dma_pool_destroy(fusion->reply_frames_desc_pool);
923 * megasas_alloc_cmds_fusion - Allocates the command packets
924 * @instance: Adapter soft state
927 * Each frame has a 32-bit field called context. This context is used to get
928 * back the megasas_cmd_fusion from the frame when a frame gets completed
929 * In this driver, the 32 bit values are the indices into an array cmd_list.
930 * This array is used only to look up the megasas_cmd_fusion given the context.
931 * The free commands themselves are maintained in a linked list called cmd_pool.
933 * cmds are formed in the io_request and sg_frame members of the
934 * megasas_cmd_fusion. The context field is used to get a request descriptor
935 * and is used as SMID of the cmd.
936 * SMID value range is from 1 to max_fw_cmds.
939 megasas_alloc_cmds_fusion(struct megasas_instance *instance)
942 struct fusion_context *fusion;
943 struct megasas_cmd_fusion *cmd;
945 dma_addr_t io_req_base_phys;
949 fusion = instance->ctrl_context;
951 if (megasas_alloc_request_fusion(instance))
954 if (instance->is_rdpq) {
955 if (megasas_alloc_rdpq_fusion(instance))
958 if (megasas_alloc_reply_fusion(instance))
961 if (megasas_alloc_cmdlist_fusion(instance))
964 /* The first 256 bytes (SMID 0) is not used. Don't add to the cmd list */
965 io_req_base = fusion->io_request_frames + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
966 io_req_base_phys = fusion->io_request_frames_phys + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
969 * Add all the commands to command pool (fusion->cmd_pool)
972 /* SMID 0 is reserved. Set SMID/index from 1 */
973 for (i = 0; i < instance->max_mpt_cmds; i++) {
974 cmd = fusion->cmd_list[i];
975 offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i;
976 memset(cmd, 0, sizeof(struct megasas_cmd_fusion));
980 (i >= instance->max_scsi_cmds && i < instance->max_fw_cmds) ?
981 (i - instance->max_scsi_cmds) :
982 (u32)ULONG_MAX; /* Set to Invalid */
983 cmd->instance = instance;
985 (struct MPI2_RAID_SCSI_IO_REQUEST *)
986 (io_req_base + offset);
987 memset(cmd->io_request, 0,
988 sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
989 cmd->io_request_phys_addr = io_req_base_phys + offset;
990 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
993 if (megasas_create_sg_sense_fusion(instance))
999 megasas_free_cmds_fusion(instance);
1004 * wait_and_poll - Issues a polling command
1005 * @instance: Adapter soft state
1006 * @cmd: Command packet to be issued
1007 * @seconds: Maximum poll time
1009 * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
1012 wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd,
1016 struct megasas_header *frame_hdr = &cmd->frame->hdr;
1019 u32 msecs = seconds * 1000;
1022 * Wait for cmd_status to change
1024 for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) {
1028 status_reg = instance->instancet->read_fw_status_reg(instance)
1030 if (status_reg == MFI_STATE_FAULT)
1035 if (frame_hdr->cmd_status == MFI_STAT_INVALID_STATUS)
1036 return DCMD_TIMEOUT;
1037 else if (frame_hdr->cmd_status == MFI_STAT_OK)
1038 return DCMD_SUCCESS;
1044 * megasas_ioc_init_fusion - Initializes the FW
1045 * @instance: Adapter soft state
1047 * Issues the IOC Init cmd
1050 megasas_ioc_init_fusion(struct megasas_instance *instance)
1052 struct megasas_init_frame *init_frame;
1053 struct MPI2_IOC_INIT_REQUEST *IOCInitMessage = NULL;
1054 dma_addr_t ioc_init_handle;
1055 struct megasas_cmd *cmd;
1056 u8 ret, cur_rdpq_mode;
1057 struct fusion_context *fusion;
1058 union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc;
1060 struct megasas_header *frame_hdr;
1061 const char *sys_info;
1062 MFI_CAPABILITIES *drv_ops;
1065 bool cur_fw_64bit_dma_capable;
1066 bool cur_intr_coalescing;
1068 fusion = instance->ctrl_context;
1070 ioc_init_handle = fusion->ioc_init_request_phys;
1071 IOCInitMessage = fusion->ioc_init_request;
1073 cmd = fusion->ioc_init_cmd;
1075 scratch_pad_1 = megasas_readl
1076 (instance, &instance->reg_set->outbound_scratch_pad_1);
1078 cur_rdpq_mode = (scratch_pad_1 & MR_RDPQ_MODE_OFFSET) ? 1 : 0;
1080 if (instance->adapter_type == INVADER_SERIES) {
1081 cur_fw_64bit_dma_capable =
1082 (scratch_pad_1 & MR_CAN_HANDLE_64_BIT_DMA_OFFSET) ? true : false;
1084 if (instance->consistent_mask_64bit && !cur_fw_64bit_dma_capable) {
1085 dev_err(&instance->pdev->dev, "Driver was operating on 64bit "
1086 "DMA mask, but upcoming FW does not support 64bit DMA mask\n");
1087 megaraid_sas_kill_hba(instance);
1093 if (instance->is_rdpq && !cur_rdpq_mode) {
1094 dev_err(&instance->pdev->dev, "Firmware downgrade *NOT SUPPORTED*"
1095 " from RDPQ mode to non RDPQ mode\n");
1100 cur_intr_coalescing = (scratch_pad_1 & MR_INTR_COALESCING_SUPPORT_OFFSET) ?
1103 if ((instance->low_latency_index_start ==
1104 MR_HIGH_IOPS_QUEUE_COUNT) && cur_intr_coalescing)
1105 instance->perf_mode = MR_BALANCED_PERF_MODE;
1107 dev_info(&instance->pdev->dev, "Performance mode :%s (latency index = %d)\n",
1108 MEGASAS_PERF_MODE_2STR(instance->perf_mode),
1109 instance->low_latency_index_start);
1111 instance->fw_sync_cache_support = (scratch_pad_1 &
1112 MR_CAN_HANDLE_SYNC_CACHE_OFFSET) ? 1 : 0;
1113 dev_info(&instance->pdev->dev, "FW supports sync cache\t: %s\n",
1114 instance->fw_sync_cache_support ? "Yes" : "No");
1116 memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST));
1118 IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT;
1119 IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER;
1120 IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION);
1121 IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
1122 IOCInitMessage->SystemRequestFrameSize = cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4);
1124 IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth);
1125 IOCInitMessage->ReplyDescriptorPostQueueAddress = instance->is_rdpq ?
1126 cpu_to_le64(fusion->rdpq_phys) :
1127 cpu_to_le64(fusion->reply_frames_desc_phys[0]);
1128 IOCInitMessage->MsgFlags = instance->is_rdpq ?
1129 MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE : 0;
1130 IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys);
1131 IOCInitMessage->SenseBufferAddressHigh = cpu_to_le32(upper_32_bits(fusion->sense_phys_addr));
1132 IOCInitMessage->HostMSIxVectors = instance->msix_vectors;
1133 IOCInitMessage->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT;
1135 time = ktime_get_real();
1136 /* Convert to milliseconds as per FW requirement */
1137 IOCInitMessage->TimeStamp = cpu_to_le64(ktime_to_ms(time));
1139 init_frame = (struct megasas_init_frame *)cmd->frame;
1140 memset(init_frame, 0, IOC_INIT_FRAME_SIZE);
1142 frame_hdr = &cmd->frame->hdr;
1143 frame_hdr->cmd_status = 0xFF;
1144 frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE);
1146 init_frame->cmd = MFI_CMD_INIT;
1147 init_frame->cmd_status = 0xFF;
1149 drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations);
1151 /* driver support Extended MSIX */
1152 if (instance->adapter_type >= INVADER_SERIES)
1153 drv_ops->mfi_capabilities.support_additional_msix = 1;
1154 /* driver supports HA / Remote LUN over Fast Path interface */
1155 drv_ops->mfi_capabilities.support_fp_remote_lun = 1;
1157 drv_ops->mfi_capabilities.support_max_255lds = 1;
1158 drv_ops->mfi_capabilities.support_ndrive_r1_lb = 1;
1159 drv_ops->mfi_capabilities.security_protocol_cmds_fw = 1;
1161 if (instance->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN)
1162 drv_ops->mfi_capabilities.support_ext_io_size = 1;
1164 drv_ops->mfi_capabilities.support_fp_rlbypass = 1;
1165 if (!dual_qdepth_disable)
1166 drv_ops->mfi_capabilities.support_ext_queue_depth = 1;
1168 drv_ops->mfi_capabilities.support_qd_throttling = 1;
1169 drv_ops->mfi_capabilities.support_pd_map_target_id = 1;
1170 drv_ops->mfi_capabilities.support_nvme_passthru = 1;
1171 drv_ops->mfi_capabilities.support_fw_exposed_dev_list = 1;
1173 if (instance->consistent_mask_64bit)
1174 drv_ops->mfi_capabilities.support_64bit_mode = 1;
1176 /* Convert capability to LE32 */
1177 cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities);
1179 sys_info = dmi_get_system_info(DMI_PRODUCT_UUID);
1180 if (instance->system_info_buf && sys_info) {
1181 memcpy(instance->system_info_buf->systemId, sys_info,
1182 strlen(sys_info) > 64 ? 64 : strlen(sys_info));
1183 instance->system_info_buf->systemIdLength =
1184 strlen(sys_info) > 64 ? 64 : strlen(sys_info);
1185 init_frame->system_info_lo = cpu_to_le32(lower_32_bits(instance->system_info_h));
1186 init_frame->system_info_hi = cpu_to_le32(upper_32_bits(instance->system_info_h));
1189 init_frame->queue_info_new_phys_addr_hi =
1190 cpu_to_le32(upper_32_bits(ioc_init_handle));
1191 init_frame->queue_info_new_phys_addr_lo =
1192 cpu_to_le32(lower_32_bits(ioc_init_handle));
1193 init_frame->data_xfer_len = cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST));
1196 * Each bit in replyqueue_mask represents one group of MSI-x vectors
1197 * (each group has 8 vectors)
1199 switch (instance->perf_mode) {
1200 case MR_BALANCED_PERF_MODE:
1201 init_frame->replyqueue_mask =
1202 cpu_to_le16(~(~0 << instance->low_latency_index_start/8));
1204 case MR_IOPS_PERF_MODE:
1205 init_frame->replyqueue_mask =
1206 cpu_to_le16(~(~0 << instance->msix_vectors/8));
1211 req_desc.u.low = cpu_to_le32(lower_32_bits(cmd->frame_phys_addr));
1212 req_desc.u.high = cpu_to_le32(upper_32_bits(cmd->frame_phys_addr));
1213 req_desc.MFAIo.RequestFlags =
1214 (MEGASAS_REQ_DESCRIPT_FLAGS_MFA <<
1215 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1218 * disable the intr before firing the init frame
1220 instance->instancet->disable_intr(instance);
1222 for (i = 0; i < (10 * 1000); i += 20) {
1223 if (megasas_readl(instance, &instance->reg_set->doorbell) & 1)
1229 /* For AERO also, IOC_INIT requires 64 bit descriptor write */
1230 megasas_write_64bit_req_desc(instance, &req_desc);
1232 wait_and_poll(instance, cmd, MFI_IO_TIMEOUT_SECS);
1234 frame_hdr = &cmd->frame->hdr;
1235 if (frame_hdr->cmd_status != 0) {
1240 if (instance->adapter_type >= AERO_SERIES) {
1241 scratch_pad_1 = megasas_readl
1242 (instance, &instance->reg_set->outbound_scratch_pad_1);
1244 instance->atomic_desc_support =
1245 (scratch_pad_1 & MR_ATOMIC_DESCRIPTOR_SUPPORT_OFFSET) ? 1 : 0;
1247 dev_info(&instance->pdev->dev, "FW supports atomic descriptor\t: %s\n",
1248 instance->atomic_desc_support ? "Yes" : "No");
1254 dev_err(&instance->pdev->dev,
1255 "Init cmd return status FAILED for SCSI host %d\n",
1256 instance->host->host_no);
1262 * megasas_sync_pd_seq_num - JBOD SEQ MAP
1263 * @instance: Adapter soft state
1264 * @pend: set to 1, if it is pended jbod map.
1266 * Issue Jbod map to the firmware. If it is pended command,
1267 * issue command and return. If it is first instance of jbod map
1268 * issue and receive command.
1271 megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) {
1273 size_t pd_seq_map_sz;
1274 struct megasas_cmd *cmd;
1275 struct megasas_dcmd_frame *dcmd;
1276 struct fusion_context *fusion = instance->ctrl_context;
1277 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
1278 dma_addr_t pd_seq_h;
1280 pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)];
1281 pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)];
1282 pd_seq_map_sz = struct_size(pd_sync, seq, MAX_PHYSICAL_DEVICES - 1);
1284 cmd = megasas_get_cmd(instance);
1286 dev_err(&instance->pdev->dev,
1287 "Could not get mfi cmd. Fail from %s %d\n",
1288 __func__, __LINE__);
1292 dcmd = &cmd->frame->dcmd;
1294 memset(pd_sync, 0, pd_seq_map_sz);
1295 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1298 dcmd->mbox.b[0] = MEGASAS_DCMD_MBOX_PEND_FLAG;
1299 dcmd->flags = MFI_FRAME_DIR_WRITE;
1300 instance->jbod_seq_cmd = cmd;
1302 dcmd->flags = MFI_FRAME_DIR_READ;
1305 dcmd->cmd = MFI_CMD_DCMD;
1306 dcmd->cmd_status = 0xFF;
1307 dcmd->sge_count = 1;
1310 dcmd->data_xfer_len = cpu_to_le32(pd_seq_map_sz);
1311 dcmd->opcode = cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO);
1313 megasas_set_dma_settings(instance, dcmd, pd_seq_h, pd_seq_map_sz);
1316 instance->instancet->issue_dcmd(instance, cmd);
1320 /* Below code is only for non pended DCMD */
1321 if (!instance->mask_interrupts)
1322 ret = megasas_issue_blocked_cmd(instance, cmd,
1323 MFI_IO_TIMEOUT_SECS);
1325 ret = megasas_issue_polled(instance, cmd);
1327 if (le32_to_cpu(pd_sync->count) > MAX_PHYSICAL_DEVICES) {
1328 dev_warn(&instance->pdev->dev,
1329 "driver supports max %d JBOD, but FW reports %d\n",
1330 MAX_PHYSICAL_DEVICES, le32_to_cpu(pd_sync->count));
1334 if (ret == DCMD_TIMEOUT)
1335 dev_warn(&instance->pdev->dev,
1336 "%s DCMD timed out, continue without JBOD sequence map\n",
1339 if (ret == DCMD_SUCCESS)
1340 instance->pd_seq_map_id++;
1342 megasas_return_cmd(instance, cmd);
1347 * megasas_get_ld_map_info - Returns FW's ld_map structure
1348 * @instance: Adapter soft state
1349 * @pend: Pend the command or not
1350 * Issues an internal command (DCMD) to get the FW's controller PD
1351 * list structure. This information is mainly used to find out SYSTEM
1352 * supported by the FW.
1353 * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO
1354 * dcmd.mbox.b[0] - number of LDs being sync'd
1355 * dcmd.mbox.b[1] - 0 - complete command immediately.
1356 * - 1 - pend till config change
1357 * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP
1358 * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and
1359 * uses extended struct MR_FW_RAID_MAP_EXT
1362 megasas_get_ld_map_info(struct megasas_instance *instance)
1365 struct megasas_cmd *cmd;
1366 struct megasas_dcmd_frame *dcmd;
1368 dma_addr_t ci_h = 0;
1370 struct fusion_context *fusion;
1372 cmd = megasas_get_cmd(instance);
1375 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for map info\n");
1379 fusion = instance->ctrl_context;
1382 megasas_return_cmd(instance, cmd);
1386 dcmd = &cmd->frame->dcmd;
1388 size_map_info = fusion->current_map_sz;
1390 ci = (void *) fusion->ld_map[(instance->map_id & 1)];
1391 ci_h = fusion->ld_map_phys[(instance->map_id & 1)];
1394 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ld_map_info\n");
1395 megasas_return_cmd(instance, cmd);
1399 memset(ci, 0, fusion->max_map_sz);
1400 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1401 dcmd->cmd = MFI_CMD_DCMD;
1402 dcmd->cmd_status = 0xFF;
1403 dcmd->sge_count = 1;
1404 dcmd->flags = MFI_FRAME_DIR_READ;
1407 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
1408 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
1410 megasas_set_dma_settings(instance, dcmd, ci_h, size_map_info);
1412 if (!instance->mask_interrupts)
1413 ret = megasas_issue_blocked_cmd(instance, cmd,
1414 MFI_IO_TIMEOUT_SECS);
1416 ret = megasas_issue_polled(instance, cmd);
1418 if (ret == DCMD_TIMEOUT)
1419 dev_warn(&instance->pdev->dev,
1420 "%s DCMD timed out, RAID map is disabled\n",
1423 megasas_return_cmd(instance, cmd);
1429 megasas_get_map_info(struct megasas_instance *instance)
1431 struct fusion_context *fusion = instance->ctrl_context;
1433 fusion->fast_path_io = 0;
1434 if (!megasas_get_ld_map_info(instance)) {
1435 if (MR_ValidateMapInfo(instance, instance->map_id)) {
1436 fusion->fast_path_io = 1;
1444 * megasas_sync_map_info - Returns FW's ld_map structure
1445 * @instance: Adapter soft state
1447 * Issues an internal command (DCMD) to get the FW's controller PD
1448 * list structure. This information is mainly used to find out SYSTEM
1449 * supported by the FW.
1452 megasas_sync_map_info(struct megasas_instance *instance)
1455 struct megasas_cmd *cmd;
1456 struct megasas_dcmd_frame *dcmd;
1458 struct fusion_context *fusion;
1459 struct MR_LD_TARGET_SYNC *ci = NULL;
1460 struct MR_DRV_RAID_MAP_ALL *map;
1461 struct MR_LD_RAID *raid;
1462 struct MR_LD_TARGET_SYNC *ld_sync;
1463 dma_addr_t ci_h = 0;
1466 cmd = megasas_get_cmd(instance);
1469 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for sync info\n");
1473 fusion = instance->ctrl_context;
1476 megasas_return_cmd(instance, cmd);
1480 map = fusion->ld_drv_map[instance->map_id & 1];
1482 num_lds = le16_to_cpu(map->raidMap.ldCount);
1484 dcmd = &cmd->frame->dcmd;
1486 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1488 ci = (struct MR_LD_TARGET_SYNC *)
1489 fusion->ld_map[(instance->map_id - 1) & 1];
1490 memset(ci, 0, fusion->max_map_sz);
1492 ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1];
1494 ld_sync = (struct MR_LD_TARGET_SYNC *)ci;
1496 for (i = 0; i < num_lds; i++, ld_sync++) {
1497 raid = MR_LdRaidGet(i, map);
1498 ld_sync->targetId = MR_GetLDTgtId(i, map);
1499 ld_sync->seqNum = raid->seqNum;
1502 size_map_info = fusion->current_map_sz;
1504 dcmd->cmd = MFI_CMD_DCMD;
1505 dcmd->cmd_status = 0xFF;
1506 dcmd->sge_count = 1;
1507 dcmd->flags = MFI_FRAME_DIR_WRITE;
1510 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
1511 dcmd->mbox.b[0] = num_lds;
1512 dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG;
1513 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
1515 megasas_set_dma_settings(instance, dcmd, ci_h, size_map_info);
1517 instance->map_update_cmd = cmd;
1519 instance->instancet->issue_dcmd(instance, cmd);
1525 * meagasas_display_intel_branding - Display branding string
1526 * @instance: per adapter object
1531 megasas_display_intel_branding(struct megasas_instance *instance)
1533 if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1536 switch (instance->pdev->device) {
1537 case PCI_DEVICE_ID_LSI_INVADER:
1538 switch (instance->pdev->subsystem_device) {
1539 case MEGARAID_INTEL_RS3DC080_SSDID:
1540 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1541 instance->host->host_no,
1542 MEGARAID_INTEL_RS3DC080_BRANDING);
1544 case MEGARAID_INTEL_RS3DC040_SSDID:
1545 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1546 instance->host->host_no,
1547 MEGARAID_INTEL_RS3DC040_BRANDING);
1549 case MEGARAID_INTEL_RS3SC008_SSDID:
1550 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1551 instance->host->host_no,
1552 MEGARAID_INTEL_RS3SC008_BRANDING);
1554 case MEGARAID_INTEL_RS3MC044_SSDID:
1555 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1556 instance->host->host_no,
1557 MEGARAID_INTEL_RS3MC044_BRANDING);
1563 case PCI_DEVICE_ID_LSI_FURY:
1564 switch (instance->pdev->subsystem_device) {
1565 case MEGARAID_INTEL_RS3WC080_SSDID:
1566 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1567 instance->host->host_no,
1568 MEGARAID_INTEL_RS3WC080_BRANDING);
1570 case MEGARAID_INTEL_RS3WC040_SSDID:
1571 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1572 instance->host->host_no,
1573 MEGARAID_INTEL_RS3WC040_BRANDING);
1579 case PCI_DEVICE_ID_LSI_CUTLASS_52:
1580 case PCI_DEVICE_ID_LSI_CUTLASS_53:
1581 switch (instance->pdev->subsystem_device) {
1582 case MEGARAID_INTEL_RMS3BC160_SSDID:
1583 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1584 instance->host->host_no,
1585 MEGARAID_INTEL_RMS3BC160_BRANDING);
1597 * megasas_allocate_raid_maps - Allocate memory for RAID maps
1598 * @instance: Adapter soft state
1600 * return: if success: return 0
1601 * failed: return -ENOMEM
1603 static inline int megasas_allocate_raid_maps(struct megasas_instance *instance)
1605 struct fusion_context *fusion;
1608 fusion = instance->ctrl_context;
1610 fusion->drv_map_pages = get_order(fusion->drv_map_sz);
1612 for (i = 0; i < 2; i++) {
1613 fusion->ld_map[i] = NULL;
1615 fusion->ld_drv_map[i] = (void *)
1616 __get_free_pages(__GFP_ZERO | GFP_KERNEL,
1617 fusion->drv_map_pages);
1619 if (!fusion->ld_drv_map[i]) {
1620 fusion->ld_drv_map[i] = vzalloc(fusion->drv_map_sz);
1622 if (!fusion->ld_drv_map[i]) {
1623 dev_err(&instance->pdev->dev,
1624 "Could not allocate memory for local map"
1625 " size requested: %d\n",
1626 fusion->drv_map_sz);
1627 goto ld_drv_map_alloc_fail;
1632 for (i = 0; i < 2; i++) {
1633 fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev,
1635 &fusion->ld_map_phys[i],
1637 if (!fusion->ld_map[i]) {
1638 dev_err(&instance->pdev->dev,
1639 "Could not allocate memory for map info %s:%d\n",
1640 __func__, __LINE__);
1641 goto ld_map_alloc_fail;
1648 for (i = 0; i < 2; i++) {
1649 if (fusion->ld_map[i])
1650 dma_free_coherent(&instance->pdev->dev,
1653 fusion->ld_map_phys[i]);
1656 ld_drv_map_alloc_fail:
1657 for (i = 0; i < 2; i++) {
1658 if (fusion->ld_drv_map[i]) {
1659 if (is_vmalloc_addr(fusion->ld_drv_map[i]))
1660 vfree(fusion->ld_drv_map[i]);
1662 free_pages((ulong)fusion->ld_drv_map[i],
1663 fusion->drv_map_pages);
1671 * megasas_configure_queue_sizes - Calculate size of request desc queue,
1673 * IO request frame queue, set can_queue.
1674 * @instance: Adapter soft state
1678 void megasas_configure_queue_sizes(struct megasas_instance *instance)
1680 struct fusion_context *fusion;
1683 fusion = instance->ctrl_context;
1684 max_cmd = instance->max_fw_cmds;
1686 if (instance->adapter_type >= VENTURA_SERIES)
1687 instance->max_mpt_cmds = instance->max_fw_cmds * RAID_1_PEER_CMDS;
1689 instance->max_mpt_cmds = instance->max_fw_cmds;
1691 instance->max_scsi_cmds = instance->max_fw_cmds - instance->max_mfi_cmds;
1692 instance->cur_can_queue = instance->max_scsi_cmds;
1693 instance->host->can_queue = instance->cur_can_queue;
1695 fusion->reply_q_depth = 2 * ((max_cmd + 1 + 15) / 16) * 16;
1697 fusion->request_alloc_sz = sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *
1698 instance->max_mpt_cmds;
1699 fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION) *
1700 (fusion->reply_q_depth);
1701 fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE +
1702 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1703 * (instance->max_mpt_cmds + 1)); /* Extra 1 for SMID 0 */
1706 static int megasas_alloc_ioc_init_frame(struct megasas_instance *instance)
1708 struct fusion_context *fusion;
1709 struct megasas_cmd *cmd;
1711 fusion = instance->ctrl_context;
1713 cmd = kzalloc(sizeof(struct megasas_cmd), GFP_KERNEL);
1716 dev_err(&instance->pdev->dev, "Failed from func: %s line: %d\n",
1717 __func__, __LINE__);
1721 cmd->frame = dma_alloc_coherent(&instance->pdev->dev,
1722 IOC_INIT_FRAME_SIZE,
1723 &cmd->frame_phys_addr, GFP_KERNEL);
1726 dev_err(&instance->pdev->dev, "Failed from func: %s line: %d\n",
1727 __func__, __LINE__);
1732 fusion->ioc_init_cmd = cmd;
1737 * megasas_free_ioc_init_cmd - Free IOC INIT command frame
1738 * @instance: Adapter soft state
1740 static inline void megasas_free_ioc_init_cmd(struct megasas_instance *instance)
1742 struct fusion_context *fusion;
1744 fusion = instance->ctrl_context;
1746 if (fusion->ioc_init_cmd && fusion->ioc_init_cmd->frame)
1747 dma_free_coherent(&instance->pdev->dev,
1748 IOC_INIT_FRAME_SIZE,
1749 fusion->ioc_init_cmd->frame,
1750 fusion->ioc_init_cmd->frame_phys_addr);
1752 kfree(fusion->ioc_init_cmd);
1756 * megasas_init_adapter_fusion - Initializes the FW
1757 * @instance: Adapter soft state
1759 * This is the main function for initializing firmware.
1762 megasas_init_adapter_fusion(struct megasas_instance *instance)
1764 struct fusion_context *fusion;
1769 fusion = instance->ctrl_context;
1771 megasas_fusion_update_can_queue(instance, PROBE_CONTEXT);
1774 * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames
1776 instance->max_mfi_cmds =
1777 MEGASAS_FUSION_INTERNAL_CMDS + MEGASAS_FUSION_IOCTL_CMDS;
1779 megasas_configure_queue_sizes(instance);
1781 scratch_pad_1 = megasas_readl(instance,
1782 &instance->reg_set->outbound_scratch_pad_1);
1783 /* If scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set,
1784 * Firmware support extended IO chain frame which is 4 times more than
1786 * Legacy Firmware - Frame size is (8 * 128) = 1K
1787 * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K
1789 if (scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK)
1790 instance->max_chain_frame_sz =
1791 ((scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_MASK) >>
1792 MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_1MB_IO;
1794 instance->max_chain_frame_sz =
1795 ((scratch_pad_1 & MEGASAS_MAX_CHAIN_SIZE_MASK) >>
1796 MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_256K_IO;
1798 if (instance->max_chain_frame_sz < MEGASAS_CHAIN_FRAME_SZ_MIN) {
1799 dev_warn(&instance->pdev->dev, "frame size %d invalid, fall back to legacy max frame size %d\n",
1800 instance->max_chain_frame_sz,
1801 MEGASAS_CHAIN_FRAME_SZ_MIN);
1802 instance->max_chain_frame_sz = MEGASAS_CHAIN_FRAME_SZ_MIN;
1805 fusion->max_sge_in_main_msg =
1806 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1807 - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16;
1809 fusion->max_sge_in_chain =
1810 instance->max_chain_frame_sz
1811 / sizeof(union MPI2_SGE_IO_UNION);
1813 instance->max_num_sge =
1814 rounddown_pow_of_two(fusion->max_sge_in_main_msg
1815 + fusion->max_sge_in_chain - 2);
1817 /* Used for pass thru MFI frame (DCMD) */
1818 fusion->chain_offset_mfi_pthru =
1819 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16;
1821 fusion->chain_offset_io_request =
1822 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
1823 sizeof(union MPI2_SGE_IO_UNION))/16;
1825 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
1826 for (i = 0 ; i < count; i++)
1827 fusion->last_reply_idx[i] = 0;
1830 * For fusion adapters, 3 commands for IOCTL and 8 commands
1831 * for driver's internal DCMDs.
1833 instance->max_scsi_cmds = instance->max_fw_cmds -
1834 (MEGASAS_FUSION_INTERNAL_CMDS +
1835 MEGASAS_FUSION_IOCTL_CMDS);
1836 sema_init(&instance->ioctl_sem, MEGASAS_FUSION_IOCTL_CMDS);
1838 if (megasas_alloc_ioc_init_frame(instance))
1842 * Allocate memory for descriptors
1843 * Create a pool of commands
1845 if (megasas_alloc_cmds(instance))
1846 goto fail_alloc_mfi_cmds;
1847 if (megasas_alloc_cmds_fusion(instance))
1848 goto fail_alloc_cmds;
1850 if (megasas_ioc_init_fusion(instance)) {
1851 status_reg = instance->instancet->read_fw_status_reg(instance);
1852 if (((status_reg & MFI_STATE_MASK) == MFI_STATE_FAULT) &&
1853 (status_reg & MFI_RESET_ADAPTER)) {
1854 /* Do a chip reset and then retry IOC INIT once */
1855 if (megasas_adp_reset_wait_for_ready
1856 (instance, true, 0) == FAILED)
1859 if (megasas_ioc_init_fusion(instance))
1866 megasas_display_intel_branding(instance);
1867 if (megasas_get_ctrl_info(instance)) {
1868 dev_err(&instance->pdev->dev,
1869 "Could not get controller info. Fail from %s %d\n",
1870 __func__, __LINE__);
1874 instance->flag_ieee = 1;
1875 instance->r1_ldio_hint_default = MR_R1_LDIO_PIGGYBACK_DEFAULT;
1876 instance->threshold_reply_count = instance->max_fw_cmds / 4;
1877 fusion->fast_path_io = 0;
1879 if (megasas_allocate_raid_maps(instance))
1882 if (!megasas_get_map_info(instance))
1883 megasas_sync_map_info(instance);
1888 megasas_free_cmds_fusion(instance);
1890 megasas_free_cmds(instance);
1891 fail_alloc_mfi_cmds:
1892 megasas_free_ioc_init_cmd(instance);
1897 * megasas_fault_detect_work - Worker function of
1898 * FW fault handling workqueue.
1899 * @work: FW fault work struct
1902 megasas_fault_detect_work(struct work_struct *work)
1904 struct megasas_instance *instance =
1905 container_of(work, struct megasas_instance,
1906 fw_fault_work.work);
1907 u32 fw_state, dma_state, status;
1909 /* Check the fw state */
1910 fw_state = instance->instancet->read_fw_status_reg(instance) &
1913 if (fw_state == MFI_STATE_FAULT) {
1914 dma_state = instance->instancet->read_fw_status_reg(instance) &
1916 /* Start collecting crash, if DMA bit is done */
1917 if (instance->crash_dump_drv_support &&
1918 instance->crash_dump_app_support && dma_state) {
1919 megasas_fusion_crash_dump(instance);
1921 if (instance->unload == 0) {
1922 status = megasas_reset_fusion(instance->host, 0);
1923 if (status != SUCCESS) {
1924 dev_err(&instance->pdev->dev,
1925 "Failed from %s %d, do not re-arm timer\n",
1926 __func__, __LINE__);
1933 if (instance->fw_fault_work_q)
1934 queue_delayed_work(instance->fw_fault_work_q,
1935 &instance->fw_fault_work,
1936 msecs_to_jiffies(MEGASAS_WATCHDOG_THREAD_INTERVAL));
1940 megasas_fusion_start_watchdog(struct megasas_instance *instance)
1942 /* Check if the Fault WQ is already started */
1943 if (instance->fw_fault_work_q)
1946 INIT_DELAYED_WORK(&instance->fw_fault_work, megasas_fault_detect_work);
1948 snprintf(instance->fault_handler_work_q_name,
1949 sizeof(instance->fault_handler_work_q_name),
1950 "poll_megasas%d_status", instance->host->host_no);
1952 instance->fw_fault_work_q =
1953 create_singlethread_workqueue(instance->fault_handler_work_q_name);
1954 if (!instance->fw_fault_work_q) {
1955 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
1956 __func__, __LINE__);
1960 queue_delayed_work(instance->fw_fault_work_q,
1961 &instance->fw_fault_work,
1962 msecs_to_jiffies(MEGASAS_WATCHDOG_THREAD_INTERVAL));
1968 megasas_fusion_stop_watchdog(struct megasas_instance *instance)
1970 struct workqueue_struct *wq;
1972 if (instance->fw_fault_work_q) {
1973 wq = instance->fw_fault_work_q;
1974 instance->fw_fault_work_q = NULL;
1975 if (!cancel_delayed_work_sync(&instance->fw_fault_work))
1976 flush_workqueue(wq);
1977 destroy_workqueue(wq);
1982 * map_cmd_status - Maps FW cmd status to OS cmd status
1983 * @fusion: fusion context
1984 * @scmd: Pointer to cmd
1985 * @status: status of cmd returned by FW
1986 * @ext_status: ext status of cmd returned by FW
1987 * @data_length: command data length
1988 * @sense: command sense data
1991 map_cmd_status(struct fusion_context *fusion,
1992 struct scsi_cmnd *scmd, u8 status, u8 ext_status,
1993 u32 data_length, u8 *sense)
1998 cmd_type = megasas_cmd_type(scmd);
2002 scmd->result = DID_OK << 16;
2005 case MFI_STAT_SCSI_IO_FAILED:
2006 case MFI_STAT_LD_INIT_IN_PROGRESS:
2007 scmd->result = (DID_ERROR << 16) | ext_status;
2010 case MFI_STAT_SCSI_DONE_WITH_ERROR:
2012 scmd->result = (DID_OK << 16) | ext_status;
2013 if (ext_status == SAM_STAT_CHECK_CONDITION) {
2014 memset(scmd->sense_buffer, 0,
2015 SCSI_SENSE_BUFFERSIZE);
2016 memcpy(scmd->sense_buffer, sense,
2017 SCSI_SENSE_BUFFERSIZE);
2018 scmd->result |= DRIVER_SENSE << 24;
2022 * If the IO request is partially completed, then MR FW will
2023 * update "io_request->DataLength" field with actual number of
2024 * bytes transferred.Driver will set residual bytes count in
2025 * SCSI command structure.
2027 resid = (scsi_bufflen(scmd) - data_length);
2028 scsi_set_resid(scmd, resid);
2031 ((cmd_type == READ_WRITE_LDIO) ||
2032 (cmd_type == READ_WRITE_SYSPDIO)))
2033 scmd_printk(KERN_INFO, scmd, "BRCM Debug mfi stat 0x%x, data len"
2034 " requested/completed 0x%x/0x%x\n",
2035 status, scsi_bufflen(scmd), data_length);
2038 case MFI_STAT_LD_OFFLINE:
2039 case MFI_STAT_DEVICE_NOT_FOUND:
2040 scmd->result = DID_BAD_TARGET << 16;
2042 case MFI_STAT_CONFIG_SEQ_MISMATCH:
2043 scmd->result = DID_IMM_RETRY << 16;
2046 scmd->result = DID_ERROR << 16;
2052 * megasas_is_prp_possible -
2053 * Checks if native NVMe PRPs can be built for the IO
2055 * @instance: Adapter soft state
2056 * @scmd: SCSI command from the mid-layer
2057 * @sge_count: scatter gather element count.
2059 * Returns: true: PRPs can be built
2060 * false: IEEE SGLs needs to be built
2063 megasas_is_prp_possible(struct megasas_instance *instance,
2064 struct scsi_cmnd *scmd, int sge_count)
2066 u32 data_length = 0;
2067 struct scatterlist *sg_scmd;
2068 bool build_prp = false;
2069 u32 mr_nvme_pg_size;
2071 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
2072 MR_DEFAULT_NVME_PAGE_SIZE);
2073 data_length = scsi_bufflen(scmd);
2074 sg_scmd = scsi_sglist(scmd);
2077 * NVMe uses one PRP for each page (or part of a page)
2078 * look at the data length - if 4 pages or less then IEEE is OK
2079 * if > 5 pages then we need to build a native SGL
2080 * if > 4 and <= 5 pages, then check physical address of 1st SG entry
2081 * if this first size in the page is >= the residual beyond 4 pages
2082 * then use IEEE, otherwise use native SGL
2085 if (data_length > (mr_nvme_pg_size * 5)) {
2087 } else if ((data_length > (mr_nvme_pg_size * 4)) &&
2088 (data_length <= (mr_nvme_pg_size * 5))) {
2089 /* check if 1st SG entry size is < residual beyond 4 pages */
2090 if (sg_dma_len(sg_scmd) < (data_length - (mr_nvme_pg_size * 4)))
2098 * megasas_make_prp_nvme -
2099 * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only
2101 * @instance: Adapter soft state
2102 * @scmd: SCSI command from the mid-layer
2103 * @sgl_ptr: SGL to be filled in
2104 * @cmd: Fusion command frame
2105 * @sge_count: scatter gather element count.
2107 * Returns: true: PRPs are built
2108 * false: IEEE SGLs needs to be built
2111 megasas_make_prp_nvme(struct megasas_instance *instance, struct scsi_cmnd *scmd,
2112 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
2113 struct megasas_cmd_fusion *cmd, int sge_count)
2115 int sge_len, offset, num_prp_in_chain = 0;
2116 struct MPI25_IEEE_SGE_CHAIN64 *main_chain_element, *ptr_first_sgl;
2118 dma_addr_t ptr_sgl_phys;
2120 u32 page_mask, page_mask_result;
2121 struct scatterlist *sg_scmd;
2123 bool build_prp = false;
2124 int data_len = scsi_bufflen(scmd);
2125 u32 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
2126 MR_DEFAULT_NVME_PAGE_SIZE);
2128 build_prp = megasas_is_prp_possible(instance, scmd, sge_count);
2134 * Nvme has a very convoluted prp format. One prp is required
2135 * for each page or partial page. Driver need to split up OS sg_list
2136 * entries if it is longer than one page or cross a page
2137 * boundary. Driver also have to insert a PRP list pointer entry as
2138 * the last entry in each physical page of the PRP list.
2140 * NOTE: The first PRP "entry" is actually placed in the first
2141 * SGL entry in the main message as IEEE 64 format. The 2nd
2142 * entry in the main message is the chain element, and the rest
2143 * of the PRP entries are built in the contiguous pcie buffer.
2145 page_mask = mr_nvme_pg_size - 1;
2146 ptr_sgl = (u64 *)cmd->sg_frame;
2147 ptr_sgl_phys = cmd->sg_frame_phys_addr;
2148 memset(ptr_sgl, 0, instance->max_chain_frame_sz);
2150 /* Build chain frame element which holds all prps except first*/
2151 main_chain_element = (struct MPI25_IEEE_SGE_CHAIN64 *)
2152 ((u8 *)sgl_ptr + sizeof(struct MPI25_IEEE_SGE_CHAIN64));
2154 main_chain_element->Address = cpu_to_le64(ptr_sgl_phys);
2155 main_chain_element->NextChainOffset = 0;
2156 main_chain_element->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
2157 IEEE_SGE_FLAGS_SYSTEM_ADDR |
2158 MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP;
2160 /* Build first prp, sge need not to be page aligned*/
2161 ptr_first_sgl = sgl_ptr;
2162 sg_scmd = scsi_sglist(scmd);
2163 sge_addr = sg_dma_address(sg_scmd);
2164 sge_len = sg_dma_len(sg_scmd);
2166 offset = (u32)(sge_addr & page_mask);
2167 first_prp_len = mr_nvme_pg_size - offset;
2169 ptr_first_sgl->Address = cpu_to_le64(sge_addr);
2170 ptr_first_sgl->Length = cpu_to_le32(first_prp_len);
2172 data_len -= first_prp_len;
2174 if (sge_len > first_prp_len) {
2175 sge_addr += first_prp_len;
2176 sge_len -= first_prp_len;
2177 } else if (sge_len == first_prp_len) {
2178 sg_scmd = sg_next(sg_scmd);
2179 sge_addr = sg_dma_address(sg_scmd);
2180 sge_len = sg_dma_len(sg_scmd);
2184 offset = (u32)(sge_addr & page_mask);
2186 /* Put PRP pointer due to page boundary*/
2187 page_mask_result = (uintptr_t)(ptr_sgl + 1) & page_mask;
2188 if (unlikely(!page_mask_result)) {
2189 scmd_printk(KERN_NOTICE,
2190 scmd, "page boundary ptr_sgl: 0x%p\n",
2193 *ptr_sgl = cpu_to_le64(ptr_sgl_phys);
2198 *ptr_sgl = cpu_to_le64(sge_addr);
2203 sge_addr += mr_nvme_pg_size;
2204 sge_len -= mr_nvme_pg_size;
2205 data_len -= mr_nvme_pg_size;
2213 sg_scmd = sg_next(sg_scmd);
2214 sge_addr = sg_dma_address(sg_scmd);
2215 sge_len = sg_dma_len(sg_scmd);
2218 main_chain_element->Length =
2219 cpu_to_le32(num_prp_in_chain * sizeof(u64));
2225 * megasas_make_sgl_fusion - Prepares 32-bit SGL
2226 * @instance: Adapter soft state
2227 * @scp: SCSI command from the mid-layer
2228 * @sgl_ptr: SGL to be filled in
2229 * @cmd: cmd we are working on
2230 * @sge_count: sge count
2234 megasas_make_sgl_fusion(struct megasas_instance *instance,
2235 struct scsi_cmnd *scp,
2236 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
2237 struct megasas_cmd_fusion *cmd, int sge_count)
2239 int i, sg_processed;
2240 struct scatterlist *os_sgl;
2241 struct fusion_context *fusion;
2243 fusion = instance->ctrl_context;
2245 if (instance->adapter_type >= INVADER_SERIES) {
2246 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
2247 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
2248 sgl_ptr_end->Flags = 0;
2251 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
2252 sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl));
2253 sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl));
2255 if (instance->adapter_type >= INVADER_SERIES)
2256 if (i == sge_count - 1)
2257 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
2259 sg_processed = i + 1;
2261 if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) &&
2262 (sge_count > fusion->max_sge_in_main_msg)) {
2264 struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
2265 if (instance->adapter_type >= INVADER_SERIES) {
2266 if ((le16_to_cpu(cmd->io_request->IoFlags) &
2267 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
2268 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
2269 cmd->io_request->ChainOffset =
2271 chain_offset_io_request;
2273 cmd->io_request->ChainOffset = 0;
2275 cmd->io_request->ChainOffset =
2276 fusion->chain_offset_io_request;
2279 /* Prepare chain element */
2280 sg_chain->NextChainOffset = 0;
2281 if (instance->adapter_type >= INVADER_SERIES)
2282 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
2285 (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
2286 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
2287 sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed)));
2288 sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr);
2291 (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame;
2292 memset(sgl_ptr, 0, instance->max_chain_frame_sz);
2298 * megasas_make_sgl - Build Scatter Gather List(SGLs)
2299 * @scp: SCSI command pointer
2300 * @instance: Soft instance of controller
2301 * @cmd: Fusion command pointer
2303 * This function will build sgls based on device type.
2304 * For nvme drives, there is different way of building sgls in nvme native
2305 * format- PRPs(Physical Region Page).
2307 * Returns the number of sg lists actually used, zero if the sg lists
2308 * is NULL, or -ENOMEM if the mapping failed
2311 int megasas_make_sgl(struct megasas_instance *instance, struct scsi_cmnd *scp,
2312 struct megasas_cmd_fusion *cmd)
2315 bool build_prp = false;
2316 struct MPI25_IEEE_SGE_CHAIN64 *sgl_chain64;
2318 sge_count = scsi_dma_map(scp);
2320 if ((sge_count > instance->max_num_sge) || (sge_count <= 0))
2323 sgl_chain64 = (struct MPI25_IEEE_SGE_CHAIN64 *)&cmd->io_request->SGL;
2324 if ((le16_to_cpu(cmd->io_request->IoFlags) &
2325 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) &&
2326 (cmd->pd_interface == NVME_PD))
2327 build_prp = megasas_make_prp_nvme(instance, scp, sgl_chain64,
2331 megasas_make_sgl_fusion(instance, scp, sgl_chain64,
2338 * megasas_set_pd_lba - Sets PD LBA
2339 * @io_request: IO request
2340 * @cdb_len: cdb length
2341 * @io_info: IO information
2342 * @scp: SCSI command
2343 * @local_map_ptr: Raid map
2344 * @ref_tag: Primary reference tag
2346 * Used to set the PD LBA in CDB for FP IOs
2349 megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
2350 struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp,
2351 struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
2353 struct MR_LD_RAID *raid;
2355 u64 start_blk = io_info->pdBlock;
2356 u8 *cdb = io_request->CDB.CDB32;
2357 u32 num_blocks = io_info->numBlocks;
2358 u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0;
2360 /* Check if T10 PI (DIF) is enabled for this LD */
2361 ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr);
2362 raid = MR_LdRaidGet(ld, local_map_ptr);
2363 if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) {
2364 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
2365 cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD;
2366 cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN;
2368 if (scp->sc_data_direction == DMA_FROM_DEVICE)
2369 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32;
2371 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32;
2372 cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL;
2375 cdb[12] = (u8)((start_blk >> 56) & 0xff);
2376 cdb[13] = (u8)((start_blk >> 48) & 0xff);
2377 cdb[14] = (u8)((start_blk >> 40) & 0xff);
2378 cdb[15] = (u8)((start_blk >> 32) & 0xff);
2379 cdb[16] = (u8)((start_blk >> 24) & 0xff);
2380 cdb[17] = (u8)((start_blk >> 16) & 0xff);
2381 cdb[18] = (u8)((start_blk >> 8) & 0xff);
2382 cdb[19] = (u8)(start_blk & 0xff);
2384 /* Logical block reference tag */
2385 io_request->CDB.EEDP32.PrimaryReferenceTag =
2386 cpu_to_be32(ref_tag);
2387 io_request->CDB.EEDP32.PrimaryApplicationTagMask = cpu_to_be16(0xffff);
2388 io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */
2390 /* Transfer length */
2391 cdb[28] = (u8)((num_blocks >> 24) & 0xff);
2392 cdb[29] = (u8)((num_blocks >> 16) & 0xff);
2393 cdb[30] = (u8)((num_blocks >> 8) & 0xff);
2394 cdb[31] = (u8)(num_blocks & 0xff);
2396 /* set SCSI IO EEDPFlags */
2397 if (scp->sc_data_direction == DMA_FROM_DEVICE) {
2398 io_request->EEDPFlags = cpu_to_le16(
2399 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2400 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
2401 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
2402 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
2403 MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE |
2404 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD);
2406 io_request->EEDPFlags = cpu_to_le16(
2407 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
2408 MPI2_SCSIIO_EEDPFLAGS_INSERT_OP);
2410 io_request->Control |= cpu_to_le32((0x4 << 26));
2411 io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size);
2413 /* Some drives don't support 16/12 byte CDB's, convert to 10 */
2414 if (((cdb_len == 12) || (cdb_len == 16)) &&
2415 (start_blk <= 0xffffffff)) {
2416 if (cdb_len == 16) {
2417 opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
2422 opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
2428 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
2435 /* Transfer length */
2436 cdb[8] = (u8)(num_blocks & 0xff);
2437 cdb[7] = (u8)((num_blocks >> 8) & 0xff);
2439 io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */
2441 } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) {
2442 /* Convert to 16 byte CDB for large LBA's */
2445 opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16;
2450 cdb[0] == READ_10 ? READ_16 : WRITE_16;
2457 cdb[0] == READ_12 ? READ_16 : WRITE_16;
2464 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
2471 /* Transfer length */
2472 cdb[13] = (u8)(num_blocks & 0xff);
2473 cdb[12] = (u8)((num_blocks >> 8) & 0xff);
2474 cdb[11] = (u8)((num_blocks >> 16) & 0xff);
2475 cdb[10] = (u8)((num_blocks >> 24) & 0xff);
2477 io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */
2481 /* Normal case, just load LBA here */
2485 u8 val = cdb[1] & 0xE0;
2486 cdb[3] = (u8)(start_blk & 0xff);
2487 cdb[2] = (u8)((start_blk >> 8) & 0xff);
2488 cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f);
2492 cdb[5] = (u8)(start_blk & 0xff);
2493 cdb[4] = (u8)((start_blk >> 8) & 0xff);
2494 cdb[3] = (u8)((start_blk >> 16) & 0xff);
2495 cdb[2] = (u8)((start_blk >> 24) & 0xff);
2498 cdb[5] = (u8)(start_blk & 0xff);
2499 cdb[4] = (u8)((start_blk >> 8) & 0xff);
2500 cdb[3] = (u8)((start_blk >> 16) & 0xff);
2501 cdb[2] = (u8)((start_blk >> 24) & 0xff);
2504 cdb[9] = (u8)(start_blk & 0xff);
2505 cdb[8] = (u8)((start_blk >> 8) & 0xff);
2506 cdb[7] = (u8)((start_blk >> 16) & 0xff);
2507 cdb[6] = (u8)((start_blk >> 24) & 0xff);
2508 cdb[5] = (u8)((start_blk >> 32) & 0xff);
2509 cdb[4] = (u8)((start_blk >> 40) & 0xff);
2510 cdb[3] = (u8)((start_blk >> 48) & 0xff);
2511 cdb[2] = (u8)((start_blk >> 56) & 0xff);
2518 * megasas_stream_detect - stream detection on read and and write IOs
2519 * @instance: Adapter soft state
2520 * @cmd: Command to be prepared
2521 * @io_info: IO Request info
2525 /** stream detection on read and and write IOs */
2526 static void megasas_stream_detect(struct megasas_instance *instance,
2527 struct megasas_cmd_fusion *cmd,
2528 struct IO_REQUEST_INFO *io_info)
2530 struct fusion_context *fusion = instance->ctrl_context;
2531 u32 device_id = io_info->ldTgtId;
2532 struct LD_STREAM_DETECT *current_ld_sd
2533 = fusion->stream_detect_by_ld[device_id];
2534 u32 *track_stream = ¤t_ld_sd->mru_bit_map, stream_num;
2535 u32 shifted_values, unshifted_values;
2536 u32 index_value_mask, shifted_values_mask;
2538 bool is_read_ahead = false;
2539 struct STREAM_DETECT *current_sd;
2540 /* find possible stream */
2541 for (i = 0; i < MAX_STREAMS_TRACKED; ++i) {
2542 stream_num = (*track_stream >>
2543 (i * BITS_PER_INDEX_STREAM)) &
2545 current_sd = ¤t_ld_sd->stream_track[stream_num];
2546 /* if we found a stream, update the raid
2547 * context and also update the mruBitMap
2549 /* boundary condition */
2550 if ((current_sd->next_seq_lba) &&
2551 (io_info->ldStartBlock >= current_sd->next_seq_lba) &&
2552 (io_info->ldStartBlock <= (current_sd->next_seq_lba + 32)) &&
2553 (current_sd->is_read == io_info->isRead)) {
2555 if ((io_info->ldStartBlock != current_sd->next_seq_lba) &&
2556 ((!io_info->isRead) || (!is_read_ahead)))
2558 * Once the API availible we need to change this.
2559 * At this point we are not allowing any gap
2563 SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35);
2564 current_sd->next_seq_lba =
2565 io_info->ldStartBlock + io_info->numBlocks;
2567 * update the mruBitMap LRU
2569 shifted_values_mask =
2570 (1 << i * BITS_PER_INDEX_STREAM) - 1;
2571 shifted_values = ((*track_stream & shifted_values_mask)
2572 << BITS_PER_INDEX_STREAM);
2574 STREAM_MASK << i * BITS_PER_INDEX_STREAM;
2576 *track_stream & ~(shifted_values_mask |
2579 unshifted_values | shifted_values | stream_num;
2584 * if we did not find any stream, create a new one
2585 * from the least recently used
2587 stream_num = (*track_stream >>
2588 ((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) &
2590 current_sd = ¤t_ld_sd->stream_track[stream_num];
2591 current_sd->is_read = io_info->isRead;
2592 current_sd->next_seq_lba = io_info->ldStartBlock + io_info->numBlocks;
2593 *track_stream = (((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num);
2598 * megasas_set_raidflag_cpu_affinity - This function sets the cpu
2599 * affinity (cpu of the controller) and raid_flags in the raid context
2602 * @fusion: Fusion context
2603 * @praid_context: IO RAID context
2604 * @raid: LD raid map
2605 * @fp_possible: Is fast path possible?
2606 * @is_read: Is read IO?
2607 * @scsi_buff_len: SCSI command buffer length
2611 megasas_set_raidflag_cpu_affinity(struct fusion_context *fusion,
2612 union RAID_CONTEXT_UNION *praid_context,
2613 struct MR_LD_RAID *raid, bool fp_possible,
2614 u8 is_read, u32 scsi_buff_len)
2616 u8 cpu_sel = MR_RAID_CTX_CPUSEL_0;
2617 struct RAID_CONTEXT_G35 *rctx_g35;
2619 rctx_g35 = &praid_context->raid_context_g35;
2622 if ((raid->cpuAffinity.pdRead.cpu0) &&
2623 (raid->cpuAffinity.pdRead.cpu1))
2624 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2625 else if (raid->cpuAffinity.pdRead.cpu1)
2626 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2628 if ((raid->cpuAffinity.pdWrite.cpu0) &&
2629 (raid->cpuAffinity.pdWrite.cpu1))
2630 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2631 else if (raid->cpuAffinity.pdWrite.cpu1)
2632 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2633 /* Fast path cache by pass capable R0/R1 VD */
2634 if ((raid->level <= 1) &&
2635 (raid->capability.fp_cache_bypass_capable)) {
2636 rctx_g35->routing_flags |=
2637 (1 << MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT);
2638 rctx_g35->raid_flags =
2639 (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
2640 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2645 if ((raid->cpuAffinity.ldRead.cpu0) &&
2646 (raid->cpuAffinity.ldRead.cpu1))
2647 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2648 else if (raid->cpuAffinity.ldRead.cpu1)
2649 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2651 if ((raid->cpuAffinity.ldWrite.cpu0) &&
2652 (raid->cpuAffinity.ldWrite.cpu1))
2653 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2654 else if (raid->cpuAffinity.ldWrite.cpu1)
2655 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2657 if (is_stream_detected(rctx_g35) &&
2658 ((raid->level == 5) || (raid->level == 6)) &&
2659 (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) &&
2660 (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS))
2661 cpu_sel = MR_RAID_CTX_CPUSEL_0;
2665 rctx_g35->routing_flags |=
2666 (cpu_sel << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2668 /* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2669 * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS.
2670 * IO Subtype is not bitmap.
2672 if ((fusion->pcie_bw_limitation) && (raid->level == 1) && (!is_read) &&
2673 (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)) {
2674 praid_context->raid_context_g35.raid_flags =
2675 (MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2676 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2681 * megasas_build_ldio_fusion - Prepares IOs to devices
2682 * @instance: Adapter soft state
2683 * @scp: SCSI command
2684 * @cmd: Command to be prepared
2686 * Prepares the io_request and chain elements (sg_frame) for IO
2687 * The IO can be for PD (Fast Path) or LD
2690 megasas_build_ldio_fusion(struct megasas_instance *instance,
2691 struct scsi_cmnd *scp,
2692 struct megasas_cmd_fusion *cmd)
2696 u32 start_lba_lo, start_lba_hi, device_id, datalength = 0;
2698 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
2699 struct IO_REQUEST_INFO io_info;
2700 struct fusion_context *fusion;
2701 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
2703 unsigned long spinlock_flags;
2704 struct MR_LD_RAID *raid = NULL;
2705 struct MR_PRIV_DEVICE *mrdev_priv;
2706 struct RAID_CONTEXT *rctx;
2707 struct RAID_CONTEXT_G35 *rctx_g35;
2709 device_id = MEGASAS_DEV_INDEX(scp);
2711 fusion = instance->ctrl_context;
2713 io_request = cmd->io_request;
2714 rctx = &io_request->RaidContext.raid_context;
2715 rctx_g35 = &io_request->RaidContext.raid_context_g35;
2717 rctx->virtual_disk_tgt_id = cpu_to_le16(device_id);
2719 rctx->ex_status = 0;
2723 fp_possible = false;
2726 * 6-byte READ(0x08) or WRITE(0x0A) cdb
2728 if (scp->cmd_len == 6) {
2729 datalength = (u32) scp->cmnd[4];
2730 start_lba_lo = ((u32) scp->cmnd[1] << 16) |
2731 ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3];
2733 start_lba_lo &= 0x1FFFFF;
2737 * 10-byte READ(0x28) or WRITE(0x2A) cdb
2739 else if (scp->cmd_len == 10) {
2740 datalength = (u32) scp->cmnd[8] |
2741 ((u32) scp->cmnd[7] << 8);
2742 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
2743 ((u32) scp->cmnd[3] << 16) |
2744 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2748 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
2750 else if (scp->cmd_len == 12) {
2751 datalength = ((u32) scp->cmnd[6] << 24) |
2752 ((u32) scp->cmnd[7] << 16) |
2753 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
2754 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
2755 ((u32) scp->cmnd[3] << 16) |
2756 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2760 * 16-byte READ(0x88) or WRITE(0x8A) cdb
2762 else if (scp->cmd_len == 16) {
2763 datalength = ((u32) scp->cmnd[10] << 24) |
2764 ((u32) scp->cmnd[11] << 16) |
2765 ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13];
2766 start_lba_lo = ((u32) scp->cmnd[6] << 24) |
2767 ((u32) scp->cmnd[7] << 16) |
2768 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
2770 start_lba_hi = ((u32) scp->cmnd[2] << 24) |
2771 ((u32) scp->cmnd[3] << 16) |
2772 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2775 memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO));
2776 io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
2777 io_info.numBlocks = datalength;
2778 io_info.ldTgtId = device_id;
2779 io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2780 scsi_buff_len = scsi_bufflen(scp);
2781 io_request->DataLength = cpu_to_le32(scsi_buff_len);
2782 io_info.data_arms = 1;
2784 if (scp->sc_data_direction == DMA_FROM_DEVICE)
2787 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2788 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
2790 if (ld < instance->fw_supported_vd_count)
2791 raid = MR_LdRaidGet(ld, local_map_ptr);
2793 if (!raid || (!fusion->fast_path_io)) {
2794 rctx->reg_lock_flags = 0;
2795 fp_possible = false;
2797 if (MR_BuildRaidContext(instance, &io_info, rctx,
2798 local_map_ptr, &raidLUN))
2799 fp_possible = (io_info.fpOkForIo > 0) ? true : false;
2802 megasas_get_msix_index(instance, scp, cmd, io_info.data_arms);
2804 if (instance->adapter_type >= VENTURA_SERIES) {
2805 /* FP for Optimal raid level 1.
2806 * All large RAID-1 writes (> 32 KiB, both WT and WB modes)
2807 * are built by the driver as LD I/Os.
2808 * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os
2809 * (there is never a reason to process these as buffered writes)
2810 * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os
2811 * with the SLD bit asserted.
2813 if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
2814 mrdev_priv = scp->device->hostdata;
2816 if (atomic_inc_return(&instance->fw_outstanding) >
2817 (instance->host->can_queue)) {
2818 fp_possible = false;
2819 atomic_dec(&instance->fw_outstanding);
2820 } else if (fusion->pcie_bw_limitation &&
2821 ((scsi_buff_len > MR_LARGE_IO_MIN_SIZE) ||
2822 (atomic_dec_if_positive(&mrdev_priv->r1_ldio_hint) > 0))) {
2823 fp_possible = false;
2824 atomic_dec(&instance->fw_outstanding);
2825 if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
2826 atomic_set(&mrdev_priv->r1_ldio_hint,
2827 instance->r1_ldio_hint_default);
2832 (io_info.isRead && io_info.ra_capable)) {
2833 spin_lock_irqsave(&instance->stream_lock,
2835 megasas_stream_detect(instance, cmd, &io_info);
2836 spin_unlock_irqrestore(&instance->stream_lock,
2838 /* In ventura if stream detected for a read and it is
2839 * read ahead capable make this IO as LDIO
2841 if (is_stream_detected(rctx_g35))
2842 fp_possible = false;
2845 /* If raid is NULL, set CPU affinity to default CPU0 */
2847 megasas_set_raidflag_cpu_affinity(fusion, &io_request->RaidContext,
2848 raid, fp_possible, io_info.isRead,
2851 rctx_g35->routing_flags |=
2852 (MR_RAID_CTX_CPUSEL_0 << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2856 megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
2857 local_map_ptr, start_lba_lo);
2858 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2859 cmd->request_desc->SCSIIO.RequestFlags =
2860 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
2861 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2862 if (instance->adapter_type == INVADER_SERIES) {
2863 rctx->type = MPI2_TYPE_CUDA;
2865 io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
2866 rctx->reg_lock_flags |=
2867 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
2868 MR_RL_FLAGS_SEQ_NUM_ENABLE);
2869 } else if (instance->adapter_type >= VENTURA_SERIES) {
2870 rctx_g35->nseg_type |= (1 << RAID_CONTEXT_NSEG_SHIFT);
2871 rctx_g35->nseg_type |= (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2872 rctx_g35->routing_flags |= (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2873 io_request->IoFlags |=
2874 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
2876 if (fusion->load_balance_info &&
2877 (fusion->load_balance_info[device_id].loadBalanceFlag) &&
2880 get_updated_dev_handle(instance,
2881 &fusion->load_balance_info[device_id],
2882 &io_info, local_map_ptr);
2883 scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
2884 cmd->pd_r1_lb = io_info.pd_after_lb;
2885 if (instance->adapter_type >= VENTURA_SERIES)
2886 rctx_g35->span_arm = io_info.span_arm;
2888 rctx->span_arm = io_info.span_arm;
2891 scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
2893 if (instance->adapter_type >= VENTURA_SERIES)
2894 cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle;
2896 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2898 if ((raidLUN[0] == 1) &&
2899 (local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) {
2900 instance->dev_handle = !(instance->dev_handle);
2902 local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].devHandle[instance->dev_handle];
2905 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
2906 io_request->DevHandle = io_info.devHandle;
2907 cmd->pd_interface = io_info.pd_interface;
2908 /* populate the LUN field */
2909 memcpy(io_request->LUN, raidLUN, 8);
2911 rctx->timeout_value =
2912 cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec);
2913 cmd->request_desc->SCSIIO.RequestFlags =
2914 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
2915 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2916 if (instance->adapter_type == INVADER_SERIES) {
2917 if (io_info.do_fp_rlbypass ||
2918 (rctx->reg_lock_flags == REGION_TYPE_UNUSED))
2919 cmd->request_desc->SCSIIO.RequestFlags =
2920 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
2921 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2922 rctx->type = MPI2_TYPE_CUDA;
2923 rctx->reg_lock_flags |=
2924 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
2925 MR_RL_FLAGS_SEQ_NUM_ENABLE);
2927 } else if (instance->adapter_type >= VENTURA_SERIES) {
2928 rctx_g35->routing_flags |= (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2929 rctx_g35->nseg_type |= (1 << RAID_CONTEXT_NSEG_SHIFT);
2930 rctx_g35->nseg_type |= (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2932 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
2933 io_request->DevHandle = cpu_to_le16(device_id);
2939 * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk
2940 * @instance: Adapter soft state
2941 * @scmd: SCSI command
2942 * @cmd: Command to be prepared
2944 * Prepares the io_request frame for non-rw io cmds for vd.
2946 static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
2947 struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd)
2950 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
2952 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
2953 struct fusion_context *fusion = instance->ctrl_context;
2957 struct MR_LD_RAID *raid;
2958 struct RAID_CONTEXT *pRAID_Context;
2961 io_request = cmd->io_request;
2962 device_id = MEGASAS_DEV_INDEX(scmd);
2963 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2964 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2965 /* get RAID_Context pointer */
2966 pRAID_Context = &io_request->RaidContext.raid_context;
2967 /* Check with FW team */
2968 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2969 pRAID_Context->reg_lock_row_lba = 0;
2970 pRAID_Context->reg_lock_length = 0;
2972 if (fusion->fast_path_io && (
2973 device_id < instance->fw_supported_vd_count)) {
2975 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
2976 if (ld >= instance->fw_supported_vd_count - 1)
2979 raid = MR_LdRaidGet(ld, local_map_ptr);
2980 if (!(raid->capability.fpNonRWCapable))
2987 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
2988 io_request->DevHandle = cpu_to_le16(device_id);
2989 io_request->LUN[1] = scmd->device->lun;
2990 pRAID_Context->timeout_value =
2991 cpu_to_le16 (scmd->request->timeout / HZ);
2992 cmd->request_desc->SCSIIO.RequestFlags =
2993 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
2994 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2997 /* set RAID context values */
2998 pRAID_Context->config_seq_num = raid->seqNum;
2999 if (instance->adapter_type < VENTURA_SERIES)
3000 pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ;
3001 pRAID_Context->timeout_value =
3002 cpu_to_le16(raid->fpIoTimeoutForLd);
3004 /* get the DevHandle for the PD (since this is
3005 fpNonRWCapable, this is a single disk RAID0) */
3007 arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr);
3008 pd = MR_ArPdGet(arRef, physArm, local_map_ptr);
3009 devHandle = MR_PdDevHandleGet(pd, local_map_ptr);
3011 /* build request descriptor */
3012 cmd->request_desc->SCSIIO.RequestFlags =
3013 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO <<
3014 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3015 cmd->request_desc->SCSIIO.DevHandle = devHandle;
3017 /* populate the LUN field */
3018 memcpy(io_request->LUN, raid->LUN, 8);
3020 /* build the raidScsiIO structure */
3021 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3022 io_request->DevHandle = devHandle;
3027 * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd
3028 * @instance: Adapter soft state
3029 * @scmd: SCSI command
3030 * @cmd: Command to be prepared
3031 * @fp_possible: parameter to detect fast path or firmware path io.
3033 * Prepares the io_request frame for rw/non-rw io cmds for syspds
3036 megasas_build_syspd_fusion(struct megasas_instance *instance,
3037 struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd,
3041 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
3043 u16 os_timeout_value;
3045 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
3046 struct RAID_CONTEXT *pRAID_Context;
3047 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
3048 struct MR_PRIV_DEVICE *mr_device_priv_data;
3049 struct fusion_context *fusion = instance->ctrl_context;
3050 pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id - 1) & 1];
3052 device_id = MEGASAS_DEV_INDEX(scmd);
3053 pd_index = MEGASAS_PD_INDEX(scmd);
3054 os_timeout_value = scmd->request->timeout / HZ;
3055 mr_device_priv_data = scmd->device->hostdata;
3056 cmd->pd_interface = mr_device_priv_data->interface_type;
3058 io_request = cmd->io_request;
3059 /* get RAID_Context pointer */
3060 pRAID_Context = &io_request->RaidContext.raid_context;
3061 pRAID_Context->reg_lock_flags = 0;
3062 pRAID_Context->reg_lock_row_lba = 0;
3063 pRAID_Context->reg_lock_length = 0;
3064 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
3065 io_request->LUN[1] = scmd->device->lun;
3066 pRAID_Context->raid_flags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
3067 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
3069 /* If FW supports PD sequence number */
3070 if (instance->support_seqnum_jbod_fp) {
3071 if (instance->use_seqnum_jbod_fp &&
3072 instance->pd_list[pd_index].driveType == TYPE_DISK) {
3074 /* More than 256 PD/JBOD support for Ventura */
3075 if (instance->support_morethan256jbod)
3076 pRAID_Context->virtual_disk_tgt_id =
3077 pd_sync->seq[pd_index].pd_target_id;
3079 pRAID_Context->virtual_disk_tgt_id =
3080 cpu_to_le16(device_id +
3081 (MAX_PHYSICAL_DEVICES - 1));
3082 pRAID_Context->config_seq_num =
3083 pd_sync->seq[pd_index].seqNum;
3084 io_request->DevHandle =
3085 pd_sync->seq[pd_index].devHandle;
3086 if (instance->adapter_type >= VENTURA_SERIES) {
3087 io_request->RaidContext.raid_context_g35.routing_flags |=
3088 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
3089 io_request->RaidContext.raid_context_g35.nseg_type |=
3090 (1 << RAID_CONTEXT_NSEG_SHIFT);
3091 io_request->RaidContext.raid_context_g35.nseg_type |=
3092 (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
3094 pRAID_Context->type = MPI2_TYPE_CUDA;
3095 pRAID_Context->nseg = 0x1;
3096 pRAID_Context->reg_lock_flags |=
3097 (MR_RL_FLAGS_SEQ_NUM_ENABLE |
3098 MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
3101 pRAID_Context->virtual_disk_tgt_id =
3102 cpu_to_le16(device_id +
3103 (MAX_PHYSICAL_DEVICES - 1));
3104 pRAID_Context->config_seq_num = 0;
3105 io_request->DevHandle = cpu_to_le16(0xFFFF);
3108 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
3109 pRAID_Context->config_seq_num = 0;
3111 if (fusion->fast_path_io) {
3113 fusion->ld_drv_map[(instance->map_id & 1)];
3114 io_request->DevHandle =
3115 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
3117 io_request->DevHandle = cpu_to_le16(0xFFFF);
3121 cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle;
3123 megasas_get_msix_index(instance, scmd, cmd, 1);
3126 /* system pd firmware path */
3127 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
3128 cmd->request_desc->SCSIIO.RequestFlags =
3129 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
3130 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3131 pRAID_Context->timeout_value = cpu_to_le16(os_timeout_value);
3132 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
3134 if (os_timeout_value)
3137 /* system pd Fast Path */
3138 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
3139 timeout_limit = (scmd->device->type == TYPE_DISK) ?
3141 pRAID_Context->timeout_value =
3142 cpu_to_le16((os_timeout_value > timeout_limit) ?
3143 timeout_limit : os_timeout_value);
3144 if (instance->adapter_type >= INVADER_SERIES)
3145 io_request->IoFlags |=
3146 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
3148 cmd->request_desc->SCSIIO.RequestFlags =
3149 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO <<
3150 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3155 * megasas_build_io_fusion - Prepares IOs to devices
3156 * @instance: Adapter soft state
3157 * @scp: SCSI command
3158 * @cmd: Command to be prepared
3160 * Invokes helper functions to prepare request frames
3161 * and sets flags appropriate for IO/Non-IO cmd
3164 megasas_build_io_fusion(struct megasas_instance *instance,
3165 struct scsi_cmnd *scp,
3166 struct megasas_cmd_fusion *cmd)
3170 struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
3171 struct MR_PRIV_DEVICE *mr_device_priv_data;
3172 mr_device_priv_data = scp->device->hostdata;
3174 /* Zero out some fields so they don't get reused */
3175 memset(io_request->LUN, 0x0, 8);
3176 io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
3177 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
3178 io_request->EEDPFlags = 0;
3179 io_request->Control = 0;
3180 io_request->EEDPBlockSize = 0;
3181 io_request->ChainOffset = 0;
3182 io_request->RaidContext.raid_context.raid_flags = 0;
3183 io_request->RaidContext.raid_context.type = 0;
3184 io_request->RaidContext.raid_context.nseg = 0;
3186 memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
3188 * Just the CDB length,rest of the Flags are zero
3189 * This will be modified for FP in build_ldio_fusion
3191 io_request->IoFlags = cpu_to_le16(scp->cmd_len);
3193 switch (cmd_type = megasas_cmd_type(scp)) {
3194 case READ_WRITE_LDIO:
3195 megasas_build_ldio_fusion(instance, scp, cmd);
3197 case NON_READ_WRITE_LDIO:
3198 megasas_build_ld_nonrw_fusion(instance, scp, cmd);
3200 case READ_WRITE_SYSPDIO:
3201 megasas_build_syspd_fusion(instance, scp, cmd, true);
3203 case NON_READ_WRITE_SYSPDIO:
3204 if (instance->secure_jbod_support ||
3205 mr_device_priv_data->is_tm_capable)
3206 megasas_build_syspd_fusion(instance, scp, cmd, false);
3208 megasas_build_syspd_fusion(instance, scp, cmd, true);
3218 sge_count = megasas_make_sgl(instance, scp, cmd);
3220 if (sge_count > instance->max_num_sge || (sge_count < 0)) {
3221 dev_err(&instance->pdev->dev,
3222 "%s %d sge_count (%d) is out of range. Range is: 0-%d\n",
3223 __func__, __LINE__, sge_count, instance->max_num_sge);
3227 if (instance->adapter_type >= VENTURA_SERIES) {
3228 set_num_sge(&io_request->RaidContext.raid_context_g35, sge_count);
3229 cpu_to_le16s(&io_request->RaidContext.raid_context_g35.routing_flags);
3230 cpu_to_le16s(&io_request->RaidContext.raid_context_g35.nseg_type);
3232 /* numSGE store lower 8 bit of sge_count.
3233 * numSGEExt store higher 8 bit of sge_count
3235 io_request->RaidContext.raid_context.num_sge = sge_count;
3236 io_request->RaidContext.raid_context.num_sge_ext =
3237 (u8)(sge_count >> 8);
3240 io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING);
3242 if (scp->sc_data_direction == DMA_TO_DEVICE)
3243 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE);
3244 else if (scp->sc_data_direction == DMA_FROM_DEVICE)
3245 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ);
3247 io_request->SGLOffset0 =
3248 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4;
3250 io_request->SenseBufferLowAddress =
3251 cpu_to_le32(lower_32_bits(cmd->sense_phys_addr));
3252 io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
3255 scp->SCp.ptr = (char *)cmd;
3260 static union MEGASAS_REQUEST_DESCRIPTOR_UNION *
3261 megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
3264 struct fusion_context *fusion;
3266 fusion = instance->ctrl_context;
3267 p = fusion->req_frames_desc +
3268 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * index;
3270 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
3274 /* megasas_prepate_secondRaid1_IO
3275 * It prepares the raid 1 second IO
3277 static void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance,
3278 struct megasas_cmd_fusion *cmd,
3279 struct megasas_cmd_fusion *r1_cmd)
3281 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL;
3282 struct fusion_context *fusion;
3283 fusion = instance->ctrl_context;
3284 req_desc = cmd->request_desc;
3285 /* copy the io request frame as well as 8 SGEs data for r1 command*/
3286 memcpy(r1_cmd->io_request, cmd->io_request,
3287 (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)));
3288 memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
3289 (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION)));
3290 /*sense buffer is different for r1 command*/
3291 r1_cmd->io_request->SenseBufferLowAddress =
3292 cpu_to_le32(lower_32_bits(r1_cmd->sense_phys_addr));
3293 r1_cmd->scmd = cmd->scmd;
3294 req_desc2 = megasas_get_request_descriptor(instance,
3295 (r1_cmd->index - 1));
3296 req_desc2->Words = 0;
3297 r1_cmd->request_desc = req_desc2;
3298 req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index);
3299 req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags;
3300 r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle;
3301 r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
3302 r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle;
3303 cmd->io_request->RaidContext.raid_context_g35.flow_specific.peer_smid =
3304 cpu_to_le16(r1_cmd->index);
3305 r1_cmd->io_request->RaidContext.raid_context_g35.flow_specific.peer_smid =
3306 cpu_to_le16(cmd->index);
3307 /*MSIxIndex of both commands request descriptors should be same*/
3308 r1_cmd->request_desc->SCSIIO.MSIxIndex =
3309 cmd->request_desc->SCSIIO.MSIxIndex;
3310 /*span arm is different for r1 cmd*/
3311 r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
3312 cmd->io_request->RaidContext.raid_context_g35.span_arm + 1;
3316 * megasas_build_and_issue_cmd_fusion -Main routine for building and
3317 * issuing non IOCTL cmd
3318 * @instance: Adapter soft state
3319 * @scmd: pointer to scsi cmd from OS
3322 megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
3323 struct scsi_cmnd *scmd)
3325 struct megasas_cmd_fusion *cmd, *r1_cmd = NULL;
3326 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3329 if ((megasas_cmd_type(scmd) == READ_WRITE_LDIO) &&
3330 instance->ldio_threshold &&
3331 (atomic_inc_return(&instance->ldio_outstanding) >
3332 instance->ldio_threshold)) {
3333 atomic_dec(&instance->ldio_outstanding);
3334 return SCSI_MLQUEUE_DEVICE_BUSY;
3337 if (atomic_inc_return(&instance->fw_outstanding) >
3338 instance->host->can_queue) {
3339 atomic_dec(&instance->fw_outstanding);
3340 return SCSI_MLQUEUE_HOST_BUSY;
3343 cmd = megasas_get_cmd_fusion(instance, scmd->request->tag);
3346 atomic_dec(&instance->fw_outstanding);
3347 return SCSI_MLQUEUE_HOST_BUSY;
3352 req_desc = megasas_get_request_descriptor(instance, index-1);
3354 req_desc->Words = 0;
3355 cmd->request_desc = req_desc;
3357 if (megasas_build_io_fusion(instance, scmd, cmd)) {
3358 megasas_return_cmd_fusion(instance, cmd);
3359 dev_err(&instance->pdev->dev, "Error building command\n");
3360 cmd->request_desc = NULL;
3361 atomic_dec(&instance->fw_outstanding);
3362 return SCSI_MLQUEUE_HOST_BUSY;
3365 req_desc = cmd->request_desc;
3366 req_desc->SCSIIO.SMID = cpu_to_le16(index);
3368 if (cmd->io_request->ChainOffset != 0 &&
3369 cmd->io_request->ChainOffset != 0xF)
3370 dev_err(&instance->pdev->dev, "The chain offset value is not "
3371 "correct : %x\n", cmd->io_request->ChainOffset);
3373 * if it is raid 1/10 fp write capable.
3374 * try to get second command from pool and construct it.
3375 * From FW, it has confirmed that lba values of two PDs
3376 * corresponds to single R1/10 LD are always same
3379 /* driver side count always should be less than max_fw_cmds
3380 * to get new command
3382 if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
3383 r1_cmd = megasas_get_cmd_fusion(instance,
3384 (scmd->request->tag + instance->max_fw_cmds));
3385 megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
3390 * Issue the command to the FW
3393 megasas_fire_cmd_fusion(instance, req_desc);
3396 megasas_fire_cmd_fusion(instance, r1_cmd->request_desc);
3403 * megasas_complete_r1_command -
3404 * completes R1 FP write commands which has valid peer smid
3405 * @instance: Adapter soft state
3406 * @cmd: MPT command frame
3410 megasas_complete_r1_command(struct megasas_instance *instance,
3411 struct megasas_cmd_fusion *cmd)
3413 u8 *sense, status, ex_status;
3416 struct fusion_context *fusion;
3417 struct megasas_cmd_fusion *r1_cmd = NULL;
3418 struct scsi_cmnd *scmd_local = NULL;
3419 struct RAID_CONTEXT_G35 *rctx_g35;
3421 rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
3422 fusion = instance->ctrl_context;
3423 peer_smid = le16_to_cpu(rctx_g35->flow_specific.peer_smid);
3425 r1_cmd = fusion->cmd_list[peer_smid - 1];
3426 scmd_local = cmd->scmd;
3427 status = rctx_g35->status;
3428 ex_status = rctx_g35->ex_status;
3429 data_length = cmd->io_request->DataLength;
3432 cmd->cmd_completed = true;
3434 /* Check if peer command is completed or not*/
3435 if (r1_cmd->cmd_completed) {
3436 rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35;
3437 if (rctx_g35->status != MFI_STAT_OK) {
3438 status = rctx_g35->status;
3439 ex_status = rctx_g35->ex_status;
3440 data_length = r1_cmd->io_request->DataLength;
3441 sense = r1_cmd->sense;
3444 megasas_return_cmd_fusion(instance, r1_cmd);
3445 map_cmd_status(fusion, scmd_local, status, ex_status,
3446 le32_to_cpu(data_length), sense);
3447 if (instance->ldio_threshold &&
3448 megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
3449 atomic_dec(&instance->ldio_outstanding);
3450 scmd_local->SCp.ptr = NULL;
3451 megasas_return_cmd_fusion(instance, cmd);
3452 scsi_dma_unmap(scmd_local);
3453 scmd_local->scsi_done(scmd_local);
3458 * complete_cmd_fusion - Completes command
3459 * @instance: Adapter soft state
3460 * @MSIxIndex: MSI number
3461 * @irq_context: IRQ context
3463 * Completes all commands that is in reply descriptor queue
3466 complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex,
3467 struct megasas_irq_context *irq_context)
3469 union MPI2_REPLY_DESCRIPTORS_UNION *desc;
3470 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
3471 struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
3472 struct fusion_context *fusion;
3473 struct megasas_cmd *cmd_mfi;
3474 struct megasas_cmd_fusion *cmd_fusion;
3475 u16 smid, num_completed;
3476 u8 reply_descript_type, *sense, status, extStatus;
3477 u32 device_id, data_length;
3478 union desc_value d_val;
3479 struct LD_LOAD_BALANCE_INFO *lbinfo;
3480 int threshold_reply_count = 0;
3481 struct scsi_cmnd *scmd_local = NULL;
3482 struct MR_TASK_MANAGE_REQUEST *mr_tm_req;
3483 struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_tm_req;
3485 fusion = instance->ctrl_context;
3487 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)
3490 desc = fusion->reply_frames_desc[MSIxIndex] +
3491 fusion->last_reply_idx[MSIxIndex];
3493 reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
3495 d_val.word = desc->Words;
3497 reply_descript_type = reply_desc->ReplyFlags &
3498 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
3500 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
3505 while (d_val.u.low != cpu_to_le32(UINT_MAX) &&
3506 d_val.u.high != cpu_to_le32(UINT_MAX)) {
3508 smid = le16_to_cpu(reply_desc->SMID);
3509 cmd_fusion = fusion->cmd_list[smid - 1];
3510 scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *)
3511 cmd_fusion->io_request;
3513 scmd_local = cmd_fusion->scmd;
3514 status = scsi_io_req->RaidContext.raid_context.status;
3515 extStatus = scsi_io_req->RaidContext.raid_context.ex_status;
3516 sense = cmd_fusion->sense;
3517 data_length = scsi_io_req->DataLength;
3519 switch (scsi_io_req->Function) {
3520 case MPI2_FUNCTION_SCSI_TASK_MGMT:
3521 mr_tm_req = (struct MR_TASK_MANAGE_REQUEST *)
3522 cmd_fusion->io_request;
3523 mpi_tm_req = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *)
3524 &mr_tm_req->TmRequest;
3525 dev_dbg(&instance->pdev->dev, "TM completion:"
3526 "type: 0x%x TaskMID: 0x%x\n",
3527 mpi_tm_req->TaskType, mpi_tm_req->TaskMID);
3528 complete(&cmd_fusion->done);
3530 case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/
3531 /* Update load balancing info */
3532 if (fusion->load_balance_info &&
3533 (cmd_fusion->scmd->SCp.Status &
3534 MEGASAS_LOAD_BALANCE_FLAG)) {
3535 device_id = MEGASAS_DEV_INDEX(scmd_local);
3536 lbinfo = &fusion->load_balance_info[device_id];
3537 atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]);
3538 cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
3540 fallthrough; /* and complete IO */
3541 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
3542 atomic_dec(&instance->fw_outstanding);
3543 if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) {
3544 map_cmd_status(fusion, scmd_local, status,
3545 extStatus, le32_to_cpu(data_length),
3547 if (instance->ldio_threshold &&
3548 (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO))
3549 atomic_dec(&instance->ldio_outstanding);
3550 scmd_local->SCp.ptr = NULL;
3551 megasas_return_cmd_fusion(instance, cmd_fusion);
3552 scsi_dma_unmap(scmd_local);
3553 scmd_local->scsi_done(scmd_local);
3554 } else /* Optimal VD - R1 FP command completion. */
3555 megasas_complete_r1_command(instance, cmd_fusion);
3557 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
3558 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
3559 /* Poll mode. Dummy free.
3560 * In case of Interrupt mode, caller has reverse check.
3562 if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) {
3563 cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE;
3564 megasas_return_cmd(instance, cmd_mfi);
3566 megasas_complete_cmd(instance, cmd_mfi, DID_OK);
3570 fusion->last_reply_idx[MSIxIndex]++;
3571 if (fusion->last_reply_idx[MSIxIndex] >=
3572 fusion->reply_q_depth)
3573 fusion->last_reply_idx[MSIxIndex] = 0;
3575 desc->Words = cpu_to_le64(ULLONG_MAX);
3577 threshold_reply_count++;
3579 /* Get the next reply descriptor */
3580 if (!fusion->last_reply_idx[MSIxIndex])
3581 desc = fusion->reply_frames_desc[MSIxIndex];
3586 (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
3588 d_val.word = desc->Words;
3590 reply_descript_type = reply_desc->ReplyFlags &
3591 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
3593 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
3596 * Write to reply post host index register after completing threshold
3597 * number of reply counts and still there are more replies in reply queue
3598 * pending to be completed
3600 if (threshold_reply_count >= instance->threshold_reply_count) {
3601 if (instance->msix_combined)
3602 writel(((MSIxIndex & 0x7) << 24) |
3603 fusion->last_reply_idx[MSIxIndex],
3604 instance->reply_post_host_index_addr[MSIxIndex/8]);
3606 writel((MSIxIndex << 24) |
3607 fusion->last_reply_idx[MSIxIndex],
3608 instance->reply_post_host_index_addr[0]);
3609 threshold_reply_count = 0;
3611 if (!irq_context->irq_poll_scheduled) {
3612 irq_context->irq_poll_scheduled = true;
3613 irq_context->irq_line_enable = true;
3614 irq_poll_sched(&irq_context->irqpoll);
3616 return num_completed;
3621 if (num_completed) {
3623 if (instance->msix_combined)
3624 writel(((MSIxIndex & 0x7) << 24) |
3625 fusion->last_reply_idx[MSIxIndex],
3626 instance->reply_post_host_index_addr[MSIxIndex/8]);
3628 writel((MSIxIndex << 24) |
3629 fusion->last_reply_idx[MSIxIndex],
3630 instance->reply_post_host_index_addr[0]);
3631 megasas_check_and_restore_queue_depth(instance);
3633 return num_completed;
3637 * megasas_enable_irq_poll() - enable irqpoll
3638 * @instance: Adapter soft state
3640 static void megasas_enable_irq_poll(struct megasas_instance *instance)
3643 struct megasas_irq_context *irq_ctx;
3645 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3647 for (i = 0; i < count; i++) {
3648 irq_ctx = &instance->irq_context[i];
3649 irq_poll_enable(&irq_ctx->irqpoll);
3654 * megasas_sync_irqs - Synchronizes all IRQs owned by adapter
3655 * @instance_addr: Adapter soft state address
3657 static void megasas_sync_irqs(unsigned long instance_addr)
3660 struct megasas_instance *instance =
3661 (struct megasas_instance *)instance_addr;
3662 struct megasas_irq_context *irq_ctx;
3664 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3666 for (i = 0; i < count; i++) {
3667 synchronize_irq(pci_irq_vector(instance->pdev, i));
3668 irq_ctx = &instance->irq_context[i];
3669 irq_poll_disable(&irq_ctx->irqpoll);
3670 if (irq_ctx->irq_poll_scheduled) {
3671 irq_ctx->irq_poll_scheduled = false;
3672 enable_irq(irq_ctx->os_irq);
3678 * megasas_irqpoll() - process a queue for completed reply descriptors
3679 * @irqpoll: IRQ poll structure associated with queue to poll.
3680 * @budget: Threshold of reply descriptors to process per poll.
3682 * Return: The number of entries processed.
3685 int megasas_irqpoll(struct irq_poll *irqpoll, int budget)
3687 struct megasas_irq_context *irq_ctx;
3688 struct megasas_instance *instance;
3691 irq_ctx = container_of(irqpoll, struct megasas_irq_context, irqpoll);
3692 instance = irq_ctx->instance;
3694 if (irq_ctx->irq_line_enable) {
3695 disable_irq_nosync(irq_ctx->os_irq);
3696 irq_ctx->irq_line_enable = false;
3699 num_entries = complete_cmd_fusion(instance, irq_ctx->MSIxIndex, irq_ctx);
3700 if (num_entries < budget) {
3701 irq_poll_complete(irqpoll);
3702 irq_ctx->irq_poll_scheduled = false;
3703 enable_irq(irq_ctx->os_irq);
3710 * megasas_complete_cmd_dpc_fusion - Completes command
3711 * @instance_addr: Adapter soft state address
3713 * Tasklet to complete cmds
3716 megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
3718 struct megasas_instance *instance =
3719 (struct megasas_instance *)instance_addr;
3720 u32 count, MSIxIndex;
3722 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3724 /* If we have already declared adapter dead, donot complete cmds */
3725 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)
3728 for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++)
3729 complete_cmd_fusion(instance, MSIxIndex, NULL);
3733 * megasas_isr_fusion - isr entry point
3735 * @devp: IRQ context
3737 static irqreturn_t megasas_isr_fusion(int irq, void *devp)
3739 struct megasas_irq_context *irq_context = devp;
3740 struct megasas_instance *instance = irq_context->instance;
3743 if (instance->mask_interrupts)
3746 if (irq_context->irq_poll_scheduled)
3749 if (!instance->msix_vectors) {
3750 mfiStatus = instance->instancet->clear_intr(instance);
3755 /* If we are resetting, bail */
3756 if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) {
3757 instance->instancet->clear_intr(instance);
3761 return complete_cmd_fusion(instance, irq_context->MSIxIndex, irq_context)
3762 ? IRQ_HANDLED : IRQ_NONE;
3766 * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
3767 * @instance: Adapter soft state
3768 * @mfi_cmd: megasas_cmd pointer
3772 build_mpt_mfi_pass_thru(struct megasas_instance *instance,
3773 struct megasas_cmd *mfi_cmd)
3775 struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain;
3776 struct MPI2_RAID_SCSI_IO_REQUEST *io_req;
3777 struct megasas_cmd_fusion *cmd;
3778 struct fusion_context *fusion;
3779 struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr;
3781 fusion = instance->ctrl_context;
3783 cmd = megasas_get_cmd_fusion(instance,
3784 instance->max_scsi_cmds + mfi_cmd->index);
3786 /* Save the smid. To be used for returning the cmd */
3787 mfi_cmd->context.smid = cmd->index;
3790 * For cmds where the flag is set, store the flag and check
3791 * on completion. For cmds with this flag, don't call
3792 * megasas_complete_cmd
3795 if (frame_hdr->flags & cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE))
3796 mfi_cmd->flags |= DRV_DCMD_POLLED_MODE;
3798 io_req = cmd->io_request;
3800 if (instance->adapter_type >= INVADER_SERIES) {
3801 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
3802 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
3803 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
3804 sgl_ptr_end->Flags = 0;
3808 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
3810 io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST;
3811 io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST,
3813 io_req->ChainOffset = fusion->chain_offset_mfi_pthru;
3815 mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr);
3817 mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
3818 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
3820 mpi25_ieee_chain->Length = cpu_to_le32(instance->mfi_frame_size);
3824 * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
3825 * @instance: Adapter soft state
3826 * @cmd: mfi cmd to build
3829 static union MEGASAS_REQUEST_DESCRIPTOR_UNION *
3830 build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
3832 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL;
3835 build_mpt_mfi_pass_thru(instance, cmd);
3836 index = cmd->context.smid;
3838 req_desc = megasas_get_request_descriptor(instance, index - 1);
3840 req_desc->Words = 0;
3841 req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
3842 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3844 req_desc->SCSIIO.SMID = cpu_to_le16(index);
3850 * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
3851 * @instance: Adapter soft state
3852 * @cmd: mfi cmd pointer
3856 megasas_issue_dcmd_fusion(struct megasas_instance *instance,
3857 struct megasas_cmd *cmd)
3859 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3861 req_desc = build_mpt_cmd(instance, cmd);
3863 megasas_fire_cmd_fusion(instance, req_desc);
3868 * megasas_release_fusion - Reverses the FW initialization
3869 * @instance: Adapter soft state
3872 megasas_release_fusion(struct megasas_instance *instance)
3874 megasas_free_ioc_init_cmd(instance);
3875 megasas_free_cmds(instance);
3876 megasas_free_cmds_fusion(instance);
3878 iounmap(instance->reg_set);
3880 pci_release_selected_regions(instance->pdev, 1<<instance->bar);
3884 * megasas_read_fw_status_reg_fusion - returns the current FW status value
3885 * @instance: Adapter soft state
3888 megasas_read_fw_status_reg_fusion(struct megasas_instance *instance)
3890 return megasas_readl(instance, &instance->reg_set->outbound_scratch_pad_0);
3894 * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3895 * @instance: Controller's soft instance
3896 * @return: Number of allocated host crash buffers
3899 megasas_alloc_host_crash_buffer(struct megasas_instance *instance)
3903 for (i = 0; i < MAX_CRASH_DUMP_SIZE; i++) {
3904 instance->crash_buf[i] = vzalloc(CRASH_DMA_BUF_SIZE);
3905 if (!instance->crash_buf[i]) {
3906 dev_info(&instance->pdev->dev, "Firmware crash dump "
3907 "memory allocation failed at index %d\n", i);
3911 instance->drv_buf_alloc = i;
3915 * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3916 * @instance: Controller's soft instance
3919 megasas_free_host_crash_buffer(struct megasas_instance *instance)
3922 for (i = 0; i < instance->drv_buf_alloc; i++) {
3923 if (instance->crash_buf[i])
3924 vfree(instance->crash_buf[i]);
3926 instance->drv_buf_index = 0;
3927 instance->drv_buf_alloc = 0;
3928 instance->fw_crash_state = UNAVAILABLE;
3929 instance->fw_crash_buffer_size = 0;
3933 * megasas_adp_reset_fusion - For controller reset
3934 * @instance: Controller's soft instance
3935 * @regs: MFI register set
3938 megasas_adp_reset_fusion(struct megasas_instance *instance,
3939 struct megasas_register_set __iomem *regs)
3941 u32 host_diag, abs_state, retry;
3943 /* Now try to reset the chip */
3944 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3945 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3946 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3947 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3948 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3949 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3950 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3952 /* Check that the diag write enable (DRWE) bit is on */
3953 host_diag = megasas_readl(instance, &instance->reg_set->fusion_host_diag);
3955 while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) {
3957 host_diag = megasas_readl(instance,
3958 &instance->reg_set->fusion_host_diag);
3959 if (retry++ == 100) {
3960 dev_warn(&instance->pdev->dev,
3961 "Host diag unlock failed from %s %d\n",
3962 __func__, __LINE__);
3966 if (!(host_diag & HOST_DIAG_WRITE_ENABLE))
3969 /* Send chip reset command */
3970 writel(host_diag | HOST_DIAG_RESET_ADAPTER,
3971 &instance->reg_set->fusion_host_diag);
3974 /* Make sure reset adapter bit is cleared */
3975 host_diag = megasas_readl(instance, &instance->reg_set->fusion_host_diag);
3977 while (host_diag & HOST_DIAG_RESET_ADAPTER) {
3979 host_diag = megasas_readl(instance,
3980 &instance->reg_set->fusion_host_diag);
3981 if (retry++ == 1000) {
3982 dev_warn(&instance->pdev->dev,
3983 "Diag reset adapter never cleared %s %d\n",
3984 __func__, __LINE__);
3988 if (host_diag & HOST_DIAG_RESET_ADAPTER)
3991 abs_state = instance->instancet->read_fw_status_reg(instance)
3995 while ((abs_state <= MFI_STATE_FW_INIT) && (retry++ < 1000)) {
3997 abs_state = instance->instancet->
3998 read_fw_status_reg(instance) & MFI_STATE_MASK;
4000 if (abs_state <= MFI_STATE_FW_INIT) {
4001 dev_warn(&instance->pdev->dev,
4002 "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n",
4003 abs_state, __func__, __LINE__);
4011 * megasas_check_reset_fusion - For controller reset check
4012 * @instance: Controller's soft instance
4013 * @regs: MFI register set
4016 megasas_check_reset_fusion(struct megasas_instance *instance,
4017 struct megasas_register_set __iomem *regs)
4023 * megasas_trigger_snap_dump - Trigger snap dump in FW
4024 * @instance: Soft instance of adapter
4026 static inline void megasas_trigger_snap_dump(struct megasas_instance *instance)
4029 u32 fw_state, abs_state;
4031 if (!instance->disableOnlineCtrlReset) {
4032 dev_info(&instance->pdev->dev, "Trigger snap dump\n");
4033 writel(MFI_ADP_TRIGGER_SNAP_DUMP,
4034 &instance->reg_set->doorbell);
4035 readl(&instance->reg_set->doorbell);
4038 for (j = 0; j < instance->snapdump_wait_time; j++) {
4039 abs_state = instance->instancet->read_fw_status_reg(instance);
4040 fw_state = abs_state & MFI_STATE_MASK;
4041 if (fw_state == MFI_STATE_FAULT) {
4042 dev_printk(KERN_ERR, &instance->pdev->dev,
4043 "FW in FAULT state Fault code:0x%x subcode:0x%x func:%s\n",
4044 abs_state & MFI_STATE_FAULT_CODE,
4045 abs_state & MFI_STATE_FAULT_SUBCODE, __func__);
4052 /* This function waits for outstanding commands on fusion to complete */
4054 megasas_wait_for_outstanding_fusion(struct megasas_instance *instance,
4055 int reason, int *convert)
4057 int i, outstanding, retval = 0, hb_seconds_missed = 0;
4058 u32 fw_state, abs_state;
4059 u32 waittime_for_io_completion;
4061 waittime_for_io_completion =
4062 min_t(u32, resetwaittime,
4063 (resetwaittime - instance->snapdump_wait_time));
4065 if (reason == MFI_IO_TIMEOUT_OCR) {
4066 dev_info(&instance->pdev->dev,
4067 "MFI command is timed out\n");
4068 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
4069 if (instance->snapdump_wait_time)
4070 megasas_trigger_snap_dump(instance);
4075 for (i = 0; i < waittime_for_io_completion; i++) {
4076 /* Check if firmware is in fault state */
4077 abs_state = instance->instancet->read_fw_status_reg(instance);
4078 fw_state = abs_state & MFI_STATE_MASK;
4079 if (fw_state == MFI_STATE_FAULT) {
4080 dev_printk(KERN_ERR, &instance->pdev->dev,
4081 "FW in FAULT state Fault code:0x%x subcode:0x%x func:%s\n",
4082 abs_state & MFI_STATE_FAULT_CODE,
4083 abs_state & MFI_STATE_FAULT_SUBCODE, __func__);
4084 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
4085 if (instance->requestorId && reason) {
4086 dev_warn(&instance->pdev->dev, "SR-IOV Found FW in FAULT"
4087 " state while polling during"
4088 " I/O timeout handling for %d\n",
4089 instance->host->host_no);
4098 /* If SR-IOV VF mode & heartbeat timeout, don't wait */
4099 if (instance->requestorId && !reason) {
4104 /* If SR-IOV VF mode & I/O timeout, check for HB timeout */
4105 if (instance->requestorId && (reason == SCSIIO_TIMEOUT_OCR)) {
4106 if (instance->hb_host_mem->HB.fwCounter !=
4107 instance->hb_host_mem->HB.driverCounter) {
4108 instance->hb_host_mem->HB.driverCounter =
4109 instance->hb_host_mem->HB.fwCounter;
4110 hb_seconds_missed = 0;
4112 hb_seconds_missed++;
4113 if (hb_seconds_missed ==
4114 (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF/HZ)) {
4115 dev_warn(&instance->pdev->dev, "SR-IOV:"
4116 " Heartbeat never completed "
4117 " while polling during I/O "
4118 " timeout handling for "
4120 instance->host->host_no);
4128 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
4129 outstanding = atomic_read(&instance->fw_outstanding);
4133 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
4134 dev_notice(&instance->pdev->dev, "[%2d]waiting for %d "
4135 "commands to complete for scsi%d\n", i,
4136 outstanding, instance->host->host_no);
4141 if (instance->snapdump_wait_time) {
4142 megasas_trigger_snap_dump(instance);
4147 if (atomic_read(&instance->fw_outstanding)) {
4148 dev_err(&instance->pdev->dev, "pending commands remain after waiting, "
4149 "will reset adapter scsi%d.\n",
4150 instance->host->host_no);
4159 void megasas_reset_reply_desc(struct megasas_instance *instance)
4162 struct fusion_context *fusion;
4163 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
4165 fusion = instance->ctrl_context;
4166 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
4167 for (i = 0 ; i < count ; i++) {
4168 fusion->last_reply_idx[i] = 0;
4169 reply_desc = fusion->reply_frames_desc[i];
4170 for (j = 0 ; j < fusion->reply_q_depth; j++, reply_desc++)
4171 reply_desc->Words = cpu_to_le64(ULLONG_MAX);
4176 * megasas_refire_mgmt_cmd : Re-fire management commands
4177 * @instance: Controller's soft instance
4179 static void megasas_refire_mgmt_cmd(struct megasas_instance *instance,
4183 struct megasas_cmd_fusion *cmd_fusion;
4184 struct fusion_context *fusion;
4185 struct megasas_cmd *cmd_mfi;
4186 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
4187 struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
4189 bool refire_cmd = false;
4193 fusion = instance->ctrl_context;
4195 /* Re-fire management commands.
4196 * Do not traverse complet MPT frame pool. Start from max_scsi_cmds.
4198 for (j = instance->max_scsi_cmds ; j < instance->max_fw_cmds; j++) {
4199 cmd_fusion = fusion->cmd_list[j];
4200 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
4201 smid = le16_to_cpu(cmd_mfi->context.smid);
4202 result = REFIRE_CMD;
4207 req_desc = megasas_get_request_descriptor(instance, smid - 1);
4209 switch (cmd_mfi->frame->hdr.cmd) {
4211 opcode = le32_to_cpu(cmd_mfi->frame->dcmd.opcode);
4212 /* Do not refire shutdown command */
4213 if (opcode == MR_DCMD_CTRL_SHUTDOWN) {
4214 cmd_mfi->frame->dcmd.cmd_status = MFI_STAT_OK;
4215 result = COMPLETE_CMD;
4219 refire_cmd = ((opcode != MR_DCMD_LD_MAP_GET_INFO)) &&
4220 (opcode != MR_DCMD_SYSTEM_PD_MAP_GET_INFO) &&
4221 !(cmd_mfi->flags & DRV_DCMD_SKIP_REFIRE);
4224 result = RETURN_CMD;
4228 if (!instance->support_nvme_passthru) {
4229 cmd_mfi->frame->hdr.cmd_status = MFI_STAT_INVALID_CMD;
4230 result = COMPLETE_CMD;
4234 case MFI_CMD_TOOLBOX:
4235 if (!instance->support_pci_lane_margining) {
4236 cmd_mfi->frame->hdr.cmd_status = MFI_STAT_INVALID_CMD;
4237 result = COMPLETE_CMD;
4245 if (return_ioctl && cmd_mfi->sync_cmd &&
4246 cmd_mfi->frame->hdr.cmd != MFI_CMD_ABORT) {
4247 dev_err(&instance->pdev->dev,
4248 "return -EBUSY from %s %d cmd 0x%x opcode 0x%x\n",
4249 __func__, __LINE__, cmd_mfi->frame->hdr.cmd,
4250 le32_to_cpu(cmd_mfi->frame->dcmd.opcode));
4251 cmd_mfi->cmd_status_drv = DCMD_BUSY;
4252 result = COMPLETE_CMD;
4255 scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *)
4256 cmd_fusion->io_request;
4257 if (scsi_io_req->Function == MPI2_FUNCTION_SCSI_TASK_MGMT)
4258 result = RETURN_CMD;
4262 megasas_fire_cmd_fusion(instance, req_desc);
4265 megasas_return_cmd(instance, cmd_mfi);
4268 megasas_complete_cmd(instance, cmd_mfi, DID_OK);
4275 * megasas_return_polled_cmds: Return polled mode commands back to the pool
4276 * before initiating an OCR.
4277 * @instance: Controller's soft instance
4280 megasas_return_polled_cmds(struct megasas_instance *instance)
4283 struct megasas_cmd_fusion *cmd_fusion;
4284 struct fusion_context *fusion;
4285 struct megasas_cmd *cmd_mfi;
4287 fusion = instance->ctrl_context;
4289 for (i = instance->max_scsi_cmds; i < instance->max_fw_cmds; i++) {
4290 cmd_fusion = fusion->cmd_list[i];
4291 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
4293 if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) {
4294 if (megasas_dbg_lvl & OCR_DEBUG)
4295 dev_info(&instance->pdev->dev,
4296 "%s %d return cmd 0x%x opcode 0x%x\n",
4297 __func__, __LINE__, cmd_mfi->frame->hdr.cmd,
4298 le32_to_cpu(cmd_mfi->frame->dcmd.opcode));
4299 cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE;
4300 megasas_return_cmd(instance, cmd_mfi);
4306 * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device
4307 * @instance: per adapter struct
4308 * @channel: the channel assigned by the OS
4309 * @id: the id assigned by the OS
4311 * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED
4314 static int megasas_track_scsiio(struct megasas_instance *instance,
4315 int id, int channel)
4318 struct megasas_cmd_fusion *cmd_fusion;
4319 struct fusion_context *fusion;
4320 fusion = instance->ctrl_context;
4322 for (i = 0 ; i < instance->max_scsi_cmds; i++) {
4323 cmd_fusion = fusion->cmd_list[i];
4324 if (cmd_fusion->scmd &&
4325 (cmd_fusion->scmd->device->id == id &&
4326 cmd_fusion->scmd->device->channel == channel)) {
4327 dev_info(&instance->pdev->dev,
4328 "SCSI commands pending to target"
4329 "channel %d id %d \tSMID: 0x%x\n",
4330 channel, id, cmd_fusion->index);
4331 scsi_print_command(cmd_fusion->scmd);
4337 return found ? FAILED : SUCCESS;
4341 * megasas_tm_response_code - translation of device response code
4342 * @instance: Controller's soft instance
4343 * @mpi_reply: MPI reply returned by firmware
4348 megasas_tm_response_code(struct megasas_instance *instance,
4349 struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply)
4353 switch (mpi_reply->ResponseCode) {
4354 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
4355 desc = "task management request completed";
4357 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
4358 desc = "invalid frame";
4360 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
4361 desc = "task management request not supported";
4363 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
4364 desc = "task management request failed";
4366 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
4367 desc = "task management request succeeded";
4369 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
4370 desc = "invalid lun";
4373 desc = "overlapped tag attempted";
4375 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
4376 desc = "task queued, however not sent to target";
4382 dev_dbg(&instance->pdev->dev, "response_code(%01x): %s\n",
4383 mpi_reply->ResponseCode, desc);
4384 dev_dbg(&instance->pdev->dev,
4385 "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo"
4386 " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n",
4387 mpi_reply->TerminationCount, mpi_reply->DevHandle,
4388 mpi_reply->Function, mpi_reply->TaskType,
4389 mpi_reply->IOCStatus, mpi_reply->IOCLogInfo);
4393 * megasas_issue_tm - main routine for sending tm requests
4394 * @instance: per adapter struct
4395 * @device_handle: device handle
4396 * @channel: the channel assigned by the OS
4397 * @id: the id assigned by the OS
4398 * @smid_task: smid assigned to the task
4399 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c)
4400 * @mr_device_priv_data: private data
4403 * MegaRaid use MPT interface for Task Magement request.
4404 * A generic API for sending task management requests to firmware.
4406 * Return SUCCESS or FAILED.
4409 megasas_issue_tm(struct megasas_instance *instance, u16 device_handle,
4410 uint channel, uint id, u16 smid_task, u8 type,
4411 struct MR_PRIV_DEVICE *mr_device_priv_data)
4413 struct MR_TASK_MANAGE_REQUEST *mr_request;
4414 struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_request;
4415 unsigned long timeleft;
4416 struct megasas_cmd_fusion *cmd_fusion;
4417 struct megasas_cmd *cmd_mfi;
4418 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
4419 struct fusion_context *fusion = NULL;
4420 struct megasas_cmd_fusion *scsi_lookup;
4422 int timeout = MEGASAS_DEFAULT_TM_TIMEOUT;
4423 struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply;
4425 fusion = instance->ctrl_context;
4427 cmd_mfi = megasas_get_cmd(instance);
4430 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
4431 __func__, __LINE__);
4435 cmd_fusion = megasas_get_cmd_fusion(instance,
4436 instance->max_scsi_cmds + cmd_mfi->index);
4438 /* Save the smid. To be used for returning the cmd */
4439 cmd_mfi->context.smid = cmd_fusion->index;
4441 req_desc = megasas_get_request_descriptor(instance,
4442 (cmd_fusion->index - 1));
4444 cmd_fusion->request_desc = req_desc;
4445 req_desc->Words = 0;
4447 mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request;
4448 memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST));
4449 mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) &mr_request->TmRequest;
4450 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
4451 mpi_request->DevHandle = cpu_to_le16(device_handle);
4452 mpi_request->TaskType = type;
4453 mpi_request->TaskMID = cpu_to_le16(smid_task);
4454 mpi_request->LUN[1] = 0;
4457 req_desc = cmd_fusion->request_desc;
4458 req_desc->HighPriority.SMID = cpu_to_le16(cmd_fusion->index);
4459 req_desc->HighPriority.RequestFlags =
4460 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
4461 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
4462 req_desc->HighPriority.MSIxIndex = 0;
4463 req_desc->HighPriority.LMID = 0;
4464 req_desc->HighPriority.Reserved1 = 0;
4466 if (channel < MEGASAS_MAX_PD_CHANNELS)
4467 mr_request->tmReqFlags.isTMForPD = 1;
4469 mr_request->tmReqFlags.isTMForLD = 1;
4471 init_completion(&cmd_fusion->done);
4472 megasas_fire_cmd_fusion(instance, req_desc);
4475 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
4476 timeout = mr_device_priv_data->task_abort_tmo;
4478 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
4479 timeout = mr_device_priv_data->target_reset_tmo;
4483 timeleft = wait_for_completion_timeout(&cmd_fusion->done, timeout * HZ);
4486 dev_err(&instance->pdev->dev,
4487 "task mgmt type 0x%x timed out\n", type);
4488 mutex_unlock(&instance->reset_mutex);
4489 rc = megasas_reset_fusion(instance->host, MFI_IO_TIMEOUT_OCR);
4490 mutex_lock(&instance->reset_mutex);
4494 mpi_reply = (struct MPI2_SCSI_TASK_MANAGE_REPLY *) &mr_request->TMReply;
4495 megasas_tm_response_code(instance, mpi_reply);
4497 megasas_return_cmd(instance, cmd_mfi);
4500 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
4501 scsi_lookup = fusion->cmd_list[smid_task - 1];
4503 if (scsi_lookup->scmd == NULL)
4506 instance->instancet->disable_intr(instance);
4507 megasas_sync_irqs((unsigned long)instance);
4508 instance->instancet->enable_intr(instance);
4509 megasas_enable_irq_poll(instance);
4510 if (scsi_lookup->scmd == NULL)
4516 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
4517 if ((channel == 0xFFFFFFFF) && (id == 0xFFFFFFFF))
4519 instance->instancet->disable_intr(instance);
4520 megasas_sync_irqs((unsigned long)instance);
4521 rc = megasas_track_scsiio(instance, id, channel);
4522 instance->instancet->enable_intr(instance);
4523 megasas_enable_irq_poll(instance);
4526 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
4527 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
4539 * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI
4540 * @instance: per adapter struct
4542 * Return Non Zero index, if SMID found in outstanding commands
4544 static u16 megasas_fusion_smid_lookup(struct scsi_cmnd *scmd)
4547 struct megasas_instance *instance;
4548 struct megasas_cmd_fusion *cmd_fusion;
4549 struct fusion_context *fusion;
4551 instance = (struct megasas_instance *)scmd->device->host->hostdata;
4553 fusion = instance->ctrl_context;
4555 for (i = 0; i < instance->max_scsi_cmds; i++) {
4556 cmd_fusion = fusion->cmd_list[i];
4557 if (cmd_fusion->scmd && (cmd_fusion->scmd == scmd)) {
4558 scmd_printk(KERN_NOTICE, scmd, "Abort request is for"
4559 " SMID: %d\n", cmd_fusion->index);
4560 ret = cmd_fusion->index;
4569 * megasas_get_tm_devhandle - Get devhandle for TM request
4570 * @sdev- OS provided scsi device
4572 * Returns- devhandle/targetID of SCSI device
4574 static u16 megasas_get_tm_devhandle(struct scsi_device *sdev)
4578 struct megasas_instance *instance;
4579 struct fusion_context *fusion;
4580 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
4581 u16 devhandle = (u16)ULONG_MAX;
4583 instance = (struct megasas_instance *)sdev->host->hostdata;
4584 fusion = instance->ctrl_context;
4586 if (!MEGASAS_IS_LOGICAL(sdev)) {
4587 if (instance->use_seqnum_jbod_fp) {
4588 pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
4590 pd_sync = (void *)fusion->pd_seq_sync
4591 [(instance->pd_seq_map_id - 1) & 1];
4592 devhandle = pd_sync->seq[pd_index].devHandle;
4594 sdev_printk(KERN_ERR, sdev, "Firmware expose tmCapable"
4595 " without JBOD MAP support from %s %d\n", __func__, __LINE__);
4597 device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL)
4599 devhandle = device_id;
4606 * megasas_task_abort_fusion : SCSI task abort function for fusion adapters
4607 * @scmd : pointer to scsi command object
4609 * Return SUCCESS, if command aborted else FAILED
4612 int megasas_task_abort_fusion(struct scsi_cmnd *scmd)
4614 struct megasas_instance *instance;
4615 u16 smid, devhandle;
4617 struct MR_PRIV_DEVICE *mr_device_priv_data;
4618 mr_device_priv_data = scmd->device->hostdata;
4620 instance = (struct megasas_instance *)scmd->device->host->hostdata;
4622 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
4623 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
4624 "SCSI host:%d\n", instance->host->host_no);
4629 if (!mr_device_priv_data) {
4630 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
4631 "scmd(%p)\n", scmd);
4632 scmd->result = DID_NO_CONNECT << 16;
4637 if (!mr_device_priv_data->is_tm_capable) {
4642 mutex_lock(&instance->reset_mutex);
4644 smid = megasas_fusion_smid_lookup(scmd);
4648 scmd_printk(KERN_NOTICE, scmd, "Command for which abort is"
4649 " issued is not found in outstanding commands\n");
4650 mutex_unlock(&instance->reset_mutex);
4654 devhandle = megasas_get_tm_devhandle(scmd->device);
4656 if (devhandle == (u16)ULONG_MAX) {
4658 sdev_printk(KERN_INFO, scmd->device,
4659 "task abort issued for invalid devhandle\n");
4660 mutex_unlock(&instance->reset_mutex);
4663 sdev_printk(KERN_INFO, scmd->device,
4664 "attempting task abort! scmd(0x%p) tm_dev_handle 0x%x\n",
4667 mr_device_priv_data->tm_busy = true;
4668 ret = megasas_issue_tm(instance, devhandle,
4669 scmd->device->channel, scmd->device->id, smid,
4670 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
4671 mr_device_priv_data);
4672 mr_device_priv_data->tm_busy = false;
4674 mutex_unlock(&instance->reset_mutex);
4675 scmd_printk(KERN_INFO, scmd, "task abort %s!! scmd(0x%p)\n",
4676 ((ret == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
4678 scsi_print_command(scmd);
4679 if (megasas_dbg_lvl & TM_DEBUG)
4680 megasas_dump_fusion_io(scmd);
4686 * megasas_reset_target_fusion : target reset function for fusion adapters
4687 * scmd: SCSI command pointer
4689 * Returns SUCCESS if all commands associated with target aborted else FAILED
4692 int megasas_reset_target_fusion(struct scsi_cmnd *scmd)
4695 struct megasas_instance *instance;
4698 struct MR_PRIV_DEVICE *mr_device_priv_data;
4699 mr_device_priv_data = scmd->device->hostdata;
4701 instance = (struct megasas_instance *)scmd->device->host->hostdata;
4703 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
4704 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
4705 "SCSI host:%d\n", instance->host->host_no);
4710 if (!mr_device_priv_data) {
4711 sdev_printk(KERN_INFO, scmd->device,
4712 "device been deleted! scmd: (0x%p)\n", scmd);
4713 scmd->result = DID_NO_CONNECT << 16;
4718 if (!mr_device_priv_data->is_tm_capable) {
4723 mutex_lock(&instance->reset_mutex);
4724 devhandle = megasas_get_tm_devhandle(scmd->device);
4726 if (devhandle == (u16)ULONG_MAX) {
4728 sdev_printk(KERN_INFO, scmd->device,
4729 "target reset issued for invalid devhandle\n");
4730 mutex_unlock(&instance->reset_mutex);
4734 sdev_printk(KERN_INFO, scmd->device,
4735 "attempting target reset! scmd(0x%p) tm_dev_handle: 0x%x\n",
4737 mr_device_priv_data->tm_busy = true;
4738 ret = megasas_issue_tm(instance, devhandle,
4739 scmd->device->channel, scmd->device->id, 0,
4740 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
4741 mr_device_priv_data);
4742 mr_device_priv_data->tm_busy = false;
4743 mutex_unlock(&instance->reset_mutex);
4744 scmd_printk(KERN_NOTICE, scmd, "target reset %s!!\n",
4745 (ret == SUCCESS) ? "SUCCESS" : "FAILED");
4751 /*SRIOV get other instance in cluster if any*/
4753 megasas_instance *megasas_get_peer_instance(struct megasas_instance *instance)
4757 for (i = 0; i < MAX_MGMT_ADAPTERS; i++) {
4758 if (megasas_mgmt_info.instance[i] &&
4759 (megasas_mgmt_info.instance[i] != instance) &&
4760 megasas_mgmt_info.instance[i]->requestorId &&
4761 megasas_mgmt_info.instance[i]->peerIsPresent &&
4762 (memcmp((megasas_mgmt_info.instance[i]->clusterId),
4763 instance->clusterId, MEGASAS_CLUSTER_ID_SIZE) == 0))
4764 return megasas_mgmt_info.instance[i];
4769 /* Check for a second path that is currently UP */
4770 int megasas_check_mpio_paths(struct megasas_instance *instance,
4771 struct scsi_cmnd *scmd)
4773 struct megasas_instance *peer_instance = NULL;
4774 int retval = (DID_REQUEUE << 16);
4776 if (instance->peerIsPresent) {
4777 peer_instance = megasas_get_peer_instance(instance);
4778 if ((peer_instance) &&
4779 (atomic_read(&peer_instance->adprecovery) ==
4780 MEGASAS_HBA_OPERATIONAL))
4781 retval = (DID_NO_CONNECT << 16);
4786 /* Core fusion reset function */
4787 int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
4789 int retval = SUCCESS, i, j, convert = 0;
4790 struct megasas_instance *instance;
4791 struct megasas_cmd_fusion *cmd_fusion, *r1_cmd;
4792 struct fusion_context *fusion;
4793 u32 abs_state, status_reg, reset_adapter, fpio_count = 0;
4794 u32 io_timeout_in_crash_mode = 0;
4795 struct scsi_cmnd *scmd_local = NULL;
4796 struct scsi_device *sdev;
4797 int ret_target_prop = DCMD_FAILED;
4798 bool is_target_prop = false;
4799 bool do_adp_reset = true;
4800 int max_reset_tries = MEGASAS_FUSION_MAX_RESET_TRIES;
4802 instance = (struct megasas_instance *)shost->hostdata;
4803 fusion = instance->ctrl_context;
4805 mutex_lock(&instance->reset_mutex);
4807 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
4808 dev_warn(&instance->pdev->dev, "Hardware critical error, "
4809 "returning FAILED for scsi%d.\n",
4810 instance->host->host_no);
4811 mutex_unlock(&instance->reset_mutex);
4814 status_reg = instance->instancet->read_fw_status_reg(instance);
4815 abs_state = status_reg & MFI_STATE_MASK;
4817 /* IO timeout detected, forcibly put FW in FAULT state */
4818 if (abs_state != MFI_STATE_FAULT && instance->crash_dump_buf &&
4819 instance->crash_dump_app_support && reason) {
4820 dev_info(&instance->pdev->dev, "IO/DCMD timeout is detected, "
4821 "forcibly FAULT Firmware\n");
4822 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT);
4823 status_reg = megasas_readl(instance, &instance->reg_set->doorbell);
4824 writel(status_reg | MFI_STATE_FORCE_OCR,
4825 &instance->reg_set->doorbell);
4826 readl(&instance->reg_set->doorbell);
4827 mutex_unlock(&instance->reset_mutex);
4830 io_timeout_in_crash_mode++;
4831 dev_dbg(&instance->pdev->dev, "waiting for [%d] "
4832 "seconds for crash dump collection and OCR "
4833 "to be done\n", (io_timeout_in_crash_mode * 3));
4834 } while ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) &&
4835 (io_timeout_in_crash_mode < 80));
4837 if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) {
4838 dev_info(&instance->pdev->dev, "OCR done for IO "
4842 dev_info(&instance->pdev->dev, "Controller is not "
4843 "operational after 240 seconds wait for IO "
4844 "timeout case in FW crash dump mode\n do "
4845 "OCR/kill adapter\n");
4846 retval = megasas_reset_fusion(shost, 0);
4851 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
4852 del_timer_sync(&instance->sriov_heartbeat_timer);
4853 set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
4854 set_bit(MEGASAS_FUSION_OCR_NOT_POSSIBLE, &instance->reset_flags);
4855 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_POLLING);
4856 instance->instancet->disable_intr(instance);
4857 megasas_sync_irqs((unsigned long)instance);
4859 /* First try waiting for commands to complete */
4860 if (megasas_wait_for_outstanding_fusion(instance, reason,
4862 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT);
4863 dev_warn(&instance->pdev->dev, "resetting fusion "
4864 "adapter scsi%d.\n", instance->host->host_no);
4868 if (megasas_dbg_lvl & OCR_DEBUG)
4869 dev_info(&instance->pdev->dev, "\nPending SCSI commands:\n");
4871 /* Now return commands back to the OS */
4872 for (i = 0 ; i < instance->max_scsi_cmds; i++) {
4873 cmd_fusion = fusion->cmd_list[i];
4874 /*check for extra commands issued by driver*/
4875 if (instance->adapter_type >= VENTURA_SERIES) {
4876 r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds];
4877 megasas_return_cmd_fusion(instance, r1_cmd);
4879 scmd_local = cmd_fusion->scmd;
4880 if (cmd_fusion->scmd) {
4881 if (megasas_dbg_lvl & OCR_DEBUG) {
4882 sdev_printk(KERN_INFO,
4883 cmd_fusion->scmd->device, "SMID: 0x%x\n",
4885 megasas_dump_fusion_io(cmd_fusion->scmd);
4888 if (cmd_fusion->io_request->Function ==
4889 MPI2_FUNCTION_SCSI_IO_REQUEST)
4892 scmd_local->result =
4893 megasas_check_mpio_paths(instance,
4895 if (instance->ldio_threshold &&
4896 megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
4897 atomic_dec(&instance->ldio_outstanding);
4898 megasas_return_cmd_fusion(instance, cmd_fusion);
4899 scsi_dma_unmap(scmd_local);
4900 scmd_local->scsi_done(scmd_local);
4904 dev_info(&instance->pdev->dev, "Outstanding fastpath IOs: %d\n",
4907 atomic_set(&instance->fw_outstanding, 0);
4909 status_reg = instance->instancet->read_fw_status_reg(instance);
4910 abs_state = status_reg & MFI_STATE_MASK;
4911 reset_adapter = status_reg & MFI_RESET_ADAPTER;
4912 if (instance->disableOnlineCtrlReset ||
4913 (abs_state == MFI_STATE_FAULT && !reset_adapter)) {
4914 /* Reset not supported, kill adapter */
4915 dev_warn(&instance->pdev->dev, "Reset not supported"
4916 ", killing adapter scsi%d.\n",
4917 instance->host->host_no);
4921 /* Let SR-IOV VF & PF sync up if there was a HB failure */
4922 if (instance->requestorId && !reason) {
4923 msleep(MEGASAS_OCR_SETTLE_TIME_VF);
4924 do_adp_reset = false;
4925 max_reset_tries = MEGASAS_SRIOV_MAX_RESET_TRIES_VF;
4928 /* Now try to reset the chip */
4929 for (i = 0; i < max_reset_tries; i++) {
4931 * Do adp reset and wait for
4932 * controller to transition to ready
4934 if (megasas_adp_reset_wait_for_ready(instance,
4935 do_adp_reset, 1) == FAILED)
4938 /* Wait for FW to become ready */
4939 if (megasas_transition_to_ready(instance, 1)) {
4940 dev_warn(&instance->pdev->dev,
4941 "Failed to transition controller to ready for "
4942 "scsi%d.\n", instance->host->host_no);
4945 megasas_reset_reply_desc(instance);
4946 megasas_fusion_update_can_queue(instance, OCR_CONTEXT);
4948 if (megasas_ioc_init_fusion(instance)) {
4952 if (megasas_get_ctrl_info(instance)) {
4953 dev_info(&instance->pdev->dev,
4954 "Failed from %s %d\n",
4955 __func__, __LINE__);
4959 megasas_refire_mgmt_cmd(instance,
4960 (i == (MEGASAS_FUSION_MAX_RESET_TRIES - 1)
4963 /* Reset load balance info */
4964 if (fusion->load_balance_info)
4965 memset(fusion->load_balance_info, 0,
4966 (sizeof(struct LD_LOAD_BALANCE_INFO) *
4967 MAX_LOGICAL_DRIVES_EXT));
4969 if (!megasas_get_map_info(instance)) {
4970 megasas_sync_map_info(instance);
4973 * Return pending polled mode cmds before
4976 megasas_return_polled_cmds(instance);
4980 megasas_setup_jbod_map(instance);
4982 /* reset stream detection array */
4983 if (instance->adapter_type >= VENTURA_SERIES) {
4984 for (j = 0; j < MAX_LOGICAL_DRIVES_EXT; ++j) {
4985 memset(fusion->stream_detect_by_ld[j],
4986 0, sizeof(struct LD_STREAM_DETECT));
4987 fusion->stream_detect_by_ld[j]->mru_bit_map
4992 clear_bit(MEGASAS_FUSION_IN_RESET,
4993 &instance->reset_flags);
4994 instance->instancet->enable_intr(instance);
4995 megasas_enable_irq_poll(instance);
4996 shost_for_each_device(sdev, shost) {
4997 if ((instance->tgt_prop) &&
4998 (instance->nvme_page_size))
4999 ret_target_prop = megasas_get_target_prop(instance, sdev);
5001 is_target_prop = (ret_target_prop == DCMD_SUCCESS) ? true : false;
5002 megasas_set_dynamic_target_properties(sdev, is_target_prop);
5005 status_reg = instance->instancet->read_fw_status_reg
5007 abs_state = status_reg & MFI_STATE_MASK;
5008 if (abs_state != MFI_STATE_OPERATIONAL) {
5009 dev_info(&instance->pdev->dev,
5010 "Adapter is not OPERATIONAL, state 0x%x for scsi:%d\n",
5011 abs_state, instance->host->host_no);
5014 atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL);
5016 dev_info(&instance->pdev->dev,
5017 "Adapter is OPERATIONAL for scsi:%d\n",
5018 instance->host->host_no);
5020 /* Restart SR-IOV heartbeat */
5021 if (instance->requestorId) {
5022 if (!megasas_sriov_start_heartbeat(instance, 0))
5023 megasas_start_timer(instance);
5025 instance->skip_heartbeat_timer_del = 1;
5028 if (instance->crash_dump_drv_support &&
5029 instance->crash_dump_app_support)
5030 megasas_set_crash_dump_params(instance,
5031 MR_CRASH_BUF_TURN_ON);
5033 megasas_set_crash_dump_params(instance,
5034 MR_CRASH_BUF_TURN_OFF);
5036 if (instance->snapdump_wait_time) {
5037 megasas_get_snapdump_properties(instance);
5038 dev_info(&instance->pdev->dev,
5039 "Snap dump wait time\t: %d\n",
5040 instance->snapdump_wait_time);
5045 /* Adapter reset completed successfully */
5046 dev_warn(&instance->pdev->dev,
5047 "Reset successful for scsi%d.\n",
5048 instance->host->host_no);
5052 /* Reset failed, kill the adapter */
5053 dev_warn(&instance->pdev->dev, "Reset failed, killing "
5054 "adapter scsi%d.\n", instance->host->host_no);
5057 /* For VF: Restart HB timer if we didn't OCR */
5058 if (instance->requestorId) {
5059 megasas_start_timer(instance);
5061 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
5062 instance->instancet->enable_intr(instance);
5063 megasas_enable_irq_poll(instance);
5064 atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL);
5068 megaraid_sas_kill_hba(instance);
5069 megasas_enable_irq_poll(instance);
5070 instance->skip_heartbeat_timer_del = 1;
5073 clear_bit(MEGASAS_FUSION_OCR_NOT_POSSIBLE, &instance->reset_flags);
5074 mutex_unlock(&instance->reset_mutex);
5078 /* Fusion Crash dump collection */
5079 static void megasas_fusion_crash_dump(struct megasas_instance *instance)
5082 u8 partial_copy = 0;
5086 status_reg = instance->instancet->read_fw_status_reg(instance);
5089 * Allocate host crash buffers to copy data from 1 MB DMA crash buffer
5090 * to host crash buffers
5092 if (instance->drv_buf_index == 0) {
5093 /* Buffer is already allocated for old Crash dump.
5094 * Do OCR and do not wait for crash dump collection
5096 if (instance->drv_buf_alloc) {
5097 dev_info(&instance->pdev->dev, "earlier crash dump is "
5098 "not yet copied by application, ignoring this "
5099 "crash dump and initiating OCR\n");
5100 status_reg |= MFI_STATE_CRASH_DUMP_DONE;
5102 &instance->reg_set->outbound_scratch_pad_0);
5103 readl(&instance->reg_set->outbound_scratch_pad_0);
5106 megasas_alloc_host_crash_buffer(instance);
5107 dev_info(&instance->pdev->dev, "Number of host crash buffers "
5108 "allocated: %d\n", instance->drv_buf_alloc);
5111 while (!(status_reg & MFI_STATE_CRASH_DUMP_DONE) &&
5112 (wait < MEGASAS_WATCHDOG_WAIT_COUNT)) {
5113 if (!(status_reg & MFI_STATE_DMADONE)) {
5115 * Next crash dump buffer is not yet DMA'd by FW
5116 * Check after 10ms. Wait for 1 second for FW to
5117 * post the next buffer. If not bail out.
5120 msleep(MEGASAS_WAIT_FOR_NEXT_DMA_MSECS);
5121 status_reg = instance->instancet->read_fw_status_reg(
5127 if (instance->drv_buf_index >= instance->drv_buf_alloc) {
5128 dev_info(&instance->pdev->dev,
5129 "Driver is done copying the buffer: %d\n",
5130 instance->drv_buf_alloc);
5131 status_reg |= MFI_STATE_CRASH_DUMP_DONE;
5135 memcpy(instance->crash_buf[instance->drv_buf_index],
5136 instance->crash_dump_buf, CRASH_DMA_BUF_SIZE);
5137 instance->drv_buf_index++;
5138 status_reg &= ~MFI_STATE_DMADONE;
5141 writel(status_reg, &instance->reg_set->outbound_scratch_pad_0);
5142 readl(&instance->reg_set->outbound_scratch_pad_0);
5144 msleep(MEGASAS_WAIT_FOR_NEXT_DMA_MSECS);
5145 status_reg = instance->instancet->read_fw_status_reg(instance);
5148 if (status_reg & MFI_STATE_CRASH_DUMP_DONE) {
5149 dev_info(&instance->pdev->dev, "Crash Dump is available,number "
5150 "of copied buffers: %d\n", instance->drv_buf_index);
5151 instance->fw_crash_buffer_size = instance->drv_buf_index;
5152 instance->fw_crash_state = AVAILABLE;
5153 instance->drv_buf_index = 0;
5154 writel(status_reg, &instance->reg_set->outbound_scratch_pad_0);
5155 readl(&instance->reg_set->outbound_scratch_pad_0);
5157 megasas_reset_fusion(instance->host, 0);
5162 /* Fusion OCR work queue */
5163 void megasas_fusion_ocr_wq(struct work_struct *work)
5165 struct megasas_instance *instance =
5166 container_of(work, struct megasas_instance, work_init);
5168 megasas_reset_fusion(instance->host, 0);
5171 /* Allocate fusion context */
5173 megasas_alloc_fusion_context(struct megasas_instance *instance)
5175 struct fusion_context *fusion;
5177 instance->ctrl_context = kzalloc(sizeof(struct fusion_context),
5179 if (!instance->ctrl_context) {
5180 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
5181 __func__, __LINE__);
5185 fusion = instance->ctrl_context;
5187 fusion->log_to_span_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
5188 sizeof(LD_SPAN_INFO));
5189 fusion->log_to_span =
5190 (PLD_SPAN_INFO)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
5191 fusion->log_to_span_pages);
5192 if (!fusion->log_to_span) {
5193 fusion->log_to_span =
5194 vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
5195 sizeof(LD_SPAN_INFO)));
5196 if (!fusion->log_to_span) {
5197 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
5198 __func__, __LINE__);
5203 fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
5204 sizeof(struct LD_LOAD_BALANCE_INFO));
5205 fusion->load_balance_info =
5206 (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
5207 fusion->load_balance_info_pages);
5208 if (!fusion->load_balance_info) {
5209 fusion->load_balance_info =
5210 vzalloc(array_size(MAX_LOGICAL_DRIVES_EXT,
5211 sizeof(struct LD_LOAD_BALANCE_INFO)));
5212 if (!fusion->load_balance_info)
5213 dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, "
5214 "continuing without Load Balance support\n");
5221 megasas_free_fusion_context(struct megasas_instance *instance)
5223 struct fusion_context *fusion = instance->ctrl_context;
5226 if (fusion->load_balance_info) {
5227 if (is_vmalloc_addr(fusion->load_balance_info))
5228 vfree(fusion->load_balance_info);
5230 free_pages((ulong)fusion->load_balance_info,
5231 fusion->load_balance_info_pages);
5234 if (fusion->log_to_span) {
5235 if (is_vmalloc_addr(fusion->log_to_span))
5236 vfree(fusion->log_to_span);
5238 free_pages((ulong)fusion->log_to_span,
5239 fusion->log_to_span_pages);
5246 struct megasas_instance_template megasas_instance_template_fusion = {
5247 .enable_intr = megasas_enable_intr_fusion,
5248 .disable_intr = megasas_disable_intr_fusion,
5249 .clear_intr = megasas_clear_intr_fusion,
5250 .read_fw_status_reg = megasas_read_fw_status_reg_fusion,
5251 .adp_reset = megasas_adp_reset_fusion,
5252 .check_reset = megasas_check_reset_fusion,
5253 .service_isr = megasas_isr_fusion,
5254 .tasklet = megasas_complete_cmd_dpc_fusion,
5255 .init_adapter = megasas_init_adapter_fusion,
5256 .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion,
5257 .issue_dcmd = megasas_issue_dcmd_fusion,