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);
1981 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1982 switch (ioc->pdev->subsystem_device) {
1983 case MPT2SAS_INTEL_RS25GB008_SSDID:
1984 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1985 MPT2SAS_INTEL_RS25GB008_BRANDING);
1996 * _base_display_hp_branding - Display branding string
1997 * @ioc: per adapter object
2002 _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
2004 if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
2007 switch (ioc->pdev->device) {
2008 case MPI2_MFGPAGE_DEVID_SAS2004:
2009 switch (ioc->pdev->subsystem_device) {
2010 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
2011 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2012 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
2017 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2018 switch (ioc->pdev->subsystem_device) {
2019 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
2020 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2021 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
2023 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
2024 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2025 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
2027 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
2028 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2029 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
2031 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
2032 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2033 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
2044 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2045 * @ioc: per adapter object
2050 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
2055 u32 iounit_pg1_flags;
2058 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2059 pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
2060 strncpy(desc, ioc->manu_pg0.ChipName, 16);
2061 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
2062 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2064 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2065 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2066 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2067 ioc->facts.FWVersion.Word & 0x000000FF,
2069 (bios_version & 0xFF000000) >> 24,
2070 (bios_version & 0x00FF0000) >> 16,
2071 (bios_version & 0x0000FF00) >> 8,
2072 bios_version & 0x000000FF);
2074 _base_display_dell_branding(ioc);
2075 _base_display_intel_branding(ioc);
2076 _base_display_hp_branding(ioc);
2078 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
2080 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
2081 printk("Initiator");
2085 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
2086 printk("%sTarget", i ? "," : "");
2092 printk("Capabilities=(");
2094 if (!ioc->hide_ir_msg) {
2095 if (ioc->facts.IOCCapabilities &
2096 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2102 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
2103 printk("%sTLR", i ? "," : "");
2107 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
2108 printk("%sMulticast", i ? "," : "");
2112 if (ioc->facts.IOCCapabilities &
2113 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
2114 printk("%sBIDI Target", i ? "," : "");
2118 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
2119 printk("%sEEDP", i ? "," : "");
2123 if (ioc->facts.IOCCapabilities &
2124 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
2125 printk("%sSnapshot Buffer", i ? "," : "");
2129 if (ioc->facts.IOCCapabilities &
2130 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
2131 printk("%sDiag Trace Buffer", i ? "," : "");
2135 if (ioc->facts.IOCCapabilities &
2136 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
2137 printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
2141 if (ioc->facts.IOCCapabilities &
2142 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
2143 printk("%sTask Set Full", i ? "," : "");
2147 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2148 if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
2149 printk("%sNCQ", i ? "," : "");
2157 * _base_update_missing_delay - change the missing delay timers
2158 * @ioc: per adapter object
2159 * @device_missing_delay: amount of time till device is reported missing
2160 * @io_missing_delay: interval IO is returned when there is a missing device
2164 * Passed on the command line, this function will modify the device missing
2165 * delay, as well as the io missing delay. This should be called at driver
2169 _base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
2170 u16 device_missing_delay, u8 io_missing_delay)
2172 u16 dmd, dmd_new, dmd_orignal;
2173 u8 io_missing_delay_original;
2175 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
2176 Mpi2ConfigReply_t mpi_reply;
2180 mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
2184 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
2185 sizeof(Mpi2SasIOUnit1PhyData_t));
2186 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
2187 if (!sas_iounit_pg1) {
2188 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2189 ioc->name, __FILE__, __LINE__, __func__);
2192 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
2193 sas_iounit_pg1, sz))) {
2194 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2195 ioc->name, __FILE__, __LINE__, __func__);
2198 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2199 MPI2_IOCSTATUS_MASK;
2200 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2201 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2202 ioc->name, __FILE__, __LINE__, __func__);
2206 /* device missing delay */
2207 dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
2208 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2209 dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2211 dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2213 if (device_missing_delay > 0x7F) {
2214 dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
2215 device_missing_delay;
2217 dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
2219 dmd = device_missing_delay;
2220 sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
2222 /* io missing delay */
2223 io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
2224 sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
2226 if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
2228 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2230 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2233 dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2234 printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
2235 "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
2236 printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
2237 "new(%d)\n", ioc->name, io_missing_delay_original,
2239 ioc->device_missing_delay = dmd_new;
2240 ioc->io_missing_delay = io_missing_delay;
2244 kfree(sas_iounit_pg1);
2248 * _base_static_config_pages - static start of day config pages
2249 * @ioc: per adapter object
2254 _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
2256 Mpi2ConfigReply_t mpi_reply;
2257 u32 iounit_pg1_flags;
2259 mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
2260 if (ioc->ir_firmware)
2261 mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
2263 mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
2264 mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
2265 mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
2266 mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
2267 mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2268 _base_display_ioc_capabilities(ioc);
2271 * Enable task_set_full handling in iounit_pg1 when the
2272 * facts capabilities indicate that its supported.
2274 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2275 if ((ioc->facts.IOCCapabilities &
2276 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
2278 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2281 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2282 ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
2283 mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2288 * _base_release_memory_pools - release memory
2289 * @ioc: per adapter object
2291 * Free memory allocated from _base_allocate_memory_pools.
2296 _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
2300 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2304 pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
2305 ioc->request, ioc->request_dma);
2306 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
2307 ": free\n", ioc->name, ioc->request));
2308 ioc->request = NULL;
2312 pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
2313 if (ioc->sense_dma_pool)
2314 pci_pool_destroy(ioc->sense_dma_pool);
2315 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
2316 ": free\n", ioc->name, ioc->sense));
2321 pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
2322 if (ioc->reply_dma_pool)
2323 pci_pool_destroy(ioc->reply_dma_pool);
2324 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
2325 ": free\n", ioc->name, ioc->reply));
2329 if (ioc->reply_free) {
2330 pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
2331 ioc->reply_free_dma);
2332 if (ioc->reply_free_dma_pool)
2333 pci_pool_destroy(ioc->reply_free_dma_pool);
2334 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
2335 "(0x%p): free\n", ioc->name, ioc->reply_free));
2336 ioc->reply_free = NULL;
2339 if (ioc->reply_post_free) {
2340 pci_pool_free(ioc->reply_post_free_dma_pool,
2341 ioc->reply_post_free, ioc->reply_post_free_dma);
2342 if (ioc->reply_post_free_dma_pool)
2343 pci_pool_destroy(ioc->reply_post_free_dma_pool);
2344 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2345 "reply_post_free_pool(0x%p): free\n", ioc->name,
2346 ioc->reply_post_free));
2347 ioc->reply_post_free = NULL;
2350 if (ioc->config_page) {
2351 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2352 "config_page(0x%p): free\n", ioc->name,
2354 pci_free_consistent(ioc->pdev, ioc->config_page_sz,
2355 ioc->config_page, ioc->config_page_dma);
2358 if (ioc->scsi_lookup) {
2359 free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
2360 ioc->scsi_lookup = NULL;
2362 kfree(ioc->hpr_lookup);
2363 kfree(ioc->internal_lookup);
2364 if (ioc->chain_lookup) {
2365 for (i = 0; i < ioc->chain_depth; i++) {
2366 if (ioc->chain_lookup[i].chain_buffer)
2367 pci_pool_free(ioc->chain_dma_pool,
2368 ioc->chain_lookup[i].chain_buffer,
2369 ioc->chain_lookup[i].chain_buffer_dma);
2371 if (ioc->chain_dma_pool)
2372 pci_pool_destroy(ioc->chain_dma_pool);
2374 if (ioc->chain_lookup) {
2375 free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
2376 ioc->chain_lookup = NULL;
2382 * _base_allocate_memory_pools - allocate start of day memory pools
2383 * @ioc: per adapter object
2384 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2386 * Returns 0 success, anything else error
2389 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2391 struct mpt2sas_facts *facts;
2392 u32 queue_size, queue_diff;
2393 u16 max_sge_elements;
2394 u16 num_of_reply_frames;
2395 u16 chains_needed_per_io;
2396 u32 sz, total_sz, reply_post_free_sz;
2398 u16 max_request_credit;
2401 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2405 facts = &ioc->facts;
2407 /* command line tunables for max sgl entries */
2408 if (max_sgl_entries != -1) {
2409 ioc->shost->sg_tablesize = (max_sgl_entries <
2410 MPT2SAS_SG_DEPTH) ? max_sgl_entries :
2413 ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
2416 /* command line tunables for max controller queue depth */
2417 if (max_queue_depth != -1)
2418 max_request_credit = (max_queue_depth < facts->RequestCredit)
2419 ? max_queue_depth : facts->RequestCredit;
2421 max_request_credit = facts->RequestCredit;
2423 ioc->hba_queue_depth = max_request_credit;
2424 ioc->hi_priority_depth = facts->HighPriorityCredit;
2425 ioc->internal_depth = ioc->hi_priority_depth + 5;
2427 /* request frame size */
2428 ioc->request_sz = facts->IOCRequestFrameSize * 4;
2430 /* reply frame size */
2431 ioc->reply_sz = facts->ReplyFrameSize * 4;
2435 /* calculate number of sg elements left over in the 1st frame */
2436 max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
2437 sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
2438 ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
2440 /* now do the same for a chain buffer */
2441 max_sge_elements = ioc->request_sz - ioc->sge_size;
2442 ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
2444 ioc->chain_offset_value_for_main_message =
2445 ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
2446 (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
2449 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2451 chains_needed_per_io = ((ioc->shost->sg_tablesize -
2452 ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
2454 if (chains_needed_per_io > facts->MaxChainDepth) {
2455 chains_needed_per_io = facts->MaxChainDepth;
2456 ioc->shost->sg_tablesize = min_t(u16,
2457 ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
2458 * chains_needed_per_io), ioc->shost->sg_tablesize);
2460 ioc->chains_needed_per_io = chains_needed_per_io;
2462 /* reply free queue sizing - taking into account for events */
2463 num_of_reply_frames = ioc->hba_queue_depth + 32;
2465 /* number of replies frames can't be a multiple of 16 */
2466 /* decrease number of reply frames by 1 */
2467 if (!(num_of_reply_frames % 16))
2468 num_of_reply_frames--;
2470 /* calculate number of reply free queue entries
2471 * (must be multiple of 16)
2474 /* (we know reply_free_queue_depth is not a multiple of 16) */
2475 queue_size = num_of_reply_frames;
2476 queue_size += 16 - (queue_size % 16);
2477 ioc->reply_free_queue_depth = queue_size;
2479 /* reply descriptor post queue sizing */
2480 /* this size should be the number of request frames + number of reply
2484 queue_size = ioc->hba_queue_depth + num_of_reply_frames + 1;
2485 /* round up to 16 byte boundary */
2486 if (queue_size % 16)
2487 queue_size += 16 - (queue_size % 16);
2489 /* check against IOC maximum reply post queue depth */
2490 if (queue_size > facts->MaxReplyDescriptorPostQueueDepth) {
2491 queue_diff = queue_size -
2492 facts->MaxReplyDescriptorPostQueueDepth;
2494 /* round queue_diff up to multiple of 16 */
2495 if (queue_diff % 16)
2496 queue_diff += 16 - (queue_diff % 16);
2498 /* adjust hba_queue_depth, reply_free_queue_depth,
2501 ioc->hba_queue_depth -= (queue_diff / 2);
2502 ioc->reply_free_queue_depth -= (queue_diff / 2);
2503 queue_size = facts->MaxReplyDescriptorPostQueueDepth;
2505 ioc->reply_post_queue_depth = queue_size;
2507 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
2508 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2509 "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
2510 ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
2511 ioc->chains_needed_per_io));
2513 ioc->scsiio_depth = ioc->hba_queue_depth -
2514 ioc->hi_priority_depth - ioc->internal_depth;
2516 /* set the scsi host can_queue depth
2517 * with some internal commands that could be outstanding
2519 ioc->shost->can_queue = ioc->scsiio_depth - (2);
2520 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2521 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2523 /* contiguous pool for request and chains, 16 byte align, one extra "
2526 ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
2527 sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
2529 /* hi-priority queue */
2530 sz += (ioc->hi_priority_depth * ioc->request_sz);
2532 /* internal queue */
2533 sz += (ioc->internal_depth * ioc->request_sz);
2535 ioc->request_dma_sz = sz;
2536 ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
2537 if (!ioc->request) {
2538 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2539 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2540 "total(%d kB)\n", ioc->name, ioc->hba_queue_depth,
2541 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2542 if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
2545 ioc->hba_queue_depth = max_request_credit - retry_sz;
2546 goto retry_allocation;
2550 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2551 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2552 "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
2553 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2556 /* hi-priority queue */
2557 ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
2559 ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
2562 /* internal queue */
2563 ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
2565 ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
2569 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
2570 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2571 ioc->request, ioc->hba_queue_depth, ioc->request_sz,
2572 (ioc->hba_queue_depth * ioc->request_sz)/1024));
2573 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
2574 ioc->name, (unsigned long long) ioc->request_dma));
2577 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
2578 ioc->scsi_lookup_pages = get_order(sz);
2579 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
2580 GFP_KERNEL, ioc->scsi_lookup_pages);
2581 if (!ioc->scsi_lookup) {
2582 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
2583 "sz(%d)\n", ioc->name, (int)sz);
2587 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
2588 "depth(%d)\n", ioc->name, ioc->request,
2589 ioc->scsiio_depth));
2591 /* loop till the allocation succeeds */
2593 sz = ioc->chain_depth * sizeof(struct chain_tracker);
2594 ioc->chain_pages = get_order(sz);
2595 ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
2596 GFP_KERNEL, ioc->chain_pages);
2597 if (ioc->chain_lookup == NULL)
2598 ioc->chain_depth -= 100;
2599 } while (ioc->chain_lookup == NULL);
2600 ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
2601 ioc->request_sz, 16, 0);
2602 if (!ioc->chain_dma_pool) {
2603 printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
2604 "failed\n", ioc->name);
2607 for (i = 0; i < ioc->chain_depth; i++) {
2608 ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
2609 ioc->chain_dma_pool , GFP_KERNEL,
2610 &ioc->chain_lookup[i].chain_buffer_dma);
2611 if (!ioc->chain_lookup[i].chain_buffer) {
2612 ioc->chain_depth = i;
2615 total_sz += ioc->request_sz;
2618 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
2619 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2620 ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
2621 ioc->request_sz))/1024));
2623 /* initialize hi-priority queue smid's */
2624 ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
2625 sizeof(struct request_tracker), GFP_KERNEL);
2626 if (!ioc->hpr_lookup) {
2627 printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
2631 ioc->hi_priority_smid = ioc->scsiio_depth + 1;
2632 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
2633 "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
2634 ioc->hi_priority_depth, ioc->hi_priority_smid));
2636 /* initialize internal queue smid's */
2637 ioc->internal_lookup = kcalloc(ioc->internal_depth,
2638 sizeof(struct request_tracker), GFP_KERNEL);
2639 if (!ioc->internal_lookup) {
2640 printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
2644 ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
2645 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
2646 "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
2647 ioc->internal_depth, ioc->internal_smid));
2649 /* sense buffers, 4 byte align */
2650 sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
2651 ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
2653 if (!ioc->sense_dma_pool) {
2654 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
2658 ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
2661 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
2665 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
2666 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2667 "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
2668 SCSI_SENSE_BUFFERSIZE, sz/1024));
2669 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
2670 ioc->name, (unsigned long long)ioc->sense_dma));
2673 /* reply pool, 4 byte align */
2674 sz = ioc->reply_free_queue_depth * ioc->reply_sz;
2675 ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
2677 if (!ioc->reply_dma_pool) {
2678 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
2682 ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
2685 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
2689 ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
2690 ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
2691 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
2692 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
2693 ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
2694 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
2695 ioc->name, (unsigned long long)ioc->reply_dma));
2698 /* reply free queue, 16 byte align */
2699 sz = ioc->reply_free_queue_depth * 4;
2700 ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
2701 ioc->pdev, sz, 16, 0);
2702 if (!ioc->reply_free_dma_pool) {
2703 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
2704 "failed\n", ioc->name);
2707 ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
2708 &ioc->reply_free_dma);
2709 if (!ioc->reply_free) {
2710 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
2711 "failed\n", ioc->name);
2714 memset(ioc->reply_free, 0, sz);
2715 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
2716 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
2717 ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
2718 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
2719 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
2722 /* reply post queue, 16 byte align */
2723 reply_post_free_sz = ioc->reply_post_queue_depth *
2724 sizeof(Mpi2DefaultReplyDescriptor_t);
2725 if (_base_is_controller_msix_enabled(ioc))
2726 sz = reply_post_free_sz * ioc->reply_queue_count;
2728 sz = reply_post_free_sz;
2729 ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
2730 ioc->pdev, sz, 16, 0);
2731 if (!ioc->reply_post_free_dma_pool) {
2732 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
2733 "failed\n", ioc->name);
2736 ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
2737 GFP_KERNEL, &ioc->reply_post_free_dma);
2738 if (!ioc->reply_post_free) {
2739 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
2740 "failed\n", ioc->name);
2743 memset(ioc->reply_post_free, 0, sz);
2744 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
2745 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2746 ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
2748 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
2749 "(0x%llx)\n", ioc->name, (unsigned long long)
2750 ioc->reply_post_free_dma));
2753 ioc->config_page_sz = 512;
2754 ioc->config_page = pci_alloc_consistent(ioc->pdev,
2755 ioc->config_page_sz, &ioc->config_page_dma);
2756 if (!ioc->config_page) {
2757 printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
2758 "failed\n", ioc->name);
2761 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
2762 "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
2763 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
2764 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
2765 total_sz += ioc->config_page_sz;
2767 printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
2768 ioc->name, total_sz/1024);
2769 printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
2770 "Max Controller Queue Depth(%d)\n",
2771 ioc->name, ioc->shost->can_queue, facts->RequestCredit);
2772 printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
2773 ioc->name, ioc->shost->sg_tablesize);
2782 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2783 * @ioc: Pointer to MPT_ADAPTER structure
2784 * @cooked: Request raw or cooked IOC state
2786 * Returns all IOC Doorbell register bits if cooked==0, else just the
2787 * Doorbell bits in MPI_IOC_STATE_MASK.
2790 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
2794 s = readl(&ioc->chip->Doorbell);
2795 sc = s & MPI2_IOC_STATE_MASK;
2796 return cooked ? sc : s;
2800 * _base_wait_on_iocstate - waiting on a particular ioc state
2801 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2802 * @timeout: timeout in second
2803 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2805 * Returns 0 for success, non-zero for failure.
2808 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
2815 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2817 current_state = mpt2sas_base_get_iocstate(ioc, 1);
2818 if (current_state == ioc_state)
2820 if (count && current_state == MPI2_IOC_STATE_FAULT)
2822 if (sleep_flag == CAN_SLEEP)
2829 return current_state;
2833 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2834 * a write to the doorbell)
2835 * @ioc: per adapter object
2836 * @timeout: timeout in second
2837 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2839 * Returns 0 for success, non-zero for failure.
2841 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2844 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
2851 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2853 int_status = readl(&ioc->chip->HostInterruptStatus);
2854 if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2855 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2856 "successful count(%d), timeout(%d)\n", ioc->name,
2857 __func__, count, timeout));
2860 if (sleep_flag == CAN_SLEEP)
2867 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2868 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2873 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2874 * @ioc: per adapter object
2875 * @timeout: timeout in second
2876 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2878 * Returns 0 for success, non-zero for failure.
2880 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2884 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
2892 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2894 int_status = readl(&ioc->chip->HostInterruptStatus);
2895 if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
2896 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2897 "successful count(%d), timeout(%d)\n", ioc->name,
2898 __func__, count, timeout));
2900 } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2901 doorbell = readl(&ioc->chip->Doorbell);
2902 if ((doorbell & MPI2_IOC_STATE_MASK) ==
2903 MPI2_IOC_STATE_FAULT) {
2904 mpt2sas_base_fault_info(ioc , doorbell);
2907 } else if (int_status == 0xFFFFFFFF)
2910 if (sleep_flag == CAN_SLEEP)
2918 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2919 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2924 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2925 * @ioc: per adapter object
2926 * @timeout: timeout in second
2927 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2929 * Returns 0 for success, non-zero for failure.
2933 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
2940 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2942 doorbell_reg = readl(&ioc->chip->Doorbell);
2943 if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
2944 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2945 "successful count(%d), timeout(%d)\n", ioc->name,
2946 __func__, count, timeout));
2949 if (sleep_flag == CAN_SLEEP)
2956 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2957 "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
2962 * _base_send_ioc_reset - send doorbell reset
2963 * @ioc: per adapter object
2964 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2965 * @timeout: timeout in second
2966 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2968 * Returns 0 for success, non-zero for failure.
2971 _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
2977 if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
2978 printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
2979 ioc->name, __func__);
2983 if (!(ioc->facts.IOCCapabilities &
2984 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
2987 printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
2989 writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
2990 &ioc->chip->Doorbell);
2991 if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
2995 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
2996 timeout, sleep_flag);
2998 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
2999 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3004 printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
3005 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
3010 * _base_handshake_req_reply_wait - send request thru doorbell interface
3011 * @ioc: per adapter object
3012 * @request_bytes: request length
3013 * @request: pointer having request payload
3014 * @reply_bytes: reply length
3015 * @reply: pointer to reply payload
3016 * @timeout: timeout in second
3017 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3019 * Returns 0 for success, non-zero for failure.
3022 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
3023 u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
3025 MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
3031 /* make sure doorbell is not in use */
3032 if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
3033 printk(MPT2SAS_ERR_FMT "doorbell is in use "
3034 " (line=%d)\n", ioc->name, __LINE__);
3038 /* clear pending doorbell interrupts from previous state changes */
3039 if (readl(&ioc->chip->HostInterruptStatus) &
3040 MPI2_HIS_IOC2SYS_DB_STATUS)
3041 writel(0, &ioc->chip->HostInterruptStatus);
3043 /* send message to ioc */
3044 writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
3045 ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
3046 &ioc->chip->Doorbell);
3048 if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
3049 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3050 "int failed (line=%d)\n", ioc->name, __LINE__);
3053 writel(0, &ioc->chip->HostInterruptStatus);
3055 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
3056 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3057 "ack failed (line=%d)\n", ioc->name, __LINE__);
3061 /* send message 32-bits at a time */
3062 for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
3063 writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
3064 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
3069 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3070 "sending request failed (line=%d)\n", ioc->name, __LINE__);
3074 /* now wait for the reply */
3075 if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
3076 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3077 "int failed (line=%d)\n", ioc->name, __LINE__);
3081 /* read the first two 16-bits, it gives the total length of the reply */
3082 reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3083 & MPI2_DOORBELL_DATA_MASK);
3084 writel(0, &ioc->chip->HostInterruptStatus);
3085 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3086 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3087 "int failed (line=%d)\n", ioc->name, __LINE__);
3090 reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3091 & MPI2_DOORBELL_DATA_MASK);
3092 writel(0, &ioc->chip->HostInterruptStatus);
3094 for (i = 2; i < default_reply->MsgLength * 2; i++) {
3095 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3096 printk(MPT2SAS_ERR_FMT "doorbell "
3097 "handshake int failed (line=%d)\n", ioc->name,
3101 if (i >= reply_bytes/2) /* overflow case */
3102 dummy = readl(&ioc->chip->Doorbell);
3104 reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3105 & MPI2_DOORBELL_DATA_MASK);
3106 writel(0, &ioc->chip->HostInterruptStatus);
3109 _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
3110 if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
3111 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
3112 " (line=%d)\n", ioc->name, __LINE__));
3114 writel(0, &ioc->chip->HostInterruptStatus);
3116 if (ioc->logging_level & MPT_DEBUG_INIT) {
3117 mfp = (__le32 *)reply;
3118 printk(KERN_INFO "\toffset:data\n");
3119 for (i = 0; i < reply_bytes/4; i++)
3120 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3121 le32_to_cpu(mfp[i]));
3127 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3128 * @ioc: per adapter object
3129 * @mpi_reply: the reply payload from FW
3130 * @mpi_request: the request payload sent to FW
3132 * The SAS IO Unit Control Request message allows the host to perform low-level
3133 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3134 * to obtain the IOC assigned device handles for a device if it has other
3135 * identifying information about the device, in addition allows the host to
3136 * remove IOC resources associated with the device.
3138 * Returns 0 for success, non-zero for failure.
3141 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
3142 Mpi2SasIoUnitControlReply_t *mpi_reply,
3143 Mpi2SasIoUnitControlRequest_t *mpi_request)
3147 unsigned long timeleft;
3151 u16 wait_state_count;
3153 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3156 mutex_lock(&ioc->base_cmds.mutex);
3158 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3159 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3160 ioc->name, __func__);
3165 wait_state_count = 0;
3166 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3167 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3168 if (wait_state_count++ == 10) {
3169 printk(MPT2SAS_ERR_FMT
3170 "%s: failed due to ioc not operational\n",
3171 ioc->name, __func__);
3176 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3177 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3178 "operational state(count=%d)\n", ioc->name,
3179 __func__, wait_state_count);
3182 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3184 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3185 ioc->name, __func__);
3191 ioc->base_cmds.status = MPT2_CMD_PENDING;
3192 request = mpt2sas_base_get_msg_frame(ioc, smid);
3193 ioc->base_cmds.smid = smid;
3194 memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
3195 if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3196 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
3197 ioc->ioc_link_reset_in_progress = 1;
3198 mpt2sas_base_put_smid_default(ioc, smid);
3199 init_completion(&ioc->base_cmds.done);
3200 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3201 msecs_to_jiffies(10000));
3202 if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3203 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
3204 ioc->ioc_link_reset_in_progress)
3205 ioc->ioc_link_reset_in_progress = 0;
3206 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3207 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3208 ioc->name, __func__);
3209 _debug_dump_mf(mpi_request,
3210 sizeof(Mpi2SasIoUnitControlRequest_t)/4);
3211 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3213 goto issue_host_reset;
3215 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3216 memcpy(mpi_reply, ioc->base_cmds.reply,
3217 sizeof(Mpi2SasIoUnitControlReply_t));
3219 memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
3220 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3225 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3227 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3230 mutex_unlock(&ioc->base_cmds.mutex);
3236 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3237 * @ioc: per adapter object
3238 * @mpi_reply: the reply payload from FW
3239 * @mpi_request: the request payload sent to FW
3241 * The SCSI Enclosure Processor request message causes the IOC to
3242 * communicate with SES devices to control LED status signals.
3244 * Returns 0 for success, non-zero for failure.
3247 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
3248 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
3252 unsigned long timeleft;
3256 u16 wait_state_count;
3258 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3261 mutex_lock(&ioc->base_cmds.mutex);
3263 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3264 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3265 ioc->name, __func__);
3270 wait_state_count = 0;
3271 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3272 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3273 if (wait_state_count++ == 10) {
3274 printk(MPT2SAS_ERR_FMT
3275 "%s: failed due to ioc not operational\n",
3276 ioc->name, __func__);
3281 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3282 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3283 "operational state(count=%d)\n", ioc->name,
3284 __func__, wait_state_count);
3287 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3289 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3290 ioc->name, __func__);
3296 ioc->base_cmds.status = MPT2_CMD_PENDING;
3297 request = mpt2sas_base_get_msg_frame(ioc, smid);
3298 ioc->base_cmds.smid = smid;
3299 memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
3300 mpt2sas_base_put_smid_default(ioc, smid);
3301 init_completion(&ioc->base_cmds.done);
3302 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3303 msecs_to_jiffies(10000));
3304 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3305 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3306 ioc->name, __func__);
3307 _debug_dump_mf(mpi_request,
3308 sizeof(Mpi2SepRequest_t)/4);
3309 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3311 goto issue_host_reset;
3313 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3314 memcpy(mpi_reply, ioc->base_cmds.reply,
3315 sizeof(Mpi2SepReply_t));
3317 memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
3318 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3323 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3325 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3328 mutex_unlock(&ioc->base_cmds.mutex);
3333 * _base_get_port_facts - obtain port facts reply and save in ioc
3334 * @ioc: per adapter object
3335 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3337 * Returns 0 for success, non-zero for failure.
3340 _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
3342 Mpi2PortFactsRequest_t mpi_request;
3343 Mpi2PortFactsReply_t mpi_reply;
3344 struct mpt2sas_port_facts *pfacts;
3345 int mpi_reply_sz, mpi_request_sz, r;
3347 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3350 mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
3351 mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
3352 memset(&mpi_request, 0, mpi_request_sz);
3353 mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
3354 mpi_request.PortNumber = port;
3355 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3356 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3359 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3360 ioc->name, __func__, r);
3364 pfacts = &ioc->pfacts[port];
3365 memset(pfacts, 0, sizeof(Mpi2PortFactsReply_t));
3366 pfacts->PortNumber = mpi_reply.PortNumber;
3367 pfacts->VP_ID = mpi_reply.VP_ID;
3368 pfacts->VF_ID = mpi_reply.VF_ID;
3369 pfacts->MaxPostedCmdBuffers =
3370 le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
3376 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3377 * @ioc: per adapter object
3378 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3380 * Returns 0 for success, non-zero for failure.
3383 _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3385 Mpi2IOCFactsRequest_t mpi_request;
3386 Mpi2IOCFactsReply_t mpi_reply;
3387 struct mpt2sas_facts *facts;
3388 int mpi_reply_sz, mpi_request_sz, r;
3390 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3393 mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
3394 mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
3395 memset(&mpi_request, 0, mpi_request_sz);
3396 mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
3397 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3398 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3401 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3402 ioc->name, __func__, r);
3406 facts = &ioc->facts;
3407 memset(facts, 0, sizeof(Mpi2IOCFactsReply_t));
3408 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
3409 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
3410 facts->VP_ID = mpi_reply.VP_ID;
3411 facts->VF_ID = mpi_reply.VF_ID;
3412 facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
3413 facts->MaxChainDepth = mpi_reply.MaxChainDepth;
3414 facts->WhoInit = mpi_reply.WhoInit;
3415 facts->NumberOfPorts = mpi_reply.NumberOfPorts;
3416 facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
3417 facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
3418 facts->MaxReplyDescriptorPostQueueDepth =
3419 le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
3420 facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
3421 facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
3422 if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
3423 ioc->ir_firmware = 1;
3424 facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
3425 facts->IOCRequestFrameSize =
3426 le16_to_cpu(mpi_reply.IOCRequestFrameSize);
3427 facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
3428 facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
3429 ioc->shost->max_id = -1;
3430 facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
3431 facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
3432 facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
3433 facts->HighPriorityCredit =
3434 le16_to_cpu(mpi_reply.HighPriorityCredit);
3435 facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
3436 facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
3438 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
3439 "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
3440 facts->MaxChainDepth));
3441 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
3442 "reply frame size(%d)\n", ioc->name,
3443 facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
3448 * _base_send_ioc_init - send ioc_init to firmware
3449 * @ioc: per adapter object
3450 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3452 * Returns 0 for success, non-zero for failure.
3455 _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3457 Mpi2IOCInitRequest_t mpi_request;
3458 Mpi2IOCInitReply_t mpi_reply;
3460 struct timeval current_time;
3463 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3466 memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
3467 mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
3468 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
3469 mpi_request.VF_ID = 0; /* TODO */
3470 mpi_request.VP_ID = 0;
3471 mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
3472 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
3474 if (_base_is_controller_msix_enabled(ioc))
3475 mpi_request.HostMSIxVectors = ioc->reply_queue_count;
3476 mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
3477 mpi_request.ReplyDescriptorPostQueueDepth =
3478 cpu_to_le16(ioc->reply_post_queue_depth);
3479 mpi_request.ReplyFreeQueueDepth =
3480 cpu_to_le16(ioc->reply_free_queue_depth);
3482 mpi_request.SenseBufferAddressHigh =
3483 cpu_to_le32((u64)ioc->sense_dma >> 32);
3484 mpi_request.SystemReplyAddressHigh =
3485 cpu_to_le32((u64)ioc->reply_dma >> 32);
3486 mpi_request.SystemRequestFrameBaseAddress =
3487 cpu_to_le64((u64)ioc->request_dma);
3488 mpi_request.ReplyFreeQueueAddress =
3489 cpu_to_le64((u64)ioc->reply_free_dma);
3490 mpi_request.ReplyDescriptorPostQueueAddress =
3491 cpu_to_le64((u64)ioc->reply_post_free_dma);
3494 /* This time stamp specifies number of milliseconds
3495 * since epoch ~ midnight January 1, 1970.
3497 do_gettimeofday(¤t_time);
3498 mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
3499 (current_time.tv_usec / 1000));
3501 if (ioc->logging_level & MPT_DEBUG_INIT) {
3505 mfp = (__le32 *)&mpi_request;
3506 printk(KERN_INFO "\toffset:data\n");
3507 for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
3508 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3509 le32_to_cpu(mfp[i]));
3512 r = _base_handshake_req_reply_wait(ioc,
3513 sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
3514 sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
3518 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3519 ioc->name, __func__, r);
3523 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
3524 if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
3525 mpi_reply.IOCLogInfo) {
3526 printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
3534 * mpt2sas_port_enable_done - command completion routine for port enable
3535 * @ioc: per adapter object
3536 * @smid: system request message index
3537 * @msix_index: MSIX table index supplied by the OS
3538 * @reply: reply message frame(lower 32bit addr)
3540 * Return 1 meaning mf should be freed from _base_interrupt
3541 * 0 means the mf is freed from this function.
3544 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3547 MPI2DefaultReply_t *mpi_reply;
3550 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3551 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3554 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3557 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3559 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3560 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3561 mpi_reply->MsgLength*4);
3563 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3565 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3567 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3568 ioc->port_enable_failed = 1;
3570 if (ioc->is_driver_loading) {
3571 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3572 mpt2sas_port_enable_complete(ioc);
3575 ioc->start_scan_failed = ioc_status;
3576 ioc->start_scan = 0;
3580 complete(&ioc->port_enable_cmds.done);
3586 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3587 * @ioc: per adapter object
3588 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3590 * Returns 0 for success, non-zero for failure.
3593 _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3595 Mpi2PortEnableRequest_t *mpi_request;
3596 Mpi2PortEnableReply_t *mpi_reply;
3597 unsigned long timeleft;
3602 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3604 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3605 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3606 ioc->name, __func__);
3610 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3612 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3613 ioc->name, __func__);
3617 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3618 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3619 ioc->port_enable_cmds.smid = smid;
3620 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3621 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3623 init_completion(&ioc->port_enable_cmds.done);
3624 mpt2sas_base_put_smid_default(ioc, smid);
3625 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
3627 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
3628 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3629 ioc->name, __func__);
3630 _debug_dump_mf(mpi_request,
3631 sizeof(Mpi2PortEnableRequest_t)/4);
3632 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
3638 mpi_reply = ioc->port_enable_cmds.reply;
3640 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3641 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3642 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3643 ioc->name, __func__, ioc_status);
3648 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3649 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3650 "SUCCESS" : "FAILED"));
3655 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3656 * @ioc: per adapter object
3658 * Returns 0 for success, non-zero for failure.
3661 mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3663 Mpi2PortEnableRequest_t *mpi_request;
3666 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3668 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3669 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3670 ioc->name, __func__);
3674 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3676 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3677 ioc->name, __func__);
3681 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3682 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3683 ioc->port_enable_cmds.smid = smid;
3684 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3685 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3687 mpt2sas_base_put_smid_default(ioc, smid);
3692 * _base_determine_wait_on_discovery - desposition
3693 * @ioc: per adapter object
3695 * Decide whether to wait on discovery to complete. Used to either
3696 * locate boot device, or report volumes ahead of physical devices.
3698 * Returns 1 for wait, 0 for don't wait
3701 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3703 /* We wait for discovery to complete if IR firmware is loaded.
3704 * The sas topology events arrive before PD events, so we need time to
3705 * turn on the bit in ioc->pd_handles to indicate PD
3706 * Also, it maybe required to report Volumes ahead of physical
3707 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3709 if (ioc->ir_firmware)
3712 /* if no Bios, then we don't need to wait */
3713 if (!ioc->bios_pg3.BiosVersion)
3716 /* Bios is present, then we drop down here.
3718 * If there any entries in the Bios Page 2, then we wait
3719 * for discovery to complete.
3722 /* Current Boot Device */
3723 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3724 MPI2_BIOSPAGE2_FORM_MASK) ==
3725 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3726 /* Request Boot Device */
3727 (ioc->bios_pg2.ReqBootDeviceForm &
3728 MPI2_BIOSPAGE2_FORM_MASK) ==
3729 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3730 /* Alternate Request Boot Device */
3731 (ioc->bios_pg2.ReqAltBootDeviceForm &
3732 MPI2_BIOSPAGE2_FORM_MASK) ==
3733 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3741 * _base_unmask_events - turn on notification for this event
3742 * @ioc: per adapter object
3743 * @event: firmware event
3745 * The mask is stored in ioc->event_masks.
3748 _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
3755 desired_event = (1 << (event % 32));
3758 ioc->event_masks[0] &= ~desired_event;
3759 else if (event < 64)
3760 ioc->event_masks[1] &= ~desired_event;
3761 else if (event < 96)
3762 ioc->event_masks[2] &= ~desired_event;
3763 else if (event < 128)
3764 ioc->event_masks[3] &= ~desired_event;
3768 * _base_event_notification - send event notification
3769 * @ioc: per adapter object
3770 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3772 * Returns 0 for success, non-zero for failure.
3775 _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3777 Mpi2EventNotificationRequest_t *mpi_request;
3778 unsigned long timeleft;
3783 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3786 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
3787 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3788 ioc->name, __func__);
3792 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3794 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3795 ioc->name, __func__);
3798 ioc->base_cmds.status = MPT2_CMD_PENDING;
3799 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3800 ioc->base_cmds.smid = smid;
3801 memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
3802 mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
3803 mpi_request->VF_ID = 0; /* TODO */
3804 mpi_request->VP_ID = 0;
3805 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3806 mpi_request->EventMasks[i] =
3807 cpu_to_le32(ioc->event_masks[i]);
3808 mpt2sas_base_put_smid_default(ioc, smid);
3809 init_completion(&ioc->base_cmds.done);
3810 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
3811 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3812 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3813 ioc->name, __func__);
3814 _debug_dump_mf(mpi_request,
3815 sizeof(Mpi2EventNotificationRequest_t)/4);
3816 if (ioc->base_cmds.status & MPT2_CMD_RESET)
3821 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
3822 ioc->name, __func__));
3823 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3828 * mpt2sas_base_validate_event_type - validating event types
3829 * @ioc: per adapter object
3830 * @event: firmware event
3832 * This will turn on firmware event notification when application
3833 * ask for that event. We don't mask events that are already enabled.
3836 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
3839 u32 event_mask, desired_event;
3840 u8 send_update_to_fw;
3842 for (i = 0, send_update_to_fw = 0; i <
3843 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
3844 event_mask = ~event_type[i];
3846 for (j = 0; j < 32; j++) {
3847 if (!(event_mask & desired_event) &&
3848 (ioc->event_masks[i] & desired_event)) {
3849 ioc->event_masks[i] &= ~desired_event;
3850 send_update_to_fw = 1;
3852 desired_event = (desired_event << 1);
3856 if (!send_update_to_fw)
3859 mutex_lock(&ioc->base_cmds.mutex);
3860 _base_event_notification(ioc, CAN_SLEEP);
3861 mutex_unlock(&ioc->base_cmds.mutex);
3865 * _base_diag_reset - the "big hammer" start of day reset
3866 * @ioc: per adapter object
3867 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3869 * Returns 0 for success, non-zero for failure.
3872 _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3874 u32 host_diagnostic;
3879 printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
3880 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
3885 /* Write magic sequence to WriteSequence register
3886 * Loop until in diagnostic mode
3888 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
3889 "sequence\n", ioc->name));
3890 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3891 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
3892 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
3893 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
3894 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
3895 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
3896 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
3899 if (sleep_flag == CAN_SLEEP)
3907 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3908 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
3909 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3910 ioc->name, count, host_diagnostic));
3912 } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
3914 hcb_size = readl(&ioc->chip->HCBSize);
3916 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
3918 writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
3919 &ioc->chip->HostDiagnostic);
3921 /* don't access any registers for 50 milliseconds */
3924 /* 300 second max wait */
3925 for (count = 0; count < 3000000 ; count++) {
3927 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3929 if (host_diagnostic == 0xFFFFFFFF)
3931 if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
3935 if (sleep_flag == CAN_SLEEP)
3941 if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
3943 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
3944 "assuming the HCB Address points to good F/W\n",
3946 host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
3947 host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
3948 writel(host_diagnostic, &ioc->chip->HostDiagnostic);
3950 drsprintk(ioc, printk(MPT2SAS_INFO_FMT
3951 "re-enable the HCDW\n", ioc->name));
3952 writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
3953 &ioc->chip->HCBSize);
3956 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
3958 writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
3959 &ioc->chip->HostDiagnostic);
3961 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
3962 "diagnostic register\n", ioc->name));
3963 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3965 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
3966 "READY state\n", ioc->name));
3967 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
3970 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3971 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3975 printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
3979 printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
3984 * _base_make_ioc_ready - put controller in READY state
3985 * @ioc: per adapter object
3986 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3987 * @type: FORCE_BIG_HAMMER or SOFT_RESET
3989 * Returns 0 for success, non-zero for failure.
3992 _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
3993 enum reset_type type)
3998 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4001 if (ioc->pci_error_recovery)
4004 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4005 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
4006 ioc->name, __func__, ioc_state));
4008 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
4011 if (ioc_state & MPI2_DOORBELL_USED) {
4012 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
4013 "active!\n", ioc->name));
4014 goto issue_diag_reset;
4017 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
4018 mpt2sas_base_fault_info(ioc, ioc_state &
4019 MPI2_DOORBELL_DATA_MASK);
4020 goto issue_diag_reset;
4023 if (type == FORCE_BIG_HAMMER)
4024 goto issue_diag_reset;
4026 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
4027 if (!(_base_send_ioc_reset(ioc,
4028 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
4029 ioc->ioc_reset_count++;
4034 rc = _base_diag_reset(ioc, CAN_SLEEP);
4035 ioc->ioc_reset_count++;
4040 * _base_make_ioc_operational - put controller in OPERATIONAL state
4041 * @ioc: per adapter object
4042 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4044 * Returns 0 for success, non-zero for failure.
4047 _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4050 unsigned long flags;
4053 struct _tr_list *delayed_tr, *delayed_tr_next;
4055 struct adapter_reply_queue *reply_q;
4056 long reply_post_free;
4057 u32 reply_post_free_sz;
4059 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4062 /* clean the delayed target reset list */
4063 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4064 &ioc->delayed_tr_list, list) {
4065 list_del(&delayed_tr->list);
4069 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4070 &ioc->delayed_tr_volume_list, list) {
4071 list_del(&delayed_tr->list);
4075 /* initialize the scsi lookup free list */
4076 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4077 INIT_LIST_HEAD(&ioc->free_list);
4079 for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
4080 INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
4081 ioc->scsi_lookup[i].cb_idx = 0xFF;
4082 ioc->scsi_lookup[i].smid = smid;
4083 ioc->scsi_lookup[i].scmd = NULL;
4084 ioc->scsi_lookup[i].direct_io = 0;
4085 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4089 /* hi-priority queue */
4090 INIT_LIST_HEAD(&ioc->hpr_free_list);
4091 smid = ioc->hi_priority_smid;
4092 for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
4093 ioc->hpr_lookup[i].cb_idx = 0xFF;
4094 ioc->hpr_lookup[i].smid = smid;
4095 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
4096 &ioc->hpr_free_list);
4099 /* internal queue */
4100 INIT_LIST_HEAD(&ioc->internal_free_list);
4101 smid = ioc->internal_smid;
4102 for (i = 0; i < ioc->internal_depth; i++, smid++) {
4103 ioc->internal_lookup[i].cb_idx = 0xFF;
4104 ioc->internal_lookup[i].smid = smid;
4105 list_add_tail(&ioc->internal_lookup[i].tracker_list,
4106 &ioc->internal_free_list);
4110 INIT_LIST_HEAD(&ioc->free_chain_list);
4111 for (i = 0; i < ioc->chain_depth; i++)
4112 list_add_tail(&ioc->chain_lookup[i].tracker_list,
4113 &ioc->free_chain_list);
4115 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4117 /* initialize Reply Free Queue */
4118 for (i = 0, reply_address = (u32)ioc->reply_dma ;
4119 i < ioc->reply_free_queue_depth ; i++, reply_address +=
4121 ioc->reply_free[i] = cpu_to_le32(reply_address);
4123 /* initialize reply queues */
4124 _base_assign_reply_queues(ioc);
4126 /* initialize Reply Post Free Queue */
4127 reply_post_free = (long)ioc->reply_post_free;
4128 reply_post_free_sz = ioc->reply_post_queue_depth *
4129 sizeof(Mpi2DefaultReplyDescriptor_t);
4130 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4131 reply_q->reply_post_host_index = 0;
4132 reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
4134 for (i = 0; i < ioc->reply_post_queue_depth; i++)
4135 reply_q->reply_post_free[i].Words =
4136 cpu_to_le64(ULLONG_MAX);
4137 if (!_base_is_controller_msix_enabled(ioc))
4138 goto skip_init_reply_post_free_queue;
4139 reply_post_free += reply_post_free_sz;
4141 skip_init_reply_post_free_queue:
4143 r = _base_send_ioc_init(ioc, sleep_flag);
4147 /* initialize reply free host index */
4148 ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
4149 writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
4151 /* initialize reply post host index */
4152 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4153 writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
4154 &ioc->chip->ReplyPostHostIndex);
4155 if (!_base_is_controller_msix_enabled(ioc))
4156 goto skip_init_reply_post_host_index;
4159 skip_init_reply_post_host_index:
4161 _base_unmask_interrupts(ioc);
4163 r = _base_event_notification(ioc, sleep_flag);
4167 if (sleep_flag == CAN_SLEEP)
4168 _base_static_config_pages(ioc);
4171 if (ioc->is_driver_loading) {
4175 ioc->wait_for_discovery_to_complete =
4176 _base_determine_wait_on_discovery(ioc);
4177 return r; /* scan_start and scan_finished support */
4181 if (ioc->wait_for_discovery_to_complete && ioc->is_warpdrive) {
4182 if (ioc->manu_pg10.OEMIdentifier == 0x80) {
4183 hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 &
4184 MFG_PAGE10_HIDE_SSDS_MASK);
4185 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
4186 ioc->mfg_pg10_hide_flag = hide_flag;
4190 r = _base_send_port_enable(ioc, sleep_flag);
4198 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4199 * @ioc: per adapter object
4204 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
4206 struct pci_dev *pdev = ioc->pdev;
4208 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4211 _base_mask_interrupts(ioc);
4212 ioc->shost_recovery = 1;
4213 _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4214 ioc->shost_recovery = 0;
4215 _base_free_irq(ioc);
4216 _base_disable_msix(ioc);
4220 pci_release_selected_regions(ioc->pdev, ioc->bars);
4221 pci_disable_pcie_error_reporting(pdev);
4222 pci_disable_device(pdev);
4227 * mpt2sas_base_attach - attach controller instance
4228 * @ioc: per adapter object
4230 * Returns 0 for success, non-zero for failure.
4233 mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4236 int cpu_id, last_cpu_id = 0;
4238 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4241 /* setup cpu_msix_table */
4242 ioc->cpu_count = num_online_cpus();
4243 for_each_online_cpu(cpu_id)
4244 last_cpu_id = cpu_id;
4245 ioc->cpu_msix_table_sz = last_cpu_id + 1;
4246 ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
4247 ioc->reply_queue_count = 1;
4248 if (!ioc->cpu_msix_table) {
4249 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
4250 "cpu_msix_table failed!!!\n", ioc->name));
4252 goto out_free_resources;
4255 if (ioc->is_warpdrive) {
4256 ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
4257 sizeof(resource_size_t *), GFP_KERNEL);
4258 if (!ioc->reply_post_host_index) {
4259 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
4260 "for cpu_msix_table failed!!!\n", ioc->name));
4262 goto out_free_resources;
4266 r = mpt2sas_base_map_resources(ioc);
4270 if (ioc->is_warpdrive) {
4271 ioc->reply_post_host_index[0] =
4272 (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
4274 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
4275 ioc->reply_post_host_index[i] = (resource_size_t *)
4276 ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
4280 pci_set_drvdata(ioc->pdev, ioc->shost);
4281 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
4283 goto out_free_resources;
4285 r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4287 goto out_free_resources;
4289 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
4290 sizeof(Mpi2PortFactsReply_t), GFP_KERNEL);
4293 goto out_free_resources;
4296 for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
4297 r = _base_get_port_facts(ioc, i, CAN_SLEEP);
4299 goto out_free_resources;
4302 r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
4304 goto out_free_resources;
4306 init_waitqueue_head(&ioc->reset_wq);
4308 /* allocate memory pd handle bitmask list */
4309 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
4310 if (ioc->facts.MaxDevHandle % 8)
4311 ioc->pd_handles_sz++;
4312 ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
4314 if (!ioc->pd_handles) {
4316 goto out_free_resources;
4319 ioc->fwfault_debug = mpt2sas_fwfault_debug;
4321 /* base internal command bits */
4322 mutex_init(&ioc->base_cmds.mutex);
4323 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4324 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4326 /* port_enable command bits */
4327 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4328 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4330 /* transport internal command bits */
4331 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4332 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
4333 mutex_init(&ioc->transport_cmds.mutex);
4335 /* scsih internal command bits */
4336 ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4337 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
4338 mutex_init(&ioc->scsih_cmds.mutex);
4340 /* task management internal command bits */
4341 ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4342 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4343 mutex_init(&ioc->tm_cmds.mutex);
4345 /* config page internal command bits */
4346 ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4347 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
4348 mutex_init(&ioc->config_cmds.mutex);
4350 /* ctl module internal command bits */
4351 ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4352 ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
4353 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
4354 mutex_init(&ioc->ctl_cmds.mutex);
4356 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4357 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4358 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
4359 !ioc->ctl_cmds.sense) {
4361 goto out_free_resources;
4364 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4365 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4366 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
4368 goto out_free_resources;
4371 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4372 ioc->event_masks[i] = -1;
4374 /* here we enable the events we care about */
4375 _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
4376 _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
4377 _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
4378 _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4379 _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
4380 _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
4381 _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
4382 _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
4383 _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
4384 _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
4385 r = _base_make_ioc_operational(ioc, CAN_SLEEP);
4387 goto out_free_resources;
4389 if (missing_delay[0] != -1 && missing_delay[1] != -1)
4390 _base_update_missing_delay(ioc, missing_delay[0],
4397 ioc->remove_host = 1;
4398 mpt2sas_base_free_resources(ioc);
4399 _base_release_memory_pools(ioc);
4400 pci_set_drvdata(ioc->pdev, NULL);
4401 kfree(ioc->cpu_msix_table);
4402 if (ioc->is_warpdrive)
4403 kfree(ioc->reply_post_host_index);
4404 kfree(ioc->pd_handles);
4405 kfree(ioc->tm_cmds.reply);
4406 kfree(ioc->transport_cmds.reply);
4407 kfree(ioc->scsih_cmds.reply);
4408 kfree(ioc->config_cmds.reply);
4409 kfree(ioc->base_cmds.reply);
4410 kfree(ioc->port_enable_cmds.reply);
4411 kfree(ioc->ctl_cmds.reply);
4412 kfree(ioc->ctl_cmds.sense);
4414 ioc->ctl_cmds.reply = NULL;
4415 ioc->base_cmds.reply = NULL;
4416 ioc->tm_cmds.reply = NULL;
4417 ioc->scsih_cmds.reply = NULL;
4418 ioc->transport_cmds.reply = NULL;
4419 ioc->config_cmds.reply = NULL;
4426 * mpt2sas_base_detach - remove controller instance
4427 * @ioc: per adapter object
4432 mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4435 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4438 mpt2sas_base_stop_watchdog(ioc);
4439 mpt2sas_base_free_resources(ioc);
4440 _base_release_memory_pools(ioc);
4441 pci_set_drvdata(ioc->pdev, NULL);
4442 kfree(ioc->cpu_msix_table);
4443 if (ioc->is_warpdrive)
4444 kfree(ioc->reply_post_host_index);
4445 kfree(ioc->pd_handles);
4447 kfree(ioc->ctl_cmds.reply);
4448 kfree(ioc->ctl_cmds.sense);
4449 kfree(ioc->base_cmds.reply);
4450 kfree(ioc->port_enable_cmds.reply);
4451 kfree(ioc->tm_cmds.reply);
4452 kfree(ioc->transport_cmds.reply);
4453 kfree(ioc->scsih_cmds.reply);
4454 kfree(ioc->config_cmds.reply);
4458 * _base_reset_handler - reset callback handler (for base)
4459 * @ioc: per adapter object
4460 * @reset_phase: phase
4462 * The handler for doing any required cleanup or initialization.
4464 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4465 * MPT2_IOC_DONE_RESET
4470 _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4472 mpt2sas_scsih_reset_handler(ioc, reset_phase);
4473 mpt2sas_ctl_reset_handler(ioc, reset_phase);
4474 switch (reset_phase) {
4475 case MPT2_IOC_PRE_RESET:
4476 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4477 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
4479 case MPT2_IOC_AFTER_RESET:
4480 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4481 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
4482 if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
4483 ioc->transport_cmds.status |= MPT2_CMD_RESET;
4484 mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
4485 complete(&ioc->transport_cmds.done);
4487 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
4488 ioc->base_cmds.status |= MPT2_CMD_RESET;
4489 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4490 complete(&ioc->base_cmds.done);
4492 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4493 ioc->port_enable_failed = 1;
4494 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4495 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4496 if (ioc->is_driver_loading) {
4497 ioc->start_scan_failed =
4498 MPI2_IOCSTATUS_INTERNAL_ERROR;
4499 ioc->start_scan = 0;
4500 ioc->port_enable_cmds.status =
4503 complete(&ioc->port_enable_cmds.done);
4506 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4507 ioc->config_cmds.status |= MPT2_CMD_RESET;
4508 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
4509 ioc->config_cmds.smid = USHRT_MAX;
4510 complete(&ioc->config_cmds.done);
4513 case MPT2_IOC_DONE_RESET:
4514 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4515 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
4521 * _wait_for_commands_to_complete - reset controller
4522 * @ioc: Pointer to MPT_ADAPTER structure
4523 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4525 * This function waiting(3s) for all pending commands to complete
4526 * prior to putting controller in reset.
4529 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4532 unsigned long flags;
4535 ioc->pending_io_count = 0;
4536 if (sleep_flag != CAN_SLEEP)
4539 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4540 if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
4543 /* pending command count */
4544 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4545 for (i = 0; i < ioc->scsiio_depth; i++)
4546 if (ioc->scsi_lookup[i].cb_idx != 0xFF)
4547 ioc->pending_io_count++;
4548 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4550 if (!ioc->pending_io_count)
4553 /* wait for pending commands to complete */
4554 wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
4558 * mpt2sas_base_hard_reset_handler - reset controller
4559 * @ioc: Pointer to MPT_ADAPTER structure
4560 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4561 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4563 * Returns 0 for success, non-zero for failure.
4566 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4567 enum reset_type type)
4570 unsigned long flags;
4572 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
4575 if (ioc->pci_error_recovery) {
4576 printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
4577 ioc->name, __func__);
4582 if (mpt2sas_fwfault_debug)
4583 mpt2sas_halt_firmware(ioc);
4585 /* TODO - What we really should be doing is pulling
4586 * out all the code associated with NO_SLEEP; its never used.
4587 * That is legacy code from mpt fusion driver, ported over.
4588 * I will leave this BUG_ON here for now till its been resolved.
4590 BUG_ON(sleep_flag == NO_SLEEP);
4592 /* wait for an active reset in progress to complete */
4593 if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
4596 } while (ioc->shost_recovery == 1);
4597 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
4599 return ioc->ioc_reset_in_progress_status;
4602 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4603 ioc->shost_recovery = 1;
4604 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4606 _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
4607 _wait_for_commands_to_complete(ioc, sleep_flag);
4608 _base_mask_interrupts(ioc);
4609 r = _base_make_ioc_ready(ioc, sleep_flag, type);
4612 _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
4614 /* If this hard reset is called while port enable is active, then
4615 * there is no reason to call make_ioc_operational
4617 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4618 ioc->remove_host = 1;
4622 r = _base_make_ioc_operational(ioc, sleep_flag);
4624 _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
4626 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
4627 ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
4629 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4630 ioc->ioc_reset_in_progress_status = r;
4631 ioc->shost_recovery = 0;
4632 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4633 mutex_unlock(&ioc->reset_in_progress_mutex);
4635 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,