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>
51 #include <scsi/scsi.h>
52 #include <scsi/scsi_cmnd.h>
53 #include <scsi/scsi_device.h>
54 #include <scsi/scsi_host.h>
55 #include <scsi/scsi_dbg.h>
56 #include <linux/dmi.h>
58 #include "megaraid_sas_fusion.h"
59 #include "megaraid_sas.h"
62 extern void megasas_free_cmds(struct megasas_instance
*instance
);
63 extern struct megasas_cmd
*megasas_get_cmd(struct megasas_instance
66 megasas_complete_cmd(struct megasas_instance
*instance
,
67 struct megasas_cmd
*cmd
, u8 alt_status
);
69 wait_and_poll(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
73 megasas_return_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
);
74 int megasas_alloc_cmds(struct megasas_instance
*instance
);
76 megasas_clear_intr_fusion(struct megasas_register_set __iomem
*regs
);
78 megasas_issue_polled(struct megasas_instance
*instance
,
79 struct megasas_cmd
*cmd
);
81 megasas_check_and_restore_queue_depth(struct megasas_instance
*instance
);
83 int megasas_transition_to_ready(struct megasas_instance
*instance
, int ocr
);
84 void megaraid_sas_kill_hba(struct megasas_instance
*instance
);
86 extern u32 megasas_dbg_lvl
;
87 void megasas_sriov_heartbeat_handler(unsigned long instance_addr
);
88 int megasas_sriov_start_heartbeat(struct megasas_instance
*instance
,
90 void megasas_start_timer(struct megasas_instance
*instance
,
91 struct timer_list
*timer
,
92 void *fn
, unsigned long interval
);
93 extern struct megasas_mgmt_info megasas_mgmt_info
;
94 extern unsigned int resetwaittime
;
95 extern unsigned int dual_qdepth_disable
;
96 static void megasas_free_rdpq_fusion(struct megasas_instance
*instance
);
97 static void megasas_free_reply_fusion(struct megasas_instance
*instance
);
102 * megasas_enable_intr_fusion - Enables interrupts
103 * @regs: MFI register set
106 megasas_enable_intr_fusion(struct megasas_instance
*instance
)
108 struct megasas_register_set __iomem
*regs
;
109 regs
= instance
->reg_set
;
111 instance
->mask_interrupts
= 0;
112 /* For Thunderbolt/Invader also clear intr on enable */
113 writel(~0, ®s
->outbound_intr_status
);
114 readl(®s
->outbound_intr_status
);
116 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK
, &(regs
)->outbound_intr_mask
);
118 /* Dummy readl to force pci flush */
119 readl(®s
->outbound_intr_mask
);
123 * megasas_disable_intr_fusion - Disables interrupt
124 * @regs: MFI register set
127 megasas_disable_intr_fusion(struct megasas_instance
*instance
)
129 u32 mask
= 0xFFFFFFFF;
131 struct megasas_register_set __iomem
*regs
;
132 regs
= instance
->reg_set
;
133 instance
->mask_interrupts
= 1;
135 writel(mask
, ®s
->outbound_intr_mask
);
136 /* Dummy readl to force pci flush */
137 status
= readl(®s
->outbound_intr_mask
);
141 megasas_clear_intr_fusion(struct megasas_register_set __iomem
*regs
)
145 * Check if it is our interrupt
147 status
= readl(®s
->outbound_intr_status
);
150 writel(status
, ®s
->outbound_intr_status
);
151 readl(®s
->outbound_intr_status
);
154 if (!(status
& MFI_FUSION_ENABLE_INTERRUPT_MASK
))
161 * megasas_get_cmd_fusion - Get a command from the free pool
162 * @instance: Adapter soft state
164 * Returns a blk_tag indexed mpt frame
166 inline struct megasas_cmd_fusion
*megasas_get_cmd_fusion(struct megasas_instance
167 *instance
, u32 blk_tag
)
169 struct fusion_context
*fusion
;
171 fusion
= instance
->ctrl_context
;
172 return fusion
->cmd_list
[blk_tag
];
176 * megasas_return_cmd_fusion - Return a cmd to free command pool
177 * @instance: Adapter soft state
178 * @cmd: Command packet to be returned to free command pool
180 inline void megasas_return_cmd_fusion(struct megasas_instance
*instance
,
181 struct megasas_cmd_fusion
*cmd
)
184 memset(cmd
->io_request
, 0, sizeof(struct MPI2_RAID_SCSI_IO_REQUEST
));
188 * megasas_fire_cmd_fusion - Sends command to the FW
191 megasas_fire_cmd_fusion(struct megasas_instance
*instance
,
192 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
)
194 #if defined(writeq) && defined(CONFIG_64BIT)
195 u64 req_data
= (((u64
)le32_to_cpu(req_desc
->u
.high
) << 32) |
196 le32_to_cpu(req_desc
->u
.low
));
198 writeq(req_data
, &instance
->reg_set
->inbound_low_queue_port
);
202 spin_lock_irqsave(&instance
->hba_lock
, flags
);
203 writel(le32_to_cpu(req_desc
->u
.low
),
204 &instance
->reg_set
->inbound_low_queue_port
);
205 writel(le32_to_cpu(req_desc
->u
.high
),
206 &instance
->reg_set
->inbound_high_queue_port
);
208 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
213 * megasas_fusion_update_can_queue - Do all Adapter Queue depth related calculations here
214 * @instance: Adapter soft state
215 * fw_boot_context: Whether this function called during probe or after OCR
217 * This function is only for fusion controllers.
218 * Update host can queue, if firmware downgrade max supported firmware commands.
219 * Firmware upgrade case will be skiped because underlying firmware has
220 * more resource than exposed to the OS.
224 megasas_fusion_update_can_queue(struct megasas_instance
*instance
, int fw_boot_context
)
226 u16 cur_max_fw_cmds
= 0;
227 u16 ldio_threshold
= 0;
228 struct megasas_register_set __iomem
*reg_set
;
230 reg_set
= instance
->reg_set
;
232 cur_max_fw_cmds
= readl(&instance
->reg_set
->outbound_scratch_pad_3
) & 0x00FFFF;
234 if (dual_qdepth_disable
|| !cur_max_fw_cmds
)
235 cur_max_fw_cmds
= instance
->instancet
->read_fw_status_reg(reg_set
) & 0x00FFFF;
238 (instance
->instancet
->read_fw_status_reg(reg_set
) & 0x00FFFF) - MEGASAS_FUSION_IOCTL_CMDS
;
240 dev_info(&instance
->pdev
->dev
,
241 "Current firmware maximum commands: %d\t LDIO threshold: %d\n",
242 cur_max_fw_cmds
, ldio_threshold
);
244 if (fw_boot_context
== OCR_CONTEXT
) {
245 cur_max_fw_cmds
= cur_max_fw_cmds
- 1;
246 if (cur_max_fw_cmds
<= instance
->max_fw_cmds
) {
247 instance
->cur_can_queue
=
248 cur_max_fw_cmds
- (MEGASAS_FUSION_INTERNAL_CMDS
+
249 MEGASAS_FUSION_IOCTL_CMDS
);
250 instance
->host
->can_queue
= instance
->cur_can_queue
;
251 instance
->ldio_threshold
= ldio_threshold
;
254 instance
->max_fw_cmds
= cur_max_fw_cmds
;
255 instance
->ldio_threshold
= ldio_threshold
;
257 if (!instance
->is_rdpq
)
258 instance
->max_fw_cmds
= min_t(u16
, instance
->max_fw_cmds
, 1024);
261 * Reduce the max supported cmds by 1. This is to ensure that the
262 * reply_q_sz (1 more than the max cmd that driver may send)
263 * does not exceed max cmds that the FW can support
265 instance
->max_fw_cmds
= instance
->max_fw_cmds
-1;
267 instance
->max_scsi_cmds
= instance
->max_fw_cmds
-
268 (MEGASAS_FUSION_INTERNAL_CMDS
+
269 MEGASAS_FUSION_IOCTL_CMDS
);
270 instance
->cur_can_queue
= instance
->max_scsi_cmds
;
274 * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
275 * @instance: Adapter soft state
278 megasas_free_cmds_fusion(struct megasas_instance
*instance
)
281 struct fusion_context
*fusion
= instance
->ctrl_context
;
282 struct megasas_cmd_fusion
*cmd
;
285 for (i
= 0; i
< instance
->max_fw_cmds
; i
++) {
286 cmd
= fusion
->cmd_list
[i
];
289 pci_pool_free(fusion
->sg_dma_pool
, cmd
->sg_frame
,
290 cmd
->sg_frame_phys_addr
);
292 pci_pool_free(fusion
->sense_dma_pool
, cmd
->sense
,
293 cmd
->sense_phys_addr
);
297 if (fusion
->sg_dma_pool
) {
298 pci_pool_destroy(fusion
->sg_dma_pool
);
299 fusion
->sg_dma_pool
= NULL
;
301 if (fusion
->sense_dma_pool
) {
302 pci_pool_destroy(fusion
->sense_dma_pool
);
303 fusion
->sense_dma_pool
= NULL
;
307 /* Reply Frame, Desc*/
308 if (instance
->is_rdpq
)
309 megasas_free_rdpq_fusion(instance
);
311 megasas_free_reply_fusion(instance
);
313 /* Request Frame, Desc*/
314 if (fusion
->req_frames_desc
)
315 dma_free_coherent(&instance
->pdev
->dev
,
316 fusion
->request_alloc_sz
, fusion
->req_frames_desc
,
317 fusion
->req_frames_desc_phys
);
318 if (fusion
->io_request_frames
)
319 pci_pool_free(fusion
->io_request_frames_pool
,
320 fusion
->io_request_frames
,
321 fusion
->io_request_frames_phys
);
322 if (fusion
->io_request_frames_pool
) {
323 pci_pool_destroy(fusion
->io_request_frames_pool
);
324 fusion
->io_request_frames_pool
= NULL
;
329 for (i
= 0; i
< instance
->max_fw_cmds
; i
++)
330 kfree(fusion
->cmd_list
[i
]);
332 kfree(fusion
->cmd_list
);
336 * megasas_create_sg_sense_fusion - Creates DMA pool for cmd frames
337 * @instance: Adapter soft state
340 static int megasas_create_sg_sense_fusion(struct megasas_instance
*instance
)
344 struct fusion_context
*fusion
;
345 struct megasas_cmd_fusion
*cmd
;
347 fusion
= instance
->ctrl_context
;
348 max_cmd
= instance
->max_fw_cmds
;
351 fusion
->sg_dma_pool
=
352 pci_pool_create("mr_sg", instance
->pdev
,
353 instance
->max_chain_frame_sz
, 4, 0);
354 /* SCSI_SENSE_BUFFERSIZE = 96 bytes */
355 fusion
->sense_dma_pool
=
356 pci_pool_create("mr_sense", instance
->pdev
,
357 SCSI_SENSE_BUFFERSIZE
, 64, 0);
359 if (!fusion
->sense_dma_pool
|| !fusion
->sg_dma_pool
) {
360 dev_err(&instance
->pdev
->dev
,
361 "Failed from %s %d\n", __func__
, __LINE__
);
366 * Allocate and attach a frame to each of the commands in cmd_list
368 for (i
= 0; i
< max_cmd
; i
++) {
369 cmd
= fusion
->cmd_list
[i
];
370 cmd
->sg_frame
= pci_pool_alloc(fusion
->sg_dma_pool
,
371 GFP_KERNEL
, &cmd
->sg_frame_phys_addr
);
373 cmd
->sense
= pci_pool_alloc(fusion
->sense_dma_pool
,
374 GFP_KERNEL
, &cmd
->sense_phys_addr
);
375 if (!cmd
->sg_frame
|| !cmd
->sense
) {
376 dev_err(&instance
->pdev
->dev
,
377 "Failed from %s %d\n", __func__
, __LINE__
);
385 megasas_alloc_cmdlist_fusion(struct megasas_instance
*instance
)
388 struct fusion_context
*fusion
;
390 fusion
= instance
->ctrl_context
;
392 max_cmd
= instance
->max_fw_cmds
;
395 * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
396 * Allocate the dynamic array first and then allocate individual
399 fusion
->cmd_list
= kzalloc(sizeof(struct megasas_cmd_fusion
*) * max_cmd
,
401 if (!fusion
->cmd_list
) {
402 dev_err(&instance
->pdev
->dev
,
403 "Failed from %s %d\n", __func__
, __LINE__
);
407 for (i
= 0; i
< max_cmd
; i
++) {
408 fusion
->cmd_list
[i
] = kzalloc(sizeof(struct megasas_cmd_fusion
),
410 if (!fusion
->cmd_list
[i
]) {
411 dev_err(&instance
->pdev
->dev
,
412 "Failed from %s %d\n", __func__
, __LINE__
);
419 megasas_alloc_request_fusion(struct megasas_instance
*instance
)
421 struct fusion_context
*fusion
;
423 fusion
= instance
->ctrl_context
;
425 fusion
->req_frames_desc
=
426 dma_alloc_coherent(&instance
->pdev
->dev
,
427 fusion
->request_alloc_sz
,
428 &fusion
->req_frames_desc_phys
, GFP_KERNEL
);
429 if (!fusion
->req_frames_desc
) {
430 dev_err(&instance
->pdev
->dev
,
431 "Failed from %s %d\n", __func__
, __LINE__
);
435 fusion
->io_request_frames_pool
=
436 pci_pool_create("mr_ioreq", instance
->pdev
,
437 fusion
->io_frames_alloc_sz
, 16, 0);
439 if (!fusion
->io_request_frames_pool
) {
440 dev_err(&instance
->pdev
->dev
,
441 "Failed from %s %d\n", __func__
, __LINE__
);
445 fusion
->io_request_frames
=
446 pci_pool_alloc(fusion
->io_request_frames_pool
,
447 GFP_KERNEL
, &fusion
->io_request_frames_phys
);
448 if (!fusion
->io_request_frames
) {
449 dev_err(&instance
->pdev
->dev
,
450 "Failed from %s %d\n", __func__
, __LINE__
);
457 megasas_alloc_reply_fusion(struct megasas_instance
*instance
)
460 struct fusion_context
*fusion
;
461 union MPI2_REPLY_DESCRIPTORS_UNION
*reply_desc
;
462 fusion
= instance
->ctrl_context
;
464 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
465 fusion
->reply_frames_desc_pool
=
466 pci_pool_create("mr_reply", instance
->pdev
,
467 fusion
->reply_alloc_sz
* count
, 16, 0);
469 if (!fusion
->reply_frames_desc_pool
) {
470 dev_err(&instance
->pdev
->dev
,
471 "Failed from %s %d\n", __func__
, __LINE__
);
475 fusion
->reply_frames_desc
[0] =
476 pci_pool_alloc(fusion
->reply_frames_desc_pool
,
477 GFP_KERNEL
, &fusion
->reply_frames_desc_phys
[0]);
478 if (!fusion
->reply_frames_desc
[0]) {
479 dev_err(&instance
->pdev
->dev
,
480 "Failed from %s %d\n", __func__
, __LINE__
);
483 reply_desc
= fusion
->reply_frames_desc
[0];
484 for (i
= 0; i
< fusion
->reply_q_depth
* count
; i
++, reply_desc
++)
485 reply_desc
->Words
= cpu_to_le64(ULLONG_MAX
);
487 /* This is not a rdpq mode, but driver still populate
488 * reply_frame_desc array to use same msix index in ISR path.
490 for (i
= 0; i
< (count
- 1); i
++)
491 fusion
->reply_frames_desc
[i
+ 1] =
492 fusion
->reply_frames_desc
[i
] +
493 (fusion
->reply_alloc_sz
)/sizeof(union MPI2_REPLY_DESCRIPTORS_UNION
);
499 megasas_alloc_rdpq_fusion(struct megasas_instance
*instance
)
502 struct fusion_context
*fusion
;
503 union MPI2_REPLY_DESCRIPTORS_UNION
*reply_desc
;
505 fusion
= instance
->ctrl_context
;
507 fusion
->rdpq_virt
= pci_alloc_consistent(instance
->pdev
,
508 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY
) * MAX_MSIX_QUEUES_FUSION
,
510 if (!fusion
->rdpq_virt
) {
511 dev_err(&instance
->pdev
->dev
,
512 "Failed from %s %d\n", __func__
, __LINE__
);
516 memset(fusion
->rdpq_virt
, 0,
517 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY
) * MAX_MSIX_QUEUES_FUSION
);
518 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
519 fusion
->reply_frames_desc_pool
= pci_pool_create("mr_rdpq",
520 instance
->pdev
, fusion
->reply_alloc_sz
, 16, 0);
522 if (!fusion
->reply_frames_desc_pool
) {
523 dev_err(&instance
->pdev
->dev
,
524 "Failed from %s %d\n", __func__
, __LINE__
);
528 for (i
= 0; i
< count
; i
++) {
529 fusion
->reply_frames_desc
[i
] =
530 pci_pool_alloc(fusion
->reply_frames_desc_pool
,
531 GFP_KERNEL
, &fusion
->reply_frames_desc_phys
[i
]);
532 if (!fusion
->reply_frames_desc
[i
]) {
533 dev_err(&instance
->pdev
->dev
,
534 "Failed from %s %d\n", __func__
, __LINE__
);
538 fusion
->rdpq_virt
[i
].RDPQBaseAddress
=
539 fusion
->reply_frames_desc_phys
[i
];
541 reply_desc
= fusion
->reply_frames_desc
[i
];
542 for (j
= 0; j
< fusion
->reply_q_depth
; j
++, reply_desc
++)
543 reply_desc
->Words
= cpu_to_le64(ULLONG_MAX
);
549 megasas_free_rdpq_fusion(struct megasas_instance
*instance
) {
552 struct fusion_context
*fusion
;
554 fusion
= instance
->ctrl_context
;
556 for (i
= 0; i
< MAX_MSIX_QUEUES_FUSION
; i
++) {
557 if (fusion
->reply_frames_desc
[i
])
558 pci_pool_free(fusion
->reply_frames_desc_pool
,
559 fusion
->reply_frames_desc
[i
],
560 fusion
->reply_frames_desc_phys
[i
]);
563 if (fusion
->reply_frames_desc_pool
)
564 pci_pool_destroy(fusion
->reply_frames_desc_pool
);
566 if (fusion
->rdpq_virt
)
567 pci_free_consistent(instance
->pdev
,
568 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY
) * MAX_MSIX_QUEUES_FUSION
,
569 fusion
->rdpq_virt
, fusion
->rdpq_phys
);
573 megasas_free_reply_fusion(struct megasas_instance
*instance
) {
575 struct fusion_context
*fusion
;
577 fusion
= instance
->ctrl_context
;
579 if (fusion
->reply_frames_desc
[0])
580 pci_pool_free(fusion
->reply_frames_desc_pool
,
581 fusion
->reply_frames_desc
[0],
582 fusion
->reply_frames_desc_phys
[0]);
584 if (fusion
->reply_frames_desc_pool
)
585 pci_pool_destroy(fusion
->reply_frames_desc_pool
);
591 * megasas_alloc_cmds_fusion - Allocates the command packets
592 * @instance: Adapter soft state
595 * Each frame has a 32-bit field called context. This context is used to get
596 * back the megasas_cmd_fusion from the frame when a frame gets completed
597 * In this driver, the 32 bit values are the indices into an array cmd_list.
598 * This array is used only to look up the megasas_cmd_fusion given the context.
599 * The free commands themselves are maintained in a linked list called cmd_pool.
601 * cmds are formed in the io_request and sg_frame members of the
602 * megasas_cmd_fusion. The context field is used to get a request descriptor
603 * and is used as SMID of the cmd.
604 * SMID value range is from 1 to max_fw_cmds.
607 megasas_alloc_cmds_fusion(struct megasas_instance
*instance
)
610 struct fusion_context
*fusion
;
611 struct megasas_cmd_fusion
*cmd
;
613 dma_addr_t io_req_base_phys
;
617 fusion
= instance
->ctrl_context
;
619 if (megasas_alloc_cmdlist_fusion(instance
))
622 if (megasas_alloc_request_fusion(instance
))
625 if (instance
->is_rdpq
) {
626 if (megasas_alloc_rdpq_fusion(instance
))
629 if (megasas_alloc_reply_fusion(instance
))
633 /* The first 256 bytes (SMID 0) is not used. Don't add to the cmd list */
634 io_req_base
= fusion
->io_request_frames
+ MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
;
635 io_req_base_phys
= fusion
->io_request_frames_phys
+ MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
;
638 * Add all the commands to command pool (fusion->cmd_pool)
641 /* SMID 0 is reserved. Set SMID/index from 1 */
642 for (i
= 0; i
< instance
->max_fw_cmds
; i
++) {
643 cmd
= fusion
->cmd_list
[i
];
644 offset
= MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
* i
;
645 memset(cmd
, 0, sizeof(struct megasas_cmd_fusion
));
648 cmd
->sync_cmd_idx
= (i
>= instance
->max_scsi_cmds
) ?
649 (i
- instance
->max_scsi_cmds
) :
650 (u32
)ULONG_MAX
; /* Set to Invalid */
651 cmd
->instance
= instance
;
653 (struct MPI2_RAID_SCSI_IO_REQUEST
*)
654 (io_req_base
+ offset
);
655 memset(cmd
->io_request
, 0,
656 sizeof(struct MPI2_RAID_SCSI_IO_REQUEST
));
657 cmd
->io_request_phys_addr
= io_req_base_phys
+ offset
;
660 if (megasas_create_sg_sense_fusion(instance
))
666 megasas_free_cmds_fusion(instance
);
671 * wait_and_poll - Issues a polling command
672 * @instance: Adapter soft state
673 * @cmd: Command packet to be issued
675 * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
678 wait_and_poll(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
682 struct megasas_header
*frame_hdr
= &cmd
->frame
->hdr
;
683 struct fusion_context
*fusion
;
685 u32 msecs
= seconds
* 1000;
687 fusion
= instance
->ctrl_context
;
689 * Wait for cmd_status to change
691 for (i
= 0; (i
< msecs
) && (frame_hdr
->cmd_status
== 0xff); i
+= 20) {
696 if (frame_hdr
->cmd_status
== MFI_STAT_INVALID_STATUS
)
698 else if (frame_hdr
->cmd_status
== MFI_STAT_OK
)
705 * megasas_ioc_init_fusion - Initializes the FW
706 * @instance: Adapter soft state
708 * Issues the IOC Init cmd
711 megasas_ioc_init_fusion(struct megasas_instance
*instance
)
713 struct megasas_init_frame
*init_frame
;
714 struct MPI2_IOC_INIT_REQUEST
*IOCInitMessage
= NULL
;
715 dma_addr_t ioc_init_handle
;
716 struct megasas_cmd
*cmd
;
717 u8 ret
, cur_rdpq_mode
;
718 struct fusion_context
*fusion
;
719 union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc
;
721 struct megasas_header
*frame_hdr
;
722 const char *sys_info
;
723 MFI_CAPABILITIES
*drv_ops
;
726 fusion
= instance
->ctrl_context
;
728 cmd
= megasas_get_cmd(instance
);
731 dev_err(&instance
->pdev
->dev
, "Could not allocate cmd for INIT Frame\n");
736 scratch_pad_2
= readl
737 (&instance
->reg_set
->outbound_scratch_pad_2
);
739 cur_rdpq_mode
= (scratch_pad_2
& MR_RDPQ_MODE_OFFSET
) ? 1 : 0;
741 if (instance
->is_rdpq
&& !cur_rdpq_mode
) {
742 dev_err(&instance
->pdev
->dev
, "Firmware downgrade *NOT SUPPORTED*"
743 " from RDPQ mode to non RDPQ mode\n");
749 dma_alloc_coherent(&instance
->pdev
->dev
,
750 sizeof(struct MPI2_IOC_INIT_REQUEST
),
751 &ioc_init_handle
, GFP_KERNEL
);
753 if (!IOCInitMessage
) {
754 dev_err(&instance
->pdev
->dev
, "Could not allocate memory for "
760 memset(IOCInitMessage
, 0, sizeof(struct MPI2_IOC_INIT_REQUEST
));
762 IOCInitMessage
->Function
= MPI2_FUNCTION_IOC_INIT
;
763 IOCInitMessage
->WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
764 IOCInitMessage
->MsgVersion
= cpu_to_le16(MPI2_VERSION
);
765 IOCInitMessage
->HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
766 IOCInitMessage
->SystemRequestFrameSize
= cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
/ 4);
768 IOCInitMessage
->ReplyDescriptorPostQueueDepth
= cpu_to_le16(fusion
->reply_q_depth
);
769 IOCInitMessage
->ReplyDescriptorPostQueueAddress
= instance
->is_rdpq
?
770 cpu_to_le64(fusion
->rdpq_phys
) :
771 cpu_to_le64(fusion
->reply_frames_desc_phys
[0]);
772 IOCInitMessage
->MsgFlags
= instance
->is_rdpq
?
773 MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE
: 0;
774 IOCInitMessage
->SystemRequestFrameBaseAddress
= cpu_to_le64(fusion
->io_request_frames_phys
);
775 IOCInitMessage
->HostMSIxVectors
= instance
->msix_vectors
;
776 init_frame
= (struct megasas_init_frame
*)cmd
->frame
;
777 memset(init_frame
, 0, MEGAMFI_FRAME_SIZE
);
779 frame_hdr
= &cmd
->frame
->hdr
;
780 frame_hdr
->cmd_status
= 0xFF;
781 frame_hdr
->flags
= cpu_to_le16(
782 le16_to_cpu(frame_hdr
->flags
) |
783 MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
);
785 init_frame
->cmd
= MFI_CMD_INIT
;
786 init_frame
->cmd_status
= 0xFF;
788 drv_ops
= (MFI_CAPABILITIES
*) &(init_frame
->driver_operations
);
790 /* driver support Extended MSIX */
791 if (fusion
->adapter_type
== INVADER_SERIES
)
792 drv_ops
->mfi_capabilities
.support_additional_msix
= 1;
793 /* driver supports HA / Remote LUN over Fast Path interface */
794 drv_ops
->mfi_capabilities
.support_fp_remote_lun
= 1;
796 drv_ops
->mfi_capabilities
.support_max_255lds
= 1;
797 drv_ops
->mfi_capabilities
.support_ndrive_r1_lb
= 1;
798 drv_ops
->mfi_capabilities
.security_protocol_cmds_fw
= 1;
800 if (instance
->max_chain_frame_sz
> MEGASAS_CHAIN_FRAME_SZ_MIN
)
801 drv_ops
->mfi_capabilities
.support_ext_io_size
= 1;
803 drv_ops
->mfi_capabilities
.support_fp_rlbypass
= 1;
804 if (!dual_qdepth_disable
)
805 drv_ops
->mfi_capabilities
.support_ext_queue_depth
= 1;
807 drv_ops
->mfi_capabilities
.support_qd_throttling
= 1;
808 /* Convert capability to LE32 */
809 cpu_to_le32s((u32
*)&init_frame
->driver_operations
.mfi_capabilities
);
811 sys_info
= dmi_get_system_info(DMI_PRODUCT_UUID
);
812 if (instance
->system_info_buf
&& sys_info
) {
813 memcpy(instance
->system_info_buf
->systemId
, sys_info
,
814 strlen(sys_info
) > 64 ? 64 : strlen(sys_info
));
815 instance
->system_info_buf
->systemIdLength
=
816 strlen(sys_info
) > 64 ? 64 : strlen(sys_info
);
817 init_frame
->system_info_lo
= instance
->system_info_h
;
818 init_frame
->system_info_hi
= 0;
821 init_frame
->queue_info_new_phys_addr_hi
=
822 cpu_to_le32(upper_32_bits(ioc_init_handle
));
823 init_frame
->queue_info_new_phys_addr_lo
=
824 cpu_to_le32(lower_32_bits(ioc_init_handle
));
825 init_frame
->data_xfer_len
= cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST
));
827 req_desc
.u
.low
= cpu_to_le32(lower_32_bits(cmd
->frame_phys_addr
));
828 req_desc
.u
.high
= cpu_to_le32(upper_32_bits(cmd
->frame_phys_addr
));
829 req_desc
.MFAIo
.RequestFlags
=
830 (MEGASAS_REQ_DESCRIPT_FLAGS_MFA
<<
831 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
834 * disable the intr before firing the init frame
836 instance
->instancet
->disable_intr(instance
);
838 for (i
= 0; i
< (10 * 1000); i
+= 20) {
839 if (readl(&instance
->reg_set
->doorbell
) & 1)
845 megasas_fire_cmd_fusion(instance
, &req_desc
);
847 wait_and_poll(instance
, cmd
, MFI_POLL_TIMEOUT_SECS
);
849 frame_hdr
= &cmd
->frame
->hdr
;
850 if (frame_hdr
->cmd_status
!= 0) {
854 dev_err(&instance
->pdev
->dev
, "Init cmd success\n");
859 megasas_return_cmd(instance
, cmd
);
861 dma_free_coherent(&instance
->pdev
->dev
,
862 sizeof(struct MPI2_IOC_INIT_REQUEST
),
863 IOCInitMessage
, ioc_init_handle
);
869 * megasas_sync_pd_seq_num - JBOD SEQ MAP
870 * @instance: Adapter soft state
871 * @pend: set to 1, if it is pended jbod map.
873 * Issue Jbod map to the firmware. If it is pended command,
874 * issue command and return. If it is first instance of jbod map
875 * issue and receive command.
878 megasas_sync_pd_seq_num(struct megasas_instance
*instance
, bool pend
) {
881 struct megasas_cmd
*cmd
;
882 struct megasas_dcmd_frame
*dcmd
;
883 struct fusion_context
*fusion
= instance
->ctrl_context
;
884 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
887 pd_sync
= (void *)fusion
->pd_seq_sync
[(instance
->pd_seq_map_id
& 1)];
888 pd_seq_h
= fusion
->pd_seq_phys
[(instance
->pd_seq_map_id
& 1)];
889 pd_seq_map_sz
= sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC
) +
890 (sizeof(struct MR_PD_CFG_SEQ
) *
891 (MAX_PHYSICAL_DEVICES
- 1));
893 cmd
= megasas_get_cmd(instance
);
895 dev_err(&instance
->pdev
->dev
,
896 "Could not get mfi cmd. Fail from %s %d\n",
901 dcmd
= &cmd
->frame
->dcmd
;
903 memset(pd_sync
, 0, pd_seq_map_sz
);
904 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
905 dcmd
->cmd
= MFI_CMD_DCMD
;
906 dcmd
->cmd_status
= 0xFF;
910 dcmd
->data_xfer_len
= cpu_to_le32(pd_seq_map_sz
);
911 dcmd
->opcode
= cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO
);
912 dcmd
->sgl
.sge32
[0].phys_addr
= cpu_to_le32(pd_seq_h
);
913 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32(pd_seq_map_sz
);
916 dcmd
->mbox
.b
[0] = MEGASAS_DCMD_MBOX_PEND_FLAG
;
917 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_WRITE
);
918 instance
->jbod_seq_cmd
= cmd
;
919 instance
->instancet
->issue_dcmd(instance
, cmd
);
923 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_READ
);
925 /* Below code is only for non pended DCMD */
926 if (instance
->ctrl_context
&& !instance
->mask_interrupts
)
927 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
928 MFI_IO_TIMEOUT_SECS
);
930 ret
= megasas_issue_polled(instance
, cmd
);
932 if (le32_to_cpu(pd_sync
->count
) > MAX_PHYSICAL_DEVICES
) {
933 dev_warn(&instance
->pdev
->dev
,
934 "driver supports max %d JBOD, but FW reports %d\n",
935 MAX_PHYSICAL_DEVICES
, le32_to_cpu(pd_sync
->count
));
939 if (ret
== DCMD_TIMEOUT
&& instance
->ctrl_context
)
940 megaraid_sas_kill_hba(instance
);
942 if (ret
== DCMD_SUCCESS
)
943 instance
->pd_seq_map_id
++;
945 megasas_return_cmd(instance
, cmd
);
950 * megasas_get_ld_map_info - Returns FW's ld_map structure
951 * @instance: Adapter soft state
952 * @pend: Pend the command or not
953 * Issues an internal command (DCMD) to get the FW's controller PD
954 * list structure. This information is mainly used to find out SYSTEM
955 * supported by the FW.
956 * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO
957 * dcmd.mbox.b[0] - number of LDs being sync'd
958 * dcmd.mbox.b[1] - 0 - complete command immediately.
959 * - 1 - pend till config change
960 * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP
961 * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and
962 * uses extended struct MR_FW_RAID_MAP_EXT
965 megasas_get_ld_map_info(struct megasas_instance
*instance
)
968 struct megasas_cmd
*cmd
;
969 struct megasas_dcmd_frame
*dcmd
;
973 struct fusion_context
*fusion
;
975 cmd
= megasas_get_cmd(instance
);
978 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get cmd for map info\n");
982 fusion
= instance
->ctrl_context
;
985 megasas_return_cmd(instance
, cmd
);
989 dcmd
= &cmd
->frame
->dcmd
;
991 size_map_info
= fusion
->current_map_sz
;
993 ci
= (void *) fusion
->ld_map
[(instance
->map_id
& 1)];
994 ci_h
= fusion
->ld_map_phys
[(instance
->map_id
& 1)];
997 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to alloc mem for ld_map_info\n");
998 megasas_return_cmd(instance
, cmd
);
1002 memset(ci
, 0, fusion
->max_map_sz
);
1003 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
1005 dev_dbg(&instance
->pdev
->dev
,
1006 "%s sending MR_DCMD_LD_MAP_GET_INFO with size %d\n",
1007 __func__
, cpu_to_le32(size_map_info
));
1009 dcmd
->cmd
= MFI_CMD_DCMD
;
1010 dcmd
->cmd_status
= 0xFF;
1011 dcmd
->sge_count
= 1;
1012 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_READ
);
1015 dcmd
->data_xfer_len
= cpu_to_le32(size_map_info
);
1016 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO
);
1017 dcmd
->sgl
.sge32
[0].phys_addr
= cpu_to_le32(ci_h
);
1018 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32(size_map_info
);
1020 if (instance
->ctrl_context
&& !instance
->mask_interrupts
)
1021 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
1022 MFI_IO_TIMEOUT_SECS
);
1024 ret
= megasas_issue_polled(instance
, cmd
);
1026 if (ret
== DCMD_TIMEOUT
&& instance
->ctrl_context
)
1027 megaraid_sas_kill_hba(instance
);
1029 megasas_return_cmd(instance
, cmd
);
1035 megasas_get_map_info(struct megasas_instance
*instance
)
1037 struct fusion_context
*fusion
= instance
->ctrl_context
;
1039 fusion
->fast_path_io
= 0;
1040 if (!megasas_get_ld_map_info(instance
)) {
1041 if (MR_ValidateMapInfo(instance
)) {
1042 fusion
->fast_path_io
= 1;
1050 * megasas_sync_map_info - Returns FW's ld_map structure
1051 * @instance: Adapter soft state
1053 * Issues an internal command (DCMD) to get the FW's controller PD
1054 * list structure. This information is mainly used to find out SYSTEM
1055 * supported by the FW.
1058 megasas_sync_map_info(struct megasas_instance
*instance
)
1061 struct megasas_cmd
*cmd
;
1062 struct megasas_dcmd_frame
*dcmd
;
1063 u32 size_sync_info
, num_lds
;
1064 struct fusion_context
*fusion
;
1065 struct MR_LD_TARGET_SYNC
*ci
= NULL
;
1066 struct MR_DRV_RAID_MAP_ALL
*map
;
1067 struct MR_LD_RAID
*raid
;
1068 struct MR_LD_TARGET_SYNC
*ld_sync
;
1069 dma_addr_t ci_h
= 0;
1072 cmd
= megasas_get_cmd(instance
);
1075 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get cmd for sync info\n");
1079 fusion
= instance
->ctrl_context
;
1082 megasas_return_cmd(instance
, cmd
);
1086 map
= fusion
->ld_drv_map
[instance
->map_id
& 1];
1088 num_lds
= le16_to_cpu(map
->raidMap
.ldCount
);
1090 dcmd
= &cmd
->frame
->dcmd
;
1092 size_sync_info
= sizeof(struct MR_LD_TARGET_SYNC
) *num_lds
;
1094 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
1096 ci
= (struct MR_LD_TARGET_SYNC
*)
1097 fusion
->ld_map
[(instance
->map_id
- 1) & 1];
1098 memset(ci
, 0, fusion
->max_map_sz
);
1100 ci_h
= fusion
->ld_map_phys
[(instance
->map_id
- 1) & 1];
1102 ld_sync
= (struct MR_LD_TARGET_SYNC
*)ci
;
1104 for (i
= 0; i
< num_lds
; i
++, ld_sync
++) {
1105 raid
= MR_LdRaidGet(i
, map
);
1106 ld_sync
->targetId
= MR_GetLDTgtId(i
, map
);
1107 ld_sync
->seqNum
= raid
->seqNum
;
1110 size_map_info
= fusion
->current_map_sz
;
1112 dcmd
->cmd
= MFI_CMD_DCMD
;
1113 dcmd
->cmd_status
= 0xFF;
1114 dcmd
->sge_count
= 1;
1115 dcmd
->flags
= cpu_to_le16(MFI_FRAME_DIR_WRITE
);
1118 dcmd
->data_xfer_len
= cpu_to_le32(size_map_info
);
1119 dcmd
->mbox
.b
[0] = num_lds
;
1120 dcmd
->mbox
.b
[1] = MEGASAS_DCMD_MBOX_PEND_FLAG
;
1121 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO
);
1122 dcmd
->sgl
.sge32
[0].phys_addr
= cpu_to_le32(ci_h
);
1123 dcmd
->sgl
.sge32
[0].length
= cpu_to_le32(size_map_info
);
1125 instance
->map_update_cmd
= cmd
;
1127 instance
->instancet
->issue_dcmd(instance
, cmd
);
1133 * meagasas_display_intel_branding - Display branding string
1134 * @instance: per adapter object
1139 megasas_display_intel_branding(struct megasas_instance
*instance
)
1141 if (instance
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
1144 switch (instance
->pdev
->device
) {
1145 case PCI_DEVICE_ID_LSI_INVADER
:
1146 switch (instance
->pdev
->subsystem_device
) {
1147 case MEGARAID_INTEL_RS3DC080_SSDID
:
1148 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1149 instance
->host
->host_no
,
1150 MEGARAID_INTEL_RS3DC080_BRANDING
);
1152 case MEGARAID_INTEL_RS3DC040_SSDID
:
1153 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1154 instance
->host
->host_no
,
1155 MEGARAID_INTEL_RS3DC040_BRANDING
);
1157 case MEGARAID_INTEL_RS3SC008_SSDID
:
1158 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1159 instance
->host
->host_no
,
1160 MEGARAID_INTEL_RS3SC008_BRANDING
);
1162 case MEGARAID_INTEL_RS3MC044_SSDID
:
1163 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1164 instance
->host
->host_no
,
1165 MEGARAID_INTEL_RS3MC044_BRANDING
);
1171 case PCI_DEVICE_ID_LSI_FURY
:
1172 switch (instance
->pdev
->subsystem_device
) {
1173 case MEGARAID_INTEL_RS3WC080_SSDID
:
1174 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1175 instance
->host
->host_no
,
1176 MEGARAID_INTEL_RS3WC080_BRANDING
);
1178 case MEGARAID_INTEL_RS3WC040_SSDID
:
1179 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1180 instance
->host
->host_no
,
1181 MEGARAID_INTEL_RS3WC040_BRANDING
);
1187 case PCI_DEVICE_ID_LSI_CUTLASS_52
:
1188 case PCI_DEVICE_ID_LSI_CUTLASS_53
:
1189 switch (instance
->pdev
->subsystem_device
) {
1190 case MEGARAID_INTEL_RMS3BC160_SSDID
:
1191 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1192 instance
->host
->host_no
,
1193 MEGARAID_INTEL_RMS3BC160_BRANDING
);
1205 * megasas_init_adapter_fusion - Initializes the FW
1206 * @instance: Adapter soft state
1208 * This is the main function for initializing firmware.
1211 megasas_init_adapter_fusion(struct megasas_instance
*instance
)
1213 struct megasas_register_set __iomem
*reg_set
;
1214 struct fusion_context
*fusion
;
1215 u32 max_cmd
, scratch_pad_2
;
1218 fusion
= instance
->ctrl_context
;
1220 reg_set
= instance
->reg_set
;
1222 megasas_fusion_update_can_queue(instance
, PROBE_CONTEXT
);
1225 * Reduce the max supported cmds by 1. This is to ensure that the
1226 * reply_q_sz (1 more than the max cmd that driver may send)
1227 * does not exceed max cmds that the FW can support
1229 instance
->max_fw_cmds
= instance
->max_fw_cmds
-1;
1232 * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames
1234 instance
->max_mfi_cmds
=
1235 MEGASAS_FUSION_INTERNAL_CMDS
+ MEGASAS_FUSION_IOCTL_CMDS
;
1237 max_cmd
= instance
->max_fw_cmds
;
1239 fusion
->reply_q_depth
= 2 * (((max_cmd
+ 1 + 15)/16)*16);
1241 fusion
->request_alloc_sz
=
1242 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION
) *max_cmd
;
1243 fusion
->reply_alloc_sz
= sizeof(union MPI2_REPLY_DESCRIPTORS_UNION
)
1244 *(fusion
->reply_q_depth
);
1245 fusion
->io_frames_alloc_sz
= MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
+
1246 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
*
1247 (max_cmd
+ 1)); /* Extra 1 for SMID 0 */
1249 scratch_pad_2
= readl(&instance
->reg_set
->outbound_scratch_pad_2
);
1250 /* If scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set,
1251 * Firmware support extended IO chain frame which is 4 times more than
1253 * Legacy Firmware - Frame size is (8 * 128) = 1K
1254 * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K
1256 if (scratch_pad_2
& MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK
)
1257 instance
->max_chain_frame_sz
=
1258 ((scratch_pad_2
& MEGASAS_MAX_CHAIN_SIZE_MASK
) >>
1259 MEGASAS_MAX_CHAIN_SHIFT
) * MEGASAS_1MB_IO
;
1261 instance
->max_chain_frame_sz
=
1262 ((scratch_pad_2
& MEGASAS_MAX_CHAIN_SIZE_MASK
) >>
1263 MEGASAS_MAX_CHAIN_SHIFT
) * MEGASAS_256K_IO
;
1265 if (instance
->max_chain_frame_sz
< MEGASAS_CHAIN_FRAME_SZ_MIN
) {
1266 dev_warn(&instance
->pdev
->dev
, "frame size %d invalid, fall back to legacy max frame size %d\n",
1267 instance
->max_chain_frame_sz
,
1268 MEGASAS_CHAIN_FRAME_SZ_MIN
);
1269 instance
->max_chain_frame_sz
= MEGASAS_CHAIN_FRAME_SZ_MIN
;
1272 fusion
->max_sge_in_main_msg
=
1273 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1274 - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
, SGL
))/16;
1276 fusion
->max_sge_in_chain
=
1277 instance
->max_chain_frame_sz
1278 / sizeof(union MPI2_SGE_IO_UNION
);
1280 instance
->max_num_sge
=
1281 rounddown_pow_of_two(fusion
->max_sge_in_main_msg
1282 + fusion
->max_sge_in_chain
- 2);
1284 /* Used for pass thru MFI frame (DCMD) */
1285 fusion
->chain_offset_mfi_pthru
=
1286 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
, SGL
)/16;
1288 fusion
->chain_offset_io_request
=
1289 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
-
1290 sizeof(union MPI2_SGE_IO_UNION
))/16;
1292 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
1293 for (i
= 0 ; i
< count
; i
++)
1294 fusion
->last_reply_idx
[i
] = 0;
1297 * For fusion adapters, 3 commands for IOCTL and 5 commands
1298 * for driver's internal DCMDs.
1300 instance
->max_scsi_cmds
= instance
->max_fw_cmds
-
1301 (MEGASAS_FUSION_INTERNAL_CMDS
+
1302 MEGASAS_FUSION_IOCTL_CMDS
);
1303 sema_init(&instance
->ioctl_sem
, MEGASAS_FUSION_IOCTL_CMDS
);
1306 * Allocate memory for descriptors
1307 * Create a pool of commands
1309 if (megasas_alloc_cmds(instance
))
1310 goto fail_alloc_mfi_cmds
;
1311 if (megasas_alloc_cmds_fusion(instance
))
1312 goto fail_alloc_cmds
;
1314 if (megasas_ioc_init_fusion(instance
))
1317 megasas_display_intel_branding(instance
);
1318 if (megasas_get_ctrl_info(instance
)) {
1319 dev_err(&instance
->pdev
->dev
,
1320 "Could not get controller info. Fail from %s %d\n",
1321 __func__
, __LINE__
);
1325 instance
->flag_ieee
= 1;
1326 fusion
->fast_path_io
= 0;
1328 fusion
->drv_map_pages
= get_order(fusion
->drv_map_sz
);
1329 for (i
= 0; i
< 2; i
++) {
1330 fusion
->ld_map
[i
] = NULL
;
1331 fusion
->ld_drv_map
[i
] = (void *)__get_free_pages(GFP_KERNEL
,
1332 fusion
->drv_map_pages
);
1333 if (!fusion
->ld_drv_map
[i
]) {
1334 dev_err(&instance
->pdev
->dev
, "Could not allocate "
1335 "memory for local map info for %d pages\n",
1336 fusion
->drv_map_pages
);
1338 free_pages((ulong
)fusion
->ld_drv_map
[0],
1339 fusion
->drv_map_pages
);
1342 memset(fusion
->ld_drv_map
[i
], 0,
1343 ((1 << PAGE_SHIFT
) << fusion
->drv_map_pages
));
1346 for (i
= 0; i
< 2; i
++) {
1347 fusion
->ld_map
[i
] = dma_alloc_coherent(&instance
->pdev
->dev
,
1349 &fusion
->ld_map_phys
[i
],
1351 if (!fusion
->ld_map
[i
]) {
1352 dev_err(&instance
->pdev
->dev
, "Could not allocate memory "
1358 if (!megasas_get_map_info(instance
))
1359 megasas_sync_map_info(instance
);
1365 dma_free_coherent(&instance
->pdev
->dev
, fusion
->max_map_sz
,
1366 fusion
->ld_map
[0], fusion
->ld_map_phys
[0]);
1368 megasas_free_cmds_fusion(instance
);
1370 megasas_free_cmds(instance
);
1371 fail_alloc_mfi_cmds
:
1376 * map_cmd_status - Maps FW cmd status to OS cmd status
1377 * @cmd : Pointer to cmd
1378 * @status : status of cmd returned by FW
1379 * @ext_status : ext status of cmd returned by FW
1383 map_cmd_status(struct megasas_cmd_fusion
*cmd
, u8 status
, u8 ext_status
)
1389 cmd
->scmd
->result
= DID_OK
<< 16;
1392 case MFI_STAT_SCSI_IO_FAILED
:
1393 case MFI_STAT_LD_INIT_IN_PROGRESS
:
1394 cmd
->scmd
->result
= (DID_ERROR
<< 16) | ext_status
;
1397 case MFI_STAT_SCSI_DONE_WITH_ERROR
:
1399 cmd
->scmd
->result
= (DID_OK
<< 16) | ext_status
;
1400 if (ext_status
== SAM_STAT_CHECK_CONDITION
) {
1401 memset(cmd
->scmd
->sense_buffer
, 0,
1402 SCSI_SENSE_BUFFERSIZE
);
1403 memcpy(cmd
->scmd
->sense_buffer
, cmd
->sense
,
1404 SCSI_SENSE_BUFFERSIZE
);
1405 cmd
->scmd
->result
|= DRIVER_SENSE
<< 24;
1409 case MFI_STAT_LD_OFFLINE
:
1410 case MFI_STAT_DEVICE_NOT_FOUND
:
1411 cmd
->scmd
->result
= DID_BAD_TARGET
<< 16;
1413 case MFI_STAT_CONFIG_SEQ_MISMATCH
:
1414 cmd
->scmd
->result
= DID_IMM_RETRY
<< 16;
1417 dev_printk(KERN_DEBUG
, &cmd
->instance
->pdev
->dev
, "FW status %#x\n", status
);
1418 cmd
->scmd
->result
= DID_ERROR
<< 16;
1424 * megasas_make_sgl_fusion - Prepares 32-bit SGL
1425 * @instance: Adapter soft state
1426 * @scp: SCSI command from the mid-layer
1427 * @sgl_ptr: SGL to be filled in
1428 * @cmd: cmd we are working on
1430 * If successful, this function returns the number of SG elements.
1433 megasas_make_sgl_fusion(struct megasas_instance
*instance
,
1434 struct scsi_cmnd
*scp
,
1435 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr
,
1436 struct megasas_cmd_fusion
*cmd
)
1438 int i
, sg_processed
, sge_count
;
1439 struct scatterlist
*os_sgl
;
1440 struct fusion_context
*fusion
;
1442 fusion
= instance
->ctrl_context
;
1444 if (fusion
->adapter_type
== INVADER_SERIES
) {
1445 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr_end
= sgl_ptr
;
1446 sgl_ptr_end
+= fusion
->max_sge_in_main_msg
- 1;
1447 sgl_ptr_end
->Flags
= 0;
1450 sge_count
= scsi_dma_map(scp
);
1452 BUG_ON(sge_count
< 0);
1454 if (sge_count
> instance
->max_num_sge
|| !sge_count
)
1457 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
1458 sgl_ptr
->Length
= cpu_to_le32(sg_dma_len(os_sgl
));
1459 sgl_ptr
->Address
= cpu_to_le64(sg_dma_address(os_sgl
));
1461 if (fusion
->adapter_type
== INVADER_SERIES
)
1462 if (i
== sge_count
- 1)
1463 sgl_ptr
->Flags
= IEEE_SGE_FLAGS_END_OF_LIST
;
1466 sg_processed
= i
+ 1;
1468 if ((sg_processed
== (fusion
->max_sge_in_main_msg
- 1)) &&
1469 (sge_count
> fusion
->max_sge_in_main_msg
)) {
1471 struct MPI25_IEEE_SGE_CHAIN64
*sg_chain
;
1472 if (fusion
->adapter_type
== INVADER_SERIES
) {
1473 if ((le16_to_cpu(cmd
->io_request
->IoFlags
) &
1474 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
) !=
1475 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
)
1476 cmd
->io_request
->ChainOffset
=
1478 chain_offset_io_request
;
1480 cmd
->io_request
->ChainOffset
= 0;
1482 cmd
->io_request
->ChainOffset
=
1483 fusion
->chain_offset_io_request
;
1486 /* Prepare chain element */
1487 sg_chain
->NextChainOffset
= 0;
1488 if (fusion
->adapter_type
== INVADER_SERIES
)
1489 sg_chain
->Flags
= IEEE_SGE_FLAGS_CHAIN_ELEMENT
;
1492 (IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
1493 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR
);
1494 sg_chain
->Length
= cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION
) * (sge_count
- sg_processed
)));
1495 sg_chain
->Address
= cpu_to_le64(cmd
->sg_frame_phys_addr
);
1498 (struct MPI25_IEEE_SGE_CHAIN64
*)cmd
->sg_frame
;
1499 memset(sgl_ptr
, 0, instance
->max_chain_frame_sz
);
1507 * megasas_set_pd_lba - Sets PD LBA
1509 * @cdb_len: cdb length
1510 * @start_blk: Start block of IO
1512 * Used to set the PD LBA in CDB for FP IOs
1515 megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
, u8 cdb_len
,
1516 struct IO_REQUEST_INFO
*io_info
, struct scsi_cmnd
*scp
,
1517 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
, u32 ref_tag
)
1519 struct MR_LD_RAID
*raid
;
1521 u64 start_blk
= io_info
->pdBlock
;
1522 u8
*cdb
= io_request
->CDB
.CDB32
;
1523 u32 num_blocks
= io_info
->numBlocks
;
1524 u8 opcode
= 0, flagvals
= 0, groupnum
= 0, control
= 0;
1526 /* Check if T10 PI (DIF) is enabled for this LD */
1527 ld
= MR_TargetIdToLdGet(io_info
->ldTgtId
, local_map_ptr
);
1528 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
1529 if (raid
->capability
.ldPiMode
== MR_PROT_INFO_TYPE_CONTROLLER
) {
1530 memset(cdb
, 0, sizeof(io_request
->CDB
.CDB32
));
1531 cdb
[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD
;
1532 cdb
[7] = MEGASAS_SCSI_ADDL_CDB_LEN
;
1534 if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
)
1535 cdb
[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32
;
1537 cdb
[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32
;
1538 cdb
[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL
;
1541 cdb
[12] = (u8
)((start_blk
>> 56) & 0xff);
1542 cdb
[13] = (u8
)((start_blk
>> 48) & 0xff);
1543 cdb
[14] = (u8
)((start_blk
>> 40) & 0xff);
1544 cdb
[15] = (u8
)((start_blk
>> 32) & 0xff);
1545 cdb
[16] = (u8
)((start_blk
>> 24) & 0xff);
1546 cdb
[17] = (u8
)((start_blk
>> 16) & 0xff);
1547 cdb
[18] = (u8
)((start_blk
>> 8) & 0xff);
1548 cdb
[19] = (u8
)(start_blk
& 0xff);
1550 /* Logical block reference tag */
1551 io_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
1552 cpu_to_be32(ref_tag
);
1553 io_request
->CDB
.EEDP32
.PrimaryApplicationTagMask
= cpu_to_be16(0xffff);
1554 io_request
->IoFlags
= cpu_to_le16(32); /* Specify 32-byte cdb */
1556 /* Transfer length */
1557 cdb
[28] = (u8
)((num_blocks
>> 24) & 0xff);
1558 cdb
[29] = (u8
)((num_blocks
>> 16) & 0xff);
1559 cdb
[30] = (u8
)((num_blocks
>> 8) & 0xff);
1560 cdb
[31] = (u8
)(num_blocks
& 0xff);
1562 /* set SCSI IO EEDPFlags */
1563 if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
) {
1564 io_request
->EEDPFlags
= cpu_to_le16(
1565 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
1566 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
1567 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
|
1568 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG
|
1569 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
);
1571 io_request
->EEDPFlags
= cpu_to_le16(
1572 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
1573 MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
);
1575 io_request
->Control
|= cpu_to_le32((0x4 << 26));
1576 io_request
->EEDPBlockSize
= cpu_to_le32(scp
->device
->sector_size
);
1578 /* Some drives don't support 16/12 byte CDB's, convert to 10 */
1579 if (((cdb_len
== 12) || (cdb_len
== 16)) &&
1580 (start_blk
<= 0xffffffff)) {
1581 if (cdb_len
== 16) {
1582 opcode
= cdb
[0] == READ_16
? READ_10
: WRITE_10
;
1587 opcode
= cdb
[0] == READ_12
? READ_10
: WRITE_10
;
1593 memset(cdb
, 0, sizeof(io_request
->CDB
.CDB32
));
1600 /* Transfer length */
1601 cdb
[8] = (u8
)(num_blocks
& 0xff);
1602 cdb
[7] = (u8
)((num_blocks
>> 8) & 0xff);
1604 io_request
->IoFlags
= cpu_to_le16(10); /* Specify 10-byte cdb */
1606 } else if ((cdb_len
< 16) && (start_blk
> 0xffffffff)) {
1607 /* Convert to 16 byte CDB for large LBA's */
1610 opcode
= cdb
[0] == READ_6
? READ_16
: WRITE_16
;
1615 cdb
[0] == READ_10
? READ_16
: WRITE_16
;
1622 cdb
[0] == READ_12
? READ_16
: WRITE_16
;
1629 memset(cdb
, 0, sizeof(io_request
->CDB
.CDB32
));
1636 /* Transfer length */
1637 cdb
[13] = (u8
)(num_blocks
& 0xff);
1638 cdb
[12] = (u8
)((num_blocks
>> 8) & 0xff);
1639 cdb
[11] = (u8
)((num_blocks
>> 16) & 0xff);
1640 cdb
[10] = (u8
)((num_blocks
>> 24) & 0xff);
1642 io_request
->IoFlags
= cpu_to_le16(16); /* Specify 16-byte cdb */
1646 /* Normal case, just load LBA here */
1650 u8 val
= cdb
[1] & 0xE0;
1651 cdb
[3] = (u8
)(start_blk
& 0xff);
1652 cdb
[2] = (u8
)((start_blk
>> 8) & 0xff);
1653 cdb
[1] = val
| ((u8
)(start_blk
>> 16) & 0x1f);
1657 cdb
[5] = (u8
)(start_blk
& 0xff);
1658 cdb
[4] = (u8
)((start_blk
>> 8) & 0xff);
1659 cdb
[3] = (u8
)((start_blk
>> 16) & 0xff);
1660 cdb
[2] = (u8
)((start_blk
>> 24) & 0xff);
1663 cdb
[5] = (u8
)(start_blk
& 0xff);
1664 cdb
[4] = (u8
)((start_blk
>> 8) & 0xff);
1665 cdb
[3] = (u8
)((start_blk
>> 16) & 0xff);
1666 cdb
[2] = (u8
)((start_blk
>> 24) & 0xff);
1669 cdb
[9] = (u8
)(start_blk
& 0xff);
1670 cdb
[8] = (u8
)((start_blk
>> 8) & 0xff);
1671 cdb
[7] = (u8
)((start_blk
>> 16) & 0xff);
1672 cdb
[6] = (u8
)((start_blk
>> 24) & 0xff);
1673 cdb
[5] = (u8
)((start_blk
>> 32) & 0xff);
1674 cdb
[4] = (u8
)((start_blk
>> 40) & 0xff);
1675 cdb
[3] = (u8
)((start_blk
>> 48) & 0xff);
1676 cdb
[2] = (u8
)((start_blk
>> 56) & 0xff);
1683 * megasas_build_ldio_fusion - Prepares IOs to devices
1684 * @instance: Adapter soft state
1685 * @scp: SCSI command
1686 * @cmd: Command to be prepared
1688 * Prepares the io_request and chain elements (sg_frame) for IO
1689 * The IO can be for PD (Fast Path) or LD
1692 megasas_build_ldio_fusion(struct megasas_instance
*instance
,
1693 struct scsi_cmnd
*scp
,
1694 struct megasas_cmd_fusion
*cmd
)
1697 u32 start_lba_lo
, start_lba_hi
, device_id
, datalength
= 0;
1698 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
1699 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
1700 struct IO_REQUEST_INFO io_info
;
1701 struct fusion_context
*fusion
;
1702 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
1705 device_id
= MEGASAS_DEV_INDEX(scp
);
1707 fusion
= instance
->ctrl_context
;
1709 io_request
= cmd
->io_request
;
1710 io_request
->RaidContext
.VirtualDiskTgtId
= cpu_to_le16(device_id
);
1711 io_request
->RaidContext
.status
= 0;
1712 io_request
->RaidContext
.exStatus
= 0;
1714 req_desc
= (union MEGASAS_REQUEST_DESCRIPTOR_UNION
*)cmd
->request_desc
;
1721 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1723 if (scp
->cmd_len
== 6) {
1724 datalength
= (u32
) scp
->cmnd
[4];
1725 start_lba_lo
= ((u32
) scp
->cmnd
[1] << 16) |
1726 ((u32
) scp
->cmnd
[2] << 8) | (u32
) scp
->cmnd
[3];
1728 start_lba_lo
&= 0x1FFFFF;
1732 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1734 else if (scp
->cmd_len
== 10) {
1735 datalength
= (u32
) scp
->cmnd
[8] |
1736 ((u32
) scp
->cmnd
[7] << 8);
1737 start_lba_lo
= ((u32
) scp
->cmnd
[2] << 24) |
1738 ((u32
) scp
->cmnd
[3] << 16) |
1739 ((u32
) scp
->cmnd
[4] << 8) | (u32
) scp
->cmnd
[5];
1743 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1745 else if (scp
->cmd_len
== 12) {
1746 datalength
= ((u32
) scp
->cmnd
[6] << 24) |
1747 ((u32
) scp
->cmnd
[7] << 16) |
1748 ((u32
) scp
->cmnd
[8] << 8) | (u32
) scp
->cmnd
[9];
1749 start_lba_lo
= ((u32
) scp
->cmnd
[2] << 24) |
1750 ((u32
) scp
->cmnd
[3] << 16) |
1751 ((u32
) scp
->cmnd
[4] << 8) | (u32
) scp
->cmnd
[5];
1755 * 16-byte READ(0x88) or WRITE(0x8A) cdb
1757 else if (scp
->cmd_len
== 16) {
1758 datalength
= ((u32
) scp
->cmnd
[10] << 24) |
1759 ((u32
) scp
->cmnd
[11] << 16) |
1760 ((u32
) scp
->cmnd
[12] << 8) | (u32
) scp
->cmnd
[13];
1761 start_lba_lo
= ((u32
) scp
->cmnd
[6] << 24) |
1762 ((u32
) scp
->cmnd
[7] << 16) |
1763 ((u32
) scp
->cmnd
[8] << 8) | (u32
) scp
->cmnd
[9];
1765 start_lba_hi
= ((u32
) scp
->cmnd
[2] << 24) |
1766 ((u32
) scp
->cmnd
[3] << 16) |
1767 ((u32
) scp
->cmnd
[4] << 8) | (u32
) scp
->cmnd
[5];
1770 memset(&io_info
, 0, sizeof(struct IO_REQUEST_INFO
));
1771 io_info
.ldStartBlock
= ((u64
)start_lba_hi
<< 32) | start_lba_lo
;
1772 io_info
.numBlocks
= datalength
;
1773 io_info
.ldTgtId
= device_id
;
1774 io_request
->DataLength
= cpu_to_le32(scsi_bufflen(scp
));
1776 if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
)
1779 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
1781 if ((MR_TargetIdToLdGet(device_id
, local_map_ptr
) >=
1782 instance
->fw_supported_vd_count
) || (!fusion
->fast_path_io
)) {
1783 io_request
->RaidContext
.regLockFlags
= 0;
1786 if (MR_BuildRaidContext(instance
, &io_info
,
1787 &io_request
->RaidContext
,
1788 local_map_ptr
, &raidLUN
))
1789 fp_possible
= io_info
.fpOkForIo
;
1792 /* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU
1793 id by default, not CPU group id, otherwise all MSI-X queues won't
1795 cmd
->request_desc
->SCSIIO
.MSIxIndex
= instance
->msix_vectors
?
1796 raw_smp_processor_id() % instance
->msix_vectors
: 0;
1799 megasas_set_pd_lba(io_request
, scp
->cmd_len
, &io_info
, scp
,
1800 local_map_ptr
, start_lba_lo
);
1801 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
1802 cmd
->request_desc
->SCSIIO
.RequestFlags
=
1803 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
1804 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
1805 if (fusion
->adapter_type
== INVADER_SERIES
) {
1806 if (io_request
->RaidContext
.regLockFlags
==
1808 cmd
->request_desc
->SCSIIO
.RequestFlags
=
1809 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK
<<
1810 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
1811 io_request
->RaidContext
.Type
= MPI2_TYPE_CUDA
;
1812 io_request
->RaidContext
.nseg
= 0x1;
1813 io_request
->IoFlags
|= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
1814 io_request
->RaidContext
.regLockFlags
|=
1815 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA
|
1816 MR_RL_FLAGS_SEQ_NUM_ENABLE
);
1818 if ((fusion
->load_balance_info
[device_id
].loadBalanceFlag
) &&
1821 get_updated_dev_handle(instance
,
1822 &fusion
->load_balance_info
[device_id
],
1824 scp
->SCp
.Status
|= MEGASAS_LOAD_BALANCE_FLAG
;
1825 cmd
->pd_r1_lb
= io_info
.pd_after_lb
;
1827 scp
->SCp
.Status
&= ~MEGASAS_LOAD_BALANCE_FLAG
;
1829 if ((raidLUN
[0] == 1) &&
1830 (local_map_ptr
->raidMap
.devHndlInfo
[io_info
.pd_after_lb
].validHandles
> 1)) {
1831 instance
->dev_handle
= !(instance
->dev_handle
);
1833 local_map_ptr
->raidMap
.devHndlInfo
[io_info
.pd_after_lb
].devHandle
[instance
->dev_handle
];
1836 cmd
->request_desc
->SCSIIO
.DevHandle
= io_info
.devHandle
;
1837 io_request
->DevHandle
= io_info
.devHandle
;
1838 /* populate the LUN field */
1839 memcpy(io_request
->LUN
, raidLUN
, 8);
1841 io_request
->RaidContext
.timeoutValue
=
1842 cpu_to_le16(local_map_ptr
->raidMap
.fpPdIoTimeoutSec
);
1843 cmd
->request_desc
->SCSIIO
.RequestFlags
=
1844 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
1845 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
1846 if (fusion
->adapter_type
== INVADER_SERIES
) {
1847 if (io_info
.do_fp_rlbypass
||
1848 (io_request
->RaidContext
.regLockFlags
== REGION_TYPE_UNUSED
))
1849 cmd
->request_desc
->SCSIIO
.RequestFlags
=
1850 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK
<<
1851 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
1852 io_request
->RaidContext
.Type
= MPI2_TYPE_CUDA
;
1853 io_request
->RaidContext
.regLockFlags
|=
1854 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0
|
1855 MR_RL_FLAGS_SEQ_NUM_ENABLE
);
1856 io_request
->RaidContext
.nseg
= 0x1;
1858 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
1859 io_request
->DevHandle
= cpu_to_le16(device_id
);
1864 * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk
1865 * @instance: Adapter soft state
1866 * @scp: SCSI command
1867 * @cmd: Command to be prepared
1869 * Prepares the io_request frame for non-rw io cmds for vd.
1871 static void megasas_build_ld_nonrw_fusion(struct megasas_instance
*instance
,
1872 struct scsi_cmnd
*scmd
, struct megasas_cmd_fusion
*cmd
)
1875 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
1877 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
1878 struct fusion_context
*fusion
= instance
->ctrl_context
;
1882 struct MR_LD_RAID
*raid
;
1883 struct RAID_CONTEXT
*pRAID_Context
;
1886 io_request
= cmd
->io_request
;
1887 device_id
= MEGASAS_DEV_INDEX(scmd
);
1888 pd_index
= MEGASAS_PD_INDEX(scmd
);
1889 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
1890 io_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
1891 /* get RAID_Context pointer */
1892 pRAID_Context
= &io_request
->RaidContext
;
1893 /* Check with FW team */
1894 pRAID_Context
->VirtualDiskTgtId
= cpu_to_le16(device_id
);
1895 pRAID_Context
->regLockRowLBA
= 0;
1896 pRAID_Context
->regLockLength
= 0;
1898 if (fusion
->fast_path_io
&& (
1899 device_id
< instance
->fw_supported_vd_count
)) {
1901 ld
= MR_TargetIdToLdGet(device_id
, local_map_ptr
);
1902 if (ld
>= instance
->fw_supported_vd_count
)
1905 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
1906 if (!(raid
->capability
.fpNonRWCapable
))
1912 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
1913 io_request
->DevHandle
= cpu_to_le16(device_id
);
1914 io_request
->LUN
[1] = scmd
->device
->lun
;
1915 pRAID_Context
->timeoutValue
=
1916 cpu_to_le16 (scmd
->request
->timeout
/ HZ
);
1917 cmd
->request_desc
->SCSIIO
.RequestFlags
=
1918 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
1919 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
1922 /* set RAID context values */
1923 pRAID_Context
->configSeqNum
= raid
->seqNum
;
1924 pRAID_Context
->regLockFlags
= REGION_TYPE_SHARED_READ
;
1925 pRAID_Context
->timeoutValue
= cpu_to_le16(raid
->fpIoTimeoutForLd
);
1927 /* get the DevHandle for the PD (since this is
1928 fpNonRWCapable, this is a single disk RAID0) */
1930 arRef
= MR_LdSpanArrayGet(ld
, span
, local_map_ptr
);
1931 pd
= MR_ArPdGet(arRef
, physArm
, local_map_ptr
);
1932 devHandle
= MR_PdDevHandleGet(pd
, local_map_ptr
);
1934 /* build request descriptor */
1935 cmd
->request_desc
->SCSIIO
.RequestFlags
=
1936 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
<<
1937 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
1938 cmd
->request_desc
->SCSIIO
.DevHandle
= devHandle
;
1940 /* populate the LUN field */
1941 memcpy(io_request
->LUN
, raid
->LUN
, 8);
1943 /* build the raidScsiIO structure */
1944 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
1945 io_request
->DevHandle
= devHandle
;
1950 * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd
1951 * @instance: Adapter soft state
1952 * @scp: SCSI command
1953 * @cmd: Command to be prepared
1954 * @fp_possible: parameter to detect fast path or firmware path io.
1956 * Prepares the io_request frame for rw/non-rw io cmds for syspds
1959 megasas_build_syspd_fusion(struct megasas_instance
*instance
,
1960 struct scsi_cmnd
*scmd
, struct megasas_cmd_fusion
*cmd
, u8 fp_possible
)
1963 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
1965 u16 os_timeout_value
;
1967 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
1968 struct RAID_CONTEXT
*pRAID_Context
;
1969 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
1970 struct fusion_context
*fusion
= instance
->ctrl_context
;
1971 pd_sync
= (void *)fusion
->pd_seq_sync
[(instance
->pd_seq_map_id
- 1) & 1];
1973 device_id
= MEGASAS_DEV_INDEX(scmd
);
1974 pd_index
= MEGASAS_PD_INDEX(scmd
);
1975 os_timeout_value
= scmd
->request
->timeout
/ HZ
;
1977 io_request
= cmd
->io_request
;
1978 /* get RAID_Context pointer */
1979 pRAID_Context
= &io_request
->RaidContext
;
1980 pRAID_Context
->regLockFlags
= 0;
1981 pRAID_Context
->regLockRowLBA
= 0;
1982 pRAID_Context
->regLockLength
= 0;
1983 io_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
1984 io_request
->LUN
[1] = scmd
->device
->lun
;
1985 pRAID_Context
->RAIDFlags
= MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
1986 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT
;
1988 /* If FW supports PD sequence number */
1989 if (instance
->use_seqnum_jbod_fp
&&
1990 instance
->pd_list
[pd_index
].driveType
== TYPE_DISK
) {
1991 /* TgtId must be incremented by 255 as jbod seq number is index
1994 pRAID_Context
->VirtualDiskTgtId
=
1995 cpu_to_le16(device_id
+ (MAX_PHYSICAL_DEVICES
- 1));
1996 pRAID_Context
->configSeqNum
= pd_sync
->seq
[pd_index
].seqNum
;
1997 io_request
->DevHandle
= pd_sync
->seq
[pd_index
].devHandle
;
1998 pRAID_Context
->regLockFlags
|=
1999 (MR_RL_FLAGS_SEQ_NUM_ENABLE
|MR_RL_FLAGS_GRANT_DESTINATION_CUDA
);
2000 } else if (fusion
->fast_path_io
) {
2001 pRAID_Context
->VirtualDiskTgtId
= cpu_to_le16(device_id
);
2002 pRAID_Context
->configSeqNum
= 0;
2003 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
2004 io_request
->DevHandle
=
2005 local_map_ptr
->raidMap
.devHndlInfo
[device_id
].curDevHdl
;
2007 /* Want to send all IO via FW path */
2008 pRAID_Context
->VirtualDiskTgtId
= cpu_to_le16(device_id
);
2009 pRAID_Context
->configSeqNum
= 0;
2010 io_request
->DevHandle
= cpu_to_le16(0xFFFF);
2013 cmd
->request_desc
->SCSIIO
.DevHandle
= io_request
->DevHandle
;
2014 cmd
->request_desc
->SCSIIO
.MSIxIndex
=
2015 instance
->msix_vectors
?
2016 (raw_smp_processor_id() % instance
->msix_vectors
) : 0;
2020 /* system pd firmware path */
2021 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
2022 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2023 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
2024 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2025 pRAID_Context
->timeoutValue
= cpu_to_le16(os_timeout_value
);
2026 pRAID_Context
->VirtualDiskTgtId
= cpu_to_le16(device_id
);
2028 /* system pd Fast Path */
2029 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2030 timeout_limit
= (scmd
->device
->type
== TYPE_DISK
) ?
2032 pRAID_Context
->timeoutValue
=
2033 cpu_to_le16((os_timeout_value
> timeout_limit
) ?
2034 timeout_limit
: os_timeout_value
);
2035 if (fusion
->adapter_type
== INVADER_SERIES
) {
2036 pRAID_Context
->Type
= MPI2_TYPE_CUDA
;
2037 pRAID_Context
->nseg
= 0x1;
2038 io_request
->IoFlags
|=
2039 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
2041 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2042 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
<<
2043 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2048 * megasas_build_io_fusion - Prepares IOs to devices
2049 * @instance: Adapter soft state
2050 * @scp: SCSI command
2051 * @cmd: Command to be prepared
2053 * Invokes helper functions to prepare request frames
2054 * and sets flags appropriate for IO/Non-IO cmd
2057 megasas_build_io_fusion(struct megasas_instance
*instance
,
2058 struct scsi_cmnd
*scp
,
2059 struct megasas_cmd_fusion
*cmd
)
2063 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
= cmd
->io_request
;
2065 /* Zero out some fields so they don't get reused */
2066 memset(io_request
->LUN
, 0x0, 8);
2067 io_request
->CDB
.EEDP32
.PrimaryReferenceTag
= 0;
2068 io_request
->CDB
.EEDP32
.PrimaryApplicationTagMask
= 0;
2069 io_request
->EEDPFlags
= 0;
2070 io_request
->Control
= 0;
2071 io_request
->EEDPBlockSize
= 0;
2072 io_request
->ChainOffset
= 0;
2073 io_request
->RaidContext
.RAIDFlags
= 0;
2074 io_request
->RaidContext
.Type
= 0;
2075 io_request
->RaidContext
.nseg
= 0;
2077 memcpy(io_request
->CDB
.CDB32
, scp
->cmnd
, scp
->cmd_len
);
2079 * Just the CDB length,rest of the Flags are zero
2080 * This will be modified for FP in build_ldio_fusion
2082 io_request
->IoFlags
= cpu_to_le16(scp
->cmd_len
);
2084 switch (cmd_type
= megasas_cmd_type(scp
)) {
2085 case READ_WRITE_LDIO
:
2086 megasas_build_ldio_fusion(instance
, scp
, cmd
);
2088 case NON_READ_WRITE_LDIO
:
2089 megasas_build_ld_nonrw_fusion(instance
, scp
, cmd
);
2091 case READ_WRITE_SYSPDIO
:
2092 case NON_READ_WRITE_SYSPDIO
:
2093 if (instance
->secure_jbod_support
&&
2094 (cmd_type
== NON_READ_WRITE_SYSPDIO
))
2095 megasas_build_syspd_fusion(instance
, scp
, cmd
, 0);
2097 megasas_build_syspd_fusion(instance
, scp
, cmd
, 1);
2108 megasas_make_sgl_fusion(instance
, scp
,
2109 (struct MPI25_IEEE_SGE_CHAIN64
*)
2110 &io_request
->SGL
, cmd
);
2112 if (sge_count
> instance
->max_num_sge
) {
2113 dev_err(&instance
->pdev
->dev
, "Error. sge_count (0x%x) exceeds "
2114 "max (0x%x) allowed\n", sge_count
,
2115 instance
->max_num_sge
);
2119 /* numSGE store lower 8 bit of sge_count.
2120 * numSGEExt store higher 8 bit of sge_count
2122 io_request
->RaidContext
.numSGE
= sge_count
;
2123 io_request
->RaidContext
.numSGEExt
= (u8
)(sge_count
>> 8);
2125 io_request
->SGLFlags
= cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING
);
2127 if (scp
->sc_data_direction
== PCI_DMA_TODEVICE
)
2128 io_request
->Control
|= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE
);
2129 else if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
)
2130 io_request
->Control
|= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ
);
2132 io_request
->SGLOffset0
=
2133 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
, SGL
) / 4;
2135 io_request
->SenseBufferLowAddress
= cpu_to_le32(cmd
->sense_phys_addr
);
2136 io_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
2139 scp
->SCp
.ptr
= (char *)cmd
;
2144 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*
2145 megasas_get_request_descriptor(struct megasas_instance
*instance
, u16 index
)
2148 struct fusion_context
*fusion
;
2150 if (index
>= instance
->max_fw_cmds
) {
2151 dev_err(&instance
->pdev
->dev
, "Invalid SMID (0x%x)request for "
2152 "descriptor for scsi%d\n", index
,
2153 instance
->host
->host_no
);
2156 fusion
= instance
->ctrl_context
;
2157 p
= fusion
->req_frames_desc
2158 +sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION
) *index
;
2160 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION
*)p
;
2164 * megasas_build_and_issue_cmd_fusion -Main routine for building and
2165 * issuing non IOCTL cmd
2166 * @instance: Adapter soft state
2167 * @scmd: pointer to scsi cmd from OS
2170 megasas_build_and_issue_cmd_fusion(struct megasas_instance
*instance
,
2171 struct scsi_cmnd
*scmd
)
2173 struct megasas_cmd_fusion
*cmd
;
2174 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
2176 struct fusion_context
*fusion
;
2178 fusion
= instance
->ctrl_context
;
2180 if ((megasas_cmd_type(scmd
) == READ_WRITE_LDIO
) &&
2181 instance
->ldio_threshold
&&
2182 (atomic_inc_return(&instance
->ldio_outstanding
) >
2183 instance
->ldio_threshold
)) {
2184 atomic_dec(&instance
->ldio_outstanding
);
2185 return SCSI_MLQUEUE_DEVICE_BUSY
;
2188 cmd
= megasas_get_cmd_fusion(instance
, scmd
->request
->tag
);
2192 req_desc
= megasas_get_request_descriptor(instance
, index
-1);
2194 return SCSI_MLQUEUE_HOST_BUSY
;
2196 req_desc
->Words
= 0;
2197 cmd
->request_desc
= req_desc
;
2199 if (megasas_build_io_fusion(instance
, scmd
, cmd
)) {
2200 megasas_return_cmd_fusion(instance
, cmd
);
2201 dev_err(&instance
->pdev
->dev
, "Error building command\n");
2202 cmd
->request_desc
= NULL
;
2203 return SCSI_MLQUEUE_HOST_BUSY
;
2206 req_desc
= cmd
->request_desc
;
2207 req_desc
->SCSIIO
.SMID
= cpu_to_le16(index
);
2209 if (cmd
->io_request
->ChainOffset
!= 0 &&
2210 cmd
->io_request
->ChainOffset
!= 0xF)
2211 dev_err(&instance
->pdev
->dev
, "The chain offset value is not "
2212 "correct : %x\n", cmd
->io_request
->ChainOffset
);
2215 * Issue the command to the FW
2217 atomic_inc(&instance
->fw_outstanding
);
2219 megasas_fire_cmd_fusion(instance
, req_desc
);
2225 * complete_cmd_fusion - Completes command
2226 * @instance: Adapter soft state
2227 * Completes all commands that is in reply descriptor queue
2230 complete_cmd_fusion(struct megasas_instance
*instance
, u32 MSIxIndex
)
2232 union MPI2_REPLY_DESCRIPTORS_UNION
*desc
;
2233 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*reply_desc
;
2234 struct MPI2_RAID_SCSI_IO_REQUEST
*scsi_io_req
;
2235 struct fusion_context
*fusion
;
2236 struct megasas_cmd
*cmd_mfi
;
2237 struct megasas_cmd_fusion
*cmd_fusion
;
2238 u16 smid
, num_completed
;
2239 u8 reply_descript_type
;
2240 u32 status
, extStatus
, device_id
;
2241 union desc_value d_val
;
2242 struct LD_LOAD_BALANCE_INFO
*lbinfo
;
2243 int threshold_reply_count
= 0;
2244 struct scsi_cmnd
*scmd_local
= NULL
;
2245 struct MR_TASK_MANAGE_REQUEST
*mr_tm_req
;
2246 struct MPI2_SCSI_TASK_MANAGE_REQUEST
*mpi_tm_req
;
2248 fusion
= instance
->ctrl_context
;
2250 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
2253 desc
= fusion
->reply_frames_desc
[MSIxIndex
] +
2254 fusion
->last_reply_idx
[MSIxIndex
];
2256 reply_desc
= (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*)desc
;
2258 d_val
.word
= desc
->Words
;
2260 reply_descript_type
= reply_desc
->ReplyFlags
&
2261 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
2263 if (reply_descript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
2268 while (d_val
.u
.low
!= cpu_to_le32(UINT_MAX
) &&
2269 d_val
.u
.high
!= cpu_to_le32(UINT_MAX
)) {
2270 smid
= le16_to_cpu(reply_desc
->SMID
);
2272 cmd_fusion
= fusion
->cmd_list
[smid
- 1];
2275 (struct MPI2_RAID_SCSI_IO_REQUEST
*)
2276 cmd_fusion
->io_request
;
2278 if (cmd_fusion
->scmd
)
2279 cmd_fusion
->scmd
->SCp
.ptr
= NULL
;
2281 scmd_local
= cmd_fusion
->scmd
;
2282 status
= scsi_io_req
->RaidContext
.status
;
2283 extStatus
= scsi_io_req
->RaidContext
.exStatus
;
2285 switch (scsi_io_req
->Function
) {
2286 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
2287 mr_tm_req
= (struct MR_TASK_MANAGE_REQUEST
*)
2288 cmd_fusion
->io_request
;
2289 mpi_tm_req
= (struct MPI2_SCSI_TASK_MANAGE_REQUEST
*)
2290 &mr_tm_req
->TmRequest
;
2291 dev_dbg(&instance
->pdev
->dev
, "TM completion:"
2292 "type: 0x%x TaskMID: 0x%x\n",
2293 mpi_tm_req
->TaskType
, mpi_tm_req
->TaskMID
);
2294 complete(&cmd_fusion
->done
);
2296 case MPI2_FUNCTION_SCSI_IO_REQUEST
: /*Fast Path IO.*/
2297 /* Update load balancing info */
2298 device_id
= MEGASAS_DEV_INDEX(scmd_local
);
2299 lbinfo
= &fusion
->load_balance_info
[device_id
];
2300 if (cmd_fusion
->scmd
->SCp
.Status
&
2301 MEGASAS_LOAD_BALANCE_FLAG
) {
2302 atomic_dec(&lbinfo
->scsi_pending_cmds
[cmd_fusion
->pd_r1_lb
]);
2303 cmd_fusion
->scmd
->SCp
.Status
&=
2304 ~MEGASAS_LOAD_BALANCE_FLAG
;
2306 if (reply_descript_type
==
2307 MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS
) {
2308 if (megasas_dbg_lvl
== 5)
2309 dev_err(&instance
->pdev
->dev
, "\nFAST Path "
2312 /* Fall thru and complete IO */
2313 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
: /* LD-IO Path */
2314 /* Map the FW Cmd Status */
2315 map_cmd_status(cmd_fusion
, status
, extStatus
);
2316 scsi_io_req
->RaidContext
.status
= 0;
2317 scsi_io_req
->RaidContext
.exStatus
= 0;
2318 if (megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
)
2319 atomic_dec(&instance
->ldio_outstanding
);
2320 megasas_return_cmd_fusion(instance
, cmd_fusion
);
2321 scsi_dma_unmap(scmd_local
);
2322 scmd_local
->scsi_done(scmd_local
);
2323 atomic_dec(&instance
->fw_outstanding
);
2326 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST
: /*MFI command */
2327 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
2329 /* Poll mode. Dummy free.
2330 * In case of Interrupt mode, caller has reverse check.
2332 if (cmd_mfi
->flags
& DRV_DCMD_POLLED_MODE
) {
2333 cmd_mfi
->flags
&= ~DRV_DCMD_POLLED_MODE
;
2334 megasas_return_cmd(instance
, cmd_mfi
);
2336 megasas_complete_cmd(instance
, cmd_mfi
, DID_OK
);
2340 fusion
->last_reply_idx
[MSIxIndex
]++;
2341 if (fusion
->last_reply_idx
[MSIxIndex
] >=
2342 fusion
->reply_q_depth
)
2343 fusion
->last_reply_idx
[MSIxIndex
] = 0;
2345 desc
->Words
= cpu_to_le64(ULLONG_MAX
);
2347 threshold_reply_count
++;
2349 /* Get the next reply descriptor */
2350 if (!fusion
->last_reply_idx
[MSIxIndex
])
2351 desc
= fusion
->reply_frames_desc
[MSIxIndex
];
2356 (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*)desc
;
2358 d_val
.word
= desc
->Words
;
2360 reply_descript_type
= reply_desc
->ReplyFlags
&
2361 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
2363 if (reply_descript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
2366 * Write to reply post host index register after completing threshold
2367 * number of reply counts and still there are more replies in reply queue
2368 * pending to be completed
2370 if (threshold_reply_count
>= THRESHOLD_REPLY_COUNT
) {
2371 if (fusion
->adapter_type
== INVADER_SERIES
)
2372 writel(((MSIxIndex
& 0x7) << 24) |
2373 fusion
->last_reply_idx
[MSIxIndex
],
2374 instance
->reply_post_host_index_addr
[MSIxIndex
/8]);
2376 writel((MSIxIndex
<< 24) |
2377 fusion
->last_reply_idx
[MSIxIndex
],
2378 instance
->reply_post_host_index_addr
[0]);
2379 threshold_reply_count
= 0;
2387 if (fusion
->adapter_type
== INVADER_SERIES
)
2388 writel(((MSIxIndex
& 0x7) << 24) |
2389 fusion
->last_reply_idx
[MSIxIndex
],
2390 instance
->reply_post_host_index_addr
[MSIxIndex
/8]);
2392 writel((MSIxIndex
<< 24) |
2393 fusion
->last_reply_idx
[MSIxIndex
],
2394 instance
->reply_post_host_index_addr
[0]);
2395 megasas_check_and_restore_queue_depth(instance
);
2400 * megasas_complete_cmd_dpc_fusion - Completes command
2401 * @instance: Adapter soft state
2403 * Tasklet to complete cmds
2406 megasas_complete_cmd_dpc_fusion(unsigned long instance_addr
)
2408 struct megasas_instance
*instance
=
2409 (struct megasas_instance
*)instance_addr
;
2410 unsigned long flags
;
2411 u32 count
, MSIxIndex
;
2413 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
2415 /* If we have already declared adapter dead, donot complete cmds */
2416 spin_lock_irqsave(&instance
->hba_lock
, flags
);
2417 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
2418 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
2421 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
2423 for (MSIxIndex
= 0 ; MSIxIndex
< count
; MSIxIndex
++)
2424 complete_cmd_fusion(instance
, MSIxIndex
);
2428 * megasas_isr_fusion - isr entry point
2430 irqreturn_t
megasas_isr_fusion(int irq
, void *devp
)
2432 struct megasas_irq_context
*irq_context
= devp
;
2433 struct megasas_instance
*instance
= irq_context
->instance
;
2434 u32 mfiStatus
, fw_state
, dma_state
;
2436 if (instance
->mask_interrupts
)
2439 if (!instance
->msix_vectors
) {
2440 mfiStatus
= instance
->instancet
->clear_intr(instance
->reg_set
);
2445 /* If we are resetting, bail */
2446 if (test_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
)) {
2447 instance
->instancet
->clear_intr(instance
->reg_set
);
2451 if (!complete_cmd_fusion(instance
, irq_context
->MSIxIndex
)) {
2452 instance
->instancet
->clear_intr(instance
->reg_set
);
2453 /* If we didn't complete any commands, check for FW fault */
2454 fw_state
= instance
->instancet
->read_fw_status_reg(
2455 instance
->reg_set
) & MFI_STATE_MASK
;
2456 dma_state
= instance
->instancet
->read_fw_status_reg
2457 (instance
->reg_set
) & MFI_STATE_DMADONE
;
2458 if (instance
->crash_dump_drv_support
&&
2459 instance
->crash_dump_app_support
) {
2460 /* Start collecting crash, if DMA bit is done */
2461 if ((fw_state
== MFI_STATE_FAULT
) && dma_state
)
2462 schedule_work(&instance
->crash_init
);
2463 else if (fw_state
== MFI_STATE_FAULT
)
2464 schedule_work(&instance
->work_init
);
2465 } else if (fw_state
== MFI_STATE_FAULT
) {
2466 dev_warn(&instance
->pdev
->dev
, "Iop2SysDoorbellInt"
2467 "for scsi%d\n", instance
->host
->host_no
);
2468 schedule_work(&instance
->work_init
);
2476 * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
2477 * @instance: Adapter soft state
2478 * mfi_cmd: megasas_cmd pointer
2482 build_mpt_mfi_pass_thru(struct megasas_instance
*instance
,
2483 struct megasas_cmd
*mfi_cmd
)
2485 struct MPI25_IEEE_SGE_CHAIN64
*mpi25_ieee_chain
;
2486 struct MPI2_RAID_SCSI_IO_REQUEST
*io_req
;
2487 struct megasas_cmd_fusion
*cmd
;
2488 struct fusion_context
*fusion
;
2489 struct megasas_header
*frame_hdr
= &mfi_cmd
->frame
->hdr
;
2491 fusion
= instance
->ctrl_context
;
2493 cmd
= megasas_get_cmd_fusion(instance
,
2494 instance
->max_scsi_cmds
+ mfi_cmd
->index
);
2496 /* Save the smid. To be used for returning the cmd */
2497 mfi_cmd
->context
.smid
= cmd
->index
;
2500 * For cmds where the flag is set, store the flag and check
2501 * on completion. For cmds with this flag, don't call
2502 * megasas_complete_cmd
2505 if (frame_hdr
->flags
& cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
))
2506 mfi_cmd
->flags
|= DRV_DCMD_POLLED_MODE
;
2508 io_req
= cmd
->io_request
;
2510 if (fusion
->adapter_type
== INVADER_SERIES
) {
2511 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr_end
=
2512 (struct MPI25_IEEE_SGE_CHAIN64
*)&io_req
->SGL
;
2513 sgl_ptr_end
+= fusion
->max_sge_in_main_msg
- 1;
2514 sgl_ptr_end
->Flags
= 0;
2518 (struct MPI25_IEEE_SGE_CHAIN64
*)&io_req
->SGL
.IeeeChain
;
2520 io_req
->Function
= MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST
;
2521 io_req
->SGLOffset0
= offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
,
2523 io_req
->ChainOffset
= fusion
->chain_offset_mfi_pthru
;
2525 mpi25_ieee_chain
->Address
= cpu_to_le64(mfi_cmd
->frame_phys_addr
);
2527 mpi25_ieee_chain
->Flags
= IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
2528 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR
;
2530 mpi25_ieee_chain
->Length
= cpu_to_le32(instance
->max_chain_frame_sz
);
2536 * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
2537 * @instance: Adapter soft state
2538 * @cmd: mfi cmd to build
2541 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*
2542 build_mpt_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
2544 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
2547 if (build_mpt_mfi_pass_thru(instance
, cmd
)) {
2548 dev_err(&instance
->pdev
->dev
, "Couldn't build MFI pass thru cmd\n");
2552 index
= cmd
->context
.smid
;
2554 req_desc
= megasas_get_request_descriptor(instance
, index
- 1);
2559 req_desc
->Words
= 0;
2560 req_desc
->SCSIIO
.RequestFlags
= (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
2561 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2563 req_desc
->SCSIIO
.SMID
= cpu_to_le16(index
);
2569 * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
2570 * @instance: Adapter soft state
2571 * @cmd: mfi cmd pointer
2575 megasas_issue_dcmd_fusion(struct megasas_instance
*instance
,
2576 struct megasas_cmd
*cmd
)
2578 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
2580 req_desc
= build_mpt_cmd(instance
, cmd
);
2582 dev_info(&instance
->pdev
->dev
, "Failed from %s %d\n",
2583 __func__
, __LINE__
);
2584 return DCMD_NOT_FIRED
;
2587 megasas_fire_cmd_fusion(instance
, req_desc
);
2588 return DCMD_SUCCESS
;
2592 * megasas_release_fusion - Reverses the FW initialization
2593 * @instance: Adapter soft state
2596 megasas_release_fusion(struct megasas_instance
*instance
)
2598 megasas_free_cmds(instance
);
2599 megasas_free_cmds_fusion(instance
);
2601 iounmap(instance
->reg_set
);
2603 pci_release_selected_regions(instance
->pdev
, instance
->bar
);
2607 * megasas_read_fw_status_reg_fusion - returns the current FW status value
2608 * @regs: MFI register set
2611 megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem
*regs
)
2613 return readl(&(regs
)->outbound_scratch_pad
);
2617 * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware
2618 * @instance: Controller's soft instance
2619 * return: Number of allocated host crash buffers
2622 megasas_alloc_host_crash_buffer(struct megasas_instance
*instance
)
2626 instance
->crash_buf_pages
= get_order(CRASH_DMA_BUF_SIZE
);
2627 for (i
= 0; i
< MAX_CRASH_DUMP_SIZE
; i
++) {
2628 instance
->crash_buf
[i
] = (void *)__get_free_pages(GFP_KERNEL
,
2629 instance
->crash_buf_pages
);
2630 if (!instance
->crash_buf
[i
]) {
2631 dev_info(&instance
->pdev
->dev
, "Firmware crash dump "
2632 "memory allocation failed at index %d\n", i
);
2635 memset(instance
->crash_buf
[i
], 0,
2636 ((1 << PAGE_SHIFT
) << instance
->crash_buf_pages
));
2638 instance
->drv_buf_alloc
= i
;
2642 * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware
2643 * @instance: Controller's soft instance
2646 megasas_free_host_crash_buffer(struct megasas_instance
*instance
)
2650 for (i
= 0; i
< instance
->drv_buf_alloc
; i
++) {
2651 if (instance
->crash_buf
[i
])
2652 free_pages((ulong
)instance
->crash_buf
[i
],
2653 instance
->crash_buf_pages
);
2655 instance
->drv_buf_index
= 0;
2656 instance
->drv_buf_alloc
= 0;
2657 instance
->fw_crash_state
= UNAVAILABLE
;
2658 instance
->fw_crash_buffer_size
= 0;
2662 * megasas_adp_reset_fusion - For controller reset
2663 * @regs: MFI register set
2666 megasas_adp_reset_fusion(struct megasas_instance
*instance
,
2667 struct megasas_register_set __iomem
*regs
)
2669 u32 host_diag
, abs_state
, retry
;
2671 /* Now try to reset the chip */
2672 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
2673 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
2674 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
2675 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
2676 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
2677 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
2678 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
2680 /* Check that the diag write enable (DRWE) bit is on */
2681 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
2683 while (!(host_diag
& HOST_DIAG_WRITE_ENABLE
)) {
2685 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
2686 if (retry
++ == 100) {
2687 dev_warn(&instance
->pdev
->dev
,
2688 "Host diag unlock failed from %s %d\n",
2689 __func__
, __LINE__
);
2693 if (!(host_diag
& HOST_DIAG_WRITE_ENABLE
))
2696 /* Send chip reset command */
2697 writel(host_diag
| HOST_DIAG_RESET_ADAPTER
,
2698 &instance
->reg_set
->fusion_host_diag
);
2701 /* Make sure reset adapter bit is cleared */
2702 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
2704 while (host_diag
& HOST_DIAG_RESET_ADAPTER
) {
2706 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
2707 if (retry
++ == 1000) {
2708 dev_warn(&instance
->pdev
->dev
,
2709 "Diag reset adapter never cleared %s %d\n",
2710 __func__
, __LINE__
);
2714 if (host_diag
& HOST_DIAG_RESET_ADAPTER
)
2717 abs_state
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
)
2721 while ((abs_state
<= MFI_STATE_FW_INIT
) && (retry
++ < 1000)) {
2723 abs_state
= instance
->instancet
->
2724 read_fw_status_reg(instance
->reg_set
) & MFI_STATE_MASK
;
2726 if (abs_state
<= MFI_STATE_FW_INIT
) {
2727 dev_warn(&instance
->pdev
->dev
,
2728 "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n",
2729 abs_state
, __func__
, __LINE__
);
2737 * megasas_check_reset_fusion - For controller reset check
2738 * @regs: MFI register set
2741 megasas_check_reset_fusion(struct megasas_instance
*instance
,
2742 struct megasas_register_set __iomem
*regs
)
2747 /* This function waits for outstanding commands on fusion to complete */
2748 int megasas_wait_for_outstanding_fusion(struct megasas_instance
*instance
,
2749 int reason
, int *convert
)
2751 int i
, outstanding
, retval
= 0, hb_seconds_missed
= 0;
2754 for (i
= 0; i
< resetwaittime
; i
++) {
2755 /* Check if firmware is in fault state */
2756 fw_state
= instance
->instancet
->read_fw_status_reg(
2757 instance
->reg_set
) & MFI_STATE_MASK
;
2758 if (fw_state
== MFI_STATE_FAULT
) {
2759 dev_warn(&instance
->pdev
->dev
, "Found FW in FAULT state,"
2760 " will reset adapter scsi%d.\n",
2761 instance
->host
->host_no
);
2766 if (reason
== MFI_IO_TIMEOUT_OCR
) {
2767 dev_info(&instance
->pdev
->dev
,
2768 "MFI IO is timed out, initiating OCR\n");
2773 /* If SR-IOV VF mode & heartbeat timeout, don't wait */
2774 if (instance
->requestorId
&& !reason
) {
2779 /* If SR-IOV VF mode & I/O timeout, check for HB timeout */
2780 if (instance
->requestorId
&& reason
) {
2781 if (instance
->hb_host_mem
->HB
.fwCounter
!=
2782 instance
->hb_host_mem
->HB
.driverCounter
) {
2783 instance
->hb_host_mem
->HB
.driverCounter
=
2784 instance
->hb_host_mem
->HB
.fwCounter
;
2785 hb_seconds_missed
= 0;
2787 hb_seconds_missed
++;
2788 if (hb_seconds_missed
==
2789 (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
/HZ
)) {
2790 dev_warn(&instance
->pdev
->dev
, "SR-IOV:"
2791 " Heartbeat never completed "
2792 " while polling during I/O "
2793 " timeout handling for "
2795 instance
->host
->host_no
);
2803 outstanding
= atomic_read(&instance
->fw_outstanding
);
2807 if (!(i
% MEGASAS_RESET_NOTICE_INTERVAL
)) {
2808 dev_notice(&instance
->pdev
->dev
, "[%2d]waiting for %d "
2809 "commands to complete for scsi%d\n", i
,
2810 outstanding
, instance
->host
->host_no
);
2811 megasas_complete_cmd_dpc_fusion(
2812 (unsigned long)instance
);
2817 if (atomic_read(&instance
->fw_outstanding
)) {
2818 dev_err(&instance
->pdev
->dev
, "pending commands remain after waiting, "
2819 "will reset adapter scsi%d.\n",
2820 instance
->host
->host_no
);
2827 void megasas_reset_reply_desc(struct megasas_instance
*instance
)
2830 struct fusion_context
*fusion
;
2831 union MPI2_REPLY_DESCRIPTORS_UNION
*reply_desc
;
2833 fusion
= instance
->ctrl_context
;
2834 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
2835 for (i
= 0 ; i
< count
; i
++) {
2836 fusion
->last_reply_idx
[i
] = 0;
2837 reply_desc
= fusion
->reply_frames_desc
[i
];
2838 for (j
= 0 ; j
< fusion
->reply_q_depth
; j
++, reply_desc
++)
2839 reply_desc
->Words
= cpu_to_le64(ULLONG_MAX
);
2844 * megasas_refire_mgmt_cmd : Re-fire management commands
2845 * @instance: Controller's soft instance
2847 void megasas_refire_mgmt_cmd(struct megasas_instance
*instance
)
2850 struct megasas_cmd_fusion
*cmd_fusion
;
2851 struct fusion_context
*fusion
;
2852 struct megasas_cmd
*cmd_mfi
;
2853 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
2855 bool refire_cmd
= 0;
2857 fusion
= instance
->ctrl_context
;
2859 /* Re-fire management commands.
2860 * Do not traverse complet MPT frame pool. Start from max_scsi_cmds.
2862 for (j
= instance
->max_scsi_cmds
; j
< instance
->max_fw_cmds
; j
++) {
2863 cmd_fusion
= fusion
->cmd_list
[j
];
2864 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
2865 smid
= le16_to_cpu(cmd_mfi
->context
.smid
);
2869 req_desc
= megasas_get_request_descriptor
2870 (instance
, smid
- 1);
2871 refire_cmd
= req_desc
&& ((cmd_mfi
->frame
->dcmd
.opcode
!=
2872 cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO
)) &&
2873 (cmd_mfi
->frame
->dcmd
.opcode
!=
2874 cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO
)))
2875 && !(cmd_mfi
->flags
& DRV_DCMD_SKIP_REFIRE
);
2877 megasas_fire_cmd_fusion(instance
, req_desc
);
2879 megasas_return_cmd(instance
, cmd_mfi
);
2884 * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device
2885 * @instance: per adapter struct
2886 * @channel: the channel assigned by the OS
2887 * @id: the id assigned by the OS
2889 * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED
2892 static int megasas_track_scsiio(struct megasas_instance
*instance
,
2893 int id
, int channel
)
2896 struct megasas_cmd_fusion
*cmd_fusion
;
2897 struct fusion_context
*fusion
;
2898 fusion
= instance
->ctrl_context
;
2900 for (i
= 0 ; i
< instance
->max_scsi_cmds
; i
++) {
2901 cmd_fusion
= fusion
->cmd_list
[i
];
2902 if (cmd_fusion
->scmd
&&
2903 (cmd_fusion
->scmd
->device
->id
== id
&&
2904 cmd_fusion
->scmd
->device
->channel
== channel
)) {
2905 dev_info(&instance
->pdev
->dev
,
2906 "SCSI commands pending to target"
2907 "channel %d id %d \tSMID: 0x%x\n",
2908 channel
, id
, cmd_fusion
->index
);
2909 scsi_print_command(cmd_fusion
->scmd
);
2915 return found
? FAILED
: SUCCESS
;
2919 * megasas_tm_response_code - translation of device response code
2920 * @ioc: per adapter object
2921 * @mpi_reply: MPI reply returned by firmware
2926 megasas_tm_response_code(struct megasas_instance
*instance
,
2927 struct MPI2_SCSI_TASK_MANAGE_REPLY
*mpi_reply
)
2931 switch (mpi_reply
->ResponseCode
) {
2932 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
2933 desc
= "task management request completed";
2935 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
2936 desc
= "invalid frame";
2938 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
2939 desc
= "task management request not supported";
2941 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
2942 desc
= "task management request failed";
2944 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
2945 desc
= "task management request succeeded";
2947 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
2948 desc
= "invalid lun";
2951 desc
= "overlapped tag attempted";
2953 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
2954 desc
= "task queued, however not sent to target";
2960 dev_dbg(&instance
->pdev
->dev
, "response_code(%01x): %s\n",
2961 mpi_reply
->ResponseCode
, desc
);
2962 dev_dbg(&instance
->pdev
->dev
,
2963 "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo"
2964 " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n",
2965 mpi_reply
->TerminationCount
, mpi_reply
->DevHandle
,
2966 mpi_reply
->Function
, mpi_reply
->TaskType
,
2967 mpi_reply
->IOCStatus
, mpi_reply
->IOCLogInfo
);
2971 * megasas_issue_tm - main routine for sending tm requests
2972 * @instance: per adapter struct
2973 * @device_handle: device handle
2974 * @channel: the channel assigned by the OS
2975 * @id: the id assigned by the OS
2976 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c)
2977 * @smid_task: smid assigned to the task
2978 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
2981 * MegaRaid use MPT interface for Task Magement request.
2982 * A generic API for sending task management requests to firmware.
2984 * Return SUCCESS or FAILED.
2987 megasas_issue_tm(struct megasas_instance
*instance
, u16 device_handle
,
2988 uint channel
, uint id
, u16 smid_task
, u8 type
)
2990 struct MR_TASK_MANAGE_REQUEST
*mr_request
;
2991 struct MPI2_SCSI_TASK_MANAGE_REQUEST
*mpi_request
;
2992 unsigned long timeleft
;
2993 struct megasas_cmd_fusion
*cmd_fusion
;
2994 struct megasas_cmd
*cmd_mfi
;
2995 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
2996 struct fusion_context
*fusion
;
2997 struct megasas_cmd_fusion
*scsi_lookup
;
2999 struct MPI2_SCSI_TASK_MANAGE_REPLY
*mpi_reply
;
3001 fusion
= instance
->ctrl_context
;
3003 cmd_mfi
= megasas_get_cmd(instance
);
3006 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
3007 __func__
, __LINE__
);
3011 cmd_fusion
= megasas_get_cmd_fusion(instance
,
3012 instance
->max_scsi_cmds
+ cmd_mfi
->index
);
3014 /* Save the smid. To be used for returning the cmd */
3015 cmd_mfi
->context
.smid
= cmd_fusion
->index
;
3017 req_desc
= megasas_get_request_descriptor(instance
,
3018 (cmd_fusion
->index
- 1));
3020 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
3021 __func__
, __LINE__
);
3022 megasas_return_cmd(instance
, cmd_mfi
);
3026 cmd_fusion
->request_desc
= req_desc
;
3027 req_desc
->Words
= 0;
3029 scsi_lookup
= fusion
->cmd_list
[smid_task
- 1];
3031 mr_request
= (struct MR_TASK_MANAGE_REQUEST
*) cmd_fusion
->io_request
;
3032 memset(mr_request
, 0, sizeof(struct MR_TASK_MANAGE_REQUEST
));
3033 mpi_request
= (struct MPI2_SCSI_TASK_MANAGE_REQUEST
*) &mr_request
->TmRequest
;
3034 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
3035 mpi_request
->DevHandle
= cpu_to_le16(device_handle
);
3036 mpi_request
->TaskType
= type
;
3037 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
3038 mpi_request
->LUN
[1] = 0;
3041 req_desc
= cmd_fusion
->request_desc
;
3042 req_desc
->HighPriority
.SMID
= cpu_to_le16(cmd_fusion
->index
);
3043 req_desc
->HighPriority
.RequestFlags
=
3044 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
<<
3045 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
3046 req_desc
->HighPriority
.MSIxIndex
= 0;
3047 req_desc
->HighPriority
.LMID
= 0;
3048 req_desc
->HighPriority
.Reserved1
= 0;
3050 if (channel
< MEGASAS_MAX_PD_CHANNELS
)
3051 mr_request
->tmReqFlags
.isTMForPD
= 1;
3053 mr_request
->tmReqFlags
.isTMForLD
= 1;
3055 init_completion(&cmd_fusion
->done
);
3056 megasas_fire_cmd_fusion(instance
, req_desc
);
3058 timeleft
= wait_for_completion_timeout(&cmd_fusion
->done
, 50 * HZ
);
3061 dev_err(&instance
->pdev
->dev
,
3062 "task mgmt type 0x%x timed out\n", type
);
3063 cmd_mfi
->flags
|= DRV_DCMD_SKIP_REFIRE
;
3064 mutex_unlock(&instance
->reset_mutex
);
3065 rc
= megasas_reset_fusion(instance
->host
, MFI_IO_TIMEOUT_OCR
);
3066 mutex_lock(&instance
->reset_mutex
);
3070 mpi_reply
= (struct MPI2_SCSI_TASK_MANAGE_REPLY
*) &mr_request
->TMReply
;
3071 megasas_tm_response_code(instance
, mpi_reply
);
3073 megasas_return_cmd(instance
, cmd_mfi
);
3076 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
3077 if (scsi_lookup
->scmd
== NULL
)
3080 instance
->instancet
->disable_intr(instance
);
3082 megasas_complete_cmd_dpc_fusion
3083 ((unsigned long)instance
);
3084 instance
->instancet
->enable_intr(instance
);
3085 if (scsi_lookup
->scmd
== NULL
)
3091 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
3092 if ((channel
== 0xFFFFFFFF) && (id
== 0xFFFFFFFF))
3094 instance
->instancet
->disable_intr(instance
);
3096 megasas_complete_cmd_dpc_fusion
3097 ((unsigned long)instance
);
3098 rc
= megasas_track_scsiio(instance
, id
, channel
);
3099 instance
->instancet
->enable_intr(instance
);
3102 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
3103 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
3115 * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI
3116 * @instance: per adapter struct
3118 * Return Non Zero index, if SMID found in outstanding commands
3120 static u16
megasas_fusion_smid_lookup(struct scsi_cmnd
*scmd
)
3123 struct megasas_instance
*instance
;
3124 struct megasas_cmd_fusion
*cmd_fusion
;
3125 struct fusion_context
*fusion
;
3127 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
3129 fusion
= instance
->ctrl_context
;
3131 for (i
= 0; i
< instance
->max_scsi_cmds
; i
++) {
3132 cmd_fusion
= fusion
->cmd_list
[i
];
3133 if (cmd_fusion
->scmd
&& (cmd_fusion
->scmd
== scmd
)) {
3134 scmd_printk(KERN_NOTICE
, scmd
, "Abort request is for"
3135 " SMID: %d\n", cmd_fusion
->index
);
3136 ret
= cmd_fusion
->index
;
3145 * megasas_get_tm_devhandle - Get devhandle for TM request
3146 * @sdev- OS provided scsi device
3148 * Returns- devhandle/targetID of SCSI device
3150 static u16
megasas_get_tm_devhandle(struct scsi_device
*sdev
)
3154 struct megasas_instance
*instance
;
3155 struct fusion_context
*fusion
;
3156 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
3157 u16 devhandle
= (u16
)ULONG_MAX
;
3159 instance
= (struct megasas_instance
*)sdev
->host
->hostdata
;
3160 fusion
= instance
->ctrl_context
;
3162 if (sdev
->channel
< MEGASAS_MAX_PD_CHANNELS
) {
3163 if (instance
->use_seqnum_jbod_fp
) {
3164 pd_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
) +
3166 pd_sync
= (void *)fusion
->pd_seq_sync
3167 [(instance
->pd_seq_map_id
- 1) & 1];
3168 devhandle
= pd_sync
->seq
[pd_index
].devHandle
;
3170 sdev_printk(KERN_ERR
, sdev
, "Firmware expose tmCapable"
3171 " without JBOD MAP support from %s %d\n", __func__
, __LINE__
);
3173 device_id
= ((sdev
->channel
% 2) * MEGASAS_MAX_DEV_PER_CHANNEL
)
3175 devhandle
= device_id
;
3182 * megasas_task_abort_fusion : SCSI task abort function for fusion adapters
3183 * @scmd : pointer to scsi command object
3185 * Return SUCCESS, if command aborted else FAILED
3188 int megasas_task_abort_fusion(struct scsi_cmnd
*scmd
)
3190 struct megasas_instance
*instance
;
3191 u16 smid
, devhandle
;
3192 struct fusion_context
*fusion
;
3194 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
3195 mr_device_priv_data
= scmd
->device
->hostdata
;
3198 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
3199 fusion
= instance
->ctrl_context
;
3201 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
3202 dev_err(&instance
->pdev
->dev
, "Controller is not OPERATIONAL,"
3203 "SCSI host:%d\n", instance
->host
->host_no
);
3208 if (!mr_device_priv_data
) {
3209 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
3210 "scmd(%p)\n", scmd
);
3211 scmd
->result
= DID_NO_CONNECT
<< 16;
3217 if (!mr_device_priv_data
->is_tm_capable
) {
3222 mutex_lock(&instance
->reset_mutex
);
3224 smid
= megasas_fusion_smid_lookup(scmd
);
3228 scmd_printk(KERN_NOTICE
, scmd
, "Command for which abort is"
3229 " issued is not found in oustanding commands\n");
3230 mutex_unlock(&instance
->reset_mutex
);
3234 devhandle
= megasas_get_tm_devhandle(scmd
->device
);
3236 if (devhandle
== (u16
)ULONG_MAX
) {
3238 sdev_printk(KERN_INFO
, scmd
->device
,
3239 "task abort issued for invalid devhandle\n");
3240 mutex_unlock(&instance
->reset_mutex
);
3243 sdev_printk(KERN_INFO
, scmd
->device
,
3244 "attempting task abort! scmd(%p) tm_dev_handle 0x%x\n",
3247 mr_device_priv_data
->tm_busy
= 1;
3248 ret
= megasas_issue_tm(instance
, devhandle
,
3249 scmd
->device
->channel
, scmd
->device
->id
, smid
,
3250 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
);
3251 mr_device_priv_data
->tm_busy
= 0;
3253 mutex_unlock(&instance
->reset_mutex
);
3255 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
3256 ((ret
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
3262 * megasas_reset_target_fusion : target reset function for fusion adapters
3263 * scmd: SCSI command pointer
3265 * Returns SUCCESS if all commands associated with target aborted else FAILED
3268 int megasas_reset_target_fusion(struct scsi_cmnd
*scmd
)
3271 struct megasas_instance
*instance
;
3274 struct fusion_context
*fusion
;
3275 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
3276 mr_device_priv_data
= scmd
->device
->hostdata
;
3278 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
3279 fusion
= instance
->ctrl_context
;
3281 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
3282 dev_err(&instance
->pdev
->dev
, "Controller is not OPERATIONAL,"
3283 "SCSI host:%d\n", instance
->host
->host_no
);
3288 if (!mr_device_priv_data
) {
3289 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
3290 "scmd(%p)\n", scmd
);
3291 scmd
->result
= DID_NO_CONNECT
<< 16;
3297 if (!mr_device_priv_data
->is_tm_capable
) {
3302 mutex_lock(&instance
->reset_mutex
);
3303 devhandle
= megasas_get_tm_devhandle(scmd
->device
);
3305 if (devhandle
== (u16
)ULONG_MAX
) {
3307 sdev_printk(KERN_INFO
, scmd
->device
,
3308 "target reset issued for invalid devhandle\n");
3309 mutex_unlock(&instance
->reset_mutex
);
3313 sdev_printk(KERN_INFO
, scmd
->device
,
3314 "attempting target reset! scmd(%p) tm_dev_handle 0x%x\n",
3316 mr_device_priv_data
->tm_busy
= 1;
3317 ret
= megasas_issue_tm(instance
, devhandle
,
3318 scmd
->device
->channel
, scmd
->device
->id
, 0,
3319 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
);
3320 mr_device_priv_data
->tm_busy
= 0;
3321 mutex_unlock(&instance
->reset_mutex
);
3323 scmd_printk(KERN_NOTICE
, scmd
, "megasas: target reset %s!!\n",
3324 (ret
== SUCCESS
) ? "SUCCESS" : "FAILED");
3329 /*SRIOV get other instance in cluster if any*/
3330 struct megasas_instance
*megasas_get_peer_instance(struct megasas_instance
*instance
)
3334 for (i
= 0; i
< MAX_MGMT_ADAPTERS
; i
++) {
3335 if (megasas_mgmt_info
.instance
[i
] &&
3336 (megasas_mgmt_info
.instance
[i
] != instance
) &&
3337 megasas_mgmt_info
.instance
[i
]->requestorId
&&
3338 megasas_mgmt_info
.instance
[i
]->peerIsPresent
&&
3339 (memcmp((megasas_mgmt_info
.instance
[i
]->clusterId
),
3340 instance
->clusterId
, MEGASAS_CLUSTER_ID_SIZE
) == 0))
3341 return megasas_mgmt_info
.instance
[i
];
3346 /* Check for a second path that is currently UP */
3347 int megasas_check_mpio_paths(struct megasas_instance
*instance
,
3348 struct scsi_cmnd
*scmd
)
3350 struct megasas_instance
*peer_instance
= NULL
;
3351 int retval
= (DID_RESET
<< 16);
3353 if (instance
->peerIsPresent
) {
3354 peer_instance
= megasas_get_peer_instance(instance
);
3355 if ((peer_instance
) &&
3356 (atomic_read(&peer_instance
->adprecovery
) ==
3357 MEGASAS_HBA_OPERATIONAL
))
3358 retval
= (DID_NO_CONNECT
<< 16);
3363 /* Core fusion reset function */
3364 int megasas_reset_fusion(struct Scsi_Host
*shost
, int reason
)
3366 int retval
= SUCCESS
, i
, convert
= 0;
3367 struct megasas_instance
*instance
;
3368 struct megasas_cmd_fusion
*cmd_fusion
;
3369 struct fusion_context
*fusion
;
3370 u32 abs_state
, status_reg
, reset_adapter
;
3371 u32 io_timeout_in_crash_mode
= 0;
3372 struct scsi_cmnd
*scmd_local
= NULL
;
3373 struct scsi_device
*sdev
;
3375 instance
= (struct megasas_instance
*)shost
->hostdata
;
3376 fusion
= instance
->ctrl_context
;
3378 mutex_lock(&instance
->reset_mutex
);
3380 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
3381 dev_warn(&instance
->pdev
->dev
, "Hardware critical error, "
3382 "returning FAILED for scsi%d.\n",
3383 instance
->host
->host_no
);
3384 mutex_unlock(&instance
->reset_mutex
);
3387 status_reg
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
);
3388 abs_state
= status_reg
& MFI_STATE_MASK
;
3390 /* IO timeout detected, forcibly put FW in FAULT state */
3391 if (abs_state
!= MFI_STATE_FAULT
&& instance
->crash_dump_buf
&&
3392 instance
->crash_dump_app_support
&& reason
) {
3393 dev_info(&instance
->pdev
->dev
, "IO/DCMD timeout is detected, "
3394 "forcibly FAULT Firmware\n");
3395 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
3396 status_reg
= readl(&instance
->reg_set
->doorbell
);
3397 writel(status_reg
| MFI_STATE_FORCE_OCR
,
3398 &instance
->reg_set
->doorbell
);
3399 readl(&instance
->reg_set
->doorbell
);
3400 mutex_unlock(&instance
->reset_mutex
);
3403 io_timeout_in_crash_mode
++;
3404 dev_dbg(&instance
->pdev
->dev
, "waiting for [%d] "
3405 "seconds for crash dump collection and OCR "
3406 "to be done\n", (io_timeout_in_crash_mode
* 3));
3407 } while ((atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) &&
3408 (io_timeout_in_crash_mode
< 80));
3410 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HBA_OPERATIONAL
) {
3411 dev_info(&instance
->pdev
->dev
, "OCR done for IO "
3415 dev_info(&instance
->pdev
->dev
, "Controller is not "
3416 "operational after 240 seconds wait for IO "
3417 "timeout case in FW crash dump mode\n do "
3418 "OCR/kill adapter\n");
3419 retval
= megasas_reset_fusion(shost
, 0);
3424 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
3425 del_timer_sync(&instance
->sriov_heartbeat_timer
);
3426 set_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
3427 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_POLLING
);
3428 instance
->instancet
->disable_intr(instance
);
3431 /* First try waiting for commands to complete */
3432 if (megasas_wait_for_outstanding_fusion(instance
, reason
,
3434 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
3435 dev_warn(&instance
->pdev
->dev
, "resetting fusion "
3436 "adapter scsi%d.\n", instance
->host
->host_no
);
3440 /* Now return commands back to the OS */
3441 for (i
= 0 ; i
< instance
->max_scsi_cmds
; i
++) {
3442 cmd_fusion
= fusion
->cmd_list
[i
];
3443 scmd_local
= cmd_fusion
->scmd
;
3444 if (cmd_fusion
->scmd
) {
3445 scmd_local
->result
=
3446 megasas_check_mpio_paths(instance
,
3448 if (megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
)
3449 atomic_dec(&instance
->ldio_outstanding
);
3450 megasas_return_cmd_fusion(instance
, cmd_fusion
);
3451 scsi_dma_unmap(scmd_local
);
3452 scmd_local
->scsi_done(scmd_local
);
3453 atomic_dec(&instance
->fw_outstanding
);
3457 status_reg
= instance
->instancet
->read_fw_status_reg(
3459 abs_state
= status_reg
& MFI_STATE_MASK
;
3460 reset_adapter
= status_reg
& MFI_RESET_ADAPTER
;
3461 if (instance
->disableOnlineCtrlReset
||
3462 (abs_state
== MFI_STATE_FAULT
&& !reset_adapter
)) {
3463 /* Reset not supported, kill adapter */
3464 dev_warn(&instance
->pdev
->dev
, "Reset not supported"
3465 ", killing adapter scsi%d.\n",
3466 instance
->host
->host_no
);
3467 megaraid_sas_kill_hba(instance
);
3468 instance
->skip_heartbeat_timer_del
= 1;
3473 /* Let SR-IOV VF & PF sync up if there was a HB failure */
3474 if (instance
->requestorId
&& !reason
) {
3475 msleep(MEGASAS_OCR_SETTLE_TIME_VF
);
3476 goto transition_to_ready
;
3479 /* Now try to reset the chip */
3480 for (i
= 0; i
< MEGASAS_FUSION_MAX_RESET_TRIES
; i
++) {
3482 if (instance
->instancet
->adp_reset
3483 (instance
, instance
->reg_set
))
3485 transition_to_ready
:
3486 /* Wait for FW to become ready */
3487 if (megasas_transition_to_ready(instance
, 1)) {
3488 dev_warn(&instance
->pdev
->dev
,
3489 "Failed to transition controller to ready for "
3490 "scsi%d.\n", instance
->host
->host_no
);
3491 if (instance
->requestorId
&& !reason
)
3492 goto fail_kill_adapter
;
3496 megasas_reset_reply_desc(instance
);
3497 megasas_fusion_update_can_queue(instance
, OCR_CONTEXT
);
3499 if (megasas_ioc_init_fusion(instance
)) {
3500 dev_warn(&instance
->pdev
->dev
,
3501 "megasas_ioc_init_fusion() failed! for "
3502 "scsi%d\n", instance
->host
->host_no
);
3503 if (instance
->requestorId
&& !reason
)
3504 goto fail_kill_adapter
;
3509 megasas_refire_mgmt_cmd(instance
);
3511 if (megasas_get_ctrl_info(instance
)) {
3512 dev_info(&instance
->pdev
->dev
,
3513 "Failed from %s %d\n",
3514 __func__
, __LINE__
);
3515 megaraid_sas_kill_hba(instance
);
3518 /* Reset load balance info */
3519 memset(fusion
->load_balance_info
, 0,
3520 sizeof(struct LD_LOAD_BALANCE_INFO
)
3521 *MAX_LOGICAL_DRIVES_EXT
);
3523 if (!megasas_get_map_info(instance
))
3524 megasas_sync_map_info(instance
);
3526 megasas_setup_jbod_map(instance
);
3528 shost_for_each_device(sdev
, shost
)
3529 megasas_update_sdev_properties(sdev
);
3531 clear_bit(MEGASAS_FUSION_IN_RESET
,
3532 &instance
->reset_flags
);
3533 instance
->instancet
->enable_intr(instance
);
3534 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
3536 /* Restart SR-IOV heartbeat */
3537 if (instance
->requestorId
) {
3538 if (!megasas_sriov_start_heartbeat(instance
, 0))
3539 megasas_start_timer(instance
,
3540 &instance
->sriov_heartbeat_timer
,
3541 megasas_sriov_heartbeat_handler
,
3542 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
);
3544 instance
->skip_heartbeat_timer_del
= 1;
3547 /* Adapter reset completed successfully */
3548 dev_warn(&instance
->pdev
->dev
, "Reset "
3549 "successful for scsi%d.\n",
3550 instance
->host
->host_no
);
3552 if (instance
->crash_dump_drv_support
&&
3553 instance
->crash_dump_app_support
)
3554 megasas_set_crash_dump_params(instance
,
3555 MR_CRASH_BUF_TURN_ON
);
3557 megasas_set_crash_dump_params(instance
,
3558 MR_CRASH_BUF_TURN_OFF
);
3564 /* Reset failed, kill the adapter */
3565 dev_warn(&instance
->pdev
->dev
, "Reset failed, killing "
3566 "adapter scsi%d.\n", instance
->host
->host_no
);
3567 megaraid_sas_kill_hba(instance
);
3568 instance
->skip_heartbeat_timer_del
= 1;
3571 /* For VF: Restart HB timer if we didn't OCR */
3572 if (instance
->requestorId
) {
3573 megasas_start_timer(instance
,
3574 &instance
->sriov_heartbeat_timer
,
3575 megasas_sriov_heartbeat_handler
,
3576 MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
);
3578 clear_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
3579 instance
->instancet
->enable_intr(instance
);
3580 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
3583 clear_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
3584 mutex_unlock(&instance
->reset_mutex
);
3588 /* Fusion Crash dump collection work queue */
3589 void megasas_fusion_crash_dump_wq(struct work_struct
*work
)
3591 struct megasas_instance
*instance
=
3592 container_of(work
, struct megasas_instance
, crash_init
);
3594 u8 partial_copy
= 0;
3597 status_reg
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
);
3600 * Allocate host crash buffers to copy data from 1 MB DMA crash buffer
3601 * to host crash buffers
3603 if (instance
->drv_buf_index
== 0) {
3604 /* Buffer is already allocated for old Crash dump.
3605 * Do OCR and do not wait for crash dump collection
3607 if (instance
->drv_buf_alloc
) {
3608 dev_info(&instance
->pdev
->dev
, "earlier crash dump is "
3609 "not yet copied by application, ignoring this "
3610 "crash dump and initiating OCR\n");
3611 status_reg
|= MFI_STATE_CRASH_DUMP_DONE
;
3613 &instance
->reg_set
->outbound_scratch_pad
);
3614 readl(&instance
->reg_set
->outbound_scratch_pad
);
3617 megasas_alloc_host_crash_buffer(instance
);
3618 dev_info(&instance
->pdev
->dev
, "Number of host crash buffers "
3619 "allocated: %d\n", instance
->drv_buf_alloc
);
3623 * Driver has allocated max buffers, which can be allocated
3624 * and FW has more crash dump data, then driver will
3627 if (instance
->drv_buf_index
>= (instance
->drv_buf_alloc
)) {
3628 dev_info(&instance
->pdev
->dev
, "Driver is done copying "
3629 "the buffer: %d\n", instance
->drv_buf_alloc
);
3630 status_reg
|= MFI_STATE_CRASH_DUMP_DONE
;
3633 memcpy(instance
->crash_buf
[instance
->drv_buf_index
],
3634 instance
->crash_dump_buf
, CRASH_DMA_BUF_SIZE
);
3635 instance
->drv_buf_index
++;
3636 status_reg
&= ~MFI_STATE_DMADONE
;
3639 if (status_reg
& MFI_STATE_CRASH_DUMP_DONE
) {
3640 dev_info(&instance
->pdev
->dev
, "Crash Dump is available,number "
3641 "of copied buffers: %d\n", instance
->drv_buf_index
);
3642 instance
->fw_crash_buffer_size
= instance
->drv_buf_index
;
3643 instance
->fw_crash_state
= AVAILABLE
;
3644 instance
->drv_buf_index
= 0;
3645 writel(status_reg
, &instance
->reg_set
->outbound_scratch_pad
);
3646 readl(&instance
->reg_set
->outbound_scratch_pad
);
3648 megasas_reset_fusion(instance
->host
, 0);
3650 writel(status_reg
, &instance
->reg_set
->outbound_scratch_pad
);
3651 readl(&instance
->reg_set
->outbound_scratch_pad
);
3656 /* Fusion OCR work queue */
3657 void megasas_fusion_ocr_wq(struct work_struct
*work
)
3659 struct megasas_instance
*instance
=
3660 container_of(work
, struct megasas_instance
, work_init
);
3662 megasas_reset_fusion(instance
->host
, 0);
3665 struct megasas_instance_template megasas_instance_template_fusion
= {
3666 .enable_intr
= megasas_enable_intr_fusion
,
3667 .disable_intr
= megasas_disable_intr_fusion
,
3668 .clear_intr
= megasas_clear_intr_fusion
,
3669 .read_fw_status_reg
= megasas_read_fw_status_reg_fusion
,
3670 .adp_reset
= megasas_adp_reset_fusion
,
3671 .check_reset
= megasas_check_reset_fusion
,
3672 .service_isr
= megasas_isr_fusion
,
3673 .tasklet
= megasas_complete_cmd_dpc_fusion
,
3674 .init_adapter
= megasas_init_adapter_fusion
,
3675 .build_and_issue_cmd
= megasas_build_and_issue_cmd_fusion
,
3676 .issue_dcmd
= megasas_issue_dcmd_fusion
,