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/mpt3sas/mpt3sas_base.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * Copyright (C) 2013-2014 Avago Technologies
8 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 * solely responsible for determining the appropriateness of using and
26 * distributing the Program and assumes all risks associated with its
27 * exercise of rights under this Agreement, including but not limited to
28 * the risks and costs of program errors, damage to or loss of data,
29 * programs or equipment, and unavailability or interruption of operations.
31 * DISCLAIMER OF LIABILITY
32 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/slab.h>
51 #include <linux/types.h>
52 #include <linux/pci.h>
53 #include <linux/kdev_t.h>
54 #include <linux/blkdev.h>
55 #include <linux/delay.h>
56 #include <linux/interrupt.h>
57 #include <linux/dma-mapping.h>
59 #include <linux/time.h>
60 #include <linux/kthread.h>
61 #include <linux/aer.h>
64 #include "mpt3sas_base.h"
66 static MPT_CALLBACK mpt_callbacks
[MPT_MAX_CALLBACKS
];
69 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
71 /* maximum controller queue depth */
72 #define MAX_HBA_QUEUE_DEPTH 30000
73 #define MAX_CHAIN_DEPTH 100000
74 static int max_queue_depth
= -1;
75 module_param(max_queue_depth
, int, 0);
76 MODULE_PARM_DESC(max_queue_depth
, " max controller queue depth ");
78 static int max_sgl_entries
= -1;
79 module_param(max_sgl_entries
, int, 0);
80 MODULE_PARM_DESC(max_sgl_entries
, " max sg entries ");
82 static int msix_disable
= -1;
83 module_param(msix_disable
, int, 0);
84 MODULE_PARM_DESC(msix_disable
, " disable msix routed interrupts (default=0)");
86 static int max_msix_vectors
= -1;
87 module_param(max_msix_vectors
, int, 0);
88 MODULE_PARM_DESC(max_msix_vectors
,
91 static int mpt3sas_fwfault_debug
;
92 MODULE_PARM_DESC(mpt3sas_fwfault_debug
,
93 " enable detection of firmware fault and halt firmware - (default=0)");
96 _base_get_ioc_facts(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
);
99 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
103 _scsih_set_fwfault_debug(const char *val
, struct kernel_param
*kp
)
105 int ret
= param_set_int(val
, kp
);
106 struct MPT3SAS_ADAPTER
*ioc
;
111 /* global ioc spinlock to protect controller list on list operations */
112 pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug
);
113 spin_lock(&gioc_lock
);
114 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
115 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
116 spin_unlock(&gioc_lock
);
119 module_param_call(mpt3sas_fwfault_debug
, _scsih_set_fwfault_debug
,
120 param_get_int
, &mpt3sas_fwfault_debug
, 0644);
123 * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc
124 * @arg: input argument, used to derive ioc
126 * Return 0 if controller is removed from pci subsystem.
127 * Return -1 for other case.
129 static int mpt3sas_remove_dead_ioc_func(void *arg
)
131 struct MPT3SAS_ADAPTER
*ioc
= (struct MPT3SAS_ADAPTER
*)arg
;
132 struct pci_dev
*pdev
;
140 pci_stop_and_remove_bus_device_locked(pdev
);
145 * _base_fault_reset_work - workq handling ioc fault conditions
146 * @work: input argument, used to derive ioc
152 _base_fault_reset_work(struct work_struct
*work
)
154 struct MPT3SAS_ADAPTER
*ioc
=
155 container_of(work
, struct MPT3SAS_ADAPTER
, fault_reset_work
.work
);
159 struct task_struct
*p
;
162 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
163 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
165 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
167 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
168 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_MASK
) {
169 pr_err(MPT3SAS_FMT
"SAS host is non-operational !!!!\n",
172 /* It may be possible that EEH recovery can resolve some of
173 * pci bus failure issues rather removing the dead ioc function
174 * by considering controller is in a non-operational state. So
175 * here priority is given to the EEH recovery. If it doesn't
176 * not resolve this issue, mpt3sas driver will consider this
177 * controller to non-operational state and remove the dead ioc
180 if (ioc
->non_operational_loop
++ < 5) {
181 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
,
187 * Call _scsih_flush_pending_cmds callback so that we flush all
188 * pending commands back to OS. This call is required to aovid
189 * deadlock at block layer. Dead IOC will fail to do diag reset,
190 * and this call is safe since dead ioc will never return any
191 * command back from HW.
193 ioc
->schedule_dead_ioc_flush_running_cmds(ioc
);
195 * Set remove_host flag early since kernel thread will
196 * take some time to execute.
198 ioc
->remove_host
= 1;
199 /*Remove the Dead Host */
200 p
= kthread_run(mpt3sas_remove_dead_ioc_func
, ioc
,
201 "%s_dead_ioc_%d", ioc
->driver_name
, ioc
->id
);
204 "%s: Running mpt3sas_dead_ioc thread failed !!!!\n",
205 ioc
->name
, __func__
);
208 "%s: Running mpt3sas_dead_ioc thread success !!!!\n",
209 ioc
->name
, __func__
);
210 return; /* don't rearm timer */
213 ioc
->non_operational_loop
= 0;
215 if ((doorbell
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
) {
216 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
218 pr_warn(MPT3SAS_FMT
"%s: hard reset: %s\n", ioc
->name
,
219 __func__
, (rc
== 0) ? "success" : "failed");
220 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
221 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
222 mpt3sas_base_fault_info(ioc
, doorbell
&
223 MPI2_DOORBELL_DATA_MASK
);
224 if (rc
&& (doorbell
& MPI2_IOC_STATE_MASK
) !=
225 MPI2_IOC_STATE_OPERATIONAL
)
226 return; /* don't rearm timer */
229 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
231 if (ioc
->fault_reset_work_q
)
232 queue_delayed_work(ioc
->fault_reset_work_q
,
233 &ioc
->fault_reset_work
,
234 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
235 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
239 * mpt3sas_base_start_watchdog - start the fault_reset_work_q
240 * @ioc: per adapter object
246 mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
250 if (ioc
->fault_reset_work_q
)
253 /* initialize fault polling */
255 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, _base_fault_reset_work
);
256 snprintf(ioc
->fault_reset_work_q_name
,
257 sizeof(ioc
->fault_reset_work_q_name
), "poll_%s%d_status",
258 ioc
->driver_name
, ioc
->id
);
259 ioc
->fault_reset_work_q
=
260 create_singlethread_workqueue(ioc
->fault_reset_work_q_name
);
261 if (!ioc
->fault_reset_work_q
) {
262 pr_err(MPT3SAS_FMT
"%s: failed (line=%d)\n",
263 ioc
->name
, __func__
, __LINE__
);
266 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
267 if (ioc
->fault_reset_work_q
)
268 queue_delayed_work(ioc
->fault_reset_work_q
,
269 &ioc
->fault_reset_work
,
270 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
271 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
275 * mpt3sas_base_stop_watchdog - stop the fault_reset_work_q
276 * @ioc: per adapter object
282 mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
285 struct workqueue_struct
*wq
;
287 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
288 wq
= ioc
->fault_reset_work_q
;
289 ioc
->fault_reset_work_q
= NULL
;
290 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
292 if (!cancel_delayed_work_sync(&ioc
->fault_reset_work
))
294 destroy_workqueue(wq
);
299 * mpt3sas_base_fault_info - verbose translation of firmware FAULT code
300 * @ioc: per adapter object
301 * @fault_code: fault code
306 mpt3sas_base_fault_info(struct MPT3SAS_ADAPTER
*ioc
, u16 fault_code
)
308 pr_err(MPT3SAS_FMT
"fault_state(0x%04x)!\n",
309 ioc
->name
, fault_code
);
313 * mpt3sas_halt_firmware - halt's mpt controller firmware
314 * @ioc: per adapter object
316 * For debugging timeout related issues. Writing 0xCOFFEE00
317 * to the doorbell register will halt controller firmware. With
318 * the purpose to stop both driver and firmware, the enduser can
319 * obtain a ring buffer from controller UART.
322 mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER
*ioc
)
326 if (!ioc
->fwfault_debug
)
331 doorbell
= readl(&ioc
->chip
->Doorbell
);
332 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
333 mpt3sas_base_fault_info(ioc
, doorbell
);
335 writel(0xC0FFEE00, &ioc
->chip
->Doorbell
);
336 pr_err(MPT3SAS_FMT
"Firmware is halted due to command timeout\n",
340 if (ioc
->fwfault_debug
== 2)
344 panic("panic in %s\n", __func__
);
348 * _base_sas_ioc_info - verbose translation of the ioc status
349 * @ioc: per adapter object
350 * @mpi_reply: reply mf payload returned from firmware
351 * @request_hdr: request mf
356 _base_sas_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, MPI2DefaultReply_t
*mpi_reply
,
357 MPI2RequestHeader_t
*request_hdr
)
359 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
363 char *func_str
= NULL
;
365 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
366 if (request_hdr
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
367 request_hdr
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
368 request_hdr
->Function
== MPI2_FUNCTION_EVENT_NOTIFICATION
)
371 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
374 switch (ioc_status
) {
376 /****************************************************************************
377 * Common IOCStatus values for all replies
378 ****************************************************************************/
380 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
381 desc
= "invalid function";
383 case MPI2_IOCSTATUS_BUSY
:
386 case MPI2_IOCSTATUS_INVALID_SGL
:
387 desc
= "invalid sgl";
389 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
390 desc
= "internal error";
392 case MPI2_IOCSTATUS_INVALID_VPID
:
393 desc
= "invalid vpid";
395 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
396 desc
= "insufficient resources";
398 case MPI2_IOCSTATUS_INVALID_FIELD
:
399 desc
= "invalid field";
401 case MPI2_IOCSTATUS_INVALID_STATE
:
402 desc
= "invalid state";
404 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED
:
405 desc
= "op state not supported";
408 /****************************************************************************
409 * Config IOCStatus values
410 ****************************************************************************/
412 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION
:
413 desc
= "config invalid action";
415 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE
:
416 desc
= "config invalid type";
418 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
:
419 desc
= "config invalid page";
421 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA
:
422 desc
= "config invalid data";
424 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS
:
425 desc
= "config no defaults";
427 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT
:
428 desc
= "config cant commit";
431 /****************************************************************************
433 ****************************************************************************/
435 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
436 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
437 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
438 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
439 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
440 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
441 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
442 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
443 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
444 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
445 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
446 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
449 /****************************************************************************
450 * For use by SCSI Initiator and SCSI Target end-to-end data protection
451 ****************************************************************************/
453 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
454 desc
= "eedp guard error";
456 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
457 desc
= "eedp ref tag error";
459 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
460 desc
= "eedp app tag error";
463 /****************************************************************************
465 ****************************************************************************/
467 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX
:
468 desc
= "target invalid io index";
470 case MPI2_IOCSTATUS_TARGET_ABORTED
:
471 desc
= "target aborted";
473 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
:
474 desc
= "target no conn retryable";
476 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION
:
477 desc
= "target no connection";
479 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
:
480 desc
= "target xfer count mismatch";
482 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
:
483 desc
= "target data offset error";
485 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
:
486 desc
= "target too much write data";
488 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT
:
489 desc
= "target iu too short";
491 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
:
492 desc
= "target ack nak timeout";
494 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED
:
495 desc
= "target nak received";
498 /****************************************************************************
499 * Serial Attached SCSI values
500 ****************************************************************************/
502 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED
:
503 desc
= "smp request failed";
505 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN
:
506 desc
= "smp data overrun";
509 /****************************************************************************
510 * Diagnostic Buffer Post / Diagnostic Release values
511 ****************************************************************************/
513 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
:
514 desc
= "diagnostic released";
523 switch (request_hdr
->Function
) {
524 case MPI2_FUNCTION_CONFIG
:
525 frame_sz
= sizeof(Mpi2ConfigRequest_t
) + ioc
->sge_size
;
526 func_str
= "config_page";
528 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
529 frame_sz
= sizeof(Mpi2SCSITaskManagementRequest_t
);
530 func_str
= "task_mgmt";
532 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
533 frame_sz
= sizeof(Mpi2SasIoUnitControlRequest_t
);
534 func_str
= "sas_iounit_ctl";
536 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
537 frame_sz
= sizeof(Mpi2SepRequest_t
);
538 func_str
= "enclosure";
540 case MPI2_FUNCTION_IOC_INIT
:
541 frame_sz
= sizeof(Mpi2IOCInitRequest_t
);
542 func_str
= "ioc_init";
544 case MPI2_FUNCTION_PORT_ENABLE
:
545 frame_sz
= sizeof(Mpi2PortEnableRequest_t
);
546 func_str
= "port_enable";
548 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
549 frame_sz
= sizeof(Mpi2SmpPassthroughRequest_t
) + ioc
->sge_size
;
550 func_str
= "smp_passthru";
554 func_str
= "unknown";
558 pr_warn(MPT3SAS_FMT
"ioc_status: %s(0x%04x), request(0x%p),(%s)\n",
559 ioc
->name
, desc
, ioc_status
, request_hdr
, func_str
);
561 _debug_dump_mf(request_hdr
, frame_sz
/4);
565 * _base_display_event_data - verbose translation of firmware asyn events
566 * @ioc: per adapter object
567 * @mpi_reply: reply mf payload returned from firmware
572 _base_display_event_data(struct MPT3SAS_ADAPTER
*ioc
,
573 Mpi2EventNotificationReply_t
*mpi_reply
)
578 if (!(ioc
->logging_level
& MPT_DEBUG_EVENTS
))
581 event
= le16_to_cpu(mpi_reply
->Event
);
584 case MPI2_EVENT_LOG_DATA
:
587 case MPI2_EVENT_STATE_CHANGE
:
588 desc
= "Status Change";
590 case MPI2_EVENT_HARD_RESET_RECEIVED
:
591 desc
= "Hard Reset Received";
593 case MPI2_EVENT_EVENT_CHANGE
:
594 desc
= "Event Change";
596 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
597 desc
= "Device Status Change";
599 case MPI2_EVENT_IR_OPERATION_STATUS
:
600 if (!ioc
->hide_ir_msg
)
601 desc
= "IR Operation Status";
603 case MPI2_EVENT_SAS_DISCOVERY
:
605 Mpi2EventDataSasDiscovery_t
*event_data
=
606 (Mpi2EventDataSasDiscovery_t
*)mpi_reply
->EventData
;
607 pr_info(MPT3SAS_FMT
"Discovery: (%s)", ioc
->name
,
608 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
610 if (event_data
->DiscoveryStatus
)
611 pr_info("discovery_status(0x%08x)",
612 le32_to_cpu(event_data
->DiscoveryStatus
));
616 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
617 desc
= "SAS Broadcast Primitive";
619 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
620 desc
= "SAS Init Device Status Change";
622 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW
:
623 desc
= "SAS Init Table Overflow";
625 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
626 desc
= "SAS Topology Change List";
628 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
629 desc
= "SAS Enclosure Device Status Change";
631 case MPI2_EVENT_IR_VOLUME
:
632 if (!ioc
->hide_ir_msg
)
635 case MPI2_EVENT_IR_PHYSICAL_DISK
:
636 if (!ioc
->hide_ir_msg
)
637 desc
= "IR Physical Disk";
639 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
640 if (!ioc
->hide_ir_msg
)
641 desc
= "IR Configuration Change List";
643 case MPI2_EVENT_LOG_ENTRY_ADDED
:
644 if (!ioc
->hide_ir_msg
)
645 desc
= "Log Entry Added";
647 case MPI2_EVENT_TEMP_THRESHOLD
:
648 desc
= "Temperature Threshold";
655 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
, desc
);
659 * _base_sas_log_info - verbose translation of firmware log info
660 * @ioc: per adapter object
661 * @log_info: log info
666 _base_sas_log_info(struct MPT3SAS_ADAPTER
*ioc
, u32 log_info
)
677 union loginfo_type sas_loginfo
;
678 char *originator_str
= NULL
;
680 sas_loginfo
.loginfo
= log_info
;
681 if (sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/)
684 /* each nexus loss loginfo */
685 if (log_info
== 0x31170000)
688 /* eat the loginfos associated with task aborts */
689 if (ioc
->ignore_loginfos
&& (log_info
== 0x30050000 || log_info
==
690 0x31140000 || log_info
== 0x31130000))
693 switch (sas_loginfo
.dw
.originator
) {
695 originator_str
= "IOP";
698 originator_str
= "PL";
701 if (!ioc
->hide_ir_msg
)
702 originator_str
= "IR";
704 originator_str
= "WarpDrive";
709 "log_info(0x%08x): originator(%s), code(0x%02x), sub_code(0x%04x)\n",
711 originator_str
, sas_loginfo
.dw
.code
,
712 sas_loginfo
.dw
.subcode
);
716 * _base_display_reply_info -
717 * @ioc: per adapter object
718 * @smid: system request message index
719 * @msix_index: MSIX table index supplied by the OS
720 * @reply: reply message frame(lower 32bit addr)
725 _base_display_reply_info(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
728 MPI2DefaultReply_t
*mpi_reply
;
732 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
733 if (unlikely(!mpi_reply
)) {
734 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
735 ioc
->name
, __FILE__
, __LINE__
, __func__
);
738 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
740 if ((ioc_status
& MPI2_IOCSTATUS_MASK
) &&
741 (ioc
->logging_level
& MPT_DEBUG_REPLY
)) {
742 _base_sas_ioc_info(ioc
, mpi_reply
,
743 mpt3sas_base_get_msg_frame(ioc
, smid
));
746 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
) {
747 loginfo
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
748 _base_sas_log_info(ioc
, loginfo
);
751 if (ioc_status
|| loginfo
) {
752 ioc_status
&= MPI2_IOCSTATUS_MASK
;
753 mpt3sas_trigger_mpi(ioc
, ioc_status
, loginfo
);
758 * mpt3sas_base_done - base internal command completion routine
759 * @ioc: per adapter object
760 * @smid: system request message index
761 * @msix_index: MSIX table index supplied by the OS
762 * @reply: reply message frame(lower 32bit addr)
764 * Return 1 meaning mf should be freed from _base_interrupt
765 * 0 means the mf is freed from this function.
768 mpt3sas_base_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
771 MPI2DefaultReply_t
*mpi_reply
;
773 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
774 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
777 if (ioc
->base_cmds
.status
== MPT3_CMD_NOT_USED
)
780 ioc
->base_cmds
.status
|= MPT3_CMD_COMPLETE
;
782 ioc
->base_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
783 memcpy(ioc
->base_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
785 ioc
->base_cmds
.status
&= ~MPT3_CMD_PENDING
;
787 complete(&ioc
->base_cmds
.done
);
792 * _base_async_event - main callback handler for firmware asyn events
793 * @ioc: per adapter object
794 * @msix_index: MSIX table index supplied by the OS
795 * @reply: reply message frame(lower 32bit addr)
797 * Return 1 meaning mf should be freed from _base_interrupt
798 * 0 means the mf is freed from this function.
801 _base_async_event(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
, u32 reply
)
803 Mpi2EventNotificationReply_t
*mpi_reply
;
804 Mpi2EventAckRequest_t
*ack_request
;
807 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
810 if (mpi_reply
->Function
!= MPI2_FUNCTION_EVENT_NOTIFICATION
)
813 _base_display_event_data(ioc
, mpi_reply
);
815 if (!(mpi_reply
->AckRequired
& MPI2_EVENT_NOTIFICATION_ACK_REQUIRED
))
817 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
819 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
820 ioc
->name
, __func__
);
824 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
825 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
826 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
827 ack_request
->Event
= mpi_reply
->Event
;
828 ack_request
->EventContext
= mpi_reply
->EventContext
;
829 ack_request
->VF_ID
= 0; /* TODO */
830 ack_request
->VP_ID
= 0;
831 mpt3sas_base_put_smid_default(ioc
, smid
);
835 /* scsih callback handler */
836 mpt3sas_scsih_event_callback(ioc
, msix_index
, reply
);
838 /* ctl callback handler */
839 mpt3sas_ctl_event_callback(ioc
, msix_index
, reply
);
845 * _base_get_cb_idx - obtain the callback index
846 * @ioc: per adapter object
847 * @smid: system request message index
849 * Return callback index.
852 _base_get_cb_idx(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
857 if (smid
< ioc
->hi_priority_smid
) {
859 cb_idx
= ioc
->scsi_lookup
[i
].cb_idx
;
860 } else if (smid
< ioc
->internal_smid
) {
861 i
= smid
- ioc
->hi_priority_smid
;
862 cb_idx
= ioc
->hpr_lookup
[i
].cb_idx
;
863 } else if (smid
<= ioc
->hba_queue_depth
) {
864 i
= smid
- ioc
->internal_smid
;
865 cb_idx
= ioc
->internal_lookup
[i
].cb_idx
;
872 * _base_mask_interrupts - disable interrupts
873 * @ioc: per adapter object
875 * Disabling ResetIRQ, Reply and Doorbell Interrupts
880 _base_mask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
884 ioc
->mask_interrupts
= 1;
885 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
886 him_register
|= MPI2_HIM_DIM
+ MPI2_HIM_RIM
+ MPI2_HIM_RESET_IRQ_MASK
;
887 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
888 readl(&ioc
->chip
->HostInterruptMask
);
892 * _base_unmask_interrupts - enable interrupts
893 * @ioc: per adapter object
895 * Enabling only Reply Interrupts
900 _base_unmask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
904 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
905 him_register
&= ~MPI2_HIM_RIM
;
906 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
907 ioc
->mask_interrupts
= 0;
910 union reply_descriptor
{
919 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
920 * @irq: irq number (not used)
921 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
922 * @r: pt_regs pointer (not used)
924 * Return IRQ_HANDLE if processed, else IRQ_NONE.
927 _base_interrupt(int irq
, void *bus_id
)
929 struct adapter_reply_queue
*reply_q
= bus_id
;
930 union reply_descriptor rd
;
932 u8 request_desript_type
;
936 u8 msix_index
= reply_q
->msix_index
;
937 struct MPT3SAS_ADAPTER
*ioc
= reply_q
->ioc
;
938 Mpi2ReplyDescriptorsUnion_t
*rpf
;
941 if (ioc
->mask_interrupts
)
944 if (!atomic_add_unless(&reply_q
->busy
, 1, 1))
947 rpf
= &reply_q
->reply_post_free
[reply_q
->reply_post_host_index
];
948 request_desript_type
= rpf
->Default
.ReplyFlags
949 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
950 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
) {
951 atomic_dec(&reply_q
->busy
);
958 rd
.word
= le64_to_cpu(rpf
->Words
);
959 if (rd
.u
.low
== UINT_MAX
|| rd
.u
.high
== UINT_MAX
)
962 smid
= le16_to_cpu(rpf
->Default
.DescriptorTypeDependent1
);
963 if (request_desript_type
==
964 MPI25_RPY_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO_SUCCESS
||
965 request_desript_type
==
966 MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS
) {
967 cb_idx
= _base_get_cb_idx(ioc
, smid
);
968 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
969 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
970 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
973 mpt3sas_base_free_smid(ioc
, smid
);
975 } else if (request_desript_type
==
976 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY
) {
978 rpf
->AddressReply
.ReplyFrameAddress
);
979 if (reply
> ioc
->reply_dma_max_address
||
980 reply
< ioc
->reply_dma_min_address
)
983 cb_idx
= _base_get_cb_idx(ioc
, smid
);
984 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
985 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
986 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
989 _base_display_reply_info(ioc
,
990 smid
, msix_index
, reply
);
992 mpt3sas_base_free_smid(ioc
,
996 _base_async_event(ioc
, msix_index
, reply
);
999 /* reply free queue handling */
1001 ioc
->reply_free_host_index
=
1002 (ioc
->reply_free_host_index
==
1003 (ioc
->reply_free_queue_depth
- 1)) ?
1004 0 : ioc
->reply_free_host_index
+ 1;
1005 ioc
->reply_free
[ioc
->reply_free_host_index
] =
1008 writel(ioc
->reply_free_host_index
,
1009 &ioc
->chip
->ReplyFreeHostIndex
);
1013 rpf
->Words
= cpu_to_le64(ULLONG_MAX
);
1014 reply_q
->reply_post_host_index
=
1015 (reply_q
->reply_post_host_index
==
1016 (ioc
->reply_post_queue_depth
- 1)) ? 0 :
1017 reply_q
->reply_post_host_index
+ 1;
1018 request_desript_type
=
1019 reply_q
->reply_post_free
[reply_q
->reply_post_host_index
].
1020 Default
.ReplyFlags
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
1022 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
1024 if (!reply_q
->reply_post_host_index
)
1025 rpf
= reply_q
->reply_post_free
;
1032 if (!completed_cmds
) {
1033 atomic_dec(&reply_q
->busy
);
1038 if (ioc
->is_warpdrive
) {
1039 writel(reply_q
->reply_post_host_index
,
1040 ioc
->reply_post_host_index
[msix_index
]);
1041 atomic_dec(&reply_q
->busy
);
1045 /* Update Reply Post Host Index.
1046 * For those HBA's which support combined reply queue feature
1047 * 1. Get the correct Supplemental Reply Post Host Index Register.
1048 * i.e. (msix_index / 8)th entry from Supplemental Reply Post Host
1049 * Index Register address bank i.e replyPostRegisterIndex[],
1050 * 2. Then update this register with new reply host index value
1051 * in ReplyPostIndex field and the MSIxIndex field with
1052 * msix_index value reduced to a value between 0 and 7,
1053 * using a modulo 8 operation. Since each Supplemental Reply Post
1054 * Host Index Register supports 8 MSI-X vectors.
1056 * For other HBA's just update the Reply Post Host Index register with
1057 * new reply host index value in ReplyPostIndex Field and msix_index
1058 * value in MSIxIndex field.
1060 if (ioc
->msix96_vector
)
1061 writel(reply_q
->reply_post_host_index
| ((msix_index
& 7) <<
1062 MPI2_RPHI_MSIX_INDEX_SHIFT
),
1063 ioc
->replyPostRegisterIndex
[msix_index
/8]);
1065 writel(reply_q
->reply_post_host_index
| (msix_index
<<
1066 MPI2_RPHI_MSIX_INDEX_SHIFT
),
1067 &ioc
->chip
->ReplyPostHostIndex
);
1068 atomic_dec(&reply_q
->busy
);
1073 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1074 * @ioc: per adapter object
1078 _base_is_controller_msix_enabled(struct MPT3SAS_ADAPTER
*ioc
)
1080 return (ioc
->facts
.IOCCapabilities
&
1081 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
;
1085 * mpt3sas_base_flush_reply_queues - flushing the MSIX reply queues
1086 * @ioc: per adapter object
1087 * Context: ISR conext
1089 * Called when a Task Management request has completed. We want
1090 * to flush the other reply queues so all the outstanding IO has been
1091 * completed back to OS before we process the TM completetion.
1096 mpt3sas_base_flush_reply_queues(struct MPT3SAS_ADAPTER
*ioc
)
1098 struct adapter_reply_queue
*reply_q
;
1100 /* If MSIX capability is turned off
1101 * then multi-queues are not enabled
1103 if (!_base_is_controller_msix_enabled(ioc
))
1106 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1107 if (ioc
->shost_recovery
)
1109 /* TMs are on msix_index == 0 */
1110 if (reply_q
->msix_index
== 0)
1112 _base_interrupt(reply_q
->vector
, (void *)reply_q
);
1117 * mpt3sas_base_release_callback_handler - clear interrupt callback handler
1118 * @cb_idx: callback index
1123 mpt3sas_base_release_callback_handler(u8 cb_idx
)
1125 mpt_callbacks
[cb_idx
] = NULL
;
1129 * mpt3sas_base_register_callback_handler - obtain index for the interrupt callback handler
1130 * @cb_func: callback function
1135 mpt3sas_base_register_callback_handler(MPT_CALLBACK cb_func
)
1139 for (cb_idx
= MPT_MAX_CALLBACKS
-1; cb_idx
; cb_idx
--)
1140 if (mpt_callbacks
[cb_idx
] == NULL
)
1143 mpt_callbacks
[cb_idx
] = cb_func
;
1148 * mpt3sas_base_initialize_callback_handler - initialize the interrupt callback handler
1153 mpt3sas_base_initialize_callback_handler(void)
1157 for (cb_idx
= 0; cb_idx
< MPT_MAX_CALLBACKS
; cb_idx
++)
1158 mpt3sas_base_release_callback_handler(cb_idx
);
1163 * _base_build_zero_len_sge - build zero length sg entry
1164 * @ioc: per adapter object
1165 * @paddr: virtual address for SGE
1167 * Create a zero length scatter gather entry to insure the IOCs hardware has
1168 * something to use if the target device goes brain dead and tries
1169 * to send data even when none is asked for.
1174 _base_build_zero_len_sge(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1176 u32 flags_length
= (u32
)((MPI2_SGE_FLAGS_LAST_ELEMENT
|
1177 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
|
1178 MPI2_SGE_FLAGS_SIMPLE_ELEMENT
) <<
1179 MPI2_SGE_FLAGS_SHIFT
);
1180 ioc
->base_add_sg_single(paddr
, flags_length
, -1);
1184 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1185 * @paddr: virtual address for SGE
1186 * @flags_length: SGE flags and data transfer length
1187 * @dma_addr: Physical address
1192 _base_add_sg_single_32(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1194 Mpi2SGESimple32_t
*sgel
= paddr
;
1196 flags_length
|= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING
|
1197 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1198 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1199 sgel
->Address
= cpu_to_le32(dma_addr
);
1204 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1205 * @paddr: virtual address for SGE
1206 * @flags_length: SGE flags and data transfer length
1207 * @dma_addr: Physical address
1212 _base_add_sg_single_64(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1214 Mpi2SGESimple64_t
*sgel
= paddr
;
1216 flags_length
|= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING
|
1217 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1218 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1219 sgel
->Address
= cpu_to_le64(dma_addr
);
1223 * _base_get_chain_buffer_tracker - obtain chain tracker
1224 * @ioc: per adapter object
1225 * @smid: smid associated to an IO request
1227 * Returns chain tracker(from ioc->free_chain_list)
1229 static struct chain_tracker
*
1230 _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1232 struct chain_tracker
*chain_req
;
1233 unsigned long flags
;
1235 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1236 if (list_empty(&ioc
->free_chain_list
)) {
1237 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1238 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1239 "chain buffers not available\n", ioc
->name
));
1242 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1243 struct chain_tracker
, tracker_list
);
1244 list_del_init(&chain_req
->tracker_list
);
1245 list_add_tail(&chain_req
->tracker_list
,
1246 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1247 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1253 * _base_build_sg - build generic sg
1254 * @ioc: per adapter object
1255 * @psge: virtual address for SGE
1256 * @data_out_dma: physical address for WRITES
1257 * @data_out_sz: data xfer size for WRITES
1258 * @data_in_dma: physical address for READS
1259 * @data_in_sz: data xfer size for READS
1264 _base_build_sg(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
1265 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1270 if (!data_out_sz
&& !data_in_sz
) {
1271 _base_build_zero_len_sge(ioc
, psge
);
1275 if (data_out_sz
&& data_in_sz
) {
1276 /* WRITE sgel first */
1277 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1278 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1279 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1280 ioc
->base_add_sg_single(psge
, sgl_flags
|
1281 data_out_sz
, data_out_dma
);
1284 psge
+= ioc
->sge_size
;
1286 /* READ sgel last */
1287 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1288 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1289 MPI2_SGE_FLAGS_END_OF_LIST
);
1290 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1291 ioc
->base_add_sg_single(psge
, sgl_flags
|
1292 data_in_sz
, data_in_dma
);
1293 } else if (data_out_sz
) /* WRITE */ {
1294 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1295 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1296 MPI2_SGE_FLAGS_END_OF_LIST
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1297 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1298 ioc
->base_add_sg_single(psge
, sgl_flags
|
1299 data_out_sz
, data_out_dma
);
1300 } else if (data_in_sz
) /* READ */ {
1301 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1302 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1303 MPI2_SGE_FLAGS_END_OF_LIST
);
1304 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1305 ioc
->base_add_sg_single(psge
, sgl_flags
|
1306 data_in_sz
, data_in_dma
);
1310 /* IEEE format sgls */
1313 * _base_add_sg_single_ieee - add sg element for IEEE format
1314 * @paddr: virtual address for SGE
1316 * @chain_offset: number of 128 byte elements from start of segment
1317 * @length: data transfer length
1318 * @dma_addr: Physical address
1323 _base_add_sg_single_ieee(void *paddr
, u8 flags
, u8 chain_offset
, u32 length
,
1324 dma_addr_t dma_addr
)
1326 Mpi25IeeeSgeChain64_t
*sgel
= paddr
;
1328 sgel
->Flags
= flags
;
1329 sgel
->NextChainOffset
= chain_offset
;
1330 sgel
->Length
= cpu_to_le32(length
);
1331 sgel
->Address
= cpu_to_le64(dma_addr
);
1335 * _base_build_zero_len_sge_ieee - build zero length sg entry for IEEE format
1336 * @ioc: per adapter object
1337 * @paddr: virtual address for SGE
1339 * Create a zero length scatter gather entry to insure the IOCs hardware has
1340 * something to use if the target device goes brain dead and tries
1341 * to send data even when none is asked for.
1346 _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1348 u8 sgl_flags
= (MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1349 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
|
1350 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
);
1351 _base_add_sg_single_ieee(paddr
, sgl_flags
, 0, 0, -1);
1355 * _base_build_sg_scmd - main sg creation routine
1356 * @ioc: per adapter object
1357 * @scmd: scsi command
1358 * @smid: system request message index
1361 * The main routine that builds scatter gather table from a given
1362 * scsi request sent via the .queuecommand main handler.
1364 * Returns 0 success, anything else error
1367 _base_build_sg_scmd(struct MPT3SAS_ADAPTER
*ioc
,
1368 struct scsi_cmnd
*scmd
, u16 smid
)
1370 Mpi2SCSIIORequest_t
*mpi_request
;
1371 dma_addr_t chain_dma
;
1372 struct scatterlist
*sg_scmd
;
1373 void *sg_local
, *chain
;
1378 u32 sges_in_segment
;
1380 u32 sgl_flags_last_element
;
1381 u32 sgl_flags_end_buffer
;
1382 struct chain_tracker
*chain_req
;
1384 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1386 /* init scatter gather flags */
1387 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1388 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1389 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1390 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1391 << MPI2_SGE_FLAGS_SHIFT
;
1392 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1393 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1394 << MPI2_SGE_FLAGS_SHIFT
;
1395 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1397 sg_scmd
= scsi_sglist(scmd
);
1398 sges_left
= scsi_dma_map(scmd
);
1399 if (sges_left
< 0) {
1400 sdev_printk(KERN_ERR
, scmd
->device
,
1401 "pci_map_sg failed: request for %d bytes!\n",
1402 scsi_bufflen(scmd
));
1406 sg_local
= &mpi_request
->SGL
;
1407 sges_in_segment
= ioc
->max_sges_in_main_message
;
1408 if (sges_left
<= sges_in_segment
)
1409 goto fill_in_last_segment
;
1411 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1412 (sges_in_segment
* ioc
->sge_size
))/4;
1414 /* fill in main message segment when there is a chain following */
1415 while (sges_in_segment
) {
1416 if (sges_in_segment
== 1)
1417 ioc
->base_add_sg_single(sg_local
,
1418 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1419 sg_dma_address(sg_scmd
));
1421 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1422 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1423 sg_scmd
= sg_next(sg_scmd
);
1424 sg_local
+= ioc
->sge_size
;
1429 /* initializing the chain flags and pointers */
1430 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1431 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1434 chain
= chain_req
->chain_buffer
;
1435 chain_dma
= chain_req
->chain_buffer_dma
;
1437 sges_in_segment
= (sges_left
<=
1438 ioc
->max_sges_in_chain_message
) ? sges_left
:
1439 ioc
->max_sges_in_chain_message
;
1440 chain_offset
= (sges_left
== sges_in_segment
) ?
1441 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1442 chain_length
= sges_in_segment
* ioc
->sge_size
;
1444 chain_offset
= chain_offset
<<
1445 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1446 chain_length
+= ioc
->sge_size
;
1448 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1449 chain_length
, chain_dma
);
1452 goto fill_in_last_segment
;
1454 /* fill in chain segments */
1455 while (sges_in_segment
) {
1456 if (sges_in_segment
== 1)
1457 ioc
->base_add_sg_single(sg_local
,
1458 sgl_flags_last_element
|
1459 sg_dma_len(sg_scmd
),
1460 sg_dma_address(sg_scmd
));
1462 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1463 sg_dma_len(sg_scmd
),
1464 sg_dma_address(sg_scmd
));
1465 sg_scmd
= sg_next(sg_scmd
);
1466 sg_local
+= ioc
->sge_size
;
1471 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1474 chain
= chain_req
->chain_buffer
;
1475 chain_dma
= chain_req
->chain_buffer_dma
;
1479 fill_in_last_segment
:
1481 /* fill the last segment */
1484 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1485 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1487 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1488 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1489 sg_scmd
= sg_next(sg_scmd
);
1490 sg_local
+= ioc
->sge_size
;
1498 * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format
1499 * @ioc: per adapter object
1500 * @scmd: scsi command
1501 * @smid: system request message index
1504 * The main routine that builds scatter gather table from a given
1505 * scsi request sent via the .queuecommand main handler.
1507 * Returns 0 success, anything else error
1510 _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER
*ioc
,
1511 struct scsi_cmnd
*scmd
, u16 smid
)
1513 Mpi2SCSIIORequest_t
*mpi_request
;
1514 dma_addr_t chain_dma
;
1515 struct scatterlist
*sg_scmd
;
1516 void *sg_local
, *chain
;
1520 u32 sges_in_segment
;
1521 u8 simple_sgl_flags
;
1522 u8 simple_sgl_flags_last
;
1524 struct chain_tracker
*chain_req
;
1526 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1528 /* init scatter gather flags */
1529 simple_sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1530 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1531 simple_sgl_flags_last
= simple_sgl_flags
|
1532 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
1533 chain_sgl_flags
= MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
1534 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1536 sg_scmd
= scsi_sglist(scmd
);
1537 sges_left
= scsi_dma_map(scmd
);
1538 if (sges_left
< 0) {
1539 sdev_printk(KERN_ERR
, scmd
->device
,
1540 "pci_map_sg failed: request for %d bytes!\n",
1541 scsi_bufflen(scmd
));
1545 sg_local
= &mpi_request
->SGL
;
1546 sges_in_segment
= (ioc
->request_sz
-
1547 offsetof(Mpi2SCSIIORequest_t
, SGL
))/ioc
->sge_size_ieee
;
1548 if (sges_left
<= sges_in_segment
)
1549 goto fill_in_last_segment
;
1551 mpi_request
->ChainOffset
= (sges_in_segment
- 1 /* chain element */) +
1552 (offsetof(Mpi2SCSIIORequest_t
, SGL
)/ioc
->sge_size_ieee
);
1554 /* fill in main message segment when there is a chain following */
1555 while (sges_in_segment
> 1) {
1556 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1557 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1558 sg_scmd
= sg_next(sg_scmd
);
1559 sg_local
+= ioc
->sge_size_ieee
;
1564 /* initializing the pointers */
1565 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1568 chain
= chain_req
->chain_buffer
;
1569 chain_dma
= chain_req
->chain_buffer_dma
;
1571 sges_in_segment
= (sges_left
<=
1572 ioc
->max_sges_in_chain_message
) ? sges_left
:
1573 ioc
->max_sges_in_chain_message
;
1574 chain_offset
= (sges_left
== sges_in_segment
) ?
1575 0 : sges_in_segment
;
1576 chain_length
= sges_in_segment
* ioc
->sge_size_ieee
;
1578 chain_length
+= ioc
->sge_size_ieee
;
1579 _base_add_sg_single_ieee(sg_local
, chain_sgl_flags
,
1580 chain_offset
, chain_length
, chain_dma
);
1584 goto fill_in_last_segment
;
1586 /* fill in chain segments */
1587 while (sges_in_segment
) {
1588 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1589 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1590 sg_scmd
= sg_next(sg_scmd
);
1591 sg_local
+= ioc
->sge_size_ieee
;
1596 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1599 chain
= chain_req
->chain_buffer
;
1600 chain_dma
= chain_req
->chain_buffer_dma
;
1604 fill_in_last_segment
:
1606 /* fill the last segment */
1607 while (sges_left
> 0) {
1609 _base_add_sg_single_ieee(sg_local
,
1610 simple_sgl_flags_last
, 0, sg_dma_len(sg_scmd
),
1611 sg_dma_address(sg_scmd
));
1613 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1614 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1615 sg_scmd
= sg_next(sg_scmd
);
1616 sg_local
+= ioc
->sge_size_ieee
;
1624 * _base_build_sg_ieee - build generic sg for IEEE format
1625 * @ioc: per adapter object
1626 * @psge: virtual address for SGE
1627 * @data_out_dma: physical address for WRITES
1628 * @data_out_sz: data xfer size for WRITES
1629 * @data_in_dma: physical address for READS
1630 * @data_in_sz: data xfer size for READS
1635 _base_build_sg_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
1636 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1641 if (!data_out_sz
&& !data_in_sz
) {
1642 _base_build_zero_len_sge_ieee(ioc
, psge
);
1646 if (data_out_sz
&& data_in_sz
) {
1647 /* WRITE sgel first */
1648 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1649 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1650 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
1654 psge
+= ioc
->sge_size_ieee
;
1656 /* READ sgel last */
1657 sgl_flags
|= MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
1658 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
1660 } else if (data_out_sz
) /* WRITE */ {
1661 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1662 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
1663 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1664 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
1666 } else if (data_in_sz
) /* READ */ {
1667 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1668 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
1669 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1670 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
1675 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1678 * _base_config_dma_addressing - set dma addressing
1679 * @ioc: per adapter object
1680 * @pdev: PCI device struct
1682 * Returns 0 for success, non-zero for failure.
1685 _base_config_dma_addressing(struct MPT3SAS_ADAPTER
*ioc
, struct pci_dev
*pdev
)
1688 u64 consistent_dma_mask
;
1691 consistent_dma_mask
= DMA_BIT_MASK(64);
1693 consistent_dma_mask
= DMA_BIT_MASK(32);
1695 if (sizeof(dma_addr_t
) > 4) {
1696 const uint64_t required_mask
=
1697 dma_get_required_mask(&pdev
->dev
);
1698 if ((required_mask
> DMA_BIT_MASK(32)) &&
1699 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1700 !pci_set_consistent_dma_mask(pdev
, consistent_dma_mask
)) {
1701 ioc
->base_add_sg_single
= &_base_add_sg_single_64
;
1702 ioc
->sge_size
= sizeof(Mpi2SGESimple64_t
);
1708 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1709 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1710 ioc
->base_add_sg_single
= &_base_add_sg_single_32
;
1711 ioc
->sge_size
= sizeof(Mpi2SGESimple32_t
);
1719 "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
1720 ioc
->name
, ioc
->dma_mask
, convert_to_kb(s
.totalram
));
1726 _base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER
*ioc
,
1727 struct pci_dev
*pdev
)
1729 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
1730 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1737 * _base_check_enable_msix - checks MSIX capabable.
1738 * @ioc: per adapter object
1740 * Check to see if card is capable of MSIX, and set number
1741 * of available msix vectors
1744 _base_check_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1747 u16 message_control
;
1749 /* Check whether controller SAS2008 B0 controller,
1750 * if it is SAS2008 B0 controller use IO-APIC instead of MSIX
1752 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
&&
1753 ioc
->pdev
->revision
== SAS2_PCI_DEVICE_B0_REVISION
) {
1757 base
= pci_find_capability(ioc
->pdev
, PCI_CAP_ID_MSIX
);
1759 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
"msix not supported\n",
1764 /* get msix vector count */
1765 /* NUMA_IO not supported for older controllers */
1766 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2004
||
1767 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
||
1768 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_1
||
1769 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_2
||
1770 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_3
||
1771 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_1
||
1772 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_2
)
1773 ioc
->msix_vector_count
= 1;
1775 pci_read_config_word(ioc
->pdev
, base
+ 2, &message_control
);
1776 ioc
->msix_vector_count
= (message_control
& 0x3FF) + 1;
1778 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
1779 "msix is supported, vector_count(%d)\n",
1780 ioc
->name
, ioc
->msix_vector_count
));
1785 * _base_free_irq - free irq
1786 * @ioc: per adapter object
1788 * Freeing respective reply_queue from the list.
1791 _base_free_irq(struct MPT3SAS_ADAPTER
*ioc
)
1793 struct adapter_reply_queue
*reply_q
, *next
;
1795 if (list_empty(&ioc
->reply_queue_list
))
1798 list_for_each_entry_safe(reply_q
, next
, &ioc
->reply_queue_list
, list
) {
1799 list_del(&reply_q
->list
);
1800 irq_set_affinity_hint(reply_q
->vector
, NULL
);
1801 free_cpumask_var(reply_q
->affinity_hint
);
1802 synchronize_irq(reply_q
->vector
);
1803 free_irq(reply_q
->vector
, reply_q
);
1809 * _base_request_irq - request irq
1810 * @ioc: per adapter object
1811 * @index: msix index into vector table
1812 * @vector: irq vector
1814 * Inserting respective reply_queue into the list.
1817 _base_request_irq(struct MPT3SAS_ADAPTER
*ioc
, u8 index
, u32 vector
)
1819 struct adapter_reply_queue
*reply_q
;
1822 reply_q
= kzalloc(sizeof(struct adapter_reply_queue
), GFP_KERNEL
);
1824 pr_err(MPT3SAS_FMT
"unable to allocate memory %d!\n",
1825 ioc
->name
, (int)sizeof(struct adapter_reply_queue
));
1829 reply_q
->msix_index
= index
;
1830 reply_q
->vector
= vector
;
1832 if (!alloc_cpumask_var(&reply_q
->affinity_hint
, GFP_KERNEL
))
1834 cpumask_clear(reply_q
->affinity_hint
);
1836 atomic_set(&reply_q
->busy
, 0);
1837 if (ioc
->msix_enable
)
1838 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d-msix%d",
1839 ioc
->driver_name
, ioc
->id
, index
);
1841 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d",
1842 ioc
->driver_name
, ioc
->id
);
1843 r
= request_irq(vector
, _base_interrupt
, IRQF_SHARED
, reply_q
->name
,
1846 pr_err(MPT3SAS_FMT
"unable to allocate interrupt %d!\n",
1847 reply_q
->name
, vector
);
1852 INIT_LIST_HEAD(&reply_q
->list
);
1853 list_add_tail(&reply_q
->list
, &ioc
->reply_queue_list
);
1858 * _base_assign_reply_queues - assigning msix index for each cpu
1859 * @ioc: per adapter object
1861 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1863 * It would nice if we could call irq_set_affinity, however it is not
1864 * an exported symbol
1867 _base_assign_reply_queues(struct MPT3SAS_ADAPTER
*ioc
)
1869 unsigned int cpu
, nr_cpus
, nr_msix
, index
= 0;
1870 struct adapter_reply_queue
*reply_q
;
1872 if (!_base_is_controller_msix_enabled(ioc
))
1875 memset(ioc
->cpu_msix_table
, 0, ioc
->cpu_msix_table_sz
);
1877 nr_cpus
= num_online_cpus();
1878 nr_msix
= ioc
->reply_queue_count
= min(ioc
->reply_queue_count
,
1879 ioc
->facts
.MaxMSIxVectors
);
1883 cpu
= cpumask_first(cpu_online_mask
);
1885 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1887 unsigned int i
, group
= nr_cpus
/ nr_msix
;
1892 if (index
< nr_cpus
% nr_msix
)
1895 for (i
= 0 ; i
< group
; i
++) {
1896 ioc
->cpu_msix_table
[cpu
] = index
;
1897 cpumask_or(reply_q
->affinity_hint
,
1898 reply_q
->affinity_hint
, get_cpu_mask(cpu
));
1899 cpu
= cpumask_next(cpu
, cpu_online_mask
);
1902 if (irq_set_affinity_hint(reply_q
->vector
,
1903 reply_q
->affinity_hint
))
1904 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
1905 "error setting affinity hint for irq vector %d\n",
1906 ioc
->name
, reply_q
->vector
));
1912 * _base_disable_msix - disables msix
1913 * @ioc: per adapter object
1917 _base_disable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1919 if (!ioc
->msix_enable
)
1921 pci_disable_msix(ioc
->pdev
);
1922 ioc
->msix_enable
= 0;
1926 * _base_enable_msix - enables msix, failback to io_apic
1927 * @ioc: per adapter object
1931 _base_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1933 struct msix_entry
*entries
, *a
;
1938 if (msix_disable
== -1 || msix_disable
== 0)
1944 if (_base_check_enable_msix(ioc
) != 0)
1947 ioc
->reply_queue_count
= min_t(int, ioc
->cpu_count
,
1948 ioc
->msix_vector_count
);
1950 printk(MPT3SAS_FMT
"MSI-X vectors supported: %d, no of cores"
1951 ": %d, max_msix_vectors: %d\n", ioc
->name
, ioc
->msix_vector_count
,
1952 ioc
->cpu_count
, max_msix_vectors
);
1954 if (!ioc
->rdpq_array_enable
&& max_msix_vectors
== -1)
1955 max_msix_vectors
= 8;
1957 if (max_msix_vectors
> 0) {
1958 ioc
->reply_queue_count
= min_t(int, max_msix_vectors
,
1959 ioc
->reply_queue_count
);
1960 ioc
->msix_vector_count
= ioc
->reply_queue_count
;
1961 } else if (max_msix_vectors
== 0)
1964 entries
= kcalloc(ioc
->reply_queue_count
, sizeof(struct msix_entry
),
1967 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
1968 "kcalloc failed @ at %s:%d/%s() !!!\n",
1969 ioc
->name
, __FILE__
, __LINE__
, __func__
));
1973 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++)
1976 r
= pci_enable_msix_exact(ioc
->pdev
, entries
, ioc
->reply_queue_count
);
1978 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
1979 "pci_enable_msix_exact failed (r=%d) !!!\n",
1985 ioc
->msix_enable
= 1;
1986 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++) {
1987 r
= _base_request_irq(ioc
, i
, a
->vector
);
1989 _base_free_irq(ioc
);
1990 _base_disable_msix(ioc
);
1999 /* failback to io_apic interrupt routing */
2002 ioc
->reply_queue_count
= 1;
2003 r
= _base_request_irq(ioc
, 0, ioc
->pdev
->irq
);
2009 * mpt3sas_base_unmap_resources - free controller resources
2010 * @ioc: per adapter object
2013 mpt3sas_base_unmap_resources(struct MPT3SAS_ADAPTER
*ioc
)
2015 struct pci_dev
*pdev
= ioc
->pdev
;
2017 dexitprintk(ioc
, printk(MPT3SAS_FMT
"%s\n",
2018 ioc
->name
, __func__
));
2020 _base_free_irq(ioc
);
2021 _base_disable_msix(ioc
);
2023 if (ioc
->msix96_vector
) {
2024 kfree(ioc
->replyPostRegisterIndex
);
2025 ioc
->replyPostRegisterIndex
= NULL
;
2028 if (ioc
->chip_phys
) {
2033 if (pci_is_enabled(pdev
)) {
2034 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
2035 pci_disable_pcie_error_reporting(pdev
);
2036 pci_disable_device(pdev
);
2041 * mpt3sas_base_map_resources - map in controller resources (io/irq/memap)
2042 * @ioc: per adapter object
2044 * Returns 0 for success, non-zero for failure.
2047 mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER
*ioc
)
2049 struct pci_dev
*pdev
= ioc
->pdev
;
2055 struct adapter_reply_queue
*reply_q
;
2057 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n",
2058 ioc
->name
, __func__
));
2060 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
2061 if (pci_enable_device_mem(pdev
)) {
2062 pr_warn(MPT3SAS_FMT
"pci_enable_device_mem: failed\n",
2069 if (pci_request_selected_regions(pdev
, ioc
->bars
,
2070 ioc
->driver_name
)) {
2071 pr_warn(MPT3SAS_FMT
"pci_request_selected_regions: failed\n",
2078 /* AER (Advanced Error Reporting) hooks */
2079 pci_enable_pcie_error_reporting(pdev
);
2081 pci_set_master(pdev
);
2084 if (_base_config_dma_addressing(ioc
, pdev
) != 0) {
2085 pr_warn(MPT3SAS_FMT
"no suitable DMA mask for %s\n",
2086 ioc
->name
, pci_name(pdev
));
2091 for (i
= 0, memap_sz
= 0, pio_sz
= 0; (i
< DEVICE_COUNT_RESOURCE
) &&
2092 (!memap_sz
|| !pio_sz
); i
++) {
2093 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
2096 pio_chip
= (u64
)pci_resource_start(pdev
, i
);
2097 pio_sz
= pci_resource_len(pdev
, i
);
2098 } else if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
2101 ioc
->chip_phys
= pci_resource_start(pdev
, i
);
2102 chip_phys
= (u64
)ioc
->chip_phys
;
2103 memap_sz
= pci_resource_len(pdev
, i
);
2104 ioc
->chip
= ioremap(ioc
->chip_phys
, memap_sz
);
2108 if (ioc
->chip
== NULL
) {
2109 pr_err(MPT3SAS_FMT
"unable to map adapter memory! "
2110 " or resource not found\n", ioc
->name
);
2115 _base_mask_interrupts(ioc
);
2117 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
2121 if (!ioc
->rdpq_array_enable_assigned
) {
2122 ioc
->rdpq_array_enable
= ioc
->rdpq_array_capable
;
2123 ioc
->rdpq_array_enable_assigned
= 1;
2126 r
= _base_enable_msix(ioc
);
2130 /* Use the Combined reply queue feature only for SAS3 C0 & higher
2131 * revision HBAs and also only when reply queue count is greater than 8
2133 if (ioc
->msix96_vector
&& ioc
->reply_queue_count
> 8) {
2134 /* Determine the Supplemental Reply Post Host Index Registers
2135 * Addresse. Supplemental Reply Post Host Index Registers
2136 * starts at offset MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET and
2137 * each register is at offset bytes of
2138 * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET from previous one.
2140 ioc
->replyPostRegisterIndex
= kcalloc(
2141 MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT
,
2142 sizeof(resource_size_t
*), GFP_KERNEL
);
2143 if (!ioc
->replyPostRegisterIndex
) {
2144 dfailprintk(ioc
, printk(MPT3SAS_FMT
2145 "allocation for reply Post Register Index failed!!!\n",
2151 for (i
= 0; i
< MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT
; i
++) {
2152 ioc
->replyPostRegisterIndex
[i
] = (resource_size_t
*)
2153 ((u8
*)&ioc
->chip
->Doorbell
+
2154 MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET
+
2155 (i
* MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET
));
2158 ioc
->msix96_vector
= 0;
2160 if (ioc
->is_warpdrive
) {
2161 ioc
->reply_post_host_index
[0] = (resource_size_t __iomem
*)
2162 &ioc
->chip
->ReplyPostHostIndex
;
2164 for (i
= 1; i
< ioc
->cpu_msix_table_sz
; i
++)
2165 ioc
->reply_post_host_index
[i
] =
2166 (resource_size_t __iomem
*)
2167 ((u8 __iomem
*)&ioc
->chip
->Doorbell
+ (0x4000 + ((i
- 1)
2171 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
)
2172 pr_info(MPT3SAS_FMT
"%s: IRQ %d\n",
2173 reply_q
->name
, ((ioc
->msix_enable
) ? "PCI-MSI-X enabled" :
2174 "IO-APIC enabled"), reply_q
->vector
);
2176 pr_info(MPT3SAS_FMT
"iomem(0x%016llx), mapped(0x%p), size(%d)\n",
2177 ioc
->name
, (unsigned long long)chip_phys
, ioc
->chip
, memap_sz
);
2178 pr_info(MPT3SAS_FMT
"ioport(0x%016llx), size(%d)\n",
2179 ioc
->name
, (unsigned long long)pio_chip
, pio_sz
);
2181 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
2182 pci_save_state(pdev
);
2186 mpt3sas_base_unmap_resources(ioc
);
2191 * mpt3sas_base_get_msg_frame - obtain request mf pointer
2192 * @ioc: per adapter object
2193 * @smid: system request message index(smid zero is invalid)
2195 * Returns virt pointer to message frame.
2198 mpt3sas_base_get_msg_frame(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2200 return (void *)(ioc
->request
+ (smid
* ioc
->request_sz
));
2204 * mpt3sas_base_get_sense_buffer - obtain a sense buffer virt addr
2205 * @ioc: per adapter object
2206 * @smid: system request message index
2208 * Returns virt pointer to sense buffer.
2211 mpt3sas_base_get_sense_buffer(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2213 return (void *)(ioc
->sense
+ ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
2217 * mpt3sas_base_get_sense_buffer_dma - obtain a sense buffer dma addr
2218 * @ioc: per adapter object
2219 * @smid: system request message index
2221 * Returns phys pointer to the low 32bit address of the sense buffer.
2224 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2226 return cpu_to_le32(ioc
->sense_dma
+ ((smid
- 1) *
2227 SCSI_SENSE_BUFFERSIZE
));
2231 * mpt3sas_base_get_reply_virt_addr - obtain reply frames virt address
2232 * @ioc: per adapter object
2233 * @phys_addr: lower 32 physical addr of the reply
2235 * Converts 32bit lower physical addr into a virt address.
2238 mpt3sas_base_get_reply_virt_addr(struct MPT3SAS_ADAPTER
*ioc
, u32 phys_addr
)
2242 return ioc
->reply
+ (phys_addr
- (u32
)ioc
->reply_dma
);
2246 _base_get_msix_index(struct MPT3SAS_ADAPTER
*ioc
)
2248 return ioc
->cpu_msix_table
[raw_smp_processor_id()];
2252 * mpt3sas_base_get_smid - obtain a free smid from internal queue
2253 * @ioc: per adapter object
2254 * @cb_idx: callback index
2256 * Returns smid (zero is invalid)
2259 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
2261 unsigned long flags
;
2262 struct request_tracker
*request
;
2265 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2266 if (list_empty(&ioc
->internal_free_list
)) {
2267 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2268 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
2269 ioc
->name
, __func__
);
2273 request
= list_entry(ioc
->internal_free_list
.next
,
2274 struct request_tracker
, tracker_list
);
2275 request
->cb_idx
= cb_idx
;
2276 smid
= request
->smid
;
2277 list_del(&request
->tracker_list
);
2278 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2283 * mpt3sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
2284 * @ioc: per adapter object
2285 * @cb_idx: callback index
2286 * @scmd: pointer to scsi command object
2288 * Returns smid (zero is invalid)
2291 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
,
2292 struct scsi_cmnd
*scmd
)
2294 unsigned long flags
;
2295 struct scsiio_tracker
*request
;
2298 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2299 if (list_empty(&ioc
->free_list
)) {
2300 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2301 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
2302 ioc
->name
, __func__
);
2306 request
= list_entry(ioc
->free_list
.next
,
2307 struct scsiio_tracker
, tracker_list
);
2308 request
->scmd
= scmd
;
2309 request
->cb_idx
= cb_idx
;
2310 smid
= request
->smid
;
2311 request
->msix_io
= _base_get_msix_index(ioc
);
2312 list_del(&request
->tracker_list
);
2313 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2318 * mpt3sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
2319 * @ioc: per adapter object
2320 * @cb_idx: callback index
2322 * Returns smid (zero is invalid)
2325 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
2327 unsigned long flags
;
2328 struct request_tracker
*request
;
2331 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2332 if (list_empty(&ioc
->hpr_free_list
)) {
2333 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2337 request
= list_entry(ioc
->hpr_free_list
.next
,
2338 struct request_tracker
, tracker_list
);
2339 request
->cb_idx
= cb_idx
;
2340 smid
= request
->smid
;
2341 list_del(&request
->tracker_list
);
2342 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2347 * mpt3sas_base_free_smid - put smid back on free_list
2348 * @ioc: per adapter object
2349 * @smid: system request message index
2354 mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2356 unsigned long flags
;
2358 struct chain_tracker
*chain_req
, *next
;
2360 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2361 if (smid
< ioc
->hi_priority_smid
) {
2364 if (!list_empty(&ioc
->scsi_lookup
[i
].chain_list
)) {
2365 list_for_each_entry_safe(chain_req
, next
,
2366 &ioc
->scsi_lookup
[i
].chain_list
, tracker_list
) {
2367 list_del_init(&chain_req
->tracker_list
);
2368 list_add(&chain_req
->tracker_list
,
2369 &ioc
->free_chain_list
);
2372 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
2373 ioc
->scsi_lookup
[i
].scmd
= NULL
;
2374 ioc
->scsi_lookup
[i
].direct_io
= 0;
2375 list_add(&ioc
->scsi_lookup
[i
].tracker_list
, &ioc
->free_list
);
2376 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2379 * See _wait_for_commands_to_complete() call with regards
2382 if (ioc
->shost_recovery
&& ioc
->pending_io_count
) {
2383 if (ioc
->pending_io_count
== 1)
2384 wake_up(&ioc
->reset_wq
);
2385 ioc
->pending_io_count
--;
2388 } else if (smid
< ioc
->internal_smid
) {
2390 i
= smid
- ioc
->hi_priority_smid
;
2391 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
2392 list_add(&ioc
->hpr_lookup
[i
].tracker_list
, &ioc
->hpr_free_list
);
2393 } else if (smid
<= ioc
->hba_queue_depth
) {
2394 /* internal queue */
2395 i
= smid
- ioc
->internal_smid
;
2396 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
2397 list_add(&ioc
->internal_lookup
[i
].tracker_list
,
2398 &ioc
->internal_free_list
);
2400 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2404 * _base_writeq - 64 bit write to MMIO
2405 * @ioc: per adapter object
2407 * @addr: address in MMIO space
2408 * @writeq_lock: spin lock
2410 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
2411 * care of 32 bit environment where its not quarenteed to send the entire word
2414 #if defined(writeq) && defined(CONFIG_64BIT)
2416 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2418 writeq(cpu_to_le64(b
), addr
);
2422 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2424 unsigned long flags
;
2425 __u64 data_out
= cpu_to_le64(b
);
2427 spin_lock_irqsave(writeq_lock
, flags
);
2428 writel((u32
)(data_out
), addr
);
2429 writel((u32
)(data_out
>> 32), (addr
+ 4));
2430 spin_unlock_irqrestore(writeq_lock
, flags
);
2435 * mpt3sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
2436 * @ioc: per adapter object
2437 * @smid: system request message index
2438 * @handle: device handle
2443 mpt3sas_base_put_smid_scsi_io(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 handle
)
2445 Mpi2RequestDescriptorUnion_t descriptor
;
2446 u64
*request
= (u64
*)&descriptor
;
2449 descriptor
.SCSIIO
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
2450 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
2451 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
2452 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
2453 descriptor
.SCSIIO
.LMID
= 0;
2454 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2455 &ioc
->scsi_lookup_lock
);
2459 * mpt3sas_base_put_smid_fast_path - send fast path request to firmware
2460 * @ioc: per adapter object
2461 * @smid: system request message index
2462 * @handle: device handle
2467 mpt3sas_base_put_smid_fast_path(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
2470 Mpi2RequestDescriptorUnion_t descriptor
;
2471 u64
*request
= (u64
*)&descriptor
;
2473 descriptor
.SCSIIO
.RequestFlags
=
2474 MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO
;
2475 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
2476 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
2477 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
2478 descriptor
.SCSIIO
.LMID
= 0;
2479 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2480 &ioc
->scsi_lookup_lock
);
2484 * mpt3sas_base_put_smid_hi_priority - send Task Managment request to firmware
2485 * @ioc: per adapter object
2486 * @smid: system request message index
2487 * @msix_task: msix_task will be same as msix of IO incase of task abort else 0.
2491 mpt3sas_base_put_smid_hi_priority(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
2494 Mpi2RequestDescriptorUnion_t descriptor
;
2495 u64
*request
= (u64
*)&descriptor
;
2497 descriptor
.HighPriority
.RequestFlags
=
2498 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
2499 descriptor
.HighPriority
.MSIxIndex
= msix_task
;
2500 descriptor
.HighPriority
.SMID
= cpu_to_le16(smid
);
2501 descriptor
.HighPriority
.LMID
= 0;
2502 descriptor
.HighPriority
.Reserved1
= 0;
2503 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2504 &ioc
->scsi_lookup_lock
);
2508 * mpt3sas_base_put_smid_default - Default, primarily used for config pages
2509 * @ioc: per adapter object
2510 * @smid: system request message index
2515 mpt3sas_base_put_smid_default(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2517 Mpi2RequestDescriptorUnion_t descriptor
;
2518 u64
*request
= (u64
*)&descriptor
;
2520 descriptor
.Default
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
2521 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
2522 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
2523 descriptor
.Default
.LMID
= 0;
2524 descriptor
.Default
.DescriptorTypeDependent
= 0;
2525 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2526 &ioc
->scsi_lookup_lock
);
2530 * _base_display_OEMs_branding - Display branding string
2531 * @ioc: per adapter object
2536 _base_display_OEMs_branding(struct MPT3SAS_ADAPTER
*ioc
)
2538 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
2541 switch (ioc
->pdev
->subsystem_vendor
) {
2542 case PCI_VENDOR_ID_INTEL
:
2543 switch (ioc
->pdev
->device
) {
2544 case MPI2_MFGPAGE_DEVID_SAS2008
:
2545 switch (ioc
->pdev
->subsystem_device
) {
2546 case MPT2SAS_INTEL_RMS2LL080_SSDID
:
2547 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2548 MPT2SAS_INTEL_RMS2LL080_BRANDING
);
2550 case MPT2SAS_INTEL_RMS2LL040_SSDID
:
2551 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2552 MPT2SAS_INTEL_RMS2LL040_BRANDING
);
2554 case MPT2SAS_INTEL_SSD910_SSDID
:
2555 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2556 MPT2SAS_INTEL_SSD910_BRANDING
);
2560 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2561 ioc
->name
, ioc
->pdev
->subsystem_device
);
2564 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
2565 switch (ioc
->pdev
->subsystem_device
) {
2566 case MPT2SAS_INTEL_RS25GB008_SSDID
:
2567 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2568 MPT2SAS_INTEL_RS25GB008_BRANDING
);
2570 case MPT2SAS_INTEL_RMS25JB080_SSDID
:
2571 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2572 MPT2SAS_INTEL_RMS25JB080_BRANDING
);
2574 case MPT2SAS_INTEL_RMS25JB040_SSDID
:
2575 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2576 MPT2SAS_INTEL_RMS25JB040_BRANDING
);
2578 case MPT2SAS_INTEL_RMS25KB080_SSDID
:
2579 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2580 MPT2SAS_INTEL_RMS25KB080_BRANDING
);
2582 case MPT2SAS_INTEL_RMS25KB040_SSDID
:
2583 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2584 MPT2SAS_INTEL_RMS25KB040_BRANDING
);
2586 case MPT2SAS_INTEL_RMS25LB040_SSDID
:
2587 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2588 MPT2SAS_INTEL_RMS25LB040_BRANDING
);
2590 case MPT2SAS_INTEL_RMS25LB080_SSDID
:
2591 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2592 MPT2SAS_INTEL_RMS25LB080_BRANDING
);
2596 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2597 ioc
->name
, ioc
->pdev
->subsystem_device
);
2600 case MPI25_MFGPAGE_DEVID_SAS3008
:
2601 switch (ioc
->pdev
->subsystem_device
) {
2602 case MPT3SAS_INTEL_RMS3JC080_SSDID
:
2603 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2604 MPT3SAS_INTEL_RMS3JC080_BRANDING
);
2607 case MPT3SAS_INTEL_RS3GC008_SSDID
:
2608 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2609 MPT3SAS_INTEL_RS3GC008_BRANDING
);
2611 case MPT3SAS_INTEL_RS3FC044_SSDID
:
2612 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2613 MPT3SAS_INTEL_RS3FC044_BRANDING
);
2615 case MPT3SAS_INTEL_RS3UC080_SSDID
:
2616 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2617 MPT3SAS_INTEL_RS3UC080_BRANDING
);
2621 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2622 ioc
->name
, ioc
->pdev
->subsystem_device
);
2628 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2629 ioc
->name
, ioc
->pdev
->subsystem_device
);
2633 case PCI_VENDOR_ID_DELL
:
2634 switch (ioc
->pdev
->device
) {
2635 case MPI2_MFGPAGE_DEVID_SAS2008
:
2636 switch (ioc
->pdev
->subsystem_device
) {
2637 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID
:
2638 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2639 MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING
);
2641 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID
:
2642 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2643 MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING
);
2645 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID
:
2646 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2647 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING
);
2649 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID
:
2650 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2651 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING
);
2653 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID
:
2654 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2655 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING
);
2657 case MPT2SAS_DELL_PERC_H200_SSDID
:
2658 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2659 MPT2SAS_DELL_PERC_H200_BRANDING
);
2661 case MPT2SAS_DELL_6GBPS_SAS_SSDID
:
2662 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2663 MPT2SAS_DELL_6GBPS_SAS_BRANDING
);
2667 "Dell 6Gbps HBA: Subsystem ID: 0x%X\n",
2668 ioc
->name
, ioc
->pdev
->subsystem_device
);
2672 case MPI25_MFGPAGE_DEVID_SAS3008
:
2673 switch (ioc
->pdev
->subsystem_device
) {
2674 case MPT3SAS_DELL_12G_HBA_SSDID
:
2675 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2676 MPT3SAS_DELL_12G_HBA_BRANDING
);
2680 "Dell 12Gbps HBA: Subsystem ID: 0x%X\n",
2681 ioc
->name
, ioc
->pdev
->subsystem_device
);
2687 "Dell HBA: Subsystem ID: 0x%X\n", ioc
->name
,
2688 ioc
->pdev
->subsystem_device
);
2692 case PCI_VENDOR_ID_CISCO
:
2693 switch (ioc
->pdev
->device
) {
2694 case MPI25_MFGPAGE_DEVID_SAS3008
:
2695 switch (ioc
->pdev
->subsystem_device
) {
2696 case MPT3SAS_CISCO_12G_8E_HBA_SSDID
:
2697 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2698 MPT3SAS_CISCO_12G_8E_HBA_BRANDING
);
2700 case MPT3SAS_CISCO_12G_8I_HBA_SSDID
:
2701 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2702 MPT3SAS_CISCO_12G_8I_HBA_BRANDING
);
2704 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID
:
2705 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2706 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING
);
2710 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n",
2711 ioc
->name
, ioc
->pdev
->subsystem_device
);
2715 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
2716 switch (ioc
->pdev
->subsystem_device
) {
2717 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID
:
2718 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2719 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING
);
2721 case MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_SSDID
:
2722 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2723 MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING
2728 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n",
2729 ioc
->name
, ioc
->pdev
->subsystem_device
);
2735 "Cisco SAS HBA: Subsystem ID: 0x%X\n",
2736 ioc
->name
, ioc
->pdev
->subsystem_device
);
2740 case MPT2SAS_HP_3PAR_SSVID
:
2741 switch (ioc
->pdev
->device
) {
2742 case MPI2_MFGPAGE_DEVID_SAS2004
:
2743 switch (ioc
->pdev
->subsystem_device
) {
2744 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID
:
2745 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2746 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING
);
2750 "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n",
2751 ioc
->name
, ioc
->pdev
->subsystem_device
);
2754 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
2755 switch (ioc
->pdev
->subsystem_device
) {
2756 case MPT2SAS_HP_2_4_INTERNAL_SSDID
:
2757 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2758 MPT2SAS_HP_2_4_INTERNAL_BRANDING
);
2760 case MPT2SAS_HP_2_4_EXTERNAL_SSDID
:
2761 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2762 MPT2SAS_HP_2_4_EXTERNAL_BRANDING
);
2764 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID
:
2765 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2766 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING
);
2768 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID
:
2769 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2770 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING
);
2774 "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n",
2775 ioc
->name
, ioc
->pdev
->subsystem_device
);
2780 "HP SAS HBA: Subsystem ID: 0x%X\n",
2781 ioc
->name
, ioc
->pdev
->subsystem_device
);
2790 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2791 * @ioc: per adapter object
2796 _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER
*ioc
)
2800 u32 iounit_pg1_flags
;
2803 bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2804 strncpy(desc
, ioc
->manu_pg0
.ChipName
, 16);
2805 pr_info(MPT3SAS_FMT
"%s: FWVersion(%02d.%02d.%02d.%02d), "\
2806 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2808 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2809 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2810 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2811 ioc
->facts
.FWVersion
.Word
& 0x000000FF,
2812 ioc
->pdev
->revision
,
2813 (bios_version
& 0xFF000000) >> 24,
2814 (bios_version
& 0x00FF0000) >> 16,
2815 (bios_version
& 0x0000FF00) >> 8,
2816 bios_version
& 0x000000FF);
2818 _base_display_OEMs_branding(ioc
);
2820 pr_info(MPT3SAS_FMT
"Protocol=(", ioc
->name
);
2822 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
) {
2823 pr_info("Initiator");
2827 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET
) {
2828 pr_info("%sTarget", i
? "," : "");
2834 pr_info("Capabilities=(");
2836 if (!ioc
->hide_ir_msg
) {
2837 if (ioc
->facts
.IOCCapabilities
&
2838 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
) {
2844 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
) {
2845 pr_info("%sTLR", i
? "," : "");
2849 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_MULTICAST
) {
2850 pr_info("%sMulticast", i
? "," : "");
2854 if (ioc
->facts
.IOCCapabilities
&
2855 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET
) {
2856 pr_info("%sBIDI Target", i
? "," : "");
2860 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_EEDP
) {
2861 pr_info("%sEEDP", i
? "," : "");
2865 if (ioc
->facts
.IOCCapabilities
&
2866 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
) {
2867 pr_info("%sSnapshot Buffer", i
? "," : "");
2871 if (ioc
->facts
.IOCCapabilities
&
2872 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
) {
2873 pr_info("%sDiag Trace Buffer", i
? "," : "");
2877 if (ioc
->facts
.IOCCapabilities
&
2878 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
) {
2879 pr_info("%sDiag Extended Buffer", i
? "," : "");
2883 if (ioc
->facts
.IOCCapabilities
&
2884 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
) {
2885 pr_info("%sTask Set Full", i
? "," : "");
2889 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2890 if (!(iounit_pg1_flags
& MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE
)) {
2891 pr_info("%sNCQ", i
? "," : "");
2899 * mpt3sas_base_update_missing_delay - change the missing delay timers
2900 * @ioc: per adapter object
2901 * @device_missing_delay: amount of time till device is reported missing
2902 * @io_missing_delay: interval IO is returned when there is a missing device
2906 * Passed on the command line, this function will modify the device missing
2907 * delay, as well as the io missing delay. This should be called at driver
2911 mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER
*ioc
,
2912 u16 device_missing_delay
, u8 io_missing_delay
)
2914 u16 dmd
, dmd_new
, dmd_orignal
;
2915 u8 io_missing_delay_original
;
2917 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
2918 Mpi2ConfigReply_t mpi_reply
;
2922 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
2926 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (num_phys
*
2927 sizeof(Mpi2SasIOUnit1PhyData_t
));
2928 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
2929 if (!sas_iounit_pg1
) {
2930 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2931 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2934 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
2935 sas_iounit_pg1
, sz
))) {
2936 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2937 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2940 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
2941 MPI2_IOCSTATUS_MASK
;
2942 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2943 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2944 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2948 /* device missing delay */
2949 dmd
= sas_iounit_pg1
->ReportDeviceMissingDelay
;
2950 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2951 dmd
= (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2953 dmd
= dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2955 if (device_missing_delay
> 0x7F) {
2956 dmd
= (device_missing_delay
> 0x7F0) ? 0x7F0 :
2957 device_missing_delay
;
2959 dmd
|= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
;
2961 dmd
= device_missing_delay
;
2962 sas_iounit_pg1
->ReportDeviceMissingDelay
= dmd
;
2964 /* io missing delay */
2965 io_missing_delay_original
= sas_iounit_pg1
->IODeviceMissingDelay
;
2966 sas_iounit_pg1
->IODeviceMissingDelay
= io_missing_delay
;
2968 if (!mpt3sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
2970 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2972 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2975 dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2976 pr_info(MPT3SAS_FMT
"device_missing_delay: old(%d), new(%d)\n",
2977 ioc
->name
, dmd_orignal
, dmd_new
);
2978 pr_info(MPT3SAS_FMT
"ioc_missing_delay: old(%d), new(%d)\n",
2979 ioc
->name
, io_missing_delay_original
,
2981 ioc
->device_missing_delay
= dmd_new
;
2982 ioc
->io_missing_delay
= io_missing_delay
;
2986 kfree(sas_iounit_pg1
);
2989 * _base_static_config_pages - static start of day config pages
2990 * @ioc: per adapter object
2995 _base_static_config_pages(struct MPT3SAS_ADAPTER
*ioc
)
2997 Mpi2ConfigReply_t mpi_reply
;
2998 u32 iounit_pg1_flags
;
3000 mpt3sas_config_get_manufacturing_pg0(ioc
, &mpi_reply
, &ioc
->manu_pg0
);
3001 if (ioc
->ir_firmware
)
3002 mpt3sas_config_get_manufacturing_pg10(ioc
, &mpi_reply
,
3006 * Ensure correct T10 PI operation if vendor left EEDPTagMode
3007 * flag unset in NVDATA.
3009 mpt3sas_config_get_manufacturing_pg11(ioc
, &mpi_reply
, &ioc
->manu_pg11
);
3010 if (ioc
->manu_pg11
.EEDPTagMode
== 0) {
3011 pr_err("%s: overriding NVDATA EEDPTagMode setting\n",
3013 ioc
->manu_pg11
.EEDPTagMode
&= ~0x3;
3014 ioc
->manu_pg11
.EEDPTagMode
|= 0x1;
3015 mpt3sas_config_set_manufacturing_pg11(ioc
, &mpi_reply
,
3019 mpt3sas_config_get_bios_pg2(ioc
, &mpi_reply
, &ioc
->bios_pg2
);
3020 mpt3sas_config_get_bios_pg3(ioc
, &mpi_reply
, &ioc
->bios_pg3
);
3021 mpt3sas_config_get_ioc_pg8(ioc
, &mpi_reply
, &ioc
->ioc_pg8
);
3022 mpt3sas_config_get_iounit_pg0(ioc
, &mpi_reply
, &ioc
->iounit_pg0
);
3023 mpt3sas_config_get_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
3024 mpt3sas_config_get_iounit_pg8(ioc
, &mpi_reply
, &ioc
->iounit_pg8
);
3025 _base_display_ioc_capabilities(ioc
);
3028 * Enable task_set_full handling in iounit_pg1 when the
3029 * facts capabilities indicate that its supported.
3031 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
3032 if ((ioc
->facts
.IOCCapabilities
&
3033 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
))
3035 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
3038 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
3039 ioc
->iounit_pg1
.Flags
= cpu_to_le32(iounit_pg1_flags
);
3040 mpt3sas_config_set_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
3042 if (ioc
->iounit_pg8
.NumSensors
)
3043 ioc
->temp_sensors_count
= ioc
->iounit_pg8
.NumSensors
;
3047 * _base_release_memory_pools - release memory
3048 * @ioc: per adapter object
3050 * Free memory allocated from _base_allocate_memory_pools.
3055 _base_release_memory_pools(struct MPT3SAS_ADAPTER
*ioc
)
3058 struct reply_post_struct
*rps
;
3060 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3064 pci_free_consistent(ioc
->pdev
, ioc
->request_dma_sz
,
3065 ioc
->request
, ioc
->request_dma
);
3066 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3067 "request_pool(0x%p): free\n",
3068 ioc
->name
, ioc
->request
));
3069 ioc
->request
= NULL
;
3073 pci_pool_free(ioc
->sense_dma_pool
, ioc
->sense
, ioc
->sense_dma
);
3074 if (ioc
->sense_dma_pool
)
3075 pci_pool_destroy(ioc
->sense_dma_pool
);
3076 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3077 "sense_pool(0x%p): free\n",
3078 ioc
->name
, ioc
->sense
));
3083 pci_pool_free(ioc
->reply_dma_pool
, ioc
->reply
, ioc
->reply_dma
);
3084 if (ioc
->reply_dma_pool
)
3085 pci_pool_destroy(ioc
->reply_dma_pool
);
3086 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3087 "reply_pool(0x%p): free\n",
3088 ioc
->name
, ioc
->reply
));
3092 if (ioc
->reply_free
) {
3093 pci_pool_free(ioc
->reply_free_dma_pool
, ioc
->reply_free
,
3094 ioc
->reply_free_dma
);
3095 if (ioc
->reply_free_dma_pool
)
3096 pci_pool_destroy(ioc
->reply_free_dma_pool
);
3097 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3098 "reply_free_pool(0x%p): free\n",
3099 ioc
->name
, ioc
->reply_free
));
3100 ioc
->reply_free
= NULL
;
3103 if (ioc
->reply_post
) {
3105 rps
= &ioc
->reply_post
[i
];
3106 if (rps
->reply_post_free
) {
3108 ioc
->reply_post_free_dma_pool
,
3109 rps
->reply_post_free
,
3110 rps
->reply_post_free_dma
);
3111 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3112 "reply_post_free_pool(0x%p): free\n",
3113 ioc
->name
, rps
->reply_post_free
));
3114 rps
->reply_post_free
= NULL
;
3116 } while (ioc
->rdpq_array_enable
&&
3117 (++i
< ioc
->reply_queue_count
));
3119 if (ioc
->reply_post_free_dma_pool
)
3120 pci_pool_destroy(ioc
->reply_post_free_dma_pool
);
3121 kfree(ioc
->reply_post
);
3124 if (ioc
->config_page
) {
3125 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3126 "config_page(0x%p): free\n", ioc
->name
,
3128 pci_free_consistent(ioc
->pdev
, ioc
->config_page_sz
,
3129 ioc
->config_page
, ioc
->config_page_dma
);
3132 if (ioc
->scsi_lookup
) {
3133 free_pages((ulong
)ioc
->scsi_lookup
, ioc
->scsi_lookup_pages
);
3134 ioc
->scsi_lookup
= NULL
;
3136 kfree(ioc
->hpr_lookup
);
3137 kfree(ioc
->internal_lookup
);
3138 if (ioc
->chain_lookup
) {
3139 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
3140 if (ioc
->chain_lookup
[i
].chain_buffer
)
3141 pci_pool_free(ioc
->chain_dma_pool
,
3142 ioc
->chain_lookup
[i
].chain_buffer
,
3143 ioc
->chain_lookup
[i
].chain_buffer_dma
);
3145 if (ioc
->chain_dma_pool
)
3146 pci_pool_destroy(ioc
->chain_dma_pool
);
3147 free_pages((ulong
)ioc
->chain_lookup
, ioc
->chain_pages
);
3148 ioc
->chain_lookup
= NULL
;
3153 * _base_allocate_memory_pools - allocate start of day memory pools
3154 * @ioc: per adapter object
3155 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3157 * Returns 0 success, anything else error
3160 _base_allocate_memory_pools(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3162 struct mpt3sas_facts
*facts
;
3163 u16 max_sge_elements
;
3164 u16 chains_needed_per_io
;
3165 u32 sz
, total_sz
, reply_post_free_sz
;
3167 u16 max_request_credit
;
3168 unsigned short sg_tablesize
;
3172 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3177 facts
= &ioc
->facts
;
3179 /* command line tunables for max sgl entries */
3180 if (max_sgl_entries
!= -1)
3181 sg_tablesize
= max_sgl_entries
;
3183 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
3184 sg_tablesize
= MPT2SAS_SG_DEPTH
;
3186 sg_tablesize
= MPT3SAS_SG_DEPTH
;
3189 if (sg_tablesize
< MPT_MIN_PHYS_SEGMENTS
)
3190 sg_tablesize
= MPT_MIN_PHYS_SEGMENTS
;
3191 else if (sg_tablesize
> MPT_MAX_PHYS_SEGMENTS
) {
3192 sg_tablesize
= min_t(unsigned short, sg_tablesize
,
3193 SCSI_MAX_SG_CHAIN_SEGMENTS
);
3195 "sg_tablesize(%u) is bigger than kernel"
3196 " defined SCSI_MAX_SG_SEGMENTS(%u)\n", ioc
->name
,
3197 sg_tablesize
, MPT_MAX_PHYS_SEGMENTS
);
3199 ioc
->shost
->sg_tablesize
= sg_tablesize
;
3201 ioc
->hi_priority_depth
= facts
->HighPriorityCredit
;
3202 ioc
->internal_depth
= ioc
->hi_priority_depth
+ (5);
3203 /* command line tunables for max controller queue depth */
3204 if (max_queue_depth
!= -1 && max_queue_depth
!= 0) {
3205 max_request_credit
= min_t(u16
, max_queue_depth
+
3206 ioc
->hi_priority_depth
+ ioc
->internal_depth
,
3207 facts
->RequestCredit
);
3208 if (max_request_credit
> MAX_HBA_QUEUE_DEPTH
)
3209 max_request_credit
= MAX_HBA_QUEUE_DEPTH
;
3211 max_request_credit
= min_t(u16
, facts
->RequestCredit
,
3212 MAX_HBA_QUEUE_DEPTH
);
3214 ioc
->hba_queue_depth
= max_request_credit
;
3216 /* request frame size */
3217 ioc
->request_sz
= facts
->IOCRequestFrameSize
* 4;
3219 /* reply frame size */
3220 ioc
->reply_sz
= facts
->ReplyFrameSize
* 4;
3222 /* calculate the max scatter element size */
3223 sge_size
= max_t(u16
, ioc
->sge_size
, ioc
->sge_size_ieee
);
3227 /* calculate number of sg elements left over in the 1st frame */
3228 max_sge_elements
= ioc
->request_sz
- ((sizeof(Mpi2SCSIIORequest_t
) -
3229 sizeof(Mpi2SGEIOUnion_t
)) + sge_size
);
3230 ioc
->max_sges_in_main_message
= max_sge_elements
/sge_size
;
3232 /* now do the same for a chain buffer */
3233 max_sge_elements
= ioc
->request_sz
- sge_size
;
3234 ioc
->max_sges_in_chain_message
= max_sge_elements
/sge_size
;
3237 * MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
3239 chains_needed_per_io
= ((ioc
->shost
->sg_tablesize
-
3240 ioc
->max_sges_in_main_message
)/ioc
->max_sges_in_chain_message
)
3242 if (chains_needed_per_io
> facts
->MaxChainDepth
) {
3243 chains_needed_per_io
= facts
->MaxChainDepth
;
3244 ioc
->shost
->sg_tablesize
= min_t(u16
,
3245 ioc
->max_sges_in_main_message
+ (ioc
->max_sges_in_chain_message
3246 * chains_needed_per_io
), ioc
->shost
->sg_tablesize
);
3248 ioc
->chains_needed_per_io
= chains_needed_per_io
;
3250 /* reply free queue sizing - taking into account for 64 FW events */
3251 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
3253 /* calculate reply descriptor post queue depth */
3254 ioc
->reply_post_queue_depth
= ioc
->hba_queue_depth
+
3255 ioc
->reply_free_queue_depth
+ 1 ;
3256 /* align the reply post queue on the next 16 count boundary */
3257 if (ioc
->reply_post_queue_depth
% 16)
3258 ioc
->reply_post_queue_depth
+= 16 -
3259 (ioc
->reply_post_queue_depth
% 16);
3262 if (ioc
->reply_post_queue_depth
>
3263 facts
->MaxReplyDescriptorPostQueueDepth
) {
3264 ioc
->reply_post_queue_depth
=
3265 facts
->MaxReplyDescriptorPostQueueDepth
-
3266 (facts
->MaxReplyDescriptorPostQueueDepth
% 16);
3267 ioc
->hba_queue_depth
=
3268 ((ioc
->reply_post_queue_depth
- 64) / 2) - 1;
3269 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
3272 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scatter gather: " \
3273 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
3274 "chains_per_io(%d)\n", ioc
->name
, ioc
->max_sges_in_main_message
,
3275 ioc
->max_sges_in_chain_message
, ioc
->shost
->sg_tablesize
,
3276 ioc
->chains_needed_per_io
));
3278 /* reply post queue, 16 byte align */
3279 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
3280 sizeof(Mpi2DefaultReplyDescriptor_t
);
3282 sz
= reply_post_free_sz
;
3283 if (_base_is_controller_msix_enabled(ioc
) && !ioc
->rdpq_array_enable
)
3284 sz
*= ioc
->reply_queue_count
;
3286 ioc
->reply_post
= kcalloc((ioc
->rdpq_array_enable
) ?
3287 (ioc
->reply_queue_count
):1,
3288 sizeof(struct reply_post_struct
), GFP_KERNEL
);
3290 if (!ioc
->reply_post
) {
3291 pr_err(MPT3SAS_FMT
"reply_post_free pool: kcalloc failed\n",
3295 ioc
->reply_post_free_dma_pool
= pci_pool_create("reply_post_free pool",
3296 ioc
->pdev
, sz
, 16, 0);
3297 if (!ioc
->reply_post_free_dma_pool
) {
3299 "reply_post_free pool: pci_pool_create failed\n",
3305 ioc
->reply_post
[i
].reply_post_free
=
3306 pci_pool_alloc(ioc
->reply_post_free_dma_pool
,
3308 &ioc
->reply_post
[i
].reply_post_free_dma
);
3309 if (!ioc
->reply_post
[i
].reply_post_free
) {
3311 "reply_post_free pool: pci_pool_alloc failed\n",
3315 memset(ioc
->reply_post
[i
].reply_post_free
, 0, sz
);
3316 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3317 "reply post free pool (0x%p): depth(%d),"
3318 "element_size(%d), pool_size(%d kB)\n", ioc
->name
,
3319 ioc
->reply_post
[i
].reply_post_free
,
3320 ioc
->reply_post_queue_depth
, 8, sz
/1024));
3321 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3322 "reply_post_free_dma = (0x%llx)\n", ioc
->name
,
3323 (unsigned long long)
3324 ioc
->reply_post
[i
].reply_post_free_dma
));
3326 } while (ioc
->rdpq_array_enable
&& (++i
< ioc
->reply_queue_count
));
3328 if (ioc
->dma_mask
== 64) {
3329 if (_base_change_consistent_dma_mask(ioc
, ioc
->pdev
) != 0) {
3331 "no suitable consistent DMA mask for %s\n",
3332 ioc
->name
, pci_name(ioc
->pdev
));
3337 ioc
->scsiio_depth
= ioc
->hba_queue_depth
-
3338 ioc
->hi_priority_depth
- ioc
->internal_depth
;
3340 /* set the scsi host can_queue depth
3341 * with some internal commands that could be outstanding
3343 ioc
->shost
->can_queue
= ioc
->scsiio_depth
;
3344 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3345 "scsi host: can_queue depth (%d)\n",
3346 ioc
->name
, ioc
->shost
->can_queue
));
3349 /* contiguous pool for request and chains, 16 byte align, one extra "
3352 ioc
->chain_depth
= ioc
->chains_needed_per_io
* ioc
->scsiio_depth
;
3353 sz
= ((ioc
->scsiio_depth
+ 1) * ioc
->request_sz
);
3355 /* hi-priority queue */
3356 sz
+= (ioc
->hi_priority_depth
* ioc
->request_sz
);
3358 /* internal queue */
3359 sz
+= (ioc
->internal_depth
* ioc
->request_sz
);
3361 ioc
->request_dma_sz
= sz
;
3362 ioc
->request
= pci_alloc_consistent(ioc
->pdev
, sz
, &ioc
->request_dma
);
3363 if (!ioc
->request
) {
3364 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
3365 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
3366 "total(%d kB)\n", ioc
->name
, ioc
->hba_queue_depth
,
3367 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
3368 if (ioc
->scsiio_depth
< MPT3SAS_SAS_QUEUE_DEPTH
)
3371 ioc
->hba_queue_depth
= max_request_credit
- retry_sz
;
3372 goto retry_allocation
;
3376 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
3377 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
3378 "total(%d kb)\n", ioc
->name
, ioc
->hba_queue_depth
,
3379 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
3381 /* hi-priority queue */
3382 ioc
->hi_priority
= ioc
->request
+ ((ioc
->scsiio_depth
+ 1) *
3384 ioc
->hi_priority_dma
= ioc
->request_dma
+ ((ioc
->scsiio_depth
+ 1) *
3387 /* internal queue */
3388 ioc
->internal
= ioc
->hi_priority
+ (ioc
->hi_priority_depth
*
3390 ioc
->internal_dma
= ioc
->hi_priority_dma
+ (ioc
->hi_priority_depth
*
3393 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3394 "request pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
3395 ioc
->name
, ioc
->request
, ioc
->hba_queue_depth
, ioc
->request_sz
,
3396 (ioc
->hba_queue_depth
* ioc
->request_sz
)/1024));
3398 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"request pool: dma(0x%llx)\n",
3399 ioc
->name
, (unsigned long long) ioc
->request_dma
));
3402 sz
= ioc
->scsiio_depth
* sizeof(struct scsiio_tracker
);
3403 ioc
->scsi_lookup_pages
= get_order(sz
);
3404 ioc
->scsi_lookup
= (struct scsiio_tracker
*)__get_free_pages(
3405 GFP_KERNEL
, ioc
->scsi_lookup_pages
);
3406 if (!ioc
->scsi_lookup
) {
3407 pr_err(MPT3SAS_FMT
"scsi_lookup: get_free_pages failed, sz(%d)\n",
3408 ioc
->name
, (int)sz
);
3412 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scsiio(0x%p): depth(%d)\n",
3413 ioc
->name
, ioc
->request
, ioc
->scsiio_depth
));
3415 ioc
->chain_depth
= min_t(u32
, ioc
->chain_depth
, MAX_CHAIN_DEPTH
);
3416 sz
= ioc
->chain_depth
* sizeof(struct chain_tracker
);
3417 ioc
->chain_pages
= get_order(sz
);
3418 ioc
->chain_lookup
= (struct chain_tracker
*)__get_free_pages(
3419 GFP_KERNEL
, ioc
->chain_pages
);
3420 if (!ioc
->chain_lookup
) {
3421 pr_err(MPT3SAS_FMT
"chain_lookup: __get_free_pages failed\n",
3425 ioc
->chain_dma_pool
= pci_pool_create("chain pool", ioc
->pdev
,
3426 ioc
->request_sz
, 16, 0);
3427 if (!ioc
->chain_dma_pool
) {
3428 pr_err(MPT3SAS_FMT
"chain_dma_pool: pci_pool_create failed\n",
3432 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
3433 ioc
->chain_lookup
[i
].chain_buffer
= pci_pool_alloc(
3434 ioc
->chain_dma_pool
, GFP_KERNEL
,
3435 &ioc
->chain_lookup
[i
].chain_buffer_dma
);
3436 if (!ioc
->chain_lookup
[i
].chain_buffer
) {
3437 ioc
->chain_depth
= i
;
3440 total_sz
+= ioc
->request_sz
;
3443 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3444 "chain pool depth(%d), frame_size(%d), pool_size(%d kB)\n",
3445 ioc
->name
, ioc
->chain_depth
, ioc
->request_sz
,
3446 ((ioc
->chain_depth
* ioc
->request_sz
))/1024));
3448 /* initialize hi-priority queue smid's */
3449 ioc
->hpr_lookup
= kcalloc(ioc
->hi_priority_depth
,
3450 sizeof(struct request_tracker
), GFP_KERNEL
);
3451 if (!ioc
->hpr_lookup
) {
3452 pr_err(MPT3SAS_FMT
"hpr_lookup: kcalloc failed\n",
3456 ioc
->hi_priority_smid
= ioc
->scsiio_depth
+ 1;
3457 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3458 "hi_priority(0x%p): depth(%d), start smid(%d)\n",
3459 ioc
->name
, ioc
->hi_priority
,
3460 ioc
->hi_priority_depth
, ioc
->hi_priority_smid
));
3462 /* initialize internal queue smid's */
3463 ioc
->internal_lookup
= kcalloc(ioc
->internal_depth
,
3464 sizeof(struct request_tracker
), GFP_KERNEL
);
3465 if (!ioc
->internal_lookup
) {
3466 pr_err(MPT3SAS_FMT
"internal_lookup: kcalloc failed\n",
3470 ioc
->internal_smid
= ioc
->hi_priority_smid
+ ioc
->hi_priority_depth
;
3471 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3472 "internal(0x%p): depth(%d), start smid(%d)\n",
3473 ioc
->name
, ioc
->internal
,
3474 ioc
->internal_depth
, ioc
->internal_smid
));
3476 /* sense buffers, 4 byte align */
3477 sz
= ioc
->scsiio_depth
* SCSI_SENSE_BUFFERSIZE
;
3478 ioc
->sense_dma_pool
= pci_pool_create("sense pool", ioc
->pdev
, sz
, 4,
3480 if (!ioc
->sense_dma_pool
) {
3481 pr_err(MPT3SAS_FMT
"sense pool: pci_pool_create failed\n",
3485 ioc
->sense
= pci_pool_alloc(ioc
->sense_dma_pool
, GFP_KERNEL
,
3488 pr_err(MPT3SAS_FMT
"sense pool: pci_pool_alloc failed\n",
3492 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3493 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
3494 "(%d kB)\n", ioc
->name
, ioc
->sense
, ioc
->scsiio_depth
,
3495 SCSI_SENSE_BUFFERSIZE
, sz
/1024));
3496 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"sense_dma(0x%llx)\n",
3497 ioc
->name
, (unsigned long long)ioc
->sense_dma
));
3500 /* reply pool, 4 byte align */
3501 sz
= ioc
->reply_free_queue_depth
* ioc
->reply_sz
;
3502 ioc
->reply_dma_pool
= pci_pool_create("reply pool", ioc
->pdev
, sz
, 4,
3504 if (!ioc
->reply_dma_pool
) {
3505 pr_err(MPT3SAS_FMT
"reply pool: pci_pool_create failed\n",
3509 ioc
->reply
= pci_pool_alloc(ioc
->reply_dma_pool
, GFP_KERNEL
,
3512 pr_err(MPT3SAS_FMT
"reply pool: pci_pool_alloc failed\n",
3516 ioc
->reply_dma_min_address
= (u32
)(ioc
->reply_dma
);
3517 ioc
->reply_dma_max_address
= (u32
)(ioc
->reply_dma
) + sz
;
3518 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3519 "reply pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
3520 ioc
->name
, ioc
->reply
,
3521 ioc
->reply_free_queue_depth
, ioc
->reply_sz
, sz
/1024));
3522 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_dma(0x%llx)\n",
3523 ioc
->name
, (unsigned long long)ioc
->reply_dma
));
3526 /* reply free queue, 16 byte align */
3527 sz
= ioc
->reply_free_queue_depth
* 4;
3528 ioc
->reply_free_dma_pool
= pci_pool_create("reply_free pool",
3529 ioc
->pdev
, sz
, 16, 0);
3530 if (!ioc
->reply_free_dma_pool
) {
3531 pr_err(MPT3SAS_FMT
"reply_free pool: pci_pool_create failed\n",
3535 ioc
->reply_free
= pci_pool_alloc(ioc
->reply_free_dma_pool
, GFP_KERNEL
,
3536 &ioc
->reply_free_dma
);
3537 if (!ioc
->reply_free
) {
3538 pr_err(MPT3SAS_FMT
"reply_free pool: pci_pool_alloc failed\n",
3542 memset(ioc
->reply_free
, 0, sz
);
3543 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_free pool(0x%p): " \
3544 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc
->name
,
3545 ioc
->reply_free
, ioc
->reply_free_queue_depth
, 4, sz
/1024));
3546 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3547 "reply_free_dma (0x%llx)\n",
3548 ioc
->name
, (unsigned long long)ioc
->reply_free_dma
));
3551 ioc
->config_page_sz
= 512;
3552 ioc
->config_page
= pci_alloc_consistent(ioc
->pdev
,
3553 ioc
->config_page_sz
, &ioc
->config_page_dma
);
3554 if (!ioc
->config_page
) {
3556 "config page: pci_pool_alloc failed\n",
3560 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3561 "config page(0x%p): size(%d)\n",
3562 ioc
->name
, ioc
->config_page
, ioc
->config_page_sz
));
3563 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"config_page_dma(0x%llx)\n",
3564 ioc
->name
, (unsigned long long)ioc
->config_page_dma
));
3565 total_sz
+= ioc
->config_page_sz
;
3567 pr_info(MPT3SAS_FMT
"Allocated physical memory: size(%d kB)\n",
3568 ioc
->name
, total_sz
/1024);
3570 "Current Controller Queue Depth(%d),Max Controller Queue Depth(%d)\n",
3571 ioc
->name
, ioc
->shost
->can_queue
, facts
->RequestCredit
);
3572 pr_info(MPT3SAS_FMT
"Scatter Gather Elements per IO(%d)\n",
3573 ioc
->name
, ioc
->shost
->sg_tablesize
);
3581 * mpt3sas_base_get_iocstate - Get the current state of a MPT adapter.
3582 * @ioc: Pointer to MPT_ADAPTER structure
3583 * @cooked: Request raw or cooked IOC state
3585 * Returns all IOC Doorbell register bits if cooked==0, else just the
3586 * Doorbell bits in MPI_IOC_STATE_MASK.
3589 mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER
*ioc
, int cooked
)
3593 s
= readl(&ioc
->chip
->Doorbell
);
3594 sc
= s
& MPI2_IOC_STATE_MASK
;
3595 return cooked
? sc
: s
;
3599 * _base_wait_on_iocstate - waiting on a particular ioc state
3600 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
3601 * @timeout: timeout in second
3602 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3604 * Returns 0 for success, non-zero for failure.
3607 _base_wait_on_iocstate(struct MPT3SAS_ADAPTER
*ioc
, u32 ioc_state
, int timeout
,
3614 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3616 current_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3617 if (current_state
== ioc_state
)
3619 if (count
&& current_state
== MPI2_IOC_STATE_FAULT
)
3621 if (sleep_flag
== CAN_SLEEP
)
3622 usleep_range(1000, 1500);
3628 return current_state
;
3632 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
3633 * a write to the doorbell)
3634 * @ioc: per adapter object
3635 * @timeout: timeout in second
3636 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3638 * Returns 0 for success, non-zero for failure.
3640 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
3643 _base_diag_reset(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
);
3646 _base_wait_for_doorbell_int(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3653 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3655 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
3656 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
3657 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3658 "%s: successful count(%d), timeout(%d)\n",
3659 ioc
->name
, __func__
, count
, timeout
));
3662 if (sleep_flag
== CAN_SLEEP
)
3663 usleep_range(1000, 1500);
3670 "%s: failed due to timeout count(%d), int_status(%x)!\n",
3671 ioc
->name
, __func__
, count
, int_status
);
3676 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
3677 * @ioc: per adapter object
3678 * @timeout: timeout in second
3679 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3681 * Returns 0 for success, non-zero for failure.
3683 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
3687 _base_wait_for_doorbell_ack(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3695 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3697 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
3698 if (!(int_status
& MPI2_HIS_SYS2IOC_DB_STATUS
)) {
3699 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3700 "%s: successful count(%d), timeout(%d)\n",
3701 ioc
->name
, __func__
, count
, timeout
));
3703 } else if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
3704 doorbell
= readl(&ioc
->chip
->Doorbell
);
3705 if ((doorbell
& MPI2_IOC_STATE_MASK
) ==
3706 MPI2_IOC_STATE_FAULT
) {
3707 mpt3sas_base_fault_info(ioc
, doorbell
);
3710 } else if (int_status
== 0xFFFFFFFF)
3713 if (sleep_flag
== CAN_SLEEP
)
3714 usleep_range(1000, 1500);
3722 "%s: failed due to timeout count(%d), int_status(%x)!\n",
3723 ioc
->name
, __func__
, count
, int_status
);
3728 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
3729 * @ioc: per adapter object
3730 * @timeout: timeout in second
3731 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3733 * Returns 0 for success, non-zero for failure.
3737 _base_wait_for_doorbell_not_used(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3744 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3746 doorbell_reg
= readl(&ioc
->chip
->Doorbell
);
3747 if (!(doorbell_reg
& MPI2_DOORBELL_USED
)) {
3748 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3749 "%s: successful count(%d), timeout(%d)\n",
3750 ioc
->name
, __func__
, count
, timeout
));
3753 if (sleep_flag
== CAN_SLEEP
)
3754 usleep_range(1000, 1500);
3761 "%s: failed due to timeout count(%d), doorbell_reg(%x)!\n",
3762 ioc
->name
, __func__
, count
, doorbell_reg
);
3767 * _base_send_ioc_reset - send doorbell reset
3768 * @ioc: per adapter object
3769 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
3770 * @timeout: timeout in second
3771 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3773 * Returns 0 for success, non-zero for failure.
3776 _base_send_ioc_reset(struct MPT3SAS_ADAPTER
*ioc
, u8 reset_type
, int timeout
,
3782 if (reset_type
!= MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
) {
3783 pr_err(MPT3SAS_FMT
"%s: unknown reset_type\n",
3784 ioc
->name
, __func__
);
3788 if (!(ioc
->facts
.IOCCapabilities
&
3789 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY
))
3792 pr_info(MPT3SAS_FMT
"sending message unit reset !!\n", ioc
->name
);
3794 writel(reset_type
<< MPI2_DOORBELL_FUNCTION_SHIFT
,
3795 &ioc
->chip
->Doorbell
);
3796 if ((_base_wait_for_doorbell_ack(ioc
, 15, sleep_flag
))) {
3800 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
,
3801 timeout
, sleep_flag
);
3804 "%s: failed going to ready state (ioc_state=0x%x)\n",
3805 ioc
->name
, __func__
, ioc_state
);
3810 pr_info(MPT3SAS_FMT
"message unit reset: %s\n",
3811 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
3816 * _base_handshake_req_reply_wait - send request thru doorbell interface
3817 * @ioc: per adapter object
3818 * @request_bytes: request length
3819 * @request: pointer having request payload
3820 * @reply_bytes: reply length
3821 * @reply: pointer to reply payload
3822 * @timeout: timeout in second
3823 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3825 * Returns 0 for success, non-zero for failure.
3828 _base_handshake_req_reply_wait(struct MPT3SAS_ADAPTER
*ioc
, int request_bytes
,
3829 u32
*request
, int reply_bytes
, u16
*reply
, int timeout
, int sleep_flag
)
3831 MPI2DefaultReply_t
*default_reply
= (MPI2DefaultReply_t
*)reply
;
3837 /* make sure doorbell is not in use */
3838 if ((readl(&ioc
->chip
->Doorbell
) & MPI2_DOORBELL_USED
)) {
3840 "doorbell is in use (line=%d)\n",
3841 ioc
->name
, __LINE__
);
3845 /* clear pending doorbell interrupts from previous state changes */
3846 if (readl(&ioc
->chip
->HostInterruptStatus
) &
3847 MPI2_HIS_IOC2SYS_DB_STATUS
)
3848 writel(0, &ioc
->chip
->HostInterruptStatus
);
3850 /* send message to ioc */
3851 writel(((MPI2_FUNCTION_HANDSHAKE
<<MPI2_DOORBELL_FUNCTION_SHIFT
) |
3852 ((request_bytes
/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT
)),
3853 &ioc
->chip
->Doorbell
);
3855 if ((_base_wait_for_doorbell_int(ioc
, 5, NO_SLEEP
))) {
3857 "doorbell handshake int failed (line=%d)\n",
3858 ioc
->name
, __LINE__
);
3861 writel(0, &ioc
->chip
->HostInterruptStatus
);
3863 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
))) {
3865 "doorbell handshake ack failed (line=%d)\n",
3866 ioc
->name
, __LINE__
);
3870 /* send message 32-bits at a time */
3871 for (i
= 0, failed
= 0; i
< request_bytes
/4 && !failed
; i
++) {
3872 writel(cpu_to_le32(request
[i
]), &ioc
->chip
->Doorbell
);
3873 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
)))
3879 "doorbell handshake sending request failed (line=%d)\n",
3880 ioc
->name
, __LINE__
);
3884 /* now wait for the reply */
3885 if ((_base_wait_for_doorbell_int(ioc
, timeout
, sleep_flag
))) {
3887 "doorbell handshake int failed (line=%d)\n",
3888 ioc
->name
, __LINE__
);
3892 /* read the first two 16-bits, it gives the total length of the reply */
3893 reply
[0] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3894 & MPI2_DOORBELL_DATA_MASK
);
3895 writel(0, &ioc
->chip
->HostInterruptStatus
);
3896 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3898 "doorbell handshake int failed (line=%d)\n",
3899 ioc
->name
, __LINE__
);
3902 reply
[1] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3903 & MPI2_DOORBELL_DATA_MASK
);
3904 writel(0, &ioc
->chip
->HostInterruptStatus
);
3906 for (i
= 2; i
< default_reply
->MsgLength
* 2; i
++) {
3907 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3909 "doorbell handshake int failed (line=%d)\n",
3910 ioc
->name
, __LINE__
);
3913 if (i
>= reply_bytes
/2) /* overflow case */
3914 dummy
= readl(&ioc
->chip
->Doorbell
);
3916 reply
[i
] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3917 & MPI2_DOORBELL_DATA_MASK
);
3918 writel(0, &ioc
->chip
->HostInterruptStatus
);
3921 _base_wait_for_doorbell_int(ioc
, 5, sleep_flag
);
3922 if (_base_wait_for_doorbell_not_used(ioc
, 5, sleep_flag
) != 0) {
3923 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3924 "doorbell is in use (line=%d)\n", ioc
->name
, __LINE__
));
3926 writel(0, &ioc
->chip
->HostInterruptStatus
);
3928 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3929 mfp
= (__le32
*)reply
;
3930 pr_info("\toffset:data\n");
3931 for (i
= 0; i
< reply_bytes
/4; i
++)
3932 pr_info("\t[0x%02x]:%08x\n", i
*4,
3933 le32_to_cpu(mfp
[i
]));
3939 * mpt3sas_base_sas_iounit_control - send sas iounit control to FW
3940 * @ioc: per adapter object
3941 * @mpi_reply: the reply payload from FW
3942 * @mpi_request: the request payload sent to FW
3944 * The SAS IO Unit Control Request message allows the host to perform low-level
3945 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3946 * to obtain the IOC assigned device handles for a device if it has other
3947 * identifying information about the device, in addition allows the host to
3948 * remove IOC resources associated with the device.
3950 * Returns 0 for success, non-zero for failure.
3953 mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER
*ioc
,
3954 Mpi2SasIoUnitControlReply_t
*mpi_reply
,
3955 Mpi2SasIoUnitControlRequest_t
*mpi_request
)
3959 unsigned long timeleft
;
3960 bool issue_reset
= false;
3963 u16 wait_state_count
;
3965 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3968 mutex_lock(&ioc
->base_cmds
.mutex
);
3970 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
3971 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
3972 ioc
->name
, __func__
);
3977 wait_state_count
= 0;
3978 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3979 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3980 if (wait_state_count
++ == 10) {
3982 "%s: failed due to ioc not operational\n",
3983 ioc
->name
, __func__
);
3988 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3990 "%s: waiting for operational state(count=%d)\n",
3991 ioc
->name
, __func__
, wait_state_count
);
3994 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3996 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3997 ioc
->name
, __func__
);
4003 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
4004 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4005 ioc
->base_cmds
.smid
= smid
;
4006 memcpy(request
, mpi_request
, sizeof(Mpi2SasIoUnitControlRequest_t
));
4007 if (mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
4008 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
)
4009 ioc
->ioc_link_reset_in_progress
= 1;
4010 init_completion(&ioc
->base_cmds
.done
);
4011 mpt3sas_base_put_smid_default(ioc
, smid
);
4012 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
4013 msecs_to_jiffies(10000));
4014 if ((mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
4015 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
) &&
4016 ioc
->ioc_link_reset_in_progress
)
4017 ioc
->ioc_link_reset_in_progress
= 0;
4018 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
4019 pr_err(MPT3SAS_FMT
"%s: timeout\n",
4020 ioc
->name
, __func__
);
4021 _debug_dump_mf(mpi_request
,
4022 sizeof(Mpi2SasIoUnitControlRequest_t
)/4);
4023 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
4025 goto issue_host_reset
;
4027 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
4028 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
4029 sizeof(Mpi2SasIoUnitControlReply_t
));
4031 memset(mpi_reply
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
4032 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4037 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
4039 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4042 mutex_unlock(&ioc
->base_cmds
.mutex
);
4047 * mpt3sas_base_scsi_enclosure_processor - sending request to sep device
4048 * @ioc: per adapter object
4049 * @mpi_reply: the reply payload from FW
4050 * @mpi_request: the request payload sent to FW
4052 * The SCSI Enclosure Processor request message causes the IOC to
4053 * communicate with SES devices to control LED status signals.
4055 * Returns 0 for success, non-zero for failure.
4058 mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER
*ioc
,
4059 Mpi2SepReply_t
*mpi_reply
, Mpi2SepRequest_t
*mpi_request
)
4063 unsigned long timeleft
;
4064 bool issue_reset
= false;
4067 u16 wait_state_count
;
4069 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4072 mutex_lock(&ioc
->base_cmds
.mutex
);
4074 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
4075 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
4076 ioc
->name
, __func__
);
4081 wait_state_count
= 0;
4082 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4083 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4084 if (wait_state_count
++ == 10) {
4086 "%s: failed due to ioc not operational\n",
4087 ioc
->name
, __func__
);
4092 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4094 "%s: waiting for operational state(count=%d)\n",
4096 __func__
, wait_state_count
);
4099 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
4101 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4102 ioc
->name
, __func__
);
4108 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
4109 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4110 ioc
->base_cmds
.smid
= smid
;
4111 memcpy(request
, mpi_request
, sizeof(Mpi2SepReply_t
));
4112 init_completion(&ioc
->base_cmds
.done
);
4113 mpt3sas_base_put_smid_default(ioc
, smid
);
4114 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
4115 msecs_to_jiffies(10000));
4116 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
4117 pr_err(MPT3SAS_FMT
"%s: timeout\n",
4118 ioc
->name
, __func__
);
4119 _debug_dump_mf(mpi_request
,
4120 sizeof(Mpi2SepRequest_t
)/4);
4121 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
4122 issue_reset
= false;
4123 goto issue_host_reset
;
4125 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
4126 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
4127 sizeof(Mpi2SepReply_t
));
4129 memset(mpi_reply
, 0, sizeof(Mpi2SepReply_t
));
4130 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4135 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
4137 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4140 mutex_unlock(&ioc
->base_cmds
.mutex
);
4145 * _base_get_port_facts - obtain port facts reply and save in ioc
4146 * @ioc: per adapter object
4147 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4149 * Returns 0 for success, non-zero for failure.
4152 _base_get_port_facts(struct MPT3SAS_ADAPTER
*ioc
, int port
, int sleep_flag
)
4154 Mpi2PortFactsRequest_t mpi_request
;
4155 Mpi2PortFactsReply_t mpi_reply
;
4156 struct mpt3sas_port_facts
*pfacts
;
4157 int mpi_reply_sz
, mpi_request_sz
, r
;
4159 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4162 mpi_reply_sz
= sizeof(Mpi2PortFactsReply_t
);
4163 mpi_request_sz
= sizeof(Mpi2PortFactsRequest_t
);
4164 memset(&mpi_request
, 0, mpi_request_sz
);
4165 mpi_request
.Function
= MPI2_FUNCTION_PORT_FACTS
;
4166 mpi_request
.PortNumber
= port
;
4167 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
4168 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
4171 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
4172 ioc
->name
, __func__
, r
);
4176 pfacts
= &ioc
->pfacts
[port
];
4177 memset(pfacts
, 0, sizeof(struct mpt3sas_port_facts
));
4178 pfacts
->PortNumber
= mpi_reply
.PortNumber
;
4179 pfacts
->VP_ID
= mpi_reply
.VP_ID
;
4180 pfacts
->VF_ID
= mpi_reply
.VF_ID
;
4181 pfacts
->MaxPostedCmdBuffers
=
4182 le16_to_cpu(mpi_reply
.MaxPostedCmdBuffers
);
4188 * _base_wait_for_iocstate - Wait until the card is in READY or OPERATIONAL
4189 * @ioc: per adapter object
4191 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4193 * Returns 0 for success, non-zero for failure.
4196 _base_wait_for_iocstate(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
4202 dinitprintk(ioc
, printk(MPT3SAS_FMT
"%s\n", ioc
->name
,
4205 if (ioc
->pci_error_recovery
) {
4206 dfailprintk(ioc
, printk(MPT3SAS_FMT
4207 "%s: host in pci error recovery\n", ioc
->name
, __func__
));
4211 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4212 dhsprintk(ioc
, printk(MPT3SAS_FMT
"%s: ioc_state(0x%08x)\n",
4213 ioc
->name
, __func__
, ioc_state
));
4215 if (((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
) ||
4216 (ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
4219 if (ioc_state
& MPI2_DOORBELL_USED
) {
4220 dhsprintk(ioc
, printk(MPT3SAS_FMT
4221 "unexpected doorbell active!\n", ioc
->name
));
4222 goto issue_diag_reset
;
4225 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
4226 mpt3sas_base_fault_info(ioc
, ioc_state
&
4227 MPI2_DOORBELL_DATA_MASK
);
4228 goto issue_diag_reset
;
4231 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
,
4232 timeout
, sleep_flag
);
4234 dfailprintk(ioc
, printk(MPT3SAS_FMT
4235 "%s: failed going to ready state (ioc_state=0x%x)\n",
4236 ioc
->name
, __func__
, ioc_state
));
4241 rc
= _base_diag_reset(ioc
, sleep_flag
);
4246 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
4247 * @ioc: per adapter object
4248 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4250 * Returns 0 for success, non-zero for failure.
4253 _base_get_ioc_facts(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4255 Mpi2IOCFactsRequest_t mpi_request
;
4256 Mpi2IOCFactsReply_t mpi_reply
;
4257 struct mpt3sas_facts
*facts
;
4258 int mpi_reply_sz
, mpi_request_sz
, r
;
4260 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4263 r
= _base_wait_for_iocstate(ioc
, 10, sleep_flag
);
4265 dfailprintk(ioc
, printk(MPT3SAS_FMT
4266 "%s: failed getting to correct state\n",
4267 ioc
->name
, __func__
));
4270 mpi_reply_sz
= sizeof(Mpi2IOCFactsReply_t
);
4271 mpi_request_sz
= sizeof(Mpi2IOCFactsRequest_t
);
4272 memset(&mpi_request
, 0, mpi_request_sz
);
4273 mpi_request
.Function
= MPI2_FUNCTION_IOC_FACTS
;
4274 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
4275 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
4278 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
4279 ioc
->name
, __func__
, r
);
4283 facts
= &ioc
->facts
;
4284 memset(facts
, 0, sizeof(struct mpt3sas_facts
));
4285 facts
->MsgVersion
= le16_to_cpu(mpi_reply
.MsgVersion
);
4286 facts
->HeaderVersion
= le16_to_cpu(mpi_reply
.HeaderVersion
);
4287 facts
->VP_ID
= mpi_reply
.VP_ID
;
4288 facts
->VF_ID
= mpi_reply
.VF_ID
;
4289 facts
->IOCExceptions
= le16_to_cpu(mpi_reply
.IOCExceptions
);
4290 facts
->MaxChainDepth
= mpi_reply
.MaxChainDepth
;
4291 facts
->WhoInit
= mpi_reply
.WhoInit
;
4292 facts
->NumberOfPorts
= mpi_reply
.NumberOfPorts
;
4293 facts
->MaxMSIxVectors
= mpi_reply
.MaxMSIxVectors
;
4294 facts
->RequestCredit
= le16_to_cpu(mpi_reply
.RequestCredit
);
4295 facts
->MaxReplyDescriptorPostQueueDepth
=
4296 le16_to_cpu(mpi_reply
.MaxReplyDescriptorPostQueueDepth
);
4297 facts
->ProductID
= le16_to_cpu(mpi_reply
.ProductID
);
4298 facts
->IOCCapabilities
= le32_to_cpu(mpi_reply
.IOCCapabilities
);
4299 if ((facts
->IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
))
4300 ioc
->ir_firmware
= 1;
4301 if ((facts
->IOCCapabilities
&
4302 MPI2_IOCFACTS_CAPABILITY_RDPQ_ARRAY_CAPABLE
))
4303 ioc
->rdpq_array_capable
= 1;
4304 facts
->FWVersion
.Word
= le32_to_cpu(mpi_reply
.FWVersion
.Word
);
4305 facts
->IOCRequestFrameSize
=
4306 le16_to_cpu(mpi_reply
.IOCRequestFrameSize
);
4307 facts
->MaxInitiators
= le16_to_cpu(mpi_reply
.MaxInitiators
);
4308 facts
->MaxTargets
= le16_to_cpu(mpi_reply
.MaxTargets
);
4309 ioc
->shost
->max_id
= -1;
4310 facts
->MaxSasExpanders
= le16_to_cpu(mpi_reply
.MaxSasExpanders
);
4311 facts
->MaxEnclosures
= le16_to_cpu(mpi_reply
.MaxEnclosures
);
4312 facts
->ProtocolFlags
= le16_to_cpu(mpi_reply
.ProtocolFlags
);
4313 facts
->HighPriorityCredit
=
4314 le16_to_cpu(mpi_reply
.HighPriorityCredit
);
4315 facts
->ReplyFrameSize
= mpi_reply
.ReplyFrameSize
;
4316 facts
->MaxDevHandle
= le16_to_cpu(mpi_reply
.MaxDevHandle
);
4318 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4319 "hba queue depth(%d), max chains per io(%d)\n",
4320 ioc
->name
, facts
->RequestCredit
,
4321 facts
->MaxChainDepth
));
4322 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4323 "request frame size(%d), reply frame size(%d)\n", ioc
->name
,
4324 facts
->IOCRequestFrameSize
* 4, facts
->ReplyFrameSize
* 4));
4329 * _base_send_ioc_init - send ioc_init to firmware
4330 * @ioc: per adapter object
4331 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4333 * Returns 0 for success, non-zero for failure.
4336 _base_send_ioc_init(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4338 Mpi2IOCInitRequest_t mpi_request
;
4339 Mpi2IOCInitReply_t mpi_reply
;
4341 struct timeval current_time
;
4343 u32 reply_post_free_array_sz
= 0;
4344 Mpi2IOCInitRDPQArrayEntry
*reply_post_free_array
= NULL
;
4345 dma_addr_t reply_post_free_array_dma
;
4347 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4350 memset(&mpi_request
, 0, sizeof(Mpi2IOCInitRequest_t
));
4351 mpi_request
.Function
= MPI2_FUNCTION_IOC_INIT
;
4352 mpi_request
.WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
4353 mpi_request
.VF_ID
= 0; /* TODO */
4354 mpi_request
.VP_ID
= 0;
4355 mpi_request
.MsgVersion
= cpu_to_le16(ioc
->hba_mpi_version_belonged
);
4356 mpi_request
.HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
4358 if (_base_is_controller_msix_enabled(ioc
))
4359 mpi_request
.HostMSIxVectors
= ioc
->reply_queue_count
;
4360 mpi_request
.SystemRequestFrameSize
= cpu_to_le16(ioc
->request_sz
/4);
4361 mpi_request
.ReplyDescriptorPostQueueDepth
=
4362 cpu_to_le16(ioc
->reply_post_queue_depth
);
4363 mpi_request
.ReplyFreeQueueDepth
=
4364 cpu_to_le16(ioc
->reply_free_queue_depth
);
4366 mpi_request
.SenseBufferAddressHigh
=
4367 cpu_to_le32((u64
)ioc
->sense_dma
>> 32);
4368 mpi_request
.SystemReplyAddressHigh
=
4369 cpu_to_le32((u64
)ioc
->reply_dma
>> 32);
4370 mpi_request
.SystemRequestFrameBaseAddress
=
4371 cpu_to_le64((u64
)ioc
->request_dma
);
4372 mpi_request
.ReplyFreeQueueAddress
=
4373 cpu_to_le64((u64
)ioc
->reply_free_dma
);
4375 if (ioc
->rdpq_array_enable
) {
4376 reply_post_free_array_sz
= ioc
->reply_queue_count
*
4377 sizeof(Mpi2IOCInitRDPQArrayEntry
);
4378 reply_post_free_array
= pci_alloc_consistent(ioc
->pdev
,
4379 reply_post_free_array_sz
, &reply_post_free_array_dma
);
4380 if (!reply_post_free_array
) {
4382 "reply_post_free_array: pci_alloc_consistent failed\n",
4387 memset(reply_post_free_array
, 0, reply_post_free_array_sz
);
4388 for (i
= 0; i
< ioc
->reply_queue_count
; i
++)
4389 reply_post_free_array
[i
].RDPQBaseAddress
=
4391 (u64
)ioc
->reply_post
[i
].reply_post_free_dma
);
4392 mpi_request
.MsgFlags
= MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE
;
4393 mpi_request
.ReplyDescriptorPostQueueAddress
=
4394 cpu_to_le64((u64
)reply_post_free_array_dma
);
4396 mpi_request
.ReplyDescriptorPostQueueAddress
=
4397 cpu_to_le64((u64
)ioc
->reply_post
[0].reply_post_free_dma
);
4400 /* This time stamp specifies number of milliseconds
4401 * since epoch ~ midnight January 1, 1970.
4403 do_gettimeofday(¤t_time
);
4404 mpi_request
.TimeStamp
= cpu_to_le64((u64
)current_time
.tv_sec
* 1000 +
4405 (current_time
.tv_usec
/ 1000));
4407 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
4411 mfp
= (__le32
*)&mpi_request
;
4412 pr_info("\toffset:data\n");
4413 for (i
= 0; i
< sizeof(Mpi2IOCInitRequest_t
)/4; i
++)
4414 pr_info("\t[0x%02x]:%08x\n", i
*4,
4415 le32_to_cpu(mfp
[i
]));
4418 r
= _base_handshake_req_reply_wait(ioc
,
4419 sizeof(Mpi2IOCInitRequest_t
), (u32
*)&mpi_request
,
4420 sizeof(Mpi2IOCInitReply_t
), (u16
*)&mpi_reply
, 10,
4424 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
4425 ioc
->name
, __func__
, r
);
4429 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4430 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
||
4431 mpi_reply
.IOCLogInfo
) {
4432 pr_err(MPT3SAS_FMT
"%s: failed\n", ioc
->name
, __func__
);
4437 if (reply_post_free_array
)
4438 pci_free_consistent(ioc
->pdev
, reply_post_free_array_sz
,
4439 reply_post_free_array
,
4440 reply_post_free_array_dma
);
4445 * mpt3sas_port_enable_done - command completion routine for port enable
4446 * @ioc: per adapter object
4447 * @smid: system request message index
4448 * @msix_index: MSIX table index supplied by the OS
4449 * @reply: reply message frame(lower 32bit addr)
4451 * Return 1 meaning mf should be freed from _base_interrupt
4452 * 0 means the mf is freed from this function.
4455 mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
4458 MPI2DefaultReply_t
*mpi_reply
;
4461 if (ioc
->port_enable_cmds
.status
== MPT3_CMD_NOT_USED
)
4464 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
4468 if (mpi_reply
->Function
!= MPI2_FUNCTION_PORT_ENABLE
)
4471 ioc
->port_enable_cmds
.status
&= ~MPT3_CMD_PENDING
;
4472 ioc
->port_enable_cmds
.status
|= MPT3_CMD_COMPLETE
;
4473 ioc
->port_enable_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
4474 memcpy(ioc
->port_enable_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
4475 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4476 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
4477 ioc
->port_enable_failed
= 1;
4479 if (ioc
->is_driver_loading
) {
4480 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
4481 mpt3sas_port_enable_complete(ioc
);
4484 ioc
->start_scan_failed
= ioc_status
;
4485 ioc
->start_scan
= 0;
4489 complete(&ioc
->port_enable_cmds
.done
);
4494 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
4495 * @ioc: per adapter object
4496 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4498 * Returns 0 for success, non-zero for failure.
4501 _base_send_port_enable(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4503 Mpi2PortEnableRequest_t
*mpi_request
;
4504 Mpi2PortEnableReply_t
*mpi_reply
;
4505 unsigned long timeleft
;
4510 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
4512 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
4513 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
4514 ioc
->name
, __func__
);
4518 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
4520 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4521 ioc
->name
, __func__
);
4525 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
4526 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4527 ioc
->port_enable_cmds
.smid
= smid
;
4528 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
4529 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
4531 init_completion(&ioc
->port_enable_cmds
.done
);
4532 mpt3sas_base_put_smid_default(ioc
, smid
);
4533 timeleft
= wait_for_completion_timeout(&ioc
->port_enable_cmds
.done
,
4535 if (!(ioc
->port_enable_cmds
.status
& MPT3_CMD_COMPLETE
)) {
4536 pr_err(MPT3SAS_FMT
"%s: timeout\n",
4537 ioc
->name
, __func__
);
4538 _debug_dump_mf(mpi_request
,
4539 sizeof(Mpi2PortEnableRequest_t
)/4);
4540 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_RESET
)
4547 mpi_reply
= ioc
->port_enable_cmds
.reply
;
4548 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
4549 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
4550 pr_err(MPT3SAS_FMT
"%s: failed with (ioc_status=0x%08x)\n",
4551 ioc
->name
, __func__
, ioc_status
);
4557 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
4558 pr_info(MPT3SAS_FMT
"port enable: %s\n", ioc
->name
, ((r
== 0) ?
4559 "SUCCESS" : "FAILED"));
4564 * mpt3sas_port_enable - initiate firmware discovery (don't wait for reply)
4565 * @ioc: per adapter object
4567 * Returns 0 for success, non-zero for failure.
4570 mpt3sas_port_enable(struct MPT3SAS_ADAPTER
*ioc
)
4572 Mpi2PortEnableRequest_t
*mpi_request
;
4575 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
4577 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
4578 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
4579 ioc
->name
, __func__
);
4583 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
4585 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4586 ioc
->name
, __func__
);
4590 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
4591 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4592 ioc
->port_enable_cmds
.smid
= smid
;
4593 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
4594 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
4596 mpt3sas_base_put_smid_default(ioc
, smid
);
4601 * _base_determine_wait_on_discovery - desposition
4602 * @ioc: per adapter object
4604 * Decide whether to wait on discovery to complete. Used to either
4605 * locate boot device, or report volumes ahead of physical devices.
4607 * Returns 1 for wait, 0 for don't wait
4610 _base_determine_wait_on_discovery(struct MPT3SAS_ADAPTER
*ioc
)
4612 /* We wait for discovery to complete if IR firmware is loaded.
4613 * The sas topology events arrive before PD events, so we need time to
4614 * turn on the bit in ioc->pd_handles to indicate PD
4615 * Also, it maybe required to report Volumes ahead of physical
4616 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
4618 if (ioc
->ir_firmware
)
4621 /* if no Bios, then we don't need to wait */
4622 if (!ioc
->bios_pg3
.BiosVersion
)
4625 /* Bios is present, then we drop down here.
4627 * If there any entries in the Bios Page 2, then we wait
4628 * for discovery to complete.
4631 /* Current Boot Device */
4632 if ((ioc
->bios_pg2
.CurrentBootDeviceForm
&
4633 MPI2_BIOSPAGE2_FORM_MASK
) ==
4634 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
4635 /* Request Boot Device */
4636 (ioc
->bios_pg2
.ReqBootDeviceForm
&
4637 MPI2_BIOSPAGE2_FORM_MASK
) ==
4638 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
4639 /* Alternate Request Boot Device */
4640 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
4641 MPI2_BIOSPAGE2_FORM_MASK
) ==
4642 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
)
4649 * _base_unmask_events - turn on notification for this event
4650 * @ioc: per adapter object
4651 * @event: firmware event
4653 * The mask is stored in ioc->event_masks.
4656 _base_unmask_events(struct MPT3SAS_ADAPTER
*ioc
, u16 event
)
4663 desired_event
= (1 << (event
% 32));
4666 ioc
->event_masks
[0] &= ~desired_event
;
4667 else if (event
< 64)
4668 ioc
->event_masks
[1] &= ~desired_event
;
4669 else if (event
< 96)
4670 ioc
->event_masks
[2] &= ~desired_event
;
4671 else if (event
< 128)
4672 ioc
->event_masks
[3] &= ~desired_event
;
4676 * _base_event_notification - send event notification
4677 * @ioc: per adapter object
4678 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4680 * Returns 0 for success, non-zero for failure.
4683 _base_event_notification(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4685 Mpi2EventNotificationRequest_t
*mpi_request
;
4686 unsigned long timeleft
;
4691 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4694 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
4695 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
4696 ioc
->name
, __func__
);
4700 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
4702 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4703 ioc
->name
, __func__
);
4706 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
4707 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4708 ioc
->base_cmds
.smid
= smid
;
4709 memset(mpi_request
, 0, sizeof(Mpi2EventNotificationRequest_t
));
4710 mpi_request
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4711 mpi_request
->VF_ID
= 0; /* TODO */
4712 mpi_request
->VP_ID
= 0;
4713 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4714 mpi_request
->EventMasks
[i
] =
4715 cpu_to_le32(ioc
->event_masks
[i
]);
4716 init_completion(&ioc
->base_cmds
.done
);
4717 mpt3sas_base_put_smid_default(ioc
, smid
);
4718 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
, 30*HZ
);
4719 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
4720 pr_err(MPT3SAS_FMT
"%s: timeout\n",
4721 ioc
->name
, __func__
);
4722 _debug_dump_mf(mpi_request
,
4723 sizeof(Mpi2EventNotificationRequest_t
)/4);
4724 if (ioc
->base_cmds
.status
& MPT3_CMD_RESET
)
4729 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: complete\n",
4730 ioc
->name
, __func__
));
4731 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4736 * mpt3sas_base_validate_event_type - validating event types
4737 * @ioc: per adapter object
4738 * @event: firmware event
4740 * This will turn on firmware event notification when application
4741 * ask for that event. We don't mask events that are already enabled.
4744 mpt3sas_base_validate_event_type(struct MPT3SAS_ADAPTER
*ioc
, u32
*event_type
)
4747 u32 event_mask
, desired_event
;
4748 u8 send_update_to_fw
;
4750 for (i
= 0, send_update_to_fw
= 0; i
<
4751 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++) {
4752 event_mask
= ~event_type
[i
];
4754 for (j
= 0; j
< 32; j
++) {
4755 if (!(event_mask
& desired_event
) &&
4756 (ioc
->event_masks
[i
] & desired_event
)) {
4757 ioc
->event_masks
[i
] &= ~desired_event
;
4758 send_update_to_fw
= 1;
4760 desired_event
= (desired_event
<< 1);
4764 if (!send_update_to_fw
)
4767 mutex_lock(&ioc
->base_cmds
.mutex
);
4768 _base_event_notification(ioc
, CAN_SLEEP
);
4769 mutex_unlock(&ioc
->base_cmds
.mutex
);
4773 * _base_diag_reset - the "big hammer" start of day reset
4774 * @ioc: per adapter object
4775 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4777 * Returns 0 for success, non-zero for failure.
4780 _base_diag_reset(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4782 u32 host_diagnostic
;
4787 pr_info(MPT3SAS_FMT
"sending diag reset !!\n", ioc
->name
);
4789 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"clear interrupts\n",
4794 /* Write magic sequence to WriteSequence register
4795 * Loop until in diagnostic mode
4797 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4798 "write magic sequence\n", ioc
->name
));
4799 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4800 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4801 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4802 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4803 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4804 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4805 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4808 if (sleep_flag
== CAN_SLEEP
)
4816 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
4817 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4818 "wrote magic sequence: count(%d), host_diagnostic(0x%08x)\n",
4819 ioc
->name
, count
, host_diagnostic
));
4821 } while ((host_diagnostic
& MPI2_DIAG_DIAG_WRITE_ENABLE
) == 0);
4823 hcb_size
= readl(&ioc
->chip
->HCBSize
);
4825 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"diag reset: issued\n",
4827 writel(host_diagnostic
| MPI2_DIAG_RESET_ADAPTER
,
4828 &ioc
->chip
->HostDiagnostic
);
4830 /*This delay allows the chip PCIe hardware time to finish reset tasks*/
4831 if (sleep_flag
== CAN_SLEEP
)
4832 msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
4834 mdelay(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
4836 /* Approximately 300 second max wait */
4837 for (count
= 0; count
< (300000000 /
4838 MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
); count
++) {
4840 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
4842 if (host_diagnostic
== 0xFFFFFFFF)
4844 if (!(host_diagnostic
& MPI2_DIAG_RESET_ADAPTER
))
4847 /* Wait to pass the second read delay window */
4848 if (sleep_flag
== CAN_SLEEP
)
4849 msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
4852 mdelay(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
4856 if (host_diagnostic
& MPI2_DIAG_HCB_MODE
) {
4858 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4859 "restart the adapter assuming the HCB Address points to good F/W\n",
4861 host_diagnostic
&= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK
;
4862 host_diagnostic
|= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW
;
4863 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
4865 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4866 "re-enable the HCDW\n", ioc
->name
));
4867 writel(hcb_size
| MPI2_HCB_SIZE_HCB_ENABLE
,
4868 &ioc
->chip
->HCBSize
);
4871 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"restart the adapter\n",
4873 writel(host_diagnostic
& ~MPI2_DIAG_HOLD_IOC_RESET
,
4874 &ioc
->chip
->HostDiagnostic
);
4876 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4877 "disable writes to the diagnostic register\n", ioc
->name
));
4878 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4880 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4881 "Wait for FW to go to the READY state\n", ioc
->name
));
4882 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, 20,
4886 "%s: failed going to ready state (ioc_state=0x%x)\n",
4887 ioc
->name
, __func__
, ioc_state
);
4891 pr_info(MPT3SAS_FMT
"diag reset: SUCCESS\n", ioc
->name
);
4895 pr_err(MPT3SAS_FMT
"diag reset: FAILED\n", ioc
->name
);
4900 * _base_make_ioc_ready - put controller in READY state
4901 * @ioc: per adapter object
4902 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4903 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4905 * Returns 0 for success, non-zero for failure.
4908 _base_make_ioc_ready(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
,
4909 enum reset_type type
)
4915 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4918 if (ioc
->pci_error_recovery
)
4921 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4922 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: ioc_state(0x%08x)\n",
4923 ioc
->name
, __func__
, ioc_state
));
4925 /* if in RESET state, it should move to READY state shortly */
4927 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_RESET
) {
4928 while ((ioc_state
& MPI2_IOC_STATE_MASK
) !=
4929 MPI2_IOC_STATE_READY
) {
4930 if (count
++ == 10) {
4932 "%s: failed going to ready state (ioc_state=0x%x)\n",
4933 ioc
->name
, __func__
, ioc_state
);
4936 if (sleep_flag
== CAN_SLEEP
)
4940 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4944 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
)
4947 if (ioc_state
& MPI2_DOORBELL_USED
) {
4948 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4949 "unexpected doorbell active!\n",
4951 goto issue_diag_reset
;
4954 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
4955 mpt3sas_base_fault_info(ioc
, ioc_state
&
4956 MPI2_DOORBELL_DATA_MASK
);
4957 goto issue_diag_reset
;
4960 if (type
== FORCE_BIG_HAMMER
)
4961 goto issue_diag_reset
;
4963 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
4964 if (!(_base_send_ioc_reset(ioc
,
4965 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
, 15, CAN_SLEEP
))) {
4970 rc
= _base_diag_reset(ioc
, CAN_SLEEP
);
4975 * _base_make_ioc_operational - put controller in OPERATIONAL state
4976 * @ioc: per adapter object
4977 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4979 * Returns 0 for success, non-zero for failure.
4982 _base_make_ioc_operational(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4985 unsigned long flags
;
4988 struct _tr_list
*delayed_tr
, *delayed_tr_next
;
4990 struct adapter_reply_queue
*reply_q
;
4991 Mpi2ReplyDescriptorsUnion_t
*reply_post_free_contig
;
4993 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4996 /* clean the delayed target reset list */
4997 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4998 &ioc
->delayed_tr_list
, list
) {
4999 list_del(&delayed_tr
->list
);
5004 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
5005 &ioc
->delayed_tr_volume_list
, list
) {
5006 list_del(&delayed_tr
->list
);
5010 /* initialize the scsi lookup free list */
5011 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5012 INIT_LIST_HEAD(&ioc
->free_list
);
5014 for (i
= 0; i
< ioc
->scsiio_depth
; i
++, smid
++) {
5015 INIT_LIST_HEAD(&ioc
->scsi_lookup
[i
].chain_list
);
5016 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
5017 ioc
->scsi_lookup
[i
].smid
= smid
;
5018 ioc
->scsi_lookup
[i
].scmd
= NULL
;
5019 ioc
->scsi_lookup
[i
].direct_io
= 0;
5020 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
5024 /* hi-priority queue */
5025 INIT_LIST_HEAD(&ioc
->hpr_free_list
);
5026 smid
= ioc
->hi_priority_smid
;
5027 for (i
= 0; i
< ioc
->hi_priority_depth
; i
++, smid
++) {
5028 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
5029 ioc
->hpr_lookup
[i
].smid
= smid
;
5030 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
5031 &ioc
->hpr_free_list
);
5034 /* internal queue */
5035 INIT_LIST_HEAD(&ioc
->internal_free_list
);
5036 smid
= ioc
->internal_smid
;
5037 for (i
= 0; i
< ioc
->internal_depth
; i
++, smid
++) {
5038 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
5039 ioc
->internal_lookup
[i
].smid
= smid
;
5040 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
5041 &ioc
->internal_free_list
);
5045 INIT_LIST_HEAD(&ioc
->free_chain_list
);
5046 for (i
= 0; i
< ioc
->chain_depth
; i
++)
5047 list_add_tail(&ioc
->chain_lookup
[i
].tracker_list
,
5048 &ioc
->free_chain_list
);
5050 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5052 /* initialize Reply Free Queue */
5053 for (i
= 0, reply_address
= (u32
)ioc
->reply_dma
;
5054 i
< ioc
->reply_free_queue_depth
; i
++, reply_address
+=
5056 ioc
->reply_free
[i
] = cpu_to_le32(reply_address
);
5058 /* initialize reply queues */
5059 if (ioc
->is_driver_loading
)
5060 _base_assign_reply_queues(ioc
);
5062 /* initialize Reply Post Free Queue */
5064 reply_post_free_contig
= ioc
->reply_post
[0].reply_post_free
;
5065 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
5067 * If RDPQ is enabled, switch to the next allocation.
5068 * Otherwise advance within the contiguous region.
5070 if (ioc
->rdpq_array_enable
) {
5071 reply_q
->reply_post_free
=
5072 ioc
->reply_post
[index
++].reply_post_free
;
5074 reply_q
->reply_post_free
= reply_post_free_contig
;
5075 reply_post_free_contig
+= ioc
->reply_post_queue_depth
;
5078 reply_q
->reply_post_host_index
= 0;
5079 for (i
= 0; i
< ioc
->reply_post_queue_depth
; i
++)
5080 reply_q
->reply_post_free
[i
].Words
=
5081 cpu_to_le64(ULLONG_MAX
);
5082 if (!_base_is_controller_msix_enabled(ioc
))
5083 goto skip_init_reply_post_free_queue
;
5085 skip_init_reply_post_free_queue
:
5087 r
= _base_send_ioc_init(ioc
, sleep_flag
);
5091 /* initialize reply free host index */
5092 ioc
->reply_free_host_index
= ioc
->reply_free_queue_depth
- 1;
5093 writel(ioc
->reply_free_host_index
, &ioc
->chip
->ReplyFreeHostIndex
);
5095 /* initialize reply post host index */
5096 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
5097 if (ioc
->msix96_vector
)
5098 writel((reply_q
->msix_index
& 7)<<
5099 MPI2_RPHI_MSIX_INDEX_SHIFT
,
5100 ioc
->replyPostRegisterIndex
[reply_q
->msix_index
/8]);
5102 writel(reply_q
->msix_index
<<
5103 MPI2_RPHI_MSIX_INDEX_SHIFT
,
5104 &ioc
->chip
->ReplyPostHostIndex
);
5106 if (!_base_is_controller_msix_enabled(ioc
))
5107 goto skip_init_reply_post_host_index
;
5110 skip_init_reply_post_host_index
:
5112 _base_unmask_interrupts(ioc
);
5113 r
= _base_event_notification(ioc
, sleep_flag
);
5117 if (sleep_flag
== CAN_SLEEP
)
5118 _base_static_config_pages(ioc
);
5121 if (ioc
->is_driver_loading
) {
5123 if (ioc
->is_warpdrive
&& ioc
->manu_pg10
.OEMIdentifier
5126 le32_to_cpu(ioc
->manu_pg10
.OEMSpecificFlags0
) &
5127 MFG_PAGE10_HIDE_SSDS_MASK
);
5128 if (hide_flag
!= MFG_PAGE10_HIDE_SSDS_MASK
)
5129 ioc
->mfg_pg10_hide_flag
= hide_flag
;
5132 ioc
->wait_for_discovery_to_complete
=
5133 _base_determine_wait_on_discovery(ioc
);
5135 return r
; /* scan_start and scan_finished support */
5138 r
= _base_send_port_enable(ioc
, sleep_flag
);
5146 * mpt3sas_base_free_resources - free resources controller resources
5147 * @ioc: per adapter object
5152 mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER
*ioc
)
5154 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5157 /* synchronizing freeing resource with pci_access_mutex lock */
5158 mutex_lock(&ioc
->pci_access_mutex
);
5159 if (ioc
->chip_phys
&& ioc
->chip
) {
5160 _base_mask_interrupts(ioc
);
5161 ioc
->shost_recovery
= 1;
5162 _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
5163 ioc
->shost_recovery
= 0;
5166 mpt3sas_base_unmap_resources(ioc
);
5167 mutex_unlock(&ioc
->pci_access_mutex
);
5172 * mpt3sas_base_attach - attach controller instance
5173 * @ioc: per adapter object
5175 * Returns 0 for success, non-zero for failure.
5178 mpt3sas_base_attach(struct MPT3SAS_ADAPTER
*ioc
)
5181 int cpu_id
, last_cpu_id
= 0;
5183 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5186 /* setup cpu_msix_table */
5187 ioc
->cpu_count
= num_online_cpus();
5188 for_each_online_cpu(cpu_id
)
5189 last_cpu_id
= cpu_id
;
5190 ioc
->cpu_msix_table_sz
= last_cpu_id
+ 1;
5191 ioc
->cpu_msix_table
= kzalloc(ioc
->cpu_msix_table_sz
, GFP_KERNEL
);
5192 ioc
->reply_queue_count
= 1;
5193 if (!ioc
->cpu_msix_table
) {
5194 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
5195 "allocation for cpu_msix_table failed!!!\n",
5198 goto out_free_resources
;
5201 if (ioc
->is_warpdrive
) {
5202 ioc
->reply_post_host_index
= kcalloc(ioc
->cpu_msix_table_sz
,
5203 sizeof(resource_size_t
*), GFP_KERNEL
);
5204 if (!ioc
->reply_post_host_index
) {
5205 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
"allocation "
5206 "for cpu_msix_table failed!!!\n", ioc
->name
));
5208 goto out_free_resources
;
5212 ioc
->rdpq_array_enable_assigned
= 0;
5214 r
= mpt3sas_base_map_resources(ioc
);
5216 goto out_free_resources
;
5218 pci_set_drvdata(ioc
->pdev
, ioc
->shost
);
5219 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
5221 goto out_free_resources
;
5223 switch (ioc
->hba_mpi_version_belonged
) {
5225 ioc
->build_sg_scmd
= &_base_build_sg_scmd
;
5226 ioc
->build_sg
= &_base_build_sg
;
5227 ioc
->build_zero_len_sge
= &_base_build_zero_len_sge
;
5232 * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and
5233 * Target Status - all require the IEEE formated scatter gather
5236 ioc
->build_sg_scmd
= &_base_build_sg_scmd_ieee
;
5237 ioc
->build_sg
= &_base_build_sg_ieee
;
5238 ioc
->build_zero_len_sge
= &_base_build_zero_len_sge_ieee
;
5239 ioc
->sge_size_ieee
= sizeof(Mpi2IeeeSgeSimple64_t
);
5244 * These function pointers for other requests that don't
5245 * the require IEEE scatter gather elements.
5247 * For example Configuration Pages and SAS IOUNIT Control don't.
5249 ioc
->build_sg_mpi
= &_base_build_sg
;
5250 ioc
->build_zero_len_sge_mpi
= &_base_build_zero_len_sge
;
5252 r
= _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
5254 goto out_free_resources
;
5256 ioc
->pfacts
= kcalloc(ioc
->facts
.NumberOfPorts
,
5257 sizeof(struct mpt3sas_port_facts
), GFP_KERNEL
);
5260 goto out_free_resources
;
5263 for (i
= 0 ; i
< ioc
->facts
.NumberOfPorts
; i
++) {
5264 r
= _base_get_port_facts(ioc
, i
, CAN_SLEEP
);
5266 goto out_free_resources
;
5269 r
= _base_allocate_memory_pools(ioc
, CAN_SLEEP
);
5271 goto out_free_resources
;
5273 init_waitqueue_head(&ioc
->reset_wq
);
5275 /* allocate memory pd handle bitmask list */
5276 ioc
->pd_handles_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
5277 if (ioc
->facts
.MaxDevHandle
% 8)
5278 ioc
->pd_handles_sz
++;
5279 ioc
->pd_handles
= kzalloc(ioc
->pd_handles_sz
,
5281 if (!ioc
->pd_handles
) {
5283 goto out_free_resources
;
5285 ioc
->blocking_handles
= kzalloc(ioc
->pd_handles_sz
,
5287 if (!ioc
->blocking_handles
) {
5289 goto out_free_resources
;
5292 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
5294 /* base internal command bits */
5295 mutex_init(&ioc
->base_cmds
.mutex
);
5296 ioc
->base_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
5297 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
5299 /* port_enable command bits */
5300 ioc
->port_enable_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
5301 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
5303 /* transport internal command bits */
5304 ioc
->transport_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
5305 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
5306 mutex_init(&ioc
->transport_cmds
.mutex
);
5308 /* scsih internal command bits */
5309 ioc
->scsih_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
5310 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
5311 mutex_init(&ioc
->scsih_cmds
.mutex
);
5313 /* task management internal command bits */
5314 ioc
->tm_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
5315 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
5316 mutex_init(&ioc
->tm_cmds
.mutex
);
5318 /* config page internal command bits */
5319 ioc
->config_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
5320 ioc
->config_cmds
.status
= MPT3_CMD_NOT_USED
;
5321 mutex_init(&ioc
->config_cmds
.mutex
);
5323 /* ctl module internal command bits */
5324 ioc
->ctl_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
5325 ioc
->ctl_cmds
.sense
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
5326 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
5327 mutex_init(&ioc
->ctl_cmds
.mutex
);
5329 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
5330 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
5331 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
||
5332 !ioc
->ctl_cmds
.sense
) {
5334 goto out_free_resources
;
5337 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
5338 ioc
->event_masks
[i
] = -1;
5340 /* here we enable the events we care about */
5341 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DISCOVERY
);
5342 _base_unmask_events(ioc
, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
);
5343 _base_unmask_events(ioc
, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
5344 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
5345 _base_unmask_events(ioc
, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
);
5346 _base_unmask_events(ioc
, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
);
5347 _base_unmask_events(ioc
, MPI2_EVENT_IR_VOLUME
);
5348 _base_unmask_events(ioc
, MPI2_EVENT_IR_PHYSICAL_DISK
);
5349 _base_unmask_events(ioc
, MPI2_EVENT_IR_OPERATION_STATUS
);
5350 _base_unmask_events(ioc
, MPI2_EVENT_LOG_ENTRY_ADDED
);
5351 _base_unmask_events(ioc
, MPI2_EVENT_TEMP_THRESHOLD
);
5353 r
= _base_make_ioc_operational(ioc
, CAN_SLEEP
);
5355 goto out_free_resources
;
5357 ioc
->non_operational_loop
= 0;
5362 ioc
->remove_host
= 1;
5364 mpt3sas_base_free_resources(ioc
);
5365 _base_release_memory_pools(ioc
);
5366 pci_set_drvdata(ioc
->pdev
, NULL
);
5367 kfree(ioc
->cpu_msix_table
);
5368 if (ioc
->is_warpdrive
)
5369 kfree(ioc
->reply_post_host_index
);
5370 kfree(ioc
->pd_handles
);
5371 kfree(ioc
->blocking_handles
);
5372 kfree(ioc
->tm_cmds
.reply
);
5373 kfree(ioc
->transport_cmds
.reply
);
5374 kfree(ioc
->scsih_cmds
.reply
);
5375 kfree(ioc
->config_cmds
.reply
);
5376 kfree(ioc
->base_cmds
.reply
);
5377 kfree(ioc
->port_enable_cmds
.reply
);
5378 kfree(ioc
->ctl_cmds
.reply
);
5379 kfree(ioc
->ctl_cmds
.sense
);
5381 ioc
->ctl_cmds
.reply
= NULL
;
5382 ioc
->base_cmds
.reply
= NULL
;
5383 ioc
->tm_cmds
.reply
= NULL
;
5384 ioc
->scsih_cmds
.reply
= NULL
;
5385 ioc
->transport_cmds
.reply
= NULL
;
5386 ioc
->config_cmds
.reply
= NULL
;
5393 * mpt3sas_base_detach - remove controller instance
5394 * @ioc: per adapter object
5399 mpt3sas_base_detach(struct MPT3SAS_ADAPTER
*ioc
)
5401 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5404 mpt3sas_base_stop_watchdog(ioc
);
5405 mpt3sas_base_free_resources(ioc
);
5406 _base_release_memory_pools(ioc
);
5407 pci_set_drvdata(ioc
->pdev
, NULL
);
5408 kfree(ioc
->cpu_msix_table
);
5409 if (ioc
->is_warpdrive
)
5410 kfree(ioc
->reply_post_host_index
);
5411 kfree(ioc
->pd_handles
);
5412 kfree(ioc
->blocking_handles
);
5414 kfree(ioc
->ctl_cmds
.reply
);
5415 kfree(ioc
->ctl_cmds
.sense
);
5416 kfree(ioc
->base_cmds
.reply
);
5417 kfree(ioc
->port_enable_cmds
.reply
);
5418 kfree(ioc
->tm_cmds
.reply
);
5419 kfree(ioc
->transport_cmds
.reply
);
5420 kfree(ioc
->scsih_cmds
.reply
);
5421 kfree(ioc
->config_cmds
.reply
);
5425 * _base_reset_handler - reset callback handler (for base)
5426 * @ioc: per adapter object
5427 * @reset_phase: phase
5429 * The handler for doing any required cleanup or initialization.
5431 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
5432 * MPT3_IOC_DONE_RESET
5437 _base_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
5439 mpt3sas_scsih_reset_handler(ioc
, reset_phase
);
5440 mpt3sas_ctl_reset_handler(ioc
, reset_phase
);
5441 switch (reset_phase
) {
5442 case MPT3_IOC_PRE_RESET
:
5443 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
5444 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
5446 case MPT3_IOC_AFTER_RESET
:
5447 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
5448 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
5449 if (ioc
->transport_cmds
.status
& MPT3_CMD_PENDING
) {
5450 ioc
->transport_cmds
.status
|= MPT3_CMD_RESET
;
5451 mpt3sas_base_free_smid(ioc
, ioc
->transport_cmds
.smid
);
5452 complete(&ioc
->transport_cmds
.done
);
5454 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
5455 ioc
->base_cmds
.status
|= MPT3_CMD_RESET
;
5456 mpt3sas_base_free_smid(ioc
, ioc
->base_cmds
.smid
);
5457 complete(&ioc
->base_cmds
.done
);
5459 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
5460 ioc
->port_enable_failed
= 1;
5461 ioc
->port_enable_cmds
.status
|= MPT3_CMD_RESET
;
5462 mpt3sas_base_free_smid(ioc
, ioc
->port_enable_cmds
.smid
);
5463 if (ioc
->is_driver_loading
) {
5464 ioc
->start_scan_failed
=
5465 MPI2_IOCSTATUS_INTERNAL_ERROR
;
5466 ioc
->start_scan
= 0;
5467 ioc
->port_enable_cmds
.status
=
5470 complete(&ioc
->port_enable_cmds
.done
);
5472 if (ioc
->config_cmds
.status
& MPT3_CMD_PENDING
) {
5473 ioc
->config_cmds
.status
|= MPT3_CMD_RESET
;
5474 mpt3sas_base_free_smid(ioc
, ioc
->config_cmds
.smid
);
5475 ioc
->config_cmds
.smid
= USHRT_MAX
;
5476 complete(&ioc
->config_cmds
.done
);
5479 case MPT3_IOC_DONE_RESET
:
5480 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
5481 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
5487 * _wait_for_commands_to_complete - reset controller
5488 * @ioc: Pointer to MPT_ADAPTER structure
5489 * @sleep_flag: CAN_SLEEP or NO_SLEEP
5491 * This function waiting(3s) for all pending commands to complete
5492 * prior to putting controller in reset.
5495 _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
5498 unsigned long flags
;
5501 ioc
->pending_io_count
= 0;
5502 if (sleep_flag
!= CAN_SLEEP
)
5505 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
5506 if ((ioc_state
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
)
5509 /* pending command count */
5510 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5511 for (i
= 0; i
< ioc
->scsiio_depth
; i
++)
5512 if (ioc
->scsi_lookup
[i
].cb_idx
!= 0xFF)
5513 ioc
->pending_io_count
++;
5514 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5516 if (!ioc
->pending_io_count
)
5519 /* wait for pending commands to complete */
5520 wait_event_timeout(ioc
->reset_wq
, ioc
->pending_io_count
== 0, 10 * HZ
);
5524 * mpt3sas_base_hard_reset_handler - reset controller
5525 * @ioc: Pointer to MPT_ADAPTER structure
5526 * @sleep_flag: CAN_SLEEP or NO_SLEEP
5527 * @type: FORCE_BIG_HAMMER or SOFT_RESET
5529 * Returns 0 for success, non-zero for failure.
5532 mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
,
5533 enum reset_type type
)
5536 unsigned long flags
;
5538 u8 is_fault
= 0, is_trigger
= 0;
5540 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
5543 if (ioc
->pci_error_recovery
) {
5544 pr_err(MPT3SAS_FMT
"%s: pci error recovery reset\n",
5545 ioc
->name
, __func__
);
5550 if (mpt3sas_fwfault_debug
)
5551 mpt3sas_halt_firmware(ioc
);
5553 /* TODO - What we really should be doing is pulling
5554 * out all the code associated with NO_SLEEP; its never used.
5555 * That is legacy code from mpt fusion driver, ported over.
5556 * I will leave this BUG_ON here for now till its been resolved.
5558 BUG_ON(sleep_flag
== NO_SLEEP
);
5560 /* wait for an active reset in progress to complete */
5561 if (!mutex_trylock(&ioc
->reset_in_progress_mutex
)) {
5564 } while (ioc
->shost_recovery
== 1);
5565 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,
5567 return ioc
->ioc_reset_in_progress_status
;
5570 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5571 ioc
->shost_recovery
= 1;
5572 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
5574 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
5575 MPT3_DIAG_BUFFER_IS_REGISTERED
) &&
5576 (!(ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
5577 MPT3_DIAG_BUFFER_IS_RELEASED
))) {
5579 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
5580 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
5583 _base_reset_handler(ioc
, MPT3_IOC_PRE_RESET
);
5584 _wait_for_commands_to_complete(ioc
, sleep_flag
);
5585 _base_mask_interrupts(ioc
);
5586 r
= _base_make_ioc_ready(ioc
, sleep_flag
, type
);
5589 _base_reset_handler(ioc
, MPT3_IOC_AFTER_RESET
);
5591 /* If this hard reset is called while port enable is active, then
5592 * there is no reason to call make_ioc_operational
5594 if (ioc
->is_driver_loading
&& ioc
->port_enable_failed
) {
5595 ioc
->remove_host
= 1;
5599 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
5603 if (ioc
->rdpq_array_enable
&& !ioc
->rdpq_array_capable
)
5604 panic("%s: Issue occurred with flashing controller firmware."
5605 "Please reboot the system and ensure that the correct"
5606 " firmware version is running\n", ioc
->name
);
5608 r
= _base_make_ioc_operational(ioc
, sleep_flag
);
5610 _base_reset_handler(ioc
, MPT3_IOC_DONE_RESET
);
5613 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %s\n",
5614 ioc
->name
, __func__
, ((r
== 0) ? "SUCCESS" : "FAILED")));
5616 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
5617 ioc
->ioc_reset_in_progress_status
= r
;
5618 ioc
->shost_recovery
= 0;
5619 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
5620 ioc
->ioc_reset_count
++;
5621 mutex_unlock(&ioc
->reset_in_progress_mutex
);
5624 if ((r
== 0) && is_trigger
) {
5626 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_FW_FAULT
);
5628 mpt3sas_trigger_master(ioc
,
5629 MASTER_TRIGGER_ADAPTER_RESET
);
5631 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,