2 * This is the Fusion MPT base driver providing common API layer interface
3 * for access to MPT (Message Passing Technology) firmware.
5 * This code is based on drivers/scsi/mpt2sas/mpt2_base.c
6 * Copyright (C) 2007-2010 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h>
54 #include <linux/delay.h>
55 #include <linux/interrupt.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/sort.h>
59 #include <linux/time.h>
60 #include <linux/kthread.h>
61 #include <linux/aer.h>
63 #include "mpt2sas_base.h"
65 static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS];
67 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
69 static int max_queue_depth = -1;
70 module_param(max_queue_depth, int, 0);
71 MODULE_PARM_DESC(max_queue_depth, " max controller queue depth ");
73 static int max_sgl_entries = -1;
74 module_param(max_sgl_entries, int, 0);
75 MODULE_PARM_DESC(max_sgl_entries, " max sg entries ");
77 static int msix_disable = -1;
78 module_param(msix_disable, int, 0);
79 MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)");
81 static int missing_delay[2] = {-1, -1};
82 module_param_array(missing_delay, int, NULL, 0);
83 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
85 static int mpt2sas_fwfault_debug;
86 MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
87 "and halt firmware - (default=0)");
89 static int disable_discovery = -1;
90 module_param(disable_discovery, int, 0);
91 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
94 /* diag_buffer_enable is bitwise
96 * bit 1 set = SNAPSHOT
97 * bit 2 set = EXTENDED
99 * Either bit can be set, or both
101 static int diag_buffer_enable;
102 module_param(diag_buffer_enable, int, 0);
103 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
104 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
107 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
111 _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
113 int ret = param_set_int(val, kp);
114 struct MPT2SAS_ADAPTER *ioc;
119 printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
120 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
121 ioc->fwfault_debug = mpt2sas_fwfault_debug;
125 module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug,
126 param_get_int, &mpt2sas_fwfault_debug, 0644);
129 * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc
130 * @arg: input argument, used to derive ioc
132 * Return 0 if controller is removed from pci subsystem.
133 * Return -1 for other case.
135 static int mpt2sas_remove_dead_ioc_func(void *arg)
137 struct MPT2SAS_ADAPTER *ioc = (struct MPT2SAS_ADAPTER *)arg;
138 struct pci_dev *pdev;
146 pci_remove_bus_device(pdev);
152 * _base_fault_reset_work - workq handling ioc fault conditions
153 * @work: input argument, used to derive ioc
159 _base_fault_reset_work(struct work_struct *work)
161 struct MPT2SAS_ADAPTER *ioc =
162 container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
166 struct task_struct *p;
168 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
169 if (ioc->shost_recovery)
171 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
173 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
174 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) {
175 printk(MPT2SAS_INFO_FMT "%s : SAS host is non-operational !!!!\n",
176 ioc->name, __func__);
179 * Call _scsih_flush_pending_cmds callback so that we flush all
180 * pending commands back to OS. This call is required to aovid
181 * deadlock at block layer. Dead IOC will fail to do diag reset,
182 * and this call is safe since dead ioc will never return any
183 * command back from HW.
185 ioc->schedule_dead_ioc_flush_running_cmds(ioc);
187 * Set remove_host flag early since kernel thread will
188 * take some time to execute.
190 ioc->remove_host = 1;
191 /*Remove the Dead Host */
192 p = kthread_run(mpt2sas_remove_dead_ioc_func, ioc,
193 "mpt2sas_dead_ioc_%d", ioc->id);
195 printk(MPT2SAS_ERR_FMT
196 "%s: Running mpt2sas_dead_ioc thread failed !!!!\n",
197 ioc->name, __func__);
199 printk(MPT2SAS_ERR_FMT
200 "%s: Running mpt2sas_dead_ioc thread success !!!!\n",
201 ioc->name, __func__);
204 return; /* don't rearm timer */
207 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
208 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
210 printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
211 __func__, (rc == 0) ? "success" : "failed");
212 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
213 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
214 mpt2sas_base_fault_info(ioc, doorbell &
215 MPI2_DOORBELL_DATA_MASK);
218 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
220 if (ioc->fault_reset_work_q)
221 queue_delayed_work(ioc->fault_reset_work_q,
222 &ioc->fault_reset_work,
223 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
224 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
228 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
229 * @ioc: per adapter object
235 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
239 if (ioc->fault_reset_work_q)
242 /* initialize fault polling */
243 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
244 snprintf(ioc->fault_reset_work_q_name,
245 sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
246 ioc->fault_reset_work_q =
247 create_singlethread_workqueue(ioc->fault_reset_work_q_name);
248 if (!ioc->fault_reset_work_q) {
249 printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
250 ioc->name, __func__, __LINE__);
253 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
254 if (ioc->fault_reset_work_q)
255 queue_delayed_work(ioc->fault_reset_work_q,
256 &ioc->fault_reset_work,
257 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
258 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
262 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
263 * @ioc: per adapter object
269 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
272 struct workqueue_struct *wq;
274 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
275 wq = ioc->fault_reset_work_q;
276 ioc->fault_reset_work_q = NULL;
277 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
279 if (!cancel_delayed_work(&ioc->fault_reset_work))
281 destroy_workqueue(wq);
286 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
287 * @ioc: per adapter object
288 * @fault_code: fault code
293 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
295 printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
296 ioc->name, fault_code);
300 * mpt2sas_halt_firmware - halt's mpt controller firmware
301 * @ioc: per adapter object
303 * For debugging timeout related issues. Writing 0xCOFFEE00
304 * to the doorbell register will halt controller firmware. With
305 * the purpose to stop both driver and firmware, the enduser can
306 * obtain a ring buffer from controller UART.
309 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc)
313 if (!ioc->fwfault_debug)
318 doorbell = readl(&ioc->chip->Doorbell);
319 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
320 mpt2sas_base_fault_info(ioc , doorbell);
322 writel(0xC0FFEE00, &ioc->chip->Doorbell);
323 printk(MPT2SAS_ERR_FMT "Firmware is halted due to command "
324 "timeout\n", ioc->name);
327 panic("panic in %s\n", __func__);
330 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
332 * _base_sas_ioc_info - verbose translation of the ioc status
333 * @ioc: per adapter object
334 * @mpi_reply: reply mf payload returned from firmware
335 * @request_hdr: request mf
340 _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
341 MPI2RequestHeader_t *request_hdr)
343 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
347 char *func_str = NULL;
349 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
350 if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
351 request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
352 request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
355 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
358 switch (ioc_status) {
360 /****************************************************************************
361 * Common IOCStatus values for all replies
362 ****************************************************************************/
364 case MPI2_IOCSTATUS_INVALID_FUNCTION:
365 desc = "invalid function";
367 case MPI2_IOCSTATUS_BUSY:
370 case MPI2_IOCSTATUS_INVALID_SGL:
371 desc = "invalid sgl";
373 case MPI2_IOCSTATUS_INTERNAL_ERROR:
374 desc = "internal error";
376 case MPI2_IOCSTATUS_INVALID_VPID:
377 desc = "invalid vpid";
379 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
380 desc = "insufficient resources";
382 case MPI2_IOCSTATUS_INVALID_FIELD:
383 desc = "invalid field";
385 case MPI2_IOCSTATUS_INVALID_STATE:
386 desc = "invalid state";
388 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
389 desc = "op state not supported";
392 /****************************************************************************
393 * Config IOCStatus values
394 ****************************************************************************/
396 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
397 desc = "config invalid action";
399 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
400 desc = "config invalid type";
402 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
403 desc = "config invalid page";
405 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
406 desc = "config invalid data";
408 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
409 desc = "config no defaults";
411 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
412 desc = "config cant commit";
415 /****************************************************************************
417 ****************************************************************************/
419 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
420 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
421 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
422 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
423 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
424 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
425 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
426 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
427 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
428 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
429 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
430 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
433 /****************************************************************************
434 * For use by SCSI Initiator and SCSI Target end-to-end data protection
435 ****************************************************************************/
437 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
438 desc = "eedp guard error";
440 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
441 desc = "eedp ref tag error";
443 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
444 desc = "eedp app tag error";
447 /****************************************************************************
449 ****************************************************************************/
451 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
452 desc = "target invalid io index";
454 case MPI2_IOCSTATUS_TARGET_ABORTED:
455 desc = "target aborted";
457 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
458 desc = "target no conn retryable";
460 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
461 desc = "target no connection";
463 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
464 desc = "target xfer count mismatch";
466 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
467 desc = "target data offset error";
469 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
470 desc = "target too much write data";
472 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
473 desc = "target iu too short";
475 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
476 desc = "target ack nak timeout";
478 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
479 desc = "target nak received";
482 /****************************************************************************
483 * Serial Attached SCSI values
484 ****************************************************************************/
486 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
487 desc = "smp request failed";
489 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
490 desc = "smp data overrun";
493 /****************************************************************************
494 * Diagnostic Buffer Post / Diagnostic Release values
495 ****************************************************************************/
497 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
498 desc = "diagnostic released";
507 switch (request_hdr->Function) {
508 case MPI2_FUNCTION_CONFIG:
509 frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
510 func_str = "config_page";
512 case MPI2_FUNCTION_SCSI_TASK_MGMT:
513 frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
514 func_str = "task_mgmt";
516 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
517 frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
518 func_str = "sas_iounit_ctl";
520 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
521 frame_sz = sizeof(Mpi2SepRequest_t);
522 func_str = "enclosure";
524 case MPI2_FUNCTION_IOC_INIT:
525 frame_sz = sizeof(Mpi2IOCInitRequest_t);
526 func_str = "ioc_init";
528 case MPI2_FUNCTION_PORT_ENABLE:
529 frame_sz = sizeof(Mpi2PortEnableRequest_t);
530 func_str = "port_enable";
532 case MPI2_FUNCTION_SMP_PASSTHROUGH:
533 frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
534 func_str = "smp_passthru";
538 func_str = "unknown";
542 printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
543 " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
545 _debug_dump_mf(request_hdr, frame_sz/4);
549 * _base_display_event_data - verbose translation of firmware asyn events
550 * @ioc: per adapter object
551 * @mpi_reply: reply mf payload returned from firmware
556 _base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
557 Mpi2EventNotificationReply_t *mpi_reply)
562 if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
565 event = le16_to_cpu(mpi_reply->Event);
568 case MPI2_EVENT_LOG_DATA:
571 case MPI2_EVENT_STATE_CHANGE:
572 desc = "Status Change";
574 case MPI2_EVENT_HARD_RESET_RECEIVED:
575 desc = "Hard Reset Received";
577 case MPI2_EVENT_EVENT_CHANGE:
578 desc = "Event Change";
580 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
581 desc = "Device Status Change";
583 case MPI2_EVENT_IR_OPERATION_STATUS:
584 if (!ioc->hide_ir_msg)
585 desc = "IR Operation Status";
587 case MPI2_EVENT_SAS_DISCOVERY:
589 Mpi2EventDataSasDiscovery_t *event_data =
590 (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData;
591 printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name,
592 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
594 if (event_data->DiscoveryStatus)
595 printk("discovery_status(0x%08x)",
596 le32_to_cpu(event_data->DiscoveryStatus));
600 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
601 desc = "SAS Broadcast Primitive";
603 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
604 desc = "SAS Init Device Status Change";
606 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
607 desc = "SAS Init Table Overflow";
609 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
610 desc = "SAS Topology Change List";
612 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
613 desc = "SAS Enclosure Device Status Change";
615 case MPI2_EVENT_IR_VOLUME:
616 if (!ioc->hide_ir_msg)
619 case MPI2_EVENT_IR_PHYSICAL_DISK:
620 if (!ioc->hide_ir_msg)
621 desc = "IR Physical Disk";
623 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
624 if (!ioc->hide_ir_msg)
625 desc = "IR Configuration Change List";
627 case MPI2_EVENT_LOG_ENTRY_ADDED:
628 if (!ioc->hide_ir_msg)
629 desc = "Log Entry Added";
636 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
641 * _base_sas_log_info - verbose translation of firmware log info
642 * @ioc: per adapter object
643 * @log_info: log info
648 _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
659 union loginfo_type sas_loginfo;
660 char *originator_str = NULL;
662 sas_loginfo.loginfo = log_info;
663 if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
666 /* each nexus loss loginfo */
667 if (log_info == 0x31170000)
670 /* eat the loginfos associated with task aborts */
671 if (ioc->ignore_loginfos && (log_info == 30050000 || log_info ==
672 0x31140000 || log_info == 0x31130000))
675 switch (sas_loginfo.dw.originator) {
677 originator_str = "IOP";
680 originator_str = "PL";
683 if (!ioc->hide_ir_msg)
684 originator_str = "IR";
686 originator_str = "WarpDrive";
690 printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
691 "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
692 originator_str, sas_loginfo.dw.code,
693 sas_loginfo.dw.subcode);
697 * _base_display_reply_info -
698 * @ioc: per adapter object
699 * @smid: system request message index
700 * @msix_index: MSIX table index supplied by the OS
701 * @reply: reply message frame(lower 32bit addr)
706 _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
709 MPI2DefaultReply_t *mpi_reply;
712 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
713 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
714 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
715 if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
716 (ioc->logging_level & MPT_DEBUG_REPLY)) {
717 _base_sas_ioc_info(ioc , mpi_reply,
718 mpt2sas_base_get_msg_frame(ioc, smid));
721 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
722 _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
726 * mpt2sas_base_done - base internal command completion routine
727 * @ioc: per adapter object
728 * @smid: system request message index
729 * @msix_index: MSIX table index supplied by the OS
730 * @reply: reply message frame(lower 32bit addr)
732 * Return 1 meaning mf should be freed from _base_interrupt
733 * 0 means the mf is freed from this function.
736 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
739 MPI2DefaultReply_t *mpi_reply;
741 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
742 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
745 if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
748 ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
750 ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
751 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
753 ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
755 complete(&ioc->base_cmds.done);
760 * _base_async_event - main callback handler for firmware asyn events
761 * @ioc: per adapter object
762 * @msix_index: MSIX table index supplied by the OS
763 * @reply: reply message frame(lower 32bit addr)
765 * Return 1 meaning mf should be freed from _base_interrupt
766 * 0 means the mf is freed from this function.
769 _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
771 Mpi2EventNotificationReply_t *mpi_reply;
772 Mpi2EventAckRequest_t *ack_request;
775 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
778 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
780 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
781 _base_display_event_data(ioc, mpi_reply);
783 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
785 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
787 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
788 ioc->name, __func__);
792 ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
793 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
794 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
795 ack_request->Event = mpi_reply->Event;
796 ack_request->EventContext = mpi_reply->EventContext;
797 ack_request->VF_ID = 0; /* TODO */
798 ack_request->VP_ID = 0;
799 mpt2sas_base_put_smid_default(ioc, smid);
803 /* scsih callback handler */
804 mpt2sas_scsih_event_callback(ioc, msix_index, reply);
806 /* ctl callback handler */
807 mpt2sas_ctl_event_callback(ioc, msix_index, reply);
813 * _base_get_cb_idx - obtain the callback index
814 * @ioc: per adapter object
815 * @smid: system request message index
817 * Return callback index.
820 _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
825 if (smid < ioc->hi_priority_smid) {
827 cb_idx = ioc->scsi_lookup[i].cb_idx;
828 } else if (smid < ioc->internal_smid) {
829 i = smid - ioc->hi_priority_smid;
830 cb_idx = ioc->hpr_lookup[i].cb_idx;
831 } else if (smid <= ioc->hba_queue_depth) {
832 i = smid - ioc->internal_smid;
833 cb_idx = ioc->internal_lookup[i].cb_idx;
840 * _base_mask_interrupts - disable interrupts
841 * @ioc: per adapter object
843 * Disabling ResetIRQ, Reply and Doorbell Interrupts
848 _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
852 ioc->mask_interrupts = 1;
853 him_register = readl(&ioc->chip->HostInterruptMask);
854 him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
855 writel(him_register, &ioc->chip->HostInterruptMask);
856 readl(&ioc->chip->HostInterruptMask);
860 * _base_unmask_interrupts - enable interrupts
861 * @ioc: per adapter object
863 * Enabling only Reply Interrupts
868 _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
872 him_register = readl(&ioc->chip->HostInterruptMask);
873 him_register &= ~MPI2_HIM_RIM;
874 writel(him_register, &ioc->chip->HostInterruptMask);
875 ioc->mask_interrupts = 0;
878 union reply_descriptor {
887 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
888 * @irq: irq number (not used)
889 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
890 * @r: pt_regs pointer (not used)
892 * Return IRQ_HANDLE if processed, else IRQ_NONE.
895 _base_interrupt(int irq, void *bus_id)
897 struct adapter_reply_queue *reply_q = bus_id;
898 union reply_descriptor rd;
900 u8 request_desript_type;
904 u8 msix_index = reply_q->msix_index;
905 struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
906 Mpi2ReplyDescriptorsUnion_t *rpf;
909 if (ioc->mask_interrupts)
912 if (!atomic_add_unless(&reply_q->busy, 1, 1))
915 rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
916 request_desript_type = rpf->Default.ReplyFlags
917 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
918 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
919 atomic_dec(&reply_q->busy);
926 rd.word = le64_to_cpu(rpf->Words);
927 if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
930 smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
931 if (request_desript_type ==
932 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
934 (rpf->AddressReply.ReplyFrameAddress);
935 if (reply > ioc->reply_dma_max_address ||
936 reply < ioc->reply_dma_min_address)
938 } else if (request_desript_type ==
939 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
941 else if (request_desript_type ==
942 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
945 cb_idx = _base_get_cb_idx(ioc, smid);
946 if (smid && cb_idx != 0xFF) {
947 rc = mpt_callbacks[cb_idx](ioc, smid, msix_index,
950 _base_display_reply_info(ioc, smid, msix_index,
953 mpt2sas_base_free_smid(ioc, smid);
956 _base_async_event(ioc, msix_index, reply);
958 /* reply free queue handling */
960 ioc->reply_free_host_index =
961 (ioc->reply_free_host_index ==
962 (ioc->reply_free_queue_depth - 1)) ?
963 0 : ioc->reply_free_host_index + 1;
964 ioc->reply_free[ioc->reply_free_host_index] =
967 writel(ioc->reply_free_host_index,
968 &ioc->chip->ReplyFreeHostIndex);
973 rpf->Words = cpu_to_le64(ULLONG_MAX);
974 reply_q->reply_post_host_index =
975 (reply_q->reply_post_host_index ==
976 (ioc->reply_post_queue_depth - 1)) ? 0 :
977 reply_q->reply_post_host_index + 1;
978 request_desript_type =
979 reply_q->reply_post_free[reply_q->reply_post_host_index].
980 Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
982 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
984 if (!reply_q->reply_post_host_index)
985 rpf = reply_q->reply_post_free;
992 if (!completed_cmds) {
993 atomic_dec(&reply_q->busy);
997 if (ioc->is_warpdrive) {
998 writel(reply_q->reply_post_host_index,
999 ioc->reply_post_host_index[msix_index]);
1000 atomic_dec(&reply_q->busy);
1003 writel(reply_q->reply_post_host_index | (msix_index <<
1004 MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
1005 atomic_dec(&reply_q->busy);
1010 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1011 * @ioc: per adapter object
1015 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
1017 return (ioc->facts.IOCCapabilities &
1018 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
1022 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
1023 * @ioc: per adapter object
1024 * Context: ISR conext
1026 * Called when a Task Management request has completed. We want
1027 * to flush the other reply queues so all the outstanding IO has been
1028 * completed back to OS before we process the TM completetion.
1033 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1035 struct adapter_reply_queue *reply_q;
1037 /* If MSIX capability is turned off
1038 * then multi-queues are not enabled
1040 if (!_base_is_controller_msix_enabled(ioc))
1043 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
1044 if (ioc->shost_recovery)
1046 /* TMs are on msix_index == 0 */
1047 if (reply_q->msix_index == 0)
1049 _base_interrupt(reply_q->vector, (void *)reply_q);
1054 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
1055 * @cb_idx: callback index
1060 mpt2sas_base_release_callback_handler(u8 cb_idx)
1062 mpt_callbacks[cb_idx] = NULL;
1066 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1067 * @cb_func: callback function
1072 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
1076 for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
1077 if (mpt_callbacks[cb_idx] == NULL)
1080 mpt_callbacks[cb_idx] = cb_func;
1085 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1090 mpt2sas_base_initialize_callback_handler(void)
1094 for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
1095 mpt2sas_base_release_callback_handler(cb_idx);
1099 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1100 * @ioc: per adapter object
1101 * @paddr: virtual address for SGE
1103 * Create a zero length scatter gather entry to insure the IOCs hardware has
1104 * something to use if the target device goes brain dead and tries
1105 * to send data even when none is asked for.
1110 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
1112 u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
1113 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
1114 MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
1115 MPI2_SGE_FLAGS_SHIFT);
1116 ioc->base_add_sg_single(paddr, flags_length, -1);
1120 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1121 * @paddr: virtual address for SGE
1122 * @flags_length: SGE flags and data transfer length
1123 * @dma_addr: Physical address
1128 _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1130 Mpi2SGESimple32_t *sgel = paddr;
1132 flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
1133 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1134 sgel->FlagsLength = cpu_to_le32(flags_length);
1135 sgel->Address = cpu_to_le32(dma_addr);
1140 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1141 * @paddr: virtual address for SGE
1142 * @flags_length: SGE flags and data transfer length
1143 * @dma_addr: Physical address
1148 _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1150 Mpi2SGESimple64_t *sgel = paddr;
1152 flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
1153 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1154 sgel->FlagsLength = cpu_to_le32(flags_length);
1155 sgel->Address = cpu_to_le64(dma_addr);
1158 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1161 * _base_config_dma_addressing - set dma addressing
1162 * @ioc: per adapter object
1163 * @pdev: PCI device struct
1165 * Returns 0 for success, non-zero for failure.
1168 _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
1173 if (sizeof(dma_addr_t) > 4) {
1174 const uint64_t required_mask =
1175 dma_get_required_mask(&pdev->dev);
1176 if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
1177 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
1178 DMA_BIT_MASK(64))) {
1179 ioc->base_add_sg_single = &_base_add_sg_single_64;
1180 ioc->sge_size = sizeof(Mpi2SGESimple64_t);
1186 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1187 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
1188 ioc->base_add_sg_single = &_base_add_sg_single_32;
1189 ioc->sge_size = sizeof(Mpi2SGESimple32_t);
1196 printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1197 "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
1203 * _base_check_enable_msix - checks MSIX capabable.
1204 * @ioc: per adapter object
1206 * Check to see if card is capable of MSIX, and set number
1207 * of available msix vectors
1210 _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1213 u16 message_control;
1216 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1218 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
1219 "supported\n", ioc->name));
1223 /* get msix vector count */
1224 /* NUMA_IO not supported for older controllers */
1225 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
1226 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
1227 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
1228 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
1229 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
1230 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
1231 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
1232 ioc->msix_vector_count = 1;
1234 pci_read_config_word(ioc->pdev, base + 2, &message_control);
1235 ioc->msix_vector_count = (message_control & 0x3FF) + 1;
1237 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
1238 "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
1244 * _base_free_irq - free irq
1245 * @ioc: per adapter object
1247 * Freeing respective reply_queue from the list.
1250 _base_free_irq(struct MPT2SAS_ADAPTER *ioc)
1252 struct adapter_reply_queue *reply_q, *next;
1254 if (list_empty(&ioc->reply_queue_list))
1257 list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
1258 list_del(&reply_q->list);
1259 synchronize_irq(reply_q->vector);
1260 free_irq(reply_q->vector, reply_q);
1266 * _base_request_irq - request irq
1267 * @ioc: per adapter object
1268 * @index: msix index into vector table
1269 * @vector: irq vector
1271 * Inserting respective reply_queue into the list.
1274 _base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
1276 struct adapter_reply_queue *reply_q;
1279 reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
1281 printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
1282 ioc->name, (int)sizeof(struct adapter_reply_queue));
1286 reply_q->msix_index = index;
1287 reply_q->vector = vector;
1288 atomic_set(&reply_q->busy, 0);
1289 if (ioc->msix_enable)
1290 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
1291 MPT2SAS_DRIVER_NAME, ioc->id, index);
1293 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
1294 MPT2SAS_DRIVER_NAME, ioc->id);
1295 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1298 printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
1299 reply_q->name, vector);
1304 INIT_LIST_HEAD(&reply_q->list);
1305 list_add_tail(&reply_q->list, &ioc->reply_queue_list);
1310 * _base_assign_reply_queues - assigning msix index for each cpu
1311 * @ioc: per adapter object
1313 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1315 * It would nice if we could call irq_set_affinity, however it is not
1316 * an exported symbol
1319 _base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1321 struct adapter_reply_queue *reply_q;
1323 int cpu_grouping, loop, grouping, grouping_mod;
1325 if (!_base_is_controller_msix_enabled(ioc))
1328 memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
1329 /* when there are more cpus than available msix vectors,
1330 * then group cpus togeather on same irq
1332 if (ioc->cpu_count > ioc->msix_vector_count) {
1333 grouping = ioc->cpu_count / ioc->msix_vector_count;
1334 grouping_mod = ioc->cpu_count % ioc->msix_vector_count;
1335 if (grouping < 2 || (grouping == 2 && !grouping_mod))
1337 else if (grouping < 4 || (grouping == 4 && !grouping_mod))
1339 else if (grouping < 8 || (grouping == 8 && !grouping_mod))
1347 reply_q = list_entry(ioc->reply_queue_list.next,
1348 struct adapter_reply_queue, list);
1349 for_each_online_cpu(cpu_id) {
1350 if (!cpu_grouping) {
1351 ioc->cpu_msix_table[cpu_id] = reply_q->msix_index;
1352 reply_q = list_entry(reply_q->list.next,
1353 struct adapter_reply_queue, list);
1355 if (loop < cpu_grouping) {
1356 ioc->cpu_msix_table[cpu_id] =
1357 reply_q->msix_index;
1360 reply_q = list_entry(reply_q->list.next,
1361 struct adapter_reply_queue, list);
1362 ioc->cpu_msix_table[cpu_id] =
1363 reply_q->msix_index;
1371 * _base_disable_msix - disables msix
1372 * @ioc: per adapter object
1376 _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
1378 if (ioc->msix_enable) {
1379 pci_disable_msix(ioc->pdev);
1380 ioc->msix_enable = 0;
1385 * _base_enable_msix - enables msix, failback to io_apic
1386 * @ioc: per adapter object
1390 _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1392 struct msix_entry *entries, *a;
1397 INIT_LIST_HEAD(&ioc->reply_queue_list);
1399 if (msix_disable == -1 || msix_disable == 0)
1405 if (_base_check_enable_msix(ioc) != 0)
1408 ioc->reply_queue_count = min_t(u8, ioc->cpu_count,
1409 ioc->msix_vector_count);
1411 entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
1414 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
1415 "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
1416 __LINE__, __func__));
1420 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
1423 r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
1425 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
1426 "failed (r=%d) !!!\n", ioc->name, r));
1431 ioc->msix_enable = 1;
1432 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
1433 r = _base_request_irq(ioc, i, a->vector);
1435 _base_free_irq(ioc);
1436 _base_disable_msix(ioc);
1445 /* failback to io_apic interrupt routing */
1448 r = _base_request_irq(ioc, 0, ioc->pdev->irq);
1454 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1455 * @ioc: per adapter object
1457 * Returns 0 for success, non-zero for failure.
1460 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1462 struct pci_dev *pdev = ioc->pdev;
1468 struct adapter_reply_queue *reply_q;
1470 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
1471 ioc->name, __func__));
1473 ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
1474 if (pci_enable_device_mem(pdev)) {
1475 printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
1476 "failed\n", ioc->name);
1481 if (pci_request_selected_regions(pdev, ioc->bars,
1482 MPT2SAS_DRIVER_NAME)) {
1483 printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
1484 "failed\n", ioc->name);
1489 /* AER (Advanced Error Reporting) hooks */
1490 pci_enable_pcie_error_reporting(pdev);
1492 pci_set_master(pdev);
1494 if (_base_config_dma_addressing(ioc, pdev) != 0) {
1495 printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
1496 ioc->name, pci_name(pdev));
1501 for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
1502 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1505 pio_chip = (u64)pci_resource_start(pdev, i);
1506 pio_sz = pci_resource_len(pdev, i);
1510 /* verify memory resource is valid before using */
1511 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
1512 ioc->chip_phys = pci_resource_start(pdev, i);
1513 chip_phys = (u64)ioc->chip_phys;
1514 memap_sz = pci_resource_len(pdev, i);
1515 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1516 if (ioc->chip == NULL) {
1517 printk(MPT2SAS_ERR_FMT "unable to map "
1518 "adapter memory!\n", ioc->name);
1526 _base_mask_interrupts(ioc);
1527 r = _base_enable_msix(ioc);
1531 list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
1532 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
1533 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
1534 "IO-APIC enabled"), reply_q->vector);
1536 printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1537 ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
1538 printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
1539 ioc->name, (unsigned long long)pio_chip, pio_sz);
1541 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1542 pci_save_state(pdev);
1550 pci_release_selected_regions(ioc->pdev, ioc->bars);
1551 pci_disable_pcie_error_reporting(pdev);
1552 pci_disable_device(pdev);
1557 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1558 * @ioc: per adapter object
1559 * @smid: system request message index(smid zero is invalid)
1561 * Returns virt pointer to message frame.
1564 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1566 return (void *)(ioc->request + (smid * ioc->request_sz));
1570 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1571 * @ioc: per adapter object
1572 * @smid: system request message index
1574 * Returns virt pointer to sense buffer.
1577 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1579 return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1583 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1584 * @ioc: per adapter object
1585 * @smid: system request message index
1587 * Returns phys pointer to the low 32bit address of the sense buffer.
1590 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1592 return cpu_to_le32(ioc->sense_dma +
1593 ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1597 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1598 * @ioc: per adapter object
1599 * @phys_addr: lower 32 physical addr of the reply
1601 * Converts 32bit lower physical addr into a virt address.
1604 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
1608 return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
1612 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1613 * @ioc: per adapter object
1614 * @cb_idx: callback index
1616 * Returns smid (zero is invalid)
1619 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1621 unsigned long flags;
1622 struct request_tracker *request;
1625 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1626 if (list_empty(&ioc->internal_free_list)) {
1627 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1628 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1629 ioc->name, __func__);
1633 request = list_entry(ioc->internal_free_list.next,
1634 struct request_tracker, tracker_list);
1635 request->cb_idx = cb_idx;
1636 smid = request->smid;
1637 list_del(&request->tracker_list);
1638 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1643 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1644 * @ioc: per adapter object
1645 * @cb_idx: callback index
1646 * @scmd: pointer to scsi command object
1648 * Returns smid (zero is invalid)
1651 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1652 struct scsi_cmnd *scmd)
1654 unsigned long flags;
1655 struct scsiio_tracker *request;
1658 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1659 if (list_empty(&ioc->free_list)) {
1660 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1661 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1662 ioc->name, __func__);
1666 request = list_entry(ioc->free_list.next,
1667 struct scsiio_tracker, tracker_list);
1668 request->scmd = scmd;
1669 request->cb_idx = cb_idx;
1670 smid = request->smid;
1671 list_del(&request->tracker_list);
1672 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1677 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1678 * @ioc: per adapter object
1679 * @cb_idx: callback index
1681 * Returns smid (zero is invalid)
1684 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1686 unsigned long flags;
1687 struct request_tracker *request;
1690 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1691 if (list_empty(&ioc->hpr_free_list)) {
1692 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1696 request = list_entry(ioc->hpr_free_list.next,
1697 struct request_tracker, tracker_list);
1698 request->cb_idx = cb_idx;
1699 smid = request->smid;
1700 list_del(&request->tracker_list);
1701 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1707 * mpt2sas_base_free_smid - put smid back on free_list
1708 * @ioc: per adapter object
1709 * @smid: system request message index
1714 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1716 unsigned long flags;
1718 struct chain_tracker *chain_req, *next;
1720 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1721 if (smid < ioc->hi_priority_smid) {
1724 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
1725 list_for_each_entry_safe(chain_req, next,
1726 &ioc->scsi_lookup[i].chain_list, tracker_list) {
1727 list_del_init(&chain_req->tracker_list);
1728 list_add_tail(&chain_req->tracker_list,
1729 &ioc->free_chain_list);
1732 ioc->scsi_lookup[i].cb_idx = 0xFF;
1733 ioc->scsi_lookup[i].scmd = NULL;
1734 ioc->scsi_lookup[i].direct_io = 0;
1735 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
1737 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1740 * See _wait_for_commands_to_complete() call with regards
1743 if (ioc->shost_recovery && ioc->pending_io_count) {
1744 if (ioc->pending_io_count == 1)
1745 wake_up(&ioc->reset_wq);
1746 ioc->pending_io_count--;
1749 } else if (smid < ioc->internal_smid) {
1751 i = smid - ioc->hi_priority_smid;
1752 ioc->hpr_lookup[i].cb_idx = 0xFF;
1753 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
1754 &ioc->hpr_free_list);
1755 } else if (smid <= ioc->hba_queue_depth) {
1756 /* internal queue */
1757 i = smid - ioc->internal_smid;
1758 ioc->internal_lookup[i].cb_idx = 0xFF;
1759 list_add_tail(&ioc->internal_lookup[i].tracker_list,
1760 &ioc->internal_free_list);
1762 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1766 * _base_writeq - 64 bit write to MMIO
1767 * @ioc: per adapter object
1769 * @addr: address in MMIO space
1770 * @writeq_lock: spin lock
1772 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1773 * care of 32 bit environment where its not quarenteed to send the entire word
1777 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1778 spinlock_t *writeq_lock)
1780 unsigned long flags;
1781 __u64 data_out = cpu_to_le64(b);
1783 spin_lock_irqsave(writeq_lock, flags);
1784 writel((u32)(data_out), addr);
1785 writel((u32)(data_out >> 32), (addr + 4));
1786 spin_unlock_irqrestore(writeq_lock, flags);
1789 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1790 spinlock_t *writeq_lock)
1792 writeq(cpu_to_le64(b), addr);
1797 _base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
1799 return ioc->cpu_msix_table[smp_processor_id()];
1803 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1804 * @ioc: per adapter object
1805 * @smid: system request message index
1806 * @handle: device handle
1811 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
1813 Mpi2RequestDescriptorUnion_t descriptor;
1814 u64 *request = (u64 *)&descriptor;
1817 descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
1818 descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc);
1819 descriptor.SCSIIO.SMID = cpu_to_le16(smid);
1820 descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
1821 descriptor.SCSIIO.LMID = 0;
1822 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1823 &ioc->scsi_lookup_lock);
1828 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1829 * @ioc: per adapter object
1830 * @smid: system request message index
1835 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1837 Mpi2RequestDescriptorUnion_t descriptor;
1838 u64 *request = (u64 *)&descriptor;
1840 descriptor.HighPriority.RequestFlags =
1841 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
1842 descriptor.HighPriority.MSIxIndex = 0;
1843 descriptor.HighPriority.SMID = cpu_to_le16(smid);
1844 descriptor.HighPriority.LMID = 0;
1845 descriptor.HighPriority.Reserved1 = 0;
1846 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1847 &ioc->scsi_lookup_lock);
1851 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1852 * @ioc: per adapter object
1853 * @smid: system request message index
1858 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1860 Mpi2RequestDescriptorUnion_t descriptor;
1861 u64 *request = (u64 *)&descriptor;
1863 descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1864 descriptor.Default.MSIxIndex = _base_get_msix_index(ioc);
1865 descriptor.Default.SMID = cpu_to_le16(smid);
1866 descriptor.Default.LMID = 0;
1867 descriptor.Default.DescriptorTypeDependent = 0;
1868 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1869 &ioc->scsi_lookup_lock);
1873 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1874 * @ioc: per adapter object
1875 * @smid: system request message index
1876 * @io_index: value used to track the IO
1881 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1884 Mpi2RequestDescriptorUnion_t descriptor;
1885 u64 *request = (u64 *)&descriptor;
1887 descriptor.SCSITarget.RequestFlags =
1888 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
1889 descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc);
1890 descriptor.SCSITarget.SMID = cpu_to_le16(smid);
1891 descriptor.SCSITarget.LMID = 0;
1892 descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
1893 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1894 &ioc->scsi_lookup_lock);
1898 * _base_display_dell_branding - Disply branding string
1899 * @ioc: per adapter object
1904 _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1906 char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
1908 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
1911 memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
1912 switch (ioc->pdev->subsystem_device) {
1913 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
1914 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
1915 MPT2SAS_DELL_BRANDING_SIZE - 1);
1917 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
1918 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
1919 MPT2SAS_DELL_BRANDING_SIZE - 1);
1921 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
1922 strncpy(dell_branding,
1923 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
1924 MPT2SAS_DELL_BRANDING_SIZE - 1);
1926 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
1927 strncpy(dell_branding,
1928 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
1929 MPT2SAS_DELL_BRANDING_SIZE - 1);
1931 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
1932 strncpy(dell_branding,
1933 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
1934 MPT2SAS_DELL_BRANDING_SIZE - 1);
1936 case MPT2SAS_DELL_PERC_H200_SSDID:
1937 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
1938 MPT2SAS_DELL_BRANDING_SIZE - 1);
1940 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
1941 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
1942 MPT2SAS_DELL_BRANDING_SIZE - 1);
1945 sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
1949 printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
1950 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
1951 ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
1952 ioc->pdev->subsystem_device);
1956 * _base_display_intel_branding - Display branding string
1957 * @ioc: per adapter object
1962 _base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
1964 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1967 switch (ioc->pdev->device) {
1968 case MPI2_MFGPAGE_DEVID_SAS2008:
1969 switch (ioc->pdev->subsystem_device) {
1970 case MPT2SAS_INTEL_RMS2LL080_SSDID:
1971 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1972 MPT2SAS_INTEL_RMS2LL080_BRANDING);
1974 case MPT2SAS_INTEL_RMS2LL040_SSDID:
1975 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1976 MPT2SAS_INTEL_RMS2LL040_BRANDING);
1978 case MPT2SAS_INTEL_RAMSDALE_SSDID:
1979 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1980 MPT2SAS_INTEL_RAMSDALE_BRANDING);
1985 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1986 switch (ioc->pdev->subsystem_device) {
1987 case MPT2SAS_INTEL_RS25GB008_SSDID:
1988 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1989 MPT2SAS_INTEL_RS25GB008_BRANDING);
1991 case MPT2SAS_INTEL_RMS25JB080_SSDID:
1992 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1993 MPT2SAS_INTEL_RMS25JB080_BRANDING);
1995 case MPT2SAS_INTEL_RMS25JB040_SSDID:
1996 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1997 MPT2SAS_INTEL_RMS25JB040_BRANDING);
1999 case MPT2SAS_INTEL_RMS25KB080_SSDID:
2000 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2001 MPT2SAS_INTEL_RMS25KB080_BRANDING);
2003 case MPT2SAS_INTEL_RMS25KB040_SSDID:
2004 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2005 MPT2SAS_INTEL_RMS25KB040_BRANDING);
2016 * _base_display_hp_branding - Display branding string
2017 * @ioc: per adapter object
2022 _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
2024 if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
2027 switch (ioc->pdev->device) {
2028 case MPI2_MFGPAGE_DEVID_SAS2004:
2029 switch (ioc->pdev->subsystem_device) {
2030 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
2031 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2032 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
2037 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2038 switch (ioc->pdev->subsystem_device) {
2039 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
2040 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2041 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
2043 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
2044 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2045 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
2047 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
2048 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2049 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
2051 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
2052 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2053 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
2064 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2065 * @ioc: per adapter object
2070 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
2075 u32 iounit_pg1_flags;
2078 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2079 pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
2080 strncpy(desc, ioc->manu_pg0.ChipName, 16);
2081 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
2082 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2084 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2085 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2086 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2087 ioc->facts.FWVersion.Word & 0x000000FF,
2089 (bios_version & 0xFF000000) >> 24,
2090 (bios_version & 0x00FF0000) >> 16,
2091 (bios_version & 0x0000FF00) >> 8,
2092 bios_version & 0x000000FF);
2094 _base_display_dell_branding(ioc);
2095 _base_display_intel_branding(ioc);
2096 _base_display_hp_branding(ioc);
2098 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
2100 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
2101 printk("Initiator");
2105 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
2106 printk("%sTarget", i ? "," : "");
2112 printk("Capabilities=(");
2114 if (!ioc->hide_ir_msg) {
2115 if (ioc->facts.IOCCapabilities &
2116 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2122 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
2123 printk("%sTLR", i ? "," : "");
2127 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
2128 printk("%sMulticast", i ? "," : "");
2132 if (ioc->facts.IOCCapabilities &
2133 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
2134 printk("%sBIDI Target", i ? "," : "");
2138 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
2139 printk("%sEEDP", i ? "," : "");
2143 if (ioc->facts.IOCCapabilities &
2144 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
2145 printk("%sSnapshot Buffer", i ? "," : "");
2149 if (ioc->facts.IOCCapabilities &
2150 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
2151 printk("%sDiag Trace Buffer", i ? "," : "");
2155 if (ioc->facts.IOCCapabilities &
2156 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
2157 printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
2161 if (ioc->facts.IOCCapabilities &
2162 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
2163 printk("%sTask Set Full", i ? "," : "");
2167 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2168 if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
2169 printk("%sNCQ", i ? "," : "");
2177 * _base_update_missing_delay - change the missing delay timers
2178 * @ioc: per adapter object
2179 * @device_missing_delay: amount of time till device is reported missing
2180 * @io_missing_delay: interval IO is returned when there is a missing device
2184 * Passed on the command line, this function will modify the device missing
2185 * delay, as well as the io missing delay. This should be called at driver
2189 _base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
2190 u16 device_missing_delay, u8 io_missing_delay)
2192 u16 dmd, dmd_new, dmd_orignal;
2193 u8 io_missing_delay_original;
2195 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
2196 Mpi2ConfigReply_t mpi_reply;
2200 mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
2204 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
2205 sizeof(Mpi2SasIOUnit1PhyData_t));
2206 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
2207 if (!sas_iounit_pg1) {
2208 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2209 ioc->name, __FILE__, __LINE__, __func__);
2212 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
2213 sas_iounit_pg1, sz))) {
2214 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2215 ioc->name, __FILE__, __LINE__, __func__);
2218 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2219 MPI2_IOCSTATUS_MASK;
2220 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2221 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2222 ioc->name, __FILE__, __LINE__, __func__);
2226 /* device missing delay */
2227 dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
2228 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2229 dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2231 dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2233 if (device_missing_delay > 0x7F) {
2234 dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
2235 device_missing_delay;
2237 dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
2239 dmd = device_missing_delay;
2240 sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
2242 /* io missing delay */
2243 io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
2244 sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
2246 if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
2248 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2250 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2253 dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2254 printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
2255 "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
2256 printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
2257 "new(%d)\n", ioc->name, io_missing_delay_original,
2259 ioc->device_missing_delay = dmd_new;
2260 ioc->io_missing_delay = io_missing_delay;
2264 kfree(sas_iounit_pg1);
2268 * _base_static_config_pages - static start of day config pages
2269 * @ioc: per adapter object
2274 _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
2276 Mpi2ConfigReply_t mpi_reply;
2277 u32 iounit_pg1_flags;
2279 mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
2280 if (ioc->ir_firmware)
2281 mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
2283 mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
2284 mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
2285 mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
2286 mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
2287 mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2288 _base_display_ioc_capabilities(ioc);
2291 * Enable task_set_full handling in iounit_pg1 when the
2292 * facts capabilities indicate that its supported.
2294 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2295 if ((ioc->facts.IOCCapabilities &
2296 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
2298 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2301 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2302 ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
2303 mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2308 * _base_release_memory_pools - release memory
2309 * @ioc: per adapter object
2311 * Free memory allocated from _base_allocate_memory_pools.
2316 _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
2320 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2324 pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
2325 ioc->request, ioc->request_dma);
2326 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
2327 ": free\n", ioc->name, ioc->request));
2328 ioc->request = NULL;
2332 pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
2333 if (ioc->sense_dma_pool)
2334 pci_pool_destroy(ioc->sense_dma_pool);
2335 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
2336 ": free\n", ioc->name, ioc->sense));
2341 pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
2342 if (ioc->reply_dma_pool)
2343 pci_pool_destroy(ioc->reply_dma_pool);
2344 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
2345 ": free\n", ioc->name, ioc->reply));
2349 if (ioc->reply_free) {
2350 pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
2351 ioc->reply_free_dma);
2352 if (ioc->reply_free_dma_pool)
2353 pci_pool_destroy(ioc->reply_free_dma_pool);
2354 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
2355 "(0x%p): free\n", ioc->name, ioc->reply_free));
2356 ioc->reply_free = NULL;
2359 if (ioc->reply_post_free) {
2360 pci_pool_free(ioc->reply_post_free_dma_pool,
2361 ioc->reply_post_free, ioc->reply_post_free_dma);
2362 if (ioc->reply_post_free_dma_pool)
2363 pci_pool_destroy(ioc->reply_post_free_dma_pool);
2364 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2365 "reply_post_free_pool(0x%p): free\n", ioc->name,
2366 ioc->reply_post_free));
2367 ioc->reply_post_free = NULL;
2370 if (ioc->config_page) {
2371 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2372 "config_page(0x%p): free\n", ioc->name,
2374 pci_free_consistent(ioc->pdev, ioc->config_page_sz,
2375 ioc->config_page, ioc->config_page_dma);
2378 if (ioc->scsi_lookup) {
2379 free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
2380 ioc->scsi_lookup = NULL;
2382 kfree(ioc->hpr_lookup);
2383 kfree(ioc->internal_lookup);
2384 if (ioc->chain_lookup) {
2385 for (i = 0; i < ioc->chain_depth; i++) {
2386 if (ioc->chain_lookup[i].chain_buffer)
2387 pci_pool_free(ioc->chain_dma_pool,
2388 ioc->chain_lookup[i].chain_buffer,
2389 ioc->chain_lookup[i].chain_buffer_dma);
2391 if (ioc->chain_dma_pool)
2392 pci_pool_destroy(ioc->chain_dma_pool);
2394 if (ioc->chain_lookup) {
2395 free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
2396 ioc->chain_lookup = NULL;
2402 * _base_allocate_memory_pools - allocate start of day memory pools
2403 * @ioc: per adapter object
2404 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2406 * Returns 0 success, anything else error
2409 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2411 struct mpt2sas_facts *facts;
2412 u32 queue_size, queue_diff;
2413 u16 max_sge_elements;
2414 u16 num_of_reply_frames;
2415 u16 chains_needed_per_io;
2416 u32 sz, total_sz, reply_post_free_sz;
2418 u16 max_request_credit;
2421 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2425 facts = &ioc->facts;
2427 /* command line tunables for max sgl entries */
2428 if (max_sgl_entries != -1) {
2429 ioc->shost->sg_tablesize = (max_sgl_entries <
2430 MPT2SAS_SG_DEPTH) ? max_sgl_entries :
2433 ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
2436 /* command line tunables for max controller queue depth */
2437 if (max_queue_depth != -1)
2438 max_request_credit = (max_queue_depth < facts->RequestCredit)
2439 ? max_queue_depth : facts->RequestCredit;
2441 max_request_credit = facts->RequestCredit;
2443 ioc->hba_queue_depth = max_request_credit;
2444 ioc->hi_priority_depth = facts->HighPriorityCredit;
2445 ioc->internal_depth = ioc->hi_priority_depth + 5;
2447 /* request frame size */
2448 ioc->request_sz = facts->IOCRequestFrameSize * 4;
2450 /* reply frame size */
2451 ioc->reply_sz = facts->ReplyFrameSize * 4;
2455 /* calculate number of sg elements left over in the 1st frame */
2456 max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
2457 sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
2458 ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
2460 /* now do the same for a chain buffer */
2461 max_sge_elements = ioc->request_sz - ioc->sge_size;
2462 ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
2464 ioc->chain_offset_value_for_main_message =
2465 ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
2466 (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
2469 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2471 chains_needed_per_io = ((ioc->shost->sg_tablesize -
2472 ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
2474 if (chains_needed_per_io > facts->MaxChainDepth) {
2475 chains_needed_per_io = facts->MaxChainDepth;
2476 ioc->shost->sg_tablesize = min_t(u16,
2477 ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
2478 * chains_needed_per_io), ioc->shost->sg_tablesize);
2480 ioc->chains_needed_per_io = chains_needed_per_io;
2482 /* reply free queue sizing - taking into account for events */
2483 num_of_reply_frames = ioc->hba_queue_depth + 32;
2485 /* number of replies frames can't be a multiple of 16 */
2486 /* decrease number of reply frames by 1 */
2487 if (!(num_of_reply_frames % 16))
2488 num_of_reply_frames--;
2490 /* calculate number of reply free queue entries
2491 * (must be multiple of 16)
2494 /* (we know reply_free_queue_depth is not a multiple of 16) */
2495 queue_size = num_of_reply_frames;
2496 queue_size += 16 - (queue_size % 16);
2497 ioc->reply_free_queue_depth = queue_size;
2499 /* reply descriptor post queue sizing */
2500 /* this size should be the number of request frames + number of reply
2504 queue_size = ioc->hba_queue_depth + num_of_reply_frames + 1;
2505 /* round up to 16 byte boundary */
2506 if (queue_size % 16)
2507 queue_size += 16 - (queue_size % 16);
2509 /* check against IOC maximum reply post queue depth */
2510 if (queue_size > facts->MaxReplyDescriptorPostQueueDepth) {
2511 queue_diff = queue_size -
2512 facts->MaxReplyDescriptorPostQueueDepth;
2514 /* round queue_diff up to multiple of 16 */
2515 if (queue_diff % 16)
2516 queue_diff += 16 - (queue_diff % 16);
2518 /* adjust hba_queue_depth, reply_free_queue_depth,
2521 ioc->hba_queue_depth -= (queue_diff / 2);
2522 ioc->reply_free_queue_depth -= (queue_diff / 2);
2523 queue_size = facts->MaxReplyDescriptorPostQueueDepth;
2525 ioc->reply_post_queue_depth = queue_size;
2527 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
2528 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2529 "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
2530 ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
2531 ioc->chains_needed_per_io));
2533 ioc->scsiio_depth = ioc->hba_queue_depth -
2534 ioc->hi_priority_depth - ioc->internal_depth;
2536 /* set the scsi host can_queue depth
2537 * with some internal commands that could be outstanding
2539 ioc->shost->can_queue = ioc->scsiio_depth - (2);
2540 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2541 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2543 /* contiguous pool for request and chains, 16 byte align, one extra "
2546 ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
2547 sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
2549 /* hi-priority queue */
2550 sz += (ioc->hi_priority_depth * ioc->request_sz);
2552 /* internal queue */
2553 sz += (ioc->internal_depth * ioc->request_sz);
2555 ioc->request_dma_sz = sz;
2556 ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
2557 if (!ioc->request) {
2558 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2559 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2560 "total(%d kB)\n", ioc->name, ioc->hba_queue_depth,
2561 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2562 if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
2565 ioc->hba_queue_depth = max_request_credit - retry_sz;
2566 goto retry_allocation;
2570 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2571 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2572 "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
2573 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2576 /* hi-priority queue */
2577 ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
2579 ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
2582 /* internal queue */
2583 ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
2585 ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
2589 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
2590 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2591 ioc->request, ioc->hba_queue_depth, ioc->request_sz,
2592 (ioc->hba_queue_depth * ioc->request_sz)/1024));
2593 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
2594 ioc->name, (unsigned long long) ioc->request_dma));
2597 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
2598 ioc->scsi_lookup_pages = get_order(sz);
2599 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
2600 GFP_KERNEL, ioc->scsi_lookup_pages);
2601 if (!ioc->scsi_lookup) {
2602 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
2603 "sz(%d)\n", ioc->name, (int)sz);
2607 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
2608 "depth(%d)\n", ioc->name, ioc->request,
2609 ioc->scsiio_depth));
2611 /* loop till the allocation succeeds */
2613 sz = ioc->chain_depth * sizeof(struct chain_tracker);
2614 ioc->chain_pages = get_order(sz);
2615 ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
2616 GFP_KERNEL, ioc->chain_pages);
2617 if (ioc->chain_lookup == NULL)
2618 ioc->chain_depth -= 100;
2619 } while (ioc->chain_lookup == NULL);
2620 ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
2621 ioc->request_sz, 16, 0);
2622 if (!ioc->chain_dma_pool) {
2623 printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
2624 "failed\n", ioc->name);
2627 for (i = 0; i < ioc->chain_depth; i++) {
2628 ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
2629 ioc->chain_dma_pool , GFP_KERNEL,
2630 &ioc->chain_lookup[i].chain_buffer_dma);
2631 if (!ioc->chain_lookup[i].chain_buffer) {
2632 ioc->chain_depth = i;
2635 total_sz += ioc->request_sz;
2638 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
2639 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2640 ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
2641 ioc->request_sz))/1024));
2643 /* initialize hi-priority queue smid's */
2644 ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
2645 sizeof(struct request_tracker), GFP_KERNEL);
2646 if (!ioc->hpr_lookup) {
2647 printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
2651 ioc->hi_priority_smid = ioc->scsiio_depth + 1;
2652 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
2653 "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
2654 ioc->hi_priority_depth, ioc->hi_priority_smid));
2656 /* initialize internal queue smid's */
2657 ioc->internal_lookup = kcalloc(ioc->internal_depth,
2658 sizeof(struct request_tracker), GFP_KERNEL);
2659 if (!ioc->internal_lookup) {
2660 printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
2664 ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
2665 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
2666 "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
2667 ioc->internal_depth, ioc->internal_smid));
2669 /* sense buffers, 4 byte align */
2670 sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
2671 ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
2673 if (!ioc->sense_dma_pool) {
2674 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
2678 ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
2681 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
2685 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
2686 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2687 "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
2688 SCSI_SENSE_BUFFERSIZE, sz/1024));
2689 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
2690 ioc->name, (unsigned long long)ioc->sense_dma));
2693 /* reply pool, 4 byte align */
2694 sz = ioc->reply_free_queue_depth * ioc->reply_sz;
2695 ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
2697 if (!ioc->reply_dma_pool) {
2698 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
2702 ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
2705 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
2709 ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
2710 ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
2711 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
2712 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
2713 ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
2714 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
2715 ioc->name, (unsigned long long)ioc->reply_dma));
2718 /* reply free queue, 16 byte align */
2719 sz = ioc->reply_free_queue_depth * 4;
2720 ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
2721 ioc->pdev, sz, 16, 0);
2722 if (!ioc->reply_free_dma_pool) {
2723 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
2724 "failed\n", ioc->name);
2727 ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
2728 &ioc->reply_free_dma);
2729 if (!ioc->reply_free) {
2730 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
2731 "failed\n", ioc->name);
2734 memset(ioc->reply_free, 0, sz);
2735 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
2736 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
2737 ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
2738 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
2739 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
2742 /* reply post queue, 16 byte align */
2743 reply_post_free_sz = ioc->reply_post_queue_depth *
2744 sizeof(Mpi2DefaultReplyDescriptor_t);
2745 if (_base_is_controller_msix_enabled(ioc))
2746 sz = reply_post_free_sz * ioc->reply_queue_count;
2748 sz = reply_post_free_sz;
2749 ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
2750 ioc->pdev, sz, 16, 0);
2751 if (!ioc->reply_post_free_dma_pool) {
2752 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
2753 "failed\n", ioc->name);
2756 ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
2757 GFP_KERNEL, &ioc->reply_post_free_dma);
2758 if (!ioc->reply_post_free) {
2759 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
2760 "failed\n", ioc->name);
2763 memset(ioc->reply_post_free, 0, sz);
2764 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
2765 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2766 ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
2768 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
2769 "(0x%llx)\n", ioc->name, (unsigned long long)
2770 ioc->reply_post_free_dma));
2773 ioc->config_page_sz = 512;
2774 ioc->config_page = pci_alloc_consistent(ioc->pdev,
2775 ioc->config_page_sz, &ioc->config_page_dma);
2776 if (!ioc->config_page) {
2777 printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
2778 "failed\n", ioc->name);
2781 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
2782 "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
2783 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
2784 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
2785 total_sz += ioc->config_page_sz;
2787 printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
2788 ioc->name, total_sz/1024);
2789 printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
2790 "Max Controller Queue Depth(%d)\n",
2791 ioc->name, ioc->shost->can_queue, facts->RequestCredit);
2792 printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
2793 ioc->name, ioc->shost->sg_tablesize);
2802 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2803 * @ioc: Pointer to MPT_ADAPTER structure
2804 * @cooked: Request raw or cooked IOC state
2806 * Returns all IOC Doorbell register bits if cooked==0, else just the
2807 * Doorbell bits in MPI_IOC_STATE_MASK.
2810 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
2814 s = readl(&ioc->chip->Doorbell);
2815 sc = s & MPI2_IOC_STATE_MASK;
2816 return cooked ? sc : s;
2820 * _base_wait_on_iocstate - waiting on a particular ioc state
2821 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2822 * @timeout: timeout in second
2823 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2825 * Returns 0 for success, non-zero for failure.
2828 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
2835 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2837 current_state = mpt2sas_base_get_iocstate(ioc, 1);
2838 if (current_state == ioc_state)
2840 if (count && current_state == MPI2_IOC_STATE_FAULT)
2842 if (sleep_flag == CAN_SLEEP)
2849 return current_state;
2853 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2854 * a write to the doorbell)
2855 * @ioc: per adapter object
2856 * @timeout: timeout in second
2857 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2859 * Returns 0 for success, non-zero for failure.
2861 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2864 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
2871 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2873 int_status = readl(&ioc->chip->HostInterruptStatus);
2874 if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2875 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2876 "successful count(%d), timeout(%d)\n", ioc->name,
2877 __func__, count, timeout));
2880 if (sleep_flag == CAN_SLEEP)
2887 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2888 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2893 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2894 * @ioc: per adapter object
2895 * @timeout: timeout in second
2896 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2898 * Returns 0 for success, non-zero for failure.
2900 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2904 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
2912 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2914 int_status = readl(&ioc->chip->HostInterruptStatus);
2915 if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
2916 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2917 "successful count(%d), timeout(%d)\n", ioc->name,
2918 __func__, count, timeout));
2920 } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2921 doorbell = readl(&ioc->chip->Doorbell);
2922 if ((doorbell & MPI2_IOC_STATE_MASK) ==
2923 MPI2_IOC_STATE_FAULT) {
2924 mpt2sas_base_fault_info(ioc , doorbell);
2927 } else if (int_status == 0xFFFFFFFF)
2930 if (sleep_flag == CAN_SLEEP)
2938 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2939 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2944 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2945 * @ioc: per adapter object
2946 * @timeout: timeout in second
2947 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2949 * Returns 0 for success, non-zero for failure.
2953 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
2960 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2962 doorbell_reg = readl(&ioc->chip->Doorbell);
2963 if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
2964 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2965 "successful count(%d), timeout(%d)\n", ioc->name,
2966 __func__, count, timeout));
2969 if (sleep_flag == CAN_SLEEP)
2976 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2977 "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
2982 * _base_send_ioc_reset - send doorbell reset
2983 * @ioc: per adapter object
2984 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2985 * @timeout: timeout in second
2986 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2988 * Returns 0 for success, non-zero for failure.
2991 _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
2997 if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
2998 printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
2999 ioc->name, __func__);
3003 if (!(ioc->facts.IOCCapabilities &
3004 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
3007 printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
3009 writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
3010 &ioc->chip->Doorbell);
3011 if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
3015 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
3016 timeout, sleep_flag);
3018 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3019 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3024 printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
3025 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
3030 * _base_handshake_req_reply_wait - send request thru doorbell interface
3031 * @ioc: per adapter object
3032 * @request_bytes: request length
3033 * @request: pointer having request payload
3034 * @reply_bytes: reply length
3035 * @reply: pointer to reply payload
3036 * @timeout: timeout in second
3037 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3039 * Returns 0 for success, non-zero for failure.
3042 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
3043 u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
3045 MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
3051 /* make sure doorbell is not in use */
3052 if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
3053 printk(MPT2SAS_ERR_FMT "doorbell is in use "
3054 " (line=%d)\n", ioc->name, __LINE__);
3058 /* clear pending doorbell interrupts from previous state changes */
3059 if (readl(&ioc->chip->HostInterruptStatus) &
3060 MPI2_HIS_IOC2SYS_DB_STATUS)
3061 writel(0, &ioc->chip->HostInterruptStatus);
3063 /* send message to ioc */
3064 writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
3065 ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
3066 &ioc->chip->Doorbell);
3068 if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
3069 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3070 "int failed (line=%d)\n", ioc->name, __LINE__);
3073 writel(0, &ioc->chip->HostInterruptStatus);
3075 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
3076 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3077 "ack failed (line=%d)\n", ioc->name, __LINE__);
3081 /* send message 32-bits at a time */
3082 for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
3083 writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
3084 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
3089 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3090 "sending request failed (line=%d)\n", ioc->name, __LINE__);
3094 /* now wait for the reply */
3095 if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
3096 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3097 "int failed (line=%d)\n", ioc->name, __LINE__);
3101 /* read the first two 16-bits, it gives the total length of the reply */
3102 reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3103 & MPI2_DOORBELL_DATA_MASK);
3104 writel(0, &ioc->chip->HostInterruptStatus);
3105 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3106 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3107 "int failed (line=%d)\n", ioc->name, __LINE__);
3110 reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3111 & MPI2_DOORBELL_DATA_MASK);
3112 writel(0, &ioc->chip->HostInterruptStatus);
3114 for (i = 2; i < default_reply->MsgLength * 2; i++) {
3115 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3116 printk(MPT2SAS_ERR_FMT "doorbell "
3117 "handshake int failed (line=%d)\n", ioc->name,
3121 if (i >= reply_bytes/2) /* overflow case */
3122 dummy = readl(&ioc->chip->Doorbell);
3124 reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3125 & MPI2_DOORBELL_DATA_MASK);
3126 writel(0, &ioc->chip->HostInterruptStatus);
3129 _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
3130 if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
3131 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
3132 " (line=%d)\n", ioc->name, __LINE__));
3134 writel(0, &ioc->chip->HostInterruptStatus);
3136 if (ioc->logging_level & MPT_DEBUG_INIT) {
3137 mfp = (__le32 *)reply;
3138 printk(KERN_INFO "\toffset:data\n");
3139 for (i = 0; i < reply_bytes/4; i++)
3140 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3141 le32_to_cpu(mfp[i]));
3147 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3148 * @ioc: per adapter object
3149 * @mpi_reply: the reply payload from FW
3150 * @mpi_request: the request payload sent to FW
3152 * The SAS IO Unit Control Request message allows the host to perform low-level
3153 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3154 * to obtain the IOC assigned device handles for a device if it has other
3155 * identifying information about the device, in addition allows the host to
3156 * remove IOC resources associated with the device.
3158 * Returns 0 for success, non-zero for failure.
3161 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
3162 Mpi2SasIoUnitControlReply_t *mpi_reply,
3163 Mpi2SasIoUnitControlRequest_t *mpi_request)
3167 unsigned long timeleft;
3171 u16 wait_state_count;
3173 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3176 mutex_lock(&ioc->base_cmds.mutex);
3178 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3179 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3180 ioc->name, __func__);
3185 wait_state_count = 0;
3186 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3187 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3188 if (wait_state_count++ == 10) {
3189 printk(MPT2SAS_ERR_FMT
3190 "%s: failed due to ioc not operational\n",
3191 ioc->name, __func__);
3196 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3197 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3198 "operational state(count=%d)\n", ioc->name,
3199 __func__, wait_state_count);
3202 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3204 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3205 ioc->name, __func__);
3211 ioc->base_cmds.status = MPT2_CMD_PENDING;
3212 request = mpt2sas_base_get_msg_frame(ioc, smid);
3213 ioc->base_cmds.smid = smid;
3214 memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
3215 if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3216 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
3217 ioc->ioc_link_reset_in_progress = 1;
3218 init_completion(&ioc->base_cmds.done);
3219 mpt2sas_base_put_smid_default(ioc, smid);
3220 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3221 msecs_to_jiffies(10000));
3222 if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3223 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
3224 ioc->ioc_link_reset_in_progress)
3225 ioc->ioc_link_reset_in_progress = 0;
3226 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3227 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3228 ioc->name, __func__);
3229 _debug_dump_mf(mpi_request,
3230 sizeof(Mpi2SasIoUnitControlRequest_t)/4);
3231 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3233 goto issue_host_reset;
3235 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3236 memcpy(mpi_reply, ioc->base_cmds.reply,
3237 sizeof(Mpi2SasIoUnitControlReply_t));
3239 memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
3240 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3245 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3247 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3250 mutex_unlock(&ioc->base_cmds.mutex);
3256 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3257 * @ioc: per adapter object
3258 * @mpi_reply: the reply payload from FW
3259 * @mpi_request: the request payload sent to FW
3261 * The SCSI Enclosure Processor request message causes the IOC to
3262 * communicate with SES devices to control LED status signals.
3264 * Returns 0 for success, non-zero for failure.
3267 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
3268 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
3272 unsigned long timeleft;
3276 u16 wait_state_count;
3278 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3281 mutex_lock(&ioc->base_cmds.mutex);
3283 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3284 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3285 ioc->name, __func__);
3290 wait_state_count = 0;
3291 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3292 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3293 if (wait_state_count++ == 10) {
3294 printk(MPT2SAS_ERR_FMT
3295 "%s: failed due to ioc not operational\n",
3296 ioc->name, __func__);
3301 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3302 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3303 "operational state(count=%d)\n", ioc->name,
3304 __func__, wait_state_count);
3307 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3309 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3310 ioc->name, __func__);
3316 ioc->base_cmds.status = MPT2_CMD_PENDING;
3317 request = mpt2sas_base_get_msg_frame(ioc, smid);
3318 ioc->base_cmds.smid = smid;
3319 memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
3320 init_completion(&ioc->base_cmds.done);
3321 mpt2sas_base_put_smid_default(ioc, smid);
3322 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3323 msecs_to_jiffies(10000));
3324 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3325 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3326 ioc->name, __func__);
3327 _debug_dump_mf(mpi_request,
3328 sizeof(Mpi2SepRequest_t)/4);
3329 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3331 goto issue_host_reset;
3333 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3334 memcpy(mpi_reply, ioc->base_cmds.reply,
3335 sizeof(Mpi2SepReply_t));
3337 memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
3338 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3343 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3345 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3348 mutex_unlock(&ioc->base_cmds.mutex);
3353 * _base_get_port_facts - obtain port facts reply and save in ioc
3354 * @ioc: per adapter object
3355 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3357 * Returns 0 for success, non-zero for failure.
3360 _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
3362 Mpi2PortFactsRequest_t mpi_request;
3363 Mpi2PortFactsReply_t mpi_reply;
3364 struct mpt2sas_port_facts *pfacts;
3365 int mpi_reply_sz, mpi_request_sz, r;
3367 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3370 mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
3371 mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
3372 memset(&mpi_request, 0, mpi_request_sz);
3373 mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
3374 mpi_request.PortNumber = port;
3375 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3376 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3379 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3380 ioc->name, __func__, r);
3384 pfacts = &ioc->pfacts[port];
3385 memset(pfacts, 0, sizeof(Mpi2PortFactsReply_t));
3386 pfacts->PortNumber = mpi_reply.PortNumber;
3387 pfacts->VP_ID = mpi_reply.VP_ID;
3388 pfacts->VF_ID = mpi_reply.VF_ID;
3389 pfacts->MaxPostedCmdBuffers =
3390 le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
3396 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3397 * @ioc: per adapter object
3398 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3400 * Returns 0 for success, non-zero for failure.
3403 _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3405 Mpi2IOCFactsRequest_t mpi_request;
3406 Mpi2IOCFactsReply_t mpi_reply;
3407 struct mpt2sas_facts *facts;
3408 int mpi_reply_sz, mpi_request_sz, r;
3410 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3413 mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
3414 mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
3415 memset(&mpi_request, 0, mpi_request_sz);
3416 mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
3417 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3418 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3421 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3422 ioc->name, __func__, r);
3426 facts = &ioc->facts;
3427 memset(facts, 0, sizeof(Mpi2IOCFactsReply_t));
3428 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
3429 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
3430 facts->VP_ID = mpi_reply.VP_ID;
3431 facts->VF_ID = mpi_reply.VF_ID;
3432 facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
3433 facts->MaxChainDepth = mpi_reply.MaxChainDepth;
3434 facts->WhoInit = mpi_reply.WhoInit;
3435 facts->NumberOfPorts = mpi_reply.NumberOfPorts;
3436 facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
3437 facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
3438 facts->MaxReplyDescriptorPostQueueDepth =
3439 le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
3440 facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
3441 facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
3442 if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
3443 ioc->ir_firmware = 1;
3444 facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
3445 facts->IOCRequestFrameSize =
3446 le16_to_cpu(mpi_reply.IOCRequestFrameSize);
3447 facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
3448 facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
3449 ioc->shost->max_id = -1;
3450 facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
3451 facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
3452 facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
3453 facts->HighPriorityCredit =
3454 le16_to_cpu(mpi_reply.HighPriorityCredit);
3455 facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
3456 facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
3458 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
3459 "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
3460 facts->MaxChainDepth));
3461 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
3462 "reply frame size(%d)\n", ioc->name,
3463 facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
3468 * _base_send_ioc_init - send ioc_init to firmware
3469 * @ioc: per adapter object
3470 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3472 * Returns 0 for success, non-zero for failure.
3475 _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3477 Mpi2IOCInitRequest_t mpi_request;
3478 Mpi2IOCInitReply_t mpi_reply;
3480 struct timeval current_time;
3483 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3486 memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
3487 mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
3488 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
3489 mpi_request.VF_ID = 0; /* TODO */
3490 mpi_request.VP_ID = 0;
3491 mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
3492 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
3494 if (_base_is_controller_msix_enabled(ioc))
3495 mpi_request.HostMSIxVectors = ioc->reply_queue_count;
3496 mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
3497 mpi_request.ReplyDescriptorPostQueueDepth =
3498 cpu_to_le16(ioc->reply_post_queue_depth);
3499 mpi_request.ReplyFreeQueueDepth =
3500 cpu_to_le16(ioc->reply_free_queue_depth);
3502 mpi_request.SenseBufferAddressHigh =
3503 cpu_to_le32((u64)ioc->sense_dma >> 32);
3504 mpi_request.SystemReplyAddressHigh =
3505 cpu_to_le32((u64)ioc->reply_dma >> 32);
3506 mpi_request.SystemRequestFrameBaseAddress =
3507 cpu_to_le64((u64)ioc->request_dma);
3508 mpi_request.ReplyFreeQueueAddress =
3509 cpu_to_le64((u64)ioc->reply_free_dma);
3510 mpi_request.ReplyDescriptorPostQueueAddress =
3511 cpu_to_le64((u64)ioc->reply_post_free_dma);
3514 /* This time stamp specifies number of milliseconds
3515 * since epoch ~ midnight January 1, 1970.
3517 do_gettimeofday(¤t_time);
3518 mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
3519 (current_time.tv_usec / 1000));
3521 if (ioc->logging_level & MPT_DEBUG_INIT) {
3525 mfp = (__le32 *)&mpi_request;
3526 printk(KERN_INFO "\toffset:data\n");
3527 for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
3528 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3529 le32_to_cpu(mfp[i]));
3532 r = _base_handshake_req_reply_wait(ioc,
3533 sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
3534 sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
3538 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3539 ioc->name, __func__, r);
3543 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
3544 if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
3545 mpi_reply.IOCLogInfo) {
3546 printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
3554 * mpt2sas_port_enable_done - command completion routine for port enable
3555 * @ioc: per adapter object
3556 * @smid: system request message index
3557 * @msix_index: MSIX table index supplied by the OS
3558 * @reply: reply message frame(lower 32bit addr)
3560 * Return 1 meaning mf should be freed from _base_interrupt
3561 * 0 means the mf is freed from this function.
3564 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3567 MPI2DefaultReply_t *mpi_reply;
3570 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3571 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3574 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3577 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3579 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3580 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3581 mpi_reply->MsgLength*4);
3583 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3585 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3587 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3588 ioc->port_enable_failed = 1;
3590 if (ioc->is_driver_loading) {
3591 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3592 mpt2sas_port_enable_complete(ioc);
3595 ioc->start_scan_failed = ioc_status;
3596 ioc->start_scan = 0;
3600 complete(&ioc->port_enable_cmds.done);
3606 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3607 * @ioc: per adapter object
3608 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3610 * Returns 0 for success, non-zero for failure.
3613 _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3615 Mpi2PortEnableRequest_t *mpi_request;
3616 Mpi2PortEnableReply_t *mpi_reply;
3617 unsigned long timeleft;
3622 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3624 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3625 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3626 ioc->name, __func__);
3630 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3632 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3633 ioc->name, __func__);
3637 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3638 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3639 ioc->port_enable_cmds.smid = smid;
3640 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3641 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3643 init_completion(&ioc->port_enable_cmds.done);
3644 mpt2sas_base_put_smid_default(ioc, smid);
3645 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
3647 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
3648 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3649 ioc->name, __func__);
3650 _debug_dump_mf(mpi_request,
3651 sizeof(Mpi2PortEnableRequest_t)/4);
3652 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
3658 mpi_reply = ioc->port_enable_cmds.reply;
3660 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3661 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3662 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3663 ioc->name, __func__, ioc_status);
3668 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3669 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3670 "SUCCESS" : "FAILED"));
3675 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3676 * @ioc: per adapter object
3678 * Returns 0 for success, non-zero for failure.
3681 mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3683 Mpi2PortEnableRequest_t *mpi_request;
3686 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3688 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3689 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3690 ioc->name, __func__);
3694 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3696 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3697 ioc->name, __func__);
3701 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3702 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3703 ioc->port_enable_cmds.smid = smid;
3704 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3705 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3707 mpt2sas_base_put_smid_default(ioc, smid);
3712 * _base_determine_wait_on_discovery - desposition
3713 * @ioc: per adapter object
3715 * Decide whether to wait on discovery to complete. Used to either
3716 * locate boot device, or report volumes ahead of physical devices.
3718 * Returns 1 for wait, 0 for don't wait
3721 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3723 /* We wait for discovery to complete if IR firmware is loaded.
3724 * The sas topology events arrive before PD events, so we need time to
3725 * turn on the bit in ioc->pd_handles to indicate PD
3726 * Also, it maybe required to report Volumes ahead of physical
3727 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3729 if (ioc->ir_firmware)
3732 /* if no Bios, then we don't need to wait */
3733 if (!ioc->bios_pg3.BiosVersion)
3736 /* Bios is present, then we drop down here.
3738 * If there any entries in the Bios Page 2, then we wait
3739 * for discovery to complete.
3742 /* Current Boot Device */
3743 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3744 MPI2_BIOSPAGE2_FORM_MASK) ==
3745 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3746 /* Request Boot Device */
3747 (ioc->bios_pg2.ReqBootDeviceForm &
3748 MPI2_BIOSPAGE2_FORM_MASK) ==
3749 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3750 /* Alternate Request Boot Device */
3751 (ioc->bios_pg2.ReqAltBootDeviceForm &
3752 MPI2_BIOSPAGE2_FORM_MASK) ==
3753 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3761 * _base_unmask_events - turn on notification for this event
3762 * @ioc: per adapter object
3763 * @event: firmware event
3765 * The mask is stored in ioc->event_masks.
3768 _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
3775 desired_event = (1 << (event % 32));
3778 ioc->event_masks[0] &= ~desired_event;
3779 else if (event < 64)
3780 ioc->event_masks[1] &= ~desired_event;
3781 else if (event < 96)
3782 ioc->event_masks[2] &= ~desired_event;
3783 else if (event < 128)
3784 ioc->event_masks[3] &= ~desired_event;
3788 * _base_event_notification - send event notification
3789 * @ioc: per adapter object
3790 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3792 * Returns 0 for success, non-zero for failure.
3795 _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3797 Mpi2EventNotificationRequest_t *mpi_request;
3798 unsigned long timeleft;
3803 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3806 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
3807 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3808 ioc->name, __func__);
3812 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3814 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3815 ioc->name, __func__);
3818 ioc->base_cmds.status = MPT2_CMD_PENDING;
3819 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3820 ioc->base_cmds.smid = smid;
3821 memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
3822 mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
3823 mpi_request->VF_ID = 0; /* TODO */
3824 mpi_request->VP_ID = 0;
3825 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3826 mpi_request->EventMasks[i] =
3827 cpu_to_le32(ioc->event_masks[i]);
3828 init_completion(&ioc->base_cmds.done);
3829 mpt2sas_base_put_smid_default(ioc, smid);
3830 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
3831 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3832 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3833 ioc->name, __func__);
3834 _debug_dump_mf(mpi_request,
3835 sizeof(Mpi2EventNotificationRequest_t)/4);
3836 if (ioc->base_cmds.status & MPT2_CMD_RESET)
3841 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
3842 ioc->name, __func__));
3843 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3848 * mpt2sas_base_validate_event_type - validating event types
3849 * @ioc: per adapter object
3850 * @event: firmware event
3852 * This will turn on firmware event notification when application
3853 * ask for that event. We don't mask events that are already enabled.
3856 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
3859 u32 event_mask, desired_event;
3860 u8 send_update_to_fw;
3862 for (i = 0, send_update_to_fw = 0; i <
3863 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
3864 event_mask = ~event_type[i];
3866 for (j = 0; j < 32; j++) {
3867 if (!(event_mask & desired_event) &&
3868 (ioc->event_masks[i] & desired_event)) {
3869 ioc->event_masks[i] &= ~desired_event;
3870 send_update_to_fw = 1;
3872 desired_event = (desired_event << 1);
3876 if (!send_update_to_fw)
3879 mutex_lock(&ioc->base_cmds.mutex);
3880 _base_event_notification(ioc, CAN_SLEEP);
3881 mutex_unlock(&ioc->base_cmds.mutex);
3885 * _base_diag_reset - the "big hammer" start of day reset
3886 * @ioc: per adapter object
3887 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3889 * Returns 0 for success, non-zero for failure.
3892 _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3894 u32 host_diagnostic;
3899 printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
3900 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
3905 /* Write magic sequence to WriteSequence register
3906 * Loop until in diagnostic mode
3908 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
3909 "sequence\n", ioc->name));
3910 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3911 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
3912 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
3913 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
3914 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
3915 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
3916 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
3919 if (sleep_flag == CAN_SLEEP)
3927 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3928 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
3929 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3930 ioc->name, count, host_diagnostic));
3932 } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
3934 hcb_size = readl(&ioc->chip->HCBSize);
3936 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
3938 writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
3939 &ioc->chip->HostDiagnostic);
3941 /* don't access any registers for 50 milliseconds */
3944 /* 300 second max wait */
3945 for (count = 0; count < 3000000 ; count++) {
3947 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3949 if (host_diagnostic == 0xFFFFFFFF)
3951 if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
3955 if (sleep_flag == CAN_SLEEP)
3961 if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
3963 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
3964 "assuming the HCB Address points to good F/W\n",
3966 host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
3967 host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
3968 writel(host_diagnostic, &ioc->chip->HostDiagnostic);
3970 drsprintk(ioc, printk(MPT2SAS_INFO_FMT
3971 "re-enable the HCDW\n", ioc->name));
3972 writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
3973 &ioc->chip->HCBSize);
3976 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
3978 writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
3979 &ioc->chip->HostDiagnostic);
3981 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
3982 "diagnostic register\n", ioc->name));
3983 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3985 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
3986 "READY state\n", ioc->name));
3987 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
3990 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3991 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3995 printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
3999 printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
4004 * _base_make_ioc_ready - put controller in READY state
4005 * @ioc: per adapter object
4006 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4007 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4009 * Returns 0 for success, non-zero for failure.
4012 _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4013 enum reset_type type)
4018 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4021 if (ioc->pci_error_recovery)
4024 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4025 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
4026 ioc->name, __func__, ioc_state));
4028 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
4031 if (ioc_state & MPI2_DOORBELL_USED) {
4032 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
4033 "active!\n", ioc->name));
4034 goto issue_diag_reset;
4037 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
4038 mpt2sas_base_fault_info(ioc, ioc_state &
4039 MPI2_DOORBELL_DATA_MASK);
4040 goto issue_diag_reset;
4043 if (type == FORCE_BIG_HAMMER)
4044 goto issue_diag_reset;
4046 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
4047 if (!(_base_send_ioc_reset(ioc,
4048 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
4049 ioc->ioc_reset_count++;
4054 rc = _base_diag_reset(ioc, CAN_SLEEP);
4055 ioc->ioc_reset_count++;
4060 * _base_make_ioc_operational - put controller in OPERATIONAL state
4061 * @ioc: per adapter object
4062 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4064 * Returns 0 for success, non-zero for failure.
4067 _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4070 unsigned long flags;
4073 struct _tr_list *delayed_tr, *delayed_tr_next;
4075 struct adapter_reply_queue *reply_q;
4076 long reply_post_free;
4077 u32 reply_post_free_sz;
4079 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4082 /* clean the delayed target reset list */
4083 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4084 &ioc->delayed_tr_list, list) {
4085 list_del(&delayed_tr->list);
4089 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4090 &ioc->delayed_tr_volume_list, list) {
4091 list_del(&delayed_tr->list);
4095 /* initialize the scsi lookup free list */
4096 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4097 INIT_LIST_HEAD(&ioc->free_list);
4099 for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
4100 INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
4101 ioc->scsi_lookup[i].cb_idx = 0xFF;
4102 ioc->scsi_lookup[i].smid = smid;
4103 ioc->scsi_lookup[i].scmd = NULL;
4104 ioc->scsi_lookup[i].direct_io = 0;
4105 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4109 /* hi-priority queue */
4110 INIT_LIST_HEAD(&ioc->hpr_free_list);
4111 smid = ioc->hi_priority_smid;
4112 for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
4113 ioc->hpr_lookup[i].cb_idx = 0xFF;
4114 ioc->hpr_lookup[i].smid = smid;
4115 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
4116 &ioc->hpr_free_list);
4119 /* internal queue */
4120 INIT_LIST_HEAD(&ioc->internal_free_list);
4121 smid = ioc->internal_smid;
4122 for (i = 0; i < ioc->internal_depth; i++, smid++) {
4123 ioc->internal_lookup[i].cb_idx = 0xFF;
4124 ioc->internal_lookup[i].smid = smid;
4125 list_add_tail(&ioc->internal_lookup[i].tracker_list,
4126 &ioc->internal_free_list);
4130 INIT_LIST_HEAD(&ioc->free_chain_list);
4131 for (i = 0; i < ioc->chain_depth; i++)
4132 list_add_tail(&ioc->chain_lookup[i].tracker_list,
4133 &ioc->free_chain_list);
4135 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4137 /* initialize Reply Free Queue */
4138 for (i = 0, reply_address = (u32)ioc->reply_dma ;
4139 i < ioc->reply_free_queue_depth ; i++, reply_address +=
4141 ioc->reply_free[i] = cpu_to_le32(reply_address);
4143 /* initialize reply queues */
4144 _base_assign_reply_queues(ioc);
4146 /* initialize Reply Post Free Queue */
4147 reply_post_free = (long)ioc->reply_post_free;
4148 reply_post_free_sz = ioc->reply_post_queue_depth *
4149 sizeof(Mpi2DefaultReplyDescriptor_t);
4150 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4151 reply_q->reply_post_host_index = 0;
4152 reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
4154 for (i = 0; i < ioc->reply_post_queue_depth; i++)
4155 reply_q->reply_post_free[i].Words =
4156 cpu_to_le64(ULLONG_MAX);
4157 if (!_base_is_controller_msix_enabled(ioc))
4158 goto skip_init_reply_post_free_queue;
4159 reply_post_free += reply_post_free_sz;
4161 skip_init_reply_post_free_queue:
4163 r = _base_send_ioc_init(ioc, sleep_flag);
4167 /* initialize reply free host index */
4168 ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
4169 writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
4171 /* initialize reply post host index */
4172 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4173 writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
4174 &ioc->chip->ReplyPostHostIndex);
4175 if (!_base_is_controller_msix_enabled(ioc))
4176 goto skip_init_reply_post_host_index;
4179 skip_init_reply_post_host_index:
4181 _base_unmask_interrupts(ioc);
4183 r = _base_event_notification(ioc, sleep_flag);
4187 if (sleep_flag == CAN_SLEEP)
4188 _base_static_config_pages(ioc);
4191 if (ioc->is_driver_loading) {
4195 ioc->wait_for_discovery_to_complete =
4196 _base_determine_wait_on_discovery(ioc);
4197 return r; /* scan_start and scan_finished support */
4201 if (ioc->wait_for_discovery_to_complete && ioc->is_warpdrive) {
4202 if (ioc->manu_pg10.OEMIdentifier == 0x80) {
4203 hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 &
4204 MFG_PAGE10_HIDE_SSDS_MASK);
4205 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
4206 ioc->mfg_pg10_hide_flag = hide_flag;
4210 r = _base_send_port_enable(ioc, sleep_flag);
4218 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4219 * @ioc: per adapter object
4224 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
4226 struct pci_dev *pdev = ioc->pdev;
4228 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4231 _base_mask_interrupts(ioc);
4232 ioc->shost_recovery = 1;
4233 _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4234 ioc->shost_recovery = 0;
4235 _base_free_irq(ioc);
4236 _base_disable_msix(ioc);
4240 pci_release_selected_regions(ioc->pdev, ioc->bars);
4241 pci_disable_pcie_error_reporting(pdev);
4242 pci_disable_device(pdev);
4247 * mpt2sas_base_attach - attach controller instance
4248 * @ioc: per adapter object
4250 * Returns 0 for success, non-zero for failure.
4253 mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4256 int cpu_id, last_cpu_id = 0;
4258 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4261 /* setup cpu_msix_table */
4262 ioc->cpu_count = num_online_cpus();
4263 for_each_online_cpu(cpu_id)
4264 last_cpu_id = cpu_id;
4265 ioc->cpu_msix_table_sz = last_cpu_id + 1;
4266 ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
4267 ioc->reply_queue_count = 1;
4268 if (!ioc->cpu_msix_table) {
4269 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
4270 "cpu_msix_table failed!!!\n", ioc->name));
4272 goto out_free_resources;
4275 if (ioc->is_warpdrive) {
4276 ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
4277 sizeof(resource_size_t *), GFP_KERNEL);
4278 if (!ioc->reply_post_host_index) {
4279 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
4280 "for cpu_msix_table failed!!!\n", ioc->name));
4282 goto out_free_resources;
4286 r = mpt2sas_base_map_resources(ioc);
4290 if (ioc->is_warpdrive) {
4291 ioc->reply_post_host_index[0] =
4292 (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
4294 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
4295 ioc->reply_post_host_index[i] = (resource_size_t *)
4296 ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
4300 pci_set_drvdata(ioc->pdev, ioc->shost);
4301 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
4303 goto out_free_resources;
4305 r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4307 goto out_free_resources;
4309 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
4310 sizeof(Mpi2PortFactsReply_t), GFP_KERNEL);
4313 goto out_free_resources;
4316 for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
4317 r = _base_get_port_facts(ioc, i, CAN_SLEEP);
4319 goto out_free_resources;
4322 r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
4324 goto out_free_resources;
4326 init_waitqueue_head(&ioc->reset_wq);
4328 /* allocate memory pd handle bitmask list */
4329 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
4330 if (ioc->facts.MaxDevHandle % 8)
4331 ioc->pd_handles_sz++;
4332 ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
4334 if (!ioc->pd_handles) {
4336 goto out_free_resources;
4339 ioc->fwfault_debug = mpt2sas_fwfault_debug;
4341 /* base internal command bits */
4342 mutex_init(&ioc->base_cmds.mutex);
4343 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4344 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4346 /* port_enable command bits */
4347 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4348 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4350 /* transport internal command bits */
4351 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4352 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
4353 mutex_init(&ioc->transport_cmds.mutex);
4355 /* scsih internal command bits */
4356 ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4357 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
4358 mutex_init(&ioc->scsih_cmds.mutex);
4360 /* task management internal command bits */
4361 ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4362 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4363 mutex_init(&ioc->tm_cmds.mutex);
4365 /* config page internal command bits */
4366 ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4367 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
4368 mutex_init(&ioc->config_cmds.mutex);
4370 /* ctl module internal command bits */
4371 ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4372 ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
4373 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
4374 mutex_init(&ioc->ctl_cmds.mutex);
4376 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4377 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4378 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
4379 !ioc->ctl_cmds.sense) {
4381 goto out_free_resources;
4384 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4385 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4386 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
4388 goto out_free_resources;
4391 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4392 ioc->event_masks[i] = -1;
4394 /* here we enable the events we care about */
4395 _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
4396 _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
4397 _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
4398 _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4399 _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
4400 _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
4401 _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
4402 _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
4403 _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
4404 _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
4405 r = _base_make_ioc_operational(ioc, CAN_SLEEP);
4407 goto out_free_resources;
4409 if (missing_delay[0] != -1 && missing_delay[1] != -1)
4410 _base_update_missing_delay(ioc, missing_delay[0],
4417 ioc->remove_host = 1;
4418 mpt2sas_base_free_resources(ioc);
4419 _base_release_memory_pools(ioc);
4420 pci_set_drvdata(ioc->pdev, NULL);
4421 kfree(ioc->cpu_msix_table);
4422 if (ioc->is_warpdrive)
4423 kfree(ioc->reply_post_host_index);
4424 kfree(ioc->pd_handles);
4425 kfree(ioc->tm_cmds.reply);
4426 kfree(ioc->transport_cmds.reply);
4427 kfree(ioc->scsih_cmds.reply);
4428 kfree(ioc->config_cmds.reply);
4429 kfree(ioc->base_cmds.reply);
4430 kfree(ioc->port_enable_cmds.reply);
4431 kfree(ioc->ctl_cmds.reply);
4432 kfree(ioc->ctl_cmds.sense);
4434 ioc->ctl_cmds.reply = NULL;
4435 ioc->base_cmds.reply = NULL;
4436 ioc->tm_cmds.reply = NULL;
4437 ioc->scsih_cmds.reply = NULL;
4438 ioc->transport_cmds.reply = NULL;
4439 ioc->config_cmds.reply = NULL;
4446 * mpt2sas_base_detach - remove controller instance
4447 * @ioc: per adapter object
4452 mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4455 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4458 mpt2sas_base_stop_watchdog(ioc);
4459 mpt2sas_base_free_resources(ioc);
4460 _base_release_memory_pools(ioc);
4461 pci_set_drvdata(ioc->pdev, NULL);
4462 kfree(ioc->cpu_msix_table);
4463 if (ioc->is_warpdrive)
4464 kfree(ioc->reply_post_host_index);
4465 kfree(ioc->pd_handles);
4467 kfree(ioc->ctl_cmds.reply);
4468 kfree(ioc->ctl_cmds.sense);
4469 kfree(ioc->base_cmds.reply);
4470 kfree(ioc->port_enable_cmds.reply);
4471 kfree(ioc->tm_cmds.reply);
4472 kfree(ioc->transport_cmds.reply);
4473 kfree(ioc->scsih_cmds.reply);
4474 kfree(ioc->config_cmds.reply);
4478 * _base_reset_handler - reset callback handler (for base)
4479 * @ioc: per adapter object
4480 * @reset_phase: phase
4482 * The handler for doing any required cleanup or initialization.
4484 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4485 * MPT2_IOC_DONE_RESET
4490 _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4492 mpt2sas_scsih_reset_handler(ioc, reset_phase);
4493 mpt2sas_ctl_reset_handler(ioc, reset_phase);
4494 switch (reset_phase) {
4495 case MPT2_IOC_PRE_RESET:
4496 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4497 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
4499 case MPT2_IOC_AFTER_RESET:
4500 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4501 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
4502 if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
4503 ioc->transport_cmds.status |= MPT2_CMD_RESET;
4504 mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
4505 complete(&ioc->transport_cmds.done);
4507 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
4508 ioc->base_cmds.status |= MPT2_CMD_RESET;
4509 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4510 complete(&ioc->base_cmds.done);
4512 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4513 ioc->port_enable_failed = 1;
4514 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4515 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4516 if (ioc->is_driver_loading) {
4517 ioc->start_scan_failed =
4518 MPI2_IOCSTATUS_INTERNAL_ERROR;
4519 ioc->start_scan = 0;
4520 ioc->port_enable_cmds.status =
4523 complete(&ioc->port_enable_cmds.done);
4526 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4527 ioc->config_cmds.status |= MPT2_CMD_RESET;
4528 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
4529 ioc->config_cmds.smid = USHRT_MAX;
4530 complete(&ioc->config_cmds.done);
4533 case MPT2_IOC_DONE_RESET:
4534 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4535 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
4541 * _wait_for_commands_to_complete - reset controller
4542 * @ioc: Pointer to MPT_ADAPTER structure
4543 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4545 * This function waiting(3s) for all pending commands to complete
4546 * prior to putting controller in reset.
4549 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4552 unsigned long flags;
4555 ioc->pending_io_count = 0;
4556 if (sleep_flag != CAN_SLEEP)
4559 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4560 if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
4563 /* pending command count */
4564 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4565 for (i = 0; i < ioc->scsiio_depth; i++)
4566 if (ioc->scsi_lookup[i].cb_idx != 0xFF)
4567 ioc->pending_io_count++;
4568 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4570 if (!ioc->pending_io_count)
4573 /* wait for pending commands to complete */
4574 wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
4578 * mpt2sas_base_hard_reset_handler - reset controller
4579 * @ioc: Pointer to MPT_ADAPTER structure
4580 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4581 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4583 * Returns 0 for success, non-zero for failure.
4586 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4587 enum reset_type type)
4590 unsigned long flags;
4592 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
4595 if (ioc->pci_error_recovery) {
4596 printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
4597 ioc->name, __func__);
4602 if (mpt2sas_fwfault_debug)
4603 mpt2sas_halt_firmware(ioc);
4605 /* TODO - What we really should be doing is pulling
4606 * out all the code associated with NO_SLEEP; its never used.
4607 * That is legacy code from mpt fusion driver, ported over.
4608 * I will leave this BUG_ON here for now till its been resolved.
4610 BUG_ON(sleep_flag == NO_SLEEP);
4612 /* wait for an active reset in progress to complete */
4613 if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
4616 } while (ioc->shost_recovery == 1);
4617 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
4619 return ioc->ioc_reset_in_progress_status;
4622 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4623 ioc->shost_recovery = 1;
4624 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4626 _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
4627 _wait_for_commands_to_complete(ioc, sleep_flag);
4628 _base_mask_interrupts(ioc);
4629 r = _base_make_ioc_ready(ioc, sleep_flag, type);
4632 _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
4634 /* If this hard reset is called while port enable is active, then
4635 * there is no reason to call make_ioc_operational
4637 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4638 ioc->remove_host = 1;
4642 r = _base_make_ioc_operational(ioc, sleep_flag);
4644 _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
4646 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
4647 ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
4649 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4650 ioc->ioc_reset_in_progress_status = r;
4651 ioc->shost_recovery = 0;
4652 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4653 mutex_unlock(&ioc->reset_in_progress_mutex);
4655 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,