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 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
52 #include <linux/delay.h>
53 #include <linux/compat.h>
54 #include <linux/poll.h>
57 #include <linux/uaccess.h>
59 #include "mpt3sas_base.h"
60 #include "mpt3sas_ctl.h"
63 static struct fasync_struct *async_queue;
64 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
68 * enum block_state - blocking state
69 * @NON_BLOCKING: non blocking
72 * These states are for ioctls that need to wait for a response
73 * from firmware, so they probably require sleep.
80 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
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);
259 * mpt3sas_ctl_done - ctl module completion routine
260 * @ioc: per adapter object
261 * @smid: system request message index
262 * @msix_index: MSIX table index supplied by the OS
263 * @reply: reply message frame(lower 32bit addr)
266 * The callback handler when using ioc->ctl_cb_idx.
268 * Return 1 meaning mf should be freed from _base_interrupt
269 * 0 means the mf is freed from this function.
272 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
275 MPI2DefaultReply_t *mpi_reply;
276 Mpi2SCSIIOReply_t *scsiio_reply;
277 const void *sense_data;
280 if (ioc->ctl_cmds.status == MPT3_CMD_NOT_USED)
282 if (ioc->ctl_cmds.smid != smid)
284 ioc->ctl_cmds.status |= MPT3_CMD_COMPLETE;
285 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
287 memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
288 ioc->ctl_cmds.status |= MPT3_CMD_REPLY_VALID;
290 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
291 mpi_reply->Function ==
292 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
293 scsiio_reply = (Mpi2SCSIIOReply_t *)mpi_reply;
294 if (scsiio_reply->SCSIState &
295 MPI2_SCSI_STATE_AUTOSENSE_VALID) {
296 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
297 le32_to_cpu(scsiio_reply->SenseCount));
298 sense_data = mpt3sas_base_get_sense_buffer(ioc,
300 memcpy(ioc->ctl_cmds.sense, sense_data, sz);
304 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
305 _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply);
307 ioc->ctl_cmds.status &= ~MPT3_CMD_PENDING;
308 complete(&ioc->ctl_cmds.done);
313 * _ctl_check_event_type - determines when an event needs logging
314 * @ioc: per adapter object
315 * @event: firmware event
317 * The bitmask in ioc->event_type[] indicates which events should be
318 * be saved in the driver event_log. This bitmask is set by application.
320 * Returns 1 when event should be captured, or zero means no match.
323 _ctl_check_event_type(struct MPT3SAS_ADAPTER *ioc, u16 event)
328 if (event >= 128 || !event || !ioc->event_log)
331 desired_event = (1 << (event % 32));
335 return desired_event & ioc->event_type[i];
339 * mpt3sas_ctl_add_to_event_log - add event
340 * @ioc: per adapter object
341 * @mpi_reply: reply message frame
346 mpt3sas_ctl_add_to_event_log(struct MPT3SAS_ADAPTER *ioc,
347 Mpi2EventNotificationReply_t *mpi_reply)
349 struct MPT3_IOCTL_EVENTS *event_log;
352 u32 sz, event_data_sz;
358 event = le16_to_cpu(mpi_reply->Event);
360 if (_ctl_check_event_type(ioc, event)) {
362 /* insert entry into circular event_log */
363 i = ioc->event_context % MPT3SAS_CTL_EVENT_LOG_SIZE;
364 event_log = ioc->event_log;
365 event_log[i].event = event;
366 event_log[i].context = ioc->event_context++;
368 event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4;
369 sz = min_t(u32, event_data_sz, MPT3_EVENT_DATA_SIZE);
370 memset(event_log[i].data, 0, MPT3_EVENT_DATA_SIZE);
371 memcpy(event_log[i].data, mpi_reply->EventData, sz);
375 /* This aen_event_read_flag flag is set until the
376 * application has read the event log.
377 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
379 if (event == MPI2_EVENT_LOG_ENTRY_ADDED ||
380 (send_aen && !ioc->aen_event_read_flag)) {
381 ioc->aen_event_read_flag = 1;
382 wake_up_interruptible(&ctl_poll_wait);
384 kill_fasync(&async_queue, SIGIO, POLL_IN);
389 * mpt3sas_ctl_event_callback - firmware event handler (called at ISR time)
390 * @ioc: per adapter object
391 * @msix_index: MSIX table index supplied by the OS
392 * @reply: reply message frame(lower 32bit addr)
393 * Context: interrupt.
395 * This function merely adds a new work task into ioc->firmware_event_thread.
396 * The tasks are worked from _firmware_event_work in user context.
398 * Return 1 meaning mf should be freed from _base_interrupt
399 * 0 means the mf is freed from this function.
402 mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
405 Mpi2EventNotificationReply_t *mpi_reply;
407 mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply);
408 mpt3sas_ctl_add_to_event_log(ioc, mpi_reply);
413 * _ctl_verify_adapter - validates ioc_number passed from application
414 * @ioc: per adapter object
415 * @iocpp: The ioc pointer is returned in this.
417 * Return (-1) means error, else ioc_number.
420 _ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp)
422 struct MPT3SAS_ADAPTER *ioc;
424 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
425 if (ioc->id != ioc_number)
435 * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
436 * @ioc: per adapter object
437 * @reset_phase: phase
439 * The handler for doing any required cleanup or initialization.
441 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
442 * MPT3_IOC_DONE_RESET
445 mpt3sas_ctl_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase)
450 switch (reset_phase) {
451 case MPT3_IOC_PRE_RESET:
452 dtmprintk(ioc, pr_info(MPT3SAS_FMT
453 "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__));
454 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
455 if (!(ioc->diag_buffer_status[i] &
456 MPT3_DIAG_BUFFER_IS_REGISTERED))
458 if ((ioc->diag_buffer_status[i] &
459 MPT3_DIAG_BUFFER_IS_RELEASED))
461 mpt3sas_send_diag_release(ioc, i, &issue_reset);
464 case MPT3_IOC_AFTER_RESET:
465 dtmprintk(ioc, pr_info(MPT3SAS_FMT
466 "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__));
467 if (ioc->ctl_cmds.status & MPT3_CMD_PENDING) {
468 ioc->ctl_cmds.status |= MPT3_CMD_RESET;
469 mpt3sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
470 complete(&ioc->ctl_cmds.done);
473 case MPT3_IOC_DONE_RESET:
474 dtmprintk(ioc, pr_info(MPT3SAS_FMT
475 "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__));
477 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
478 if (!(ioc->diag_buffer_status[i] &
479 MPT3_DIAG_BUFFER_IS_REGISTERED))
481 if ((ioc->diag_buffer_status[i] &
482 MPT3_DIAG_BUFFER_IS_RELEASED))
484 ioc->diag_buffer_status[i] |=
485 MPT3_DIAG_BUFFER_IS_DIAG_RESET;
497 * Called when application request fasyn callback handler.
500 _ctl_fasync(int fd, struct file *filep, int mode)
502 return fasync_helper(fd, filep, mode, &async_queue);
510 * Called when application releases the fasyn callback handler.
513 _ctl_release(struct inode *inode, struct file *filep)
515 return fasync_helper(-1, filep, 0, &async_queue);
525 _ctl_poll(struct file *filep, poll_table *wait)
527 struct MPT3SAS_ADAPTER *ioc;
529 poll_wait(filep, &ctl_poll_wait, wait);
531 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
532 if (ioc->aen_event_read_flag)
533 return POLLIN | POLLRDNORM;
539 * _ctl_set_task_mid - assign an active smid to tm request
540 * @ioc: per adapter object
541 * @karg - (struct mpt3_ioctl_command)
542 * @tm_request - pointer to mf from user space
544 * Returns 0 when an smid if found, else fail.
545 * during failure, the reply frame is filled.
548 _ctl_set_task_mid(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command *karg,
549 Mpi2SCSITaskManagementRequest_t *tm_request)
554 struct scsi_cmnd *scmd;
555 struct MPT3SAS_DEVICE *priv_data;
557 Mpi2SCSITaskManagementReply_t *tm_reply;
562 if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
564 else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK)
569 lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN);
571 handle = le16_to_cpu(tm_request->DevHandle);
572 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
573 for (i = ioc->scsiio_depth; i && !found; i--) {
574 scmd = ioc->scsi_lookup[i - 1].scmd;
575 if (scmd == NULL || scmd->device == NULL ||
576 scmd->device->hostdata == NULL)
578 if (lun != scmd->device->lun)
580 priv_data = scmd->device->hostdata;
581 if (priv_data->sas_target == NULL)
583 if (priv_data->sas_target->handle != handle)
585 tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid);
588 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
591 dctlprintk(ioc, pr_info(MPT3SAS_FMT
592 "%s: handle(0x%04x), lun(%d), no active mid!!\n",
594 desc, le16_to_cpu(tm_request->DevHandle), lun));
595 tm_reply = ioc->ctl_cmds.reply;
596 tm_reply->DevHandle = tm_request->DevHandle;
597 tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
598 tm_reply->TaskType = tm_request->TaskType;
599 tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4;
600 tm_reply->VP_ID = tm_request->VP_ID;
601 tm_reply->VF_ID = tm_request->VF_ID;
602 sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz);
603 if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply,
605 pr_err("failure at %s:%d/%s()!\n", __FILE__,
610 dctlprintk(ioc, pr_info(MPT3SAS_FMT
611 "%s: handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name,
612 desc, le16_to_cpu(tm_request->DevHandle), lun,
613 le16_to_cpu(tm_request->TaskMID)));
618 * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode
619 * @ioc: per adapter object
620 * @karg - (struct mpt3_ioctl_command)
621 * @mf - pointer to mf in user space
624 _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,
627 MPI2RequestHeader_t *mpi_request = NULL, *request;
628 MPI2DefaultReply_t *mpi_reply;
632 unsigned long timeout, timeleft;
636 void *data_out = NULL;
637 dma_addr_t data_out_dma = 0;
638 size_t data_out_sz = 0;
639 void *data_in = NULL;
640 dma_addr_t data_in_dma = 0;
641 size_t data_in_sz = 0;
643 u16 wait_state_count;
647 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
648 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
649 ioc->name, __func__);
654 wait_state_count = 0;
655 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
656 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
657 if (wait_state_count++ == 10) {
659 "%s: failed due to ioc not operational\n",
660 ioc->name, __func__);
665 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
667 "%s: waiting for operational state(count=%d)\n",
669 __func__, wait_state_count);
671 if (wait_state_count)
672 pr_info(MPT3SAS_FMT "%s: ioc is operational\n",
673 ioc->name, __func__);
675 mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL);
678 "%s: failed obtaining a memory for mpi_request\n",
679 ioc->name, __func__);
684 /* Check for overflow and wraparound */
685 if (karg.data_sge_offset * 4 > ioc->request_sz ||
686 karg.data_sge_offset > (UINT_MAX / 4)) {
691 /* copy in request message frame from user */
692 if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
693 pr_err("failure at %s:%d/%s()!\n", __FILE__, __LINE__,
699 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
700 smid = mpt3sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx);
702 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
703 ioc->name, __func__);
709 smid = mpt3sas_base_get_smid_scsiio(ioc, ioc->ctl_cb_idx, NULL);
711 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
712 ioc->name, __func__);
719 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
720 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
721 request = mpt3sas_base_get_msg_frame(ioc, smid);
722 memcpy(request, mpi_request, karg.data_sge_offset*4);
723 ioc->ctl_cmds.smid = smid;
724 data_out_sz = karg.data_out_size;
725 data_in_sz = karg.data_in_size;
727 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
728 mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
729 if (!le16_to_cpu(mpi_request->FunctionDependent1) ||
730 le16_to_cpu(mpi_request->FunctionDependent1) >
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 = pci_alloc_consistent(ioc->pdev, data_out_sz,
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 = pci_alloc_consistent(ioc->pdev, data_in_sz,
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 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
775 _ctl_display_some_debug(ioc, smid, "ctl_request", NULL);
778 init_completion(&ioc->ctl_cmds.done);
779 switch (mpi_request->Function) {
780 case MPI2_FUNCTION_SCSI_IO_REQUEST:
781 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
783 Mpi2SCSIIORequest_t *scsiio_request =
784 (Mpi2SCSIIORequest_t *)request;
785 scsiio_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
786 scsiio_request->SenseBufferLowAddress =
787 mpt3sas_base_get_sense_buffer_dma(ioc, smid);
788 memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE);
789 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
790 data_in_dma, data_in_sz);
792 if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)
793 mpt3sas_base_put_smid_scsi_io(ioc, smid,
794 le16_to_cpu(mpi_request->FunctionDependent1));
796 mpt3sas_base_put_smid_default(ioc, smid);
799 case MPI2_FUNCTION_SCSI_TASK_MGMT:
801 Mpi2SCSITaskManagementRequest_t *tm_request =
802 (Mpi2SCSITaskManagementRequest_t *)request;
804 dtmprintk(ioc, pr_info(MPT3SAS_FMT
805 "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
807 le16_to_cpu(tm_request->DevHandle), tm_request->TaskType));
809 if (tm_request->TaskType ==
810 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ||
811 tm_request->TaskType ==
812 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) {
813 if (_ctl_set_task_mid(ioc, &karg, tm_request)) {
814 mpt3sas_base_free_smid(ioc, smid);
819 mpt3sas_scsih_set_tm_flag(ioc, le16_to_cpu(
820 tm_request->DevHandle));
821 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
822 data_in_dma, data_in_sz);
823 mpt3sas_base_put_smid_hi_priority(ioc, smid);
826 case MPI2_FUNCTION_SMP_PASSTHROUGH:
828 Mpi2SmpPassthroughRequest_t *smp_request =
829 (Mpi2SmpPassthroughRequest_t *)mpi_request;
832 /* ioc determines which port to use */
833 smp_request->PhysicalPort = 0xFF;
834 if (smp_request->PassthroughFlags &
835 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
836 data = (u8 *)&smp_request->SGL;
838 if (unlikely(data_out == NULL)) {
839 pr_err("failure at %s:%d/%s()!\n",
840 __FILE__, __LINE__, __func__);
841 mpt3sas_base_free_smid(ioc, smid);
848 if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
849 ioc->ioc_link_reset_in_progress = 1;
850 ioc->ignore_loginfos = 1;
852 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
854 mpt3sas_base_put_smid_default(ioc, smid);
857 case MPI2_FUNCTION_SATA_PASSTHROUGH:
858 case MPI2_FUNCTION_FW_DOWNLOAD:
859 case MPI2_FUNCTION_FW_UPLOAD:
861 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
863 mpt3sas_base_put_smid_default(ioc, smid);
866 case MPI2_FUNCTION_TOOLBOX:
868 Mpi2ToolboxCleanRequest_t *toolbox_request =
869 (Mpi2ToolboxCleanRequest_t *)mpi_request;
871 if (toolbox_request->Tool == MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL) {
872 ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
873 data_in_dma, data_in_sz);
875 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
876 data_in_dma, data_in_sz);
878 mpt3sas_base_put_smid_default(ioc, smid);
881 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
883 Mpi2SasIoUnitControlRequest_t *sasiounit_request =
884 (Mpi2SasIoUnitControlRequest_t *)mpi_request;
886 if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET
887 || sasiounit_request->Operation ==
888 MPI2_SAS_OP_PHY_LINK_RESET) {
889 ioc->ioc_link_reset_in_progress = 1;
890 ioc->ignore_loginfos = 1;
892 /* drop to default case for posting the request */
895 ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
896 data_in_dma, data_in_sz);
897 mpt3sas_base_put_smid_default(ioc, smid);
901 if (karg.timeout < MPT3_IOCTL_DEFAULT_TIMEOUT)
902 timeout = MPT3_IOCTL_DEFAULT_TIMEOUT;
904 timeout = karg.timeout;
905 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
907 if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
908 Mpi2SCSITaskManagementRequest_t *tm_request =
909 (Mpi2SCSITaskManagementRequest_t *)mpi_request;
910 mpt3sas_scsih_clear_tm_flag(ioc, le16_to_cpu(
911 tm_request->DevHandle));
912 mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT);
913 } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH ||
914 mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) &&
915 ioc->ioc_link_reset_in_progress) {
916 ioc->ioc_link_reset_in_progress = 0;
917 ioc->ignore_loginfos = 0;
919 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
920 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
922 _debug_dump_mf(mpi_request, karg.data_sge_offset);
923 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
925 goto issue_host_reset;
928 mpi_reply = ioc->ctl_cmds.reply;
929 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
931 #ifdef CONFIG_SCSI_MPT3SAS_LOGGING
932 if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT &&
933 (ioc->logging_level & MPT_DEBUG_TM)) {
934 Mpi2SCSITaskManagementReply_t *tm_reply =
935 (Mpi2SCSITaskManagementReply_t *)mpi_reply;
937 pr_info(MPT3SAS_FMT "TASK_MGMT: " \
938 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
939 "TerminationCount(0x%08x)\n", ioc->name,
940 le16_to_cpu(tm_reply->IOCStatus),
941 le32_to_cpu(tm_reply->IOCLogInfo),
942 le32_to_cpu(tm_reply->TerminationCount));
945 /* copy out xdata to user */
947 if (copy_to_user(karg.data_in_buf_ptr, data_in,
949 pr_err("failure at %s:%d/%s()!\n", __FILE__,
956 /* copy out reply message frame to user */
957 if (karg.max_reply_bytes) {
958 sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz);
959 if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply,
961 pr_err("failure at %s:%d/%s()!\n", __FILE__,
968 /* copy out sense to user */
969 if (karg.max_sense_bytes && (mpi_request->Function ==
970 MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function ==
971 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) {
972 sz = min_t(u32, karg.max_sense_bytes, SCSI_SENSE_BUFFERSIZE);
973 if (copy_to_user(karg.sense_data_ptr, ioc->ctl_cmds.sense,
975 pr_err("failure at %s:%d/%s()!\n", __FILE__,
985 if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
986 mpi_request->Function ==
987 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
988 mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH)) {
989 pr_info(MPT3SAS_FMT "issue target reset: handle = (0x%04x)\n",
991 le16_to_cpu(mpi_request->FunctionDependent1));
992 mpt3sas_halt_firmware(ioc);
993 mpt3sas_scsih_issue_tm(ioc,
994 le16_to_cpu(mpi_request->FunctionDependent1), 0, 0,
995 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30,
998 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1004 /* free memory associated with sg buffers */
1006 pci_free_consistent(ioc->pdev, data_in_sz, data_in,
1010 pci_free_consistent(ioc->pdev, data_out_sz, data_out,
1014 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1019 * _ctl_getiocinfo - main handler for MPT3IOCINFO opcode
1020 * @ioc: per adapter object
1021 * @arg - user space buffer containing ioctl content
1024 _ctl_getiocinfo(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1026 struct mpt3_ioctl_iocinfo karg;
1028 if (copy_from_user(&karg, arg, sizeof(karg))) {
1029 pr_err("failure at %s:%d/%s()!\n",
1030 __FILE__, __LINE__, __func__);
1034 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1037 memset(&karg, 0 , sizeof(karg));
1038 karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS3;
1040 karg.port_number = ioc->pfacts[0].PortNumber;
1041 karg.hw_rev = ioc->pdev->revision;
1042 karg.pci_id = ioc->pdev->device;
1043 karg.subsystem_device = ioc->pdev->subsystem_device;
1044 karg.subsystem_vendor = ioc->pdev->subsystem_vendor;
1045 karg.pci_information.u.bits.bus = ioc->pdev->bus->number;
1046 karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn);
1047 karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn);
1048 karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus);
1049 karg.firmware_version = ioc->facts.FWVersion.Word;
1050 strcpy(karg.driver_version, MPT3SAS_DRIVER_NAME);
1051 strcat(karg.driver_version, "-");
1052 strcat(karg.driver_version, MPT3SAS_DRIVER_VERSION);
1053 karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
1055 if (copy_to_user(arg, &karg, sizeof(karg))) {
1056 pr_err("failure at %s:%d/%s()!\n",
1057 __FILE__, __LINE__, __func__);
1064 * _ctl_eventquery - main handler for MPT3EVENTQUERY opcode
1065 * @ioc: per adapter object
1066 * @arg - user space buffer containing ioctl content
1069 _ctl_eventquery(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1071 struct mpt3_ioctl_eventquery karg;
1073 if (copy_from_user(&karg, arg, sizeof(karg))) {
1074 pr_err("failure at %s:%d/%s()!\n",
1075 __FILE__, __LINE__, __func__);
1079 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1082 karg.event_entries = MPT3SAS_CTL_EVENT_LOG_SIZE;
1083 memcpy(karg.event_types, ioc->event_type,
1084 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1086 if (copy_to_user(arg, &karg, sizeof(karg))) {
1087 pr_err("failure at %s:%d/%s()!\n",
1088 __FILE__, __LINE__, __func__);
1095 * _ctl_eventenable - main handler for MPT3EVENTENABLE opcode
1096 * @ioc: per adapter object
1097 * @arg - user space buffer containing ioctl content
1100 _ctl_eventenable(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1102 struct mpt3_ioctl_eventenable karg;
1104 if (copy_from_user(&karg, arg, sizeof(karg))) {
1105 pr_err("failure at %s:%d/%s()!\n",
1106 __FILE__, __LINE__, __func__);
1110 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1113 memcpy(ioc->event_type, karg.event_types,
1114 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32));
1115 mpt3sas_base_validate_event_type(ioc, ioc->event_type);
1119 /* initialize event_log */
1120 ioc->event_context = 0;
1121 ioc->aen_event_read_flag = 0;
1122 ioc->event_log = kcalloc(MPT3SAS_CTL_EVENT_LOG_SIZE,
1123 sizeof(struct MPT3_IOCTL_EVENTS), GFP_KERNEL);
1124 if (!ioc->event_log) {
1125 pr_err("failure at %s:%d/%s()!\n",
1126 __FILE__, __LINE__, __func__);
1133 * _ctl_eventreport - main handler for MPT3EVENTREPORT opcode
1134 * @ioc: per adapter object
1135 * @arg - user space buffer containing ioctl content
1138 _ctl_eventreport(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1140 struct mpt3_ioctl_eventreport karg;
1141 u32 number_bytes, max_events, max;
1142 struct mpt3_ioctl_eventreport __user *uarg = arg;
1144 if (copy_from_user(&karg, arg, sizeof(karg))) {
1145 pr_err("failure at %s:%d/%s()!\n",
1146 __FILE__, __LINE__, __func__);
1150 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1153 number_bytes = karg.hdr.max_data_size -
1154 sizeof(struct mpt3_ioctl_header);
1155 max_events = number_bytes/sizeof(struct MPT3_IOCTL_EVENTS);
1156 max = min_t(u32, MPT3SAS_CTL_EVENT_LOG_SIZE, max_events);
1158 /* If fewer than 1 event is requested, there must have
1159 * been some type of error.
1161 if (!max || !ioc->event_log)
1164 number_bytes = max * sizeof(struct MPT3_IOCTL_EVENTS);
1165 if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) {
1166 pr_err("failure at %s:%d/%s()!\n",
1167 __FILE__, __LINE__, __func__);
1171 /* reset flag so SIGIO can restart */
1172 ioc->aen_event_read_flag = 0;
1177 * _ctl_do_reset - main handler for MPT3HARDRESET opcode
1178 * @ioc: per adapter object
1179 * @arg - user space buffer containing ioctl content
1182 _ctl_do_reset(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1184 struct mpt3_ioctl_diag_reset karg;
1187 if (copy_from_user(&karg, arg, sizeof(karg))) {
1188 pr_err("failure at %s:%d/%s()!\n",
1189 __FILE__, __LINE__, __func__);
1193 if (ioc->shost_recovery || ioc->pci_error_recovery ||
1194 ioc->is_driver_loading)
1197 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name,
1200 retval = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1202 pr_info(MPT3SAS_FMT "host reset: %s\n",
1203 ioc->name, ((!retval) ? "SUCCESS" : "FAILED"));
1208 * _ctl_btdh_search_sas_device - searching for sas device
1209 * @ioc: per adapter object
1210 * @btdh: btdh ioctl payload
1213 _ctl_btdh_search_sas_device(struct MPT3SAS_ADAPTER *ioc,
1214 struct mpt3_ioctl_btdh_mapping *btdh)
1216 struct _sas_device *sas_device;
1217 unsigned long flags;
1220 if (list_empty(&ioc->sas_device_list))
1223 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1224 list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
1225 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1226 btdh->handle == sas_device->handle) {
1227 btdh->bus = sas_device->channel;
1228 btdh->id = sas_device->id;
1231 } else if (btdh->bus == sas_device->channel && btdh->id ==
1232 sas_device->id && btdh->handle == 0xFFFF) {
1233 btdh->handle = sas_device->handle;
1239 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1244 * _ctl_btdh_search_raid_device - searching for raid device
1245 * @ioc: per adapter object
1246 * @btdh: btdh ioctl payload
1249 _ctl_btdh_search_raid_device(struct MPT3SAS_ADAPTER *ioc,
1250 struct mpt3_ioctl_btdh_mapping *btdh)
1252 struct _raid_device *raid_device;
1253 unsigned long flags;
1256 if (list_empty(&ioc->raid_device_list))
1259 spin_lock_irqsave(&ioc->raid_device_lock, flags);
1260 list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
1261 if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF &&
1262 btdh->handle == raid_device->handle) {
1263 btdh->bus = raid_device->channel;
1264 btdh->id = raid_device->id;
1267 } else if (btdh->bus == raid_device->channel && btdh->id ==
1268 raid_device->id && btdh->handle == 0xFFFF) {
1269 btdh->handle = raid_device->handle;
1275 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1280 * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode
1281 * @ioc: per adapter object
1282 * @arg - user space buffer containing ioctl content
1285 _ctl_btdh_mapping(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1287 struct mpt3_ioctl_btdh_mapping karg;
1290 if (copy_from_user(&karg, arg, sizeof(karg))) {
1291 pr_err("failure at %s:%d/%s()!\n",
1292 __FILE__, __LINE__, __func__);
1296 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1299 rc = _ctl_btdh_search_sas_device(ioc, &karg);
1301 _ctl_btdh_search_raid_device(ioc, &karg);
1303 if (copy_to_user(arg, &karg, sizeof(karg))) {
1304 pr_err("failure at %s:%d/%s()!\n",
1305 __FILE__, __LINE__, __func__);
1312 * _ctl_diag_capability - return diag buffer capability
1313 * @ioc: per adapter object
1314 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1316 * returns 1 when diag buffer support is enabled in firmware
1319 _ctl_diag_capability(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type)
1323 switch (buffer_type) {
1324 case MPI2_DIAG_BUF_TYPE_TRACE:
1325 if (ioc->facts.IOCCapabilities &
1326 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER)
1329 case MPI2_DIAG_BUF_TYPE_SNAPSHOT:
1330 if (ioc->facts.IOCCapabilities &
1331 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER)
1334 case MPI2_DIAG_BUF_TYPE_EXTENDED:
1335 if (ioc->facts.IOCCapabilities &
1336 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER)
1345 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1346 * @ioc: per adapter object
1347 * @diag_register: the diag_register struct passed in from user space
1351 _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc,
1352 struct mpt3_diag_register *diag_register)
1355 void *request_data = NULL;
1356 dma_addr_t request_data_dma;
1357 u32 request_data_sz = 0;
1358 Mpi2DiagBufferPostRequest_t *mpi_request;
1359 Mpi2DiagBufferPostReply_t *mpi_reply;
1361 unsigned long timeleft;
1367 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1370 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1371 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1373 "%s: failed due to ioc not operational\n",
1374 ioc->name, __func__);
1379 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1380 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
1381 ioc->name, __func__);
1386 buffer_type = diag_register->buffer_type;
1387 if (!_ctl_diag_capability(ioc, buffer_type)) {
1389 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1390 ioc->name, __func__, buffer_type);
1394 if (ioc->diag_buffer_status[buffer_type] &
1395 MPT3_DIAG_BUFFER_IS_REGISTERED) {
1397 "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1398 ioc->name, __func__,
1403 if (diag_register->requested_buffer_size % 4) {
1405 "%s: the requested_buffer_size is not 4 byte aligned\n",
1406 ioc->name, __func__);
1410 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1412 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1413 ioc->name, __func__);
1419 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
1420 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1421 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1422 ioc->ctl_cmds.smid = smid;
1424 request_data = ioc->diag_buffer[buffer_type];
1425 request_data_sz = diag_register->requested_buffer_size;
1426 ioc->unique_id[buffer_type] = diag_register->unique_id;
1427 ioc->diag_buffer_status[buffer_type] = 0;
1428 memcpy(ioc->product_specific[buffer_type],
1429 diag_register->product_specific, MPT3_PRODUCT_SPECIFIC_DWORDS);
1430 ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags;
1433 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1434 if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) {
1435 pci_free_consistent(ioc->pdev,
1436 ioc->diag_buffer_sz[buffer_type],
1437 request_data, request_data_dma);
1438 request_data = NULL;
1442 if (request_data == NULL) {
1443 ioc->diag_buffer_sz[buffer_type] = 0;
1444 ioc->diag_buffer_dma[buffer_type] = 0;
1445 request_data = pci_alloc_consistent(
1446 ioc->pdev, request_data_sz, &request_data_dma);
1447 if (request_data == NULL) {
1448 pr_err(MPT3SAS_FMT "%s: failed allocating memory" \
1449 " for diag buffers, requested size(%d)\n",
1450 ioc->name, __func__, request_data_sz);
1451 mpt3sas_base_free_smid(ioc, smid);
1454 ioc->diag_buffer[buffer_type] = request_data;
1455 ioc->diag_buffer_sz[buffer_type] = request_data_sz;
1456 ioc->diag_buffer_dma[buffer_type] = request_data_dma;
1459 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
1460 mpi_request->BufferType = diag_register->buffer_type;
1461 mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags);
1462 mpi_request->BufferAddress = cpu_to_le64(request_data_dma);
1463 mpi_request->BufferLength = cpu_to_le32(request_data_sz);
1464 mpi_request->VF_ID = 0; /* TODO */
1465 mpi_request->VP_ID = 0;
1467 dctlprintk(ioc, pr_info(MPT3SAS_FMT
1468 "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1469 ioc->name, __func__, request_data,
1470 (unsigned long long)request_data_dma,
1471 le32_to_cpu(mpi_request->BufferLength)));
1473 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
1474 mpi_request->ProductSpecific[i] =
1475 cpu_to_le32(ioc->product_specific[buffer_type][i]);
1477 init_completion(&ioc->ctl_cmds.done);
1478 mpt3sas_base_put_smid_default(ioc, smid);
1479 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
1480 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
1482 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1483 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
1485 _debug_dump_mf(mpi_request,
1486 sizeof(Mpi2DiagBufferPostRequest_t)/4);
1487 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
1489 goto issue_host_reset;
1492 /* process the completed Reply Message Frame */
1493 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1494 pr_err(MPT3SAS_FMT "%s: no reply message\n",
1495 ioc->name, __func__);
1500 mpi_reply = ioc->ctl_cmds.reply;
1501 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1503 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1504 ioc->diag_buffer_status[buffer_type] |=
1505 MPT3_DIAG_BUFFER_IS_REGISTERED;
1506 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
1507 ioc->name, __func__));
1510 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1511 ioc->name, __func__,
1512 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
1518 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1523 if (rc && request_data)
1524 pci_free_consistent(ioc->pdev, request_data_sz,
1525 request_data, request_data_dma);
1527 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1532 * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time
1533 * @ioc: per adapter object
1534 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1536 * This is called when command line option diag_buffer_enable is enabled
1537 * at driver load time.
1540 mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER *ioc, u8 bits_to_register)
1542 struct mpt3_diag_register diag_register;
1544 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
1546 if (bits_to_register & 1) {
1547 pr_info(MPT3SAS_FMT "registering trace buffer support\n",
1549 ioc->diag_trigger_master.MasterData =
1550 (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET);
1551 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
1552 /* register for 2MB buffers */
1553 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1554 diag_register.unique_id = 0x7075900;
1555 _ctl_diag_register_2(ioc, &diag_register);
1558 if (bits_to_register & 2) {
1559 pr_info(MPT3SAS_FMT "registering snapshot buffer support\n",
1561 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT;
1562 /* register for 2MB buffers */
1563 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1564 diag_register.unique_id = 0x7075901;
1565 _ctl_diag_register_2(ioc, &diag_register);
1568 if (bits_to_register & 4) {
1569 pr_info(MPT3SAS_FMT "registering extended buffer support\n",
1571 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED;
1572 /* register for 2MB buffers */
1573 diag_register.requested_buffer_size = 2 * (1024 * 1024);
1574 diag_register.unique_id = 0x7075901;
1575 _ctl_diag_register_2(ioc, &diag_register);
1580 * _ctl_diag_register - application register with driver
1581 * @ioc: per adapter object
1582 * @arg - user space buffer containing ioctl content
1584 * This will allow the driver to setup any required buffers that will be
1585 * needed by firmware to communicate with the driver.
1588 _ctl_diag_register(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1590 struct mpt3_diag_register karg;
1593 if (copy_from_user(&karg, arg, sizeof(karg))) {
1594 pr_err("failure at %s:%d/%s()!\n",
1595 __FILE__, __LINE__, __func__);
1599 rc = _ctl_diag_register_2(ioc, &karg);
1604 * _ctl_diag_unregister - application unregister with driver
1605 * @ioc: per adapter object
1606 * @arg - user space buffer containing ioctl content
1608 * This will allow the driver to cleanup any memory allocated for diag
1609 * messages and to free up any resources.
1612 _ctl_diag_unregister(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1614 struct mpt3_diag_unregister karg;
1616 dma_addr_t request_data_dma;
1617 u32 request_data_sz;
1620 if (copy_from_user(&karg, arg, sizeof(karg))) {
1621 pr_err("failure at %s:%d/%s()!\n",
1622 __FILE__, __LINE__, __func__);
1626 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1629 buffer_type = karg.unique_id & 0x000000ff;
1630 if (!_ctl_diag_capability(ioc, buffer_type)) {
1632 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1633 ioc->name, __func__, buffer_type);
1637 if ((ioc->diag_buffer_status[buffer_type] &
1638 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1640 "%s: buffer_type(0x%02x) is not registered\n",
1641 ioc->name, __func__, buffer_type);
1644 if ((ioc->diag_buffer_status[buffer_type] &
1645 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
1647 "%s: buffer_type(0x%02x) has not been released\n",
1648 ioc->name, __func__, buffer_type);
1652 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1654 "%s: unique_id(0x%08x) is not registered\n",
1655 ioc->name, __func__, karg.unique_id);
1659 request_data = ioc->diag_buffer[buffer_type];
1660 if (!request_data) {
1662 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1663 ioc->name, __func__, buffer_type);
1667 request_data_sz = ioc->diag_buffer_sz[buffer_type];
1668 request_data_dma = ioc->diag_buffer_dma[buffer_type];
1669 pci_free_consistent(ioc->pdev, request_data_sz,
1670 request_data, request_data_dma);
1671 ioc->diag_buffer[buffer_type] = NULL;
1672 ioc->diag_buffer_status[buffer_type] = 0;
1677 * _ctl_diag_query - query relevant info associated with diag buffers
1678 * @ioc: per adapter object
1679 * @arg - user space buffer containing ioctl content
1681 * The application will send only buffer_type and unique_id. Driver will
1682 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1683 * 0x00, the driver will return info specified by Buffer Type.
1686 _ctl_diag_query(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1688 struct mpt3_diag_query karg;
1693 if (copy_from_user(&karg, arg, sizeof(karg))) {
1694 pr_err("failure at %s:%d/%s()!\n",
1695 __FILE__, __LINE__, __func__);
1699 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1702 karg.application_flags = 0;
1703 buffer_type = karg.buffer_type;
1705 if (!_ctl_diag_capability(ioc, buffer_type)) {
1707 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1708 ioc->name, __func__, buffer_type);
1712 if ((ioc->diag_buffer_status[buffer_type] &
1713 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1715 "%s: buffer_type(0x%02x) is not registered\n",
1716 ioc->name, __func__, buffer_type);
1720 if (karg.unique_id & 0xffffff00) {
1721 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1723 "%s: unique_id(0x%08x) is not registered\n",
1724 ioc->name, __func__, karg.unique_id);
1729 request_data = ioc->diag_buffer[buffer_type];
1730 if (!request_data) {
1732 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
1733 ioc->name, __func__, buffer_type);
1737 if (ioc->diag_buffer_status[buffer_type] & MPT3_DIAG_BUFFER_IS_RELEASED)
1738 karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1739 MPT3_APP_FLAGS_BUFFER_VALID);
1741 karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED |
1742 MPT3_APP_FLAGS_BUFFER_VALID |
1743 MPT3_APP_FLAGS_FW_BUFFER_ACCESS);
1745 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
1746 karg.product_specific[i] =
1747 ioc->product_specific[buffer_type][i];
1749 karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type];
1750 karg.driver_added_buffer_size = 0;
1751 karg.unique_id = ioc->unique_id[buffer_type];
1752 karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type];
1754 if (copy_to_user(arg, &karg, sizeof(struct mpt3_diag_query))) {
1756 "%s: unable to write mpt3_diag_query data @ %p\n",
1757 ioc->name, __func__, arg);
1764 * mpt3sas_send_diag_release - Diag Release Message
1765 * @ioc: per adapter object
1766 * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
1767 * @issue_reset - specifies whether host reset is required.
1771 mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type,
1774 Mpi2DiagReleaseRequest_t *mpi_request;
1775 Mpi2DiagReleaseReply_t *mpi_reply;
1780 unsigned long timeleft;
1782 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1788 ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
1789 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
1790 if (ioc->diag_buffer_status[buffer_type] &
1791 MPT3_DIAG_BUFFER_IS_REGISTERED)
1792 ioc->diag_buffer_status[buffer_type] |=
1793 MPT3_DIAG_BUFFER_IS_RELEASED;
1794 dctlprintk(ioc, pr_info(MPT3SAS_FMT
1795 "%s: skipping due to FAULT state\n", ioc->name,
1801 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
1802 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
1803 ioc->name, __func__);
1808 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
1810 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
1811 ioc->name, __func__);
1816 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
1817 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
1818 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
1819 ioc->ctl_cmds.smid = smid;
1821 mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE;
1822 mpi_request->BufferType = buffer_type;
1823 mpi_request->VF_ID = 0; /* TODO */
1824 mpi_request->VP_ID = 0;
1826 init_completion(&ioc->ctl_cmds.done);
1827 mpt3sas_base_put_smid_default(ioc, smid);
1828 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
1829 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
1831 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
1832 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
1834 _debug_dump_mf(mpi_request,
1835 sizeof(Mpi2DiagReleaseRequest_t)/4);
1836 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
1842 /* process the completed Reply Message Frame */
1843 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
1844 pr_err(MPT3SAS_FMT "%s: no reply message\n",
1845 ioc->name, __func__);
1850 mpi_reply = ioc->ctl_cmds.reply;
1851 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
1853 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
1854 ioc->diag_buffer_status[buffer_type] |=
1855 MPT3_DIAG_BUFFER_IS_RELEASED;
1856 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
1857 ioc->name, __func__));
1860 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1861 ioc->name, __func__,
1862 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
1867 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
1872 * _ctl_diag_release - request to send Diag Release Message to firmware
1873 * @arg - user space buffer containing ioctl content
1875 * This allows ownership of the specified buffer to returned to the driver,
1876 * allowing an application to read the buffer without fear that firmware is
1877 * overwritting information in the buffer.
1880 _ctl_diag_release(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1882 struct mpt3_diag_release karg;
1888 if (copy_from_user(&karg, arg, sizeof(karg))) {
1889 pr_err("failure at %s:%d/%s()!\n",
1890 __FILE__, __LINE__, __func__);
1894 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1897 buffer_type = karg.unique_id & 0x000000ff;
1898 if (!_ctl_diag_capability(ioc, buffer_type)) {
1900 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1901 ioc->name, __func__, buffer_type);
1905 if ((ioc->diag_buffer_status[buffer_type] &
1906 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
1908 "%s: buffer_type(0x%02x) is not registered\n",
1909 ioc->name, __func__, buffer_type);
1913 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1915 "%s: unique_id(0x%08x) is not registered\n",
1916 ioc->name, __func__, karg.unique_id);
1920 if (ioc->diag_buffer_status[buffer_type] &
1921 MPT3_DIAG_BUFFER_IS_RELEASED) {
1923 "%s: buffer_type(0x%02x) is already released\n",
1924 ioc->name, __func__,
1929 request_data = ioc->diag_buffer[buffer_type];
1931 if (!request_data) {
1933 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1934 ioc->name, __func__, buffer_type);
1938 /* buffers were released by due to host reset */
1939 if ((ioc->diag_buffer_status[buffer_type] &
1940 MPT3_DIAG_BUFFER_IS_DIAG_RESET)) {
1941 ioc->diag_buffer_status[buffer_type] |=
1942 MPT3_DIAG_BUFFER_IS_RELEASED;
1943 ioc->diag_buffer_status[buffer_type] &=
1944 ~MPT3_DIAG_BUFFER_IS_DIAG_RESET;
1946 "%s: buffer_type(0x%02x) was released due to host reset\n",
1947 ioc->name, __func__, buffer_type);
1951 rc = mpt3sas_send_diag_release(ioc, buffer_type, &issue_reset);
1954 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
1961 * _ctl_diag_read_buffer - request for copy of the diag buffer
1962 * @ioc: per adapter object
1963 * @arg - user space buffer containing ioctl content
1966 _ctl_diag_read_buffer(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
1968 struct mpt3_diag_read_buffer karg;
1969 struct mpt3_diag_read_buffer __user *uarg = arg;
1970 void *request_data, *diag_data;
1971 Mpi2DiagBufferPostRequest_t *mpi_request;
1972 Mpi2DiagBufferPostReply_t *mpi_reply;
1975 unsigned long timeleft, request_size, copy_size;
1980 if (copy_from_user(&karg, arg, sizeof(karg))) {
1981 pr_err("failure at %s:%d/%s()!\n",
1982 __FILE__, __LINE__, __func__);
1986 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name,
1989 buffer_type = karg.unique_id & 0x000000ff;
1990 if (!_ctl_diag_capability(ioc, buffer_type)) {
1992 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1993 ioc->name, __func__, buffer_type);
1997 if (karg.unique_id != ioc->unique_id[buffer_type]) {
1999 "%s: unique_id(0x%08x) is not registered\n",
2000 ioc->name, __func__, karg.unique_id);
2004 request_data = ioc->diag_buffer[buffer_type];
2005 if (!request_data) {
2007 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2008 ioc->name, __func__, buffer_type);
2012 request_size = ioc->diag_buffer_sz[buffer_type];
2014 if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
2015 pr_err(MPT3SAS_FMT "%s: either the starting_offset " \
2016 "or bytes_to_read are not 4 byte aligned\n", ioc->name,
2021 if (karg.starting_offset > request_size)
2024 diag_data = (void *)(request_data + karg.starting_offset);
2025 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2026 "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2027 ioc->name, __func__,
2028 diag_data, karg.starting_offset, karg.bytes_to_read));
2030 /* Truncate data on requests that are too large */
2031 if ((diag_data + karg.bytes_to_read < diag_data) ||
2032 (diag_data + karg.bytes_to_read > request_data + request_size))
2033 copy_size = request_size - karg.starting_offset;
2035 copy_size = karg.bytes_to_read;
2037 if (copy_to_user((void __user *)uarg->diagnostic_data,
2038 diag_data, copy_size)) {
2040 "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2041 ioc->name, __func__, diag_data);
2045 if ((karg.flags & MPT3_FLAGS_REREGISTER) == 0)
2048 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2049 "%s: Reregister buffer_type(0x%02x)\n",
2050 ioc->name, __func__, buffer_type));
2051 if ((ioc->diag_buffer_status[buffer_type] &
2052 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
2053 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2054 "%s: buffer_type(0x%02x) is still registered\n",
2055 ioc->name, __func__, buffer_type));
2058 /* Get a free request frame and save the message context.
2061 if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
2062 pr_err(MPT3SAS_FMT "%s: ctl_cmd in use\n",
2063 ioc->name, __func__);
2068 smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx);
2070 pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n",
2071 ioc->name, __func__);
2077 ioc->ctl_cmds.status = MPT3_CMD_PENDING;
2078 memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz);
2079 mpi_request = mpt3sas_base_get_msg_frame(ioc, smid);
2080 ioc->ctl_cmds.smid = smid;
2082 mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST;
2083 mpi_request->BufferType = buffer_type;
2084 mpi_request->BufferLength =
2085 cpu_to_le32(ioc->diag_buffer_sz[buffer_type]);
2086 mpi_request->BufferAddress =
2087 cpu_to_le64(ioc->diag_buffer_dma[buffer_type]);
2088 for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
2089 mpi_request->ProductSpecific[i] =
2090 cpu_to_le32(ioc->product_specific[buffer_type][i]);
2091 mpi_request->VF_ID = 0; /* TODO */
2092 mpi_request->VP_ID = 0;
2094 init_completion(&ioc->ctl_cmds.done);
2095 mpt3sas_base_put_smid_default(ioc, smid);
2096 timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done,
2097 MPT3_IOCTL_DEFAULT_TIMEOUT*HZ);
2099 if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) {
2100 pr_err(MPT3SAS_FMT "%s: timeout\n", ioc->name,
2102 _debug_dump_mf(mpi_request,
2103 sizeof(Mpi2DiagBufferPostRequest_t)/4);
2104 if (!(ioc->ctl_cmds.status & MPT3_CMD_RESET))
2106 goto issue_host_reset;
2109 /* process the completed Reply Message Frame */
2110 if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) {
2111 pr_err(MPT3SAS_FMT "%s: no reply message\n",
2112 ioc->name, __func__);
2117 mpi_reply = ioc->ctl_cmds.reply;
2118 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
2120 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
2121 ioc->diag_buffer_status[buffer_type] |=
2122 MPT3_DIAG_BUFFER_IS_REGISTERED;
2123 dctlprintk(ioc, pr_info(MPT3SAS_FMT "%s: success\n",
2124 ioc->name, __func__));
2127 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2128 ioc->name, __func__,
2129 ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo));
2135 mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP,
2140 ioc->ctl_cmds.status = MPT3_CMD_NOT_USED;
2146 #ifdef CONFIG_COMPAT
2148 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2149 * @ioc: per adapter object
2150 * @cmd - ioctl opcode
2151 * @arg - (struct mpt3_ioctl_command32)
2153 * MPT3COMMAND32 - Handle 32bit applications running on 64bit os.
2156 _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER *ioc, unsigned cmd,
2159 struct mpt3_ioctl_command32 karg32;
2160 struct mpt3_ioctl_command32 __user *uarg;
2161 struct mpt3_ioctl_command karg;
2163 if (_IOC_SIZE(cmd) != sizeof(struct mpt3_ioctl_command32))
2166 uarg = (struct mpt3_ioctl_command32 __user *) arg;
2168 if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) {
2169 pr_err("failure at %s:%d/%s()!\n",
2170 __FILE__, __LINE__, __func__);
2174 memset(&karg, 0, sizeof(struct mpt3_ioctl_command));
2175 karg.hdr.ioc_number = karg32.hdr.ioc_number;
2176 karg.hdr.port_number = karg32.hdr.port_number;
2177 karg.hdr.max_data_size = karg32.hdr.max_data_size;
2178 karg.timeout = karg32.timeout;
2179 karg.max_reply_bytes = karg32.max_reply_bytes;
2180 karg.data_in_size = karg32.data_in_size;
2181 karg.data_out_size = karg32.data_out_size;
2182 karg.max_sense_bytes = karg32.max_sense_bytes;
2183 karg.data_sge_offset = karg32.data_sge_offset;
2184 karg.reply_frame_buf_ptr = compat_ptr(karg32.reply_frame_buf_ptr);
2185 karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr);
2186 karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr);
2187 karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr);
2188 return _ctl_do_mpt_command(ioc, karg, &uarg->mf);
2193 * _ctl_ioctl_main - main ioctl entry point
2194 * @file - (struct file)
2195 * @cmd - ioctl opcode
2197 * compat - handles 32 bit applications in 64bit os
2200 _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg,
2203 struct MPT3SAS_ADAPTER *ioc;
2204 struct mpt3_ioctl_header ioctl_header;
2205 enum block_state state;
2208 /* get IOCTL header */
2209 if (copy_from_user(&ioctl_header, (char __user *)arg,
2210 sizeof(struct mpt3_ioctl_header))) {
2211 pr_err("failure at %s:%d/%s()!\n",
2212 __FILE__, __LINE__, __func__);
2216 if (_ctl_verify_adapter(ioctl_header.ioc_number, &ioc) == -1 || !ioc)
2219 if (ioc->shost_recovery || ioc->pci_error_recovery ||
2220 ioc->is_driver_loading)
2223 state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING;
2224 if (state == NON_BLOCKING) {
2225 if (!mutex_trylock(&ioc->ctl_cmds.mutex))
2227 } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex))
2228 return -ERESTARTSYS;
2233 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_iocinfo))
2234 ret = _ctl_getiocinfo(ioc, arg);
2236 #ifdef CONFIG_COMPAT
2241 struct mpt3_ioctl_command __user *uarg;
2242 struct mpt3_ioctl_command karg;
2244 #ifdef CONFIG_COMPAT
2246 ret = _ctl_compat_mpt_command(ioc, cmd, arg);
2250 if (copy_from_user(&karg, arg, sizeof(karg))) {
2251 pr_err("failure at %s:%d/%s()!\n",
2252 __FILE__, __LINE__, __func__);
2257 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_command)) {
2259 ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf);
2263 case MPT3EVENTQUERY:
2264 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventquery))
2265 ret = _ctl_eventquery(ioc, arg);
2267 case MPT3EVENTENABLE:
2268 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventenable))
2269 ret = _ctl_eventenable(ioc, arg);
2271 case MPT3EVENTREPORT:
2272 ret = _ctl_eventreport(ioc, arg);
2275 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_diag_reset))
2276 ret = _ctl_do_reset(ioc, arg);
2278 case MPT3BTDHMAPPING:
2279 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_btdh_mapping))
2280 ret = _ctl_btdh_mapping(ioc, arg);
2282 case MPT3DIAGREGISTER:
2283 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_register))
2284 ret = _ctl_diag_register(ioc, arg);
2286 case MPT3DIAGUNREGISTER:
2287 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_unregister))
2288 ret = _ctl_diag_unregister(ioc, arg);
2291 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_query))
2292 ret = _ctl_diag_query(ioc, arg);
2294 case MPT3DIAGRELEASE:
2295 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_release))
2296 ret = _ctl_diag_release(ioc, arg);
2298 case MPT3DIAGREADBUFFER:
2299 if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_read_buffer))
2300 ret = _ctl_diag_read_buffer(ioc, arg);
2303 dctlprintk(ioc, pr_info(MPT3SAS_FMT
2304 "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd));
2308 mutex_unlock(&ioc->ctl_cmds.mutex);
2313 * _ctl_ioctl - main ioctl entry point (unlocked)
2314 * @file - (struct file)
2315 * @cmd - ioctl opcode
2319 _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2323 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0);
2327 #ifdef CONFIG_COMPAT
2329 * _ctl_ioctl_compat - main ioctl entry point (compat)
2334 * This routine handles 32 bit applications in 64bit os.
2337 _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2341 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1);
2346 /* scsi host attributes */
2348 * _ctl_version_fw_show - firmware version
2349 * @cdev - pointer to embedded class device
2350 * @buf - the buffer returned
2352 * A sysfs 'read-only' shost attribute.
2355 _ctl_version_fw_show(struct device *cdev, struct device_attribute *attr,
2358 struct Scsi_Host *shost = class_to_shost(cdev);
2359 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2361 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2362 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2363 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2364 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2365 ioc->facts.FWVersion.Word & 0x000000FF);
2367 static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL);
2370 * _ctl_version_bios_show - bios version
2371 * @cdev - pointer to embedded class device
2372 * @buf - the buffer returned
2374 * A sysfs 'read-only' shost attribute.
2377 _ctl_version_bios_show(struct device *cdev, struct device_attribute *attr,
2380 struct Scsi_Host *shost = class_to_shost(cdev);
2381 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2383 u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
2385 return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
2386 (version & 0xFF000000) >> 24,
2387 (version & 0x00FF0000) >> 16,
2388 (version & 0x0000FF00) >> 8,
2389 version & 0x000000FF);
2391 static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL);
2394 * _ctl_version_mpi_show - MPI (message passing interface) version
2395 * @cdev - pointer to embedded class device
2396 * @buf - the buffer returned
2398 * A sysfs 'read-only' shost attribute.
2401 _ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr,
2404 struct Scsi_Host *shost = class_to_shost(cdev);
2405 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2407 return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
2408 ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
2410 static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL);
2413 * _ctl_version_product_show - product name
2414 * @cdev - pointer to embedded class device
2415 * @buf - the buffer returned
2417 * A sysfs 'read-only' shost attribute.
2420 _ctl_version_product_show(struct device *cdev, struct device_attribute *attr,
2423 struct Scsi_Host *shost = class_to_shost(cdev);
2424 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2426 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
2428 static DEVICE_ATTR(version_product, S_IRUGO, _ctl_version_product_show, NULL);
2431 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2432 * @cdev - pointer to embedded class device
2433 * @buf - the buffer returned
2435 * A sysfs 'read-only' shost attribute.
2438 _ctl_version_nvdata_persistent_show(struct device *cdev,
2439 struct device_attribute *attr, char *buf)
2441 struct Scsi_Host *shost = class_to_shost(cdev);
2442 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2444 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2445 le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
2447 static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
2448 _ctl_version_nvdata_persistent_show, NULL);
2451 * _ctl_version_nvdata_default_show - nvdata default version
2452 * @cdev - pointer to embedded class device
2453 * @buf - the buffer returned
2455 * A sysfs 'read-only' shost attribute.
2458 _ctl_version_nvdata_default_show(struct device *cdev, struct device_attribute
2461 struct Scsi_Host *shost = class_to_shost(cdev);
2462 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2464 return snprintf(buf, PAGE_SIZE, "%08xh\n",
2465 le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
2467 static DEVICE_ATTR(version_nvdata_default, S_IRUGO,
2468 _ctl_version_nvdata_default_show, NULL);
2471 * _ctl_board_name_show - board name
2472 * @cdev - pointer to embedded class device
2473 * @buf - the buffer returned
2475 * A sysfs 'read-only' shost attribute.
2478 _ctl_board_name_show(struct device *cdev, struct device_attribute *attr,
2481 struct Scsi_Host *shost = class_to_shost(cdev);
2482 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2484 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
2486 static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL);
2489 * _ctl_board_assembly_show - board assembly name
2490 * @cdev - pointer to embedded class device
2491 * @buf - the buffer returned
2493 * A sysfs 'read-only' shost attribute.
2496 _ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr,
2499 struct Scsi_Host *shost = class_to_shost(cdev);
2500 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2502 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
2504 static DEVICE_ATTR(board_assembly, S_IRUGO, _ctl_board_assembly_show, NULL);
2507 * _ctl_board_tracer_show - board tracer number
2508 * @cdev - pointer to embedded class device
2509 * @buf - the buffer returned
2511 * A sysfs 'read-only' shost attribute.
2514 _ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr,
2517 struct Scsi_Host *shost = class_to_shost(cdev);
2518 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2520 return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
2522 static DEVICE_ATTR(board_tracer, S_IRUGO, _ctl_board_tracer_show, NULL);
2525 * _ctl_io_delay_show - io missing delay
2526 * @cdev - pointer to embedded class device
2527 * @buf - the buffer returned
2529 * This is for firmware implemention for deboucing device
2532 * A sysfs 'read-only' shost attribute.
2535 _ctl_io_delay_show(struct device *cdev, struct device_attribute *attr,
2538 struct Scsi_Host *shost = class_to_shost(cdev);
2539 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2541 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
2543 static DEVICE_ATTR(io_delay, S_IRUGO, _ctl_io_delay_show, NULL);
2546 * _ctl_device_delay_show - device missing delay
2547 * @cdev - pointer to embedded class device
2548 * @buf - the buffer returned
2550 * This is for firmware implemention for deboucing device
2553 * A sysfs 'read-only' shost attribute.
2556 _ctl_device_delay_show(struct device *cdev, struct device_attribute *attr,
2559 struct Scsi_Host *shost = class_to_shost(cdev);
2560 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2562 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
2564 static DEVICE_ATTR(device_delay, S_IRUGO, _ctl_device_delay_show, NULL);
2567 * _ctl_fw_queue_depth_show - global credits
2568 * @cdev - pointer to embedded class device
2569 * @buf - the buffer returned
2571 * This is firmware queue depth limit
2573 * A sysfs 'read-only' shost attribute.
2576 _ctl_fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
2579 struct Scsi_Host *shost = class_to_shost(cdev);
2580 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2582 return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
2584 static DEVICE_ATTR(fw_queue_depth, S_IRUGO, _ctl_fw_queue_depth_show, NULL);
2587 * _ctl_sas_address_show - sas address
2588 * @cdev - pointer to embedded class device
2589 * @buf - the buffer returned
2591 * This is the controller sas address
2593 * A sysfs 'read-only' shost attribute.
2596 _ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr,
2600 struct Scsi_Host *shost = class_to_shost(cdev);
2601 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2603 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
2604 (unsigned long long)ioc->sas_hba.sas_address);
2606 static DEVICE_ATTR(host_sas_address, S_IRUGO,
2607 _ctl_host_sas_address_show, NULL);
2610 * _ctl_logging_level_show - logging level
2611 * @cdev - pointer to embedded class device
2612 * @buf - the buffer returned
2614 * A sysfs 'read/write' shost attribute.
2617 _ctl_logging_level_show(struct device *cdev, struct device_attribute *attr,
2620 struct Scsi_Host *shost = class_to_shost(cdev);
2621 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2623 return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
2626 _ctl_logging_level_store(struct device *cdev, struct device_attribute *attr,
2627 const char *buf, size_t count)
2629 struct Scsi_Host *shost = class_to_shost(cdev);
2630 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2633 if (sscanf(buf, "%x", &val) != 1)
2636 ioc->logging_level = val;
2637 pr_info(MPT3SAS_FMT "logging_level=%08xh\n", ioc->name,
2638 ioc->logging_level);
2641 static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR, _ctl_logging_level_show,
2642 _ctl_logging_level_store);
2645 * _ctl_fwfault_debug_show - show/store fwfault_debug
2646 * @cdev - pointer to embedded class device
2647 * @buf - the buffer returned
2649 * mpt3sas_fwfault_debug is command line option
2650 * A sysfs 'read/write' shost attribute.
2653 _ctl_fwfault_debug_show(struct device *cdev, struct device_attribute *attr,
2656 struct Scsi_Host *shost = class_to_shost(cdev);
2657 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2659 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
2662 _ctl_fwfault_debug_store(struct device *cdev, struct device_attribute *attr,
2663 const char *buf, size_t count)
2665 struct Scsi_Host *shost = class_to_shost(cdev);
2666 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2669 if (sscanf(buf, "%d", &val) != 1)
2672 ioc->fwfault_debug = val;
2673 pr_info(MPT3SAS_FMT "fwfault_debug=%d\n", ioc->name,
2674 ioc->fwfault_debug);
2677 static DEVICE_ATTR(fwfault_debug, S_IRUGO | S_IWUSR,
2678 _ctl_fwfault_debug_show, _ctl_fwfault_debug_store);
2681 * _ctl_ioc_reset_count_show - ioc reset count
2682 * @cdev - pointer to embedded class device
2683 * @buf - the buffer returned
2685 * This is firmware queue depth limit
2687 * A sysfs 'read-only' shost attribute.
2690 _ctl_ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
2693 struct Scsi_Host *shost = class_to_shost(cdev);
2694 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2696 return snprintf(buf, PAGE_SIZE, "%d\n", ioc->ioc_reset_count);
2698 static DEVICE_ATTR(ioc_reset_count, S_IRUGO, _ctl_ioc_reset_count_show, NULL);
2701 * _ctl_ioc_reply_queue_count_show - number of reply queues
2702 * @cdev - pointer to embedded class device
2703 * @buf - the buffer returned
2705 * This is number of reply queues
2707 * A sysfs 'read-only' shost attribute.
2710 _ctl_ioc_reply_queue_count_show(struct device *cdev,
2711 struct device_attribute *attr, char *buf)
2713 u8 reply_queue_count;
2714 struct Scsi_Host *shost = class_to_shost(cdev);
2715 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2717 if ((ioc->facts.IOCCapabilities &
2718 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable)
2719 reply_queue_count = ioc->reply_queue_count;
2721 reply_queue_count = 1;
2723 return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count);
2725 static DEVICE_ATTR(reply_queue_count, S_IRUGO, _ctl_ioc_reply_queue_count_show,
2728 struct DIAG_BUFFER_START {
2739 * _ctl_host_trace_buffer_size_show - host buffer size (trace only)
2740 * @cdev - pointer to embedded class device
2741 * @buf - the buffer returned
2743 * A sysfs 'read-only' shost attribute.
2746 _ctl_host_trace_buffer_size_show(struct device *cdev,
2747 struct device_attribute *attr, char *buf)
2749 struct Scsi_Host *shost = class_to_shost(cdev);
2750 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2752 struct DIAG_BUFFER_START *request_data;
2754 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
2756 "%s: host_trace_buffer is not registered\n",
2757 ioc->name, __func__);
2761 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2762 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
2764 "%s: host_trace_buffer is not registered\n",
2765 ioc->name, __func__);
2769 request_data = (struct DIAG_BUFFER_START *)
2770 ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE];
2771 if ((le32_to_cpu(request_data->DiagVersion) == 0x00000000 ||
2772 le32_to_cpu(request_data->DiagVersion) == 0x01000000 ||
2773 le32_to_cpu(request_data->DiagVersion) == 0x01010000) &&
2774 le32_to_cpu(request_data->Reserved3) == 0x4742444c)
2775 size = le32_to_cpu(request_data->Size);
2777 ioc->ring_buffer_sz = size;
2778 return snprintf(buf, PAGE_SIZE, "%d\n", size);
2780 static DEVICE_ATTR(host_trace_buffer_size, S_IRUGO,
2781 _ctl_host_trace_buffer_size_show, NULL);
2784 * _ctl_host_trace_buffer_show - firmware ring buffer (trace only)
2785 * @cdev - pointer to embedded class device
2786 * @buf - the buffer returned
2788 * A sysfs 'read/write' shost attribute.
2790 * You will only be able to read 4k bytes of ring buffer at a time.
2791 * In order to read beyond 4k bytes, you will have to write out the
2792 * offset to the same attribute, it will move the pointer.
2795 _ctl_host_trace_buffer_show(struct device *cdev, struct device_attribute *attr,
2798 struct Scsi_Host *shost = class_to_shost(cdev);
2799 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2803 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
2805 "%s: host_trace_buffer is not registered\n",
2806 ioc->name, __func__);
2810 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2811 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
2813 "%s: host_trace_buffer is not registered\n",
2814 ioc->name, __func__);
2818 if (ioc->ring_buffer_offset > ioc->ring_buffer_sz)
2821 size = ioc->ring_buffer_sz - ioc->ring_buffer_offset;
2822 size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size;
2823 request_data = ioc->diag_buffer[0] + ioc->ring_buffer_offset;
2824 memcpy(buf, request_data, size);
2829 _ctl_host_trace_buffer_store(struct device *cdev, struct device_attribute *attr,
2830 const char *buf, size_t count)
2832 struct Scsi_Host *shost = class_to_shost(cdev);
2833 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2836 if (sscanf(buf, "%d", &val) != 1)
2839 ioc->ring_buffer_offset = val;
2842 static DEVICE_ATTR(host_trace_buffer, S_IRUGO | S_IWUSR,
2843 _ctl_host_trace_buffer_show, _ctl_host_trace_buffer_store);
2846 /*****************************************/
2849 * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only)
2850 * @cdev - pointer to embedded class device
2851 * @buf - the buffer returned
2853 * A sysfs 'read/write' shost attribute.
2855 * This is a mechnism to post/release host_trace_buffers
2858 _ctl_host_trace_buffer_enable_show(struct device *cdev,
2859 struct device_attribute *attr, char *buf)
2861 struct Scsi_Host *shost = class_to_shost(cdev);
2862 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2864 if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) ||
2865 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2866 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0))
2867 return snprintf(buf, PAGE_SIZE, "off\n");
2868 else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2869 MPT3_DIAG_BUFFER_IS_RELEASED))
2870 return snprintf(buf, PAGE_SIZE, "release\n");
2872 return snprintf(buf, PAGE_SIZE, "post\n");
2876 _ctl_host_trace_buffer_enable_store(struct device *cdev,
2877 struct device_attribute *attr, const char *buf, size_t count)
2879 struct Scsi_Host *shost = class_to_shost(cdev);
2880 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2882 struct mpt3_diag_register diag_register;
2885 /* don't allow post/release occurr while recovery is active */
2886 if (ioc->shost_recovery || ioc->remove_host ||
2887 ioc->pci_error_recovery || ioc->is_driver_loading)
2890 if (sscanf(buf, "%9s", str) != 1)
2893 if (!strcmp(str, "post")) {
2894 /* exit out if host buffers are already posted */
2895 if ((ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) &&
2896 (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2897 MPT3_DIAG_BUFFER_IS_REGISTERED) &&
2898 ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2899 MPT3_DIAG_BUFFER_IS_RELEASED) == 0))
2901 memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
2902 pr_info(MPT3SAS_FMT "posting host trace buffers\n",
2904 diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
2905 diag_register.requested_buffer_size = (1024 * 1024);
2906 diag_register.unique_id = 0x7075900;
2907 ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] = 0;
2908 _ctl_diag_register_2(ioc, &diag_register);
2909 } else if (!strcmp(str, "release")) {
2910 /* exit out if host buffers are already released */
2911 if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE])
2913 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2914 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0)
2916 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
2917 MPT3_DIAG_BUFFER_IS_RELEASED))
2919 pr_info(MPT3SAS_FMT "releasing host trace buffer\n",
2921 mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE,
2928 static DEVICE_ATTR(host_trace_buffer_enable, S_IRUGO | S_IWUSR,
2929 _ctl_host_trace_buffer_enable_show,
2930 _ctl_host_trace_buffer_enable_store);
2932 /*********** diagnostic trigger suppport *********************************/
2935 * _ctl_diag_trigger_master_show - show the diag_trigger_master attribute
2936 * @cdev - pointer to embedded class device
2937 * @buf - the buffer returned
2939 * A sysfs 'read/write' shost attribute.
2942 _ctl_diag_trigger_master_show(struct device *cdev,
2943 struct device_attribute *attr, char *buf)
2946 struct Scsi_Host *shost = class_to_shost(cdev);
2947 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2948 unsigned long flags;
2951 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
2952 rc = sizeof(struct SL_WH_MASTER_TRIGGER_T);
2953 memcpy(buf, &ioc->diag_trigger_master, rc);
2954 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
2959 * _ctl_diag_trigger_master_store - store the diag_trigger_master attribute
2960 * @cdev - pointer to embedded class device
2961 * @buf - the buffer returned
2963 * A sysfs 'read/write' shost attribute.
2966 _ctl_diag_trigger_master_store(struct device *cdev,
2967 struct device_attribute *attr, const char *buf, size_t count)
2970 struct Scsi_Host *shost = class_to_shost(cdev);
2971 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
2972 unsigned long flags;
2975 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
2976 rc = min(sizeof(struct SL_WH_MASTER_TRIGGER_T), count);
2977 memset(&ioc->diag_trigger_master, 0,
2978 sizeof(struct SL_WH_MASTER_TRIGGER_T));
2979 memcpy(&ioc->diag_trigger_master, buf, rc);
2980 ioc->diag_trigger_master.MasterData |=
2981 (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET);
2982 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
2985 static DEVICE_ATTR(diag_trigger_master, S_IRUGO | S_IWUSR,
2986 _ctl_diag_trigger_master_show, _ctl_diag_trigger_master_store);
2990 * _ctl_diag_trigger_event_show - show the diag_trigger_event attribute
2991 * @cdev - pointer to embedded class device
2992 * @buf - the buffer returned
2994 * A sysfs 'read/write' shost attribute.
2997 _ctl_diag_trigger_event_show(struct device *cdev,
2998 struct device_attribute *attr, char *buf)
3000 struct Scsi_Host *shost = class_to_shost(cdev);
3001 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3002 unsigned long flags;
3005 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3006 rc = sizeof(struct SL_WH_EVENT_TRIGGERS_T);
3007 memcpy(buf, &ioc->diag_trigger_event, rc);
3008 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3013 * _ctl_diag_trigger_event_store - store the diag_trigger_event attribute
3014 * @cdev - pointer to embedded class device
3015 * @buf - the buffer returned
3017 * A sysfs 'read/write' shost attribute.
3020 _ctl_diag_trigger_event_store(struct device *cdev,
3021 struct device_attribute *attr, const char *buf, size_t count)
3024 struct Scsi_Host *shost = class_to_shost(cdev);
3025 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3026 unsigned long flags;
3029 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3030 sz = min(sizeof(struct SL_WH_EVENT_TRIGGERS_T), count);
3031 memset(&ioc->diag_trigger_event, 0,
3032 sizeof(struct SL_WH_EVENT_TRIGGERS_T));
3033 memcpy(&ioc->diag_trigger_event, buf, sz);
3034 if (ioc->diag_trigger_event.ValidEntries > NUM_VALID_ENTRIES)
3035 ioc->diag_trigger_event.ValidEntries = NUM_VALID_ENTRIES;
3036 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3039 static DEVICE_ATTR(diag_trigger_event, S_IRUGO | S_IWUSR,
3040 _ctl_diag_trigger_event_show, _ctl_diag_trigger_event_store);
3044 * _ctl_diag_trigger_scsi_show - show the diag_trigger_scsi attribute
3045 * @cdev - pointer to embedded class device
3046 * @buf - the buffer returned
3048 * A sysfs 'read/write' shost attribute.
3051 _ctl_diag_trigger_scsi_show(struct device *cdev,
3052 struct device_attribute *attr, char *buf)
3054 struct Scsi_Host *shost = class_to_shost(cdev);
3055 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3056 unsigned long flags;
3059 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3060 rc = sizeof(struct SL_WH_SCSI_TRIGGERS_T);
3061 memcpy(buf, &ioc->diag_trigger_scsi, rc);
3062 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3067 * _ctl_diag_trigger_scsi_store - store the diag_trigger_scsi attribute
3068 * @cdev - pointer to embedded class device
3069 * @buf - the buffer returned
3071 * A sysfs 'read/write' shost attribute.
3074 _ctl_diag_trigger_scsi_store(struct device *cdev,
3075 struct device_attribute *attr, const char *buf, size_t count)
3077 struct Scsi_Host *shost = class_to_shost(cdev);
3078 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3079 unsigned long flags;
3082 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3083 sz = min(sizeof(struct SL_WH_SCSI_TRIGGERS_T), count);
3084 memset(&ioc->diag_trigger_scsi, 0,
3085 sizeof(struct SL_WH_EVENT_TRIGGERS_T));
3086 memcpy(&ioc->diag_trigger_scsi, buf, sz);
3087 if (ioc->diag_trigger_scsi.ValidEntries > NUM_VALID_ENTRIES)
3088 ioc->diag_trigger_scsi.ValidEntries = NUM_VALID_ENTRIES;
3089 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3092 static DEVICE_ATTR(diag_trigger_scsi, S_IRUGO | S_IWUSR,
3093 _ctl_diag_trigger_scsi_show, _ctl_diag_trigger_scsi_store);
3097 * _ctl_diag_trigger_scsi_show - show the diag_trigger_mpi attribute
3098 * @cdev - pointer to embedded class device
3099 * @buf - the buffer returned
3101 * A sysfs 'read/write' shost attribute.
3104 _ctl_diag_trigger_mpi_show(struct device *cdev,
3105 struct device_attribute *attr, char *buf)
3107 struct Scsi_Host *shost = class_to_shost(cdev);
3108 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3109 unsigned long flags;
3112 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3113 rc = sizeof(struct SL_WH_MPI_TRIGGERS_T);
3114 memcpy(buf, &ioc->diag_trigger_mpi, rc);
3115 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3120 * _ctl_diag_trigger_mpi_store - store the diag_trigger_mpi attribute
3121 * @cdev - pointer to embedded class device
3122 * @buf - the buffer returned
3124 * A sysfs 'read/write' shost attribute.
3127 _ctl_diag_trigger_mpi_store(struct device *cdev,
3128 struct device_attribute *attr, const char *buf, size_t count)
3130 struct Scsi_Host *shost = class_to_shost(cdev);
3131 struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
3132 unsigned long flags;
3135 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
3136 sz = min(sizeof(struct SL_WH_MPI_TRIGGERS_T), count);
3137 memset(&ioc->diag_trigger_mpi, 0,
3138 sizeof(ioc->diag_trigger_mpi));
3139 memcpy(&ioc->diag_trigger_mpi, buf, sz);
3140 if (ioc->diag_trigger_mpi.ValidEntries > NUM_VALID_ENTRIES)
3141 ioc->diag_trigger_mpi.ValidEntries = NUM_VALID_ENTRIES;
3142 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
3146 static DEVICE_ATTR(diag_trigger_mpi, S_IRUGO | S_IWUSR,
3147 _ctl_diag_trigger_mpi_show, _ctl_diag_trigger_mpi_store);
3149 /*********** diagnostic trigger suppport *** END ****************************/
3153 /*****************************************/
3155 struct device_attribute *mpt3sas_host_attrs[] = {
3156 &dev_attr_version_fw,
3157 &dev_attr_version_bios,
3158 &dev_attr_version_mpi,
3159 &dev_attr_version_product,
3160 &dev_attr_version_nvdata_persistent,
3161 &dev_attr_version_nvdata_default,
3162 &dev_attr_board_name,
3163 &dev_attr_board_assembly,
3164 &dev_attr_board_tracer,
3166 &dev_attr_device_delay,
3167 &dev_attr_logging_level,
3168 &dev_attr_fwfault_debug,
3169 &dev_attr_fw_queue_depth,
3170 &dev_attr_host_sas_address,
3171 &dev_attr_ioc_reset_count,
3172 &dev_attr_host_trace_buffer_size,
3173 &dev_attr_host_trace_buffer,
3174 &dev_attr_host_trace_buffer_enable,
3175 &dev_attr_reply_queue_count,
3176 &dev_attr_diag_trigger_master,
3177 &dev_attr_diag_trigger_event,
3178 &dev_attr_diag_trigger_scsi,
3179 &dev_attr_diag_trigger_mpi,
3183 /* device attributes */
3186 * _ctl_device_sas_address_show - sas address
3187 * @cdev - pointer to embedded class device
3188 * @buf - the buffer returned
3190 * This is the sas address for the target
3192 * A sysfs 'read-only' shost attribute.
3195 _ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr,
3198 struct scsi_device *sdev = to_scsi_device(dev);
3199 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3201 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
3202 (unsigned long long)sas_device_priv_data->sas_target->sas_address);
3204 static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL);
3207 * _ctl_device_handle_show - device handle
3208 * @cdev - pointer to embedded class device
3209 * @buf - the buffer returned
3211 * This is the firmware assigned device handle
3213 * A sysfs 'read-only' shost attribute.
3216 _ctl_device_handle_show(struct device *dev, struct device_attribute *attr,
3219 struct scsi_device *sdev = to_scsi_device(dev);
3220 struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
3222 return snprintf(buf, PAGE_SIZE, "0x%04x\n",
3223 sas_device_priv_data->sas_target->handle);
3225 static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL);
3227 struct device_attribute *mpt3sas_dev_attrs[] = {
3228 &dev_attr_sas_address,
3229 &dev_attr_sas_device_handle,
3233 static const struct file_operations ctl_fops = {
3234 .owner = THIS_MODULE,
3235 .unlocked_ioctl = _ctl_ioctl,
3236 .release = _ctl_release,
3238 .fasync = _ctl_fasync,
3239 #ifdef CONFIG_COMPAT
3240 .compat_ioctl = _ctl_ioctl_compat,
3244 static struct miscdevice ctl_dev = {
3245 .minor = MPT3SAS_MINOR,
3246 .name = MPT3SAS_DEV_NAME,
3251 * mpt3sas_ctl_init - main entry point for ctl.
3255 mpt3sas_ctl_init(void)
3258 if (misc_register(&ctl_dev) < 0)
3259 pr_err("%s can't register misc device [minor=%d]\n",
3260 MPT3SAS_DRIVER_NAME, MPT3SAS_MINOR);
3262 init_waitqueue_head(&ctl_poll_wait);
3266 * mpt3sas_ctl_exit - exit point for ctl
3270 mpt3sas_ctl_exit(void)
3272 struct MPT3SAS_ADAPTER *ioc;
3275 list_for_each_entry(ioc, &mpt3sas_ioc_list, list) {
3277 /* free memory associated to diag buffers */
3278 for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) {
3279 if (!ioc->diag_buffer[i])
3281 if (!(ioc->diag_buffer_status[i] &
3282 MPT3_DIAG_BUFFER_IS_REGISTERED))
3284 if ((ioc->diag_buffer_status[i] &
3285 MPT3_DIAG_BUFFER_IS_RELEASED))
3287 pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i],
3288 ioc->diag_buffer[i], ioc->diag_buffer_dma[i]);
3289 ioc->diag_buffer[i] = NULL;
3290 ioc->diag_buffer_status[i] = 0;
3293 kfree(ioc->event_log);
3295 misc_deregister(&ctl_dev);