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 do_gettimeofday(&tv
);
1046 /* Convert to milliseconds as per FW requirement */
1047 IOCInitMessage
->TimeStamp
= cpu_to_le64((tv
.tv_sec
* 1000) +
1048 (tv
.tv_usec
/ 1000));
1050 init_frame
= (struct megasas_init_frame
*)cmd
->frame
;
1051 memset(init_frame
, 0, MEGAMFI_FRAME_SIZE
);
1053 frame_hdr
= &cmd
->frame
->hdr
;
1054 frame_hdr
->cmd_status
= 0xFF;
1055 frame_hdr
->flags
= cpu_to_le16(
1056 le16_to_cpu(frame_hdr
->flags
) |
1057 MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
);
1059 init_frame
->cmd
= MFI_CMD_INIT
;
1060 init_frame
->cmd_status
= 0xFF;
1062 drv_ops
= (MFI_CAPABILITIES
*) &(init_frame
->driver_operations
);
1064 /* driver support Extended MSIX */
1065 if (instance
->adapter_type
>= INVADER_SERIES
)
1066 drv_ops
->mfi_capabilities
.support_additional_msix
= 1;
1067 /* driver supports HA / Remote LUN over Fast Path interface */
1068 drv_ops
->mfi_capabilities
.support_fp_remote_lun
= 1;
1070 drv_ops
->mfi_capabilities
.support_max_255lds
= 1;
1071 drv_ops
->mfi_capabilities
.support_ndrive_r1_lb
= 1;
1072 drv_ops
->mfi_capabilities
.security_protocol_cmds_fw
= 1;
1074 if (instance
->max_chain_frame_sz
> MEGASAS_CHAIN_FRAME_SZ_MIN
)
1075 drv_ops
->mfi_capabilities
.support_ext_io_size
= 1;
1077 drv_ops
->mfi_capabilities
.support_fp_rlbypass
= 1;
1078 if (!dual_qdepth_disable
)
1079 drv_ops
->mfi_capabilities
.support_ext_queue_depth
= 1;
1081 drv_ops
->mfi_capabilities
.support_qd_throttling
= 1;
1082 drv_ops
->mfi_capabilities
.support_pd_map_target_id
= 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
)) {
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
= kmalloc(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 spin_lock_irqsave(&instance
->stream_lock
, spinlock_flags
);
2668 megasas_stream_detect(instance
, cmd
, &io_info
);
2669 spin_unlock_irqrestore(&instance
->stream_lock
, spinlock_flags
);
2670 /* In ventura if stream detected for a read and it is read ahead
2671 * capable make this IO as LDIO
2673 if (is_stream_detected(&io_request
->RaidContext
.raid_context_g35
) &&
2674 io_info
.isRead
&& io_info
.ra_capable
)
2675 fp_possible
= false;
2677 /* FP for Optimal raid level 1.
2678 * All large RAID-1 writes (> 32 KiB, both WT and WB modes)
2679 * are built by the driver as LD I/Os.
2680 * All small RAID-1 WT writes (<= 32 KiB) are built as FP I/Os
2681 * (there is never a reason to process these as buffered writes)
2682 * All small RAID-1 WB writes (<= 32 KiB) are built as FP I/Os
2683 * with the SLD bit asserted.
2685 if (io_info
.r1_alt_dev_handle
!= MR_DEVHANDLE_INVALID
) {
2686 mrdev_priv
= scp
->device
->hostdata
;
2688 if (atomic_inc_return(&instance
->fw_outstanding
) >
2689 (instance
->host
->can_queue
)) {
2690 fp_possible
= false;
2691 atomic_dec(&instance
->fw_outstanding
);
2692 } else if ((scsi_buff_len
> MR_LARGE_IO_MIN_SIZE
) ||
2693 (atomic_dec_if_positive(&mrdev_priv
->r1_ldio_hint
) > 0)) {
2694 fp_possible
= false;
2695 atomic_dec(&instance
->fw_outstanding
);
2696 if (scsi_buff_len
> MR_LARGE_IO_MIN_SIZE
)
2697 atomic_set(&mrdev_priv
->r1_ldio_hint
,
2698 instance
->r1_ldio_hint_default
);
2702 /* If raid is NULL, set CPU affinity to default CPU0 */
2704 megasas_set_raidflag_cpu_affinity(praid_context
,
2705 raid
, fp_possible
, io_info
.isRead
,
2708 praid_context
->raid_context_g35
.routing_flags
|=
2709 (MR_RAID_CTX_CPUSEL_0
<< MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT
);
2713 megasas_set_pd_lba(io_request
, scp
->cmd_len
, &io_info
, scp
,
2714 local_map_ptr
, start_lba_lo
);
2715 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2716 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2717 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
2718 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2719 if (instance
->adapter_type
== INVADER_SERIES
) {
2720 if (io_request
->RaidContext
.raid_context
.reg_lock_flags
==
2722 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2723 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK
<<
2724 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2725 io_request
->RaidContext
.raid_context
.type
2727 io_request
->RaidContext
.raid_context
.nseg
= 0x1;
2728 io_request
->IoFlags
|= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
2729 io_request
->RaidContext
.raid_context
.reg_lock_flags
|=
2730 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA
|
2731 MR_RL_FLAGS_SEQ_NUM_ENABLE
);
2732 } else if (instance
->adapter_type
== VENTURA_SERIES
) {
2733 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2734 (1 << RAID_CONTEXT_NSEG_SHIFT
);
2735 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2736 (MPI2_TYPE_CUDA
<< RAID_CONTEXT_TYPE_SHIFT
);
2737 io_request
->RaidContext
.raid_context_g35
.routing_flags
|=
2738 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT
);
2739 io_request
->IoFlags
|=
2740 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
2742 if (fusion
->load_balance_info
&&
2743 (fusion
->load_balance_info
[device_id
].loadBalanceFlag
) &&
2746 get_updated_dev_handle(instance
,
2747 &fusion
->load_balance_info
[device_id
],
2748 &io_info
, local_map_ptr
);
2749 scp
->SCp
.Status
|= MEGASAS_LOAD_BALANCE_FLAG
;
2750 cmd
->pd_r1_lb
= io_info
.pd_after_lb
;
2751 if (instance
->adapter_type
== VENTURA_SERIES
)
2752 io_request
->RaidContext
.raid_context_g35
.span_arm
2755 io_request
->RaidContext
.raid_context
.span_arm
2759 scp
->SCp
.Status
&= ~MEGASAS_LOAD_BALANCE_FLAG
;
2761 if (instance
->adapter_type
== VENTURA_SERIES
)
2762 cmd
->r1_alt_dev_handle
= io_info
.r1_alt_dev_handle
;
2764 cmd
->r1_alt_dev_handle
= MR_DEVHANDLE_INVALID
;
2766 if ((raidLUN
[0] == 1) &&
2767 (local_map_ptr
->raidMap
.devHndlInfo
[io_info
.pd_after_lb
].validHandles
> 1)) {
2768 instance
->dev_handle
= !(instance
->dev_handle
);
2770 local_map_ptr
->raidMap
.devHndlInfo
[io_info
.pd_after_lb
].devHandle
[instance
->dev_handle
];
2773 cmd
->request_desc
->SCSIIO
.DevHandle
= io_info
.devHandle
;
2774 io_request
->DevHandle
= io_info
.devHandle
;
2775 cmd
->pd_interface
= io_info
.pd_interface
;
2776 /* populate the LUN field */
2777 memcpy(io_request
->LUN
, raidLUN
, 8);
2779 io_request
->RaidContext
.raid_context
.timeout_value
=
2780 cpu_to_le16(local_map_ptr
->raidMap
.fpPdIoTimeoutSec
);
2781 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2782 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
2783 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2784 if (instance
->adapter_type
== INVADER_SERIES
) {
2785 if (io_info
.do_fp_rlbypass
||
2786 (io_request
->RaidContext
.raid_context
.reg_lock_flags
2787 == REGION_TYPE_UNUSED
))
2788 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2789 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK
<<
2790 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2791 io_request
->RaidContext
.raid_context
.type
2793 io_request
->RaidContext
.raid_context
.reg_lock_flags
|=
2794 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0
|
2795 MR_RL_FLAGS_SEQ_NUM_ENABLE
);
2796 io_request
->RaidContext
.raid_context
.nseg
= 0x1;
2797 } else if (instance
->adapter_type
== VENTURA_SERIES
) {
2798 io_request
->RaidContext
.raid_context_g35
.routing_flags
|=
2799 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT
);
2800 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2801 (1 << RAID_CONTEXT_NSEG_SHIFT
);
2802 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2803 (MPI2_TYPE_CUDA
<< RAID_CONTEXT_TYPE_SHIFT
);
2805 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
2806 io_request
->DevHandle
= cpu_to_le16(device_id
);
2812 * megasas_build_ld_nonrw_fusion - prepares non rw ios for virtual disk
2813 * @instance: Adapter soft state
2814 * @scp: SCSI command
2815 * @cmd: Command to be prepared
2817 * Prepares the io_request frame for non-rw io cmds for vd.
2819 static void megasas_build_ld_nonrw_fusion(struct megasas_instance
*instance
,
2820 struct scsi_cmnd
*scmd
, struct megasas_cmd_fusion
*cmd
)
2823 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
2825 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
2826 struct fusion_context
*fusion
= instance
->ctrl_context
;
2830 struct MR_LD_RAID
*raid
;
2831 struct RAID_CONTEXT
*pRAID_Context
;
2834 io_request
= cmd
->io_request
;
2835 device_id
= MEGASAS_DEV_INDEX(scmd
);
2836 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
2837 io_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2838 /* get RAID_Context pointer */
2839 pRAID_Context
= &io_request
->RaidContext
.raid_context
;
2840 /* Check with FW team */
2841 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
2842 pRAID_Context
->reg_lock_row_lba
= 0;
2843 pRAID_Context
->reg_lock_length
= 0;
2845 if (fusion
->fast_path_io
&& (
2846 device_id
< instance
->fw_supported_vd_count
)) {
2848 ld
= MR_TargetIdToLdGet(device_id
, local_map_ptr
);
2849 if (ld
>= instance
->fw_supported_vd_count
)
2852 raid
= MR_LdRaidGet(ld
, local_map_ptr
);
2853 if (!(raid
->capability
.fpNonRWCapable
))
2860 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
2861 io_request
->DevHandle
= cpu_to_le16(device_id
);
2862 io_request
->LUN
[1] = scmd
->device
->lun
;
2863 pRAID_Context
->timeout_value
=
2864 cpu_to_le16 (scmd
->request
->timeout
/ HZ
);
2865 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2866 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
2867 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2870 /* set RAID context values */
2871 pRAID_Context
->config_seq_num
= raid
->seqNum
;
2872 if (instance
->adapter_type
!= VENTURA_SERIES
)
2873 pRAID_Context
->reg_lock_flags
= REGION_TYPE_SHARED_READ
;
2874 pRAID_Context
->timeout_value
=
2875 cpu_to_le16(raid
->fpIoTimeoutForLd
);
2877 /* get the DevHandle for the PD (since this is
2878 fpNonRWCapable, this is a single disk RAID0) */
2880 arRef
= MR_LdSpanArrayGet(ld
, span
, local_map_ptr
);
2881 pd
= MR_ArPdGet(arRef
, physArm
, local_map_ptr
);
2882 devHandle
= MR_PdDevHandleGet(pd
, local_map_ptr
);
2884 /* build request descriptor */
2885 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2886 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
<<
2887 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2888 cmd
->request_desc
->SCSIIO
.DevHandle
= devHandle
;
2890 /* populate the LUN field */
2891 memcpy(io_request
->LUN
, raid
->LUN
, 8);
2893 /* build the raidScsiIO structure */
2894 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
2895 io_request
->DevHandle
= devHandle
;
2900 * megasas_build_syspd_fusion - prepares rw/non-rw ios for syspd
2901 * @instance: Adapter soft state
2902 * @scp: SCSI command
2903 * @cmd: Command to be prepared
2904 * @fp_possible: parameter to detect fast path or firmware path io.
2906 * Prepares the io_request frame for rw/non-rw io cmds for syspds
2909 megasas_build_syspd_fusion(struct megasas_instance
*instance
,
2910 struct scsi_cmnd
*scmd
, struct megasas_cmd_fusion
*cmd
,
2914 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
;
2916 u16 os_timeout_value
;
2918 struct MR_DRV_RAID_MAP_ALL
*local_map_ptr
;
2919 struct RAID_CONTEXT
*pRAID_Context
;
2920 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
2921 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
2922 struct fusion_context
*fusion
= instance
->ctrl_context
;
2923 pd_sync
= (void *)fusion
->pd_seq_sync
[(instance
->pd_seq_map_id
- 1) & 1];
2925 device_id
= MEGASAS_DEV_INDEX(scmd
);
2926 pd_index
= MEGASAS_PD_INDEX(scmd
);
2927 os_timeout_value
= scmd
->request
->timeout
/ HZ
;
2928 mr_device_priv_data
= scmd
->device
->hostdata
;
2929 cmd
->pd_interface
= mr_device_priv_data
->interface_type
;
2931 io_request
= cmd
->io_request
;
2932 /* get RAID_Context pointer */
2933 pRAID_Context
= &io_request
->RaidContext
.raid_context
;
2934 pRAID_Context
->reg_lock_flags
= 0;
2935 pRAID_Context
->reg_lock_row_lba
= 0;
2936 pRAID_Context
->reg_lock_length
= 0;
2937 io_request
->DataLength
= cpu_to_le32(scsi_bufflen(scmd
));
2938 io_request
->LUN
[1] = scmd
->device
->lun
;
2939 pRAID_Context
->raid_flags
= MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD
2940 << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT
;
2942 /* If FW supports PD sequence number */
2943 if (instance
->use_seqnum_jbod_fp
&&
2944 instance
->pd_list
[pd_index
].driveType
== TYPE_DISK
) {
2945 /* TgtId must be incremented by 255 as jbod seq number is index
2948 /* More than 256 PD/JBOD support for Ventura */
2949 if (instance
->support_morethan256jbod
)
2950 pRAID_Context
->virtual_disk_tgt_id
=
2951 pd_sync
->seq
[pd_index
].pd_target_id
;
2953 pRAID_Context
->virtual_disk_tgt_id
=
2954 cpu_to_le16(device_id
+ (MAX_PHYSICAL_DEVICES
- 1));
2955 pRAID_Context
->config_seq_num
= pd_sync
->seq
[pd_index
].seqNum
;
2956 io_request
->DevHandle
= pd_sync
->seq
[pd_index
].devHandle
;
2957 if (instance
->adapter_type
== VENTURA_SERIES
) {
2958 io_request
->RaidContext
.raid_context_g35
.routing_flags
|=
2959 (1 << MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT
);
2960 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2961 (1 << RAID_CONTEXT_NSEG_SHIFT
);
2962 io_request
->RaidContext
.raid_context_g35
.nseg_type
|=
2963 (MPI2_TYPE_CUDA
<< RAID_CONTEXT_TYPE_SHIFT
);
2965 pRAID_Context
->type
= MPI2_TYPE_CUDA
;
2966 pRAID_Context
->nseg
= 0x1;
2967 pRAID_Context
->reg_lock_flags
|=
2968 (MR_RL_FLAGS_SEQ_NUM_ENABLE
|MR_RL_FLAGS_GRANT_DESTINATION_CUDA
);
2970 } else if (fusion
->fast_path_io
) {
2971 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
2972 pRAID_Context
->config_seq_num
= 0;
2973 local_map_ptr
= fusion
->ld_drv_map
[(instance
->map_id
& 1)];
2974 io_request
->DevHandle
=
2975 local_map_ptr
->raidMap
.devHndlInfo
[device_id
].curDevHdl
;
2977 /* Want to send all IO via FW path */
2978 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
2979 pRAID_Context
->config_seq_num
= 0;
2980 io_request
->DevHandle
= cpu_to_le16(0xFFFF);
2983 cmd
->request_desc
->SCSIIO
.DevHandle
= io_request
->DevHandle
;
2984 cmd
->request_desc
->SCSIIO
.MSIxIndex
=
2985 instance
->msix_vectors
?
2986 (raw_smp_processor_id() % instance
->msix_vectors
) : 0;
2990 /* system pd firmware path */
2991 io_request
->Function
= MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
;
2992 cmd
->request_desc
->SCSIIO
.RequestFlags
=
2993 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
2994 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
2995 pRAID_Context
->timeout_value
= cpu_to_le16(os_timeout_value
);
2996 pRAID_Context
->virtual_disk_tgt_id
= cpu_to_le16(device_id
);
2998 /* system pd Fast Path */
2999 io_request
->Function
= MPI2_FUNCTION_SCSI_IO_REQUEST
;
3000 timeout_limit
= (scmd
->device
->type
== TYPE_DISK
) ?
3002 pRAID_Context
->timeout_value
=
3003 cpu_to_le16((os_timeout_value
> timeout_limit
) ?
3004 timeout_limit
: os_timeout_value
);
3005 if (instance
->adapter_type
>= INVADER_SERIES
)
3006 io_request
->IoFlags
|=
3007 cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH
);
3009 cmd
->request_desc
->SCSIIO
.RequestFlags
=
3010 (MPI2_REQ_DESCRIPT_FLAGS_FP_IO
<<
3011 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
3016 * megasas_build_io_fusion - Prepares IOs to devices
3017 * @instance: Adapter soft state
3018 * @scp: SCSI command
3019 * @cmd: Command to be prepared
3021 * Invokes helper functions to prepare request frames
3022 * and sets flags appropriate for IO/Non-IO cmd
3025 megasas_build_io_fusion(struct megasas_instance
*instance
,
3026 struct scsi_cmnd
*scp
,
3027 struct megasas_cmd_fusion
*cmd
)
3031 struct MPI2_RAID_SCSI_IO_REQUEST
*io_request
= cmd
->io_request
;
3032 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
3033 mr_device_priv_data
= scp
->device
->hostdata
;
3035 /* Zero out some fields so they don't get reused */
3036 memset(io_request
->LUN
, 0x0, 8);
3037 io_request
->CDB
.EEDP32
.PrimaryReferenceTag
= 0;
3038 io_request
->CDB
.EEDP32
.PrimaryApplicationTagMask
= 0;
3039 io_request
->EEDPFlags
= 0;
3040 io_request
->Control
= 0;
3041 io_request
->EEDPBlockSize
= 0;
3042 io_request
->ChainOffset
= 0;
3043 io_request
->RaidContext
.raid_context
.raid_flags
= 0;
3044 io_request
->RaidContext
.raid_context
.type
= 0;
3045 io_request
->RaidContext
.raid_context
.nseg
= 0;
3047 memcpy(io_request
->CDB
.CDB32
, scp
->cmnd
, scp
->cmd_len
);
3049 * Just the CDB length,rest of the Flags are zero
3050 * This will be modified for FP in build_ldio_fusion
3052 io_request
->IoFlags
= cpu_to_le16(scp
->cmd_len
);
3054 switch (cmd_type
= megasas_cmd_type(scp
)) {
3055 case READ_WRITE_LDIO
:
3056 megasas_build_ldio_fusion(instance
, scp
, cmd
);
3058 case NON_READ_WRITE_LDIO
:
3059 megasas_build_ld_nonrw_fusion(instance
, scp
, cmd
);
3061 case READ_WRITE_SYSPDIO
:
3062 megasas_build_syspd_fusion(instance
, scp
, cmd
, true);
3064 case NON_READ_WRITE_SYSPDIO
:
3065 if (instance
->secure_jbod_support
||
3066 mr_device_priv_data
->is_tm_capable
)
3067 megasas_build_syspd_fusion(instance
, scp
, cmd
, false);
3069 megasas_build_syspd_fusion(instance
, scp
, cmd
, true);
3079 sge_count
= megasas_make_sgl(instance
, scp
, cmd
);
3081 if (sge_count
> instance
->max_num_sge
|| (sge_count
< 0)) {
3082 dev_err(&instance
->pdev
->dev
,
3083 "%s %d sge_count (%d) is out of range. Range is: 0-%d\n",
3084 __func__
, __LINE__
, sge_count
, instance
->max_num_sge
);
3088 if (instance
->adapter_type
== VENTURA_SERIES
) {
3089 set_num_sge(&io_request
->RaidContext
.raid_context_g35
, sge_count
);
3090 cpu_to_le16s(&io_request
->RaidContext
.raid_context_g35
.routing_flags
);
3091 cpu_to_le16s(&io_request
->RaidContext
.raid_context_g35
.nseg_type
);
3093 /* numSGE store lower 8 bit of sge_count.
3094 * numSGEExt store higher 8 bit of sge_count
3096 io_request
->RaidContext
.raid_context
.num_sge
= sge_count
;
3097 io_request
->RaidContext
.raid_context
.num_sge_ext
=
3098 (u8
)(sge_count
>> 8);
3101 io_request
->SGLFlags
= cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING
);
3103 if (scp
->sc_data_direction
== PCI_DMA_TODEVICE
)
3104 io_request
->Control
|= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE
);
3105 else if (scp
->sc_data_direction
== PCI_DMA_FROMDEVICE
)
3106 io_request
->Control
|= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ
);
3108 io_request
->SGLOffset0
=
3109 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
, SGL
) / 4;
3111 io_request
->SenseBufferLowAddress
=
3112 cpu_to_le32(lower_32_bits(cmd
->sense_phys_addr
));
3113 io_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
3116 scp
->SCp
.ptr
= (char *)cmd
;
3121 static union MEGASAS_REQUEST_DESCRIPTOR_UNION
*
3122 megasas_get_request_descriptor(struct megasas_instance
*instance
, u16 index
)
3125 struct fusion_context
*fusion
;
3127 fusion
= instance
->ctrl_context
;
3128 p
= fusion
->req_frames_desc
+
3129 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION
) * index
;
3131 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION
*)p
;
3135 /* megasas_prepate_secondRaid1_IO
3136 * It prepares the raid 1 second IO
3138 void megasas_prepare_secondRaid1_IO(struct megasas_instance
*instance
,
3139 struct megasas_cmd_fusion
*cmd
,
3140 struct megasas_cmd_fusion
*r1_cmd
)
3142 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
, *req_desc2
= NULL
;
3143 struct fusion_context
*fusion
;
3144 fusion
= instance
->ctrl_context
;
3145 req_desc
= cmd
->request_desc
;
3146 /* copy the io request frame as well as 8 SGEs data for r1 command*/
3147 memcpy(r1_cmd
->io_request
, cmd
->io_request
,
3148 (sizeof(struct MPI2_RAID_SCSI_IO_REQUEST
)));
3149 memcpy(&r1_cmd
->io_request
->SGL
, &cmd
->io_request
->SGL
,
3150 (fusion
->max_sge_in_main_msg
* sizeof(union MPI2_SGE_IO_UNION
)));
3151 /*sense buffer is different for r1 command*/
3152 r1_cmd
->io_request
->SenseBufferLowAddress
=
3153 cpu_to_le32(lower_32_bits(r1_cmd
->sense_phys_addr
));
3154 r1_cmd
->scmd
= cmd
->scmd
;
3155 req_desc2
= megasas_get_request_descriptor(instance
,
3156 (r1_cmd
->index
- 1));
3157 req_desc2
->Words
= 0;
3158 r1_cmd
->request_desc
= req_desc2
;
3159 req_desc2
->SCSIIO
.SMID
= cpu_to_le16(r1_cmd
->index
);
3160 req_desc2
->SCSIIO
.RequestFlags
= req_desc
->SCSIIO
.RequestFlags
;
3161 r1_cmd
->request_desc
->SCSIIO
.DevHandle
= cmd
->r1_alt_dev_handle
;
3162 r1_cmd
->io_request
->DevHandle
= cmd
->r1_alt_dev_handle
;
3163 r1_cmd
->r1_alt_dev_handle
= cmd
->io_request
->DevHandle
;
3164 cmd
->io_request
->RaidContext
.raid_context_g35
.smid
.peer_smid
=
3165 cpu_to_le16(r1_cmd
->index
);
3166 r1_cmd
->io_request
->RaidContext
.raid_context_g35
.smid
.peer_smid
=
3167 cpu_to_le16(cmd
->index
);
3168 /*MSIxIndex of both commands request descriptors should be same*/
3169 r1_cmd
->request_desc
->SCSIIO
.MSIxIndex
=
3170 cmd
->request_desc
->SCSIIO
.MSIxIndex
;
3171 /*span arm is different for r1 cmd*/
3172 r1_cmd
->io_request
->RaidContext
.raid_context_g35
.span_arm
=
3173 cmd
->io_request
->RaidContext
.raid_context_g35
.span_arm
+ 1;
3177 * megasas_build_and_issue_cmd_fusion -Main routine for building and
3178 * issuing non IOCTL cmd
3179 * @instance: Adapter soft state
3180 * @scmd: pointer to scsi cmd from OS
3183 megasas_build_and_issue_cmd_fusion(struct megasas_instance
*instance
,
3184 struct scsi_cmnd
*scmd
)
3186 struct megasas_cmd_fusion
*cmd
, *r1_cmd
= NULL
;
3187 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
3189 struct fusion_context
*fusion
;
3191 fusion
= instance
->ctrl_context
;
3193 if ((megasas_cmd_type(scmd
) == READ_WRITE_LDIO
) &&
3194 instance
->ldio_threshold
&&
3195 (atomic_inc_return(&instance
->ldio_outstanding
) >
3196 instance
->ldio_threshold
)) {
3197 atomic_dec(&instance
->ldio_outstanding
);
3198 return SCSI_MLQUEUE_DEVICE_BUSY
;
3201 if (atomic_inc_return(&instance
->fw_outstanding
) >
3202 instance
->host
->can_queue
) {
3203 atomic_dec(&instance
->fw_outstanding
);
3204 return SCSI_MLQUEUE_HOST_BUSY
;
3207 cmd
= megasas_get_cmd_fusion(instance
, scmd
->request
->tag
);
3210 atomic_dec(&instance
->fw_outstanding
);
3211 return SCSI_MLQUEUE_HOST_BUSY
;
3216 req_desc
= megasas_get_request_descriptor(instance
, index
-1);
3218 req_desc
->Words
= 0;
3219 cmd
->request_desc
= req_desc
;
3221 if (megasas_build_io_fusion(instance
, scmd
, cmd
)) {
3222 megasas_return_cmd_fusion(instance
, cmd
);
3223 dev_err(&instance
->pdev
->dev
, "Error building command\n");
3224 cmd
->request_desc
= NULL
;
3225 atomic_dec(&instance
->fw_outstanding
);
3226 return SCSI_MLQUEUE_HOST_BUSY
;
3229 req_desc
= cmd
->request_desc
;
3230 req_desc
->SCSIIO
.SMID
= cpu_to_le16(index
);
3232 if (cmd
->io_request
->ChainOffset
!= 0 &&
3233 cmd
->io_request
->ChainOffset
!= 0xF)
3234 dev_err(&instance
->pdev
->dev
, "The chain offset value is not "
3235 "correct : %x\n", cmd
->io_request
->ChainOffset
);
3237 * if it is raid 1/10 fp write capable.
3238 * try to get second command from pool and construct it.
3239 * From FW, it has confirmed that lba values of two PDs
3240 * corresponds to single R1/10 LD are always same
3243 /* driver side count always should be less than max_fw_cmds
3244 * to get new command
3246 if (cmd
->r1_alt_dev_handle
!= MR_DEVHANDLE_INVALID
) {
3247 r1_cmd
= megasas_get_cmd_fusion(instance
,
3248 (scmd
->request
->tag
+ instance
->max_fw_cmds
));
3249 megasas_prepare_secondRaid1_IO(instance
, cmd
, r1_cmd
);
3254 * Issue the command to the FW
3257 megasas_fire_cmd_fusion(instance
, req_desc
);
3260 megasas_fire_cmd_fusion(instance
, r1_cmd
->request_desc
);
3267 * megasas_complete_r1_command -
3268 * completes R1 FP write commands which has valid peer smid
3269 * @instance: Adapter soft state
3270 * @cmd_fusion: MPT command frame
3274 megasas_complete_r1_command(struct megasas_instance
*instance
,
3275 struct megasas_cmd_fusion
*cmd
)
3277 u8
*sense
, status
, ex_status
;
3280 struct fusion_context
*fusion
;
3281 struct megasas_cmd_fusion
*r1_cmd
= NULL
;
3282 struct scsi_cmnd
*scmd_local
= NULL
;
3283 struct RAID_CONTEXT_G35
*rctx_g35
;
3285 rctx_g35
= &cmd
->io_request
->RaidContext
.raid_context_g35
;
3286 fusion
= instance
->ctrl_context
;
3287 peer_smid
= le16_to_cpu(rctx_g35
->smid
.peer_smid
);
3289 r1_cmd
= fusion
->cmd_list
[peer_smid
- 1];
3290 scmd_local
= cmd
->scmd
;
3291 status
= rctx_g35
->status
;
3292 ex_status
= rctx_g35
->ex_status
;
3293 data_length
= cmd
->io_request
->DataLength
;
3296 cmd
->cmd_completed
= true;
3298 /* Check if peer command is completed or not*/
3299 if (r1_cmd
->cmd_completed
) {
3300 rctx_g35
= &r1_cmd
->io_request
->RaidContext
.raid_context_g35
;
3301 if (rctx_g35
->status
!= MFI_STAT_OK
) {
3302 status
= rctx_g35
->status
;
3303 ex_status
= rctx_g35
->ex_status
;
3304 data_length
= r1_cmd
->io_request
->DataLength
;
3305 sense
= r1_cmd
->sense
;
3308 megasas_return_cmd_fusion(instance
, r1_cmd
);
3309 map_cmd_status(fusion
, scmd_local
, status
, ex_status
,
3310 le32_to_cpu(data_length
), sense
);
3311 if (instance
->ldio_threshold
&&
3312 megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
)
3313 atomic_dec(&instance
->ldio_outstanding
);
3314 scmd_local
->SCp
.ptr
= NULL
;
3315 megasas_return_cmd_fusion(instance
, cmd
);
3316 scsi_dma_unmap(scmd_local
);
3317 scmd_local
->scsi_done(scmd_local
);
3322 * complete_cmd_fusion - Completes command
3323 * @instance: Adapter soft state
3324 * Completes all commands that is in reply descriptor queue
3327 complete_cmd_fusion(struct megasas_instance
*instance
, u32 MSIxIndex
)
3329 union MPI2_REPLY_DESCRIPTORS_UNION
*desc
;
3330 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*reply_desc
;
3331 struct MPI2_RAID_SCSI_IO_REQUEST
*scsi_io_req
;
3332 struct fusion_context
*fusion
;
3333 struct megasas_cmd
*cmd_mfi
;
3334 struct megasas_cmd_fusion
*cmd_fusion
;
3335 u16 smid
, num_completed
;
3336 u8 reply_descript_type
, *sense
, status
, extStatus
;
3337 u32 device_id
, data_length
;
3338 union desc_value d_val
;
3339 struct LD_LOAD_BALANCE_INFO
*lbinfo
;
3340 int threshold_reply_count
= 0;
3341 struct scsi_cmnd
*scmd_local
= NULL
;
3342 struct MR_TASK_MANAGE_REQUEST
*mr_tm_req
;
3343 struct MPI2_SCSI_TASK_MANAGE_REQUEST
*mpi_tm_req
;
3345 fusion
= instance
->ctrl_context
;
3347 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
)
3350 desc
= fusion
->reply_frames_desc
[MSIxIndex
] +
3351 fusion
->last_reply_idx
[MSIxIndex
];
3353 reply_desc
= (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*)desc
;
3355 d_val
.word
= desc
->Words
;
3357 reply_descript_type
= reply_desc
->ReplyFlags
&
3358 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
3360 if (reply_descript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
3365 while (d_val
.u
.low
!= cpu_to_le32(UINT_MAX
) &&
3366 d_val
.u
.high
!= cpu_to_le32(UINT_MAX
)) {
3368 smid
= le16_to_cpu(reply_desc
->SMID
);
3369 cmd_fusion
= fusion
->cmd_list
[smid
- 1];
3370 scsi_io_req
= (struct MPI2_RAID_SCSI_IO_REQUEST
*)
3371 cmd_fusion
->io_request
;
3373 scmd_local
= cmd_fusion
->scmd
;
3374 status
= scsi_io_req
->RaidContext
.raid_context
.status
;
3375 extStatus
= scsi_io_req
->RaidContext
.raid_context
.ex_status
;
3376 sense
= cmd_fusion
->sense
;
3377 data_length
= scsi_io_req
->DataLength
;
3379 switch (scsi_io_req
->Function
) {
3380 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
3381 mr_tm_req
= (struct MR_TASK_MANAGE_REQUEST
*)
3382 cmd_fusion
->io_request
;
3383 mpi_tm_req
= (struct MPI2_SCSI_TASK_MANAGE_REQUEST
*)
3384 &mr_tm_req
->TmRequest
;
3385 dev_dbg(&instance
->pdev
->dev
, "TM completion:"
3386 "type: 0x%x TaskMID: 0x%x\n",
3387 mpi_tm_req
->TaskType
, mpi_tm_req
->TaskMID
);
3388 complete(&cmd_fusion
->done
);
3390 case MPI2_FUNCTION_SCSI_IO_REQUEST
: /*Fast Path IO.*/
3391 /* Update load balancing info */
3392 if (fusion
->load_balance_info
&&
3393 (cmd_fusion
->scmd
->SCp
.Status
&
3394 MEGASAS_LOAD_BALANCE_FLAG
)) {
3395 device_id
= MEGASAS_DEV_INDEX(scmd_local
);
3396 lbinfo
= &fusion
->load_balance_info
[device_id
];
3397 atomic_dec(&lbinfo
->scsi_pending_cmds
[cmd_fusion
->pd_r1_lb
]);
3398 cmd_fusion
->scmd
->SCp
.Status
&= ~MEGASAS_LOAD_BALANCE_FLAG
;
3400 //Fall thru and complete IO
3401 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST
: /* LD-IO Path */
3402 atomic_dec(&instance
->fw_outstanding
);
3403 if (cmd_fusion
->r1_alt_dev_handle
== MR_DEVHANDLE_INVALID
) {
3404 map_cmd_status(fusion
, scmd_local
, status
,
3405 extStatus
, le32_to_cpu(data_length
),
3407 if (instance
->ldio_threshold
&&
3408 (megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
))
3409 atomic_dec(&instance
->ldio_outstanding
);
3410 scmd_local
->SCp
.ptr
= NULL
;
3411 megasas_return_cmd_fusion(instance
, cmd_fusion
);
3412 scsi_dma_unmap(scmd_local
);
3413 scmd_local
->scsi_done(scmd_local
);
3414 } else /* Optimal VD - R1 FP command completion. */
3415 megasas_complete_r1_command(instance
, cmd_fusion
);
3417 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST
: /*MFI command */
3418 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
3419 /* Poll mode. Dummy free.
3420 * In case of Interrupt mode, caller has reverse check.
3422 if (cmd_mfi
->flags
& DRV_DCMD_POLLED_MODE
) {
3423 cmd_mfi
->flags
&= ~DRV_DCMD_POLLED_MODE
;
3424 megasas_return_cmd(instance
, cmd_mfi
);
3426 megasas_complete_cmd(instance
, cmd_mfi
, DID_OK
);
3430 fusion
->last_reply_idx
[MSIxIndex
]++;
3431 if (fusion
->last_reply_idx
[MSIxIndex
] >=
3432 fusion
->reply_q_depth
)
3433 fusion
->last_reply_idx
[MSIxIndex
] = 0;
3435 desc
->Words
= cpu_to_le64(ULLONG_MAX
);
3437 threshold_reply_count
++;
3439 /* Get the next reply descriptor */
3440 if (!fusion
->last_reply_idx
[MSIxIndex
])
3441 desc
= fusion
->reply_frames_desc
[MSIxIndex
];
3446 (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR
*)desc
;
3448 d_val
.word
= desc
->Words
;
3450 reply_descript_type
= reply_desc
->ReplyFlags
&
3451 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
3453 if (reply_descript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
3456 * Write to reply post host index register after completing threshold
3457 * number of reply counts and still there are more replies in reply queue
3458 * pending to be completed
3460 if (threshold_reply_count
>= THRESHOLD_REPLY_COUNT
) {
3461 if (instance
->msix_combined
)
3462 writel(((MSIxIndex
& 0x7) << 24) |
3463 fusion
->last_reply_idx
[MSIxIndex
],
3464 instance
->reply_post_host_index_addr
[MSIxIndex
/8]);
3466 writel((MSIxIndex
<< 24) |
3467 fusion
->last_reply_idx
[MSIxIndex
],
3468 instance
->reply_post_host_index_addr
[0]);
3469 threshold_reply_count
= 0;
3477 if (instance
->msix_combined
)
3478 writel(((MSIxIndex
& 0x7) << 24) |
3479 fusion
->last_reply_idx
[MSIxIndex
],
3480 instance
->reply_post_host_index_addr
[MSIxIndex
/8]);
3482 writel((MSIxIndex
<< 24) |
3483 fusion
->last_reply_idx
[MSIxIndex
],
3484 instance
->reply_post_host_index_addr
[0]);
3485 megasas_check_and_restore_queue_depth(instance
);
3490 * megasas_sync_irqs - Synchronizes all IRQs owned by adapter
3491 * @instance: Adapter soft state
3493 void megasas_sync_irqs(unsigned long instance_addr
)
3496 struct megasas_instance
*instance
=
3497 (struct megasas_instance
*)instance_addr
;
3499 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
3501 for (i
= 0; i
< count
; i
++)
3502 synchronize_irq(pci_irq_vector(instance
->pdev
, i
));
3506 * megasas_complete_cmd_dpc_fusion - Completes command
3507 * @instance: Adapter soft state
3509 * Tasklet to complete cmds
3512 megasas_complete_cmd_dpc_fusion(unsigned long instance_addr
)
3514 struct megasas_instance
*instance
=
3515 (struct megasas_instance
*)instance_addr
;
3516 unsigned long flags
;
3517 u32 count
, MSIxIndex
;
3519 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
3521 /* If we have already declared adapter dead, donot complete cmds */
3522 spin_lock_irqsave(&instance
->hba_lock
, flags
);
3523 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
3524 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3527 spin_unlock_irqrestore(&instance
->hba_lock
, flags
);
3529 for (MSIxIndex
= 0 ; MSIxIndex
< count
; MSIxIndex
++)
3530 complete_cmd_fusion(instance
, MSIxIndex
);
3534 * megasas_isr_fusion - isr entry point
3536 irqreturn_t
megasas_isr_fusion(int irq
, void *devp
)
3538 struct megasas_irq_context
*irq_context
= devp
;
3539 struct megasas_instance
*instance
= irq_context
->instance
;
3540 u32 mfiStatus
, fw_state
, dma_state
;
3542 if (instance
->mask_interrupts
)
3545 if (!instance
->msix_vectors
) {
3546 mfiStatus
= instance
->instancet
->clear_intr(instance
->reg_set
);
3551 /* If we are resetting, bail */
3552 if (test_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
)) {
3553 instance
->instancet
->clear_intr(instance
->reg_set
);
3557 if (!complete_cmd_fusion(instance
, irq_context
->MSIxIndex
)) {
3558 instance
->instancet
->clear_intr(instance
->reg_set
);
3559 /* If we didn't complete any commands, check for FW fault */
3560 fw_state
= instance
->instancet
->read_fw_status_reg(
3561 instance
->reg_set
) & MFI_STATE_MASK
;
3562 dma_state
= instance
->instancet
->read_fw_status_reg
3563 (instance
->reg_set
) & MFI_STATE_DMADONE
;
3564 if (instance
->crash_dump_drv_support
&&
3565 instance
->crash_dump_app_support
) {
3566 /* Start collecting crash, if DMA bit is done */
3567 if ((fw_state
== MFI_STATE_FAULT
) && dma_state
)
3568 schedule_work(&instance
->crash_init
);
3569 else if (fw_state
== MFI_STATE_FAULT
) {
3570 if (instance
->unload
== 0)
3571 schedule_work(&instance
->work_init
);
3573 } else if (fw_state
== MFI_STATE_FAULT
) {
3574 dev_warn(&instance
->pdev
->dev
, "Iop2SysDoorbellInt"
3575 "for scsi%d\n", instance
->host
->host_no
);
3576 if (instance
->unload
== 0)
3577 schedule_work(&instance
->work_init
);
3585 * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
3586 * @instance: Adapter soft state
3587 * mfi_cmd: megasas_cmd pointer
3591 build_mpt_mfi_pass_thru(struct megasas_instance
*instance
,
3592 struct megasas_cmd
*mfi_cmd
)
3594 struct MPI25_IEEE_SGE_CHAIN64
*mpi25_ieee_chain
;
3595 struct MPI2_RAID_SCSI_IO_REQUEST
*io_req
;
3596 struct megasas_cmd_fusion
*cmd
;
3597 struct fusion_context
*fusion
;
3598 struct megasas_header
*frame_hdr
= &mfi_cmd
->frame
->hdr
;
3600 fusion
= instance
->ctrl_context
;
3602 cmd
= megasas_get_cmd_fusion(instance
,
3603 instance
->max_scsi_cmds
+ mfi_cmd
->index
);
3605 /* Save the smid. To be used for returning the cmd */
3606 mfi_cmd
->context
.smid
= cmd
->index
;
3609 * For cmds where the flag is set, store the flag and check
3610 * on completion. For cmds with this flag, don't call
3611 * megasas_complete_cmd
3614 if (frame_hdr
->flags
& cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE
))
3615 mfi_cmd
->flags
|= DRV_DCMD_POLLED_MODE
;
3617 io_req
= cmd
->io_request
;
3619 if (instance
->adapter_type
>= INVADER_SERIES
) {
3620 struct MPI25_IEEE_SGE_CHAIN64
*sgl_ptr_end
=
3621 (struct MPI25_IEEE_SGE_CHAIN64
*)&io_req
->SGL
;
3622 sgl_ptr_end
+= fusion
->max_sge_in_main_msg
- 1;
3623 sgl_ptr_end
->Flags
= 0;
3627 (struct MPI25_IEEE_SGE_CHAIN64
*)&io_req
->SGL
.IeeeChain
;
3629 io_req
->Function
= MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST
;
3630 io_req
->SGLOffset0
= offsetof(struct MPI2_RAID_SCSI_IO_REQUEST
,
3632 io_req
->ChainOffset
= fusion
->chain_offset_mfi_pthru
;
3634 mpi25_ieee_chain
->Address
= cpu_to_le64(mfi_cmd
->frame_phys_addr
);
3636 mpi25_ieee_chain
->Flags
= IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
3637 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR
;
3639 mpi25_ieee_chain
->Length
= cpu_to_le32(instance
->mfi_frame_size
);
3643 * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
3644 * @instance: Adapter soft state
3645 * @cmd: mfi cmd to build
3648 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*
3649 build_mpt_cmd(struct megasas_instance
*instance
, struct megasas_cmd
*cmd
)
3651 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
= NULL
;
3654 build_mpt_mfi_pass_thru(instance
, cmd
);
3655 index
= cmd
->context
.smid
;
3657 req_desc
= megasas_get_request_descriptor(instance
, index
- 1);
3659 req_desc
->Words
= 0;
3660 req_desc
->SCSIIO
.RequestFlags
= (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
<<
3661 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
3663 req_desc
->SCSIIO
.SMID
= cpu_to_le16(index
);
3669 * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
3670 * @instance: Adapter soft state
3671 * @cmd: mfi cmd pointer
3675 megasas_issue_dcmd_fusion(struct megasas_instance
*instance
,
3676 struct megasas_cmd
*cmd
)
3678 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
3680 req_desc
= build_mpt_cmd(instance
, cmd
);
3682 megasas_fire_cmd_fusion(instance
, req_desc
);
3687 * megasas_release_fusion - Reverses the FW initialization
3688 * @instance: Adapter soft state
3691 megasas_release_fusion(struct megasas_instance
*instance
)
3693 megasas_free_ioc_init_cmd(instance
);
3694 megasas_free_cmds(instance
);
3695 megasas_free_cmds_fusion(instance
);
3697 iounmap(instance
->reg_set
);
3699 pci_release_selected_regions(instance
->pdev
, 1<<instance
->bar
);
3703 * megasas_read_fw_status_reg_fusion - returns the current FW status value
3704 * @regs: MFI register set
3707 megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem
*regs
)
3709 return readl(&(regs
)->outbound_scratch_pad
);
3713 * megasas_alloc_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3714 * @instance: Controller's soft instance
3715 * return: Number of allocated host crash buffers
3718 megasas_alloc_host_crash_buffer(struct megasas_instance
*instance
)
3722 for (i
= 0; i
< MAX_CRASH_DUMP_SIZE
; i
++) {
3723 instance
->crash_buf
[i
] = vzalloc(CRASH_DMA_BUF_SIZE
);
3724 if (!instance
->crash_buf
[i
]) {
3725 dev_info(&instance
->pdev
->dev
, "Firmware crash dump "
3726 "memory allocation failed at index %d\n", i
);
3730 instance
->drv_buf_alloc
= i
;
3734 * megasas_free_host_crash_buffer - Host buffers for Crash dump collection from Firmware
3735 * @instance: Controller's soft instance
3738 megasas_free_host_crash_buffer(struct megasas_instance
*instance
)
3741 for (i
= 0; i
< instance
->drv_buf_alloc
; i
++) {
3742 if (instance
->crash_buf
[i
])
3743 vfree(instance
->crash_buf
[i
]);
3745 instance
->drv_buf_index
= 0;
3746 instance
->drv_buf_alloc
= 0;
3747 instance
->fw_crash_state
= UNAVAILABLE
;
3748 instance
->fw_crash_buffer_size
= 0;
3752 * megasas_adp_reset_fusion - For controller reset
3753 * @regs: MFI register set
3756 megasas_adp_reset_fusion(struct megasas_instance
*instance
,
3757 struct megasas_register_set __iomem
*regs
)
3759 u32 host_diag
, abs_state
, retry
;
3761 /* Now try to reset the chip */
3762 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3763 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3764 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3765 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3766 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3767 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3768 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &instance
->reg_set
->fusion_seq_offset
);
3770 /* Check that the diag write enable (DRWE) bit is on */
3771 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3773 while (!(host_diag
& HOST_DIAG_WRITE_ENABLE
)) {
3775 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3776 if (retry
++ == 100) {
3777 dev_warn(&instance
->pdev
->dev
,
3778 "Host diag unlock failed from %s %d\n",
3779 __func__
, __LINE__
);
3783 if (!(host_diag
& HOST_DIAG_WRITE_ENABLE
))
3786 /* Send chip reset command */
3787 writel(host_diag
| HOST_DIAG_RESET_ADAPTER
,
3788 &instance
->reg_set
->fusion_host_diag
);
3791 /* Make sure reset adapter bit is cleared */
3792 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3794 while (host_diag
& HOST_DIAG_RESET_ADAPTER
) {
3796 host_diag
= readl(&instance
->reg_set
->fusion_host_diag
);
3797 if (retry
++ == 1000) {
3798 dev_warn(&instance
->pdev
->dev
,
3799 "Diag reset adapter never cleared %s %d\n",
3800 __func__
, __LINE__
);
3804 if (host_diag
& HOST_DIAG_RESET_ADAPTER
)
3807 abs_state
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
)
3811 while ((abs_state
<= MFI_STATE_FW_INIT
) && (retry
++ < 1000)) {
3813 abs_state
= instance
->instancet
->
3814 read_fw_status_reg(instance
->reg_set
) & MFI_STATE_MASK
;
3816 if (abs_state
<= MFI_STATE_FW_INIT
) {
3817 dev_warn(&instance
->pdev
->dev
,
3818 "fw state < MFI_STATE_FW_INIT, state = 0x%x %s %d\n",
3819 abs_state
, __func__
, __LINE__
);
3827 * megasas_check_reset_fusion - For controller reset check
3828 * @regs: MFI register set
3831 megasas_check_reset_fusion(struct megasas_instance
*instance
,
3832 struct megasas_register_set __iomem
*regs
)
3837 /* This function waits for outstanding commands on fusion to complete */
3838 int megasas_wait_for_outstanding_fusion(struct megasas_instance
*instance
,
3839 int reason
, int *convert
)
3841 int i
, outstanding
, retval
= 0, hb_seconds_missed
= 0;
3844 for (i
= 0; i
< resetwaittime
; i
++) {
3845 /* Check if firmware is in fault state */
3846 fw_state
= instance
->instancet
->read_fw_status_reg(
3847 instance
->reg_set
) & MFI_STATE_MASK
;
3848 if (fw_state
== MFI_STATE_FAULT
) {
3849 dev_warn(&instance
->pdev
->dev
, "Found FW in FAULT state,"
3850 " will reset adapter scsi%d.\n",
3851 instance
->host
->host_no
);
3852 megasas_complete_cmd_dpc_fusion((unsigned long)instance
);
3853 if (instance
->requestorId
&& reason
) {
3854 dev_warn(&instance
->pdev
->dev
, "SR-IOV Found FW in FAULT"
3855 " state while polling during"
3856 " I/O timeout handling for %d\n",
3857 instance
->host
->host_no
);
3865 if (reason
== MFI_IO_TIMEOUT_OCR
) {
3866 dev_info(&instance
->pdev
->dev
,
3867 "MFI IO is timed out, initiating OCR\n");
3868 megasas_complete_cmd_dpc_fusion((unsigned long)instance
);
3873 /* If SR-IOV VF mode & heartbeat timeout, don't wait */
3874 if (instance
->requestorId
&& !reason
) {
3879 /* If SR-IOV VF mode & I/O timeout, check for HB timeout */
3880 if (instance
->requestorId
&& (reason
== SCSIIO_TIMEOUT_OCR
)) {
3881 if (instance
->hb_host_mem
->HB
.fwCounter
!=
3882 instance
->hb_host_mem
->HB
.driverCounter
) {
3883 instance
->hb_host_mem
->HB
.driverCounter
=
3884 instance
->hb_host_mem
->HB
.fwCounter
;
3885 hb_seconds_missed
= 0;
3887 hb_seconds_missed
++;
3888 if (hb_seconds_missed
==
3889 (MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF
/HZ
)) {
3890 dev_warn(&instance
->pdev
->dev
, "SR-IOV:"
3891 " Heartbeat never completed "
3892 " while polling during I/O "
3893 " timeout handling for "
3895 instance
->host
->host_no
);
3903 megasas_complete_cmd_dpc_fusion((unsigned long)instance
);
3904 outstanding
= atomic_read(&instance
->fw_outstanding
);
3908 if (!(i
% MEGASAS_RESET_NOTICE_INTERVAL
)) {
3909 dev_notice(&instance
->pdev
->dev
, "[%2d]waiting for %d "
3910 "commands to complete for scsi%d\n", i
,
3911 outstanding
, instance
->host
->host_no
);
3916 if (atomic_read(&instance
->fw_outstanding
)) {
3917 dev_err(&instance
->pdev
->dev
, "pending commands remain after waiting, "
3918 "will reset adapter scsi%d.\n",
3919 instance
->host
->host_no
);
3927 void megasas_reset_reply_desc(struct megasas_instance
*instance
)
3930 struct fusion_context
*fusion
;
3931 union MPI2_REPLY_DESCRIPTORS_UNION
*reply_desc
;
3933 fusion
= instance
->ctrl_context
;
3934 count
= instance
->msix_vectors
> 0 ? instance
->msix_vectors
: 1;
3935 for (i
= 0 ; i
< count
; i
++) {
3936 fusion
->last_reply_idx
[i
] = 0;
3937 reply_desc
= fusion
->reply_frames_desc
[i
];
3938 for (j
= 0 ; j
< fusion
->reply_q_depth
; j
++, reply_desc
++)
3939 reply_desc
->Words
= cpu_to_le64(ULLONG_MAX
);
3944 * megasas_refire_mgmt_cmd : Re-fire management commands
3945 * @instance: Controller's soft instance
3947 void megasas_refire_mgmt_cmd(struct megasas_instance
*instance
)
3950 struct megasas_cmd_fusion
*cmd_fusion
;
3951 struct fusion_context
*fusion
;
3952 struct megasas_cmd
*cmd_mfi
;
3953 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
3955 bool refire_cmd
= 0;
3957 fusion
= instance
->ctrl_context
;
3959 /* Re-fire management commands.
3960 * Do not traverse complet MPT frame pool. Start from max_scsi_cmds.
3962 for (j
= instance
->max_scsi_cmds
; j
< instance
->max_fw_cmds
; j
++) {
3963 cmd_fusion
= fusion
->cmd_list
[j
];
3964 cmd_mfi
= instance
->cmd_list
[cmd_fusion
->sync_cmd_idx
];
3965 smid
= le16_to_cpu(cmd_mfi
->context
.smid
);
3970 /* Do not refire shutdown command */
3971 if (le32_to_cpu(cmd_mfi
->frame
->dcmd
.opcode
) ==
3972 MR_DCMD_CTRL_SHUTDOWN
) {
3973 cmd_mfi
->frame
->dcmd
.cmd_status
= MFI_STAT_OK
;
3974 megasas_complete_cmd(instance
, cmd_mfi
, DID_OK
);
3978 req_desc
= megasas_get_request_descriptor
3979 (instance
, smid
- 1);
3980 refire_cmd
= req_desc
&& ((cmd_mfi
->frame
->dcmd
.opcode
!=
3981 cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO
)) &&
3982 (cmd_mfi
->frame
->dcmd
.opcode
!=
3983 cpu_to_le32(MR_DCMD_SYSTEM_PD_MAP_GET_INFO
)))
3984 && !(cmd_mfi
->flags
& DRV_DCMD_SKIP_REFIRE
);
3986 megasas_fire_cmd_fusion(instance
, req_desc
);
3988 megasas_return_cmd(instance
, cmd_mfi
);
3993 * megasas_track_scsiio : Track SCSI IOs outstanding to a SCSI device
3994 * @instance: per adapter struct
3995 * @channel: the channel assigned by the OS
3996 * @id: the id assigned by the OS
3998 * Returns SUCCESS if no IOs pending to SCSI device, else return FAILED
4001 static int megasas_track_scsiio(struct megasas_instance
*instance
,
4002 int id
, int channel
)
4005 struct megasas_cmd_fusion
*cmd_fusion
;
4006 struct fusion_context
*fusion
;
4007 fusion
= instance
->ctrl_context
;
4009 for (i
= 0 ; i
< instance
->max_scsi_cmds
; i
++) {
4010 cmd_fusion
= fusion
->cmd_list
[i
];
4011 if (cmd_fusion
->scmd
&&
4012 (cmd_fusion
->scmd
->device
->id
== id
&&
4013 cmd_fusion
->scmd
->device
->channel
== channel
)) {
4014 dev_info(&instance
->pdev
->dev
,
4015 "SCSI commands pending to target"
4016 "channel %d id %d \tSMID: 0x%x\n",
4017 channel
, id
, cmd_fusion
->index
);
4018 scsi_print_command(cmd_fusion
->scmd
);
4024 return found
? FAILED
: SUCCESS
;
4028 * megasas_tm_response_code - translation of device response code
4029 * @ioc: per adapter object
4030 * @mpi_reply: MPI reply returned by firmware
4035 megasas_tm_response_code(struct megasas_instance
*instance
,
4036 struct MPI2_SCSI_TASK_MANAGE_REPLY
*mpi_reply
)
4040 switch (mpi_reply
->ResponseCode
) {
4041 case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE
:
4042 desc
= "task management request completed";
4044 case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME
:
4045 desc
= "invalid frame";
4047 case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED
:
4048 desc
= "task management request not supported";
4050 case MPI2_SCSITASKMGMT_RSP_TM_FAILED
:
4051 desc
= "task management request failed";
4053 case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED
:
4054 desc
= "task management request succeeded";
4056 case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN
:
4057 desc
= "invalid lun";
4060 desc
= "overlapped tag attempted";
4062 case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC
:
4063 desc
= "task queued, however not sent to target";
4069 dev_dbg(&instance
->pdev
->dev
, "response_code(%01x): %s\n",
4070 mpi_reply
->ResponseCode
, desc
);
4071 dev_dbg(&instance
->pdev
->dev
,
4072 "TerminationCount/DevHandle/Function/TaskType/IOCStat/IOCLoginfo"
4073 " 0x%x/0x%x/0x%x/0x%x/0x%x/0x%x\n",
4074 mpi_reply
->TerminationCount
, mpi_reply
->DevHandle
,
4075 mpi_reply
->Function
, mpi_reply
->TaskType
,
4076 mpi_reply
->IOCStatus
, mpi_reply
->IOCLogInfo
);
4080 * megasas_issue_tm - main routine for sending tm requests
4081 * @instance: per adapter struct
4082 * @device_handle: device handle
4083 * @channel: the channel assigned by the OS
4084 * @id: the id assigned by the OS
4085 * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in megaraid_sas_fusion.c)
4086 * @smid_task: smid assigned to the task
4087 * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
4090 * MegaRaid use MPT interface for Task Magement request.
4091 * A generic API for sending task management requests to firmware.
4093 * Return SUCCESS or FAILED.
4096 megasas_issue_tm(struct megasas_instance
*instance
, u16 device_handle
,
4097 uint channel
, uint id
, u16 smid_task
, u8 type
)
4099 struct MR_TASK_MANAGE_REQUEST
*mr_request
;
4100 struct MPI2_SCSI_TASK_MANAGE_REQUEST
*mpi_request
;
4101 unsigned long timeleft
;
4102 struct megasas_cmd_fusion
*cmd_fusion
;
4103 struct megasas_cmd
*cmd_mfi
;
4104 union MEGASAS_REQUEST_DESCRIPTOR_UNION
*req_desc
;
4105 struct fusion_context
*fusion
= NULL
;
4106 struct megasas_cmd_fusion
*scsi_lookup
;
4108 struct MPI2_SCSI_TASK_MANAGE_REPLY
*mpi_reply
;
4110 fusion
= instance
->ctrl_context
;
4112 cmd_mfi
= megasas_get_cmd(instance
);
4115 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
4116 __func__
, __LINE__
);
4120 cmd_fusion
= megasas_get_cmd_fusion(instance
,
4121 instance
->max_scsi_cmds
+ cmd_mfi
->index
);
4123 /* Save the smid. To be used for returning the cmd */
4124 cmd_mfi
->context
.smid
= cmd_fusion
->index
;
4126 req_desc
= megasas_get_request_descriptor(instance
,
4127 (cmd_fusion
->index
- 1));
4129 cmd_fusion
->request_desc
= req_desc
;
4130 req_desc
->Words
= 0;
4132 mr_request
= (struct MR_TASK_MANAGE_REQUEST
*) cmd_fusion
->io_request
;
4133 memset(mr_request
, 0, sizeof(struct MR_TASK_MANAGE_REQUEST
));
4134 mpi_request
= (struct MPI2_SCSI_TASK_MANAGE_REQUEST
*) &mr_request
->TmRequest
;
4135 mpi_request
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
4136 mpi_request
->DevHandle
= cpu_to_le16(device_handle
);
4137 mpi_request
->TaskType
= type
;
4138 mpi_request
->TaskMID
= cpu_to_le16(smid_task
);
4139 mpi_request
->LUN
[1] = 0;
4142 req_desc
= cmd_fusion
->request_desc
;
4143 req_desc
->HighPriority
.SMID
= cpu_to_le16(cmd_fusion
->index
);
4144 req_desc
->HighPriority
.RequestFlags
=
4145 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
<<
4146 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT
);
4147 req_desc
->HighPriority
.MSIxIndex
= 0;
4148 req_desc
->HighPriority
.LMID
= 0;
4149 req_desc
->HighPriority
.Reserved1
= 0;
4151 if (channel
< MEGASAS_MAX_PD_CHANNELS
)
4152 mr_request
->tmReqFlags
.isTMForPD
= 1;
4154 mr_request
->tmReqFlags
.isTMForLD
= 1;
4156 init_completion(&cmd_fusion
->done
);
4157 megasas_fire_cmd_fusion(instance
, req_desc
);
4159 timeleft
= wait_for_completion_timeout(&cmd_fusion
->done
, 50 * HZ
);
4162 dev_err(&instance
->pdev
->dev
,
4163 "task mgmt type 0x%x timed out\n", type
);
4164 cmd_mfi
->flags
|= DRV_DCMD_SKIP_REFIRE
;
4165 mutex_unlock(&instance
->reset_mutex
);
4166 rc
= megasas_reset_fusion(instance
->host
, MFI_IO_TIMEOUT_OCR
);
4167 mutex_lock(&instance
->reset_mutex
);
4171 mpi_reply
= (struct MPI2_SCSI_TASK_MANAGE_REPLY
*) &mr_request
->TMReply
;
4172 megasas_tm_response_code(instance
, mpi_reply
);
4174 megasas_return_cmd(instance
, cmd_mfi
);
4177 case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
:
4178 scsi_lookup
= fusion
->cmd_list
[smid_task
- 1];
4180 if (scsi_lookup
->scmd
== NULL
)
4183 instance
->instancet
->disable_intr(instance
);
4184 megasas_sync_irqs((unsigned long)instance
);
4185 instance
->instancet
->enable_intr(instance
);
4186 if (scsi_lookup
->scmd
== NULL
)
4192 case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
:
4193 if ((channel
== 0xFFFFFFFF) && (id
== 0xFFFFFFFF))
4195 instance
->instancet
->disable_intr(instance
);
4196 megasas_sync_irqs((unsigned long)instance
);
4197 rc
= megasas_track_scsiio(instance
, id
, channel
);
4198 instance
->instancet
->enable_intr(instance
);
4201 case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET
:
4202 case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
:
4214 * megasas_fusion_smid_lookup : Look for fusion command correpspodning to SCSI
4215 * @instance: per adapter struct
4217 * Return Non Zero index, if SMID found in outstanding commands
4219 static u16
megasas_fusion_smid_lookup(struct scsi_cmnd
*scmd
)
4222 struct megasas_instance
*instance
;
4223 struct megasas_cmd_fusion
*cmd_fusion
;
4224 struct fusion_context
*fusion
;
4226 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
4228 fusion
= instance
->ctrl_context
;
4230 for (i
= 0; i
< instance
->max_scsi_cmds
; i
++) {
4231 cmd_fusion
= fusion
->cmd_list
[i
];
4232 if (cmd_fusion
->scmd
&& (cmd_fusion
->scmd
== scmd
)) {
4233 scmd_printk(KERN_NOTICE
, scmd
, "Abort request is for"
4234 " SMID: %d\n", cmd_fusion
->index
);
4235 ret
= cmd_fusion
->index
;
4244 * megasas_get_tm_devhandle - Get devhandle for TM request
4245 * @sdev- OS provided scsi device
4247 * Returns- devhandle/targetID of SCSI device
4249 static u16
megasas_get_tm_devhandle(struct scsi_device
*sdev
)
4253 struct megasas_instance
*instance
;
4254 struct fusion_context
*fusion
;
4255 struct MR_PD_CFG_SEQ_NUM_SYNC
*pd_sync
;
4256 u16 devhandle
= (u16
)ULONG_MAX
;
4258 instance
= (struct megasas_instance
*)sdev
->host
->hostdata
;
4259 fusion
= instance
->ctrl_context
;
4261 if (!MEGASAS_IS_LOGICAL(sdev
)) {
4262 if (instance
->use_seqnum_jbod_fp
) {
4263 pd_index
= (sdev
->channel
* MEGASAS_MAX_DEV_PER_CHANNEL
)
4265 pd_sync
= (void *)fusion
->pd_seq_sync
4266 [(instance
->pd_seq_map_id
- 1) & 1];
4267 devhandle
= pd_sync
->seq
[pd_index
].devHandle
;
4269 sdev_printk(KERN_ERR
, sdev
, "Firmware expose tmCapable"
4270 " without JBOD MAP support from %s %d\n", __func__
, __LINE__
);
4272 device_id
= ((sdev
->channel
% 2) * MEGASAS_MAX_DEV_PER_CHANNEL
)
4274 devhandle
= device_id
;
4281 * megasas_task_abort_fusion : SCSI task abort function for fusion adapters
4282 * @scmd : pointer to scsi command object
4284 * Return SUCCESS, if command aborted else FAILED
4287 int megasas_task_abort_fusion(struct scsi_cmnd
*scmd
)
4289 struct megasas_instance
*instance
;
4290 u16 smid
, devhandle
;
4291 struct fusion_context
*fusion
;
4293 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
4294 mr_device_priv_data
= scmd
->device
->hostdata
;
4297 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
4298 fusion
= instance
->ctrl_context
;
4300 scmd_printk(KERN_INFO
, scmd
, "task abort called for scmd(%p)\n", scmd
);
4301 scsi_print_command(scmd
);
4303 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
4304 dev_err(&instance
->pdev
->dev
, "Controller is not OPERATIONAL,"
4305 "SCSI host:%d\n", instance
->host
->host_no
);
4310 if (!mr_device_priv_data
) {
4311 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
4312 "scmd(%p)\n", scmd
);
4313 scmd
->result
= DID_NO_CONNECT
<< 16;
4319 if (!mr_device_priv_data
->is_tm_capable
) {
4324 mutex_lock(&instance
->reset_mutex
);
4326 smid
= megasas_fusion_smid_lookup(scmd
);
4330 scmd_printk(KERN_NOTICE
, scmd
, "Command for which abort is"
4331 " issued is not found in oustanding commands\n");
4332 mutex_unlock(&instance
->reset_mutex
);
4336 devhandle
= megasas_get_tm_devhandle(scmd
->device
);
4338 if (devhandle
== (u16
)ULONG_MAX
) {
4340 sdev_printk(KERN_INFO
, scmd
->device
,
4341 "task abort issued for invalid devhandle\n");
4342 mutex_unlock(&instance
->reset_mutex
);
4345 sdev_printk(KERN_INFO
, scmd
->device
,
4346 "attempting task abort! scmd(%p) tm_dev_handle 0x%x\n",
4349 mr_device_priv_data
->tm_busy
= 1;
4350 ret
= megasas_issue_tm(instance
, devhandle
,
4351 scmd
->device
->channel
, scmd
->device
->id
, smid
,
4352 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
);
4353 mr_device_priv_data
->tm_busy
= 0;
4355 mutex_unlock(&instance
->reset_mutex
);
4357 sdev_printk(KERN_INFO
, scmd
->device
, "task abort: %s scmd(%p)\n",
4358 ((ret
== SUCCESS
) ? "SUCCESS" : "FAILED"), scmd
);
4364 * megasas_reset_target_fusion : target reset function for fusion adapters
4365 * scmd: SCSI command pointer
4367 * Returns SUCCESS if all commands associated with target aborted else FAILED
4370 int megasas_reset_target_fusion(struct scsi_cmnd
*scmd
)
4373 struct megasas_instance
*instance
;
4376 struct fusion_context
*fusion
;
4377 struct MR_PRIV_DEVICE
*mr_device_priv_data
;
4378 mr_device_priv_data
= scmd
->device
->hostdata
;
4380 instance
= (struct megasas_instance
*)scmd
->device
->host
->hostdata
;
4381 fusion
= instance
->ctrl_context
;
4383 sdev_printk(KERN_INFO
, scmd
->device
,
4384 "target reset called for scmd(%p)\n", scmd
);
4386 if (atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) {
4387 dev_err(&instance
->pdev
->dev
, "Controller is not OPERATIONAL,"
4388 "SCSI host:%d\n", instance
->host
->host_no
);
4393 if (!mr_device_priv_data
) {
4394 sdev_printk(KERN_INFO
, scmd
->device
, "device been deleted! "
4395 "scmd(%p)\n", scmd
);
4396 scmd
->result
= DID_NO_CONNECT
<< 16;
4402 if (!mr_device_priv_data
->is_tm_capable
) {
4407 mutex_lock(&instance
->reset_mutex
);
4408 devhandle
= megasas_get_tm_devhandle(scmd
->device
);
4410 if (devhandle
== (u16
)ULONG_MAX
) {
4412 sdev_printk(KERN_INFO
, scmd
->device
,
4413 "target reset issued for invalid devhandle\n");
4414 mutex_unlock(&instance
->reset_mutex
);
4418 sdev_printk(KERN_INFO
, scmd
->device
,
4419 "attempting target reset! scmd(%p) tm_dev_handle 0x%x\n",
4421 mr_device_priv_data
->tm_busy
= 1;
4422 ret
= megasas_issue_tm(instance
, devhandle
,
4423 scmd
->device
->channel
, scmd
->device
->id
, 0,
4424 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
);
4425 mr_device_priv_data
->tm_busy
= 0;
4426 mutex_unlock(&instance
->reset_mutex
);
4428 scmd_printk(KERN_NOTICE
, scmd
, "megasas: target reset %s!!\n",
4429 (ret
== SUCCESS
) ? "SUCCESS" : "FAILED");
4434 /*SRIOV get other instance in cluster if any*/
4435 struct megasas_instance
*megasas_get_peer_instance(struct megasas_instance
*instance
)
4439 for (i
= 0; i
< MAX_MGMT_ADAPTERS
; i
++) {
4440 if (megasas_mgmt_info
.instance
[i
] &&
4441 (megasas_mgmt_info
.instance
[i
] != instance
) &&
4442 megasas_mgmt_info
.instance
[i
]->requestorId
&&
4443 megasas_mgmt_info
.instance
[i
]->peerIsPresent
&&
4444 (memcmp((megasas_mgmt_info
.instance
[i
]->clusterId
),
4445 instance
->clusterId
, MEGASAS_CLUSTER_ID_SIZE
) == 0))
4446 return megasas_mgmt_info
.instance
[i
];
4451 /* Check for a second path that is currently UP */
4452 int megasas_check_mpio_paths(struct megasas_instance
*instance
,
4453 struct scsi_cmnd
*scmd
)
4455 struct megasas_instance
*peer_instance
= NULL
;
4456 int retval
= (DID_REQUEUE
<< 16);
4458 if (instance
->peerIsPresent
) {
4459 peer_instance
= megasas_get_peer_instance(instance
);
4460 if ((peer_instance
) &&
4461 (atomic_read(&peer_instance
->adprecovery
) ==
4462 MEGASAS_HBA_OPERATIONAL
))
4463 retval
= (DID_NO_CONNECT
<< 16);
4468 /* Core fusion reset function */
4469 int megasas_reset_fusion(struct Scsi_Host
*shost
, int reason
)
4471 int retval
= SUCCESS
, i
, j
, convert
= 0;
4472 struct megasas_instance
*instance
;
4473 struct megasas_cmd_fusion
*cmd_fusion
, *r1_cmd
;
4474 struct fusion_context
*fusion
;
4475 u32 abs_state
, status_reg
, reset_adapter
;
4476 u32 io_timeout_in_crash_mode
= 0;
4477 struct scsi_cmnd
*scmd_local
= NULL
;
4478 struct scsi_device
*sdev
;
4480 instance
= (struct megasas_instance
*)shost
->hostdata
;
4481 fusion
= instance
->ctrl_context
;
4483 mutex_lock(&instance
->reset_mutex
);
4485 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HW_CRITICAL_ERROR
) {
4486 dev_warn(&instance
->pdev
->dev
, "Hardware critical error, "
4487 "returning FAILED for scsi%d.\n",
4488 instance
->host
->host_no
);
4489 mutex_unlock(&instance
->reset_mutex
);
4492 status_reg
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
);
4493 abs_state
= status_reg
& MFI_STATE_MASK
;
4495 /* IO timeout detected, forcibly put FW in FAULT state */
4496 if (abs_state
!= MFI_STATE_FAULT
&& instance
->crash_dump_buf
&&
4497 instance
->crash_dump_app_support
&& reason
) {
4498 dev_info(&instance
->pdev
->dev
, "IO/DCMD timeout is detected, "
4499 "forcibly FAULT Firmware\n");
4500 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
4501 status_reg
= readl(&instance
->reg_set
->doorbell
);
4502 writel(status_reg
| MFI_STATE_FORCE_OCR
,
4503 &instance
->reg_set
->doorbell
);
4504 readl(&instance
->reg_set
->doorbell
);
4505 mutex_unlock(&instance
->reset_mutex
);
4508 io_timeout_in_crash_mode
++;
4509 dev_dbg(&instance
->pdev
->dev
, "waiting for [%d] "
4510 "seconds for crash dump collection and OCR "
4511 "to be done\n", (io_timeout_in_crash_mode
* 3));
4512 } while ((atomic_read(&instance
->adprecovery
) != MEGASAS_HBA_OPERATIONAL
) &&
4513 (io_timeout_in_crash_mode
< 80));
4515 if (atomic_read(&instance
->adprecovery
) == MEGASAS_HBA_OPERATIONAL
) {
4516 dev_info(&instance
->pdev
->dev
, "OCR done for IO "
4520 dev_info(&instance
->pdev
->dev
, "Controller is not "
4521 "operational after 240 seconds wait for IO "
4522 "timeout case in FW crash dump mode\n do "
4523 "OCR/kill adapter\n");
4524 retval
= megasas_reset_fusion(shost
, 0);
4529 if (instance
->requestorId
&& !instance
->skip_heartbeat_timer_del
)
4530 del_timer_sync(&instance
->sriov_heartbeat_timer
);
4531 set_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
4532 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_POLLING
);
4533 instance
->instancet
->disable_intr(instance
);
4534 megasas_sync_irqs((unsigned long)instance
);
4536 /* First try waiting for commands to complete */
4537 if (megasas_wait_for_outstanding_fusion(instance
, reason
,
4539 atomic_set(&instance
->adprecovery
, MEGASAS_ADPRESET_SM_INFAULT
);
4540 dev_warn(&instance
->pdev
->dev
, "resetting fusion "
4541 "adapter scsi%d.\n", instance
->host
->host_no
);
4545 if (megasas_dbg_lvl
& OCR_LOGS
)
4546 dev_info(&instance
->pdev
->dev
, "\nPending SCSI commands:\n");
4548 /* Now return commands back to the OS */
4549 for (i
= 0 ; i
< instance
->max_scsi_cmds
; i
++) {
4550 cmd_fusion
= fusion
->cmd_list
[i
];
4551 /*check for extra commands issued by driver*/
4552 if (instance
->adapter_type
== VENTURA_SERIES
) {
4553 r1_cmd
= fusion
->cmd_list
[i
+ instance
->max_fw_cmds
];
4554 megasas_return_cmd_fusion(instance
, r1_cmd
);
4556 scmd_local
= cmd_fusion
->scmd
;
4557 if (cmd_fusion
->scmd
) {
4558 if (megasas_dbg_lvl
& OCR_LOGS
) {
4559 sdev_printk(KERN_INFO
,
4560 cmd_fusion
->scmd
->device
, "SMID: 0x%x\n",
4562 scsi_print_command(cmd_fusion
->scmd
);
4565 scmd_local
->result
=
4566 megasas_check_mpio_paths(instance
,
4568 if (instance
->ldio_threshold
&&
4569 megasas_cmd_type(scmd_local
) == READ_WRITE_LDIO
)
4570 atomic_dec(&instance
->ldio_outstanding
);
4571 megasas_return_cmd_fusion(instance
, cmd_fusion
);
4572 scsi_dma_unmap(scmd_local
);
4573 scmd_local
->scsi_done(scmd_local
);
4577 atomic_set(&instance
->fw_outstanding
, 0);
4579 status_reg
= instance
->instancet
->read_fw_status_reg(
4581 abs_state
= status_reg
& MFI_STATE_MASK
;
4582 reset_adapter
= status_reg
& MFI_RESET_ADAPTER
;
4583 if (instance
->disableOnlineCtrlReset
||
4584 (abs_state
== MFI_STATE_FAULT
&& !reset_adapter
)) {
4585 /* Reset not supported, kill adapter */
4586 dev_warn(&instance
->pdev
->dev
, "Reset not supported"
4587 ", killing adapter scsi%d.\n",
4588 instance
->host
->host_no
);
4589 megaraid_sas_kill_hba(instance
);
4590 instance
->skip_heartbeat_timer_del
= 1;
4595 /* Let SR-IOV VF & PF sync up if there was a HB failure */
4596 if (instance
->requestorId
&& !reason
) {
4597 msleep(MEGASAS_OCR_SETTLE_TIME_VF
);
4598 goto transition_to_ready
;
4601 /* Now try to reset the chip */
4602 for (i
= 0; i
< MEGASAS_FUSION_MAX_RESET_TRIES
; i
++) {
4604 if (instance
->instancet
->adp_reset
4605 (instance
, instance
->reg_set
))
4607 transition_to_ready
:
4608 /* Wait for FW to become ready */
4609 if (megasas_transition_to_ready(instance
, 1)) {
4610 dev_warn(&instance
->pdev
->dev
,
4611 "Failed to transition controller to ready for "
4612 "scsi%d.\n", instance
->host
->host_no
);
4613 if (instance
->requestorId
&& !reason
)
4614 goto fail_kill_adapter
;
4618 megasas_reset_reply_desc(instance
);
4619 megasas_fusion_update_can_queue(instance
, OCR_CONTEXT
);
4621 if (megasas_ioc_init_fusion(instance
)) {
4622 if (instance
->requestorId
&& !reason
)
4623 goto fail_kill_adapter
;
4628 megasas_refire_mgmt_cmd(instance
);
4630 if (megasas_get_ctrl_info(instance
)) {
4631 dev_info(&instance
->pdev
->dev
,
4632 "Failed from %s %d\n",
4633 __func__
, __LINE__
);
4634 megaraid_sas_kill_hba(instance
);
4638 /* Reset load balance info */
4639 if (fusion
->load_balance_info
)
4640 memset(fusion
->load_balance_info
, 0,
4641 (sizeof(struct LD_LOAD_BALANCE_INFO
) *
4642 MAX_LOGICAL_DRIVES_EXT
));
4644 if (!megasas_get_map_info(instance
))
4645 megasas_sync_map_info(instance
);
4647 megasas_setup_jbod_map(instance
);
4649 shost_for_each_device(sdev
, shost
)
4650 megasas_set_dynamic_target_properties(sdev
);
4652 /* reset stream detection array */
4653 if (instance
->adapter_type
== VENTURA_SERIES
) {
4654 for (j
= 0; j
< MAX_LOGICAL_DRIVES_EXT
; ++j
) {
4655 memset(fusion
->stream_detect_by_ld
[j
],
4656 0, sizeof(struct LD_STREAM_DETECT
));
4657 fusion
->stream_detect_by_ld
[j
]->mru_bit_map
4662 clear_bit(MEGASAS_FUSION_IN_RESET
,
4663 &instance
->reset_flags
);
4664 instance
->instancet
->enable_intr(instance
);
4665 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
4667 dev_info(&instance
->pdev
->dev
, "Interrupts are enabled and"
4668 " controller is OPERATIONAL for scsi:%d\n",
4669 instance
->host
->host_no
);
4671 /* Restart SR-IOV heartbeat */
4672 if (instance
->requestorId
) {
4673 if (!megasas_sriov_start_heartbeat(instance
, 0))
4674 megasas_start_timer(instance
);
4676 instance
->skip_heartbeat_timer_del
= 1;
4679 if (instance
->crash_dump_drv_support
&&
4680 instance
->crash_dump_app_support
)
4681 megasas_set_crash_dump_params(instance
,
4682 MR_CRASH_BUF_TURN_ON
);
4684 megasas_set_crash_dump_params(instance
,
4685 MR_CRASH_BUF_TURN_OFF
);
4689 /* Adapter reset completed successfully */
4690 dev_warn(&instance
->pdev
->dev
,
4691 "Reset successful for scsi%d.\n",
4692 instance
->host
->host_no
);
4697 /* Reset failed, kill the adapter */
4698 dev_warn(&instance
->pdev
->dev
, "Reset failed, killing "
4699 "adapter scsi%d.\n", instance
->host
->host_no
);
4700 megaraid_sas_kill_hba(instance
);
4701 instance
->skip_heartbeat_timer_del
= 1;
4704 /* For VF: Restart HB timer if we didn't OCR */
4705 if (instance
->requestorId
) {
4706 megasas_start_timer(instance
);
4708 clear_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
4709 instance
->instancet
->enable_intr(instance
);
4710 atomic_set(&instance
->adprecovery
, MEGASAS_HBA_OPERATIONAL
);
4713 clear_bit(MEGASAS_FUSION_IN_RESET
, &instance
->reset_flags
);
4714 mutex_unlock(&instance
->reset_mutex
);
4718 /* Fusion Crash dump collection work queue */
4719 void megasas_fusion_crash_dump_wq(struct work_struct
*work
)
4721 struct megasas_instance
*instance
=
4722 container_of(work
, struct megasas_instance
, crash_init
);
4724 u8 partial_copy
= 0;
4727 status_reg
= instance
->instancet
->read_fw_status_reg(instance
->reg_set
);
4730 * Allocate host crash buffers to copy data from 1 MB DMA crash buffer
4731 * to host crash buffers
4733 if (instance
->drv_buf_index
== 0) {
4734 /* Buffer is already allocated for old Crash dump.
4735 * Do OCR and do not wait for crash dump collection
4737 if (instance
->drv_buf_alloc
) {
4738 dev_info(&instance
->pdev
->dev
, "earlier crash dump is "
4739 "not yet copied by application, ignoring this "
4740 "crash dump and initiating OCR\n");
4741 status_reg
|= MFI_STATE_CRASH_DUMP_DONE
;
4743 &instance
->reg_set
->outbound_scratch_pad
);
4744 readl(&instance
->reg_set
->outbound_scratch_pad
);
4747 megasas_alloc_host_crash_buffer(instance
);
4748 dev_info(&instance
->pdev
->dev
, "Number of host crash buffers "
4749 "allocated: %d\n", instance
->drv_buf_alloc
);
4753 * Driver has allocated max buffers, which can be allocated
4754 * and FW has more crash dump data, then driver will
4757 if (instance
->drv_buf_index
>= (instance
->drv_buf_alloc
)) {
4758 dev_info(&instance
->pdev
->dev
, "Driver is done copying "
4759 "the buffer: %d\n", instance
->drv_buf_alloc
);
4760 status_reg
|= MFI_STATE_CRASH_DUMP_DONE
;
4763 memcpy(instance
->crash_buf
[instance
->drv_buf_index
],
4764 instance
->crash_dump_buf
, CRASH_DMA_BUF_SIZE
);
4765 instance
->drv_buf_index
++;
4766 status_reg
&= ~MFI_STATE_DMADONE
;
4769 if (status_reg
& MFI_STATE_CRASH_DUMP_DONE
) {
4770 dev_info(&instance
->pdev
->dev
, "Crash Dump is available,number "
4771 "of copied buffers: %d\n", instance
->drv_buf_index
);
4772 instance
->fw_crash_buffer_size
= instance
->drv_buf_index
;
4773 instance
->fw_crash_state
= AVAILABLE
;
4774 instance
->drv_buf_index
= 0;
4775 writel(status_reg
, &instance
->reg_set
->outbound_scratch_pad
);
4776 readl(&instance
->reg_set
->outbound_scratch_pad
);
4778 megasas_reset_fusion(instance
->host
, 0);
4780 writel(status_reg
, &instance
->reg_set
->outbound_scratch_pad
);
4781 readl(&instance
->reg_set
->outbound_scratch_pad
);
4786 /* Fusion OCR work queue */
4787 void megasas_fusion_ocr_wq(struct work_struct
*work
)
4789 struct megasas_instance
*instance
=
4790 container_of(work
, struct megasas_instance
, work_init
);
4792 megasas_reset_fusion(instance
->host
, 0);
4795 /* Allocate fusion context */
4797 megasas_alloc_fusion_context(struct megasas_instance
*instance
)
4799 struct fusion_context
*fusion
;
4801 instance
->ctrl_context
= kzalloc(sizeof(struct fusion_context
),
4803 if (!instance
->ctrl_context
) {
4804 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
4805 __func__
, __LINE__
);
4809 fusion
= instance
->ctrl_context
;
4811 fusion
->log_to_span_pages
= get_order(MAX_LOGICAL_DRIVES_EXT
*
4812 sizeof(LD_SPAN_INFO
));
4813 fusion
->log_to_span
=
4814 (PLD_SPAN_INFO
)__get_free_pages(GFP_KERNEL
| __GFP_ZERO
,
4815 fusion
->log_to_span_pages
);
4816 if (!fusion
->log_to_span
) {
4817 fusion
->log_to_span
= vzalloc(MAX_LOGICAL_DRIVES_EXT
*
4818 sizeof(LD_SPAN_INFO
));
4819 if (!fusion
->log_to_span
) {
4820 dev_err(&instance
->pdev
->dev
, "Failed from %s %d\n",
4821 __func__
, __LINE__
);
4826 fusion
->load_balance_info_pages
= get_order(MAX_LOGICAL_DRIVES_EXT
*
4827 sizeof(struct LD_LOAD_BALANCE_INFO
));
4828 fusion
->load_balance_info
=
4829 (struct LD_LOAD_BALANCE_INFO
*)__get_free_pages(GFP_KERNEL
| __GFP_ZERO
,
4830 fusion
->load_balance_info_pages
);
4831 if (!fusion
->load_balance_info
) {
4832 fusion
->load_balance_info
= vzalloc(MAX_LOGICAL_DRIVES_EXT
*
4833 sizeof(struct LD_LOAD_BALANCE_INFO
));
4834 if (!fusion
->load_balance_info
)
4835 dev_err(&instance
->pdev
->dev
, "Failed to allocate load_balance_info, "
4836 "continuing without Load Balance support\n");
4843 megasas_free_fusion_context(struct megasas_instance
*instance
)
4845 struct fusion_context
*fusion
= instance
->ctrl_context
;
4848 if (fusion
->load_balance_info
) {
4849 if (is_vmalloc_addr(fusion
->load_balance_info
))
4850 vfree(fusion
->load_balance_info
);
4852 free_pages((ulong
)fusion
->load_balance_info
,
4853 fusion
->load_balance_info_pages
);
4856 if (fusion
->log_to_span
) {
4857 if (is_vmalloc_addr(fusion
->log_to_span
))
4858 vfree(fusion
->log_to_span
);
4860 free_pages((ulong
)fusion
->log_to_span
,
4861 fusion
->log_to_span_pages
);
4868 struct megasas_instance_template megasas_instance_template_fusion
= {
4869 .enable_intr
= megasas_enable_intr_fusion
,
4870 .disable_intr
= megasas_disable_intr_fusion
,
4871 .clear_intr
= megasas_clear_intr_fusion
,
4872 .read_fw_status_reg
= megasas_read_fw_status_reg_fusion
,
4873 .adp_reset
= megasas_adp_reset_fusion
,
4874 .check_reset
= megasas_check_reset_fusion
,
4875 .service_isr
= megasas_isr_fusion
,
4876 .tasklet
= megasas_complete_cmd_dpc_fusion
,
4877 .init_adapter
= megasas_init_adapter_fusion
,
4878 .build_and_issue_cmd
= megasas_build_and_issue_cmd_fusion
,
4879 .issue_dcmd
= megasas_issue_dcmd_fusion
,