2 * This is the Fusion MPT base driver providing common API layer interface
3 * for access to MPT (Message Passing Technology) firmware.
5 * This code is based on drivers/scsi/mpt3sas/mpt3sas_base.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * (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>
58 #include <linux/time.h>
59 #include <linux/kthread.h>
60 #include <linux/aer.h>
63 #include "mpt3sas_base.h"
65 static MPT_CALLBACK mpt_callbacks
[MPT_MAX_CALLBACKS
];
68 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
70 /* maximum controller queue depth */
71 #define MAX_HBA_QUEUE_DEPTH 30000
72 #define MAX_CHAIN_DEPTH 100000
73 static int max_queue_depth
= -1;
74 module_param(max_queue_depth
, int, 0);
75 MODULE_PARM_DESC(max_queue_depth
, " max controller queue depth ");
77 static int max_sgl_entries
= -1;
78 module_param(max_sgl_entries
, int, 0);
79 MODULE_PARM_DESC(max_sgl_entries
, " max sg entries ");
81 static int msix_disable
= -1;
82 module_param(msix_disable
, int, 0);
83 MODULE_PARM_DESC(msix_disable
, " disable msix routed interrupts (default=0)");
85 static int max_msix_vectors
= 8;
86 module_param(max_msix_vectors
, int, 0);
87 MODULE_PARM_DESC(max_msix_vectors
,
88 " max msix vectors - (default=8)");
90 static int mpt3sas_fwfault_debug
;
91 MODULE_PARM_DESC(mpt3sas_fwfault_debug
,
92 " enable detection of firmware fault and halt firmware - (default=0)");
95 _base_get_ioc_facts(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
);
98 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
102 _scsih_set_fwfault_debug(const char *val
, struct kernel_param
*kp
)
104 int ret
= param_set_int(val
, kp
);
105 struct MPT3SAS_ADAPTER
*ioc
;
110 pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug
);
111 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
112 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
115 module_param_call(mpt3sas_fwfault_debug
, _scsih_set_fwfault_debug
,
116 param_get_int
, &mpt3sas_fwfault_debug
, 0644);
119 * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc
120 * @arg: input argument, used to derive ioc
122 * Return 0 if controller is removed from pci subsystem.
123 * Return -1 for other case.
125 static int mpt3sas_remove_dead_ioc_func(void *arg
)
127 struct MPT3SAS_ADAPTER
*ioc
= (struct MPT3SAS_ADAPTER
*)arg
;
128 struct pci_dev
*pdev
;
136 pci_stop_and_remove_bus_device_locked(pdev
);
141 * _base_fault_reset_work - workq handling ioc fault conditions
142 * @work: input argument, used to derive ioc
148 _base_fault_reset_work(struct work_struct
*work
)
150 struct MPT3SAS_ADAPTER
*ioc
=
151 container_of(work
, struct MPT3SAS_ADAPTER
, fault_reset_work
.work
);
155 struct task_struct
*p
;
158 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
159 if (ioc
->shost_recovery
)
161 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
163 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
164 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_MASK
) {
165 pr_err(MPT3SAS_FMT
"SAS host is non-operational !!!!\n",
169 * Call _scsih_flush_pending_cmds callback so that we flush all
170 * pending commands back to OS. This call is required to aovid
171 * deadlock at block layer. Dead IOC will fail to do diag reset,
172 * and this call is safe since dead ioc will never return any
173 * command back from HW.
175 ioc
->schedule_dead_ioc_flush_running_cmds(ioc
);
177 * Set remove_host flag early since kernel thread will
178 * take some time to execute.
180 ioc
->remove_host
= 1;
181 /*Remove the Dead Host */
182 p
= kthread_run(mpt3sas_remove_dead_ioc_func
, ioc
,
183 "mpt3sas_dead_ioc_%d", ioc
->id
);
186 "%s: Running mpt3sas_dead_ioc thread failed !!!!\n",
187 ioc
->name
, __func__
);
190 "%s: Running mpt3sas_dead_ioc thread success !!!!\n",
191 ioc
->name
, __func__
);
192 return; /* don't rearm timer */
195 if ((doorbell
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
) {
196 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
198 pr_warn(MPT3SAS_FMT
"%s: hard reset: %s\n", ioc
->name
,
199 __func__
, (rc
== 0) ? "success" : "failed");
200 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
201 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
202 mpt3sas_base_fault_info(ioc
, doorbell
&
203 MPI2_DOORBELL_DATA_MASK
);
204 if (rc
&& (doorbell
& MPI2_IOC_STATE_MASK
) !=
205 MPI2_IOC_STATE_OPERATIONAL
)
206 return; /* don't rearm timer */
209 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
211 if (ioc
->fault_reset_work_q
)
212 queue_delayed_work(ioc
->fault_reset_work_q
,
213 &ioc
->fault_reset_work
,
214 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
215 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
219 * mpt3sas_base_start_watchdog - start the fault_reset_work_q
220 * @ioc: per adapter object
226 mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
230 if (ioc
->fault_reset_work_q
)
233 /* initialize fault polling */
235 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, _base_fault_reset_work
);
236 snprintf(ioc
->fault_reset_work_q_name
,
237 sizeof(ioc
->fault_reset_work_q_name
), "poll_%d_status", ioc
->id
);
238 ioc
->fault_reset_work_q
=
239 create_singlethread_workqueue(ioc
->fault_reset_work_q_name
);
240 if (!ioc
->fault_reset_work_q
) {
241 pr_err(MPT3SAS_FMT
"%s: failed (line=%d)\n",
242 ioc
->name
, __func__
, __LINE__
);
245 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
246 if (ioc
->fault_reset_work_q
)
247 queue_delayed_work(ioc
->fault_reset_work_q
,
248 &ioc
->fault_reset_work
,
249 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
250 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
254 * mpt3sas_base_stop_watchdog - stop the fault_reset_work_q
255 * @ioc: per adapter object
261 mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
264 struct workqueue_struct
*wq
;
266 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
267 wq
= ioc
->fault_reset_work_q
;
268 ioc
->fault_reset_work_q
= NULL
;
269 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
271 if (!cancel_delayed_work_sync(&ioc
->fault_reset_work
))
273 destroy_workqueue(wq
);
278 * mpt3sas_base_fault_info - verbose translation of firmware FAULT code
279 * @ioc: per adapter object
280 * @fault_code: fault code
285 mpt3sas_base_fault_info(struct MPT3SAS_ADAPTER
*ioc
, u16 fault_code
)
287 pr_err(MPT3SAS_FMT
"fault_state(0x%04x)!\n",
288 ioc
->name
, fault_code
);
292 * mpt3sas_halt_firmware - halt's mpt controller firmware
293 * @ioc: per adapter object
295 * For debugging timeout related issues. Writing 0xCOFFEE00
296 * to the doorbell register will halt controller firmware. With
297 * the purpose to stop both driver and firmware, the enduser can
298 * obtain a ring buffer from controller UART.
301 mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER
*ioc
)
305 if (!ioc
->fwfault_debug
)
310 doorbell
= readl(&ioc
->chip
->Doorbell
);
311 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
312 mpt3sas_base_fault_info(ioc
, doorbell
);
314 writel(0xC0FFEE00, &ioc
->chip
->Doorbell
);
315 pr_err(MPT3SAS_FMT
"Firmware is halted due to command timeout\n",
319 if (ioc
->fwfault_debug
== 2)
323 panic("panic in %s\n", __func__
);
326 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
328 * _base_sas_ioc_info - verbose translation of the ioc status
329 * @ioc: per adapter object
330 * @mpi_reply: reply mf payload returned from firmware
331 * @request_hdr: request mf
336 _base_sas_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, MPI2DefaultReply_t
*mpi_reply
,
337 MPI2RequestHeader_t
*request_hdr
)
339 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
343 char *func_str
= NULL
;
345 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
346 if (request_hdr
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
347 request_hdr
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
348 request_hdr
->Function
== MPI2_FUNCTION_EVENT_NOTIFICATION
)
351 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
354 switch (ioc_status
) {
356 /****************************************************************************
357 * Common IOCStatus values for all replies
358 ****************************************************************************/
360 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
361 desc
= "invalid function";
363 case MPI2_IOCSTATUS_BUSY
:
366 case MPI2_IOCSTATUS_INVALID_SGL
:
367 desc
= "invalid sgl";
369 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
370 desc
= "internal error";
372 case MPI2_IOCSTATUS_INVALID_VPID
:
373 desc
= "invalid vpid";
375 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
376 desc
= "insufficient resources";
378 case MPI2_IOCSTATUS_INVALID_FIELD
:
379 desc
= "invalid field";
381 case MPI2_IOCSTATUS_INVALID_STATE
:
382 desc
= "invalid state";
384 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED
:
385 desc
= "op state not supported";
388 /****************************************************************************
389 * Config IOCStatus values
390 ****************************************************************************/
392 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION
:
393 desc
= "config invalid action";
395 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE
:
396 desc
= "config invalid type";
398 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
:
399 desc
= "config invalid page";
401 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA
:
402 desc
= "config invalid data";
404 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS
:
405 desc
= "config no defaults";
407 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT
:
408 desc
= "config cant commit";
411 /****************************************************************************
413 ****************************************************************************/
415 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
416 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
417 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
418 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
419 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
420 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
421 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
422 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
423 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
424 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
425 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
426 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
429 /****************************************************************************
430 * For use by SCSI Initiator and SCSI Target end-to-end data protection
431 ****************************************************************************/
433 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
434 desc
= "eedp guard error";
436 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
437 desc
= "eedp ref tag error";
439 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
440 desc
= "eedp app tag error";
443 /****************************************************************************
445 ****************************************************************************/
447 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX
:
448 desc
= "target invalid io index";
450 case MPI2_IOCSTATUS_TARGET_ABORTED
:
451 desc
= "target aborted";
453 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
:
454 desc
= "target no conn retryable";
456 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION
:
457 desc
= "target no connection";
459 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
:
460 desc
= "target xfer count mismatch";
462 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
:
463 desc
= "target data offset error";
465 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
:
466 desc
= "target too much write data";
468 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT
:
469 desc
= "target iu too short";
471 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
:
472 desc
= "target ack nak timeout";
474 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED
:
475 desc
= "target nak received";
478 /****************************************************************************
479 * Serial Attached SCSI values
480 ****************************************************************************/
482 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED
:
483 desc
= "smp request failed";
485 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN
:
486 desc
= "smp data overrun";
489 /****************************************************************************
490 * Diagnostic Buffer Post / Diagnostic Release values
491 ****************************************************************************/
493 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
:
494 desc
= "diagnostic released";
503 switch (request_hdr
->Function
) {
504 case MPI2_FUNCTION_CONFIG
:
505 frame_sz
= sizeof(Mpi2ConfigRequest_t
) + ioc
->sge_size
;
506 func_str
= "config_page";
508 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
509 frame_sz
= sizeof(Mpi2SCSITaskManagementRequest_t
);
510 func_str
= "task_mgmt";
512 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
513 frame_sz
= sizeof(Mpi2SasIoUnitControlRequest_t
);
514 func_str
= "sas_iounit_ctl";
516 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
517 frame_sz
= sizeof(Mpi2SepRequest_t
);
518 func_str
= "enclosure";
520 case MPI2_FUNCTION_IOC_INIT
:
521 frame_sz
= sizeof(Mpi2IOCInitRequest_t
);
522 func_str
= "ioc_init";
524 case MPI2_FUNCTION_PORT_ENABLE
:
525 frame_sz
= sizeof(Mpi2PortEnableRequest_t
);
526 func_str
= "port_enable";
528 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
529 frame_sz
= sizeof(Mpi2SmpPassthroughRequest_t
) + ioc
->sge_size
;
530 func_str
= "smp_passthru";
534 func_str
= "unknown";
538 pr_warn(MPT3SAS_FMT
"ioc_status: %s(0x%04x), request(0x%p),(%s)\n",
539 ioc
->name
, desc
, ioc_status
, request_hdr
, func_str
);
541 _debug_dump_mf(request_hdr
, frame_sz
/4);
545 * _base_display_event_data - verbose translation of firmware asyn events
546 * @ioc: per adapter object
547 * @mpi_reply: reply mf payload returned from firmware
552 _base_display_event_data(struct MPT3SAS_ADAPTER
*ioc
,
553 Mpi2EventNotificationReply_t
*mpi_reply
)
558 if (!(ioc
->logging_level
& MPT_DEBUG_EVENTS
))
561 event
= le16_to_cpu(mpi_reply
->Event
);
564 case MPI2_EVENT_LOG_DATA
:
567 case MPI2_EVENT_STATE_CHANGE
:
568 desc
= "Status Change";
570 case MPI2_EVENT_HARD_RESET_RECEIVED
:
571 desc
= "Hard Reset Received";
573 case MPI2_EVENT_EVENT_CHANGE
:
574 desc
= "Event Change";
576 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
577 desc
= "Device Status Change";
579 case MPI2_EVENT_IR_OPERATION_STATUS
:
580 desc
= "IR Operation Status";
582 case MPI2_EVENT_SAS_DISCOVERY
:
584 Mpi2EventDataSasDiscovery_t
*event_data
=
585 (Mpi2EventDataSasDiscovery_t
*)mpi_reply
->EventData
;
586 pr_info(MPT3SAS_FMT
"Discovery: (%s)", ioc
->name
,
587 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
589 if (event_data
->DiscoveryStatus
)
590 pr_info("discovery_status(0x%08x)",
591 le32_to_cpu(event_data
->DiscoveryStatus
));
595 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
596 desc
= "SAS Broadcast Primitive";
598 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
599 desc
= "SAS Init Device Status Change";
601 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW
:
602 desc
= "SAS Init Table Overflow";
604 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
605 desc
= "SAS Topology Change List";
607 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
608 desc
= "SAS Enclosure Device Status Change";
610 case MPI2_EVENT_IR_VOLUME
:
613 case MPI2_EVENT_IR_PHYSICAL_DISK
:
614 desc
= "IR Physical Disk";
616 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
617 desc
= "IR Configuration Change List";
619 case MPI2_EVENT_LOG_ENTRY_ADDED
:
620 desc
= "Log Entry Added";
627 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
, desc
);
632 * _base_sas_log_info - verbose translation of firmware log info
633 * @ioc: per adapter object
634 * @log_info: log info
639 _base_sas_log_info(struct MPT3SAS_ADAPTER
*ioc
, u32 log_info
)
650 union loginfo_type sas_loginfo
;
651 char *originator_str
= NULL
;
653 sas_loginfo
.loginfo
= log_info
;
654 if (sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/)
657 /* each nexus loss loginfo */
658 if (log_info
== 0x31170000)
661 /* eat the loginfos associated with task aborts */
662 if (ioc
->ignore_loginfos
&& (log_info
== 0x30050000 || log_info
==
663 0x31140000 || log_info
== 0x31130000))
666 switch (sas_loginfo
.dw
.originator
) {
668 originator_str
= "IOP";
671 originator_str
= "PL";
674 originator_str
= "IR";
679 "log_info(0x%08x): originator(%s), code(0x%02x), sub_code(0x%04x)\n",
681 originator_str
, sas_loginfo
.dw
.code
,
682 sas_loginfo
.dw
.subcode
);
686 * _base_display_reply_info -
687 * @ioc: per adapter object
688 * @smid: system request message index
689 * @msix_index: MSIX table index supplied by the OS
690 * @reply: reply message frame(lower 32bit addr)
695 _base_display_reply_info(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
698 MPI2DefaultReply_t
*mpi_reply
;
702 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
703 if (unlikely(!mpi_reply
)) {
704 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
705 ioc
->name
, __FILE__
, __LINE__
, __func__
);
708 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
709 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
710 if ((ioc_status
& MPI2_IOCSTATUS_MASK
) &&
711 (ioc
->logging_level
& MPT_DEBUG_REPLY
)) {
712 _base_sas_ioc_info(ioc
, mpi_reply
,
713 mpt3sas_base_get_msg_frame(ioc
, smid
));
716 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
) {
717 loginfo
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
718 _base_sas_log_info(ioc
, loginfo
);
721 if (ioc_status
|| loginfo
) {
722 ioc_status
&= MPI2_IOCSTATUS_MASK
;
723 mpt3sas_trigger_mpi(ioc
, ioc_status
, loginfo
);
728 * mpt3sas_base_done - base internal command completion routine
729 * @ioc: per adapter object
730 * @smid: system request message index
731 * @msix_index: MSIX table index supplied by the OS
732 * @reply: reply message frame(lower 32bit addr)
734 * Return 1 meaning mf should be freed from _base_interrupt
735 * 0 means the mf is freed from this function.
738 mpt3sas_base_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
741 MPI2DefaultReply_t
*mpi_reply
;
743 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
744 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
747 if (ioc
->base_cmds
.status
== MPT3_CMD_NOT_USED
)
750 ioc
->base_cmds
.status
|= MPT3_CMD_COMPLETE
;
752 ioc
->base_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
753 memcpy(ioc
->base_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
755 ioc
->base_cmds
.status
&= ~MPT3_CMD_PENDING
;
757 complete(&ioc
->base_cmds
.done
);
762 * _base_async_event - main callback handler for firmware asyn events
763 * @ioc: per adapter object
764 * @msix_index: MSIX table index supplied by the OS
765 * @reply: reply message frame(lower 32bit addr)
767 * Return 1 meaning mf should be freed from _base_interrupt
768 * 0 means the mf is freed from this function.
771 _base_async_event(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
, u32 reply
)
773 Mpi2EventNotificationReply_t
*mpi_reply
;
774 Mpi2EventAckRequest_t
*ack_request
;
777 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
780 if (mpi_reply
->Function
!= MPI2_FUNCTION_EVENT_NOTIFICATION
)
782 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
783 _base_display_event_data(ioc
, mpi_reply
);
785 if (!(mpi_reply
->AckRequired
& MPI2_EVENT_NOTIFICATION_ACK_REQUIRED
))
787 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
789 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
790 ioc
->name
, __func__
);
794 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
795 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
796 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
797 ack_request
->Event
= mpi_reply
->Event
;
798 ack_request
->EventContext
= mpi_reply
->EventContext
;
799 ack_request
->VF_ID
= 0; /* TODO */
800 ack_request
->VP_ID
= 0;
801 mpt3sas_base_put_smid_default(ioc
, smid
);
805 /* scsih callback handler */
806 mpt3sas_scsih_event_callback(ioc
, msix_index
, reply
);
808 /* ctl callback handler */
809 mpt3sas_ctl_event_callback(ioc
, msix_index
, reply
);
815 * _base_get_cb_idx - obtain the callback index
816 * @ioc: per adapter object
817 * @smid: system request message index
819 * Return callback index.
822 _base_get_cb_idx(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
827 if (smid
< ioc
->hi_priority_smid
) {
829 cb_idx
= ioc
->scsi_lookup
[i
].cb_idx
;
830 } else if (smid
< ioc
->internal_smid
) {
831 i
= smid
- ioc
->hi_priority_smid
;
832 cb_idx
= ioc
->hpr_lookup
[i
].cb_idx
;
833 } else if (smid
<= ioc
->hba_queue_depth
) {
834 i
= smid
- ioc
->internal_smid
;
835 cb_idx
= ioc
->internal_lookup
[i
].cb_idx
;
842 * _base_mask_interrupts - disable interrupts
843 * @ioc: per adapter object
845 * Disabling ResetIRQ, Reply and Doorbell Interrupts
850 _base_mask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
854 ioc
->mask_interrupts
= 1;
855 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
856 him_register
|= MPI2_HIM_DIM
+ MPI2_HIM_RIM
+ MPI2_HIM_RESET_IRQ_MASK
;
857 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
858 readl(&ioc
->chip
->HostInterruptMask
);
862 * _base_unmask_interrupts - enable interrupts
863 * @ioc: per adapter object
865 * Enabling only Reply Interrupts
870 _base_unmask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
874 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
875 him_register
&= ~MPI2_HIM_RIM
;
876 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
877 ioc
->mask_interrupts
= 0;
880 union reply_descriptor
{
889 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
890 * @irq: irq number (not used)
891 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
892 * @r: pt_regs pointer (not used)
894 * Return IRQ_HANDLE if processed, else IRQ_NONE.
897 _base_interrupt(int irq
, void *bus_id
)
899 struct adapter_reply_queue
*reply_q
= bus_id
;
900 union reply_descriptor rd
;
902 u8 request_desript_type
;
906 u8 msix_index
= reply_q
->msix_index
;
907 struct MPT3SAS_ADAPTER
*ioc
= reply_q
->ioc
;
908 Mpi2ReplyDescriptorsUnion_t
*rpf
;
911 if (ioc
->mask_interrupts
)
914 if (!atomic_add_unless(&reply_q
->busy
, 1, 1))
917 rpf
= &reply_q
->reply_post_free
[reply_q
->reply_post_host_index
];
918 request_desript_type
= rpf
->Default
.ReplyFlags
919 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
920 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
) {
921 atomic_dec(&reply_q
->busy
);
928 rd
.word
= le64_to_cpu(rpf
->Words
);
929 if (rd
.u
.low
== UINT_MAX
|| rd
.u
.high
== UINT_MAX
)
932 smid
= le16_to_cpu(rpf
->Default
.DescriptorTypeDependent1
);
933 if (request_desript_type
==
934 MPI25_RPY_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO_SUCCESS
||
935 request_desript_type
==
936 MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS
) {
937 cb_idx
= _base_get_cb_idx(ioc
, smid
);
938 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
939 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
940 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
943 mpt3sas_base_free_smid(ioc
, smid
);
945 } else if (request_desript_type
==
946 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY
) {
948 rpf
->AddressReply
.ReplyFrameAddress
);
949 if (reply
> ioc
->reply_dma_max_address
||
950 reply
< ioc
->reply_dma_min_address
)
953 cb_idx
= _base_get_cb_idx(ioc
, smid
);
954 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
955 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
956 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
959 _base_display_reply_info(ioc
,
960 smid
, msix_index
, reply
);
962 mpt3sas_base_free_smid(ioc
,
966 _base_async_event(ioc
, msix_index
, reply
);
969 /* reply free queue handling */
971 ioc
->reply_free_host_index
=
972 (ioc
->reply_free_host_index
==
973 (ioc
->reply_free_queue_depth
- 1)) ?
974 0 : ioc
->reply_free_host_index
+ 1;
975 ioc
->reply_free
[ioc
->reply_free_host_index
] =
978 writel(ioc
->reply_free_host_index
,
979 &ioc
->chip
->ReplyFreeHostIndex
);
983 rpf
->Words
= cpu_to_le64(ULLONG_MAX
);
984 reply_q
->reply_post_host_index
=
985 (reply_q
->reply_post_host_index
==
986 (ioc
->reply_post_queue_depth
- 1)) ? 0 :
987 reply_q
->reply_post_host_index
+ 1;
988 request_desript_type
=
989 reply_q
->reply_post_free
[reply_q
->reply_post_host_index
].
990 Default
.ReplyFlags
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
992 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
994 if (!reply_q
->reply_post_host_index
)
995 rpf
= reply_q
->reply_post_free
;
1002 if (!completed_cmds
) {
1003 atomic_dec(&reply_q
->busy
);
1008 writel(reply_q
->reply_post_host_index
| (msix_index
<<
1009 MPI2_RPHI_MSIX_INDEX_SHIFT
), &ioc
->chip
->ReplyPostHostIndex
);
1010 atomic_dec(&reply_q
->busy
);
1015 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1016 * @ioc: per adapter object
1020 _base_is_controller_msix_enabled(struct MPT3SAS_ADAPTER
*ioc
)
1022 return (ioc
->facts
.IOCCapabilities
&
1023 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
;
1027 * mpt3sas_base_flush_reply_queues - flushing the MSIX reply queues
1028 * @ioc: per adapter object
1029 * Context: ISR conext
1031 * Called when a Task Management request has completed. We want
1032 * to flush the other reply queues so all the outstanding IO has been
1033 * completed back to OS before we process the TM completetion.
1038 mpt3sas_base_flush_reply_queues(struct MPT3SAS_ADAPTER
*ioc
)
1040 struct adapter_reply_queue
*reply_q
;
1042 /* If MSIX capability is turned off
1043 * then multi-queues are not enabled
1045 if (!_base_is_controller_msix_enabled(ioc
))
1048 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1049 if (ioc
->shost_recovery
)
1051 /* TMs are on msix_index == 0 */
1052 if (reply_q
->msix_index
== 0)
1054 _base_interrupt(reply_q
->vector
, (void *)reply_q
);
1059 * mpt3sas_base_release_callback_handler - clear interrupt callback handler
1060 * @cb_idx: callback index
1065 mpt3sas_base_release_callback_handler(u8 cb_idx
)
1067 mpt_callbacks
[cb_idx
] = NULL
;
1071 * mpt3sas_base_register_callback_handler - obtain index for the interrupt callback handler
1072 * @cb_func: callback function
1077 mpt3sas_base_register_callback_handler(MPT_CALLBACK cb_func
)
1081 for (cb_idx
= MPT_MAX_CALLBACKS
-1; cb_idx
; cb_idx
--)
1082 if (mpt_callbacks
[cb_idx
] == NULL
)
1085 mpt_callbacks
[cb_idx
] = cb_func
;
1090 * mpt3sas_base_initialize_callback_handler - initialize the interrupt callback handler
1095 mpt3sas_base_initialize_callback_handler(void)
1099 for (cb_idx
= 0; cb_idx
< MPT_MAX_CALLBACKS
; cb_idx
++)
1100 mpt3sas_base_release_callback_handler(cb_idx
);
1105 * _base_build_zero_len_sge - build zero length sg entry
1106 * @ioc: per adapter object
1107 * @paddr: virtual address for SGE
1109 * Create a zero length scatter gather entry to insure the IOCs hardware has
1110 * something to use if the target device goes brain dead and tries
1111 * to send data even when none is asked for.
1116 _base_build_zero_len_sge(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1118 u32 flags_length
= (u32
)((MPI2_SGE_FLAGS_LAST_ELEMENT
|
1119 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
|
1120 MPI2_SGE_FLAGS_SIMPLE_ELEMENT
) <<
1121 MPI2_SGE_FLAGS_SHIFT
);
1122 ioc
->base_add_sg_single(paddr
, flags_length
, -1);
1126 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1127 * @paddr: virtual address for SGE
1128 * @flags_length: SGE flags and data transfer length
1129 * @dma_addr: Physical address
1134 _base_add_sg_single_32(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1136 Mpi2SGESimple32_t
*sgel
= paddr
;
1138 flags_length
|= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING
|
1139 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1140 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1141 sgel
->Address
= cpu_to_le32(dma_addr
);
1146 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1147 * @paddr: virtual address for SGE
1148 * @flags_length: SGE flags and data transfer length
1149 * @dma_addr: Physical address
1154 _base_add_sg_single_64(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1156 Mpi2SGESimple64_t
*sgel
= paddr
;
1158 flags_length
|= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING
|
1159 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1160 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1161 sgel
->Address
= cpu_to_le64(dma_addr
);
1165 * _base_get_chain_buffer_tracker - obtain chain tracker
1166 * @ioc: per adapter object
1167 * @smid: smid associated to an IO request
1169 * Returns chain tracker(from ioc->free_chain_list)
1171 static struct chain_tracker
*
1172 _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1174 struct chain_tracker
*chain_req
;
1175 unsigned long flags
;
1177 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1178 if (list_empty(&ioc
->free_chain_list
)) {
1179 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1180 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1181 "chain buffers not available\n", ioc
->name
));
1184 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1185 struct chain_tracker
, tracker_list
);
1186 list_del_init(&chain_req
->tracker_list
);
1187 list_add_tail(&chain_req
->tracker_list
,
1188 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1189 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1195 * _base_build_sg - build generic sg
1196 * @ioc: per adapter object
1197 * @psge: virtual address for SGE
1198 * @data_out_dma: physical address for WRITES
1199 * @data_out_sz: data xfer size for WRITES
1200 * @data_in_dma: physical address for READS
1201 * @data_in_sz: data xfer size for READS
1206 _base_build_sg(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
1207 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1212 if (!data_out_sz
&& !data_in_sz
) {
1213 _base_build_zero_len_sge(ioc
, psge
);
1217 if (data_out_sz
&& data_in_sz
) {
1218 /* WRITE sgel first */
1219 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1220 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1221 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1222 ioc
->base_add_sg_single(psge
, sgl_flags
|
1223 data_out_sz
, data_out_dma
);
1226 psge
+= ioc
->sge_size
;
1228 /* READ sgel last */
1229 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1230 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1231 MPI2_SGE_FLAGS_END_OF_LIST
);
1232 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1233 ioc
->base_add_sg_single(psge
, sgl_flags
|
1234 data_in_sz
, data_in_dma
);
1235 } else if (data_out_sz
) /* WRITE */ {
1236 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1237 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1238 MPI2_SGE_FLAGS_END_OF_LIST
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1239 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1240 ioc
->base_add_sg_single(psge
, sgl_flags
|
1241 data_out_sz
, data_out_dma
);
1242 } else if (data_in_sz
) /* READ */ {
1243 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1244 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1245 MPI2_SGE_FLAGS_END_OF_LIST
);
1246 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1247 ioc
->base_add_sg_single(psge
, sgl_flags
|
1248 data_in_sz
, data_in_dma
);
1252 /* IEEE format sgls */
1255 * _base_add_sg_single_ieee - add sg element for IEEE format
1256 * @paddr: virtual address for SGE
1258 * @chain_offset: number of 128 byte elements from start of segment
1259 * @length: data transfer length
1260 * @dma_addr: Physical address
1265 _base_add_sg_single_ieee(void *paddr
, u8 flags
, u8 chain_offset
, u32 length
,
1266 dma_addr_t dma_addr
)
1268 Mpi25IeeeSgeChain64_t
*sgel
= paddr
;
1270 sgel
->Flags
= flags
;
1271 sgel
->NextChainOffset
= chain_offset
;
1272 sgel
->Length
= cpu_to_le32(length
);
1273 sgel
->Address
= cpu_to_le64(dma_addr
);
1277 * _base_build_zero_len_sge_ieee - build zero length sg entry for IEEE format
1278 * @ioc: per adapter object
1279 * @paddr: virtual address for SGE
1281 * Create a zero length scatter gather entry to insure the IOCs hardware has
1282 * something to use if the target device goes brain dead and tries
1283 * to send data even when none is asked for.
1288 _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1290 u8 sgl_flags
= (MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1291 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
|
1292 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
);
1293 _base_add_sg_single_ieee(paddr
, sgl_flags
, 0, 0, -1);
1297 * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format
1298 * @ioc: per adapter object
1299 * @scmd: scsi command
1300 * @smid: system request message index
1303 * The main routine that builds scatter gather table from a given
1304 * scsi request sent via the .queuecommand main handler.
1306 * Returns 0 success, anything else error
1309 _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER
*ioc
,
1310 struct scsi_cmnd
*scmd
, u16 smid
)
1312 Mpi2SCSIIORequest_t
*mpi_request
;
1313 dma_addr_t chain_dma
;
1314 struct scatterlist
*sg_scmd
;
1315 void *sg_local
, *chain
;
1319 u32 sges_in_segment
;
1320 u8 simple_sgl_flags
;
1321 u8 simple_sgl_flags_last
;
1323 struct chain_tracker
*chain_req
;
1325 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1327 /* init scatter gather flags */
1328 simple_sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1329 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1330 simple_sgl_flags_last
= simple_sgl_flags
|
1331 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
1332 chain_sgl_flags
= MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
1333 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1335 sg_scmd
= scsi_sglist(scmd
);
1336 sges_left
= scsi_dma_map(scmd
);
1338 sdev_printk(KERN_ERR
, scmd
->device
,
1339 "pci_map_sg failed: request for %d bytes!\n",
1340 scsi_bufflen(scmd
));
1344 sg_local
= &mpi_request
->SGL
;
1345 sges_in_segment
= (ioc
->request_sz
-
1346 offsetof(Mpi2SCSIIORequest_t
, SGL
))/ioc
->sge_size_ieee
;
1347 if (sges_left
<= sges_in_segment
)
1348 goto fill_in_last_segment
;
1350 mpi_request
->ChainOffset
= (sges_in_segment
- 1 /* chain element */) +
1351 (offsetof(Mpi2SCSIIORequest_t
, SGL
)/ioc
->sge_size_ieee
);
1353 /* fill in main message segment when there is a chain following */
1354 while (sges_in_segment
> 1) {
1355 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1356 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1357 sg_scmd
= sg_next(sg_scmd
);
1358 sg_local
+= ioc
->sge_size_ieee
;
1363 /* initializing the pointers */
1364 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1367 chain
= chain_req
->chain_buffer
;
1368 chain_dma
= chain_req
->chain_buffer_dma
;
1370 sges_in_segment
= (sges_left
<=
1371 ioc
->max_sges_in_chain_message
) ? sges_left
:
1372 ioc
->max_sges_in_chain_message
;
1373 chain_offset
= (sges_left
== sges_in_segment
) ?
1374 0 : sges_in_segment
;
1375 chain_length
= sges_in_segment
* ioc
->sge_size_ieee
;
1377 chain_length
+= ioc
->sge_size_ieee
;
1378 _base_add_sg_single_ieee(sg_local
, chain_sgl_flags
,
1379 chain_offset
, chain_length
, chain_dma
);
1383 goto fill_in_last_segment
;
1385 /* fill in chain segments */
1386 while (sges_in_segment
) {
1387 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1388 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1389 sg_scmd
= sg_next(sg_scmd
);
1390 sg_local
+= ioc
->sge_size_ieee
;
1395 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1398 chain
= chain_req
->chain_buffer
;
1399 chain_dma
= chain_req
->chain_buffer_dma
;
1403 fill_in_last_segment
:
1405 /* fill the last segment */
1408 _base_add_sg_single_ieee(sg_local
,
1409 simple_sgl_flags_last
, 0, sg_dma_len(sg_scmd
),
1410 sg_dma_address(sg_scmd
));
1412 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1413 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1414 sg_scmd
= sg_next(sg_scmd
);
1415 sg_local
+= ioc
->sge_size_ieee
;
1423 * _base_build_sg_ieee - build generic sg for IEEE format
1424 * @ioc: per adapter object
1425 * @psge: virtual address for SGE
1426 * @data_out_dma: physical address for WRITES
1427 * @data_out_sz: data xfer size for WRITES
1428 * @data_in_dma: physical address for READS
1429 * @data_in_sz: data xfer size for READS
1434 _base_build_sg_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
1435 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1440 if (!data_out_sz
&& !data_in_sz
) {
1441 _base_build_zero_len_sge_ieee(ioc
, psge
);
1445 if (data_out_sz
&& data_in_sz
) {
1446 /* WRITE sgel first */
1447 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1448 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1449 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
1453 psge
+= ioc
->sge_size_ieee
;
1455 /* READ sgel last */
1456 sgl_flags
|= MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
1457 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
1459 } else if (data_out_sz
) /* WRITE */ {
1460 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1461 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
1462 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1463 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
1465 } else if (data_in_sz
) /* READ */ {
1466 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1467 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
1468 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1469 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
1474 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1477 * _base_config_dma_addressing - set dma addressing
1478 * @ioc: per adapter object
1479 * @pdev: PCI device struct
1481 * Returns 0 for success, non-zero for failure.
1484 _base_config_dma_addressing(struct MPT3SAS_ADAPTER
*ioc
, struct pci_dev
*pdev
)
1487 u64 consistent_dma_mask
;
1490 consistent_dma_mask
= DMA_BIT_MASK(64);
1492 consistent_dma_mask
= DMA_BIT_MASK(32);
1494 if (sizeof(dma_addr_t
) > 4) {
1495 const uint64_t required_mask
=
1496 dma_get_required_mask(&pdev
->dev
);
1497 if ((required_mask
> DMA_BIT_MASK(32)) &&
1498 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1499 !pci_set_consistent_dma_mask(pdev
, consistent_dma_mask
)) {
1500 ioc
->base_add_sg_single
= &_base_add_sg_single_64
;
1501 ioc
->sge_size
= sizeof(Mpi2SGESimple64_t
);
1507 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1508 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1509 ioc
->base_add_sg_single
= &_base_add_sg_single_32
;
1510 ioc
->sge_size
= sizeof(Mpi2SGESimple32_t
);
1518 "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
1519 ioc
->name
, ioc
->dma_mask
, convert_to_kb(s
.totalram
));
1525 _base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER
*ioc
,
1526 struct pci_dev
*pdev
)
1528 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
1529 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
1536 * _base_check_enable_msix - checks MSIX capabable.
1537 * @ioc: per adapter object
1539 * Check to see if card is capable of MSIX, and set number
1540 * of available msix vectors
1543 _base_check_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1546 u16 message_control
;
1548 base
= pci_find_capability(ioc
->pdev
, PCI_CAP_ID_MSIX
);
1550 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
"msix not supported\n",
1555 /* get msix vector count */
1557 pci_read_config_word(ioc
->pdev
, base
+ 2, &message_control
);
1558 ioc
->msix_vector_count
= (message_control
& 0x3FF) + 1;
1559 if (ioc
->msix_vector_count
> 8)
1560 ioc
->msix_vector_count
= 8;
1561 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
1562 "msix is supported, vector_count(%d)\n",
1563 ioc
->name
, ioc
->msix_vector_count
));
1568 * _base_free_irq - free irq
1569 * @ioc: per adapter object
1571 * Freeing respective reply_queue from the list.
1574 _base_free_irq(struct MPT3SAS_ADAPTER
*ioc
)
1576 struct adapter_reply_queue
*reply_q
, *next
;
1578 if (list_empty(&ioc
->reply_queue_list
))
1581 list_for_each_entry_safe(reply_q
, next
, &ioc
->reply_queue_list
, list
) {
1582 list_del(&reply_q
->list
);
1583 synchronize_irq(reply_q
->vector
);
1584 free_irq(reply_q
->vector
, reply_q
);
1590 * _base_request_irq - request irq
1591 * @ioc: per adapter object
1592 * @index: msix index into vector table
1593 * @vector: irq vector
1595 * Inserting respective reply_queue into the list.
1598 _base_request_irq(struct MPT3SAS_ADAPTER
*ioc
, u8 index
, u32 vector
)
1600 struct adapter_reply_queue
*reply_q
;
1603 reply_q
= kzalloc(sizeof(struct adapter_reply_queue
), GFP_KERNEL
);
1605 pr_err(MPT3SAS_FMT
"unable to allocate memory %d!\n",
1606 ioc
->name
, (int)sizeof(struct adapter_reply_queue
));
1610 reply_q
->msix_index
= index
;
1611 reply_q
->vector
= vector
;
1612 atomic_set(&reply_q
->busy
, 0);
1613 if (ioc
->msix_enable
)
1614 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d-msix%d",
1615 MPT3SAS_DRIVER_NAME
, ioc
->id
, index
);
1617 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d",
1618 MPT3SAS_DRIVER_NAME
, ioc
->id
);
1619 r
= request_irq(vector
, _base_interrupt
, IRQF_SHARED
, reply_q
->name
,
1622 pr_err(MPT3SAS_FMT
"unable to allocate interrupt %d!\n",
1623 reply_q
->name
, vector
);
1628 INIT_LIST_HEAD(&reply_q
->list
);
1629 list_add_tail(&reply_q
->list
, &ioc
->reply_queue_list
);
1634 * _base_assign_reply_queues - assigning msix index for each cpu
1635 * @ioc: per adapter object
1637 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1639 * It would nice if we could call irq_set_affinity, however it is not
1640 * an exported symbol
1643 _base_assign_reply_queues(struct MPT3SAS_ADAPTER
*ioc
)
1645 unsigned int cpu
, nr_cpus
, nr_msix
, index
= 0;
1647 if (!_base_is_controller_msix_enabled(ioc
))
1650 memset(ioc
->cpu_msix_table
, 0, ioc
->cpu_msix_table_sz
);
1652 nr_cpus
= num_online_cpus();
1653 nr_msix
= ioc
->reply_queue_count
= min(ioc
->reply_queue_count
,
1654 ioc
->facts
.MaxMSIxVectors
);
1658 cpu
= cpumask_first(cpu_online_mask
);
1661 unsigned int i
, group
= nr_cpus
/ nr_msix
;
1663 if (index
< nr_cpus
% nr_msix
)
1666 for (i
= 0 ; i
< group
; i
++) {
1667 ioc
->cpu_msix_table
[cpu
] = index
;
1668 cpu
= cpumask_next(cpu
, cpu_online_mask
);
1673 } while (cpu
< nr_cpus
);
1677 * _base_disable_msix - disables msix
1678 * @ioc: per adapter object
1682 _base_disable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1684 if (!ioc
->msix_enable
)
1686 pci_disable_msix(ioc
->pdev
);
1687 ioc
->msix_enable
= 0;
1691 * _base_enable_msix - enables msix, failback to io_apic
1692 * @ioc: per adapter object
1696 _base_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1698 struct msix_entry
*entries
, *a
;
1703 if (msix_disable
== -1 || msix_disable
== 0)
1709 if (_base_check_enable_msix(ioc
) != 0)
1712 ioc
->reply_queue_count
= min_t(int, ioc
->cpu_count
,
1713 ioc
->msix_vector_count
);
1715 printk(MPT3SAS_FMT
"MSI-X vectors supported: %d, no of cores"
1716 ": %d, max_msix_vectors: %d\n", ioc
->name
, ioc
->msix_vector_count
,
1717 ioc
->cpu_count
, max_msix_vectors
);
1719 if (!ioc
->rdpq_array_enable
&& max_msix_vectors
== -1)
1720 max_msix_vectors
= 8;
1722 if (max_msix_vectors
> 0) {
1723 ioc
->reply_queue_count
= min_t(int, max_msix_vectors
,
1724 ioc
->reply_queue_count
);
1725 ioc
->msix_vector_count
= ioc
->reply_queue_count
;
1726 } else if (max_msix_vectors
== 0)
1729 entries
= kcalloc(ioc
->reply_queue_count
, sizeof(struct msix_entry
),
1732 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
1733 "kcalloc failed @ at %s:%d/%s() !!!\n",
1734 ioc
->name
, __FILE__
, __LINE__
, __func__
));
1738 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++)
1741 r
= pci_enable_msix_exact(ioc
->pdev
, entries
, ioc
->reply_queue_count
);
1743 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
1744 "pci_enable_msix_exact failed (r=%d) !!!\n",
1750 ioc
->msix_enable
= 1;
1751 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++) {
1752 r
= _base_request_irq(ioc
, i
, a
->vector
);
1754 _base_free_irq(ioc
);
1755 _base_disable_msix(ioc
);
1764 /* failback to io_apic interrupt routing */
1767 ioc
->reply_queue_count
= 1;
1768 r
= _base_request_irq(ioc
, 0, ioc
->pdev
->irq
);
1774 * mpt3sas_base_map_resources - map in controller resources (io/irq/memap)
1775 * @ioc: per adapter object
1777 * Returns 0 for success, non-zero for failure.
1780 mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER
*ioc
)
1782 struct pci_dev
*pdev
= ioc
->pdev
;
1788 struct adapter_reply_queue
*reply_q
;
1790 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n",
1791 ioc
->name
, __func__
));
1793 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1794 if (pci_enable_device_mem(pdev
)) {
1795 pr_warn(MPT3SAS_FMT
"pci_enable_device_mem: failed\n",
1802 if (pci_request_selected_regions(pdev
, ioc
->bars
,
1803 MPT3SAS_DRIVER_NAME
)) {
1804 pr_warn(MPT3SAS_FMT
"pci_request_selected_regions: failed\n",
1811 /* AER (Advanced Error Reporting) hooks */
1812 pci_enable_pcie_error_reporting(pdev
);
1814 pci_set_master(pdev
);
1817 if (_base_config_dma_addressing(ioc
, pdev
) != 0) {
1818 pr_warn(MPT3SAS_FMT
"no suitable DMA mask for %s\n",
1819 ioc
->name
, pci_name(pdev
));
1824 for (i
= 0, memap_sz
= 0, pio_sz
= 0 ; i
< DEVICE_COUNT_RESOURCE
; i
++) {
1825 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
1828 pio_chip
= (u64
)pci_resource_start(pdev
, i
);
1829 pio_sz
= pci_resource_len(pdev
, i
);
1830 } else if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
1833 ioc
->chip_phys
= pci_resource_start(pdev
, i
);
1834 chip_phys
= (u64
)ioc
->chip_phys
;
1835 memap_sz
= pci_resource_len(pdev
, i
);
1836 ioc
->chip
= ioremap(ioc
->chip_phys
, memap_sz
);
1837 if (ioc
->chip
== NULL
) {
1838 pr_err(MPT3SAS_FMT
"unable to map adapter memory!\n",
1846 _base_mask_interrupts(ioc
);
1848 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
1852 if (!ioc
->rdpq_array_enable_assigned
) {
1853 ioc
->rdpq_array_enable
= ioc
->rdpq_array_capable
;
1854 ioc
->rdpq_array_enable_assigned
= 1;
1857 r
= _base_enable_msix(ioc
);
1861 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
)
1862 pr_info(MPT3SAS_FMT
"%s: IRQ %d\n",
1863 reply_q
->name
, ((ioc
->msix_enable
) ? "PCI-MSI-X enabled" :
1864 "IO-APIC enabled"), reply_q
->vector
);
1866 pr_info(MPT3SAS_FMT
"iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1867 ioc
->name
, (unsigned long long)chip_phys
, ioc
->chip
, memap_sz
);
1868 pr_info(MPT3SAS_FMT
"ioport(0x%016llx), size(%d)\n",
1869 ioc
->name
, (unsigned long long)pio_chip
, pio_sz
);
1871 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1872 pci_save_state(pdev
);
1879 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
1880 pci_disable_pcie_error_reporting(pdev
);
1881 pci_disable_device(pdev
);
1886 * mpt3sas_base_get_msg_frame - obtain request mf pointer
1887 * @ioc: per adapter object
1888 * @smid: system request message index(smid zero is invalid)
1890 * Returns virt pointer to message frame.
1893 mpt3sas_base_get_msg_frame(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1895 return (void *)(ioc
->request
+ (smid
* ioc
->request_sz
));
1899 * mpt3sas_base_get_sense_buffer - obtain a sense buffer virt addr
1900 * @ioc: per adapter object
1901 * @smid: system request message index
1903 * Returns virt pointer to sense buffer.
1906 mpt3sas_base_get_sense_buffer(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1908 return (void *)(ioc
->sense
+ ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1912 * mpt3sas_base_get_sense_buffer_dma - obtain a sense buffer dma addr
1913 * @ioc: per adapter object
1914 * @smid: system request message index
1916 * Returns phys pointer to the low 32bit address of the sense buffer.
1919 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1921 return cpu_to_le32(ioc
->sense_dma
+ ((smid
- 1) *
1922 SCSI_SENSE_BUFFERSIZE
));
1926 * mpt3sas_base_get_reply_virt_addr - obtain reply frames virt address
1927 * @ioc: per adapter object
1928 * @phys_addr: lower 32 physical addr of the reply
1930 * Converts 32bit lower physical addr into a virt address.
1933 mpt3sas_base_get_reply_virt_addr(struct MPT3SAS_ADAPTER
*ioc
, u32 phys_addr
)
1937 return ioc
->reply
+ (phys_addr
- (u32
)ioc
->reply_dma
);
1941 * mpt3sas_base_get_smid - obtain a free smid from internal queue
1942 * @ioc: per adapter object
1943 * @cb_idx: callback index
1945 * Returns smid (zero is invalid)
1948 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
1950 unsigned long flags
;
1951 struct request_tracker
*request
;
1954 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1955 if (list_empty(&ioc
->internal_free_list
)) {
1956 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1957 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
1958 ioc
->name
, __func__
);
1962 request
= list_entry(ioc
->internal_free_list
.next
,
1963 struct request_tracker
, tracker_list
);
1964 request
->cb_idx
= cb_idx
;
1965 smid
= request
->smid
;
1966 list_del(&request
->tracker_list
);
1967 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1972 * mpt3sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1973 * @ioc: per adapter object
1974 * @cb_idx: callback index
1975 * @scmd: pointer to scsi command object
1977 * Returns smid (zero is invalid)
1980 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
,
1981 struct scsi_cmnd
*scmd
)
1983 unsigned long flags
;
1984 struct scsiio_tracker
*request
;
1987 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1988 if (list_empty(&ioc
->free_list
)) {
1989 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1990 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
1991 ioc
->name
, __func__
);
1995 request
= list_entry(ioc
->free_list
.next
,
1996 struct scsiio_tracker
, tracker_list
);
1997 request
->scmd
= scmd
;
1998 request
->cb_idx
= cb_idx
;
1999 smid
= request
->smid
;
2000 list_del(&request
->tracker_list
);
2001 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2006 * mpt3sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
2007 * @ioc: per adapter object
2008 * @cb_idx: callback index
2010 * Returns smid (zero is invalid)
2013 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
2015 unsigned long flags
;
2016 struct request_tracker
*request
;
2019 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2020 if (list_empty(&ioc
->hpr_free_list
)) {
2021 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2025 request
= list_entry(ioc
->hpr_free_list
.next
,
2026 struct request_tracker
, tracker_list
);
2027 request
->cb_idx
= cb_idx
;
2028 smid
= request
->smid
;
2029 list_del(&request
->tracker_list
);
2030 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2035 * mpt3sas_base_free_smid - put smid back on free_list
2036 * @ioc: per adapter object
2037 * @smid: system request message index
2042 mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2044 unsigned long flags
;
2046 struct chain_tracker
*chain_req
, *next
;
2048 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2049 if (smid
< ioc
->hi_priority_smid
) {
2052 if (!list_empty(&ioc
->scsi_lookup
[i
].chain_list
)) {
2053 list_for_each_entry_safe(chain_req
, next
,
2054 &ioc
->scsi_lookup
[i
].chain_list
, tracker_list
) {
2055 list_del_init(&chain_req
->tracker_list
);
2056 list_add(&chain_req
->tracker_list
,
2057 &ioc
->free_chain_list
);
2060 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
2061 ioc
->scsi_lookup
[i
].scmd
= NULL
;
2062 list_add(&ioc
->scsi_lookup
[i
].tracker_list
, &ioc
->free_list
);
2063 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2066 * See _wait_for_commands_to_complete() call with regards
2069 if (ioc
->shost_recovery
&& ioc
->pending_io_count
) {
2070 if (ioc
->pending_io_count
== 1)
2071 wake_up(&ioc
->reset_wq
);
2072 ioc
->pending_io_count
--;
2075 } else if (smid
< ioc
->internal_smid
) {
2077 i
= smid
- ioc
->hi_priority_smid
;
2078 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
2079 list_add(&ioc
->hpr_lookup
[i
].tracker_list
, &ioc
->hpr_free_list
);
2080 } else if (smid
<= ioc
->hba_queue_depth
) {
2081 /* internal queue */
2082 i
= smid
- ioc
->internal_smid
;
2083 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
2084 list_add(&ioc
->internal_lookup
[i
].tracker_list
,
2085 &ioc
->internal_free_list
);
2087 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2091 * _base_writeq - 64 bit write to MMIO
2092 * @ioc: per adapter object
2094 * @addr: address in MMIO space
2095 * @writeq_lock: spin lock
2097 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
2098 * care of 32 bit environment where its not quarenteed to send the entire word
2101 #if defined(writeq) && defined(CONFIG_64BIT)
2103 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2105 writeq(cpu_to_le64(b
), addr
);
2109 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2111 unsigned long flags
;
2112 __u64 data_out
= cpu_to_le64(b
);
2114 spin_lock_irqsave(writeq_lock
, flags
);
2115 writel((u32
)(data_out
), addr
);
2116 writel((u32
)(data_out
>> 32), (addr
+ 4));
2117 spin_unlock_irqrestore(writeq_lock
, flags
);
2122 _base_get_msix_index(struct MPT3SAS_ADAPTER
*ioc
)
2124 return ioc
->cpu_msix_table
[raw_smp_processor_id()];
2128 * mpt3sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
2129 * @ioc: per adapter object
2130 * @smid: system request message index
2131 * @handle: device handle
2136 mpt3sas_base_put_smid_scsi_io(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 handle
)
2138 Mpi2RequestDescriptorUnion_t descriptor
;
2139 u64
*request
= (u64
*)&descriptor
;
2142 descriptor
.SCSIIO
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
2143 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
2144 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
2145 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
2146 descriptor
.SCSIIO
.LMID
= 0;
2147 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2148 &ioc
->scsi_lookup_lock
);
2152 * mpt3sas_base_put_smid_fast_path - send fast path request to firmware
2153 * @ioc: per adapter object
2154 * @smid: system request message index
2155 * @handle: device handle
2160 mpt3sas_base_put_smid_fast_path(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
2163 Mpi2RequestDescriptorUnion_t descriptor
;
2164 u64
*request
= (u64
*)&descriptor
;
2166 descriptor
.SCSIIO
.RequestFlags
=
2167 MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO
;
2168 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
2169 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
2170 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
2171 descriptor
.SCSIIO
.LMID
= 0;
2172 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2173 &ioc
->scsi_lookup_lock
);
2177 * mpt3sas_base_put_smid_hi_priority - send Task Managment request to firmware
2178 * @ioc: per adapter object
2179 * @smid: system request message index
2184 mpt3sas_base_put_smid_hi_priority(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2186 Mpi2RequestDescriptorUnion_t descriptor
;
2187 u64
*request
= (u64
*)&descriptor
;
2189 descriptor
.HighPriority
.RequestFlags
=
2190 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
2191 descriptor
.HighPriority
.MSIxIndex
= 0;
2192 descriptor
.HighPriority
.SMID
= cpu_to_le16(smid
);
2193 descriptor
.HighPriority
.LMID
= 0;
2194 descriptor
.HighPriority
.Reserved1
= 0;
2195 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2196 &ioc
->scsi_lookup_lock
);
2200 * mpt3sas_base_put_smid_default - Default, primarily used for config pages
2201 * @ioc: per adapter object
2202 * @smid: system request message index
2207 mpt3sas_base_put_smid_default(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2209 Mpi2RequestDescriptorUnion_t descriptor
;
2210 u64
*request
= (u64
*)&descriptor
;
2212 descriptor
.Default
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
2213 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
2214 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
2215 descriptor
.Default
.LMID
= 0;
2216 descriptor
.Default
.DescriptorTypeDependent
= 0;
2217 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2218 &ioc
->scsi_lookup_lock
);
2222 * _base_display_intel_branding - Display branding string
2223 * @ioc: per adapter object
2228 _base_display_intel_branding(struct MPT3SAS_ADAPTER
*ioc
)
2230 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
2233 switch (ioc
->pdev
->device
) {
2234 case MPI25_MFGPAGE_DEVID_SAS3008
:
2235 switch (ioc
->pdev
->subsystem_device
) {
2236 case MPT3SAS_INTEL_RMS3JC080_SSDID
:
2237 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2238 MPT3SAS_INTEL_RMS3JC080_BRANDING
);
2241 case MPT3SAS_INTEL_RS3GC008_SSDID
:
2242 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2243 MPT3SAS_INTEL_RS3GC008_BRANDING
);
2245 case MPT3SAS_INTEL_RS3FC044_SSDID
:
2246 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2247 MPT3SAS_INTEL_RS3FC044_BRANDING
);
2249 case MPT3SAS_INTEL_RS3UC080_SSDID
:
2250 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2251 MPT3SAS_INTEL_RS3UC080_BRANDING
);
2255 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2256 ioc
->name
, ioc
->pdev
->subsystem_device
);
2262 "Intel(R) Controller: Subsystem ID: 0x%X\n",
2263 ioc
->name
, ioc
->pdev
->subsystem_device
);
2271 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2272 * @ioc: per adapter object
2277 _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER
*ioc
)
2281 u32 iounit_pg1_flags
;
2284 bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2285 strncpy(desc
, ioc
->manu_pg0
.ChipName
, 16);
2286 pr_info(MPT3SAS_FMT
"%s: FWVersion(%02d.%02d.%02d.%02d), "\
2287 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2289 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2290 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2291 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2292 ioc
->facts
.FWVersion
.Word
& 0x000000FF,
2293 ioc
->pdev
->revision
,
2294 (bios_version
& 0xFF000000) >> 24,
2295 (bios_version
& 0x00FF0000) >> 16,
2296 (bios_version
& 0x0000FF00) >> 8,
2297 bios_version
& 0x000000FF);
2299 _base_display_intel_branding(ioc
);
2301 pr_info(MPT3SAS_FMT
"Protocol=(", ioc
->name
);
2303 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
) {
2304 pr_info("Initiator");
2308 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET
) {
2309 pr_info("%sTarget", i
? "," : "");
2315 pr_info("Capabilities=(");
2317 if (ioc
->facts
.IOCCapabilities
&
2318 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
) {
2323 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
) {
2324 pr_info("%sTLR", i
? "," : "");
2328 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_MULTICAST
) {
2329 pr_info("%sMulticast", i
? "," : "");
2333 if (ioc
->facts
.IOCCapabilities
&
2334 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET
) {
2335 pr_info("%sBIDI Target", i
? "," : "");
2339 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_EEDP
) {
2340 pr_info("%sEEDP", i
? "," : "");
2344 if (ioc
->facts
.IOCCapabilities
&
2345 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
) {
2346 pr_info("%sSnapshot Buffer", i
? "," : "");
2350 if (ioc
->facts
.IOCCapabilities
&
2351 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
) {
2352 pr_info("%sDiag Trace Buffer", i
? "," : "");
2356 if (ioc
->facts
.IOCCapabilities
&
2357 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
) {
2358 pr_info("%sDiag Extended Buffer", i
? "," : "");
2362 if (ioc
->facts
.IOCCapabilities
&
2363 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
) {
2364 pr_info("%sTask Set Full", i
? "," : "");
2368 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2369 if (!(iounit_pg1_flags
& MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE
)) {
2370 pr_info("%sNCQ", i
? "," : "");
2378 * mpt3sas_base_update_missing_delay - change the missing delay timers
2379 * @ioc: per adapter object
2380 * @device_missing_delay: amount of time till device is reported missing
2381 * @io_missing_delay: interval IO is returned when there is a missing device
2385 * Passed on the command line, this function will modify the device missing
2386 * delay, as well as the io missing delay. This should be called at driver
2390 mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER
*ioc
,
2391 u16 device_missing_delay
, u8 io_missing_delay
)
2393 u16 dmd
, dmd_new
, dmd_orignal
;
2394 u8 io_missing_delay_original
;
2396 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
2397 Mpi2ConfigReply_t mpi_reply
;
2401 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
2405 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (num_phys
*
2406 sizeof(Mpi2SasIOUnit1PhyData_t
));
2407 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
2408 if (!sas_iounit_pg1
) {
2409 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2410 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2413 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
2414 sas_iounit_pg1
, sz
))) {
2415 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2416 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2419 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
2420 MPI2_IOCSTATUS_MASK
;
2421 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2422 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2423 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2427 /* device missing delay */
2428 dmd
= sas_iounit_pg1
->ReportDeviceMissingDelay
;
2429 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2430 dmd
= (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2432 dmd
= dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2434 if (device_missing_delay
> 0x7F) {
2435 dmd
= (device_missing_delay
> 0x7F0) ? 0x7F0 :
2436 device_missing_delay
;
2438 dmd
|= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
;
2440 dmd
= device_missing_delay
;
2441 sas_iounit_pg1
->ReportDeviceMissingDelay
= dmd
;
2443 /* io missing delay */
2444 io_missing_delay_original
= sas_iounit_pg1
->IODeviceMissingDelay
;
2445 sas_iounit_pg1
->IODeviceMissingDelay
= io_missing_delay
;
2447 if (!mpt3sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
2449 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2451 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2454 dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2455 pr_info(MPT3SAS_FMT
"device_missing_delay: old(%d), new(%d)\n",
2456 ioc
->name
, dmd_orignal
, dmd_new
);
2457 pr_info(MPT3SAS_FMT
"ioc_missing_delay: old(%d), new(%d)\n",
2458 ioc
->name
, io_missing_delay_original
,
2460 ioc
->device_missing_delay
= dmd_new
;
2461 ioc
->io_missing_delay
= io_missing_delay
;
2465 kfree(sas_iounit_pg1
);
2468 * _base_static_config_pages - static start of day config pages
2469 * @ioc: per adapter object
2474 _base_static_config_pages(struct MPT3SAS_ADAPTER
*ioc
)
2476 Mpi2ConfigReply_t mpi_reply
;
2477 u32 iounit_pg1_flags
;
2479 mpt3sas_config_get_manufacturing_pg0(ioc
, &mpi_reply
, &ioc
->manu_pg0
);
2480 if (ioc
->ir_firmware
)
2481 mpt3sas_config_get_manufacturing_pg10(ioc
, &mpi_reply
,
2485 * Ensure correct T10 PI operation if vendor left EEDPTagMode
2486 * flag unset in NVDATA.
2488 mpt3sas_config_get_manufacturing_pg11(ioc
, &mpi_reply
, &ioc
->manu_pg11
);
2489 if (ioc
->manu_pg11
.EEDPTagMode
== 0) {
2490 pr_err("%s: overriding NVDATA EEDPTagMode setting\n",
2492 ioc
->manu_pg11
.EEDPTagMode
&= ~0x3;
2493 ioc
->manu_pg11
.EEDPTagMode
|= 0x1;
2494 mpt3sas_config_set_manufacturing_pg11(ioc
, &mpi_reply
,
2498 mpt3sas_config_get_bios_pg2(ioc
, &mpi_reply
, &ioc
->bios_pg2
);
2499 mpt3sas_config_get_bios_pg3(ioc
, &mpi_reply
, &ioc
->bios_pg3
);
2500 mpt3sas_config_get_ioc_pg8(ioc
, &mpi_reply
, &ioc
->ioc_pg8
);
2501 mpt3sas_config_get_iounit_pg0(ioc
, &mpi_reply
, &ioc
->iounit_pg0
);
2502 mpt3sas_config_get_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2503 _base_display_ioc_capabilities(ioc
);
2506 * Enable task_set_full handling in iounit_pg1 when the
2507 * facts capabilities indicate that its supported.
2509 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2510 if ((ioc
->facts
.IOCCapabilities
&
2511 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
))
2513 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2516 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2517 ioc
->iounit_pg1
.Flags
= cpu_to_le32(iounit_pg1_flags
);
2518 mpt3sas_config_set_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2522 * _base_release_memory_pools - release memory
2523 * @ioc: per adapter object
2525 * Free memory allocated from _base_allocate_memory_pools.
2530 _base_release_memory_pools(struct MPT3SAS_ADAPTER
*ioc
)
2533 struct reply_post_struct
*rps
;
2535 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2539 pci_free_consistent(ioc
->pdev
, ioc
->request_dma_sz
,
2540 ioc
->request
, ioc
->request_dma
);
2541 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2542 "request_pool(0x%p): free\n",
2543 ioc
->name
, ioc
->request
));
2544 ioc
->request
= NULL
;
2548 pci_pool_free(ioc
->sense_dma_pool
, ioc
->sense
, ioc
->sense_dma
);
2549 if (ioc
->sense_dma_pool
)
2550 pci_pool_destroy(ioc
->sense_dma_pool
);
2551 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2552 "sense_pool(0x%p): free\n",
2553 ioc
->name
, ioc
->sense
));
2558 pci_pool_free(ioc
->reply_dma_pool
, ioc
->reply
, ioc
->reply_dma
);
2559 if (ioc
->reply_dma_pool
)
2560 pci_pool_destroy(ioc
->reply_dma_pool
);
2561 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2562 "reply_pool(0x%p): free\n",
2563 ioc
->name
, ioc
->reply
));
2567 if (ioc
->reply_free
) {
2568 pci_pool_free(ioc
->reply_free_dma_pool
, ioc
->reply_free
,
2569 ioc
->reply_free_dma
);
2570 if (ioc
->reply_free_dma_pool
)
2571 pci_pool_destroy(ioc
->reply_free_dma_pool
);
2572 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2573 "reply_free_pool(0x%p): free\n",
2574 ioc
->name
, ioc
->reply_free
));
2575 ioc
->reply_free
= NULL
;
2578 if (ioc
->reply_post
) {
2580 rps
= &ioc
->reply_post
[i
];
2581 if (rps
->reply_post_free
) {
2583 ioc
->reply_post_free_dma_pool
,
2584 rps
->reply_post_free
,
2585 rps
->reply_post_free_dma
);
2586 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2587 "reply_post_free_pool(0x%p): free\n",
2588 ioc
->name
, rps
->reply_post_free
));
2589 rps
->reply_post_free
= NULL
;
2591 } while (ioc
->rdpq_array_enable
&&
2592 (++i
< ioc
->reply_queue_count
));
2594 if (ioc
->reply_post_free_dma_pool
)
2595 pci_pool_destroy(ioc
->reply_post_free_dma_pool
);
2596 kfree(ioc
->reply_post
);
2599 if (ioc
->config_page
) {
2600 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2601 "config_page(0x%p): free\n", ioc
->name
,
2603 pci_free_consistent(ioc
->pdev
, ioc
->config_page_sz
,
2604 ioc
->config_page
, ioc
->config_page_dma
);
2607 if (ioc
->scsi_lookup
) {
2608 free_pages((ulong
)ioc
->scsi_lookup
, ioc
->scsi_lookup_pages
);
2609 ioc
->scsi_lookup
= NULL
;
2611 kfree(ioc
->hpr_lookup
);
2612 kfree(ioc
->internal_lookup
);
2613 if (ioc
->chain_lookup
) {
2614 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2615 if (ioc
->chain_lookup
[i
].chain_buffer
)
2616 pci_pool_free(ioc
->chain_dma_pool
,
2617 ioc
->chain_lookup
[i
].chain_buffer
,
2618 ioc
->chain_lookup
[i
].chain_buffer_dma
);
2620 if (ioc
->chain_dma_pool
)
2621 pci_pool_destroy(ioc
->chain_dma_pool
);
2622 free_pages((ulong
)ioc
->chain_lookup
, ioc
->chain_pages
);
2623 ioc
->chain_lookup
= NULL
;
2628 * _base_allocate_memory_pools - allocate start of day memory pools
2629 * @ioc: per adapter object
2630 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2632 * Returns 0 success, anything else error
2635 _base_allocate_memory_pools(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
2637 struct mpt3sas_facts
*facts
;
2638 u16 max_sge_elements
;
2639 u16 chains_needed_per_io
;
2640 u32 sz
, total_sz
, reply_post_free_sz
;
2642 u16 max_request_credit
;
2643 unsigned short sg_tablesize
;
2647 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2652 facts
= &ioc
->facts
;
2654 /* command line tunables for max sgl entries */
2655 if (max_sgl_entries
!= -1)
2656 sg_tablesize
= max_sgl_entries
;
2658 sg_tablesize
= MPT3SAS_SG_DEPTH
;
2660 if (sg_tablesize
< MPT3SAS_MIN_PHYS_SEGMENTS
)
2661 sg_tablesize
= MPT3SAS_MIN_PHYS_SEGMENTS
;
2662 else if (sg_tablesize
> MPT3SAS_MAX_PHYS_SEGMENTS
)
2663 sg_tablesize
= MPT3SAS_MAX_PHYS_SEGMENTS
;
2664 ioc
->shost
->sg_tablesize
= sg_tablesize
;
2666 ioc
->hi_priority_depth
= facts
->HighPriorityCredit
;
2667 ioc
->internal_depth
= ioc
->hi_priority_depth
+ (5);
2668 /* command line tunables for max controller queue depth */
2669 if (max_queue_depth
!= -1 && max_queue_depth
!= 0) {
2670 max_request_credit
= min_t(u16
, max_queue_depth
+
2671 ioc
->hi_priority_depth
+ ioc
->internal_depth
,
2672 facts
->RequestCredit
);
2673 if (max_request_credit
> MAX_HBA_QUEUE_DEPTH
)
2674 max_request_credit
= MAX_HBA_QUEUE_DEPTH
;
2676 max_request_credit
= min_t(u16
, facts
->RequestCredit
,
2677 MAX_HBA_QUEUE_DEPTH
);
2679 ioc
->hba_queue_depth
= max_request_credit
;
2681 /* request frame size */
2682 ioc
->request_sz
= facts
->IOCRequestFrameSize
* 4;
2684 /* reply frame size */
2685 ioc
->reply_sz
= facts
->ReplyFrameSize
* 4;
2687 /* calculate the max scatter element size */
2688 sge_size
= max_t(u16
, ioc
->sge_size
, ioc
->sge_size_ieee
);
2692 /* calculate number of sg elements left over in the 1st frame */
2693 max_sge_elements
= ioc
->request_sz
- ((sizeof(Mpi2SCSIIORequest_t
) -
2694 sizeof(Mpi2SGEIOUnion_t
)) + sge_size
);
2695 ioc
->max_sges_in_main_message
= max_sge_elements
/sge_size
;
2697 /* now do the same for a chain buffer */
2698 max_sge_elements
= ioc
->request_sz
- sge_size
;
2699 ioc
->max_sges_in_chain_message
= max_sge_elements
/sge_size
;
2702 * MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2704 chains_needed_per_io
= ((ioc
->shost
->sg_tablesize
-
2705 ioc
->max_sges_in_main_message
)/ioc
->max_sges_in_chain_message
)
2707 if (chains_needed_per_io
> facts
->MaxChainDepth
) {
2708 chains_needed_per_io
= facts
->MaxChainDepth
;
2709 ioc
->shost
->sg_tablesize
= min_t(u16
,
2710 ioc
->max_sges_in_main_message
+ (ioc
->max_sges_in_chain_message
2711 * chains_needed_per_io
), ioc
->shost
->sg_tablesize
);
2713 ioc
->chains_needed_per_io
= chains_needed_per_io
;
2715 /* reply free queue sizing - taking into account for 64 FW events */
2716 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
2718 /* calculate reply descriptor post queue depth */
2719 ioc
->reply_post_queue_depth
= ioc
->hba_queue_depth
+
2720 ioc
->reply_free_queue_depth
+ 1 ;
2721 /* align the reply post queue on the next 16 count boundary */
2722 if (ioc
->reply_post_queue_depth
% 16)
2723 ioc
->reply_post_queue_depth
+= 16 -
2724 (ioc
->reply_post_queue_depth
% 16);
2727 if (ioc
->reply_post_queue_depth
>
2728 facts
->MaxReplyDescriptorPostQueueDepth
) {
2729 ioc
->reply_post_queue_depth
=
2730 facts
->MaxReplyDescriptorPostQueueDepth
-
2731 (facts
->MaxReplyDescriptorPostQueueDepth
% 16);
2732 ioc
->hba_queue_depth
=
2733 ((ioc
->reply_post_queue_depth
- 64) / 2) - 1;
2734 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
2737 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scatter gather: " \
2738 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2739 "chains_per_io(%d)\n", ioc
->name
, ioc
->max_sges_in_main_message
,
2740 ioc
->max_sges_in_chain_message
, ioc
->shost
->sg_tablesize
,
2741 ioc
->chains_needed_per_io
));
2743 /* reply post queue, 16 byte align */
2744 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
2745 sizeof(Mpi2DefaultReplyDescriptor_t
);
2747 sz
= reply_post_free_sz
;
2748 if (_base_is_controller_msix_enabled(ioc
) && !ioc
->rdpq_array_enable
)
2749 sz
*= ioc
->reply_queue_count
;
2751 ioc
->reply_post
= kcalloc((ioc
->rdpq_array_enable
) ?
2752 (ioc
->reply_queue_count
):1,
2753 sizeof(struct reply_post_struct
), GFP_KERNEL
);
2755 if (!ioc
->reply_post
) {
2756 pr_err(MPT3SAS_FMT
"reply_post_free pool: kcalloc failed\n",
2760 ioc
->reply_post_free_dma_pool
= pci_pool_create("reply_post_free pool",
2761 ioc
->pdev
, sz
, 16, 0);
2762 if (!ioc
->reply_post_free_dma_pool
) {
2764 "reply_post_free pool: pci_pool_create failed\n",
2770 ioc
->reply_post
[i
].reply_post_free
=
2771 pci_pool_alloc(ioc
->reply_post_free_dma_pool
,
2773 &ioc
->reply_post
[i
].reply_post_free_dma
);
2774 if (!ioc
->reply_post
[i
].reply_post_free
) {
2776 "reply_post_free pool: pci_pool_alloc failed\n",
2780 memset(ioc
->reply_post
[i
].reply_post_free
, 0, sz
);
2781 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2782 "reply post free pool (0x%p): depth(%d),"
2783 "element_size(%d), pool_size(%d kB)\n", ioc
->name
,
2784 ioc
->reply_post
[i
].reply_post_free
,
2785 ioc
->reply_post_queue_depth
, 8, sz
/1024));
2786 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2787 "reply_post_free_dma = (0x%llx)\n", ioc
->name
,
2788 (unsigned long long)
2789 ioc
->reply_post
[i
].reply_post_free_dma
));
2791 } while (ioc
->rdpq_array_enable
&& (++i
< ioc
->reply_queue_count
));
2793 if (ioc
->dma_mask
== 64) {
2794 if (_base_change_consistent_dma_mask(ioc
, ioc
->pdev
) != 0) {
2796 "no suitable consistent DMA mask for %s\n",
2797 ioc
->name
, pci_name(ioc
->pdev
));
2802 ioc
->scsiio_depth
= ioc
->hba_queue_depth
-
2803 ioc
->hi_priority_depth
- ioc
->internal_depth
;
2805 /* set the scsi host can_queue depth
2806 * with some internal commands that could be outstanding
2808 ioc
->shost
->can_queue
= ioc
->scsiio_depth
;
2809 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2810 "scsi host: can_queue depth (%d)\n",
2811 ioc
->name
, ioc
->shost
->can_queue
));
2814 /* contiguous pool for request and chains, 16 byte align, one extra "
2817 ioc
->chain_depth
= ioc
->chains_needed_per_io
* ioc
->scsiio_depth
;
2818 sz
= ((ioc
->scsiio_depth
+ 1) * ioc
->request_sz
);
2820 /* hi-priority queue */
2821 sz
+= (ioc
->hi_priority_depth
* ioc
->request_sz
);
2823 /* internal queue */
2824 sz
+= (ioc
->internal_depth
* ioc
->request_sz
);
2826 ioc
->request_dma_sz
= sz
;
2827 ioc
->request
= pci_alloc_consistent(ioc
->pdev
, sz
, &ioc
->request_dma
);
2828 if (!ioc
->request
) {
2829 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
2830 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2831 "total(%d kB)\n", ioc
->name
, ioc
->hba_queue_depth
,
2832 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2833 if (ioc
->scsiio_depth
< MPT3SAS_SAS_QUEUE_DEPTH
)
2836 ioc
->hba_queue_depth
= max_request_credit
- retry_sz
;
2837 goto retry_allocation
;
2841 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
2842 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2843 "total(%d kb)\n", ioc
->name
, ioc
->hba_queue_depth
,
2844 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2846 /* hi-priority queue */
2847 ioc
->hi_priority
= ioc
->request
+ ((ioc
->scsiio_depth
+ 1) *
2849 ioc
->hi_priority_dma
= ioc
->request_dma
+ ((ioc
->scsiio_depth
+ 1) *
2852 /* internal queue */
2853 ioc
->internal
= ioc
->hi_priority
+ (ioc
->hi_priority_depth
*
2855 ioc
->internal_dma
= ioc
->hi_priority_dma
+ (ioc
->hi_priority_depth
*
2858 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2859 "request pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
2860 ioc
->name
, ioc
->request
, ioc
->hba_queue_depth
, ioc
->request_sz
,
2861 (ioc
->hba_queue_depth
* ioc
->request_sz
)/1024));
2863 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"request pool: dma(0x%llx)\n",
2864 ioc
->name
, (unsigned long long) ioc
->request_dma
));
2867 sz
= ioc
->scsiio_depth
* sizeof(struct scsiio_tracker
);
2868 ioc
->scsi_lookup_pages
= get_order(sz
);
2869 ioc
->scsi_lookup
= (struct scsiio_tracker
*)__get_free_pages(
2870 GFP_KERNEL
, ioc
->scsi_lookup_pages
);
2871 if (!ioc
->scsi_lookup
) {
2872 pr_err(MPT3SAS_FMT
"scsi_lookup: get_free_pages failed, sz(%d)\n",
2873 ioc
->name
, (int)sz
);
2877 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scsiio(0x%p): depth(%d)\n",
2878 ioc
->name
, ioc
->request
, ioc
->scsiio_depth
));
2880 ioc
->chain_depth
= min_t(u32
, ioc
->chain_depth
, MAX_CHAIN_DEPTH
);
2881 sz
= ioc
->chain_depth
* sizeof(struct chain_tracker
);
2882 ioc
->chain_pages
= get_order(sz
);
2883 ioc
->chain_lookup
= (struct chain_tracker
*)__get_free_pages(
2884 GFP_KERNEL
, ioc
->chain_pages
);
2885 if (!ioc
->chain_lookup
) {
2886 pr_err(MPT3SAS_FMT
"chain_lookup: __get_free_pages failed\n",
2890 ioc
->chain_dma_pool
= pci_pool_create("chain pool", ioc
->pdev
,
2891 ioc
->request_sz
, 16, 0);
2892 if (!ioc
->chain_dma_pool
) {
2893 pr_err(MPT3SAS_FMT
"chain_dma_pool: pci_pool_create failed\n",
2897 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2898 ioc
->chain_lookup
[i
].chain_buffer
= pci_pool_alloc(
2899 ioc
->chain_dma_pool
, GFP_KERNEL
,
2900 &ioc
->chain_lookup
[i
].chain_buffer_dma
);
2901 if (!ioc
->chain_lookup
[i
].chain_buffer
) {
2902 ioc
->chain_depth
= i
;
2905 total_sz
+= ioc
->request_sz
;
2908 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2909 "chain pool depth(%d), frame_size(%d), pool_size(%d kB)\n",
2910 ioc
->name
, ioc
->chain_depth
, ioc
->request_sz
,
2911 ((ioc
->chain_depth
* ioc
->request_sz
))/1024));
2913 /* initialize hi-priority queue smid's */
2914 ioc
->hpr_lookup
= kcalloc(ioc
->hi_priority_depth
,
2915 sizeof(struct request_tracker
), GFP_KERNEL
);
2916 if (!ioc
->hpr_lookup
) {
2917 pr_err(MPT3SAS_FMT
"hpr_lookup: kcalloc failed\n",
2921 ioc
->hi_priority_smid
= ioc
->scsiio_depth
+ 1;
2922 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2923 "hi_priority(0x%p): depth(%d), start smid(%d)\n",
2924 ioc
->name
, ioc
->hi_priority
,
2925 ioc
->hi_priority_depth
, ioc
->hi_priority_smid
));
2927 /* initialize internal queue smid's */
2928 ioc
->internal_lookup
= kcalloc(ioc
->internal_depth
,
2929 sizeof(struct request_tracker
), GFP_KERNEL
);
2930 if (!ioc
->internal_lookup
) {
2931 pr_err(MPT3SAS_FMT
"internal_lookup: kcalloc failed\n",
2935 ioc
->internal_smid
= ioc
->hi_priority_smid
+ ioc
->hi_priority_depth
;
2936 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2937 "internal(0x%p): depth(%d), start smid(%d)\n",
2938 ioc
->name
, ioc
->internal
,
2939 ioc
->internal_depth
, ioc
->internal_smid
));
2941 /* sense buffers, 4 byte align */
2942 sz
= ioc
->scsiio_depth
* SCSI_SENSE_BUFFERSIZE
;
2943 ioc
->sense_dma_pool
= pci_pool_create("sense pool", ioc
->pdev
, sz
, 4,
2945 if (!ioc
->sense_dma_pool
) {
2946 pr_err(MPT3SAS_FMT
"sense pool: pci_pool_create failed\n",
2950 ioc
->sense
= pci_pool_alloc(ioc
->sense_dma_pool
, GFP_KERNEL
,
2953 pr_err(MPT3SAS_FMT
"sense pool: pci_pool_alloc failed\n",
2957 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2958 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2959 "(%d kB)\n", ioc
->name
, ioc
->sense
, ioc
->scsiio_depth
,
2960 SCSI_SENSE_BUFFERSIZE
, sz
/1024));
2961 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"sense_dma(0x%llx)\n",
2962 ioc
->name
, (unsigned long long)ioc
->sense_dma
));
2965 /* reply pool, 4 byte align */
2966 sz
= ioc
->reply_free_queue_depth
* ioc
->reply_sz
;
2967 ioc
->reply_dma_pool
= pci_pool_create("reply pool", ioc
->pdev
, sz
, 4,
2969 if (!ioc
->reply_dma_pool
) {
2970 pr_err(MPT3SAS_FMT
"reply pool: pci_pool_create failed\n",
2974 ioc
->reply
= pci_pool_alloc(ioc
->reply_dma_pool
, GFP_KERNEL
,
2977 pr_err(MPT3SAS_FMT
"reply pool: pci_pool_alloc failed\n",
2981 ioc
->reply_dma_min_address
= (u32
)(ioc
->reply_dma
);
2982 ioc
->reply_dma_max_address
= (u32
)(ioc
->reply_dma
) + sz
;
2983 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2984 "reply pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
2985 ioc
->name
, ioc
->reply
,
2986 ioc
->reply_free_queue_depth
, ioc
->reply_sz
, sz
/1024));
2987 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_dma(0x%llx)\n",
2988 ioc
->name
, (unsigned long long)ioc
->reply_dma
));
2991 /* reply free queue, 16 byte align */
2992 sz
= ioc
->reply_free_queue_depth
* 4;
2993 ioc
->reply_free_dma_pool
= pci_pool_create("reply_free pool",
2994 ioc
->pdev
, sz
, 16, 0);
2995 if (!ioc
->reply_free_dma_pool
) {
2996 pr_err(MPT3SAS_FMT
"reply_free pool: pci_pool_create failed\n",
3000 ioc
->reply_free
= pci_pool_alloc(ioc
->reply_free_dma_pool
, GFP_KERNEL
,
3001 &ioc
->reply_free_dma
);
3002 if (!ioc
->reply_free
) {
3003 pr_err(MPT3SAS_FMT
"reply_free pool: pci_pool_alloc failed\n",
3007 memset(ioc
->reply_free
, 0, sz
);
3008 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_free pool(0x%p): " \
3009 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc
->name
,
3010 ioc
->reply_free
, ioc
->reply_free_queue_depth
, 4, sz
/1024));
3011 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3012 "reply_free_dma (0x%llx)\n",
3013 ioc
->name
, (unsigned long long)ioc
->reply_free_dma
));
3016 ioc
->config_page_sz
= 512;
3017 ioc
->config_page
= pci_alloc_consistent(ioc
->pdev
,
3018 ioc
->config_page_sz
, &ioc
->config_page_dma
);
3019 if (!ioc
->config_page
) {
3021 "config page: pci_pool_alloc failed\n",
3025 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3026 "config page(0x%p): size(%d)\n",
3027 ioc
->name
, ioc
->config_page
, ioc
->config_page_sz
));
3028 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"config_page_dma(0x%llx)\n",
3029 ioc
->name
, (unsigned long long)ioc
->config_page_dma
));
3030 total_sz
+= ioc
->config_page_sz
;
3032 pr_info(MPT3SAS_FMT
"Allocated physical memory: size(%d kB)\n",
3033 ioc
->name
, total_sz
/1024);
3035 "Current Controller Queue Depth(%d),Max Controller Queue Depth(%d)\n",
3036 ioc
->name
, ioc
->shost
->can_queue
, facts
->RequestCredit
);
3037 pr_info(MPT3SAS_FMT
"Scatter Gather Elements per IO(%d)\n",
3038 ioc
->name
, ioc
->shost
->sg_tablesize
);
3046 * mpt3sas_base_get_iocstate - Get the current state of a MPT adapter.
3047 * @ioc: Pointer to MPT_ADAPTER structure
3048 * @cooked: Request raw or cooked IOC state
3050 * Returns all IOC Doorbell register bits if cooked==0, else just the
3051 * Doorbell bits in MPI_IOC_STATE_MASK.
3054 mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER
*ioc
, int cooked
)
3058 s
= readl(&ioc
->chip
->Doorbell
);
3059 sc
= s
& MPI2_IOC_STATE_MASK
;
3060 return cooked
? sc
: s
;
3064 * _base_wait_on_iocstate - waiting on a particular ioc state
3065 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
3066 * @timeout: timeout in second
3067 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3069 * Returns 0 for success, non-zero for failure.
3072 _base_wait_on_iocstate(struct MPT3SAS_ADAPTER
*ioc
, u32 ioc_state
, int timeout
,
3079 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3081 current_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3082 if (current_state
== ioc_state
)
3084 if (count
&& current_state
== MPI2_IOC_STATE_FAULT
)
3086 if (sleep_flag
== CAN_SLEEP
)
3087 usleep_range(1000, 1500);
3093 return current_state
;
3097 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
3098 * a write to the doorbell)
3099 * @ioc: per adapter object
3100 * @timeout: timeout in second
3101 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3103 * Returns 0 for success, non-zero for failure.
3105 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
3108 _base_wait_for_doorbell_int(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3115 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3117 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
3118 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
3119 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3120 "%s: successful count(%d), timeout(%d)\n",
3121 ioc
->name
, __func__
, count
, timeout
));
3124 if (sleep_flag
== CAN_SLEEP
)
3125 usleep_range(1000, 1500);
3132 "%s: failed due to timeout count(%d), int_status(%x)!\n",
3133 ioc
->name
, __func__
, count
, int_status
);
3138 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
3139 * @ioc: per adapter object
3140 * @timeout: timeout in second
3141 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3143 * Returns 0 for success, non-zero for failure.
3145 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
3149 _base_wait_for_doorbell_ack(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3157 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3159 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
3160 if (!(int_status
& MPI2_HIS_SYS2IOC_DB_STATUS
)) {
3161 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3162 "%s: successful count(%d), timeout(%d)\n",
3163 ioc
->name
, __func__
, count
, timeout
));
3165 } else if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
3166 doorbell
= readl(&ioc
->chip
->Doorbell
);
3167 if ((doorbell
& MPI2_IOC_STATE_MASK
) ==
3168 MPI2_IOC_STATE_FAULT
) {
3169 mpt3sas_base_fault_info(ioc
, doorbell
);
3172 } else if (int_status
== 0xFFFFFFFF)
3175 if (sleep_flag
== CAN_SLEEP
)
3176 usleep_range(1000, 1500);
3184 "%s: failed due to timeout count(%d), int_status(%x)!\n",
3185 ioc
->name
, __func__
, count
, int_status
);
3190 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
3191 * @ioc: per adapter object
3192 * @timeout: timeout in second
3193 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3195 * Returns 0 for success, non-zero for failure.
3199 _base_wait_for_doorbell_not_used(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3206 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3208 doorbell_reg
= readl(&ioc
->chip
->Doorbell
);
3209 if (!(doorbell_reg
& MPI2_DOORBELL_USED
)) {
3210 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3211 "%s: successful count(%d), timeout(%d)\n",
3212 ioc
->name
, __func__
, count
, timeout
));
3215 if (sleep_flag
== CAN_SLEEP
)
3216 usleep_range(1000, 1500);
3223 "%s: failed due to timeout count(%d), doorbell_reg(%x)!\n",
3224 ioc
->name
, __func__
, count
, doorbell_reg
);
3229 * _base_send_ioc_reset - send doorbell reset
3230 * @ioc: per adapter object
3231 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
3232 * @timeout: timeout in second
3233 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3235 * Returns 0 for success, non-zero for failure.
3238 _base_send_ioc_reset(struct MPT3SAS_ADAPTER
*ioc
, u8 reset_type
, int timeout
,
3244 if (reset_type
!= MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
) {
3245 pr_err(MPT3SAS_FMT
"%s: unknown reset_type\n",
3246 ioc
->name
, __func__
);
3250 if (!(ioc
->facts
.IOCCapabilities
&
3251 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY
))
3254 pr_info(MPT3SAS_FMT
"sending message unit reset !!\n", ioc
->name
);
3256 writel(reset_type
<< MPI2_DOORBELL_FUNCTION_SHIFT
,
3257 &ioc
->chip
->Doorbell
);
3258 if ((_base_wait_for_doorbell_ack(ioc
, 15, sleep_flag
))) {
3262 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
,
3263 timeout
, sleep_flag
);
3266 "%s: failed going to ready state (ioc_state=0x%x)\n",
3267 ioc
->name
, __func__
, ioc_state
);
3272 pr_info(MPT3SAS_FMT
"message unit reset: %s\n",
3273 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
3278 * _base_handshake_req_reply_wait - send request thru doorbell interface
3279 * @ioc: per adapter object
3280 * @request_bytes: request length
3281 * @request: pointer having request payload
3282 * @reply_bytes: reply length
3283 * @reply: pointer to reply payload
3284 * @timeout: timeout in second
3285 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3287 * Returns 0 for success, non-zero for failure.
3290 _base_handshake_req_reply_wait(struct MPT3SAS_ADAPTER
*ioc
, int request_bytes
,
3291 u32
*request
, int reply_bytes
, u16
*reply
, int timeout
, int sleep_flag
)
3293 MPI2DefaultReply_t
*default_reply
= (MPI2DefaultReply_t
*)reply
;
3299 /* make sure doorbell is not in use */
3300 if ((readl(&ioc
->chip
->Doorbell
) & MPI2_DOORBELL_USED
)) {
3302 "doorbell is in use (line=%d)\n",
3303 ioc
->name
, __LINE__
);
3307 /* clear pending doorbell interrupts from previous state changes */
3308 if (readl(&ioc
->chip
->HostInterruptStatus
) &
3309 MPI2_HIS_IOC2SYS_DB_STATUS
)
3310 writel(0, &ioc
->chip
->HostInterruptStatus
);
3312 /* send message to ioc */
3313 writel(((MPI2_FUNCTION_HANDSHAKE
<<MPI2_DOORBELL_FUNCTION_SHIFT
) |
3314 ((request_bytes
/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT
)),
3315 &ioc
->chip
->Doorbell
);
3317 if ((_base_wait_for_doorbell_int(ioc
, 5, NO_SLEEP
))) {
3319 "doorbell handshake int failed (line=%d)\n",
3320 ioc
->name
, __LINE__
);
3323 writel(0, &ioc
->chip
->HostInterruptStatus
);
3325 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
))) {
3327 "doorbell handshake ack failed (line=%d)\n",
3328 ioc
->name
, __LINE__
);
3332 /* send message 32-bits at a time */
3333 for (i
= 0, failed
= 0; i
< request_bytes
/4 && !failed
; i
++) {
3334 writel(cpu_to_le32(request
[i
]), &ioc
->chip
->Doorbell
);
3335 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
)))
3341 "doorbell handshake sending request failed (line=%d)\n",
3342 ioc
->name
, __LINE__
);
3346 /* now wait for the reply */
3347 if ((_base_wait_for_doorbell_int(ioc
, timeout
, sleep_flag
))) {
3349 "doorbell handshake int failed (line=%d)\n",
3350 ioc
->name
, __LINE__
);
3354 /* read the first two 16-bits, it gives the total length of the reply */
3355 reply
[0] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3356 & MPI2_DOORBELL_DATA_MASK
);
3357 writel(0, &ioc
->chip
->HostInterruptStatus
);
3358 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3360 "doorbell handshake int failed (line=%d)\n",
3361 ioc
->name
, __LINE__
);
3364 reply
[1] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3365 & MPI2_DOORBELL_DATA_MASK
);
3366 writel(0, &ioc
->chip
->HostInterruptStatus
);
3368 for (i
= 2; i
< default_reply
->MsgLength
* 2; i
++) {
3369 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3371 "doorbell handshake int failed (line=%d)\n",
3372 ioc
->name
, __LINE__
);
3375 if (i
>= reply_bytes
/2) /* overflow case */
3376 dummy
= readl(&ioc
->chip
->Doorbell
);
3378 reply
[i
] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3379 & MPI2_DOORBELL_DATA_MASK
);
3380 writel(0, &ioc
->chip
->HostInterruptStatus
);
3383 _base_wait_for_doorbell_int(ioc
, 5, sleep_flag
);
3384 if (_base_wait_for_doorbell_not_used(ioc
, 5, sleep_flag
) != 0) {
3385 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3386 "doorbell is in use (line=%d)\n", ioc
->name
, __LINE__
));
3388 writel(0, &ioc
->chip
->HostInterruptStatus
);
3390 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3391 mfp
= (__le32
*)reply
;
3392 pr_info("\toffset:data\n");
3393 for (i
= 0; i
< reply_bytes
/4; i
++)
3394 pr_info("\t[0x%02x]:%08x\n", i
*4,
3395 le32_to_cpu(mfp
[i
]));
3401 * mpt3sas_base_sas_iounit_control - send sas iounit control to FW
3402 * @ioc: per adapter object
3403 * @mpi_reply: the reply payload from FW
3404 * @mpi_request: the request payload sent to FW
3406 * The SAS IO Unit Control Request message allows the host to perform low-level
3407 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3408 * to obtain the IOC assigned device handles for a device if it has other
3409 * identifying information about the device, in addition allows the host to
3410 * remove IOC resources associated with the device.
3412 * Returns 0 for success, non-zero for failure.
3415 mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER
*ioc
,
3416 Mpi2SasIoUnitControlReply_t
*mpi_reply
,
3417 Mpi2SasIoUnitControlRequest_t
*mpi_request
)
3421 unsigned long timeleft
;
3425 u16 wait_state_count
;
3427 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3430 mutex_lock(&ioc
->base_cmds
.mutex
);
3432 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
3433 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
3434 ioc
->name
, __func__
);
3439 wait_state_count
= 0;
3440 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3441 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3442 if (wait_state_count
++ == 10) {
3444 "%s: failed due to ioc not operational\n",
3445 ioc
->name
, __func__
);
3450 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3452 "%s: waiting for operational state(count=%d)\n",
3453 ioc
->name
, __func__
, wait_state_count
);
3456 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3458 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3459 ioc
->name
, __func__
);
3465 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
3466 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3467 ioc
->base_cmds
.smid
= smid
;
3468 memcpy(request
, mpi_request
, sizeof(Mpi2SasIoUnitControlRequest_t
));
3469 if (mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3470 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
)
3471 ioc
->ioc_link_reset_in_progress
= 1;
3472 init_completion(&ioc
->base_cmds
.done
);
3473 mpt3sas_base_put_smid_default(ioc
, smid
);
3474 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3475 msecs_to_jiffies(10000));
3476 if ((mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3477 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
) &&
3478 ioc
->ioc_link_reset_in_progress
)
3479 ioc
->ioc_link_reset_in_progress
= 0;
3480 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
3481 pr_err(MPT3SAS_FMT
"%s: timeout\n",
3482 ioc
->name
, __func__
);
3483 _debug_dump_mf(mpi_request
,
3484 sizeof(Mpi2SasIoUnitControlRequest_t
)/4);
3485 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
3487 goto issue_host_reset
;
3489 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
3490 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3491 sizeof(Mpi2SasIoUnitControlReply_t
));
3493 memset(mpi_reply
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
3494 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3499 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3501 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3504 mutex_unlock(&ioc
->base_cmds
.mutex
);
3509 * mpt3sas_base_scsi_enclosure_processor - sending request to sep device
3510 * @ioc: per adapter object
3511 * @mpi_reply: the reply payload from FW
3512 * @mpi_request: the request payload sent to FW
3514 * The SCSI Enclosure Processor request message causes the IOC to
3515 * communicate with SES devices to control LED status signals.
3517 * Returns 0 for success, non-zero for failure.
3520 mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER
*ioc
,
3521 Mpi2SepReply_t
*mpi_reply
, Mpi2SepRequest_t
*mpi_request
)
3525 unsigned long timeleft
;
3529 u16 wait_state_count
;
3531 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3534 mutex_lock(&ioc
->base_cmds
.mutex
);
3536 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
3537 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
3538 ioc
->name
, __func__
);
3543 wait_state_count
= 0;
3544 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3545 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3546 if (wait_state_count
++ == 10) {
3548 "%s: failed due to ioc not operational\n",
3549 ioc
->name
, __func__
);
3554 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3556 "%s: waiting for operational state(count=%d)\n",
3558 __func__
, wait_state_count
);
3561 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3563 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3564 ioc
->name
, __func__
);
3570 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
3571 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3572 ioc
->base_cmds
.smid
= smid
;
3573 memcpy(request
, mpi_request
, sizeof(Mpi2SepReply_t
));
3574 init_completion(&ioc
->base_cmds
.done
);
3575 mpt3sas_base_put_smid_default(ioc
, smid
);
3576 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3577 msecs_to_jiffies(10000));
3578 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
3579 pr_err(MPT3SAS_FMT
"%s: timeout\n",
3580 ioc
->name
, __func__
);
3581 _debug_dump_mf(mpi_request
,
3582 sizeof(Mpi2SepRequest_t
)/4);
3583 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
3585 goto issue_host_reset
;
3587 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
3588 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3589 sizeof(Mpi2SepReply_t
));
3591 memset(mpi_reply
, 0, sizeof(Mpi2SepReply_t
));
3592 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3597 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3599 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3602 mutex_unlock(&ioc
->base_cmds
.mutex
);
3607 * _base_get_port_facts - obtain port facts reply and save in ioc
3608 * @ioc: per adapter object
3609 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3611 * Returns 0 for success, non-zero for failure.
3614 _base_get_port_facts(struct MPT3SAS_ADAPTER
*ioc
, int port
, int sleep_flag
)
3616 Mpi2PortFactsRequest_t mpi_request
;
3617 Mpi2PortFactsReply_t mpi_reply
;
3618 struct mpt3sas_port_facts
*pfacts
;
3619 int mpi_reply_sz
, mpi_request_sz
, r
;
3621 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3624 mpi_reply_sz
= sizeof(Mpi2PortFactsReply_t
);
3625 mpi_request_sz
= sizeof(Mpi2PortFactsRequest_t
);
3626 memset(&mpi_request
, 0, mpi_request_sz
);
3627 mpi_request
.Function
= MPI2_FUNCTION_PORT_FACTS
;
3628 mpi_request
.PortNumber
= port
;
3629 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3630 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3633 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
3634 ioc
->name
, __func__
, r
);
3638 pfacts
= &ioc
->pfacts
[port
];
3639 memset(pfacts
, 0, sizeof(struct mpt3sas_port_facts
));
3640 pfacts
->PortNumber
= mpi_reply
.PortNumber
;
3641 pfacts
->VP_ID
= mpi_reply
.VP_ID
;
3642 pfacts
->VF_ID
= mpi_reply
.VF_ID
;
3643 pfacts
->MaxPostedCmdBuffers
=
3644 le16_to_cpu(mpi_reply
.MaxPostedCmdBuffers
);
3650 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3651 * @ioc: per adapter object
3652 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3654 * Returns 0 for success, non-zero for failure.
3657 _base_get_ioc_facts(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3659 Mpi2IOCFactsRequest_t mpi_request
;
3660 Mpi2IOCFactsReply_t mpi_reply
;
3661 struct mpt3sas_facts
*facts
;
3662 int mpi_reply_sz
, mpi_request_sz
, r
;
3664 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3667 mpi_reply_sz
= sizeof(Mpi2IOCFactsReply_t
);
3668 mpi_request_sz
= sizeof(Mpi2IOCFactsRequest_t
);
3669 memset(&mpi_request
, 0, mpi_request_sz
);
3670 mpi_request
.Function
= MPI2_FUNCTION_IOC_FACTS
;
3671 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3672 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3675 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
3676 ioc
->name
, __func__
, r
);
3680 facts
= &ioc
->facts
;
3681 memset(facts
, 0, sizeof(struct mpt3sas_facts
));
3682 facts
->MsgVersion
= le16_to_cpu(mpi_reply
.MsgVersion
);
3683 facts
->HeaderVersion
= le16_to_cpu(mpi_reply
.HeaderVersion
);
3684 facts
->VP_ID
= mpi_reply
.VP_ID
;
3685 facts
->VF_ID
= mpi_reply
.VF_ID
;
3686 facts
->IOCExceptions
= le16_to_cpu(mpi_reply
.IOCExceptions
);
3687 facts
->MaxChainDepth
= mpi_reply
.MaxChainDepth
;
3688 facts
->WhoInit
= mpi_reply
.WhoInit
;
3689 facts
->NumberOfPorts
= mpi_reply
.NumberOfPorts
;
3690 facts
->MaxMSIxVectors
= mpi_reply
.MaxMSIxVectors
;
3691 facts
->RequestCredit
= le16_to_cpu(mpi_reply
.RequestCredit
);
3692 facts
->MaxReplyDescriptorPostQueueDepth
=
3693 le16_to_cpu(mpi_reply
.MaxReplyDescriptorPostQueueDepth
);
3694 facts
->ProductID
= le16_to_cpu(mpi_reply
.ProductID
);
3695 facts
->IOCCapabilities
= le32_to_cpu(mpi_reply
.IOCCapabilities
);
3696 if ((facts
->IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
))
3697 ioc
->ir_firmware
= 1;
3698 if ((facts
->IOCCapabilities
&
3699 MPI2_IOCFACTS_CAPABILITY_RDPQ_ARRAY_CAPABLE
))
3700 ioc
->rdpq_array_capable
= 1;
3701 facts
->FWVersion
.Word
= le32_to_cpu(mpi_reply
.FWVersion
.Word
);
3702 facts
->IOCRequestFrameSize
=
3703 le16_to_cpu(mpi_reply
.IOCRequestFrameSize
);
3704 facts
->MaxInitiators
= le16_to_cpu(mpi_reply
.MaxInitiators
);
3705 facts
->MaxTargets
= le16_to_cpu(mpi_reply
.MaxTargets
);
3706 ioc
->shost
->max_id
= -1;
3707 facts
->MaxSasExpanders
= le16_to_cpu(mpi_reply
.MaxSasExpanders
);
3708 facts
->MaxEnclosures
= le16_to_cpu(mpi_reply
.MaxEnclosures
);
3709 facts
->ProtocolFlags
= le16_to_cpu(mpi_reply
.ProtocolFlags
);
3710 facts
->HighPriorityCredit
=
3711 le16_to_cpu(mpi_reply
.HighPriorityCredit
);
3712 facts
->ReplyFrameSize
= mpi_reply
.ReplyFrameSize
;
3713 facts
->MaxDevHandle
= le16_to_cpu(mpi_reply
.MaxDevHandle
);
3715 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3716 "hba queue depth(%d), max chains per io(%d)\n",
3717 ioc
->name
, facts
->RequestCredit
,
3718 facts
->MaxChainDepth
));
3719 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3720 "request frame size(%d), reply frame size(%d)\n", ioc
->name
,
3721 facts
->IOCRequestFrameSize
* 4, facts
->ReplyFrameSize
* 4));
3726 * _base_send_ioc_init - send ioc_init to firmware
3727 * @ioc: per adapter object
3728 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3730 * Returns 0 for success, non-zero for failure.
3733 _base_send_ioc_init(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3735 Mpi2IOCInitRequest_t mpi_request
;
3736 Mpi2IOCInitReply_t mpi_reply
;
3738 struct timeval current_time
;
3740 u32 reply_post_free_array_sz
= 0;
3741 Mpi2IOCInitRDPQArrayEntry
*reply_post_free_array
= NULL
;
3742 dma_addr_t reply_post_free_array_dma
;
3744 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3747 memset(&mpi_request
, 0, sizeof(Mpi2IOCInitRequest_t
));
3748 mpi_request
.Function
= MPI2_FUNCTION_IOC_INIT
;
3749 mpi_request
.WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
3750 mpi_request
.VF_ID
= 0; /* TODO */
3751 mpi_request
.VP_ID
= 0;
3752 mpi_request
.MsgVersion
= cpu_to_le16(MPI2_VERSION
);
3753 mpi_request
.HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
3755 if (_base_is_controller_msix_enabled(ioc
))
3756 mpi_request
.HostMSIxVectors
= ioc
->reply_queue_count
;
3757 mpi_request
.SystemRequestFrameSize
= cpu_to_le16(ioc
->request_sz
/4);
3758 mpi_request
.ReplyDescriptorPostQueueDepth
=
3759 cpu_to_le16(ioc
->reply_post_queue_depth
);
3760 mpi_request
.ReplyFreeQueueDepth
=
3761 cpu_to_le16(ioc
->reply_free_queue_depth
);
3763 mpi_request
.SenseBufferAddressHigh
=
3764 cpu_to_le32((u64
)ioc
->sense_dma
>> 32);
3765 mpi_request
.SystemReplyAddressHigh
=
3766 cpu_to_le32((u64
)ioc
->reply_dma
>> 32);
3767 mpi_request
.SystemRequestFrameBaseAddress
=
3768 cpu_to_le64((u64
)ioc
->request_dma
);
3769 mpi_request
.ReplyFreeQueueAddress
=
3770 cpu_to_le64((u64
)ioc
->reply_free_dma
);
3772 if (ioc
->rdpq_array_enable
) {
3773 reply_post_free_array_sz
= ioc
->reply_queue_count
*
3774 sizeof(Mpi2IOCInitRDPQArrayEntry
);
3775 reply_post_free_array
= pci_alloc_consistent(ioc
->pdev
,
3776 reply_post_free_array_sz
, &reply_post_free_array_dma
);
3777 if (!reply_post_free_array
) {
3779 "reply_post_free_array: pci_alloc_consistent failed\n",
3784 memset(reply_post_free_array
, 0, reply_post_free_array_sz
);
3785 for (i
= 0; i
< ioc
->reply_queue_count
; i
++)
3786 reply_post_free_array
[i
].RDPQBaseAddress
=
3788 (u64
)ioc
->reply_post
[i
].reply_post_free_dma
);
3789 mpi_request
.MsgFlags
= MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE
;
3790 mpi_request
.ReplyDescriptorPostQueueAddress
=
3791 cpu_to_le64((u64
)reply_post_free_array_dma
);
3793 mpi_request
.ReplyDescriptorPostQueueAddress
=
3794 cpu_to_le64((u64
)ioc
->reply_post
[0].reply_post_free_dma
);
3797 /* This time stamp specifies number of milliseconds
3798 * since epoch ~ midnight January 1, 1970.
3800 do_gettimeofday(¤t_time
);
3801 mpi_request
.TimeStamp
= cpu_to_le64((u64
)current_time
.tv_sec
* 1000 +
3802 (current_time
.tv_usec
/ 1000));
3804 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3808 mfp
= (__le32
*)&mpi_request
;
3809 pr_info("\toffset:data\n");
3810 for (i
= 0; i
< sizeof(Mpi2IOCInitRequest_t
)/4; i
++)
3811 pr_info("\t[0x%02x]:%08x\n", i
*4,
3812 le32_to_cpu(mfp
[i
]));
3815 r
= _base_handshake_req_reply_wait(ioc
,
3816 sizeof(Mpi2IOCInitRequest_t
), (u32
*)&mpi_request
,
3817 sizeof(Mpi2IOCInitReply_t
), (u16
*)&mpi_reply
, 10,
3821 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
3822 ioc
->name
, __func__
, r
);
3826 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3827 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
||
3828 mpi_reply
.IOCLogInfo
) {
3829 pr_err(MPT3SAS_FMT
"%s: failed\n", ioc
->name
, __func__
);
3834 if (reply_post_free_array
)
3835 pci_free_consistent(ioc
->pdev
, reply_post_free_array_sz
,
3836 reply_post_free_array
,
3837 reply_post_free_array_dma
);
3842 * mpt3sas_port_enable_done - command completion routine for port enable
3843 * @ioc: per adapter object
3844 * @smid: system request message index
3845 * @msix_index: MSIX table index supplied by the OS
3846 * @reply: reply message frame(lower 32bit addr)
3848 * Return 1 meaning mf should be freed from _base_interrupt
3849 * 0 means the mf is freed from this function.
3852 mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3855 MPI2DefaultReply_t
*mpi_reply
;
3858 if (ioc
->port_enable_cmds
.status
== MPT3_CMD_NOT_USED
)
3861 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3865 if (mpi_reply
->Function
!= MPI2_FUNCTION_PORT_ENABLE
)
3868 ioc
->port_enable_cmds
.status
&= ~MPT3_CMD_PENDING
;
3869 ioc
->port_enable_cmds
.status
|= MPT3_CMD_COMPLETE
;
3870 ioc
->port_enable_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
3871 memcpy(ioc
->port_enable_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
3872 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3873 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3874 ioc
->port_enable_failed
= 1;
3876 if (ioc
->is_driver_loading
) {
3877 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
3878 mpt3sas_port_enable_complete(ioc
);
3881 ioc
->start_scan_failed
= ioc_status
;
3882 ioc
->start_scan
= 0;
3886 complete(&ioc
->port_enable_cmds
.done
);
3891 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3892 * @ioc: per adapter object
3893 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3895 * Returns 0 for success, non-zero for failure.
3898 _base_send_port_enable(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3900 Mpi2PortEnableRequest_t
*mpi_request
;
3901 Mpi2PortEnableReply_t
*mpi_reply
;
3902 unsigned long timeleft
;
3907 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
3909 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
3910 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
3911 ioc
->name
, __func__
);
3915 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3917 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3918 ioc
->name
, __func__
);
3922 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
3923 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3924 ioc
->port_enable_cmds
.smid
= smid
;
3925 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3926 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3928 init_completion(&ioc
->port_enable_cmds
.done
);
3929 mpt3sas_base_put_smid_default(ioc
, smid
);
3930 timeleft
= wait_for_completion_timeout(&ioc
->port_enable_cmds
.done
,
3932 if (!(ioc
->port_enable_cmds
.status
& MPT3_CMD_COMPLETE
)) {
3933 pr_err(MPT3SAS_FMT
"%s: timeout\n",
3934 ioc
->name
, __func__
);
3935 _debug_dump_mf(mpi_request
,
3936 sizeof(Mpi2PortEnableRequest_t
)/4);
3937 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_RESET
)
3944 mpi_reply
= ioc
->port_enable_cmds
.reply
;
3945 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3946 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3947 pr_err(MPT3SAS_FMT
"%s: failed with (ioc_status=0x%08x)\n",
3948 ioc
->name
, __func__
, ioc_status
);
3954 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
3955 pr_info(MPT3SAS_FMT
"port enable: %s\n", ioc
->name
, ((r
== 0) ?
3956 "SUCCESS" : "FAILED"));
3961 * mpt3sas_port_enable - initiate firmware discovery (don't wait for reply)
3962 * @ioc: per adapter object
3964 * Returns 0 for success, non-zero for failure.
3967 mpt3sas_port_enable(struct MPT3SAS_ADAPTER
*ioc
)
3969 Mpi2PortEnableRequest_t
*mpi_request
;
3972 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
3974 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
3975 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
3976 ioc
->name
, __func__
);
3980 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3982 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3983 ioc
->name
, __func__
);
3987 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
3988 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3989 ioc
->port_enable_cmds
.smid
= smid
;
3990 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3991 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3993 mpt3sas_base_put_smid_default(ioc
, smid
);
3998 * _base_determine_wait_on_discovery - desposition
3999 * @ioc: per adapter object
4001 * Decide whether to wait on discovery to complete. Used to either
4002 * locate boot device, or report volumes ahead of physical devices.
4004 * Returns 1 for wait, 0 for don't wait
4007 _base_determine_wait_on_discovery(struct MPT3SAS_ADAPTER
*ioc
)
4009 /* We wait for discovery to complete if IR firmware is loaded.
4010 * The sas topology events arrive before PD events, so we need time to
4011 * turn on the bit in ioc->pd_handles to indicate PD
4012 * Also, it maybe required to report Volumes ahead of physical
4013 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
4015 if (ioc
->ir_firmware
)
4018 /* if no Bios, then we don't need to wait */
4019 if (!ioc
->bios_pg3
.BiosVersion
)
4022 /* Bios is present, then we drop down here.
4024 * If there any entries in the Bios Page 2, then we wait
4025 * for discovery to complete.
4028 /* Current Boot Device */
4029 if ((ioc
->bios_pg2
.CurrentBootDeviceForm
&
4030 MPI2_BIOSPAGE2_FORM_MASK
) ==
4031 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
4032 /* Request Boot Device */
4033 (ioc
->bios_pg2
.ReqBootDeviceForm
&
4034 MPI2_BIOSPAGE2_FORM_MASK
) ==
4035 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
4036 /* Alternate Request Boot Device */
4037 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
4038 MPI2_BIOSPAGE2_FORM_MASK
) ==
4039 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
)
4046 * _base_unmask_events - turn on notification for this event
4047 * @ioc: per adapter object
4048 * @event: firmware event
4050 * The mask is stored in ioc->event_masks.
4053 _base_unmask_events(struct MPT3SAS_ADAPTER
*ioc
, u16 event
)
4060 desired_event
= (1 << (event
% 32));
4063 ioc
->event_masks
[0] &= ~desired_event
;
4064 else if (event
< 64)
4065 ioc
->event_masks
[1] &= ~desired_event
;
4066 else if (event
< 96)
4067 ioc
->event_masks
[2] &= ~desired_event
;
4068 else if (event
< 128)
4069 ioc
->event_masks
[3] &= ~desired_event
;
4073 * _base_event_notification - send event notification
4074 * @ioc: per adapter object
4075 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4077 * Returns 0 for success, non-zero for failure.
4080 _base_event_notification(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4082 Mpi2EventNotificationRequest_t
*mpi_request
;
4083 unsigned long timeleft
;
4088 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4091 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
4092 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
4093 ioc
->name
, __func__
);
4097 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
4099 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4100 ioc
->name
, __func__
);
4103 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
4104 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4105 ioc
->base_cmds
.smid
= smid
;
4106 memset(mpi_request
, 0, sizeof(Mpi2EventNotificationRequest_t
));
4107 mpi_request
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
4108 mpi_request
->VF_ID
= 0; /* TODO */
4109 mpi_request
->VP_ID
= 0;
4110 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4111 mpi_request
->EventMasks
[i
] =
4112 cpu_to_le32(ioc
->event_masks
[i
]);
4113 init_completion(&ioc
->base_cmds
.done
);
4114 mpt3sas_base_put_smid_default(ioc
, smid
);
4115 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
, 30*HZ
);
4116 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
4117 pr_err(MPT3SAS_FMT
"%s: timeout\n",
4118 ioc
->name
, __func__
);
4119 _debug_dump_mf(mpi_request
,
4120 sizeof(Mpi2EventNotificationRequest_t
)/4);
4121 if (ioc
->base_cmds
.status
& MPT3_CMD_RESET
)
4126 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: complete\n",
4127 ioc
->name
, __func__
));
4128 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4133 * mpt3sas_base_validate_event_type - validating event types
4134 * @ioc: per adapter object
4135 * @event: firmware event
4137 * This will turn on firmware event notification when application
4138 * ask for that event. We don't mask events that are already enabled.
4141 mpt3sas_base_validate_event_type(struct MPT3SAS_ADAPTER
*ioc
, u32
*event_type
)
4144 u32 event_mask
, desired_event
;
4145 u8 send_update_to_fw
;
4147 for (i
= 0, send_update_to_fw
= 0; i
<
4148 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++) {
4149 event_mask
= ~event_type
[i
];
4151 for (j
= 0; j
< 32; j
++) {
4152 if (!(event_mask
& desired_event
) &&
4153 (ioc
->event_masks
[i
] & desired_event
)) {
4154 ioc
->event_masks
[i
] &= ~desired_event
;
4155 send_update_to_fw
= 1;
4157 desired_event
= (desired_event
<< 1);
4161 if (!send_update_to_fw
)
4164 mutex_lock(&ioc
->base_cmds
.mutex
);
4165 _base_event_notification(ioc
, CAN_SLEEP
);
4166 mutex_unlock(&ioc
->base_cmds
.mutex
);
4170 * _base_diag_reset - the "big hammer" start of day reset
4171 * @ioc: per adapter object
4172 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4174 * Returns 0 for success, non-zero for failure.
4177 _base_diag_reset(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4179 u32 host_diagnostic
;
4184 pr_info(MPT3SAS_FMT
"sending diag reset !!\n", ioc
->name
);
4186 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"clear interrupts\n",
4191 /* Write magic sequence to WriteSequence register
4192 * Loop until in diagnostic mode
4194 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4195 "write magic sequence\n", ioc
->name
));
4196 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4197 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4198 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4199 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4200 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4201 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4202 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4205 if (sleep_flag
== CAN_SLEEP
)
4213 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
4214 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4215 "wrote magic sequence: count(%d), host_diagnostic(0x%08x)\n",
4216 ioc
->name
, count
, host_diagnostic
));
4218 } while ((host_diagnostic
& MPI2_DIAG_DIAG_WRITE_ENABLE
) == 0);
4220 hcb_size
= readl(&ioc
->chip
->HCBSize
);
4222 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"diag reset: issued\n",
4224 writel(host_diagnostic
| MPI2_DIAG_RESET_ADAPTER
,
4225 &ioc
->chip
->HostDiagnostic
);
4227 /*This delay allows the chip PCIe hardware time to finish reset tasks*/
4228 if (sleep_flag
== CAN_SLEEP
)
4229 msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
4231 mdelay(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
4233 /* Approximately 300 second max wait */
4234 for (count
= 0; count
< (300000000 /
4235 MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
); count
++) {
4237 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
4239 if (host_diagnostic
== 0xFFFFFFFF)
4241 if (!(host_diagnostic
& MPI2_DIAG_RESET_ADAPTER
))
4244 /* Wait to pass the second read delay window */
4245 if (sleep_flag
== CAN_SLEEP
)
4246 msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
4249 mdelay(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
4253 if (host_diagnostic
& MPI2_DIAG_HCB_MODE
) {
4255 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4256 "restart the adapter assuming the HCB Address points to good F/W\n",
4258 host_diagnostic
&= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK
;
4259 host_diagnostic
|= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW
;
4260 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
4262 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4263 "re-enable the HCDW\n", ioc
->name
));
4264 writel(hcb_size
| MPI2_HCB_SIZE_HCB_ENABLE
,
4265 &ioc
->chip
->HCBSize
);
4268 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"restart the adapter\n",
4270 writel(host_diagnostic
& ~MPI2_DIAG_HOLD_IOC_RESET
,
4271 &ioc
->chip
->HostDiagnostic
);
4273 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4274 "disable writes to the diagnostic register\n", ioc
->name
));
4275 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4277 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4278 "Wait for FW to go to the READY state\n", ioc
->name
));
4279 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, 20,
4283 "%s: failed going to ready state (ioc_state=0x%x)\n",
4284 ioc
->name
, __func__
, ioc_state
);
4288 pr_info(MPT3SAS_FMT
"diag reset: SUCCESS\n", ioc
->name
);
4292 pr_err(MPT3SAS_FMT
"diag reset: FAILED\n", ioc
->name
);
4297 * _base_make_ioc_ready - put controller in READY state
4298 * @ioc: per adapter object
4299 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4300 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4302 * Returns 0 for success, non-zero for failure.
4305 _base_make_ioc_ready(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
,
4306 enum reset_type type
)
4312 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4315 if (ioc
->pci_error_recovery
)
4318 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4319 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: ioc_state(0x%08x)\n",
4320 ioc
->name
, __func__
, ioc_state
));
4322 /* if in RESET state, it should move to READY state shortly */
4324 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_RESET
) {
4325 while ((ioc_state
& MPI2_IOC_STATE_MASK
) !=
4326 MPI2_IOC_STATE_READY
) {
4327 if (count
++ == 10) {
4329 "%s: failed going to ready state (ioc_state=0x%x)\n",
4330 ioc
->name
, __func__
, ioc_state
);
4333 if (sleep_flag
== CAN_SLEEP
)
4337 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4341 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
)
4344 if (ioc_state
& MPI2_DOORBELL_USED
) {
4345 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4346 "unexpected doorbell active!\n",
4348 goto issue_diag_reset
;
4351 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
4352 mpt3sas_base_fault_info(ioc
, ioc_state
&
4353 MPI2_DOORBELL_DATA_MASK
);
4354 goto issue_diag_reset
;
4357 if (type
== FORCE_BIG_HAMMER
)
4358 goto issue_diag_reset
;
4360 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
4361 if (!(_base_send_ioc_reset(ioc
,
4362 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
, 15, CAN_SLEEP
))) {
4367 rc
= _base_diag_reset(ioc
, CAN_SLEEP
);
4372 * _base_make_ioc_operational - put controller in OPERATIONAL state
4373 * @ioc: per adapter object
4374 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4376 * Returns 0 for success, non-zero for failure.
4379 _base_make_ioc_operational(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4382 unsigned long flags
;
4385 struct _tr_list
*delayed_tr
, *delayed_tr_next
;
4386 struct adapter_reply_queue
*reply_q
;
4387 long reply_post_free
;
4388 u32 reply_post_free_sz
, index
= 0;
4390 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4393 /* clean the delayed target reset list */
4394 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4395 &ioc
->delayed_tr_list
, list
) {
4396 list_del(&delayed_tr
->list
);
4401 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4402 &ioc
->delayed_tr_volume_list
, list
) {
4403 list_del(&delayed_tr
->list
);
4407 /* initialize the scsi lookup free list */
4408 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4409 INIT_LIST_HEAD(&ioc
->free_list
);
4411 for (i
= 0; i
< ioc
->scsiio_depth
; i
++, smid
++) {
4412 INIT_LIST_HEAD(&ioc
->scsi_lookup
[i
].chain_list
);
4413 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
4414 ioc
->scsi_lookup
[i
].smid
= smid
;
4415 ioc
->scsi_lookup
[i
].scmd
= NULL
;
4416 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
4420 /* hi-priority queue */
4421 INIT_LIST_HEAD(&ioc
->hpr_free_list
);
4422 smid
= ioc
->hi_priority_smid
;
4423 for (i
= 0; i
< ioc
->hi_priority_depth
; i
++, smid
++) {
4424 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
4425 ioc
->hpr_lookup
[i
].smid
= smid
;
4426 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
4427 &ioc
->hpr_free_list
);
4430 /* internal queue */
4431 INIT_LIST_HEAD(&ioc
->internal_free_list
);
4432 smid
= ioc
->internal_smid
;
4433 for (i
= 0; i
< ioc
->internal_depth
; i
++, smid
++) {
4434 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
4435 ioc
->internal_lookup
[i
].smid
= smid
;
4436 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
4437 &ioc
->internal_free_list
);
4441 INIT_LIST_HEAD(&ioc
->free_chain_list
);
4442 for (i
= 0; i
< ioc
->chain_depth
; i
++)
4443 list_add_tail(&ioc
->chain_lookup
[i
].tracker_list
,
4444 &ioc
->free_chain_list
);
4446 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4448 /* initialize Reply Free Queue */
4449 for (i
= 0, reply_address
= (u32
)ioc
->reply_dma
;
4450 i
< ioc
->reply_free_queue_depth
; i
++, reply_address
+=
4452 ioc
->reply_free
[i
] = cpu_to_le32(reply_address
);
4454 /* initialize reply queues */
4455 if (ioc
->is_driver_loading
)
4456 _base_assign_reply_queues(ioc
);
4458 /* initialize Reply Post Free Queue */
4459 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
4460 sizeof(Mpi2DefaultReplyDescriptor_t
);
4461 reply_post_free
= (long)ioc
->reply_post
[index
].reply_post_free
;
4462 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4463 reply_q
->reply_post_host_index
= 0;
4464 reply_q
->reply_post_free
= (Mpi2ReplyDescriptorsUnion_t
*)
4466 for (i
= 0; i
< ioc
->reply_post_queue_depth
; i
++)
4467 reply_q
->reply_post_free
[i
].Words
=
4468 cpu_to_le64(ULLONG_MAX
);
4469 if (!_base_is_controller_msix_enabled(ioc
))
4470 goto skip_init_reply_post_free_queue
;
4472 * If RDPQ is enabled, switch to the next allocation.
4473 * Otherwise advance within the contiguous region.
4475 if (ioc
->rdpq_array_enable
)
4476 reply_post_free
= (long)
4477 ioc
->reply_post
[++index
].reply_post_free
;
4479 reply_post_free
+= reply_post_free_sz
;
4481 skip_init_reply_post_free_queue
:
4483 r
= _base_send_ioc_init(ioc
, sleep_flag
);
4487 /* initialize reply free host index */
4488 ioc
->reply_free_host_index
= ioc
->reply_free_queue_depth
- 1;
4489 writel(ioc
->reply_free_host_index
, &ioc
->chip
->ReplyFreeHostIndex
);
4491 /* initialize reply post host index */
4492 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4493 writel(reply_q
->msix_index
<< MPI2_RPHI_MSIX_INDEX_SHIFT
,
4494 &ioc
->chip
->ReplyPostHostIndex
);
4495 if (!_base_is_controller_msix_enabled(ioc
))
4496 goto skip_init_reply_post_host_index
;
4499 skip_init_reply_post_host_index
:
4501 _base_unmask_interrupts(ioc
);
4502 r
= _base_event_notification(ioc
, sleep_flag
);
4506 if (sleep_flag
== CAN_SLEEP
)
4507 _base_static_config_pages(ioc
);
4510 if (ioc
->is_driver_loading
) {
4511 ioc
->wait_for_discovery_to_complete
=
4512 _base_determine_wait_on_discovery(ioc
);
4514 return r
; /* scan_start and scan_finished support */
4517 r
= _base_send_port_enable(ioc
, sleep_flag
);
4525 * mpt3sas_base_free_resources - free resources controller resources
4526 * @ioc: per adapter object
4531 mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER
*ioc
)
4533 struct pci_dev
*pdev
= ioc
->pdev
;
4535 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4538 if (ioc
->chip_phys
&& ioc
->chip
) {
4539 _base_mask_interrupts(ioc
);
4540 ioc
->shost_recovery
= 1;
4541 _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4542 ioc
->shost_recovery
= 0;
4545 _base_free_irq(ioc
);
4546 _base_disable_msix(ioc
);
4548 if (ioc
->chip_phys
&& ioc
->chip
)
4552 if (pci_is_enabled(pdev
)) {
4553 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
4554 pci_disable_pcie_error_reporting(pdev
);
4555 pci_disable_device(pdev
);
4561 * mpt3sas_base_attach - attach controller instance
4562 * @ioc: per adapter object
4564 * Returns 0 for success, non-zero for failure.
4567 mpt3sas_base_attach(struct MPT3SAS_ADAPTER
*ioc
)
4570 int cpu_id
, last_cpu_id
= 0;
4572 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4575 /* setup cpu_msix_table */
4576 ioc
->cpu_count
= num_online_cpus();
4577 for_each_online_cpu(cpu_id
)
4578 last_cpu_id
= cpu_id
;
4579 ioc
->cpu_msix_table_sz
= last_cpu_id
+ 1;
4580 ioc
->cpu_msix_table
= kzalloc(ioc
->cpu_msix_table_sz
, GFP_KERNEL
);
4581 ioc
->reply_queue_count
= 1;
4582 if (!ioc
->cpu_msix_table
) {
4583 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
4584 "allocation for cpu_msix_table failed!!!\n",
4587 goto out_free_resources
;
4590 ioc
->rdpq_array_enable_assigned
= 0;
4592 r
= mpt3sas_base_map_resources(ioc
);
4594 goto out_free_resources
;
4597 pci_set_drvdata(ioc
->pdev
, ioc
->shost
);
4598 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
4600 goto out_free_resources
;
4604 * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and
4605 * Target Status - all require the IEEE formated scatter gather
4609 ioc
->build_sg_scmd
= &_base_build_sg_scmd_ieee
;
4610 ioc
->build_sg
= &_base_build_sg_ieee
;
4611 ioc
->build_zero_len_sge
= &_base_build_zero_len_sge_ieee
;
4613 ioc
->sge_size_ieee
= sizeof(Mpi2IeeeSgeSimple64_t
);
4616 * These function pointers for other requests that don't
4617 * the require IEEE scatter gather elements.
4619 * For example Configuration Pages and SAS IOUNIT Control don't.
4621 ioc
->build_sg_mpi
= &_base_build_sg
;
4622 ioc
->build_zero_len_sge_mpi
= &_base_build_zero_len_sge
;
4624 r
= _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4626 goto out_free_resources
;
4628 ioc
->pfacts
= kcalloc(ioc
->facts
.NumberOfPorts
,
4629 sizeof(struct mpt3sas_port_facts
), GFP_KERNEL
);
4632 goto out_free_resources
;
4635 for (i
= 0 ; i
< ioc
->facts
.NumberOfPorts
; i
++) {
4636 r
= _base_get_port_facts(ioc
, i
, CAN_SLEEP
);
4638 goto out_free_resources
;
4641 r
= _base_allocate_memory_pools(ioc
, CAN_SLEEP
);
4643 goto out_free_resources
;
4645 init_waitqueue_head(&ioc
->reset_wq
);
4647 /* allocate memory pd handle bitmask list */
4648 ioc
->pd_handles_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
4649 if (ioc
->facts
.MaxDevHandle
% 8)
4650 ioc
->pd_handles_sz
++;
4651 ioc
->pd_handles
= kzalloc(ioc
->pd_handles_sz
,
4653 if (!ioc
->pd_handles
) {
4655 goto out_free_resources
;
4657 ioc
->blocking_handles
= kzalloc(ioc
->pd_handles_sz
,
4659 if (!ioc
->blocking_handles
) {
4661 goto out_free_resources
;
4664 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
4666 /* base internal command bits */
4667 mutex_init(&ioc
->base_cmds
.mutex
);
4668 ioc
->base_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4669 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4671 /* port_enable command bits */
4672 ioc
->port_enable_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4673 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
4675 /* transport internal command bits */
4676 ioc
->transport_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4677 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
4678 mutex_init(&ioc
->transport_cmds
.mutex
);
4680 /* scsih internal command bits */
4681 ioc
->scsih_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4682 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
4683 mutex_init(&ioc
->scsih_cmds
.mutex
);
4685 /* task management internal command bits */
4686 ioc
->tm_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4687 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
4688 mutex_init(&ioc
->tm_cmds
.mutex
);
4690 /* config page internal command bits */
4691 ioc
->config_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4692 ioc
->config_cmds
.status
= MPT3_CMD_NOT_USED
;
4693 mutex_init(&ioc
->config_cmds
.mutex
);
4695 /* ctl module internal command bits */
4696 ioc
->ctl_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4697 ioc
->ctl_cmds
.sense
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
4698 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
4699 mutex_init(&ioc
->ctl_cmds
.mutex
);
4701 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4702 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4703 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
||
4704 !ioc
->ctl_cmds
.sense
) {
4706 goto out_free_resources
;
4709 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4710 ioc
->event_masks
[i
] = -1;
4712 /* here we enable the events we care about */
4713 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DISCOVERY
);
4714 _base_unmask_events(ioc
, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
);
4715 _base_unmask_events(ioc
, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
4716 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4717 _base_unmask_events(ioc
, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
);
4718 _base_unmask_events(ioc
, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
);
4719 _base_unmask_events(ioc
, MPI2_EVENT_IR_VOLUME
);
4720 _base_unmask_events(ioc
, MPI2_EVENT_IR_PHYSICAL_DISK
);
4721 _base_unmask_events(ioc
, MPI2_EVENT_IR_OPERATION_STATUS
);
4722 _base_unmask_events(ioc
, MPI2_EVENT_LOG_ENTRY_ADDED
);
4724 r
= _base_make_ioc_operational(ioc
, CAN_SLEEP
);
4726 goto out_free_resources
;
4732 ioc
->remove_host
= 1;
4734 mpt3sas_base_free_resources(ioc
);
4735 _base_release_memory_pools(ioc
);
4736 pci_set_drvdata(ioc
->pdev
, NULL
);
4737 kfree(ioc
->cpu_msix_table
);
4738 kfree(ioc
->pd_handles
);
4739 kfree(ioc
->blocking_handles
);
4740 kfree(ioc
->tm_cmds
.reply
);
4741 kfree(ioc
->transport_cmds
.reply
);
4742 kfree(ioc
->scsih_cmds
.reply
);
4743 kfree(ioc
->config_cmds
.reply
);
4744 kfree(ioc
->base_cmds
.reply
);
4745 kfree(ioc
->port_enable_cmds
.reply
);
4746 kfree(ioc
->ctl_cmds
.reply
);
4747 kfree(ioc
->ctl_cmds
.sense
);
4749 ioc
->ctl_cmds
.reply
= NULL
;
4750 ioc
->base_cmds
.reply
= NULL
;
4751 ioc
->tm_cmds
.reply
= NULL
;
4752 ioc
->scsih_cmds
.reply
= NULL
;
4753 ioc
->transport_cmds
.reply
= NULL
;
4754 ioc
->config_cmds
.reply
= NULL
;
4761 * mpt3sas_base_detach - remove controller instance
4762 * @ioc: per adapter object
4767 mpt3sas_base_detach(struct MPT3SAS_ADAPTER
*ioc
)
4769 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4772 mpt3sas_base_stop_watchdog(ioc
);
4773 mpt3sas_base_free_resources(ioc
);
4774 _base_release_memory_pools(ioc
);
4775 pci_set_drvdata(ioc
->pdev
, NULL
);
4776 kfree(ioc
->cpu_msix_table
);
4777 kfree(ioc
->pd_handles
);
4778 kfree(ioc
->blocking_handles
);
4780 kfree(ioc
->ctl_cmds
.reply
);
4781 kfree(ioc
->ctl_cmds
.sense
);
4782 kfree(ioc
->base_cmds
.reply
);
4783 kfree(ioc
->port_enable_cmds
.reply
);
4784 kfree(ioc
->tm_cmds
.reply
);
4785 kfree(ioc
->transport_cmds
.reply
);
4786 kfree(ioc
->scsih_cmds
.reply
);
4787 kfree(ioc
->config_cmds
.reply
);
4791 * _base_reset_handler - reset callback handler (for base)
4792 * @ioc: per adapter object
4793 * @reset_phase: phase
4795 * The handler for doing any required cleanup or initialization.
4797 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
4798 * MPT3_IOC_DONE_RESET
4803 _base_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
4805 mpt3sas_scsih_reset_handler(ioc
, reset_phase
);
4806 mpt3sas_ctl_reset_handler(ioc
, reset_phase
);
4807 switch (reset_phase
) {
4808 case MPT3_IOC_PRE_RESET
:
4809 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4810 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
4812 case MPT3_IOC_AFTER_RESET
:
4813 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4814 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
4815 if (ioc
->transport_cmds
.status
& MPT3_CMD_PENDING
) {
4816 ioc
->transport_cmds
.status
|= MPT3_CMD_RESET
;
4817 mpt3sas_base_free_smid(ioc
, ioc
->transport_cmds
.smid
);
4818 complete(&ioc
->transport_cmds
.done
);
4820 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
4821 ioc
->base_cmds
.status
|= MPT3_CMD_RESET
;
4822 mpt3sas_base_free_smid(ioc
, ioc
->base_cmds
.smid
);
4823 complete(&ioc
->base_cmds
.done
);
4825 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
4826 ioc
->port_enable_failed
= 1;
4827 ioc
->port_enable_cmds
.status
|= MPT3_CMD_RESET
;
4828 mpt3sas_base_free_smid(ioc
, ioc
->port_enable_cmds
.smid
);
4829 if (ioc
->is_driver_loading
) {
4830 ioc
->start_scan_failed
=
4831 MPI2_IOCSTATUS_INTERNAL_ERROR
;
4832 ioc
->start_scan
= 0;
4833 ioc
->port_enable_cmds
.status
=
4836 complete(&ioc
->port_enable_cmds
.done
);
4838 if (ioc
->config_cmds
.status
& MPT3_CMD_PENDING
) {
4839 ioc
->config_cmds
.status
|= MPT3_CMD_RESET
;
4840 mpt3sas_base_free_smid(ioc
, ioc
->config_cmds
.smid
);
4841 ioc
->config_cmds
.smid
= USHRT_MAX
;
4842 complete(&ioc
->config_cmds
.done
);
4845 case MPT3_IOC_DONE_RESET
:
4846 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4847 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
4853 * _wait_for_commands_to_complete - reset controller
4854 * @ioc: Pointer to MPT_ADAPTER structure
4855 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4857 * This function waiting(3s) for all pending commands to complete
4858 * prior to putting controller in reset.
4861 _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4864 unsigned long flags
;
4867 ioc
->pending_io_count
= 0;
4868 if (sleep_flag
!= CAN_SLEEP
)
4871 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4872 if ((ioc_state
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
)
4875 /* pending command count */
4876 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4877 for (i
= 0; i
< ioc
->scsiio_depth
; i
++)
4878 if (ioc
->scsi_lookup
[i
].cb_idx
!= 0xFF)
4879 ioc
->pending_io_count
++;
4880 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4882 if (!ioc
->pending_io_count
)
4885 /* wait for pending commands to complete */
4886 wait_event_timeout(ioc
->reset_wq
, ioc
->pending_io_count
== 0, 10 * HZ
);
4890 * mpt3sas_base_hard_reset_handler - reset controller
4891 * @ioc: Pointer to MPT_ADAPTER structure
4892 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4893 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4895 * Returns 0 for success, non-zero for failure.
4898 mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
,
4899 enum reset_type type
)
4902 unsigned long flags
;
4904 u8 is_fault
= 0, is_trigger
= 0;
4906 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
4909 if (ioc
->pci_error_recovery
) {
4910 pr_err(MPT3SAS_FMT
"%s: pci error recovery reset\n",
4911 ioc
->name
, __func__
);
4916 if (mpt3sas_fwfault_debug
)
4917 mpt3sas_halt_firmware(ioc
);
4919 /* TODO - What we really should be doing is pulling
4920 * out all the code associated with NO_SLEEP; its never used.
4921 * That is legacy code from mpt fusion driver, ported over.
4922 * I will leave this BUG_ON here for now till its been resolved.
4924 BUG_ON(sleep_flag
== NO_SLEEP
);
4926 /* wait for an active reset in progress to complete */
4927 if (!mutex_trylock(&ioc
->reset_in_progress_mutex
)) {
4930 } while (ioc
->shost_recovery
== 1);
4931 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,
4933 return ioc
->ioc_reset_in_progress_status
;
4936 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4937 ioc
->shost_recovery
= 1;
4938 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4940 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
4941 MPT3_DIAG_BUFFER_IS_REGISTERED
) &&
4942 (!(ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
4943 MPT3_DIAG_BUFFER_IS_RELEASED
))) {
4945 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4946 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
4949 _base_reset_handler(ioc
, MPT3_IOC_PRE_RESET
);
4950 _wait_for_commands_to_complete(ioc
, sleep_flag
);
4951 _base_mask_interrupts(ioc
);
4952 r
= _base_make_ioc_ready(ioc
, sleep_flag
, type
);
4955 _base_reset_handler(ioc
, MPT3_IOC_AFTER_RESET
);
4957 /* If this hard reset is called while port enable is active, then
4958 * there is no reason to call make_ioc_operational
4960 if (ioc
->is_driver_loading
&& ioc
->port_enable_failed
) {
4961 ioc
->remove_host
= 1;
4965 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
4969 if (ioc
->rdpq_array_enable
&& !ioc
->rdpq_array_capable
)
4970 panic("%s: Issue occurred with flashing controller firmware."
4971 "Please reboot the system and ensure that the correct"
4972 " firmware version is running\n", ioc
->name
);
4974 r
= _base_make_ioc_operational(ioc
, sleep_flag
);
4976 _base_reset_handler(ioc
, MPT3_IOC_DONE_RESET
);
4979 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %s\n",
4980 ioc
->name
, __func__
, ((r
== 0) ? "SUCCESS" : "FAILED")));
4982 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4983 ioc
->ioc_reset_in_progress_status
= r
;
4984 ioc
->shost_recovery
= 0;
4985 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4986 ioc
->ioc_reset_count
++;
4987 mutex_unlock(&ioc
->reset_in_progress_mutex
);
4990 if ((r
== 0) && is_trigger
) {
4992 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_FW_FAULT
);
4994 mpt3sas_trigger_master(ioc
,
4995 MASTER_TRIGGER_ADAPTER_RESET
);
4997 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,