2 * This is the Fusion MPT base driver providing common API layer interface
3 * for access to MPT (Message Passing Technology) firmware.
5 * This code is based on drivers/scsi/mpt3sas/mpt3sas_base.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * Copyright (C) 2013-2014 Avago Technologies
8 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 * solely responsible for determining the appropriateness of using and
26 * distributing the Program and assumes all risks associated with its
27 * exercise of rights under this Agreement, including but not limited to
28 * the risks and costs of program errors, damage to or loss of data,
29 * programs or equipment, and unavailability or interruption of operations.
31 * DISCLAIMER OF LIABILITY
32 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/slab.h>
51 #include <linux/types.h>
52 #include <linux/pci.h>
53 #include <linux/kdev_t.h>
54 #include <linux/blkdev.h>
55 #include <linux/delay.h>
56 #include <linux/interrupt.h>
57 #include <linux/dma-mapping.h>
59 #include <linux/time.h>
60 #include <linux/ktime.h>
61 #include <linux/kthread.h>
62 #include <asm/page.h> /* To get host page size per arch */
63 #include <linux/aer.h>
66 #include "mpt3sas_base.h"
68 static MPT_CALLBACK mpt_callbacks
[MPT_MAX_CALLBACKS
];
71 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
73 /* maximum controller queue depth */
74 #define MAX_HBA_QUEUE_DEPTH 30000
75 #define MAX_CHAIN_DEPTH 100000
76 static int max_queue_depth
= -1;
77 module_param(max_queue_depth
, int, 0);
78 MODULE_PARM_DESC(max_queue_depth
, " max controller queue depth ");
80 static int max_sgl_entries
= -1;
81 module_param(max_sgl_entries
, int, 0);
82 MODULE_PARM_DESC(max_sgl_entries
, " max sg entries ");
84 static int msix_disable
= -1;
85 module_param(msix_disable
, int, 0);
86 MODULE_PARM_DESC(msix_disable
, " disable msix routed interrupts (default=0)");
88 static int smp_affinity_enable
= 1;
89 module_param(smp_affinity_enable
, int, S_IRUGO
);
90 MODULE_PARM_DESC(smp_affinity_enable
, "SMP affinity feature enable/disbale Default: enable(1)");
92 static int max_msix_vectors
= -1;
93 module_param(max_msix_vectors
, int, 0);
94 MODULE_PARM_DESC(max_msix_vectors
,
97 static int mpt3sas_fwfault_debug
;
98 MODULE_PARM_DESC(mpt3sas_fwfault_debug
,
99 " enable detection of firmware fault and halt firmware - (default=0)");
102 _base_get_ioc_facts(struct MPT3SAS_ADAPTER
*ioc
);
105 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
109 _scsih_set_fwfault_debug(const char *val
, struct kernel_param
*kp
)
111 int ret
= param_set_int(val
, kp
);
112 struct MPT3SAS_ADAPTER
*ioc
;
117 /* global ioc spinlock to protect controller list on list operations */
118 pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug
);
119 spin_lock(&gioc_lock
);
120 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
121 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
122 spin_unlock(&gioc_lock
);
125 module_param_call(mpt3sas_fwfault_debug
, _scsih_set_fwfault_debug
,
126 param_get_int
, &mpt3sas_fwfault_debug
, 0644);
129 * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc
130 * @arg: input argument, used to derive ioc
132 * Return 0 if controller is removed from pci subsystem.
133 * Return -1 for other case.
135 static int mpt3sas_remove_dead_ioc_func(void *arg
)
137 struct MPT3SAS_ADAPTER
*ioc
= (struct MPT3SAS_ADAPTER
*)arg
;
138 struct pci_dev
*pdev
;
146 pci_stop_and_remove_bus_device_locked(pdev
);
151 * _base_fault_reset_work - workq handling ioc fault conditions
152 * @work: input argument, used to derive ioc
158 _base_fault_reset_work(struct work_struct
*work
)
160 struct MPT3SAS_ADAPTER
*ioc
=
161 container_of(work
, struct MPT3SAS_ADAPTER
, fault_reset_work
.work
);
165 struct task_struct
*p
;
168 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
169 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
)
171 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
173 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
174 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_MASK
) {
175 pr_err(MPT3SAS_FMT
"SAS host is non-operational !!!!\n",
178 /* It may be possible that EEH recovery can resolve some of
179 * pci bus failure issues rather removing the dead ioc function
180 * by considering controller is in a non-operational state. So
181 * here priority is given to the EEH recovery. If it doesn't
182 * not resolve this issue, mpt3sas driver will consider this
183 * controller to non-operational state and remove the dead ioc
186 if (ioc
->non_operational_loop
++ < 5) {
187 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
,
193 * Call _scsih_flush_pending_cmds callback so that we flush all
194 * pending commands back to OS. This call is required to aovid
195 * deadlock at block layer. Dead IOC will fail to do diag reset,
196 * and this call is safe since dead ioc will never return any
197 * command back from HW.
199 ioc
->schedule_dead_ioc_flush_running_cmds(ioc
);
201 * Set remove_host flag early since kernel thread will
202 * take some time to execute.
204 ioc
->remove_host
= 1;
205 /*Remove the Dead Host */
206 p
= kthread_run(mpt3sas_remove_dead_ioc_func
, ioc
,
207 "%s_dead_ioc_%d", ioc
->driver_name
, ioc
->id
);
210 "%s: Running mpt3sas_dead_ioc thread failed !!!!\n",
211 ioc
->name
, __func__
);
214 "%s: Running mpt3sas_dead_ioc thread success !!!!\n",
215 ioc
->name
, __func__
);
216 return; /* don't rearm timer */
219 ioc
->non_operational_loop
= 0;
221 if ((doorbell
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
) {
222 rc
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
223 pr_warn(MPT3SAS_FMT
"%s: hard reset: %s\n", ioc
->name
,
224 __func__
, (rc
== 0) ? "success" : "failed");
225 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
226 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
227 mpt3sas_base_fault_info(ioc
, doorbell
&
228 MPI2_DOORBELL_DATA_MASK
);
229 if (rc
&& (doorbell
& MPI2_IOC_STATE_MASK
) !=
230 MPI2_IOC_STATE_OPERATIONAL
)
231 return; /* don't rearm timer */
234 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
236 if (ioc
->fault_reset_work_q
)
237 queue_delayed_work(ioc
->fault_reset_work_q
,
238 &ioc
->fault_reset_work
,
239 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
240 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
244 * mpt3sas_base_start_watchdog - start the fault_reset_work_q
245 * @ioc: per adapter object
251 mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
255 if (ioc
->fault_reset_work_q
)
258 /* initialize fault polling */
260 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, _base_fault_reset_work
);
261 snprintf(ioc
->fault_reset_work_q_name
,
262 sizeof(ioc
->fault_reset_work_q_name
), "poll_%s%d_status",
263 ioc
->driver_name
, ioc
->id
);
264 ioc
->fault_reset_work_q
=
265 create_singlethread_workqueue(ioc
->fault_reset_work_q_name
);
266 if (!ioc
->fault_reset_work_q
) {
267 pr_err(MPT3SAS_FMT
"%s: failed (line=%d)\n",
268 ioc
->name
, __func__
, __LINE__
);
271 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
272 if (ioc
->fault_reset_work_q
)
273 queue_delayed_work(ioc
->fault_reset_work_q
,
274 &ioc
->fault_reset_work
,
275 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
276 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
280 * mpt3sas_base_stop_watchdog - stop the fault_reset_work_q
281 * @ioc: per adapter object
287 mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
290 struct workqueue_struct
*wq
;
292 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
293 wq
= ioc
->fault_reset_work_q
;
294 ioc
->fault_reset_work_q
= NULL
;
295 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
297 if (!cancel_delayed_work_sync(&ioc
->fault_reset_work
))
299 destroy_workqueue(wq
);
304 * mpt3sas_base_fault_info - verbose translation of firmware FAULT code
305 * @ioc: per adapter object
306 * @fault_code: fault code
311 mpt3sas_base_fault_info(struct MPT3SAS_ADAPTER
*ioc
, u16 fault_code
)
313 pr_err(MPT3SAS_FMT
"fault_state(0x%04x)!\n",
314 ioc
->name
, fault_code
);
318 * mpt3sas_halt_firmware - halt's mpt controller firmware
319 * @ioc: per adapter object
321 * For debugging timeout related issues. Writing 0xCOFFEE00
322 * to the doorbell register will halt controller firmware. With
323 * the purpose to stop both driver and firmware, the enduser can
324 * obtain a ring buffer from controller UART.
327 mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER
*ioc
)
331 if (!ioc
->fwfault_debug
)
336 doorbell
= readl(&ioc
->chip
->Doorbell
);
337 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
338 mpt3sas_base_fault_info(ioc
, doorbell
);
340 writel(0xC0FFEE00, &ioc
->chip
->Doorbell
);
341 pr_err(MPT3SAS_FMT
"Firmware is halted due to command timeout\n",
345 if (ioc
->fwfault_debug
== 2)
349 panic("panic in %s\n", __func__
);
353 * _base_sas_ioc_info - verbose translation of the ioc status
354 * @ioc: per adapter object
355 * @mpi_reply: reply mf payload returned from firmware
356 * @request_hdr: request mf
361 _base_sas_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, MPI2DefaultReply_t
*mpi_reply
,
362 MPI2RequestHeader_t
*request_hdr
)
364 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
368 char *func_str
= NULL
;
370 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
371 if (request_hdr
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
372 request_hdr
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
373 request_hdr
->Function
== MPI2_FUNCTION_EVENT_NOTIFICATION
)
376 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
379 switch (ioc_status
) {
381 /****************************************************************************
382 * Common IOCStatus values for all replies
383 ****************************************************************************/
385 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
386 desc
= "invalid function";
388 case MPI2_IOCSTATUS_BUSY
:
391 case MPI2_IOCSTATUS_INVALID_SGL
:
392 desc
= "invalid sgl";
394 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
395 desc
= "internal error";
397 case MPI2_IOCSTATUS_INVALID_VPID
:
398 desc
= "invalid vpid";
400 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
401 desc
= "insufficient resources";
403 case MPI2_IOCSTATUS_INSUFFICIENT_POWER
:
404 desc
= "insufficient power";
406 case MPI2_IOCSTATUS_INVALID_FIELD
:
407 desc
= "invalid field";
409 case MPI2_IOCSTATUS_INVALID_STATE
:
410 desc
= "invalid state";
412 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED
:
413 desc
= "op state not supported";
416 /****************************************************************************
417 * Config IOCStatus values
418 ****************************************************************************/
420 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION
:
421 desc
= "config invalid action";
423 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE
:
424 desc
= "config invalid type";
426 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
:
427 desc
= "config invalid page";
429 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA
:
430 desc
= "config invalid data";
432 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS
:
433 desc
= "config no defaults";
435 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT
:
436 desc
= "config cant commit";
439 /****************************************************************************
441 ****************************************************************************/
443 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
444 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
445 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
446 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
447 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
448 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
449 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
450 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
451 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
452 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
453 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
454 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
457 /****************************************************************************
458 * For use by SCSI Initiator and SCSI Target end-to-end data protection
459 ****************************************************************************/
461 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
462 desc
= "eedp guard error";
464 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
465 desc
= "eedp ref tag error";
467 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
468 desc
= "eedp app tag error";
471 /****************************************************************************
473 ****************************************************************************/
475 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX
:
476 desc
= "target invalid io index";
478 case MPI2_IOCSTATUS_TARGET_ABORTED
:
479 desc
= "target aborted";
481 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
:
482 desc
= "target no conn retryable";
484 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION
:
485 desc
= "target no connection";
487 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
:
488 desc
= "target xfer count mismatch";
490 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
:
491 desc
= "target data offset error";
493 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
:
494 desc
= "target too much write data";
496 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT
:
497 desc
= "target iu too short";
499 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
:
500 desc
= "target ack nak timeout";
502 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED
:
503 desc
= "target nak received";
506 /****************************************************************************
507 * Serial Attached SCSI values
508 ****************************************************************************/
510 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED
:
511 desc
= "smp request failed";
513 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN
:
514 desc
= "smp data overrun";
517 /****************************************************************************
518 * Diagnostic Buffer Post / Diagnostic Release values
519 ****************************************************************************/
521 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
:
522 desc
= "diagnostic released";
531 switch (request_hdr
->Function
) {
532 case MPI2_FUNCTION_CONFIG
:
533 frame_sz
= sizeof(Mpi2ConfigRequest_t
) + ioc
->sge_size
;
534 func_str
= "config_page";
536 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
537 frame_sz
= sizeof(Mpi2SCSITaskManagementRequest_t
);
538 func_str
= "task_mgmt";
540 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
541 frame_sz
= sizeof(Mpi2SasIoUnitControlRequest_t
);
542 func_str
= "sas_iounit_ctl";
544 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
545 frame_sz
= sizeof(Mpi2SepRequest_t
);
546 func_str
= "enclosure";
548 case MPI2_FUNCTION_IOC_INIT
:
549 frame_sz
= sizeof(Mpi2IOCInitRequest_t
);
550 func_str
= "ioc_init";
552 case MPI2_FUNCTION_PORT_ENABLE
:
553 frame_sz
= sizeof(Mpi2PortEnableRequest_t
);
554 func_str
= "port_enable";
556 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
557 frame_sz
= sizeof(Mpi2SmpPassthroughRequest_t
) + ioc
->sge_size
;
558 func_str
= "smp_passthru";
560 case MPI2_FUNCTION_NVME_ENCAPSULATED
:
561 frame_sz
= sizeof(Mpi26NVMeEncapsulatedRequest_t
) +
563 func_str
= "nvme_encapsulated";
567 func_str
= "unknown";
571 pr_warn(MPT3SAS_FMT
"ioc_status: %s(0x%04x), request(0x%p),(%s)\n",
572 ioc
->name
, desc
, ioc_status
, request_hdr
, func_str
);
574 _debug_dump_mf(request_hdr
, frame_sz
/4);
578 * _base_display_event_data - verbose translation of firmware asyn events
579 * @ioc: per adapter object
580 * @mpi_reply: reply mf payload returned from firmware
585 _base_display_event_data(struct MPT3SAS_ADAPTER
*ioc
,
586 Mpi2EventNotificationReply_t
*mpi_reply
)
591 if (!(ioc
->logging_level
& MPT_DEBUG_EVENTS
))
594 event
= le16_to_cpu(mpi_reply
->Event
);
597 case MPI2_EVENT_LOG_DATA
:
600 case MPI2_EVENT_STATE_CHANGE
:
601 desc
= "Status Change";
603 case MPI2_EVENT_HARD_RESET_RECEIVED
:
604 desc
= "Hard Reset Received";
606 case MPI2_EVENT_EVENT_CHANGE
:
607 desc
= "Event Change";
609 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
610 desc
= "Device Status Change";
612 case MPI2_EVENT_IR_OPERATION_STATUS
:
613 if (!ioc
->hide_ir_msg
)
614 desc
= "IR Operation Status";
616 case MPI2_EVENT_SAS_DISCOVERY
:
618 Mpi2EventDataSasDiscovery_t
*event_data
=
619 (Mpi2EventDataSasDiscovery_t
*)mpi_reply
->EventData
;
620 pr_info(MPT3SAS_FMT
"Discovery: (%s)", ioc
->name
,
621 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
623 if (event_data
->DiscoveryStatus
)
624 pr_cont(" discovery_status(0x%08x)",
625 le32_to_cpu(event_data
->DiscoveryStatus
));
629 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
630 desc
= "SAS Broadcast Primitive";
632 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
633 desc
= "SAS Init Device Status Change";
635 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW
:
636 desc
= "SAS Init Table Overflow";
638 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
639 desc
= "SAS Topology Change List";
641 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
642 desc
= "SAS Enclosure Device Status Change";
644 case MPI2_EVENT_IR_VOLUME
:
645 if (!ioc
->hide_ir_msg
)
648 case MPI2_EVENT_IR_PHYSICAL_DISK
:
649 if (!ioc
->hide_ir_msg
)
650 desc
= "IR Physical Disk";
652 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
653 if (!ioc
->hide_ir_msg
)
654 desc
= "IR Configuration Change List";
656 case MPI2_EVENT_LOG_ENTRY_ADDED
:
657 if (!ioc
->hide_ir_msg
)
658 desc
= "Log Entry Added";
660 case MPI2_EVENT_TEMP_THRESHOLD
:
661 desc
= "Temperature Threshold";
663 case MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
:
664 desc
= "Cable Event";
666 case MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
:
667 desc
= "PCIE Device Status Change";
669 case MPI2_EVENT_PCIE_ENUMERATION
:
671 Mpi26EventDataPCIeEnumeration_t
*event_data
=
672 (Mpi26EventDataPCIeEnumeration_t
*)mpi_reply
->EventData
;
673 pr_info(MPT3SAS_FMT
"PCIE Enumeration: (%s)", ioc
->name
,
674 (event_data
->ReasonCode
==
675 MPI26_EVENT_PCIE_ENUM_RC_STARTED
) ?
677 if (event_data
->EnumerationStatus
)
678 pr_info("enumeration_status(0x%08x)",
679 le32_to_cpu(event_data
->EnumerationStatus
));
683 case MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
684 desc
= "PCIE Topology Change List";
691 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
, desc
);
695 * _base_sas_log_info - verbose translation of firmware log info
696 * @ioc: per adapter object
697 * @log_info: log info
702 _base_sas_log_info(struct MPT3SAS_ADAPTER
*ioc
, u32 log_info
)
713 union loginfo_type sas_loginfo
;
714 char *originator_str
= NULL
;
716 sas_loginfo
.loginfo
= log_info
;
717 if (sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/)
720 /* each nexus loss loginfo */
721 if (log_info
== 0x31170000)
724 /* eat the loginfos associated with task aborts */
725 if (ioc
->ignore_loginfos
&& (log_info
== 0x30050000 || log_info
==
726 0x31140000 || log_info
== 0x31130000))
729 switch (sas_loginfo
.dw
.originator
) {
731 originator_str
= "IOP";
734 originator_str
= "PL";
737 if (!ioc
->hide_ir_msg
)
738 originator_str
= "IR";
740 originator_str
= "WarpDrive";
745 "log_info(0x%08x): originator(%s), code(0x%02x), sub_code(0x%04x)\n",
747 originator_str
, sas_loginfo
.dw
.code
,
748 sas_loginfo
.dw
.subcode
);
752 * _base_display_reply_info -
753 * @ioc: per adapter object
754 * @smid: system request message index
755 * @msix_index: MSIX table index supplied by the OS
756 * @reply: reply message frame(lower 32bit addr)
761 _base_display_reply_info(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
764 MPI2DefaultReply_t
*mpi_reply
;
768 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
769 if (unlikely(!mpi_reply
)) {
770 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
771 ioc
->name
, __FILE__
, __LINE__
, __func__
);
774 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
776 if ((ioc_status
& MPI2_IOCSTATUS_MASK
) &&
777 (ioc
->logging_level
& MPT_DEBUG_REPLY
)) {
778 _base_sas_ioc_info(ioc
, mpi_reply
,
779 mpt3sas_base_get_msg_frame(ioc
, smid
));
782 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
) {
783 loginfo
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
784 _base_sas_log_info(ioc
, loginfo
);
787 if (ioc_status
|| loginfo
) {
788 ioc_status
&= MPI2_IOCSTATUS_MASK
;
789 mpt3sas_trigger_mpi(ioc
, ioc_status
, loginfo
);
794 * mpt3sas_base_done - base internal command completion routine
795 * @ioc: per adapter object
796 * @smid: system request message index
797 * @msix_index: MSIX table index supplied by the OS
798 * @reply: reply message frame(lower 32bit addr)
800 * Return 1 meaning mf should be freed from _base_interrupt
801 * 0 means the mf is freed from this function.
804 mpt3sas_base_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
807 MPI2DefaultReply_t
*mpi_reply
;
809 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
810 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
811 return mpt3sas_check_for_pending_internal_cmds(ioc
, smid
);
813 if (ioc
->base_cmds
.status
== MPT3_CMD_NOT_USED
)
816 ioc
->base_cmds
.status
|= MPT3_CMD_COMPLETE
;
818 ioc
->base_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
819 memcpy(ioc
->base_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
821 ioc
->base_cmds
.status
&= ~MPT3_CMD_PENDING
;
823 complete(&ioc
->base_cmds
.done
);
828 * _base_async_event - main callback handler for firmware asyn events
829 * @ioc: per adapter object
830 * @msix_index: MSIX table index supplied by the OS
831 * @reply: reply message frame(lower 32bit addr)
833 * Return 1 meaning mf should be freed from _base_interrupt
834 * 0 means the mf is freed from this function.
837 _base_async_event(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
, u32 reply
)
839 Mpi2EventNotificationReply_t
*mpi_reply
;
840 Mpi2EventAckRequest_t
*ack_request
;
842 struct _event_ack_list
*delayed_event_ack
;
844 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
847 if (mpi_reply
->Function
!= MPI2_FUNCTION_EVENT_NOTIFICATION
)
850 _base_display_event_data(ioc
, mpi_reply
);
852 if (!(mpi_reply
->AckRequired
& MPI2_EVENT_NOTIFICATION_ACK_REQUIRED
))
854 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
856 delayed_event_ack
= kzalloc(sizeof(*delayed_event_ack
),
858 if (!delayed_event_ack
)
860 INIT_LIST_HEAD(&delayed_event_ack
->list
);
861 delayed_event_ack
->Event
= mpi_reply
->Event
;
862 delayed_event_ack
->EventContext
= mpi_reply
->EventContext
;
863 list_add_tail(&delayed_event_ack
->list
,
864 &ioc
->delayed_event_ack_list
);
865 dewtprintk(ioc
, pr_info(MPT3SAS_FMT
866 "DELAYED: EVENT ACK: event (0x%04x)\n",
867 ioc
->name
, le16_to_cpu(mpi_reply
->Event
)));
871 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
872 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
873 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
874 ack_request
->Event
= mpi_reply
->Event
;
875 ack_request
->EventContext
= mpi_reply
->EventContext
;
876 ack_request
->VF_ID
= 0; /* TODO */
877 ack_request
->VP_ID
= 0;
878 ioc
->put_smid_default(ioc
, smid
);
882 /* scsih callback handler */
883 mpt3sas_scsih_event_callback(ioc
, msix_index
, reply
);
885 /* ctl callback handler */
886 mpt3sas_ctl_event_callback(ioc
, msix_index
, reply
);
892 * _base_get_cb_idx - obtain the callback index
893 * @ioc: per adapter object
894 * @smid: system request message index
896 * Return callback index.
899 _base_get_cb_idx(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
904 if (smid
< ioc
->hi_priority_smid
) {
906 cb_idx
= ioc
->scsi_lookup
[i
].cb_idx
;
907 } else if (smid
< ioc
->internal_smid
) {
908 i
= smid
- ioc
->hi_priority_smid
;
909 cb_idx
= ioc
->hpr_lookup
[i
].cb_idx
;
910 } else if (smid
<= ioc
->hba_queue_depth
) {
911 i
= smid
- ioc
->internal_smid
;
912 cb_idx
= ioc
->internal_lookup
[i
].cb_idx
;
919 * _base_mask_interrupts - disable interrupts
920 * @ioc: per adapter object
922 * Disabling ResetIRQ, Reply and Doorbell Interrupts
927 _base_mask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
931 ioc
->mask_interrupts
= 1;
932 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
933 him_register
|= MPI2_HIM_DIM
+ MPI2_HIM_RIM
+ MPI2_HIM_RESET_IRQ_MASK
;
934 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
935 readl(&ioc
->chip
->HostInterruptMask
);
939 * _base_unmask_interrupts - enable interrupts
940 * @ioc: per adapter object
942 * Enabling only Reply Interrupts
947 _base_unmask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
951 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
952 him_register
&= ~MPI2_HIM_RIM
;
953 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
954 ioc
->mask_interrupts
= 0;
957 union reply_descriptor
{
966 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
967 * @irq: irq number (not used)
968 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
969 * @r: pt_regs pointer (not used)
971 * Return IRQ_HANDLE if processed, else IRQ_NONE.
974 _base_interrupt(int irq
, void *bus_id
)
976 struct adapter_reply_queue
*reply_q
= bus_id
;
977 union reply_descriptor rd
;
979 u8 request_desript_type
;
983 u8 msix_index
= reply_q
->msix_index
;
984 struct MPT3SAS_ADAPTER
*ioc
= reply_q
->ioc
;
985 Mpi2ReplyDescriptorsUnion_t
*rpf
;
988 if (ioc
->mask_interrupts
)
991 if (!atomic_add_unless(&reply_q
->busy
, 1, 1))
994 rpf
= &reply_q
->reply_post_free
[reply_q
->reply_post_host_index
];
995 request_desript_type
= rpf
->Default
.ReplyFlags
996 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
997 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
) {
998 atomic_dec(&reply_q
->busy
);
1005 rd
.word
= le64_to_cpu(rpf
->Words
);
1006 if (rd
.u
.low
== UINT_MAX
|| rd
.u
.high
== UINT_MAX
)
1009 smid
= le16_to_cpu(rpf
->Default
.DescriptorTypeDependent1
);
1010 if (request_desript_type
==
1011 MPI25_RPY_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO_SUCCESS
||
1012 request_desript_type
==
1013 MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS
||
1014 request_desript_type
==
1015 MPI26_RPY_DESCRIPT_FLAGS_PCIE_ENCAPSULATED_SUCCESS
) {
1016 cb_idx
= _base_get_cb_idx(ioc
, smid
);
1017 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
1018 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
1019 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
1022 mpt3sas_base_free_smid(ioc
, smid
);
1024 } else if (request_desript_type
==
1025 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY
) {
1026 reply
= le32_to_cpu(
1027 rpf
->AddressReply
.ReplyFrameAddress
);
1028 if (reply
> ioc
->reply_dma_max_address
||
1029 reply
< ioc
->reply_dma_min_address
)
1032 cb_idx
= _base_get_cb_idx(ioc
, smid
);
1033 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
1034 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
1035 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
1038 _base_display_reply_info(ioc
,
1039 smid
, msix_index
, reply
);
1041 mpt3sas_base_free_smid(ioc
,
1045 _base_async_event(ioc
, msix_index
, reply
);
1048 /* reply free queue handling */
1050 ioc
->reply_free_host_index
=
1051 (ioc
->reply_free_host_index
==
1052 (ioc
->reply_free_queue_depth
- 1)) ?
1053 0 : ioc
->reply_free_host_index
+ 1;
1054 ioc
->reply_free
[ioc
->reply_free_host_index
] =
1056 writel(ioc
->reply_free_host_index
,
1057 &ioc
->chip
->ReplyFreeHostIndex
);
1061 rpf
->Words
= cpu_to_le64(ULLONG_MAX
);
1062 reply_q
->reply_post_host_index
=
1063 (reply_q
->reply_post_host_index
==
1064 (ioc
->reply_post_queue_depth
- 1)) ? 0 :
1065 reply_q
->reply_post_host_index
+ 1;
1066 request_desript_type
=
1067 reply_q
->reply_post_free
[reply_q
->reply_post_host_index
].
1068 Default
.ReplyFlags
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
1070 /* Update the reply post host index after continuously
1071 * processing the threshold number of Reply Descriptors.
1072 * So that FW can find enough entries to post the Reply
1073 * Descriptors in the reply descriptor post queue.
1075 if (completed_cmds
> ioc
->hba_queue_depth
/3) {
1076 if (ioc
->combined_reply_queue
) {
1077 writel(reply_q
->reply_post_host_index
|
1078 ((msix_index
& 7) <<
1079 MPI2_RPHI_MSIX_INDEX_SHIFT
),
1080 ioc
->replyPostRegisterIndex
[msix_index
/8]);
1082 writel(reply_q
->reply_post_host_index
|
1084 MPI2_RPHI_MSIX_INDEX_SHIFT
),
1085 &ioc
->chip
->ReplyPostHostIndex
);
1089 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
1091 if (!reply_q
->reply_post_host_index
)
1092 rpf
= reply_q
->reply_post_free
;
1099 if (!completed_cmds
) {
1100 atomic_dec(&reply_q
->busy
);
1104 if (ioc
->is_warpdrive
) {
1105 writel(reply_q
->reply_post_host_index
,
1106 ioc
->reply_post_host_index
[msix_index
]);
1107 atomic_dec(&reply_q
->busy
);
1111 /* Update Reply Post Host Index.
1112 * For those HBA's which support combined reply queue feature
1113 * 1. Get the correct Supplemental Reply Post Host Index Register.
1114 * i.e. (msix_index / 8)th entry from Supplemental Reply Post Host
1115 * Index Register address bank i.e replyPostRegisterIndex[],
1116 * 2. Then update this register with new reply host index value
1117 * in ReplyPostIndex field and the MSIxIndex field with
1118 * msix_index value reduced to a value between 0 and 7,
1119 * using a modulo 8 operation. Since each Supplemental Reply Post
1120 * Host Index Register supports 8 MSI-X vectors.
1122 * For other HBA's just update the Reply Post Host Index register with
1123 * new reply host index value in ReplyPostIndex Field and msix_index
1124 * value in MSIxIndex field.
1126 if (ioc
->combined_reply_queue
)
1127 writel(reply_q
->reply_post_host_index
| ((msix_index
& 7) <<
1128 MPI2_RPHI_MSIX_INDEX_SHIFT
),
1129 ioc
->replyPostRegisterIndex
[msix_index
/8]);
1131 writel(reply_q
->reply_post_host_index
| (msix_index
<<
1132 MPI2_RPHI_MSIX_INDEX_SHIFT
),
1133 &ioc
->chip
->ReplyPostHostIndex
);
1134 atomic_dec(&reply_q
->busy
);
1139 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1140 * @ioc: per adapter object
1144 _base_is_controller_msix_enabled(struct MPT3SAS_ADAPTER
*ioc
)
1146 return (ioc
->facts
.IOCCapabilities
&
1147 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
;
1151 * mpt3sas_base_sync_reply_irqs - flush pending MSIX interrupts
1152 * @ioc: per adapter object
1153 * Context: non ISR conext
1155 * Called when a Task Management request has completed.
1160 mpt3sas_base_sync_reply_irqs(struct MPT3SAS_ADAPTER
*ioc
)
1162 struct adapter_reply_queue
*reply_q
;
1164 /* If MSIX capability is turned off
1165 * then multi-queues are not enabled
1167 if (!_base_is_controller_msix_enabled(ioc
))
1170 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1171 if (ioc
->shost_recovery
|| ioc
->remove_host
||
1172 ioc
->pci_error_recovery
)
1174 /* TMs are on msix_index == 0 */
1175 if (reply_q
->msix_index
== 0)
1177 synchronize_irq(pci_irq_vector(ioc
->pdev
, reply_q
->msix_index
));
1182 * mpt3sas_base_release_callback_handler - clear interrupt callback handler
1183 * @cb_idx: callback index
1188 mpt3sas_base_release_callback_handler(u8 cb_idx
)
1190 mpt_callbacks
[cb_idx
] = NULL
;
1194 * mpt3sas_base_register_callback_handler - obtain index for the interrupt callback handler
1195 * @cb_func: callback function
1200 mpt3sas_base_register_callback_handler(MPT_CALLBACK cb_func
)
1204 for (cb_idx
= MPT_MAX_CALLBACKS
-1; cb_idx
; cb_idx
--)
1205 if (mpt_callbacks
[cb_idx
] == NULL
)
1208 mpt_callbacks
[cb_idx
] = cb_func
;
1213 * mpt3sas_base_initialize_callback_handler - initialize the interrupt callback handler
1218 mpt3sas_base_initialize_callback_handler(void)
1222 for (cb_idx
= 0; cb_idx
< MPT_MAX_CALLBACKS
; cb_idx
++)
1223 mpt3sas_base_release_callback_handler(cb_idx
);
1228 * _base_build_zero_len_sge - build zero length sg entry
1229 * @ioc: per adapter object
1230 * @paddr: virtual address for SGE
1232 * Create a zero length scatter gather entry to insure the IOCs hardware has
1233 * something to use if the target device goes brain dead and tries
1234 * to send data even when none is asked for.
1239 _base_build_zero_len_sge(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1241 u32 flags_length
= (u32
)((MPI2_SGE_FLAGS_LAST_ELEMENT
|
1242 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
|
1243 MPI2_SGE_FLAGS_SIMPLE_ELEMENT
) <<
1244 MPI2_SGE_FLAGS_SHIFT
);
1245 ioc
->base_add_sg_single(paddr
, flags_length
, -1);
1249 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1250 * @paddr: virtual address for SGE
1251 * @flags_length: SGE flags and data transfer length
1252 * @dma_addr: Physical address
1257 _base_add_sg_single_32(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1259 Mpi2SGESimple32_t
*sgel
= paddr
;
1261 flags_length
|= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING
|
1262 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1263 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1264 sgel
->Address
= cpu_to_le32(dma_addr
);
1269 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1270 * @paddr: virtual address for SGE
1271 * @flags_length: SGE flags and data transfer length
1272 * @dma_addr: Physical address
1277 _base_add_sg_single_64(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1279 Mpi2SGESimple64_t
*sgel
= paddr
;
1281 flags_length
|= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING
|
1282 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1283 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1284 sgel
->Address
= cpu_to_le64(dma_addr
);
1288 * _base_get_chain_buffer_tracker - obtain chain tracker
1289 * @ioc: per adapter object
1290 * @smid: smid associated to an IO request
1292 * Returns chain tracker(from ioc->free_chain_list)
1294 static struct chain_tracker
*
1295 _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1297 struct chain_tracker
*chain_req
;
1298 unsigned long flags
;
1300 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1301 if (list_empty(&ioc
->free_chain_list
)) {
1302 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1303 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1304 "chain buffers not available\n", ioc
->name
));
1307 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1308 struct chain_tracker
, tracker_list
);
1309 list_del_init(&chain_req
->tracker_list
);
1310 list_add_tail(&chain_req
->tracker_list
,
1311 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1312 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1318 * _base_build_sg - build generic sg
1319 * @ioc: per adapter object
1320 * @psge: virtual address for SGE
1321 * @data_out_dma: physical address for WRITES
1322 * @data_out_sz: data xfer size for WRITES
1323 * @data_in_dma: physical address for READS
1324 * @data_in_sz: data xfer size for READS
1329 _base_build_sg(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
1330 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1335 if (!data_out_sz
&& !data_in_sz
) {
1336 _base_build_zero_len_sge(ioc
, psge
);
1340 if (data_out_sz
&& data_in_sz
) {
1341 /* WRITE sgel first */
1342 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1343 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1344 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1345 ioc
->base_add_sg_single(psge
, sgl_flags
|
1346 data_out_sz
, data_out_dma
);
1349 psge
+= ioc
->sge_size
;
1351 /* READ sgel last */
1352 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1353 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1354 MPI2_SGE_FLAGS_END_OF_LIST
);
1355 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1356 ioc
->base_add_sg_single(psge
, sgl_flags
|
1357 data_in_sz
, data_in_dma
);
1358 } else if (data_out_sz
) /* WRITE */ {
1359 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1360 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1361 MPI2_SGE_FLAGS_END_OF_LIST
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1362 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1363 ioc
->base_add_sg_single(psge
, sgl_flags
|
1364 data_out_sz
, data_out_dma
);
1365 } else if (data_in_sz
) /* READ */ {
1366 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1367 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1368 MPI2_SGE_FLAGS_END_OF_LIST
);
1369 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1370 ioc
->base_add_sg_single(psge
, sgl_flags
|
1371 data_in_sz
, data_in_dma
);
1375 /* IEEE format sgls */
1378 * _base_build_nvme_prp - This function is called for NVMe end devices to build
1379 * a native SGL (NVMe PRP). The native SGL is built starting in the first PRP
1380 * entry of the NVMe message (PRP1). If the data buffer is small enough to be
1381 * described entirely using PRP1, then PRP2 is not used. If needed, PRP2 is
1382 * used to describe a larger data buffer. If the data buffer is too large to
1383 * describe using the two PRP entriess inside the NVMe message, then PRP1
1384 * describes the first data memory segment, and PRP2 contains a pointer to a PRP
1385 * list located elsewhere in memory to describe the remaining data memory
1386 * segments. The PRP list will be contiguous.
1388 * The native SGL for NVMe devices is a Physical Region Page (PRP). A PRP
1389 * consists of a list of PRP entries to describe a number of noncontigous
1390 * physical memory segments as a single memory buffer, just as a SGL does. Note
1391 * however, that this function is only used by the IOCTL call, so the memory
1392 * given will be guaranteed to be contiguous. There is no need to translate
1393 * non-contiguous SGL into a PRP in this case. All PRPs will describe
1394 * contiguous space that is one page size each.
1396 * Each NVMe message contains two PRP entries. The first (PRP1) either contains
1397 * a PRP list pointer or a PRP element, depending upon the command. PRP2
1398 * contains the second PRP element if the memory being described fits within 2
1399 * PRP entries, or a PRP list pointer if the PRP spans more than two entries.
1401 * A PRP list pointer contains the address of a PRP list, structured as a linear
1402 * array of PRP entries. Each PRP entry in this list describes a segment of
1405 * Each 64-bit PRP entry comprises an address and an offset field. The address
1406 * always points at the beginning of a 4KB physical memory page, and the offset
1407 * describes where within that 4KB page the memory segment begins. Only the
1408 * first element in a PRP list may contain a non-zero offest, implying that all
1409 * memory segments following the first begin at the start of a 4KB page.
1411 * Each PRP element normally describes 4KB of physical memory, with exceptions
1412 * for the first and last elements in the list. If the memory being described
1413 * by the list begins at a non-zero offset within the first 4KB page, then the
1414 * first PRP element will contain a non-zero offset indicating where the region
1415 * begins within the 4KB page. The last memory segment may end before the end
1416 * of the 4KB segment, depending upon the overall size of the memory being
1417 * described by the PRP list.
1419 * Since PRP entries lack any indication of size, the overall data buffer length
1420 * is used to determine where the end of the data memory buffer is located, and
1421 * how many PRP entries are required to describe it.
1423 * @ioc: per adapter object
1424 * @smid: system request message index for getting asscociated SGL
1425 * @nvme_encap_request: the NVMe request msg frame pointer
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_nvme_prp(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
1435 Mpi26NVMeEncapsulatedRequest_t
*nvme_encap_request
,
1436 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1439 int prp_size
= NVME_PRP_SIZE
;
1440 u64
*prp_entry
, *prp1_entry
, *prp2_entry
, *prp_entry_phys
;
1441 u64
*prp_page
, *prp_page_phys
;
1442 u32 offset
, entry_len
;
1443 u32 page_mask_result
, page_mask
;
1448 * Not all commands require a data transfer. If no data, just return
1449 * without constructing any PRP.
1451 if (!data_in_sz
&& !data_out_sz
)
1454 * Set pointers to PRP1 and PRP2, which are in the NVMe command.
1455 * PRP1 is located at a 24 byte offset from the start of the NVMe
1456 * command. Then set the current PRP entry pointer to PRP1.
1458 prp1_entry
= (u64
*)(nvme_encap_request
->NVMe_Command
+
1459 NVME_CMD_PRP1_OFFSET
);
1460 prp2_entry
= (u64
*)(nvme_encap_request
->NVMe_Command
+
1461 NVME_CMD_PRP2_OFFSET
);
1462 prp_entry
= prp1_entry
;
1464 * For the PRP entries, use the specially allocated buffer of
1465 * contiguous memory.
1467 prp_page
= (u64
*)mpt3sas_base_get_pcie_sgl(ioc
, smid
);
1468 prp_page_phys
= (u64
*)mpt3sas_base_get_pcie_sgl_dma(ioc
, smid
);
1471 * Check if we are within 1 entry of a page boundary we don't
1472 * want our first entry to be a PRP List entry.
1474 page_mask
= ioc
->page_size
- 1;
1475 page_mask_result
= (uintptr_t)((u8
*)prp_page
+ prp_size
) & page_mask
;
1476 if (!page_mask_result
) {
1477 /* Bump up to next page boundary. */
1478 prp_page
= (u64
*)((u8
*)prp_page
+ prp_size
);
1479 prp_page_phys
= (u64
*)((u8
*)prp_page_phys
+ prp_size
);
1483 * Set PRP physical pointer, which initially points to the current PRP
1486 prp_entry_phys
= prp_page_phys
;
1488 /* Get physical address and length of the data buffer. */
1490 paddr
= data_in_dma
;
1491 length
= data_in_sz
;
1493 paddr
= data_out_dma
;
1494 length
= data_out_sz
;
1497 /* Loop while the length is not zero. */
1500 * Check if we need to put a list pointer here if we are at
1501 * page boundary - prp_size (8 bytes).
1504 (uintptr_t)((u8
*)prp_entry_phys
+ prp_size
) & page_mask
;
1505 if (!page_mask_result
) {
1507 * This is the last entry in a PRP List, so we need to
1508 * put a PRP list pointer here. What this does is:
1509 * - bump the current memory pointer to the next
1510 * address, which will be the next full page.
1511 * - set the PRP Entry to point to that page. This
1512 * is now the PRP List pointer.
1513 * - bump the PRP Entry pointer the start of the
1514 * next page. Since all of this PRP memory is
1515 * contiguous, no need to get a new page - it's
1516 * just the next address.
1519 *prp_entry
= cpu_to_le64((uintptr_t)prp_entry_phys
);
1523 /* Need to handle if entry will be part of a page. */
1524 offset
= (u32
)paddr
& page_mask
;
1525 entry_len
= ioc
->page_size
- offset
;
1527 if (prp_entry
== prp1_entry
) {
1529 * Must fill in the first PRP pointer (PRP1) before
1532 *prp1_entry
= cpu_to_le64((u64
)paddr
);
1535 * Now point to the second PRP entry within the
1538 prp_entry
= prp2_entry
;
1539 } else if (prp_entry
== prp2_entry
) {
1541 * Should the PRP2 entry be a PRP List pointer or just
1542 * a regular PRP pointer? If there is more than one
1543 * more page of data, must use a PRP List pointer.
1545 if (length
> ioc
->page_size
) {
1547 * PRP2 will contain a PRP List pointer because
1548 * more PRP's are needed with this command. The
1549 * list will start at the beginning of the
1550 * contiguous buffer.
1553 cpu_to_le64((uintptr_t)prp_entry_phys
);
1556 * The next PRP Entry will be the start of the
1559 prp_entry
= prp_page
;
1562 * After this, the PRP Entries are complete.
1563 * This command uses 2 PRP's and no PRP list.
1565 *prp2_entry
= cpu_to_le64((u64
)paddr
);
1569 * Put entry in list and bump the addresses.
1571 * After PRP1 and PRP2 are filled in, this will fill in
1572 * all remaining PRP entries in a PRP List, one per
1573 * each time through the loop.
1575 *prp_entry
= cpu_to_le64((u64
)paddr
);
1581 * Bump the phys address of the command's data buffer by the
1586 /* Decrement length accounting for last partial page. */
1587 if (entry_len
> length
)
1590 length
-= entry_len
;
1595 * base_make_prp_nvme -
1596 * Prepare PRPs(Physical Region Page)- SGLs specific to NVMe drives only
1598 * @ioc: per adapter object
1599 * @scmd: SCSI command from the mid-layer
1600 * @mpi_request: mpi request
1602 * @sge_count: scatter gather element count.
1604 * Returns: true: PRPs are built
1605 * false: IEEE SGLs needs to be built
1608 base_make_prp_nvme(struct MPT3SAS_ADAPTER
*ioc
,
1609 struct scsi_cmnd
*scmd
,
1610 Mpi25SCSIIORequest_t
*mpi_request
,
1611 u16 smid
, int sge_count
)
1613 int sge_len
, offset
, num_prp_in_chain
= 0;
1614 Mpi25IeeeSgeChain64_t
*main_chain_element
, *ptr_first_sgl
;
1616 dma_addr_t msg_phys
;
1618 u32 page_mask
, page_mask_result
;
1619 struct scatterlist
*sg_scmd
;
1621 int data_len
= scsi_bufflen(scmd
);
1624 nvme_pg_size
= max_t(u32
, ioc
->page_size
, NVME_PRP_PAGE_SIZE
);
1626 * Nvme has a very convoluted prp format. One prp is required
1627 * for each page or partial page. Driver need to split up OS sg_list
1628 * entries if it is longer than one page or cross a page
1629 * boundary. Driver also have to insert a PRP list pointer entry as
1630 * the last entry in each physical page of the PRP list.
1632 * NOTE: The first PRP "entry" is actually placed in the first
1633 * SGL entry in the main message as IEEE 64 format. The 2nd
1634 * entry in the main message is the chain element, and the rest
1635 * of the PRP entries are built in the contiguous pcie buffer.
1637 page_mask
= nvme_pg_size
- 1;
1640 * Native SGL is needed.
1641 * Put a chain element in main message frame that points to the first
1644 * NOTE: The ChainOffset field must be 0 when using a chain pointer to
1648 /* Set main message chain element pointer */
1649 main_chain_element
= (pMpi25IeeeSgeChain64_t
)&mpi_request
->SGL
;
1651 * For NVMe the chain element needs to be the 2nd SG entry in the main
1654 main_chain_element
= (Mpi25IeeeSgeChain64_t
*)
1655 ((u8
*)main_chain_element
+ sizeof(MPI25_IEEE_SGE_CHAIN64
));
1658 * For the PRP entries, use the specially allocated buffer of
1659 * contiguous memory. Normal chain buffers can't be used
1660 * because each chain buffer would need to be the size of an OS
1663 curr_buff
= mpt3sas_base_get_pcie_sgl(ioc
, smid
);
1664 msg_phys
= (dma_addr_t
)mpt3sas_base_get_pcie_sgl_dma(ioc
, smid
);
1666 main_chain_element
->Address
= cpu_to_le64(msg_phys
);
1667 main_chain_element
->NextChainOffset
= 0;
1668 main_chain_element
->Flags
= MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
1669 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
|
1670 MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP
;
1672 /* Build first prp, sge need not to be page aligned*/
1673 ptr_first_sgl
= (pMpi25IeeeSgeChain64_t
)&mpi_request
->SGL
;
1674 sg_scmd
= scsi_sglist(scmd
);
1675 sge_addr
= sg_dma_address(sg_scmd
);
1676 sge_len
= sg_dma_len(sg_scmd
);
1678 offset
= (u32
)(sge_addr
& page_mask
);
1679 first_prp_len
= nvme_pg_size
- offset
;
1681 ptr_first_sgl
->Address
= cpu_to_le64(sge_addr
);
1682 ptr_first_sgl
->Length
= cpu_to_le32(first_prp_len
);
1684 data_len
-= first_prp_len
;
1686 if (sge_len
> first_prp_len
) {
1687 sge_addr
+= first_prp_len
;
1688 sge_len
-= first_prp_len
;
1689 } else if (data_len
&& (sge_len
== first_prp_len
)) {
1690 sg_scmd
= sg_next(sg_scmd
);
1691 sge_addr
= sg_dma_address(sg_scmd
);
1692 sge_len
= sg_dma_len(sg_scmd
);
1696 offset
= (u32
)(sge_addr
& page_mask
);
1698 /* Put PRP pointer due to page boundary*/
1699 page_mask_result
= (uintptr_t)(curr_buff
+ 1) & page_mask
;
1700 if (unlikely(!page_mask_result
)) {
1701 scmd_printk(KERN_NOTICE
,
1702 scmd
, "page boundary curr_buff: 0x%p\n",
1705 *curr_buff
= cpu_to_le64(msg_phys
);
1710 *curr_buff
= cpu_to_le64(sge_addr
);
1715 sge_addr
+= nvme_pg_size
;
1716 sge_len
-= nvme_pg_size
;
1717 data_len
-= nvme_pg_size
;
1725 sg_scmd
= sg_next(sg_scmd
);
1726 sge_addr
= sg_dma_address(sg_scmd
);
1727 sge_len
= sg_dma_len(sg_scmd
);
1730 main_chain_element
->Length
=
1731 cpu_to_le32(num_prp_in_chain
* sizeof(u64
));
1736 base_is_prp_possible(struct MPT3SAS_ADAPTER
*ioc
,
1737 struct _pcie_device
*pcie_device
, struct scsi_cmnd
*scmd
, int sge_count
)
1739 u32 data_length
= 0;
1740 struct scatterlist
*sg_scmd
;
1741 bool build_prp
= true;
1743 data_length
= cpu_to_le32(scsi_bufflen(scmd
));
1744 sg_scmd
= scsi_sglist(scmd
);
1746 /* If Datalenth is <= 16K and number of SGE’s entries are <= 2
1749 if ((data_length
<= NVME_PRP_PAGE_SIZE
*4) && (sge_count
<= 2))
1756 * _base_check_pcie_native_sgl - This function is called for PCIe end devices to
1757 * determine if the driver needs to build a native SGL. If so, that native
1758 * SGL is built in the special contiguous buffers allocated especially for
1759 * PCIe SGL creation. If the driver will not build a native SGL, return
1760 * TRUE and a normal IEEE SGL will be built. Currently this routine
1762 * @ioc: per adapter object
1763 * @mpi_request: mf request pointer
1764 * @smid: system request message index
1765 * @scmd: scsi command
1766 * @pcie_device: points to the PCIe device's info
1768 * Returns 0 if native SGL was built, 1 if no SGL was built
1771 _base_check_pcie_native_sgl(struct MPT3SAS_ADAPTER
*ioc
,
1772 Mpi25SCSIIORequest_t
*mpi_request
, u16 smid
, struct scsi_cmnd
*scmd
,
1773 struct _pcie_device
*pcie_device
)
1775 struct scatterlist
*sg_scmd
;
1778 /* Get the SG list pointer and info. */
1779 sg_scmd
= scsi_sglist(scmd
);
1780 sges_left
= scsi_dma_map(scmd
);
1781 if (sges_left
< 0) {
1782 sdev_printk(KERN_ERR
, scmd
->device
,
1783 "scsi_dma_map failed: request for %d bytes!\n",
1784 scsi_bufflen(scmd
));
1788 /* Check if we need to build a native SG list. */
1789 if (base_is_prp_possible(ioc
, pcie_device
,
1790 scmd
, sges_left
) == 0) {
1791 /* We built a native SG list, just return. */
1796 * Build native NVMe PRP.
1798 base_make_prp_nvme(ioc
, scmd
, mpi_request
,
1803 scsi_dma_unmap(scmd
);
1808 * _base_add_sg_single_ieee - add sg element for IEEE format
1809 * @paddr: virtual address for SGE
1811 * @chain_offset: number of 128 byte elements from start of segment
1812 * @length: data transfer length
1813 * @dma_addr: Physical address
1818 _base_add_sg_single_ieee(void *paddr
, u8 flags
, u8 chain_offset
, u32 length
,
1819 dma_addr_t dma_addr
)
1821 Mpi25IeeeSgeChain64_t
*sgel
= paddr
;
1823 sgel
->Flags
= flags
;
1824 sgel
->NextChainOffset
= chain_offset
;
1825 sgel
->Length
= cpu_to_le32(length
);
1826 sgel
->Address
= cpu_to_le64(dma_addr
);
1830 * _base_build_zero_len_sge_ieee - build zero length sg entry for IEEE format
1831 * @ioc: per adapter object
1832 * @paddr: virtual address for SGE
1834 * Create a zero length scatter gather entry to insure the IOCs hardware has
1835 * something to use if the target device goes brain dead and tries
1836 * to send data even when none is asked for.
1841 _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1843 u8 sgl_flags
= (MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1844 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
|
1845 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
);
1847 _base_add_sg_single_ieee(paddr
, sgl_flags
, 0, 0, -1);
1851 * _base_build_sg_scmd - main sg creation routine
1852 * pcie_device is unused here!
1853 * @ioc: per adapter object
1854 * @scmd: scsi command
1855 * @smid: system request message index
1856 * @unused: unused pcie_device pointer
1859 * The main routine that builds scatter gather table from a given
1860 * scsi request sent via the .queuecommand main handler.
1862 * Returns 0 success, anything else error
1865 _base_build_sg_scmd(struct MPT3SAS_ADAPTER
*ioc
,
1866 struct scsi_cmnd
*scmd
, u16 smid
, struct _pcie_device
*unused
)
1868 Mpi2SCSIIORequest_t
*mpi_request
;
1869 dma_addr_t chain_dma
;
1870 struct scatterlist
*sg_scmd
;
1871 void *sg_local
, *chain
;
1876 u32 sges_in_segment
;
1878 u32 sgl_flags_last_element
;
1879 u32 sgl_flags_end_buffer
;
1880 struct chain_tracker
*chain_req
;
1882 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1884 /* init scatter gather flags */
1885 sgl_flags
= MPI2_SGE_FLAGS_SIMPLE_ELEMENT
;
1886 if (scmd
->sc_data_direction
== DMA_TO_DEVICE
)
1887 sgl_flags
|= MPI2_SGE_FLAGS_HOST_TO_IOC
;
1888 sgl_flags_last_element
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
)
1889 << MPI2_SGE_FLAGS_SHIFT
;
1890 sgl_flags_end_buffer
= (sgl_flags
| MPI2_SGE_FLAGS_LAST_ELEMENT
|
1891 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
)
1892 << MPI2_SGE_FLAGS_SHIFT
;
1893 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1895 sg_scmd
= scsi_sglist(scmd
);
1896 sges_left
= scsi_dma_map(scmd
);
1897 if (sges_left
< 0) {
1898 sdev_printk(KERN_ERR
, scmd
->device
,
1899 "pci_map_sg failed: request for %d bytes!\n",
1900 scsi_bufflen(scmd
));
1904 sg_local
= &mpi_request
->SGL
;
1905 sges_in_segment
= ioc
->max_sges_in_main_message
;
1906 if (sges_left
<= sges_in_segment
)
1907 goto fill_in_last_segment
;
1909 mpi_request
->ChainOffset
= (offsetof(Mpi2SCSIIORequest_t
, SGL
) +
1910 (sges_in_segment
* ioc
->sge_size
))/4;
1912 /* fill in main message segment when there is a chain following */
1913 while (sges_in_segment
) {
1914 if (sges_in_segment
== 1)
1915 ioc
->base_add_sg_single(sg_local
,
1916 sgl_flags_last_element
| sg_dma_len(sg_scmd
),
1917 sg_dma_address(sg_scmd
));
1919 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1920 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1921 sg_scmd
= sg_next(sg_scmd
);
1922 sg_local
+= ioc
->sge_size
;
1927 /* initializing the chain flags and pointers */
1928 chain_flags
= MPI2_SGE_FLAGS_CHAIN_ELEMENT
<< MPI2_SGE_FLAGS_SHIFT
;
1929 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1932 chain
= chain_req
->chain_buffer
;
1933 chain_dma
= chain_req
->chain_buffer_dma
;
1935 sges_in_segment
= (sges_left
<=
1936 ioc
->max_sges_in_chain_message
) ? sges_left
:
1937 ioc
->max_sges_in_chain_message
;
1938 chain_offset
= (sges_left
== sges_in_segment
) ?
1939 0 : (sges_in_segment
* ioc
->sge_size
)/4;
1940 chain_length
= sges_in_segment
* ioc
->sge_size
;
1942 chain_offset
= chain_offset
<<
1943 MPI2_SGE_CHAIN_OFFSET_SHIFT
;
1944 chain_length
+= ioc
->sge_size
;
1946 ioc
->base_add_sg_single(sg_local
, chain_flags
| chain_offset
|
1947 chain_length
, chain_dma
);
1950 goto fill_in_last_segment
;
1952 /* fill in chain segments */
1953 while (sges_in_segment
) {
1954 if (sges_in_segment
== 1)
1955 ioc
->base_add_sg_single(sg_local
,
1956 sgl_flags_last_element
|
1957 sg_dma_len(sg_scmd
),
1958 sg_dma_address(sg_scmd
));
1960 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1961 sg_dma_len(sg_scmd
),
1962 sg_dma_address(sg_scmd
));
1963 sg_scmd
= sg_next(sg_scmd
);
1964 sg_local
+= ioc
->sge_size
;
1969 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1972 chain
= chain_req
->chain_buffer
;
1973 chain_dma
= chain_req
->chain_buffer_dma
;
1977 fill_in_last_segment
:
1979 /* fill the last segment */
1982 ioc
->base_add_sg_single(sg_local
, sgl_flags_end_buffer
|
1983 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1985 ioc
->base_add_sg_single(sg_local
, sgl_flags
|
1986 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1987 sg_scmd
= sg_next(sg_scmd
);
1988 sg_local
+= ioc
->sge_size
;
1996 * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format
1997 * @ioc: per adapter object
1998 * @scmd: scsi command
1999 * @smid: system request message index
2000 * @pcie_device: Pointer to pcie_device. If set, the pcie native sgl will be
2001 * constructed on need.
2004 * The main routine that builds scatter gather table from a given
2005 * scsi request sent via the .queuecommand main handler.
2007 * Returns 0 success, anything else error
2010 _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER
*ioc
,
2011 struct scsi_cmnd
*scmd
, u16 smid
, struct _pcie_device
*pcie_device
)
2013 Mpi25SCSIIORequest_t
*mpi_request
;
2014 dma_addr_t chain_dma
;
2015 struct scatterlist
*sg_scmd
;
2016 void *sg_local
, *chain
;
2020 u32 sges_in_segment
;
2021 u8 simple_sgl_flags
;
2022 u8 simple_sgl_flags_last
;
2024 struct chain_tracker
*chain_req
;
2026 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2028 /* init scatter gather flags */
2029 simple_sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
2030 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
2031 simple_sgl_flags_last
= simple_sgl_flags
|
2032 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
2033 chain_sgl_flags
= MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
2034 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
2036 /* Check if we need to build a native SG list. */
2037 if ((pcie_device
) && (_base_check_pcie_native_sgl(ioc
, mpi_request
,
2038 smid
, scmd
, pcie_device
) == 0)) {
2039 /* We built a native SG list, just return. */
2043 sg_scmd
= scsi_sglist(scmd
);
2044 sges_left
= scsi_dma_map(scmd
);
2045 if (sges_left
< 0) {
2046 sdev_printk(KERN_ERR
, scmd
->device
,
2047 "pci_map_sg failed: request for %d bytes!\n",
2048 scsi_bufflen(scmd
));
2052 sg_local
= &mpi_request
->SGL
;
2053 sges_in_segment
= (ioc
->request_sz
-
2054 offsetof(Mpi25SCSIIORequest_t
, SGL
))/ioc
->sge_size_ieee
;
2055 if (sges_left
<= sges_in_segment
)
2056 goto fill_in_last_segment
;
2058 mpi_request
->ChainOffset
= (sges_in_segment
- 1 /* chain element */) +
2059 (offsetof(Mpi25SCSIIORequest_t
, SGL
)/ioc
->sge_size_ieee
);
2061 /* fill in main message segment when there is a chain following */
2062 while (sges_in_segment
> 1) {
2063 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
2064 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
2065 sg_scmd
= sg_next(sg_scmd
);
2066 sg_local
+= ioc
->sge_size_ieee
;
2071 /* initializing the pointers */
2072 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
2075 chain
= chain_req
->chain_buffer
;
2076 chain_dma
= chain_req
->chain_buffer_dma
;
2078 sges_in_segment
= (sges_left
<=
2079 ioc
->max_sges_in_chain_message
) ? sges_left
:
2080 ioc
->max_sges_in_chain_message
;
2081 chain_offset
= (sges_left
== sges_in_segment
) ?
2082 0 : sges_in_segment
;
2083 chain_length
= sges_in_segment
* ioc
->sge_size_ieee
;
2085 chain_length
+= ioc
->sge_size_ieee
;
2086 _base_add_sg_single_ieee(sg_local
, chain_sgl_flags
,
2087 chain_offset
, chain_length
, chain_dma
);
2091 goto fill_in_last_segment
;
2093 /* fill in chain segments */
2094 while (sges_in_segment
) {
2095 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
2096 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
2097 sg_scmd
= sg_next(sg_scmd
);
2098 sg_local
+= ioc
->sge_size_ieee
;
2103 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
2106 chain
= chain_req
->chain_buffer
;
2107 chain_dma
= chain_req
->chain_buffer_dma
;
2111 fill_in_last_segment
:
2113 /* fill the last segment */
2114 while (sges_left
> 0) {
2116 _base_add_sg_single_ieee(sg_local
,
2117 simple_sgl_flags_last
, 0, sg_dma_len(sg_scmd
),
2118 sg_dma_address(sg_scmd
));
2120 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
2121 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
2122 sg_scmd
= sg_next(sg_scmd
);
2123 sg_local
+= ioc
->sge_size_ieee
;
2131 * _base_build_sg_ieee - build generic sg for IEEE format
2132 * @ioc: per adapter object
2133 * @psge: virtual address for SGE
2134 * @data_out_dma: physical address for WRITES
2135 * @data_out_sz: data xfer size for WRITES
2136 * @data_in_dma: physical address for READS
2137 * @data_in_sz: data xfer size for READS
2142 _base_build_sg_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
2143 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
2148 if (!data_out_sz
&& !data_in_sz
) {
2149 _base_build_zero_len_sge_ieee(ioc
, psge
);
2153 if (data_out_sz
&& data_in_sz
) {
2154 /* WRITE sgel first */
2155 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
2156 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
2157 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
2161 psge
+= ioc
->sge_size_ieee
;
2163 /* READ sgel last */
2164 sgl_flags
|= MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
2165 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
2167 } else if (data_out_sz
) /* WRITE */ {
2168 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
2169 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
2170 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
2171 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
2173 } else if (data_in_sz
) /* READ */ {
2174 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
2175 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
2176 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
2177 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
2182 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
2185 * _base_config_dma_addressing - set dma addressing
2186 * @ioc: per adapter object
2187 * @pdev: PCI device struct
2189 * Returns 0 for success, non-zero for failure.
2192 _base_config_dma_addressing(struct MPT3SAS_ADAPTER
*ioc
, struct pci_dev
*pdev
)
2195 u64 consistent_dma_mask
;
2198 consistent_dma_mask
= DMA_BIT_MASK(64);
2200 consistent_dma_mask
= DMA_BIT_MASK(32);
2202 if (sizeof(dma_addr_t
) > 4) {
2203 const uint64_t required_mask
=
2204 dma_get_required_mask(&pdev
->dev
);
2205 if ((required_mask
> DMA_BIT_MASK(32)) &&
2206 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
2207 !pci_set_consistent_dma_mask(pdev
, consistent_dma_mask
)) {
2208 ioc
->base_add_sg_single
= &_base_add_sg_single_64
;
2209 ioc
->sge_size
= sizeof(Mpi2SGESimple64_t
);
2215 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
2216 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
2217 ioc
->base_add_sg_single
= &_base_add_sg_single_32
;
2218 ioc
->sge_size
= sizeof(Mpi2SGESimple32_t
);
2226 "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
2227 ioc
->name
, ioc
->dma_mask
, convert_to_kb(s
.totalram
));
2233 _base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER
*ioc
,
2234 struct pci_dev
*pdev
)
2236 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
2237 if (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)))
2244 * _base_check_enable_msix - checks MSIX capabable.
2245 * @ioc: per adapter object
2247 * Check to see if card is capable of MSIX, and set number
2248 * of available msix vectors
2251 _base_check_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
2254 u16 message_control
;
2256 /* Check whether controller SAS2008 B0 controller,
2257 * if it is SAS2008 B0 controller use IO-APIC instead of MSIX
2259 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
&&
2260 ioc
->pdev
->revision
== SAS2_PCI_DEVICE_B0_REVISION
) {
2264 base
= pci_find_capability(ioc
->pdev
, PCI_CAP_ID_MSIX
);
2266 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
"msix not supported\n",
2271 /* get msix vector count */
2272 /* NUMA_IO not supported for older controllers */
2273 if (ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2004
||
2274 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2008
||
2275 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_1
||
2276 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_2
||
2277 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2108_3
||
2278 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_1
||
2279 ioc
->pdev
->device
== MPI2_MFGPAGE_DEVID_SAS2116_2
)
2280 ioc
->msix_vector_count
= 1;
2282 pci_read_config_word(ioc
->pdev
, base
+ 2, &message_control
);
2283 ioc
->msix_vector_count
= (message_control
& 0x3FF) + 1;
2285 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2286 "msix is supported, vector_count(%d)\n",
2287 ioc
->name
, ioc
->msix_vector_count
));
2292 * _base_free_irq - free irq
2293 * @ioc: per adapter object
2295 * Freeing respective reply_queue from the list.
2298 _base_free_irq(struct MPT3SAS_ADAPTER
*ioc
)
2300 struct adapter_reply_queue
*reply_q
, *next
;
2302 if (list_empty(&ioc
->reply_queue_list
))
2305 list_for_each_entry_safe(reply_q
, next
, &ioc
->reply_queue_list
, list
) {
2306 list_del(&reply_q
->list
);
2307 free_irq(pci_irq_vector(ioc
->pdev
, reply_q
->msix_index
),
2314 * _base_request_irq - request irq
2315 * @ioc: per adapter object
2316 * @index: msix index into vector table
2318 * Inserting respective reply_queue into the list.
2321 _base_request_irq(struct MPT3SAS_ADAPTER
*ioc
, u8 index
)
2323 struct pci_dev
*pdev
= ioc
->pdev
;
2324 struct adapter_reply_queue
*reply_q
;
2327 reply_q
= kzalloc(sizeof(struct adapter_reply_queue
), GFP_KERNEL
);
2329 pr_err(MPT3SAS_FMT
"unable to allocate memory %d!\n",
2330 ioc
->name
, (int)sizeof(struct adapter_reply_queue
));
2334 reply_q
->msix_index
= index
;
2336 atomic_set(&reply_q
->busy
, 0);
2337 if (ioc
->msix_enable
)
2338 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d-msix%d",
2339 ioc
->driver_name
, ioc
->id
, index
);
2341 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d",
2342 ioc
->driver_name
, ioc
->id
);
2343 r
= request_irq(pci_irq_vector(pdev
, index
), _base_interrupt
,
2344 IRQF_SHARED
, reply_q
->name
, reply_q
);
2346 pr_err(MPT3SAS_FMT
"unable to allocate interrupt %d!\n",
2347 reply_q
->name
, pci_irq_vector(pdev
, index
));
2352 INIT_LIST_HEAD(&reply_q
->list
);
2353 list_add_tail(&reply_q
->list
, &ioc
->reply_queue_list
);
2358 * _base_assign_reply_queues - assigning msix index for each cpu
2359 * @ioc: per adapter object
2361 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
2363 * It would nice if we could call irq_set_affinity, however it is not
2364 * an exported symbol
2367 _base_assign_reply_queues(struct MPT3SAS_ADAPTER
*ioc
)
2369 unsigned int cpu
, nr_cpus
, nr_msix
, index
= 0;
2370 struct adapter_reply_queue
*reply_q
;
2372 if (!_base_is_controller_msix_enabled(ioc
))
2375 memset(ioc
->cpu_msix_table
, 0, ioc
->cpu_msix_table_sz
);
2377 nr_cpus
= num_online_cpus();
2378 nr_msix
= ioc
->reply_queue_count
= min(ioc
->reply_queue_count
,
2379 ioc
->facts
.MaxMSIxVectors
);
2383 if (smp_affinity_enable
) {
2384 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
2385 const cpumask_t
*mask
= pci_irq_get_affinity(ioc
->pdev
,
2386 reply_q
->msix_index
);
2388 pr_warn(MPT3SAS_FMT
"no affinity for msi %x\n",
2389 ioc
->name
, reply_q
->msix_index
);
2393 for_each_cpu(cpu
, mask
)
2394 ioc
->cpu_msix_table
[cpu
] = reply_q
->msix_index
;
2398 cpu
= cpumask_first(cpu_online_mask
);
2400 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
2402 unsigned int i
, group
= nr_cpus
/ nr_msix
;
2407 if (index
< nr_cpus
% nr_msix
)
2410 for (i
= 0 ; i
< group
; i
++) {
2411 ioc
->cpu_msix_table
[cpu
] = reply_q
->msix_index
;
2412 cpu
= cpumask_next(cpu
, cpu_online_mask
);
2419 * _base_disable_msix - disables msix
2420 * @ioc: per adapter object
2424 _base_disable_msix(struct MPT3SAS_ADAPTER
*ioc
)
2426 if (!ioc
->msix_enable
)
2428 pci_disable_msix(ioc
->pdev
);
2429 ioc
->msix_enable
= 0;
2433 * _base_enable_msix - enables msix, failback to io_apic
2434 * @ioc: per adapter object
2438 _base_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
2441 int i
, local_max_msix_vectors
;
2443 unsigned int irq_flags
= PCI_IRQ_MSIX
;
2445 if (msix_disable
== -1 || msix_disable
== 0)
2451 if (_base_check_enable_msix(ioc
) != 0)
2454 ioc
->reply_queue_count
= min_t(int, ioc
->cpu_count
,
2455 ioc
->msix_vector_count
);
2457 printk(MPT3SAS_FMT
"MSI-X vectors supported: %d, no of cores"
2458 ": %d, max_msix_vectors: %d\n", ioc
->name
, ioc
->msix_vector_count
,
2459 ioc
->cpu_count
, max_msix_vectors
);
2461 if (!ioc
->rdpq_array_enable
&& max_msix_vectors
== -1)
2462 local_max_msix_vectors
= (reset_devices
) ? 1 : 8;
2464 local_max_msix_vectors
= max_msix_vectors
;
2466 if (local_max_msix_vectors
> 0)
2467 ioc
->reply_queue_count
= min_t(int, local_max_msix_vectors
,
2468 ioc
->reply_queue_count
);
2469 else if (local_max_msix_vectors
== 0)
2472 if (ioc
->msix_vector_count
< ioc
->cpu_count
)
2473 smp_affinity_enable
= 0;
2475 if (smp_affinity_enable
)
2476 irq_flags
|= PCI_IRQ_AFFINITY
;
2478 r
= pci_alloc_irq_vectors(ioc
->pdev
, 1, ioc
->reply_queue_count
,
2481 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
2482 "pci_alloc_irq_vectors failed (r=%d) !!!\n",
2487 ioc
->msix_enable
= 1;
2488 ioc
->reply_queue_count
= r
;
2489 for (i
= 0; i
< ioc
->reply_queue_count
; i
++) {
2490 r
= _base_request_irq(ioc
, i
);
2492 _base_free_irq(ioc
);
2493 _base_disable_msix(ioc
);
2500 /* failback to io_apic interrupt routing */
2503 ioc
->reply_queue_count
= 1;
2504 r
= pci_alloc_irq_vectors(ioc
->pdev
, 1, 1, PCI_IRQ_LEGACY
);
2506 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
2507 "pci_alloc_irq_vector(legacy) failed (r=%d) !!!\n",
2510 r
= _base_request_irq(ioc
, 0);
2516 * mpt3sas_base_unmap_resources - free controller resources
2517 * @ioc: per adapter object
2520 mpt3sas_base_unmap_resources(struct MPT3SAS_ADAPTER
*ioc
)
2522 struct pci_dev
*pdev
= ioc
->pdev
;
2524 dexitprintk(ioc
, printk(MPT3SAS_FMT
"%s\n",
2525 ioc
->name
, __func__
));
2527 _base_free_irq(ioc
);
2528 _base_disable_msix(ioc
);
2530 if (ioc
->combined_reply_queue
) {
2531 kfree(ioc
->replyPostRegisterIndex
);
2532 ioc
->replyPostRegisterIndex
= NULL
;
2535 if (ioc
->chip_phys
) {
2540 if (pci_is_enabled(pdev
)) {
2541 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
2542 pci_disable_pcie_error_reporting(pdev
);
2543 pci_disable_device(pdev
);
2548 * mpt3sas_base_map_resources - map in controller resources (io/irq/memap)
2549 * @ioc: per adapter object
2551 * Returns 0 for success, non-zero for failure.
2554 mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER
*ioc
)
2556 struct pci_dev
*pdev
= ioc
->pdev
;
2562 struct adapter_reply_queue
*reply_q
;
2564 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n",
2565 ioc
->name
, __func__
));
2567 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
2568 if (pci_enable_device_mem(pdev
)) {
2569 pr_warn(MPT3SAS_FMT
"pci_enable_device_mem: failed\n",
2576 if (pci_request_selected_regions(pdev
, ioc
->bars
,
2577 ioc
->driver_name
)) {
2578 pr_warn(MPT3SAS_FMT
"pci_request_selected_regions: failed\n",
2585 /* AER (Advanced Error Reporting) hooks */
2586 pci_enable_pcie_error_reporting(pdev
);
2588 pci_set_master(pdev
);
2591 if (_base_config_dma_addressing(ioc
, pdev
) != 0) {
2592 pr_warn(MPT3SAS_FMT
"no suitable DMA mask for %s\n",
2593 ioc
->name
, pci_name(pdev
));
2598 for (i
= 0, memap_sz
= 0, pio_sz
= 0; (i
< DEVICE_COUNT_RESOURCE
) &&
2599 (!memap_sz
|| !pio_sz
); i
++) {
2600 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
2603 pio_chip
= (u64
)pci_resource_start(pdev
, i
);
2604 pio_sz
= pci_resource_len(pdev
, i
);
2605 } else if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
2608 ioc
->chip_phys
= pci_resource_start(pdev
, i
);
2609 chip_phys
= (u64
)ioc
->chip_phys
;
2610 memap_sz
= pci_resource_len(pdev
, i
);
2611 ioc
->chip
= ioremap(ioc
->chip_phys
, memap_sz
);
2615 if (ioc
->chip
== NULL
) {
2616 pr_err(MPT3SAS_FMT
"unable to map adapter memory! "
2617 " or resource not found\n", ioc
->name
);
2622 _base_mask_interrupts(ioc
);
2624 r
= _base_get_ioc_facts(ioc
);
2628 if (!ioc
->rdpq_array_enable_assigned
) {
2629 ioc
->rdpq_array_enable
= ioc
->rdpq_array_capable
;
2630 ioc
->rdpq_array_enable_assigned
= 1;
2633 r
= _base_enable_msix(ioc
);
2637 /* Use the Combined reply queue feature only for SAS3 C0 & higher
2638 * revision HBAs and also only when reply queue count is greater than 8
2640 if (ioc
->combined_reply_queue
&& ioc
->reply_queue_count
> 8) {
2641 /* Determine the Supplemental Reply Post Host Index Registers
2642 * Addresse. Supplemental Reply Post Host Index Registers
2643 * starts at offset MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET and
2644 * each register is at offset bytes of
2645 * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET from previous one.
2647 ioc
->replyPostRegisterIndex
= kcalloc(
2648 ioc
->combined_reply_index_count
,
2649 sizeof(resource_size_t
*), GFP_KERNEL
);
2650 if (!ioc
->replyPostRegisterIndex
) {
2651 dfailprintk(ioc
, printk(MPT3SAS_FMT
2652 "allocation for reply Post Register Index failed!!!\n",
2658 for (i
= 0; i
< ioc
->combined_reply_index_count
; i
++) {
2659 ioc
->replyPostRegisterIndex
[i
] = (resource_size_t
*)
2660 ((u8
*)&ioc
->chip
->Doorbell
+
2661 MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET
+
2662 (i
* MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET
));
2665 ioc
->combined_reply_queue
= 0;
2667 if (ioc
->is_warpdrive
) {
2668 ioc
->reply_post_host_index
[0] = (resource_size_t __iomem
*)
2669 &ioc
->chip
->ReplyPostHostIndex
;
2671 for (i
= 1; i
< ioc
->cpu_msix_table_sz
; i
++)
2672 ioc
->reply_post_host_index
[i
] =
2673 (resource_size_t __iomem
*)
2674 ((u8 __iomem
*)&ioc
->chip
->Doorbell
+ (0x4000 + ((i
- 1)
2678 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
)
2679 pr_info(MPT3SAS_FMT
"%s: IRQ %d\n",
2680 reply_q
->name
, ((ioc
->msix_enable
) ? "PCI-MSI-X enabled" :
2682 pci_irq_vector(ioc
->pdev
, reply_q
->msix_index
));
2684 pr_info(MPT3SAS_FMT
"iomem(0x%016llx), mapped(0x%p), size(%d)\n",
2685 ioc
->name
, (unsigned long long)chip_phys
, ioc
->chip
, memap_sz
);
2686 pr_info(MPT3SAS_FMT
"ioport(0x%016llx), size(%d)\n",
2687 ioc
->name
, (unsigned long long)pio_chip
, pio_sz
);
2689 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
2690 pci_save_state(pdev
);
2694 mpt3sas_base_unmap_resources(ioc
);
2699 * mpt3sas_base_get_msg_frame - obtain request mf pointer
2700 * @ioc: per adapter object
2701 * @smid: system request message index(smid zero is invalid)
2703 * Returns virt pointer to message frame.
2706 mpt3sas_base_get_msg_frame(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2708 return (void *)(ioc
->request
+ (smid
* ioc
->request_sz
));
2712 * mpt3sas_base_get_sense_buffer - obtain a sense buffer virt addr
2713 * @ioc: per adapter object
2714 * @smid: system request message index
2716 * Returns virt pointer to sense buffer.
2719 mpt3sas_base_get_sense_buffer(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2721 return (void *)(ioc
->sense
+ ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
2725 * mpt3sas_base_get_sense_buffer_dma - obtain a sense buffer dma addr
2726 * @ioc: per adapter object
2727 * @smid: system request message index
2729 * Returns phys pointer to the low 32bit address of the sense buffer.
2732 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2734 return cpu_to_le32(ioc
->sense_dma
+ ((smid
- 1) *
2735 SCSI_SENSE_BUFFERSIZE
));
2739 * mpt3sas_base_get_pcie_sgl - obtain a PCIe SGL virt addr
2740 * @ioc: per adapter object
2741 * @smid: system request message index
2743 * Returns virt pointer to a PCIe SGL.
2746 mpt3sas_base_get_pcie_sgl(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2748 return (void *)(ioc
->scsi_lookup
[smid
- 1].pcie_sg_list
.pcie_sgl
);
2752 * mpt3sas_base_get_pcie_sgl_dma - obtain a PCIe SGL dma addr
2753 * @ioc: per adapter object
2754 * @smid: system request message index
2756 * Returns phys pointer to the address of the PCIe buffer.
2759 mpt3sas_base_get_pcie_sgl_dma(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2761 return (void *)(uintptr_t)
2762 (ioc
->scsi_lookup
[smid
- 1].pcie_sg_list
.pcie_sgl_dma
);
2766 * mpt3sas_base_get_reply_virt_addr - obtain reply frames virt address
2767 * @ioc: per adapter object
2768 * @phys_addr: lower 32 physical addr of the reply
2770 * Converts 32bit lower physical addr into a virt address.
2773 mpt3sas_base_get_reply_virt_addr(struct MPT3SAS_ADAPTER
*ioc
, u32 phys_addr
)
2777 return ioc
->reply
+ (phys_addr
- (u32
)ioc
->reply_dma
);
2781 _base_get_msix_index(struct MPT3SAS_ADAPTER
*ioc
)
2783 return ioc
->cpu_msix_table
[raw_smp_processor_id()];
2787 * mpt3sas_base_get_smid - obtain a free smid from internal queue
2788 * @ioc: per adapter object
2789 * @cb_idx: callback index
2791 * Returns smid (zero is invalid)
2794 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
2796 unsigned long flags
;
2797 struct request_tracker
*request
;
2800 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2801 if (list_empty(&ioc
->internal_free_list
)) {
2802 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2803 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
2804 ioc
->name
, __func__
);
2808 request
= list_entry(ioc
->internal_free_list
.next
,
2809 struct request_tracker
, tracker_list
);
2810 request
->cb_idx
= cb_idx
;
2811 smid
= request
->smid
;
2812 list_del(&request
->tracker_list
);
2813 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2818 * mpt3sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
2819 * @ioc: per adapter object
2820 * @cb_idx: callback index
2821 * @scmd: pointer to scsi command object
2823 * Returns smid (zero is invalid)
2826 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
,
2827 struct scsi_cmnd
*scmd
)
2829 unsigned long flags
;
2830 struct scsiio_tracker
*request
;
2833 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2834 if (list_empty(&ioc
->free_list
)) {
2835 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2836 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
2837 ioc
->name
, __func__
);
2841 request
= list_entry(ioc
->free_list
.next
,
2842 struct scsiio_tracker
, tracker_list
);
2843 request
->scmd
= scmd
;
2844 request
->cb_idx
= cb_idx
;
2845 smid
= request
->smid
;
2846 request
->msix_io
= _base_get_msix_index(ioc
);
2847 list_del(&request
->tracker_list
);
2848 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2853 * mpt3sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
2854 * @ioc: per adapter object
2855 * @cb_idx: callback index
2857 * Returns smid (zero is invalid)
2860 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
2862 unsigned long flags
;
2863 struct request_tracker
*request
;
2866 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2867 if (list_empty(&ioc
->hpr_free_list
)) {
2868 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2872 request
= list_entry(ioc
->hpr_free_list
.next
,
2873 struct request_tracker
, tracker_list
);
2874 request
->cb_idx
= cb_idx
;
2875 smid
= request
->smid
;
2876 list_del(&request
->tracker_list
);
2877 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2882 * mpt3sas_base_free_smid - put smid back on free_list
2883 * @ioc: per adapter object
2884 * @smid: system request message index
2889 mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2891 unsigned long flags
;
2893 struct chain_tracker
*chain_req
, *next
;
2895 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2896 if (smid
< ioc
->hi_priority_smid
) {
2899 if (!list_empty(&ioc
->scsi_lookup
[i
].chain_list
)) {
2900 list_for_each_entry_safe(chain_req
, next
,
2901 &ioc
->scsi_lookup
[i
].chain_list
, tracker_list
) {
2902 list_del_init(&chain_req
->tracker_list
);
2903 list_add(&chain_req
->tracker_list
,
2904 &ioc
->free_chain_list
);
2907 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
2908 ioc
->scsi_lookup
[i
].scmd
= NULL
;
2909 ioc
->scsi_lookup
[i
].direct_io
= 0;
2910 list_add(&ioc
->scsi_lookup
[i
].tracker_list
, &ioc
->free_list
);
2911 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2914 * See _wait_for_commands_to_complete() call with regards
2917 if (ioc
->shost_recovery
&& ioc
->pending_io_count
) {
2918 if (ioc
->pending_io_count
== 1)
2919 wake_up(&ioc
->reset_wq
);
2920 ioc
->pending_io_count
--;
2923 } else if (smid
< ioc
->internal_smid
) {
2925 i
= smid
- ioc
->hi_priority_smid
;
2926 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
2927 list_add(&ioc
->hpr_lookup
[i
].tracker_list
, &ioc
->hpr_free_list
);
2928 } else if (smid
<= ioc
->hba_queue_depth
) {
2929 /* internal queue */
2930 i
= smid
- ioc
->internal_smid
;
2931 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
2932 list_add(&ioc
->internal_lookup
[i
].tracker_list
,
2933 &ioc
->internal_free_list
);
2935 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2939 * _base_writeq - 64 bit write to MMIO
2940 * @ioc: per adapter object
2942 * @addr: address in MMIO space
2943 * @writeq_lock: spin lock
2945 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
2946 * care of 32 bit environment where its not quarenteed to send the entire word
2949 #if defined(writeq) && defined(CONFIG_64BIT)
2951 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2953 writeq(cpu_to_le64(b
), addr
);
2957 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2959 unsigned long flags
;
2960 __u64 data_out
= cpu_to_le64(b
);
2962 spin_lock_irqsave(writeq_lock
, flags
);
2963 writel((u32
)(data_out
), addr
);
2964 writel((u32
)(data_out
>> 32), (addr
+ 4));
2965 spin_unlock_irqrestore(writeq_lock
, flags
);
2970 * _base_put_smid_scsi_io - send SCSI_IO request to firmware
2971 * @ioc: per adapter object
2972 * @smid: system request message index
2973 * @handle: device handle
2978 _base_put_smid_scsi_io(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 handle
)
2980 Mpi2RequestDescriptorUnion_t descriptor
;
2981 u64
*request
= (u64
*)&descriptor
;
2984 descriptor
.SCSIIO
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
2985 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
2986 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
2987 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
2988 descriptor
.SCSIIO
.LMID
= 0;
2989 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2990 &ioc
->scsi_lookup_lock
);
2994 * _base_put_smid_fast_path - send fast path request to firmware
2995 * @ioc: per adapter object
2996 * @smid: system request message index
2997 * @handle: device handle
3002 _base_put_smid_fast_path(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3005 Mpi2RequestDescriptorUnion_t descriptor
;
3006 u64
*request
= (u64
*)&descriptor
;
3008 descriptor
.SCSIIO
.RequestFlags
=
3009 MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO
;
3010 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
3011 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
3012 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
3013 descriptor
.SCSIIO
.LMID
= 0;
3014 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
3015 &ioc
->scsi_lookup_lock
);
3019 * _base_put_smid_hi_priority - send Task Management request to firmware
3020 * @ioc: per adapter object
3021 * @smid: system request message index
3022 * @msix_task: msix_task will be same as msix of IO incase of task abort else 0.
3026 _base_put_smid_hi_priority(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3029 Mpi2RequestDescriptorUnion_t descriptor
;
3030 u64
*request
= (u64
*)&descriptor
;
3032 descriptor
.HighPriority
.RequestFlags
=
3033 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
3034 descriptor
.HighPriority
.MSIxIndex
= msix_task
;
3035 descriptor
.HighPriority
.SMID
= cpu_to_le16(smid
);
3036 descriptor
.HighPriority
.LMID
= 0;
3037 descriptor
.HighPriority
.Reserved1
= 0;
3038 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
3039 &ioc
->scsi_lookup_lock
);
3043 * _base_put_smid_nvme_encap - send NVMe encapsulated request to
3045 * @ioc: per adapter object
3046 * @smid: system request message index
3051 _base_put_smid_nvme_encap(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3053 Mpi2RequestDescriptorUnion_t descriptor
;
3054 u64
*request
= (u64
*)&descriptor
;
3056 descriptor
.Default
.RequestFlags
=
3057 MPI26_REQ_DESCRIPT_FLAGS_PCIE_ENCAPSULATED
;
3058 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
3059 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
3060 descriptor
.Default
.LMID
= 0;
3061 descriptor
.Default
.DescriptorTypeDependent
= 0;
3062 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
3063 &ioc
->scsi_lookup_lock
);
3067 * _base_put_smid_default - Default, primarily used for config pages
3068 * @ioc: per adapter object
3069 * @smid: system request message index
3074 _base_put_smid_default(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3076 Mpi2RequestDescriptorUnion_t descriptor
;
3077 u64
*request
= (u64
*)&descriptor
;
3079 descriptor
.Default
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
3080 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
3081 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
3082 descriptor
.Default
.LMID
= 0;
3083 descriptor
.Default
.DescriptorTypeDependent
= 0;
3084 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
3085 &ioc
->scsi_lookup_lock
);
3089 * _base_put_smid_scsi_io_atomic - send SCSI_IO request to firmware using
3090 * Atomic Request Descriptor
3091 * @ioc: per adapter object
3092 * @smid: system request message index
3093 * @handle: device handle, unused in this function, for function type match
3098 _base_put_smid_scsi_io_atomic(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3101 Mpi26AtomicRequestDescriptor_t descriptor
;
3102 u32
*request
= (u32
*)&descriptor
;
3104 descriptor
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
3105 descriptor
.MSIxIndex
= _base_get_msix_index(ioc
);
3106 descriptor
.SMID
= cpu_to_le16(smid
);
3108 writel(cpu_to_le32(*request
), &ioc
->chip
->AtomicRequestDescriptorPost
);
3112 * _base_put_smid_fast_path_atomic - send fast path request to firmware
3113 * using Atomic Request Descriptor
3114 * @ioc: per adapter object
3115 * @smid: system request message index
3116 * @handle: device handle, unused in this function, for function type match
3120 _base_put_smid_fast_path_atomic(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3123 Mpi26AtomicRequestDescriptor_t descriptor
;
3124 u32
*request
= (u32
*)&descriptor
;
3126 descriptor
.RequestFlags
= MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO
;
3127 descriptor
.MSIxIndex
= _base_get_msix_index(ioc
);
3128 descriptor
.SMID
= cpu_to_le16(smid
);
3130 writel(cpu_to_le32(*request
), &ioc
->chip
->AtomicRequestDescriptorPost
);
3134 * _base_put_smid_hi_priority_atomic - send Task Management request to
3135 * firmware using Atomic Request Descriptor
3136 * @ioc: per adapter object
3137 * @smid: system request message index
3138 * @msix_task: msix_task will be same as msix of IO incase of task abort else 0
3143 _base_put_smid_hi_priority_atomic(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
3146 Mpi26AtomicRequestDescriptor_t descriptor
;
3147 u32
*request
= (u32
*)&descriptor
;
3149 descriptor
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
3150 descriptor
.MSIxIndex
= msix_task
;
3151 descriptor
.SMID
= cpu_to_le16(smid
);
3153 writel(cpu_to_le32(*request
), &ioc
->chip
->AtomicRequestDescriptorPost
);
3157 * _base_put_smid_nvme_encap_atomic - send NVMe encapsulated request to
3158 * firmware using Atomic Request Descriptor
3159 * @ioc: per adapter object
3160 * @smid: system request message index
3165 _base_put_smid_nvme_encap_atomic(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3167 Mpi26AtomicRequestDescriptor_t descriptor
;
3168 u32
*request
= (u32
*)&descriptor
;
3170 descriptor
.RequestFlags
= MPI26_REQ_DESCRIPT_FLAGS_PCIE_ENCAPSULATED
;
3171 descriptor
.MSIxIndex
= _base_get_msix_index(ioc
);
3172 descriptor
.SMID
= cpu_to_le16(smid
);
3174 writel(cpu_to_le32(*request
), &ioc
->chip
->AtomicRequestDescriptorPost
);
3178 * _base_put_smid_default - Default, primarily used for config pages
3179 * use Atomic Request Descriptor
3180 * @ioc: per adapter object
3181 * @smid: system request message index
3186 _base_put_smid_default_atomic(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
3188 Mpi26AtomicRequestDescriptor_t descriptor
;
3189 u32
*request
= (u32
*)&descriptor
;
3191 descriptor
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
3192 descriptor
.MSIxIndex
= _base_get_msix_index(ioc
);
3193 descriptor
.SMID
= cpu_to_le16(smid
);
3195 writel(cpu_to_le32(*request
), &ioc
->chip
->AtomicRequestDescriptorPost
);
3199 * _base_display_OEMs_branding - Display branding string
3200 * @ioc: per adapter object
3205 _base_display_OEMs_branding(struct MPT3SAS_ADAPTER
*ioc
)
3207 if (ioc
->pdev
->subsystem_vendor
!= PCI_VENDOR_ID_INTEL
)
3210 switch (ioc
->pdev
->subsystem_vendor
) {
3211 case PCI_VENDOR_ID_INTEL
:
3212 switch (ioc
->pdev
->device
) {
3213 case MPI2_MFGPAGE_DEVID_SAS2008
:
3214 switch (ioc
->pdev
->subsystem_device
) {
3215 case MPT2SAS_INTEL_RMS2LL080_SSDID
:
3216 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3217 MPT2SAS_INTEL_RMS2LL080_BRANDING
);
3219 case MPT2SAS_INTEL_RMS2LL040_SSDID
:
3220 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3221 MPT2SAS_INTEL_RMS2LL040_BRANDING
);
3223 case MPT2SAS_INTEL_SSD910_SSDID
:
3224 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3225 MPT2SAS_INTEL_SSD910_BRANDING
);
3229 "Intel(R) Controller: Subsystem ID: 0x%X\n",
3230 ioc
->name
, ioc
->pdev
->subsystem_device
);
3233 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
3234 switch (ioc
->pdev
->subsystem_device
) {
3235 case MPT2SAS_INTEL_RS25GB008_SSDID
:
3236 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3237 MPT2SAS_INTEL_RS25GB008_BRANDING
);
3239 case MPT2SAS_INTEL_RMS25JB080_SSDID
:
3240 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3241 MPT2SAS_INTEL_RMS25JB080_BRANDING
);
3243 case MPT2SAS_INTEL_RMS25JB040_SSDID
:
3244 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3245 MPT2SAS_INTEL_RMS25JB040_BRANDING
);
3247 case MPT2SAS_INTEL_RMS25KB080_SSDID
:
3248 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3249 MPT2SAS_INTEL_RMS25KB080_BRANDING
);
3251 case MPT2SAS_INTEL_RMS25KB040_SSDID
:
3252 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3253 MPT2SAS_INTEL_RMS25KB040_BRANDING
);
3255 case MPT2SAS_INTEL_RMS25LB040_SSDID
:
3256 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3257 MPT2SAS_INTEL_RMS25LB040_BRANDING
);
3259 case MPT2SAS_INTEL_RMS25LB080_SSDID
:
3260 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3261 MPT2SAS_INTEL_RMS25LB080_BRANDING
);
3265 "Intel(R) Controller: Subsystem ID: 0x%X\n",
3266 ioc
->name
, ioc
->pdev
->subsystem_device
);
3269 case MPI25_MFGPAGE_DEVID_SAS3008
:
3270 switch (ioc
->pdev
->subsystem_device
) {
3271 case MPT3SAS_INTEL_RMS3JC080_SSDID
:
3272 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3273 MPT3SAS_INTEL_RMS3JC080_BRANDING
);
3276 case MPT3SAS_INTEL_RS3GC008_SSDID
:
3277 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3278 MPT3SAS_INTEL_RS3GC008_BRANDING
);
3280 case MPT3SAS_INTEL_RS3FC044_SSDID
:
3281 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3282 MPT3SAS_INTEL_RS3FC044_BRANDING
);
3284 case MPT3SAS_INTEL_RS3UC080_SSDID
:
3285 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3286 MPT3SAS_INTEL_RS3UC080_BRANDING
);
3290 "Intel(R) Controller: Subsystem ID: 0x%X\n",
3291 ioc
->name
, ioc
->pdev
->subsystem_device
);
3297 "Intel(R) Controller: Subsystem ID: 0x%X\n",
3298 ioc
->name
, ioc
->pdev
->subsystem_device
);
3302 case PCI_VENDOR_ID_DELL
:
3303 switch (ioc
->pdev
->device
) {
3304 case MPI2_MFGPAGE_DEVID_SAS2008
:
3305 switch (ioc
->pdev
->subsystem_device
) {
3306 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID
:
3307 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3308 MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING
);
3310 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID
:
3311 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3312 MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING
);
3314 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID
:
3315 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3316 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING
);
3318 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID
:
3319 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3320 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING
);
3322 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID
:
3323 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3324 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING
);
3326 case MPT2SAS_DELL_PERC_H200_SSDID
:
3327 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3328 MPT2SAS_DELL_PERC_H200_BRANDING
);
3330 case MPT2SAS_DELL_6GBPS_SAS_SSDID
:
3331 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3332 MPT2SAS_DELL_6GBPS_SAS_BRANDING
);
3336 "Dell 6Gbps HBA: Subsystem ID: 0x%X\n",
3337 ioc
->name
, ioc
->pdev
->subsystem_device
);
3341 case MPI25_MFGPAGE_DEVID_SAS3008
:
3342 switch (ioc
->pdev
->subsystem_device
) {
3343 case MPT3SAS_DELL_12G_HBA_SSDID
:
3344 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3345 MPT3SAS_DELL_12G_HBA_BRANDING
);
3349 "Dell 12Gbps HBA: Subsystem ID: 0x%X\n",
3350 ioc
->name
, ioc
->pdev
->subsystem_device
);
3356 "Dell HBA: Subsystem ID: 0x%X\n", ioc
->name
,
3357 ioc
->pdev
->subsystem_device
);
3361 case PCI_VENDOR_ID_CISCO
:
3362 switch (ioc
->pdev
->device
) {
3363 case MPI25_MFGPAGE_DEVID_SAS3008
:
3364 switch (ioc
->pdev
->subsystem_device
) {
3365 case MPT3SAS_CISCO_12G_8E_HBA_SSDID
:
3366 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3367 MPT3SAS_CISCO_12G_8E_HBA_BRANDING
);
3369 case MPT3SAS_CISCO_12G_8I_HBA_SSDID
:
3370 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3371 MPT3SAS_CISCO_12G_8I_HBA_BRANDING
);
3373 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID
:
3374 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3375 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING
);
3379 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n",
3380 ioc
->name
, ioc
->pdev
->subsystem_device
);
3384 case MPI25_MFGPAGE_DEVID_SAS3108_1
:
3385 switch (ioc
->pdev
->subsystem_device
) {
3386 case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID
:
3387 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3388 MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING
);
3390 case MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_SSDID
:
3391 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3392 MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING
3397 "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n",
3398 ioc
->name
, ioc
->pdev
->subsystem_device
);
3404 "Cisco SAS HBA: Subsystem ID: 0x%X\n",
3405 ioc
->name
, ioc
->pdev
->subsystem_device
);
3409 case MPT2SAS_HP_3PAR_SSVID
:
3410 switch (ioc
->pdev
->device
) {
3411 case MPI2_MFGPAGE_DEVID_SAS2004
:
3412 switch (ioc
->pdev
->subsystem_device
) {
3413 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID
:
3414 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3415 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING
);
3419 "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n",
3420 ioc
->name
, ioc
->pdev
->subsystem_device
);
3423 case MPI2_MFGPAGE_DEVID_SAS2308_2
:
3424 switch (ioc
->pdev
->subsystem_device
) {
3425 case MPT2SAS_HP_2_4_INTERNAL_SSDID
:
3426 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3427 MPT2SAS_HP_2_4_INTERNAL_BRANDING
);
3429 case MPT2SAS_HP_2_4_EXTERNAL_SSDID
:
3430 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3431 MPT2SAS_HP_2_4_EXTERNAL_BRANDING
);
3433 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID
:
3434 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3435 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING
);
3437 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID
:
3438 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3439 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING
);
3443 "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n",
3444 ioc
->name
, ioc
->pdev
->subsystem_device
);
3449 "HP SAS HBA: Subsystem ID: 0x%X\n",
3450 ioc
->name
, ioc
->pdev
->subsystem_device
);
3459 * _base_display_ioc_capabilities - Disply IOC's capabilities.
3460 * @ioc: per adapter object
3465 _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER
*ioc
)
3469 u32 iounit_pg1_flags
;
3472 bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
3473 strncpy(desc
, ioc
->manu_pg0
.ChipName
, 16);
3474 pr_info(MPT3SAS_FMT
"%s: FWVersion(%02d.%02d.%02d.%02d), "\
3475 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
3477 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
3478 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
3479 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
3480 ioc
->facts
.FWVersion
.Word
& 0x000000FF,
3481 ioc
->pdev
->revision
,
3482 (bios_version
& 0xFF000000) >> 24,
3483 (bios_version
& 0x00FF0000) >> 16,
3484 (bios_version
& 0x0000FF00) >> 8,
3485 bios_version
& 0x000000FF);
3487 _base_display_OEMs_branding(ioc
);
3489 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_NVME_DEVICES
) {
3490 pr_info("%sNVMe", i
? "," : "");
3494 pr_info(MPT3SAS_FMT
"Protocol=(", ioc
->name
);
3496 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
) {
3497 pr_info("Initiator");
3501 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET
) {
3502 pr_info("%sTarget", i
? "," : "");
3508 pr_info("Capabilities=(");
3510 if (!ioc
->hide_ir_msg
) {
3511 if (ioc
->facts
.IOCCapabilities
&
3512 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
) {
3518 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
) {
3519 pr_info("%sTLR", i
? "," : "");
3523 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_MULTICAST
) {
3524 pr_info("%sMulticast", i
? "," : "");
3528 if (ioc
->facts
.IOCCapabilities
&
3529 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET
) {
3530 pr_info("%sBIDI Target", i
? "," : "");
3534 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_EEDP
) {
3535 pr_info("%sEEDP", i
? "," : "");
3539 if (ioc
->facts
.IOCCapabilities
&
3540 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
) {
3541 pr_info("%sSnapshot Buffer", i
? "," : "");
3545 if (ioc
->facts
.IOCCapabilities
&
3546 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
) {
3547 pr_info("%sDiag Trace Buffer", i
? "," : "");
3551 if (ioc
->facts
.IOCCapabilities
&
3552 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
) {
3553 pr_info("%sDiag Extended Buffer", i
? "," : "");
3557 if (ioc
->facts
.IOCCapabilities
&
3558 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
) {
3559 pr_info("%sTask Set Full", i
? "," : "");
3563 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
3564 if (!(iounit_pg1_flags
& MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE
)) {
3565 pr_info("%sNCQ", i
? "," : "");
3573 * mpt3sas_base_update_missing_delay - change the missing delay timers
3574 * @ioc: per adapter object
3575 * @device_missing_delay: amount of time till device is reported missing
3576 * @io_missing_delay: interval IO is returned when there is a missing device
3580 * Passed on the command line, this function will modify the device missing
3581 * delay, as well as the io missing delay. This should be called at driver
3585 mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER
*ioc
,
3586 u16 device_missing_delay
, u8 io_missing_delay
)
3588 u16 dmd
, dmd_new
, dmd_orignal
;
3589 u8 io_missing_delay_original
;
3591 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
3592 Mpi2ConfigReply_t mpi_reply
;
3596 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
3600 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (num_phys
*
3601 sizeof(Mpi2SasIOUnit1PhyData_t
));
3602 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
3603 if (!sas_iounit_pg1
) {
3604 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
3605 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3608 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
3609 sas_iounit_pg1
, sz
))) {
3610 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
3611 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3614 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
3615 MPI2_IOCSTATUS_MASK
;
3616 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3617 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
3618 ioc
->name
, __FILE__
, __LINE__
, __func__
);
3622 /* device missing delay */
3623 dmd
= sas_iounit_pg1
->ReportDeviceMissingDelay
;
3624 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3625 dmd
= (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3627 dmd
= dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3629 if (device_missing_delay
> 0x7F) {
3630 dmd
= (device_missing_delay
> 0x7F0) ? 0x7F0 :
3631 device_missing_delay
;
3633 dmd
|= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
;
3635 dmd
= device_missing_delay
;
3636 sas_iounit_pg1
->ReportDeviceMissingDelay
= dmd
;
3638 /* io missing delay */
3639 io_missing_delay_original
= sas_iounit_pg1
->IODeviceMissingDelay
;
3640 sas_iounit_pg1
->IODeviceMissingDelay
= io_missing_delay
;
3642 if (!mpt3sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
3644 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
3646 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
3649 dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
3650 pr_info(MPT3SAS_FMT
"device_missing_delay: old(%d), new(%d)\n",
3651 ioc
->name
, dmd_orignal
, dmd_new
);
3652 pr_info(MPT3SAS_FMT
"ioc_missing_delay: old(%d), new(%d)\n",
3653 ioc
->name
, io_missing_delay_original
,
3655 ioc
->device_missing_delay
= dmd_new
;
3656 ioc
->io_missing_delay
= io_missing_delay
;
3660 kfree(sas_iounit_pg1
);
3663 * _base_static_config_pages - static start of day config pages
3664 * @ioc: per adapter object
3669 _base_static_config_pages(struct MPT3SAS_ADAPTER
*ioc
)
3671 Mpi2ConfigReply_t mpi_reply
;
3672 u32 iounit_pg1_flags
;
3674 mpt3sas_config_get_manufacturing_pg0(ioc
, &mpi_reply
, &ioc
->manu_pg0
);
3675 if (ioc
->ir_firmware
)
3676 mpt3sas_config_get_manufacturing_pg10(ioc
, &mpi_reply
,
3680 * Ensure correct T10 PI operation if vendor left EEDPTagMode
3681 * flag unset in NVDATA.
3683 mpt3sas_config_get_manufacturing_pg11(ioc
, &mpi_reply
, &ioc
->manu_pg11
);
3684 if (ioc
->manu_pg11
.EEDPTagMode
== 0) {
3685 pr_err("%s: overriding NVDATA EEDPTagMode setting\n",
3687 ioc
->manu_pg11
.EEDPTagMode
&= ~0x3;
3688 ioc
->manu_pg11
.EEDPTagMode
|= 0x1;
3689 mpt3sas_config_set_manufacturing_pg11(ioc
, &mpi_reply
,
3693 mpt3sas_config_get_bios_pg2(ioc
, &mpi_reply
, &ioc
->bios_pg2
);
3694 mpt3sas_config_get_bios_pg3(ioc
, &mpi_reply
, &ioc
->bios_pg3
);
3695 mpt3sas_config_get_ioc_pg8(ioc
, &mpi_reply
, &ioc
->ioc_pg8
);
3696 mpt3sas_config_get_iounit_pg0(ioc
, &mpi_reply
, &ioc
->iounit_pg0
);
3697 mpt3sas_config_get_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
3698 mpt3sas_config_get_iounit_pg8(ioc
, &mpi_reply
, &ioc
->iounit_pg8
);
3699 _base_display_ioc_capabilities(ioc
);
3702 * Enable task_set_full handling in iounit_pg1 when the
3703 * facts capabilities indicate that its supported.
3705 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
3706 if ((ioc
->facts
.IOCCapabilities
&
3707 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
))
3709 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
3712 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
3713 ioc
->iounit_pg1
.Flags
= cpu_to_le32(iounit_pg1_flags
);
3714 mpt3sas_config_set_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
3716 if (ioc
->iounit_pg8
.NumSensors
)
3717 ioc
->temp_sensors_count
= ioc
->iounit_pg8
.NumSensors
;
3721 * _base_release_memory_pools - release memory
3722 * @ioc: per adapter object
3724 * Free memory allocated from _base_allocate_memory_pools.
3729 _base_release_memory_pools(struct MPT3SAS_ADAPTER
*ioc
)
3732 struct reply_post_struct
*rps
;
3734 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3738 pci_free_consistent(ioc
->pdev
, ioc
->request_dma_sz
,
3739 ioc
->request
, ioc
->request_dma
);
3740 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3741 "request_pool(0x%p): free\n",
3742 ioc
->name
, ioc
->request
));
3743 ioc
->request
= NULL
;
3747 dma_pool_free(ioc
->sense_dma_pool
, ioc
->sense
, ioc
->sense_dma
);
3748 dma_pool_destroy(ioc
->sense_dma_pool
);
3749 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3750 "sense_pool(0x%p): free\n",
3751 ioc
->name
, ioc
->sense
));
3756 dma_pool_free(ioc
->reply_dma_pool
, ioc
->reply
, ioc
->reply_dma
);
3757 dma_pool_destroy(ioc
->reply_dma_pool
);
3758 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3759 "reply_pool(0x%p): free\n",
3760 ioc
->name
, ioc
->reply
));
3764 if (ioc
->reply_free
) {
3765 dma_pool_free(ioc
->reply_free_dma_pool
, ioc
->reply_free
,
3766 ioc
->reply_free_dma
);
3767 dma_pool_destroy(ioc
->reply_free_dma_pool
);
3768 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3769 "reply_free_pool(0x%p): free\n",
3770 ioc
->name
, ioc
->reply_free
));
3771 ioc
->reply_free
= NULL
;
3774 if (ioc
->reply_post
) {
3776 rps
= &ioc
->reply_post
[i
];
3777 if (rps
->reply_post_free
) {
3779 ioc
->reply_post_free_dma_pool
,
3780 rps
->reply_post_free
,
3781 rps
->reply_post_free_dma
);
3782 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3783 "reply_post_free_pool(0x%p): free\n",
3784 ioc
->name
, rps
->reply_post_free
));
3785 rps
->reply_post_free
= NULL
;
3787 } while (ioc
->rdpq_array_enable
&&
3788 (++i
< ioc
->reply_queue_count
));
3790 dma_pool_destroy(ioc
->reply_post_free_dma_pool
);
3791 kfree(ioc
->reply_post
);
3794 if (ioc
->pcie_sgl_dma_pool
) {
3795 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
3796 if (ioc
->scsi_lookup
[i
].pcie_sg_list
.pcie_sgl
)
3797 pci_pool_free(ioc
->pcie_sgl_dma_pool
,
3798 ioc
->scsi_lookup
[i
].pcie_sg_list
.pcie_sgl
,
3799 ioc
->scsi_lookup
[i
].pcie_sg_list
.pcie_sgl_dma
);
3801 if (ioc
->pcie_sgl_dma_pool
)
3802 pci_pool_destroy(ioc
->pcie_sgl_dma_pool
);
3805 if (ioc
->config_page
) {
3806 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
3807 "config_page(0x%p): free\n", ioc
->name
,
3809 pci_free_consistent(ioc
->pdev
, ioc
->config_page_sz
,
3810 ioc
->config_page
, ioc
->config_page_dma
);
3813 if (ioc
->scsi_lookup
) {
3814 free_pages((ulong
)ioc
->scsi_lookup
, ioc
->scsi_lookup_pages
);
3815 ioc
->scsi_lookup
= NULL
;
3817 kfree(ioc
->hpr_lookup
);
3818 kfree(ioc
->internal_lookup
);
3819 if (ioc
->chain_lookup
) {
3820 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
3821 if (ioc
->chain_lookup
[i
].chain_buffer
)
3822 dma_pool_free(ioc
->chain_dma_pool
,
3823 ioc
->chain_lookup
[i
].chain_buffer
,
3824 ioc
->chain_lookup
[i
].chain_buffer_dma
);
3826 dma_pool_destroy(ioc
->chain_dma_pool
);
3827 free_pages((ulong
)ioc
->chain_lookup
, ioc
->chain_pages
);
3828 ioc
->chain_lookup
= NULL
;
3833 * _base_allocate_memory_pools - allocate start of day memory pools
3834 * @ioc: per adapter object
3836 * Returns 0 success, anything else error
3839 _base_allocate_memory_pools(struct MPT3SAS_ADAPTER
*ioc
)
3841 struct mpt3sas_facts
*facts
;
3842 u16 max_sge_elements
;
3843 u16 chains_needed_per_io
;
3844 u32 sz
, total_sz
, reply_post_free_sz
;
3846 u16 max_request_credit
, nvme_blocks_needed
;
3847 unsigned short sg_tablesize
;
3851 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3856 facts
= &ioc
->facts
;
3858 /* command line tunables for max sgl entries */
3859 if (max_sgl_entries
!= -1)
3860 sg_tablesize
= max_sgl_entries
;
3862 if (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
)
3863 sg_tablesize
= MPT2SAS_SG_DEPTH
;
3865 sg_tablesize
= MPT3SAS_SG_DEPTH
;
3868 /* max sgl entries <= MPT_KDUMP_MIN_PHYS_SEGMENTS in KDUMP mode */
3870 sg_tablesize
= min_t(unsigned short, sg_tablesize
,
3871 MPT_KDUMP_MIN_PHYS_SEGMENTS
);
3873 if (sg_tablesize
< MPT_MIN_PHYS_SEGMENTS
)
3874 sg_tablesize
= MPT_MIN_PHYS_SEGMENTS
;
3875 else if (sg_tablesize
> MPT_MAX_PHYS_SEGMENTS
) {
3876 sg_tablesize
= min_t(unsigned short, sg_tablesize
,
3879 "sg_tablesize(%u) is bigger than kernel"
3880 " defined SG_CHUNK_SIZE(%u)\n", ioc
->name
,
3881 sg_tablesize
, MPT_MAX_PHYS_SEGMENTS
);
3883 ioc
->shost
->sg_tablesize
= sg_tablesize
;
3885 ioc
->internal_depth
= min_t(int, (facts
->HighPriorityCredit
+ (5)),
3886 (facts
->RequestCredit
/ 4));
3887 if (ioc
->internal_depth
< INTERNAL_CMDS_COUNT
) {
3888 if (facts
->RequestCredit
<= (INTERNAL_CMDS_COUNT
+
3889 INTERNAL_SCSIIO_CMDS_COUNT
)) {
3890 pr_err(MPT3SAS_FMT
"IOC doesn't have enough Request \
3891 Credits, it has just %d number of credits\n",
3892 ioc
->name
, facts
->RequestCredit
);
3895 ioc
->internal_depth
= 10;
3898 ioc
->hi_priority_depth
= ioc
->internal_depth
- (5);
3899 /* command line tunables for max controller queue depth */
3900 if (max_queue_depth
!= -1 && max_queue_depth
!= 0) {
3901 max_request_credit
= min_t(u16
, max_queue_depth
+
3902 ioc
->internal_depth
, facts
->RequestCredit
);
3903 if (max_request_credit
> MAX_HBA_QUEUE_DEPTH
)
3904 max_request_credit
= MAX_HBA_QUEUE_DEPTH
;
3905 } else if (reset_devices
)
3906 max_request_credit
= min_t(u16
, facts
->RequestCredit
,
3907 (MPT3SAS_KDUMP_SCSI_IO_DEPTH
+ ioc
->internal_depth
));
3909 max_request_credit
= min_t(u16
, facts
->RequestCredit
,
3910 MAX_HBA_QUEUE_DEPTH
);
3912 /* Firmware maintains additional facts->HighPriorityCredit number of
3913 * credits for HiPriprity Request messages, so hba queue depth will be
3914 * sum of max_request_credit and high priority queue depth.
3916 ioc
->hba_queue_depth
= max_request_credit
+ ioc
->hi_priority_depth
;
3918 /* request frame size */
3919 ioc
->request_sz
= facts
->IOCRequestFrameSize
* 4;
3921 /* reply frame size */
3922 ioc
->reply_sz
= facts
->ReplyFrameSize
* 4;
3924 /* chain segment size */
3925 if (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
3926 if (facts
->IOCMaxChainSegmentSize
)
3927 ioc
->chain_segment_sz
=
3928 facts
->IOCMaxChainSegmentSize
*
3931 /* set to 128 bytes size if IOCMaxChainSegmentSize is zero */
3932 ioc
->chain_segment_sz
= DEFAULT_NUM_FWCHAIN_ELEMTS
*
3935 ioc
->chain_segment_sz
= ioc
->request_sz
;
3937 /* calculate the max scatter element size */
3938 sge_size
= max_t(u16
, ioc
->sge_size
, ioc
->sge_size_ieee
);
3942 /* calculate number of sg elements left over in the 1st frame */
3943 max_sge_elements
= ioc
->request_sz
- ((sizeof(Mpi2SCSIIORequest_t
) -
3944 sizeof(Mpi2SGEIOUnion_t
)) + sge_size
);
3945 ioc
->max_sges_in_main_message
= max_sge_elements
/sge_size
;
3947 /* now do the same for a chain buffer */
3948 max_sge_elements
= ioc
->chain_segment_sz
- sge_size
;
3949 ioc
->max_sges_in_chain_message
= max_sge_elements
/sge_size
;
3952 * MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
3954 chains_needed_per_io
= ((ioc
->shost
->sg_tablesize
-
3955 ioc
->max_sges_in_main_message
)/ioc
->max_sges_in_chain_message
)
3957 if (chains_needed_per_io
> facts
->MaxChainDepth
) {
3958 chains_needed_per_io
= facts
->MaxChainDepth
;
3959 ioc
->shost
->sg_tablesize
= min_t(u16
,
3960 ioc
->max_sges_in_main_message
+ (ioc
->max_sges_in_chain_message
3961 * chains_needed_per_io
), ioc
->shost
->sg_tablesize
);
3963 ioc
->chains_needed_per_io
= chains_needed_per_io
;
3965 /* reply free queue sizing - taking into account for 64 FW events */
3966 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
3968 /* calculate reply descriptor post queue depth */
3969 ioc
->reply_post_queue_depth
= ioc
->hba_queue_depth
+
3970 ioc
->reply_free_queue_depth
+ 1 ;
3971 /* align the reply post queue on the next 16 count boundary */
3972 if (ioc
->reply_post_queue_depth
% 16)
3973 ioc
->reply_post_queue_depth
+= 16 -
3974 (ioc
->reply_post_queue_depth
% 16);
3976 if (ioc
->reply_post_queue_depth
>
3977 facts
->MaxReplyDescriptorPostQueueDepth
) {
3978 ioc
->reply_post_queue_depth
=
3979 facts
->MaxReplyDescriptorPostQueueDepth
-
3980 (facts
->MaxReplyDescriptorPostQueueDepth
% 16);
3981 ioc
->hba_queue_depth
=
3982 ((ioc
->reply_post_queue_depth
- 64) / 2) - 1;
3983 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
3986 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scatter gather: " \
3987 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
3988 "chains_per_io(%d)\n", ioc
->name
, ioc
->max_sges_in_main_message
,
3989 ioc
->max_sges_in_chain_message
, ioc
->shost
->sg_tablesize
,
3990 ioc
->chains_needed_per_io
));
3992 /* reply post queue, 16 byte align */
3993 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
3994 sizeof(Mpi2DefaultReplyDescriptor_t
);
3996 sz
= reply_post_free_sz
;
3997 if (_base_is_controller_msix_enabled(ioc
) && !ioc
->rdpq_array_enable
)
3998 sz
*= ioc
->reply_queue_count
;
4000 ioc
->reply_post
= kcalloc((ioc
->rdpq_array_enable
) ?
4001 (ioc
->reply_queue_count
):1,
4002 sizeof(struct reply_post_struct
), GFP_KERNEL
);
4004 if (!ioc
->reply_post
) {
4005 pr_err(MPT3SAS_FMT
"reply_post_free pool: kcalloc failed\n",
4009 ioc
->reply_post_free_dma_pool
= dma_pool_create("reply_post_free pool",
4010 &ioc
->pdev
->dev
, sz
, 16, 0);
4011 if (!ioc
->reply_post_free_dma_pool
) {
4013 "reply_post_free pool: dma_pool_create failed\n",
4019 ioc
->reply_post
[i
].reply_post_free
=
4020 dma_pool_alloc(ioc
->reply_post_free_dma_pool
,
4022 &ioc
->reply_post
[i
].reply_post_free_dma
);
4023 if (!ioc
->reply_post
[i
].reply_post_free
) {
4025 "reply_post_free pool: dma_pool_alloc failed\n",
4029 memset(ioc
->reply_post
[i
].reply_post_free
, 0, sz
);
4030 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4031 "reply post free pool (0x%p): depth(%d),"
4032 "element_size(%d), pool_size(%d kB)\n", ioc
->name
,
4033 ioc
->reply_post
[i
].reply_post_free
,
4034 ioc
->reply_post_queue_depth
, 8, sz
/1024));
4035 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4036 "reply_post_free_dma = (0x%llx)\n", ioc
->name
,
4037 (unsigned long long)
4038 ioc
->reply_post
[i
].reply_post_free_dma
));
4040 } while (ioc
->rdpq_array_enable
&& (++i
< ioc
->reply_queue_count
));
4042 if (ioc
->dma_mask
== 64) {
4043 if (_base_change_consistent_dma_mask(ioc
, ioc
->pdev
) != 0) {
4045 "no suitable consistent DMA mask for %s\n",
4046 ioc
->name
, pci_name(ioc
->pdev
));
4051 ioc
->scsiio_depth
= ioc
->hba_queue_depth
-
4052 ioc
->hi_priority_depth
- ioc
->internal_depth
;
4054 /* set the scsi host can_queue depth
4055 * with some internal commands that could be outstanding
4057 ioc
->shost
->can_queue
= ioc
->scsiio_depth
- INTERNAL_SCSIIO_CMDS_COUNT
;
4058 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4059 "scsi host: can_queue depth (%d)\n",
4060 ioc
->name
, ioc
->shost
->can_queue
));
4063 /* contiguous pool for request and chains, 16 byte align, one extra "
4066 ioc
->chain_depth
= ioc
->chains_needed_per_io
* ioc
->scsiio_depth
;
4067 sz
= ((ioc
->scsiio_depth
+ 1) * ioc
->request_sz
);
4069 /* hi-priority queue */
4070 sz
+= (ioc
->hi_priority_depth
* ioc
->request_sz
);
4072 /* internal queue */
4073 sz
+= (ioc
->internal_depth
* ioc
->request_sz
);
4075 ioc
->request_dma_sz
= sz
;
4076 ioc
->request
= pci_alloc_consistent(ioc
->pdev
, sz
, &ioc
->request_dma
);
4077 if (!ioc
->request
) {
4078 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
4079 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
4080 "total(%d kB)\n", ioc
->name
, ioc
->hba_queue_depth
,
4081 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
4082 if (ioc
->scsiio_depth
< MPT3SAS_SAS_QUEUE_DEPTH
)
4085 ioc
->hba_queue_depth
-= retry_sz
;
4086 _base_release_memory_pools(ioc
);
4087 goto retry_allocation
;
4091 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
4092 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
4093 "total(%d kb)\n", ioc
->name
, ioc
->hba_queue_depth
,
4094 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
4096 /* hi-priority queue */
4097 ioc
->hi_priority
= ioc
->request
+ ((ioc
->scsiio_depth
+ 1) *
4099 ioc
->hi_priority_dma
= ioc
->request_dma
+ ((ioc
->scsiio_depth
+ 1) *
4102 /* internal queue */
4103 ioc
->internal
= ioc
->hi_priority
+ (ioc
->hi_priority_depth
*
4105 ioc
->internal_dma
= ioc
->hi_priority_dma
+ (ioc
->hi_priority_depth
*
4108 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4109 "request pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
4110 ioc
->name
, ioc
->request
, ioc
->hba_queue_depth
, ioc
->request_sz
,
4111 (ioc
->hba_queue_depth
* ioc
->request_sz
)/1024));
4113 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"request pool: dma(0x%llx)\n",
4114 ioc
->name
, (unsigned long long) ioc
->request_dma
));
4117 sz
= ioc
->scsiio_depth
* sizeof(struct scsiio_tracker
);
4118 ioc
->scsi_lookup_pages
= get_order(sz
);
4119 ioc
->scsi_lookup
= (struct scsiio_tracker
*)__get_free_pages(
4120 GFP_KERNEL
, ioc
->scsi_lookup_pages
);
4121 if (!ioc
->scsi_lookup
) {
4122 pr_err(MPT3SAS_FMT
"scsi_lookup: get_free_pages failed, sz(%d)\n",
4123 ioc
->name
, (int)sz
);
4127 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scsiio(0x%p): depth(%d)\n",
4128 ioc
->name
, ioc
->request
, ioc
->scsiio_depth
));
4130 ioc
->chain_depth
= min_t(u32
, ioc
->chain_depth
, MAX_CHAIN_DEPTH
);
4131 sz
= ioc
->chain_depth
* sizeof(struct chain_tracker
);
4132 ioc
->chain_pages
= get_order(sz
);
4133 ioc
->chain_lookup
= (struct chain_tracker
*)__get_free_pages(
4134 GFP_KERNEL
, ioc
->chain_pages
);
4135 if (!ioc
->chain_lookup
) {
4136 pr_err(MPT3SAS_FMT
"chain_lookup: __get_free_pages failed\n",
4140 ioc
->chain_dma_pool
= dma_pool_create("chain pool", &ioc
->pdev
->dev
,
4141 ioc
->chain_segment_sz
, 16, 0);
4142 if (!ioc
->chain_dma_pool
) {
4143 pr_err(MPT3SAS_FMT
"chain_dma_pool: dma_pool_create failed\n",
4147 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
4148 ioc
->chain_lookup
[i
].chain_buffer
= dma_pool_alloc(
4149 ioc
->chain_dma_pool
, GFP_KERNEL
,
4150 &ioc
->chain_lookup
[i
].chain_buffer_dma
);
4151 if (!ioc
->chain_lookup
[i
].chain_buffer
) {
4152 ioc
->chain_depth
= i
;
4155 total_sz
+= ioc
->chain_segment_sz
;
4158 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4159 "chain pool depth(%d), frame_size(%d), pool_size(%d kB)\n",
4160 ioc
->name
, ioc
->chain_depth
, ioc
->chain_segment_sz
,
4161 ((ioc
->chain_depth
* ioc
->chain_segment_sz
))/1024));
4163 /* initialize hi-priority queue smid's */
4164 ioc
->hpr_lookup
= kcalloc(ioc
->hi_priority_depth
,
4165 sizeof(struct request_tracker
), GFP_KERNEL
);
4166 if (!ioc
->hpr_lookup
) {
4167 pr_err(MPT3SAS_FMT
"hpr_lookup: kcalloc failed\n",
4171 ioc
->hi_priority_smid
= ioc
->scsiio_depth
+ 1;
4172 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4173 "hi_priority(0x%p): depth(%d), start smid(%d)\n",
4174 ioc
->name
, ioc
->hi_priority
,
4175 ioc
->hi_priority_depth
, ioc
->hi_priority_smid
));
4177 /* initialize internal queue smid's */
4178 ioc
->internal_lookup
= kcalloc(ioc
->internal_depth
,
4179 sizeof(struct request_tracker
), GFP_KERNEL
);
4180 if (!ioc
->internal_lookup
) {
4181 pr_err(MPT3SAS_FMT
"internal_lookup: kcalloc failed\n",
4185 ioc
->internal_smid
= ioc
->hi_priority_smid
+ ioc
->hi_priority_depth
;
4186 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4187 "internal(0x%p): depth(%d), start smid(%d)\n",
4188 ioc
->name
, ioc
->internal
,
4189 ioc
->internal_depth
, ioc
->internal_smid
));
4191 * The number of NVMe page sized blocks needed is:
4192 * (((sg_tablesize * 8) - 1) / (page_size - 8)) + 1
4193 * ((sg_tablesize * 8) - 1) is the max PRP's minus the first PRP entry
4194 * that is placed in the main message frame. 8 is the size of each PRP
4195 * entry or PRP list pointer entry. 8 is subtracted from page_size
4196 * because of the PRP list pointer entry at the end of a page, so this
4197 * is not counted as a PRP entry. The 1 added page is a round up.
4199 * To avoid allocation failures due to the amount of memory that could
4200 * be required for NVMe PRP's, only each set of NVMe blocks will be
4201 * contiguous, so a new set is allocated for each possible I/O.
4203 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_NVME_DEVICES
) {
4204 nvme_blocks_needed
=
4205 (ioc
->shost
->sg_tablesize
* NVME_PRP_SIZE
) - 1;
4206 nvme_blocks_needed
/= (ioc
->page_size
- NVME_PRP_SIZE
);
4207 nvme_blocks_needed
++;
4209 sz
= nvme_blocks_needed
* ioc
->page_size
;
4210 ioc
->pcie_sgl_dma_pool
=
4211 pci_pool_create("PCIe SGL pool", ioc
->pdev
, sz
, 16, 0);
4212 if (!ioc
->pcie_sgl_dma_pool
) {
4214 "PCIe SGL pool: pci_pool_create failed\n",
4218 for (i
= 0; i
< ioc
->scsiio_depth
; i
++) {
4219 ioc
->scsi_lookup
[i
].pcie_sg_list
.pcie_sgl
=
4220 pci_pool_alloc(ioc
->pcie_sgl_dma_pool
,
4222 &ioc
->scsi_lookup
[i
].pcie_sg_list
.pcie_sgl_dma
);
4223 if (!ioc
->scsi_lookup
[i
].pcie_sg_list
.pcie_sgl
) {
4225 "PCIe SGL pool: pci_pool_alloc failed\n",
4231 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"PCIe sgl pool depth(%d), "
4232 "element_size(%d), pool_size(%d kB)\n", ioc
->name
,
4233 ioc
->scsiio_depth
, sz
, (sz
* ioc
->scsiio_depth
)/1024));
4234 total_sz
+= sz
* ioc
->scsiio_depth
;
4236 /* sense buffers, 4 byte align */
4237 sz
= ioc
->scsiio_depth
* SCSI_SENSE_BUFFERSIZE
;
4238 ioc
->sense_dma_pool
= dma_pool_create("sense pool", &ioc
->pdev
->dev
, sz
,
4240 if (!ioc
->sense_dma_pool
) {
4241 pr_err(MPT3SAS_FMT
"sense pool: dma_pool_create failed\n",
4245 ioc
->sense
= dma_pool_alloc(ioc
->sense_dma_pool
, GFP_KERNEL
,
4248 pr_err(MPT3SAS_FMT
"sense pool: dma_pool_alloc failed\n",
4252 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4253 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
4254 "(%d kB)\n", ioc
->name
, ioc
->sense
, ioc
->scsiio_depth
,
4255 SCSI_SENSE_BUFFERSIZE
, sz
/1024));
4256 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"sense_dma(0x%llx)\n",
4257 ioc
->name
, (unsigned long long)ioc
->sense_dma
));
4260 /* reply pool, 4 byte align */
4261 sz
= ioc
->reply_free_queue_depth
* ioc
->reply_sz
;
4262 ioc
->reply_dma_pool
= dma_pool_create("reply pool", &ioc
->pdev
->dev
, sz
,
4264 if (!ioc
->reply_dma_pool
) {
4265 pr_err(MPT3SAS_FMT
"reply pool: dma_pool_create failed\n",
4269 ioc
->reply
= dma_pool_alloc(ioc
->reply_dma_pool
, GFP_KERNEL
,
4272 pr_err(MPT3SAS_FMT
"reply pool: dma_pool_alloc failed\n",
4276 ioc
->reply_dma_min_address
= (u32
)(ioc
->reply_dma
);
4277 ioc
->reply_dma_max_address
= (u32
)(ioc
->reply_dma
) + sz
;
4278 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4279 "reply pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
4280 ioc
->name
, ioc
->reply
,
4281 ioc
->reply_free_queue_depth
, ioc
->reply_sz
, sz
/1024));
4282 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_dma(0x%llx)\n",
4283 ioc
->name
, (unsigned long long)ioc
->reply_dma
));
4286 /* reply free queue, 16 byte align */
4287 sz
= ioc
->reply_free_queue_depth
* 4;
4288 ioc
->reply_free_dma_pool
= dma_pool_create("reply_free pool",
4289 &ioc
->pdev
->dev
, sz
, 16, 0);
4290 if (!ioc
->reply_free_dma_pool
) {
4291 pr_err(MPT3SAS_FMT
"reply_free pool: dma_pool_create failed\n",
4295 ioc
->reply_free
= dma_pool_alloc(ioc
->reply_free_dma_pool
, GFP_KERNEL
,
4296 &ioc
->reply_free_dma
);
4297 if (!ioc
->reply_free
) {
4298 pr_err(MPT3SAS_FMT
"reply_free pool: dma_pool_alloc failed\n",
4302 memset(ioc
->reply_free
, 0, sz
);
4303 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_free pool(0x%p): " \
4304 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc
->name
,
4305 ioc
->reply_free
, ioc
->reply_free_queue_depth
, 4, sz
/1024));
4306 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4307 "reply_free_dma (0x%llx)\n",
4308 ioc
->name
, (unsigned long long)ioc
->reply_free_dma
));
4311 ioc
->config_page_sz
= 512;
4312 ioc
->config_page
= pci_alloc_consistent(ioc
->pdev
,
4313 ioc
->config_page_sz
, &ioc
->config_page_dma
);
4314 if (!ioc
->config_page
) {
4316 "config page: dma_pool_alloc failed\n",
4320 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
4321 "config page(0x%p): size(%d)\n",
4322 ioc
->name
, ioc
->config_page
, ioc
->config_page_sz
));
4323 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"config_page_dma(0x%llx)\n",
4324 ioc
->name
, (unsigned long long)ioc
->config_page_dma
));
4325 total_sz
+= ioc
->config_page_sz
;
4327 pr_info(MPT3SAS_FMT
"Allocated physical memory: size(%d kB)\n",
4328 ioc
->name
, total_sz
/1024);
4330 "Current Controller Queue Depth(%d),Max Controller Queue Depth(%d)\n",
4331 ioc
->name
, ioc
->shost
->can_queue
, facts
->RequestCredit
);
4332 pr_info(MPT3SAS_FMT
"Scatter Gather Elements per IO(%d)\n",
4333 ioc
->name
, ioc
->shost
->sg_tablesize
);
4341 * mpt3sas_base_get_iocstate - Get the current state of a MPT adapter.
4342 * @ioc: Pointer to MPT_ADAPTER structure
4343 * @cooked: Request raw or cooked IOC state
4345 * Returns all IOC Doorbell register bits if cooked==0, else just the
4346 * Doorbell bits in MPI_IOC_STATE_MASK.
4349 mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER
*ioc
, int cooked
)
4353 s
= readl(&ioc
->chip
->Doorbell
);
4354 sc
= s
& MPI2_IOC_STATE_MASK
;
4355 return cooked
? sc
: s
;
4359 * _base_wait_on_iocstate - waiting on a particular ioc state
4360 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
4361 * @timeout: timeout in second
4363 * Returns 0 for success, non-zero for failure.
4366 _base_wait_on_iocstate(struct MPT3SAS_ADAPTER
*ioc
, u32 ioc_state
, int timeout
)
4372 cntdn
= 1000 * timeout
;
4374 current_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4375 if (current_state
== ioc_state
)
4377 if (count
&& current_state
== MPI2_IOC_STATE_FAULT
)
4380 usleep_range(1000, 1500);
4384 return current_state
;
4388 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
4389 * a write to the doorbell)
4390 * @ioc: per adapter object
4391 * @timeout: timeout in second
4393 * Returns 0 for success, non-zero for failure.
4395 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
4398 _base_diag_reset(struct MPT3SAS_ADAPTER
*ioc
);
4401 _base_wait_for_doorbell_int(struct MPT3SAS_ADAPTER
*ioc
, int timeout
)
4407 cntdn
= 1000 * timeout
;
4409 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
4410 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
4411 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4412 "%s: successful count(%d), timeout(%d)\n",
4413 ioc
->name
, __func__
, count
, timeout
));
4417 usleep_range(1000, 1500);
4422 "%s: failed due to timeout count(%d), int_status(%x)!\n",
4423 ioc
->name
, __func__
, count
, int_status
);
4428 _base_spin_on_doorbell_int(struct MPT3SAS_ADAPTER
*ioc
, int timeout
)
4434 cntdn
= 2000 * timeout
;
4436 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
4437 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
4438 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4439 "%s: successful count(%d), timeout(%d)\n",
4440 ioc
->name
, __func__
, count
, timeout
));
4449 "%s: failed due to timeout count(%d), int_status(%x)!\n",
4450 ioc
->name
, __func__
, count
, int_status
);
4456 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
4457 * @ioc: per adapter object
4458 * @timeout: timeout in second
4460 * Returns 0 for success, non-zero for failure.
4462 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
4466 _base_wait_for_doorbell_ack(struct MPT3SAS_ADAPTER
*ioc
, int timeout
)
4473 cntdn
= 1000 * timeout
;
4475 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
4476 if (!(int_status
& MPI2_HIS_SYS2IOC_DB_STATUS
)) {
4477 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4478 "%s: successful count(%d), timeout(%d)\n",
4479 ioc
->name
, __func__
, count
, timeout
));
4481 } else if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
4482 doorbell
= readl(&ioc
->chip
->Doorbell
);
4483 if ((doorbell
& MPI2_IOC_STATE_MASK
) ==
4484 MPI2_IOC_STATE_FAULT
) {
4485 mpt3sas_base_fault_info(ioc
, doorbell
);
4488 } else if (int_status
== 0xFFFFFFFF)
4491 usleep_range(1000, 1500);
4497 "%s: failed due to timeout count(%d), int_status(%x)!\n",
4498 ioc
->name
, __func__
, count
, int_status
);
4503 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
4504 * @ioc: per adapter object
4505 * @timeout: timeout in second
4507 * Returns 0 for success, non-zero for failure.
4511 _base_wait_for_doorbell_not_used(struct MPT3SAS_ADAPTER
*ioc
, int timeout
)
4517 cntdn
= 1000 * timeout
;
4519 doorbell_reg
= readl(&ioc
->chip
->Doorbell
);
4520 if (!(doorbell_reg
& MPI2_DOORBELL_USED
)) {
4521 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4522 "%s: successful count(%d), timeout(%d)\n",
4523 ioc
->name
, __func__
, count
, timeout
));
4527 usleep_range(1000, 1500);
4532 "%s: failed due to timeout count(%d), doorbell_reg(%x)!\n",
4533 ioc
->name
, __func__
, count
, doorbell_reg
);
4538 * _base_send_ioc_reset - send doorbell reset
4539 * @ioc: per adapter object
4540 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
4541 * @timeout: timeout in second
4543 * Returns 0 for success, non-zero for failure.
4546 _base_send_ioc_reset(struct MPT3SAS_ADAPTER
*ioc
, u8 reset_type
, int timeout
)
4551 if (reset_type
!= MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
) {
4552 pr_err(MPT3SAS_FMT
"%s: unknown reset_type\n",
4553 ioc
->name
, __func__
);
4557 if (!(ioc
->facts
.IOCCapabilities
&
4558 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY
))
4561 pr_info(MPT3SAS_FMT
"sending message unit reset !!\n", ioc
->name
);
4563 writel(reset_type
<< MPI2_DOORBELL_FUNCTION_SHIFT
,
4564 &ioc
->chip
->Doorbell
);
4565 if ((_base_wait_for_doorbell_ack(ioc
, 15))) {
4569 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, timeout
);
4572 "%s: failed going to ready state (ioc_state=0x%x)\n",
4573 ioc
->name
, __func__
, ioc_state
);
4578 pr_info(MPT3SAS_FMT
"message unit reset: %s\n",
4579 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
4584 * _base_handshake_req_reply_wait - send request thru doorbell interface
4585 * @ioc: per adapter object
4586 * @request_bytes: request length
4587 * @request: pointer having request payload
4588 * @reply_bytes: reply length
4589 * @reply: pointer to reply payload
4590 * @timeout: timeout in second
4592 * Returns 0 for success, non-zero for failure.
4595 _base_handshake_req_reply_wait(struct MPT3SAS_ADAPTER
*ioc
, int request_bytes
,
4596 u32
*request
, int reply_bytes
, u16
*reply
, int timeout
)
4598 MPI2DefaultReply_t
*default_reply
= (MPI2DefaultReply_t
*)reply
;
4603 /* make sure doorbell is not in use */
4604 if ((readl(&ioc
->chip
->Doorbell
) & MPI2_DOORBELL_USED
)) {
4606 "doorbell is in use (line=%d)\n",
4607 ioc
->name
, __LINE__
);
4611 /* clear pending doorbell interrupts from previous state changes */
4612 if (readl(&ioc
->chip
->HostInterruptStatus
) &
4613 MPI2_HIS_IOC2SYS_DB_STATUS
)
4614 writel(0, &ioc
->chip
->HostInterruptStatus
);
4616 /* send message to ioc */
4617 writel(((MPI2_FUNCTION_HANDSHAKE
<<MPI2_DOORBELL_FUNCTION_SHIFT
) |
4618 ((request_bytes
/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT
)),
4619 &ioc
->chip
->Doorbell
);
4621 if ((_base_spin_on_doorbell_int(ioc
, 5))) {
4623 "doorbell handshake int failed (line=%d)\n",
4624 ioc
->name
, __LINE__
);
4627 writel(0, &ioc
->chip
->HostInterruptStatus
);
4629 if ((_base_wait_for_doorbell_ack(ioc
, 5))) {
4631 "doorbell handshake ack failed (line=%d)\n",
4632 ioc
->name
, __LINE__
);
4636 /* send message 32-bits at a time */
4637 for (i
= 0, failed
= 0; i
< request_bytes
/4 && !failed
; i
++) {
4638 writel(cpu_to_le32(request
[i
]), &ioc
->chip
->Doorbell
);
4639 if ((_base_wait_for_doorbell_ack(ioc
, 5)))
4645 "doorbell handshake sending request failed (line=%d)\n",
4646 ioc
->name
, __LINE__
);
4650 /* now wait for the reply */
4651 if ((_base_wait_for_doorbell_int(ioc
, timeout
))) {
4653 "doorbell handshake int failed (line=%d)\n",
4654 ioc
->name
, __LINE__
);
4658 /* read the first two 16-bits, it gives the total length of the reply */
4659 reply
[0] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
4660 & MPI2_DOORBELL_DATA_MASK
);
4661 writel(0, &ioc
->chip
->HostInterruptStatus
);
4662 if ((_base_wait_for_doorbell_int(ioc
, 5))) {
4664 "doorbell handshake int failed (line=%d)\n",
4665 ioc
->name
, __LINE__
);
4668 reply
[1] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
4669 & MPI2_DOORBELL_DATA_MASK
);
4670 writel(0, &ioc
->chip
->HostInterruptStatus
);
4672 for (i
= 2; i
< default_reply
->MsgLength
* 2; i
++) {
4673 if ((_base_wait_for_doorbell_int(ioc
, 5))) {
4675 "doorbell handshake int failed (line=%d)\n",
4676 ioc
->name
, __LINE__
);
4679 if (i
>= reply_bytes
/2) /* overflow case */
4680 readl(&ioc
->chip
->Doorbell
);
4682 reply
[i
] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
4683 & MPI2_DOORBELL_DATA_MASK
);
4684 writel(0, &ioc
->chip
->HostInterruptStatus
);
4687 _base_wait_for_doorbell_int(ioc
, 5);
4688 if (_base_wait_for_doorbell_not_used(ioc
, 5) != 0) {
4689 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4690 "doorbell is in use (line=%d)\n", ioc
->name
, __LINE__
));
4692 writel(0, &ioc
->chip
->HostInterruptStatus
);
4694 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
4695 mfp
= (__le32
*)reply
;
4696 pr_info("\toffset:data\n");
4697 for (i
= 0; i
< reply_bytes
/4; i
++)
4698 pr_info("\t[0x%02x]:%08x\n", i
*4,
4699 le32_to_cpu(mfp
[i
]));
4705 * mpt3sas_base_sas_iounit_control - send sas iounit control to FW
4706 * @ioc: per adapter object
4707 * @mpi_reply: the reply payload from FW
4708 * @mpi_request: the request payload sent to FW
4710 * The SAS IO Unit Control Request message allows the host to perform low-level
4711 * operations, such as resets on the PHYs of the IO Unit, also allows the host
4712 * to obtain the IOC assigned device handles for a device if it has other
4713 * identifying information about the device, in addition allows the host to
4714 * remove IOC resources associated with the device.
4716 * Returns 0 for success, non-zero for failure.
4719 mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER
*ioc
,
4720 Mpi2SasIoUnitControlReply_t
*mpi_reply
,
4721 Mpi2SasIoUnitControlRequest_t
*mpi_request
)
4725 bool issue_reset
= false;
4728 u16 wait_state_count
;
4730 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4733 mutex_lock(&ioc
->base_cmds
.mutex
);
4735 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
4736 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
4737 ioc
->name
, __func__
);
4742 wait_state_count
= 0;
4743 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4744 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4745 if (wait_state_count
++ == 10) {
4747 "%s: failed due to ioc not operational\n",
4748 ioc
->name
, __func__
);
4753 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4755 "%s: waiting for operational state(count=%d)\n",
4756 ioc
->name
, __func__
, wait_state_count
);
4759 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
4761 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4762 ioc
->name
, __func__
);
4768 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
4769 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4770 ioc
->base_cmds
.smid
= smid
;
4771 memcpy(request
, mpi_request
, sizeof(Mpi2SasIoUnitControlRequest_t
));
4772 if (mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
4773 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
)
4774 ioc
->ioc_link_reset_in_progress
= 1;
4775 init_completion(&ioc
->base_cmds
.done
);
4776 ioc
->put_smid_default(ioc
, smid
);
4777 wait_for_completion_timeout(&ioc
->base_cmds
.done
,
4778 msecs_to_jiffies(10000));
4779 if ((mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
4780 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
) &&
4781 ioc
->ioc_link_reset_in_progress
)
4782 ioc
->ioc_link_reset_in_progress
= 0;
4783 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
4784 pr_err(MPT3SAS_FMT
"%s: timeout\n",
4785 ioc
->name
, __func__
);
4786 _debug_dump_mf(mpi_request
,
4787 sizeof(Mpi2SasIoUnitControlRequest_t
)/4);
4788 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
4790 goto issue_host_reset
;
4792 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
4793 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
4794 sizeof(Mpi2SasIoUnitControlReply_t
));
4796 memset(mpi_reply
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
4797 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4802 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
4803 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4806 mutex_unlock(&ioc
->base_cmds
.mutex
);
4811 * mpt3sas_base_scsi_enclosure_processor - sending request to sep device
4812 * @ioc: per adapter object
4813 * @mpi_reply: the reply payload from FW
4814 * @mpi_request: the request payload sent to FW
4816 * The SCSI Enclosure Processor request message causes the IOC to
4817 * communicate with SES devices to control LED status signals.
4819 * Returns 0 for success, non-zero for failure.
4822 mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER
*ioc
,
4823 Mpi2SepReply_t
*mpi_reply
, Mpi2SepRequest_t
*mpi_request
)
4827 bool issue_reset
= false;
4830 u16 wait_state_count
;
4832 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4835 mutex_lock(&ioc
->base_cmds
.mutex
);
4837 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
4838 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
4839 ioc
->name
, __func__
);
4844 wait_state_count
= 0;
4845 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4846 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
4847 if (wait_state_count
++ == 10) {
4849 "%s: failed due to ioc not operational\n",
4850 ioc
->name
, __func__
);
4855 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
4857 "%s: waiting for operational state(count=%d)\n",
4859 __func__
, wait_state_count
);
4862 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
4864 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
4865 ioc
->name
, __func__
);
4871 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
4872 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
4873 ioc
->base_cmds
.smid
= smid
;
4874 memcpy(request
, mpi_request
, sizeof(Mpi2SepReply_t
));
4875 init_completion(&ioc
->base_cmds
.done
);
4876 ioc
->put_smid_default(ioc
, smid
);
4877 wait_for_completion_timeout(&ioc
->base_cmds
.done
,
4878 msecs_to_jiffies(10000));
4879 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
4880 pr_err(MPT3SAS_FMT
"%s: timeout\n",
4881 ioc
->name
, __func__
);
4882 _debug_dump_mf(mpi_request
,
4883 sizeof(Mpi2SepRequest_t
)/4);
4884 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
4885 issue_reset
= false;
4886 goto issue_host_reset
;
4888 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
4889 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
4890 sizeof(Mpi2SepReply_t
));
4892 memset(mpi_reply
, 0, sizeof(Mpi2SepReply_t
));
4893 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4898 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
4899 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4902 mutex_unlock(&ioc
->base_cmds
.mutex
);
4907 * _base_get_port_facts - obtain port facts reply and save in ioc
4908 * @ioc: per adapter object
4910 * Returns 0 for success, non-zero for failure.
4913 _base_get_port_facts(struct MPT3SAS_ADAPTER
*ioc
, int port
)
4915 Mpi2PortFactsRequest_t mpi_request
;
4916 Mpi2PortFactsReply_t mpi_reply
;
4917 struct mpt3sas_port_facts
*pfacts
;
4918 int mpi_reply_sz
, mpi_request_sz
, r
;
4920 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4923 mpi_reply_sz
= sizeof(Mpi2PortFactsReply_t
);
4924 mpi_request_sz
= sizeof(Mpi2PortFactsRequest_t
);
4925 memset(&mpi_request
, 0, mpi_request_sz
);
4926 mpi_request
.Function
= MPI2_FUNCTION_PORT_FACTS
;
4927 mpi_request
.PortNumber
= port
;
4928 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
4929 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5);
4932 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
4933 ioc
->name
, __func__
, r
);
4937 pfacts
= &ioc
->pfacts
[port
];
4938 memset(pfacts
, 0, sizeof(struct mpt3sas_port_facts
));
4939 pfacts
->PortNumber
= mpi_reply
.PortNumber
;
4940 pfacts
->VP_ID
= mpi_reply
.VP_ID
;
4941 pfacts
->VF_ID
= mpi_reply
.VF_ID
;
4942 pfacts
->MaxPostedCmdBuffers
=
4943 le16_to_cpu(mpi_reply
.MaxPostedCmdBuffers
);
4949 * _base_wait_for_iocstate - Wait until the card is in READY or OPERATIONAL
4950 * @ioc: per adapter object
4953 * Returns 0 for success, non-zero for failure.
4956 _base_wait_for_iocstate(struct MPT3SAS_ADAPTER
*ioc
, int timeout
)
4961 dinitprintk(ioc
, printk(MPT3SAS_FMT
"%s\n", ioc
->name
,
4964 if (ioc
->pci_error_recovery
) {
4965 dfailprintk(ioc
, printk(MPT3SAS_FMT
4966 "%s: host in pci error recovery\n", ioc
->name
, __func__
));
4970 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4971 dhsprintk(ioc
, printk(MPT3SAS_FMT
"%s: ioc_state(0x%08x)\n",
4972 ioc
->name
, __func__
, ioc_state
));
4974 if (((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
) ||
4975 (ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
4978 if (ioc_state
& MPI2_DOORBELL_USED
) {
4979 dhsprintk(ioc
, printk(MPT3SAS_FMT
4980 "unexpected doorbell active!\n", ioc
->name
));
4981 goto issue_diag_reset
;
4984 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
4985 mpt3sas_base_fault_info(ioc
, ioc_state
&
4986 MPI2_DOORBELL_DATA_MASK
);
4987 goto issue_diag_reset
;
4990 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, timeout
);
4992 dfailprintk(ioc
, printk(MPT3SAS_FMT
4993 "%s: failed going to ready state (ioc_state=0x%x)\n",
4994 ioc
->name
, __func__
, ioc_state
));
4999 rc
= _base_diag_reset(ioc
);
5004 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
5005 * @ioc: per adapter object
5007 * Returns 0 for success, non-zero for failure.
5010 _base_get_ioc_facts(struct MPT3SAS_ADAPTER
*ioc
)
5012 Mpi2IOCFactsRequest_t mpi_request
;
5013 Mpi2IOCFactsReply_t mpi_reply
;
5014 struct mpt3sas_facts
*facts
;
5015 int mpi_reply_sz
, mpi_request_sz
, r
;
5017 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5020 r
= _base_wait_for_iocstate(ioc
, 10);
5022 dfailprintk(ioc
, printk(MPT3SAS_FMT
5023 "%s: failed getting to correct state\n",
5024 ioc
->name
, __func__
));
5027 mpi_reply_sz
= sizeof(Mpi2IOCFactsReply_t
);
5028 mpi_request_sz
= sizeof(Mpi2IOCFactsRequest_t
);
5029 memset(&mpi_request
, 0, mpi_request_sz
);
5030 mpi_request
.Function
= MPI2_FUNCTION_IOC_FACTS
;
5031 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
5032 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5);
5035 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
5036 ioc
->name
, __func__
, r
);
5040 facts
= &ioc
->facts
;
5041 memset(facts
, 0, sizeof(struct mpt3sas_facts
));
5042 facts
->MsgVersion
= le16_to_cpu(mpi_reply
.MsgVersion
);
5043 facts
->HeaderVersion
= le16_to_cpu(mpi_reply
.HeaderVersion
);
5044 facts
->VP_ID
= mpi_reply
.VP_ID
;
5045 facts
->VF_ID
= mpi_reply
.VF_ID
;
5046 facts
->IOCExceptions
= le16_to_cpu(mpi_reply
.IOCExceptions
);
5047 facts
->MaxChainDepth
= mpi_reply
.MaxChainDepth
;
5048 facts
->WhoInit
= mpi_reply
.WhoInit
;
5049 facts
->NumberOfPorts
= mpi_reply
.NumberOfPorts
;
5050 facts
->MaxMSIxVectors
= mpi_reply
.MaxMSIxVectors
;
5051 facts
->RequestCredit
= le16_to_cpu(mpi_reply
.RequestCredit
);
5052 facts
->MaxReplyDescriptorPostQueueDepth
=
5053 le16_to_cpu(mpi_reply
.MaxReplyDescriptorPostQueueDepth
);
5054 facts
->ProductID
= le16_to_cpu(mpi_reply
.ProductID
);
5055 facts
->IOCCapabilities
= le32_to_cpu(mpi_reply
.IOCCapabilities
);
5056 if ((facts
->IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
))
5057 ioc
->ir_firmware
= 1;
5058 if ((facts
->IOCCapabilities
&
5059 MPI2_IOCFACTS_CAPABILITY_RDPQ_ARRAY_CAPABLE
) && (!reset_devices
))
5060 ioc
->rdpq_array_capable
= 1;
5061 if (facts
->IOCCapabilities
& MPI26_IOCFACTS_CAPABILITY_ATOMIC_REQ
)
5062 ioc
->atomic_desc_capable
= 1;
5063 facts
->FWVersion
.Word
= le32_to_cpu(mpi_reply
.FWVersion
.Word
);
5064 facts
->IOCRequestFrameSize
=
5065 le16_to_cpu(mpi_reply
.IOCRequestFrameSize
);
5066 if (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
) {
5067 facts
->IOCMaxChainSegmentSize
=
5068 le16_to_cpu(mpi_reply
.IOCMaxChainSegmentSize
);
5070 facts
->MaxInitiators
= le16_to_cpu(mpi_reply
.MaxInitiators
);
5071 facts
->MaxTargets
= le16_to_cpu(mpi_reply
.MaxTargets
);
5072 ioc
->shost
->max_id
= -1;
5073 facts
->MaxSasExpanders
= le16_to_cpu(mpi_reply
.MaxSasExpanders
);
5074 facts
->MaxEnclosures
= le16_to_cpu(mpi_reply
.MaxEnclosures
);
5075 facts
->ProtocolFlags
= le16_to_cpu(mpi_reply
.ProtocolFlags
);
5076 facts
->HighPriorityCredit
=
5077 le16_to_cpu(mpi_reply
.HighPriorityCredit
);
5078 facts
->ReplyFrameSize
= mpi_reply
.ReplyFrameSize
;
5079 facts
->MaxDevHandle
= le16_to_cpu(mpi_reply
.MaxDevHandle
);
5080 facts
->CurrentHostPageSize
= mpi_reply
.CurrentHostPageSize
;
5083 * Get the Page Size from IOC Facts. If it's 0, default to 4k.
5085 ioc
->page_size
= 1 << facts
->CurrentHostPageSize
;
5086 if (ioc
->page_size
== 1) {
5087 pr_info(MPT3SAS_FMT
"CurrentHostPageSize is 0: Setting "
5088 "default host page size to 4k\n", ioc
->name
);
5089 ioc
->page_size
= 1 << MPT3SAS_HOST_PAGE_SIZE_4K
;
5091 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"CurrentHostPageSize(%d)\n",
5092 ioc
->name
, facts
->CurrentHostPageSize
));
5094 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
5095 "hba queue depth(%d), max chains per io(%d)\n",
5096 ioc
->name
, facts
->RequestCredit
,
5097 facts
->MaxChainDepth
));
5098 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
5099 "request frame size(%d), reply frame size(%d)\n", ioc
->name
,
5100 facts
->IOCRequestFrameSize
* 4, facts
->ReplyFrameSize
* 4));
5105 * _base_send_ioc_init - send ioc_init to firmware
5106 * @ioc: per adapter object
5108 * Returns 0 for success, non-zero for failure.
5111 _base_send_ioc_init(struct MPT3SAS_ADAPTER
*ioc
)
5113 Mpi2IOCInitRequest_t mpi_request
;
5114 Mpi2IOCInitReply_t mpi_reply
;
5116 ktime_t current_time
;
5118 u32 reply_post_free_array_sz
= 0;
5119 Mpi2IOCInitRDPQArrayEntry
*reply_post_free_array
= NULL
;
5120 dma_addr_t reply_post_free_array_dma
;
5122 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5125 memset(&mpi_request
, 0, sizeof(Mpi2IOCInitRequest_t
));
5126 mpi_request
.Function
= MPI2_FUNCTION_IOC_INIT
;
5127 mpi_request
.WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
5128 mpi_request
.VF_ID
= 0; /* TODO */
5129 mpi_request
.VP_ID
= 0;
5130 mpi_request
.MsgVersion
= cpu_to_le16(ioc
->hba_mpi_version_belonged
);
5131 mpi_request
.HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
5132 mpi_request
.HostPageSize
= MPT3SAS_HOST_PAGE_SIZE_4K
;
5134 if (_base_is_controller_msix_enabled(ioc
))
5135 mpi_request
.HostMSIxVectors
= ioc
->reply_queue_count
;
5136 mpi_request
.SystemRequestFrameSize
= cpu_to_le16(ioc
->request_sz
/4);
5137 mpi_request
.ReplyDescriptorPostQueueDepth
=
5138 cpu_to_le16(ioc
->reply_post_queue_depth
);
5139 mpi_request
.ReplyFreeQueueDepth
=
5140 cpu_to_le16(ioc
->reply_free_queue_depth
);
5142 mpi_request
.SenseBufferAddressHigh
=
5143 cpu_to_le32((u64
)ioc
->sense_dma
>> 32);
5144 mpi_request
.SystemReplyAddressHigh
=
5145 cpu_to_le32((u64
)ioc
->reply_dma
>> 32);
5146 mpi_request
.SystemRequestFrameBaseAddress
=
5147 cpu_to_le64((u64
)ioc
->request_dma
);
5148 mpi_request
.ReplyFreeQueueAddress
=
5149 cpu_to_le64((u64
)ioc
->reply_free_dma
);
5151 if (ioc
->rdpq_array_enable
) {
5152 reply_post_free_array_sz
= ioc
->reply_queue_count
*
5153 sizeof(Mpi2IOCInitRDPQArrayEntry
);
5154 reply_post_free_array
= pci_alloc_consistent(ioc
->pdev
,
5155 reply_post_free_array_sz
, &reply_post_free_array_dma
);
5156 if (!reply_post_free_array
) {
5158 "reply_post_free_array: pci_alloc_consistent failed\n",
5163 memset(reply_post_free_array
, 0, reply_post_free_array_sz
);
5164 for (i
= 0; i
< ioc
->reply_queue_count
; i
++)
5165 reply_post_free_array
[i
].RDPQBaseAddress
=
5167 (u64
)ioc
->reply_post
[i
].reply_post_free_dma
);
5168 mpi_request
.MsgFlags
= MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE
;
5169 mpi_request
.ReplyDescriptorPostQueueAddress
=
5170 cpu_to_le64((u64
)reply_post_free_array_dma
);
5172 mpi_request
.ReplyDescriptorPostQueueAddress
=
5173 cpu_to_le64((u64
)ioc
->reply_post
[0].reply_post_free_dma
);
5176 /* This time stamp specifies number of milliseconds
5177 * since epoch ~ midnight January 1, 1970.
5179 current_time
= ktime_get_real();
5180 mpi_request
.TimeStamp
= cpu_to_le64(ktime_to_ms(current_time
));
5182 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
5186 mfp
= (__le32
*)&mpi_request
;
5187 pr_info("\toffset:data\n");
5188 for (i
= 0; i
< sizeof(Mpi2IOCInitRequest_t
)/4; i
++)
5189 pr_info("\t[0x%02x]:%08x\n", i
*4,
5190 le32_to_cpu(mfp
[i
]));
5193 r
= _base_handshake_req_reply_wait(ioc
,
5194 sizeof(Mpi2IOCInitRequest_t
), (u32
*)&mpi_request
,
5195 sizeof(Mpi2IOCInitReply_t
), (u16
*)&mpi_reply
, 10);
5198 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
5199 ioc
->name
, __func__
, r
);
5203 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5204 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
||
5205 mpi_reply
.IOCLogInfo
) {
5206 pr_err(MPT3SAS_FMT
"%s: failed\n", ioc
->name
, __func__
);
5211 if (reply_post_free_array
)
5212 pci_free_consistent(ioc
->pdev
, reply_post_free_array_sz
,
5213 reply_post_free_array
,
5214 reply_post_free_array_dma
);
5219 * mpt3sas_port_enable_done - command completion routine for port enable
5220 * @ioc: per adapter object
5221 * @smid: system request message index
5222 * @msix_index: MSIX table index supplied by the OS
5223 * @reply: reply message frame(lower 32bit addr)
5225 * Return 1 meaning mf should be freed from _base_interrupt
5226 * 0 means the mf is freed from this function.
5229 mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
5232 MPI2DefaultReply_t
*mpi_reply
;
5235 if (ioc
->port_enable_cmds
.status
== MPT3_CMD_NOT_USED
)
5238 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
5242 if (mpi_reply
->Function
!= MPI2_FUNCTION_PORT_ENABLE
)
5245 ioc
->port_enable_cmds
.status
&= ~MPT3_CMD_PENDING
;
5246 ioc
->port_enable_cmds
.status
|= MPT3_CMD_COMPLETE
;
5247 ioc
->port_enable_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
5248 memcpy(ioc
->port_enable_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
5249 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5250 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
5251 ioc
->port_enable_failed
= 1;
5253 if (ioc
->is_driver_loading
) {
5254 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
5255 mpt3sas_port_enable_complete(ioc
);
5258 ioc
->start_scan_failed
= ioc_status
;
5259 ioc
->start_scan
= 0;
5263 complete(&ioc
->port_enable_cmds
.done
);
5268 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
5269 * @ioc: per adapter object
5271 * Returns 0 for success, non-zero for failure.
5274 _base_send_port_enable(struct MPT3SAS_ADAPTER
*ioc
)
5276 Mpi2PortEnableRequest_t
*mpi_request
;
5277 Mpi2PortEnableReply_t
*mpi_reply
;
5282 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
5284 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
5285 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
5286 ioc
->name
, __func__
);
5290 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
5292 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
5293 ioc
->name
, __func__
);
5297 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
5298 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5299 ioc
->port_enable_cmds
.smid
= smid
;
5300 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
5301 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
5303 init_completion(&ioc
->port_enable_cmds
.done
);
5304 ioc
->put_smid_default(ioc
, smid
);
5305 wait_for_completion_timeout(&ioc
->port_enable_cmds
.done
, 300*HZ
);
5306 if (!(ioc
->port_enable_cmds
.status
& MPT3_CMD_COMPLETE
)) {
5307 pr_err(MPT3SAS_FMT
"%s: timeout\n",
5308 ioc
->name
, __func__
);
5309 _debug_dump_mf(mpi_request
,
5310 sizeof(Mpi2PortEnableRequest_t
)/4);
5311 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_RESET
)
5318 mpi_reply
= ioc
->port_enable_cmds
.reply
;
5319 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
5320 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
5321 pr_err(MPT3SAS_FMT
"%s: failed with (ioc_status=0x%08x)\n",
5322 ioc
->name
, __func__
, ioc_status
);
5328 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
5329 pr_info(MPT3SAS_FMT
"port enable: %s\n", ioc
->name
, ((r
== 0) ?
5330 "SUCCESS" : "FAILED"));
5335 * mpt3sas_port_enable - initiate firmware discovery (don't wait for reply)
5336 * @ioc: per adapter object
5338 * Returns 0 for success, non-zero for failure.
5341 mpt3sas_port_enable(struct MPT3SAS_ADAPTER
*ioc
)
5343 Mpi2PortEnableRequest_t
*mpi_request
;
5346 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
5348 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
5349 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
5350 ioc
->name
, __func__
);
5354 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
5356 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
5357 ioc
->name
, __func__
);
5361 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
5362 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5363 ioc
->port_enable_cmds
.smid
= smid
;
5364 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
5365 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
5367 ioc
->put_smid_default(ioc
, smid
);
5372 * _base_determine_wait_on_discovery - desposition
5373 * @ioc: per adapter object
5375 * Decide whether to wait on discovery to complete. Used to either
5376 * locate boot device, or report volumes ahead of physical devices.
5378 * Returns 1 for wait, 0 for don't wait
5381 _base_determine_wait_on_discovery(struct MPT3SAS_ADAPTER
*ioc
)
5383 /* We wait for discovery to complete if IR firmware is loaded.
5384 * The sas topology events arrive before PD events, so we need time to
5385 * turn on the bit in ioc->pd_handles to indicate PD
5386 * Also, it maybe required to report Volumes ahead of physical
5387 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
5389 if (ioc
->ir_firmware
)
5392 /* if no Bios, then we don't need to wait */
5393 if (!ioc
->bios_pg3
.BiosVersion
)
5396 /* Bios is present, then we drop down here.
5398 * If there any entries in the Bios Page 2, then we wait
5399 * for discovery to complete.
5402 /* Current Boot Device */
5403 if ((ioc
->bios_pg2
.CurrentBootDeviceForm
&
5404 MPI2_BIOSPAGE2_FORM_MASK
) ==
5405 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
5406 /* Request Boot Device */
5407 (ioc
->bios_pg2
.ReqBootDeviceForm
&
5408 MPI2_BIOSPAGE2_FORM_MASK
) ==
5409 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
5410 /* Alternate Request Boot Device */
5411 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
5412 MPI2_BIOSPAGE2_FORM_MASK
) ==
5413 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
)
5420 * _base_unmask_events - turn on notification for this event
5421 * @ioc: per adapter object
5422 * @event: firmware event
5424 * The mask is stored in ioc->event_masks.
5427 _base_unmask_events(struct MPT3SAS_ADAPTER
*ioc
, u16 event
)
5434 desired_event
= (1 << (event
% 32));
5437 ioc
->event_masks
[0] &= ~desired_event
;
5438 else if (event
< 64)
5439 ioc
->event_masks
[1] &= ~desired_event
;
5440 else if (event
< 96)
5441 ioc
->event_masks
[2] &= ~desired_event
;
5442 else if (event
< 128)
5443 ioc
->event_masks
[3] &= ~desired_event
;
5447 * _base_event_notification - send event notification
5448 * @ioc: per adapter object
5450 * Returns 0 for success, non-zero for failure.
5453 _base_event_notification(struct MPT3SAS_ADAPTER
*ioc
)
5455 Mpi2EventNotificationRequest_t
*mpi_request
;
5460 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5463 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
5464 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
5465 ioc
->name
, __func__
);
5469 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
5471 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
5472 ioc
->name
, __func__
);
5475 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
5476 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
5477 ioc
->base_cmds
.smid
= smid
;
5478 memset(mpi_request
, 0, sizeof(Mpi2EventNotificationRequest_t
));
5479 mpi_request
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
5480 mpi_request
->VF_ID
= 0; /* TODO */
5481 mpi_request
->VP_ID
= 0;
5482 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
5483 mpi_request
->EventMasks
[i
] =
5484 cpu_to_le32(ioc
->event_masks
[i
]);
5485 init_completion(&ioc
->base_cmds
.done
);
5486 ioc
->put_smid_default(ioc
, smid
);
5487 wait_for_completion_timeout(&ioc
->base_cmds
.done
, 30*HZ
);
5488 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
5489 pr_err(MPT3SAS_FMT
"%s: timeout\n",
5490 ioc
->name
, __func__
);
5491 _debug_dump_mf(mpi_request
,
5492 sizeof(Mpi2EventNotificationRequest_t
)/4);
5493 if (ioc
->base_cmds
.status
& MPT3_CMD_RESET
)
5498 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: complete\n",
5499 ioc
->name
, __func__
));
5500 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
5505 * mpt3sas_base_validate_event_type - validating event types
5506 * @ioc: per adapter object
5507 * @event: firmware event
5509 * This will turn on firmware event notification when application
5510 * ask for that event. We don't mask events that are already enabled.
5513 mpt3sas_base_validate_event_type(struct MPT3SAS_ADAPTER
*ioc
, u32
*event_type
)
5516 u32 event_mask
, desired_event
;
5517 u8 send_update_to_fw
;
5519 for (i
= 0, send_update_to_fw
= 0; i
<
5520 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++) {
5521 event_mask
= ~event_type
[i
];
5523 for (j
= 0; j
< 32; j
++) {
5524 if (!(event_mask
& desired_event
) &&
5525 (ioc
->event_masks
[i
] & desired_event
)) {
5526 ioc
->event_masks
[i
] &= ~desired_event
;
5527 send_update_to_fw
= 1;
5529 desired_event
= (desired_event
<< 1);
5533 if (!send_update_to_fw
)
5536 mutex_lock(&ioc
->base_cmds
.mutex
);
5537 _base_event_notification(ioc
);
5538 mutex_unlock(&ioc
->base_cmds
.mutex
);
5542 * _base_diag_reset - the "big hammer" start of day reset
5543 * @ioc: per adapter object
5545 * Returns 0 for success, non-zero for failure.
5548 _base_diag_reset(struct MPT3SAS_ADAPTER
*ioc
)
5550 u32 host_diagnostic
;
5555 pr_info(MPT3SAS_FMT
"sending diag reset !!\n", ioc
->name
);
5557 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"clear interrupts\n",
5562 /* Write magic sequence to WriteSequence register
5563 * Loop until in diagnostic mode
5565 drsprintk(ioc
, pr_info(MPT3SAS_FMT
5566 "write magic sequence\n", ioc
->name
));
5567 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5568 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5569 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5570 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5571 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5572 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5573 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5581 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
5582 drsprintk(ioc
, pr_info(MPT3SAS_FMT
5583 "wrote magic sequence: count(%d), host_diagnostic(0x%08x)\n",
5584 ioc
->name
, count
, host_diagnostic
));
5586 } while ((host_diagnostic
& MPI2_DIAG_DIAG_WRITE_ENABLE
) == 0);
5588 hcb_size
= readl(&ioc
->chip
->HCBSize
);
5590 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"diag reset: issued\n",
5592 writel(host_diagnostic
| MPI2_DIAG_RESET_ADAPTER
,
5593 &ioc
->chip
->HostDiagnostic
);
5595 /*This delay allows the chip PCIe hardware time to finish reset tasks*/
5596 msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
5598 /* Approximately 300 second max wait */
5599 for (count
= 0; count
< (300000000 /
5600 MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
); count
++) {
5602 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
5604 if (host_diagnostic
== 0xFFFFFFFF)
5606 if (!(host_diagnostic
& MPI2_DIAG_RESET_ADAPTER
))
5609 msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
/ 1000);
5612 if (host_diagnostic
& MPI2_DIAG_HCB_MODE
) {
5614 drsprintk(ioc
, pr_info(MPT3SAS_FMT
5615 "restart the adapter assuming the HCB Address points to good F/W\n",
5617 host_diagnostic
&= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK
;
5618 host_diagnostic
|= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW
;
5619 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
5621 drsprintk(ioc
, pr_info(MPT3SAS_FMT
5622 "re-enable the HCDW\n", ioc
->name
));
5623 writel(hcb_size
| MPI2_HCB_SIZE_HCB_ENABLE
,
5624 &ioc
->chip
->HCBSize
);
5627 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"restart the adapter\n",
5629 writel(host_diagnostic
& ~MPI2_DIAG_HOLD_IOC_RESET
,
5630 &ioc
->chip
->HostDiagnostic
);
5632 drsprintk(ioc
, pr_info(MPT3SAS_FMT
5633 "disable writes to the diagnostic register\n", ioc
->name
));
5634 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
5636 drsprintk(ioc
, pr_info(MPT3SAS_FMT
5637 "Wait for FW to go to the READY state\n", ioc
->name
));
5638 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, 20);
5641 "%s: failed going to ready state (ioc_state=0x%x)\n",
5642 ioc
->name
, __func__
, ioc_state
);
5646 pr_info(MPT3SAS_FMT
"diag reset: SUCCESS\n", ioc
->name
);
5650 pr_err(MPT3SAS_FMT
"diag reset: FAILED\n", ioc
->name
);
5655 * _base_make_ioc_ready - put controller in READY state
5656 * @ioc: per adapter object
5657 * @type: FORCE_BIG_HAMMER or SOFT_RESET
5659 * Returns 0 for success, non-zero for failure.
5662 _base_make_ioc_ready(struct MPT3SAS_ADAPTER
*ioc
, enum reset_type type
)
5668 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5671 if (ioc
->pci_error_recovery
)
5674 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
5675 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: ioc_state(0x%08x)\n",
5676 ioc
->name
, __func__
, ioc_state
));
5678 /* if in RESET state, it should move to READY state shortly */
5680 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_RESET
) {
5681 while ((ioc_state
& MPI2_IOC_STATE_MASK
) !=
5682 MPI2_IOC_STATE_READY
) {
5683 if (count
++ == 10) {
5685 "%s: failed going to ready state (ioc_state=0x%x)\n",
5686 ioc
->name
, __func__
, ioc_state
);
5690 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
5694 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
)
5697 if (ioc_state
& MPI2_DOORBELL_USED
) {
5698 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
5699 "unexpected doorbell active!\n",
5701 goto issue_diag_reset
;
5704 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
5705 mpt3sas_base_fault_info(ioc
, ioc_state
&
5706 MPI2_DOORBELL_DATA_MASK
);
5707 goto issue_diag_reset
;
5710 if (type
== FORCE_BIG_HAMMER
)
5711 goto issue_diag_reset
;
5713 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
5714 if (!(_base_send_ioc_reset(ioc
,
5715 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
, 15))) {
5720 rc
= _base_diag_reset(ioc
);
5725 * _base_make_ioc_operational - put controller in OPERATIONAL state
5726 * @ioc: per adapter object
5728 * Returns 0 for success, non-zero for failure.
5731 _base_make_ioc_operational(struct MPT3SAS_ADAPTER
*ioc
)
5734 unsigned long flags
;
5737 struct _tr_list
*delayed_tr
, *delayed_tr_next
;
5738 struct _sc_list
*delayed_sc
, *delayed_sc_next
;
5739 struct _event_ack_list
*delayed_event_ack
, *delayed_event_ack_next
;
5741 struct adapter_reply_queue
*reply_q
;
5742 Mpi2ReplyDescriptorsUnion_t
*reply_post_free_contig
;
5744 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5747 /* clean the delayed target reset list */
5748 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
5749 &ioc
->delayed_tr_list
, list
) {
5750 list_del(&delayed_tr
->list
);
5755 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
5756 &ioc
->delayed_tr_volume_list
, list
) {
5757 list_del(&delayed_tr
->list
);
5761 list_for_each_entry_safe(delayed_sc
, delayed_sc_next
,
5762 &ioc
->delayed_sc_list
, list
) {
5763 list_del(&delayed_sc
->list
);
5767 list_for_each_entry_safe(delayed_event_ack
, delayed_event_ack_next
,
5768 &ioc
->delayed_event_ack_list
, list
) {
5769 list_del(&delayed_event_ack
->list
);
5770 kfree(delayed_event_ack
);
5773 /* initialize the scsi lookup free list */
5774 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
5775 INIT_LIST_HEAD(&ioc
->free_list
);
5777 for (i
= 0; i
< ioc
->scsiio_depth
; i
++, smid
++) {
5778 INIT_LIST_HEAD(&ioc
->scsi_lookup
[i
].chain_list
);
5779 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
5780 ioc
->scsi_lookup
[i
].smid
= smid
;
5781 ioc
->scsi_lookup
[i
].scmd
= NULL
;
5782 ioc
->scsi_lookup
[i
].direct_io
= 0;
5783 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
5787 /* hi-priority queue */
5788 INIT_LIST_HEAD(&ioc
->hpr_free_list
);
5789 smid
= ioc
->hi_priority_smid
;
5790 for (i
= 0; i
< ioc
->hi_priority_depth
; i
++, smid
++) {
5791 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
5792 ioc
->hpr_lookup
[i
].smid
= smid
;
5793 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
5794 &ioc
->hpr_free_list
);
5797 /* internal queue */
5798 INIT_LIST_HEAD(&ioc
->internal_free_list
);
5799 smid
= ioc
->internal_smid
;
5800 for (i
= 0; i
< ioc
->internal_depth
; i
++, smid
++) {
5801 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
5802 ioc
->internal_lookup
[i
].smid
= smid
;
5803 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
5804 &ioc
->internal_free_list
);
5808 INIT_LIST_HEAD(&ioc
->free_chain_list
);
5809 for (i
= 0; i
< ioc
->chain_depth
; i
++)
5810 list_add_tail(&ioc
->chain_lookup
[i
].tracker_list
,
5811 &ioc
->free_chain_list
);
5813 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
5815 /* initialize Reply Free Queue */
5816 for (i
= 0, reply_address
= (u32
)ioc
->reply_dma
;
5817 i
< ioc
->reply_free_queue_depth
; i
++, reply_address
+=
5819 ioc
->reply_free
[i
] = cpu_to_le32(reply_address
);
5821 /* initialize reply queues */
5822 if (ioc
->is_driver_loading
)
5823 _base_assign_reply_queues(ioc
);
5825 /* initialize Reply Post Free Queue */
5827 reply_post_free_contig
= ioc
->reply_post
[0].reply_post_free
;
5828 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
5830 * If RDPQ is enabled, switch to the next allocation.
5831 * Otherwise advance within the contiguous region.
5833 if (ioc
->rdpq_array_enable
) {
5834 reply_q
->reply_post_free
=
5835 ioc
->reply_post
[index
++].reply_post_free
;
5837 reply_q
->reply_post_free
= reply_post_free_contig
;
5838 reply_post_free_contig
+= ioc
->reply_post_queue_depth
;
5841 reply_q
->reply_post_host_index
= 0;
5842 for (i
= 0; i
< ioc
->reply_post_queue_depth
; i
++)
5843 reply_q
->reply_post_free
[i
].Words
=
5844 cpu_to_le64(ULLONG_MAX
);
5845 if (!_base_is_controller_msix_enabled(ioc
))
5846 goto skip_init_reply_post_free_queue
;
5848 skip_init_reply_post_free_queue
:
5850 r
= _base_send_ioc_init(ioc
);
5854 /* initialize reply free host index */
5855 ioc
->reply_free_host_index
= ioc
->reply_free_queue_depth
- 1;
5856 writel(ioc
->reply_free_host_index
, &ioc
->chip
->ReplyFreeHostIndex
);
5858 /* initialize reply post host index */
5859 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
5860 if (ioc
->combined_reply_queue
)
5861 writel((reply_q
->msix_index
& 7)<<
5862 MPI2_RPHI_MSIX_INDEX_SHIFT
,
5863 ioc
->replyPostRegisterIndex
[reply_q
->msix_index
/8]);
5865 writel(reply_q
->msix_index
<<
5866 MPI2_RPHI_MSIX_INDEX_SHIFT
,
5867 &ioc
->chip
->ReplyPostHostIndex
);
5869 if (!_base_is_controller_msix_enabled(ioc
))
5870 goto skip_init_reply_post_host_index
;
5873 skip_init_reply_post_host_index
:
5875 _base_unmask_interrupts(ioc
);
5876 r
= _base_event_notification(ioc
);
5880 _base_static_config_pages(ioc
);
5882 if (ioc
->is_driver_loading
) {
5884 if (ioc
->is_warpdrive
&& ioc
->manu_pg10
.OEMIdentifier
5887 le32_to_cpu(ioc
->manu_pg10
.OEMSpecificFlags0
) &
5888 MFG_PAGE10_HIDE_SSDS_MASK
);
5889 if (hide_flag
!= MFG_PAGE10_HIDE_SSDS_MASK
)
5890 ioc
->mfg_pg10_hide_flag
= hide_flag
;
5893 ioc
->wait_for_discovery_to_complete
=
5894 _base_determine_wait_on_discovery(ioc
);
5896 return r
; /* scan_start and scan_finished support */
5899 r
= _base_send_port_enable(ioc
);
5907 * mpt3sas_base_free_resources - free resources controller resources
5908 * @ioc: per adapter object
5913 mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER
*ioc
)
5915 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5918 /* synchronizing freeing resource with pci_access_mutex lock */
5919 mutex_lock(&ioc
->pci_access_mutex
);
5920 if (ioc
->chip_phys
&& ioc
->chip
) {
5921 _base_mask_interrupts(ioc
);
5922 ioc
->shost_recovery
= 1;
5923 _base_make_ioc_ready(ioc
, SOFT_RESET
);
5924 ioc
->shost_recovery
= 0;
5927 mpt3sas_base_unmap_resources(ioc
);
5928 mutex_unlock(&ioc
->pci_access_mutex
);
5933 * mpt3sas_base_attach - attach controller instance
5934 * @ioc: per adapter object
5936 * Returns 0 for success, non-zero for failure.
5939 mpt3sas_base_attach(struct MPT3SAS_ADAPTER
*ioc
)
5942 int cpu_id
, last_cpu_id
= 0;
5944 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
5947 /* setup cpu_msix_table */
5948 ioc
->cpu_count
= num_online_cpus();
5949 for_each_online_cpu(cpu_id
)
5950 last_cpu_id
= cpu_id
;
5951 ioc
->cpu_msix_table_sz
= last_cpu_id
+ 1;
5952 ioc
->cpu_msix_table
= kzalloc(ioc
->cpu_msix_table_sz
, GFP_KERNEL
);
5953 ioc
->reply_queue_count
= 1;
5954 if (!ioc
->cpu_msix_table
) {
5955 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
5956 "allocation for cpu_msix_table failed!!!\n",
5959 goto out_free_resources
;
5962 if (ioc
->is_warpdrive
) {
5963 ioc
->reply_post_host_index
= kcalloc(ioc
->cpu_msix_table_sz
,
5964 sizeof(resource_size_t
*), GFP_KERNEL
);
5965 if (!ioc
->reply_post_host_index
) {
5966 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
"allocation "
5967 "for reply_post_host_index failed!!!\n",
5970 goto out_free_resources
;
5974 ioc
->rdpq_array_enable_assigned
= 0;
5976 r
= mpt3sas_base_map_resources(ioc
);
5978 goto out_free_resources
;
5980 pci_set_drvdata(ioc
->pdev
, ioc
->shost
);
5981 r
= _base_get_ioc_facts(ioc
);
5983 goto out_free_resources
;
5985 switch (ioc
->hba_mpi_version_belonged
) {
5987 ioc
->build_sg_scmd
= &_base_build_sg_scmd
;
5988 ioc
->build_sg
= &_base_build_sg
;
5989 ioc
->build_zero_len_sge
= &_base_build_zero_len_sge
;
5995 * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and
5996 * Target Status - all require the IEEE formated scatter gather
5999 ioc
->build_sg_scmd
= &_base_build_sg_scmd_ieee
;
6000 ioc
->build_sg
= &_base_build_sg_ieee
;
6001 ioc
->build_nvme_prp
= &_base_build_nvme_prp
;
6002 ioc
->build_zero_len_sge
= &_base_build_zero_len_sge_ieee
;
6003 ioc
->sge_size_ieee
= sizeof(Mpi2IeeeSgeSimple64_t
);
6008 if (ioc
->atomic_desc_capable
) {
6009 ioc
->put_smid_default
= &_base_put_smid_default_atomic
;
6010 ioc
->put_smid_scsi_io
= &_base_put_smid_scsi_io_atomic
;
6011 ioc
->put_smid_fast_path
= &_base_put_smid_fast_path_atomic
;
6012 ioc
->put_smid_hi_priority
= &_base_put_smid_hi_priority_atomic
;
6013 ioc
->put_smid_nvme_encap
= &_base_put_smid_nvme_encap_atomic
;
6015 ioc
->put_smid_default
= &_base_put_smid_default
;
6016 ioc
->put_smid_scsi_io
= &_base_put_smid_scsi_io
;
6017 ioc
->put_smid_fast_path
= &_base_put_smid_fast_path
;
6018 ioc
->put_smid_hi_priority
= &_base_put_smid_hi_priority
;
6019 ioc
->put_smid_nvme_encap
= &_base_put_smid_nvme_encap
;
6024 * These function pointers for other requests that don't
6025 * the require IEEE scatter gather elements.
6027 * For example Configuration Pages and SAS IOUNIT Control don't.
6029 ioc
->build_sg_mpi
= &_base_build_sg
;
6030 ioc
->build_zero_len_sge_mpi
= &_base_build_zero_len_sge
;
6032 r
= _base_make_ioc_ready(ioc
, SOFT_RESET
);
6034 goto out_free_resources
;
6036 ioc
->pfacts
= kcalloc(ioc
->facts
.NumberOfPorts
,
6037 sizeof(struct mpt3sas_port_facts
), GFP_KERNEL
);
6040 goto out_free_resources
;
6043 for (i
= 0 ; i
< ioc
->facts
.NumberOfPorts
; i
++) {
6044 r
= _base_get_port_facts(ioc
, i
);
6046 goto out_free_resources
;
6049 r
= _base_allocate_memory_pools(ioc
);
6051 goto out_free_resources
;
6053 init_waitqueue_head(&ioc
->reset_wq
);
6055 /* allocate memory pd handle bitmask list */
6056 ioc
->pd_handles_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
6057 if (ioc
->facts
.MaxDevHandle
% 8)
6058 ioc
->pd_handles_sz
++;
6059 ioc
->pd_handles
= kzalloc(ioc
->pd_handles_sz
,
6061 if (!ioc
->pd_handles
) {
6063 goto out_free_resources
;
6065 ioc
->blocking_handles
= kzalloc(ioc
->pd_handles_sz
,
6067 if (!ioc
->blocking_handles
) {
6069 goto out_free_resources
;
6072 /* allocate memory for pending OS device add list */
6073 ioc
->pend_os_device_add_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
6074 if (ioc
->facts
.MaxDevHandle
% 8)
6075 ioc
->pend_os_device_add_sz
++;
6076 ioc
->pend_os_device_add
= kzalloc(ioc
->pend_os_device_add_sz
,
6078 if (!ioc
->pend_os_device_add
)
6079 goto out_free_resources
;
6081 ioc
->device_remove_in_progress_sz
= ioc
->pend_os_device_add_sz
;
6082 ioc
->device_remove_in_progress
=
6083 kzalloc(ioc
->device_remove_in_progress_sz
, GFP_KERNEL
);
6084 if (!ioc
->device_remove_in_progress
)
6085 goto out_free_resources
;
6087 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
6089 /* base internal command bits */
6090 mutex_init(&ioc
->base_cmds
.mutex
);
6091 ioc
->base_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
6092 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
6094 /* port_enable command bits */
6095 ioc
->port_enable_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
6096 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
6098 /* transport internal command bits */
6099 ioc
->transport_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
6100 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
6101 mutex_init(&ioc
->transport_cmds
.mutex
);
6103 /* scsih internal command bits */
6104 ioc
->scsih_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
6105 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
6106 mutex_init(&ioc
->scsih_cmds
.mutex
);
6108 /* task management internal command bits */
6109 ioc
->tm_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
6110 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
6111 mutex_init(&ioc
->tm_cmds
.mutex
);
6113 /* config page internal command bits */
6114 ioc
->config_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
6115 ioc
->config_cmds
.status
= MPT3_CMD_NOT_USED
;
6116 mutex_init(&ioc
->config_cmds
.mutex
);
6118 /* ctl module internal command bits */
6119 ioc
->ctl_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
6120 ioc
->ctl_cmds
.sense
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
6121 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
6122 mutex_init(&ioc
->ctl_cmds
.mutex
);
6124 if (!ioc
->base_cmds
.reply
|| !ioc
->port_enable_cmds
.reply
||
6125 !ioc
->transport_cmds
.reply
|| !ioc
->scsih_cmds
.reply
||
6126 !ioc
->tm_cmds
.reply
|| !ioc
->config_cmds
.reply
||
6127 !ioc
->ctl_cmds
.reply
|| !ioc
->ctl_cmds
.sense
) {
6129 goto out_free_resources
;
6132 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
6133 ioc
->event_masks
[i
] = -1;
6135 /* here we enable the events we care about */
6136 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DISCOVERY
);
6137 _base_unmask_events(ioc
, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
);
6138 _base_unmask_events(ioc
, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
6139 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
6140 _base_unmask_events(ioc
, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
);
6141 _base_unmask_events(ioc
, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
);
6142 _base_unmask_events(ioc
, MPI2_EVENT_IR_VOLUME
);
6143 _base_unmask_events(ioc
, MPI2_EVENT_IR_PHYSICAL_DISK
);
6144 _base_unmask_events(ioc
, MPI2_EVENT_IR_OPERATION_STATUS
);
6145 _base_unmask_events(ioc
, MPI2_EVENT_LOG_ENTRY_ADDED
);
6146 _base_unmask_events(ioc
, MPI2_EVENT_TEMP_THRESHOLD
);
6147 _base_unmask_events(ioc
, MPI2_EVENT_ACTIVE_CABLE_EXCEPTION
);
6148 if (ioc
->hba_mpi_version_belonged
== MPI26_VERSION
) {
6149 if (ioc
->is_gen35_ioc
) {
6150 _base_unmask_events(ioc
,
6151 MPI2_EVENT_PCIE_DEVICE_STATUS_CHANGE
);
6152 _base_unmask_events(ioc
, MPI2_EVENT_PCIE_ENUMERATION
);
6153 _base_unmask_events(ioc
,
6154 MPI2_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
);
6157 r
= _base_make_ioc_operational(ioc
);
6159 goto out_free_resources
;
6161 ioc
->non_operational_loop
= 0;
6162 ioc
->got_task_abort_from_ioctl
= 0;
6167 ioc
->remove_host
= 1;
6169 mpt3sas_base_free_resources(ioc
);
6170 _base_release_memory_pools(ioc
);
6171 pci_set_drvdata(ioc
->pdev
, NULL
);
6172 kfree(ioc
->cpu_msix_table
);
6173 if (ioc
->is_warpdrive
)
6174 kfree(ioc
->reply_post_host_index
);
6175 kfree(ioc
->pd_handles
);
6176 kfree(ioc
->blocking_handles
);
6177 kfree(ioc
->device_remove_in_progress
);
6178 kfree(ioc
->pend_os_device_add
);
6179 kfree(ioc
->tm_cmds
.reply
);
6180 kfree(ioc
->transport_cmds
.reply
);
6181 kfree(ioc
->scsih_cmds
.reply
);
6182 kfree(ioc
->config_cmds
.reply
);
6183 kfree(ioc
->base_cmds
.reply
);
6184 kfree(ioc
->port_enable_cmds
.reply
);
6185 kfree(ioc
->ctl_cmds
.reply
);
6186 kfree(ioc
->ctl_cmds
.sense
);
6188 ioc
->ctl_cmds
.reply
= NULL
;
6189 ioc
->base_cmds
.reply
= NULL
;
6190 ioc
->tm_cmds
.reply
= NULL
;
6191 ioc
->scsih_cmds
.reply
= NULL
;
6192 ioc
->transport_cmds
.reply
= NULL
;
6193 ioc
->config_cmds
.reply
= NULL
;
6200 * mpt3sas_base_detach - remove controller instance
6201 * @ioc: per adapter object
6206 mpt3sas_base_detach(struct MPT3SAS_ADAPTER
*ioc
)
6208 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
6211 mpt3sas_base_stop_watchdog(ioc
);
6212 mpt3sas_base_free_resources(ioc
);
6213 _base_release_memory_pools(ioc
);
6214 pci_set_drvdata(ioc
->pdev
, NULL
);
6215 kfree(ioc
->cpu_msix_table
);
6216 if (ioc
->is_warpdrive
)
6217 kfree(ioc
->reply_post_host_index
);
6218 kfree(ioc
->pd_handles
);
6219 kfree(ioc
->blocking_handles
);
6220 kfree(ioc
->device_remove_in_progress
);
6221 kfree(ioc
->pend_os_device_add
);
6223 kfree(ioc
->ctl_cmds
.reply
);
6224 kfree(ioc
->ctl_cmds
.sense
);
6225 kfree(ioc
->base_cmds
.reply
);
6226 kfree(ioc
->port_enable_cmds
.reply
);
6227 kfree(ioc
->tm_cmds
.reply
);
6228 kfree(ioc
->transport_cmds
.reply
);
6229 kfree(ioc
->scsih_cmds
.reply
);
6230 kfree(ioc
->config_cmds
.reply
);
6234 * _base_reset_handler - reset callback handler (for base)
6235 * @ioc: per adapter object
6236 * @reset_phase: phase
6238 * The handler for doing any required cleanup or initialization.
6240 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
6241 * MPT3_IOC_DONE_RESET
6246 _base_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
6248 mpt3sas_scsih_reset_handler(ioc
, reset_phase
);
6249 mpt3sas_ctl_reset_handler(ioc
, reset_phase
);
6250 switch (reset_phase
) {
6251 case MPT3_IOC_PRE_RESET
:
6252 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
6253 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
6255 case MPT3_IOC_AFTER_RESET
:
6256 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
6257 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
6258 if (ioc
->transport_cmds
.status
& MPT3_CMD_PENDING
) {
6259 ioc
->transport_cmds
.status
|= MPT3_CMD_RESET
;
6260 mpt3sas_base_free_smid(ioc
, ioc
->transport_cmds
.smid
);
6261 complete(&ioc
->transport_cmds
.done
);
6263 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
6264 ioc
->base_cmds
.status
|= MPT3_CMD_RESET
;
6265 mpt3sas_base_free_smid(ioc
, ioc
->base_cmds
.smid
);
6266 complete(&ioc
->base_cmds
.done
);
6268 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
6269 ioc
->port_enable_failed
= 1;
6270 ioc
->port_enable_cmds
.status
|= MPT3_CMD_RESET
;
6271 mpt3sas_base_free_smid(ioc
, ioc
->port_enable_cmds
.smid
);
6272 if (ioc
->is_driver_loading
) {
6273 ioc
->start_scan_failed
=
6274 MPI2_IOCSTATUS_INTERNAL_ERROR
;
6275 ioc
->start_scan
= 0;
6276 ioc
->port_enable_cmds
.status
=
6279 complete(&ioc
->port_enable_cmds
.done
);
6281 if (ioc
->config_cmds
.status
& MPT3_CMD_PENDING
) {
6282 ioc
->config_cmds
.status
|= MPT3_CMD_RESET
;
6283 mpt3sas_base_free_smid(ioc
, ioc
->config_cmds
.smid
);
6284 ioc
->config_cmds
.smid
= USHRT_MAX
;
6285 complete(&ioc
->config_cmds
.done
);
6288 case MPT3_IOC_DONE_RESET
:
6289 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
6290 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
6296 * _wait_for_commands_to_complete - reset controller
6297 * @ioc: Pointer to MPT_ADAPTER structure
6299 * This function waiting(3s) for all pending commands to complete
6300 * prior to putting controller in reset.
6303 _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER
*ioc
)
6306 unsigned long flags
;
6309 ioc
->pending_io_count
= 0;
6311 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
6312 if ((ioc_state
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
)
6315 /* pending command count */
6316 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
6317 for (i
= 0; i
< ioc
->scsiio_depth
; i
++)
6318 if (ioc
->scsi_lookup
[i
].cb_idx
!= 0xFF)
6319 ioc
->pending_io_count
++;
6320 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
6322 if (!ioc
->pending_io_count
)
6325 /* wait for pending commands to complete */
6326 wait_event_timeout(ioc
->reset_wq
, ioc
->pending_io_count
== 0, 10 * HZ
);
6330 * mpt3sas_base_hard_reset_handler - reset controller
6331 * @ioc: Pointer to MPT_ADAPTER structure
6332 * @type: FORCE_BIG_HAMMER or SOFT_RESET
6334 * Returns 0 for success, non-zero for failure.
6337 mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER
*ioc
,
6338 enum reset_type type
)
6341 unsigned long flags
;
6343 u8 is_fault
= 0, is_trigger
= 0;
6345 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
6348 if (ioc
->pci_error_recovery
) {
6349 pr_err(MPT3SAS_FMT
"%s: pci error recovery reset\n",
6350 ioc
->name
, __func__
);
6355 if (mpt3sas_fwfault_debug
)
6356 mpt3sas_halt_firmware(ioc
);
6358 /* wait for an active reset in progress to complete */
6359 if (!mutex_trylock(&ioc
->reset_in_progress_mutex
)) {
6362 } while (ioc
->shost_recovery
== 1);
6363 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,
6365 return ioc
->ioc_reset_in_progress_status
;
6368 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6369 ioc
->shost_recovery
= 1;
6370 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
6372 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
6373 MPT3_DIAG_BUFFER_IS_REGISTERED
) &&
6374 (!(ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
6375 MPT3_DIAG_BUFFER_IS_RELEASED
))) {
6377 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
6378 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
6381 _base_reset_handler(ioc
, MPT3_IOC_PRE_RESET
);
6382 _wait_for_commands_to_complete(ioc
);
6383 _base_mask_interrupts(ioc
);
6384 r
= _base_make_ioc_ready(ioc
, type
);
6387 _base_reset_handler(ioc
, MPT3_IOC_AFTER_RESET
);
6389 /* If this hard reset is called while port enable is active, then
6390 * there is no reason to call make_ioc_operational
6392 if (ioc
->is_driver_loading
&& ioc
->port_enable_failed
) {
6393 ioc
->remove_host
= 1;
6397 r
= _base_get_ioc_facts(ioc
);
6401 if (ioc
->rdpq_array_enable
&& !ioc
->rdpq_array_capable
)
6402 panic("%s: Issue occurred with flashing controller firmware."
6403 "Please reboot the system and ensure that the correct"
6404 " firmware version is running\n", ioc
->name
);
6406 r
= _base_make_ioc_operational(ioc
);
6408 _base_reset_handler(ioc
, MPT3_IOC_DONE_RESET
);
6411 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %s\n",
6412 ioc
->name
, __func__
, ((r
== 0) ? "SUCCESS" : "FAILED")));
6414 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
6415 ioc
->ioc_reset_in_progress_status
= r
;
6416 ioc
->shost_recovery
= 0;
6417 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
6418 ioc
->ioc_reset_count
++;
6419 mutex_unlock(&ioc
->reset_in_progress_mutex
);
6422 if ((r
== 0) && is_trigger
) {
6424 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_FW_FAULT
);
6426 mpt3sas_trigger_master(ioc
,
6427 MASTER_TRIGGER_ADAPTER_RESET
);
6429 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,