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-2013 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 mpt2sas_fwfault_debug;
84 MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
85 "and halt firmware - (default=0)");
87 static int disable_discovery = -1;
88 module_param(disable_discovery, int, 0);
89 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
92 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
96 _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
98 int ret = param_set_int(val, kp);
99 struct MPT2SAS_ADAPTER *ioc;
104 printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
105 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
106 ioc->fwfault_debug = mpt2sas_fwfault_debug;
110 module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug,
111 param_get_int, &mpt2sas_fwfault_debug, 0644);
114 * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc
115 * @arg: input argument, used to derive ioc
117 * Return 0 if controller is removed from pci subsystem.
118 * Return -1 for other case.
120 static int mpt2sas_remove_dead_ioc_func(void *arg)
122 struct MPT2SAS_ADAPTER *ioc = (struct MPT2SAS_ADAPTER *)arg;
123 struct pci_dev *pdev;
131 pci_stop_and_remove_bus_device_locked(pdev);
137 * _base_fault_reset_work - workq handling ioc fault conditions
138 * @work: input argument, used to derive ioc
144 _base_fault_reset_work(struct work_struct *work)
146 struct MPT2SAS_ADAPTER *ioc =
147 container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
151 struct task_struct *p;
153 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
154 if (ioc->shost_recovery || ioc->pci_error_recovery)
156 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
158 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
159 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) {
160 printk(MPT2SAS_INFO_FMT "%s : SAS host is non-operational !!!!\n",
161 ioc->name, __func__);
163 /* It may be possible that EEH recovery can resolve some of
164 * pci bus failure issues rather removing the dead ioc function
165 * by considering controller is in a non-operational state. So
166 * here priority is given to the EEH recovery. If it doesn't
167 * not resolve this issue, mpt2sas driver will consider this
168 * controller to non-operational state and remove the dead ioc
171 if (ioc->non_operational_loop++ < 5) {
172 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock,
178 * Call _scsih_flush_pending_cmds callback so that we flush all
179 * pending commands back to OS. This call is required to aovid
180 * deadlock at block layer. Dead IOC will fail to do diag reset,
181 * and this call is safe since dead ioc will never return any
182 * command back from HW.
184 ioc->schedule_dead_ioc_flush_running_cmds(ioc);
186 * Set remove_host flag early since kernel thread will
187 * take some time to execute.
189 ioc->remove_host = 1;
190 /*Remove the Dead Host */
191 p = kthread_run(mpt2sas_remove_dead_ioc_func, ioc,
192 "mpt2sas_dead_ioc_%d", ioc->id);
194 printk(MPT2SAS_ERR_FMT
195 "%s: Running mpt2sas_dead_ioc thread failed !!!!\n",
196 ioc->name, __func__);
198 printk(MPT2SAS_ERR_FMT
199 "%s: Running mpt2sas_dead_ioc thread success !!!!\n",
200 ioc->name, __func__);
203 return; /* don't rearm timer */
206 ioc->non_operational_loop = 0;
208 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
209 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
211 printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
212 __func__, (rc == 0) ? "success" : "failed");
213 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
214 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
215 mpt2sas_base_fault_info(ioc, doorbell &
216 MPI2_DOORBELL_DATA_MASK);
219 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
221 if (ioc->fault_reset_work_q)
222 queue_delayed_work(ioc->fault_reset_work_q,
223 &ioc->fault_reset_work,
224 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
225 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
229 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
230 * @ioc: per adapter object
236 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
240 if (ioc->fault_reset_work_q)
243 /* initialize fault polling */
244 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
245 snprintf(ioc->fault_reset_work_q_name,
246 sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
247 ioc->fault_reset_work_q =
248 create_singlethread_workqueue(ioc->fault_reset_work_q_name);
249 if (!ioc->fault_reset_work_q) {
250 printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
251 ioc->name, __func__, __LINE__);
254 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
255 if (ioc->fault_reset_work_q)
256 queue_delayed_work(ioc->fault_reset_work_q,
257 &ioc->fault_reset_work,
258 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
259 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
263 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
264 * @ioc: per adapter object
270 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
273 struct workqueue_struct *wq;
275 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
276 wq = ioc->fault_reset_work_q;
277 ioc->fault_reset_work_q = NULL;
278 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
280 if (!cancel_delayed_work_sync(&ioc->fault_reset_work))
282 destroy_workqueue(wq);
287 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
288 * @ioc: per adapter object
289 * @fault_code: fault code
294 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
296 printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
297 ioc->name, fault_code);
301 * mpt2sas_halt_firmware - halt's mpt controller firmware
302 * @ioc: per adapter object
304 * For debugging timeout related issues. Writing 0xCOFFEE00
305 * to the doorbell register will halt controller firmware. With
306 * the purpose to stop both driver and firmware, the enduser can
307 * obtain a ring buffer from controller UART.
310 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc)
314 if (!ioc->fwfault_debug)
319 doorbell = readl(&ioc->chip->Doorbell);
320 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
321 mpt2sas_base_fault_info(ioc , doorbell);
323 writel(0xC0FFEE00, &ioc->chip->Doorbell);
324 printk(MPT2SAS_ERR_FMT "Firmware is halted due to command "
325 "timeout\n", ioc->name);
328 panic("panic in %s\n", __func__);
331 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
333 * _base_sas_ioc_info - verbose translation of the ioc status
334 * @ioc: per adapter object
335 * @mpi_reply: reply mf payload returned from firmware
336 * @request_hdr: request mf
341 _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
342 MPI2RequestHeader_t *request_hdr)
344 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
348 char *func_str = NULL;
350 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
351 if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
352 request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
353 request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
356 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
359 switch (ioc_status) {
361 /****************************************************************************
362 * Common IOCStatus values for all replies
363 ****************************************************************************/
365 case MPI2_IOCSTATUS_INVALID_FUNCTION:
366 desc = "invalid function";
368 case MPI2_IOCSTATUS_BUSY:
371 case MPI2_IOCSTATUS_INVALID_SGL:
372 desc = "invalid sgl";
374 case MPI2_IOCSTATUS_INTERNAL_ERROR:
375 desc = "internal error";
377 case MPI2_IOCSTATUS_INVALID_VPID:
378 desc = "invalid vpid";
380 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
381 desc = "insufficient resources";
383 case MPI2_IOCSTATUS_INVALID_FIELD:
384 desc = "invalid field";
386 case MPI2_IOCSTATUS_INVALID_STATE:
387 desc = "invalid state";
389 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
390 desc = "op state not supported";
393 /****************************************************************************
394 * Config IOCStatus values
395 ****************************************************************************/
397 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
398 desc = "config invalid action";
400 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
401 desc = "config invalid type";
403 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
404 desc = "config invalid page";
406 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
407 desc = "config invalid data";
409 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
410 desc = "config no defaults";
412 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
413 desc = "config cant commit";
416 /****************************************************************************
418 ****************************************************************************/
420 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
421 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
422 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
423 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
424 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
425 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
426 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
427 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
428 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
429 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
430 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
431 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
434 /****************************************************************************
435 * For use by SCSI Initiator and SCSI Target end-to-end data protection
436 ****************************************************************************/
438 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
439 desc = "eedp guard error";
441 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
442 desc = "eedp ref tag error";
444 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
445 desc = "eedp app tag error";
448 /****************************************************************************
450 ****************************************************************************/
452 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
453 desc = "target invalid io index";
455 case MPI2_IOCSTATUS_TARGET_ABORTED:
456 desc = "target aborted";
458 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
459 desc = "target no conn retryable";
461 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
462 desc = "target no connection";
464 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
465 desc = "target xfer count mismatch";
467 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
468 desc = "target data offset error";
470 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
471 desc = "target too much write data";
473 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
474 desc = "target iu too short";
476 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
477 desc = "target ack nak timeout";
479 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
480 desc = "target nak received";
483 /****************************************************************************
484 * Serial Attached SCSI values
485 ****************************************************************************/
487 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
488 desc = "smp request failed";
490 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
491 desc = "smp data overrun";
494 /****************************************************************************
495 * Diagnostic Buffer Post / Diagnostic Release values
496 ****************************************************************************/
498 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
499 desc = "diagnostic released";
508 switch (request_hdr->Function) {
509 case MPI2_FUNCTION_CONFIG:
510 frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
511 func_str = "config_page";
513 case MPI2_FUNCTION_SCSI_TASK_MGMT:
514 frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
515 func_str = "task_mgmt";
517 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
518 frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
519 func_str = "sas_iounit_ctl";
521 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
522 frame_sz = sizeof(Mpi2SepRequest_t);
523 func_str = "enclosure";
525 case MPI2_FUNCTION_IOC_INIT:
526 frame_sz = sizeof(Mpi2IOCInitRequest_t);
527 func_str = "ioc_init";
529 case MPI2_FUNCTION_PORT_ENABLE:
530 frame_sz = sizeof(Mpi2PortEnableRequest_t);
531 func_str = "port_enable";
533 case MPI2_FUNCTION_SMP_PASSTHROUGH:
534 frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
535 func_str = "smp_passthru";
539 func_str = "unknown";
543 printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
544 " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
546 _debug_dump_mf(request_hdr, frame_sz/4);
550 * _base_display_event_data - verbose translation of firmware asyn events
551 * @ioc: per adapter object
552 * @mpi_reply: reply mf payload returned from firmware
557 _base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
558 Mpi2EventNotificationReply_t *mpi_reply)
563 if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
566 event = le16_to_cpu(mpi_reply->Event);
569 case MPI2_EVENT_LOG_DATA:
572 case MPI2_EVENT_STATE_CHANGE:
573 desc = "Status Change";
575 case MPI2_EVENT_HARD_RESET_RECEIVED:
576 desc = "Hard Reset Received";
578 case MPI2_EVENT_EVENT_CHANGE:
579 desc = "Event Change";
581 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
582 desc = "Device Status Change";
584 case MPI2_EVENT_IR_OPERATION_STATUS:
585 if (!ioc->hide_ir_msg)
586 desc = "IR Operation Status";
588 case MPI2_EVENT_SAS_DISCOVERY:
590 Mpi2EventDataSasDiscovery_t *event_data =
591 (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData;
592 printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name,
593 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
595 if (event_data->DiscoveryStatus)
596 printk("discovery_status(0x%08x)",
597 le32_to_cpu(event_data->DiscoveryStatus));
601 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
602 desc = "SAS Broadcast Primitive";
604 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
605 desc = "SAS Init Device Status Change";
607 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
608 desc = "SAS Init Table Overflow";
610 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
611 desc = "SAS Topology Change List";
613 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
614 desc = "SAS Enclosure Device Status Change";
616 case MPI2_EVENT_IR_VOLUME:
617 if (!ioc->hide_ir_msg)
620 case MPI2_EVENT_IR_PHYSICAL_DISK:
621 if (!ioc->hide_ir_msg)
622 desc = "IR Physical Disk";
624 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
625 if (!ioc->hide_ir_msg)
626 desc = "IR Configuration Change List";
628 case MPI2_EVENT_LOG_ENTRY_ADDED:
629 if (!ioc->hide_ir_msg)
630 desc = "Log Entry Added";
637 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
642 * _base_sas_log_info - verbose translation of firmware log info
643 * @ioc: per adapter object
644 * @log_info: log info
649 _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
660 union loginfo_type sas_loginfo;
661 char *originator_str = NULL;
663 sas_loginfo.loginfo = log_info;
664 if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
667 /* each nexus loss loginfo */
668 if (log_info == 0x31170000)
671 /* eat the loginfos associated with task aborts */
672 if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info ==
673 0x31140000 || log_info == 0x31130000))
676 switch (sas_loginfo.dw.originator) {
678 originator_str = "IOP";
681 originator_str = "PL";
684 if (!ioc->hide_ir_msg)
685 originator_str = "IR";
687 originator_str = "WarpDrive";
691 printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
692 "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
693 originator_str, sas_loginfo.dw.code,
694 sas_loginfo.dw.subcode);
698 * _base_display_reply_info -
699 * @ioc: per adapter object
700 * @smid: system request message index
701 * @msix_index: MSIX table index supplied by the OS
702 * @reply: reply message frame(lower 32bit addr)
707 _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
710 MPI2DefaultReply_t *mpi_reply;
713 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
714 if (unlikely(!mpi_reply)) {
715 printk(MPT2SAS_ERR_FMT "mpi_reply not valid at %s:%d/%s()!\n",
716 ioc->name, __FILE__, __LINE__, __func__);
719 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
720 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
721 if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
722 (ioc->logging_level & MPT_DEBUG_REPLY)) {
723 _base_sas_ioc_info(ioc , mpi_reply,
724 mpt2sas_base_get_msg_frame(ioc, smid));
727 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
728 _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
732 * mpt2sas_base_done - base internal command completion routine
733 * @ioc: per adapter object
734 * @smid: system request message index
735 * @msix_index: MSIX table index supplied by the OS
736 * @reply: reply message frame(lower 32bit addr)
738 * Return 1 meaning mf should be freed from _base_interrupt
739 * 0 means the mf is freed from this function.
742 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
745 MPI2DefaultReply_t *mpi_reply;
747 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
748 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
751 if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
754 ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
756 ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
757 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
759 ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
761 complete(&ioc->base_cmds.done);
766 * _base_async_event - main callback handler for firmware asyn events
767 * @ioc: per adapter object
768 * @msix_index: MSIX table index supplied by the OS
769 * @reply: reply message frame(lower 32bit addr)
774 _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
776 Mpi2EventNotificationReply_t *mpi_reply;
777 Mpi2EventAckRequest_t *ack_request;
780 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
783 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
785 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
786 _base_display_event_data(ioc, mpi_reply);
788 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
790 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
792 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
793 ioc->name, __func__);
797 ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
798 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
799 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
800 ack_request->Event = mpi_reply->Event;
801 ack_request->EventContext = mpi_reply->EventContext;
802 ack_request->VF_ID = 0; /* TODO */
803 ack_request->VP_ID = 0;
804 mpt2sas_base_put_smid_default(ioc, smid);
808 /* scsih callback handler */
809 mpt2sas_scsih_event_callback(ioc, msix_index, reply);
811 /* ctl callback handler */
812 mpt2sas_ctl_event_callback(ioc, msix_index, reply);
818 * _base_get_cb_idx - obtain the callback index
819 * @ioc: per adapter object
820 * @smid: system request message index
822 * Return callback index.
825 _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
830 if (smid < ioc->hi_priority_smid) {
832 cb_idx = ioc->scsi_lookup[i].cb_idx;
833 } else if (smid < ioc->internal_smid) {
834 i = smid - ioc->hi_priority_smid;
835 cb_idx = ioc->hpr_lookup[i].cb_idx;
836 } else if (smid <= ioc->hba_queue_depth) {
837 i = smid - ioc->internal_smid;
838 cb_idx = ioc->internal_lookup[i].cb_idx;
845 * _base_mask_interrupts - disable interrupts
846 * @ioc: per adapter object
848 * Disabling ResetIRQ, Reply and Doorbell Interrupts
853 _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
857 ioc->mask_interrupts = 1;
858 him_register = readl(&ioc->chip->HostInterruptMask);
859 him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
860 writel(him_register, &ioc->chip->HostInterruptMask);
861 readl(&ioc->chip->HostInterruptMask);
865 * _base_unmask_interrupts - enable interrupts
866 * @ioc: per adapter object
868 * Enabling only Reply Interrupts
873 _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
877 him_register = readl(&ioc->chip->HostInterruptMask);
878 him_register &= ~MPI2_HIM_RIM;
879 writel(him_register, &ioc->chip->HostInterruptMask);
880 ioc->mask_interrupts = 0;
883 union reply_descriptor {
892 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
893 * @irq: irq number (not used)
894 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
895 * @r: pt_regs pointer (not used)
897 * Return IRQ_HANDLE if processed, else IRQ_NONE.
900 _base_interrupt(int irq, void *bus_id)
902 struct adapter_reply_queue *reply_q = bus_id;
903 union reply_descriptor rd;
905 u8 request_desript_type;
909 u8 msix_index = reply_q->msix_index;
910 struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
911 Mpi2ReplyDescriptorsUnion_t *rpf;
914 if (ioc->mask_interrupts)
917 if (!atomic_add_unless(&reply_q->busy, 1, 1))
920 rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
921 request_desript_type = rpf->Default.ReplyFlags
922 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
923 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
924 atomic_dec(&reply_q->busy);
931 rd.word = le64_to_cpu(rpf->Words);
932 if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
935 smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
936 if (request_desript_type ==
937 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
939 (rpf->AddressReply.ReplyFrameAddress);
940 if (reply > ioc->reply_dma_max_address ||
941 reply < ioc->reply_dma_min_address)
943 } else if (request_desript_type ==
944 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
946 else if (request_desript_type ==
947 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
950 cb_idx = _base_get_cb_idx(ioc, smid);
951 if ((likely(cb_idx < MPT_MAX_CALLBACKS))
952 && (likely(mpt_callbacks[cb_idx] != NULL))) {
953 rc = mpt_callbacks[cb_idx](ioc, smid,
956 _base_display_reply_info(ioc, smid,
959 mpt2sas_base_free_smid(ioc, smid);
963 _base_async_event(ioc, msix_index, reply);
965 /* reply free queue handling */
967 ioc->reply_free_host_index =
968 (ioc->reply_free_host_index ==
969 (ioc->reply_free_queue_depth - 1)) ?
970 0 : ioc->reply_free_host_index + 1;
971 ioc->reply_free[ioc->reply_free_host_index] =
974 writel(ioc->reply_free_host_index,
975 &ioc->chip->ReplyFreeHostIndex);
980 rpf->Words = cpu_to_le64(ULLONG_MAX);
981 reply_q->reply_post_host_index =
982 (reply_q->reply_post_host_index ==
983 (ioc->reply_post_queue_depth - 1)) ? 0 :
984 reply_q->reply_post_host_index + 1;
985 request_desript_type =
986 reply_q->reply_post_free[reply_q->reply_post_host_index].
987 Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
989 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
991 if (!reply_q->reply_post_host_index)
992 rpf = reply_q->reply_post_free;
999 if (!completed_cmds) {
1000 atomic_dec(&reply_q->busy);
1004 if (ioc->is_warpdrive) {
1005 writel(reply_q->reply_post_host_index,
1006 ioc->reply_post_host_index[msix_index]);
1007 atomic_dec(&reply_q->busy);
1010 writel(reply_q->reply_post_host_index | (msix_index <<
1011 MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
1012 atomic_dec(&reply_q->busy);
1017 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1018 * @ioc: per adapter object
1022 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
1024 return (ioc->facts.IOCCapabilities &
1025 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
1029 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
1030 * @ioc: per adapter object
1031 * Context: ISR conext
1033 * Called when a Task Management request has completed. We want
1034 * to flush the other reply queues so all the outstanding IO has been
1035 * completed back to OS before we process the TM completetion.
1040 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1042 struct adapter_reply_queue *reply_q;
1044 /* If MSIX capability is turned off
1045 * then multi-queues are not enabled
1047 if (!_base_is_controller_msix_enabled(ioc))
1050 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
1051 if (ioc->shost_recovery)
1053 /* TMs are on msix_index == 0 */
1054 if (reply_q->msix_index == 0)
1056 _base_interrupt(reply_q->vector, (void *)reply_q);
1061 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
1062 * @cb_idx: callback index
1067 mpt2sas_base_release_callback_handler(u8 cb_idx)
1069 mpt_callbacks[cb_idx] = NULL;
1073 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1074 * @cb_func: callback function
1079 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
1083 for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
1084 if (mpt_callbacks[cb_idx] == NULL)
1087 mpt_callbacks[cb_idx] = cb_func;
1092 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1097 mpt2sas_base_initialize_callback_handler(void)
1101 for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
1102 mpt2sas_base_release_callback_handler(cb_idx);
1106 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1107 * @ioc: per adapter object
1108 * @paddr: virtual address for SGE
1110 * Create a zero length scatter gather entry to insure the IOCs hardware has
1111 * something to use if the target device goes brain dead and tries
1112 * to send data even when none is asked for.
1117 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
1119 u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
1120 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
1121 MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
1122 MPI2_SGE_FLAGS_SHIFT);
1123 ioc->base_add_sg_single(paddr, flags_length, -1);
1127 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1128 * @paddr: virtual address for SGE
1129 * @flags_length: SGE flags and data transfer length
1130 * @dma_addr: Physical address
1135 _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1137 Mpi2SGESimple32_t *sgel = paddr;
1139 flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
1140 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1141 sgel->FlagsLength = cpu_to_le32(flags_length);
1142 sgel->Address = cpu_to_le32(dma_addr);
1147 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1148 * @paddr: virtual address for SGE
1149 * @flags_length: SGE flags and data transfer length
1150 * @dma_addr: Physical address
1155 _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1157 Mpi2SGESimple64_t *sgel = paddr;
1159 flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
1160 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1161 sgel->FlagsLength = cpu_to_le32(flags_length);
1162 sgel->Address = cpu_to_le64(dma_addr);
1165 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1168 * _base_config_dma_addressing - set dma addressing
1169 * @ioc: per adapter object
1170 * @pdev: PCI device struct
1172 * Returns 0 for success, non-zero for failure.
1175 _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
1180 if (sizeof(dma_addr_t) > 4) {
1181 const uint64_t required_mask =
1182 dma_get_required_mask(&pdev->dev);
1183 if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
1184 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
1185 DMA_BIT_MASK(64))) {
1186 ioc->base_add_sg_single = &_base_add_sg_single_64;
1187 ioc->sge_size = sizeof(Mpi2SGESimple64_t);
1193 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1194 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
1195 ioc->base_add_sg_single = &_base_add_sg_single_32;
1196 ioc->sge_size = sizeof(Mpi2SGESimple32_t);
1203 printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1204 "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
1210 * _base_check_enable_msix - checks MSIX capabable.
1211 * @ioc: per adapter object
1213 * Check to see if card is capable of MSIX, and set number
1214 * of available msix vectors
1217 _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1220 u16 message_control;
1223 /* Check whether controller SAS2008 B0 controller,
1224 if it is SAS2008 B0 controller use IO-APIC instead of MSIX */
1225 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 &&
1226 ioc->pdev->revision == 0x01) {
1230 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1232 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
1233 "supported\n", ioc->name));
1237 /* get msix vector count */
1238 /* NUMA_IO not supported for older controllers */
1239 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
1240 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
1241 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
1242 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
1243 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
1244 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
1245 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
1246 ioc->msix_vector_count = 1;
1248 pci_read_config_word(ioc->pdev, base + 2, &message_control);
1249 ioc->msix_vector_count = (message_control & 0x3FF) + 1;
1251 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
1252 "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
1258 * _base_free_irq - free irq
1259 * @ioc: per adapter object
1261 * Freeing respective reply_queue from the list.
1264 _base_free_irq(struct MPT2SAS_ADAPTER *ioc)
1266 struct adapter_reply_queue *reply_q, *next;
1268 if (list_empty(&ioc->reply_queue_list))
1271 list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
1272 list_del(&reply_q->list);
1273 synchronize_irq(reply_q->vector);
1274 free_irq(reply_q->vector, reply_q);
1280 * _base_request_irq - request irq
1281 * @ioc: per adapter object
1282 * @index: msix index into vector table
1283 * @vector: irq vector
1285 * Inserting respective reply_queue into the list.
1288 _base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
1290 struct adapter_reply_queue *reply_q;
1293 reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
1295 printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
1296 ioc->name, (int)sizeof(struct adapter_reply_queue));
1300 reply_q->msix_index = index;
1301 reply_q->vector = vector;
1302 atomic_set(&reply_q->busy, 0);
1303 if (ioc->msix_enable)
1304 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
1305 MPT2SAS_DRIVER_NAME, ioc->id, index);
1307 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
1308 MPT2SAS_DRIVER_NAME, ioc->id);
1309 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1312 printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
1313 reply_q->name, vector);
1318 INIT_LIST_HEAD(&reply_q->list);
1319 list_add_tail(&reply_q->list, &ioc->reply_queue_list);
1324 * _base_assign_reply_queues - assigning msix index for each cpu
1325 * @ioc: per adapter object
1327 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1329 * It would nice if we could call irq_set_affinity, however it is not
1330 * an exported symbol
1333 _base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1335 unsigned int cpu, nr_cpus, nr_msix, index = 0;
1337 if (!_base_is_controller_msix_enabled(ioc))
1340 memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
1342 nr_cpus = num_online_cpus();
1343 nr_msix = ioc->reply_queue_count = min(ioc->reply_queue_count,
1344 ioc->facts.MaxMSIxVectors);
1348 cpu = cpumask_first(cpu_online_mask);
1351 unsigned int i, group = nr_cpus / nr_msix;
1353 if (index < nr_cpus % nr_msix)
1356 for (i = 0 ; i < group ; i++) {
1357 ioc->cpu_msix_table[cpu] = index;
1358 cpu = cpumask_next(cpu, cpu_online_mask);
1363 } while (cpu < nr_cpus);
1367 * _base_disable_msix - disables msix
1368 * @ioc: per adapter object
1372 _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
1374 if (ioc->msix_enable) {
1375 pci_disable_msix(ioc->pdev);
1376 ioc->msix_enable = 0;
1381 * _base_enable_msix - enables msix, failback to io_apic
1382 * @ioc: per adapter object
1386 _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1388 struct msix_entry *entries, *a;
1393 if (msix_disable == -1 || msix_disable == 0)
1399 if (_base_check_enable_msix(ioc) != 0)
1402 ioc->reply_queue_count = min_t(int, ioc->cpu_count,
1403 ioc->msix_vector_count);
1405 entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
1408 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
1409 "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
1410 __LINE__, __func__));
1414 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
1417 r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
1419 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
1420 "failed (r=%d) !!!\n", ioc->name, r));
1425 ioc->msix_enable = 1;
1426 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
1427 r = _base_request_irq(ioc, i, a->vector);
1429 _base_free_irq(ioc);
1430 _base_disable_msix(ioc);
1439 /* failback to io_apic interrupt routing */
1442 r = _base_request_irq(ioc, 0, ioc->pdev->irq);
1448 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1449 * @ioc: per adapter object
1451 * Returns 0 for success, non-zero for failure.
1454 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1456 struct pci_dev *pdev = ioc->pdev;
1462 struct adapter_reply_queue *reply_q;
1464 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
1465 ioc->name, __func__));
1467 ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
1468 if (pci_enable_device_mem(pdev)) {
1469 printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
1470 "failed\n", ioc->name);
1476 if (pci_request_selected_regions(pdev, ioc->bars,
1477 MPT2SAS_DRIVER_NAME)) {
1478 printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
1479 "failed\n", ioc->name);
1485 /* AER (Advanced Error Reporting) hooks */
1486 pci_enable_pcie_error_reporting(pdev);
1488 pci_set_master(pdev);
1490 if (_base_config_dma_addressing(ioc, pdev) != 0) {
1491 printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
1492 ioc->name, pci_name(pdev));
1497 for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
1498 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1501 pio_chip = (u64)pci_resource_start(pdev, i);
1502 pio_sz = pci_resource_len(pdev, i);
1506 /* verify memory resource is valid before using */
1507 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
1508 ioc->chip_phys = pci_resource_start(pdev, i);
1509 chip_phys = (u64)ioc->chip_phys;
1510 memap_sz = pci_resource_len(pdev, i);
1511 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1512 if (ioc->chip == NULL) {
1513 printk(MPT2SAS_ERR_FMT "unable to map "
1514 "adapter memory!\n", ioc->name);
1522 _base_mask_interrupts(ioc);
1523 r = _base_enable_msix(ioc);
1527 list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
1528 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
1529 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
1530 "IO-APIC enabled"), reply_q->vector);
1532 printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1533 ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
1534 printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
1535 ioc->name, (unsigned long long)pio_chip, pio_sz);
1537 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1538 pci_save_state(pdev);
1546 pci_release_selected_regions(ioc->pdev, ioc->bars);
1547 pci_disable_pcie_error_reporting(pdev);
1548 pci_disable_device(pdev);
1553 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1554 * @ioc: per adapter object
1555 * @smid: system request message index(smid zero is invalid)
1557 * Returns virt pointer to message frame.
1560 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1562 return (void *)(ioc->request + (smid * ioc->request_sz));
1566 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1567 * @ioc: per adapter object
1568 * @smid: system request message index
1570 * Returns virt pointer to sense buffer.
1573 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1575 return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1579 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1580 * @ioc: per adapter object
1581 * @smid: system request message index
1583 * Returns phys pointer to the low 32bit address of the sense buffer.
1586 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1588 return cpu_to_le32(ioc->sense_dma +
1589 ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1593 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1594 * @ioc: per adapter object
1595 * @phys_addr: lower 32 physical addr of the reply
1597 * Converts 32bit lower physical addr into a virt address.
1600 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
1604 return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
1608 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1609 * @ioc: per adapter object
1610 * @cb_idx: callback index
1612 * Returns smid (zero is invalid)
1615 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1617 unsigned long flags;
1618 struct request_tracker *request;
1621 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1622 if (list_empty(&ioc->internal_free_list)) {
1623 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1624 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1625 ioc->name, __func__);
1629 request = list_entry(ioc->internal_free_list.next,
1630 struct request_tracker, tracker_list);
1631 request->cb_idx = cb_idx;
1632 smid = request->smid;
1633 list_del(&request->tracker_list);
1634 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1639 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1640 * @ioc: per adapter object
1641 * @cb_idx: callback index
1642 * @scmd: pointer to scsi command object
1644 * Returns smid (zero is invalid)
1647 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1648 struct scsi_cmnd *scmd)
1650 unsigned long flags;
1651 struct scsiio_tracker *request;
1654 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1655 if (list_empty(&ioc->free_list)) {
1656 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1657 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1658 ioc->name, __func__);
1662 request = list_entry(ioc->free_list.next,
1663 struct scsiio_tracker, tracker_list);
1664 request->scmd = scmd;
1665 request->cb_idx = cb_idx;
1666 smid = request->smid;
1667 list_del(&request->tracker_list);
1668 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1673 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1674 * @ioc: per adapter object
1675 * @cb_idx: callback index
1677 * Returns smid (zero is invalid)
1680 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1682 unsigned long flags;
1683 struct request_tracker *request;
1686 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1687 if (list_empty(&ioc->hpr_free_list)) {
1688 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1692 request = list_entry(ioc->hpr_free_list.next,
1693 struct request_tracker, tracker_list);
1694 request->cb_idx = cb_idx;
1695 smid = request->smid;
1696 list_del(&request->tracker_list);
1697 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1703 * mpt2sas_base_free_smid - put smid back on free_list
1704 * @ioc: per adapter object
1705 * @smid: system request message index
1710 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1712 unsigned long flags;
1714 struct chain_tracker *chain_req, *next;
1716 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1717 if (smid < ioc->hi_priority_smid) {
1720 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
1721 list_for_each_entry_safe(chain_req, next,
1722 &ioc->scsi_lookup[i].chain_list, tracker_list) {
1723 list_del_init(&chain_req->tracker_list);
1724 list_add(&chain_req->tracker_list,
1725 &ioc->free_chain_list);
1728 ioc->scsi_lookup[i].cb_idx = 0xFF;
1729 ioc->scsi_lookup[i].scmd = NULL;
1730 ioc->scsi_lookup[i].direct_io = 0;
1731 list_add(&ioc->scsi_lookup[i].tracker_list,
1733 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1736 * See _wait_for_commands_to_complete() call with regards
1739 if (ioc->shost_recovery && ioc->pending_io_count) {
1740 if (ioc->pending_io_count == 1)
1741 wake_up(&ioc->reset_wq);
1742 ioc->pending_io_count--;
1745 } else if (smid < ioc->internal_smid) {
1747 i = smid - ioc->hi_priority_smid;
1748 ioc->hpr_lookup[i].cb_idx = 0xFF;
1749 list_add(&ioc->hpr_lookup[i].tracker_list,
1750 &ioc->hpr_free_list);
1751 } else if (smid <= ioc->hba_queue_depth) {
1752 /* internal queue */
1753 i = smid - ioc->internal_smid;
1754 ioc->internal_lookup[i].cb_idx = 0xFF;
1755 list_add(&ioc->internal_lookup[i].tracker_list,
1756 &ioc->internal_free_list);
1758 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1762 * _base_writeq - 64 bit write to MMIO
1763 * @ioc: per adapter object
1765 * @addr: address in MMIO space
1766 * @writeq_lock: spin lock
1768 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1769 * care of 32 bit environment where its not quarenteed to send the entire word
1773 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1774 spinlock_t *writeq_lock)
1776 unsigned long flags;
1777 __u64 data_out = cpu_to_le64(b);
1779 spin_lock_irqsave(writeq_lock, flags);
1780 writel((u32)(data_out), addr);
1781 writel((u32)(data_out >> 32), (addr + 4));
1782 spin_unlock_irqrestore(writeq_lock, flags);
1785 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1786 spinlock_t *writeq_lock)
1788 writeq(cpu_to_le64(b), addr);
1793 _base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
1795 return ioc->cpu_msix_table[raw_smp_processor_id()];
1799 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1800 * @ioc: per adapter object
1801 * @smid: system request message index
1802 * @handle: device handle
1807 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
1809 Mpi2RequestDescriptorUnion_t descriptor;
1810 u64 *request = (u64 *)&descriptor;
1813 descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
1814 descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc);
1815 descriptor.SCSIIO.SMID = cpu_to_le16(smid);
1816 descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
1817 descriptor.SCSIIO.LMID = 0;
1818 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1819 &ioc->scsi_lookup_lock);
1824 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1825 * @ioc: per adapter object
1826 * @smid: system request message index
1831 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1833 Mpi2RequestDescriptorUnion_t descriptor;
1834 u64 *request = (u64 *)&descriptor;
1836 descriptor.HighPriority.RequestFlags =
1837 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
1838 descriptor.HighPriority.MSIxIndex = 0;
1839 descriptor.HighPriority.SMID = cpu_to_le16(smid);
1840 descriptor.HighPriority.LMID = 0;
1841 descriptor.HighPriority.Reserved1 = 0;
1842 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1843 &ioc->scsi_lookup_lock);
1847 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1848 * @ioc: per adapter object
1849 * @smid: system request message index
1854 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1856 Mpi2RequestDescriptorUnion_t descriptor;
1857 u64 *request = (u64 *)&descriptor;
1859 descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1860 descriptor.Default.MSIxIndex = _base_get_msix_index(ioc);
1861 descriptor.Default.SMID = cpu_to_le16(smid);
1862 descriptor.Default.LMID = 0;
1863 descriptor.Default.DescriptorTypeDependent = 0;
1864 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1865 &ioc->scsi_lookup_lock);
1869 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1870 * @ioc: per adapter object
1871 * @smid: system request message index
1872 * @io_index: value used to track the IO
1877 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1880 Mpi2RequestDescriptorUnion_t descriptor;
1881 u64 *request = (u64 *)&descriptor;
1883 descriptor.SCSITarget.RequestFlags =
1884 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
1885 descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc);
1886 descriptor.SCSITarget.SMID = cpu_to_le16(smid);
1887 descriptor.SCSITarget.LMID = 0;
1888 descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
1889 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1890 &ioc->scsi_lookup_lock);
1894 * _base_display_dell_branding - Disply branding string
1895 * @ioc: per adapter object
1900 _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1902 char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
1904 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
1907 memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
1908 switch (ioc->pdev->subsystem_device) {
1909 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
1910 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
1911 MPT2SAS_DELL_BRANDING_SIZE - 1);
1913 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
1914 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
1915 MPT2SAS_DELL_BRANDING_SIZE - 1);
1917 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
1918 strncpy(dell_branding,
1919 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
1920 MPT2SAS_DELL_BRANDING_SIZE - 1);
1922 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
1923 strncpy(dell_branding,
1924 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
1925 MPT2SAS_DELL_BRANDING_SIZE - 1);
1927 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
1928 strncpy(dell_branding,
1929 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
1930 MPT2SAS_DELL_BRANDING_SIZE - 1);
1932 case MPT2SAS_DELL_PERC_H200_SSDID:
1933 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
1934 MPT2SAS_DELL_BRANDING_SIZE - 1);
1936 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
1937 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
1938 MPT2SAS_DELL_BRANDING_SIZE - 1);
1941 sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
1945 printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
1946 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
1947 ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
1948 ioc->pdev->subsystem_device);
1952 * _base_display_intel_branding - Display branding string
1953 * @ioc: per adapter object
1958 _base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
1960 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1963 switch (ioc->pdev->device) {
1964 case MPI2_MFGPAGE_DEVID_SAS2008:
1965 switch (ioc->pdev->subsystem_device) {
1966 case MPT2SAS_INTEL_RMS2LL080_SSDID:
1967 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1968 MPT2SAS_INTEL_RMS2LL080_BRANDING);
1970 case MPT2SAS_INTEL_RMS2LL040_SSDID:
1971 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1972 MPT2SAS_INTEL_RMS2LL040_BRANDING);
1974 case MPT2SAS_INTEL_SSD910_SSDID:
1975 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1976 MPT2SAS_INTEL_SSD910_BRANDING);
1981 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1982 switch (ioc->pdev->subsystem_device) {
1983 case MPT2SAS_INTEL_RS25GB008_SSDID:
1984 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1985 MPT2SAS_INTEL_RS25GB008_BRANDING);
1987 case MPT2SAS_INTEL_RMS25JB080_SSDID:
1988 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1989 MPT2SAS_INTEL_RMS25JB080_BRANDING);
1991 case MPT2SAS_INTEL_RMS25JB040_SSDID:
1992 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1993 MPT2SAS_INTEL_RMS25JB040_BRANDING);
1995 case MPT2SAS_INTEL_RMS25KB080_SSDID:
1996 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1997 MPT2SAS_INTEL_RMS25KB080_BRANDING);
1999 case MPT2SAS_INTEL_RMS25KB040_SSDID:
2000 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2001 MPT2SAS_INTEL_RMS25KB040_BRANDING);
2003 case MPT2SAS_INTEL_RMS25LB040_SSDID:
2004 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2005 MPT2SAS_INTEL_RMS25LB040_BRANDING);
2007 case MPT2SAS_INTEL_RMS25LB080_SSDID:
2008 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2009 MPT2SAS_INTEL_RMS25LB080_BRANDING);
2020 * _base_display_hp_branding - Display branding string
2021 * @ioc: per adapter object
2026 _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
2028 if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
2031 switch (ioc->pdev->device) {
2032 case MPI2_MFGPAGE_DEVID_SAS2004:
2033 switch (ioc->pdev->subsystem_device) {
2034 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
2035 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2036 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
2041 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2042 switch (ioc->pdev->subsystem_device) {
2043 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
2044 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2045 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
2047 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
2048 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2049 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
2051 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
2052 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2053 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
2055 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
2056 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2057 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
2068 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2069 * @ioc: per adapter object
2074 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
2078 u32 iounit_pg1_flags;
2081 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2082 strncpy(desc, ioc->manu_pg0.ChipName, 16);
2083 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
2084 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2086 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2087 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2088 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2089 ioc->facts.FWVersion.Word & 0x000000FF,
2090 ioc->pdev->revision,
2091 (bios_version & 0xFF000000) >> 24,
2092 (bios_version & 0x00FF0000) >> 16,
2093 (bios_version & 0x0000FF00) >> 8,
2094 bios_version & 0x000000FF);
2096 _base_display_dell_branding(ioc);
2097 _base_display_intel_branding(ioc);
2098 _base_display_hp_branding(ioc);
2100 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
2102 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
2103 printk("Initiator");
2107 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
2108 printk("%sTarget", i ? "," : "");
2114 printk("Capabilities=(");
2116 if (!ioc->hide_ir_msg) {
2117 if (ioc->facts.IOCCapabilities &
2118 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2124 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
2125 printk("%sTLR", i ? "," : "");
2129 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
2130 printk("%sMulticast", i ? "," : "");
2134 if (ioc->facts.IOCCapabilities &
2135 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
2136 printk("%sBIDI Target", i ? "," : "");
2140 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
2141 printk("%sEEDP", i ? "," : "");
2145 if (ioc->facts.IOCCapabilities &
2146 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
2147 printk("%sSnapshot Buffer", i ? "," : "");
2151 if (ioc->facts.IOCCapabilities &
2152 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
2153 printk("%sDiag Trace Buffer", i ? "," : "");
2157 if (ioc->facts.IOCCapabilities &
2158 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
2159 printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
2163 if (ioc->facts.IOCCapabilities &
2164 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
2165 printk("%sTask Set Full", i ? "," : "");
2169 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2170 if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
2171 printk("%sNCQ", i ? "," : "");
2179 * mpt2sas_base_update_missing_delay - change the missing delay timers
2180 * @ioc: per adapter object
2181 * @device_missing_delay: amount of time till device is reported missing
2182 * @io_missing_delay: interval IO is returned when there is a missing device
2186 * Passed on the command line, this function will modify the device missing
2187 * delay, as well as the io missing delay. This should be called at driver
2191 mpt2sas_base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
2192 u16 device_missing_delay, u8 io_missing_delay)
2194 u16 dmd, dmd_new, dmd_orignal;
2195 u8 io_missing_delay_original;
2197 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
2198 Mpi2ConfigReply_t mpi_reply;
2202 mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
2206 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
2207 sizeof(Mpi2SasIOUnit1PhyData_t));
2208 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
2209 if (!sas_iounit_pg1) {
2210 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2211 ioc->name, __FILE__, __LINE__, __func__);
2214 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
2215 sas_iounit_pg1, sz))) {
2216 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2217 ioc->name, __FILE__, __LINE__, __func__);
2220 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2221 MPI2_IOCSTATUS_MASK;
2222 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2223 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2224 ioc->name, __FILE__, __LINE__, __func__);
2228 /* device missing delay */
2229 dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
2230 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2231 dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2233 dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2235 if (device_missing_delay > 0x7F) {
2236 dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
2237 device_missing_delay;
2239 dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
2241 dmd = device_missing_delay;
2242 sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
2244 /* io missing delay */
2245 io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
2246 sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
2248 if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
2250 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2252 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2255 dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2256 printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
2257 "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
2258 printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
2259 "new(%d)\n", ioc->name, io_missing_delay_original,
2261 ioc->device_missing_delay = dmd_new;
2262 ioc->io_missing_delay = io_missing_delay;
2266 kfree(sas_iounit_pg1);
2270 * _base_static_config_pages - static start of day config pages
2271 * @ioc: per adapter object
2276 _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
2278 Mpi2ConfigReply_t mpi_reply;
2279 u32 iounit_pg1_flags;
2281 mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
2282 if (ioc->ir_firmware)
2283 mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
2285 mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
2286 mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
2287 mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
2288 mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
2289 mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2290 _base_display_ioc_capabilities(ioc);
2293 * Enable task_set_full handling in iounit_pg1 when the
2294 * facts capabilities indicate that its supported.
2296 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2297 if ((ioc->facts.IOCCapabilities &
2298 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
2300 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2303 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2304 ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
2305 mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2310 * _base_release_memory_pools - release memory
2311 * @ioc: per adapter object
2313 * Free memory allocated from _base_allocate_memory_pools.
2318 _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
2322 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2326 pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
2327 ioc->request, ioc->request_dma);
2328 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
2329 ": free\n", ioc->name, ioc->request));
2330 ioc->request = NULL;
2334 pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
2335 if (ioc->sense_dma_pool)
2336 pci_pool_destroy(ioc->sense_dma_pool);
2337 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
2338 ": free\n", ioc->name, ioc->sense));
2343 pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
2344 if (ioc->reply_dma_pool)
2345 pci_pool_destroy(ioc->reply_dma_pool);
2346 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
2347 ": free\n", ioc->name, ioc->reply));
2351 if (ioc->reply_free) {
2352 pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
2353 ioc->reply_free_dma);
2354 if (ioc->reply_free_dma_pool)
2355 pci_pool_destroy(ioc->reply_free_dma_pool);
2356 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
2357 "(0x%p): free\n", ioc->name, ioc->reply_free));
2358 ioc->reply_free = NULL;
2361 if (ioc->reply_post_free) {
2362 pci_pool_free(ioc->reply_post_free_dma_pool,
2363 ioc->reply_post_free, ioc->reply_post_free_dma);
2364 if (ioc->reply_post_free_dma_pool)
2365 pci_pool_destroy(ioc->reply_post_free_dma_pool);
2366 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2367 "reply_post_free_pool(0x%p): free\n", ioc->name,
2368 ioc->reply_post_free));
2369 ioc->reply_post_free = NULL;
2372 if (ioc->config_page) {
2373 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2374 "config_page(0x%p): free\n", ioc->name,
2376 pci_free_consistent(ioc->pdev, ioc->config_page_sz,
2377 ioc->config_page, ioc->config_page_dma);
2380 if (ioc->scsi_lookup) {
2381 free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
2382 ioc->scsi_lookup = NULL;
2384 kfree(ioc->hpr_lookup);
2385 kfree(ioc->internal_lookup);
2386 if (ioc->chain_lookup) {
2387 for (i = 0; i < ioc->chain_depth; i++) {
2388 if (ioc->chain_lookup[i].chain_buffer)
2389 pci_pool_free(ioc->chain_dma_pool,
2390 ioc->chain_lookup[i].chain_buffer,
2391 ioc->chain_lookup[i].chain_buffer_dma);
2393 if (ioc->chain_dma_pool)
2394 pci_pool_destroy(ioc->chain_dma_pool);
2395 free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
2396 ioc->chain_lookup = NULL;
2402 * _base_allocate_memory_pools - allocate start of day memory pools
2403 * @ioc: per adapter object
2404 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2406 * Returns 0 success, anything else error
2409 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2411 struct mpt2sas_facts *facts;
2412 u16 max_sge_elements;
2413 u16 chains_needed_per_io;
2414 u32 sz, total_sz, reply_post_free_sz;
2416 u16 max_request_credit;
2419 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2423 facts = &ioc->facts;
2425 /* command line tunables for max sgl entries */
2426 if (max_sgl_entries != -1) {
2427 ioc->shost->sg_tablesize = (max_sgl_entries <
2428 MPT2SAS_SG_DEPTH) ? max_sgl_entries :
2431 ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
2434 /* command line tunables for max controller queue depth */
2435 if (max_queue_depth != -1 && max_queue_depth != 0) {
2436 max_request_credit = min_t(u16, max_queue_depth +
2437 ioc->hi_priority_depth + ioc->internal_depth,
2438 facts->RequestCredit);
2439 if (max_request_credit > MAX_HBA_QUEUE_DEPTH)
2440 max_request_credit = MAX_HBA_QUEUE_DEPTH;
2442 max_request_credit = min_t(u16, facts->RequestCredit,
2443 MAX_HBA_QUEUE_DEPTH);
2445 ioc->hba_queue_depth = max_request_credit;
2446 ioc->hi_priority_depth = facts->HighPriorityCredit;
2447 ioc->internal_depth = ioc->hi_priority_depth + 5;
2449 /* request frame size */
2450 ioc->request_sz = facts->IOCRequestFrameSize * 4;
2452 /* reply frame size */
2453 ioc->reply_sz = facts->ReplyFrameSize * 4;
2457 /* calculate number of sg elements left over in the 1st frame */
2458 max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
2459 sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
2460 ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
2462 /* now do the same for a chain buffer */
2463 max_sge_elements = ioc->request_sz - ioc->sge_size;
2464 ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
2466 ioc->chain_offset_value_for_main_message =
2467 ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
2468 (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
2471 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2473 chains_needed_per_io = ((ioc->shost->sg_tablesize -
2474 ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
2476 if (chains_needed_per_io > facts->MaxChainDepth) {
2477 chains_needed_per_io = facts->MaxChainDepth;
2478 ioc->shost->sg_tablesize = min_t(u16,
2479 ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
2480 * chains_needed_per_io), ioc->shost->sg_tablesize);
2482 ioc->chains_needed_per_io = chains_needed_per_io;
2484 /* reply free queue sizing - taking into account for 64 FW events */
2485 ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64;
2487 /* calculate reply descriptor post queue depth */
2488 ioc->reply_post_queue_depth = ioc->hba_queue_depth +
2489 ioc->reply_free_queue_depth + 1;
2490 /* align the reply post queue on the next 16 count boundary */
2491 if (ioc->reply_post_queue_depth % 16)
2492 ioc->reply_post_queue_depth += 16 -
2493 (ioc->reply_post_queue_depth % 16);
2496 if (ioc->reply_post_queue_depth >
2497 facts->MaxReplyDescriptorPostQueueDepth) {
2498 ioc->reply_post_queue_depth =
2499 facts->MaxReplyDescriptorPostQueueDepth -
2500 (facts->MaxReplyDescriptorPostQueueDepth % 16);
2501 ioc->hba_queue_depth =
2502 ((ioc->reply_post_queue_depth - 64) / 2) - 1;
2503 ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64;
2506 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
2507 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2508 "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
2509 ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
2510 ioc->chains_needed_per_io));
2512 ioc->scsiio_depth = ioc->hba_queue_depth -
2513 ioc->hi_priority_depth - ioc->internal_depth;
2515 /* set the scsi host can_queue depth
2516 * with some internal commands that could be outstanding
2518 ioc->shost->can_queue = ioc->scsiio_depth;
2519 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2520 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2522 /* contiguous pool for request and chains, 16 byte align, one extra "
2525 ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
2526 sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
2528 /* hi-priority queue */
2529 sz += (ioc->hi_priority_depth * ioc->request_sz);
2531 /* internal queue */
2532 sz += (ioc->internal_depth * ioc->request_sz);
2534 ioc->request_dma_sz = sz;
2535 ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
2536 if (!ioc->request) {
2537 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2538 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2539 "total(%d kB)\n", ioc->name, ioc->hba_queue_depth,
2540 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2541 if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
2544 ioc->hba_queue_depth = max_request_credit - retry_sz;
2545 goto retry_allocation;
2549 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2550 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2551 "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
2552 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2555 /* hi-priority queue */
2556 ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
2558 ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
2561 /* internal queue */
2562 ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
2564 ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
2568 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
2569 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2570 ioc->request, ioc->hba_queue_depth, ioc->request_sz,
2571 (ioc->hba_queue_depth * ioc->request_sz)/1024));
2572 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
2573 ioc->name, (unsigned long long) ioc->request_dma));
2576 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
2577 ioc->scsi_lookup_pages = get_order(sz);
2578 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
2579 GFP_KERNEL, ioc->scsi_lookup_pages);
2580 if (!ioc->scsi_lookup) {
2581 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
2582 "sz(%d)\n", ioc->name, (int)sz);
2586 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
2587 "depth(%d)\n", ioc->name, ioc->request,
2588 ioc->scsiio_depth));
2590 ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH);
2591 sz = ioc->chain_depth * sizeof(struct chain_tracker);
2592 ioc->chain_pages = get_order(sz);
2594 ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
2595 GFP_KERNEL, ioc->chain_pages);
2596 if (!ioc->chain_lookup) {
2597 printk(MPT2SAS_ERR_FMT "chain_lookup: get_free_pages failed, "
2598 "sz(%d)\n", ioc->name, (int)sz);
2601 ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
2602 ioc->request_sz, 16, 0);
2603 if (!ioc->chain_dma_pool) {
2604 printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
2605 "failed\n", ioc->name);
2608 for (i = 0; i < ioc->chain_depth; i++) {
2609 ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
2610 ioc->chain_dma_pool , GFP_KERNEL,
2611 &ioc->chain_lookup[i].chain_buffer_dma);
2612 if (!ioc->chain_lookup[i].chain_buffer) {
2613 ioc->chain_depth = i;
2616 total_sz += ioc->request_sz;
2619 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
2620 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2621 ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
2622 ioc->request_sz))/1024));
2624 /* initialize hi-priority queue smid's */
2625 ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
2626 sizeof(struct request_tracker), GFP_KERNEL);
2627 if (!ioc->hpr_lookup) {
2628 printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
2632 ioc->hi_priority_smid = ioc->scsiio_depth + 1;
2633 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
2634 "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
2635 ioc->hi_priority_depth, ioc->hi_priority_smid));
2637 /* initialize internal queue smid's */
2638 ioc->internal_lookup = kcalloc(ioc->internal_depth,
2639 sizeof(struct request_tracker), GFP_KERNEL);
2640 if (!ioc->internal_lookup) {
2641 printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
2645 ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
2646 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
2647 "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
2648 ioc->internal_depth, ioc->internal_smid));
2650 /* sense buffers, 4 byte align */
2651 sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
2652 ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
2654 if (!ioc->sense_dma_pool) {
2655 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
2659 ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
2662 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
2666 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
2667 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2668 "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
2669 SCSI_SENSE_BUFFERSIZE, sz/1024));
2670 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
2671 ioc->name, (unsigned long long)ioc->sense_dma));
2674 /* reply pool, 4 byte align */
2675 sz = ioc->reply_free_queue_depth * ioc->reply_sz;
2676 ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
2678 if (!ioc->reply_dma_pool) {
2679 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
2683 ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
2686 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
2690 ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
2691 ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
2692 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
2693 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
2694 ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
2695 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
2696 ioc->name, (unsigned long long)ioc->reply_dma));
2699 /* reply free queue, 16 byte align */
2700 sz = ioc->reply_free_queue_depth * 4;
2701 ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
2702 ioc->pdev, sz, 16, 0);
2703 if (!ioc->reply_free_dma_pool) {
2704 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
2705 "failed\n", ioc->name);
2708 ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
2709 &ioc->reply_free_dma);
2710 if (!ioc->reply_free) {
2711 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
2712 "failed\n", ioc->name);
2715 memset(ioc->reply_free, 0, sz);
2716 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
2717 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
2718 ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
2719 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
2720 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
2723 /* reply post queue, 16 byte align */
2724 reply_post_free_sz = ioc->reply_post_queue_depth *
2725 sizeof(Mpi2DefaultReplyDescriptor_t);
2726 if (_base_is_controller_msix_enabled(ioc))
2727 sz = reply_post_free_sz * ioc->reply_queue_count;
2729 sz = reply_post_free_sz;
2730 ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
2731 ioc->pdev, sz, 16, 0);
2732 if (!ioc->reply_post_free_dma_pool) {
2733 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
2734 "failed\n", ioc->name);
2737 ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
2738 GFP_KERNEL, &ioc->reply_post_free_dma);
2739 if (!ioc->reply_post_free) {
2740 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
2741 "failed\n", ioc->name);
2744 memset(ioc->reply_post_free, 0, sz);
2745 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
2746 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2747 ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
2749 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
2750 "(0x%llx)\n", ioc->name, (unsigned long long)
2751 ioc->reply_post_free_dma));
2754 ioc->config_page_sz = 512;
2755 ioc->config_page = pci_alloc_consistent(ioc->pdev,
2756 ioc->config_page_sz, &ioc->config_page_dma);
2757 if (!ioc->config_page) {
2758 printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
2759 "failed\n", ioc->name);
2762 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
2763 "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
2764 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
2765 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
2766 total_sz += ioc->config_page_sz;
2768 printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
2769 ioc->name, total_sz/1024);
2770 printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
2771 "Max Controller Queue Depth(%d)\n",
2772 ioc->name, ioc->shost->can_queue, facts->RequestCredit);
2773 printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
2774 ioc->name, ioc->shost->sg_tablesize);
2783 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2784 * @ioc: Pointer to MPT_ADAPTER structure
2785 * @cooked: Request raw or cooked IOC state
2787 * Returns all IOC Doorbell register bits if cooked==0, else just the
2788 * Doorbell bits in MPI_IOC_STATE_MASK.
2791 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
2795 s = readl(&ioc->chip->Doorbell);
2796 sc = s & MPI2_IOC_STATE_MASK;
2797 return cooked ? sc : s;
2801 * _base_wait_on_iocstate - waiting on a particular ioc state
2802 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2803 * @timeout: timeout in second
2804 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2806 * Returns 0 for success, non-zero for failure.
2809 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
2816 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2818 current_state = mpt2sas_base_get_iocstate(ioc, 1);
2819 if (current_state == ioc_state)
2821 if (count && current_state == MPI2_IOC_STATE_FAULT)
2823 if (sleep_flag == CAN_SLEEP)
2830 return current_state;
2834 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2835 * a write to the doorbell)
2836 * @ioc: per adapter object
2837 * @timeout: timeout in second
2838 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2840 * Returns 0 for success, non-zero for failure.
2842 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2845 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
2852 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2854 int_status = readl(&ioc->chip->HostInterruptStatus);
2855 if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2856 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2857 "successful count(%d), timeout(%d)\n", ioc->name,
2858 __func__, count, timeout));
2861 if (sleep_flag == CAN_SLEEP)
2868 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2869 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2874 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2875 * @ioc: per adapter object
2876 * @timeout: timeout in second
2877 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2879 * Returns 0 for success, non-zero for failure.
2881 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2885 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
2893 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2895 int_status = readl(&ioc->chip->HostInterruptStatus);
2896 if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
2897 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2898 "successful count(%d), timeout(%d)\n", ioc->name,
2899 __func__, count, timeout));
2901 } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2902 doorbell = readl(&ioc->chip->Doorbell);
2903 if ((doorbell & MPI2_IOC_STATE_MASK) ==
2904 MPI2_IOC_STATE_FAULT) {
2905 mpt2sas_base_fault_info(ioc , doorbell);
2908 } else if (int_status == 0xFFFFFFFF)
2911 if (sleep_flag == CAN_SLEEP)
2919 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2920 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2925 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2926 * @ioc: per adapter object
2927 * @timeout: timeout in second
2928 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2930 * Returns 0 for success, non-zero for failure.
2934 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
2941 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2943 doorbell_reg = readl(&ioc->chip->Doorbell);
2944 if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
2945 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2946 "successful count(%d), timeout(%d)\n", ioc->name,
2947 __func__, count, timeout));
2950 if (sleep_flag == CAN_SLEEP)
2957 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2958 "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
2963 * _base_send_ioc_reset - send doorbell reset
2964 * @ioc: per adapter object
2965 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2966 * @timeout: timeout in second
2967 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2969 * Returns 0 for success, non-zero for failure.
2972 _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
2978 if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
2979 printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
2980 ioc->name, __func__);
2984 if (!(ioc->facts.IOCCapabilities &
2985 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
2988 printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
2990 writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
2991 &ioc->chip->Doorbell);
2992 if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
2996 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
2997 timeout, sleep_flag);
2999 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3000 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3005 printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
3006 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
3011 * _base_handshake_req_reply_wait - send request thru doorbell interface
3012 * @ioc: per adapter object
3013 * @request_bytes: request length
3014 * @request: pointer having request payload
3015 * @reply_bytes: reply length
3016 * @reply: pointer to reply payload
3017 * @timeout: timeout in second
3018 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3020 * Returns 0 for success, non-zero for failure.
3023 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
3024 u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
3026 MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
3032 /* make sure doorbell is not in use */
3033 if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
3034 printk(MPT2SAS_ERR_FMT "doorbell is in use "
3035 " (line=%d)\n", ioc->name, __LINE__);
3039 /* clear pending doorbell interrupts from previous state changes */
3040 if (readl(&ioc->chip->HostInterruptStatus) &
3041 MPI2_HIS_IOC2SYS_DB_STATUS)
3042 writel(0, &ioc->chip->HostInterruptStatus);
3044 /* send message to ioc */
3045 writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
3046 ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
3047 &ioc->chip->Doorbell);
3049 if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
3050 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3051 "int failed (line=%d)\n", ioc->name, __LINE__);
3054 writel(0, &ioc->chip->HostInterruptStatus);
3056 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
3057 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3058 "ack failed (line=%d)\n", ioc->name, __LINE__);
3062 /* send message 32-bits at a time */
3063 for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
3064 writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
3065 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
3070 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3071 "sending request failed (line=%d)\n", ioc->name, __LINE__);
3075 /* now wait for the reply */
3076 if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
3077 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3078 "int failed (line=%d)\n", ioc->name, __LINE__);
3082 /* read the first two 16-bits, it gives the total length of the reply */
3083 reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3084 & MPI2_DOORBELL_DATA_MASK);
3085 writel(0, &ioc->chip->HostInterruptStatus);
3086 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3087 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3088 "int failed (line=%d)\n", ioc->name, __LINE__);
3091 reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3092 & MPI2_DOORBELL_DATA_MASK);
3093 writel(0, &ioc->chip->HostInterruptStatus);
3095 for (i = 2; i < default_reply->MsgLength * 2; i++) {
3096 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3097 printk(MPT2SAS_ERR_FMT "doorbell "
3098 "handshake int failed (line=%d)\n", ioc->name,
3102 if (i >= reply_bytes/2) /* overflow case */
3103 dummy = readl(&ioc->chip->Doorbell);
3105 reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3106 & MPI2_DOORBELL_DATA_MASK);
3107 writel(0, &ioc->chip->HostInterruptStatus);
3110 _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
3111 if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
3112 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
3113 " (line=%d)\n", ioc->name, __LINE__));
3115 writel(0, &ioc->chip->HostInterruptStatus);
3117 if (ioc->logging_level & MPT_DEBUG_INIT) {
3118 mfp = (__le32 *)reply;
3119 printk(KERN_INFO "\toffset:data\n");
3120 for (i = 0; i < reply_bytes/4; i++)
3121 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3122 le32_to_cpu(mfp[i]));
3128 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3129 * @ioc: per adapter object
3130 * @mpi_reply: the reply payload from FW
3131 * @mpi_request: the request payload sent to FW
3133 * The SAS IO Unit Control Request message allows the host to perform low-level
3134 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3135 * to obtain the IOC assigned device handles for a device if it has other
3136 * identifying information about the device, in addition allows the host to
3137 * remove IOC resources associated with the device.
3139 * Returns 0 for success, non-zero for failure.
3142 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
3143 Mpi2SasIoUnitControlReply_t *mpi_reply,
3144 Mpi2SasIoUnitControlRequest_t *mpi_request)
3148 unsigned long timeleft;
3152 u16 wait_state_count;
3154 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3157 mutex_lock(&ioc->base_cmds.mutex);
3159 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3160 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3161 ioc->name, __func__);
3166 wait_state_count = 0;
3167 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3168 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3169 if (wait_state_count++ == 10) {
3170 printk(MPT2SAS_ERR_FMT
3171 "%s: failed due to ioc not operational\n",
3172 ioc->name, __func__);
3177 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3178 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3179 "operational state(count=%d)\n", ioc->name,
3180 __func__, wait_state_count);
3183 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3185 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3186 ioc->name, __func__);
3192 ioc->base_cmds.status = MPT2_CMD_PENDING;
3193 request = mpt2sas_base_get_msg_frame(ioc, smid);
3194 ioc->base_cmds.smid = smid;
3195 memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
3196 if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3197 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
3198 ioc->ioc_link_reset_in_progress = 1;
3199 init_completion(&ioc->base_cmds.done);
3200 mpt2sas_base_put_smid_default(ioc, smid);
3201 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3202 msecs_to_jiffies(10000));
3203 if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3204 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
3205 ioc->ioc_link_reset_in_progress)
3206 ioc->ioc_link_reset_in_progress = 0;
3207 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3208 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3209 ioc->name, __func__);
3210 _debug_dump_mf(mpi_request,
3211 sizeof(Mpi2SasIoUnitControlRequest_t)/4);
3212 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3214 goto issue_host_reset;
3216 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3217 memcpy(mpi_reply, ioc->base_cmds.reply,
3218 sizeof(Mpi2SasIoUnitControlReply_t));
3220 memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
3221 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3226 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3228 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3231 mutex_unlock(&ioc->base_cmds.mutex);
3237 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3238 * @ioc: per adapter object
3239 * @mpi_reply: the reply payload from FW
3240 * @mpi_request: the request payload sent to FW
3242 * The SCSI Enclosure Processor request message causes the IOC to
3243 * communicate with SES devices to control LED status signals.
3245 * Returns 0 for success, non-zero for failure.
3248 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
3249 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
3253 unsigned long timeleft;
3257 u16 wait_state_count;
3259 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3262 mutex_lock(&ioc->base_cmds.mutex);
3264 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3265 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3266 ioc->name, __func__);
3271 wait_state_count = 0;
3272 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3273 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3274 if (wait_state_count++ == 10) {
3275 printk(MPT2SAS_ERR_FMT
3276 "%s: failed due to ioc not operational\n",
3277 ioc->name, __func__);
3282 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3283 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3284 "operational state(count=%d)\n", ioc->name,
3285 __func__, wait_state_count);
3288 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3290 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3291 ioc->name, __func__);
3297 ioc->base_cmds.status = MPT2_CMD_PENDING;
3298 request = mpt2sas_base_get_msg_frame(ioc, smid);
3299 ioc->base_cmds.smid = smid;
3300 memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
3301 init_completion(&ioc->base_cmds.done);
3302 mpt2sas_base_put_smid_default(ioc, smid);
3303 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3304 msecs_to_jiffies(10000));
3305 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3306 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3307 ioc->name, __func__);
3308 _debug_dump_mf(mpi_request,
3309 sizeof(Mpi2SepRequest_t)/4);
3310 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3312 goto issue_host_reset;
3314 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3315 memcpy(mpi_reply, ioc->base_cmds.reply,
3316 sizeof(Mpi2SepReply_t));
3318 memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
3319 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3324 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3326 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3329 mutex_unlock(&ioc->base_cmds.mutex);
3334 * _base_get_port_facts - obtain port facts reply and save in ioc
3335 * @ioc: per adapter object
3336 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3338 * Returns 0 for success, non-zero for failure.
3341 _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
3343 Mpi2PortFactsRequest_t mpi_request;
3344 Mpi2PortFactsReply_t mpi_reply;
3345 struct mpt2sas_port_facts *pfacts;
3346 int mpi_reply_sz, mpi_request_sz, r;
3348 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3351 mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
3352 mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
3353 memset(&mpi_request, 0, mpi_request_sz);
3354 mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
3355 mpi_request.PortNumber = port;
3356 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3357 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3360 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3361 ioc->name, __func__, r);
3365 pfacts = &ioc->pfacts[port];
3366 memset(pfacts, 0, sizeof(struct mpt2sas_port_facts));
3367 pfacts->PortNumber = mpi_reply.PortNumber;
3368 pfacts->VP_ID = mpi_reply.VP_ID;
3369 pfacts->VF_ID = mpi_reply.VF_ID;
3370 pfacts->MaxPostedCmdBuffers =
3371 le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
3377 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3378 * @ioc: per adapter object
3379 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3381 * Returns 0 for success, non-zero for failure.
3384 _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3386 Mpi2IOCFactsRequest_t mpi_request;
3387 Mpi2IOCFactsReply_t mpi_reply;
3388 struct mpt2sas_facts *facts;
3389 int mpi_reply_sz, mpi_request_sz, r;
3391 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3394 mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
3395 mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
3396 memset(&mpi_request, 0, mpi_request_sz);
3397 mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
3398 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3399 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3402 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3403 ioc->name, __func__, r);
3407 facts = &ioc->facts;
3408 memset(facts, 0, sizeof(struct mpt2sas_facts));
3409 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
3410 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
3411 facts->VP_ID = mpi_reply.VP_ID;
3412 facts->VF_ID = mpi_reply.VF_ID;
3413 facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
3414 facts->MaxChainDepth = mpi_reply.MaxChainDepth;
3415 facts->WhoInit = mpi_reply.WhoInit;
3416 facts->NumberOfPorts = mpi_reply.NumberOfPorts;
3417 facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
3418 facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
3419 facts->MaxReplyDescriptorPostQueueDepth =
3420 le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
3421 facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
3422 facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
3423 if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
3424 ioc->ir_firmware = 1;
3425 facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
3426 facts->IOCRequestFrameSize =
3427 le16_to_cpu(mpi_reply.IOCRequestFrameSize);
3428 facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
3429 facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
3430 ioc->shost->max_id = -1;
3431 facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
3432 facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
3433 facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
3434 facts->HighPriorityCredit =
3435 le16_to_cpu(mpi_reply.HighPriorityCredit);
3436 facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
3437 facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
3439 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
3440 "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
3441 facts->MaxChainDepth));
3442 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
3443 "reply frame size(%d)\n", ioc->name,
3444 facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
3449 * _base_send_ioc_init - send ioc_init to firmware
3450 * @ioc: per adapter object
3451 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3453 * Returns 0 for success, non-zero for failure.
3456 _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3458 Mpi2IOCInitRequest_t mpi_request;
3459 Mpi2IOCInitReply_t mpi_reply;
3461 struct timeval current_time;
3464 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3467 memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
3468 mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
3469 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
3470 mpi_request.VF_ID = 0; /* TODO */
3471 mpi_request.VP_ID = 0;
3472 mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
3473 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
3475 if (_base_is_controller_msix_enabled(ioc))
3476 mpi_request.HostMSIxVectors = ioc->reply_queue_count;
3477 mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
3478 mpi_request.ReplyDescriptorPostQueueDepth =
3479 cpu_to_le16(ioc->reply_post_queue_depth);
3480 mpi_request.ReplyFreeQueueDepth =
3481 cpu_to_le16(ioc->reply_free_queue_depth);
3483 mpi_request.SenseBufferAddressHigh =
3484 cpu_to_le32((u64)ioc->sense_dma >> 32);
3485 mpi_request.SystemReplyAddressHigh =
3486 cpu_to_le32((u64)ioc->reply_dma >> 32);
3487 mpi_request.SystemRequestFrameBaseAddress =
3488 cpu_to_le64((u64)ioc->request_dma);
3489 mpi_request.ReplyFreeQueueAddress =
3490 cpu_to_le64((u64)ioc->reply_free_dma);
3491 mpi_request.ReplyDescriptorPostQueueAddress =
3492 cpu_to_le64((u64)ioc->reply_post_free_dma);
3495 /* This time stamp specifies number of milliseconds
3496 * since epoch ~ midnight January 1, 1970.
3498 do_gettimeofday(¤t_time);
3499 mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
3500 (current_time.tv_usec / 1000));
3502 if (ioc->logging_level & MPT_DEBUG_INIT) {
3506 mfp = (__le32 *)&mpi_request;
3507 printk(KERN_INFO "\toffset:data\n");
3508 for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
3509 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3510 le32_to_cpu(mfp[i]));
3513 r = _base_handshake_req_reply_wait(ioc,
3514 sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
3515 sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
3519 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3520 ioc->name, __func__, r);
3524 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
3525 if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
3526 mpi_reply.IOCLogInfo) {
3527 printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
3535 * mpt2sas_port_enable_done - command completion routine for port enable
3536 * @ioc: per adapter object
3537 * @smid: system request message index
3538 * @msix_index: MSIX table index supplied by the OS
3539 * @reply: reply message frame(lower 32bit addr)
3541 * Return 1 meaning mf should be freed from _base_interrupt
3542 * 0 means the mf is freed from this function.
3545 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3548 MPI2DefaultReply_t *mpi_reply;
3551 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3552 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3555 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3558 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3560 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3561 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3562 mpi_reply->MsgLength*4);
3564 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3566 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3568 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3569 ioc->port_enable_failed = 1;
3571 if (ioc->is_driver_loading) {
3572 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3573 mpt2sas_port_enable_complete(ioc);
3576 ioc->start_scan_failed = ioc_status;
3577 ioc->start_scan = 0;
3581 complete(&ioc->port_enable_cmds.done);
3587 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3588 * @ioc: per adapter object
3589 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3591 * Returns 0 for success, non-zero for failure.
3594 _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3596 Mpi2PortEnableRequest_t *mpi_request;
3597 Mpi2PortEnableReply_t *mpi_reply;
3598 unsigned long timeleft;
3603 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3605 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3606 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3607 ioc->name, __func__);
3611 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3613 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3614 ioc->name, __func__);
3618 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3619 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3620 ioc->port_enable_cmds.smid = smid;
3621 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3622 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3624 init_completion(&ioc->port_enable_cmds.done);
3625 mpt2sas_base_put_smid_default(ioc, smid);
3626 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
3628 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
3629 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3630 ioc->name, __func__);
3631 _debug_dump_mf(mpi_request,
3632 sizeof(Mpi2PortEnableRequest_t)/4);
3633 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
3639 mpi_reply = ioc->port_enable_cmds.reply;
3641 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3642 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3643 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3644 ioc->name, __func__, ioc_status);
3649 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3650 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3651 "SUCCESS" : "FAILED"));
3656 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3657 * @ioc: per adapter object
3659 * Returns 0 for success, non-zero for failure.
3662 mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3664 Mpi2PortEnableRequest_t *mpi_request;
3667 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3669 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3670 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3671 ioc->name, __func__);
3675 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3677 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3678 ioc->name, __func__);
3682 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3683 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3684 ioc->port_enable_cmds.smid = smid;
3685 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3686 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3688 mpt2sas_base_put_smid_default(ioc, smid);
3693 * _base_determine_wait_on_discovery - desposition
3694 * @ioc: per adapter object
3696 * Decide whether to wait on discovery to complete. Used to either
3697 * locate boot device, or report volumes ahead of physical devices.
3699 * Returns 1 for wait, 0 for don't wait
3702 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3704 /* We wait for discovery to complete if IR firmware is loaded.
3705 * The sas topology events arrive before PD events, so we need time to
3706 * turn on the bit in ioc->pd_handles to indicate PD
3707 * Also, it maybe required to report Volumes ahead of physical
3708 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3710 if (ioc->ir_firmware)
3713 /* if no Bios, then we don't need to wait */
3714 if (!ioc->bios_pg3.BiosVersion)
3717 /* Bios is present, then we drop down here.
3719 * If there any entries in the Bios Page 2, then we wait
3720 * for discovery to complete.
3723 /* Current Boot Device */
3724 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3725 MPI2_BIOSPAGE2_FORM_MASK) ==
3726 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3727 /* Request Boot Device */
3728 (ioc->bios_pg2.ReqBootDeviceForm &
3729 MPI2_BIOSPAGE2_FORM_MASK) ==
3730 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3731 /* Alternate Request Boot Device */
3732 (ioc->bios_pg2.ReqAltBootDeviceForm &
3733 MPI2_BIOSPAGE2_FORM_MASK) ==
3734 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3742 * _base_unmask_events - turn on notification for this event
3743 * @ioc: per adapter object
3744 * @event: firmware event
3746 * The mask is stored in ioc->event_masks.
3749 _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
3756 desired_event = (1 << (event % 32));
3759 ioc->event_masks[0] &= ~desired_event;
3760 else if (event < 64)
3761 ioc->event_masks[1] &= ~desired_event;
3762 else if (event < 96)
3763 ioc->event_masks[2] &= ~desired_event;
3764 else if (event < 128)
3765 ioc->event_masks[3] &= ~desired_event;
3769 * _base_event_notification - send event notification
3770 * @ioc: per adapter object
3771 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3773 * Returns 0 for success, non-zero for failure.
3776 _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3778 Mpi2EventNotificationRequest_t *mpi_request;
3779 unsigned long timeleft;
3784 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3787 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
3788 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3789 ioc->name, __func__);
3793 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3795 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3796 ioc->name, __func__);
3799 ioc->base_cmds.status = MPT2_CMD_PENDING;
3800 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3801 ioc->base_cmds.smid = smid;
3802 memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
3803 mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
3804 mpi_request->VF_ID = 0; /* TODO */
3805 mpi_request->VP_ID = 0;
3806 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3807 mpi_request->EventMasks[i] =
3808 cpu_to_le32(ioc->event_masks[i]);
3809 init_completion(&ioc->base_cmds.done);
3810 mpt2sas_base_put_smid_default(ioc, smid);
3811 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
3812 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3813 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3814 ioc->name, __func__);
3815 _debug_dump_mf(mpi_request,
3816 sizeof(Mpi2EventNotificationRequest_t)/4);
3817 if (ioc->base_cmds.status & MPT2_CMD_RESET)
3822 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
3823 ioc->name, __func__));
3824 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3829 * mpt2sas_base_validate_event_type - validating event types
3830 * @ioc: per adapter object
3831 * @event: firmware event
3833 * This will turn on firmware event notification when application
3834 * ask for that event. We don't mask events that are already enabled.
3837 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
3840 u32 event_mask, desired_event;
3841 u8 send_update_to_fw;
3843 for (i = 0, send_update_to_fw = 0; i <
3844 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
3845 event_mask = ~event_type[i];
3847 for (j = 0; j < 32; j++) {
3848 if (!(event_mask & desired_event) &&
3849 (ioc->event_masks[i] & desired_event)) {
3850 ioc->event_masks[i] &= ~desired_event;
3851 send_update_to_fw = 1;
3853 desired_event = (desired_event << 1);
3857 if (!send_update_to_fw)
3860 mutex_lock(&ioc->base_cmds.mutex);
3861 _base_event_notification(ioc, CAN_SLEEP);
3862 mutex_unlock(&ioc->base_cmds.mutex);
3866 * _base_diag_reset - the "big hammer" start of day reset
3867 * @ioc: per adapter object
3868 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3870 * Returns 0 for success, non-zero for failure.
3873 _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3875 u32 host_diagnostic;
3880 printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
3881 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
3886 /* Write magic sequence to WriteSequence register
3887 * Loop until in diagnostic mode
3889 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
3890 "sequence\n", ioc->name));
3891 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3892 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
3893 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
3894 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
3895 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
3896 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
3897 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
3900 if (sleep_flag == CAN_SLEEP)
3908 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3909 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
3910 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3911 ioc->name, count, host_diagnostic));
3913 } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
3915 hcb_size = readl(&ioc->chip->HCBSize);
3917 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
3919 writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
3920 &ioc->chip->HostDiagnostic);
3922 /* This delay allows the chip PCIe hardware time to finish reset tasks*/
3923 if (sleep_flag == CAN_SLEEP)
3924 msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000);
3926 mdelay(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000);
3928 /* Approximately 300 second max wait */
3929 for (count = 0; count < (300000000 /
3930 MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC); count++) {
3932 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3934 if (host_diagnostic == 0xFFFFFFFF)
3936 if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
3939 /* Wait to pass the second read delay window */
3940 if (sleep_flag == CAN_SLEEP)
3941 msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
3944 mdelay(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
3948 if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
3950 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
3951 "assuming the HCB Address points to good F/W\n",
3953 host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
3954 host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
3955 writel(host_diagnostic, &ioc->chip->HostDiagnostic);
3957 drsprintk(ioc, printk(MPT2SAS_INFO_FMT
3958 "re-enable the HCDW\n", ioc->name));
3959 writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
3960 &ioc->chip->HCBSize);
3963 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
3965 writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
3966 &ioc->chip->HostDiagnostic);
3968 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
3969 "diagnostic register\n", ioc->name));
3970 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3972 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
3973 "READY state\n", ioc->name));
3974 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
3977 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3978 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3982 printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
3986 printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
3991 * _base_make_ioc_ready - put controller in READY state
3992 * @ioc: per adapter object
3993 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3994 * @type: FORCE_BIG_HAMMER or SOFT_RESET
3996 * Returns 0 for success, non-zero for failure.
3999 _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4000 enum reset_type type)
4005 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4008 if (ioc->pci_error_recovery)
4011 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4012 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
4013 ioc->name, __func__, ioc_state));
4015 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
4018 if (ioc_state & MPI2_DOORBELL_USED) {
4019 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
4020 "active!\n", ioc->name));
4021 goto issue_diag_reset;
4024 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
4025 mpt2sas_base_fault_info(ioc, ioc_state &
4026 MPI2_DOORBELL_DATA_MASK);
4027 goto issue_diag_reset;
4030 if (type == FORCE_BIG_HAMMER)
4031 goto issue_diag_reset;
4033 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
4034 if (!(_base_send_ioc_reset(ioc,
4035 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
4036 ioc->ioc_reset_count++;
4041 rc = _base_diag_reset(ioc, CAN_SLEEP);
4042 ioc->ioc_reset_count++;
4047 * _base_make_ioc_operational - put controller in OPERATIONAL state
4048 * @ioc: per adapter object
4049 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4051 * Returns 0 for success, non-zero for failure.
4054 _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4057 unsigned long flags;
4060 struct _tr_list *delayed_tr, *delayed_tr_next;
4062 struct adapter_reply_queue *reply_q;
4063 long reply_post_free;
4064 u32 reply_post_free_sz;
4066 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4069 /* clean the delayed target reset list */
4070 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4071 &ioc->delayed_tr_list, list) {
4072 list_del(&delayed_tr->list);
4076 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4077 &ioc->delayed_tr_volume_list, list) {
4078 list_del(&delayed_tr->list);
4082 /* initialize the scsi lookup free list */
4083 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4084 INIT_LIST_HEAD(&ioc->free_list);
4086 for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
4087 INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
4088 ioc->scsi_lookup[i].cb_idx = 0xFF;
4089 ioc->scsi_lookup[i].smid = smid;
4090 ioc->scsi_lookup[i].scmd = NULL;
4091 ioc->scsi_lookup[i].direct_io = 0;
4092 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4096 /* hi-priority queue */
4097 INIT_LIST_HEAD(&ioc->hpr_free_list);
4098 smid = ioc->hi_priority_smid;
4099 for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
4100 ioc->hpr_lookup[i].cb_idx = 0xFF;
4101 ioc->hpr_lookup[i].smid = smid;
4102 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
4103 &ioc->hpr_free_list);
4106 /* internal queue */
4107 INIT_LIST_HEAD(&ioc->internal_free_list);
4108 smid = ioc->internal_smid;
4109 for (i = 0; i < ioc->internal_depth; i++, smid++) {
4110 ioc->internal_lookup[i].cb_idx = 0xFF;
4111 ioc->internal_lookup[i].smid = smid;
4112 list_add_tail(&ioc->internal_lookup[i].tracker_list,
4113 &ioc->internal_free_list);
4117 INIT_LIST_HEAD(&ioc->free_chain_list);
4118 for (i = 0; i < ioc->chain_depth; i++)
4119 list_add_tail(&ioc->chain_lookup[i].tracker_list,
4120 &ioc->free_chain_list);
4122 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4124 /* initialize Reply Free Queue */
4125 for (i = 0, reply_address = (u32)ioc->reply_dma ;
4126 i < ioc->reply_free_queue_depth ; i++, reply_address +=
4128 ioc->reply_free[i] = cpu_to_le32(reply_address);
4130 /* initialize reply queues */
4131 if (ioc->is_driver_loading)
4132 _base_assign_reply_queues(ioc);
4134 /* initialize Reply Post Free Queue */
4135 reply_post_free = (long)ioc->reply_post_free;
4136 reply_post_free_sz = ioc->reply_post_queue_depth *
4137 sizeof(Mpi2DefaultReplyDescriptor_t);
4138 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4139 reply_q->reply_post_host_index = 0;
4140 reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
4142 for (i = 0; i < ioc->reply_post_queue_depth; i++)
4143 reply_q->reply_post_free[i].Words =
4144 cpu_to_le64(ULLONG_MAX);
4145 if (!_base_is_controller_msix_enabled(ioc))
4146 goto skip_init_reply_post_free_queue;
4147 reply_post_free += reply_post_free_sz;
4149 skip_init_reply_post_free_queue:
4151 r = _base_send_ioc_init(ioc, sleep_flag);
4155 /* initialize reply free host index */
4156 ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
4157 writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
4159 /* initialize reply post host index */
4160 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4161 writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
4162 &ioc->chip->ReplyPostHostIndex);
4163 if (!_base_is_controller_msix_enabled(ioc))
4164 goto skip_init_reply_post_host_index;
4167 skip_init_reply_post_host_index:
4169 _base_unmask_interrupts(ioc);
4171 r = _base_event_notification(ioc, sleep_flag);
4175 if (sleep_flag == CAN_SLEEP)
4176 _base_static_config_pages(ioc);
4179 if (ioc->is_driver_loading) {
4180 if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier
4183 le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) &
4184 MFG_PAGE10_HIDE_SSDS_MASK);
4185 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
4186 ioc->mfg_pg10_hide_flag = hide_flag;
4188 ioc->wait_for_discovery_to_complete =
4189 _base_determine_wait_on_discovery(ioc);
4190 return r; /* scan_start and scan_finished support */
4192 r = _base_send_port_enable(ioc, sleep_flag);
4200 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4201 * @ioc: per adapter object
4206 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
4208 struct pci_dev *pdev = ioc->pdev;
4210 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4213 if (ioc->chip_phys && ioc->chip) {
4214 _base_mask_interrupts(ioc);
4215 ioc->shost_recovery = 1;
4216 _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4217 ioc->shost_recovery = 0;
4220 _base_free_irq(ioc);
4221 _base_disable_msix(ioc);
4223 if (ioc->chip_phys && ioc->chip)
4227 if (pci_is_enabled(pdev)) {
4228 pci_release_selected_regions(ioc->pdev, ioc->bars);
4229 pci_disable_pcie_error_reporting(pdev);
4230 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] = (resource_size_t __iomem *)
4281 &ioc->chip->ReplyPostHostIndex;
4283 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
4284 ioc->reply_post_host_index[i] =
4285 (resource_size_t __iomem *)
4286 ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
4290 pci_set_drvdata(ioc->pdev, ioc->shost);
4291 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
4293 goto out_free_resources;
4295 r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4297 goto out_free_resources;
4299 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
4300 sizeof(struct mpt2sas_port_facts), GFP_KERNEL);
4303 goto out_free_resources;
4306 for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
4307 r = _base_get_port_facts(ioc, i, CAN_SLEEP);
4309 goto out_free_resources;
4312 r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
4314 goto out_free_resources;
4316 init_waitqueue_head(&ioc->reset_wq);
4317 /* allocate memory pd handle bitmask list */
4318 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
4319 if (ioc->facts.MaxDevHandle % 8)
4320 ioc->pd_handles_sz++;
4321 ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
4323 if (!ioc->pd_handles) {
4325 goto out_free_resources;
4327 ioc->blocking_handles = kzalloc(ioc->pd_handles_sz,
4329 if (!ioc->blocking_handles) {
4331 goto out_free_resources;
4333 ioc->fwfault_debug = mpt2sas_fwfault_debug;
4335 /* base internal command bits */
4336 mutex_init(&ioc->base_cmds.mutex);
4337 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4338 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4340 /* port_enable command bits */
4341 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4342 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4344 /* transport internal command bits */
4345 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4346 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
4347 mutex_init(&ioc->transport_cmds.mutex);
4349 /* scsih internal command bits */
4350 ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4351 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
4352 mutex_init(&ioc->scsih_cmds.mutex);
4354 /* task management internal command bits */
4355 ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4356 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4357 mutex_init(&ioc->tm_cmds.mutex);
4359 /* config page internal command bits */
4360 ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4361 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
4362 mutex_init(&ioc->config_cmds.mutex);
4364 /* ctl module internal command bits */
4365 ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4366 ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
4367 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
4368 mutex_init(&ioc->ctl_cmds.mutex);
4370 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4371 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4372 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
4373 !ioc->ctl_cmds.sense) {
4375 goto out_free_resources;
4378 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4379 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4380 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
4382 goto out_free_resources;
4385 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4386 ioc->event_masks[i] = -1;
4388 /* here we enable the events we care about */
4389 _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
4390 _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
4391 _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
4392 _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4393 _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
4394 _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
4395 _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
4396 _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
4397 _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
4398 _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
4399 r = _base_make_ioc_operational(ioc, CAN_SLEEP);
4401 goto out_free_resources;
4403 ioc->non_operational_loop = 0;
4409 ioc->remove_host = 1;
4410 mpt2sas_base_free_resources(ioc);
4411 _base_release_memory_pools(ioc);
4412 pci_set_drvdata(ioc->pdev, NULL);
4413 kfree(ioc->cpu_msix_table);
4414 if (ioc->is_warpdrive)
4415 kfree(ioc->reply_post_host_index);
4416 kfree(ioc->pd_handles);
4417 kfree(ioc->blocking_handles);
4418 kfree(ioc->tm_cmds.reply);
4419 kfree(ioc->transport_cmds.reply);
4420 kfree(ioc->scsih_cmds.reply);
4421 kfree(ioc->config_cmds.reply);
4422 kfree(ioc->base_cmds.reply);
4423 kfree(ioc->port_enable_cmds.reply);
4424 kfree(ioc->ctl_cmds.reply);
4425 kfree(ioc->ctl_cmds.sense);
4427 ioc->ctl_cmds.reply = NULL;
4428 ioc->base_cmds.reply = NULL;
4429 ioc->tm_cmds.reply = NULL;
4430 ioc->scsih_cmds.reply = NULL;
4431 ioc->transport_cmds.reply = NULL;
4432 ioc->config_cmds.reply = NULL;
4439 * mpt2sas_base_detach - remove controller instance
4440 * @ioc: per adapter object
4445 mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4448 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4451 mpt2sas_base_stop_watchdog(ioc);
4452 mpt2sas_base_free_resources(ioc);
4453 _base_release_memory_pools(ioc);
4454 pci_set_drvdata(ioc->pdev, NULL);
4455 kfree(ioc->cpu_msix_table);
4456 if (ioc->is_warpdrive)
4457 kfree(ioc->reply_post_host_index);
4458 kfree(ioc->pd_handles);
4459 kfree(ioc->blocking_handles);
4461 kfree(ioc->ctl_cmds.reply);
4462 kfree(ioc->ctl_cmds.sense);
4463 kfree(ioc->base_cmds.reply);
4464 kfree(ioc->port_enable_cmds.reply);
4465 kfree(ioc->tm_cmds.reply);
4466 kfree(ioc->transport_cmds.reply);
4467 kfree(ioc->scsih_cmds.reply);
4468 kfree(ioc->config_cmds.reply);
4472 * _base_reset_handler - reset callback handler (for base)
4473 * @ioc: per adapter object
4474 * @reset_phase: phase
4476 * The handler for doing any required cleanup or initialization.
4478 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4479 * MPT2_IOC_DONE_RESET
4484 _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4486 mpt2sas_scsih_reset_handler(ioc, reset_phase);
4487 mpt2sas_ctl_reset_handler(ioc, reset_phase);
4488 switch (reset_phase) {
4489 case MPT2_IOC_PRE_RESET:
4490 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4491 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
4493 case MPT2_IOC_AFTER_RESET:
4494 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4495 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
4496 if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
4497 ioc->transport_cmds.status |= MPT2_CMD_RESET;
4498 mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
4499 complete(&ioc->transport_cmds.done);
4501 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
4502 ioc->base_cmds.status |= MPT2_CMD_RESET;
4503 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4504 complete(&ioc->base_cmds.done);
4506 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4507 ioc->port_enable_failed = 1;
4508 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4509 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4510 if (ioc->is_driver_loading) {
4511 ioc->start_scan_failed =
4512 MPI2_IOCSTATUS_INTERNAL_ERROR;
4513 ioc->start_scan = 0;
4514 ioc->port_enable_cmds.status =
4517 complete(&ioc->port_enable_cmds.done);
4520 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4521 ioc->config_cmds.status |= MPT2_CMD_RESET;
4522 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
4523 ioc->config_cmds.smid = USHRT_MAX;
4524 complete(&ioc->config_cmds.done);
4527 case MPT2_IOC_DONE_RESET:
4528 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4529 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
4535 * _wait_for_commands_to_complete - reset controller
4536 * @ioc: Pointer to MPT_ADAPTER structure
4537 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4539 * This function waiting(3s) for all pending commands to complete
4540 * prior to putting controller in reset.
4543 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4546 unsigned long flags;
4549 ioc->pending_io_count = 0;
4550 if (sleep_flag != CAN_SLEEP)
4553 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4554 if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
4557 /* pending command count */
4558 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4559 for (i = 0; i < ioc->scsiio_depth; i++)
4560 if (ioc->scsi_lookup[i].cb_idx != 0xFF)
4561 ioc->pending_io_count++;
4562 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4564 if (!ioc->pending_io_count)
4567 /* wait for pending commands to complete */
4568 wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
4572 * mpt2sas_base_hard_reset_handler - reset controller
4573 * @ioc: Pointer to MPT_ADAPTER structure
4574 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4575 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4577 * Returns 0 for success, non-zero for failure.
4580 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4581 enum reset_type type)
4584 unsigned long flags;
4586 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
4589 if (ioc->pci_error_recovery) {
4590 printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
4591 ioc->name, __func__);
4596 if (mpt2sas_fwfault_debug)
4597 mpt2sas_halt_firmware(ioc);
4599 /* TODO - What we really should be doing is pulling
4600 * out all the code associated with NO_SLEEP; its never used.
4601 * That is legacy code from mpt fusion driver, ported over.
4602 * I will leave this BUG_ON here for now till its been resolved.
4604 BUG_ON(sleep_flag == NO_SLEEP);
4606 /* wait for an active reset in progress to complete */
4607 if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
4610 } while (ioc->shost_recovery == 1);
4611 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
4613 return ioc->ioc_reset_in_progress_status;
4616 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4617 ioc->shost_recovery = 1;
4618 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4620 _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
4621 _wait_for_commands_to_complete(ioc, sleep_flag);
4622 _base_mask_interrupts(ioc);
4623 r = _base_make_ioc_ready(ioc, sleep_flag, type);
4626 _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
4628 /* If this hard reset is called while port enable is active, then
4629 * there is no reason to call make_ioc_operational
4631 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4632 ioc->remove_host = 1;
4636 r = _base_make_ioc_operational(ioc, sleep_flag);
4638 _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
4640 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
4641 ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
4643 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4644 ioc->ioc_reset_in_progress_status = r;
4645 ioc->shost_recovery = 0;
4646 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4647 mutex_unlock(&ioc->reset_in_progress_mutex);
4650 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,