2 * Linux MegaRAID driver for SAS based RAID controllers
4 * Copyright (c) 2009-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * FILE: megaraid_sas_fusion.c
22 * Authors: Avago Technologies
25 * Kashyap Desai <kashyap.desai@avagotech.com>
26 * Sumit Saxena <sumit.saxena@avagotech.com>
28 * Send feedback to: megaraidlinux.pdl@avagotech.com
30 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
31 * San Jose, California 95131
34 #include <linux/kernel.h>
35 #include <linux/types.h>
36 #include <linux/pci.h>
37 #include <linux/list.h>
38 #include <linux/moduleparam.h>
39 #include <linux/module.h>
40 #include <linux/spinlock.h>
41 #include <linux/interrupt.h>
42 #include <linux/delay.h>
43 #include <linux/uio.h>
44 #include <linux/uaccess.h>
46 #include <linux/compat.h>
47 #include <linux/blkdev.h>
48 #include <linux/mutex.h>
49 #include <linux/poll.h>
50 #include <linux/vmalloc.h>
52 #include <scsi/scsi.h>
53 #include <scsi/scsi_cmnd.h>
54 #include <scsi/scsi_device.h>
55 #include <scsi/scsi_host.h>
56 #include <scsi/scsi_dbg.h>
57 #include <linux/dmi.h>
59 #include "megaraid_sas_fusion.h"
60 #include "megaraid_sas.h"
63 extern void megasas_free_cmds(struct megasas_instance
*instance
);
64 extern struct megasas_cmd
*megasas_get_cmd(struct megasas_instance
67 megasas_complete_cmd(struct megasas_instance
*instance
,
68 struct megasas_cmd
*cmd
, u8 alt_status
);
70 wait_and_poll(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
74 megasas_return_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
);
75 int megasas_alloc_cmds(struct megasas_instance
*instance
);
77 megasas_clear_intr_fusion(struct megasas_register_set __iomem
*regs
);
79 megasas_issue_polled(struct megasas_instance
*instance
,
80 struct megasas_cmd
*cmd
);
82 megasas_check_and_restore_queue_depth(struct megasas_instance
*instance
);
84 int megasas_transition_to_ready(struct megasas_instance
*instance
, int ocr
);
85 void megaraid_sas_kill_hba(struct megasas_instance
*instance
);
87 extern u32 megasas_dbg_lvl
;
88 int megasas_sriov_start_heartbeat(struct megasas_instance
*instance
,
90 void megasas_start_timer(struct megasas_instance
*instance
);
91 extern struct megasas_mgmt_info megasas_mgmt_info
;
92 extern unsigned int resetwaittime
;
93 extern unsigned int dual_qdepth_disable
;
94 static void megasas_free_rdpq_fusion(struct megasas_instance
*instance
);
95 static void megasas_free_reply_fusion(struct megasas_instance
*instance
);
97 void megasas_configure_queue_sizes(struct megasas_instance
*instance
);
100 * megasas_check_same_4gb_region - check if allocation
101 * crosses same 4GB boundary or not
102 * @instance - adapter's soft instance
103 * start_addr - start address of DMA allocation
104 * size - size of allocation in bytes
105 * return - true : allocation does not cross same
107 * false: allocation crosses same
110 static inline bool megasas_check_same_4gb_region
111 (struct megasas_instance
*instance
, dma_addr_t start_addr
, size_t size
)
115 end_addr
= start_addr
+ size
;
117 if (upper_32_bits(start_addr
) != upper_32_bits(end_addr
)) {
118 dev_err(&instance
->pdev
->dev
,
119 "Failed to get same 4GB boundary: start_addr: 0x%llx end_addr: 0x%llx\n",
120 (unsigned long long)start_addr
,
121 (unsigned long long)end_addr
);
129 * megasas_enable_intr_fusion - Enables interrupts
130 * @regs: MFI register set
133 megasas_enable_intr_fusion(struct megasas_instance
*instance
)
135 struct megasas_register_set __iomem
*regs
;
136 regs
= instance
->reg_set
;
138 instance
->mask_interrupts
= 0;
139 /* For Thunderbolt/Invader also clear intr on enable */
140 writel(~0, ®s
->outbound_intr_status
);
141 readl(®s
->outbound_intr_status
);
143 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK
, &(regs
)->outbound_intr_mask
);
145 /* Dummy readl to force pci flush */
146 readl(®s
->outbound_intr_mask
);
150 * megasas_disable_intr_fusion - Disables interrupt
151 * @regs: MFI register set
154 megasas_disable_intr_fusion(struct megasas_instance
*instance
)
156 u32 mask
= 0xFFFFFFFF;
158 struct megasas_register_set __iomem
*regs
;
159 regs
= instance
->reg_set
;
160 instance
->mask_interrupts
= 1;
162 writel(mask
, ®s
->outbound_intr_mask
);
163 /* Dummy readl to force pci flush */
164 status
= readl(®s
->outbound_intr_mask
);
168 megasas_clear_intr_fusion(struct megasas_register_set __iomem
*regs
)
172 * Check if it is our interrupt
174 status
= readl(®s
->outbound_intr_status
);
177 writel(status
, ®s
->outbound_intr_status
);
178 readl(®s
->outbound_intr_status
);
181 if (!(status
& MFI_FUSION_ENABLE_INTERRUPT_MASK
))
188 * megasas_get_cmd_fusion - Get a command from the free pool
189 * @instance: Adapter soft state
191 * Returns a blk_tag indexed mpt frame
193 inline struct megasas_cmd_fusion
*megasas_get_cmd_fusion(struct megasas_instance
194 *instance
, u32 blk_tag
)
196 struct fusion_context
*fusion
;
198 fusion
= instance
->ctrl_context
;
199 return fusion
->cmd_list
[blk_tag
];
203 * megasas_return_cmd_fusion - Return a cmd to free command pool
204 * @instance: Adapter soft state
205 * @cmd: Command packet to be returned to free command pool
207 inline void megasas_return_cmd_fusion(struct megasas_instance
*instance
,
208 struct megasas_cmd_fusion
*cmd
)
211 memset(cmd
->io_request
, 0, MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
);
212 cmd
->r1_alt_dev_handle
= MR_DEVHANDLE_INVALID
;
213 cmd
->cmd_completed
= false;
217 * megasas_fire_cmd_fusion - Sends command to the FW
218 * @instance: Adapter soft state
219 * @req_desc: 32bit or 64bit Request descriptor
221 * Perform PCI Write. Ventura supports 32 bit Descriptor.
222 * Prior to Ventura (12G) MR controller supports 64 bit Descriptor.
226 megasas_fire_cmd_fusion(struct megasas_instance
*instance
,
227 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
)
229 if (instance
->adapter_type
== VENTURA_SERIES
)
230 writel(le32_to_cpu(req_desc
->u
.low
),
231 &instance
->reg_set
->inbound_single_queue_port
);
233 #if defined(writeq) && defined(CONFIG_64BIT)
234 u64 req_data
= (((u64
)le32_to_cpu(req_desc
->u
.high
) << 32) |
235 le32_to_cpu(req_desc
->u
.low
));
237 writeq(req_data
, &instance
->reg_set
->inbound_low_queue_port
);
240 spin_lock_irqsave(&instance
->hba_lock
, flags
);
241 writel(le32_to_cpu(req_desc
->u
.low
),
242 &instance
->reg_set
->inbound_low_queue_port
);
243 writel(le32_to_cpu(req_desc
->u
.high
),
244 &instance
->reg_set
->inbound_high_queue_port
);
246 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
252 * megasas_fusion_update_can_queue - Do all Adapter Queue depth related calculations here
253 * @instance: Adapter soft state
254 * fw_boot_context: Whether this function called during probe or after OCR
256 * This function is only for fusion controllers.
257 * Update host can queue, if firmware downgrade max supported firmware commands.
258 * Firmware upgrade case will be skiped because underlying firmware has
259 * more resource than exposed to the OS.
263 megasas_fusion_update_can_queue(struct megasas_instance
*instance
, int fw_boot_context
)
265 u16 cur_max_fw_cmds
= 0;
266 u16 ldio_threshold
= 0;
267 struct megasas_register_set __iomem
*reg_set
;
269 reg_set
= instance
->reg_set
;
271 /* ventura FW does not fill outbound_scratch_pad_3 with queue depth */
272 if (instance
->adapter_type
< VENTURA_SERIES
)
274 readl(&instance
->reg_set
->outbound_scratch_pad_3
) & 0x00FFFF;
276 if (dual_qdepth_disable
|| !cur_max_fw_cmds
)
277 cur_max_fw_cmds
= instance
->instancet
->read_fw_status_reg(reg_set
) & 0x00FFFF;
280 (instance
->instancet
->read_fw_status_reg(reg_set
) & 0x00FFFF) - MEGASAS_FUSION_IOCTL_CMDS
;
282 dev_info(&instance
->pdev
->dev
,
283 "Current firmware supports maximum commands: %d\t LDIO threshold: %d\n",
284 cur_max_fw_cmds
, ldio_threshold
);
286 if (fw_boot_context
== OCR_CONTEXT
) {
287 cur_max_fw_cmds
= cur_max_fw_cmds
- 1;
288 if (cur_max_fw_cmds
< instance
->max_fw_cmds
) {
289 instance
->cur_can_queue
=
290 cur_max_fw_cmds
- (MEGASAS_FUSION_INTERNAL_CMDS
+
291 MEGASAS_FUSION_IOCTL_CMDS
);
292 instance
->host
->can_queue
= instance
->cur_can_queue
;
293 instance
->ldio_threshold
= ldio_threshold
;
296 instance
->max_fw_cmds
= cur_max_fw_cmds
;
297 instance
->ldio_threshold
= ldio_threshold
;
300 instance
->max_fw_cmds
= min(instance
->max_fw_cmds
,
301 (u16
)MEGASAS_KDUMP_QUEUE_DEPTH
);
303 * Reduce the max supported cmds by 1. This is to ensure that the
304 * reply_q_sz (1 more than the max cmd that driver may send)
305 * does not exceed max cmds that the FW can support
307 instance
->max_fw_cmds
= instance
->max_fw_cmds
-1;
311 * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
312 * @instance: Adapter soft state
315 megasas_free_cmds_fusion(struct megasas_instance
*instance
)
318 struct fusion_context
*fusion
= instance
->ctrl_context
;
319 struct megasas_cmd_fusion
*cmd
;
322 dma_pool_free(fusion
->sense_dma_pool
, fusion
->sense
,
323 fusion
->sense_phys_addr
);
326 if (fusion
->cmd_list
) {
327 for (i
= 0; i
< instance
->max_mpt_cmds
; i
++) {
328 cmd
= fusion
->cmd_list
[i
];
331 dma_pool_free(fusion
->sg_dma_pool
,
333 cmd
->sg_frame_phys_addr
);
337 kfree(fusion
->cmd_list
);
340 if (fusion
->sg_dma_pool
) {
341 dma_pool_destroy(fusion
->sg_dma_pool
);
342 fusion
->sg_dma_pool
= NULL
;
344 if (fusion
->sense_dma_pool
) {
345 dma_pool_destroy(fusion
->sense_dma_pool
);
346 fusion
->sense_dma_pool
= NULL
;
350 /* Reply Frame, Desc*/
351 if (instance
->is_rdpq
)
352 megasas_free_rdpq_fusion(instance
);
354 megasas_free_reply_fusion(instance
);
356 /* Request Frame, Desc*/
357 if (fusion
->req_frames_desc
)
358 dma_free_coherent(&instance
->pdev
->dev
,
359 fusion
->request_alloc_sz
, fusion
->req_frames_desc
,
360 fusion
->req_frames_desc_phys
);
361 if (fusion
->io_request_frames
)
362 dma_pool_free(fusion
->io_request_frames_pool
,
363 fusion
->io_request_frames
,
364 fusion
->io_request_frames_phys
);
365 if (fusion
->io_request_frames_pool
) {
366 dma_pool_destroy(fusion
->io_request_frames_pool
);
367 fusion
->io_request_frames_pool
= NULL
;
372 * megasas_create_sg_sense_fusion - Creates DMA pool for cmd frames
373 * @instance: Adapter soft state
376 static int megasas_create_sg_sense_fusion(struct megasas_instance
*instance
)
380 struct fusion_context
*fusion
;
381 struct megasas_cmd_fusion
*cmd
;
385 fusion
= instance
->ctrl_context
;
386 max_cmd
= instance
->max_fw_cmds
;
387 sense_sz
= instance
->max_mpt_cmds
* SCSI_SENSE_BUFFERSIZE
;
389 fusion
->sg_dma_pool
=
390 dma_pool_create("mr_sg", &instance
->pdev
->dev
,
391 instance
->max_chain_frame_sz
,
392 MR_DEFAULT_NVME_PAGE_SIZE
, 0);
393 /* SCSI_SENSE_BUFFERSIZE = 96 bytes */
394 fusion
->sense_dma_pool
=
395 dma_pool_create("mr_sense", &instance
->pdev
->dev
,
398 if (!fusion
->sense_dma_pool
|| !fusion
->sg_dma_pool
) {
399 dev_err(&instance
->pdev
->dev
,
400 "Failed from %s %d\n", __func__
, __LINE__
);
404 fusion
->sense
= dma_pool_alloc(fusion
->sense_dma_pool
,
405 GFP_KERNEL
, &fusion
->sense_phys_addr
);
406 if (!fusion
->sense
) {
407 dev_err(&instance
->pdev
->dev
,
408 "failed from %s %d\n", __func__
, __LINE__
);
412 /* sense buffer, request frame and reply desc pool requires to be in
413 * same 4 gb region. Below function will check this.
414 * In case of failure, new pci pool will be created with updated
416 * Older allocation and pool will be destroyed.
417 * Alignment will be used such a way that next allocation if success,
418 * will always meet same 4gb region requirement.
419 * Actual requirement is not alignment, but we need start and end of
420 * DMA address must have same upper 32 bit address.
423 if (!megasas_check_same_4gb_region(instance
, fusion
->sense_phys_addr
,
425 dma_pool_free(fusion
->sense_dma_pool
, fusion
->sense
,
426 fusion
->sense_phys_addr
);
427 fusion
->sense
= NULL
;
428 dma_pool_destroy(fusion
->sense_dma_pool
);
430 fusion
->sense_dma_pool
=
431 dma_pool_create("mr_sense_align", &instance
->pdev
->dev
,
432 sense_sz
, roundup_pow_of_two(sense_sz
),
434 if (!fusion
->sense_dma_pool
) {
435 dev_err(&instance
->pdev
->dev
,
436 "Failed from %s %d\n", __func__
, __LINE__
);
439 fusion
->sense
= dma_pool_alloc(fusion
->sense_dma_pool
,
441 &fusion
->sense_phys_addr
);
442 if (!fusion
->sense
) {
443 dev_err(&instance
->pdev
->dev
,
444 "failed from %s %d\n", __func__
, __LINE__
);
450 * Allocate and attach a frame to each of the commands in cmd_list
452 for (i
= 0; i
< max_cmd
; i
++) {
453 cmd
= fusion
->cmd_list
[i
];
454 cmd
->sg_frame
= dma_pool_alloc(fusion
->sg_dma_pool
,
455 GFP_KERNEL
, &cmd
->sg_frame_phys_addr
);
457 offset
= SCSI_SENSE_BUFFERSIZE
* i
;
458 cmd
->sense
= (u8
*)fusion
->sense
+ offset
;
459 cmd
->sense_phys_addr
= fusion
->sense_phys_addr
+ offset
;
461 if (!cmd
->sg_frame
) {
462 dev_err(&instance
->pdev
->dev
,
463 "Failed from %s %d\n", __func__
, __LINE__
);
468 /* create sense buffer for the raid 1/10 fp */
469 for (i
= max_cmd
; i
< instance
->max_mpt_cmds
; i
++) {
470 cmd
= fusion
->cmd_list
[i
];
471 offset
= SCSI_SENSE_BUFFERSIZE
* i
;
472 cmd
->sense
= (u8
*)fusion
->sense
+ offset
;
473 cmd
->sense_phys_addr
= fusion
->sense_phys_addr
+ offset
;
481 megasas_alloc_cmdlist_fusion(struct megasas_instance
*instance
)
483 u32 max_mpt_cmd
, i
, j
;
484 struct fusion_context
*fusion
;
486 fusion
= instance
->ctrl_context
;
488 max_mpt_cmd
= instance
->max_mpt_cmds
;
491 * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
492 * Allocate the dynamic array first and then allocate individual
496 kzalloc(sizeof(struct megasas_cmd_fusion
*) * max_mpt_cmd
,
498 if (!fusion
->cmd_list
) {
499 dev_err(&instance
->pdev
->dev
,
500 "Failed from %s %d\n", __func__
, __LINE__
);
504 for (i
= 0; i
< max_mpt_cmd
; i
++) {
505 fusion
->cmd_list
[i
] = kzalloc(sizeof(struct megasas_cmd_fusion
),
507 if (!fusion
->cmd_list
[i
]) {
508 for (j
= 0; j
< i
; j
++)
509 kfree(fusion
->cmd_list
[j
]);
510 kfree(fusion
->cmd_list
);
511 dev_err(&instance
->pdev
->dev
,
512 "Failed from %s %d\n", __func__
, __LINE__
);
520 megasas_alloc_request_fusion(struct megasas_instance
*instance
)
522 struct fusion_context
*fusion
;
524 fusion
= instance
->ctrl_context
;
527 fusion
->io_request_frames_pool
=
528 dma_pool_create("mr_ioreq", &instance
->pdev
->dev
,
529 fusion
->io_frames_alloc_sz
, 16, 0);
531 if (!fusion
->io_request_frames_pool
) {
532 dev_err(&instance
->pdev
->dev
,
533 "Failed from %s %d\n", __func__
, __LINE__
);
537 fusion
->io_request_frames
=
538 dma_pool_alloc(fusion
->io_request_frames_pool
,
539 GFP_KERNEL
, &fusion
->io_request_frames_phys
);
540 if (!fusion
->io_request_frames
) {
541 if (instance
->max_fw_cmds
>= (MEGASAS_REDUCE_QD_COUNT
* 2)) {
542 instance
->max_fw_cmds
-= MEGASAS_REDUCE_QD_COUNT
;
543 dma_pool_destroy(fusion
->io_request_frames_pool
);
544 megasas_configure_queue_sizes(instance
);
547 dev_err(&instance
->pdev
->dev
,
548 "Failed from %s %d\n", __func__
, __LINE__
);
553 if (!megasas_check_same_4gb_region(instance
,
554 fusion
->io_request_frames_phys
,
555 fusion
->io_frames_alloc_sz
)) {
556 dma_pool_free(fusion
->io_request_frames_pool
,
557 fusion
->io_request_frames
,
558 fusion
->io_request_frames_phys
);
559 fusion
->io_request_frames
= NULL
;
560 dma_pool_destroy(fusion
->io_request_frames_pool
);
562 fusion
->io_request_frames_pool
=
563 dma_pool_create("mr_ioreq_align",
564 &instance
->pdev
->dev
,
565 fusion
->io_frames_alloc_sz
,
566 roundup_pow_of_two(fusion
->io_frames_alloc_sz
),
569 if (!fusion
->io_request_frames_pool
) {
570 dev_err(&instance
->pdev
->dev
,
571 "Failed from %s %d\n", __func__
, __LINE__
);
575 fusion
->io_request_frames
=
576 dma_pool_alloc(fusion
->io_request_frames_pool
,
578 &fusion
->io_request_frames_phys
);
580 if (!fusion
->io_request_frames
) {
581 dev_err(&instance
->pdev
->dev
,
582 "Failed from %s %d\n", __func__
, __LINE__
);
587 fusion
->req_frames_desc
=
588 dma_alloc_coherent(&instance
->pdev
->dev
,
589 fusion
->request_alloc_sz
,
590 &fusion
->req_frames_desc_phys
, GFP_KERNEL
);
591 if (!fusion
->req_frames_desc
) {
592 dev_err(&instance
->pdev
->dev
,
593 "Failed from %s %d\n", __func__
, __LINE__
);
601 megasas_alloc_reply_fusion(struct megasas_instance
*instance
)
604 struct fusion_context
*fusion
;
605 union MPI2_REPLY_DESCRIPTORS_UNION
*reply_desc
;
606 fusion
= instance
->ctrl_context
;
608 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
609 fusion
->reply_frames_desc_pool
=
610 dma_pool_create("mr_reply", &instance
->pdev
->dev
,
611 fusion
->reply_alloc_sz
* count
, 16, 0);
613 if (!fusion
->reply_frames_desc_pool
) {
614 dev_err(&instance
->pdev
->dev
,
615 "Failed from %s %d\n", __func__
, __LINE__
);
619 fusion
->reply_frames_desc
[0] =
620 dma_pool_alloc(fusion
->reply_frames_desc_pool
,
621 GFP_KERNEL
, &fusion
->reply_frames_desc_phys
[0]);
622 if (!fusion
->reply_frames_desc
[0]) {
623 dev_err(&instance
->pdev
->dev
,
624 "Failed from %s %d\n", __func__
, __LINE__
);
628 if (!megasas_check_same_4gb_region(instance
,
629 fusion
->reply_frames_desc_phys
[0],
630 (fusion
->reply_alloc_sz
* count
))) {
631 dma_pool_free(fusion
->reply_frames_desc_pool
,
632 fusion
->reply_frames_desc
[0],
633 fusion
->reply_frames_desc_phys
[0]);
634 fusion
->reply_frames_desc
[0] = NULL
;
635 dma_pool_destroy(fusion
->reply_frames_desc_pool
);
637 fusion
->reply_frames_desc_pool
=
638 dma_pool_create("mr_reply_align",
639 &instance
->pdev
->dev
,
640 fusion
->reply_alloc_sz
* count
,
641 roundup_pow_of_two(fusion
->reply_alloc_sz
* count
),
644 if (!fusion
->reply_frames_desc_pool
) {
645 dev_err(&instance
->pdev
->dev
,
646 "Failed from %s %d\n", __func__
, __LINE__
);
650 fusion
->reply_frames_desc
[0] =
651 dma_pool_alloc(fusion
->reply_frames_desc_pool
,
653 &fusion
->reply_frames_desc_phys
[0]);
655 if (!fusion
->reply_frames_desc
[0]) {
656 dev_err(&instance
->pdev
->dev
,
657 "Failed from %s %d\n", __func__
, __LINE__
);
662 reply_desc
= fusion
->reply_frames_desc
[0];
663 for (i
= 0; i
< fusion
->reply_q_depth
* count
; i
++, reply_desc
++)
664 reply_desc
->Words
= cpu_to_le64(ULLONG_MAX
);
666 /* This is not a rdpq mode, but driver still populate
667 * reply_frame_desc array to use same msix index in ISR path.
669 for (i
= 0; i
< (count
- 1); i
++)
670 fusion
->reply_frames_desc
[i
+ 1] =
671 fusion
->reply_frames_desc
[i
] +
672 (fusion
->reply_alloc_sz
)/sizeof(union MPI2_REPLY_DESCRIPTORS_UNION
);
678 megasas_alloc_rdpq_fusion(struct megasas_instance
*instance
)
680 int i
, j
, k
, msix_count
;
681 struct fusion_context
*fusion
;
682 union MPI2_REPLY_DESCRIPTORS_UNION
*reply_desc
;
683 union MPI2_REPLY_DESCRIPTORS_UNION
*rdpq_chunk_virt
[RDPQ_MAX_CHUNK_COUNT
];
684 dma_addr_t rdpq_chunk_phys
[RDPQ_MAX_CHUNK_COUNT
];
685 u8 dma_alloc_count
, abs_index
;
686 u32 chunk_size
, array_size
, offset
;
688 fusion
= instance
->ctrl_context
;
689 chunk_size
= fusion
->reply_alloc_sz
* RDPQ_MAX_INDEX_IN_ONE_CHUNK
;
690 array_size
= sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY
) *
691 MAX_MSIX_QUEUES_FUSION
;
693 fusion
->rdpq_virt
= pci_alloc_consistent(instance
->pdev
, array_size
,
695 if (!fusion
->rdpq_virt
) {
696 dev_err(&instance
->pdev
->dev
,
697 "Failed from %s %d\n", __func__
, __LINE__
);
701 memset(fusion
->rdpq_virt
, 0, array_size
);
702 msix_count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
704 fusion
->reply_frames_desc_pool
= dma_pool_create("mr_rdpq",
705 &instance
->pdev
->dev
,
707 fusion
->reply_frames_desc_pool_align
=
708 dma_pool_create("mr_rdpq_align",
709 &instance
->pdev
->dev
,
711 roundup_pow_of_two(chunk_size
),
714 if (!fusion
->reply_frames_desc_pool
||
715 !fusion
->reply_frames_desc_pool_align
) {
716 dev_err(&instance
->pdev
->dev
,
717 "Failed from %s %d\n", __func__
, __LINE__
);
722 * For INVADER_SERIES each set of 8 reply queues(0-7, 8-15, ..) and
723 * VENTURA_SERIES each set of 16 reply queues(0-15, 16-31, ..) should be
724 * within 4GB boundary and also reply queues in a set must have same
725 * upper 32-bits in their memory address. so here driver is allocating the
726 * DMA'able memory for reply queues according. Driver uses limitation of
727 * VENTURA_SERIES to manage INVADER_SERIES as well.
729 dma_alloc_count
= DIV_ROUND_UP(msix_count
, RDPQ_MAX_INDEX_IN_ONE_CHUNK
);
731 for (i
= 0; i
< dma_alloc_count
; i
++) {
733 dma_pool_alloc(fusion
->reply_frames_desc_pool
,
734 GFP_KERNEL
, &rdpq_chunk_phys
[i
]);
735 if (!rdpq_chunk_virt
[i
]) {
736 dev_err(&instance
->pdev
->dev
,
737 "Failed from %s %d\n", __func__
, __LINE__
);
740 /* reply desc pool requires to be in same 4 gb region.
741 * Below function will check this.
742 * In case of failure, new pci pool will be created with updated
744 * For RDPQ buffers, driver always allocate two separate pci pool.
745 * Alignment will be used such a way that next allocation if
746 * success, will always meet same 4gb region requirement.
747 * rdpq_tracker keep track of each buffer's physical,
748 * virtual address and pci pool descriptor. It will help driver
749 * while freeing the resources.
752 if (!megasas_check_same_4gb_region(instance
, rdpq_chunk_phys
[i
],
754 dma_pool_free(fusion
->reply_frames_desc_pool
,
759 dma_pool_alloc(fusion
->reply_frames_desc_pool_align
,
760 GFP_KERNEL
, &rdpq_chunk_phys
[i
]);
761 if (!rdpq_chunk_virt
[i
]) {
762 dev_err(&instance
->pdev
->dev
,
763 "Failed from %s %d\n",
767 fusion
->rdpq_tracker
[i
].dma_pool_ptr
=
768 fusion
->reply_frames_desc_pool_align
;
770 fusion
->rdpq_tracker
[i
].dma_pool_ptr
=
771 fusion
->reply_frames_desc_pool
;
774 fusion
->rdpq_tracker
[i
].pool_entry_phys
= rdpq_chunk_phys
[i
];
775 fusion
->rdpq_tracker
[i
].pool_entry_virt
= rdpq_chunk_virt
[i
];
778 for (k
= 0; k
< dma_alloc_count
; k
++) {
779 for (i
= 0; i
< RDPQ_MAX_INDEX_IN_ONE_CHUNK
; i
++) {
780 abs_index
= (k
* RDPQ_MAX_INDEX_IN_ONE_CHUNK
) + i
;
782 if (abs_index
== msix_count
)
784 offset
= fusion
->reply_alloc_sz
* i
;
785 fusion
->rdpq_virt
[abs_index
].RDPQBaseAddress
=
786 cpu_to_le64(rdpq_chunk_phys
[k
] + offset
);
787 fusion
->reply_frames_desc_phys
[abs_index
] =
788 rdpq_chunk_phys
[k
] + offset
;
789 fusion
->reply_frames_desc
[abs_index
] =
790 (union MPI2_REPLY_DESCRIPTORS_UNION
*)((u8
*)rdpq_chunk_virt
[k
] + offset
);
792 reply_desc
= fusion
->reply_frames_desc
[abs_index
];
793 for (j
= 0; j
< fusion
->reply_q_depth
; j
++, reply_desc
++)
794 reply_desc
->Words
= ULLONG_MAX
;
802 megasas_free_rdpq_fusion(struct megasas_instance
*instance
) {
805 struct fusion_context
*fusion
;
807 fusion
= instance
->ctrl_context
;
809 for (i
= 0; i
< RDPQ_MAX_CHUNK_COUNT
; i
++) {
810 if (fusion
->rdpq_tracker
[i
].pool_entry_virt
)
811 dma_pool_free(fusion
->rdpq_tracker
[i
].dma_pool_ptr
,
812 fusion
->rdpq_tracker
[i
].pool_entry_virt
,
813 fusion
->rdpq_tracker
[i
].pool_entry_phys
);
817 if (fusion
->reply_frames_desc_pool
)
818 dma_pool_destroy(fusion
->reply_frames_desc_pool
);
819 if (fusion
->reply_frames_desc_pool_align
)
820 dma_pool_destroy(fusion
->reply_frames_desc_pool_align
);
822 if (fusion
->rdpq_virt
)
823 pci_free_consistent(instance
->pdev
,
824 sizeof(struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY
) * MAX_MSIX_QUEUES_FUSION
,
825 fusion
->rdpq_virt
, fusion
->rdpq_phys
);
829 megasas_free_reply_fusion(struct megasas_instance
*instance
) {
831 struct fusion_context
*fusion
;
833 fusion
= instance
->ctrl_context
;
835 if (fusion
->reply_frames_desc
[0])
836 dma_pool_free(fusion
->reply_frames_desc_pool
,
837 fusion
->reply_frames_desc
[0],
838 fusion
->reply_frames_desc_phys
[0]);
840 if (fusion
->reply_frames_desc_pool
)
841 dma_pool_destroy(fusion
->reply_frames_desc_pool
);
847 * megasas_alloc_cmds_fusion - Allocates the command packets
848 * @instance: Adapter soft state
851 * Each frame has a 32-bit field called context. This context is used to get
852 * back the megasas_cmd_fusion from the frame when a frame gets completed
853 * In this driver, the 32 bit values are the indices into an array cmd_list.
854 * This array is used only to look up the megasas_cmd_fusion given the context.
855 * The free commands themselves are maintained in a linked list called cmd_pool.
857 * cmds are formed in the io_request and sg_frame members of the
858 * megasas_cmd_fusion. The context field is used to get a request descriptor
859 * and is used as SMID of the cmd.
860 * SMID value range is from 1 to max_fw_cmds.
863 megasas_alloc_cmds_fusion(struct megasas_instance
*instance
)
866 struct fusion_context
*fusion
;
867 struct megasas_cmd_fusion
*cmd
;
869 dma_addr_t io_req_base_phys
;
873 fusion
= instance
->ctrl_context
;
875 if (megasas_alloc_request_fusion(instance
))
878 if (instance
->is_rdpq
) {
879 if (megasas_alloc_rdpq_fusion(instance
))
882 if (megasas_alloc_reply_fusion(instance
))
885 if (megasas_alloc_cmdlist_fusion(instance
))
888 dev_info(&instance
->pdev
->dev
, "Configured max firmware commands: %d\n",
889 instance
->max_fw_cmds
);
891 /* The first 256 bytes (SMID 0) is not used. Don't add to the cmd list */
892 io_req_base
= fusion
->io_request_frames
+ MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
;
893 io_req_base_phys
= fusion
->io_request_frames_phys
+ MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
;
896 * Add all the commands to command pool (fusion->cmd_pool)
899 /* SMID 0 is reserved. Set SMID/index from 1 */
900 for (i
= 0; i
< instance
->max_mpt_cmds
; i
++) {
901 cmd
= fusion
->cmd_list
[i
];
902 offset
= MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
* i
;
903 memset(cmd
, 0, sizeof(struct megasas_cmd_fusion
));
907 (i
>= instance
->max_scsi_cmds
&& i
< instance
->max_fw_cmds
) ?
908 (i
- instance
->max_scsi_cmds
) :
909 (u32
)ULONG_MAX
; /* Set to Invalid */
910 cmd
->instance
= instance
;
912 (struct MPI2_RAID_SCSI_IO_REQUEST
*)
913 (io_req_base
+ offset
);
914 memset(cmd
->io_request
, 0,
915 sizeof(struct MPI2_RAID_SCSI_IO_REQUEST
));
916 cmd
->io_request_phys_addr
= io_req_base_phys
+ offset
;
917 cmd
->r1_alt_dev_handle
= MR_DEVHANDLE_INVALID
;
920 if (megasas_create_sg_sense_fusion(instance
))
926 megasas_free_cmds_fusion(instance
);
931 * wait_and_poll - Issues a polling command
932 * @instance: Adapter soft state
933 * @cmd: Command packet to be issued
935 * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
938 wait_and_poll(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
,
942 struct megasas_header
*frame_hdr
= &cmd
->frame
->hdr
;
943 struct fusion_context
*fusion
;
945 u32 msecs
= seconds
* 1000;
947 fusion
= instance
->ctrl_context
;
949 * Wait for cmd_status to change
951 for (i
= 0; (i
< msecs
) && (frame_hdr
->cmd_status
== 0xff); i
+= 20) {
956 if (frame_hdr
->cmd_status
== MFI_STAT_INVALID_STATUS
)
958 else if (frame_hdr
->cmd_status
== MFI_STAT_OK
)
965 * megasas_ioc_init_fusion - Initializes the FW
966 * @instance: Adapter soft state
968 * Issues the IOC Init cmd
971 megasas_ioc_init_fusion(struct megasas_instance
*instance
)
973 struct megasas_init_frame
*init_frame
;
974 struct MPI2_IOC_INIT_REQUEST
*IOCInitMessage
= NULL
;
975 dma_addr_t ioc_init_handle
;
976 struct megasas_cmd
*cmd
;
977 u8 ret
, cur_rdpq_mode
;
978 struct fusion_context
*fusion
;
979 union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc
;
981 struct megasas_header
*frame_hdr
;
982 const char *sys_info
;
983 MFI_CAPABILITIES
*drv_ops
;
987 bool cur_fw_64bit_dma_capable
;
989 fusion
= instance
->ctrl_context
;
991 ioc_init_handle
= fusion
->ioc_init_request_phys
;
992 IOCInitMessage
= fusion
->ioc_init_request
;
994 cmd
= fusion
->ioc_init_cmd
;
996 scratch_pad_2
= readl
997 (&instance
->reg_set
->outbound_scratch_pad_2
);
999 cur_rdpq_mode
= (scratch_pad_2
& MR_RDPQ_MODE_OFFSET
) ? 1 : 0;
1001 if (instance
->adapter_type
== INVADER_SERIES
) {
1002 cur_fw_64bit_dma_capable
=
1003 (scratch_pad_2
& MR_CAN_HANDLE_64_BIT_DMA_OFFSET
) ? true : false;
1005 if (instance
->consistent_mask_64bit
&& !cur_fw_64bit_dma_capable
) {
1006 dev_err(&instance
->pdev
->dev
, "Driver was operating on 64bit "
1007 "DMA mask, but upcoming FW does not support 64bit DMA mask\n");
1008 megaraid_sas_kill_hba(instance
);
1014 if (instance
->is_rdpq
&& !cur_rdpq_mode
) {
1015 dev_err(&instance
->pdev
->dev
, "Firmware downgrade *NOT SUPPORTED*"
1016 " from RDPQ mode to non RDPQ mode\n");
1021 instance
->fw_sync_cache_support
= (scratch_pad_2
&
1022 MR_CAN_HANDLE_SYNC_CACHE_OFFSET
) ? 1 : 0;
1023 dev_info(&instance
->pdev
->dev
, "FW supports sync cache\t: %s\n",
1024 instance
->fw_sync_cache_support
? "Yes" : "No");
1026 memset(IOCInitMessage
, 0, sizeof(struct MPI2_IOC_INIT_REQUEST
));
1028 IOCInitMessage
->Function
= MPI2_FUNCTION_IOC_INIT
;
1029 IOCInitMessage
->WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
1030 IOCInitMessage
->MsgVersion
= cpu_to_le16(MPI2_VERSION
);
1031 IOCInitMessage
->HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
1032 IOCInitMessage
->SystemRequestFrameSize
= cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
/ 4);
1034 IOCInitMessage
->ReplyDescriptorPostQueueDepth
= cpu_to_le16(fusion
->reply_q_depth
);
1035 IOCInitMessage
->ReplyDescriptorPostQueueAddress
= instance
->is_rdpq
?
1036 cpu_to_le64(fusion
->rdpq_phys
) :
1037 cpu_to_le64(fusion
->reply_frames_desc_phys
[0]);
1038 IOCInitMessage
->MsgFlags
= instance
->is_rdpq
?
1039 MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE
: 0;
1040 IOCInitMessage
->SystemRequestFrameBaseAddress
= cpu_to_le64(fusion
->io_request_frames_phys
);
1041 IOCInitMessage
->SenseBufferAddressHigh
= cpu_to_le32(upper_32_bits(fusion
->sense_phys_addr
));
1042 IOCInitMessage
->HostMSIxVectors
= instance
->msix_vectors
;
1043 IOCInitMessage
->HostPageSize
= MR_DEFAULT_NVME_PAGE_SHIFT
;
1045 time
= ktime_get_real();
1046 /* Convert to milliseconds as per FW requirement */
1047 IOCInitMessage
->TimeStamp
= cpu_to_le64(ktime_to_ms(time
));
1049 init_frame
= (struct megasas_init_frame
*)cmd
->frame
;
1050 memset(init_frame
, 0, IOC_INIT_FRAME_SIZE
);
1052 frame_hdr
= &cmd
->frame
->hdr
;
1053 frame_hdr
->cmd_status
= 0xFF;
1054 frame_hdr
->flags
= cpu_to_le16(
1055 le16_to_cpu(frame_hdr
->flags
) |
1056 MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
);
1058 init_frame
->cmd
= MFI_CMD_INIT
;
1059 init_frame
->cmd_status
= 0xFF;
1061 drv_ops
= (MFI_CAPABILITIES
*) &(init_frame
->driver_operations
);
1063 /* driver support Extended MSIX */
1064 if (instance
->adapter_type
>= INVADER_SERIES
)
1065 drv_ops
->mfi_capabilities
.support_additional_msix
= 1;
1066 /* driver supports HA / Remote LUN over Fast Path interface */
1067 drv_ops
->mfi_capabilities
.support_fp_remote_lun
= 1;
1069 drv_ops
->mfi_capabilities
.support_max_255lds
= 1;
1070 drv_ops
->mfi_capabilities
.support_ndrive_r1_lb
= 1;
1071 drv_ops
->mfi_capabilities
.security_protocol_cmds_fw
= 1;
1073 if (instance
->max_chain_frame_sz
> MEGASAS_CHAIN_FRAME_SZ_MIN
)
1074 drv_ops
->mfi_capabilities
.support_ext_io_size
= 1;
1076 drv_ops
->mfi_capabilities
.support_fp_rlbypass
= 1;
1077 if (!dual_qdepth_disable
)
1078 drv_ops
->mfi_capabilities
.support_ext_queue_depth
= 1;
1080 drv_ops
->mfi_capabilities
.support_qd_throttling
= 1;
1081 drv_ops
->mfi_capabilities
.support_pd_map_target_id
= 1;
1082 drv_ops
->mfi_capabilities
.support_nvme_passthru
= 1;
1084 if (instance
->consistent_mask_64bit
)
1085 drv_ops
->mfi_capabilities
.support_64bit_mode
= 1;
1087 /* Convert capability to LE32 */
1088 cpu_to_le32s((u32
*)&init_frame
->driver_operations
.mfi_capabilities
);
1090 sys_info
= dmi_get_system_info(DMI_PRODUCT_UUID
);
1091 if (instance
->system_info_buf
&& sys_info
) {
1092 memcpy(instance
->system_info_buf
->systemId
, sys_info
,
1093 strlen(sys_info
) > 64 ? 64 : strlen(sys_info
));
1094 instance
->system_info_buf
->systemIdLength
=
1095 strlen(sys_info
) > 64 ? 64 : strlen(sys_info
);
1096 init_frame
->system_info_lo
= cpu_to_le32(lower_32_bits(instance
->system_info_h
));
1097 init_frame
->system_info_hi
= cpu_to_le32(upper_32_bits(instance
->system_info_h
));
1100 init_frame
->queue_info_new_phys_addr_hi
=
1101 cpu_to_le32(upper_32_bits(ioc_init_handle
));
1102 init_frame
->queue_info_new_phys_addr_lo
=
1103 cpu_to_le32(lower_32_bits(ioc_init_handle
));
1104 init_frame
->data_xfer_len
= cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST
));
1106 req_desc
.u
.low
= cpu_to_le32(lower_32_bits(cmd
->frame_phys_addr
));
1107 req_desc
.u
.high
= cpu_to_le32(upper_32_bits(cmd
->frame_phys_addr
));
1108 req_desc
.MFAIo
.RequestFlags
=
1109 (MEGASAS_REQ_DESCRIPT_FLAGS_MFA
<<
1110 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
1113 * disable the intr before firing the init frame
1115 instance
->instancet
->disable_intr(instance
);
1117 for (i
= 0; i
< (10 * 1000); i
+= 20) {
1118 if (readl(&instance
->reg_set
->doorbell
) & 1)
1124 /* For Ventura also IOC INIT required 64 bit Descriptor write. */
1125 spin_lock_irqsave(&instance
->hba_lock
, flags
);
1126 writel(le32_to_cpu(req_desc
.u
.low
),
1127 &instance
->reg_set
->inbound_low_queue_port
);
1128 writel(le32_to_cpu(req_desc
.u
.high
),
1129 &instance
->reg_set
->inbound_high_queue_port
);
1131 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
1133 wait_and_poll(instance
, cmd
, MFI_POLL_TIMEOUT_SECS
);
1135 frame_hdr
= &cmd
->frame
->hdr
;
1136 if (frame_hdr
->cmd_status
!= 0) {
1144 dev_err(&instance
->pdev
->dev
,
1145 "Init cmd return status %s for SCSI host %d\n",
1146 ret
? "FAILED" : "SUCCESS", instance
->host
->host_no
);
1152 * megasas_sync_pd_seq_num - JBOD SEQ MAP
1153 * @instance: Adapter soft state
1154 * @pend: set to 1, if it is pended jbod map.
1156 * Issue Jbod map to the firmware. If it is pended command,
1157 * issue command and return. If it is first instance of jbod map
1158 * issue and receive command.
1161 megasas_sync_pd_seq_num(struct megasas_instance
*instance
, bool pend
) {
1164 struct megasas_cmd
*cmd
;
1165 struct megasas_dcmd_frame
*dcmd
;
1166 struct fusion_context
*fusion
= instance
->ctrl_context
;
1167 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
1168 dma_addr_t pd_seq_h
;
1170 pd_sync
= (void *)fusion
->pd_seq_sync
[(instance
->pd_seq_map_id
& 1)];
1171 pd_seq_h
= fusion
->pd_seq_phys
[(instance
->pd_seq_map_id
& 1)];
1172 pd_seq_map_sz
= sizeof(struct MR_PD_CFG_SEQ_NUM_SYNC
) +
1173 (sizeof(struct MR_PD_CFG_SEQ
) *
1174 (MAX_PHYSICAL_DEVICES
- 1));
1176 cmd
= megasas_get_cmd(instance
);
1178 dev_err(&instance
->pdev
->dev
,
1179 "Could not get mfi cmd. Fail from %s %d\n",
1180 __func__
, __LINE__
);
1184 dcmd
= &cmd
->frame
->dcmd
;
1186 memset(pd_sync
, 0, pd_seq_map_sz
);
1187 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
1190 dcmd
->mbox
.b
[0] = MEGASAS_DCMD_MBOX_PEND_FLAG
;
1191 dcmd
->flags
= MFI_FRAME_DIR_WRITE
;
1192 instance
->jbod_seq_cmd
= cmd
;
1194 dcmd
->flags
= MFI_FRAME_DIR_READ
;
1197 dcmd
->cmd
= MFI_CMD_DCMD
;
1198 dcmd
->cmd_status
= 0xFF;
1199 dcmd
->sge_count
= 1;
1202 dcmd
->data_xfer_len
= cpu_to_le32(pd_seq_map_sz
);
1203 dcmd
->opcode
= cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO
);
1205 megasas_set_dma_settings(instance
, dcmd
, pd_seq_h
, pd_seq_map_sz
);
1208 instance
->instancet
->issue_dcmd(instance
, cmd
);
1212 /* Below code is only for non pended DCMD */
1213 if (!instance
->mask_interrupts
)
1214 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
1215 MFI_IO_TIMEOUT_SECS
);
1217 ret
= megasas_issue_polled(instance
, cmd
);
1219 if (le32_to_cpu(pd_sync
->count
) > MAX_PHYSICAL_DEVICES
) {
1220 dev_warn(&instance
->pdev
->dev
,
1221 "driver supports max %d JBOD, but FW reports %d\n",
1222 MAX_PHYSICAL_DEVICES
, le32_to_cpu(pd_sync
->count
));
1226 if (ret
== DCMD_TIMEOUT
)
1227 megaraid_sas_kill_hba(instance
);
1229 if (ret
== DCMD_SUCCESS
)
1230 instance
->pd_seq_map_id
++;
1232 megasas_return_cmd(instance
, cmd
);
1237 * megasas_get_ld_map_info - Returns FW's ld_map structure
1238 * @instance: Adapter soft state
1239 * @pend: Pend the command or not
1240 * Issues an internal command (DCMD) to get the FW's controller PD
1241 * list structure. This information is mainly used to find out SYSTEM
1242 * supported by the FW.
1243 * dcmd.mbox value setting for MR_DCMD_LD_MAP_GET_INFO
1244 * dcmd.mbox.b[0] - number of LDs being sync'd
1245 * dcmd.mbox.b[1] - 0 - complete command immediately.
1246 * - 1 - pend till config change
1247 * dcmd.mbox.b[2] - 0 - supports max 64 lds and uses legacy MR_FW_RAID_MAP
1248 * - 1 - supports max MAX_LOGICAL_DRIVES_EXT lds and
1249 * uses extended struct MR_FW_RAID_MAP_EXT
1252 megasas_get_ld_map_info(struct megasas_instance
*instance
)
1255 struct megasas_cmd
*cmd
;
1256 struct megasas_dcmd_frame
*dcmd
;
1258 dma_addr_t ci_h
= 0;
1260 struct fusion_context
*fusion
;
1262 cmd
= megasas_get_cmd(instance
);
1265 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get cmd for map info\n");
1269 fusion
= instance
->ctrl_context
;
1272 megasas_return_cmd(instance
, cmd
);
1276 dcmd
= &cmd
->frame
->dcmd
;
1278 size_map_info
= fusion
->current_map_sz
;
1280 ci
= (void *) fusion
->ld_map
[(instance
->map_id
& 1)];
1281 ci_h
= fusion
->ld_map_phys
[(instance
->map_id
& 1)];
1284 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to alloc mem for ld_map_info\n");
1285 megasas_return_cmd(instance
, cmd
);
1289 memset(ci
, 0, fusion
->max_map_sz
);
1290 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
1291 dcmd
->cmd
= MFI_CMD_DCMD
;
1292 dcmd
->cmd_status
= 0xFF;
1293 dcmd
->sge_count
= 1;
1294 dcmd
->flags
= MFI_FRAME_DIR_READ
;
1297 dcmd
->data_xfer_len
= cpu_to_le32(size_map_info
);
1298 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO
);
1300 megasas_set_dma_settings(instance
, dcmd
, ci_h
, size_map_info
);
1302 if (!instance
->mask_interrupts
)
1303 ret
= megasas_issue_blocked_cmd(instance
, cmd
,
1304 MFI_IO_TIMEOUT_SECS
);
1306 ret
= megasas_issue_polled(instance
, cmd
);
1308 if (ret
== DCMD_TIMEOUT
)
1309 megaraid_sas_kill_hba(instance
);
1311 megasas_return_cmd(instance
, cmd
);
1317 megasas_get_map_info(struct megasas_instance
*instance
)
1319 struct fusion_context
*fusion
= instance
->ctrl_context
;
1321 fusion
->fast_path_io
= 0;
1322 if (!megasas_get_ld_map_info(instance
)) {
1323 if (MR_ValidateMapInfo(instance
, instance
->map_id
)) {
1324 fusion
->fast_path_io
= 1;
1332 * megasas_sync_map_info - Returns FW's ld_map structure
1333 * @instance: Adapter soft state
1335 * Issues an internal command (DCMD) to get the FW's controller PD
1336 * list structure. This information is mainly used to find out SYSTEM
1337 * supported by the FW.
1340 megasas_sync_map_info(struct megasas_instance
*instance
)
1343 struct megasas_cmd
*cmd
;
1344 struct megasas_dcmd_frame
*dcmd
;
1347 struct fusion_context
*fusion
;
1348 struct MR_LD_TARGET_SYNC
*ci
= NULL
;
1349 struct MR_DRV_RAID_MAP_ALL
*map
;
1350 struct MR_LD_RAID
*raid
;
1351 struct MR_LD_TARGET_SYNC
*ld_sync
;
1352 dma_addr_t ci_h
= 0;
1355 cmd
= megasas_get_cmd(instance
);
1358 dev_printk(KERN_DEBUG
, &instance
->pdev
->dev
, "Failed to get cmd for sync info\n");
1362 fusion
= instance
->ctrl_context
;
1365 megasas_return_cmd(instance
, cmd
);
1369 map
= fusion
->ld_drv_map
[instance
->map_id
& 1];
1371 num_lds
= le16_to_cpu(map
->raidMap
.ldCount
);
1373 dcmd
= &cmd
->frame
->dcmd
;
1375 size_sync_info
= sizeof(struct MR_LD_TARGET_SYNC
) *num_lds
;
1377 memset(dcmd
->mbox
.b
, 0, MFI_MBOX_SIZE
);
1379 ci
= (struct MR_LD_TARGET_SYNC
*)
1380 fusion
->ld_map
[(instance
->map_id
- 1) & 1];
1381 memset(ci
, 0, fusion
->max_map_sz
);
1383 ci_h
= fusion
->ld_map_phys
[(instance
->map_id
- 1) & 1];
1385 ld_sync
= (struct MR_LD_TARGET_SYNC
*)ci
;
1387 for (i
= 0; i
< num_lds
; i
++, ld_sync
++) {
1388 raid
= MR_LdRaidGet(i
, map
);
1389 ld_sync
->targetId
= MR_GetLDTgtId(i
, map
);
1390 ld_sync
->seqNum
= raid
->seqNum
;
1393 size_map_info
= fusion
->current_map_sz
;
1395 dcmd
->cmd
= MFI_CMD_DCMD
;
1396 dcmd
->cmd_status
= 0xFF;
1397 dcmd
->sge_count
= 1;
1398 dcmd
->flags
= MFI_FRAME_DIR_WRITE
;
1401 dcmd
->data_xfer_len
= cpu_to_le32(size_map_info
);
1402 dcmd
->mbox
.b
[0] = num_lds
;
1403 dcmd
->mbox
.b
[1] = MEGASAS_DCMD_MBOX_PEND_FLAG
;
1404 dcmd
->opcode
= cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO
);
1406 megasas_set_dma_settings(instance
, dcmd
, ci_h
, size_map_info
);
1408 instance
->map_update_cmd
= cmd
;
1410 instance
->instancet
->issue_dcmd(instance
, cmd
);
1416 * meagasas_display_intel_branding - Display branding string
1417 * @instance: per adapter object
1422 megasas_display_intel_branding(struct megasas_instance
*instance
)
1424 if (instance
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
1427 switch (instance
->pdev
->device
) {
1428 case PCI_DEVICE_ID_LSI_INVADER
:
1429 switch (instance
->pdev
->subsystem_device
) {
1430 case MEGARAID_INTEL_RS3DC080_SSDID
:
1431 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1432 instance
->host
->host_no
,
1433 MEGARAID_INTEL_RS3DC080_BRANDING
);
1435 case MEGARAID_INTEL_RS3DC040_SSDID
:
1436 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1437 instance
->host
->host_no
,
1438 MEGARAID_INTEL_RS3DC040_BRANDING
);
1440 case MEGARAID_INTEL_RS3SC008_SSDID
:
1441 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1442 instance
->host
->host_no
,
1443 MEGARAID_INTEL_RS3SC008_BRANDING
);
1445 case MEGARAID_INTEL_RS3MC044_SSDID
:
1446 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1447 instance
->host
->host_no
,
1448 MEGARAID_INTEL_RS3MC044_BRANDING
);
1454 case PCI_DEVICE_ID_LSI_FURY
:
1455 switch (instance
->pdev
->subsystem_device
) {
1456 case MEGARAID_INTEL_RS3WC080_SSDID
:
1457 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1458 instance
->host
->host_no
,
1459 MEGARAID_INTEL_RS3WC080_BRANDING
);
1461 case MEGARAID_INTEL_RS3WC040_SSDID
:
1462 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1463 instance
->host
->host_no
,
1464 MEGARAID_INTEL_RS3WC040_BRANDING
);
1470 case PCI_DEVICE_ID_LSI_CUTLASS_52
:
1471 case PCI_DEVICE_ID_LSI_CUTLASS_53
:
1472 switch (instance
->pdev
->subsystem_device
) {
1473 case MEGARAID_INTEL_RMS3BC160_SSDID
:
1474 dev_info(&instance
->pdev
->dev
, "scsi host %d: %s\n",
1475 instance
->host
->host_no
,
1476 MEGARAID_INTEL_RMS3BC160_BRANDING
);
1488 * megasas_allocate_raid_maps - Allocate memory for RAID maps
1489 * @instance: Adapter soft state
1491 * return: if success: return 0
1492 * failed: return -ENOMEM
1494 static inline int megasas_allocate_raid_maps(struct megasas_instance
*instance
)
1496 struct fusion_context
*fusion
;
1499 fusion
= instance
->ctrl_context
;
1501 fusion
->drv_map_pages
= get_order(fusion
->drv_map_sz
);
1503 for (i
= 0; i
< 2; i
++) {
1504 fusion
->ld_map
[i
] = NULL
;
1506 fusion
->ld_drv_map
[i
] = (void *)
1507 __get_free_pages(__GFP_ZERO
| GFP_KERNEL
,
1508 fusion
->drv_map_pages
);
1510 if (!fusion
->ld_drv_map
[i
]) {
1511 fusion
->ld_drv_map
[i
] = vzalloc(fusion
->drv_map_sz
);
1513 if (!fusion
->ld_drv_map
[i
]) {
1514 dev_err(&instance
->pdev
->dev
,
1515 "Could not allocate memory for local map"
1516 " size requested: %d\n",
1517 fusion
->drv_map_sz
);
1518 goto ld_drv_map_alloc_fail
;
1523 for (i
= 0; i
< 2; i
++) {
1524 fusion
->ld_map
[i
] = dma_alloc_coherent(&instance
->pdev
->dev
,
1526 &fusion
->ld_map_phys
[i
],
1528 if (!fusion
->ld_map
[i
]) {
1529 dev_err(&instance
->pdev
->dev
,
1530 "Could not allocate memory for map info %s:%d\n",
1531 __func__
, __LINE__
);
1532 goto ld_map_alloc_fail
;
1539 for (i
= 0; i
< 2; i
++) {
1540 if (fusion
->ld_map
[i
])
1541 dma_free_coherent(&instance
->pdev
->dev
,
1544 fusion
->ld_map_phys
[i
]);
1547 ld_drv_map_alloc_fail
:
1548 for (i
= 0; i
< 2; i
++) {
1549 if (fusion
->ld_drv_map
[i
]) {
1550 if (is_vmalloc_addr(fusion
->ld_drv_map
[i
]))
1551 vfree(fusion
->ld_drv_map
[i
]);
1553 free_pages((ulong
)fusion
->ld_drv_map
[i
],
1554 fusion
->drv_map_pages
);
1562 * megasas_configure_queue_sizes - Calculate size of request desc queue,
1564 * IO request frame queue, set can_queue.
1565 * @instance: Adapter soft state
1569 void megasas_configure_queue_sizes(struct megasas_instance
*instance
)
1571 struct fusion_context
*fusion
;
1574 fusion
= instance
->ctrl_context
;
1575 max_cmd
= instance
->max_fw_cmds
;
1577 if (instance
->adapter_type
== VENTURA_SERIES
)
1578 instance
->max_mpt_cmds
= instance
->max_fw_cmds
* RAID_1_PEER_CMDS
;
1580 instance
->max_mpt_cmds
= instance
->max_fw_cmds
;
1582 instance
->max_scsi_cmds
= instance
->max_fw_cmds
-
1583 (MEGASAS_FUSION_INTERNAL_CMDS
+
1584 MEGASAS_FUSION_IOCTL_CMDS
);
1585 instance
->cur_can_queue
= instance
->max_scsi_cmds
;
1586 instance
->host
->can_queue
= instance
->cur_can_queue
;
1588 fusion
->reply_q_depth
= 2 * ((max_cmd
+ 1 + 15) / 16) * 16;
1590 fusion
->request_alloc_sz
= sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION
) *
1591 instance
->max_mpt_cmds
;
1592 fusion
->reply_alloc_sz
= sizeof(union MPI2_REPLY_DESCRIPTORS_UNION
) *
1593 (fusion
->reply_q_depth
);
1594 fusion
->io_frames_alloc_sz
= MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
+
1595 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1596 * (instance
->max_mpt_cmds
+ 1)); /* Extra 1 for SMID 0 */
1599 static int megasas_alloc_ioc_init_frame(struct megasas_instance
*instance
)
1601 struct fusion_context
*fusion
;
1602 struct megasas_cmd
*cmd
;
1604 fusion
= instance
->ctrl_context
;
1606 cmd
= kzalloc(sizeof(struct megasas_cmd
), GFP_KERNEL
);
1609 dev_err(&instance
->pdev
->dev
, "Failed from func: %s line: %d\n",
1610 __func__
, __LINE__
);
1614 cmd
->frame
= dma_alloc_coherent(&instance
->pdev
->dev
,
1615 IOC_INIT_FRAME_SIZE
,
1616 &cmd
->frame_phys_addr
, GFP_KERNEL
);
1619 dev_err(&instance
->pdev
->dev
, "Failed from func: %s line: %d\n",
1620 __func__
, __LINE__
);
1625 fusion
->ioc_init_cmd
= cmd
;
1630 * megasas_free_ioc_init_cmd - Free IOC INIT command frame
1631 * @instance: Adapter soft state
1633 static inline void megasas_free_ioc_init_cmd(struct megasas_instance
*instance
)
1635 struct fusion_context
*fusion
;
1637 fusion
= instance
->ctrl_context
;
1639 if (fusion
->ioc_init_cmd
&& fusion
->ioc_init_cmd
->frame
)
1640 dma_free_coherent(&instance
->pdev
->dev
,
1641 IOC_INIT_FRAME_SIZE
,
1642 fusion
->ioc_init_cmd
->frame
,
1643 fusion
->ioc_init_cmd
->frame_phys_addr
);
1645 if (fusion
->ioc_init_cmd
)
1646 kfree(fusion
->ioc_init_cmd
);
1650 * megasas_init_adapter_fusion - Initializes the FW
1651 * @instance: Adapter soft state
1653 * This is the main function for initializing firmware.
1656 megasas_init_adapter_fusion(struct megasas_instance
*instance
)
1658 struct megasas_register_set __iomem
*reg_set
;
1659 struct fusion_context
*fusion
;
1663 fusion
= instance
->ctrl_context
;
1665 reg_set
= instance
->reg_set
;
1667 megasas_fusion_update_can_queue(instance
, PROBE_CONTEXT
);
1670 * Only Driver's internal DCMDs and IOCTL DCMDs needs to have MFI frames
1672 instance
->max_mfi_cmds
=
1673 MEGASAS_FUSION_INTERNAL_CMDS
+ MEGASAS_FUSION_IOCTL_CMDS
;
1675 megasas_configure_queue_sizes(instance
);
1677 scratch_pad_2
= readl(&instance
->reg_set
->outbound_scratch_pad_2
);
1678 /* If scratch_pad_2 & MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK is set,
1679 * Firmware support extended IO chain frame which is 4 times more than
1681 * Legacy Firmware - Frame size is (8 * 128) = 1K
1682 * 1M IO Firmware - Frame size is (8 * 128 * 4) = 4K
1684 if (scratch_pad_2
& MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK
)
1685 instance
->max_chain_frame_sz
=
1686 ((scratch_pad_2
& MEGASAS_MAX_CHAIN_SIZE_MASK
) >>
1687 MEGASAS_MAX_CHAIN_SHIFT
) * MEGASAS_1MB_IO
;
1689 instance
->max_chain_frame_sz
=
1690 ((scratch_pad_2
& MEGASAS_MAX_CHAIN_SIZE_MASK
) >>
1691 MEGASAS_MAX_CHAIN_SHIFT
) * MEGASAS_256K_IO
;
1693 if (instance
->max_chain_frame_sz
< MEGASAS_CHAIN_FRAME_SZ_MIN
) {
1694 dev_warn(&instance
->pdev
->dev
, "frame size %d invalid, fall back to legacy max frame size %d\n",
1695 instance
->max_chain_frame_sz
,
1696 MEGASAS_CHAIN_FRAME_SZ_MIN
);
1697 instance
->max_chain_frame_sz
= MEGASAS_CHAIN_FRAME_SZ_MIN
;
1700 fusion
->max_sge_in_main_msg
=
1701 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
1702 - offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
, SGL
))/16;
1704 fusion
->max_sge_in_chain
=
1705 instance
->max_chain_frame_sz
1706 / sizeof(union MPI2_SGE_IO_UNION
);
1708 instance
->max_num_sge
=
1709 rounddown_pow_of_two(fusion
->max_sge_in_main_msg
1710 + fusion
->max_sge_in_chain
- 2);
1712 /* Used for pass thru MFI frame (DCMD) */
1713 fusion
->chain_offset_mfi_pthru
=
1714 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
, SGL
)/16;
1716 fusion
->chain_offset_io_request
=
1717 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE
-
1718 sizeof(union MPI2_SGE_IO_UNION
))/16;
1720 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
1721 for (i
= 0 ; i
< count
; i
++)
1722 fusion
->last_reply_idx
[i
] = 0;
1725 * For fusion adapters, 3 commands for IOCTL and 8 commands
1726 * for driver's internal DCMDs.
1728 instance
->max_scsi_cmds
= instance
->max_fw_cmds
-
1729 (MEGASAS_FUSION_INTERNAL_CMDS
+
1730 MEGASAS_FUSION_IOCTL_CMDS
);
1731 sema_init(&instance
->ioctl_sem
, MEGASAS_FUSION_IOCTL_CMDS
);
1733 if (megasas_alloc_ioc_init_frame(instance
))
1737 * Allocate memory for descriptors
1738 * Create a pool of commands
1740 if (megasas_alloc_cmds(instance
))
1741 goto fail_alloc_mfi_cmds
;
1742 if (megasas_alloc_cmds_fusion(instance
))
1743 goto fail_alloc_cmds
;
1745 if (megasas_ioc_init_fusion(instance
))
1748 megasas_display_intel_branding(instance
);
1749 if (megasas_get_ctrl_info(instance
)) {
1750 dev_err(&instance
->pdev
->dev
,
1751 "Could not get controller info. Fail from %s %d\n",
1752 __func__
, __LINE__
);
1756 instance
->flag_ieee
= 1;
1757 instance
->r1_ldio_hint_default
= MR_R1_LDIO_PIGGYBACK_DEFAULT
;
1758 fusion
->fast_path_io
= 0;
1760 if (megasas_allocate_raid_maps(instance
))
1763 if (!megasas_get_map_info(instance
))
1764 megasas_sync_map_info(instance
);
1769 megasas_free_cmds_fusion(instance
);
1771 megasas_free_cmds(instance
);
1772 fail_alloc_mfi_cmds
:
1773 megasas_free_ioc_init_cmd(instance
);
1778 * map_cmd_status - Maps FW cmd status to OS cmd status
1779 * @cmd : Pointer to cmd
1780 * @status : status of cmd returned by FW
1781 * @ext_status : ext status of cmd returned by FW
1785 map_cmd_status(struct fusion_context
*fusion
,
1786 struct scsi_cmnd
*scmd
, u8 status
, u8 ext_status
,
1787 u32 data_length
, u8
*sense
)
1792 cmd_type
= megasas_cmd_type(scmd
);
1796 scmd
->result
= DID_OK
<< 16;
1799 case MFI_STAT_SCSI_IO_FAILED
:
1800 case MFI_STAT_LD_INIT_IN_PROGRESS
:
1801 scmd
->result
= (DID_ERROR
<< 16) | ext_status
;
1804 case MFI_STAT_SCSI_DONE_WITH_ERROR
:
1806 scmd
->result
= (DID_OK
<< 16) | ext_status
;
1807 if (ext_status
== SAM_STAT_CHECK_CONDITION
) {
1808 memset(scmd
->sense_buffer
, 0,
1809 SCSI_SENSE_BUFFERSIZE
);
1810 memcpy(scmd
->sense_buffer
, sense
,
1811 SCSI_SENSE_BUFFERSIZE
);
1812 scmd
->result
|= DRIVER_SENSE
<< 24;
1816 * If the IO request is partially completed, then MR FW will
1817 * update "io_request->DataLength" field with actual number of
1818 * bytes transferred.Driver will set residual bytes count in
1819 * SCSI command structure.
1821 resid
= (scsi_bufflen(scmd
) - data_length
);
1822 scsi_set_resid(scmd
, resid
);
1825 ((cmd_type
== READ_WRITE_LDIO
) ||
1826 (cmd_type
== READ_WRITE_SYSPDIO
)))
1827 scmd_printk(KERN_INFO
, scmd
, "BRCM Debug mfi stat 0x%x, data len"
1828 " requested/completed 0x%x/0x%x\n",
1829 status
, scsi_bufflen(scmd
), data_length
);
1832 case MFI_STAT_LD_OFFLINE
:
1833 case MFI_STAT_DEVICE_NOT_FOUND
:
1834 scmd
->result
= DID_BAD_TARGET
<< 16;
1836 case MFI_STAT_CONFIG_SEQ_MISMATCH
:
1837 scmd
->result
= DID_IMM_RETRY
<< 16;
1840 scmd
->result
= DID_ERROR
<< 16;
1846 * megasas_is_prp_possible -
1847 * Checks if native NVMe PRPs can be built for the IO
1849 * @instance: Adapter soft state
1850 * @scmd: SCSI command from the mid-layer
1851 * @sge_count: scatter gather element count.
1853 * Returns: true: PRPs can be built
1854 * false: IEEE SGLs needs to be built
1857 megasas_is_prp_possible(struct megasas_instance
*instance
,
1858 struct scsi_cmnd
*scmd
, int sge_count
)
1860 struct fusion_context
*fusion
;
1862 u32 data_length
= 0;
1863 struct scatterlist
*sg_scmd
;
1864 bool build_prp
= false;
1865 u32 mr_nvme_pg_size
;
1867 mr_nvme_pg_size
= max_t(u32
, instance
->nvme_page_size
,
1868 MR_DEFAULT_NVME_PAGE_SIZE
);
1869 fusion
= instance
->ctrl_context
;
1870 data_length
= scsi_bufflen(scmd
);
1871 sg_scmd
= scsi_sglist(scmd
);
1874 * NVMe uses one PRP for each page (or part of a page)
1875 * look at the data length - if 4 pages or less then IEEE is OK
1876 * if > 5 pages then we need to build a native SGL
1877 * if > 4 and <= 5 pages, then check physical address of 1st SG entry
1878 * if this first size in the page is >= the residual beyond 4 pages
1879 * then use IEEE, otherwise use native SGL
1882 if (data_length
> (mr_nvme_pg_size
* 5)) {
1884 } else if ((data_length
> (mr_nvme_pg_size
* 4)) &&
1885 (data_length
<= (mr_nvme_pg_size
* 5))) {
1886 /* check if 1st SG entry size is < residual beyond 4 pages */
1887 if (sg_dma_len(sg_scmd
) < (data_length
- (mr_nvme_pg_size
* 4)))
1892 * Below code detects gaps/holes in IO data buffers.
1893 * What does holes/gaps mean?
1894 * Any SGE except first one in a SGL starts at non NVME page size
1895 * aligned address OR Any SGE except last one in a SGL ends at
1896 * non NVME page size boundary.
1898 * Driver has already informed block layer by setting boundary rules for
1899 * bio merging done at NVME page size boundary calling kernel API
1900 * blk_queue_virt_boundary inside slave_config.
1901 * Still there is possibility of IO coming with holes to driver because of
1902 * IO merging done by IO scheduler.
1904 * With SCSI BLK MQ enabled, there will be no IO with holes as there is no
1905 * IO scheduling so no IO merging.
1907 * With SCSI BLK MQ disabled, IO scheduler may attempt to merge IOs and
1908 * then sending IOs with holes.
1910 * Though driver can request block layer to disable IO merging by calling-
1911 * queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, sdev->request_queue) but
1912 * user may tune sysfs parameter- nomerges again to 0 or 1.
1914 * If in future IO scheduling is enabled with SCSI BLK MQ,
1915 * this algorithm to detect holes will be required in driver
1916 * for SCSI BLK MQ enabled case as well.
1920 scsi_for_each_sg(scmd
, sg_scmd
, sge_count
, i
) {
1921 if ((i
!= 0) && (i
!= (sge_count
- 1))) {
1922 if (mega_mod64(sg_dma_len(sg_scmd
), mr_nvme_pg_size
) ||
1923 mega_mod64(sg_dma_address(sg_scmd
),
1926 atomic_inc(&instance
->sge_holes_type1
);
1931 if ((sge_count
> 1) && (i
== 0)) {
1932 if ((mega_mod64((sg_dma_address(sg_scmd
) +
1933 sg_dma_len(sg_scmd
)),
1934 mr_nvme_pg_size
))) {
1936 atomic_inc(&instance
->sge_holes_type2
);
1941 if ((sge_count
> 1) && (i
== (sge_count
- 1))) {
1942 if (mega_mod64(sg_dma_address(sg_scmd
),
1945 atomic_inc(&instance
->sge_holes_type3
);
1955 * megasas_make_prp_nvme -
1956 * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only
1958 * @instance: Adapter soft state
1959 * @scmd: SCSI command from the mid-layer
1960 * @sgl_ptr: SGL to be filled in
1961 * @cmd: Fusion command frame
1962 * @sge_count: scatter gather element count.
1964 * Returns: true: PRPs are built
1965 * false: IEEE SGLs needs to be built
1968 megasas_make_prp_nvme(struct megasas_instance
*instance
, struct scsi_cmnd
*scmd
,
1969 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr
,
1970 struct megasas_cmd_fusion
*cmd
, int sge_count
)
1972 int sge_len
, offset
, num_prp_in_chain
= 0;
1973 struct MPI25_IEEE_SGE_CHAIN64
*main_chain_element
, *ptr_first_sgl
;
1975 dma_addr_t ptr_sgl_phys
;
1977 u32 page_mask
, page_mask_result
;
1978 struct scatterlist
*sg_scmd
;
1980 bool build_prp
= false;
1981 int data_len
= scsi_bufflen(scmd
);
1982 struct fusion_context
*fusion
;
1983 u32 mr_nvme_pg_size
= max_t(u32
, instance
->nvme_page_size
,
1984 MR_DEFAULT_NVME_PAGE_SIZE
);
1986 fusion
= instance
->ctrl_context
;
1988 build_prp
= megasas_is_prp_possible(instance
, scmd
, sge_count
);
1994 * Nvme has a very convoluted prp format. One prp is required
1995 * for each page or partial page. Driver need to split up OS sg_list
1996 * entries if it is longer than one page or cross a page
1997 * boundary. Driver also have to insert a PRP list pointer entry as
1998 * the last entry in each physical page of the PRP list.
2000 * NOTE: The first PRP "entry" is actually placed in the first
2001 * SGL entry in the main message as IEEE 64 format. The 2nd
2002 * entry in the main message is the chain element, and the rest
2003 * of the PRP entries are built in the contiguous pcie buffer.
2005 page_mask
= mr_nvme_pg_size
- 1;
2006 ptr_sgl
= (u64
*)cmd
->sg_frame
;
2007 ptr_sgl_phys
= cmd
->sg_frame_phys_addr
;
2008 memset(ptr_sgl
, 0, instance
->max_chain_frame_sz
);
2010 /* Build chain frame element which holds all prps except first*/
2011 main_chain_element
= (struct MPI25_IEEE_SGE_CHAIN64
*)
2012 ((u8
*)sgl_ptr
+ sizeof(struct MPI25_IEEE_SGE_CHAIN64
));
2014 main_chain_element
->Address
= cpu_to_le64(ptr_sgl_phys
);
2015 main_chain_element
->NextChainOffset
= 0;
2016 main_chain_element
->Flags
= IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
2017 IEEE_SGE_FLAGS_SYSTEM_ADDR
|
2018 MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP
;
2020 /* Build first prp, sge need not to be page aligned*/
2021 ptr_first_sgl
= sgl_ptr
;
2022 sg_scmd
= scsi_sglist(scmd
);
2023 sge_addr
= sg_dma_address(sg_scmd
);
2024 sge_len
= sg_dma_len(sg_scmd
);
2026 offset
= (u32
)(sge_addr
& page_mask
);
2027 first_prp_len
= mr_nvme_pg_size
- offset
;
2029 ptr_first_sgl
->Address
= cpu_to_le64(sge_addr
);
2030 ptr_first_sgl
->Length
= cpu_to_le32(first_prp_len
);
2032 data_len
-= first_prp_len
;
2034 if (sge_len
> first_prp_len
) {
2035 sge_addr
+= first_prp_len
;
2036 sge_len
-= first_prp_len
;
2037 } else if (sge_len
== first_prp_len
) {
2038 sg_scmd
= sg_next(sg_scmd
);
2039 sge_addr
= sg_dma_address(sg_scmd
);
2040 sge_len
= sg_dma_len(sg_scmd
);
2044 offset
= (u32
)(sge_addr
& page_mask
);
2046 /* Put PRP pointer due to page boundary*/
2047 page_mask_result
= (uintptr_t)(ptr_sgl
+ 1) & page_mask
;
2048 if (unlikely(!page_mask_result
)) {
2049 scmd_printk(KERN_NOTICE
,
2050 scmd
, "page boundary ptr_sgl: 0x%p\n",
2053 *ptr_sgl
= cpu_to_le64(ptr_sgl_phys
);
2058 *ptr_sgl
= cpu_to_le64(sge_addr
);
2063 sge_addr
+= mr_nvme_pg_size
;
2064 sge_len
-= mr_nvme_pg_size
;
2065 data_len
-= mr_nvme_pg_size
;
2073 sg_scmd
= sg_next(sg_scmd
);
2074 sge_addr
= sg_dma_address(sg_scmd
);
2075 sge_len
= sg_dma_len(sg_scmd
);
2078 main_chain_element
->Length
=
2079 cpu_to_le32(num_prp_in_chain
* sizeof(u64
));
2081 atomic_inc(&instance
->prp_sgl
);
2086 * megasas_make_sgl_fusion - Prepares 32-bit SGL
2087 * @instance: Adapter soft state
2088 * @scp: SCSI command from the mid-layer
2089 * @sgl_ptr: SGL to be filled in
2090 * @cmd: cmd we are working on
2091 * @sge_count sge count
2095 megasas_make_sgl_fusion(struct megasas_instance
*instance
,
2096 struct scsi_cmnd
*scp
,
2097 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr
,
2098 struct megasas_cmd_fusion
*cmd
, int sge_count
)
2100 int i
, sg_processed
;
2101 struct scatterlist
*os_sgl
;
2102 struct fusion_context
*fusion
;
2104 fusion
= instance
->ctrl_context
;
2106 if (instance
->adapter_type
>= INVADER_SERIES
) {
2107 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr_end
= sgl_ptr
;
2108 sgl_ptr_end
+= fusion
->max_sge_in_main_msg
- 1;
2109 sgl_ptr_end
->Flags
= 0;
2112 scsi_for_each_sg(scp
, os_sgl
, sge_count
, i
) {
2113 sgl_ptr
->Length
= cpu_to_le32(sg_dma_len(os_sgl
));
2114 sgl_ptr
->Address
= cpu_to_le64(sg_dma_address(os_sgl
));
2116 if (instance
->adapter_type
>= INVADER_SERIES
)
2117 if (i
== sge_count
- 1)
2118 sgl_ptr
->Flags
= IEEE_SGE_FLAGS_END_OF_LIST
;
2120 sg_processed
= i
+ 1;
2122 if ((sg_processed
== (fusion
->max_sge_in_main_msg
- 1)) &&
2123 (sge_count
> fusion
->max_sge_in_main_msg
)) {
2125 struct MPI25_IEEE_SGE_CHAIN64
*sg_chain
;
2126 if (instance
->adapter_type
>= INVADER_SERIES
) {
2127 if ((le16_to_cpu(cmd
->io_request
->IoFlags
) &
2128 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
) !=
2129 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
)
2130 cmd
->io_request
->ChainOffset
=
2132 chain_offset_io_request
;
2134 cmd
->io_request
->ChainOffset
= 0;
2136 cmd
->io_request
->ChainOffset
=
2137 fusion
->chain_offset_io_request
;
2140 /* Prepare chain element */
2141 sg_chain
->NextChainOffset
= 0;
2142 if (instance
->adapter_type
>= INVADER_SERIES
)
2143 sg_chain
->Flags
= IEEE_SGE_FLAGS_CHAIN_ELEMENT
;
2146 (IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
2147 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR
);
2148 sg_chain
->Length
= cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION
) * (sge_count
- sg_processed
)));
2149 sg_chain
->Address
= cpu_to_le64(cmd
->sg_frame_phys_addr
);
2152 (struct MPI25_IEEE_SGE_CHAIN64
*)cmd
->sg_frame
;
2153 memset(sgl_ptr
, 0, instance
->max_chain_frame_sz
);
2156 atomic_inc(&instance
->ieee_sgl
);
2160 * megasas_make_sgl - Build Scatter Gather List(SGLs)
2161 * @scp: SCSI command pointer
2162 * @instance: Soft instance of controller
2163 * @cmd: Fusion command pointer
2165 * This function will build sgls based on device type.
2166 * For nvme drives, there is different way of building sgls in nvme native
2167 * format- PRPs(Physical Region Page).
2169 * Returns the number of sg lists actually used, zero if the sg lists
2170 * is NULL, or -ENOMEM if the mapping failed
2173 int megasas_make_sgl(struct megasas_instance
*instance
, struct scsi_cmnd
*scp
,
2174 struct megasas_cmd_fusion
*cmd
)
2177 bool build_prp
= false;
2178 struct MPI25_IEEE_SGE_CHAIN64
*sgl_chain64
;
2180 sge_count
= scsi_dma_map(scp
);
2182 if ((sge_count
> instance
->max_num_sge
) || (sge_count
<= 0))
2185 sgl_chain64
= (struct MPI25_IEEE_SGE_CHAIN64
*)&cmd
->io_request
->SGL
;
2186 if ((le16_to_cpu(cmd
->io_request
->IoFlags
) &
2187 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
) &&
2188 (cmd
->pd_interface
== NVME_PD
))
2189 build_prp
= megasas_make_prp_nvme(instance
, scp
, sgl_chain64
,
2193 megasas_make_sgl_fusion(instance
, scp
, sgl_chain64
,
2200 * megasas_set_pd_lba - Sets PD LBA
2202 * @cdb_len: cdb length
2203 * @start_blk: Start block of IO
2205 * Used to set the PD LBA in CDB for FP IOs
2208 megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
, u8 cdb_len
,
2209 struct IO_REQUEST_INFO
*io_info
, struct scsi_cmnd
*scp
,
2210 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
, u32 ref_tag
)
2212 struct MR_LD_RAID
*raid
;
2214 u64 start_blk
= io_info
->pdBlock
;
2215 u8
*cdb
= io_request
->CDB
.CDB32
;
2216 u32 num_blocks
= io_info
->numBlocks
;
2217 u8 opcode
= 0, flagvals
= 0, groupnum
= 0, control
= 0;
2219 /* Check if T10 PI (DIF) is enabled for this LD */
2220 ld
= MR_TargetIdToLdGet(io_info
->ldTgtId
, local_map_ptr
);
2221 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
2222 if (raid
->capability
.ldPiMode
== MR_PROT_INFO_TYPE_CONTROLLER
) {
2223 memset(cdb
, 0, sizeof(io_request
->CDB
.CDB32
));
2224 cdb
[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD
;
2225 cdb
[7] = MEGASAS_SCSI_ADDL_CDB_LEN
;
2227 if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
)
2228 cdb
[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32
;
2230 cdb
[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32
;
2231 cdb
[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL
;
2234 cdb
[12] = (u8
)((start_blk
>> 56) & 0xff);
2235 cdb
[13] = (u8
)((start_blk
>> 48) & 0xff);
2236 cdb
[14] = (u8
)((start_blk
>> 40) & 0xff);
2237 cdb
[15] = (u8
)((start_blk
>> 32) & 0xff);
2238 cdb
[16] = (u8
)((start_blk
>> 24) & 0xff);
2239 cdb
[17] = (u8
)((start_blk
>> 16) & 0xff);
2240 cdb
[18] = (u8
)((start_blk
>> 8) & 0xff);
2241 cdb
[19] = (u8
)(start_blk
& 0xff);
2243 /* Logical block reference tag */
2244 io_request
->CDB
.EEDP32
.PrimaryReferenceTag
=
2245 cpu_to_be32(ref_tag
);
2246 io_request
->CDB
.EEDP32
.PrimaryApplicationTagMask
= cpu_to_be16(0xffff);
2247 io_request
->IoFlags
= cpu_to_le16(32); /* Specify 32-byte cdb */
2249 /* Transfer length */
2250 cdb
[28] = (u8
)((num_blocks
>> 24) & 0xff);
2251 cdb
[29] = (u8
)((num_blocks
>> 16) & 0xff);
2252 cdb
[30] = (u8
)((num_blocks
>> 8) & 0xff);
2253 cdb
[31] = (u8
)(num_blocks
& 0xff);
2255 /* set SCSI IO EEDPFlags */
2256 if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
) {
2257 io_request
->EEDPFlags
= cpu_to_le16(
2258 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2259 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG
|
2260 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP
|
2261 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG
|
2262 MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE
|
2263 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD
);
2265 io_request
->EEDPFlags
= cpu_to_le16(
2266 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG
|
2267 MPI2_SCSIIO_EEDPFLAGS_INSERT_OP
);
2269 io_request
->Control
|= cpu_to_le32((0x4 << 26));
2270 io_request
->EEDPBlockSize
= cpu_to_le32(scp
->device
->sector_size
);
2272 /* Some drives don't support 16/12 byte CDB's, convert to 10 */
2273 if (((cdb_len
== 12) || (cdb_len
== 16)) &&
2274 (start_blk
<= 0xffffffff)) {
2275 if (cdb_len
== 16) {
2276 opcode
= cdb
[0] == READ_16
? READ_10
: WRITE_10
;
2281 opcode
= cdb
[0] == READ_12
? READ_10
: WRITE_10
;
2287 memset(cdb
, 0, sizeof(io_request
->CDB
.CDB32
));
2294 /* Transfer length */
2295 cdb
[8] = (u8
)(num_blocks
& 0xff);
2296 cdb
[7] = (u8
)((num_blocks
>> 8) & 0xff);
2298 io_request
->IoFlags
= cpu_to_le16(10); /* Specify 10-byte cdb */
2300 } else if ((cdb_len
< 16) && (start_blk
> 0xffffffff)) {
2301 /* Convert to 16 byte CDB for large LBA's */
2304 opcode
= cdb
[0] == READ_6
? READ_16
: WRITE_16
;
2309 cdb
[0] == READ_10
? READ_16
: WRITE_16
;
2316 cdb
[0] == READ_12
? READ_16
: WRITE_16
;
2323 memset(cdb
, 0, sizeof(io_request
->CDB
.CDB32
));
2330 /* Transfer length */
2331 cdb
[13] = (u8
)(num_blocks
& 0xff);
2332 cdb
[12] = (u8
)((num_blocks
>> 8) & 0xff);
2333 cdb
[11] = (u8
)((num_blocks
>> 16) & 0xff);
2334 cdb
[10] = (u8
)((num_blocks
>> 24) & 0xff);
2336 io_request
->IoFlags
= cpu_to_le16(16); /* Specify 16-byte cdb */
2340 /* Normal case, just load LBA here */
2344 u8 val
= cdb
[1] & 0xE0;
2345 cdb
[3] = (u8
)(start_blk
& 0xff);
2346 cdb
[2] = (u8
)((start_blk
>> 8) & 0xff);
2347 cdb
[1] = val
| ((u8
)(start_blk
>> 16) & 0x1f);
2351 cdb
[5] = (u8
)(start_blk
& 0xff);
2352 cdb
[4] = (u8
)((start_blk
>> 8) & 0xff);
2353 cdb
[3] = (u8
)((start_blk
>> 16) & 0xff);
2354 cdb
[2] = (u8
)((start_blk
>> 24) & 0xff);
2357 cdb
[5] = (u8
)(start_blk
& 0xff);
2358 cdb
[4] = (u8
)((start_blk
>> 8) & 0xff);
2359 cdb
[3] = (u8
)((start_blk
>> 16) & 0xff);
2360 cdb
[2] = (u8
)((start_blk
>> 24) & 0xff);
2363 cdb
[9] = (u8
)(start_blk
& 0xff);
2364 cdb
[8] = (u8
)((start_blk
>> 8) & 0xff);
2365 cdb
[7] = (u8
)((start_blk
>> 16) & 0xff);
2366 cdb
[6] = (u8
)((start_blk
>> 24) & 0xff);
2367 cdb
[5] = (u8
)((start_blk
>> 32) & 0xff);
2368 cdb
[4] = (u8
)((start_blk
>> 40) & 0xff);
2369 cdb
[3] = (u8
)((start_blk
>> 48) & 0xff);
2370 cdb
[2] = (u8
)((start_blk
>> 56) & 0xff);
2377 * megasas_stream_detect - stream detection on read and and write IOs
2378 * @instance: Adapter soft state
2379 * @cmd: Command to be prepared
2380 * @io_info: IO Request info
2384 /** stream detection on read and and write IOs */
2385 static void megasas_stream_detect(struct megasas_instance
*instance
,
2386 struct megasas_cmd_fusion
*cmd
,
2387 struct IO_REQUEST_INFO
*io_info
)
2389 struct fusion_context
*fusion
= instance
->ctrl_context
;
2390 u32 device_id
= io_info
->ldTgtId
;
2391 struct LD_STREAM_DETECT
*current_ld_sd
2392 = fusion
->stream_detect_by_ld
[device_id
];
2393 u32
*track_stream
= ¤t_ld_sd
->mru_bit_map
, stream_num
;
2394 u32 shifted_values
, unshifted_values
;
2395 u32 index_value_mask
, shifted_values_mask
;
2397 bool is_read_ahead
= false;
2398 struct STREAM_DETECT
*current_sd
;
2399 /* find possible stream */
2400 for (i
= 0; i
< MAX_STREAMS_TRACKED
; ++i
) {
2401 stream_num
= (*track_stream
>>
2402 (i
* BITS_PER_INDEX_STREAM
)) &
2404 current_sd
= ¤t_ld_sd
->stream_track
[stream_num
];
2405 /* if we found a stream, update the raid
2406 * context and also update the mruBitMap
2408 /* boundary condition */
2409 if ((current_sd
->next_seq_lba
) &&
2410 (io_info
->ldStartBlock
>= current_sd
->next_seq_lba
) &&
2411 (io_info
->ldStartBlock
<= (current_sd
->next_seq_lba
+ 32)) &&
2412 (current_sd
->is_read
== io_info
->isRead
)) {
2414 if ((io_info
->ldStartBlock
!= current_sd
->next_seq_lba
) &&
2415 ((!io_info
->isRead
) || (!is_read_ahead
)))
2417 * Once the API availible we need to change this.
2418 * At this point we are not allowing any gap
2422 SET_STREAM_DETECTED(cmd
->io_request
->RaidContext
.raid_context_g35
);
2423 current_sd
->next_seq_lba
=
2424 io_info
->ldStartBlock
+ io_info
->numBlocks
;
2426 * update the mruBitMap LRU
2428 shifted_values_mask
=
2429 (1 << i
* BITS_PER_INDEX_STREAM
) - 1;
2430 shifted_values
= ((*track_stream
& shifted_values_mask
)
2431 << BITS_PER_INDEX_STREAM
);
2433 STREAM_MASK
<< i
* BITS_PER_INDEX_STREAM
;
2435 *track_stream
& ~(shifted_values_mask
|
2438 unshifted_values
| shifted_values
| stream_num
;
2443 * if we did not find any stream, create a new one
2444 * from the least recently used
2446 stream_num
= (*track_stream
>>
2447 ((MAX_STREAMS_TRACKED
- 1) * BITS_PER_INDEX_STREAM
)) &
2449 current_sd
= ¤t_ld_sd
->stream_track
[stream_num
];
2450 current_sd
->is_read
= io_info
->isRead
;
2451 current_sd
->next_seq_lba
= io_info
->ldStartBlock
+ io_info
->numBlocks
;
2452 *track_stream
= (((*track_stream
& ZERO_LAST_STREAM
) << 4) | stream_num
);
2457 * megasas_set_raidflag_cpu_affinity - This function sets the cpu
2458 * affinity (cpu of the controller) and raid_flags in the raid context
2461 * @praid_context: IO RAID context
2462 * @raid: LD raid map
2463 * @fp_possible: Is fast path possible?
2464 * @is_read: Is read IO?
2468 megasas_set_raidflag_cpu_affinity(union RAID_CONTEXT_UNION
*praid_context
,
2469 struct MR_LD_RAID
*raid
, bool fp_possible
,
2470 u8 is_read
, u32 scsi_buff_len
)
2472 u8 cpu_sel
= MR_RAID_CTX_CPUSEL_0
;
2473 struct RAID_CONTEXT_G35
*rctx_g35
;
2475 rctx_g35
= &praid_context
->raid_context_g35
;
2478 if ((raid
->cpuAffinity
.pdRead
.cpu0
) &&
2479 (raid
->cpuAffinity
.pdRead
.cpu1
))
2480 cpu_sel
= MR_RAID_CTX_CPUSEL_FCFS
;
2481 else if (raid
->cpuAffinity
.pdRead
.cpu1
)
2482 cpu_sel
= MR_RAID_CTX_CPUSEL_1
;
2484 if ((raid
->cpuAffinity
.pdWrite
.cpu0
) &&
2485 (raid
->cpuAffinity
.pdWrite
.cpu1
))
2486 cpu_sel
= MR_RAID_CTX_CPUSEL_FCFS
;
2487 else if (raid
->cpuAffinity
.pdWrite
.cpu1
)
2488 cpu_sel
= MR_RAID_CTX_CPUSEL_1
;
2489 /* Fast path cache by pass capable R0/R1 VD */
2490 if ((raid
->level
<= 1) &&
2491 (raid
->capability
.fp_cache_bypass_capable
)) {
2492 rctx_g35
->routing_flags
|=
2493 (1 << MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT
);
2494 rctx_g35
->raid_flags
=
2495 (MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS
2496 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT
);
2501 if ((raid
->cpuAffinity
.ldRead
.cpu0
) &&
2502 (raid
->cpuAffinity
.ldRead
.cpu1
))
2503 cpu_sel
= MR_RAID_CTX_CPUSEL_FCFS
;
2504 else if (raid
->cpuAffinity
.ldRead
.cpu1
)
2505 cpu_sel
= MR_RAID_CTX_CPUSEL_1
;
2507 if ((raid
->cpuAffinity
.ldWrite
.cpu0
) &&
2508 (raid
->cpuAffinity
.ldWrite
.cpu1
))
2509 cpu_sel
= MR_RAID_CTX_CPUSEL_FCFS
;
2510 else if (raid
->cpuAffinity
.ldWrite
.cpu1
)
2511 cpu_sel
= MR_RAID_CTX_CPUSEL_1
;
2513 if (is_stream_detected(rctx_g35
) &&
2514 ((raid
->level
== 5) || (raid
->level
== 6)) &&
2515 (raid
->writeMode
== MR_RL_WRITE_THROUGH_MODE
) &&
2516 (cpu_sel
== MR_RAID_CTX_CPUSEL_FCFS
))
2517 cpu_sel
= MR_RAID_CTX_CPUSEL_0
;
2521 rctx_g35
->routing_flags
|=
2522 (cpu_sel
<< MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT
);
2524 /* Always give priority to MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2525 * vs MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS.
2526 * IO Subtype is not bitmap.
2528 if ((raid
->level
== 1) && (!is_read
)) {
2529 if (scsi_buff_len
> MR_LARGE_IO_MIN_SIZE
)
2530 praid_context
->raid_context_g35
.raid_flags
=
2531 (MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT
2532 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT
);
2537 * megasas_build_ldio_fusion - Prepares IOs to devices
2538 * @instance: Adapter soft state
2539 * @scp: SCSI command
2540 * @cmd: Command to be prepared
2542 * Prepares the io_request and chain elements (sg_frame) for IO
2543 * The IO can be for PD (Fast Path) or LD
2546 megasas_build_ldio_fusion(struct megasas_instance
*instance
,
2547 struct scsi_cmnd
*scp
,
2548 struct megasas_cmd_fusion
*cmd
)
2552 u32 start_lba_lo
, start_lba_hi
, device_id
, datalength
= 0;
2554 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
2555 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
2556 struct IO_REQUEST_INFO io_info
;
2557 struct fusion_context
*fusion
;
2558 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
2560 unsigned long spinlock_flags
;
2561 union RAID_CONTEXT_UNION
*praid_context
;
2562 struct MR_LD_RAID
*raid
= NULL
;
2563 struct MR_PRIV_DEVICE
*mrdev_priv
;
2565 device_id
= MEGASAS_DEV_INDEX(scp
);
2567 fusion
= instance
->ctrl_context
;
2569 io_request
= cmd
->io_request
;
2570 io_request
->RaidContext
.raid_context
.virtual_disk_tgt_id
=
2571 cpu_to_le16(device_id
);
2572 io_request
->RaidContext
.raid_context
.status
= 0;
2573 io_request
->RaidContext
.raid_context
.ex_status
= 0;
2575 req_desc
= (union MEGASAS_REQUEST_DESCRIPTOR_UNION
*)cmd
->request_desc
;
2579 fp_possible
= false;
2582 * 6-byte READ(0x08) or WRITE(0x0A) cdb
2584 if (scp
->cmd_len
== 6) {
2585 datalength
= (u32
) scp
->cmnd
[4];
2586 start_lba_lo
= ((u32
) scp
->cmnd
[1] << 16) |
2587 ((u32
) scp
->cmnd
[2] << 8) | (u32
) scp
->cmnd
[3];
2589 start_lba_lo
&= 0x1FFFFF;
2593 * 10-byte READ(0x28) or WRITE(0x2A) cdb
2595 else if (scp
->cmd_len
== 10) {
2596 datalength
= (u32
) scp
->cmnd
[8] |
2597 ((u32
) scp
->cmnd
[7] << 8);
2598 start_lba_lo
= ((u32
) scp
->cmnd
[2] << 24) |
2599 ((u32
) scp
->cmnd
[3] << 16) |
2600 ((u32
) scp
->cmnd
[4] << 8) | (u32
) scp
->cmnd
[5];
2604 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
2606 else if (scp
->cmd_len
== 12) {
2607 datalength
= ((u32
) scp
->cmnd
[6] << 24) |
2608 ((u32
) scp
->cmnd
[7] << 16) |
2609 ((u32
) scp
->cmnd
[8] << 8) | (u32
) scp
->cmnd
[9];
2610 start_lba_lo
= ((u32
) scp
->cmnd
[2] << 24) |
2611 ((u32
) scp
->cmnd
[3] << 16) |
2612 ((u32
) scp
->cmnd
[4] << 8) | (u32
) scp
->cmnd
[5];
2616 * 16-byte READ(0x88) or WRITE(0x8A) cdb
2618 else if (scp
->cmd_len
== 16) {
2619 datalength
= ((u32
) scp
->cmnd
[10] << 24) |
2620 ((u32
) scp
->cmnd
[11] << 16) |
2621 ((u32
) scp
->cmnd
[12] << 8) | (u32
) scp
->cmnd
[13];
2622 start_lba_lo
= ((u32
) scp
->cmnd
[6] << 24) |
2623 ((u32
) scp
->cmnd
[7] << 16) |
2624 ((u32
) scp
->cmnd
[8] << 8) | (u32
) scp
->cmnd
[9];
2626 start_lba_hi
= ((u32
) scp
->cmnd
[2] << 24) |
2627 ((u32
) scp
->cmnd
[3] << 16) |
2628 ((u32
) scp
->cmnd
[4] << 8) | (u32
) scp
->cmnd
[5];
2631 memset(&io_info
, 0, sizeof(struct IO_REQUEST_INFO
));
2632 io_info
.ldStartBlock
= ((u64
)start_lba_hi
<< 32) | start_lba_lo
;
2633 io_info
.numBlocks
= datalength
;
2634 io_info
.ldTgtId
= device_id
;
2635 io_info
.r1_alt_dev_handle
= MR_DEVHANDLE_INVALID
;
2636 scsi_buff_len
= scsi_bufflen(scp
);
2637 io_request
->DataLength
= cpu_to_le32(scsi_buff_len
);
2639 if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
)
2642 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
2643 ld
= MR_TargetIdToLdGet(device_id
, local_map_ptr
);
2645 if (ld
< instance
->fw_supported_vd_count
)
2646 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
2648 if (!raid
|| (!fusion
->fast_path_io
)) {
2649 io_request
->RaidContext
.raid_context
.reg_lock_flags
= 0;
2650 fp_possible
= false;
2652 if (MR_BuildRaidContext(instance
, &io_info
,
2653 &io_request
->RaidContext
.raid_context
,
2654 local_map_ptr
, &raidLUN
))
2655 fp_possible
= (io_info
.fpOkForIo
> 0) ? true : false;
2658 /* Use raw_smp_processor_id() for now until cmd->request->cpu is CPU
2659 id by default, not CPU group id, otherwise all MSI-X queues won't
2661 cmd
->request_desc
->SCSIIO
.MSIxIndex
= instance
->msix_vectors
?
2662 raw_smp_processor_id() % instance
->msix_vectors
: 0;
2664 praid_context
= &io_request
->RaidContext
;
2666 if (instance
->adapter_type
== VENTURA_SERIES
) {
2667 /* FP for Optimal raid level 1.
2668 * All large RAID-1 writes (> 32 KiB, both WT and WB modes)
2669 * are built by the driver as LD I/Os.
2670 * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os
2671 * (there is never a reason to process these as buffered writes)
2672 * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os
2673 * with the SLD bit asserted.
2675 if (io_info
.r1_alt_dev_handle
!= MR_DEVHANDLE_INVALID
) {
2676 mrdev_priv
= scp
->device
->hostdata
;
2678 if (atomic_inc_return(&instance
->fw_outstanding
) >
2679 (instance
->host
->can_queue
)) {
2680 fp_possible
= false;
2681 atomic_dec(&instance
->fw_outstanding
);
2682 } else if ((scsi_buff_len
> MR_LARGE_IO_MIN_SIZE
) ||
2683 (atomic_dec_if_positive(&mrdev_priv
->r1_ldio_hint
) > 0)) {
2684 fp_possible
= false;
2685 atomic_dec(&instance
->fw_outstanding
);
2686 if (scsi_buff_len
> MR_LARGE_IO_MIN_SIZE
)
2687 atomic_set(&mrdev_priv
->r1_ldio_hint
,
2688 instance
->r1_ldio_hint_default
);
2693 (io_info
.isRead
&& io_info
.ra_capable
)) {
2694 spin_lock_irqsave(&instance
->stream_lock
,
2696 megasas_stream_detect(instance
, cmd
, &io_info
);
2697 spin_unlock_irqrestore(&instance
->stream_lock
,
2699 /* In ventura if stream detected for a read and it is
2700 * read ahead capable make this IO as LDIO
2702 if (is_stream_detected(&io_request
->RaidContext
.raid_context_g35
))
2703 fp_possible
= false;
2706 /* If raid is NULL, set CPU affinity to default CPU0 */
2708 megasas_set_raidflag_cpu_affinity(praid_context
,
2709 raid
, fp_possible
, io_info
.isRead
,
2712 praid_context
->raid_context_g35
.routing_flags
|=
2713 (MR_RAID_CTX_CPUSEL_0
<< MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT
);
2717 megasas_set_pd_lba(io_request
, scp
->cmd_len
, &io_info
, scp
,
2718 local_map_ptr
, start_lba_lo
);
2719 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2720 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2721 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
2722 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2723 if (instance
->adapter_type
== INVADER_SERIES
) {
2724 if (io_request
->RaidContext
.raid_context
.reg_lock_flags
==
2726 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2727 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK
<<
2728 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2729 io_request
->RaidContext
.raid_context
.type
2731 io_request
->RaidContext
.raid_context
.nseg
= 0x1;
2732 io_request
->IoFlags
|= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
2733 io_request
->RaidContext
.raid_context
.reg_lock_flags
|=
2734 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA
|
2735 MR_RL_FLAGS_SEQ_NUM_ENABLE
);
2736 } else if (instance
->adapter_type
== VENTURA_SERIES
) {
2737 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2738 (1 << RAID_CONTEXT_NSEG_SHIFT
);
2739 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2740 (MPI2_TYPE_CUDA
<< RAID_CONTEXT_TYPE_SHIFT
);
2741 io_request
->RaidContext
.raid_context_g35
.routing_flags
|=
2742 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT
);
2743 io_request
->IoFlags
|=
2744 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
2746 if (fusion
->load_balance_info
&&
2747 (fusion
->load_balance_info
[device_id
].loadBalanceFlag
) &&
2750 get_updated_dev_handle(instance
,
2751 &fusion
->load_balance_info
[device_id
],
2752 &io_info
, local_map_ptr
);
2753 scp
->SCp
.Status
|= MEGASAS_LOAD_BALANCE_FLAG
;
2754 cmd
->pd_r1_lb
= io_info
.pd_after_lb
;
2755 if (instance
->adapter_type
== VENTURA_SERIES
)
2756 io_request
->RaidContext
.raid_context_g35
.span_arm
2759 io_request
->RaidContext
.raid_context
.span_arm
2763 scp
->SCp
.Status
&= ~MEGASAS_LOAD_BALANCE_FLAG
;
2765 if (instance
->adapter_type
== VENTURA_SERIES
)
2766 cmd
->r1_alt_dev_handle
= io_info
.r1_alt_dev_handle
;
2768 cmd
->r1_alt_dev_handle
= MR_DEVHANDLE_INVALID
;
2770 if ((raidLUN
[0] == 1) &&
2771 (local_map_ptr
->raidMap
.devHndlInfo
[io_info
.pd_after_lb
].validHandles
> 1)) {
2772 instance
->dev_handle
= !(instance
->dev_handle
);
2774 local_map_ptr
->raidMap
.devHndlInfo
[io_info
.pd_after_lb
].devHandle
[instance
->dev_handle
];
2777 cmd
->request_desc
->SCSIIO
.DevHandle
= io_info
.devHandle
;
2778 io_request
->DevHandle
= io_info
.devHandle
;
2779 cmd
->pd_interface
= io_info
.pd_interface
;
2780 /* populate the LUN field */
2781 memcpy(io_request
->LUN
, raidLUN
, 8);
2783 io_request
->RaidContext
.raid_context
.timeout_value
=
2784 cpu_to_le16(local_map_ptr
->raidMap
.fpPdIoTimeoutSec
);
2785 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2786 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
2787 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2788 if (instance
->adapter_type
== INVADER_SERIES
) {
2789 if (io_info
.do_fp_rlbypass
||
2790 (io_request
->RaidContext
.raid_context
.reg_lock_flags
2791 == REGION_TYPE_UNUSED
))
2792 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2793 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK
<<
2794 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2795 io_request
->RaidContext
.raid_context
.type
2797 io_request
->RaidContext
.raid_context
.reg_lock_flags
|=
2798 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0
|
2799 MR_RL_FLAGS_SEQ_NUM_ENABLE
);
2800 io_request
->RaidContext
.raid_context
.nseg
= 0x1;
2801 } else if (instance
->adapter_type
== VENTURA_SERIES
) {
2802 io_request
->RaidContext
.raid_context_g35
.routing_flags
|=
2803 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT
);
2804 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2805 (1 << RAID_CONTEXT_NSEG_SHIFT
);
2806 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2807 (MPI2_TYPE_CUDA
<< RAID_CONTEXT_TYPE_SHIFT
);
2809 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
2810 io_request
->DevHandle
= cpu_to_le16(device_id
);
2816 * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk
2817 * @instance: Adapter soft state
2818 * @scp: SCSI command
2819 * @cmd: Command to be prepared
2821 * Prepares the io_request frame for non-rw io cmds for vd.
2823 static void megasas_build_ld_nonrw_fusion(struct megasas_instance
*instance
,
2824 struct scsi_cmnd
*scmd
, struct megasas_cmd_fusion
*cmd
)
2827 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
2829 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
2830 struct fusion_context
*fusion
= instance
->ctrl_context
;
2834 struct MR_LD_RAID
*raid
;
2835 struct RAID_CONTEXT
*pRAID_Context
;
2838 io_request
= cmd
->io_request
;
2839 device_id
= MEGASAS_DEV_INDEX(scmd
);
2840 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
2841 io_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2842 /* get RAID_Context pointer */
2843 pRAID_Context
= &io_request
->RaidContext
.raid_context
;
2844 /* Check with FW team */
2845 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
2846 pRAID_Context
->reg_lock_row_lba
= 0;
2847 pRAID_Context
->reg_lock_length
= 0;
2849 if (fusion
->fast_path_io
&& (
2850 device_id
< instance
->fw_supported_vd_count
)) {
2852 ld
= MR_TargetIdToLdGet(device_id
, local_map_ptr
);
2853 if (ld
>= instance
->fw_supported_vd_count
)
2856 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
2857 if (!(raid
->capability
.fpNonRWCapable
))
2864 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
2865 io_request
->DevHandle
= cpu_to_le16(device_id
);
2866 io_request
->LUN
[1] = scmd
->device
->lun
;
2867 pRAID_Context
->timeout_value
=
2868 cpu_to_le16 (scmd
->request
->timeout
/ HZ
);
2869 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2870 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
2871 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2874 /* set RAID context values */
2875 pRAID_Context
->config_seq_num
= raid
->seqNum
;
2876 if (instance
->adapter_type
!= VENTURA_SERIES
)
2877 pRAID_Context
->reg_lock_flags
= REGION_TYPE_SHARED_READ
;
2878 pRAID_Context
->timeout_value
=
2879 cpu_to_le16(raid
->fpIoTimeoutForLd
);
2881 /* get the DevHandle for the PD (since this is
2882 fpNonRWCapable, this is a single disk RAID0) */
2884 arRef
= MR_LdSpanArrayGet(ld
, span
, local_map_ptr
);
2885 pd
= MR_ArPdGet(arRef
, physArm
, local_map_ptr
);
2886 devHandle
= MR_PdDevHandleGet(pd
, local_map_ptr
);
2888 /* build request descriptor */
2889 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2890 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
<<
2891 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2892 cmd
->request_desc
->SCSIIO
.DevHandle
= devHandle
;
2894 /* populate the LUN field */
2895 memcpy(io_request
->LUN
, raid
->LUN
, 8);
2897 /* build the raidScsiIO structure */
2898 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2899 io_request
->DevHandle
= devHandle
;
2904 * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd
2905 * @instance: Adapter soft state
2906 * @scp: SCSI command
2907 * @cmd: Command to be prepared
2908 * @fp_possible: parameter to detect fast path or firmware path io.
2910 * Prepares the io_request frame for rw/non-rw io cmds for syspds
2913 megasas_build_syspd_fusion(struct megasas_instance
*instance
,
2914 struct scsi_cmnd
*scmd
, struct megasas_cmd_fusion
*cmd
,
2918 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
2920 u16 os_timeout_value
;
2922 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
2923 struct RAID_CONTEXT
*pRAID_Context
;
2924 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
2925 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
2926 struct fusion_context
*fusion
= instance
->ctrl_context
;
2927 pd_sync
= (void *)fusion
->pd_seq_sync
[(instance
->pd_seq_map_id
- 1) & 1];
2929 device_id
= MEGASAS_DEV_INDEX(scmd
);
2930 pd_index
= MEGASAS_PD_INDEX(scmd
);
2931 os_timeout_value
= scmd
->request
->timeout
/ HZ
;
2932 mr_device_priv_data
= scmd
->device
->hostdata
;
2933 cmd
->pd_interface
= mr_device_priv_data
->interface_type
;
2935 io_request
= cmd
->io_request
;
2936 /* get RAID_Context pointer */
2937 pRAID_Context
= &io_request
->RaidContext
.raid_context
;
2938 pRAID_Context
->reg_lock_flags
= 0;
2939 pRAID_Context
->reg_lock_row_lba
= 0;
2940 pRAID_Context
->reg_lock_length
= 0;
2941 io_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2942 io_request
->LUN
[1] = scmd
->device
->lun
;
2943 pRAID_Context
->raid_flags
= MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
2944 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT
;
2946 /* If FW supports PD sequence number */
2947 if (instance
->use_seqnum_jbod_fp
&&
2948 instance
->pd_list
[pd_index
].driveType
== TYPE_DISK
) {
2949 /* TgtId must be incremented by 255 as jbod seq number is index
2952 /* More than 256 PD/JBOD support for Ventura */
2953 if (instance
->support_morethan256jbod
)
2954 pRAID_Context
->virtual_disk_tgt_id
=
2955 pd_sync
->seq
[pd_index
].pd_target_id
;
2957 pRAID_Context
->virtual_disk_tgt_id
=
2958 cpu_to_le16(device_id
+ (MAX_PHYSICAL_DEVICES
- 1));
2959 pRAID_Context
->config_seq_num
= pd_sync
->seq
[pd_index
].seqNum
;
2960 io_request
->DevHandle
= pd_sync
->seq
[pd_index
].devHandle
;
2961 if (instance
->adapter_type
== VENTURA_SERIES
) {
2962 io_request
->RaidContext
.raid_context_g35
.routing_flags
|=
2963 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT
);
2964 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2965 (1 << RAID_CONTEXT_NSEG_SHIFT
);
2966 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2967 (MPI2_TYPE_CUDA
<< RAID_CONTEXT_TYPE_SHIFT
);
2969 pRAID_Context
->type
= MPI2_TYPE_CUDA
;
2970 pRAID_Context
->nseg
= 0x1;
2971 pRAID_Context
->reg_lock_flags
|=
2972 (MR_RL_FLAGS_SEQ_NUM_ENABLE
|MR_RL_FLAGS_GRANT_DESTINATION_CUDA
);
2974 } else if (fusion
->fast_path_io
) {
2975 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
2976 pRAID_Context
->config_seq_num
= 0;
2977 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
2978 io_request
->DevHandle
=
2979 local_map_ptr
->raidMap
.devHndlInfo
[device_id
].curDevHdl
;
2981 /* Want to send all IO via FW path */
2982 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
2983 pRAID_Context
->config_seq_num
= 0;
2984 io_request
->DevHandle
= cpu_to_le16(0xFFFF);
2987 cmd
->request_desc
->SCSIIO
.DevHandle
= io_request
->DevHandle
;
2988 cmd
->request_desc
->SCSIIO
.MSIxIndex
=
2989 instance
->msix_vectors
?
2990 (raw_smp_processor_id() % instance
->msix_vectors
) : 0;
2994 /* system pd firmware path */
2995 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
2996 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2997 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
2998 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2999 pRAID_Context
->timeout_value
= cpu_to_le16(os_timeout_value
);
3000 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
3002 /* system pd Fast Path */
3003 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3004 timeout_limit
= (scmd
->device
->type
== TYPE_DISK
) ?
3006 pRAID_Context
->timeout_value
=
3007 cpu_to_le16((os_timeout_value
> timeout_limit
) ?
3008 timeout_limit
: os_timeout_value
);
3009 if (instance
->adapter_type
>= INVADER_SERIES
)
3010 io_request
->IoFlags
|=
3011 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
3013 cmd
->request_desc
->SCSIIO
.RequestFlags
=
3014 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
<<
3015 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
3020 * megasas_build_io_fusion - Prepares IOs to devices
3021 * @instance: Adapter soft state
3022 * @scp: SCSI command
3023 * @cmd: Command to be prepared
3025 * Invokes helper functions to prepare request frames
3026 * and sets flags appropriate for IO/Non-IO cmd
3029 megasas_build_io_fusion(struct megasas_instance
*instance
,
3030 struct scsi_cmnd
*scp
,
3031 struct megasas_cmd_fusion
*cmd
)
3035 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
= cmd
->io_request
;
3036 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
3037 mr_device_priv_data
= scp
->device
->hostdata
;
3039 /* Zero out some fields so they don't get reused */
3040 memset(io_request
->LUN
, 0x0, 8);
3041 io_request
->CDB
.EEDP32
.PrimaryReferenceTag
= 0;
3042 io_request
->CDB
.EEDP32
.PrimaryApplicationTagMask
= 0;
3043 io_request
->EEDPFlags
= 0;
3044 io_request
->Control
= 0;
3045 io_request
->EEDPBlockSize
= 0;
3046 io_request
->ChainOffset
= 0;
3047 io_request
->RaidContext
.raid_context
.raid_flags
= 0;
3048 io_request
->RaidContext
.raid_context
.type
= 0;
3049 io_request
->RaidContext
.raid_context
.nseg
= 0;
3051 memcpy(io_request
->CDB
.CDB32
, scp
->cmnd
, scp
->cmd_len
);
3053 * Just the CDB length,rest of the Flags are zero
3054 * This will be modified for FP in build_ldio_fusion
3056 io_request
->IoFlags
= cpu_to_le16(scp
->cmd_len
);
3058 switch (cmd_type
= megasas_cmd_type(scp
)) {
3059 case READ_WRITE_LDIO
:
3060 megasas_build_ldio_fusion(instance
, scp
, cmd
);
3062 case NON_READ_WRITE_LDIO
:
3063 megasas_build_ld_nonrw_fusion(instance
, scp
, cmd
);
3065 case READ_WRITE_SYSPDIO
:
3066 megasas_build_syspd_fusion(instance
, scp
, cmd
, true);
3068 case NON_READ_WRITE_SYSPDIO
:
3069 if (instance
->secure_jbod_support
||
3070 mr_device_priv_data
->is_tm_capable
)
3071 megasas_build_syspd_fusion(instance
, scp
, cmd
, false);
3073 megasas_build_syspd_fusion(instance
, scp
, cmd
, true);
3083 sge_count
= megasas_make_sgl(instance
, scp
, cmd
);
3085 if (sge_count
> instance
->max_num_sge
|| (sge_count
< 0)) {
3086 dev_err(&instance
->pdev
->dev
,
3087 "%s %d sge_count (%d) is out of range. Range is: 0-%d\n",
3088 __func__
, __LINE__
, sge_count
, instance
->max_num_sge
);
3092 if (instance
->adapter_type
== VENTURA_SERIES
) {
3093 set_num_sge(&io_request
->RaidContext
.raid_context_g35
, sge_count
);
3094 cpu_to_le16s(&io_request
->RaidContext
.raid_context_g35
.routing_flags
);
3095 cpu_to_le16s(&io_request
->RaidContext
.raid_context_g35
.nseg_type
);
3097 /* numSGE store lower 8 bit of sge_count.
3098 * numSGEExt store higher 8 bit of sge_count
3100 io_request
->RaidContext
.raid_context
.num_sge
= sge_count
;
3101 io_request
->RaidContext
.raid_context
.num_sge_ext
=
3102 (u8
)(sge_count
>> 8);
3105 io_request
->SGLFlags
= cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING
);
3107 if (scp
->sc_data_direction
== PCI_DMA_TODEVICE
)
3108 io_request
->Control
|= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE
);
3109 else if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
)
3110 io_request
->Control
|= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ
);
3112 io_request
->SGLOffset0
=
3113 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
, SGL
) / 4;
3115 io_request
->SenseBufferLowAddress
=
3116 cpu_to_le32(lower_32_bits(cmd
->sense_phys_addr
));
3117 io_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3120 scp
->SCp
.ptr
= (char *)cmd
;
3125 static union MEGASAS_REQUEST_DESCRIPTOR_UNION
*
3126 megasas_get_request_descriptor(struct megasas_instance
*instance
, u16 index
)
3129 struct fusion_context
*fusion
;
3131 fusion
= instance
->ctrl_context
;
3132 p
= fusion
->req_frames_desc
+
3133 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION
) * index
;
3135 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION
*)p
;
3139 /* megasas_prepate_secondRaid1_IO
3140 * It prepares the raid 1 second IO
3142 void megasas_prepare_secondRaid1_IO(struct megasas_instance
*instance
,
3143 struct megasas_cmd_fusion
*cmd
,
3144 struct megasas_cmd_fusion
*r1_cmd
)
3146 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
, *req_desc2
= NULL
;
3147 struct fusion_context
*fusion
;
3148 fusion
= instance
->ctrl_context
;
3149 req_desc
= cmd
->request_desc
;
3150 /* copy the io request frame as well as 8 SGEs data for r1 command*/
3151 memcpy(r1_cmd
->io_request
, cmd
->io_request
,
3152 (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST
)));
3153 memcpy(&r1_cmd
->io_request
->SGL
, &cmd
->io_request
->SGL
,
3154 (fusion
->max_sge_in_main_msg
* sizeof(union MPI2_SGE_IO_UNION
)));
3155 /*sense buffer is different for r1 command*/
3156 r1_cmd
->io_request
->SenseBufferLowAddress
=
3157 cpu_to_le32(lower_32_bits(r1_cmd
->sense_phys_addr
));
3158 r1_cmd
->scmd
= cmd
->scmd
;
3159 req_desc2
= megasas_get_request_descriptor(instance
,
3160 (r1_cmd
->index
- 1));
3161 req_desc2
->Words
= 0;
3162 r1_cmd
->request_desc
= req_desc2
;
3163 req_desc2
->SCSIIO
.SMID
= cpu_to_le16(r1_cmd
->index
);
3164 req_desc2
->SCSIIO
.RequestFlags
= req_desc
->SCSIIO
.RequestFlags
;
3165 r1_cmd
->request_desc
->SCSIIO
.DevHandle
= cmd
->r1_alt_dev_handle
;
3166 r1_cmd
->io_request
->DevHandle
= cmd
->r1_alt_dev_handle
;
3167 r1_cmd
->r1_alt_dev_handle
= cmd
->io_request
->DevHandle
;
3168 cmd
->io_request
->RaidContext
.raid_context_g35
.smid
.peer_smid
=
3169 cpu_to_le16(r1_cmd
->index
);
3170 r1_cmd
->io_request
->RaidContext
.raid_context_g35
.smid
.peer_smid
=
3171 cpu_to_le16(cmd
->index
);
3172 /*MSIxIndex of both commands request descriptors should be same*/
3173 r1_cmd
->request_desc
->SCSIIO
.MSIxIndex
=
3174 cmd
->request_desc
->SCSIIO
.MSIxIndex
;
3175 /*span arm is different for r1 cmd*/
3176 r1_cmd
->io_request
->RaidContext
.raid_context_g35
.span_arm
=
3177 cmd
->io_request
->RaidContext
.raid_context_g35
.span_arm
+ 1;
3181 * megasas_build_and_issue_cmd_fusion -Main routine for building and
3182 * issuing non IOCTL cmd
3183 * @instance: Adapter soft state
3184 * @scmd: pointer to scsi cmd from OS
3187 megasas_build_and_issue_cmd_fusion(struct megasas_instance
*instance
,
3188 struct scsi_cmnd
*scmd
)
3190 struct megasas_cmd_fusion
*cmd
, *r1_cmd
= NULL
;
3191 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
3193 struct fusion_context
*fusion
;
3195 fusion
= instance
->ctrl_context
;
3197 if ((megasas_cmd_type(scmd
) == READ_WRITE_LDIO
) &&
3198 instance
->ldio_threshold
&&
3199 (atomic_inc_return(&instance
->ldio_outstanding
) >
3200 instance
->ldio_threshold
)) {
3201 atomic_dec(&instance
->ldio_outstanding
);
3202 return SCSI_MLQUEUE_DEVICE_BUSY
;
3205 if (atomic_inc_return(&instance
->fw_outstanding
) >
3206 instance
->host
->can_queue
) {
3207 atomic_dec(&instance
->fw_outstanding
);
3208 return SCSI_MLQUEUE_HOST_BUSY
;
3211 cmd
= megasas_get_cmd_fusion(instance
, scmd
->request
->tag
);
3214 atomic_dec(&instance
->fw_outstanding
);
3215 return SCSI_MLQUEUE_HOST_BUSY
;
3220 req_desc
= megasas_get_request_descriptor(instance
, index
-1);
3222 req_desc
->Words
= 0;
3223 cmd
->request_desc
= req_desc
;
3225 if (megasas_build_io_fusion(instance
, scmd
, cmd
)) {
3226 megasas_return_cmd_fusion(instance
, cmd
);
3227 dev_err(&instance
->pdev
->dev
, "Error building command\n");
3228 cmd
->request_desc
= NULL
;
3229 atomic_dec(&instance
->fw_outstanding
);
3230 return SCSI_MLQUEUE_HOST_BUSY
;
3233 req_desc
= cmd
->request_desc
;
3234 req_desc
->SCSIIO
.SMID
= cpu_to_le16(index
);
3236 if (cmd
->io_request
->ChainOffset
!= 0 &&
3237 cmd
->io_request
->ChainOffset
!= 0xF)
3238 dev_err(&instance
->pdev
->dev
, "The chain offset value is not "
3239 "correct : %x\n", cmd
->io_request
->ChainOffset
);
3241 * if it is raid 1/10 fp write capable.
3242 * try to get second command from pool and construct it.
3243 * From FW, it has confirmed that lba values of two PDs
3244 * corresponds to single R1/10 LD are always same
3247 /* driver side count always should be less than max_fw_cmds
3248 * to get new command
3250 if (cmd
->r1_alt_dev_handle
!= MR_DEVHANDLE_INVALID
) {
3251 r1_cmd
= megasas_get_cmd_fusion(instance
,
3252 (scmd
->request
->tag
+ instance
->max_fw_cmds
));
3253 megasas_prepare_secondRaid1_IO(instance
, cmd
, r1_cmd
);
3258 * Issue the command to the FW
3261 megasas_fire_cmd_fusion(instance
, req_desc
);
3264 megasas_fire_cmd_fusion(instance
, r1_cmd
->request_desc
);
3271 * megasas_complete_r1_command -
3272 * completes R1 FP write commands which has valid peer smid
3273 * @instance: Adapter soft state
3274 * @cmd_fusion: MPT command frame
3278 megasas_complete_r1_command(struct megasas_instance
*instance
,
3279 struct megasas_cmd_fusion
*cmd
)
3281 u8
*sense
, status
, ex_status
;
3284 struct fusion_context
*fusion
;
3285 struct megasas_cmd_fusion
*r1_cmd
= NULL
;
3286 struct scsi_cmnd
*scmd_local
= NULL
;
3287 struct RAID_CONTEXT_G35
*rctx_g35
;
3289 rctx_g35
= &cmd
->io_request
->RaidContext
.raid_context_g35
;
3290 fusion
= instance
->ctrl_context
;
3291 peer_smid
= le16_to_cpu(rctx_g35
->smid
.peer_smid
);
3293 r1_cmd
= fusion
->cmd_list
[peer_smid
- 1];
3294 scmd_local
= cmd
->scmd
;
3295 status
= rctx_g35
->status
;
3296 ex_status
= rctx_g35
->ex_status
;
3297 data_length
= cmd
->io_request
->DataLength
;
3300 cmd
->cmd_completed
= true;
3302 /* Check if peer command is completed or not*/
3303 if (r1_cmd
->cmd_completed
) {
3304 rctx_g35
= &r1_cmd
->io_request
->RaidContext
.raid_context_g35
;
3305 if (rctx_g35
->status
!= MFI_STAT_OK
) {
3306 status
= rctx_g35
->status
;
3307 ex_status
= rctx_g35
->ex_status
;
3308 data_length
= r1_cmd
->io_request
->DataLength
;
3309 sense
= r1_cmd
->sense
;
3312 megasas_return_cmd_fusion(instance
, r1_cmd
);
3313 map_cmd_status(fusion
, scmd_local
, status
, ex_status
,
3314 le32_to_cpu(data_length
), sense
);
3315 if (instance
->ldio_threshold
&&
3316 megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
)
3317 atomic_dec(&instance
->ldio_outstanding
);
3318 scmd_local
->SCp
.ptr
= NULL
;
3319 megasas_return_cmd_fusion(instance
, cmd
);
3320 scsi_dma_unmap(scmd_local
);
3321 scmd_local
->scsi_done(scmd_local
);
3326 * complete_cmd_fusion - Completes command
3327 * @instance: Adapter soft state
3328 * Completes all commands that is in reply descriptor queue
3331 complete_cmd_fusion(struct megasas_instance
*instance
, u32 MSIxIndex
)
3333 union MPI2_REPLY_DESCRIPTORS_UNION
*desc
;
3334 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*reply_desc
;
3335 struct MPI2_RAID_SCSI_IO_REQUEST
*scsi_io_req
;
3336 struct fusion_context
*fusion
;
3337 struct megasas_cmd
*cmd_mfi
;
3338 struct megasas_cmd_fusion
*cmd_fusion
;
3339 u16 smid
, num_completed
;
3340 u8 reply_descript_type
, *sense
, status
, extStatus
;
3341 u32 device_id
, data_length
;
3342 union desc_value d_val
;
3343 struct LD_LOAD_BALANCE_INFO
*lbinfo
;
3344 int threshold_reply_count
= 0;
3345 struct scsi_cmnd
*scmd_local
= NULL
;
3346 struct MR_TASK_MANAGE_REQUEST
*mr_tm_req
;
3347 struct MPI2_SCSI_TASK_MANAGE_REQUEST
*mpi_tm_req
;
3349 fusion
= instance
->ctrl_context
;
3351 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
3354 desc
= fusion
->reply_frames_desc
[MSIxIndex
] +
3355 fusion
->last_reply_idx
[MSIxIndex
];
3357 reply_desc
= (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*)desc
;
3359 d_val
.word
= desc
->Words
;
3361 reply_descript_type
= reply_desc
->ReplyFlags
&
3362 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
3364 if (reply_descript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
3369 while (d_val
.u
.low
!= cpu_to_le32(UINT_MAX
) &&
3370 d_val
.u
.high
!= cpu_to_le32(UINT_MAX
)) {
3372 smid
= le16_to_cpu(reply_desc
->SMID
);
3373 cmd_fusion
= fusion
->cmd_list
[smid
- 1];
3374 scsi_io_req
= (struct MPI2_RAID_SCSI_IO_REQUEST
*)
3375 cmd_fusion
->io_request
;
3377 scmd_local
= cmd_fusion
->scmd
;
3378 status
= scsi_io_req
->RaidContext
.raid_context
.status
;
3379 extStatus
= scsi_io_req
->RaidContext
.raid_context
.ex_status
;
3380 sense
= cmd_fusion
->sense
;
3381 data_length
= scsi_io_req
->DataLength
;
3383 switch (scsi_io_req
->Function
) {
3384 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
3385 mr_tm_req
= (struct MR_TASK_MANAGE_REQUEST
*)
3386 cmd_fusion
->io_request
;
3387 mpi_tm_req
= (struct MPI2_SCSI_TASK_MANAGE_REQUEST
*)
3388 &mr_tm_req
->TmRequest
;
3389 dev_dbg(&instance
->pdev
->dev
, "TM completion:"
3390 "type: 0x%x TaskMID: 0x%x\n",
3391 mpi_tm_req
->TaskType
, mpi_tm_req
->TaskMID
);
3392 complete(&cmd_fusion
->done
);
3394 case MPI2_FUNCTION_SCSI_IO_REQUEST
: /*Fast Path IO.*/
3395 /* Update load balancing info */
3396 if (fusion
->load_balance_info
&&
3397 (cmd_fusion
->scmd
->SCp
.Status
&
3398 MEGASAS_LOAD_BALANCE_FLAG
)) {
3399 device_id
= MEGASAS_DEV_INDEX(scmd_local
);
3400 lbinfo
= &fusion
->load_balance_info
[device_id
];
3401 atomic_dec(&lbinfo
->scsi_pending_cmds
[cmd_fusion
->pd_r1_lb
]);
3402 cmd_fusion
->scmd
->SCp
.Status
&= ~MEGASAS_LOAD_BALANCE_FLAG
;
3404 //Fall thru and complete IO
3405 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
: /* LD-IO Path */
3406 atomic_dec(&instance
->fw_outstanding
);
3407 if (cmd_fusion
->r1_alt_dev_handle
== MR_DEVHANDLE_INVALID
) {
3408 map_cmd_status(fusion
, scmd_local
, status
,
3409 extStatus
, le32_to_cpu(data_length
),
3411 if (instance
->ldio_threshold
&&
3412 (megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
))
3413 atomic_dec(&instance
->ldio_outstanding
);
3414 scmd_local
->SCp
.ptr
= NULL
;
3415 megasas_return_cmd_fusion(instance
, cmd_fusion
);
3416 scsi_dma_unmap(scmd_local
);
3417 scmd_local
->scsi_done(scmd_local
);
3418 } else /* Optimal VD - R1 FP command completion. */
3419 megasas_complete_r1_command(instance
, cmd_fusion
);
3421 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST
: /*MFI command */
3422 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
3423 /* Poll mode. Dummy free.
3424 * In case of Interrupt mode, caller has reverse check.
3426 if (cmd_mfi
->flags
& DRV_DCMD_POLLED_MODE
) {
3427 cmd_mfi
->flags
&= ~DRV_DCMD_POLLED_MODE
;
3428 megasas_return_cmd(instance
, cmd_mfi
);
3430 megasas_complete_cmd(instance
, cmd_mfi
, DID_OK
);
3434 fusion
->last_reply_idx
[MSIxIndex
]++;
3435 if (fusion
->last_reply_idx
[MSIxIndex
] >=
3436 fusion
->reply_q_depth
)
3437 fusion
->last_reply_idx
[MSIxIndex
] = 0;
3439 desc
->Words
= cpu_to_le64(ULLONG_MAX
);
3441 threshold_reply_count
++;
3443 /* Get the next reply descriptor */
3444 if (!fusion
->last_reply_idx
[MSIxIndex
])
3445 desc
= fusion
->reply_frames_desc
[MSIxIndex
];
3450 (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*)desc
;
3452 d_val
.word
= desc
->Words
;
3454 reply_descript_type
= reply_desc
->ReplyFlags
&
3455 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
3457 if (reply_descript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
3460 * Write to reply post host index register after completing threshold
3461 * number of reply counts and still there are more replies in reply queue
3462 * pending to be completed
3464 if (threshold_reply_count
>= THRESHOLD_REPLY_COUNT
) {
3465 if (instance
->msix_combined
)
3466 writel(((MSIxIndex
& 0x7) << 24) |
3467 fusion
->last_reply_idx
[MSIxIndex
],
3468 instance
->reply_post_host_index_addr
[MSIxIndex
/8]);
3470 writel((MSIxIndex
<< 24) |
3471 fusion
->last_reply_idx
[MSIxIndex
],
3472 instance
->reply_post_host_index_addr
[0]);
3473 threshold_reply_count
= 0;
3481 if (instance
->msix_combined
)
3482 writel(((MSIxIndex
& 0x7) << 24) |
3483 fusion
->last_reply_idx
[MSIxIndex
],
3484 instance
->reply_post_host_index_addr
[MSIxIndex
/8]);
3486 writel((MSIxIndex
<< 24) |
3487 fusion
->last_reply_idx
[MSIxIndex
],
3488 instance
->reply_post_host_index_addr
[0]);
3489 megasas_check_and_restore_queue_depth(instance
);
3494 * megasas_sync_irqs - Synchronizes all IRQs owned by adapter
3495 * @instance: Adapter soft state
3497 void megasas_sync_irqs(unsigned long instance_addr
)
3500 struct megasas_instance
*instance
=
3501 (struct megasas_instance
*)instance_addr
;
3503 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
3505 for (i
= 0; i
< count
; i
++)
3506 synchronize_irq(pci_irq_vector(instance
->pdev
, i
));
3510 * megasas_complete_cmd_dpc_fusion - Completes command
3511 * @instance: Adapter soft state
3513 * Tasklet to complete cmds
3516 megasas_complete_cmd_dpc_fusion(unsigned long instance_addr
)
3518 struct megasas_instance
*instance
=
3519 (struct megasas_instance
*)instance_addr
;
3520 unsigned long flags
;
3521 u32 count
, MSIxIndex
;
3523 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
3525 /* If we have already declared adapter dead, donot complete cmds */
3526 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3527 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
3528 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3531 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3533 for (MSIxIndex
= 0 ; MSIxIndex
< count
; MSIxIndex
++)
3534 complete_cmd_fusion(instance
, MSIxIndex
);
3538 * megasas_isr_fusion - isr entry point
3540 irqreturn_t
megasas_isr_fusion(int irq
, void *devp
)
3542 struct megasas_irq_context
*irq_context
= devp
;
3543 struct megasas_instance
*instance
= irq_context
->instance
;
3544 u32 mfiStatus
, fw_state
, dma_state
;
3546 if (instance
->mask_interrupts
)
3549 if (!instance
->msix_vectors
) {
3550 mfiStatus
= instance
->instancet
->clear_intr(instance
->reg_set
);
3555 /* If we are resetting, bail */
3556 if (test_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
)) {
3557 instance
->instancet
->clear_intr(instance
->reg_set
);
3561 if (!complete_cmd_fusion(instance
, irq_context
->MSIxIndex
)) {
3562 instance
->instancet
->clear_intr(instance
->reg_set
);
3563 /* If we didn't complete any commands, check for FW fault */
3564 fw_state
= instance
->instancet
->read_fw_status_reg(
3565 instance
->reg_set
) & MFI_STATE_MASK
;
3566 dma_state
= instance
->instancet
->read_fw_status_reg
3567 (instance
->reg_set
) & MFI_STATE_DMADONE
;
3568 if (instance
->crash_dump_drv_support
&&
3569 instance
->crash_dump_app_support
) {
3570 /* Start collecting crash, if DMA bit is done */
3571 if ((fw_state
== MFI_STATE_FAULT
) && dma_state
)
3572 schedule_work(&instance
->crash_init
);
3573 else if (fw_state
== MFI_STATE_FAULT
) {
3574 if (instance
->unload
== 0)
3575 schedule_work(&instance
->work_init
);
3577 } else if (fw_state
== MFI_STATE_FAULT
) {
3578 dev_warn(&instance
->pdev
->dev
, "Iop2SysDoorbellInt"
3579 "for scsi%d\n", instance
->host
->host_no
);
3580 if (instance
->unload
== 0)
3581 schedule_work(&instance
->work_init
);
3589 * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
3590 * @instance: Adapter soft state
3591 * mfi_cmd: megasas_cmd pointer
3595 build_mpt_mfi_pass_thru(struct megasas_instance
*instance
,
3596 struct megasas_cmd
*mfi_cmd
)
3598 struct MPI25_IEEE_SGE_CHAIN64
*mpi25_ieee_chain
;
3599 struct MPI2_RAID_SCSI_IO_REQUEST
*io_req
;
3600 struct megasas_cmd_fusion
*cmd
;
3601 struct fusion_context
*fusion
;
3602 struct megasas_header
*frame_hdr
= &mfi_cmd
->frame
->hdr
;
3604 fusion
= instance
->ctrl_context
;
3606 cmd
= megasas_get_cmd_fusion(instance
,
3607 instance
->max_scsi_cmds
+ mfi_cmd
->index
);
3609 /* Save the smid. To be used for returning the cmd */
3610 mfi_cmd
->context
.smid
= cmd
->index
;
3613 * For cmds where the flag is set, store the flag and check
3614 * on completion. For cmds with this flag, don't call
3615 * megasas_complete_cmd
3618 if (frame_hdr
->flags
& cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
))
3619 mfi_cmd
->flags
|= DRV_DCMD_POLLED_MODE
;
3621 io_req
= cmd
->io_request
;
3623 if (instance
->adapter_type
>= INVADER_SERIES
) {
3624 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr_end
=
3625 (struct MPI25_IEEE_SGE_CHAIN64
*)&io_req
->SGL
;
3626 sgl_ptr_end
+= fusion
->max_sge_in_main_msg
- 1;
3627 sgl_ptr_end
->Flags
= 0;
3631 (struct MPI25_IEEE_SGE_CHAIN64
*)&io_req
->SGL
.IeeeChain
;
3633 io_req
->Function
= MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST
;
3634 io_req
->SGLOffset0
= offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
,
3636 io_req
->ChainOffset
= fusion
->chain_offset_mfi_pthru
;
3638 mpi25_ieee_chain
->Address
= cpu_to_le64(mfi_cmd
->frame_phys_addr
);
3640 mpi25_ieee_chain
->Flags
= IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
3641 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR
;
3643 mpi25_ieee_chain
->Length
= cpu_to_le32(instance
->mfi_frame_size
);
3647 * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
3648 * @instance: Adapter soft state
3649 * @cmd: mfi cmd to build
3652 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*
3653 build_mpt_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
3655 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
= NULL
;
3658 build_mpt_mfi_pass_thru(instance
, cmd
);
3659 index
= cmd
->context
.smid
;
3661 req_desc
= megasas_get_request_descriptor(instance
, index
- 1);
3663 req_desc
->Words
= 0;
3664 req_desc
->SCSIIO
.RequestFlags
= (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
3665 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
3667 req_desc
->SCSIIO
.SMID
= cpu_to_le16(index
);
3673 * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
3674 * @instance: Adapter soft state
3675 * @cmd: mfi cmd pointer
3679 megasas_issue_dcmd_fusion(struct megasas_instance
*instance
,
3680 struct megasas_cmd
*cmd
)
3682 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
3684 req_desc
= build_mpt_cmd(instance
, cmd
);
3686 megasas_fire_cmd_fusion(instance
, req_desc
);
3691 * megasas_release_fusion - Reverses the FW initialization
3692 * @instance: Adapter soft state
3695 megasas_release_fusion(struct megasas_instance
*instance
)
3697 megasas_free_ioc_init_cmd(instance
);
3698 megasas_free_cmds(instance
);
3699 megasas_free_cmds_fusion(instance
);
3701 iounmap(instance
->reg_set
);
3703 pci_release_selected_regions(instance
->pdev
, 1<<instance
->bar
);
3707 * megasas_read_fw_status_reg_fusion - returns the current FW status value
3708 * @regs: MFI register set
3711 megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem
*regs
)
3713 return readl(&(regs
)->outbound_scratch_pad
);
3717 * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3718 * @instance: Controller's soft instance
3719 * return: Number of allocated host crash buffers
3722 megasas_alloc_host_crash_buffer(struct megasas_instance
*instance
)
3726 for (i
= 0; i
< MAX_CRASH_DUMP_SIZE
; i
++) {
3727 instance
->crash_buf
[i
] = vzalloc(CRASH_DMA_BUF_SIZE
);
3728 if (!instance
->crash_buf
[i
]) {
3729 dev_info(&instance
->pdev
->dev
, "Firmware crash dump "
3730 "memory allocation failed at index %d\n", i
);
3734 instance
->drv_buf_alloc
= i
;
3738 * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3739 * @instance: Controller's soft instance
3742 megasas_free_host_crash_buffer(struct megasas_instance
*instance
)
3745 for (i
= 0; i
< instance
->drv_buf_alloc
; i
++) {
3746 if (instance
->crash_buf
[i
])
3747 vfree(instance
->crash_buf
[i
]);
3749 instance
->drv_buf_index
= 0;
3750 instance
->drv_buf_alloc
= 0;
3751 instance
->fw_crash_state
= UNAVAILABLE
;
3752 instance
->fw_crash_buffer_size
= 0;
3756 * megasas_adp_reset_fusion - For controller reset
3757 * @regs: MFI register set
3760 megasas_adp_reset_fusion(struct megasas_instance
*instance
,
3761 struct megasas_register_set __iomem
*regs
)
3763 u32 host_diag
, abs_state
, retry
;
3765 /* Now try to reset the chip */
3766 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3767 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3768 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3769 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3770 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3771 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3772 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3774 /* Check that the diag write enable (DRWE) bit is on */
3775 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3777 while (!(host_diag
& HOST_DIAG_WRITE_ENABLE
)) {
3779 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3780 if (retry
++ == 100) {
3781 dev_warn(&instance
->pdev
->dev
,
3782 "Host diag unlock failed from %s %d\n",
3783 __func__
, __LINE__
);
3787 if (!(host_diag
& HOST_DIAG_WRITE_ENABLE
))
3790 /* Send chip reset command */
3791 writel(host_diag
| HOST_DIAG_RESET_ADAPTER
,
3792 &instance
->reg_set
->fusion_host_diag
);
3795 /* Make sure reset adapter bit is cleared */
3796 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3798 while (host_diag
& HOST_DIAG_RESET_ADAPTER
) {
3800 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3801 if (retry
++ == 1000) {
3802 dev_warn(&instance
->pdev
->dev
,
3803 "Diag reset adapter never cleared %s %d\n",
3804 __func__
, __LINE__
);
3808 if (host_diag
& HOST_DIAG_RESET_ADAPTER
)
3811 abs_state
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
)
3815 while ((abs_state
<= MFI_STATE_FW_INIT
) && (retry
++ < 1000)) {
3817 abs_state
= instance
->instancet
->
3818 read_fw_status_reg(instance
->reg_set
) & MFI_STATE_MASK
;
3820 if (abs_state
<= MFI_STATE_FW_INIT
) {
3821 dev_warn(&instance
->pdev
->dev
,
3822 "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n",
3823 abs_state
, __func__
, __LINE__
);
3831 * megasas_check_reset_fusion - For controller reset check
3832 * @regs: MFI register set
3835 megasas_check_reset_fusion(struct megasas_instance
*instance
,
3836 struct megasas_register_set __iomem
*regs
)
3841 /* This function waits for outstanding commands on fusion to complete */
3842 int megasas_wait_for_outstanding_fusion(struct megasas_instance
*instance
,
3843 int reason
, int *convert
)
3845 int i
, outstanding
, retval
= 0, hb_seconds_missed
= 0;
3848 for (i
= 0; i
< resetwaittime
; i
++) {
3849 /* Check if firmware is in fault state */
3850 fw_state
= instance
->instancet
->read_fw_status_reg(
3851 instance
->reg_set
) & MFI_STATE_MASK
;
3852 if (fw_state
== MFI_STATE_FAULT
) {
3853 dev_warn(&instance
->pdev
->dev
, "Found FW in FAULT state,"
3854 " will reset adapter scsi%d.\n",
3855 instance
->host
->host_no
);
3856 megasas_complete_cmd_dpc_fusion((unsigned long)instance
);
3857 if (instance
->requestorId
&& reason
) {
3858 dev_warn(&instance
->pdev
->dev
, "SR-IOV Found FW in FAULT"
3859 " state while polling during"
3860 " I/O timeout handling for %d\n",
3861 instance
->host
->host_no
);
3869 if (reason
== MFI_IO_TIMEOUT_OCR
) {
3870 dev_info(&instance
->pdev
->dev
,
3871 "MFI IO is timed out, initiating OCR\n");
3872 megasas_complete_cmd_dpc_fusion((unsigned long)instance
);
3877 /* If SR-IOV VF mode & heartbeat timeout, don't wait */
3878 if (instance
->requestorId
&& !reason
) {
3883 /* If SR-IOV VF mode & I/O timeout, check for HB timeout */
3884 if (instance
->requestorId
&& (reason
== SCSIIO_TIMEOUT_OCR
)) {
3885 if (instance
->hb_host_mem
->HB
.fwCounter
!=
3886 instance
->hb_host_mem
->HB
.driverCounter
) {
3887 instance
->hb_host_mem
->HB
.driverCounter
=
3888 instance
->hb_host_mem
->HB
.fwCounter
;
3889 hb_seconds_missed
= 0;
3891 hb_seconds_missed
++;
3892 if (hb_seconds_missed
==
3893 (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
/HZ
)) {
3894 dev_warn(&instance
->pdev
->dev
, "SR-IOV:"
3895 " Heartbeat never completed "
3896 " while polling during I/O "
3897 " timeout handling for "
3899 instance
->host
->host_no
);
3907 megasas_complete_cmd_dpc_fusion((unsigned long)instance
);
3908 outstanding
= atomic_read(&instance
->fw_outstanding
);
3912 if (!(i
% MEGASAS_RESET_NOTICE_INTERVAL
)) {
3913 dev_notice(&instance
->pdev
->dev
, "[%2d]waiting for %d "
3914 "commands to complete for scsi%d\n", i
,
3915 outstanding
, instance
->host
->host_no
);
3920 if (atomic_read(&instance
->fw_outstanding
)) {
3921 dev_err(&instance
->pdev
->dev
, "pending commands remain after waiting, "
3922 "will reset adapter scsi%d.\n",
3923 instance
->host
->host_no
);
3931 void megasas_reset_reply_desc(struct megasas_instance
*instance
)
3934 struct fusion_context
*fusion
;
3935 union MPI2_REPLY_DESCRIPTORS_UNION
*reply_desc
;
3937 fusion
= instance
->ctrl_context
;
3938 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
3939 for (i
= 0 ; i
< count
; i
++) {
3940 fusion
->last_reply_idx
[i
] = 0;
3941 reply_desc
= fusion
->reply_frames_desc
[i
];
3942 for (j
= 0 ; j
< fusion
->reply_q_depth
; j
++, reply_desc
++)
3943 reply_desc
->Words
= cpu_to_le64(ULLONG_MAX
);
3948 * megasas_refire_mgmt_cmd : Re-fire management commands
3949 * @instance: Controller's soft instance
3951 void megasas_refire_mgmt_cmd(struct megasas_instance
*instance
)
3954 struct megasas_cmd_fusion
*cmd_fusion
;
3955 struct fusion_context
*fusion
;
3956 struct megasas_cmd
*cmd_mfi
;
3957 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
3959 bool refire_cmd
= 0;
3963 fusion
= instance
->ctrl_context
;
3965 /* Re-fire management commands.
3966 * Do not traverse complet MPT frame pool. Start from max_scsi_cmds.
3968 for (j
= instance
->max_scsi_cmds
; j
< instance
->max_fw_cmds
; j
++) {
3969 cmd_fusion
= fusion
->cmd_list
[j
];
3970 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
3971 smid
= le16_to_cpu(cmd_mfi
->context
.smid
);
3972 result
= REFIRE_CMD
;
3977 req_desc
= megasas_get_request_descriptor(instance
, smid
- 1);
3979 switch (cmd_mfi
->frame
->hdr
.cmd
) {
3981 opcode
= le32_to_cpu(cmd_mfi
->frame
->dcmd
.opcode
);
3982 /* Do not refire shutdown command */
3983 if (opcode
== MR_DCMD_CTRL_SHUTDOWN
) {
3984 cmd_mfi
->frame
->dcmd
.cmd_status
= MFI_STAT_OK
;
3985 result
= COMPLETE_CMD
;
3989 refire_cmd
= ((opcode
!= MR_DCMD_LD_MAP_GET_INFO
)) &&
3990 (opcode
!= MR_DCMD_SYSTEM_PD_MAP_GET_INFO
) &&
3991 !(cmd_mfi
->flags
& DRV_DCMD_SKIP_REFIRE
);
3994 result
= RETURN_CMD
;
3998 if (!instance
->support_nvme_passthru
) {
3999 cmd_mfi
->frame
->hdr
.cmd_status
= MFI_STAT_INVALID_CMD
;
4000 result
= COMPLETE_CMD
;
4010 megasas_fire_cmd_fusion(instance
, req_desc
);
4013 megasas_return_cmd(instance
, cmd_mfi
);
4016 megasas_complete_cmd(instance
, cmd_mfi
, DID_OK
);
4023 * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device
4024 * @instance: per adapter struct
4025 * @channel: the channel assigned by the OS
4026 * @id: the id assigned by the OS
4028 * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED
4031 static int megasas_track_scsiio(struct megasas_instance
*instance
,
4032 int id
, int channel
)
4035 struct megasas_cmd_fusion
*cmd_fusion
;
4036 struct fusion_context
*fusion
;
4037 fusion
= instance
->ctrl_context
;
4039 for (i
= 0 ; i
< instance
->max_scsi_cmds
; i
++) {
4040 cmd_fusion
= fusion
->cmd_list
[i
];
4041 if (cmd_fusion
->scmd
&&
4042 (cmd_fusion
->scmd
->device
->id
== id
&&
4043 cmd_fusion
->scmd
->device
->channel
== channel
)) {
4044 dev_info(&instance
->pdev
->dev
,
4045 "SCSI commands pending to target"
4046 "channel %d id %d \tSMID: 0x%x\n",
4047 channel
, id
, cmd_fusion
->index
);
4048 scsi_print_command(cmd_fusion
->scmd
);
4054 return found
? FAILED
: SUCCESS
;
4058 * megasas_tm_response_code - translation of device response code
4059 * @ioc: per adapter object
4060 * @mpi_reply: MPI reply returned by firmware
4065 megasas_tm_response_code(struct megasas_instance
*instance
,
4066 struct MPI2_SCSI_TASK_MANAGE_REPLY
*mpi_reply
)
4070 switch (mpi_reply
->ResponseCode
) {
4071 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
4072 desc
= "task management request completed";
4074 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
4075 desc
= "invalid frame";
4077 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
4078 desc
= "task management request not supported";
4080 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
4081 desc
= "task management request failed";
4083 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
4084 desc
= "task management request succeeded";
4086 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
4087 desc
= "invalid lun";
4090 desc
= "overlapped tag attempted";
4092 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
4093 desc
= "task queued, however not sent to target";
4099 dev_dbg(&instance
->pdev
->dev
, "response_code(%01x): %s\n",
4100 mpi_reply
->ResponseCode
, desc
);
4101 dev_dbg(&instance
->pdev
->dev
,
4102 "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo"
4103 " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n",
4104 mpi_reply
->TerminationCount
, mpi_reply
->DevHandle
,
4105 mpi_reply
->Function
, mpi_reply
->TaskType
,
4106 mpi_reply
->IOCStatus
, mpi_reply
->IOCLogInfo
);
4110 * megasas_issue_tm - main routine for sending tm requests
4111 * @instance: per adapter struct
4112 * @device_handle: device handle
4113 * @channel: the channel assigned by the OS
4114 * @id: the id assigned by the OS
4115 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c)
4116 * @smid_task: smid assigned to the task
4117 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
4120 * MegaRaid use MPT interface for Task Magement request.
4121 * A generic API for sending task management requests to firmware.
4123 * Return SUCCESS or FAILED.
4126 megasas_issue_tm(struct megasas_instance
*instance
, u16 device_handle
,
4127 uint channel
, uint id
, u16 smid_task
, u8 type
)
4129 struct MR_TASK_MANAGE_REQUEST
*mr_request
;
4130 struct MPI2_SCSI_TASK_MANAGE_REQUEST
*mpi_request
;
4131 unsigned long timeleft
;
4132 struct megasas_cmd_fusion
*cmd_fusion
;
4133 struct megasas_cmd
*cmd_mfi
;
4134 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
4135 struct fusion_context
*fusion
= NULL
;
4136 struct megasas_cmd_fusion
*scsi_lookup
;
4138 struct MPI2_SCSI_TASK_MANAGE_REPLY
*mpi_reply
;
4140 fusion
= instance
->ctrl_context
;
4142 cmd_mfi
= megasas_get_cmd(instance
);
4145 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
4146 __func__
, __LINE__
);
4150 cmd_fusion
= megasas_get_cmd_fusion(instance
,
4151 instance
->max_scsi_cmds
+ cmd_mfi
->index
);
4153 /* Save the smid. To be used for returning the cmd */
4154 cmd_mfi
->context
.smid
= cmd_fusion
->index
;
4156 req_desc
= megasas_get_request_descriptor(instance
,
4157 (cmd_fusion
->index
- 1));
4159 cmd_fusion
->request_desc
= req_desc
;
4160 req_desc
->Words
= 0;
4162 mr_request
= (struct MR_TASK_MANAGE_REQUEST
*) cmd_fusion
->io_request
;
4163 memset(mr_request
, 0, sizeof(struct MR_TASK_MANAGE_REQUEST
));
4164 mpi_request
= (struct MPI2_SCSI_TASK_MANAGE_REQUEST
*) &mr_request
->TmRequest
;
4165 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
4166 mpi_request
->DevHandle
= cpu_to_le16(device_handle
);
4167 mpi_request
->TaskType
= type
;
4168 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
4169 mpi_request
->LUN
[1] = 0;
4172 req_desc
= cmd_fusion
->request_desc
;
4173 req_desc
->HighPriority
.SMID
= cpu_to_le16(cmd_fusion
->index
);
4174 req_desc
->HighPriority
.RequestFlags
=
4175 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
<<
4176 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
4177 req_desc
->HighPriority
.MSIxIndex
= 0;
4178 req_desc
->HighPriority
.LMID
= 0;
4179 req_desc
->HighPriority
.Reserved1
= 0;
4181 if (channel
< MEGASAS_MAX_PD_CHANNELS
)
4182 mr_request
->tmReqFlags
.isTMForPD
= 1;
4184 mr_request
->tmReqFlags
.isTMForLD
= 1;
4186 init_completion(&cmd_fusion
->done
);
4187 megasas_fire_cmd_fusion(instance
, req_desc
);
4189 timeleft
= wait_for_completion_timeout(&cmd_fusion
->done
, 50 * HZ
);
4192 dev_err(&instance
->pdev
->dev
,
4193 "task mgmt type 0x%x timed out\n", type
);
4194 cmd_mfi
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4195 mutex_unlock(&instance
->reset_mutex
);
4196 rc
= megasas_reset_fusion(instance
->host
, MFI_IO_TIMEOUT_OCR
);
4197 mutex_lock(&instance
->reset_mutex
);
4201 mpi_reply
= (struct MPI2_SCSI_TASK_MANAGE_REPLY
*) &mr_request
->TMReply
;
4202 megasas_tm_response_code(instance
, mpi_reply
);
4204 megasas_return_cmd(instance
, cmd_mfi
);
4207 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
4208 scsi_lookup
= fusion
->cmd_list
[smid_task
- 1];
4210 if (scsi_lookup
->scmd
== NULL
)
4213 instance
->instancet
->disable_intr(instance
);
4214 megasas_sync_irqs((unsigned long)instance
);
4215 instance
->instancet
->enable_intr(instance
);
4216 if (scsi_lookup
->scmd
== NULL
)
4222 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
4223 if ((channel
== 0xFFFFFFFF) && (id
== 0xFFFFFFFF))
4225 instance
->instancet
->disable_intr(instance
);
4226 megasas_sync_irqs((unsigned long)instance
);
4227 rc
= megasas_track_scsiio(instance
, id
, channel
);
4228 instance
->instancet
->enable_intr(instance
);
4231 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
4232 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
4244 * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI
4245 * @instance: per adapter struct
4247 * Return Non Zero index, if SMID found in outstanding commands
4249 static u16
megasas_fusion_smid_lookup(struct scsi_cmnd
*scmd
)
4252 struct megasas_instance
*instance
;
4253 struct megasas_cmd_fusion
*cmd_fusion
;
4254 struct fusion_context
*fusion
;
4256 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
4258 fusion
= instance
->ctrl_context
;
4260 for (i
= 0; i
< instance
->max_scsi_cmds
; i
++) {
4261 cmd_fusion
= fusion
->cmd_list
[i
];
4262 if (cmd_fusion
->scmd
&& (cmd_fusion
->scmd
== scmd
)) {
4263 scmd_printk(KERN_NOTICE
, scmd
, "Abort request is for"
4264 " SMID: %d\n", cmd_fusion
->index
);
4265 ret
= cmd_fusion
->index
;
4274 * megasas_get_tm_devhandle - Get devhandle for TM request
4275 * @sdev- OS provided scsi device
4277 * Returns- devhandle/targetID of SCSI device
4279 static u16
megasas_get_tm_devhandle(struct scsi_device
*sdev
)
4283 struct megasas_instance
*instance
;
4284 struct fusion_context
*fusion
;
4285 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
4286 u16 devhandle
= (u16
)ULONG_MAX
;
4288 instance
= (struct megasas_instance
*)sdev
->host
->hostdata
;
4289 fusion
= instance
->ctrl_context
;
4291 if (!MEGASAS_IS_LOGICAL(sdev
)) {
4292 if (instance
->use_seqnum_jbod_fp
) {
4293 pd_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
)
4295 pd_sync
= (void *)fusion
->pd_seq_sync
4296 [(instance
->pd_seq_map_id
- 1) & 1];
4297 devhandle
= pd_sync
->seq
[pd_index
].devHandle
;
4299 sdev_printk(KERN_ERR
, sdev
, "Firmware expose tmCapable"
4300 " without JBOD MAP support from %s %d\n", __func__
, __LINE__
);
4302 device_id
= ((sdev
->channel
% 2) * MEGASAS_MAX_DEV_PER_CHANNEL
)
4304 devhandle
= device_id
;
4311 * megasas_task_abort_fusion : SCSI task abort function for fusion adapters
4312 * @scmd : pointer to scsi command object
4314 * Return SUCCESS, if command aborted else FAILED
4317 int megasas_task_abort_fusion(struct scsi_cmnd
*scmd
)
4319 struct megasas_instance
*instance
;
4320 u16 smid
, devhandle
;
4321 struct fusion_context
*fusion
;
4323 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
4324 mr_device_priv_data
= scmd
->device
->hostdata
;
4327 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
4328 fusion
= instance
->ctrl_context
;
4330 scmd_printk(KERN_INFO
, scmd
, "task abort called for scmd(%p)\n", scmd
);
4331 scsi_print_command(scmd
);
4333 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
4334 dev_err(&instance
->pdev
->dev
, "Controller is not OPERATIONAL,"
4335 "SCSI host:%d\n", instance
->host
->host_no
);
4340 if (!mr_device_priv_data
) {
4341 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
4342 "scmd(%p)\n", scmd
);
4343 scmd
->result
= DID_NO_CONNECT
<< 16;
4349 if (!mr_device_priv_data
->is_tm_capable
) {
4354 mutex_lock(&instance
->reset_mutex
);
4356 smid
= megasas_fusion_smid_lookup(scmd
);
4360 scmd_printk(KERN_NOTICE
, scmd
, "Command for which abort is"
4361 " issued is not found in oustanding commands\n");
4362 mutex_unlock(&instance
->reset_mutex
);
4366 devhandle
= megasas_get_tm_devhandle(scmd
->device
);
4368 if (devhandle
== (u16
)ULONG_MAX
) {
4370 sdev_printk(KERN_INFO
, scmd
->device
,
4371 "task abort issued for invalid devhandle\n");
4372 mutex_unlock(&instance
->reset_mutex
);
4375 sdev_printk(KERN_INFO
, scmd
->device
,
4376 "attempting task abort! scmd(%p) tm_dev_handle 0x%x\n",
4379 mr_device_priv_data
->tm_busy
= 1;
4380 ret
= megasas_issue_tm(instance
, devhandle
,
4381 scmd
->device
->channel
, scmd
->device
->id
, smid
,
4382 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
);
4383 mr_device_priv_data
->tm_busy
= 0;
4385 mutex_unlock(&instance
->reset_mutex
);
4387 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
4388 ((ret
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
4394 * megasas_reset_target_fusion : target reset function for fusion adapters
4395 * scmd: SCSI command pointer
4397 * Returns SUCCESS if all commands associated with target aborted else FAILED
4400 int megasas_reset_target_fusion(struct scsi_cmnd
*scmd
)
4403 struct megasas_instance
*instance
;
4406 struct fusion_context
*fusion
;
4407 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
4408 mr_device_priv_data
= scmd
->device
->hostdata
;
4410 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
4411 fusion
= instance
->ctrl_context
;
4413 sdev_printk(KERN_INFO
, scmd
->device
,
4414 "target reset called for scmd(%p)\n", scmd
);
4416 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
4417 dev_err(&instance
->pdev
->dev
, "Controller is not OPERATIONAL,"
4418 "SCSI host:%d\n", instance
->host
->host_no
);
4423 if (!mr_device_priv_data
) {
4424 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
4425 "scmd(%p)\n", scmd
);
4426 scmd
->result
= DID_NO_CONNECT
<< 16;
4432 if (!mr_device_priv_data
->is_tm_capable
) {
4437 mutex_lock(&instance
->reset_mutex
);
4438 devhandle
= megasas_get_tm_devhandle(scmd
->device
);
4440 if (devhandle
== (u16
)ULONG_MAX
) {
4442 sdev_printk(KERN_INFO
, scmd
->device
,
4443 "target reset issued for invalid devhandle\n");
4444 mutex_unlock(&instance
->reset_mutex
);
4448 sdev_printk(KERN_INFO
, scmd
->device
,
4449 "attempting target reset! scmd(%p) tm_dev_handle 0x%x\n",
4451 mr_device_priv_data
->tm_busy
= 1;
4452 ret
= megasas_issue_tm(instance
, devhandle
,
4453 scmd
->device
->channel
, scmd
->device
->id
, 0,
4454 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
);
4455 mr_device_priv_data
->tm_busy
= 0;
4456 mutex_unlock(&instance
->reset_mutex
);
4458 scmd_printk(KERN_NOTICE
, scmd
, "megasas: target reset %s!!\n",
4459 (ret
== SUCCESS
) ? "SUCCESS" : "FAILED");
4464 /*SRIOV get other instance in cluster if any*/
4465 struct megasas_instance
*megasas_get_peer_instance(struct megasas_instance
*instance
)
4469 for (i
= 0; i
< MAX_MGMT_ADAPTERS
; i
++) {
4470 if (megasas_mgmt_info
.instance
[i
] &&
4471 (megasas_mgmt_info
.instance
[i
] != instance
) &&
4472 megasas_mgmt_info
.instance
[i
]->requestorId
&&
4473 megasas_mgmt_info
.instance
[i
]->peerIsPresent
&&
4474 (memcmp((megasas_mgmt_info
.instance
[i
]->clusterId
),
4475 instance
->clusterId
, MEGASAS_CLUSTER_ID_SIZE
) == 0))
4476 return megasas_mgmt_info
.instance
[i
];
4481 /* Check for a second path that is currently UP */
4482 int megasas_check_mpio_paths(struct megasas_instance
*instance
,
4483 struct scsi_cmnd
*scmd
)
4485 struct megasas_instance
*peer_instance
= NULL
;
4486 int retval
= (DID_REQUEUE
<< 16);
4488 if (instance
->peerIsPresent
) {
4489 peer_instance
= megasas_get_peer_instance(instance
);
4490 if ((peer_instance
) &&
4491 (atomic_read(&peer_instance
->adprecovery
) ==
4492 MEGASAS_HBA_OPERATIONAL
))
4493 retval
= (DID_NO_CONNECT
<< 16);
4498 /* Core fusion reset function */
4499 int megasas_reset_fusion(struct Scsi_Host
*shost
, int reason
)
4501 int retval
= SUCCESS
, i
, j
, convert
= 0;
4502 struct megasas_instance
*instance
;
4503 struct megasas_cmd_fusion
*cmd_fusion
, *r1_cmd
;
4504 struct fusion_context
*fusion
;
4505 u32 abs_state
, status_reg
, reset_adapter
;
4506 u32 io_timeout_in_crash_mode
= 0;
4507 struct scsi_cmnd
*scmd_local
= NULL
;
4508 struct scsi_device
*sdev
;
4510 instance
= (struct megasas_instance
*)shost
->hostdata
;
4511 fusion
= instance
->ctrl_context
;
4513 mutex_lock(&instance
->reset_mutex
);
4515 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
4516 dev_warn(&instance
->pdev
->dev
, "Hardware critical error, "
4517 "returning FAILED for scsi%d.\n",
4518 instance
->host
->host_no
);
4519 mutex_unlock(&instance
->reset_mutex
);
4522 status_reg
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
);
4523 abs_state
= status_reg
& MFI_STATE_MASK
;
4525 /* IO timeout detected, forcibly put FW in FAULT state */
4526 if (abs_state
!= MFI_STATE_FAULT
&& instance
->crash_dump_buf
&&
4527 instance
->crash_dump_app_support
&& reason
) {
4528 dev_info(&instance
->pdev
->dev
, "IO/DCMD timeout is detected, "
4529 "forcibly FAULT Firmware\n");
4530 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
4531 status_reg
= readl(&instance
->reg_set
->doorbell
);
4532 writel(status_reg
| MFI_STATE_FORCE_OCR
,
4533 &instance
->reg_set
->doorbell
);
4534 readl(&instance
->reg_set
->doorbell
);
4535 mutex_unlock(&instance
->reset_mutex
);
4538 io_timeout_in_crash_mode
++;
4539 dev_dbg(&instance
->pdev
->dev
, "waiting for [%d] "
4540 "seconds for crash dump collection and OCR "
4541 "to be done\n", (io_timeout_in_crash_mode
* 3));
4542 } while ((atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) &&
4543 (io_timeout_in_crash_mode
< 80));
4545 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HBA_OPERATIONAL
) {
4546 dev_info(&instance
->pdev
->dev
, "OCR done for IO "
4550 dev_info(&instance
->pdev
->dev
, "Controller is not "
4551 "operational after 240 seconds wait for IO "
4552 "timeout case in FW crash dump mode\n do "
4553 "OCR/kill adapter\n");
4554 retval
= megasas_reset_fusion(shost
, 0);
4559 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
4560 del_timer_sync(&instance
->sriov_heartbeat_timer
);
4561 set_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
4562 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_POLLING
);
4563 instance
->instancet
->disable_intr(instance
);
4564 megasas_sync_irqs((unsigned long)instance
);
4566 /* First try waiting for commands to complete */
4567 if (megasas_wait_for_outstanding_fusion(instance
, reason
,
4569 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
4570 dev_warn(&instance
->pdev
->dev
, "resetting fusion "
4571 "adapter scsi%d.\n", instance
->host
->host_no
);
4575 if (megasas_dbg_lvl
& OCR_LOGS
)
4576 dev_info(&instance
->pdev
->dev
, "\nPending SCSI commands:\n");
4578 /* Now return commands back to the OS */
4579 for (i
= 0 ; i
< instance
->max_scsi_cmds
; i
++) {
4580 cmd_fusion
= fusion
->cmd_list
[i
];
4581 /*check for extra commands issued by driver*/
4582 if (instance
->adapter_type
== VENTURA_SERIES
) {
4583 r1_cmd
= fusion
->cmd_list
[i
+ instance
->max_fw_cmds
];
4584 megasas_return_cmd_fusion(instance
, r1_cmd
);
4586 scmd_local
= cmd_fusion
->scmd
;
4587 if (cmd_fusion
->scmd
) {
4588 if (megasas_dbg_lvl
& OCR_LOGS
) {
4589 sdev_printk(KERN_INFO
,
4590 cmd_fusion
->scmd
->device
, "SMID: 0x%x\n",
4592 scsi_print_command(cmd_fusion
->scmd
);
4595 scmd_local
->result
=
4596 megasas_check_mpio_paths(instance
,
4598 if (instance
->ldio_threshold
&&
4599 megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
)
4600 atomic_dec(&instance
->ldio_outstanding
);
4601 megasas_return_cmd_fusion(instance
, cmd_fusion
);
4602 scsi_dma_unmap(scmd_local
);
4603 scmd_local
->scsi_done(scmd_local
);
4607 atomic_set(&instance
->fw_outstanding
, 0);
4609 status_reg
= instance
->instancet
->read_fw_status_reg(
4611 abs_state
= status_reg
& MFI_STATE_MASK
;
4612 reset_adapter
= status_reg
& MFI_RESET_ADAPTER
;
4613 if (instance
->disableOnlineCtrlReset
||
4614 (abs_state
== MFI_STATE_FAULT
&& !reset_adapter
)) {
4615 /* Reset not supported, kill adapter */
4616 dev_warn(&instance
->pdev
->dev
, "Reset not supported"
4617 ", killing adapter scsi%d.\n",
4618 instance
->host
->host_no
);
4619 megaraid_sas_kill_hba(instance
);
4620 instance
->skip_heartbeat_timer_del
= 1;
4625 /* Let SR-IOV VF & PF sync up if there was a HB failure */
4626 if (instance
->requestorId
&& !reason
) {
4627 msleep(MEGASAS_OCR_SETTLE_TIME_VF
);
4628 goto transition_to_ready
;
4631 /* Now try to reset the chip */
4632 for (i
= 0; i
< MEGASAS_FUSION_MAX_RESET_TRIES
; i
++) {
4634 if (instance
->instancet
->adp_reset
4635 (instance
, instance
->reg_set
))
4637 transition_to_ready
:
4638 /* Wait for FW to become ready */
4639 if (megasas_transition_to_ready(instance
, 1)) {
4640 dev_warn(&instance
->pdev
->dev
,
4641 "Failed to transition controller to ready for "
4642 "scsi%d.\n", instance
->host
->host_no
);
4643 if (instance
->requestorId
&& !reason
)
4644 goto fail_kill_adapter
;
4648 megasas_reset_reply_desc(instance
);
4649 megasas_fusion_update_can_queue(instance
, OCR_CONTEXT
);
4651 if (megasas_ioc_init_fusion(instance
)) {
4652 if (instance
->requestorId
&& !reason
)
4653 goto fail_kill_adapter
;
4658 if (megasas_get_ctrl_info(instance
)) {
4659 dev_info(&instance
->pdev
->dev
,
4660 "Failed from %s %d\n",
4661 __func__
, __LINE__
);
4662 megaraid_sas_kill_hba(instance
);
4667 megasas_refire_mgmt_cmd(instance
);
4669 /* Reset load balance info */
4670 if (fusion
->load_balance_info
)
4671 memset(fusion
->load_balance_info
, 0,
4672 (sizeof(struct LD_LOAD_BALANCE_INFO
) *
4673 MAX_LOGICAL_DRIVES_EXT
));
4675 if (!megasas_get_map_info(instance
))
4676 megasas_sync_map_info(instance
);
4678 megasas_setup_jbod_map(instance
);
4680 shost_for_each_device(sdev
, shost
)
4681 megasas_set_dynamic_target_properties(sdev
);
4683 /* reset stream detection array */
4684 if (instance
->adapter_type
== VENTURA_SERIES
) {
4685 for (j
= 0; j
< MAX_LOGICAL_DRIVES_EXT
; ++j
) {
4686 memset(fusion
->stream_detect_by_ld
[j
],
4687 0, sizeof(struct LD_STREAM_DETECT
));
4688 fusion
->stream_detect_by_ld
[j
]->mru_bit_map
4693 clear_bit(MEGASAS_FUSION_IN_RESET
,
4694 &instance
->reset_flags
);
4695 instance
->instancet
->enable_intr(instance
);
4696 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
4698 dev_info(&instance
->pdev
->dev
, "Interrupts are enabled and"
4699 " controller is OPERATIONAL for scsi:%d\n",
4700 instance
->host
->host_no
);
4702 /* Restart SR-IOV heartbeat */
4703 if (instance
->requestorId
) {
4704 if (!megasas_sriov_start_heartbeat(instance
, 0))
4705 megasas_start_timer(instance
);
4707 instance
->skip_heartbeat_timer_del
= 1;
4710 if (instance
->crash_dump_drv_support
&&
4711 instance
->crash_dump_app_support
)
4712 megasas_set_crash_dump_params(instance
,
4713 MR_CRASH_BUF_TURN_ON
);
4715 megasas_set_crash_dump_params(instance
,
4716 MR_CRASH_BUF_TURN_OFF
);
4720 /* Adapter reset completed successfully */
4721 dev_warn(&instance
->pdev
->dev
,
4722 "Reset successful for scsi%d.\n",
4723 instance
->host
->host_no
);
4728 /* Reset failed, kill the adapter */
4729 dev_warn(&instance
->pdev
->dev
, "Reset failed, killing "
4730 "adapter scsi%d.\n", instance
->host
->host_no
);
4731 megaraid_sas_kill_hba(instance
);
4732 instance
->skip_heartbeat_timer_del
= 1;
4735 /* For VF: Restart HB timer if we didn't OCR */
4736 if (instance
->requestorId
) {
4737 megasas_start_timer(instance
);
4739 clear_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
4740 instance
->instancet
->enable_intr(instance
);
4741 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
4744 clear_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
4745 mutex_unlock(&instance
->reset_mutex
);
4749 /* Fusion Crash dump collection work queue */
4750 void megasas_fusion_crash_dump_wq(struct work_struct
*work
)
4752 struct megasas_instance
*instance
=
4753 container_of(work
, struct megasas_instance
, crash_init
);
4755 u8 partial_copy
= 0;
4758 status_reg
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
);
4761 * Allocate host crash buffers to copy data from 1 MB DMA crash buffer
4762 * to host crash buffers
4764 if (instance
->drv_buf_index
== 0) {
4765 /* Buffer is already allocated for old Crash dump.
4766 * Do OCR and do not wait for crash dump collection
4768 if (instance
->drv_buf_alloc
) {
4769 dev_info(&instance
->pdev
->dev
, "earlier crash dump is "
4770 "not yet copied by application, ignoring this "
4771 "crash dump and initiating OCR\n");
4772 status_reg
|= MFI_STATE_CRASH_DUMP_DONE
;
4774 &instance
->reg_set
->outbound_scratch_pad
);
4775 readl(&instance
->reg_set
->outbound_scratch_pad
);
4778 megasas_alloc_host_crash_buffer(instance
);
4779 dev_info(&instance
->pdev
->dev
, "Number of host crash buffers "
4780 "allocated: %d\n", instance
->drv_buf_alloc
);
4784 * Driver has allocated max buffers, which can be allocated
4785 * and FW has more crash dump data, then driver will
4788 if (instance
->drv_buf_index
>= (instance
->drv_buf_alloc
)) {
4789 dev_info(&instance
->pdev
->dev
, "Driver is done copying "
4790 "the buffer: %d\n", instance
->drv_buf_alloc
);
4791 status_reg
|= MFI_STATE_CRASH_DUMP_DONE
;
4794 memcpy(instance
->crash_buf
[instance
->drv_buf_index
],
4795 instance
->crash_dump_buf
, CRASH_DMA_BUF_SIZE
);
4796 instance
->drv_buf_index
++;
4797 status_reg
&= ~MFI_STATE_DMADONE
;
4800 if (status_reg
& MFI_STATE_CRASH_DUMP_DONE
) {
4801 dev_info(&instance
->pdev
->dev
, "Crash Dump is available,number "
4802 "of copied buffers: %d\n", instance
->drv_buf_index
);
4803 instance
->fw_crash_buffer_size
= instance
->drv_buf_index
;
4804 instance
->fw_crash_state
= AVAILABLE
;
4805 instance
->drv_buf_index
= 0;
4806 writel(status_reg
, &instance
->reg_set
->outbound_scratch_pad
);
4807 readl(&instance
->reg_set
->outbound_scratch_pad
);
4809 megasas_reset_fusion(instance
->host
, 0);
4811 writel(status_reg
, &instance
->reg_set
->outbound_scratch_pad
);
4812 readl(&instance
->reg_set
->outbound_scratch_pad
);
4817 /* Fusion OCR work queue */
4818 void megasas_fusion_ocr_wq(struct work_struct
*work
)
4820 struct megasas_instance
*instance
=
4821 container_of(work
, struct megasas_instance
, work_init
);
4823 megasas_reset_fusion(instance
->host
, 0);
4826 /* Allocate fusion context */
4828 megasas_alloc_fusion_context(struct megasas_instance
*instance
)
4830 struct fusion_context
*fusion
;
4832 instance
->ctrl_context
= kzalloc(sizeof(struct fusion_context
),
4834 if (!instance
->ctrl_context
) {
4835 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
4836 __func__
, __LINE__
);
4840 fusion
= instance
->ctrl_context
;
4842 fusion
->log_to_span_pages
= get_order(MAX_LOGICAL_DRIVES_EXT
*
4843 sizeof(LD_SPAN_INFO
));
4844 fusion
->log_to_span
=
4845 (PLD_SPAN_INFO
)__get_free_pages(GFP_KERNEL
| __GFP_ZERO
,
4846 fusion
->log_to_span_pages
);
4847 if (!fusion
->log_to_span
) {
4848 fusion
->log_to_span
= vzalloc(MAX_LOGICAL_DRIVES_EXT
*
4849 sizeof(LD_SPAN_INFO
));
4850 if (!fusion
->log_to_span
) {
4851 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
4852 __func__
, __LINE__
);
4857 fusion
->load_balance_info_pages
= get_order(MAX_LOGICAL_DRIVES_EXT
*
4858 sizeof(struct LD_LOAD_BALANCE_INFO
));
4859 fusion
->load_balance_info
=
4860 (struct LD_LOAD_BALANCE_INFO
*)__get_free_pages(GFP_KERNEL
| __GFP_ZERO
,
4861 fusion
->load_balance_info_pages
);
4862 if (!fusion
->load_balance_info
) {
4863 fusion
->load_balance_info
= vzalloc(MAX_LOGICAL_DRIVES_EXT
*
4864 sizeof(struct LD_LOAD_BALANCE_INFO
));
4865 if (!fusion
->load_balance_info
)
4866 dev_err(&instance
->pdev
->dev
, "Failed to allocate load_balance_info, "
4867 "continuing without Load Balance support\n");
4874 megasas_free_fusion_context(struct megasas_instance
*instance
)
4876 struct fusion_context
*fusion
= instance
->ctrl_context
;
4879 if (fusion
->load_balance_info
) {
4880 if (is_vmalloc_addr(fusion
->load_balance_info
))
4881 vfree(fusion
->load_balance_info
);
4883 free_pages((ulong
)fusion
->load_balance_info
,
4884 fusion
->load_balance_info_pages
);
4887 if (fusion
->log_to_span
) {
4888 if (is_vmalloc_addr(fusion
->log_to_span
))
4889 vfree(fusion
->log_to_span
);
4891 free_pages((ulong
)fusion
->log_to_span
,
4892 fusion
->log_to_span_pages
);
4899 struct megasas_instance_template megasas_instance_template_fusion
= {
4900 .enable_intr
= megasas_enable_intr_fusion
,
4901 .disable_intr
= megasas_disable_intr_fusion
,
4902 .clear_intr
= megasas_clear_intr_fusion
,
4903 .read_fw_status_reg
= megasas_read_fw_status_reg_fusion
,
4904 .adp_reset
= megasas_adp_reset_fusion
,
4905 .check_reset
= megasas_check_reset_fusion
,
4906 .service_isr
= megasas_isr_fusion
,
4907 .tasklet
= megasas_complete_cmd_dpc_fusion
,
4908 .init_adapter
= megasas_init_adapter_fusion
,
4909 .build_and_issue_cmd
= megasas_build_and_issue_cmd_fusion
,
4910 .issue_dcmd
= megasas_issue_dcmd_fusion
,