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 static int max_queue_depth = -1;
69 module_param(max_queue_depth, int, 0);
70 MODULE_PARM_DESC(max_queue_depth, " max controller queue depth ");
72 static int max_sgl_entries = -1;
73 module_param(max_sgl_entries, int, 0);
74 MODULE_PARM_DESC(max_sgl_entries, " max sg entries ");
76 static int msix_disable = -1;
77 module_param(msix_disable, int, 0);
78 MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)");
80 static int missing_delay[2] = {-1, -1};
81 module_param_array(missing_delay, int, NULL, 0);
82 MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
84 static int mpt2sas_fwfault_debug;
85 MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
86 "and halt firmware - (default=0)");
88 static int disable_discovery = -1;
89 module_param(disable_discovery, int, 0);
90 MODULE_PARM_DESC(disable_discovery, " disable discovery ");
93 /* diag_buffer_enable is bitwise
95 * bit 1 set = SNAPSHOT
96 * bit 2 set = EXTENDED
98 * Either bit can be set, or both
100 static int diag_buffer_enable;
101 module_param(diag_buffer_enable, int, 0);
102 MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
103 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
106 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
110 _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
112 int ret = param_set_int(val, kp);
113 struct MPT2SAS_ADAPTER *ioc;
118 printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
119 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
120 ioc->fwfault_debug = mpt2sas_fwfault_debug;
123 module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug,
124 param_get_int, &mpt2sas_fwfault_debug, 0644);
127 * _base_fault_reset_work - workq handling ioc fault conditions
128 * @work: input argument, used to derive ioc
134 _base_fault_reset_work(struct work_struct *work)
136 struct MPT2SAS_ADAPTER *ioc =
137 container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
142 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
143 if (ioc->shost_recovery)
145 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
147 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
148 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
149 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
151 printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
152 __func__, (rc == 0) ? "success" : "failed");
153 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
154 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
155 mpt2sas_base_fault_info(ioc, doorbell &
156 MPI2_DOORBELL_DATA_MASK);
159 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
161 if (ioc->fault_reset_work_q)
162 queue_delayed_work(ioc->fault_reset_work_q,
163 &ioc->fault_reset_work,
164 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
165 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
169 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
170 * @ioc: per adapter object
176 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
180 if (ioc->fault_reset_work_q)
183 /* initialize fault polling */
184 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
185 snprintf(ioc->fault_reset_work_q_name,
186 sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
187 ioc->fault_reset_work_q =
188 create_singlethread_workqueue(ioc->fault_reset_work_q_name);
189 if (!ioc->fault_reset_work_q) {
190 printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
191 ioc->name, __func__, __LINE__);
194 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
195 if (ioc->fault_reset_work_q)
196 queue_delayed_work(ioc->fault_reset_work_q,
197 &ioc->fault_reset_work,
198 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
199 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
203 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
204 * @ioc: per adapter object
210 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
213 struct workqueue_struct *wq;
215 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
216 wq = ioc->fault_reset_work_q;
217 ioc->fault_reset_work_q = NULL;
218 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
220 if (!cancel_delayed_work(&ioc->fault_reset_work))
222 destroy_workqueue(wq);
227 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
228 * @ioc: per adapter object
229 * @fault_code: fault code
234 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
236 printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
237 ioc->name, fault_code);
241 * mpt2sas_halt_firmware - halt's mpt controller firmware
242 * @ioc: per adapter object
244 * For debugging timeout related issues. Writing 0xCOFFEE00
245 * to the doorbell register will halt controller firmware. With
246 * the purpose to stop both driver and firmware, the enduser can
247 * obtain a ring buffer from controller UART.
250 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc)
254 if (!ioc->fwfault_debug)
259 doorbell = readl(&ioc->chip->Doorbell);
260 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
261 mpt2sas_base_fault_info(ioc , doorbell);
263 writel(0xC0FFEE00, &ioc->chip->Doorbell);
264 printk(MPT2SAS_ERR_FMT "Firmware is halted due to command "
265 "timeout\n", ioc->name);
268 panic("panic in %s\n", __func__);
271 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
273 * _base_sas_ioc_info - verbose translation of the ioc status
274 * @ioc: per adapter object
275 * @mpi_reply: reply mf payload returned from firmware
276 * @request_hdr: request mf
281 _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
282 MPI2RequestHeader_t *request_hdr)
284 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
288 char *func_str = NULL;
290 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
291 if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
292 request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
293 request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
296 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
299 switch (ioc_status) {
301 /****************************************************************************
302 * Common IOCStatus values for all replies
303 ****************************************************************************/
305 case MPI2_IOCSTATUS_INVALID_FUNCTION:
306 desc = "invalid function";
308 case MPI2_IOCSTATUS_BUSY:
311 case MPI2_IOCSTATUS_INVALID_SGL:
312 desc = "invalid sgl";
314 case MPI2_IOCSTATUS_INTERNAL_ERROR:
315 desc = "internal error";
317 case MPI2_IOCSTATUS_INVALID_VPID:
318 desc = "invalid vpid";
320 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
321 desc = "insufficient resources";
323 case MPI2_IOCSTATUS_INVALID_FIELD:
324 desc = "invalid field";
326 case MPI2_IOCSTATUS_INVALID_STATE:
327 desc = "invalid state";
329 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
330 desc = "op state not supported";
333 /****************************************************************************
334 * Config IOCStatus values
335 ****************************************************************************/
337 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
338 desc = "config invalid action";
340 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
341 desc = "config invalid type";
343 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
344 desc = "config invalid page";
346 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
347 desc = "config invalid data";
349 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
350 desc = "config no defaults";
352 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
353 desc = "config cant commit";
356 /****************************************************************************
358 ****************************************************************************/
360 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
361 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
362 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
363 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
364 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
365 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
366 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
367 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
368 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
369 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
370 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
371 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
374 /****************************************************************************
375 * For use by SCSI Initiator and SCSI Target end-to-end data protection
376 ****************************************************************************/
378 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
379 desc = "eedp guard error";
381 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
382 desc = "eedp ref tag error";
384 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
385 desc = "eedp app tag error";
388 /****************************************************************************
390 ****************************************************************************/
392 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
393 desc = "target invalid io index";
395 case MPI2_IOCSTATUS_TARGET_ABORTED:
396 desc = "target aborted";
398 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
399 desc = "target no conn retryable";
401 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
402 desc = "target no connection";
404 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
405 desc = "target xfer count mismatch";
407 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
408 desc = "target data offset error";
410 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
411 desc = "target too much write data";
413 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
414 desc = "target iu too short";
416 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
417 desc = "target ack nak timeout";
419 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
420 desc = "target nak received";
423 /****************************************************************************
424 * Serial Attached SCSI values
425 ****************************************************************************/
427 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
428 desc = "smp request failed";
430 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
431 desc = "smp data overrun";
434 /****************************************************************************
435 * Diagnostic Buffer Post / Diagnostic Release values
436 ****************************************************************************/
438 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
439 desc = "diagnostic released";
448 switch (request_hdr->Function) {
449 case MPI2_FUNCTION_CONFIG:
450 frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
451 func_str = "config_page";
453 case MPI2_FUNCTION_SCSI_TASK_MGMT:
454 frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
455 func_str = "task_mgmt";
457 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
458 frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
459 func_str = "sas_iounit_ctl";
461 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
462 frame_sz = sizeof(Mpi2SepRequest_t);
463 func_str = "enclosure";
465 case MPI2_FUNCTION_IOC_INIT:
466 frame_sz = sizeof(Mpi2IOCInitRequest_t);
467 func_str = "ioc_init";
469 case MPI2_FUNCTION_PORT_ENABLE:
470 frame_sz = sizeof(Mpi2PortEnableRequest_t);
471 func_str = "port_enable";
473 case MPI2_FUNCTION_SMP_PASSTHROUGH:
474 frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
475 func_str = "smp_passthru";
479 func_str = "unknown";
483 printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
484 " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
486 _debug_dump_mf(request_hdr, frame_sz/4);
490 * _base_display_event_data - verbose translation of firmware asyn events
491 * @ioc: per adapter object
492 * @mpi_reply: reply mf payload returned from firmware
497 _base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
498 Mpi2EventNotificationReply_t *mpi_reply)
503 if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
506 event = le16_to_cpu(mpi_reply->Event);
509 case MPI2_EVENT_LOG_DATA:
512 case MPI2_EVENT_STATE_CHANGE:
513 desc = "Status Change";
515 case MPI2_EVENT_HARD_RESET_RECEIVED:
516 desc = "Hard Reset Received";
518 case MPI2_EVENT_EVENT_CHANGE:
519 desc = "Event Change";
521 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
522 desc = "Device Status Change";
524 case MPI2_EVENT_IR_OPERATION_STATUS:
525 if (!ioc->hide_ir_msg)
526 desc = "IR Operation Status";
528 case MPI2_EVENT_SAS_DISCOVERY:
530 Mpi2EventDataSasDiscovery_t *event_data =
531 (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData;
532 printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name,
533 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
535 if (event_data->DiscoveryStatus)
536 printk("discovery_status(0x%08x)",
537 le32_to_cpu(event_data->DiscoveryStatus));
541 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
542 desc = "SAS Broadcast Primitive";
544 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
545 desc = "SAS Init Device Status Change";
547 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
548 desc = "SAS Init Table Overflow";
550 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
551 desc = "SAS Topology Change List";
553 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
554 desc = "SAS Enclosure Device Status Change";
556 case MPI2_EVENT_IR_VOLUME:
557 if (!ioc->hide_ir_msg)
560 case MPI2_EVENT_IR_PHYSICAL_DISK:
561 if (!ioc->hide_ir_msg)
562 desc = "IR Physical Disk";
564 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
565 if (!ioc->hide_ir_msg)
566 desc = "IR Configuration Change List";
568 case MPI2_EVENT_LOG_ENTRY_ADDED:
569 if (!ioc->hide_ir_msg)
570 desc = "Log Entry Added";
577 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
582 * _base_sas_log_info - verbose translation of firmware log info
583 * @ioc: per adapter object
584 * @log_info: log info
589 _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
600 union loginfo_type sas_loginfo;
601 char *originator_str = NULL;
603 sas_loginfo.loginfo = log_info;
604 if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
607 /* each nexus loss loginfo */
608 if (log_info == 0x31170000)
611 /* eat the loginfos associated with task aborts */
612 if (ioc->ignore_loginfos && (log_info == 30050000 || log_info ==
613 0x31140000 || log_info == 0x31130000))
616 switch (sas_loginfo.dw.originator) {
618 originator_str = "IOP";
621 originator_str = "PL";
624 if (!ioc->hide_ir_msg)
625 originator_str = "IR";
627 originator_str = "WarpDrive";
631 printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
632 "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
633 originator_str, sas_loginfo.dw.code,
634 sas_loginfo.dw.subcode);
638 * _base_display_reply_info -
639 * @ioc: per adapter object
640 * @smid: system request message index
641 * @msix_index: MSIX table index supplied by the OS
642 * @reply: reply message frame(lower 32bit addr)
647 _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
650 MPI2DefaultReply_t *mpi_reply;
653 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
654 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
655 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
656 if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
657 (ioc->logging_level & MPT_DEBUG_REPLY)) {
658 _base_sas_ioc_info(ioc , mpi_reply,
659 mpt2sas_base_get_msg_frame(ioc, smid));
662 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
663 _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
667 * mpt2sas_base_done - base internal command completion routine
668 * @ioc: per adapter object
669 * @smid: system request message index
670 * @msix_index: MSIX table index supplied by the OS
671 * @reply: reply message frame(lower 32bit addr)
673 * Return 1 meaning mf should be freed from _base_interrupt
674 * 0 means the mf is freed from this function.
677 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
680 MPI2DefaultReply_t *mpi_reply;
682 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
683 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
686 if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
689 ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
691 ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
692 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
694 ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
696 complete(&ioc->base_cmds.done);
701 * _base_async_event - main callback handler for firmware asyn events
702 * @ioc: per adapter object
703 * @msix_index: MSIX table index supplied by the OS
704 * @reply: reply message frame(lower 32bit addr)
706 * Return 1 meaning mf should be freed from _base_interrupt
707 * 0 means the mf is freed from this function.
710 _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
712 Mpi2EventNotificationReply_t *mpi_reply;
713 Mpi2EventAckRequest_t *ack_request;
716 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
719 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
721 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
722 _base_display_event_data(ioc, mpi_reply);
724 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
726 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
728 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
729 ioc->name, __func__);
733 ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
734 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
735 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
736 ack_request->Event = mpi_reply->Event;
737 ack_request->EventContext = mpi_reply->EventContext;
738 ack_request->VF_ID = 0; /* TODO */
739 ack_request->VP_ID = 0;
740 mpt2sas_base_put_smid_default(ioc, smid);
744 /* scsih callback handler */
745 mpt2sas_scsih_event_callback(ioc, msix_index, reply);
747 /* ctl callback handler */
748 mpt2sas_ctl_event_callback(ioc, msix_index, reply);
754 * _base_get_cb_idx - obtain the callback index
755 * @ioc: per adapter object
756 * @smid: system request message index
758 * Return callback index.
761 _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
766 if (smid < ioc->hi_priority_smid) {
768 cb_idx = ioc->scsi_lookup[i].cb_idx;
769 } else if (smid < ioc->internal_smid) {
770 i = smid - ioc->hi_priority_smid;
771 cb_idx = ioc->hpr_lookup[i].cb_idx;
772 } else if (smid <= ioc->hba_queue_depth) {
773 i = smid - ioc->internal_smid;
774 cb_idx = ioc->internal_lookup[i].cb_idx;
781 * _base_mask_interrupts - disable interrupts
782 * @ioc: per adapter object
784 * Disabling ResetIRQ, Reply and Doorbell Interrupts
789 _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
793 ioc->mask_interrupts = 1;
794 him_register = readl(&ioc->chip->HostInterruptMask);
795 him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
796 writel(him_register, &ioc->chip->HostInterruptMask);
797 readl(&ioc->chip->HostInterruptMask);
801 * _base_unmask_interrupts - enable interrupts
802 * @ioc: per adapter object
804 * Enabling only Reply Interrupts
809 _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
813 him_register = readl(&ioc->chip->HostInterruptMask);
814 him_register &= ~MPI2_HIM_RIM;
815 writel(him_register, &ioc->chip->HostInterruptMask);
816 ioc->mask_interrupts = 0;
819 union reply_descriptor {
828 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
829 * @irq: irq number (not used)
830 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
831 * @r: pt_regs pointer (not used)
833 * Return IRQ_HANDLE if processed, else IRQ_NONE.
836 _base_interrupt(int irq, void *bus_id)
838 struct adapter_reply_queue *reply_q = bus_id;
839 union reply_descriptor rd;
841 u8 request_desript_type;
845 u8 msix_index = reply_q->msix_index;
846 struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
847 Mpi2ReplyDescriptorsUnion_t *rpf;
850 if (ioc->mask_interrupts)
853 if (!atomic_add_unless(&reply_q->busy, 1, 1))
856 rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
857 request_desript_type = rpf->Default.ReplyFlags
858 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
859 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
860 atomic_dec(&reply_q->busy);
867 rd.word = le64_to_cpu(rpf->Words);
868 if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
871 smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
872 if (request_desript_type ==
873 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
875 (rpf->AddressReply.ReplyFrameAddress);
876 if (reply > ioc->reply_dma_max_address ||
877 reply < ioc->reply_dma_min_address)
879 } else if (request_desript_type ==
880 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
882 else if (request_desript_type ==
883 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
886 cb_idx = _base_get_cb_idx(ioc, smid);
887 if (smid && cb_idx != 0xFF) {
888 rc = mpt_callbacks[cb_idx](ioc, smid, msix_index,
891 _base_display_reply_info(ioc, smid, msix_index,
894 mpt2sas_base_free_smid(ioc, smid);
897 _base_async_event(ioc, msix_index, reply);
899 /* reply free queue handling */
901 ioc->reply_free_host_index =
902 (ioc->reply_free_host_index ==
903 (ioc->reply_free_queue_depth - 1)) ?
904 0 : ioc->reply_free_host_index + 1;
905 ioc->reply_free[ioc->reply_free_host_index] =
908 writel(ioc->reply_free_host_index,
909 &ioc->chip->ReplyFreeHostIndex);
914 rpf->Words = cpu_to_le64(ULLONG_MAX);
915 reply_q->reply_post_host_index =
916 (reply_q->reply_post_host_index ==
917 (ioc->reply_post_queue_depth - 1)) ? 0 :
918 reply_q->reply_post_host_index + 1;
919 request_desript_type =
920 reply_q->reply_post_free[reply_q->reply_post_host_index].
921 Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
923 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
925 if (!reply_q->reply_post_host_index)
926 rpf = reply_q->reply_post_free;
933 if (!completed_cmds) {
934 atomic_dec(&reply_q->busy);
938 if (ioc->is_warpdrive) {
939 writel(reply_q->reply_post_host_index,
940 ioc->reply_post_host_index[msix_index]);
941 atomic_dec(&reply_q->busy);
944 writel(reply_q->reply_post_host_index | (msix_index <<
945 MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
946 atomic_dec(&reply_q->busy);
951 * _base_is_controller_msix_enabled - is controller support muli-reply queues
952 * @ioc: per adapter object
956 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
958 return (ioc->facts.IOCCapabilities &
959 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
963 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
964 * @ioc: per adapter object
965 * Context: ISR conext
967 * Called when a Task Management request has completed. We want
968 * to flush the other reply queues so all the outstanding IO has been
969 * completed back to OS before we process the TM completetion.
974 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
976 struct adapter_reply_queue *reply_q;
978 /* If MSIX capability is turned off
979 * then multi-queues are not enabled
981 if (!_base_is_controller_msix_enabled(ioc))
984 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
985 if (ioc->shost_recovery)
987 /* TMs are on msix_index == 0 */
988 if (reply_q->msix_index == 0)
990 _base_interrupt(reply_q->vector, (void *)reply_q);
995 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
996 * @cb_idx: callback index
1001 mpt2sas_base_release_callback_handler(u8 cb_idx)
1003 mpt_callbacks[cb_idx] = NULL;
1007 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1008 * @cb_func: callback function
1013 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
1017 for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
1018 if (mpt_callbacks[cb_idx] == NULL)
1021 mpt_callbacks[cb_idx] = cb_func;
1026 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1031 mpt2sas_base_initialize_callback_handler(void)
1035 for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
1036 mpt2sas_base_release_callback_handler(cb_idx);
1040 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1041 * @ioc: per adapter object
1042 * @paddr: virtual address for SGE
1044 * Create a zero length scatter gather entry to insure the IOCs hardware has
1045 * something to use if the target device goes brain dead and tries
1046 * to send data even when none is asked for.
1051 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
1053 u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
1054 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
1055 MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
1056 MPI2_SGE_FLAGS_SHIFT);
1057 ioc->base_add_sg_single(paddr, flags_length, -1);
1061 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1062 * @paddr: virtual address for SGE
1063 * @flags_length: SGE flags and data transfer length
1064 * @dma_addr: Physical address
1069 _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1071 Mpi2SGESimple32_t *sgel = paddr;
1073 flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
1074 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1075 sgel->FlagsLength = cpu_to_le32(flags_length);
1076 sgel->Address = cpu_to_le32(dma_addr);
1081 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1082 * @paddr: virtual address for SGE
1083 * @flags_length: SGE flags and data transfer length
1084 * @dma_addr: Physical address
1089 _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1091 Mpi2SGESimple64_t *sgel = paddr;
1093 flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
1094 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1095 sgel->FlagsLength = cpu_to_le32(flags_length);
1096 sgel->Address = cpu_to_le64(dma_addr);
1099 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1102 * _base_config_dma_addressing - set dma addressing
1103 * @ioc: per adapter object
1104 * @pdev: PCI device struct
1106 * Returns 0 for success, non-zero for failure.
1109 _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
1114 if (sizeof(dma_addr_t) > 4) {
1115 const uint64_t required_mask =
1116 dma_get_required_mask(&pdev->dev);
1117 if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
1118 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
1119 DMA_BIT_MASK(64))) {
1120 ioc->base_add_sg_single = &_base_add_sg_single_64;
1121 ioc->sge_size = sizeof(Mpi2SGESimple64_t);
1127 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1128 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
1129 ioc->base_add_sg_single = &_base_add_sg_single_32;
1130 ioc->sge_size = sizeof(Mpi2SGESimple32_t);
1137 printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1138 "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
1144 * _base_check_enable_msix - checks MSIX capabable.
1145 * @ioc: per adapter object
1147 * Check to see if card is capable of MSIX, and set number
1148 * of available msix vectors
1151 _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1154 u16 message_control;
1157 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1159 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
1160 "supported\n", ioc->name));
1164 /* get msix vector count */
1165 /* NUMA_IO not supported for older controllers */
1166 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
1167 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
1168 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
1169 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
1170 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
1171 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
1172 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
1173 ioc->msix_vector_count = 1;
1175 pci_read_config_word(ioc->pdev, base + 2, &message_control);
1176 ioc->msix_vector_count = (message_control & 0x3FF) + 1;
1178 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
1179 "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
1185 * _base_free_irq - free irq
1186 * @ioc: per adapter object
1188 * Freeing respective reply_queue from the list.
1191 _base_free_irq(struct MPT2SAS_ADAPTER *ioc)
1193 struct adapter_reply_queue *reply_q, *next;
1195 if (list_empty(&ioc->reply_queue_list))
1198 list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
1199 list_del(&reply_q->list);
1200 synchronize_irq(reply_q->vector);
1201 free_irq(reply_q->vector, reply_q);
1207 * _base_request_irq - request irq
1208 * @ioc: per adapter object
1209 * @index: msix index into vector table
1210 * @vector: irq vector
1212 * Inserting respective reply_queue into the list.
1215 _base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
1217 struct adapter_reply_queue *reply_q;
1220 reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
1222 printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
1223 ioc->name, (int)sizeof(struct adapter_reply_queue));
1227 reply_q->msix_index = index;
1228 reply_q->vector = vector;
1229 atomic_set(&reply_q->busy, 0);
1230 if (ioc->msix_enable)
1231 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
1232 MPT2SAS_DRIVER_NAME, ioc->id, index);
1234 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
1235 MPT2SAS_DRIVER_NAME, ioc->id);
1236 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1239 printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
1240 reply_q->name, vector);
1245 INIT_LIST_HEAD(&reply_q->list);
1246 list_add_tail(&reply_q->list, &ioc->reply_queue_list);
1251 * _base_assign_reply_queues - assigning msix index for each cpu
1252 * @ioc: per adapter object
1254 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1256 * It would nice if we could call irq_set_affinity, however it is not
1257 * an exported symbol
1260 _base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1262 struct adapter_reply_queue *reply_q;
1264 int cpu_grouping, loop, grouping, grouping_mod;
1266 if (!_base_is_controller_msix_enabled(ioc))
1269 memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
1270 /* when there are more cpus than available msix vectors,
1271 * then group cpus togeather on same irq
1273 if (ioc->cpu_count > ioc->msix_vector_count) {
1274 grouping = ioc->cpu_count / ioc->msix_vector_count;
1275 grouping_mod = ioc->cpu_count % ioc->msix_vector_count;
1276 if (grouping < 2 || (grouping == 2 && !grouping_mod))
1278 else if (grouping < 4 || (grouping == 4 && !grouping_mod))
1280 else if (grouping < 8 || (grouping == 8 && !grouping_mod))
1288 reply_q = list_entry(ioc->reply_queue_list.next,
1289 struct adapter_reply_queue, list);
1290 for_each_online_cpu(cpu_id) {
1291 if (!cpu_grouping) {
1292 ioc->cpu_msix_table[cpu_id] = reply_q->msix_index;
1293 reply_q = list_entry(reply_q->list.next,
1294 struct adapter_reply_queue, list);
1296 if (loop < cpu_grouping) {
1297 ioc->cpu_msix_table[cpu_id] =
1298 reply_q->msix_index;
1301 reply_q = list_entry(reply_q->list.next,
1302 struct adapter_reply_queue, list);
1303 ioc->cpu_msix_table[cpu_id] =
1304 reply_q->msix_index;
1312 * _base_disable_msix - disables msix
1313 * @ioc: per adapter object
1317 _base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
1319 if (ioc->msix_enable) {
1320 pci_disable_msix(ioc->pdev);
1321 ioc->msix_enable = 0;
1326 * _base_enable_msix - enables msix, failback to io_apic
1327 * @ioc: per adapter object
1331 _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1333 struct msix_entry *entries, *a;
1338 INIT_LIST_HEAD(&ioc->reply_queue_list);
1340 if (msix_disable == -1 || msix_disable == 0)
1346 if (_base_check_enable_msix(ioc) != 0)
1349 ioc->reply_queue_count = min_t(u8, ioc->cpu_count,
1350 ioc->msix_vector_count);
1352 entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
1355 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
1356 "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
1357 __LINE__, __func__));
1361 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
1364 r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
1366 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
1367 "failed (r=%d) !!!\n", ioc->name, r));
1372 ioc->msix_enable = 1;
1373 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
1374 r = _base_request_irq(ioc, i, a->vector);
1376 _base_free_irq(ioc);
1377 _base_disable_msix(ioc);
1386 /* failback to io_apic interrupt routing */
1389 r = _base_request_irq(ioc, 0, ioc->pdev->irq);
1395 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1396 * @ioc: per adapter object
1398 * Returns 0 for success, non-zero for failure.
1401 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1403 struct pci_dev *pdev = ioc->pdev;
1409 struct adapter_reply_queue *reply_q;
1411 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
1412 ioc->name, __func__));
1414 ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
1415 if (pci_enable_device_mem(pdev)) {
1416 printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
1417 "failed\n", ioc->name);
1422 if (pci_request_selected_regions(pdev, ioc->bars,
1423 MPT2SAS_DRIVER_NAME)) {
1424 printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
1425 "failed\n", ioc->name);
1430 /* AER (Advanced Error Reporting) hooks */
1431 pci_enable_pcie_error_reporting(pdev);
1433 pci_set_master(pdev);
1435 if (_base_config_dma_addressing(ioc, pdev) != 0) {
1436 printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
1437 ioc->name, pci_name(pdev));
1442 for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
1443 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
1446 pio_chip = (u64)pci_resource_start(pdev, i);
1447 pio_sz = pci_resource_len(pdev, i);
1451 /* verify memory resource is valid before using */
1452 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
1453 ioc->chip_phys = pci_resource_start(pdev, i);
1454 chip_phys = (u64)ioc->chip_phys;
1455 memap_sz = pci_resource_len(pdev, i);
1456 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1457 if (ioc->chip == NULL) {
1458 printk(MPT2SAS_ERR_FMT "unable to map "
1459 "adapter memory!\n", ioc->name);
1467 _base_mask_interrupts(ioc);
1468 r = _base_enable_msix(ioc);
1472 list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
1473 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
1474 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
1475 "IO-APIC enabled"), reply_q->vector);
1477 printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1478 ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
1479 printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
1480 ioc->name, (unsigned long long)pio_chip, pio_sz);
1482 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1483 pci_save_state(pdev);
1491 pci_release_selected_regions(ioc->pdev, ioc->bars);
1492 pci_disable_pcie_error_reporting(pdev);
1493 pci_disable_device(pdev);
1498 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1499 * @ioc: per adapter object
1500 * @smid: system request message index(smid zero is invalid)
1502 * Returns virt pointer to message frame.
1505 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1507 return (void *)(ioc->request + (smid * ioc->request_sz));
1511 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1512 * @ioc: per adapter object
1513 * @smid: system request message index
1515 * Returns virt pointer to sense buffer.
1518 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1520 return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1524 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1525 * @ioc: per adapter object
1526 * @smid: system request message index
1528 * Returns phys pointer to the low 32bit address of the sense buffer.
1531 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1533 return cpu_to_le32(ioc->sense_dma +
1534 ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1538 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1539 * @ioc: per adapter object
1540 * @phys_addr: lower 32 physical addr of the reply
1542 * Converts 32bit lower physical addr into a virt address.
1545 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
1549 return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
1553 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1554 * @ioc: per adapter object
1555 * @cb_idx: callback index
1557 * Returns smid (zero is invalid)
1560 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1562 unsigned long flags;
1563 struct request_tracker *request;
1566 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1567 if (list_empty(&ioc->internal_free_list)) {
1568 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1569 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1570 ioc->name, __func__);
1574 request = list_entry(ioc->internal_free_list.next,
1575 struct request_tracker, tracker_list);
1576 request->cb_idx = cb_idx;
1577 smid = request->smid;
1578 list_del(&request->tracker_list);
1579 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1584 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1585 * @ioc: per adapter object
1586 * @cb_idx: callback index
1587 * @scmd: pointer to scsi command object
1589 * Returns smid (zero is invalid)
1592 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1593 struct scsi_cmnd *scmd)
1595 unsigned long flags;
1596 struct scsiio_tracker *request;
1599 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1600 if (list_empty(&ioc->free_list)) {
1601 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1602 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1603 ioc->name, __func__);
1607 request = list_entry(ioc->free_list.next,
1608 struct scsiio_tracker, tracker_list);
1609 request->scmd = scmd;
1610 request->cb_idx = cb_idx;
1611 smid = request->smid;
1612 list_del(&request->tracker_list);
1613 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1618 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1619 * @ioc: per adapter object
1620 * @cb_idx: callback index
1622 * Returns smid (zero is invalid)
1625 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1627 unsigned long flags;
1628 struct request_tracker *request;
1631 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1632 if (list_empty(&ioc->hpr_free_list)) {
1633 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1637 request = list_entry(ioc->hpr_free_list.next,
1638 struct request_tracker, tracker_list);
1639 request->cb_idx = cb_idx;
1640 smid = request->smid;
1641 list_del(&request->tracker_list);
1642 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1648 * mpt2sas_base_free_smid - put smid back on free_list
1649 * @ioc: per adapter object
1650 * @smid: system request message index
1655 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1657 unsigned long flags;
1659 struct chain_tracker *chain_req, *next;
1661 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1662 if (smid < ioc->hi_priority_smid) {
1665 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
1666 list_for_each_entry_safe(chain_req, next,
1667 &ioc->scsi_lookup[i].chain_list, tracker_list) {
1668 list_del_init(&chain_req->tracker_list);
1669 list_add_tail(&chain_req->tracker_list,
1670 &ioc->free_chain_list);
1673 ioc->scsi_lookup[i].cb_idx = 0xFF;
1674 ioc->scsi_lookup[i].scmd = NULL;
1675 ioc->scsi_lookup[i].direct_io = 0;
1676 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
1678 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1681 * See _wait_for_commands_to_complete() call with regards
1684 if (ioc->shost_recovery && ioc->pending_io_count) {
1685 if (ioc->pending_io_count == 1)
1686 wake_up(&ioc->reset_wq);
1687 ioc->pending_io_count--;
1690 } else if (smid < ioc->internal_smid) {
1692 i = smid - ioc->hi_priority_smid;
1693 ioc->hpr_lookup[i].cb_idx = 0xFF;
1694 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
1695 &ioc->hpr_free_list);
1696 } else if (smid <= ioc->hba_queue_depth) {
1697 /* internal queue */
1698 i = smid - ioc->internal_smid;
1699 ioc->internal_lookup[i].cb_idx = 0xFF;
1700 list_add_tail(&ioc->internal_lookup[i].tracker_list,
1701 &ioc->internal_free_list);
1703 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1707 * _base_writeq - 64 bit write to MMIO
1708 * @ioc: per adapter object
1710 * @addr: address in MMIO space
1711 * @writeq_lock: spin lock
1713 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1714 * care of 32 bit environment where its not quarenteed to send the entire word
1718 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1719 spinlock_t *writeq_lock)
1721 unsigned long flags;
1722 __u64 data_out = cpu_to_le64(b);
1724 spin_lock_irqsave(writeq_lock, flags);
1725 writel((u32)(data_out), addr);
1726 writel((u32)(data_out >> 32), (addr + 4));
1727 spin_unlock_irqrestore(writeq_lock, flags);
1730 static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1731 spinlock_t *writeq_lock)
1733 writeq(cpu_to_le64(b), addr);
1738 _base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
1740 return ioc->cpu_msix_table[smp_processor_id()];
1744 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1745 * @ioc: per adapter object
1746 * @smid: system request message index
1747 * @handle: device handle
1752 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
1754 Mpi2RequestDescriptorUnion_t descriptor;
1755 u64 *request = (u64 *)&descriptor;
1758 descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
1759 descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc);
1760 descriptor.SCSIIO.SMID = cpu_to_le16(smid);
1761 descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
1762 descriptor.SCSIIO.LMID = 0;
1763 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1764 &ioc->scsi_lookup_lock);
1769 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1770 * @ioc: per adapter object
1771 * @smid: system request message index
1776 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1778 Mpi2RequestDescriptorUnion_t descriptor;
1779 u64 *request = (u64 *)&descriptor;
1781 descriptor.HighPriority.RequestFlags =
1782 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
1783 descriptor.HighPriority.MSIxIndex = 0;
1784 descriptor.HighPriority.SMID = cpu_to_le16(smid);
1785 descriptor.HighPriority.LMID = 0;
1786 descriptor.HighPriority.Reserved1 = 0;
1787 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1788 &ioc->scsi_lookup_lock);
1792 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1793 * @ioc: per adapter object
1794 * @smid: system request message index
1799 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1801 Mpi2RequestDescriptorUnion_t descriptor;
1802 u64 *request = (u64 *)&descriptor;
1804 descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
1805 descriptor.Default.MSIxIndex = _base_get_msix_index(ioc);
1806 descriptor.Default.SMID = cpu_to_le16(smid);
1807 descriptor.Default.LMID = 0;
1808 descriptor.Default.DescriptorTypeDependent = 0;
1809 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1810 &ioc->scsi_lookup_lock);
1814 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1815 * @ioc: per adapter object
1816 * @smid: system request message index
1817 * @io_index: value used to track the IO
1822 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1825 Mpi2RequestDescriptorUnion_t descriptor;
1826 u64 *request = (u64 *)&descriptor;
1828 descriptor.SCSITarget.RequestFlags =
1829 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
1830 descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc);
1831 descriptor.SCSITarget.SMID = cpu_to_le16(smid);
1832 descriptor.SCSITarget.LMID = 0;
1833 descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
1834 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1835 &ioc->scsi_lookup_lock);
1839 * _base_display_dell_branding - Disply branding string
1840 * @ioc: per adapter object
1845 _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1847 char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
1849 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
1852 memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
1853 switch (ioc->pdev->subsystem_device) {
1854 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
1855 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
1856 MPT2SAS_DELL_BRANDING_SIZE - 1);
1858 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
1859 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
1860 MPT2SAS_DELL_BRANDING_SIZE - 1);
1862 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
1863 strncpy(dell_branding,
1864 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
1865 MPT2SAS_DELL_BRANDING_SIZE - 1);
1867 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
1868 strncpy(dell_branding,
1869 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
1870 MPT2SAS_DELL_BRANDING_SIZE - 1);
1872 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
1873 strncpy(dell_branding,
1874 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
1875 MPT2SAS_DELL_BRANDING_SIZE - 1);
1877 case MPT2SAS_DELL_PERC_H200_SSDID:
1878 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
1879 MPT2SAS_DELL_BRANDING_SIZE - 1);
1881 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
1882 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
1883 MPT2SAS_DELL_BRANDING_SIZE - 1);
1886 sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
1890 printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
1891 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
1892 ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
1893 ioc->pdev->subsystem_device);
1897 * _base_display_intel_branding - Display branding string
1898 * @ioc: per adapter object
1903 _base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
1905 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1908 switch (ioc->pdev->device) {
1909 case MPI2_MFGPAGE_DEVID_SAS2008:
1910 switch (ioc->pdev->subsystem_device) {
1911 case MPT2SAS_INTEL_RMS2LL080_SSDID:
1912 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1913 MPT2SAS_INTEL_RMS2LL080_BRANDING);
1915 case MPT2SAS_INTEL_RMS2LL040_SSDID:
1916 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1917 MPT2SAS_INTEL_RMS2LL040_BRANDING);
1922 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1923 switch (ioc->pdev->subsystem_device) {
1924 case MPT2SAS_INTEL_RS25GB008_SSDID:
1925 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1926 MPT2SAS_INTEL_RS25GB008_BRANDING);
1937 * _base_display_hp_branding - Display branding string
1938 * @ioc: per adapter object
1943 _base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
1945 if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
1948 switch (ioc->pdev->device) {
1949 case MPI2_MFGPAGE_DEVID_SAS2004:
1950 switch (ioc->pdev->subsystem_device) {
1951 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
1952 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1953 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
1958 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1959 switch (ioc->pdev->subsystem_device) {
1960 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
1961 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1962 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
1964 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
1965 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1966 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
1968 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
1969 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1970 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
1972 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
1973 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1974 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
1985 * _base_display_ioc_capabilities - Disply IOC's capabilities.
1986 * @ioc: per adapter object
1991 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
1996 u32 iounit_pg1_flags;
1999 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2000 pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
2001 strncpy(desc, ioc->manu_pg0.ChipName, 16);
2002 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
2003 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2005 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2006 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2007 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2008 ioc->facts.FWVersion.Word & 0x000000FF,
2010 (bios_version & 0xFF000000) >> 24,
2011 (bios_version & 0x00FF0000) >> 16,
2012 (bios_version & 0x0000FF00) >> 8,
2013 bios_version & 0x000000FF);
2015 _base_display_dell_branding(ioc);
2016 _base_display_intel_branding(ioc);
2017 _base_display_hp_branding(ioc);
2019 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
2021 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
2022 printk("Initiator");
2026 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
2027 printk("%sTarget", i ? "," : "");
2033 printk("Capabilities=(");
2035 if (!ioc->hide_ir_msg) {
2036 if (ioc->facts.IOCCapabilities &
2037 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2043 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
2044 printk("%sTLR", i ? "," : "");
2048 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
2049 printk("%sMulticast", i ? "," : "");
2053 if (ioc->facts.IOCCapabilities &
2054 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
2055 printk("%sBIDI Target", i ? "," : "");
2059 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
2060 printk("%sEEDP", i ? "," : "");
2064 if (ioc->facts.IOCCapabilities &
2065 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
2066 printk("%sSnapshot Buffer", i ? "," : "");
2070 if (ioc->facts.IOCCapabilities &
2071 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
2072 printk("%sDiag Trace Buffer", i ? "," : "");
2076 if (ioc->facts.IOCCapabilities &
2077 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
2078 printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
2082 if (ioc->facts.IOCCapabilities &
2083 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
2084 printk("%sTask Set Full", i ? "," : "");
2088 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2089 if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
2090 printk("%sNCQ", i ? "," : "");
2098 * _base_update_missing_delay - change the missing delay timers
2099 * @ioc: per adapter object
2100 * @device_missing_delay: amount of time till device is reported missing
2101 * @io_missing_delay: interval IO is returned when there is a missing device
2105 * Passed on the command line, this function will modify the device missing
2106 * delay, as well as the io missing delay. This should be called at driver
2110 _base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
2111 u16 device_missing_delay, u8 io_missing_delay)
2113 u16 dmd, dmd_new, dmd_orignal;
2114 u8 io_missing_delay_original;
2116 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
2117 Mpi2ConfigReply_t mpi_reply;
2121 mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
2125 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
2126 sizeof(Mpi2SasIOUnit1PhyData_t));
2127 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
2128 if (!sas_iounit_pg1) {
2129 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2130 ioc->name, __FILE__, __LINE__, __func__);
2133 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
2134 sas_iounit_pg1, sz))) {
2135 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2136 ioc->name, __FILE__, __LINE__, __func__);
2139 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2140 MPI2_IOCSTATUS_MASK;
2141 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2142 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2143 ioc->name, __FILE__, __LINE__, __func__);
2147 /* device missing delay */
2148 dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
2149 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2150 dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2152 dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2154 if (device_missing_delay > 0x7F) {
2155 dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
2156 device_missing_delay;
2158 dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
2160 dmd = device_missing_delay;
2161 sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
2163 /* io missing delay */
2164 io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
2165 sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
2167 if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
2169 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2171 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2174 dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2175 printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
2176 "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
2177 printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
2178 "new(%d)\n", ioc->name, io_missing_delay_original,
2180 ioc->device_missing_delay = dmd_new;
2181 ioc->io_missing_delay = io_missing_delay;
2185 kfree(sas_iounit_pg1);
2189 * _base_static_config_pages - static start of day config pages
2190 * @ioc: per adapter object
2195 _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
2197 Mpi2ConfigReply_t mpi_reply;
2198 u32 iounit_pg1_flags;
2200 mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
2201 if (ioc->ir_firmware)
2202 mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
2204 mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
2205 mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
2206 mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
2207 mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
2208 mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2209 _base_display_ioc_capabilities(ioc);
2212 * Enable task_set_full handling in iounit_pg1 when the
2213 * facts capabilities indicate that its supported.
2215 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2216 if ((ioc->facts.IOCCapabilities &
2217 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
2219 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2222 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2223 ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
2224 mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2229 * _base_release_memory_pools - release memory
2230 * @ioc: per adapter object
2232 * Free memory allocated from _base_allocate_memory_pools.
2237 _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
2241 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2245 pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
2246 ioc->request, ioc->request_dma);
2247 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
2248 ": free\n", ioc->name, ioc->request));
2249 ioc->request = NULL;
2253 pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
2254 if (ioc->sense_dma_pool)
2255 pci_pool_destroy(ioc->sense_dma_pool);
2256 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
2257 ": free\n", ioc->name, ioc->sense));
2262 pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
2263 if (ioc->reply_dma_pool)
2264 pci_pool_destroy(ioc->reply_dma_pool);
2265 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
2266 ": free\n", ioc->name, ioc->reply));
2270 if (ioc->reply_free) {
2271 pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
2272 ioc->reply_free_dma);
2273 if (ioc->reply_free_dma_pool)
2274 pci_pool_destroy(ioc->reply_free_dma_pool);
2275 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
2276 "(0x%p): free\n", ioc->name, ioc->reply_free));
2277 ioc->reply_free = NULL;
2280 if (ioc->reply_post_free) {
2281 pci_pool_free(ioc->reply_post_free_dma_pool,
2282 ioc->reply_post_free, ioc->reply_post_free_dma);
2283 if (ioc->reply_post_free_dma_pool)
2284 pci_pool_destroy(ioc->reply_post_free_dma_pool);
2285 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2286 "reply_post_free_pool(0x%p): free\n", ioc->name,
2287 ioc->reply_post_free));
2288 ioc->reply_post_free = NULL;
2291 if (ioc->config_page) {
2292 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2293 "config_page(0x%p): free\n", ioc->name,
2295 pci_free_consistent(ioc->pdev, ioc->config_page_sz,
2296 ioc->config_page, ioc->config_page_dma);
2299 if (ioc->scsi_lookup) {
2300 free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
2301 ioc->scsi_lookup = NULL;
2303 kfree(ioc->hpr_lookup);
2304 kfree(ioc->internal_lookup);
2305 if (ioc->chain_lookup) {
2306 for (i = 0; i < ioc->chain_depth; i++) {
2307 if (ioc->chain_lookup[i].chain_buffer)
2308 pci_pool_free(ioc->chain_dma_pool,
2309 ioc->chain_lookup[i].chain_buffer,
2310 ioc->chain_lookup[i].chain_buffer_dma);
2312 if (ioc->chain_dma_pool)
2313 pci_pool_destroy(ioc->chain_dma_pool);
2315 if (ioc->chain_lookup) {
2316 free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
2317 ioc->chain_lookup = NULL;
2323 * _base_allocate_memory_pools - allocate start of day memory pools
2324 * @ioc: per adapter object
2325 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2327 * Returns 0 success, anything else error
2330 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2332 struct mpt2sas_facts *facts;
2333 u32 queue_size, queue_diff;
2334 u16 max_sge_elements;
2335 u16 num_of_reply_frames;
2336 u16 chains_needed_per_io;
2337 u32 sz, total_sz, reply_post_free_sz;
2339 u16 max_request_credit;
2342 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2346 facts = &ioc->facts;
2348 /* command line tunables for max sgl entries */
2349 if (max_sgl_entries != -1) {
2350 ioc->shost->sg_tablesize = (max_sgl_entries <
2351 MPT2SAS_SG_DEPTH) ? max_sgl_entries :
2354 ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
2357 /* command line tunables for max controller queue depth */
2358 if (max_queue_depth != -1)
2359 max_request_credit = (max_queue_depth < facts->RequestCredit)
2360 ? max_queue_depth : facts->RequestCredit;
2362 max_request_credit = facts->RequestCredit;
2364 ioc->hba_queue_depth = max_request_credit;
2365 ioc->hi_priority_depth = facts->HighPriorityCredit;
2366 ioc->internal_depth = ioc->hi_priority_depth + 5;
2368 /* request frame size */
2369 ioc->request_sz = facts->IOCRequestFrameSize * 4;
2371 /* reply frame size */
2372 ioc->reply_sz = facts->ReplyFrameSize * 4;
2376 /* calculate number of sg elements left over in the 1st frame */
2377 max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
2378 sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
2379 ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
2381 /* now do the same for a chain buffer */
2382 max_sge_elements = ioc->request_sz - ioc->sge_size;
2383 ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
2385 ioc->chain_offset_value_for_main_message =
2386 ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
2387 (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
2390 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2392 chains_needed_per_io = ((ioc->shost->sg_tablesize -
2393 ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
2395 if (chains_needed_per_io > facts->MaxChainDepth) {
2396 chains_needed_per_io = facts->MaxChainDepth;
2397 ioc->shost->sg_tablesize = min_t(u16,
2398 ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
2399 * chains_needed_per_io), ioc->shost->sg_tablesize);
2401 ioc->chains_needed_per_io = chains_needed_per_io;
2403 /* reply free queue sizing - taking into account for events */
2404 num_of_reply_frames = ioc->hba_queue_depth + 32;
2406 /* number of replies frames can't be a multiple of 16 */
2407 /* decrease number of reply frames by 1 */
2408 if (!(num_of_reply_frames % 16))
2409 num_of_reply_frames--;
2411 /* calculate number of reply free queue entries
2412 * (must be multiple of 16)
2415 /* (we know reply_free_queue_depth is not a multiple of 16) */
2416 queue_size = num_of_reply_frames;
2417 queue_size += 16 - (queue_size % 16);
2418 ioc->reply_free_queue_depth = queue_size;
2420 /* reply descriptor post queue sizing */
2421 /* this size should be the number of request frames + number of reply
2425 queue_size = ioc->hba_queue_depth + num_of_reply_frames + 1;
2426 /* round up to 16 byte boundary */
2427 if (queue_size % 16)
2428 queue_size += 16 - (queue_size % 16);
2430 /* check against IOC maximum reply post queue depth */
2431 if (queue_size > facts->MaxReplyDescriptorPostQueueDepth) {
2432 queue_diff = queue_size -
2433 facts->MaxReplyDescriptorPostQueueDepth;
2435 /* round queue_diff up to multiple of 16 */
2436 if (queue_diff % 16)
2437 queue_diff += 16 - (queue_diff % 16);
2439 /* adjust hba_queue_depth, reply_free_queue_depth,
2442 ioc->hba_queue_depth -= (queue_diff / 2);
2443 ioc->reply_free_queue_depth -= (queue_diff / 2);
2444 queue_size = facts->MaxReplyDescriptorPostQueueDepth;
2446 ioc->reply_post_queue_depth = queue_size;
2448 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
2449 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2450 "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
2451 ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
2452 ioc->chains_needed_per_io));
2454 ioc->scsiio_depth = ioc->hba_queue_depth -
2455 ioc->hi_priority_depth - ioc->internal_depth;
2457 /* set the scsi host can_queue depth
2458 * with some internal commands that could be outstanding
2460 ioc->shost->can_queue = ioc->scsiio_depth - (2);
2461 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2462 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2464 /* contiguous pool for request and chains, 16 byte align, one extra "
2467 ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
2468 sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
2470 /* hi-priority queue */
2471 sz += (ioc->hi_priority_depth * ioc->request_sz);
2473 /* internal queue */
2474 sz += (ioc->internal_depth * ioc->request_sz);
2476 ioc->request_dma_sz = sz;
2477 ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
2478 if (!ioc->request) {
2479 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2480 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2481 "total(%d kB)\n", ioc->name, ioc->hba_queue_depth,
2482 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2483 if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
2486 ioc->hba_queue_depth = max_request_credit - retry_sz;
2487 goto retry_allocation;
2491 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
2492 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2493 "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
2494 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2497 /* hi-priority queue */
2498 ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
2500 ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
2503 /* internal queue */
2504 ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
2506 ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
2510 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
2511 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2512 ioc->request, ioc->hba_queue_depth, ioc->request_sz,
2513 (ioc->hba_queue_depth * ioc->request_sz)/1024));
2514 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
2515 ioc->name, (unsigned long long) ioc->request_dma));
2518 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
2519 ioc->scsi_lookup_pages = get_order(sz);
2520 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
2521 GFP_KERNEL, ioc->scsi_lookup_pages);
2522 if (!ioc->scsi_lookup) {
2523 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
2524 "sz(%d)\n", ioc->name, (int)sz);
2528 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
2529 "depth(%d)\n", ioc->name, ioc->request,
2530 ioc->scsiio_depth));
2532 /* loop till the allocation succeeds */
2534 sz = ioc->chain_depth * sizeof(struct chain_tracker);
2535 ioc->chain_pages = get_order(sz);
2536 ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
2537 GFP_KERNEL, ioc->chain_pages);
2538 if (ioc->chain_lookup == NULL)
2539 ioc->chain_depth -= 100;
2540 } while (ioc->chain_lookup == NULL);
2541 ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
2542 ioc->request_sz, 16, 0);
2543 if (!ioc->chain_dma_pool) {
2544 printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
2545 "failed\n", ioc->name);
2548 for (i = 0; i < ioc->chain_depth; i++) {
2549 ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
2550 ioc->chain_dma_pool , GFP_KERNEL,
2551 &ioc->chain_lookup[i].chain_buffer_dma);
2552 if (!ioc->chain_lookup[i].chain_buffer) {
2553 ioc->chain_depth = i;
2556 total_sz += ioc->request_sz;
2559 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
2560 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2561 ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
2562 ioc->request_sz))/1024));
2564 /* initialize hi-priority queue smid's */
2565 ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
2566 sizeof(struct request_tracker), GFP_KERNEL);
2567 if (!ioc->hpr_lookup) {
2568 printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
2572 ioc->hi_priority_smid = ioc->scsiio_depth + 1;
2573 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
2574 "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
2575 ioc->hi_priority_depth, ioc->hi_priority_smid));
2577 /* initialize internal queue smid's */
2578 ioc->internal_lookup = kcalloc(ioc->internal_depth,
2579 sizeof(struct request_tracker), GFP_KERNEL);
2580 if (!ioc->internal_lookup) {
2581 printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
2585 ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
2586 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
2587 "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
2588 ioc->internal_depth, ioc->internal_smid));
2590 /* sense buffers, 4 byte align */
2591 sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
2592 ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
2594 if (!ioc->sense_dma_pool) {
2595 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
2599 ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
2602 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
2606 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
2607 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2608 "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
2609 SCSI_SENSE_BUFFERSIZE, sz/1024));
2610 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
2611 ioc->name, (unsigned long long)ioc->sense_dma));
2614 /* reply pool, 4 byte align */
2615 sz = ioc->reply_free_queue_depth * ioc->reply_sz;
2616 ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
2618 if (!ioc->reply_dma_pool) {
2619 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
2623 ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
2626 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
2630 ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
2631 ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
2632 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
2633 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
2634 ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
2635 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
2636 ioc->name, (unsigned long long)ioc->reply_dma));
2639 /* reply free queue, 16 byte align */
2640 sz = ioc->reply_free_queue_depth * 4;
2641 ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
2642 ioc->pdev, sz, 16, 0);
2643 if (!ioc->reply_free_dma_pool) {
2644 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
2645 "failed\n", ioc->name);
2648 ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
2649 &ioc->reply_free_dma);
2650 if (!ioc->reply_free) {
2651 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
2652 "failed\n", ioc->name);
2655 memset(ioc->reply_free, 0, sz);
2656 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
2657 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
2658 ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
2659 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
2660 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
2663 /* reply post queue, 16 byte align */
2664 reply_post_free_sz = ioc->reply_post_queue_depth *
2665 sizeof(Mpi2DefaultReplyDescriptor_t);
2666 if (_base_is_controller_msix_enabled(ioc))
2667 sz = reply_post_free_sz * ioc->reply_queue_count;
2669 sz = reply_post_free_sz;
2670 ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
2671 ioc->pdev, sz, 16, 0);
2672 if (!ioc->reply_post_free_dma_pool) {
2673 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
2674 "failed\n", ioc->name);
2677 ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
2678 GFP_KERNEL, &ioc->reply_post_free_dma);
2679 if (!ioc->reply_post_free) {
2680 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
2681 "failed\n", ioc->name);
2684 memset(ioc->reply_post_free, 0, sz);
2685 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
2686 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2687 ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
2689 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
2690 "(0x%llx)\n", ioc->name, (unsigned long long)
2691 ioc->reply_post_free_dma));
2694 ioc->config_page_sz = 512;
2695 ioc->config_page = pci_alloc_consistent(ioc->pdev,
2696 ioc->config_page_sz, &ioc->config_page_dma);
2697 if (!ioc->config_page) {
2698 printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
2699 "failed\n", ioc->name);
2702 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
2703 "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
2704 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
2705 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
2706 total_sz += ioc->config_page_sz;
2708 printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
2709 ioc->name, total_sz/1024);
2710 printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
2711 "Max Controller Queue Depth(%d)\n",
2712 ioc->name, ioc->shost->can_queue, facts->RequestCredit);
2713 printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
2714 ioc->name, ioc->shost->sg_tablesize);
2723 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2724 * @ioc: Pointer to MPT_ADAPTER structure
2725 * @cooked: Request raw or cooked IOC state
2727 * Returns all IOC Doorbell register bits if cooked==0, else just the
2728 * Doorbell bits in MPI_IOC_STATE_MASK.
2731 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
2735 s = readl(&ioc->chip->Doorbell);
2736 sc = s & MPI2_IOC_STATE_MASK;
2737 return cooked ? sc : s;
2741 * _base_wait_on_iocstate - waiting on a particular ioc state
2742 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2743 * @timeout: timeout in second
2744 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2746 * Returns 0 for success, non-zero for failure.
2749 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
2756 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2758 current_state = mpt2sas_base_get_iocstate(ioc, 1);
2759 if (current_state == ioc_state)
2761 if (count && current_state == MPI2_IOC_STATE_FAULT)
2763 if (sleep_flag == CAN_SLEEP)
2770 return current_state;
2774 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2775 * a write to the doorbell)
2776 * @ioc: per adapter object
2777 * @timeout: timeout in second
2778 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2780 * Returns 0 for success, non-zero for failure.
2782 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2785 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
2792 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2794 int_status = readl(&ioc->chip->HostInterruptStatus);
2795 if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2796 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2797 "successful count(%d), timeout(%d)\n", ioc->name,
2798 __func__, count, timeout));
2801 if (sleep_flag == CAN_SLEEP)
2808 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2809 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2814 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2815 * @ioc: per adapter object
2816 * @timeout: timeout in second
2817 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2819 * Returns 0 for success, non-zero for failure.
2821 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2825 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
2833 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2835 int_status = readl(&ioc->chip->HostInterruptStatus);
2836 if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
2837 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2838 "successful count(%d), timeout(%d)\n", ioc->name,
2839 __func__, count, timeout));
2841 } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2842 doorbell = readl(&ioc->chip->Doorbell);
2843 if ((doorbell & MPI2_IOC_STATE_MASK) ==
2844 MPI2_IOC_STATE_FAULT) {
2845 mpt2sas_base_fault_info(ioc , doorbell);
2848 } else if (int_status == 0xFFFFFFFF)
2851 if (sleep_flag == CAN_SLEEP)
2859 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2860 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2865 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2866 * @ioc: per adapter object
2867 * @timeout: timeout in second
2868 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2870 * Returns 0 for success, non-zero for failure.
2874 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
2881 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2883 doorbell_reg = readl(&ioc->chip->Doorbell);
2884 if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
2885 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
2886 "successful count(%d), timeout(%d)\n", ioc->name,
2887 __func__, count, timeout));
2890 if (sleep_flag == CAN_SLEEP)
2897 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2898 "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
2903 * _base_send_ioc_reset - send doorbell reset
2904 * @ioc: per adapter object
2905 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2906 * @timeout: timeout in second
2907 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2909 * Returns 0 for success, non-zero for failure.
2912 _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
2918 if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
2919 printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
2920 ioc->name, __func__);
2924 if (!(ioc->facts.IOCCapabilities &
2925 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
2928 printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
2930 writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
2931 &ioc->chip->Doorbell);
2932 if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
2936 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
2937 timeout, sleep_flag);
2939 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
2940 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
2945 printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
2946 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
2951 * _base_handshake_req_reply_wait - send request thru doorbell interface
2952 * @ioc: per adapter object
2953 * @request_bytes: request length
2954 * @request: pointer having request payload
2955 * @reply_bytes: reply length
2956 * @reply: pointer to reply payload
2957 * @timeout: timeout in second
2958 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2960 * Returns 0 for success, non-zero for failure.
2963 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
2964 u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
2966 MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
2972 /* make sure doorbell is not in use */
2973 if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
2974 printk(MPT2SAS_ERR_FMT "doorbell is in use "
2975 " (line=%d)\n", ioc->name, __LINE__);
2979 /* clear pending doorbell interrupts from previous state changes */
2980 if (readl(&ioc->chip->HostInterruptStatus) &
2981 MPI2_HIS_IOC2SYS_DB_STATUS)
2982 writel(0, &ioc->chip->HostInterruptStatus);
2984 /* send message to ioc */
2985 writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
2986 ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
2987 &ioc->chip->Doorbell);
2989 if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
2990 printk(MPT2SAS_ERR_FMT "doorbell handshake "
2991 "int failed (line=%d)\n", ioc->name, __LINE__);
2994 writel(0, &ioc->chip->HostInterruptStatus);
2996 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
2997 printk(MPT2SAS_ERR_FMT "doorbell handshake "
2998 "ack failed (line=%d)\n", ioc->name, __LINE__);
3002 /* send message 32-bits at a time */
3003 for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
3004 writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
3005 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
3010 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3011 "sending request failed (line=%d)\n", ioc->name, __LINE__);
3015 /* now wait for the reply */
3016 if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
3017 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3018 "int failed (line=%d)\n", ioc->name, __LINE__);
3022 /* read the first two 16-bits, it gives the total length of the reply */
3023 reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3024 & MPI2_DOORBELL_DATA_MASK);
3025 writel(0, &ioc->chip->HostInterruptStatus);
3026 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3027 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3028 "int failed (line=%d)\n", ioc->name, __LINE__);
3031 reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3032 & MPI2_DOORBELL_DATA_MASK);
3033 writel(0, &ioc->chip->HostInterruptStatus);
3035 for (i = 2; i < default_reply->MsgLength * 2; i++) {
3036 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3037 printk(MPT2SAS_ERR_FMT "doorbell "
3038 "handshake int failed (line=%d)\n", ioc->name,
3042 if (i >= reply_bytes/2) /* overflow case */
3043 dummy = readl(&ioc->chip->Doorbell);
3045 reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3046 & MPI2_DOORBELL_DATA_MASK);
3047 writel(0, &ioc->chip->HostInterruptStatus);
3050 _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
3051 if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
3052 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
3053 " (line=%d)\n", ioc->name, __LINE__));
3055 writel(0, &ioc->chip->HostInterruptStatus);
3057 if (ioc->logging_level & MPT_DEBUG_INIT) {
3058 mfp = (__le32 *)reply;
3059 printk(KERN_INFO "\toffset:data\n");
3060 for (i = 0; i < reply_bytes/4; i++)
3061 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3062 le32_to_cpu(mfp[i]));
3068 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3069 * @ioc: per adapter object
3070 * @mpi_reply: the reply payload from FW
3071 * @mpi_request: the request payload sent to FW
3073 * The SAS IO Unit Control Request message allows the host to perform low-level
3074 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3075 * to obtain the IOC assigned device handles for a device if it has other
3076 * identifying information about the device, in addition allows the host to
3077 * remove IOC resources associated with the device.
3079 * Returns 0 for success, non-zero for failure.
3082 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
3083 Mpi2SasIoUnitControlReply_t *mpi_reply,
3084 Mpi2SasIoUnitControlRequest_t *mpi_request)
3088 unsigned long timeleft;
3092 u16 wait_state_count;
3094 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3097 mutex_lock(&ioc->base_cmds.mutex);
3099 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3100 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3101 ioc->name, __func__);
3106 wait_state_count = 0;
3107 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3108 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3109 if (wait_state_count++ == 10) {
3110 printk(MPT2SAS_ERR_FMT
3111 "%s: failed due to ioc not operational\n",
3112 ioc->name, __func__);
3117 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3118 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3119 "operational state(count=%d)\n", ioc->name,
3120 __func__, wait_state_count);
3123 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3125 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3126 ioc->name, __func__);
3132 ioc->base_cmds.status = MPT2_CMD_PENDING;
3133 request = mpt2sas_base_get_msg_frame(ioc, smid);
3134 ioc->base_cmds.smid = smid;
3135 memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
3136 if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3137 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
3138 ioc->ioc_link_reset_in_progress = 1;
3139 mpt2sas_base_put_smid_default(ioc, smid);
3140 init_completion(&ioc->base_cmds.done);
3141 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3142 msecs_to_jiffies(10000));
3143 if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3144 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
3145 ioc->ioc_link_reset_in_progress)
3146 ioc->ioc_link_reset_in_progress = 0;
3147 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3148 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3149 ioc->name, __func__);
3150 _debug_dump_mf(mpi_request,
3151 sizeof(Mpi2SasIoUnitControlRequest_t)/4);
3152 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3154 goto issue_host_reset;
3156 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3157 memcpy(mpi_reply, ioc->base_cmds.reply,
3158 sizeof(Mpi2SasIoUnitControlReply_t));
3160 memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
3161 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3166 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3168 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3171 mutex_unlock(&ioc->base_cmds.mutex);
3177 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3178 * @ioc: per adapter object
3179 * @mpi_reply: the reply payload from FW
3180 * @mpi_request: the request payload sent to FW
3182 * The SCSI Enclosure Processor request message causes the IOC to
3183 * communicate with SES devices to control LED status signals.
3185 * Returns 0 for success, non-zero for failure.
3188 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
3189 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
3193 unsigned long timeleft;
3197 u16 wait_state_count;
3199 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3202 mutex_lock(&ioc->base_cmds.mutex);
3204 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3205 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3206 ioc->name, __func__);
3211 wait_state_count = 0;
3212 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3213 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3214 if (wait_state_count++ == 10) {
3215 printk(MPT2SAS_ERR_FMT
3216 "%s: failed due to ioc not operational\n",
3217 ioc->name, __func__);
3222 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3223 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3224 "operational state(count=%d)\n", ioc->name,
3225 __func__, wait_state_count);
3228 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3230 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3231 ioc->name, __func__);
3237 ioc->base_cmds.status = MPT2_CMD_PENDING;
3238 request = mpt2sas_base_get_msg_frame(ioc, smid);
3239 ioc->base_cmds.smid = smid;
3240 memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
3241 mpt2sas_base_put_smid_default(ioc, smid);
3242 init_completion(&ioc->base_cmds.done);
3243 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3244 msecs_to_jiffies(10000));
3245 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3246 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3247 ioc->name, __func__);
3248 _debug_dump_mf(mpi_request,
3249 sizeof(Mpi2SepRequest_t)/4);
3250 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3252 goto issue_host_reset;
3254 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3255 memcpy(mpi_reply, ioc->base_cmds.reply,
3256 sizeof(Mpi2SepReply_t));
3258 memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
3259 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3264 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3266 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3269 mutex_unlock(&ioc->base_cmds.mutex);
3274 * _base_get_port_facts - obtain port facts reply and save in ioc
3275 * @ioc: per adapter object
3276 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3278 * Returns 0 for success, non-zero for failure.
3281 _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
3283 Mpi2PortFactsRequest_t mpi_request;
3284 Mpi2PortFactsReply_t mpi_reply;
3285 struct mpt2sas_port_facts *pfacts;
3286 int mpi_reply_sz, mpi_request_sz, r;
3288 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3291 mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
3292 mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
3293 memset(&mpi_request, 0, mpi_request_sz);
3294 mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
3295 mpi_request.PortNumber = port;
3296 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3297 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3300 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3301 ioc->name, __func__, r);
3305 pfacts = &ioc->pfacts[port];
3306 memset(pfacts, 0, sizeof(Mpi2PortFactsReply_t));
3307 pfacts->PortNumber = mpi_reply.PortNumber;
3308 pfacts->VP_ID = mpi_reply.VP_ID;
3309 pfacts->VF_ID = mpi_reply.VF_ID;
3310 pfacts->MaxPostedCmdBuffers =
3311 le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
3317 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3318 * @ioc: per adapter object
3319 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3321 * Returns 0 for success, non-zero for failure.
3324 _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3326 Mpi2IOCFactsRequest_t mpi_request;
3327 Mpi2IOCFactsReply_t mpi_reply;
3328 struct mpt2sas_facts *facts;
3329 int mpi_reply_sz, mpi_request_sz, r;
3331 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3334 mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
3335 mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
3336 memset(&mpi_request, 0, mpi_request_sz);
3337 mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
3338 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3339 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3342 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3343 ioc->name, __func__, r);
3347 facts = &ioc->facts;
3348 memset(facts, 0, sizeof(Mpi2IOCFactsReply_t));
3349 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
3350 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
3351 facts->VP_ID = mpi_reply.VP_ID;
3352 facts->VF_ID = mpi_reply.VF_ID;
3353 facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
3354 facts->MaxChainDepth = mpi_reply.MaxChainDepth;
3355 facts->WhoInit = mpi_reply.WhoInit;
3356 facts->NumberOfPorts = mpi_reply.NumberOfPorts;
3357 facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
3358 facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
3359 facts->MaxReplyDescriptorPostQueueDepth =
3360 le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
3361 facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
3362 facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
3363 if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
3364 ioc->ir_firmware = 1;
3365 facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
3366 facts->IOCRequestFrameSize =
3367 le16_to_cpu(mpi_reply.IOCRequestFrameSize);
3368 facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
3369 facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
3370 ioc->shost->max_id = -1;
3371 facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
3372 facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
3373 facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
3374 facts->HighPriorityCredit =
3375 le16_to_cpu(mpi_reply.HighPriorityCredit);
3376 facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
3377 facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
3379 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
3380 "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
3381 facts->MaxChainDepth));
3382 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
3383 "reply frame size(%d)\n", ioc->name,
3384 facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
3389 * _base_send_ioc_init - send ioc_init to firmware
3390 * @ioc: per adapter object
3391 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3393 * Returns 0 for success, non-zero for failure.
3396 _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3398 Mpi2IOCInitRequest_t mpi_request;
3399 Mpi2IOCInitReply_t mpi_reply;
3401 struct timeval current_time;
3404 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3407 memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
3408 mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
3409 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
3410 mpi_request.VF_ID = 0; /* TODO */
3411 mpi_request.VP_ID = 0;
3412 mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
3413 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
3415 if (_base_is_controller_msix_enabled(ioc))
3416 mpi_request.HostMSIxVectors = ioc->reply_queue_count;
3417 mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
3418 mpi_request.ReplyDescriptorPostQueueDepth =
3419 cpu_to_le16(ioc->reply_post_queue_depth);
3420 mpi_request.ReplyFreeQueueDepth =
3421 cpu_to_le16(ioc->reply_free_queue_depth);
3423 mpi_request.SenseBufferAddressHigh =
3424 cpu_to_le32((u64)ioc->sense_dma >> 32);
3425 mpi_request.SystemReplyAddressHigh =
3426 cpu_to_le32((u64)ioc->reply_dma >> 32);
3427 mpi_request.SystemRequestFrameBaseAddress =
3428 cpu_to_le64((u64)ioc->request_dma);
3429 mpi_request.ReplyFreeQueueAddress =
3430 cpu_to_le64((u64)ioc->reply_free_dma);
3431 mpi_request.ReplyDescriptorPostQueueAddress =
3432 cpu_to_le64((u64)ioc->reply_post_free_dma);
3435 /* This time stamp specifies number of milliseconds
3436 * since epoch ~ midnight January 1, 1970.
3438 do_gettimeofday(¤t_time);
3439 mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
3440 (current_time.tv_usec / 1000));
3442 if (ioc->logging_level & MPT_DEBUG_INIT) {
3446 mfp = (__le32 *)&mpi_request;
3447 printk(KERN_INFO "\toffset:data\n");
3448 for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
3449 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
3450 le32_to_cpu(mfp[i]));
3453 r = _base_handshake_req_reply_wait(ioc,
3454 sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
3455 sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
3459 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3460 ioc->name, __func__, r);
3464 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
3465 if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
3466 mpi_reply.IOCLogInfo) {
3467 printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
3475 * mpt2sas_port_enable_done - command completion routine for port enable
3476 * @ioc: per adapter object
3477 * @smid: system request message index
3478 * @msix_index: MSIX table index supplied by the OS
3479 * @reply: reply message frame(lower 32bit addr)
3481 * Return 1 meaning mf should be freed from _base_interrupt
3482 * 0 means the mf is freed from this function.
3485 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3488 MPI2DefaultReply_t *mpi_reply;
3491 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3492 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3495 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3498 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3500 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3501 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3502 mpi_reply->MsgLength*4);
3504 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3506 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3508 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3509 ioc->port_enable_failed = 1;
3511 if (ioc->is_driver_loading) {
3512 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3513 mpt2sas_port_enable_complete(ioc);
3516 ioc->start_scan_failed = ioc_status;
3517 ioc->start_scan = 0;
3521 complete(&ioc->port_enable_cmds.done);
3527 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3528 * @ioc: per adapter object
3529 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3531 * Returns 0 for success, non-zero for failure.
3534 _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3536 Mpi2PortEnableRequest_t *mpi_request;
3537 Mpi2PortEnableReply_t *mpi_reply;
3538 unsigned long timeleft;
3543 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3545 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3546 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3547 ioc->name, __func__);
3551 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3553 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3554 ioc->name, __func__);
3558 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3559 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3560 ioc->port_enable_cmds.smid = smid;
3561 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3562 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3564 init_completion(&ioc->port_enable_cmds.done);
3565 mpt2sas_base_put_smid_default(ioc, smid);
3566 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
3568 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
3569 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3570 ioc->name, __func__);
3571 _debug_dump_mf(mpi_request,
3572 sizeof(Mpi2PortEnableRequest_t)/4);
3573 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
3579 mpi_reply = ioc->port_enable_cmds.reply;
3581 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3582 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3583 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3584 ioc->name, __func__, ioc_status);
3589 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3590 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3591 "SUCCESS" : "FAILED"));
3596 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3597 * @ioc: per adapter object
3599 * Returns 0 for success, non-zero for failure.
3602 mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3604 Mpi2PortEnableRequest_t *mpi_request;
3607 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3609 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3610 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3611 ioc->name, __func__);
3615 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3617 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3618 ioc->name, __func__);
3622 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3623 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3624 ioc->port_enable_cmds.smid = smid;
3625 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3626 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3628 mpt2sas_base_put_smid_default(ioc, smid);
3633 * _base_determine_wait_on_discovery - desposition
3634 * @ioc: per adapter object
3636 * Decide whether to wait on discovery to complete. Used to either
3637 * locate boot device, or report volumes ahead of physical devices.
3639 * Returns 1 for wait, 0 for don't wait
3642 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3644 /* We wait for discovery to complete if IR firmware is loaded.
3645 * The sas topology events arrive before PD events, so we need time to
3646 * turn on the bit in ioc->pd_handles to indicate PD
3647 * Also, it maybe required to report Volumes ahead of physical
3648 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3650 if (ioc->ir_firmware)
3653 /* if no Bios, then we don't need to wait */
3654 if (!ioc->bios_pg3.BiosVersion)
3657 /* Bios is present, then we drop down here.
3659 * If there any entries in the Bios Page 2, then we wait
3660 * for discovery to complete.
3663 /* Current Boot Device */
3664 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3665 MPI2_BIOSPAGE2_FORM_MASK) ==
3666 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3667 /* Request Boot Device */
3668 (ioc->bios_pg2.ReqBootDeviceForm &
3669 MPI2_BIOSPAGE2_FORM_MASK) ==
3670 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3671 /* Alternate Request Boot Device */
3672 (ioc->bios_pg2.ReqAltBootDeviceForm &
3673 MPI2_BIOSPAGE2_FORM_MASK) ==
3674 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3682 * _base_unmask_events - turn on notification for this event
3683 * @ioc: per adapter object
3684 * @event: firmware event
3686 * The mask is stored in ioc->event_masks.
3689 _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
3696 desired_event = (1 << (event % 32));
3699 ioc->event_masks[0] &= ~desired_event;
3700 else if (event < 64)
3701 ioc->event_masks[1] &= ~desired_event;
3702 else if (event < 96)
3703 ioc->event_masks[2] &= ~desired_event;
3704 else if (event < 128)
3705 ioc->event_masks[3] &= ~desired_event;
3709 * _base_event_notification - send event notification
3710 * @ioc: per adapter object
3711 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3713 * Returns 0 for success, non-zero for failure.
3716 _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3718 Mpi2EventNotificationRequest_t *mpi_request;
3719 unsigned long timeleft;
3724 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3727 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
3728 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3729 ioc->name, __func__);
3733 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3735 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3736 ioc->name, __func__);
3739 ioc->base_cmds.status = MPT2_CMD_PENDING;
3740 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3741 ioc->base_cmds.smid = smid;
3742 memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
3743 mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
3744 mpi_request->VF_ID = 0; /* TODO */
3745 mpi_request->VP_ID = 0;
3746 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3747 mpi_request->EventMasks[i] =
3748 cpu_to_le32(ioc->event_masks[i]);
3749 mpt2sas_base_put_smid_default(ioc, smid);
3750 init_completion(&ioc->base_cmds.done);
3751 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
3752 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3753 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3754 ioc->name, __func__);
3755 _debug_dump_mf(mpi_request,
3756 sizeof(Mpi2EventNotificationRequest_t)/4);
3757 if (ioc->base_cmds.status & MPT2_CMD_RESET)
3762 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
3763 ioc->name, __func__));
3764 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3769 * mpt2sas_base_validate_event_type - validating event types
3770 * @ioc: per adapter object
3771 * @event: firmware event
3773 * This will turn on firmware event notification when application
3774 * ask for that event. We don't mask events that are already enabled.
3777 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
3780 u32 event_mask, desired_event;
3781 u8 send_update_to_fw;
3783 for (i = 0, send_update_to_fw = 0; i <
3784 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
3785 event_mask = ~event_type[i];
3787 for (j = 0; j < 32; j++) {
3788 if (!(event_mask & desired_event) &&
3789 (ioc->event_masks[i] & desired_event)) {
3790 ioc->event_masks[i] &= ~desired_event;
3791 send_update_to_fw = 1;
3793 desired_event = (desired_event << 1);
3797 if (!send_update_to_fw)
3800 mutex_lock(&ioc->base_cmds.mutex);
3801 _base_event_notification(ioc, CAN_SLEEP);
3802 mutex_unlock(&ioc->base_cmds.mutex);
3806 * _base_diag_reset - the "big hammer" start of day reset
3807 * @ioc: per adapter object
3808 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3810 * Returns 0 for success, non-zero for failure.
3813 _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3815 u32 host_diagnostic;
3820 printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
3821 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
3826 /* Write magic sequence to WriteSequence register
3827 * Loop until in diagnostic mode
3829 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
3830 "sequence\n", ioc->name));
3831 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3832 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
3833 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
3834 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
3835 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
3836 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
3837 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
3840 if (sleep_flag == CAN_SLEEP)
3848 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3849 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
3850 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3851 ioc->name, count, host_diagnostic));
3853 } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
3855 hcb_size = readl(&ioc->chip->HCBSize);
3857 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
3859 writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
3860 &ioc->chip->HostDiagnostic);
3862 /* don't access any registers for 50 milliseconds */
3865 /* 300 second max wait */
3866 for (count = 0; count < 3000000 ; count++) {
3868 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3870 if (host_diagnostic == 0xFFFFFFFF)
3872 if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
3876 if (sleep_flag == CAN_SLEEP)
3882 if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
3884 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
3885 "assuming the HCB Address points to good F/W\n",
3887 host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
3888 host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
3889 writel(host_diagnostic, &ioc->chip->HostDiagnostic);
3891 drsprintk(ioc, printk(MPT2SAS_INFO_FMT
3892 "re-enable the HCDW\n", ioc->name));
3893 writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
3894 &ioc->chip->HCBSize);
3897 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
3899 writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
3900 &ioc->chip->HostDiagnostic);
3902 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
3903 "diagnostic register\n", ioc->name));
3904 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3906 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
3907 "READY state\n", ioc->name));
3908 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
3911 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3912 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3916 printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
3920 printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
3925 * _base_make_ioc_ready - put controller in READY state
3926 * @ioc: per adapter object
3927 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3928 * @type: FORCE_BIG_HAMMER or SOFT_RESET
3930 * Returns 0 for success, non-zero for failure.
3933 _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
3934 enum reset_type type)
3939 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
3942 if (ioc->pci_error_recovery)
3945 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
3946 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
3947 ioc->name, __func__, ioc_state));
3949 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
3952 if (ioc_state & MPI2_DOORBELL_USED) {
3953 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
3954 "active!\n", ioc->name));
3955 goto issue_diag_reset;
3958 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
3959 mpt2sas_base_fault_info(ioc, ioc_state &
3960 MPI2_DOORBELL_DATA_MASK);
3961 goto issue_diag_reset;
3964 if (type == FORCE_BIG_HAMMER)
3965 goto issue_diag_reset;
3967 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
3968 if (!(_base_send_ioc_reset(ioc,
3969 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
3970 ioc->ioc_reset_count++;
3975 rc = _base_diag_reset(ioc, CAN_SLEEP);
3976 ioc->ioc_reset_count++;
3981 * _base_make_ioc_operational - put controller in OPERATIONAL state
3982 * @ioc: per adapter object
3983 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3985 * Returns 0 for success, non-zero for failure.
3988 _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3991 unsigned long flags;
3994 struct _tr_list *delayed_tr, *delayed_tr_next;
3996 struct adapter_reply_queue *reply_q;
3997 long reply_post_free;
3998 u32 reply_post_free_sz;
4000 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4003 /* clean the delayed target reset list */
4004 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4005 &ioc->delayed_tr_list, list) {
4006 list_del(&delayed_tr->list);
4010 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4011 &ioc->delayed_tr_volume_list, list) {
4012 list_del(&delayed_tr->list);
4016 /* initialize the scsi lookup free list */
4017 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4018 INIT_LIST_HEAD(&ioc->free_list);
4020 for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
4021 INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
4022 ioc->scsi_lookup[i].cb_idx = 0xFF;
4023 ioc->scsi_lookup[i].smid = smid;
4024 ioc->scsi_lookup[i].scmd = NULL;
4025 ioc->scsi_lookup[i].direct_io = 0;
4026 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4030 /* hi-priority queue */
4031 INIT_LIST_HEAD(&ioc->hpr_free_list);
4032 smid = ioc->hi_priority_smid;
4033 for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
4034 ioc->hpr_lookup[i].cb_idx = 0xFF;
4035 ioc->hpr_lookup[i].smid = smid;
4036 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
4037 &ioc->hpr_free_list);
4040 /* internal queue */
4041 INIT_LIST_HEAD(&ioc->internal_free_list);
4042 smid = ioc->internal_smid;
4043 for (i = 0; i < ioc->internal_depth; i++, smid++) {
4044 ioc->internal_lookup[i].cb_idx = 0xFF;
4045 ioc->internal_lookup[i].smid = smid;
4046 list_add_tail(&ioc->internal_lookup[i].tracker_list,
4047 &ioc->internal_free_list);
4051 INIT_LIST_HEAD(&ioc->free_chain_list);
4052 for (i = 0; i < ioc->chain_depth; i++)
4053 list_add_tail(&ioc->chain_lookup[i].tracker_list,
4054 &ioc->free_chain_list);
4056 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4058 /* initialize Reply Free Queue */
4059 for (i = 0, reply_address = (u32)ioc->reply_dma ;
4060 i < ioc->reply_free_queue_depth ; i++, reply_address +=
4062 ioc->reply_free[i] = cpu_to_le32(reply_address);
4064 /* initialize reply queues */
4065 _base_assign_reply_queues(ioc);
4067 /* initialize Reply Post Free Queue */
4068 reply_post_free = (long)ioc->reply_post_free;
4069 reply_post_free_sz = ioc->reply_post_queue_depth *
4070 sizeof(Mpi2DefaultReplyDescriptor_t);
4071 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4072 reply_q->reply_post_host_index = 0;
4073 reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
4075 for (i = 0; i < ioc->reply_post_queue_depth; i++)
4076 reply_q->reply_post_free[i].Words =
4077 cpu_to_le64(ULLONG_MAX);
4078 if (!_base_is_controller_msix_enabled(ioc))
4079 goto skip_init_reply_post_free_queue;
4080 reply_post_free += reply_post_free_sz;
4082 skip_init_reply_post_free_queue:
4084 r = _base_send_ioc_init(ioc, sleep_flag);
4088 /* initialize reply free host index */
4089 ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
4090 writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
4092 /* initialize reply post host index */
4093 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4094 writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
4095 &ioc->chip->ReplyPostHostIndex);
4096 if (!_base_is_controller_msix_enabled(ioc))
4097 goto skip_init_reply_post_host_index;
4100 skip_init_reply_post_host_index:
4102 _base_unmask_interrupts(ioc);
4104 r = _base_event_notification(ioc, sleep_flag);
4108 if (sleep_flag == CAN_SLEEP)
4109 _base_static_config_pages(ioc);
4112 if (ioc->is_driver_loading) {
4116 ioc->wait_for_discovery_to_complete =
4117 _base_determine_wait_on_discovery(ioc);
4118 return r; /* scan_start and scan_finished support */
4122 if (ioc->wait_for_discovery_to_complete && ioc->is_warpdrive) {
4123 if (ioc->manu_pg10.OEMIdentifier == 0x80) {
4124 hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 &
4125 MFG_PAGE10_HIDE_SSDS_MASK);
4126 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
4127 ioc->mfg_pg10_hide_flag = hide_flag;
4131 r = _base_send_port_enable(ioc, sleep_flag);
4139 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4140 * @ioc: per adapter object
4145 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
4147 struct pci_dev *pdev = ioc->pdev;
4149 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4152 _base_mask_interrupts(ioc);
4153 ioc->shost_recovery = 1;
4154 _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4155 ioc->shost_recovery = 0;
4156 _base_free_irq(ioc);
4157 _base_disable_msix(ioc);
4161 pci_release_selected_regions(ioc->pdev, ioc->bars);
4162 pci_disable_pcie_error_reporting(pdev);
4163 pci_disable_device(pdev);
4168 * mpt2sas_base_attach - attach controller instance
4169 * @ioc: per adapter object
4171 * Returns 0 for success, non-zero for failure.
4174 mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4177 int cpu_id, last_cpu_id = 0;
4179 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4182 /* setup cpu_msix_table */
4183 ioc->cpu_count = num_online_cpus();
4184 for_each_online_cpu(cpu_id)
4185 last_cpu_id = cpu_id;
4186 ioc->cpu_msix_table_sz = last_cpu_id + 1;
4187 ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
4188 ioc->reply_queue_count = 1;
4189 if (!ioc->cpu_msix_table) {
4190 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
4191 "cpu_msix_table failed!!!\n", ioc->name));
4193 goto out_free_resources;
4196 if (ioc->is_warpdrive) {
4197 ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
4198 sizeof(resource_size_t *), GFP_KERNEL);
4199 if (!ioc->reply_post_host_index) {
4200 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
4201 "for cpu_msix_table failed!!!\n", ioc->name));
4203 goto out_free_resources;
4207 r = mpt2sas_base_map_resources(ioc);
4211 if (ioc->is_warpdrive) {
4212 ioc->reply_post_host_index[0] =
4213 (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
4215 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
4216 ioc->reply_post_host_index[i] = (resource_size_t *)
4217 ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
4221 pci_set_drvdata(ioc->pdev, ioc->shost);
4222 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
4224 goto out_free_resources;
4226 r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
4228 goto out_free_resources;
4230 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
4231 sizeof(Mpi2PortFactsReply_t), GFP_KERNEL);
4234 goto out_free_resources;
4237 for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
4238 r = _base_get_port_facts(ioc, i, CAN_SLEEP);
4240 goto out_free_resources;
4243 r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
4245 goto out_free_resources;
4247 init_waitqueue_head(&ioc->reset_wq);
4249 /* allocate memory pd handle bitmask list */
4250 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
4251 if (ioc->facts.MaxDevHandle % 8)
4252 ioc->pd_handles_sz++;
4253 ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
4255 if (!ioc->pd_handles) {
4257 goto out_free_resources;
4260 ioc->fwfault_debug = mpt2sas_fwfault_debug;
4262 /* base internal command bits */
4263 mutex_init(&ioc->base_cmds.mutex);
4264 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4265 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4267 /* port_enable command bits */
4268 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4269 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4271 /* transport internal command bits */
4272 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4273 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
4274 mutex_init(&ioc->transport_cmds.mutex);
4276 /* scsih internal command bits */
4277 ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4278 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
4279 mutex_init(&ioc->scsih_cmds.mutex);
4281 /* task management internal command bits */
4282 ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4283 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4284 mutex_init(&ioc->tm_cmds.mutex);
4286 /* config page internal command bits */
4287 ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4288 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
4289 mutex_init(&ioc->config_cmds.mutex);
4291 /* ctl module internal command bits */
4292 ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4293 ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
4294 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
4295 mutex_init(&ioc->ctl_cmds.mutex);
4297 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4298 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4299 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
4300 !ioc->ctl_cmds.sense) {
4302 goto out_free_resources;
4305 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4306 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4307 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
4309 goto out_free_resources;
4312 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4313 ioc->event_masks[i] = -1;
4315 /* here we enable the events we care about */
4316 _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
4317 _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
4318 _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
4319 _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4320 _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
4321 _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
4322 _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
4323 _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
4324 _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
4325 _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
4326 r = _base_make_ioc_operational(ioc, CAN_SLEEP);
4328 goto out_free_resources;
4330 if (missing_delay[0] != -1 && missing_delay[1] != -1)
4331 _base_update_missing_delay(ioc, missing_delay[0],
4338 ioc->remove_host = 1;
4339 mpt2sas_base_free_resources(ioc);
4340 _base_release_memory_pools(ioc);
4341 pci_set_drvdata(ioc->pdev, NULL);
4342 kfree(ioc->cpu_msix_table);
4343 if (ioc->is_warpdrive)
4344 kfree(ioc->reply_post_host_index);
4345 kfree(ioc->pd_handles);
4346 kfree(ioc->tm_cmds.reply);
4347 kfree(ioc->transport_cmds.reply);
4348 kfree(ioc->scsih_cmds.reply);
4349 kfree(ioc->config_cmds.reply);
4350 kfree(ioc->base_cmds.reply);
4351 kfree(ioc->port_enable_cmds.reply);
4352 kfree(ioc->ctl_cmds.reply);
4353 kfree(ioc->ctl_cmds.sense);
4355 ioc->ctl_cmds.reply = NULL;
4356 ioc->base_cmds.reply = NULL;
4357 ioc->tm_cmds.reply = NULL;
4358 ioc->scsih_cmds.reply = NULL;
4359 ioc->transport_cmds.reply = NULL;
4360 ioc->config_cmds.reply = NULL;
4367 * mpt2sas_base_detach - remove controller instance
4368 * @ioc: per adapter object
4373 mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4376 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
4379 mpt2sas_base_stop_watchdog(ioc);
4380 mpt2sas_base_free_resources(ioc);
4381 _base_release_memory_pools(ioc);
4382 pci_set_drvdata(ioc->pdev, NULL);
4383 kfree(ioc->cpu_msix_table);
4384 if (ioc->is_warpdrive)
4385 kfree(ioc->reply_post_host_index);
4386 kfree(ioc->pd_handles);
4388 kfree(ioc->ctl_cmds.reply);
4389 kfree(ioc->ctl_cmds.sense);
4390 kfree(ioc->base_cmds.reply);
4391 kfree(ioc->port_enable_cmds.reply);
4392 kfree(ioc->tm_cmds.reply);
4393 kfree(ioc->transport_cmds.reply);
4394 kfree(ioc->scsih_cmds.reply);
4395 kfree(ioc->config_cmds.reply);
4399 * _base_reset_handler - reset callback handler (for base)
4400 * @ioc: per adapter object
4401 * @reset_phase: phase
4403 * The handler for doing any required cleanup or initialization.
4405 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4406 * MPT2_IOC_DONE_RESET
4411 _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4413 mpt2sas_scsih_reset_handler(ioc, reset_phase);
4414 mpt2sas_ctl_reset_handler(ioc, reset_phase);
4415 switch (reset_phase) {
4416 case MPT2_IOC_PRE_RESET:
4417 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4418 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
4420 case MPT2_IOC_AFTER_RESET:
4421 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4422 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
4423 if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
4424 ioc->transport_cmds.status |= MPT2_CMD_RESET;
4425 mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
4426 complete(&ioc->transport_cmds.done);
4428 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
4429 ioc->base_cmds.status |= MPT2_CMD_RESET;
4430 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4431 complete(&ioc->base_cmds.done);
4433 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4434 ioc->port_enable_failed = 1;
4435 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4436 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4437 if (ioc->is_driver_loading) {
4438 ioc->start_scan_failed =
4439 MPI2_IOCSTATUS_INTERNAL_ERROR;
4440 ioc->start_scan = 0;
4441 ioc->port_enable_cmds.status =
4444 complete(&ioc->port_enable_cmds.done);
4447 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4448 ioc->config_cmds.status |= MPT2_CMD_RESET;
4449 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
4450 ioc->config_cmds.smid = USHRT_MAX;
4451 complete(&ioc->config_cmds.done);
4454 case MPT2_IOC_DONE_RESET:
4455 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
4456 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
4462 * _wait_for_commands_to_complete - reset controller
4463 * @ioc: Pointer to MPT_ADAPTER structure
4464 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4466 * This function waiting(3s) for all pending commands to complete
4467 * prior to putting controller in reset.
4470 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4473 unsigned long flags;
4476 ioc->pending_io_count = 0;
4477 if (sleep_flag != CAN_SLEEP)
4480 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4481 if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
4484 /* pending command count */
4485 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4486 for (i = 0; i < ioc->scsiio_depth; i++)
4487 if (ioc->scsi_lookup[i].cb_idx != 0xFF)
4488 ioc->pending_io_count++;
4489 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4491 if (!ioc->pending_io_count)
4494 /* wait for pending commands to complete */
4495 wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
4499 * mpt2sas_base_hard_reset_handler - reset controller
4500 * @ioc: Pointer to MPT_ADAPTER structure
4501 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4502 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4504 * Returns 0 for success, non-zero for failure.
4507 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4508 enum reset_type type)
4511 unsigned long flags;
4513 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
4516 if (ioc->pci_error_recovery) {
4517 printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
4518 ioc->name, __func__);
4523 if (mpt2sas_fwfault_debug)
4524 mpt2sas_halt_firmware(ioc);
4526 /* TODO - What we really should be doing is pulling
4527 * out all the code associated with NO_SLEEP; its never used.
4528 * That is legacy code from mpt fusion driver, ported over.
4529 * I will leave this BUG_ON here for now till its been resolved.
4531 BUG_ON(sleep_flag == NO_SLEEP);
4533 /* wait for an active reset in progress to complete */
4534 if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
4537 } while (ioc->shost_recovery == 1);
4538 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
4540 return ioc->ioc_reset_in_progress_status;
4543 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4544 ioc->shost_recovery = 1;
4545 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4547 _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
4548 _wait_for_commands_to_complete(ioc, sleep_flag);
4549 _base_mask_interrupts(ioc);
4550 r = _base_make_ioc_ready(ioc, sleep_flag, type);
4553 _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
4555 /* If this hard reset is called while port enable is active, then
4556 * there is no reason to call make_ioc_operational
4558 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4559 ioc->remove_host = 1;
4563 r = _base_make_ioc_operational(ioc, sleep_flag);
4565 _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
4567 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
4568 ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
4570 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4571 ioc->ioc_reset_in_progress_status = r;
4572 ioc->shost_recovery = 0;
4573 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4574 mutex_unlock(&ioc->reset_in_progress_mutex);
4576 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,