2 * This is the Fusion MPT base driver providing common API layer interface
3 * for access to MPT (Message Passing Technology) firmware.
5 * This code is based on drivers/scsi/mpt2sas/mpt2_base.c
6 * Copyright (C) 2007-2010 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h>
54 #include <linux/delay.h>
55 #include <linux/interrupt.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/sort.h>
59 #include <linux/time.h>
60 #include <linux/aer.h>
62 #include "mpt2sas_base.h"
64 static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS];
66 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
68 #define MAX_HBA_QUEUE_DEPTH 30000
69 #define MAX_CHAIN_DEPTH 100000
70 static int max_queue_depth = -1;
71 module_param(max_queue_depth, int, 0);
72 MODULE_PARM_DESC(max_queue_depth, " max controller queue depth ");
74 static int max_sgl_entries = -1;
75 module_param(max_sgl_entries, int, 0);
76 MODULE_PARM_DESC(max_sgl_entries, " max sg entries ");
78 static int msix_disable = -1;
79 module_param(msix_disable, int, 0);
80 MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)");
82 static int mpt2sas_fwfault_debug;
83 MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
84 "and halt firmware - (default=0)");
86 static int disable_discovery = -1;
87 module_param(disable_discovery, int, 0);
88 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
91 /* diag_buffer_enable is bitwise
93 * bit 1 set = SNAPSHOT
94 * bit 2 set = EXTENDED
96 * Either bit can be set, or both
98 static int diag_buffer_enable;
99 module_param(diag_buffer_enable, int, 0);
100 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
101 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
104 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
108 _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
110 int ret = param_set_int(val, kp);
111 struct MPT2SAS_ADAPTER *ioc;
116 printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
117 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
118 ioc->fwfault_debug = mpt2sas_fwfault_debug;
121 module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug,
122 param_get_int, &mpt2sas_fwfault_debug, 0644);
125 * _base_fault_reset_work - workq handling ioc fault conditions
126 * @work: input argument, used to derive ioc
132 _base_fault_reset_work(struct work_struct *work)
134 struct MPT2SAS_ADAPTER *ioc =
135 container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
140 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
141 if (ioc->shost_recovery)
143 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
145 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
146 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
147 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
149 printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
150 __func__, (rc == 0) ? "success" : "failed");
151 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
152 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
153 mpt2sas_base_fault_info(ioc, doorbell &
154 MPI2_DOORBELL_DATA_MASK);
157 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
159 if (ioc->fault_reset_work_q)
160 queue_delayed_work(ioc->fault_reset_work_q,
161 &ioc->fault_reset_work,
162 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
163 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
167 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
168 * @ioc: per adapter object
174 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
178 if (ioc->fault_reset_work_q)
181 /* initialize fault polling */
182 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
183 snprintf(ioc->fault_reset_work_q_name,
184 sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
185 ioc->fault_reset_work_q =
186 create_singlethread_workqueue(ioc->fault_reset_work_q_name);
187 if (!ioc->fault_reset_work_q) {
188 printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
189 ioc->name, __func__, __LINE__);
192 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
193 if (ioc->fault_reset_work_q)
194 queue_delayed_work(ioc->fault_reset_work_q,
195 &ioc->fault_reset_work,
196 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
197 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
201 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
202 * @ioc: per adapter object
208 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
211 struct workqueue_struct *wq;
213 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
214 wq = ioc->fault_reset_work_q;
215 ioc->fault_reset_work_q = NULL;
216 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
218 if (!cancel_delayed_work(&ioc->fault_reset_work))
220 destroy_workqueue(wq);
225 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
226 * @ioc: per adapter object
227 * @fault_code: fault code
232 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
234 printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
235 ioc->name, fault_code);
239 * mpt2sas_halt_firmware - halt's mpt controller firmware
240 * @ioc: per adapter object
242 * For debugging timeout related issues. Writing 0xCOFFEE00
243 * to the doorbell register will halt controller firmware. With
244 * the purpose to stop both driver and firmware, the enduser can
245 * obtain a ring buffer from controller UART.
248 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc)
252 if (!ioc->fwfault_debug)
257 doorbell = readl(&ioc->chip->Doorbell);
258 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
259 mpt2sas_base_fault_info(ioc , doorbell);
261 writel(0xC0FFEE00, &ioc->chip->Doorbell);
262 printk(MPT2SAS_ERR_FMT "Firmware is halted due to command "
263 "timeout\n", ioc->name);
266 panic("panic in %s\n", __func__);
269 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
271 * _base_sas_ioc_info - verbose translation of the ioc status
272 * @ioc: per adapter object
273 * @mpi_reply: reply mf payload returned from firmware
274 * @request_hdr: request mf
279 _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
280 MPI2RequestHeader_t *request_hdr)
282 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
286 char *func_str = NULL;
288 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
289 if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
290 request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
291 request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
294 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
297 switch (ioc_status) {
299 /****************************************************************************
300 * Common IOCStatus values for all replies
301 ****************************************************************************/
303 case MPI2_IOCSTATUS_INVALID_FUNCTION:
304 desc = "invalid function";
306 case MPI2_IOCSTATUS_BUSY:
309 case MPI2_IOCSTATUS_INVALID_SGL:
310 desc = "invalid sgl";
312 case MPI2_IOCSTATUS_INTERNAL_ERROR:
313 desc = "internal error";
315 case MPI2_IOCSTATUS_INVALID_VPID:
316 desc = "invalid vpid";
318 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
319 desc = "insufficient resources";
321 case MPI2_IOCSTATUS_INVALID_FIELD:
322 desc = "invalid field";
324 case MPI2_IOCSTATUS_INVALID_STATE:
325 desc = "invalid state";
327 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
328 desc = "op state not supported";
331 /****************************************************************************
332 * Config IOCStatus values
333 ****************************************************************************/
335 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
336 desc = "config invalid action";
338 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
339 desc = "config invalid type";
341 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
342 desc = "config invalid page";
344 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
345 desc = "config invalid data";
347 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
348 desc = "config no defaults";
350 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
351 desc = "config cant commit";
354 /****************************************************************************
356 ****************************************************************************/
358 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
359 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
360 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
361 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
362 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
363 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
364 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
365 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
366 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
367 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
368 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
369 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
372 /****************************************************************************
373 * For use by SCSI Initiator and SCSI Target end-to-end data protection
374 ****************************************************************************/
376 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
377 desc = "eedp guard error";
379 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
380 desc = "eedp ref tag error";
382 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
383 desc = "eedp app tag error";
386 /****************************************************************************
388 ****************************************************************************/
390 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
391 desc = "target invalid io index";
393 case MPI2_IOCSTATUS_TARGET_ABORTED:
394 desc = "target aborted";
396 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
397 desc = "target no conn retryable";
399 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
400 desc = "target no connection";
402 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
403 desc = "target xfer count mismatch";
405 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
406 desc = "target data offset error";
408 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
409 desc = "target too much write data";
411 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
412 desc = "target iu too short";
414 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
415 desc = "target ack nak timeout";
417 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
418 desc = "target nak received";
421 /****************************************************************************
422 * Serial Attached SCSI values
423 ****************************************************************************/
425 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
426 desc = "smp request failed";
428 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
429 desc = "smp data overrun";
432 /****************************************************************************
433 * Diagnostic Buffer Post / Diagnostic Release values
434 ****************************************************************************/
436 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
437 desc = "diagnostic released";
446 switch (request_hdr->Function) {
447 case MPI2_FUNCTION_CONFIG:
448 frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
449 func_str = "config_page";
451 case MPI2_FUNCTION_SCSI_TASK_MGMT:
452 frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
453 func_str = "task_mgmt";
455 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
456 frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
457 func_str = "sas_iounit_ctl";
459 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
460 frame_sz = sizeof(Mpi2SepRequest_t);
461 func_str = "enclosure";
463 case MPI2_FUNCTION_IOC_INIT:
464 frame_sz = sizeof(Mpi2IOCInitRequest_t);
465 func_str = "ioc_init";
467 case MPI2_FUNCTION_PORT_ENABLE:
468 frame_sz = sizeof(Mpi2PortEnableRequest_t);
469 func_str = "port_enable";
471 case MPI2_FUNCTION_SMP_PASSTHROUGH:
472 frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
473 func_str = "smp_passthru";
477 func_str = "unknown";
481 printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
482 " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
484 _debug_dump_mf(request_hdr, frame_sz/4);
488 * _base_display_event_data - verbose translation of firmware asyn events
489 * @ioc: per adapter object
490 * @mpi_reply: reply mf payload returned from firmware
495 _base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
496 Mpi2EventNotificationReply_t *mpi_reply)
501 if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
504 event = le16_to_cpu(mpi_reply->Event);
507 case MPI2_EVENT_LOG_DATA:
510 case MPI2_EVENT_STATE_CHANGE:
511 desc = "Status Change";
513 case MPI2_EVENT_HARD_RESET_RECEIVED:
514 desc = "Hard Reset Received";
516 case MPI2_EVENT_EVENT_CHANGE:
517 desc = "Event Change";
519 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
520 desc = "Device Status Change";
522 case MPI2_EVENT_IR_OPERATION_STATUS:
523 if (!ioc->hide_ir_msg)
524 desc = "IR Operation Status";
526 case MPI2_EVENT_SAS_DISCOVERY:
528 Mpi2EventDataSasDiscovery_t *event_data =
529 (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData;
530 printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name,
531 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
533 if (event_data->DiscoveryStatus)
534 printk("discovery_status(0x%08x)",
535 le32_to_cpu(event_data->DiscoveryStatus));
539 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
540 desc = "SAS Broadcast Primitive";
542 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
543 desc = "SAS Init Device Status Change";
545 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
546 desc = "SAS Init Table Overflow";
548 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
549 desc = "SAS Topology Change List";
551 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
552 desc = "SAS Enclosure Device Status Change";
554 case MPI2_EVENT_IR_VOLUME:
555 if (!ioc->hide_ir_msg)
558 case MPI2_EVENT_IR_PHYSICAL_DISK:
559 if (!ioc->hide_ir_msg)
560 desc = "IR Physical Disk";
562 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
563 if (!ioc->hide_ir_msg)
564 desc = "IR Configuration Change List";
566 case MPI2_EVENT_LOG_ENTRY_ADDED:
567 if (!ioc->hide_ir_msg)
568 desc = "Log Entry Added";
575 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
580 * _base_sas_log_info - verbose translation of firmware log info
581 * @ioc: per adapter object
582 * @log_info: log info
587 _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
598 union loginfo_type sas_loginfo;
599 char *originator_str = NULL;
601 sas_loginfo.loginfo = log_info;
602 if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
605 /* each nexus loss loginfo */
606 if (log_info == 0x31170000)
609 /* eat the loginfos associated with task aborts */
610 if (ioc->ignore_loginfos && (log_info == 30050000 || log_info ==
611 0x31140000 || log_info == 0x31130000))
614 switch (sas_loginfo.dw.originator) {
616 originator_str = "IOP";
619 originator_str = "PL";
622 if (!ioc->hide_ir_msg)
623 originator_str = "IR";
625 originator_str = "WarpDrive";
629 printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
630 "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
631 originator_str, sas_loginfo.dw.code,
632 sas_loginfo.dw.subcode);
636 * _base_display_reply_info -
637 * @ioc: per adapter object
638 * @smid: system request message index
639 * @msix_index: MSIX table index supplied by the OS
640 * @reply: reply message frame(lower 32bit addr)
645 _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
648 MPI2DefaultReply_t *mpi_reply;
651 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
652 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
653 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
654 if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
655 (ioc->logging_level & MPT_DEBUG_REPLY)) {
656 _base_sas_ioc_info(ioc , mpi_reply,
657 mpt2sas_base_get_msg_frame(ioc, smid));
660 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
661 _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
665 * mpt2sas_base_done - base internal command completion routine
666 * @ioc: per adapter object
667 * @smid: system request message index
668 * @msix_index: MSIX table index supplied by the OS
669 * @reply: reply message frame(lower 32bit addr)
671 * Return 1 meaning mf should be freed from _base_interrupt
672 * 0 means the mf is freed from this function.
675 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
678 MPI2DefaultReply_t *mpi_reply;
680 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
681 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
684 if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
687 ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
689 ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
690 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
692 ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
694 complete(&ioc->base_cmds.done);
699 * _base_async_event - main callback handler for firmware asyn events
700 * @ioc: per adapter object
701 * @msix_index: MSIX table index supplied by the OS
702 * @reply: reply message frame(lower 32bit addr)
704 * Return 1 meaning mf should be freed from _base_interrupt
705 * 0 means the mf is freed from this function.
708 _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
710 Mpi2EventNotificationReply_t *mpi_reply;
711 Mpi2EventAckRequest_t *ack_request;
714 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
717 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
719 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
720 _base_display_event_data(ioc, mpi_reply);
722 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
724 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
726 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
727 ioc->name, __func__);
731 ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
732 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
733 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
734 ack_request->Event = mpi_reply->Event;
735 ack_request->EventContext = mpi_reply->EventContext;
736 ack_request->VF_ID = 0; /* TODO */
737 ack_request->VP_ID = 0;
738 mpt2sas_base_put_smid_default(ioc, smid);
742 /* scsih callback handler */
743 mpt2sas_scsih_event_callback(ioc, msix_index, reply);
745 /* ctl callback handler */
746 mpt2sas_ctl_event_callback(ioc, msix_index, reply);
752 * _base_get_cb_idx - obtain the callback index
753 * @ioc: per adapter object
754 * @smid: system request message index
756 * Return callback index.
759 _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
764 if (smid < ioc->hi_priority_smid) {
766 cb_idx = ioc->scsi_lookup[i].cb_idx;
767 } else if (smid < ioc->internal_smid) {
768 i = smid - ioc->hi_priority_smid;
769 cb_idx = ioc->hpr_lookup[i].cb_idx;
770 } else if (smid <= ioc->hba_queue_depth) {
771 i = smid - ioc->internal_smid;
772 cb_idx = ioc->internal_lookup[i].cb_idx;
779 * _base_mask_interrupts - disable interrupts
780 * @ioc: per adapter object
782 * Disabling ResetIRQ, Reply and Doorbell Interrupts
787 _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
791 ioc->mask_interrupts = 1;
792 him_register = readl(&ioc->chip->HostInterruptMask);
793 him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
794 writel(him_register, &ioc->chip->HostInterruptMask);
795 readl(&ioc->chip->HostInterruptMask);
799 * _base_unmask_interrupts - enable interrupts
800 * @ioc: per adapter object
802 * Enabling only Reply Interrupts
807 _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
811 him_register = readl(&ioc->chip->HostInterruptMask);
812 him_register &= ~MPI2_HIM_RIM;
813 writel(him_register, &ioc->chip->HostInterruptMask);
814 ioc->mask_interrupts = 0;
817 union reply_descriptor {
826 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
827 * @irq: irq number (not used)
828 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
829 * @r: pt_regs pointer (not used)
831 * Return IRQ_HANDLE if processed, else IRQ_NONE.
834 _base_interrupt(int irq, void *bus_id)
836 struct adapter_reply_queue *reply_q = bus_id;
837 union reply_descriptor rd;
839 u8 request_desript_type;
843 u8 msix_index = reply_q->msix_index;
844 struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
845 Mpi2ReplyDescriptorsUnion_t *rpf;
848 if (ioc->mask_interrupts)
851 if (!atomic_add_unless(&reply_q->busy, 1, 1))
854 rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
855 request_desript_type = rpf->Default.ReplyFlags
856 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
857 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
858 atomic_dec(&reply_q->busy);
865 rd.word = le64_to_cpu(rpf->Words);
866 if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
869 smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
870 if (request_desript_type ==
871 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
873 (rpf->AddressReply.ReplyFrameAddress);
874 if (reply > ioc->reply_dma_max_address ||
875 reply < ioc->reply_dma_min_address)
877 } else if (request_desript_type ==
878 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
880 else if (request_desript_type ==
881 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
884 cb_idx = _base_get_cb_idx(ioc, smid);
885 if (smid && cb_idx != 0xFF) {
886 rc = mpt_callbacks[cb_idx](ioc, smid, msix_index,
889 _base_display_reply_info(ioc, smid, msix_index,
892 mpt2sas_base_free_smid(ioc, smid);
895 _base_async_event(ioc, msix_index, reply);
897 /* reply free queue handling */
899 ioc->reply_free_host_index =
900 (ioc->reply_free_host_index ==
901 (ioc->reply_free_queue_depth - 1)) ?
902 0 : ioc->reply_free_host_index + 1;
903 ioc->reply_free[ioc->reply_free_host_index] =
906 writel(ioc->reply_free_host_index,
907 &ioc->chip->ReplyFreeHostIndex);
912 rpf->Words = cpu_to_le64(ULLONG_MAX);
913 reply_q->reply_post_host_index =
914 (reply_q->reply_post_host_index ==
915 (ioc->reply_post_queue_depth - 1)) ? 0 :
916 reply_q->reply_post_host_index + 1;
917 request_desript_type =
918 reply_q->reply_post_free[reply_q->reply_post_host_index].
919 Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
921 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
923 if (!reply_q->reply_post_host_index)
924 rpf = reply_q->reply_post_free;
931 if (!completed_cmds) {
932 atomic_dec(&reply_q->busy);
936 if (ioc->is_warpdrive) {
937 writel(reply_q->reply_post_host_index,
938 ioc->reply_post_host_index[msix_index]);
939 atomic_dec(&reply_q->busy);
942 writel(reply_q->reply_post_host_index | (msix_index <<
943 MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
944 atomic_dec(&reply_q->busy);
949 * _base_is_controller_msix_enabled - is controller support muli-reply queues
950 * @ioc: per adapter object
954 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
956 return (ioc->facts.IOCCapabilities &
957 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
961 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
962 * @ioc: per adapter object
963 * Context: ISR conext
965 * Called when a Task Management request has completed. We want
966 * to flush the other reply queues so all the outstanding IO has been
967 * completed back to OS before we process the TM completetion.
972 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
974 struct adapter_reply_queue *reply_q;
976 /* If MSIX capability is turned off
977 * then multi-queues are not enabled
979 if (!_base_is_controller_msix_enabled(ioc))
982 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
983 if (ioc->shost_recovery)
985 /* TMs are on msix_index == 0 */
986 if (reply_q->msix_index == 0)
988 _base_interrupt(reply_q->vector, (void *)reply_q);
993 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
994 * @cb_idx: callback index
999 mpt2sas_base_release_callback_handler(u8 cb_idx)
1001 mpt_callbacks[cb_idx] = NULL;
1005 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1006 * @cb_func: callback function
1011 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
1015 for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
1016 if (mpt_callbacks[cb_idx] == NULL)
1019 mpt_callbacks[cb_idx] = cb_func;
1024 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1029 mpt2sas_base_initialize_callback_handler(void)
1033 for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
1034 mpt2sas_base_release_callback_handler(cb_idx);
1038 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1039 * @ioc: per adapter object
1040 * @paddr: virtual address for SGE
1042 * Create a zero length scatter gather entry to insure the IOCs hardware has
1043 * something to use if the target device goes brain dead and tries
1044 * to send data even when none is asked for.
1049 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
1051 u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
1052 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
1053 MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
1054 MPI2_SGE_FLAGS_SHIFT);
1055 ioc->base_add_sg_single(paddr, flags_length, -1);
1059 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1060 * @paddr: virtual address for SGE
1061 * @flags_length: SGE flags and data transfer length
1062 * @dma_addr: Physical address
1067 _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1069 Mpi2SGESimple32_t *sgel = paddr;
1071 flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
1072 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1073 sgel->FlagsLength = cpu_to_le32(flags_length);
1074 sgel->Address = cpu_to_le32(dma_addr);
1079 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1080 * @paddr: virtual address for SGE
1081 * @flags_length: SGE flags and data transfer length
1082 * @dma_addr: Physical address
1087 _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1089 Mpi2SGESimple64_t *sgel = paddr;
1091 flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
1092 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1093 sgel->FlagsLength = cpu_to_le32(flags_length);
1094 sgel->Address = cpu_to_le64(dma_addr);
1097 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1100 * _base_config_dma_addressing - set dma addressing
1101 * @ioc: per adapter object
1102 * @pdev: PCI device struct
1104 * Returns 0 for success, non-zero for failure.
1107 _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
1112 if (sizeof(dma_addr_t) > 4) {
1113 const uint64_t required_mask =
1114 dma_get_required_mask(&pdev->dev);
1115 if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
1116 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
1117 DMA_BIT_MASK(64))) {
1118 ioc->base_add_sg_single = &_base_add_sg_single_64;
1119 ioc->sge_size = sizeof(Mpi2SGESimple64_t);
1125 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1126 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
1127 ioc->base_add_sg_single = &_base_add_sg_single_32;
1128 ioc->sge_size = sizeof(Mpi2SGESimple32_t);
1135 printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1136 "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
1142 * _base_check_enable_msix - checks MSIX capabable.
1143 * @ioc: per adapter object
1145 * Check to see if card is capable of MSIX, and set number
1146 * of available msix vectors
1149 _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1152 u16 message_control;
1155 /* Check whether controller SAS2008 B0 controller,
1156 if it is SAS2008 B0 controller use IO-APIC instead of MSIX */
1157 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 &&
1158 ioc->pdev->revision == 0x01) {
1162 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1164 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
1165 "supported\n", ioc->name));
1169 /* get msix vector count */
1170 /* NUMA_IO not supported for older controllers */
1171 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
1172 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
1173 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
1174 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
1175 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
1176 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
1177 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
1178 ioc->msix_vector_count = 1;
1180 pci_read_config_word(ioc->pdev, base + 2, &message_control);
1181 ioc->msix_vector_count = (message_control & 0x3FF) + 1;
1183 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
1184 "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
1190 * _base_free_irq - free irq
1191 * @ioc: per adapter object
1193 * Freeing respective reply_queue from the list.
1196 _base_free_irq(struct MPT2SAS_ADAPTER *ioc)
1198 struct adapter_reply_queue *reply_q, *next;
1200 if (list_empty(&ioc->reply_queue_list))
1203 list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
1204 list_del(&reply_q->list);
1205 synchronize_irq(reply_q->vector);
1206 free_irq(reply_q->vector, reply_q);
1212 * _base_request_irq - request irq
1213 * @ioc: per adapter object
1214 * @index: msix index into vector table
1215 * @vector: irq vector
1217 * Inserting respective reply_queue into the list.
1220 _base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
1222 struct adapter_reply_queue *reply_q;
1225 reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
1227 printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
1228 ioc->name, (int)sizeof(struct adapter_reply_queue));
1232 reply_q->msix_index = index;
1233 reply_q->vector = vector;
1234 atomic_set(&reply_q->busy, 0);
1235 if (ioc->msix_enable)
1236 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
1237 MPT2SAS_DRIVER_NAME, ioc->id, index);
1239 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
1240 MPT2SAS_DRIVER_NAME, ioc->id);
1241 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1244 printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
1245 reply_q->name, vector);
1250 INIT_LIST_HEAD(&reply_q->list);
1251 list_add_tail(&reply_q->list, &ioc->reply_queue_list);
1256 * _base_assign_reply_queues - assigning msix index for each cpu
1257 * @ioc: per adapter object
1259 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1261 * It would nice if we could call irq_set_affinity, however it is not
1262 * an exported symbol
1265 _base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1267 struct adapter_reply_queue *reply_q;
1269 int cpu_grouping, loop, grouping, grouping_mod;
1271 if (!_base_is_controller_msix_enabled(ioc))
1274 memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
1275 /* when there are more cpus than available msix vectors,
1276 * then group cpus togeather on same irq
1278 if (ioc->cpu_count > ioc->msix_vector_count) {
1279 grouping = ioc->cpu_count / ioc->msix_vector_count;
1280 grouping_mod = ioc->cpu_count % ioc->msix_vector_count;
1281 if (grouping < 2 || (grouping == 2 && !grouping_mod))
1283 else if (grouping < 4 || (grouping == 4 && !grouping_mod))
1285 else if (grouping < 8 || (grouping == 8 && !grouping_mod))
1293 reply_q = list_entry(ioc->reply_queue_list.next,
1294 struct adapter_reply_queue, list);
1295 for_each_online_cpu(cpu_id) {
1296 if (!cpu_grouping) {
1297 ioc->cpu_msix_table[cpu_id] = reply_q->msix_index;
1298 reply_q = list_entry(reply_q->list.next,
1299 struct adapter_reply_queue, list);
1301 if (loop < cpu_grouping) {
1302 ioc->cpu_msix_table[cpu_id] =
1303 reply_q->msix_index;
1306 reply_q = list_entry(reply_q->list.next,
1307 struct adapter_reply_queue, list);
1308 ioc->cpu_msix_table[cpu_id] =
1309 reply_q->msix_index;
1317 * _base_disable_msix - disables msix
1318 * @ioc: per adapter object
1322 _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
1324 if (ioc->msix_enable) {
1325 pci_disable_msix(ioc->pdev);
1326 ioc->msix_enable = 0;
1331 * _base_enable_msix - enables msix, failback to io_apic
1332 * @ioc: per adapter object
1336 _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1338 struct msix_entry *entries, *a;
1343 INIT_LIST_HEAD(&ioc->reply_queue_list);
1345 if (msix_disable == -1 || msix_disable == 0)
1351 if (_base_check_enable_msix(ioc) != 0)
1354 ioc->reply_queue_count = min_t(u8, ioc->cpu_count,
1355 ioc->msix_vector_count);
1357 entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
1360 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
1361 "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
1362 __LINE__, __func__));
1366 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
1369 r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
1371 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
1372 "failed (r=%d) !!!\n", ioc->name, r));
1377 ioc->msix_enable = 1;
1378 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
1379 r = _base_request_irq(ioc, i, a->vector);
1381 _base_free_irq(ioc);
1382 _base_disable_msix(ioc);
1391 /* failback to io_apic interrupt routing */
1394 r = _base_request_irq(ioc, 0, ioc->pdev->irq);
1400 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1401 * @ioc: per adapter object
1403 * Returns 0 for success, non-zero for failure.
1406 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1408 struct pci_dev *pdev = ioc->pdev;
1414 struct adapter_reply_queue *reply_q;
1416 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
1417 ioc->name, __func__));
1419 ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
1420 if (pci_enable_device_mem(pdev)) {
1421 printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
1422 "failed\n", ioc->name);
1427 if (pci_request_selected_regions(pdev, ioc->bars,
1428 MPT2SAS_DRIVER_NAME)) {
1429 printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
1430 "failed\n", ioc->name);
1435 /* AER (Advanced Error Reporting) hooks */
1436 pci_enable_pcie_error_reporting(pdev);
1438 pci_set_master(pdev);
1440 if (_base_config_dma_addressing(ioc, pdev) != 0) {
1441 printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
1442 ioc->name, pci_name(pdev));
1447 for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
1448 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1451 pio_chip = (u64)pci_resource_start(pdev, i);
1452 pio_sz = pci_resource_len(pdev, i);
1456 /* verify memory resource is valid before using */
1457 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
1458 ioc->chip_phys = pci_resource_start(pdev, i);
1459 chip_phys = (u64)ioc->chip_phys;
1460 memap_sz = pci_resource_len(pdev, i);
1461 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1462 if (ioc->chip == NULL) {
1463 printk(MPT2SAS_ERR_FMT "unable to map "
1464 "adapter memory!\n", ioc->name);
1472 _base_mask_interrupts(ioc);
1473 r = _base_enable_msix(ioc);
1477 list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
1478 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
1479 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
1480 "IO-APIC enabled"), reply_q->vector);
1482 printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1483 ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
1484 printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
1485 ioc->name, (unsigned long long)pio_chip, pio_sz);
1487 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1488 pci_save_state(pdev);
1496 pci_release_selected_regions(ioc->pdev, ioc->bars);
1497 pci_disable_pcie_error_reporting(pdev);
1498 pci_disable_device(pdev);
1503 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1504 * @ioc: per adapter object
1505 * @smid: system request message index(smid zero is invalid)
1507 * Returns virt pointer to message frame.
1510 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1512 return (void *)(ioc->request + (smid * ioc->request_sz));
1516 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1517 * @ioc: per adapter object
1518 * @smid: system request message index
1520 * Returns virt pointer to sense buffer.
1523 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1525 return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1529 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1530 * @ioc: per adapter object
1531 * @smid: system request message index
1533 * Returns phys pointer to the low 32bit address of the sense buffer.
1536 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1538 return cpu_to_le32(ioc->sense_dma +
1539 ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1543 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1544 * @ioc: per adapter object
1545 * @phys_addr: lower 32 physical addr of the reply
1547 * Converts 32bit lower physical addr into a virt address.
1550 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
1554 return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
1558 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1559 * @ioc: per adapter object
1560 * @cb_idx: callback index
1562 * Returns smid (zero is invalid)
1565 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1567 unsigned long flags;
1568 struct request_tracker *request;
1571 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1572 if (list_empty(&ioc->internal_free_list)) {
1573 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1574 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1575 ioc->name, __func__);
1579 request = list_entry(ioc->internal_free_list.next,
1580 struct request_tracker, tracker_list);
1581 request->cb_idx = cb_idx;
1582 smid = request->smid;
1583 list_del(&request->tracker_list);
1584 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1589 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1590 * @ioc: per adapter object
1591 * @cb_idx: callback index
1592 * @scmd: pointer to scsi command object
1594 * Returns smid (zero is invalid)
1597 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1598 struct scsi_cmnd *scmd)
1600 unsigned long flags;
1601 struct scsiio_tracker *request;
1604 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1605 if (list_empty(&ioc->free_list)) {
1606 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1607 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1608 ioc->name, __func__);
1612 request = list_entry(ioc->free_list.next,
1613 struct scsiio_tracker, tracker_list);
1614 request->scmd = scmd;
1615 request->cb_idx = cb_idx;
1616 smid = request->smid;
1617 list_del(&request->tracker_list);
1618 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1623 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1624 * @ioc: per adapter object
1625 * @cb_idx: callback index
1627 * Returns smid (zero is invalid)
1630 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1632 unsigned long flags;
1633 struct request_tracker *request;
1636 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1637 if (list_empty(&ioc->hpr_free_list)) {
1638 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1642 request = list_entry(ioc->hpr_free_list.next,
1643 struct request_tracker, tracker_list);
1644 request->cb_idx = cb_idx;
1645 smid = request->smid;
1646 list_del(&request->tracker_list);
1647 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1653 * mpt2sas_base_free_smid - put smid back on free_list
1654 * @ioc: per adapter object
1655 * @smid: system request message index
1660 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1662 unsigned long flags;
1664 struct chain_tracker *chain_req, *next;
1666 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1667 if (smid < ioc->hi_priority_smid) {
1670 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
1671 list_for_each_entry_safe(chain_req, next,
1672 &ioc->scsi_lookup[i].chain_list, tracker_list) {
1673 list_del_init(&chain_req->tracker_list);
1674 list_add_tail(&chain_req->tracker_list,
1675 &ioc->free_chain_list);
1678 ioc->scsi_lookup[i].cb_idx = 0xFF;
1679 ioc->scsi_lookup[i].scmd = NULL;
1680 ioc->scsi_lookup[i].direct_io = 0;
1681 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
1683 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1686 * See _wait_for_commands_to_complete() call with regards
1689 if (ioc->shost_recovery && ioc->pending_io_count) {
1690 if (ioc->pending_io_count == 1)
1691 wake_up(&ioc->reset_wq);
1692 ioc->pending_io_count--;
1695 } else if (smid < ioc->internal_smid) {
1697 i = smid - ioc->hi_priority_smid;
1698 ioc->hpr_lookup[i].cb_idx = 0xFF;
1699 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
1700 &ioc->hpr_free_list);
1701 } else if (smid <= ioc->hba_queue_depth) {
1702 /* internal queue */
1703 i = smid - ioc->internal_smid;
1704 ioc->internal_lookup[i].cb_idx = 0xFF;
1705 list_add_tail(&ioc->internal_lookup[i].tracker_list,
1706 &ioc->internal_free_list);
1708 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1712 * _base_writeq - 64 bit write to MMIO
1713 * @ioc: per adapter object
1715 * @addr: address in MMIO space
1716 * @writeq_lock: spin lock
1718 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1719 * care of 32 bit environment where its not quarenteed to send the entire word
1723 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1724 spinlock_t *writeq_lock)
1726 unsigned long flags;
1727 __u64 data_out = cpu_to_le64(b);
1729 spin_lock_irqsave(writeq_lock, flags);
1730 writel((u32)(data_out), addr);
1731 writel((u32)(data_out >> 32), (addr + 4));
1732 spin_unlock_irqrestore(writeq_lock, flags);
1735 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1736 spinlock_t *writeq_lock)
1738 writeq(cpu_to_le64(b), addr);
1743 _base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
1745 return ioc->cpu_msix_table[raw_smp_processor_id()];
1749 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1750 * @ioc: per adapter object
1751 * @smid: system request message index
1752 * @handle: device handle
1757 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
1759 Mpi2RequestDescriptorUnion_t descriptor;
1760 u64 *request = (u64 *)&descriptor;
1763 descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
1764 descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc);
1765 descriptor.SCSIIO.SMID = cpu_to_le16(smid);
1766 descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
1767 descriptor.SCSIIO.LMID = 0;
1768 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1769 &ioc->scsi_lookup_lock);
1774 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1775 * @ioc: per adapter object
1776 * @smid: system request message index
1781 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1783 Mpi2RequestDescriptorUnion_t descriptor;
1784 u64 *request = (u64 *)&descriptor;
1786 descriptor.HighPriority.RequestFlags =
1787 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
1788 descriptor.HighPriority.MSIxIndex = 0;
1789 descriptor.HighPriority.SMID = cpu_to_le16(smid);
1790 descriptor.HighPriority.LMID = 0;
1791 descriptor.HighPriority.Reserved1 = 0;
1792 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1793 &ioc->scsi_lookup_lock);
1797 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1798 * @ioc: per adapter object
1799 * @smid: system request message index
1804 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1806 Mpi2RequestDescriptorUnion_t descriptor;
1807 u64 *request = (u64 *)&descriptor;
1809 descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1810 descriptor.Default.MSIxIndex = _base_get_msix_index(ioc);
1811 descriptor.Default.SMID = cpu_to_le16(smid);
1812 descriptor.Default.LMID = 0;
1813 descriptor.Default.DescriptorTypeDependent = 0;
1814 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1815 &ioc->scsi_lookup_lock);
1819 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1820 * @ioc: per adapter object
1821 * @smid: system request message index
1822 * @io_index: value used to track the IO
1827 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1830 Mpi2RequestDescriptorUnion_t descriptor;
1831 u64 *request = (u64 *)&descriptor;
1833 descriptor.SCSITarget.RequestFlags =
1834 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
1835 descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc);
1836 descriptor.SCSITarget.SMID = cpu_to_le16(smid);
1837 descriptor.SCSITarget.LMID = 0;
1838 descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
1839 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1840 &ioc->scsi_lookup_lock);
1844 * _base_display_dell_branding - Disply branding string
1845 * @ioc: per adapter object
1850 _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1852 char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
1854 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
1857 memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
1858 switch (ioc->pdev->subsystem_device) {
1859 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
1860 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
1861 MPT2SAS_DELL_BRANDING_SIZE - 1);
1863 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
1864 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
1865 MPT2SAS_DELL_BRANDING_SIZE - 1);
1867 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
1868 strncpy(dell_branding,
1869 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
1870 MPT2SAS_DELL_BRANDING_SIZE - 1);
1872 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
1873 strncpy(dell_branding,
1874 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
1875 MPT2SAS_DELL_BRANDING_SIZE - 1);
1877 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
1878 strncpy(dell_branding,
1879 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
1880 MPT2SAS_DELL_BRANDING_SIZE - 1);
1882 case MPT2SAS_DELL_PERC_H200_SSDID:
1883 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
1884 MPT2SAS_DELL_BRANDING_SIZE - 1);
1886 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
1887 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
1888 MPT2SAS_DELL_BRANDING_SIZE - 1);
1891 sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
1895 printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
1896 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
1897 ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
1898 ioc->pdev->subsystem_device);
1902 * _base_display_intel_branding - Display branding string
1903 * @ioc: per adapter object
1908 _base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
1910 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1913 switch (ioc->pdev->device) {
1914 case MPI2_MFGPAGE_DEVID_SAS2008:
1915 switch (ioc->pdev->subsystem_device) {
1916 case MPT2SAS_INTEL_RMS2LL080_SSDID:
1917 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1918 MPT2SAS_INTEL_RMS2LL080_BRANDING);
1920 case MPT2SAS_INTEL_RMS2LL040_SSDID:
1921 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1922 MPT2SAS_INTEL_RMS2LL040_BRANDING);
1927 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1928 switch (ioc->pdev->subsystem_device) {
1929 case MPT2SAS_INTEL_RS25GB008_SSDID:
1930 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1931 MPT2SAS_INTEL_RS25GB008_BRANDING);
1942 * _base_display_hp_branding - Display branding string
1943 * @ioc: per adapter object
1948 _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
1950 if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
1953 switch (ioc->pdev->device) {
1954 case MPI2_MFGPAGE_DEVID_SAS2004:
1955 switch (ioc->pdev->subsystem_device) {
1956 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
1957 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1958 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
1963 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1964 switch (ioc->pdev->subsystem_device) {
1965 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
1966 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1967 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
1969 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
1970 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1971 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
1973 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
1974 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1975 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
1977 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
1978 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1979 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
1990 * _base_display_ioc_capabilities - Disply IOC's capabilities.
1991 * @ioc: per adapter object
1996 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
2001 u32 iounit_pg1_flags;
2004 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2005 pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
2006 strncpy(desc, ioc->manu_pg0.ChipName, 16);
2007 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
2008 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2010 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2011 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2012 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2013 ioc->facts.FWVersion.Word & 0x000000FF,
2015 (bios_version & 0xFF000000) >> 24,
2016 (bios_version & 0x00FF0000) >> 16,
2017 (bios_version & 0x0000FF00) >> 8,
2018 bios_version & 0x000000FF);
2020 _base_display_dell_branding(ioc);
2021 _base_display_intel_branding(ioc);
2022 _base_display_hp_branding(ioc);
2024 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
2026 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
2027 printk("Initiator");
2031 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
2032 printk("%sTarget", i ? "," : "");
2038 printk("Capabilities=(");
2040 if (!ioc->hide_ir_msg) {
2041 if (ioc->facts.IOCCapabilities &
2042 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2048 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
2049 printk("%sTLR", i ? "," : "");
2053 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
2054 printk("%sMulticast", i ? "," : "");
2058 if (ioc->facts.IOCCapabilities &
2059 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
2060 printk("%sBIDI Target", i ? "," : "");
2064 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
2065 printk("%sEEDP", i ? "," : "");
2069 if (ioc->facts.IOCCapabilities &
2070 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
2071 printk("%sSnapshot Buffer", i ? "," : "");
2075 if (ioc->facts.IOCCapabilities &
2076 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
2077 printk("%sDiag Trace Buffer", i ? "," : "");
2081 if (ioc->facts.IOCCapabilities &
2082 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
2083 printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
2087 if (ioc->facts.IOCCapabilities &
2088 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
2089 printk("%sTask Set Full", i ? "," : "");
2093 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2094 if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
2095 printk("%sNCQ", i ? "," : "");
2103 * mpt2sas_base_update_missing_delay - change the missing delay timers
2104 * @ioc: per adapter object
2105 * @device_missing_delay: amount of time till device is reported missing
2106 * @io_missing_delay: interval IO is returned when there is a missing device
2110 * Passed on the command line, this function will modify the device missing
2111 * delay, as well as the io missing delay. This should be called at driver
2115 mpt2sas_base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
2116 u16 device_missing_delay, u8 io_missing_delay)
2118 u16 dmd, dmd_new, dmd_orignal;
2119 u8 io_missing_delay_original;
2121 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
2122 Mpi2ConfigReply_t mpi_reply;
2126 mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
2130 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
2131 sizeof(Mpi2SasIOUnit1PhyData_t));
2132 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
2133 if (!sas_iounit_pg1) {
2134 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2135 ioc->name, __FILE__, __LINE__, __func__);
2138 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
2139 sas_iounit_pg1, sz))) {
2140 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2141 ioc->name, __FILE__, __LINE__, __func__);
2144 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2145 MPI2_IOCSTATUS_MASK;
2146 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2147 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2148 ioc->name, __FILE__, __LINE__, __func__);
2152 /* device missing delay */
2153 dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
2154 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2155 dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2157 dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2159 if (device_missing_delay > 0x7F) {
2160 dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
2161 device_missing_delay;
2163 dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
2165 dmd = device_missing_delay;
2166 sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
2168 /* io missing delay */
2169 io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
2170 sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
2172 if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
2174 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2176 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2179 dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2180 printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
2181 "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
2182 printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
2183 "new(%d)\n", ioc->name, io_missing_delay_original,
2185 ioc->device_missing_delay = dmd_new;
2186 ioc->io_missing_delay = io_missing_delay;
2190 kfree(sas_iounit_pg1);
2194 * _base_static_config_pages - static start of day config pages
2195 * @ioc: per adapter object
2200 _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
2202 Mpi2ConfigReply_t mpi_reply;
2203 u32 iounit_pg1_flags;
2205 mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
2206 if (ioc->ir_firmware)
2207 mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
2209 mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
2210 mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
2211 mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
2212 mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
2213 mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2214 _base_display_ioc_capabilities(ioc);
2217 * Enable task_set_full handling in iounit_pg1 when the
2218 * facts capabilities indicate that its supported.
2220 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2221 if ((ioc->facts.IOCCapabilities &
2222 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
2224 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2227 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2228 ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
2229 mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2234 * _base_release_memory_pools - release memory
2235 * @ioc: per adapter object
2237 * Free memory allocated from _base_allocate_memory_pools.
2242 _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
2246 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2250 pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
2251 ioc->request, ioc->request_dma);
2252 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
2253 ": free\n", ioc->name, ioc->request));
2254 ioc->request = NULL;
2258 pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
2259 if (ioc->sense_dma_pool)
2260 pci_pool_destroy(ioc->sense_dma_pool);
2261 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
2262 ": free\n", ioc->name, ioc->sense));
2267 pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
2268 if (ioc->reply_dma_pool)
2269 pci_pool_destroy(ioc->reply_dma_pool);
2270 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
2271 ": free\n", ioc->name, ioc->reply));
2275 if (ioc->reply_free) {
2276 pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
2277 ioc->reply_free_dma);
2278 if (ioc->reply_free_dma_pool)
2279 pci_pool_destroy(ioc->reply_free_dma_pool);
2280 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
2281 "(0x%p): free\n", ioc->name, ioc->reply_free));
2282 ioc->reply_free = NULL;
2285 if (ioc->reply_post_free) {
2286 pci_pool_free(ioc->reply_post_free_dma_pool,
2287 ioc->reply_post_free, ioc->reply_post_free_dma);
2288 if (ioc->reply_post_free_dma_pool)
2289 pci_pool_destroy(ioc->reply_post_free_dma_pool);
2290 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2291 "reply_post_free_pool(0x%p): free\n", ioc->name,
2292 ioc->reply_post_free));
2293 ioc->reply_post_free = NULL;
2296 if (ioc->config_page) {
2297 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2298 "config_page(0x%p): free\n", ioc->name,
2300 pci_free_consistent(ioc->pdev, ioc->config_page_sz,
2301 ioc->config_page, ioc->config_page_dma);
2304 if (ioc->scsi_lookup) {
2305 free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
2306 ioc->scsi_lookup = NULL;
2308 kfree(ioc->hpr_lookup);
2309 kfree(ioc->internal_lookup);
2310 if (ioc->chain_lookup) {
2311 for (i = 0; i < ioc->chain_depth; i++) {
2312 if (ioc->chain_lookup[i].chain_buffer)
2313 pci_pool_free(ioc->chain_dma_pool,
2314 ioc->chain_lookup[i].chain_buffer,
2315 ioc->chain_lookup[i].chain_buffer_dma);
2317 if (ioc->chain_dma_pool)
2318 pci_pool_destroy(ioc->chain_dma_pool);
2319 free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
2320 ioc->chain_lookup = NULL;
2326 * _base_allocate_memory_pools - allocate start of day memory pools
2327 * @ioc: per adapter object
2328 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2330 * Returns 0 success, anything else error
2333 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2335 struct mpt2sas_facts *facts;
2336 u16 max_sge_elements;
2337 u16 chains_needed_per_io;
2338 u32 sz, total_sz, reply_post_free_sz;
2340 u16 max_request_credit;
2343 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2347 facts = &ioc->facts;
2349 /* command line tunables for max sgl entries */
2350 if (max_sgl_entries != -1) {
2351 ioc->shost->sg_tablesize = (max_sgl_entries <
2352 MPT2SAS_SG_DEPTH) ? max_sgl_entries :
2355 ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
2358 /* command line tunables for max controller queue depth */
2359 if (max_queue_depth != -1 && max_queue_depth != 0) {
2360 max_request_credit = min_t(u16, max_queue_depth +
2361 ioc->hi_priority_depth + ioc->internal_depth,
2362 facts->RequestCredit);
2363 if (max_request_credit > MAX_HBA_QUEUE_DEPTH)
2364 max_request_credit = MAX_HBA_QUEUE_DEPTH;
2366 max_request_credit = min_t(u16, facts->RequestCredit,
2367 MAX_HBA_QUEUE_DEPTH);
2369 ioc->hba_queue_depth = max_request_credit;
2370 ioc->hi_priority_depth = facts->HighPriorityCredit;
2371 ioc->internal_depth = ioc->hi_priority_depth + 5;
2373 /* request frame size */
2374 ioc->request_sz = facts->IOCRequestFrameSize * 4;
2376 /* reply frame size */
2377 ioc->reply_sz = facts->ReplyFrameSize * 4;
2381 /* calculate number of sg elements left over in the 1st frame */
2382 max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
2383 sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
2384 ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
2386 /* now do the same for a chain buffer */
2387 max_sge_elements = ioc->request_sz - ioc->sge_size;
2388 ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
2390 ioc->chain_offset_value_for_main_message =
2391 ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
2392 (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
2395 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2397 chains_needed_per_io = ((ioc->shost->sg_tablesize -
2398 ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
2400 if (chains_needed_per_io > facts->MaxChainDepth) {
2401 chains_needed_per_io = facts->MaxChainDepth;
2402 ioc->shost->sg_tablesize = min_t(u16,
2403 ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
2404 * chains_needed_per_io), ioc->shost->sg_tablesize);
2406 ioc->chains_needed_per_io = chains_needed_per_io;
2408 /* reply free queue sizing - taking into account for 64 FW events */
2409 ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64;
2411 /* align the reply post queue on the next 16 count boundary */
2412 if (!ioc->reply_free_queue_depth % 16)
2413 ioc->reply_post_queue_depth = ioc->reply_free_queue_depth + 16;
2415 ioc->reply_post_queue_depth = ioc->reply_free_queue_depth +
2416 32 - (ioc->reply_free_queue_depth % 16);
2417 if (ioc->reply_post_queue_depth >
2418 facts->MaxReplyDescriptorPostQueueDepth) {
2419 ioc->reply_post_queue_depth = min_t(u16,
2420 (facts->MaxReplyDescriptorPostQueueDepth -
2421 (facts->MaxReplyDescriptorPostQueueDepth % 16)),
2422 (ioc->hba_queue_depth - (ioc->hba_queue_depth % 16)));
2423 ioc->reply_free_queue_depth = ioc->reply_post_queue_depth - 16;
2424 ioc->hba_queue_depth = ioc->reply_free_queue_depth - 64;
2428 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
2429 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2430 "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
2431 ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
2432 ioc->chains_needed_per_io));
2434 ioc->scsiio_depth = ioc->hba_queue_depth -
2435 ioc->hi_priority_depth - ioc->internal_depth;
2437 /* set the scsi host can_queue depth
2438 * with some internal commands that could be outstanding
2440 ioc->shost->can_queue = ioc->scsiio_depth;
2441 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2442 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2444 /* contiguous pool for request and chains, 16 byte align, one extra "
2447 ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
2448 sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
2450 /* hi-priority queue */
2451 sz += (ioc->hi_priority_depth * ioc->request_sz);
2453 /* internal queue */
2454 sz += (ioc->internal_depth * ioc->request_sz);
2456 ioc->request_dma_sz = sz;
2457 ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
2458 if (!ioc->request) {
2459 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2460 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2461 "total(%d kB)\n", ioc->name, ioc->hba_queue_depth,
2462 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2463 if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
2466 ioc->hba_queue_depth = max_request_credit - retry_sz;
2467 goto retry_allocation;
2471 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2472 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2473 "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
2474 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2477 /* hi-priority queue */
2478 ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
2480 ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
2483 /* internal queue */
2484 ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
2486 ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
2490 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
2491 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2492 ioc->request, ioc->hba_queue_depth, ioc->request_sz,
2493 (ioc->hba_queue_depth * ioc->request_sz)/1024));
2494 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
2495 ioc->name, (unsigned long long) ioc->request_dma));
2498 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
2499 ioc->scsi_lookup_pages = get_order(sz);
2500 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
2501 GFP_KERNEL, ioc->scsi_lookup_pages);
2502 if (!ioc->scsi_lookup) {
2503 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
2504 "sz(%d)\n", ioc->name, (int)sz);
2508 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
2509 "depth(%d)\n", ioc->name, ioc->request,
2510 ioc->scsiio_depth));
2512 ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH);
2513 sz = ioc->chain_depth * sizeof(struct chain_tracker);
2514 ioc->chain_pages = get_order(sz);
2516 ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
2517 GFP_KERNEL, ioc->chain_pages);
2518 ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
2519 ioc->request_sz, 16, 0);
2520 if (!ioc->chain_dma_pool) {
2521 printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
2522 "failed\n", ioc->name);
2525 for (i = 0; i < ioc->chain_depth; i++) {
2526 ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
2527 ioc->chain_dma_pool , GFP_KERNEL,
2528 &ioc->chain_lookup[i].chain_buffer_dma);
2529 if (!ioc->chain_lookup[i].chain_buffer) {
2530 ioc->chain_depth = i;
2533 total_sz += ioc->request_sz;
2536 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
2537 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2538 ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
2539 ioc->request_sz))/1024));
2541 /* initialize hi-priority queue smid's */
2542 ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
2543 sizeof(struct request_tracker), GFP_KERNEL);
2544 if (!ioc->hpr_lookup) {
2545 printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
2549 ioc->hi_priority_smid = ioc->scsiio_depth + 1;
2550 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
2551 "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
2552 ioc->hi_priority_depth, ioc->hi_priority_smid));
2554 /* initialize internal queue smid's */
2555 ioc->internal_lookup = kcalloc(ioc->internal_depth,
2556 sizeof(struct request_tracker), GFP_KERNEL);
2557 if (!ioc->internal_lookup) {
2558 printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
2562 ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
2563 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
2564 "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
2565 ioc->internal_depth, ioc->internal_smid));
2567 /* sense buffers, 4 byte align */
2568 sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
2569 ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
2571 if (!ioc->sense_dma_pool) {
2572 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
2576 ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
2579 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
2583 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
2584 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2585 "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
2586 SCSI_SENSE_BUFFERSIZE, sz/1024));
2587 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
2588 ioc->name, (unsigned long long)ioc->sense_dma));
2591 /* reply pool, 4 byte align */
2592 sz = ioc->reply_free_queue_depth * ioc->reply_sz;
2593 ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
2595 if (!ioc->reply_dma_pool) {
2596 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
2600 ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
2603 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
2607 ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
2608 ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
2609 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
2610 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
2611 ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
2612 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
2613 ioc->name, (unsigned long long)ioc->reply_dma));
2616 /* reply free queue, 16 byte align */
2617 sz = ioc->reply_free_queue_depth * 4;
2618 ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
2619 ioc->pdev, sz, 16, 0);
2620 if (!ioc->reply_free_dma_pool) {
2621 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
2622 "failed\n", ioc->name);
2625 ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
2626 &ioc->reply_free_dma);
2627 if (!ioc->reply_free) {
2628 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
2629 "failed\n", ioc->name);
2632 memset(ioc->reply_free, 0, sz);
2633 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
2634 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
2635 ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
2636 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
2637 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
2640 /* reply post queue, 16 byte align */
2641 reply_post_free_sz = ioc->reply_post_queue_depth *
2642 sizeof(Mpi2DefaultReplyDescriptor_t);
2643 if (_base_is_controller_msix_enabled(ioc))
2644 sz = reply_post_free_sz * ioc->reply_queue_count;
2646 sz = reply_post_free_sz;
2647 ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
2648 ioc->pdev, sz, 16, 0);
2649 if (!ioc->reply_post_free_dma_pool) {
2650 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
2651 "failed\n", ioc->name);
2654 ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
2655 GFP_KERNEL, &ioc->reply_post_free_dma);
2656 if (!ioc->reply_post_free) {
2657 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
2658 "failed\n", ioc->name);
2661 memset(ioc->reply_post_free, 0, sz);
2662 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
2663 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2664 ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
2666 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
2667 "(0x%llx)\n", ioc->name, (unsigned long long)
2668 ioc->reply_post_free_dma));
2671 ioc->config_page_sz = 512;
2672 ioc->config_page = pci_alloc_consistent(ioc->pdev,
2673 ioc->config_page_sz, &ioc->config_page_dma);
2674 if (!ioc->config_page) {
2675 printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
2676 "failed\n", ioc->name);
2679 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
2680 "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
2681 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
2682 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
2683 total_sz += ioc->config_page_sz;
2685 printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
2686 ioc->name, total_sz/1024);
2687 printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
2688 "Max Controller Queue Depth(%d)\n",
2689 ioc->name, ioc->shost->can_queue, facts->RequestCredit);
2690 printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
2691 ioc->name, ioc->shost->sg_tablesize);
2700 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2701 * @ioc: Pointer to MPT_ADAPTER structure
2702 * @cooked: Request raw or cooked IOC state
2704 * Returns all IOC Doorbell register bits if cooked==0, else just the
2705 * Doorbell bits in MPI_IOC_STATE_MASK.
2708 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
2712 s = readl(&ioc->chip->Doorbell);
2713 sc = s & MPI2_IOC_STATE_MASK;
2714 return cooked ? sc : s;
2718 * _base_wait_on_iocstate - waiting on a particular ioc state
2719 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2720 * @timeout: timeout in second
2721 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2723 * Returns 0 for success, non-zero for failure.
2726 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
2733 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2735 current_state = mpt2sas_base_get_iocstate(ioc, 1);
2736 if (current_state == ioc_state)
2738 if (count && current_state == MPI2_IOC_STATE_FAULT)
2740 if (sleep_flag == CAN_SLEEP)
2747 return current_state;
2751 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2752 * a write to the doorbell)
2753 * @ioc: per adapter object
2754 * @timeout: timeout in second
2755 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2757 * Returns 0 for success, non-zero for failure.
2759 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2762 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
2769 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2771 int_status = readl(&ioc->chip->HostInterruptStatus);
2772 if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2773 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2774 "successful count(%d), timeout(%d)\n", ioc->name,
2775 __func__, count, timeout));
2778 if (sleep_flag == CAN_SLEEP)
2785 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2786 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2791 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2792 * @ioc: per adapter object
2793 * @timeout: timeout in second
2794 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2796 * Returns 0 for success, non-zero for failure.
2798 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2802 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
2810 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2812 int_status = readl(&ioc->chip->HostInterruptStatus);
2813 if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
2814 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2815 "successful count(%d), timeout(%d)\n", ioc->name,
2816 __func__, count, timeout));
2818 } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2819 doorbell = readl(&ioc->chip->Doorbell);
2820 if ((doorbell & MPI2_IOC_STATE_MASK) ==
2821 MPI2_IOC_STATE_FAULT) {
2822 mpt2sas_base_fault_info(ioc , doorbell);
2825 } else if (int_status == 0xFFFFFFFF)
2828 if (sleep_flag == CAN_SLEEP)
2836 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2837 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2842 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2843 * @ioc: per adapter object
2844 * @timeout: timeout in second
2845 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2847 * Returns 0 for success, non-zero for failure.
2851 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
2858 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2860 doorbell_reg = readl(&ioc->chip->Doorbell);
2861 if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
2862 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2863 "successful count(%d), timeout(%d)\n", ioc->name,
2864 __func__, count, timeout));
2867 if (sleep_flag == CAN_SLEEP)
2874 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2875 "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
2880 * _base_send_ioc_reset - send doorbell reset
2881 * @ioc: per adapter object
2882 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2883 * @timeout: timeout in second
2884 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2886 * Returns 0 for success, non-zero for failure.
2889 _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
2895 if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
2896 printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
2897 ioc->name, __func__);
2901 if (!(ioc->facts.IOCCapabilities &
2902 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
2905 printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
2907 writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
2908 &ioc->chip->Doorbell);
2909 if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
2913 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
2914 timeout, sleep_flag);
2916 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
2917 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
2922 printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
2923 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
2928 * _base_handshake_req_reply_wait - send request thru doorbell interface
2929 * @ioc: per adapter object
2930 * @request_bytes: request length
2931 * @request: pointer having request payload
2932 * @reply_bytes: reply length
2933 * @reply: pointer to reply payload
2934 * @timeout: timeout in second
2935 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2937 * Returns 0 for success, non-zero for failure.
2940 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
2941 u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
2943 MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
2949 /* make sure doorbell is not in use */
2950 if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
2951 printk(MPT2SAS_ERR_FMT "doorbell is in use "
2952 " (line=%d)\n", ioc->name, __LINE__);
2956 /* clear pending doorbell interrupts from previous state changes */
2957 if (readl(&ioc->chip->HostInterruptStatus) &
2958 MPI2_HIS_IOC2SYS_DB_STATUS)
2959 writel(0, &ioc->chip->HostInterruptStatus);
2961 /* send message to ioc */
2962 writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
2963 ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
2964 &ioc->chip->Doorbell);
2966 if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
2967 printk(MPT2SAS_ERR_FMT "doorbell handshake "
2968 "int failed (line=%d)\n", ioc->name, __LINE__);
2971 writel(0, &ioc->chip->HostInterruptStatus);
2973 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
2974 printk(MPT2SAS_ERR_FMT "doorbell handshake "
2975 "ack failed (line=%d)\n", ioc->name, __LINE__);
2979 /* send message 32-bits at a time */
2980 for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
2981 writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
2982 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
2987 printk(MPT2SAS_ERR_FMT "doorbell handshake "
2988 "sending request failed (line=%d)\n", ioc->name, __LINE__);
2992 /* now wait for the reply */
2993 if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
2994 printk(MPT2SAS_ERR_FMT "doorbell handshake "
2995 "int failed (line=%d)\n", ioc->name, __LINE__);
2999 /* read the first two 16-bits, it gives the total length of the reply */
3000 reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3001 & MPI2_DOORBELL_DATA_MASK);
3002 writel(0, &ioc->chip->HostInterruptStatus);
3003 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3004 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3005 "int failed (line=%d)\n", ioc->name, __LINE__);
3008 reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3009 & MPI2_DOORBELL_DATA_MASK);
3010 writel(0, &ioc->chip->HostInterruptStatus);
3012 for (i = 2; i < default_reply->MsgLength * 2; i++) {
3013 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3014 printk(MPT2SAS_ERR_FMT "doorbell "
3015 "handshake int failed (line=%d)\n", ioc->name,
3019 if (i >= reply_bytes/2) /* overflow case */
3020 dummy = readl(&ioc->chip->Doorbell);
3022 reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3023 & MPI2_DOORBELL_DATA_MASK);
3024 writel(0, &ioc->chip->HostInterruptStatus);
3027 _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
3028 if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
3029 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
3030 " (line=%d)\n", ioc->name, __LINE__));
3032 writel(0, &ioc->chip->HostInterruptStatus);
3034 if (ioc->logging_level & MPT_DEBUG_INIT) {
3035 mfp = (__le32 *)reply;
3036 printk(KERN_INFO "\toffset:data\n");
3037 for (i = 0; i < reply_bytes/4; i++)
3038 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3039 le32_to_cpu(mfp[i]));
3045 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3046 * @ioc: per adapter object
3047 * @mpi_reply: the reply payload from FW
3048 * @mpi_request: the request payload sent to FW
3050 * The SAS IO Unit Control Request message allows the host to perform low-level
3051 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3052 * to obtain the IOC assigned device handles for a device if it has other
3053 * identifying information about the device, in addition allows the host to
3054 * remove IOC resources associated with the device.
3056 * Returns 0 for success, non-zero for failure.
3059 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
3060 Mpi2SasIoUnitControlReply_t *mpi_reply,
3061 Mpi2SasIoUnitControlRequest_t *mpi_request)
3065 unsigned long timeleft;
3069 u16 wait_state_count;
3071 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3074 mutex_lock(&ioc->base_cmds.mutex);
3076 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3077 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3078 ioc->name, __func__);
3083 wait_state_count = 0;
3084 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3085 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3086 if (wait_state_count++ == 10) {
3087 printk(MPT2SAS_ERR_FMT
3088 "%s: failed due to ioc not operational\n",
3089 ioc->name, __func__);
3094 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3095 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3096 "operational state(count=%d)\n", ioc->name,
3097 __func__, wait_state_count);
3100 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3102 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3103 ioc->name, __func__);
3109 ioc->base_cmds.status = MPT2_CMD_PENDING;
3110 request = mpt2sas_base_get_msg_frame(ioc, smid);
3111 ioc->base_cmds.smid = smid;
3112 memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
3113 if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3114 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
3115 ioc->ioc_link_reset_in_progress = 1;
3116 mpt2sas_base_put_smid_default(ioc, smid);
3117 init_completion(&ioc->base_cmds.done);
3118 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3119 msecs_to_jiffies(10000));
3120 if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3121 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
3122 ioc->ioc_link_reset_in_progress)
3123 ioc->ioc_link_reset_in_progress = 0;
3124 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3125 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3126 ioc->name, __func__);
3127 _debug_dump_mf(mpi_request,
3128 sizeof(Mpi2SasIoUnitControlRequest_t)/4);
3129 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3131 goto issue_host_reset;
3133 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3134 memcpy(mpi_reply, ioc->base_cmds.reply,
3135 sizeof(Mpi2SasIoUnitControlReply_t));
3137 memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
3138 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3143 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3145 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3148 mutex_unlock(&ioc->base_cmds.mutex);
3154 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3155 * @ioc: per adapter object
3156 * @mpi_reply: the reply payload from FW
3157 * @mpi_request: the request payload sent to FW
3159 * The SCSI Enclosure Processor request message causes the IOC to
3160 * communicate with SES devices to control LED status signals.
3162 * Returns 0 for success, non-zero for failure.
3165 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
3166 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
3170 unsigned long timeleft;
3174 u16 wait_state_count;
3176 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3179 mutex_lock(&ioc->base_cmds.mutex);
3181 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3182 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3183 ioc->name, __func__);
3188 wait_state_count = 0;
3189 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3190 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3191 if (wait_state_count++ == 10) {
3192 printk(MPT2SAS_ERR_FMT
3193 "%s: failed due to ioc not operational\n",
3194 ioc->name, __func__);
3199 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3200 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3201 "operational state(count=%d)\n", ioc->name,
3202 __func__, wait_state_count);
3205 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3207 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3208 ioc->name, __func__);
3214 ioc->base_cmds.status = MPT2_CMD_PENDING;
3215 request = mpt2sas_base_get_msg_frame(ioc, smid);
3216 ioc->base_cmds.smid = smid;
3217 memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
3218 mpt2sas_base_put_smid_default(ioc, smid);
3219 init_completion(&ioc->base_cmds.done);
3220 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3221 msecs_to_jiffies(10000));
3222 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3223 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3224 ioc->name, __func__);
3225 _debug_dump_mf(mpi_request,
3226 sizeof(Mpi2SepRequest_t)/4);
3227 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3229 goto issue_host_reset;
3231 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3232 memcpy(mpi_reply, ioc->base_cmds.reply,
3233 sizeof(Mpi2SepReply_t));
3235 memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
3236 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3241 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3243 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3246 mutex_unlock(&ioc->base_cmds.mutex);
3251 * _base_get_port_facts - obtain port facts reply and save in ioc
3252 * @ioc: per adapter object
3253 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3255 * Returns 0 for success, non-zero for failure.
3258 _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
3260 Mpi2PortFactsRequest_t mpi_request;
3261 Mpi2PortFactsReply_t mpi_reply;
3262 struct mpt2sas_port_facts *pfacts;
3263 int mpi_reply_sz, mpi_request_sz, r;
3265 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3268 mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
3269 mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
3270 memset(&mpi_request, 0, mpi_request_sz);
3271 mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
3272 mpi_request.PortNumber = port;
3273 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3274 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3277 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3278 ioc->name, __func__, r);
3282 pfacts = &ioc->pfacts[port];
3283 memset(pfacts, 0, sizeof(struct mpt2sas_port_facts));
3284 pfacts->PortNumber = mpi_reply.PortNumber;
3285 pfacts->VP_ID = mpi_reply.VP_ID;
3286 pfacts->VF_ID = mpi_reply.VF_ID;
3287 pfacts->MaxPostedCmdBuffers =
3288 le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
3294 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3295 * @ioc: per adapter object
3296 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3298 * Returns 0 for success, non-zero for failure.
3301 _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3303 Mpi2IOCFactsRequest_t mpi_request;
3304 Mpi2IOCFactsReply_t mpi_reply;
3305 struct mpt2sas_facts *facts;
3306 int mpi_reply_sz, mpi_request_sz, r;
3308 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3311 mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
3312 mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
3313 memset(&mpi_request, 0, mpi_request_sz);
3314 mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
3315 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3316 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3319 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3320 ioc->name, __func__, r);
3324 facts = &ioc->facts;
3325 memset(facts, 0, sizeof(struct mpt2sas_facts));
3326 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
3327 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
3328 facts->VP_ID = mpi_reply.VP_ID;
3329 facts->VF_ID = mpi_reply.VF_ID;
3330 facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
3331 facts->MaxChainDepth = mpi_reply.MaxChainDepth;
3332 facts->WhoInit = mpi_reply.WhoInit;
3333 facts->NumberOfPorts = mpi_reply.NumberOfPorts;
3334 facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
3335 facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
3336 facts->MaxReplyDescriptorPostQueueDepth =
3337 le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
3338 facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
3339 facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
3340 if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
3341 ioc->ir_firmware = 1;
3342 facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
3343 facts->IOCRequestFrameSize =
3344 le16_to_cpu(mpi_reply.IOCRequestFrameSize);
3345 facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
3346 facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
3347 ioc->shost->max_id = -1;
3348 facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
3349 facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
3350 facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
3351 facts->HighPriorityCredit =
3352 le16_to_cpu(mpi_reply.HighPriorityCredit);
3353 facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
3354 facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
3356 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
3357 "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
3358 facts->MaxChainDepth));
3359 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
3360 "reply frame size(%d)\n", ioc->name,
3361 facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
3366 * _base_send_ioc_init - send ioc_init to firmware
3367 * @ioc: per adapter object
3368 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3370 * Returns 0 for success, non-zero for failure.
3373 _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3375 Mpi2IOCInitRequest_t mpi_request;
3376 Mpi2IOCInitReply_t mpi_reply;
3378 struct timeval current_time;
3381 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3384 memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
3385 mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
3386 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
3387 mpi_request.VF_ID = 0; /* TODO */
3388 mpi_request.VP_ID = 0;
3389 mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
3390 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
3392 if (_base_is_controller_msix_enabled(ioc))
3393 mpi_request.HostMSIxVectors = ioc->reply_queue_count;
3394 mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
3395 mpi_request.ReplyDescriptorPostQueueDepth =
3396 cpu_to_le16(ioc->reply_post_queue_depth);
3397 mpi_request.ReplyFreeQueueDepth =
3398 cpu_to_le16(ioc->reply_free_queue_depth);
3400 mpi_request.SenseBufferAddressHigh =
3401 cpu_to_le32((u64)ioc->sense_dma >> 32);
3402 mpi_request.SystemReplyAddressHigh =
3403 cpu_to_le32((u64)ioc->reply_dma >> 32);
3404 mpi_request.SystemRequestFrameBaseAddress =
3405 cpu_to_le64((u64)ioc->request_dma);
3406 mpi_request.ReplyFreeQueueAddress =
3407 cpu_to_le64((u64)ioc->reply_free_dma);
3408 mpi_request.ReplyDescriptorPostQueueAddress =
3409 cpu_to_le64((u64)ioc->reply_post_free_dma);
3412 /* This time stamp specifies number of milliseconds
3413 * since epoch ~ midnight January 1, 1970.
3415 do_gettimeofday(¤t_time);
3416 mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
3417 (current_time.tv_usec / 1000));
3419 if (ioc->logging_level & MPT_DEBUG_INIT) {
3423 mfp = (__le32 *)&mpi_request;
3424 printk(KERN_INFO "\toffset:data\n");
3425 for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
3426 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3427 le32_to_cpu(mfp[i]));
3430 r = _base_handshake_req_reply_wait(ioc,
3431 sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
3432 sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
3436 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3437 ioc->name, __func__, r);
3441 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
3442 if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
3443 mpi_reply.IOCLogInfo) {
3444 printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
3452 * mpt2sas_port_enable_done - command completion routine for port enable
3453 * @ioc: per adapter object
3454 * @smid: system request message index
3455 * @msix_index: MSIX table index supplied by the OS
3456 * @reply: reply message frame(lower 32bit addr)
3458 * Return 1 meaning mf should be freed from _base_interrupt
3459 * 0 means the mf is freed from this function.
3462 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3465 MPI2DefaultReply_t *mpi_reply;
3468 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3469 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3472 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3475 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3477 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3478 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3479 mpi_reply->MsgLength*4);
3481 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3483 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3485 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3486 ioc->port_enable_failed = 1;
3488 if (ioc->is_driver_loading) {
3489 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3490 mpt2sas_port_enable_complete(ioc);
3493 ioc->start_scan_failed = ioc_status;
3494 ioc->start_scan = 0;
3498 complete(&ioc->port_enable_cmds.done);
3504 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3505 * @ioc: per adapter object
3506 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3508 * Returns 0 for success, non-zero for failure.
3511 _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3513 Mpi2PortEnableRequest_t *mpi_request;
3514 Mpi2PortEnableReply_t *mpi_reply;
3515 unsigned long timeleft;
3520 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3522 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3523 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3524 ioc->name, __func__);
3528 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3530 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3531 ioc->name, __func__);
3535 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3536 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3537 ioc->port_enable_cmds.smid = smid;
3538 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3539 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3541 init_completion(&ioc->port_enable_cmds.done);
3542 mpt2sas_base_put_smid_default(ioc, smid);
3543 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
3545 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
3546 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3547 ioc->name, __func__);
3548 _debug_dump_mf(mpi_request,
3549 sizeof(Mpi2PortEnableRequest_t)/4);
3550 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
3556 mpi_reply = ioc->port_enable_cmds.reply;
3558 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3559 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3560 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3561 ioc->name, __func__, ioc_status);
3566 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3567 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3568 "SUCCESS" : "FAILED"));
3573 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3574 * @ioc: per adapter object
3576 * Returns 0 for success, non-zero for failure.
3579 mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3581 Mpi2PortEnableRequest_t *mpi_request;
3584 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3586 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3587 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3588 ioc->name, __func__);
3592 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3594 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3595 ioc->name, __func__);
3599 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3600 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3601 ioc->port_enable_cmds.smid = smid;
3602 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3603 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3605 mpt2sas_base_put_smid_default(ioc, smid);
3610 * _base_determine_wait_on_discovery - desposition
3611 * @ioc: per adapter object
3613 * Decide whether to wait on discovery to complete. Used to either
3614 * locate boot device, or report volumes ahead of physical devices.
3616 * Returns 1 for wait, 0 for don't wait
3619 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3621 /* We wait for discovery to complete if IR firmware is loaded.
3622 * The sas topology events arrive before PD events, so we need time to
3623 * turn on the bit in ioc->pd_handles to indicate PD
3624 * Also, it maybe required to report Volumes ahead of physical
3625 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3627 if (ioc->ir_firmware)
3630 /* if no Bios, then we don't need to wait */
3631 if (!ioc->bios_pg3.BiosVersion)
3634 /* Bios is present, then we drop down here.
3636 * If there any entries in the Bios Page 2, then we wait
3637 * for discovery to complete.
3640 /* Current Boot Device */
3641 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3642 MPI2_BIOSPAGE2_FORM_MASK) ==
3643 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3644 /* Request Boot Device */
3645 (ioc->bios_pg2.ReqBootDeviceForm &
3646 MPI2_BIOSPAGE2_FORM_MASK) ==
3647 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3648 /* Alternate Request Boot Device */
3649 (ioc->bios_pg2.ReqAltBootDeviceForm &
3650 MPI2_BIOSPAGE2_FORM_MASK) ==
3651 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3659 * _base_unmask_events - turn on notification for this event
3660 * @ioc: per adapter object
3661 * @event: firmware event
3663 * The mask is stored in ioc->event_masks.
3666 _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
3673 desired_event = (1 << (event % 32));
3676 ioc->event_masks[0] &= ~desired_event;
3677 else if (event < 64)
3678 ioc->event_masks[1] &= ~desired_event;
3679 else if (event < 96)
3680 ioc->event_masks[2] &= ~desired_event;
3681 else if (event < 128)
3682 ioc->event_masks[3] &= ~desired_event;
3686 * _base_event_notification - send event notification
3687 * @ioc: per adapter object
3688 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3690 * Returns 0 for success, non-zero for failure.
3693 _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3695 Mpi2EventNotificationRequest_t *mpi_request;
3696 unsigned long timeleft;
3701 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3704 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
3705 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3706 ioc->name, __func__);
3710 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3712 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3713 ioc->name, __func__);
3716 ioc->base_cmds.status = MPT2_CMD_PENDING;
3717 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3718 ioc->base_cmds.smid = smid;
3719 memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
3720 mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
3721 mpi_request->VF_ID = 0; /* TODO */
3722 mpi_request->VP_ID = 0;
3723 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3724 mpi_request->EventMasks[i] =
3725 cpu_to_le32(ioc->event_masks[i]);
3726 mpt2sas_base_put_smid_default(ioc, smid);
3727 init_completion(&ioc->base_cmds.done);
3728 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
3729 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3730 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3731 ioc->name, __func__);
3732 _debug_dump_mf(mpi_request,
3733 sizeof(Mpi2EventNotificationRequest_t)/4);
3734 if (ioc->base_cmds.status & MPT2_CMD_RESET)
3739 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
3740 ioc->name, __func__));
3741 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3746 * mpt2sas_base_validate_event_type - validating event types
3747 * @ioc: per adapter object
3748 * @event: firmware event
3750 * This will turn on firmware event notification when application
3751 * ask for that event. We don't mask events that are already enabled.
3754 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
3757 u32 event_mask, desired_event;
3758 u8 send_update_to_fw;
3760 for (i = 0, send_update_to_fw = 0; i <
3761 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
3762 event_mask = ~event_type[i];
3764 for (j = 0; j < 32; j++) {
3765 if (!(event_mask & desired_event) &&
3766 (ioc->event_masks[i] & desired_event)) {
3767 ioc->event_masks[i] &= ~desired_event;
3768 send_update_to_fw = 1;
3770 desired_event = (desired_event << 1);
3774 if (!send_update_to_fw)
3777 mutex_lock(&ioc->base_cmds.mutex);
3778 _base_event_notification(ioc, CAN_SLEEP);
3779 mutex_unlock(&ioc->base_cmds.mutex);
3783 * _base_diag_reset - the "big hammer" start of day reset
3784 * @ioc: per adapter object
3785 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3787 * Returns 0 for success, non-zero for failure.
3790 _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3792 u32 host_diagnostic;
3797 printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
3798 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
3803 /* Write magic sequence to WriteSequence register
3804 * Loop until in diagnostic mode
3806 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
3807 "sequence\n", ioc->name));
3808 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3809 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
3810 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
3811 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
3812 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
3813 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
3814 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
3817 if (sleep_flag == CAN_SLEEP)
3825 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3826 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
3827 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3828 ioc->name, count, host_diagnostic));
3830 } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
3832 hcb_size = readl(&ioc->chip->HCBSize);
3834 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
3836 writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
3837 &ioc->chip->HostDiagnostic);
3839 /* don't access any registers for 50 milliseconds */
3842 /* 300 second max wait */
3843 for (count = 0; count < 3000000 ; count++) {
3845 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3847 if (host_diagnostic == 0xFFFFFFFF)
3849 if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
3853 if (sleep_flag == CAN_SLEEP)
3859 if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
3861 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
3862 "assuming the HCB Address points to good F/W\n",
3864 host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
3865 host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
3866 writel(host_diagnostic, &ioc->chip->HostDiagnostic);
3868 drsprintk(ioc, printk(MPT2SAS_INFO_FMT
3869 "re-enable the HCDW\n", ioc->name));
3870 writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
3871 &ioc->chip->HCBSize);
3874 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
3876 writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
3877 &ioc->chip->HostDiagnostic);
3879 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
3880 "diagnostic register\n", ioc->name));
3881 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3883 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
3884 "READY state\n", ioc->name));
3885 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
3888 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3889 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3893 printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
3897 printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
3902 * _base_make_ioc_ready - put controller in READY state
3903 * @ioc: per adapter object
3904 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3905 * @type: FORCE_BIG_HAMMER or SOFT_RESET
3907 * Returns 0 for success, non-zero for failure.
3910 _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
3911 enum reset_type type)
3916 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3919 if (ioc->pci_error_recovery)
3922 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
3923 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
3924 ioc->name, __func__, ioc_state));
3926 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
3929 if (ioc_state & MPI2_DOORBELL_USED) {
3930 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
3931 "active!\n", ioc->name));
3932 goto issue_diag_reset;
3935 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
3936 mpt2sas_base_fault_info(ioc, ioc_state &
3937 MPI2_DOORBELL_DATA_MASK);
3938 goto issue_diag_reset;
3941 if (type == FORCE_BIG_HAMMER)
3942 goto issue_diag_reset;
3944 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
3945 if (!(_base_send_ioc_reset(ioc,
3946 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
3947 ioc->ioc_reset_count++;
3952 rc = _base_diag_reset(ioc, CAN_SLEEP);
3953 ioc->ioc_reset_count++;
3958 * _base_make_ioc_operational - put controller in OPERATIONAL state
3959 * @ioc: per adapter object
3960 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3962 * Returns 0 for success, non-zero for failure.
3965 _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3968 unsigned long flags;
3971 struct _tr_list *delayed_tr, *delayed_tr_next;
3973 struct adapter_reply_queue *reply_q;
3974 long reply_post_free;
3975 u32 reply_post_free_sz;
3977 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3980 /* clean the delayed target reset list */
3981 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
3982 &ioc->delayed_tr_list, list) {
3983 list_del(&delayed_tr->list);
3987 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
3988 &ioc->delayed_tr_volume_list, list) {
3989 list_del(&delayed_tr->list);
3993 /* initialize the scsi lookup free list */
3994 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
3995 INIT_LIST_HEAD(&ioc->free_list);
3997 for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
3998 INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
3999 ioc->scsi_lookup[i].cb_idx = 0xFF;
4000 ioc->scsi_lookup[i].smid = smid;
4001 ioc->scsi_lookup[i].scmd = NULL;
4002 ioc->scsi_lookup[i].direct_io = 0;
4003 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4007 /* hi-priority queue */
4008 INIT_LIST_HEAD(&ioc->hpr_free_list);
4009 smid = ioc->hi_priority_smid;
4010 for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
4011 ioc->hpr_lookup[i].cb_idx = 0xFF;
4012 ioc->hpr_lookup[i].smid = smid;
4013 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
4014 &ioc->hpr_free_list);
4017 /* internal queue */
4018 INIT_LIST_HEAD(&ioc->internal_free_list);
4019 smid = ioc->internal_smid;
4020 for (i = 0; i < ioc->internal_depth; i++, smid++) {
4021 ioc->internal_lookup[i].cb_idx = 0xFF;
4022 ioc->internal_lookup[i].smid = smid;
4023 list_add_tail(&ioc->internal_lookup[i].tracker_list,
4024 &ioc->internal_free_list);
4028 INIT_LIST_HEAD(&ioc->free_chain_list);
4029 for (i = 0; i < ioc->chain_depth; i++)
4030 list_add_tail(&ioc->chain_lookup[i].tracker_list,
4031 &ioc->free_chain_list);
4033 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4035 /* initialize Reply Free Queue */
4036 for (i = 0, reply_address = (u32)ioc->reply_dma ;
4037 i < ioc->reply_free_queue_depth ; i++, reply_address +=
4039 ioc->reply_free[i] = cpu_to_le32(reply_address);
4041 /* initialize reply queues */
4042 if (ioc->is_driver_loading)
4043 _base_assign_reply_queues(ioc);
4045 /* initialize Reply Post Free Queue */
4046 reply_post_free = (long)ioc->reply_post_free;
4047 reply_post_free_sz = ioc->reply_post_queue_depth *
4048 sizeof(Mpi2DefaultReplyDescriptor_t);
4049 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4050 reply_q->reply_post_host_index = 0;
4051 reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
4053 for (i = 0; i < ioc->reply_post_queue_depth; i++)
4054 reply_q->reply_post_free[i].Words =
4055 cpu_to_le64(ULLONG_MAX);
4056 if (!_base_is_controller_msix_enabled(ioc))
4057 goto skip_init_reply_post_free_queue;
4058 reply_post_free += reply_post_free_sz;
4060 skip_init_reply_post_free_queue:
4062 r = _base_send_ioc_init(ioc, sleep_flag);
4066 /* initialize reply free host index */
4067 ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
4068 writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
4070 /* initialize reply post host index */
4071 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4072 writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
4073 &ioc->chip->ReplyPostHostIndex);
4074 if (!_base_is_controller_msix_enabled(ioc))
4075 goto skip_init_reply_post_host_index;
4078 skip_init_reply_post_host_index:
4080 _base_unmask_interrupts(ioc);
4082 r = _base_event_notification(ioc, sleep_flag);
4086 if (sleep_flag == CAN_SLEEP)
4087 _base_static_config_pages(ioc);
4090 if (ioc->is_driver_loading) {
4091 if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier
4093 hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 &
4094 MFG_PAGE10_HIDE_SSDS_MASK);
4095 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
4096 ioc->mfg_pg10_hide_flag = hide_flag;
4098 ioc->wait_for_discovery_to_complete =
4099 _base_determine_wait_on_discovery(ioc);
4100 return r; /* scan_start and scan_finished support */
4102 r = _base_send_port_enable(ioc, sleep_flag);
4110 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4111 * @ioc: per adapter object
4116 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
4118 struct pci_dev *pdev = ioc->pdev;
4120 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4123 _base_mask_interrupts(ioc);
4124 ioc->shost_recovery = 1;
4125 _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4126 ioc->shost_recovery = 0;
4127 _base_free_irq(ioc);
4128 _base_disable_msix(ioc);
4132 pci_release_selected_regions(ioc->pdev, ioc->bars);
4133 pci_disable_pcie_error_reporting(pdev);
4134 pci_disable_device(pdev);
4139 * mpt2sas_base_attach - attach controller instance
4140 * @ioc: per adapter object
4142 * Returns 0 for success, non-zero for failure.
4145 mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4148 int cpu_id, last_cpu_id = 0;
4150 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4153 /* setup cpu_msix_table */
4154 ioc->cpu_count = num_online_cpus();
4155 for_each_online_cpu(cpu_id)
4156 last_cpu_id = cpu_id;
4157 ioc->cpu_msix_table_sz = last_cpu_id + 1;
4158 ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
4159 ioc->reply_queue_count = 1;
4160 if (!ioc->cpu_msix_table) {
4161 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
4162 "cpu_msix_table failed!!!\n", ioc->name));
4164 goto out_free_resources;
4167 if (ioc->is_warpdrive) {
4168 ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
4169 sizeof(resource_size_t *), GFP_KERNEL);
4170 if (!ioc->reply_post_host_index) {
4171 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
4172 "for cpu_msix_table failed!!!\n", ioc->name));
4174 goto out_free_resources;
4178 r = mpt2sas_base_map_resources(ioc);
4182 if (ioc->is_warpdrive) {
4183 ioc->reply_post_host_index[0] =
4184 (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
4186 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
4187 ioc->reply_post_host_index[i] = (resource_size_t *)
4188 ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
4192 pci_set_drvdata(ioc->pdev, ioc->shost);
4193 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
4195 goto out_free_resources;
4197 r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4199 goto out_free_resources;
4201 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
4202 sizeof(struct mpt2sas_port_facts), GFP_KERNEL);
4205 goto out_free_resources;
4208 for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
4209 r = _base_get_port_facts(ioc, i, CAN_SLEEP);
4211 goto out_free_resources;
4214 r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
4216 goto out_free_resources;
4218 init_waitqueue_head(&ioc->reset_wq);
4220 /* allocate memory pd handle bitmask list */
4221 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
4222 if (ioc->facts.MaxDevHandle % 8)
4223 ioc->pd_handles_sz++;
4224 ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
4226 if (!ioc->pd_handles) {
4228 goto out_free_resources;
4231 ioc->fwfault_debug = mpt2sas_fwfault_debug;
4233 /* base internal command bits */
4234 mutex_init(&ioc->base_cmds.mutex);
4235 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4236 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4238 /* port_enable command bits */
4239 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4240 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4242 /* transport internal command bits */
4243 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4244 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
4245 mutex_init(&ioc->transport_cmds.mutex);
4247 /* scsih internal command bits */
4248 ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4249 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
4250 mutex_init(&ioc->scsih_cmds.mutex);
4252 /* task management internal command bits */
4253 ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4254 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4255 mutex_init(&ioc->tm_cmds.mutex);
4257 /* config page internal command bits */
4258 ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4259 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
4260 mutex_init(&ioc->config_cmds.mutex);
4262 /* ctl module internal command bits */
4263 ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4264 ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
4265 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
4266 mutex_init(&ioc->ctl_cmds.mutex);
4268 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4269 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4270 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
4271 !ioc->ctl_cmds.sense) {
4273 goto out_free_resources;
4276 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4277 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4278 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
4280 goto out_free_resources;
4283 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4284 ioc->event_masks[i] = -1;
4286 /* here we enable the events we care about */
4287 _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
4288 _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
4289 _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
4290 _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4291 _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
4292 _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
4293 _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
4294 _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
4295 _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
4296 _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
4297 r = _base_make_ioc_operational(ioc, CAN_SLEEP);
4299 goto out_free_resources;
4306 ioc->remove_host = 1;
4307 mpt2sas_base_free_resources(ioc);
4308 _base_release_memory_pools(ioc);
4309 pci_set_drvdata(ioc->pdev, NULL);
4310 kfree(ioc->cpu_msix_table);
4311 if (ioc->is_warpdrive)
4312 kfree(ioc->reply_post_host_index);
4313 kfree(ioc->pd_handles);
4314 kfree(ioc->tm_cmds.reply);
4315 kfree(ioc->transport_cmds.reply);
4316 kfree(ioc->scsih_cmds.reply);
4317 kfree(ioc->config_cmds.reply);
4318 kfree(ioc->base_cmds.reply);
4319 kfree(ioc->port_enable_cmds.reply);
4320 kfree(ioc->ctl_cmds.reply);
4321 kfree(ioc->ctl_cmds.sense);
4323 ioc->ctl_cmds.reply = NULL;
4324 ioc->base_cmds.reply = NULL;
4325 ioc->tm_cmds.reply = NULL;
4326 ioc->scsih_cmds.reply = NULL;
4327 ioc->transport_cmds.reply = NULL;
4328 ioc->config_cmds.reply = NULL;
4335 * mpt2sas_base_detach - remove controller instance
4336 * @ioc: per adapter object
4341 mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4344 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4347 mpt2sas_base_stop_watchdog(ioc);
4348 mpt2sas_base_free_resources(ioc);
4349 _base_release_memory_pools(ioc);
4350 pci_set_drvdata(ioc->pdev, NULL);
4351 kfree(ioc->cpu_msix_table);
4352 if (ioc->is_warpdrive)
4353 kfree(ioc->reply_post_host_index);
4354 kfree(ioc->pd_handles);
4356 kfree(ioc->ctl_cmds.reply);
4357 kfree(ioc->ctl_cmds.sense);
4358 kfree(ioc->base_cmds.reply);
4359 kfree(ioc->port_enable_cmds.reply);
4360 kfree(ioc->tm_cmds.reply);
4361 kfree(ioc->transport_cmds.reply);
4362 kfree(ioc->scsih_cmds.reply);
4363 kfree(ioc->config_cmds.reply);
4367 * _base_reset_handler - reset callback handler (for base)
4368 * @ioc: per adapter object
4369 * @reset_phase: phase
4371 * The handler for doing any required cleanup or initialization.
4373 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4374 * MPT2_IOC_DONE_RESET
4379 _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4381 mpt2sas_scsih_reset_handler(ioc, reset_phase);
4382 mpt2sas_ctl_reset_handler(ioc, reset_phase);
4383 switch (reset_phase) {
4384 case MPT2_IOC_PRE_RESET:
4385 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4386 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
4388 case MPT2_IOC_AFTER_RESET:
4389 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4390 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
4391 if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
4392 ioc->transport_cmds.status |= MPT2_CMD_RESET;
4393 mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
4394 complete(&ioc->transport_cmds.done);
4396 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
4397 ioc->base_cmds.status |= MPT2_CMD_RESET;
4398 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4399 complete(&ioc->base_cmds.done);
4401 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4402 ioc->port_enable_failed = 1;
4403 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4404 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4405 if (ioc->is_driver_loading) {
4406 ioc->start_scan_failed =
4407 MPI2_IOCSTATUS_INTERNAL_ERROR;
4408 ioc->start_scan = 0;
4409 ioc->port_enable_cmds.status =
4412 complete(&ioc->port_enable_cmds.done);
4415 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4416 ioc->config_cmds.status |= MPT2_CMD_RESET;
4417 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
4418 ioc->config_cmds.smid = USHRT_MAX;
4419 complete(&ioc->config_cmds.done);
4422 case MPT2_IOC_DONE_RESET:
4423 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4424 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
4430 * _wait_for_commands_to_complete - reset controller
4431 * @ioc: Pointer to MPT_ADAPTER structure
4432 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4434 * This function waiting(3s) for all pending commands to complete
4435 * prior to putting controller in reset.
4438 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4441 unsigned long flags;
4444 ioc->pending_io_count = 0;
4445 if (sleep_flag != CAN_SLEEP)
4448 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4449 if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
4452 /* pending command count */
4453 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4454 for (i = 0; i < ioc->scsiio_depth; i++)
4455 if (ioc->scsi_lookup[i].cb_idx != 0xFF)
4456 ioc->pending_io_count++;
4457 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4459 if (!ioc->pending_io_count)
4462 /* wait for pending commands to complete */
4463 wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
4467 * mpt2sas_base_hard_reset_handler - reset controller
4468 * @ioc: Pointer to MPT_ADAPTER structure
4469 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4470 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4472 * Returns 0 for success, non-zero for failure.
4475 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4476 enum reset_type type)
4479 unsigned long flags;
4481 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
4484 if (ioc->pci_error_recovery) {
4485 printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
4486 ioc->name, __func__);
4491 if (mpt2sas_fwfault_debug)
4492 mpt2sas_halt_firmware(ioc);
4494 /* TODO - What we really should be doing is pulling
4495 * out all the code associated with NO_SLEEP; its never used.
4496 * That is legacy code from mpt fusion driver, ported over.
4497 * I will leave this BUG_ON here for now till its been resolved.
4499 BUG_ON(sleep_flag == NO_SLEEP);
4501 /* wait for an active reset in progress to complete */
4502 if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
4505 } while (ioc->shost_recovery == 1);
4506 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
4508 return ioc->ioc_reset_in_progress_status;
4511 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4512 ioc->shost_recovery = 1;
4513 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4515 _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
4516 _wait_for_commands_to_complete(ioc, sleep_flag);
4517 _base_mask_interrupts(ioc);
4518 r = _base_make_ioc_ready(ioc, sleep_flag, type);
4521 _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
4523 /* If this hard reset is called while port enable is active, then
4524 * there is no reason to call make_ioc_operational
4526 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4527 ioc->remove_host = 1;
4531 r = _base_make_ioc_operational(ioc, sleep_flag);
4533 _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
4535 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
4536 ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
4538 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4539 ioc->ioc_reset_in_progress_status = r;
4540 ioc->shost_recovery = 0;
4541 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4542 mutex_unlock(&ioc->reset_in_progress_mutex);
4544 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,