2 * Linux MegaRAID driver for SAS based RAID controllers
4 * Copyright (c) 2009-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * FILE: megaraid_sas_fusion.c
22 * Authors: Avago Technologies
25 * Kashyap Desai <kashyap.desai@avagotech.com>
26 * Sumit Saxena <sumit.saxena@avagotech.com>
28 * Send feedback to: megaraidlinux.pdl@avagotech.com
30 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
31 * San Jose, California 95131
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/list.h>
38 #include <linux/moduleparam.h>
39 #include <linux/module.h>
40 #include <linux/spinlock.h>
41 #include <linux/interrupt.h>
42 #include <linux/delay.h>
43 #include <linux/uio.h>
44 #include <linux/uaccess.h>
46 #include <linux/compat.h>
47 #include <linux/blkdev.h>
48 #include <linux/mutex.h>
49 #include <linux/poll.h>
50 #include <linux/vmalloc.h>
52 #include <scsi/scsi.h>
53 #include <scsi/scsi_cmnd.h>
54 #include <scsi/scsi_device.h>
55 #include <scsi/scsi_host.h>
56 #include <scsi/scsi_dbg.h>
57 #include <linux/dmi.h>
59 #include "megaraid_sas_fusion.h"
60 #include "megaraid_sas.h"
63 extern void megasas_free_cmds(struct megasas_instance *instance);
64 extern struct megasas_cmd *megasas_get_cmd(struct megasas_instance
67 megasas_complete_cmd(struct megasas_instance *instance,
68 struct megasas_cmd *cmd, u8 alt_status);
70 wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd,
74 megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd);
75 int megasas_alloc_cmds(struct megasas_instance *instance);
77 megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs);
79 megasas_issue_polled(struct megasas_instance *instance,
80 struct megasas_cmd *cmd);
82 megasas_check_and_restore_queue_depth(struct megasas_instance *instance);
84 int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
85 void megaraid_sas_kill_hba(struct megasas_instance *instance);
87 extern u32 megasas_dbg_lvl;
88 void megasas_sriov_heartbeat_handler(unsigned long instance_addr);
89 int megasas_sriov_start_heartbeat(struct megasas_instance *instance,
91 void megasas_start_timer(struct megasas_instance *instance,
92 struct timer_list *timer,
93 void *fn, unsigned long interval);
94 extern struct megasas_mgmt_info megasas_mgmt_info;
95 extern unsigned int resetwaittime;
96 extern unsigned int dual_qdepth_disable;
97 static void megasas_free_rdpq_fusion(struct megasas_instance *instance);
98 static void megasas_free_reply_fusion(struct megasas_instance *instance);
103 * megasas_enable_intr_fusion - Enables interrupts
104 * @regs: MFI register set
107 megasas_enable_intr_fusion(struct megasas_instance *instance)
109 struct megasas_register_set __iomem *regs;
110 regs = instance->reg_set;
112 instance->mask_interrupts = 0;
113 /* For Thunderbolt/Invader also clear intr on enable */
114 writel(~0, ®s->outbound_intr_status);
115 readl(®s->outbound_intr_status);
117 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
119 /* Dummy readl to force pci flush */
120 readl(®s->outbound_intr_mask);
124 * megasas_disable_intr_fusion - Disables interrupt
125 * @regs: MFI register set
128 megasas_disable_intr_fusion(struct megasas_instance *instance)
130 u32 mask = 0xFFFFFFFF;
132 struct megasas_register_set __iomem *regs;
133 regs = instance->reg_set;
134 instance->mask_interrupts = 1;
136 writel(mask, ®s->outbound_intr_mask);
137 /* Dummy readl to force pci flush */
138 status = readl(®s->outbound_intr_mask);
142 megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs)
146 * Check if it is our interrupt
148 status = readl(®s->outbound_intr_status);
151 writel(status, ®s->outbound_intr_status);
152 readl(®s->outbound_intr_status);
155 if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
162 * megasas_get_cmd_fusion - Get a command from the free pool
163 * @instance: Adapter soft state
165 * Returns a blk_tag indexed mpt frame
167 inline struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance
168 *instance, u32 blk_tag)
170 struct fusion_context *fusion;
172 fusion = instance->ctrl_context;
173 return fusion->cmd_list[blk_tag];
177 * megasas_return_cmd_fusion - Return a cmd to free command pool
178 * @instance: Adapter soft state
179 * @cmd: Command packet to be returned to free command pool
181 inline void megasas_return_cmd_fusion(struct megasas_instance *instance,
182 struct megasas_cmd_fusion *cmd)
185 memset(cmd->io_request, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE);
186 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
187 cmd->cmd_completed = false;
191 * megasas_fire_cmd_fusion - Sends command to the FW
192 * @instance: Adapter soft state
193 * @req_desc: 32bit or 64bit Request descriptor
195 * Perform PCI Write. Ventura supports 32 bit Descriptor.
196 * Prior to Ventura (12G) MR controller supports 64 bit Descriptor.
200 megasas_fire_cmd_fusion(struct megasas_instance *instance,
201 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc)
203 if (instance->is_ventura)
204 writel(le32_to_cpu(req_desc->u.low),
205 &instance->reg_set->inbound_single_queue_port);
207 #if defined(writeq) && defined(CONFIG_64BIT)
208 u64 req_data = (((u64)le32_to_cpu(req_desc->u.high) << 32) |
209 le32_to_cpu(req_desc->u.low));
211 writeq(req_data, &instance->reg_set->inbound_low_queue_port);
214 spin_lock_irqsave(&instance->hba_lock, flags);
215 writel(le32_to_cpu(req_desc->u.low),
216 &instance->reg_set->inbound_low_queue_port);
217 writel(le32_to_cpu(req_desc->u.high),
218 &instance->reg_set->inbound_high_queue_port);
220 spin_unlock_irqrestore(&instance->hba_lock, flags);
226 * megasas_fusion_update_can_queue - Do all Adapter Queue depth related calculations here
227 * @instance: Adapter soft state
228 * fw_boot_context: Whether this function called during probe or after OCR
230 * This function is only for fusion controllers.
231 * Update host can queue, if firmware downgrade max supported firmware commands.
232 * Firmware upgrade case will be skiped because underlying firmware has
233 * more resource than exposed to the OS.
237 megasas_fusion_update_can_queue(struct megasas_instance *instance, int fw_boot_context)
239 u16 cur_max_fw_cmds = 0;
240 u16 ldio_threshold = 0;
241 struct megasas_register_set __iomem *reg_set;
243 reg_set = instance->reg_set;
245 /* ventura FW does not fill outbound_scratch_pad_3 with queue depth */
246 if (!instance->is_ventura)
248 readl(&instance->reg_set->outbound_scratch_pad_3) & 0x00FFFF;
250 if (dual_qdepth_disable || !cur_max_fw_cmds)
251 cur_max_fw_cmds = instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
254 (instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF) - MEGASAS_FUSION_IOCTL_CMDS;
256 dev_info(&instance->pdev->dev,
257 "Current firmware maximum commands: %d\t LDIO threshold: %d\n",
258 cur_max_fw_cmds, ldio_threshold);
260 if (fw_boot_context == OCR_CONTEXT) {
261 cur_max_fw_cmds = cur_max_fw_cmds - 1;
262 if (cur_max_fw_cmds < instance->max_fw_cmds) {
263 instance->cur_can_queue =
264 cur_max_fw_cmds - (MEGASAS_FUSION_INTERNAL_CMDS +
265 MEGASAS_FUSION_IOCTL_CMDS);
266 instance->host->can_queue = instance->cur_can_queue;
267 instance->ldio_threshold = ldio_threshold;
270 instance->max_fw_cmds = cur_max_fw_cmds;
271 instance->ldio_threshold = ldio_threshold;
273 if (!instance->is_rdpq)
274 instance->max_fw_cmds =
275 min_t(u16, instance->max_fw_cmds, 1024);
278 instance->max_fw_cmds = min(instance->max_fw_cmds,
279 (u16)MEGASAS_KDUMP_QUEUE_DEPTH);
281 * Reduce the max supported cmds by 1. This is to ensure that the
282 * reply_q_sz (1 more than the max cmd that driver may send)
283 * does not exceed max cmds that the FW can support
285 instance->max_fw_cmds = instance->max_fw_cmds-1;
287 instance->max_scsi_cmds = instance->max_fw_cmds -
288 (MEGASAS_FUSION_INTERNAL_CMDS +
289 MEGASAS_FUSION_IOCTL_CMDS);
290 instance->cur_can_queue = instance->max_scsi_cmds;
291 instance->host->can_queue = instance->cur_can_queue;
294 if (instance->is_ventura)
295 instance->max_mpt_cmds =
296 instance->max_fw_cmds * RAID_1_PEER_CMDS;
298 instance->max_mpt_cmds = instance->max_fw_cmds;
301 * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
302 * @instance: Adapter soft state
305 megasas_free_cmds_fusion(struct megasas_instance *instance)
308 struct fusion_context *fusion = instance->ctrl_context;
309 struct megasas_cmd_fusion *cmd;
312 for (i = 0; i < instance->max_mpt_cmds; i++) {
313 cmd = fusion->cmd_list[i];
316 pci_pool_free(fusion->sg_dma_pool, cmd->sg_frame,
317 cmd->sg_frame_phys_addr);
319 pci_pool_free(fusion->sense_dma_pool, cmd->sense,
320 cmd->sense_phys_addr);
324 if (fusion->sg_dma_pool) {
325 pci_pool_destroy(fusion->sg_dma_pool);
326 fusion->sg_dma_pool = NULL;
328 if (fusion->sense_dma_pool) {
329 pci_pool_destroy(fusion->sense_dma_pool);
330 fusion->sense_dma_pool = NULL;
334 /* Reply Frame, Desc*/
335 if (instance->is_rdpq)
336 megasas_free_rdpq_fusion(instance);
338 megasas_free_reply_fusion(instance);
340 /* Request Frame, Desc*/
341 if (fusion->req_frames_desc)
342 dma_free_coherent(&instance->pdev->dev,
343 fusion->request_alloc_sz, fusion->req_frames_desc,
344 fusion->req_frames_desc_phys);
345 if (fusion->io_request_frames)
346 pci_pool_free(fusion->io_request_frames_pool,
347 fusion->io_request_frames,
348 fusion->io_request_frames_phys);
349 if (fusion->io_request_frames_pool) {
350 pci_pool_destroy(fusion->io_request_frames_pool);
351 fusion->io_request_frames_pool = NULL;
356 for (i = 0; i < instance->max_mpt_cmds; i++)
357 kfree(fusion->cmd_list[i]);
359 kfree(fusion->cmd_list);
363 * megasas_create_sg_sense_fusion - Creates DMA pool for cmd frames
364 * @instance: Adapter soft state
367 static int megasas_create_sg_sense_fusion(struct megasas_instance *instance)
371 struct fusion_context *fusion;
372 struct megasas_cmd_fusion *cmd;
374 fusion = instance->ctrl_context;
375 max_cmd = instance->max_fw_cmds;
378 fusion->sg_dma_pool =
379 pci_pool_create("mr_sg", instance->pdev,
380 instance->max_chain_frame_sz,
381 MR_DEFAULT_NVME_PAGE_SIZE, 0);
382 /* SCSI_SENSE_BUFFERSIZE = 96 bytes */
383 fusion->sense_dma_pool =
384 pci_pool_create("mr_sense", instance->pdev,
385 SCSI_SENSE_BUFFERSIZE, 64, 0);
387 if (!fusion->sense_dma_pool || !fusion->sg_dma_pool) {
388 dev_err(&instance->pdev->dev,
389 "Failed from %s %d\n", __func__, __LINE__);
394 * Allocate and attach a frame to each of the commands in cmd_list
396 for (i = 0; i < max_cmd; i++) {
397 cmd = fusion->cmd_list[i];
398 cmd->sg_frame = pci_pool_alloc(fusion->sg_dma_pool,
399 GFP_KERNEL, &cmd->sg_frame_phys_addr);
401 cmd->sense = pci_pool_alloc(fusion->sense_dma_pool,
402 GFP_KERNEL, &cmd->sense_phys_addr);
403 if (!cmd->sg_frame || !cmd->sense) {
404 dev_err(&instance->pdev->dev,
405 "Failed from %s %d\n", __func__, __LINE__);
410 /* create sense buffer for the raid 1/10 fp */
411 for (i = max_cmd; i < instance->max_mpt_cmds; i++) {
412 cmd = fusion->cmd_list[i];
413 cmd->sense = pci_pool_alloc(fusion->sense_dma_pool,
414 GFP_KERNEL, &cmd->sense_phys_addr);
416 dev_err(&instance->pdev->dev,
417 "Failed from %s %d\n", __func__, __LINE__);
426 megasas_alloc_cmdlist_fusion(struct megasas_instance *instance)
429 struct fusion_context *fusion;
431 fusion = instance->ctrl_context;
433 max_mpt_cmd = instance->max_mpt_cmds;
436 * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
437 * Allocate the dynamic array first and then allocate individual
441 kzalloc(sizeof(struct megasas_cmd_fusion *) * max_mpt_cmd,
443 if (!fusion->cmd_list) {
444 dev_err(&instance->pdev->dev,
445 "Failed from %s %d\n", __func__, __LINE__);
449 for (i = 0; i < max_mpt_cmd; i++) {
450 fusion->cmd_list[i] = kzalloc(sizeof(struct megasas_cmd_fusion),
452 if (!fusion->cmd_list[i]) {
453 dev_err(&instance->pdev->dev,
454 "Failed from %s %d\n", __func__, __LINE__);
461 megasas_alloc_request_fusion(struct megasas_instance *instance)
463 struct fusion_context *fusion;
465 fusion = instance->ctrl_context;
467 fusion->req_frames_desc =
468 dma_alloc_coherent(&instance->pdev->dev,
469 fusion->request_alloc_sz,
470 &fusion->req_frames_desc_phys, GFP_KERNEL);
471 if (!fusion->req_frames_desc) {
472 dev_err(&instance->pdev->dev,
473 "Failed from %s %d\n", __func__, __LINE__);
477 fusion->io_request_frames_pool =
478 pci_pool_create("mr_ioreq", instance->pdev,
479 fusion->io_frames_alloc_sz, 16, 0);
481 if (!fusion->io_request_frames_pool) {
482 dev_err(&instance->pdev->dev,
483 "Failed from %s %d\n", __func__, __LINE__);
487 fusion->io_request_frames =
488 pci_pool_alloc(fusion->io_request_frames_pool,
489 GFP_KERNEL, &fusion->io_request_frames_phys);
490 if (!fusion->io_request_frames) {
491 dev_err(&instance->pdev->dev,
492 "Failed from %s %d\n", __func__, __LINE__);
499 megasas_alloc_reply_fusion(struct megasas_instance *instance)
502 struct fusion_context *fusion;
503 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
504 fusion = instance->ctrl_context;
506 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
507 fusion->reply_frames_desc_pool =
508 pci_pool_create("mr_reply", instance->pdev,
509 fusion->reply_alloc_sz * count, 16, 0);
511 if (!fusion->reply_frames_desc_pool) {
512 dev_err(&instance->pdev->dev,
513 "Failed from %s %d\n", __func__, __LINE__);
517 fusion->reply_frames_desc[0] =
518 pci_pool_alloc(fusion->reply_frames_desc_pool,
519 GFP_KERNEL, &fusion->reply_frames_desc_phys[0]);
520 if (!fusion->reply_frames_desc[0]) {
521 dev_err(&instance->pdev->dev,
522 "Failed from %s %d\n", __func__, __LINE__);
525 reply_desc = fusion->reply_frames_desc[0];
526 for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++)
527 reply_desc->Words = cpu_to_le64(ULLONG_MAX);
529 /* This is not a rdpq mode, but driver still populate
530 * reply_frame_desc array to use same msix index in ISR path.
532 for (i = 0; i < (count - 1); i++)
533 fusion->reply_frames_desc[i + 1] =
534 fusion->reply_frames_desc[i] +
535 (fusion->reply_alloc_sz)/sizeof(union MPI2_REPLY_DESCRIPTORS_UNION);
541 megasas_alloc_rdpq_fusion(struct megasas_instance *instance)
544 struct fusion_context *fusion;
545 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
547 fusion = instance->ctrl_context;
549 fusion->rdpq_virt = pci_alloc_consistent(instance->pdev,
550 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION,
552 if (!fusion->rdpq_virt) {
553 dev_err(&instance->pdev->dev,
554 "Failed from %s %d\n", __func__, __LINE__);
558 memset(fusion->rdpq_virt, 0,
559 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION);
560 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
561 fusion->reply_frames_desc_pool = pci_pool_create("mr_rdpq",
562 instance->pdev, fusion->reply_alloc_sz, 16, 0);
564 if (!fusion->reply_frames_desc_pool) {
565 dev_err(&instance->pdev->dev,
566 "Failed from %s %d\n", __func__, __LINE__);
570 for (i = 0; i < count; i++) {
571 fusion->reply_frames_desc[i] =
572 pci_pool_alloc(fusion->reply_frames_desc_pool,
573 GFP_KERNEL, &fusion->reply_frames_desc_phys[i]);
574 if (!fusion->reply_frames_desc[i]) {
575 dev_err(&instance->pdev->dev,
576 "Failed from %s %d\n", __func__, __LINE__);
580 fusion->rdpq_virt[i].RDPQBaseAddress =
581 cpu_to_le64(fusion->reply_frames_desc_phys[i]);
583 reply_desc = fusion->reply_frames_desc[i];
584 for (j = 0; j < fusion->reply_q_depth; j++, reply_desc++)
585 reply_desc->Words = cpu_to_le64(ULLONG_MAX);
591 megasas_free_rdpq_fusion(struct megasas_instance *instance) {
594 struct fusion_context *fusion;
596 fusion = instance->ctrl_context;
598 for (i = 0; i < MAX_MSIX_QUEUES_FUSION; i++) {
599 if (fusion->reply_frames_desc[i])
600 pci_pool_free(fusion->reply_frames_desc_pool,
601 fusion->reply_frames_desc[i],
602 fusion->reply_frames_desc_phys[i]);
605 if (fusion->reply_frames_desc_pool)
606 pci_pool_destroy(fusion->reply_frames_desc_pool);
608 if (fusion->rdpq_virt)
609 pci_free_consistent(instance->pdev,
610 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY) * MAX_MSIX_QUEUES_FUSION,
611 fusion->rdpq_virt, fusion->rdpq_phys);
615 megasas_free_reply_fusion(struct megasas_instance *instance) {
617 struct fusion_context *fusion;
619 fusion = instance->ctrl_context;
621 if (fusion->reply_frames_desc[0])
622 pci_pool_free(fusion->reply_frames_desc_pool,
623 fusion->reply_frames_desc[0],
624 fusion->reply_frames_desc_phys[0]);
626 if (fusion->reply_frames_desc_pool)
627 pci_pool_destroy(fusion->reply_frames_desc_pool);
633 * megasas_alloc_cmds_fusion - Allocates the command packets
634 * @instance: Adapter soft state
637 * Each frame has a 32-bit field called context. This context is used to get
638 * back the megasas_cmd_fusion from the frame when a frame gets completed
639 * In this driver, the 32 bit values are the indices into an array cmd_list.
640 * This array is used only to look up the megasas_cmd_fusion given the context.
641 * The free commands themselves are maintained in a linked list called cmd_pool.
643 * cmds are formed in the io_request and sg_frame members of the
644 * megasas_cmd_fusion. The context field is used to get a request descriptor
645 * and is used as SMID of the cmd.
646 * SMID value range is from 1 to max_fw_cmds.
649 megasas_alloc_cmds_fusion(struct megasas_instance *instance)
652 struct fusion_context *fusion;
653 struct megasas_cmd_fusion *cmd;
655 dma_addr_t io_req_base_phys;
659 fusion = instance->ctrl_context;
661 if (megasas_alloc_cmdlist_fusion(instance))
664 if (megasas_alloc_request_fusion(instance))
667 if (instance->is_rdpq) {
668 if (megasas_alloc_rdpq_fusion(instance))
671 if (megasas_alloc_reply_fusion(instance))
675 /* The first 256 bytes (SMID 0) is not used. Don't add to the cmd list */
676 io_req_base = fusion->io_request_frames + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
677 io_req_base_phys = fusion->io_request_frames_phys + MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
680 * Add all the commands to command pool (fusion->cmd_pool)
683 /* SMID 0 is reserved. Set SMID/index from 1 */
684 for (i = 0; i < instance->max_mpt_cmds; i++) {
685 cmd = fusion->cmd_list[i];
686 offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i;
687 memset(cmd, 0, sizeof(struct megasas_cmd_fusion));
691 (i >= instance->max_scsi_cmds && i < instance->max_fw_cmds) ?
692 (i - instance->max_scsi_cmds) :
693 (u32)ULONG_MAX; /* Set to Invalid */
694 cmd->instance = instance;
696 (struct MPI2_RAID_SCSI_IO_REQUEST *)
697 (io_req_base + offset);
698 memset(cmd->io_request, 0,
699 sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
700 cmd->io_request_phys_addr = io_req_base_phys + offset;
701 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
704 if (megasas_create_sg_sense_fusion(instance))
710 megasas_free_cmds_fusion(instance);
715 * wait_and_poll - Issues a polling command
716 * @instance: Adapter soft state
717 * @cmd: Command packet to be issued
719 * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
722 wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd,
726 struct megasas_header *frame_hdr = &cmd->frame->hdr;
727 struct fusion_context *fusion;
729 u32 msecs = seconds * 1000;
731 fusion = instance->ctrl_context;
733 * Wait for cmd_status to change
735 for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) {
740 if (frame_hdr->cmd_status == MFI_STAT_INVALID_STATUS)
742 else if (frame_hdr->cmd_status == MFI_STAT_OK)
749 * megasas_ioc_init_fusion - Initializes the FW
750 * @instance: Adapter soft state
752 * Issues the IOC Init cmd
755 megasas_ioc_init_fusion(struct megasas_instance *instance)
757 struct megasas_init_frame *init_frame;
758 struct MPI2_IOC_INIT_REQUEST *IOCInitMessage = NULL;
759 dma_addr_t ioc_init_handle;
760 struct megasas_cmd *cmd;
761 u8 ret, cur_rdpq_mode;
762 struct fusion_context *fusion;
763 union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc;
765 struct megasas_header *frame_hdr;
766 const char *sys_info;
767 MFI_CAPABILITIES *drv_ops;
771 fusion = instance->ctrl_context;
773 cmd = megasas_get_cmd(instance);
776 dev_err(&instance->pdev->dev, "Could not allocate cmd for INIT Frame\n");
781 scratch_pad_2 = readl
782 (&instance->reg_set->outbound_scratch_pad_2);
784 cur_rdpq_mode = (scratch_pad_2 & MR_RDPQ_MODE_OFFSET) ? 1 : 0;
786 if (instance->is_rdpq && !cur_rdpq_mode) {
787 dev_err(&instance->pdev->dev, "Firmware downgrade *NOT SUPPORTED*"
788 " from RDPQ mode to non RDPQ mode\n");
793 instance->fw_sync_cache_support = (scratch_pad_2 &
794 MR_CAN_HANDLE_SYNC_CACHE_OFFSET) ? 1 : 0;
795 dev_info(&instance->pdev->dev, "FW supports sync cache\t: %s\n",
796 instance->fw_sync_cache_support ? "Yes" : "No");
799 dma_alloc_coherent(&instance->pdev->dev,
800 sizeof(struct MPI2_IOC_INIT_REQUEST),
801 &ioc_init_handle, GFP_KERNEL);
803 if (!IOCInitMessage) {
804 dev_err(&instance->pdev->dev, "Could not allocate memory for "
810 memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST));
812 IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT;
813 IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER;
814 IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION);
815 IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
816 IOCInitMessage->SystemRequestFrameSize = cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4);
818 IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth);
819 IOCInitMessage->ReplyDescriptorPostQueueAddress = instance->is_rdpq ?
820 cpu_to_le64(fusion->rdpq_phys) :
821 cpu_to_le64(fusion->reply_frames_desc_phys[0]);
822 IOCInitMessage->MsgFlags = instance->is_rdpq ?
823 MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE : 0;
824 IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys);
825 IOCInitMessage->HostMSIxVectors = instance->msix_vectors;
826 IOCInitMessage->HostPageSize = MR_DEFAULT_NVME_PAGE_SHIFT;
827 init_frame = (struct megasas_init_frame *)cmd->frame;
828 memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
830 frame_hdr = &cmd->frame->hdr;
831 frame_hdr->cmd_status = 0xFF;
832 frame_hdr->flags = cpu_to_le16(
833 le16_to_cpu(frame_hdr->flags) |
834 MFI_FRAME_DONT_POST_IN_REPLY_QUEUE);
836 init_frame->cmd = MFI_CMD_INIT;
837 init_frame->cmd_status = 0xFF;
839 drv_ops = (MFI_CAPABILITIES *) &(init_frame->driver_operations);
841 /* driver support Extended MSIX */
842 if (fusion->adapter_type >= INVADER_SERIES)
843 drv_ops->mfi_capabilities.support_additional_msix = 1;
844 /* driver supports HA / Remote LUN over Fast Path interface */
845 drv_ops->mfi_capabilities.support_fp_remote_lun = 1;
847 drv_ops->mfi_capabilities.support_max_255lds = 1;
848 drv_ops->mfi_capabilities.support_ndrive_r1_lb = 1;
849 drv_ops->mfi_capabilities.security_protocol_cmds_fw = 1;
851 if (instance->max_chain_frame_sz > MEGASAS_CHAIN_FRAME_SZ_MIN)
852 drv_ops->mfi_capabilities.support_ext_io_size = 1;
854 drv_ops->mfi_capabilities.support_fp_rlbypass = 1;
855 if (!dual_qdepth_disable)
856 drv_ops->mfi_capabilities.support_ext_queue_depth = 1;
858 drv_ops->mfi_capabilities.support_qd_throttling = 1;
859 drv_ops->mfi_capabilities.support_pd_map_target_id = 1;
860 /* Convert capability to LE32 */
861 cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities);
863 sys_info = dmi_get_system_info(DMI_PRODUCT_UUID);
864 if (instance->system_info_buf && sys_info) {
865 memcpy(instance->system_info_buf->systemId, sys_info,
866 strlen(sys_info) > 64 ? 64 : strlen(sys_info));
867 instance->system_info_buf->systemIdLength =
868 strlen(sys_info) > 64 ? 64 : strlen(sys_info);
869 init_frame->system_info_lo = instance->system_info_h;
870 init_frame->system_info_hi = 0;
873 init_frame->queue_info_new_phys_addr_hi =
874 cpu_to_le32(upper_32_bits(ioc_init_handle));
875 init_frame->queue_info_new_phys_addr_lo =
876 cpu_to_le32(lower_32_bits(ioc_init_handle));
877 init_frame->data_xfer_len = cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST));
879 req_desc.u.low = cpu_to_le32(lower_32_bits(cmd->frame_phys_addr));
880 req_desc.u.high = cpu_to_le32(upper_32_bits(cmd->frame_phys_addr));
881 req_desc.MFAIo.RequestFlags =
882 (MEGASAS_REQ_DESCRIPT_FLAGS_MFA <<
883 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
886 * disable the intr before firing the init frame
888 instance->instancet->disable_intr(instance);
890 for (i = 0; i < (10 * 1000); i += 20) {
891 if (readl(&instance->reg_set->doorbell) & 1)
897 /* For Ventura also IOC INIT required 64 bit Descriptor write. */
898 spin_lock_irqsave(&instance->hba_lock, flags);
899 writel(le32_to_cpu(req_desc.u.low),
900 &instance->reg_set->inbound_low_queue_port);
901 writel(le32_to_cpu(req_desc.u.high),
902 &instance->reg_set->inbound_high_queue_port);
904 spin_unlock_irqrestore(&instance->hba_lock, flags);
906 wait_and_poll(instance, cmd, MFI_POLL_TIMEOUT_SECS);
908 frame_hdr = &cmd->frame->hdr;
909 if (frame_hdr->cmd_status != 0) {
913 dev_info(&instance->pdev->dev, "Init cmd success\n");
918 megasas_return_cmd(instance, cmd);
920 dma_free_coherent(&instance->pdev->dev,
921 sizeof(struct MPI2_IOC_INIT_REQUEST),
922 IOCInitMessage, ioc_init_handle);
928 * megasas_sync_pd_seq_num - JBOD SEQ MAP
929 * @instance: Adapter soft state
930 * @pend: set to 1, if it is pended jbod map.
932 * Issue Jbod map to the firmware. If it is pended command,
933 * issue command and return. If it is first instance of jbod map
934 * issue and receive command.
937 megasas_sync_pd_seq_num(struct megasas_instance *instance, bool pend) {
940 struct megasas_cmd *cmd;
941 struct megasas_dcmd_frame *dcmd;
942 struct fusion_context *fusion = instance->ctrl_context;
943 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
946 pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id & 1)];
947 pd_seq_h = fusion->pd_seq_phys[(instance->pd_seq_map_id & 1)];
948 pd_seq_map_sz = sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC) +
949 (sizeof(struct MR_PD_CFG_SEQ) *
950 (MAX_PHYSICAL_DEVICES - 1));
952 cmd = megasas_get_cmd(instance);
954 dev_err(&instance->pdev->dev,
955 "Could not get mfi cmd. Fail from %s %d\n",
960 dcmd = &cmd->frame->dcmd;
962 memset(pd_sync, 0, pd_seq_map_sz);
963 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
964 dcmd->cmd = MFI_CMD_DCMD;
965 dcmd->cmd_status = 0xFF;
969 dcmd->data_xfer_len = cpu_to_le32(pd_seq_map_sz);
970 dcmd->opcode = cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO);
971 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(pd_seq_h);
972 dcmd->sgl.sge32[0].length = cpu_to_le32(pd_seq_map_sz);
975 dcmd->mbox.b[0] = MEGASAS_DCMD_MBOX_PEND_FLAG;
976 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE);
977 instance->jbod_seq_cmd = cmd;
978 instance->instancet->issue_dcmd(instance, cmd);
982 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
984 /* Below code is only for non pended DCMD */
985 if (instance->ctrl_context && !instance->mask_interrupts)
986 ret = megasas_issue_blocked_cmd(instance, cmd,
987 MFI_IO_TIMEOUT_SECS);
989 ret = megasas_issue_polled(instance, cmd);
991 if (le32_to_cpu(pd_sync->count) > MAX_PHYSICAL_DEVICES) {
992 dev_warn(&instance->pdev->dev,
993 "driver supports max %d JBOD, but FW reports %d\n",
994 MAX_PHYSICAL_DEVICES, le32_to_cpu(pd_sync->count));
998 if (ret == DCMD_TIMEOUT && instance->ctrl_context)
999 megaraid_sas_kill_hba(instance);
1001 if (ret == DCMD_SUCCESS)
1002 instance->pd_seq_map_id++;
1004 megasas_return_cmd(instance, cmd);
1009 * megasas_get_ld_map_info - Returns FW's ld_map structure
1010 * @instance: Adapter soft state
1011 * @pend: Pend the command or not
1012 * Issues an internal command (DCMD) to get the FW's controller PD
1013 * list structure. This information is mainly used to find out SYSTEM
1014 * supported by the FW.
1015 * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO
1016 * dcmd.mbox.b[0] - number of LDs being sync'd
1017 * dcmd.mbox.b[1] - 0 - complete command immediately.
1018 * - 1 - pend till config change
1019 * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP
1020 * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and
1021 * uses extended struct MR_FW_RAID_MAP_EXT
1024 megasas_get_ld_map_info(struct megasas_instance *instance)
1027 struct megasas_cmd *cmd;
1028 struct megasas_dcmd_frame *dcmd;
1030 dma_addr_t ci_h = 0;
1032 struct fusion_context *fusion;
1034 cmd = megasas_get_cmd(instance);
1037 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for map info\n");
1041 fusion = instance->ctrl_context;
1044 megasas_return_cmd(instance, cmd);
1048 dcmd = &cmd->frame->dcmd;
1050 size_map_info = fusion->current_map_sz;
1052 ci = (void *) fusion->ld_map[(instance->map_id & 1)];
1053 ci_h = fusion->ld_map_phys[(instance->map_id & 1)];
1056 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to alloc mem for ld_map_info\n");
1057 megasas_return_cmd(instance, cmd);
1061 memset(ci, 0, fusion->max_map_sz);
1062 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1063 dcmd->cmd = MFI_CMD_DCMD;
1064 dcmd->cmd_status = 0xFF;
1065 dcmd->sge_count = 1;
1066 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
1069 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
1070 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
1071 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
1072 dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info);
1074 if (instance->ctrl_context && !instance->mask_interrupts)
1075 ret = megasas_issue_blocked_cmd(instance, cmd,
1076 MFI_IO_TIMEOUT_SECS);
1078 ret = megasas_issue_polled(instance, cmd);
1080 if (ret == DCMD_TIMEOUT && instance->ctrl_context)
1081 megaraid_sas_kill_hba(instance);
1083 megasas_return_cmd(instance, cmd);
1089 megasas_get_map_info(struct megasas_instance *instance)
1091 struct fusion_context *fusion = instance->ctrl_context;
1093 fusion->fast_path_io = 0;
1094 if (!megasas_get_ld_map_info(instance)) {
1095 if (MR_ValidateMapInfo(instance)) {
1096 fusion->fast_path_io = 1;
1104 * megasas_sync_map_info - Returns FW's ld_map structure
1105 * @instance: Adapter soft state
1107 * Issues an internal command (DCMD) to get the FW's controller PD
1108 * list structure. This information is mainly used to find out SYSTEM
1109 * supported by the FW.
1112 megasas_sync_map_info(struct megasas_instance *instance)
1115 struct megasas_cmd *cmd;
1116 struct megasas_dcmd_frame *dcmd;
1119 struct fusion_context *fusion;
1120 struct MR_LD_TARGET_SYNC *ci = NULL;
1121 struct MR_DRV_RAID_MAP_ALL *map;
1122 struct MR_LD_RAID *raid;
1123 struct MR_LD_TARGET_SYNC *ld_sync;
1124 dma_addr_t ci_h = 0;
1127 cmd = megasas_get_cmd(instance);
1130 dev_printk(KERN_DEBUG, &instance->pdev->dev, "Failed to get cmd for sync info\n");
1134 fusion = instance->ctrl_context;
1137 megasas_return_cmd(instance, cmd);
1141 map = fusion->ld_drv_map[instance->map_id & 1];
1143 num_lds = le16_to_cpu(map->raidMap.ldCount);
1145 dcmd = &cmd->frame->dcmd;
1147 size_sync_info = sizeof(struct MR_LD_TARGET_SYNC) *num_lds;
1149 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
1151 ci = (struct MR_LD_TARGET_SYNC *)
1152 fusion->ld_map[(instance->map_id - 1) & 1];
1153 memset(ci, 0, fusion->max_map_sz);
1155 ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1];
1157 ld_sync = (struct MR_LD_TARGET_SYNC *)ci;
1159 for (i = 0; i < num_lds; i++, ld_sync++) {
1160 raid = MR_LdRaidGet(i, map);
1161 ld_sync->targetId = MR_GetLDTgtId(i, map);
1162 ld_sync->seqNum = raid->seqNum;
1165 size_map_info = fusion->current_map_sz;
1167 dcmd->cmd = MFI_CMD_DCMD;
1168 dcmd->cmd_status = 0xFF;
1169 dcmd->sge_count = 1;
1170 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE);
1173 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
1174 dcmd->mbox.b[0] = num_lds;
1175 dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG;
1176 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
1177 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
1178 dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info);
1180 instance->map_update_cmd = cmd;
1182 instance->instancet->issue_dcmd(instance, cmd);
1188 * meagasas_display_intel_branding - Display branding string
1189 * @instance: per adapter object
1194 megasas_display_intel_branding(struct megasas_instance *instance)
1196 if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1199 switch (instance->pdev->device) {
1200 case PCI_DEVICE_ID_LSI_INVADER:
1201 switch (instance->pdev->subsystem_device) {
1202 case MEGARAID_INTEL_RS3DC080_SSDID:
1203 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1204 instance->host->host_no,
1205 MEGARAID_INTEL_RS3DC080_BRANDING);
1207 case MEGARAID_INTEL_RS3DC040_SSDID:
1208 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1209 instance->host->host_no,
1210 MEGARAID_INTEL_RS3DC040_BRANDING);
1212 case MEGARAID_INTEL_RS3SC008_SSDID:
1213 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1214 instance->host->host_no,
1215 MEGARAID_INTEL_RS3SC008_BRANDING);
1217 case MEGARAID_INTEL_RS3MC044_SSDID:
1218 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1219 instance->host->host_no,
1220 MEGARAID_INTEL_RS3MC044_BRANDING);
1226 case PCI_DEVICE_ID_LSI_FURY:
1227 switch (instance->pdev->subsystem_device) {
1228 case MEGARAID_INTEL_RS3WC080_SSDID:
1229 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1230 instance->host->host_no,
1231 MEGARAID_INTEL_RS3WC080_BRANDING);
1233 case MEGARAID_INTEL_RS3WC040_SSDID:
1234 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1235 instance->host->host_no,
1236 MEGARAID_INTEL_RS3WC040_BRANDING);
1242 case PCI_DEVICE_ID_LSI_CUTLASS_52:
1243 case PCI_DEVICE_ID_LSI_CUTLASS_53:
1244 switch (instance->pdev->subsystem_device) {
1245 case MEGARAID_INTEL_RMS3BC160_SSDID:
1246 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
1247 instance->host->host_no,
1248 MEGARAID_INTEL_RMS3BC160_BRANDING);
1260 * megasas_init_adapter_fusion - Initializes the FW
1261 * @instance: Adapter soft state
1263 * This is the main function for initializing firmware.
1266 megasas_init_adapter_fusion(struct megasas_instance *instance)
1268 struct megasas_register_set __iomem *reg_set;
1269 struct fusion_context *fusion;
1274 fusion = instance->ctrl_context;
1276 reg_set = instance->reg_set;
1278 megasas_fusion_update_can_queue(instance, PROBE_CONTEXT);
1281 * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames
1283 instance->max_mfi_cmds =
1284 MEGASAS_FUSION_INTERNAL_CMDS + MEGASAS_FUSION_IOCTL_CMDS;
1286 max_cmd = instance->max_fw_cmds;
1288 fusion->reply_q_depth = 2 * (((max_cmd + 1 + 15)/16)*16);
1290 fusion->request_alloc_sz =
1291 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * instance->max_mpt_cmds;
1292 fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)
1293 *(fusion->reply_q_depth);
1294 fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE +
1295 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1296 * (instance->max_mpt_cmds + 1)); /* Extra 1 for SMID 0 */
1298 scratch_pad_2 = readl(&instance->reg_set->outbound_scratch_pad_2);
1299 /* If scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set,
1300 * Firmware support extended IO chain frame which is 4 times more than
1302 * Legacy Firmware - Frame size is (8 * 128) = 1K
1303 * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K
1305 if (scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK)
1306 instance->max_chain_frame_sz =
1307 ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >>
1308 MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_1MB_IO;
1310 instance->max_chain_frame_sz =
1311 ((scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_MASK) >>
1312 MEGASAS_MAX_CHAIN_SHIFT) * MEGASAS_256K_IO;
1314 if (instance->max_chain_frame_sz < MEGASAS_CHAIN_FRAME_SZ_MIN) {
1315 dev_warn(&instance->pdev->dev, "frame size %d invalid, fall back to legacy max frame size %d\n",
1316 instance->max_chain_frame_sz,
1317 MEGASAS_CHAIN_FRAME_SZ_MIN);
1318 instance->max_chain_frame_sz = MEGASAS_CHAIN_FRAME_SZ_MIN;
1321 fusion->max_sge_in_main_msg =
1322 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1323 - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16;
1325 fusion->max_sge_in_chain =
1326 instance->max_chain_frame_sz
1327 / sizeof(union MPI2_SGE_IO_UNION);
1329 instance->max_num_sge =
1330 rounddown_pow_of_two(fusion->max_sge_in_main_msg
1331 + fusion->max_sge_in_chain - 2);
1333 /* Used for pass thru MFI frame (DCMD) */
1334 fusion->chain_offset_mfi_pthru =
1335 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16;
1337 fusion->chain_offset_io_request =
1338 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
1339 sizeof(union MPI2_SGE_IO_UNION))/16;
1341 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
1342 for (i = 0 ; i < count; i++)
1343 fusion->last_reply_idx[i] = 0;
1346 * For fusion adapters, 3 commands for IOCTL and 8 commands
1347 * for driver's internal DCMDs.
1349 instance->max_scsi_cmds = instance->max_fw_cmds -
1350 (MEGASAS_FUSION_INTERNAL_CMDS +
1351 MEGASAS_FUSION_IOCTL_CMDS);
1352 sema_init(&instance->ioctl_sem, MEGASAS_FUSION_IOCTL_CMDS);
1355 * Allocate memory for descriptors
1356 * Create a pool of commands
1358 if (megasas_alloc_cmds(instance))
1359 goto fail_alloc_mfi_cmds;
1360 if (megasas_alloc_cmds_fusion(instance))
1361 goto fail_alloc_cmds;
1363 if (megasas_ioc_init_fusion(instance))
1366 megasas_display_intel_branding(instance);
1367 if (megasas_get_ctrl_info(instance)) {
1368 dev_err(&instance->pdev->dev,
1369 "Could not get controller info. Fail from %s %d\n",
1370 __func__, __LINE__);
1374 instance->flag_ieee = 1;
1375 instance->r1_ldio_hint_default = MR_R1_LDIO_PIGGYBACK_DEFAULT;
1376 fusion->fast_path_io = 0;
1378 fusion->drv_map_pages = get_order(fusion->drv_map_sz);
1379 for (i = 0; i < 2; i++) {
1380 fusion->ld_map[i] = NULL;
1381 fusion->ld_drv_map[i] = (void *)__get_free_pages(GFP_KERNEL,
1382 fusion->drv_map_pages);
1383 if (!fusion->ld_drv_map[i]) {
1384 dev_err(&instance->pdev->dev, "Could not allocate "
1385 "memory for local map info for %d pages\n",
1386 fusion->drv_map_pages);
1388 free_pages((ulong)fusion->ld_drv_map[0],
1389 fusion->drv_map_pages);
1392 memset(fusion->ld_drv_map[i], 0,
1393 ((1 << PAGE_SHIFT) << fusion->drv_map_pages));
1396 for (i = 0; i < 2; i++) {
1397 fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev,
1399 &fusion->ld_map_phys[i],
1401 if (!fusion->ld_map[i]) {
1402 dev_err(&instance->pdev->dev, "Could not allocate memory "
1408 if (!megasas_get_map_info(instance))
1409 megasas_sync_map_info(instance);
1415 dma_free_coherent(&instance->pdev->dev, fusion->max_map_sz,
1416 fusion->ld_map[0], fusion->ld_map_phys[0]);
1418 megasas_free_cmds_fusion(instance);
1420 megasas_free_cmds(instance);
1421 fail_alloc_mfi_cmds:
1426 * map_cmd_status - Maps FW cmd status to OS cmd status
1427 * @cmd : Pointer to cmd
1428 * @status : status of cmd returned by FW
1429 * @ext_status : ext status of cmd returned by FW
1433 map_cmd_status(struct fusion_context *fusion,
1434 struct scsi_cmnd *scmd, u8 status, u8 ext_status,
1435 u32 data_length, u8 *sense)
1440 cmd_type = megasas_cmd_type(scmd);
1444 scmd->result = DID_OK << 16;
1447 case MFI_STAT_SCSI_IO_FAILED:
1448 case MFI_STAT_LD_INIT_IN_PROGRESS:
1449 scmd->result = (DID_ERROR << 16) | ext_status;
1452 case MFI_STAT_SCSI_DONE_WITH_ERROR:
1454 scmd->result = (DID_OK << 16) | ext_status;
1455 if (ext_status == SAM_STAT_CHECK_CONDITION) {
1456 memset(scmd->sense_buffer, 0,
1457 SCSI_SENSE_BUFFERSIZE);
1458 memcpy(scmd->sense_buffer, sense,
1459 SCSI_SENSE_BUFFERSIZE);
1460 scmd->result |= DRIVER_SENSE << 24;
1464 * If the IO request is partially completed, then MR FW will
1465 * update "io_request->DataLength" field with actual number of
1466 * bytes transferred.Driver will set residual bytes count in
1467 * SCSI command structure.
1469 resid = (scsi_bufflen(scmd) - data_length);
1470 scsi_set_resid(scmd, resid);
1473 ((cmd_type == READ_WRITE_LDIO) ||
1474 (cmd_type == READ_WRITE_SYSPDIO)))
1475 scmd_printk(KERN_INFO, scmd, "BRCM Debug mfi stat 0x%x, data len"
1476 " requested/completed 0x%x/0x%x\n",
1477 status, scsi_bufflen(scmd), data_length);
1480 case MFI_STAT_LD_OFFLINE:
1481 case MFI_STAT_DEVICE_NOT_FOUND:
1482 scmd->result = DID_BAD_TARGET << 16;
1484 case MFI_STAT_CONFIG_SEQ_MISMATCH:
1485 scmd->result = DID_IMM_RETRY << 16;
1488 scmd->result = DID_ERROR << 16;
1494 * megasas_is_prp_possible -
1495 * Checks if native NVMe PRPs can be built for the IO
1497 * @instance: Adapter soft state
1498 * @scmd: SCSI command from the mid-layer
1499 * @sge_count: scatter gather element count.
1501 * Returns: true: PRPs can be built
1502 * false: IEEE SGLs needs to be built
1505 megasas_is_prp_possible(struct megasas_instance *instance,
1506 struct scsi_cmnd *scmd, int sge_count)
1508 struct fusion_context *fusion;
1510 u32 data_length = 0;
1511 struct scatterlist *sg_scmd;
1512 bool build_prp = false;
1513 u32 mr_nvme_pg_size;
1515 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
1516 MR_DEFAULT_NVME_PAGE_SIZE);
1517 fusion = instance->ctrl_context;
1518 data_length = scsi_bufflen(scmd);
1519 sg_scmd = scsi_sglist(scmd);
1522 * NVMe uses one PRP for each page (or part of a page)
1523 * look at the data length - if 4 pages or less then IEEE is OK
1524 * if > 5 pages then we need to build a native SGL
1525 * if > 4 and <= 5 pages, then check physical address of 1st SG entry
1526 * if this first size in the page is >= the residual beyond 4 pages
1527 * then use IEEE, otherwise use native SGL
1530 if (data_length > (mr_nvme_pg_size * 5)) {
1532 } else if ((data_length > (mr_nvme_pg_size * 4)) &&
1533 (data_length <= (mr_nvme_pg_size * 5))) {
1534 /* check if 1st SG entry size is < residual beyond 4 pages */
1535 if (sg_dma_len(sg_scmd) < (data_length - (mr_nvme_pg_size * 4)))
1540 * Below code detects gaps/holes in IO data buffers.
1541 * What does holes/gaps mean?
1542 * Any SGE except first one in a SGL starts at non NVME page size
1543 * aligned address OR Any SGE except last one in a SGL ends at
1544 * non NVME page size boundary.
1546 * Driver has already informed block layer by setting boundary rules for
1547 * bio merging done at NVME page size boundary calling kernel API
1548 * blk_queue_virt_boundary inside slave_config.
1549 * Still there is possibility of IO coming with holes to driver because of
1550 * IO merging done by IO scheduler.
1552 * With SCSI BLK MQ enabled, there will be no IO with holes as there is no
1553 * IO scheduling so no IO merging.
1555 * With SCSI BLK MQ disabled, IO scheduler may attempt to merge IOs and
1556 * then sending IOs with holes.
1558 * Though driver can request block layer to disable IO merging by calling-
1559 * queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue) but
1560 * user may tune sysfs parameter- nomerges again to 0 or 1.
1562 * If in future IO scheduling is enabled with SCSI BLK MQ,
1563 * this algorithm to detect holes will be required in driver
1564 * for SCSI BLK MQ enabled case as well.
1568 scsi_for_each_sg(scmd, sg_scmd, sge_count, i) {
1569 if ((i != 0) && (i != (sge_count - 1))) {
1570 if (mega_mod64(sg_dma_len(sg_scmd), mr_nvme_pg_size) ||
1571 mega_mod64(sg_dma_address(sg_scmd),
1574 atomic_inc(&instance->sge_holes_type1);
1579 if ((sge_count > 1) && (i == 0)) {
1580 if ((mega_mod64((sg_dma_address(sg_scmd) +
1581 sg_dma_len(sg_scmd)),
1582 mr_nvme_pg_size))) {
1584 atomic_inc(&instance->sge_holes_type2);
1589 if ((sge_count > 1) && (i == (sge_count - 1))) {
1590 if (mega_mod64(sg_dma_address(sg_scmd),
1593 atomic_inc(&instance->sge_holes_type3);
1603 * megasas_make_prp_nvme -
1604 * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only
1606 * @instance: Adapter soft state
1607 * @scmd: SCSI command from the mid-layer
1608 * @sgl_ptr: SGL to be filled in
1609 * @cmd: Fusion command frame
1610 * @sge_count: scatter gather element count.
1612 * Returns: true: PRPs are built
1613 * false: IEEE SGLs needs to be built
1616 megasas_make_prp_nvme(struct megasas_instance *instance, struct scsi_cmnd *scmd,
1617 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
1618 struct megasas_cmd_fusion *cmd, int sge_count)
1620 int sge_len, offset, num_prp_in_chain = 0;
1621 struct MPI25_IEEE_SGE_CHAIN64 *main_chain_element, *ptr_first_sgl;
1623 dma_addr_t ptr_sgl_phys;
1625 u32 page_mask, page_mask_result;
1626 struct scatterlist *sg_scmd;
1628 bool build_prp = false;
1629 int data_len = scsi_bufflen(scmd);
1630 struct fusion_context *fusion;
1631 u32 mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
1632 MR_DEFAULT_NVME_PAGE_SIZE);
1634 fusion = instance->ctrl_context;
1636 build_prp = megasas_is_prp_possible(instance, scmd, sge_count);
1642 * Nvme has a very convoluted prp format. One prp is required
1643 * for each page or partial page. Driver need to split up OS sg_list
1644 * entries if it is longer than one page or cross a page
1645 * boundary. Driver also have to insert a PRP list pointer entry as
1646 * the last entry in each physical page of the PRP list.
1648 * NOTE: The first PRP "entry" is actually placed in the first
1649 * SGL entry in the main message as IEEE 64 format. The 2nd
1650 * entry in the main message is the chain element, and the rest
1651 * of the PRP entries are built in the contiguous pcie buffer.
1653 page_mask = mr_nvme_pg_size - 1;
1654 ptr_sgl = (u64 *)cmd->sg_frame;
1655 ptr_sgl_phys = cmd->sg_frame_phys_addr;
1656 memset(ptr_sgl, 0, instance->max_chain_frame_sz);
1658 /* Build chain frame element which holds all prps except first*/
1659 main_chain_element = (struct MPI25_IEEE_SGE_CHAIN64 *)
1660 ((u8 *)sgl_ptr + sizeof(struct MPI25_IEEE_SGE_CHAIN64));
1662 main_chain_element->Address = cpu_to_le64(ptr_sgl_phys);
1663 main_chain_element->NextChainOffset = 0;
1664 main_chain_element->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
1665 IEEE_SGE_FLAGS_SYSTEM_ADDR |
1666 MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP;
1668 /* Build first prp, sge need not to be page aligned*/
1669 ptr_first_sgl = sgl_ptr;
1670 sg_scmd = scsi_sglist(scmd);
1671 sge_addr = sg_dma_address(sg_scmd);
1672 sge_len = sg_dma_len(sg_scmd);
1674 offset = (u32)(sge_addr & page_mask);
1675 first_prp_len = mr_nvme_pg_size - offset;
1677 ptr_first_sgl->Address = cpu_to_le64(sge_addr);
1678 ptr_first_sgl->Length = cpu_to_le32(first_prp_len);
1680 data_len -= first_prp_len;
1682 if (sge_len > first_prp_len) {
1683 sge_addr += first_prp_len;
1684 sge_len -= first_prp_len;
1685 } else if (sge_len == first_prp_len) {
1686 sg_scmd = sg_next(sg_scmd);
1687 sge_addr = sg_dma_address(sg_scmd);
1688 sge_len = sg_dma_len(sg_scmd);
1692 offset = (u32)(sge_addr & page_mask);
1694 /* Put PRP pointer due to page boundary*/
1695 page_mask_result = (uintptr_t)(ptr_sgl + 1) & page_mask;
1696 if (unlikely(!page_mask_result)) {
1697 scmd_printk(KERN_NOTICE,
1698 scmd, "page boundary ptr_sgl: 0x%p\n",
1701 *ptr_sgl = cpu_to_le64(ptr_sgl_phys);
1706 *ptr_sgl = cpu_to_le64(sge_addr);
1711 sge_addr += mr_nvme_pg_size;
1712 sge_len -= mr_nvme_pg_size;
1713 data_len -= mr_nvme_pg_size;
1721 sg_scmd = sg_next(sg_scmd);
1722 sge_addr = sg_dma_address(sg_scmd);
1723 sge_len = sg_dma_len(sg_scmd);
1726 main_chain_element->Length =
1727 cpu_to_le32(num_prp_in_chain * sizeof(u64));
1729 atomic_inc(&instance->prp_sgl);
1734 * megasas_make_sgl_fusion - Prepares 32-bit SGL
1735 * @instance: Adapter soft state
1736 * @scp: SCSI command from the mid-layer
1737 * @sgl_ptr: SGL to be filled in
1738 * @cmd: cmd we are working on
1739 * @sge_count sge count
1743 megasas_make_sgl_fusion(struct megasas_instance *instance,
1744 struct scsi_cmnd *scp,
1745 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
1746 struct megasas_cmd_fusion *cmd, int sge_count)
1748 int i, sg_processed;
1749 struct scatterlist *os_sgl;
1750 struct fusion_context *fusion;
1752 fusion = instance->ctrl_context;
1754 if (fusion->adapter_type >= INVADER_SERIES) {
1755 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
1756 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
1757 sgl_ptr_end->Flags = 0;
1760 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
1761 sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl));
1762 sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl));
1764 if (fusion->adapter_type >= INVADER_SERIES)
1765 if (i == sge_count - 1)
1766 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
1768 sg_processed = i + 1;
1770 if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) &&
1771 (sge_count > fusion->max_sge_in_main_msg)) {
1773 struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
1774 if (fusion->adapter_type >= INVADER_SERIES) {
1775 if ((le16_to_cpu(cmd->io_request->IoFlags) &
1776 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
1777 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
1778 cmd->io_request->ChainOffset =
1780 chain_offset_io_request;
1782 cmd->io_request->ChainOffset = 0;
1784 cmd->io_request->ChainOffset =
1785 fusion->chain_offset_io_request;
1788 /* Prepare chain element */
1789 sg_chain->NextChainOffset = 0;
1790 if (fusion->adapter_type >= INVADER_SERIES)
1791 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
1794 (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
1795 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
1796 sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed)));
1797 sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr);
1800 (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame;
1801 memset(sgl_ptr, 0, instance->max_chain_frame_sz);
1804 atomic_inc(&instance->ieee_sgl);
1808 * megasas_make_sgl - Build Scatter Gather List(SGLs)
1809 * @scp: SCSI command pointer
1810 * @instance: Soft instance of controller
1811 * @cmd: Fusion command pointer
1813 * This function will build sgls based on device type.
1814 * For nvme drives, there is different way of building sgls in nvme native
1815 * format- PRPs(Physical Region Page).
1817 * Returns the number of sg lists actually used, zero if the sg lists
1818 * is NULL, or -ENOMEM if the mapping failed
1821 int megasas_make_sgl(struct megasas_instance *instance, struct scsi_cmnd *scp,
1822 struct megasas_cmd_fusion *cmd)
1825 bool build_prp = false;
1826 struct MPI25_IEEE_SGE_CHAIN64 *sgl_chain64;
1828 sge_count = scsi_dma_map(scp);
1830 if ((sge_count > instance->max_num_sge) || (sge_count <= 0))
1833 sgl_chain64 = (struct MPI25_IEEE_SGE_CHAIN64 *)&cmd->io_request->SGL;
1834 if ((le16_to_cpu(cmd->io_request->IoFlags) &
1835 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) &&
1836 (cmd->pd_interface == NVME_PD))
1837 build_prp = megasas_make_prp_nvme(instance, scp, sgl_chain64,
1841 megasas_make_sgl_fusion(instance, scp, sgl_chain64,
1848 * megasas_set_pd_lba - Sets PD LBA
1850 * @cdb_len: cdb length
1851 * @start_blk: Start block of IO
1853 * Used to set the PD LBA in CDB for FP IOs
1856 megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
1857 struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp,
1858 struct MR_DRV_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
1860 struct MR_LD_RAID *raid;
1862 u64 start_blk = io_info->pdBlock;
1863 u8 *cdb = io_request->CDB.CDB32;
1864 u32 num_blocks = io_info->numBlocks;
1865 u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0;
1867 /* Check if T10 PI (DIF) is enabled for this LD */
1868 ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr);
1869 raid = MR_LdRaidGet(ld, local_map_ptr);
1870 if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) {
1871 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1872 cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD;
1873 cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN;
1875 if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
1876 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32;
1878 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32;
1879 cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL;
1882 cdb[12] = (u8)((start_blk >> 56) & 0xff);
1883 cdb[13] = (u8)((start_blk >> 48) & 0xff);
1884 cdb[14] = (u8)((start_blk >> 40) & 0xff);
1885 cdb[15] = (u8)((start_blk >> 32) & 0xff);
1886 cdb[16] = (u8)((start_blk >> 24) & 0xff);
1887 cdb[17] = (u8)((start_blk >> 16) & 0xff);
1888 cdb[18] = (u8)((start_blk >> 8) & 0xff);
1889 cdb[19] = (u8)(start_blk & 0xff);
1891 /* Logical block reference tag */
1892 io_request->CDB.EEDP32.PrimaryReferenceTag =
1893 cpu_to_be32(ref_tag);
1894 io_request->CDB.EEDP32.PrimaryApplicationTagMask = cpu_to_be16(0xffff);
1895 io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */
1897 /* Transfer length */
1898 cdb[28] = (u8)((num_blocks >> 24) & 0xff);
1899 cdb[29] = (u8)((num_blocks >> 16) & 0xff);
1900 cdb[30] = (u8)((num_blocks >> 8) & 0xff);
1901 cdb[31] = (u8)(num_blocks & 0xff);
1903 /* set SCSI IO EEDPFlags */
1904 if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) {
1905 io_request->EEDPFlags = cpu_to_le16(
1906 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
1907 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
1908 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
1909 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
1910 MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE |
1911 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD);
1913 io_request->EEDPFlags = cpu_to_le16(
1914 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
1915 MPI2_SCSIIO_EEDPFLAGS_INSERT_OP);
1917 io_request->Control |= cpu_to_le32((0x4 << 26));
1918 io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size);
1920 /* Some drives don't support 16/12 byte CDB's, convert to 10 */
1921 if (((cdb_len == 12) || (cdb_len == 16)) &&
1922 (start_blk <= 0xffffffff)) {
1923 if (cdb_len == 16) {
1924 opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
1929 opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
1935 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1942 /* Transfer length */
1943 cdb[8] = (u8)(num_blocks & 0xff);
1944 cdb[7] = (u8)((num_blocks >> 8) & 0xff);
1946 io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */
1948 } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) {
1949 /* Convert to 16 byte CDB for large LBA's */
1952 opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16;
1957 cdb[0] == READ_10 ? READ_16 : WRITE_16;
1964 cdb[0] == READ_12 ? READ_16 : WRITE_16;
1971 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1978 /* Transfer length */
1979 cdb[13] = (u8)(num_blocks & 0xff);
1980 cdb[12] = (u8)((num_blocks >> 8) & 0xff);
1981 cdb[11] = (u8)((num_blocks >> 16) & 0xff);
1982 cdb[10] = (u8)((num_blocks >> 24) & 0xff);
1984 io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */
1988 /* Normal case, just load LBA here */
1992 u8 val = cdb[1] & 0xE0;
1993 cdb[3] = (u8)(start_blk & 0xff);
1994 cdb[2] = (u8)((start_blk >> 8) & 0xff);
1995 cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f);
1999 cdb[5] = (u8)(start_blk & 0xff);
2000 cdb[4] = (u8)((start_blk >> 8) & 0xff);
2001 cdb[3] = (u8)((start_blk >> 16) & 0xff);
2002 cdb[2] = (u8)((start_blk >> 24) & 0xff);
2005 cdb[5] = (u8)(start_blk & 0xff);
2006 cdb[4] = (u8)((start_blk >> 8) & 0xff);
2007 cdb[3] = (u8)((start_blk >> 16) & 0xff);
2008 cdb[2] = (u8)((start_blk >> 24) & 0xff);
2011 cdb[9] = (u8)(start_blk & 0xff);
2012 cdb[8] = (u8)((start_blk >> 8) & 0xff);
2013 cdb[7] = (u8)((start_blk >> 16) & 0xff);
2014 cdb[6] = (u8)((start_blk >> 24) & 0xff);
2015 cdb[5] = (u8)((start_blk >> 32) & 0xff);
2016 cdb[4] = (u8)((start_blk >> 40) & 0xff);
2017 cdb[3] = (u8)((start_blk >> 48) & 0xff);
2018 cdb[2] = (u8)((start_blk >> 56) & 0xff);
2025 * megasas_stream_detect - stream detection on read and and write IOs
2026 * @instance: Adapter soft state
2027 * @cmd: Command to be prepared
2028 * @io_info: IO Request info
2032 /** stream detection on read and and write IOs */
2033 static void megasas_stream_detect(struct megasas_instance *instance,
2034 struct megasas_cmd_fusion *cmd,
2035 struct IO_REQUEST_INFO *io_info)
2037 struct fusion_context *fusion = instance->ctrl_context;
2038 u32 device_id = io_info->ldTgtId;
2039 struct LD_STREAM_DETECT *current_ld_sd
2040 = fusion->stream_detect_by_ld[device_id];
2041 u32 *track_stream = ¤t_ld_sd->mru_bit_map, stream_num;
2042 u32 shifted_values, unshifted_values;
2043 u32 index_value_mask, shifted_values_mask;
2045 bool is_read_ahead = false;
2046 struct STREAM_DETECT *current_sd;
2047 /* find possible stream */
2048 for (i = 0; i < MAX_STREAMS_TRACKED; ++i) {
2049 stream_num = (*track_stream >>
2050 (i * BITS_PER_INDEX_STREAM)) &
2052 current_sd = ¤t_ld_sd->stream_track[stream_num];
2053 /* if we found a stream, update the raid
2054 * context and also update the mruBitMap
2056 /* boundary condition */
2057 if ((current_sd->next_seq_lba) &&
2058 (io_info->ldStartBlock >= current_sd->next_seq_lba) &&
2059 (io_info->ldStartBlock <= (current_sd->next_seq_lba + 32)) &&
2060 (current_sd->is_read == io_info->isRead)) {
2062 if ((io_info->ldStartBlock != current_sd->next_seq_lba) &&
2063 ((!io_info->isRead) || (!is_read_ahead)))
2065 * Once the API availible we need to change this.
2066 * At this point we are not allowing any gap
2070 SET_STREAM_DETECTED(cmd->io_request->RaidContext.raid_context_g35);
2071 current_sd->next_seq_lba =
2072 io_info->ldStartBlock + io_info->numBlocks;
2074 * update the mruBitMap LRU
2076 shifted_values_mask =
2077 (1 << i * BITS_PER_INDEX_STREAM) - 1;
2078 shifted_values = ((*track_stream & shifted_values_mask)
2079 << BITS_PER_INDEX_STREAM);
2081 STREAM_MASK << i * BITS_PER_INDEX_STREAM;
2083 *track_stream & ~(shifted_values_mask |
2086 unshifted_values | shifted_values | stream_num;
2091 * if we did not find any stream, create a new one
2092 * from the least recently used
2094 stream_num = (*track_stream >>
2095 ((MAX_STREAMS_TRACKED - 1) * BITS_PER_INDEX_STREAM)) &
2097 current_sd = ¤t_ld_sd->stream_track[stream_num];
2098 current_sd->is_read = io_info->isRead;
2099 current_sd->next_seq_lba = io_info->ldStartBlock + io_info->numBlocks;
2100 *track_stream = (((*track_stream & ZERO_LAST_STREAM) << 4) | stream_num);
2105 * megasas_set_raidflag_cpu_affinity - This function sets the cpu
2106 * affinity (cpu of the controller) and raid_flags in the raid context
2109 * @praid_context: IO RAID context
2110 * @raid: LD raid map
2111 * @fp_possible: Is fast path possible?
2112 * @is_read: Is read IO?
2116 megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION *praid_context,
2117 struct MR_LD_RAID *raid, bool fp_possible,
2118 u8 is_read, u32 scsi_buff_len)
2120 u8 cpu_sel = MR_RAID_CTX_CPUSEL_0;
2121 struct RAID_CONTEXT_G35 *rctx_g35;
2123 rctx_g35 = &praid_context->raid_context_g35;
2126 if ((raid->cpuAffinity.pdRead.cpu0) &&
2127 (raid->cpuAffinity.pdRead.cpu1))
2128 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2129 else if (raid->cpuAffinity.pdRead.cpu1)
2130 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2132 if ((raid->cpuAffinity.pdWrite.cpu0) &&
2133 (raid->cpuAffinity.pdWrite.cpu1))
2134 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2135 else if (raid->cpuAffinity.pdWrite.cpu1)
2136 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2137 /* Fast path cache by pass capable R0/R1 VD */
2138 if ((raid->level <= 1) &&
2139 (raid->capability.fp_cache_bypass_capable)) {
2140 rctx_g35->routing_flags |=
2141 (1 << MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT);
2142 rctx_g35->raid_flags =
2143 (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
2144 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2149 if ((raid->cpuAffinity.ldRead.cpu0) &&
2150 (raid->cpuAffinity.ldRead.cpu1))
2151 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2152 else if (raid->cpuAffinity.ldRead.cpu1)
2153 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2155 if ((raid->cpuAffinity.ldWrite.cpu0) &&
2156 (raid->cpuAffinity.ldWrite.cpu1))
2157 cpu_sel = MR_RAID_CTX_CPUSEL_FCFS;
2158 else if (raid->cpuAffinity.ldWrite.cpu1)
2159 cpu_sel = MR_RAID_CTX_CPUSEL_1;
2161 if (is_stream_detected(rctx_g35) &&
2162 ((raid->level == 5) || (raid->level == 6)) &&
2163 (raid->writeMode == MR_RL_WRITE_THROUGH_MODE) &&
2164 (cpu_sel == MR_RAID_CTX_CPUSEL_FCFS))
2165 cpu_sel = MR_RAID_CTX_CPUSEL_0;
2169 rctx_g35->routing_flags |=
2170 (cpu_sel << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2172 /* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2173 * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS.
2174 * IO Subtype is not bitmap.
2176 if ((raid->level == 1) && (!is_read)) {
2177 if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
2178 praid_context->raid_context_g35.raid_flags =
2179 (MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2180 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
2185 * megasas_build_ldio_fusion - Prepares IOs to devices
2186 * @instance: Adapter soft state
2187 * @scp: SCSI command
2188 * @cmd: Command to be prepared
2190 * Prepares the io_request and chain elements (sg_frame) for IO
2191 * The IO can be for PD (Fast Path) or LD
2194 megasas_build_ldio_fusion(struct megasas_instance *instance,
2195 struct scsi_cmnd *scp,
2196 struct megasas_cmd_fusion *cmd)
2200 u32 start_lba_lo, start_lba_hi, device_id, datalength = 0;
2202 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
2203 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
2204 struct IO_REQUEST_INFO io_info;
2205 struct fusion_context *fusion;
2206 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
2208 unsigned long spinlock_flags;
2209 union RAID_CONTEXT_UNION *praid_context;
2210 struct MR_LD_RAID *raid = NULL;
2211 struct MR_PRIV_DEVICE *mrdev_priv;
2213 device_id = MEGASAS_DEV_INDEX(scp);
2215 fusion = instance->ctrl_context;
2217 io_request = cmd->io_request;
2218 io_request->RaidContext.raid_context.virtual_disk_tgt_id =
2219 cpu_to_le16(device_id);
2220 io_request->RaidContext.raid_context.status = 0;
2221 io_request->RaidContext.raid_context.ex_status = 0;
2223 req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc;
2227 fp_possible = false;
2230 * 6-byte READ(0x08) or WRITE(0x0A) cdb
2232 if (scp->cmd_len == 6) {
2233 datalength = (u32) scp->cmnd[4];
2234 start_lba_lo = ((u32) scp->cmnd[1] << 16) |
2235 ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3];
2237 start_lba_lo &= 0x1FFFFF;
2241 * 10-byte READ(0x28) or WRITE(0x2A) cdb
2243 else if (scp->cmd_len == 10) {
2244 datalength = (u32) scp->cmnd[8] |
2245 ((u32) scp->cmnd[7] << 8);
2246 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
2247 ((u32) scp->cmnd[3] << 16) |
2248 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2252 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
2254 else if (scp->cmd_len == 12) {
2255 datalength = ((u32) scp->cmnd[6] << 24) |
2256 ((u32) scp->cmnd[7] << 16) |
2257 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
2258 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
2259 ((u32) scp->cmnd[3] << 16) |
2260 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2264 * 16-byte READ(0x88) or WRITE(0x8A) cdb
2266 else if (scp->cmd_len == 16) {
2267 datalength = ((u32) scp->cmnd[10] << 24) |
2268 ((u32) scp->cmnd[11] << 16) |
2269 ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13];
2270 start_lba_lo = ((u32) scp->cmnd[6] << 24) |
2271 ((u32) scp->cmnd[7] << 16) |
2272 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
2274 start_lba_hi = ((u32) scp->cmnd[2] << 24) |
2275 ((u32) scp->cmnd[3] << 16) |
2276 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
2279 memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO));
2280 io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
2281 io_info.numBlocks = datalength;
2282 io_info.ldTgtId = device_id;
2283 io_info.r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2284 scsi_buff_len = scsi_bufflen(scp);
2285 io_request->DataLength = cpu_to_le32(scsi_buff_len);
2287 if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
2290 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2291 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
2293 if (ld < instance->fw_supported_vd_count)
2294 raid = MR_LdRaidGet(ld, local_map_ptr);
2296 if (!raid || (!fusion->fast_path_io)) {
2297 io_request->RaidContext.raid_context.reg_lock_flags = 0;
2298 fp_possible = false;
2300 if (MR_BuildRaidContext(instance, &io_info,
2301 &io_request->RaidContext.raid_context,
2302 local_map_ptr, &raidLUN))
2303 fp_possible = (io_info.fpOkForIo > 0) ? true : false;
2306 /* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU
2307 id by default, not CPU group id, otherwise all MSI-X queues won't
2309 cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
2310 raw_smp_processor_id() % instance->msix_vectors : 0;
2312 praid_context = &io_request->RaidContext;
2314 if (instance->is_ventura) {
2315 spin_lock_irqsave(&instance->stream_lock, spinlock_flags);
2316 megasas_stream_detect(instance, cmd, &io_info);
2317 spin_unlock_irqrestore(&instance->stream_lock, spinlock_flags);
2318 /* In ventura if stream detected for a read and it is read ahead
2319 * capable make this IO as LDIO
2321 if (is_stream_detected(&io_request->RaidContext.raid_context_g35) &&
2322 io_info.isRead && io_info.ra_capable)
2323 fp_possible = false;
2325 /* FP for Optimal raid level 1.
2326 * All large RAID-1 writes (> 32 KiB, both WT and WB modes)
2327 * are built by the driver as LD I/Os.
2328 * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os
2329 * (there is never a reason to process these as buffered writes)
2330 * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os
2331 * with the SLD bit asserted.
2333 if (io_info.r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
2334 mrdev_priv = scp->device->hostdata;
2336 if (atomic_inc_return(&instance->fw_outstanding) >
2337 (instance->host->can_queue)) {
2338 fp_possible = false;
2339 atomic_dec(&instance->fw_outstanding);
2340 } else if ((scsi_buff_len > MR_LARGE_IO_MIN_SIZE) ||
2341 (atomic_dec_if_positive(&mrdev_priv->r1_ldio_hint) > 0)) {
2342 fp_possible = false;
2343 atomic_dec(&instance->fw_outstanding);
2344 if (scsi_buff_len > MR_LARGE_IO_MIN_SIZE)
2345 atomic_set(&mrdev_priv->r1_ldio_hint,
2346 instance->r1_ldio_hint_default);
2350 /* If raid is NULL, set CPU affinity to default CPU0 */
2352 megasas_set_raidflag_cpu_affinity(praid_context,
2353 raid, fp_possible, io_info.isRead,
2356 praid_context->raid_context_g35.routing_flags |=
2357 (MR_RAID_CTX_CPUSEL_0 << MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT);
2361 megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
2362 local_map_ptr, start_lba_lo);
2363 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2364 cmd->request_desc->SCSIIO.RequestFlags =
2365 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
2366 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2367 if (fusion->adapter_type == INVADER_SERIES) {
2368 if (io_request->RaidContext.raid_context.reg_lock_flags ==
2370 cmd->request_desc->SCSIIO.RequestFlags =
2371 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
2372 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2373 io_request->RaidContext.raid_context.type
2375 io_request->RaidContext.raid_context.nseg = 0x1;
2376 io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
2377 io_request->RaidContext.raid_context.reg_lock_flags |=
2378 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
2379 MR_RL_FLAGS_SEQ_NUM_ENABLE);
2380 } else if (instance->is_ventura) {
2381 io_request->RaidContext.raid_context_g35.nseg_type |=
2382 (1 << RAID_CONTEXT_NSEG_SHIFT);
2383 io_request->RaidContext.raid_context_g35.nseg_type |=
2384 (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2385 io_request->RaidContext.raid_context_g35.routing_flags |=
2386 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2387 io_request->IoFlags |=
2388 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
2390 if (fusion->load_balance_info &&
2391 (fusion->load_balance_info[device_id].loadBalanceFlag) &&
2394 get_updated_dev_handle(instance,
2395 &fusion->load_balance_info[device_id],
2396 &io_info, local_map_ptr);
2397 scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
2398 cmd->pd_r1_lb = io_info.pd_after_lb;
2399 if (instance->is_ventura)
2400 io_request->RaidContext.raid_context_g35.span_arm
2403 io_request->RaidContext.raid_context.span_arm
2407 scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
2409 if (instance->is_ventura)
2410 cmd->r1_alt_dev_handle = io_info.r1_alt_dev_handle;
2412 cmd->r1_alt_dev_handle = MR_DEVHANDLE_INVALID;
2414 if ((raidLUN[0] == 1) &&
2415 (local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].validHandles > 1)) {
2416 instance->dev_handle = !(instance->dev_handle);
2418 local_map_ptr->raidMap.devHndlInfo[io_info.pd_after_lb].devHandle[instance->dev_handle];
2421 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
2422 io_request->DevHandle = io_info.devHandle;
2423 cmd->pd_interface = io_info.pd_interface;
2424 /* populate the LUN field */
2425 memcpy(io_request->LUN, raidLUN, 8);
2427 io_request->RaidContext.raid_context.timeout_value =
2428 cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec);
2429 cmd->request_desc->SCSIIO.RequestFlags =
2430 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
2431 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2432 if (fusion->adapter_type == INVADER_SERIES) {
2433 if (io_info.do_fp_rlbypass ||
2434 (io_request->RaidContext.raid_context.reg_lock_flags
2435 == REGION_TYPE_UNUSED))
2436 cmd->request_desc->SCSIIO.RequestFlags =
2437 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
2438 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2439 io_request->RaidContext.raid_context.type
2441 io_request->RaidContext.raid_context.reg_lock_flags |=
2442 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
2443 MR_RL_FLAGS_SEQ_NUM_ENABLE);
2444 io_request->RaidContext.raid_context.nseg = 0x1;
2445 } else if (instance->is_ventura) {
2446 io_request->RaidContext.raid_context_g35.routing_flags |=
2447 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2448 io_request->RaidContext.raid_context_g35.nseg_type |=
2449 (1 << RAID_CONTEXT_NSEG_SHIFT);
2450 io_request->RaidContext.raid_context_g35.nseg_type |=
2451 (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2453 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
2454 io_request->DevHandle = cpu_to_le16(device_id);
2460 * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk
2461 * @instance: Adapter soft state
2462 * @scp: SCSI command
2463 * @cmd: Command to be prepared
2465 * Prepares the io_request frame for non-rw io cmds for vd.
2467 static void megasas_build_ld_nonrw_fusion(struct megasas_instance *instance,
2468 struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd)
2471 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
2473 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
2474 struct fusion_context *fusion = instance->ctrl_context;
2478 struct MR_LD_RAID *raid;
2479 struct RAID_CONTEXT *pRAID_Context;
2482 io_request = cmd->io_request;
2483 device_id = MEGASAS_DEV_INDEX(scmd);
2484 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2485 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2486 /* get RAID_Context pointer */
2487 pRAID_Context = &io_request->RaidContext.raid_context;
2488 /* Check with FW team */
2489 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2490 pRAID_Context->reg_lock_row_lba = 0;
2491 pRAID_Context->reg_lock_length = 0;
2493 if (fusion->fast_path_io && (
2494 device_id < instance->fw_supported_vd_count)) {
2496 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
2497 if (ld >= instance->fw_supported_vd_count)
2500 raid = MR_LdRaidGet(ld, local_map_ptr);
2501 if (!(raid->capability.fpNonRWCapable))
2508 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
2509 io_request->DevHandle = cpu_to_le16(device_id);
2510 io_request->LUN[1] = scmd->device->lun;
2511 pRAID_Context->timeout_value =
2512 cpu_to_le16 (scmd->request->timeout / HZ);
2513 cmd->request_desc->SCSIIO.RequestFlags =
2514 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
2515 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2518 /* set RAID context values */
2519 pRAID_Context->config_seq_num = raid->seqNum;
2520 if (!instance->is_ventura)
2521 pRAID_Context->reg_lock_flags = REGION_TYPE_SHARED_READ;
2522 pRAID_Context->timeout_value =
2523 cpu_to_le16(raid->fpIoTimeoutForLd);
2525 /* get the DevHandle for the PD (since this is
2526 fpNonRWCapable, this is a single disk RAID0) */
2528 arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr);
2529 pd = MR_ArPdGet(arRef, physArm, local_map_ptr);
2530 devHandle = MR_PdDevHandleGet(pd, local_map_ptr);
2532 /* build request descriptor */
2533 cmd->request_desc->SCSIIO.RequestFlags =
2534 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO <<
2535 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2536 cmd->request_desc->SCSIIO.DevHandle = devHandle;
2538 /* populate the LUN field */
2539 memcpy(io_request->LUN, raid->LUN, 8);
2541 /* build the raidScsiIO structure */
2542 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2543 io_request->DevHandle = devHandle;
2548 * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd
2549 * @instance: Adapter soft state
2550 * @scp: SCSI command
2551 * @cmd: Command to be prepared
2552 * @fp_possible: parameter to detect fast path or firmware path io.
2554 * Prepares the io_request frame for rw/non-rw io cmds for syspds
2557 megasas_build_syspd_fusion(struct megasas_instance *instance,
2558 struct scsi_cmnd *scmd, struct megasas_cmd_fusion *cmd,
2562 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
2564 u16 os_timeout_value;
2566 struct MR_DRV_RAID_MAP_ALL *local_map_ptr;
2567 struct RAID_CONTEXT *pRAID_Context;
2568 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
2569 struct MR_PRIV_DEVICE *mr_device_priv_data;
2570 struct fusion_context *fusion = instance->ctrl_context;
2571 pd_sync = (void *)fusion->pd_seq_sync[(instance->pd_seq_map_id - 1) & 1];
2573 device_id = MEGASAS_DEV_INDEX(scmd);
2574 pd_index = MEGASAS_PD_INDEX(scmd);
2575 os_timeout_value = scmd->request->timeout / HZ;
2576 mr_device_priv_data = scmd->device->hostdata;
2577 cmd->pd_interface = mr_device_priv_data->interface_type;
2579 io_request = cmd->io_request;
2580 /* get RAID_Context pointer */
2581 pRAID_Context = &io_request->RaidContext.raid_context;
2582 pRAID_Context->reg_lock_flags = 0;
2583 pRAID_Context->reg_lock_row_lba = 0;
2584 pRAID_Context->reg_lock_length = 0;
2585 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
2586 io_request->LUN[1] = scmd->device->lun;
2587 pRAID_Context->raid_flags = MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
2588 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
2590 /* If FW supports PD sequence number */
2591 if (instance->use_seqnum_jbod_fp &&
2592 instance->pd_list[pd_index].driveType == TYPE_DISK) {
2593 /* TgtId must be incremented by 255 as jbod seq number is index
2596 /* More than 256 PD/JBOD support for Ventura */
2597 if (instance->support_morethan256jbod)
2598 pRAID_Context->virtual_disk_tgt_id =
2599 pd_sync->seq[pd_index].pd_target_id;
2601 pRAID_Context->virtual_disk_tgt_id =
2602 cpu_to_le16(device_id + (MAX_PHYSICAL_DEVICES - 1));
2603 pRAID_Context->config_seq_num = pd_sync->seq[pd_index].seqNum;
2604 io_request->DevHandle = pd_sync->seq[pd_index].devHandle;
2605 if (instance->is_ventura) {
2606 io_request->RaidContext.raid_context_g35.routing_flags |=
2607 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT);
2608 io_request->RaidContext.raid_context_g35.nseg_type |=
2609 (1 << RAID_CONTEXT_NSEG_SHIFT);
2610 io_request->RaidContext.raid_context_g35.nseg_type |=
2611 (MPI2_TYPE_CUDA << RAID_CONTEXT_TYPE_SHIFT);
2613 pRAID_Context->type = MPI2_TYPE_CUDA;
2614 pRAID_Context->nseg = 0x1;
2615 pRAID_Context->reg_lock_flags |=
2616 (MR_RL_FLAGS_SEQ_NUM_ENABLE|MR_RL_FLAGS_GRANT_DESTINATION_CUDA);
2618 } else if (fusion->fast_path_io) {
2619 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2620 pRAID_Context->config_seq_num = 0;
2621 local_map_ptr = fusion->ld_drv_map[(instance->map_id & 1)];
2622 io_request->DevHandle =
2623 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
2625 /* Want to send all IO via FW path */
2626 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2627 pRAID_Context->config_seq_num = 0;
2628 io_request->DevHandle = cpu_to_le16(0xFFFF);
2631 cmd->request_desc->SCSIIO.DevHandle = io_request->DevHandle;
2632 cmd->request_desc->SCSIIO.MSIxIndex =
2633 instance->msix_vectors ?
2634 (raw_smp_processor_id() % instance->msix_vectors) : 0;
2638 /* system pd firmware path */
2639 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
2640 cmd->request_desc->SCSIIO.RequestFlags =
2641 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
2642 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2643 pRAID_Context->timeout_value = cpu_to_le16(os_timeout_value);
2644 pRAID_Context->virtual_disk_tgt_id = cpu_to_le16(device_id);
2646 /* system pd Fast Path */
2647 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
2648 timeout_limit = (scmd->device->type == TYPE_DISK) ?
2650 pRAID_Context->timeout_value =
2651 cpu_to_le16((os_timeout_value > timeout_limit) ?
2652 timeout_limit : os_timeout_value);
2653 if (fusion->adapter_type >= INVADER_SERIES)
2654 io_request->IoFlags |=
2655 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
2657 cmd->request_desc->SCSIIO.RequestFlags =
2658 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO <<
2659 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2664 * megasas_build_io_fusion - Prepares IOs to devices
2665 * @instance: Adapter soft state
2666 * @scp: SCSI command
2667 * @cmd: Command to be prepared
2669 * Invokes helper functions to prepare request frames
2670 * and sets flags appropriate for IO/Non-IO cmd
2673 megasas_build_io_fusion(struct megasas_instance *instance,
2674 struct scsi_cmnd *scp,
2675 struct megasas_cmd_fusion *cmd)
2679 struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
2680 struct MR_PRIV_DEVICE *mr_device_priv_data;
2681 mr_device_priv_data = scp->device->hostdata;
2683 /* Zero out some fields so they don't get reused */
2684 memset(io_request->LUN, 0x0, 8);
2685 io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
2686 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
2687 io_request->EEDPFlags = 0;
2688 io_request->Control = 0;
2689 io_request->EEDPBlockSize = 0;
2690 io_request->ChainOffset = 0;
2691 io_request->RaidContext.raid_context.raid_flags = 0;
2692 io_request->RaidContext.raid_context.type = 0;
2693 io_request->RaidContext.raid_context.nseg = 0;
2695 memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
2697 * Just the CDB length,rest of the Flags are zero
2698 * This will be modified for FP in build_ldio_fusion
2700 io_request->IoFlags = cpu_to_le16(scp->cmd_len);
2702 switch (cmd_type = megasas_cmd_type(scp)) {
2703 case READ_WRITE_LDIO:
2704 megasas_build_ldio_fusion(instance, scp, cmd);
2706 case NON_READ_WRITE_LDIO:
2707 megasas_build_ld_nonrw_fusion(instance, scp, cmd);
2709 case READ_WRITE_SYSPDIO:
2710 megasas_build_syspd_fusion(instance, scp, cmd, true);
2712 case NON_READ_WRITE_SYSPDIO:
2713 if (instance->secure_jbod_support ||
2714 mr_device_priv_data->is_tm_capable)
2715 megasas_build_syspd_fusion(instance, scp, cmd, false);
2717 megasas_build_syspd_fusion(instance, scp, cmd, true);
2727 sge_count = megasas_make_sgl(instance, scp, cmd);
2729 if (sge_count > instance->max_num_sge || (sge_count < 0)) {
2730 dev_err(&instance->pdev->dev,
2731 "%s %d sge_count (%d) is out of range. Range is: 0-%d\n",
2732 __func__, __LINE__, sge_count, instance->max_num_sge);
2736 if (instance->is_ventura) {
2737 set_num_sge(&io_request->RaidContext.raid_context_g35, sge_count);
2738 cpu_to_le16s(&io_request->RaidContext.raid_context_g35.routing_flags);
2739 cpu_to_le16s(&io_request->RaidContext.raid_context_g35.nseg_type);
2741 /* numSGE store lower 8 bit of sge_count.
2742 * numSGEExt store higher 8 bit of sge_count
2744 io_request->RaidContext.raid_context.num_sge = sge_count;
2745 io_request->RaidContext.raid_context.num_sge_ext =
2746 (u8)(sge_count >> 8);
2749 io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING);
2751 if (scp->sc_data_direction == PCI_DMA_TODEVICE)
2752 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE);
2753 else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
2754 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ);
2756 io_request->SGLOffset0 =
2757 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4;
2759 io_request->SenseBufferLowAddress = cpu_to_le32(cmd->sense_phys_addr);
2760 io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
2763 scp->SCp.ptr = (char *)cmd;
2768 static union MEGASAS_REQUEST_DESCRIPTOR_UNION *
2769 megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
2772 struct fusion_context *fusion;
2774 fusion = instance->ctrl_context;
2775 p = fusion->req_frames_desc +
2776 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) * index;
2778 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
2782 /* megasas_prepate_secondRaid1_IO
2783 * It prepares the raid 1 second IO
2785 void megasas_prepare_secondRaid1_IO(struct megasas_instance *instance,
2786 struct megasas_cmd_fusion *cmd,
2787 struct megasas_cmd_fusion *r1_cmd)
2789 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc, *req_desc2 = NULL;
2790 struct fusion_context *fusion;
2791 fusion = instance->ctrl_context;
2792 req_desc = cmd->request_desc;
2793 /* copy the io request frame as well as 8 SGEs data for r1 command*/
2794 memcpy(r1_cmd->io_request, cmd->io_request,
2795 (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST)));
2796 memcpy(&r1_cmd->io_request->SGL, &cmd->io_request->SGL,
2797 (fusion->max_sge_in_main_msg * sizeof(union MPI2_SGE_IO_UNION)));
2798 /*sense buffer is different for r1 command*/
2799 r1_cmd->io_request->SenseBufferLowAddress =
2800 cpu_to_le32(r1_cmd->sense_phys_addr);
2801 r1_cmd->scmd = cmd->scmd;
2802 req_desc2 = megasas_get_request_descriptor(instance,
2803 (r1_cmd->index - 1));
2804 req_desc2->Words = 0;
2805 r1_cmd->request_desc = req_desc2;
2806 req_desc2->SCSIIO.SMID = cpu_to_le16(r1_cmd->index);
2807 req_desc2->SCSIIO.RequestFlags = req_desc->SCSIIO.RequestFlags;
2808 r1_cmd->request_desc->SCSIIO.DevHandle = cmd->r1_alt_dev_handle;
2809 r1_cmd->io_request->DevHandle = cmd->r1_alt_dev_handle;
2810 r1_cmd->r1_alt_dev_handle = cmd->io_request->DevHandle;
2811 cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
2812 cpu_to_le16(r1_cmd->index);
2813 r1_cmd->io_request->RaidContext.raid_context_g35.smid.peer_smid =
2814 cpu_to_le16(cmd->index);
2815 /*MSIxIndex of both commands request descriptors should be same*/
2816 r1_cmd->request_desc->SCSIIO.MSIxIndex =
2817 cmd->request_desc->SCSIIO.MSIxIndex;
2818 /*span arm is different for r1 cmd*/
2819 r1_cmd->io_request->RaidContext.raid_context_g35.span_arm =
2820 cmd->io_request->RaidContext.raid_context_g35.span_arm + 1;
2824 * megasas_build_and_issue_cmd_fusion -Main routine for building and
2825 * issuing non IOCTL cmd
2826 * @instance: Adapter soft state
2827 * @scmd: pointer to scsi cmd from OS
2830 megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
2831 struct scsi_cmnd *scmd)
2833 struct megasas_cmd_fusion *cmd, *r1_cmd = NULL;
2834 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
2836 struct fusion_context *fusion;
2838 fusion = instance->ctrl_context;
2840 if ((megasas_cmd_type(scmd) == READ_WRITE_LDIO) &&
2841 instance->ldio_threshold &&
2842 (atomic_inc_return(&instance->ldio_outstanding) >
2843 instance->ldio_threshold)) {
2844 atomic_dec(&instance->ldio_outstanding);
2845 return SCSI_MLQUEUE_DEVICE_BUSY;
2848 if (atomic_inc_return(&instance->fw_outstanding) >
2849 instance->host->can_queue) {
2850 atomic_dec(&instance->fw_outstanding);
2851 return SCSI_MLQUEUE_HOST_BUSY;
2854 cmd = megasas_get_cmd_fusion(instance, scmd->request->tag);
2857 atomic_dec(&instance->fw_outstanding);
2858 return SCSI_MLQUEUE_HOST_BUSY;
2863 req_desc = megasas_get_request_descriptor(instance, index-1);
2865 req_desc->Words = 0;
2866 cmd->request_desc = req_desc;
2868 if (megasas_build_io_fusion(instance, scmd, cmd)) {
2869 megasas_return_cmd_fusion(instance, cmd);
2870 dev_err(&instance->pdev->dev, "Error building command\n");
2871 cmd->request_desc = NULL;
2872 atomic_dec(&instance->fw_outstanding);
2873 return SCSI_MLQUEUE_HOST_BUSY;
2876 req_desc = cmd->request_desc;
2877 req_desc->SCSIIO.SMID = cpu_to_le16(index);
2879 if (cmd->io_request->ChainOffset != 0 &&
2880 cmd->io_request->ChainOffset != 0xF)
2881 dev_err(&instance->pdev->dev, "The chain offset value is not "
2882 "correct : %x\n", cmd->io_request->ChainOffset);
2884 * if it is raid 1/10 fp write capable.
2885 * try to get second command from pool and construct it.
2886 * From FW, it has confirmed that lba values of two PDs
2887 * corresponds to single R1/10 LD are always same
2890 /* driver side count always should be less than max_fw_cmds
2891 * to get new command
2893 if (cmd->r1_alt_dev_handle != MR_DEVHANDLE_INVALID) {
2894 r1_cmd = megasas_get_cmd_fusion(instance,
2895 (scmd->request->tag + instance->max_fw_cmds));
2896 megasas_prepare_secondRaid1_IO(instance, cmd, r1_cmd);
2901 * Issue the command to the FW
2904 megasas_fire_cmd_fusion(instance, req_desc);
2907 megasas_fire_cmd_fusion(instance, r1_cmd->request_desc);
2914 * megasas_complete_r1_command -
2915 * completes R1 FP write commands which has valid peer smid
2916 * @instance: Adapter soft state
2917 * @cmd_fusion: MPT command frame
2921 megasas_complete_r1_command(struct megasas_instance *instance,
2922 struct megasas_cmd_fusion *cmd)
2924 u8 *sense, status, ex_status;
2927 struct fusion_context *fusion;
2928 struct megasas_cmd_fusion *r1_cmd = NULL;
2929 struct scsi_cmnd *scmd_local = NULL;
2930 struct RAID_CONTEXT_G35 *rctx_g35;
2932 rctx_g35 = &cmd->io_request->RaidContext.raid_context_g35;
2933 fusion = instance->ctrl_context;
2934 peer_smid = le16_to_cpu(rctx_g35->smid.peer_smid);
2936 r1_cmd = fusion->cmd_list[peer_smid - 1];
2937 scmd_local = cmd->scmd;
2938 status = rctx_g35->status;
2939 ex_status = rctx_g35->ex_status;
2940 data_length = cmd->io_request->DataLength;
2943 cmd->cmd_completed = true;
2945 /* Check if peer command is completed or not*/
2946 if (r1_cmd->cmd_completed) {
2947 rctx_g35 = &r1_cmd->io_request->RaidContext.raid_context_g35;
2948 if (rctx_g35->status != MFI_STAT_OK) {
2949 status = rctx_g35->status;
2950 ex_status = rctx_g35->ex_status;
2951 data_length = r1_cmd->io_request->DataLength;
2952 sense = r1_cmd->sense;
2955 megasas_return_cmd_fusion(instance, r1_cmd);
2956 map_cmd_status(fusion, scmd_local, status, ex_status,
2957 le32_to_cpu(data_length), sense);
2958 if (instance->ldio_threshold &&
2959 megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
2960 atomic_dec(&instance->ldio_outstanding);
2961 scmd_local->SCp.ptr = NULL;
2962 megasas_return_cmd_fusion(instance, cmd);
2963 scsi_dma_unmap(scmd_local);
2964 scmd_local->scsi_done(scmd_local);
2969 * complete_cmd_fusion - Completes command
2970 * @instance: Adapter soft state
2971 * Completes all commands that is in reply descriptor queue
2974 complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
2976 union MPI2_REPLY_DESCRIPTORS_UNION *desc;
2977 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
2978 struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
2979 struct fusion_context *fusion;
2980 struct megasas_cmd *cmd_mfi;
2981 struct megasas_cmd_fusion *cmd_fusion;
2982 u16 smid, num_completed;
2983 u8 reply_descript_type, *sense, status, extStatus;
2984 u32 device_id, data_length;
2985 union desc_value d_val;
2986 struct LD_LOAD_BALANCE_INFO *lbinfo;
2987 int threshold_reply_count = 0;
2988 struct scsi_cmnd *scmd_local = NULL;
2989 struct MR_TASK_MANAGE_REQUEST *mr_tm_req;
2990 struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_tm_req;
2992 fusion = instance->ctrl_context;
2994 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR)
2997 desc = fusion->reply_frames_desc[MSIxIndex] +
2998 fusion->last_reply_idx[MSIxIndex];
3000 reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
3002 d_val.word = desc->Words;
3004 reply_descript_type = reply_desc->ReplyFlags &
3005 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
3007 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
3012 while (d_val.u.low != cpu_to_le32(UINT_MAX) &&
3013 d_val.u.high != cpu_to_le32(UINT_MAX)) {
3015 smid = le16_to_cpu(reply_desc->SMID);
3016 cmd_fusion = fusion->cmd_list[smid - 1];
3017 scsi_io_req = (struct MPI2_RAID_SCSI_IO_REQUEST *)
3018 cmd_fusion->io_request;
3020 scmd_local = cmd_fusion->scmd;
3021 status = scsi_io_req->RaidContext.raid_context.status;
3022 extStatus = scsi_io_req->RaidContext.raid_context.ex_status;
3023 sense = cmd_fusion->sense;
3024 data_length = scsi_io_req->DataLength;
3026 switch (scsi_io_req->Function) {
3027 case MPI2_FUNCTION_SCSI_TASK_MGMT:
3028 mr_tm_req = (struct MR_TASK_MANAGE_REQUEST *)
3029 cmd_fusion->io_request;
3030 mpi_tm_req = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *)
3031 &mr_tm_req->TmRequest;
3032 dev_dbg(&instance->pdev->dev, "TM completion:"
3033 "type: 0x%x TaskMID: 0x%x\n",
3034 mpi_tm_req->TaskType, mpi_tm_req->TaskMID);
3035 complete(&cmd_fusion->done);
3037 case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/
3038 /* Update load balancing info */
3039 if (fusion->load_balance_info &&
3040 (cmd_fusion->scmd->SCp.Status &
3041 MEGASAS_LOAD_BALANCE_FLAG)) {
3042 device_id = MEGASAS_DEV_INDEX(scmd_local);
3043 lbinfo = &fusion->load_balance_info[device_id];
3044 atomic_dec(&lbinfo->scsi_pending_cmds[cmd_fusion->pd_r1_lb]);
3045 cmd_fusion->scmd->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
3047 //Fall thru and complete IO
3048 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
3049 atomic_dec(&instance->fw_outstanding);
3050 if (cmd_fusion->r1_alt_dev_handle == MR_DEVHANDLE_INVALID) {
3051 map_cmd_status(fusion, scmd_local, status,
3052 extStatus, le32_to_cpu(data_length),
3054 if (instance->ldio_threshold &&
3055 (megasas_cmd_type(scmd_local) == READ_WRITE_LDIO))
3056 atomic_dec(&instance->ldio_outstanding);
3057 scmd_local->SCp.ptr = NULL;
3058 megasas_return_cmd_fusion(instance, cmd_fusion);
3059 scsi_dma_unmap(scmd_local);
3060 scmd_local->scsi_done(scmd_local);
3061 } else /* Optimal VD - R1 FP command completion. */
3062 megasas_complete_r1_command(instance, cmd_fusion);
3064 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
3065 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
3066 /* Poll mode. Dummy free.
3067 * In case of Interrupt mode, caller has reverse check.
3069 if (cmd_mfi->flags & DRV_DCMD_POLLED_MODE) {
3070 cmd_mfi->flags &= ~DRV_DCMD_POLLED_MODE;
3071 megasas_return_cmd(instance, cmd_mfi);
3073 megasas_complete_cmd(instance, cmd_mfi, DID_OK);
3077 fusion->last_reply_idx[MSIxIndex]++;
3078 if (fusion->last_reply_idx[MSIxIndex] >=
3079 fusion->reply_q_depth)
3080 fusion->last_reply_idx[MSIxIndex] = 0;
3082 desc->Words = cpu_to_le64(ULLONG_MAX);
3084 threshold_reply_count++;
3086 /* Get the next reply descriptor */
3087 if (!fusion->last_reply_idx[MSIxIndex])
3088 desc = fusion->reply_frames_desc[MSIxIndex];
3093 (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
3095 d_val.word = desc->Words;
3097 reply_descript_type = reply_desc->ReplyFlags &
3098 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
3100 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
3103 * Write to reply post host index register after completing threshold
3104 * number of reply counts and still there are more replies in reply queue
3105 * pending to be completed
3107 if (threshold_reply_count >= THRESHOLD_REPLY_COUNT) {
3108 if (instance->msix_combined)
3109 writel(((MSIxIndex & 0x7) << 24) |
3110 fusion->last_reply_idx[MSIxIndex],
3111 instance->reply_post_host_index_addr[MSIxIndex/8]);
3113 writel((MSIxIndex << 24) |
3114 fusion->last_reply_idx[MSIxIndex],
3115 instance->reply_post_host_index_addr[0]);
3116 threshold_reply_count = 0;
3124 if (instance->msix_combined)
3125 writel(((MSIxIndex & 0x7) << 24) |
3126 fusion->last_reply_idx[MSIxIndex],
3127 instance->reply_post_host_index_addr[MSIxIndex/8]);
3129 writel((MSIxIndex << 24) |
3130 fusion->last_reply_idx[MSIxIndex],
3131 instance->reply_post_host_index_addr[0]);
3132 megasas_check_and_restore_queue_depth(instance);
3137 * megasas_sync_irqs - Synchronizes all IRQs owned by adapter
3138 * @instance: Adapter soft state
3140 void megasas_sync_irqs(unsigned long instance_addr)
3143 struct megasas_instance *instance =
3144 (struct megasas_instance *)instance_addr;
3146 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3148 for (i = 0; i < count; i++)
3149 synchronize_irq(pci_irq_vector(instance->pdev, i));
3153 * megasas_complete_cmd_dpc_fusion - Completes command
3154 * @instance: Adapter soft state
3156 * Tasklet to complete cmds
3159 megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
3161 struct megasas_instance *instance =
3162 (struct megasas_instance *)instance_addr;
3163 unsigned long flags;
3164 u32 count, MSIxIndex;
3166 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3168 /* If we have already declared adapter dead, donot complete cmds */
3169 spin_lock_irqsave(&instance->hba_lock, flags);
3170 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
3171 spin_unlock_irqrestore(&instance->hba_lock, flags);
3174 spin_unlock_irqrestore(&instance->hba_lock, flags);
3176 for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++)
3177 complete_cmd_fusion(instance, MSIxIndex);
3181 * megasas_isr_fusion - isr entry point
3183 irqreturn_t megasas_isr_fusion(int irq, void *devp)
3185 struct megasas_irq_context *irq_context = devp;
3186 struct megasas_instance *instance = irq_context->instance;
3187 u32 mfiStatus, fw_state, dma_state;
3189 if (instance->mask_interrupts)
3192 if (!instance->msix_vectors) {
3193 mfiStatus = instance->instancet->clear_intr(instance->reg_set);
3198 /* If we are resetting, bail */
3199 if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) {
3200 instance->instancet->clear_intr(instance->reg_set);
3204 if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) {
3205 instance->instancet->clear_intr(instance->reg_set);
3206 /* If we didn't complete any commands, check for FW fault */
3207 fw_state = instance->instancet->read_fw_status_reg(
3208 instance->reg_set) & MFI_STATE_MASK;
3209 dma_state = instance->instancet->read_fw_status_reg
3210 (instance->reg_set) & MFI_STATE_DMADONE;
3211 if (instance->crash_dump_drv_support &&
3212 instance->crash_dump_app_support) {
3213 /* Start collecting crash, if DMA bit is done */
3214 if ((fw_state == MFI_STATE_FAULT) && dma_state)
3215 schedule_work(&instance->crash_init);
3216 else if (fw_state == MFI_STATE_FAULT) {
3217 if (instance->unload == 0)
3218 schedule_work(&instance->work_init);
3220 } else if (fw_state == MFI_STATE_FAULT) {
3221 dev_warn(&instance->pdev->dev, "Iop2SysDoorbellInt"
3222 "for scsi%d\n", instance->host->host_no);
3223 if (instance->unload == 0)
3224 schedule_work(&instance->work_init);
3232 * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
3233 * @instance: Adapter soft state
3234 * mfi_cmd: megasas_cmd pointer
3238 build_mpt_mfi_pass_thru(struct megasas_instance *instance,
3239 struct megasas_cmd *mfi_cmd)
3241 struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain;
3242 struct MPI2_RAID_SCSI_IO_REQUEST *io_req;
3243 struct megasas_cmd_fusion *cmd;
3244 struct fusion_context *fusion;
3245 struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr;
3247 fusion = instance->ctrl_context;
3249 cmd = megasas_get_cmd_fusion(instance,
3250 instance->max_scsi_cmds + mfi_cmd->index);
3252 /* Save the smid. To be used for returning the cmd */
3253 mfi_cmd->context.smid = cmd->index;
3256 * For cmds where the flag is set, store the flag and check
3257 * on completion. For cmds with this flag, don't call
3258 * megasas_complete_cmd
3261 if (frame_hdr->flags & cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE))
3262 mfi_cmd->flags |= DRV_DCMD_POLLED_MODE;
3264 io_req = cmd->io_request;
3266 if (fusion->adapter_type >= INVADER_SERIES) {
3267 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
3268 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
3269 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
3270 sgl_ptr_end->Flags = 0;
3274 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
3276 io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST;
3277 io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST,
3279 io_req->ChainOffset = fusion->chain_offset_mfi_pthru;
3281 mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr);
3283 mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
3284 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
3286 mpi25_ieee_chain->Length = cpu_to_le32(instance->max_chain_frame_sz);
3290 * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
3291 * @instance: Adapter soft state
3292 * @cmd: mfi cmd to build
3295 union MEGASAS_REQUEST_DESCRIPTOR_UNION *
3296 build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
3298 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc = NULL;
3301 build_mpt_mfi_pass_thru(instance, cmd);
3302 index = cmd->context.smid;
3304 req_desc = megasas_get_request_descriptor(instance, index - 1);
3306 req_desc->Words = 0;
3307 req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
3308 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3310 req_desc->SCSIIO.SMID = cpu_to_le16(index);
3316 * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
3317 * @instance: Adapter soft state
3318 * @cmd: mfi cmd pointer
3322 megasas_issue_dcmd_fusion(struct megasas_instance *instance,
3323 struct megasas_cmd *cmd)
3325 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3327 req_desc = build_mpt_cmd(instance, cmd);
3329 megasas_fire_cmd_fusion(instance, req_desc);
3334 * megasas_release_fusion - Reverses the FW initialization
3335 * @instance: Adapter soft state
3338 megasas_release_fusion(struct megasas_instance *instance)
3340 megasas_free_cmds(instance);
3341 megasas_free_cmds_fusion(instance);
3343 iounmap(instance->reg_set);
3345 pci_release_selected_regions(instance->pdev, 1<<instance->bar);
3349 * megasas_read_fw_status_reg_fusion - returns the current FW status value
3350 * @regs: MFI register set
3353 megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs)
3355 return readl(&(regs)->outbound_scratch_pad);
3359 * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3360 * @instance: Controller's soft instance
3361 * return: Number of allocated host crash buffers
3364 megasas_alloc_host_crash_buffer(struct megasas_instance *instance)
3368 instance->crash_buf_pages = get_order(CRASH_DMA_BUF_SIZE);
3369 for (i = 0; i < MAX_CRASH_DUMP_SIZE; i++) {
3370 instance->crash_buf[i] = (void *)__get_free_pages(GFP_KERNEL,
3371 instance->crash_buf_pages);
3372 if (!instance->crash_buf[i]) {
3373 dev_info(&instance->pdev->dev, "Firmware crash dump "
3374 "memory allocation failed at index %d\n", i);
3377 memset(instance->crash_buf[i], 0,
3378 ((1 << PAGE_SHIFT) << instance->crash_buf_pages));
3380 instance->drv_buf_alloc = i;
3384 * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3385 * @instance: Controller's soft instance
3388 megasas_free_host_crash_buffer(struct megasas_instance *instance)
3392 for (i = 0; i < instance->drv_buf_alloc; i++) {
3393 if (instance->crash_buf[i])
3394 free_pages((ulong)instance->crash_buf[i],
3395 instance->crash_buf_pages);
3397 instance->drv_buf_index = 0;
3398 instance->drv_buf_alloc = 0;
3399 instance->fw_crash_state = UNAVAILABLE;
3400 instance->fw_crash_buffer_size = 0;
3404 * megasas_adp_reset_fusion - For controller reset
3405 * @regs: MFI register set
3408 megasas_adp_reset_fusion(struct megasas_instance *instance,
3409 struct megasas_register_set __iomem *regs)
3411 u32 host_diag, abs_state, retry;
3413 /* Now try to reset the chip */
3414 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3415 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3416 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3417 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3418 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3419 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3420 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &instance->reg_set->fusion_seq_offset);
3422 /* Check that the diag write enable (DRWE) bit is on */
3423 host_diag = readl(&instance->reg_set->fusion_host_diag);
3425 while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) {
3427 host_diag = readl(&instance->reg_set->fusion_host_diag);
3428 if (retry++ == 100) {
3429 dev_warn(&instance->pdev->dev,
3430 "Host diag unlock failed from %s %d\n",
3431 __func__, __LINE__);
3435 if (!(host_diag & HOST_DIAG_WRITE_ENABLE))
3438 /* Send chip reset command */
3439 writel(host_diag | HOST_DIAG_RESET_ADAPTER,
3440 &instance->reg_set->fusion_host_diag);
3443 /* Make sure reset adapter bit is cleared */
3444 host_diag = readl(&instance->reg_set->fusion_host_diag);
3446 while (host_diag & HOST_DIAG_RESET_ADAPTER) {
3448 host_diag = readl(&instance->reg_set->fusion_host_diag);
3449 if (retry++ == 1000) {
3450 dev_warn(&instance->pdev->dev,
3451 "Diag reset adapter never cleared %s %d\n",
3452 __func__, __LINE__);
3456 if (host_diag & HOST_DIAG_RESET_ADAPTER)
3459 abs_state = instance->instancet->read_fw_status_reg(instance->reg_set)
3463 while ((abs_state <= MFI_STATE_FW_INIT) && (retry++ < 1000)) {
3465 abs_state = instance->instancet->
3466 read_fw_status_reg(instance->reg_set) & MFI_STATE_MASK;
3468 if (abs_state <= MFI_STATE_FW_INIT) {
3469 dev_warn(&instance->pdev->dev,
3470 "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n",
3471 abs_state, __func__, __LINE__);
3479 * megasas_check_reset_fusion - For controller reset check
3480 * @regs: MFI register set
3483 megasas_check_reset_fusion(struct megasas_instance *instance,
3484 struct megasas_register_set __iomem *regs)
3489 /* This function waits for outstanding commands on fusion to complete */
3490 int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance,
3491 int reason, int *convert)
3493 int i, outstanding, retval = 0, hb_seconds_missed = 0;
3496 for (i = 0; i < resetwaittime; i++) {
3497 /* Check if firmware is in fault state */
3498 fw_state = instance->instancet->read_fw_status_reg(
3499 instance->reg_set) & MFI_STATE_MASK;
3500 if (fw_state == MFI_STATE_FAULT) {
3501 dev_warn(&instance->pdev->dev, "Found FW in FAULT state,"
3502 " will reset adapter scsi%d.\n",
3503 instance->host->host_no);
3504 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
3505 if (instance->requestorId && reason) {
3506 dev_warn(&instance->pdev->dev, "SR-IOV Found FW in FAULT"
3507 " state while polling during"
3508 " I/O timeout handling for %d\n",
3509 instance->host->host_no);
3517 if (reason == MFI_IO_TIMEOUT_OCR) {
3518 dev_info(&instance->pdev->dev,
3519 "MFI IO is timed out, initiating OCR\n");
3520 megasas_complete_cmd_dpc_fusion((unsigned long)instance);
3525 /* If SR-IOV VF mode & heartbeat timeout, don't wait */
3526 if (instance->requestorId && !reason) {
3531 /* If SR-IOV VF mode & I/O timeout, check for HB timeout */
3532 if (instance->requestorId && (reason == SCSIIO_TIMEOUT_OCR)) {
3533 if (instance->hb_host_mem->HB.fwCounter !=
3534 instance->hb_host_mem->HB.driverCounter) {
3535 instance->hb_host_mem->HB.driverCounter =
3536 instance->hb_host_mem->HB.fwCounter;
3537 hb_seconds_missed = 0;
3539 hb_seconds_missed++;
3540 if (hb_seconds_missed ==
3541 (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF/HZ)) {
3542 dev_warn(&instance->pdev->dev, "SR-IOV:"
3543 " Heartbeat never completed "
3544 " while polling during I/O "
3545 " timeout handling for "
3547 instance->host->host_no);
3555 outstanding = atomic_read(&instance->fw_outstanding);
3559 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
3560 dev_notice(&instance->pdev->dev, "[%2d]waiting for %d "
3561 "commands to complete for scsi%d\n", i,
3562 outstanding, instance->host->host_no);
3563 megasas_complete_cmd_dpc_fusion(
3564 (unsigned long)instance);
3569 if (atomic_read(&instance->fw_outstanding)) {
3570 dev_err(&instance->pdev->dev, "pending commands remain after waiting, "
3571 "will reset adapter scsi%d.\n",
3572 instance->host->host_no);
3580 void megasas_reset_reply_desc(struct megasas_instance *instance)
3583 struct fusion_context *fusion;
3584 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
3586 fusion = instance->ctrl_context;
3587 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
3588 for (i = 0 ; i < count ; i++) {
3589 fusion->last_reply_idx[i] = 0;
3590 reply_desc = fusion->reply_frames_desc[i];
3591 for (j = 0 ; j < fusion->reply_q_depth; j++, reply_desc++)
3592 reply_desc->Words = cpu_to_le64(ULLONG_MAX);
3597 * megasas_refire_mgmt_cmd : Re-fire management commands
3598 * @instance: Controller's soft instance
3600 void megasas_refire_mgmt_cmd(struct megasas_instance *instance)
3603 struct megasas_cmd_fusion *cmd_fusion;
3604 struct fusion_context *fusion;
3605 struct megasas_cmd *cmd_mfi;
3606 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3608 bool refire_cmd = 0;
3610 fusion = instance->ctrl_context;
3612 /* Re-fire management commands.
3613 * Do not traverse complet MPT frame pool. Start from max_scsi_cmds.
3615 for (j = instance->max_scsi_cmds ; j < instance->max_fw_cmds; j++) {
3616 cmd_fusion = fusion->cmd_list[j];
3617 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
3618 smid = le16_to_cpu(cmd_mfi->context.smid);
3622 req_desc = megasas_get_request_descriptor
3623 (instance, smid - 1);
3624 refire_cmd = req_desc && ((cmd_mfi->frame->dcmd.opcode !=
3625 cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO)) &&
3626 (cmd_mfi->frame->dcmd.opcode !=
3627 cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO)))
3628 && !(cmd_mfi->flags & DRV_DCMD_SKIP_REFIRE);
3630 megasas_fire_cmd_fusion(instance, req_desc);
3632 megasas_return_cmd(instance, cmd_mfi);
3637 * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device
3638 * @instance: per adapter struct
3639 * @channel: the channel assigned by the OS
3640 * @id: the id assigned by the OS
3642 * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED
3645 static int megasas_track_scsiio(struct megasas_instance *instance,
3646 int id, int channel)
3649 struct megasas_cmd_fusion *cmd_fusion;
3650 struct fusion_context *fusion;
3651 fusion = instance->ctrl_context;
3653 for (i = 0 ; i < instance->max_scsi_cmds; i++) {
3654 cmd_fusion = fusion->cmd_list[i];
3655 if (cmd_fusion->scmd &&
3656 (cmd_fusion->scmd->device->id == id &&
3657 cmd_fusion->scmd->device->channel == channel)) {
3658 dev_info(&instance->pdev->dev,
3659 "SCSI commands pending to target"
3660 "channel %d id %d \tSMID: 0x%x\n",
3661 channel, id, cmd_fusion->index);
3662 scsi_print_command(cmd_fusion->scmd);
3668 return found ? FAILED : SUCCESS;
3672 * megasas_tm_response_code - translation of device response code
3673 * @ioc: per adapter object
3674 * @mpi_reply: MPI reply returned by firmware
3679 megasas_tm_response_code(struct megasas_instance *instance,
3680 struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply)
3684 switch (mpi_reply->ResponseCode) {
3685 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
3686 desc = "task management request completed";
3688 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
3689 desc = "invalid frame";
3691 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
3692 desc = "task management request not supported";
3694 case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
3695 desc = "task management request failed";
3697 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
3698 desc = "task management request succeeded";
3700 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
3701 desc = "invalid lun";
3704 desc = "overlapped tag attempted";
3706 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
3707 desc = "task queued, however not sent to target";
3713 dev_dbg(&instance->pdev->dev, "response_code(%01x): %s\n",
3714 mpi_reply->ResponseCode, desc);
3715 dev_dbg(&instance->pdev->dev,
3716 "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo"
3717 " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n",
3718 mpi_reply->TerminationCount, mpi_reply->DevHandle,
3719 mpi_reply->Function, mpi_reply->TaskType,
3720 mpi_reply->IOCStatus, mpi_reply->IOCLogInfo);
3724 * megasas_issue_tm - main routine for sending tm requests
3725 * @instance: per adapter struct
3726 * @device_handle: device handle
3727 * @channel: the channel assigned by the OS
3728 * @id: the id assigned by the OS
3729 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c)
3730 * @smid_task: smid assigned to the task
3731 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
3734 * MegaRaid use MPT interface for Task Magement request.
3735 * A generic API for sending task management requests to firmware.
3737 * Return SUCCESS or FAILED.
3740 megasas_issue_tm(struct megasas_instance *instance, u16 device_handle,
3741 uint channel, uint id, u16 smid_task, u8 type)
3743 struct MR_TASK_MANAGE_REQUEST *mr_request;
3744 struct MPI2_SCSI_TASK_MANAGE_REQUEST *mpi_request;
3745 unsigned long timeleft;
3746 struct megasas_cmd_fusion *cmd_fusion;
3747 struct megasas_cmd *cmd_mfi;
3748 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
3749 struct fusion_context *fusion;
3750 struct megasas_cmd_fusion *scsi_lookup;
3752 struct MPI2_SCSI_TASK_MANAGE_REPLY *mpi_reply;
3754 fusion = instance->ctrl_context;
3756 cmd_mfi = megasas_get_cmd(instance);
3759 dev_err(&instance->pdev->dev, "Failed from %s %d\n",
3760 __func__, __LINE__);
3764 cmd_fusion = megasas_get_cmd_fusion(instance,
3765 instance->max_scsi_cmds + cmd_mfi->index);
3767 /* Save the smid. To be used for returning the cmd */
3768 cmd_mfi->context.smid = cmd_fusion->index;
3770 req_desc = megasas_get_request_descriptor(instance,
3771 (cmd_fusion->index - 1));
3773 cmd_fusion->request_desc = req_desc;
3774 req_desc->Words = 0;
3776 scsi_lookup = fusion->cmd_list[smid_task - 1];
3778 mr_request = (struct MR_TASK_MANAGE_REQUEST *) cmd_fusion->io_request;
3779 memset(mr_request, 0, sizeof(struct MR_TASK_MANAGE_REQUEST));
3780 mpi_request = (struct MPI2_SCSI_TASK_MANAGE_REQUEST *) &mr_request->TmRequest;
3781 mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
3782 mpi_request->DevHandle = cpu_to_le16(device_handle);
3783 mpi_request->TaskType = type;
3784 mpi_request->TaskMID = cpu_to_le16(smid_task);
3785 mpi_request->LUN[1] = 0;
3788 req_desc = cmd_fusion->request_desc;
3789 req_desc->HighPriority.SMID = cpu_to_le16(cmd_fusion->index);
3790 req_desc->HighPriority.RequestFlags =
3791 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
3792 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
3793 req_desc->HighPriority.MSIxIndex = 0;
3794 req_desc->HighPriority.LMID = 0;
3795 req_desc->HighPriority.Reserved1 = 0;
3797 if (channel < MEGASAS_MAX_PD_CHANNELS)
3798 mr_request->tmReqFlags.isTMForPD = 1;
3800 mr_request->tmReqFlags.isTMForLD = 1;
3802 init_completion(&cmd_fusion->done);
3803 megasas_fire_cmd_fusion(instance, req_desc);
3805 timeleft = wait_for_completion_timeout(&cmd_fusion->done, 50 * HZ);
3808 dev_err(&instance->pdev->dev,
3809 "task mgmt type 0x%x timed out\n", type);
3810 cmd_mfi->flags |= DRV_DCMD_SKIP_REFIRE;
3811 mutex_unlock(&instance->reset_mutex);
3812 rc = megasas_reset_fusion(instance->host, MFI_IO_TIMEOUT_OCR);
3813 mutex_lock(&instance->reset_mutex);
3817 mpi_reply = (struct MPI2_SCSI_TASK_MANAGE_REPLY *) &mr_request->TMReply;
3818 megasas_tm_response_code(instance, mpi_reply);
3820 megasas_return_cmd(instance, cmd_mfi);
3823 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
3824 if (scsi_lookup->scmd == NULL)
3827 instance->instancet->disable_intr(instance);
3828 megasas_sync_irqs((unsigned long)instance);
3829 megasas_complete_cmd_dpc_fusion
3830 ((unsigned long)instance);
3831 instance->instancet->enable_intr(instance);
3832 if (scsi_lookup->scmd == NULL)
3838 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
3839 if ((channel == 0xFFFFFFFF) && (id == 0xFFFFFFFF))
3841 instance->instancet->disable_intr(instance);
3843 megasas_complete_cmd_dpc_fusion
3844 ((unsigned long)instance);
3845 rc = megasas_track_scsiio(instance, id, channel);
3846 instance->instancet->enable_intr(instance);
3849 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
3850 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
3862 * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI
3863 * @instance: per adapter struct
3865 * Return Non Zero index, if SMID found in outstanding commands
3867 static u16 megasas_fusion_smid_lookup(struct scsi_cmnd *scmd)
3870 struct megasas_instance *instance;
3871 struct megasas_cmd_fusion *cmd_fusion;
3872 struct fusion_context *fusion;
3874 instance = (struct megasas_instance *)scmd->device->host->hostdata;
3876 fusion = instance->ctrl_context;
3878 for (i = 0; i < instance->max_scsi_cmds; i++) {
3879 cmd_fusion = fusion->cmd_list[i];
3880 if (cmd_fusion->scmd && (cmd_fusion->scmd == scmd)) {
3881 scmd_printk(KERN_NOTICE, scmd, "Abort request is for"
3882 " SMID: %d\n", cmd_fusion->index);
3883 ret = cmd_fusion->index;
3892 * megasas_get_tm_devhandle - Get devhandle for TM request
3893 * @sdev- OS provided scsi device
3895 * Returns- devhandle/targetID of SCSI device
3897 static u16 megasas_get_tm_devhandle(struct scsi_device *sdev)
3901 struct megasas_instance *instance;
3902 struct fusion_context *fusion;
3903 struct MR_PD_CFG_SEQ_NUM_SYNC *pd_sync;
3904 u16 devhandle = (u16)ULONG_MAX;
3906 instance = (struct megasas_instance *)sdev->host->hostdata;
3907 fusion = instance->ctrl_context;
3909 if (!MEGASAS_IS_LOGICAL(sdev)) {
3910 if (instance->use_seqnum_jbod_fp) {
3911 pd_index = (sdev->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
3913 pd_sync = (void *)fusion->pd_seq_sync
3914 [(instance->pd_seq_map_id - 1) & 1];
3915 devhandle = pd_sync->seq[pd_index].devHandle;
3917 sdev_printk(KERN_ERR, sdev, "Firmware expose tmCapable"
3918 " without JBOD MAP support from %s %d\n", __func__, __LINE__);
3920 device_id = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL)
3922 devhandle = device_id;
3929 * megasas_task_abort_fusion : SCSI task abort function for fusion adapters
3930 * @scmd : pointer to scsi command object
3932 * Return SUCCESS, if command aborted else FAILED
3935 int megasas_task_abort_fusion(struct scsi_cmnd *scmd)
3937 struct megasas_instance *instance;
3938 u16 smid, devhandle;
3939 struct fusion_context *fusion;
3941 struct MR_PRIV_DEVICE *mr_device_priv_data;
3942 mr_device_priv_data = scmd->device->hostdata;
3945 instance = (struct megasas_instance *)scmd->device->host->hostdata;
3946 fusion = instance->ctrl_context;
3948 scmd_printk(KERN_INFO, scmd, "task abort called for scmd(%p)\n", scmd);
3949 scsi_print_command(scmd);
3951 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
3952 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
3953 "SCSI host:%d\n", instance->host->host_no);
3958 if (!mr_device_priv_data) {
3959 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
3960 "scmd(%p)\n", scmd);
3961 scmd->result = DID_NO_CONNECT << 16;
3967 if (!mr_device_priv_data->is_tm_capable) {
3972 mutex_lock(&instance->reset_mutex);
3974 smid = megasas_fusion_smid_lookup(scmd);
3978 scmd_printk(KERN_NOTICE, scmd, "Command for which abort is"
3979 " issued is not found in oustanding commands\n");
3980 mutex_unlock(&instance->reset_mutex);
3984 devhandle = megasas_get_tm_devhandle(scmd->device);
3986 if (devhandle == (u16)ULONG_MAX) {
3988 sdev_printk(KERN_INFO, scmd->device,
3989 "task abort issued for invalid devhandle\n");
3990 mutex_unlock(&instance->reset_mutex);
3993 sdev_printk(KERN_INFO, scmd->device,
3994 "attempting task abort! scmd(%p) tm_dev_handle 0x%x\n",
3997 mr_device_priv_data->tm_busy = 1;
3998 ret = megasas_issue_tm(instance, devhandle,
3999 scmd->device->channel, scmd->device->id, smid,
4000 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK);
4001 mr_device_priv_data->tm_busy = 0;
4003 mutex_unlock(&instance->reset_mutex);
4005 sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
4006 ((ret == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
4012 * megasas_reset_target_fusion : target reset function for fusion adapters
4013 * scmd: SCSI command pointer
4015 * Returns SUCCESS if all commands associated with target aborted else FAILED
4018 int megasas_reset_target_fusion(struct scsi_cmnd *scmd)
4021 struct megasas_instance *instance;
4024 struct fusion_context *fusion;
4025 struct MR_PRIV_DEVICE *mr_device_priv_data;
4026 mr_device_priv_data = scmd->device->hostdata;
4028 instance = (struct megasas_instance *)scmd->device->host->hostdata;
4029 fusion = instance->ctrl_context;
4031 sdev_printk(KERN_INFO, scmd->device,
4032 "target reset called for scmd(%p)\n", scmd);
4034 if (atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) {
4035 dev_err(&instance->pdev->dev, "Controller is not OPERATIONAL,"
4036 "SCSI host:%d\n", instance->host->host_no);
4041 if (!mr_device_priv_data) {
4042 sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
4043 "scmd(%p)\n", scmd);
4044 scmd->result = DID_NO_CONNECT << 16;
4050 if (!mr_device_priv_data->is_tm_capable) {
4055 mutex_lock(&instance->reset_mutex);
4056 devhandle = megasas_get_tm_devhandle(scmd->device);
4058 if (devhandle == (u16)ULONG_MAX) {
4060 sdev_printk(KERN_INFO, scmd->device,
4061 "target reset issued for invalid devhandle\n");
4062 mutex_unlock(&instance->reset_mutex);
4066 sdev_printk(KERN_INFO, scmd->device,
4067 "attempting target reset! scmd(%p) tm_dev_handle 0x%x\n",
4069 mr_device_priv_data->tm_busy = 1;
4070 ret = megasas_issue_tm(instance, devhandle,
4071 scmd->device->channel, scmd->device->id, 0,
4072 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET);
4073 mr_device_priv_data->tm_busy = 0;
4074 mutex_unlock(&instance->reset_mutex);
4076 scmd_printk(KERN_NOTICE, scmd, "megasas: target reset %s!!\n",
4077 (ret == SUCCESS) ? "SUCCESS" : "FAILED");
4082 /*SRIOV get other instance in cluster if any*/
4083 struct megasas_instance *megasas_get_peer_instance(struct megasas_instance *instance)
4087 for (i = 0; i < MAX_MGMT_ADAPTERS; i++) {
4088 if (megasas_mgmt_info.instance[i] &&
4089 (megasas_mgmt_info.instance[i] != instance) &&
4090 megasas_mgmt_info.instance[i]->requestorId &&
4091 megasas_mgmt_info.instance[i]->peerIsPresent &&
4092 (memcmp((megasas_mgmt_info.instance[i]->clusterId),
4093 instance->clusterId, MEGASAS_CLUSTER_ID_SIZE) == 0))
4094 return megasas_mgmt_info.instance[i];
4099 /* Check for a second path that is currently UP */
4100 int megasas_check_mpio_paths(struct megasas_instance *instance,
4101 struct scsi_cmnd *scmd)
4103 struct megasas_instance *peer_instance = NULL;
4104 int retval = (DID_REQUEUE << 16);
4106 if (instance->peerIsPresent) {
4107 peer_instance = megasas_get_peer_instance(instance);
4108 if ((peer_instance) &&
4109 (atomic_read(&peer_instance->adprecovery) ==
4110 MEGASAS_HBA_OPERATIONAL))
4111 retval = (DID_NO_CONNECT << 16);
4116 /* Core fusion reset function */
4117 int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
4119 int retval = SUCCESS, i, j, convert = 0;
4120 struct megasas_instance *instance;
4121 struct megasas_cmd_fusion *cmd_fusion, *r1_cmd;
4122 struct fusion_context *fusion;
4123 u32 abs_state, status_reg, reset_adapter;
4124 u32 io_timeout_in_crash_mode = 0;
4125 struct scsi_cmnd *scmd_local = NULL;
4126 struct scsi_device *sdev;
4128 instance = (struct megasas_instance *)shost->hostdata;
4129 fusion = instance->ctrl_context;
4131 mutex_lock(&instance->reset_mutex);
4133 if (atomic_read(&instance->adprecovery) == MEGASAS_HW_CRITICAL_ERROR) {
4134 dev_warn(&instance->pdev->dev, "Hardware critical error, "
4135 "returning FAILED for scsi%d.\n",
4136 instance->host->host_no);
4137 mutex_unlock(&instance->reset_mutex);
4140 status_reg = instance->instancet->read_fw_status_reg(instance->reg_set);
4141 abs_state = status_reg & MFI_STATE_MASK;
4143 /* IO timeout detected, forcibly put FW in FAULT state */
4144 if (abs_state != MFI_STATE_FAULT && instance->crash_dump_buf &&
4145 instance->crash_dump_app_support && reason) {
4146 dev_info(&instance->pdev->dev, "IO/DCMD timeout is detected, "
4147 "forcibly FAULT Firmware\n");
4148 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT);
4149 status_reg = readl(&instance->reg_set->doorbell);
4150 writel(status_reg | MFI_STATE_FORCE_OCR,
4151 &instance->reg_set->doorbell);
4152 readl(&instance->reg_set->doorbell);
4153 mutex_unlock(&instance->reset_mutex);
4156 io_timeout_in_crash_mode++;
4157 dev_dbg(&instance->pdev->dev, "waiting for [%d] "
4158 "seconds for crash dump collection and OCR "
4159 "to be done\n", (io_timeout_in_crash_mode * 3));
4160 } while ((atomic_read(&instance->adprecovery) != MEGASAS_HBA_OPERATIONAL) &&
4161 (io_timeout_in_crash_mode < 80));
4163 if (atomic_read(&instance->adprecovery) == MEGASAS_HBA_OPERATIONAL) {
4164 dev_info(&instance->pdev->dev, "OCR done for IO "
4168 dev_info(&instance->pdev->dev, "Controller is not "
4169 "operational after 240 seconds wait for IO "
4170 "timeout case in FW crash dump mode\n do "
4171 "OCR/kill adapter\n");
4172 retval = megasas_reset_fusion(shost, 0);
4177 if (instance->requestorId && !instance->skip_heartbeat_timer_del)
4178 del_timer_sync(&instance->sriov_heartbeat_timer);
4179 set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
4180 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_POLLING);
4181 instance->instancet->disable_intr(instance);
4182 megasas_sync_irqs((unsigned long)instance);
4184 /* First try waiting for commands to complete */
4185 if (megasas_wait_for_outstanding_fusion(instance, reason,
4187 atomic_set(&instance->adprecovery, MEGASAS_ADPRESET_SM_INFAULT);
4188 dev_warn(&instance->pdev->dev, "resetting fusion "
4189 "adapter scsi%d.\n", instance->host->host_no);
4193 if (megasas_dbg_lvl & OCR_LOGS)
4194 dev_info(&instance->pdev->dev, "\nPending SCSI commands:\n");
4196 /* Now return commands back to the OS */
4197 for (i = 0 ; i < instance->max_scsi_cmds; i++) {
4198 cmd_fusion = fusion->cmd_list[i];
4199 /*check for extra commands issued by driver*/
4200 if (instance->is_ventura) {
4201 r1_cmd = fusion->cmd_list[i + instance->max_fw_cmds];
4202 megasas_return_cmd_fusion(instance, r1_cmd);
4204 scmd_local = cmd_fusion->scmd;
4205 if (cmd_fusion->scmd) {
4206 if (megasas_dbg_lvl & OCR_LOGS) {
4207 sdev_printk(KERN_INFO,
4208 cmd_fusion->scmd->device, "SMID: 0x%x\n",
4210 scsi_print_command(cmd_fusion->scmd);
4213 scmd_local->result =
4214 megasas_check_mpio_paths(instance,
4216 if (instance->ldio_threshold &&
4217 megasas_cmd_type(scmd_local) == READ_WRITE_LDIO)
4218 atomic_dec(&instance->ldio_outstanding);
4219 megasas_return_cmd_fusion(instance, cmd_fusion);
4220 scsi_dma_unmap(scmd_local);
4221 scmd_local->scsi_done(scmd_local);
4225 atomic_set(&instance->fw_outstanding, 0);
4227 status_reg = instance->instancet->read_fw_status_reg(
4229 abs_state = status_reg & MFI_STATE_MASK;
4230 reset_adapter = status_reg & MFI_RESET_ADAPTER;
4231 if (instance->disableOnlineCtrlReset ||
4232 (abs_state == MFI_STATE_FAULT && !reset_adapter)) {
4233 /* Reset not supported, kill adapter */
4234 dev_warn(&instance->pdev->dev, "Reset not supported"
4235 ", killing adapter scsi%d.\n",
4236 instance->host->host_no);
4237 megaraid_sas_kill_hba(instance);
4238 instance->skip_heartbeat_timer_del = 1;
4243 /* Let SR-IOV VF & PF sync up if there was a HB failure */
4244 if (instance->requestorId && !reason) {
4245 msleep(MEGASAS_OCR_SETTLE_TIME_VF);
4246 goto transition_to_ready;
4249 /* Now try to reset the chip */
4250 for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) {
4252 if (instance->instancet->adp_reset
4253 (instance, instance->reg_set))
4255 transition_to_ready:
4256 /* Wait for FW to become ready */
4257 if (megasas_transition_to_ready(instance, 1)) {
4258 dev_warn(&instance->pdev->dev,
4259 "Failed to transition controller to ready for "
4260 "scsi%d.\n", instance->host->host_no);
4261 if (instance->requestorId && !reason)
4262 goto fail_kill_adapter;
4266 megasas_reset_reply_desc(instance);
4267 megasas_fusion_update_can_queue(instance, OCR_CONTEXT);
4269 if (megasas_ioc_init_fusion(instance)) {
4270 dev_warn(&instance->pdev->dev,
4271 "megasas_ioc_init_fusion() failed! for "
4272 "scsi%d\n", instance->host->host_no);
4273 if (instance->requestorId && !reason)
4274 goto fail_kill_adapter;
4279 megasas_refire_mgmt_cmd(instance);
4281 if (megasas_get_ctrl_info(instance)) {
4282 dev_info(&instance->pdev->dev,
4283 "Failed from %s %d\n",
4284 __func__, __LINE__);
4285 megaraid_sas_kill_hba(instance);
4289 /* Reset load balance info */
4290 if (fusion->load_balance_info)
4291 memset(fusion->load_balance_info, 0,
4292 (sizeof(struct LD_LOAD_BALANCE_INFO) *
4293 MAX_LOGICAL_DRIVES_EXT));
4295 if (!megasas_get_map_info(instance))
4296 megasas_sync_map_info(instance);
4298 megasas_setup_jbod_map(instance);
4300 shost_for_each_device(sdev, shost)
4301 megasas_set_dynamic_target_properties(sdev);
4303 /* reset stream detection array */
4304 if (instance->is_ventura) {
4305 for (j = 0; j < MAX_LOGICAL_DRIVES_EXT; ++j) {
4306 memset(fusion->stream_detect_by_ld[j],
4307 0, sizeof(struct LD_STREAM_DETECT));
4308 fusion->stream_detect_by_ld[j]->mru_bit_map
4313 clear_bit(MEGASAS_FUSION_IN_RESET,
4314 &instance->reset_flags);
4315 instance->instancet->enable_intr(instance);
4316 atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL);
4318 /* Restart SR-IOV heartbeat */
4319 if (instance->requestorId) {
4320 if (!megasas_sriov_start_heartbeat(instance, 0))
4321 megasas_start_timer(instance,
4322 &instance->sriov_heartbeat_timer,
4323 megasas_sriov_heartbeat_handler,
4324 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
4326 instance->skip_heartbeat_timer_del = 1;
4329 /* Adapter reset completed successfully */
4330 dev_warn(&instance->pdev->dev, "Reset "
4331 "successful for scsi%d.\n",
4332 instance->host->host_no);
4334 if (instance->crash_dump_drv_support &&
4335 instance->crash_dump_app_support)
4336 megasas_set_crash_dump_params(instance,
4337 MR_CRASH_BUF_TURN_ON);
4339 megasas_set_crash_dump_params(instance,
4340 MR_CRASH_BUF_TURN_OFF);
4346 /* Reset failed, kill the adapter */
4347 dev_warn(&instance->pdev->dev, "Reset failed, killing "
4348 "adapter scsi%d.\n", instance->host->host_no);
4349 megaraid_sas_kill_hba(instance);
4350 instance->skip_heartbeat_timer_del = 1;
4353 /* For VF: Restart HB timer if we didn't OCR */
4354 if (instance->requestorId) {
4355 megasas_start_timer(instance,
4356 &instance->sriov_heartbeat_timer,
4357 megasas_sriov_heartbeat_handler,
4358 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF);
4360 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
4361 instance->instancet->enable_intr(instance);
4362 atomic_set(&instance->adprecovery, MEGASAS_HBA_OPERATIONAL);
4365 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
4366 mutex_unlock(&instance->reset_mutex);
4370 /* Fusion Crash dump collection work queue */
4371 void megasas_fusion_crash_dump_wq(struct work_struct *work)
4373 struct megasas_instance *instance =
4374 container_of(work, struct megasas_instance, crash_init);
4376 u8 partial_copy = 0;
4379 status_reg = instance->instancet->read_fw_status_reg(instance->reg_set);
4382 * Allocate host crash buffers to copy data from 1 MB DMA crash buffer
4383 * to host crash buffers
4385 if (instance->drv_buf_index == 0) {
4386 /* Buffer is already allocated for old Crash dump.
4387 * Do OCR and do not wait for crash dump collection
4389 if (instance->drv_buf_alloc) {
4390 dev_info(&instance->pdev->dev, "earlier crash dump is "
4391 "not yet copied by application, ignoring this "
4392 "crash dump and initiating OCR\n");
4393 status_reg |= MFI_STATE_CRASH_DUMP_DONE;
4395 &instance->reg_set->outbound_scratch_pad);
4396 readl(&instance->reg_set->outbound_scratch_pad);
4399 megasas_alloc_host_crash_buffer(instance);
4400 dev_info(&instance->pdev->dev, "Number of host crash buffers "
4401 "allocated: %d\n", instance->drv_buf_alloc);
4405 * Driver has allocated max buffers, which can be allocated
4406 * and FW has more crash dump data, then driver will
4409 if (instance->drv_buf_index >= (instance->drv_buf_alloc)) {
4410 dev_info(&instance->pdev->dev, "Driver is done copying "
4411 "the buffer: %d\n", instance->drv_buf_alloc);
4412 status_reg |= MFI_STATE_CRASH_DUMP_DONE;
4415 memcpy(instance->crash_buf[instance->drv_buf_index],
4416 instance->crash_dump_buf, CRASH_DMA_BUF_SIZE);
4417 instance->drv_buf_index++;
4418 status_reg &= ~MFI_STATE_DMADONE;
4421 if (status_reg & MFI_STATE_CRASH_DUMP_DONE) {
4422 dev_info(&instance->pdev->dev, "Crash Dump is available,number "
4423 "of copied buffers: %d\n", instance->drv_buf_index);
4424 instance->fw_crash_buffer_size = instance->drv_buf_index;
4425 instance->fw_crash_state = AVAILABLE;
4426 instance->drv_buf_index = 0;
4427 writel(status_reg, &instance->reg_set->outbound_scratch_pad);
4428 readl(&instance->reg_set->outbound_scratch_pad);
4430 megasas_reset_fusion(instance->host, 0);
4432 writel(status_reg, &instance->reg_set->outbound_scratch_pad);
4433 readl(&instance->reg_set->outbound_scratch_pad);
4438 /* Fusion OCR work queue */
4439 void megasas_fusion_ocr_wq(struct work_struct *work)
4441 struct megasas_instance *instance =
4442 container_of(work, struct megasas_instance, work_init);
4444 megasas_reset_fusion(instance->host, 0);
4447 /* Allocate fusion context */
4449 megasas_alloc_fusion_context(struct megasas_instance *instance)
4451 struct fusion_context *fusion;
4453 instance->ctrl_context_pages = get_order(sizeof(struct fusion_context));
4454 instance->ctrl_context = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
4455 instance->ctrl_context_pages);
4456 if (!instance->ctrl_context) {
4457 /* fall back to using vmalloc for fusion_context */
4458 instance->ctrl_context = vzalloc(sizeof(struct fusion_context));
4459 if (!instance->ctrl_context) {
4460 dev_err(&instance->pdev->dev, "Failed from %s %d\n", __func__, __LINE__);
4465 fusion = instance->ctrl_context;
4467 fusion->load_balance_info_pages = get_order(MAX_LOGICAL_DRIVES_EXT *
4468 sizeof(struct LD_LOAD_BALANCE_INFO));
4469 fusion->load_balance_info =
4470 (struct LD_LOAD_BALANCE_INFO *)__get_free_pages(GFP_KERNEL | __GFP_ZERO,
4471 fusion->load_balance_info_pages);
4472 if (!fusion->load_balance_info) {
4473 fusion->load_balance_info = vzalloc(MAX_LOGICAL_DRIVES_EXT *
4474 sizeof(struct LD_LOAD_BALANCE_INFO));
4475 if (!fusion->load_balance_info)
4476 dev_err(&instance->pdev->dev, "Failed to allocate load_balance_info, "
4477 "continuing without Load Balance support\n");
4484 megasas_free_fusion_context(struct megasas_instance *instance)
4486 struct fusion_context *fusion = instance->ctrl_context;
4489 if (fusion->load_balance_info) {
4490 if (is_vmalloc_addr(fusion->load_balance_info))
4491 vfree(fusion->load_balance_info);
4493 free_pages((ulong)fusion->load_balance_info,
4494 fusion->load_balance_info_pages);
4497 if (is_vmalloc_addr(fusion))
4500 free_pages((ulong)fusion,
4501 instance->ctrl_context_pages);
4505 struct megasas_instance_template megasas_instance_template_fusion = {
4506 .enable_intr = megasas_enable_intr_fusion,
4507 .disable_intr = megasas_disable_intr_fusion,
4508 .clear_intr = megasas_clear_intr_fusion,
4509 .read_fw_status_reg = megasas_read_fw_status_reg_fusion,
4510 .adp_reset = megasas_adp_reset_fusion,
4511 .check_reset = megasas_check_reset_fusion,
4512 .service_isr = megasas_isr_fusion,
4513 .tasklet = megasas_complete_cmd_dpc_fusion,
4514 .init_adapter = megasas_init_adapter_fusion,
4515 .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion,
4516 .issue_dcmd = megasas_issue_dcmd_fusion,