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-2012 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h>
54 #include <linux/delay.h>
55 #include <linux/interrupt.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/sort.h>
59 #include <linux/time.h>
60 #include <linux/kthread.h>
61 #include <linux/aer.h>
63 #include "mpt2sas_base.h"
65 static MPT_CALLBACK mpt_callbacks
[MPT_MAX_CALLBACKS
];
67 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
69 #define MAX_HBA_QUEUE_DEPTH 30000
70 #define MAX_CHAIN_DEPTH 100000
71 static int max_queue_depth
= -1;
72 module_param(max_queue_depth
, int, 0);
73 MODULE_PARM_DESC(max_queue_depth
, " max controller queue depth ");
75 static int max_sgl_entries
= -1;
76 module_param(max_sgl_entries
, int, 0);
77 MODULE_PARM_DESC(max_sgl_entries
, " max sg entries ");
79 static int msix_disable
= -1;
80 module_param(msix_disable
, int, 0);
81 MODULE_PARM_DESC(msix_disable
, " disable msix routed interrupts (default=0)");
83 static int missing_delay
[2] = {-1, -1};
84 module_param_array(missing_delay
, int, NULL
, 0);
85 MODULE_PARM_DESC(missing_delay
, " device missing delay , io missing delay");
87 static int mpt2sas_fwfault_debug
;
88 MODULE_PARM_DESC(mpt2sas_fwfault_debug
, " enable detection of firmware fault "
89 "and halt firmware - (default=0)");
91 static int disable_discovery
= -1;
92 module_param(disable_discovery
, int, 0);
93 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
96 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
100 _scsih_set_fwfault_debug(const char *val
, struct kernel_param
*kp
)
102 int ret
= param_set_int(val
, kp
);
103 struct MPT2SAS_ADAPTER
*ioc
;
108 printk(KERN_INFO
"setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug
);
109 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
110 ioc
->fwfault_debug
= mpt2sas_fwfault_debug
;
114 module_param_call(mpt2sas_fwfault_debug
, _scsih_set_fwfault_debug
,
115 param_get_int
, &mpt2sas_fwfault_debug
, 0644);
118 * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc
119 * @arg: input argument, used to derive ioc
121 * Return 0 if controller is removed from pci subsystem.
122 * Return -1 for other case.
124 static int mpt2sas_remove_dead_ioc_func(void *arg
)
126 struct MPT2SAS_ADAPTER
*ioc
= (struct MPT2SAS_ADAPTER
*)arg
;
127 struct pci_dev
*pdev
;
135 pci_stop_and_remove_bus_device(pdev
);
141 * _base_fault_reset_work - workq handling ioc fault conditions
142 * @work: input argument, used to derive ioc
148 _base_fault_reset_work(struct work_struct
*work
)
150 struct MPT2SAS_ADAPTER
*ioc
=
151 container_of(work
, struct MPT2SAS_ADAPTER
, fault_reset_work
.work
);
155 struct task_struct
*p
;
157 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
158 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
160 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
162 doorbell
= mpt2sas_base_get_iocstate(ioc
, 0);
163 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_MASK
) {
164 printk(MPT2SAS_INFO_FMT
"%s : SAS host is non-operational !!!!\n",
165 ioc
->name
, __func__
);
167 /* It may be possible that EEH recovery can resolve some of
168 * pci bus failure issues rather removing the dead ioc function
169 * by considering controller is in a non-operational state. So
170 * here priority is given to the EEH recovery. If it doesn't
171 * not resolve this issue, mpt2sas driver will consider this
172 * controller to non-operational state and remove the dead ioc
175 if (ioc
->non_operational_loop
++ < 5) {
176 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
,
182 * Call _scsih_flush_pending_cmds callback so that we flush all
183 * pending commands back to OS. This call is required to aovid
184 * deadlock at block layer. Dead IOC will fail to do diag reset,
185 * and this call is safe since dead ioc will never return any
186 * command back from HW.
188 ioc
->schedule_dead_ioc_flush_running_cmds(ioc
);
190 * Set remove_host flag early since kernel thread will
191 * take some time to execute.
193 ioc
->remove_host
= 1;
194 /*Remove the Dead Host */
195 p
= kthread_run(mpt2sas_remove_dead_ioc_func
, ioc
,
196 "mpt2sas_dead_ioc_%d", ioc
->id
);
198 printk(MPT2SAS_ERR_FMT
199 "%s: Running mpt2sas_dead_ioc thread failed !!!!\n",
200 ioc
->name
, __func__
);
202 printk(MPT2SAS_ERR_FMT
203 "%s: Running mpt2sas_dead_ioc thread success !!!!\n",
204 ioc
->name
, __func__
);
207 return; /* don't rearm timer */
210 ioc
->non_operational_loop
= 0;
212 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
213 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
215 printk(MPT2SAS_WARN_FMT
"%s: hard reset: %s\n", ioc
->name
,
216 __func__
, (rc
== 0) ? "success" : "failed");
217 doorbell
= mpt2sas_base_get_iocstate(ioc
, 0);
218 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
219 mpt2sas_base_fault_info(ioc
, doorbell
&
220 MPI2_DOORBELL_DATA_MASK
);
223 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
225 if (ioc
->fault_reset_work_q
)
226 queue_delayed_work(ioc
->fault_reset_work_q
,
227 &ioc
->fault_reset_work
,
228 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
229 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
233 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
234 * @ioc: per adapter object
240 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER
*ioc
)
244 if (ioc
->fault_reset_work_q
)
247 /* initialize fault polling */
248 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, _base_fault_reset_work
);
249 snprintf(ioc
->fault_reset_work_q_name
,
250 sizeof(ioc
->fault_reset_work_q_name
), "poll_%d_status", ioc
->id
);
251 ioc
->fault_reset_work_q
=
252 create_singlethread_workqueue(ioc
->fault_reset_work_q_name
);
253 if (!ioc
->fault_reset_work_q
) {
254 printk(MPT2SAS_ERR_FMT
"%s: failed (line=%d)\n",
255 ioc
->name
, __func__
, __LINE__
);
258 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
259 if (ioc
->fault_reset_work_q
)
260 queue_delayed_work(ioc
->fault_reset_work_q
,
261 &ioc
->fault_reset_work
,
262 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
263 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
267 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
268 * @ioc: per adapter object
274 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER
*ioc
)
277 struct workqueue_struct
*wq
;
279 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
280 wq
= ioc
->fault_reset_work_q
;
281 ioc
->fault_reset_work_q
= NULL
;
282 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
284 if (!cancel_delayed_work(&ioc
->fault_reset_work
))
286 destroy_workqueue(wq
);
291 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
292 * @ioc: per adapter object
293 * @fault_code: fault code
298 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER
*ioc
, u16 fault_code
)
300 printk(MPT2SAS_ERR_FMT
"fault_state(0x%04x)!\n",
301 ioc
->name
, fault_code
);
305 * mpt2sas_halt_firmware - halt's mpt controller firmware
306 * @ioc: per adapter object
308 * For debugging timeout related issues. Writing 0xCOFFEE00
309 * to the doorbell register will halt controller firmware. With
310 * the purpose to stop both driver and firmware, the enduser can
311 * obtain a ring buffer from controller UART.
314 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER
*ioc
)
318 if (!ioc
->fwfault_debug
)
323 doorbell
= readl(&ioc
->chip
->Doorbell
);
324 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
325 mpt2sas_base_fault_info(ioc
, doorbell
);
327 writel(0xC0FFEE00, &ioc
->chip
->Doorbell
);
328 printk(MPT2SAS_ERR_FMT
"Firmware is halted due to command "
329 "timeout\n", ioc
->name
);
332 panic("panic in %s\n", __func__
);
335 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
337 * _base_sas_ioc_info - verbose translation of the ioc status
338 * @ioc: per adapter object
339 * @mpi_reply: reply mf payload returned from firmware
340 * @request_hdr: request mf
345 _base_sas_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, MPI2DefaultReply_t
*mpi_reply
,
346 MPI2RequestHeader_t
*request_hdr
)
348 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
352 char *func_str
= NULL
;
354 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
355 if (request_hdr
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
356 request_hdr
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
357 request_hdr
->Function
== MPI2_FUNCTION_EVENT_NOTIFICATION
)
360 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
363 switch (ioc_status
) {
365 /****************************************************************************
366 * Common IOCStatus values for all replies
367 ****************************************************************************/
369 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
370 desc
= "invalid function";
372 case MPI2_IOCSTATUS_BUSY
:
375 case MPI2_IOCSTATUS_INVALID_SGL
:
376 desc
= "invalid sgl";
378 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
379 desc
= "internal error";
381 case MPI2_IOCSTATUS_INVALID_VPID
:
382 desc
= "invalid vpid";
384 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
385 desc
= "insufficient resources";
387 case MPI2_IOCSTATUS_INVALID_FIELD
:
388 desc
= "invalid field";
390 case MPI2_IOCSTATUS_INVALID_STATE
:
391 desc
= "invalid state";
393 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED
:
394 desc
= "op state not supported";
397 /****************************************************************************
398 * Config IOCStatus values
399 ****************************************************************************/
401 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION
:
402 desc
= "config invalid action";
404 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE
:
405 desc
= "config invalid type";
407 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
:
408 desc
= "config invalid page";
410 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA
:
411 desc
= "config invalid data";
413 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS
:
414 desc
= "config no defaults";
416 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT
:
417 desc
= "config cant commit";
420 /****************************************************************************
422 ****************************************************************************/
424 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
425 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
426 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
427 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
428 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
429 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
430 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
431 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
432 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
433 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
434 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
435 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
438 /****************************************************************************
439 * For use by SCSI Initiator and SCSI Target end-to-end data protection
440 ****************************************************************************/
442 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
443 desc
= "eedp guard error";
445 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
446 desc
= "eedp ref tag error";
448 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
449 desc
= "eedp app tag error";
452 /****************************************************************************
454 ****************************************************************************/
456 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX
:
457 desc
= "target invalid io index";
459 case MPI2_IOCSTATUS_TARGET_ABORTED
:
460 desc
= "target aborted";
462 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
:
463 desc
= "target no conn retryable";
465 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION
:
466 desc
= "target no connection";
468 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
:
469 desc
= "target xfer count mismatch";
471 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
:
472 desc
= "target data offset error";
474 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
:
475 desc
= "target too much write data";
477 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT
:
478 desc
= "target iu too short";
480 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
:
481 desc
= "target ack nak timeout";
483 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED
:
484 desc
= "target nak received";
487 /****************************************************************************
488 * Serial Attached SCSI values
489 ****************************************************************************/
491 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED
:
492 desc
= "smp request failed";
494 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN
:
495 desc
= "smp data overrun";
498 /****************************************************************************
499 * Diagnostic Buffer Post / Diagnostic Release values
500 ****************************************************************************/
502 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
:
503 desc
= "diagnostic released";
512 switch (request_hdr
->Function
) {
513 case MPI2_FUNCTION_CONFIG
:
514 frame_sz
= sizeof(Mpi2ConfigRequest_t
) + ioc
->sge_size
;
515 func_str
= "config_page";
517 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
518 frame_sz
= sizeof(Mpi2SCSITaskManagementRequest_t
);
519 func_str
= "task_mgmt";
521 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
522 frame_sz
= sizeof(Mpi2SasIoUnitControlRequest_t
);
523 func_str
= "sas_iounit_ctl";
525 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
526 frame_sz
= sizeof(Mpi2SepRequest_t
);
527 func_str
= "enclosure";
529 case MPI2_FUNCTION_IOC_INIT
:
530 frame_sz
= sizeof(Mpi2IOCInitRequest_t
);
531 func_str
= "ioc_init";
533 case MPI2_FUNCTION_PORT_ENABLE
:
534 frame_sz
= sizeof(Mpi2PortEnableRequest_t
);
535 func_str
= "port_enable";
537 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
538 frame_sz
= sizeof(Mpi2SmpPassthroughRequest_t
) + ioc
->sge_size
;
539 func_str
= "smp_passthru";
543 func_str
= "unknown";
547 printk(MPT2SAS_WARN_FMT
"ioc_status: %s(0x%04x), request(0x%p),"
548 " (%s)\n", ioc
->name
, desc
, ioc_status
, request_hdr
, func_str
);
550 _debug_dump_mf(request_hdr
, frame_sz
/4);
554 * _base_display_event_data - verbose translation of firmware asyn events
555 * @ioc: per adapter object
556 * @mpi_reply: reply mf payload returned from firmware
561 _base_display_event_data(struct MPT2SAS_ADAPTER
*ioc
,
562 Mpi2EventNotificationReply_t
*mpi_reply
)
567 if (!(ioc
->logging_level
& MPT_DEBUG_EVENTS
))
570 event
= le16_to_cpu(mpi_reply
->Event
);
573 case MPI2_EVENT_LOG_DATA
:
576 case MPI2_EVENT_STATE_CHANGE
:
577 desc
= "Status Change";
579 case MPI2_EVENT_HARD_RESET_RECEIVED
:
580 desc
= "Hard Reset Received";
582 case MPI2_EVENT_EVENT_CHANGE
:
583 desc
= "Event Change";
585 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
586 desc
= "Device Status Change";
588 case MPI2_EVENT_IR_OPERATION_STATUS
:
589 if (!ioc
->hide_ir_msg
)
590 desc
= "IR Operation Status";
592 case MPI2_EVENT_SAS_DISCOVERY
:
594 Mpi2EventDataSasDiscovery_t
*event_data
=
595 (Mpi2EventDataSasDiscovery_t
*)mpi_reply
->EventData
;
596 printk(MPT2SAS_INFO_FMT
"Discovery: (%s)", ioc
->name
,
597 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
599 if (event_data
->DiscoveryStatus
)
600 printk("discovery_status(0x%08x)",
601 le32_to_cpu(event_data
->DiscoveryStatus
));
605 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
606 desc
= "SAS Broadcast Primitive";
608 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
609 desc
= "SAS Init Device Status Change";
611 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW
:
612 desc
= "SAS Init Table Overflow";
614 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
615 desc
= "SAS Topology Change List";
617 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
618 desc
= "SAS Enclosure Device Status Change";
620 case MPI2_EVENT_IR_VOLUME
:
621 if (!ioc
->hide_ir_msg
)
624 case MPI2_EVENT_IR_PHYSICAL_DISK
:
625 if (!ioc
->hide_ir_msg
)
626 desc
= "IR Physical Disk";
628 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
629 if (!ioc
->hide_ir_msg
)
630 desc
= "IR Configuration Change List";
632 case MPI2_EVENT_LOG_ENTRY_ADDED
:
633 if (!ioc
->hide_ir_msg
)
634 desc
= "Log Entry Added";
641 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, desc
);
646 * _base_sas_log_info - verbose translation of firmware log info
647 * @ioc: per adapter object
648 * @log_info: log info
653 _base_sas_log_info(struct MPT2SAS_ADAPTER
*ioc
, u32 log_info
)
664 union loginfo_type sas_loginfo
;
665 char *originator_str
= NULL
;
667 sas_loginfo
.loginfo
= log_info
;
668 if (sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/)
671 /* each nexus loss loginfo */
672 if (log_info
== 0x31170000)
675 /* eat the loginfos associated with task aborts */
676 if (ioc
->ignore_loginfos
&& (log_info
== 0x30050000 || log_info
==
677 0x31140000 || log_info
== 0x31130000))
680 switch (sas_loginfo
.dw
.originator
) {
682 originator_str
= "IOP";
685 originator_str
= "PL";
688 if (!ioc
->hide_ir_msg
)
689 originator_str
= "IR";
691 originator_str
= "WarpDrive";
695 printk(MPT2SAS_WARN_FMT
"log_info(0x%08x): originator(%s), "
696 "code(0x%02x), sub_code(0x%04x)\n", ioc
->name
, log_info
,
697 originator_str
, sas_loginfo
.dw
.code
,
698 sas_loginfo
.dw
.subcode
);
702 * _base_display_reply_info -
703 * @ioc: per adapter object
704 * @smid: system request message index
705 * @msix_index: MSIX table index supplied by the OS
706 * @reply: reply message frame(lower 32bit addr)
711 _base_display_reply_info(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
714 MPI2DefaultReply_t
*mpi_reply
;
717 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
718 if (unlikely(!mpi_reply
)) {
719 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
720 ioc
->name
, __FILE__
, __LINE__
, __func__
);
723 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
724 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
725 if ((ioc_status
& MPI2_IOCSTATUS_MASK
) &&
726 (ioc
->logging_level
& MPT_DEBUG_REPLY
)) {
727 _base_sas_ioc_info(ioc
, mpi_reply
,
728 mpt2sas_base_get_msg_frame(ioc
, smid
));
731 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
732 _base_sas_log_info(ioc
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
736 * mpt2sas_base_done - base internal command completion routine
737 * @ioc: per adapter object
738 * @smid: system request message index
739 * @msix_index: MSIX table index supplied by the OS
740 * @reply: reply message frame(lower 32bit addr)
742 * Return 1 meaning mf should be freed from _base_interrupt
743 * 0 means the mf is freed from this function.
746 mpt2sas_base_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
749 MPI2DefaultReply_t
*mpi_reply
;
751 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
752 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
755 if (ioc
->base_cmds
.status
== MPT2_CMD_NOT_USED
)
758 ioc
->base_cmds
.status
|= MPT2_CMD_COMPLETE
;
760 ioc
->base_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
761 memcpy(ioc
->base_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
763 ioc
->base_cmds
.status
&= ~MPT2_CMD_PENDING
;
765 complete(&ioc
->base_cmds
.done
);
770 * _base_async_event - main callback handler for firmware asyn events
771 * @ioc: per adapter object
772 * @msix_index: MSIX table index supplied by the OS
773 * @reply: reply message frame(lower 32bit addr)
775 * Return 1 meaning mf should be freed from _base_interrupt
776 * 0 means the mf is freed from this function.
779 _base_async_event(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
, u32 reply
)
781 Mpi2EventNotificationReply_t
*mpi_reply
;
782 Mpi2EventAckRequest_t
*ack_request
;
785 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
788 if (mpi_reply
->Function
!= MPI2_FUNCTION_EVENT_NOTIFICATION
)
790 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
791 _base_display_event_data(ioc
, mpi_reply
);
793 if (!(mpi_reply
->AckRequired
& MPI2_EVENT_NOTIFICATION_ACK_REQUIRED
))
795 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
797 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
798 ioc
->name
, __func__
);
802 ack_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
803 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
804 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
805 ack_request
->Event
= mpi_reply
->Event
;
806 ack_request
->EventContext
= mpi_reply
->EventContext
;
807 ack_request
->VF_ID
= 0; /* TODO */
808 ack_request
->VP_ID
= 0;
809 mpt2sas_base_put_smid_default(ioc
, smid
);
813 /* scsih callback handler */
814 mpt2sas_scsih_event_callback(ioc
, msix_index
, reply
);
816 /* ctl callback handler */
817 mpt2sas_ctl_event_callback(ioc
, msix_index
, reply
);
823 * _base_get_cb_idx - obtain the callback index
824 * @ioc: per adapter object
825 * @smid: system request message index
827 * Return callback index.
830 _base_get_cb_idx(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
835 if (smid
< ioc
->hi_priority_smid
) {
837 cb_idx
= ioc
->scsi_lookup
[i
].cb_idx
;
838 } else if (smid
< ioc
->internal_smid
) {
839 i
= smid
- ioc
->hi_priority_smid
;
840 cb_idx
= ioc
->hpr_lookup
[i
].cb_idx
;
841 } else if (smid
<= ioc
->hba_queue_depth
) {
842 i
= smid
- ioc
->internal_smid
;
843 cb_idx
= ioc
->internal_lookup
[i
].cb_idx
;
850 * _base_mask_interrupts - disable interrupts
851 * @ioc: per adapter object
853 * Disabling ResetIRQ, Reply and Doorbell Interrupts
858 _base_mask_interrupts(struct MPT2SAS_ADAPTER
*ioc
)
862 ioc
->mask_interrupts
= 1;
863 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
864 him_register
|= MPI2_HIM_DIM
+ MPI2_HIM_RIM
+ MPI2_HIM_RESET_IRQ_MASK
;
865 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
866 readl(&ioc
->chip
->HostInterruptMask
);
870 * _base_unmask_interrupts - enable interrupts
871 * @ioc: per adapter object
873 * Enabling only Reply Interrupts
878 _base_unmask_interrupts(struct MPT2SAS_ADAPTER
*ioc
)
882 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
883 him_register
&= ~MPI2_HIM_RIM
;
884 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
885 ioc
->mask_interrupts
= 0;
888 union reply_descriptor
{
897 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
898 * @irq: irq number (not used)
899 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
900 * @r: pt_regs pointer (not used)
902 * Return IRQ_HANDLE if processed, else IRQ_NONE.
905 _base_interrupt(int irq
, void *bus_id
)
907 struct adapter_reply_queue
*reply_q
= bus_id
;
908 union reply_descriptor rd
;
910 u8 request_desript_type
;
914 u8 msix_index
= reply_q
->msix_index
;
915 struct MPT2SAS_ADAPTER
*ioc
= reply_q
->ioc
;
916 Mpi2ReplyDescriptorsUnion_t
*rpf
;
919 if (ioc
->mask_interrupts
)
922 if (!atomic_add_unless(&reply_q
->busy
, 1, 1))
925 rpf
= &reply_q
->reply_post_free
[reply_q
->reply_post_host_index
];
926 request_desript_type
= rpf
->Default
.ReplyFlags
927 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
928 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
) {
929 atomic_dec(&reply_q
->busy
);
936 rd
.word
= le64_to_cpu(rpf
->Words
);
937 if (rd
.u
.low
== UINT_MAX
|| rd
.u
.high
== UINT_MAX
)
940 smid
= le16_to_cpu(rpf
->Default
.DescriptorTypeDependent1
);
941 if (request_desript_type
==
942 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY
) {
944 (rpf
->AddressReply
.ReplyFrameAddress
);
945 if (reply
> ioc
->reply_dma_max_address
||
946 reply
< ioc
->reply_dma_min_address
)
948 } else if (request_desript_type
==
949 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER
)
951 else if (request_desript_type
==
952 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS
)
955 cb_idx
= _base_get_cb_idx(ioc
, smid
);
956 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
))
957 && (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
958 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
961 _base_display_reply_info(ioc
, smid
,
964 mpt2sas_base_free_smid(ioc
, smid
);
968 _base_async_event(ioc
, msix_index
, reply
);
970 /* reply free queue handling */
972 ioc
->reply_free_host_index
=
973 (ioc
->reply_free_host_index
==
974 (ioc
->reply_free_queue_depth
- 1)) ?
975 0 : ioc
->reply_free_host_index
+ 1;
976 ioc
->reply_free
[ioc
->reply_free_host_index
] =
979 writel(ioc
->reply_free_host_index
,
980 &ioc
->chip
->ReplyFreeHostIndex
);
985 rpf
->Words
= cpu_to_le64(ULLONG_MAX
);
986 reply_q
->reply_post_host_index
=
987 (reply_q
->reply_post_host_index
==
988 (ioc
->reply_post_queue_depth
- 1)) ? 0 :
989 reply_q
->reply_post_host_index
+ 1;
990 request_desript_type
=
991 reply_q
->reply_post_free
[reply_q
->reply_post_host_index
].
992 Default
.ReplyFlags
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
994 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
996 if (!reply_q
->reply_post_host_index
)
997 rpf
= reply_q
->reply_post_free
;
1004 if (!completed_cmds
) {
1005 atomic_dec(&reply_q
->busy
);
1009 if (ioc
->is_warpdrive
) {
1010 writel(reply_q
->reply_post_host_index
,
1011 ioc
->reply_post_host_index
[msix_index
]);
1012 atomic_dec(&reply_q
->busy
);
1015 writel(reply_q
->reply_post_host_index
| (msix_index
<<
1016 MPI2_RPHI_MSIX_INDEX_SHIFT
), &ioc
->chip
->ReplyPostHostIndex
);
1017 atomic_dec(&reply_q
->busy
);
1022 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1023 * @ioc: per adapter object
1027 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER
*ioc
)
1029 return (ioc
->facts
.IOCCapabilities
&
1030 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
;
1034 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
1035 * @ioc: per adapter object
1036 * Context: ISR conext
1038 * Called when a Task Management request has completed. We want
1039 * to flush the other reply queues so all the outstanding IO has been
1040 * completed back to OS before we process the TM completetion.
1045 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER
*ioc
)
1047 struct adapter_reply_queue
*reply_q
;
1049 /* If MSIX capability is turned off
1050 * then multi-queues are not enabled
1052 if (!_base_is_controller_msix_enabled(ioc
))
1055 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1056 if (ioc
->shost_recovery
)
1058 /* TMs are on msix_index == 0 */
1059 if (reply_q
->msix_index
== 0)
1061 _base_interrupt(reply_q
->vector
, (void *)reply_q
);
1066 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
1067 * @cb_idx: callback index
1072 mpt2sas_base_release_callback_handler(u8 cb_idx
)
1074 mpt_callbacks
[cb_idx
] = NULL
;
1078 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1079 * @cb_func: callback function
1084 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func
)
1088 for (cb_idx
= MPT_MAX_CALLBACKS
-1; cb_idx
; cb_idx
--)
1089 if (mpt_callbacks
[cb_idx
] == NULL
)
1092 mpt_callbacks
[cb_idx
] = cb_func
;
1097 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1102 mpt2sas_base_initialize_callback_handler(void)
1106 for (cb_idx
= 0; cb_idx
< MPT_MAX_CALLBACKS
; cb_idx
++)
1107 mpt2sas_base_release_callback_handler(cb_idx
);
1111 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1112 * @ioc: per adapter object
1113 * @paddr: virtual address for SGE
1115 * Create a zero length scatter gather entry to insure the IOCs hardware has
1116 * something to use if the target device goes brain dead and tries
1117 * to send data even when none is asked for.
1122 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER
*ioc
, void *paddr
)
1124 u32 flags_length
= (u32
)((MPI2_SGE_FLAGS_LAST_ELEMENT
|
1125 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
|
1126 MPI2_SGE_FLAGS_SIMPLE_ELEMENT
) <<
1127 MPI2_SGE_FLAGS_SHIFT
);
1128 ioc
->base_add_sg_single(paddr
, flags_length
, -1);
1132 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1133 * @paddr: virtual address for SGE
1134 * @flags_length: SGE flags and data transfer length
1135 * @dma_addr: Physical address
1140 _base_add_sg_single_32(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1142 Mpi2SGESimple32_t
*sgel
= paddr
;
1144 flags_length
|= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING
|
1145 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1146 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1147 sgel
->Address
= cpu_to_le32(dma_addr
);
1152 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1153 * @paddr: virtual address for SGE
1154 * @flags_length: SGE flags and data transfer length
1155 * @dma_addr: Physical address
1160 _base_add_sg_single_64(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1162 Mpi2SGESimple64_t
*sgel
= paddr
;
1164 flags_length
|= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING
|
1165 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1166 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1167 sgel
->Address
= cpu_to_le64(dma_addr
);
1170 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1173 * _base_config_dma_addressing - set dma addressing
1174 * @ioc: per adapter object
1175 * @pdev: PCI device struct
1177 * Returns 0 for success, non-zero for failure.
1180 _base_config_dma_addressing(struct MPT2SAS_ADAPTER
*ioc
, struct pci_dev
*pdev
)
1185 if (sizeof(dma_addr_t
) > 4) {
1186 const uint64_t required_mask
=
1187 dma_get_required_mask(&pdev
->dev
);
1188 if ((required_mask
> DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev
,
1189 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev
,
1190 DMA_BIT_MASK(64))) {
1191 ioc
->base_add_sg_single
= &_base_add_sg_single_64
;
1192 ioc
->sge_size
= sizeof(Mpi2SGESimple64_t
);
1198 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1199 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1200 ioc
->base_add_sg_single
= &_base_add_sg_single_32
;
1201 ioc
->sge_size
= sizeof(Mpi2SGESimple32_t
);
1208 printk(MPT2SAS_INFO_FMT
"%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1209 "total mem (%ld kB)\n", ioc
->name
, desc
, convert_to_kb(s
.totalram
));
1215 * _base_check_enable_msix - checks MSIX capabable.
1216 * @ioc: per adapter object
1218 * Check to see if card is capable of MSIX, and set number
1219 * of available msix vectors
1222 _base_check_enable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1225 u16 message_control
;
1228 /* Check whether controller SAS2008 B0 controller,
1229 if it is SAS2008 B0 controller use IO-APIC instead of MSIX */
1230 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
&&
1231 ioc
->pdev
->revision
== 0x01) {
1235 base
= pci_find_capability(ioc
->pdev
, PCI_CAP_ID_MSIX
);
1237 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"msix not "
1238 "supported\n", ioc
->name
));
1242 /* get msix vector count */
1243 /* NUMA_IO not supported for older controllers */
1244 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2004
||
1245 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
||
1246 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_1
||
1247 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_2
||
1248 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_3
||
1249 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_1
||
1250 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_2
)
1251 ioc
->msix_vector_count
= 1;
1253 pci_read_config_word(ioc
->pdev
, base
+ 2, &message_control
);
1254 ioc
->msix_vector_count
= (message_control
& 0x3FF) + 1;
1256 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"msix is supported, "
1257 "vector_count(%d)\n", ioc
->name
, ioc
->msix_vector_count
));
1263 * _base_free_irq - free irq
1264 * @ioc: per adapter object
1266 * Freeing respective reply_queue from the list.
1269 _base_free_irq(struct MPT2SAS_ADAPTER
*ioc
)
1271 struct adapter_reply_queue
*reply_q
, *next
;
1273 if (list_empty(&ioc
->reply_queue_list
))
1276 list_for_each_entry_safe(reply_q
, next
, &ioc
->reply_queue_list
, list
) {
1277 list_del(&reply_q
->list
);
1278 synchronize_irq(reply_q
->vector
);
1279 free_irq(reply_q
->vector
, reply_q
);
1285 * _base_request_irq - request irq
1286 * @ioc: per adapter object
1287 * @index: msix index into vector table
1288 * @vector: irq vector
1290 * Inserting respective reply_queue into the list.
1293 _base_request_irq(struct MPT2SAS_ADAPTER
*ioc
, u8 index
, u32 vector
)
1295 struct adapter_reply_queue
*reply_q
;
1298 reply_q
= kzalloc(sizeof(struct adapter_reply_queue
), GFP_KERNEL
);
1300 printk(MPT2SAS_ERR_FMT
"unable to allocate memory %d!\n",
1301 ioc
->name
, (int)sizeof(struct adapter_reply_queue
));
1305 reply_q
->msix_index
= index
;
1306 reply_q
->vector
= vector
;
1307 atomic_set(&reply_q
->busy
, 0);
1308 if (ioc
->msix_enable
)
1309 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d-msix%d",
1310 MPT2SAS_DRIVER_NAME
, ioc
->id
, index
);
1312 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d",
1313 MPT2SAS_DRIVER_NAME
, ioc
->id
);
1314 r
= request_irq(vector
, _base_interrupt
, IRQF_SHARED
, reply_q
->name
,
1317 printk(MPT2SAS_ERR_FMT
"unable to allocate interrupt %d!\n",
1318 reply_q
->name
, vector
);
1323 INIT_LIST_HEAD(&reply_q
->list
);
1324 list_add_tail(&reply_q
->list
, &ioc
->reply_queue_list
);
1329 * _base_assign_reply_queues - assigning msix index for each cpu
1330 * @ioc: per adapter object
1332 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1334 * It would nice if we could call irq_set_affinity, however it is not
1335 * an exported symbol
1338 _base_assign_reply_queues(struct MPT2SAS_ADAPTER
*ioc
)
1340 struct adapter_reply_queue
*reply_q
;
1342 int cpu_grouping
, loop
, grouping
, grouping_mod
;
1344 if (!_base_is_controller_msix_enabled(ioc
))
1347 memset(ioc
->cpu_msix_table
, 0, ioc
->cpu_msix_table_sz
);
1348 /* when there are more cpus than available msix vectors,
1349 * then group cpus togeather on same irq
1351 if (ioc
->cpu_count
> ioc
->msix_vector_count
) {
1352 grouping
= ioc
->cpu_count
/ ioc
->msix_vector_count
;
1353 grouping_mod
= ioc
->cpu_count
% ioc
->msix_vector_count
;
1354 if (grouping
< 2 || (grouping
== 2 && !grouping_mod
))
1356 else if (grouping
< 4 || (grouping
== 4 && !grouping_mod
))
1358 else if (grouping
< 8 || (grouping
== 8 && !grouping_mod
))
1366 reply_q
= list_entry(ioc
->reply_queue_list
.next
,
1367 struct adapter_reply_queue
, list
);
1368 for_each_online_cpu(cpu_id
) {
1369 if (!cpu_grouping
) {
1370 ioc
->cpu_msix_table
[cpu_id
] = reply_q
->msix_index
;
1371 reply_q
= list_entry(reply_q
->list
.next
,
1372 struct adapter_reply_queue
, list
);
1374 if (loop
< cpu_grouping
) {
1375 ioc
->cpu_msix_table
[cpu_id
] =
1376 reply_q
->msix_index
;
1379 reply_q
= list_entry(reply_q
->list
.next
,
1380 struct adapter_reply_queue
, list
);
1381 ioc
->cpu_msix_table
[cpu_id
] =
1382 reply_q
->msix_index
;
1390 * _base_disable_msix - disables msix
1391 * @ioc: per adapter object
1395 _base_disable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1397 if (ioc
->msix_enable
) {
1398 pci_disable_msix(ioc
->pdev
);
1399 ioc
->msix_enable
= 0;
1404 * _base_enable_msix - enables msix, failback to io_apic
1405 * @ioc: per adapter object
1409 _base_enable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1411 struct msix_entry
*entries
, *a
;
1416 INIT_LIST_HEAD(&ioc
->reply_queue_list
);
1418 if (msix_disable
== -1 || msix_disable
== 0)
1424 if (_base_check_enable_msix(ioc
) != 0)
1427 ioc
->reply_queue_count
= min_t(int, ioc
->cpu_count
,
1428 ioc
->msix_vector_count
);
1430 entries
= kcalloc(ioc
->reply_queue_count
, sizeof(struct msix_entry
),
1433 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"kcalloc "
1434 "failed @ at %s:%d/%s() !!!\n", ioc
->name
, __FILE__
,
1435 __LINE__
, __func__
));
1439 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++)
1442 r
= pci_enable_msix(ioc
->pdev
, entries
, ioc
->reply_queue_count
);
1444 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"pci_enable_msix "
1445 "failed (r=%d) !!!\n", ioc
->name
, r
));
1450 ioc
->msix_enable
= 1;
1451 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++) {
1452 r
= _base_request_irq(ioc
, i
, a
->vector
);
1454 _base_free_irq(ioc
);
1455 _base_disable_msix(ioc
);
1464 /* failback to io_apic interrupt routing */
1467 r
= _base_request_irq(ioc
, 0, ioc
->pdev
->irq
);
1473 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1474 * @ioc: per adapter object
1476 * Returns 0 for success, non-zero for failure.
1479 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER
*ioc
)
1481 struct pci_dev
*pdev
= ioc
->pdev
;
1487 struct adapter_reply_queue
*reply_q
;
1489 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n",
1490 ioc
->name
, __func__
));
1492 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1493 if (pci_enable_device_mem(pdev
)) {
1494 printk(MPT2SAS_WARN_FMT
"pci_enable_device_mem: "
1495 "failed\n", ioc
->name
);
1500 if (pci_request_selected_regions(pdev
, ioc
->bars
,
1501 MPT2SAS_DRIVER_NAME
)) {
1502 printk(MPT2SAS_WARN_FMT
"pci_request_selected_regions: "
1503 "failed\n", ioc
->name
);
1508 /* AER (Advanced Error Reporting) hooks */
1509 pci_enable_pcie_error_reporting(pdev
);
1511 pci_set_master(pdev
);
1513 if (_base_config_dma_addressing(ioc
, pdev
) != 0) {
1514 printk(MPT2SAS_WARN_FMT
"no suitable DMA mask for %s\n",
1515 ioc
->name
, pci_name(pdev
));
1520 for (i
= 0, memap_sz
= 0, pio_sz
= 0 ; i
< DEVICE_COUNT_RESOURCE
; i
++) {
1521 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
1524 pio_chip
= (u64
)pci_resource_start(pdev
, i
);
1525 pio_sz
= pci_resource_len(pdev
, i
);
1529 /* verify memory resource is valid before using */
1530 if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
1531 ioc
->chip_phys
= pci_resource_start(pdev
, i
);
1532 chip_phys
= (u64
)ioc
->chip_phys
;
1533 memap_sz
= pci_resource_len(pdev
, i
);
1534 ioc
->chip
= ioremap(ioc
->chip_phys
, memap_sz
);
1535 if (ioc
->chip
== NULL
) {
1536 printk(MPT2SAS_ERR_FMT
"unable to map "
1537 "adapter memory!\n", ioc
->name
);
1545 _base_mask_interrupts(ioc
);
1546 r
= _base_enable_msix(ioc
);
1550 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
)
1551 printk(MPT2SAS_INFO_FMT
"%s: IRQ %d\n",
1552 reply_q
->name
, ((ioc
->msix_enable
) ? "PCI-MSI-X enabled" :
1553 "IO-APIC enabled"), reply_q
->vector
);
1555 printk(MPT2SAS_INFO_FMT
"iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1556 ioc
->name
, (unsigned long long)chip_phys
, ioc
->chip
, memap_sz
);
1557 printk(MPT2SAS_INFO_FMT
"ioport(0x%016llx), size(%d)\n",
1558 ioc
->name
, (unsigned long long)pio_chip
, pio_sz
);
1560 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1561 pci_save_state(pdev
);
1569 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
1570 pci_disable_pcie_error_reporting(pdev
);
1571 pci_disable_device(pdev
);
1576 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1577 * @ioc: per adapter object
1578 * @smid: system request message index(smid zero is invalid)
1580 * Returns virt pointer to message frame.
1583 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1585 return (void *)(ioc
->request
+ (smid
* ioc
->request_sz
));
1589 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1590 * @ioc: per adapter object
1591 * @smid: system request message index
1593 * Returns virt pointer to sense buffer.
1596 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1598 return (void *)(ioc
->sense
+ ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1602 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1603 * @ioc: per adapter object
1604 * @smid: system request message index
1606 * Returns phys pointer to the low 32bit address of the sense buffer.
1609 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1611 return cpu_to_le32(ioc
->sense_dma
+
1612 ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1616 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1617 * @ioc: per adapter object
1618 * @phys_addr: lower 32 physical addr of the reply
1620 * Converts 32bit lower physical addr into a virt address.
1623 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER
*ioc
, u32 phys_addr
)
1627 return ioc
->reply
+ (phys_addr
- (u32
)ioc
->reply_dma
);
1631 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1632 * @ioc: per adapter object
1633 * @cb_idx: callback index
1635 * Returns smid (zero is invalid)
1638 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
)
1640 unsigned long flags
;
1641 struct request_tracker
*request
;
1644 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1645 if (list_empty(&ioc
->internal_free_list
)) {
1646 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1647 printk(MPT2SAS_ERR_FMT
"%s: smid not available\n",
1648 ioc
->name
, __func__
);
1652 request
= list_entry(ioc
->internal_free_list
.next
,
1653 struct request_tracker
, tracker_list
);
1654 request
->cb_idx
= cb_idx
;
1655 smid
= request
->smid
;
1656 list_del(&request
->tracker_list
);
1657 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1662 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1663 * @ioc: per adapter object
1664 * @cb_idx: callback index
1665 * @scmd: pointer to scsi command object
1667 * Returns smid (zero is invalid)
1670 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
,
1671 struct scsi_cmnd
*scmd
)
1673 unsigned long flags
;
1674 struct scsiio_tracker
*request
;
1677 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1678 if (list_empty(&ioc
->free_list
)) {
1679 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1680 printk(MPT2SAS_ERR_FMT
"%s: smid not available\n",
1681 ioc
->name
, __func__
);
1685 request
= list_entry(ioc
->free_list
.next
,
1686 struct scsiio_tracker
, tracker_list
);
1687 request
->scmd
= scmd
;
1688 request
->cb_idx
= cb_idx
;
1689 smid
= request
->smid
;
1690 list_del(&request
->tracker_list
);
1691 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1696 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1697 * @ioc: per adapter object
1698 * @cb_idx: callback index
1700 * Returns smid (zero is invalid)
1703 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
)
1705 unsigned long flags
;
1706 struct request_tracker
*request
;
1709 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1710 if (list_empty(&ioc
->hpr_free_list
)) {
1711 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1715 request
= list_entry(ioc
->hpr_free_list
.next
,
1716 struct request_tracker
, tracker_list
);
1717 request
->cb_idx
= cb_idx
;
1718 smid
= request
->smid
;
1719 list_del(&request
->tracker_list
);
1720 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1726 * mpt2sas_base_free_smid - put smid back on free_list
1727 * @ioc: per adapter object
1728 * @smid: system request message index
1733 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1735 unsigned long flags
;
1737 struct chain_tracker
*chain_req
, *next
;
1739 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1740 if (smid
< ioc
->hi_priority_smid
) {
1743 if (!list_empty(&ioc
->scsi_lookup
[i
].chain_list
)) {
1744 list_for_each_entry_safe(chain_req
, next
,
1745 &ioc
->scsi_lookup
[i
].chain_list
, tracker_list
) {
1746 list_del_init(&chain_req
->tracker_list
);
1747 list_add_tail(&chain_req
->tracker_list
,
1748 &ioc
->free_chain_list
);
1751 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
1752 ioc
->scsi_lookup
[i
].scmd
= NULL
;
1753 ioc
->scsi_lookup
[i
].direct_io
= 0;
1754 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
1756 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1759 * See _wait_for_commands_to_complete() call with regards
1762 if (ioc
->shost_recovery
&& ioc
->pending_io_count
) {
1763 if (ioc
->pending_io_count
== 1)
1764 wake_up(&ioc
->reset_wq
);
1765 ioc
->pending_io_count
--;
1768 } else if (smid
< ioc
->internal_smid
) {
1770 i
= smid
- ioc
->hi_priority_smid
;
1771 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
1772 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
1773 &ioc
->hpr_free_list
);
1774 } else if (smid
<= ioc
->hba_queue_depth
) {
1775 /* internal queue */
1776 i
= smid
- ioc
->internal_smid
;
1777 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
1778 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
1779 &ioc
->internal_free_list
);
1781 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1785 * _base_writeq - 64 bit write to MMIO
1786 * @ioc: per adapter object
1788 * @addr: address in MMIO space
1789 * @writeq_lock: spin lock
1791 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1792 * care of 32 bit environment where its not quarenteed to send the entire word
1796 static inline void _base_writeq(__u64 b
, volatile void __iomem
*addr
,
1797 spinlock_t
*writeq_lock
)
1799 unsigned long flags
;
1800 __u64 data_out
= cpu_to_le64(b
);
1802 spin_lock_irqsave(writeq_lock
, flags
);
1803 writel((u32
)(data_out
), addr
);
1804 writel((u32
)(data_out
>> 32), (addr
+ 4));
1805 spin_unlock_irqrestore(writeq_lock
, flags
);
1808 static inline void _base_writeq(__u64 b
, volatile void __iomem
*addr
,
1809 spinlock_t
*writeq_lock
)
1811 writeq(cpu_to_le64(b
), addr
);
1816 _base_get_msix_index(struct MPT2SAS_ADAPTER
*ioc
)
1818 return ioc
->cpu_msix_table
[raw_smp_processor_id()];
1822 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1823 * @ioc: per adapter object
1824 * @smid: system request message index
1825 * @handle: device handle
1830 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u16 handle
)
1832 Mpi2RequestDescriptorUnion_t descriptor
;
1833 u64
*request
= (u64
*)&descriptor
;
1836 descriptor
.SCSIIO
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
1837 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
1838 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
1839 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
1840 descriptor
.SCSIIO
.LMID
= 0;
1841 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1842 &ioc
->scsi_lookup_lock
);
1847 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1848 * @ioc: per adapter object
1849 * @smid: system request message index
1854 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1856 Mpi2RequestDescriptorUnion_t descriptor
;
1857 u64
*request
= (u64
*)&descriptor
;
1859 descriptor
.HighPriority
.RequestFlags
=
1860 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
1861 descriptor
.HighPriority
.MSIxIndex
= 0;
1862 descriptor
.HighPriority
.SMID
= cpu_to_le16(smid
);
1863 descriptor
.HighPriority
.LMID
= 0;
1864 descriptor
.HighPriority
.Reserved1
= 0;
1865 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1866 &ioc
->scsi_lookup_lock
);
1870 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1871 * @ioc: per adapter object
1872 * @smid: system request message index
1877 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1879 Mpi2RequestDescriptorUnion_t descriptor
;
1880 u64
*request
= (u64
*)&descriptor
;
1882 descriptor
.Default
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
1883 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
1884 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
1885 descriptor
.Default
.LMID
= 0;
1886 descriptor
.Default
.DescriptorTypeDependent
= 0;
1887 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1888 &ioc
->scsi_lookup_lock
);
1892 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1893 * @ioc: per adapter object
1894 * @smid: system request message index
1895 * @io_index: value used to track the IO
1900 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
1903 Mpi2RequestDescriptorUnion_t descriptor
;
1904 u64
*request
= (u64
*)&descriptor
;
1906 descriptor
.SCSITarget
.RequestFlags
=
1907 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET
;
1908 descriptor
.SCSITarget
.MSIxIndex
= _base_get_msix_index(ioc
);
1909 descriptor
.SCSITarget
.SMID
= cpu_to_le16(smid
);
1910 descriptor
.SCSITarget
.LMID
= 0;
1911 descriptor
.SCSITarget
.IoIndex
= cpu_to_le16(io_index
);
1912 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1913 &ioc
->scsi_lookup_lock
);
1917 * _base_display_dell_branding - Disply branding string
1918 * @ioc: per adapter object
1923 _base_display_dell_branding(struct MPT2SAS_ADAPTER
*ioc
)
1925 char dell_branding
[MPT2SAS_DELL_BRANDING_SIZE
];
1927 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_DELL
)
1930 memset(dell_branding
, 0, MPT2SAS_DELL_BRANDING_SIZE
);
1931 switch (ioc
->pdev
->subsystem_device
) {
1932 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID
:
1933 strncpy(dell_branding
, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING
,
1934 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1936 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID
:
1937 strncpy(dell_branding
, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING
,
1938 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1940 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID
:
1941 strncpy(dell_branding
,
1942 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING
,
1943 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1945 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID
:
1946 strncpy(dell_branding
,
1947 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING
,
1948 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1950 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID
:
1951 strncpy(dell_branding
,
1952 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING
,
1953 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1955 case MPT2SAS_DELL_PERC_H200_SSDID
:
1956 strncpy(dell_branding
, MPT2SAS_DELL_PERC_H200_BRANDING
,
1957 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1959 case MPT2SAS_DELL_6GBPS_SAS_SSDID
:
1960 strncpy(dell_branding
, MPT2SAS_DELL_6GBPS_SAS_BRANDING
,
1961 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1964 sprintf(dell_branding
, "0x%4X", ioc
->pdev
->subsystem_device
);
1968 printk(MPT2SAS_INFO_FMT
"%s: Vendor(0x%04X), Device(0x%04X),"
1969 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc
->name
, dell_branding
,
1970 ioc
->pdev
->vendor
, ioc
->pdev
->device
, ioc
->pdev
->subsystem_vendor
,
1971 ioc
->pdev
->subsystem_device
);
1975 * _base_display_intel_branding - Display branding string
1976 * @ioc: per adapter object
1981 _base_display_intel_branding(struct MPT2SAS_ADAPTER
*ioc
)
1983 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
1986 switch (ioc
->pdev
->device
) {
1987 case MPI2_MFGPAGE_DEVID_SAS2008
:
1988 switch (ioc
->pdev
->subsystem_device
) {
1989 case MPT2SAS_INTEL_RMS2LL080_SSDID
:
1990 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1991 MPT2SAS_INTEL_RMS2LL080_BRANDING
);
1993 case MPT2SAS_INTEL_RMS2LL040_SSDID
:
1994 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1995 MPT2SAS_INTEL_RMS2LL040_BRANDING
);
1997 case MPT2SAS_INTEL_SSD910_SSDID
:
1998 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1999 MPT2SAS_INTEL_SSD910_BRANDING
);
2004 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
2005 switch (ioc
->pdev
->subsystem_device
) {
2006 case MPT2SAS_INTEL_RS25GB008_SSDID
:
2007 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2008 MPT2SAS_INTEL_RS25GB008_BRANDING
);
2010 case MPT2SAS_INTEL_RMS25JB080_SSDID
:
2011 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2012 MPT2SAS_INTEL_RMS25JB080_BRANDING
);
2014 case MPT2SAS_INTEL_RMS25JB040_SSDID
:
2015 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2016 MPT2SAS_INTEL_RMS25JB040_BRANDING
);
2018 case MPT2SAS_INTEL_RMS25KB080_SSDID
:
2019 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2020 MPT2SAS_INTEL_RMS25KB080_BRANDING
);
2022 case MPT2SAS_INTEL_RMS25KB040_SSDID
:
2023 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2024 MPT2SAS_INTEL_RMS25KB040_BRANDING
);
2026 case MPT2SAS_INTEL_RMS25LB040_SSDID
:
2027 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2028 MPT2SAS_INTEL_RMS25LB040_BRANDING
);
2030 case MPT2SAS_INTEL_RMS25LB080_SSDID
:
2031 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2032 MPT2SAS_INTEL_RMS25LB080_BRANDING
);
2043 * _base_display_hp_branding - Display branding string
2044 * @ioc: per adapter object
2049 _base_display_hp_branding(struct MPT2SAS_ADAPTER
*ioc
)
2051 if (ioc
->pdev
->subsystem_vendor
!= MPT2SAS_HP_3PAR_SSVID
)
2054 switch (ioc
->pdev
->device
) {
2055 case MPI2_MFGPAGE_DEVID_SAS2004
:
2056 switch (ioc
->pdev
->subsystem_device
) {
2057 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID
:
2058 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2059 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING
);
2064 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
2065 switch (ioc
->pdev
->subsystem_device
) {
2066 case MPT2SAS_HP_2_4_INTERNAL_SSDID
:
2067 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2068 MPT2SAS_HP_2_4_INTERNAL_BRANDING
);
2070 case MPT2SAS_HP_2_4_EXTERNAL_SSDID
:
2071 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2072 MPT2SAS_HP_2_4_EXTERNAL_BRANDING
);
2074 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID
:
2075 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2076 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING
);
2078 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID
:
2079 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2080 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING
);
2091 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2092 * @ioc: per adapter object
2097 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER
*ioc
)
2101 u32 iounit_pg1_flags
;
2104 bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2105 strncpy(desc
, ioc
->manu_pg0
.ChipName
, 16);
2106 printk(MPT2SAS_INFO_FMT
"%s: FWVersion(%02d.%02d.%02d.%02d), "
2107 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2109 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2110 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2111 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2112 ioc
->facts
.FWVersion
.Word
& 0x000000FF,
2113 ioc
->pdev
->revision
,
2114 (bios_version
& 0xFF000000) >> 24,
2115 (bios_version
& 0x00FF0000) >> 16,
2116 (bios_version
& 0x0000FF00) >> 8,
2117 bios_version
& 0x000000FF);
2119 _base_display_dell_branding(ioc
);
2120 _base_display_intel_branding(ioc
);
2121 _base_display_hp_branding(ioc
);
2123 printk(MPT2SAS_INFO_FMT
"Protocol=(", ioc
->name
);
2125 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
) {
2126 printk("Initiator");
2130 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET
) {
2131 printk("%sTarget", i
? "," : "");
2137 printk("Capabilities=(");
2139 if (!ioc
->hide_ir_msg
) {
2140 if (ioc
->facts
.IOCCapabilities
&
2141 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
) {
2147 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
) {
2148 printk("%sTLR", i
? "," : "");
2152 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_MULTICAST
) {
2153 printk("%sMulticast", i
? "," : "");
2157 if (ioc
->facts
.IOCCapabilities
&
2158 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET
) {
2159 printk("%sBIDI Target", i
? "," : "");
2163 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_EEDP
) {
2164 printk("%sEEDP", i
? "," : "");
2168 if (ioc
->facts
.IOCCapabilities
&
2169 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
) {
2170 printk("%sSnapshot Buffer", i
? "," : "");
2174 if (ioc
->facts
.IOCCapabilities
&
2175 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
) {
2176 printk("%sDiag Trace Buffer", i
? "," : "");
2180 if (ioc
->facts
.IOCCapabilities
&
2181 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
) {
2182 printk(KERN_INFO
"%sDiag Extended Buffer", i
? "," : "");
2186 if (ioc
->facts
.IOCCapabilities
&
2187 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
) {
2188 printk("%sTask Set Full", i
? "," : "");
2192 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2193 if (!(iounit_pg1_flags
& MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE
)) {
2194 printk("%sNCQ", i
? "," : "");
2202 * _base_update_missing_delay - change the missing delay timers
2203 * @ioc: per adapter object
2204 * @device_missing_delay: amount of time till device is reported missing
2205 * @io_missing_delay: interval IO is returned when there is a missing device
2209 * Passed on the command line, this function will modify the device missing
2210 * delay, as well as the io missing delay. This should be called at driver
2214 _base_update_missing_delay(struct MPT2SAS_ADAPTER
*ioc
,
2215 u16 device_missing_delay
, u8 io_missing_delay
)
2217 u16 dmd
, dmd_new
, dmd_orignal
;
2218 u8 io_missing_delay_original
;
2220 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
2221 Mpi2ConfigReply_t mpi_reply
;
2225 mpt2sas_config_get_number_hba_phys(ioc
, &num_phys
);
2229 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (num_phys
*
2230 sizeof(Mpi2SasIOUnit1PhyData_t
));
2231 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
2232 if (!sas_iounit_pg1
) {
2233 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2234 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2237 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
2238 sas_iounit_pg1
, sz
))) {
2239 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2240 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2243 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
2244 MPI2_IOCSTATUS_MASK
;
2245 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2246 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2247 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2251 /* device missing delay */
2252 dmd
= sas_iounit_pg1
->ReportDeviceMissingDelay
;
2253 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2254 dmd
= (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2256 dmd
= dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2258 if (device_missing_delay
> 0x7F) {
2259 dmd
= (device_missing_delay
> 0x7F0) ? 0x7F0 :
2260 device_missing_delay
;
2262 dmd
|= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
;
2264 dmd
= device_missing_delay
;
2265 sas_iounit_pg1
->ReportDeviceMissingDelay
= dmd
;
2267 /* io missing delay */
2268 io_missing_delay_original
= sas_iounit_pg1
->IODeviceMissingDelay
;
2269 sas_iounit_pg1
->IODeviceMissingDelay
= io_missing_delay
;
2271 if (!mpt2sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
2273 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2275 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2278 dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2279 printk(MPT2SAS_INFO_FMT
"device_missing_delay: old(%d), "
2280 "new(%d)\n", ioc
->name
, dmd_orignal
, dmd_new
);
2281 printk(MPT2SAS_INFO_FMT
"ioc_missing_delay: old(%d), "
2282 "new(%d)\n", ioc
->name
, io_missing_delay_original
,
2284 ioc
->device_missing_delay
= dmd_new
;
2285 ioc
->io_missing_delay
= io_missing_delay
;
2289 kfree(sas_iounit_pg1
);
2293 * _base_static_config_pages - static start of day config pages
2294 * @ioc: per adapter object
2299 _base_static_config_pages(struct MPT2SAS_ADAPTER
*ioc
)
2301 Mpi2ConfigReply_t mpi_reply
;
2302 u32 iounit_pg1_flags
;
2304 mpt2sas_config_get_manufacturing_pg0(ioc
, &mpi_reply
, &ioc
->manu_pg0
);
2305 if (ioc
->ir_firmware
)
2306 mpt2sas_config_get_manufacturing_pg10(ioc
, &mpi_reply
,
2308 mpt2sas_config_get_bios_pg2(ioc
, &mpi_reply
, &ioc
->bios_pg2
);
2309 mpt2sas_config_get_bios_pg3(ioc
, &mpi_reply
, &ioc
->bios_pg3
);
2310 mpt2sas_config_get_ioc_pg8(ioc
, &mpi_reply
, &ioc
->ioc_pg8
);
2311 mpt2sas_config_get_iounit_pg0(ioc
, &mpi_reply
, &ioc
->iounit_pg0
);
2312 mpt2sas_config_get_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2313 _base_display_ioc_capabilities(ioc
);
2316 * Enable task_set_full handling in iounit_pg1 when the
2317 * facts capabilities indicate that its supported.
2319 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2320 if ((ioc
->facts
.IOCCapabilities
&
2321 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
))
2323 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2326 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2327 ioc
->iounit_pg1
.Flags
= cpu_to_le32(iounit_pg1_flags
);
2328 mpt2sas_config_set_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2333 * _base_release_memory_pools - release memory
2334 * @ioc: per adapter object
2336 * Free memory allocated from _base_allocate_memory_pools.
2341 _base_release_memory_pools(struct MPT2SAS_ADAPTER
*ioc
)
2345 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2349 pci_free_consistent(ioc
->pdev
, ioc
->request_dma_sz
,
2350 ioc
->request
, ioc
->request_dma
);
2351 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request_pool(0x%p)"
2352 ": free\n", ioc
->name
, ioc
->request
));
2353 ioc
->request
= NULL
;
2357 pci_pool_free(ioc
->sense_dma_pool
, ioc
->sense
, ioc
->sense_dma
);
2358 if (ioc
->sense_dma_pool
)
2359 pci_pool_destroy(ioc
->sense_dma_pool
);
2360 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sense_pool(0x%p)"
2361 ": free\n", ioc
->name
, ioc
->sense
));
2366 pci_pool_free(ioc
->reply_dma_pool
, ioc
->reply
, ioc
->reply_dma
);
2367 if (ioc
->reply_dma_pool
)
2368 pci_pool_destroy(ioc
->reply_dma_pool
);
2369 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_pool(0x%p)"
2370 ": free\n", ioc
->name
, ioc
->reply
));
2374 if (ioc
->reply_free
) {
2375 pci_pool_free(ioc
->reply_free_dma_pool
, ioc
->reply_free
,
2376 ioc
->reply_free_dma
);
2377 if (ioc
->reply_free_dma_pool
)
2378 pci_pool_destroy(ioc
->reply_free_dma_pool
);
2379 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free_pool"
2380 "(0x%p): free\n", ioc
->name
, ioc
->reply_free
));
2381 ioc
->reply_free
= NULL
;
2384 if (ioc
->reply_post_free
) {
2385 pci_pool_free(ioc
->reply_post_free_dma_pool
,
2386 ioc
->reply_post_free
, ioc
->reply_post_free_dma
);
2387 if (ioc
->reply_post_free_dma_pool
)
2388 pci_pool_destroy(ioc
->reply_post_free_dma_pool
);
2389 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2390 "reply_post_free_pool(0x%p): free\n", ioc
->name
,
2391 ioc
->reply_post_free
));
2392 ioc
->reply_post_free
= NULL
;
2395 if (ioc
->config_page
) {
2396 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2397 "config_page(0x%p): free\n", ioc
->name
,
2399 pci_free_consistent(ioc
->pdev
, ioc
->config_page_sz
,
2400 ioc
->config_page
, ioc
->config_page_dma
);
2403 if (ioc
->scsi_lookup
) {
2404 free_pages((ulong
)ioc
->scsi_lookup
, ioc
->scsi_lookup_pages
);
2405 ioc
->scsi_lookup
= NULL
;
2407 kfree(ioc
->hpr_lookup
);
2408 kfree(ioc
->internal_lookup
);
2409 if (ioc
->chain_lookup
) {
2410 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2411 if (ioc
->chain_lookup
[i
].chain_buffer
)
2412 pci_pool_free(ioc
->chain_dma_pool
,
2413 ioc
->chain_lookup
[i
].chain_buffer
,
2414 ioc
->chain_lookup
[i
].chain_buffer_dma
);
2416 if (ioc
->chain_dma_pool
)
2417 pci_pool_destroy(ioc
->chain_dma_pool
);
2418 free_pages((ulong
)ioc
->chain_lookup
, ioc
->chain_pages
);
2419 ioc
->chain_lookup
= NULL
;
2425 * _base_allocate_memory_pools - allocate start of day memory pools
2426 * @ioc: per adapter object
2427 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2429 * Returns 0 success, anything else error
2432 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
2434 struct mpt2sas_facts
*facts
;
2435 u16 max_sge_elements
;
2436 u16 chains_needed_per_io
;
2437 u32 sz
, total_sz
, reply_post_free_sz
;
2439 u16 max_request_credit
;
2442 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2446 facts
= &ioc
->facts
;
2448 /* command line tunables for max sgl entries */
2449 if (max_sgl_entries
!= -1) {
2450 ioc
->shost
->sg_tablesize
= (max_sgl_entries
<
2451 MPT2SAS_SG_DEPTH
) ? max_sgl_entries
:
2454 ioc
->shost
->sg_tablesize
= MPT2SAS_SG_DEPTH
;
2457 /* command line tunables for max controller queue depth */
2458 if (max_queue_depth
!= -1 && max_queue_depth
!= 0) {
2459 max_request_credit
= min_t(u16
, max_queue_depth
+
2460 ioc
->hi_priority_depth
+ ioc
->internal_depth
,
2461 facts
->RequestCredit
);
2462 if (max_request_credit
> MAX_HBA_QUEUE_DEPTH
)
2463 max_request_credit
= MAX_HBA_QUEUE_DEPTH
;
2465 max_request_credit
= min_t(u16
, facts
->RequestCredit
,
2466 MAX_HBA_QUEUE_DEPTH
);
2468 ioc
->hba_queue_depth
= max_request_credit
;
2469 ioc
->hi_priority_depth
= facts
->HighPriorityCredit
;
2470 ioc
->internal_depth
= ioc
->hi_priority_depth
+ 5;
2472 /* request frame size */
2473 ioc
->request_sz
= facts
->IOCRequestFrameSize
* 4;
2475 /* reply frame size */
2476 ioc
->reply_sz
= facts
->ReplyFrameSize
* 4;
2480 /* calculate number of sg elements left over in the 1st frame */
2481 max_sge_elements
= ioc
->request_sz
- ((sizeof(Mpi2SCSIIORequest_t
) -
2482 sizeof(Mpi2SGEIOUnion_t
)) + ioc
->sge_size
);
2483 ioc
->max_sges_in_main_message
= max_sge_elements
/ioc
->sge_size
;
2485 /* now do the same for a chain buffer */
2486 max_sge_elements
= ioc
->request_sz
- ioc
->sge_size
;
2487 ioc
->max_sges_in_chain_message
= max_sge_elements
/ioc
->sge_size
;
2489 ioc
->chain_offset_value_for_main_message
=
2490 ((sizeof(Mpi2SCSIIORequest_t
) - sizeof(Mpi2SGEIOUnion_t
)) +
2491 (ioc
->max_sges_in_chain_message
* ioc
->sge_size
)) / 4;
2494 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2496 chains_needed_per_io
= ((ioc
->shost
->sg_tablesize
-
2497 ioc
->max_sges_in_main_message
)/ioc
->max_sges_in_chain_message
)
2499 if (chains_needed_per_io
> facts
->MaxChainDepth
) {
2500 chains_needed_per_io
= facts
->MaxChainDepth
;
2501 ioc
->shost
->sg_tablesize
= min_t(u16
,
2502 ioc
->max_sges_in_main_message
+ (ioc
->max_sges_in_chain_message
2503 * chains_needed_per_io
), ioc
->shost
->sg_tablesize
);
2505 ioc
->chains_needed_per_io
= chains_needed_per_io
;
2507 /* reply free queue sizing - taking into account for 64 FW events */
2508 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
2510 /* align the reply post queue on the next 16 count boundary */
2511 if (!ioc
->reply_free_queue_depth
% 16)
2512 ioc
->reply_post_queue_depth
= ioc
->reply_free_queue_depth
+ 16;
2514 ioc
->reply_post_queue_depth
= ioc
->reply_free_queue_depth
+
2515 32 - (ioc
->reply_free_queue_depth
% 16);
2516 if (ioc
->reply_post_queue_depth
>
2517 facts
->MaxReplyDescriptorPostQueueDepth
) {
2518 ioc
->reply_post_queue_depth
= min_t(u16
,
2519 (facts
->MaxReplyDescriptorPostQueueDepth
-
2520 (facts
->MaxReplyDescriptorPostQueueDepth
% 16)),
2521 (ioc
->hba_queue_depth
- (ioc
->hba_queue_depth
% 16)));
2522 ioc
->reply_free_queue_depth
= ioc
->reply_post_queue_depth
- 16;
2523 ioc
->hba_queue_depth
= ioc
->reply_free_queue_depth
- 64;
2527 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scatter gather: "
2528 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2529 "chains_per_io(%d)\n", ioc
->name
, ioc
->max_sges_in_main_message
,
2530 ioc
->max_sges_in_chain_message
, ioc
->shost
->sg_tablesize
,
2531 ioc
->chains_needed_per_io
));
2533 ioc
->scsiio_depth
= ioc
->hba_queue_depth
-
2534 ioc
->hi_priority_depth
- ioc
->internal_depth
;
2536 /* set the scsi host can_queue depth
2537 * with some internal commands that could be outstanding
2539 ioc
->shost
->can_queue
= ioc
->scsiio_depth
;
2540 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scsi host: "
2541 "can_queue depth (%d)\n", ioc
->name
, ioc
->shost
->can_queue
));
2543 /* contiguous pool for request and chains, 16 byte align, one extra "
2546 ioc
->chain_depth
= ioc
->chains_needed_per_io
* ioc
->scsiio_depth
;
2547 sz
= ((ioc
->scsiio_depth
+ 1) * ioc
->request_sz
);
2549 /* hi-priority queue */
2550 sz
+= (ioc
->hi_priority_depth
* ioc
->request_sz
);
2552 /* internal queue */
2553 sz
+= (ioc
->internal_depth
* ioc
->request_sz
);
2555 ioc
->request_dma_sz
= sz
;
2556 ioc
->request
= pci_alloc_consistent(ioc
->pdev
, sz
, &ioc
->request_dma
);
2557 if (!ioc
->request
) {
2558 printk(MPT2SAS_ERR_FMT
"request pool: pci_alloc_consistent "
2559 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2560 "total(%d kB)\n", ioc
->name
, ioc
->hba_queue_depth
,
2561 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2562 if (ioc
->scsiio_depth
< MPT2SAS_SAS_QUEUE_DEPTH
)
2565 ioc
->hba_queue_depth
= max_request_credit
- retry_sz
;
2566 goto retry_allocation
;
2570 printk(MPT2SAS_ERR_FMT
"request pool: pci_alloc_consistent "
2571 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2572 "total(%d kb)\n", ioc
->name
, ioc
->hba_queue_depth
,
2573 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2576 /* hi-priority queue */
2577 ioc
->hi_priority
= ioc
->request
+ ((ioc
->scsiio_depth
+ 1) *
2579 ioc
->hi_priority_dma
= ioc
->request_dma
+ ((ioc
->scsiio_depth
+ 1) *
2582 /* internal queue */
2583 ioc
->internal
= ioc
->hi_priority
+ (ioc
->hi_priority_depth
*
2585 ioc
->internal_dma
= ioc
->hi_priority_dma
+ (ioc
->hi_priority_depth
*
2589 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request pool(0x%p): "
2590 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
,
2591 ioc
->request
, ioc
->hba_queue_depth
, ioc
->request_sz
,
2592 (ioc
->hba_queue_depth
* ioc
->request_sz
)/1024));
2593 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request pool: dma(0x%llx)\n",
2594 ioc
->name
, (unsigned long long) ioc
->request_dma
));
2597 sz
= ioc
->scsiio_depth
* sizeof(struct scsiio_tracker
);
2598 ioc
->scsi_lookup_pages
= get_order(sz
);
2599 ioc
->scsi_lookup
= (struct scsiio_tracker
*)__get_free_pages(
2600 GFP_KERNEL
, ioc
->scsi_lookup_pages
);
2601 if (!ioc
->scsi_lookup
) {
2602 printk(MPT2SAS_ERR_FMT
"scsi_lookup: get_free_pages failed, "
2603 "sz(%d)\n", ioc
->name
, (int)sz
);
2607 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scsiio(0x%p): "
2608 "depth(%d)\n", ioc
->name
, ioc
->request
,
2609 ioc
->scsiio_depth
));
2611 ioc
->chain_depth
= min_t(u32
, ioc
->chain_depth
, MAX_CHAIN_DEPTH
);
2612 sz
= ioc
->chain_depth
* sizeof(struct chain_tracker
);
2613 ioc
->chain_pages
= get_order(sz
);
2615 ioc
->chain_lookup
= (struct chain_tracker
*)__get_free_pages(
2616 GFP_KERNEL
, ioc
->chain_pages
);
2617 if (!ioc
->chain_lookup
) {
2618 printk(MPT2SAS_ERR_FMT
"chain_lookup: get_free_pages failed, "
2619 "sz(%d)\n", ioc
->name
, (int)sz
);
2622 ioc
->chain_dma_pool
= pci_pool_create("chain pool", ioc
->pdev
,
2623 ioc
->request_sz
, 16, 0);
2624 if (!ioc
->chain_dma_pool
) {
2625 printk(MPT2SAS_ERR_FMT
"chain_dma_pool: pci_pool_create "
2626 "failed\n", ioc
->name
);
2629 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2630 ioc
->chain_lookup
[i
].chain_buffer
= pci_pool_alloc(
2631 ioc
->chain_dma_pool
, GFP_KERNEL
,
2632 &ioc
->chain_lookup
[i
].chain_buffer_dma
);
2633 if (!ioc
->chain_lookup
[i
].chain_buffer
) {
2634 ioc
->chain_depth
= i
;
2637 total_sz
+= ioc
->request_sz
;
2640 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"chain pool depth"
2641 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
,
2642 ioc
->chain_depth
, ioc
->request_sz
, ((ioc
->chain_depth
*
2643 ioc
->request_sz
))/1024));
2645 /* initialize hi-priority queue smid's */
2646 ioc
->hpr_lookup
= kcalloc(ioc
->hi_priority_depth
,
2647 sizeof(struct request_tracker
), GFP_KERNEL
);
2648 if (!ioc
->hpr_lookup
) {
2649 printk(MPT2SAS_ERR_FMT
"hpr_lookup: kcalloc failed\n",
2653 ioc
->hi_priority_smid
= ioc
->scsiio_depth
+ 1;
2654 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"hi_priority(0x%p): "
2655 "depth(%d), start smid(%d)\n", ioc
->name
, ioc
->hi_priority
,
2656 ioc
->hi_priority_depth
, ioc
->hi_priority_smid
));
2658 /* initialize internal queue smid's */
2659 ioc
->internal_lookup
= kcalloc(ioc
->internal_depth
,
2660 sizeof(struct request_tracker
), GFP_KERNEL
);
2661 if (!ioc
->internal_lookup
) {
2662 printk(MPT2SAS_ERR_FMT
"internal_lookup: kcalloc failed\n",
2666 ioc
->internal_smid
= ioc
->hi_priority_smid
+ ioc
->hi_priority_depth
;
2667 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"internal(0x%p): "
2668 "depth(%d), start smid(%d)\n", ioc
->name
, ioc
->internal
,
2669 ioc
->internal_depth
, ioc
->internal_smid
));
2671 /* sense buffers, 4 byte align */
2672 sz
= ioc
->scsiio_depth
* SCSI_SENSE_BUFFERSIZE
;
2673 ioc
->sense_dma_pool
= pci_pool_create("sense pool", ioc
->pdev
, sz
, 4,
2675 if (!ioc
->sense_dma_pool
) {
2676 printk(MPT2SAS_ERR_FMT
"sense pool: pci_pool_create failed\n",
2680 ioc
->sense
= pci_pool_alloc(ioc
->sense_dma_pool
, GFP_KERNEL
,
2683 printk(MPT2SAS_ERR_FMT
"sense pool: pci_pool_alloc failed\n",
2687 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2688 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2689 "(%d kB)\n", ioc
->name
, ioc
->sense
, ioc
->scsiio_depth
,
2690 SCSI_SENSE_BUFFERSIZE
, sz
/1024));
2691 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sense_dma(0x%llx)\n",
2692 ioc
->name
, (unsigned long long)ioc
->sense_dma
));
2695 /* reply pool, 4 byte align */
2696 sz
= ioc
->reply_free_queue_depth
* ioc
->reply_sz
;
2697 ioc
->reply_dma_pool
= pci_pool_create("reply pool", ioc
->pdev
, sz
, 4,
2699 if (!ioc
->reply_dma_pool
) {
2700 printk(MPT2SAS_ERR_FMT
"reply pool: pci_pool_create failed\n",
2704 ioc
->reply
= pci_pool_alloc(ioc
->reply_dma_pool
, GFP_KERNEL
,
2707 printk(MPT2SAS_ERR_FMT
"reply pool: pci_pool_alloc failed\n",
2711 ioc
->reply_dma_min_address
= (u32
)(ioc
->reply_dma
);
2712 ioc
->reply_dma_max_address
= (u32
)(ioc
->reply_dma
) + sz
;
2713 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply pool(0x%p): depth"
2714 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
, ioc
->reply
,
2715 ioc
->reply_free_queue_depth
, ioc
->reply_sz
, sz
/1024));
2716 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_dma(0x%llx)\n",
2717 ioc
->name
, (unsigned long long)ioc
->reply_dma
));
2720 /* reply free queue, 16 byte align */
2721 sz
= ioc
->reply_free_queue_depth
* 4;
2722 ioc
->reply_free_dma_pool
= pci_pool_create("reply_free pool",
2723 ioc
->pdev
, sz
, 16, 0);
2724 if (!ioc
->reply_free_dma_pool
) {
2725 printk(MPT2SAS_ERR_FMT
"reply_free pool: pci_pool_create "
2726 "failed\n", ioc
->name
);
2729 ioc
->reply_free
= pci_pool_alloc(ioc
->reply_free_dma_pool
, GFP_KERNEL
,
2730 &ioc
->reply_free_dma
);
2731 if (!ioc
->reply_free
) {
2732 printk(MPT2SAS_ERR_FMT
"reply_free pool: pci_pool_alloc "
2733 "failed\n", ioc
->name
);
2736 memset(ioc
->reply_free
, 0, sz
);
2737 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free pool(0x%p): "
2738 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc
->name
,
2739 ioc
->reply_free
, ioc
->reply_free_queue_depth
, 4, sz
/1024));
2740 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free_dma"
2741 "(0x%llx)\n", ioc
->name
, (unsigned long long)ioc
->reply_free_dma
));
2744 /* reply post queue, 16 byte align */
2745 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
2746 sizeof(Mpi2DefaultReplyDescriptor_t
);
2747 if (_base_is_controller_msix_enabled(ioc
))
2748 sz
= reply_post_free_sz
* ioc
->reply_queue_count
;
2750 sz
= reply_post_free_sz
;
2751 ioc
->reply_post_free_dma_pool
= pci_pool_create("reply_post_free pool",
2752 ioc
->pdev
, sz
, 16, 0);
2753 if (!ioc
->reply_post_free_dma_pool
) {
2754 printk(MPT2SAS_ERR_FMT
"reply_post_free pool: pci_pool_create "
2755 "failed\n", ioc
->name
);
2758 ioc
->reply_post_free
= pci_pool_alloc(ioc
->reply_post_free_dma_pool
,
2759 GFP_KERNEL
, &ioc
->reply_post_free_dma
);
2760 if (!ioc
->reply_post_free
) {
2761 printk(MPT2SAS_ERR_FMT
"reply_post_free pool: pci_pool_alloc "
2762 "failed\n", ioc
->name
);
2765 memset(ioc
->reply_post_free
, 0, sz
);
2766 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply post free pool"
2767 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2768 ioc
->name
, ioc
->reply_post_free
, ioc
->reply_post_queue_depth
, 8,
2770 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_post_free_dma = "
2771 "(0x%llx)\n", ioc
->name
, (unsigned long long)
2772 ioc
->reply_post_free_dma
));
2775 ioc
->config_page_sz
= 512;
2776 ioc
->config_page
= pci_alloc_consistent(ioc
->pdev
,
2777 ioc
->config_page_sz
, &ioc
->config_page_dma
);
2778 if (!ioc
->config_page
) {
2779 printk(MPT2SAS_ERR_FMT
"config page: pci_pool_alloc "
2780 "failed\n", ioc
->name
);
2783 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"config page(0x%p): size"
2784 "(%d)\n", ioc
->name
, ioc
->config_page
, ioc
->config_page_sz
));
2785 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"config_page_dma"
2786 "(0x%llx)\n", ioc
->name
, (unsigned long long)ioc
->config_page_dma
));
2787 total_sz
+= ioc
->config_page_sz
;
2789 printk(MPT2SAS_INFO_FMT
"Allocated physical memory: size(%d kB)\n",
2790 ioc
->name
, total_sz
/1024);
2791 printk(MPT2SAS_INFO_FMT
"Current Controller Queue Depth(%d), "
2792 "Max Controller Queue Depth(%d)\n",
2793 ioc
->name
, ioc
->shost
->can_queue
, facts
->RequestCredit
);
2794 printk(MPT2SAS_INFO_FMT
"Scatter Gather Elements per IO(%d)\n",
2795 ioc
->name
, ioc
->shost
->sg_tablesize
);
2804 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2805 * @ioc: Pointer to MPT_ADAPTER structure
2806 * @cooked: Request raw or cooked IOC state
2808 * Returns all IOC Doorbell register bits if cooked==0, else just the
2809 * Doorbell bits in MPI_IOC_STATE_MASK.
2812 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER
*ioc
, int cooked
)
2816 s
= readl(&ioc
->chip
->Doorbell
);
2817 sc
= s
& MPI2_IOC_STATE_MASK
;
2818 return cooked
? sc
: s
;
2822 * _base_wait_on_iocstate - waiting on a particular ioc state
2823 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2824 * @timeout: timeout in second
2825 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2827 * Returns 0 for success, non-zero for failure.
2830 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER
*ioc
, u32 ioc_state
, int timeout
,
2837 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2839 current_state
= mpt2sas_base_get_iocstate(ioc
, 1);
2840 if (current_state
== ioc_state
)
2842 if (count
&& current_state
== MPI2_IOC_STATE_FAULT
)
2844 if (sleep_flag
== CAN_SLEEP
)
2851 return current_state
;
2855 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2856 * a write to the doorbell)
2857 * @ioc: per adapter object
2858 * @timeout: timeout in second
2859 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2861 * Returns 0 for success, non-zero for failure.
2863 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2866 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2873 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2875 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
2876 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
2877 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2878 "successful count(%d), timeout(%d)\n", ioc
->name
,
2879 __func__
, count
, timeout
));
2882 if (sleep_flag
== CAN_SLEEP
)
2889 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2890 "int_status(%x)!\n", ioc
->name
, __func__
, count
, int_status
);
2895 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2896 * @ioc: per adapter object
2897 * @timeout: timeout in second
2898 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2900 * Returns 0 for success, non-zero for failure.
2902 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2906 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2914 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2916 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
2917 if (!(int_status
& MPI2_HIS_SYS2IOC_DB_STATUS
)) {
2918 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2919 "successful count(%d), timeout(%d)\n", ioc
->name
,
2920 __func__
, count
, timeout
));
2922 } else if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
2923 doorbell
= readl(&ioc
->chip
->Doorbell
);
2924 if ((doorbell
& MPI2_IOC_STATE_MASK
) ==
2925 MPI2_IOC_STATE_FAULT
) {
2926 mpt2sas_base_fault_info(ioc
, doorbell
);
2929 } else if (int_status
== 0xFFFFFFFF)
2932 if (sleep_flag
== CAN_SLEEP
)
2940 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2941 "int_status(%x)!\n", ioc
->name
, __func__
, count
, int_status
);
2946 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2947 * @ioc: per adapter object
2948 * @timeout: timeout in second
2949 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2951 * Returns 0 for success, non-zero for failure.
2955 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2962 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2964 doorbell_reg
= readl(&ioc
->chip
->Doorbell
);
2965 if (!(doorbell_reg
& MPI2_DOORBELL_USED
)) {
2966 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2967 "successful count(%d), timeout(%d)\n", ioc
->name
,
2968 __func__
, count
, timeout
));
2971 if (sleep_flag
== CAN_SLEEP
)
2978 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2979 "doorbell_reg(%x)!\n", ioc
->name
, __func__
, count
, doorbell_reg
);
2984 * _base_send_ioc_reset - send doorbell reset
2985 * @ioc: per adapter object
2986 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2987 * @timeout: timeout in second
2988 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2990 * Returns 0 for success, non-zero for failure.
2993 _base_send_ioc_reset(struct MPT2SAS_ADAPTER
*ioc
, u8 reset_type
, int timeout
,
2999 if (reset_type
!= MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
) {
3000 printk(MPT2SAS_ERR_FMT
"%s: unknown reset_type\n",
3001 ioc
->name
, __func__
);
3005 if (!(ioc
->facts
.IOCCapabilities
&
3006 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY
))
3009 printk(MPT2SAS_INFO_FMT
"sending message unit reset !!\n", ioc
->name
);
3011 writel(reset_type
<< MPI2_DOORBELL_FUNCTION_SHIFT
,
3012 &ioc
->chip
->Doorbell
);
3013 if ((_base_wait_for_doorbell_ack(ioc
, 15, sleep_flag
))) {
3017 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
,
3018 timeout
, sleep_flag
);
3020 printk(MPT2SAS_ERR_FMT
"%s: failed going to ready state "
3021 " (ioc_state=0x%x)\n", ioc
->name
, __func__
, ioc_state
);
3026 printk(MPT2SAS_INFO_FMT
"message unit reset: %s\n",
3027 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
3032 * _base_handshake_req_reply_wait - send request thru doorbell interface
3033 * @ioc: per adapter object
3034 * @request_bytes: request length
3035 * @request: pointer having request payload
3036 * @reply_bytes: reply length
3037 * @reply: pointer to reply payload
3038 * @timeout: timeout in second
3039 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3041 * Returns 0 for success, non-zero for failure.
3044 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER
*ioc
, int request_bytes
,
3045 u32
*request
, int reply_bytes
, u16
*reply
, int timeout
, int sleep_flag
)
3047 MPI2DefaultReply_t
*default_reply
= (MPI2DefaultReply_t
*)reply
;
3053 /* make sure doorbell is not in use */
3054 if ((readl(&ioc
->chip
->Doorbell
) & MPI2_DOORBELL_USED
)) {
3055 printk(MPT2SAS_ERR_FMT
"doorbell is in use "
3056 " (line=%d)\n", ioc
->name
, __LINE__
);
3060 /* clear pending doorbell interrupts from previous state changes */
3061 if (readl(&ioc
->chip
->HostInterruptStatus
) &
3062 MPI2_HIS_IOC2SYS_DB_STATUS
)
3063 writel(0, &ioc
->chip
->HostInterruptStatus
);
3065 /* send message to ioc */
3066 writel(((MPI2_FUNCTION_HANDSHAKE
<<MPI2_DOORBELL_FUNCTION_SHIFT
) |
3067 ((request_bytes
/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT
)),
3068 &ioc
->chip
->Doorbell
);
3070 if ((_base_wait_for_doorbell_int(ioc
, 5, NO_SLEEP
))) {
3071 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3072 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3075 writel(0, &ioc
->chip
->HostInterruptStatus
);
3077 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
))) {
3078 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3079 "ack failed (line=%d)\n", ioc
->name
, __LINE__
);
3083 /* send message 32-bits at a time */
3084 for (i
= 0, failed
= 0; i
< request_bytes
/4 && !failed
; i
++) {
3085 writel(cpu_to_le32(request
[i
]), &ioc
->chip
->Doorbell
);
3086 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
)))
3091 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3092 "sending request failed (line=%d)\n", ioc
->name
, __LINE__
);
3096 /* now wait for the reply */
3097 if ((_base_wait_for_doorbell_int(ioc
, timeout
, sleep_flag
))) {
3098 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3099 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3103 /* read the first two 16-bits, it gives the total length of the reply */
3104 reply
[0] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3105 & MPI2_DOORBELL_DATA_MASK
);
3106 writel(0, &ioc
->chip
->HostInterruptStatus
);
3107 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3108 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3109 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3112 reply
[1] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3113 & MPI2_DOORBELL_DATA_MASK
);
3114 writel(0, &ioc
->chip
->HostInterruptStatus
);
3116 for (i
= 2; i
< default_reply
->MsgLength
* 2; i
++) {
3117 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3118 printk(MPT2SAS_ERR_FMT
"doorbell "
3119 "handshake int failed (line=%d)\n", ioc
->name
,
3123 if (i
>= reply_bytes
/2) /* overflow case */
3124 dummy
= readl(&ioc
->chip
->Doorbell
);
3126 reply
[i
] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3127 & MPI2_DOORBELL_DATA_MASK
);
3128 writel(0, &ioc
->chip
->HostInterruptStatus
);
3131 _base_wait_for_doorbell_int(ioc
, 5, sleep_flag
);
3132 if (_base_wait_for_doorbell_not_used(ioc
, 5, sleep_flag
) != 0) {
3133 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"doorbell is in use "
3134 " (line=%d)\n", ioc
->name
, __LINE__
));
3136 writel(0, &ioc
->chip
->HostInterruptStatus
);
3138 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3139 mfp
= (__le32
*)reply
;
3140 printk(KERN_INFO
"\toffset:data\n");
3141 for (i
= 0; i
< reply_bytes
/4; i
++)
3142 printk(KERN_INFO
"\t[0x%02x]:%08x\n", i
*4,
3143 le32_to_cpu(mfp
[i
]));
3149 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3150 * @ioc: per adapter object
3151 * @mpi_reply: the reply payload from FW
3152 * @mpi_request: the request payload sent to FW
3154 * The SAS IO Unit Control Request message allows the host to perform low-level
3155 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3156 * to obtain the IOC assigned device handles for a device if it has other
3157 * identifying information about the device, in addition allows the host to
3158 * remove IOC resources associated with the device.
3160 * Returns 0 for success, non-zero for failure.
3163 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER
*ioc
,
3164 Mpi2SasIoUnitControlReply_t
*mpi_reply
,
3165 Mpi2SasIoUnitControlRequest_t
*mpi_request
)
3169 unsigned long timeleft
;
3173 u16 wait_state_count
;
3175 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3178 mutex_lock(&ioc
->base_cmds
.mutex
);
3180 if (ioc
->base_cmds
.status
!= MPT2_CMD_NOT_USED
) {
3181 printk(MPT2SAS_ERR_FMT
"%s: base_cmd in use\n",
3182 ioc
->name
, __func__
);
3187 wait_state_count
= 0;
3188 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3189 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3190 if (wait_state_count
++ == 10) {
3191 printk(MPT2SAS_ERR_FMT
3192 "%s: failed due to ioc not operational\n",
3193 ioc
->name
, __func__
);
3198 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3199 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
3200 "operational state(count=%d)\n", ioc
->name
,
3201 __func__
, wait_state_count
);
3204 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3206 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3207 ioc
->name
, __func__
);
3213 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3214 request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3215 ioc
->base_cmds
.smid
= smid
;
3216 memcpy(request
, mpi_request
, sizeof(Mpi2SasIoUnitControlRequest_t
));
3217 if (mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3218 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
)
3219 ioc
->ioc_link_reset_in_progress
= 1;
3220 init_completion(&ioc
->base_cmds
.done
);
3221 mpt2sas_base_put_smid_default(ioc
, smid
);
3222 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3223 msecs_to_jiffies(10000));
3224 if ((mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3225 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
) &&
3226 ioc
->ioc_link_reset_in_progress
)
3227 ioc
->ioc_link_reset_in_progress
= 0;
3228 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3229 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3230 ioc
->name
, __func__
);
3231 _debug_dump_mf(mpi_request
,
3232 sizeof(Mpi2SasIoUnitControlRequest_t
)/4);
3233 if (!(ioc
->base_cmds
.status
& MPT2_CMD_RESET
))
3235 goto issue_host_reset
;
3237 if (ioc
->base_cmds
.status
& MPT2_CMD_REPLY_VALID
)
3238 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3239 sizeof(Mpi2SasIoUnitControlReply_t
));
3241 memset(mpi_reply
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
3242 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3247 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3249 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3252 mutex_unlock(&ioc
->base_cmds
.mutex
);
3258 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3259 * @ioc: per adapter object
3260 * @mpi_reply: the reply payload from FW
3261 * @mpi_request: the request payload sent to FW
3263 * The SCSI Enclosure Processor request message causes the IOC to
3264 * communicate with SES devices to control LED status signals.
3266 * Returns 0 for success, non-zero for failure.
3269 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER
*ioc
,
3270 Mpi2SepReply_t
*mpi_reply
, Mpi2SepRequest_t
*mpi_request
)
3274 unsigned long timeleft
;
3278 u16 wait_state_count
;
3280 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3283 mutex_lock(&ioc
->base_cmds
.mutex
);
3285 if (ioc
->base_cmds
.status
!= MPT2_CMD_NOT_USED
) {
3286 printk(MPT2SAS_ERR_FMT
"%s: base_cmd in use\n",
3287 ioc
->name
, __func__
);
3292 wait_state_count
= 0;
3293 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3294 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3295 if (wait_state_count
++ == 10) {
3296 printk(MPT2SAS_ERR_FMT
3297 "%s: failed due to ioc not operational\n",
3298 ioc
->name
, __func__
);
3303 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3304 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
3305 "operational state(count=%d)\n", ioc
->name
,
3306 __func__
, wait_state_count
);
3309 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3311 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3312 ioc
->name
, __func__
);
3318 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3319 request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3320 ioc
->base_cmds
.smid
= smid
;
3321 memcpy(request
, mpi_request
, sizeof(Mpi2SepReply_t
));
3322 init_completion(&ioc
->base_cmds
.done
);
3323 mpt2sas_base_put_smid_default(ioc
, smid
);
3324 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3325 msecs_to_jiffies(10000));
3326 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3327 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3328 ioc
->name
, __func__
);
3329 _debug_dump_mf(mpi_request
,
3330 sizeof(Mpi2SepRequest_t
)/4);
3331 if (!(ioc
->base_cmds
.status
& MPT2_CMD_RESET
))
3333 goto issue_host_reset
;
3335 if (ioc
->base_cmds
.status
& MPT2_CMD_REPLY_VALID
)
3336 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3337 sizeof(Mpi2SepReply_t
));
3339 memset(mpi_reply
, 0, sizeof(Mpi2SepReply_t
));
3340 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3345 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3347 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3350 mutex_unlock(&ioc
->base_cmds
.mutex
);
3355 * _base_get_port_facts - obtain port facts reply and save in ioc
3356 * @ioc: per adapter object
3357 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3359 * Returns 0 for success, non-zero for failure.
3362 _base_get_port_facts(struct MPT2SAS_ADAPTER
*ioc
, int port
, int sleep_flag
)
3364 Mpi2PortFactsRequest_t mpi_request
;
3365 Mpi2PortFactsReply_t mpi_reply
;
3366 struct mpt2sas_port_facts
*pfacts
;
3367 int mpi_reply_sz
, mpi_request_sz
, r
;
3369 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3372 mpi_reply_sz
= sizeof(Mpi2PortFactsReply_t
);
3373 mpi_request_sz
= sizeof(Mpi2PortFactsRequest_t
);
3374 memset(&mpi_request
, 0, mpi_request_sz
);
3375 mpi_request
.Function
= MPI2_FUNCTION_PORT_FACTS
;
3376 mpi_request
.PortNumber
= port
;
3377 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3378 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3381 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3382 ioc
->name
, __func__
, r
);
3386 pfacts
= &ioc
->pfacts
[port
];
3387 memset(pfacts
, 0, sizeof(struct mpt2sas_port_facts
));
3388 pfacts
->PortNumber
= mpi_reply
.PortNumber
;
3389 pfacts
->VP_ID
= mpi_reply
.VP_ID
;
3390 pfacts
->VF_ID
= mpi_reply
.VF_ID
;
3391 pfacts
->MaxPostedCmdBuffers
=
3392 le16_to_cpu(mpi_reply
.MaxPostedCmdBuffers
);
3398 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3399 * @ioc: per adapter object
3400 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3402 * Returns 0 for success, non-zero for failure.
3405 _base_get_ioc_facts(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3407 Mpi2IOCFactsRequest_t mpi_request
;
3408 Mpi2IOCFactsReply_t mpi_reply
;
3409 struct mpt2sas_facts
*facts
;
3410 int mpi_reply_sz
, mpi_request_sz
, r
;
3412 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3415 mpi_reply_sz
= sizeof(Mpi2IOCFactsReply_t
);
3416 mpi_request_sz
= sizeof(Mpi2IOCFactsRequest_t
);
3417 memset(&mpi_request
, 0, mpi_request_sz
);
3418 mpi_request
.Function
= MPI2_FUNCTION_IOC_FACTS
;
3419 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3420 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3423 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3424 ioc
->name
, __func__
, r
);
3428 facts
= &ioc
->facts
;
3429 memset(facts
, 0, sizeof(struct mpt2sas_facts
));
3430 facts
->MsgVersion
= le16_to_cpu(mpi_reply
.MsgVersion
);
3431 facts
->HeaderVersion
= le16_to_cpu(mpi_reply
.HeaderVersion
);
3432 facts
->VP_ID
= mpi_reply
.VP_ID
;
3433 facts
->VF_ID
= mpi_reply
.VF_ID
;
3434 facts
->IOCExceptions
= le16_to_cpu(mpi_reply
.IOCExceptions
);
3435 facts
->MaxChainDepth
= mpi_reply
.MaxChainDepth
;
3436 facts
->WhoInit
= mpi_reply
.WhoInit
;
3437 facts
->NumberOfPorts
= mpi_reply
.NumberOfPorts
;
3438 facts
->MaxMSIxVectors
= mpi_reply
.MaxMSIxVectors
;
3439 facts
->RequestCredit
= le16_to_cpu(mpi_reply
.RequestCredit
);
3440 facts
->MaxReplyDescriptorPostQueueDepth
=
3441 le16_to_cpu(mpi_reply
.MaxReplyDescriptorPostQueueDepth
);
3442 facts
->ProductID
= le16_to_cpu(mpi_reply
.ProductID
);
3443 facts
->IOCCapabilities
= le32_to_cpu(mpi_reply
.IOCCapabilities
);
3444 if ((facts
->IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
))
3445 ioc
->ir_firmware
= 1;
3446 facts
->FWVersion
.Word
= le32_to_cpu(mpi_reply
.FWVersion
.Word
);
3447 facts
->IOCRequestFrameSize
=
3448 le16_to_cpu(mpi_reply
.IOCRequestFrameSize
);
3449 facts
->MaxInitiators
= le16_to_cpu(mpi_reply
.MaxInitiators
);
3450 facts
->MaxTargets
= le16_to_cpu(mpi_reply
.MaxTargets
);
3451 ioc
->shost
->max_id
= -1;
3452 facts
->MaxSasExpanders
= le16_to_cpu(mpi_reply
.MaxSasExpanders
);
3453 facts
->MaxEnclosures
= le16_to_cpu(mpi_reply
.MaxEnclosures
);
3454 facts
->ProtocolFlags
= le16_to_cpu(mpi_reply
.ProtocolFlags
);
3455 facts
->HighPriorityCredit
=
3456 le16_to_cpu(mpi_reply
.HighPriorityCredit
);
3457 facts
->ReplyFrameSize
= mpi_reply
.ReplyFrameSize
;
3458 facts
->MaxDevHandle
= le16_to_cpu(mpi_reply
.MaxDevHandle
);
3460 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"hba queue depth(%d), "
3461 "max chains per io(%d)\n", ioc
->name
, facts
->RequestCredit
,
3462 facts
->MaxChainDepth
));
3463 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request frame size(%d), "
3464 "reply frame size(%d)\n", ioc
->name
,
3465 facts
->IOCRequestFrameSize
* 4, facts
->ReplyFrameSize
* 4));
3470 * _base_send_ioc_init - send ioc_init to firmware
3471 * @ioc: per adapter object
3472 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3474 * Returns 0 for success, non-zero for failure.
3477 _base_send_ioc_init(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3479 Mpi2IOCInitRequest_t mpi_request
;
3480 Mpi2IOCInitReply_t mpi_reply
;
3482 struct timeval current_time
;
3485 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3488 memset(&mpi_request
, 0, sizeof(Mpi2IOCInitRequest_t
));
3489 mpi_request
.Function
= MPI2_FUNCTION_IOC_INIT
;
3490 mpi_request
.WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
3491 mpi_request
.VF_ID
= 0; /* TODO */
3492 mpi_request
.VP_ID
= 0;
3493 mpi_request
.MsgVersion
= cpu_to_le16(MPI2_VERSION
);
3494 mpi_request
.HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
3496 if (_base_is_controller_msix_enabled(ioc
))
3497 mpi_request
.HostMSIxVectors
= ioc
->reply_queue_count
;
3498 mpi_request
.SystemRequestFrameSize
= cpu_to_le16(ioc
->request_sz
/4);
3499 mpi_request
.ReplyDescriptorPostQueueDepth
=
3500 cpu_to_le16(ioc
->reply_post_queue_depth
);
3501 mpi_request
.ReplyFreeQueueDepth
=
3502 cpu_to_le16(ioc
->reply_free_queue_depth
);
3504 mpi_request
.SenseBufferAddressHigh
=
3505 cpu_to_le32((u64
)ioc
->sense_dma
>> 32);
3506 mpi_request
.SystemReplyAddressHigh
=
3507 cpu_to_le32((u64
)ioc
->reply_dma
>> 32);
3508 mpi_request
.SystemRequestFrameBaseAddress
=
3509 cpu_to_le64((u64
)ioc
->request_dma
);
3510 mpi_request
.ReplyFreeQueueAddress
=
3511 cpu_to_le64((u64
)ioc
->reply_free_dma
);
3512 mpi_request
.ReplyDescriptorPostQueueAddress
=
3513 cpu_to_le64((u64
)ioc
->reply_post_free_dma
);
3516 /* This time stamp specifies number of milliseconds
3517 * since epoch ~ midnight January 1, 1970.
3519 do_gettimeofday(¤t_time
);
3520 mpi_request
.TimeStamp
= cpu_to_le64((u64
)current_time
.tv_sec
* 1000 +
3521 (current_time
.tv_usec
/ 1000));
3523 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3527 mfp
= (__le32
*)&mpi_request
;
3528 printk(KERN_INFO
"\toffset:data\n");
3529 for (i
= 0; i
< sizeof(Mpi2IOCInitRequest_t
)/4; i
++)
3530 printk(KERN_INFO
"\t[0x%02x]:%08x\n", i
*4,
3531 le32_to_cpu(mfp
[i
]));
3534 r
= _base_handshake_req_reply_wait(ioc
,
3535 sizeof(Mpi2IOCInitRequest_t
), (u32
*)&mpi_request
,
3536 sizeof(Mpi2IOCInitReply_t
), (u16
*)&mpi_reply
, 10,
3540 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3541 ioc
->name
, __func__
, r
);
3545 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3546 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
||
3547 mpi_reply
.IOCLogInfo
) {
3548 printk(MPT2SAS_ERR_FMT
"%s: failed\n", ioc
->name
, __func__
);
3556 * mpt2sas_port_enable_done - command completion routine for port enable
3557 * @ioc: per adapter object
3558 * @smid: system request message index
3559 * @msix_index: MSIX table index supplied by the OS
3560 * @reply: reply message frame(lower 32bit addr)
3562 * Return 1 meaning mf should be freed from _base_interrupt
3563 * 0 means the mf is freed from this function.
3566 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3569 MPI2DefaultReply_t
*mpi_reply
;
3572 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3573 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
3576 if (ioc
->port_enable_cmds
.status
== MPT2_CMD_NOT_USED
)
3579 ioc
->port_enable_cmds
.status
|= MPT2_CMD_COMPLETE
;
3581 ioc
->port_enable_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3582 memcpy(ioc
->port_enable_cmds
.reply
, mpi_reply
,
3583 mpi_reply
->MsgLength
*4);
3585 ioc
->port_enable_cmds
.status
&= ~MPT2_CMD_PENDING
;
3587 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3589 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3590 ioc
->port_enable_failed
= 1;
3592 if (ioc
->is_driver_loading
) {
3593 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
3594 mpt2sas_port_enable_complete(ioc
);
3597 ioc
->start_scan_failed
= ioc_status
;
3598 ioc
->start_scan
= 0;
3602 complete(&ioc
->port_enable_cmds
.done
);
3608 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3609 * @ioc: per adapter object
3610 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3612 * Returns 0 for success, non-zero for failure.
3615 _base_send_port_enable(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3617 Mpi2PortEnableRequest_t
*mpi_request
;
3618 Mpi2PortEnableReply_t
*mpi_reply
;
3619 unsigned long timeleft
;
3624 printk(MPT2SAS_INFO_FMT
"sending port enable !!\n", ioc
->name
);
3626 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_PENDING
) {
3627 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3628 ioc
->name
, __func__
);
3632 smid
= mpt2sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3634 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3635 ioc
->name
, __func__
);
3639 ioc
->port_enable_cmds
.status
= MPT2_CMD_PENDING
;
3640 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3641 ioc
->port_enable_cmds
.smid
= smid
;
3642 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3643 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3645 init_completion(&ioc
->port_enable_cmds
.done
);
3646 mpt2sas_base_put_smid_default(ioc
, smid
);
3647 timeleft
= wait_for_completion_timeout(&ioc
->port_enable_cmds
.done
,
3649 if (!(ioc
->port_enable_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3650 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3651 ioc
->name
, __func__
);
3652 _debug_dump_mf(mpi_request
,
3653 sizeof(Mpi2PortEnableRequest_t
)/4);
3654 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_RESET
)
3660 mpi_reply
= ioc
->port_enable_cmds
.reply
;
3662 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3663 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3664 printk(MPT2SAS_ERR_FMT
"%s: failed with (ioc_status=0x%08x)\n",
3665 ioc
->name
, __func__
, ioc_status
);
3670 ioc
->port_enable_cmds
.status
= MPT2_CMD_NOT_USED
;
3671 printk(MPT2SAS_INFO_FMT
"port enable: %s\n", ioc
->name
, ((r
== 0) ?
3672 "SUCCESS" : "FAILED"));
3677 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3678 * @ioc: per adapter object
3680 * Returns 0 for success, non-zero for failure.
3683 mpt2sas_port_enable(struct MPT2SAS_ADAPTER
*ioc
)
3685 Mpi2PortEnableRequest_t
*mpi_request
;
3688 printk(MPT2SAS_INFO_FMT
"sending port enable !!\n", ioc
->name
);
3690 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_PENDING
) {
3691 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3692 ioc
->name
, __func__
);
3696 smid
= mpt2sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3698 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3699 ioc
->name
, __func__
);
3703 ioc
->port_enable_cmds
.status
= MPT2_CMD_PENDING
;
3704 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3705 ioc
->port_enable_cmds
.smid
= smid
;
3706 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3707 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3709 mpt2sas_base_put_smid_default(ioc
, smid
);
3714 * _base_determine_wait_on_discovery - desposition
3715 * @ioc: per adapter object
3717 * Decide whether to wait on discovery to complete. Used to either
3718 * locate boot device, or report volumes ahead of physical devices.
3720 * Returns 1 for wait, 0 for don't wait
3723 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER
*ioc
)
3725 /* We wait for discovery to complete if IR firmware is loaded.
3726 * The sas topology events arrive before PD events, so we need time to
3727 * turn on the bit in ioc->pd_handles to indicate PD
3728 * Also, it maybe required to report Volumes ahead of physical
3729 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3731 if (ioc
->ir_firmware
)
3734 /* if no Bios, then we don't need to wait */
3735 if (!ioc
->bios_pg3
.BiosVersion
)
3738 /* Bios is present, then we drop down here.
3740 * If there any entries in the Bios Page 2, then we wait
3741 * for discovery to complete.
3744 /* Current Boot Device */
3745 if ((ioc
->bios_pg2
.CurrentBootDeviceForm
&
3746 MPI2_BIOSPAGE2_FORM_MASK
) ==
3747 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
3748 /* Request Boot Device */
3749 (ioc
->bios_pg2
.ReqBootDeviceForm
&
3750 MPI2_BIOSPAGE2_FORM_MASK
) ==
3751 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
3752 /* Alternate Request Boot Device */
3753 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
3754 MPI2_BIOSPAGE2_FORM_MASK
) ==
3755 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
)
3763 * _base_unmask_events - turn on notification for this event
3764 * @ioc: per adapter object
3765 * @event: firmware event
3767 * The mask is stored in ioc->event_masks.
3770 _base_unmask_events(struct MPT2SAS_ADAPTER
*ioc
, u16 event
)
3777 desired_event
= (1 << (event
% 32));
3780 ioc
->event_masks
[0] &= ~desired_event
;
3781 else if (event
< 64)
3782 ioc
->event_masks
[1] &= ~desired_event
;
3783 else if (event
< 96)
3784 ioc
->event_masks
[2] &= ~desired_event
;
3785 else if (event
< 128)
3786 ioc
->event_masks
[3] &= ~desired_event
;
3790 * _base_event_notification - send event notification
3791 * @ioc: per adapter object
3792 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3794 * Returns 0 for success, non-zero for failure.
3797 _base_event_notification(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3799 Mpi2EventNotificationRequest_t
*mpi_request
;
3800 unsigned long timeleft
;
3805 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3808 if (ioc
->base_cmds
.status
& MPT2_CMD_PENDING
) {
3809 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3810 ioc
->name
, __func__
);
3814 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3816 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3817 ioc
->name
, __func__
);
3820 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3821 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3822 ioc
->base_cmds
.smid
= smid
;
3823 memset(mpi_request
, 0, sizeof(Mpi2EventNotificationRequest_t
));
3824 mpi_request
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3825 mpi_request
->VF_ID
= 0; /* TODO */
3826 mpi_request
->VP_ID
= 0;
3827 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
3828 mpi_request
->EventMasks
[i
] =
3829 cpu_to_le32(ioc
->event_masks
[i
]);
3830 init_completion(&ioc
->base_cmds
.done
);
3831 mpt2sas_base_put_smid_default(ioc
, smid
);
3832 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
, 30*HZ
);
3833 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3834 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3835 ioc
->name
, __func__
);
3836 _debug_dump_mf(mpi_request
,
3837 sizeof(Mpi2EventNotificationRequest_t
)/4);
3838 if (ioc
->base_cmds
.status
& MPT2_CMD_RESET
)
3843 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: complete\n",
3844 ioc
->name
, __func__
));
3845 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3850 * mpt2sas_base_validate_event_type - validating event types
3851 * @ioc: per adapter object
3852 * @event: firmware event
3854 * This will turn on firmware event notification when application
3855 * ask for that event. We don't mask events that are already enabled.
3858 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER
*ioc
, u32
*event_type
)
3861 u32 event_mask
, desired_event
;
3862 u8 send_update_to_fw
;
3864 for (i
= 0, send_update_to_fw
= 0; i
<
3865 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++) {
3866 event_mask
= ~event_type
[i
];
3868 for (j
= 0; j
< 32; j
++) {
3869 if (!(event_mask
& desired_event
) &&
3870 (ioc
->event_masks
[i
] & desired_event
)) {
3871 ioc
->event_masks
[i
] &= ~desired_event
;
3872 send_update_to_fw
= 1;
3874 desired_event
= (desired_event
<< 1);
3878 if (!send_update_to_fw
)
3881 mutex_lock(&ioc
->base_cmds
.mutex
);
3882 _base_event_notification(ioc
, CAN_SLEEP
);
3883 mutex_unlock(&ioc
->base_cmds
.mutex
);
3887 * _base_diag_reset - the "big hammer" start of day reset
3888 * @ioc: per adapter object
3889 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3891 * Returns 0 for success, non-zero for failure.
3894 _base_diag_reset(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3896 u32 host_diagnostic
;
3901 printk(MPT2SAS_INFO_FMT
"sending diag reset !!\n", ioc
->name
);
3902 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"clear interrupts\n",
3907 /* Write magic sequence to WriteSequence register
3908 * Loop until in diagnostic mode
3910 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"write magic "
3911 "sequence\n", ioc
->name
));
3912 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3913 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3914 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3915 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3916 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3917 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3918 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3921 if (sleep_flag
== CAN_SLEEP
)
3929 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
3930 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"wrote magic "
3931 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3932 ioc
->name
, count
, host_diagnostic
));
3934 } while ((host_diagnostic
& MPI2_DIAG_DIAG_WRITE_ENABLE
) == 0);
3936 hcb_size
= readl(&ioc
->chip
->HCBSize
);
3938 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"diag reset: issued\n",
3940 writel(host_diagnostic
| MPI2_DIAG_RESET_ADAPTER
,
3941 &ioc
->chip
->HostDiagnostic
);
3943 /* don't access any registers for 50 milliseconds */
3946 /* 300 second max wait */
3947 for (count
= 0; count
< 3000000 ; count
++) {
3949 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
3951 if (host_diagnostic
== 0xFFFFFFFF)
3953 if (!(host_diagnostic
& MPI2_DIAG_RESET_ADAPTER
))
3957 if (sleep_flag
== CAN_SLEEP
)
3963 if (host_diagnostic
& MPI2_DIAG_HCB_MODE
) {
3965 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"restart the adapter "
3966 "assuming the HCB Address points to good F/W\n",
3968 host_diagnostic
&= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK
;
3969 host_diagnostic
|= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW
;
3970 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
3972 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
3973 "re-enable the HCDW\n", ioc
->name
));
3974 writel(hcb_size
| MPI2_HCB_SIZE_HCB_ENABLE
,
3975 &ioc
->chip
->HCBSize
);
3978 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"restart the adapter\n",
3980 writel(host_diagnostic
& ~MPI2_DIAG_HOLD_IOC_RESET
,
3981 &ioc
->chip
->HostDiagnostic
);
3983 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"disable writes to the "
3984 "diagnostic register\n", ioc
->name
));
3985 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3987 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"Wait for FW to go to the "
3988 "READY state\n", ioc
->name
));
3989 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, 20,
3992 printk(MPT2SAS_ERR_FMT
"%s: failed going to ready state "
3993 " (ioc_state=0x%x)\n", ioc
->name
, __func__
, ioc_state
);
3997 printk(MPT2SAS_INFO_FMT
"diag reset: SUCCESS\n", ioc
->name
);
4001 printk(MPT2SAS_ERR_FMT
"diag reset: FAILED\n", ioc
->name
);
4006 * _base_make_ioc_ready - put controller in READY state
4007 * @ioc: per adapter object
4008 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4009 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4011 * Returns 0 for success, non-zero for failure.
4014 _base_make_ioc_ready(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
,
4015 enum reset_type type
)
4020 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4023 if (ioc
->pci_error_recovery
)
4026 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
4027 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: ioc_state(0x%08x)\n",
4028 ioc
->name
, __func__
, ioc_state
));
4030 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
)
4033 if (ioc_state
& MPI2_DOORBELL_USED
) {
4034 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
4035 "active!\n", ioc
->name
));
4036 goto issue_diag_reset
;
4039 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
4040 mpt2sas_base_fault_info(ioc
, ioc_state
&
4041 MPI2_DOORBELL_DATA_MASK
);
4042 goto issue_diag_reset
;
4045 if (type
== FORCE_BIG_HAMMER
)
4046 goto issue_diag_reset
;
4048 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
4049 if (!(_base_send_ioc_reset(ioc
,
4050 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
, 15, CAN_SLEEP
))) {
4051 ioc
->ioc_reset_count
++;
4056 rc
= _base_diag_reset(ioc
, CAN_SLEEP
);
4057 ioc
->ioc_reset_count
++;
4062 * _base_make_ioc_operational - put controller in OPERATIONAL state
4063 * @ioc: per adapter object
4064 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4066 * Returns 0 for success, non-zero for failure.
4069 _base_make_ioc_operational(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
4072 unsigned long flags
;
4075 struct _tr_list
*delayed_tr
, *delayed_tr_next
;
4077 struct adapter_reply_queue
*reply_q
;
4078 long reply_post_free
;
4079 u32 reply_post_free_sz
;
4081 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4084 /* clean the delayed target reset list */
4085 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4086 &ioc
->delayed_tr_list
, list
) {
4087 list_del(&delayed_tr
->list
);
4091 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4092 &ioc
->delayed_tr_volume_list
, list
) {
4093 list_del(&delayed_tr
->list
);
4097 /* initialize the scsi lookup free list */
4098 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4099 INIT_LIST_HEAD(&ioc
->free_list
);
4101 for (i
= 0; i
< ioc
->scsiio_depth
; i
++, smid
++) {
4102 INIT_LIST_HEAD(&ioc
->scsi_lookup
[i
].chain_list
);
4103 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
4104 ioc
->scsi_lookup
[i
].smid
= smid
;
4105 ioc
->scsi_lookup
[i
].scmd
= NULL
;
4106 ioc
->scsi_lookup
[i
].direct_io
= 0;
4107 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
4111 /* hi-priority queue */
4112 INIT_LIST_HEAD(&ioc
->hpr_free_list
);
4113 smid
= ioc
->hi_priority_smid
;
4114 for (i
= 0; i
< ioc
->hi_priority_depth
; i
++, smid
++) {
4115 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
4116 ioc
->hpr_lookup
[i
].smid
= smid
;
4117 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
4118 &ioc
->hpr_free_list
);
4121 /* internal queue */
4122 INIT_LIST_HEAD(&ioc
->internal_free_list
);
4123 smid
= ioc
->internal_smid
;
4124 for (i
= 0; i
< ioc
->internal_depth
; i
++, smid
++) {
4125 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
4126 ioc
->internal_lookup
[i
].smid
= smid
;
4127 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
4128 &ioc
->internal_free_list
);
4132 INIT_LIST_HEAD(&ioc
->free_chain_list
);
4133 for (i
= 0; i
< ioc
->chain_depth
; i
++)
4134 list_add_tail(&ioc
->chain_lookup
[i
].tracker_list
,
4135 &ioc
->free_chain_list
);
4137 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4139 /* initialize Reply Free Queue */
4140 for (i
= 0, reply_address
= (u32
)ioc
->reply_dma
;
4141 i
< ioc
->reply_free_queue_depth
; i
++, reply_address
+=
4143 ioc
->reply_free
[i
] = cpu_to_le32(reply_address
);
4145 /* initialize reply queues */
4146 if (ioc
->is_driver_loading
)
4147 _base_assign_reply_queues(ioc
);
4149 /* initialize Reply Post Free Queue */
4150 reply_post_free
= (long)ioc
->reply_post_free
;
4151 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
4152 sizeof(Mpi2DefaultReplyDescriptor_t
);
4153 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4154 reply_q
->reply_post_host_index
= 0;
4155 reply_q
->reply_post_free
= (Mpi2ReplyDescriptorsUnion_t
*)
4157 for (i
= 0; i
< ioc
->reply_post_queue_depth
; i
++)
4158 reply_q
->reply_post_free
[i
].Words
=
4159 cpu_to_le64(ULLONG_MAX
);
4160 if (!_base_is_controller_msix_enabled(ioc
))
4161 goto skip_init_reply_post_free_queue
;
4162 reply_post_free
+= reply_post_free_sz
;
4164 skip_init_reply_post_free_queue
:
4166 r
= _base_send_ioc_init(ioc
, sleep_flag
);
4170 /* initialize reply free host index */
4171 ioc
->reply_free_host_index
= ioc
->reply_free_queue_depth
- 1;
4172 writel(ioc
->reply_free_host_index
, &ioc
->chip
->ReplyFreeHostIndex
);
4174 /* initialize reply post host index */
4175 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4176 writel(reply_q
->msix_index
<< MPI2_RPHI_MSIX_INDEX_SHIFT
,
4177 &ioc
->chip
->ReplyPostHostIndex
);
4178 if (!_base_is_controller_msix_enabled(ioc
))
4179 goto skip_init_reply_post_host_index
;
4182 skip_init_reply_post_host_index
:
4184 _base_unmask_interrupts(ioc
);
4186 r
= _base_event_notification(ioc
, sleep_flag
);
4190 if (sleep_flag
== CAN_SLEEP
)
4191 _base_static_config_pages(ioc
);
4194 if (ioc
->is_driver_loading
) {
4195 if (ioc
->is_warpdrive
&& ioc
->manu_pg10
.OEMIdentifier
4198 le32_to_cpu(ioc
->manu_pg10
.OEMSpecificFlags0
) &
4199 MFG_PAGE10_HIDE_SSDS_MASK
);
4200 if (hide_flag
!= MFG_PAGE10_HIDE_SSDS_MASK
)
4201 ioc
->mfg_pg10_hide_flag
= hide_flag
;
4203 ioc
->wait_for_discovery_to_complete
=
4204 _base_determine_wait_on_discovery(ioc
);
4205 return r
; /* scan_start and scan_finished support */
4207 r
= _base_send_port_enable(ioc
, sleep_flag
);
4215 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4216 * @ioc: per adapter object
4221 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER
*ioc
)
4223 struct pci_dev
*pdev
= ioc
->pdev
;
4225 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4228 _base_mask_interrupts(ioc
);
4229 ioc
->shost_recovery
= 1;
4230 _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4231 ioc
->shost_recovery
= 0;
4232 _base_free_irq(ioc
);
4233 _base_disable_msix(ioc
);
4237 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
4238 pci_disable_pcie_error_reporting(pdev
);
4239 pci_disable_device(pdev
);
4244 * mpt2sas_base_attach - attach controller instance
4245 * @ioc: per adapter object
4247 * Returns 0 for success, non-zero for failure.
4250 mpt2sas_base_attach(struct MPT2SAS_ADAPTER
*ioc
)
4253 int cpu_id
, last_cpu_id
= 0;
4255 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4258 /* setup cpu_msix_table */
4259 ioc
->cpu_count
= num_online_cpus();
4260 for_each_online_cpu(cpu_id
)
4261 last_cpu_id
= cpu_id
;
4262 ioc
->cpu_msix_table_sz
= last_cpu_id
+ 1;
4263 ioc
->cpu_msix_table
= kzalloc(ioc
->cpu_msix_table_sz
, GFP_KERNEL
);
4264 ioc
->reply_queue_count
= 1;
4265 if (!ioc
->cpu_msix_table
) {
4266 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"allocation for "
4267 "cpu_msix_table failed!!!\n", ioc
->name
));
4269 goto out_free_resources
;
4272 if (ioc
->is_warpdrive
) {
4273 ioc
->reply_post_host_index
= kcalloc(ioc
->cpu_msix_table_sz
,
4274 sizeof(resource_size_t
*), GFP_KERNEL
);
4275 if (!ioc
->reply_post_host_index
) {
4276 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"allocation "
4277 "for cpu_msix_table failed!!!\n", ioc
->name
));
4279 goto out_free_resources
;
4283 r
= mpt2sas_base_map_resources(ioc
);
4285 goto out_free_resources
;
4287 if (ioc
->is_warpdrive
) {
4288 ioc
->reply_post_host_index
[0] =
4289 (resource_size_t
*)&ioc
->chip
->ReplyPostHostIndex
;
4291 for (i
= 1; i
< ioc
->cpu_msix_table_sz
; i
++)
4292 ioc
->reply_post_host_index
[i
] = (resource_size_t
*)
4293 ((u8
*)&ioc
->chip
->Doorbell
+ (0x4000 + ((i
- 1)
4297 pci_set_drvdata(ioc
->pdev
, ioc
->shost
);
4298 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
4300 goto out_free_resources
;
4302 r
= _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4304 goto out_free_resources
;
4306 ioc
->pfacts
= kcalloc(ioc
->facts
.NumberOfPorts
,
4307 sizeof(struct mpt2sas_port_facts
), GFP_KERNEL
);
4310 goto out_free_resources
;
4313 for (i
= 0 ; i
< ioc
->facts
.NumberOfPorts
; i
++) {
4314 r
= _base_get_port_facts(ioc
, i
, CAN_SLEEP
);
4316 goto out_free_resources
;
4319 r
= _base_allocate_memory_pools(ioc
, CAN_SLEEP
);
4321 goto out_free_resources
;
4323 init_waitqueue_head(&ioc
->reset_wq
);
4324 /* allocate memory pd handle bitmask list */
4325 ioc
->pd_handles_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
4326 if (ioc
->facts
.MaxDevHandle
% 8)
4327 ioc
->pd_handles_sz
++;
4328 ioc
->pd_handles
= kzalloc(ioc
->pd_handles_sz
,
4330 if (!ioc
->pd_handles
) {
4332 goto out_free_resources
;
4334 ioc
->blocking_handles
= kzalloc(ioc
->pd_handles_sz
,
4336 if (!ioc
->blocking_handles
) {
4338 goto out_free_resources
;
4340 ioc
->fwfault_debug
= mpt2sas_fwfault_debug
;
4342 /* base internal command bits */
4343 mutex_init(&ioc
->base_cmds
.mutex
);
4344 ioc
->base_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4345 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
4347 /* port_enable command bits */
4348 ioc
->port_enable_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4349 ioc
->port_enable_cmds
.status
= MPT2_CMD_NOT_USED
;
4351 /* transport internal command bits */
4352 ioc
->transport_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4353 ioc
->transport_cmds
.status
= MPT2_CMD_NOT_USED
;
4354 mutex_init(&ioc
->transport_cmds
.mutex
);
4356 /* scsih internal command bits */
4357 ioc
->scsih_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4358 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
4359 mutex_init(&ioc
->scsih_cmds
.mutex
);
4361 /* task management internal command bits */
4362 ioc
->tm_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4363 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4364 mutex_init(&ioc
->tm_cmds
.mutex
);
4366 /* config page internal command bits */
4367 ioc
->config_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4368 ioc
->config_cmds
.status
= MPT2_CMD_NOT_USED
;
4369 mutex_init(&ioc
->config_cmds
.mutex
);
4371 /* ctl module internal command bits */
4372 ioc
->ctl_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4373 ioc
->ctl_cmds
.sense
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
4374 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
4375 mutex_init(&ioc
->ctl_cmds
.mutex
);
4377 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4378 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4379 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
||
4380 !ioc
->ctl_cmds
.sense
) {
4382 goto out_free_resources
;
4385 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4386 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4387 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
) {
4389 goto out_free_resources
;
4392 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4393 ioc
->event_masks
[i
] = -1;
4395 /* here we enable the events we care about */
4396 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DISCOVERY
);
4397 _base_unmask_events(ioc
, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
);
4398 _base_unmask_events(ioc
, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
4399 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4400 _base_unmask_events(ioc
, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
);
4401 _base_unmask_events(ioc
, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
);
4402 _base_unmask_events(ioc
, MPI2_EVENT_IR_VOLUME
);
4403 _base_unmask_events(ioc
, MPI2_EVENT_IR_PHYSICAL_DISK
);
4404 _base_unmask_events(ioc
, MPI2_EVENT_IR_OPERATION_STATUS
);
4405 _base_unmask_events(ioc
, MPI2_EVENT_LOG_ENTRY_ADDED
);
4406 r
= _base_make_ioc_operational(ioc
, CAN_SLEEP
);
4408 goto out_free_resources
;
4410 if (missing_delay
[0] != -1 && missing_delay
[1] != -1)
4411 _base_update_missing_delay(ioc
, missing_delay
[0],
4413 ioc
->non_operational_loop
= 0;
4419 ioc
->remove_host
= 1;
4420 mpt2sas_base_free_resources(ioc
);
4421 _base_release_memory_pools(ioc
);
4422 pci_set_drvdata(ioc
->pdev
, NULL
);
4423 kfree(ioc
->cpu_msix_table
);
4424 if (ioc
->is_warpdrive
)
4425 kfree(ioc
->reply_post_host_index
);
4426 kfree(ioc
->pd_handles
);
4427 kfree(ioc
->blocking_handles
);
4428 kfree(ioc
->tm_cmds
.reply
);
4429 kfree(ioc
->transport_cmds
.reply
);
4430 kfree(ioc
->scsih_cmds
.reply
);
4431 kfree(ioc
->config_cmds
.reply
);
4432 kfree(ioc
->base_cmds
.reply
);
4433 kfree(ioc
->port_enable_cmds
.reply
);
4434 kfree(ioc
->ctl_cmds
.reply
);
4435 kfree(ioc
->ctl_cmds
.sense
);
4437 ioc
->ctl_cmds
.reply
= NULL
;
4438 ioc
->base_cmds
.reply
= NULL
;
4439 ioc
->tm_cmds
.reply
= NULL
;
4440 ioc
->scsih_cmds
.reply
= NULL
;
4441 ioc
->transport_cmds
.reply
= NULL
;
4442 ioc
->config_cmds
.reply
= NULL
;
4449 * mpt2sas_base_detach - remove controller instance
4450 * @ioc: per adapter object
4455 mpt2sas_base_detach(struct MPT2SAS_ADAPTER
*ioc
)
4458 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4461 mpt2sas_base_stop_watchdog(ioc
);
4462 mpt2sas_base_free_resources(ioc
);
4463 _base_release_memory_pools(ioc
);
4464 pci_set_drvdata(ioc
->pdev
, NULL
);
4465 kfree(ioc
->cpu_msix_table
);
4466 if (ioc
->is_warpdrive
)
4467 kfree(ioc
->reply_post_host_index
);
4468 kfree(ioc
->pd_handles
);
4469 kfree(ioc
->blocking_handles
);
4471 kfree(ioc
->ctl_cmds
.reply
);
4472 kfree(ioc
->ctl_cmds
.sense
);
4473 kfree(ioc
->base_cmds
.reply
);
4474 kfree(ioc
->port_enable_cmds
.reply
);
4475 kfree(ioc
->tm_cmds
.reply
);
4476 kfree(ioc
->transport_cmds
.reply
);
4477 kfree(ioc
->scsih_cmds
.reply
);
4478 kfree(ioc
->config_cmds
.reply
);
4482 * _base_reset_handler - reset callback handler (for base)
4483 * @ioc: per adapter object
4484 * @reset_phase: phase
4486 * The handler for doing any required cleanup or initialization.
4488 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4489 * MPT2_IOC_DONE_RESET
4494 _base_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
4496 mpt2sas_scsih_reset_handler(ioc
, reset_phase
);
4497 mpt2sas_ctl_reset_handler(ioc
, reset_phase
);
4498 switch (reset_phase
) {
4499 case MPT2_IOC_PRE_RESET
:
4500 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4501 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
4503 case MPT2_IOC_AFTER_RESET
:
4504 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4505 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
4506 if (ioc
->transport_cmds
.status
& MPT2_CMD_PENDING
) {
4507 ioc
->transport_cmds
.status
|= MPT2_CMD_RESET
;
4508 mpt2sas_base_free_smid(ioc
, ioc
->transport_cmds
.smid
);
4509 complete(&ioc
->transport_cmds
.done
);
4511 if (ioc
->base_cmds
.status
& MPT2_CMD_PENDING
) {
4512 ioc
->base_cmds
.status
|= MPT2_CMD_RESET
;
4513 mpt2sas_base_free_smid(ioc
, ioc
->base_cmds
.smid
);
4514 complete(&ioc
->base_cmds
.done
);
4516 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_PENDING
) {
4517 ioc
->port_enable_failed
= 1;
4518 ioc
->port_enable_cmds
.status
|= MPT2_CMD_RESET
;
4519 mpt2sas_base_free_smid(ioc
, ioc
->port_enable_cmds
.smid
);
4520 if (ioc
->is_driver_loading
) {
4521 ioc
->start_scan_failed
=
4522 MPI2_IOCSTATUS_INTERNAL_ERROR
;
4523 ioc
->start_scan
= 0;
4524 ioc
->port_enable_cmds
.status
=
4527 complete(&ioc
->port_enable_cmds
.done
);
4530 if (ioc
->config_cmds
.status
& MPT2_CMD_PENDING
) {
4531 ioc
->config_cmds
.status
|= MPT2_CMD_RESET
;
4532 mpt2sas_base_free_smid(ioc
, ioc
->config_cmds
.smid
);
4533 ioc
->config_cmds
.smid
= USHRT_MAX
;
4534 complete(&ioc
->config_cmds
.done
);
4537 case MPT2_IOC_DONE_RESET
:
4538 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4539 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
4545 * _wait_for_commands_to_complete - reset controller
4546 * @ioc: Pointer to MPT_ADAPTER structure
4547 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4549 * This function waiting(3s) for all pending commands to complete
4550 * prior to putting controller in reset.
4553 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
4556 unsigned long flags
;
4559 ioc
->pending_io_count
= 0;
4560 if (sleep_flag
!= CAN_SLEEP
)
4563 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
4564 if ((ioc_state
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
)
4567 /* pending command count */
4568 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4569 for (i
= 0; i
< ioc
->scsiio_depth
; i
++)
4570 if (ioc
->scsi_lookup
[i
].cb_idx
!= 0xFF)
4571 ioc
->pending_io_count
++;
4572 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4574 if (!ioc
->pending_io_count
)
4577 /* wait for pending commands to complete */
4578 wait_event_timeout(ioc
->reset_wq
, ioc
->pending_io_count
== 0, 10 * HZ
);
4582 * mpt2sas_base_hard_reset_handler - reset controller
4583 * @ioc: Pointer to MPT_ADAPTER structure
4584 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4585 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4587 * Returns 0 for success, non-zero for failure.
4590 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
,
4591 enum reset_type type
)
4594 unsigned long flags
;
4596 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
4599 if (ioc
->pci_error_recovery
) {
4600 printk(MPT2SAS_ERR_FMT
"%s: pci error recovery reset\n",
4601 ioc
->name
, __func__
);
4606 if (mpt2sas_fwfault_debug
)
4607 mpt2sas_halt_firmware(ioc
);
4609 /* TODO - What we really should be doing is pulling
4610 * out all the code associated with NO_SLEEP; its never used.
4611 * That is legacy code from mpt fusion driver, ported over.
4612 * I will leave this BUG_ON here for now till its been resolved.
4614 BUG_ON(sleep_flag
== NO_SLEEP
);
4616 /* wait for an active reset in progress to complete */
4617 if (!mutex_trylock(&ioc
->reset_in_progress_mutex
)) {
4620 } while (ioc
->shost_recovery
== 1);
4621 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit\n", ioc
->name
,
4623 return ioc
->ioc_reset_in_progress_status
;
4626 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4627 ioc
->shost_recovery
= 1;
4628 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4630 _base_reset_handler(ioc
, MPT2_IOC_PRE_RESET
);
4631 _wait_for_commands_to_complete(ioc
, sleep_flag
);
4632 _base_mask_interrupts(ioc
);
4633 r
= _base_make_ioc_ready(ioc
, sleep_flag
, type
);
4636 _base_reset_handler(ioc
, MPT2_IOC_AFTER_RESET
);
4638 /* If this hard reset is called while port enable is active, then
4639 * there is no reason to call make_ioc_operational
4641 if (ioc
->is_driver_loading
&& ioc
->port_enable_failed
) {
4642 ioc
->remove_host
= 1;
4646 r
= _base_make_ioc_operational(ioc
, sleep_flag
);
4648 _base_reset_handler(ioc
, MPT2_IOC_DONE_RESET
);
4650 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %s\n",
4651 ioc
->name
, __func__
, ((r
== 0) ? "SUCCESS" : "FAILED")));
4653 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4654 ioc
->ioc_reset_in_progress_status
= r
;
4655 ioc
->shost_recovery
= 0;
4656 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4657 mutex_unlock(&ioc
->reset_in_progress_mutex
);
4660 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit\n", ioc
->name
,