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-2013 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h>
54 #include <linux/delay.h>
55 #include <linux/interrupt.h>
56 #include <linux/dma-mapping.h>
58 #include <linux/time.h>
59 #include <linux/kthread.h>
60 #include <linux/aer.h>
63 #include "mpt3sas_base.h"
65 static MPT_CALLBACK mpt_callbacks
[MPT_MAX_CALLBACKS
];
68 #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
70 /* maximum controller queue depth */
71 #define MAX_HBA_QUEUE_DEPTH 30000
72 #define MAX_CHAIN_DEPTH 100000
73 static int max_queue_depth
= -1;
74 module_param(max_queue_depth
, int, 0);
75 MODULE_PARM_DESC(max_queue_depth
, " max controller queue depth ");
77 static int max_sgl_entries
= -1;
78 module_param(max_sgl_entries
, int, 0);
79 MODULE_PARM_DESC(max_sgl_entries
, " max sg entries ");
81 static int msix_disable
= -1;
82 module_param(msix_disable
, int, 0);
83 MODULE_PARM_DESC(msix_disable
, " disable msix routed interrupts (default=0)");
85 static int max_msix_vectors
= 8;
86 module_param(max_msix_vectors
, int, 0);
87 MODULE_PARM_DESC(max_msix_vectors
,
88 " max msix vectors - (default=8)");
90 static int mpt3sas_fwfault_debug
;
91 MODULE_PARM_DESC(mpt3sas_fwfault_debug
,
92 " enable detection of firmware fault and halt firmware - (default=0)");
96 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
100 _scsih_set_fwfault_debug(const char *val
, struct kernel_param
*kp
)
102 int ret
= param_set_int(val
, kp
);
103 struct MPT3SAS_ADAPTER
*ioc
;
108 pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug
);
109 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
)
110 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
113 module_param_call(mpt3sas_fwfault_debug
, _scsih_set_fwfault_debug
,
114 param_get_int
, &mpt3sas_fwfault_debug
, 0644);
117 * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc
118 * @arg: input argument, used to derive ioc
120 * Return 0 if controller is removed from pci subsystem.
121 * Return -1 for other case.
123 static int mpt3sas_remove_dead_ioc_func(void *arg
)
125 struct MPT3SAS_ADAPTER
*ioc
= (struct MPT3SAS_ADAPTER
*)arg
;
126 struct pci_dev
*pdev
;
134 pci_stop_and_remove_bus_device(pdev
);
139 * _base_fault_reset_work - workq handling ioc fault conditions
140 * @work: input argument, used to derive ioc
146 _base_fault_reset_work(struct work_struct
*work
)
148 struct MPT3SAS_ADAPTER
*ioc
=
149 container_of(work
, struct MPT3SAS_ADAPTER
, fault_reset_work
.work
);
153 struct task_struct
*p
;
156 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
157 if (ioc
->shost_recovery
)
159 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
161 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
162 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_MASK
) {
163 pr_err(MPT3SAS_FMT
"SAS host is non-operational !!!!\n",
167 * Call _scsih_flush_pending_cmds callback so that we flush all
168 * pending commands back to OS. This call is required to aovid
169 * deadlock at block layer. Dead IOC will fail to do diag reset,
170 * and this call is safe since dead ioc will never return any
171 * command back from HW.
173 ioc
->schedule_dead_ioc_flush_running_cmds(ioc
);
175 * Set remove_host flag early since kernel thread will
176 * take some time to execute.
178 ioc
->remove_host
= 1;
179 /*Remove the Dead Host */
180 p
= kthread_run(mpt3sas_remove_dead_ioc_func
, ioc
,
181 "mpt3sas_dead_ioc_%d", ioc
->id
);
184 "%s: Running mpt3sas_dead_ioc thread failed !!!!\n",
185 ioc
->name
, __func__
);
188 "%s: Running mpt3sas_dead_ioc thread success !!!!\n",
189 ioc
->name
, __func__
);
190 return; /* don't rearm timer */
193 if ((doorbell
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
) {
194 rc
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
196 pr_warn(MPT3SAS_FMT
"%s: hard reset: %s\n", ioc
->name
,
197 __func__
, (rc
== 0) ? "success" : "failed");
198 doorbell
= mpt3sas_base_get_iocstate(ioc
, 0);
199 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
200 mpt3sas_base_fault_info(ioc
, doorbell
&
201 MPI2_DOORBELL_DATA_MASK
);
202 if (rc
&& (doorbell
& MPI2_IOC_STATE_MASK
) !=
203 MPI2_IOC_STATE_OPERATIONAL
)
204 return; /* don't rearm timer */
207 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
209 if (ioc
->fault_reset_work_q
)
210 queue_delayed_work(ioc
->fault_reset_work_q
,
211 &ioc
->fault_reset_work
,
212 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
213 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
217 * mpt3sas_base_start_watchdog - start the fault_reset_work_q
218 * @ioc: per adapter object
224 mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
228 if (ioc
->fault_reset_work_q
)
231 /* initialize fault polling */
233 INIT_DELAYED_WORK(&ioc
->fault_reset_work
, _base_fault_reset_work
);
234 snprintf(ioc
->fault_reset_work_q_name
,
235 sizeof(ioc
->fault_reset_work_q_name
), "poll_%d_status", ioc
->id
);
236 ioc
->fault_reset_work_q
=
237 create_singlethread_workqueue(ioc
->fault_reset_work_q_name
);
238 if (!ioc
->fault_reset_work_q
) {
239 pr_err(MPT3SAS_FMT
"%s: failed (line=%d)\n",
240 ioc
->name
, __func__
, __LINE__
);
243 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
244 if (ioc
->fault_reset_work_q
)
245 queue_delayed_work(ioc
->fault_reset_work_q
,
246 &ioc
->fault_reset_work
,
247 msecs_to_jiffies(FAULT_POLLING_INTERVAL
));
248 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
252 * mpt3sas_base_stop_watchdog - stop the fault_reset_work_q
253 * @ioc: per adapter object
259 mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER
*ioc
)
262 struct workqueue_struct
*wq
;
264 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
265 wq
= ioc
->fault_reset_work_q
;
266 ioc
->fault_reset_work_q
= NULL
;
267 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
269 if (!cancel_delayed_work(&ioc
->fault_reset_work
))
271 destroy_workqueue(wq
);
276 * mpt3sas_base_fault_info - verbose translation of firmware FAULT code
277 * @ioc: per adapter object
278 * @fault_code: fault code
283 mpt3sas_base_fault_info(struct MPT3SAS_ADAPTER
*ioc
, u16 fault_code
)
285 pr_err(MPT3SAS_FMT
"fault_state(0x%04x)!\n",
286 ioc
->name
, fault_code
);
290 * mpt3sas_halt_firmware - halt's mpt controller firmware
291 * @ioc: per adapter object
293 * For debugging timeout related issues. Writing 0xCOFFEE00
294 * to the doorbell register will halt controller firmware. With
295 * the purpose to stop both driver and firmware, the enduser can
296 * obtain a ring buffer from controller UART.
299 mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER
*ioc
)
303 if (!ioc
->fwfault_debug
)
308 doorbell
= readl(&ioc
->chip
->Doorbell
);
309 if ((doorbell
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
310 mpt3sas_base_fault_info(ioc
, doorbell
);
312 writel(0xC0FFEE00, &ioc
->chip
->Doorbell
);
313 pr_err(MPT3SAS_FMT
"Firmware is halted due to command timeout\n",
317 if (ioc
->fwfault_debug
== 2)
321 panic("panic in %s\n", __func__
);
324 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
326 * _base_sas_ioc_info - verbose translation of the ioc status
327 * @ioc: per adapter object
328 * @mpi_reply: reply mf payload returned from firmware
329 * @request_hdr: request mf
334 _base_sas_ioc_info(struct MPT3SAS_ADAPTER
*ioc
, MPI2DefaultReply_t
*mpi_reply
,
335 MPI2RequestHeader_t
*request_hdr
)
337 u16 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) &
341 char *func_str
= NULL
;
343 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
344 if (request_hdr
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
345 request_hdr
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
346 request_hdr
->Function
== MPI2_FUNCTION_EVENT_NOTIFICATION
)
349 if (ioc_status
== MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
)
352 switch (ioc_status
) {
354 /****************************************************************************
355 * Common IOCStatus values for all replies
356 ****************************************************************************/
358 case MPI2_IOCSTATUS_INVALID_FUNCTION
:
359 desc
= "invalid function";
361 case MPI2_IOCSTATUS_BUSY
:
364 case MPI2_IOCSTATUS_INVALID_SGL
:
365 desc
= "invalid sgl";
367 case MPI2_IOCSTATUS_INTERNAL_ERROR
:
368 desc
= "internal error";
370 case MPI2_IOCSTATUS_INVALID_VPID
:
371 desc
= "invalid vpid";
373 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES
:
374 desc
= "insufficient resources";
376 case MPI2_IOCSTATUS_INVALID_FIELD
:
377 desc
= "invalid field";
379 case MPI2_IOCSTATUS_INVALID_STATE
:
380 desc
= "invalid state";
382 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED
:
383 desc
= "op state not supported";
386 /****************************************************************************
387 * Config IOCStatus values
388 ****************************************************************************/
390 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION
:
391 desc
= "config invalid action";
393 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE
:
394 desc
= "config invalid type";
396 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE
:
397 desc
= "config invalid page";
399 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA
:
400 desc
= "config invalid data";
402 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS
:
403 desc
= "config no defaults";
405 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT
:
406 desc
= "config cant commit";
409 /****************************************************************************
411 ****************************************************************************/
413 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR
:
414 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE
:
415 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE
:
416 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN
:
417 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN
:
418 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR
:
419 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR
:
420 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED
:
421 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH
:
422 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED
:
423 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED
:
424 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED
:
427 /****************************************************************************
428 * For use by SCSI Initiator and SCSI Target end-to-end data protection
429 ****************************************************************************/
431 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR
:
432 desc
= "eedp guard error";
434 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR
:
435 desc
= "eedp ref tag error";
437 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR
:
438 desc
= "eedp app tag error";
441 /****************************************************************************
443 ****************************************************************************/
445 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX
:
446 desc
= "target invalid io index";
448 case MPI2_IOCSTATUS_TARGET_ABORTED
:
449 desc
= "target aborted";
451 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE
:
452 desc
= "target no conn retryable";
454 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION
:
455 desc
= "target no connection";
457 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH
:
458 desc
= "target xfer count mismatch";
460 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR
:
461 desc
= "target data offset error";
463 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA
:
464 desc
= "target too much write data";
466 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT
:
467 desc
= "target iu too short";
469 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT
:
470 desc
= "target ack nak timeout";
472 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED
:
473 desc
= "target nak received";
476 /****************************************************************************
477 * Serial Attached SCSI values
478 ****************************************************************************/
480 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED
:
481 desc
= "smp request failed";
483 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN
:
484 desc
= "smp data overrun";
487 /****************************************************************************
488 * Diagnostic Buffer Post / Diagnostic Release values
489 ****************************************************************************/
491 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED
:
492 desc
= "diagnostic released";
501 switch (request_hdr
->Function
) {
502 case MPI2_FUNCTION_CONFIG
:
503 frame_sz
= sizeof(Mpi2ConfigRequest_t
) + ioc
->sge_size
;
504 func_str
= "config_page";
506 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
507 frame_sz
= sizeof(Mpi2SCSITaskManagementRequest_t
);
508 func_str
= "task_mgmt";
510 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
511 frame_sz
= sizeof(Mpi2SasIoUnitControlRequest_t
);
512 func_str
= "sas_iounit_ctl";
514 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR
:
515 frame_sz
= sizeof(Mpi2SepRequest_t
);
516 func_str
= "enclosure";
518 case MPI2_FUNCTION_IOC_INIT
:
519 frame_sz
= sizeof(Mpi2IOCInitRequest_t
);
520 func_str
= "ioc_init";
522 case MPI2_FUNCTION_PORT_ENABLE
:
523 frame_sz
= sizeof(Mpi2PortEnableRequest_t
);
524 func_str
= "port_enable";
526 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
527 frame_sz
= sizeof(Mpi2SmpPassthroughRequest_t
) + ioc
->sge_size
;
528 func_str
= "smp_passthru";
532 func_str
= "unknown";
536 pr_warn(MPT3SAS_FMT
"ioc_status: %s(0x%04x), request(0x%p),(%s)\n",
537 ioc
->name
, desc
, ioc_status
, request_hdr
, func_str
);
539 _debug_dump_mf(request_hdr
, frame_sz
/4);
543 * _base_display_event_data - verbose translation of firmware asyn events
544 * @ioc: per adapter object
545 * @mpi_reply: reply mf payload returned from firmware
550 _base_display_event_data(struct MPT3SAS_ADAPTER
*ioc
,
551 Mpi2EventNotificationReply_t
*mpi_reply
)
556 if (!(ioc
->logging_level
& MPT_DEBUG_EVENTS
))
559 event
= le16_to_cpu(mpi_reply
->Event
);
562 case MPI2_EVENT_LOG_DATA
:
565 case MPI2_EVENT_STATE_CHANGE
:
566 desc
= "Status Change";
568 case MPI2_EVENT_HARD_RESET_RECEIVED
:
569 desc
= "Hard Reset Received";
571 case MPI2_EVENT_EVENT_CHANGE
:
572 desc
= "Event Change";
574 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
:
575 desc
= "Device Status Change";
577 case MPI2_EVENT_IR_OPERATION_STATUS
:
578 desc
= "IR Operation Status";
580 case MPI2_EVENT_SAS_DISCOVERY
:
582 Mpi2EventDataSasDiscovery_t
*event_data
=
583 (Mpi2EventDataSasDiscovery_t
*)mpi_reply
->EventData
;
584 pr_info(MPT3SAS_FMT
"Discovery: (%s)", ioc
->name
,
585 (event_data
->ReasonCode
== MPI2_EVENT_SAS_DISC_RC_STARTED
) ?
587 if (event_data
->DiscoveryStatus
)
588 pr_info("discovery_status(0x%08x)",
589 le32_to_cpu(event_data
->DiscoveryStatus
));
593 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
:
594 desc
= "SAS Broadcast Primitive";
596 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
597 desc
= "SAS Init Device Status Change";
599 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW
:
600 desc
= "SAS Init Table Overflow";
602 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
603 desc
= "SAS Topology Change List";
605 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
:
606 desc
= "SAS Enclosure Device Status Change";
608 case MPI2_EVENT_IR_VOLUME
:
611 case MPI2_EVENT_IR_PHYSICAL_DISK
:
612 desc
= "IR Physical Disk";
614 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
:
615 desc
= "IR Configuration Change List";
617 case MPI2_EVENT_LOG_ENTRY_ADDED
:
618 desc
= "Log Entry Added";
625 pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
, desc
);
630 * _base_sas_log_info - verbose translation of firmware log info
631 * @ioc: per adapter object
632 * @log_info: log info
637 _base_sas_log_info(struct MPT3SAS_ADAPTER
*ioc
, u32 log_info
)
648 union loginfo_type sas_loginfo
;
649 char *originator_str
= NULL
;
651 sas_loginfo
.loginfo
= log_info
;
652 if (sas_loginfo
.dw
.bus_type
!= 3 /*SAS*/)
655 /* each nexus loss loginfo */
656 if (log_info
== 0x31170000)
659 /* eat the loginfos associated with task aborts */
660 if (ioc
->ignore_loginfos
&& (log_info
== 0x30050000 || log_info
==
661 0x31140000 || log_info
== 0x31130000))
664 switch (sas_loginfo
.dw
.originator
) {
666 originator_str
= "IOP";
669 originator_str
= "PL";
672 originator_str
= "IR";
677 "log_info(0x%08x): originator(%s), code(0x%02x), sub_code(0x%04x)\n",
679 originator_str
, sas_loginfo
.dw
.code
,
680 sas_loginfo
.dw
.subcode
);
684 * _base_display_reply_info -
685 * @ioc: per adapter object
686 * @smid: system request message index
687 * @msix_index: MSIX table index supplied by the OS
688 * @reply: reply message frame(lower 32bit addr)
693 _base_display_reply_info(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
696 MPI2DefaultReply_t
*mpi_reply
;
700 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
701 if (unlikely(!mpi_reply
)) {
702 pr_err(MPT3SAS_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
703 ioc
->name
, __FILE__
, __LINE__
, __func__
);
706 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
);
707 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
708 if ((ioc_status
& MPI2_IOCSTATUS_MASK
) &&
709 (ioc
->logging_level
& MPT_DEBUG_REPLY
)) {
710 _base_sas_ioc_info(ioc
, mpi_reply
,
711 mpt3sas_base_get_msg_frame(ioc
, smid
));
714 if (ioc_status
& MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE
) {
715 loginfo
= le32_to_cpu(mpi_reply
->IOCLogInfo
);
716 _base_sas_log_info(ioc
, loginfo
);
719 if (ioc_status
|| loginfo
) {
720 ioc_status
&= MPI2_IOCSTATUS_MASK
;
721 mpt3sas_trigger_mpi(ioc
, ioc_status
, loginfo
);
726 * mpt3sas_base_done - base internal command completion routine
727 * @ioc: per adapter object
728 * @smid: system request message index
729 * @msix_index: MSIX table index supplied by the OS
730 * @reply: reply message frame(lower 32bit addr)
732 * Return 1 meaning mf should be freed from _base_interrupt
733 * 0 means the mf is freed from this function.
736 mpt3sas_base_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
739 MPI2DefaultReply_t
*mpi_reply
;
741 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
742 if (mpi_reply
&& mpi_reply
->Function
== MPI2_FUNCTION_EVENT_ACK
)
745 if (ioc
->base_cmds
.status
== MPT3_CMD_NOT_USED
)
748 ioc
->base_cmds
.status
|= MPT3_CMD_COMPLETE
;
750 ioc
->base_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
751 memcpy(ioc
->base_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
753 ioc
->base_cmds
.status
&= ~MPT3_CMD_PENDING
;
755 complete(&ioc
->base_cmds
.done
);
760 * _base_async_event - main callback handler for firmware asyn events
761 * @ioc: per adapter object
762 * @msix_index: MSIX table index supplied by the OS
763 * @reply: reply message frame(lower 32bit addr)
765 * Return 1 meaning mf should be freed from _base_interrupt
766 * 0 means the mf is freed from this function.
769 _base_async_event(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
, u32 reply
)
771 Mpi2EventNotificationReply_t
*mpi_reply
;
772 Mpi2EventAckRequest_t
*ack_request
;
775 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
778 if (mpi_reply
->Function
!= MPI2_FUNCTION_EVENT_NOTIFICATION
)
780 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
781 _base_display_event_data(ioc
, mpi_reply
);
783 if (!(mpi_reply
->AckRequired
& MPI2_EVENT_NOTIFICATION_ACK_REQUIRED
))
785 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
787 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
788 ioc
->name
, __func__
);
792 ack_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
793 memset(ack_request
, 0, sizeof(Mpi2EventAckRequest_t
));
794 ack_request
->Function
= MPI2_FUNCTION_EVENT_ACK
;
795 ack_request
->Event
= mpi_reply
->Event
;
796 ack_request
->EventContext
= mpi_reply
->EventContext
;
797 ack_request
->VF_ID
= 0; /* TODO */
798 ack_request
->VP_ID
= 0;
799 mpt3sas_base_put_smid_default(ioc
, smid
);
803 /* scsih callback handler */
804 mpt3sas_scsih_event_callback(ioc
, msix_index
, reply
);
806 /* ctl callback handler */
807 mpt3sas_ctl_event_callback(ioc
, msix_index
, reply
);
813 * _base_get_cb_idx - obtain the callback index
814 * @ioc: per adapter object
815 * @smid: system request message index
817 * Return callback index.
820 _base_get_cb_idx(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
825 if (smid
< ioc
->hi_priority_smid
) {
827 cb_idx
= ioc
->scsi_lookup
[i
].cb_idx
;
828 } else if (smid
< ioc
->internal_smid
) {
829 i
= smid
- ioc
->hi_priority_smid
;
830 cb_idx
= ioc
->hpr_lookup
[i
].cb_idx
;
831 } else if (smid
<= ioc
->hba_queue_depth
) {
832 i
= smid
- ioc
->internal_smid
;
833 cb_idx
= ioc
->internal_lookup
[i
].cb_idx
;
840 * _base_mask_interrupts - disable interrupts
841 * @ioc: per adapter object
843 * Disabling ResetIRQ, Reply and Doorbell Interrupts
848 _base_mask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
852 ioc
->mask_interrupts
= 1;
853 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
854 him_register
|= MPI2_HIM_DIM
+ MPI2_HIM_RIM
+ MPI2_HIM_RESET_IRQ_MASK
;
855 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
856 readl(&ioc
->chip
->HostInterruptMask
);
860 * _base_unmask_interrupts - enable interrupts
861 * @ioc: per adapter object
863 * Enabling only Reply Interrupts
868 _base_unmask_interrupts(struct MPT3SAS_ADAPTER
*ioc
)
872 him_register
= readl(&ioc
->chip
->HostInterruptMask
);
873 him_register
&= ~MPI2_HIM_RIM
;
874 writel(him_register
, &ioc
->chip
->HostInterruptMask
);
875 ioc
->mask_interrupts
= 0;
878 union reply_descriptor
{
887 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
888 * @irq: irq number (not used)
889 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
890 * @r: pt_regs pointer (not used)
892 * Return IRQ_HANDLE if processed, else IRQ_NONE.
895 _base_interrupt(int irq
, void *bus_id
)
897 struct adapter_reply_queue
*reply_q
= bus_id
;
898 union reply_descriptor rd
;
900 u8 request_desript_type
;
904 u8 msix_index
= reply_q
->msix_index
;
905 struct MPT3SAS_ADAPTER
*ioc
= reply_q
->ioc
;
906 Mpi2ReplyDescriptorsUnion_t
*rpf
;
909 if (ioc
->mask_interrupts
)
912 if (!atomic_add_unless(&reply_q
->busy
, 1, 1))
915 rpf
= &reply_q
->reply_post_free
[reply_q
->reply_post_host_index
];
916 request_desript_type
= rpf
->Default
.ReplyFlags
917 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
918 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
) {
919 atomic_dec(&reply_q
->busy
);
926 rd
.word
= le64_to_cpu(rpf
->Words
);
927 if (rd
.u
.low
== UINT_MAX
|| rd
.u
.high
== UINT_MAX
)
930 smid
= le16_to_cpu(rpf
->Default
.DescriptorTypeDependent1
);
931 if (request_desript_type
==
932 MPI25_RPY_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO_SUCCESS
||
933 request_desript_type
==
934 MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS
) {
935 cb_idx
= _base_get_cb_idx(ioc
, smid
);
936 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
937 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
938 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
941 mpt3sas_base_free_smid(ioc
, smid
);
943 } else if (request_desript_type
==
944 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY
) {
946 rpf
->AddressReply
.ReplyFrameAddress
);
947 if (reply
> ioc
->reply_dma_max_address
||
948 reply
< ioc
->reply_dma_min_address
)
951 cb_idx
= _base_get_cb_idx(ioc
, smid
);
952 if ((likely(cb_idx
< MPT_MAX_CALLBACKS
)) &&
953 (likely(mpt_callbacks
[cb_idx
] != NULL
))) {
954 rc
= mpt_callbacks
[cb_idx
](ioc
, smid
,
957 _base_display_reply_info(ioc
,
958 smid
, msix_index
, reply
);
960 mpt3sas_base_free_smid(ioc
,
964 _base_async_event(ioc
, msix_index
, reply
);
967 /* reply free queue handling */
969 ioc
->reply_free_host_index
=
970 (ioc
->reply_free_host_index
==
971 (ioc
->reply_free_queue_depth
- 1)) ?
972 0 : ioc
->reply_free_host_index
+ 1;
973 ioc
->reply_free
[ioc
->reply_free_host_index
] =
976 writel(ioc
->reply_free_host_index
,
977 &ioc
->chip
->ReplyFreeHostIndex
);
981 rpf
->Words
= cpu_to_le64(ULLONG_MAX
);
982 reply_q
->reply_post_host_index
=
983 (reply_q
->reply_post_host_index
==
984 (ioc
->reply_post_queue_depth
- 1)) ? 0 :
985 reply_q
->reply_post_host_index
+ 1;
986 request_desript_type
=
987 reply_q
->reply_post_free
[reply_q
->reply_post_host_index
].
988 Default
.ReplyFlags
& MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK
;
990 if (request_desript_type
== MPI2_RPY_DESCRIPT_FLAGS_UNUSED
)
992 if (!reply_q
->reply_post_host_index
)
993 rpf
= reply_q
->reply_post_free
;
1000 if (!completed_cmds
) {
1001 atomic_dec(&reply_q
->busy
);
1006 writel(reply_q
->reply_post_host_index
| (msix_index
<<
1007 MPI2_RPHI_MSIX_INDEX_SHIFT
), &ioc
->chip
->ReplyPostHostIndex
);
1008 atomic_dec(&reply_q
->busy
);
1013 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1014 * @ioc: per adapter object
1018 _base_is_controller_msix_enabled(struct MPT3SAS_ADAPTER
*ioc
)
1020 return (ioc
->facts
.IOCCapabilities
&
1021 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
;
1025 * mpt3sas_base_flush_reply_queues - flushing the MSIX reply queues
1026 * @ioc: per adapter object
1027 * Context: ISR conext
1029 * Called when a Task Management request has completed. We want
1030 * to flush the other reply queues so all the outstanding IO has been
1031 * completed back to OS before we process the TM completetion.
1036 mpt3sas_base_flush_reply_queues(struct MPT3SAS_ADAPTER
*ioc
)
1038 struct adapter_reply_queue
*reply_q
;
1040 /* If MSIX capability is turned off
1041 * then multi-queues are not enabled
1043 if (!_base_is_controller_msix_enabled(ioc
))
1046 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1047 if (ioc
->shost_recovery
)
1049 /* TMs are on msix_index == 0 */
1050 if (reply_q
->msix_index
== 0)
1052 _base_interrupt(reply_q
->vector
, (void *)reply_q
);
1057 * mpt3sas_base_release_callback_handler - clear interrupt callback handler
1058 * @cb_idx: callback index
1063 mpt3sas_base_release_callback_handler(u8 cb_idx
)
1065 mpt_callbacks
[cb_idx
] = NULL
;
1069 * mpt3sas_base_register_callback_handler - obtain index for the interrupt callback handler
1070 * @cb_func: callback function
1075 mpt3sas_base_register_callback_handler(MPT_CALLBACK cb_func
)
1079 for (cb_idx
= MPT_MAX_CALLBACKS
-1; cb_idx
; cb_idx
--)
1080 if (mpt_callbacks
[cb_idx
] == NULL
)
1083 mpt_callbacks
[cb_idx
] = cb_func
;
1088 * mpt3sas_base_initialize_callback_handler - initialize the interrupt callback handler
1093 mpt3sas_base_initialize_callback_handler(void)
1097 for (cb_idx
= 0; cb_idx
< MPT_MAX_CALLBACKS
; cb_idx
++)
1098 mpt3sas_base_release_callback_handler(cb_idx
);
1103 * _base_build_zero_len_sge - build zero length sg entry
1104 * @ioc: per adapter object
1105 * @paddr: virtual address for SGE
1107 * Create a zero length scatter gather entry to insure the IOCs hardware has
1108 * something to use if the target device goes brain dead and tries
1109 * to send data even when none is asked for.
1114 _base_build_zero_len_sge(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1116 u32 flags_length
= (u32
)((MPI2_SGE_FLAGS_LAST_ELEMENT
|
1117 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_END_OF_LIST
|
1118 MPI2_SGE_FLAGS_SIMPLE_ELEMENT
) <<
1119 MPI2_SGE_FLAGS_SHIFT
);
1120 ioc
->base_add_sg_single(paddr
, flags_length
, -1);
1124 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1125 * @paddr: virtual address for SGE
1126 * @flags_length: SGE flags and data transfer length
1127 * @dma_addr: Physical address
1132 _base_add_sg_single_32(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1134 Mpi2SGESimple32_t
*sgel
= paddr
;
1136 flags_length
|= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING
|
1137 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1138 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1139 sgel
->Address
= cpu_to_le32(dma_addr
);
1144 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1145 * @paddr: virtual address for SGE
1146 * @flags_length: SGE flags and data transfer length
1147 * @dma_addr: Physical address
1152 _base_add_sg_single_64(void *paddr
, u32 flags_length
, dma_addr_t dma_addr
)
1154 Mpi2SGESimple64_t
*sgel
= paddr
;
1156 flags_length
|= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING
|
1157 MPI2_SGE_FLAGS_SYSTEM_ADDRESS
) << MPI2_SGE_FLAGS_SHIFT
;
1158 sgel
->FlagsLength
= cpu_to_le32(flags_length
);
1159 sgel
->Address
= cpu_to_le64(dma_addr
);
1163 * _base_get_chain_buffer_tracker - obtain chain tracker
1164 * @ioc: per adapter object
1165 * @smid: smid associated to an IO request
1167 * Returns chain tracker(from ioc->free_chain_list)
1169 static struct chain_tracker
*
1170 _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1172 struct chain_tracker
*chain_req
;
1173 unsigned long flags
;
1175 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1176 if (list_empty(&ioc
->free_chain_list
)) {
1177 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1178 dfailprintk(ioc
, pr_warn(MPT3SAS_FMT
1179 "chain buffers not available\n", ioc
->name
));
1182 chain_req
= list_entry(ioc
->free_chain_list
.next
,
1183 struct chain_tracker
, tracker_list
);
1184 list_del_init(&chain_req
->tracker_list
);
1185 list_add_tail(&chain_req
->tracker_list
,
1186 &ioc
->scsi_lookup
[smid
- 1].chain_list
);
1187 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1193 * _base_build_sg - build generic sg
1194 * @ioc: per adapter object
1195 * @psge: virtual address for SGE
1196 * @data_out_dma: physical address for WRITES
1197 * @data_out_sz: data xfer size for WRITES
1198 * @data_in_dma: physical address for READS
1199 * @data_in_sz: data xfer size for READS
1204 _base_build_sg(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
1205 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1210 if (!data_out_sz
&& !data_in_sz
) {
1211 _base_build_zero_len_sge(ioc
, psge
);
1215 if (data_out_sz
&& data_in_sz
) {
1216 /* WRITE sgel first */
1217 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1218 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1219 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1220 ioc
->base_add_sg_single(psge
, sgl_flags
|
1221 data_out_sz
, data_out_dma
);
1224 psge
+= ioc
->sge_size
;
1226 /* READ sgel last */
1227 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1228 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1229 MPI2_SGE_FLAGS_END_OF_LIST
);
1230 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1231 ioc
->base_add_sg_single(psge
, sgl_flags
|
1232 data_in_sz
, data_in_dma
);
1233 } else if (data_out_sz
) /* WRITE */ {
1234 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1235 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1236 MPI2_SGE_FLAGS_END_OF_LIST
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
1237 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1238 ioc
->base_add_sg_single(psge
, sgl_flags
|
1239 data_out_sz
, data_out_dma
);
1240 } else if (data_in_sz
) /* READ */ {
1241 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
1242 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
1243 MPI2_SGE_FLAGS_END_OF_LIST
);
1244 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
1245 ioc
->base_add_sg_single(psge
, sgl_flags
|
1246 data_in_sz
, data_in_dma
);
1250 /* IEEE format sgls */
1253 * _base_add_sg_single_ieee - add sg element for IEEE format
1254 * @paddr: virtual address for SGE
1256 * @chain_offset: number of 128 byte elements from start of segment
1257 * @length: data transfer length
1258 * @dma_addr: Physical address
1263 _base_add_sg_single_ieee(void *paddr
, u8 flags
, u8 chain_offset
, u32 length
,
1264 dma_addr_t dma_addr
)
1266 Mpi25IeeeSgeChain64_t
*sgel
= paddr
;
1268 sgel
->Flags
= flags
;
1269 sgel
->NextChainOffset
= chain_offset
;
1270 sgel
->Length
= cpu_to_le32(length
);
1271 sgel
->Address
= cpu_to_le64(dma_addr
);
1275 * _base_build_zero_len_sge_ieee - build zero length sg entry for IEEE format
1276 * @ioc: per adapter object
1277 * @paddr: virtual address for SGE
1279 * Create a zero length scatter gather entry to insure the IOCs hardware has
1280 * something to use if the target device goes brain dead and tries
1281 * to send data even when none is asked for.
1286 _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *paddr
)
1288 u8 sgl_flags
= (MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1289 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
|
1290 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
);
1291 _base_add_sg_single_ieee(paddr
, sgl_flags
, 0, 0, -1);
1295 * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format
1296 * @ioc: per adapter object
1297 * @scmd: scsi command
1298 * @smid: system request message index
1301 * The main routine that builds scatter gather table from a given
1302 * scsi request sent via the .queuecommand main handler.
1304 * Returns 0 success, anything else error
1307 _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER
*ioc
,
1308 struct scsi_cmnd
*scmd
, u16 smid
)
1310 Mpi2SCSIIORequest_t
*mpi_request
;
1311 dma_addr_t chain_dma
;
1312 struct scatterlist
*sg_scmd
;
1313 void *sg_local
, *chain
;
1317 u32 sges_in_segment
;
1318 u8 simple_sgl_flags
;
1319 u8 simple_sgl_flags_last
;
1321 struct chain_tracker
*chain_req
;
1323 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1325 /* init scatter gather flags */
1326 simple_sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1327 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1328 simple_sgl_flags_last
= simple_sgl_flags
|
1329 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
1330 chain_sgl_flags
= MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT
|
1331 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1333 sg_scmd
= scsi_sglist(scmd
);
1334 sges_left
= scsi_dma_map(scmd
);
1336 sdev_printk(KERN_ERR
, scmd
->device
,
1337 "pci_map_sg failed: request for %d bytes!\n",
1338 scsi_bufflen(scmd
));
1342 sg_local
= &mpi_request
->SGL
;
1343 sges_in_segment
= (ioc
->request_sz
-
1344 offsetof(Mpi2SCSIIORequest_t
, SGL
))/ioc
->sge_size_ieee
;
1345 if (sges_left
<= sges_in_segment
)
1346 goto fill_in_last_segment
;
1348 mpi_request
->ChainOffset
= (sges_in_segment
- 1 /* chain element */) +
1349 (offsetof(Mpi2SCSIIORequest_t
, SGL
)/ioc
->sge_size_ieee
);
1351 /* fill in main message segment when there is a chain following */
1352 while (sges_in_segment
> 1) {
1353 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1354 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1355 sg_scmd
= sg_next(sg_scmd
);
1356 sg_local
+= ioc
->sge_size_ieee
;
1361 /* initializing the pointers */
1362 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1365 chain
= chain_req
->chain_buffer
;
1366 chain_dma
= chain_req
->chain_buffer_dma
;
1368 sges_in_segment
= (sges_left
<=
1369 ioc
->max_sges_in_chain_message
) ? sges_left
:
1370 ioc
->max_sges_in_chain_message
;
1371 chain_offset
= (sges_left
== sges_in_segment
) ?
1372 0 : sges_in_segment
;
1373 chain_length
= sges_in_segment
* ioc
->sge_size_ieee
;
1375 chain_length
+= ioc
->sge_size_ieee
;
1376 _base_add_sg_single_ieee(sg_local
, chain_sgl_flags
,
1377 chain_offset
, chain_length
, chain_dma
);
1381 goto fill_in_last_segment
;
1383 /* fill in chain segments */
1384 while (sges_in_segment
) {
1385 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1386 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1387 sg_scmd
= sg_next(sg_scmd
);
1388 sg_local
+= ioc
->sge_size_ieee
;
1393 chain_req
= _base_get_chain_buffer_tracker(ioc
, smid
);
1396 chain
= chain_req
->chain_buffer
;
1397 chain_dma
= chain_req
->chain_buffer_dma
;
1401 fill_in_last_segment
:
1403 /* fill the last segment */
1406 _base_add_sg_single_ieee(sg_local
,
1407 simple_sgl_flags_last
, 0, sg_dma_len(sg_scmd
),
1408 sg_dma_address(sg_scmd
));
1410 _base_add_sg_single_ieee(sg_local
, simple_sgl_flags
, 0,
1411 sg_dma_len(sg_scmd
), sg_dma_address(sg_scmd
));
1412 sg_scmd
= sg_next(sg_scmd
);
1413 sg_local
+= ioc
->sge_size_ieee
;
1421 * _base_build_sg_ieee - build generic sg for IEEE format
1422 * @ioc: per adapter object
1423 * @psge: virtual address for SGE
1424 * @data_out_dma: physical address for WRITES
1425 * @data_out_sz: data xfer size for WRITES
1426 * @data_in_dma: physical address for READS
1427 * @data_in_sz: data xfer size for READS
1432 _base_build_sg_ieee(struct MPT3SAS_ADAPTER
*ioc
, void *psge
,
1433 dma_addr_t data_out_dma
, size_t data_out_sz
, dma_addr_t data_in_dma
,
1438 if (!data_out_sz
&& !data_in_sz
) {
1439 _base_build_zero_len_sge_ieee(ioc
, psge
);
1443 if (data_out_sz
&& data_in_sz
) {
1444 /* WRITE sgel first */
1445 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1446 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1447 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
1451 psge
+= ioc
->sge_size_ieee
;
1453 /* READ sgel last */
1454 sgl_flags
|= MPI25_IEEE_SGE_FLAGS_END_OF_LIST
;
1455 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
1457 } else if (data_out_sz
) /* WRITE */ {
1458 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1459 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
1460 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1461 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_out_sz
,
1463 } else if (data_in_sz
) /* READ */ {
1464 sgl_flags
= MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT
|
1465 MPI25_IEEE_SGE_FLAGS_END_OF_LIST
|
1466 MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR
;
1467 _base_add_sg_single_ieee(psge
, sgl_flags
, 0, data_in_sz
,
1472 #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1475 * _base_config_dma_addressing - set dma addressing
1476 * @ioc: per adapter object
1477 * @pdev: PCI device struct
1479 * Returns 0 for success, non-zero for failure.
1482 _base_config_dma_addressing(struct MPT3SAS_ADAPTER
*ioc
, struct pci_dev
*pdev
)
1487 if (sizeof(dma_addr_t
) > 4) {
1488 const uint64_t required_mask
=
1489 dma_get_required_mask(&pdev
->dev
);
1490 if ((required_mask
> DMA_BIT_MASK(32)) &&
1491 !pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) &&
1492 !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64))) {
1493 ioc
->base_add_sg_single
= &_base_add_sg_single_64
;
1494 ioc
->sge_size
= sizeof(Mpi2SGESimple64_t
);
1500 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))
1501 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32))) {
1502 ioc
->base_add_sg_single
= &_base_add_sg_single_32
;
1503 ioc
->sge_size
= sizeof(Mpi2SGESimple32_t
);
1511 "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n",
1512 ioc
->name
, desc
, convert_to_kb(s
.totalram
));
1518 * _base_check_enable_msix - checks MSIX capabable.
1519 * @ioc: per adapter object
1521 * Check to see if card is capable of MSIX, and set number
1522 * of available msix vectors
1525 _base_check_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1528 u16 message_control
;
1530 base
= pci_find_capability(ioc
->pdev
, PCI_CAP_ID_MSIX
);
1532 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
"msix not supported\n",
1537 /* get msix vector count */
1539 pci_read_config_word(ioc
->pdev
, base
+ 2, &message_control
);
1540 ioc
->msix_vector_count
= (message_control
& 0x3FF) + 1;
1541 if (ioc
->msix_vector_count
> 8)
1542 ioc
->msix_vector_count
= 8;
1543 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
1544 "msix is supported, vector_count(%d)\n",
1545 ioc
->name
, ioc
->msix_vector_count
));
1550 * _base_free_irq - free irq
1551 * @ioc: per adapter object
1553 * Freeing respective reply_queue from the list.
1556 _base_free_irq(struct MPT3SAS_ADAPTER
*ioc
)
1558 struct adapter_reply_queue
*reply_q
, *next
;
1560 if (list_empty(&ioc
->reply_queue_list
))
1563 list_for_each_entry_safe(reply_q
, next
, &ioc
->reply_queue_list
, list
) {
1564 list_del(&reply_q
->list
);
1565 synchronize_irq(reply_q
->vector
);
1566 free_irq(reply_q
->vector
, reply_q
);
1572 * _base_request_irq - request irq
1573 * @ioc: per adapter object
1574 * @index: msix index into vector table
1575 * @vector: irq vector
1577 * Inserting respective reply_queue into the list.
1580 _base_request_irq(struct MPT3SAS_ADAPTER
*ioc
, u8 index
, u32 vector
)
1582 struct adapter_reply_queue
*reply_q
;
1585 reply_q
= kzalloc(sizeof(struct adapter_reply_queue
), GFP_KERNEL
);
1587 pr_err(MPT3SAS_FMT
"unable to allocate memory %d!\n",
1588 ioc
->name
, (int)sizeof(struct adapter_reply_queue
));
1592 reply_q
->msix_index
= index
;
1593 reply_q
->vector
= vector
;
1594 atomic_set(&reply_q
->busy
, 0);
1595 if (ioc
->msix_enable
)
1596 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d-msix%d",
1597 MPT3SAS_DRIVER_NAME
, ioc
->id
, index
);
1599 snprintf(reply_q
->name
, MPT_NAME_LENGTH
, "%s%d",
1600 MPT3SAS_DRIVER_NAME
, ioc
->id
);
1601 r
= request_irq(vector
, _base_interrupt
, IRQF_SHARED
, reply_q
->name
,
1604 pr_err(MPT3SAS_FMT
"unable to allocate interrupt %d!\n",
1605 reply_q
->name
, vector
);
1610 INIT_LIST_HEAD(&reply_q
->list
);
1611 list_add_tail(&reply_q
->list
, &ioc
->reply_queue_list
);
1616 * _base_assign_reply_queues - assigning msix index for each cpu
1617 * @ioc: per adapter object
1619 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1621 * It would nice if we could call irq_set_affinity, however it is not
1622 * an exported symbol
1625 _base_assign_reply_queues(struct MPT3SAS_ADAPTER
*ioc
)
1627 struct adapter_reply_queue
*reply_q
;
1629 int cpu_grouping
, loop
, grouping
, grouping_mod
;
1632 if (!_base_is_controller_msix_enabled(ioc
))
1635 memset(ioc
->cpu_msix_table
, 0, ioc
->cpu_msix_table_sz
);
1637 /* NUMA Hardware bug workaround - drop to less reply queues */
1638 if (ioc
->reply_queue_count
> ioc
->facts
.MaxMSIxVectors
) {
1639 ioc
->reply_queue_count
= ioc
->facts
.MaxMSIxVectors
;
1641 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
1642 reply_q
->msix_index
= reply_queue
;
1643 if (++reply_queue
== ioc
->reply_queue_count
)
1648 /* when there are more cpus than available msix vectors,
1649 * then group cpus togeather on same irq
1651 if (ioc
->cpu_count
> ioc
->msix_vector_count
) {
1652 grouping
= ioc
->cpu_count
/ ioc
->msix_vector_count
;
1653 grouping_mod
= ioc
->cpu_count
% ioc
->msix_vector_count
;
1654 if (grouping
< 2 || (grouping
== 2 && !grouping_mod
))
1656 else if (grouping
< 4 || (grouping
== 4 && !grouping_mod
))
1658 else if (grouping
< 8 || (grouping
== 8 && !grouping_mod
))
1666 reply_q
= list_entry(ioc
->reply_queue_list
.next
,
1667 struct adapter_reply_queue
, list
);
1668 for_each_online_cpu(cpu_id
) {
1669 if (!cpu_grouping
) {
1670 ioc
->cpu_msix_table
[cpu_id
] = reply_q
->msix_index
;
1671 reply_q
= list_entry(reply_q
->list
.next
,
1672 struct adapter_reply_queue
, list
);
1674 if (loop
< cpu_grouping
) {
1675 ioc
->cpu_msix_table
[cpu_id
] =
1676 reply_q
->msix_index
;
1679 reply_q
= list_entry(reply_q
->list
.next
,
1680 struct adapter_reply_queue
, list
);
1681 ioc
->cpu_msix_table
[cpu_id
] =
1682 reply_q
->msix_index
;
1690 * _base_disable_msix - disables msix
1691 * @ioc: per adapter object
1695 _base_disable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1697 if (!ioc
->msix_enable
)
1699 pci_disable_msix(ioc
->pdev
);
1700 ioc
->msix_enable
= 0;
1704 * _base_enable_msix - enables msix, failback to io_apic
1705 * @ioc: per adapter object
1709 _base_enable_msix(struct MPT3SAS_ADAPTER
*ioc
)
1711 struct msix_entry
*entries
, *a
;
1716 if (msix_disable
== -1 || msix_disable
== 0)
1722 if (_base_check_enable_msix(ioc
) != 0)
1725 ioc
->reply_queue_count
= min_t(int, ioc
->cpu_count
,
1726 ioc
->msix_vector_count
);
1728 printk(MPT3SAS_FMT
"MSI-X vectors supported: %d, no of cores"
1729 ": %d, max_msix_vectors: %d\n", ioc
->name
, ioc
->msix_vector_count
,
1730 ioc
->cpu_count
, max_msix_vectors
);
1732 if (max_msix_vectors
> 0) {
1733 ioc
->reply_queue_count
= min_t(int, max_msix_vectors
,
1734 ioc
->reply_queue_count
);
1735 ioc
->msix_vector_count
= ioc
->reply_queue_count
;
1738 entries
= kcalloc(ioc
->reply_queue_count
, sizeof(struct msix_entry
),
1741 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
1742 "kcalloc failed @ at %s:%d/%s() !!!\n",
1743 ioc
->name
, __FILE__
, __LINE__
, __func__
));
1747 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++)
1750 r
= pci_enable_msix(ioc
->pdev
, entries
, ioc
->reply_queue_count
);
1752 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
1753 "pci_enable_msix failed (r=%d) !!!\n",
1759 ioc
->msix_enable
= 1;
1760 for (i
= 0, a
= entries
; i
< ioc
->reply_queue_count
; i
++, a
++) {
1761 r
= _base_request_irq(ioc
, i
, a
->vector
);
1763 _base_free_irq(ioc
);
1764 _base_disable_msix(ioc
);
1773 /* failback to io_apic interrupt routing */
1776 r
= _base_request_irq(ioc
, 0, ioc
->pdev
->irq
);
1782 * mpt3sas_base_map_resources - map in controller resources (io/irq/memap)
1783 * @ioc: per adapter object
1785 * Returns 0 for success, non-zero for failure.
1788 mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER
*ioc
)
1790 struct pci_dev
*pdev
= ioc
->pdev
;
1796 struct adapter_reply_queue
*reply_q
;
1798 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n",
1799 ioc
->name
, __func__
));
1801 ioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
1802 if (pci_enable_device_mem(pdev
)) {
1803 pr_warn(MPT3SAS_FMT
"pci_enable_device_mem: failed\n",
1810 if (pci_request_selected_regions(pdev
, ioc
->bars
,
1811 MPT3SAS_DRIVER_NAME
)) {
1812 pr_warn(MPT3SAS_FMT
"pci_request_selected_regions: failed\n",
1819 /* AER (Advanced Error Reporting) hooks */
1820 pci_enable_pcie_error_reporting(pdev
);
1822 pci_set_master(pdev
);
1825 if (_base_config_dma_addressing(ioc
, pdev
) != 0) {
1826 pr_warn(MPT3SAS_FMT
"no suitable DMA mask for %s\n",
1827 ioc
->name
, pci_name(pdev
));
1832 for (i
= 0, memap_sz
= 0, pio_sz
= 0 ; i
< DEVICE_COUNT_RESOURCE
; i
++) {
1833 if (pci_resource_flags(pdev
, i
) & IORESOURCE_IO
) {
1836 pio_chip
= (u64
)pci_resource_start(pdev
, i
);
1837 pio_sz
= pci_resource_len(pdev
, i
);
1838 } else if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
1841 ioc
->chip_phys
= pci_resource_start(pdev
, i
);
1842 chip_phys
= (u64
)ioc
->chip_phys
;
1843 memap_sz
= pci_resource_len(pdev
, i
);
1844 ioc
->chip
= ioremap(ioc
->chip_phys
, memap_sz
);
1845 if (ioc
->chip
== NULL
) {
1846 pr_err(MPT3SAS_FMT
"unable to map adapter memory!\n",
1854 _base_mask_interrupts(ioc
);
1855 r
= _base_enable_msix(ioc
);
1859 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
)
1860 pr_info(MPT3SAS_FMT
"%s: IRQ %d\n",
1861 reply_q
->name
, ((ioc
->msix_enable
) ? "PCI-MSI-X enabled" :
1862 "IO-APIC enabled"), reply_q
->vector
);
1864 pr_info(MPT3SAS_FMT
"iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1865 ioc
->name
, (unsigned long long)chip_phys
, ioc
->chip
, memap_sz
);
1866 pr_info(MPT3SAS_FMT
"ioport(0x%016llx), size(%d)\n",
1867 ioc
->name
, (unsigned long long)pio_chip
, pio_sz
);
1869 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1870 pci_save_state(pdev
);
1877 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
1878 pci_disable_pcie_error_reporting(pdev
);
1879 pci_disable_device(pdev
);
1884 * mpt3sas_base_get_msg_frame - obtain request mf pointer
1885 * @ioc: per adapter object
1886 * @smid: system request message index(smid zero is invalid)
1888 * Returns virt pointer to message frame.
1891 mpt3sas_base_get_msg_frame(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1893 return (void *)(ioc
->request
+ (smid
* ioc
->request_sz
));
1897 * mpt3sas_base_get_sense_buffer - obtain a sense buffer virt addr
1898 * @ioc: per adapter object
1899 * @smid: system request message index
1901 * Returns virt pointer to sense buffer.
1904 mpt3sas_base_get_sense_buffer(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1906 return (void *)(ioc
->sense
+ ((smid
- 1) * SCSI_SENSE_BUFFERSIZE
));
1910 * mpt3sas_base_get_sense_buffer_dma - obtain a sense buffer dma addr
1911 * @ioc: per adapter object
1912 * @smid: system request message index
1914 * Returns phys pointer to the low 32bit address of the sense buffer.
1917 mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
1919 return cpu_to_le32(ioc
->sense_dma
+ ((smid
- 1) *
1920 SCSI_SENSE_BUFFERSIZE
));
1924 * mpt3sas_base_get_reply_virt_addr - obtain reply frames virt address
1925 * @ioc: per adapter object
1926 * @phys_addr: lower 32 physical addr of the reply
1928 * Converts 32bit lower physical addr into a virt address.
1931 mpt3sas_base_get_reply_virt_addr(struct MPT3SAS_ADAPTER
*ioc
, u32 phys_addr
)
1935 return ioc
->reply
+ (phys_addr
- (u32
)ioc
->reply_dma
);
1939 * mpt3sas_base_get_smid - obtain a free smid from internal queue
1940 * @ioc: per adapter object
1941 * @cb_idx: callback index
1943 * Returns smid (zero is invalid)
1946 mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
1948 unsigned long flags
;
1949 struct request_tracker
*request
;
1952 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1953 if (list_empty(&ioc
->internal_free_list
)) {
1954 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1955 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
1956 ioc
->name
, __func__
);
1960 request
= list_entry(ioc
->internal_free_list
.next
,
1961 struct request_tracker
, tracker_list
);
1962 request
->cb_idx
= cb_idx
;
1963 smid
= request
->smid
;
1964 list_del(&request
->tracker_list
);
1965 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1970 * mpt3sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1971 * @ioc: per adapter object
1972 * @cb_idx: callback index
1973 * @scmd: pointer to scsi command object
1975 * Returns smid (zero is invalid)
1978 mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
,
1979 struct scsi_cmnd
*scmd
)
1981 unsigned long flags
;
1982 struct scsiio_tracker
*request
;
1985 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
1986 if (list_empty(&ioc
->free_list
)) {
1987 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
1988 pr_err(MPT3SAS_FMT
"%s: smid not available\n",
1989 ioc
->name
, __func__
);
1993 request
= list_entry(ioc
->free_list
.next
,
1994 struct scsiio_tracker
, tracker_list
);
1995 request
->scmd
= scmd
;
1996 request
->cb_idx
= cb_idx
;
1997 smid
= request
->smid
;
1998 list_del(&request
->tracker_list
);
1999 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2004 * mpt3sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
2005 * @ioc: per adapter object
2006 * @cb_idx: callback index
2008 * Returns smid (zero is invalid)
2011 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER
*ioc
, u8 cb_idx
)
2013 unsigned long flags
;
2014 struct request_tracker
*request
;
2017 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2018 if (list_empty(&ioc
->hpr_free_list
)) {
2019 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2023 request
= list_entry(ioc
->hpr_free_list
.next
,
2024 struct request_tracker
, tracker_list
);
2025 request
->cb_idx
= cb_idx
;
2026 smid
= request
->smid
;
2027 list_del(&request
->tracker_list
);
2028 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2033 * mpt3sas_base_free_smid - put smid back on free_list
2034 * @ioc: per adapter object
2035 * @smid: system request message index
2040 mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2042 unsigned long flags
;
2044 struct chain_tracker
*chain_req
, *next
;
2046 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
2047 if (smid
< ioc
->hi_priority_smid
) {
2050 if (!list_empty(&ioc
->scsi_lookup
[i
].chain_list
)) {
2051 list_for_each_entry_safe(chain_req
, next
,
2052 &ioc
->scsi_lookup
[i
].chain_list
, tracker_list
) {
2053 list_del_init(&chain_req
->tracker_list
);
2054 list_add(&chain_req
->tracker_list
,
2055 &ioc
->free_chain_list
);
2058 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
2059 ioc
->scsi_lookup
[i
].scmd
= NULL
;
2060 list_add(&ioc
->scsi_lookup
[i
].tracker_list
, &ioc
->free_list
);
2061 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2064 * See _wait_for_commands_to_complete() call with regards
2067 if (ioc
->shost_recovery
&& ioc
->pending_io_count
) {
2068 if (ioc
->pending_io_count
== 1)
2069 wake_up(&ioc
->reset_wq
);
2070 ioc
->pending_io_count
--;
2073 } else if (smid
< ioc
->internal_smid
) {
2075 i
= smid
- ioc
->hi_priority_smid
;
2076 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
2077 list_add(&ioc
->hpr_lookup
[i
].tracker_list
, &ioc
->hpr_free_list
);
2078 } else if (smid
<= ioc
->hba_queue_depth
) {
2079 /* internal queue */
2080 i
= smid
- ioc
->internal_smid
;
2081 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
2082 list_add(&ioc
->internal_lookup
[i
].tracker_list
,
2083 &ioc
->internal_free_list
);
2085 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
2089 * _base_writeq - 64 bit write to MMIO
2090 * @ioc: per adapter object
2092 * @addr: address in MMIO space
2093 * @writeq_lock: spin lock
2095 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
2096 * care of 32 bit environment where its not quarenteed to send the entire word
2099 #if defined(writeq) && defined(CONFIG_64BIT)
2101 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2103 writeq(cpu_to_le64(b
), addr
);
2107 _base_writeq(__u64 b
, volatile void __iomem
*addr
, spinlock_t
*writeq_lock
)
2109 unsigned long flags
;
2110 __u64 data_out
= cpu_to_le64(b
);
2112 spin_lock_irqsave(writeq_lock
, flags
);
2113 writel((u32
)(data_out
), addr
);
2114 writel((u32
)(data_out
>> 32), (addr
+ 4));
2115 spin_unlock_irqrestore(writeq_lock
, flags
);
2120 _base_get_msix_index(struct MPT3SAS_ADAPTER
*ioc
)
2122 return ioc
->cpu_msix_table
[raw_smp_processor_id()];
2126 * mpt3sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
2127 * @ioc: per adapter object
2128 * @smid: system request message index
2129 * @handle: device handle
2134 mpt3sas_base_put_smid_scsi_io(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u16 handle
)
2136 Mpi2RequestDescriptorUnion_t descriptor
;
2137 u64
*request
= (u64
*)&descriptor
;
2140 descriptor
.SCSIIO
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO
;
2141 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
2142 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
2143 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
2144 descriptor
.SCSIIO
.LMID
= 0;
2145 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2146 &ioc
->scsi_lookup_lock
);
2150 * mpt3sas_base_put_smid_fast_path - send fast path request to firmware
2151 * @ioc: per adapter object
2152 * @smid: system request message index
2153 * @handle: device handle
2158 mpt3sas_base_put_smid_fast_path(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
2161 Mpi2RequestDescriptorUnion_t descriptor
;
2162 u64
*request
= (u64
*)&descriptor
;
2164 descriptor
.SCSIIO
.RequestFlags
=
2165 MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO
;
2166 descriptor
.SCSIIO
.MSIxIndex
= _base_get_msix_index(ioc
);
2167 descriptor
.SCSIIO
.SMID
= cpu_to_le16(smid
);
2168 descriptor
.SCSIIO
.DevHandle
= cpu_to_le16(handle
);
2169 descriptor
.SCSIIO
.LMID
= 0;
2170 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2171 &ioc
->scsi_lookup_lock
);
2175 * mpt3sas_base_put_smid_hi_priority - send Task Managment request to firmware
2176 * @ioc: per adapter object
2177 * @smid: system request message index
2182 mpt3sas_base_put_smid_hi_priority(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2184 Mpi2RequestDescriptorUnion_t descriptor
;
2185 u64
*request
= (u64
*)&descriptor
;
2187 descriptor
.HighPriority
.RequestFlags
=
2188 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY
;
2189 descriptor
.HighPriority
.MSIxIndex
= 0;
2190 descriptor
.HighPriority
.SMID
= cpu_to_le16(smid
);
2191 descriptor
.HighPriority
.LMID
= 0;
2192 descriptor
.HighPriority
.Reserved1
= 0;
2193 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2194 &ioc
->scsi_lookup_lock
);
2198 * mpt3sas_base_put_smid_default - Default, primarily used for config pages
2199 * @ioc: per adapter object
2200 * @smid: system request message index
2205 mpt3sas_base_put_smid_default(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
)
2207 Mpi2RequestDescriptorUnion_t descriptor
;
2208 u64
*request
= (u64
*)&descriptor
;
2210 descriptor
.Default
.RequestFlags
= MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE
;
2211 descriptor
.Default
.MSIxIndex
= _base_get_msix_index(ioc
);
2212 descriptor
.Default
.SMID
= cpu_to_le16(smid
);
2213 descriptor
.Default
.LMID
= 0;
2214 descriptor
.Default
.DescriptorTypeDependent
= 0;
2215 _base_writeq(*request
, &ioc
->chip
->RequestDescriptorPostLow
,
2216 &ioc
->scsi_lookup_lock
);
2222 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2223 * @ioc: per adapter object
2228 _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER
*ioc
)
2232 u32 iounit_pg1_flags
;
2235 bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2236 strncpy(desc
, ioc
->manu_pg0
.ChipName
, 16);
2237 pr_info(MPT3SAS_FMT
"%s: FWVersion(%02d.%02d.%02d.%02d), "\
2238 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2240 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2241 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2242 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2243 ioc
->facts
.FWVersion
.Word
& 0x000000FF,
2244 ioc
->pdev
->revision
,
2245 (bios_version
& 0xFF000000) >> 24,
2246 (bios_version
& 0x00FF0000) >> 16,
2247 (bios_version
& 0x0000FF00) >> 8,
2248 bios_version
& 0x000000FF);
2250 pr_info(MPT3SAS_FMT
"Protocol=(", ioc
->name
);
2252 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR
) {
2253 pr_info("Initiator");
2257 if (ioc
->facts
.ProtocolFlags
& MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET
) {
2258 pr_info("%sTarget", i
? "," : "");
2264 pr_info("Capabilities=(");
2266 if (ioc
->facts
.IOCCapabilities
&
2267 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
) {
2272 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_TLR
) {
2273 pr_info("%sTLR", i
? "," : "");
2277 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_MULTICAST
) {
2278 pr_info("%sMulticast", i
? "," : "");
2282 if (ioc
->facts
.IOCCapabilities
&
2283 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET
) {
2284 pr_info("%sBIDI Target", i
? "," : "");
2288 if (ioc
->facts
.IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_EEDP
) {
2289 pr_info("%sEEDP", i
? "," : "");
2293 if (ioc
->facts
.IOCCapabilities
&
2294 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
) {
2295 pr_info("%sSnapshot Buffer", i
? "," : "");
2299 if (ioc
->facts
.IOCCapabilities
&
2300 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
) {
2301 pr_info("%sDiag Trace Buffer", i
? "," : "");
2305 if (ioc
->facts
.IOCCapabilities
&
2306 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
) {
2307 pr_info("%sDiag Extended Buffer", i
? "," : "");
2311 if (ioc
->facts
.IOCCapabilities
&
2312 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
) {
2313 pr_info("%sTask Set Full", i
? "," : "");
2317 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2318 if (!(iounit_pg1_flags
& MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE
)) {
2319 pr_info("%sNCQ", i
? "," : "");
2327 * mpt3sas_base_update_missing_delay - change the missing delay timers
2328 * @ioc: per adapter object
2329 * @device_missing_delay: amount of time till device is reported missing
2330 * @io_missing_delay: interval IO is returned when there is a missing device
2334 * Passed on the command line, this function will modify the device missing
2335 * delay, as well as the io missing delay. This should be called at driver
2339 mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER
*ioc
,
2340 u16 device_missing_delay
, u8 io_missing_delay
)
2342 u16 dmd
, dmd_new
, dmd_orignal
;
2343 u8 io_missing_delay_original
;
2345 Mpi2SasIOUnitPage1_t
*sas_iounit_pg1
= NULL
;
2346 Mpi2ConfigReply_t mpi_reply
;
2350 mpt3sas_config_get_number_hba_phys(ioc
, &num_phys
);
2354 sz
= offsetof(Mpi2SasIOUnitPage1_t
, PhyData
) + (num_phys
*
2355 sizeof(Mpi2SasIOUnit1PhyData_t
));
2356 sas_iounit_pg1
= kzalloc(sz
, GFP_KERNEL
);
2357 if (!sas_iounit_pg1
) {
2358 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2359 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2362 if ((mpt3sas_config_get_sas_iounit_pg1(ioc
, &mpi_reply
,
2363 sas_iounit_pg1
, sz
))) {
2364 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2365 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2368 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) &
2369 MPI2_IOCSTATUS_MASK
;
2370 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2371 pr_err(MPT3SAS_FMT
"failure at %s:%d/%s()!\n",
2372 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2376 /* device missing delay */
2377 dmd
= sas_iounit_pg1
->ReportDeviceMissingDelay
;
2378 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2379 dmd
= (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2381 dmd
= dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2383 if (device_missing_delay
> 0x7F) {
2384 dmd
= (device_missing_delay
> 0x7F0) ? 0x7F0 :
2385 device_missing_delay
;
2387 dmd
|= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
;
2389 dmd
= device_missing_delay
;
2390 sas_iounit_pg1
->ReportDeviceMissingDelay
= dmd
;
2392 /* io missing delay */
2393 io_missing_delay_original
= sas_iounit_pg1
->IODeviceMissingDelay
;
2394 sas_iounit_pg1
->IODeviceMissingDelay
= io_missing_delay
;
2396 if (!mpt3sas_config_set_sas_iounit_pg1(ioc
, &mpi_reply
, sas_iounit_pg1
,
2398 if (dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16
)
2400 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
) * 16;
2403 dmd
& MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK
;
2404 pr_info(MPT3SAS_FMT
"device_missing_delay: old(%d), new(%d)\n",
2405 ioc
->name
, dmd_orignal
, dmd_new
);
2406 pr_info(MPT3SAS_FMT
"ioc_missing_delay: old(%d), new(%d)\n",
2407 ioc
->name
, io_missing_delay_original
,
2409 ioc
->device_missing_delay
= dmd_new
;
2410 ioc
->io_missing_delay
= io_missing_delay
;
2414 kfree(sas_iounit_pg1
);
2417 * _base_static_config_pages - static start of day config pages
2418 * @ioc: per adapter object
2423 _base_static_config_pages(struct MPT3SAS_ADAPTER
*ioc
)
2425 Mpi2ConfigReply_t mpi_reply
;
2426 u32 iounit_pg1_flags
;
2428 mpt3sas_config_get_manufacturing_pg0(ioc
, &mpi_reply
, &ioc
->manu_pg0
);
2429 if (ioc
->ir_firmware
)
2430 mpt3sas_config_get_manufacturing_pg10(ioc
, &mpi_reply
,
2434 * Ensure correct T10 PI operation if vendor left EEDPTagMode
2435 * flag unset in NVDATA.
2437 mpt3sas_config_get_manufacturing_pg11(ioc
, &mpi_reply
, &ioc
->manu_pg11
);
2438 if (ioc
->manu_pg11
.EEDPTagMode
== 0) {
2439 pr_err("%s: overriding NVDATA EEDPTagMode setting\n",
2441 ioc
->manu_pg11
.EEDPTagMode
&= ~0x3;
2442 ioc
->manu_pg11
.EEDPTagMode
|= 0x1;
2443 mpt3sas_config_set_manufacturing_pg11(ioc
, &mpi_reply
,
2447 mpt3sas_config_get_bios_pg2(ioc
, &mpi_reply
, &ioc
->bios_pg2
);
2448 mpt3sas_config_get_bios_pg3(ioc
, &mpi_reply
, &ioc
->bios_pg3
);
2449 mpt3sas_config_get_ioc_pg8(ioc
, &mpi_reply
, &ioc
->ioc_pg8
);
2450 mpt3sas_config_get_iounit_pg0(ioc
, &mpi_reply
, &ioc
->iounit_pg0
);
2451 mpt3sas_config_get_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2452 _base_display_ioc_capabilities(ioc
);
2455 * Enable task_set_full handling in iounit_pg1 when the
2456 * facts capabilities indicate that its supported.
2458 iounit_pg1_flags
= le32_to_cpu(ioc
->iounit_pg1
.Flags
);
2459 if ((ioc
->facts
.IOCCapabilities
&
2460 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING
))
2462 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2465 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING
;
2466 ioc
->iounit_pg1
.Flags
= cpu_to_le32(iounit_pg1_flags
);
2467 mpt3sas_config_set_iounit_pg1(ioc
, &mpi_reply
, &ioc
->iounit_pg1
);
2471 * _base_release_memory_pools - release memory
2472 * @ioc: per adapter object
2474 * Free memory allocated from _base_allocate_memory_pools.
2479 _base_release_memory_pools(struct MPT3SAS_ADAPTER
*ioc
)
2483 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2487 pci_free_consistent(ioc
->pdev
, ioc
->request_dma_sz
,
2488 ioc
->request
, ioc
->request_dma
);
2489 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2490 "request_pool(0x%p): free\n",
2491 ioc
->name
, ioc
->request
));
2492 ioc
->request
= NULL
;
2496 pci_pool_free(ioc
->sense_dma_pool
, ioc
->sense
, ioc
->sense_dma
);
2497 if (ioc
->sense_dma_pool
)
2498 pci_pool_destroy(ioc
->sense_dma_pool
);
2499 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2500 "sense_pool(0x%p): free\n",
2501 ioc
->name
, ioc
->sense
));
2506 pci_pool_free(ioc
->reply_dma_pool
, ioc
->reply
, ioc
->reply_dma
);
2507 if (ioc
->reply_dma_pool
)
2508 pci_pool_destroy(ioc
->reply_dma_pool
);
2509 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2510 "reply_pool(0x%p): free\n",
2511 ioc
->name
, ioc
->reply
));
2515 if (ioc
->reply_free
) {
2516 pci_pool_free(ioc
->reply_free_dma_pool
, ioc
->reply_free
,
2517 ioc
->reply_free_dma
);
2518 if (ioc
->reply_free_dma_pool
)
2519 pci_pool_destroy(ioc
->reply_free_dma_pool
);
2520 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2521 "reply_free_pool(0x%p): free\n",
2522 ioc
->name
, ioc
->reply_free
));
2523 ioc
->reply_free
= NULL
;
2526 if (ioc
->reply_post_free
) {
2527 pci_pool_free(ioc
->reply_post_free_dma_pool
,
2528 ioc
->reply_post_free
, ioc
->reply_post_free_dma
);
2529 if (ioc
->reply_post_free_dma_pool
)
2530 pci_pool_destroy(ioc
->reply_post_free_dma_pool
);
2531 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2532 "reply_post_free_pool(0x%p): free\n", ioc
->name
,
2533 ioc
->reply_post_free
));
2534 ioc
->reply_post_free
= NULL
;
2537 if (ioc
->config_page
) {
2538 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
2539 "config_page(0x%p): free\n", ioc
->name
,
2541 pci_free_consistent(ioc
->pdev
, ioc
->config_page_sz
,
2542 ioc
->config_page
, ioc
->config_page_dma
);
2545 if (ioc
->scsi_lookup
) {
2546 free_pages((ulong
)ioc
->scsi_lookup
, ioc
->scsi_lookup_pages
);
2547 ioc
->scsi_lookup
= NULL
;
2549 kfree(ioc
->hpr_lookup
);
2550 kfree(ioc
->internal_lookup
);
2551 if (ioc
->chain_lookup
) {
2552 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2553 if (ioc
->chain_lookup
[i
].chain_buffer
)
2554 pci_pool_free(ioc
->chain_dma_pool
,
2555 ioc
->chain_lookup
[i
].chain_buffer
,
2556 ioc
->chain_lookup
[i
].chain_buffer_dma
);
2558 if (ioc
->chain_dma_pool
)
2559 pci_pool_destroy(ioc
->chain_dma_pool
);
2560 free_pages((ulong
)ioc
->chain_lookup
, ioc
->chain_pages
);
2561 ioc
->chain_lookup
= NULL
;
2566 * _base_allocate_memory_pools - allocate start of day memory pools
2567 * @ioc: per adapter object
2568 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2570 * Returns 0 success, anything else error
2573 _base_allocate_memory_pools(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
2575 struct mpt3sas_facts
*facts
;
2576 u16 max_sge_elements
;
2577 u16 chains_needed_per_io
;
2578 u32 sz
, total_sz
, reply_post_free_sz
;
2580 u16 max_request_credit
;
2581 unsigned short sg_tablesize
;
2585 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2590 facts
= &ioc
->facts
;
2592 /* command line tunables for max sgl entries */
2593 if (max_sgl_entries
!= -1)
2594 sg_tablesize
= max_sgl_entries
;
2596 sg_tablesize
= MPT3SAS_SG_DEPTH
;
2598 if (sg_tablesize
< MPT3SAS_MIN_PHYS_SEGMENTS
)
2599 sg_tablesize
= MPT3SAS_MIN_PHYS_SEGMENTS
;
2600 else if (sg_tablesize
> MPT3SAS_MAX_PHYS_SEGMENTS
)
2601 sg_tablesize
= MPT3SAS_MAX_PHYS_SEGMENTS
;
2602 ioc
->shost
->sg_tablesize
= sg_tablesize
;
2604 ioc
->hi_priority_depth
= facts
->HighPriorityCredit
;
2605 ioc
->internal_depth
= ioc
->hi_priority_depth
+ (5);
2606 /* command line tunables for max controller queue depth */
2607 if (max_queue_depth
!= -1 && max_queue_depth
!= 0) {
2608 max_request_credit
= min_t(u16
, max_queue_depth
+
2609 ioc
->hi_priority_depth
+ ioc
->internal_depth
,
2610 facts
->RequestCredit
);
2611 if (max_request_credit
> MAX_HBA_QUEUE_DEPTH
)
2612 max_request_credit
= MAX_HBA_QUEUE_DEPTH
;
2614 max_request_credit
= min_t(u16
, facts
->RequestCredit
,
2615 MAX_HBA_QUEUE_DEPTH
);
2617 ioc
->hba_queue_depth
= max_request_credit
;
2619 /* request frame size */
2620 ioc
->request_sz
= facts
->IOCRequestFrameSize
* 4;
2622 /* reply frame size */
2623 ioc
->reply_sz
= facts
->ReplyFrameSize
* 4;
2625 /* calculate the max scatter element size */
2626 sge_size
= max_t(u16
, ioc
->sge_size
, ioc
->sge_size_ieee
);
2630 /* calculate number of sg elements left over in the 1st frame */
2631 max_sge_elements
= ioc
->request_sz
- ((sizeof(Mpi2SCSIIORequest_t
) -
2632 sizeof(Mpi2SGEIOUnion_t
)) + sge_size
);
2633 ioc
->max_sges_in_main_message
= max_sge_elements
/sge_size
;
2635 /* now do the same for a chain buffer */
2636 max_sge_elements
= ioc
->request_sz
- sge_size
;
2637 ioc
->max_sges_in_chain_message
= max_sge_elements
/sge_size
;
2640 * MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2642 chains_needed_per_io
= ((ioc
->shost
->sg_tablesize
-
2643 ioc
->max_sges_in_main_message
)/ioc
->max_sges_in_chain_message
)
2645 if (chains_needed_per_io
> facts
->MaxChainDepth
) {
2646 chains_needed_per_io
= facts
->MaxChainDepth
;
2647 ioc
->shost
->sg_tablesize
= min_t(u16
,
2648 ioc
->max_sges_in_main_message
+ (ioc
->max_sges_in_chain_message
2649 * chains_needed_per_io
), ioc
->shost
->sg_tablesize
);
2651 ioc
->chains_needed_per_io
= chains_needed_per_io
;
2653 /* reply free queue sizing - taking into account for 64 FW events */
2654 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
2656 /* calculate reply descriptor post queue depth */
2657 ioc
->reply_post_queue_depth
= ioc
->hba_queue_depth
+
2658 ioc
->reply_free_queue_depth
+ 1 ;
2659 /* align the reply post queue on the next 16 count boundary */
2660 if (ioc
->reply_post_queue_depth
% 16)
2661 ioc
->reply_post_queue_depth
+= 16 -
2662 (ioc
->reply_post_queue_depth
% 16);
2665 if (ioc
->reply_post_queue_depth
>
2666 facts
->MaxReplyDescriptorPostQueueDepth
) {
2667 ioc
->reply_post_queue_depth
=
2668 facts
->MaxReplyDescriptorPostQueueDepth
-
2669 (facts
->MaxReplyDescriptorPostQueueDepth
% 16);
2670 ioc
->hba_queue_depth
=
2671 ((ioc
->reply_post_queue_depth
- 64) / 2) - 1;
2672 ioc
->reply_free_queue_depth
= ioc
->hba_queue_depth
+ 64;
2675 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scatter gather: " \
2676 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2677 "chains_per_io(%d)\n", ioc
->name
, ioc
->max_sges_in_main_message
,
2678 ioc
->max_sges_in_chain_message
, ioc
->shost
->sg_tablesize
,
2679 ioc
->chains_needed_per_io
));
2681 ioc
->scsiio_depth
= ioc
->hba_queue_depth
-
2682 ioc
->hi_priority_depth
- ioc
->internal_depth
;
2684 /* set the scsi host can_queue depth
2685 * with some internal commands that could be outstanding
2687 ioc
->shost
->can_queue
= ioc
->scsiio_depth
;
2688 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2689 "scsi host: can_queue depth (%d)\n",
2690 ioc
->name
, ioc
->shost
->can_queue
));
2693 /* contiguous pool for request and chains, 16 byte align, one extra "
2696 ioc
->chain_depth
= ioc
->chains_needed_per_io
* ioc
->scsiio_depth
;
2697 sz
= ((ioc
->scsiio_depth
+ 1) * ioc
->request_sz
);
2699 /* hi-priority queue */
2700 sz
+= (ioc
->hi_priority_depth
* ioc
->request_sz
);
2702 /* internal queue */
2703 sz
+= (ioc
->internal_depth
* ioc
->request_sz
);
2705 ioc
->request_dma_sz
= sz
;
2706 ioc
->request
= pci_alloc_consistent(ioc
->pdev
, sz
, &ioc
->request_dma
);
2707 if (!ioc
->request
) {
2708 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
2709 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2710 "total(%d kB)\n", ioc
->name
, ioc
->hba_queue_depth
,
2711 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2712 if (ioc
->scsiio_depth
< MPT3SAS_SAS_QUEUE_DEPTH
)
2715 ioc
->hba_queue_depth
= max_request_credit
- retry_sz
;
2716 goto retry_allocation
;
2720 pr_err(MPT3SAS_FMT
"request pool: pci_alloc_consistent " \
2721 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2722 "total(%d kb)\n", ioc
->name
, ioc
->hba_queue_depth
,
2723 ioc
->chains_needed_per_io
, ioc
->request_sz
, sz
/1024);
2725 /* hi-priority queue */
2726 ioc
->hi_priority
= ioc
->request
+ ((ioc
->scsiio_depth
+ 1) *
2728 ioc
->hi_priority_dma
= ioc
->request_dma
+ ((ioc
->scsiio_depth
+ 1) *
2731 /* internal queue */
2732 ioc
->internal
= ioc
->hi_priority
+ (ioc
->hi_priority_depth
*
2734 ioc
->internal_dma
= ioc
->hi_priority_dma
+ (ioc
->hi_priority_depth
*
2737 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2738 "request pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
2739 ioc
->name
, ioc
->request
, ioc
->hba_queue_depth
, ioc
->request_sz
,
2740 (ioc
->hba_queue_depth
* ioc
->request_sz
)/1024));
2742 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"request pool: dma(0x%llx)\n",
2743 ioc
->name
, (unsigned long long) ioc
->request_dma
));
2746 sz
= ioc
->scsiio_depth
* sizeof(struct scsiio_tracker
);
2747 ioc
->scsi_lookup_pages
= get_order(sz
);
2748 ioc
->scsi_lookup
= (struct scsiio_tracker
*)__get_free_pages(
2749 GFP_KERNEL
, ioc
->scsi_lookup_pages
);
2750 if (!ioc
->scsi_lookup
) {
2751 pr_err(MPT3SAS_FMT
"scsi_lookup: get_free_pages failed, sz(%d)\n",
2752 ioc
->name
, (int)sz
);
2756 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"scsiio(0x%p): depth(%d)\n",
2757 ioc
->name
, ioc
->request
, ioc
->scsiio_depth
));
2759 ioc
->chain_depth
= min_t(u32
, ioc
->chain_depth
, MAX_CHAIN_DEPTH
);
2760 sz
= ioc
->chain_depth
* sizeof(struct chain_tracker
);
2761 ioc
->chain_pages
= get_order(sz
);
2762 ioc
->chain_lookup
= (struct chain_tracker
*)__get_free_pages(
2763 GFP_KERNEL
, ioc
->chain_pages
);
2764 if (!ioc
->chain_lookup
) {
2765 pr_err(MPT3SAS_FMT
"chain_lookup: __get_free_pages failed\n",
2769 ioc
->chain_dma_pool
= pci_pool_create("chain pool", ioc
->pdev
,
2770 ioc
->request_sz
, 16, 0);
2771 if (!ioc
->chain_dma_pool
) {
2772 pr_err(MPT3SAS_FMT
"chain_dma_pool: pci_pool_create failed\n",
2776 for (i
= 0; i
< ioc
->chain_depth
; i
++) {
2777 ioc
->chain_lookup
[i
].chain_buffer
= pci_pool_alloc(
2778 ioc
->chain_dma_pool
, GFP_KERNEL
,
2779 &ioc
->chain_lookup
[i
].chain_buffer_dma
);
2780 if (!ioc
->chain_lookup
[i
].chain_buffer
) {
2781 ioc
->chain_depth
= i
;
2784 total_sz
+= ioc
->request_sz
;
2787 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2788 "chain pool depth(%d), frame_size(%d), pool_size(%d kB)\n",
2789 ioc
->name
, ioc
->chain_depth
, ioc
->request_sz
,
2790 ((ioc
->chain_depth
* ioc
->request_sz
))/1024));
2792 /* initialize hi-priority queue smid's */
2793 ioc
->hpr_lookup
= kcalloc(ioc
->hi_priority_depth
,
2794 sizeof(struct request_tracker
), GFP_KERNEL
);
2795 if (!ioc
->hpr_lookup
) {
2796 pr_err(MPT3SAS_FMT
"hpr_lookup: kcalloc failed\n",
2800 ioc
->hi_priority_smid
= ioc
->scsiio_depth
+ 1;
2801 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2802 "hi_priority(0x%p): depth(%d), start smid(%d)\n",
2803 ioc
->name
, ioc
->hi_priority
,
2804 ioc
->hi_priority_depth
, ioc
->hi_priority_smid
));
2806 /* initialize internal queue smid's */
2807 ioc
->internal_lookup
= kcalloc(ioc
->internal_depth
,
2808 sizeof(struct request_tracker
), GFP_KERNEL
);
2809 if (!ioc
->internal_lookup
) {
2810 pr_err(MPT3SAS_FMT
"internal_lookup: kcalloc failed\n",
2814 ioc
->internal_smid
= ioc
->hi_priority_smid
+ ioc
->hi_priority_depth
;
2815 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2816 "internal(0x%p): depth(%d), start smid(%d)\n",
2817 ioc
->name
, ioc
->internal
,
2818 ioc
->internal_depth
, ioc
->internal_smid
));
2820 /* sense buffers, 4 byte align */
2821 sz
= ioc
->scsiio_depth
* SCSI_SENSE_BUFFERSIZE
;
2822 ioc
->sense_dma_pool
= pci_pool_create("sense pool", ioc
->pdev
, sz
, 4,
2824 if (!ioc
->sense_dma_pool
) {
2825 pr_err(MPT3SAS_FMT
"sense pool: pci_pool_create failed\n",
2829 ioc
->sense
= pci_pool_alloc(ioc
->sense_dma_pool
, GFP_KERNEL
,
2832 pr_err(MPT3SAS_FMT
"sense pool: pci_pool_alloc failed\n",
2836 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2837 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
2838 "(%d kB)\n", ioc
->name
, ioc
->sense
, ioc
->scsiio_depth
,
2839 SCSI_SENSE_BUFFERSIZE
, sz
/1024));
2840 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"sense_dma(0x%llx)\n",
2841 ioc
->name
, (unsigned long long)ioc
->sense_dma
));
2844 /* reply pool, 4 byte align */
2845 sz
= ioc
->reply_free_queue_depth
* ioc
->reply_sz
;
2846 ioc
->reply_dma_pool
= pci_pool_create("reply pool", ioc
->pdev
, sz
, 4,
2848 if (!ioc
->reply_dma_pool
) {
2849 pr_err(MPT3SAS_FMT
"reply pool: pci_pool_create failed\n",
2853 ioc
->reply
= pci_pool_alloc(ioc
->reply_dma_pool
, GFP_KERNEL
,
2856 pr_err(MPT3SAS_FMT
"reply pool: pci_pool_alloc failed\n",
2860 ioc
->reply_dma_min_address
= (u32
)(ioc
->reply_dma
);
2861 ioc
->reply_dma_max_address
= (u32
)(ioc
->reply_dma
) + sz
;
2862 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2863 "reply pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n",
2864 ioc
->name
, ioc
->reply
,
2865 ioc
->reply_free_queue_depth
, ioc
->reply_sz
, sz
/1024));
2866 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_dma(0x%llx)\n",
2867 ioc
->name
, (unsigned long long)ioc
->reply_dma
));
2870 /* reply free queue, 16 byte align */
2871 sz
= ioc
->reply_free_queue_depth
* 4;
2872 ioc
->reply_free_dma_pool
= pci_pool_create("reply_free pool",
2873 ioc
->pdev
, sz
, 16, 0);
2874 if (!ioc
->reply_free_dma_pool
) {
2875 pr_err(MPT3SAS_FMT
"reply_free pool: pci_pool_create failed\n",
2879 ioc
->reply_free
= pci_pool_alloc(ioc
->reply_free_dma_pool
, GFP_KERNEL
,
2880 &ioc
->reply_free_dma
);
2881 if (!ioc
->reply_free
) {
2882 pr_err(MPT3SAS_FMT
"reply_free pool: pci_pool_alloc failed\n",
2886 memset(ioc
->reply_free
, 0, sz
);
2887 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply_free pool(0x%p): " \
2888 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc
->name
,
2889 ioc
->reply_free
, ioc
->reply_free_queue_depth
, 4, sz
/1024));
2890 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2891 "reply_free_dma (0x%llx)\n",
2892 ioc
->name
, (unsigned long long)ioc
->reply_free_dma
));
2895 /* reply post queue, 16 byte align */
2896 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
2897 sizeof(Mpi2DefaultReplyDescriptor_t
);
2898 if (_base_is_controller_msix_enabled(ioc
))
2899 sz
= reply_post_free_sz
* ioc
->reply_queue_count
;
2901 sz
= reply_post_free_sz
;
2902 ioc
->reply_post_free_dma_pool
= pci_pool_create("reply_post_free pool",
2903 ioc
->pdev
, sz
, 16, 0);
2904 if (!ioc
->reply_post_free_dma_pool
) {
2906 "reply_post_free pool: pci_pool_create failed\n",
2910 ioc
->reply_post_free
= pci_pool_alloc(ioc
->reply_post_free_dma_pool
,
2911 GFP_KERNEL
, &ioc
->reply_post_free_dma
);
2912 if (!ioc
->reply_post_free
) {
2914 "reply_post_free pool: pci_pool_alloc failed\n",
2918 memset(ioc
->reply_post_free
, 0, sz
);
2919 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"reply post free pool" \
2920 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2921 ioc
->name
, ioc
->reply_post_free
, ioc
->reply_post_queue_depth
, 8,
2923 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2924 "reply_post_free_dma = (0x%llx)\n",
2925 ioc
->name
, (unsigned long long)
2926 ioc
->reply_post_free_dma
));
2929 ioc
->config_page_sz
= 512;
2930 ioc
->config_page
= pci_alloc_consistent(ioc
->pdev
,
2931 ioc
->config_page_sz
, &ioc
->config_page_dma
);
2932 if (!ioc
->config_page
) {
2934 "config page: pci_pool_alloc failed\n",
2938 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
2939 "config page(0x%p): size(%d)\n",
2940 ioc
->name
, ioc
->config_page
, ioc
->config_page_sz
));
2941 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"config_page_dma(0x%llx)\n",
2942 ioc
->name
, (unsigned long long)ioc
->config_page_dma
));
2943 total_sz
+= ioc
->config_page_sz
;
2945 pr_info(MPT3SAS_FMT
"Allocated physical memory: size(%d kB)\n",
2946 ioc
->name
, total_sz
/1024);
2948 "Current Controller Queue Depth(%d),Max Controller Queue Depth(%d)\n",
2949 ioc
->name
, ioc
->shost
->can_queue
, facts
->RequestCredit
);
2950 pr_info(MPT3SAS_FMT
"Scatter Gather Elements per IO(%d)\n",
2951 ioc
->name
, ioc
->shost
->sg_tablesize
);
2959 * mpt3sas_base_get_iocstate - Get the current state of a MPT adapter.
2960 * @ioc: Pointer to MPT_ADAPTER structure
2961 * @cooked: Request raw or cooked IOC state
2963 * Returns all IOC Doorbell register bits if cooked==0, else just the
2964 * Doorbell bits in MPI_IOC_STATE_MASK.
2967 mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER
*ioc
, int cooked
)
2971 s
= readl(&ioc
->chip
->Doorbell
);
2972 sc
= s
& MPI2_IOC_STATE_MASK
;
2973 return cooked
? sc
: s
;
2977 * _base_wait_on_iocstate - waiting on a particular ioc state
2978 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2979 * @timeout: timeout in second
2980 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2982 * Returns 0 for success, non-zero for failure.
2985 _base_wait_on_iocstate(struct MPT3SAS_ADAPTER
*ioc
, u32 ioc_state
, int timeout
,
2992 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
2994 current_state
= mpt3sas_base_get_iocstate(ioc
, 1);
2995 if (current_state
== ioc_state
)
2997 if (count
&& current_state
== MPI2_IOC_STATE_FAULT
)
2999 if (sleep_flag
== CAN_SLEEP
)
3000 usleep_range(1000, 1500);
3006 return current_state
;
3010 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
3011 * a write to the doorbell)
3012 * @ioc: per adapter object
3013 * @timeout: timeout in second
3014 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3016 * Returns 0 for success, non-zero for failure.
3018 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
3021 _base_wait_for_doorbell_int(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3028 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3030 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
3031 if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
3032 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3033 "%s: successful count(%d), timeout(%d)\n",
3034 ioc
->name
, __func__
, count
, timeout
));
3037 if (sleep_flag
== CAN_SLEEP
)
3038 usleep_range(1000, 1500);
3045 "%s: failed due to timeout count(%d), int_status(%x)!\n",
3046 ioc
->name
, __func__
, count
, int_status
);
3051 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
3052 * @ioc: per adapter object
3053 * @timeout: timeout in second
3054 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3056 * Returns 0 for success, non-zero for failure.
3058 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
3062 _base_wait_for_doorbell_ack(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3070 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3072 int_status
= readl(&ioc
->chip
->HostInterruptStatus
);
3073 if (!(int_status
& MPI2_HIS_SYS2IOC_DB_STATUS
)) {
3074 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3075 "%s: successful count(%d), timeout(%d)\n",
3076 ioc
->name
, __func__
, count
, timeout
));
3078 } else if (int_status
& MPI2_HIS_IOC2SYS_DB_STATUS
) {
3079 doorbell
= readl(&ioc
->chip
->Doorbell
);
3080 if ((doorbell
& MPI2_IOC_STATE_MASK
) ==
3081 MPI2_IOC_STATE_FAULT
) {
3082 mpt3sas_base_fault_info(ioc
, doorbell
);
3085 } else if (int_status
== 0xFFFFFFFF)
3088 if (sleep_flag
== CAN_SLEEP
)
3089 usleep_range(1000, 1500);
3097 "%s: failed due to timeout count(%d), int_status(%x)!\n",
3098 ioc
->name
, __func__
, count
, int_status
);
3103 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
3104 * @ioc: per adapter object
3105 * @timeout: timeout in second
3106 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3108 * Returns 0 for success, non-zero for failure.
3112 _base_wait_for_doorbell_not_used(struct MPT3SAS_ADAPTER
*ioc
, int timeout
,
3119 cntdn
= (sleep_flag
== CAN_SLEEP
) ? 1000*timeout
: 2000*timeout
;
3121 doorbell_reg
= readl(&ioc
->chip
->Doorbell
);
3122 if (!(doorbell_reg
& MPI2_DOORBELL_USED
)) {
3123 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3124 "%s: successful count(%d), timeout(%d)\n",
3125 ioc
->name
, __func__
, count
, timeout
));
3128 if (sleep_flag
== CAN_SLEEP
)
3129 usleep_range(1000, 1500);
3136 "%s: failed due to timeout count(%d), doorbell_reg(%x)!\n",
3137 ioc
->name
, __func__
, count
, doorbell_reg
);
3142 * _base_send_ioc_reset - send doorbell reset
3143 * @ioc: per adapter object
3144 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
3145 * @timeout: timeout in second
3146 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3148 * Returns 0 for success, non-zero for failure.
3151 _base_send_ioc_reset(struct MPT3SAS_ADAPTER
*ioc
, u8 reset_type
, int timeout
,
3157 if (reset_type
!= MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
) {
3158 pr_err(MPT3SAS_FMT
"%s: unknown reset_type\n",
3159 ioc
->name
, __func__
);
3163 if (!(ioc
->facts
.IOCCapabilities
&
3164 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY
))
3167 pr_info(MPT3SAS_FMT
"sending message unit reset !!\n", ioc
->name
);
3169 writel(reset_type
<< MPI2_DOORBELL_FUNCTION_SHIFT
,
3170 &ioc
->chip
->Doorbell
);
3171 if ((_base_wait_for_doorbell_ack(ioc
, 15, sleep_flag
))) {
3175 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
,
3176 timeout
, sleep_flag
);
3179 "%s: failed going to ready state (ioc_state=0x%x)\n",
3180 ioc
->name
, __func__
, ioc_state
);
3185 pr_info(MPT3SAS_FMT
"message unit reset: %s\n",
3186 ioc
->name
, ((r
== 0) ? "SUCCESS" : "FAILED"));
3191 * _base_handshake_req_reply_wait - send request thru doorbell interface
3192 * @ioc: per adapter object
3193 * @request_bytes: request length
3194 * @request: pointer having request payload
3195 * @reply_bytes: reply length
3196 * @reply: pointer to reply payload
3197 * @timeout: timeout in second
3198 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3200 * Returns 0 for success, non-zero for failure.
3203 _base_handshake_req_reply_wait(struct MPT3SAS_ADAPTER
*ioc
, int request_bytes
,
3204 u32
*request
, int reply_bytes
, u16
*reply
, int timeout
, int sleep_flag
)
3206 MPI2DefaultReply_t
*default_reply
= (MPI2DefaultReply_t
*)reply
;
3212 /* make sure doorbell is not in use */
3213 if ((readl(&ioc
->chip
->Doorbell
) & MPI2_DOORBELL_USED
)) {
3215 "doorbell is in use (line=%d)\n",
3216 ioc
->name
, __LINE__
);
3220 /* clear pending doorbell interrupts from previous state changes */
3221 if (readl(&ioc
->chip
->HostInterruptStatus
) &
3222 MPI2_HIS_IOC2SYS_DB_STATUS
)
3223 writel(0, &ioc
->chip
->HostInterruptStatus
);
3225 /* send message to ioc */
3226 writel(((MPI2_FUNCTION_HANDSHAKE
<<MPI2_DOORBELL_FUNCTION_SHIFT
) |
3227 ((request_bytes
/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT
)),
3228 &ioc
->chip
->Doorbell
);
3230 if ((_base_wait_for_doorbell_int(ioc
, 5, NO_SLEEP
))) {
3232 "doorbell handshake int failed (line=%d)\n",
3233 ioc
->name
, __LINE__
);
3236 writel(0, &ioc
->chip
->HostInterruptStatus
);
3238 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
))) {
3240 "doorbell handshake ack failed (line=%d)\n",
3241 ioc
->name
, __LINE__
);
3245 /* send message 32-bits at a time */
3246 for (i
= 0, failed
= 0; i
< request_bytes
/4 && !failed
; i
++) {
3247 writel(cpu_to_le32(request
[i
]), &ioc
->chip
->Doorbell
);
3248 if ((_base_wait_for_doorbell_ack(ioc
, 5, sleep_flag
)))
3254 "doorbell handshake sending request failed (line=%d)\n",
3255 ioc
->name
, __LINE__
);
3259 /* now wait for the reply */
3260 if ((_base_wait_for_doorbell_int(ioc
, timeout
, sleep_flag
))) {
3262 "doorbell handshake int failed (line=%d)\n",
3263 ioc
->name
, __LINE__
);
3267 /* read the first two 16-bits, it gives the total length of the reply */
3268 reply
[0] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3269 & MPI2_DOORBELL_DATA_MASK
);
3270 writel(0, &ioc
->chip
->HostInterruptStatus
);
3271 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3273 "doorbell handshake int failed (line=%d)\n",
3274 ioc
->name
, __LINE__
);
3277 reply
[1] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3278 & MPI2_DOORBELL_DATA_MASK
);
3279 writel(0, &ioc
->chip
->HostInterruptStatus
);
3281 for (i
= 2; i
< default_reply
->MsgLength
* 2; i
++) {
3282 if ((_base_wait_for_doorbell_int(ioc
, 5, sleep_flag
))) {
3284 "doorbell handshake int failed (line=%d)\n",
3285 ioc
->name
, __LINE__
);
3288 if (i
>= reply_bytes
/2) /* overflow case */
3289 dummy
= readl(&ioc
->chip
->Doorbell
);
3291 reply
[i
] = le16_to_cpu(readl(&ioc
->chip
->Doorbell
)
3292 & MPI2_DOORBELL_DATA_MASK
);
3293 writel(0, &ioc
->chip
->HostInterruptStatus
);
3296 _base_wait_for_doorbell_int(ioc
, 5, sleep_flag
);
3297 if (_base_wait_for_doorbell_not_used(ioc
, 5, sleep_flag
) != 0) {
3298 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
3299 "doorbell is in use (line=%d)\n", ioc
->name
, __LINE__
));
3301 writel(0, &ioc
->chip
->HostInterruptStatus
);
3303 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3304 mfp
= (__le32
*)reply
;
3305 pr_info("\toffset:data\n");
3306 for (i
= 0; i
< reply_bytes
/4; i
++)
3307 pr_info("\t[0x%02x]:%08x\n", i
*4,
3308 le32_to_cpu(mfp
[i
]));
3314 * mpt3sas_base_sas_iounit_control - send sas iounit control to FW
3315 * @ioc: per adapter object
3316 * @mpi_reply: the reply payload from FW
3317 * @mpi_request: the request payload sent to FW
3319 * The SAS IO Unit Control Request message allows the host to perform low-level
3320 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3321 * to obtain the IOC assigned device handles for a device if it has other
3322 * identifying information about the device, in addition allows the host to
3323 * remove IOC resources associated with the device.
3325 * Returns 0 for success, non-zero for failure.
3328 mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER
*ioc
,
3329 Mpi2SasIoUnitControlReply_t
*mpi_reply
,
3330 Mpi2SasIoUnitControlRequest_t
*mpi_request
)
3334 unsigned long timeleft
;
3338 u16 wait_state_count
;
3340 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3343 mutex_lock(&ioc
->base_cmds
.mutex
);
3345 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
3346 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
3347 ioc
->name
, __func__
);
3352 wait_state_count
= 0;
3353 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3354 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3355 if (wait_state_count
++ == 10) {
3357 "%s: failed due to ioc not operational\n",
3358 ioc
->name
, __func__
);
3363 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3365 "%s: waiting for operational state(count=%d)\n",
3366 ioc
->name
, __func__
, wait_state_count
);
3369 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3371 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3372 ioc
->name
, __func__
);
3378 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
3379 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3380 ioc
->base_cmds
.smid
= smid
;
3381 memcpy(request
, mpi_request
, sizeof(Mpi2SasIoUnitControlRequest_t
));
3382 if (mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3383 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
)
3384 ioc
->ioc_link_reset_in_progress
= 1;
3385 init_completion(&ioc
->base_cmds
.done
);
3386 mpt3sas_base_put_smid_default(ioc
, smid
);
3387 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3388 msecs_to_jiffies(10000));
3389 if ((mpi_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
||
3390 mpi_request
->Operation
== MPI2_SAS_OP_PHY_LINK_RESET
) &&
3391 ioc
->ioc_link_reset_in_progress
)
3392 ioc
->ioc_link_reset_in_progress
= 0;
3393 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
3394 pr_err(MPT3SAS_FMT
"%s: timeout\n",
3395 ioc
->name
, __func__
);
3396 _debug_dump_mf(mpi_request
,
3397 sizeof(Mpi2SasIoUnitControlRequest_t
)/4);
3398 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
3400 goto issue_host_reset
;
3402 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
3403 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3404 sizeof(Mpi2SasIoUnitControlReply_t
));
3406 memset(mpi_reply
, 0, sizeof(Mpi2SasIoUnitControlReply_t
));
3407 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3412 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3414 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3417 mutex_unlock(&ioc
->base_cmds
.mutex
);
3422 * mpt3sas_base_scsi_enclosure_processor - sending request to sep device
3423 * @ioc: per adapter object
3424 * @mpi_reply: the reply payload from FW
3425 * @mpi_request: the request payload sent to FW
3427 * The SCSI Enclosure Processor request message causes the IOC to
3428 * communicate with SES devices to control LED status signals.
3430 * Returns 0 for success, non-zero for failure.
3433 mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER
*ioc
,
3434 Mpi2SepReply_t
*mpi_reply
, Mpi2SepRequest_t
*mpi_request
)
3438 unsigned long timeleft
;
3442 u16 wait_state_count
;
3444 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3447 mutex_lock(&ioc
->base_cmds
.mutex
);
3449 if (ioc
->base_cmds
.status
!= MPT3_CMD_NOT_USED
) {
3450 pr_err(MPT3SAS_FMT
"%s: base_cmd in use\n",
3451 ioc
->name
, __func__
);
3456 wait_state_count
= 0;
3457 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3458 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
3459 if (wait_state_count
++ == 10) {
3461 "%s: failed due to ioc not operational\n",
3462 ioc
->name
, __func__
);
3467 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
3469 "%s: waiting for operational state(count=%d)\n",
3471 __func__
, wait_state_count
);
3474 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3476 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3477 ioc
->name
, __func__
);
3483 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
3484 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3485 ioc
->base_cmds
.smid
= smid
;
3486 memcpy(request
, mpi_request
, sizeof(Mpi2SepReply_t
));
3487 init_completion(&ioc
->base_cmds
.done
);
3488 mpt3sas_base_put_smid_default(ioc
, smid
);
3489 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
,
3490 msecs_to_jiffies(10000));
3491 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
3492 pr_err(MPT3SAS_FMT
"%s: timeout\n",
3493 ioc
->name
, __func__
);
3494 _debug_dump_mf(mpi_request
,
3495 sizeof(Mpi2SepRequest_t
)/4);
3496 if (!(ioc
->base_cmds
.status
& MPT3_CMD_RESET
))
3498 goto issue_host_reset
;
3500 if (ioc
->base_cmds
.status
& MPT3_CMD_REPLY_VALID
)
3501 memcpy(mpi_reply
, ioc
->base_cmds
.reply
,
3502 sizeof(Mpi2SepReply_t
));
3504 memset(mpi_reply
, 0, sizeof(Mpi2SepReply_t
));
3505 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3510 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
3512 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
3515 mutex_unlock(&ioc
->base_cmds
.mutex
);
3520 * _base_get_port_facts - obtain port facts reply and save in ioc
3521 * @ioc: per adapter object
3522 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3524 * Returns 0 for success, non-zero for failure.
3527 _base_get_port_facts(struct MPT3SAS_ADAPTER
*ioc
, int port
, int sleep_flag
)
3529 Mpi2PortFactsRequest_t mpi_request
;
3530 Mpi2PortFactsReply_t mpi_reply
;
3531 struct mpt3sas_port_facts
*pfacts
;
3532 int mpi_reply_sz
, mpi_request_sz
, r
;
3534 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3537 mpi_reply_sz
= sizeof(Mpi2PortFactsReply_t
);
3538 mpi_request_sz
= sizeof(Mpi2PortFactsRequest_t
);
3539 memset(&mpi_request
, 0, mpi_request_sz
);
3540 mpi_request
.Function
= MPI2_FUNCTION_PORT_FACTS
;
3541 mpi_request
.PortNumber
= port
;
3542 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3543 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3546 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
3547 ioc
->name
, __func__
, r
);
3551 pfacts
= &ioc
->pfacts
[port
];
3552 memset(pfacts
, 0, sizeof(struct mpt3sas_port_facts
));
3553 pfacts
->PortNumber
= mpi_reply
.PortNumber
;
3554 pfacts
->VP_ID
= mpi_reply
.VP_ID
;
3555 pfacts
->VF_ID
= mpi_reply
.VF_ID
;
3556 pfacts
->MaxPostedCmdBuffers
=
3557 le16_to_cpu(mpi_reply
.MaxPostedCmdBuffers
);
3563 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3564 * @ioc: per adapter object
3565 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3567 * Returns 0 for success, non-zero for failure.
3570 _base_get_ioc_facts(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3572 Mpi2IOCFactsRequest_t mpi_request
;
3573 Mpi2IOCFactsReply_t mpi_reply
;
3574 struct mpt3sas_facts
*facts
;
3575 int mpi_reply_sz
, mpi_request_sz
, r
;
3577 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3580 mpi_reply_sz
= sizeof(Mpi2IOCFactsReply_t
);
3581 mpi_request_sz
= sizeof(Mpi2IOCFactsRequest_t
);
3582 memset(&mpi_request
, 0, mpi_request_sz
);
3583 mpi_request
.Function
= MPI2_FUNCTION_IOC_FACTS
;
3584 r
= _base_handshake_req_reply_wait(ioc
, mpi_request_sz
,
3585 (u32
*)&mpi_request
, mpi_reply_sz
, (u16
*)&mpi_reply
, 5, CAN_SLEEP
);
3588 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
3589 ioc
->name
, __func__
, r
);
3593 facts
= &ioc
->facts
;
3594 memset(facts
, 0, sizeof(struct mpt3sas_facts
));
3595 facts
->MsgVersion
= le16_to_cpu(mpi_reply
.MsgVersion
);
3596 facts
->HeaderVersion
= le16_to_cpu(mpi_reply
.HeaderVersion
);
3597 facts
->VP_ID
= mpi_reply
.VP_ID
;
3598 facts
->VF_ID
= mpi_reply
.VF_ID
;
3599 facts
->IOCExceptions
= le16_to_cpu(mpi_reply
.IOCExceptions
);
3600 facts
->MaxChainDepth
= mpi_reply
.MaxChainDepth
;
3601 facts
->WhoInit
= mpi_reply
.WhoInit
;
3602 facts
->NumberOfPorts
= mpi_reply
.NumberOfPorts
;
3603 facts
->MaxMSIxVectors
= mpi_reply
.MaxMSIxVectors
;
3604 facts
->RequestCredit
= le16_to_cpu(mpi_reply
.RequestCredit
);
3605 facts
->MaxReplyDescriptorPostQueueDepth
=
3606 le16_to_cpu(mpi_reply
.MaxReplyDescriptorPostQueueDepth
);
3607 facts
->ProductID
= le16_to_cpu(mpi_reply
.ProductID
);
3608 facts
->IOCCapabilities
= le32_to_cpu(mpi_reply
.IOCCapabilities
);
3609 if ((facts
->IOCCapabilities
& MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID
))
3610 ioc
->ir_firmware
= 1;
3611 facts
->FWVersion
.Word
= le32_to_cpu(mpi_reply
.FWVersion
.Word
);
3612 facts
->IOCRequestFrameSize
=
3613 le16_to_cpu(mpi_reply
.IOCRequestFrameSize
);
3614 facts
->MaxInitiators
= le16_to_cpu(mpi_reply
.MaxInitiators
);
3615 facts
->MaxTargets
= le16_to_cpu(mpi_reply
.MaxTargets
);
3616 ioc
->shost
->max_id
= -1;
3617 facts
->MaxSasExpanders
= le16_to_cpu(mpi_reply
.MaxSasExpanders
);
3618 facts
->MaxEnclosures
= le16_to_cpu(mpi_reply
.MaxEnclosures
);
3619 facts
->ProtocolFlags
= le16_to_cpu(mpi_reply
.ProtocolFlags
);
3620 facts
->HighPriorityCredit
=
3621 le16_to_cpu(mpi_reply
.HighPriorityCredit
);
3622 facts
->ReplyFrameSize
= mpi_reply
.ReplyFrameSize
;
3623 facts
->MaxDevHandle
= le16_to_cpu(mpi_reply
.MaxDevHandle
);
3625 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3626 "hba queue depth(%d), max chains per io(%d)\n",
3627 ioc
->name
, facts
->RequestCredit
,
3628 facts
->MaxChainDepth
));
3629 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
3630 "request frame size(%d), reply frame size(%d)\n", ioc
->name
,
3631 facts
->IOCRequestFrameSize
* 4, facts
->ReplyFrameSize
* 4));
3636 * _base_send_ioc_init - send ioc_init to firmware
3637 * @ioc: per adapter object
3638 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3640 * Returns 0 for success, non-zero for failure.
3643 _base_send_ioc_init(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3645 Mpi2IOCInitRequest_t mpi_request
;
3646 Mpi2IOCInitReply_t mpi_reply
;
3648 struct timeval current_time
;
3651 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3654 memset(&mpi_request
, 0, sizeof(Mpi2IOCInitRequest_t
));
3655 mpi_request
.Function
= MPI2_FUNCTION_IOC_INIT
;
3656 mpi_request
.WhoInit
= MPI2_WHOINIT_HOST_DRIVER
;
3657 mpi_request
.VF_ID
= 0; /* TODO */
3658 mpi_request
.VP_ID
= 0;
3659 mpi_request
.MsgVersion
= cpu_to_le16(MPI2_VERSION
);
3660 mpi_request
.HeaderVersion
= cpu_to_le16(MPI2_HEADER_VERSION
);
3662 if (_base_is_controller_msix_enabled(ioc
))
3663 mpi_request
.HostMSIxVectors
= ioc
->reply_queue_count
;
3664 mpi_request
.SystemRequestFrameSize
= cpu_to_le16(ioc
->request_sz
/4);
3665 mpi_request
.ReplyDescriptorPostQueueDepth
=
3666 cpu_to_le16(ioc
->reply_post_queue_depth
);
3667 mpi_request
.ReplyFreeQueueDepth
=
3668 cpu_to_le16(ioc
->reply_free_queue_depth
);
3670 mpi_request
.SenseBufferAddressHigh
=
3671 cpu_to_le32((u64
)ioc
->sense_dma
>> 32);
3672 mpi_request
.SystemReplyAddressHigh
=
3673 cpu_to_le32((u64
)ioc
->reply_dma
>> 32);
3674 mpi_request
.SystemRequestFrameBaseAddress
=
3675 cpu_to_le64((u64
)ioc
->request_dma
);
3676 mpi_request
.ReplyFreeQueueAddress
=
3677 cpu_to_le64((u64
)ioc
->reply_free_dma
);
3678 mpi_request
.ReplyDescriptorPostQueueAddress
=
3679 cpu_to_le64((u64
)ioc
->reply_post_free_dma
);
3682 /* This time stamp specifies number of milliseconds
3683 * since epoch ~ midnight January 1, 1970.
3685 do_gettimeofday(¤t_time
);
3686 mpi_request
.TimeStamp
= cpu_to_le64((u64
)current_time
.tv_sec
* 1000 +
3687 (current_time
.tv_usec
/ 1000));
3689 if (ioc
->logging_level
& MPT_DEBUG_INIT
) {
3693 mfp
= (__le32
*)&mpi_request
;
3694 pr_info("\toffset:data\n");
3695 for (i
= 0; i
< sizeof(Mpi2IOCInitRequest_t
)/4; i
++)
3696 pr_info("\t[0x%02x]:%08x\n", i
*4,
3697 le32_to_cpu(mfp
[i
]));
3700 r
= _base_handshake_req_reply_wait(ioc
,
3701 sizeof(Mpi2IOCInitRequest_t
), (u32
*)&mpi_request
,
3702 sizeof(Mpi2IOCInitReply_t
), (u16
*)&mpi_reply
, 10,
3706 pr_err(MPT3SAS_FMT
"%s: handshake failed (r=%d)\n",
3707 ioc
->name
, __func__
, r
);
3711 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3712 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
||
3713 mpi_reply
.IOCLogInfo
) {
3714 pr_err(MPT3SAS_FMT
"%s: failed\n", ioc
->name
, __func__
);
3722 * mpt3sas_port_enable_done - command completion routine for port enable
3723 * @ioc: per adapter object
3724 * @smid: system request message index
3725 * @msix_index: MSIX table index supplied by the OS
3726 * @reply: reply message frame(lower 32bit addr)
3728 * Return 1 meaning mf should be freed from _base_interrupt
3729 * 0 means the mf is freed from this function.
3732 mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
3735 MPI2DefaultReply_t
*mpi_reply
;
3738 if (ioc
->port_enable_cmds
.status
== MPT3_CMD_NOT_USED
)
3741 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
3745 if (mpi_reply
->Function
!= MPI2_FUNCTION_PORT_ENABLE
)
3748 ioc
->port_enable_cmds
.status
&= ~MPT3_CMD_PENDING
;
3749 ioc
->port_enable_cmds
.status
|= MPT3_CMD_COMPLETE
;
3750 ioc
->port_enable_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
3751 memcpy(ioc
->port_enable_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
3752 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3753 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
)
3754 ioc
->port_enable_failed
= 1;
3756 if (ioc
->is_driver_loading
) {
3757 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
3758 mpt3sas_port_enable_complete(ioc
);
3761 ioc
->start_scan_failed
= ioc_status
;
3762 ioc
->start_scan
= 0;
3766 complete(&ioc
->port_enable_cmds
.done
);
3771 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3772 * @ioc: per adapter object
3773 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3775 * Returns 0 for success, non-zero for failure.
3778 _base_send_port_enable(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3780 Mpi2PortEnableRequest_t
*mpi_request
;
3781 Mpi2PortEnableReply_t
*mpi_reply
;
3782 unsigned long timeleft
;
3787 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
3789 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
3790 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
3791 ioc
->name
, __func__
);
3795 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3797 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3798 ioc
->name
, __func__
);
3802 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
3803 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3804 ioc
->port_enable_cmds
.smid
= smid
;
3805 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3806 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3808 init_completion(&ioc
->port_enable_cmds
.done
);
3809 mpt3sas_base_put_smid_default(ioc
, smid
);
3810 timeleft
= wait_for_completion_timeout(&ioc
->port_enable_cmds
.done
,
3812 if (!(ioc
->port_enable_cmds
.status
& MPT3_CMD_COMPLETE
)) {
3813 pr_err(MPT3SAS_FMT
"%s: timeout\n",
3814 ioc
->name
, __func__
);
3815 _debug_dump_mf(mpi_request
,
3816 sizeof(Mpi2PortEnableRequest_t
)/4);
3817 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_RESET
)
3824 mpi_reply
= ioc
->port_enable_cmds
.reply
;
3825 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3826 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3827 pr_err(MPT3SAS_FMT
"%s: failed with (ioc_status=0x%08x)\n",
3828 ioc
->name
, __func__
, ioc_status
);
3834 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
3835 pr_info(MPT3SAS_FMT
"port enable: %s\n", ioc
->name
, ((r
== 0) ?
3836 "SUCCESS" : "FAILED"));
3841 * mpt3sas_port_enable - initiate firmware discovery (don't wait for reply)
3842 * @ioc: per adapter object
3844 * Returns 0 for success, non-zero for failure.
3847 mpt3sas_port_enable(struct MPT3SAS_ADAPTER
*ioc
)
3849 Mpi2PortEnableRequest_t
*mpi_request
;
3852 pr_info(MPT3SAS_FMT
"sending port enable !!\n", ioc
->name
);
3854 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
3855 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
3856 ioc
->name
, __func__
);
3860 smid
= mpt3sas_base_get_smid(ioc
, ioc
->port_enable_cb_idx
);
3862 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3863 ioc
->name
, __func__
);
3867 ioc
->port_enable_cmds
.status
= MPT3_CMD_PENDING
;
3868 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3869 ioc
->port_enable_cmds
.smid
= smid
;
3870 memset(mpi_request
, 0, sizeof(Mpi2PortEnableRequest_t
));
3871 mpi_request
->Function
= MPI2_FUNCTION_PORT_ENABLE
;
3873 mpt3sas_base_put_smid_default(ioc
, smid
);
3878 * _base_determine_wait_on_discovery - desposition
3879 * @ioc: per adapter object
3881 * Decide whether to wait on discovery to complete. Used to either
3882 * locate boot device, or report volumes ahead of physical devices.
3884 * Returns 1 for wait, 0 for don't wait
3887 _base_determine_wait_on_discovery(struct MPT3SAS_ADAPTER
*ioc
)
3889 /* We wait for discovery to complete if IR firmware is loaded.
3890 * The sas topology events arrive before PD events, so we need time to
3891 * turn on the bit in ioc->pd_handles to indicate PD
3892 * Also, it maybe required to report Volumes ahead of physical
3893 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3895 if (ioc
->ir_firmware
)
3898 /* if no Bios, then we don't need to wait */
3899 if (!ioc
->bios_pg3
.BiosVersion
)
3902 /* Bios is present, then we drop down here.
3904 * If there any entries in the Bios Page 2, then we wait
3905 * for discovery to complete.
3908 /* Current Boot Device */
3909 if ((ioc
->bios_pg2
.CurrentBootDeviceForm
&
3910 MPI2_BIOSPAGE2_FORM_MASK
) ==
3911 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
3912 /* Request Boot Device */
3913 (ioc
->bios_pg2
.ReqBootDeviceForm
&
3914 MPI2_BIOSPAGE2_FORM_MASK
) ==
3915 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
&&
3916 /* Alternate Request Boot Device */
3917 (ioc
->bios_pg2
.ReqAltBootDeviceForm
&
3918 MPI2_BIOSPAGE2_FORM_MASK
) ==
3919 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED
)
3926 * _base_unmask_events - turn on notification for this event
3927 * @ioc: per adapter object
3928 * @event: firmware event
3930 * The mask is stored in ioc->event_masks.
3933 _base_unmask_events(struct MPT3SAS_ADAPTER
*ioc
, u16 event
)
3940 desired_event
= (1 << (event
% 32));
3943 ioc
->event_masks
[0] &= ~desired_event
;
3944 else if (event
< 64)
3945 ioc
->event_masks
[1] &= ~desired_event
;
3946 else if (event
< 96)
3947 ioc
->event_masks
[2] &= ~desired_event
;
3948 else if (event
< 128)
3949 ioc
->event_masks
[3] &= ~desired_event
;
3953 * _base_event_notification - send event notification
3954 * @ioc: per adapter object
3955 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3957 * Returns 0 for success, non-zero for failure.
3960 _base_event_notification(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
3962 Mpi2EventNotificationRequest_t
*mpi_request
;
3963 unsigned long timeleft
;
3968 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
3971 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
3972 pr_err(MPT3SAS_FMT
"%s: internal command already in use\n",
3973 ioc
->name
, __func__
);
3977 smid
= mpt3sas_base_get_smid(ioc
, ioc
->base_cb_idx
);
3979 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
3980 ioc
->name
, __func__
);
3983 ioc
->base_cmds
.status
= MPT3_CMD_PENDING
;
3984 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
3985 ioc
->base_cmds
.smid
= smid
;
3986 memset(mpi_request
, 0, sizeof(Mpi2EventNotificationRequest_t
));
3987 mpi_request
->Function
= MPI2_FUNCTION_EVENT_NOTIFICATION
;
3988 mpi_request
->VF_ID
= 0; /* TODO */
3989 mpi_request
->VP_ID
= 0;
3990 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
3991 mpi_request
->EventMasks
[i
] =
3992 cpu_to_le32(ioc
->event_masks
[i
]);
3993 init_completion(&ioc
->base_cmds
.done
);
3994 mpt3sas_base_put_smid_default(ioc
, smid
);
3995 timeleft
= wait_for_completion_timeout(&ioc
->base_cmds
.done
, 30*HZ
);
3996 if (!(ioc
->base_cmds
.status
& MPT3_CMD_COMPLETE
)) {
3997 pr_err(MPT3SAS_FMT
"%s: timeout\n",
3998 ioc
->name
, __func__
);
3999 _debug_dump_mf(mpi_request
,
4000 sizeof(Mpi2EventNotificationRequest_t
)/4);
4001 if (ioc
->base_cmds
.status
& MPT3_CMD_RESET
)
4006 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: complete\n",
4007 ioc
->name
, __func__
));
4008 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4013 * mpt3sas_base_validate_event_type - validating event types
4014 * @ioc: per adapter object
4015 * @event: firmware event
4017 * This will turn on firmware event notification when application
4018 * ask for that event. We don't mask events that are already enabled.
4021 mpt3sas_base_validate_event_type(struct MPT3SAS_ADAPTER
*ioc
, u32
*event_type
)
4024 u32 event_mask
, desired_event
;
4025 u8 send_update_to_fw
;
4027 for (i
= 0, send_update_to_fw
= 0; i
<
4028 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++) {
4029 event_mask
= ~event_type
[i
];
4031 for (j
= 0; j
< 32; j
++) {
4032 if (!(event_mask
& desired_event
) &&
4033 (ioc
->event_masks
[i
] & desired_event
)) {
4034 ioc
->event_masks
[i
] &= ~desired_event
;
4035 send_update_to_fw
= 1;
4037 desired_event
= (desired_event
<< 1);
4041 if (!send_update_to_fw
)
4044 mutex_lock(&ioc
->base_cmds
.mutex
);
4045 _base_event_notification(ioc
, CAN_SLEEP
);
4046 mutex_unlock(&ioc
->base_cmds
.mutex
);
4050 * _base_diag_reset - the "big hammer" start of day reset
4051 * @ioc: per adapter object
4052 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4054 * Returns 0 for success, non-zero for failure.
4057 _base_diag_reset(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4059 u32 host_diagnostic
;
4064 pr_info(MPT3SAS_FMT
"sending diag reset !!\n", ioc
->name
);
4066 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"clear interrupts\n",
4071 /* Write magic sequence to WriteSequence register
4072 * Loop until in diagnostic mode
4074 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4075 "write magic sequence\n", ioc
->name
));
4076 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4077 writel(MPI2_WRSEQ_1ST_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4078 writel(MPI2_WRSEQ_2ND_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4079 writel(MPI2_WRSEQ_3RD_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4080 writel(MPI2_WRSEQ_4TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4081 writel(MPI2_WRSEQ_5TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4082 writel(MPI2_WRSEQ_6TH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4085 if (sleep_flag
== CAN_SLEEP
)
4093 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
4094 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4095 "wrote magic sequence: count(%d), host_diagnostic(0x%08x)\n",
4096 ioc
->name
, count
, host_diagnostic
));
4098 } while ((host_diagnostic
& MPI2_DIAG_DIAG_WRITE_ENABLE
) == 0);
4100 hcb_size
= readl(&ioc
->chip
->HCBSize
);
4102 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"diag reset: issued\n",
4104 writel(host_diagnostic
| MPI2_DIAG_RESET_ADAPTER
,
4105 &ioc
->chip
->HostDiagnostic
);
4107 /*This delay allows the chip PCIe hardware time to finish reset tasks*/
4108 if (sleep_flag
== CAN_SLEEP
)
4109 msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
4111 mdelay(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC
/1000);
4113 /* Approximately 300 second max wait */
4114 for (count
= 0; count
< (300000000 /
4115 MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
); count
++) {
4117 host_diagnostic
= readl(&ioc
->chip
->HostDiagnostic
);
4119 if (host_diagnostic
== 0xFFFFFFFF)
4121 if (!(host_diagnostic
& MPI2_DIAG_RESET_ADAPTER
))
4124 /* Wait to pass the second read delay window */
4125 if (sleep_flag
== CAN_SLEEP
)
4126 msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
4129 mdelay(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC
4133 if (host_diagnostic
& MPI2_DIAG_HCB_MODE
) {
4135 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4136 "restart the adapter assuming the HCB Address points to good F/W\n",
4138 host_diagnostic
&= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK
;
4139 host_diagnostic
|= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW
;
4140 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
4142 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4143 "re-enable the HCDW\n", ioc
->name
));
4144 writel(hcb_size
| MPI2_HCB_SIZE_HCB_ENABLE
,
4145 &ioc
->chip
->HCBSize
);
4148 drsprintk(ioc
, pr_info(MPT3SAS_FMT
"restart the adapter\n",
4150 writel(host_diagnostic
& ~MPI2_DIAG_HOLD_IOC_RESET
,
4151 &ioc
->chip
->HostDiagnostic
);
4153 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4154 "disable writes to the diagnostic register\n", ioc
->name
));
4155 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE
, &ioc
->chip
->WriteSequence
);
4157 drsprintk(ioc
, pr_info(MPT3SAS_FMT
4158 "Wait for FW to go to the READY state\n", ioc
->name
));
4159 ioc_state
= _base_wait_on_iocstate(ioc
, MPI2_IOC_STATE_READY
, 20,
4163 "%s: failed going to ready state (ioc_state=0x%x)\n",
4164 ioc
->name
, __func__
, ioc_state
);
4168 pr_info(MPT3SAS_FMT
"diag reset: SUCCESS\n", ioc
->name
);
4172 pr_err(MPT3SAS_FMT
"diag reset: FAILED\n", ioc
->name
);
4177 * _base_make_ioc_ready - put controller in READY state
4178 * @ioc: per adapter object
4179 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4180 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4182 * Returns 0 for success, non-zero for failure.
4185 _base_make_ioc_ready(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
,
4186 enum reset_type type
)
4192 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4195 if (ioc
->pci_error_recovery
)
4198 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4199 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: ioc_state(0x%08x)\n",
4200 ioc
->name
, __func__
, ioc_state
));
4202 /* if in RESET state, it should move to READY state shortly */
4204 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_RESET
) {
4205 while ((ioc_state
& MPI2_IOC_STATE_MASK
) !=
4206 MPI2_IOC_STATE_READY
) {
4207 if (count
++ == 10) {
4209 "%s: failed going to ready state (ioc_state=0x%x)\n",
4210 ioc
->name
, __func__
, ioc_state
);
4213 if (sleep_flag
== CAN_SLEEP
)
4217 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4221 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_READY
)
4224 if (ioc_state
& MPI2_DOORBELL_USED
) {
4225 dhsprintk(ioc
, pr_info(MPT3SAS_FMT
4226 "unexpected doorbell active!\n",
4228 goto issue_diag_reset
;
4231 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
) {
4232 mpt3sas_base_fault_info(ioc
, ioc_state
&
4233 MPI2_DOORBELL_DATA_MASK
);
4234 goto issue_diag_reset
;
4237 if (type
== FORCE_BIG_HAMMER
)
4238 goto issue_diag_reset
;
4240 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_OPERATIONAL
)
4241 if (!(_base_send_ioc_reset(ioc
,
4242 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
, 15, CAN_SLEEP
))) {
4247 rc
= _base_diag_reset(ioc
, CAN_SLEEP
);
4252 * _base_make_ioc_operational - put controller in OPERATIONAL state
4253 * @ioc: per adapter object
4254 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4256 * Returns 0 for success, non-zero for failure.
4259 _base_make_ioc_operational(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4262 unsigned long flags
;
4265 struct _tr_list
*delayed_tr
, *delayed_tr_next
;
4266 struct adapter_reply_queue
*reply_q
;
4267 long reply_post_free
;
4268 u32 reply_post_free_sz
;
4270 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4273 /* clean the delayed target reset list */
4274 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4275 &ioc
->delayed_tr_list
, list
) {
4276 list_del(&delayed_tr
->list
);
4281 list_for_each_entry_safe(delayed_tr
, delayed_tr_next
,
4282 &ioc
->delayed_tr_volume_list
, list
) {
4283 list_del(&delayed_tr
->list
);
4287 /* initialize the scsi lookup free list */
4288 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4289 INIT_LIST_HEAD(&ioc
->free_list
);
4291 for (i
= 0; i
< ioc
->scsiio_depth
; i
++, smid
++) {
4292 INIT_LIST_HEAD(&ioc
->scsi_lookup
[i
].chain_list
);
4293 ioc
->scsi_lookup
[i
].cb_idx
= 0xFF;
4294 ioc
->scsi_lookup
[i
].smid
= smid
;
4295 ioc
->scsi_lookup
[i
].scmd
= NULL
;
4296 list_add_tail(&ioc
->scsi_lookup
[i
].tracker_list
,
4300 /* hi-priority queue */
4301 INIT_LIST_HEAD(&ioc
->hpr_free_list
);
4302 smid
= ioc
->hi_priority_smid
;
4303 for (i
= 0; i
< ioc
->hi_priority_depth
; i
++, smid
++) {
4304 ioc
->hpr_lookup
[i
].cb_idx
= 0xFF;
4305 ioc
->hpr_lookup
[i
].smid
= smid
;
4306 list_add_tail(&ioc
->hpr_lookup
[i
].tracker_list
,
4307 &ioc
->hpr_free_list
);
4310 /* internal queue */
4311 INIT_LIST_HEAD(&ioc
->internal_free_list
);
4312 smid
= ioc
->internal_smid
;
4313 for (i
= 0; i
< ioc
->internal_depth
; i
++, smid
++) {
4314 ioc
->internal_lookup
[i
].cb_idx
= 0xFF;
4315 ioc
->internal_lookup
[i
].smid
= smid
;
4316 list_add_tail(&ioc
->internal_lookup
[i
].tracker_list
,
4317 &ioc
->internal_free_list
);
4321 INIT_LIST_HEAD(&ioc
->free_chain_list
);
4322 for (i
= 0; i
< ioc
->chain_depth
; i
++)
4323 list_add_tail(&ioc
->chain_lookup
[i
].tracker_list
,
4324 &ioc
->free_chain_list
);
4326 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4328 /* initialize Reply Free Queue */
4329 for (i
= 0, reply_address
= (u32
)ioc
->reply_dma
;
4330 i
< ioc
->reply_free_queue_depth
; i
++, reply_address
+=
4332 ioc
->reply_free
[i
] = cpu_to_le32(reply_address
);
4334 /* initialize reply queues */
4335 if (ioc
->is_driver_loading
)
4336 _base_assign_reply_queues(ioc
);
4338 /* initialize Reply Post Free Queue */
4339 reply_post_free
= (long)ioc
->reply_post_free
;
4340 reply_post_free_sz
= ioc
->reply_post_queue_depth
*
4341 sizeof(Mpi2DefaultReplyDescriptor_t
);
4342 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4343 reply_q
->reply_post_host_index
= 0;
4344 reply_q
->reply_post_free
= (Mpi2ReplyDescriptorsUnion_t
*)
4346 for (i
= 0; i
< ioc
->reply_post_queue_depth
; i
++)
4347 reply_q
->reply_post_free
[i
].Words
=
4348 cpu_to_le64(ULLONG_MAX
);
4349 if (!_base_is_controller_msix_enabled(ioc
))
4350 goto skip_init_reply_post_free_queue
;
4351 reply_post_free
+= reply_post_free_sz
;
4353 skip_init_reply_post_free_queue
:
4355 r
= _base_send_ioc_init(ioc
, sleep_flag
);
4359 /* initialize reply free host index */
4360 ioc
->reply_free_host_index
= ioc
->reply_free_queue_depth
- 1;
4361 writel(ioc
->reply_free_host_index
, &ioc
->chip
->ReplyFreeHostIndex
);
4363 /* initialize reply post host index */
4364 list_for_each_entry(reply_q
, &ioc
->reply_queue_list
, list
) {
4365 writel(reply_q
->msix_index
<< MPI2_RPHI_MSIX_INDEX_SHIFT
,
4366 &ioc
->chip
->ReplyPostHostIndex
);
4367 if (!_base_is_controller_msix_enabled(ioc
))
4368 goto skip_init_reply_post_host_index
;
4371 skip_init_reply_post_host_index
:
4373 _base_unmask_interrupts(ioc
);
4374 r
= _base_event_notification(ioc
, sleep_flag
);
4378 if (sleep_flag
== CAN_SLEEP
)
4379 _base_static_config_pages(ioc
);
4382 if (ioc
->is_driver_loading
) {
4383 ioc
->wait_for_discovery_to_complete
=
4384 _base_determine_wait_on_discovery(ioc
);
4386 return r
; /* scan_start and scan_finished support */
4389 r
= _base_send_port_enable(ioc
, sleep_flag
);
4397 * mpt3sas_base_free_resources - free resources controller resources
4398 * @ioc: per adapter object
4403 mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER
*ioc
)
4405 struct pci_dev
*pdev
= ioc
->pdev
;
4407 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4410 if (ioc
->chip_phys
&& ioc
->chip
) {
4411 _base_mask_interrupts(ioc
);
4412 ioc
->shost_recovery
= 1;
4413 _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4414 ioc
->shost_recovery
= 0;
4417 _base_free_irq(ioc
);
4418 _base_disable_msix(ioc
);
4420 if (ioc
->chip_phys
&& ioc
->chip
)
4424 if (pci_is_enabled(pdev
)) {
4425 pci_release_selected_regions(ioc
->pdev
, ioc
->bars
);
4426 pci_disable_pcie_error_reporting(pdev
);
4427 pci_disable_device(pdev
);
4433 * mpt3sas_base_attach - attach controller instance
4434 * @ioc: per adapter object
4436 * Returns 0 for success, non-zero for failure.
4439 mpt3sas_base_attach(struct MPT3SAS_ADAPTER
*ioc
)
4442 int cpu_id
, last_cpu_id
= 0;
4444 dinitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4447 /* setup cpu_msix_table */
4448 ioc
->cpu_count
= num_online_cpus();
4449 for_each_online_cpu(cpu_id
)
4450 last_cpu_id
= cpu_id
;
4451 ioc
->cpu_msix_table_sz
= last_cpu_id
+ 1;
4452 ioc
->cpu_msix_table
= kzalloc(ioc
->cpu_msix_table_sz
, GFP_KERNEL
);
4453 ioc
->reply_queue_count
= 1;
4454 if (!ioc
->cpu_msix_table
) {
4455 dfailprintk(ioc
, pr_info(MPT3SAS_FMT
4456 "allocation for cpu_msix_table failed!!!\n",
4459 goto out_free_resources
;
4462 r
= mpt3sas_base_map_resources(ioc
);
4464 goto out_free_resources
;
4467 pci_set_drvdata(ioc
->pdev
, ioc
->shost
);
4468 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
4470 goto out_free_resources
;
4474 * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and
4475 * Target Status - all require the IEEE formated scatter gather
4479 ioc
->build_sg_scmd
= &_base_build_sg_scmd_ieee
;
4480 ioc
->build_sg
= &_base_build_sg_ieee
;
4481 ioc
->build_zero_len_sge
= &_base_build_zero_len_sge_ieee
;
4483 ioc
->sge_size_ieee
= sizeof(Mpi2IeeeSgeSimple64_t
);
4486 * These function pointers for other requests that don't
4487 * the require IEEE scatter gather elements.
4489 * For example Configuration Pages and SAS IOUNIT Control don't.
4491 ioc
->build_sg_mpi
= &_base_build_sg
;
4492 ioc
->build_zero_len_sge_mpi
= &_base_build_zero_len_sge
;
4494 r
= _base_make_ioc_ready(ioc
, CAN_SLEEP
, SOFT_RESET
);
4496 goto out_free_resources
;
4498 ioc
->pfacts
= kcalloc(ioc
->facts
.NumberOfPorts
,
4499 sizeof(struct mpt3sas_port_facts
), GFP_KERNEL
);
4502 goto out_free_resources
;
4505 for (i
= 0 ; i
< ioc
->facts
.NumberOfPorts
; i
++) {
4506 r
= _base_get_port_facts(ioc
, i
, CAN_SLEEP
);
4508 goto out_free_resources
;
4511 r
= _base_allocate_memory_pools(ioc
, CAN_SLEEP
);
4513 goto out_free_resources
;
4515 init_waitqueue_head(&ioc
->reset_wq
);
4517 /* allocate memory pd handle bitmask list */
4518 ioc
->pd_handles_sz
= (ioc
->facts
.MaxDevHandle
/ 8);
4519 if (ioc
->facts
.MaxDevHandle
% 8)
4520 ioc
->pd_handles_sz
++;
4521 ioc
->pd_handles
= kzalloc(ioc
->pd_handles_sz
,
4523 if (!ioc
->pd_handles
) {
4525 goto out_free_resources
;
4527 ioc
->blocking_handles
= kzalloc(ioc
->pd_handles_sz
,
4529 if (!ioc
->blocking_handles
) {
4531 goto out_free_resources
;
4534 ioc
->fwfault_debug
= mpt3sas_fwfault_debug
;
4536 /* base internal command bits */
4537 mutex_init(&ioc
->base_cmds
.mutex
);
4538 ioc
->base_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4539 ioc
->base_cmds
.status
= MPT3_CMD_NOT_USED
;
4541 /* port_enable command bits */
4542 ioc
->port_enable_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4543 ioc
->port_enable_cmds
.status
= MPT3_CMD_NOT_USED
;
4545 /* transport internal command bits */
4546 ioc
->transport_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4547 ioc
->transport_cmds
.status
= MPT3_CMD_NOT_USED
;
4548 mutex_init(&ioc
->transport_cmds
.mutex
);
4550 /* scsih internal command bits */
4551 ioc
->scsih_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4552 ioc
->scsih_cmds
.status
= MPT3_CMD_NOT_USED
;
4553 mutex_init(&ioc
->scsih_cmds
.mutex
);
4555 /* task management internal command bits */
4556 ioc
->tm_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4557 ioc
->tm_cmds
.status
= MPT3_CMD_NOT_USED
;
4558 mutex_init(&ioc
->tm_cmds
.mutex
);
4560 /* config page internal command bits */
4561 ioc
->config_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4562 ioc
->config_cmds
.status
= MPT3_CMD_NOT_USED
;
4563 mutex_init(&ioc
->config_cmds
.mutex
);
4565 /* ctl module internal command bits */
4566 ioc
->ctl_cmds
.reply
= kzalloc(ioc
->reply_sz
, GFP_KERNEL
);
4567 ioc
->ctl_cmds
.sense
= kzalloc(SCSI_SENSE_BUFFERSIZE
, GFP_KERNEL
);
4568 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
4569 mutex_init(&ioc
->ctl_cmds
.mutex
);
4571 if (!ioc
->base_cmds
.reply
|| !ioc
->transport_cmds
.reply
||
4572 !ioc
->scsih_cmds
.reply
|| !ioc
->tm_cmds
.reply
||
4573 !ioc
->config_cmds
.reply
|| !ioc
->ctl_cmds
.reply
||
4574 !ioc
->ctl_cmds
.sense
) {
4576 goto out_free_resources
;
4579 for (i
= 0; i
< MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4580 ioc
->event_masks
[i
] = -1;
4582 /* here we enable the events we care about */
4583 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DISCOVERY
);
4584 _base_unmask_events(ioc
, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE
);
4585 _base_unmask_events(ioc
, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
4586 _base_unmask_events(ioc
, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE
);
4587 _base_unmask_events(ioc
, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE
);
4588 _base_unmask_events(ioc
, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST
);
4589 _base_unmask_events(ioc
, MPI2_EVENT_IR_VOLUME
);
4590 _base_unmask_events(ioc
, MPI2_EVENT_IR_PHYSICAL_DISK
);
4591 _base_unmask_events(ioc
, MPI2_EVENT_IR_OPERATION_STATUS
);
4592 _base_unmask_events(ioc
, MPI2_EVENT_LOG_ENTRY_ADDED
);
4594 r
= _base_make_ioc_operational(ioc
, CAN_SLEEP
);
4596 goto out_free_resources
;
4602 ioc
->remove_host
= 1;
4604 mpt3sas_base_free_resources(ioc
);
4605 _base_release_memory_pools(ioc
);
4606 pci_set_drvdata(ioc
->pdev
, NULL
);
4607 kfree(ioc
->cpu_msix_table
);
4608 kfree(ioc
->pd_handles
);
4609 kfree(ioc
->blocking_handles
);
4610 kfree(ioc
->tm_cmds
.reply
);
4611 kfree(ioc
->transport_cmds
.reply
);
4612 kfree(ioc
->scsih_cmds
.reply
);
4613 kfree(ioc
->config_cmds
.reply
);
4614 kfree(ioc
->base_cmds
.reply
);
4615 kfree(ioc
->port_enable_cmds
.reply
);
4616 kfree(ioc
->ctl_cmds
.reply
);
4617 kfree(ioc
->ctl_cmds
.sense
);
4619 ioc
->ctl_cmds
.reply
= NULL
;
4620 ioc
->base_cmds
.reply
= NULL
;
4621 ioc
->tm_cmds
.reply
= NULL
;
4622 ioc
->scsih_cmds
.reply
= NULL
;
4623 ioc
->transport_cmds
.reply
= NULL
;
4624 ioc
->config_cmds
.reply
= NULL
;
4631 * mpt3sas_base_detach - remove controller instance
4632 * @ioc: per adapter object
4637 mpt3sas_base_detach(struct MPT3SAS_ADAPTER
*ioc
)
4639 dexitprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
4642 mpt3sas_base_stop_watchdog(ioc
);
4643 mpt3sas_base_free_resources(ioc
);
4644 _base_release_memory_pools(ioc
);
4645 pci_set_drvdata(ioc
->pdev
, NULL
);
4646 kfree(ioc
->cpu_msix_table
);
4647 kfree(ioc
->pd_handles
);
4648 kfree(ioc
->blocking_handles
);
4650 kfree(ioc
->ctl_cmds
.reply
);
4651 kfree(ioc
->ctl_cmds
.sense
);
4652 kfree(ioc
->base_cmds
.reply
);
4653 kfree(ioc
->port_enable_cmds
.reply
);
4654 kfree(ioc
->tm_cmds
.reply
);
4655 kfree(ioc
->transport_cmds
.reply
);
4656 kfree(ioc
->scsih_cmds
.reply
);
4657 kfree(ioc
->config_cmds
.reply
);
4661 * _base_reset_handler - reset callback handler (for base)
4662 * @ioc: per adapter object
4663 * @reset_phase: phase
4665 * The handler for doing any required cleanup or initialization.
4667 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
4668 * MPT3_IOC_DONE_RESET
4673 _base_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
4675 mpt3sas_scsih_reset_handler(ioc
, reset_phase
);
4676 mpt3sas_ctl_reset_handler(ioc
, reset_phase
);
4677 switch (reset_phase
) {
4678 case MPT3_IOC_PRE_RESET
:
4679 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4680 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
4682 case MPT3_IOC_AFTER_RESET
:
4683 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4684 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
4685 if (ioc
->transport_cmds
.status
& MPT3_CMD_PENDING
) {
4686 ioc
->transport_cmds
.status
|= MPT3_CMD_RESET
;
4687 mpt3sas_base_free_smid(ioc
, ioc
->transport_cmds
.smid
);
4688 complete(&ioc
->transport_cmds
.done
);
4690 if (ioc
->base_cmds
.status
& MPT3_CMD_PENDING
) {
4691 ioc
->base_cmds
.status
|= MPT3_CMD_RESET
;
4692 mpt3sas_base_free_smid(ioc
, ioc
->base_cmds
.smid
);
4693 complete(&ioc
->base_cmds
.done
);
4695 if (ioc
->port_enable_cmds
.status
& MPT3_CMD_PENDING
) {
4696 ioc
->port_enable_failed
= 1;
4697 ioc
->port_enable_cmds
.status
|= MPT3_CMD_RESET
;
4698 mpt3sas_base_free_smid(ioc
, ioc
->port_enable_cmds
.smid
);
4699 if (ioc
->is_driver_loading
) {
4700 ioc
->start_scan_failed
=
4701 MPI2_IOCSTATUS_INTERNAL_ERROR
;
4702 ioc
->start_scan
= 0;
4703 ioc
->port_enable_cmds
.status
=
4706 complete(&ioc
->port_enable_cmds
.done
);
4708 if (ioc
->config_cmds
.status
& MPT3_CMD_PENDING
) {
4709 ioc
->config_cmds
.status
|= MPT3_CMD_RESET
;
4710 mpt3sas_base_free_smid(ioc
, ioc
->config_cmds
.smid
);
4711 ioc
->config_cmds
.smid
= USHRT_MAX
;
4712 complete(&ioc
->config_cmds
.done
);
4715 case MPT3_IOC_DONE_RESET
:
4716 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
4717 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
4723 * _wait_for_commands_to_complete - reset controller
4724 * @ioc: Pointer to MPT_ADAPTER structure
4725 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4727 * This function waiting(3s) for all pending commands to complete
4728 * prior to putting controller in reset.
4731 _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
)
4734 unsigned long flags
;
4737 ioc
->pending_io_count
= 0;
4738 if (sleep_flag
!= CAN_SLEEP
)
4741 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4742 if ((ioc_state
& MPI2_IOC_STATE_MASK
) != MPI2_IOC_STATE_OPERATIONAL
)
4745 /* pending command count */
4746 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
4747 for (i
= 0; i
< ioc
->scsiio_depth
; i
++)
4748 if (ioc
->scsi_lookup
[i
].cb_idx
!= 0xFF)
4749 ioc
->pending_io_count
++;
4750 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
4752 if (!ioc
->pending_io_count
)
4755 /* wait for pending commands to complete */
4756 wait_event_timeout(ioc
->reset_wq
, ioc
->pending_io_count
== 0, 10 * HZ
);
4760 * mpt3sas_base_hard_reset_handler - reset controller
4761 * @ioc: Pointer to MPT_ADAPTER structure
4762 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4763 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4765 * Returns 0 for success, non-zero for failure.
4768 mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int sleep_flag
,
4769 enum reset_type type
)
4772 unsigned long flags
;
4774 u8 is_fault
= 0, is_trigger
= 0;
4776 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
4779 if (ioc
->pci_error_recovery
) {
4780 pr_err(MPT3SAS_FMT
"%s: pci error recovery reset\n",
4781 ioc
->name
, __func__
);
4786 if (mpt3sas_fwfault_debug
)
4787 mpt3sas_halt_firmware(ioc
);
4789 /* TODO - What we really should be doing is pulling
4790 * out all the code associated with NO_SLEEP; its never used.
4791 * That is legacy code from mpt fusion driver, ported over.
4792 * I will leave this BUG_ON here for now till its been resolved.
4794 BUG_ON(sleep_flag
== NO_SLEEP
);
4796 /* wait for an active reset in progress to complete */
4797 if (!mutex_trylock(&ioc
->reset_in_progress_mutex
)) {
4800 } while (ioc
->shost_recovery
== 1);
4801 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,
4803 return ioc
->ioc_reset_in_progress_status
;
4806 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4807 ioc
->shost_recovery
= 1;
4808 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4810 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
4811 MPT3_DIAG_BUFFER_IS_REGISTERED
) &&
4812 (!(ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
4813 MPT3_DIAG_BUFFER_IS_RELEASED
))) {
4815 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 0);
4816 if ((ioc_state
& MPI2_IOC_STATE_MASK
) == MPI2_IOC_STATE_FAULT
)
4819 _base_reset_handler(ioc
, MPT3_IOC_PRE_RESET
);
4820 _wait_for_commands_to_complete(ioc
, sleep_flag
);
4821 _base_mask_interrupts(ioc
);
4822 r
= _base_make_ioc_ready(ioc
, sleep_flag
, type
);
4825 _base_reset_handler(ioc
, MPT3_IOC_AFTER_RESET
);
4827 /* If this hard reset is called while port enable is active, then
4828 * there is no reason to call make_ioc_operational
4830 if (ioc
->is_driver_loading
&& ioc
->port_enable_failed
) {
4831 ioc
->remove_host
= 1;
4835 r
= _base_get_ioc_facts(ioc
, CAN_SLEEP
);
4838 r
= _base_make_ioc_operational(ioc
, sleep_flag
);
4840 _base_reset_handler(ioc
, MPT3_IOC_DONE_RESET
);
4843 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: %s\n",
4844 ioc
->name
, __func__
, ((r
== 0) ? "SUCCESS" : "FAILED")));
4846 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
4847 ioc
->ioc_reset_in_progress_status
= r
;
4848 ioc
->shost_recovery
= 0;
4849 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
4850 ioc
->ioc_reset_count
++;
4851 mutex_unlock(&ioc
->reset_in_progress_mutex
);
4854 if ((r
== 0) && is_trigger
) {
4856 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_FW_FAULT
);
4858 mpt3sas_trigger_master(ioc
,
4859 MASTER_TRIGGER_ADAPTER_RESET
);
4861 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: exit\n", ioc
->name
,