2 * Management Module Support for MPT (Message Passing Technology) based
5 * This code is based on drivers/scsi/mpt3sas/mpt3sas_ctl.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * Copyright (C) 2013-2014 Avago Technologies
8 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 * solely responsible for determining the appropriateness of using and
26 * distributing the Program and assumes all risks associated with its
27 * exercise of rights under this Agreement, including but not limited to
28 * the risks and costs of program errors, damage to or loss of data,
29 * programs or equipment, and unavailability or interruption of operations.
31 * DISCLAIMER OF LIABILITY
32 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/slab.h>
51 #include <linux/types.h>
52 #include <linux/pci.h>
53 #include <linux/delay.h>
54 #include <linux/compat.h>
55 #include <linux/poll.h>
58 #include <linux/uaccess.h>
60 #include "mpt3sas_base.h"
61 #include "mpt3sas_ctl.h"
64 static struct fasync_struct *async_queue;
65 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
69 * enum block_state - blocking state
70 * @NON_BLOCKING: non blocking
73 * These states are for ioctls that need to wait for a response
74 * from firmware, so they probably require sleep.
82 * _ctl_display_some_debug - debug routine
83 * @ioc: per adapter object
84 * @smid: system request message index
85 * @calling_function_name: string pass from calling function
86 * @mpi_reply: reply message frame
89 * Function for displaying debug info helpful when debugging issues
93 _ctl_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid,
94 char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
96 Mpi2ConfigRequest_t *mpi_request;
99 if (!(ioc->logging_level & MPT_DEBUG_IOCTL))
102 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
103 switch (mpi_request->Function) {
104 case MPI2_FUNCTION_SCSI_IO_REQUEST:
106 Mpi2SCSIIORequest_t *scsi_request =
107 (Mpi2SCSIIORequest_t *)mpi_request;
109 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
110 "scsi_io, cmd(0x%02x), cdb_len(%d)",
111 scsi_request->CDB.CDB32[0],
112 le16_to_cpu(scsi_request->IoFlags) & 0xF);
113 desc = ioc->tmp_string;
116 case MPI2_FUNCTION_SCSI_TASK_MGMT:
119 case MPI2_FUNCTION_IOC_INIT:
122 case MPI2_FUNCTION_IOC_FACTS:
125 case MPI2_FUNCTION_CONFIG:
127 Mpi2ConfigRequest_t *config_request =
128 (Mpi2ConfigRequest_t *)mpi_request;
130 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
131 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
132 (config_request->Header.PageType &
133 MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType,
134 config_request->Header.PageNumber);
135 desc = ioc->tmp_string;
138 case MPI2_FUNCTION_PORT_FACTS:
141 case MPI2_FUNCTION_PORT_ENABLE:
142 desc = "port_enable";
144 case MPI2_FUNCTION_EVENT_NOTIFICATION:
145 desc = "event_notification";
147 case MPI2_FUNCTION_FW_DOWNLOAD:
148 desc = "fw_download";
150 case MPI2_FUNCTION_FW_UPLOAD:
153 case MPI2_FUNCTION_RAID_ACTION:
154 desc = "raid_action";
156 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
158 Mpi2SCSIIORequest_t *scsi_request =
159 (Mpi2SCSIIORequest_t *)mpi_request;
161 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
162 "raid_pass, cmd(0x%02x), cdb_len(%d)",
163 scsi_request->CDB.CDB32[0],
164 le16_to_cpu(scsi_request->IoFlags) & 0xF);
165 desc = ioc->tmp_string;
168 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
169 desc = "sas_iounit_cntl";
171 case MPI2_FUNCTION_SATA_PASSTHROUGH:
174 case MPI2_FUNCTION_DIAG_BUFFER_POST:
175 desc = "diag_buffer_post";
177 case MPI2_FUNCTION_DIAG_RELEASE:
178 desc = "diag_release";
180 case MPI2_FUNCTION_SMP_PASSTHROUGH:
181 desc = "smp_passthrough";
188 ioc_info(ioc, "%s: %s, smid(%d)\n", calling_function_name, desc, smid);
193 if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
194 ioc_info(ioc, "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
195 le16_to_cpu(mpi_reply->IOCStatus),
196 le32_to_cpu(mpi_reply->IOCLogInfo));
198 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
199 mpi_request->Function ==
200 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
201 Mpi2SCSIIOReply_t *scsi_reply =
202 (Mpi2SCSIIOReply_t *)mpi_reply;
203 struct _sas_device *sas_device = NULL;
204 struct _pcie_device *pcie_device = NULL;
206 sas_device = mpt3sas_get_sdev_by_handle(ioc,
207 le16_to_cpu(scsi_reply->DevHandle));
209 ioc_warn(ioc, "\tsas_address(0x%016llx), phy(%d)\n",
210 (u64)sas_device->sas_address,
212 ioc_warn(ioc, "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
213 (u64)sas_device->enclosure_logical_id,
215 sas_device_put(sas_device);
218 pcie_device = mpt3sas_get_pdev_by_handle(ioc,
219 le16_to_cpu(scsi_reply->DevHandle));
221 ioc_warn(ioc, "\tWWID(0x%016llx), port(%d)\n",
222 (unsigned long long)pcie_device->wwid,
223 pcie_device->port_num);
224 if (pcie_device->enclosure_handle != 0)
225 ioc_warn(ioc, "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
226 (u64)pcie_device->enclosure_logical_id,
228 pcie_device_put(pcie_device);
231 if (scsi_reply->SCSIState || scsi_reply->SCSIStatus)
232 ioc_info(ioc, "\tscsi_state(0x%02x), scsi_status(0x%02x)\n",
233 scsi_reply->SCSIState,
234 scsi_reply->SCSIStatus);
239 * mpt3sas_ctl_done - ctl module completion routine
240 * @ioc: per adapter object
241 * @smid: system request message index
242 * @msix_index: MSIX table index supplied by the OS
243 * @reply: reply message frame(lower 32bit addr)
246 * The callback handler when using ioc->ctl_cb_idx.
248 * Return: 1 meaning mf should be freed from _base_interrupt
249 * 0 means the mf is freed from this function.
252 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
255 MPI2DefaultReply_t *mpi_reply;
256 Mpi2SCSIIOReply_t *scsiio_reply;
257 Mpi26NVMeEncapsulatedErrorReply_t *nvme_error_reply;
258 const void *sense_data;
261 if (ioc->ctl_cmds.status == MPT3_CMD_NOT_USED)
263 if (ioc->ctl_cmds.smid != smid)
265 ioc->ctl_cmds.status |= MPT3_CMD_COMPLETE;
266 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
268 memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
269 ioc->ctl_cmds.status |= MPT3_CMD_REPLY_VALID;
271 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
272 mpi_reply->Function ==
273 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
274 scsiio_reply = (Mpi2SCSIIOReply_t *)mpi_reply;
275 if (scsiio_reply->SCSIState &
276 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
277 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
278 le32_to_cpu(scsiio_reply->SenseCount));
279 sense_data = mpt3sas_base_get_sense_buffer(ioc,
281 memcpy(ioc->ctl_cmds.sense, sense_data, sz);
285 * Get Error Response data for NVMe device. The ctl_cmds.sense
286 * buffer is used to store the Error Response data.
288 if (mpi_reply->Function == MPI2_FUNCTION_NVME_ENCAPSULATED) {
290 (Mpi26NVMeEncapsulatedErrorReply_t *)mpi_reply;
291 sz = min_t(u32, NVME_ERROR_RESPONSE_SIZE,
292 le16_to_cpu(nvme_error_reply->ErrorResponseCount));
293 sense_data = mpt3sas_base_get_sense_buffer(ioc, smid);
294 memcpy(ioc->ctl_cmds.sense, sense_data, sz);
298 _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply);
299 ioc->ctl_cmds.status &= ~MPT3_CMD_PENDING;
300 complete(&ioc->ctl_cmds.done);
305 * _ctl_check_event_type - determines when an event needs logging
306 * @ioc: per adapter object
307 * @event: firmware event
309 * The bitmask in ioc->event_type[] indicates which events should be
310 * be saved in the driver event_log. This bitmask is set by application.
312 * Return: 1 when event should be captured, or zero means no match.
315 _ctl_check_event_type(struct MPT3SAS_ADAPTER *ioc, u16 event)
320 if (event >= 128 || !event || !ioc->event_log)
323 desired_event = (1 << (event % 32));
327 return desired_event & ioc->event_type[i];
331 * mpt3sas_ctl_add_to_event_log - add event
332 * @ioc: per adapter object
333 * @mpi_reply: reply message frame
336 mpt3sas_ctl_add_to_event_log(struct MPT3SAS_ADAPTER *ioc,
337 Mpi2EventNotificationReply_t *mpi_reply)
339 struct MPT3_IOCTL_EVENTS *event_log;
342 u32 sz, event_data_sz;
348 event = le16_to_cpu(mpi_reply->Event);
350 if (_ctl_check_event_type(ioc, event)) {
352 /* insert entry into circular event_log */
353 i = ioc->event_context % MPT3SAS_CTL_EVENT_LOG_SIZE;
354 event_log = ioc->event_log;
355 event_log[i].event = event;
356 event_log[i].context = ioc->event_context++;
358 event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4;
359 sz = min_t(u32, event_data_sz, MPT3_EVENT_DATA_SIZE);
360 memset(event_log[i].data, 0, MPT3_EVENT_DATA_SIZE);
361 memcpy(event_log[i].data, mpi_reply->EventData, sz);
365 /* This aen_event_read_flag flag is set until the
366 * application has read the event log.
367 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
369 if (event == MPI2_EVENT_LOG_ENTRY_ADDED ||
370 (send_aen && !ioc->aen_event_read_flag)) {
371 ioc->aen_event_read_flag = 1;
372 wake_up_interruptible(&ctl_poll_wait);
374 kill_fasync(&async_queue, SIGIO, POLL_IN);
379 * mpt3sas_ctl_event_callback - firmware event handler (called at ISR time)
380 * @ioc: per adapter object
381 * @msix_index: MSIX table index supplied by the OS
382 * @reply: reply message frame(lower 32bit addr)
383 * Context: interrupt.
385 * This function merely adds a new work task into ioc->firmware_event_thread.
386 * The tasks are worked from _firmware_event_work in user context.
388 * Return: 1 meaning mf should be freed from _base_interrupt
389 * 0 means the mf is freed from this function.
392 mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
395 Mpi2EventNotificationReply_t *mpi_reply;
397 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
399 mpt3sas_ctl_add_to_event_log(ioc, mpi_reply);
404 * _ctl_verify_adapter - validates ioc_number passed from application
406 * @iocpp: The ioc pointer is returned in this.
407 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
408 * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
410 * Return: (-1) means error, else ioc_number.
413 _ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp,
416 struct MPT3SAS_ADAPTER *ioc;
418 /* global ioc lock to protect controller on list operations */
419 spin_lock(&gioc_lock);
420 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
421 if (ioc->id != ioc_number)
423 /* Check whether this ioctl command is from right
424 * ioctl device or not, if not continue the search.
426 version = ioc->hba_mpi_version_belonged;
427 /* MPI25_VERSION and MPI26_VERSION uses same ioctl
430 if (mpi_version == (MPI25_VERSION | MPI26_VERSION)) {
431 if ((version == MPI25_VERSION) ||
432 (version == MPI26_VERSION))
437 if (version != mpi_version)
441 spin_unlock(&gioc_lock);
445 spin_unlock(&gioc_lock);
451 * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
452 * @ioc: per adapter object
454 * The handler for doing any required cleanup or initialization.
456 void mpt3sas_ctl_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc)
461 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__));
462 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
463 if (!(ioc->diag_buffer_status[i] &
464 MPT3_DIAG_BUFFER_IS_REGISTERED))
466 if ((ioc->diag_buffer_status[i] &
467 MPT3_DIAG_BUFFER_IS_RELEASED))
469 mpt3sas_send_diag_release(ioc, i, &issue_reset);
474 * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
475 * @ioc: per adapter object
477 * The handler for doing any required cleanup or initialization.
479 void mpt3sas_ctl_after_reset_handler(struct MPT3SAS_ADAPTER *ioc)
481 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_AFTER_RESET\n", __func__));
482 if (ioc->ctl_cmds.status & MPT3_CMD_PENDING) {
483 ioc->ctl_cmds.status |= MPT3_CMD_RESET;
484 mpt3sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
485 complete(&ioc->ctl_cmds.done);
490 * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
491 * @ioc: per adapter object
493 * The handler for doing any required cleanup or initialization.
495 void mpt3sas_ctl_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
499 dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__));
501 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
502 if (!(ioc->diag_buffer_status[i] &
503 MPT3_DIAG_BUFFER_IS_REGISTERED))
505 if ((ioc->diag_buffer_status[i] &
506 MPT3_DIAG_BUFFER_IS_RELEASED))
508 ioc->diag_buffer_status[i] |=
509 MPT3_DIAG_BUFFER_IS_DIAG_RESET;
519 * Called when application request fasyn callback handler.
522 _ctl_fasync(int fd, struct file *filep, int mode)
524 return fasync_helper(fd, filep, mode, &async_queue);
534 _ctl_poll(struct file *filep, poll_table *wait)
536 struct MPT3SAS_ADAPTER *ioc;
538 poll_wait(filep, &ctl_poll_wait, wait);
540 /* global ioc lock to protect controller on list operations */
541 spin_lock(&gioc_lock);
542 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
543 if (ioc->aen_event_read_flag) {
544 spin_unlock(&gioc_lock);
545 return EPOLLIN | EPOLLRDNORM;
548 spin_unlock(&gioc_lock);
553 * _ctl_set_task_mid - assign an active smid to tm request
554 * @ioc: per adapter object
555 * @karg: (struct mpt3_ioctl_command)
556 * @tm_request: pointer to mf from user space
558 * Return: 0 when an smid if found, else fail.
559 * during failure, the reply frame is filled.
562 _ctl_set_task_mid(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command *karg,
563 Mpi2SCSITaskManagementRequest_t *tm_request)
568 struct scsi_cmnd *scmd;
569 struct MPT3SAS_DEVICE *priv_data;
570 Mpi2SCSITaskManagementReply_t *tm_reply;
575 if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
577 else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
582 lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
584 handle = le16_to_cpu(tm_request->DevHandle);
585 for (smid = ioc->scsiio_depth; smid && !found; smid--) {
586 struct scsiio_tracker *st;
588 scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid);
591 if (lun != scmd->device->lun)
593 priv_data = scmd->device->hostdata;
594 if (priv_data->sas_target == NULL)
596 if (priv_data->sas_target->handle != handle)
598 st = scsi_cmd_priv(scmd);
601 * If the given TaskMID from the user space is zero, then the
602 * first outstanding smid will be picked up. Otherwise,
603 * targeted smid will be the one.
605 if (!tm_request->TaskMID || tm_request->TaskMID == st->smid) {
606 tm_request->TaskMID = cpu_to_le16(st->smid);
613 ioc_info(ioc, "%s: handle(0x%04x), lun(%d), no active mid!!\n",
614 desc, le16_to_cpu(tm_request->DevHandle),
616 tm_reply = ioc->ctl_cmds.reply;
617 tm_reply->DevHandle = tm_request->DevHandle;
618 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
619 tm_reply->TaskType = tm_request->TaskType;
620 tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
621 tm_reply->VP_ID = tm_request->VP_ID;
622 tm_reply->VF_ID = tm_request->VF_ID;
623 sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz);
624 if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply,
626 pr_err("failure at %s:%d/%s()!\n", __FILE__,
632 ioc_info(ioc, "%s: handle(0x%04x), lun(%d), task_mid(%d)\n",
633 desc, le16_to_cpu(tm_request->DevHandle), lun,
634 le16_to_cpu(tm_request->TaskMID)));
639 * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode
640 * @ioc: per adapter object
641 * @karg: (struct mpt3_ioctl_command)
642 * @mf: pointer to mf in user space
645 _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
648 MPI2RequestHeader_t *mpi_request = NULL, *request;
649 MPI2DefaultReply_t *mpi_reply;
650 Mpi26NVMeEncapsulatedRequest_t *nvme_encap_request = NULL;
651 struct _pcie_device *pcie_device = NULL;
653 unsigned long timeout;
657 void *data_out = NULL;
658 dma_addr_t data_out_dma = 0;
659 size_t data_out_sz = 0;
660 void *data_in = NULL;
661 dma_addr_t data_in_dma = 0;
662 size_t data_in_sz = 0;
664 u16 device_handle = MPT3SAS_INVALID_DEVICE_HANDLE;
668 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
669 ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
674 ret = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT);
678 mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL);
680 ioc_err(ioc, "%s: failed obtaining a memory for mpi_request\n",
686 /* Check for overflow and wraparound */
687 if (karg.data_sge_offset * 4 > ioc->request_sz ||
688 karg.data_sge_offset > (UINT_MAX / 4)) {
693 /* copy in request message frame from user */
694 if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
695 pr_err("failure at %s:%d/%s()!\n", __FILE__, __LINE__,
701 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
702 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx);
704 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
709 /* Use first reserved smid for passthrough ioctls */
710 smid = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT + 1;
714 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
715 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
716 request = mpt3sas_base_get_msg_frame(ioc, smid);
717 memset(request, 0, ioc->request_sz);
718 memcpy(request, mpi_request, karg.data_sge_offset*4);
719 ioc->ctl_cmds.smid = smid;
720 data_out_sz = karg.data_out_size;
721 data_in_sz = karg.data_in_size;
723 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
724 mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
725 mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT ||
726 mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH ||
727 mpi_request->Function == MPI2_FUNCTION_NVME_ENCAPSULATED) {
729 device_handle = le16_to_cpu(mpi_request->FunctionDependent1);
730 if (!device_handle || (device_handle >
731 ioc->facts.MaxDevHandle)) {
733 mpt3sas_base_free_smid(ioc, smid);
738 /* obtain dma-able memory for data transfer */
739 if (data_out_sz) /* WRITE */ {
740 data_out = dma_alloc_coherent(&ioc->pdev->dev, data_out_sz,
741 &data_out_dma, GFP_KERNEL);
743 pr_err("failure at %s:%d/%s()!\n", __FILE__,
746 mpt3sas_base_free_smid(ioc, smid);
749 if (copy_from_user(data_out, karg.data_out_buf_ptr,
751 pr_err("failure at %s:%d/%s()!\n", __FILE__,
754 mpt3sas_base_free_smid(ioc, smid);
759 if (data_in_sz) /* READ */ {
760 data_in = dma_alloc_coherent(&ioc->pdev->dev, data_in_sz,
761 &data_in_dma, GFP_KERNEL);
763 pr_err("failure at %s:%d/%s()!\n", __FILE__,
766 mpt3sas_base_free_smid(ioc, smid);
771 psge = (void *)request + (karg.data_sge_offset*4);
773 /* send command to firmware */
774 _ctl_display_some_debug(ioc, smid, "ctl_request", NULL);
776 init_completion(&ioc->ctl_cmds.done);
777 switch (mpi_request->Function) {
778 case MPI2_FUNCTION_NVME_ENCAPSULATED:
780 nvme_encap_request = (Mpi26NVMeEncapsulatedRequest_t *)request;
781 if (!ioc->pcie_sg_lookup) {
782 dtmprintk(ioc, ioc_info(ioc,
783 "HBA doesn't support NVMe. Rejecting NVMe Encapsulated request.\n"
786 if (ioc->logging_level & MPT_DEBUG_TM)
787 _debug_dump_mf(nvme_encap_request,
789 mpt3sas_base_free_smid(ioc, smid);
794 * Get the Physical Address of the sense buffer.
795 * Use Error Response buffer address field to hold the sense
797 * Clear the internal sense buffer, which will potentially hold
798 * the Completion Queue Entry on return, or 0 if no Entry.
799 * Build the PRPs and set direction bits.
802 nvme_encap_request->ErrorResponseBaseAddress =
803 cpu_to_le64(ioc->sense_dma & 0xFFFFFFFF00000000UL);
804 nvme_encap_request->ErrorResponseBaseAddress |=
805 cpu_to_le64(le32_to_cpu(
806 mpt3sas_base_get_sense_buffer_dma(ioc, smid)));
807 nvme_encap_request->ErrorResponseAllocationLength =
808 cpu_to_le16(NVME_ERROR_RESPONSE_SIZE);
809 memset(ioc->ctl_cmds.sense, 0, NVME_ERROR_RESPONSE_SIZE);
810 ioc->build_nvme_prp(ioc, smid, nvme_encap_request,
811 data_out_dma, data_out_sz, data_in_dma, data_in_sz);
812 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
814 ioc_info(ioc, "handle(0x%04x): ioctl failed due to device removal in progress\n",
816 mpt3sas_base_free_smid(ioc, smid);
820 mpt3sas_base_put_smid_nvme_encap(ioc, smid);
823 case MPI2_FUNCTION_SCSI_IO_REQUEST:
824 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
826 Mpi2SCSIIORequest_t *scsiio_request =
827 (Mpi2SCSIIORequest_t *)request;
828 scsiio_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
829 scsiio_request->SenseBufferLowAddress =
830 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
831 memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE);
832 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
834 ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
836 mpt3sas_base_free_smid(ioc, smid);
840 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
841 data_in_dma, data_in_sz);
842 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)
843 ioc->put_smid_scsi_io(ioc, smid, device_handle);
845 ioc->put_smid_default(ioc, smid);
848 case MPI2_FUNCTION_SCSI_TASK_MGMT:
850 Mpi2SCSITaskManagementRequest_t *tm_request =
851 (Mpi2SCSITaskManagementRequest_t *)request;
854 ioc_info(ioc, "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
855 le16_to_cpu(tm_request->DevHandle),
856 tm_request->TaskType));
857 ioc->got_task_abort_from_ioctl = 1;
858 if (tm_request->TaskType ==
859 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
860 tm_request->TaskType ==
861 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
862 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
863 mpt3sas_base_free_smid(ioc, smid);
864 ioc->got_task_abort_from_ioctl = 0;
868 ioc->got_task_abort_from_ioctl = 0;
870 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
872 ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
874 mpt3sas_base_free_smid(ioc, smid);
878 mpt3sas_scsih_set_tm_flag(ioc, le16_to_cpu(
879 tm_request->DevHandle));
880 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
881 data_in_dma, data_in_sz);
882 ioc->put_smid_hi_priority(ioc, smid, 0);
885 case MPI2_FUNCTION_SMP_PASSTHROUGH:
887 Mpi2SmpPassthroughRequest_t *smp_request =
888 (Mpi2SmpPassthroughRequest_t *)mpi_request;
891 /* ioc determines which port to use */
892 smp_request->PhysicalPort = 0xFF;
893 if (smp_request->PassthroughFlags &
894 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
895 data = (u8 *)&smp_request->SGL;
897 if (unlikely(data_out == NULL)) {
898 pr_err("failure at %s:%d/%s()!\n",
899 __FILE__, __LINE__, __func__);
900 mpt3sas_base_free_smid(ioc, smid);
907 if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
908 ioc->ioc_link_reset_in_progress = 1;
909 ioc->ignore_loginfos = 1;
911 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
913 ioc->put_smid_default(ioc, smid);
916 case MPI2_FUNCTION_SATA_PASSTHROUGH:
918 if (test_bit(device_handle, ioc->device_remove_in_progress)) {
920 ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
922 mpt3sas_base_free_smid(ioc, smid);
926 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
928 ioc->put_smid_default(ioc, smid);
931 case MPI2_FUNCTION_FW_DOWNLOAD:
932 case MPI2_FUNCTION_FW_UPLOAD:
934 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
936 ioc->put_smid_default(ioc, smid);
939 case MPI2_FUNCTION_TOOLBOX:
941 Mpi2ToolboxCleanRequest_t *toolbox_request =
942 (Mpi2ToolboxCleanRequest_t *)mpi_request;
944 if ((toolbox_request->Tool == MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL)
945 || (toolbox_request->Tool ==
946 MPI26_TOOLBOX_BACKEND_PCIE_LANE_MARGIN))
947 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
948 data_in_dma, data_in_sz);
949 else if (toolbox_request->Tool ==
950 MPI2_TOOLBOX_MEMORY_MOVE_TOOL) {
951 Mpi2ToolboxMemMoveRequest_t *mem_move_request =
952 (Mpi2ToolboxMemMoveRequest_t *)request;
953 Mpi2SGESimple64_t tmp, *src = NULL, *dst = NULL;
955 ioc->build_sg_mpi(ioc, psge, data_out_dma,
956 data_out_sz, data_in_dma, data_in_sz);
957 if (data_out_sz && !data_in_sz) {
959 (Mpi2SGESimple64_t *)&mem_move_request->SGL;
960 src = (void *)dst + ioc->sge_size;
962 memcpy(&tmp, src, ioc->sge_size);
963 memcpy(src, dst, ioc->sge_size);
964 memcpy(dst, &tmp, ioc->sge_size);
966 if (ioc->logging_level & MPT_DEBUG_TM) {
968 "Mpi2ToolboxMemMoveRequest_t request msg\n");
969 _debug_dump_mf(mem_move_request,
973 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
974 data_in_dma, data_in_sz);
975 ioc->put_smid_default(ioc, smid);
978 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
980 Mpi2SasIoUnitControlRequest_t *sasiounit_request =
981 (Mpi2SasIoUnitControlRequest_t *)mpi_request;
983 if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET
984 || sasiounit_request->Operation ==
985 MPI2_SAS_OP_PHY_LINK_RESET) {
986 ioc->ioc_link_reset_in_progress = 1;
987 ioc->ignore_loginfos = 1;
989 /* drop to default case for posting the request */
993 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
994 data_in_dma, data_in_sz);
995 ioc->put_smid_default(ioc, smid);
999 if (karg.timeout < MPT3_IOCTL_DEFAULT_TIMEOUT)
1000 timeout = MPT3_IOCTL_DEFAULT_TIMEOUT;
1002 timeout = karg.timeout;
1003 wait_for_completion_timeout(&ioc->ctl_cmds.done, timeout*HZ);
1004 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
1005 Mpi2SCSITaskManagementRequest_t *tm_request =
1006 (Mpi2SCSITaskManagementRequest_t *)mpi_request;
1007 mpt3sas_scsih_clear_tm_flag(ioc, le16_to_cpu(
1008 tm_request->DevHandle));
1009 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
1010 } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH ||
1011 mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) &&
1012 ioc->ioc_link_reset_in_progress) {
1013 ioc->ioc_link_reset_in_progress = 0;
1014 ioc->ignore_loginfos = 0;
1016 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1018 mpt3sas_base_check_cmd_timeout(ioc,
1019 ioc->ctl_cmds.status, mpi_request,
1020 karg.data_sge_offset);
1021 goto issue_host_reset;
1024 mpi_reply = ioc->ctl_cmds.reply;
1026 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT &&
1027 (ioc->logging_level & MPT_DEBUG_TM)) {
1028 Mpi2SCSITaskManagementReply_t *tm_reply =
1029 (Mpi2SCSITaskManagementReply_t *)mpi_reply;
1031 ioc_info(ioc, "TASK_MGMT: IOCStatus(0x%04x), IOCLogInfo(0x%08x), TerminationCount(0x%08x)\n",
1032 le16_to_cpu(tm_reply->IOCStatus),
1033 le32_to_cpu(tm_reply->IOCLogInfo),
1034 le32_to_cpu(tm_reply->TerminationCount));
1037 /* copy out xdata to user */
1039 if (copy_to_user(karg.data_in_buf_ptr, data_in,
1041 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1042 __LINE__, __func__);
1048 /* copy out reply message frame to user */
1049 if (karg.max_reply_bytes) {
1050 sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz);
1051 if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply,
1053 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1054 __LINE__, __func__);
1060 /* copy out sense/NVMe Error Response to user */
1061 if (karg.max_sense_bytes && (mpi_request->Function ==
1062 MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function ==
1063 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || mpi_request->Function ==
1064 MPI2_FUNCTION_NVME_ENCAPSULATED)) {
1065 if (karg.sense_data_ptr == NULL) {
1066 ioc_info(ioc, "Response buffer provided by application is NULL; Response data will not be returned\n");
1069 sz_arg = (mpi_request->Function ==
1070 MPI2_FUNCTION_NVME_ENCAPSULATED) ? NVME_ERROR_RESPONSE_SIZE :
1071 SCSI_SENSE_BUFFERSIZE;
1072 sz = min_t(u32, karg.max_sense_bytes, sz_arg);
1073 if (copy_to_user(karg.sense_data_ptr, ioc->ctl_cmds.sense,
1075 pr_err("failure at %s:%d/%s()!\n", __FILE__,
1076 __LINE__, __func__);
1085 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
1086 mpi_request->Function ==
1087 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
1088 mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH)) {
1089 ioc_info(ioc, "issue target reset: handle = (0x%04x)\n",
1090 le16_to_cpu(mpi_request->FunctionDependent1));
1091 mpt3sas_halt_firmware(ioc);
1092 pcie_device = mpt3sas_get_pdev_by_handle(ioc,
1093 le16_to_cpu(mpi_request->FunctionDependent1));
1094 if (pcie_device && (!ioc->tm_custom_handling) &&
1095 (!(mpt3sas_scsih_is_pcie_scsi_device(
1096 pcie_device->device_info))))
1097 mpt3sas_scsih_issue_locked_tm(ioc,
1098 le16_to_cpu(mpi_request->FunctionDependent1),
1099 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
1100 0, pcie_device->reset_timeout,
1101 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE);
1103 mpt3sas_scsih_issue_locked_tm(ioc,
1104 le16_to_cpu(mpi_request->FunctionDependent1),
1105 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
1106 0, 30, MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET);
1108 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1113 pcie_device_put(pcie_device);
1115 /* free memory associated with sg buffers */
1117 dma_free_coherent(&ioc->pdev->dev, data_in_sz, data_in,
1121 dma_free_coherent(&ioc->pdev->dev, data_out_sz, data_out,
1125 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1130 * _ctl_getiocinfo - main handler for MPT3IOCINFO opcode
1131 * @ioc: per adapter object
1132 * @arg: user space buffer containing ioctl content
1135 _ctl_getiocinfo(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1137 struct mpt3_ioctl_iocinfo karg;
1139 dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1142 memset(&karg, 0 , sizeof(karg));
1144 karg.port_number = ioc->pfacts[0].PortNumber;
1145 karg.hw_rev = ioc->pdev->revision;
1146 karg.pci_id = ioc->pdev->device;
1147 karg.subsystem_device = ioc->pdev->subsystem_device;
1148 karg.subsystem_vendor = ioc->pdev->subsystem_vendor;
1149 karg.pci_information.u.bits.bus = ioc->pdev->bus->number;
1150 karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn);
1151 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
1152 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
1153 karg.firmware_version = ioc->facts.FWVersion.Word;
1154 strcpy(karg.driver_version, ioc->driver_name);
1155 strcat(karg.driver_version, "-");
1156 switch (ioc->hba_mpi_version_belonged) {
1158 if (ioc->is_warpdrive)
1159 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2_SSS6200;
1161 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2;
1162 strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION);
1166 if (ioc->is_gen35_ioc)
1167 karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS35;
1169 karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS3;
1170 strcat(karg.driver_version, MPT3SAS_DRIVER_VERSION);
1173 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
1175 if (copy_to_user(arg, &karg, sizeof(karg))) {
1176 pr_err("failure at %s:%d/%s()!\n",
1177 __FILE__, __LINE__, __func__);
1184 * _ctl_eventquery - main handler for MPT3EVENTQUERY opcode
1185 * @ioc: per adapter object
1186 * @arg: user space buffer containing ioctl content
1189 _ctl_eventquery(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1191 struct mpt3_ioctl_eventquery karg;
1193 if (copy_from_user(&karg, arg, sizeof(karg))) {
1194 pr_err("failure at %s:%d/%s()!\n",
1195 __FILE__, __LINE__, __func__);
1199 dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1202 karg.event_entries = MPT3SAS_CTL_EVENT_LOG_SIZE;
1203 memcpy(karg.event_types, ioc->event_type,
1204 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1206 if (copy_to_user(arg, &karg, sizeof(karg))) {
1207 pr_err("failure at %s:%d/%s()!\n",
1208 __FILE__, __LINE__, __func__);
1215 * _ctl_eventenable - main handler for MPT3EVENTENABLE opcode
1216 * @ioc: per adapter object
1217 * @arg: user space buffer containing ioctl content
1220 _ctl_eventenable(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1222 struct mpt3_ioctl_eventenable karg;
1224 if (copy_from_user(&karg, arg, sizeof(karg))) {
1225 pr_err("failure at %s:%d/%s()!\n",
1226 __FILE__, __LINE__, __func__);
1230 dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1233 memcpy(ioc->event_type, karg.event_types,
1234 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1235 mpt3sas_base_validate_event_type(ioc, ioc->event_type);
1239 /* initialize event_log */
1240 ioc->event_context = 0;
1241 ioc->aen_event_read_flag = 0;
1242 ioc->event_log = kcalloc(MPT3SAS_CTL_EVENT_LOG_SIZE,
1243 sizeof(struct MPT3_IOCTL_EVENTS), GFP_KERNEL);
1244 if (!ioc->event_log) {
1245 pr_err("failure at %s:%d/%s()!\n",
1246 __FILE__, __LINE__, __func__);
1253 * _ctl_eventreport - main handler for MPT3EVENTREPORT opcode
1254 * @ioc: per adapter object
1255 * @arg: user space buffer containing ioctl content
1258 _ctl_eventreport(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1260 struct mpt3_ioctl_eventreport karg;
1261 u32 number_bytes, max_events, max;
1262 struct mpt3_ioctl_eventreport __user *uarg = arg;
1264 if (copy_from_user(&karg, arg, sizeof(karg))) {
1265 pr_err("failure at %s:%d/%s()!\n",
1266 __FILE__, __LINE__, __func__);
1270 dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1273 number_bytes = karg.hdr.max_data_size -
1274 sizeof(struct mpt3_ioctl_header);
1275 max_events = number_bytes/sizeof(struct MPT3_IOCTL_EVENTS);
1276 max = min_t(u32, MPT3SAS_CTL_EVENT_LOG_SIZE, max_events);
1278 /* If fewer than 1 event is requested, there must have
1279 * been some type of error.
1281 if (!max || !ioc->event_log)
1284 number_bytes = max * sizeof(struct MPT3_IOCTL_EVENTS);
1285 if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) {
1286 pr_err("failure at %s:%d/%s()!\n",
1287 __FILE__, __LINE__, __func__);
1291 /* reset flag so SIGIO can restart */
1292 ioc->aen_event_read_flag = 0;
1297 * _ctl_do_reset - main handler for MPT3HARDRESET opcode
1298 * @ioc: per adapter object
1299 * @arg: user space buffer containing ioctl content
1302 _ctl_do_reset(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1304 struct mpt3_ioctl_diag_reset karg;
1307 if (copy_from_user(&karg, arg, sizeof(karg))) {
1308 pr_err("failure at %s:%d/%s()!\n",
1309 __FILE__, __LINE__, __func__);
1313 if (ioc->shost_recovery || ioc->pci_error_recovery ||
1314 ioc->is_driver_loading)
1317 dctlprintk(ioc, ioc_info(ioc, "%s: enter\n",
1320 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1321 ioc_info(ioc, "host reset: %s\n", ((!retval) ? "SUCCESS" : "FAILED"));
1326 * _ctl_btdh_search_sas_device - searching for sas device
1327 * @ioc: per adapter object
1328 * @btdh: btdh ioctl payload
1331 _ctl_btdh_search_sas_device(struct MPT3SAS_ADAPTER *ioc,
1332 struct mpt3_ioctl_btdh_mapping *btdh)
1334 struct _sas_device *sas_device;
1335 unsigned long flags;
1338 if (list_empty(&ioc->sas_device_list))
1341 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1342 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
1343 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1344 btdh->handle == sas_device->handle) {
1345 btdh->bus = sas_device->channel;
1346 btdh->id = sas_device->id;
1349 } else if (btdh->bus == sas_device->channel && btdh->id ==
1350 sas_device->id && btdh->handle == 0xFFFF) {
1351 btdh->handle = sas_device->handle;
1357 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1362 * _ctl_btdh_search_pcie_device - searching for pcie device
1363 * @ioc: per adapter object
1364 * @btdh: btdh ioctl payload
1367 _ctl_btdh_search_pcie_device(struct MPT3SAS_ADAPTER *ioc,
1368 struct mpt3_ioctl_btdh_mapping *btdh)
1370 struct _pcie_device *pcie_device;
1371 unsigned long flags;
1374 if (list_empty(&ioc->pcie_device_list))
1377 spin_lock_irqsave(&ioc->pcie_device_lock, flags);
1378 list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) {
1379 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1380 btdh->handle == pcie_device->handle) {
1381 btdh->bus = pcie_device->channel;
1382 btdh->id = pcie_device->id;
1385 } else if (btdh->bus == pcie_device->channel && btdh->id ==
1386 pcie_device->id && btdh->handle == 0xFFFF) {
1387 btdh->handle = pcie_device->handle;
1393 spin_unlock_irqrestore(&ioc->pcie_device_lock, flags);
1398 * _ctl_btdh_search_raid_device - searching for raid device
1399 * @ioc: per adapter object
1400 * @btdh: btdh ioctl payload
1403 _ctl_btdh_search_raid_device(struct MPT3SAS_ADAPTER *ioc,
1404 struct mpt3_ioctl_btdh_mapping *btdh)
1406 struct _raid_device *raid_device;
1407 unsigned long flags;
1410 if (list_empty(&ioc->raid_device_list))
1413 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1414 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1415 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1416 btdh->handle == raid_device->handle) {
1417 btdh->bus = raid_device->channel;
1418 btdh->id = raid_device->id;
1421 } else if (btdh->bus == raid_device->channel && btdh->id ==
1422 raid_device->id && btdh->handle == 0xFFFF) {
1423 btdh->handle = raid_device->handle;
1429 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1434 * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode
1435 * @ioc: per adapter object
1436 * @arg: user space buffer containing ioctl content
1439 _ctl_btdh_mapping(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1441 struct mpt3_ioctl_btdh_mapping karg;
1444 if (copy_from_user(&karg, arg, sizeof(karg))) {
1445 pr_err("failure at %s:%d/%s()!\n",
1446 __FILE__, __LINE__, __func__);
1450 dctlprintk(ioc, ioc_info(ioc, "%s\n",
1453 rc = _ctl_btdh_search_sas_device(ioc, &karg);
1455 rc = _ctl_btdh_search_pcie_device(ioc, &karg);
1457 _ctl_btdh_search_raid_device(ioc, &karg);
1459 if (copy_to_user(arg, &karg, sizeof(karg))) {
1460 pr_err("failure at %s:%d/%s()!\n",
1461 __FILE__, __LINE__, __func__);
1468 * _ctl_diag_capability - return diag buffer capability
1469 * @ioc: per adapter object
1470 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1472 * returns 1 when diag buffer support is enabled in firmware
1475 _ctl_diag_capability(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type)
1479 switch (buffer_type) {
1480 case MPI2_DIAG_BUF_TYPE_TRACE:
1481 if (ioc->facts.IOCCapabilities &
1482 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER)
1485 case MPI2_DIAG_BUF_TYPE_SNAPSHOT:
1486 if (ioc->facts.IOCCapabilities &
1487 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER)
1490 case MPI2_DIAG_BUF_TYPE_EXTENDED:
1491 if (ioc->facts.IOCCapabilities &
1492 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER)
1501 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1502 * @ioc: per adapter object
1503 * @diag_register: the diag_register struct passed in from user space
1507 _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
1508 struct mpt3_diag_register *diag_register)
1511 void *request_data = NULL;
1512 dma_addr_t request_data_dma;
1513 u32 request_data_sz = 0;
1514 Mpi2DiagBufferPostRequest_t *mpi_request;
1515 Mpi2DiagBufferPostReply_t *mpi_reply;
1522 dctlprintk(ioc, ioc_info(ioc, "%s\n",
1525 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1526 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1527 ioc_err(ioc, "%s: failed due to ioc not operational\n",
1533 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1534 ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
1539 buffer_type = diag_register->buffer_type;
1540 if (!_ctl_diag_capability(ioc, buffer_type)) {
1541 ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
1542 __func__, buffer_type);
1546 if (ioc->diag_buffer_status[buffer_type] &
1547 MPT3_DIAG_BUFFER_IS_REGISTERED) {
1548 ioc_err(ioc, "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1549 __func__, buffer_type);
1553 if (diag_register->requested_buffer_size % 4) {
1554 ioc_err(ioc, "%s: the requested_buffer_size is not 4 byte aligned\n",
1559 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1561 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
1567 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
1568 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1569 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1570 ioc->ctl_cmds.smid = smid;
1572 request_data = ioc->diag_buffer[buffer_type];
1573 request_data_sz = diag_register->requested_buffer_size;
1574 ioc->unique_id[buffer_type] = diag_register->unique_id;
1575 ioc->diag_buffer_status[buffer_type] = 0;
1576 memcpy(ioc->product_specific[buffer_type],
1577 diag_register->product_specific, MPT3_PRODUCT_SPECIFIC_DWORDS);
1578 ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags;
1581 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1582 if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) {
1583 dma_free_coherent(&ioc->pdev->dev,
1584 ioc->diag_buffer_sz[buffer_type],
1585 request_data, request_data_dma);
1586 request_data = NULL;
1590 if (request_data == NULL) {
1591 ioc->diag_buffer_sz[buffer_type] = 0;
1592 ioc->diag_buffer_dma[buffer_type] = 0;
1593 request_data = dma_alloc_coherent(&ioc->pdev->dev,
1594 request_data_sz, &request_data_dma, GFP_KERNEL);
1595 if (request_data == NULL) {
1596 ioc_err(ioc, "%s: failed allocating memory for diag buffers, requested size(%d)\n",
1597 __func__, request_data_sz);
1598 mpt3sas_base_free_smid(ioc, smid);
1602 ioc->diag_buffer[buffer_type] = request_data;
1603 ioc->diag_buffer_sz[buffer_type] = request_data_sz;
1604 ioc->diag_buffer_dma[buffer_type] = request_data_dma;
1607 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1608 mpi_request->BufferType = diag_register->buffer_type;
1609 mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags);
1610 mpi_request->BufferAddress = cpu_to_le64(request_data_dma);
1611 mpi_request->BufferLength = cpu_to_le32(request_data_sz);
1612 mpi_request->VF_ID = 0; /* TODO */
1613 mpi_request->VP_ID = 0;
1616 ioc_info(ioc, "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1617 __func__, request_data,
1618 (unsigned long long)request_data_dma,
1619 le32_to_cpu(mpi_request->BufferLength)));
1621 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
1622 mpi_request->ProductSpecific[i] =
1623 cpu_to_le32(ioc->product_specific[buffer_type][i]);
1625 init_completion(&ioc->ctl_cmds.done);
1626 ioc->put_smid_default(ioc, smid);
1627 wait_for_completion_timeout(&ioc->ctl_cmds.done,
1628 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
1630 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1632 mpt3sas_base_check_cmd_timeout(ioc,
1633 ioc->ctl_cmds.status, mpi_request,
1634 sizeof(Mpi2DiagBufferPostRequest_t)/4);
1635 goto issue_host_reset;
1638 /* process the completed Reply Message Frame */
1639 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1640 ioc_err(ioc, "%s: no reply message\n", __func__);
1645 mpi_reply = ioc->ctl_cmds.reply;
1646 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1648 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1649 ioc->diag_buffer_status[buffer_type] |=
1650 MPT3_DIAG_BUFFER_IS_REGISTERED;
1651 dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__));
1653 ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1655 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
1661 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1665 if (rc && request_data)
1666 dma_free_coherent(&ioc->pdev->dev, request_data_sz,
1667 request_data, request_data_dma);
1669 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1674 * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time
1675 * @ioc: per adapter object
1676 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1678 * This is called when command line option diag_buffer_enable is enabled
1679 * at driver load time.
1682 mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER *ioc, u8 bits_to_register)
1684 struct mpt3_diag_register diag_register;
1686 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
1688 if (bits_to_register & 1) {
1689 ioc_info(ioc, "registering trace buffer support\n");
1690 ioc->diag_trigger_master.MasterData =
1691 (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET);
1692 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
1693 /* register for 2MB buffers */
1694 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1695 diag_register.unique_id = 0x7075900;
1696 _ctl_diag_register_2(ioc, &diag_register);
1699 if (bits_to_register & 2) {
1700 ioc_info(ioc, "registering snapshot buffer support\n");
1701 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT;
1702 /* register for 2MB buffers */
1703 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1704 diag_register.unique_id = 0x7075901;
1705 _ctl_diag_register_2(ioc, &diag_register);
1708 if (bits_to_register & 4) {
1709 ioc_info(ioc, "registering extended buffer support\n");
1710 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED;
1711 /* register for 2MB buffers */
1712 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1713 diag_register.unique_id = 0x7075901;
1714 _ctl_diag_register_2(ioc, &diag_register);
1719 * _ctl_diag_register - application register with driver
1720 * @ioc: per adapter object
1721 * @arg: user space buffer containing ioctl content
1723 * This will allow the driver to setup any required buffers that will be
1724 * needed by firmware to communicate with the driver.
1727 _ctl_diag_register(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1729 struct mpt3_diag_register karg;
1732 if (copy_from_user(&karg, arg, sizeof(karg))) {
1733 pr_err("failure at %s:%d/%s()!\n",
1734 __FILE__, __LINE__, __func__);
1738 rc = _ctl_diag_register_2(ioc, &karg);
1743 * _ctl_diag_unregister - application unregister with driver
1744 * @ioc: per adapter object
1745 * @arg: user space buffer containing ioctl content
1747 * This will allow the driver to cleanup any memory allocated for diag
1748 * messages and to free up any resources.
1751 _ctl_diag_unregister(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1753 struct mpt3_diag_unregister karg;
1755 dma_addr_t request_data_dma;
1756 u32 request_data_sz;
1759 if (copy_from_user(&karg, arg, sizeof(karg))) {
1760 pr_err("failure at %s:%d/%s()!\n",
1761 __FILE__, __LINE__, __func__);
1765 dctlprintk(ioc, ioc_info(ioc, "%s\n",
1768 buffer_type = karg.unique_id & 0x000000ff;
1769 if (!_ctl_diag_capability(ioc, buffer_type)) {
1770 ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
1771 __func__, buffer_type);
1775 if ((ioc->diag_buffer_status[buffer_type] &
1776 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1777 ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
1778 __func__, buffer_type);
1781 if ((ioc->diag_buffer_status[buffer_type] &
1782 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
1783 ioc_err(ioc, "%s: buffer_type(0x%02x) has not been released\n",
1784 __func__, buffer_type);
1788 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1789 ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
1790 __func__, karg.unique_id);
1794 request_data = ioc->diag_buffer[buffer_type];
1795 if (!request_data) {
1796 ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1797 __func__, buffer_type);
1801 request_data_sz = ioc->diag_buffer_sz[buffer_type];
1802 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1803 dma_free_coherent(&ioc->pdev->dev, request_data_sz,
1804 request_data, request_data_dma);
1805 ioc->diag_buffer[buffer_type] = NULL;
1806 ioc->diag_buffer_status[buffer_type] = 0;
1811 * _ctl_diag_query - query relevant info associated with diag buffers
1812 * @ioc: per adapter object
1813 * @arg: user space buffer containing ioctl content
1815 * The application will send only buffer_type and unique_id. Driver will
1816 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1817 * 0x00, the driver will return info specified by Buffer Type.
1820 _ctl_diag_query(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1822 struct mpt3_diag_query karg;
1827 if (copy_from_user(&karg, arg, sizeof(karg))) {
1828 pr_err("failure at %s:%d/%s()!\n",
1829 __FILE__, __LINE__, __func__);
1833 dctlprintk(ioc, ioc_info(ioc, "%s\n",
1836 karg.application_flags = 0;
1837 buffer_type = karg.buffer_type;
1839 if (!_ctl_diag_capability(ioc, buffer_type)) {
1840 ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
1841 __func__, buffer_type);
1845 if ((ioc->diag_buffer_status[buffer_type] &
1846 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1847 ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
1848 __func__, buffer_type);
1852 if (karg.unique_id & 0xffffff00) {
1853 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1854 ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
1855 __func__, karg.unique_id);
1860 request_data = ioc->diag_buffer[buffer_type];
1861 if (!request_data) {
1862 ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
1863 __func__, buffer_type);
1867 if (ioc->diag_buffer_status[buffer_type] & MPT3_DIAG_BUFFER_IS_RELEASED)
1868 karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1869 MPT3_APP_FLAGS_BUFFER_VALID);
1871 karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1872 MPT3_APP_FLAGS_BUFFER_VALID |
1873 MPT3_APP_FLAGS_FW_BUFFER_ACCESS);
1875 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
1876 karg.product_specific[i] =
1877 ioc->product_specific[buffer_type][i];
1879 karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type];
1880 karg.driver_added_buffer_size = 0;
1881 karg.unique_id = ioc->unique_id[buffer_type];
1882 karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type];
1884 if (copy_to_user(arg, &karg, sizeof(struct mpt3_diag_query))) {
1885 ioc_err(ioc, "%s: unable to write mpt3_diag_query data @ %p\n",
1893 * mpt3sas_send_diag_release - Diag Release Message
1894 * @ioc: per adapter object
1895 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1896 * @issue_reset: specifies whether host reset is required.
1900 mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type,
1903 Mpi2DiagReleaseRequest_t *mpi_request;
1904 Mpi2DiagReleaseReply_t *mpi_reply;
1910 dctlprintk(ioc, ioc_info(ioc, "%s\n",
1916 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1917 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1918 if (ioc->diag_buffer_status[buffer_type] &
1919 MPT3_DIAG_BUFFER_IS_REGISTERED)
1920 ioc->diag_buffer_status[buffer_type] |=
1921 MPT3_DIAG_BUFFER_IS_RELEASED;
1923 ioc_info(ioc, "%s: skipping due to FAULT state\n",
1929 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1930 ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
1935 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1937 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
1942 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
1943 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1944 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1945 ioc->ctl_cmds.smid = smid;
1947 mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE;
1948 mpi_request->BufferType = buffer_type;
1949 mpi_request->VF_ID = 0; /* TODO */
1950 mpi_request->VP_ID = 0;
1952 init_completion(&ioc->ctl_cmds.done);
1953 ioc->put_smid_default(ioc, smid);
1954 wait_for_completion_timeout(&ioc->ctl_cmds.done,
1955 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
1957 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1958 *issue_reset = mpt3sas_base_check_cmd_timeout(ioc,
1959 ioc->ctl_cmds.status, mpi_request,
1960 sizeof(Mpi2DiagReleaseRequest_t)/4);
1965 /* process the completed Reply Message Frame */
1966 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1967 ioc_err(ioc, "%s: no reply message\n", __func__);
1972 mpi_reply = ioc->ctl_cmds.reply;
1973 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1975 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1976 ioc->diag_buffer_status[buffer_type] |=
1977 MPT3_DIAG_BUFFER_IS_RELEASED;
1978 dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__));
1980 ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1982 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
1987 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1992 * _ctl_diag_release - request to send Diag Release Message to firmware
1994 * @arg: user space buffer containing ioctl content
1996 * This allows ownership of the specified buffer to returned to the driver,
1997 * allowing an application to read the buffer without fear that firmware is
1998 * overwriting information in the buffer.
2001 _ctl_diag_release(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
2003 struct mpt3_diag_release karg;
2009 if (copy_from_user(&karg, arg, sizeof(karg))) {
2010 pr_err("failure at %s:%d/%s()!\n",
2011 __FILE__, __LINE__, __func__);
2015 dctlprintk(ioc, ioc_info(ioc, "%s\n",
2018 buffer_type = karg.unique_id & 0x000000ff;
2019 if (!_ctl_diag_capability(ioc, buffer_type)) {
2020 ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2021 __func__, buffer_type);
2025 if ((ioc->diag_buffer_status[buffer_type] &
2026 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
2027 ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
2028 __func__, buffer_type);
2032 if (karg.unique_id != ioc->unique_id[buffer_type]) {
2033 ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
2034 __func__, karg.unique_id);
2038 if (ioc->diag_buffer_status[buffer_type] &
2039 MPT3_DIAG_BUFFER_IS_RELEASED) {
2040 ioc_err(ioc, "%s: buffer_type(0x%02x) is already released\n",
2041 __func__, buffer_type);
2045 request_data = ioc->diag_buffer[buffer_type];
2047 if (!request_data) {
2048 ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
2049 __func__, buffer_type);
2053 /* buffers were released by due to host reset */
2054 if ((ioc->diag_buffer_status[buffer_type] &
2055 MPT3_DIAG_BUFFER_IS_DIAG_RESET)) {
2056 ioc->diag_buffer_status[buffer_type] |=
2057 MPT3_DIAG_BUFFER_IS_RELEASED;
2058 ioc->diag_buffer_status[buffer_type] &=
2059 ~MPT3_DIAG_BUFFER_IS_DIAG_RESET;
2060 ioc_err(ioc, "%s: buffer_type(0x%02x) was released due to host reset\n",
2061 __func__, buffer_type);
2065 rc = mpt3sas_send_diag_release(ioc, buffer_type, &issue_reset);
2068 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2074 * _ctl_diag_read_buffer - request for copy of the diag buffer
2075 * @ioc: per adapter object
2076 * @arg: user space buffer containing ioctl content
2079 _ctl_diag_read_buffer(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
2081 struct mpt3_diag_read_buffer karg;
2082 struct mpt3_diag_read_buffer __user *uarg = arg;
2083 void *request_data, *diag_data;
2084 Mpi2DiagBufferPostRequest_t *mpi_request;
2085 Mpi2DiagBufferPostReply_t *mpi_reply;
2088 unsigned long request_size, copy_size;
2093 if (copy_from_user(&karg, arg, sizeof(karg))) {
2094 pr_err("failure at %s:%d/%s()!\n",
2095 __FILE__, __LINE__, __func__);
2099 dctlprintk(ioc, ioc_info(ioc, "%s\n",
2102 buffer_type = karg.unique_id & 0x000000ff;
2103 if (!_ctl_diag_capability(ioc, buffer_type)) {
2104 ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2105 __func__, buffer_type);
2109 if (karg.unique_id != ioc->unique_id[buffer_type]) {
2110 ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
2111 __func__, karg.unique_id);
2115 request_data = ioc->diag_buffer[buffer_type];
2116 if (!request_data) {
2117 ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2118 __func__, buffer_type);
2122 request_size = ioc->diag_buffer_sz[buffer_type];
2124 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
2125 ioc_err(ioc, "%s: either the starting_offset or bytes_to_read are not 4 byte aligned\n",
2130 if (karg.starting_offset > request_size)
2133 diag_data = (void *)(request_data + karg.starting_offset);
2135 ioc_info(ioc, "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2136 __func__, diag_data, karg.starting_offset,
2137 karg.bytes_to_read));
2139 /* Truncate data on requests that are too large */
2140 if ((diag_data + karg.bytes_to_read < diag_data) ||
2141 (diag_data + karg.bytes_to_read > request_data + request_size))
2142 copy_size = request_size - karg.starting_offset;
2144 copy_size = karg.bytes_to_read;
2146 if (copy_to_user((void __user *)uarg->diagnostic_data,
2147 diag_data, copy_size)) {
2148 ioc_err(ioc, "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2149 __func__, diag_data);
2153 if ((karg.flags & MPT3_FLAGS_REREGISTER) == 0)
2157 ioc_info(ioc, "%s: Reregister buffer_type(0x%02x)\n",
2158 __func__, buffer_type));
2159 if ((ioc->diag_buffer_status[buffer_type] &
2160 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
2162 ioc_info(ioc, "%s: buffer_type(0x%02x) is still registered\n",
2163 __func__, buffer_type));
2166 /* Get a free request frame and save the message context.
2169 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
2170 ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
2175 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
2177 ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
2183 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
2184 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
2185 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2186 ioc->ctl_cmds.smid = smid;
2188 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
2189 mpi_request->BufferType = buffer_type;
2190 mpi_request->BufferLength =
2191 cpu_to_le32(ioc->diag_buffer_sz[buffer_type]);
2192 mpi_request->BufferAddress =
2193 cpu_to_le64(ioc->diag_buffer_dma[buffer_type]);
2194 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
2195 mpi_request->ProductSpecific[i] =
2196 cpu_to_le32(ioc->product_specific[buffer_type][i]);
2197 mpi_request->VF_ID = 0; /* TODO */
2198 mpi_request->VP_ID = 0;
2200 init_completion(&ioc->ctl_cmds.done);
2201 ioc->put_smid_default(ioc, smid);
2202 wait_for_completion_timeout(&ioc->ctl_cmds.done,
2203 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
2205 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
2207 mpt3sas_base_check_cmd_timeout(ioc,
2208 ioc->ctl_cmds.status, mpi_request,
2209 sizeof(Mpi2DiagBufferPostRequest_t)/4);
2210 goto issue_host_reset;
2213 /* process the completed Reply Message Frame */
2214 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
2215 ioc_err(ioc, "%s: no reply message\n", __func__);
2220 mpi_reply = ioc->ctl_cmds.reply;
2221 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
2223 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
2224 ioc->diag_buffer_status[buffer_type] |=
2225 MPT3_DIAG_BUFFER_IS_REGISTERED;
2226 dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__));
2228 ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2229 __func__, ioc_status,
2230 le32_to_cpu(mpi_reply->IOCLogInfo));
2236 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2240 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
2246 #ifdef CONFIG_COMPAT
2248 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2249 * @ioc: per adapter object
2250 * @cmd: ioctl opcode
2251 * @arg: (struct mpt3_ioctl_command32)
2253 * MPT3COMMAND32 - Handle 32bit applications running on 64bit os.
2256 _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER *ioc, unsigned cmd,
2259 struct mpt3_ioctl_command32 karg32;
2260 struct mpt3_ioctl_command32 __user *uarg;
2261 struct mpt3_ioctl_command karg;
2263 if (_IOC_SIZE(cmd) != sizeof(struct mpt3_ioctl_command32))
2266 uarg = (struct mpt3_ioctl_command32 __user *) arg;
2268 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) {
2269 pr_err("failure at %s:%d/%s()!\n",
2270 __FILE__, __LINE__, __func__);
2274 memset(&karg, 0, sizeof(struct mpt3_ioctl_command));
2275 karg.hdr.ioc_number = karg32.hdr.ioc_number;
2276 karg.hdr.port_number = karg32.hdr.port_number;
2277 karg.hdr.max_data_size = karg32.hdr.max_data_size;
2278 karg.timeout = karg32.timeout;
2279 karg.max_reply_bytes = karg32.max_reply_bytes;
2280 karg.data_in_size = karg32.data_in_size;
2281 karg.data_out_size = karg32.data_out_size;
2282 karg.max_sense_bytes = karg32.max_sense_bytes;
2283 karg.data_sge_offset = karg32.data_sge_offset;
2284 karg.reply_frame_buf_ptr = compat_ptr(karg32.reply_frame_buf_ptr);
2285 karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr);
2286 karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr);
2287 karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr);
2288 return _ctl_do_mpt_command(ioc, karg, &uarg->mf);
2293 * _ctl_ioctl_main - main ioctl entry point
2294 * @file: (struct file)
2295 * @cmd: ioctl opcode
2296 * @arg: user space data buffer
2297 * @compat: handles 32 bit applications in 64bit os
2298 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
2299 * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
2302 _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
2303 u8 compat, u16 mpi_version)
2305 struct MPT3SAS_ADAPTER *ioc;
2306 struct mpt3_ioctl_header ioctl_header;
2307 enum block_state state;
2310 /* get IOCTL header */
2311 if (copy_from_user(&ioctl_header, (char __user *)arg,
2312 sizeof(struct mpt3_ioctl_header))) {
2313 pr_err("failure at %s:%d/%s()!\n",
2314 __FILE__, __LINE__, __func__);
2318 if (_ctl_verify_adapter(ioctl_header.ioc_number,
2319 &ioc, mpi_version) == -1 || !ioc)
2322 /* pci_access_mutex lock acquired by ioctl path */
2323 mutex_lock(&ioc->pci_access_mutex);
2325 if (ioc->shost_recovery || ioc->pci_error_recovery ||
2326 ioc->is_driver_loading || ioc->remove_host) {
2328 goto out_unlock_pciaccess;
2331 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
2332 if (state == NON_BLOCKING) {
2333 if (!mutex_trylock(&ioc->ctl_cmds.mutex)) {
2335 goto out_unlock_pciaccess;
2337 } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) {
2339 goto out_unlock_pciaccess;
2345 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_iocinfo))
2346 ret = _ctl_getiocinfo(ioc, arg);
2348 #ifdef CONFIG_COMPAT
2353 struct mpt3_ioctl_command __user *uarg;
2354 struct mpt3_ioctl_command karg;
2356 #ifdef CONFIG_COMPAT
2358 ret = _ctl_compat_mpt_command(ioc, cmd, arg);
2362 if (copy_from_user(&karg, arg, sizeof(karg))) {
2363 pr_err("failure at %s:%d/%s()!\n",
2364 __FILE__, __LINE__, __func__);
2369 if (karg.hdr.ioc_number != ioctl_header.ioc_number) {
2373 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_command)) {
2375 ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf);
2379 case MPT3EVENTQUERY:
2380 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventquery))
2381 ret = _ctl_eventquery(ioc, arg);
2383 case MPT3EVENTENABLE:
2384 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventenable))
2385 ret = _ctl_eventenable(ioc, arg);
2387 case MPT3EVENTREPORT:
2388 ret = _ctl_eventreport(ioc, arg);
2391 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_diag_reset))
2392 ret = _ctl_do_reset(ioc, arg);
2394 case MPT3BTDHMAPPING:
2395 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_btdh_mapping))
2396 ret = _ctl_btdh_mapping(ioc, arg);
2398 case MPT3DIAGREGISTER:
2399 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_register))
2400 ret = _ctl_diag_register(ioc, arg);
2402 case MPT3DIAGUNREGISTER:
2403 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_unregister))
2404 ret = _ctl_diag_unregister(ioc, arg);
2407 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_query))
2408 ret = _ctl_diag_query(ioc, arg);
2410 case MPT3DIAGRELEASE:
2411 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_release))
2412 ret = _ctl_diag_release(ioc, arg);
2414 case MPT3DIAGREADBUFFER:
2415 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_read_buffer))
2416 ret = _ctl_diag_read_buffer(ioc, arg);
2420 ioc_info(ioc, "unsupported ioctl opcode(0x%08x)\n",
2425 mutex_unlock(&ioc->ctl_cmds.mutex);
2426 out_unlock_pciaccess:
2427 mutex_unlock(&ioc->pci_access_mutex);
2432 * _ctl_ioctl - mpt3ctl main ioctl entry point (unlocked)
2433 * @file: (struct file)
2434 * @cmd: ioctl opcode
2438 _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2442 /* pass MPI25_VERSION | MPI26_VERSION value,
2443 * to indicate that this ioctl cmd
2444 * came from mpt3ctl ioctl device.
2446 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0,
2447 MPI25_VERSION | MPI26_VERSION);
2452 * _ctl_mpt2_ioctl - mpt2ctl main ioctl entry point (unlocked)
2453 * @file: (struct file)
2454 * @cmd: ioctl opcode
2458 _ctl_mpt2_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2462 /* pass MPI2_VERSION value, to indicate that this ioctl cmd
2463 * came from mpt2ctl ioctl device.
2465 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0, MPI2_VERSION);
2468 #ifdef CONFIG_COMPAT
2470 *_ ctl_ioctl_compat - main ioctl entry point (compat)
2475 * This routine handles 32 bit applications in 64bit os.
2478 _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2482 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1,
2483 MPI25_VERSION | MPI26_VERSION);
2488 *_ ctl_mpt2_ioctl_compat - main ioctl entry point (compat)
2493 * This routine handles 32 bit applications in 64bit os.
2496 _ctl_mpt2_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2500 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1, MPI2_VERSION);
2505 /* scsi host attributes */
2507 * version_fw_show - firmware version
2508 * @cdev: pointer to embedded class device
2510 * @buf: the buffer returned
2512 * A sysfs 'read-only' shost attribute.
2515 version_fw_show(struct device *cdev, struct device_attribute *attr,
2518 struct Scsi_Host *shost = class_to_shost(cdev);
2519 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2521 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2522 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2523 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2524 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2525 ioc->facts.FWVersion.Word & 0x000000FF);
2527 static DEVICE_ATTR_RO(version_fw);
2530 * version_bios_show - bios version
2531 * @cdev: pointer to embedded class device
2533 * @buf: the buffer returned
2535 * A sysfs 'read-only' shost attribute.
2538 version_bios_show(struct device *cdev, struct device_attribute *attr,
2541 struct Scsi_Host *shost = class_to_shost(cdev);
2542 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2544 u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2546 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2547 (version & 0xFF000000) >> 24,
2548 (version & 0x00FF0000) >> 16,
2549 (version & 0x0000FF00) >> 8,
2550 version & 0x000000FF);
2552 static DEVICE_ATTR_RO(version_bios);
2555 * version_mpi_show - MPI (message passing interface) version
2556 * @cdev: pointer to embedded class device
2558 * @buf: the buffer returned
2560 * A sysfs 'read-only' shost attribute.
2563 version_mpi_show(struct device *cdev, struct device_attribute *attr,
2566 struct Scsi_Host *shost = class_to_shost(cdev);
2567 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2569 return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
2570 ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
2572 static DEVICE_ATTR_RO(version_mpi);
2575 * version_product_show - product name
2576 * @cdev: pointer to embedded class device
2578 * @buf: the buffer returned
2580 * A sysfs 'read-only' shost attribute.
2583 version_product_show(struct device *cdev, struct device_attribute *attr,
2586 struct Scsi_Host *shost = class_to_shost(cdev);
2587 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2589 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
2591 static DEVICE_ATTR_RO(version_product);
2594 * version_nvdata_persistent_show - ndvata persistent version
2595 * @cdev: pointer to embedded class device
2597 * @buf: the buffer returned
2599 * A sysfs 'read-only' shost attribute.
2602 version_nvdata_persistent_show(struct device *cdev,
2603 struct device_attribute *attr, char *buf)
2605 struct Scsi_Host *shost = class_to_shost(cdev);
2606 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2608 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2609 le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
2611 static DEVICE_ATTR_RO(version_nvdata_persistent);
2614 * version_nvdata_default_show - nvdata default version
2615 * @cdev: pointer to embedded class device
2617 * @buf: the buffer returned
2619 * A sysfs 'read-only' shost attribute.
2622 version_nvdata_default_show(struct device *cdev, struct device_attribute
2625 struct Scsi_Host *shost = class_to_shost(cdev);
2626 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2628 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2629 le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
2631 static DEVICE_ATTR_RO(version_nvdata_default);
2634 * board_name_show - board name
2635 * @cdev: pointer to embedded class device
2637 * @buf: the buffer returned
2639 * A sysfs 'read-only' shost attribute.
2642 board_name_show(struct device *cdev, struct device_attribute *attr,
2645 struct Scsi_Host *shost = class_to_shost(cdev);
2646 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2648 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
2650 static DEVICE_ATTR_RO(board_name);
2653 * board_assembly_show - board assembly name
2654 * @cdev: pointer to embedded class device
2656 * @buf: the buffer returned
2658 * A sysfs 'read-only' shost attribute.
2661 board_assembly_show(struct device *cdev, struct device_attribute *attr,
2664 struct Scsi_Host *shost = class_to_shost(cdev);
2665 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2667 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
2669 static DEVICE_ATTR_RO(board_assembly);
2672 * board_tracer_show - board tracer number
2673 * @cdev: pointer to embedded class device
2675 * @buf: the buffer returned
2677 * A sysfs 'read-only' shost attribute.
2680 board_tracer_show(struct device *cdev, struct device_attribute *attr,
2683 struct Scsi_Host *shost = class_to_shost(cdev);
2684 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2686 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
2688 static DEVICE_ATTR_RO(board_tracer);
2691 * io_delay_show - io missing delay
2692 * @cdev: pointer to embedded class device
2694 * @buf: the buffer returned
2696 * This is for firmware implemention for deboucing device
2699 * A sysfs 'read-only' shost attribute.
2702 io_delay_show(struct device *cdev, struct device_attribute *attr,
2705 struct Scsi_Host *shost = class_to_shost(cdev);
2706 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2708 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
2710 static DEVICE_ATTR_RO(io_delay);
2713 * device_delay_show - device missing delay
2714 * @cdev: pointer to embedded class device
2716 * @buf: the buffer returned
2718 * This is for firmware implemention for deboucing device
2721 * A sysfs 'read-only' shost attribute.
2724 device_delay_show(struct device *cdev, struct device_attribute *attr,
2727 struct Scsi_Host *shost = class_to_shost(cdev);
2728 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2730 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
2732 static DEVICE_ATTR_RO(device_delay);
2735 * fw_queue_depth_show - global credits
2736 * @cdev: pointer to embedded class device
2738 * @buf: the buffer returned
2740 * This is firmware queue depth limit
2742 * A sysfs 'read-only' shost attribute.
2745 fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
2748 struct Scsi_Host *shost = class_to_shost(cdev);
2749 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2751 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
2753 static DEVICE_ATTR_RO(fw_queue_depth);
2756 * sas_address_show - sas address
2757 * @cdev: pointer to embedded class device
2759 * @buf: the buffer returned
2761 * This is the controller sas address
2763 * A sysfs 'read-only' shost attribute.
2766 host_sas_address_show(struct device *cdev, struct device_attribute *attr,
2770 struct Scsi_Host *shost = class_to_shost(cdev);
2771 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2773 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
2774 (unsigned long long)ioc->sas_hba.sas_address);
2776 static DEVICE_ATTR_RO(host_sas_address);
2779 * logging_level_show - logging level
2780 * @cdev: pointer to embedded class device
2782 * @buf: the buffer returned
2784 * A sysfs 'read/write' shost attribute.
2787 logging_level_show(struct device *cdev, struct device_attribute *attr,
2790 struct Scsi_Host *shost = class_to_shost(cdev);
2791 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2793 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
2796 logging_level_store(struct device *cdev, struct device_attribute *attr,
2797 const char *buf, size_t count)
2799 struct Scsi_Host *shost = class_to_shost(cdev);
2800 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2803 if (sscanf(buf, "%x", &val) != 1)
2806 ioc->logging_level = val;
2807 ioc_info(ioc, "logging_level=%08xh\n",
2808 ioc->logging_level);
2811 static DEVICE_ATTR_RW(logging_level);
2814 * fwfault_debug_show - show/store fwfault_debug
2815 * @cdev: pointer to embedded class device
2817 * @buf: the buffer returned
2819 * mpt3sas_fwfault_debug is command line option
2820 * A sysfs 'read/write' shost attribute.
2823 fwfault_debug_show(struct device *cdev, struct device_attribute *attr,
2826 struct Scsi_Host *shost = class_to_shost(cdev);
2827 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2829 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
2832 fwfault_debug_store(struct device *cdev, struct device_attribute *attr,
2833 const char *buf, size_t count)
2835 struct Scsi_Host *shost = class_to_shost(cdev);
2836 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2839 if (sscanf(buf, "%d", &val) != 1)
2842 ioc->fwfault_debug = val;
2843 ioc_info(ioc, "fwfault_debug=%d\n",
2844 ioc->fwfault_debug);
2847 static DEVICE_ATTR_RW(fwfault_debug);
2850 * ioc_reset_count_show - ioc reset count
2851 * @cdev: pointer to embedded class device
2853 * @buf: the buffer returned
2855 * This is firmware queue depth limit
2857 * A sysfs 'read-only' shost attribute.
2860 ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
2863 struct Scsi_Host *shost = class_to_shost(cdev);
2864 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2866 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->ioc_reset_count);
2868 static DEVICE_ATTR_RO(ioc_reset_count);
2871 * reply_queue_count_show - number of reply queues
2872 * @cdev: pointer to embedded class device
2874 * @buf: the buffer returned
2876 * This is number of reply queues
2878 * A sysfs 'read-only' shost attribute.
2881 reply_queue_count_show(struct device *cdev,
2882 struct device_attribute *attr, char *buf)
2884 u8 reply_queue_count;
2885 struct Scsi_Host *shost = class_to_shost(cdev);
2886 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2888 if ((ioc->facts.IOCCapabilities &
2889 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable)
2890 reply_queue_count = ioc->reply_queue_count;
2892 reply_queue_count = 1;
2894 return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count);
2896 static DEVICE_ATTR_RO(reply_queue_count);
2899 * BRM_status_show - Backup Rail Monitor Status
2900 * @cdev: pointer to embedded class device
2902 * @buf: the buffer returned
2904 * This is number of reply queues
2906 * A sysfs 'read-only' shost attribute.
2909 BRM_status_show(struct device *cdev, struct device_attribute *attr,
2912 struct Scsi_Host *shost = class_to_shost(cdev);
2913 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2914 Mpi2IOUnitPage3_t *io_unit_pg3 = NULL;
2915 Mpi2ConfigReply_t mpi_reply;
2916 u16 backup_rail_monitor_status = 0;
2921 if (!ioc->is_warpdrive) {
2922 ioc_err(ioc, "%s: BRM attribute is only for warpdrive\n",
2926 /* pci_access_mutex lock acquired by sysfs show path */
2927 mutex_lock(&ioc->pci_access_mutex);
2928 if (ioc->pci_error_recovery || ioc->remove_host)
2931 /* allocate upto GPIOVal 36 entries */
2932 sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
2933 io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
2936 ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n",
2941 if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
2943 ioc_err(ioc, "%s: failed reading iounit_pg3\n",
2949 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
2950 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2951 ioc_err(ioc, "%s: iounit_pg3 failed with ioc_status(0x%04x)\n",
2952 __func__, ioc_status);
2957 if (io_unit_pg3->GPIOCount < 25) {
2958 ioc_err(ioc, "%s: iounit_pg3->GPIOCount less than 25 entries, detected (%d) entries\n",
2959 __func__, io_unit_pg3->GPIOCount);
2964 /* BRM status is in bit zero of GPIOVal[24] */
2965 backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]);
2966 rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1));
2970 mutex_unlock(&ioc->pci_access_mutex);
2973 static DEVICE_ATTR_RO(BRM_status);
2975 struct DIAG_BUFFER_START {
2986 * host_trace_buffer_size_show - host buffer size (trace only)
2987 * @cdev: pointer to embedded class device
2989 * @buf: the buffer returned
2991 * A sysfs 'read-only' shost attribute.
2994 host_trace_buffer_size_show(struct device *cdev,
2995 struct device_attribute *attr, char *buf)
2997 struct Scsi_Host *shost = class_to_shost(cdev);
2998 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3000 struct DIAG_BUFFER_START *request_data;
3002 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
3003 ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3008 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3009 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
3010 ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3015 request_data = (struct DIAG_BUFFER_START *)
3016 ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE];
3017 if ((le32_to_cpu(request_data->DiagVersion) == 0x00000000 ||
3018 le32_to_cpu(request_data->DiagVersion) == 0x01000000 ||
3019 le32_to_cpu(request_data->DiagVersion) == 0x01010000) &&
3020 le32_to_cpu(request_data->Reserved3) == 0x4742444c)
3021 size = le32_to_cpu(request_data->Size);
3023 ioc->ring_buffer_sz = size;
3024 return snprintf(buf, PAGE_SIZE, "%d\n", size);
3026 static DEVICE_ATTR_RO(host_trace_buffer_size);
3029 * host_trace_buffer_show - firmware ring buffer (trace only)
3030 * @cdev: pointer to embedded class device
3032 * @buf: the buffer returned
3034 * A sysfs 'read/write' shost attribute.
3036 * You will only be able to read 4k bytes of ring buffer at a time.
3037 * In order to read beyond 4k bytes, you will have to write out the
3038 * offset to the same attribute, it will move the pointer.
3041 host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
3044 struct Scsi_Host *shost = class_to_shost(cdev);
3045 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3049 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
3050 ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3055 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3056 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
3057 ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
3062 if (ioc->ring_buffer_offset > ioc->ring_buffer_sz)
3065 size = ioc->ring_buffer_sz - ioc->ring_buffer_offset;
3066 size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size;
3067 request_data = ioc->diag_buffer[0] + ioc->ring_buffer_offset;
3068 memcpy(buf, request_data, size);
3073 host_trace_buffer_store(struct device *cdev, struct device_attribute *attr,
3074 const char *buf, size_t count)
3076 struct Scsi_Host *shost = class_to_shost(cdev);
3077 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3080 if (sscanf(buf, "%d", &val) != 1)
3083 ioc->ring_buffer_offset = val;
3086 static DEVICE_ATTR_RW(host_trace_buffer);
3089 /*****************************************/
3092 * host_trace_buffer_enable_show - firmware ring buffer (trace only)
3093 * @cdev: pointer to embedded class device
3095 * @buf: the buffer returned
3097 * A sysfs 'read/write' shost attribute.
3099 * This is a mechnism to post/release host_trace_buffers
3102 host_trace_buffer_enable_show(struct device *cdev,
3103 struct device_attribute *attr, char *buf)
3105 struct Scsi_Host *shost = class_to_shost(cdev);
3106 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3108 if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) ||
3109 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3110 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0))
3111 return snprintf(buf, PAGE_SIZE, "off\n");
3112 else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3113 MPT3_DIAG_BUFFER_IS_RELEASED))
3114 return snprintf(buf, PAGE_SIZE, "release\n");
3116 return snprintf(buf, PAGE_SIZE, "post\n");
3120 host_trace_buffer_enable_store(struct device *cdev,
3121 struct device_attribute *attr, const char *buf, size_t count)
3123 struct Scsi_Host *shost = class_to_shost(cdev);
3124 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3126 struct mpt3_diag_register diag_register;
3129 /* don't allow post/release occurr while recovery is active */
3130 if (ioc->shost_recovery || ioc->remove_host ||
3131 ioc->pci_error_recovery || ioc->is_driver_loading)
3134 if (sscanf(buf, "%9s", str) != 1)
3137 if (!strcmp(str, "post")) {
3138 /* exit out if host buffers are already posted */
3139 if ((ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) &&
3140 (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3141 MPT3_DIAG_BUFFER_IS_REGISTERED) &&
3142 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3143 MPT3_DIAG_BUFFER_IS_RELEASED) == 0))
3145 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
3146 ioc_info(ioc, "posting host trace buffers\n");
3147 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
3148 diag_register.requested_buffer_size = (1024 * 1024);
3149 diag_register.unique_id = 0x7075900;
3150 ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] = 0;
3151 _ctl_diag_register_2(ioc, &diag_register);
3152 } else if (!strcmp(str, "release")) {
3153 /* exit out if host buffers are already released */
3154 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE])
3156 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3157 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0)
3159 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3160 MPT3_DIAG_BUFFER_IS_RELEASED))
3162 ioc_info(ioc, "releasing host trace buffer\n");
3163 mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE,
3170 static DEVICE_ATTR_RW(host_trace_buffer_enable);
3172 /*********** diagnostic trigger suppport *********************************/
3175 * diag_trigger_master_show - show the diag_trigger_master attribute
3176 * @cdev: pointer to embedded class device
3178 * @buf: the buffer returned
3180 * A sysfs 'read/write' shost attribute.
3183 diag_trigger_master_show(struct device *cdev,
3184 struct device_attribute *attr, char *buf)
3187 struct Scsi_Host *shost = class_to_shost(cdev);
3188 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3189 unsigned long flags;
3192 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3193 rc = sizeof(struct SL_WH_MASTER_TRIGGER_T);
3194 memcpy(buf, &ioc->diag_trigger_master, rc);
3195 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3200 * diag_trigger_master_store - store the diag_trigger_master attribute
3201 * @cdev: pointer to embedded class device
3203 * @buf: the buffer returned
3206 * A sysfs 'read/write' shost attribute.
3209 diag_trigger_master_store(struct device *cdev,
3210 struct device_attribute *attr, const char *buf, size_t count)
3213 struct Scsi_Host *shost = class_to_shost(cdev);
3214 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3215 unsigned long flags;
3218 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3219 rc = min(sizeof(struct SL_WH_MASTER_TRIGGER_T), count);
3220 memset(&ioc->diag_trigger_master, 0,
3221 sizeof(struct SL_WH_MASTER_TRIGGER_T));
3222 memcpy(&ioc->diag_trigger_master, buf, rc);
3223 ioc->diag_trigger_master.MasterData |=
3224 (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET);
3225 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3228 static DEVICE_ATTR_RW(diag_trigger_master);
3232 * diag_trigger_event_show - show the diag_trigger_event attribute
3233 * @cdev: pointer to embedded class device
3235 * @buf: the buffer returned
3237 * A sysfs 'read/write' shost attribute.
3240 diag_trigger_event_show(struct device *cdev,
3241 struct device_attribute *attr, char *buf)
3243 struct Scsi_Host *shost = class_to_shost(cdev);
3244 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3245 unsigned long flags;
3248 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3249 rc = sizeof(struct SL_WH_EVENT_TRIGGERS_T);
3250 memcpy(buf, &ioc->diag_trigger_event, rc);
3251 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3256 * diag_trigger_event_store - store the diag_trigger_event attribute
3257 * @cdev: pointer to embedded class device
3259 * @buf: the buffer returned
3262 * A sysfs 'read/write' shost attribute.
3265 diag_trigger_event_store(struct device *cdev,
3266 struct device_attribute *attr, const char *buf, size_t count)
3269 struct Scsi_Host *shost = class_to_shost(cdev);
3270 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3271 unsigned long flags;
3274 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3275 sz = min(sizeof(struct SL_WH_EVENT_TRIGGERS_T), count);
3276 memset(&ioc->diag_trigger_event, 0,
3277 sizeof(struct SL_WH_EVENT_TRIGGERS_T));
3278 memcpy(&ioc->diag_trigger_event, buf, sz);
3279 if (ioc->diag_trigger_event.ValidEntries > NUM_VALID_ENTRIES)
3280 ioc->diag_trigger_event.ValidEntries = NUM_VALID_ENTRIES;
3281 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3284 static DEVICE_ATTR_RW(diag_trigger_event);
3288 * diag_trigger_scsi_show - show the diag_trigger_scsi attribute
3289 * @cdev: pointer to embedded class device
3291 * @buf: the buffer returned
3293 * A sysfs 'read/write' shost attribute.
3296 diag_trigger_scsi_show(struct device *cdev,
3297 struct device_attribute *attr, char *buf)
3299 struct Scsi_Host *shost = class_to_shost(cdev);
3300 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3301 unsigned long flags;
3304 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3305 rc = sizeof(struct SL_WH_SCSI_TRIGGERS_T);
3306 memcpy(buf, &ioc->diag_trigger_scsi, rc);
3307 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3312 * diag_trigger_scsi_store - store the diag_trigger_scsi attribute
3313 * @cdev: pointer to embedded class device
3315 * @buf: the buffer returned
3318 * A sysfs 'read/write' shost attribute.
3321 diag_trigger_scsi_store(struct device *cdev,
3322 struct device_attribute *attr, const char *buf, size_t count)
3324 struct Scsi_Host *shost = class_to_shost(cdev);
3325 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3326 unsigned long flags;
3329 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3330 sz = min(sizeof(ioc->diag_trigger_scsi), count);
3331 memset(&ioc->diag_trigger_scsi, 0, sizeof(ioc->diag_trigger_scsi));
3332 memcpy(&ioc->diag_trigger_scsi, buf, sz);
3333 if (ioc->diag_trigger_scsi.ValidEntries > NUM_VALID_ENTRIES)
3334 ioc->diag_trigger_scsi.ValidEntries = NUM_VALID_ENTRIES;
3335 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3338 static DEVICE_ATTR_RW(diag_trigger_scsi);
3342 * diag_trigger_scsi_show - show the diag_trigger_mpi attribute
3343 * @cdev: pointer to embedded class device
3345 * @buf: the buffer returned
3347 * A sysfs 'read/write' shost attribute.
3350 diag_trigger_mpi_show(struct device *cdev,
3351 struct device_attribute *attr, char *buf)
3353 struct Scsi_Host *shost = class_to_shost(cdev);
3354 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3355 unsigned long flags;
3358 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3359 rc = sizeof(struct SL_WH_MPI_TRIGGERS_T);
3360 memcpy(buf, &ioc->diag_trigger_mpi, rc);
3361 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3366 * diag_trigger_mpi_store - store the diag_trigger_mpi attribute
3367 * @cdev: pointer to embedded class device
3369 * @buf: the buffer returned
3372 * A sysfs 'read/write' shost attribute.
3375 diag_trigger_mpi_store(struct device *cdev,
3376 struct device_attribute *attr, const char *buf, size_t count)
3378 struct Scsi_Host *shost = class_to_shost(cdev);
3379 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3380 unsigned long flags;
3383 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3384 sz = min(sizeof(struct SL_WH_MPI_TRIGGERS_T), count);
3385 memset(&ioc->diag_trigger_mpi, 0,
3386 sizeof(ioc->diag_trigger_mpi));
3387 memcpy(&ioc->diag_trigger_mpi, buf, sz);
3388 if (ioc->diag_trigger_mpi.ValidEntries > NUM_VALID_ENTRIES)
3389 ioc->diag_trigger_mpi.ValidEntries = NUM_VALID_ENTRIES;
3390 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3394 static DEVICE_ATTR_RW(diag_trigger_mpi);
3396 /*********** diagnostic trigger suppport *** END ****************************/
3398 /*****************************************/
3401 * drv_support_bitmap_show - driver supported feature bitmap
3402 * @cdev - pointer to embedded class device
3403 * @buf - the buffer returned
3405 * A sysfs 'read-only' shost attribute.
3408 drv_support_bitmap_show(struct device *cdev,
3409 struct device_attribute *attr, char *buf)
3411 struct Scsi_Host *shost = class_to_shost(cdev);
3412 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3414 return snprintf(buf, PAGE_SIZE, "0x%08x\n", ioc->drv_support_bitmap);
3416 static DEVICE_ATTR_RO(drv_support_bitmap);
3419 * enable_sdev_max_qd_show - display whether sdev max qd is enabled/disabled
3420 * @cdev - pointer to embedded class device
3421 * @buf - the buffer returned
3423 * A sysfs read/write shost attribute. This attribute is used to set the
3424 * targets queue depth to HBA IO queue depth if this attribute is enabled.
3427 enable_sdev_max_qd_show(struct device *cdev,
3428 struct device_attribute *attr, char *buf)
3430 struct Scsi_Host *shost = class_to_shost(cdev);
3431 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3433 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->enable_sdev_max_qd);
3437 * enable_sdev_max_qd_store - Enable/disable sdev max qd
3438 * @cdev - pointer to embedded class device
3439 * @buf - the buffer returned
3441 * A sysfs read/write shost attribute. This attribute is used to set the
3442 * targets queue depth to HBA IO queue depth if this attribute is enabled.
3443 * If this attribute is disabled then targets will have corresponding default
3447 enable_sdev_max_qd_store(struct device *cdev,
3448 struct device_attribute *attr, const char *buf, size_t count)
3450 struct Scsi_Host *shost = class_to_shost(cdev);
3451 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3452 struct MPT3SAS_DEVICE *sas_device_priv_data;
3453 struct MPT3SAS_TARGET *sas_target_priv_data;
3455 struct scsi_device *sdev;
3456 struct _raid_device *raid_device;
3459 if (kstrtoint(buf, 0, &val) != 0)
3464 ioc->enable_sdev_max_qd = 0;
3465 shost_for_each_device(sdev, ioc->shost) {
3466 sas_device_priv_data = sdev->hostdata;
3467 if (!sas_device_priv_data)
3469 sas_target_priv_data = sas_device_priv_data->sas_target;
3470 if (!sas_target_priv_data)
3473 if (sas_target_priv_data->flags &
3474 MPT_TARGET_FLAGS_VOLUME) {
3476 mpt3sas_raid_device_find_by_handle(ioc,
3477 sas_target_priv_data->handle);
3479 switch (raid_device->volume_type) {
3480 case MPI2_RAID_VOL_TYPE_RAID0:
3481 if (raid_device->device_info &
3482 MPI2_SAS_DEVICE_INFO_SSP_TARGET)
3484 MPT3SAS_SAS_QUEUE_DEPTH;
3487 MPT3SAS_SATA_QUEUE_DEPTH;
3489 case MPI2_RAID_VOL_TYPE_RAID1E:
3490 case MPI2_RAID_VOL_TYPE_RAID1:
3491 case MPI2_RAID_VOL_TYPE_RAID10:
3492 case MPI2_RAID_VOL_TYPE_UNKNOWN:
3494 qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
3496 } else if (sas_target_priv_data->flags &
3497 MPT_TARGET_FLAGS_PCIE_DEVICE)
3498 qdepth = MPT3SAS_NVME_QUEUE_DEPTH;
3500 qdepth = MPT3SAS_SAS_QUEUE_DEPTH;
3502 mpt3sas_scsih_change_queue_depth(sdev, qdepth);
3506 ioc->enable_sdev_max_qd = 1;
3507 shost_for_each_device(sdev, ioc->shost)
3508 mpt3sas_scsih_change_queue_depth(sdev,
3517 static DEVICE_ATTR_RW(enable_sdev_max_qd);
3519 struct device_attribute *mpt3sas_host_attrs[] = {
3520 &dev_attr_version_fw,
3521 &dev_attr_version_bios,
3522 &dev_attr_version_mpi,
3523 &dev_attr_version_product,
3524 &dev_attr_version_nvdata_persistent,
3525 &dev_attr_version_nvdata_default,
3526 &dev_attr_board_name,
3527 &dev_attr_board_assembly,
3528 &dev_attr_board_tracer,
3530 &dev_attr_device_delay,
3531 &dev_attr_logging_level,
3532 &dev_attr_fwfault_debug,
3533 &dev_attr_fw_queue_depth,
3534 &dev_attr_host_sas_address,
3535 &dev_attr_ioc_reset_count,
3536 &dev_attr_host_trace_buffer_size,
3537 &dev_attr_host_trace_buffer,
3538 &dev_attr_host_trace_buffer_enable,
3539 &dev_attr_reply_queue_count,
3540 &dev_attr_diag_trigger_master,
3541 &dev_attr_diag_trigger_event,
3542 &dev_attr_diag_trigger_scsi,
3543 &dev_attr_diag_trigger_mpi,
3544 &dev_attr_drv_support_bitmap,
3545 &dev_attr_BRM_status,
3546 &dev_attr_enable_sdev_max_qd,
3550 /* device attributes */
3553 * sas_address_show - sas address
3554 * @dev: pointer to embedded class device
3556 * @buf: the buffer returned
3558 * This is the sas address for the target
3560 * A sysfs 'read-only' shost attribute.
3563 sas_address_show(struct device *dev, struct device_attribute *attr,
3566 struct scsi_device *sdev = to_scsi_device(dev);
3567 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3569 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
3570 (unsigned long long)sas_device_priv_data->sas_target->sas_address);
3572 static DEVICE_ATTR_RO(sas_address);
3575 * sas_device_handle_show - device handle
3576 * @dev: pointer to embedded class device
3578 * @buf: the buffer returned
3580 * This is the firmware assigned device handle
3582 * A sysfs 'read-only' shost attribute.
3585 sas_device_handle_show(struct device *dev, struct device_attribute *attr,
3588 struct scsi_device *sdev = to_scsi_device(dev);
3589 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3591 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
3592 sas_device_priv_data->sas_target->handle);
3594 static DEVICE_ATTR_RO(sas_device_handle);
3597 * sas_ncq_io_prio_show - send prioritized io commands to device
3598 * @dev: pointer to embedded device
3600 * @buf: the buffer returned
3602 * A sysfs 'read/write' sdev attribute, only works with SATA
3605 sas_ncq_prio_enable_show(struct device *dev,
3606 struct device_attribute *attr, char *buf)
3608 struct scsi_device *sdev = to_scsi_device(dev);
3609 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3611 return snprintf(buf, PAGE_SIZE, "%d\n",
3612 sas_device_priv_data->ncq_prio_enable);
3616 sas_ncq_prio_enable_store(struct device *dev,
3617 struct device_attribute *attr,
3618 const char *buf, size_t count)
3620 struct scsi_device *sdev = to_scsi_device(dev);
3621 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3622 bool ncq_prio_enable = 0;
3624 if (kstrtobool(buf, &ncq_prio_enable))
3627 if (!scsih_ncq_prio_supp(sdev))
3630 sas_device_priv_data->ncq_prio_enable = ncq_prio_enable;
3633 static DEVICE_ATTR_RW(sas_ncq_prio_enable);
3635 struct device_attribute *mpt3sas_dev_attrs[] = {
3636 &dev_attr_sas_address,
3637 &dev_attr_sas_device_handle,
3638 &dev_attr_sas_ncq_prio_enable,
3642 /* file operations table for mpt3ctl device */
3643 static const struct file_operations ctl_fops = {
3644 .owner = THIS_MODULE,
3645 .unlocked_ioctl = _ctl_ioctl,
3647 .fasync = _ctl_fasync,
3648 #ifdef CONFIG_COMPAT
3649 .compat_ioctl = _ctl_ioctl_compat,
3653 /* file operations table for mpt2ctl device */
3654 static const struct file_operations ctl_gen2_fops = {
3655 .owner = THIS_MODULE,
3656 .unlocked_ioctl = _ctl_mpt2_ioctl,
3658 .fasync = _ctl_fasync,
3659 #ifdef CONFIG_COMPAT
3660 .compat_ioctl = _ctl_mpt2_ioctl_compat,
3664 static struct miscdevice ctl_dev = {
3665 .minor = MPT3SAS_MINOR,
3666 .name = MPT3SAS_DEV_NAME,
3670 static struct miscdevice gen2_ctl_dev = {
3671 .minor = MPT2SAS_MINOR,
3672 .name = MPT2SAS_DEV_NAME,
3673 .fops = &ctl_gen2_fops,
3677 * mpt3sas_ctl_init - main entry point for ctl.
3678 * @hbas_to_enumerate: ?
3681 mpt3sas_ctl_init(ushort hbas_to_enumerate)
3685 /* Don't register mpt3ctl ioctl device if
3686 * hbas_to_enumarate is one.
3688 if (hbas_to_enumerate != 1)
3689 if (misc_register(&ctl_dev) < 0)
3690 pr_err("%s can't register misc device [minor=%d]\n",
3691 MPT3SAS_DRIVER_NAME, MPT3SAS_MINOR);
3693 /* Don't register mpt3ctl ioctl device if
3694 * hbas_to_enumarate is two.
3696 if (hbas_to_enumerate != 2)
3697 if (misc_register(&gen2_ctl_dev) < 0)
3698 pr_err("%s can't register misc device [minor=%d]\n",
3699 MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR);
3701 init_waitqueue_head(&ctl_poll_wait);
3705 * mpt3sas_ctl_exit - exit point for ctl
3706 * @hbas_to_enumerate: ?
3709 mpt3sas_ctl_exit(ushort hbas_to_enumerate)
3711 struct MPT3SAS_ADAPTER *ioc;
3714 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
3716 /* free memory associated to diag buffers */
3717 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
3718 if (!ioc->diag_buffer[i])
3720 dma_free_coherent(&ioc->pdev->dev,
3721 ioc->diag_buffer_sz[i],
3722 ioc->diag_buffer[i],
3723 ioc->diag_buffer_dma[i]);
3724 ioc->diag_buffer[i] = NULL;
3725 ioc->diag_buffer_status[i] = 0;
3728 kfree(ioc->event_log);
3730 if (hbas_to_enumerate != 1)
3731 misc_deregister(&ctl_dev);
3732 if (hbas_to_enumerate != 2)
3733 misc_deregister(&gen2_ctl_dev);