2 * This is the Fusion MPT base driver providing common API layer interface
3 * for access to MPT (Message Passing Technology) firmware.
5 * This code is based on drivers/scsi/mpt2sas/mpt2_base.c
6 * Copyright (C) 2007-2010 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h>
54 #include <linux/delay.h>
55 #include <linux/interrupt.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/sort.h>
59 #include <linux/time.h>
60 #include <linux/aer.h>
62 #include "mpt2sas_base.h"
64 static MPT_CALLBACK mpt_callbacks
[MPT_MAX_CALLBACKS
];
66 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
68 static int max_queue_depth
= -1;
69 module_param(max_queue_depth
, int, 0);
70 MODULE_PARM_DESC(max_queue_depth
, " max controller queue depth ");
72 static int max_sgl_entries
= -1;
73 module_param(max_sgl_entries
, int, 0);
74 MODULE_PARM_DESC(max_sgl_entries
, " max sg entries ");
76 static int msix_disable
= -1;
77 module_param(msix_disable
, int, 0);
78 MODULE_PARM_DESC(msix_disable
, " disable msix routed interrupts (default=0)");
80 static int missing_delay
[2] = {-1, -1};
81 module_param_array(missing_delay
, int, NULL
, 0);
82 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
84 /* diag_buffer_enable is bitwise
86 * bit 1 set = SNAPSHOT
87 * bit 2 set = EXTENDED
89 * Either bit can be set, or both
91 static int diag_buffer_enable
;
92 module_param(diag_buffer_enable
, int, 0);
93 MODULE_PARM_DESC(diag_buffer_enable
, " post diag buffers "
94 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
96 static int mpt2sas_fwfault_debug
;
97 MODULE_PARM_DESC(mpt2sas_fwfault_debug
, " enable detection of firmware fault "
98 "and halt firmware - (default=0)");
100 static int disable_discovery
= -1;
101 module_param(disable_discovery
, int, 0);
102 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
105 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
109 _scsih_set_fwfault_debug(const char *val
, struct kernel_param
*kp
)
111 int ret
= param_set_int(val
, kp
);
112 struct MPT2SAS_ADAPTER
*ioc
;
117 printk(KERN_INFO
"setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug
);
118 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
119 ioc
->fwfault_debug
= mpt2sas_fwfault_debug
;
122 module_param_call(mpt2sas_fwfault_debug
, _scsih_set_fwfault_debug
,
123 param_get_int
, &mpt2sas_fwfault_debug
, 0644);
126 * _base_fault_reset_work - workq handling ioc fault conditions
127 * @work: input argument, used to derive ioc
133 _base_fault_reset_work(struct work_struct
*work
)
135 struct MPT2SAS_ADAPTER
*ioc
=
136 container_of(work
, struct MPT2SAS_ADAPTER
, fault_reset_work
.work
);
141 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
142 if (ioc
->shost_recovery
)
144 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
146 doorbell
= mpt2sas_base_get_iocstate(ioc
, 0);
147 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
148 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
150 printk(MPT2SAS_WARN_FMT
"%s: hard reset: %s\n", ioc
->name
,
151 __func__
, (rc
== 0) ? "success" : "failed");
152 doorbell
= mpt2sas_base_get_iocstate(ioc
, 0);
153 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
154 mpt2sas_base_fault_info(ioc
, doorbell
&
155 MPI2_DOORBELL_DATA_MASK
);
158 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
160 if (ioc
->fault_reset_work_q
)
161 queue_delayed_work(ioc
->fault_reset_work_q
,
162 &ioc
->fault_reset_work
,
163 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
164 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
168 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
169 * @ioc: per adapter object
175 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER
*ioc
)
179 if (ioc
->fault_reset_work_q
)
182 /* initialize fault polling */
183 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, _base_fault_reset_work
);
184 snprintf(ioc
->fault_reset_work_q_name
,
185 sizeof(ioc
->fault_reset_work_q_name
), "poll_%d_status", ioc
->id
);
186 ioc
->fault_reset_work_q
=
187 create_singlethread_workqueue(ioc
->fault_reset_work_q_name
);
188 if (!ioc
->fault_reset_work_q
) {
189 printk(MPT2SAS_ERR_FMT
"%s: failed (line=%d)\n",
190 ioc
->name
, __func__
, __LINE__
);
193 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
194 if (ioc
->fault_reset_work_q
)
195 queue_delayed_work(ioc
->fault_reset_work_q
,
196 &ioc
->fault_reset_work
,
197 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
198 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
202 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
203 * @ioc: per adapter object
209 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER
*ioc
)
212 struct workqueue_struct
*wq
;
214 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
215 wq
= ioc
->fault_reset_work_q
;
216 ioc
->fault_reset_work_q
= NULL
;
217 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
219 if (!cancel_delayed_work(&ioc
->fault_reset_work
))
221 destroy_workqueue(wq
);
226 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
227 * @ioc: per adapter object
228 * @fault_code: fault code
233 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER
*ioc
, u16 fault_code
)
235 printk(MPT2SAS_ERR_FMT
"fault_state(0x%04x)!\n",
236 ioc
->name
, fault_code
);
240 * mpt2sas_halt_firmware - halt's mpt controller firmware
241 * @ioc: per adapter object
243 * For debugging timeout related issues. Writing 0xCOFFEE00
244 * to the doorbell register will halt controller firmware. With
245 * the purpose to stop both driver and firmware, the enduser can
246 * obtain a ring buffer from controller UART.
249 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER
*ioc
)
253 if (!ioc
->fwfault_debug
)
258 doorbell
= readl(&ioc
->chip
->Doorbell
);
259 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
260 mpt2sas_base_fault_info(ioc
, doorbell
);
262 writel(0xC0FFEE00, &ioc
->chip
->Doorbell
);
263 printk(MPT2SAS_ERR_FMT
"Firmware is halted due to command "
264 "timeout\n", ioc
->name
);
267 panic("panic in %s\n", __func__
);
270 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
272 * _base_sas_ioc_info - verbose translation of the ioc status
273 * @ioc: per adapter object
274 * @mpi_reply: reply mf payload returned from firmware
275 * @request_hdr: request mf
280 _base_sas_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, MPI2DefaultReply_t
*mpi_reply
,
281 MPI2RequestHeader_t
*request_hdr
)
283 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
287 char *func_str
= NULL
;
289 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
290 if (request_hdr
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
291 request_hdr
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
292 request_hdr
->Function
== MPI2_FUNCTION_EVENT_NOTIFICATION
)
295 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
298 switch (ioc_status
) {
300 /****************************************************************************
301 * Common IOCStatus values for all replies
302 ****************************************************************************/
304 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
305 desc
= "invalid function";
307 case MPI2_IOCSTATUS_BUSY
:
310 case MPI2_IOCSTATUS_INVALID_SGL
:
311 desc
= "invalid sgl";
313 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
314 desc
= "internal error";
316 case MPI2_IOCSTATUS_INVALID_VPID
:
317 desc
= "invalid vpid";
319 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
320 desc
= "insufficient resources";
322 case MPI2_IOCSTATUS_INVALID_FIELD
:
323 desc
= "invalid field";
325 case MPI2_IOCSTATUS_INVALID_STATE
:
326 desc
= "invalid state";
328 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED
:
329 desc
= "op state not supported";
332 /****************************************************************************
333 * Config IOCStatus values
334 ****************************************************************************/
336 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION
:
337 desc
= "config invalid action";
339 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE
:
340 desc
= "config invalid type";
342 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
:
343 desc
= "config invalid page";
345 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA
:
346 desc
= "config invalid data";
348 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS
:
349 desc
= "config no defaults";
351 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT
:
352 desc
= "config cant commit";
355 /****************************************************************************
357 ****************************************************************************/
359 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
360 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
361 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
362 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
363 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
364 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
365 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
366 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
367 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
368 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
369 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
370 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
373 /****************************************************************************
374 * For use by SCSI Initiator and SCSI Target end-to-end data protection
375 ****************************************************************************/
377 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
378 desc
= "eedp guard error";
380 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
381 desc
= "eedp ref tag error";
383 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
384 desc
= "eedp app tag error";
387 /****************************************************************************
389 ****************************************************************************/
391 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX
:
392 desc
= "target invalid io index";
394 case MPI2_IOCSTATUS_TARGET_ABORTED
:
395 desc
= "target aborted";
397 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
:
398 desc
= "target no conn retryable";
400 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION
:
401 desc
= "target no connection";
403 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
:
404 desc
= "target xfer count mismatch";
406 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
:
407 desc
= "target data offset error";
409 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
:
410 desc
= "target too much write data";
412 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT
:
413 desc
= "target iu too short";
415 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
:
416 desc
= "target ack nak timeout";
418 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED
:
419 desc
= "target nak received";
422 /****************************************************************************
423 * Serial Attached SCSI values
424 ****************************************************************************/
426 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED
:
427 desc
= "smp request failed";
429 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN
:
430 desc
= "smp data overrun";
433 /****************************************************************************
434 * Diagnostic Buffer Post / Diagnostic Release values
435 ****************************************************************************/
437 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
:
438 desc
= "diagnostic released";
447 switch (request_hdr
->Function
) {
448 case MPI2_FUNCTION_CONFIG
:
449 frame_sz
= sizeof(Mpi2ConfigRequest_t
) + ioc
->sge_size
;
450 func_str
= "config_page";
452 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
453 frame_sz
= sizeof(Mpi2SCSITaskManagementRequest_t
);
454 func_str
= "task_mgmt";
456 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
457 frame_sz
= sizeof(Mpi2SasIoUnitControlRequest_t
);
458 func_str
= "sas_iounit_ctl";
460 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
461 frame_sz
= sizeof(Mpi2SepRequest_t
);
462 func_str
= "enclosure";
464 case MPI2_FUNCTION_IOC_INIT
:
465 frame_sz
= sizeof(Mpi2IOCInitRequest_t
);
466 func_str
= "ioc_init";
468 case MPI2_FUNCTION_PORT_ENABLE
:
469 frame_sz
= sizeof(Mpi2PortEnableRequest_t
);
470 func_str
= "port_enable";
472 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
473 frame_sz
= sizeof(Mpi2SmpPassthroughRequest_t
) + ioc
->sge_size
;
474 func_str
= "smp_passthru";
478 func_str
= "unknown";
482 printk(MPT2SAS_WARN_FMT
"ioc_status: %s(0x%04x), request(0x%p),"
483 " (%s)\n", ioc
->name
, desc
, ioc_status
, request_hdr
, func_str
);
485 _debug_dump_mf(request_hdr
, frame_sz
/4);
489 * _base_display_event_data - verbose translation of firmware asyn events
490 * @ioc: per adapter object
491 * @mpi_reply: reply mf payload returned from firmware
496 _base_display_event_data(struct MPT2SAS_ADAPTER
*ioc
,
497 Mpi2EventNotificationReply_t
*mpi_reply
)
502 if (!(ioc
->logging_level
& MPT_DEBUG_EVENTS
))
505 event
= le16_to_cpu(mpi_reply
->Event
);
508 case MPI2_EVENT_LOG_DATA
:
511 case MPI2_EVENT_STATE_CHANGE
:
512 desc
= "Status Change";
514 case MPI2_EVENT_HARD_RESET_RECEIVED
:
515 desc
= "Hard Reset Received";
517 case MPI2_EVENT_EVENT_CHANGE
:
518 desc
= "Event Change";
520 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
521 desc
= "Device Status Change";
523 case MPI2_EVENT_IR_OPERATION_STATUS
:
524 if (!ioc
->hide_ir_msg
)
525 desc
= "IR Operation Status";
527 case MPI2_EVENT_SAS_DISCOVERY
:
529 Mpi2EventDataSasDiscovery_t
*event_data
=
530 (Mpi2EventDataSasDiscovery_t
*)mpi_reply
->EventData
;
531 printk(MPT2SAS_INFO_FMT
"Discovery: (%s)", ioc
->name
,
532 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
534 if (event_data
->DiscoveryStatus
)
535 printk("discovery_status(0x%08x)",
536 le32_to_cpu(event_data
->DiscoveryStatus
));
540 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
541 desc
= "SAS Broadcast Primitive";
543 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
544 desc
= "SAS Init Device Status Change";
546 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW
:
547 desc
= "SAS Init Table Overflow";
549 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
550 desc
= "SAS Topology Change List";
552 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
553 desc
= "SAS Enclosure Device Status Change";
555 case MPI2_EVENT_IR_VOLUME
:
556 if (!ioc
->hide_ir_msg
)
559 case MPI2_EVENT_IR_PHYSICAL_DISK
:
560 if (!ioc
->hide_ir_msg
)
561 desc
= "IR Physical Disk";
563 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
564 if (!ioc
->hide_ir_msg
)
565 desc
= "IR Configuration Change List";
567 case MPI2_EVENT_LOG_ENTRY_ADDED
:
568 if (!ioc
->hide_ir_msg
)
569 desc
= "Log Entry Added";
576 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, desc
);
581 * _base_sas_log_info - verbose translation of firmware log info
582 * @ioc: per adapter object
583 * @log_info: log info
588 _base_sas_log_info(struct MPT2SAS_ADAPTER
*ioc
, u32 log_info
)
599 union loginfo_type sas_loginfo
;
600 char *originator_str
= NULL
;
602 sas_loginfo
.loginfo
= log_info
;
603 if (sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/)
606 /* each nexus loss loginfo */
607 if (log_info
== 0x31170000)
610 /* eat the loginfos associated with task aborts */
611 if (ioc
->ignore_loginfos
&& (log_info
== 30050000 || log_info
==
612 0x31140000 || log_info
== 0x31130000))
615 switch (sas_loginfo
.dw
.originator
) {
617 originator_str
= "IOP";
620 originator_str
= "PL";
623 if (!ioc
->hide_ir_msg
)
624 originator_str
= "IR";
626 originator_str
= "WarpDrive";
630 printk(MPT2SAS_WARN_FMT
"log_info(0x%08x): originator(%s), "
631 "code(0x%02x), sub_code(0x%04x)\n", ioc
->name
, log_info
,
632 originator_str
, sas_loginfo
.dw
.code
,
633 sas_loginfo
.dw
.subcode
);
637 * _base_display_reply_info -
638 * @ioc: per adapter object
639 * @smid: system request message index
640 * @msix_index: MSIX table index supplied by the OS
641 * @reply: reply message frame(lower 32bit addr)
646 _base_display_reply_info(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
649 MPI2DefaultReply_t
*mpi_reply
;
652 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
653 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
654 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
655 if ((ioc_status
& MPI2_IOCSTATUS_MASK
) &&
656 (ioc
->logging_level
& MPT_DEBUG_REPLY
)) {
657 _base_sas_ioc_info(ioc
, mpi_reply
,
658 mpt2sas_base_get_msg_frame(ioc
, smid
));
661 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
662 _base_sas_log_info(ioc
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
666 * mpt2sas_base_done - base internal command completion routine
667 * @ioc: per adapter object
668 * @smid: system request message index
669 * @msix_index: MSIX table index supplied by the OS
670 * @reply: reply message frame(lower 32bit addr)
672 * Return 1 meaning mf should be freed from _base_interrupt
673 * 0 means the mf is freed from this function.
676 mpt2sas_base_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
679 MPI2DefaultReply_t
*mpi_reply
;
681 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
682 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
685 if (ioc
->base_cmds
.status
== MPT2_CMD_NOT_USED
)
688 ioc
->base_cmds
.status
|= MPT2_CMD_COMPLETE
;
690 ioc
->base_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
691 memcpy(ioc
->base_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
693 ioc
->base_cmds
.status
&= ~MPT2_CMD_PENDING
;
694 complete(&ioc
->base_cmds
.done
);
699 * _base_async_event - main callback handler for firmware asyn events
700 * @ioc: per adapter object
701 * @msix_index: MSIX table index supplied by the OS
702 * @reply: reply message frame(lower 32bit addr)
704 * Return 1 meaning mf should be freed from _base_interrupt
705 * 0 means the mf is freed from this function.
708 _base_async_event(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
, u32 reply
)
710 Mpi2EventNotificationReply_t
*mpi_reply
;
711 Mpi2EventAckRequest_t
*ack_request
;
714 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
717 if (mpi_reply
->Function
!= MPI2_FUNCTION_EVENT_NOTIFICATION
)
719 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
720 _base_display_event_data(ioc
, mpi_reply
);
722 if (!(mpi_reply
->AckRequired
& MPI2_EVENT_NOTIFICATION_ACK_REQUIRED
))
724 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
726 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
727 ioc
->name
, __func__
);
731 ack_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
732 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
733 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
734 ack_request
->Event
= mpi_reply
->Event
;
735 ack_request
->EventContext
= mpi_reply
->EventContext
;
736 ack_request
->VF_ID
= 0; /* TODO */
737 ack_request
->VP_ID
= 0;
738 mpt2sas_base_put_smid_default(ioc
, smid
);
742 /* scsih callback handler */
743 mpt2sas_scsih_event_callback(ioc
, msix_index
, reply
);
745 /* ctl callback handler */
746 mpt2sas_ctl_event_callback(ioc
, msix_index
, reply
);
752 * _base_get_cb_idx - obtain the callback index
753 * @ioc: per adapter object
754 * @smid: system request message index
756 * Return callback index.
759 _base_get_cb_idx(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
764 if (smid
< ioc
->hi_priority_smid
) {
766 cb_idx
= ioc
->scsi_lookup
[i
].cb_idx
;
767 } else if (smid
< ioc
->internal_smid
) {
768 i
= smid
- ioc
->hi_priority_smid
;
769 cb_idx
= ioc
->hpr_lookup
[i
].cb_idx
;
770 } else if (smid
<= ioc
->hba_queue_depth
) {
771 i
= smid
- ioc
->internal_smid
;
772 cb_idx
= ioc
->internal_lookup
[i
].cb_idx
;
779 * _base_mask_interrupts - disable interrupts
780 * @ioc: per adapter object
782 * Disabling ResetIRQ, Reply and Doorbell Interrupts
787 _base_mask_interrupts(struct MPT2SAS_ADAPTER
*ioc
)
791 ioc
->mask_interrupts
= 1;
792 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
793 him_register
|= MPI2_HIM_DIM
+ MPI2_HIM_RIM
+ MPI2_HIM_RESET_IRQ_MASK
;
794 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
795 readl(&ioc
->chip
->HostInterruptMask
);
799 * _base_unmask_interrupts - enable interrupts
800 * @ioc: per adapter object
802 * Enabling only Reply Interrupts
807 _base_unmask_interrupts(struct MPT2SAS_ADAPTER
*ioc
)
811 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
812 him_register
&= ~MPI2_HIM_RIM
;
813 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
814 ioc
->mask_interrupts
= 0;
817 union reply_descriptor
{
826 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
827 * @irq: irq number (not used)
828 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
829 * @r: pt_regs pointer (not used)
831 * Return IRQ_HANDLE if processed, else IRQ_NONE.
834 _base_interrupt(int irq
, void *bus_id
)
836 struct adapter_reply_queue
*reply_q
= bus_id
;
837 union reply_descriptor rd
;
839 u8 request_desript_type
;
843 u8 msix_index
= reply_q
->msix_index
;
844 struct MPT2SAS_ADAPTER
*ioc
= reply_q
->ioc
;
845 Mpi2ReplyDescriptorsUnion_t
*rpf
;
848 if (ioc
->mask_interrupts
)
851 if (!atomic_add_unless(&reply_q
->busy
, 1, 1))
854 rpf
= &reply_q
->reply_post_free
[reply_q
->reply_post_host_index
];
855 request_desript_type
= rpf
->Default
.ReplyFlags
856 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
857 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
) {
858 atomic_dec(&reply_q
->busy
);
865 rd
.word
= le64_to_cpu(rpf
->Words
);
866 if (rd
.u
.low
== UINT_MAX
|| rd
.u
.high
== UINT_MAX
)
869 smid
= le16_to_cpu(rpf
->Default
.DescriptorTypeDependent1
);
870 if (request_desript_type
==
871 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY
) {
873 (rpf
->AddressReply
.ReplyFrameAddress
);
874 if (reply
> ioc
->reply_dma_max_address
||
875 reply
< ioc
->reply_dma_min_address
)
877 } else if (request_desript_type
==
878 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER
)
880 else if (request_desript_type
==
881 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS
)
884 cb_idx
= _base_get_cb_idx(ioc
, smid
);
885 if (smid
&& cb_idx
!= 0xFF) {
886 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
, msix_index
,
889 _base_display_reply_info(ioc
, smid
, msix_index
,
892 mpt2sas_base_free_smid(ioc
, smid
);
895 _base_async_event(ioc
, msix_index
, reply
);
897 /* reply free queue handling */
899 ioc
->reply_free_host_index
=
900 (ioc
->reply_free_host_index
==
901 (ioc
->reply_free_queue_depth
- 1)) ?
902 0 : ioc
->reply_free_host_index
+ 1;
903 ioc
->reply_free
[ioc
->reply_free_host_index
] =
906 writel(ioc
->reply_free_host_index
,
907 &ioc
->chip
->ReplyFreeHostIndex
);
912 rpf
->Words
= cpu_to_le64(ULLONG_MAX
);
913 reply_q
->reply_post_host_index
=
914 (reply_q
->reply_post_host_index
==
915 (ioc
->reply_post_queue_depth
- 1)) ? 0 :
916 reply_q
->reply_post_host_index
+ 1;
917 request_desript_type
=
918 reply_q
->reply_post_free
[reply_q
->reply_post_host_index
].
919 Default
.ReplyFlags
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
921 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
923 if (!reply_q
->reply_post_host_index
)
924 rpf
= reply_q
->reply_post_free
;
931 if (!completed_cmds
) {
932 atomic_dec(&reply_q
->busy
);
936 if (ioc
->is_warpdrive
) {
937 writel(reply_q
->reply_post_host_index
,
938 ioc
->reply_post_host_index
[msix_index
]);
939 atomic_dec(&reply_q
->busy
);
942 writel(reply_q
->reply_post_host_index
| (msix_index
<<
943 MPI2_RPHI_MSIX_INDEX_SHIFT
), &ioc
->chip
->ReplyPostHostIndex
);
944 atomic_dec(&reply_q
->busy
);
949 * _base_is_controller_msix_enabled - is controller support muli-reply queues
950 * @ioc: per adapter object
954 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER
*ioc
)
956 return (ioc
->facts
.IOCCapabilities
&
957 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
;
961 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
962 * @ioc: per adapter object
963 * Context: ISR conext
965 * Called when a Task Management request has completed. We want
966 * to flush the other reply queues so all the outstanding IO has been
967 * completed back to OS before we process the TM completetion.
972 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER
*ioc
)
974 struct adapter_reply_queue
*reply_q
;
976 /* If MSIX capability is turned off
977 * then multi-queues are not enabled
979 if (!_base_is_controller_msix_enabled(ioc
))
982 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
983 if (ioc
->shost_recovery
)
985 /* TMs are on msix_index == 0 */
986 if (reply_q
->msix_index
== 0)
988 _base_interrupt(reply_q
->vector
, (void *)reply_q
);
993 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
994 * @cb_idx: callback index
999 mpt2sas_base_release_callback_handler(u8 cb_idx
)
1001 mpt_callbacks
[cb_idx
] = NULL
;
1005 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1006 * @cb_func: callback function
1011 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func
)
1015 for (cb_idx
= MPT_MAX_CALLBACKS
-1; cb_idx
; cb_idx
--)
1016 if (mpt_callbacks
[cb_idx
] == NULL
)
1019 mpt_callbacks
[cb_idx
] = cb_func
;
1024 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1029 mpt2sas_base_initialize_callback_handler(void)
1033 for (cb_idx
= 0; cb_idx
< MPT_MAX_CALLBACKS
; cb_idx
++)
1034 mpt2sas_base_release_callback_handler(cb_idx
);
1038 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1039 * @ioc: per adapter object
1040 * @paddr: virtual address for SGE
1042 * Create a zero length scatter gather entry to insure the IOCs hardware has
1043 * something to use if the target device goes brain dead and tries
1044 * to send data even when none is asked for.
1049 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER
*ioc
, void *paddr
)
1051 u32 flags_length
= (u32
)((MPI2_SGE_FLAGS_LAST_ELEMENT
|
1052 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
|
1053 MPI2_SGE_FLAGS_SIMPLE_ELEMENT
) <<
1054 MPI2_SGE_FLAGS_SHIFT
);
1055 ioc
->base_add_sg_single(paddr
, flags_length
, -1);
1059 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1060 * @paddr: virtual address for SGE
1061 * @flags_length: SGE flags and data transfer length
1062 * @dma_addr: Physical address
1067 _base_add_sg_single_32(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1069 Mpi2SGESimple32_t
*sgel
= paddr
;
1071 flags_length
|= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING
|
1072 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1073 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1074 sgel
->Address
= cpu_to_le32(dma_addr
);
1079 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1080 * @paddr: virtual address for SGE
1081 * @flags_length: SGE flags and data transfer length
1082 * @dma_addr: Physical address
1087 _base_add_sg_single_64(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1089 Mpi2SGESimple64_t
*sgel
= paddr
;
1091 flags_length
|= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING
|
1092 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1093 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1094 sgel
->Address
= cpu_to_le64(dma_addr
);
1097 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1100 * _base_config_dma_addressing - set dma addressing
1101 * @ioc: per adapter object
1102 * @pdev: PCI device struct
1104 * Returns 0 for success, non-zero for failure.
1107 _base_config_dma_addressing(struct MPT2SAS_ADAPTER
*ioc
, struct pci_dev
*pdev
)
1112 if (sizeof(dma_addr_t
) > 4) {
1113 const uint64_t required_mask
=
1114 dma_get_required_mask(&pdev
->dev
);
1115 if ((required_mask
> DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev
,
1116 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev
,
1117 DMA_BIT_MASK(64))) {
1118 ioc
->base_add_sg_single
= &_base_add_sg_single_64
;
1119 ioc
->sge_size
= sizeof(Mpi2SGESimple64_t
);
1125 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1126 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1127 ioc
->base_add_sg_single
= &_base_add_sg_single_32
;
1128 ioc
->sge_size
= sizeof(Mpi2SGESimple32_t
);
1135 printk(MPT2SAS_INFO_FMT
"%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1136 "total mem (%ld kB)\n", ioc
->name
, desc
, convert_to_kb(s
.totalram
));
1142 * _base_check_enable_msix - checks MSIX capabable.
1143 * @ioc: per adapter object
1145 * Check to see if card is capable of MSIX, and set number
1146 * of available msix vectors
1149 _base_check_enable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1152 u16 message_control
;
1155 base
= pci_find_capability(ioc
->pdev
, PCI_CAP_ID_MSIX
);
1157 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"msix not "
1158 "supported\n", ioc
->name
));
1162 /* get msix vector count */
1163 /* NUMA_IO not supported for older controllers */
1164 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2004
||
1165 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
||
1166 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_1
||
1167 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_2
||
1168 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_3
||
1169 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_1
||
1170 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_2
)
1171 ioc
->msix_vector_count
= 1;
1173 pci_read_config_word(ioc
->pdev
, base
+ 2, &message_control
);
1174 ioc
->msix_vector_count
= (message_control
& 0x3FF) + 1;
1176 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"msix is supported, "
1177 "vector_count(%d)\n", ioc
->name
, ioc
->msix_vector_count
));
1183 * _base_free_irq - free irq
1184 * @ioc: per adapter object
1186 * Freeing respective reply_queue from the list.
1189 _base_free_irq(struct MPT2SAS_ADAPTER
*ioc
)
1191 struct adapter_reply_queue
*reply_q
, *next
;
1193 if (list_empty(&ioc
->reply_queue_list
))
1196 list_for_each_entry_safe(reply_q
, next
, &ioc
->reply_queue_list
, list
) {
1197 list_del(&reply_q
->list
);
1198 synchronize_irq(reply_q
->vector
);
1199 free_irq(reply_q
->vector
, reply_q
);
1205 * _base_request_irq - request irq
1206 * @ioc: per adapter object
1207 * @index: msix index into vector table
1208 * @vector: irq vector
1210 * Inserting respective reply_queue into the list.
1213 _base_request_irq(struct MPT2SAS_ADAPTER
*ioc
, u8 index
, u32 vector
)
1215 struct adapter_reply_queue
*reply_q
;
1218 reply_q
= kzalloc(sizeof(struct adapter_reply_queue
), GFP_KERNEL
);
1220 printk(MPT2SAS_ERR_FMT
"unable to allocate memory %d!\n",
1221 ioc
->name
, (int)sizeof(struct adapter_reply_queue
));
1225 reply_q
->msix_index
= index
;
1226 reply_q
->vector
= vector
;
1227 atomic_set(&reply_q
->busy
, 0);
1228 if (ioc
->msix_enable
)
1229 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d-msix%d",
1230 MPT2SAS_DRIVER_NAME
, ioc
->id
, index
);
1232 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d",
1233 MPT2SAS_DRIVER_NAME
, ioc
->id
);
1234 r
= request_irq(vector
, _base_interrupt
, IRQF_SHARED
, reply_q
->name
,
1237 printk(MPT2SAS_ERR_FMT
"unable to allocate interrupt %d!\n",
1238 reply_q
->name
, vector
);
1243 INIT_LIST_HEAD(&reply_q
->list
);
1244 list_add_tail(&reply_q
->list
, &ioc
->reply_queue_list
);
1249 * _base_assign_reply_queues - assigning msix index for each cpu
1250 * @ioc: per adapter object
1252 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1254 * It would nice if we could call irq_set_affinity, however it is not
1255 * an exported symbol
1258 _base_assign_reply_queues(struct MPT2SAS_ADAPTER
*ioc
)
1260 struct adapter_reply_queue
*reply_q
;
1262 int cpu_grouping
, loop
, grouping
, grouping_mod
;
1264 if (!_base_is_controller_msix_enabled(ioc
))
1267 memset(ioc
->cpu_msix_table
, 0, ioc
->cpu_msix_table_sz
);
1268 /* when there are more cpus than available msix vectors,
1269 * then group cpus togeather on same irq
1271 if (ioc
->cpu_count
> ioc
->msix_vector_count
) {
1272 grouping
= ioc
->cpu_count
/ ioc
->msix_vector_count
;
1273 grouping_mod
= ioc
->cpu_count
% ioc
->msix_vector_count
;
1274 if (grouping
< 2 || (grouping
== 2 && !grouping_mod
))
1276 else if (grouping
< 4 || (grouping
== 4 && !grouping_mod
))
1278 else if (grouping
< 8 || (grouping
== 8 && !grouping_mod
))
1286 reply_q
= list_entry(ioc
->reply_queue_list
.next
,
1287 struct adapter_reply_queue
, list
);
1288 for_each_online_cpu(cpu_id
) {
1289 if (!cpu_grouping
) {
1290 ioc
->cpu_msix_table
[cpu_id
] = reply_q
->msix_index
;
1291 reply_q
= list_entry(reply_q
->list
.next
,
1292 struct adapter_reply_queue
, list
);
1294 if (loop
< cpu_grouping
) {
1295 ioc
->cpu_msix_table
[cpu_id
] =
1296 reply_q
->msix_index
;
1299 reply_q
= list_entry(reply_q
->list
.next
,
1300 struct adapter_reply_queue
, list
);
1301 ioc
->cpu_msix_table
[cpu_id
] =
1302 reply_q
->msix_index
;
1310 * _base_disable_msix - disables msix
1311 * @ioc: per adapter object
1315 _base_disable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1317 if (ioc
->msix_enable
) {
1318 pci_disable_msix(ioc
->pdev
);
1319 ioc
->msix_enable
= 0;
1324 * _base_enable_msix - enables msix, failback to io_apic
1325 * @ioc: per adapter object
1329 _base_enable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1331 struct msix_entry
*entries
, *a
;
1336 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
1338 if (msix_disable
== -1 || msix_disable
== 0)
1344 if (_base_check_enable_msix(ioc
) != 0)
1347 ioc
->reply_queue_count
= min_t(u8
, ioc
->cpu_count
,
1348 ioc
->msix_vector_count
);
1350 entries
= kcalloc(ioc
->reply_queue_count
, sizeof(struct msix_entry
),
1353 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"kcalloc "
1354 "failed @ at %s:%d/%s() !!!\n", ioc
->name
, __FILE__
,
1355 __LINE__
, __func__
));
1359 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++)
1362 r
= pci_enable_msix(ioc
->pdev
, entries
, ioc
->reply_queue_count
);
1364 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"pci_enable_msix "
1365 "failed (r=%d) !!!\n", ioc
->name
, r
));
1370 ioc
->msix_enable
= 1;
1371 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++) {
1372 r
= _base_request_irq(ioc
, i
, a
->vector
);
1374 _base_free_irq(ioc
);
1375 _base_disable_msix(ioc
);
1384 /* failback to io_apic interrupt routing */
1387 r
= _base_request_irq(ioc
, 0, ioc
->pdev
->irq
);
1393 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1394 * @ioc: per adapter object
1396 * Returns 0 for success, non-zero for failure.
1399 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER
*ioc
)
1401 struct pci_dev
*pdev
= ioc
->pdev
;
1407 struct adapter_reply_queue
*reply_q
;
1409 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n",
1410 ioc
->name
, __func__
));
1412 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1413 if (pci_enable_device_mem(pdev
)) {
1414 printk(MPT2SAS_WARN_FMT
"pci_enable_device_mem: "
1415 "failed\n", ioc
->name
);
1420 if (pci_request_selected_regions(pdev
, ioc
->bars
,
1421 MPT2SAS_DRIVER_NAME
)) {
1422 printk(MPT2SAS_WARN_FMT
"pci_request_selected_regions: "
1423 "failed\n", ioc
->name
);
1428 /* AER (Advanced Error Reporting) hooks */
1429 pci_enable_pcie_error_reporting(pdev
);
1431 pci_set_master(pdev
);
1433 if (_base_config_dma_addressing(ioc
, pdev
) != 0) {
1434 printk(MPT2SAS_WARN_FMT
"no suitable DMA mask for %s\n",
1435 ioc
->name
, pci_name(pdev
));
1440 for (i
= 0, memap_sz
= 0, pio_sz
= 0 ; i
< DEVICE_COUNT_RESOURCE
; i
++) {
1441 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
1444 pio_chip
= (u64
)pci_resource_start(pdev
, i
);
1445 pio_sz
= pci_resource_len(pdev
, i
);
1449 /* verify memory resource is valid before using */
1450 if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
1451 ioc
->chip_phys
= pci_resource_start(pdev
, i
);
1452 chip_phys
= (u64
)ioc
->chip_phys
;
1453 memap_sz
= pci_resource_len(pdev
, i
);
1454 ioc
->chip
= ioremap(ioc
->chip_phys
, memap_sz
);
1455 if (ioc
->chip
== NULL
) {
1456 printk(MPT2SAS_ERR_FMT
"unable to map "
1457 "adapter memory!\n", ioc
->name
);
1465 _base_mask_interrupts(ioc
);
1466 r
= _base_enable_msix(ioc
);
1470 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
)
1471 printk(MPT2SAS_INFO_FMT
"%s: IRQ %d\n",
1472 reply_q
->name
, ((ioc
->msix_enable
) ? "PCI-MSI-X enabled" :
1473 "IO-APIC enabled"), reply_q
->vector
);
1475 printk(MPT2SAS_INFO_FMT
"iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1476 ioc
->name
, (unsigned long long)chip_phys
, ioc
->chip
, memap_sz
);
1477 printk(MPT2SAS_INFO_FMT
"ioport(0x%016llx), size(%d)\n",
1478 ioc
->name
, (unsigned long long)pio_chip
, pio_sz
);
1480 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1481 pci_save_state(pdev
);
1489 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
1490 pci_disable_pcie_error_reporting(pdev
);
1491 pci_disable_device(pdev
);
1496 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1497 * @ioc: per adapter object
1498 * @smid: system request message index(smid zero is invalid)
1500 * Returns virt pointer to message frame.
1503 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1505 return (void *)(ioc
->request
+ (smid
* ioc
->request_sz
));
1509 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1510 * @ioc: per adapter object
1511 * @smid: system request message index
1513 * Returns virt pointer to sense buffer.
1516 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1518 return (void *)(ioc
->sense
+ ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1522 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1523 * @ioc: per adapter object
1524 * @smid: system request message index
1526 * Returns phys pointer to the low 32bit address of the sense buffer.
1529 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1531 return cpu_to_le32(ioc
->sense_dma
+
1532 ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1536 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1537 * @ioc: per adapter object
1538 * @phys_addr: lower 32 physical addr of the reply
1540 * Converts 32bit lower physical addr into a virt address.
1543 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER
*ioc
, u32 phys_addr
)
1547 return ioc
->reply
+ (phys_addr
- (u32
)ioc
->reply_dma
);
1551 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1552 * @ioc: per adapter object
1553 * @cb_idx: callback index
1555 * Returns smid (zero is invalid)
1558 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
)
1560 unsigned long flags
;
1561 struct request_tracker
*request
;
1564 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1565 if (list_empty(&ioc
->internal_free_list
)) {
1566 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1567 printk(MPT2SAS_ERR_FMT
"%s: smid not available\n",
1568 ioc
->name
, __func__
);
1572 request
= list_entry(ioc
->internal_free_list
.next
,
1573 struct request_tracker
, tracker_list
);
1574 request
->cb_idx
= cb_idx
;
1575 smid
= request
->smid
;
1576 list_del(&request
->tracker_list
);
1577 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1582 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1583 * @ioc: per adapter object
1584 * @cb_idx: callback index
1585 * @scmd: pointer to scsi command object
1587 * Returns smid (zero is invalid)
1590 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
,
1591 struct scsi_cmnd
*scmd
)
1593 unsigned long flags
;
1594 struct scsiio_tracker
*request
;
1597 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1598 if (list_empty(&ioc
->free_list
)) {
1599 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1600 printk(MPT2SAS_ERR_FMT
"%s: smid not available\n",
1601 ioc
->name
, __func__
);
1605 request
= list_entry(ioc
->free_list
.next
,
1606 struct scsiio_tracker
, tracker_list
);
1607 request
->scmd
= scmd
;
1608 request
->cb_idx
= cb_idx
;
1609 smid
= request
->smid
;
1610 list_del(&request
->tracker_list
);
1611 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1616 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1617 * @ioc: per adapter object
1618 * @cb_idx: callback index
1620 * Returns smid (zero is invalid)
1623 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
)
1625 unsigned long flags
;
1626 struct request_tracker
*request
;
1629 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1630 if (list_empty(&ioc
->hpr_free_list
)) {
1631 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1635 request
= list_entry(ioc
->hpr_free_list
.next
,
1636 struct request_tracker
, tracker_list
);
1637 request
->cb_idx
= cb_idx
;
1638 smid
= request
->smid
;
1639 list_del(&request
->tracker_list
);
1640 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1646 * mpt2sas_base_free_smid - put smid back on free_list
1647 * @ioc: per adapter object
1648 * @smid: system request message index
1653 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1655 unsigned long flags
;
1657 struct chain_tracker
*chain_req
, *next
;
1659 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1660 if (smid
< ioc
->hi_priority_smid
) {
1663 if (!list_empty(&ioc
->scsi_lookup
[i
].chain_list
)) {
1664 list_for_each_entry_safe(chain_req
, next
,
1665 &ioc
->scsi_lookup
[i
].chain_list
, tracker_list
) {
1666 list_del_init(&chain_req
->tracker_list
);
1667 list_add_tail(&chain_req
->tracker_list
,
1668 &ioc
->free_chain_list
);
1671 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
1672 ioc
->scsi_lookup
[i
].scmd
= NULL
;
1673 ioc
->scsi_lookup
[i
].direct_io
= 0;
1674 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
1676 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1679 * See _wait_for_commands_to_complete() call with regards
1682 if (ioc
->shost_recovery
&& ioc
->pending_io_count
) {
1683 if (ioc
->pending_io_count
== 1)
1684 wake_up(&ioc
->reset_wq
);
1685 ioc
->pending_io_count
--;
1688 } else if (smid
< ioc
->internal_smid
) {
1690 i
= smid
- ioc
->hi_priority_smid
;
1691 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
1692 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
1693 &ioc
->hpr_free_list
);
1694 } else if (smid
<= ioc
->hba_queue_depth
) {
1695 /* internal queue */
1696 i
= smid
- ioc
->internal_smid
;
1697 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
1698 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
1699 &ioc
->internal_free_list
);
1701 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1705 * _base_writeq - 64 bit write to MMIO
1706 * @ioc: per adapter object
1708 * @addr: address in MMIO space
1709 * @writeq_lock: spin lock
1711 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1712 * care of 32 bit environment where its not quarenteed to send the entire word
1716 static inline void _base_writeq(__u64 b
, volatile void __iomem
*addr
,
1717 spinlock_t
*writeq_lock
)
1719 unsigned long flags
;
1720 __u64 data_out
= cpu_to_le64(b
);
1722 spin_lock_irqsave(writeq_lock
, flags
);
1723 writel((u32
)(data_out
), addr
);
1724 writel((u32
)(data_out
>> 32), (addr
+ 4));
1725 spin_unlock_irqrestore(writeq_lock
, flags
);
1728 static inline void _base_writeq(__u64 b
, volatile void __iomem
*addr
,
1729 spinlock_t
*writeq_lock
)
1731 writeq(cpu_to_le64(b
), addr
);
1736 _base_get_msix_index(struct MPT2SAS_ADAPTER
*ioc
)
1738 return ioc
->cpu_msix_table
[smp_processor_id()];
1742 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1743 * @ioc: per adapter object
1744 * @smid: system request message index
1745 * @handle: device handle
1750 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u16 handle
)
1752 Mpi2RequestDescriptorUnion_t descriptor
;
1753 u64
*request
= (u64
*)&descriptor
;
1756 descriptor
.SCSIIO
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
1757 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
1758 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
1759 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
1760 descriptor
.SCSIIO
.LMID
= 0;
1761 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1762 &ioc
->scsi_lookup_lock
);
1767 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1768 * @ioc: per adapter object
1769 * @smid: system request message index
1774 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1776 Mpi2RequestDescriptorUnion_t descriptor
;
1777 u64
*request
= (u64
*)&descriptor
;
1779 descriptor
.HighPriority
.RequestFlags
=
1780 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
1781 descriptor
.HighPriority
.MSIxIndex
= 0;
1782 descriptor
.HighPriority
.SMID
= cpu_to_le16(smid
);
1783 descriptor
.HighPriority
.LMID
= 0;
1784 descriptor
.HighPriority
.Reserved1
= 0;
1785 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1786 &ioc
->scsi_lookup_lock
);
1790 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1791 * @ioc: per adapter object
1792 * @smid: system request message index
1797 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1799 Mpi2RequestDescriptorUnion_t descriptor
;
1800 u64
*request
= (u64
*)&descriptor
;
1802 descriptor
.Default
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
1803 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
1804 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
1805 descriptor
.Default
.LMID
= 0;
1806 descriptor
.Default
.DescriptorTypeDependent
= 0;
1807 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1808 &ioc
->scsi_lookup_lock
);
1812 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1813 * @ioc: per adapter object
1814 * @smid: system request message index
1815 * @io_index: value used to track the IO
1820 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
1823 Mpi2RequestDescriptorUnion_t descriptor
;
1824 u64
*request
= (u64
*)&descriptor
;
1826 descriptor
.SCSITarget
.RequestFlags
=
1827 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET
;
1828 descriptor
.SCSITarget
.MSIxIndex
= _base_get_msix_index(ioc
);
1829 descriptor
.SCSITarget
.SMID
= cpu_to_le16(smid
);
1830 descriptor
.SCSITarget
.LMID
= 0;
1831 descriptor
.SCSITarget
.IoIndex
= cpu_to_le16(io_index
);
1832 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1833 &ioc
->scsi_lookup_lock
);
1837 * _base_display_dell_branding - Disply branding string
1838 * @ioc: per adapter object
1843 _base_display_dell_branding(struct MPT2SAS_ADAPTER
*ioc
)
1845 char dell_branding
[MPT2SAS_DELL_BRANDING_SIZE
];
1847 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_DELL
)
1850 memset(dell_branding
, 0, MPT2SAS_DELL_BRANDING_SIZE
);
1851 switch (ioc
->pdev
->subsystem_device
) {
1852 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID
:
1853 strncpy(dell_branding
, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING
,
1854 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1856 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID
:
1857 strncpy(dell_branding
, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING
,
1858 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1860 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID
:
1861 strncpy(dell_branding
,
1862 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING
,
1863 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1865 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID
:
1866 strncpy(dell_branding
,
1867 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING
,
1868 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1870 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID
:
1871 strncpy(dell_branding
,
1872 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING
,
1873 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1875 case MPT2SAS_DELL_PERC_H200_SSDID
:
1876 strncpy(dell_branding
, MPT2SAS_DELL_PERC_H200_BRANDING
,
1877 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1879 case MPT2SAS_DELL_6GBPS_SAS_SSDID
:
1880 strncpy(dell_branding
, MPT2SAS_DELL_6GBPS_SAS_BRANDING
,
1881 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1884 sprintf(dell_branding
, "0x%4X", ioc
->pdev
->subsystem_device
);
1888 printk(MPT2SAS_INFO_FMT
"%s: Vendor(0x%04X), Device(0x%04X),"
1889 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc
->name
, dell_branding
,
1890 ioc
->pdev
->vendor
, ioc
->pdev
->device
, ioc
->pdev
->subsystem_vendor
,
1891 ioc
->pdev
->subsystem_device
);
1895 * _base_display_intel_branding - Display branding string
1896 * @ioc: per adapter object
1901 _base_display_intel_branding(struct MPT2SAS_ADAPTER
*ioc
)
1903 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
1906 switch (ioc
->pdev
->device
) {
1907 case MPI2_MFGPAGE_DEVID_SAS2008
:
1908 switch (ioc
->pdev
->subsystem_device
) {
1909 case MPT2SAS_INTEL_RMS2LL080_SSDID
:
1910 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1911 MPT2SAS_INTEL_RMS2LL080_BRANDING
);
1913 case MPT2SAS_INTEL_RMS2LL040_SSDID
:
1914 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1915 MPT2SAS_INTEL_RMS2LL040_BRANDING
);
1920 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
1921 switch (ioc
->pdev
->subsystem_device
) {
1922 case MPT2SAS_INTEL_RS25GB008_SSDID
:
1923 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1924 MPT2SAS_INTEL_RS25GB008_BRANDING
);
1935 * _base_display_hp_branding - Display branding string
1936 * @ioc: per adapter object
1941 _base_display_hp_branding(struct MPT2SAS_ADAPTER
*ioc
)
1943 if (ioc
->pdev
->subsystem_vendor
!= MPT2SAS_HP_3PAR_SSVID
)
1946 switch (ioc
->pdev
->device
) {
1947 case MPI2_MFGPAGE_DEVID_SAS2004
:
1948 switch (ioc
->pdev
->subsystem_device
) {
1949 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID
:
1950 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1951 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING
);
1956 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
1957 switch (ioc
->pdev
->subsystem_device
) {
1958 case MPT2SAS_HP_2_4_INTERNAL_SSDID
:
1959 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1960 MPT2SAS_HP_2_4_INTERNAL_BRANDING
);
1962 case MPT2SAS_HP_2_4_EXTERNAL_SSDID
:
1963 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1964 MPT2SAS_HP_2_4_EXTERNAL_BRANDING
);
1966 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID
:
1967 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1968 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING
);
1970 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID
:
1971 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1972 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING
);
1983 * _base_display_ioc_capabilities - Disply IOC's capabilities.
1984 * @ioc: per adapter object
1989 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER
*ioc
)
1994 u32 iounit_pg1_flags
;
1997 bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
1998 pci_read_config_byte(ioc
->pdev
, PCI_CLASS_REVISION
, &revision
);
1999 strncpy(desc
, ioc
->manu_pg0
.ChipName
, 16);
2000 printk(MPT2SAS_INFO_FMT
"%s: FWVersion(%02d.%02d.%02d.%02d), "
2001 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2003 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2004 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2005 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2006 ioc
->facts
.FWVersion
.Word
& 0x000000FF,
2008 (bios_version
& 0xFF000000) >> 24,
2009 (bios_version
& 0x00FF0000) >> 16,
2010 (bios_version
& 0x0000FF00) >> 8,
2011 bios_version
& 0x000000FF);
2013 _base_display_dell_branding(ioc
);
2014 _base_display_intel_branding(ioc
);
2015 _base_display_hp_branding(ioc
);
2017 printk(MPT2SAS_INFO_FMT
"Protocol=(", ioc
->name
);
2019 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
) {
2020 printk("Initiator");
2024 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET
) {
2025 printk("%sTarget", i
? "," : "");
2031 printk("Capabilities=(");
2033 if (!ioc
->hide_ir_msg
) {
2034 if (ioc
->facts
.IOCCapabilities
&
2035 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
) {
2041 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
) {
2042 printk("%sTLR", i
? "," : "");
2046 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_MULTICAST
) {
2047 printk("%sMulticast", i
? "," : "");
2051 if (ioc
->facts
.IOCCapabilities
&
2052 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET
) {
2053 printk("%sBIDI Target", i
? "," : "");
2057 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_EEDP
) {
2058 printk("%sEEDP", i
? "," : "");
2062 if (ioc
->facts
.IOCCapabilities
&
2063 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
) {
2064 printk("%sSnapshot Buffer", i
? "," : "");
2068 if (ioc
->facts
.IOCCapabilities
&
2069 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
) {
2070 printk("%sDiag Trace Buffer", i
? "," : "");
2074 if (ioc
->facts
.IOCCapabilities
&
2075 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
) {
2076 printk(KERN_INFO
"%sDiag Extended Buffer", i
? "," : "");
2080 if (ioc
->facts
.IOCCapabilities
&
2081 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
) {
2082 printk("%sTask Set Full", i
? "," : "");
2086 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2087 if (!(iounit_pg1_flags
& MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE
)) {
2088 printk("%sNCQ", i
? "," : "");
2096 * _base_update_missing_delay - change the missing delay timers
2097 * @ioc: per adapter object
2098 * @device_missing_delay: amount of time till device is reported missing
2099 * @io_missing_delay: interval IO is returned when there is a missing device
2103 * Passed on the command line, this function will modify the device missing
2104 * delay, as well as the io missing delay. This should be called at driver
2108 _base_update_missing_delay(struct MPT2SAS_ADAPTER
*ioc
,
2109 u16 device_missing_delay
, u8 io_missing_delay
)
2111 u16 dmd
, dmd_new
, dmd_orignal
;
2112 u8 io_missing_delay_original
;
2114 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
2115 Mpi2ConfigReply_t mpi_reply
;
2119 mpt2sas_config_get_number_hba_phys(ioc
, &num_phys
);
2123 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (num_phys
*
2124 sizeof(Mpi2SasIOUnit1PhyData_t
));
2125 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
2126 if (!sas_iounit_pg1
) {
2127 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2128 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2131 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
2132 sas_iounit_pg1
, sz
))) {
2133 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2134 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2137 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
2138 MPI2_IOCSTATUS_MASK
;
2139 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2140 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2141 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2145 /* device missing delay */
2146 dmd
= sas_iounit_pg1
->ReportDeviceMissingDelay
;
2147 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2148 dmd
= (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2150 dmd
= dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2152 if (device_missing_delay
> 0x7F) {
2153 dmd
= (device_missing_delay
> 0x7F0) ? 0x7F0 :
2154 device_missing_delay
;
2156 dmd
|= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
;
2158 dmd
= device_missing_delay
;
2159 sas_iounit_pg1
->ReportDeviceMissingDelay
= dmd
;
2161 /* io missing delay */
2162 io_missing_delay_original
= sas_iounit_pg1
->IODeviceMissingDelay
;
2163 sas_iounit_pg1
->IODeviceMissingDelay
= io_missing_delay
;
2165 if (!mpt2sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
2167 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2169 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2172 dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2173 printk(MPT2SAS_INFO_FMT
"device_missing_delay: old(%d), "
2174 "new(%d)\n", ioc
->name
, dmd_orignal
, dmd_new
);
2175 printk(MPT2SAS_INFO_FMT
"ioc_missing_delay: old(%d), "
2176 "new(%d)\n", ioc
->name
, io_missing_delay_original
,
2178 ioc
->device_missing_delay
= dmd_new
;
2179 ioc
->io_missing_delay
= io_missing_delay
;
2183 kfree(sas_iounit_pg1
);
2187 * _base_static_config_pages - static start of day config pages
2188 * @ioc: per adapter object
2193 _base_static_config_pages(struct MPT2SAS_ADAPTER
*ioc
)
2195 Mpi2ConfigReply_t mpi_reply
;
2196 u32 iounit_pg1_flags
;
2198 mpt2sas_config_get_manufacturing_pg0(ioc
, &mpi_reply
, &ioc
->manu_pg0
);
2199 if (ioc
->ir_firmware
)
2200 mpt2sas_config_get_manufacturing_pg10(ioc
, &mpi_reply
,
2202 mpt2sas_config_get_bios_pg2(ioc
, &mpi_reply
, &ioc
->bios_pg2
);
2203 mpt2sas_config_get_bios_pg3(ioc
, &mpi_reply
, &ioc
->bios_pg3
);
2204 mpt2sas_config_get_ioc_pg8(ioc
, &mpi_reply
, &ioc
->ioc_pg8
);
2205 mpt2sas_config_get_iounit_pg0(ioc
, &mpi_reply
, &ioc
->iounit_pg0
);
2206 mpt2sas_config_get_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2207 _base_display_ioc_capabilities(ioc
);
2210 * Enable task_set_full handling in iounit_pg1 when the
2211 * facts capabilities indicate that its supported.
2213 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2214 if ((ioc
->facts
.IOCCapabilities
&
2215 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
))
2217 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2220 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2221 ioc
->iounit_pg1
.Flags
= cpu_to_le32(iounit_pg1_flags
);
2222 mpt2sas_config_set_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2227 * _base_release_memory_pools - release memory
2228 * @ioc: per adapter object
2230 * Free memory allocated from _base_allocate_memory_pools.
2235 _base_release_memory_pools(struct MPT2SAS_ADAPTER
*ioc
)
2239 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2243 pci_free_consistent(ioc
->pdev
, ioc
->request_dma_sz
,
2244 ioc
->request
, ioc
->request_dma
);
2245 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request_pool(0x%p)"
2246 ": free\n", ioc
->name
, ioc
->request
));
2247 ioc
->request
= NULL
;
2251 pci_pool_free(ioc
->sense_dma_pool
, ioc
->sense
, ioc
->sense_dma
);
2252 if (ioc
->sense_dma_pool
)
2253 pci_pool_destroy(ioc
->sense_dma_pool
);
2254 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sense_pool(0x%p)"
2255 ": free\n", ioc
->name
, ioc
->sense
));
2260 pci_pool_free(ioc
->reply_dma_pool
, ioc
->reply
, ioc
->reply_dma
);
2261 if (ioc
->reply_dma_pool
)
2262 pci_pool_destroy(ioc
->reply_dma_pool
);
2263 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_pool(0x%p)"
2264 ": free\n", ioc
->name
, ioc
->reply
));
2268 if (ioc
->reply_free
) {
2269 pci_pool_free(ioc
->reply_free_dma_pool
, ioc
->reply_free
,
2270 ioc
->reply_free_dma
);
2271 if (ioc
->reply_free_dma_pool
)
2272 pci_pool_destroy(ioc
->reply_free_dma_pool
);
2273 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free_pool"
2274 "(0x%p): free\n", ioc
->name
, ioc
->reply_free
));
2275 ioc
->reply_free
= NULL
;
2278 if (ioc
->reply_post_free
) {
2279 pci_pool_free(ioc
->reply_post_free_dma_pool
,
2280 ioc
->reply_post_free
, ioc
->reply_post_free_dma
);
2281 if (ioc
->reply_post_free_dma_pool
)
2282 pci_pool_destroy(ioc
->reply_post_free_dma_pool
);
2283 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2284 "reply_post_free_pool(0x%p): free\n", ioc
->name
,
2285 ioc
->reply_post_free
));
2286 ioc
->reply_post_free
= NULL
;
2289 if (ioc
->config_page
) {
2290 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2291 "config_page(0x%p): free\n", ioc
->name
,
2293 pci_free_consistent(ioc
->pdev
, ioc
->config_page_sz
,
2294 ioc
->config_page
, ioc
->config_page_dma
);
2297 if (ioc
->scsi_lookup
) {
2298 free_pages((ulong
)ioc
->scsi_lookup
, ioc
->scsi_lookup_pages
);
2299 ioc
->scsi_lookup
= NULL
;
2301 kfree(ioc
->hpr_lookup
);
2302 kfree(ioc
->internal_lookup
);
2303 if (ioc
->chain_lookup
) {
2304 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2305 if (ioc
->chain_lookup
[i
].chain_buffer
)
2306 pci_pool_free(ioc
->chain_dma_pool
,
2307 ioc
->chain_lookup
[i
].chain_buffer
,
2308 ioc
->chain_lookup
[i
].chain_buffer_dma
);
2310 if (ioc
->chain_dma_pool
)
2311 pci_pool_destroy(ioc
->chain_dma_pool
);
2313 if (ioc
->chain_lookup
) {
2314 free_pages((ulong
)ioc
->chain_lookup
, ioc
->chain_pages
);
2315 ioc
->chain_lookup
= NULL
;
2321 * _base_allocate_memory_pools - allocate start of day memory pools
2322 * @ioc: per adapter object
2323 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2325 * Returns 0 success, anything else error
2328 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
2330 struct mpt2sas_facts
*facts
;
2331 u32 queue_size
, queue_diff
;
2332 u16 max_sge_elements
;
2333 u16 num_of_reply_frames
;
2334 u16 chains_needed_per_io
;
2335 u32 sz
, total_sz
, reply_post_free_sz
;
2337 u16 max_request_credit
;
2340 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2344 facts
= &ioc
->facts
;
2346 /* command line tunables for max sgl entries */
2347 if (max_sgl_entries
!= -1) {
2348 ioc
->shost
->sg_tablesize
= (max_sgl_entries
<
2349 MPT2SAS_SG_DEPTH
) ? max_sgl_entries
:
2352 ioc
->shost
->sg_tablesize
= MPT2SAS_SG_DEPTH
;
2355 /* command line tunables for max controller queue depth */
2356 if (max_queue_depth
!= -1)
2357 max_request_credit
= (max_queue_depth
< facts
->RequestCredit
)
2358 ? max_queue_depth
: facts
->RequestCredit
;
2360 max_request_credit
= facts
->RequestCredit
;
2362 ioc
->hba_queue_depth
= max_request_credit
;
2363 ioc
->hi_priority_depth
= facts
->HighPriorityCredit
;
2364 ioc
->internal_depth
= ioc
->hi_priority_depth
+ 5;
2366 /* request frame size */
2367 ioc
->request_sz
= facts
->IOCRequestFrameSize
* 4;
2369 /* reply frame size */
2370 ioc
->reply_sz
= facts
->ReplyFrameSize
* 4;
2374 /* calculate number of sg elements left over in the 1st frame */
2375 max_sge_elements
= ioc
->request_sz
- ((sizeof(Mpi2SCSIIORequest_t
) -
2376 sizeof(Mpi2SGEIOUnion_t
)) + ioc
->sge_size
);
2377 ioc
->max_sges_in_main_message
= max_sge_elements
/ioc
->sge_size
;
2379 /* now do the same for a chain buffer */
2380 max_sge_elements
= ioc
->request_sz
- ioc
->sge_size
;
2381 ioc
->max_sges_in_chain_message
= max_sge_elements
/ioc
->sge_size
;
2383 ioc
->chain_offset_value_for_main_message
=
2384 ((sizeof(Mpi2SCSIIORequest_t
) - sizeof(Mpi2SGEIOUnion_t
)) +
2385 (ioc
->max_sges_in_chain_message
* ioc
->sge_size
)) / 4;
2388 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2390 chains_needed_per_io
= ((ioc
->shost
->sg_tablesize
-
2391 ioc
->max_sges_in_main_message
)/ioc
->max_sges_in_chain_message
)
2393 if (chains_needed_per_io
> facts
->MaxChainDepth
) {
2394 chains_needed_per_io
= facts
->MaxChainDepth
;
2395 ioc
->shost
->sg_tablesize
= min_t(u16
,
2396 ioc
->max_sges_in_main_message
+ (ioc
->max_sges_in_chain_message
2397 * chains_needed_per_io
), ioc
->shost
->sg_tablesize
);
2399 ioc
->chains_needed_per_io
= chains_needed_per_io
;
2401 /* reply free queue sizing - taking into account for events */
2402 num_of_reply_frames
= ioc
->hba_queue_depth
+ 32;
2404 /* number of replies frames can't be a multiple of 16 */
2405 /* decrease number of reply frames by 1 */
2406 if (!(num_of_reply_frames
% 16))
2407 num_of_reply_frames
--;
2409 /* calculate number of reply free queue entries
2410 * (must be multiple of 16)
2413 /* (we know reply_free_queue_depth is not a multiple of 16) */
2414 queue_size
= num_of_reply_frames
;
2415 queue_size
+= 16 - (queue_size
% 16);
2416 ioc
->reply_free_queue_depth
= queue_size
;
2418 /* reply descriptor post queue sizing */
2419 /* this size should be the number of request frames + number of reply
2423 queue_size
= ioc
->hba_queue_depth
+ num_of_reply_frames
+ 1;
2424 /* round up to 16 byte boundary */
2425 if (queue_size
% 16)
2426 queue_size
+= 16 - (queue_size
% 16);
2428 /* check against IOC maximum reply post queue depth */
2429 if (queue_size
> facts
->MaxReplyDescriptorPostQueueDepth
) {
2430 queue_diff
= queue_size
-
2431 facts
->MaxReplyDescriptorPostQueueDepth
;
2433 /* round queue_diff up to multiple of 16 */
2434 if (queue_diff
% 16)
2435 queue_diff
+= 16 - (queue_diff
% 16);
2437 /* adjust hba_queue_depth, reply_free_queue_depth,
2440 ioc
->hba_queue_depth
-= (queue_diff
/ 2);
2441 ioc
->reply_free_queue_depth
-= (queue_diff
/ 2);
2442 queue_size
= facts
->MaxReplyDescriptorPostQueueDepth
;
2444 ioc
->reply_post_queue_depth
= queue_size
;
2446 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scatter gather: "
2447 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2448 "chains_per_io(%d)\n", ioc
->name
, ioc
->max_sges_in_main_message
,
2449 ioc
->max_sges_in_chain_message
, ioc
->shost
->sg_tablesize
,
2450 ioc
->chains_needed_per_io
));
2452 ioc
->scsiio_depth
= ioc
->hba_queue_depth
-
2453 ioc
->hi_priority_depth
- ioc
->internal_depth
;
2455 /* set the scsi host can_queue depth
2456 * with some internal commands that could be outstanding
2458 ioc
->shost
->can_queue
= ioc
->scsiio_depth
- (2);
2459 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scsi host: "
2460 "can_queue depth (%d)\n", ioc
->name
, ioc
->shost
->can_queue
));
2462 /* contiguous pool for request and chains, 16 byte align, one extra "
2465 ioc
->chain_depth
= ioc
->chains_needed_per_io
* ioc
->scsiio_depth
;
2466 sz
= ((ioc
->scsiio_depth
+ 1) * ioc
->request_sz
);
2468 /* hi-priority queue */
2469 sz
+= (ioc
->hi_priority_depth
* ioc
->request_sz
);
2471 /* internal queue */
2472 sz
+= (ioc
->internal_depth
* ioc
->request_sz
);
2474 ioc
->request_dma_sz
= sz
;
2475 ioc
->request
= pci_alloc_consistent(ioc
->pdev
, sz
, &ioc
->request_dma
);
2476 if (!ioc
->request
) {
2477 printk(MPT2SAS_ERR_FMT
"request pool: pci_alloc_consistent "
2478 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2479 "total(%d kB)\n", ioc
->name
, ioc
->hba_queue_depth
,
2480 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2481 if (ioc
->scsiio_depth
< MPT2SAS_SAS_QUEUE_DEPTH
)
2484 ioc
->hba_queue_depth
= max_request_credit
- retry_sz
;
2485 goto retry_allocation
;
2489 printk(MPT2SAS_ERR_FMT
"request pool: pci_alloc_consistent "
2490 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2491 "total(%d kb)\n", ioc
->name
, ioc
->hba_queue_depth
,
2492 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2495 /* hi-priority queue */
2496 ioc
->hi_priority
= ioc
->request
+ ((ioc
->scsiio_depth
+ 1) *
2498 ioc
->hi_priority_dma
= ioc
->request_dma
+ ((ioc
->scsiio_depth
+ 1) *
2501 /* internal queue */
2502 ioc
->internal
= ioc
->hi_priority
+ (ioc
->hi_priority_depth
*
2504 ioc
->internal_dma
= ioc
->hi_priority_dma
+ (ioc
->hi_priority_depth
*
2508 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request pool(0x%p): "
2509 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
,
2510 ioc
->request
, ioc
->hba_queue_depth
, ioc
->request_sz
,
2511 (ioc
->hba_queue_depth
* ioc
->request_sz
)/1024));
2512 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request pool: dma(0x%llx)\n",
2513 ioc
->name
, (unsigned long long) ioc
->request_dma
));
2516 sz
= ioc
->scsiio_depth
* sizeof(struct scsiio_tracker
);
2517 ioc
->scsi_lookup_pages
= get_order(sz
);
2518 ioc
->scsi_lookup
= (struct scsiio_tracker
*)__get_free_pages(
2519 GFP_KERNEL
, ioc
->scsi_lookup_pages
);
2520 if (!ioc
->scsi_lookup
) {
2521 printk(MPT2SAS_ERR_FMT
"scsi_lookup: get_free_pages failed, "
2522 "sz(%d)\n", ioc
->name
, (int)sz
);
2526 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scsiio(0x%p): "
2527 "depth(%d)\n", ioc
->name
, ioc
->request
,
2528 ioc
->scsiio_depth
));
2530 /* loop till the allocation succeeds */
2532 sz
= ioc
->chain_depth
* sizeof(struct chain_tracker
);
2533 ioc
->chain_pages
= get_order(sz
);
2534 ioc
->chain_lookup
= (struct chain_tracker
*)__get_free_pages(
2535 GFP_KERNEL
, ioc
->chain_pages
);
2536 if (ioc
->chain_lookup
== NULL
)
2537 ioc
->chain_depth
-= 100;
2538 } while (ioc
->chain_lookup
== NULL
);
2539 ioc
->chain_dma_pool
= pci_pool_create("chain pool", ioc
->pdev
,
2540 ioc
->request_sz
, 16, 0);
2541 if (!ioc
->chain_dma_pool
) {
2542 printk(MPT2SAS_ERR_FMT
"chain_dma_pool: pci_pool_create "
2543 "failed\n", ioc
->name
);
2546 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2547 ioc
->chain_lookup
[i
].chain_buffer
= pci_pool_alloc(
2548 ioc
->chain_dma_pool
, GFP_KERNEL
,
2549 &ioc
->chain_lookup
[i
].chain_buffer_dma
);
2550 if (!ioc
->chain_lookup
[i
].chain_buffer
) {
2551 ioc
->chain_depth
= i
;
2554 total_sz
+= ioc
->request_sz
;
2557 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"chain pool depth"
2558 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
,
2559 ioc
->chain_depth
, ioc
->request_sz
, ((ioc
->chain_depth
*
2560 ioc
->request_sz
))/1024));
2562 /* initialize hi-priority queue smid's */
2563 ioc
->hpr_lookup
= kcalloc(ioc
->hi_priority_depth
,
2564 sizeof(struct request_tracker
), GFP_KERNEL
);
2565 if (!ioc
->hpr_lookup
) {
2566 printk(MPT2SAS_ERR_FMT
"hpr_lookup: kcalloc failed\n",
2570 ioc
->hi_priority_smid
= ioc
->scsiio_depth
+ 1;
2571 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"hi_priority(0x%p): "
2572 "depth(%d), start smid(%d)\n", ioc
->name
, ioc
->hi_priority
,
2573 ioc
->hi_priority_depth
, ioc
->hi_priority_smid
));
2575 /* initialize internal queue smid's */
2576 ioc
->internal_lookup
= kcalloc(ioc
->internal_depth
,
2577 sizeof(struct request_tracker
), GFP_KERNEL
);
2578 if (!ioc
->internal_lookup
) {
2579 printk(MPT2SAS_ERR_FMT
"internal_lookup: kcalloc failed\n",
2583 ioc
->internal_smid
= ioc
->hi_priority_smid
+ ioc
->hi_priority_depth
;
2584 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"internal(0x%p): "
2585 "depth(%d), start smid(%d)\n", ioc
->name
, ioc
->internal
,
2586 ioc
->internal_depth
, ioc
->internal_smid
));
2588 /* sense buffers, 4 byte align */
2589 sz
= ioc
->scsiio_depth
* SCSI_SENSE_BUFFERSIZE
;
2590 ioc
->sense_dma_pool
= pci_pool_create("sense pool", ioc
->pdev
, sz
, 4,
2592 if (!ioc
->sense_dma_pool
) {
2593 printk(MPT2SAS_ERR_FMT
"sense pool: pci_pool_create failed\n",
2597 ioc
->sense
= pci_pool_alloc(ioc
->sense_dma_pool
, GFP_KERNEL
,
2600 printk(MPT2SAS_ERR_FMT
"sense pool: pci_pool_alloc failed\n",
2604 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2605 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2606 "(%d kB)\n", ioc
->name
, ioc
->sense
, ioc
->scsiio_depth
,
2607 SCSI_SENSE_BUFFERSIZE
, sz
/1024));
2608 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sense_dma(0x%llx)\n",
2609 ioc
->name
, (unsigned long long)ioc
->sense_dma
));
2612 /* reply pool, 4 byte align */
2613 sz
= ioc
->reply_free_queue_depth
* ioc
->reply_sz
;
2614 ioc
->reply_dma_pool
= pci_pool_create("reply pool", ioc
->pdev
, sz
, 4,
2616 if (!ioc
->reply_dma_pool
) {
2617 printk(MPT2SAS_ERR_FMT
"reply pool: pci_pool_create failed\n",
2621 ioc
->reply
= pci_pool_alloc(ioc
->reply_dma_pool
, GFP_KERNEL
,
2624 printk(MPT2SAS_ERR_FMT
"reply pool: pci_pool_alloc failed\n",
2628 ioc
->reply_dma_min_address
= (u32
)(ioc
->reply_dma
);
2629 ioc
->reply_dma_max_address
= (u32
)(ioc
->reply_dma
) + sz
;
2630 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply pool(0x%p): depth"
2631 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
, ioc
->reply
,
2632 ioc
->reply_free_queue_depth
, ioc
->reply_sz
, sz
/1024));
2633 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_dma(0x%llx)\n",
2634 ioc
->name
, (unsigned long long)ioc
->reply_dma
));
2637 /* reply free queue, 16 byte align */
2638 sz
= ioc
->reply_free_queue_depth
* 4;
2639 ioc
->reply_free_dma_pool
= pci_pool_create("reply_free pool",
2640 ioc
->pdev
, sz
, 16, 0);
2641 if (!ioc
->reply_free_dma_pool
) {
2642 printk(MPT2SAS_ERR_FMT
"reply_free pool: pci_pool_create "
2643 "failed\n", ioc
->name
);
2646 ioc
->reply_free
= pci_pool_alloc(ioc
->reply_free_dma_pool
, GFP_KERNEL
,
2647 &ioc
->reply_free_dma
);
2648 if (!ioc
->reply_free
) {
2649 printk(MPT2SAS_ERR_FMT
"reply_free pool: pci_pool_alloc "
2650 "failed\n", ioc
->name
);
2653 memset(ioc
->reply_free
, 0, sz
);
2654 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free pool(0x%p): "
2655 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc
->name
,
2656 ioc
->reply_free
, ioc
->reply_free_queue_depth
, 4, sz
/1024));
2657 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free_dma"
2658 "(0x%llx)\n", ioc
->name
, (unsigned long long)ioc
->reply_free_dma
));
2661 /* reply post queue, 16 byte align */
2662 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
2663 sizeof(Mpi2DefaultReplyDescriptor_t
);
2664 if (_base_is_controller_msix_enabled(ioc
))
2665 sz
= reply_post_free_sz
* ioc
->reply_queue_count
;
2667 sz
= reply_post_free_sz
;
2668 ioc
->reply_post_free_dma_pool
= pci_pool_create("reply_post_free pool",
2669 ioc
->pdev
, sz
, 16, 0);
2670 if (!ioc
->reply_post_free_dma_pool
) {
2671 printk(MPT2SAS_ERR_FMT
"reply_post_free pool: pci_pool_create "
2672 "failed\n", ioc
->name
);
2675 ioc
->reply_post_free
= pci_pool_alloc(ioc
->reply_post_free_dma_pool
,
2676 GFP_KERNEL
, &ioc
->reply_post_free_dma
);
2677 if (!ioc
->reply_post_free
) {
2678 printk(MPT2SAS_ERR_FMT
"reply_post_free pool: pci_pool_alloc "
2679 "failed\n", ioc
->name
);
2682 memset(ioc
->reply_post_free
, 0, sz
);
2683 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply post free pool"
2684 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2685 ioc
->name
, ioc
->reply_post_free
, ioc
->reply_post_queue_depth
, 8,
2687 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_post_free_dma = "
2688 "(0x%llx)\n", ioc
->name
, (unsigned long long)
2689 ioc
->reply_post_free_dma
));
2692 ioc
->config_page_sz
= 512;
2693 ioc
->config_page
= pci_alloc_consistent(ioc
->pdev
,
2694 ioc
->config_page_sz
, &ioc
->config_page_dma
);
2695 if (!ioc
->config_page
) {
2696 printk(MPT2SAS_ERR_FMT
"config page: pci_pool_alloc "
2697 "failed\n", ioc
->name
);
2700 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"config page(0x%p): size"
2701 "(%d)\n", ioc
->name
, ioc
->config_page
, ioc
->config_page_sz
));
2702 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"config_page_dma"
2703 "(0x%llx)\n", ioc
->name
, (unsigned long long)ioc
->config_page_dma
));
2704 total_sz
+= ioc
->config_page_sz
;
2706 printk(MPT2SAS_INFO_FMT
"Allocated physical memory: size(%d kB)\n",
2707 ioc
->name
, total_sz
/1024);
2708 printk(MPT2SAS_INFO_FMT
"Current Controller Queue Depth(%d), "
2709 "Max Controller Queue Depth(%d)\n",
2710 ioc
->name
, ioc
->shost
->can_queue
, facts
->RequestCredit
);
2711 printk(MPT2SAS_INFO_FMT
"Scatter Gather Elements per IO(%d)\n",
2712 ioc
->name
, ioc
->shost
->sg_tablesize
);
2721 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2722 * @ioc: Pointer to MPT_ADAPTER structure
2723 * @cooked: Request raw or cooked IOC state
2725 * Returns all IOC Doorbell register bits if cooked==0, else just the
2726 * Doorbell bits in MPI_IOC_STATE_MASK.
2729 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER
*ioc
, int cooked
)
2733 s
= readl(&ioc
->chip
->Doorbell
);
2734 sc
= s
& MPI2_IOC_STATE_MASK
;
2735 return cooked
? sc
: s
;
2739 * _base_wait_on_iocstate - waiting on a particular ioc state
2740 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2741 * @timeout: timeout in second
2742 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2744 * Returns 0 for success, non-zero for failure.
2747 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER
*ioc
, u32 ioc_state
, int timeout
,
2754 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2756 current_state
= mpt2sas_base_get_iocstate(ioc
, 1);
2757 if (current_state
== ioc_state
)
2759 if (count
&& current_state
== MPI2_IOC_STATE_FAULT
)
2761 if (sleep_flag
== CAN_SLEEP
)
2768 return current_state
;
2772 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2773 * a write to the doorbell)
2774 * @ioc: per adapter object
2775 * @timeout: timeout in second
2776 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2778 * Returns 0 for success, non-zero for failure.
2780 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2783 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2790 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2792 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
2793 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
2794 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2795 "successful count(%d), timeout(%d)\n", ioc
->name
,
2796 __func__
, count
, timeout
));
2799 if (sleep_flag
== CAN_SLEEP
)
2806 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2807 "int_status(%x)!\n", ioc
->name
, __func__
, count
, int_status
);
2812 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2813 * @ioc: per adapter object
2814 * @timeout: timeout in second
2815 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2817 * Returns 0 for success, non-zero for failure.
2819 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2823 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2831 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2833 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
2834 if (!(int_status
& MPI2_HIS_SYS2IOC_DB_STATUS
)) {
2835 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2836 "successful count(%d), timeout(%d)\n", ioc
->name
,
2837 __func__
, count
, timeout
));
2839 } else if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
2840 doorbell
= readl(&ioc
->chip
->Doorbell
);
2841 if ((doorbell
& MPI2_IOC_STATE_MASK
) ==
2842 MPI2_IOC_STATE_FAULT
) {
2843 mpt2sas_base_fault_info(ioc
, doorbell
);
2846 } else if (int_status
== 0xFFFFFFFF)
2849 if (sleep_flag
== CAN_SLEEP
)
2857 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2858 "int_status(%x)!\n", ioc
->name
, __func__
, count
, int_status
);
2863 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2864 * @ioc: per adapter object
2865 * @timeout: timeout in second
2866 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2868 * Returns 0 for success, non-zero for failure.
2872 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2879 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2881 doorbell_reg
= readl(&ioc
->chip
->Doorbell
);
2882 if (!(doorbell_reg
& MPI2_DOORBELL_USED
)) {
2883 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2884 "successful count(%d), timeout(%d)\n", ioc
->name
,
2885 __func__
, count
, timeout
));
2888 if (sleep_flag
== CAN_SLEEP
)
2895 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2896 "doorbell_reg(%x)!\n", ioc
->name
, __func__
, count
, doorbell_reg
);
2901 * _base_send_ioc_reset - send doorbell reset
2902 * @ioc: per adapter object
2903 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2904 * @timeout: timeout in second
2905 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2907 * Returns 0 for success, non-zero for failure.
2910 _base_send_ioc_reset(struct MPT2SAS_ADAPTER
*ioc
, u8 reset_type
, int timeout
,
2916 if (reset_type
!= MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
) {
2917 printk(MPT2SAS_ERR_FMT
"%s: unknown reset_type\n",
2918 ioc
->name
, __func__
);
2922 if (!(ioc
->facts
.IOCCapabilities
&
2923 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY
))
2926 printk(MPT2SAS_INFO_FMT
"sending message unit reset !!\n", ioc
->name
);
2928 writel(reset_type
<< MPI2_DOORBELL_FUNCTION_SHIFT
,
2929 &ioc
->chip
->Doorbell
);
2930 if ((_base_wait_for_doorbell_ack(ioc
, 15, sleep_flag
))) {
2934 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
,
2935 timeout
, sleep_flag
);
2937 printk(MPT2SAS_ERR_FMT
"%s: failed going to ready state "
2938 " (ioc_state=0x%x)\n", ioc
->name
, __func__
, ioc_state
);
2943 printk(MPT2SAS_INFO_FMT
"message unit reset: %s\n",
2944 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
2949 * _base_handshake_req_reply_wait - send request thru doorbell interface
2950 * @ioc: per adapter object
2951 * @request_bytes: request length
2952 * @request: pointer having request payload
2953 * @reply_bytes: reply length
2954 * @reply: pointer to reply payload
2955 * @timeout: timeout in second
2956 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2958 * Returns 0 for success, non-zero for failure.
2961 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER
*ioc
, int request_bytes
,
2962 u32
*request
, int reply_bytes
, u16
*reply
, int timeout
, int sleep_flag
)
2964 MPI2DefaultReply_t
*default_reply
= (MPI2DefaultReply_t
*)reply
;
2970 /* make sure doorbell is not in use */
2971 if ((readl(&ioc
->chip
->Doorbell
) & MPI2_DOORBELL_USED
)) {
2972 printk(MPT2SAS_ERR_FMT
"doorbell is in use "
2973 " (line=%d)\n", ioc
->name
, __LINE__
);
2977 /* clear pending doorbell interrupts from previous state changes */
2978 if (readl(&ioc
->chip
->HostInterruptStatus
) &
2979 MPI2_HIS_IOC2SYS_DB_STATUS
)
2980 writel(0, &ioc
->chip
->HostInterruptStatus
);
2982 /* send message to ioc */
2983 writel(((MPI2_FUNCTION_HANDSHAKE
<<MPI2_DOORBELL_FUNCTION_SHIFT
) |
2984 ((request_bytes
/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT
)),
2985 &ioc
->chip
->Doorbell
);
2987 if ((_base_wait_for_doorbell_int(ioc
, 5, NO_SLEEP
))) {
2988 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
2989 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
2992 writel(0, &ioc
->chip
->HostInterruptStatus
);
2994 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
))) {
2995 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
2996 "ack failed (line=%d)\n", ioc
->name
, __LINE__
);
3000 /* send message 32-bits at a time */
3001 for (i
= 0, failed
= 0; i
< request_bytes
/4 && !failed
; i
++) {
3002 writel(cpu_to_le32(request
[i
]), &ioc
->chip
->Doorbell
);
3003 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
)))
3008 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3009 "sending request failed (line=%d)\n", ioc
->name
, __LINE__
);
3013 /* now wait for the reply */
3014 if ((_base_wait_for_doorbell_int(ioc
, timeout
, sleep_flag
))) {
3015 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3016 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3020 /* read the first two 16-bits, it gives the total length of the reply */
3021 reply
[0] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3022 & MPI2_DOORBELL_DATA_MASK
);
3023 writel(0, &ioc
->chip
->HostInterruptStatus
);
3024 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3025 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3026 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3029 reply
[1] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3030 & MPI2_DOORBELL_DATA_MASK
);
3031 writel(0, &ioc
->chip
->HostInterruptStatus
);
3033 for (i
= 2; i
< default_reply
->MsgLength
* 2; i
++) {
3034 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3035 printk(MPT2SAS_ERR_FMT
"doorbell "
3036 "handshake int failed (line=%d)\n", ioc
->name
,
3040 if (i
>= reply_bytes
/2) /* overflow case */
3041 dummy
= readl(&ioc
->chip
->Doorbell
);
3043 reply
[i
] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3044 & MPI2_DOORBELL_DATA_MASK
);
3045 writel(0, &ioc
->chip
->HostInterruptStatus
);
3048 _base_wait_for_doorbell_int(ioc
, 5, sleep_flag
);
3049 if (_base_wait_for_doorbell_not_used(ioc
, 5, sleep_flag
) != 0) {
3050 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"doorbell is in use "
3051 " (line=%d)\n", ioc
->name
, __LINE__
));
3053 writel(0, &ioc
->chip
->HostInterruptStatus
);
3055 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3056 mfp
= (__le32
*)reply
;
3057 printk(KERN_INFO
"\toffset:data\n");
3058 for (i
= 0; i
< reply_bytes
/4; i
++)
3059 printk(KERN_INFO
"\t[0x%02x]:%08x\n", i
*4,
3060 le32_to_cpu(mfp
[i
]));
3066 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3067 * @ioc: per adapter object
3068 * @mpi_reply: the reply payload from FW
3069 * @mpi_request: the request payload sent to FW
3071 * The SAS IO Unit Control Request message allows the host to perform low-level
3072 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3073 * to obtain the IOC assigned device handles for a device if it has other
3074 * identifying information about the device, in addition allows the host to
3075 * remove IOC resources associated with the device.
3077 * Returns 0 for success, non-zero for failure.
3080 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER
*ioc
,
3081 Mpi2SasIoUnitControlReply_t
*mpi_reply
,
3082 Mpi2SasIoUnitControlRequest_t
*mpi_request
)
3086 unsigned long timeleft
;
3090 u16 wait_state_count
;
3092 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3095 mutex_lock(&ioc
->base_cmds
.mutex
);
3097 if (ioc
->base_cmds
.status
!= MPT2_CMD_NOT_USED
) {
3098 printk(MPT2SAS_ERR_FMT
"%s: base_cmd in use\n",
3099 ioc
->name
, __func__
);
3104 wait_state_count
= 0;
3105 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3106 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3107 if (wait_state_count
++ == 10) {
3108 printk(MPT2SAS_ERR_FMT
3109 "%s: failed due to ioc not operational\n",
3110 ioc
->name
, __func__
);
3115 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3116 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
3117 "operational state(count=%d)\n", ioc
->name
,
3118 __func__
, wait_state_count
);
3121 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3123 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3124 ioc
->name
, __func__
);
3130 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3131 request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3132 ioc
->base_cmds
.smid
= smid
;
3133 memcpy(request
, mpi_request
, sizeof(Mpi2SasIoUnitControlRequest_t
));
3134 if (mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3135 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
)
3136 ioc
->ioc_link_reset_in_progress
= 1;
3137 mpt2sas_base_put_smid_default(ioc
, smid
);
3138 init_completion(&ioc
->base_cmds
.done
);
3139 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3140 msecs_to_jiffies(10000));
3141 if ((mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3142 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
) &&
3143 ioc
->ioc_link_reset_in_progress
)
3144 ioc
->ioc_link_reset_in_progress
= 0;
3145 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3146 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3147 ioc
->name
, __func__
);
3148 _debug_dump_mf(mpi_request
,
3149 sizeof(Mpi2SasIoUnitControlRequest_t
)/4);
3150 if (!(ioc
->base_cmds
.status
& MPT2_CMD_RESET
))
3152 goto issue_host_reset
;
3154 if (ioc
->base_cmds
.status
& MPT2_CMD_REPLY_VALID
)
3155 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3156 sizeof(Mpi2SasIoUnitControlReply_t
));
3158 memset(mpi_reply
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
3159 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3164 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3166 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3169 mutex_unlock(&ioc
->base_cmds
.mutex
);
3175 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3176 * @ioc: per adapter object
3177 * @mpi_reply: the reply payload from FW
3178 * @mpi_request: the request payload sent to FW
3180 * The SCSI Enclosure Processor request message causes the IOC to
3181 * communicate with SES devices to control LED status signals.
3183 * Returns 0 for success, non-zero for failure.
3186 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER
*ioc
,
3187 Mpi2SepReply_t
*mpi_reply
, Mpi2SepRequest_t
*mpi_request
)
3191 unsigned long timeleft
;
3195 u16 wait_state_count
;
3197 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3200 mutex_lock(&ioc
->base_cmds
.mutex
);
3202 if (ioc
->base_cmds
.status
!= MPT2_CMD_NOT_USED
) {
3203 printk(MPT2SAS_ERR_FMT
"%s: base_cmd in use\n",
3204 ioc
->name
, __func__
);
3209 wait_state_count
= 0;
3210 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3211 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3212 if (wait_state_count
++ == 10) {
3213 printk(MPT2SAS_ERR_FMT
3214 "%s: failed due to ioc not operational\n",
3215 ioc
->name
, __func__
);
3220 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3221 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
3222 "operational state(count=%d)\n", ioc
->name
,
3223 __func__
, wait_state_count
);
3226 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3228 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3229 ioc
->name
, __func__
);
3235 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3236 request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3237 ioc
->base_cmds
.smid
= smid
;
3238 memcpy(request
, mpi_request
, sizeof(Mpi2SepReply_t
));
3239 mpt2sas_base_put_smid_default(ioc
, smid
);
3240 init_completion(&ioc
->base_cmds
.done
);
3241 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3242 msecs_to_jiffies(10000));
3243 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3244 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3245 ioc
->name
, __func__
);
3246 _debug_dump_mf(mpi_request
,
3247 sizeof(Mpi2SepRequest_t
)/4);
3248 if (!(ioc
->base_cmds
.status
& MPT2_CMD_RESET
))
3250 goto issue_host_reset
;
3252 if (ioc
->base_cmds
.status
& MPT2_CMD_REPLY_VALID
)
3253 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3254 sizeof(Mpi2SepReply_t
));
3256 memset(mpi_reply
, 0, sizeof(Mpi2SepReply_t
));
3257 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3262 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3264 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3267 mutex_unlock(&ioc
->base_cmds
.mutex
);
3272 * _base_get_port_facts - obtain port facts reply and save in ioc
3273 * @ioc: per adapter object
3274 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3276 * Returns 0 for success, non-zero for failure.
3279 _base_get_port_facts(struct MPT2SAS_ADAPTER
*ioc
, int port
, int sleep_flag
)
3281 Mpi2PortFactsRequest_t mpi_request
;
3282 Mpi2PortFactsReply_t mpi_reply
;
3283 struct mpt2sas_port_facts
*pfacts
;
3284 int mpi_reply_sz
, mpi_request_sz
, r
;
3286 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3289 mpi_reply_sz
= sizeof(Mpi2PortFactsReply_t
);
3290 mpi_request_sz
= sizeof(Mpi2PortFactsRequest_t
);
3291 memset(&mpi_request
, 0, mpi_request_sz
);
3292 mpi_request
.Function
= MPI2_FUNCTION_PORT_FACTS
;
3293 mpi_request
.PortNumber
= port
;
3294 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3295 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3298 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3299 ioc
->name
, __func__
, r
);
3303 pfacts
= &ioc
->pfacts
[port
];
3304 memset(pfacts
, 0, sizeof(Mpi2PortFactsReply_t
));
3305 pfacts
->PortNumber
= mpi_reply
.PortNumber
;
3306 pfacts
->VP_ID
= mpi_reply
.VP_ID
;
3307 pfacts
->VF_ID
= mpi_reply
.VF_ID
;
3308 pfacts
->MaxPostedCmdBuffers
=
3309 le16_to_cpu(mpi_reply
.MaxPostedCmdBuffers
);
3315 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3316 * @ioc: per adapter object
3317 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3319 * Returns 0 for success, non-zero for failure.
3322 _base_get_ioc_facts(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3324 Mpi2IOCFactsRequest_t mpi_request
;
3325 Mpi2IOCFactsReply_t mpi_reply
;
3326 struct mpt2sas_facts
*facts
;
3327 int mpi_reply_sz
, mpi_request_sz
, r
;
3329 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3332 mpi_reply_sz
= sizeof(Mpi2IOCFactsReply_t
);
3333 mpi_request_sz
= sizeof(Mpi2IOCFactsRequest_t
);
3334 memset(&mpi_request
, 0, mpi_request_sz
);
3335 mpi_request
.Function
= MPI2_FUNCTION_IOC_FACTS
;
3336 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3337 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3340 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3341 ioc
->name
, __func__
, r
);
3345 facts
= &ioc
->facts
;
3346 memset(facts
, 0, sizeof(Mpi2IOCFactsReply_t
));
3347 facts
->MsgVersion
= le16_to_cpu(mpi_reply
.MsgVersion
);
3348 facts
->HeaderVersion
= le16_to_cpu(mpi_reply
.HeaderVersion
);
3349 facts
->VP_ID
= mpi_reply
.VP_ID
;
3350 facts
->VF_ID
= mpi_reply
.VF_ID
;
3351 facts
->IOCExceptions
= le16_to_cpu(mpi_reply
.IOCExceptions
);
3352 facts
->MaxChainDepth
= mpi_reply
.MaxChainDepth
;
3353 facts
->WhoInit
= mpi_reply
.WhoInit
;
3354 facts
->NumberOfPorts
= mpi_reply
.NumberOfPorts
;
3355 facts
->MaxMSIxVectors
= mpi_reply
.MaxMSIxVectors
;
3356 facts
->RequestCredit
= le16_to_cpu(mpi_reply
.RequestCredit
);
3357 facts
->MaxReplyDescriptorPostQueueDepth
=
3358 le16_to_cpu(mpi_reply
.MaxReplyDescriptorPostQueueDepth
);
3359 facts
->ProductID
= le16_to_cpu(mpi_reply
.ProductID
);
3360 facts
->IOCCapabilities
= le32_to_cpu(mpi_reply
.IOCCapabilities
);
3361 if ((facts
->IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
))
3362 ioc
->ir_firmware
= 1;
3363 facts
->FWVersion
.Word
= le32_to_cpu(mpi_reply
.FWVersion
.Word
);
3364 facts
->IOCRequestFrameSize
=
3365 le16_to_cpu(mpi_reply
.IOCRequestFrameSize
);
3366 facts
->MaxInitiators
= le16_to_cpu(mpi_reply
.MaxInitiators
);
3367 facts
->MaxTargets
= le16_to_cpu(mpi_reply
.MaxTargets
);
3368 ioc
->shost
->max_id
= -1;
3369 facts
->MaxSasExpanders
= le16_to_cpu(mpi_reply
.MaxSasExpanders
);
3370 facts
->MaxEnclosures
= le16_to_cpu(mpi_reply
.MaxEnclosures
);
3371 facts
->ProtocolFlags
= le16_to_cpu(mpi_reply
.ProtocolFlags
);
3372 facts
->HighPriorityCredit
=
3373 le16_to_cpu(mpi_reply
.HighPriorityCredit
);
3374 facts
->ReplyFrameSize
= mpi_reply
.ReplyFrameSize
;
3375 facts
->MaxDevHandle
= le16_to_cpu(mpi_reply
.MaxDevHandle
);
3377 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"hba queue depth(%d), "
3378 "max chains per io(%d)\n", ioc
->name
, facts
->RequestCredit
,
3379 facts
->MaxChainDepth
));
3380 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request frame size(%d), "
3381 "reply frame size(%d)\n", ioc
->name
,
3382 facts
->IOCRequestFrameSize
* 4, facts
->ReplyFrameSize
* 4));
3387 * _base_send_ioc_init - send ioc_init to firmware
3388 * @ioc: per adapter object
3389 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3391 * Returns 0 for success, non-zero for failure.
3394 _base_send_ioc_init(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3396 Mpi2IOCInitRequest_t mpi_request
;
3397 Mpi2IOCInitReply_t mpi_reply
;
3399 struct timeval current_time
;
3402 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3405 memset(&mpi_request
, 0, sizeof(Mpi2IOCInitRequest_t
));
3406 mpi_request
.Function
= MPI2_FUNCTION_IOC_INIT
;
3407 mpi_request
.WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
3408 mpi_request
.VF_ID
= 0; /* TODO */
3409 mpi_request
.VP_ID
= 0;
3410 mpi_request
.MsgVersion
= cpu_to_le16(MPI2_VERSION
);
3411 mpi_request
.HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
3413 if (_base_is_controller_msix_enabled(ioc
))
3414 mpi_request
.HostMSIxVectors
= ioc
->reply_queue_count
;
3415 mpi_request
.SystemRequestFrameSize
= cpu_to_le16(ioc
->request_sz
/4);
3416 mpi_request
.ReplyDescriptorPostQueueDepth
=
3417 cpu_to_le16(ioc
->reply_post_queue_depth
);
3418 mpi_request
.ReplyFreeQueueDepth
=
3419 cpu_to_le16(ioc
->reply_free_queue_depth
);
3421 mpi_request
.SenseBufferAddressHigh
=
3422 cpu_to_le32((u64
)ioc
->sense_dma
>> 32);
3423 mpi_request
.SystemReplyAddressHigh
=
3424 cpu_to_le32((u64
)ioc
->reply_dma
>> 32);
3425 mpi_request
.SystemRequestFrameBaseAddress
=
3426 cpu_to_le64((u64
)ioc
->request_dma
);
3427 mpi_request
.ReplyFreeQueueAddress
=
3428 cpu_to_le64((u64
)ioc
->reply_free_dma
);
3429 mpi_request
.ReplyDescriptorPostQueueAddress
=
3430 cpu_to_le64((u64
)ioc
->reply_post_free_dma
);
3433 /* This time stamp specifies number of milliseconds
3434 * since epoch ~ midnight January 1, 1970.
3436 do_gettimeofday(¤t_time
);
3437 mpi_request
.TimeStamp
= cpu_to_le64((u64
)current_time
.tv_sec
* 1000 +
3438 (current_time
.tv_usec
/ 1000));
3440 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3444 mfp
= (__le32
*)&mpi_request
;
3445 printk(KERN_INFO
"\toffset:data\n");
3446 for (i
= 0; i
< sizeof(Mpi2IOCInitRequest_t
)/4; i
++)
3447 printk(KERN_INFO
"\t[0x%02x]:%08x\n", i
*4,
3448 le32_to_cpu(mfp
[i
]));
3451 r
= _base_handshake_req_reply_wait(ioc
,
3452 sizeof(Mpi2IOCInitRequest_t
), (u32
*)&mpi_request
,
3453 sizeof(Mpi2IOCInitReply_t
), (u16
*)&mpi_reply
, 10,
3457 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3458 ioc
->name
, __func__
, r
);
3462 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3463 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
||
3464 mpi_reply
.IOCLogInfo
) {
3465 printk(MPT2SAS_ERR_FMT
"%s: failed\n", ioc
->name
, __func__
);
3473 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3474 * @ioc: per adapter object
3475 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3477 * Returns 0 for success, non-zero for failure.
3480 _base_send_port_enable(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3482 Mpi2PortEnableRequest_t
*mpi_request
;
3484 unsigned long timeleft
;
3488 printk(MPT2SAS_INFO_FMT
"sending port enable !!\n", ioc
->name
);
3490 if (ioc
->base_cmds
.status
& MPT2_CMD_PENDING
) {
3491 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3492 ioc
->name
, __func__
);
3496 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3498 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3499 ioc
->name
, __func__
);
3503 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3504 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3505 ioc
->base_cmds
.smid
= smid
;
3506 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3507 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3508 mpi_request
->VF_ID
= 0; /* TODO */
3509 mpi_request
->VP_ID
= 0;
3511 mpt2sas_base_put_smid_default(ioc
, smid
);
3512 init_completion(&ioc
->base_cmds
.done
);
3513 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3515 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3516 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3517 ioc
->name
, __func__
);
3518 _debug_dump_mf(mpi_request
,
3519 sizeof(Mpi2PortEnableRequest_t
)/4);
3520 if (ioc
->base_cmds
.status
& MPT2_CMD_RESET
)
3526 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: complete\n",
3527 ioc
->name
, __func__
));
3529 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_OPERATIONAL
,
3532 printk(MPT2SAS_ERR_FMT
"%s: failed going to operational state "
3533 " (ioc_state=0x%x)\n", ioc
->name
, __func__
, ioc_state
);
3537 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3538 printk(MPT2SAS_INFO_FMT
"port enable: %s\n",
3539 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
3544 * _base_unmask_events - turn on notification for this event
3545 * @ioc: per adapter object
3546 * @event: firmware event
3548 * The mask is stored in ioc->event_masks.
3551 _base_unmask_events(struct MPT2SAS_ADAPTER
*ioc
, u16 event
)
3558 desired_event
= (1 << (event
% 32));
3561 ioc
->event_masks
[0] &= ~desired_event
;
3562 else if (event
< 64)
3563 ioc
->event_masks
[1] &= ~desired_event
;
3564 else if (event
< 96)
3565 ioc
->event_masks
[2] &= ~desired_event
;
3566 else if (event
< 128)
3567 ioc
->event_masks
[3] &= ~desired_event
;
3571 * _base_event_notification - send event notification
3572 * @ioc: per adapter object
3573 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3575 * Returns 0 for success, non-zero for failure.
3578 _base_event_notification(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3580 Mpi2EventNotificationRequest_t
*mpi_request
;
3581 unsigned long timeleft
;
3586 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3589 if (ioc
->base_cmds
.status
& MPT2_CMD_PENDING
) {
3590 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3591 ioc
->name
, __func__
);
3595 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3597 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3598 ioc
->name
, __func__
);
3601 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3602 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3603 ioc
->base_cmds
.smid
= smid
;
3604 memset(mpi_request
, 0, sizeof(Mpi2EventNotificationRequest_t
));
3605 mpi_request
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3606 mpi_request
->VF_ID
= 0; /* TODO */
3607 mpi_request
->VP_ID
= 0;
3608 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
3609 mpi_request
->EventMasks
[i
] =
3610 cpu_to_le32(ioc
->event_masks
[i
]);
3611 mpt2sas_base_put_smid_default(ioc
, smid
);
3612 init_completion(&ioc
->base_cmds
.done
);
3613 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
, 30*HZ
);
3614 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3615 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3616 ioc
->name
, __func__
);
3617 _debug_dump_mf(mpi_request
,
3618 sizeof(Mpi2EventNotificationRequest_t
)/4);
3619 if (ioc
->base_cmds
.status
& MPT2_CMD_RESET
)
3624 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: complete\n",
3625 ioc
->name
, __func__
));
3626 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3631 * mpt2sas_base_validate_event_type - validating event types
3632 * @ioc: per adapter object
3633 * @event: firmware event
3635 * This will turn on firmware event notification when application
3636 * ask for that event. We don't mask events that are already enabled.
3639 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER
*ioc
, u32
*event_type
)
3642 u32 event_mask
, desired_event
;
3643 u8 send_update_to_fw
;
3645 for (i
= 0, send_update_to_fw
= 0; i
<
3646 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++) {
3647 event_mask
= ~event_type
[i
];
3649 for (j
= 0; j
< 32; j
++) {
3650 if (!(event_mask
& desired_event
) &&
3651 (ioc
->event_masks
[i
] & desired_event
)) {
3652 ioc
->event_masks
[i
] &= ~desired_event
;
3653 send_update_to_fw
= 1;
3655 desired_event
= (desired_event
<< 1);
3659 if (!send_update_to_fw
)
3662 mutex_lock(&ioc
->base_cmds
.mutex
);
3663 _base_event_notification(ioc
, CAN_SLEEP
);
3664 mutex_unlock(&ioc
->base_cmds
.mutex
);
3668 * _base_diag_reset - the "big hammer" start of day reset
3669 * @ioc: per adapter object
3670 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3672 * Returns 0 for success, non-zero for failure.
3675 _base_diag_reset(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3677 u32 host_diagnostic
;
3682 printk(MPT2SAS_INFO_FMT
"sending diag reset !!\n", ioc
->name
);
3683 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"clear interrupts\n",
3688 /* Write magic sequence to WriteSequence register
3689 * Loop until in diagnostic mode
3691 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"write magic "
3692 "sequence\n", ioc
->name
));
3693 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3694 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3695 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3696 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3697 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3698 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3699 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3702 if (sleep_flag
== CAN_SLEEP
)
3710 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
3711 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"wrote magic "
3712 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3713 ioc
->name
, count
, host_diagnostic
));
3715 } while ((host_diagnostic
& MPI2_DIAG_DIAG_WRITE_ENABLE
) == 0);
3717 hcb_size
= readl(&ioc
->chip
->HCBSize
);
3719 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"diag reset: issued\n",
3721 writel(host_diagnostic
| MPI2_DIAG_RESET_ADAPTER
,
3722 &ioc
->chip
->HostDiagnostic
);
3724 /* don't access any registers for 50 milliseconds */
3727 /* 300 second max wait */
3728 for (count
= 0; count
< 3000000 ; count
++) {
3730 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
3732 if (host_diagnostic
== 0xFFFFFFFF)
3734 if (!(host_diagnostic
& MPI2_DIAG_RESET_ADAPTER
))
3738 if (sleep_flag
== CAN_SLEEP
)
3744 if (host_diagnostic
& MPI2_DIAG_HCB_MODE
) {
3746 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"restart the adapter "
3747 "assuming the HCB Address points to good F/W\n",
3749 host_diagnostic
&= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK
;
3750 host_diagnostic
|= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW
;
3751 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
3753 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
3754 "re-enable the HCDW\n", ioc
->name
));
3755 writel(hcb_size
| MPI2_HCB_SIZE_HCB_ENABLE
,
3756 &ioc
->chip
->HCBSize
);
3759 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"restart the adapter\n",
3761 writel(host_diagnostic
& ~MPI2_DIAG_HOLD_IOC_RESET
,
3762 &ioc
->chip
->HostDiagnostic
);
3764 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"disable writes to the "
3765 "diagnostic register\n", ioc
->name
));
3766 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3768 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"Wait for FW to go to the "
3769 "READY state\n", ioc
->name
));
3770 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, 20,
3773 printk(MPT2SAS_ERR_FMT
"%s: failed going to ready state "
3774 " (ioc_state=0x%x)\n", ioc
->name
, __func__
, ioc_state
);
3778 printk(MPT2SAS_INFO_FMT
"diag reset: SUCCESS\n", ioc
->name
);
3782 printk(MPT2SAS_ERR_FMT
"diag reset: FAILED\n", ioc
->name
);
3787 * _base_make_ioc_ready - put controller in READY state
3788 * @ioc: per adapter object
3789 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3790 * @type: FORCE_BIG_HAMMER or SOFT_RESET
3792 * Returns 0 for success, non-zero for failure.
3795 _base_make_ioc_ready(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
,
3796 enum reset_type type
)
3801 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3804 if (ioc
->pci_error_recovery
)
3807 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
3808 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: ioc_state(0x%08x)\n",
3809 ioc
->name
, __func__
, ioc_state
));
3811 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
)
3814 if (ioc_state
& MPI2_DOORBELL_USED
) {
3815 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
3816 "active!\n", ioc
->name
));
3817 goto issue_diag_reset
;
3820 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
3821 mpt2sas_base_fault_info(ioc
, ioc_state
&
3822 MPI2_DOORBELL_DATA_MASK
);
3823 goto issue_diag_reset
;
3826 if (type
== FORCE_BIG_HAMMER
)
3827 goto issue_diag_reset
;
3829 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
3830 if (!(_base_send_ioc_reset(ioc
,
3831 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
, 15, CAN_SLEEP
))) {
3832 ioc
->ioc_reset_count
++;
3837 rc
= _base_diag_reset(ioc
, CAN_SLEEP
);
3838 ioc
->ioc_reset_count
++;
3843 * _base_make_ioc_operational - put controller in OPERATIONAL state
3844 * @ioc: per adapter object
3845 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3847 * Returns 0 for success, non-zero for failure.
3850 _base_make_ioc_operational(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3853 unsigned long flags
;
3856 struct _tr_list
*delayed_tr
, *delayed_tr_next
;
3858 struct adapter_reply_queue
*reply_q
;
3859 long reply_post_free
;
3860 u32 reply_post_free_sz
;
3862 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3865 /* clean the delayed target reset list */
3866 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
3867 &ioc
->delayed_tr_list
, list
) {
3868 list_del(&delayed_tr
->list
);
3872 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
3873 &ioc
->delayed_tr_volume_list
, list
) {
3874 list_del(&delayed_tr
->list
);
3878 /* initialize the scsi lookup free list */
3879 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
3880 INIT_LIST_HEAD(&ioc
->free_list
);
3882 for (i
= 0; i
< ioc
->scsiio_depth
; i
++, smid
++) {
3883 INIT_LIST_HEAD(&ioc
->scsi_lookup
[i
].chain_list
);
3884 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
3885 ioc
->scsi_lookup
[i
].smid
= smid
;
3886 ioc
->scsi_lookup
[i
].scmd
= NULL
;
3887 ioc
->scsi_lookup
[i
].direct_io
= 0;
3888 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
3892 /* hi-priority queue */
3893 INIT_LIST_HEAD(&ioc
->hpr_free_list
);
3894 smid
= ioc
->hi_priority_smid
;
3895 for (i
= 0; i
< ioc
->hi_priority_depth
; i
++, smid
++) {
3896 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
3897 ioc
->hpr_lookup
[i
].smid
= smid
;
3898 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
3899 &ioc
->hpr_free_list
);
3902 /* internal queue */
3903 INIT_LIST_HEAD(&ioc
->internal_free_list
);
3904 smid
= ioc
->internal_smid
;
3905 for (i
= 0; i
< ioc
->internal_depth
; i
++, smid
++) {
3906 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
3907 ioc
->internal_lookup
[i
].smid
= smid
;
3908 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
3909 &ioc
->internal_free_list
);
3913 INIT_LIST_HEAD(&ioc
->free_chain_list
);
3914 for (i
= 0; i
< ioc
->chain_depth
; i
++)
3915 list_add_tail(&ioc
->chain_lookup
[i
].tracker_list
,
3916 &ioc
->free_chain_list
);
3918 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
3920 /* initialize Reply Free Queue */
3921 for (i
= 0, reply_address
= (u32
)ioc
->reply_dma
;
3922 i
< ioc
->reply_free_queue_depth
; i
++, reply_address
+=
3924 ioc
->reply_free
[i
] = cpu_to_le32(reply_address
);
3926 /* initialize reply queues */
3927 _base_assign_reply_queues(ioc
);
3929 /* initialize Reply Post Free Queue */
3930 reply_post_free
= (long)ioc
->reply_post_free
;
3931 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
3932 sizeof(Mpi2DefaultReplyDescriptor_t
);
3933 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
3934 reply_q
->reply_post_host_index
= 0;
3935 reply_q
->reply_post_free
= (Mpi2ReplyDescriptorsUnion_t
*)
3937 for (i
= 0; i
< ioc
->reply_post_queue_depth
; i
++)
3938 reply_q
->reply_post_free
[i
].Words
=
3939 cpu_to_le64(ULLONG_MAX
);
3940 if (!_base_is_controller_msix_enabled(ioc
))
3941 goto skip_init_reply_post_free_queue
;
3942 reply_post_free
+= reply_post_free_sz
;
3944 skip_init_reply_post_free_queue
:
3946 r
= _base_send_ioc_init(ioc
, sleep_flag
);
3950 /* initialize reply free host index */
3951 ioc
->reply_free_host_index
= ioc
->reply_free_queue_depth
- 1;
3952 writel(ioc
->reply_free_host_index
, &ioc
->chip
->ReplyFreeHostIndex
);
3954 /* initialize reply post host index */
3955 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
3956 writel(reply_q
->msix_index
<< MPI2_RPHI_MSIX_INDEX_SHIFT
,
3957 &ioc
->chip
->ReplyPostHostIndex
);
3958 if (!_base_is_controller_msix_enabled(ioc
))
3959 goto skip_init_reply_post_host_index
;
3962 skip_init_reply_post_host_index
:
3964 _base_unmask_interrupts(ioc
);
3965 r
= _base_event_notification(ioc
, sleep_flag
);
3969 if (sleep_flag
== CAN_SLEEP
)
3970 _base_static_config_pages(ioc
);
3972 if (ioc
->wait_for_port_enable_to_complete
&& ioc
->is_warpdrive
) {
3973 if (ioc
->manu_pg10
.OEMIdentifier
== 0x80) {
3974 hide_flag
= (u8
) (ioc
->manu_pg10
.OEMSpecificFlags0
&
3975 MFG_PAGE10_HIDE_SSDS_MASK
);
3976 if (hide_flag
!= MFG_PAGE10_HIDE_SSDS_MASK
)
3977 ioc
->mfg_pg10_hide_flag
= hide_flag
;
3981 if (ioc
->wait_for_port_enable_to_complete
) {
3982 if (diag_buffer_enable
!= 0)
3983 mpt2sas_enable_diag_buffer(ioc
, diag_buffer_enable
);
3984 if (disable_discovery
> 0)
3988 r
= _base_send_port_enable(ioc
, sleep_flag
);
3996 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
3997 * @ioc: per adapter object
4002 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER
*ioc
)
4004 struct pci_dev
*pdev
= ioc
->pdev
;
4006 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4009 _base_mask_interrupts(ioc
);
4010 ioc
->shost_recovery
= 1;
4011 _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4012 ioc
->shost_recovery
= 0;
4013 _base_free_irq(ioc
);
4014 _base_disable_msix(ioc
);
4018 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
4019 pci_disable_pcie_error_reporting(pdev
);
4020 pci_disable_device(pdev
);
4025 * mpt2sas_base_attach - attach controller instance
4026 * @ioc: per adapter object
4028 * Returns 0 for success, non-zero for failure.
4031 mpt2sas_base_attach(struct MPT2SAS_ADAPTER
*ioc
)
4034 int cpu_id
, last_cpu_id
= 0;
4036 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4039 /* setup cpu_msix_table */
4040 ioc
->cpu_count
= num_online_cpus();
4041 for_each_online_cpu(cpu_id
)
4042 last_cpu_id
= cpu_id
;
4043 ioc
->cpu_msix_table_sz
= last_cpu_id
+ 1;
4044 ioc
->cpu_msix_table
= kzalloc(ioc
->cpu_msix_table_sz
, GFP_KERNEL
);
4045 ioc
->reply_queue_count
= 1;
4046 if (!ioc
->cpu_msix_table
) {
4047 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"allocation for "
4048 "cpu_msix_table failed!!!\n", ioc
->name
));
4050 goto out_free_resources
;
4053 if (ioc
->is_warpdrive
) {
4054 ioc
->reply_post_host_index
= kcalloc(ioc
->cpu_msix_table_sz
,
4055 sizeof(resource_size_t
*), GFP_KERNEL
);
4056 if (!ioc
->reply_post_host_index
) {
4057 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"allocation "
4058 "for cpu_msix_table failed!!!\n", ioc
->name
));
4060 goto out_free_resources
;
4064 r
= mpt2sas_base_map_resources(ioc
);
4068 if (ioc
->is_warpdrive
) {
4069 ioc
->reply_post_host_index
[0] =
4070 (resource_size_t
*)&ioc
->chip
->ReplyPostHostIndex
;
4072 for (i
= 1; i
< ioc
->cpu_msix_table_sz
; i
++)
4073 ioc
->reply_post_host_index
[i
] = (resource_size_t
*)
4074 ((u8
*)&ioc
->chip
->Doorbell
+ (0x4000 + ((i
- 1)
4078 pci_set_drvdata(ioc
->pdev
, ioc
->shost
);
4079 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
4081 goto out_free_resources
;
4083 r
= _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4085 goto out_free_resources
;
4087 ioc
->pfacts
= kcalloc(ioc
->facts
.NumberOfPorts
,
4088 sizeof(Mpi2PortFactsReply_t
), GFP_KERNEL
);
4091 goto out_free_resources
;
4094 for (i
= 0 ; i
< ioc
->facts
.NumberOfPorts
; i
++) {
4095 r
= _base_get_port_facts(ioc
, i
, CAN_SLEEP
);
4097 goto out_free_resources
;
4100 r
= _base_allocate_memory_pools(ioc
, CAN_SLEEP
);
4102 goto out_free_resources
;
4104 init_waitqueue_head(&ioc
->reset_wq
);
4106 /* allocate memory pd handle bitmask list */
4107 ioc
->pd_handles_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
4108 if (ioc
->facts
.MaxDevHandle
% 8)
4109 ioc
->pd_handles_sz
++;
4110 ioc
->pd_handles
= kzalloc(ioc
->pd_handles_sz
,
4112 if (!ioc
->pd_handles
) {
4114 goto out_free_resources
;
4117 ioc
->fwfault_debug
= mpt2sas_fwfault_debug
;
4119 /* base internal command bits */
4120 mutex_init(&ioc
->base_cmds
.mutex
);
4121 ioc
->base_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4122 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
4124 /* transport internal command bits */
4125 ioc
->transport_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4126 ioc
->transport_cmds
.status
= MPT2_CMD_NOT_USED
;
4127 mutex_init(&ioc
->transport_cmds
.mutex
);
4129 /* scsih internal command bits */
4130 ioc
->scsih_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4131 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
4132 mutex_init(&ioc
->scsih_cmds
.mutex
);
4134 /* task management internal command bits */
4135 ioc
->tm_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4136 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4137 mutex_init(&ioc
->tm_cmds
.mutex
);
4139 /* config page internal command bits */
4140 ioc
->config_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4141 ioc
->config_cmds
.status
= MPT2_CMD_NOT_USED
;
4142 mutex_init(&ioc
->config_cmds
.mutex
);
4144 /* ctl module internal command bits */
4145 ioc
->ctl_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4146 ioc
->ctl_cmds
.sense
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
4147 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
4148 mutex_init(&ioc
->ctl_cmds
.mutex
);
4150 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4151 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4152 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
||
4153 !ioc
->ctl_cmds
.sense
) {
4155 goto out_free_resources
;
4158 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4159 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4160 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
) {
4162 goto out_free_resources
;
4165 init_completion(&ioc
->shost_recovery_done
);
4167 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4168 ioc
->event_masks
[i
] = -1;
4170 /* here we enable the events we care about */
4171 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DISCOVERY
);
4172 _base_unmask_events(ioc
, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
);
4173 _base_unmask_events(ioc
, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
4174 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4175 _base_unmask_events(ioc
, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
);
4176 _base_unmask_events(ioc
, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
);
4177 _base_unmask_events(ioc
, MPI2_EVENT_IR_VOLUME
);
4178 _base_unmask_events(ioc
, MPI2_EVENT_IR_PHYSICAL_DISK
);
4179 _base_unmask_events(ioc
, MPI2_EVENT_IR_OPERATION_STATUS
);
4180 _base_unmask_events(ioc
, MPI2_EVENT_LOG_ENTRY_ADDED
);
4181 r
= _base_make_ioc_operational(ioc
, CAN_SLEEP
);
4183 goto out_free_resources
;
4185 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
4186 _base_update_missing_delay(ioc
, missing_delay
[0],
4189 mpt2sas_base_start_watchdog(ioc
);
4194 ioc
->remove_host
= 1;
4195 mpt2sas_base_free_resources(ioc
);
4196 _base_release_memory_pools(ioc
);
4197 pci_set_drvdata(ioc
->pdev
, NULL
);
4198 kfree(ioc
->cpu_msix_table
);
4199 if (ioc
->is_warpdrive
)
4200 kfree(ioc
->reply_post_host_index
);
4201 kfree(ioc
->pd_handles
);
4202 kfree(ioc
->tm_cmds
.reply
);
4203 kfree(ioc
->transport_cmds
.reply
);
4204 kfree(ioc
->scsih_cmds
.reply
);
4205 kfree(ioc
->config_cmds
.reply
);
4206 kfree(ioc
->base_cmds
.reply
);
4207 kfree(ioc
->ctl_cmds
.reply
);
4208 kfree(ioc
->ctl_cmds
.sense
);
4210 ioc
->ctl_cmds
.reply
= NULL
;
4211 ioc
->base_cmds
.reply
= NULL
;
4212 ioc
->tm_cmds
.reply
= NULL
;
4213 ioc
->scsih_cmds
.reply
= NULL
;
4214 ioc
->transport_cmds
.reply
= NULL
;
4215 ioc
->config_cmds
.reply
= NULL
;
4222 * mpt2sas_base_detach - remove controller instance
4223 * @ioc: per adapter object
4228 mpt2sas_base_detach(struct MPT2SAS_ADAPTER
*ioc
)
4231 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4234 mpt2sas_base_stop_watchdog(ioc
);
4235 mpt2sas_base_free_resources(ioc
);
4236 _base_release_memory_pools(ioc
);
4237 pci_set_drvdata(ioc
->pdev
, NULL
);
4238 kfree(ioc
->cpu_msix_table
);
4239 if (ioc
->is_warpdrive
)
4240 kfree(ioc
->reply_post_host_index
);
4241 kfree(ioc
->pd_handles
);
4243 kfree(ioc
->ctl_cmds
.reply
);
4244 kfree(ioc
->ctl_cmds
.sense
);
4245 kfree(ioc
->base_cmds
.reply
);
4246 kfree(ioc
->tm_cmds
.reply
);
4247 kfree(ioc
->transport_cmds
.reply
);
4248 kfree(ioc
->scsih_cmds
.reply
);
4249 kfree(ioc
->config_cmds
.reply
);
4253 * _base_reset_handler - reset callback handler (for base)
4254 * @ioc: per adapter object
4255 * @reset_phase: phase
4257 * The handler for doing any required cleanup or initialization.
4259 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4260 * MPT2_IOC_DONE_RESET
4265 _base_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
4267 mpt2sas_scsih_reset_handler(ioc
, reset_phase
);
4268 mpt2sas_ctl_reset_handler(ioc
, reset_phase
);
4269 switch (reset_phase
) {
4270 case MPT2_IOC_PRE_RESET
:
4271 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4272 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
4274 case MPT2_IOC_AFTER_RESET
:
4275 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4276 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
4277 if (ioc
->transport_cmds
.status
& MPT2_CMD_PENDING
) {
4278 ioc
->transport_cmds
.status
|= MPT2_CMD_RESET
;
4279 mpt2sas_base_free_smid(ioc
, ioc
->transport_cmds
.smid
);
4280 complete(&ioc
->transport_cmds
.done
);
4282 if (ioc
->base_cmds
.status
& MPT2_CMD_PENDING
) {
4283 ioc
->base_cmds
.status
|= MPT2_CMD_RESET
;
4284 mpt2sas_base_free_smid(ioc
, ioc
->base_cmds
.smid
);
4285 complete(&ioc
->base_cmds
.done
);
4287 if (ioc
->config_cmds
.status
& MPT2_CMD_PENDING
) {
4288 ioc
->config_cmds
.status
|= MPT2_CMD_RESET
;
4289 mpt2sas_base_free_smid(ioc
, ioc
->config_cmds
.smid
);
4290 ioc
->config_cmds
.smid
= USHRT_MAX
;
4291 complete(&ioc
->config_cmds
.done
);
4294 case MPT2_IOC_DONE_RESET
:
4295 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4296 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
4302 * _wait_for_commands_to_complete - reset controller
4303 * @ioc: Pointer to MPT_ADAPTER structure
4304 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4306 * This function waiting(3s) for all pending commands to complete
4307 * prior to putting controller in reset.
4310 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
4313 unsigned long flags
;
4316 ioc
->pending_io_count
= 0;
4317 if (sleep_flag
!= CAN_SLEEP
)
4320 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
4321 if ((ioc_state
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
)
4324 /* pending command count */
4325 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4326 for (i
= 0; i
< ioc
->scsiio_depth
; i
++)
4327 if (ioc
->scsi_lookup
[i
].cb_idx
!= 0xFF)
4328 ioc
->pending_io_count
++;
4329 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4331 if (!ioc
->pending_io_count
)
4334 /* wait for pending commands to complete */
4335 wait_event_timeout(ioc
->reset_wq
, ioc
->pending_io_count
== 0, 10 * HZ
);
4339 * mpt2sas_base_hard_reset_handler - reset controller
4340 * @ioc: Pointer to MPT_ADAPTER structure
4341 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4342 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4344 * Returns 0 for success, non-zero for failure.
4347 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
,
4348 enum reset_type type
)
4351 unsigned long flags
;
4352 u8 pe_complete
= ioc
->wait_for_port_enable_to_complete
;
4354 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
4357 if (ioc
->pci_error_recovery
) {
4358 printk(MPT2SAS_ERR_FMT
"%s: pci error recovery reset\n",
4359 ioc
->name
, __func__
);
4364 if (mpt2sas_fwfault_debug
)
4365 mpt2sas_halt_firmware(ioc
);
4367 /* TODO - What we really should be doing is pulling
4368 * out all the code associated with NO_SLEEP; its never used.
4369 * That is legacy code from mpt fusion driver, ported over.
4370 * I will leave this BUG_ON here for now till its been resolved.
4372 BUG_ON(sleep_flag
== NO_SLEEP
);
4374 /* wait for an active reset in progress to complete */
4375 if (!mutex_trylock(&ioc
->reset_in_progress_mutex
)) {
4378 } while (ioc
->shost_recovery
== 1);
4379 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit\n", ioc
->name
,
4381 return ioc
->ioc_reset_in_progress_status
;
4384 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4385 ioc
->shost_recovery
= 1;
4386 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4388 _base_reset_handler(ioc
, MPT2_IOC_PRE_RESET
);
4389 _wait_for_commands_to_complete(ioc
, sleep_flag
);
4390 _base_mask_interrupts(ioc
);
4391 r
= _base_make_ioc_ready(ioc
, sleep_flag
, type
);
4394 _base_reset_handler(ioc
, MPT2_IOC_AFTER_RESET
);
4396 /* If this hard reset is called while port enable is active, then
4397 * there is no reason to call make_ioc_operational
4403 r
= _base_make_ioc_operational(ioc
, sleep_flag
);
4405 _base_reset_handler(ioc
, MPT2_IOC_DONE_RESET
);
4407 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %s\n",
4408 ioc
->name
, __func__
, ((r
== 0) ? "SUCCESS" : "FAILED")));
4410 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4411 ioc
->ioc_reset_in_progress_status
= r
;
4412 ioc
->shost_recovery
= 0;
4413 complete(&ioc
->shost_recovery_done
);
4414 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4415 mutex_unlock(&ioc
->reset_in_progress_mutex
);
4417 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit\n", ioc
->name
,