2 * Management Module Support for MPT (Message Passing Technology) based
5 * This code is based on drivers/scsi/mpt3sas/mpt3sas_ctl.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * Copyright (C) 2013-2014 Avago Technologies
8 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 * solely responsible for determining the appropriateness of using and
26 * distributing the Program and assumes all risks associated with its
27 * exercise of rights under this Agreement, including but not limited to
28 * the risks and costs of program errors, damage to or loss of data,
29 * programs or equipment, and unavailability or interruption of operations.
31 * DISCLAIMER OF LIABILITY
32 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/slab.h>
51 #include <linux/types.h>
52 #include <linux/pci.h>
53 #include <linux/delay.h>
54 #include <linux/compat.h>
55 #include <linux/poll.h>
58 #include <linux/uaccess.h>
60 #include "mpt3sas_base.h"
61 #include "mpt3sas_ctl.h"
64 static struct fasync_struct
*async_queue
;
65 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait
);
69 * enum block_state - blocking state
70 * @NON_BLOCKING: non blocking
73 * These states are for ioctls that need to wait for a response
74 * from firmware, so they probably require sleep.
82 * _ctl_display_some_debug - debug routine
83 * @ioc: per adapter object
84 * @smid: system request message index
85 * @calling_function_name: string pass from calling function
86 * @mpi_reply: reply message frame
89 * Function for displaying debug info helpful when debugging issues
93 _ctl_display_some_debug(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
94 char *calling_function_name
, MPI2DefaultReply_t
*mpi_reply
)
96 Mpi2ConfigRequest_t
*mpi_request
;
99 if (!(ioc
->logging_level
& MPT_DEBUG_IOCTL
))
102 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
103 switch (mpi_request
->Function
) {
104 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
106 Mpi2SCSIIORequest_t
*scsi_request
=
107 (Mpi2SCSIIORequest_t
*)mpi_request
;
109 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
110 "scsi_io, cmd(0x%02x), cdb_len(%d)",
111 scsi_request
->CDB
.CDB32
[0],
112 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
113 desc
= ioc
->tmp_string
;
116 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
119 case MPI2_FUNCTION_IOC_INIT
:
122 case MPI2_FUNCTION_IOC_FACTS
:
125 case MPI2_FUNCTION_CONFIG
:
127 Mpi2ConfigRequest_t
*config_request
=
128 (Mpi2ConfigRequest_t
*)mpi_request
;
130 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
131 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
132 (config_request
->Header
.PageType
&
133 MPI2_CONFIG_PAGETYPE_MASK
), config_request
->ExtPageType
,
134 config_request
->Header
.PageNumber
);
135 desc
= ioc
->tmp_string
;
138 case MPI2_FUNCTION_PORT_FACTS
:
141 case MPI2_FUNCTION_PORT_ENABLE
:
142 desc
= "port_enable";
144 case MPI2_FUNCTION_EVENT_NOTIFICATION
:
145 desc
= "event_notification";
147 case MPI2_FUNCTION_FW_DOWNLOAD
:
148 desc
= "fw_download";
150 case MPI2_FUNCTION_FW_UPLOAD
:
153 case MPI2_FUNCTION_RAID_ACTION
:
154 desc
= "raid_action";
156 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
158 Mpi2SCSIIORequest_t
*scsi_request
=
159 (Mpi2SCSIIORequest_t
*)mpi_request
;
161 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
162 "raid_pass, cmd(0x%02x), cdb_len(%d)",
163 scsi_request
->CDB
.CDB32
[0],
164 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
165 desc
= ioc
->tmp_string
;
168 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
169 desc
= "sas_iounit_cntl";
171 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
174 case MPI2_FUNCTION_DIAG_BUFFER_POST
:
175 desc
= "diag_buffer_post";
177 case MPI2_FUNCTION_DIAG_RELEASE
:
178 desc
= "diag_release";
180 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
181 desc
= "smp_passthrough";
183 case MPI2_FUNCTION_TOOLBOX
:
186 case MPI2_FUNCTION_NVME_ENCAPSULATED
:
187 desc
= "nvme_encapsulated";
194 ioc_info(ioc
, "%s: %s, smid(%d)\n", calling_function_name
, desc
, smid
);
199 if (mpi_reply
->IOCStatus
|| mpi_reply
->IOCLogInfo
)
200 ioc_info(ioc
, "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
201 le16_to_cpu(mpi_reply
->IOCStatus
),
202 le32_to_cpu(mpi_reply
->IOCLogInfo
));
204 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
205 mpi_request
->Function
==
206 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
207 Mpi2SCSIIOReply_t
*scsi_reply
=
208 (Mpi2SCSIIOReply_t
*)mpi_reply
;
209 struct _sas_device
*sas_device
= NULL
;
210 struct _pcie_device
*pcie_device
= NULL
;
212 sas_device
= mpt3sas_get_sdev_by_handle(ioc
,
213 le16_to_cpu(scsi_reply
->DevHandle
));
215 ioc_warn(ioc
, "\tsas_address(0x%016llx), phy(%d)\n",
216 (u64
)sas_device
->sas_address
,
218 ioc_warn(ioc
, "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
219 (u64
)sas_device
->enclosure_logical_id
,
221 sas_device_put(sas_device
);
224 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
,
225 le16_to_cpu(scsi_reply
->DevHandle
));
227 ioc_warn(ioc
, "\tWWID(0x%016llx), port(%d)\n",
228 (unsigned long long)pcie_device
->wwid
,
229 pcie_device
->port_num
);
230 if (pcie_device
->enclosure_handle
!= 0)
231 ioc_warn(ioc
, "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
232 (u64
)pcie_device
->enclosure_logical_id
,
234 pcie_device_put(pcie_device
);
237 if (scsi_reply
->SCSIState
|| scsi_reply
->SCSIStatus
)
238 ioc_info(ioc
, "\tscsi_state(0x%02x), scsi_status(0x%02x)\n",
239 scsi_reply
->SCSIState
,
240 scsi_reply
->SCSIStatus
);
245 * mpt3sas_ctl_done - ctl module completion routine
246 * @ioc: per adapter object
247 * @smid: system request message index
248 * @msix_index: MSIX table index supplied by the OS
249 * @reply: reply message frame(lower 32bit addr)
252 * The callback handler when using ioc->ctl_cb_idx.
254 * Return: 1 meaning mf should be freed from _base_interrupt
255 * 0 means the mf is freed from this function.
258 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
261 MPI2DefaultReply_t
*mpi_reply
;
262 Mpi2SCSIIOReply_t
*scsiio_reply
;
263 Mpi26NVMeEncapsulatedErrorReply_t
*nvme_error_reply
;
264 const void *sense_data
;
267 if (ioc
->ctl_cmds
.status
== MPT3_CMD_NOT_USED
)
269 if (ioc
->ctl_cmds
.smid
!= smid
)
271 ioc
->ctl_cmds
.status
|= MPT3_CMD_COMPLETE
;
272 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
274 memcpy(ioc
->ctl_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
275 ioc
->ctl_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
277 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
278 mpi_reply
->Function
==
279 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
280 scsiio_reply
= (Mpi2SCSIIOReply_t
*)mpi_reply
;
281 if (scsiio_reply
->SCSIState
&
282 MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
283 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
284 le32_to_cpu(scsiio_reply
->SenseCount
));
285 sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
287 memcpy(ioc
->ctl_cmds
.sense
, sense_data
, sz
);
291 * Get Error Response data for NVMe device. The ctl_cmds.sense
292 * buffer is used to store the Error Response data.
294 if (mpi_reply
->Function
== MPI2_FUNCTION_NVME_ENCAPSULATED
) {
296 (Mpi26NVMeEncapsulatedErrorReply_t
*)mpi_reply
;
297 sz
= min_t(u32
, NVME_ERROR_RESPONSE_SIZE
,
298 le16_to_cpu(nvme_error_reply
->ErrorResponseCount
));
299 sense_data
= mpt3sas_base_get_sense_buffer(ioc
, smid
);
300 memcpy(ioc
->ctl_cmds
.sense
, sense_data
, sz
);
304 _ctl_display_some_debug(ioc
, smid
, "ctl_done", mpi_reply
);
305 ioc
->ctl_cmds
.status
&= ~MPT3_CMD_PENDING
;
306 complete(&ioc
->ctl_cmds
.done
);
311 * _ctl_check_event_type - determines when an event needs logging
312 * @ioc: per adapter object
313 * @event: firmware event
315 * The bitmask in ioc->event_type[] indicates which events should be
316 * be saved in the driver event_log. This bitmask is set by application.
318 * Return: 1 when event should be captured, or zero means no match.
321 _ctl_check_event_type(struct MPT3SAS_ADAPTER
*ioc
, u16 event
)
326 if (event
>= 128 || !event
|| !ioc
->event_log
)
329 desired_event
= (1 << (event
% 32));
333 return desired_event
& ioc
->event_type
[i
];
337 * mpt3sas_ctl_add_to_event_log - add event
338 * @ioc: per adapter object
339 * @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
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_pre_reset_handler - reset callback handler (for ctl)
458 * @ioc: per adapter object
460 * The handler for doing any required cleanup or initialization.
462 void mpt3sas_ctl_pre_reset_handler(struct MPT3SAS_ADAPTER
*ioc
)
467 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_PRE_RESET\n", __func__
));
468 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
469 if (!(ioc
->diag_buffer_status
[i
] &
470 MPT3_DIAG_BUFFER_IS_REGISTERED
))
472 if ((ioc
->diag_buffer_status
[i
] &
473 MPT3_DIAG_BUFFER_IS_RELEASED
))
477 * add a log message to indicate the release
480 "%s: Releasing the trace buffer due to adapter reset.",
482 ioc
->htb_rel
.buffer_rel_condition
=
483 MPT3_DIAG_BUFFER_REL_TRIGGER
;
484 mpt3sas_send_diag_release(ioc
, i
, &issue_reset
);
489 * mpt3sas_ctl_clear_outstanding_ioctls - clears outstanding ioctl cmd.
490 * @ioc: per adapter object
492 * The handler for doing any required cleanup or initialization.
494 void mpt3sas_ctl_clear_outstanding_ioctls(struct MPT3SAS_ADAPTER
*ioc
)
497 ioc_info(ioc
, "%s: clear outstanding ioctl cmd\n", __func__
));
498 if (ioc
->ctl_cmds
.status
& MPT3_CMD_PENDING
) {
499 ioc
->ctl_cmds
.status
|= MPT3_CMD_RESET
;
500 mpt3sas_base_free_smid(ioc
, ioc
->ctl_cmds
.smid
);
501 complete(&ioc
->ctl_cmds
.done
);
506 * mpt3sas_ctl_reset_done_handler - reset callback handler (for ctl)
507 * @ioc: per adapter object
509 * The handler for doing any required cleanup or initialization.
511 void mpt3sas_ctl_reset_done_handler(struct MPT3SAS_ADAPTER
*ioc
)
515 dtmprintk(ioc
, ioc_info(ioc
, "%s: MPT3_IOC_DONE_RESET\n", __func__
));
517 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
518 if (!(ioc
->diag_buffer_status
[i
] &
519 MPT3_DIAG_BUFFER_IS_REGISTERED
))
521 if ((ioc
->diag_buffer_status
[i
] &
522 MPT3_DIAG_BUFFER_IS_RELEASED
))
524 ioc
->diag_buffer_status
[i
] |=
525 MPT3_DIAG_BUFFER_IS_DIAG_RESET
;
535 * Called when application request fasyn callback handler.
538 _ctl_fasync(int fd
, struct file
*filep
, int mode
)
540 return fasync_helper(fd
, filep
, mode
, &async_queue
);
550 _ctl_poll(struct file
*filep
, poll_table
*wait
)
552 struct MPT3SAS_ADAPTER
*ioc
;
554 poll_wait(filep
, &ctl_poll_wait
, wait
);
556 /* global ioc lock to protect controller on list operations */
557 spin_lock(&gioc_lock
);
558 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
) {
559 if (ioc
->aen_event_read_flag
) {
560 spin_unlock(&gioc_lock
);
561 return EPOLLIN
| EPOLLRDNORM
;
564 spin_unlock(&gioc_lock
);
569 * _ctl_set_task_mid - assign an active smid to tm request
570 * @ioc: per adapter object
571 * @karg: (struct mpt3_ioctl_command)
572 * @tm_request: pointer to mf from user space
574 * Return: 0 when an smid if found, else fail.
575 * during failure, the reply frame is filled.
578 _ctl_set_task_mid(struct MPT3SAS_ADAPTER
*ioc
, struct mpt3_ioctl_command
*karg
,
579 Mpi2SCSITaskManagementRequest_t
*tm_request
)
584 struct scsi_cmnd
*scmd
;
585 struct MPT3SAS_DEVICE
*priv_data
;
586 Mpi2SCSITaskManagementReply_t
*tm_reply
;
591 if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
593 else if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
)
598 lun
= scsilun_to_int((struct scsi_lun
*)tm_request
->LUN
);
600 handle
= le16_to_cpu(tm_request
->DevHandle
);
601 for (smid
= ioc
->scsiio_depth
; smid
&& !found
; smid
--) {
602 struct scsiio_tracker
*st
;
605 scmd
= mpt3sas_scsih_scsi_lookup_get(ioc
, smid
);
608 if (lun
!= scmd
->device
->lun
)
610 priv_data
= scmd
->device
->hostdata
;
611 if (priv_data
->sas_target
== NULL
)
613 if (priv_data
->sas_target
->handle
!= handle
)
615 st
= scsi_cmd_priv(scmd
);
618 * If the given TaskMID from the user space is zero, then the
619 * first outstanding smid will be picked up. Otherwise,
620 * targeted smid will be the one.
622 task_mid
= cpu_to_le16(st
->smid
);
623 if (!tm_request
->TaskMID
)
624 tm_request
->TaskMID
= task_mid
;
625 found
= tm_request
->TaskMID
== task_mid
;
630 ioc_info(ioc
, "%s: handle(0x%04x), lun(%d), no active mid!!\n",
631 desc
, le16_to_cpu(tm_request
->DevHandle
),
633 tm_reply
= ioc
->ctl_cmds
.reply
;
634 tm_reply
->DevHandle
= tm_request
->DevHandle
;
635 tm_reply
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
636 tm_reply
->TaskType
= tm_request
->TaskType
;
637 tm_reply
->MsgLength
= sizeof(Mpi2SCSITaskManagementReply_t
)/4;
638 tm_reply
->VP_ID
= tm_request
->VP_ID
;
639 tm_reply
->VF_ID
= tm_request
->VF_ID
;
640 sz
= min_t(u32
, karg
->max_reply_bytes
, ioc
->reply_sz
);
641 if (copy_to_user(karg
->reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
643 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
649 ioc_info(ioc
, "%s: handle(0x%04x), lun(%d), task_mid(%d)\n",
650 desc
, le16_to_cpu(tm_request
->DevHandle
), lun
,
651 le16_to_cpu(tm_request
->TaskMID
)));
656 * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode
657 * @ioc: per adapter object
658 * @karg: (struct mpt3_ioctl_command)
659 * @mf: pointer to mf in user space
662 _ctl_do_mpt_command(struct MPT3SAS_ADAPTER
*ioc
, struct mpt3_ioctl_command karg
,
665 MPI2RequestHeader_t
*mpi_request
= NULL
, *request
;
666 MPI2DefaultReply_t
*mpi_reply
;
667 Mpi26NVMeEncapsulatedRequest_t
*nvme_encap_request
= NULL
;
668 struct _pcie_device
*pcie_device
= NULL
;
670 unsigned long timeout
;
674 void *data_out
= NULL
;
675 dma_addr_t data_out_dma
= 0;
676 size_t data_out_sz
= 0;
677 void *data_in
= NULL
;
678 dma_addr_t data_in_dma
= 0;
679 size_t data_in_sz
= 0;
681 u16 device_handle
= MPT3SAS_INVALID_DEVICE_HANDLE
;
685 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
686 ioc_err(ioc
, "%s: ctl_cmd in use\n", __func__
);
691 ret
= mpt3sas_wait_for_ioc(ioc
, IOC_OPERATIONAL_WAIT_COUNT
);
695 mpi_request
= kzalloc(ioc
->request_sz
, GFP_KERNEL
);
697 ioc_err(ioc
, "%s: failed obtaining a memory for mpi_request\n",
703 /* Check for overflow and wraparound */
704 if (karg
.data_sge_offset
* 4 > ioc
->request_sz
||
705 karg
.data_sge_offset
> (UINT_MAX
/ 4)) {
710 /* copy in request message frame from user */
711 if (copy_from_user(mpi_request
, mf
, karg
.data_sge_offset
*4)) {
712 pr_err("failure at %s:%d/%s()!\n", __FILE__
, __LINE__
,
718 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
719 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->ctl_cb_idx
);
721 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
726 /* Use first reserved smid for passthrough ioctls */
727 smid
= ioc
->scsiio_depth
- INTERNAL_SCSIIO_CMDS_COUNT
+ 1;
731 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
732 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
733 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
734 memset(request
, 0, ioc
->request_sz
);
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 mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
||
743 mpi_request
->Function
== MPI2_FUNCTION_SATA_PASSTHROUGH
||
744 mpi_request
->Function
== MPI2_FUNCTION_NVME_ENCAPSULATED
) {
746 device_handle
= le16_to_cpu(mpi_request
->FunctionDependent1
);
747 if (!device_handle
|| (device_handle
>
748 ioc
->facts
.MaxDevHandle
)) {
750 mpt3sas_base_free_smid(ioc
, smid
);
755 /* obtain dma-able memory for data transfer */
756 if (data_out_sz
) /* WRITE */ {
757 data_out
= dma_alloc_coherent(&ioc
->pdev
->dev
, data_out_sz
,
758 &data_out_dma
, GFP_KERNEL
);
760 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
763 mpt3sas_base_free_smid(ioc
, smid
);
766 if (copy_from_user(data_out
, karg
.data_out_buf_ptr
,
768 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
771 mpt3sas_base_free_smid(ioc
, smid
);
776 if (data_in_sz
) /* READ */ {
777 data_in
= dma_alloc_coherent(&ioc
->pdev
->dev
, data_in_sz
,
778 &data_in_dma
, GFP_KERNEL
);
780 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
783 mpt3sas_base_free_smid(ioc
, smid
);
788 psge
= (void *)request
+ (karg
.data_sge_offset
*4);
790 /* send command to firmware */
791 _ctl_display_some_debug(ioc
, smid
, "ctl_request", NULL
);
793 init_completion(&ioc
->ctl_cmds
.done
);
794 switch (mpi_request
->Function
) {
795 case MPI2_FUNCTION_NVME_ENCAPSULATED
:
797 nvme_encap_request
= (Mpi26NVMeEncapsulatedRequest_t
*)request
;
798 if (!ioc
->pcie_sg_lookup
) {
799 dtmprintk(ioc
, ioc_info(ioc
,
800 "HBA doesn't support NVMe. Rejecting NVMe Encapsulated request.\n"
803 if (ioc
->logging_level
& MPT_DEBUG_TM
)
804 _debug_dump_mf(nvme_encap_request
,
806 mpt3sas_base_free_smid(ioc
, smid
);
811 * Get the Physical Address of the sense buffer.
812 * Use Error Response buffer address field to hold the sense
814 * Clear the internal sense buffer, which will potentially hold
815 * the Completion Queue Entry on return, or 0 if no Entry.
816 * Build the PRPs and set direction bits.
819 nvme_encap_request
->ErrorResponseBaseAddress
=
820 cpu_to_le64(ioc
->sense_dma
& 0xFFFFFFFF00000000UL
);
821 nvme_encap_request
->ErrorResponseBaseAddress
|=
822 cpu_to_le64(le32_to_cpu(
823 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
)));
824 nvme_encap_request
->ErrorResponseAllocationLength
=
825 cpu_to_le16(NVME_ERROR_RESPONSE_SIZE
);
826 memset(ioc
->ctl_cmds
.sense
, 0, NVME_ERROR_RESPONSE_SIZE
);
827 ioc
->build_nvme_prp(ioc
, smid
, nvme_encap_request
,
828 data_out_dma
, data_out_sz
, data_in_dma
, data_in_sz
);
829 if (test_bit(device_handle
, ioc
->device_remove_in_progress
)) {
831 ioc_info(ioc
, "handle(0x%04x): ioctl failed due to device removal in progress\n",
833 mpt3sas_base_free_smid(ioc
, smid
);
837 mpt3sas_base_put_smid_nvme_encap(ioc
, smid
);
840 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
841 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
843 Mpi2SCSIIORequest_t
*scsiio_request
=
844 (Mpi2SCSIIORequest_t
*)request
;
845 scsiio_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
846 scsiio_request
->SenseBufferLowAddress
=
847 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
848 memset(ioc
->ctl_cmds
.sense
, 0, SCSI_SENSE_BUFFERSIZE
);
849 if (test_bit(device_handle
, ioc
->device_remove_in_progress
)) {
851 ioc_info(ioc
, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
853 mpt3sas_base_free_smid(ioc
, smid
);
857 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
,
858 data_in_dma
, data_in_sz
);
859 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)
860 ioc
->put_smid_scsi_io(ioc
, smid
, device_handle
);
862 ioc
->put_smid_default(ioc
, smid
);
865 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
867 Mpi2SCSITaskManagementRequest_t
*tm_request
=
868 (Mpi2SCSITaskManagementRequest_t
*)request
;
871 ioc_info(ioc
, "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
872 le16_to_cpu(tm_request
->DevHandle
),
873 tm_request
->TaskType
));
874 ioc
->got_task_abort_from_ioctl
= 1;
875 if (tm_request
->TaskType
==
876 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
||
877 tm_request
->TaskType
==
878 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
) {
879 if (_ctl_set_task_mid(ioc
, &karg
, tm_request
)) {
880 mpt3sas_base_free_smid(ioc
, smid
);
881 ioc
->got_task_abort_from_ioctl
= 0;
885 ioc
->got_task_abort_from_ioctl
= 0;
887 if (test_bit(device_handle
, ioc
->device_remove_in_progress
)) {
889 ioc_info(ioc
, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
891 mpt3sas_base_free_smid(ioc
, smid
);
895 mpt3sas_scsih_set_tm_flag(ioc
, le16_to_cpu(
896 tm_request
->DevHandle
));
897 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
898 data_in_dma
, data_in_sz
);
899 ioc
->put_smid_hi_priority(ioc
, smid
, 0);
902 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
904 Mpi2SmpPassthroughRequest_t
*smp_request
=
905 (Mpi2SmpPassthroughRequest_t
*)mpi_request
;
908 if (!ioc
->multipath_on_hba
) {
909 /* ioc determines which port to use */
910 smp_request
->PhysicalPort
= 0xFF;
912 if (smp_request
->PassthroughFlags
&
913 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE
)
914 data
= (u8
*)&smp_request
->SGL
;
916 if (unlikely(data_out
== NULL
)) {
917 pr_err("failure at %s:%d/%s()!\n",
918 __FILE__
, __LINE__
, __func__
);
919 mpt3sas_base_free_smid(ioc
, smid
);
926 if (data
[1] == 0x91 && (data
[10] == 1 || data
[10] == 2)) {
927 ioc
->ioc_link_reset_in_progress
= 1;
928 ioc
->ignore_loginfos
= 1;
930 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
, data_in_dma
,
932 ioc
->put_smid_default(ioc
, smid
);
935 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
937 if (test_bit(device_handle
, ioc
->device_remove_in_progress
)) {
939 ioc_info(ioc
, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
941 mpt3sas_base_free_smid(ioc
, smid
);
945 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
, data_in_dma
,
947 ioc
->put_smid_default(ioc
, smid
);
950 case MPI2_FUNCTION_FW_DOWNLOAD
:
952 if (ioc
->pdev
->vendor
== MPI2_MFGPAGE_VENDORID_ATTO
) {
953 ioc_info(ioc
, "Firmware download not supported for ATTO HBA.\n");
959 case MPI2_FUNCTION_FW_UPLOAD
:
961 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
, data_in_dma
,
963 ioc
->put_smid_default(ioc
, smid
);
966 case MPI2_FUNCTION_TOOLBOX
:
968 Mpi2ToolboxCleanRequest_t
*toolbox_request
=
969 (Mpi2ToolboxCleanRequest_t
*)mpi_request
;
971 if ((toolbox_request
->Tool
== MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL
)
972 || (toolbox_request
->Tool
==
973 MPI26_TOOLBOX_BACKEND_PCIE_LANE_MARGIN
))
974 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
,
975 data_in_dma
, data_in_sz
);
976 else if (toolbox_request
->Tool
==
977 MPI2_TOOLBOX_MEMORY_MOVE_TOOL
) {
978 Mpi2ToolboxMemMoveRequest_t
*mem_move_request
=
979 (Mpi2ToolboxMemMoveRequest_t
*)request
;
980 Mpi2SGESimple64_t tmp
, *src
= NULL
, *dst
= NULL
;
982 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
,
983 data_out_sz
, data_in_dma
, data_in_sz
);
984 if (data_out_sz
&& !data_in_sz
) {
986 (Mpi2SGESimple64_t
*)&mem_move_request
->SGL
;
987 src
= (void *)dst
+ ioc
->sge_size
;
989 memcpy(&tmp
, src
, ioc
->sge_size
);
990 memcpy(src
, dst
, ioc
->sge_size
);
991 memcpy(dst
, &tmp
, ioc
->sge_size
);
993 if (ioc
->logging_level
& MPT_DEBUG_TM
) {
995 "Mpi2ToolboxMemMoveRequest_t request msg\n");
996 _debug_dump_mf(mem_move_request
,
1000 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
1001 data_in_dma
, data_in_sz
);
1002 ioc
->put_smid_default(ioc
, smid
);
1005 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
1007 Mpi2SasIoUnitControlRequest_t
*sasiounit_request
=
1008 (Mpi2SasIoUnitControlRequest_t
*)mpi_request
;
1010 if (sasiounit_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
1011 || sasiounit_request
->Operation
==
1012 MPI2_SAS_OP_PHY_LINK_RESET
) {
1013 ioc
->ioc_link_reset_in_progress
= 1;
1014 ioc
->ignore_loginfos
= 1;
1016 /* drop to default case for posting the request */
1020 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
1021 data_in_dma
, data_in_sz
);
1022 ioc
->put_smid_default(ioc
, smid
);
1026 if (karg
.timeout
< MPT3_IOCTL_DEFAULT_TIMEOUT
)
1027 timeout
= MPT3_IOCTL_DEFAULT_TIMEOUT
;
1029 timeout
= karg
.timeout
;
1030 wait_for_completion_timeout(&ioc
->ctl_cmds
.done
, timeout
*HZ
);
1031 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
1032 Mpi2SCSITaskManagementRequest_t
*tm_request
=
1033 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
1034 mpt3sas_scsih_clear_tm_flag(ioc
, le16_to_cpu(
1035 tm_request
->DevHandle
));
1036 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
1037 } else if ((mpi_request
->Function
== MPI2_FUNCTION_SMP_PASSTHROUGH
||
1038 mpi_request
->Function
== MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
) &&
1039 ioc
->ioc_link_reset_in_progress
) {
1040 ioc
->ioc_link_reset_in_progress
= 0;
1041 ioc
->ignore_loginfos
= 0;
1043 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1044 mpt3sas_check_cmd_timeout(ioc
,
1045 ioc
->ctl_cmds
.status
, mpi_request
,
1046 karg
.data_sge_offset
, issue_reset
);
1047 goto issue_host_reset
;
1050 mpi_reply
= ioc
->ctl_cmds
.reply
;
1052 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
&&
1053 (ioc
->logging_level
& MPT_DEBUG_TM
)) {
1054 Mpi2SCSITaskManagementReply_t
*tm_reply
=
1055 (Mpi2SCSITaskManagementReply_t
*)mpi_reply
;
1057 ioc_info(ioc
, "TASK_MGMT: IOCStatus(0x%04x), IOCLogInfo(0x%08x), TerminationCount(0x%08x)\n",
1058 le16_to_cpu(tm_reply
->IOCStatus
),
1059 le32_to_cpu(tm_reply
->IOCLogInfo
),
1060 le32_to_cpu(tm_reply
->TerminationCount
));
1063 /* copy out xdata to user */
1065 if (copy_to_user(karg
.data_in_buf_ptr
, data_in
,
1067 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
1068 __LINE__
, __func__
);
1074 /* copy out reply message frame to user */
1075 if (karg
.max_reply_bytes
) {
1076 sz
= min_t(u32
, karg
.max_reply_bytes
, ioc
->reply_sz
);
1077 if (copy_to_user(karg
.reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
1079 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
1080 __LINE__
, __func__
);
1086 /* copy out sense/NVMe Error Response to user */
1087 if (karg
.max_sense_bytes
&& (mpi_request
->Function
==
1088 MPI2_FUNCTION_SCSI_IO_REQUEST
|| mpi_request
->Function
==
1089 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
|| mpi_request
->Function
==
1090 MPI2_FUNCTION_NVME_ENCAPSULATED
)) {
1091 if (karg
.sense_data_ptr
== NULL
) {
1092 ioc_info(ioc
, "Response buffer provided by application is NULL; Response data will not be returned\n");
1095 sz_arg
= (mpi_request
->Function
==
1096 MPI2_FUNCTION_NVME_ENCAPSULATED
) ? NVME_ERROR_RESPONSE_SIZE
:
1097 SCSI_SENSE_BUFFERSIZE
;
1098 sz
= min_t(u32
, karg
.max_sense_bytes
, sz_arg
);
1099 if (copy_to_user(karg
.sense_data_ptr
, ioc
->ctl_cmds
.sense
,
1101 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
1102 __LINE__
, __func__
);
1111 if ((mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
1112 mpi_request
->Function
==
1113 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
1114 mpi_request
->Function
== MPI2_FUNCTION_SATA_PASSTHROUGH
)) {
1115 ioc_info(ioc
, "issue target reset: handle = (0x%04x)\n",
1116 le16_to_cpu(mpi_request
->FunctionDependent1
));
1117 mpt3sas_halt_firmware(ioc
);
1118 pcie_device
= mpt3sas_get_pdev_by_handle(ioc
,
1119 le16_to_cpu(mpi_request
->FunctionDependent1
));
1120 if (pcie_device
&& (!ioc
->tm_custom_handling
) &&
1121 (!(mpt3sas_scsih_is_pcie_scsi_device(
1122 pcie_device
->device_info
))))
1123 mpt3sas_scsih_issue_locked_tm(ioc
,
1124 le16_to_cpu(mpi_request
->FunctionDependent1
),
1126 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
1127 0, pcie_device
->reset_timeout
,
1128 MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE
);
1130 mpt3sas_scsih_issue_locked_tm(ioc
,
1131 le16_to_cpu(mpi_request
->FunctionDependent1
),
1133 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0,
1134 0, 30, MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET
);
1136 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
1141 pcie_device_put(pcie_device
);
1143 /* free memory associated with sg buffers */
1145 dma_free_coherent(&ioc
->pdev
->dev
, data_in_sz
, data_in
,
1149 dma_free_coherent(&ioc
->pdev
->dev
, data_out_sz
, data_out
,
1153 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1158 * _ctl_getiocinfo - main handler for MPT3IOCINFO opcode
1159 * @ioc: per adapter object
1160 * @arg: user space buffer containing ioctl content
1163 _ctl_getiocinfo(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1165 struct mpt3_ioctl_iocinfo karg
;
1167 dctlprintk(ioc
, ioc_info(ioc
, "%s: enter\n",
1170 memset(&karg
, 0 , sizeof(karg
));
1172 karg
.port_number
= ioc
->pfacts
[0].PortNumber
;
1173 karg
.hw_rev
= ioc
->pdev
->revision
;
1174 karg
.pci_id
= ioc
->pdev
->device
;
1175 karg
.subsystem_device
= ioc
->pdev
->subsystem_device
;
1176 karg
.subsystem_vendor
= ioc
->pdev
->subsystem_vendor
;
1177 karg
.pci_information
.u
.bits
.bus
= ioc
->pdev
->bus
->number
;
1178 karg
.pci_information
.u
.bits
.device
= PCI_SLOT(ioc
->pdev
->devfn
);
1179 karg
.pci_information
.u
.bits
.function
= PCI_FUNC(ioc
->pdev
->devfn
);
1180 karg
.pci_information
.segment_id
= pci_domain_nr(ioc
->pdev
->bus
);
1181 karg
.firmware_version
= ioc
->facts
.FWVersion
.Word
;
1182 strcpy(karg
.driver_version
, ioc
->driver_name
);
1183 strcat(karg
.driver_version
, "-");
1184 switch (ioc
->hba_mpi_version_belonged
) {
1186 if (ioc
->is_warpdrive
)
1187 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2_SSS6200
;
1189 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2
;
1190 strcat(karg
.driver_version
, MPT2SAS_DRIVER_VERSION
);
1194 if (ioc
->is_gen35_ioc
)
1195 karg
.adapter_type
= MPT3_IOCTL_INTERFACE_SAS35
;
1197 karg
.adapter_type
= MPT3_IOCTL_INTERFACE_SAS3
;
1198 strcat(karg
.driver_version
, MPT3SAS_DRIVER_VERSION
);
1201 karg
.bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
1203 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1204 pr_err("failure at %s:%d/%s()!\n",
1205 __FILE__
, __LINE__
, __func__
);
1212 * _ctl_eventquery - main handler for MPT3EVENTQUERY opcode
1213 * @ioc: per adapter object
1214 * @arg: user space buffer containing ioctl content
1217 _ctl_eventquery(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1219 struct mpt3_ioctl_eventquery karg
;
1221 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1222 pr_err("failure at %s:%d/%s()!\n",
1223 __FILE__
, __LINE__
, __func__
);
1227 dctlprintk(ioc
, ioc_info(ioc
, "%s: enter\n",
1230 karg
.event_entries
= MPT3SAS_CTL_EVENT_LOG_SIZE
;
1231 memcpy(karg
.event_types
, ioc
->event_type
,
1232 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1234 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1235 pr_err("failure at %s:%d/%s()!\n",
1236 __FILE__
, __LINE__
, __func__
);
1243 * _ctl_eventenable - main handler for MPT3EVENTENABLE opcode
1244 * @ioc: per adapter object
1245 * @arg: user space buffer containing ioctl content
1248 _ctl_eventenable(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1250 struct mpt3_ioctl_eventenable karg
;
1252 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1253 pr_err("failure at %s:%d/%s()!\n",
1254 __FILE__
, __LINE__
, __func__
);
1258 dctlprintk(ioc
, ioc_info(ioc
, "%s: enter\n",
1261 memcpy(ioc
->event_type
, karg
.event_types
,
1262 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1263 mpt3sas_base_validate_event_type(ioc
, ioc
->event_type
);
1267 /* initialize event_log */
1268 ioc
->event_context
= 0;
1269 ioc
->aen_event_read_flag
= 0;
1270 ioc
->event_log
= kcalloc(MPT3SAS_CTL_EVENT_LOG_SIZE
,
1271 sizeof(struct MPT3_IOCTL_EVENTS
), GFP_KERNEL
);
1272 if (!ioc
->event_log
) {
1273 pr_err("failure at %s:%d/%s()!\n",
1274 __FILE__
, __LINE__
, __func__
);
1281 * _ctl_eventreport - main handler for MPT3EVENTREPORT opcode
1282 * @ioc: per adapter object
1283 * @arg: user space buffer containing ioctl content
1286 _ctl_eventreport(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1288 struct mpt3_ioctl_eventreport karg
;
1289 u32 number_bytes
, max_events
, max
;
1290 struct mpt3_ioctl_eventreport __user
*uarg
= arg
;
1292 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1293 pr_err("failure at %s:%d/%s()!\n",
1294 __FILE__
, __LINE__
, __func__
);
1298 dctlprintk(ioc
, ioc_info(ioc
, "%s: enter\n",
1301 number_bytes
= karg
.hdr
.max_data_size
-
1302 sizeof(struct mpt3_ioctl_header
);
1303 max_events
= number_bytes
/sizeof(struct MPT3_IOCTL_EVENTS
);
1304 max
= min_t(u32
, MPT3SAS_CTL_EVENT_LOG_SIZE
, max_events
);
1306 /* If fewer than 1 event is requested, there must have
1307 * been some type of error.
1309 if (!max
|| !ioc
->event_log
)
1312 number_bytes
= max
* sizeof(struct MPT3_IOCTL_EVENTS
);
1313 if (copy_to_user(uarg
->event_data
, ioc
->event_log
, number_bytes
)) {
1314 pr_err("failure at %s:%d/%s()!\n",
1315 __FILE__
, __LINE__
, __func__
);
1319 /* reset flag so SIGIO can restart */
1320 ioc
->aen_event_read_flag
= 0;
1325 * _ctl_do_reset - main handler for MPT3HARDRESET opcode
1326 * @ioc: per adapter object
1327 * @arg: user space buffer containing ioctl content
1330 _ctl_do_reset(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1332 struct mpt3_ioctl_diag_reset karg
;
1335 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1336 pr_err("failure at %s:%d/%s()!\n",
1337 __FILE__
, __LINE__
, __func__
);
1341 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
1342 ioc
->is_driver_loading
)
1345 dctlprintk(ioc
, ioc_info(ioc
, "%s: enter\n",
1348 ioc
->reset_from_user
= 1;
1349 retval
= mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
1351 "Ioctl: host reset: %s\n", ((!retval
) ? "SUCCESS" : "FAILED"));
1356 * _ctl_btdh_search_sas_device - searching for sas device
1357 * @ioc: per adapter object
1358 * @btdh: btdh ioctl payload
1361 _ctl_btdh_search_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
1362 struct mpt3_ioctl_btdh_mapping
*btdh
)
1364 struct _sas_device
*sas_device
;
1365 unsigned long flags
;
1368 if (list_empty(&ioc
->sas_device_list
))
1371 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1372 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
1373 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1374 btdh
->handle
== sas_device
->handle
) {
1375 btdh
->bus
= sas_device
->channel
;
1376 btdh
->id
= sas_device
->id
;
1379 } else if (btdh
->bus
== sas_device
->channel
&& btdh
->id
==
1380 sas_device
->id
&& btdh
->handle
== 0xFFFF) {
1381 btdh
->handle
= sas_device
->handle
;
1387 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1392 * _ctl_btdh_search_pcie_device - searching for pcie device
1393 * @ioc: per adapter object
1394 * @btdh: btdh ioctl payload
1397 _ctl_btdh_search_pcie_device(struct MPT3SAS_ADAPTER
*ioc
,
1398 struct mpt3_ioctl_btdh_mapping
*btdh
)
1400 struct _pcie_device
*pcie_device
;
1401 unsigned long flags
;
1404 if (list_empty(&ioc
->pcie_device_list
))
1407 spin_lock_irqsave(&ioc
->pcie_device_lock
, flags
);
1408 list_for_each_entry(pcie_device
, &ioc
->pcie_device_list
, list
) {
1409 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1410 btdh
->handle
== pcie_device
->handle
) {
1411 btdh
->bus
= pcie_device
->channel
;
1412 btdh
->id
= pcie_device
->id
;
1415 } else if (btdh
->bus
== pcie_device
->channel
&& btdh
->id
==
1416 pcie_device
->id
&& btdh
->handle
== 0xFFFF) {
1417 btdh
->handle
= pcie_device
->handle
;
1423 spin_unlock_irqrestore(&ioc
->pcie_device_lock
, flags
);
1428 * _ctl_btdh_search_raid_device - searching for raid device
1429 * @ioc: per adapter object
1430 * @btdh: btdh ioctl payload
1433 _ctl_btdh_search_raid_device(struct MPT3SAS_ADAPTER
*ioc
,
1434 struct mpt3_ioctl_btdh_mapping
*btdh
)
1436 struct _raid_device
*raid_device
;
1437 unsigned long flags
;
1440 if (list_empty(&ioc
->raid_device_list
))
1443 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1444 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1445 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1446 btdh
->handle
== raid_device
->handle
) {
1447 btdh
->bus
= raid_device
->channel
;
1448 btdh
->id
= raid_device
->id
;
1451 } else if (btdh
->bus
== raid_device
->channel
&& btdh
->id
==
1452 raid_device
->id
&& btdh
->handle
== 0xFFFF) {
1453 btdh
->handle
= raid_device
->handle
;
1459 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1464 * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode
1465 * @ioc: per adapter object
1466 * @arg: user space buffer containing ioctl content
1469 _ctl_btdh_mapping(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1471 struct mpt3_ioctl_btdh_mapping karg
;
1474 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1475 pr_err("failure at %s:%d/%s()!\n",
1476 __FILE__
, __LINE__
, __func__
);
1480 dctlprintk(ioc
, ioc_info(ioc
, "%s\n",
1483 rc
= _ctl_btdh_search_sas_device(ioc
, &karg
);
1485 rc
= _ctl_btdh_search_pcie_device(ioc
, &karg
);
1487 _ctl_btdh_search_raid_device(ioc
, &karg
);
1489 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1490 pr_err("failure at %s:%d/%s()!\n",
1491 __FILE__
, __LINE__
, __func__
);
1498 * _ctl_diag_capability - return diag buffer capability
1499 * @ioc: per adapter object
1500 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1502 * returns 1 when diag buffer support is enabled in firmware
1505 _ctl_diag_capability(struct MPT3SAS_ADAPTER
*ioc
, u8 buffer_type
)
1509 switch (buffer_type
) {
1510 case MPI2_DIAG_BUF_TYPE_TRACE
:
1511 if (ioc
->facts
.IOCCapabilities
&
1512 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
)
1515 case MPI2_DIAG_BUF_TYPE_SNAPSHOT
:
1516 if (ioc
->facts
.IOCCapabilities
&
1517 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
)
1520 case MPI2_DIAG_BUF_TYPE_EXTENDED
:
1521 if (ioc
->facts
.IOCCapabilities
&
1522 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
)
1530 * _ctl_diag_get_bufftype - return diag buffer type
1531 * either TRACE, SNAPSHOT, or EXTENDED
1532 * @ioc: per adapter object
1533 * @unique_id: specifies the unique_id for the buffer
1535 * returns MPT3_DIAG_UID_NOT_FOUND if the id not found
1538 _ctl_diag_get_bufftype(struct MPT3SAS_ADAPTER
*ioc
, u32 unique_id
)
1542 for (index
= 0; index
< MPI2_DIAG_BUF_TYPE_COUNT
; index
++) {
1543 if (ioc
->unique_id
[index
] == unique_id
)
1547 return MPT3_DIAG_UID_NOT_FOUND
;
1551 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1552 * @ioc: per adapter object
1553 * @diag_register: the diag_register struct passed in from user space
1557 _ctl_diag_register_2(struct MPT3SAS_ADAPTER
*ioc
,
1558 struct mpt3_diag_register
*diag_register
)
1561 void *request_data
= NULL
;
1562 dma_addr_t request_data_dma
;
1563 u32 request_data_sz
= 0;
1564 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1565 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1572 dctlprintk(ioc
, ioc_info(ioc
, "%s\n",
1575 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1576 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1577 ioc_err(ioc
, "%s: failed due to ioc not operational\n",
1583 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1584 ioc_err(ioc
, "%s: ctl_cmd in use\n", __func__
);
1589 buffer_type
= diag_register
->buffer_type
;
1590 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1591 ioc_err(ioc
, "%s: doesn't have capability for buffer_type(0x%02x)\n",
1592 __func__
, buffer_type
);
1596 if (diag_register
->unique_id
== 0) {
1598 "%s: Invalid UID(0x%08x), buffer_type(0x%02x)\n", __func__
,
1599 diag_register
->unique_id
, buffer_type
);
1603 if ((ioc
->diag_buffer_status
[buffer_type
] &
1604 MPT3_DIAG_BUFFER_IS_APP_OWNED
) &&
1605 !(ioc
->diag_buffer_status
[buffer_type
] &
1606 MPT3_DIAG_BUFFER_IS_RELEASED
)) {
1608 "%s: buffer_type(0x%02x) is already registered by application with UID(0x%08x)\n",
1609 __func__
, buffer_type
, ioc
->unique_id
[buffer_type
]);
1613 if (ioc
->diag_buffer_status
[buffer_type
] &
1614 MPT3_DIAG_BUFFER_IS_REGISTERED
) {
1616 * If driver posts buffer initially, then an application wants
1617 * to Register that buffer (own it) without Releasing first,
1618 * the application Register command MUST have the same buffer
1619 * type and size in the Register command (obtained from the
1620 * Query command). Otherwise that Register command will be
1621 * failed. If the application has released the buffer but wants
1622 * to re-register it, it should be allowed as long as the
1623 * Unique-Id/Size match.
1626 if (ioc
->unique_id
[buffer_type
] == MPT3DIAGBUFFUNIQUEID
&&
1627 ioc
->diag_buffer_sz
[buffer_type
] ==
1628 diag_register
->requested_buffer_size
) {
1630 if (!(ioc
->diag_buffer_status
[buffer_type
] &
1631 MPT3_DIAG_BUFFER_IS_RELEASED
)) {
1632 dctlprintk(ioc
, ioc_info(ioc
,
1633 "%s: diag_buffer (%d) ownership changed. old-ID(0x%08x), new-ID(0x%08x)\n",
1634 __func__
, buffer_type
,
1635 ioc
->unique_id
[buffer_type
],
1636 diag_register
->unique_id
));
1639 * Application wants to own the buffer with
1642 ioc
->unique_id
[buffer_type
] =
1643 diag_register
->unique_id
;
1644 rc
= 0; /* success */
1647 } else if (ioc
->unique_id
[buffer_type
] !=
1648 MPT3DIAGBUFFUNIQUEID
) {
1649 if (ioc
->unique_id
[buffer_type
] !=
1650 diag_register
->unique_id
||
1651 ioc
->diag_buffer_sz
[buffer_type
] !=
1652 diag_register
->requested_buffer_size
||
1653 !(ioc
->diag_buffer_status
[buffer_type
] &
1654 MPT3_DIAG_BUFFER_IS_RELEASED
)) {
1656 "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1657 __func__
, buffer_type
);
1661 ioc_err(ioc
, "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1662 __func__
, buffer_type
);
1665 } else if (ioc
->diag_buffer_status
[buffer_type
] &
1666 MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
) {
1668 if (ioc
->unique_id
[buffer_type
] != MPT3DIAGBUFFUNIQUEID
||
1669 ioc
->diag_buffer_sz
[buffer_type
] !=
1670 diag_register
->requested_buffer_size
) {
1673 "%s: already a buffer is allocated for buffer_type(0x%02x) of size %d bytes, so please try registering again with same size\n",
1674 __func__
, buffer_type
,
1675 ioc
->diag_buffer_sz
[buffer_type
]);
1680 if (diag_register
->requested_buffer_size
% 4) {
1681 ioc_err(ioc
, "%s: the requested_buffer_size is not 4 byte aligned\n",
1686 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1688 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
1694 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
1695 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1696 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1697 memset(mpi_request
, 0, ioc
->request_sz
);
1698 ioc
->ctl_cmds
.smid
= smid
;
1700 request_data
= ioc
->diag_buffer
[buffer_type
];
1701 request_data_sz
= diag_register
->requested_buffer_size
;
1702 ioc
->unique_id
[buffer_type
] = diag_register
->unique_id
;
1703 /* Reset ioc variables used for additional query commands */
1704 ioc
->reset_from_user
= 0;
1705 memset(&ioc
->htb_rel
, 0, sizeof(struct htb_rel_query
));
1706 ioc
->diag_buffer_status
[buffer_type
] &=
1707 MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
;
1708 memcpy(ioc
->product_specific
[buffer_type
],
1709 diag_register
->product_specific
, MPT3_PRODUCT_SPECIFIC_DWORDS
);
1710 ioc
->diagnostic_flags
[buffer_type
] = diag_register
->diagnostic_flags
;
1713 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1714 if (request_data_sz
!= ioc
->diag_buffer_sz
[buffer_type
]) {
1715 dma_free_coherent(&ioc
->pdev
->dev
,
1716 ioc
->diag_buffer_sz
[buffer_type
],
1717 request_data
, request_data_dma
);
1718 request_data
= NULL
;
1722 if (request_data
== NULL
) {
1723 ioc
->diag_buffer_sz
[buffer_type
] = 0;
1724 ioc
->diag_buffer_dma
[buffer_type
] = 0;
1725 request_data
= dma_alloc_coherent(&ioc
->pdev
->dev
,
1726 request_data_sz
, &request_data_dma
, GFP_KERNEL
);
1727 if (request_data
== NULL
) {
1728 ioc_err(ioc
, "%s: failed allocating memory for diag buffers, requested size(%d)\n",
1729 __func__
, request_data_sz
);
1730 mpt3sas_base_free_smid(ioc
, smid
);
1734 ioc
->diag_buffer
[buffer_type
] = request_data
;
1735 ioc
->diag_buffer_sz
[buffer_type
] = request_data_sz
;
1736 ioc
->diag_buffer_dma
[buffer_type
] = request_data_dma
;
1739 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1740 mpi_request
->BufferType
= diag_register
->buffer_type
;
1741 mpi_request
->Flags
= cpu_to_le32(diag_register
->diagnostic_flags
);
1742 mpi_request
->BufferAddress
= cpu_to_le64(request_data_dma
);
1743 mpi_request
->BufferLength
= cpu_to_le32(request_data_sz
);
1744 mpi_request
->VF_ID
= 0; /* TODO */
1745 mpi_request
->VP_ID
= 0;
1748 ioc_info(ioc
, "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1749 __func__
, request_data
,
1750 (unsigned long long)request_data_dma
,
1751 le32_to_cpu(mpi_request
->BufferLength
)));
1753 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
1754 mpi_request
->ProductSpecific
[i
] =
1755 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1757 init_completion(&ioc
->ctl_cmds
.done
);
1758 ioc
->put_smid_default(ioc
, smid
);
1759 wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1760 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1762 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1763 mpt3sas_check_cmd_timeout(ioc
,
1764 ioc
->ctl_cmds
.status
, mpi_request
,
1765 sizeof(Mpi2DiagBufferPostRequest_t
)/4, issue_reset
);
1766 goto issue_host_reset
;
1769 /* process the completed Reply Message Frame */
1770 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
1771 ioc_err(ioc
, "%s: no reply message\n", __func__
);
1776 mpi_reply
= ioc
->ctl_cmds
.reply
;
1777 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1779 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1780 ioc
->diag_buffer_status
[buffer_type
] |=
1781 MPT3_DIAG_BUFFER_IS_REGISTERED
;
1782 dctlprintk(ioc
, ioc_info(ioc
, "%s: success\n", __func__
));
1784 ioc_info(ioc
, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1786 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
1792 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
1796 if (rc
&& request_data
) {
1797 dma_free_coherent(&ioc
->pdev
->dev
, request_data_sz
,
1798 request_data
, request_data_dma
);
1799 ioc
->diag_buffer
[buffer_type
] = NULL
;
1800 ioc
->diag_buffer_status
[buffer_type
] &=
1801 ~MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
;
1804 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1809 * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time
1810 * @ioc: per adapter object
1811 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1813 * This is called when command line option diag_buffer_enable is enabled
1814 * at driver load time.
1817 mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER
*ioc
, u8 bits_to_register
)
1819 struct mpt3_diag_register diag_register
;
1821 u32 trace_buff_size
= ioc
->manu_pg11
.HostTraceBufferMaxSizeKB
<<10;
1822 u32 min_trace_buff_size
= 0;
1823 u32 decr_trace_buff_size
= 0;
1825 memset(&diag_register
, 0, sizeof(struct mpt3_diag_register
));
1827 if (bits_to_register
& 1) {
1828 ioc_info(ioc
, "registering trace buffer support\n");
1829 ioc
->diag_trigger_master
.MasterData
=
1830 (MASTER_TRIGGER_FW_FAULT
+ MASTER_TRIGGER_ADAPTER_RESET
);
1831 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
1832 diag_register
.unique_id
=
1833 (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
) ?
1834 (MPT2DIAGBUFFUNIQUEID
):(MPT3DIAGBUFFUNIQUEID
);
1836 if (trace_buff_size
!= 0) {
1837 diag_register
.requested_buffer_size
= trace_buff_size
;
1838 min_trace_buff_size
=
1839 ioc
->manu_pg11
.HostTraceBufferMinSizeKB
<<10;
1840 decr_trace_buff_size
=
1841 ioc
->manu_pg11
.HostTraceBufferDecrementSizeKB
<<10;
1843 if (min_trace_buff_size
> trace_buff_size
) {
1844 /* The buff size is not set correctly */
1846 "Min Trace Buff size (%d KB) greater than Max Trace Buff size (%d KB)\n",
1847 min_trace_buff_size
>>10,
1848 trace_buff_size
>>10);
1850 "Using zero Min Trace Buff Size\n");
1851 min_trace_buff_size
= 0;
1854 if (decr_trace_buff_size
== 0) {
1856 * retry the min size if decrement
1859 decr_trace_buff_size
=
1860 trace_buff_size
- min_trace_buff_size
;
1863 /* register for 2MB buffers */
1864 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1868 ret_val
= _ctl_diag_register_2(ioc
, &diag_register
);
1870 if (ret_val
== -ENOMEM
&& min_trace_buff_size
&&
1871 (trace_buff_size
- decr_trace_buff_size
) >=
1872 min_trace_buff_size
) {
1873 /* adjust the buffer size */
1874 trace_buff_size
-= decr_trace_buff_size
;
1875 diag_register
.requested_buffer_size
=
1881 if (ret_val
== -ENOMEM
)
1883 "Cannot allocate trace buffer memory. Last memory tried = %d KB\n",
1884 diag_register
.requested_buffer_size
>>10);
1885 else if (ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
]
1886 & MPT3_DIAG_BUFFER_IS_REGISTERED
) {
1887 ioc_info(ioc
, "Trace buffer memory %d KB allocated\n",
1888 diag_register
.requested_buffer_size
>>10);
1889 if (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
)
1890 ioc
->diag_buffer_status
[
1891 MPI2_DIAG_BUF_TYPE_TRACE
] |=
1892 MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
;
1896 if (bits_to_register
& 2) {
1897 ioc_info(ioc
, "registering snapshot buffer support\n");
1898 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_SNAPSHOT
;
1899 /* register for 2MB buffers */
1900 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1901 diag_register
.unique_id
= 0x7075901;
1902 _ctl_diag_register_2(ioc
, &diag_register
);
1905 if (bits_to_register
& 4) {
1906 ioc_info(ioc
, "registering extended buffer support\n");
1907 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_EXTENDED
;
1908 /* register for 2MB buffers */
1909 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1910 diag_register
.unique_id
= 0x7075901;
1911 _ctl_diag_register_2(ioc
, &diag_register
);
1916 * _ctl_diag_register - application register with driver
1917 * @ioc: per adapter object
1918 * @arg: user space buffer containing ioctl content
1920 * This will allow the driver to setup any required buffers that will be
1921 * needed by firmware to communicate with the driver.
1924 _ctl_diag_register(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1926 struct mpt3_diag_register karg
;
1929 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1930 pr_err("failure at %s:%d/%s()!\n",
1931 __FILE__
, __LINE__
, __func__
);
1935 rc
= _ctl_diag_register_2(ioc
, &karg
);
1937 if (!rc
&& (ioc
->diag_buffer_status
[karg
.buffer_type
] &
1938 MPT3_DIAG_BUFFER_IS_REGISTERED
))
1939 ioc
->diag_buffer_status
[karg
.buffer_type
] |=
1940 MPT3_DIAG_BUFFER_IS_APP_OWNED
;
1946 * _ctl_diag_unregister - application unregister with driver
1947 * @ioc: per adapter object
1948 * @arg: user space buffer containing ioctl content
1950 * This will allow the driver to cleanup any memory allocated for diag
1951 * messages and to free up any resources.
1954 _ctl_diag_unregister(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1956 struct mpt3_diag_unregister karg
;
1958 dma_addr_t request_data_dma
;
1959 u32 request_data_sz
;
1962 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1963 pr_err("failure at %s:%d/%s()!\n",
1964 __FILE__
, __LINE__
, __func__
);
1968 dctlprintk(ioc
, ioc_info(ioc
, "%s\n",
1971 buffer_type
= _ctl_diag_get_bufftype(ioc
, karg
.unique_id
);
1972 if (buffer_type
== MPT3_DIAG_UID_NOT_FOUND
) {
1973 ioc_err(ioc
, "%s: buffer with unique_id(0x%08x) not found\n",
1974 __func__
, karg
.unique_id
);
1978 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1979 ioc_err(ioc
, "%s: doesn't have capability for buffer_type(0x%02x)\n",
1980 __func__
, buffer_type
);
1984 if ((ioc
->diag_buffer_status
[buffer_type
] &
1985 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1986 ioc_err(ioc
, "%s: buffer_type(0x%02x) is not registered\n",
1987 __func__
, buffer_type
);
1990 if ((ioc
->diag_buffer_status
[buffer_type
] &
1991 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0) {
1992 ioc_err(ioc
, "%s: buffer_type(0x%02x) has not been released\n",
1993 __func__
, buffer_type
);
1997 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1998 ioc_err(ioc
, "%s: unique_id(0x%08x) is not registered\n",
1999 __func__
, karg
.unique_id
);
2003 request_data
= ioc
->diag_buffer
[buffer_type
];
2004 if (!request_data
) {
2005 ioc_err(ioc
, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
2006 __func__
, buffer_type
);
2010 if (ioc
->diag_buffer_status
[buffer_type
] &
2011 MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
) {
2012 ioc
->unique_id
[buffer_type
] = MPT3DIAGBUFFUNIQUEID
;
2013 ioc
->diag_buffer_status
[buffer_type
] &=
2014 ~MPT3_DIAG_BUFFER_IS_APP_OWNED
;
2015 ioc
->diag_buffer_status
[buffer_type
] &=
2016 ~MPT3_DIAG_BUFFER_IS_REGISTERED
;
2018 request_data_sz
= ioc
->diag_buffer_sz
[buffer_type
];
2019 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
2020 dma_free_coherent(&ioc
->pdev
->dev
, request_data_sz
,
2021 request_data
, request_data_dma
);
2022 ioc
->diag_buffer
[buffer_type
] = NULL
;
2023 ioc
->diag_buffer_status
[buffer_type
] = 0;
2029 * _ctl_diag_query - query relevant info associated with diag buffers
2030 * @ioc: per adapter object
2031 * @arg: user space buffer containing ioctl content
2033 * The application will send only buffer_type and unique_id. Driver will
2034 * inspect unique_id first, if valid, fill in all the info. If unique_id is
2035 * 0x00, the driver will return info specified by Buffer Type.
2038 _ctl_diag_query(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
2040 struct mpt3_diag_query karg
;
2045 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2046 pr_err("failure at %s:%d/%s()!\n",
2047 __FILE__
, __LINE__
, __func__
);
2051 dctlprintk(ioc
, ioc_info(ioc
, "%s\n",
2054 karg
.application_flags
= 0;
2055 buffer_type
= karg
.buffer_type
;
2057 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
2058 ioc_err(ioc
, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2059 __func__
, buffer_type
);
2063 if (!(ioc
->diag_buffer_status
[buffer_type
] &
2064 MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
)) {
2065 if ((ioc
->diag_buffer_status
[buffer_type
] &
2066 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2067 ioc_err(ioc
, "%s: buffer_type(0x%02x) is not registered\n",
2068 __func__
, buffer_type
);
2073 if (karg
.unique_id
) {
2074 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
2075 ioc_err(ioc
, "%s: unique_id(0x%08x) is not registered\n",
2076 __func__
, karg
.unique_id
);
2081 request_data
= ioc
->diag_buffer
[buffer_type
];
2082 if (!request_data
) {
2083 ioc_err(ioc
, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2084 __func__
, buffer_type
);
2088 if ((ioc
->diag_buffer_status
[buffer_type
] &
2089 MPT3_DIAG_BUFFER_IS_REGISTERED
))
2090 karg
.application_flags
|= MPT3_APP_FLAGS_BUFFER_VALID
;
2092 if (!(ioc
->diag_buffer_status
[buffer_type
] &
2093 MPT3_DIAG_BUFFER_IS_RELEASED
))
2094 karg
.application_flags
|= MPT3_APP_FLAGS_FW_BUFFER_ACCESS
;
2096 if (!(ioc
->diag_buffer_status
[buffer_type
] &
2097 MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
))
2098 karg
.application_flags
|= MPT3_APP_FLAGS_DYNAMIC_BUFFER_ALLOC
;
2100 if ((ioc
->diag_buffer_status
[buffer_type
] &
2101 MPT3_DIAG_BUFFER_IS_APP_OWNED
))
2102 karg
.application_flags
|= MPT3_APP_FLAGS_APP_OWNED
;
2104 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
2105 karg
.product_specific
[i
] =
2106 ioc
->product_specific
[buffer_type
][i
];
2108 karg
.total_buffer_size
= ioc
->diag_buffer_sz
[buffer_type
];
2109 karg
.driver_added_buffer_size
= 0;
2110 karg
.unique_id
= ioc
->unique_id
[buffer_type
];
2111 karg
.diagnostic_flags
= ioc
->diagnostic_flags
[buffer_type
];
2113 if (copy_to_user(arg
, &karg
, sizeof(struct mpt3_diag_query
))) {
2114 ioc_err(ioc
, "%s: unable to write mpt3_diag_query data @ %p\n",
2122 * mpt3sas_send_diag_release - Diag Release Message
2123 * @ioc: per adapter object
2124 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
2125 * @issue_reset: specifies whether host reset is required.
2129 mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER
*ioc
, u8 buffer_type
,
2132 Mpi2DiagReleaseRequest_t
*mpi_request
;
2133 Mpi2DiagReleaseReply_t
*mpi_reply
;
2138 u8 reset_needed
= 0;
2140 dctlprintk(ioc
, ioc_info(ioc
, "%s\n",
2147 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
2148 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
2149 if (ioc
->diag_buffer_status
[buffer_type
] &
2150 MPT3_DIAG_BUFFER_IS_REGISTERED
)
2151 ioc
->diag_buffer_status
[buffer_type
] |=
2152 MPT3_DIAG_BUFFER_IS_RELEASED
;
2154 ioc_info(ioc
, "%s: skipping due to FAULT state\n",
2160 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2161 ioc_err(ioc
, "%s: ctl_cmd in use\n", __func__
);
2166 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
2168 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
2173 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
2174 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
2175 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2176 memset(mpi_request
, 0, ioc
->request_sz
);
2177 ioc
->ctl_cmds
.smid
= smid
;
2179 mpi_request
->Function
= MPI2_FUNCTION_DIAG_RELEASE
;
2180 mpi_request
->BufferType
= buffer_type
;
2181 mpi_request
->VF_ID
= 0; /* TODO */
2182 mpi_request
->VP_ID
= 0;
2184 init_completion(&ioc
->ctl_cmds
.done
);
2185 ioc
->put_smid_default(ioc
, smid
);
2186 wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
2187 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
2189 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2190 mpt3sas_check_cmd_timeout(ioc
,
2191 ioc
->ctl_cmds
.status
, mpi_request
,
2192 sizeof(Mpi2DiagReleaseRequest_t
)/4, reset_needed
);
2193 *issue_reset
= reset_needed
;
2198 /* process the completed Reply Message Frame */
2199 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
2200 ioc_err(ioc
, "%s: no reply message\n", __func__
);
2205 mpi_reply
= ioc
->ctl_cmds
.reply
;
2206 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2208 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
2209 ioc
->diag_buffer_status
[buffer_type
] |=
2210 MPT3_DIAG_BUFFER_IS_RELEASED
;
2211 dctlprintk(ioc
, ioc_info(ioc
, "%s: success\n", __func__
));
2213 ioc_info(ioc
, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2215 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
2220 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
2225 * _ctl_diag_release - request to send Diag Release Message to firmware
2227 * @arg: user space buffer containing ioctl content
2229 * This allows ownership of the specified buffer to returned to the driver,
2230 * allowing an application to read the buffer without fear that firmware is
2231 * overwriting information in the buffer.
2234 _ctl_diag_release(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
2236 struct mpt3_diag_release karg
;
2242 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2243 pr_err("failure at %s:%d/%s()!\n",
2244 __FILE__
, __LINE__
, __func__
);
2248 dctlprintk(ioc
, ioc_info(ioc
, "%s\n",
2251 buffer_type
= _ctl_diag_get_bufftype(ioc
, karg
.unique_id
);
2252 if (buffer_type
== MPT3_DIAG_UID_NOT_FOUND
) {
2253 ioc_err(ioc
, "%s: buffer with unique_id(0x%08x) not found\n",
2254 __func__
, karg
.unique_id
);
2258 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
2259 ioc_err(ioc
, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2260 __func__
, buffer_type
);
2264 if ((ioc
->diag_buffer_status
[buffer_type
] &
2265 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2266 ioc_err(ioc
, "%s: buffer_type(0x%02x) is not registered\n",
2267 __func__
, buffer_type
);
2271 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
2272 ioc_err(ioc
, "%s: unique_id(0x%08x) is not registered\n",
2273 __func__
, karg
.unique_id
);
2277 if (ioc
->diag_buffer_status
[buffer_type
] &
2278 MPT3_DIAG_BUFFER_IS_RELEASED
) {
2279 ioc_err(ioc
, "%s: buffer_type(0x%02x) is already released\n",
2280 __func__
, buffer_type
);
2284 request_data
= ioc
->diag_buffer
[buffer_type
];
2286 if (!request_data
) {
2287 ioc_err(ioc
, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
2288 __func__
, buffer_type
);
2292 /* buffers were released by due to host reset */
2293 if ((ioc
->diag_buffer_status
[buffer_type
] &
2294 MPT3_DIAG_BUFFER_IS_DIAG_RESET
)) {
2295 ioc
->diag_buffer_status
[buffer_type
] |=
2296 MPT3_DIAG_BUFFER_IS_RELEASED
;
2297 ioc
->diag_buffer_status
[buffer_type
] &=
2298 ~MPT3_DIAG_BUFFER_IS_DIAG_RESET
;
2299 ioc_err(ioc
, "%s: buffer_type(0x%02x) was released due to host reset\n",
2300 __func__
, buffer_type
);
2304 rc
= mpt3sas_send_diag_release(ioc
, buffer_type
, &issue_reset
);
2307 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2313 * _ctl_diag_read_buffer - request for copy of the diag buffer
2314 * @ioc: per adapter object
2315 * @arg: user space buffer containing ioctl content
2318 _ctl_diag_read_buffer(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
2320 struct mpt3_diag_read_buffer karg
;
2321 struct mpt3_diag_read_buffer __user
*uarg
= arg
;
2322 void *request_data
, *diag_data
;
2323 Mpi2DiagBufferPostRequest_t
*mpi_request
;
2324 Mpi2DiagBufferPostReply_t
*mpi_reply
;
2327 unsigned long request_size
, copy_size
;
2332 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2333 pr_err("failure at %s:%d/%s()!\n",
2334 __FILE__
, __LINE__
, __func__
);
2338 dctlprintk(ioc
, ioc_info(ioc
, "%s\n",
2341 buffer_type
= _ctl_diag_get_bufftype(ioc
, karg
.unique_id
);
2342 if (buffer_type
== MPT3_DIAG_UID_NOT_FOUND
) {
2343 ioc_err(ioc
, "%s: buffer with unique_id(0x%08x) not found\n",
2344 __func__
, karg
.unique_id
);
2348 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
2349 ioc_err(ioc
, "%s: doesn't have capability for buffer_type(0x%02x)\n",
2350 __func__
, buffer_type
);
2354 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
2355 ioc_err(ioc
, "%s: unique_id(0x%08x) is not registered\n",
2356 __func__
, karg
.unique_id
);
2360 request_data
= ioc
->diag_buffer
[buffer_type
];
2361 if (!request_data
) {
2362 ioc_err(ioc
, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2363 __func__
, buffer_type
);
2367 request_size
= ioc
->diag_buffer_sz
[buffer_type
];
2369 if ((karg
.starting_offset
% 4) || (karg
.bytes_to_read
% 4)) {
2370 ioc_err(ioc
, "%s: either the starting_offset or bytes_to_read are not 4 byte aligned\n",
2375 if (karg
.starting_offset
> request_size
)
2378 diag_data
= (void *)(request_data
+ karg
.starting_offset
);
2380 ioc_info(ioc
, "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2381 __func__
, diag_data
, karg
.starting_offset
,
2382 karg
.bytes_to_read
));
2384 /* Truncate data on requests that are too large */
2385 if ((diag_data
+ karg
.bytes_to_read
< diag_data
) ||
2386 (diag_data
+ karg
.bytes_to_read
> request_data
+ request_size
))
2387 copy_size
= request_size
- karg
.starting_offset
;
2389 copy_size
= karg
.bytes_to_read
;
2391 if (copy_to_user((void __user
*)uarg
->diagnostic_data
,
2392 diag_data
, copy_size
)) {
2393 ioc_err(ioc
, "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2394 __func__
, diag_data
);
2398 if ((karg
.flags
& MPT3_FLAGS_REREGISTER
) == 0)
2402 ioc_info(ioc
, "%s: Reregister buffer_type(0x%02x)\n",
2403 __func__
, buffer_type
));
2404 if ((ioc
->diag_buffer_status
[buffer_type
] &
2405 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0) {
2407 ioc_info(ioc
, "%s: buffer_type(0x%02x) is still registered\n",
2408 __func__
, buffer_type
));
2411 /* Get a free request frame and save the message context.
2414 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2415 ioc_err(ioc
, "%s: ctl_cmd in use\n", __func__
);
2420 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
2422 ioc_err(ioc
, "%s: failed obtaining a smid\n", __func__
);
2428 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
2429 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
2430 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2431 memset(mpi_request
, 0, ioc
->request_sz
);
2432 ioc
->ctl_cmds
.smid
= smid
;
2434 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
2435 mpi_request
->BufferType
= buffer_type
;
2436 mpi_request
->BufferLength
=
2437 cpu_to_le32(ioc
->diag_buffer_sz
[buffer_type
]);
2438 mpi_request
->BufferAddress
=
2439 cpu_to_le64(ioc
->diag_buffer_dma
[buffer_type
]);
2440 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
2441 mpi_request
->ProductSpecific
[i
] =
2442 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
2443 mpi_request
->VF_ID
= 0; /* TODO */
2444 mpi_request
->VP_ID
= 0;
2446 init_completion(&ioc
->ctl_cmds
.done
);
2447 ioc
->put_smid_default(ioc
, smid
);
2448 wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
2449 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
2451 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2452 mpt3sas_check_cmd_timeout(ioc
,
2453 ioc
->ctl_cmds
.status
, mpi_request
,
2454 sizeof(Mpi2DiagBufferPostRequest_t
)/4, issue_reset
);
2455 goto issue_host_reset
;
2458 /* process the completed Reply Message Frame */
2459 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
2460 ioc_err(ioc
, "%s: no reply message\n", __func__
);
2465 mpi_reply
= ioc
->ctl_cmds
.reply
;
2466 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2468 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
2469 ioc
->diag_buffer_status
[buffer_type
] |=
2470 MPT3_DIAG_BUFFER_IS_REGISTERED
;
2471 ioc
->diag_buffer_status
[buffer_type
] &=
2472 ~MPT3_DIAG_BUFFER_IS_RELEASED
;
2473 dctlprintk(ioc
, ioc_info(ioc
, "%s: success\n", __func__
));
2475 ioc_info(ioc
, "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2476 __func__
, ioc_status
,
2477 le32_to_cpu(mpi_reply
->IOCLogInfo
));
2483 mpt3sas_base_hard_reset_handler(ioc
, FORCE_BIG_HAMMER
);
2487 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
2492 * _ctl_addnl_diag_query - query relevant info associated with diag buffers
2493 * @ioc: per adapter object
2494 * @arg: user space buffer containing ioctl content
2496 * The application will send only unique_id. Driver will
2497 * inspect unique_id first, if valid, fill the details related to cause
2498 * for diag buffer release.
2501 _ctl_addnl_diag_query(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
2503 struct mpt3_addnl_diag_query karg
;
2504 u32 buffer_type
= 0;
2506 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2507 pr_err("%s: failure at %s:%d/%s()!\n",
2508 ioc
->name
, __FILE__
, __LINE__
, __func__
);
2511 dctlprintk(ioc
, ioc_info(ioc
, "%s\n", __func__
));
2512 if (karg
.unique_id
== 0) {
2513 ioc_err(ioc
, "%s: unique_id is(0x%08x)\n",
2514 __func__
, karg
.unique_id
);
2517 buffer_type
= _ctl_diag_get_bufftype(ioc
, karg
.unique_id
);
2518 if (buffer_type
== MPT3_DIAG_UID_NOT_FOUND
) {
2519 ioc_err(ioc
, "%s: buffer with unique_id(0x%08x) not found\n",
2520 __func__
, karg
.unique_id
);
2523 memset(&karg
.rel_query
, 0, sizeof(karg
.rel_query
));
2524 if ((ioc
->diag_buffer_status
[buffer_type
] &
2525 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2526 ioc_info(ioc
, "%s: buffer_type(0x%02x) is not registered\n",
2527 __func__
, buffer_type
);
2530 if ((ioc
->diag_buffer_status
[buffer_type
] &
2531 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0) {
2532 ioc_err(ioc
, "%s: buffer_type(0x%02x) is not released\n",
2533 __func__
, buffer_type
);
2536 memcpy(&karg
.rel_query
, &ioc
->htb_rel
, sizeof(karg
.rel_query
));
2538 if (copy_to_user(arg
, &karg
, sizeof(struct mpt3_addnl_diag_query
))) {
2539 ioc_err(ioc
, "%s: unable to write mpt3_addnl_diag_query data @ %p\n",
2547 * _ctl_enable_diag_sbr_reload - enable sbr reload bit
2548 * @ioc: per adapter object
2549 * @arg: user space buffer containing ioctl content
2551 * Enable the SBR reload bit
2554 _ctl_enable_diag_sbr_reload(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
2556 u32 ioc_state
, host_diagnostic
;
2558 if (ioc
->shost_recovery
||
2559 ioc
->pci_error_recovery
|| ioc
->is_driver_loading
||
2563 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
2565 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
)
2568 host_diagnostic
= ioc
->base_readl(&ioc
->chip
->HostDiagnostic
);
2570 if (host_diagnostic
& MPI2_DIAG_SBR_RELOAD
)
2573 if (mutex_trylock(&ioc
->hostdiag_unlock_mutex
)) {
2574 if (mpt3sas_base_unlock_and_get_host_diagnostic(ioc
, &host_diagnostic
)) {
2575 mutex_unlock(&ioc
->hostdiag_unlock_mutex
);
2581 host_diagnostic
|= MPI2_DIAG_SBR_RELOAD
;
2582 writel(host_diagnostic
, &ioc
->chip
->HostDiagnostic
);
2583 host_diagnostic
= ioc
->base_readl(&ioc
->chip
->HostDiagnostic
);
2584 mpt3sas_base_lock_host_diagnostic(ioc
);
2585 mutex_unlock(&ioc
->hostdiag_unlock_mutex
);
2587 if (!(host_diagnostic
& MPI2_DIAG_SBR_RELOAD
)) {
2588 ioc_err(ioc
, "%s: Failed to set Diag SBR Reload Bit\n", __func__
);
2592 ioc_info(ioc
, "%s: Successfully set the Diag SBR Reload Bit\n", __func__
);
2596 #ifdef CONFIG_COMPAT
2598 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2599 * @ioc: per adapter object
2600 * @cmd: ioctl opcode
2601 * @arg: (struct mpt3_ioctl_command32)
2603 * MPT3COMMAND32 - Handle 32bit applications running on 64bit os.
2606 _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER
*ioc
, unsigned cmd
,
2609 struct mpt3_ioctl_command32 karg32
;
2610 struct mpt3_ioctl_command32 __user
*uarg
;
2611 struct mpt3_ioctl_command karg
;
2613 if (_IOC_SIZE(cmd
) != sizeof(struct mpt3_ioctl_command32
))
2616 uarg
= (struct mpt3_ioctl_command32 __user
*) arg
;
2618 if (copy_from_user(&karg32
, (char __user
*)arg
, sizeof(karg32
))) {
2619 pr_err("failure at %s:%d/%s()!\n",
2620 __FILE__
, __LINE__
, __func__
);
2624 memset(&karg
, 0, sizeof(struct mpt3_ioctl_command
));
2625 karg
.hdr
.ioc_number
= karg32
.hdr
.ioc_number
;
2626 karg
.hdr
.port_number
= karg32
.hdr
.port_number
;
2627 karg
.hdr
.max_data_size
= karg32
.hdr
.max_data_size
;
2628 karg
.timeout
= karg32
.timeout
;
2629 karg
.max_reply_bytes
= karg32
.max_reply_bytes
;
2630 karg
.data_in_size
= karg32
.data_in_size
;
2631 karg
.data_out_size
= karg32
.data_out_size
;
2632 karg
.max_sense_bytes
= karg32
.max_sense_bytes
;
2633 karg
.data_sge_offset
= karg32
.data_sge_offset
;
2634 karg
.reply_frame_buf_ptr
= compat_ptr(karg32
.reply_frame_buf_ptr
);
2635 karg
.data_in_buf_ptr
= compat_ptr(karg32
.data_in_buf_ptr
);
2636 karg
.data_out_buf_ptr
= compat_ptr(karg32
.data_out_buf_ptr
);
2637 karg
.sense_data_ptr
= compat_ptr(karg32
.sense_data_ptr
);
2638 return _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2643 * _ctl_ioctl_main - main ioctl entry point
2644 * @file: (struct file)
2645 * @cmd: ioctl opcode
2646 * @arg: user space data buffer
2647 * @compat: handles 32 bit applications in 64bit os
2648 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
2649 * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
2652 _ctl_ioctl_main(struct file
*file
, unsigned int cmd
, void __user
*arg
,
2653 u8 compat
, u16 mpi_version
)
2655 struct MPT3SAS_ADAPTER
*ioc
;
2656 struct mpt3_ioctl_header ioctl_header
;
2657 enum block_state state
;
2658 long ret
= -ENOIOCTLCMD
;
2660 /* get IOCTL header */
2661 if (copy_from_user(&ioctl_header
, (char __user
*)arg
,
2662 sizeof(struct mpt3_ioctl_header
))) {
2663 pr_err("failure at %s:%d/%s()!\n",
2664 __FILE__
, __LINE__
, __func__
);
2668 if (_ctl_verify_adapter(ioctl_header
.ioc_number
,
2669 &ioc
, mpi_version
) == -1 || !ioc
)
2672 /* pci_access_mutex lock acquired by ioctl path */
2673 mutex_lock(&ioc
->pci_access_mutex
);
2675 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
2676 ioc
->is_driver_loading
|| ioc
->remove_host
) {
2678 goto out_unlock_pciaccess
;
2681 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
: BLOCKING
;
2682 if (state
== NON_BLOCKING
) {
2683 if (!mutex_trylock(&ioc
->ctl_cmds
.mutex
)) {
2685 goto out_unlock_pciaccess
;
2687 } else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
)) {
2689 goto out_unlock_pciaccess
;
2695 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_iocinfo
))
2696 ret
= _ctl_getiocinfo(ioc
, arg
);
2698 #ifdef CONFIG_COMPAT
2703 struct mpt3_ioctl_command __user
*uarg
;
2704 struct mpt3_ioctl_command karg
;
2706 #ifdef CONFIG_COMPAT
2708 ret
= _ctl_compat_mpt_command(ioc
, cmd
, arg
);
2712 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2713 pr_err("failure at %s:%d/%s()!\n",
2714 __FILE__
, __LINE__
, __func__
);
2719 if (karg
.hdr
.ioc_number
!= ioctl_header
.ioc_number
) {
2723 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_command
)) {
2725 ret
= _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2729 case MPT3EVENTQUERY
:
2730 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_eventquery
))
2731 ret
= _ctl_eventquery(ioc
, arg
);
2733 case MPT3EVENTENABLE
:
2734 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_eventenable
))
2735 ret
= _ctl_eventenable(ioc
, arg
);
2737 case MPT3EVENTREPORT
:
2738 ret
= _ctl_eventreport(ioc
, arg
);
2741 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_diag_reset
))
2742 ret
= _ctl_do_reset(ioc
, arg
);
2744 case MPT3BTDHMAPPING
:
2745 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_btdh_mapping
))
2746 ret
= _ctl_btdh_mapping(ioc
, arg
);
2748 case MPT3DIAGREGISTER
:
2749 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_register
))
2750 ret
= _ctl_diag_register(ioc
, arg
);
2752 case MPT3DIAGUNREGISTER
:
2753 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_unregister
))
2754 ret
= _ctl_diag_unregister(ioc
, arg
);
2757 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_query
))
2758 ret
= _ctl_diag_query(ioc
, arg
);
2760 case MPT3DIAGRELEASE
:
2761 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_release
))
2762 ret
= _ctl_diag_release(ioc
, arg
);
2764 case MPT3DIAGREADBUFFER
:
2765 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_read_buffer
))
2766 ret
= _ctl_diag_read_buffer(ioc
, arg
);
2768 case MPT3ADDNLDIAGQUERY
:
2769 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_addnl_diag_query
))
2770 ret
= _ctl_addnl_diag_query(ioc
, arg
);
2772 case MPT3ENABLEDIAGSBRRELOAD
:
2773 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_enable_diag_sbr_reload
))
2774 ret
= _ctl_enable_diag_sbr_reload(ioc
, arg
);
2778 ioc_info(ioc
, "unsupported ioctl opcode(0x%08x)\n",
2783 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
2784 out_unlock_pciaccess
:
2785 mutex_unlock(&ioc
->pci_access_mutex
);
2790 * _ctl_ioctl - mpt3ctl main ioctl entry point (unlocked)
2791 * @file: (struct file)
2792 * @cmd: ioctl opcode
2796 _ctl_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2800 /* pass MPI25_VERSION | MPI26_VERSION value,
2801 * to indicate that this ioctl cmd
2802 * came from mpt3ctl ioctl device.
2804 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 0,
2805 MPI25_VERSION
| MPI26_VERSION
);
2810 * _ctl_mpt2_ioctl - mpt2ctl main ioctl entry point (unlocked)
2811 * @file: (struct file)
2812 * @cmd: ioctl opcode
2816 _ctl_mpt2_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2820 /* pass MPI2_VERSION value, to indicate that this ioctl cmd
2821 * came from mpt2ctl ioctl device.
2823 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 0, MPI2_VERSION
);
2826 #ifdef CONFIG_COMPAT
2828 * _ctl_ioctl_compat - main ioctl entry point (compat)
2833 * This routine handles 32 bit applications in 64bit os.
2836 _ctl_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2840 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 1,
2841 MPI25_VERSION
| MPI26_VERSION
);
2846 * _ctl_mpt2_ioctl_compat - main ioctl entry point (compat)
2851 * This routine handles 32 bit applications in 64bit os.
2854 _ctl_mpt2_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2858 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 1, MPI2_VERSION
);
2863 /* scsi host attributes */
2865 * version_fw_show - firmware version
2866 * @cdev: pointer to embedded class device
2868 * @buf: the buffer returned
2870 * A sysfs 'read-only' shost attribute.
2873 version_fw_show(struct device
*cdev
, struct device_attribute
*attr
,
2876 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2877 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2879 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2880 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2881 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2882 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2883 ioc
->facts
.FWVersion
.Word
& 0x000000FF);
2885 static DEVICE_ATTR_RO(version_fw
);
2888 * version_bios_show - bios version
2889 * @cdev: pointer to embedded class device
2891 * @buf: the buffer returned
2893 * A sysfs 'read-only' shost attribute.
2896 version_bios_show(struct device
*cdev
, struct device_attribute
*attr
,
2899 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2900 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2902 u32 version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2904 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2905 (version
& 0xFF000000) >> 24,
2906 (version
& 0x00FF0000) >> 16,
2907 (version
& 0x0000FF00) >> 8,
2908 version
& 0x000000FF);
2910 static DEVICE_ATTR_RO(version_bios
);
2913 * version_mpi_show - MPI (message passing interface) version
2914 * @cdev: pointer to embedded class device
2916 * @buf: the buffer returned
2918 * A sysfs 'read-only' shost attribute.
2921 version_mpi_show(struct device
*cdev
, struct device_attribute
*attr
,
2924 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2925 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2927 return snprintf(buf
, PAGE_SIZE
, "%03x.%02x\n",
2928 ioc
->facts
.MsgVersion
, ioc
->facts
.HeaderVersion
>> 8);
2930 static DEVICE_ATTR_RO(version_mpi
);
2933 * version_product_show - product name
2934 * @cdev: pointer to embedded class device
2936 * @buf: the buffer returned
2938 * A sysfs 'read-only' shost attribute.
2941 version_product_show(struct device
*cdev
, struct device_attribute
*attr
,
2944 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2945 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2947 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.ChipName
);
2949 static DEVICE_ATTR_RO(version_product
);
2952 * version_nvdata_persistent_show - ndvata persistent version
2953 * @cdev: pointer to embedded class device
2955 * @buf: the buffer returned
2957 * A sysfs 'read-only' shost attribute.
2960 version_nvdata_persistent_show(struct device
*cdev
,
2961 struct device_attribute
*attr
, char *buf
)
2963 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2964 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2966 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2967 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionPersistent
.Word
));
2969 static DEVICE_ATTR_RO(version_nvdata_persistent
);
2972 * version_nvdata_default_show - nvdata default version
2973 * @cdev: pointer to embedded class device
2975 * @buf: the buffer returned
2977 * A sysfs 'read-only' shost attribute.
2980 version_nvdata_default_show(struct device
*cdev
, struct device_attribute
2983 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2984 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2986 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2987 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionDefault
.Word
));
2989 static DEVICE_ATTR_RO(version_nvdata_default
);
2992 * board_name_show - board name
2993 * @cdev: pointer to embedded class device
2995 * @buf: the buffer returned
2997 * A sysfs 'read-only' shost attribute.
3000 board_name_show(struct device
*cdev
, struct device_attribute
*attr
,
3003 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3004 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3006 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardName
);
3008 static DEVICE_ATTR_RO(board_name
);
3011 * board_assembly_show - board assembly name
3012 * @cdev: pointer to embedded class device
3014 * @buf: the buffer returned
3016 * A sysfs 'read-only' shost attribute.
3019 board_assembly_show(struct device
*cdev
, struct device_attribute
*attr
,
3022 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3023 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3025 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardAssembly
);
3027 static DEVICE_ATTR_RO(board_assembly
);
3030 * board_tracer_show - board tracer number
3031 * @cdev: pointer to embedded class device
3033 * @buf: the buffer returned
3035 * A sysfs 'read-only' shost attribute.
3038 board_tracer_show(struct device
*cdev
, struct device_attribute
*attr
,
3041 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3042 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3044 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardTracerNumber
);
3046 static DEVICE_ATTR_RO(board_tracer
);
3049 * io_delay_show - io missing delay
3050 * @cdev: pointer to embedded class device
3052 * @buf: the buffer returned
3054 * This is for firmware implemention for deboucing device
3057 * A sysfs 'read-only' shost attribute.
3060 io_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
3063 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3064 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3066 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->io_missing_delay
);
3068 static DEVICE_ATTR_RO(io_delay
);
3071 * device_delay_show - device missing delay
3072 * @cdev: pointer to embedded class device
3074 * @buf: the buffer returned
3076 * This is for firmware implemention for deboucing device
3079 * A sysfs 'read-only' shost attribute.
3082 device_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
3085 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3086 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3088 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->device_missing_delay
);
3090 static DEVICE_ATTR_RO(device_delay
);
3093 * fw_queue_depth_show - global credits
3094 * @cdev: pointer to embedded class device
3096 * @buf: the buffer returned
3098 * This is firmware queue depth limit
3100 * A sysfs 'read-only' shost attribute.
3103 fw_queue_depth_show(struct device
*cdev
, struct device_attribute
*attr
,
3106 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3107 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3109 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->facts
.RequestCredit
);
3111 static DEVICE_ATTR_RO(fw_queue_depth
);
3114 * host_sas_address_show - sas address
3115 * @cdev: pointer to embedded class device
3117 * @buf: the buffer returned
3119 * This is the controller sas address
3121 * A sysfs 'read-only' shost attribute.
3124 host_sas_address_show(struct device
*cdev
, struct device_attribute
*attr
,
3128 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3129 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3131 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
3132 (unsigned long long)ioc
->sas_hba
.sas_address
);
3134 static DEVICE_ATTR_RO(host_sas_address
);
3137 * logging_level_show - logging level
3138 * @cdev: pointer to embedded class device
3140 * @buf: the buffer returned
3142 * A sysfs 'read/write' shost attribute.
3145 logging_level_show(struct device
*cdev
, struct device_attribute
*attr
,
3148 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3149 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3151 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", ioc
->logging_level
);
3154 logging_level_store(struct device
*cdev
, struct device_attribute
*attr
,
3155 const char *buf
, size_t count
)
3157 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3158 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3161 if (sscanf(buf
, "%x", &val
) != 1)
3164 ioc
->logging_level
= val
;
3165 ioc_info(ioc
, "logging_level=%08xh\n",
3166 ioc
->logging_level
);
3169 static DEVICE_ATTR_RW(logging_level
);
3172 * fwfault_debug_show - show/store fwfault_debug
3173 * @cdev: pointer to embedded class device
3175 * @buf: the buffer returned
3177 * mpt3sas_fwfault_debug is command line option
3178 * A sysfs 'read/write' shost attribute.
3181 fwfault_debug_show(struct device
*cdev
, struct device_attribute
*attr
,
3184 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3185 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3187 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->fwfault_debug
);
3190 fwfault_debug_store(struct device
*cdev
, struct device_attribute
*attr
,
3191 const char *buf
, size_t count
)
3193 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3194 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3197 if (sscanf(buf
, "%d", &val
) != 1)
3200 ioc
->fwfault_debug
= val
;
3201 ioc_info(ioc
, "fwfault_debug=%d\n",
3202 ioc
->fwfault_debug
);
3205 static DEVICE_ATTR_RW(fwfault_debug
);
3208 * ioc_reset_count_show - ioc reset count
3209 * @cdev: pointer to embedded class device
3211 * @buf: the buffer returned
3213 * This is firmware queue depth limit
3215 * A sysfs 'read-only' shost attribute.
3218 ioc_reset_count_show(struct device
*cdev
, struct device_attribute
*attr
,
3221 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3222 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3224 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->ioc_reset_count
);
3226 static DEVICE_ATTR_RO(ioc_reset_count
);
3229 * reply_queue_count_show - number of reply queues
3230 * @cdev: pointer to embedded class device
3232 * @buf: the buffer returned
3234 * This is number of reply queues
3236 * A sysfs 'read-only' shost attribute.
3239 reply_queue_count_show(struct device
*cdev
,
3240 struct device_attribute
*attr
, char *buf
)
3242 u8 reply_queue_count
;
3243 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3244 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3246 if ((ioc
->facts
.IOCCapabilities
&
3247 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
)
3248 reply_queue_count
= ioc
->reply_queue_count
;
3250 reply_queue_count
= 1;
3252 return snprintf(buf
, PAGE_SIZE
, "%d\n", reply_queue_count
);
3254 static DEVICE_ATTR_RO(reply_queue_count
);
3257 * BRM_status_show - Backup Rail Monitor Status
3258 * @cdev: pointer to embedded class device
3260 * @buf: the buffer returned
3262 * This is number of reply queues
3264 * A sysfs 'read-only' shost attribute.
3267 BRM_status_show(struct device
*cdev
, struct device_attribute
*attr
,
3270 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3271 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3272 Mpi2IOUnitPage3_t io_unit_pg3
;
3273 Mpi2ConfigReply_t mpi_reply
;
3274 u16 backup_rail_monitor_status
= 0;
3279 if (!ioc
->is_warpdrive
) {
3280 ioc_err(ioc
, "%s: BRM attribute is only for warpdrive\n",
3284 /* pci_access_mutex lock acquired by sysfs show path */
3285 mutex_lock(&ioc
->pci_access_mutex
);
3286 if (ioc
->pci_error_recovery
|| ioc
->remove_host
)
3289 sz
= sizeof(io_unit_pg3
);
3290 memset(&io_unit_pg3
, 0, sz
);
3292 if (mpt3sas_config_get_iounit_pg3(ioc
, &mpi_reply
, &io_unit_pg3
, sz
) !=
3294 ioc_err(ioc
, "%s: failed reading iounit_pg3\n",
3300 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
3301 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
3302 ioc_err(ioc
, "%s: iounit_pg3 failed with ioc_status(0x%04x)\n",
3303 __func__
, ioc_status
);
3308 if (io_unit_pg3
.GPIOCount
< 25) {
3309 ioc_err(ioc
, "%s: iounit_pg3.GPIOCount less than 25 entries, detected (%d) entries\n",
3310 __func__
, io_unit_pg3
.GPIOCount
);
3315 /* BRM status is in bit zero of GPIOVal[24] */
3316 backup_rail_monitor_status
= le16_to_cpu(io_unit_pg3
.GPIOVal
[24]);
3317 rc
= snprintf(buf
, PAGE_SIZE
, "%d\n", (backup_rail_monitor_status
& 1));
3320 mutex_unlock(&ioc
->pci_access_mutex
);
3323 static DEVICE_ATTR_RO(BRM_status
);
3325 struct DIAG_BUFFER_START
{
3336 * host_trace_buffer_size_show - host buffer size (trace only)
3337 * @cdev: pointer to embedded class device
3339 * @buf: the buffer returned
3341 * A sysfs 'read-only' shost attribute.
3344 host_trace_buffer_size_show(struct device
*cdev
,
3345 struct device_attribute
*attr
, char *buf
)
3347 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3348 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3350 struct DIAG_BUFFER_START
*request_data
;
3352 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
3353 ioc_err(ioc
, "%s: host_trace_buffer is not registered\n",
3358 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3359 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
3360 ioc_err(ioc
, "%s: host_trace_buffer is not registered\n",
3365 request_data
= (struct DIAG_BUFFER_START
*)
3366 ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
];
3367 if ((le32_to_cpu(request_data
->DiagVersion
) == 0x00000000 ||
3368 le32_to_cpu(request_data
->DiagVersion
) == 0x01000000 ||
3369 le32_to_cpu(request_data
->DiagVersion
) == 0x01010000) &&
3370 le32_to_cpu(request_data
->Reserved3
) == 0x4742444c)
3371 size
= le32_to_cpu(request_data
->Size
);
3373 ioc
->ring_buffer_sz
= size
;
3374 return snprintf(buf
, PAGE_SIZE
, "%d\n", size
);
3376 static DEVICE_ATTR_RO(host_trace_buffer_size
);
3379 * host_trace_buffer_show - firmware ring buffer (trace only)
3380 * @cdev: pointer to embedded class device
3382 * @buf: the buffer returned
3384 * A sysfs 'read/write' shost attribute.
3386 * You will only be able to read 4k bytes of ring buffer at a time.
3387 * In order to read beyond 4k bytes, you will have to write out the
3388 * offset to the same attribute, it will move the pointer.
3391 host_trace_buffer_show(struct device
*cdev
, struct device_attribute
*attr
,
3394 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3395 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3399 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
3400 ioc_err(ioc
, "%s: host_trace_buffer is not registered\n",
3405 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3406 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
3407 ioc_err(ioc
, "%s: host_trace_buffer is not registered\n",
3412 if (ioc
->ring_buffer_offset
> ioc
->ring_buffer_sz
)
3415 size
= ioc
->ring_buffer_sz
- ioc
->ring_buffer_offset
;
3416 size
= (size
>= PAGE_SIZE
) ? (PAGE_SIZE
- 1) : size
;
3417 request_data
= ioc
->diag_buffer
[0] + ioc
->ring_buffer_offset
;
3418 memcpy(buf
, request_data
, size
);
3423 host_trace_buffer_store(struct device
*cdev
, struct device_attribute
*attr
,
3424 const char *buf
, size_t count
)
3426 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3427 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3430 if (sscanf(buf
, "%d", &val
) != 1)
3433 ioc
->ring_buffer_offset
= val
;
3436 static DEVICE_ATTR_RW(host_trace_buffer
);
3439 /*****************************************/
3442 * host_trace_buffer_enable_show - firmware ring buffer (trace only)
3443 * @cdev: pointer to embedded class device
3445 * @buf: the buffer returned
3447 * A sysfs 'read/write' shost attribute.
3449 * This is a mechnism to post/release host_trace_buffers
3452 host_trace_buffer_enable_show(struct device
*cdev
,
3453 struct device_attribute
*attr
, char *buf
)
3455 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3456 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3458 if ((!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) ||
3459 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3460 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0))
3461 return snprintf(buf
, PAGE_SIZE
, "off\n");
3462 else if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3463 MPT3_DIAG_BUFFER_IS_RELEASED
))
3464 return snprintf(buf
, PAGE_SIZE
, "release\n");
3466 return snprintf(buf
, PAGE_SIZE
, "post\n");
3470 host_trace_buffer_enable_store(struct device
*cdev
,
3471 struct device_attribute
*attr
, const char *buf
, size_t count
)
3473 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3474 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3476 struct mpt3_diag_register diag_register
;
3479 /* don't allow post/release occurr while recovery is active */
3480 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3481 ioc
->pci_error_recovery
|| ioc
->is_driver_loading
)
3484 if (sscanf(buf
, "%9s", str
) != 1)
3487 if (!strcmp(str
, "post")) {
3488 /* exit out if host buffers are already posted */
3489 if ((ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) &&
3490 (ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3491 MPT3_DIAG_BUFFER_IS_REGISTERED
) &&
3492 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3493 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0))
3495 memset(&diag_register
, 0, sizeof(struct mpt3_diag_register
));
3496 ioc_info(ioc
, "posting host trace buffers\n");
3497 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
3499 if (ioc
->manu_pg11
.HostTraceBufferMaxSizeKB
!= 0 &&
3500 ioc
->diag_buffer_sz
[MPI2_DIAG_BUF_TYPE_TRACE
] != 0) {
3501 /* post the same buffer allocated previously */
3502 diag_register
.requested_buffer_size
=
3503 ioc
->diag_buffer_sz
[MPI2_DIAG_BUF_TYPE_TRACE
];
3506 * Free the diag buffer memory which was previously
3507 * allocated by an application.
3509 if ((ioc
->diag_buffer_sz
[MPI2_DIAG_BUF_TYPE_TRACE
] != 0)
3511 (ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3512 MPT3_DIAG_BUFFER_IS_APP_OWNED
)) {
3513 dma_free_coherent(&ioc
->pdev
->dev
,
3514 ioc
->diag_buffer_sz
[MPI2_DIAG_BUF_TYPE_TRACE
],
3515 ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
],
3516 ioc
->diag_buffer_dma
[MPI2_DIAG_BUF_TYPE_TRACE
]);
3517 ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
] =
3521 diag_register
.requested_buffer_size
= (1024 * 1024);
3524 diag_register
.unique_id
=
3525 (ioc
->hba_mpi_version_belonged
== MPI2_VERSION
) ?
3526 (MPT2DIAGBUFFUNIQUEID
):(MPT3DIAGBUFFUNIQUEID
);
3527 ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] = 0;
3528 _ctl_diag_register_2(ioc
, &diag_register
);
3529 if (ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3530 MPT3_DIAG_BUFFER_IS_REGISTERED
) {
3532 "Trace buffer %d KB allocated through sysfs\n",
3533 diag_register
.requested_buffer_size
>>10);
3534 if (ioc
->hba_mpi_version_belonged
!= MPI2_VERSION
)
3535 ioc
->diag_buffer_status
[
3536 MPI2_DIAG_BUF_TYPE_TRACE
] |=
3537 MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED
;
3539 } else if (!strcmp(str
, "release")) {
3540 /* exit out if host buffers are already released */
3541 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
])
3543 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3544 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0)
3546 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3547 MPT3_DIAG_BUFFER_IS_RELEASED
))
3549 ioc_info(ioc
, "releasing host trace buffer\n");
3550 ioc
->htb_rel
.buffer_rel_condition
= MPT3_DIAG_BUFFER_REL_SYSFS
;
3551 mpt3sas_send_diag_release(ioc
, MPI2_DIAG_BUF_TYPE_TRACE
,
3558 static DEVICE_ATTR_RW(host_trace_buffer_enable
);
3560 /*********** diagnostic trigger suppport *********************************/
3563 * diag_trigger_master_show - show the diag_trigger_master attribute
3564 * @cdev: pointer to embedded class device
3566 * @buf: the buffer returned
3568 * A sysfs 'read/write' shost attribute.
3571 diag_trigger_master_show(struct device
*cdev
,
3572 struct device_attribute
*attr
, char *buf
)
3575 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3576 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3577 unsigned long flags
;
3580 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3581 rc
= sizeof(struct SL_WH_MASTER_TRIGGER_T
);
3582 memcpy(buf
, &ioc
->diag_trigger_master
, rc
);
3583 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3588 * diag_trigger_master_store - store the diag_trigger_master attribute
3589 * @cdev: pointer to embedded class device
3591 * @buf: the buffer returned
3594 * A sysfs 'read/write' shost attribute.
3597 diag_trigger_master_store(struct device
*cdev
,
3598 struct device_attribute
*attr
, const char *buf
, size_t count
)
3601 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3602 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3603 struct SL_WH_MASTER_TRIGGER_T
*master_tg
;
3604 unsigned long flags
;
3608 rc
= min(sizeof(struct SL_WH_MASTER_TRIGGER_T
), count
);
3610 if (ioc
->supports_trigger_pages
) {
3611 master_tg
= kzalloc(sizeof(struct SL_WH_MASTER_TRIGGER_T
),
3616 memcpy(master_tg
, buf
, rc
);
3617 if (!master_tg
->MasterData
)
3619 if (mpt3sas_config_update_driver_trigger_pg1(ioc
, master_tg
,
3627 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3628 memset(&ioc
->diag_trigger_master
, 0,
3629 sizeof(struct SL_WH_MASTER_TRIGGER_T
));
3630 memcpy(&ioc
->diag_trigger_master
, buf
, rc
);
3631 ioc
->diag_trigger_master
.MasterData
|=
3632 (MASTER_TRIGGER_FW_FAULT
+ MASTER_TRIGGER_ADAPTER_RESET
);
3633 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3636 static DEVICE_ATTR_RW(diag_trigger_master
);
3640 * diag_trigger_event_show - show the diag_trigger_event attribute
3641 * @cdev: pointer to embedded class device
3643 * @buf: the buffer returned
3645 * A sysfs 'read/write' shost attribute.
3648 diag_trigger_event_show(struct device
*cdev
,
3649 struct device_attribute
*attr
, char *buf
)
3651 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3652 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3653 unsigned long flags
;
3656 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3657 rc
= sizeof(struct SL_WH_EVENT_TRIGGERS_T
);
3658 memcpy(buf
, &ioc
->diag_trigger_event
, rc
);
3659 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3664 * diag_trigger_event_store - store the diag_trigger_event attribute
3665 * @cdev: pointer to embedded class device
3667 * @buf: the buffer returned
3670 * A sysfs 'read/write' shost attribute.
3673 diag_trigger_event_store(struct device
*cdev
,
3674 struct device_attribute
*attr
, const char *buf
, size_t count
)
3677 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3678 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3679 struct SL_WH_EVENT_TRIGGERS_T
*event_tg
;
3680 unsigned long flags
;
3684 sz
= min(sizeof(struct SL_WH_EVENT_TRIGGERS_T
), count
);
3685 if (ioc
->supports_trigger_pages
) {
3686 event_tg
= kzalloc(sizeof(struct SL_WH_EVENT_TRIGGERS_T
),
3691 memcpy(event_tg
, buf
, sz
);
3692 if (!event_tg
->ValidEntries
)
3694 if (mpt3sas_config_update_driver_trigger_pg2(ioc
, event_tg
,
3702 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3704 memset(&ioc
->diag_trigger_event
, 0,
3705 sizeof(struct SL_WH_EVENT_TRIGGERS_T
));
3706 memcpy(&ioc
->diag_trigger_event
, buf
, sz
);
3707 if (ioc
->diag_trigger_event
.ValidEntries
> NUM_VALID_ENTRIES
)
3708 ioc
->diag_trigger_event
.ValidEntries
= NUM_VALID_ENTRIES
;
3709 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3712 static DEVICE_ATTR_RW(diag_trigger_event
);
3716 * diag_trigger_scsi_show - show the diag_trigger_scsi attribute
3717 * @cdev: pointer to embedded class device
3719 * @buf: the buffer returned
3721 * A sysfs 'read/write' shost attribute.
3724 diag_trigger_scsi_show(struct device
*cdev
,
3725 struct device_attribute
*attr
, char *buf
)
3727 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3728 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3729 unsigned long flags
;
3732 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3733 rc
= sizeof(struct SL_WH_SCSI_TRIGGERS_T
);
3734 memcpy(buf
, &ioc
->diag_trigger_scsi
, rc
);
3735 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3740 * diag_trigger_scsi_store - store the diag_trigger_scsi attribute
3741 * @cdev: pointer to embedded class device
3743 * @buf: the buffer returned
3746 * A sysfs 'read/write' shost attribute.
3749 diag_trigger_scsi_store(struct device
*cdev
,
3750 struct device_attribute
*attr
, const char *buf
, size_t count
)
3752 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3753 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3754 struct SL_WH_SCSI_TRIGGERS_T
*scsi_tg
;
3755 unsigned long flags
;
3759 sz
= min(sizeof(struct SL_WH_SCSI_TRIGGERS_T
), count
);
3760 if (ioc
->supports_trigger_pages
) {
3761 scsi_tg
= kzalloc(sizeof(struct SL_WH_SCSI_TRIGGERS_T
),
3766 memcpy(scsi_tg
, buf
, sz
);
3767 if (!scsi_tg
->ValidEntries
)
3769 if (mpt3sas_config_update_driver_trigger_pg3(ioc
, scsi_tg
,
3777 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3779 memset(&ioc
->diag_trigger_scsi
, 0, sizeof(ioc
->diag_trigger_scsi
));
3780 memcpy(&ioc
->diag_trigger_scsi
, buf
, sz
);
3781 if (ioc
->diag_trigger_scsi
.ValidEntries
> NUM_VALID_ENTRIES
)
3782 ioc
->diag_trigger_scsi
.ValidEntries
= NUM_VALID_ENTRIES
;
3783 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3786 static DEVICE_ATTR_RW(diag_trigger_scsi
);
3790 * diag_trigger_mpi_show - show the diag_trigger_mpi attribute
3791 * @cdev: pointer to embedded class device
3793 * @buf: the buffer returned
3795 * A sysfs 'read/write' shost attribute.
3798 diag_trigger_mpi_show(struct device
*cdev
,
3799 struct device_attribute
*attr
, char *buf
)
3801 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3802 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3803 unsigned long flags
;
3806 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3807 rc
= sizeof(struct SL_WH_MPI_TRIGGERS_T
);
3808 memcpy(buf
, &ioc
->diag_trigger_mpi
, rc
);
3809 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3814 * diag_trigger_mpi_store - store the diag_trigger_mpi attribute
3815 * @cdev: pointer to embedded class device
3817 * @buf: the buffer returned
3820 * A sysfs 'read/write' shost attribute.
3823 diag_trigger_mpi_store(struct device
*cdev
,
3824 struct device_attribute
*attr
, const char *buf
, size_t count
)
3826 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3827 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3828 struct SL_WH_MPI_TRIGGERS_T
*mpi_tg
;
3829 unsigned long flags
;
3833 sz
= min(sizeof(struct SL_WH_MPI_TRIGGERS_T
), count
);
3834 if (ioc
->supports_trigger_pages
) {
3835 mpi_tg
= kzalloc(sizeof(struct SL_WH_MPI_TRIGGERS_T
),
3840 memcpy(mpi_tg
, buf
, sz
);
3841 if (!mpi_tg
->ValidEntries
)
3843 if (mpt3sas_config_update_driver_trigger_pg4(ioc
, mpi_tg
,
3851 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3852 memset(&ioc
->diag_trigger_mpi
, 0,
3853 sizeof(ioc
->diag_trigger_mpi
));
3854 memcpy(&ioc
->diag_trigger_mpi
, buf
, sz
);
3855 if (ioc
->diag_trigger_mpi
.ValidEntries
> NUM_VALID_ENTRIES
)
3856 ioc
->diag_trigger_mpi
.ValidEntries
= NUM_VALID_ENTRIES
;
3857 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3861 static DEVICE_ATTR_RW(diag_trigger_mpi
);
3863 /*********** diagnostic trigger suppport *** END ****************************/
3865 /*****************************************/
3868 * drv_support_bitmap_show - driver supported feature bitmap
3869 * @cdev: pointer to embedded class device
3871 * @buf: the buffer returned
3873 * A sysfs 'read-only' shost attribute.
3876 drv_support_bitmap_show(struct device
*cdev
,
3877 struct device_attribute
*attr
, char *buf
)
3879 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3880 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3882 return snprintf(buf
, PAGE_SIZE
, "0x%08x\n", ioc
->drv_support_bitmap
);
3884 static DEVICE_ATTR_RO(drv_support_bitmap
);
3887 * enable_sdev_max_qd_show - display whether sdev max qd is enabled/disabled
3888 * @cdev: pointer to embedded class device
3890 * @buf: the buffer returned
3892 * A sysfs read/write shost attribute. This attribute is used to set the
3893 * targets queue depth to HBA IO queue depth if this attribute is enabled.
3896 enable_sdev_max_qd_show(struct device
*cdev
,
3897 struct device_attribute
*attr
, char *buf
)
3899 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3900 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3902 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->enable_sdev_max_qd
);
3906 * enable_sdev_max_qd_store - Enable/disable sdev max qd
3907 * @cdev: pointer to embedded class device
3909 * @buf: the buffer returned
3912 * A sysfs read/write shost attribute. This attribute is used to set the
3913 * targets queue depth to HBA IO queue depth if this attribute is enabled.
3914 * If this attribute is disabled then targets will have corresponding default
3918 enable_sdev_max_qd_store(struct device
*cdev
,
3919 struct device_attribute
*attr
, const char *buf
, size_t count
)
3921 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3922 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3923 struct MPT3SAS_DEVICE
*sas_device_priv_data
;
3924 struct MPT3SAS_TARGET
*sas_target_priv_data
;
3926 struct scsi_device
*sdev
;
3927 struct _raid_device
*raid_device
;
3930 if (kstrtoint(buf
, 0, &val
) != 0)
3935 ioc
->enable_sdev_max_qd
= 0;
3936 shost_for_each_device(sdev
, ioc
->shost
) {
3937 sas_device_priv_data
= sdev
->hostdata
;
3938 if (!sas_device_priv_data
)
3940 sas_target_priv_data
= sas_device_priv_data
->sas_target
;
3941 if (!sas_target_priv_data
)
3944 if (sas_target_priv_data
->flags
&
3945 MPT_TARGET_FLAGS_VOLUME
) {
3947 mpt3sas_raid_device_find_by_handle(ioc
,
3948 sas_target_priv_data
->handle
);
3950 switch (raid_device
->volume_type
) {
3951 case MPI2_RAID_VOL_TYPE_RAID0
:
3952 if (raid_device
->device_info
&
3953 MPI2_SAS_DEVICE_INFO_SSP_TARGET
)
3955 MPT3SAS_SAS_QUEUE_DEPTH
;
3958 MPT3SAS_SATA_QUEUE_DEPTH
;
3960 case MPI2_RAID_VOL_TYPE_RAID1E
:
3961 case MPI2_RAID_VOL_TYPE_RAID1
:
3962 case MPI2_RAID_VOL_TYPE_RAID10
:
3963 case MPI2_RAID_VOL_TYPE_UNKNOWN
:
3965 qdepth
= MPT3SAS_RAID_QUEUE_DEPTH
;
3967 } else if (sas_target_priv_data
->flags
&
3968 MPT_TARGET_FLAGS_PCIE_DEVICE
)
3969 qdepth
= ioc
->max_nvme_qd
;
3971 qdepth
= (sas_target_priv_data
->sas_dev
->port_type
> 1) ?
3972 ioc
->max_wideport_qd
: ioc
->max_narrowport_qd
;
3974 mpt3sas_scsih_change_queue_depth(sdev
, qdepth
);
3978 ioc
->enable_sdev_max_qd
= 1;
3979 shost_for_each_device(sdev
, ioc
->shost
)
3980 mpt3sas_scsih_change_queue_depth(sdev
,
3989 static DEVICE_ATTR_RW(enable_sdev_max_qd
);
3991 static struct attribute
*mpt3sas_host_attrs
[] = {
3992 &dev_attr_version_fw
.attr
,
3993 &dev_attr_version_bios
.attr
,
3994 &dev_attr_version_mpi
.attr
,
3995 &dev_attr_version_product
.attr
,
3996 &dev_attr_version_nvdata_persistent
.attr
,
3997 &dev_attr_version_nvdata_default
.attr
,
3998 &dev_attr_board_name
.attr
,
3999 &dev_attr_board_assembly
.attr
,
4000 &dev_attr_board_tracer
.attr
,
4001 &dev_attr_io_delay
.attr
,
4002 &dev_attr_device_delay
.attr
,
4003 &dev_attr_logging_level
.attr
,
4004 &dev_attr_fwfault_debug
.attr
,
4005 &dev_attr_fw_queue_depth
.attr
,
4006 &dev_attr_host_sas_address
.attr
,
4007 &dev_attr_ioc_reset_count
.attr
,
4008 &dev_attr_host_trace_buffer_size
.attr
,
4009 &dev_attr_host_trace_buffer
.attr
,
4010 &dev_attr_host_trace_buffer_enable
.attr
,
4011 &dev_attr_reply_queue_count
.attr
,
4012 &dev_attr_diag_trigger_master
.attr
,
4013 &dev_attr_diag_trigger_event
.attr
,
4014 &dev_attr_diag_trigger_scsi
.attr
,
4015 &dev_attr_diag_trigger_mpi
.attr
,
4016 &dev_attr_drv_support_bitmap
.attr
,
4017 &dev_attr_BRM_status
.attr
,
4018 &dev_attr_enable_sdev_max_qd
.attr
,
4022 static const struct attribute_group mpt3sas_host_attr_group
= {
4023 .attrs
= mpt3sas_host_attrs
4026 const struct attribute_group
*mpt3sas_host_groups
[] = {
4027 &mpt3sas_host_attr_group
,
4031 /* device attributes */
4034 * sas_address_show - sas address
4035 * @dev: pointer to embedded class device
4037 * @buf: the buffer returned
4039 * This is the sas address for the target
4041 * A sysfs 'read-only' shost attribute.
4044 sas_address_show(struct device
*dev
, struct device_attribute
*attr
,
4047 struct scsi_device
*sdev
= to_scsi_device(dev
);
4048 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
4050 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
4051 (unsigned long long)sas_device_priv_data
->sas_target
->sas_address
);
4053 static DEVICE_ATTR_RO(sas_address
);
4056 * sas_device_handle_show - device handle
4057 * @dev: pointer to embedded class device
4059 * @buf: the buffer returned
4061 * This is the firmware assigned device handle
4063 * A sysfs 'read-only' shost attribute.
4066 sas_device_handle_show(struct device
*dev
, struct device_attribute
*attr
,
4069 struct scsi_device
*sdev
= to_scsi_device(dev
);
4070 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
4072 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n",
4073 sas_device_priv_data
->sas_target
->handle
);
4075 static DEVICE_ATTR_RO(sas_device_handle
);
4078 * sas_ncq_prio_supported_show - Indicate if device supports NCQ priority
4079 * @dev: pointer to embedded device
4080 * @attr: sas_ncq_prio_supported attribute descriptor
4081 * @buf: the buffer returned
4083 * A sysfs 'read-only' sdev attribute, only works with SATA
4086 sas_ncq_prio_supported_show(struct device
*dev
,
4087 struct device_attribute
*attr
, char *buf
)
4089 struct scsi_device
*sdev
= to_scsi_device(dev
);
4091 return sysfs_emit(buf
, "%d\n", sas_ata_ncq_prio_supported(sdev
));
4093 static DEVICE_ATTR_RO(sas_ncq_prio_supported
);
4096 * sas_ncq_prio_enable_show - send prioritized io commands to device
4097 * @dev: pointer to embedded device
4099 * @buf: the buffer returned
4101 * A sysfs 'read/write' sdev attribute, only works with SATA
4104 sas_ncq_prio_enable_show(struct device
*dev
,
4105 struct device_attribute
*attr
, char *buf
)
4107 struct scsi_device
*sdev
= to_scsi_device(dev
);
4108 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
4110 return snprintf(buf
, PAGE_SIZE
, "%d\n",
4111 sas_device_priv_data
->ncq_prio_enable
);
4115 sas_ncq_prio_enable_store(struct device
*dev
,
4116 struct device_attribute
*attr
,
4117 const char *buf
, size_t count
)
4119 struct scsi_device
*sdev
= to_scsi_device(dev
);
4120 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
4121 bool ncq_prio_enable
= 0;
4123 if (kstrtobool(buf
, &ncq_prio_enable
))
4126 if (!sas_ata_ncq_prio_supported(sdev
))
4129 sas_device_priv_data
->ncq_prio_enable
= ncq_prio_enable
;
4132 static DEVICE_ATTR_RW(sas_ncq_prio_enable
);
4134 static struct attribute
*mpt3sas_dev_attrs
[] = {
4135 &dev_attr_sas_address
.attr
,
4136 &dev_attr_sas_device_handle
.attr
,
4137 &dev_attr_sas_ncq_prio_supported
.attr
,
4138 &dev_attr_sas_ncq_prio_enable
.attr
,
4142 static const struct attribute_group mpt3sas_dev_attr_group
= {
4143 .attrs
= mpt3sas_dev_attrs
4146 const struct attribute_group
*mpt3sas_dev_groups
[] = {
4147 &mpt3sas_dev_attr_group
,
4151 /* file operations table for mpt3ctl device */
4152 static const struct file_operations ctl_fops
= {
4153 .owner
= THIS_MODULE
,
4154 .unlocked_ioctl
= _ctl_ioctl
,
4156 .fasync
= _ctl_fasync
,
4157 #ifdef CONFIG_COMPAT
4158 .compat_ioctl
= _ctl_ioctl_compat
,
4162 /* file operations table for mpt2ctl device */
4163 static const struct file_operations ctl_gen2_fops
= {
4164 .owner
= THIS_MODULE
,
4165 .unlocked_ioctl
= _ctl_mpt2_ioctl
,
4167 .fasync
= _ctl_fasync
,
4168 #ifdef CONFIG_COMPAT
4169 .compat_ioctl
= _ctl_mpt2_ioctl_compat
,
4173 static struct miscdevice ctl_dev
= {
4174 .minor
= MPT3SAS_MINOR
,
4175 .name
= MPT3SAS_DEV_NAME
,
4179 static struct miscdevice gen2_ctl_dev
= {
4180 .minor
= MPT2SAS_MINOR
,
4181 .name
= MPT2SAS_DEV_NAME
,
4182 .fops
= &ctl_gen2_fops
,
4186 * mpt3sas_ctl_init - main entry point for ctl.
4187 * @hbas_to_enumerate: ?
4190 mpt3sas_ctl_init(ushort hbas_to_enumerate
)
4194 /* Don't register mpt3ctl ioctl device if
4195 * hbas_to_enumarate is one.
4197 if (hbas_to_enumerate
!= 1)
4198 if (misc_register(&ctl_dev
) < 0)
4199 pr_err("%s can't register misc device [minor=%d]\n",
4200 MPT3SAS_DRIVER_NAME
, MPT3SAS_MINOR
);
4202 /* Don't register mpt3ctl ioctl device if
4203 * hbas_to_enumarate is two.
4205 if (hbas_to_enumerate
!= 2)
4206 if (misc_register(&gen2_ctl_dev
) < 0)
4207 pr_err("%s can't register misc device [minor=%d]\n",
4208 MPT2SAS_DRIVER_NAME
, MPT2SAS_MINOR
);
4210 init_waitqueue_head(&ctl_poll_wait
);
4214 * mpt3sas_ctl_release - release dma for ctl
4215 * @ioc: per adapter object
4218 mpt3sas_ctl_release(struct MPT3SAS_ADAPTER
*ioc
)
4222 /* free memory associated to diag buffers */
4223 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
4224 if (!ioc
->diag_buffer
[i
])
4226 dma_free_coherent(&ioc
->pdev
->dev
,
4227 ioc
->diag_buffer_sz
[i
],
4228 ioc
->diag_buffer
[i
],
4229 ioc
->diag_buffer_dma
[i
]);
4230 ioc
->diag_buffer
[i
] = NULL
;
4231 ioc
->diag_buffer_status
[i
] = 0;
4234 kfree(ioc
->event_log
);
4238 * mpt3sas_ctl_exit - exit point for ctl
4239 * @hbas_to_enumerate: ?
4242 mpt3sas_ctl_exit(ushort hbas_to_enumerate
)
4245 if (hbas_to_enumerate
!= 1)
4246 misc_deregister(&ctl_dev
);
4247 if (hbas_to_enumerate
!= 2)
4248 misc_deregister(&gen2_ctl_dev
);