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-2012 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 #define MAX_HBA_QUEUE_DEPTH 30000
70 #define MAX_CHAIN_DEPTH 100000
71 static int max_queue_depth = -1;
72 module_param(max_queue_depth, int, 0);
73 MODULE_PARM_DESC(max_queue_depth, " max controller queue depth ");
75 static int max_sgl_entries = -1;
76 module_param(max_sgl_entries, int, 0);
77 MODULE_PARM_DESC(max_sgl_entries, " max sg entries ");
79 static int msix_disable = -1;
80 module_param(msix_disable, int, 0);
81 MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)");
83 static int missing_delay[2] = {-1, -1};
84 module_param_array(missing_delay, int, NULL, 0);
85 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
87 static int mpt2sas_fwfault_debug;
88 MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
89 "and halt firmware - (default=0)");
91 static int disable_discovery = -1;
92 module_param(disable_discovery, int, 0);
93 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
96 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
100 _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
102 int ret = param_set_int(val, kp);
103 struct MPT2SAS_ADAPTER *ioc;
108 printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
109 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
110 ioc->fwfault_debug = mpt2sas_fwfault_debug;
114 module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug,
115 param_get_int, &mpt2sas_fwfault_debug, 0644);
118 * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc
119 * @arg: input argument, used to derive ioc
121 * Return 0 if controller is removed from pci subsystem.
122 * Return -1 for other case.
124 static int mpt2sas_remove_dead_ioc_func(void *arg)
126 struct MPT2SAS_ADAPTER *ioc = (struct MPT2SAS_ADAPTER *)arg;
127 struct pci_dev *pdev;
135 pci_stop_and_remove_bus_device(pdev);
141 * _base_fault_reset_work - workq handling ioc fault conditions
142 * @work: input argument, used to derive ioc
148 _base_fault_reset_work(struct work_struct *work)
150 struct MPT2SAS_ADAPTER *ioc =
151 container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
155 struct task_struct *p;
157 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
158 if (ioc->shost_recovery || ioc->pci_error_recovery)
160 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
162 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
163 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) {
164 printk(MPT2SAS_INFO_FMT "%s : SAS host is non-operational !!!!\n",
165 ioc->name, __func__);
167 /* It may be possible that EEH recovery can resolve some of
168 * pci bus failure issues rather removing the dead ioc function
169 * by considering controller is in a non-operational state. So
170 * here priority is given to the EEH recovery. If it doesn't
171 * not resolve this issue, mpt2sas driver will consider this
172 * controller to non-operational state and remove the dead ioc
175 if (ioc->non_operational_loop++ < 5) {
176 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock,
182 * Call _scsih_flush_pending_cmds callback so that we flush all
183 * pending commands back to OS. This call is required to aovid
184 * deadlock at block layer. Dead IOC will fail to do diag reset,
185 * and this call is safe since dead ioc will never return any
186 * command back from HW.
188 ioc->schedule_dead_ioc_flush_running_cmds(ioc);
190 * Set remove_host flag early since kernel thread will
191 * take some time to execute.
193 ioc->remove_host = 1;
194 /*Remove the Dead Host */
195 p = kthread_run(mpt2sas_remove_dead_ioc_func, ioc,
196 "mpt2sas_dead_ioc_%d", ioc->id);
198 printk(MPT2SAS_ERR_FMT
199 "%s: Running mpt2sas_dead_ioc thread failed !!!!\n",
200 ioc->name, __func__);
202 printk(MPT2SAS_ERR_FMT
203 "%s: Running mpt2sas_dead_ioc thread success !!!!\n",
204 ioc->name, __func__);
207 return; /* don't rearm timer */
210 ioc->non_operational_loop = 0;
212 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
213 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
215 printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
216 __func__, (rc == 0) ? "success" : "failed");
217 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
218 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
219 mpt2sas_base_fault_info(ioc, doorbell &
220 MPI2_DOORBELL_DATA_MASK);
223 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
225 if (ioc->fault_reset_work_q)
226 queue_delayed_work(ioc->fault_reset_work_q,
227 &ioc->fault_reset_work,
228 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
229 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
233 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
234 * @ioc: per adapter object
240 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
244 if (ioc->fault_reset_work_q)
247 /* initialize fault polling */
248 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
249 snprintf(ioc->fault_reset_work_q_name,
250 sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
251 ioc->fault_reset_work_q =
252 create_singlethread_workqueue(ioc->fault_reset_work_q_name);
253 if (!ioc->fault_reset_work_q) {
254 printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
255 ioc->name, __func__, __LINE__);
258 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
259 if (ioc->fault_reset_work_q)
260 queue_delayed_work(ioc->fault_reset_work_q,
261 &ioc->fault_reset_work,
262 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
263 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
267 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
268 * @ioc: per adapter object
274 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
277 struct workqueue_struct *wq;
279 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
280 wq = ioc->fault_reset_work_q;
281 ioc->fault_reset_work_q = NULL;
282 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
284 if (!cancel_delayed_work(&ioc->fault_reset_work))
286 destroy_workqueue(wq);
291 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
292 * @ioc: per adapter object
293 * @fault_code: fault code
298 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
300 printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
301 ioc->name, fault_code);
305 * mpt2sas_halt_firmware - halt's mpt controller firmware
306 * @ioc: per adapter object
308 * For debugging timeout related issues. Writing 0xCOFFEE00
309 * to the doorbell register will halt controller firmware. With
310 * the purpose to stop both driver and firmware, the enduser can
311 * obtain a ring buffer from controller UART.
314 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc)
318 if (!ioc->fwfault_debug)
323 doorbell = readl(&ioc->chip->Doorbell);
324 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
325 mpt2sas_base_fault_info(ioc , doorbell);
327 writel(0xC0FFEE00, &ioc->chip->Doorbell);
328 printk(MPT2SAS_ERR_FMT "Firmware is halted due to command "
329 "timeout\n", ioc->name);
332 panic("panic in %s\n", __func__);
335 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
337 * _base_sas_ioc_info - verbose translation of the ioc status
338 * @ioc: per adapter object
339 * @mpi_reply: reply mf payload returned from firmware
340 * @request_hdr: request mf
345 _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
346 MPI2RequestHeader_t *request_hdr)
348 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
352 char *func_str = NULL;
354 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
355 if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
356 request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
357 request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
360 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
363 switch (ioc_status) {
365 /****************************************************************************
366 * Common IOCStatus values for all replies
367 ****************************************************************************/
369 case MPI2_IOCSTATUS_INVALID_FUNCTION:
370 desc = "invalid function";
372 case MPI2_IOCSTATUS_BUSY:
375 case MPI2_IOCSTATUS_INVALID_SGL:
376 desc = "invalid sgl";
378 case MPI2_IOCSTATUS_INTERNAL_ERROR:
379 desc = "internal error";
381 case MPI2_IOCSTATUS_INVALID_VPID:
382 desc = "invalid vpid";
384 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
385 desc = "insufficient resources";
387 case MPI2_IOCSTATUS_INVALID_FIELD:
388 desc = "invalid field";
390 case MPI2_IOCSTATUS_INVALID_STATE:
391 desc = "invalid state";
393 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
394 desc = "op state not supported";
397 /****************************************************************************
398 * Config IOCStatus values
399 ****************************************************************************/
401 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
402 desc = "config invalid action";
404 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
405 desc = "config invalid type";
407 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
408 desc = "config invalid page";
410 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
411 desc = "config invalid data";
413 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
414 desc = "config no defaults";
416 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
417 desc = "config cant commit";
420 /****************************************************************************
422 ****************************************************************************/
424 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
425 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
426 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
427 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
428 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
429 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
430 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
431 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
432 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
433 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
434 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
435 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
438 /****************************************************************************
439 * For use by SCSI Initiator and SCSI Target end-to-end data protection
440 ****************************************************************************/
442 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
443 desc = "eedp guard error";
445 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
446 desc = "eedp ref tag error";
448 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
449 desc = "eedp app tag error";
452 /****************************************************************************
454 ****************************************************************************/
456 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
457 desc = "target invalid io index";
459 case MPI2_IOCSTATUS_TARGET_ABORTED:
460 desc = "target aborted";
462 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
463 desc = "target no conn retryable";
465 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
466 desc = "target no connection";
468 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
469 desc = "target xfer count mismatch";
471 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
472 desc = "target data offset error";
474 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
475 desc = "target too much write data";
477 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
478 desc = "target iu too short";
480 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
481 desc = "target ack nak timeout";
483 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
484 desc = "target nak received";
487 /****************************************************************************
488 * Serial Attached SCSI values
489 ****************************************************************************/
491 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
492 desc = "smp request failed";
494 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
495 desc = "smp data overrun";
498 /****************************************************************************
499 * Diagnostic Buffer Post / Diagnostic Release values
500 ****************************************************************************/
502 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
503 desc = "diagnostic released";
512 switch (request_hdr->Function) {
513 case MPI2_FUNCTION_CONFIG:
514 frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
515 func_str = "config_page";
517 case MPI2_FUNCTION_SCSI_TASK_MGMT:
518 frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
519 func_str = "task_mgmt";
521 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
522 frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
523 func_str = "sas_iounit_ctl";
525 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
526 frame_sz = sizeof(Mpi2SepRequest_t);
527 func_str = "enclosure";
529 case MPI2_FUNCTION_IOC_INIT:
530 frame_sz = sizeof(Mpi2IOCInitRequest_t);
531 func_str = "ioc_init";
533 case MPI2_FUNCTION_PORT_ENABLE:
534 frame_sz = sizeof(Mpi2PortEnableRequest_t);
535 func_str = "port_enable";
537 case MPI2_FUNCTION_SMP_PASSTHROUGH:
538 frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
539 func_str = "smp_passthru";
543 func_str = "unknown";
547 printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
548 " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
550 _debug_dump_mf(request_hdr, frame_sz/4);
554 * _base_display_event_data - verbose translation of firmware asyn events
555 * @ioc: per adapter object
556 * @mpi_reply: reply mf payload returned from firmware
561 _base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
562 Mpi2EventNotificationReply_t *mpi_reply)
567 if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
570 event = le16_to_cpu(mpi_reply->Event);
573 case MPI2_EVENT_LOG_DATA:
576 case MPI2_EVENT_STATE_CHANGE:
577 desc = "Status Change";
579 case MPI2_EVENT_HARD_RESET_RECEIVED:
580 desc = "Hard Reset Received";
582 case MPI2_EVENT_EVENT_CHANGE:
583 desc = "Event Change";
585 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
586 desc = "Device Status Change";
588 case MPI2_EVENT_IR_OPERATION_STATUS:
589 if (!ioc->hide_ir_msg)
590 desc = "IR Operation Status";
592 case MPI2_EVENT_SAS_DISCOVERY:
594 Mpi2EventDataSasDiscovery_t *event_data =
595 (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData;
596 printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name,
597 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
599 if (event_data->DiscoveryStatus)
600 printk("discovery_status(0x%08x)",
601 le32_to_cpu(event_data->DiscoveryStatus));
605 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
606 desc = "SAS Broadcast Primitive";
608 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
609 desc = "SAS Init Device Status Change";
611 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
612 desc = "SAS Init Table Overflow";
614 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
615 desc = "SAS Topology Change List";
617 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
618 desc = "SAS Enclosure Device Status Change";
620 case MPI2_EVENT_IR_VOLUME:
621 if (!ioc->hide_ir_msg)
624 case MPI2_EVENT_IR_PHYSICAL_DISK:
625 if (!ioc->hide_ir_msg)
626 desc = "IR Physical Disk";
628 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
629 if (!ioc->hide_ir_msg)
630 desc = "IR Configuration Change List";
632 case MPI2_EVENT_LOG_ENTRY_ADDED:
633 if (!ioc->hide_ir_msg)
634 desc = "Log Entry Added";
641 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
646 * _base_sas_log_info - verbose translation of firmware log info
647 * @ioc: per adapter object
648 * @log_info: log info
653 _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
664 union loginfo_type sas_loginfo;
665 char *originator_str = NULL;
667 sas_loginfo.loginfo = log_info;
668 if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
671 /* each nexus loss loginfo */
672 if (log_info == 0x31170000)
675 /* eat the loginfos associated with task aborts */
676 if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info ==
677 0x31140000 || log_info == 0x31130000))
680 switch (sas_loginfo.dw.originator) {
682 originator_str = "IOP";
685 originator_str = "PL";
688 if (!ioc->hide_ir_msg)
689 originator_str = "IR";
691 originator_str = "WarpDrive";
695 printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
696 "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
697 originator_str, sas_loginfo.dw.code,
698 sas_loginfo.dw.subcode);
702 * _base_display_reply_info -
703 * @ioc: per adapter object
704 * @smid: system request message index
705 * @msix_index: MSIX table index supplied by the OS
706 * @reply: reply message frame(lower 32bit addr)
711 _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
714 MPI2DefaultReply_t *mpi_reply;
717 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
718 if (unlikely(!mpi_reply)) {
719 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
720 ioc->name, __FILE__, __LINE__, __func__);
723 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
724 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
725 if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
726 (ioc->logging_level & MPT_DEBUG_REPLY)) {
727 _base_sas_ioc_info(ioc , mpi_reply,
728 mpt2sas_base_get_msg_frame(ioc, smid));
731 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
732 _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
736 * mpt2sas_base_done - base internal command completion routine
737 * @ioc: per adapter object
738 * @smid: system request message index
739 * @msix_index: MSIX table index supplied by the OS
740 * @reply: reply message frame(lower 32bit addr)
742 * Return 1 meaning mf should be freed from _base_interrupt
743 * 0 means the mf is freed from this function.
746 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
749 MPI2DefaultReply_t *mpi_reply;
751 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
752 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
755 if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
758 ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
760 ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
761 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
763 ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
765 complete(&ioc->base_cmds.done);
770 * _base_async_event - main callback handler for firmware asyn events
771 * @ioc: per adapter object
772 * @msix_index: MSIX table index supplied by the OS
773 * @reply: reply message frame(lower 32bit addr)
775 * Return 1 meaning mf should be freed from _base_interrupt
776 * 0 means the mf is freed from this function.
779 _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
781 Mpi2EventNotificationReply_t *mpi_reply;
782 Mpi2EventAckRequest_t *ack_request;
785 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
788 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
790 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
791 _base_display_event_data(ioc, mpi_reply);
793 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
795 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
797 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
798 ioc->name, __func__);
802 ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
803 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
804 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
805 ack_request->Event = mpi_reply->Event;
806 ack_request->EventContext = mpi_reply->EventContext;
807 ack_request->VF_ID = 0; /* TODO */
808 ack_request->VP_ID = 0;
809 mpt2sas_base_put_smid_default(ioc, smid);
813 /* scsih callback handler */
814 mpt2sas_scsih_event_callback(ioc, msix_index, reply);
816 /* ctl callback handler */
817 mpt2sas_ctl_event_callback(ioc, msix_index, reply);
823 * _base_get_cb_idx - obtain the callback index
824 * @ioc: per adapter object
825 * @smid: system request message index
827 * Return callback index.
830 _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
835 if (smid < ioc->hi_priority_smid) {
837 cb_idx = ioc->scsi_lookup[i].cb_idx;
838 } else if (smid < ioc->internal_smid) {
839 i = smid - ioc->hi_priority_smid;
840 cb_idx = ioc->hpr_lookup[i].cb_idx;
841 } else if (smid <= ioc->hba_queue_depth) {
842 i = smid - ioc->internal_smid;
843 cb_idx = ioc->internal_lookup[i].cb_idx;
850 * _base_mask_interrupts - disable interrupts
851 * @ioc: per adapter object
853 * Disabling ResetIRQ, Reply and Doorbell Interrupts
858 _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
862 ioc->mask_interrupts = 1;
863 him_register = readl(&ioc->chip->HostInterruptMask);
864 him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
865 writel(him_register, &ioc->chip->HostInterruptMask);
866 readl(&ioc->chip->HostInterruptMask);
870 * _base_unmask_interrupts - enable interrupts
871 * @ioc: per adapter object
873 * Enabling only Reply Interrupts
878 _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
882 him_register = readl(&ioc->chip->HostInterruptMask);
883 him_register &= ~MPI2_HIM_RIM;
884 writel(him_register, &ioc->chip->HostInterruptMask);
885 ioc->mask_interrupts = 0;
888 union reply_descriptor {
897 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
898 * @irq: irq number (not used)
899 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
900 * @r: pt_regs pointer (not used)
902 * Return IRQ_HANDLE if processed, else IRQ_NONE.
905 _base_interrupt(int irq, void *bus_id)
907 struct adapter_reply_queue *reply_q = bus_id;
908 union reply_descriptor rd;
910 u8 request_desript_type;
914 u8 msix_index = reply_q->msix_index;
915 struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
916 Mpi2ReplyDescriptorsUnion_t *rpf;
919 if (ioc->mask_interrupts)
922 if (!atomic_add_unless(&reply_q->busy, 1, 1))
925 rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
926 request_desript_type = rpf->Default.ReplyFlags
927 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
928 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
929 atomic_dec(&reply_q->busy);
936 rd.word = le64_to_cpu(rpf->Words);
937 if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
940 smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
941 if (request_desript_type ==
942 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
944 (rpf->AddressReply.ReplyFrameAddress);
945 if (reply > ioc->reply_dma_max_address ||
946 reply < ioc->reply_dma_min_address)
948 } else if (request_desript_type ==
949 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
951 else if (request_desript_type ==
952 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
955 cb_idx = _base_get_cb_idx(ioc, smid);
956 if ((likely(cb_idx < MPT_MAX_CALLBACKS))
957 && (likely(mpt_callbacks[cb_idx] != NULL))) {
958 rc = mpt_callbacks[cb_idx](ioc, smid,
961 _base_display_reply_info(ioc, smid,
964 mpt2sas_base_free_smid(ioc, smid);
968 _base_async_event(ioc, msix_index, reply);
970 /* reply free queue handling */
972 ioc->reply_free_host_index =
973 (ioc->reply_free_host_index ==
974 (ioc->reply_free_queue_depth - 1)) ?
975 0 : ioc->reply_free_host_index + 1;
976 ioc->reply_free[ioc->reply_free_host_index] =
979 writel(ioc->reply_free_host_index,
980 &ioc->chip->ReplyFreeHostIndex);
985 rpf->Words = cpu_to_le64(ULLONG_MAX);
986 reply_q->reply_post_host_index =
987 (reply_q->reply_post_host_index ==
988 (ioc->reply_post_queue_depth - 1)) ? 0 :
989 reply_q->reply_post_host_index + 1;
990 request_desript_type =
991 reply_q->reply_post_free[reply_q->reply_post_host_index].
992 Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
994 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
996 if (!reply_q->reply_post_host_index)
997 rpf = reply_q->reply_post_free;
1004 if (!completed_cmds) {
1005 atomic_dec(&reply_q->busy);
1009 if (ioc->is_warpdrive) {
1010 writel(reply_q->reply_post_host_index,
1011 ioc->reply_post_host_index[msix_index]);
1012 atomic_dec(&reply_q->busy);
1015 writel(reply_q->reply_post_host_index | (msix_index <<
1016 MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
1017 atomic_dec(&reply_q->busy);
1022 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1023 * @ioc: per adapter object
1027 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
1029 return (ioc->facts.IOCCapabilities &
1030 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
1034 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
1035 * @ioc: per adapter object
1036 * Context: ISR conext
1038 * Called when a Task Management request has completed. We want
1039 * to flush the other reply queues so all the outstanding IO has been
1040 * completed back to OS before we process the TM completetion.
1045 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1047 struct adapter_reply_queue *reply_q;
1049 /* If MSIX capability is turned off
1050 * then multi-queues are not enabled
1052 if (!_base_is_controller_msix_enabled(ioc))
1055 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
1056 if (ioc->shost_recovery)
1058 /* TMs are on msix_index == 0 */
1059 if (reply_q->msix_index == 0)
1061 _base_interrupt(reply_q->vector, (void *)reply_q);
1066 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
1067 * @cb_idx: callback index
1072 mpt2sas_base_release_callback_handler(u8 cb_idx)
1074 mpt_callbacks[cb_idx] = NULL;
1078 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1079 * @cb_func: callback function
1084 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
1088 for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
1089 if (mpt_callbacks[cb_idx] == NULL)
1092 mpt_callbacks[cb_idx] = cb_func;
1097 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1102 mpt2sas_base_initialize_callback_handler(void)
1106 for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
1107 mpt2sas_base_release_callback_handler(cb_idx);
1111 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1112 * @ioc: per adapter object
1113 * @paddr: virtual address for SGE
1115 * Create a zero length scatter gather entry to insure the IOCs hardware has
1116 * something to use if the target device goes brain dead and tries
1117 * to send data even when none is asked for.
1122 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
1124 u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
1125 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
1126 MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
1127 MPI2_SGE_FLAGS_SHIFT);
1128 ioc->base_add_sg_single(paddr, flags_length, -1);
1132 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1133 * @paddr: virtual address for SGE
1134 * @flags_length: SGE flags and data transfer length
1135 * @dma_addr: Physical address
1140 _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1142 Mpi2SGESimple32_t *sgel = paddr;
1144 flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
1145 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1146 sgel->FlagsLength = cpu_to_le32(flags_length);
1147 sgel->Address = cpu_to_le32(dma_addr);
1152 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1153 * @paddr: virtual address for SGE
1154 * @flags_length: SGE flags and data transfer length
1155 * @dma_addr: Physical address
1160 _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1162 Mpi2SGESimple64_t *sgel = paddr;
1164 flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
1165 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1166 sgel->FlagsLength = cpu_to_le32(flags_length);
1167 sgel->Address = cpu_to_le64(dma_addr);
1170 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1173 * _base_config_dma_addressing - set dma addressing
1174 * @ioc: per adapter object
1175 * @pdev: PCI device struct
1177 * Returns 0 for success, non-zero for failure.
1180 _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
1185 if (sizeof(dma_addr_t) > 4) {
1186 const uint64_t required_mask =
1187 dma_get_required_mask(&pdev->dev);
1188 if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
1189 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
1190 DMA_BIT_MASK(64))) {
1191 ioc->base_add_sg_single = &_base_add_sg_single_64;
1192 ioc->sge_size = sizeof(Mpi2SGESimple64_t);
1198 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1199 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
1200 ioc->base_add_sg_single = &_base_add_sg_single_32;
1201 ioc->sge_size = sizeof(Mpi2SGESimple32_t);
1208 printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1209 "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
1215 * _base_check_enable_msix - checks MSIX capabable.
1216 * @ioc: per adapter object
1218 * Check to see if card is capable of MSIX, and set number
1219 * of available msix vectors
1222 _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1225 u16 message_control;
1228 /* Check whether controller SAS2008 B0 controller,
1229 if it is SAS2008 B0 controller use IO-APIC instead of MSIX */
1230 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 &&
1231 ioc->pdev->revision == 0x01) {
1235 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1237 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
1238 "supported\n", ioc->name));
1242 /* get msix vector count */
1243 /* NUMA_IO not supported for older controllers */
1244 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
1245 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
1246 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
1247 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
1248 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
1249 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
1250 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
1251 ioc->msix_vector_count = 1;
1253 pci_read_config_word(ioc->pdev, base + 2, &message_control);
1254 ioc->msix_vector_count = (message_control & 0x3FF) + 1;
1256 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
1257 "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
1263 * _base_free_irq - free irq
1264 * @ioc: per adapter object
1266 * Freeing respective reply_queue from the list.
1269 _base_free_irq(struct MPT2SAS_ADAPTER *ioc)
1271 struct adapter_reply_queue *reply_q, *next;
1273 if (list_empty(&ioc->reply_queue_list))
1276 list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
1277 list_del(&reply_q->list);
1278 synchronize_irq(reply_q->vector);
1279 free_irq(reply_q->vector, reply_q);
1285 * _base_request_irq - request irq
1286 * @ioc: per adapter object
1287 * @index: msix index into vector table
1288 * @vector: irq vector
1290 * Inserting respective reply_queue into the list.
1293 _base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
1295 struct adapter_reply_queue *reply_q;
1298 reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
1300 printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
1301 ioc->name, (int)sizeof(struct adapter_reply_queue));
1305 reply_q->msix_index = index;
1306 reply_q->vector = vector;
1307 atomic_set(&reply_q->busy, 0);
1308 if (ioc->msix_enable)
1309 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
1310 MPT2SAS_DRIVER_NAME, ioc->id, index);
1312 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
1313 MPT2SAS_DRIVER_NAME, ioc->id);
1314 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1317 printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
1318 reply_q->name, vector);
1323 INIT_LIST_HEAD(&reply_q->list);
1324 list_add_tail(&reply_q->list, &ioc->reply_queue_list);
1329 * _base_assign_reply_queues - assigning msix index for each cpu
1330 * @ioc: per adapter object
1332 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1334 * It would nice if we could call irq_set_affinity, however it is not
1335 * an exported symbol
1338 _base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1340 struct adapter_reply_queue *reply_q;
1342 int cpu_grouping, loop, grouping, grouping_mod;
1344 if (!_base_is_controller_msix_enabled(ioc))
1347 memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
1348 /* when there are more cpus than available msix vectors,
1349 * then group cpus togeather on same irq
1351 if (ioc->cpu_count > ioc->msix_vector_count) {
1352 grouping = ioc->cpu_count / ioc->msix_vector_count;
1353 grouping_mod = ioc->cpu_count % ioc->msix_vector_count;
1354 if (grouping < 2 || (grouping == 2 && !grouping_mod))
1356 else if (grouping < 4 || (grouping == 4 && !grouping_mod))
1358 else if (grouping < 8 || (grouping == 8 && !grouping_mod))
1366 reply_q = list_entry(ioc->reply_queue_list.next,
1367 struct adapter_reply_queue, list);
1368 for_each_online_cpu(cpu_id) {
1369 if (!cpu_grouping) {
1370 ioc->cpu_msix_table[cpu_id] = reply_q->msix_index;
1371 reply_q = list_entry(reply_q->list.next,
1372 struct adapter_reply_queue, list);
1374 if (loop < cpu_grouping) {
1375 ioc->cpu_msix_table[cpu_id] =
1376 reply_q->msix_index;
1379 reply_q = list_entry(reply_q->list.next,
1380 struct adapter_reply_queue, list);
1381 ioc->cpu_msix_table[cpu_id] =
1382 reply_q->msix_index;
1390 * _base_disable_msix - disables msix
1391 * @ioc: per adapter object
1395 _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
1397 if (ioc->msix_enable) {
1398 pci_disable_msix(ioc->pdev);
1399 ioc->msix_enable = 0;
1404 * _base_enable_msix - enables msix, failback to io_apic
1405 * @ioc: per adapter object
1409 _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1411 struct msix_entry *entries, *a;
1416 INIT_LIST_HEAD(&ioc->reply_queue_list);
1418 if (msix_disable == -1 || msix_disable == 0)
1424 if (_base_check_enable_msix(ioc) != 0)
1427 ioc->reply_queue_count = min_t(int, ioc->cpu_count,
1428 ioc->msix_vector_count);
1430 entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
1433 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
1434 "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
1435 __LINE__, __func__));
1439 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
1442 r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
1444 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
1445 "failed (r=%d) !!!\n", ioc->name, r));
1450 ioc->msix_enable = 1;
1451 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
1452 r = _base_request_irq(ioc, i, a->vector);
1454 _base_free_irq(ioc);
1455 _base_disable_msix(ioc);
1464 /* failback to io_apic interrupt routing */
1467 r = _base_request_irq(ioc, 0, ioc->pdev->irq);
1473 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1474 * @ioc: per adapter object
1476 * Returns 0 for success, non-zero for failure.
1479 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1481 struct pci_dev *pdev = ioc->pdev;
1487 struct adapter_reply_queue *reply_q;
1489 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
1490 ioc->name, __func__));
1492 ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
1493 if (pci_enable_device_mem(pdev)) {
1494 printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
1495 "failed\n", ioc->name);
1500 if (pci_request_selected_regions(pdev, ioc->bars,
1501 MPT2SAS_DRIVER_NAME)) {
1502 printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
1503 "failed\n", ioc->name);
1508 /* AER (Advanced Error Reporting) hooks */
1509 pci_enable_pcie_error_reporting(pdev);
1511 pci_set_master(pdev);
1513 if (_base_config_dma_addressing(ioc, pdev) != 0) {
1514 printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
1515 ioc->name, pci_name(pdev));
1520 for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
1521 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1524 pio_chip = (u64)pci_resource_start(pdev, i);
1525 pio_sz = pci_resource_len(pdev, i);
1529 /* verify memory resource is valid before using */
1530 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
1531 ioc->chip_phys = pci_resource_start(pdev, i);
1532 chip_phys = (u64)ioc->chip_phys;
1533 memap_sz = pci_resource_len(pdev, i);
1534 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1535 if (ioc->chip == NULL) {
1536 printk(MPT2SAS_ERR_FMT "unable to map "
1537 "adapter memory!\n", ioc->name);
1545 _base_mask_interrupts(ioc);
1546 r = _base_enable_msix(ioc);
1550 list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
1551 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
1552 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
1553 "IO-APIC enabled"), reply_q->vector);
1555 printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1556 ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
1557 printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
1558 ioc->name, (unsigned long long)pio_chip, pio_sz);
1560 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1561 pci_save_state(pdev);
1569 pci_release_selected_regions(ioc->pdev, ioc->bars);
1570 pci_disable_pcie_error_reporting(pdev);
1571 pci_disable_device(pdev);
1576 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1577 * @ioc: per adapter object
1578 * @smid: system request message index(smid zero is invalid)
1580 * Returns virt pointer to message frame.
1583 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1585 return (void *)(ioc->request + (smid * ioc->request_sz));
1589 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1590 * @ioc: per adapter object
1591 * @smid: system request message index
1593 * Returns virt pointer to sense buffer.
1596 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1598 return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1602 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1603 * @ioc: per adapter object
1604 * @smid: system request message index
1606 * Returns phys pointer to the low 32bit address of the sense buffer.
1609 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1611 return cpu_to_le32(ioc->sense_dma +
1612 ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1616 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1617 * @ioc: per adapter object
1618 * @phys_addr: lower 32 physical addr of the reply
1620 * Converts 32bit lower physical addr into a virt address.
1623 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
1627 return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
1631 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1632 * @ioc: per adapter object
1633 * @cb_idx: callback index
1635 * Returns smid (zero is invalid)
1638 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1640 unsigned long flags;
1641 struct request_tracker *request;
1644 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1645 if (list_empty(&ioc->internal_free_list)) {
1646 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1647 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1648 ioc->name, __func__);
1652 request = list_entry(ioc->internal_free_list.next,
1653 struct request_tracker, tracker_list);
1654 request->cb_idx = cb_idx;
1655 smid = request->smid;
1656 list_del(&request->tracker_list);
1657 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1662 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1663 * @ioc: per adapter object
1664 * @cb_idx: callback index
1665 * @scmd: pointer to scsi command object
1667 * Returns smid (zero is invalid)
1670 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1671 struct scsi_cmnd *scmd)
1673 unsigned long flags;
1674 struct scsiio_tracker *request;
1677 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1678 if (list_empty(&ioc->free_list)) {
1679 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1680 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1681 ioc->name, __func__);
1685 request = list_entry(ioc->free_list.next,
1686 struct scsiio_tracker, tracker_list);
1687 request->scmd = scmd;
1688 request->cb_idx = cb_idx;
1689 smid = request->smid;
1690 list_del(&request->tracker_list);
1691 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1696 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1697 * @ioc: per adapter object
1698 * @cb_idx: callback index
1700 * Returns smid (zero is invalid)
1703 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1705 unsigned long flags;
1706 struct request_tracker *request;
1709 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1710 if (list_empty(&ioc->hpr_free_list)) {
1711 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1715 request = list_entry(ioc->hpr_free_list.next,
1716 struct request_tracker, tracker_list);
1717 request->cb_idx = cb_idx;
1718 smid = request->smid;
1719 list_del(&request->tracker_list);
1720 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1726 * mpt2sas_base_free_smid - put smid back on free_list
1727 * @ioc: per adapter object
1728 * @smid: system request message index
1733 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1735 unsigned long flags;
1737 struct chain_tracker *chain_req, *next;
1739 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1740 if (smid < ioc->hi_priority_smid) {
1743 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
1744 list_for_each_entry_safe(chain_req, next,
1745 &ioc->scsi_lookup[i].chain_list, tracker_list) {
1746 list_del_init(&chain_req->tracker_list);
1747 list_add_tail(&chain_req->tracker_list,
1748 &ioc->free_chain_list);
1751 ioc->scsi_lookup[i].cb_idx = 0xFF;
1752 ioc->scsi_lookup[i].scmd = NULL;
1753 ioc->scsi_lookup[i].direct_io = 0;
1754 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
1756 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1759 * See _wait_for_commands_to_complete() call with regards
1762 if (ioc->shost_recovery && ioc->pending_io_count) {
1763 if (ioc->pending_io_count == 1)
1764 wake_up(&ioc->reset_wq);
1765 ioc->pending_io_count--;
1768 } else if (smid < ioc->internal_smid) {
1770 i = smid - ioc->hi_priority_smid;
1771 ioc->hpr_lookup[i].cb_idx = 0xFF;
1772 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
1773 &ioc->hpr_free_list);
1774 } else if (smid <= ioc->hba_queue_depth) {
1775 /* internal queue */
1776 i = smid - ioc->internal_smid;
1777 ioc->internal_lookup[i].cb_idx = 0xFF;
1778 list_add_tail(&ioc->internal_lookup[i].tracker_list,
1779 &ioc->internal_free_list);
1781 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1785 * _base_writeq - 64 bit write to MMIO
1786 * @ioc: per adapter object
1788 * @addr: address in MMIO space
1789 * @writeq_lock: spin lock
1791 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1792 * care of 32 bit environment where its not quarenteed to send the entire word
1796 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1797 spinlock_t *writeq_lock)
1799 unsigned long flags;
1800 __u64 data_out = cpu_to_le64(b);
1802 spin_lock_irqsave(writeq_lock, flags);
1803 writel((u32)(data_out), addr);
1804 writel((u32)(data_out >> 32), (addr + 4));
1805 spin_unlock_irqrestore(writeq_lock, flags);
1808 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1809 spinlock_t *writeq_lock)
1811 writeq(cpu_to_le64(b), addr);
1816 _base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
1818 return ioc->cpu_msix_table[raw_smp_processor_id()];
1822 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1823 * @ioc: per adapter object
1824 * @smid: system request message index
1825 * @handle: device handle
1830 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
1832 Mpi2RequestDescriptorUnion_t descriptor;
1833 u64 *request = (u64 *)&descriptor;
1836 descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
1837 descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc);
1838 descriptor.SCSIIO.SMID = cpu_to_le16(smid);
1839 descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
1840 descriptor.SCSIIO.LMID = 0;
1841 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1842 &ioc->scsi_lookup_lock);
1847 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1848 * @ioc: per adapter object
1849 * @smid: system request message index
1854 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1856 Mpi2RequestDescriptorUnion_t descriptor;
1857 u64 *request = (u64 *)&descriptor;
1859 descriptor.HighPriority.RequestFlags =
1860 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
1861 descriptor.HighPriority.MSIxIndex = 0;
1862 descriptor.HighPriority.SMID = cpu_to_le16(smid);
1863 descriptor.HighPriority.LMID = 0;
1864 descriptor.HighPriority.Reserved1 = 0;
1865 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1866 &ioc->scsi_lookup_lock);
1870 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1871 * @ioc: per adapter object
1872 * @smid: system request message index
1877 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1879 Mpi2RequestDescriptorUnion_t descriptor;
1880 u64 *request = (u64 *)&descriptor;
1882 descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1883 descriptor.Default.MSIxIndex = _base_get_msix_index(ioc);
1884 descriptor.Default.SMID = cpu_to_le16(smid);
1885 descriptor.Default.LMID = 0;
1886 descriptor.Default.DescriptorTypeDependent = 0;
1887 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1888 &ioc->scsi_lookup_lock);
1892 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1893 * @ioc: per adapter object
1894 * @smid: system request message index
1895 * @io_index: value used to track the IO
1900 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1903 Mpi2RequestDescriptorUnion_t descriptor;
1904 u64 *request = (u64 *)&descriptor;
1906 descriptor.SCSITarget.RequestFlags =
1907 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
1908 descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc);
1909 descriptor.SCSITarget.SMID = cpu_to_le16(smid);
1910 descriptor.SCSITarget.LMID = 0;
1911 descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
1912 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1913 &ioc->scsi_lookup_lock);
1917 * _base_display_dell_branding - Disply branding string
1918 * @ioc: per adapter object
1923 _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1925 char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
1927 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
1930 memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
1931 switch (ioc->pdev->subsystem_device) {
1932 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
1933 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
1934 MPT2SAS_DELL_BRANDING_SIZE - 1);
1936 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
1937 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
1938 MPT2SAS_DELL_BRANDING_SIZE - 1);
1940 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
1941 strncpy(dell_branding,
1942 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
1943 MPT2SAS_DELL_BRANDING_SIZE - 1);
1945 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
1946 strncpy(dell_branding,
1947 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
1948 MPT2SAS_DELL_BRANDING_SIZE - 1);
1950 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
1951 strncpy(dell_branding,
1952 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
1953 MPT2SAS_DELL_BRANDING_SIZE - 1);
1955 case MPT2SAS_DELL_PERC_H200_SSDID:
1956 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
1957 MPT2SAS_DELL_BRANDING_SIZE - 1);
1959 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
1960 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
1961 MPT2SAS_DELL_BRANDING_SIZE - 1);
1964 sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
1968 printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
1969 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
1970 ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
1971 ioc->pdev->subsystem_device);
1975 * _base_display_intel_branding - Display branding string
1976 * @ioc: per adapter object
1981 _base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
1983 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1986 switch (ioc->pdev->device) {
1987 case MPI2_MFGPAGE_DEVID_SAS2008:
1988 switch (ioc->pdev->subsystem_device) {
1989 case MPT2SAS_INTEL_RMS2LL080_SSDID:
1990 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1991 MPT2SAS_INTEL_RMS2LL080_BRANDING);
1993 case MPT2SAS_INTEL_RMS2LL040_SSDID:
1994 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1995 MPT2SAS_INTEL_RMS2LL040_BRANDING);
1997 case MPT2SAS_INTEL_SSD910_SSDID:
1998 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1999 MPT2SAS_INTEL_SSD910_BRANDING);
2004 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2005 switch (ioc->pdev->subsystem_device) {
2006 case MPT2SAS_INTEL_RS25GB008_SSDID:
2007 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2008 MPT2SAS_INTEL_RS25GB008_BRANDING);
2010 case MPT2SAS_INTEL_RMS25JB080_SSDID:
2011 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2012 MPT2SAS_INTEL_RMS25JB080_BRANDING);
2014 case MPT2SAS_INTEL_RMS25JB040_SSDID:
2015 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2016 MPT2SAS_INTEL_RMS25JB040_BRANDING);
2018 case MPT2SAS_INTEL_RMS25KB080_SSDID:
2019 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2020 MPT2SAS_INTEL_RMS25KB080_BRANDING);
2022 case MPT2SAS_INTEL_RMS25KB040_SSDID:
2023 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2024 MPT2SAS_INTEL_RMS25KB040_BRANDING);
2035 * _base_display_hp_branding - Display branding string
2036 * @ioc: per adapter object
2041 _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
2043 if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
2046 switch (ioc->pdev->device) {
2047 case MPI2_MFGPAGE_DEVID_SAS2004:
2048 switch (ioc->pdev->subsystem_device) {
2049 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
2050 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2051 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
2056 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2057 switch (ioc->pdev->subsystem_device) {
2058 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
2059 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2060 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
2062 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
2063 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2064 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
2066 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
2067 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2068 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
2070 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
2071 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2072 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
2083 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2084 * @ioc: per adapter object
2089 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
2093 u32 iounit_pg1_flags;
2096 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2097 strncpy(desc, ioc->manu_pg0.ChipName, 16);
2098 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
2099 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2101 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2102 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2103 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2104 ioc->facts.FWVersion.Word & 0x000000FF,
2105 ioc->pdev->revision,
2106 (bios_version & 0xFF000000) >> 24,
2107 (bios_version & 0x00FF0000) >> 16,
2108 (bios_version & 0x0000FF00) >> 8,
2109 bios_version & 0x000000FF);
2111 _base_display_dell_branding(ioc);
2112 _base_display_intel_branding(ioc);
2113 _base_display_hp_branding(ioc);
2115 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
2117 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
2118 printk("Initiator");
2122 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
2123 printk("%sTarget", i ? "," : "");
2129 printk("Capabilities=(");
2131 if (!ioc->hide_ir_msg) {
2132 if (ioc->facts.IOCCapabilities &
2133 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2139 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
2140 printk("%sTLR", i ? "," : "");
2144 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
2145 printk("%sMulticast", i ? "," : "");
2149 if (ioc->facts.IOCCapabilities &
2150 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
2151 printk("%sBIDI Target", i ? "," : "");
2155 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
2156 printk("%sEEDP", i ? "," : "");
2160 if (ioc->facts.IOCCapabilities &
2161 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
2162 printk("%sSnapshot Buffer", i ? "," : "");
2166 if (ioc->facts.IOCCapabilities &
2167 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
2168 printk("%sDiag Trace Buffer", i ? "," : "");
2172 if (ioc->facts.IOCCapabilities &
2173 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
2174 printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
2178 if (ioc->facts.IOCCapabilities &
2179 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
2180 printk("%sTask Set Full", i ? "," : "");
2184 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2185 if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
2186 printk("%sNCQ", i ? "," : "");
2194 * _base_update_missing_delay - change the missing delay timers
2195 * @ioc: per adapter object
2196 * @device_missing_delay: amount of time till device is reported missing
2197 * @io_missing_delay: interval IO is returned when there is a missing device
2201 * Passed on the command line, this function will modify the device missing
2202 * delay, as well as the io missing delay. This should be called at driver
2206 _base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
2207 u16 device_missing_delay, u8 io_missing_delay)
2209 u16 dmd, dmd_new, dmd_orignal;
2210 u8 io_missing_delay_original;
2212 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
2213 Mpi2ConfigReply_t mpi_reply;
2217 mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
2221 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
2222 sizeof(Mpi2SasIOUnit1PhyData_t));
2223 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
2224 if (!sas_iounit_pg1) {
2225 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2226 ioc->name, __FILE__, __LINE__, __func__);
2229 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
2230 sas_iounit_pg1, sz))) {
2231 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2232 ioc->name, __FILE__, __LINE__, __func__);
2235 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2236 MPI2_IOCSTATUS_MASK;
2237 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2238 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2239 ioc->name, __FILE__, __LINE__, __func__);
2243 /* device missing delay */
2244 dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
2245 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2246 dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2248 dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2250 if (device_missing_delay > 0x7F) {
2251 dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
2252 device_missing_delay;
2254 dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
2256 dmd = device_missing_delay;
2257 sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
2259 /* io missing delay */
2260 io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
2261 sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
2263 if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
2265 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2267 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2270 dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2271 printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
2272 "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
2273 printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
2274 "new(%d)\n", ioc->name, io_missing_delay_original,
2276 ioc->device_missing_delay = dmd_new;
2277 ioc->io_missing_delay = io_missing_delay;
2281 kfree(sas_iounit_pg1);
2285 * _base_static_config_pages - static start of day config pages
2286 * @ioc: per adapter object
2291 _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
2293 Mpi2ConfigReply_t mpi_reply;
2294 u32 iounit_pg1_flags;
2296 mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
2297 if (ioc->ir_firmware)
2298 mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
2300 mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
2301 mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
2302 mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
2303 mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
2304 mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2305 _base_display_ioc_capabilities(ioc);
2308 * Enable task_set_full handling in iounit_pg1 when the
2309 * facts capabilities indicate that its supported.
2311 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2312 if ((ioc->facts.IOCCapabilities &
2313 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
2315 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2318 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2319 ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
2320 mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2325 * _base_release_memory_pools - release memory
2326 * @ioc: per adapter object
2328 * Free memory allocated from _base_allocate_memory_pools.
2333 _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
2337 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2341 pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
2342 ioc->request, ioc->request_dma);
2343 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
2344 ": free\n", ioc->name, ioc->request));
2345 ioc->request = NULL;
2349 pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
2350 if (ioc->sense_dma_pool)
2351 pci_pool_destroy(ioc->sense_dma_pool);
2352 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
2353 ": free\n", ioc->name, ioc->sense));
2358 pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
2359 if (ioc->reply_dma_pool)
2360 pci_pool_destroy(ioc->reply_dma_pool);
2361 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
2362 ": free\n", ioc->name, ioc->reply));
2366 if (ioc->reply_free) {
2367 pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
2368 ioc->reply_free_dma);
2369 if (ioc->reply_free_dma_pool)
2370 pci_pool_destroy(ioc->reply_free_dma_pool);
2371 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
2372 "(0x%p): free\n", ioc->name, ioc->reply_free));
2373 ioc->reply_free = NULL;
2376 if (ioc->reply_post_free) {
2377 pci_pool_free(ioc->reply_post_free_dma_pool,
2378 ioc->reply_post_free, ioc->reply_post_free_dma);
2379 if (ioc->reply_post_free_dma_pool)
2380 pci_pool_destroy(ioc->reply_post_free_dma_pool);
2381 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2382 "reply_post_free_pool(0x%p): free\n", ioc->name,
2383 ioc->reply_post_free));
2384 ioc->reply_post_free = NULL;
2387 if (ioc->config_page) {
2388 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2389 "config_page(0x%p): free\n", ioc->name,
2391 pci_free_consistent(ioc->pdev, ioc->config_page_sz,
2392 ioc->config_page, ioc->config_page_dma);
2395 if (ioc->scsi_lookup) {
2396 free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
2397 ioc->scsi_lookup = NULL;
2399 kfree(ioc->hpr_lookup);
2400 kfree(ioc->internal_lookup);
2401 if (ioc->chain_lookup) {
2402 for (i = 0; i < ioc->chain_depth; i++) {
2403 if (ioc->chain_lookup[i].chain_buffer)
2404 pci_pool_free(ioc->chain_dma_pool,
2405 ioc->chain_lookup[i].chain_buffer,
2406 ioc->chain_lookup[i].chain_buffer_dma);
2408 if (ioc->chain_dma_pool)
2409 pci_pool_destroy(ioc->chain_dma_pool);
2410 free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
2411 ioc->chain_lookup = NULL;
2417 * _base_allocate_memory_pools - allocate start of day memory pools
2418 * @ioc: per adapter object
2419 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2421 * Returns 0 success, anything else error
2424 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2426 struct mpt2sas_facts *facts;
2427 u16 max_sge_elements;
2428 u16 chains_needed_per_io;
2429 u32 sz, total_sz, reply_post_free_sz;
2431 u16 max_request_credit;
2434 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2438 facts = &ioc->facts;
2440 /* command line tunables for max sgl entries */
2441 if (max_sgl_entries != -1) {
2442 ioc->shost->sg_tablesize = (max_sgl_entries <
2443 MPT2SAS_SG_DEPTH) ? max_sgl_entries :
2446 ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
2449 /* command line tunables for max controller queue depth */
2450 if (max_queue_depth != -1 && max_queue_depth != 0) {
2451 max_request_credit = min_t(u16, max_queue_depth +
2452 ioc->hi_priority_depth + ioc->internal_depth,
2453 facts->RequestCredit);
2454 if (max_request_credit > MAX_HBA_QUEUE_DEPTH)
2455 max_request_credit = MAX_HBA_QUEUE_DEPTH;
2457 max_request_credit = min_t(u16, facts->RequestCredit,
2458 MAX_HBA_QUEUE_DEPTH);
2460 ioc->hba_queue_depth = max_request_credit;
2461 ioc->hi_priority_depth = facts->HighPriorityCredit;
2462 ioc->internal_depth = ioc->hi_priority_depth + 5;
2464 /* request frame size */
2465 ioc->request_sz = facts->IOCRequestFrameSize * 4;
2467 /* reply frame size */
2468 ioc->reply_sz = facts->ReplyFrameSize * 4;
2472 /* calculate number of sg elements left over in the 1st frame */
2473 max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
2474 sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
2475 ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
2477 /* now do the same for a chain buffer */
2478 max_sge_elements = ioc->request_sz - ioc->sge_size;
2479 ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
2481 ioc->chain_offset_value_for_main_message =
2482 ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
2483 (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
2486 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2488 chains_needed_per_io = ((ioc->shost->sg_tablesize -
2489 ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
2491 if (chains_needed_per_io > facts->MaxChainDepth) {
2492 chains_needed_per_io = facts->MaxChainDepth;
2493 ioc->shost->sg_tablesize = min_t(u16,
2494 ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
2495 * chains_needed_per_io), ioc->shost->sg_tablesize);
2497 ioc->chains_needed_per_io = chains_needed_per_io;
2499 /* reply free queue sizing - taking into account for 64 FW events */
2500 ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64;
2502 /* align the reply post queue on the next 16 count boundary */
2503 if (!ioc->reply_free_queue_depth % 16)
2504 ioc->reply_post_queue_depth = ioc->reply_free_queue_depth + 16;
2506 ioc->reply_post_queue_depth = ioc->reply_free_queue_depth +
2507 32 - (ioc->reply_free_queue_depth % 16);
2508 if (ioc->reply_post_queue_depth >
2509 facts->MaxReplyDescriptorPostQueueDepth) {
2510 ioc->reply_post_queue_depth = min_t(u16,
2511 (facts->MaxReplyDescriptorPostQueueDepth -
2512 (facts->MaxReplyDescriptorPostQueueDepth % 16)),
2513 (ioc->hba_queue_depth - (ioc->hba_queue_depth % 16)));
2514 ioc->reply_free_queue_depth = ioc->reply_post_queue_depth - 16;
2515 ioc->hba_queue_depth = ioc->reply_free_queue_depth - 64;
2519 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
2520 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2521 "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
2522 ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
2523 ioc->chains_needed_per_io));
2525 ioc->scsiio_depth = ioc->hba_queue_depth -
2526 ioc->hi_priority_depth - ioc->internal_depth;
2528 /* set the scsi host can_queue depth
2529 * with some internal commands that could be outstanding
2531 ioc->shost->can_queue = ioc->scsiio_depth;
2532 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2533 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2535 /* contiguous pool for request and chains, 16 byte align, one extra "
2538 ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
2539 sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
2541 /* hi-priority queue */
2542 sz += (ioc->hi_priority_depth * ioc->request_sz);
2544 /* internal queue */
2545 sz += (ioc->internal_depth * ioc->request_sz);
2547 ioc->request_dma_sz = sz;
2548 ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
2549 if (!ioc->request) {
2550 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2551 "failed: 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);
2554 if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
2557 ioc->hba_queue_depth = max_request_credit - retry_sz;
2558 goto retry_allocation;
2562 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2563 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2564 "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
2565 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2568 /* hi-priority queue */
2569 ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
2571 ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
2574 /* internal queue */
2575 ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
2577 ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
2581 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
2582 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2583 ioc->request, ioc->hba_queue_depth, ioc->request_sz,
2584 (ioc->hba_queue_depth * ioc->request_sz)/1024));
2585 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
2586 ioc->name, (unsigned long long) ioc->request_dma));
2589 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
2590 ioc->scsi_lookup_pages = get_order(sz);
2591 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
2592 GFP_KERNEL, ioc->scsi_lookup_pages);
2593 if (!ioc->scsi_lookup) {
2594 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
2595 "sz(%d)\n", ioc->name, (int)sz);
2599 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
2600 "depth(%d)\n", ioc->name, ioc->request,
2601 ioc->scsiio_depth));
2603 ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH);
2604 sz = ioc->chain_depth * sizeof(struct chain_tracker);
2605 ioc->chain_pages = get_order(sz);
2607 ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
2608 GFP_KERNEL, ioc->chain_pages);
2609 if (!ioc->chain_lookup) {
2610 printk(MPT2SAS_ERR_FMT "chain_lookup: get_free_pages failed, "
2611 "sz(%d)\n", ioc->name, (int)sz);
2614 ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
2615 ioc->request_sz, 16, 0);
2616 if (!ioc->chain_dma_pool) {
2617 printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
2618 "failed\n", ioc->name);
2621 for (i = 0; i < ioc->chain_depth; i++) {
2622 ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
2623 ioc->chain_dma_pool , GFP_KERNEL,
2624 &ioc->chain_lookup[i].chain_buffer_dma);
2625 if (!ioc->chain_lookup[i].chain_buffer) {
2626 ioc->chain_depth = i;
2629 total_sz += ioc->request_sz;
2632 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
2633 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2634 ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
2635 ioc->request_sz))/1024));
2637 /* initialize hi-priority queue smid's */
2638 ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
2639 sizeof(struct request_tracker), GFP_KERNEL);
2640 if (!ioc->hpr_lookup) {
2641 printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
2645 ioc->hi_priority_smid = ioc->scsiio_depth + 1;
2646 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
2647 "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
2648 ioc->hi_priority_depth, ioc->hi_priority_smid));
2650 /* initialize internal queue smid's */
2651 ioc->internal_lookup = kcalloc(ioc->internal_depth,
2652 sizeof(struct request_tracker), GFP_KERNEL);
2653 if (!ioc->internal_lookup) {
2654 printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
2658 ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
2659 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
2660 "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
2661 ioc->internal_depth, ioc->internal_smid));
2663 /* sense buffers, 4 byte align */
2664 sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
2665 ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
2667 if (!ioc->sense_dma_pool) {
2668 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
2672 ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
2675 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
2679 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
2680 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2681 "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
2682 SCSI_SENSE_BUFFERSIZE, sz/1024));
2683 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
2684 ioc->name, (unsigned long long)ioc->sense_dma));
2687 /* reply pool, 4 byte align */
2688 sz = ioc->reply_free_queue_depth * ioc->reply_sz;
2689 ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
2691 if (!ioc->reply_dma_pool) {
2692 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
2696 ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
2699 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
2703 ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
2704 ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
2705 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
2706 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
2707 ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
2708 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
2709 ioc->name, (unsigned long long)ioc->reply_dma));
2712 /* reply free queue, 16 byte align */
2713 sz = ioc->reply_free_queue_depth * 4;
2714 ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
2715 ioc->pdev, sz, 16, 0);
2716 if (!ioc->reply_free_dma_pool) {
2717 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
2718 "failed\n", ioc->name);
2721 ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
2722 &ioc->reply_free_dma);
2723 if (!ioc->reply_free) {
2724 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
2725 "failed\n", ioc->name);
2728 memset(ioc->reply_free, 0, sz);
2729 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
2730 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
2731 ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
2732 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
2733 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
2736 /* reply post queue, 16 byte align */
2737 reply_post_free_sz = ioc->reply_post_queue_depth *
2738 sizeof(Mpi2DefaultReplyDescriptor_t);
2739 if (_base_is_controller_msix_enabled(ioc))
2740 sz = reply_post_free_sz * ioc->reply_queue_count;
2742 sz = reply_post_free_sz;
2743 ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
2744 ioc->pdev, sz, 16, 0);
2745 if (!ioc->reply_post_free_dma_pool) {
2746 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
2747 "failed\n", ioc->name);
2750 ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
2751 GFP_KERNEL, &ioc->reply_post_free_dma);
2752 if (!ioc->reply_post_free) {
2753 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
2754 "failed\n", ioc->name);
2757 memset(ioc->reply_post_free, 0, sz);
2758 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
2759 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2760 ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
2762 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
2763 "(0x%llx)\n", ioc->name, (unsigned long long)
2764 ioc->reply_post_free_dma));
2767 ioc->config_page_sz = 512;
2768 ioc->config_page = pci_alloc_consistent(ioc->pdev,
2769 ioc->config_page_sz, &ioc->config_page_dma);
2770 if (!ioc->config_page) {
2771 printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
2772 "failed\n", ioc->name);
2775 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
2776 "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
2777 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
2778 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
2779 total_sz += ioc->config_page_sz;
2781 printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
2782 ioc->name, total_sz/1024);
2783 printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
2784 "Max Controller Queue Depth(%d)\n",
2785 ioc->name, ioc->shost->can_queue, facts->RequestCredit);
2786 printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
2787 ioc->name, ioc->shost->sg_tablesize);
2796 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2797 * @ioc: Pointer to MPT_ADAPTER structure
2798 * @cooked: Request raw or cooked IOC state
2800 * Returns all IOC Doorbell register bits if cooked==0, else just the
2801 * Doorbell bits in MPI_IOC_STATE_MASK.
2804 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
2808 s = readl(&ioc->chip->Doorbell);
2809 sc = s & MPI2_IOC_STATE_MASK;
2810 return cooked ? sc : s;
2814 * _base_wait_on_iocstate - waiting on a particular ioc state
2815 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2816 * @timeout: timeout in second
2817 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2819 * Returns 0 for success, non-zero for failure.
2822 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
2829 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2831 current_state = mpt2sas_base_get_iocstate(ioc, 1);
2832 if (current_state == ioc_state)
2834 if (count && current_state == MPI2_IOC_STATE_FAULT)
2836 if (sleep_flag == CAN_SLEEP)
2843 return current_state;
2847 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2848 * a write to the doorbell)
2849 * @ioc: per adapter object
2850 * @timeout: timeout in second
2851 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2853 * Returns 0 for success, non-zero for failure.
2855 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2858 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
2865 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2867 int_status = readl(&ioc->chip->HostInterruptStatus);
2868 if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2869 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2870 "successful count(%d), timeout(%d)\n", ioc->name,
2871 __func__, count, timeout));
2874 if (sleep_flag == CAN_SLEEP)
2881 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2882 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2887 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2888 * @ioc: per adapter object
2889 * @timeout: timeout in second
2890 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2892 * Returns 0 for success, non-zero for failure.
2894 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2898 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
2906 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2908 int_status = readl(&ioc->chip->HostInterruptStatus);
2909 if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
2910 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2911 "successful count(%d), timeout(%d)\n", ioc->name,
2912 __func__, count, timeout));
2914 } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2915 doorbell = readl(&ioc->chip->Doorbell);
2916 if ((doorbell & MPI2_IOC_STATE_MASK) ==
2917 MPI2_IOC_STATE_FAULT) {
2918 mpt2sas_base_fault_info(ioc , doorbell);
2921 } else if (int_status == 0xFFFFFFFF)
2924 if (sleep_flag == CAN_SLEEP)
2932 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2933 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2938 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2939 * @ioc: per adapter object
2940 * @timeout: timeout in second
2941 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2943 * Returns 0 for success, non-zero for failure.
2947 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
2954 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2956 doorbell_reg = readl(&ioc->chip->Doorbell);
2957 if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
2958 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2959 "successful count(%d), timeout(%d)\n", ioc->name,
2960 __func__, count, timeout));
2963 if (sleep_flag == CAN_SLEEP)
2970 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2971 "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
2976 * _base_send_ioc_reset - send doorbell reset
2977 * @ioc: per adapter object
2978 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2979 * @timeout: timeout in second
2980 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2982 * Returns 0 for success, non-zero for failure.
2985 _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
2991 if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
2992 printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
2993 ioc->name, __func__);
2997 if (!(ioc->facts.IOCCapabilities &
2998 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
3001 printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
3003 writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
3004 &ioc->chip->Doorbell);
3005 if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
3009 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
3010 timeout, sleep_flag);
3012 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3013 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3018 printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
3019 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
3024 * _base_handshake_req_reply_wait - send request thru doorbell interface
3025 * @ioc: per adapter object
3026 * @request_bytes: request length
3027 * @request: pointer having request payload
3028 * @reply_bytes: reply length
3029 * @reply: pointer to reply payload
3030 * @timeout: timeout in second
3031 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3033 * Returns 0 for success, non-zero for failure.
3036 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
3037 u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
3039 MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
3045 /* make sure doorbell is not in use */
3046 if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
3047 printk(MPT2SAS_ERR_FMT "doorbell is in use "
3048 " (line=%d)\n", ioc->name, __LINE__);
3052 /* clear pending doorbell interrupts from previous state changes */
3053 if (readl(&ioc->chip->HostInterruptStatus) &
3054 MPI2_HIS_IOC2SYS_DB_STATUS)
3055 writel(0, &ioc->chip->HostInterruptStatus);
3057 /* send message to ioc */
3058 writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
3059 ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
3060 &ioc->chip->Doorbell);
3062 if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
3063 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3064 "int failed (line=%d)\n", ioc->name, __LINE__);
3067 writel(0, &ioc->chip->HostInterruptStatus);
3069 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
3070 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3071 "ack failed (line=%d)\n", ioc->name, __LINE__);
3075 /* send message 32-bits at a time */
3076 for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
3077 writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
3078 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
3083 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3084 "sending request failed (line=%d)\n", ioc->name, __LINE__);
3088 /* now wait for the reply */
3089 if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
3090 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3091 "int failed (line=%d)\n", ioc->name, __LINE__);
3095 /* read the first two 16-bits, it gives the total length of the reply */
3096 reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3097 & MPI2_DOORBELL_DATA_MASK);
3098 writel(0, &ioc->chip->HostInterruptStatus);
3099 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3100 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3101 "int failed (line=%d)\n", ioc->name, __LINE__);
3104 reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3105 & MPI2_DOORBELL_DATA_MASK);
3106 writel(0, &ioc->chip->HostInterruptStatus);
3108 for (i = 2; i < default_reply->MsgLength * 2; i++) {
3109 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3110 printk(MPT2SAS_ERR_FMT "doorbell "
3111 "handshake int failed (line=%d)\n", ioc->name,
3115 if (i >= reply_bytes/2) /* overflow case */
3116 dummy = readl(&ioc->chip->Doorbell);
3118 reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3119 & MPI2_DOORBELL_DATA_MASK);
3120 writel(0, &ioc->chip->HostInterruptStatus);
3123 _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
3124 if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
3125 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
3126 " (line=%d)\n", ioc->name, __LINE__));
3128 writel(0, &ioc->chip->HostInterruptStatus);
3130 if (ioc->logging_level & MPT_DEBUG_INIT) {
3131 mfp = (__le32 *)reply;
3132 printk(KERN_INFO "\toffset:data\n");
3133 for (i = 0; i < reply_bytes/4; i++)
3134 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3135 le32_to_cpu(mfp[i]));
3141 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3142 * @ioc: per adapter object
3143 * @mpi_reply: the reply payload from FW
3144 * @mpi_request: the request payload sent to FW
3146 * The SAS IO Unit Control Request message allows the host to perform low-level
3147 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3148 * to obtain the IOC assigned device handles for a device if it has other
3149 * identifying information about the device, in addition allows the host to
3150 * remove IOC resources associated with the device.
3152 * Returns 0 for success, non-zero for failure.
3155 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
3156 Mpi2SasIoUnitControlReply_t *mpi_reply,
3157 Mpi2SasIoUnitControlRequest_t *mpi_request)
3161 unsigned long timeleft;
3165 u16 wait_state_count;
3167 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3170 mutex_lock(&ioc->base_cmds.mutex);
3172 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3173 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3174 ioc->name, __func__);
3179 wait_state_count = 0;
3180 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3181 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3182 if (wait_state_count++ == 10) {
3183 printk(MPT2SAS_ERR_FMT
3184 "%s: failed due to ioc not operational\n",
3185 ioc->name, __func__);
3190 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3191 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3192 "operational state(count=%d)\n", ioc->name,
3193 __func__, wait_state_count);
3196 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3198 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3199 ioc->name, __func__);
3205 ioc->base_cmds.status = MPT2_CMD_PENDING;
3206 request = mpt2sas_base_get_msg_frame(ioc, smid);
3207 ioc->base_cmds.smid = smid;
3208 memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
3209 if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3210 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
3211 ioc->ioc_link_reset_in_progress = 1;
3212 init_completion(&ioc->base_cmds.done);
3213 mpt2sas_base_put_smid_default(ioc, smid);
3214 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3215 msecs_to_jiffies(10000));
3216 if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3217 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
3218 ioc->ioc_link_reset_in_progress)
3219 ioc->ioc_link_reset_in_progress = 0;
3220 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3221 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3222 ioc->name, __func__);
3223 _debug_dump_mf(mpi_request,
3224 sizeof(Mpi2SasIoUnitControlRequest_t)/4);
3225 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3227 goto issue_host_reset;
3229 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3230 memcpy(mpi_reply, ioc->base_cmds.reply,
3231 sizeof(Mpi2SasIoUnitControlReply_t));
3233 memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
3234 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3239 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3241 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3244 mutex_unlock(&ioc->base_cmds.mutex);
3250 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3251 * @ioc: per adapter object
3252 * @mpi_reply: the reply payload from FW
3253 * @mpi_request: the request payload sent to FW
3255 * The SCSI Enclosure Processor request message causes the IOC to
3256 * communicate with SES devices to control LED status signals.
3258 * Returns 0 for success, non-zero for failure.
3261 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
3262 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
3266 unsigned long timeleft;
3270 u16 wait_state_count;
3272 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3275 mutex_lock(&ioc->base_cmds.mutex);
3277 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3278 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3279 ioc->name, __func__);
3284 wait_state_count = 0;
3285 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3286 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3287 if (wait_state_count++ == 10) {
3288 printk(MPT2SAS_ERR_FMT
3289 "%s: failed due to ioc not operational\n",
3290 ioc->name, __func__);
3295 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3296 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3297 "operational state(count=%d)\n", ioc->name,
3298 __func__, wait_state_count);
3301 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3303 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3304 ioc->name, __func__);
3310 ioc->base_cmds.status = MPT2_CMD_PENDING;
3311 request = mpt2sas_base_get_msg_frame(ioc, smid);
3312 ioc->base_cmds.smid = smid;
3313 memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
3314 init_completion(&ioc->base_cmds.done);
3315 mpt2sas_base_put_smid_default(ioc, smid);
3316 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3317 msecs_to_jiffies(10000));
3318 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3319 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3320 ioc->name, __func__);
3321 _debug_dump_mf(mpi_request,
3322 sizeof(Mpi2SepRequest_t)/4);
3323 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3325 goto issue_host_reset;
3327 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3328 memcpy(mpi_reply, ioc->base_cmds.reply,
3329 sizeof(Mpi2SepReply_t));
3331 memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
3332 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3337 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3339 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3342 mutex_unlock(&ioc->base_cmds.mutex);
3347 * _base_get_port_facts - obtain port facts reply and save in ioc
3348 * @ioc: per adapter object
3349 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3351 * Returns 0 for success, non-zero for failure.
3354 _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
3356 Mpi2PortFactsRequest_t mpi_request;
3357 Mpi2PortFactsReply_t mpi_reply;
3358 struct mpt2sas_port_facts *pfacts;
3359 int mpi_reply_sz, mpi_request_sz, r;
3361 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3364 mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
3365 mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
3366 memset(&mpi_request, 0, mpi_request_sz);
3367 mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
3368 mpi_request.PortNumber = port;
3369 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3370 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3373 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3374 ioc->name, __func__, r);
3378 pfacts = &ioc->pfacts[port];
3379 memset(pfacts, 0, sizeof(struct mpt2sas_port_facts));
3380 pfacts->PortNumber = mpi_reply.PortNumber;
3381 pfacts->VP_ID = mpi_reply.VP_ID;
3382 pfacts->VF_ID = mpi_reply.VF_ID;
3383 pfacts->MaxPostedCmdBuffers =
3384 le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
3390 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3391 * @ioc: per adapter object
3392 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3394 * Returns 0 for success, non-zero for failure.
3397 _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3399 Mpi2IOCFactsRequest_t mpi_request;
3400 Mpi2IOCFactsReply_t mpi_reply;
3401 struct mpt2sas_facts *facts;
3402 int mpi_reply_sz, mpi_request_sz, r;
3404 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3407 mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
3408 mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
3409 memset(&mpi_request, 0, mpi_request_sz);
3410 mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
3411 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3412 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3415 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3416 ioc->name, __func__, r);
3420 facts = &ioc->facts;
3421 memset(facts, 0, sizeof(struct mpt2sas_facts));
3422 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
3423 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
3424 facts->VP_ID = mpi_reply.VP_ID;
3425 facts->VF_ID = mpi_reply.VF_ID;
3426 facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
3427 facts->MaxChainDepth = mpi_reply.MaxChainDepth;
3428 facts->WhoInit = mpi_reply.WhoInit;
3429 facts->NumberOfPorts = mpi_reply.NumberOfPorts;
3430 facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
3431 facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
3432 facts->MaxReplyDescriptorPostQueueDepth =
3433 le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
3434 facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
3435 facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
3436 if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
3437 ioc->ir_firmware = 1;
3438 facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
3439 facts->IOCRequestFrameSize =
3440 le16_to_cpu(mpi_reply.IOCRequestFrameSize);
3441 facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
3442 facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
3443 ioc->shost->max_id = -1;
3444 facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
3445 facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
3446 facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
3447 facts->HighPriorityCredit =
3448 le16_to_cpu(mpi_reply.HighPriorityCredit);
3449 facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
3450 facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
3452 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
3453 "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
3454 facts->MaxChainDepth));
3455 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
3456 "reply frame size(%d)\n", ioc->name,
3457 facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
3462 * _base_send_ioc_init - send ioc_init to firmware
3463 * @ioc: per adapter object
3464 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3466 * Returns 0 for success, non-zero for failure.
3469 _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3471 Mpi2IOCInitRequest_t mpi_request;
3472 Mpi2IOCInitReply_t mpi_reply;
3474 struct timeval current_time;
3477 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3480 memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
3481 mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
3482 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
3483 mpi_request.VF_ID = 0; /* TODO */
3484 mpi_request.VP_ID = 0;
3485 mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
3486 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
3488 if (_base_is_controller_msix_enabled(ioc))
3489 mpi_request.HostMSIxVectors = ioc->reply_queue_count;
3490 mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
3491 mpi_request.ReplyDescriptorPostQueueDepth =
3492 cpu_to_le16(ioc->reply_post_queue_depth);
3493 mpi_request.ReplyFreeQueueDepth =
3494 cpu_to_le16(ioc->reply_free_queue_depth);
3496 mpi_request.SenseBufferAddressHigh =
3497 cpu_to_le32((u64)ioc->sense_dma >> 32);
3498 mpi_request.SystemReplyAddressHigh =
3499 cpu_to_le32((u64)ioc->reply_dma >> 32);
3500 mpi_request.SystemRequestFrameBaseAddress =
3501 cpu_to_le64((u64)ioc->request_dma);
3502 mpi_request.ReplyFreeQueueAddress =
3503 cpu_to_le64((u64)ioc->reply_free_dma);
3504 mpi_request.ReplyDescriptorPostQueueAddress =
3505 cpu_to_le64((u64)ioc->reply_post_free_dma);
3508 /* This time stamp specifies number of milliseconds
3509 * since epoch ~ midnight January 1, 1970.
3511 do_gettimeofday(¤t_time);
3512 mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
3513 (current_time.tv_usec / 1000));
3515 if (ioc->logging_level & MPT_DEBUG_INIT) {
3519 mfp = (__le32 *)&mpi_request;
3520 printk(KERN_INFO "\toffset:data\n");
3521 for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
3522 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3523 le32_to_cpu(mfp[i]));
3526 r = _base_handshake_req_reply_wait(ioc,
3527 sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
3528 sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
3532 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3533 ioc->name, __func__, r);
3537 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
3538 if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
3539 mpi_reply.IOCLogInfo) {
3540 printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
3548 * mpt2sas_port_enable_done - command completion routine for port enable
3549 * @ioc: per adapter object
3550 * @smid: system request message index
3551 * @msix_index: MSIX table index supplied by the OS
3552 * @reply: reply message frame(lower 32bit addr)
3554 * Return 1 meaning mf should be freed from _base_interrupt
3555 * 0 means the mf is freed from this function.
3558 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3561 MPI2DefaultReply_t *mpi_reply;
3564 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3565 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3568 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3571 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3573 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3574 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3575 mpi_reply->MsgLength*4);
3577 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3579 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3581 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3582 ioc->port_enable_failed = 1;
3584 if (ioc->is_driver_loading) {
3585 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3586 mpt2sas_port_enable_complete(ioc);
3589 ioc->start_scan_failed = ioc_status;
3590 ioc->start_scan = 0;
3594 complete(&ioc->port_enable_cmds.done);
3600 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3601 * @ioc: per adapter object
3602 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3604 * Returns 0 for success, non-zero for failure.
3607 _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3609 Mpi2PortEnableRequest_t *mpi_request;
3610 Mpi2PortEnableReply_t *mpi_reply;
3611 unsigned long timeleft;
3616 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3618 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3619 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3620 ioc->name, __func__);
3624 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3626 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3627 ioc->name, __func__);
3631 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3632 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3633 ioc->port_enable_cmds.smid = smid;
3634 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3635 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3637 init_completion(&ioc->port_enable_cmds.done);
3638 mpt2sas_base_put_smid_default(ioc, smid);
3639 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
3641 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
3642 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3643 ioc->name, __func__);
3644 _debug_dump_mf(mpi_request,
3645 sizeof(Mpi2PortEnableRequest_t)/4);
3646 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
3652 mpi_reply = ioc->port_enable_cmds.reply;
3654 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3655 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3656 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3657 ioc->name, __func__, ioc_status);
3662 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3663 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3664 "SUCCESS" : "FAILED"));
3669 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3670 * @ioc: per adapter object
3672 * Returns 0 for success, non-zero for failure.
3675 mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3677 Mpi2PortEnableRequest_t *mpi_request;
3680 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3682 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3683 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3684 ioc->name, __func__);
3688 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3690 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3691 ioc->name, __func__);
3695 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3696 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3697 ioc->port_enable_cmds.smid = smid;
3698 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3699 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3701 mpt2sas_base_put_smid_default(ioc, smid);
3706 * _base_determine_wait_on_discovery - desposition
3707 * @ioc: per adapter object
3709 * Decide whether to wait on discovery to complete. Used to either
3710 * locate boot device, or report volumes ahead of physical devices.
3712 * Returns 1 for wait, 0 for don't wait
3715 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3717 /* We wait for discovery to complete if IR firmware is loaded.
3718 * The sas topology events arrive before PD events, so we need time to
3719 * turn on the bit in ioc->pd_handles to indicate PD
3720 * Also, it maybe required to report Volumes ahead of physical
3721 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3723 if (ioc->ir_firmware)
3726 /* if no Bios, then we don't need to wait */
3727 if (!ioc->bios_pg3.BiosVersion)
3730 /* Bios is present, then we drop down here.
3732 * If there any entries in the Bios Page 2, then we wait
3733 * for discovery to complete.
3736 /* Current Boot Device */
3737 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3738 MPI2_BIOSPAGE2_FORM_MASK) ==
3739 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3740 /* Request Boot Device */
3741 (ioc->bios_pg2.ReqBootDeviceForm &
3742 MPI2_BIOSPAGE2_FORM_MASK) ==
3743 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3744 /* Alternate Request Boot Device */
3745 (ioc->bios_pg2.ReqAltBootDeviceForm &
3746 MPI2_BIOSPAGE2_FORM_MASK) ==
3747 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3755 * _base_unmask_events - turn on notification for this event
3756 * @ioc: per adapter object
3757 * @event: firmware event
3759 * The mask is stored in ioc->event_masks.
3762 _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
3769 desired_event = (1 << (event % 32));
3772 ioc->event_masks[0] &= ~desired_event;
3773 else if (event < 64)
3774 ioc->event_masks[1] &= ~desired_event;
3775 else if (event < 96)
3776 ioc->event_masks[2] &= ~desired_event;
3777 else if (event < 128)
3778 ioc->event_masks[3] &= ~desired_event;
3782 * _base_event_notification - send event notification
3783 * @ioc: per adapter object
3784 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3786 * Returns 0 for success, non-zero for failure.
3789 _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3791 Mpi2EventNotificationRequest_t *mpi_request;
3792 unsigned long timeleft;
3797 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3800 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
3801 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3802 ioc->name, __func__);
3806 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3808 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3809 ioc->name, __func__);
3812 ioc->base_cmds.status = MPT2_CMD_PENDING;
3813 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3814 ioc->base_cmds.smid = smid;
3815 memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
3816 mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
3817 mpi_request->VF_ID = 0; /* TODO */
3818 mpi_request->VP_ID = 0;
3819 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3820 mpi_request->EventMasks[i] =
3821 cpu_to_le32(ioc->event_masks[i]);
3822 init_completion(&ioc->base_cmds.done);
3823 mpt2sas_base_put_smid_default(ioc, smid);
3824 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
3825 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3826 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3827 ioc->name, __func__);
3828 _debug_dump_mf(mpi_request,
3829 sizeof(Mpi2EventNotificationRequest_t)/4);
3830 if (ioc->base_cmds.status & MPT2_CMD_RESET)
3835 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
3836 ioc->name, __func__));
3837 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3842 * mpt2sas_base_validate_event_type - validating event types
3843 * @ioc: per adapter object
3844 * @event: firmware event
3846 * This will turn on firmware event notification when application
3847 * ask for that event. We don't mask events that are already enabled.
3850 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
3853 u32 event_mask, desired_event;
3854 u8 send_update_to_fw;
3856 for (i = 0, send_update_to_fw = 0; i <
3857 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
3858 event_mask = ~event_type[i];
3860 for (j = 0; j < 32; j++) {
3861 if (!(event_mask & desired_event) &&
3862 (ioc->event_masks[i] & desired_event)) {
3863 ioc->event_masks[i] &= ~desired_event;
3864 send_update_to_fw = 1;
3866 desired_event = (desired_event << 1);
3870 if (!send_update_to_fw)
3873 mutex_lock(&ioc->base_cmds.mutex);
3874 _base_event_notification(ioc, CAN_SLEEP);
3875 mutex_unlock(&ioc->base_cmds.mutex);
3879 * _base_diag_reset - the "big hammer" start of day reset
3880 * @ioc: per adapter object
3881 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3883 * Returns 0 for success, non-zero for failure.
3886 _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3888 u32 host_diagnostic;
3893 printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
3894 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
3899 /* Write magic sequence to WriteSequence register
3900 * Loop until in diagnostic mode
3902 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
3903 "sequence\n", ioc->name));
3904 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3905 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
3906 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
3907 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
3908 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
3909 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
3910 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
3913 if (sleep_flag == CAN_SLEEP)
3921 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3922 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
3923 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3924 ioc->name, count, host_diagnostic));
3926 } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
3928 hcb_size = readl(&ioc->chip->HCBSize);
3930 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
3932 writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
3933 &ioc->chip->HostDiagnostic);
3935 /* don't access any registers for 50 milliseconds */
3938 /* 300 second max wait */
3939 for (count = 0; count < 3000000 ; count++) {
3941 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3943 if (host_diagnostic == 0xFFFFFFFF)
3945 if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
3949 if (sleep_flag == CAN_SLEEP)
3955 if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
3957 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
3958 "assuming the HCB Address points to good F/W\n",
3960 host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
3961 host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
3962 writel(host_diagnostic, &ioc->chip->HostDiagnostic);
3964 drsprintk(ioc, printk(MPT2SAS_INFO_FMT
3965 "re-enable the HCDW\n", ioc->name));
3966 writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
3967 &ioc->chip->HCBSize);
3970 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
3972 writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
3973 &ioc->chip->HostDiagnostic);
3975 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
3976 "diagnostic register\n", ioc->name));
3977 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3979 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
3980 "READY state\n", ioc->name));
3981 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
3984 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3985 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3989 printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
3993 printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
3998 * _base_make_ioc_ready - put controller in READY state
3999 * @ioc: per adapter object
4000 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4001 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4003 * Returns 0 for success, non-zero for failure.
4006 _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4007 enum reset_type type)
4012 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4015 if (ioc->pci_error_recovery)
4018 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4019 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
4020 ioc->name, __func__, ioc_state));
4022 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
4025 if (ioc_state & MPI2_DOORBELL_USED) {
4026 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
4027 "active!\n", ioc->name));
4028 goto issue_diag_reset;
4031 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
4032 mpt2sas_base_fault_info(ioc, ioc_state &
4033 MPI2_DOORBELL_DATA_MASK);
4034 goto issue_diag_reset;
4037 if (type == FORCE_BIG_HAMMER)
4038 goto issue_diag_reset;
4040 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
4041 if (!(_base_send_ioc_reset(ioc,
4042 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
4043 ioc->ioc_reset_count++;
4048 rc = _base_diag_reset(ioc, CAN_SLEEP);
4049 ioc->ioc_reset_count++;
4054 * _base_make_ioc_operational - put controller in OPERATIONAL state
4055 * @ioc: per adapter object
4056 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4058 * Returns 0 for success, non-zero for failure.
4061 _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4064 unsigned long flags;
4067 struct _tr_list *delayed_tr, *delayed_tr_next;
4069 struct adapter_reply_queue *reply_q;
4070 long reply_post_free;
4071 u32 reply_post_free_sz;
4073 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4076 /* clean the delayed target reset list */
4077 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4078 &ioc->delayed_tr_list, list) {
4079 list_del(&delayed_tr->list);
4083 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4084 &ioc->delayed_tr_volume_list, list) {
4085 list_del(&delayed_tr->list);
4089 /* initialize the scsi lookup free list */
4090 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4091 INIT_LIST_HEAD(&ioc->free_list);
4093 for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
4094 INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
4095 ioc->scsi_lookup[i].cb_idx = 0xFF;
4096 ioc->scsi_lookup[i].smid = smid;
4097 ioc->scsi_lookup[i].scmd = NULL;
4098 ioc->scsi_lookup[i].direct_io = 0;
4099 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4103 /* hi-priority queue */
4104 INIT_LIST_HEAD(&ioc->hpr_free_list);
4105 smid = ioc->hi_priority_smid;
4106 for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
4107 ioc->hpr_lookup[i].cb_idx = 0xFF;
4108 ioc->hpr_lookup[i].smid = smid;
4109 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
4110 &ioc->hpr_free_list);
4113 /* internal queue */
4114 INIT_LIST_HEAD(&ioc->internal_free_list);
4115 smid = ioc->internal_smid;
4116 for (i = 0; i < ioc->internal_depth; i++, smid++) {
4117 ioc->internal_lookup[i].cb_idx = 0xFF;
4118 ioc->internal_lookup[i].smid = smid;
4119 list_add_tail(&ioc->internal_lookup[i].tracker_list,
4120 &ioc->internal_free_list);
4124 INIT_LIST_HEAD(&ioc->free_chain_list);
4125 for (i = 0; i < ioc->chain_depth; i++)
4126 list_add_tail(&ioc->chain_lookup[i].tracker_list,
4127 &ioc->free_chain_list);
4129 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4131 /* initialize Reply Free Queue */
4132 for (i = 0, reply_address = (u32)ioc->reply_dma ;
4133 i < ioc->reply_free_queue_depth ; i++, reply_address +=
4135 ioc->reply_free[i] = cpu_to_le32(reply_address);
4137 /* initialize reply queues */
4138 if (ioc->is_driver_loading)
4139 _base_assign_reply_queues(ioc);
4141 /* initialize Reply Post Free Queue */
4142 reply_post_free = (long)ioc->reply_post_free;
4143 reply_post_free_sz = ioc->reply_post_queue_depth *
4144 sizeof(Mpi2DefaultReplyDescriptor_t);
4145 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4146 reply_q->reply_post_host_index = 0;
4147 reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
4149 for (i = 0; i < ioc->reply_post_queue_depth; i++)
4150 reply_q->reply_post_free[i].Words =
4151 cpu_to_le64(ULLONG_MAX);
4152 if (!_base_is_controller_msix_enabled(ioc))
4153 goto skip_init_reply_post_free_queue;
4154 reply_post_free += reply_post_free_sz;
4156 skip_init_reply_post_free_queue:
4158 r = _base_send_ioc_init(ioc, sleep_flag);
4162 /* initialize reply free host index */
4163 ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
4164 writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
4166 /* initialize reply post host index */
4167 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4168 writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
4169 &ioc->chip->ReplyPostHostIndex);
4170 if (!_base_is_controller_msix_enabled(ioc))
4171 goto skip_init_reply_post_host_index;
4174 skip_init_reply_post_host_index:
4176 _base_unmask_interrupts(ioc);
4178 r = _base_event_notification(ioc, sleep_flag);
4182 if (sleep_flag == CAN_SLEEP)
4183 _base_static_config_pages(ioc);
4186 if (ioc->is_driver_loading) {
4187 if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier
4190 le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) &
4191 MFG_PAGE10_HIDE_SSDS_MASK);
4192 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
4193 ioc->mfg_pg10_hide_flag = hide_flag;
4195 ioc->wait_for_discovery_to_complete =
4196 _base_determine_wait_on_discovery(ioc);
4197 return r; /* scan_start and scan_finished support */
4199 r = _base_send_port_enable(ioc, sleep_flag);
4207 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4208 * @ioc: per adapter object
4213 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
4215 struct pci_dev *pdev = ioc->pdev;
4217 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4220 _base_mask_interrupts(ioc);
4221 ioc->shost_recovery = 1;
4222 _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4223 ioc->shost_recovery = 0;
4224 _base_free_irq(ioc);
4225 _base_disable_msix(ioc);
4229 pci_release_selected_regions(ioc->pdev, ioc->bars);
4230 pci_disable_pcie_error_reporting(pdev);
4231 pci_disable_device(pdev);
4236 * mpt2sas_base_attach - attach controller instance
4237 * @ioc: per adapter object
4239 * Returns 0 for success, non-zero for failure.
4242 mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4245 int cpu_id, last_cpu_id = 0;
4247 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4250 /* setup cpu_msix_table */
4251 ioc->cpu_count = num_online_cpus();
4252 for_each_online_cpu(cpu_id)
4253 last_cpu_id = cpu_id;
4254 ioc->cpu_msix_table_sz = last_cpu_id + 1;
4255 ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
4256 ioc->reply_queue_count = 1;
4257 if (!ioc->cpu_msix_table) {
4258 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
4259 "cpu_msix_table failed!!!\n", ioc->name));
4261 goto out_free_resources;
4264 if (ioc->is_warpdrive) {
4265 ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
4266 sizeof(resource_size_t *), GFP_KERNEL);
4267 if (!ioc->reply_post_host_index) {
4268 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
4269 "for cpu_msix_table failed!!!\n", ioc->name));
4271 goto out_free_resources;
4275 r = mpt2sas_base_map_resources(ioc);
4277 goto out_free_resources;
4279 if (ioc->is_warpdrive) {
4280 ioc->reply_post_host_index[0] =
4281 (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
4283 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
4284 ioc->reply_post_host_index[i] = (resource_size_t *)
4285 ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
4289 pci_set_drvdata(ioc->pdev, ioc->shost);
4290 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
4292 goto out_free_resources;
4294 r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4296 goto out_free_resources;
4298 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
4299 sizeof(struct mpt2sas_port_facts), GFP_KERNEL);
4302 goto out_free_resources;
4305 for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
4306 r = _base_get_port_facts(ioc, i, CAN_SLEEP);
4308 goto out_free_resources;
4311 r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
4313 goto out_free_resources;
4315 init_waitqueue_head(&ioc->reset_wq);
4316 /* allocate memory pd handle bitmask list */
4317 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
4318 if (ioc->facts.MaxDevHandle % 8)
4319 ioc->pd_handles_sz++;
4320 ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
4322 if (!ioc->pd_handles) {
4324 goto out_free_resources;
4326 ioc->blocking_handles = kzalloc(ioc->pd_handles_sz,
4328 if (!ioc->blocking_handles) {
4330 goto out_free_resources;
4332 ioc->fwfault_debug = mpt2sas_fwfault_debug;
4334 /* base internal command bits */
4335 mutex_init(&ioc->base_cmds.mutex);
4336 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4337 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4339 /* port_enable command bits */
4340 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4341 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4343 /* transport internal command bits */
4344 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4345 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
4346 mutex_init(&ioc->transport_cmds.mutex);
4348 /* scsih internal command bits */
4349 ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4350 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
4351 mutex_init(&ioc->scsih_cmds.mutex);
4353 /* task management internal command bits */
4354 ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4355 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4356 mutex_init(&ioc->tm_cmds.mutex);
4358 /* config page internal command bits */
4359 ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4360 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
4361 mutex_init(&ioc->config_cmds.mutex);
4363 /* ctl module internal command bits */
4364 ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4365 ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
4366 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
4367 mutex_init(&ioc->ctl_cmds.mutex);
4369 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4370 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4371 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
4372 !ioc->ctl_cmds.sense) {
4374 goto out_free_resources;
4377 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4378 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4379 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
4381 goto out_free_resources;
4384 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4385 ioc->event_masks[i] = -1;
4387 /* here we enable the events we care about */
4388 _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
4389 _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
4390 _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
4391 _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4392 _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
4393 _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
4394 _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
4395 _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
4396 _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
4397 _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
4398 r = _base_make_ioc_operational(ioc, CAN_SLEEP);
4400 goto out_free_resources;
4402 if (missing_delay[0] != -1 && missing_delay[1] != -1)
4403 _base_update_missing_delay(ioc, missing_delay[0],
4405 ioc->non_operational_loop = 0;
4411 ioc->remove_host = 1;
4412 mpt2sas_base_free_resources(ioc);
4413 _base_release_memory_pools(ioc);
4414 pci_set_drvdata(ioc->pdev, NULL);
4415 kfree(ioc->cpu_msix_table);
4416 if (ioc->is_warpdrive)
4417 kfree(ioc->reply_post_host_index);
4418 kfree(ioc->pd_handles);
4419 kfree(ioc->blocking_handles);
4420 kfree(ioc->tm_cmds.reply);
4421 kfree(ioc->transport_cmds.reply);
4422 kfree(ioc->scsih_cmds.reply);
4423 kfree(ioc->config_cmds.reply);
4424 kfree(ioc->base_cmds.reply);
4425 kfree(ioc->port_enable_cmds.reply);
4426 kfree(ioc->ctl_cmds.reply);
4427 kfree(ioc->ctl_cmds.sense);
4429 ioc->ctl_cmds.reply = NULL;
4430 ioc->base_cmds.reply = NULL;
4431 ioc->tm_cmds.reply = NULL;
4432 ioc->scsih_cmds.reply = NULL;
4433 ioc->transport_cmds.reply = NULL;
4434 ioc->config_cmds.reply = NULL;
4441 * mpt2sas_base_detach - remove controller instance
4442 * @ioc: per adapter object
4447 mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4450 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4453 mpt2sas_base_stop_watchdog(ioc);
4454 mpt2sas_base_free_resources(ioc);
4455 _base_release_memory_pools(ioc);
4456 pci_set_drvdata(ioc->pdev, NULL);
4457 kfree(ioc->cpu_msix_table);
4458 if (ioc->is_warpdrive)
4459 kfree(ioc->reply_post_host_index);
4460 kfree(ioc->pd_handles);
4461 kfree(ioc->blocking_handles);
4463 kfree(ioc->ctl_cmds.reply);
4464 kfree(ioc->ctl_cmds.sense);
4465 kfree(ioc->base_cmds.reply);
4466 kfree(ioc->port_enable_cmds.reply);
4467 kfree(ioc->tm_cmds.reply);
4468 kfree(ioc->transport_cmds.reply);
4469 kfree(ioc->scsih_cmds.reply);
4470 kfree(ioc->config_cmds.reply);
4474 * _base_reset_handler - reset callback handler (for base)
4475 * @ioc: per adapter object
4476 * @reset_phase: phase
4478 * The handler for doing any required cleanup or initialization.
4480 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4481 * MPT2_IOC_DONE_RESET
4486 _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4488 mpt2sas_scsih_reset_handler(ioc, reset_phase);
4489 mpt2sas_ctl_reset_handler(ioc, reset_phase);
4490 switch (reset_phase) {
4491 case MPT2_IOC_PRE_RESET:
4492 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4493 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
4495 case MPT2_IOC_AFTER_RESET:
4496 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4497 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
4498 if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
4499 ioc->transport_cmds.status |= MPT2_CMD_RESET;
4500 mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
4501 complete(&ioc->transport_cmds.done);
4503 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
4504 ioc->base_cmds.status |= MPT2_CMD_RESET;
4505 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4506 complete(&ioc->base_cmds.done);
4508 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4509 ioc->port_enable_failed = 1;
4510 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4511 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4512 if (ioc->is_driver_loading) {
4513 ioc->start_scan_failed =
4514 MPI2_IOCSTATUS_INTERNAL_ERROR;
4515 ioc->start_scan = 0;
4516 ioc->port_enable_cmds.status =
4519 complete(&ioc->port_enable_cmds.done);
4522 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4523 ioc->config_cmds.status |= MPT2_CMD_RESET;
4524 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
4525 ioc->config_cmds.smid = USHRT_MAX;
4526 complete(&ioc->config_cmds.done);
4529 case MPT2_IOC_DONE_RESET:
4530 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4531 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
4537 * _wait_for_commands_to_complete - reset controller
4538 * @ioc: Pointer to MPT_ADAPTER structure
4539 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4541 * This function waiting(3s) for all pending commands to complete
4542 * prior to putting controller in reset.
4545 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4548 unsigned long flags;
4551 ioc->pending_io_count = 0;
4552 if (sleep_flag != CAN_SLEEP)
4555 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4556 if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
4559 /* pending command count */
4560 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4561 for (i = 0; i < ioc->scsiio_depth; i++)
4562 if (ioc->scsi_lookup[i].cb_idx != 0xFF)
4563 ioc->pending_io_count++;
4564 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4566 if (!ioc->pending_io_count)
4569 /* wait for pending commands to complete */
4570 wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
4574 * mpt2sas_base_hard_reset_handler - reset controller
4575 * @ioc: Pointer to MPT_ADAPTER structure
4576 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4577 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4579 * Returns 0 for success, non-zero for failure.
4582 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4583 enum reset_type type)
4586 unsigned long flags;
4588 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
4591 if (ioc->pci_error_recovery) {
4592 printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
4593 ioc->name, __func__);
4598 if (mpt2sas_fwfault_debug)
4599 mpt2sas_halt_firmware(ioc);
4601 /* TODO - What we really should be doing is pulling
4602 * out all the code associated with NO_SLEEP; its never used.
4603 * That is legacy code from mpt fusion driver, ported over.
4604 * I will leave this BUG_ON here for now till its been resolved.
4606 BUG_ON(sleep_flag == NO_SLEEP);
4608 /* wait for an active reset in progress to complete */
4609 if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
4612 } while (ioc->shost_recovery == 1);
4613 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
4615 return ioc->ioc_reset_in_progress_status;
4618 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4619 ioc->shost_recovery = 1;
4620 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4622 _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
4623 _wait_for_commands_to_complete(ioc, sleep_flag);
4624 _base_mask_interrupts(ioc);
4625 r = _base_make_ioc_ready(ioc, sleep_flag, type);
4628 _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
4630 /* If this hard reset is called while port enable is active, then
4631 * there is no reason to call make_ioc_operational
4633 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4634 ioc->remove_host = 1;
4638 r = _base_make_ioc_operational(ioc, sleep_flag);
4640 _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
4642 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
4643 ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
4645 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4646 ioc->ioc_reset_in_progress_status = r;
4647 ioc->shost_recovery = 0;
4648 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4649 mutex_unlock(&ioc->reset_in_progress_mutex);
4652 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,