2 * Management Module Support for MPT (Message Passing Technology) based
5 * This code is based on drivers/scsi/mpt3sas/mpt3sas_ctl.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * Copyright (C) 2013-2014 Avago Technologies
8 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 * solely responsible for determining the appropriateness of using and
26 * distributing the Program and assumes all risks associated with its
27 * exercise of rights under this Agreement, including but not limited to
28 * the risks and costs of program errors, damage to or loss of data,
29 * programs or equipment, and unavailability or interruption of operations.
31 * DISCLAIMER OF LIABILITY
32 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/slab.h>
51 #include <linux/types.h>
52 #include <linux/pci.h>
53 #include <linux/delay.h>
54 #include <linux/compat.h>
55 #include <linux/poll.h>
58 #include <linux/uaccess.h>
60 #include "mpt3sas_base.h"
61 #include "mpt3sas_ctl.h"
64 static struct fasync_struct
*async_queue
;
65 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait
);
69 * enum block_state - blocking state
70 * @NON_BLOCKING: non blocking
73 * These states are for ioctls that need to wait for a response
74 * from firmware, so they probably require sleep.
82 * _ctl_sas_device_find_by_handle - sas device search
83 * @ioc: per adapter object
84 * @handle: sas device handle (assigned by firmware)
85 * Context: Calling function should acquire ioc->sas_device_lock
87 * This searches for sas_device based on sas_address, then return sas_device
90 static struct _sas_device
*
91 _ctl_sas_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
93 struct _sas_device
*sas_device
, *r
;
96 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
97 if (sas_device
->handle
!= handle
)
108 * _ctl_display_some_debug - debug routine
109 * @ioc: per adapter object
110 * @smid: system request message index
111 * @calling_function_name: string pass from calling function
112 * @mpi_reply: reply message frame
115 * Function for displaying debug info helpful when debugging issues
119 _ctl_display_some_debug(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
120 char *calling_function_name
, MPI2DefaultReply_t
*mpi_reply
)
122 Mpi2ConfigRequest_t
*mpi_request
;
125 if (!(ioc
->logging_level
& MPT_DEBUG_IOCTL
))
128 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
129 switch (mpi_request
->Function
) {
130 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
132 Mpi2SCSIIORequest_t
*scsi_request
=
133 (Mpi2SCSIIORequest_t
*)mpi_request
;
135 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
136 "scsi_io, cmd(0x%02x), cdb_len(%d)",
137 scsi_request
->CDB
.CDB32
[0],
138 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
139 desc
= ioc
->tmp_string
;
142 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
145 case MPI2_FUNCTION_IOC_INIT
:
148 case MPI2_FUNCTION_IOC_FACTS
:
151 case MPI2_FUNCTION_CONFIG
:
153 Mpi2ConfigRequest_t
*config_request
=
154 (Mpi2ConfigRequest_t
*)mpi_request
;
156 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
157 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
158 (config_request
->Header
.PageType
&
159 MPI2_CONFIG_PAGETYPE_MASK
), config_request
->ExtPageType
,
160 config_request
->Header
.PageNumber
);
161 desc
= ioc
->tmp_string
;
164 case MPI2_FUNCTION_PORT_FACTS
:
167 case MPI2_FUNCTION_PORT_ENABLE
:
168 desc
= "port_enable";
170 case MPI2_FUNCTION_EVENT_NOTIFICATION
:
171 desc
= "event_notification";
173 case MPI2_FUNCTION_FW_DOWNLOAD
:
174 desc
= "fw_download";
176 case MPI2_FUNCTION_FW_UPLOAD
:
179 case MPI2_FUNCTION_RAID_ACTION
:
180 desc
= "raid_action";
182 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
184 Mpi2SCSIIORequest_t
*scsi_request
=
185 (Mpi2SCSIIORequest_t
*)mpi_request
;
187 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
188 "raid_pass, cmd(0x%02x), cdb_len(%d)",
189 scsi_request
->CDB
.CDB32
[0],
190 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
191 desc
= ioc
->tmp_string
;
194 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
195 desc
= "sas_iounit_cntl";
197 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
200 case MPI2_FUNCTION_DIAG_BUFFER_POST
:
201 desc
= "diag_buffer_post";
203 case MPI2_FUNCTION_DIAG_RELEASE
:
204 desc
= "diag_release";
206 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
207 desc
= "smp_passthrough";
214 pr_info(MPT3SAS_FMT
"%s: %s, smid(%d)\n",
215 ioc
->name
, calling_function_name
, desc
, smid
);
220 if (mpi_reply
->IOCStatus
|| mpi_reply
->IOCLogInfo
)
222 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
223 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
224 le32_to_cpu(mpi_reply
->IOCLogInfo
));
226 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
227 mpi_request
->Function
==
228 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
229 Mpi2SCSIIOReply_t
*scsi_reply
=
230 (Mpi2SCSIIOReply_t
*)mpi_reply
;
231 struct _sas_device
*sas_device
= NULL
;
234 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
235 sas_device
= _ctl_sas_device_find_by_handle(ioc
,
236 le16_to_cpu(scsi_reply
->DevHandle
));
238 pr_warn(MPT3SAS_FMT
"\tsas_address(0x%016llx), phy(%d)\n",
239 ioc
->name
, (unsigned long long)
240 sas_device
->sas_address
, sas_device
->phy
);
242 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
243 ioc
->name
, (unsigned long long)
244 sas_device
->enclosure_logical_id
, sas_device
->slot
);
246 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
247 if (scsi_reply
->SCSIState
|| scsi_reply
->SCSIStatus
)
249 "\tscsi_state(0x%02x), scsi_status"
250 "(0x%02x)\n", ioc
->name
,
251 scsi_reply
->SCSIState
,
252 scsi_reply
->SCSIStatus
);
257 * mpt3sas_ctl_done - ctl module completion routine
258 * @ioc: per adapter object
259 * @smid: system request message index
260 * @msix_index: MSIX table index supplied by the OS
261 * @reply: reply message frame(lower 32bit addr)
264 * The callback handler when using ioc->ctl_cb_idx.
266 * Return 1 meaning mf should be freed from _base_interrupt
267 * 0 means the mf is freed from this function.
270 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
273 MPI2DefaultReply_t
*mpi_reply
;
274 Mpi2SCSIIOReply_t
*scsiio_reply
;
275 const void *sense_data
;
278 if (ioc
->ctl_cmds
.status
== MPT3_CMD_NOT_USED
)
280 if (ioc
->ctl_cmds
.smid
!= smid
)
282 ioc
->ctl_cmds
.status
|= MPT3_CMD_COMPLETE
;
283 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
285 memcpy(ioc
->ctl_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
286 ioc
->ctl_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
288 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
289 mpi_reply
->Function
==
290 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
291 scsiio_reply
= (Mpi2SCSIIOReply_t
*)mpi_reply
;
292 if (scsiio_reply
->SCSIState
&
293 MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
294 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
295 le32_to_cpu(scsiio_reply
->SenseCount
));
296 sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
298 memcpy(ioc
->ctl_cmds
.sense
, sense_data
, sz
);
302 _ctl_display_some_debug(ioc
, smid
, "ctl_done", mpi_reply
);
303 ioc
->ctl_cmds
.status
&= ~MPT3_CMD_PENDING
;
304 complete(&ioc
->ctl_cmds
.done
);
309 * _ctl_check_event_type - determines when an event needs logging
310 * @ioc: per adapter object
311 * @event: firmware event
313 * The bitmask in ioc->event_type[] indicates which events should be
314 * be saved in the driver event_log. This bitmask is set by application.
316 * Returns 1 when event should be captured, or zero means no match.
319 _ctl_check_event_type(struct MPT3SAS_ADAPTER
*ioc
, u16 event
)
324 if (event
>= 128 || !event
|| !ioc
->event_log
)
327 desired_event
= (1 << (event
% 32));
331 return desired_event
& ioc
->event_type
[i
];
335 * mpt3sas_ctl_add_to_event_log - add event
336 * @ioc: per adapter object
337 * @mpi_reply: reply message frame
342 mpt3sas_ctl_add_to_event_log(struct MPT3SAS_ADAPTER
*ioc
,
343 Mpi2EventNotificationReply_t
*mpi_reply
)
345 struct MPT3_IOCTL_EVENTS
*event_log
;
348 u32 sz
, event_data_sz
;
354 event
= le16_to_cpu(mpi_reply
->Event
);
356 if (_ctl_check_event_type(ioc
, event
)) {
358 /* insert entry into circular event_log */
359 i
= ioc
->event_context
% MPT3SAS_CTL_EVENT_LOG_SIZE
;
360 event_log
= ioc
->event_log
;
361 event_log
[i
].event
= event
;
362 event_log
[i
].context
= ioc
->event_context
++;
364 event_data_sz
= le16_to_cpu(mpi_reply
->EventDataLength
)*4;
365 sz
= min_t(u32
, event_data_sz
, MPT3_EVENT_DATA_SIZE
);
366 memset(event_log
[i
].data
, 0, MPT3_EVENT_DATA_SIZE
);
367 memcpy(event_log
[i
].data
, mpi_reply
->EventData
, sz
);
371 /* This aen_event_read_flag flag is set until the
372 * application has read the event log.
373 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
375 if (event
== MPI2_EVENT_LOG_ENTRY_ADDED
||
376 (send_aen
&& !ioc
->aen_event_read_flag
)) {
377 ioc
->aen_event_read_flag
= 1;
378 wake_up_interruptible(&ctl_poll_wait
);
380 kill_fasync(&async_queue
, SIGIO
, POLL_IN
);
385 * mpt3sas_ctl_event_callback - firmware event handler (called at ISR time)
386 * @ioc: per adapter object
387 * @msix_index: MSIX table index supplied by the OS
388 * @reply: reply message frame(lower 32bit addr)
389 * Context: interrupt.
391 * This function merely adds a new work task into ioc->firmware_event_thread.
392 * The tasks are worked from _firmware_event_work in user context.
394 * Return 1 meaning mf should be freed from _base_interrupt
395 * 0 means the mf is freed from this function.
398 mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
401 Mpi2EventNotificationReply_t
*mpi_reply
;
403 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
404 mpt3sas_ctl_add_to_event_log(ioc
, mpi_reply
);
409 * _ctl_verify_adapter - validates ioc_number passed from application
410 * @ioc: per adapter object
411 * @iocpp: The ioc pointer is returned in this.
412 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
413 * MPI25_VERSION for mpt3ctl ioctl device.
415 * Return (-1) means error, else ioc_number.
418 _ctl_verify_adapter(int ioc_number
, struct MPT3SAS_ADAPTER
**iocpp
,
421 struct MPT3SAS_ADAPTER
*ioc
;
422 /* global ioc lock to protect controller on list operations */
423 spin_lock(&gioc_lock
);
424 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
) {
425 if (ioc
->id
!= ioc_number
)
427 /* Check whether this ioctl command is from right
428 * ioctl device or not, if not continue the search.
430 if (ioc
->hba_mpi_version_belonged
!= mpi_version
)
432 spin_unlock(&gioc_lock
);
436 spin_unlock(&gioc_lock
);
442 * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
443 * @ioc: per adapter object
444 * @reset_phase: phase
446 * The handler for doing any required cleanup or initialization.
448 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
449 * MPT3_IOC_DONE_RESET
452 mpt3sas_ctl_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
457 switch (reset_phase
) {
458 case MPT3_IOC_PRE_RESET
:
459 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
460 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
461 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
462 if (!(ioc
->diag_buffer_status
[i
] &
463 MPT3_DIAG_BUFFER_IS_REGISTERED
))
465 if ((ioc
->diag_buffer_status
[i
] &
466 MPT3_DIAG_BUFFER_IS_RELEASED
))
468 mpt3sas_send_diag_release(ioc
, i
, &issue_reset
);
471 case MPT3_IOC_AFTER_RESET
:
472 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
473 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
474 if (ioc
->ctl_cmds
.status
& MPT3_CMD_PENDING
) {
475 ioc
->ctl_cmds
.status
|= MPT3_CMD_RESET
;
476 mpt3sas_base_free_smid(ioc
, ioc
->ctl_cmds
.smid
);
477 complete(&ioc
->ctl_cmds
.done
);
480 case MPT3_IOC_DONE_RESET
:
481 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
482 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
484 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
485 if (!(ioc
->diag_buffer_status
[i
] &
486 MPT3_DIAG_BUFFER_IS_REGISTERED
))
488 if ((ioc
->diag_buffer_status
[i
] &
489 MPT3_DIAG_BUFFER_IS_RELEASED
))
491 ioc
->diag_buffer_status
[i
] |=
492 MPT3_DIAG_BUFFER_IS_DIAG_RESET
;
504 * Called when application request fasyn callback handler.
507 _ctl_fasync(int fd
, struct file
*filep
, int mode
)
509 return fasync_helper(fd
, filep
, mode
, &async_queue
);
519 _ctl_poll(struct file
*filep
, poll_table
*wait
)
521 struct MPT3SAS_ADAPTER
*ioc
;
523 poll_wait(filep
, &ctl_poll_wait
, wait
);
525 /* global ioc lock to protect controller on list operations */
526 spin_lock(&gioc_lock
);
527 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
) {
528 if (ioc
->aen_event_read_flag
) {
529 spin_unlock(&gioc_lock
);
530 return POLLIN
| POLLRDNORM
;
533 spin_unlock(&gioc_lock
);
538 * _ctl_set_task_mid - assign an active smid to tm request
539 * @ioc: per adapter object
540 * @karg - (struct mpt3_ioctl_command)
541 * @tm_request - pointer to mf from user space
543 * Returns 0 when an smid if found, else fail.
544 * during failure, the reply frame is filled.
547 _ctl_set_task_mid(struct MPT3SAS_ADAPTER
*ioc
, struct mpt3_ioctl_command
*karg
,
548 Mpi2SCSITaskManagementRequest_t
*tm_request
)
553 struct scsi_cmnd
*scmd
;
554 struct MPT3SAS_DEVICE
*priv_data
;
556 Mpi2SCSITaskManagementReply_t
*tm_reply
;
561 if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
563 else if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
)
568 lun
= scsilun_to_int((struct scsi_lun
*)tm_request
->LUN
);
570 handle
= le16_to_cpu(tm_request
->DevHandle
);
571 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
572 for (i
= ioc
->scsiio_depth
; i
&& !found
; i
--) {
573 scmd
= ioc
->scsi_lookup
[i
- 1].scmd
;
574 if (scmd
== NULL
|| scmd
->device
== NULL
||
575 scmd
->device
->hostdata
== NULL
)
577 if (lun
!= scmd
->device
->lun
)
579 priv_data
= scmd
->device
->hostdata
;
580 if (priv_data
->sas_target
== NULL
)
582 if (priv_data
->sas_target
->handle
!= handle
)
584 tm_request
->TaskMID
= cpu_to_le16(ioc
->scsi_lookup
[i
- 1].smid
);
587 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
590 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
591 "%s: handle(0x%04x), lun(%d), no active mid!!\n",
593 desc
, le16_to_cpu(tm_request
->DevHandle
), lun
));
594 tm_reply
= ioc
->ctl_cmds
.reply
;
595 tm_reply
->DevHandle
= tm_request
->DevHandle
;
596 tm_reply
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
597 tm_reply
->TaskType
= tm_request
->TaskType
;
598 tm_reply
->MsgLength
= sizeof(Mpi2SCSITaskManagementReply_t
)/4;
599 tm_reply
->VP_ID
= tm_request
->VP_ID
;
600 tm_reply
->VF_ID
= tm_request
->VF_ID
;
601 sz
= min_t(u32
, karg
->max_reply_bytes
, ioc
->reply_sz
);
602 if (copy_to_user(karg
->reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
604 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
609 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
610 "%s: handle(0x%04x), lun(%d), task_mid(%d)\n", ioc
->name
,
611 desc
, le16_to_cpu(tm_request
->DevHandle
), lun
,
612 le16_to_cpu(tm_request
->TaskMID
)));
617 * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode
618 * @ioc: per adapter object
619 * @karg - (struct mpt3_ioctl_command)
620 * @mf - pointer to mf in user space
623 _ctl_do_mpt_command(struct MPT3SAS_ADAPTER
*ioc
, struct mpt3_ioctl_command karg
,
626 MPI2RequestHeader_t
*mpi_request
= NULL
, *request
;
627 MPI2DefaultReply_t
*mpi_reply
;
631 unsigned long timeout
, timeleft
;
635 void *data_out
= NULL
;
636 dma_addr_t data_out_dma
= 0;
637 size_t data_out_sz
= 0;
638 void *data_in
= NULL
;
639 dma_addr_t data_in_dma
= 0;
640 size_t data_in_sz
= 0;
642 u16 wait_state_count
;
646 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
647 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
648 ioc
->name
, __func__
);
653 wait_state_count
= 0;
654 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
655 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
656 if (wait_state_count
++ == 10) {
658 "%s: failed due to ioc not operational\n",
659 ioc
->name
, __func__
);
664 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
666 "%s: waiting for operational state(count=%d)\n",
668 __func__
, wait_state_count
);
670 if (wait_state_count
)
671 pr_info(MPT3SAS_FMT
"%s: ioc is operational\n",
672 ioc
->name
, __func__
);
674 mpi_request
= kzalloc(ioc
->request_sz
, GFP_KERNEL
);
677 "%s: failed obtaining a memory for mpi_request\n",
678 ioc
->name
, __func__
);
683 /* Check for overflow and wraparound */
684 if (karg
.data_sge_offset
* 4 > ioc
->request_sz
||
685 karg
.data_sge_offset
> (UINT_MAX
/ 4)) {
690 /* copy in request message frame from user */
691 if (copy_from_user(mpi_request
, mf
, karg
.data_sge_offset
*4)) {
692 pr_err("failure at %s:%d/%s()!\n", __FILE__
, __LINE__
,
698 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
699 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->ctl_cb_idx
);
701 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
702 ioc
->name
, __func__
);
708 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->ctl_cb_idx
, NULL
);
710 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
711 ioc
->name
, __func__
);
718 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
719 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
720 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
721 memcpy(request
, mpi_request
, karg
.data_sge_offset
*4);
722 ioc
->ctl_cmds
.smid
= smid
;
723 data_out_sz
= karg
.data_out_size
;
724 data_in_sz
= karg
.data_in_size
;
726 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
727 mpi_request
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
728 if (!le16_to_cpu(mpi_request
->FunctionDependent1
) ||
729 le16_to_cpu(mpi_request
->FunctionDependent1
) >
730 ioc
->facts
.MaxDevHandle
) {
732 mpt3sas_base_free_smid(ioc
, smid
);
737 /* obtain dma-able memory for data transfer */
738 if (data_out_sz
) /* WRITE */ {
739 data_out
= pci_alloc_consistent(ioc
->pdev
, data_out_sz
,
742 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
745 mpt3sas_base_free_smid(ioc
, smid
);
748 if (copy_from_user(data_out
, karg
.data_out_buf_ptr
,
750 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
753 mpt3sas_base_free_smid(ioc
, smid
);
758 if (data_in_sz
) /* READ */ {
759 data_in
= pci_alloc_consistent(ioc
->pdev
, data_in_sz
,
762 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
765 mpt3sas_base_free_smid(ioc
, smid
);
770 psge
= (void *)request
+ (karg
.data_sge_offset
*4);
772 /* send command to firmware */
773 _ctl_display_some_debug(ioc
, smid
, "ctl_request", NULL
);
775 init_completion(&ioc
->ctl_cmds
.done
);
776 switch (mpi_request
->Function
) {
777 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
778 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
780 Mpi2SCSIIORequest_t
*scsiio_request
=
781 (Mpi2SCSIIORequest_t
*)request
;
782 scsiio_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
783 scsiio_request
->SenseBufferLowAddress
=
784 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
785 memset(ioc
->ctl_cmds
.sense
, 0, SCSI_SENSE_BUFFERSIZE
);
786 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
,
787 data_in_dma
, data_in_sz
);
789 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)
790 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
791 le16_to_cpu(mpi_request
->FunctionDependent1
));
793 mpt3sas_base_put_smid_default(ioc
, smid
);
796 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
798 Mpi2SCSITaskManagementRequest_t
*tm_request
=
799 (Mpi2SCSITaskManagementRequest_t
*)request
;
801 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
802 "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
804 le16_to_cpu(tm_request
->DevHandle
), tm_request
->TaskType
));
806 if (tm_request
->TaskType
==
807 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
||
808 tm_request
->TaskType
==
809 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
) {
810 if (_ctl_set_task_mid(ioc
, &karg
, tm_request
)) {
811 mpt3sas_base_free_smid(ioc
, smid
);
816 mpt3sas_scsih_set_tm_flag(ioc
, le16_to_cpu(
817 tm_request
->DevHandle
));
818 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
819 data_in_dma
, data_in_sz
);
820 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
823 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
825 Mpi2SmpPassthroughRequest_t
*smp_request
=
826 (Mpi2SmpPassthroughRequest_t
*)mpi_request
;
829 /* ioc determines which port to use */
830 smp_request
->PhysicalPort
= 0xFF;
831 if (smp_request
->PassthroughFlags
&
832 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE
)
833 data
= (u8
*)&smp_request
->SGL
;
835 if (unlikely(data_out
== NULL
)) {
836 pr_err("failure at %s:%d/%s()!\n",
837 __FILE__
, __LINE__
, __func__
);
838 mpt3sas_base_free_smid(ioc
, smid
);
845 if (data
[1] == 0x91 && (data
[10] == 1 || data
[10] == 2)) {
846 ioc
->ioc_link_reset_in_progress
= 1;
847 ioc
->ignore_loginfos
= 1;
849 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
, data_in_dma
,
851 mpt3sas_base_put_smid_default(ioc
, smid
);
854 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
855 case MPI2_FUNCTION_FW_DOWNLOAD
:
856 case MPI2_FUNCTION_FW_UPLOAD
:
858 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
, data_in_dma
,
860 mpt3sas_base_put_smid_default(ioc
, smid
);
863 case MPI2_FUNCTION_TOOLBOX
:
865 Mpi2ToolboxCleanRequest_t
*toolbox_request
=
866 (Mpi2ToolboxCleanRequest_t
*)mpi_request
;
868 if (toolbox_request
->Tool
== MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL
) {
869 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
,
870 data_in_dma
, data_in_sz
);
872 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
873 data_in_dma
, data_in_sz
);
875 mpt3sas_base_put_smid_default(ioc
, smid
);
878 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
880 Mpi2SasIoUnitControlRequest_t
*sasiounit_request
=
881 (Mpi2SasIoUnitControlRequest_t
*)mpi_request
;
883 if (sasiounit_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
884 || sasiounit_request
->Operation
==
885 MPI2_SAS_OP_PHY_LINK_RESET
) {
886 ioc
->ioc_link_reset_in_progress
= 1;
887 ioc
->ignore_loginfos
= 1;
889 /* drop to default case for posting the request */
892 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
893 data_in_dma
, data_in_sz
);
894 mpt3sas_base_put_smid_default(ioc
, smid
);
898 if (karg
.timeout
< MPT3_IOCTL_DEFAULT_TIMEOUT
)
899 timeout
= MPT3_IOCTL_DEFAULT_TIMEOUT
;
901 timeout
= karg
.timeout
;
902 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
904 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
905 Mpi2SCSITaskManagementRequest_t
*tm_request
=
906 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
907 mpt3sas_scsih_clear_tm_flag(ioc
, le16_to_cpu(
908 tm_request
->DevHandle
));
909 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
910 } else if ((mpi_request
->Function
== MPI2_FUNCTION_SMP_PASSTHROUGH
||
911 mpi_request
->Function
== MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
) &&
912 ioc
->ioc_link_reset_in_progress
) {
913 ioc
->ioc_link_reset_in_progress
= 0;
914 ioc
->ignore_loginfos
= 0;
916 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
917 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
919 _debug_dump_mf(mpi_request
, karg
.data_sge_offset
);
920 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
922 goto issue_host_reset
;
925 mpi_reply
= ioc
->ctl_cmds
.reply
;
926 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
928 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
&&
929 (ioc
->logging_level
& MPT_DEBUG_TM
)) {
930 Mpi2SCSITaskManagementReply_t
*tm_reply
=
931 (Mpi2SCSITaskManagementReply_t
*)mpi_reply
;
933 pr_info(MPT3SAS_FMT
"TASK_MGMT: " \
934 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
935 "TerminationCount(0x%08x)\n", ioc
->name
,
936 le16_to_cpu(tm_reply
->IOCStatus
),
937 le32_to_cpu(tm_reply
->IOCLogInfo
),
938 le32_to_cpu(tm_reply
->TerminationCount
));
941 /* copy out xdata to user */
943 if (copy_to_user(karg
.data_in_buf_ptr
, data_in
,
945 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
952 /* copy out reply message frame to user */
953 if (karg
.max_reply_bytes
) {
954 sz
= min_t(u32
, karg
.max_reply_bytes
, ioc
->reply_sz
);
955 if (copy_to_user(karg
.reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
957 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
964 /* copy out sense to user */
965 if (karg
.max_sense_bytes
&& (mpi_request
->Function
==
966 MPI2_FUNCTION_SCSI_IO_REQUEST
|| mpi_request
->Function
==
967 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
968 sz
= min_t(u32
, karg
.max_sense_bytes
, SCSI_SENSE_BUFFERSIZE
);
969 if (copy_to_user(karg
.sense_data_ptr
, ioc
->ctl_cmds
.sense
,
971 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
981 if ((mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
982 mpi_request
->Function
==
983 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
984 mpi_request
->Function
== MPI2_FUNCTION_SATA_PASSTHROUGH
)) {
985 pr_info(MPT3SAS_FMT
"issue target reset: handle = (0x%04x)\n",
987 le16_to_cpu(mpi_request
->FunctionDependent1
));
988 mpt3sas_halt_firmware(ioc
);
989 mpt3sas_scsih_issue_tm(ioc
,
990 le16_to_cpu(mpi_request
->FunctionDependent1
), 0, 0,
991 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30,
994 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1000 /* free memory associated with sg buffers */
1002 pci_free_consistent(ioc
->pdev
, data_in_sz
, data_in
,
1006 pci_free_consistent(ioc
->pdev
, data_out_sz
, data_out
,
1010 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1015 * _ctl_getiocinfo - main handler for MPT3IOCINFO opcode
1016 * @ioc: per adapter object
1017 * @arg - user space buffer containing ioctl content
1020 _ctl_getiocinfo(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1022 struct mpt3_ioctl_iocinfo karg
;
1024 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1025 pr_err("failure at %s:%d/%s()!\n",
1026 __FILE__
, __LINE__
, __func__
);
1030 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1033 memset(&karg
, 0 , sizeof(karg
));
1035 karg
.port_number
= ioc
->pfacts
[0].PortNumber
;
1036 karg
.hw_rev
= ioc
->pdev
->revision
;
1037 karg
.pci_id
= ioc
->pdev
->device
;
1038 karg
.subsystem_device
= ioc
->pdev
->subsystem_device
;
1039 karg
.subsystem_vendor
= ioc
->pdev
->subsystem_vendor
;
1040 karg
.pci_information
.u
.bits
.bus
= ioc
->pdev
->bus
->number
;
1041 karg
.pci_information
.u
.bits
.device
= PCI_SLOT(ioc
->pdev
->devfn
);
1042 karg
.pci_information
.u
.bits
.function
= PCI_FUNC(ioc
->pdev
->devfn
);
1043 karg
.pci_information
.segment_id
= pci_domain_nr(ioc
->pdev
->bus
);
1044 karg
.firmware_version
= ioc
->facts
.FWVersion
.Word
;
1045 strcpy(karg
.driver_version
, ioc
->driver_name
);
1046 strcat(karg
.driver_version
, "-");
1047 switch (ioc
->hba_mpi_version_belonged
) {
1049 if (ioc
->is_warpdrive
)
1050 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2_SSS6200
;
1052 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2
;
1053 strcat(karg
.driver_version
, MPT2SAS_DRIVER_VERSION
);
1056 karg
.adapter_type
= MPT3_IOCTL_INTERFACE_SAS3
;
1057 strcat(karg
.driver_version
, MPT3SAS_DRIVER_VERSION
);
1060 karg
.bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
1062 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1063 pr_err("failure at %s:%d/%s()!\n",
1064 __FILE__
, __LINE__
, __func__
);
1071 * _ctl_eventquery - main handler for MPT3EVENTQUERY opcode
1072 * @ioc: per adapter object
1073 * @arg - user space buffer containing ioctl content
1076 _ctl_eventquery(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1078 struct mpt3_ioctl_eventquery karg
;
1080 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1081 pr_err("failure at %s:%d/%s()!\n",
1082 __FILE__
, __LINE__
, __func__
);
1086 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1089 karg
.event_entries
= MPT3SAS_CTL_EVENT_LOG_SIZE
;
1090 memcpy(karg
.event_types
, ioc
->event_type
,
1091 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1093 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1094 pr_err("failure at %s:%d/%s()!\n",
1095 __FILE__
, __LINE__
, __func__
);
1102 * _ctl_eventenable - main handler for MPT3EVENTENABLE opcode
1103 * @ioc: per adapter object
1104 * @arg - user space buffer containing ioctl content
1107 _ctl_eventenable(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1109 struct mpt3_ioctl_eventenable karg
;
1111 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1112 pr_err("failure at %s:%d/%s()!\n",
1113 __FILE__
, __LINE__
, __func__
);
1117 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1120 memcpy(ioc
->event_type
, karg
.event_types
,
1121 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1122 mpt3sas_base_validate_event_type(ioc
, ioc
->event_type
);
1126 /* initialize event_log */
1127 ioc
->event_context
= 0;
1128 ioc
->aen_event_read_flag
= 0;
1129 ioc
->event_log
= kcalloc(MPT3SAS_CTL_EVENT_LOG_SIZE
,
1130 sizeof(struct MPT3_IOCTL_EVENTS
), GFP_KERNEL
);
1131 if (!ioc
->event_log
) {
1132 pr_err("failure at %s:%d/%s()!\n",
1133 __FILE__
, __LINE__
, __func__
);
1140 * _ctl_eventreport - main handler for MPT3EVENTREPORT opcode
1141 * @ioc: per adapter object
1142 * @arg - user space buffer containing ioctl content
1145 _ctl_eventreport(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1147 struct mpt3_ioctl_eventreport karg
;
1148 u32 number_bytes
, max_events
, max
;
1149 struct mpt3_ioctl_eventreport __user
*uarg
= arg
;
1151 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1152 pr_err("failure at %s:%d/%s()!\n",
1153 __FILE__
, __LINE__
, __func__
);
1157 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1160 number_bytes
= karg
.hdr
.max_data_size
-
1161 sizeof(struct mpt3_ioctl_header
);
1162 max_events
= number_bytes
/sizeof(struct MPT3_IOCTL_EVENTS
);
1163 max
= min_t(u32
, MPT3SAS_CTL_EVENT_LOG_SIZE
, max_events
);
1165 /* If fewer than 1 event is requested, there must have
1166 * been some type of error.
1168 if (!max
|| !ioc
->event_log
)
1171 number_bytes
= max
* sizeof(struct MPT3_IOCTL_EVENTS
);
1172 if (copy_to_user(uarg
->event_data
, ioc
->event_log
, number_bytes
)) {
1173 pr_err("failure at %s:%d/%s()!\n",
1174 __FILE__
, __LINE__
, __func__
);
1178 /* reset flag so SIGIO can restart */
1179 ioc
->aen_event_read_flag
= 0;
1184 * _ctl_do_reset - main handler for MPT3HARDRESET opcode
1185 * @ioc: per adapter object
1186 * @arg - user space buffer containing ioctl content
1189 _ctl_do_reset(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1191 struct mpt3_ioctl_diag_reset karg
;
1194 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1195 pr_err("failure at %s:%d/%s()!\n",
1196 __FILE__
, __LINE__
, __func__
);
1200 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
1201 ioc
->is_driver_loading
)
1204 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1207 retval
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1209 pr_info(MPT3SAS_FMT
"host reset: %s\n",
1210 ioc
->name
, ((!retval
) ? "SUCCESS" : "FAILED"));
1215 * _ctl_btdh_search_sas_device - searching for sas device
1216 * @ioc: per adapter object
1217 * @btdh: btdh ioctl payload
1220 _ctl_btdh_search_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
1221 struct mpt3_ioctl_btdh_mapping
*btdh
)
1223 struct _sas_device
*sas_device
;
1224 unsigned long flags
;
1227 if (list_empty(&ioc
->sas_device_list
))
1230 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1231 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
1232 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1233 btdh
->handle
== sas_device
->handle
) {
1234 btdh
->bus
= sas_device
->channel
;
1235 btdh
->id
= sas_device
->id
;
1238 } else if (btdh
->bus
== sas_device
->channel
&& btdh
->id
==
1239 sas_device
->id
&& btdh
->handle
== 0xFFFF) {
1240 btdh
->handle
= sas_device
->handle
;
1246 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1251 * _ctl_btdh_search_raid_device - searching for raid device
1252 * @ioc: per adapter object
1253 * @btdh: btdh ioctl payload
1256 _ctl_btdh_search_raid_device(struct MPT3SAS_ADAPTER
*ioc
,
1257 struct mpt3_ioctl_btdh_mapping
*btdh
)
1259 struct _raid_device
*raid_device
;
1260 unsigned long flags
;
1263 if (list_empty(&ioc
->raid_device_list
))
1266 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1267 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1268 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1269 btdh
->handle
== raid_device
->handle
) {
1270 btdh
->bus
= raid_device
->channel
;
1271 btdh
->id
= raid_device
->id
;
1274 } else if (btdh
->bus
== raid_device
->channel
&& btdh
->id
==
1275 raid_device
->id
&& btdh
->handle
== 0xFFFF) {
1276 btdh
->handle
= raid_device
->handle
;
1282 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1287 * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode
1288 * @ioc: per adapter object
1289 * @arg - user space buffer containing ioctl content
1292 _ctl_btdh_mapping(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1294 struct mpt3_ioctl_btdh_mapping karg
;
1297 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1298 pr_err("failure at %s:%d/%s()!\n",
1299 __FILE__
, __LINE__
, __func__
);
1303 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1306 rc
= _ctl_btdh_search_sas_device(ioc
, &karg
);
1308 _ctl_btdh_search_raid_device(ioc
, &karg
);
1310 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1311 pr_err("failure at %s:%d/%s()!\n",
1312 __FILE__
, __LINE__
, __func__
);
1319 * _ctl_diag_capability - return diag buffer capability
1320 * @ioc: per adapter object
1321 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1323 * returns 1 when diag buffer support is enabled in firmware
1326 _ctl_diag_capability(struct MPT3SAS_ADAPTER
*ioc
, u8 buffer_type
)
1330 switch (buffer_type
) {
1331 case MPI2_DIAG_BUF_TYPE_TRACE
:
1332 if (ioc
->facts
.IOCCapabilities
&
1333 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
)
1336 case MPI2_DIAG_BUF_TYPE_SNAPSHOT
:
1337 if (ioc
->facts
.IOCCapabilities
&
1338 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
)
1341 case MPI2_DIAG_BUF_TYPE_EXTENDED
:
1342 if (ioc
->facts
.IOCCapabilities
&
1343 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
)
1352 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1353 * @ioc: per adapter object
1354 * @diag_register: the diag_register struct passed in from user space
1358 _ctl_diag_register_2(struct MPT3SAS_ADAPTER
*ioc
,
1359 struct mpt3_diag_register
*diag_register
)
1362 void *request_data
= NULL
;
1363 dma_addr_t request_data_dma
;
1364 u32 request_data_sz
= 0;
1365 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1366 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1368 unsigned long timeleft
;
1374 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1377 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1378 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1380 "%s: failed due to ioc not operational\n",
1381 ioc
->name
, __func__
);
1386 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1387 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
1388 ioc
->name
, __func__
);
1393 buffer_type
= diag_register
->buffer_type
;
1394 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1396 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1397 ioc
->name
, __func__
, buffer_type
);
1401 if (ioc
->diag_buffer_status
[buffer_type
] &
1402 MPT3_DIAG_BUFFER_IS_REGISTERED
) {
1404 "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1405 ioc
->name
, __func__
,
1410 if (diag_register
->requested_buffer_size
% 4) {
1412 "%s: the requested_buffer_size is not 4 byte aligned\n",
1413 ioc
->name
, __func__
);
1417 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1419 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
1420 ioc
->name
, __func__
);
1426 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
1427 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1428 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1429 ioc
->ctl_cmds
.smid
= smid
;
1431 request_data
= ioc
->diag_buffer
[buffer_type
];
1432 request_data_sz
= diag_register
->requested_buffer_size
;
1433 ioc
->unique_id
[buffer_type
] = diag_register
->unique_id
;
1434 ioc
->diag_buffer_status
[buffer_type
] = 0;
1435 memcpy(ioc
->product_specific
[buffer_type
],
1436 diag_register
->product_specific
, MPT3_PRODUCT_SPECIFIC_DWORDS
);
1437 ioc
->diagnostic_flags
[buffer_type
] = diag_register
->diagnostic_flags
;
1440 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1441 if (request_data_sz
!= ioc
->diag_buffer_sz
[buffer_type
]) {
1442 pci_free_consistent(ioc
->pdev
,
1443 ioc
->diag_buffer_sz
[buffer_type
],
1444 request_data
, request_data_dma
);
1445 request_data
= NULL
;
1449 if (request_data
== NULL
) {
1450 ioc
->diag_buffer_sz
[buffer_type
] = 0;
1451 ioc
->diag_buffer_dma
[buffer_type
] = 0;
1452 request_data
= pci_alloc_consistent(
1453 ioc
->pdev
, request_data_sz
, &request_data_dma
);
1454 if (request_data
== NULL
) {
1455 pr_err(MPT3SAS_FMT
"%s: failed allocating memory" \
1456 " for diag buffers, requested size(%d)\n",
1457 ioc
->name
, __func__
, request_data_sz
);
1458 mpt3sas_base_free_smid(ioc
, smid
);
1461 ioc
->diag_buffer
[buffer_type
] = request_data
;
1462 ioc
->diag_buffer_sz
[buffer_type
] = request_data_sz
;
1463 ioc
->diag_buffer_dma
[buffer_type
] = request_data_dma
;
1466 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1467 mpi_request
->BufferType
= diag_register
->buffer_type
;
1468 mpi_request
->Flags
= cpu_to_le32(diag_register
->diagnostic_flags
);
1469 mpi_request
->BufferAddress
= cpu_to_le64(request_data_dma
);
1470 mpi_request
->BufferLength
= cpu_to_le32(request_data_sz
);
1471 mpi_request
->VF_ID
= 0; /* TODO */
1472 mpi_request
->VP_ID
= 0;
1474 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
1475 "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1476 ioc
->name
, __func__
, request_data
,
1477 (unsigned long long)request_data_dma
,
1478 le32_to_cpu(mpi_request
->BufferLength
)));
1480 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
1481 mpi_request
->ProductSpecific
[i
] =
1482 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1484 init_completion(&ioc
->ctl_cmds
.done
);
1485 mpt3sas_base_put_smid_default(ioc
, smid
);
1486 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1487 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1489 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1490 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
1492 _debug_dump_mf(mpi_request
,
1493 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
1494 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
1496 goto issue_host_reset
;
1499 /* process the completed Reply Message Frame */
1500 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
1501 pr_err(MPT3SAS_FMT
"%s: no reply message\n",
1502 ioc
->name
, __func__
);
1507 mpi_reply
= ioc
->ctl_cmds
.reply
;
1508 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1510 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1511 ioc
->diag_buffer_status
[buffer_type
] |=
1512 MPT3_DIAG_BUFFER_IS_REGISTERED
;
1513 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: success\n",
1514 ioc
->name
, __func__
));
1517 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1518 ioc
->name
, __func__
,
1519 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
1525 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1530 if (rc
&& request_data
)
1531 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1532 request_data
, request_data_dma
);
1534 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1539 * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time
1540 * @ioc: per adapter object
1541 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1543 * This is called when command line option diag_buffer_enable is enabled
1544 * at driver load time.
1547 mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER
*ioc
, u8 bits_to_register
)
1549 struct mpt3_diag_register diag_register
;
1551 memset(&diag_register
, 0, sizeof(struct mpt3_diag_register
));
1553 if (bits_to_register
& 1) {
1554 pr_info(MPT3SAS_FMT
"registering trace buffer support\n",
1556 ioc
->diag_trigger_master
.MasterData
=
1557 (MASTER_TRIGGER_FW_FAULT
+ MASTER_TRIGGER_ADAPTER_RESET
);
1558 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
1559 /* register for 2MB buffers */
1560 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1561 diag_register
.unique_id
= 0x7075900;
1562 _ctl_diag_register_2(ioc
, &diag_register
);
1565 if (bits_to_register
& 2) {
1566 pr_info(MPT3SAS_FMT
"registering snapshot buffer support\n",
1568 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_SNAPSHOT
;
1569 /* register for 2MB buffers */
1570 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1571 diag_register
.unique_id
= 0x7075901;
1572 _ctl_diag_register_2(ioc
, &diag_register
);
1575 if (bits_to_register
& 4) {
1576 pr_info(MPT3SAS_FMT
"registering extended buffer support\n",
1578 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_EXTENDED
;
1579 /* register for 2MB buffers */
1580 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1581 diag_register
.unique_id
= 0x7075901;
1582 _ctl_diag_register_2(ioc
, &diag_register
);
1587 * _ctl_diag_register - application register with driver
1588 * @ioc: per adapter object
1589 * @arg - user space buffer containing ioctl content
1591 * This will allow the driver to setup any required buffers that will be
1592 * needed by firmware to communicate with the driver.
1595 _ctl_diag_register(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1597 struct mpt3_diag_register karg
;
1600 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1601 pr_err("failure at %s:%d/%s()!\n",
1602 __FILE__
, __LINE__
, __func__
);
1606 rc
= _ctl_diag_register_2(ioc
, &karg
);
1611 * _ctl_diag_unregister - application unregister with driver
1612 * @ioc: per adapter object
1613 * @arg - user space buffer containing ioctl content
1615 * This will allow the driver to cleanup any memory allocated for diag
1616 * messages and to free up any resources.
1619 _ctl_diag_unregister(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1621 struct mpt3_diag_unregister karg
;
1623 dma_addr_t request_data_dma
;
1624 u32 request_data_sz
;
1627 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1628 pr_err("failure at %s:%d/%s()!\n",
1629 __FILE__
, __LINE__
, __func__
);
1633 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1636 buffer_type
= karg
.unique_id
& 0x000000ff;
1637 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1639 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1640 ioc
->name
, __func__
, buffer_type
);
1644 if ((ioc
->diag_buffer_status
[buffer_type
] &
1645 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1647 "%s: buffer_type(0x%02x) is not registered\n",
1648 ioc
->name
, __func__
, buffer_type
);
1651 if ((ioc
->diag_buffer_status
[buffer_type
] &
1652 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0) {
1654 "%s: buffer_type(0x%02x) has not been released\n",
1655 ioc
->name
, __func__
, buffer_type
);
1659 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1661 "%s: unique_id(0x%08x) is not registered\n",
1662 ioc
->name
, __func__
, karg
.unique_id
);
1666 request_data
= ioc
->diag_buffer
[buffer_type
];
1667 if (!request_data
) {
1669 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1670 ioc
->name
, __func__
, buffer_type
);
1674 request_data_sz
= ioc
->diag_buffer_sz
[buffer_type
];
1675 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1676 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1677 request_data
, request_data_dma
);
1678 ioc
->diag_buffer
[buffer_type
] = NULL
;
1679 ioc
->diag_buffer_status
[buffer_type
] = 0;
1684 * _ctl_diag_query - query relevant info associated with diag buffers
1685 * @ioc: per adapter object
1686 * @arg - user space buffer containing ioctl content
1688 * The application will send only buffer_type and unique_id. Driver will
1689 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1690 * 0x00, the driver will return info specified by Buffer Type.
1693 _ctl_diag_query(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1695 struct mpt3_diag_query karg
;
1700 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1701 pr_err("failure at %s:%d/%s()!\n",
1702 __FILE__
, __LINE__
, __func__
);
1706 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1709 karg
.application_flags
= 0;
1710 buffer_type
= karg
.buffer_type
;
1712 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1714 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1715 ioc
->name
, __func__
, buffer_type
);
1719 if ((ioc
->diag_buffer_status
[buffer_type
] &
1720 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1722 "%s: buffer_type(0x%02x) is not registered\n",
1723 ioc
->name
, __func__
, buffer_type
);
1727 if (karg
.unique_id
& 0xffffff00) {
1728 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1730 "%s: unique_id(0x%08x) is not registered\n",
1731 ioc
->name
, __func__
, karg
.unique_id
);
1736 request_data
= ioc
->diag_buffer
[buffer_type
];
1737 if (!request_data
) {
1739 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
1740 ioc
->name
, __func__
, buffer_type
);
1744 if (ioc
->diag_buffer_status
[buffer_type
] & MPT3_DIAG_BUFFER_IS_RELEASED
)
1745 karg
.application_flags
= (MPT3_APP_FLAGS_APP_OWNED
|
1746 MPT3_APP_FLAGS_BUFFER_VALID
);
1748 karg
.application_flags
= (MPT3_APP_FLAGS_APP_OWNED
|
1749 MPT3_APP_FLAGS_BUFFER_VALID
|
1750 MPT3_APP_FLAGS_FW_BUFFER_ACCESS
);
1752 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
1753 karg
.product_specific
[i
] =
1754 ioc
->product_specific
[buffer_type
][i
];
1756 karg
.total_buffer_size
= ioc
->diag_buffer_sz
[buffer_type
];
1757 karg
.driver_added_buffer_size
= 0;
1758 karg
.unique_id
= ioc
->unique_id
[buffer_type
];
1759 karg
.diagnostic_flags
= ioc
->diagnostic_flags
[buffer_type
];
1761 if (copy_to_user(arg
, &karg
, sizeof(struct mpt3_diag_query
))) {
1763 "%s: unable to write mpt3_diag_query data @ %p\n",
1764 ioc
->name
, __func__
, arg
);
1771 * mpt3sas_send_diag_release - Diag Release Message
1772 * @ioc: per adapter object
1773 * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
1774 * @issue_reset - specifies whether host reset is required.
1778 mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER
*ioc
, u8 buffer_type
,
1781 Mpi2DiagReleaseRequest_t
*mpi_request
;
1782 Mpi2DiagReleaseReply_t
*mpi_reply
;
1787 unsigned long timeleft
;
1789 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1795 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1796 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1797 if (ioc
->diag_buffer_status
[buffer_type
] &
1798 MPT3_DIAG_BUFFER_IS_REGISTERED
)
1799 ioc
->diag_buffer_status
[buffer_type
] |=
1800 MPT3_DIAG_BUFFER_IS_RELEASED
;
1801 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
1802 "%s: skipping due to FAULT state\n", ioc
->name
,
1808 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1809 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
1810 ioc
->name
, __func__
);
1815 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1817 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
1818 ioc
->name
, __func__
);
1823 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
1824 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1825 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1826 ioc
->ctl_cmds
.smid
= smid
;
1828 mpi_request
->Function
= MPI2_FUNCTION_DIAG_RELEASE
;
1829 mpi_request
->BufferType
= buffer_type
;
1830 mpi_request
->VF_ID
= 0; /* TODO */
1831 mpi_request
->VP_ID
= 0;
1833 init_completion(&ioc
->ctl_cmds
.done
);
1834 mpt3sas_base_put_smid_default(ioc
, smid
);
1835 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1836 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1838 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1839 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
1841 _debug_dump_mf(mpi_request
,
1842 sizeof(Mpi2DiagReleaseRequest_t
)/4);
1843 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
1849 /* process the completed Reply Message Frame */
1850 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
1851 pr_err(MPT3SAS_FMT
"%s: no reply message\n",
1852 ioc
->name
, __func__
);
1857 mpi_reply
= ioc
->ctl_cmds
.reply
;
1858 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1860 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1861 ioc
->diag_buffer_status
[buffer_type
] |=
1862 MPT3_DIAG_BUFFER_IS_RELEASED
;
1863 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: success\n",
1864 ioc
->name
, __func__
));
1867 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1868 ioc
->name
, __func__
,
1869 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
1874 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1879 * _ctl_diag_release - request to send Diag Release Message to firmware
1880 * @arg - user space buffer containing ioctl content
1882 * This allows ownership of the specified buffer to returned to the driver,
1883 * allowing an application to read the buffer without fear that firmware is
1884 * overwritting information in the buffer.
1887 _ctl_diag_release(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1889 struct mpt3_diag_release karg
;
1895 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1896 pr_err("failure at %s:%d/%s()!\n",
1897 __FILE__
, __LINE__
, __func__
);
1901 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1904 buffer_type
= karg
.unique_id
& 0x000000ff;
1905 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1907 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1908 ioc
->name
, __func__
, buffer_type
);
1912 if ((ioc
->diag_buffer_status
[buffer_type
] &
1913 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1915 "%s: buffer_type(0x%02x) is not registered\n",
1916 ioc
->name
, __func__
, buffer_type
);
1920 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1922 "%s: unique_id(0x%08x) is not registered\n",
1923 ioc
->name
, __func__
, karg
.unique_id
);
1927 if (ioc
->diag_buffer_status
[buffer_type
] &
1928 MPT3_DIAG_BUFFER_IS_RELEASED
) {
1930 "%s: buffer_type(0x%02x) is already released\n",
1931 ioc
->name
, __func__
,
1936 request_data
= ioc
->diag_buffer
[buffer_type
];
1938 if (!request_data
) {
1940 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1941 ioc
->name
, __func__
, buffer_type
);
1945 /* buffers were released by due to host reset */
1946 if ((ioc
->diag_buffer_status
[buffer_type
] &
1947 MPT3_DIAG_BUFFER_IS_DIAG_RESET
)) {
1948 ioc
->diag_buffer_status
[buffer_type
] |=
1949 MPT3_DIAG_BUFFER_IS_RELEASED
;
1950 ioc
->diag_buffer_status
[buffer_type
] &=
1951 ~MPT3_DIAG_BUFFER_IS_DIAG_RESET
;
1953 "%s: buffer_type(0x%02x) was released due to host reset\n",
1954 ioc
->name
, __func__
, buffer_type
);
1958 rc
= mpt3sas_send_diag_release(ioc
, buffer_type
, &issue_reset
);
1961 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1968 * _ctl_diag_read_buffer - request for copy of the diag buffer
1969 * @ioc: per adapter object
1970 * @arg - user space buffer containing ioctl content
1973 _ctl_diag_read_buffer(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1975 struct mpt3_diag_read_buffer karg
;
1976 struct mpt3_diag_read_buffer __user
*uarg
= arg
;
1977 void *request_data
, *diag_data
;
1978 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1979 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1982 unsigned long timeleft
, request_size
, copy_size
;
1987 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1988 pr_err("failure at %s:%d/%s()!\n",
1989 __FILE__
, __LINE__
, __func__
);
1993 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1996 buffer_type
= karg
.unique_id
& 0x000000ff;
1997 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1999 "%s: doesn't have capability for buffer_type(0x%02x)\n",
2000 ioc
->name
, __func__
, buffer_type
);
2004 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
2006 "%s: unique_id(0x%08x) is not registered\n",
2007 ioc
->name
, __func__
, karg
.unique_id
);
2011 request_data
= ioc
->diag_buffer
[buffer_type
];
2012 if (!request_data
) {
2014 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2015 ioc
->name
, __func__
, buffer_type
);
2019 request_size
= ioc
->diag_buffer_sz
[buffer_type
];
2021 if ((karg
.starting_offset
% 4) || (karg
.bytes_to_read
% 4)) {
2022 pr_err(MPT3SAS_FMT
"%s: either the starting_offset " \
2023 "or bytes_to_read are not 4 byte aligned\n", ioc
->name
,
2028 if (karg
.starting_offset
> request_size
)
2031 diag_data
= (void *)(request_data
+ karg
.starting_offset
);
2032 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2033 "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2034 ioc
->name
, __func__
,
2035 diag_data
, karg
.starting_offset
, karg
.bytes_to_read
));
2037 /* Truncate data on requests that are too large */
2038 if ((diag_data
+ karg
.bytes_to_read
< diag_data
) ||
2039 (diag_data
+ karg
.bytes_to_read
> request_data
+ request_size
))
2040 copy_size
= request_size
- karg
.starting_offset
;
2042 copy_size
= karg
.bytes_to_read
;
2044 if (copy_to_user((void __user
*)uarg
->diagnostic_data
,
2045 diag_data
, copy_size
)) {
2047 "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2048 ioc
->name
, __func__
, diag_data
);
2052 if ((karg
.flags
& MPT3_FLAGS_REREGISTER
) == 0)
2055 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2056 "%s: Reregister buffer_type(0x%02x)\n",
2057 ioc
->name
, __func__
, buffer_type
));
2058 if ((ioc
->diag_buffer_status
[buffer_type
] &
2059 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0) {
2060 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2061 "%s: buffer_type(0x%02x) is still registered\n",
2062 ioc
->name
, __func__
, buffer_type
));
2065 /* Get a free request frame and save the message context.
2068 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2069 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
2070 ioc
->name
, __func__
);
2075 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
2077 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2078 ioc
->name
, __func__
);
2084 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
2085 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
2086 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2087 ioc
->ctl_cmds
.smid
= smid
;
2089 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
2090 mpi_request
->BufferType
= buffer_type
;
2091 mpi_request
->BufferLength
=
2092 cpu_to_le32(ioc
->diag_buffer_sz
[buffer_type
]);
2093 mpi_request
->BufferAddress
=
2094 cpu_to_le64(ioc
->diag_buffer_dma
[buffer_type
]);
2095 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
2096 mpi_request
->ProductSpecific
[i
] =
2097 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
2098 mpi_request
->VF_ID
= 0; /* TODO */
2099 mpi_request
->VP_ID
= 0;
2101 init_completion(&ioc
->ctl_cmds
.done
);
2102 mpt3sas_base_put_smid_default(ioc
, smid
);
2103 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
2104 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
2106 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2107 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
2109 _debug_dump_mf(mpi_request
,
2110 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
2111 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
2113 goto issue_host_reset
;
2116 /* process the completed Reply Message Frame */
2117 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
2118 pr_err(MPT3SAS_FMT
"%s: no reply message\n",
2119 ioc
->name
, __func__
);
2124 mpi_reply
= ioc
->ctl_cmds
.reply
;
2125 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2127 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
2128 ioc
->diag_buffer_status
[buffer_type
] |=
2129 MPT3_DIAG_BUFFER_IS_REGISTERED
;
2130 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: success\n",
2131 ioc
->name
, __func__
));
2134 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2135 ioc
->name
, __func__
,
2136 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
2142 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2147 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
2153 #ifdef CONFIG_COMPAT
2155 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2156 * @ioc: per adapter object
2157 * @cmd - ioctl opcode
2158 * @arg - (struct mpt3_ioctl_command32)
2160 * MPT3COMMAND32 - Handle 32bit applications running on 64bit os.
2163 _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER
*ioc
, unsigned cmd
,
2166 struct mpt3_ioctl_command32 karg32
;
2167 struct mpt3_ioctl_command32 __user
*uarg
;
2168 struct mpt3_ioctl_command karg
;
2170 if (_IOC_SIZE(cmd
) != sizeof(struct mpt3_ioctl_command32
))
2173 uarg
= (struct mpt3_ioctl_command32 __user
*) arg
;
2175 if (copy_from_user(&karg32
, (char __user
*)arg
, sizeof(karg32
))) {
2176 pr_err("failure at %s:%d/%s()!\n",
2177 __FILE__
, __LINE__
, __func__
);
2181 memset(&karg
, 0, sizeof(struct mpt3_ioctl_command
));
2182 karg
.hdr
.ioc_number
= karg32
.hdr
.ioc_number
;
2183 karg
.hdr
.port_number
= karg32
.hdr
.port_number
;
2184 karg
.hdr
.max_data_size
= karg32
.hdr
.max_data_size
;
2185 karg
.timeout
= karg32
.timeout
;
2186 karg
.max_reply_bytes
= karg32
.max_reply_bytes
;
2187 karg
.data_in_size
= karg32
.data_in_size
;
2188 karg
.data_out_size
= karg32
.data_out_size
;
2189 karg
.max_sense_bytes
= karg32
.max_sense_bytes
;
2190 karg
.data_sge_offset
= karg32
.data_sge_offset
;
2191 karg
.reply_frame_buf_ptr
= compat_ptr(karg32
.reply_frame_buf_ptr
);
2192 karg
.data_in_buf_ptr
= compat_ptr(karg32
.data_in_buf_ptr
);
2193 karg
.data_out_buf_ptr
= compat_ptr(karg32
.data_out_buf_ptr
);
2194 karg
.sense_data_ptr
= compat_ptr(karg32
.sense_data_ptr
);
2195 return _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2200 * _ctl_ioctl_main - main ioctl entry point
2201 * @file - (struct file)
2202 * @cmd - ioctl opcode
2203 * @arg - user space data buffer
2204 * @compat - handles 32 bit applications in 64bit os
2205 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
2206 * MPI25_VERSION for mpt3ctl ioctl device.
2209 _ctl_ioctl_main(struct file
*file
, unsigned int cmd
, void __user
*arg
,
2210 u8 compat
, u16 mpi_version
)
2212 struct MPT3SAS_ADAPTER
*ioc
;
2213 struct mpt3_ioctl_header ioctl_header
;
2214 enum block_state state
;
2217 /* get IOCTL header */
2218 if (copy_from_user(&ioctl_header
, (char __user
*)arg
,
2219 sizeof(struct mpt3_ioctl_header
))) {
2220 pr_err("failure at %s:%d/%s()!\n",
2221 __FILE__
, __LINE__
, __func__
);
2225 if (_ctl_verify_adapter(ioctl_header
.ioc_number
,
2226 &ioc
, mpi_version
) == -1 || !ioc
)
2229 /* pci_access_mutex lock acquired by ioctl path */
2230 mutex_lock(&ioc
->pci_access_mutex
);
2232 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
2233 ioc
->is_driver_loading
|| ioc
->remove_host
) {
2235 goto out_unlock_pciaccess
;
2238 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
: BLOCKING
;
2239 if (state
== NON_BLOCKING
) {
2240 if (!mutex_trylock(&ioc
->ctl_cmds
.mutex
)) {
2242 goto out_unlock_pciaccess
;
2244 } else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
)) {
2246 goto out_unlock_pciaccess
;
2252 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_iocinfo
))
2253 ret
= _ctl_getiocinfo(ioc
, arg
);
2255 #ifdef CONFIG_COMPAT
2260 struct mpt3_ioctl_command __user
*uarg
;
2261 struct mpt3_ioctl_command karg
;
2263 #ifdef CONFIG_COMPAT
2265 ret
= _ctl_compat_mpt_command(ioc
, cmd
, arg
);
2269 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2270 pr_err("failure at %s:%d/%s()!\n",
2271 __FILE__
, __LINE__
, __func__
);
2276 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_command
)) {
2278 ret
= _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2282 case MPT3EVENTQUERY
:
2283 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_eventquery
))
2284 ret
= _ctl_eventquery(ioc
, arg
);
2286 case MPT3EVENTENABLE
:
2287 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_eventenable
))
2288 ret
= _ctl_eventenable(ioc
, arg
);
2290 case MPT3EVENTREPORT
:
2291 ret
= _ctl_eventreport(ioc
, arg
);
2294 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_diag_reset
))
2295 ret
= _ctl_do_reset(ioc
, arg
);
2297 case MPT3BTDHMAPPING
:
2298 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_btdh_mapping
))
2299 ret
= _ctl_btdh_mapping(ioc
, arg
);
2301 case MPT3DIAGREGISTER
:
2302 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_register
))
2303 ret
= _ctl_diag_register(ioc
, arg
);
2305 case MPT3DIAGUNREGISTER
:
2306 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_unregister
))
2307 ret
= _ctl_diag_unregister(ioc
, arg
);
2310 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_query
))
2311 ret
= _ctl_diag_query(ioc
, arg
);
2313 case MPT3DIAGRELEASE
:
2314 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_release
))
2315 ret
= _ctl_diag_release(ioc
, arg
);
2317 case MPT3DIAGREADBUFFER
:
2318 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_read_buffer
))
2319 ret
= _ctl_diag_read_buffer(ioc
, arg
);
2322 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2323 "unsupported ioctl opcode(0x%08x)\n", ioc
->name
, cmd
));
2327 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
2328 out_unlock_pciaccess
:
2329 mutex_unlock(&ioc
->pci_access_mutex
);
2334 * _ctl_ioctl - mpt3ctl main ioctl entry point (unlocked)
2335 * @file - (struct file)
2336 * @cmd - ioctl opcode
2340 _ctl_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2344 /* pass MPI25_VERSION value, to indicate that this ioctl cmd
2345 * came from mpt3ctl ioctl device.
2347 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 0, MPI25_VERSION
);
2352 * _ctl_mpt2_ioctl - mpt2ctl main ioctl entry point (unlocked)
2353 * @file - (struct file)
2354 * @cmd - ioctl opcode
2358 _ctl_mpt2_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2362 /* pass MPI2_VERSION value, to indicate that this ioctl cmd
2363 * came from mpt2ctl ioctl device.
2365 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 0, MPI2_VERSION
);
2368 #ifdef CONFIG_COMPAT
2370 *_ ctl_ioctl_compat - main ioctl entry point (compat)
2375 * This routine handles 32 bit applications in 64bit os.
2378 _ctl_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2382 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 1, MPI25_VERSION
);
2387 *_ ctl_mpt2_ioctl_compat - main ioctl entry point (compat)
2392 * This routine handles 32 bit applications in 64bit os.
2395 _ctl_mpt2_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2399 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 1, MPI2_VERSION
);
2404 /* scsi host attributes */
2406 * _ctl_version_fw_show - firmware version
2407 * @cdev - pointer to embedded class device
2408 * @buf - the buffer returned
2410 * A sysfs 'read-only' shost attribute.
2413 _ctl_version_fw_show(struct device
*cdev
, struct device_attribute
*attr
,
2416 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2417 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2419 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2420 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2421 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2422 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2423 ioc
->facts
.FWVersion
.Word
& 0x000000FF);
2425 static DEVICE_ATTR(version_fw
, S_IRUGO
, _ctl_version_fw_show
, NULL
);
2428 * _ctl_version_bios_show - bios version
2429 * @cdev - pointer to embedded class device
2430 * @buf - the buffer returned
2432 * A sysfs 'read-only' shost attribute.
2435 _ctl_version_bios_show(struct device
*cdev
, struct device_attribute
*attr
,
2438 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2439 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2441 u32 version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2443 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2444 (version
& 0xFF000000) >> 24,
2445 (version
& 0x00FF0000) >> 16,
2446 (version
& 0x0000FF00) >> 8,
2447 version
& 0x000000FF);
2449 static DEVICE_ATTR(version_bios
, S_IRUGO
, _ctl_version_bios_show
, NULL
);
2452 * _ctl_version_mpi_show - MPI (message passing interface) version
2453 * @cdev - pointer to embedded class device
2454 * @buf - the buffer returned
2456 * A sysfs 'read-only' shost attribute.
2459 _ctl_version_mpi_show(struct device
*cdev
, struct device_attribute
*attr
,
2462 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2463 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2465 return snprintf(buf
, PAGE_SIZE
, "%03x.%02x\n",
2466 ioc
->facts
.MsgVersion
, ioc
->facts
.HeaderVersion
>> 8);
2468 static DEVICE_ATTR(version_mpi
, S_IRUGO
, _ctl_version_mpi_show
, NULL
);
2471 * _ctl_version_product_show - product name
2472 * @cdev - pointer to embedded class device
2473 * @buf - the buffer returned
2475 * A sysfs 'read-only' shost attribute.
2478 _ctl_version_product_show(struct device
*cdev
, struct device_attribute
*attr
,
2481 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2482 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2484 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.ChipName
);
2486 static DEVICE_ATTR(version_product
, S_IRUGO
, _ctl_version_product_show
, NULL
);
2489 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2490 * @cdev - pointer to embedded class device
2491 * @buf - the buffer returned
2493 * A sysfs 'read-only' shost attribute.
2496 _ctl_version_nvdata_persistent_show(struct device
*cdev
,
2497 struct device_attribute
*attr
, char *buf
)
2499 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2500 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2502 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2503 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionPersistent
.Word
));
2505 static DEVICE_ATTR(version_nvdata_persistent
, S_IRUGO
,
2506 _ctl_version_nvdata_persistent_show
, NULL
);
2509 * _ctl_version_nvdata_default_show - nvdata default version
2510 * @cdev - pointer to embedded class device
2511 * @buf - the buffer returned
2513 * A sysfs 'read-only' shost attribute.
2516 _ctl_version_nvdata_default_show(struct device
*cdev
, struct device_attribute
2519 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2520 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2522 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2523 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionDefault
.Word
));
2525 static DEVICE_ATTR(version_nvdata_default
, S_IRUGO
,
2526 _ctl_version_nvdata_default_show
, NULL
);
2529 * _ctl_board_name_show - board name
2530 * @cdev - pointer to embedded class device
2531 * @buf - the buffer returned
2533 * A sysfs 'read-only' shost attribute.
2536 _ctl_board_name_show(struct device
*cdev
, struct device_attribute
*attr
,
2539 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2540 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2542 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardName
);
2544 static DEVICE_ATTR(board_name
, S_IRUGO
, _ctl_board_name_show
, NULL
);
2547 * _ctl_board_assembly_show - board assembly name
2548 * @cdev - pointer to embedded class device
2549 * @buf - the buffer returned
2551 * A sysfs 'read-only' shost attribute.
2554 _ctl_board_assembly_show(struct device
*cdev
, struct device_attribute
*attr
,
2557 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2558 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2560 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardAssembly
);
2562 static DEVICE_ATTR(board_assembly
, S_IRUGO
, _ctl_board_assembly_show
, NULL
);
2565 * _ctl_board_tracer_show - board tracer number
2566 * @cdev - pointer to embedded class device
2567 * @buf - the buffer returned
2569 * A sysfs 'read-only' shost attribute.
2572 _ctl_board_tracer_show(struct device
*cdev
, struct device_attribute
*attr
,
2575 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2576 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2578 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardTracerNumber
);
2580 static DEVICE_ATTR(board_tracer
, S_IRUGO
, _ctl_board_tracer_show
, NULL
);
2583 * _ctl_io_delay_show - io missing delay
2584 * @cdev - pointer to embedded class device
2585 * @buf - the buffer returned
2587 * This is for firmware implemention for deboucing device
2590 * A sysfs 'read-only' shost attribute.
2593 _ctl_io_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2596 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2597 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2599 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->io_missing_delay
);
2601 static DEVICE_ATTR(io_delay
, S_IRUGO
, _ctl_io_delay_show
, NULL
);
2604 * _ctl_device_delay_show - device missing delay
2605 * @cdev - pointer to embedded class device
2606 * @buf - the buffer returned
2608 * This is for firmware implemention for deboucing device
2611 * A sysfs 'read-only' shost attribute.
2614 _ctl_device_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2617 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2618 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2620 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->device_missing_delay
);
2622 static DEVICE_ATTR(device_delay
, S_IRUGO
, _ctl_device_delay_show
, NULL
);
2625 * _ctl_fw_queue_depth_show - global credits
2626 * @cdev - pointer to embedded class device
2627 * @buf - the buffer returned
2629 * This is firmware queue depth limit
2631 * A sysfs 'read-only' shost attribute.
2634 _ctl_fw_queue_depth_show(struct device
*cdev
, struct device_attribute
*attr
,
2637 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2638 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2640 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->facts
.RequestCredit
);
2642 static DEVICE_ATTR(fw_queue_depth
, S_IRUGO
, _ctl_fw_queue_depth_show
, NULL
);
2645 * _ctl_sas_address_show - sas address
2646 * @cdev - pointer to embedded class device
2647 * @buf - the buffer returned
2649 * This is the controller sas address
2651 * A sysfs 'read-only' shost attribute.
2654 _ctl_host_sas_address_show(struct device
*cdev
, struct device_attribute
*attr
,
2658 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2659 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2661 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
2662 (unsigned long long)ioc
->sas_hba
.sas_address
);
2664 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
2665 _ctl_host_sas_address_show
, NULL
);
2668 * _ctl_logging_level_show - logging level
2669 * @cdev - pointer to embedded class device
2670 * @buf - the buffer returned
2672 * A sysfs 'read/write' shost attribute.
2675 _ctl_logging_level_show(struct device
*cdev
, struct device_attribute
*attr
,
2678 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2679 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2681 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", ioc
->logging_level
);
2684 _ctl_logging_level_store(struct device
*cdev
, struct device_attribute
*attr
,
2685 const char *buf
, size_t count
)
2687 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2688 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2691 if (sscanf(buf
, "%x", &val
) != 1)
2694 ioc
->logging_level
= val
;
2695 pr_info(MPT3SAS_FMT
"logging_level=%08xh\n", ioc
->name
,
2696 ioc
->logging_level
);
2699 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
, _ctl_logging_level_show
,
2700 _ctl_logging_level_store
);
2703 * _ctl_fwfault_debug_show - show/store fwfault_debug
2704 * @cdev - pointer to embedded class device
2705 * @buf - the buffer returned
2707 * mpt3sas_fwfault_debug is command line option
2708 * A sysfs 'read/write' shost attribute.
2711 _ctl_fwfault_debug_show(struct device
*cdev
, struct device_attribute
*attr
,
2714 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2715 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2717 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->fwfault_debug
);
2720 _ctl_fwfault_debug_store(struct device
*cdev
, struct device_attribute
*attr
,
2721 const char *buf
, size_t count
)
2723 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2724 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2727 if (sscanf(buf
, "%d", &val
) != 1)
2730 ioc
->fwfault_debug
= val
;
2731 pr_info(MPT3SAS_FMT
"fwfault_debug=%d\n", ioc
->name
,
2732 ioc
->fwfault_debug
);
2735 static DEVICE_ATTR(fwfault_debug
, S_IRUGO
| S_IWUSR
,
2736 _ctl_fwfault_debug_show
, _ctl_fwfault_debug_store
);
2739 * _ctl_ioc_reset_count_show - ioc reset count
2740 * @cdev - pointer to embedded class device
2741 * @buf - the buffer returned
2743 * This is firmware queue depth limit
2745 * A sysfs 'read-only' shost attribute.
2748 _ctl_ioc_reset_count_show(struct device
*cdev
, struct device_attribute
*attr
,
2751 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2752 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2754 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->ioc_reset_count
);
2756 static DEVICE_ATTR(ioc_reset_count
, S_IRUGO
, _ctl_ioc_reset_count_show
, NULL
);
2759 * _ctl_ioc_reply_queue_count_show - number of reply queues
2760 * @cdev - pointer to embedded class device
2761 * @buf - the buffer returned
2763 * This is number of reply queues
2765 * A sysfs 'read-only' shost attribute.
2768 _ctl_ioc_reply_queue_count_show(struct device
*cdev
,
2769 struct device_attribute
*attr
, char *buf
)
2771 u8 reply_queue_count
;
2772 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2773 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2775 if ((ioc
->facts
.IOCCapabilities
&
2776 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
)
2777 reply_queue_count
= ioc
->reply_queue_count
;
2779 reply_queue_count
= 1;
2781 return snprintf(buf
, PAGE_SIZE
, "%d\n", reply_queue_count
);
2783 static DEVICE_ATTR(reply_queue_count
, S_IRUGO
, _ctl_ioc_reply_queue_count_show
,
2787 * _ctl_BRM_status_show - Backup Rail Monitor Status
2788 * @cdev - pointer to embedded class device
2789 * @buf - the buffer returned
2791 * This is number of reply queues
2793 * A sysfs 'read-only' shost attribute.
2796 _ctl_BRM_status_show(struct device
*cdev
, struct device_attribute
*attr
,
2799 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2800 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2801 Mpi2IOUnitPage3_t
*io_unit_pg3
= NULL
;
2802 Mpi2ConfigReply_t mpi_reply
;
2803 u16 backup_rail_monitor_status
= 0;
2808 if (!ioc
->is_warpdrive
) {
2809 pr_err(MPT3SAS_FMT
"%s: BRM attribute is only for"
2810 " warpdrive\n", ioc
->name
, __func__
);
2813 /* pci_access_mutex lock acquired by sysfs show path */
2814 mutex_lock(&ioc
->pci_access_mutex
);
2815 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
2816 mutex_unlock(&ioc
->pci_access_mutex
);
2820 /* allocate upto GPIOVal 36 entries */
2821 sz
= offsetof(Mpi2IOUnitPage3_t
, GPIOVal
) + (sizeof(u16
) * 36);
2822 io_unit_pg3
= kzalloc(sz
, GFP_KERNEL
);
2824 pr_err(MPT3SAS_FMT
"%s: failed allocating memory "
2825 "for iounit_pg3: (%d) bytes\n", ioc
->name
, __func__
, sz
);
2829 if (mpt3sas_config_get_iounit_pg3(ioc
, &mpi_reply
, io_unit_pg3
, sz
) !=
2832 "%s: failed reading iounit_pg3\n", ioc
->name
,
2837 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2838 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2839 pr_err(MPT3SAS_FMT
"%s: iounit_pg3 failed with "
2840 "ioc_status(0x%04x)\n", ioc
->name
, __func__
, ioc_status
);
2844 if (io_unit_pg3
->GPIOCount
< 25) {
2845 pr_err(MPT3SAS_FMT
"%s: iounit_pg3->GPIOCount less than "
2846 "25 entries, detected (%d) entries\n", ioc
->name
, __func__
,
2847 io_unit_pg3
->GPIOCount
);
2851 /* BRM status is in bit zero of GPIOVal[24] */
2852 backup_rail_monitor_status
= le16_to_cpu(io_unit_pg3
->GPIOVal
[24]);
2853 rc
= snprintf(buf
, PAGE_SIZE
, "%d\n", (backup_rail_monitor_status
& 1));
2857 mutex_unlock(&ioc
->pci_access_mutex
);
2860 static DEVICE_ATTR(BRM_status
, S_IRUGO
, _ctl_BRM_status_show
, NULL
);
2862 struct DIAG_BUFFER_START
{
2873 * _ctl_host_trace_buffer_size_show - host buffer size (trace only)
2874 * @cdev - pointer to embedded class device
2875 * @buf - the buffer returned
2877 * A sysfs 'read-only' shost attribute.
2880 _ctl_host_trace_buffer_size_show(struct device
*cdev
,
2881 struct device_attribute
*attr
, char *buf
)
2883 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2884 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2886 struct DIAG_BUFFER_START
*request_data
;
2888 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
2890 "%s: host_trace_buffer is not registered\n",
2891 ioc
->name
, __func__
);
2895 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2896 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2898 "%s: host_trace_buffer is not registered\n",
2899 ioc
->name
, __func__
);
2903 request_data
= (struct DIAG_BUFFER_START
*)
2904 ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
];
2905 if ((le32_to_cpu(request_data
->DiagVersion
) == 0x00000000 ||
2906 le32_to_cpu(request_data
->DiagVersion
) == 0x01000000 ||
2907 le32_to_cpu(request_data
->DiagVersion
) == 0x01010000) &&
2908 le32_to_cpu(request_data
->Reserved3
) == 0x4742444c)
2909 size
= le32_to_cpu(request_data
->Size
);
2911 ioc
->ring_buffer_sz
= size
;
2912 return snprintf(buf
, PAGE_SIZE
, "%d\n", size
);
2914 static DEVICE_ATTR(host_trace_buffer_size
, S_IRUGO
,
2915 _ctl_host_trace_buffer_size_show
, NULL
);
2918 * _ctl_host_trace_buffer_show - firmware ring buffer (trace only)
2919 * @cdev - pointer to embedded class device
2920 * @buf - the buffer returned
2922 * A sysfs 'read/write' shost attribute.
2924 * You will only be able to read 4k bytes of ring buffer at a time.
2925 * In order to read beyond 4k bytes, you will have to write out the
2926 * offset to the same attribute, it will move the pointer.
2929 _ctl_host_trace_buffer_show(struct device
*cdev
, struct device_attribute
*attr
,
2932 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2933 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2937 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
2939 "%s: host_trace_buffer is not registered\n",
2940 ioc
->name
, __func__
);
2944 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2945 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2947 "%s: host_trace_buffer is not registered\n",
2948 ioc
->name
, __func__
);
2952 if (ioc
->ring_buffer_offset
> ioc
->ring_buffer_sz
)
2955 size
= ioc
->ring_buffer_sz
- ioc
->ring_buffer_offset
;
2956 size
= (size
>= PAGE_SIZE
) ? (PAGE_SIZE
- 1) : size
;
2957 request_data
= ioc
->diag_buffer
[0] + ioc
->ring_buffer_offset
;
2958 memcpy(buf
, request_data
, size
);
2963 _ctl_host_trace_buffer_store(struct device
*cdev
, struct device_attribute
*attr
,
2964 const char *buf
, size_t count
)
2966 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2967 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2970 if (sscanf(buf
, "%d", &val
) != 1)
2973 ioc
->ring_buffer_offset
= val
;
2976 static DEVICE_ATTR(host_trace_buffer
, S_IRUGO
| S_IWUSR
,
2977 _ctl_host_trace_buffer_show
, _ctl_host_trace_buffer_store
);
2980 /*****************************************/
2983 * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only)
2984 * @cdev - pointer to embedded class device
2985 * @buf - the buffer returned
2987 * A sysfs 'read/write' shost attribute.
2989 * This is a mechnism to post/release host_trace_buffers
2992 _ctl_host_trace_buffer_enable_show(struct device
*cdev
,
2993 struct device_attribute
*attr
, char *buf
)
2995 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2996 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2998 if ((!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) ||
2999 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3000 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0))
3001 return snprintf(buf
, PAGE_SIZE
, "off\n");
3002 else if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3003 MPT3_DIAG_BUFFER_IS_RELEASED
))
3004 return snprintf(buf
, PAGE_SIZE
, "release\n");
3006 return snprintf(buf
, PAGE_SIZE
, "post\n");
3010 _ctl_host_trace_buffer_enable_store(struct device
*cdev
,
3011 struct device_attribute
*attr
, const char *buf
, size_t count
)
3013 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3014 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3016 struct mpt3_diag_register diag_register
;
3019 /* don't allow post/release occurr while recovery is active */
3020 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3021 ioc
->pci_error_recovery
|| ioc
->is_driver_loading
)
3024 if (sscanf(buf
, "%9s", str
) != 1)
3027 if (!strcmp(str
, "post")) {
3028 /* exit out if host buffers are already posted */
3029 if ((ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) &&
3030 (ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3031 MPT3_DIAG_BUFFER_IS_REGISTERED
) &&
3032 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3033 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0))
3035 memset(&diag_register
, 0, sizeof(struct mpt3_diag_register
));
3036 pr_info(MPT3SAS_FMT
"posting host trace buffers\n",
3038 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
3039 diag_register
.requested_buffer_size
= (1024 * 1024);
3040 diag_register
.unique_id
= 0x7075900;
3041 ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] = 0;
3042 _ctl_diag_register_2(ioc
, &diag_register
);
3043 } else if (!strcmp(str
, "release")) {
3044 /* exit out if host buffers are already released */
3045 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
])
3047 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3048 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0)
3050 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3051 MPT3_DIAG_BUFFER_IS_RELEASED
))
3053 pr_info(MPT3SAS_FMT
"releasing host trace buffer\n",
3055 mpt3sas_send_diag_release(ioc
, MPI2_DIAG_BUF_TYPE_TRACE
,
3062 static DEVICE_ATTR(host_trace_buffer_enable
, S_IRUGO
| S_IWUSR
,
3063 _ctl_host_trace_buffer_enable_show
,
3064 _ctl_host_trace_buffer_enable_store
);
3066 /*********** diagnostic trigger suppport *********************************/
3069 * _ctl_diag_trigger_master_show - show the diag_trigger_master attribute
3070 * @cdev - pointer to embedded class device
3071 * @buf - the buffer returned
3073 * A sysfs 'read/write' shost attribute.
3076 _ctl_diag_trigger_master_show(struct device
*cdev
,
3077 struct device_attribute
*attr
, char *buf
)
3080 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3081 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3082 unsigned long flags
;
3085 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3086 rc
= sizeof(struct SL_WH_MASTER_TRIGGER_T
);
3087 memcpy(buf
, &ioc
->diag_trigger_master
, rc
);
3088 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3093 * _ctl_diag_trigger_master_store - store the diag_trigger_master attribute
3094 * @cdev - pointer to embedded class device
3095 * @buf - the buffer returned
3097 * A sysfs 'read/write' shost attribute.
3100 _ctl_diag_trigger_master_store(struct device
*cdev
,
3101 struct device_attribute
*attr
, const char *buf
, size_t count
)
3104 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3105 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3106 unsigned long flags
;
3109 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3110 rc
= min(sizeof(struct SL_WH_MASTER_TRIGGER_T
), count
);
3111 memset(&ioc
->diag_trigger_master
, 0,
3112 sizeof(struct SL_WH_MASTER_TRIGGER_T
));
3113 memcpy(&ioc
->diag_trigger_master
, buf
, rc
);
3114 ioc
->diag_trigger_master
.MasterData
|=
3115 (MASTER_TRIGGER_FW_FAULT
+ MASTER_TRIGGER_ADAPTER_RESET
);
3116 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3119 static DEVICE_ATTR(diag_trigger_master
, S_IRUGO
| S_IWUSR
,
3120 _ctl_diag_trigger_master_show
, _ctl_diag_trigger_master_store
);
3124 * _ctl_diag_trigger_event_show - show the diag_trigger_event attribute
3125 * @cdev - pointer to embedded class device
3126 * @buf - the buffer returned
3128 * A sysfs 'read/write' shost attribute.
3131 _ctl_diag_trigger_event_show(struct device
*cdev
,
3132 struct device_attribute
*attr
, char *buf
)
3134 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3135 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3136 unsigned long flags
;
3139 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3140 rc
= sizeof(struct SL_WH_EVENT_TRIGGERS_T
);
3141 memcpy(buf
, &ioc
->diag_trigger_event
, rc
);
3142 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3147 * _ctl_diag_trigger_event_store - store the diag_trigger_event attribute
3148 * @cdev - pointer to embedded class device
3149 * @buf - the buffer returned
3151 * A sysfs 'read/write' shost attribute.
3154 _ctl_diag_trigger_event_store(struct device
*cdev
,
3155 struct device_attribute
*attr
, const char *buf
, size_t count
)
3158 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3159 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3160 unsigned long flags
;
3163 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3164 sz
= min(sizeof(struct SL_WH_EVENT_TRIGGERS_T
), count
);
3165 memset(&ioc
->diag_trigger_event
, 0,
3166 sizeof(struct SL_WH_EVENT_TRIGGERS_T
));
3167 memcpy(&ioc
->diag_trigger_event
, buf
, sz
);
3168 if (ioc
->diag_trigger_event
.ValidEntries
> NUM_VALID_ENTRIES
)
3169 ioc
->diag_trigger_event
.ValidEntries
= NUM_VALID_ENTRIES
;
3170 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3173 static DEVICE_ATTR(diag_trigger_event
, S_IRUGO
| S_IWUSR
,
3174 _ctl_diag_trigger_event_show
, _ctl_diag_trigger_event_store
);
3178 * _ctl_diag_trigger_scsi_show - show the diag_trigger_scsi attribute
3179 * @cdev - pointer to embedded class device
3180 * @buf - the buffer returned
3182 * A sysfs 'read/write' shost attribute.
3185 _ctl_diag_trigger_scsi_show(struct device
*cdev
,
3186 struct device_attribute
*attr
, char *buf
)
3188 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3189 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3190 unsigned long flags
;
3193 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3194 rc
= sizeof(struct SL_WH_SCSI_TRIGGERS_T
);
3195 memcpy(buf
, &ioc
->diag_trigger_scsi
, rc
);
3196 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3201 * _ctl_diag_trigger_scsi_store - store the diag_trigger_scsi attribute
3202 * @cdev - pointer to embedded class device
3203 * @buf - the buffer returned
3205 * A sysfs 'read/write' shost attribute.
3208 _ctl_diag_trigger_scsi_store(struct device
*cdev
,
3209 struct device_attribute
*attr
, const char *buf
, size_t count
)
3211 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3212 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3213 unsigned long flags
;
3216 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3217 sz
= min(sizeof(struct SL_WH_SCSI_TRIGGERS_T
), count
);
3218 memset(&ioc
->diag_trigger_scsi
, 0,
3219 sizeof(struct SL_WH_EVENT_TRIGGERS_T
));
3220 memcpy(&ioc
->diag_trigger_scsi
, buf
, sz
);
3221 if (ioc
->diag_trigger_scsi
.ValidEntries
> NUM_VALID_ENTRIES
)
3222 ioc
->diag_trigger_scsi
.ValidEntries
= NUM_VALID_ENTRIES
;
3223 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3226 static DEVICE_ATTR(diag_trigger_scsi
, S_IRUGO
| S_IWUSR
,
3227 _ctl_diag_trigger_scsi_show
, _ctl_diag_trigger_scsi_store
);
3231 * _ctl_diag_trigger_scsi_show - show the diag_trigger_mpi attribute
3232 * @cdev - pointer to embedded class device
3233 * @buf - the buffer returned
3235 * A sysfs 'read/write' shost attribute.
3238 _ctl_diag_trigger_mpi_show(struct device
*cdev
,
3239 struct device_attribute
*attr
, char *buf
)
3241 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3242 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3243 unsigned long flags
;
3246 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3247 rc
= sizeof(struct SL_WH_MPI_TRIGGERS_T
);
3248 memcpy(buf
, &ioc
->diag_trigger_mpi
, rc
);
3249 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3254 * _ctl_diag_trigger_mpi_store - store the diag_trigger_mpi attribute
3255 * @cdev - pointer to embedded class device
3256 * @buf - the buffer returned
3258 * A sysfs 'read/write' shost attribute.
3261 _ctl_diag_trigger_mpi_store(struct device
*cdev
,
3262 struct device_attribute
*attr
, const char *buf
, size_t count
)
3264 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3265 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3266 unsigned long flags
;
3269 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3270 sz
= min(sizeof(struct SL_WH_MPI_TRIGGERS_T
), count
);
3271 memset(&ioc
->diag_trigger_mpi
, 0,
3272 sizeof(ioc
->diag_trigger_mpi
));
3273 memcpy(&ioc
->diag_trigger_mpi
, buf
, sz
);
3274 if (ioc
->diag_trigger_mpi
.ValidEntries
> NUM_VALID_ENTRIES
)
3275 ioc
->diag_trigger_mpi
.ValidEntries
= NUM_VALID_ENTRIES
;
3276 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3280 static DEVICE_ATTR(diag_trigger_mpi
, S_IRUGO
| S_IWUSR
,
3281 _ctl_diag_trigger_mpi_show
, _ctl_diag_trigger_mpi_store
);
3283 /*********** diagnostic trigger suppport *** END ****************************/
3287 /*****************************************/
3289 struct device_attribute
*mpt3sas_host_attrs
[] = {
3290 &dev_attr_version_fw
,
3291 &dev_attr_version_bios
,
3292 &dev_attr_version_mpi
,
3293 &dev_attr_version_product
,
3294 &dev_attr_version_nvdata_persistent
,
3295 &dev_attr_version_nvdata_default
,
3296 &dev_attr_board_name
,
3297 &dev_attr_board_assembly
,
3298 &dev_attr_board_tracer
,
3300 &dev_attr_device_delay
,
3301 &dev_attr_logging_level
,
3302 &dev_attr_fwfault_debug
,
3303 &dev_attr_fw_queue_depth
,
3304 &dev_attr_host_sas_address
,
3305 &dev_attr_ioc_reset_count
,
3306 &dev_attr_host_trace_buffer_size
,
3307 &dev_attr_host_trace_buffer
,
3308 &dev_attr_host_trace_buffer_enable
,
3309 &dev_attr_reply_queue_count
,
3310 &dev_attr_diag_trigger_master
,
3311 &dev_attr_diag_trigger_event
,
3312 &dev_attr_diag_trigger_scsi
,
3313 &dev_attr_diag_trigger_mpi
,
3314 &dev_attr_BRM_status
,
3318 /* device attributes */
3321 * _ctl_device_sas_address_show - sas address
3322 * @cdev - pointer to embedded class device
3323 * @buf - the buffer returned
3325 * This is the sas address for the target
3327 * A sysfs 'read-only' shost attribute.
3330 _ctl_device_sas_address_show(struct device
*dev
, struct device_attribute
*attr
,
3333 struct scsi_device
*sdev
= to_scsi_device(dev
);
3334 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
3336 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
3337 (unsigned long long)sas_device_priv_data
->sas_target
->sas_address
);
3339 static DEVICE_ATTR(sas_address
, S_IRUGO
, _ctl_device_sas_address_show
, NULL
);
3342 * _ctl_device_handle_show - device handle
3343 * @cdev - pointer to embedded class device
3344 * @buf - the buffer returned
3346 * This is the firmware assigned device handle
3348 * A sysfs 'read-only' shost attribute.
3351 _ctl_device_handle_show(struct device
*dev
, struct device_attribute
*attr
,
3354 struct scsi_device
*sdev
= to_scsi_device(dev
);
3355 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
3357 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n",
3358 sas_device_priv_data
->sas_target
->handle
);
3360 static DEVICE_ATTR(sas_device_handle
, S_IRUGO
, _ctl_device_handle_show
, NULL
);
3362 struct device_attribute
*mpt3sas_dev_attrs
[] = {
3363 &dev_attr_sas_address
,
3364 &dev_attr_sas_device_handle
,
3368 /* file operations table for mpt3ctl device */
3369 static const struct file_operations ctl_fops
= {
3370 .owner
= THIS_MODULE
,
3371 .unlocked_ioctl
= _ctl_ioctl
,
3373 .fasync
= _ctl_fasync
,
3374 #ifdef CONFIG_COMPAT
3375 .compat_ioctl
= _ctl_ioctl_compat
,
3379 /* file operations table for mpt2ctl device */
3380 static const struct file_operations ctl_gen2_fops
= {
3381 .owner
= THIS_MODULE
,
3382 .unlocked_ioctl
= _ctl_mpt2_ioctl
,
3384 .fasync
= _ctl_fasync
,
3385 #ifdef CONFIG_COMPAT
3386 .compat_ioctl
= _ctl_mpt2_ioctl_compat
,
3390 static struct miscdevice ctl_dev
= {
3391 .minor
= MPT3SAS_MINOR
,
3392 .name
= MPT3SAS_DEV_NAME
,
3396 static struct miscdevice gen2_ctl_dev
= {
3397 .minor
= MPT2SAS_MINOR
,
3398 .name
= MPT2SAS_DEV_NAME
,
3399 .fops
= &ctl_gen2_fops
,
3403 * mpt3sas_ctl_init - main entry point for ctl.
3407 mpt3sas_ctl_init(ushort hbas_to_enumerate
)
3411 /* Don't register mpt3ctl ioctl device if
3412 * hbas_to_enumarate is one.
3414 if (hbas_to_enumerate
!= 1)
3415 if (misc_register(&ctl_dev
) < 0)
3416 pr_err("%s can't register misc device [minor=%d]\n",
3417 MPT3SAS_DRIVER_NAME
, MPT3SAS_MINOR
);
3419 /* Don't register mpt3ctl ioctl device if
3420 * hbas_to_enumarate is two.
3422 if (hbas_to_enumerate
!= 2)
3423 if (misc_register(&gen2_ctl_dev
) < 0)
3424 pr_err("%s can't register misc device [minor=%d]\n",
3425 MPT2SAS_DRIVER_NAME
, MPT2SAS_MINOR
);
3427 init_waitqueue_head(&ctl_poll_wait
);
3431 * mpt3sas_ctl_exit - exit point for ctl
3435 mpt3sas_ctl_exit(ushort hbas_to_enumerate
)
3437 struct MPT3SAS_ADAPTER
*ioc
;
3440 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
) {
3442 /* free memory associated to diag buffers */
3443 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
3444 if (!ioc
->diag_buffer
[i
])
3446 if (!(ioc
->diag_buffer_status
[i
] &
3447 MPT3_DIAG_BUFFER_IS_REGISTERED
))
3449 if ((ioc
->diag_buffer_status
[i
] &
3450 MPT3_DIAG_BUFFER_IS_RELEASED
))
3452 pci_free_consistent(ioc
->pdev
, ioc
->diag_buffer_sz
[i
],
3453 ioc
->diag_buffer
[i
], ioc
->diag_buffer_dma
[i
]);
3454 ioc
->diag_buffer
[i
] = NULL
;
3455 ioc
->diag_buffer_status
[i
] = 0;
3458 kfree(ioc
->event_log
);
3460 if (hbas_to_enumerate
!= 1)
3461 misc_deregister(&ctl_dev
);
3462 if (hbas_to_enumerate
!= 2)
3463 misc_deregister(&gen2_ctl_dev
);