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-2013 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 mpt2sas_fwfault_debug
;
84 MODULE_PARM_DESC(mpt2sas_fwfault_debug
, " enable detection of firmware fault "
85 "and halt firmware - (default=0)");
87 static int disable_discovery
= -1;
88 module_param(disable_discovery
, int, 0);
89 MODULE_PARM_DESC(disable_discovery
, " disable discovery ");
92 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
96 _scsih_set_fwfault_debug(const char *val
, struct kernel_param
*kp
)
98 int ret
= param_set_int(val
, kp
);
99 struct MPT2SAS_ADAPTER
*ioc
;
104 printk(KERN_INFO
"setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug
);
105 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
)
106 ioc
->fwfault_debug
= mpt2sas_fwfault_debug
;
110 module_param_call(mpt2sas_fwfault_debug
, _scsih_set_fwfault_debug
,
111 param_get_int
, &mpt2sas_fwfault_debug
, 0644);
114 * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc
115 * @arg: input argument, used to derive ioc
117 * Return 0 if controller is removed from pci subsystem.
118 * Return -1 for other case.
120 static int mpt2sas_remove_dead_ioc_func(void *arg
)
122 struct MPT2SAS_ADAPTER
*ioc
= (struct MPT2SAS_ADAPTER
*)arg
;
123 struct pci_dev
*pdev
;
131 pci_stop_and_remove_bus_device_locked(pdev
);
137 * _base_fault_reset_work - workq handling ioc fault conditions
138 * @work: input argument, used to derive ioc
144 _base_fault_reset_work(struct work_struct
*work
)
146 struct MPT2SAS_ADAPTER
*ioc
=
147 container_of(work
, struct MPT2SAS_ADAPTER
, fault_reset_work
.work
);
151 struct task_struct
*p
;
153 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
154 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
156 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
158 doorbell
= mpt2sas_base_get_iocstate(ioc
, 0);
159 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_MASK
) {
160 printk(MPT2SAS_INFO_FMT
"%s : SAS host is non-operational !!!!\n",
161 ioc
->name
, __func__
);
163 /* It may be possible that EEH recovery can resolve some of
164 * pci bus failure issues rather removing the dead ioc function
165 * by considering controller is in a non-operational state. So
166 * here priority is given to the EEH recovery. If it doesn't
167 * not resolve this issue, mpt2sas driver will consider this
168 * controller to non-operational state and remove the dead ioc
171 if (ioc
->non_operational_loop
++ < 5) {
172 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
,
178 * Call _scsih_flush_pending_cmds callback so that we flush all
179 * pending commands back to OS. This call is required to aovid
180 * deadlock at block layer. Dead IOC will fail to do diag reset,
181 * and this call is safe since dead ioc will never return any
182 * command back from HW.
184 ioc
->schedule_dead_ioc_flush_running_cmds(ioc
);
186 * Set remove_host flag early since kernel thread will
187 * take some time to execute.
189 ioc
->remove_host
= 1;
190 /*Remove the Dead Host */
191 p
= kthread_run(mpt2sas_remove_dead_ioc_func
, ioc
,
192 "mpt2sas_dead_ioc_%d", ioc
->id
);
194 printk(MPT2SAS_ERR_FMT
195 "%s: Running mpt2sas_dead_ioc thread failed !!!!\n",
196 ioc
->name
, __func__
);
198 printk(MPT2SAS_ERR_FMT
199 "%s: Running mpt2sas_dead_ioc thread success !!!!\n",
200 ioc
->name
, __func__
);
203 return; /* don't rearm timer */
206 ioc
->non_operational_loop
= 0;
208 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
209 rc
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
211 printk(MPT2SAS_WARN_FMT
"%s: hard reset: %s\n", ioc
->name
,
212 __func__
, (rc
== 0) ? "success" : "failed");
213 doorbell
= mpt2sas_base_get_iocstate(ioc
, 0);
214 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
215 mpt2sas_base_fault_info(ioc
, doorbell
&
216 MPI2_DOORBELL_DATA_MASK
);
219 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
221 if (ioc
->fault_reset_work_q
)
222 queue_delayed_work(ioc
->fault_reset_work_q
,
223 &ioc
->fault_reset_work
,
224 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
225 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
229 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
230 * @ioc: per adapter object
236 mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER
*ioc
)
240 if (ioc
->fault_reset_work_q
)
243 /* initialize fault polling */
244 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, _base_fault_reset_work
);
245 snprintf(ioc
->fault_reset_work_q_name
,
246 sizeof(ioc
->fault_reset_work_q_name
), "poll_%d_status", ioc
->id
);
247 ioc
->fault_reset_work_q
=
248 create_singlethread_workqueue(ioc
->fault_reset_work_q_name
);
249 if (!ioc
->fault_reset_work_q
) {
250 printk(MPT2SAS_ERR_FMT
"%s: failed (line=%d)\n",
251 ioc
->name
, __func__
, __LINE__
);
254 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
255 if (ioc
->fault_reset_work_q
)
256 queue_delayed_work(ioc
->fault_reset_work_q
,
257 &ioc
->fault_reset_work
,
258 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
259 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
263 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
264 * @ioc: per adapter object
270 mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER
*ioc
)
273 struct workqueue_struct
*wq
;
275 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
276 wq
= ioc
->fault_reset_work_q
;
277 ioc
->fault_reset_work_q
= NULL
;
278 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
280 if (!cancel_delayed_work(&ioc
->fault_reset_work
))
282 destroy_workqueue(wq
);
287 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
288 * @ioc: per adapter object
289 * @fault_code: fault code
294 mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER
*ioc
, u16 fault_code
)
296 printk(MPT2SAS_ERR_FMT
"fault_state(0x%04x)!\n",
297 ioc
->name
, fault_code
);
301 * mpt2sas_halt_firmware - halt's mpt controller firmware
302 * @ioc: per adapter object
304 * For debugging timeout related issues. Writing 0xCOFFEE00
305 * to the doorbell register will halt controller firmware. With
306 * the purpose to stop both driver and firmware, the enduser can
307 * obtain a ring buffer from controller UART.
310 mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER
*ioc
)
314 if (!ioc
->fwfault_debug
)
319 doorbell
= readl(&ioc
->chip
->Doorbell
);
320 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
321 mpt2sas_base_fault_info(ioc
, doorbell
);
323 writel(0xC0FFEE00, &ioc
->chip
->Doorbell
);
324 printk(MPT2SAS_ERR_FMT
"Firmware is halted due to command "
325 "timeout\n", ioc
->name
);
328 panic("panic in %s\n", __func__
);
331 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
333 * _base_sas_ioc_info - verbose translation of the ioc status
334 * @ioc: per adapter object
335 * @mpi_reply: reply mf payload returned from firmware
336 * @request_hdr: request mf
341 _base_sas_ioc_info(struct MPT2SAS_ADAPTER
*ioc
, MPI2DefaultReply_t
*mpi_reply
,
342 MPI2RequestHeader_t
*request_hdr
)
344 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
348 char *func_str
= NULL
;
350 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
351 if (request_hdr
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
352 request_hdr
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
353 request_hdr
->Function
== MPI2_FUNCTION_EVENT_NOTIFICATION
)
356 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
359 switch (ioc_status
) {
361 /****************************************************************************
362 * Common IOCStatus values for all replies
363 ****************************************************************************/
365 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
366 desc
= "invalid function";
368 case MPI2_IOCSTATUS_BUSY
:
371 case MPI2_IOCSTATUS_INVALID_SGL
:
372 desc
= "invalid sgl";
374 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
375 desc
= "internal error";
377 case MPI2_IOCSTATUS_INVALID_VPID
:
378 desc
= "invalid vpid";
380 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
381 desc
= "insufficient resources";
383 case MPI2_IOCSTATUS_INVALID_FIELD
:
384 desc
= "invalid field";
386 case MPI2_IOCSTATUS_INVALID_STATE
:
387 desc
= "invalid state";
389 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED
:
390 desc
= "op state not supported";
393 /****************************************************************************
394 * Config IOCStatus values
395 ****************************************************************************/
397 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION
:
398 desc
= "config invalid action";
400 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE
:
401 desc
= "config invalid type";
403 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
:
404 desc
= "config invalid page";
406 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA
:
407 desc
= "config invalid data";
409 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS
:
410 desc
= "config no defaults";
412 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT
:
413 desc
= "config cant commit";
416 /****************************************************************************
418 ****************************************************************************/
420 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
421 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
422 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
423 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
424 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
425 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
426 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
427 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
428 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
429 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
430 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
431 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
434 /****************************************************************************
435 * For use by SCSI Initiator and SCSI Target end-to-end data protection
436 ****************************************************************************/
438 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
439 desc
= "eedp guard error";
441 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
442 desc
= "eedp ref tag error";
444 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
445 desc
= "eedp app tag error";
448 /****************************************************************************
450 ****************************************************************************/
452 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX
:
453 desc
= "target invalid io index";
455 case MPI2_IOCSTATUS_TARGET_ABORTED
:
456 desc
= "target aborted";
458 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
:
459 desc
= "target no conn retryable";
461 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION
:
462 desc
= "target no connection";
464 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
:
465 desc
= "target xfer count mismatch";
467 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
:
468 desc
= "target data offset error";
470 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
:
471 desc
= "target too much write data";
473 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT
:
474 desc
= "target iu too short";
476 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
:
477 desc
= "target ack nak timeout";
479 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED
:
480 desc
= "target nak received";
483 /****************************************************************************
484 * Serial Attached SCSI values
485 ****************************************************************************/
487 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED
:
488 desc
= "smp request failed";
490 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN
:
491 desc
= "smp data overrun";
494 /****************************************************************************
495 * Diagnostic Buffer Post / Diagnostic Release values
496 ****************************************************************************/
498 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
:
499 desc
= "diagnostic released";
508 switch (request_hdr
->Function
) {
509 case MPI2_FUNCTION_CONFIG
:
510 frame_sz
= sizeof(Mpi2ConfigRequest_t
) + ioc
->sge_size
;
511 func_str
= "config_page";
513 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
514 frame_sz
= sizeof(Mpi2SCSITaskManagementRequest_t
);
515 func_str
= "task_mgmt";
517 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
518 frame_sz
= sizeof(Mpi2SasIoUnitControlRequest_t
);
519 func_str
= "sas_iounit_ctl";
521 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
522 frame_sz
= sizeof(Mpi2SepRequest_t
);
523 func_str
= "enclosure";
525 case MPI2_FUNCTION_IOC_INIT
:
526 frame_sz
= sizeof(Mpi2IOCInitRequest_t
);
527 func_str
= "ioc_init";
529 case MPI2_FUNCTION_PORT_ENABLE
:
530 frame_sz
= sizeof(Mpi2PortEnableRequest_t
);
531 func_str
= "port_enable";
533 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
534 frame_sz
= sizeof(Mpi2SmpPassthroughRequest_t
) + ioc
->sge_size
;
535 func_str
= "smp_passthru";
539 func_str
= "unknown";
543 printk(MPT2SAS_WARN_FMT
"ioc_status: %s(0x%04x), request(0x%p),"
544 " (%s)\n", ioc
->name
, desc
, ioc_status
, request_hdr
, func_str
);
546 _debug_dump_mf(request_hdr
, frame_sz
/4);
550 * _base_display_event_data - verbose translation of firmware asyn events
551 * @ioc: per adapter object
552 * @mpi_reply: reply mf payload returned from firmware
557 _base_display_event_data(struct MPT2SAS_ADAPTER
*ioc
,
558 Mpi2EventNotificationReply_t
*mpi_reply
)
563 if (!(ioc
->logging_level
& MPT_DEBUG_EVENTS
))
566 event
= le16_to_cpu(mpi_reply
->Event
);
569 case MPI2_EVENT_LOG_DATA
:
572 case MPI2_EVENT_STATE_CHANGE
:
573 desc
= "Status Change";
575 case MPI2_EVENT_HARD_RESET_RECEIVED
:
576 desc
= "Hard Reset Received";
578 case MPI2_EVENT_EVENT_CHANGE
:
579 desc
= "Event Change";
581 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
582 desc
= "Device Status Change";
584 case MPI2_EVENT_IR_OPERATION_STATUS
:
585 if (!ioc
->hide_ir_msg
)
586 desc
= "IR Operation Status";
588 case MPI2_EVENT_SAS_DISCOVERY
:
590 Mpi2EventDataSasDiscovery_t
*event_data
=
591 (Mpi2EventDataSasDiscovery_t
*)mpi_reply
->EventData
;
592 printk(MPT2SAS_INFO_FMT
"Discovery: (%s)", ioc
->name
,
593 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
595 if (event_data
->DiscoveryStatus
)
596 printk("discovery_status(0x%08x)",
597 le32_to_cpu(event_data
->DiscoveryStatus
));
601 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
602 desc
= "SAS Broadcast Primitive";
604 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
605 desc
= "SAS Init Device Status Change";
607 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW
:
608 desc
= "SAS Init Table Overflow";
610 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
611 desc
= "SAS Topology Change List";
613 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
614 desc
= "SAS Enclosure Device Status Change";
616 case MPI2_EVENT_IR_VOLUME
:
617 if (!ioc
->hide_ir_msg
)
620 case MPI2_EVENT_IR_PHYSICAL_DISK
:
621 if (!ioc
->hide_ir_msg
)
622 desc
= "IR Physical Disk";
624 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
625 if (!ioc
->hide_ir_msg
)
626 desc
= "IR Configuration Change List";
628 case MPI2_EVENT_LOG_ENTRY_ADDED
:
629 if (!ioc
->hide_ir_msg
)
630 desc
= "Log Entry Added";
637 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
, desc
);
642 * _base_sas_log_info - verbose translation of firmware log info
643 * @ioc: per adapter object
644 * @log_info: log info
649 _base_sas_log_info(struct MPT2SAS_ADAPTER
*ioc
, u32 log_info
)
660 union loginfo_type sas_loginfo
;
661 char *originator_str
= NULL
;
663 sas_loginfo
.loginfo
= log_info
;
664 if (sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/)
667 /* each nexus loss loginfo */
668 if (log_info
== 0x31170000)
671 /* eat the loginfos associated with task aborts */
672 if (ioc
->ignore_loginfos
&& (log_info
== 0x30050000 || log_info
==
673 0x31140000 || log_info
== 0x31130000))
676 switch (sas_loginfo
.dw
.originator
) {
678 originator_str
= "IOP";
681 originator_str
= "PL";
684 if (!ioc
->hide_ir_msg
)
685 originator_str
= "IR";
687 originator_str
= "WarpDrive";
691 printk(MPT2SAS_WARN_FMT
"log_info(0x%08x): originator(%s), "
692 "code(0x%02x), sub_code(0x%04x)\n", ioc
->name
, log_info
,
693 originator_str
, sas_loginfo
.dw
.code
,
694 sas_loginfo
.dw
.subcode
);
698 * _base_display_reply_info -
699 * @ioc: per adapter object
700 * @smid: system request message index
701 * @msix_index: MSIX table index supplied by the OS
702 * @reply: reply message frame(lower 32bit addr)
707 _base_display_reply_info(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
710 MPI2DefaultReply_t
*mpi_reply
;
713 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
714 if (unlikely(!mpi_reply
)) {
715 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
716 ioc
->name
, __FILE__
, __LINE__
, __func__
);
719 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
720 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
721 if ((ioc_status
& MPI2_IOCSTATUS_MASK
) &&
722 (ioc
->logging_level
& MPT_DEBUG_REPLY
)) {
723 _base_sas_ioc_info(ioc
, mpi_reply
,
724 mpt2sas_base_get_msg_frame(ioc
, smid
));
727 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
)
728 _base_sas_log_info(ioc
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
732 * mpt2sas_base_done - base internal command completion routine
733 * @ioc: per adapter object
734 * @smid: system request message index
735 * @msix_index: MSIX table index supplied by the OS
736 * @reply: reply message frame(lower 32bit addr)
738 * Return 1 meaning mf should be freed from _base_interrupt
739 * 0 means the mf is freed from this function.
742 mpt2sas_base_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
745 MPI2DefaultReply_t
*mpi_reply
;
747 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
748 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
751 if (ioc
->base_cmds
.status
== MPT2_CMD_NOT_USED
)
754 ioc
->base_cmds
.status
|= MPT2_CMD_COMPLETE
;
756 ioc
->base_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
757 memcpy(ioc
->base_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
759 ioc
->base_cmds
.status
&= ~MPT2_CMD_PENDING
;
761 complete(&ioc
->base_cmds
.done
);
766 * _base_async_event - main callback handler for firmware asyn events
767 * @ioc: per adapter object
768 * @msix_index: MSIX table index supplied by the OS
769 * @reply: reply message frame(lower 32bit addr)
774 _base_async_event(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
, u32 reply
)
776 Mpi2EventNotificationReply_t
*mpi_reply
;
777 Mpi2EventAckRequest_t
*ack_request
;
780 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
783 if (mpi_reply
->Function
!= MPI2_FUNCTION_EVENT_NOTIFICATION
)
785 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
786 _base_display_event_data(ioc
, mpi_reply
);
788 if (!(mpi_reply
->AckRequired
& MPI2_EVENT_NOTIFICATION_ACK_REQUIRED
))
790 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
792 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
793 ioc
->name
, __func__
);
797 ack_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
798 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
799 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
800 ack_request
->Event
= mpi_reply
->Event
;
801 ack_request
->EventContext
= mpi_reply
->EventContext
;
802 ack_request
->VF_ID
= 0; /* TODO */
803 ack_request
->VP_ID
= 0;
804 mpt2sas_base_put_smid_default(ioc
, smid
);
808 /* scsih callback handler */
809 mpt2sas_scsih_event_callback(ioc
, msix_index
, reply
);
811 /* ctl callback handler */
812 mpt2sas_ctl_event_callback(ioc
, msix_index
, reply
);
818 * _base_get_cb_idx - obtain the callback index
819 * @ioc: per adapter object
820 * @smid: system request message index
822 * Return callback index.
825 _base_get_cb_idx(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
830 if (smid
< ioc
->hi_priority_smid
) {
832 cb_idx
= ioc
->scsi_lookup
[i
].cb_idx
;
833 } else if (smid
< ioc
->internal_smid
) {
834 i
= smid
- ioc
->hi_priority_smid
;
835 cb_idx
= ioc
->hpr_lookup
[i
].cb_idx
;
836 } else if (smid
<= ioc
->hba_queue_depth
) {
837 i
= smid
- ioc
->internal_smid
;
838 cb_idx
= ioc
->internal_lookup
[i
].cb_idx
;
845 * _base_mask_interrupts - disable interrupts
846 * @ioc: per adapter object
848 * Disabling ResetIRQ, Reply and Doorbell Interrupts
853 _base_mask_interrupts(struct MPT2SAS_ADAPTER
*ioc
)
857 ioc
->mask_interrupts
= 1;
858 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
859 him_register
|= MPI2_HIM_DIM
+ MPI2_HIM_RIM
+ MPI2_HIM_RESET_IRQ_MASK
;
860 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
861 readl(&ioc
->chip
->HostInterruptMask
);
865 * _base_unmask_interrupts - enable interrupts
866 * @ioc: per adapter object
868 * Enabling only Reply Interrupts
873 _base_unmask_interrupts(struct MPT2SAS_ADAPTER
*ioc
)
877 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
878 him_register
&= ~MPI2_HIM_RIM
;
879 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
880 ioc
->mask_interrupts
= 0;
883 union reply_descriptor
{
892 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
893 * @irq: irq number (not used)
894 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
895 * @r: pt_regs pointer (not used)
897 * Return IRQ_HANDLE if processed, else IRQ_NONE.
900 _base_interrupt(int irq
, void *bus_id
)
902 struct adapter_reply_queue
*reply_q
= bus_id
;
903 union reply_descriptor rd
;
905 u8 request_desript_type
;
909 u8 msix_index
= reply_q
->msix_index
;
910 struct MPT2SAS_ADAPTER
*ioc
= reply_q
->ioc
;
911 Mpi2ReplyDescriptorsUnion_t
*rpf
;
914 if (ioc
->mask_interrupts
)
917 if (!atomic_add_unless(&reply_q
->busy
, 1, 1))
920 rpf
= &reply_q
->reply_post_free
[reply_q
->reply_post_host_index
];
921 request_desript_type
= rpf
->Default
.ReplyFlags
922 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
923 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
) {
924 atomic_dec(&reply_q
->busy
);
931 rd
.word
= le64_to_cpu(rpf
->Words
);
932 if (rd
.u
.low
== UINT_MAX
|| rd
.u
.high
== UINT_MAX
)
935 smid
= le16_to_cpu(rpf
->Default
.DescriptorTypeDependent1
);
936 if (request_desript_type
==
937 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY
) {
939 (rpf
->AddressReply
.ReplyFrameAddress
);
940 if (reply
> ioc
->reply_dma_max_address
||
941 reply
< ioc
->reply_dma_min_address
)
943 } else if (request_desript_type
==
944 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER
)
946 else if (request_desript_type
==
947 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS
)
950 cb_idx
= _base_get_cb_idx(ioc
, smid
);
951 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
))
952 && (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
953 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
956 _base_display_reply_info(ioc
, smid
,
959 mpt2sas_base_free_smid(ioc
, smid
);
963 _base_async_event(ioc
, msix_index
, reply
);
965 /* reply free queue handling */
967 ioc
->reply_free_host_index
=
968 (ioc
->reply_free_host_index
==
969 (ioc
->reply_free_queue_depth
- 1)) ?
970 0 : ioc
->reply_free_host_index
+ 1;
971 ioc
->reply_free
[ioc
->reply_free_host_index
] =
974 writel(ioc
->reply_free_host_index
,
975 &ioc
->chip
->ReplyFreeHostIndex
);
980 rpf
->Words
= cpu_to_le64(ULLONG_MAX
);
981 reply_q
->reply_post_host_index
=
982 (reply_q
->reply_post_host_index
==
983 (ioc
->reply_post_queue_depth
- 1)) ? 0 :
984 reply_q
->reply_post_host_index
+ 1;
985 request_desript_type
=
986 reply_q
->reply_post_free
[reply_q
->reply_post_host_index
].
987 Default
.ReplyFlags
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
989 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
991 if (!reply_q
->reply_post_host_index
)
992 rpf
= reply_q
->reply_post_free
;
999 if (!completed_cmds
) {
1000 atomic_dec(&reply_q
->busy
);
1004 if (ioc
->is_warpdrive
) {
1005 writel(reply_q
->reply_post_host_index
,
1006 ioc
->reply_post_host_index
[msix_index
]);
1007 atomic_dec(&reply_q
->busy
);
1010 writel(reply_q
->reply_post_host_index
| (msix_index
<<
1011 MPI2_RPHI_MSIX_INDEX_SHIFT
), &ioc
->chip
->ReplyPostHostIndex
);
1012 atomic_dec(&reply_q
->busy
);
1017 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1018 * @ioc: per adapter object
1022 _base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER
*ioc
)
1024 return (ioc
->facts
.IOCCapabilities
&
1025 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
;
1029 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
1030 * @ioc: per adapter object
1031 * Context: ISR conext
1033 * Called when a Task Management request has completed. We want
1034 * to flush the other reply queues so all the outstanding IO has been
1035 * completed back to OS before we process the TM completetion.
1040 mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER
*ioc
)
1042 struct adapter_reply_queue
*reply_q
;
1044 /* If MSIX capability is turned off
1045 * then multi-queues are not enabled
1047 if (!_base_is_controller_msix_enabled(ioc
))
1050 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1051 if (ioc
->shost_recovery
)
1053 /* TMs are on msix_index == 0 */
1054 if (reply_q
->msix_index
== 0)
1056 _base_interrupt(reply_q
->vector
, (void *)reply_q
);
1061 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
1062 * @cb_idx: callback index
1067 mpt2sas_base_release_callback_handler(u8 cb_idx
)
1069 mpt_callbacks
[cb_idx
] = NULL
;
1073 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1074 * @cb_func: callback function
1079 mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func
)
1083 for (cb_idx
= MPT_MAX_CALLBACKS
-1; cb_idx
; cb_idx
--)
1084 if (mpt_callbacks
[cb_idx
] == NULL
)
1087 mpt_callbacks
[cb_idx
] = cb_func
;
1092 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1097 mpt2sas_base_initialize_callback_handler(void)
1101 for (cb_idx
= 0; cb_idx
< MPT_MAX_CALLBACKS
; cb_idx
++)
1102 mpt2sas_base_release_callback_handler(cb_idx
);
1106 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1107 * @ioc: per adapter object
1108 * @paddr: virtual address for SGE
1110 * Create a zero length scatter gather entry to insure the IOCs hardware has
1111 * something to use if the target device goes brain dead and tries
1112 * to send data even when none is asked for.
1117 mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER
*ioc
, void *paddr
)
1119 u32 flags_length
= (u32
)((MPI2_SGE_FLAGS_LAST_ELEMENT
|
1120 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
|
1121 MPI2_SGE_FLAGS_SIMPLE_ELEMENT
) <<
1122 MPI2_SGE_FLAGS_SHIFT
);
1123 ioc
->base_add_sg_single(paddr
, flags_length
, -1);
1127 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1128 * @paddr: virtual address for SGE
1129 * @flags_length: SGE flags and data transfer length
1130 * @dma_addr: Physical address
1135 _base_add_sg_single_32(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1137 Mpi2SGESimple32_t
*sgel
= paddr
;
1139 flags_length
|= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING
|
1140 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1141 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1142 sgel
->Address
= cpu_to_le32(dma_addr
);
1147 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1148 * @paddr: virtual address for SGE
1149 * @flags_length: SGE flags and data transfer length
1150 * @dma_addr: Physical address
1155 _base_add_sg_single_64(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1157 Mpi2SGESimple64_t
*sgel
= paddr
;
1159 flags_length
|= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING
|
1160 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1161 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1162 sgel
->Address
= cpu_to_le64(dma_addr
);
1165 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1168 * _base_config_dma_addressing - set dma addressing
1169 * @ioc: per adapter object
1170 * @pdev: PCI device struct
1172 * Returns 0 for success, non-zero for failure.
1175 _base_config_dma_addressing(struct MPT2SAS_ADAPTER
*ioc
, struct pci_dev
*pdev
)
1180 if (sizeof(dma_addr_t
) > 4) {
1181 const uint64_t required_mask
=
1182 dma_get_required_mask(&pdev
->dev
);
1183 if ((required_mask
> DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev
,
1184 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev
,
1185 DMA_BIT_MASK(64))) {
1186 ioc
->base_add_sg_single
= &_base_add_sg_single_64
;
1187 ioc
->sge_size
= sizeof(Mpi2SGESimple64_t
);
1193 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1194 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1195 ioc
->base_add_sg_single
= &_base_add_sg_single_32
;
1196 ioc
->sge_size
= sizeof(Mpi2SGESimple32_t
);
1203 printk(MPT2SAS_INFO_FMT
"%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1204 "total mem (%ld kB)\n", ioc
->name
, desc
, convert_to_kb(s
.totalram
));
1210 * _base_check_enable_msix - checks MSIX capabable.
1211 * @ioc: per adapter object
1213 * Check to see if card is capable of MSIX, and set number
1214 * of available msix vectors
1217 _base_check_enable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1220 u16 message_control
;
1223 /* Check whether controller SAS2008 B0 controller,
1224 if it is SAS2008 B0 controller use IO-APIC instead of MSIX */
1225 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
&&
1226 ioc
->pdev
->revision
== 0x01) {
1230 base
= pci_find_capability(ioc
->pdev
, PCI_CAP_ID_MSIX
);
1232 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"msix not "
1233 "supported\n", ioc
->name
));
1237 /* get msix vector count */
1238 /* NUMA_IO not supported for older controllers */
1239 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2004
||
1240 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
||
1241 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_1
||
1242 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_2
||
1243 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_3
||
1244 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_1
||
1245 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_2
)
1246 ioc
->msix_vector_count
= 1;
1248 pci_read_config_word(ioc
->pdev
, base
+ 2, &message_control
);
1249 ioc
->msix_vector_count
= (message_control
& 0x3FF) + 1;
1251 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"msix is supported, "
1252 "vector_count(%d)\n", ioc
->name
, ioc
->msix_vector_count
));
1258 * _base_free_irq - free irq
1259 * @ioc: per adapter object
1261 * Freeing respective reply_queue from the list.
1264 _base_free_irq(struct MPT2SAS_ADAPTER
*ioc
)
1266 struct adapter_reply_queue
*reply_q
, *next
;
1268 if (list_empty(&ioc
->reply_queue_list
))
1271 list_for_each_entry_safe(reply_q
, next
, &ioc
->reply_queue_list
, list
) {
1272 list_del(&reply_q
->list
);
1273 synchronize_irq(reply_q
->vector
);
1274 free_irq(reply_q
->vector
, reply_q
);
1280 * _base_request_irq - request irq
1281 * @ioc: per adapter object
1282 * @index: msix index into vector table
1283 * @vector: irq vector
1285 * Inserting respective reply_queue into the list.
1288 _base_request_irq(struct MPT2SAS_ADAPTER
*ioc
, u8 index
, u32 vector
)
1290 struct adapter_reply_queue
*reply_q
;
1293 reply_q
= kzalloc(sizeof(struct adapter_reply_queue
), GFP_KERNEL
);
1295 printk(MPT2SAS_ERR_FMT
"unable to allocate memory %d!\n",
1296 ioc
->name
, (int)sizeof(struct adapter_reply_queue
));
1300 reply_q
->msix_index
= index
;
1301 reply_q
->vector
= vector
;
1302 atomic_set(&reply_q
->busy
, 0);
1303 if (ioc
->msix_enable
)
1304 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d-msix%d",
1305 MPT2SAS_DRIVER_NAME
, ioc
->id
, index
);
1307 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d",
1308 MPT2SAS_DRIVER_NAME
, ioc
->id
);
1309 r
= request_irq(vector
, _base_interrupt
, IRQF_SHARED
, reply_q
->name
,
1312 printk(MPT2SAS_ERR_FMT
"unable to allocate interrupt %d!\n",
1313 reply_q
->name
, vector
);
1318 INIT_LIST_HEAD(&reply_q
->list
);
1319 list_add_tail(&reply_q
->list
, &ioc
->reply_queue_list
);
1324 * _base_assign_reply_queues - assigning msix index for each cpu
1325 * @ioc: per adapter object
1327 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1329 * It would nice if we could call irq_set_affinity, however it is not
1330 * an exported symbol
1333 _base_assign_reply_queues(struct MPT2SAS_ADAPTER
*ioc
)
1335 struct adapter_reply_queue
*reply_q
;
1337 int cpu_grouping
, loop
, grouping
, grouping_mod
;
1339 if (!_base_is_controller_msix_enabled(ioc
))
1342 memset(ioc
->cpu_msix_table
, 0, ioc
->cpu_msix_table_sz
);
1343 /* when there are more cpus than available msix vectors,
1344 * then group cpus togeather on same irq
1346 if (ioc
->cpu_count
> ioc
->msix_vector_count
) {
1347 grouping
= ioc
->cpu_count
/ ioc
->msix_vector_count
;
1348 grouping_mod
= ioc
->cpu_count
% ioc
->msix_vector_count
;
1349 if (grouping
< 2 || (grouping
== 2 && !grouping_mod
))
1351 else if (grouping
< 4 || (grouping
== 4 && !grouping_mod
))
1353 else if (grouping
< 8 || (grouping
== 8 && !grouping_mod
))
1361 reply_q
= list_entry(ioc
->reply_queue_list
.next
,
1362 struct adapter_reply_queue
, list
);
1363 for_each_online_cpu(cpu_id
) {
1364 if (!cpu_grouping
) {
1365 ioc
->cpu_msix_table
[cpu_id
] = reply_q
->msix_index
;
1366 reply_q
= list_entry(reply_q
->list
.next
,
1367 struct adapter_reply_queue
, list
);
1369 if (loop
< cpu_grouping
) {
1370 ioc
->cpu_msix_table
[cpu_id
] =
1371 reply_q
->msix_index
;
1374 reply_q
= list_entry(reply_q
->list
.next
,
1375 struct adapter_reply_queue
, list
);
1376 ioc
->cpu_msix_table
[cpu_id
] =
1377 reply_q
->msix_index
;
1385 * _base_disable_msix - disables msix
1386 * @ioc: per adapter object
1390 _base_disable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1392 if (ioc
->msix_enable
) {
1393 pci_disable_msix(ioc
->pdev
);
1394 ioc
->msix_enable
= 0;
1399 * _base_enable_msix - enables msix, failback to io_apic
1400 * @ioc: per adapter object
1404 _base_enable_msix(struct MPT2SAS_ADAPTER
*ioc
)
1406 struct msix_entry
*entries
, *a
;
1411 if (msix_disable
== -1 || msix_disable
== 0)
1417 if (_base_check_enable_msix(ioc
) != 0)
1420 ioc
->reply_queue_count
= min_t(int, ioc
->cpu_count
,
1421 ioc
->msix_vector_count
);
1423 entries
= kcalloc(ioc
->reply_queue_count
, sizeof(struct msix_entry
),
1426 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"kcalloc "
1427 "failed @ at %s:%d/%s() !!!\n", ioc
->name
, __FILE__
,
1428 __LINE__
, __func__
));
1432 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++)
1435 r
= pci_enable_msix(ioc
->pdev
, entries
, ioc
->reply_queue_count
);
1437 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"pci_enable_msix "
1438 "failed (r=%d) !!!\n", ioc
->name
, r
));
1443 ioc
->msix_enable
= 1;
1444 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++) {
1445 r
= _base_request_irq(ioc
, i
, a
->vector
);
1447 _base_free_irq(ioc
);
1448 _base_disable_msix(ioc
);
1457 /* failback to io_apic interrupt routing */
1460 r
= _base_request_irq(ioc
, 0, ioc
->pdev
->irq
);
1466 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1467 * @ioc: per adapter object
1469 * Returns 0 for success, non-zero for failure.
1472 mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER
*ioc
)
1474 struct pci_dev
*pdev
= ioc
->pdev
;
1480 struct adapter_reply_queue
*reply_q
;
1482 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n",
1483 ioc
->name
, __func__
));
1485 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1486 if (pci_enable_device_mem(pdev
)) {
1487 printk(MPT2SAS_WARN_FMT
"pci_enable_device_mem: "
1488 "failed\n", ioc
->name
);
1494 if (pci_request_selected_regions(pdev
, ioc
->bars
,
1495 MPT2SAS_DRIVER_NAME
)) {
1496 printk(MPT2SAS_WARN_FMT
"pci_request_selected_regions: "
1497 "failed\n", ioc
->name
);
1503 /* AER (Advanced Error Reporting) hooks */
1504 pci_enable_pcie_error_reporting(pdev
);
1506 pci_set_master(pdev
);
1508 if (_base_config_dma_addressing(ioc
, pdev
) != 0) {
1509 printk(MPT2SAS_WARN_FMT
"no suitable DMA mask for %s\n",
1510 ioc
->name
, pci_name(pdev
));
1515 for (i
= 0, memap_sz
= 0, pio_sz
= 0 ; i
< DEVICE_COUNT_RESOURCE
; i
++) {
1516 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
1519 pio_chip
= (u64
)pci_resource_start(pdev
, i
);
1520 pio_sz
= pci_resource_len(pdev
, i
);
1524 /* verify memory resource is valid before using */
1525 if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
1526 ioc
->chip_phys
= pci_resource_start(pdev
, i
);
1527 chip_phys
= (u64
)ioc
->chip_phys
;
1528 memap_sz
= pci_resource_len(pdev
, i
);
1529 ioc
->chip
= ioremap(ioc
->chip_phys
, memap_sz
);
1530 if (ioc
->chip
== NULL
) {
1531 printk(MPT2SAS_ERR_FMT
"unable to map "
1532 "adapter memory!\n", ioc
->name
);
1540 _base_mask_interrupts(ioc
);
1541 r
= _base_enable_msix(ioc
);
1545 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
)
1546 printk(MPT2SAS_INFO_FMT
"%s: IRQ %d\n",
1547 reply_q
->name
, ((ioc
->msix_enable
) ? "PCI-MSI-X enabled" :
1548 "IO-APIC enabled"), reply_q
->vector
);
1550 printk(MPT2SAS_INFO_FMT
"iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1551 ioc
->name
, (unsigned long long)chip_phys
, ioc
->chip
, memap_sz
);
1552 printk(MPT2SAS_INFO_FMT
"ioport(0x%016llx), size(%d)\n",
1553 ioc
->name
, (unsigned long long)pio_chip
, pio_sz
);
1555 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1556 pci_save_state(pdev
);
1564 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
1565 pci_disable_pcie_error_reporting(pdev
);
1566 pci_disable_device(pdev
);
1571 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1572 * @ioc: per adapter object
1573 * @smid: system request message index(smid zero is invalid)
1575 * Returns virt pointer to message frame.
1578 mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1580 return (void *)(ioc
->request
+ (smid
* ioc
->request_sz
));
1584 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1585 * @ioc: per adapter object
1586 * @smid: system request message index
1588 * Returns virt pointer to sense buffer.
1591 mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1593 return (void *)(ioc
->sense
+ ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1597 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1598 * @ioc: per adapter object
1599 * @smid: system request message index
1601 * Returns phys pointer to the low 32bit address of the sense buffer.
1604 mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1606 return cpu_to_le32(ioc
->sense_dma
+
1607 ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1611 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1612 * @ioc: per adapter object
1613 * @phys_addr: lower 32 physical addr of the reply
1615 * Converts 32bit lower physical addr into a virt address.
1618 mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER
*ioc
, u32 phys_addr
)
1622 return ioc
->reply
+ (phys_addr
- (u32
)ioc
->reply_dma
);
1626 * mpt2sas_base_get_smid - obtain a free smid from internal queue
1627 * @ioc: per adapter object
1628 * @cb_idx: callback index
1630 * Returns smid (zero is invalid)
1633 mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
)
1635 unsigned long flags
;
1636 struct request_tracker
*request
;
1639 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1640 if (list_empty(&ioc
->internal_free_list
)) {
1641 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1642 printk(MPT2SAS_ERR_FMT
"%s: smid not available\n",
1643 ioc
->name
, __func__
);
1647 request
= list_entry(ioc
->internal_free_list
.next
,
1648 struct request_tracker
, tracker_list
);
1649 request
->cb_idx
= cb_idx
;
1650 smid
= request
->smid
;
1651 list_del(&request
->tracker_list
);
1652 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1657 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1658 * @ioc: per adapter object
1659 * @cb_idx: callback index
1660 * @scmd: pointer to scsi command object
1662 * Returns smid (zero is invalid)
1665 mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
,
1666 struct scsi_cmnd
*scmd
)
1668 unsigned long flags
;
1669 struct scsiio_tracker
*request
;
1672 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1673 if (list_empty(&ioc
->free_list
)) {
1674 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1675 printk(MPT2SAS_ERR_FMT
"%s: smid not available\n",
1676 ioc
->name
, __func__
);
1680 request
= list_entry(ioc
->free_list
.next
,
1681 struct scsiio_tracker
, tracker_list
);
1682 request
->scmd
= scmd
;
1683 request
->cb_idx
= cb_idx
;
1684 smid
= request
->smid
;
1685 list_del(&request
->tracker_list
);
1686 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1691 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1692 * @ioc: per adapter object
1693 * @cb_idx: callback index
1695 * Returns smid (zero is invalid)
1698 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER
*ioc
, u8 cb_idx
)
1700 unsigned long flags
;
1701 struct request_tracker
*request
;
1704 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1705 if (list_empty(&ioc
->hpr_free_list
)) {
1706 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1710 request
= list_entry(ioc
->hpr_free_list
.next
,
1711 struct request_tracker
, tracker_list
);
1712 request
->cb_idx
= cb_idx
;
1713 smid
= request
->smid
;
1714 list_del(&request
->tracker_list
);
1715 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1721 * mpt2sas_base_free_smid - put smid back on free_list
1722 * @ioc: per adapter object
1723 * @smid: system request message index
1728 mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1730 unsigned long flags
;
1732 struct chain_tracker
*chain_req
, *next
;
1734 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1735 if (smid
< ioc
->hi_priority_smid
) {
1738 if (!list_empty(&ioc
->scsi_lookup
[i
].chain_list
)) {
1739 list_for_each_entry_safe(chain_req
, next
,
1740 &ioc
->scsi_lookup
[i
].chain_list
, tracker_list
) {
1741 list_del_init(&chain_req
->tracker_list
);
1742 list_add_tail(&chain_req
->tracker_list
,
1743 &ioc
->free_chain_list
);
1746 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
1747 ioc
->scsi_lookup
[i
].scmd
= NULL
;
1748 ioc
->scsi_lookup
[i
].direct_io
= 0;
1749 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
1751 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1754 * See _wait_for_commands_to_complete() call with regards
1757 if (ioc
->shost_recovery
&& ioc
->pending_io_count
) {
1758 if (ioc
->pending_io_count
== 1)
1759 wake_up(&ioc
->reset_wq
);
1760 ioc
->pending_io_count
--;
1763 } else if (smid
< ioc
->internal_smid
) {
1765 i
= smid
- ioc
->hi_priority_smid
;
1766 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
1767 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
1768 &ioc
->hpr_free_list
);
1769 } else if (smid
<= ioc
->hba_queue_depth
) {
1770 /* internal queue */
1771 i
= smid
- ioc
->internal_smid
;
1772 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
1773 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
1774 &ioc
->internal_free_list
);
1776 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1780 * _base_writeq - 64 bit write to MMIO
1781 * @ioc: per adapter object
1783 * @addr: address in MMIO space
1784 * @writeq_lock: spin lock
1786 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1787 * care of 32 bit environment where its not quarenteed to send the entire word
1791 static inline void _base_writeq(__u64 b
, volatile void __iomem
*addr
,
1792 spinlock_t
*writeq_lock
)
1794 unsigned long flags
;
1795 __u64 data_out
= cpu_to_le64(b
);
1797 spin_lock_irqsave(writeq_lock
, flags
);
1798 writel((u32
)(data_out
), addr
);
1799 writel((u32
)(data_out
>> 32), (addr
+ 4));
1800 spin_unlock_irqrestore(writeq_lock
, flags
);
1803 static inline void _base_writeq(__u64 b
, volatile void __iomem
*addr
,
1804 spinlock_t
*writeq_lock
)
1806 writeq(cpu_to_le64(b
), addr
);
1811 _base_get_msix_index(struct MPT2SAS_ADAPTER
*ioc
)
1813 return ioc
->cpu_msix_table
[raw_smp_processor_id()];
1817 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1818 * @ioc: per adapter object
1819 * @smid: system request message index
1820 * @handle: device handle
1825 mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u16 handle
)
1827 Mpi2RequestDescriptorUnion_t descriptor
;
1828 u64
*request
= (u64
*)&descriptor
;
1831 descriptor
.SCSIIO
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
1832 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
1833 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
1834 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
1835 descriptor
.SCSIIO
.LMID
= 0;
1836 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1837 &ioc
->scsi_lookup_lock
);
1842 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
1843 * @ioc: per adapter object
1844 * @smid: system request message index
1849 mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1851 Mpi2RequestDescriptorUnion_t descriptor
;
1852 u64
*request
= (u64
*)&descriptor
;
1854 descriptor
.HighPriority
.RequestFlags
=
1855 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
1856 descriptor
.HighPriority
.MSIxIndex
= 0;
1857 descriptor
.HighPriority
.SMID
= cpu_to_le16(smid
);
1858 descriptor
.HighPriority
.LMID
= 0;
1859 descriptor
.HighPriority
.Reserved1
= 0;
1860 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1861 &ioc
->scsi_lookup_lock
);
1865 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1866 * @ioc: per adapter object
1867 * @smid: system request message index
1872 mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
)
1874 Mpi2RequestDescriptorUnion_t descriptor
;
1875 u64
*request
= (u64
*)&descriptor
;
1877 descriptor
.Default
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
1878 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
1879 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
1880 descriptor
.Default
.LMID
= 0;
1881 descriptor
.Default
.DescriptorTypeDependent
= 0;
1882 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1883 &ioc
->scsi_lookup_lock
);
1887 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1888 * @ioc: per adapter object
1889 * @smid: system request message index
1890 * @io_index: value used to track the IO
1895 mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
1898 Mpi2RequestDescriptorUnion_t descriptor
;
1899 u64
*request
= (u64
*)&descriptor
;
1901 descriptor
.SCSITarget
.RequestFlags
=
1902 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET
;
1903 descriptor
.SCSITarget
.MSIxIndex
= _base_get_msix_index(ioc
);
1904 descriptor
.SCSITarget
.SMID
= cpu_to_le16(smid
);
1905 descriptor
.SCSITarget
.LMID
= 0;
1906 descriptor
.SCSITarget
.IoIndex
= cpu_to_le16(io_index
);
1907 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
1908 &ioc
->scsi_lookup_lock
);
1912 * _base_display_dell_branding - Disply branding string
1913 * @ioc: per adapter object
1918 _base_display_dell_branding(struct MPT2SAS_ADAPTER
*ioc
)
1920 char dell_branding
[MPT2SAS_DELL_BRANDING_SIZE
];
1922 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_DELL
)
1925 memset(dell_branding
, 0, MPT2SAS_DELL_BRANDING_SIZE
);
1926 switch (ioc
->pdev
->subsystem_device
) {
1927 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID
:
1928 strncpy(dell_branding
, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING
,
1929 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1931 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID
:
1932 strncpy(dell_branding
, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING
,
1933 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1935 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID
:
1936 strncpy(dell_branding
,
1937 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING
,
1938 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1940 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID
:
1941 strncpy(dell_branding
,
1942 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING
,
1943 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1945 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID
:
1946 strncpy(dell_branding
,
1947 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING
,
1948 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1950 case MPT2SAS_DELL_PERC_H200_SSDID
:
1951 strncpy(dell_branding
, MPT2SAS_DELL_PERC_H200_BRANDING
,
1952 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1954 case MPT2SAS_DELL_6GBPS_SAS_SSDID
:
1955 strncpy(dell_branding
, MPT2SAS_DELL_6GBPS_SAS_BRANDING
,
1956 MPT2SAS_DELL_BRANDING_SIZE
- 1);
1959 sprintf(dell_branding
, "0x%4X", ioc
->pdev
->subsystem_device
);
1963 printk(MPT2SAS_INFO_FMT
"%s: Vendor(0x%04X), Device(0x%04X),"
1964 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc
->name
, dell_branding
,
1965 ioc
->pdev
->vendor
, ioc
->pdev
->device
, ioc
->pdev
->subsystem_vendor
,
1966 ioc
->pdev
->subsystem_device
);
1970 * _base_display_intel_branding - Display branding string
1971 * @ioc: per adapter object
1976 _base_display_intel_branding(struct MPT2SAS_ADAPTER
*ioc
)
1978 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
1981 switch (ioc
->pdev
->device
) {
1982 case MPI2_MFGPAGE_DEVID_SAS2008
:
1983 switch (ioc
->pdev
->subsystem_device
) {
1984 case MPT2SAS_INTEL_RMS2LL080_SSDID
:
1985 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1986 MPT2SAS_INTEL_RMS2LL080_BRANDING
);
1988 case MPT2SAS_INTEL_RMS2LL040_SSDID
:
1989 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1990 MPT2SAS_INTEL_RMS2LL040_BRANDING
);
1992 case MPT2SAS_INTEL_SSD910_SSDID
:
1993 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1994 MPT2SAS_INTEL_SSD910_BRANDING
);
1999 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
2000 switch (ioc
->pdev
->subsystem_device
) {
2001 case MPT2SAS_INTEL_RS25GB008_SSDID
:
2002 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2003 MPT2SAS_INTEL_RS25GB008_BRANDING
);
2005 case MPT2SAS_INTEL_RMS25JB080_SSDID
:
2006 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2007 MPT2SAS_INTEL_RMS25JB080_BRANDING
);
2009 case MPT2SAS_INTEL_RMS25JB040_SSDID
:
2010 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2011 MPT2SAS_INTEL_RMS25JB040_BRANDING
);
2013 case MPT2SAS_INTEL_RMS25KB080_SSDID
:
2014 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2015 MPT2SAS_INTEL_RMS25KB080_BRANDING
);
2017 case MPT2SAS_INTEL_RMS25KB040_SSDID
:
2018 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2019 MPT2SAS_INTEL_RMS25KB040_BRANDING
);
2021 case MPT2SAS_INTEL_RMS25LB040_SSDID
:
2022 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2023 MPT2SAS_INTEL_RMS25LB040_BRANDING
);
2025 case MPT2SAS_INTEL_RMS25LB080_SSDID
:
2026 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2027 MPT2SAS_INTEL_RMS25LB080_BRANDING
);
2038 * _base_display_hp_branding - Display branding string
2039 * @ioc: per adapter object
2044 _base_display_hp_branding(struct MPT2SAS_ADAPTER
*ioc
)
2046 if (ioc
->pdev
->subsystem_vendor
!= MPT2SAS_HP_3PAR_SSVID
)
2049 switch (ioc
->pdev
->device
) {
2050 case MPI2_MFGPAGE_DEVID_SAS2004
:
2051 switch (ioc
->pdev
->subsystem_device
) {
2052 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID
:
2053 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2054 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING
);
2059 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
2060 switch (ioc
->pdev
->subsystem_device
) {
2061 case MPT2SAS_HP_2_4_INTERNAL_SSDID
:
2062 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2063 MPT2SAS_HP_2_4_INTERNAL_BRANDING
);
2065 case MPT2SAS_HP_2_4_EXTERNAL_SSDID
:
2066 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2067 MPT2SAS_HP_2_4_EXTERNAL_BRANDING
);
2069 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID
:
2070 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2071 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING
);
2073 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID
:
2074 printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2075 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING
);
2086 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2087 * @ioc: per adapter object
2092 _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER
*ioc
)
2096 u32 iounit_pg1_flags
;
2099 bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2100 strncpy(desc
, ioc
->manu_pg0
.ChipName
, 16);
2101 printk(MPT2SAS_INFO_FMT
"%s: FWVersion(%02d.%02d.%02d.%02d), "
2102 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2104 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2105 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2106 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2107 ioc
->facts
.FWVersion
.Word
& 0x000000FF,
2108 ioc
->pdev
->revision
,
2109 (bios_version
& 0xFF000000) >> 24,
2110 (bios_version
& 0x00FF0000) >> 16,
2111 (bios_version
& 0x0000FF00) >> 8,
2112 bios_version
& 0x000000FF);
2114 _base_display_dell_branding(ioc
);
2115 _base_display_intel_branding(ioc
);
2116 _base_display_hp_branding(ioc
);
2118 printk(MPT2SAS_INFO_FMT
"Protocol=(", ioc
->name
);
2120 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
) {
2121 printk("Initiator");
2125 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET
) {
2126 printk("%sTarget", i
? "," : "");
2132 printk("Capabilities=(");
2134 if (!ioc
->hide_ir_msg
) {
2135 if (ioc
->facts
.IOCCapabilities
&
2136 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
) {
2142 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
) {
2143 printk("%sTLR", i
? "," : "");
2147 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_MULTICAST
) {
2148 printk("%sMulticast", i
? "," : "");
2152 if (ioc
->facts
.IOCCapabilities
&
2153 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET
) {
2154 printk("%sBIDI Target", i
? "," : "");
2158 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_EEDP
) {
2159 printk("%sEEDP", i
? "," : "");
2163 if (ioc
->facts
.IOCCapabilities
&
2164 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
) {
2165 printk("%sSnapshot Buffer", i
? "," : "");
2169 if (ioc
->facts
.IOCCapabilities
&
2170 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
) {
2171 printk("%sDiag Trace Buffer", i
? "," : "");
2175 if (ioc
->facts
.IOCCapabilities
&
2176 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
) {
2177 printk(KERN_INFO
"%sDiag Extended Buffer", i
? "," : "");
2181 if (ioc
->facts
.IOCCapabilities
&
2182 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
) {
2183 printk("%sTask Set Full", i
? "," : "");
2187 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2188 if (!(iounit_pg1_flags
& MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE
)) {
2189 printk("%sNCQ", i
? "," : "");
2197 * mpt2sas_base_update_missing_delay - change the missing delay timers
2198 * @ioc: per adapter object
2199 * @device_missing_delay: amount of time till device is reported missing
2200 * @io_missing_delay: interval IO is returned when there is a missing device
2204 * Passed on the command line, this function will modify the device missing
2205 * delay, as well as the io missing delay. This should be called at driver
2209 mpt2sas_base_update_missing_delay(struct MPT2SAS_ADAPTER
*ioc
,
2210 u16 device_missing_delay
, u8 io_missing_delay
)
2212 u16 dmd
, dmd_new
, dmd_orignal
;
2213 u8 io_missing_delay_original
;
2215 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
2216 Mpi2ConfigReply_t mpi_reply
;
2220 mpt2sas_config_get_number_hba_phys(ioc
, &num_phys
);
2224 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (num_phys
*
2225 sizeof(Mpi2SasIOUnit1PhyData_t
));
2226 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
2227 if (!sas_iounit_pg1
) {
2228 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2229 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2232 if ((mpt2sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
2233 sas_iounit_pg1
, sz
))) {
2234 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2235 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2238 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
2239 MPI2_IOCSTATUS_MASK
;
2240 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2241 printk(MPT2SAS_ERR_FMT
"failure at %s:%d/%s()!\n",
2242 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2246 /* device missing delay */
2247 dmd
= sas_iounit_pg1
->ReportDeviceMissingDelay
;
2248 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2249 dmd
= (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2251 dmd
= dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2253 if (device_missing_delay
> 0x7F) {
2254 dmd
= (device_missing_delay
> 0x7F0) ? 0x7F0 :
2255 device_missing_delay
;
2257 dmd
|= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
;
2259 dmd
= device_missing_delay
;
2260 sas_iounit_pg1
->ReportDeviceMissingDelay
= dmd
;
2262 /* io missing delay */
2263 io_missing_delay_original
= sas_iounit_pg1
->IODeviceMissingDelay
;
2264 sas_iounit_pg1
->IODeviceMissingDelay
= io_missing_delay
;
2266 if (!mpt2sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
2268 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2270 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2273 dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2274 printk(MPT2SAS_INFO_FMT
"device_missing_delay: old(%d), "
2275 "new(%d)\n", ioc
->name
, dmd_orignal
, dmd_new
);
2276 printk(MPT2SAS_INFO_FMT
"ioc_missing_delay: old(%d), "
2277 "new(%d)\n", ioc
->name
, io_missing_delay_original
,
2279 ioc
->device_missing_delay
= dmd_new
;
2280 ioc
->io_missing_delay
= io_missing_delay
;
2284 kfree(sas_iounit_pg1
);
2288 * _base_static_config_pages - static start of day config pages
2289 * @ioc: per adapter object
2294 _base_static_config_pages(struct MPT2SAS_ADAPTER
*ioc
)
2296 Mpi2ConfigReply_t mpi_reply
;
2297 u32 iounit_pg1_flags
;
2299 mpt2sas_config_get_manufacturing_pg0(ioc
, &mpi_reply
, &ioc
->manu_pg0
);
2300 if (ioc
->ir_firmware
)
2301 mpt2sas_config_get_manufacturing_pg10(ioc
, &mpi_reply
,
2303 mpt2sas_config_get_bios_pg2(ioc
, &mpi_reply
, &ioc
->bios_pg2
);
2304 mpt2sas_config_get_bios_pg3(ioc
, &mpi_reply
, &ioc
->bios_pg3
);
2305 mpt2sas_config_get_ioc_pg8(ioc
, &mpi_reply
, &ioc
->ioc_pg8
);
2306 mpt2sas_config_get_iounit_pg0(ioc
, &mpi_reply
, &ioc
->iounit_pg0
);
2307 mpt2sas_config_get_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2308 _base_display_ioc_capabilities(ioc
);
2311 * Enable task_set_full handling in iounit_pg1 when the
2312 * facts capabilities indicate that its supported.
2314 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2315 if ((ioc
->facts
.IOCCapabilities
&
2316 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
))
2318 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2321 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2322 ioc
->iounit_pg1
.Flags
= cpu_to_le32(iounit_pg1_flags
);
2323 mpt2sas_config_set_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2328 * _base_release_memory_pools - release memory
2329 * @ioc: per adapter object
2331 * Free memory allocated from _base_allocate_memory_pools.
2336 _base_release_memory_pools(struct MPT2SAS_ADAPTER
*ioc
)
2340 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2344 pci_free_consistent(ioc
->pdev
, ioc
->request_dma_sz
,
2345 ioc
->request
, ioc
->request_dma
);
2346 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request_pool(0x%p)"
2347 ": free\n", ioc
->name
, ioc
->request
));
2348 ioc
->request
= NULL
;
2352 pci_pool_free(ioc
->sense_dma_pool
, ioc
->sense
, ioc
->sense_dma
);
2353 if (ioc
->sense_dma_pool
)
2354 pci_pool_destroy(ioc
->sense_dma_pool
);
2355 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sense_pool(0x%p)"
2356 ": free\n", ioc
->name
, ioc
->sense
));
2361 pci_pool_free(ioc
->reply_dma_pool
, ioc
->reply
, ioc
->reply_dma
);
2362 if (ioc
->reply_dma_pool
)
2363 pci_pool_destroy(ioc
->reply_dma_pool
);
2364 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_pool(0x%p)"
2365 ": free\n", ioc
->name
, ioc
->reply
));
2369 if (ioc
->reply_free
) {
2370 pci_pool_free(ioc
->reply_free_dma_pool
, ioc
->reply_free
,
2371 ioc
->reply_free_dma
);
2372 if (ioc
->reply_free_dma_pool
)
2373 pci_pool_destroy(ioc
->reply_free_dma_pool
);
2374 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free_pool"
2375 "(0x%p): free\n", ioc
->name
, ioc
->reply_free
));
2376 ioc
->reply_free
= NULL
;
2379 if (ioc
->reply_post_free
) {
2380 pci_pool_free(ioc
->reply_post_free_dma_pool
,
2381 ioc
->reply_post_free
, ioc
->reply_post_free_dma
);
2382 if (ioc
->reply_post_free_dma_pool
)
2383 pci_pool_destroy(ioc
->reply_post_free_dma_pool
);
2384 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2385 "reply_post_free_pool(0x%p): free\n", ioc
->name
,
2386 ioc
->reply_post_free
));
2387 ioc
->reply_post_free
= NULL
;
2390 if (ioc
->config_page
) {
2391 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2392 "config_page(0x%p): free\n", ioc
->name
,
2394 pci_free_consistent(ioc
->pdev
, ioc
->config_page_sz
,
2395 ioc
->config_page
, ioc
->config_page_dma
);
2398 if (ioc
->scsi_lookup
) {
2399 free_pages((ulong
)ioc
->scsi_lookup
, ioc
->scsi_lookup_pages
);
2400 ioc
->scsi_lookup
= NULL
;
2402 kfree(ioc
->hpr_lookup
);
2403 kfree(ioc
->internal_lookup
);
2404 if (ioc
->chain_lookup
) {
2405 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2406 if (ioc
->chain_lookup
[i
].chain_buffer
)
2407 pci_pool_free(ioc
->chain_dma_pool
,
2408 ioc
->chain_lookup
[i
].chain_buffer
,
2409 ioc
->chain_lookup
[i
].chain_buffer_dma
);
2411 if (ioc
->chain_dma_pool
)
2412 pci_pool_destroy(ioc
->chain_dma_pool
);
2413 free_pages((ulong
)ioc
->chain_lookup
, ioc
->chain_pages
);
2414 ioc
->chain_lookup
= NULL
;
2420 * _base_allocate_memory_pools - allocate start of day memory pools
2421 * @ioc: per adapter object
2422 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2424 * Returns 0 success, anything else error
2427 _base_allocate_memory_pools(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
2429 struct mpt2sas_facts
*facts
;
2430 u16 max_sge_elements
;
2431 u16 chains_needed_per_io
;
2432 u32 sz
, total_sz
, reply_post_free_sz
;
2434 u16 max_request_credit
;
2437 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
2441 facts
= &ioc
->facts
;
2443 /* command line tunables for max sgl entries */
2444 if (max_sgl_entries
!= -1) {
2445 ioc
->shost
->sg_tablesize
= (max_sgl_entries
<
2446 MPT2SAS_SG_DEPTH
) ? max_sgl_entries
:
2449 ioc
->shost
->sg_tablesize
= MPT2SAS_SG_DEPTH
;
2452 /* command line tunables for max controller queue depth */
2453 if (max_queue_depth
!= -1 && max_queue_depth
!= 0) {
2454 max_request_credit
= min_t(u16
, max_queue_depth
+
2455 ioc
->hi_priority_depth
+ ioc
->internal_depth
,
2456 facts
->RequestCredit
);
2457 if (max_request_credit
> MAX_HBA_QUEUE_DEPTH
)
2458 max_request_credit
= MAX_HBA_QUEUE_DEPTH
;
2460 max_request_credit
= min_t(u16
, facts
->RequestCredit
,
2461 MAX_HBA_QUEUE_DEPTH
);
2463 ioc
->hba_queue_depth
= max_request_credit
;
2464 ioc
->hi_priority_depth
= facts
->HighPriorityCredit
;
2465 ioc
->internal_depth
= ioc
->hi_priority_depth
+ 5;
2467 /* request frame size */
2468 ioc
->request_sz
= facts
->IOCRequestFrameSize
* 4;
2470 /* reply frame size */
2471 ioc
->reply_sz
= facts
->ReplyFrameSize
* 4;
2475 /* calculate number of sg elements left over in the 1st frame */
2476 max_sge_elements
= ioc
->request_sz
- ((sizeof(Mpi2SCSIIORequest_t
) -
2477 sizeof(Mpi2SGEIOUnion_t
)) + ioc
->sge_size
);
2478 ioc
->max_sges_in_main_message
= max_sge_elements
/ioc
->sge_size
;
2480 /* now do the same for a chain buffer */
2481 max_sge_elements
= ioc
->request_sz
- ioc
->sge_size
;
2482 ioc
->max_sges_in_chain_message
= max_sge_elements
/ioc
->sge_size
;
2484 ioc
->chain_offset_value_for_main_message
=
2485 ((sizeof(Mpi2SCSIIORequest_t
) - sizeof(Mpi2SGEIOUnion_t
)) +
2486 (ioc
->max_sges_in_chain_message
* ioc
->sge_size
)) / 4;
2489 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2491 chains_needed_per_io
= ((ioc
->shost
->sg_tablesize
-
2492 ioc
->max_sges_in_main_message
)/ioc
->max_sges_in_chain_message
)
2494 if (chains_needed_per_io
> facts
->MaxChainDepth
) {
2495 chains_needed_per_io
= facts
->MaxChainDepth
;
2496 ioc
->shost
->sg_tablesize
= min_t(u16
,
2497 ioc
->max_sges_in_main_message
+ (ioc
->max_sges_in_chain_message
2498 * chains_needed_per_io
), ioc
->shost
->sg_tablesize
);
2500 ioc
->chains_needed_per_io
= chains_needed_per_io
;
2502 /* reply free queue sizing - taking into account for 64 FW events */
2503 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
2505 /* calculate reply descriptor post queue depth */
2506 ioc
->reply_post_queue_depth
= ioc
->hba_queue_depth
+
2507 ioc
->reply_free_queue_depth
+ 1;
2508 /* align the reply post queue on the next 16 count boundary */
2509 if (ioc
->reply_post_queue_depth
% 16)
2510 ioc
->reply_post_queue_depth
+= 16 -
2511 (ioc
->reply_post_queue_depth
% 16);
2514 if (ioc
->reply_post_queue_depth
>
2515 facts
->MaxReplyDescriptorPostQueueDepth
) {
2516 ioc
->reply_post_queue_depth
=
2517 facts
->MaxReplyDescriptorPostQueueDepth
-
2518 (facts
->MaxReplyDescriptorPostQueueDepth
% 16);
2519 ioc
->hba_queue_depth
=
2520 ((ioc
->reply_post_queue_depth
- 64) / 2) - 1;
2521 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
2524 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scatter gather: "
2525 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2526 "chains_per_io(%d)\n", ioc
->name
, ioc
->max_sges_in_main_message
,
2527 ioc
->max_sges_in_chain_message
, ioc
->shost
->sg_tablesize
,
2528 ioc
->chains_needed_per_io
));
2530 ioc
->scsiio_depth
= ioc
->hba_queue_depth
-
2531 ioc
->hi_priority_depth
- ioc
->internal_depth
;
2533 /* set the scsi host can_queue depth
2534 * with some internal commands that could be outstanding
2536 ioc
->shost
->can_queue
= ioc
->scsiio_depth
;
2537 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scsi host: "
2538 "can_queue depth (%d)\n", ioc
->name
, ioc
->shost
->can_queue
));
2540 /* contiguous pool for request and chains, 16 byte align, one extra "
2543 ioc
->chain_depth
= ioc
->chains_needed_per_io
* ioc
->scsiio_depth
;
2544 sz
= ((ioc
->scsiio_depth
+ 1) * ioc
->request_sz
);
2546 /* hi-priority queue */
2547 sz
+= (ioc
->hi_priority_depth
* ioc
->request_sz
);
2549 /* internal queue */
2550 sz
+= (ioc
->internal_depth
* ioc
->request_sz
);
2552 ioc
->request_dma_sz
= sz
;
2553 ioc
->request
= pci_alloc_consistent(ioc
->pdev
, sz
, &ioc
->request_dma
);
2554 if (!ioc
->request
) {
2555 printk(MPT2SAS_ERR_FMT
"request pool: pci_alloc_consistent "
2556 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2557 "total(%d kB)\n", ioc
->name
, ioc
->hba_queue_depth
,
2558 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2559 if (ioc
->scsiio_depth
< MPT2SAS_SAS_QUEUE_DEPTH
)
2562 ioc
->hba_queue_depth
= max_request_credit
- retry_sz
;
2563 goto retry_allocation
;
2567 printk(MPT2SAS_ERR_FMT
"request pool: pci_alloc_consistent "
2568 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2569 "total(%d kb)\n", ioc
->name
, ioc
->hba_queue_depth
,
2570 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2573 /* hi-priority queue */
2574 ioc
->hi_priority
= ioc
->request
+ ((ioc
->scsiio_depth
+ 1) *
2576 ioc
->hi_priority_dma
= ioc
->request_dma
+ ((ioc
->scsiio_depth
+ 1) *
2579 /* internal queue */
2580 ioc
->internal
= ioc
->hi_priority
+ (ioc
->hi_priority_depth
*
2582 ioc
->internal_dma
= ioc
->hi_priority_dma
+ (ioc
->hi_priority_depth
*
2586 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request pool(0x%p): "
2587 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
,
2588 ioc
->request
, ioc
->hba_queue_depth
, ioc
->request_sz
,
2589 (ioc
->hba_queue_depth
* ioc
->request_sz
)/1024));
2590 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request pool: dma(0x%llx)\n",
2591 ioc
->name
, (unsigned long long) ioc
->request_dma
));
2594 sz
= ioc
->scsiio_depth
* sizeof(struct scsiio_tracker
);
2595 ioc
->scsi_lookup_pages
= get_order(sz
);
2596 ioc
->scsi_lookup
= (struct scsiio_tracker
*)__get_free_pages(
2597 GFP_KERNEL
, ioc
->scsi_lookup_pages
);
2598 if (!ioc
->scsi_lookup
) {
2599 printk(MPT2SAS_ERR_FMT
"scsi_lookup: get_free_pages failed, "
2600 "sz(%d)\n", ioc
->name
, (int)sz
);
2604 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"scsiio(0x%p): "
2605 "depth(%d)\n", ioc
->name
, ioc
->request
,
2606 ioc
->scsiio_depth
));
2608 ioc
->chain_depth
= min_t(u32
, ioc
->chain_depth
, MAX_CHAIN_DEPTH
);
2609 sz
= ioc
->chain_depth
* sizeof(struct chain_tracker
);
2610 ioc
->chain_pages
= get_order(sz
);
2612 ioc
->chain_lookup
= (struct chain_tracker
*)__get_free_pages(
2613 GFP_KERNEL
, ioc
->chain_pages
);
2614 if (!ioc
->chain_lookup
) {
2615 printk(MPT2SAS_ERR_FMT
"chain_lookup: get_free_pages failed, "
2616 "sz(%d)\n", ioc
->name
, (int)sz
);
2619 ioc
->chain_dma_pool
= pci_pool_create("chain pool", ioc
->pdev
,
2620 ioc
->request_sz
, 16, 0);
2621 if (!ioc
->chain_dma_pool
) {
2622 printk(MPT2SAS_ERR_FMT
"chain_dma_pool: pci_pool_create "
2623 "failed\n", ioc
->name
);
2626 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2627 ioc
->chain_lookup
[i
].chain_buffer
= pci_pool_alloc(
2628 ioc
->chain_dma_pool
, GFP_KERNEL
,
2629 &ioc
->chain_lookup
[i
].chain_buffer_dma
);
2630 if (!ioc
->chain_lookup
[i
].chain_buffer
) {
2631 ioc
->chain_depth
= i
;
2634 total_sz
+= ioc
->request_sz
;
2637 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"chain pool depth"
2638 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
,
2639 ioc
->chain_depth
, ioc
->request_sz
, ((ioc
->chain_depth
*
2640 ioc
->request_sz
))/1024));
2642 /* initialize hi-priority queue smid's */
2643 ioc
->hpr_lookup
= kcalloc(ioc
->hi_priority_depth
,
2644 sizeof(struct request_tracker
), GFP_KERNEL
);
2645 if (!ioc
->hpr_lookup
) {
2646 printk(MPT2SAS_ERR_FMT
"hpr_lookup: kcalloc failed\n",
2650 ioc
->hi_priority_smid
= ioc
->scsiio_depth
+ 1;
2651 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"hi_priority(0x%p): "
2652 "depth(%d), start smid(%d)\n", ioc
->name
, ioc
->hi_priority
,
2653 ioc
->hi_priority_depth
, ioc
->hi_priority_smid
));
2655 /* initialize internal queue smid's */
2656 ioc
->internal_lookup
= kcalloc(ioc
->internal_depth
,
2657 sizeof(struct request_tracker
), GFP_KERNEL
);
2658 if (!ioc
->internal_lookup
) {
2659 printk(MPT2SAS_ERR_FMT
"internal_lookup: kcalloc failed\n",
2663 ioc
->internal_smid
= ioc
->hi_priority_smid
+ ioc
->hi_priority_depth
;
2664 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"internal(0x%p): "
2665 "depth(%d), start smid(%d)\n", ioc
->name
, ioc
->internal
,
2666 ioc
->internal_depth
, ioc
->internal_smid
));
2668 /* sense buffers, 4 byte align */
2669 sz
= ioc
->scsiio_depth
* SCSI_SENSE_BUFFERSIZE
;
2670 ioc
->sense_dma_pool
= pci_pool_create("sense pool", ioc
->pdev
, sz
, 4,
2672 if (!ioc
->sense_dma_pool
) {
2673 printk(MPT2SAS_ERR_FMT
"sense pool: pci_pool_create failed\n",
2677 ioc
->sense
= pci_pool_alloc(ioc
->sense_dma_pool
, GFP_KERNEL
,
2680 printk(MPT2SAS_ERR_FMT
"sense pool: pci_pool_alloc failed\n",
2684 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
2685 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2686 "(%d kB)\n", ioc
->name
, ioc
->sense
, ioc
->scsiio_depth
,
2687 SCSI_SENSE_BUFFERSIZE
, sz
/1024));
2688 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"sense_dma(0x%llx)\n",
2689 ioc
->name
, (unsigned long long)ioc
->sense_dma
));
2692 /* reply pool, 4 byte align */
2693 sz
= ioc
->reply_free_queue_depth
* ioc
->reply_sz
;
2694 ioc
->reply_dma_pool
= pci_pool_create("reply pool", ioc
->pdev
, sz
, 4,
2696 if (!ioc
->reply_dma_pool
) {
2697 printk(MPT2SAS_ERR_FMT
"reply pool: pci_pool_create failed\n",
2701 ioc
->reply
= pci_pool_alloc(ioc
->reply_dma_pool
, GFP_KERNEL
,
2704 printk(MPT2SAS_ERR_FMT
"reply pool: pci_pool_alloc failed\n",
2708 ioc
->reply_dma_min_address
= (u32
)(ioc
->reply_dma
);
2709 ioc
->reply_dma_max_address
= (u32
)(ioc
->reply_dma
) + sz
;
2710 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply pool(0x%p): depth"
2711 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc
->name
, ioc
->reply
,
2712 ioc
->reply_free_queue_depth
, ioc
->reply_sz
, sz
/1024));
2713 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_dma(0x%llx)\n",
2714 ioc
->name
, (unsigned long long)ioc
->reply_dma
));
2717 /* reply free queue, 16 byte align */
2718 sz
= ioc
->reply_free_queue_depth
* 4;
2719 ioc
->reply_free_dma_pool
= pci_pool_create("reply_free pool",
2720 ioc
->pdev
, sz
, 16, 0);
2721 if (!ioc
->reply_free_dma_pool
) {
2722 printk(MPT2SAS_ERR_FMT
"reply_free pool: pci_pool_create "
2723 "failed\n", ioc
->name
);
2726 ioc
->reply_free
= pci_pool_alloc(ioc
->reply_free_dma_pool
, GFP_KERNEL
,
2727 &ioc
->reply_free_dma
);
2728 if (!ioc
->reply_free
) {
2729 printk(MPT2SAS_ERR_FMT
"reply_free pool: pci_pool_alloc "
2730 "failed\n", ioc
->name
);
2733 memset(ioc
->reply_free
, 0, sz
);
2734 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free pool(0x%p): "
2735 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc
->name
,
2736 ioc
->reply_free
, ioc
->reply_free_queue_depth
, 4, sz
/1024));
2737 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_free_dma"
2738 "(0x%llx)\n", ioc
->name
, (unsigned long long)ioc
->reply_free_dma
));
2741 /* reply post queue, 16 byte align */
2742 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
2743 sizeof(Mpi2DefaultReplyDescriptor_t
);
2744 if (_base_is_controller_msix_enabled(ioc
))
2745 sz
= reply_post_free_sz
* ioc
->reply_queue_count
;
2747 sz
= reply_post_free_sz
;
2748 ioc
->reply_post_free_dma_pool
= pci_pool_create("reply_post_free pool",
2749 ioc
->pdev
, sz
, 16, 0);
2750 if (!ioc
->reply_post_free_dma_pool
) {
2751 printk(MPT2SAS_ERR_FMT
"reply_post_free pool: pci_pool_create "
2752 "failed\n", ioc
->name
);
2755 ioc
->reply_post_free
= pci_pool_alloc(ioc
->reply_post_free_dma_pool
,
2756 GFP_KERNEL
, &ioc
->reply_post_free_dma
);
2757 if (!ioc
->reply_post_free
) {
2758 printk(MPT2SAS_ERR_FMT
"reply_post_free pool: pci_pool_alloc "
2759 "failed\n", ioc
->name
);
2762 memset(ioc
->reply_post_free
, 0, sz
);
2763 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply post free pool"
2764 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2765 ioc
->name
, ioc
->reply_post_free
, ioc
->reply_post_queue_depth
, 8,
2767 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"reply_post_free_dma = "
2768 "(0x%llx)\n", ioc
->name
, (unsigned long long)
2769 ioc
->reply_post_free_dma
));
2772 ioc
->config_page_sz
= 512;
2773 ioc
->config_page
= pci_alloc_consistent(ioc
->pdev
,
2774 ioc
->config_page_sz
, &ioc
->config_page_dma
);
2775 if (!ioc
->config_page
) {
2776 printk(MPT2SAS_ERR_FMT
"config page: pci_pool_alloc "
2777 "failed\n", ioc
->name
);
2780 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"config page(0x%p): size"
2781 "(%d)\n", ioc
->name
, ioc
->config_page
, ioc
->config_page_sz
));
2782 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"config_page_dma"
2783 "(0x%llx)\n", ioc
->name
, (unsigned long long)ioc
->config_page_dma
));
2784 total_sz
+= ioc
->config_page_sz
;
2786 printk(MPT2SAS_INFO_FMT
"Allocated physical memory: size(%d kB)\n",
2787 ioc
->name
, total_sz
/1024);
2788 printk(MPT2SAS_INFO_FMT
"Current Controller Queue Depth(%d), "
2789 "Max Controller Queue Depth(%d)\n",
2790 ioc
->name
, ioc
->shost
->can_queue
, facts
->RequestCredit
);
2791 printk(MPT2SAS_INFO_FMT
"Scatter Gather Elements per IO(%d)\n",
2792 ioc
->name
, ioc
->shost
->sg_tablesize
);
2801 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2802 * @ioc: Pointer to MPT_ADAPTER structure
2803 * @cooked: Request raw or cooked IOC state
2805 * Returns all IOC Doorbell register bits if cooked==0, else just the
2806 * Doorbell bits in MPI_IOC_STATE_MASK.
2809 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER
*ioc
, int cooked
)
2813 s
= readl(&ioc
->chip
->Doorbell
);
2814 sc
= s
& MPI2_IOC_STATE_MASK
;
2815 return cooked
? sc
: s
;
2819 * _base_wait_on_iocstate - waiting on a particular ioc state
2820 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2821 * @timeout: timeout in second
2822 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2824 * Returns 0 for success, non-zero for failure.
2827 _base_wait_on_iocstate(struct MPT2SAS_ADAPTER
*ioc
, u32 ioc_state
, int timeout
,
2834 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2836 current_state
= mpt2sas_base_get_iocstate(ioc
, 1);
2837 if (current_state
== ioc_state
)
2839 if (count
&& current_state
== MPI2_IOC_STATE_FAULT
)
2841 if (sleep_flag
== CAN_SLEEP
)
2848 return current_state
;
2852 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2853 * a write to the doorbell)
2854 * @ioc: per adapter object
2855 * @timeout: timeout in second
2856 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2858 * Returns 0 for success, non-zero for failure.
2860 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2863 _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2870 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2872 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
2873 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
2874 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2875 "successful count(%d), timeout(%d)\n", ioc
->name
,
2876 __func__
, count
, timeout
));
2879 if (sleep_flag
== CAN_SLEEP
)
2886 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2887 "int_status(%x)!\n", ioc
->name
, __func__
, count
, int_status
);
2892 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2893 * @ioc: per adapter object
2894 * @timeout: timeout in second
2895 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2897 * Returns 0 for success, non-zero for failure.
2899 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2903 _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2911 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2913 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
2914 if (!(int_status
& MPI2_HIS_SYS2IOC_DB_STATUS
)) {
2915 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2916 "successful count(%d), timeout(%d)\n", ioc
->name
,
2917 __func__
, count
, timeout
));
2919 } else if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
2920 doorbell
= readl(&ioc
->chip
->Doorbell
);
2921 if ((doorbell
& MPI2_IOC_STATE_MASK
) ==
2922 MPI2_IOC_STATE_FAULT
) {
2923 mpt2sas_base_fault_info(ioc
, doorbell
);
2926 } else if (int_status
== 0xFFFFFFFF)
2929 if (sleep_flag
== CAN_SLEEP
)
2937 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2938 "int_status(%x)!\n", ioc
->name
, __func__
, count
, int_status
);
2943 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2944 * @ioc: per adapter object
2945 * @timeout: timeout in second
2946 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2948 * Returns 0 for success, non-zero for failure.
2952 _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER
*ioc
, int timeout
,
2959 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2961 doorbell_reg
= readl(&ioc
->chip
->Doorbell
);
2962 if (!(doorbell_reg
& MPI2_DOORBELL_USED
)) {
2963 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2964 "successful count(%d), timeout(%d)\n", ioc
->name
,
2965 __func__
, count
, timeout
));
2968 if (sleep_flag
== CAN_SLEEP
)
2975 printk(MPT2SAS_ERR_FMT
"%s: failed due to timeout count(%d), "
2976 "doorbell_reg(%x)!\n", ioc
->name
, __func__
, count
, doorbell_reg
);
2981 * _base_send_ioc_reset - send doorbell reset
2982 * @ioc: per adapter object
2983 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2984 * @timeout: timeout in second
2985 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2987 * Returns 0 for success, non-zero for failure.
2990 _base_send_ioc_reset(struct MPT2SAS_ADAPTER
*ioc
, u8 reset_type
, int timeout
,
2996 if (reset_type
!= MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
) {
2997 printk(MPT2SAS_ERR_FMT
"%s: unknown reset_type\n",
2998 ioc
->name
, __func__
);
3002 if (!(ioc
->facts
.IOCCapabilities
&
3003 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY
))
3006 printk(MPT2SAS_INFO_FMT
"sending message unit reset !!\n", ioc
->name
);
3008 writel(reset_type
<< MPI2_DOORBELL_FUNCTION_SHIFT
,
3009 &ioc
->chip
->Doorbell
);
3010 if ((_base_wait_for_doorbell_ack(ioc
, 15, sleep_flag
))) {
3014 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
,
3015 timeout
, sleep_flag
);
3017 printk(MPT2SAS_ERR_FMT
"%s: failed going to ready state "
3018 " (ioc_state=0x%x)\n", ioc
->name
, __func__
, ioc_state
);
3023 printk(MPT2SAS_INFO_FMT
"message unit reset: %s\n",
3024 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
3029 * _base_handshake_req_reply_wait - send request thru doorbell interface
3030 * @ioc: per adapter object
3031 * @request_bytes: request length
3032 * @request: pointer having request payload
3033 * @reply_bytes: reply length
3034 * @reply: pointer to reply payload
3035 * @timeout: timeout in second
3036 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3038 * Returns 0 for success, non-zero for failure.
3041 _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER
*ioc
, int request_bytes
,
3042 u32
*request
, int reply_bytes
, u16
*reply
, int timeout
, int sleep_flag
)
3044 MPI2DefaultReply_t
*default_reply
= (MPI2DefaultReply_t
*)reply
;
3050 /* make sure doorbell is not in use */
3051 if ((readl(&ioc
->chip
->Doorbell
) & MPI2_DOORBELL_USED
)) {
3052 printk(MPT2SAS_ERR_FMT
"doorbell is in use "
3053 " (line=%d)\n", ioc
->name
, __LINE__
);
3057 /* clear pending doorbell interrupts from previous state changes */
3058 if (readl(&ioc
->chip
->HostInterruptStatus
) &
3059 MPI2_HIS_IOC2SYS_DB_STATUS
)
3060 writel(0, &ioc
->chip
->HostInterruptStatus
);
3062 /* send message to ioc */
3063 writel(((MPI2_FUNCTION_HANDSHAKE
<<MPI2_DOORBELL_FUNCTION_SHIFT
) |
3064 ((request_bytes
/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT
)),
3065 &ioc
->chip
->Doorbell
);
3067 if ((_base_wait_for_doorbell_int(ioc
, 5, NO_SLEEP
))) {
3068 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3069 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3072 writel(0, &ioc
->chip
->HostInterruptStatus
);
3074 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
))) {
3075 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3076 "ack failed (line=%d)\n", ioc
->name
, __LINE__
);
3080 /* send message 32-bits at a time */
3081 for (i
= 0, failed
= 0; i
< request_bytes
/4 && !failed
; i
++) {
3082 writel(cpu_to_le32(request
[i
]), &ioc
->chip
->Doorbell
);
3083 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
)))
3088 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3089 "sending request failed (line=%d)\n", ioc
->name
, __LINE__
);
3093 /* now wait for the reply */
3094 if ((_base_wait_for_doorbell_int(ioc
, timeout
, sleep_flag
))) {
3095 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3096 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3100 /* read the first two 16-bits, it gives the total length of the reply */
3101 reply
[0] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3102 & MPI2_DOORBELL_DATA_MASK
);
3103 writel(0, &ioc
->chip
->HostInterruptStatus
);
3104 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3105 printk(MPT2SAS_ERR_FMT
"doorbell handshake "
3106 "int failed (line=%d)\n", ioc
->name
, __LINE__
);
3109 reply
[1] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3110 & MPI2_DOORBELL_DATA_MASK
);
3111 writel(0, &ioc
->chip
->HostInterruptStatus
);
3113 for (i
= 2; i
< default_reply
->MsgLength
* 2; i
++) {
3114 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3115 printk(MPT2SAS_ERR_FMT
"doorbell "
3116 "handshake int failed (line=%d)\n", ioc
->name
,
3120 if (i
>= reply_bytes
/2) /* overflow case */
3121 dummy
= readl(&ioc
->chip
->Doorbell
);
3123 reply
[i
] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3124 & MPI2_DOORBELL_DATA_MASK
);
3125 writel(0, &ioc
->chip
->HostInterruptStatus
);
3128 _base_wait_for_doorbell_int(ioc
, 5, sleep_flag
);
3129 if (_base_wait_for_doorbell_not_used(ioc
, 5, sleep_flag
) != 0) {
3130 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"doorbell is in use "
3131 " (line=%d)\n", ioc
->name
, __LINE__
));
3133 writel(0, &ioc
->chip
->HostInterruptStatus
);
3135 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3136 mfp
= (__le32
*)reply
;
3137 printk(KERN_INFO
"\toffset:data\n");
3138 for (i
= 0; i
< reply_bytes
/4; i
++)
3139 printk(KERN_INFO
"\t[0x%02x]:%08x\n", i
*4,
3140 le32_to_cpu(mfp
[i
]));
3146 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3147 * @ioc: per adapter object
3148 * @mpi_reply: the reply payload from FW
3149 * @mpi_request: the request payload sent to FW
3151 * The SAS IO Unit Control Request message allows the host to perform low-level
3152 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3153 * to obtain the IOC assigned device handles for a device if it has other
3154 * identifying information about the device, in addition allows the host to
3155 * remove IOC resources associated with the device.
3157 * Returns 0 for success, non-zero for failure.
3160 mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER
*ioc
,
3161 Mpi2SasIoUnitControlReply_t
*mpi_reply
,
3162 Mpi2SasIoUnitControlRequest_t
*mpi_request
)
3166 unsigned long timeleft
;
3170 u16 wait_state_count
;
3172 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3175 mutex_lock(&ioc
->base_cmds
.mutex
);
3177 if (ioc
->base_cmds
.status
!= MPT2_CMD_NOT_USED
) {
3178 printk(MPT2SAS_ERR_FMT
"%s: base_cmd in use\n",
3179 ioc
->name
, __func__
);
3184 wait_state_count
= 0;
3185 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3186 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3187 if (wait_state_count
++ == 10) {
3188 printk(MPT2SAS_ERR_FMT
3189 "%s: failed due to ioc not operational\n",
3190 ioc
->name
, __func__
);
3195 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3196 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
3197 "operational state(count=%d)\n", ioc
->name
,
3198 __func__
, wait_state_count
);
3201 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3203 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3204 ioc
->name
, __func__
);
3210 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3211 request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3212 ioc
->base_cmds
.smid
= smid
;
3213 memcpy(request
, mpi_request
, sizeof(Mpi2SasIoUnitControlRequest_t
));
3214 if (mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3215 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
)
3216 ioc
->ioc_link_reset_in_progress
= 1;
3217 init_completion(&ioc
->base_cmds
.done
);
3218 mpt2sas_base_put_smid_default(ioc
, smid
);
3219 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3220 msecs_to_jiffies(10000));
3221 if ((mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3222 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
) &&
3223 ioc
->ioc_link_reset_in_progress
)
3224 ioc
->ioc_link_reset_in_progress
= 0;
3225 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3226 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3227 ioc
->name
, __func__
);
3228 _debug_dump_mf(mpi_request
,
3229 sizeof(Mpi2SasIoUnitControlRequest_t
)/4);
3230 if (!(ioc
->base_cmds
.status
& MPT2_CMD_RESET
))
3232 goto issue_host_reset
;
3234 if (ioc
->base_cmds
.status
& MPT2_CMD_REPLY_VALID
)
3235 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3236 sizeof(Mpi2SasIoUnitControlReply_t
));
3238 memset(mpi_reply
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
3239 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3244 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3246 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3249 mutex_unlock(&ioc
->base_cmds
.mutex
);
3255 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3256 * @ioc: per adapter object
3257 * @mpi_reply: the reply payload from FW
3258 * @mpi_request: the request payload sent to FW
3260 * The SCSI Enclosure Processor request message causes the IOC to
3261 * communicate with SES devices to control LED status signals.
3263 * Returns 0 for success, non-zero for failure.
3266 mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER
*ioc
,
3267 Mpi2SepReply_t
*mpi_reply
, Mpi2SepRequest_t
*mpi_request
)
3271 unsigned long timeleft
;
3275 u16 wait_state_count
;
3277 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3280 mutex_lock(&ioc
->base_cmds
.mutex
);
3282 if (ioc
->base_cmds
.status
!= MPT2_CMD_NOT_USED
) {
3283 printk(MPT2SAS_ERR_FMT
"%s: base_cmd in use\n",
3284 ioc
->name
, __func__
);
3289 wait_state_count
= 0;
3290 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3291 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3292 if (wait_state_count
++ == 10) {
3293 printk(MPT2SAS_ERR_FMT
3294 "%s: failed due to ioc not operational\n",
3295 ioc
->name
, __func__
);
3300 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
3301 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
3302 "operational state(count=%d)\n", ioc
->name
,
3303 __func__
, wait_state_count
);
3306 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3308 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3309 ioc
->name
, __func__
);
3315 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3316 request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3317 ioc
->base_cmds
.smid
= smid
;
3318 memcpy(request
, mpi_request
, sizeof(Mpi2SepReply_t
));
3319 init_completion(&ioc
->base_cmds
.done
);
3320 mpt2sas_base_put_smid_default(ioc
, smid
);
3321 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3322 msecs_to_jiffies(10000));
3323 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3324 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3325 ioc
->name
, __func__
);
3326 _debug_dump_mf(mpi_request
,
3327 sizeof(Mpi2SepRequest_t
)/4);
3328 if (!(ioc
->base_cmds
.status
& MPT2_CMD_RESET
))
3330 goto issue_host_reset
;
3332 if (ioc
->base_cmds
.status
& MPT2_CMD_REPLY_VALID
)
3333 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3334 sizeof(Mpi2SepReply_t
));
3336 memset(mpi_reply
, 0, sizeof(Mpi2SepReply_t
));
3337 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3342 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3344 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3347 mutex_unlock(&ioc
->base_cmds
.mutex
);
3352 * _base_get_port_facts - obtain port facts reply and save in ioc
3353 * @ioc: per adapter object
3354 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3356 * Returns 0 for success, non-zero for failure.
3359 _base_get_port_facts(struct MPT2SAS_ADAPTER
*ioc
, int port
, int sleep_flag
)
3361 Mpi2PortFactsRequest_t mpi_request
;
3362 Mpi2PortFactsReply_t mpi_reply
;
3363 struct mpt2sas_port_facts
*pfacts
;
3364 int mpi_reply_sz
, mpi_request_sz
, r
;
3366 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3369 mpi_reply_sz
= sizeof(Mpi2PortFactsReply_t
);
3370 mpi_request_sz
= sizeof(Mpi2PortFactsRequest_t
);
3371 memset(&mpi_request
, 0, mpi_request_sz
);
3372 mpi_request
.Function
= MPI2_FUNCTION_PORT_FACTS
;
3373 mpi_request
.PortNumber
= port
;
3374 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3375 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3378 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3379 ioc
->name
, __func__
, r
);
3383 pfacts
= &ioc
->pfacts
[port
];
3384 memset(pfacts
, 0, sizeof(struct mpt2sas_port_facts
));
3385 pfacts
->PortNumber
= mpi_reply
.PortNumber
;
3386 pfacts
->VP_ID
= mpi_reply
.VP_ID
;
3387 pfacts
->VF_ID
= mpi_reply
.VF_ID
;
3388 pfacts
->MaxPostedCmdBuffers
=
3389 le16_to_cpu(mpi_reply
.MaxPostedCmdBuffers
);
3395 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3396 * @ioc: per adapter object
3397 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3399 * Returns 0 for success, non-zero for failure.
3402 _base_get_ioc_facts(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3404 Mpi2IOCFactsRequest_t mpi_request
;
3405 Mpi2IOCFactsReply_t mpi_reply
;
3406 struct mpt2sas_facts
*facts
;
3407 int mpi_reply_sz
, mpi_request_sz
, r
;
3409 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3412 mpi_reply_sz
= sizeof(Mpi2IOCFactsReply_t
);
3413 mpi_request_sz
= sizeof(Mpi2IOCFactsRequest_t
);
3414 memset(&mpi_request
, 0, mpi_request_sz
);
3415 mpi_request
.Function
= MPI2_FUNCTION_IOC_FACTS
;
3416 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3417 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3420 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3421 ioc
->name
, __func__
, r
);
3425 facts
= &ioc
->facts
;
3426 memset(facts
, 0, sizeof(struct mpt2sas_facts
));
3427 facts
->MsgVersion
= le16_to_cpu(mpi_reply
.MsgVersion
);
3428 facts
->HeaderVersion
= le16_to_cpu(mpi_reply
.HeaderVersion
);
3429 facts
->VP_ID
= mpi_reply
.VP_ID
;
3430 facts
->VF_ID
= mpi_reply
.VF_ID
;
3431 facts
->IOCExceptions
= le16_to_cpu(mpi_reply
.IOCExceptions
);
3432 facts
->MaxChainDepth
= mpi_reply
.MaxChainDepth
;
3433 facts
->WhoInit
= mpi_reply
.WhoInit
;
3434 facts
->NumberOfPorts
= mpi_reply
.NumberOfPorts
;
3435 facts
->MaxMSIxVectors
= mpi_reply
.MaxMSIxVectors
;
3436 facts
->RequestCredit
= le16_to_cpu(mpi_reply
.RequestCredit
);
3437 facts
->MaxReplyDescriptorPostQueueDepth
=
3438 le16_to_cpu(mpi_reply
.MaxReplyDescriptorPostQueueDepth
);
3439 facts
->ProductID
= le16_to_cpu(mpi_reply
.ProductID
);
3440 facts
->IOCCapabilities
= le32_to_cpu(mpi_reply
.IOCCapabilities
);
3441 if ((facts
->IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
))
3442 ioc
->ir_firmware
= 1;
3443 facts
->FWVersion
.Word
= le32_to_cpu(mpi_reply
.FWVersion
.Word
);
3444 facts
->IOCRequestFrameSize
=
3445 le16_to_cpu(mpi_reply
.IOCRequestFrameSize
);
3446 facts
->MaxInitiators
= le16_to_cpu(mpi_reply
.MaxInitiators
);
3447 facts
->MaxTargets
= le16_to_cpu(mpi_reply
.MaxTargets
);
3448 ioc
->shost
->max_id
= -1;
3449 facts
->MaxSasExpanders
= le16_to_cpu(mpi_reply
.MaxSasExpanders
);
3450 facts
->MaxEnclosures
= le16_to_cpu(mpi_reply
.MaxEnclosures
);
3451 facts
->ProtocolFlags
= le16_to_cpu(mpi_reply
.ProtocolFlags
);
3452 facts
->HighPriorityCredit
=
3453 le16_to_cpu(mpi_reply
.HighPriorityCredit
);
3454 facts
->ReplyFrameSize
= mpi_reply
.ReplyFrameSize
;
3455 facts
->MaxDevHandle
= le16_to_cpu(mpi_reply
.MaxDevHandle
);
3457 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"hba queue depth(%d), "
3458 "max chains per io(%d)\n", ioc
->name
, facts
->RequestCredit
,
3459 facts
->MaxChainDepth
));
3460 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"request frame size(%d), "
3461 "reply frame size(%d)\n", ioc
->name
,
3462 facts
->IOCRequestFrameSize
* 4, facts
->ReplyFrameSize
* 4));
3467 * _base_send_ioc_init - send ioc_init to firmware
3468 * @ioc: per adapter object
3469 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3471 * Returns 0 for success, non-zero for failure.
3474 _base_send_ioc_init(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3476 Mpi2IOCInitRequest_t mpi_request
;
3477 Mpi2IOCInitReply_t mpi_reply
;
3479 struct timeval current_time
;
3482 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3485 memset(&mpi_request
, 0, sizeof(Mpi2IOCInitRequest_t
));
3486 mpi_request
.Function
= MPI2_FUNCTION_IOC_INIT
;
3487 mpi_request
.WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
3488 mpi_request
.VF_ID
= 0; /* TODO */
3489 mpi_request
.VP_ID
= 0;
3490 mpi_request
.MsgVersion
= cpu_to_le16(MPI2_VERSION
);
3491 mpi_request
.HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
3493 if (_base_is_controller_msix_enabled(ioc
))
3494 mpi_request
.HostMSIxVectors
= ioc
->reply_queue_count
;
3495 mpi_request
.SystemRequestFrameSize
= cpu_to_le16(ioc
->request_sz
/4);
3496 mpi_request
.ReplyDescriptorPostQueueDepth
=
3497 cpu_to_le16(ioc
->reply_post_queue_depth
);
3498 mpi_request
.ReplyFreeQueueDepth
=
3499 cpu_to_le16(ioc
->reply_free_queue_depth
);
3501 mpi_request
.SenseBufferAddressHigh
=
3502 cpu_to_le32((u64
)ioc
->sense_dma
>> 32);
3503 mpi_request
.SystemReplyAddressHigh
=
3504 cpu_to_le32((u64
)ioc
->reply_dma
>> 32);
3505 mpi_request
.SystemRequestFrameBaseAddress
=
3506 cpu_to_le64((u64
)ioc
->request_dma
);
3507 mpi_request
.ReplyFreeQueueAddress
=
3508 cpu_to_le64((u64
)ioc
->reply_free_dma
);
3509 mpi_request
.ReplyDescriptorPostQueueAddress
=
3510 cpu_to_le64((u64
)ioc
->reply_post_free_dma
);
3513 /* This time stamp specifies number of milliseconds
3514 * since epoch ~ midnight January 1, 1970.
3516 do_gettimeofday(¤t_time
);
3517 mpi_request
.TimeStamp
= cpu_to_le64((u64
)current_time
.tv_sec
* 1000 +
3518 (current_time
.tv_usec
/ 1000));
3520 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3524 mfp
= (__le32
*)&mpi_request
;
3525 printk(KERN_INFO
"\toffset:data\n");
3526 for (i
= 0; i
< sizeof(Mpi2IOCInitRequest_t
)/4; i
++)
3527 printk(KERN_INFO
"\t[0x%02x]:%08x\n", i
*4,
3528 le32_to_cpu(mfp
[i
]));
3531 r
= _base_handshake_req_reply_wait(ioc
,
3532 sizeof(Mpi2IOCInitRequest_t
), (u32
*)&mpi_request
,
3533 sizeof(Mpi2IOCInitReply_t
), (u16
*)&mpi_reply
, 10,
3537 printk(MPT2SAS_ERR_FMT
"%s: handshake failed (r=%d)\n",
3538 ioc
->name
, __func__
, r
);
3542 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3543 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
||
3544 mpi_reply
.IOCLogInfo
) {
3545 printk(MPT2SAS_ERR_FMT
"%s: failed\n", ioc
->name
, __func__
);
3553 * mpt2sas_port_enable_done - command completion routine for port enable
3554 * @ioc: per adapter object
3555 * @smid: system request message index
3556 * @msix_index: MSIX table index supplied by the OS
3557 * @reply: reply message frame(lower 32bit addr)
3559 * Return 1 meaning mf should be freed from _base_interrupt
3560 * 0 means the mf is freed from this function.
3563 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3566 MPI2DefaultReply_t
*mpi_reply
;
3569 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
3570 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
3573 if (ioc
->port_enable_cmds
.status
== MPT2_CMD_NOT_USED
)
3576 ioc
->port_enable_cmds
.status
|= MPT2_CMD_COMPLETE
;
3578 ioc
->port_enable_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
3579 memcpy(ioc
->port_enable_cmds
.reply
, mpi_reply
,
3580 mpi_reply
->MsgLength
*4);
3582 ioc
->port_enable_cmds
.status
&= ~MPT2_CMD_PENDING
;
3584 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3586 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3587 ioc
->port_enable_failed
= 1;
3589 if (ioc
->is_driver_loading
) {
3590 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
3591 mpt2sas_port_enable_complete(ioc
);
3594 ioc
->start_scan_failed
= ioc_status
;
3595 ioc
->start_scan
= 0;
3599 complete(&ioc
->port_enable_cmds
.done
);
3605 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3606 * @ioc: per adapter object
3607 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3609 * Returns 0 for success, non-zero for failure.
3612 _base_send_port_enable(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3614 Mpi2PortEnableRequest_t
*mpi_request
;
3615 Mpi2PortEnableReply_t
*mpi_reply
;
3616 unsigned long timeleft
;
3621 printk(MPT2SAS_INFO_FMT
"sending port enable !!\n", ioc
->name
);
3623 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_PENDING
) {
3624 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3625 ioc
->name
, __func__
);
3629 smid
= mpt2sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3631 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3632 ioc
->name
, __func__
);
3636 ioc
->port_enable_cmds
.status
= MPT2_CMD_PENDING
;
3637 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3638 ioc
->port_enable_cmds
.smid
= smid
;
3639 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3640 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3642 init_completion(&ioc
->port_enable_cmds
.done
);
3643 mpt2sas_base_put_smid_default(ioc
, smid
);
3644 timeleft
= wait_for_completion_timeout(&ioc
->port_enable_cmds
.done
,
3646 if (!(ioc
->port_enable_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3647 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3648 ioc
->name
, __func__
);
3649 _debug_dump_mf(mpi_request
,
3650 sizeof(Mpi2PortEnableRequest_t
)/4);
3651 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_RESET
)
3657 mpi_reply
= ioc
->port_enable_cmds
.reply
;
3659 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3660 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3661 printk(MPT2SAS_ERR_FMT
"%s: failed with (ioc_status=0x%08x)\n",
3662 ioc
->name
, __func__
, ioc_status
);
3667 ioc
->port_enable_cmds
.status
= MPT2_CMD_NOT_USED
;
3668 printk(MPT2SAS_INFO_FMT
"port enable: %s\n", ioc
->name
, ((r
== 0) ?
3669 "SUCCESS" : "FAILED"));
3674 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3675 * @ioc: per adapter object
3677 * Returns 0 for success, non-zero for failure.
3680 mpt2sas_port_enable(struct MPT2SAS_ADAPTER
*ioc
)
3682 Mpi2PortEnableRequest_t
*mpi_request
;
3685 printk(MPT2SAS_INFO_FMT
"sending port enable !!\n", ioc
->name
);
3687 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_PENDING
) {
3688 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3689 ioc
->name
, __func__
);
3693 smid
= mpt2sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3695 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3696 ioc
->name
, __func__
);
3700 ioc
->port_enable_cmds
.status
= MPT2_CMD_PENDING
;
3701 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3702 ioc
->port_enable_cmds
.smid
= smid
;
3703 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3704 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3706 mpt2sas_base_put_smid_default(ioc
, smid
);
3711 * _base_determine_wait_on_discovery - desposition
3712 * @ioc: per adapter object
3714 * Decide whether to wait on discovery to complete. Used to either
3715 * locate boot device, or report volumes ahead of physical devices.
3717 * Returns 1 for wait, 0 for don't wait
3720 _base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER
*ioc
)
3722 /* We wait for discovery to complete if IR firmware is loaded.
3723 * The sas topology events arrive before PD events, so we need time to
3724 * turn on the bit in ioc->pd_handles to indicate PD
3725 * Also, it maybe required to report Volumes ahead of physical
3726 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3728 if (ioc
->ir_firmware
)
3731 /* if no Bios, then we don't need to wait */
3732 if (!ioc
->bios_pg3
.BiosVersion
)
3735 /* Bios is present, then we drop down here.
3737 * If there any entries in the Bios Page 2, then we wait
3738 * for discovery to complete.
3741 /* Current Boot Device */
3742 if ((ioc
->bios_pg2
.CurrentBootDeviceForm
&
3743 MPI2_BIOSPAGE2_FORM_MASK
) ==
3744 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
3745 /* Request Boot Device */
3746 (ioc
->bios_pg2
.ReqBootDeviceForm
&
3747 MPI2_BIOSPAGE2_FORM_MASK
) ==
3748 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
3749 /* Alternate Request Boot Device */
3750 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
3751 MPI2_BIOSPAGE2_FORM_MASK
) ==
3752 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
)
3760 * _base_unmask_events - turn on notification for this event
3761 * @ioc: per adapter object
3762 * @event: firmware event
3764 * The mask is stored in ioc->event_masks.
3767 _base_unmask_events(struct MPT2SAS_ADAPTER
*ioc
, u16 event
)
3774 desired_event
= (1 << (event
% 32));
3777 ioc
->event_masks
[0] &= ~desired_event
;
3778 else if (event
< 64)
3779 ioc
->event_masks
[1] &= ~desired_event
;
3780 else if (event
< 96)
3781 ioc
->event_masks
[2] &= ~desired_event
;
3782 else if (event
< 128)
3783 ioc
->event_masks
[3] &= ~desired_event
;
3787 * _base_event_notification - send event notification
3788 * @ioc: per adapter object
3789 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3791 * Returns 0 for success, non-zero for failure.
3794 _base_event_notification(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3796 Mpi2EventNotificationRequest_t
*mpi_request
;
3797 unsigned long timeleft
;
3802 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
3805 if (ioc
->base_cmds
.status
& MPT2_CMD_PENDING
) {
3806 printk(MPT2SAS_ERR_FMT
"%s: internal command already in use\n",
3807 ioc
->name
, __func__
);
3811 smid
= mpt2sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3813 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
3814 ioc
->name
, __func__
);
3817 ioc
->base_cmds
.status
= MPT2_CMD_PENDING
;
3818 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
3819 ioc
->base_cmds
.smid
= smid
;
3820 memset(mpi_request
, 0, sizeof(Mpi2EventNotificationRequest_t
));
3821 mpi_request
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3822 mpi_request
->VF_ID
= 0; /* TODO */
3823 mpi_request
->VP_ID
= 0;
3824 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
3825 mpi_request
->EventMasks
[i
] =
3826 cpu_to_le32(ioc
->event_masks
[i
]);
3827 init_completion(&ioc
->base_cmds
.done
);
3828 mpt2sas_base_put_smid_default(ioc
, smid
);
3829 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
, 30*HZ
);
3830 if (!(ioc
->base_cmds
.status
& MPT2_CMD_COMPLETE
)) {
3831 printk(MPT2SAS_ERR_FMT
"%s: timeout\n",
3832 ioc
->name
, __func__
);
3833 _debug_dump_mf(mpi_request
,
3834 sizeof(Mpi2EventNotificationRequest_t
)/4);
3835 if (ioc
->base_cmds
.status
& MPT2_CMD_RESET
)
3840 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: complete\n",
3841 ioc
->name
, __func__
));
3842 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
3847 * mpt2sas_base_validate_event_type - validating event types
3848 * @ioc: per adapter object
3849 * @event: firmware event
3851 * This will turn on firmware event notification when application
3852 * ask for that event. We don't mask events that are already enabled.
3855 mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER
*ioc
, u32
*event_type
)
3858 u32 event_mask
, desired_event
;
3859 u8 send_update_to_fw
;
3861 for (i
= 0, send_update_to_fw
= 0; i
<
3862 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++) {
3863 event_mask
= ~event_type
[i
];
3865 for (j
= 0; j
< 32; j
++) {
3866 if (!(event_mask
& desired_event
) &&
3867 (ioc
->event_masks
[i
] & desired_event
)) {
3868 ioc
->event_masks
[i
] &= ~desired_event
;
3869 send_update_to_fw
= 1;
3871 desired_event
= (desired_event
<< 1);
3875 if (!send_update_to_fw
)
3878 mutex_lock(&ioc
->base_cmds
.mutex
);
3879 _base_event_notification(ioc
, CAN_SLEEP
);
3880 mutex_unlock(&ioc
->base_cmds
.mutex
);
3884 * _base_diag_reset - the "big hammer" start of day reset
3885 * @ioc: per adapter object
3886 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3888 * Returns 0 for success, non-zero for failure.
3891 _base_diag_reset(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
3893 u32 host_diagnostic
;
3898 printk(MPT2SAS_INFO_FMT
"sending diag reset !!\n", ioc
->name
);
3899 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"clear interrupts\n",
3904 /* Write magic sequence to WriteSequence register
3905 * Loop until in diagnostic mode
3907 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"write magic "
3908 "sequence\n", ioc
->name
));
3909 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3910 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3911 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3912 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3913 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3914 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3915 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3918 if (sleep_flag
== CAN_SLEEP
)
3926 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
3927 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"wrote magic "
3928 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3929 ioc
->name
, count
, host_diagnostic
));
3931 } while ((host_diagnostic
& MPI2_DIAG_DIAG_WRITE_ENABLE
) == 0);
3933 hcb_size
= readl(&ioc
->chip
->HCBSize
);
3935 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"diag reset: issued\n",
3937 writel(host_diagnostic
| MPI2_DIAG_RESET_ADAPTER
,
3938 &ioc
->chip
->HostDiagnostic
);
3940 /* This delay allows the chip PCIe hardware time to finish reset tasks*/
3941 if (sleep_flag
== CAN_SLEEP
)
3942 msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
3944 mdelay(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
3946 /* Approximately 300 second max wait */
3947 for (count
= 0; count
< (300000000 /
3948 MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
); count
++) {
3950 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
3952 if (host_diagnostic
== 0xFFFFFFFF)
3954 if (!(host_diagnostic
& MPI2_DIAG_RESET_ADAPTER
))
3957 /* Wait to pass the second read delay window */
3958 if (sleep_flag
== CAN_SLEEP
)
3959 msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
3962 mdelay(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
3966 if (host_diagnostic
& MPI2_DIAG_HCB_MODE
) {
3968 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"restart the adapter "
3969 "assuming the HCB Address points to good F/W\n",
3971 host_diagnostic
&= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK
;
3972 host_diagnostic
|= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW
;
3973 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
3975 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
3976 "re-enable the HCDW\n", ioc
->name
));
3977 writel(hcb_size
| MPI2_HCB_SIZE_HCB_ENABLE
,
3978 &ioc
->chip
->HCBSize
);
3981 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"restart the adapter\n",
3983 writel(host_diagnostic
& ~MPI2_DIAG_HOLD_IOC_RESET
,
3984 &ioc
->chip
->HostDiagnostic
);
3986 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"disable writes to the "
3987 "diagnostic register\n", ioc
->name
));
3988 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
3990 drsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"Wait for FW to go to the "
3991 "READY state\n", ioc
->name
));
3992 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, 20,
3995 printk(MPT2SAS_ERR_FMT
"%s: failed going to ready state "
3996 " (ioc_state=0x%x)\n", ioc
->name
, __func__
, ioc_state
);
4000 printk(MPT2SAS_INFO_FMT
"diag reset: SUCCESS\n", ioc
->name
);
4004 printk(MPT2SAS_ERR_FMT
"diag reset: FAILED\n", ioc
->name
);
4009 * _base_make_ioc_ready - put controller in READY state
4010 * @ioc: per adapter object
4011 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4012 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4014 * Returns 0 for success, non-zero for failure.
4017 _base_make_ioc_ready(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
,
4018 enum reset_type type
)
4023 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4026 if (ioc
->pci_error_recovery
)
4029 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
4030 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: ioc_state(0x%08x)\n",
4031 ioc
->name
, __func__
, ioc_state
));
4033 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
)
4036 if (ioc_state
& MPI2_DOORBELL_USED
) {
4037 dhsprintk(ioc
, printk(MPT2SAS_INFO_FMT
"unexpected doorbell "
4038 "active!\n", ioc
->name
));
4039 goto issue_diag_reset
;
4042 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
4043 mpt2sas_base_fault_info(ioc
, ioc_state
&
4044 MPI2_DOORBELL_DATA_MASK
);
4045 goto issue_diag_reset
;
4048 if (type
== FORCE_BIG_HAMMER
)
4049 goto issue_diag_reset
;
4051 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
4052 if (!(_base_send_ioc_reset(ioc
,
4053 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
, 15, CAN_SLEEP
))) {
4054 ioc
->ioc_reset_count
++;
4059 rc
= _base_diag_reset(ioc
, CAN_SLEEP
);
4060 ioc
->ioc_reset_count
++;
4065 * _base_make_ioc_operational - put controller in OPERATIONAL state
4066 * @ioc: per adapter object
4067 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4069 * Returns 0 for success, non-zero for failure.
4072 _base_make_ioc_operational(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
4075 unsigned long flags
;
4078 struct _tr_list
*delayed_tr
, *delayed_tr_next
;
4080 struct adapter_reply_queue
*reply_q
;
4081 long reply_post_free
;
4082 u32 reply_post_free_sz
;
4084 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4087 /* clean the delayed target reset list */
4088 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4089 &ioc
->delayed_tr_list
, list
) {
4090 list_del(&delayed_tr
->list
);
4094 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4095 &ioc
->delayed_tr_volume_list
, list
) {
4096 list_del(&delayed_tr
->list
);
4100 /* initialize the scsi lookup free list */
4101 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4102 INIT_LIST_HEAD(&ioc
->free_list
);
4104 for (i
= 0; i
< ioc
->scsiio_depth
; i
++, smid
++) {
4105 INIT_LIST_HEAD(&ioc
->scsi_lookup
[i
].chain_list
);
4106 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
4107 ioc
->scsi_lookup
[i
].smid
= smid
;
4108 ioc
->scsi_lookup
[i
].scmd
= NULL
;
4109 ioc
->scsi_lookup
[i
].direct_io
= 0;
4110 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
4114 /* hi-priority queue */
4115 INIT_LIST_HEAD(&ioc
->hpr_free_list
);
4116 smid
= ioc
->hi_priority_smid
;
4117 for (i
= 0; i
< ioc
->hi_priority_depth
; i
++, smid
++) {
4118 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
4119 ioc
->hpr_lookup
[i
].smid
= smid
;
4120 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
4121 &ioc
->hpr_free_list
);
4124 /* internal queue */
4125 INIT_LIST_HEAD(&ioc
->internal_free_list
);
4126 smid
= ioc
->internal_smid
;
4127 for (i
= 0; i
< ioc
->internal_depth
; i
++, smid
++) {
4128 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
4129 ioc
->internal_lookup
[i
].smid
= smid
;
4130 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
4131 &ioc
->internal_free_list
);
4135 INIT_LIST_HEAD(&ioc
->free_chain_list
);
4136 for (i
= 0; i
< ioc
->chain_depth
; i
++)
4137 list_add_tail(&ioc
->chain_lookup
[i
].tracker_list
,
4138 &ioc
->free_chain_list
);
4140 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4142 /* initialize Reply Free Queue */
4143 for (i
= 0, reply_address
= (u32
)ioc
->reply_dma
;
4144 i
< ioc
->reply_free_queue_depth
; i
++, reply_address
+=
4146 ioc
->reply_free
[i
] = cpu_to_le32(reply_address
);
4148 /* initialize reply queues */
4149 if (ioc
->is_driver_loading
)
4150 _base_assign_reply_queues(ioc
);
4152 /* initialize Reply Post Free Queue */
4153 reply_post_free
= (long)ioc
->reply_post_free
;
4154 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
4155 sizeof(Mpi2DefaultReplyDescriptor_t
);
4156 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4157 reply_q
->reply_post_host_index
= 0;
4158 reply_q
->reply_post_free
= (Mpi2ReplyDescriptorsUnion_t
*)
4160 for (i
= 0; i
< ioc
->reply_post_queue_depth
; i
++)
4161 reply_q
->reply_post_free
[i
].Words
=
4162 cpu_to_le64(ULLONG_MAX
);
4163 if (!_base_is_controller_msix_enabled(ioc
))
4164 goto skip_init_reply_post_free_queue
;
4165 reply_post_free
+= reply_post_free_sz
;
4167 skip_init_reply_post_free_queue
:
4169 r
= _base_send_ioc_init(ioc
, sleep_flag
);
4173 /* initialize reply free host index */
4174 ioc
->reply_free_host_index
= ioc
->reply_free_queue_depth
- 1;
4175 writel(ioc
->reply_free_host_index
, &ioc
->chip
->ReplyFreeHostIndex
);
4177 /* initialize reply post host index */
4178 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4179 writel(reply_q
->msix_index
<< MPI2_RPHI_MSIX_INDEX_SHIFT
,
4180 &ioc
->chip
->ReplyPostHostIndex
);
4181 if (!_base_is_controller_msix_enabled(ioc
))
4182 goto skip_init_reply_post_host_index
;
4185 skip_init_reply_post_host_index
:
4187 _base_unmask_interrupts(ioc
);
4189 r
= _base_event_notification(ioc
, sleep_flag
);
4193 if (sleep_flag
== CAN_SLEEP
)
4194 _base_static_config_pages(ioc
);
4197 if (ioc
->is_driver_loading
) {
4198 if (ioc
->is_warpdrive
&& ioc
->manu_pg10
.OEMIdentifier
4201 le32_to_cpu(ioc
->manu_pg10
.OEMSpecificFlags0
) &
4202 MFG_PAGE10_HIDE_SSDS_MASK
);
4203 if (hide_flag
!= MFG_PAGE10_HIDE_SSDS_MASK
)
4204 ioc
->mfg_pg10_hide_flag
= hide_flag
;
4206 ioc
->wait_for_discovery_to_complete
=
4207 _base_determine_wait_on_discovery(ioc
);
4208 return r
; /* scan_start and scan_finished support */
4210 r
= _base_send_port_enable(ioc
, sleep_flag
);
4218 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4219 * @ioc: per adapter object
4224 mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER
*ioc
)
4226 struct pci_dev
*pdev
= ioc
->pdev
;
4228 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4231 if (ioc
->chip_phys
&& ioc
->chip
) {
4232 _base_mask_interrupts(ioc
);
4233 ioc
->shost_recovery
= 1;
4234 _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4235 ioc
->shost_recovery
= 0;
4238 _base_free_irq(ioc
);
4239 _base_disable_msix(ioc
);
4241 if (ioc
->chip_phys
&& ioc
->chip
)
4245 if (pci_is_enabled(pdev
)) {
4246 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
4247 pci_disable_pcie_error_reporting(pdev
);
4248 pci_disable_device(pdev
);
4254 * mpt2sas_base_attach - attach controller instance
4255 * @ioc: per adapter object
4257 * Returns 0 for success, non-zero for failure.
4260 mpt2sas_base_attach(struct MPT2SAS_ADAPTER
*ioc
)
4263 int cpu_id
, last_cpu_id
= 0;
4265 dinitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4268 /* setup cpu_msix_table */
4269 ioc
->cpu_count
= num_online_cpus();
4270 for_each_online_cpu(cpu_id
)
4271 last_cpu_id
= cpu_id
;
4272 ioc
->cpu_msix_table_sz
= last_cpu_id
+ 1;
4273 ioc
->cpu_msix_table
= kzalloc(ioc
->cpu_msix_table_sz
, GFP_KERNEL
);
4274 ioc
->reply_queue_count
= 1;
4275 if (!ioc
->cpu_msix_table
) {
4276 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"allocation for "
4277 "cpu_msix_table failed!!!\n", ioc
->name
));
4279 goto out_free_resources
;
4282 if (ioc
->is_warpdrive
) {
4283 ioc
->reply_post_host_index
= kcalloc(ioc
->cpu_msix_table_sz
,
4284 sizeof(resource_size_t
*), GFP_KERNEL
);
4285 if (!ioc
->reply_post_host_index
) {
4286 dfailprintk(ioc
, printk(MPT2SAS_INFO_FMT
"allocation "
4287 "for cpu_msix_table failed!!!\n", ioc
->name
));
4289 goto out_free_resources
;
4293 r
= mpt2sas_base_map_resources(ioc
);
4295 goto out_free_resources
;
4297 if (ioc
->is_warpdrive
) {
4298 ioc
->reply_post_host_index
[0] =
4299 (resource_size_t
*)&ioc
->chip
->ReplyPostHostIndex
;
4301 for (i
= 1; i
< ioc
->cpu_msix_table_sz
; i
++)
4302 ioc
->reply_post_host_index
[i
] = (resource_size_t
*)
4303 ((u8
*)&ioc
->chip
->Doorbell
+ (0x4000 + ((i
- 1)
4307 pci_set_drvdata(ioc
->pdev
, ioc
->shost
);
4308 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
4310 goto out_free_resources
;
4312 r
= _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4314 goto out_free_resources
;
4316 ioc
->pfacts
= kcalloc(ioc
->facts
.NumberOfPorts
,
4317 sizeof(struct mpt2sas_port_facts
), GFP_KERNEL
);
4320 goto out_free_resources
;
4323 for (i
= 0 ; i
< ioc
->facts
.NumberOfPorts
; i
++) {
4324 r
= _base_get_port_facts(ioc
, i
, CAN_SLEEP
);
4326 goto out_free_resources
;
4329 r
= _base_allocate_memory_pools(ioc
, CAN_SLEEP
);
4331 goto out_free_resources
;
4333 init_waitqueue_head(&ioc
->reset_wq
);
4334 /* allocate memory pd handle bitmask list */
4335 ioc
->pd_handles_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
4336 if (ioc
->facts
.MaxDevHandle
% 8)
4337 ioc
->pd_handles_sz
++;
4338 ioc
->pd_handles
= kzalloc(ioc
->pd_handles_sz
,
4340 if (!ioc
->pd_handles
) {
4342 goto out_free_resources
;
4344 ioc
->blocking_handles
= kzalloc(ioc
->pd_handles_sz
,
4346 if (!ioc
->blocking_handles
) {
4348 goto out_free_resources
;
4350 ioc
->fwfault_debug
= mpt2sas_fwfault_debug
;
4352 /* base internal command bits */
4353 mutex_init(&ioc
->base_cmds
.mutex
);
4354 ioc
->base_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4355 ioc
->base_cmds
.status
= MPT2_CMD_NOT_USED
;
4357 /* port_enable command bits */
4358 ioc
->port_enable_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4359 ioc
->port_enable_cmds
.status
= MPT2_CMD_NOT_USED
;
4361 /* transport internal command bits */
4362 ioc
->transport_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4363 ioc
->transport_cmds
.status
= MPT2_CMD_NOT_USED
;
4364 mutex_init(&ioc
->transport_cmds
.mutex
);
4366 /* scsih internal command bits */
4367 ioc
->scsih_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4368 ioc
->scsih_cmds
.status
= MPT2_CMD_NOT_USED
;
4369 mutex_init(&ioc
->scsih_cmds
.mutex
);
4371 /* task management internal command bits */
4372 ioc
->tm_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4373 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
4374 mutex_init(&ioc
->tm_cmds
.mutex
);
4376 /* config page internal command bits */
4377 ioc
->config_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4378 ioc
->config_cmds
.status
= MPT2_CMD_NOT_USED
;
4379 mutex_init(&ioc
->config_cmds
.mutex
);
4381 /* ctl module internal command bits */
4382 ioc
->ctl_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4383 ioc
->ctl_cmds
.sense
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
4384 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
4385 mutex_init(&ioc
->ctl_cmds
.mutex
);
4387 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4388 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4389 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
||
4390 !ioc
->ctl_cmds
.sense
) {
4392 goto out_free_resources
;
4395 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4396 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4397 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
) {
4399 goto out_free_resources
;
4402 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4403 ioc
->event_masks
[i
] = -1;
4405 /* here we enable the events we care about */
4406 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DISCOVERY
);
4407 _base_unmask_events(ioc
, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
);
4408 _base_unmask_events(ioc
, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
4409 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4410 _base_unmask_events(ioc
, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
);
4411 _base_unmask_events(ioc
, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
);
4412 _base_unmask_events(ioc
, MPI2_EVENT_IR_VOLUME
);
4413 _base_unmask_events(ioc
, MPI2_EVENT_IR_PHYSICAL_DISK
);
4414 _base_unmask_events(ioc
, MPI2_EVENT_IR_OPERATION_STATUS
);
4415 _base_unmask_events(ioc
, MPI2_EVENT_LOG_ENTRY_ADDED
);
4416 r
= _base_make_ioc_operational(ioc
, CAN_SLEEP
);
4418 goto out_free_resources
;
4420 ioc
->non_operational_loop
= 0;
4426 ioc
->remove_host
= 1;
4427 mpt2sas_base_free_resources(ioc
);
4428 _base_release_memory_pools(ioc
);
4429 pci_set_drvdata(ioc
->pdev
, NULL
);
4430 kfree(ioc
->cpu_msix_table
);
4431 if (ioc
->is_warpdrive
)
4432 kfree(ioc
->reply_post_host_index
);
4433 kfree(ioc
->pd_handles
);
4434 kfree(ioc
->blocking_handles
);
4435 kfree(ioc
->tm_cmds
.reply
);
4436 kfree(ioc
->transport_cmds
.reply
);
4437 kfree(ioc
->scsih_cmds
.reply
);
4438 kfree(ioc
->config_cmds
.reply
);
4439 kfree(ioc
->base_cmds
.reply
);
4440 kfree(ioc
->port_enable_cmds
.reply
);
4441 kfree(ioc
->ctl_cmds
.reply
);
4442 kfree(ioc
->ctl_cmds
.sense
);
4444 ioc
->ctl_cmds
.reply
= NULL
;
4445 ioc
->base_cmds
.reply
= NULL
;
4446 ioc
->tm_cmds
.reply
= NULL
;
4447 ioc
->scsih_cmds
.reply
= NULL
;
4448 ioc
->transport_cmds
.reply
= NULL
;
4449 ioc
->config_cmds
.reply
= NULL
;
4456 * mpt2sas_base_detach - remove controller instance
4457 * @ioc: per adapter object
4462 mpt2sas_base_detach(struct MPT2SAS_ADAPTER
*ioc
)
4465 dexitprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
4468 mpt2sas_base_stop_watchdog(ioc
);
4469 mpt2sas_base_free_resources(ioc
);
4470 _base_release_memory_pools(ioc
);
4471 pci_set_drvdata(ioc
->pdev
, NULL
);
4472 kfree(ioc
->cpu_msix_table
);
4473 if (ioc
->is_warpdrive
)
4474 kfree(ioc
->reply_post_host_index
);
4475 kfree(ioc
->pd_handles
);
4476 kfree(ioc
->blocking_handles
);
4478 kfree(ioc
->ctl_cmds
.reply
);
4479 kfree(ioc
->ctl_cmds
.sense
);
4480 kfree(ioc
->base_cmds
.reply
);
4481 kfree(ioc
->port_enable_cmds
.reply
);
4482 kfree(ioc
->tm_cmds
.reply
);
4483 kfree(ioc
->transport_cmds
.reply
);
4484 kfree(ioc
->scsih_cmds
.reply
);
4485 kfree(ioc
->config_cmds
.reply
);
4489 * _base_reset_handler - reset callback handler (for base)
4490 * @ioc: per adapter object
4491 * @reset_phase: phase
4493 * The handler for doing any required cleanup or initialization.
4495 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4496 * MPT2_IOC_DONE_RESET
4501 _base_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
4503 mpt2sas_scsih_reset_handler(ioc
, reset_phase
);
4504 mpt2sas_ctl_reset_handler(ioc
, reset_phase
);
4505 switch (reset_phase
) {
4506 case MPT2_IOC_PRE_RESET
:
4507 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4508 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
4510 case MPT2_IOC_AFTER_RESET
:
4511 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4512 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
4513 if (ioc
->transport_cmds
.status
& MPT2_CMD_PENDING
) {
4514 ioc
->transport_cmds
.status
|= MPT2_CMD_RESET
;
4515 mpt2sas_base_free_smid(ioc
, ioc
->transport_cmds
.smid
);
4516 complete(&ioc
->transport_cmds
.done
);
4518 if (ioc
->base_cmds
.status
& MPT2_CMD_PENDING
) {
4519 ioc
->base_cmds
.status
|= MPT2_CMD_RESET
;
4520 mpt2sas_base_free_smid(ioc
, ioc
->base_cmds
.smid
);
4521 complete(&ioc
->base_cmds
.done
);
4523 if (ioc
->port_enable_cmds
.status
& MPT2_CMD_PENDING
) {
4524 ioc
->port_enable_failed
= 1;
4525 ioc
->port_enable_cmds
.status
|= MPT2_CMD_RESET
;
4526 mpt2sas_base_free_smid(ioc
, ioc
->port_enable_cmds
.smid
);
4527 if (ioc
->is_driver_loading
) {
4528 ioc
->start_scan_failed
=
4529 MPI2_IOCSTATUS_INTERNAL_ERROR
;
4530 ioc
->start_scan
= 0;
4531 ioc
->port_enable_cmds
.status
=
4534 complete(&ioc
->port_enable_cmds
.done
);
4537 if (ioc
->config_cmds
.status
& MPT2_CMD_PENDING
) {
4538 ioc
->config_cmds
.status
|= MPT2_CMD_RESET
;
4539 mpt2sas_base_free_smid(ioc
, ioc
->config_cmds
.smid
);
4540 ioc
->config_cmds
.smid
= USHRT_MAX
;
4541 complete(&ioc
->config_cmds
.done
);
4544 case MPT2_IOC_DONE_RESET
:
4545 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
4546 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
4552 * _wait_for_commands_to_complete - reset controller
4553 * @ioc: Pointer to MPT_ADAPTER structure
4554 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4556 * This function waiting(3s) for all pending commands to complete
4557 * prior to putting controller in reset.
4560 _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
)
4563 unsigned long flags
;
4566 ioc
->pending_io_count
= 0;
4567 if (sleep_flag
!= CAN_SLEEP
)
4570 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 0);
4571 if ((ioc_state
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
)
4574 /* pending command count */
4575 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4576 for (i
= 0; i
< ioc
->scsiio_depth
; i
++)
4577 if (ioc
->scsi_lookup
[i
].cb_idx
!= 0xFF)
4578 ioc
->pending_io_count
++;
4579 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4581 if (!ioc
->pending_io_count
)
4584 /* wait for pending commands to complete */
4585 wait_event_timeout(ioc
->reset_wq
, ioc
->pending_io_count
== 0, 10 * HZ
);
4589 * mpt2sas_base_hard_reset_handler - reset controller
4590 * @ioc: Pointer to MPT_ADAPTER structure
4591 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4592 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4594 * Returns 0 for success, non-zero for failure.
4597 mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int sleep_flag
,
4598 enum reset_type type
)
4601 unsigned long flags
;
4603 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
4606 if (ioc
->pci_error_recovery
) {
4607 printk(MPT2SAS_ERR_FMT
"%s: pci error recovery reset\n",
4608 ioc
->name
, __func__
);
4613 if (mpt2sas_fwfault_debug
)
4614 mpt2sas_halt_firmware(ioc
);
4616 /* TODO - What we really should be doing is pulling
4617 * out all the code associated with NO_SLEEP; its never used.
4618 * That is legacy code from mpt fusion driver, ported over.
4619 * I will leave this BUG_ON here for now till its been resolved.
4621 BUG_ON(sleep_flag
== NO_SLEEP
);
4623 /* wait for an active reset in progress to complete */
4624 if (!mutex_trylock(&ioc
->reset_in_progress_mutex
)) {
4627 } while (ioc
->shost_recovery
== 1);
4628 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit\n", ioc
->name
,
4630 return ioc
->ioc_reset_in_progress_status
;
4633 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4634 ioc
->shost_recovery
= 1;
4635 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4637 _base_reset_handler(ioc
, MPT2_IOC_PRE_RESET
);
4638 _wait_for_commands_to_complete(ioc
, sleep_flag
);
4639 _base_mask_interrupts(ioc
);
4640 r
= _base_make_ioc_ready(ioc
, sleep_flag
, type
);
4643 _base_reset_handler(ioc
, MPT2_IOC_AFTER_RESET
);
4645 /* If this hard reset is called while port enable is active, then
4646 * there is no reason to call make_ioc_operational
4648 if (ioc
->is_driver_loading
&& ioc
->port_enable_failed
) {
4649 ioc
->remove_host
= 1;
4653 r
= _base_make_ioc_operational(ioc
, sleep_flag
);
4655 _base_reset_handler(ioc
, MPT2_IOC_DONE_RESET
);
4657 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: %s\n",
4658 ioc
->name
, __func__
, ((r
== 0) ? "SUCCESS" : "FAILED")));
4660 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4661 ioc
->ioc_reset_in_progress_status
= r
;
4662 ioc
->shost_recovery
= 0;
4663 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4664 mutex_unlock(&ioc
->reset_in_progress_mutex
);
4667 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: exit\n", ioc
->name
,