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_sas_device_find_by_handle - sas device search
83 * @ioc: per adapter object
84 * @handle: sas device handle (assigned by firmware)
85 * Context: Calling function should acquire ioc->sas_device_lock
87 * This searches for sas_device based on sas_address, then return sas_device
90 static struct _sas_device *
91 _ctl_sas_device_find_by_handle(struct MPT3SAS_ADAPTER *ioc, u16 handle)
93 struct _sas_device *sas_device, *r;
96 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
97 if (sas_device->handle != handle)
108 * _ctl_display_some_debug - debug routine
109 * @ioc: per adapter object
110 * @smid: system request message index
111 * @calling_function_name: string pass from calling function
112 * @mpi_reply: reply message frame
115 * Function for displaying debug info helpful when debugging issues
119 _ctl_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid,
120 char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
122 Mpi2ConfigRequest_t *mpi_request;
125 if (!(ioc->logging_level & MPT_DEBUG_IOCTL))
128 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
129 switch (mpi_request->Function) {
130 case MPI2_FUNCTION_SCSI_IO_REQUEST:
132 Mpi2SCSIIORequest_t *scsi_request =
133 (Mpi2SCSIIORequest_t *)mpi_request;
135 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
136 "scsi_io, cmd(0x%02x), cdb_len(%d)",
137 scsi_request->CDB.CDB32[0],
138 le16_to_cpu(scsi_request->IoFlags) & 0xF);
139 desc = ioc->tmp_string;
142 case MPI2_FUNCTION_SCSI_TASK_MGMT:
145 case MPI2_FUNCTION_IOC_INIT:
148 case MPI2_FUNCTION_IOC_FACTS:
151 case MPI2_FUNCTION_CONFIG:
153 Mpi2ConfigRequest_t *config_request =
154 (Mpi2ConfigRequest_t *)mpi_request;
156 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
157 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
158 (config_request->Header.PageType &
159 MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType,
160 config_request->Header.PageNumber);
161 desc = ioc->tmp_string;
164 case MPI2_FUNCTION_PORT_FACTS:
167 case MPI2_FUNCTION_PORT_ENABLE:
168 desc = "port_enable";
170 case MPI2_FUNCTION_EVENT_NOTIFICATION:
171 desc = "event_notification";
173 case MPI2_FUNCTION_FW_DOWNLOAD:
174 desc = "fw_download";
176 case MPI2_FUNCTION_FW_UPLOAD:
179 case MPI2_FUNCTION_RAID_ACTION:
180 desc = "raid_action";
182 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
184 Mpi2SCSIIORequest_t *scsi_request =
185 (Mpi2SCSIIORequest_t *)mpi_request;
187 snprintf(ioc->tmp_string, MPT_STRING_LENGTH,
188 "raid_pass, cmd(0x%02x), cdb_len(%d)",
189 scsi_request->CDB.CDB32[0],
190 le16_to_cpu(scsi_request->IoFlags) & 0xF);
191 desc = ioc->tmp_string;
194 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
195 desc = "sas_iounit_cntl";
197 case MPI2_FUNCTION_SATA_PASSTHROUGH:
200 case MPI2_FUNCTION_DIAG_BUFFER_POST:
201 desc = "diag_buffer_post";
203 case MPI2_FUNCTION_DIAG_RELEASE:
204 desc = "diag_release";
206 case MPI2_FUNCTION_SMP_PASSTHROUGH:
207 desc = "smp_passthrough";
214 pr_info(MPT3SAS_FMT "%s: %s, smid(%d)\n",
215 ioc->name, calling_function_name, desc, smid);
220 if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo)
222 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
223 ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
224 le32_to_cpu(mpi_reply->IOCLogInfo));
226 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
227 mpi_request->Function ==
228 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
229 Mpi2SCSIIOReply_t *scsi_reply =
230 (Mpi2SCSIIOReply_t *)mpi_reply;
231 struct _sas_device *sas_device = NULL;
234 spin_lock_irqsave(&ioc->sas_device_lock, flags);
235 sas_device = _ctl_sas_device_find_by_handle(ioc,
236 le16_to_cpu(scsi_reply->DevHandle));
238 pr_warn(MPT3SAS_FMT "\tsas_address(0x%016llx), phy(%d)\n",
239 ioc->name, (unsigned long long)
240 sas_device->sas_address, sas_device->phy);
242 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
243 ioc->name, (unsigned long long)
244 sas_device->enclosure_logical_id, sas_device->slot);
246 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
247 if (scsi_reply->SCSIState || scsi_reply->SCSIStatus)
249 "\tscsi_state(0x%02x), scsi_status"
250 "(0x%02x)\n", ioc->name,
251 scsi_reply->SCSIState,
252 scsi_reply->SCSIStatus);
257 * mpt3sas_ctl_done - ctl module completion routine
258 * @ioc: per adapter object
259 * @smid: system request message index
260 * @msix_index: MSIX table index supplied by the OS
261 * @reply: reply message frame(lower 32bit addr)
264 * The callback handler when using ioc->ctl_cb_idx.
266 * Return 1 meaning mf should be freed from _base_interrupt
267 * 0 means the mf is freed from this function.
270 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
273 MPI2DefaultReply_t *mpi_reply;
274 Mpi2SCSIIOReply_t *scsiio_reply;
275 const void *sense_data;
278 if (ioc->ctl_cmds.status == MPT3_CMD_NOT_USED)
280 if (ioc->ctl_cmds.smid != smid)
282 ioc->ctl_cmds.status |= MPT3_CMD_COMPLETE;
283 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
285 memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
286 ioc->ctl_cmds.status |= MPT3_CMD_REPLY_VALID;
288 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
289 mpi_reply->Function ==
290 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
291 scsiio_reply = (Mpi2SCSIIOReply_t *)mpi_reply;
292 if (scsiio_reply->SCSIState &
293 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
294 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
295 le32_to_cpu(scsiio_reply->SenseCount));
296 sense_data = mpt3sas_base_get_sense_buffer(ioc,
298 memcpy(ioc->ctl_cmds.sense, sense_data, sz);
302 _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply);
303 ioc->ctl_cmds.status &= ~MPT3_CMD_PENDING;
304 complete(&ioc->ctl_cmds.done);
309 * _ctl_check_event_type - determines when an event needs logging
310 * @ioc: per adapter object
311 * @event: firmware event
313 * The bitmask in ioc->event_type[] indicates which events should be
314 * be saved in the driver event_log. This bitmask is set by application.
316 * Returns 1 when event should be captured, or zero means no match.
319 _ctl_check_event_type(struct MPT3SAS_ADAPTER *ioc, u16 event)
324 if (event >= 128 || !event || !ioc->event_log)
327 desired_event = (1 << (event % 32));
331 return desired_event & ioc->event_type[i];
335 * mpt3sas_ctl_add_to_event_log - add event
336 * @ioc: per adapter object
337 * @mpi_reply: reply message frame
342 mpt3sas_ctl_add_to_event_log(struct MPT3SAS_ADAPTER *ioc,
343 Mpi2EventNotificationReply_t *mpi_reply)
345 struct MPT3_IOCTL_EVENTS *event_log;
348 u32 sz, event_data_sz;
354 event = le16_to_cpu(mpi_reply->Event);
356 if (_ctl_check_event_type(ioc, event)) {
358 /* insert entry into circular event_log */
359 i = ioc->event_context % MPT3SAS_CTL_EVENT_LOG_SIZE;
360 event_log = ioc->event_log;
361 event_log[i].event = event;
362 event_log[i].context = ioc->event_context++;
364 event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4;
365 sz = min_t(u32, event_data_sz, MPT3_EVENT_DATA_SIZE);
366 memset(event_log[i].data, 0, MPT3_EVENT_DATA_SIZE);
367 memcpy(event_log[i].data, mpi_reply->EventData, sz);
371 /* This aen_event_read_flag flag is set until the
372 * application has read the event log.
373 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
375 if (event == MPI2_EVENT_LOG_ENTRY_ADDED ||
376 (send_aen && !ioc->aen_event_read_flag)) {
377 ioc->aen_event_read_flag = 1;
378 wake_up_interruptible(&ctl_poll_wait);
380 kill_fasync(&async_queue, SIGIO, POLL_IN);
385 * mpt3sas_ctl_event_callback - firmware event handler (called at ISR time)
386 * @ioc: per adapter object
387 * @msix_index: MSIX table index supplied by the OS
388 * @reply: reply message frame(lower 32bit addr)
389 * Context: interrupt.
391 * This function merely adds a new work task into ioc->firmware_event_thread.
392 * The tasks are worked from _firmware_event_work in user context.
394 * Return 1 meaning mf should be freed from _base_interrupt
395 * 0 means the mf is freed from this function.
398 mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
401 Mpi2EventNotificationReply_t *mpi_reply;
403 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
405 mpt3sas_ctl_add_to_event_log(ioc, mpi_reply);
410 * _ctl_verify_adapter - validates ioc_number passed from application
411 * @ioc: per adapter object
412 * @iocpp: The ioc pointer is returned in this.
413 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
414 * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
416 * Return (-1) means error, else ioc_number.
419 _ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp,
422 struct MPT3SAS_ADAPTER *ioc;
424 /* global ioc lock to protect controller on list operations */
425 spin_lock(&gioc_lock);
426 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
427 if (ioc->id != ioc_number)
429 /* Check whether this ioctl command is from right
430 * ioctl device or not, if not continue the search.
432 version = ioc->hba_mpi_version_belonged;
433 /* MPI25_VERSION and MPI26_VERSION uses same ioctl
436 if (mpi_version == (MPI25_VERSION | MPI26_VERSION)) {
437 if ((version == MPI25_VERSION) ||
438 (version == MPI26_VERSION))
443 if (version != mpi_version)
447 spin_unlock(&gioc_lock);
451 spin_unlock(&gioc_lock);
457 * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
458 * @ioc: per adapter object
459 * @reset_phase: phase
461 * The handler for doing any required cleanup or initialization.
463 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
464 * MPT3_IOC_DONE_RESET
467 mpt3sas_ctl_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
472 switch (reset_phase) {
473 case MPT3_IOC_PRE_RESET:
474 dtmprintk(ioc, pr_info(MPT3SAS_FMT
475 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
476 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
477 if (!(ioc->diag_buffer_status[i] &
478 MPT3_DIAG_BUFFER_IS_REGISTERED))
480 if ((ioc->diag_buffer_status[i] &
481 MPT3_DIAG_BUFFER_IS_RELEASED))
483 mpt3sas_send_diag_release(ioc, i, &issue_reset);
486 case MPT3_IOC_AFTER_RESET:
487 dtmprintk(ioc, pr_info(MPT3SAS_FMT
488 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
489 if (ioc->ctl_cmds.status & MPT3_CMD_PENDING) {
490 ioc->ctl_cmds.status |= MPT3_CMD_RESET;
491 mpt3sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
492 complete(&ioc->ctl_cmds.done);
495 case MPT3_IOC_DONE_RESET:
496 dtmprintk(ioc, pr_info(MPT3SAS_FMT
497 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
499 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
500 if (!(ioc->diag_buffer_status[i] &
501 MPT3_DIAG_BUFFER_IS_REGISTERED))
503 if ((ioc->diag_buffer_status[i] &
504 MPT3_DIAG_BUFFER_IS_RELEASED))
506 ioc->diag_buffer_status[i] |=
507 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 POLLIN | POLLRDNORM;
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 * Returns 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;
571 Mpi2SCSITaskManagementReply_t *tm_reply;
576 if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
578 else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
583 lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
585 handle = le16_to_cpu(tm_request->DevHandle);
586 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
587 for (i = ioc->scsiio_depth; i && !found; i--) {
588 scmd = ioc->scsi_lookup[i - 1].scmd;
589 if (scmd == NULL || scmd->device == NULL ||
590 scmd->device->hostdata == NULL)
592 if (lun != scmd->device->lun)
594 priv_data = scmd->device->hostdata;
595 if (priv_data->sas_target == NULL)
597 if (priv_data->sas_target->handle != handle)
599 tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid);
602 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
605 dctlprintk(ioc, pr_info(MPT3SAS_FMT
606 "%s: handle(0x%04x), lun(%d), no active mid!!\n",
608 desc, le16_to_cpu(tm_request->DevHandle), lun));
609 tm_reply = ioc->ctl_cmds.reply;
610 tm_reply->DevHandle = tm_request->DevHandle;
611 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
612 tm_reply->TaskType = tm_request->TaskType;
613 tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
614 tm_reply->VP_ID = tm_request->VP_ID;
615 tm_reply->VF_ID = tm_request->VF_ID;
616 sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz);
617 if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply,
619 pr_err("failure at %s:%d/%s()!\n", __FILE__,
624 dctlprintk(ioc, pr_info(MPT3SAS_FMT
625 "%s: handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
626 desc, le16_to_cpu(tm_request->DevHandle), lun,
627 le16_to_cpu(tm_request->TaskMID)));
632 * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode
633 * @ioc: per adapter object
634 * @karg - (struct mpt3_ioctl_command)
635 * @mf - pointer to mf in user space
638 _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
641 MPI2RequestHeader_t *mpi_request = NULL, *request;
642 MPI2DefaultReply_t *mpi_reply;
645 unsigned long timeout;
649 void *data_out = NULL;
650 dma_addr_t data_out_dma = 0;
651 size_t data_out_sz = 0;
652 void *data_in = NULL;
653 dma_addr_t data_in_dma = 0;
654 size_t data_in_sz = 0;
656 u16 wait_state_count;
660 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
661 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
662 ioc->name, __func__);
667 wait_state_count = 0;
668 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
669 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
670 if (wait_state_count++ == 10) {
672 "%s: failed due to ioc not operational\n",
673 ioc->name, __func__);
678 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
680 "%s: waiting for operational state(count=%d)\n",
682 __func__, wait_state_count);
684 if (wait_state_count)
685 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
686 ioc->name, __func__);
688 mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL);
691 "%s: failed obtaining a memory for mpi_request\n",
692 ioc->name, __func__);
697 /* Check for overflow and wraparound */
698 if (karg.data_sge_offset * 4 > ioc->request_sz ||
699 karg.data_sge_offset > (UINT_MAX / 4)) {
704 /* copy in request message frame from user */
705 if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
706 pr_err("failure at %s:%d/%s()!\n", __FILE__, __LINE__,
712 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
713 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx);
715 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
716 ioc->name, __func__);
722 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->ctl_cb_idx, NULL);
724 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
725 ioc->name, __func__);
732 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
733 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
734 request = mpt3sas_base_get_msg_frame(ioc, smid);
735 memcpy(request, mpi_request, karg.data_sge_offset*4);
736 ioc->ctl_cmds.smid = smid;
737 data_out_sz = karg.data_out_size;
738 data_in_sz = karg.data_in_size;
740 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
741 mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
742 if (!le16_to_cpu(mpi_request->FunctionDependent1) ||
743 le16_to_cpu(mpi_request->FunctionDependent1) >
744 ioc->facts.MaxDevHandle) {
746 mpt3sas_base_free_smid(ioc, smid);
751 /* obtain dma-able memory for data transfer */
752 if (data_out_sz) /* WRITE */ {
753 data_out = pci_alloc_consistent(ioc->pdev, data_out_sz,
756 pr_err("failure at %s:%d/%s()!\n", __FILE__,
759 mpt3sas_base_free_smid(ioc, smid);
762 if (copy_from_user(data_out, karg.data_out_buf_ptr,
764 pr_err("failure at %s:%d/%s()!\n", __FILE__,
767 mpt3sas_base_free_smid(ioc, smid);
772 if (data_in_sz) /* READ */ {
773 data_in = pci_alloc_consistent(ioc->pdev, data_in_sz,
776 pr_err("failure at %s:%d/%s()!\n", __FILE__,
779 mpt3sas_base_free_smid(ioc, smid);
784 psge = (void *)request + (karg.data_sge_offset*4);
786 /* send command to firmware */
787 _ctl_display_some_debug(ioc, smid, "ctl_request", NULL);
789 init_completion(&ioc->ctl_cmds.done);
790 switch (mpi_request->Function) {
791 case MPI2_FUNCTION_SCSI_IO_REQUEST:
792 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
794 Mpi2SCSIIORequest_t *scsiio_request =
795 (Mpi2SCSIIORequest_t *)request;
796 scsiio_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
797 scsiio_request->SenseBufferLowAddress =
798 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
799 memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE);
800 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
801 data_in_dma, data_in_sz);
803 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)
804 mpt3sas_base_put_smid_scsi_io(ioc, smid,
805 le16_to_cpu(mpi_request->FunctionDependent1));
807 mpt3sas_base_put_smid_default(ioc, smid);
810 case MPI2_FUNCTION_SCSI_TASK_MGMT:
812 Mpi2SCSITaskManagementRequest_t *tm_request =
813 (Mpi2SCSITaskManagementRequest_t *)request;
815 dtmprintk(ioc, pr_info(MPT3SAS_FMT
816 "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
818 le16_to_cpu(tm_request->DevHandle), tm_request->TaskType));
820 if (tm_request->TaskType ==
821 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
822 tm_request->TaskType ==
823 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
824 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
825 mpt3sas_base_free_smid(ioc, smid);
830 mpt3sas_scsih_set_tm_flag(ioc, le16_to_cpu(
831 tm_request->DevHandle));
832 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
833 data_in_dma, data_in_sz);
834 mpt3sas_base_put_smid_hi_priority(ioc, smid, 0);
837 case MPI2_FUNCTION_SMP_PASSTHROUGH:
839 Mpi2SmpPassthroughRequest_t *smp_request =
840 (Mpi2SmpPassthroughRequest_t *)mpi_request;
843 /* ioc determines which port to use */
844 smp_request->PhysicalPort = 0xFF;
845 if (smp_request->PassthroughFlags &
846 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
847 data = (u8 *)&smp_request->SGL;
849 if (unlikely(data_out == NULL)) {
850 pr_err("failure at %s:%d/%s()!\n",
851 __FILE__, __LINE__, __func__);
852 mpt3sas_base_free_smid(ioc, smid);
859 if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
860 ioc->ioc_link_reset_in_progress = 1;
861 ioc->ignore_loginfos = 1;
863 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
865 mpt3sas_base_put_smid_default(ioc, smid);
868 case MPI2_FUNCTION_SATA_PASSTHROUGH:
869 case MPI2_FUNCTION_FW_DOWNLOAD:
870 case MPI2_FUNCTION_FW_UPLOAD:
872 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
874 mpt3sas_base_put_smid_default(ioc, smid);
877 case MPI2_FUNCTION_TOOLBOX:
879 Mpi2ToolboxCleanRequest_t *toolbox_request =
880 (Mpi2ToolboxCleanRequest_t *)mpi_request;
882 if (toolbox_request->Tool == MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL) {
883 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
884 data_in_dma, data_in_sz);
886 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
887 data_in_dma, data_in_sz);
889 mpt3sas_base_put_smid_default(ioc, smid);
892 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
894 Mpi2SasIoUnitControlRequest_t *sasiounit_request =
895 (Mpi2SasIoUnitControlRequest_t *)mpi_request;
897 if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET
898 || sasiounit_request->Operation ==
899 MPI2_SAS_OP_PHY_LINK_RESET) {
900 ioc->ioc_link_reset_in_progress = 1;
901 ioc->ignore_loginfos = 1;
903 /* drop to default case for posting the request */
906 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
907 data_in_dma, data_in_sz);
908 mpt3sas_base_put_smid_default(ioc, smid);
912 if (karg.timeout < MPT3_IOCTL_DEFAULT_TIMEOUT)
913 timeout = MPT3_IOCTL_DEFAULT_TIMEOUT;
915 timeout = karg.timeout;
916 wait_for_completion_timeout(&ioc->ctl_cmds.done, timeout*HZ);
917 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
918 Mpi2SCSITaskManagementRequest_t *tm_request =
919 (Mpi2SCSITaskManagementRequest_t *)mpi_request;
920 mpt3sas_scsih_clear_tm_flag(ioc, le16_to_cpu(
921 tm_request->DevHandle));
922 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
923 } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH ||
924 mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) &&
925 ioc->ioc_link_reset_in_progress) {
926 ioc->ioc_link_reset_in_progress = 0;
927 ioc->ignore_loginfos = 0;
929 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
930 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
932 _debug_dump_mf(mpi_request, karg.data_sge_offset);
933 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
935 goto issue_host_reset;
938 mpi_reply = ioc->ctl_cmds.reply;
940 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT &&
941 (ioc->logging_level & MPT_DEBUG_TM)) {
942 Mpi2SCSITaskManagementReply_t *tm_reply =
943 (Mpi2SCSITaskManagementReply_t *)mpi_reply;
945 pr_info(MPT3SAS_FMT "TASK_MGMT: " \
946 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
947 "TerminationCount(0x%08x)\n", ioc->name,
948 le16_to_cpu(tm_reply->IOCStatus),
949 le32_to_cpu(tm_reply->IOCLogInfo),
950 le32_to_cpu(tm_reply->TerminationCount));
953 /* copy out xdata to user */
955 if (copy_to_user(karg.data_in_buf_ptr, data_in,
957 pr_err("failure at %s:%d/%s()!\n", __FILE__,
964 /* copy out reply message frame to user */
965 if (karg.max_reply_bytes) {
966 sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz);
967 if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply,
969 pr_err("failure at %s:%d/%s()!\n", __FILE__,
976 /* copy out sense to user */
977 if (karg.max_sense_bytes && (mpi_request->Function ==
978 MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function ==
979 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
980 sz = min_t(u32, karg.max_sense_bytes, SCSI_SENSE_BUFFERSIZE);
981 if (copy_to_user(karg.sense_data_ptr, ioc->ctl_cmds.sense,
983 pr_err("failure at %s:%d/%s()!\n", __FILE__,
993 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
994 mpi_request->Function ==
995 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
996 mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH)) {
997 pr_info(MPT3SAS_FMT "issue target reset: handle = (0x%04x)\n",
999 le16_to_cpu(mpi_request->FunctionDependent1));
1000 mpt3sas_halt_firmware(ioc);
1001 mpt3sas_scsih_issue_locked_tm(ioc,
1002 le16_to_cpu(mpi_request->FunctionDependent1), 0, 0,
1003 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
1005 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1010 /* free memory associated with sg buffers */
1012 pci_free_consistent(ioc->pdev, data_in_sz, data_in,
1016 pci_free_consistent(ioc->pdev, data_out_sz, data_out,
1020 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1025 * _ctl_getiocinfo - main handler for MPT3IOCINFO opcode
1026 * @ioc: per adapter object
1027 * @arg - user space buffer containing ioctl content
1030 _ctl_getiocinfo(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1032 struct mpt3_ioctl_iocinfo karg;
1034 if (copy_from_user(&karg, arg, sizeof(karg))) {
1035 pr_err("failure at %s:%d/%s()!\n",
1036 __FILE__, __LINE__, __func__);
1040 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1043 memset(&karg, 0 , sizeof(karg));
1045 karg.port_number = ioc->pfacts[0].PortNumber;
1046 karg.hw_rev = ioc->pdev->revision;
1047 karg.pci_id = ioc->pdev->device;
1048 karg.subsystem_device = ioc->pdev->subsystem_device;
1049 karg.subsystem_vendor = ioc->pdev->subsystem_vendor;
1050 karg.pci_information.u.bits.bus = ioc->pdev->bus->number;
1051 karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn);
1052 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
1053 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
1054 karg.firmware_version = ioc->facts.FWVersion.Word;
1055 strcpy(karg.driver_version, ioc->driver_name);
1056 strcat(karg.driver_version, "-");
1057 switch (ioc->hba_mpi_version_belonged) {
1059 if (ioc->is_warpdrive)
1060 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2_SSS6200;
1062 karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2;
1063 strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION);
1067 karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS3;
1068 strcat(karg.driver_version, MPT3SAS_DRIVER_VERSION);
1071 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
1073 if (copy_to_user(arg, &karg, sizeof(karg))) {
1074 pr_err("failure at %s:%d/%s()!\n",
1075 __FILE__, __LINE__, __func__);
1082 * _ctl_eventquery - main handler for MPT3EVENTQUERY opcode
1083 * @ioc: per adapter object
1084 * @arg - user space buffer containing ioctl content
1087 _ctl_eventquery(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1089 struct mpt3_ioctl_eventquery karg;
1091 if (copy_from_user(&karg, arg, sizeof(karg))) {
1092 pr_err("failure at %s:%d/%s()!\n",
1093 __FILE__, __LINE__, __func__);
1097 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1100 karg.event_entries = MPT3SAS_CTL_EVENT_LOG_SIZE;
1101 memcpy(karg.event_types, ioc->event_type,
1102 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1104 if (copy_to_user(arg, &karg, sizeof(karg))) {
1105 pr_err("failure at %s:%d/%s()!\n",
1106 __FILE__, __LINE__, __func__);
1113 * _ctl_eventenable - main handler for MPT3EVENTENABLE opcode
1114 * @ioc: per adapter object
1115 * @arg - user space buffer containing ioctl content
1118 _ctl_eventenable(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1120 struct mpt3_ioctl_eventenable karg;
1122 if (copy_from_user(&karg, arg, sizeof(karg))) {
1123 pr_err("failure at %s:%d/%s()!\n",
1124 __FILE__, __LINE__, __func__);
1128 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1131 memcpy(ioc->event_type, karg.event_types,
1132 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1133 mpt3sas_base_validate_event_type(ioc, ioc->event_type);
1137 /* initialize event_log */
1138 ioc->event_context = 0;
1139 ioc->aen_event_read_flag = 0;
1140 ioc->event_log = kcalloc(MPT3SAS_CTL_EVENT_LOG_SIZE,
1141 sizeof(struct MPT3_IOCTL_EVENTS), GFP_KERNEL);
1142 if (!ioc->event_log) {
1143 pr_err("failure at %s:%d/%s()!\n",
1144 __FILE__, __LINE__, __func__);
1151 * _ctl_eventreport - main handler for MPT3EVENTREPORT opcode
1152 * @ioc: per adapter object
1153 * @arg - user space buffer containing ioctl content
1156 _ctl_eventreport(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1158 struct mpt3_ioctl_eventreport karg;
1159 u32 number_bytes, max_events, max;
1160 struct mpt3_ioctl_eventreport __user *uarg = arg;
1162 if (copy_from_user(&karg, arg, sizeof(karg))) {
1163 pr_err("failure at %s:%d/%s()!\n",
1164 __FILE__, __LINE__, __func__);
1168 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1171 number_bytes = karg.hdr.max_data_size -
1172 sizeof(struct mpt3_ioctl_header);
1173 max_events = number_bytes/sizeof(struct MPT3_IOCTL_EVENTS);
1174 max = min_t(u32, MPT3SAS_CTL_EVENT_LOG_SIZE, max_events);
1176 /* If fewer than 1 event is requested, there must have
1177 * been some type of error.
1179 if (!max || !ioc->event_log)
1182 number_bytes = max * sizeof(struct MPT3_IOCTL_EVENTS);
1183 if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) {
1184 pr_err("failure at %s:%d/%s()!\n",
1185 __FILE__, __LINE__, __func__);
1189 /* reset flag so SIGIO can restart */
1190 ioc->aen_event_read_flag = 0;
1195 * _ctl_do_reset - main handler for MPT3HARDRESET opcode
1196 * @ioc: per adapter object
1197 * @arg - user space buffer containing ioctl content
1200 _ctl_do_reset(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1202 struct mpt3_ioctl_diag_reset karg;
1205 if (copy_from_user(&karg, arg, sizeof(karg))) {
1206 pr_err("failure at %s:%d/%s()!\n",
1207 __FILE__, __LINE__, __func__);
1211 if (ioc->shost_recovery || ioc->pci_error_recovery ||
1212 ioc->is_driver_loading)
1215 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1218 retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1219 pr_info(MPT3SAS_FMT "host reset: %s\n",
1220 ioc->name, ((!retval) ? "SUCCESS" : "FAILED"));
1225 * _ctl_btdh_search_sas_device - searching for sas device
1226 * @ioc: per adapter object
1227 * @btdh: btdh ioctl payload
1230 _ctl_btdh_search_sas_device(struct MPT3SAS_ADAPTER *ioc,
1231 struct mpt3_ioctl_btdh_mapping *btdh)
1233 struct _sas_device *sas_device;
1234 unsigned long flags;
1237 if (list_empty(&ioc->sas_device_list))
1240 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1241 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
1242 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1243 btdh->handle == sas_device->handle) {
1244 btdh->bus = sas_device->channel;
1245 btdh->id = sas_device->id;
1248 } else if (btdh->bus == sas_device->channel && btdh->id ==
1249 sas_device->id && btdh->handle == 0xFFFF) {
1250 btdh->handle = sas_device->handle;
1256 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1261 * _ctl_btdh_search_raid_device - searching for raid device
1262 * @ioc: per adapter object
1263 * @btdh: btdh ioctl payload
1266 _ctl_btdh_search_raid_device(struct MPT3SAS_ADAPTER *ioc,
1267 struct mpt3_ioctl_btdh_mapping *btdh)
1269 struct _raid_device *raid_device;
1270 unsigned long flags;
1273 if (list_empty(&ioc->raid_device_list))
1276 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1277 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1278 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1279 btdh->handle == raid_device->handle) {
1280 btdh->bus = raid_device->channel;
1281 btdh->id = raid_device->id;
1284 } else if (btdh->bus == raid_device->channel && btdh->id ==
1285 raid_device->id && btdh->handle == 0xFFFF) {
1286 btdh->handle = raid_device->handle;
1292 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1297 * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode
1298 * @ioc: per adapter object
1299 * @arg - user space buffer containing ioctl content
1302 _ctl_btdh_mapping(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1304 struct mpt3_ioctl_btdh_mapping karg;
1307 if (copy_from_user(&karg, arg, sizeof(karg))) {
1308 pr_err("failure at %s:%d/%s()!\n",
1309 __FILE__, __LINE__, __func__);
1313 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1316 rc = _ctl_btdh_search_sas_device(ioc, &karg);
1318 _ctl_btdh_search_raid_device(ioc, &karg);
1320 if (copy_to_user(arg, &karg, sizeof(karg))) {
1321 pr_err("failure at %s:%d/%s()!\n",
1322 __FILE__, __LINE__, __func__);
1329 * _ctl_diag_capability - return diag buffer capability
1330 * @ioc: per adapter object
1331 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1333 * returns 1 when diag buffer support is enabled in firmware
1336 _ctl_diag_capability(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type)
1340 switch (buffer_type) {
1341 case MPI2_DIAG_BUF_TYPE_TRACE:
1342 if (ioc->facts.IOCCapabilities &
1343 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER)
1346 case MPI2_DIAG_BUF_TYPE_SNAPSHOT:
1347 if (ioc->facts.IOCCapabilities &
1348 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER)
1351 case MPI2_DIAG_BUF_TYPE_EXTENDED:
1352 if (ioc->facts.IOCCapabilities &
1353 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER)
1362 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1363 * @ioc: per adapter object
1364 * @diag_register: the diag_register struct passed in from user space
1368 _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
1369 struct mpt3_diag_register *diag_register)
1372 void *request_data = NULL;
1373 dma_addr_t request_data_dma;
1374 u32 request_data_sz = 0;
1375 Mpi2DiagBufferPostRequest_t *mpi_request;
1376 Mpi2DiagBufferPostReply_t *mpi_reply;
1383 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1386 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1387 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1389 "%s: failed due to ioc not operational\n",
1390 ioc->name, __func__);
1395 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1396 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
1397 ioc->name, __func__);
1402 buffer_type = diag_register->buffer_type;
1403 if (!_ctl_diag_capability(ioc, buffer_type)) {
1405 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1406 ioc->name, __func__, buffer_type);
1410 if (ioc->diag_buffer_status[buffer_type] &
1411 MPT3_DIAG_BUFFER_IS_REGISTERED) {
1413 "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1414 ioc->name, __func__,
1419 if (diag_register->requested_buffer_size % 4) {
1421 "%s: the requested_buffer_size is not 4 byte aligned\n",
1422 ioc->name, __func__);
1426 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1428 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1429 ioc->name, __func__);
1435 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
1436 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1437 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1438 ioc->ctl_cmds.smid = smid;
1440 request_data = ioc->diag_buffer[buffer_type];
1441 request_data_sz = diag_register->requested_buffer_size;
1442 ioc->unique_id[buffer_type] = diag_register->unique_id;
1443 ioc->diag_buffer_status[buffer_type] = 0;
1444 memcpy(ioc->product_specific[buffer_type],
1445 diag_register->product_specific, MPT3_PRODUCT_SPECIFIC_DWORDS);
1446 ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags;
1449 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1450 if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) {
1451 pci_free_consistent(ioc->pdev,
1452 ioc->diag_buffer_sz[buffer_type],
1453 request_data, request_data_dma);
1454 request_data = NULL;
1458 if (request_data == NULL) {
1459 ioc->diag_buffer_sz[buffer_type] = 0;
1460 ioc->diag_buffer_dma[buffer_type] = 0;
1461 request_data = pci_alloc_consistent(
1462 ioc->pdev, request_data_sz, &request_data_dma);
1463 if (request_data == NULL) {
1464 pr_err(MPT3SAS_FMT "%s: failed allocating memory" \
1465 " for diag buffers, requested size(%d)\n",
1466 ioc->name, __func__, request_data_sz);
1467 mpt3sas_base_free_smid(ioc, smid);
1470 ioc->diag_buffer[buffer_type] = request_data;
1471 ioc->diag_buffer_sz[buffer_type] = request_data_sz;
1472 ioc->diag_buffer_dma[buffer_type] = request_data_dma;
1475 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1476 mpi_request->BufferType = diag_register->buffer_type;
1477 mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags);
1478 mpi_request->BufferAddress = cpu_to_le64(request_data_dma);
1479 mpi_request->BufferLength = cpu_to_le32(request_data_sz);
1480 mpi_request->VF_ID = 0; /* TODO */
1481 mpi_request->VP_ID = 0;
1483 dctlprintk(ioc, pr_info(MPT3SAS_FMT
1484 "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1485 ioc->name, __func__, request_data,
1486 (unsigned long long)request_data_dma,
1487 le32_to_cpu(mpi_request->BufferLength)));
1489 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
1490 mpi_request->ProductSpecific[i] =
1491 cpu_to_le32(ioc->product_specific[buffer_type][i]);
1493 init_completion(&ioc->ctl_cmds.done);
1494 mpt3sas_base_put_smid_default(ioc, smid);
1495 wait_for_completion_timeout(&ioc->ctl_cmds.done,
1496 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
1498 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1499 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
1501 _debug_dump_mf(mpi_request,
1502 sizeof(Mpi2DiagBufferPostRequest_t)/4);
1503 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
1505 goto issue_host_reset;
1508 /* process the completed Reply Message Frame */
1509 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1510 pr_err(MPT3SAS_FMT "%s: no reply message\n",
1511 ioc->name, __func__);
1516 mpi_reply = ioc->ctl_cmds.reply;
1517 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1519 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1520 ioc->diag_buffer_status[buffer_type] |=
1521 MPT3_DIAG_BUFFER_IS_REGISTERED;
1522 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
1523 ioc->name, __func__));
1526 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1527 ioc->name, __func__,
1528 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
1534 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1538 if (rc && request_data)
1539 pci_free_consistent(ioc->pdev, request_data_sz,
1540 request_data, request_data_dma);
1542 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1547 * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time
1548 * @ioc: per adapter object
1549 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1551 * This is called when command line option diag_buffer_enable is enabled
1552 * at driver load time.
1555 mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER *ioc, u8 bits_to_register)
1557 struct mpt3_diag_register diag_register;
1559 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
1561 if (bits_to_register & 1) {
1562 pr_info(MPT3SAS_FMT "registering trace buffer support\n",
1564 ioc->diag_trigger_master.MasterData =
1565 (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET);
1566 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
1567 /* register for 2MB buffers */
1568 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1569 diag_register.unique_id = 0x7075900;
1570 _ctl_diag_register_2(ioc, &diag_register);
1573 if (bits_to_register & 2) {
1574 pr_info(MPT3SAS_FMT "registering snapshot buffer support\n",
1576 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT;
1577 /* register for 2MB buffers */
1578 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1579 diag_register.unique_id = 0x7075901;
1580 _ctl_diag_register_2(ioc, &diag_register);
1583 if (bits_to_register & 4) {
1584 pr_info(MPT3SAS_FMT "registering extended buffer support\n",
1586 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED;
1587 /* register for 2MB buffers */
1588 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1589 diag_register.unique_id = 0x7075901;
1590 _ctl_diag_register_2(ioc, &diag_register);
1595 * _ctl_diag_register - application register with driver
1596 * @ioc: per adapter object
1597 * @arg - user space buffer containing ioctl content
1599 * This will allow the driver to setup any required buffers that will be
1600 * needed by firmware to communicate with the driver.
1603 _ctl_diag_register(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1605 struct mpt3_diag_register karg;
1608 if (copy_from_user(&karg, arg, sizeof(karg))) {
1609 pr_err("failure at %s:%d/%s()!\n",
1610 __FILE__, __LINE__, __func__);
1614 rc = _ctl_diag_register_2(ioc, &karg);
1619 * _ctl_diag_unregister - application unregister with driver
1620 * @ioc: per adapter object
1621 * @arg - user space buffer containing ioctl content
1623 * This will allow the driver to cleanup any memory allocated for diag
1624 * messages and to free up any resources.
1627 _ctl_diag_unregister(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1629 struct mpt3_diag_unregister karg;
1631 dma_addr_t request_data_dma;
1632 u32 request_data_sz;
1635 if (copy_from_user(&karg, arg, sizeof(karg))) {
1636 pr_err("failure at %s:%d/%s()!\n",
1637 __FILE__, __LINE__, __func__);
1641 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1644 buffer_type = karg.unique_id & 0x000000ff;
1645 if (!_ctl_diag_capability(ioc, buffer_type)) {
1647 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1648 ioc->name, __func__, buffer_type);
1652 if ((ioc->diag_buffer_status[buffer_type] &
1653 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1655 "%s: buffer_type(0x%02x) is not registered\n",
1656 ioc->name, __func__, buffer_type);
1659 if ((ioc->diag_buffer_status[buffer_type] &
1660 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
1662 "%s: buffer_type(0x%02x) has not been released\n",
1663 ioc->name, __func__, buffer_type);
1667 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1669 "%s: unique_id(0x%08x) is not registered\n",
1670 ioc->name, __func__, karg.unique_id);
1674 request_data = ioc->diag_buffer[buffer_type];
1675 if (!request_data) {
1677 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1678 ioc->name, __func__, buffer_type);
1682 request_data_sz = ioc->diag_buffer_sz[buffer_type];
1683 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1684 pci_free_consistent(ioc->pdev, request_data_sz,
1685 request_data, request_data_dma);
1686 ioc->diag_buffer[buffer_type] = NULL;
1687 ioc->diag_buffer_status[buffer_type] = 0;
1692 * _ctl_diag_query - query relevant info associated with diag buffers
1693 * @ioc: per adapter object
1694 * @arg - user space buffer containing ioctl content
1696 * The application will send only buffer_type and unique_id. Driver will
1697 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1698 * 0x00, the driver will return info specified by Buffer Type.
1701 _ctl_diag_query(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1703 struct mpt3_diag_query karg;
1708 if (copy_from_user(&karg, arg, sizeof(karg))) {
1709 pr_err("failure at %s:%d/%s()!\n",
1710 __FILE__, __LINE__, __func__);
1714 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1717 karg.application_flags = 0;
1718 buffer_type = karg.buffer_type;
1720 if (!_ctl_diag_capability(ioc, buffer_type)) {
1722 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1723 ioc->name, __func__, buffer_type);
1727 if ((ioc->diag_buffer_status[buffer_type] &
1728 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1730 "%s: buffer_type(0x%02x) is not registered\n",
1731 ioc->name, __func__, buffer_type);
1735 if (karg.unique_id & 0xffffff00) {
1736 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1738 "%s: unique_id(0x%08x) is not registered\n",
1739 ioc->name, __func__, karg.unique_id);
1744 request_data = ioc->diag_buffer[buffer_type];
1745 if (!request_data) {
1747 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
1748 ioc->name, __func__, buffer_type);
1752 if (ioc->diag_buffer_status[buffer_type] & MPT3_DIAG_BUFFER_IS_RELEASED)
1753 karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1754 MPT3_APP_FLAGS_BUFFER_VALID);
1756 karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1757 MPT3_APP_FLAGS_BUFFER_VALID |
1758 MPT3_APP_FLAGS_FW_BUFFER_ACCESS);
1760 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
1761 karg.product_specific[i] =
1762 ioc->product_specific[buffer_type][i];
1764 karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type];
1765 karg.driver_added_buffer_size = 0;
1766 karg.unique_id = ioc->unique_id[buffer_type];
1767 karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type];
1769 if (copy_to_user(arg, &karg, sizeof(struct mpt3_diag_query))) {
1771 "%s: unable to write mpt3_diag_query data @ %p\n",
1772 ioc->name, __func__, arg);
1779 * mpt3sas_send_diag_release - Diag Release Message
1780 * @ioc: per adapter object
1781 * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
1782 * @issue_reset - specifies whether host reset is required.
1786 mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type,
1789 Mpi2DiagReleaseRequest_t *mpi_request;
1790 Mpi2DiagReleaseReply_t *mpi_reply;
1796 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1802 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1803 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1804 if (ioc->diag_buffer_status[buffer_type] &
1805 MPT3_DIAG_BUFFER_IS_REGISTERED)
1806 ioc->diag_buffer_status[buffer_type] |=
1807 MPT3_DIAG_BUFFER_IS_RELEASED;
1808 dctlprintk(ioc, pr_info(MPT3SAS_FMT
1809 "%s: skipping due to FAULT state\n", ioc->name,
1815 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1816 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
1817 ioc->name, __func__);
1822 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1824 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1825 ioc->name, __func__);
1830 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
1831 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1832 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1833 ioc->ctl_cmds.smid = smid;
1835 mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE;
1836 mpi_request->BufferType = buffer_type;
1837 mpi_request->VF_ID = 0; /* TODO */
1838 mpi_request->VP_ID = 0;
1840 init_completion(&ioc->ctl_cmds.done);
1841 mpt3sas_base_put_smid_default(ioc, smid);
1842 wait_for_completion_timeout(&ioc->ctl_cmds.done,
1843 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
1845 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1846 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
1848 _debug_dump_mf(mpi_request,
1849 sizeof(Mpi2DiagReleaseRequest_t)/4);
1850 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
1856 /* process the completed Reply Message Frame */
1857 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1858 pr_err(MPT3SAS_FMT "%s: no reply message\n",
1859 ioc->name, __func__);
1864 mpi_reply = ioc->ctl_cmds.reply;
1865 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1867 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1868 ioc->diag_buffer_status[buffer_type] |=
1869 MPT3_DIAG_BUFFER_IS_RELEASED;
1870 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
1871 ioc->name, __func__));
1874 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1875 ioc->name, __func__,
1876 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
1881 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1886 * _ctl_diag_release - request to send Diag Release Message to firmware
1887 * @arg - user space buffer containing ioctl content
1889 * This allows ownership of the specified buffer to returned to the driver,
1890 * allowing an application to read the buffer without fear that firmware is
1891 * overwritting information in the buffer.
1894 _ctl_diag_release(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1896 struct mpt3_diag_release karg;
1902 if (copy_from_user(&karg, arg, sizeof(karg))) {
1903 pr_err("failure at %s:%d/%s()!\n",
1904 __FILE__, __LINE__, __func__);
1908 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1911 buffer_type = karg.unique_id & 0x000000ff;
1912 if (!_ctl_diag_capability(ioc, buffer_type)) {
1914 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1915 ioc->name, __func__, buffer_type);
1919 if ((ioc->diag_buffer_status[buffer_type] &
1920 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1922 "%s: buffer_type(0x%02x) is not registered\n",
1923 ioc->name, __func__, buffer_type);
1927 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1929 "%s: unique_id(0x%08x) is not registered\n",
1930 ioc->name, __func__, karg.unique_id);
1934 if (ioc->diag_buffer_status[buffer_type] &
1935 MPT3_DIAG_BUFFER_IS_RELEASED) {
1937 "%s: buffer_type(0x%02x) is already released\n",
1938 ioc->name, __func__,
1943 request_data = ioc->diag_buffer[buffer_type];
1945 if (!request_data) {
1947 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1948 ioc->name, __func__, buffer_type);
1952 /* buffers were released by due to host reset */
1953 if ((ioc->diag_buffer_status[buffer_type] &
1954 MPT3_DIAG_BUFFER_IS_DIAG_RESET)) {
1955 ioc->diag_buffer_status[buffer_type] |=
1956 MPT3_DIAG_BUFFER_IS_RELEASED;
1957 ioc->diag_buffer_status[buffer_type] &=
1958 ~MPT3_DIAG_BUFFER_IS_DIAG_RESET;
1960 "%s: buffer_type(0x%02x) was released due to host reset\n",
1961 ioc->name, __func__, buffer_type);
1965 rc = mpt3sas_send_diag_release(ioc, buffer_type, &issue_reset);
1968 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
1974 * _ctl_diag_read_buffer - request for copy of the diag buffer
1975 * @ioc: per adapter object
1976 * @arg - user space buffer containing ioctl content
1979 _ctl_diag_read_buffer(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1981 struct mpt3_diag_read_buffer karg;
1982 struct mpt3_diag_read_buffer __user *uarg = arg;
1983 void *request_data, *diag_data;
1984 Mpi2DiagBufferPostRequest_t *mpi_request;
1985 Mpi2DiagBufferPostReply_t *mpi_reply;
1988 unsigned long request_size, copy_size;
1993 if (copy_from_user(&karg, arg, sizeof(karg))) {
1994 pr_err("failure at %s:%d/%s()!\n",
1995 __FILE__, __LINE__, __func__);
1999 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
2002 buffer_type = karg.unique_id & 0x000000ff;
2003 if (!_ctl_diag_capability(ioc, buffer_type)) {
2005 "%s: doesn't have capability for buffer_type(0x%02x)\n",
2006 ioc->name, __func__, buffer_type);
2010 if (karg.unique_id != ioc->unique_id[buffer_type]) {
2012 "%s: unique_id(0x%08x) is not registered\n",
2013 ioc->name, __func__, karg.unique_id);
2017 request_data = ioc->diag_buffer[buffer_type];
2018 if (!request_data) {
2020 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2021 ioc->name, __func__, buffer_type);
2025 request_size = ioc->diag_buffer_sz[buffer_type];
2027 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
2028 pr_err(MPT3SAS_FMT "%s: either the starting_offset " \
2029 "or bytes_to_read are not 4 byte aligned\n", ioc->name,
2034 if (karg.starting_offset > request_size)
2037 diag_data = (void *)(request_data + karg.starting_offset);
2038 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2039 "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2040 ioc->name, __func__,
2041 diag_data, karg.starting_offset, karg.bytes_to_read));
2043 /* Truncate data on requests that are too large */
2044 if ((diag_data + karg.bytes_to_read < diag_data) ||
2045 (diag_data + karg.bytes_to_read > request_data + request_size))
2046 copy_size = request_size - karg.starting_offset;
2048 copy_size = karg.bytes_to_read;
2050 if (copy_to_user((void __user *)uarg->diagnostic_data,
2051 diag_data, copy_size)) {
2053 "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2054 ioc->name, __func__, diag_data);
2058 if ((karg.flags & MPT3_FLAGS_REREGISTER) == 0)
2061 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2062 "%s: Reregister buffer_type(0x%02x)\n",
2063 ioc->name, __func__, buffer_type));
2064 if ((ioc->diag_buffer_status[buffer_type] &
2065 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
2066 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2067 "%s: buffer_type(0x%02x) is still registered\n",
2068 ioc->name, __func__, buffer_type));
2071 /* Get a free request frame and save the message context.
2074 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
2075 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
2076 ioc->name, __func__);
2081 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
2083 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2084 ioc->name, __func__);
2090 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
2091 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
2092 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2093 ioc->ctl_cmds.smid = smid;
2095 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
2096 mpi_request->BufferType = buffer_type;
2097 mpi_request->BufferLength =
2098 cpu_to_le32(ioc->diag_buffer_sz[buffer_type]);
2099 mpi_request->BufferAddress =
2100 cpu_to_le64(ioc->diag_buffer_dma[buffer_type]);
2101 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
2102 mpi_request->ProductSpecific[i] =
2103 cpu_to_le32(ioc->product_specific[buffer_type][i]);
2104 mpi_request->VF_ID = 0; /* TODO */
2105 mpi_request->VP_ID = 0;
2107 init_completion(&ioc->ctl_cmds.done);
2108 mpt3sas_base_put_smid_default(ioc, smid);
2109 wait_for_completion_timeout(&ioc->ctl_cmds.done,
2110 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
2112 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
2113 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
2115 _debug_dump_mf(mpi_request,
2116 sizeof(Mpi2DiagBufferPostRequest_t)/4);
2117 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
2119 goto issue_host_reset;
2122 /* process the completed Reply Message Frame */
2123 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
2124 pr_err(MPT3SAS_FMT "%s: no reply message\n",
2125 ioc->name, __func__);
2130 mpi_reply = ioc->ctl_cmds.reply;
2131 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
2133 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
2134 ioc->diag_buffer_status[buffer_type] |=
2135 MPT3_DIAG_BUFFER_IS_REGISTERED;
2136 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
2137 ioc->name, __func__));
2140 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2141 ioc->name, __func__,
2142 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
2148 mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
2152 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
2158 #ifdef CONFIG_COMPAT
2160 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2161 * @ioc: per adapter object
2162 * @cmd - ioctl opcode
2163 * @arg - (struct mpt3_ioctl_command32)
2165 * MPT3COMMAND32 - Handle 32bit applications running on 64bit os.
2168 _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER *ioc, unsigned cmd,
2171 struct mpt3_ioctl_command32 karg32;
2172 struct mpt3_ioctl_command32 __user *uarg;
2173 struct mpt3_ioctl_command karg;
2175 if (_IOC_SIZE(cmd) != sizeof(struct mpt3_ioctl_command32))
2178 uarg = (struct mpt3_ioctl_command32 __user *) arg;
2180 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) {
2181 pr_err("failure at %s:%d/%s()!\n",
2182 __FILE__, __LINE__, __func__);
2186 memset(&karg, 0, sizeof(struct mpt3_ioctl_command));
2187 karg.hdr.ioc_number = karg32.hdr.ioc_number;
2188 karg.hdr.port_number = karg32.hdr.port_number;
2189 karg.hdr.max_data_size = karg32.hdr.max_data_size;
2190 karg.timeout = karg32.timeout;
2191 karg.max_reply_bytes = karg32.max_reply_bytes;
2192 karg.data_in_size = karg32.data_in_size;
2193 karg.data_out_size = karg32.data_out_size;
2194 karg.max_sense_bytes = karg32.max_sense_bytes;
2195 karg.data_sge_offset = karg32.data_sge_offset;
2196 karg.reply_frame_buf_ptr = compat_ptr(karg32.reply_frame_buf_ptr);
2197 karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr);
2198 karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr);
2199 karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr);
2200 return _ctl_do_mpt_command(ioc, karg, &uarg->mf);
2205 * _ctl_ioctl_main - main ioctl entry point
2206 * @file - (struct file)
2207 * @cmd - ioctl opcode
2208 * @arg - user space data buffer
2209 * @compat - handles 32 bit applications in 64bit os
2210 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
2211 * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
2214 _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
2215 u8 compat, u16 mpi_version)
2217 struct MPT3SAS_ADAPTER *ioc;
2218 struct mpt3_ioctl_header ioctl_header;
2219 enum block_state state;
2222 /* get IOCTL header */
2223 if (copy_from_user(&ioctl_header, (char __user *)arg,
2224 sizeof(struct mpt3_ioctl_header))) {
2225 pr_err("failure at %s:%d/%s()!\n",
2226 __FILE__, __LINE__, __func__);
2230 if (_ctl_verify_adapter(ioctl_header.ioc_number,
2231 &ioc, mpi_version) == -1 || !ioc)
2234 /* pci_access_mutex lock acquired by ioctl path */
2235 mutex_lock(&ioc->pci_access_mutex);
2237 if (ioc->shost_recovery || ioc->pci_error_recovery ||
2238 ioc->is_driver_loading || ioc->remove_host) {
2240 goto out_unlock_pciaccess;
2243 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
2244 if (state == NON_BLOCKING) {
2245 if (!mutex_trylock(&ioc->ctl_cmds.mutex)) {
2247 goto out_unlock_pciaccess;
2249 } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) {
2251 goto out_unlock_pciaccess;
2257 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_iocinfo))
2258 ret = _ctl_getiocinfo(ioc, arg);
2260 #ifdef CONFIG_COMPAT
2265 struct mpt3_ioctl_command __user *uarg;
2266 struct mpt3_ioctl_command karg;
2268 #ifdef CONFIG_COMPAT
2270 ret = _ctl_compat_mpt_command(ioc, cmd, arg);
2274 if (copy_from_user(&karg, arg, sizeof(karg))) {
2275 pr_err("failure at %s:%d/%s()!\n",
2276 __FILE__, __LINE__, __func__);
2281 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_command)) {
2283 ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf);
2287 case MPT3EVENTQUERY:
2288 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventquery))
2289 ret = _ctl_eventquery(ioc, arg);
2291 case MPT3EVENTENABLE:
2292 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventenable))
2293 ret = _ctl_eventenable(ioc, arg);
2295 case MPT3EVENTREPORT:
2296 ret = _ctl_eventreport(ioc, arg);
2299 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_diag_reset))
2300 ret = _ctl_do_reset(ioc, arg);
2302 case MPT3BTDHMAPPING:
2303 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_btdh_mapping))
2304 ret = _ctl_btdh_mapping(ioc, arg);
2306 case MPT3DIAGREGISTER:
2307 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_register))
2308 ret = _ctl_diag_register(ioc, arg);
2310 case MPT3DIAGUNREGISTER:
2311 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_unregister))
2312 ret = _ctl_diag_unregister(ioc, arg);
2315 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_query))
2316 ret = _ctl_diag_query(ioc, arg);
2318 case MPT3DIAGRELEASE:
2319 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_release))
2320 ret = _ctl_diag_release(ioc, arg);
2322 case MPT3DIAGREADBUFFER:
2323 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_read_buffer))
2324 ret = _ctl_diag_read_buffer(ioc, arg);
2327 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2328 "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd));
2332 mutex_unlock(&ioc->ctl_cmds.mutex);
2333 out_unlock_pciaccess:
2334 mutex_unlock(&ioc->pci_access_mutex);
2339 * _ctl_ioctl - mpt3ctl main ioctl entry point (unlocked)
2340 * @file - (struct file)
2341 * @cmd - ioctl opcode
2345 _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2349 /* pass MPI25_VERSION | MPI26_VERSION value,
2350 * to indicate that this ioctl cmd
2351 * came from mpt3ctl ioctl device.
2353 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0,
2354 MPI25_VERSION | MPI26_VERSION);
2359 * _ctl_mpt2_ioctl - mpt2ctl main ioctl entry point (unlocked)
2360 * @file - (struct file)
2361 * @cmd - ioctl opcode
2365 _ctl_mpt2_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2369 /* pass MPI2_VERSION value, to indicate that this ioctl cmd
2370 * came from mpt2ctl ioctl device.
2372 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0, MPI2_VERSION);
2375 #ifdef CONFIG_COMPAT
2377 *_ ctl_ioctl_compat - main ioctl entry point (compat)
2382 * This routine handles 32 bit applications in 64bit os.
2385 _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2389 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1,
2390 MPI25_VERSION | MPI26_VERSION);
2395 *_ ctl_mpt2_ioctl_compat - main ioctl entry point (compat)
2400 * This routine handles 32 bit applications in 64bit os.
2403 _ctl_mpt2_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2407 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1, MPI2_VERSION);
2412 /* scsi host attributes */
2414 * _ctl_version_fw_show - firmware version
2415 * @cdev - pointer to embedded class device
2416 * @buf - the buffer returned
2418 * A sysfs 'read-only' shost attribute.
2421 _ctl_version_fw_show(struct device *cdev, struct device_attribute *attr,
2424 struct Scsi_Host *shost = class_to_shost(cdev);
2425 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2427 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2428 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2429 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2430 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2431 ioc->facts.FWVersion.Word & 0x000000FF);
2433 static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL);
2436 * _ctl_version_bios_show - bios version
2437 * @cdev - pointer to embedded class device
2438 * @buf - the buffer returned
2440 * A sysfs 'read-only' shost attribute.
2443 _ctl_version_bios_show(struct device *cdev, struct device_attribute *attr,
2446 struct Scsi_Host *shost = class_to_shost(cdev);
2447 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2449 u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2451 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2452 (version & 0xFF000000) >> 24,
2453 (version & 0x00FF0000) >> 16,
2454 (version & 0x0000FF00) >> 8,
2455 version & 0x000000FF);
2457 static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL);
2460 * _ctl_version_mpi_show - MPI (message passing interface) version
2461 * @cdev - pointer to embedded class device
2462 * @buf - the buffer returned
2464 * A sysfs 'read-only' shost attribute.
2467 _ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr,
2470 struct Scsi_Host *shost = class_to_shost(cdev);
2471 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2473 return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
2474 ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
2476 static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL);
2479 * _ctl_version_product_show - product name
2480 * @cdev - pointer to embedded class device
2481 * @buf - the buffer returned
2483 * A sysfs 'read-only' shost attribute.
2486 _ctl_version_product_show(struct device *cdev, struct device_attribute *attr,
2489 struct Scsi_Host *shost = class_to_shost(cdev);
2490 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2492 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
2494 static DEVICE_ATTR(version_product, S_IRUGO, _ctl_version_product_show, NULL);
2497 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2498 * @cdev - pointer to embedded class device
2499 * @buf - the buffer returned
2501 * A sysfs 'read-only' shost attribute.
2504 _ctl_version_nvdata_persistent_show(struct device *cdev,
2505 struct device_attribute *attr, char *buf)
2507 struct Scsi_Host *shost = class_to_shost(cdev);
2508 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2510 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2511 le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
2513 static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
2514 _ctl_version_nvdata_persistent_show, NULL);
2517 * _ctl_version_nvdata_default_show - nvdata default version
2518 * @cdev - pointer to embedded class device
2519 * @buf - the buffer returned
2521 * A sysfs 'read-only' shost attribute.
2524 _ctl_version_nvdata_default_show(struct device *cdev, struct device_attribute
2527 struct Scsi_Host *shost = class_to_shost(cdev);
2528 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2530 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2531 le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
2533 static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
2534 _ctl_version_nvdata_default_show, NULL);
2537 * _ctl_board_name_show - board name
2538 * @cdev - pointer to embedded class device
2539 * @buf - the buffer returned
2541 * A sysfs 'read-only' shost attribute.
2544 _ctl_board_name_show(struct device *cdev, struct device_attribute *attr,
2547 struct Scsi_Host *shost = class_to_shost(cdev);
2548 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2550 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
2552 static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL);
2555 * _ctl_board_assembly_show - board assembly name
2556 * @cdev - pointer to embedded class device
2557 * @buf - the buffer returned
2559 * A sysfs 'read-only' shost attribute.
2562 _ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr,
2565 struct Scsi_Host *shost = class_to_shost(cdev);
2566 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2568 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
2570 static DEVICE_ATTR(board_assembly, S_IRUGO, _ctl_board_assembly_show, NULL);
2573 * _ctl_board_tracer_show - board tracer number
2574 * @cdev - pointer to embedded class device
2575 * @buf - the buffer returned
2577 * A sysfs 'read-only' shost attribute.
2580 _ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr,
2583 struct Scsi_Host *shost = class_to_shost(cdev);
2584 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2586 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
2588 static DEVICE_ATTR(board_tracer, S_IRUGO, _ctl_board_tracer_show, NULL);
2591 * _ctl_io_delay_show - io missing delay
2592 * @cdev - pointer to embedded class device
2593 * @buf - the buffer returned
2595 * This is for firmware implemention for deboucing device
2598 * A sysfs 'read-only' shost attribute.
2601 _ctl_io_delay_show(struct device *cdev, struct device_attribute *attr,
2604 struct Scsi_Host *shost = class_to_shost(cdev);
2605 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2607 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
2609 static DEVICE_ATTR(io_delay, S_IRUGO, _ctl_io_delay_show, NULL);
2612 * _ctl_device_delay_show - device missing delay
2613 * @cdev - pointer to embedded class device
2614 * @buf - the buffer returned
2616 * This is for firmware implemention for deboucing device
2619 * A sysfs 'read-only' shost attribute.
2622 _ctl_device_delay_show(struct device *cdev, struct device_attribute *attr,
2625 struct Scsi_Host *shost = class_to_shost(cdev);
2626 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2628 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
2630 static DEVICE_ATTR(device_delay, S_IRUGO, _ctl_device_delay_show, NULL);
2633 * _ctl_fw_queue_depth_show - global credits
2634 * @cdev - pointer to embedded class device
2635 * @buf - the buffer returned
2637 * This is firmware queue depth limit
2639 * A sysfs 'read-only' shost attribute.
2642 _ctl_fw_queue_depth_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, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
2650 static DEVICE_ATTR(fw_queue_depth, S_IRUGO, _ctl_fw_queue_depth_show, NULL);
2653 * _ctl_sas_address_show - sas address
2654 * @cdev - pointer to embedded class device
2655 * @buf - the buffer returned
2657 * This is the controller sas address
2659 * A sysfs 'read-only' shost attribute.
2662 _ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr,
2666 struct Scsi_Host *shost = class_to_shost(cdev);
2667 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2669 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
2670 (unsigned long long)ioc->sas_hba.sas_address);
2672 static DEVICE_ATTR(host_sas_address, S_IRUGO,
2673 _ctl_host_sas_address_show, NULL);
2676 * _ctl_logging_level_show - logging level
2677 * @cdev - pointer to embedded class device
2678 * @buf - the buffer returned
2680 * A sysfs 'read/write' shost attribute.
2683 _ctl_logging_level_show(struct device *cdev, struct device_attribute *attr,
2686 struct Scsi_Host *shost = class_to_shost(cdev);
2687 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2689 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
2692 _ctl_logging_level_store(struct device *cdev, struct device_attribute *attr,
2693 const char *buf, size_t count)
2695 struct Scsi_Host *shost = class_to_shost(cdev);
2696 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2699 if (sscanf(buf, "%x", &val) != 1)
2702 ioc->logging_level = val;
2703 pr_info(MPT3SAS_FMT "logging_level=%08xh\n", ioc->name,
2704 ioc->logging_level);
2707 static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR, _ctl_logging_level_show,
2708 _ctl_logging_level_store);
2711 * _ctl_fwfault_debug_show - show/store fwfault_debug
2712 * @cdev - pointer to embedded class device
2713 * @buf - the buffer returned
2715 * mpt3sas_fwfault_debug is command line option
2716 * A sysfs 'read/write' shost attribute.
2719 _ctl_fwfault_debug_show(struct device *cdev, struct device_attribute *attr,
2722 struct Scsi_Host *shost = class_to_shost(cdev);
2723 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2725 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
2728 _ctl_fwfault_debug_store(struct device *cdev, struct device_attribute *attr,
2729 const char *buf, size_t count)
2731 struct Scsi_Host *shost = class_to_shost(cdev);
2732 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2735 if (sscanf(buf, "%d", &val) != 1)
2738 ioc->fwfault_debug = val;
2739 pr_info(MPT3SAS_FMT "fwfault_debug=%d\n", ioc->name,
2740 ioc->fwfault_debug);
2743 static DEVICE_ATTR(fwfault_debug, S_IRUGO | S_IWUSR,
2744 _ctl_fwfault_debug_show, _ctl_fwfault_debug_store);
2747 * _ctl_ioc_reset_count_show - ioc reset count
2748 * @cdev - pointer to embedded class device
2749 * @buf - the buffer returned
2751 * This is firmware queue depth limit
2753 * A sysfs 'read-only' shost attribute.
2756 _ctl_ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
2759 struct Scsi_Host *shost = class_to_shost(cdev);
2760 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2762 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->ioc_reset_count);
2764 static DEVICE_ATTR(ioc_reset_count, S_IRUGO, _ctl_ioc_reset_count_show, NULL);
2767 * _ctl_ioc_reply_queue_count_show - number of reply queues
2768 * @cdev - pointer to embedded class device
2769 * @buf - the buffer returned
2771 * This is number of reply queues
2773 * A sysfs 'read-only' shost attribute.
2776 _ctl_ioc_reply_queue_count_show(struct device *cdev,
2777 struct device_attribute *attr, char *buf)
2779 u8 reply_queue_count;
2780 struct Scsi_Host *shost = class_to_shost(cdev);
2781 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2783 if ((ioc->facts.IOCCapabilities &
2784 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable)
2785 reply_queue_count = ioc->reply_queue_count;
2787 reply_queue_count = 1;
2789 return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count);
2791 static DEVICE_ATTR(reply_queue_count, S_IRUGO, _ctl_ioc_reply_queue_count_show,
2795 * _ctl_BRM_status_show - Backup Rail Monitor Status
2796 * @cdev - pointer to embedded class device
2797 * @buf - the buffer returned
2799 * This is number of reply queues
2801 * A sysfs 'read-only' shost attribute.
2804 _ctl_BRM_status_show(struct device *cdev, struct device_attribute *attr,
2807 struct Scsi_Host *shost = class_to_shost(cdev);
2808 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2809 Mpi2IOUnitPage3_t *io_unit_pg3 = NULL;
2810 Mpi2ConfigReply_t mpi_reply;
2811 u16 backup_rail_monitor_status = 0;
2816 if (!ioc->is_warpdrive) {
2817 pr_err(MPT3SAS_FMT "%s: BRM attribute is only for"
2818 " warpdrive\n", ioc->name, __func__);
2821 /* pci_access_mutex lock acquired by sysfs show path */
2822 mutex_lock(&ioc->pci_access_mutex);
2823 if (ioc->pci_error_recovery || ioc->remove_host) {
2824 mutex_unlock(&ioc->pci_access_mutex);
2828 /* allocate upto GPIOVal 36 entries */
2829 sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36);
2830 io_unit_pg3 = kzalloc(sz, GFP_KERNEL);
2832 pr_err(MPT3SAS_FMT "%s: failed allocating memory "
2833 "for iounit_pg3: (%d) bytes\n", ioc->name, __func__, sz);
2837 if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) !=
2840 "%s: failed reading iounit_pg3\n", ioc->name,
2845 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
2846 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2847 pr_err(MPT3SAS_FMT "%s: iounit_pg3 failed with "
2848 "ioc_status(0x%04x)\n", ioc->name, __func__, ioc_status);
2852 if (io_unit_pg3->GPIOCount < 25) {
2853 pr_err(MPT3SAS_FMT "%s: iounit_pg3->GPIOCount less than "
2854 "25 entries, detected (%d) entries\n", ioc->name, __func__,
2855 io_unit_pg3->GPIOCount);
2859 /* BRM status is in bit zero of GPIOVal[24] */
2860 backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]);
2861 rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1));
2865 mutex_unlock(&ioc->pci_access_mutex);
2868 static DEVICE_ATTR(BRM_status, S_IRUGO, _ctl_BRM_status_show, NULL);
2870 struct DIAG_BUFFER_START {
2881 * _ctl_host_trace_buffer_size_show - host buffer size (trace only)
2882 * @cdev - pointer to embedded class device
2883 * @buf - the buffer returned
2885 * A sysfs 'read-only' shost attribute.
2888 _ctl_host_trace_buffer_size_show(struct device *cdev,
2889 struct device_attribute *attr, char *buf)
2891 struct Scsi_Host *shost = class_to_shost(cdev);
2892 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2894 struct DIAG_BUFFER_START *request_data;
2896 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
2898 "%s: host_trace_buffer is not registered\n",
2899 ioc->name, __func__);
2903 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2904 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
2906 "%s: host_trace_buffer is not registered\n",
2907 ioc->name, __func__);
2911 request_data = (struct DIAG_BUFFER_START *)
2912 ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE];
2913 if ((le32_to_cpu(request_data->DiagVersion) == 0x00000000 ||
2914 le32_to_cpu(request_data->DiagVersion) == 0x01000000 ||
2915 le32_to_cpu(request_data->DiagVersion) == 0x01010000) &&
2916 le32_to_cpu(request_data->Reserved3) == 0x4742444c)
2917 size = le32_to_cpu(request_data->Size);
2919 ioc->ring_buffer_sz = size;
2920 return snprintf(buf, PAGE_SIZE, "%d\n", size);
2922 static DEVICE_ATTR(host_trace_buffer_size, S_IRUGO,
2923 _ctl_host_trace_buffer_size_show, NULL);
2926 * _ctl_host_trace_buffer_show - firmware ring buffer (trace only)
2927 * @cdev - pointer to embedded class device
2928 * @buf - the buffer returned
2930 * A sysfs 'read/write' shost attribute.
2932 * You will only be able to read 4k bytes of ring buffer at a time.
2933 * In order to read beyond 4k bytes, you will have to write out the
2934 * offset to the same attribute, it will move the pointer.
2937 _ctl_host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
2940 struct Scsi_Host *shost = class_to_shost(cdev);
2941 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2945 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
2947 "%s: host_trace_buffer is not registered\n",
2948 ioc->name, __func__);
2952 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2953 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
2955 "%s: host_trace_buffer is not registered\n",
2956 ioc->name, __func__);
2960 if (ioc->ring_buffer_offset > ioc->ring_buffer_sz)
2963 size = ioc->ring_buffer_sz - ioc->ring_buffer_offset;
2964 size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size;
2965 request_data = ioc->diag_buffer[0] + ioc->ring_buffer_offset;
2966 memcpy(buf, request_data, size);
2971 _ctl_host_trace_buffer_store(struct device *cdev, struct device_attribute *attr,
2972 const char *buf, size_t count)
2974 struct Scsi_Host *shost = class_to_shost(cdev);
2975 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2978 if (sscanf(buf, "%d", &val) != 1)
2981 ioc->ring_buffer_offset = val;
2984 static DEVICE_ATTR(host_trace_buffer, S_IRUGO | S_IWUSR,
2985 _ctl_host_trace_buffer_show, _ctl_host_trace_buffer_store);
2988 /*****************************************/
2991 * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only)
2992 * @cdev - pointer to embedded class device
2993 * @buf - the buffer returned
2995 * A sysfs 'read/write' shost attribute.
2997 * This is a mechnism to post/release host_trace_buffers
3000 _ctl_host_trace_buffer_enable_show(struct device *cdev,
3001 struct device_attribute *attr, char *buf)
3003 struct Scsi_Host *shost = class_to_shost(cdev);
3004 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3006 if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) ||
3007 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3008 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0))
3009 return snprintf(buf, PAGE_SIZE, "off\n");
3010 else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3011 MPT3_DIAG_BUFFER_IS_RELEASED))
3012 return snprintf(buf, PAGE_SIZE, "release\n");
3014 return snprintf(buf, PAGE_SIZE, "post\n");
3018 _ctl_host_trace_buffer_enable_store(struct device *cdev,
3019 struct device_attribute *attr, const char *buf, size_t count)
3021 struct Scsi_Host *shost = class_to_shost(cdev);
3022 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3024 struct mpt3_diag_register diag_register;
3027 /* don't allow post/release occurr while recovery is active */
3028 if (ioc->shost_recovery || ioc->remove_host ||
3029 ioc->pci_error_recovery || ioc->is_driver_loading)
3032 if (sscanf(buf, "%9s", str) != 1)
3035 if (!strcmp(str, "post")) {
3036 /* exit out if host buffers are already posted */
3037 if ((ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) &&
3038 (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3039 MPT3_DIAG_BUFFER_IS_REGISTERED) &&
3040 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3041 MPT3_DIAG_BUFFER_IS_RELEASED) == 0))
3043 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
3044 pr_info(MPT3SAS_FMT "posting host trace buffers\n",
3046 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
3047 diag_register.requested_buffer_size = (1024 * 1024);
3048 diag_register.unique_id = 0x7075900;
3049 ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] = 0;
3050 _ctl_diag_register_2(ioc, &diag_register);
3051 } else if (!strcmp(str, "release")) {
3052 /* exit out if host buffers are already released */
3053 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE])
3055 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3056 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0)
3058 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
3059 MPT3_DIAG_BUFFER_IS_RELEASED))
3061 pr_info(MPT3SAS_FMT "releasing host trace buffer\n",
3063 mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE,
3070 static DEVICE_ATTR(host_trace_buffer_enable, S_IRUGO | S_IWUSR,
3071 _ctl_host_trace_buffer_enable_show,
3072 _ctl_host_trace_buffer_enable_store);
3074 /*********** diagnostic trigger suppport *********************************/
3077 * _ctl_diag_trigger_master_show - show the diag_trigger_master attribute
3078 * @cdev - pointer to embedded class device
3079 * @buf - the buffer returned
3081 * A sysfs 'read/write' shost attribute.
3084 _ctl_diag_trigger_master_show(struct device *cdev,
3085 struct device_attribute *attr, char *buf)
3088 struct Scsi_Host *shost = class_to_shost(cdev);
3089 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3090 unsigned long flags;
3093 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3094 rc = sizeof(struct SL_WH_MASTER_TRIGGER_T);
3095 memcpy(buf, &ioc->diag_trigger_master, rc);
3096 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3101 * _ctl_diag_trigger_master_store - store the diag_trigger_master attribute
3102 * @cdev - pointer to embedded class device
3103 * @buf - the buffer returned
3105 * A sysfs 'read/write' shost attribute.
3108 _ctl_diag_trigger_master_store(struct device *cdev,
3109 struct device_attribute *attr, const char *buf, size_t count)
3112 struct Scsi_Host *shost = class_to_shost(cdev);
3113 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3114 unsigned long flags;
3117 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3118 rc = min(sizeof(struct SL_WH_MASTER_TRIGGER_T), count);
3119 memset(&ioc->diag_trigger_master, 0,
3120 sizeof(struct SL_WH_MASTER_TRIGGER_T));
3121 memcpy(&ioc->diag_trigger_master, buf, rc);
3122 ioc->diag_trigger_master.MasterData |=
3123 (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET);
3124 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3127 static DEVICE_ATTR(diag_trigger_master, S_IRUGO | S_IWUSR,
3128 _ctl_diag_trigger_master_show, _ctl_diag_trigger_master_store);
3132 * _ctl_diag_trigger_event_show - show the diag_trigger_event attribute
3133 * @cdev - pointer to embedded class device
3134 * @buf - the buffer returned
3136 * A sysfs 'read/write' shost attribute.
3139 _ctl_diag_trigger_event_show(struct device *cdev,
3140 struct device_attribute *attr, char *buf)
3142 struct Scsi_Host *shost = class_to_shost(cdev);
3143 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3144 unsigned long flags;
3147 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3148 rc = sizeof(struct SL_WH_EVENT_TRIGGERS_T);
3149 memcpy(buf, &ioc->diag_trigger_event, rc);
3150 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3155 * _ctl_diag_trigger_event_store - store the diag_trigger_event attribute
3156 * @cdev - pointer to embedded class device
3157 * @buf - the buffer returned
3159 * A sysfs 'read/write' shost attribute.
3162 _ctl_diag_trigger_event_store(struct device *cdev,
3163 struct device_attribute *attr, const char *buf, size_t count)
3166 struct Scsi_Host *shost = class_to_shost(cdev);
3167 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3168 unsigned long flags;
3171 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3172 sz = min(sizeof(struct SL_WH_EVENT_TRIGGERS_T), count);
3173 memset(&ioc->diag_trigger_event, 0,
3174 sizeof(struct SL_WH_EVENT_TRIGGERS_T));
3175 memcpy(&ioc->diag_trigger_event, buf, sz);
3176 if (ioc->diag_trigger_event.ValidEntries > NUM_VALID_ENTRIES)
3177 ioc->diag_trigger_event.ValidEntries = NUM_VALID_ENTRIES;
3178 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3181 static DEVICE_ATTR(diag_trigger_event, S_IRUGO | S_IWUSR,
3182 _ctl_diag_trigger_event_show, _ctl_diag_trigger_event_store);
3186 * _ctl_diag_trigger_scsi_show - show the diag_trigger_scsi attribute
3187 * @cdev - pointer to embedded class device
3188 * @buf - the buffer returned
3190 * A sysfs 'read/write' shost attribute.
3193 _ctl_diag_trigger_scsi_show(struct device *cdev,
3194 struct device_attribute *attr, char *buf)
3196 struct Scsi_Host *shost = class_to_shost(cdev);
3197 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3198 unsigned long flags;
3201 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3202 rc = sizeof(struct SL_WH_SCSI_TRIGGERS_T);
3203 memcpy(buf, &ioc->diag_trigger_scsi, rc);
3204 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3209 * _ctl_diag_trigger_scsi_store - store the diag_trigger_scsi attribute
3210 * @cdev - pointer to embedded class device
3211 * @buf - the buffer returned
3213 * A sysfs 'read/write' shost attribute.
3216 _ctl_diag_trigger_scsi_store(struct device *cdev,
3217 struct device_attribute *attr, const char *buf, size_t count)
3219 struct Scsi_Host *shost = class_to_shost(cdev);
3220 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3221 unsigned long flags;
3224 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3225 sz = min(sizeof(struct SL_WH_SCSI_TRIGGERS_T), count);
3226 memset(&ioc->diag_trigger_scsi, 0,
3227 sizeof(struct SL_WH_EVENT_TRIGGERS_T));
3228 memcpy(&ioc->diag_trigger_scsi, buf, sz);
3229 if (ioc->diag_trigger_scsi.ValidEntries > NUM_VALID_ENTRIES)
3230 ioc->diag_trigger_scsi.ValidEntries = NUM_VALID_ENTRIES;
3231 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3234 static DEVICE_ATTR(diag_trigger_scsi, S_IRUGO | S_IWUSR,
3235 _ctl_diag_trigger_scsi_show, _ctl_diag_trigger_scsi_store);
3239 * _ctl_diag_trigger_scsi_show - show the diag_trigger_mpi attribute
3240 * @cdev - pointer to embedded class device
3241 * @buf - the buffer returned
3243 * A sysfs 'read/write' shost attribute.
3246 _ctl_diag_trigger_mpi_show(struct device *cdev,
3247 struct device_attribute *attr, char *buf)
3249 struct Scsi_Host *shost = class_to_shost(cdev);
3250 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3251 unsigned long flags;
3254 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3255 rc = sizeof(struct SL_WH_MPI_TRIGGERS_T);
3256 memcpy(buf, &ioc->diag_trigger_mpi, rc);
3257 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3262 * _ctl_diag_trigger_mpi_store - store the diag_trigger_mpi attribute
3263 * @cdev - pointer to embedded class device
3264 * @buf - the buffer returned
3266 * A sysfs 'read/write' shost attribute.
3269 _ctl_diag_trigger_mpi_store(struct device *cdev,
3270 struct device_attribute *attr, const char *buf, size_t count)
3272 struct Scsi_Host *shost = class_to_shost(cdev);
3273 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3274 unsigned long flags;
3277 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3278 sz = min(sizeof(struct SL_WH_MPI_TRIGGERS_T), count);
3279 memset(&ioc->diag_trigger_mpi, 0,
3280 sizeof(ioc->diag_trigger_mpi));
3281 memcpy(&ioc->diag_trigger_mpi, buf, sz);
3282 if (ioc->diag_trigger_mpi.ValidEntries > NUM_VALID_ENTRIES)
3283 ioc->diag_trigger_mpi.ValidEntries = NUM_VALID_ENTRIES;
3284 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3288 static DEVICE_ATTR(diag_trigger_mpi, S_IRUGO | S_IWUSR,
3289 _ctl_diag_trigger_mpi_show, _ctl_diag_trigger_mpi_store);
3291 /*********** diagnostic trigger suppport *** END ****************************/
3295 /*****************************************/
3297 struct device_attribute *mpt3sas_host_attrs[] = {
3298 &dev_attr_version_fw,
3299 &dev_attr_version_bios,
3300 &dev_attr_version_mpi,
3301 &dev_attr_version_product,
3302 &dev_attr_version_nvdata_persistent,
3303 &dev_attr_version_nvdata_default,
3304 &dev_attr_board_name,
3305 &dev_attr_board_assembly,
3306 &dev_attr_board_tracer,
3308 &dev_attr_device_delay,
3309 &dev_attr_logging_level,
3310 &dev_attr_fwfault_debug,
3311 &dev_attr_fw_queue_depth,
3312 &dev_attr_host_sas_address,
3313 &dev_attr_ioc_reset_count,
3314 &dev_attr_host_trace_buffer_size,
3315 &dev_attr_host_trace_buffer,
3316 &dev_attr_host_trace_buffer_enable,
3317 &dev_attr_reply_queue_count,
3318 &dev_attr_diag_trigger_master,
3319 &dev_attr_diag_trigger_event,
3320 &dev_attr_diag_trigger_scsi,
3321 &dev_attr_diag_trigger_mpi,
3322 &dev_attr_BRM_status,
3326 /* device attributes */
3329 * _ctl_device_sas_address_show - sas address
3330 * @cdev - pointer to embedded class device
3331 * @buf - the buffer returned
3333 * This is the sas address for the target
3335 * A sysfs 'read-only' shost attribute.
3338 _ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr,
3341 struct scsi_device *sdev = to_scsi_device(dev);
3342 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3344 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
3345 (unsigned long long)sas_device_priv_data->sas_target->sas_address);
3347 static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL);
3350 * _ctl_device_handle_show - device handle
3351 * @cdev - pointer to embedded class device
3352 * @buf - the buffer returned
3354 * This is the firmware assigned device handle
3356 * A sysfs 'read-only' shost attribute.
3359 _ctl_device_handle_show(struct device *dev, struct device_attribute *attr,
3362 struct scsi_device *sdev = to_scsi_device(dev);
3363 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3365 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
3366 sas_device_priv_data->sas_target->handle);
3368 static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL);
3370 struct device_attribute *mpt3sas_dev_attrs[] = {
3371 &dev_attr_sas_address,
3372 &dev_attr_sas_device_handle,
3376 /* file operations table for mpt3ctl device */
3377 static const struct file_operations ctl_fops = {
3378 .owner = THIS_MODULE,
3379 .unlocked_ioctl = _ctl_ioctl,
3381 .fasync = _ctl_fasync,
3382 #ifdef CONFIG_COMPAT
3383 .compat_ioctl = _ctl_ioctl_compat,
3387 /* file operations table for mpt2ctl device */
3388 static const struct file_operations ctl_gen2_fops = {
3389 .owner = THIS_MODULE,
3390 .unlocked_ioctl = _ctl_mpt2_ioctl,
3392 .fasync = _ctl_fasync,
3393 #ifdef CONFIG_COMPAT
3394 .compat_ioctl = _ctl_mpt2_ioctl_compat,
3398 static struct miscdevice ctl_dev = {
3399 .minor = MPT3SAS_MINOR,
3400 .name = MPT3SAS_DEV_NAME,
3404 static struct miscdevice gen2_ctl_dev = {
3405 .minor = MPT2SAS_MINOR,
3406 .name = MPT2SAS_DEV_NAME,
3407 .fops = &ctl_gen2_fops,
3411 * mpt3sas_ctl_init - main entry point for ctl.
3415 mpt3sas_ctl_init(ushort hbas_to_enumerate)
3419 /* Don't register mpt3ctl ioctl device if
3420 * hbas_to_enumarate is one.
3422 if (hbas_to_enumerate != 1)
3423 if (misc_register(&ctl_dev) < 0)
3424 pr_err("%s can't register misc device [minor=%d]\n",
3425 MPT3SAS_DRIVER_NAME, MPT3SAS_MINOR);
3427 /* Don't register mpt3ctl ioctl device if
3428 * hbas_to_enumarate is two.
3430 if (hbas_to_enumerate != 2)
3431 if (misc_register(&gen2_ctl_dev) < 0)
3432 pr_err("%s can't register misc device [minor=%d]\n",
3433 MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR);
3435 init_waitqueue_head(&ctl_poll_wait);
3439 * mpt3sas_ctl_exit - exit point for ctl
3443 mpt3sas_ctl_exit(ushort hbas_to_enumerate)
3445 struct MPT3SAS_ADAPTER *ioc;
3448 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
3450 /* free memory associated to diag buffers */
3451 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
3452 if (!ioc->diag_buffer[i])
3454 if (!(ioc->diag_buffer_status[i] &
3455 MPT3_DIAG_BUFFER_IS_REGISTERED))
3457 if ((ioc->diag_buffer_status[i] &
3458 MPT3_DIAG_BUFFER_IS_RELEASED))
3460 pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i],
3461 ioc->diag_buffer[i], ioc->diag_buffer_dma[i]);
3462 ioc->diag_buffer[i] = NULL;
3463 ioc->diag_buffer_status[i] = 0;
3466 kfree(ioc->event_log);
3468 if (hbas_to_enumerate != 1)
3469 misc_deregister(&ctl_dev);
3470 if (hbas_to_enumerate != 2)
3471 misc_deregister(&gen2_ctl_dev);