2 * Management Module Support for MPT (Message Passing Technology) based
5 * This code is based on drivers/scsi/mpt3sas/mpt3sas_ctl.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * Copyright (C) 2013-2014 Avago Technologies
8 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 * solely responsible for determining the appropriateness of using and
26 * distributing the Program and assumes all risks associated with its
27 * exercise of rights under this Agreement, including but not limited to
28 * the risks and costs of program errors, damage to or loss of data,
29 * programs or equipment, and unavailability or interruption of operations.
31 * DISCLAIMER OF LIABILITY
32 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/slab.h>
51 #include <linux/types.h>
52 #include <linux/pci.h>
53 #include <linux/delay.h>
54 #include <linux/compat.h>
55 #include <linux/poll.h>
58 #include <linux/uaccess.h>
60 #include "mpt3sas_base.h"
61 #include "mpt3sas_ctl.h"
64 static struct fasync_struct
*async_queue
;
65 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait
);
69 * enum block_state - blocking state
70 * @NON_BLOCKING: non blocking
73 * These states are for ioctls that need to wait for a response
74 * from firmware, so they probably require sleep.
82 * _ctl_sas_device_find_by_handle - sas device search
83 * @ioc: per adapter object
84 * @handle: sas device handle (assigned by firmware)
85 * Context: Calling function should acquire ioc->sas_device_lock
87 * This searches for sas_device based on sas_address, then return sas_device
90 static struct _sas_device
*
91 _ctl_sas_device_find_by_handle(struct MPT3SAS_ADAPTER
*ioc
, u16 handle
)
93 struct _sas_device
*sas_device
, *r
;
96 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
97 if (sas_device
->handle
!= handle
)
108 * _ctl_display_some_debug - debug routine
109 * @ioc: per adapter object
110 * @smid: system request message index
111 * @calling_function_name: string pass from calling function
112 * @mpi_reply: reply message frame
115 * Function for displaying debug info helpful when debugging issues
119 _ctl_display_some_debug(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
,
120 char *calling_function_name
, MPI2DefaultReply_t
*mpi_reply
)
122 Mpi2ConfigRequest_t
*mpi_request
;
125 if (!(ioc
->logging_level
& MPT_DEBUG_IOCTL
))
128 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
129 switch (mpi_request
->Function
) {
130 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
132 Mpi2SCSIIORequest_t
*scsi_request
=
133 (Mpi2SCSIIORequest_t
*)mpi_request
;
135 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
136 "scsi_io, cmd(0x%02x), cdb_len(%d)",
137 scsi_request
->CDB
.CDB32
[0],
138 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
139 desc
= ioc
->tmp_string
;
142 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
145 case MPI2_FUNCTION_IOC_INIT
:
148 case MPI2_FUNCTION_IOC_FACTS
:
151 case MPI2_FUNCTION_CONFIG
:
153 Mpi2ConfigRequest_t
*config_request
=
154 (Mpi2ConfigRequest_t
*)mpi_request
;
156 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
157 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
158 (config_request
->Header
.PageType
&
159 MPI2_CONFIG_PAGETYPE_MASK
), config_request
->ExtPageType
,
160 config_request
->Header
.PageNumber
);
161 desc
= ioc
->tmp_string
;
164 case MPI2_FUNCTION_PORT_FACTS
:
167 case MPI2_FUNCTION_PORT_ENABLE
:
168 desc
= "port_enable";
170 case MPI2_FUNCTION_EVENT_NOTIFICATION
:
171 desc
= "event_notification";
173 case MPI2_FUNCTION_FW_DOWNLOAD
:
174 desc
= "fw_download";
176 case MPI2_FUNCTION_FW_UPLOAD
:
179 case MPI2_FUNCTION_RAID_ACTION
:
180 desc
= "raid_action";
182 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
184 Mpi2SCSIIORequest_t
*scsi_request
=
185 (Mpi2SCSIIORequest_t
*)mpi_request
;
187 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
188 "raid_pass, cmd(0x%02x), cdb_len(%d)",
189 scsi_request
->CDB
.CDB32
[0],
190 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
191 desc
= ioc
->tmp_string
;
194 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
195 desc
= "sas_iounit_cntl";
197 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
200 case MPI2_FUNCTION_DIAG_BUFFER_POST
:
201 desc
= "diag_buffer_post";
203 case MPI2_FUNCTION_DIAG_RELEASE
:
204 desc
= "diag_release";
206 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
207 desc
= "smp_passthrough";
214 pr_info(MPT3SAS_FMT
"%s: %s, smid(%d)\n",
215 ioc
->name
, calling_function_name
, desc
, smid
);
220 if (mpi_reply
->IOCStatus
|| mpi_reply
->IOCLogInfo
)
222 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
223 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
224 le32_to_cpu(mpi_reply
->IOCLogInfo
));
226 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
227 mpi_request
->Function
==
228 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
229 Mpi2SCSIIOReply_t
*scsi_reply
=
230 (Mpi2SCSIIOReply_t
*)mpi_reply
;
231 struct _sas_device
*sas_device
= NULL
;
234 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
235 sas_device
= _ctl_sas_device_find_by_handle(ioc
,
236 le16_to_cpu(scsi_reply
->DevHandle
));
238 pr_warn(MPT3SAS_FMT
"\tsas_address(0x%016llx), phy(%d)\n",
239 ioc
->name
, (unsigned long long)
240 sas_device
->sas_address
, sas_device
->phy
);
242 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
243 ioc
->name
, (unsigned long long)
244 sas_device
->enclosure_logical_id
, sas_device
->slot
);
246 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
247 if (scsi_reply
->SCSIState
|| scsi_reply
->SCSIStatus
)
249 "\tscsi_state(0x%02x), scsi_status"
250 "(0x%02x)\n", ioc
->name
,
251 scsi_reply
->SCSIState
,
252 scsi_reply
->SCSIStatus
);
257 * mpt3sas_ctl_done - ctl module completion routine
258 * @ioc: per adapter object
259 * @smid: system request message index
260 * @msix_index: MSIX table index supplied by the OS
261 * @reply: reply message frame(lower 32bit addr)
264 * The callback handler when using ioc->ctl_cb_idx.
266 * Return 1 meaning mf should be freed from _base_interrupt
267 * 0 means the mf is freed from this function.
270 mpt3sas_ctl_done(struct MPT3SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
273 MPI2DefaultReply_t
*mpi_reply
;
274 Mpi2SCSIIOReply_t
*scsiio_reply
;
275 const void *sense_data
;
278 if (ioc
->ctl_cmds
.status
== MPT3_CMD_NOT_USED
)
280 if (ioc
->ctl_cmds
.smid
!= smid
)
282 ioc
->ctl_cmds
.status
|= MPT3_CMD_COMPLETE
;
283 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
285 memcpy(ioc
->ctl_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
286 ioc
->ctl_cmds
.status
|= MPT3_CMD_REPLY_VALID
;
288 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
289 mpi_reply
->Function
==
290 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
291 scsiio_reply
= (Mpi2SCSIIOReply_t
*)mpi_reply
;
292 if (scsiio_reply
->SCSIState
&
293 MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
294 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
295 le32_to_cpu(scsiio_reply
->SenseCount
));
296 sense_data
= mpt3sas_base_get_sense_buffer(ioc
,
298 memcpy(ioc
->ctl_cmds
.sense
, sense_data
, sz
);
302 _ctl_display_some_debug(ioc
, smid
, "ctl_done", mpi_reply
);
303 ioc
->ctl_cmds
.status
&= ~MPT3_CMD_PENDING
;
304 complete(&ioc
->ctl_cmds
.done
);
309 * _ctl_check_event_type - determines when an event needs logging
310 * @ioc: per adapter object
311 * @event: firmware event
313 * The bitmask in ioc->event_type[] indicates which events should be
314 * be saved in the driver event_log. This bitmask is set by application.
316 * Returns 1 when event should be captured, or zero means no match.
319 _ctl_check_event_type(struct MPT3SAS_ADAPTER
*ioc
, u16 event
)
324 if (event
>= 128 || !event
|| !ioc
->event_log
)
327 desired_event
= (1 << (event
% 32));
331 return desired_event
& ioc
->event_type
[i
];
335 * mpt3sas_ctl_add_to_event_log - add event
336 * @ioc: per adapter object
337 * @mpi_reply: reply message frame
342 mpt3sas_ctl_add_to_event_log(struct MPT3SAS_ADAPTER
*ioc
,
343 Mpi2EventNotificationReply_t
*mpi_reply
)
345 struct MPT3_IOCTL_EVENTS
*event_log
;
348 u32 sz
, event_data_sz
;
354 event
= le16_to_cpu(mpi_reply
->Event
);
356 if (_ctl_check_event_type(ioc
, event
)) {
358 /* insert entry into circular event_log */
359 i
= ioc
->event_context
% MPT3SAS_CTL_EVENT_LOG_SIZE
;
360 event_log
= ioc
->event_log
;
361 event_log
[i
].event
= event
;
362 event_log
[i
].context
= ioc
->event_context
++;
364 event_data_sz
= le16_to_cpu(mpi_reply
->EventDataLength
)*4;
365 sz
= min_t(u32
, event_data_sz
, MPT3_EVENT_DATA_SIZE
);
366 memset(event_log
[i
].data
, 0, MPT3_EVENT_DATA_SIZE
);
367 memcpy(event_log
[i
].data
, mpi_reply
->EventData
, sz
);
371 /* This aen_event_read_flag flag is set until the
372 * application has read the event log.
373 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
375 if (event
== MPI2_EVENT_LOG_ENTRY_ADDED
||
376 (send_aen
&& !ioc
->aen_event_read_flag
)) {
377 ioc
->aen_event_read_flag
= 1;
378 wake_up_interruptible(&ctl_poll_wait
);
380 kill_fasync(&async_queue
, SIGIO
, POLL_IN
);
385 * mpt3sas_ctl_event_callback - firmware event handler (called at ISR time)
386 * @ioc: per adapter object
387 * @msix_index: MSIX table index supplied by the OS
388 * @reply: reply message frame(lower 32bit addr)
389 * Context: interrupt.
391 * This function merely adds a new work task into ioc->firmware_event_thread.
392 * The tasks are worked from _firmware_event_work in user context.
394 * Return 1 meaning mf should be freed from _base_interrupt
395 * 0 means the mf is freed from this function.
398 mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER
*ioc
, u8 msix_index
,
401 Mpi2EventNotificationReply_t
*mpi_reply
;
403 mpi_reply
= mpt3sas_base_get_reply_virt_addr(ioc
, reply
);
405 mpt3sas_ctl_add_to_event_log(ioc
, mpi_reply
);
410 * _ctl_verify_adapter - validates ioc_number passed from application
411 * @ioc: per adapter object
412 * @iocpp: The ioc pointer is returned in this.
413 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
414 * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
416 * Return (-1) means error, else ioc_number.
419 _ctl_verify_adapter(int ioc_number
, struct MPT3SAS_ADAPTER
**iocpp
,
422 struct MPT3SAS_ADAPTER
*ioc
;
424 /* global ioc lock to protect controller on list operations */
425 spin_lock(&gioc_lock
);
426 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
) {
427 if (ioc
->id
!= ioc_number
)
429 /* Check whether this ioctl command is from right
430 * ioctl device or not, if not continue the search.
432 version
= ioc
->hba_mpi_version_belonged
;
433 /* MPI25_VERSION and MPI26_VERSION uses same ioctl
436 if (mpi_version
== (MPI25_VERSION
| MPI26_VERSION
)) {
437 if ((version
== MPI25_VERSION
) ||
438 (version
== MPI26_VERSION
))
443 if (version
!= mpi_version
)
447 spin_unlock(&gioc_lock
);
451 spin_unlock(&gioc_lock
);
457 * mpt3sas_ctl_reset_handler - reset callback handler (for ctl)
458 * @ioc: per adapter object
459 * @reset_phase: phase
461 * The handler for doing any required cleanup or initialization.
463 * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET,
464 * MPT3_IOC_DONE_RESET
467 mpt3sas_ctl_reset_handler(struct MPT3SAS_ADAPTER
*ioc
, int reset_phase
)
472 switch (reset_phase
) {
473 case MPT3_IOC_PRE_RESET
:
474 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
475 "%s: MPT3_IOC_PRE_RESET\n", ioc
->name
, __func__
));
476 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
477 if (!(ioc
->diag_buffer_status
[i
] &
478 MPT3_DIAG_BUFFER_IS_REGISTERED
))
480 if ((ioc
->diag_buffer_status
[i
] &
481 MPT3_DIAG_BUFFER_IS_RELEASED
))
483 mpt3sas_send_diag_release(ioc
, i
, &issue_reset
);
486 case MPT3_IOC_AFTER_RESET
:
487 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
488 "%s: MPT3_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
489 if (ioc
->ctl_cmds
.status
& MPT3_CMD_PENDING
) {
490 ioc
->ctl_cmds
.status
|= MPT3_CMD_RESET
;
491 mpt3sas_base_free_smid(ioc
, ioc
->ctl_cmds
.smid
);
492 complete(&ioc
->ctl_cmds
.done
);
495 case MPT3_IOC_DONE_RESET
:
496 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
497 "%s: MPT3_IOC_DONE_RESET\n", ioc
->name
, __func__
));
499 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
500 if (!(ioc
->diag_buffer_status
[i
] &
501 MPT3_DIAG_BUFFER_IS_REGISTERED
))
503 if ((ioc
->diag_buffer_status
[i
] &
504 MPT3_DIAG_BUFFER_IS_RELEASED
))
506 ioc
->diag_buffer_status
[i
] |=
507 MPT3_DIAG_BUFFER_IS_DIAG_RESET
;
519 * Called when application request fasyn callback handler.
522 _ctl_fasync(int fd
, struct file
*filep
, int mode
)
524 return fasync_helper(fd
, filep
, mode
, &async_queue
);
534 _ctl_poll(struct file
*filep
, poll_table
*wait
)
536 struct MPT3SAS_ADAPTER
*ioc
;
538 poll_wait(filep
, &ctl_poll_wait
, wait
);
540 /* global ioc lock to protect controller on list operations */
541 spin_lock(&gioc_lock
);
542 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
) {
543 if (ioc
->aen_event_read_flag
) {
544 spin_unlock(&gioc_lock
);
545 return POLLIN
| POLLRDNORM
;
548 spin_unlock(&gioc_lock
);
553 * _ctl_set_task_mid - assign an active smid to tm request
554 * @ioc: per adapter object
555 * @karg - (struct mpt3_ioctl_command)
556 * @tm_request - pointer to mf from user space
558 * Returns 0 when an smid if found, else fail.
559 * during failure, the reply frame is filled.
562 _ctl_set_task_mid(struct MPT3SAS_ADAPTER
*ioc
, struct mpt3_ioctl_command
*karg
,
563 Mpi2SCSITaskManagementRequest_t
*tm_request
)
568 struct scsi_cmnd
*scmd
;
569 struct MPT3SAS_DEVICE
*priv_data
;
571 Mpi2SCSITaskManagementReply_t
*tm_reply
;
576 if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
578 else if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
)
583 lun
= scsilun_to_int((struct scsi_lun
*)tm_request
->LUN
);
585 handle
= le16_to_cpu(tm_request
->DevHandle
);
586 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
587 for (i
= ioc
->scsiio_depth
; i
&& !found
; i
--) {
588 scmd
= ioc
->scsi_lookup
[i
- 1].scmd
;
589 if (scmd
== NULL
|| scmd
->device
== NULL
||
590 scmd
->device
->hostdata
== NULL
)
592 if (lun
!= scmd
->device
->lun
)
594 priv_data
= scmd
->device
->hostdata
;
595 if (priv_data
->sas_target
== NULL
)
597 if (priv_data
->sas_target
->handle
!= handle
)
599 tm_request
->TaskMID
= cpu_to_le16(ioc
->scsi_lookup
[i
- 1].smid
);
602 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
605 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
606 "%s: handle(0x%04x), lun(%d), no active mid!!\n",
608 desc
, le16_to_cpu(tm_request
->DevHandle
), lun
));
609 tm_reply
= ioc
->ctl_cmds
.reply
;
610 tm_reply
->DevHandle
= tm_request
->DevHandle
;
611 tm_reply
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
612 tm_reply
->TaskType
= tm_request
->TaskType
;
613 tm_reply
->MsgLength
= sizeof(Mpi2SCSITaskManagementReply_t
)/4;
614 tm_reply
->VP_ID
= tm_request
->VP_ID
;
615 tm_reply
->VF_ID
= tm_request
->VF_ID
;
616 sz
= min_t(u32
, karg
->max_reply_bytes
, ioc
->reply_sz
);
617 if (copy_to_user(karg
->reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
619 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
624 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
625 "%s: handle(0x%04x), lun(%d), task_mid(%d)\n", ioc
->name
,
626 desc
, le16_to_cpu(tm_request
->DevHandle
), lun
,
627 le16_to_cpu(tm_request
->TaskMID
)));
632 * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode
633 * @ioc: per adapter object
634 * @karg - (struct mpt3_ioctl_command)
635 * @mf - pointer to mf in user space
638 _ctl_do_mpt_command(struct MPT3SAS_ADAPTER
*ioc
, struct mpt3_ioctl_command karg
,
641 MPI2RequestHeader_t
*mpi_request
= NULL
, *request
;
642 MPI2DefaultReply_t
*mpi_reply
;
646 unsigned long timeout
, timeleft
;
650 void *data_out
= NULL
;
651 dma_addr_t data_out_dma
= 0;
652 size_t data_out_sz
= 0;
653 void *data_in
= NULL
;
654 dma_addr_t data_in_dma
= 0;
655 size_t data_in_sz
= 0;
657 u16 wait_state_count
;
661 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
662 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
663 ioc
->name
, __func__
);
668 wait_state_count
= 0;
669 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
670 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
671 if (wait_state_count
++ == 10) {
673 "%s: failed due to ioc not operational\n",
674 ioc
->name
, __func__
);
679 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
681 "%s: waiting for operational state(count=%d)\n",
683 __func__
, wait_state_count
);
685 if (wait_state_count
)
686 pr_info(MPT3SAS_FMT
"%s: ioc is operational\n",
687 ioc
->name
, __func__
);
689 mpi_request
= kzalloc(ioc
->request_sz
, GFP_KERNEL
);
692 "%s: failed obtaining a memory for mpi_request\n",
693 ioc
->name
, __func__
);
698 /* Check for overflow and wraparound */
699 if (karg
.data_sge_offset
* 4 > ioc
->request_sz
||
700 karg
.data_sge_offset
> (UINT_MAX
/ 4)) {
705 /* copy in request message frame from user */
706 if (copy_from_user(mpi_request
, mf
, karg
.data_sge_offset
*4)) {
707 pr_err("failure at %s:%d/%s()!\n", __FILE__
, __LINE__
,
713 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
714 smid
= mpt3sas_base_get_smid_hpr(ioc
, ioc
->ctl_cb_idx
);
716 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
717 ioc
->name
, __func__
);
723 smid
= mpt3sas_base_get_smid_scsiio(ioc
, ioc
->ctl_cb_idx
, NULL
);
725 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
726 ioc
->name
, __func__
);
733 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
734 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
735 request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
736 memcpy(request
, mpi_request
, karg
.data_sge_offset
*4);
737 ioc
->ctl_cmds
.smid
= smid
;
738 data_out_sz
= karg
.data_out_size
;
739 data_in_sz
= karg
.data_in_size
;
741 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
742 mpi_request
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
743 if (!le16_to_cpu(mpi_request
->FunctionDependent1
) ||
744 le16_to_cpu(mpi_request
->FunctionDependent1
) >
745 ioc
->facts
.MaxDevHandle
) {
747 mpt3sas_base_free_smid(ioc
, smid
);
752 /* obtain dma-able memory for data transfer */
753 if (data_out_sz
) /* WRITE */ {
754 data_out
= pci_alloc_consistent(ioc
->pdev
, data_out_sz
,
757 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
760 mpt3sas_base_free_smid(ioc
, smid
);
763 if (copy_from_user(data_out
, karg
.data_out_buf_ptr
,
765 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
768 mpt3sas_base_free_smid(ioc
, smid
);
773 if (data_in_sz
) /* READ */ {
774 data_in
= pci_alloc_consistent(ioc
->pdev
, data_in_sz
,
777 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
780 mpt3sas_base_free_smid(ioc
, smid
);
785 psge
= (void *)request
+ (karg
.data_sge_offset
*4);
787 /* send command to firmware */
788 _ctl_display_some_debug(ioc
, smid
, "ctl_request", NULL
);
790 init_completion(&ioc
->ctl_cmds
.done
);
791 switch (mpi_request
->Function
) {
792 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
793 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
795 Mpi2SCSIIORequest_t
*scsiio_request
=
796 (Mpi2SCSIIORequest_t
*)request
;
797 scsiio_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
798 scsiio_request
->SenseBufferLowAddress
=
799 mpt3sas_base_get_sense_buffer_dma(ioc
, smid
);
800 memset(ioc
->ctl_cmds
.sense
, 0, SCSI_SENSE_BUFFERSIZE
);
801 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
,
802 data_in_dma
, data_in_sz
);
804 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)
805 mpt3sas_base_put_smid_scsi_io(ioc
, smid
,
806 le16_to_cpu(mpi_request
->FunctionDependent1
));
808 mpt3sas_base_put_smid_default(ioc
, smid
);
811 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
813 Mpi2SCSITaskManagementRequest_t
*tm_request
=
814 (Mpi2SCSITaskManagementRequest_t
*)request
;
816 dtmprintk(ioc
, pr_info(MPT3SAS_FMT
817 "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n",
819 le16_to_cpu(tm_request
->DevHandle
), tm_request
->TaskType
));
821 if (tm_request
->TaskType
==
822 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
||
823 tm_request
->TaskType
==
824 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
) {
825 if (_ctl_set_task_mid(ioc
, &karg
, tm_request
)) {
826 mpt3sas_base_free_smid(ioc
, smid
);
831 mpt3sas_scsih_set_tm_flag(ioc
, le16_to_cpu(
832 tm_request
->DevHandle
));
833 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
834 data_in_dma
, data_in_sz
);
835 mpt3sas_base_put_smid_hi_priority(ioc
, smid
, 0);
838 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
840 Mpi2SmpPassthroughRequest_t
*smp_request
=
841 (Mpi2SmpPassthroughRequest_t
*)mpi_request
;
844 /* ioc determines which port to use */
845 smp_request
->PhysicalPort
= 0xFF;
846 if (smp_request
->PassthroughFlags
&
847 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE
)
848 data
= (u8
*)&smp_request
->SGL
;
850 if (unlikely(data_out
== NULL
)) {
851 pr_err("failure at %s:%d/%s()!\n",
852 __FILE__
, __LINE__
, __func__
);
853 mpt3sas_base_free_smid(ioc
, smid
);
860 if (data
[1] == 0x91 && (data
[10] == 1 || data
[10] == 2)) {
861 ioc
->ioc_link_reset_in_progress
= 1;
862 ioc
->ignore_loginfos
= 1;
864 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
, data_in_dma
,
866 mpt3sas_base_put_smid_default(ioc
, smid
);
869 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
870 case MPI2_FUNCTION_FW_DOWNLOAD
:
871 case MPI2_FUNCTION_FW_UPLOAD
:
873 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
, data_in_dma
,
875 mpt3sas_base_put_smid_default(ioc
, smid
);
878 case MPI2_FUNCTION_TOOLBOX
:
880 Mpi2ToolboxCleanRequest_t
*toolbox_request
=
881 (Mpi2ToolboxCleanRequest_t
*)mpi_request
;
883 if (toolbox_request
->Tool
== MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL
) {
884 ioc
->build_sg(ioc
, psge
, data_out_dma
, data_out_sz
,
885 data_in_dma
, data_in_sz
);
887 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
888 data_in_dma
, data_in_sz
);
890 mpt3sas_base_put_smid_default(ioc
, smid
);
893 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
895 Mpi2SasIoUnitControlRequest_t
*sasiounit_request
=
896 (Mpi2SasIoUnitControlRequest_t
*)mpi_request
;
898 if (sasiounit_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
899 || sasiounit_request
->Operation
==
900 MPI2_SAS_OP_PHY_LINK_RESET
) {
901 ioc
->ioc_link_reset_in_progress
= 1;
902 ioc
->ignore_loginfos
= 1;
904 /* drop to default case for posting the request */
907 ioc
->build_sg_mpi(ioc
, psge
, data_out_dma
, data_out_sz
,
908 data_in_dma
, data_in_sz
);
909 mpt3sas_base_put_smid_default(ioc
, smid
);
913 if (karg
.timeout
< MPT3_IOCTL_DEFAULT_TIMEOUT
)
914 timeout
= MPT3_IOCTL_DEFAULT_TIMEOUT
;
916 timeout
= karg
.timeout
;
917 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
919 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
920 Mpi2SCSITaskManagementRequest_t
*tm_request
=
921 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
922 mpt3sas_scsih_clear_tm_flag(ioc
, le16_to_cpu(
923 tm_request
->DevHandle
));
924 mpt3sas_trigger_master(ioc
, MASTER_TRIGGER_TASK_MANAGMENT
);
925 } else if ((mpi_request
->Function
== MPI2_FUNCTION_SMP_PASSTHROUGH
||
926 mpi_request
->Function
== MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
) &&
927 ioc
->ioc_link_reset_in_progress
) {
928 ioc
->ioc_link_reset_in_progress
= 0;
929 ioc
->ignore_loginfos
= 0;
931 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
932 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
934 _debug_dump_mf(mpi_request
, karg
.data_sge_offset
);
935 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
937 goto issue_host_reset
;
940 mpi_reply
= ioc
->ctl_cmds
.reply
;
941 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
943 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
&&
944 (ioc
->logging_level
& MPT_DEBUG_TM
)) {
945 Mpi2SCSITaskManagementReply_t
*tm_reply
=
946 (Mpi2SCSITaskManagementReply_t
*)mpi_reply
;
948 pr_info(MPT3SAS_FMT
"TASK_MGMT: " \
949 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
950 "TerminationCount(0x%08x)\n", ioc
->name
,
951 le16_to_cpu(tm_reply
->IOCStatus
),
952 le32_to_cpu(tm_reply
->IOCLogInfo
),
953 le32_to_cpu(tm_reply
->TerminationCount
));
956 /* copy out xdata to user */
958 if (copy_to_user(karg
.data_in_buf_ptr
, data_in
,
960 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
967 /* copy out reply message frame to user */
968 if (karg
.max_reply_bytes
) {
969 sz
= min_t(u32
, karg
.max_reply_bytes
, ioc
->reply_sz
);
970 if (copy_to_user(karg
.reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
972 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
979 /* copy out sense to user */
980 if (karg
.max_sense_bytes
&& (mpi_request
->Function
==
981 MPI2_FUNCTION_SCSI_IO_REQUEST
|| mpi_request
->Function
==
982 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
983 sz
= min_t(u32
, karg
.max_sense_bytes
, SCSI_SENSE_BUFFERSIZE
);
984 if (copy_to_user(karg
.sense_data_ptr
, ioc
->ctl_cmds
.sense
,
986 pr_err("failure at %s:%d/%s()!\n", __FILE__
,
996 if ((mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
997 mpi_request
->Function
==
998 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
999 mpi_request
->Function
== MPI2_FUNCTION_SATA_PASSTHROUGH
)) {
1000 pr_info(MPT3SAS_FMT
"issue target reset: handle = (0x%04x)\n",
1002 le16_to_cpu(mpi_request
->FunctionDependent1
));
1003 mpt3sas_halt_firmware(ioc
);
1004 mpt3sas_scsih_issue_tm(ioc
,
1005 le16_to_cpu(mpi_request
->FunctionDependent1
), 0, 0,
1006 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 30,
1009 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1015 /* free memory associated with sg buffers */
1017 pci_free_consistent(ioc
->pdev
, data_in_sz
, data_in
,
1021 pci_free_consistent(ioc
->pdev
, data_out_sz
, data_out
,
1025 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1030 * _ctl_getiocinfo - main handler for MPT3IOCINFO opcode
1031 * @ioc: per adapter object
1032 * @arg - user space buffer containing ioctl content
1035 _ctl_getiocinfo(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1037 struct mpt3_ioctl_iocinfo karg
;
1039 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1040 pr_err("failure at %s:%d/%s()!\n",
1041 __FILE__
, __LINE__
, __func__
);
1045 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1048 memset(&karg
, 0 , sizeof(karg
));
1050 karg
.port_number
= ioc
->pfacts
[0].PortNumber
;
1051 karg
.hw_rev
= ioc
->pdev
->revision
;
1052 karg
.pci_id
= ioc
->pdev
->device
;
1053 karg
.subsystem_device
= ioc
->pdev
->subsystem_device
;
1054 karg
.subsystem_vendor
= ioc
->pdev
->subsystem_vendor
;
1055 karg
.pci_information
.u
.bits
.bus
= ioc
->pdev
->bus
->number
;
1056 karg
.pci_information
.u
.bits
.device
= PCI_SLOT(ioc
->pdev
->devfn
);
1057 karg
.pci_information
.u
.bits
.function
= PCI_FUNC(ioc
->pdev
->devfn
);
1058 karg
.pci_information
.segment_id
= pci_domain_nr(ioc
->pdev
->bus
);
1059 karg
.firmware_version
= ioc
->facts
.FWVersion
.Word
;
1060 strcpy(karg
.driver_version
, ioc
->driver_name
);
1061 strcat(karg
.driver_version
, "-");
1062 switch (ioc
->hba_mpi_version_belonged
) {
1064 if (ioc
->is_warpdrive
)
1065 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2_SSS6200
;
1067 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2
;
1068 strcat(karg
.driver_version
, MPT2SAS_DRIVER_VERSION
);
1072 karg
.adapter_type
= MPT3_IOCTL_INTERFACE_SAS3
;
1073 strcat(karg
.driver_version
, MPT3SAS_DRIVER_VERSION
);
1076 karg
.bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
1078 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1079 pr_err("failure at %s:%d/%s()!\n",
1080 __FILE__
, __LINE__
, __func__
);
1087 * _ctl_eventquery - main handler for MPT3EVENTQUERY opcode
1088 * @ioc: per adapter object
1089 * @arg - user space buffer containing ioctl content
1092 _ctl_eventquery(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1094 struct mpt3_ioctl_eventquery karg
;
1096 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1097 pr_err("failure at %s:%d/%s()!\n",
1098 __FILE__
, __LINE__
, __func__
);
1102 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1105 karg
.event_entries
= MPT3SAS_CTL_EVENT_LOG_SIZE
;
1106 memcpy(karg
.event_types
, ioc
->event_type
,
1107 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1109 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1110 pr_err("failure at %s:%d/%s()!\n",
1111 __FILE__
, __LINE__
, __func__
);
1118 * _ctl_eventenable - main handler for MPT3EVENTENABLE opcode
1119 * @ioc: per adapter object
1120 * @arg - user space buffer containing ioctl content
1123 _ctl_eventenable(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1125 struct mpt3_ioctl_eventenable karg
;
1127 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1128 pr_err("failure at %s:%d/%s()!\n",
1129 __FILE__
, __LINE__
, __func__
);
1133 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1136 memcpy(ioc
->event_type
, karg
.event_types
,
1137 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1138 mpt3sas_base_validate_event_type(ioc
, ioc
->event_type
);
1142 /* initialize event_log */
1143 ioc
->event_context
= 0;
1144 ioc
->aen_event_read_flag
= 0;
1145 ioc
->event_log
= kcalloc(MPT3SAS_CTL_EVENT_LOG_SIZE
,
1146 sizeof(struct MPT3_IOCTL_EVENTS
), GFP_KERNEL
);
1147 if (!ioc
->event_log
) {
1148 pr_err("failure at %s:%d/%s()!\n",
1149 __FILE__
, __LINE__
, __func__
);
1156 * _ctl_eventreport - main handler for MPT3EVENTREPORT opcode
1157 * @ioc: per adapter object
1158 * @arg - user space buffer containing ioctl content
1161 _ctl_eventreport(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1163 struct mpt3_ioctl_eventreport karg
;
1164 u32 number_bytes
, max_events
, max
;
1165 struct mpt3_ioctl_eventreport __user
*uarg
= arg
;
1167 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1168 pr_err("failure at %s:%d/%s()!\n",
1169 __FILE__
, __LINE__
, __func__
);
1173 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1176 number_bytes
= karg
.hdr
.max_data_size
-
1177 sizeof(struct mpt3_ioctl_header
);
1178 max_events
= number_bytes
/sizeof(struct MPT3_IOCTL_EVENTS
);
1179 max
= min_t(u32
, MPT3SAS_CTL_EVENT_LOG_SIZE
, max_events
);
1181 /* If fewer than 1 event is requested, there must have
1182 * been some type of error.
1184 if (!max
|| !ioc
->event_log
)
1187 number_bytes
= max
* sizeof(struct MPT3_IOCTL_EVENTS
);
1188 if (copy_to_user(uarg
->event_data
, ioc
->event_log
, number_bytes
)) {
1189 pr_err("failure at %s:%d/%s()!\n",
1190 __FILE__
, __LINE__
, __func__
);
1194 /* reset flag so SIGIO can restart */
1195 ioc
->aen_event_read_flag
= 0;
1200 * _ctl_do_reset - main handler for MPT3HARDRESET opcode
1201 * @ioc: per adapter object
1202 * @arg - user space buffer containing ioctl content
1205 _ctl_do_reset(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1207 struct mpt3_ioctl_diag_reset karg
;
1210 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1211 pr_err("failure at %s:%d/%s()!\n",
1212 __FILE__
, __LINE__
, __func__
);
1216 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
1217 ioc
->is_driver_loading
)
1220 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: enter\n", ioc
->name
,
1223 retval
= mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1225 pr_info(MPT3SAS_FMT
"host reset: %s\n",
1226 ioc
->name
, ((!retval
) ? "SUCCESS" : "FAILED"));
1231 * _ctl_btdh_search_sas_device - searching for sas device
1232 * @ioc: per adapter object
1233 * @btdh: btdh ioctl payload
1236 _ctl_btdh_search_sas_device(struct MPT3SAS_ADAPTER
*ioc
,
1237 struct mpt3_ioctl_btdh_mapping
*btdh
)
1239 struct _sas_device
*sas_device
;
1240 unsigned long flags
;
1243 if (list_empty(&ioc
->sas_device_list
))
1246 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1247 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
1248 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1249 btdh
->handle
== sas_device
->handle
) {
1250 btdh
->bus
= sas_device
->channel
;
1251 btdh
->id
= sas_device
->id
;
1254 } else if (btdh
->bus
== sas_device
->channel
&& btdh
->id
==
1255 sas_device
->id
&& btdh
->handle
== 0xFFFF) {
1256 btdh
->handle
= sas_device
->handle
;
1262 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1267 * _ctl_btdh_search_raid_device - searching for raid device
1268 * @ioc: per adapter object
1269 * @btdh: btdh ioctl payload
1272 _ctl_btdh_search_raid_device(struct MPT3SAS_ADAPTER
*ioc
,
1273 struct mpt3_ioctl_btdh_mapping
*btdh
)
1275 struct _raid_device
*raid_device
;
1276 unsigned long flags
;
1279 if (list_empty(&ioc
->raid_device_list
))
1282 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1283 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1284 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1285 btdh
->handle
== raid_device
->handle
) {
1286 btdh
->bus
= raid_device
->channel
;
1287 btdh
->id
= raid_device
->id
;
1290 } else if (btdh
->bus
== raid_device
->channel
&& btdh
->id
==
1291 raid_device
->id
&& btdh
->handle
== 0xFFFF) {
1292 btdh
->handle
= raid_device
->handle
;
1298 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1303 * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode
1304 * @ioc: per adapter object
1305 * @arg - user space buffer containing ioctl content
1308 _ctl_btdh_mapping(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1310 struct mpt3_ioctl_btdh_mapping karg
;
1313 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1314 pr_err("failure at %s:%d/%s()!\n",
1315 __FILE__
, __LINE__
, __func__
);
1319 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1322 rc
= _ctl_btdh_search_sas_device(ioc
, &karg
);
1324 _ctl_btdh_search_raid_device(ioc
, &karg
);
1326 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1327 pr_err("failure at %s:%d/%s()!\n",
1328 __FILE__
, __LINE__
, __func__
);
1335 * _ctl_diag_capability - return diag buffer capability
1336 * @ioc: per adapter object
1337 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1339 * returns 1 when diag buffer support is enabled in firmware
1342 _ctl_diag_capability(struct MPT3SAS_ADAPTER
*ioc
, u8 buffer_type
)
1346 switch (buffer_type
) {
1347 case MPI2_DIAG_BUF_TYPE_TRACE
:
1348 if (ioc
->facts
.IOCCapabilities
&
1349 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
)
1352 case MPI2_DIAG_BUF_TYPE_SNAPSHOT
:
1353 if (ioc
->facts
.IOCCapabilities
&
1354 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
)
1357 case MPI2_DIAG_BUF_TYPE_EXTENDED
:
1358 if (ioc
->facts
.IOCCapabilities
&
1359 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
)
1368 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1369 * @ioc: per adapter object
1370 * @diag_register: the diag_register struct passed in from user space
1374 _ctl_diag_register_2(struct MPT3SAS_ADAPTER
*ioc
,
1375 struct mpt3_diag_register
*diag_register
)
1378 void *request_data
= NULL
;
1379 dma_addr_t request_data_dma
;
1380 u32 request_data_sz
= 0;
1381 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1382 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1384 unsigned long timeleft
;
1390 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1393 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1394 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1396 "%s: failed due to ioc not operational\n",
1397 ioc
->name
, __func__
);
1402 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1403 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
1404 ioc
->name
, __func__
);
1409 buffer_type
= diag_register
->buffer_type
;
1410 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1412 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1413 ioc
->name
, __func__
, buffer_type
);
1417 if (ioc
->diag_buffer_status
[buffer_type
] &
1418 MPT3_DIAG_BUFFER_IS_REGISTERED
) {
1420 "%s: already has a registered buffer for buffer_type(0x%02x)\n",
1421 ioc
->name
, __func__
,
1426 if (diag_register
->requested_buffer_size
% 4) {
1428 "%s: the requested_buffer_size is not 4 byte aligned\n",
1429 ioc
->name
, __func__
);
1433 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1435 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
1436 ioc
->name
, __func__
);
1442 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
1443 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1444 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1445 ioc
->ctl_cmds
.smid
= smid
;
1447 request_data
= ioc
->diag_buffer
[buffer_type
];
1448 request_data_sz
= diag_register
->requested_buffer_size
;
1449 ioc
->unique_id
[buffer_type
] = diag_register
->unique_id
;
1450 ioc
->diag_buffer_status
[buffer_type
] = 0;
1451 memcpy(ioc
->product_specific
[buffer_type
],
1452 diag_register
->product_specific
, MPT3_PRODUCT_SPECIFIC_DWORDS
);
1453 ioc
->diagnostic_flags
[buffer_type
] = diag_register
->diagnostic_flags
;
1456 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1457 if (request_data_sz
!= ioc
->diag_buffer_sz
[buffer_type
]) {
1458 pci_free_consistent(ioc
->pdev
,
1459 ioc
->diag_buffer_sz
[buffer_type
],
1460 request_data
, request_data_dma
);
1461 request_data
= NULL
;
1465 if (request_data
== NULL
) {
1466 ioc
->diag_buffer_sz
[buffer_type
] = 0;
1467 ioc
->diag_buffer_dma
[buffer_type
] = 0;
1468 request_data
= pci_alloc_consistent(
1469 ioc
->pdev
, request_data_sz
, &request_data_dma
);
1470 if (request_data
== NULL
) {
1471 pr_err(MPT3SAS_FMT
"%s: failed allocating memory" \
1472 " for diag buffers, requested size(%d)\n",
1473 ioc
->name
, __func__
, request_data_sz
);
1474 mpt3sas_base_free_smid(ioc
, smid
);
1477 ioc
->diag_buffer
[buffer_type
] = request_data
;
1478 ioc
->diag_buffer_sz
[buffer_type
] = request_data_sz
;
1479 ioc
->diag_buffer_dma
[buffer_type
] = request_data_dma
;
1482 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1483 mpi_request
->BufferType
= diag_register
->buffer_type
;
1484 mpi_request
->Flags
= cpu_to_le32(diag_register
->diagnostic_flags
);
1485 mpi_request
->BufferAddress
= cpu_to_le64(request_data_dma
);
1486 mpi_request
->BufferLength
= cpu_to_le32(request_data_sz
);
1487 mpi_request
->VF_ID
= 0; /* TODO */
1488 mpi_request
->VP_ID
= 0;
1490 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
1491 "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n",
1492 ioc
->name
, __func__
, request_data
,
1493 (unsigned long long)request_data_dma
,
1494 le32_to_cpu(mpi_request
->BufferLength
)));
1496 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
1497 mpi_request
->ProductSpecific
[i
] =
1498 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1500 init_completion(&ioc
->ctl_cmds
.done
);
1501 mpt3sas_base_put_smid_default(ioc
, smid
);
1502 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1503 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1505 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1506 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
1508 _debug_dump_mf(mpi_request
,
1509 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
1510 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
1512 goto issue_host_reset
;
1515 /* process the completed Reply Message Frame */
1516 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
1517 pr_err(MPT3SAS_FMT
"%s: no reply message\n",
1518 ioc
->name
, __func__
);
1523 mpi_reply
= ioc
->ctl_cmds
.reply
;
1524 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1526 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1527 ioc
->diag_buffer_status
[buffer_type
] |=
1528 MPT3_DIAG_BUFFER_IS_REGISTERED
;
1529 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: success\n",
1530 ioc
->name
, __func__
));
1533 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1534 ioc
->name
, __func__
,
1535 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
1541 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1546 if (rc
&& request_data
)
1547 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1548 request_data
, request_data_dma
);
1550 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1555 * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time
1556 * @ioc: per adapter object
1557 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1559 * This is called when command line option diag_buffer_enable is enabled
1560 * at driver load time.
1563 mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER
*ioc
, u8 bits_to_register
)
1565 struct mpt3_diag_register diag_register
;
1567 memset(&diag_register
, 0, sizeof(struct mpt3_diag_register
));
1569 if (bits_to_register
& 1) {
1570 pr_info(MPT3SAS_FMT
"registering trace buffer support\n",
1572 ioc
->diag_trigger_master
.MasterData
=
1573 (MASTER_TRIGGER_FW_FAULT
+ MASTER_TRIGGER_ADAPTER_RESET
);
1574 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
1575 /* register for 2MB buffers */
1576 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1577 diag_register
.unique_id
= 0x7075900;
1578 _ctl_diag_register_2(ioc
, &diag_register
);
1581 if (bits_to_register
& 2) {
1582 pr_info(MPT3SAS_FMT
"registering snapshot buffer support\n",
1584 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_SNAPSHOT
;
1585 /* register for 2MB buffers */
1586 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1587 diag_register
.unique_id
= 0x7075901;
1588 _ctl_diag_register_2(ioc
, &diag_register
);
1591 if (bits_to_register
& 4) {
1592 pr_info(MPT3SAS_FMT
"registering extended buffer support\n",
1594 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_EXTENDED
;
1595 /* register for 2MB buffers */
1596 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1597 diag_register
.unique_id
= 0x7075901;
1598 _ctl_diag_register_2(ioc
, &diag_register
);
1603 * _ctl_diag_register - application register with driver
1604 * @ioc: per adapter object
1605 * @arg - user space buffer containing ioctl content
1607 * This will allow the driver to setup any required buffers that will be
1608 * needed by firmware to communicate with the driver.
1611 _ctl_diag_register(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1613 struct mpt3_diag_register karg
;
1616 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1617 pr_err("failure at %s:%d/%s()!\n",
1618 __FILE__
, __LINE__
, __func__
);
1622 rc
= _ctl_diag_register_2(ioc
, &karg
);
1627 * _ctl_diag_unregister - application unregister with driver
1628 * @ioc: per adapter object
1629 * @arg - user space buffer containing ioctl content
1631 * This will allow the driver to cleanup any memory allocated for diag
1632 * messages and to free up any resources.
1635 _ctl_diag_unregister(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1637 struct mpt3_diag_unregister karg
;
1639 dma_addr_t request_data_dma
;
1640 u32 request_data_sz
;
1643 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1644 pr_err("failure at %s:%d/%s()!\n",
1645 __FILE__
, __LINE__
, __func__
);
1649 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1652 buffer_type
= karg
.unique_id
& 0x000000ff;
1653 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1655 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1656 ioc
->name
, __func__
, buffer_type
);
1660 if ((ioc
->diag_buffer_status
[buffer_type
] &
1661 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1663 "%s: buffer_type(0x%02x) is not registered\n",
1664 ioc
->name
, __func__
, buffer_type
);
1667 if ((ioc
->diag_buffer_status
[buffer_type
] &
1668 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0) {
1670 "%s: buffer_type(0x%02x) has not been released\n",
1671 ioc
->name
, __func__
, buffer_type
);
1675 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1677 "%s: unique_id(0x%08x) is not registered\n",
1678 ioc
->name
, __func__
, karg
.unique_id
);
1682 request_data
= ioc
->diag_buffer
[buffer_type
];
1683 if (!request_data
) {
1685 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1686 ioc
->name
, __func__
, buffer_type
);
1690 request_data_sz
= ioc
->diag_buffer_sz
[buffer_type
];
1691 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1692 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1693 request_data
, request_data_dma
);
1694 ioc
->diag_buffer
[buffer_type
] = NULL
;
1695 ioc
->diag_buffer_status
[buffer_type
] = 0;
1700 * _ctl_diag_query - query relevant info associated with diag buffers
1701 * @ioc: per adapter object
1702 * @arg - user space buffer containing ioctl content
1704 * The application will send only buffer_type and unique_id. Driver will
1705 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1706 * 0x00, the driver will return info specified by Buffer Type.
1709 _ctl_diag_query(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1711 struct mpt3_diag_query karg
;
1716 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1717 pr_err("failure at %s:%d/%s()!\n",
1718 __FILE__
, __LINE__
, __func__
);
1722 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1725 karg
.application_flags
= 0;
1726 buffer_type
= karg
.buffer_type
;
1728 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1730 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1731 ioc
->name
, __func__
, buffer_type
);
1735 if ((ioc
->diag_buffer_status
[buffer_type
] &
1736 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1738 "%s: buffer_type(0x%02x) is not registered\n",
1739 ioc
->name
, __func__
, buffer_type
);
1743 if (karg
.unique_id
& 0xffffff00) {
1744 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1746 "%s: unique_id(0x%08x) is not registered\n",
1747 ioc
->name
, __func__
, karg
.unique_id
);
1752 request_data
= ioc
->diag_buffer
[buffer_type
];
1753 if (!request_data
) {
1755 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
1756 ioc
->name
, __func__
, buffer_type
);
1760 if (ioc
->diag_buffer_status
[buffer_type
] & MPT3_DIAG_BUFFER_IS_RELEASED
)
1761 karg
.application_flags
= (MPT3_APP_FLAGS_APP_OWNED
|
1762 MPT3_APP_FLAGS_BUFFER_VALID
);
1764 karg
.application_flags
= (MPT3_APP_FLAGS_APP_OWNED
|
1765 MPT3_APP_FLAGS_BUFFER_VALID
|
1766 MPT3_APP_FLAGS_FW_BUFFER_ACCESS
);
1768 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
1769 karg
.product_specific
[i
] =
1770 ioc
->product_specific
[buffer_type
][i
];
1772 karg
.total_buffer_size
= ioc
->diag_buffer_sz
[buffer_type
];
1773 karg
.driver_added_buffer_size
= 0;
1774 karg
.unique_id
= ioc
->unique_id
[buffer_type
];
1775 karg
.diagnostic_flags
= ioc
->diagnostic_flags
[buffer_type
];
1777 if (copy_to_user(arg
, &karg
, sizeof(struct mpt3_diag_query
))) {
1779 "%s: unable to write mpt3_diag_query data @ %p\n",
1780 ioc
->name
, __func__
, arg
);
1787 * mpt3sas_send_diag_release - Diag Release Message
1788 * @ioc: per adapter object
1789 * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
1790 * @issue_reset - specifies whether host reset is required.
1794 mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER
*ioc
, u8 buffer_type
,
1797 Mpi2DiagReleaseRequest_t
*mpi_request
;
1798 Mpi2DiagReleaseReply_t
*mpi_reply
;
1803 unsigned long timeleft
;
1805 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1811 ioc_state
= mpt3sas_base_get_iocstate(ioc
, 1);
1812 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1813 if (ioc
->diag_buffer_status
[buffer_type
] &
1814 MPT3_DIAG_BUFFER_IS_REGISTERED
)
1815 ioc
->diag_buffer_status
[buffer_type
] |=
1816 MPT3_DIAG_BUFFER_IS_RELEASED
;
1817 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
1818 "%s: skipping due to FAULT state\n", ioc
->name
,
1824 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
1825 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
1826 ioc
->name
, __func__
);
1831 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1833 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
1834 ioc
->name
, __func__
);
1839 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
1840 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1841 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
1842 ioc
->ctl_cmds
.smid
= smid
;
1844 mpi_request
->Function
= MPI2_FUNCTION_DIAG_RELEASE
;
1845 mpi_request
->BufferType
= buffer_type
;
1846 mpi_request
->VF_ID
= 0; /* TODO */
1847 mpi_request
->VP_ID
= 0;
1849 init_completion(&ioc
->ctl_cmds
.done
);
1850 mpt3sas_base_put_smid_default(ioc
, smid
);
1851 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1852 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1854 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
1855 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
1857 _debug_dump_mf(mpi_request
,
1858 sizeof(Mpi2DiagReleaseRequest_t
)/4);
1859 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
1865 /* process the completed Reply Message Frame */
1866 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
1867 pr_err(MPT3SAS_FMT
"%s: no reply message\n",
1868 ioc
->name
, __func__
);
1873 mpi_reply
= ioc
->ctl_cmds
.reply
;
1874 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1876 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1877 ioc
->diag_buffer_status
[buffer_type
] |=
1878 MPT3_DIAG_BUFFER_IS_RELEASED
;
1879 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: success\n",
1880 ioc
->name
, __func__
));
1883 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
1884 ioc
->name
, __func__
,
1885 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
1890 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
1895 * _ctl_diag_release - request to send Diag Release Message to firmware
1896 * @arg - user space buffer containing ioctl content
1898 * This allows ownership of the specified buffer to returned to the driver,
1899 * allowing an application to read the buffer without fear that firmware is
1900 * overwritting information in the buffer.
1903 _ctl_diag_release(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1905 struct mpt3_diag_release karg
;
1911 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1912 pr_err("failure at %s:%d/%s()!\n",
1913 __FILE__
, __LINE__
, __func__
);
1917 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
1920 buffer_type
= karg
.unique_id
& 0x000000ff;
1921 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1923 "%s: doesn't have capability for buffer_type(0x%02x)\n",
1924 ioc
->name
, __func__
, buffer_type
);
1928 if ((ioc
->diag_buffer_status
[buffer_type
] &
1929 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1931 "%s: buffer_type(0x%02x) is not registered\n",
1932 ioc
->name
, __func__
, buffer_type
);
1936 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1938 "%s: unique_id(0x%08x) is not registered\n",
1939 ioc
->name
, __func__
, karg
.unique_id
);
1943 if (ioc
->diag_buffer_status
[buffer_type
] &
1944 MPT3_DIAG_BUFFER_IS_RELEASED
) {
1946 "%s: buffer_type(0x%02x) is already released\n",
1947 ioc
->name
, __func__
,
1952 request_data
= ioc
->diag_buffer
[buffer_type
];
1954 if (!request_data
) {
1956 "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
1957 ioc
->name
, __func__
, buffer_type
);
1961 /* buffers were released by due to host reset */
1962 if ((ioc
->diag_buffer_status
[buffer_type
] &
1963 MPT3_DIAG_BUFFER_IS_DIAG_RESET
)) {
1964 ioc
->diag_buffer_status
[buffer_type
] |=
1965 MPT3_DIAG_BUFFER_IS_RELEASED
;
1966 ioc
->diag_buffer_status
[buffer_type
] &=
1967 ~MPT3_DIAG_BUFFER_IS_DIAG_RESET
;
1969 "%s: buffer_type(0x%02x) was released due to host reset\n",
1970 ioc
->name
, __func__
, buffer_type
);
1974 rc
= mpt3sas_send_diag_release(ioc
, buffer_type
, &issue_reset
);
1977 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1984 * _ctl_diag_read_buffer - request for copy of the diag buffer
1985 * @ioc: per adapter object
1986 * @arg - user space buffer containing ioctl content
1989 _ctl_diag_read_buffer(struct MPT3SAS_ADAPTER
*ioc
, void __user
*arg
)
1991 struct mpt3_diag_read_buffer karg
;
1992 struct mpt3_diag_read_buffer __user
*uarg
= arg
;
1993 void *request_data
, *diag_data
;
1994 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1995 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1998 unsigned long timeleft
, request_size
, copy_size
;
2003 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2004 pr_err("failure at %s:%d/%s()!\n",
2005 __FILE__
, __LINE__
, __func__
);
2009 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s\n", ioc
->name
,
2012 buffer_type
= karg
.unique_id
& 0x000000ff;
2013 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
2015 "%s: doesn't have capability for buffer_type(0x%02x)\n",
2016 ioc
->name
, __func__
, buffer_type
);
2020 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
2022 "%s: unique_id(0x%08x) is not registered\n",
2023 ioc
->name
, __func__
, karg
.unique_id
);
2027 request_data
= ioc
->diag_buffer
[buffer_type
];
2028 if (!request_data
) {
2030 "%s: doesn't have buffer for buffer_type(0x%02x)\n",
2031 ioc
->name
, __func__
, buffer_type
);
2035 request_size
= ioc
->diag_buffer_sz
[buffer_type
];
2037 if ((karg
.starting_offset
% 4) || (karg
.bytes_to_read
% 4)) {
2038 pr_err(MPT3SAS_FMT
"%s: either the starting_offset " \
2039 "or bytes_to_read are not 4 byte aligned\n", ioc
->name
,
2044 if (karg
.starting_offset
> request_size
)
2047 diag_data
= (void *)(request_data
+ karg
.starting_offset
);
2048 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2049 "%s: diag_buffer(%p), offset(%d), sz(%d)\n",
2050 ioc
->name
, __func__
,
2051 diag_data
, karg
.starting_offset
, karg
.bytes_to_read
));
2053 /* Truncate data on requests that are too large */
2054 if ((diag_data
+ karg
.bytes_to_read
< diag_data
) ||
2055 (diag_data
+ karg
.bytes_to_read
> request_data
+ request_size
))
2056 copy_size
= request_size
- karg
.starting_offset
;
2058 copy_size
= karg
.bytes_to_read
;
2060 if (copy_to_user((void __user
*)uarg
->diagnostic_data
,
2061 diag_data
, copy_size
)) {
2063 "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
2064 ioc
->name
, __func__
, diag_data
);
2068 if ((karg
.flags
& MPT3_FLAGS_REREGISTER
) == 0)
2071 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2072 "%s: Reregister buffer_type(0x%02x)\n",
2073 ioc
->name
, __func__
, buffer_type
));
2074 if ((ioc
->diag_buffer_status
[buffer_type
] &
2075 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0) {
2076 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2077 "%s: buffer_type(0x%02x) is still registered\n",
2078 ioc
->name
, __func__
, buffer_type
));
2081 /* Get a free request frame and save the message context.
2084 if (ioc
->ctl_cmds
.status
!= MPT3_CMD_NOT_USED
) {
2085 pr_err(MPT3SAS_FMT
"%s: ctl_cmd in use\n",
2086 ioc
->name
, __func__
);
2091 smid
= mpt3sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
2093 pr_err(MPT3SAS_FMT
"%s: failed obtaining a smid\n",
2094 ioc
->name
, __func__
);
2100 ioc
->ctl_cmds
.status
= MPT3_CMD_PENDING
;
2101 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
2102 mpi_request
= mpt3sas_base_get_msg_frame(ioc
, smid
);
2103 ioc
->ctl_cmds
.smid
= smid
;
2105 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
2106 mpi_request
->BufferType
= buffer_type
;
2107 mpi_request
->BufferLength
=
2108 cpu_to_le32(ioc
->diag_buffer_sz
[buffer_type
]);
2109 mpi_request
->BufferAddress
=
2110 cpu_to_le64(ioc
->diag_buffer_dma
[buffer_type
]);
2111 for (i
= 0; i
< MPT3_PRODUCT_SPECIFIC_DWORDS
; i
++)
2112 mpi_request
->ProductSpecific
[i
] =
2113 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
2114 mpi_request
->VF_ID
= 0; /* TODO */
2115 mpi_request
->VP_ID
= 0;
2117 init_completion(&ioc
->ctl_cmds
.done
);
2118 mpt3sas_base_put_smid_default(ioc
, smid
);
2119 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
2120 MPT3_IOCTL_DEFAULT_TIMEOUT
*HZ
);
2122 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_COMPLETE
)) {
2123 pr_err(MPT3SAS_FMT
"%s: timeout\n", ioc
->name
,
2125 _debug_dump_mf(mpi_request
,
2126 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
2127 if (!(ioc
->ctl_cmds
.status
& MPT3_CMD_RESET
))
2129 goto issue_host_reset
;
2132 /* process the completed Reply Message Frame */
2133 if ((ioc
->ctl_cmds
.status
& MPT3_CMD_REPLY_VALID
) == 0) {
2134 pr_err(MPT3SAS_FMT
"%s: no reply message\n",
2135 ioc
->name
, __func__
);
2140 mpi_reply
= ioc
->ctl_cmds
.reply
;
2141 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2143 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
2144 ioc
->diag_buffer_status
[buffer_type
] |=
2145 MPT3_DIAG_BUFFER_IS_REGISTERED
;
2146 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
"%s: success\n",
2147 ioc
->name
, __func__
));
2150 "%s: ioc_status(0x%04x) log_info(0x%08x)\n",
2151 ioc
->name
, __func__
,
2152 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
2158 mpt3sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2163 ioc
->ctl_cmds
.status
= MPT3_CMD_NOT_USED
;
2169 #ifdef CONFIG_COMPAT
2171 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2172 * @ioc: per adapter object
2173 * @cmd - ioctl opcode
2174 * @arg - (struct mpt3_ioctl_command32)
2176 * MPT3COMMAND32 - Handle 32bit applications running on 64bit os.
2179 _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER
*ioc
, unsigned cmd
,
2182 struct mpt3_ioctl_command32 karg32
;
2183 struct mpt3_ioctl_command32 __user
*uarg
;
2184 struct mpt3_ioctl_command karg
;
2186 if (_IOC_SIZE(cmd
) != sizeof(struct mpt3_ioctl_command32
))
2189 uarg
= (struct mpt3_ioctl_command32 __user
*) arg
;
2191 if (copy_from_user(&karg32
, (char __user
*)arg
, sizeof(karg32
))) {
2192 pr_err("failure at %s:%d/%s()!\n",
2193 __FILE__
, __LINE__
, __func__
);
2197 memset(&karg
, 0, sizeof(struct mpt3_ioctl_command
));
2198 karg
.hdr
.ioc_number
= karg32
.hdr
.ioc_number
;
2199 karg
.hdr
.port_number
= karg32
.hdr
.port_number
;
2200 karg
.hdr
.max_data_size
= karg32
.hdr
.max_data_size
;
2201 karg
.timeout
= karg32
.timeout
;
2202 karg
.max_reply_bytes
= karg32
.max_reply_bytes
;
2203 karg
.data_in_size
= karg32
.data_in_size
;
2204 karg
.data_out_size
= karg32
.data_out_size
;
2205 karg
.max_sense_bytes
= karg32
.max_sense_bytes
;
2206 karg
.data_sge_offset
= karg32
.data_sge_offset
;
2207 karg
.reply_frame_buf_ptr
= compat_ptr(karg32
.reply_frame_buf_ptr
);
2208 karg
.data_in_buf_ptr
= compat_ptr(karg32
.data_in_buf_ptr
);
2209 karg
.data_out_buf_ptr
= compat_ptr(karg32
.data_out_buf_ptr
);
2210 karg
.sense_data_ptr
= compat_ptr(karg32
.sense_data_ptr
);
2211 return _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2216 * _ctl_ioctl_main - main ioctl entry point
2217 * @file - (struct file)
2218 * @cmd - ioctl opcode
2219 * @arg - user space data buffer
2220 * @compat - handles 32 bit applications in 64bit os
2221 * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device &
2222 * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
2225 _ctl_ioctl_main(struct file
*file
, unsigned int cmd
, void __user
*arg
,
2226 u8 compat
, u16 mpi_version
)
2228 struct MPT3SAS_ADAPTER
*ioc
;
2229 struct mpt3_ioctl_header ioctl_header
;
2230 enum block_state state
;
2233 /* get IOCTL header */
2234 if (copy_from_user(&ioctl_header
, (char __user
*)arg
,
2235 sizeof(struct mpt3_ioctl_header
))) {
2236 pr_err("failure at %s:%d/%s()!\n",
2237 __FILE__
, __LINE__
, __func__
);
2241 if (_ctl_verify_adapter(ioctl_header
.ioc_number
,
2242 &ioc
, mpi_version
) == -1 || !ioc
)
2245 /* pci_access_mutex lock acquired by ioctl path */
2246 mutex_lock(&ioc
->pci_access_mutex
);
2248 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
2249 ioc
->is_driver_loading
|| ioc
->remove_host
) {
2251 goto out_unlock_pciaccess
;
2254 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
: BLOCKING
;
2255 if (state
== NON_BLOCKING
) {
2256 if (!mutex_trylock(&ioc
->ctl_cmds
.mutex
)) {
2258 goto out_unlock_pciaccess
;
2260 } else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
)) {
2262 goto out_unlock_pciaccess
;
2268 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_iocinfo
))
2269 ret
= _ctl_getiocinfo(ioc
, arg
);
2271 #ifdef CONFIG_COMPAT
2276 struct mpt3_ioctl_command __user
*uarg
;
2277 struct mpt3_ioctl_command karg
;
2279 #ifdef CONFIG_COMPAT
2281 ret
= _ctl_compat_mpt_command(ioc
, cmd
, arg
);
2285 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2286 pr_err("failure at %s:%d/%s()!\n",
2287 __FILE__
, __LINE__
, __func__
);
2292 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_command
)) {
2294 ret
= _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2298 case MPT3EVENTQUERY
:
2299 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_eventquery
))
2300 ret
= _ctl_eventquery(ioc
, arg
);
2302 case MPT3EVENTENABLE
:
2303 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_eventenable
))
2304 ret
= _ctl_eventenable(ioc
, arg
);
2306 case MPT3EVENTREPORT
:
2307 ret
= _ctl_eventreport(ioc
, arg
);
2310 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_diag_reset
))
2311 ret
= _ctl_do_reset(ioc
, arg
);
2313 case MPT3BTDHMAPPING
:
2314 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_ioctl_btdh_mapping
))
2315 ret
= _ctl_btdh_mapping(ioc
, arg
);
2317 case MPT3DIAGREGISTER
:
2318 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_register
))
2319 ret
= _ctl_diag_register(ioc
, arg
);
2321 case MPT3DIAGUNREGISTER
:
2322 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_unregister
))
2323 ret
= _ctl_diag_unregister(ioc
, arg
);
2326 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_query
))
2327 ret
= _ctl_diag_query(ioc
, arg
);
2329 case MPT3DIAGRELEASE
:
2330 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_release
))
2331 ret
= _ctl_diag_release(ioc
, arg
);
2333 case MPT3DIAGREADBUFFER
:
2334 if (_IOC_SIZE(cmd
) == sizeof(struct mpt3_diag_read_buffer
))
2335 ret
= _ctl_diag_read_buffer(ioc
, arg
);
2338 dctlprintk(ioc
, pr_info(MPT3SAS_FMT
2339 "unsupported ioctl opcode(0x%08x)\n", ioc
->name
, cmd
));
2343 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
2344 out_unlock_pciaccess
:
2345 mutex_unlock(&ioc
->pci_access_mutex
);
2350 * _ctl_ioctl - mpt3ctl main ioctl entry point (unlocked)
2351 * @file - (struct file)
2352 * @cmd - ioctl opcode
2356 _ctl_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2360 /* pass MPI25_VERSION | MPI26_VERSION value,
2361 * to indicate that this ioctl cmd
2362 * came from mpt3ctl ioctl device.
2364 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 0,
2365 MPI25_VERSION
| MPI26_VERSION
);
2370 * _ctl_mpt2_ioctl - mpt2ctl main ioctl entry point (unlocked)
2371 * @file - (struct file)
2372 * @cmd - ioctl opcode
2376 _ctl_mpt2_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2380 /* pass MPI2_VERSION value, to indicate that this ioctl cmd
2381 * came from mpt2ctl ioctl device.
2383 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 0, MPI2_VERSION
);
2386 #ifdef CONFIG_COMPAT
2388 *_ ctl_ioctl_compat - main ioctl entry point (compat)
2393 * This routine handles 32 bit applications in 64bit os.
2396 _ctl_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2400 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 1,
2401 MPI25_VERSION
| MPI26_VERSION
);
2406 *_ ctl_mpt2_ioctl_compat - main ioctl entry point (compat)
2411 * This routine handles 32 bit applications in 64bit os.
2414 _ctl_mpt2_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2418 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 1, MPI2_VERSION
);
2423 /* scsi host attributes */
2425 * _ctl_version_fw_show - firmware version
2426 * @cdev - pointer to embedded class device
2427 * @buf - the buffer returned
2429 * A sysfs 'read-only' shost attribute.
2432 _ctl_version_fw_show(struct device
*cdev
, struct device_attribute
*attr
,
2435 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2436 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2438 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2439 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2440 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2441 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2442 ioc
->facts
.FWVersion
.Word
& 0x000000FF);
2444 static DEVICE_ATTR(version_fw
, S_IRUGO
, _ctl_version_fw_show
, NULL
);
2447 * _ctl_version_bios_show - bios version
2448 * @cdev - pointer to embedded class device
2449 * @buf - the buffer returned
2451 * A sysfs 'read-only' shost attribute.
2454 _ctl_version_bios_show(struct device
*cdev
, struct device_attribute
*attr
,
2457 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2458 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2460 u32 version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2462 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2463 (version
& 0xFF000000) >> 24,
2464 (version
& 0x00FF0000) >> 16,
2465 (version
& 0x0000FF00) >> 8,
2466 version
& 0x000000FF);
2468 static DEVICE_ATTR(version_bios
, S_IRUGO
, _ctl_version_bios_show
, NULL
);
2471 * _ctl_version_mpi_show - MPI (message passing interface) version
2472 * @cdev - pointer to embedded class device
2473 * @buf - the buffer returned
2475 * A sysfs 'read-only' shost attribute.
2478 _ctl_version_mpi_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
, PAGE_SIZE
, "%03x.%02x\n",
2485 ioc
->facts
.MsgVersion
, ioc
->facts
.HeaderVersion
>> 8);
2487 static DEVICE_ATTR(version_mpi
, S_IRUGO
, _ctl_version_mpi_show
, NULL
);
2490 * _ctl_version_product_show - product name
2491 * @cdev - pointer to embedded class device
2492 * @buf - the buffer returned
2494 * A sysfs 'read-only' shost attribute.
2497 _ctl_version_product_show(struct device
*cdev
, struct device_attribute
*attr
,
2500 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2501 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2503 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.ChipName
);
2505 static DEVICE_ATTR(version_product
, S_IRUGO
, _ctl_version_product_show
, NULL
);
2508 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2509 * @cdev - pointer to embedded class device
2510 * @buf - the buffer returned
2512 * A sysfs 'read-only' shost attribute.
2515 _ctl_version_nvdata_persistent_show(struct device
*cdev
,
2516 struct device_attribute
*attr
, char *buf
)
2518 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2519 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2521 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2522 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionPersistent
.Word
));
2524 static DEVICE_ATTR(version_nvdata_persistent
, S_IRUGO
,
2525 _ctl_version_nvdata_persistent_show
, NULL
);
2528 * _ctl_version_nvdata_default_show - nvdata default version
2529 * @cdev - pointer to embedded class device
2530 * @buf - the buffer returned
2532 * A sysfs 'read-only' shost attribute.
2535 _ctl_version_nvdata_default_show(struct device
*cdev
, struct device_attribute
2538 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2539 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2541 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2542 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionDefault
.Word
));
2544 static DEVICE_ATTR(version_nvdata_default
, S_IRUGO
,
2545 _ctl_version_nvdata_default_show
, NULL
);
2548 * _ctl_board_name_show - board name
2549 * @cdev - pointer to embedded class device
2550 * @buf - the buffer returned
2552 * A sysfs 'read-only' shost attribute.
2555 _ctl_board_name_show(struct device
*cdev
, struct device_attribute
*attr
,
2558 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2559 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2561 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardName
);
2563 static DEVICE_ATTR(board_name
, S_IRUGO
, _ctl_board_name_show
, NULL
);
2566 * _ctl_board_assembly_show - board assembly name
2567 * @cdev - pointer to embedded class device
2568 * @buf - the buffer returned
2570 * A sysfs 'read-only' shost attribute.
2573 _ctl_board_assembly_show(struct device
*cdev
, struct device_attribute
*attr
,
2576 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2577 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2579 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardAssembly
);
2581 static DEVICE_ATTR(board_assembly
, S_IRUGO
, _ctl_board_assembly_show
, NULL
);
2584 * _ctl_board_tracer_show - board tracer number
2585 * @cdev - pointer to embedded class device
2586 * @buf - the buffer returned
2588 * A sysfs 'read-only' shost attribute.
2591 _ctl_board_tracer_show(struct device
*cdev
, struct device_attribute
*attr
,
2594 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2595 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2597 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardTracerNumber
);
2599 static DEVICE_ATTR(board_tracer
, S_IRUGO
, _ctl_board_tracer_show
, NULL
);
2602 * _ctl_io_delay_show - io missing delay
2603 * @cdev - pointer to embedded class device
2604 * @buf - the buffer returned
2606 * This is for firmware implemention for deboucing device
2609 * A sysfs 'read-only' shost attribute.
2612 _ctl_io_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2615 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2616 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2618 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->io_missing_delay
);
2620 static DEVICE_ATTR(io_delay
, S_IRUGO
, _ctl_io_delay_show
, NULL
);
2623 * _ctl_device_delay_show - device missing delay
2624 * @cdev - pointer to embedded class device
2625 * @buf - the buffer returned
2627 * This is for firmware implemention for deboucing device
2630 * A sysfs 'read-only' shost attribute.
2633 _ctl_device_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2636 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2637 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2639 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->device_missing_delay
);
2641 static DEVICE_ATTR(device_delay
, S_IRUGO
, _ctl_device_delay_show
, NULL
);
2644 * _ctl_fw_queue_depth_show - global credits
2645 * @cdev - pointer to embedded class device
2646 * @buf - the buffer returned
2648 * This is firmware queue depth limit
2650 * A sysfs 'read-only' shost attribute.
2653 _ctl_fw_queue_depth_show(struct device
*cdev
, struct device_attribute
*attr
,
2656 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2657 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2659 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->facts
.RequestCredit
);
2661 static DEVICE_ATTR(fw_queue_depth
, S_IRUGO
, _ctl_fw_queue_depth_show
, NULL
);
2664 * _ctl_sas_address_show - sas address
2665 * @cdev - pointer to embedded class device
2666 * @buf - the buffer returned
2668 * This is the controller sas address
2670 * A sysfs 'read-only' shost attribute.
2673 _ctl_host_sas_address_show(struct device
*cdev
, struct device_attribute
*attr
,
2677 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2678 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2680 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
2681 (unsigned long long)ioc
->sas_hba
.sas_address
);
2683 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
2684 _ctl_host_sas_address_show
, NULL
);
2687 * _ctl_logging_level_show - logging level
2688 * @cdev - pointer to embedded class device
2689 * @buf - the buffer returned
2691 * A sysfs 'read/write' shost attribute.
2694 _ctl_logging_level_show(struct device
*cdev
, struct device_attribute
*attr
,
2697 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2698 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2700 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", ioc
->logging_level
);
2703 _ctl_logging_level_store(struct device
*cdev
, struct device_attribute
*attr
,
2704 const char *buf
, size_t count
)
2706 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2707 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2710 if (sscanf(buf
, "%x", &val
) != 1)
2713 ioc
->logging_level
= val
;
2714 pr_info(MPT3SAS_FMT
"logging_level=%08xh\n", ioc
->name
,
2715 ioc
->logging_level
);
2718 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
, _ctl_logging_level_show
,
2719 _ctl_logging_level_store
);
2722 * _ctl_fwfault_debug_show - show/store fwfault_debug
2723 * @cdev - pointer to embedded class device
2724 * @buf - the buffer returned
2726 * mpt3sas_fwfault_debug is command line option
2727 * A sysfs 'read/write' shost attribute.
2730 _ctl_fwfault_debug_show(struct device
*cdev
, struct device_attribute
*attr
,
2733 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2734 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2736 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->fwfault_debug
);
2739 _ctl_fwfault_debug_store(struct device
*cdev
, struct device_attribute
*attr
,
2740 const char *buf
, size_t count
)
2742 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2743 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2746 if (sscanf(buf
, "%d", &val
) != 1)
2749 ioc
->fwfault_debug
= val
;
2750 pr_info(MPT3SAS_FMT
"fwfault_debug=%d\n", ioc
->name
,
2751 ioc
->fwfault_debug
);
2754 static DEVICE_ATTR(fwfault_debug
, S_IRUGO
| S_IWUSR
,
2755 _ctl_fwfault_debug_show
, _ctl_fwfault_debug_store
);
2758 * _ctl_ioc_reset_count_show - ioc reset count
2759 * @cdev - pointer to embedded class device
2760 * @buf - the buffer returned
2762 * This is firmware queue depth limit
2764 * A sysfs 'read-only' shost attribute.
2767 _ctl_ioc_reset_count_show(struct device
*cdev
, struct device_attribute
*attr
,
2770 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2771 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2773 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->ioc_reset_count
);
2775 static DEVICE_ATTR(ioc_reset_count
, S_IRUGO
, _ctl_ioc_reset_count_show
, NULL
);
2778 * _ctl_ioc_reply_queue_count_show - number of reply queues
2779 * @cdev - pointer to embedded class device
2780 * @buf - the buffer returned
2782 * This is number of reply queues
2784 * A sysfs 'read-only' shost attribute.
2787 _ctl_ioc_reply_queue_count_show(struct device
*cdev
,
2788 struct device_attribute
*attr
, char *buf
)
2790 u8 reply_queue_count
;
2791 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2792 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2794 if ((ioc
->facts
.IOCCapabilities
&
2795 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
)
2796 reply_queue_count
= ioc
->reply_queue_count
;
2798 reply_queue_count
= 1;
2800 return snprintf(buf
, PAGE_SIZE
, "%d\n", reply_queue_count
);
2802 static DEVICE_ATTR(reply_queue_count
, S_IRUGO
, _ctl_ioc_reply_queue_count_show
,
2806 * _ctl_BRM_status_show - Backup Rail Monitor Status
2807 * @cdev - pointer to embedded class device
2808 * @buf - the buffer returned
2810 * This is number of reply queues
2812 * A sysfs 'read-only' shost attribute.
2815 _ctl_BRM_status_show(struct device
*cdev
, struct device_attribute
*attr
,
2818 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2819 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2820 Mpi2IOUnitPage3_t
*io_unit_pg3
= NULL
;
2821 Mpi2ConfigReply_t mpi_reply
;
2822 u16 backup_rail_monitor_status
= 0;
2827 if (!ioc
->is_warpdrive
) {
2828 pr_err(MPT3SAS_FMT
"%s: BRM attribute is only for"
2829 " warpdrive\n", ioc
->name
, __func__
);
2832 /* pci_access_mutex lock acquired by sysfs show path */
2833 mutex_lock(&ioc
->pci_access_mutex
);
2834 if (ioc
->pci_error_recovery
|| ioc
->remove_host
) {
2835 mutex_unlock(&ioc
->pci_access_mutex
);
2839 /* allocate upto GPIOVal 36 entries */
2840 sz
= offsetof(Mpi2IOUnitPage3_t
, GPIOVal
) + (sizeof(u16
) * 36);
2841 io_unit_pg3
= kzalloc(sz
, GFP_KERNEL
);
2843 pr_err(MPT3SAS_FMT
"%s: failed allocating memory "
2844 "for iounit_pg3: (%d) bytes\n", ioc
->name
, __func__
, sz
);
2848 if (mpt3sas_config_get_iounit_pg3(ioc
, &mpi_reply
, io_unit_pg3
, sz
) !=
2851 "%s: failed reading iounit_pg3\n", ioc
->name
,
2856 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2857 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2858 pr_err(MPT3SAS_FMT
"%s: iounit_pg3 failed with "
2859 "ioc_status(0x%04x)\n", ioc
->name
, __func__
, ioc_status
);
2863 if (io_unit_pg3
->GPIOCount
< 25) {
2864 pr_err(MPT3SAS_FMT
"%s: iounit_pg3->GPIOCount less than "
2865 "25 entries, detected (%d) entries\n", ioc
->name
, __func__
,
2866 io_unit_pg3
->GPIOCount
);
2870 /* BRM status is in bit zero of GPIOVal[24] */
2871 backup_rail_monitor_status
= le16_to_cpu(io_unit_pg3
->GPIOVal
[24]);
2872 rc
= snprintf(buf
, PAGE_SIZE
, "%d\n", (backup_rail_monitor_status
& 1));
2876 mutex_unlock(&ioc
->pci_access_mutex
);
2879 static DEVICE_ATTR(BRM_status
, S_IRUGO
, _ctl_BRM_status_show
, NULL
);
2881 struct DIAG_BUFFER_START
{
2892 * _ctl_host_trace_buffer_size_show - host buffer size (trace only)
2893 * @cdev - pointer to embedded class device
2894 * @buf - the buffer returned
2896 * A sysfs 'read-only' shost attribute.
2899 _ctl_host_trace_buffer_size_show(struct device
*cdev
,
2900 struct device_attribute
*attr
, char *buf
)
2902 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2903 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2905 struct DIAG_BUFFER_START
*request_data
;
2907 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
2909 "%s: host_trace_buffer is not registered\n",
2910 ioc
->name
, __func__
);
2914 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2915 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2917 "%s: host_trace_buffer is not registered\n",
2918 ioc
->name
, __func__
);
2922 request_data
= (struct DIAG_BUFFER_START
*)
2923 ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
];
2924 if ((le32_to_cpu(request_data
->DiagVersion
) == 0x00000000 ||
2925 le32_to_cpu(request_data
->DiagVersion
) == 0x01000000 ||
2926 le32_to_cpu(request_data
->DiagVersion
) == 0x01010000) &&
2927 le32_to_cpu(request_data
->Reserved3
) == 0x4742444c)
2928 size
= le32_to_cpu(request_data
->Size
);
2930 ioc
->ring_buffer_sz
= size
;
2931 return snprintf(buf
, PAGE_SIZE
, "%d\n", size
);
2933 static DEVICE_ATTR(host_trace_buffer_size
, S_IRUGO
,
2934 _ctl_host_trace_buffer_size_show
, NULL
);
2937 * _ctl_host_trace_buffer_show - firmware ring buffer (trace only)
2938 * @cdev - pointer to embedded class device
2939 * @buf - the buffer returned
2941 * A sysfs 'read/write' shost attribute.
2943 * You will only be able to read 4k bytes of ring buffer at a time.
2944 * In order to read beyond 4k bytes, you will have to write out the
2945 * offset to the same attribute, it will move the pointer.
2948 _ctl_host_trace_buffer_show(struct device
*cdev
, struct device_attribute
*attr
,
2951 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2952 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2956 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
2958 "%s: host_trace_buffer is not registered\n",
2959 ioc
->name
, __func__
);
2963 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2964 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2966 "%s: host_trace_buffer is not registered\n",
2967 ioc
->name
, __func__
);
2971 if (ioc
->ring_buffer_offset
> ioc
->ring_buffer_sz
)
2974 size
= ioc
->ring_buffer_sz
- ioc
->ring_buffer_offset
;
2975 size
= (size
>= PAGE_SIZE
) ? (PAGE_SIZE
- 1) : size
;
2976 request_data
= ioc
->diag_buffer
[0] + ioc
->ring_buffer_offset
;
2977 memcpy(buf
, request_data
, size
);
2982 _ctl_host_trace_buffer_store(struct device
*cdev
, struct device_attribute
*attr
,
2983 const char *buf
, size_t count
)
2985 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2986 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
2989 if (sscanf(buf
, "%d", &val
) != 1)
2992 ioc
->ring_buffer_offset
= val
;
2995 static DEVICE_ATTR(host_trace_buffer
, S_IRUGO
| S_IWUSR
,
2996 _ctl_host_trace_buffer_show
, _ctl_host_trace_buffer_store
);
2999 /*****************************************/
3002 * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only)
3003 * @cdev - pointer to embedded class device
3004 * @buf - the buffer returned
3006 * A sysfs 'read/write' shost attribute.
3008 * This is a mechnism to post/release host_trace_buffers
3011 _ctl_host_trace_buffer_enable_show(struct device
*cdev
,
3012 struct device_attribute
*attr
, char *buf
)
3014 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3015 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3017 if ((!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) ||
3018 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3019 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0))
3020 return snprintf(buf
, PAGE_SIZE
, "off\n");
3021 else if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3022 MPT3_DIAG_BUFFER_IS_RELEASED
))
3023 return snprintf(buf
, PAGE_SIZE
, "release\n");
3025 return snprintf(buf
, PAGE_SIZE
, "post\n");
3029 _ctl_host_trace_buffer_enable_store(struct device
*cdev
,
3030 struct device_attribute
*attr
, const char *buf
, size_t count
)
3032 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3033 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3035 struct mpt3_diag_register diag_register
;
3038 /* don't allow post/release occurr while recovery is active */
3039 if (ioc
->shost_recovery
|| ioc
->remove_host
||
3040 ioc
->pci_error_recovery
|| ioc
->is_driver_loading
)
3043 if (sscanf(buf
, "%9s", str
) != 1)
3046 if (!strcmp(str
, "post")) {
3047 /* exit out if host buffers are already posted */
3048 if ((ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) &&
3049 (ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3050 MPT3_DIAG_BUFFER_IS_REGISTERED
) &&
3051 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3052 MPT3_DIAG_BUFFER_IS_RELEASED
) == 0))
3054 memset(&diag_register
, 0, sizeof(struct mpt3_diag_register
));
3055 pr_info(MPT3SAS_FMT
"posting host trace buffers\n",
3057 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
3058 diag_register
.requested_buffer_size
= (1024 * 1024);
3059 diag_register
.unique_id
= 0x7075900;
3060 ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] = 0;
3061 _ctl_diag_register_2(ioc
, &diag_register
);
3062 } else if (!strcmp(str
, "release")) {
3063 /* exit out if host buffers are already released */
3064 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
])
3066 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3067 MPT3_DIAG_BUFFER_IS_REGISTERED
) == 0)
3069 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
3070 MPT3_DIAG_BUFFER_IS_RELEASED
))
3072 pr_info(MPT3SAS_FMT
"releasing host trace buffer\n",
3074 mpt3sas_send_diag_release(ioc
, MPI2_DIAG_BUF_TYPE_TRACE
,
3081 static DEVICE_ATTR(host_trace_buffer_enable
, S_IRUGO
| S_IWUSR
,
3082 _ctl_host_trace_buffer_enable_show
,
3083 _ctl_host_trace_buffer_enable_store
);
3085 /*********** diagnostic trigger suppport *********************************/
3088 * _ctl_diag_trigger_master_show - show the diag_trigger_master attribute
3089 * @cdev - pointer to embedded class device
3090 * @buf - the buffer returned
3092 * A sysfs 'read/write' shost attribute.
3095 _ctl_diag_trigger_master_show(struct device
*cdev
,
3096 struct device_attribute
*attr
, char *buf
)
3099 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3100 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3101 unsigned long flags
;
3104 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3105 rc
= sizeof(struct SL_WH_MASTER_TRIGGER_T
);
3106 memcpy(buf
, &ioc
->diag_trigger_master
, rc
);
3107 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3112 * _ctl_diag_trigger_master_store - store the diag_trigger_master attribute
3113 * @cdev - pointer to embedded class device
3114 * @buf - the buffer returned
3116 * A sysfs 'read/write' shost attribute.
3119 _ctl_diag_trigger_master_store(struct device
*cdev
,
3120 struct device_attribute
*attr
, const char *buf
, size_t count
)
3123 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3124 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3125 unsigned long flags
;
3128 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3129 rc
= min(sizeof(struct SL_WH_MASTER_TRIGGER_T
), count
);
3130 memset(&ioc
->diag_trigger_master
, 0,
3131 sizeof(struct SL_WH_MASTER_TRIGGER_T
));
3132 memcpy(&ioc
->diag_trigger_master
, buf
, rc
);
3133 ioc
->diag_trigger_master
.MasterData
|=
3134 (MASTER_TRIGGER_FW_FAULT
+ MASTER_TRIGGER_ADAPTER_RESET
);
3135 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3138 static DEVICE_ATTR(diag_trigger_master
, S_IRUGO
| S_IWUSR
,
3139 _ctl_diag_trigger_master_show
, _ctl_diag_trigger_master_store
);
3143 * _ctl_diag_trigger_event_show - show the diag_trigger_event attribute
3144 * @cdev - pointer to embedded class device
3145 * @buf - the buffer returned
3147 * A sysfs 'read/write' shost attribute.
3150 _ctl_diag_trigger_event_show(struct device
*cdev
,
3151 struct device_attribute
*attr
, char *buf
)
3153 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3154 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3155 unsigned long flags
;
3158 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3159 rc
= sizeof(struct SL_WH_EVENT_TRIGGERS_T
);
3160 memcpy(buf
, &ioc
->diag_trigger_event
, rc
);
3161 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3166 * _ctl_diag_trigger_event_store - store the diag_trigger_event attribute
3167 * @cdev - pointer to embedded class device
3168 * @buf - the buffer returned
3170 * A sysfs 'read/write' shost attribute.
3173 _ctl_diag_trigger_event_store(struct device
*cdev
,
3174 struct device_attribute
*attr
, const char *buf
, size_t count
)
3177 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3178 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3179 unsigned long flags
;
3182 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3183 sz
= min(sizeof(struct SL_WH_EVENT_TRIGGERS_T
), count
);
3184 memset(&ioc
->diag_trigger_event
, 0,
3185 sizeof(struct SL_WH_EVENT_TRIGGERS_T
));
3186 memcpy(&ioc
->diag_trigger_event
, buf
, sz
);
3187 if (ioc
->diag_trigger_event
.ValidEntries
> NUM_VALID_ENTRIES
)
3188 ioc
->diag_trigger_event
.ValidEntries
= NUM_VALID_ENTRIES
;
3189 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3192 static DEVICE_ATTR(diag_trigger_event
, S_IRUGO
| S_IWUSR
,
3193 _ctl_diag_trigger_event_show
, _ctl_diag_trigger_event_store
);
3197 * _ctl_diag_trigger_scsi_show - show the diag_trigger_scsi attribute
3198 * @cdev - pointer to embedded class device
3199 * @buf - the buffer returned
3201 * A sysfs 'read/write' shost attribute.
3204 _ctl_diag_trigger_scsi_show(struct device
*cdev
,
3205 struct device_attribute
*attr
, char *buf
)
3207 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3208 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3209 unsigned long flags
;
3212 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3213 rc
= sizeof(struct SL_WH_SCSI_TRIGGERS_T
);
3214 memcpy(buf
, &ioc
->diag_trigger_scsi
, rc
);
3215 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3220 * _ctl_diag_trigger_scsi_store - store the diag_trigger_scsi attribute
3221 * @cdev - pointer to embedded class device
3222 * @buf - the buffer returned
3224 * A sysfs 'read/write' shost attribute.
3227 _ctl_diag_trigger_scsi_store(struct device
*cdev
,
3228 struct device_attribute
*attr
, const char *buf
, size_t count
)
3230 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3231 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3232 unsigned long flags
;
3235 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3236 sz
= min(sizeof(struct SL_WH_SCSI_TRIGGERS_T
), count
);
3237 memset(&ioc
->diag_trigger_scsi
, 0,
3238 sizeof(struct SL_WH_EVENT_TRIGGERS_T
));
3239 memcpy(&ioc
->diag_trigger_scsi
, buf
, sz
);
3240 if (ioc
->diag_trigger_scsi
.ValidEntries
> NUM_VALID_ENTRIES
)
3241 ioc
->diag_trigger_scsi
.ValidEntries
= NUM_VALID_ENTRIES
;
3242 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3245 static DEVICE_ATTR(diag_trigger_scsi
, S_IRUGO
| S_IWUSR
,
3246 _ctl_diag_trigger_scsi_show
, _ctl_diag_trigger_scsi_store
);
3250 * _ctl_diag_trigger_scsi_show - show the diag_trigger_mpi attribute
3251 * @cdev - pointer to embedded class device
3252 * @buf - the buffer returned
3254 * A sysfs 'read/write' shost attribute.
3257 _ctl_diag_trigger_mpi_show(struct device
*cdev
,
3258 struct device_attribute
*attr
, char *buf
)
3260 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3261 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3262 unsigned long flags
;
3265 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3266 rc
= sizeof(struct SL_WH_MPI_TRIGGERS_T
);
3267 memcpy(buf
, &ioc
->diag_trigger_mpi
, rc
);
3268 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3273 * _ctl_diag_trigger_mpi_store - store the diag_trigger_mpi attribute
3274 * @cdev - pointer to embedded class device
3275 * @buf - the buffer returned
3277 * A sysfs 'read/write' shost attribute.
3280 _ctl_diag_trigger_mpi_store(struct device
*cdev
,
3281 struct device_attribute
*attr
, const char *buf
, size_t count
)
3283 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3284 struct MPT3SAS_ADAPTER
*ioc
= shost_priv(shost
);
3285 unsigned long flags
;
3288 spin_lock_irqsave(&ioc
->diag_trigger_lock
, flags
);
3289 sz
= min(sizeof(struct SL_WH_MPI_TRIGGERS_T
), count
);
3290 memset(&ioc
->diag_trigger_mpi
, 0,
3291 sizeof(ioc
->diag_trigger_mpi
));
3292 memcpy(&ioc
->diag_trigger_mpi
, buf
, sz
);
3293 if (ioc
->diag_trigger_mpi
.ValidEntries
> NUM_VALID_ENTRIES
)
3294 ioc
->diag_trigger_mpi
.ValidEntries
= NUM_VALID_ENTRIES
;
3295 spin_unlock_irqrestore(&ioc
->diag_trigger_lock
, flags
);
3299 static DEVICE_ATTR(diag_trigger_mpi
, S_IRUGO
| S_IWUSR
,
3300 _ctl_diag_trigger_mpi_show
, _ctl_diag_trigger_mpi_store
);
3302 /*********** diagnostic trigger suppport *** END ****************************/
3306 /*****************************************/
3308 struct device_attribute
*mpt3sas_host_attrs
[] = {
3309 &dev_attr_version_fw
,
3310 &dev_attr_version_bios
,
3311 &dev_attr_version_mpi
,
3312 &dev_attr_version_product
,
3313 &dev_attr_version_nvdata_persistent
,
3314 &dev_attr_version_nvdata_default
,
3315 &dev_attr_board_name
,
3316 &dev_attr_board_assembly
,
3317 &dev_attr_board_tracer
,
3319 &dev_attr_device_delay
,
3320 &dev_attr_logging_level
,
3321 &dev_attr_fwfault_debug
,
3322 &dev_attr_fw_queue_depth
,
3323 &dev_attr_host_sas_address
,
3324 &dev_attr_ioc_reset_count
,
3325 &dev_attr_host_trace_buffer_size
,
3326 &dev_attr_host_trace_buffer
,
3327 &dev_attr_host_trace_buffer_enable
,
3328 &dev_attr_reply_queue_count
,
3329 &dev_attr_diag_trigger_master
,
3330 &dev_attr_diag_trigger_event
,
3331 &dev_attr_diag_trigger_scsi
,
3332 &dev_attr_diag_trigger_mpi
,
3333 &dev_attr_BRM_status
,
3337 /* device attributes */
3340 * _ctl_device_sas_address_show - sas address
3341 * @cdev - pointer to embedded class device
3342 * @buf - the buffer returned
3344 * This is the sas address for the target
3346 * A sysfs 'read-only' shost attribute.
3349 _ctl_device_sas_address_show(struct device
*dev
, struct device_attribute
*attr
,
3352 struct scsi_device
*sdev
= to_scsi_device(dev
);
3353 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
3355 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
3356 (unsigned long long)sas_device_priv_data
->sas_target
->sas_address
);
3358 static DEVICE_ATTR(sas_address
, S_IRUGO
, _ctl_device_sas_address_show
, NULL
);
3361 * _ctl_device_handle_show - device handle
3362 * @cdev - pointer to embedded class device
3363 * @buf - the buffer returned
3365 * This is the firmware assigned device handle
3367 * A sysfs 'read-only' shost attribute.
3370 _ctl_device_handle_show(struct device
*dev
, struct device_attribute
*attr
,
3373 struct scsi_device
*sdev
= to_scsi_device(dev
);
3374 struct MPT3SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
3376 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n",
3377 sas_device_priv_data
->sas_target
->handle
);
3379 static DEVICE_ATTR(sas_device_handle
, S_IRUGO
, _ctl_device_handle_show
, NULL
);
3381 struct device_attribute
*mpt3sas_dev_attrs
[] = {
3382 &dev_attr_sas_address
,
3383 &dev_attr_sas_device_handle
,
3387 /* file operations table for mpt3ctl device */
3388 static const struct file_operations ctl_fops
= {
3389 .owner
= THIS_MODULE
,
3390 .unlocked_ioctl
= _ctl_ioctl
,
3392 .fasync
= _ctl_fasync
,
3393 #ifdef CONFIG_COMPAT
3394 .compat_ioctl
= _ctl_ioctl_compat
,
3398 /* file operations table for mpt2ctl device */
3399 static const struct file_operations ctl_gen2_fops
= {
3400 .owner
= THIS_MODULE
,
3401 .unlocked_ioctl
= _ctl_mpt2_ioctl
,
3403 .fasync
= _ctl_fasync
,
3404 #ifdef CONFIG_COMPAT
3405 .compat_ioctl
= _ctl_mpt2_ioctl_compat
,
3409 static struct miscdevice ctl_dev
= {
3410 .minor
= MPT3SAS_MINOR
,
3411 .name
= MPT3SAS_DEV_NAME
,
3415 static struct miscdevice gen2_ctl_dev
= {
3416 .minor
= MPT2SAS_MINOR
,
3417 .name
= MPT2SAS_DEV_NAME
,
3418 .fops
= &ctl_gen2_fops
,
3422 * mpt3sas_ctl_init - main entry point for ctl.
3426 mpt3sas_ctl_init(ushort hbas_to_enumerate
)
3430 /* Don't register mpt3ctl ioctl device if
3431 * hbas_to_enumarate is one.
3433 if (hbas_to_enumerate
!= 1)
3434 if (misc_register(&ctl_dev
) < 0)
3435 pr_err("%s can't register misc device [minor=%d]\n",
3436 MPT3SAS_DRIVER_NAME
, MPT3SAS_MINOR
);
3438 /* Don't register mpt3ctl ioctl device if
3439 * hbas_to_enumarate is two.
3441 if (hbas_to_enumerate
!= 2)
3442 if (misc_register(&gen2_ctl_dev
) < 0)
3443 pr_err("%s can't register misc device [minor=%d]\n",
3444 MPT2SAS_DRIVER_NAME
, MPT2SAS_MINOR
);
3446 init_waitqueue_head(&ctl_poll_wait
);
3450 * mpt3sas_ctl_exit - exit point for ctl
3454 mpt3sas_ctl_exit(ushort hbas_to_enumerate
)
3456 struct MPT3SAS_ADAPTER
*ioc
;
3459 list_for_each_entry(ioc
, &mpt3sas_ioc_list
, list
) {
3461 /* free memory associated to diag buffers */
3462 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
3463 if (!ioc
->diag_buffer
[i
])
3465 if (!(ioc
->diag_buffer_status
[i
] &
3466 MPT3_DIAG_BUFFER_IS_REGISTERED
))
3468 if ((ioc
->diag_buffer_status
[i
] &
3469 MPT3_DIAG_BUFFER_IS_RELEASED
))
3471 pci_free_consistent(ioc
->pdev
, ioc
->diag_buffer_sz
[i
],
3472 ioc
->diag_buffer
[i
], ioc
->diag_buffer_dma
[i
]);
3473 ioc
->diag_buffer
[i
] = NULL
;
3474 ioc
->diag_buffer_status
[i
] = 0;
3477 kfree(ioc
->event_log
);
3479 if (hbas_to_enumerate
!= 1)
3480 misc_deregister(&ctl_dev
);
3481 if (hbas_to_enumerate
!= 2)
3482 misc_deregister(&gen2_ctl_dev
);