blob: f77715adf6bd18193fecb6f76fc5b0aeb5a251c9 [file] [log] [blame]
adam radford9c915a82010-12-21 13:34:31 -08001/*
2 * Linux MegaRAID driver for SAS based RAID controllers
3 *
adam radfordae590572012-10-01 19:27:34 -07004 * Copyright (c) 2009-2012 LSI Corporation.
adam radford9c915a82010-12-21 13:34:31 -08005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * FILE: megaraid_sas_fusion.c
21 *
22 * Authors: LSI Corporation
23 * Sumant Patro
24 * Adam Radford <linuxraid@lsi.com>
25 *
26 * Send feedback to: <megaraidlinux@lsi.com>
27 *
28 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035
29 * ATTN: Linuxraid
30 */
31
32#include <linux/kernel.h>
33#include <linux/types.h>
34#include <linux/pci.h>
35#include <linux/list.h>
36#include <linux/moduleparam.h>
37#include <linux/module.h>
38#include <linux/spinlock.h>
39#include <linux/interrupt.h>
40#include <linux/delay.h>
adam radford9c915a82010-12-21 13:34:31 -080041#include <linux/uio.h>
42#include <linux/uaccess.h>
43#include <linux/fs.h>
44#include <linux/compat.h>
45#include <linux/blkdev.h>
46#include <linux/mutex.h>
47#include <linux/poll.h>
48
49#include <scsi/scsi.h>
50#include <scsi/scsi_cmnd.h>
51#include <scsi/scsi_device.h>
52#include <scsi/scsi_host.h>
53
54#include "megaraid_sas_fusion.h"
55#include "megaraid_sas.h"
56
57extern void megasas_free_cmds(struct megasas_instance *instance);
58extern struct megasas_cmd *megasas_get_cmd(struct megasas_instance
59 *instance);
60extern void
61megasas_complete_cmd(struct megasas_instance *instance,
62 struct megasas_cmd *cmd, u8 alt_status);
63int megasas_is_ldio(struct scsi_cmnd *cmd);
64int
65wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd);
66
67void
68megasas_return_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd);
69int megasas_alloc_cmds(struct megasas_instance *instance);
70int
71megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs);
72int
73megasas_issue_polled(struct megasas_instance *instance,
74 struct megasas_cmd *cmd);
adam radford53ef2bb2011-02-24 20:56:05 -080075void
76megasas_check_and_restore_queue_depth(struct megasas_instance *instance);
77
adam radford9c915a82010-12-21 13:34:31 -080078u16 get_updated_dev_handle(struct LD_LOAD_BALANCE_INFO *lbInfo,
79 struct IO_REQUEST_INFO *in_info);
adam radford058a8fa2011-10-08 18:14:27 -070080int megasas_transition_to_ready(struct megasas_instance *instance, int ocr);
adam radford9c915a82010-12-21 13:34:31 -080081void megaraid_sas_kill_hba(struct megasas_instance *instance);
82
83extern u32 megasas_dbg_lvl;
adam radfordc007b8b2012-07-17 18:20:24 -070084extern int resetwaittime;
adam radford9c915a82010-12-21 13:34:31 -080085
86/**
87 * megasas_enable_intr_fusion - Enables interrupts
88 * @regs: MFI register set
89 */
90void
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +053091megasas_enable_intr_fusion(struct megasas_instance *instance)
adam radford9c915a82010-12-21 13:34:31 -080092{
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +053093 struct megasas_register_set __iomem *regs;
94 regs = instance->reg_set;
adam radford6497b242011-10-08 18:14:50 -070095 /* For Thunderbolt/Invader also clear intr on enable */
96 writel(~0, &regs->outbound_intr_status);
97 readl(&regs->outbound_intr_status);
98
adam radford9c915a82010-12-21 13:34:31 -080099 writel(~MFI_FUSION_ENABLE_INTERRUPT_MASK, &(regs)->outbound_intr_mask);
100
101 /* Dummy readl to force pci flush */
102 readl(&regs->outbound_intr_mask);
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +0530103 instance->mask_interrupts = 0;
adam radford9c915a82010-12-21 13:34:31 -0800104}
105
106/**
107 * megasas_disable_intr_fusion - Disables interrupt
108 * @regs: MFI register set
109 */
110void
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +0530111megasas_disable_intr_fusion(struct megasas_instance *instance)
adam radford9c915a82010-12-21 13:34:31 -0800112{
113 u32 mask = 0xFFFFFFFF;
114 u32 status;
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +0530115 struct megasas_register_set __iomem *regs;
116 regs = instance->reg_set;
117 instance->mask_interrupts = 1;
adam radford9c915a82010-12-21 13:34:31 -0800118
119 writel(mask, &regs->outbound_intr_mask);
120 /* Dummy readl to force pci flush */
121 status = readl(&regs->outbound_intr_mask);
122}
123
124int
125megasas_clear_intr_fusion(struct megasas_register_set __iomem *regs)
126{
127 u32 status;
128 /*
129 * Check if it is our interrupt
130 */
131 status = readl(&regs->outbound_intr_status);
132
133 if (status & 1) {
134 writel(status, &regs->outbound_intr_status);
135 readl(&regs->outbound_intr_status);
136 return 1;
137 }
138 if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK))
139 return 0;
140
adam radford9c915a82010-12-21 13:34:31 -0800141 return 1;
142}
143
144/**
145 * megasas_get_cmd_fusion - Get a command from the free pool
146 * @instance: Adapter soft state
147 *
148 * Returns a free command from the pool
149 */
150struct megasas_cmd_fusion *megasas_get_cmd_fusion(struct megasas_instance
151 *instance)
152{
153 unsigned long flags;
154 struct fusion_context *fusion =
155 (struct fusion_context *)instance->ctrl_context;
156 struct megasas_cmd_fusion *cmd = NULL;
157
158 spin_lock_irqsave(&fusion->cmd_pool_lock, flags);
159
160 if (!list_empty(&fusion->cmd_pool)) {
161 cmd = list_entry((&fusion->cmd_pool)->next,
162 struct megasas_cmd_fusion, list);
163 list_del_init(&cmd->list);
164 } else {
165 printk(KERN_ERR "megasas: Command pool (fusion) empty!\n");
166 }
167
168 spin_unlock_irqrestore(&fusion->cmd_pool_lock, flags);
169 return cmd;
170}
171
172/**
173 * megasas_return_cmd_fusion - Return a cmd to free command pool
174 * @instance: Adapter soft state
175 * @cmd: Command packet to be returned to free command pool
176 */
177static inline void
178megasas_return_cmd_fusion(struct megasas_instance *instance,
179 struct megasas_cmd_fusion *cmd)
180{
181 unsigned long flags;
182 struct fusion_context *fusion =
183 (struct fusion_context *)instance->ctrl_context;
184
185 spin_lock_irqsave(&fusion->cmd_pool_lock, flags);
186
187 cmd->scmd = NULL;
188 cmd->sync_cmd_idx = (u32)ULONG_MAX;
189 list_add_tail(&cmd->list, &fusion->cmd_pool);
190
191 spin_unlock_irqrestore(&fusion->cmd_pool_lock, flags);
192}
193
194/**
195 * megasas_teardown_frame_pool_fusion - Destroy the cmd frame DMA pool
196 * @instance: Adapter soft state
197 */
198static void megasas_teardown_frame_pool_fusion(
199 struct megasas_instance *instance)
200{
201 int i;
202 struct fusion_context *fusion = instance->ctrl_context;
203
204 u16 max_cmd = instance->max_fw_cmds;
205
206 struct megasas_cmd_fusion *cmd;
207
208 if (!fusion->sg_dma_pool || !fusion->sense_dma_pool) {
209 printk(KERN_ERR "megasas: dma pool is null. SG Pool %p, "
210 "sense pool : %p\n", fusion->sg_dma_pool,
211 fusion->sense_dma_pool);
212 return;
213 }
214
215 /*
216 * Return all frames to pool
217 */
218 for (i = 0; i < max_cmd; i++) {
219
220 cmd = fusion->cmd_list[i];
221
222 if (cmd->sg_frame)
223 pci_pool_free(fusion->sg_dma_pool, cmd->sg_frame,
224 cmd->sg_frame_phys_addr);
225
226 if (cmd->sense)
227 pci_pool_free(fusion->sense_dma_pool, cmd->sense,
228 cmd->sense_phys_addr);
229 }
230
231 /*
232 * Now destroy the pool itself
233 */
234 pci_pool_destroy(fusion->sg_dma_pool);
235 pci_pool_destroy(fusion->sense_dma_pool);
236
237 fusion->sg_dma_pool = NULL;
238 fusion->sense_dma_pool = NULL;
239}
240
241/**
242 * megasas_free_cmds_fusion - Free all the cmds in the free cmd pool
243 * @instance: Adapter soft state
244 */
245void
246megasas_free_cmds_fusion(struct megasas_instance *instance)
247{
248 int i;
249 struct fusion_context *fusion = instance->ctrl_context;
250
251 u32 max_cmds, req_sz, reply_sz, io_frames_sz;
252
253
254 req_sz = fusion->request_alloc_sz;
255 reply_sz = fusion->reply_alloc_sz;
256 io_frames_sz = fusion->io_frames_alloc_sz;
257
258 max_cmds = instance->max_fw_cmds;
259
260 /* Free descriptors and request Frames memory */
261 if (fusion->req_frames_desc)
262 dma_free_coherent(&instance->pdev->dev, req_sz,
263 fusion->req_frames_desc,
264 fusion->req_frames_desc_phys);
265
266 if (fusion->reply_frames_desc) {
267 pci_pool_free(fusion->reply_frames_desc_pool,
268 fusion->reply_frames_desc,
269 fusion->reply_frames_desc_phys);
270 pci_pool_destroy(fusion->reply_frames_desc_pool);
271 }
272
273 if (fusion->io_request_frames) {
274 pci_pool_free(fusion->io_request_frames_pool,
275 fusion->io_request_frames,
276 fusion->io_request_frames_phys);
277 pci_pool_destroy(fusion->io_request_frames_pool);
278 }
279
280 /* Free the Fusion frame pool */
281 megasas_teardown_frame_pool_fusion(instance);
282
283 /* Free all the commands in the cmd_list */
284 for (i = 0; i < max_cmds; i++)
285 kfree(fusion->cmd_list[i]);
286
287 /* Free the cmd_list buffer itself */
288 kfree(fusion->cmd_list);
289 fusion->cmd_list = NULL;
290
291 INIT_LIST_HEAD(&fusion->cmd_pool);
292}
293
294/**
295 * megasas_create_frame_pool_fusion - Creates DMA pool for cmd frames
296 * @instance: Adapter soft state
297 *
298 */
299static int megasas_create_frame_pool_fusion(struct megasas_instance *instance)
300{
301 int i;
302 u32 max_cmd;
303 struct fusion_context *fusion;
304 struct megasas_cmd_fusion *cmd;
305 u32 total_sz_chain_frame;
306
307 fusion = instance->ctrl_context;
308 max_cmd = instance->max_fw_cmds;
309
310 total_sz_chain_frame = MEGASAS_MAX_SZ_CHAIN_FRAME;
311
312 /*
313 * Use DMA pool facility provided by PCI layer
314 */
315
316 fusion->sg_dma_pool = pci_pool_create("megasas sg pool fusion",
317 instance->pdev,
318 total_sz_chain_frame, 4,
319 0);
320 if (!fusion->sg_dma_pool) {
321 printk(KERN_DEBUG "megasas: failed to setup request pool "
322 "fusion\n");
323 return -ENOMEM;
324 }
325 fusion->sense_dma_pool = pci_pool_create("megasas sense pool fusion",
326 instance->pdev,
327 SCSI_SENSE_BUFFERSIZE, 64, 0);
328
329 if (!fusion->sense_dma_pool) {
330 printk(KERN_DEBUG "megasas: failed to setup sense pool "
331 "fusion\n");
332 pci_pool_destroy(fusion->sg_dma_pool);
333 fusion->sg_dma_pool = NULL;
334 return -ENOMEM;
335 }
336
337 /*
338 * Allocate and attach a frame to each of the commands in cmd_list
339 */
340 for (i = 0; i < max_cmd; i++) {
341
342 cmd = fusion->cmd_list[i];
343
344 cmd->sg_frame = pci_pool_alloc(fusion->sg_dma_pool,
345 GFP_KERNEL,
346 &cmd->sg_frame_phys_addr);
347
348 cmd->sense = pci_pool_alloc(fusion->sense_dma_pool,
349 GFP_KERNEL, &cmd->sense_phys_addr);
350 /*
351 * megasas_teardown_frame_pool_fusion() takes care of freeing
352 * whatever has been allocated
353 */
354 if (!cmd->sg_frame || !cmd->sense) {
355 printk(KERN_DEBUG "megasas: pci_pool_alloc failed\n");
356 megasas_teardown_frame_pool_fusion(instance);
357 return -ENOMEM;
358 }
359 }
360 return 0;
361}
362
363/**
364 * megasas_alloc_cmds_fusion - Allocates the command packets
365 * @instance: Adapter soft state
366 *
367 *
368 * Each frame has a 32-bit field called context. This context is used to get
369 * back the megasas_cmd_fusion from the frame when a frame gets completed
370 * In this driver, the 32 bit values are the indices into an array cmd_list.
371 * This array is used only to look up the megasas_cmd_fusion given the context.
372 * The free commands themselves are maintained in a linked list called cmd_pool.
373 *
374 * cmds are formed in the io_request and sg_frame members of the
375 * megasas_cmd_fusion. The context field is used to get a request descriptor
376 * and is used as SMID of the cmd.
377 * SMID value range is from 1 to max_fw_cmds.
378 */
379int
380megasas_alloc_cmds_fusion(struct megasas_instance *instance)
381{
adam radfordc8e858f2011-10-08 18:15:13 -0700382 int i, j, count;
adam radford9c915a82010-12-21 13:34:31 -0800383 u32 max_cmd, io_frames_sz;
384 struct fusion_context *fusion;
385 struct megasas_cmd_fusion *cmd;
386 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
387 u32 offset;
388 dma_addr_t io_req_base_phys;
389 u8 *io_req_base;
390
391 fusion = instance->ctrl_context;
392
393 max_cmd = instance->max_fw_cmds;
394
395 fusion->req_frames_desc =
396 dma_alloc_coherent(&instance->pdev->dev,
397 fusion->request_alloc_sz,
398 &fusion->req_frames_desc_phys, GFP_KERNEL);
399
400 if (!fusion->req_frames_desc) {
401 printk(KERN_ERR "megasas; Could not allocate memory for "
402 "request_frames\n");
403 goto fail_req_desc;
404 }
405
adam radfordc8e858f2011-10-08 18:15:13 -0700406 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
adam radford9c915a82010-12-21 13:34:31 -0800407 fusion->reply_frames_desc_pool =
408 pci_pool_create("reply_frames pool", instance->pdev,
adam radfordc8e858f2011-10-08 18:15:13 -0700409 fusion->reply_alloc_sz * count, 16, 0);
adam radford9c915a82010-12-21 13:34:31 -0800410
411 if (!fusion->reply_frames_desc_pool) {
412 printk(KERN_ERR "megasas; Could not allocate memory for "
413 "reply_frame pool\n");
414 goto fail_reply_desc;
415 }
416
417 fusion->reply_frames_desc =
418 pci_pool_alloc(fusion->reply_frames_desc_pool, GFP_KERNEL,
419 &fusion->reply_frames_desc_phys);
420 if (!fusion->reply_frames_desc) {
421 printk(KERN_ERR "megasas; Could not allocate memory for "
422 "reply_frame pool\n");
423 pci_pool_destroy(fusion->reply_frames_desc_pool);
424 goto fail_reply_desc;
425 }
426
427 reply_desc = fusion->reply_frames_desc;
adam radfordc8e858f2011-10-08 18:15:13 -0700428 for (i = 0; i < fusion->reply_q_depth * count; i++, reply_desc++)
adam radford9c915a82010-12-21 13:34:31 -0800429 reply_desc->Words = ULLONG_MAX;
430
431 io_frames_sz = fusion->io_frames_alloc_sz;
432
433 fusion->io_request_frames_pool =
434 pci_pool_create("io_request_frames pool", instance->pdev,
435 fusion->io_frames_alloc_sz, 16, 0);
436
437 if (!fusion->io_request_frames_pool) {
438 printk(KERN_ERR "megasas: Could not allocate memory for "
439 "io_request_frame pool\n");
440 goto fail_io_frames;
441 }
442
443 fusion->io_request_frames =
444 pci_pool_alloc(fusion->io_request_frames_pool, GFP_KERNEL,
445 &fusion->io_request_frames_phys);
446 if (!fusion->io_request_frames) {
447 printk(KERN_ERR "megasas: Could not allocate memory for "
448 "io_request_frames frames\n");
449 pci_pool_destroy(fusion->io_request_frames_pool);
450 goto fail_io_frames;
451 }
452
453 /*
454 * fusion->cmd_list is an array of struct megasas_cmd_fusion pointers.
455 * Allocate the dynamic array first and then allocate individual
456 * commands.
457 */
Fengguang Wu7731e6b2012-08-24 23:27:35 +0800458 fusion->cmd_list = kzalloc(sizeof(struct megasas_cmd_fusion *)
459 * max_cmd, GFP_KERNEL);
adam radford9c915a82010-12-21 13:34:31 -0800460
461 if (!fusion->cmd_list) {
462 printk(KERN_DEBUG "megasas: out of memory. Could not alloc "
463 "memory for cmd_list_fusion\n");
464 goto fail_cmd_list;
465 }
466
adam radford9c915a82010-12-21 13:34:31 -0800467 max_cmd = instance->max_fw_cmds;
468 for (i = 0; i < max_cmd; i++) {
469 fusion->cmd_list[i] = kmalloc(sizeof(struct megasas_cmd_fusion),
470 GFP_KERNEL);
471 if (!fusion->cmd_list[i]) {
472 printk(KERN_ERR "Could not alloc cmd list fusion\n");
473
474 for (j = 0; j < i; j++)
475 kfree(fusion->cmd_list[j]);
476
477 kfree(fusion->cmd_list);
478 fusion->cmd_list = NULL;
479 goto fail_cmd_list;
480 }
481 }
482
483 /* The first 256 bytes (SMID 0) is not used. Don't add to cmd list */
484 io_req_base = fusion->io_request_frames +
485 MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
486 io_req_base_phys = fusion->io_request_frames_phys +
487 MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE;
488
489 /*
490 * Add all the commands to command pool (fusion->cmd_pool)
491 */
492
493 /* SMID 0 is reserved. Set SMID/index from 1 */
494 for (i = 0; i < max_cmd; i++) {
495 cmd = fusion->cmd_list[i];
496 offset = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE * i;
497 memset(cmd, 0, sizeof(struct megasas_cmd_fusion));
498 cmd->index = i + 1;
499 cmd->scmd = NULL;
500 cmd->sync_cmd_idx = (u32)ULONG_MAX; /* Set to Invalid */
501 cmd->instance = instance;
502 cmd->io_request =
503 (struct MPI2_RAID_SCSI_IO_REQUEST *)
504 (io_req_base + offset);
505 memset(cmd->io_request, 0,
506 sizeof(struct MPI2_RAID_SCSI_IO_REQUEST));
507 cmd->io_request_phys_addr = io_req_base_phys + offset;
508
509 list_add_tail(&cmd->list, &fusion->cmd_pool);
510 }
511
512 /*
513 * Create a frame pool and assign one frame to each cmd
514 */
515 if (megasas_create_frame_pool_fusion(instance)) {
516 printk(KERN_DEBUG "megasas: Error creating frame DMA pool\n");
517 megasas_free_cmds_fusion(instance);
518 goto fail_req_desc;
519 }
520
521 return 0;
522
523fail_cmd_list:
524 pci_pool_free(fusion->io_request_frames_pool, fusion->io_request_frames,
525 fusion->io_request_frames_phys);
526 pci_pool_destroy(fusion->io_request_frames_pool);
527fail_io_frames:
528 dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz,
529 fusion->reply_frames_desc,
530 fusion->reply_frames_desc_phys);
531 pci_pool_free(fusion->reply_frames_desc_pool,
532 fusion->reply_frames_desc,
533 fusion->reply_frames_desc_phys);
534 pci_pool_destroy(fusion->reply_frames_desc_pool);
535
536fail_reply_desc:
537 dma_free_coherent(&instance->pdev->dev, fusion->request_alloc_sz,
538 fusion->req_frames_desc,
539 fusion->req_frames_desc_phys);
540fail_req_desc:
541 return -ENOMEM;
542}
543
544/**
545 * wait_and_poll - Issues a polling command
546 * @instance: Adapter soft state
547 * @cmd: Command packet to be issued
548 *
549 * For polling, MFI requires the cmd_status to be set to 0xFF before posting.
550 */
551int
552wait_and_poll(struct megasas_instance *instance, struct megasas_cmd *cmd)
553{
554 int i;
555 struct megasas_header *frame_hdr = &cmd->frame->hdr;
556
557 u32 msecs = MFI_POLL_TIMEOUT_SECS * 1000;
558
559 /*
560 * Wait for cmd_status to change
561 */
562 for (i = 0; (i < msecs) && (frame_hdr->cmd_status == 0xff); i += 20) {
563 rmb();
564 msleep(20);
565 }
566
567 if (frame_hdr->cmd_status == 0xff)
568 return -ETIME;
569
570 return 0;
571}
572
573/**
574 * megasas_ioc_init_fusion - Initializes the FW
575 * @instance: Adapter soft state
576 *
577 * Issues the IOC Init cmd
578 */
579int
580megasas_ioc_init_fusion(struct megasas_instance *instance)
581{
582 struct megasas_init_frame *init_frame;
583 struct MPI2_IOC_INIT_REQUEST *IOCInitMessage;
584 dma_addr_t ioc_init_handle;
adam radford9c915a82010-12-21 13:34:31 -0800585 struct megasas_cmd *cmd;
586 u8 ret;
587 struct fusion_context *fusion;
adam radfordc77a9bd2014-03-10 02:51:36 -0700588 union MEGASAS_REQUEST_DESCRIPTOR_UNION req_desc;
adam radford9c915a82010-12-21 13:34:31 -0800589 int i;
590 struct megasas_header *frame_hdr;
591
592 fusion = instance->ctrl_context;
593
594 cmd = megasas_get_cmd(instance);
595
596 if (!cmd) {
597 printk(KERN_ERR "Could not allocate cmd for INIT Frame\n");
598 ret = 1;
599 goto fail_get_cmd;
600 }
601
602 IOCInitMessage =
603 dma_alloc_coherent(&instance->pdev->dev,
604 sizeof(struct MPI2_IOC_INIT_REQUEST),
605 &ioc_init_handle, GFP_KERNEL);
606
607 if (!IOCInitMessage) {
608 printk(KERN_ERR "Could not allocate memory for "
609 "IOCInitMessage\n");
610 ret = 1;
611 goto fail_fw_init;
612 }
613
614 memset(IOCInitMessage, 0, sizeof(struct MPI2_IOC_INIT_REQUEST));
615
616 IOCInitMessage->Function = MPI2_FUNCTION_IOC_INIT;
617 IOCInitMessage->WhoInit = MPI2_WHOINIT_HOST_DRIVER;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530618 IOCInitMessage->MsgVersion = cpu_to_le16(MPI2_VERSION);
619 IOCInitMessage->HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
620 IOCInitMessage->SystemRequestFrameSize = cpu_to_le16(MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE / 4);
adam radford9c915a82010-12-21 13:34:31 -0800621
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530622 IOCInitMessage->ReplyDescriptorPostQueueDepth = cpu_to_le16(fusion->reply_q_depth);
623 IOCInitMessage->ReplyDescriptorPostQueueAddress = cpu_to_le64(fusion->reply_frames_desc_phys);
624 IOCInitMessage->SystemRequestFrameBaseAddress = cpu_to_le64(fusion->io_request_frames_phys);
adam radford5738f992012-03-19 19:49:53 -0700625 IOCInitMessage->HostMSIxVectors = instance->msix_vectors;
adam radford9c915a82010-12-21 13:34:31 -0800626 init_frame = (struct megasas_init_frame *)cmd->frame;
627 memset(init_frame, 0, MEGAMFI_FRAME_SIZE);
628
629 frame_hdr = &cmd->frame->hdr;
adam radford9c915a82010-12-21 13:34:31 -0800630 frame_hdr->cmd_status = 0xFF;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530631 frame_hdr->flags |= cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE);
adam radford9c915a82010-12-21 13:34:31 -0800632
633 init_frame->cmd = MFI_CMD_INIT;
634 init_frame->cmd_status = 0xFF;
635
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +0530636 /* driver support Extended MSIX */
637 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
638 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY))
639 init_frame->driver_operations.
640 mfi_capabilities.support_additional_msix = 1;
adam radford21c9e162013-09-06 15:27:14 -0700641 /* driver supports HA / Remote LUN over Fast Path interface */
642 init_frame->driver_operations.mfi_capabilities.support_fp_remote_lun
643 = 1;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530644 /* Convert capability to LE32 */
645 cpu_to_le32s((u32 *)&init_frame->driver_operations.mfi_capabilities);
adam radford21c9e162013-09-06 15:27:14 -0700646
Hannes Reineckefdc5a972014-01-16 11:25:33 +0100647 init_frame->queue_info_new_phys_addr_hi =
648 cpu_to_le32(upper_32_bits(ioc_init_handle));
649 init_frame->queue_info_new_phys_addr_lo =
650 cpu_to_le32(lower_32_bits(ioc_init_handle));
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530651 init_frame->data_xfer_len = cpu_to_le32(sizeof(struct MPI2_IOC_INIT_REQUEST));
adam radford9c915a82010-12-21 13:34:31 -0800652
adam radfordc77a9bd2014-03-10 02:51:36 -0700653 req_desc.Words = 0;
654 req_desc.MFAIo.RequestFlags =
adam radford9c915a82010-12-21 13:34:31 -0800655 (MEGASAS_REQ_DESCRIPT_FLAGS_MFA <<
656 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
adam radfordc77a9bd2014-03-10 02:51:36 -0700657 cpu_to_le32s((u32 *)&req_desc.MFAIo);
658 req_desc.Words |= cpu_to_le64(cmd->frame_phys_addr);
adam radford9c915a82010-12-21 13:34:31 -0800659
660 /*
661 * disable the intr before firing the init frame
662 */
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +0530663 instance->instancet->disable_intr(instance);
adam radford9c915a82010-12-21 13:34:31 -0800664
665 for (i = 0; i < (10 * 1000); i += 20) {
666 if (readl(&instance->reg_set->doorbell) & 1)
667 msleep(20);
668 else
669 break;
670 }
671
adam radfordc77a9bd2014-03-10 02:51:36 -0700672 instance->instancet->fire_cmd(instance, req_desc.u.low,
673 req_desc.u.high, instance->reg_set);
adam radford9c915a82010-12-21 13:34:31 -0800674
675 wait_and_poll(instance, cmd);
676
677 frame_hdr = &cmd->frame->hdr;
678 if (frame_hdr->cmd_status != 0) {
679 ret = 1;
680 goto fail_fw_init;
681 }
682 printk(KERN_ERR "megasas:IOC Init cmd success\n");
683
684 ret = 0;
685
686fail_fw_init:
687 megasas_return_cmd(instance, cmd);
688 if (IOCInitMessage)
689 dma_free_coherent(&instance->pdev->dev,
690 sizeof(struct MPI2_IOC_INIT_REQUEST),
691 IOCInitMessage, ioc_init_handle);
692fail_get_cmd:
693 return ret;
694}
695
696/*
adam radford9c915a82010-12-21 13:34:31 -0800697 * megasas_get_ld_map_info - Returns FW's ld_map structure
698 * @instance: Adapter soft state
699 * @pend: Pend the command or not
700 * Issues an internal command (DCMD) to get the FW's controller PD
701 * list structure. This information is mainly used to find out SYSTEM
702 * supported by the FW.
703 */
704static int
705megasas_get_ld_map_info(struct megasas_instance *instance)
706{
707 int ret = 0;
708 struct megasas_cmd *cmd;
709 struct megasas_dcmd_frame *dcmd;
710 struct MR_FW_RAID_MAP_ALL *ci;
711 dma_addr_t ci_h = 0;
712 u32 size_map_info;
713 struct fusion_context *fusion;
714
715 cmd = megasas_get_cmd(instance);
716
717 if (!cmd) {
718 printk(KERN_DEBUG "megasas: Failed to get cmd for map info.\n");
719 return -ENOMEM;
720 }
721
722 fusion = instance->ctrl_context;
723
724 if (!fusion) {
725 megasas_return_cmd(instance, cmd);
Hannes Reinecke2f8bdfa2014-01-16 11:25:35 +0100726 return -ENXIO;
adam radford9c915a82010-12-21 13:34:31 -0800727 }
728
729 dcmd = &cmd->frame->dcmd;
730
731 size_map_info = sizeof(struct MR_FW_RAID_MAP) +
732 (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1));
733
734 ci = fusion->ld_map[(instance->map_id & 1)];
735 ci_h = fusion->ld_map_phys[(instance->map_id & 1)];
736
737 if (!ci) {
738 printk(KERN_DEBUG "Failed to alloc mem for ld_map_info\n");
739 megasas_return_cmd(instance, cmd);
740 return -ENOMEM;
741 }
742
743 memset(ci, 0, sizeof(*ci));
744 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
745
746 dcmd->cmd = MFI_CMD_DCMD;
747 dcmd->cmd_status = 0xFF;
748 dcmd->sge_count = 1;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530749 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_READ);
adam radford9c915a82010-12-21 13:34:31 -0800750 dcmd->timeout = 0;
751 dcmd->pad_0 = 0;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530752 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
753 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
754 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
755 dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info);
adam radford9c915a82010-12-21 13:34:31 -0800756
757 if (!megasas_issue_polled(instance, cmd))
758 ret = 0;
759 else {
760 printk(KERN_ERR "megasas: Get LD Map Info Failed\n");
761 ret = -1;
762 }
763
764 megasas_return_cmd(instance, cmd);
765
766 return ret;
767}
768
769u8
770megasas_get_map_info(struct megasas_instance *instance)
771{
772 struct fusion_context *fusion = instance->ctrl_context;
773
774 fusion->fast_path_io = 0;
775 if (!megasas_get_ld_map_info(instance)) {
Sumit.Saxena@lsi.combc93d422013-05-22 12:35:04 +0530776 if (MR_ValidateMapInfo(instance)) {
adam radford9c915a82010-12-21 13:34:31 -0800777 fusion->fast_path_io = 1;
778 return 0;
779 }
780 }
781 return 1;
782}
783
784/*
785 * megasas_sync_map_info - Returns FW's ld_map structure
786 * @instance: Adapter soft state
787 *
788 * Issues an internal command (DCMD) to get the FW's controller PD
789 * list structure. This information is mainly used to find out SYSTEM
790 * supported by the FW.
791 */
792int
793megasas_sync_map_info(struct megasas_instance *instance)
794{
795 int ret = 0, i;
796 struct megasas_cmd *cmd;
797 struct megasas_dcmd_frame *dcmd;
798 u32 size_sync_info, num_lds;
799 struct fusion_context *fusion;
800 struct MR_LD_TARGET_SYNC *ci = NULL;
801 struct MR_FW_RAID_MAP_ALL *map;
802 struct MR_LD_RAID *raid;
803 struct MR_LD_TARGET_SYNC *ld_sync;
804 dma_addr_t ci_h = 0;
805 u32 size_map_info;
806
807 cmd = megasas_get_cmd(instance);
808
809 if (!cmd) {
810 printk(KERN_DEBUG "megasas: Failed to get cmd for sync"
811 "info.\n");
812 return -ENOMEM;
813 }
814
815 fusion = instance->ctrl_context;
816
817 if (!fusion) {
818 megasas_return_cmd(instance, cmd);
819 return 1;
820 }
821
822 map = fusion->ld_map[instance->map_id & 1];
823
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530824 num_lds = le32_to_cpu(map->raidMap.ldCount);
adam radford9c915a82010-12-21 13:34:31 -0800825
826 dcmd = &cmd->frame->dcmd;
827
828 size_sync_info = sizeof(struct MR_LD_TARGET_SYNC) *num_lds;
829
830 memset(dcmd->mbox.b, 0, MFI_MBOX_SIZE);
831
832 ci = (struct MR_LD_TARGET_SYNC *)
833 fusion->ld_map[(instance->map_id - 1) & 1];
834 memset(ci, 0, sizeof(struct MR_FW_RAID_MAP_ALL));
835
836 ci_h = fusion->ld_map_phys[(instance->map_id - 1) & 1];
837
838 ld_sync = (struct MR_LD_TARGET_SYNC *)ci;
839
840 for (i = 0; i < num_lds; i++, ld_sync++) {
841 raid = MR_LdRaidGet(i, map);
842 ld_sync->targetId = MR_GetLDTgtId(i, map);
843 ld_sync->seqNum = raid->seqNum;
844 }
845
846 size_map_info = sizeof(struct MR_FW_RAID_MAP) +
847 (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1));
848
849 dcmd->cmd = MFI_CMD_DCMD;
850 dcmd->cmd_status = 0xFF;
851 dcmd->sge_count = 1;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530852 dcmd->flags = cpu_to_le16(MFI_FRAME_DIR_WRITE);
adam radford9c915a82010-12-21 13:34:31 -0800853 dcmd->timeout = 0;
854 dcmd->pad_0 = 0;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530855 dcmd->data_xfer_len = cpu_to_le32(size_map_info);
adam radford9c915a82010-12-21 13:34:31 -0800856 dcmd->mbox.b[0] = num_lds;
857 dcmd->mbox.b[1] = MEGASAS_DCMD_MBOX_PEND_FLAG;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +0530858 dcmd->opcode = cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO);
859 dcmd->sgl.sge32[0].phys_addr = cpu_to_le32(ci_h);
860 dcmd->sgl.sge32[0].length = cpu_to_le32(size_map_info);
adam radford9c915a82010-12-21 13:34:31 -0800861
862 instance->map_update_cmd = cmd;
863
864 instance->instancet->issue_dcmd(instance, cmd);
865
866 return ret;
867}
868
Sumit.Saxena@lsi.com39b72c32013-05-22 12:32:43 +0530869/*
870 * meagasas_display_intel_branding - Display branding string
871 * @instance: per adapter object
872 *
873 * Return nothing.
874 */
875static void
876megasas_display_intel_branding(struct megasas_instance *instance)
877{
878 if (instance->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
879 return;
880
881 switch (instance->pdev->device) {
882 case PCI_DEVICE_ID_LSI_INVADER:
883 switch (instance->pdev->subsystem_device) {
884 case MEGARAID_INTEL_RS3DC080_SSDID:
885 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
886 instance->host->host_no,
887 MEGARAID_INTEL_RS3DC080_BRANDING);
888 break;
889 case MEGARAID_INTEL_RS3DC040_SSDID:
890 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
891 instance->host->host_no,
892 MEGARAID_INTEL_RS3DC040_BRANDING);
893 break;
894 case MEGARAID_INTEL_RS3SC008_SSDID:
895 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
896 instance->host->host_no,
897 MEGARAID_INTEL_RS3SC008_BRANDING);
898 break;
899 case MEGARAID_INTEL_RS3MC044_SSDID:
900 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
901 instance->host->host_no,
902 MEGARAID_INTEL_RS3MC044_BRANDING);
903 break;
904 default:
905 break;
906 }
907 break;
908 case PCI_DEVICE_ID_LSI_FURY:
909 switch (instance->pdev->subsystem_device) {
910 case MEGARAID_INTEL_RS3WC080_SSDID:
911 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
912 instance->host->host_no,
913 MEGARAID_INTEL_RS3WC080_BRANDING);
914 break;
915 case MEGARAID_INTEL_RS3WC040_SSDID:
916 dev_info(&instance->pdev->dev, "scsi host %d: %s\n",
917 instance->host->host_no,
918 MEGARAID_INTEL_RS3WC040_BRANDING);
919 break;
920 default:
921 break;
922 }
923 break;
924 default:
925 break;
926 }
927}
928
adam radford9c915a82010-12-21 13:34:31 -0800929/**
930 * megasas_init_adapter_fusion - Initializes the FW
931 * @instance: Adapter soft state
932 *
933 * This is the main function for initializing firmware.
934 */
935u32
936megasas_init_adapter_fusion(struct megasas_instance *instance)
937{
938 struct megasas_register_set __iomem *reg_set;
939 struct fusion_context *fusion;
940 u32 max_cmd;
adam radfordc8e858f2011-10-08 18:15:13 -0700941 int i = 0, count;
adam radford9c915a82010-12-21 13:34:31 -0800942
943 fusion = instance->ctrl_context;
944
945 reg_set = instance->reg_set;
946
947 /*
948 * Get various operational parameters from status register
949 */
950 instance->max_fw_cmds =
951 instance->instancet->read_fw_status_reg(reg_set) & 0x00FFFF;
952 instance->max_fw_cmds = min(instance->max_fw_cmds, (u16)1008);
953
954 /*
955 * Reduce the max supported cmds by 1. This is to ensure that the
956 * reply_q_sz (1 more than the max cmd that driver may send)
957 * does not exceed max cmds that the FW can support
958 */
959 instance->max_fw_cmds = instance->max_fw_cmds-1;
960 /* Only internal cmds (DCMD) need to have MFI frames */
961 instance->max_mfi_cmds = MEGASAS_INT_CMDS;
962
963 max_cmd = instance->max_fw_cmds;
964
965 fusion->reply_q_depth = ((max_cmd + 1 + 15)/16)*16;
966
967 fusion->request_alloc_sz =
968 sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *max_cmd;
969 fusion->reply_alloc_sz = sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)
970 *(fusion->reply_q_depth);
971 fusion->io_frames_alloc_sz = MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE +
972 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE *
973 (max_cmd + 1)); /* Extra 1 for SMID 0 */
974
975 fusion->max_sge_in_main_msg =
976 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
977 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL))/16;
978
979 fusion->max_sge_in_chain =
980 MEGASAS_MAX_SZ_CHAIN_FRAME / sizeof(union MPI2_SGE_IO_UNION);
981
982 instance->max_num_sge = fusion->max_sge_in_main_msg +
983 fusion->max_sge_in_chain - 2;
984
985 /* Used for pass thru MFI frame (DCMD) */
986 fusion->chain_offset_mfi_pthru =
987 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL)/16;
988
989 fusion->chain_offset_io_request =
990 (MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE -
991 sizeof(union MPI2_SGE_IO_UNION))/16;
992
adam radfordc8e858f2011-10-08 18:15:13 -0700993 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
994 for (i = 0 ; i < count; i++)
995 fusion->last_reply_idx[i] = 0;
adam radford9c915a82010-12-21 13:34:31 -0800996
997 /*
998 * Allocate memory for descriptors
999 * Create a pool of commands
1000 */
1001 if (megasas_alloc_cmds(instance))
1002 goto fail_alloc_mfi_cmds;
1003 if (megasas_alloc_cmds_fusion(instance))
1004 goto fail_alloc_cmds;
1005
1006 if (megasas_ioc_init_fusion(instance))
1007 goto fail_ioc_init;
1008
Sumit.Saxena@lsi.com39b72c32013-05-22 12:32:43 +05301009 megasas_display_intel_branding(instance);
1010
adam radford9c915a82010-12-21 13:34:31 -08001011 instance->flag_ieee = 1;
1012
1013 fusion->map_sz = sizeof(struct MR_FW_RAID_MAP) +
1014 (sizeof(struct MR_LD_SPAN_MAP) *(MAX_LOGICAL_DRIVES - 1));
1015
1016 fusion->fast_path_io = 0;
1017
1018 for (i = 0; i < 2; i++) {
1019 fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev,
1020 fusion->map_sz,
1021 &fusion->ld_map_phys[i],
1022 GFP_KERNEL);
1023 if (!fusion->ld_map[i]) {
1024 printk(KERN_ERR "megasas: Could not allocate memory "
1025 "for map info\n");
1026 goto fail_map_info;
1027 }
1028 }
1029
1030 if (!megasas_get_map_info(instance))
1031 megasas_sync_map_info(instance);
1032
1033 return 0;
1034
adam radford9c915a82010-12-21 13:34:31 -08001035fail_map_info:
1036 if (i == 1)
1037 dma_free_coherent(&instance->pdev->dev, fusion->map_sz,
1038 fusion->ld_map[0], fusion->ld_map_phys[0]);
1039fail_ioc_init:
adam radfordeb1b1232011-02-24 20:55:56 -08001040 megasas_free_cmds_fusion(instance);
1041fail_alloc_cmds:
1042 megasas_free_cmds(instance);
1043fail_alloc_mfi_cmds:
adam radford9c915a82010-12-21 13:34:31 -08001044 return 1;
1045}
1046
1047/**
1048 * megasas_fire_cmd_fusion - Sends command to the FW
1049 * @frame_phys_addr : Physical address of cmd
1050 * @frame_count : Number of frames for the command
1051 * @regs : MFI register set
1052 */
1053void
1054megasas_fire_cmd_fusion(struct megasas_instance *instance,
1055 dma_addr_t req_desc_lo,
1056 u32 req_desc_hi,
1057 struct megasas_register_set __iomem *regs)
1058{
1059 unsigned long flags;
1060
1061 spin_lock_irqsave(&instance->hba_lock, flags);
1062
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301063 writel(le32_to_cpu(req_desc_lo), &(regs)->inbound_low_queue_port);
1064 writel(le32_to_cpu(req_desc_hi), &(regs)->inbound_high_queue_port);
adam radford9c915a82010-12-21 13:34:31 -08001065 spin_unlock_irqrestore(&instance->hba_lock, flags);
1066}
1067
1068/**
1069 * map_cmd_status - Maps FW cmd status to OS cmd status
1070 * @cmd : Pointer to cmd
1071 * @status : status of cmd returned by FW
1072 * @ext_status : ext status of cmd returned by FW
1073 */
1074
1075void
1076map_cmd_status(struct megasas_cmd_fusion *cmd, u8 status, u8 ext_status)
1077{
1078
1079 switch (status) {
1080
1081 case MFI_STAT_OK:
1082 cmd->scmd->result = DID_OK << 16;
1083 break;
1084
1085 case MFI_STAT_SCSI_IO_FAILED:
1086 case MFI_STAT_LD_INIT_IN_PROGRESS:
1087 cmd->scmd->result = (DID_ERROR << 16) | ext_status;
1088 break;
1089
1090 case MFI_STAT_SCSI_DONE_WITH_ERROR:
1091
1092 cmd->scmd->result = (DID_OK << 16) | ext_status;
1093 if (ext_status == SAM_STAT_CHECK_CONDITION) {
1094 memset(cmd->scmd->sense_buffer, 0,
1095 SCSI_SENSE_BUFFERSIZE);
1096 memcpy(cmd->scmd->sense_buffer, cmd->sense,
1097 SCSI_SENSE_BUFFERSIZE);
1098 cmd->scmd->result |= DRIVER_SENSE << 24;
1099 }
1100 break;
1101
1102 case MFI_STAT_LD_OFFLINE:
1103 case MFI_STAT_DEVICE_NOT_FOUND:
1104 cmd->scmd->result = DID_BAD_TARGET << 16;
1105 break;
adam radford36807e62011-10-08 18:15:06 -07001106 case MFI_STAT_CONFIG_SEQ_MISMATCH:
1107 cmd->scmd->result = DID_IMM_RETRY << 16;
1108 break;
adam radford9c915a82010-12-21 13:34:31 -08001109 default:
1110 printk(KERN_DEBUG "megasas: FW status %#x\n", status);
1111 cmd->scmd->result = DID_ERROR << 16;
1112 break;
1113 }
1114}
1115
1116/**
1117 * megasas_make_sgl_fusion - Prepares 32-bit SGL
1118 * @instance: Adapter soft state
1119 * @scp: SCSI command from the mid-layer
1120 * @sgl_ptr: SGL to be filled in
1121 * @cmd: cmd we are working on
1122 *
1123 * If successful, this function returns the number of SG elements.
1124 */
1125static int
1126megasas_make_sgl_fusion(struct megasas_instance *instance,
1127 struct scsi_cmnd *scp,
1128 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr,
1129 struct megasas_cmd_fusion *cmd)
1130{
adam radford36807e62011-10-08 18:15:06 -07001131 int i, sg_processed, sge_count;
adam radford9c915a82010-12-21 13:34:31 -08001132 struct scatterlist *os_sgl;
1133 struct fusion_context *fusion;
1134
1135 fusion = instance->ctrl_context;
1136
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +05301137 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
1138 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
adam radford36807e62011-10-08 18:15:06 -07001139 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end = sgl_ptr;
1140 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
1141 sgl_ptr_end->Flags = 0;
1142 }
adam radford9c915a82010-12-21 13:34:31 -08001143
1144 sge_count = scsi_dma_map(scp);
1145
1146 BUG_ON(sge_count < 0);
1147
1148 if (sge_count > instance->max_num_sge || !sge_count)
1149 return sge_count;
1150
adam radford9c915a82010-12-21 13:34:31 -08001151 scsi_for_each_sg(scp, os_sgl, sge_count, i) {
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301152 sgl_ptr->Length = cpu_to_le32(sg_dma_len(os_sgl));
1153 sgl_ptr->Address = cpu_to_le64(sg_dma_address(os_sgl));
adam radford9c915a82010-12-21 13:34:31 -08001154 sgl_ptr->Flags = 0;
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +05301155 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
1156 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
adam radford36807e62011-10-08 18:15:06 -07001157 if (i == sge_count - 1)
1158 sgl_ptr->Flags = IEEE_SGE_FLAGS_END_OF_LIST;
1159 }
adam radford9c915a82010-12-21 13:34:31 -08001160 sgl_ptr++;
1161
1162 sg_processed = i + 1;
1163
1164 if ((sg_processed == (fusion->max_sge_in_main_msg - 1)) &&
1165 (sge_count > fusion->max_sge_in_main_msg)) {
1166
1167 struct MPI25_IEEE_SGE_CHAIN64 *sg_chain;
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +05301168 if ((instance->pdev->device ==
1169 PCI_DEVICE_ID_LSI_INVADER) ||
1170 (instance->pdev->device ==
1171 PCI_DEVICE_ID_LSI_FURY)) {
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301172 if ((le16_to_cpu(cmd->io_request->IoFlags) &
1173 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
1174 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
adam radford36807e62011-10-08 18:15:06 -07001175 cmd->io_request->ChainOffset =
1176 fusion->
1177 chain_offset_io_request;
1178 else
1179 cmd->io_request->ChainOffset = 0;
1180 } else
1181 cmd->io_request->ChainOffset =
1182 fusion->chain_offset_io_request;
1183
adam radford9c915a82010-12-21 13:34:31 -08001184 sg_chain = sgl_ptr;
1185 /* Prepare chain element */
1186 sg_chain->NextChainOffset = 0;
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +05301187 if ((instance->pdev->device ==
1188 PCI_DEVICE_ID_LSI_INVADER) ||
1189 (instance->pdev->device ==
1190 PCI_DEVICE_ID_LSI_FURY))
adam radford36807e62011-10-08 18:15:06 -07001191 sg_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT;
1192 else
1193 sg_chain->Flags =
1194 (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
1195 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR);
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301196 sg_chain->Length = cpu_to_le32((sizeof(union MPI2_SGE_IO_UNION) * (sge_count - sg_processed)));
1197 sg_chain->Address = cpu_to_le64(cmd->sg_frame_phys_addr);
adam radford9c915a82010-12-21 13:34:31 -08001198
1199 sgl_ptr =
1200 (struct MPI25_IEEE_SGE_CHAIN64 *)cmd->sg_frame;
1201 }
1202 }
1203
1204 return sge_count;
1205}
1206
1207/**
1208 * megasas_set_pd_lba - Sets PD LBA
1209 * @cdb: CDB
1210 * @cdb_len: cdb length
1211 * @start_blk: Start block of IO
1212 *
1213 * Used to set the PD LBA in CDB for FP IOs
1214 */
1215void
1216megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
1217 struct IO_REQUEST_INFO *io_info, struct scsi_cmnd *scp,
1218 struct MR_FW_RAID_MAP_ALL *local_map_ptr, u32 ref_tag)
1219{
1220 struct MR_LD_RAID *raid;
1221 u32 ld;
1222 u64 start_blk = io_info->pdBlock;
1223 u8 *cdb = io_request->CDB.CDB32;
1224 u32 num_blocks = io_info->numBlocks;
adam radford495c5602011-05-11 18:34:40 -07001225 u8 opcode = 0, flagvals = 0, groupnum = 0, control = 0;
adam radford9c915a82010-12-21 13:34:31 -08001226
1227 /* Check if T10 PI (DIF) is enabled for this LD */
1228 ld = MR_TargetIdToLdGet(io_info->ldTgtId, local_map_ptr);
1229 raid = MR_LdRaidGet(ld, local_map_ptr);
1230 if (raid->capability.ldPiMode == MR_PROT_INFO_TYPE_CONTROLLER) {
1231 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1232 cdb[0] = MEGASAS_SCSI_VARIABLE_LENGTH_CMD;
1233 cdb[7] = MEGASAS_SCSI_ADDL_CDB_LEN;
1234
1235 if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
1236 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_READ32;
1237 else
1238 cdb[9] = MEGASAS_SCSI_SERVICE_ACTION_WRITE32;
1239 cdb[10] = MEGASAS_RD_WR_PROTECT_CHECK_ALL;
1240
1241 /* LBA */
1242 cdb[12] = (u8)((start_blk >> 56) & 0xff);
1243 cdb[13] = (u8)((start_blk >> 48) & 0xff);
1244 cdb[14] = (u8)((start_blk >> 40) & 0xff);
1245 cdb[15] = (u8)((start_blk >> 32) & 0xff);
1246 cdb[16] = (u8)((start_blk >> 24) & 0xff);
1247 cdb[17] = (u8)((start_blk >> 16) & 0xff);
1248 cdb[18] = (u8)((start_blk >> 8) & 0xff);
1249 cdb[19] = (u8)(start_blk & 0xff);
1250
1251 /* Logical block reference tag */
1252 io_request->CDB.EEDP32.PrimaryReferenceTag =
1253 cpu_to_be32(ref_tag);
1254 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0xffff;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301255 io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */
adam radford9c915a82010-12-21 13:34:31 -08001256
1257 /* Transfer length */
1258 cdb[28] = (u8)((num_blocks >> 24) & 0xff);
1259 cdb[29] = (u8)((num_blocks >> 16) & 0xff);
1260 cdb[30] = (u8)((num_blocks >> 8) & 0xff);
1261 cdb[31] = (u8)(num_blocks & 0xff);
1262
1263 /* set SCSI IO EEDPFlags */
1264 if (scp->sc_data_direction == PCI_DMA_FROMDEVICE) {
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301265 io_request->EEDPFlags = cpu_to_le16(
adam radford9c915a82010-12-21 13:34:31 -08001266 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
1267 MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
1268 MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP |
1269 MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG |
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301270 MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD);
adam radford9c915a82010-12-21 13:34:31 -08001271 } else {
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301272 io_request->EEDPFlags = cpu_to_le16(
adam radford9c915a82010-12-21 13:34:31 -08001273 MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301274 MPI2_SCSIIO_EEDPFLAGS_INSERT_OP);
adam radford9c915a82010-12-21 13:34:31 -08001275 }
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301276 io_request->Control |= cpu_to_le32((0x4 << 26));
1277 io_request->EEDPBlockSize = cpu_to_le32(scp->device->sector_size);
adam radford9c915a82010-12-21 13:34:31 -08001278 } else {
1279 /* Some drives don't support 16/12 byte CDB's, convert to 10 */
1280 if (((cdb_len == 12) || (cdb_len == 16)) &&
1281 (start_blk <= 0xffffffff)) {
1282 if (cdb_len == 16) {
1283 opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
1284 flagvals = cdb[1];
1285 groupnum = cdb[14];
1286 control = cdb[15];
1287 } else {
1288 opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
1289 flagvals = cdb[1];
1290 groupnum = cdb[10];
1291 control = cdb[11];
1292 }
1293
1294 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1295
1296 cdb[0] = opcode;
1297 cdb[1] = flagvals;
1298 cdb[6] = groupnum;
1299 cdb[9] = control;
1300
1301 /* Transfer length */
1302 cdb[8] = (u8)(num_blocks & 0xff);
1303 cdb[7] = (u8)((num_blocks >> 8) & 0xff);
1304
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301305 io_request->IoFlags = cpu_to_le16(10); /* Specify 10-byte cdb */
adam radford9c915a82010-12-21 13:34:31 -08001306 cdb_len = 10;
adam radford495c5602011-05-11 18:34:40 -07001307 } else if ((cdb_len < 16) && (start_blk > 0xffffffff)) {
1308 /* Convert to 16 byte CDB for large LBA's */
1309 switch (cdb_len) {
1310 case 6:
1311 opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16;
1312 control = cdb[5];
1313 break;
1314 case 10:
1315 opcode =
1316 cdb[0] == READ_10 ? READ_16 : WRITE_16;
1317 flagvals = cdb[1];
1318 groupnum = cdb[6];
1319 control = cdb[9];
1320 break;
1321 case 12:
1322 opcode =
1323 cdb[0] == READ_12 ? READ_16 : WRITE_16;
1324 flagvals = cdb[1];
1325 groupnum = cdb[10];
1326 control = cdb[11];
1327 break;
1328 }
1329
1330 memset(cdb, 0, sizeof(io_request->CDB.CDB32));
1331
1332 cdb[0] = opcode;
1333 cdb[1] = flagvals;
1334 cdb[14] = groupnum;
1335 cdb[15] = control;
1336
1337 /* Transfer length */
1338 cdb[13] = (u8)(num_blocks & 0xff);
1339 cdb[12] = (u8)((num_blocks >> 8) & 0xff);
1340 cdb[11] = (u8)((num_blocks >> 16) & 0xff);
1341 cdb[10] = (u8)((num_blocks >> 24) & 0xff);
1342
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301343 io_request->IoFlags = cpu_to_le16(16); /* Specify 16-byte cdb */
adam radford495c5602011-05-11 18:34:40 -07001344 cdb_len = 16;
adam radford9c915a82010-12-21 13:34:31 -08001345 }
1346
1347 /* Normal case, just load LBA here */
1348 switch (cdb_len) {
1349 case 6:
1350 {
1351 u8 val = cdb[1] & 0xE0;
1352 cdb[3] = (u8)(start_blk & 0xff);
1353 cdb[2] = (u8)((start_blk >> 8) & 0xff);
1354 cdb[1] = val | ((u8)(start_blk >> 16) & 0x1f);
1355 break;
1356 }
1357 case 10:
1358 cdb[5] = (u8)(start_blk & 0xff);
1359 cdb[4] = (u8)((start_blk >> 8) & 0xff);
1360 cdb[3] = (u8)((start_blk >> 16) & 0xff);
1361 cdb[2] = (u8)((start_blk >> 24) & 0xff);
1362 break;
1363 case 12:
1364 cdb[5] = (u8)(start_blk & 0xff);
1365 cdb[4] = (u8)((start_blk >> 8) & 0xff);
1366 cdb[3] = (u8)((start_blk >> 16) & 0xff);
1367 cdb[2] = (u8)((start_blk >> 24) & 0xff);
1368 break;
1369 case 16:
1370 cdb[9] = (u8)(start_blk & 0xff);
1371 cdb[8] = (u8)((start_blk >> 8) & 0xff);
1372 cdb[7] = (u8)((start_blk >> 16) & 0xff);
1373 cdb[6] = (u8)((start_blk >> 24) & 0xff);
1374 cdb[5] = (u8)((start_blk >> 32) & 0xff);
1375 cdb[4] = (u8)((start_blk >> 40) & 0xff);
1376 cdb[3] = (u8)((start_blk >> 48) & 0xff);
1377 cdb[2] = (u8)((start_blk >> 56) & 0xff);
1378 break;
1379 }
1380 }
1381}
1382
1383/**
1384 * megasas_build_ldio_fusion - Prepares IOs to devices
1385 * @instance: Adapter soft state
1386 * @scp: SCSI command
1387 * @cmd: Command to be prepared
1388 *
1389 * Prepares the io_request and chain elements (sg_frame) for IO
1390 * The IO can be for PD (Fast Path) or LD
1391 */
1392void
1393megasas_build_ldio_fusion(struct megasas_instance *instance,
1394 struct scsi_cmnd *scp,
1395 struct megasas_cmd_fusion *cmd)
1396{
1397 u8 fp_possible;
adam radfordf9eff812012-10-01 19:27:07 -07001398 u32 start_lba_lo, start_lba_hi, device_id, datalength = 0;
adam radford9c915a82010-12-21 13:34:31 -08001399 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
1400 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
1401 struct IO_REQUEST_INFO io_info;
1402 struct fusion_context *fusion;
1403 struct MR_FW_RAID_MAP_ALL *local_map_ptr;
adam radford21c9e162013-09-06 15:27:14 -07001404 u8 *raidLUN;
adam radford9c915a82010-12-21 13:34:31 -08001405
1406 device_id = MEGASAS_DEV_INDEX(instance, scp);
1407
1408 fusion = instance->ctrl_context;
1409
1410 io_request = cmd->io_request;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301411 io_request->RaidContext.VirtualDiskTgtId = cpu_to_le16(device_id);
adam radford9c915a82010-12-21 13:34:31 -08001412 io_request->RaidContext.status = 0;
1413 io_request->RaidContext.exStatus = 0;
1414
1415 req_desc = (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)cmd->request_desc;
1416
1417 start_lba_lo = 0;
1418 start_lba_hi = 0;
1419 fp_possible = 0;
1420
1421 /*
1422 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1423 */
1424 if (scp->cmd_len == 6) {
adam radfordf9eff812012-10-01 19:27:07 -07001425 datalength = (u32) scp->cmnd[4];
adam radford9c915a82010-12-21 13:34:31 -08001426 start_lba_lo = ((u32) scp->cmnd[1] << 16) |
1427 ((u32) scp->cmnd[2] << 8) | (u32) scp->cmnd[3];
1428
1429 start_lba_lo &= 0x1FFFFF;
1430 }
1431
1432 /*
1433 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1434 */
1435 else if (scp->cmd_len == 10) {
adam radfordf9eff812012-10-01 19:27:07 -07001436 datalength = (u32) scp->cmnd[8] |
adam radford9c915a82010-12-21 13:34:31 -08001437 ((u32) scp->cmnd[7] << 8);
1438 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
1439 ((u32) scp->cmnd[3] << 16) |
1440 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
1441 }
1442
1443 /*
1444 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1445 */
1446 else if (scp->cmd_len == 12) {
adam radfordf9eff812012-10-01 19:27:07 -07001447 datalength = ((u32) scp->cmnd[6] << 24) |
adam radford9c915a82010-12-21 13:34:31 -08001448 ((u32) scp->cmnd[7] << 16) |
1449 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
1450 start_lba_lo = ((u32) scp->cmnd[2] << 24) |
1451 ((u32) scp->cmnd[3] << 16) |
1452 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
1453 }
1454
1455 /*
1456 * 16-byte READ(0x88) or WRITE(0x8A) cdb
1457 */
1458 else if (scp->cmd_len == 16) {
adam radfordf9eff812012-10-01 19:27:07 -07001459 datalength = ((u32) scp->cmnd[10] << 24) |
adam radford9c915a82010-12-21 13:34:31 -08001460 ((u32) scp->cmnd[11] << 16) |
1461 ((u32) scp->cmnd[12] << 8) | (u32) scp->cmnd[13];
1462 start_lba_lo = ((u32) scp->cmnd[6] << 24) |
1463 ((u32) scp->cmnd[7] << 16) |
1464 ((u32) scp->cmnd[8] << 8) | (u32) scp->cmnd[9];
1465
1466 start_lba_hi = ((u32) scp->cmnd[2] << 24) |
1467 ((u32) scp->cmnd[3] << 16) |
1468 ((u32) scp->cmnd[4] << 8) | (u32) scp->cmnd[5];
1469 }
1470
1471 memset(&io_info, 0, sizeof(struct IO_REQUEST_INFO));
1472 io_info.ldStartBlock = ((u64)start_lba_hi << 32) | start_lba_lo;
adam radfordf9eff812012-10-01 19:27:07 -07001473 io_info.numBlocks = datalength;
adam radford9c915a82010-12-21 13:34:31 -08001474 io_info.ldTgtId = device_id;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301475 io_request->DataLength = cpu_to_le32(scsi_bufflen(scp));
adam radford9c915a82010-12-21 13:34:31 -08001476
1477 if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
1478 io_info.isRead = 1;
1479
1480 local_map_ptr = fusion->ld_map[(instance->map_id & 1)];
1481
1482 if ((MR_TargetIdToLdGet(device_id, local_map_ptr) >=
1483 MAX_LOGICAL_DRIVES) || (!fusion->fast_path_io)) {
1484 io_request->RaidContext.regLockFlags = 0;
1485 fp_possible = 0;
1486 } else {
adam radford36807e62011-10-08 18:15:06 -07001487 if (MR_BuildRaidContext(instance, &io_info,
1488 &io_request->RaidContext,
adam radford21c9e162013-09-06 15:27:14 -07001489 local_map_ptr, &raidLUN))
adam radford9c915a82010-12-21 13:34:31 -08001490 fp_possible = io_info.fpOkForIo;
1491 }
1492
adam radfordc8e858f2011-10-08 18:15:13 -07001493 /* Use smp_processor_id() for now until cmd->request->cpu is CPU
1494 id by default, not CPU group id, otherwise all MSI-X queues won't
1495 be utilized */
1496 cmd->request_desc->SCSIIO.MSIxIndex = instance->msix_vectors ?
1497 smp_processor_id() % instance->msix_vectors : 0;
1498
adam radford9c915a82010-12-21 13:34:31 -08001499 if (fp_possible) {
1500 megasas_set_pd_lba(io_request, scp->cmd_len, &io_info, scp,
1501 local_map_ptr, start_lba_lo);
adam radford9c915a82010-12-21 13:34:31 -08001502 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
1503 cmd->request_desc->SCSIIO.RequestFlags =
1504 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
1505 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +05301506 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
1507 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
adam radford36807e62011-10-08 18:15:06 -07001508 if (io_request->RaidContext.regLockFlags ==
1509 REGION_TYPE_UNUSED)
1510 cmd->request_desc->SCSIIO.RequestFlags =
1511 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
1512 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1513 io_request->RaidContext.Type = MPI2_TYPE_CUDA;
1514 io_request->RaidContext.nseg = 0x1;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301515 io_request->IoFlags |= cpu_to_le16(MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
adam radford36807e62011-10-08 18:15:06 -07001516 io_request->RaidContext.regLockFlags |=
1517 (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
1518 MR_RL_FLAGS_SEQ_NUM_ENABLE);
1519 }
adam radford9c915a82010-12-21 13:34:31 -08001520 if ((fusion->load_balance_info[device_id].loadBalanceFlag) &&
1521 (io_info.isRead)) {
1522 io_info.devHandle =
1523 get_updated_dev_handle(
1524 &fusion->load_balance_info[device_id],
1525 &io_info);
1526 scp->SCp.Status |= MEGASAS_LOAD_BALANCE_FLAG;
1527 } else
1528 scp->SCp.Status &= ~MEGASAS_LOAD_BALANCE_FLAG;
1529 cmd->request_desc->SCSIIO.DevHandle = io_info.devHandle;
1530 io_request->DevHandle = io_info.devHandle;
adam radford21c9e162013-09-06 15:27:14 -07001531 /* populate the LUN field */
1532 memcpy(io_request->LUN, raidLUN, 8);
adam radford9c915a82010-12-21 13:34:31 -08001533 } else {
1534 io_request->RaidContext.timeoutValue =
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301535 cpu_to_le16(local_map_ptr->raidMap.fpPdIoTimeoutSec);
adam radford9c915a82010-12-21 13:34:31 -08001536 cmd->request_desc->SCSIIO.RequestFlags =
1537 (MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO
1538 << MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +05301539 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
1540 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
adam radford36807e62011-10-08 18:15:06 -07001541 if (io_request->RaidContext.regLockFlags ==
1542 REGION_TYPE_UNUSED)
1543 cmd->request_desc->SCSIIO.RequestFlags =
1544 (MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK <<
1545 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1546 io_request->RaidContext.Type = MPI2_TYPE_CUDA;
1547 io_request->RaidContext.regLockFlags |=
1548 (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
1549 MR_RL_FLAGS_SEQ_NUM_ENABLE);
1550 io_request->RaidContext.nseg = 0x1;
1551 }
1552 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301553 io_request->DevHandle = cpu_to_le16(device_id);
adam radford9c915a82010-12-21 13:34:31 -08001554 } /* Not FP */
1555}
1556
1557/**
1558 * megasas_build_dcdb_fusion - Prepares IOs to devices
1559 * @instance: Adapter soft state
1560 * @scp: SCSI command
1561 * @cmd: Command to be prepared
1562 *
1563 * Prepares the io_request frame for non-io cmds
1564 */
1565static void
1566megasas_build_dcdb_fusion(struct megasas_instance *instance,
1567 struct scsi_cmnd *scmd,
1568 struct megasas_cmd_fusion *cmd)
1569{
1570 u32 device_id;
1571 struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
1572 u16 pd_index = 0;
1573 struct MR_FW_RAID_MAP_ALL *local_map_ptr;
1574 struct fusion_context *fusion = instance->ctrl_context;
adam radford21c9e162013-09-06 15:27:14 -07001575 u8 span, physArm;
1576 u16 devHandle;
1577 u32 ld, arRef, pd;
1578 struct MR_LD_RAID *raid;
1579 struct RAID_CONTEXT *pRAID_Context;
adam radford9c915a82010-12-21 13:34:31 -08001580
1581 io_request = cmd->io_request;
1582 device_id = MEGASAS_DEV_INDEX(instance, scmd);
1583 pd_index = (scmd->device->channel * MEGASAS_MAX_DEV_PER_CHANNEL)
1584 +scmd->device->id;
1585 local_map_ptr = fusion->ld_map[(instance->map_id & 1)];
1586
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301587 io_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
adam radford21c9e162013-09-06 15:27:14 -07001588
1589
adam radford9c915a82010-12-21 13:34:31 -08001590 /* Check if this is a system PD I/O */
adam radforde187df62012-10-01 19:27:12 -07001591 if (scmd->device->channel < MEGASAS_MAX_PD_CHANNELS &&
1592 instance->pd_list[pd_index].driveState == MR_PD_STATE_SYSTEM) {
adam radford9c915a82010-12-21 13:34:31 -08001593 io_request->Function = 0;
adam radford9c5ebd02013-02-09 15:29:20 -08001594 if (fusion->fast_path_io)
1595 io_request->DevHandle =
adam radford9c915a82010-12-21 13:34:31 -08001596 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
1597 io_request->RaidContext.timeoutValue =
1598 local_map_ptr->raidMap.fpPdIoTimeoutSec;
1599 io_request->RaidContext.regLockFlags = 0;
1600 io_request->RaidContext.regLockRowLBA = 0;
1601 io_request->RaidContext.regLockLength = 0;
1602 io_request->RaidContext.RAIDFlags =
1603 MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD <<
1604 MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT;
Sumit.Saxena@lsi.com5d0d9082013-05-22 12:33:29 +05301605 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
1606 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY))
Sumit.Saxena@lsi.combe263742014-02-12 23:37:46 +05301607 io_request->IoFlags |= cpu_to_le16(
1608 MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH);
adam radford9c915a82010-12-21 13:34:31 -08001609 cmd->request_desc->SCSIIO.RequestFlags =
1610 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
1611 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
adam radford8ead5812012-10-01 19:27:20 -07001612 cmd->request_desc->SCSIIO.DevHandle =
1613 local_map_ptr->raidMap.devHndlInfo[device_id].curDevHdl;
Sumit.Saxena@lsi.com8058a162014-03-02 05:28:11 +05301614 cmd->request_desc->SCSIIO.MSIxIndex =
1615 instance->msix_vectors ? smp_processor_id() % instance->msix_vectors : 0;
Sumit.Saxena@lsi.com32d87452013-05-22 12:31:18 +05301616 /*
1617 * If the command is for the tape device, set the
1618 * FP timeout to the os layer timeout value.
1619 */
1620 if (scmd->device->type == TYPE_TAPE) {
1621 if ((scmd->request->timeout / HZ) > 0xFFFF)
1622 io_request->RaidContext.timeoutValue =
1623 0xFFFF;
1624 else
1625 io_request->RaidContext.timeoutValue =
1626 scmd->request->timeout / HZ;
1627 }
adam radford9c915a82010-12-21 13:34:31 -08001628 } else {
adam radford21c9e162013-09-06 15:27:14 -07001629 if (scmd->device->channel < MEGASAS_MAX_PD_CHANNELS)
1630 goto NonFastPath;
1631
1632 ld = MR_TargetIdToLdGet(device_id, local_map_ptr);
1633 if ((ld >= MAX_LOGICAL_DRIVES) || (!fusion->fast_path_io))
1634 goto NonFastPath;
1635
1636 raid = MR_LdRaidGet(ld, local_map_ptr);
1637
1638 /* check if this LD is FP capable */
1639 if (!(raid->capability.fpNonRWCapable))
1640 /* not FP capable, send as non-FP */
1641 goto NonFastPath;
1642
1643 /* get RAID_Context pointer */
1644 pRAID_Context = &io_request->RaidContext;
1645
1646 /* set RAID context values */
1647 pRAID_Context->regLockFlags = REGION_TYPE_SHARED_READ;
1648 pRAID_Context->timeoutValue = raid->fpIoTimeoutForLd;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301649 pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
adam radford21c9e162013-09-06 15:27:14 -07001650 pRAID_Context->regLockRowLBA = 0;
1651 pRAID_Context->regLockLength = 0;
1652 pRAID_Context->configSeqNum = raid->seqNum;
1653
1654 /* get the DevHandle for the PD (since this is
1655 fpNonRWCapable, this is a single disk RAID0) */
1656 span = physArm = 0;
1657 arRef = MR_LdSpanArrayGet(ld, span, local_map_ptr);
1658 pd = MR_ArPdGet(arRef, physArm, local_map_ptr);
1659 devHandle = MR_PdDevHandleGet(pd, local_map_ptr);
1660
1661 /* build request descriptor */
1662 cmd->request_desc->SCSIIO.RequestFlags =
1663 (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
1664 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1665 cmd->request_desc->SCSIIO.DevHandle = devHandle;
1666
1667 /* populate the LUN field */
1668 memcpy(io_request->LUN, raid->LUN, 8);
1669
1670 /* build the raidScsiIO structure */
1671 io_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
1672 io_request->DevHandle = devHandle;
1673
1674 return;
1675
1676NonFastPath:
adam radford9c915a82010-12-21 13:34:31 -08001677 io_request->Function = MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301678 io_request->DevHandle = cpu_to_le16(device_id);
adam radford9c915a82010-12-21 13:34:31 -08001679 cmd->request_desc->SCSIIO.RequestFlags =
1680 (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
1681 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
1682 }
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301683 io_request->RaidContext.VirtualDiskTgtId = cpu_to_le16(device_id);
adam radfordeaa3c242011-02-24 20:56:49 -08001684 io_request->LUN[1] = scmd->device->lun;
adam radford9c915a82010-12-21 13:34:31 -08001685}
1686
1687/**
1688 * megasas_build_io_fusion - Prepares IOs to devices
1689 * @instance: Adapter soft state
1690 * @scp: SCSI command
1691 * @cmd: Command to be prepared
1692 *
1693 * Invokes helper functions to prepare request frames
1694 * and sets flags appropriate for IO/Non-IO cmd
1695 */
1696int
1697megasas_build_io_fusion(struct megasas_instance *instance,
1698 struct scsi_cmnd *scp,
1699 struct megasas_cmd_fusion *cmd)
1700{
1701 u32 device_id, sge_count;
1702 struct MPI2_RAID_SCSI_IO_REQUEST *io_request = cmd->io_request;
1703
1704 device_id = MEGASAS_DEV_INDEX(instance, scp);
1705
1706 /* Zero out some fields so they don't get reused */
adam radfordeaa3c242011-02-24 20:56:49 -08001707 io_request->LUN[1] = 0;
adam radford9c915a82010-12-21 13:34:31 -08001708 io_request->CDB.EEDP32.PrimaryReferenceTag = 0;
1709 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0;
1710 io_request->EEDPFlags = 0;
1711 io_request->Control = 0;
1712 io_request->EEDPBlockSize = 0;
adam radford36807e62011-10-08 18:15:06 -07001713 io_request->ChainOffset = 0;
adam radford9c915a82010-12-21 13:34:31 -08001714 io_request->RaidContext.RAIDFlags = 0;
adam radford36807e62011-10-08 18:15:06 -07001715 io_request->RaidContext.Type = 0;
1716 io_request->RaidContext.nseg = 0;
adam radford9c915a82010-12-21 13:34:31 -08001717
1718 memcpy(io_request->CDB.CDB32, scp->cmnd, scp->cmd_len);
1719 /*
1720 * Just the CDB length,rest of the Flags are zero
1721 * This will be modified for FP in build_ldio_fusion
1722 */
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301723 io_request->IoFlags = cpu_to_le16(scp->cmd_len);
adam radford9c915a82010-12-21 13:34:31 -08001724
1725 if (megasas_is_ldio(scp))
1726 megasas_build_ldio_fusion(instance, scp, cmd);
1727 else
1728 megasas_build_dcdb_fusion(instance, scp, cmd);
1729
1730 /*
1731 * Construct SGL
1732 */
1733
1734 sge_count =
1735 megasas_make_sgl_fusion(instance, scp,
1736 (struct MPI25_IEEE_SGE_CHAIN64 *)
1737 &io_request->SGL, cmd);
1738
1739 if (sge_count > instance->max_num_sge) {
1740 printk(KERN_ERR "megasas: Error. sge_count (0x%x) exceeds "
1741 "max (0x%x) allowed\n", sge_count,
1742 instance->max_num_sge);
1743 return 1;
1744 }
1745
1746 io_request->RaidContext.numSGE = sge_count;
1747
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301748 io_request->SGLFlags = cpu_to_le16(MPI2_SGE_FLAGS_64_BIT_ADDRESSING);
adam radford9c915a82010-12-21 13:34:31 -08001749
1750 if (scp->sc_data_direction == PCI_DMA_TODEVICE)
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301751 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_WRITE);
adam radford9c915a82010-12-21 13:34:31 -08001752 else if (scp->sc_data_direction == PCI_DMA_FROMDEVICE)
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301753 io_request->Control |= cpu_to_le32(MPI2_SCSIIO_CONTROL_READ);
adam radford9c915a82010-12-21 13:34:31 -08001754
1755 io_request->SGLOffset0 =
1756 offsetof(struct MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4;
1757
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301758 io_request->SenseBufferLowAddress = cpu_to_le32(cmd->sense_phys_addr);
adam radford9c915a82010-12-21 13:34:31 -08001759 io_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
1760
1761 cmd->scmd = scp;
1762 scp->SCp.ptr = (char *)cmd;
1763
1764 return 0;
1765}
1766
1767union MEGASAS_REQUEST_DESCRIPTOR_UNION *
1768megasas_get_request_descriptor(struct megasas_instance *instance, u16 index)
1769{
1770 u8 *p;
1771 struct fusion_context *fusion;
1772
1773 if (index >= instance->max_fw_cmds) {
1774 printk(KERN_ERR "megasas: Invalid SMID (0x%x)request for "
1775 "descriptor\n", index);
1776 return NULL;
1777 }
1778 fusion = instance->ctrl_context;
1779 p = fusion->req_frames_desc
1780 +sizeof(union MEGASAS_REQUEST_DESCRIPTOR_UNION) *index;
1781
1782 return (union MEGASAS_REQUEST_DESCRIPTOR_UNION *)p;
1783}
1784
1785/**
1786 * megasas_build_and_issue_cmd_fusion -Main routine for building and
1787 * issuing non IOCTL cmd
1788 * @instance: Adapter soft state
1789 * @scmd: pointer to scsi cmd from OS
1790 */
1791static u32
1792megasas_build_and_issue_cmd_fusion(struct megasas_instance *instance,
1793 struct scsi_cmnd *scmd)
1794{
1795 struct megasas_cmd_fusion *cmd;
1796 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
1797 u32 index;
1798 struct fusion_context *fusion;
1799
1800 fusion = instance->ctrl_context;
1801
1802 cmd = megasas_get_cmd_fusion(instance);
1803 if (!cmd)
1804 return SCSI_MLQUEUE_HOST_BUSY;
1805
1806 index = cmd->index;
1807
1808 req_desc = megasas_get_request_descriptor(instance, index-1);
1809 if (!req_desc)
1810 return 1;
1811
1812 req_desc->Words = 0;
1813 cmd->request_desc = req_desc;
adam radford9c915a82010-12-21 13:34:31 -08001814
1815 if (megasas_build_io_fusion(instance, scmd, cmd)) {
1816 megasas_return_cmd_fusion(instance, cmd);
1817 printk(KERN_ERR "megasas: Error building command.\n");
1818 cmd->request_desc = NULL;
1819 return 1;
1820 }
1821
1822 req_desc = cmd->request_desc;
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301823 req_desc->SCSIIO.SMID = cpu_to_le16(index);
adam radford9c915a82010-12-21 13:34:31 -08001824
1825 if (cmd->io_request->ChainOffset != 0 &&
1826 cmd->io_request->ChainOffset != 0xF)
1827 printk(KERN_ERR "megasas: The chain offset value is not "
1828 "correct : %x\n", cmd->io_request->ChainOffset);
1829
1830 /*
1831 * Issue the command to the FW
1832 */
1833 atomic_inc(&instance->fw_outstanding);
1834
1835 instance->instancet->fire_cmd(instance,
1836 req_desc->u.low, req_desc->u.high,
1837 instance->reg_set);
1838
1839 return 0;
1840}
1841
1842/**
1843 * complete_cmd_fusion - Completes command
1844 * @instance: Adapter soft state
1845 * Completes all commands that is in reply descriptor queue
1846 */
1847int
adam radfordc8e858f2011-10-08 18:15:13 -07001848complete_cmd_fusion(struct megasas_instance *instance, u32 MSIxIndex)
adam radford9c915a82010-12-21 13:34:31 -08001849{
1850 union MPI2_REPLY_DESCRIPTORS_UNION *desc;
1851 struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *reply_desc;
1852 struct MPI2_RAID_SCSI_IO_REQUEST *scsi_io_req;
1853 struct fusion_context *fusion;
1854 struct megasas_cmd *cmd_mfi;
1855 struct megasas_cmd_fusion *cmd_fusion;
1856 u16 smid, num_completed;
1857 u8 reply_descript_type, arm;
1858 u32 status, extStatus, device_id;
1859 union desc_value d_val;
1860 struct LD_LOAD_BALANCE_INFO *lbinfo;
1861
1862 fusion = instance->ctrl_context;
1863
1864 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR)
1865 return IRQ_HANDLED;
1866
1867 desc = fusion->reply_frames_desc;
adam radfordc8e858f2011-10-08 18:15:13 -07001868 desc += ((MSIxIndex * fusion->reply_alloc_sz)/
1869 sizeof(union MPI2_REPLY_DESCRIPTORS_UNION)) +
1870 fusion->last_reply_idx[MSIxIndex];
adam radford9c915a82010-12-21 13:34:31 -08001871
1872 reply_desc = (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
1873
1874 d_val.word = desc->Words;
1875
1876 reply_descript_type = reply_desc->ReplyFlags &
1877 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
1878
1879 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
1880 return IRQ_NONE;
1881
adam radford9c915a82010-12-21 13:34:31 -08001882 num_completed = 0;
1883
1884 while ((d_val.u.low != UINT_MAX) && (d_val.u.high != UINT_MAX)) {
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05301885 smid = le16_to_cpu(reply_desc->SMID);
adam radford9c915a82010-12-21 13:34:31 -08001886
1887 cmd_fusion = fusion->cmd_list[smid - 1];
1888
1889 scsi_io_req =
1890 (struct MPI2_RAID_SCSI_IO_REQUEST *)
1891 cmd_fusion->io_request;
1892
1893 if (cmd_fusion->scmd)
1894 cmd_fusion->scmd->SCp.ptr = NULL;
1895
1896 status = scsi_io_req->RaidContext.status;
1897 extStatus = scsi_io_req->RaidContext.exStatus;
1898
1899 switch (scsi_io_req->Function) {
1900 case MPI2_FUNCTION_SCSI_IO_REQUEST: /*Fast Path IO.*/
1901 /* Update load balancing info */
1902 device_id = MEGASAS_DEV_INDEX(instance,
1903 cmd_fusion->scmd);
1904 lbinfo = &fusion->load_balance_info[device_id];
1905 if (cmd_fusion->scmd->SCp.Status &
1906 MEGASAS_LOAD_BALANCE_FLAG) {
1907 arm = lbinfo->raid1DevHandle[0] ==
1908 cmd_fusion->io_request->DevHandle ? 0 :
1909 1;
1910 atomic_dec(&lbinfo->scsi_pending_cmds[arm]);
1911 cmd_fusion->scmd->SCp.Status &=
1912 ~MEGASAS_LOAD_BALANCE_FLAG;
1913 }
1914 if (reply_descript_type ==
1915 MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) {
1916 if (megasas_dbg_lvl == 5)
1917 printk(KERN_ERR "\nmegasas: FAST Path "
1918 "IO Success\n");
1919 }
1920 /* Fall thru and complete IO */
1921 case MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST: /* LD-IO Path */
1922 /* Map the FW Cmd Status */
1923 map_cmd_status(cmd_fusion, status, extStatus);
1924 scsi_dma_unmap(cmd_fusion->scmd);
1925 cmd_fusion->scmd->scsi_done(cmd_fusion->scmd);
1926 scsi_io_req->RaidContext.status = 0;
1927 scsi_io_req->RaidContext.exStatus = 0;
1928 megasas_return_cmd_fusion(instance, cmd_fusion);
1929 atomic_dec(&instance->fw_outstanding);
1930
1931 break;
1932 case MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST: /*MFI command */
1933 cmd_mfi = instance->cmd_list[cmd_fusion->sync_cmd_idx];
1934 megasas_complete_cmd(instance, cmd_mfi, DID_OK);
1935 cmd_fusion->flags = 0;
1936 megasas_return_cmd_fusion(instance, cmd_fusion);
1937
1938 break;
1939 }
1940
adam radfordc8e858f2011-10-08 18:15:13 -07001941 fusion->last_reply_idx[MSIxIndex]++;
1942 if (fusion->last_reply_idx[MSIxIndex] >=
1943 fusion->reply_q_depth)
1944 fusion->last_reply_idx[MSIxIndex] = 0;
adam radford9c915a82010-12-21 13:34:31 -08001945
1946 desc->Words = ULLONG_MAX;
1947 num_completed++;
1948
1949 /* Get the next reply descriptor */
adam radfordc8e858f2011-10-08 18:15:13 -07001950 if (!fusion->last_reply_idx[MSIxIndex])
1951 desc = fusion->reply_frames_desc +
1952 ((MSIxIndex * fusion->reply_alloc_sz)/
1953 sizeof(union MPI2_REPLY_DESCRIPTORS_UNION));
adam radford9c915a82010-12-21 13:34:31 -08001954 else
1955 desc++;
1956
1957 reply_desc =
1958 (struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR *)desc;
1959
1960 d_val.word = desc->Words;
1961
1962 reply_descript_type = reply_desc->ReplyFlags &
1963 MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
1964
1965 if (reply_descript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
1966 break;
1967 }
1968
1969 if (!num_completed)
1970 return IRQ_NONE;
1971
1972 wmb();
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +05301973 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
1974 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY))
1975 writel(((MSIxIndex & 0x7) << 24) |
1976 fusion->last_reply_idx[MSIxIndex],
1977 instance->reply_post_host_index_addr[MSIxIndex/8]);
1978 else
1979 writel((MSIxIndex << 24) |
1980 fusion->last_reply_idx[MSIxIndex],
1981 instance->reply_post_host_index_addr[0]);
adam radford53ef2bb2011-02-24 20:56:05 -08001982 megasas_check_and_restore_queue_depth(instance);
adam radford9c915a82010-12-21 13:34:31 -08001983 return IRQ_HANDLED;
1984}
1985
1986/**
1987 * megasas_complete_cmd_dpc_fusion - Completes command
1988 * @instance: Adapter soft state
1989 *
1990 * Tasklet to complete cmds
1991 */
1992void
1993megasas_complete_cmd_dpc_fusion(unsigned long instance_addr)
1994{
1995 struct megasas_instance *instance =
1996 (struct megasas_instance *)instance_addr;
1997 unsigned long flags;
adam radfordc8e858f2011-10-08 18:15:13 -07001998 u32 count, MSIxIndex;
1999
2000 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
adam radford9c915a82010-12-21 13:34:31 -08002001
2002 /* If we have already declared adapter dead, donot complete cmds */
2003 spin_lock_irqsave(&instance->hba_lock, flags);
2004 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
2005 spin_unlock_irqrestore(&instance->hba_lock, flags);
2006 return;
2007 }
2008 spin_unlock_irqrestore(&instance->hba_lock, flags);
2009
adam radfordc8e858f2011-10-08 18:15:13 -07002010 for (MSIxIndex = 0 ; MSIxIndex < count; MSIxIndex++)
2011 complete_cmd_fusion(instance, MSIxIndex);
adam radford9c915a82010-12-21 13:34:31 -08002012}
2013
2014/**
2015 * megasas_isr_fusion - isr entry point
2016 */
2017irqreturn_t megasas_isr_fusion(int irq, void *devp)
2018{
adam radfordc8e858f2011-10-08 18:15:13 -07002019 struct megasas_irq_context *irq_context = devp;
2020 struct megasas_instance *instance = irq_context->instance;
adam radford9c915a82010-12-21 13:34:31 -08002021 u32 mfiStatus, fw_state;
2022
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +05302023 if (instance->mask_interrupts)
2024 return IRQ_NONE;
2025
adam radfordc8e858f2011-10-08 18:15:13 -07002026 if (!instance->msix_vectors) {
adam radford9c915a82010-12-21 13:34:31 -08002027 mfiStatus = instance->instancet->clear_intr(instance->reg_set);
2028 if (!mfiStatus)
2029 return IRQ_NONE;
2030 }
2031
2032 /* If we are resetting, bail */
adam radford6497b242011-10-08 18:14:50 -07002033 if (test_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags)) {
2034 instance->instancet->clear_intr(instance->reg_set);
adam radford9c915a82010-12-21 13:34:31 -08002035 return IRQ_HANDLED;
adam radford6497b242011-10-08 18:14:50 -07002036 }
adam radford9c915a82010-12-21 13:34:31 -08002037
adam radfordc8e858f2011-10-08 18:15:13 -07002038 if (!complete_cmd_fusion(instance, irq_context->MSIxIndex)) {
adam radford6497b242011-10-08 18:14:50 -07002039 instance->instancet->clear_intr(instance->reg_set);
adam radford9c915a82010-12-21 13:34:31 -08002040 /* If we didn't complete any commands, check for FW fault */
2041 fw_state = instance->instancet->read_fw_status_reg(
2042 instance->reg_set) & MFI_STATE_MASK;
2043 if (fw_state == MFI_STATE_FAULT)
2044 schedule_work(&instance->work_init);
2045 }
2046
2047 return IRQ_HANDLED;
2048}
2049
2050/**
2051 * build_mpt_mfi_pass_thru - builds a cmd fo MFI Pass thru
2052 * @instance: Adapter soft state
2053 * mfi_cmd: megasas_cmd pointer
2054 *
2055 */
2056u8
2057build_mpt_mfi_pass_thru(struct megasas_instance *instance,
2058 struct megasas_cmd *mfi_cmd)
2059{
2060 struct MPI25_IEEE_SGE_CHAIN64 *mpi25_ieee_chain;
2061 struct MPI2_RAID_SCSI_IO_REQUEST *io_req;
2062 struct megasas_cmd_fusion *cmd;
2063 struct fusion_context *fusion;
2064 struct megasas_header *frame_hdr = &mfi_cmd->frame->hdr;
2065
2066 cmd = megasas_get_cmd_fusion(instance);
2067 if (!cmd)
2068 return 1;
2069
2070 /* Save the smid. To be used for returning the cmd */
2071 mfi_cmd->context.smid = cmd->index;
2072
2073 cmd->sync_cmd_idx = mfi_cmd->index;
2074
2075 /*
2076 * For cmds where the flag is set, store the flag and check
2077 * on completion. For cmds with this flag, don't call
2078 * megasas_complete_cmd
2079 */
2080
2081 if (frame_hdr->flags & MFI_FRAME_DONT_POST_IN_REPLY_QUEUE)
2082 cmd->flags = MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
2083
2084 fusion = instance->ctrl_context;
2085 io_req = cmd->io_request;
adam radford36807e62011-10-08 18:15:06 -07002086
Sumit.Saxena@lsi.com21d3c712013-05-22 12:31:43 +05302087 if ((instance->pdev->device == PCI_DEVICE_ID_LSI_INVADER) ||
2088 (instance->pdev->device == PCI_DEVICE_ID_LSI_FURY)) {
adam radford36807e62011-10-08 18:15:06 -07002089 struct MPI25_IEEE_SGE_CHAIN64 *sgl_ptr_end =
2090 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL;
2091 sgl_ptr_end += fusion->max_sge_in_main_msg - 1;
2092 sgl_ptr_end->Flags = 0;
2093 }
2094
adam radford9c915a82010-12-21 13:34:31 -08002095 mpi25_ieee_chain =
2096 (struct MPI25_IEEE_SGE_CHAIN64 *)&io_req->SGL.IeeeChain;
2097
2098 io_req->Function = MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST;
2099 io_req->SGLOffset0 = offsetof(struct MPI2_RAID_SCSI_IO_REQUEST,
2100 SGL) / 4;
2101 io_req->ChainOffset = fusion->chain_offset_mfi_pthru;
2102
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05302103 mpi25_ieee_chain->Address = cpu_to_le64(mfi_cmd->frame_phys_addr);
adam radford9c915a82010-12-21 13:34:31 -08002104
2105 mpi25_ieee_chain->Flags = IEEE_SGE_FLAGS_CHAIN_ELEMENT |
2106 MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR;
2107
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05302108 mpi25_ieee_chain->Length = cpu_to_le32(MEGASAS_MAX_SZ_CHAIN_FRAME);
adam radford9c915a82010-12-21 13:34:31 -08002109
2110 return 0;
2111}
2112
2113/**
2114 * build_mpt_cmd - Calls helper function to build a cmd MFI Pass thru cmd
2115 * @instance: Adapter soft state
2116 * @cmd: mfi cmd to build
2117 *
2118 */
2119union MEGASAS_REQUEST_DESCRIPTOR_UNION *
2120build_mpt_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd)
2121{
2122 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
2123 u16 index;
2124
2125 if (build_mpt_mfi_pass_thru(instance, cmd)) {
2126 printk(KERN_ERR "Couldn't build MFI pass thru cmd\n");
2127 return NULL;
2128 }
2129
2130 index = cmd->context.smid;
2131
2132 req_desc = megasas_get_request_descriptor(instance, index - 1);
2133
2134 if (!req_desc)
2135 return NULL;
2136
2137 req_desc->Words = 0;
2138 req_desc->SCSIIO.RequestFlags = (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
2139 MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
2140
Sumit.Saxena@lsi.com94cd65d2013-09-06 15:50:52 +05302141 req_desc->SCSIIO.SMID = cpu_to_le16(index);
adam radford9c915a82010-12-21 13:34:31 -08002142
2143 return req_desc;
2144}
2145
2146/**
2147 * megasas_issue_dcmd_fusion - Issues a MFI Pass thru cmd
2148 * @instance: Adapter soft state
2149 * @cmd: mfi cmd pointer
2150 *
2151 */
2152void
2153megasas_issue_dcmd_fusion(struct megasas_instance *instance,
2154 struct megasas_cmd *cmd)
2155{
2156 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
adam radford9c915a82010-12-21 13:34:31 -08002157
2158 req_desc = build_mpt_cmd(instance, cmd);
2159 if (!req_desc) {
2160 printk(KERN_ERR "Couldn't issue MFI pass thru cmd\n");
2161 return;
2162 }
adam radford9c915a82010-12-21 13:34:31 -08002163 instance->instancet->fire_cmd(instance, req_desc->u.low,
2164 req_desc->u.high, instance->reg_set);
2165}
2166
2167/**
2168 * megasas_release_fusion - Reverses the FW initialization
2169 * @intance: Adapter soft state
2170 */
2171void
2172megasas_release_fusion(struct megasas_instance *instance)
2173{
2174 megasas_free_cmds(instance);
2175 megasas_free_cmds_fusion(instance);
2176
2177 iounmap(instance->reg_set);
2178
2179 pci_release_selected_regions(instance->pdev, instance->bar);
2180}
2181
2182/**
2183 * megasas_read_fw_status_reg_fusion - returns the current FW status value
2184 * @regs: MFI register set
2185 */
2186static u32
2187megasas_read_fw_status_reg_fusion(struct megasas_register_set __iomem *regs)
2188{
2189 return readl(&(regs)->outbound_scratch_pad);
2190}
2191
2192/**
2193 * megasas_adp_reset_fusion - For controller reset
2194 * @regs: MFI register set
2195 */
2196static int
2197megasas_adp_reset_fusion(struct megasas_instance *instance,
2198 struct megasas_register_set __iomem *regs)
2199{
2200 return 0;
2201}
2202
2203/**
2204 * megasas_check_reset_fusion - For controller reset check
2205 * @regs: MFI register set
2206 */
2207static int
2208megasas_check_reset_fusion(struct megasas_instance *instance,
2209 struct megasas_register_set __iomem *regs)
2210{
2211 return 0;
2212}
2213
2214/* This function waits for outstanding commands on fusion to complete */
2215int megasas_wait_for_outstanding_fusion(struct megasas_instance *instance)
2216{
2217 int i, outstanding, retval = 0;
adam radfordc007b8b2012-07-17 18:20:24 -07002218 u32 fw_state;
adam radford9c915a82010-12-21 13:34:31 -08002219
adam radfordc007b8b2012-07-17 18:20:24 -07002220 for (i = 0; i < resetwaittime; i++) {
adam radford9c915a82010-12-21 13:34:31 -08002221 /* Check if firmware is in fault state */
2222 fw_state = instance->instancet->read_fw_status_reg(
2223 instance->reg_set) & MFI_STATE_MASK;
2224 if (fw_state == MFI_STATE_FAULT) {
2225 printk(KERN_WARNING "megasas: Found FW in FAULT state,"
2226 " will reset adapter.\n");
2227 retval = 1;
2228 goto out;
2229 }
2230
2231 outstanding = atomic_read(&instance->fw_outstanding);
2232 if (!outstanding)
2233 goto out;
2234
2235 if (!(i % MEGASAS_RESET_NOTICE_INTERVAL)) {
2236 printk(KERN_NOTICE "megasas: [%2d]waiting for %d "
2237 "commands to complete\n", i, outstanding);
2238 megasas_complete_cmd_dpc_fusion(
2239 (unsigned long)instance);
2240 }
2241 msleep(1000);
2242 }
2243
2244 if (atomic_read(&instance->fw_outstanding)) {
2245 printk("megaraid_sas: pending commands remain after waiting, "
2246 "will reset adapter.\n");
2247 retval = 1;
2248 }
2249out:
2250 return retval;
2251}
2252
2253void megasas_reset_reply_desc(struct megasas_instance *instance)
2254{
adam radfordc8e858f2011-10-08 18:15:13 -07002255 int i, count;
adam radford9c915a82010-12-21 13:34:31 -08002256 struct fusion_context *fusion;
2257 union MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
2258
2259 fusion = instance->ctrl_context;
adam radfordc8e858f2011-10-08 18:15:13 -07002260 count = instance->msix_vectors > 0 ? instance->msix_vectors : 1;
2261 for (i = 0 ; i < count ; i++)
2262 fusion->last_reply_idx[i] = 0;
adam radford9c915a82010-12-21 13:34:31 -08002263 reply_desc = fusion->reply_frames_desc;
adam radfordc8e858f2011-10-08 18:15:13 -07002264 for (i = 0 ; i < fusion->reply_q_depth * count; i++, reply_desc++)
adam radford9c915a82010-12-21 13:34:31 -08002265 reply_desc->Words = ULLONG_MAX;
2266}
2267
2268/* Core fusion reset function */
2269int megasas_reset_fusion(struct Scsi_Host *shost)
2270{
2271 int retval = SUCCESS, i, j, retry = 0;
2272 struct megasas_instance *instance;
2273 struct megasas_cmd_fusion *cmd_fusion;
2274 struct fusion_context *fusion;
2275 struct megasas_cmd *cmd_mfi;
2276 union MEGASAS_REQUEST_DESCRIPTOR_UNION *req_desc;
adam radford7e70e732011-05-11 18:34:08 -07002277 u32 host_diag, abs_state, status_reg, reset_adapter;
adam radford9c915a82010-12-21 13:34:31 -08002278
2279 instance = (struct megasas_instance *)shost->hostdata;
2280 fusion = instance->ctrl_context;
2281
adam radford9c915a82010-12-21 13:34:31 -08002282 if (instance->adprecovery == MEGASAS_HW_CRITICAL_ERROR) {
2283 printk(KERN_WARNING "megaraid_sas: Hardware critical error, "
2284 "returning FAILED.\n");
adam radfordd4a759a2011-10-08 18:14:39 -07002285 return FAILED;
adam radford9c915a82010-12-21 13:34:31 -08002286 }
2287
adam radford7e70e732011-05-11 18:34:08 -07002288 mutex_lock(&instance->reset_mutex);
2289 set_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
2290 instance->adprecovery = MEGASAS_ADPRESET_SM_INFAULT;
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +05302291 instance->instancet->disable_intr(instance);
adam radford7e70e732011-05-11 18:34:08 -07002292 msleep(1000);
2293
adam radford9c915a82010-12-21 13:34:31 -08002294 /* First try waiting for commands to complete */
2295 if (megasas_wait_for_outstanding_fusion(instance)) {
2296 printk(KERN_WARNING "megaraid_sas: resetting fusion "
2297 "adapter.\n");
2298 /* Now return commands back to the OS */
2299 for (i = 0 ; i < instance->max_fw_cmds; i++) {
2300 cmd_fusion = fusion->cmd_list[i];
2301 if (cmd_fusion->scmd) {
2302 scsi_dma_unmap(cmd_fusion->scmd);
2303 cmd_fusion->scmd->result = (DID_RESET << 16);
2304 cmd_fusion->scmd->scsi_done(cmd_fusion->scmd);
2305 megasas_return_cmd_fusion(instance, cmd_fusion);
2306 atomic_dec(&instance->fw_outstanding);
2307 }
2308 }
2309
adam radford7e70e732011-05-11 18:34:08 -07002310 status_reg = instance->instancet->read_fw_status_reg(
2311 instance->reg_set);
2312 abs_state = status_reg & MFI_STATE_MASK;
2313 reset_adapter = status_reg & MFI_RESET_ADAPTER;
2314 if (instance->disableOnlineCtrlReset ||
2315 (abs_state == MFI_STATE_FAULT && !reset_adapter)) {
adam radford9c915a82010-12-21 13:34:31 -08002316 /* Reset not supported, kill adapter */
2317 printk(KERN_WARNING "megaraid_sas: Reset not supported"
2318 ", killing adapter.\n");
2319 megaraid_sas_kill_hba(instance);
2320 instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
2321 retval = FAILED;
2322 goto out;
2323 }
2324
2325 /* Now try to reset the chip */
2326 for (i = 0; i < MEGASAS_FUSION_MAX_RESET_TRIES; i++) {
2327 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE,
2328 &instance->reg_set->fusion_seq_offset);
2329 writel(MPI2_WRSEQ_1ST_KEY_VALUE,
2330 &instance->reg_set->fusion_seq_offset);
2331 writel(MPI2_WRSEQ_2ND_KEY_VALUE,
2332 &instance->reg_set->fusion_seq_offset);
2333 writel(MPI2_WRSEQ_3RD_KEY_VALUE,
2334 &instance->reg_set->fusion_seq_offset);
2335 writel(MPI2_WRSEQ_4TH_KEY_VALUE,
2336 &instance->reg_set->fusion_seq_offset);
2337 writel(MPI2_WRSEQ_5TH_KEY_VALUE,
2338 &instance->reg_set->fusion_seq_offset);
2339 writel(MPI2_WRSEQ_6TH_KEY_VALUE,
2340 &instance->reg_set->fusion_seq_offset);
2341
2342 /* Check that the diag write enable (DRWE) bit is on */
2343 host_diag = readl(&instance->reg_set->fusion_host_diag);
adam radford7e70e732011-05-11 18:34:08 -07002344 retry = 0;
adam radford9c915a82010-12-21 13:34:31 -08002345 while (!(host_diag & HOST_DIAG_WRITE_ENABLE)) {
2346 msleep(100);
2347 host_diag =
2348 readl(&instance->reg_set->fusion_host_diag);
2349 if (retry++ == 100) {
2350 printk(KERN_WARNING "megaraid_sas: "
2351 "Host diag unlock failed!\n");
2352 break;
2353 }
2354 }
2355 if (!(host_diag & HOST_DIAG_WRITE_ENABLE))
2356 continue;
2357
2358 /* Send chip reset command */
2359 writel(host_diag | HOST_DIAG_RESET_ADAPTER,
2360 &instance->reg_set->fusion_host_diag);
2361 msleep(3000);
2362
2363 /* Make sure reset adapter bit is cleared */
2364 host_diag = readl(&instance->reg_set->fusion_host_diag);
2365 retry = 0;
2366 while (host_diag & HOST_DIAG_RESET_ADAPTER) {
2367 msleep(100);
2368 host_diag =
2369 readl(&instance->reg_set->fusion_host_diag);
2370 if (retry++ == 1000) {
2371 printk(KERN_WARNING "megaraid_sas: "
2372 "Diag reset adapter never "
2373 "cleared!\n");
2374 break;
2375 }
2376 }
2377 if (host_diag & HOST_DIAG_RESET_ADAPTER)
2378 continue;
2379
2380 abs_state =
2381 instance->instancet->read_fw_status_reg(
adam radford7e70e732011-05-11 18:34:08 -07002382 instance->reg_set) & MFI_STATE_MASK;
adam radford9c915a82010-12-21 13:34:31 -08002383 retry = 0;
2384
2385 while ((abs_state <= MFI_STATE_FW_INIT) &&
2386 (retry++ < 1000)) {
2387 msleep(100);
2388 abs_state =
2389 instance->instancet->read_fw_status_reg(
adam radford7e70e732011-05-11 18:34:08 -07002390 instance->reg_set) & MFI_STATE_MASK;
adam radford9c915a82010-12-21 13:34:31 -08002391 }
2392 if (abs_state <= MFI_STATE_FW_INIT) {
2393 printk(KERN_WARNING "megaraid_sas: firmware "
2394 "state < MFI_STATE_FW_INIT, state = "
2395 "0x%x\n", abs_state);
2396 continue;
2397 }
2398
2399 /* Wait for FW to become ready */
adam radford058a8fa2011-10-08 18:14:27 -07002400 if (megasas_transition_to_ready(instance, 1)) {
adam radford9c915a82010-12-21 13:34:31 -08002401 printk(KERN_WARNING "megaraid_sas: Failed to "
2402 "transition controller to ready.\n");
2403 continue;
2404 }
2405
2406 megasas_reset_reply_desc(instance);
2407 if (megasas_ioc_init_fusion(instance)) {
2408 printk(KERN_WARNING "megaraid_sas: "
2409 "megasas_ioc_init_fusion() failed!\n");
2410 continue;
2411 }
2412
adam radford3f0e58bc2011-10-08 18:14:59 -07002413 clear_bit(MEGASAS_FUSION_IN_RESET,
2414 &instance->reset_flags);
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +05302415 instance->instancet->enable_intr(instance);
adam radford9c915a82010-12-21 13:34:31 -08002416 instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
2417
2418 /* Re-fire management commands */
2419 for (j = 0 ; j < instance->max_fw_cmds; j++) {
2420 cmd_fusion = fusion->cmd_list[j];
2421 if (cmd_fusion->sync_cmd_idx !=
2422 (u32)ULONG_MAX) {
2423 cmd_mfi =
2424 instance->
2425 cmd_list[cmd_fusion->sync_cmd_idx];
2426 if (cmd_mfi->frame->dcmd.opcode ==
Sumit.Saxena@lsi.combe263742014-02-12 23:37:46 +05302427 cpu_to_le32(MR_DCMD_LD_MAP_GET_INFO)) {
adam radford9c915a82010-12-21 13:34:31 -08002428 megasas_return_cmd(instance,
2429 cmd_mfi);
2430 megasas_return_cmd_fusion(
2431 instance, cmd_fusion);
2432 } else {
2433 req_desc =
2434 megasas_get_request_descriptor(
2435 instance,
2436 cmd_mfi->context.smid
2437 -1);
2438 if (!req_desc)
2439 printk(KERN_WARNING
2440 "req_desc NULL"
2441 "\n");
2442 else {
2443 instance->instancet->
2444 fire_cmd(instance,
2445 req_desc->
2446 u.low,
2447 req_desc->
2448 u.high,
2449 instance->
2450 reg_set);
2451 }
2452 }
2453 }
2454 }
2455
2456 /* Reset load balance info */
2457 memset(fusion->load_balance_info, 0,
2458 sizeof(struct LD_LOAD_BALANCE_INFO)
2459 *MAX_LOGICAL_DRIVES);
2460
2461 if (!megasas_get_map_info(instance))
2462 megasas_sync_map_info(instance);
2463
2464 /* Adapter reset completed successfully */
2465 printk(KERN_WARNING "megaraid_sas: Reset "
2466 "successful.\n");
2467 retval = SUCCESS;
2468 goto out;
2469 }
2470 /* Reset failed, kill the adapter */
2471 printk(KERN_WARNING "megaraid_sas: Reset failed, killing "
2472 "adapter.\n");
2473 megaraid_sas_kill_hba(instance);
Sumit.Saxena@lsi.comcfbe7552014-02-12 23:36:15 +05302474 instance->adprecovery = MEGASAS_HW_CRITICAL_ERROR;
adam radford9c915a82010-12-21 13:34:31 -08002475 retval = FAILED;
2476 } else {
adam radford3f0e58bc2011-10-08 18:14:59 -07002477 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
Sumit.Saxena@lsi.comd46a3ad2013-05-22 12:34:14 +05302478 instance->instancet->enable_intr(instance);
adam radford9c915a82010-12-21 13:34:31 -08002479 instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
2480 }
2481out:
2482 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags);
2483 mutex_unlock(&instance->reset_mutex);
2484 return retval;
2485}
2486
2487/* Fusion OCR work queue */
2488void megasas_fusion_ocr_wq(struct work_struct *work)
2489{
2490 struct megasas_instance *instance =
2491 container_of(work, struct megasas_instance, work_init);
2492
2493 megasas_reset_fusion(instance->host);
2494}
2495
2496struct megasas_instance_template megasas_instance_template_fusion = {
2497 .fire_cmd = megasas_fire_cmd_fusion,
2498 .enable_intr = megasas_enable_intr_fusion,
2499 .disable_intr = megasas_disable_intr_fusion,
2500 .clear_intr = megasas_clear_intr_fusion,
2501 .read_fw_status_reg = megasas_read_fw_status_reg_fusion,
2502 .adp_reset = megasas_adp_reset_fusion,
2503 .check_reset = megasas_check_reset_fusion,
2504 .service_isr = megasas_isr_fusion,
2505 .tasklet = megasas_complete_cmd_dpc_fusion,
2506 .init_adapter = megasas_init_adapter_fusion,
2507 .build_and_issue_cmd = megasas_build_and_issue_cmd_fusion,
2508 .issue_dcmd = megasas_issue_dcmd_fusion,
2509};