2 * Management Module Support for MPT (Message Passing Technology) based
5 * This code is based on drivers/scsi/mpt2sas/mpt2_ctl.c
6 * Copyright (C) 2007-2009 LSI Corporation
7 * (mailto:DL-MPTFusionLinux@lsi.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
45 #include <linux/version.h>
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/smp_lock.h>
55 #include <linux/compat.h>
56 #include <linux/poll.h>
59 #include <linux/uaccess.h>
61 #include "mpt2sas_base.h"
62 #include "mpt2sas_ctl.h"
64 static struct fasync_struct
*async_queue
;
65 static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait
);
67 static int _ctl_send_release(struct MPT2SAS_ADAPTER
*ioc
, u8 buffer_type
,
71 * enum block_state - blocking state
72 * @NON_BLOCKING: non blocking
75 * These states are for ioctls that need to wait for a response
76 * from firmware, so they probably require sleep.
83 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
85 * _ctl_display_some_debug - debug routine
86 * @ioc: per adapter object
87 * @smid: system request message index
88 * @calling_function_name: string pass from calling function
89 * @mpi_reply: reply message frame
92 * Function for displaying debug info helpfull when debugging issues
96 _ctl_display_some_debug(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
97 char *calling_function_name
, MPI2DefaultReply_t
*mpi_reply
)
99 Mpi2ConfigRequest_t
*mpi_request
;
102 if (!(ioc
->logging_level
& MPT_DEBUG_IOCTL
))
105 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
106 switch (mpi_request
->Function
) {
107 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
109 Mpi2SCSIIORequest_t
*scsi_request
=
110 (Mpi2SCSIIORequest_t
*)mpi_request
;
112 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
113 "scsi_io, cmd(0x%02x), cdb_len(%d)",
114 scsi_request
->CDB
.CDB32
[0],
115 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
116 desc
= ioc
->tmp_string
;
119 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
122 case MPI2_FUNCTION_IOC_INIT
:
125 case MPI2_FUNCTION_IOC_FACTS
:
128 case MPI2_FUNCTION_CONFIG
:
130 Mpi2ConfigRequest_t
*config_request
=
131 (Mpi2ConfigRequest_t
*)mpi_request
;
133 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
134 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
135 (config_request
->Header
.PageType
&
136 MPI2_CONFIG_PAGETYPE_MASK
), config_request
->ExtPageType
,
137 config_request
->Header
.PageNumber
);
138 desc
= ioc
->tmp_string
;
141 case MPI2_FUNCTION_PORT_FACTS
:
144 case MPI2_FUNCTION_PORT_ENABLE
:
145 desc
= "port_enable";
147 case MPI2_FUNCTION_EVENT_NOTIFICATION
:
148 desc
= "event_notification";
150 case MPI2_FUNCTION_FW_DOWNLOAD
:
151 desc
= "fw_download";
153 case MPI2_FUNCTION_FW_UPLOAD
:
156 case MPI2_FUNCTION_RAID_ACTION
:
157 desc
= "raid_action";
159 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
161 Mpi2SCSIIORequest_t
*scsi_request
=
162 (Mpi2SCSIIORequest_t
*)mpi_request
;
164 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
165 "raid_pass, cmd(0x%02x), cdb_len(%d)",
166 scsi_request
->CDB
.CDB32
[0],
167 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
168 desc
= ioc
->tmp_string
;
171 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
172 desc
= "sas_iounit_cntl";
174 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
177 case MPI2_FUNCTION_DIAG_BUFFER_POST
:
178 desc
= "diag_buffer_post";
180 case MPI2_FUNCTION_DIAG_RELEASE
:
181 desc
= "diag_release";
183 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
184 desc
= "smp_passthrough";
191 printk(MPT2SAS_DEBUG_FMT
"%s: %s, smid(%d)\n",
192 ioc
->name
, calling_function_name
, desc
, smid
);
197 if (mpi_reply
->IOCStatus
|| mpi_reply
->IOCLogInfo
)
198 printk(MPT2SAS_DEBUG_FMT
199 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
200 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
201 le32_to_cpu(mpi_reply
->IOCLogInfo
));
203 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
204 mpi_request
->Function
==
205 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
206 Mpi2SCSIIOReply_t
*scsi_reply
=
207 (Mpi2SCSIIOReply_t
*)mpi_reply
;
208 if (scsi_reply
->SCSIState
|| scsi_reply
->SCSIStatus
)
209 printk(MPT2SAS_DEBUG_FMT
210 "\tscsi_state(0x%02x), scsi_status"
211 "(0x%02x)\n", ioc
->name
,
212 scsi_reply
->SCSIState
,
213 scsi_reply
->SCSIStatus
);
219 * mpt2sas_ctl_done - ctl module completion routine
220 * @ioc: per adapter object
221 * @smid: system request message index
222 * @msix_index: MSIX table index supplied by the OS
223 * @reply: reply message frame(lower 32bit addr)
226 * The callback handler when using ioc->ctl_cb_idx.
228 * Return 1 meaning mf should be freed from _base_interrupt
229 * 0 means the mf is freed from this function.
232 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
235 MPI2DefaultReply_t
*mpi_reply
;
237 if (ioc
->ctl_cmds
.status
== MPT2_CMD_NOT_USED
)
239 if (ioc
->ctl_cmds
.smid
!= smid
)
241 ioc
->ctl_cmds
.status
|= MPT2_CMD_COMPLETE
;
242 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
244 memcpy(ioc
->ctl_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
245 ioc
->ctl_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
247 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
248 _ctl_display_some_debug(ioc
, smid
, "ctl_done", mpi_reply
);
250 ioc
->ctl_cmds
.status
&= ~MPT2_CMD_PENDING
;
251 complete(&ioc
->ctl_cmds
.done
);
256 * _ctl_check_event_type - determines when an event needs logging
257 * @ioc: per adapter object
258 * @event: firmware event
260 * The bitmask in ioc->event_type[] indicates which events should be
261 * be saved in the driver event_log. This bitmask is set by application.
263 * Returns 1 when event should be captured, or zero means no match.
266 _ctl_check_event_type(struct MPT2SAS_ADAPTER
*ioc
, u16 event
)
271 if (event
>= 128 || !event
|| !ioc
->event_log
)
274 desired_event
= (1 << (event
% 32));
278 return desired_event
& ioc
->event_type
[i
];
282 * mpt2sas_ctl_add_to_event_log - add event
283 * @ioc: per adapter object
284 * @mpi_reply: reply message frame
289 mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER
*ioc
,
290 Mpi2EventNotificationReply_t
*mpi_reply
)
292 struct MPT2_IOCTL_EVENTS
*event_log
;
295 u32 sz
, event_data_sz
;
301 event
= le16_to_cpu(mpi_reply
->Event
);
303 if (_ctl_check_event_type(ioc
, event
)) {
305 /* insert entry into circular event_log */
306 i
= ioc
->event_context
% MPT2SAS_CTL_EVENT_LOG_SIZE
;
307 event_log
= ioc
->event_log
;
308 event_log
[i
].event
= event
;
309 event_log
[i
].context
= ioc
->event_context
++;
311 event_data_sz
= le16_to_cpu(mpi_reply
->EventDataLength
)*4;
312 sz
= min_t(u32
, event_data_sz
, MPT2_EVENT_DATA_SIZE
);
313 memset(event_log
[i
].data
, 0, MPT2_EVENT_DATA_SIZE
);
314 memcpy(event_log
[i
].data
, mpi_reply
->EventData
, sz
);
318 /* This aen_event_read_flag flag is set until the
319 * application has read the event log.
320 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
322 if (event
== MPI2_EVENT_LOG_ENTRY_ADDED
||
323 (send_aen
&& !ioc
->aen_event_read_flag
)) {
324 ioc
->aen_event_read_flag
= 1;
325 wake_up_interruptible(&ctl_poll_wait
);
327 kill_fasync(&async_queue
, SIGIO
, POLL_IN
);
332 * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time)
333 * @ioc: per adapter object
334 * @msix_index: MSIX table index supplied by the OS
335 * @reply: reply message frame(lower 32bit addr)
336 * Context: interrupt.
338 * This function merely adds a new work task into ioc->firmware_event_thread.
339 * The tasks are worked from _firmware_event_work in user context.
341 * Return 1 meaning mf should be freed from _base_interrupt
342 * 0 means the mf is freed from this function.
345 mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
348 Mpi2EventNotificationReply_t
*mpi_reply
;
350 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
351 mpt2sas_ctl_add_to_event_log(ioc
, mpi_reply
);
356 * _ctl_verify_adapter - validates ioc_number passed from application
357 * @ioc: per adapter object
358 * @iocpp: The ioc pointer is returned in this.
360 * Return (-1) means error, else ioc_number.
363 _ctl_verify_adapter(int ioc_number
, struct MPT2SAS_ADAPTER
**iocpp
)
365 struct MPT2SAS_ADAPTER
*ioc
;
367 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
368 if (ioc
->id
!= ioc_number
)
378 * mpt2sas_ctl_reset_handler - reset callback handler (for ctl)
379 * @ioc: per adapter object
380 * @reset_phase: phase
382 * The handler for doing any required cleanup or initialization.
384 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
385 * MPT2_IOC_DONE_RESET
388 mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
393 switch (reset_phase
) {
394 case MPT2_IOC_PRE_RESET
:
395 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
396 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
397 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
398 if (!(ioc
->diag_buffer_status
[i
] &
399 MPT2_DIAG_BUFFER_IS_REGISTERED
))
401 if ((ioc
->diag_buffer_status
[i
] &
402 MPT2_DIAG_BUFFER_IS_RELEASED
))
404 _ctl_send_release(ioc
, i
, &issue_reset
);
407 case MPT2_IOC_AFTER_RESET
:
408 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
409 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
410 if (ioc
->ctl_cmds
.status
& MPT2_CMD_PENDING
) {
411 ioc
->ctl_cmds
.status
|= MPT2_CMD_RESET
;
412 mpt2sas_base_free_smid(ioc
, ioc
->ctl_cmds
.smid
);
413 complete(&ioc
->ctl_cmds
.done
);
416 case MPT2_IOC_DONE_RESET
:
417 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
418 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
420 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
421 if (!(ioc
->diag_buffer_status
[i
] &
422 MPT2_DIAG_BUFFER_IS_REGISTERED
))
424 if ((ioc
->diag_buffer_status
[i
] &
425 MPT2_DIAG_BUFFER_IS_RELEASED
))
427 ioc
->diag_buffer_status
[i
] |=
428 MPT2_DIAG_BUFFER_IS_DIAG_RESET
;
440 * Called when application request fasyn callback handler.
443 _ctl_fasync(int fd
, struct file
*filep
, int mode
)
445 return fasync_helper(fd
, filep
, mode
, &async_queue
);
453 * Called when application releases the fasyn callback handler.
456 _ctl_release(struct inode
*inode
, struct file
*filep
)
458 return fasync_helper(-1, filep
, 0, &async_queue
);
468 _ctl_poll(struct file
*filep
, poll_table
*wait
)
470 struct MPT2SAS_ADAPTER
*ioc
;
472 poll_wait(filep
, &ctl_poll_wait
, wait
);
474 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
475 if (ioc
->aen_event_read_flag
)
476 return POLLIN
| POLLRDNORM
;
482 * _ctl_set_task_mid - assign an active smid to tm request
483 * @ioc: per adapter object
484 * @karg - (struct mpt2_ioctl_command)
485 * @tm_request - pointer to mf from user space
487 * Returns 0 when an smid if found, else fail.
488 * during failure, the reply frame is filled.
491 _ctl_set_task_mid(struct MPT2SAS_ADAPTER
*ioc
, struct mpt2_ioctl_command
*karg
,
492 Mpi2SCSITaskManagementRequest_t
*tm_request
)
497 struct scsi_cmnd
*scmd
;
498 struct MPT2SAS_DEVICE
*priv_data
;
500 Mpi2SCSITaskManagementReply_t
*tm_reply
;
505 if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
507 else if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
)
512 lun
= scsilun_to_int((struct scsi_lun
*)tm_request
->LUN
);
514 handle
= le16_to_cpu(tm_request
->DevHandle
);
515 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
516 for (i
= ioc
->scsiio_depth
; i
&& !found
; i
--) {
517 scmd
= ioc
->scsi_lookup
[i
- 1].scmd
;
518 if (scmd
== NULL
|| scmd
->device
== NULL
||
519 scmd
->device
->hostdata
== NULL
)
521 if (lun
!= scmd
->device
->lun
)
523 priv_data
= scmd
->device
->hostdata
;
524 if (priv_data
->sas_target
== NULL
)
526 if (priv_data
->sas_target
->handle
!= handle
)
528 tm_request
->TaskMID
= cpu_to_le16(ioc
->scsi_lookup
[i
- 1].smid
);
531 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
534 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
535 "handle(0x%04x), lun(%d), no active mid!!\n", ioc
->name
,
536 desc
, tm_request
->DevHandle
, lun
));
537 tm_reply
= ioc
->ctl_cmds
.reply
;
538 tm_reply
->DevHandle
= tm_request
->DevHandle
;
539 tm_reply
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
540 tm_reply
->TaskType
= tm_request
->TaskType
;
541 tm_reply
->MsgLength
= sizeof(Mpi2SCSITaskManagementReply_t
)/4;
542 tm_reply
->VP_ID
= tm_request
->VP_ID
;
543 tm_reply
->VF_ID
= tm_request
->VF_ID
;
544 sz
= min_t(u32
, karg
->max_reply_bytes
, ioc
->reply_sz
);
545 if (copy_to_user(karg
->reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
547 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
552 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
553 "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc
->name
,
554 desc
, tm_request
->DevHandle
, lun
, tm_request
->TaskMID
));
559 * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode
560 * @ioc: per adapter object
561 * @karg - (struct mpt2_ioctl_command)
562 * @mf - pointer to mf in user space
563 * @state - NON_BLOCKING or BLOCKING
566 _ctl_do_mpt_command(struct MPT2SAS_ADAPTER
*ioc
,
567 struct mpt2_ioctl_command karg
, void __user
*mf
, enum block_state state
)
569 MPI2RequestHeader_t
*mpi_request
;
570 MPI2DefaultReply_t
*mpi_reply
;
574 unsigned long timeout
, timeleft
;
578 void *priv_sense
= NULL
;
579 void *data_out
= NULL
;
580 dma_addr_t data_out_dma
;
581 size_t data_out_sz
= 0;
582 void *data_in
= NULL
;
583 dma_addr_t data_in_dma
;
584 size_t data_in_sz
= 0;
587 u16 wait_state_count
;
591 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
593 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
596 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
597 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
598 ioc
->name
, __func__
);
603 wait_state_count
= 0;
604 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
605 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
606 if (wait_state_count
++ == 10) {
607 printk(MPT2SAS_ERR_FMT
608 "%s: failed due to ioc not operational\n",
609 ioc
->name
, __func__
);
614 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
615 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
616 "operational state(count=%d)\n", ioc
->name
,
617 __func__
, wait_state_count
);
619 if (wait_state_count
)
620 printk(MPT2SAS_INFO_FMT
"%s: ioc is operational\n",
621 ioc
->name
, __func__
);
623 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->ctl_cb_idx
, NULL
);
625 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
626 ioc
->name
, __func__
);
632 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
633 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
634 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
635 ioc
->ctl_cmds
.smid
= smid
;
636 data_out_sz
= karg
.data_out_size
;
637 data_in_sz
= karg
.data_in_size
;
639 /* copy in request message frame from user */
640 if (copy_from_user(mpi_request
, mf
, karg
.data_sge_offset
*4)) {
641 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
, __LINE__
,
644 mpt2sas_base_free_smid(ioc
, smid
);
648 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
649 mpi_request
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
650 if (!mpi_request
->FunctionDependent1
||
651 mpi_request
->FunctionDependent1
>
652 cpu_to_le16(ioc
->facts
.MaxDevHandle
)) {
654 mpt2sas_base_free_smid(ioc
, smid
);
659 /* obtain dma-able memory for data transfer */
660 if (data_out_sz
) /* WRITE */ {
661 data_out
= pci_alloc_consistent(ioc
->pdev
, data_out_sz
,
664 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
667 mpt2sas_base_free_smid(ioc
, smid
);
670 if (copy_from_user(data_out
, karg
.data_out_buf_ptr
,
672 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
675 mpt2sas_base_free_smid(ioc
, smid
);
680 if (data_in_sz
) /* READ */ {
681 data_in
= pci_alloc_consistent(ioc
->pdev
, data_in_sz
,
684 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
687 mpt2sas_base_free_smid(ioc
, smid
);
692 /* add scatter gather elements */
693 psge
= (void *)mpi_request
+ (karg
.data_sge_offset
*4);
695 if (!data_out_sz
&& !data_in_sz
) {
696 mpt2sas_base_build_zero_len_sge(ioc
, psge
);
697 } else if (data_out_sz
&& data_in_sz
) {
698 /* WRITE sgel first */
699 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
700 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
701 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
702 ioc
->base_add_sg_single(psge
, sgl_flags
|
703 data_out_sz
, data_out_dma
);
706 psge
+= ioc
->sge_size
;
709 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
710 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
711 MPI2_SGE_FLAGS_END_OF_LIST
);
712 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
713 ioc
->base_add_sg_single(psge
, sgl_flags
|
714 data_in_sz
, data_in_dma
);
715 } else if (data_out_sz
) /* WRITE */ {
716 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
717 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
718 MPI2_SGE_FLAGS_END_OF_LIST
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
719 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
720 ioc
->base_add_sg_single(psge
, sgl_flags
|
721 data_out_sz
, data_out_dma
);
722 } else if (data_in_sz
) /* READ */ {
723 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
724 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
725 MPI2_SGE_FLAGS_END_OF_LIST
);
726 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
727 ioc
->base_add_sg_single(psge
, sgl_flags
|
728 data_in_sz
, data_in_dma
);
731 /* send command to firmware */
732 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
733 _ctl_display_some_debug(ioc
, smid
, "ctl_request", NULL
);
736 switch (mpi_request
->Function
) {
737 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
738 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
740 Mpi2SCSIIORequest_t
*scsiio_request
=
741 (Mpi2SCSIIORequest_t
*)mpi_request
;
742 scsiio_request
->SenseBufferLowAddress
=
743 (u32
)mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
744 priv_sense
= mpt2sas_base_get_sense_buffer(ioc
, smid
);
745 memset(priv_sense
, 0, SCSI_SENSE_BUFFERSIZE
);
746 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
747 le16_to_cpu(mpi_request
->FunctionDependent1
));
750 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
752 Mpi2SCSITaskManagementRequest_t
*tm_request
=
753 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
755 if (tm_request
->TaskType
==
756 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
||
757 tm_request
->TaskType
==
758 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
) {
759 if (_ctl_set_task_mid(ioc
, &karg
, tm_request
)) {
760 mpt2sas_base_free_smid(ioc
, smid
);
765 mutex_lock(&ioc
->tm_cmds
.mutex
);
766 mpt2sas_scsih_set_tm_flag(ioc
, le16_to_cpu(
767 tm_request
->DevHandle
));
768 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
771 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
773 Mpi2SmpPassthroughRequest_t
*smp_request
=
774 (Mpi2SmpPassthroughRequest_t
*)mpi_request
;
777 /* ioc determines which port to use */
778 smp_request
->PhysicalPort
= 0xFF;
779 if (smp_request
->PassthroughFlags
&
780 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE
)
781 data
= (u8
*)&smp_request
->SGL
;
785 if (data
[1] == 0x91 && (data
[10] == 1 || data
[10] == 2)) {
786 ioc
->ioc_link_reset_in_progress
= 1;
787 ioc
->ignore_loginfos
= 1;
789 mpt2sas_base_put_smid_default(ioc
, smid
);
792 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
794 Mpi2SasIoUnitControlRequest_t
*sasiounit_request
=
795 (Mpi2SasIoUnitControlRequest_t
*)mpi_request
;
797 if (sasiounit_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
798 || sasiounit_request
->Operation
==
799 MPI2_SAS_OP_PHY_LINK_RESET
) {
800 ioc
->ioc_link_reset_in_progress
= 1;
801 ioc
->ignore_loginfos
= 1;
803 mpt2sas_base_put_smid_default(ioc
, smid
);
807 mpt2sas_base_put_smid_default(ioc
, smid
);
811 if (karg
.timeout
< MPT2_IOCTL_DEFAULT_TIMEOUT
)
812 timeout
= MPT2_IOCTL_DEFAULT_TIMEOUT
;
814 timeout
= karg
.timeout
;
815 init_completion(&ioc
->ctl_cmds
.done
);
816 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
818 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
819 Mpi2SCSITaskManagementRequest_t
*tm_request
=
820 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
821 mutex_unlock(&ioc
->tm_cmds
.mutex
);
822 mpt2sas_scsih_clear_tm_flag(ioc
, le16_to_cpu(
823 tm_request
->DevHandle
));
824 } else if ((mpi_request
->Function
== MPI2_FUNCTION_SMP_PASSTHROUGH
||
825 mpi_request
->Function
== MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
) &&
826 ioc
->ioc_link_reset_in_progress
) {
827 ioc
->ioc_link_reset_in_progress
= 0;
828 ioc
->ignore_loginfos
= 0;
830 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
831 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
833 _debug_dump_mf(mpi_request
, karg
.data_sge_offset
);
834 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
836 goto issue_host_reset
;
839 mpi_reply
= ioc
->ctl_cmds
.reply
;
840 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
842 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
843 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
&&
844 (ioc
->logging_level
& MPT_DEBUG_TM
)) {
845 Mpi2SCSITaskManagementReply_t
*tm_reply
=
846 (Mpi2SCSITaskManagementReply_t
*)mpi_reply
;
848 printk(MPT2SAS_DEBUG_FMT
"TASK_MGMT: "
849 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
850 "TerminationCount(0x%08x)\n", ioc
->name
,
851 tm_reply
->IOCStatus
, tm_reply
->IOCLogInfo
,
852 tm_reply
->TerminationCount
);
855 /* copy out xdata to user */
857 if (copy_to_user(karg
.data_in_buf_ptr
, data_in
,
859 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
866 /* copy out reply message frame to user */
867 if (karg
.max_reply_bytes
) {
868 sz
= min_t(u32
, karg
.max_reply_bytes
, ioc
->reply_sz
);
869 if (copy_to_user(karg
.reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
871 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
878 /* copy out sense to user */
879 if (karg
.max_sense_bytes
&& (mpi_request
->Function
==
880 MPI2_FUNCTION_SCSI_IO_REQUEST
|| mpi_request
->Function
==
881 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
882 sz
= min_t(u32
, karg
.max_sense_bytes
, SCSI_SENSE_BUFFERSIZE
);
883 if (copy_to_user(karg
.sense_data_ptr
, priv_sense
, sz
)) {
884 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
893 if ((mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
894 mpi_request
->Function
==
895 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
896 printk(MPT2SAS_INFO_FMT
"issue target reset: handle "
897 "= (0x%04x)\n", ioc
->name
,
898 mpi_request
->FunctionDependent1
);
899 mpt2sas_halt_firmware(ioc
);
900 mutex_lock(&ioc
->tm_cmds
.mutex
);
901 mpt2sas_scsih_issue_tm(ioc
,
902 mpi_request
->FunctionDependent1
, 0,
903 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
904 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
905 mutex_unlock(&ioc
->tm_cmds
.mutex
);
907 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
913 /* free memory associated with sg buffers */
915 pci_free_consistent(ioc
->pdev
, data_in_sz
, data_in
,
919 pci_free_consistent(ioc
->pdev
, data_out_sz
, data_out
,
922 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
923 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
928 * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode
929 * @arg - user space buffer containing ioctl content
932 _ctl_getiocinfo(void __user
*arg
)
934 struct mpt2_ioctl_iocinfo karg
;
935 struct MPT2SAS_ADAPTER
*ioc
;
938 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
939 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
940 __FILE__
, __LINE__
, __func__
);
943 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
946 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
949 memset(&karg
, 0 , sizeof(karg
));
950 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2
;
952 karg
.port_number
= ioc
->pfacts
[0].PortNumber
;
953 pci_read_config_byte(ioc
->pdev
, PCI_CLASS_REVISION
, &revision
);
954 karg
.hw_rev
= revision
;
955 karg
.pci_id
= ioc
->pdev
->device
;
956 karg
.subsystem_device
= ioc
->pdev
->subsystem_device
;
957 karg
.subsystem_vendor
= ioc
->pdev
->subsystem_vendor
;
958 karg
.pci_information
.u
.bits
.bus
= ioc
->pdev
->bus
->number
;
959 karg
.pci_information
.u
.bits
.device
= PCI_SLOT(ioc
->pdev
->devfn
);
960 karg
.pci_information
.u
.bits
.function
= PCI_FUNC(ioc
->pdev
->devfn
);
961 karg
.pci_information
.segment_id
= pci_domain_nr(ioc
->pdev
->bus
);
962 karg
.firmware_version
= ioc
->facts
.FWVersion
.Word
;
963 strcpy(karg
.driver_version
, MPT2SAS_DRIVER_NAME
);
964 strcat(karg
.driver_version
, "-");
965 strcat(karg
.driver_version
, MPT2SAS_DRIVER_VERSION
);
966 karg
.bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
968 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
969 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
970 __FILE__
, __LINE__
, __func__
);
977 * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode
978 * @arg - user space buffer containing ioctl content
981 _ctl_eventquery(void __user
*arg
)
983 struct mpt2_ioctl_eventquery karg
;
984 struct MPT2SAS_ADAPTER
*ioc
;
986 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
987 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
988 __FILE__
, __LINE__
, __func__
);
991 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
994 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
997 karg
.event_entries
= MPT2SAS_CTL_EVENT_LOG_SIZE
;
998 memcpy(karg
.event_types
, ioc
->event_type
,
999 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1001 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1002 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1003 __FILE__
, __LINE__
, __func__
);
1010 * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode
1011 * @arg - user space buffer containing ioctl content
1014 _ctl_eventenable(void __user
*arg
)
1016 struct mpt2_ioctl_eventenable karg
;
1017 struct MPT2SAS_ADAPTER
*ioc
;
1019 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1020 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1021 __FILE__
, __LINE__
, __func__
);
1024 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1027 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
1032 memcpy(ioc
->event_type
, karg
.event_types
,
1033 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1034 mpt2sas_base_validate_event_type(ioc
, ioc
->event_type
);
1036 /* initialize event_log */
1037 ioc
->event_context
= 0;
1038 ioc
->aen_event_read_flag
= 0;
1039 ioc
->event_log
= kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE
,
1040 sizeof(struct MPT2_IOCTL_EVENTS
), GFP_KERNEL
);
1041 if (!ioc
->event_log
) {
1042 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1043 __FILE__
, __LINE__
, __func__
);
1050 * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode
1051 * @arg - user space buffer containing ioctl content
1054 _ctl_eventreport(void __user
*arg
)
1056 struct mpt2_ioctl_eventreport karg
;
1057 struct MPT2SAS_ADAPTER
*ioc
;
1058 u32 number_bytes
, max_events
, max
;
1059 struct mpt2_ioctl_eventreport __user
*uarg
= arg
;
1061 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1062 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1063 __FILE__
, __LINE__
, __func__
);
1066 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1069 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
1072 number_bytes
= karg
.hdr
.max_data_size
-
1073 sizeof(struct mpt2_ioctl_header
);
1074 max_events
= number_bytes
/sizeof(struct MPT2_IOCTL_EVENTS
);
1075 max
= min_t(u32
, MPT2SAS_CTL_EVENT_LOG_SIZE
, max_events
);
1077 /* If fewer than 1 event is requested, there must have
1078 * been some type of error.
1080 if (!max
|| !ioc
->event_log
)
1083 number_bytes
= max
* sizeof(struct MPT2_IOCTL_EVENTS
);
1084 if (copy_to_user(uarg
->event_data
, ioc
->event_log
, number_bytes
)) {
1085 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1086 __FILE__
, __LINE__
, __func__
);
1090 /* reset flag so SIGIO can restart */
1091 ioc
->aen_event_read_flag
= 0;
1096 * _ctl_do_reset - main handler for MPT2HARDRESET opcode
1097 * @arg - user space buffer containing ioctl content
1100 _ctl_do_reset(void __user
*arg
)
1102 struct mpt2_ioctl_diag_reset karg
;
1103 struct MPT2SAS_ADAPTER
*ioc
;
1106 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1107 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1108 __FILE__
, __LINE__
, __func__
);
1111 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1114 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
1117 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1119 printk(MPT2SAS_INFO_FMT
"host reset: %s\n",
1120 ioc
->name
, ((!retval
) ? "SUCCESS" : "FAILED"));
1125 * _ctl_btdh_search_sas_device - searching for sas device
1126 * @ioc: per adapter object
1127 * @btdh: btdh ioctl payload
1130 _ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER
*ioc
,
1131 struct mpt2_ioctl_btdh_mapping
*btdh
)
1133 struct _sas_device
*sas_device
;
1134 unsigned long flags
;
1137 if (list_empty(&ioc
->sas_device_list
))
1140 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1141 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
1142 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1143 btdh
->handle
== sas_device
->handle
) {
1144 btdh
->bus
= sas_device
->channel
;
1145 btdh
->id
= sas_device
->id
;
1148 } else if (btdh
->bus
== sas_device
->channel
&& btdh
->id
==
1149 sas_device
->id
&& btdh
->handle
== 0xFFFF) {
1150 btdh
->handle
= sas_device
->handle
;
1156 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1161 * _ctl_btdh_search_raid_device - searching for raid device
1162 * @ioc: per adapter object
1163 * @btdh: btdh ioctl payload
1166 _ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER
*ioc
,
1167 struct mpt2_ioctl_btdh_mapping
*btdh
)
1169 struct _raid_device
*raid_device
;
1170 unsigned long flags
;
1173 if (list_empty(&ioc
->raid_device_list
))
1176 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1177 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1178 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1179 btdh
->handle
== raid_device
->handle
) {
1180 btdh
->bus
= raid_device
->channel
;
1181 btdh
->id
= raid_device
->id
;
1184 } else if (btdh
->bus
== raid_device
->channel
&& btdh
->id
==
1185 raid_device
->id
&& btdh
->handle
== 0xFFFF) {
1186 btdh
->handle
= raid_device
->handle
;
1192 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1197 * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode
1198 * @arg - user space buffer containing ioctl content
1201 _ctl_btdh_mapping(void __user
*arg
)
1203 struct mpt2_ioctl_btdh_mapping karg
;
1204 struct MPT2SAS_ADAPTER
*ioc
;
1207 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1208 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1209 __FILE__
, __LINE__
, __func__
);
1212 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1215 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1218 rc
= _ctl_btdh_search_sas_device(ioc
, &karg
);
1220 _ctl_btdh_search_raid_device(ioc
, &karg
);
1222 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1223 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1224 __FILE__
, __LINE__
, __func__
);
1231 * _ctl_diag_capability - return diag buffer capability
1232 * @ioc: per adapter object
1233 * @buffer_type: specifies either TRACE or SNAPSHOT
1235 * returns 1 when diag buffer support is enabled in firmware
1238 _ctl_diag_capability(struct MPT2SAS_ADAPTER
*ioc
, u8 buffer_type
)
1242 switch (buffer_type
) {
1243 case MPI2_DIAG_BUF_TYPE_TRACE
:
1244 if (ioc
->facts
.IOCCapabilities
&
1245 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
)
1248 case MPI2_DIAG_BUF_TYPE_SNAPSHOT
:
1249 if (ioc
->facts
.IOCCapabilities
&
1250 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
)
1259 * _ctl_diag_register - application register with driver
1260 * @arg - user space buffer containing ioctl content
1261 * @state - NON_BLOCKING or BLOCKING
1263 * This will allow the driver to setup any required buffers that will be
1264 * needed by firmware to communicate with the driver.
1267 _ctl_diag_register(void __user
*arg
, enum block_state state
)
1269 struct mpt2_diag_register karg
;
1270 struct MPT2SAS_ADAPTER
*ioc
;
1272 void *request_data
= NULL
;
1273 dma_addr_t request_data_dma
;
1274 u32 request_data_sz
= 0;
1275 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1276 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1278 unsigned long timeleft
;
1283 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1284 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1285 __FILE__
, __LINE__
, __func__
);
1288 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1291 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1294 buffer_type
= karg
.buffer_type
;
1295 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1296 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1297 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1301 if (ioc
->diag_buffer_status
[buffer_type
] &
1302 MPT2_DIAG_BUFFER_IS_REGISTERED
) {
1303 printk(MPT2SAS_ERR_FMT
"%s: already has a registered "
1304 "buffer for buffer_type(0x%02x)\n", ioc
->name
, __func__
,
1309 if (karg
.requested_buffer_size
% 4) {
1310 printk(MPT2SAS_ERR_FMT
"%s: the requested_buffer_size "
1311 "is not 4 byte aligned\n", ioc
->name
, __func__
);
1315 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
1317 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
1318 return -ERESTARTSYS
;
1320 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1321 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1322 ioc
->name
, __func__
);
1327 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1329 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1330 ioc
->name
, __func__
);
1336 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1337 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1338 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1339 ioc
->ctl_cmds
.smid
= smid
;
1341 request_data
= ioc
->diag_buffer
[buffer_type
];
1342 request_data_sz
= karg
.requested_buffer_size
;
1343 ioc
->unique_id
[buffer_type
] = karg
.unique_id
;
1344 ioc
->diag_buffer_status
[buffer_type
] = 0;
1345 memcpy(ioc
->product_specific
[buffer_type
], karg
.product_specific
,
1346 MPT2_PRODUCT_SPECIFIC_DWORDS
);
1347 ioc
->diagnostic_flags
[buffer_type
] = karg
.diagnostic_flags
;
1350 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1351 if (request_data_sz
!= ioc
->diag_buffer_sz
[buffer_type
]) {
1352 pci_free_consistent(ioc
->pdev
,
1353 ioc
->diag_buffer_sz
[buffer_type
],
1354 request_data
, request_data_dma
);
1355 request_data
= NULL
;
1359 if (request_data
== NULL
) {
1360 ioc
->diag_buffer_sz
[buffer_type
] = 0;
1361 ioc
->diag_buffer_dma
[buffer_type
] = 0;
1362 request_data
= pci_alloc_consistent(
1363 ioc
->pdev
, request_data_sz
, &request_data_dma
);
1364 if (request_data
== NULL
) {
1365 printk(MPT2SAS_ERR_FMT
"%s: failed allocating memory"
1366 " for diag buffers, requested size(%d)\n",
1367 ioc
->name
, __func__
, request_data_sz
);
1368 mpt2sas_base_free_smid(ioc
, smid
);
1371 ioc
->diag_buffer
[buffer_type
] = request_data
;
1372 ioc
->diag_buffer_sz
[buffer_type
] = request_data_sz
;
1373 ioc
->diag_buffer_dma
[buffer_type
] = request_data_dma
;
1376 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1377 mpi_request
->BufferType
= karg
.buffer_type
;
1378 mpi_request
->Flags
= cpu_to_le32(karg
.diagnostic_flags
);
1379 mpi_request
->BufferAddress
= cpu_to_le64(request_data_dma
);
1380 mpi_request
->BufferLength
= cpu_to_le32(request_data_sz
);
1381 mpi_request
->VF_ID
= 0; /* TODO */
1382 mpi_request
->VP_ID
= 0;
1384 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: diag_buffer(0x%p), "
1385 "dma(0x%llx), sz(%d)\n", ioc
->name
, __func__
, request_data
,
1386 (unsigned long long)request_data_dma
, mpi_request
->BufferLength
));
1388 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1389 mpi_request
->ProductSpecific
[i
] =
1390 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1392 mpt2sas_base_put_smid_default(ioc
, smid
);
1393 init_completion(&ioc
->ctl_cmds
.done
);
1394 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1395 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1397 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1398 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1400 _debug_dump_mf(mpi_request
,
1401 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
1402 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1404 goto issue_host_reset
;
1407 /* process the completed Reply Message Frame */
1408 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1409 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1410 ioc
->name
, __func__
);
1415 mpi_reply
= ioc
->ctl_cmds
.reply
;
1416 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1418 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1419 ioc
->diag_buffer_status
[buffer_type
] |=
1420 MPT2_DIAG_BUFFER_IS_REGISTERED
;
1421 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: success\n",
1422 ioc
->name
, __func__
));
1424 printk(MPT2SAS_DEBUG_FMT
"%s: ioc_status(0x%04x) "
1425 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1426 ioc_status
, mpi_reply
->IOCLogInfo
);
1432 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1437 if (rc
&& request_data
)
1438 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1439 request_data
, request_data_dma
);
1441 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1442 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
1447 * _ctl_diag_unregister - application unregister with driver
1448 * @arg - user space buffer containing ioctl content
1450 * This will allow the driver to cleanup any memory allocated for diag
1451 * messages and to free up any resources.
1454 _ctl_diag_unregister(void __user
*arg
)
1456 struct mpt2_diag_unregister karg
;
1457 struct MPT2SAS_ADAPTER
*ioc
;
1459 dma_addr_t request_data_dma
;
1460 u32 request_data_sz
;
1463 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1464 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1465 __FILE__
, __LINE__
, __func__
);
1468 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1471 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1474 buffer_type
= karg
.unique_id
& 0x000000ff;
1475 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1476 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1477 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1481 if ((ioc
->diag_buffer_status
[buffer_type
] &
1482 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1483 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1484 "registered\n", ioc
->name
, __func__
, buffer_type
);
1487 if ((ioc
->diag_buffer_status
[buffer_type
] &
1488 MPT2_DIAG_BUFFER_IS_RELEASED
) == 0) {
1489 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) has not been "
1490 "released\n", ioc
->name
, __func__
, buffer_type
);
1494 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1495 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1496 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1500 request_data
= ioc
->diag_buffer
[buffer_type
];
1501 if (!request_data
) {
1502 printk(MPT2SAS_ERR_FMT
"%s: doesn't have memory allocated for "
1503 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1507 request_data_sz
= ioc
->diag_buffer_sz
[buffer_type
];
1508 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1509 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1510 request_data
, request_data_dma
);
1511 ioc
->diag_buffer
[buffer_type
] = NULL
;
1512 ioc
->diag_buffer_status
[buffer_type
] = 0;
1517 * _ctl_diag_query - query relevant info associated with diag buffers
1518 * @arg - user space buffer containing ioctl content
1520 * The application will send only buffer_type and unique_id. Driver will
1521 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1522 * 0x00, the driver will return info specified by Buffer Type.
1525 _ctl_diag_query(void __user
*arg
)
1527 struct mpt2_diag_query karg
;
1528 struct MPT2SAS_ADAPTER
*ioc
;
1533 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1534 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1535 __FILE__
, __LINE__
, __func__
);
1538 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1541 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1544 karg
.application_flags
= 0;
1545 buffer_type
= karg
.buffer_type
;
1547 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1548 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1549 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1553 if ((ioc
->diag_buffer_status
[buffer_type
] &
1554 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1555 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1556 "registered\n", ioc
->name
, __func__
, buffer_type
);
1560 if (karg
.unique_id
& 0xffffff00) {
1561 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1562 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1563 "registered\n", ioc
->name
, __func__
,
1569 request_data
= ioc
->diag_buffer
[buffer_type
];
1570 if (!request_data
) {
1571 printk(MPT2SAS_ERR_FMT
"%s: doesn't have buffer for "
1572 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1576 if (ioc
->diag_buffer_status
[buffer_type
] & MPT2_DIAG_BUFFER_IS_RELEASED
)
1577 karg
.application_flags
= (MPT2_APP_FLAGS_APP_OWNED
|
1578 MPT2_APP_FLAGS_BUFFER_VALID
);
1580 karg
.application_flags
= (MPT2_APP_FLAGS_APP_OWNED
|
1581 MPT2_APP_FLAGS_BUFFER_VALID
|
1582 MPT2_APP_FLAGS_FW_BUFFER_ACCESS
);
1584 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1585 karg
.product_specific
[i
] =
1586 ioc
->product_specific
[buffer_type
][i
];
1588 karg
.total_buffer_size
= ioc
->diag_buffer_sz
[buffer_type
];
1589 karg
.driver_added_buffer_size
= 0;
1590 karg
.unique_id
= ioc
->unique_id
[buffer_type
];
1591 karg
.diagnostic_flags
= ioc
->diagnostic_flags
[buffer_type
];
1593 if (copy_to_user(arg
, &karg
, sizeof(struct mpt2_diag_query
))) {
1594 printk(MPT2SAS_ERR_FMT
"%s: unable to write mpt2_diag_query "
1595 "data @ %p\n", ioc
->name
, __func__
, arg
);
1602 * _ctl_send_release - Diag Release Message
1603 * @ioc: per adapter object
1604 * @buffer_type - specifies either TRACE or SNAPSHOT
1605 * @issue_reset - specifies whether host reset is required.
1609 _ctl_send_release(struct MPT2SAS_ADAPTER
*ioc
, u8 buffer_type
, u8
*issue_reset
)
1611 Mpi2DiagReleaseRequest_t
*mpi_request
;
1612 Mpi2DiagReleaseReply_t
*mpi_reply
;
1617 unsigned long timeleft
;
1619 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1625 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
1626 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1627 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
1628 "skipping due to FAULT state\n", ioc
->name
,
1634 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1635 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1636 ioc
->name
, __func__
);
1641 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1643 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1644 ioc
->name
, __func__
);
1649 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1650 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1651 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1652 ioc
->ctl_cmds
.smid
= smid
;
1654 mpi_request
->Function
= MPI2_FUNCTION_DIAG_RELEASE
;
1655 mpi_request
->BufferType
= buffer_type
;
1656 mpi_request
->VF_ID
= 0; /* TODO */
1657 mpi_request
->VP_ID
= 0;
1659 mpt2sas_base_put_smid_default(ioc
, smid
);
1660 init_completion(&ioc
->ctl_cmds
.done
);
1661 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1662 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1664 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1665 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1667 _debug_dump_mf(mpi_request
,
1668 sizeof(Mpi2DiagReleaseRequest_t
)/4);
1669 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1675 /* process the completed Reply Message Frame */
1676 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1677 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1678 ioc
->name
, __func__
);
1683 mpi_reply
= ioc
->ctl_cmds
.reply
;
1684 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1686 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1687 ioc
->diag_buffer_status
[buffer_type
] |=
1688 MPT2_DIAG_BUFFER_IS_RELEASED
;
1689 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: success\n",
1690 ioc
->name
, __func__
));
1692 printk(MPT2SAS_DEBUG_FMT
"%s: ioc_status(0x%04x) "
1693 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1694 ioc_status
, mpi_reply
->IOCLogInfo
);
1699 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1704 * _ctl_diag_release - request to send Diag Release Message to firmware
1705 * @arg - user space buffer containing ioctl content
1706 * @state - NON_BLOCKING or BLOCKING
1708 * This allows ownership of the specified buffer to returned to the driver,
1709 * allowing an application to read the buffer without fear that firmware is
1710 * overwritting information in the buffer.
1713 _ctl_diag_release(void __user
*arg
, enum block_state state
)
1715 struct mpt2_diag_release karg
;
1716 struct MPT2SAS_ADAPTER
*ioc
;
1722 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1723 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1724 __FILE__
, __LINE__
, __func__
);
1727 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1730 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1733 buffer_type
= karg
.unique_id
& 0x000000ff;
1734 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1735 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1736 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1740 if ((ioc
->diag_buffer_status
[buffer_type
] &
1741 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1742 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1743 "registered\n", ioc
->name
, __func__
, buffer_type
);
1747 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1748 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1749 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1753 if (ioc
->diag_buffer_status
[buffer_type
] &
1754 MPT2_DIAG_BUFFER_IS_RELEASED
) {
1755 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) "
1756 "is already released\n", ioc
->name
, __func__
,
1761 request_data
= ioc
->diag_buffer
[buffer_type
];
1763 if (!request_data
) {
1764 printk(MPT2SAS_ERR_FMT
"%s: doesn't have memory allocated for "
1765 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1769 /* buffers were released by due to host reset */
1770 if ((ioc
->diag_buffer_status
[buffer_type
] &
1771 MPT2_DIAG_BUFFER_IS_DIAG_RESET
)) {
1772 ioc
->diag_buffer_status
[buffer_type
] |=
1773 MPT2_DIAG_BUFFER_IS_RELEASED
;
1774 ioc
->diag_buffer_status
[buffer_type
] &=
1775 ~MPT2_DIAG_BUFFER_IS_DIAG_RESET
;
1776 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) "
1777 "was released due to host reset\n", ioc
->name
, __func__
,
1782 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
1784 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
1785 return -ERESTARTSYS
;
1787 rc
= _ctl_send_release(ioc
, buffer_type
, &issue_reset
);
1790 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1793 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
1798 * _ctl_diag_read_buffer - request for copy of the diag buffer
1799 * @arg - user space buffer containing ioctl content
1800 * @state - NON_BLOCKING or BLOCKING
1803 _ctl_diag_read_buffer(void __user
*arg
, enum block_state state
)
1805 struct mpt2_diag_read_buffer karg
;
1806 struct mpt2_diag_read_buffer __user
*uarg
= arg
;
1807 struct MPT2SAS_ADAPTER
*ioc
;
1808 void *request_data
, *diag_data
;
1809 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1810 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1813 unsigned long timeleft
;
1818 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1819 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1820 __FILE__
, __LINE__
, __func__
);
1823 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1826 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1829 buffer_type
= karg
.unique_id
& 0x000000ff;
1830 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1831 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1832 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1836 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1837 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1838 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1842 request_data
= ioc
->diag_buffer
[buffer_type
];
1843 if (!request_data
) {
1844 printk(MPT2SAS_ERR_FMT
"%s: doesn't have buffer for "
1845 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1849 if ((karg
.starting_offset
% 4) || (karg
.bytes_to_read
% 4)) {
1850 printk(MPT2SAS_ERR_FMT
"%s: either the starting_offset "
1851 "or bytes_to_read are not 4 byte aligned\n", ioc
->name
,
1856 diag_data
= (void *)(request_data
+ karg
.starting_offset
);
1857 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: diag_buffer(%p), "
1858 "offset(%d), sz(%d)\n", ioc
->name
, __func__
,
1859 diag_data
, karg
.starting_offset
, karg
.bytes_to_read
));
1861 if (copy_to_user((void __user
*)uarg
->diagnostic_data
,
1862 diag_data
, karg
.bytes_to_read
)) {
1863 printk(MPT2SAS_ERR_FMT
"%s: Unable to write "
1864 "mpt_diag_read_buffer_t data @ %p\n", ioc
->name
,
1865 __func__
, diag_data
);
1869 if ((karg
.flags
& MPT2_FLAGS_REREGISTER
) == 0)
1872 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: Reregister "
1873 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
));
1874 if ((ioc
->diag_buffer_status
[buffer_type
] &
1875 MPT2_DIAG_BUFFER_IS_RELEASED
) == 0) {
1876 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
1877 "buffer_type(0x%02x) is still registered\n", ioc
->name
,
1878 __func__
, buffer_type
));
1881 /* Get a free request frame and save the message context.
1883 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
1885 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
1886 return -ERESTARTSYS
;
1888 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1889 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1890 ioc
->name
, __func__
);
1895 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1897 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1898 ioc
->name
, __func__
);
1904 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1905 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1906 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1907 ioc
->ctl_cmds
.smid
= smid
;
1909 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1910 mpi_request
->BufferType
= buffer_type
;
1911 mpi_request
->BufferLength
=
1912 cpu_to_le32(ioc
->diag_buffer_sz
[buffer_type
]);
1913 mpi_request
->BufferAddress
=
1914 cpu_to_le64(ioc
->diag_buffer_dma
[buffer_type
]);
1915 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1916 mpi_request
->ProductSpecific
[i
] =
1917 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1918 mpi_request
->VF_ID
= 0; /* TODO */
1919 mpi_request
->VP_ID
= 0;
1921 mpt2sas_base_put_smid_default(ioc
, smid
);
1922 init_completion(&ioc
->ctl_cmds
.done
);
1923 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1924 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1926 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1927 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1929 _debug_dump_mf(mpi_request
,
1930 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
1931 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1933 goto issue_host_reset
;
1936 /* process the completed Reply Message Frame */
1937 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1938 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1939 ioc
->name
, __func__
);
1944 mpi_reply
= ioc
->ctl_cmds
.reply
;
1945 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1947 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1948 ioc
->diag_buffer_status
[buffer_type
] |=
1949 MPT2_DIAG_BUFFER_IS_REGISTERED
;
1950 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: success\n",
1951 ioc
->name
, __func__
));
1953 printk(MPT2SAS_DEBUG_FMT
"%s: ioc_status(0x%04x) "
1954 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1955 ioc_status
, mpi_reply
->IOCLogInfo
);
1961 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1966 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1967 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
1972 * _ctl_ioctl_main - main ioctl entry point
1973 * @file - (struct file)
1974 * @cmd - ioctl opcode
1978 _ctl_ioctl_main(struct file
*file
, unsigned int cmd
, void __user
*arg
)
1980 enum block_state state
;
1983 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
:
1988 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_iocinfo
))
1989 ret
= _ctl_getiocinfo(arg
);
1993 struct mpt2_ioctl_command karg
;
1994 struct mpt2_ioctl_command __user
*uarg
;
1995 struct MPT2SAS_ADAPTER
*ioc
;
1997 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1998 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1999 __FILE__
, __LINE__
, __func__
);
2003 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 ||
2007 if (ioc
->shost_recovery
)
2010 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_command
)) {
2012 ret
= _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
, state
);
2016 case MPT2EVENTQUERY
:
2017 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_eventquery
))
2018 ret
= _ctl_eventquery(arg
);
2020 case MPT2EVENTENABLE
:
2021 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_eventenable
))
2022 ret
= _ctl_eventenable(arg
);
2024 case MPT2EVENTREPORT
:
2025 ret
= _ctl_eventreport(arg
);
2028 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_diag_reset
))
2029 ret
= _ctl_do_reset(arg
);
2031 case MPT2BTDHMAPPING
:
2032 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_btdh_mapping
))
2033 ret
= _ctl_btdh_mapping(arg
);
2035 case MPT2DIAGREGISTER
:
2036 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_register
))
2037 ret
= _ctl_diag_register(arg
, state
);
2039 case MPT2DIAGUNREGISTER
:
2040 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_unregister
))
2041 ret
= _ctl_diag_unregister(arg
);
2044 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_query
))
2045 ret
= _ctl_diag_query(arg
);
2047 case MPT2DIAGRELEASE
:
2048 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_release
))
2049 ret
= _ctl_diag_release(arg
, state
);
2051 case MPT2DIAGREADBUFFER
:
2052 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_read_buffer
))
2053 ret
= _ctl_diag_read_buffer(arg
, state
);
2057 struct mpt2_ioctl_command karg
;
2058 struct MPT2SAS_ADAPTER
*ioc
;
2060 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2061 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
2062 __FILE__
, __LINE__
, __func__
);
2066 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 ||
2070 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
2071 "unsupported ioctl opcode(0x%08x)\n", ioc
->name
, cmd
));
2079 * _ctl_ioctl - main ioctl entry point (unlocked)
2080 * @file - (struct file)
2081 * @cmd - ioctl opcode
2085 _ctl_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2090 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
);
2095 #ifdef CONFIG_COMPAT
2097 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2098 * @file - (struct file)
2099 * @cmd - ioctl opcode
2100 * @arg - (struct mpt2_ioctl_command32)
2102 * MPT2COMMAND32 - Handle 32bit applications running on 64bit os.
2105 _ctl_compat_mpt_command(struct file
*file
, unsigned cmd
, unsigned long arg
)
2107 struct mpt2_ioctl_command32 karg32
;
2108 struct mpt2_ioctl_command32 __user
*uarg
;
2109 struct mpt2_ioctl_command karg
;
2110 struct MPT2SAS_ADAPTER
*ioc
;
2111 enum block_state state
;
2113 if (_IOC_SIZE(cmd
) != sizeof(struct mpt2_ioctl_command32
))
2116 uarg
= (struct mpt2_ioctl_command32 __user
*) arg
;
2118 if (copy_from_user(&karg32
, (char __user
*)arg
, sizeof(karg32
))) {
2119 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
2120 __FILE__
, __LINE__
, __func__
);
2123 if (_ctl_verify_adapter(karg32
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
2126 if (ioc
->shost_recovery
)
2129 memset(&karg
, 0, sizeof(struct mpt2_ioctl_command
));
2130 karg
.hdr
.ioc_number
= karg32
.hdr
.ioc_number
;
2131 karg
.hdr
.port_number
= karg32
.hdr
.port_number
;
2132 karg
.hdr
.max_data_size
= karg32
.hdr
.max_data_size
;
2133 karg
.timeout
= karg32
.timeout
;
2134 karg
.max_reply_bytes
= karg32
.max_reply_bytes
;
2135 karg
.data_in_size
= karg32
.data_in_size
;
2136 karg
.data_out_size
= karg32
.data_out_size
;
2137 karg
.max_sense_bytes
= karg32
.max_sense_bytes
;
2138 karg
.data_sge_offset
= karg32
.data_sge_offset
;
2139 memcpy(&karg
.reply_frame_buf_ptr
, &karg32
.reply_frame_buf_ptr
,
2141 memcpy(&karg
.data_in_buf_ptr
, &karg32
.data_in_buf_ptr
,
2143 memcpy(&karg
.data_out_buf_ptr
, &karg32
.data_out_buf_ptr
,
2145 memcpy(&karg
.sense_data_ptr
, &karg32
.sense_data_ptr
,
2147 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
: BLOCKING
;
2148 return _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
, state
);
2152 * _ctl_ioctl_compat - main ioctl entry point (compat)
2157 * This routine handles 32 bit applications in 64bit os.
2160 _ctl_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2165 if (cmd
== MPT2COMMAND32
)
2166 ret
= _ctl_compat_mpt_command(file
, cmd
, arg
);
2168 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
);
2174 /* scsi host attributes */
2177 * _ctl_version_fw_show - firmware version
2178 * @cdev - pointer to embedded class device
2179 * @buf - the buffer returned
2181 * A sysfs 'read-only' shost attribute.
2184 _ctl_version_fw_show(struct device
*cdev
, struct device_attribute
*attr
,
2187 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2188 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2190 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2191 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2192 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2193 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2194 ioc
->facts
.FWVersion
.Word
& 0x000000FF);
2196 static DEVICE_ATTR(version_fw
, S_IRUGO
, _ctl_version_fw_show
, NULL
);
2199 * _ctl_version_bios_show - bios version
2200 * @cdev - pointer to embedded class device
2201 * @buf - the buffer returned
2203 * A sysfs 'read-only' shost attribute.
2206 _ctl_version_bios_show(struct device
*cdev
, struct device_attribute
*attr
,
2209 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2210 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2212 u32 version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2214 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2215 (version
& 0xFF000000) >> 24,
2216 (version
& 0x00FF0000) >> 16,
2217 (version
& 0x0000FF00) >> 8,
2218 version
& 0x000000FF);
2220 static DEVICE_ATTR(version_bios
, S_IRUGO
, _ctl_version_bios_show
, NULL
);
2223 * _ctl_version_mpi_show - MPI (message passing interface) version
2224 * @cdev - pointer to embedded class device
2225 * @buf - the buffer returned
2227 * A sysfs 'read-only' shost attribute.
2230 _ctl_version_mpi_show(struct device
*cdev
, struct device_attribute
*attr
,
2233 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2234 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2236 return snprintf(buf
, PAGE_SIZE
, "%03x.%02x\n",
2237 ioc
->facts
.MsgVersion
, ioc
->facts
.HeaderVersion
>> 8);
2239 static DEVICE_ATTR(version_mpi
, S_IRUGO
, _ctl_version_mpi_show
, NULL
);
2242 * _ctl_version_product_show - product name
2243 * @cdev - pointer to embedded class device
2244 * @buf - the buffer returned
2246 * A sysfs 'read-only' shost attribute.
2249 _ctl_version_product_show(struct device
*cdev
, struct device_attribute
*attr
,
2252 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2253 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2255 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.ChipName
);
2257 static DEVICE_ATTR(version_product
, S_IRUGO
,
2258 _ctl_version_product_show
, NULL
);
2261 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2262 * @cdev - pointer to embedded class device
2263 * @buf - the buffer returned
2265 * A sysfs 'read-only' shost attribute.
2268 _ctl_version_nvdata_persistent_show(struct device
*cdev
,
2269 struct device_attribute
*attr
, char *buf
)
2271 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2272 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2274 return snprintf(buf
, PAGE_SIZE
, "%02xh\n",
2275 le16_to_cpu(ioc
->iounit_pg0
.NvdataVersionPersistent
.Word
));
2277 static DEVICE_ATTR(version_nvdata_persistent
, S_IRUGO
,
2278 _ctl_version_nvdata_persistent_show
, NULL
);
2281 * _ctl_version_nvdata_default_show - nvdata default version
2282 * @cdev - pointer to embedded class device
2283 * @buf - the buffer returned
2285 * A sysfs 'read-only' shost attribute.
2288 _ctl_version_nvdata_default_show(struct device
*cdev
,
2289 struct device_attribute
*attr
, char *buf
)
2291 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2292 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2294 return snprintf(buf
, PAGE_SIZE
, "%02xh\n",
2295 le16_to_cpu(ioc
->iounit_pg0
.NvdataVersionDefault
.Word
));
2297 static DEVICE_ATTR(version_nvdata_default
, S_IRUGO
,
2298 _ctl_version_nvdata_default_show
, NULL
);
2301 * _ctl_board_name_show - board name
2302 * @cdev - pointer to embedded class device
2303 * @buf - the buffer returned
2305 * A sysfs 'read-only' shost attribute.
2308 _ctl_board_name_show(struct device
*cdev
, struct device_attribute
*attr
,
2311 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2312 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2314 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardName
);
2316 static DEVICE_ATTR(board_name
, S_IRUGO
, _ctl_board_name_show
, NULL
);
2319 * _ctl_board_assembly_show - board assembly name
2320 * @cdev - pointer to embedded class device
2321 * @buf - the buffer returned
2323 * A sysfs 'read-only' shost attribute.
2326 _ctl_board_assembly_show(struct device
*cdev
, struct device_attribute
*attr
,
2329 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2330 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2332 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardAssembly
);
2334 static DEVICE_ATTR(board_assembly
, S_IRUGO
,
2335 _ctl_board_assembly_show
, NULL
);
2338 * _ctl_board_tracer_show - board tracer number
2339 * @cdev - pointer to embedded class device
2340 * @buf - the buffer returned
2342 * A sysfs 'read-only' shost attribute.
2345 _ctl_board_tracer_show(struct device
*cdev
, struct device_attribute
*attr
,
2348 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2349 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2351 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardTracerNumber
);
2353 static DEVICE_ATTR(board_tracer
, S_IRUGO
,
2354 _ctl_board_tracer_show
, NULL
);
2357 * _ctl_io_delay_show - io missing delay
2358 * @cdev - pointer to embedded class device
2359 * @buf - the buffer returned
2361 * This is for firmware implemention for deboucing device
2364 * A sysfs 'read-only' shost attribute.
2367 _ctl_io_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2370 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2371 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2373 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->io_missing_delay
);
2375 static DEVICE_ATTR(io_delay
, S_IRUGO
,
2376 _ctl_io_delay_show
, NULL
);
2379 * _ctl_device_delay_show - device missing delay
2380 * @cdev - pointer to embedded class device
2381 * @buf - the buffer returned
2383 * This is for firmware implemention for deboucing device
2386 * A sysfs 'read-only' shost attribute.
2389 _ctl_device_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2392 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2393 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2395 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->device_missing_delay
);
2397 static DEVICE_ATTR(device_delay
, S_IRUGO
,
2398 _ctl_device_delay_show
, NULL
);
2401 * _ctl_fw_queue_depth_show - global credits
2402 * @cdev - pointer to embedded class device
2403 * @buf - the buffer returned
2405 * This is firmware queue depth limit
2407 * A sysfs 'read-only' shost attribute.
2410 _ctl_fw_queue_depth_show(struct device
*cdev
, struct device_attribute
*attr
,
2413 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2414 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2416 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->facts
.RequestCredit
);
2418 static DEVICE_ATTR(fw_queue_depth
, S_IRUGO
,
2419 _ctl_fw_queue_depth_show
, NULL
);
2422 * _ctl_sas_address_show - sas address
2423 * @cdev - pointer to embedded class device
2424 * @buf - the buffer returned
2426 * This is the controller sas address
2428 * A sysfs 'read-only' shost attribute.
2431 _ctl_host_sas_address_show(struct device
*cdev
, struct device_attribute
*attr
,
2434 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2435 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2437 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
2438 (unsigned long long)ioc
->sas_hba
.sas_address
);
2440 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
2441 _ctl_host_sas_address_show
, NULL
);
2444 * _ctl_logging_level_show - logging level
2445 * @cdev - pointer to embedded class device
2446 * @buf - the buffer returned
2448 * A sysfs 'read/write' shost attribute.
2451 _ctl_logging_level_show(struct device
*cdev
, struct device_attribute
*attr
,
2454 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2455 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2457 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", ioc
->logging_level
);
2460 _ctl_logging_level_store(struct device
*cdev
, struct device_attribute
*attr
,
2461 const char *buf
, size_t count
)
2463 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2464 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2467 if (sscanf(buf
, "%x", &val
) != 1)
2470 ioc
->logging_level
= val
;
2471 printk(MPT2SAS_INFO_FMT
"logging_level=%08xh\n", ioc
->name
,
2472 ioc
->logging_level
);
2475 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
,
2476 _ctl_logging_level_show
, _ctl_logging_level_store
);
2478 /* device attributes */
2480 * _ctl_fwfault_debug_show - show/store fwfault_debug
2481 * @cdev - pointer to embedded class device
2482 * @buf - the buffer returned
2484 * mpt2sas_fwfault_debug is command line option
2485 * A sysfs 'read/write' shost attribute.
2488 _ctl_fwfault_debug_show(struct device
*cdev
,
2489 struct device_attribute
*attr
, char *buf
)
2491 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2492 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2494 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->fwfault_debug
);
2497 _ctl_fwfault_debug_store(struct device
*cdev
,
2498 struct device_attribute
*attr
, const char *buf
, size_t count
)
2500 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2501 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2504 if (sscanf(buf
, "%d", &val
) != 1)
2507 ioc
->fwfault_debug
= val
;
2508 printk(MPT2SAS_INFO_FMT
"fwfault_debug=%d\n", ioc
->name
,
2509 ioc
->fwfault_debug
);
2512 static DEVICE_ATTR(fwfault_debug
, S_IRUGO
| S_IWUSR
,
2513 _ctl_fwfault_debug_show
, _ctl_fwfault_debug_store
);
2515 struct device_attribute
*mpt2sas_host_attrs
[] = {
2516 &dev_attr_version_fw
,
2517 &dev_attr_version_bios
,
2518 &dev_attr_version_mpi
,
2519 &dev_attr_version_product
,
2520 &dev_attr_version_nvdata_persistent
,
2521 &dev_attr_version_nvdata_default
,
2522 &dev_attr_board_name
,
2523 &dev_attr_board_assembly
,
2524 &dev_attr_board_tracer
,
2526 &dev_attr_device_delay
,
2527 &dev_attr_logging_level
,
2528 &dev_attr_fwfault_debug
,
2529 &dev_attr_fw_queue_depth
,
2530 &dev_attr_host_sas_address
,
2535 * _ctl_device_sas_address_show - sas address
2536 * @cdev - pointer to embedded class device
2537 * @buf - the buffer returned
2539 * This is the sas address for the target
2541 * A sysfs 'read-only' shost attribute.
2544 _ctl_device_sas_address_show(struct device
*dev
, struct device_attribute
*attr
,
2547 struct scsi_device
*sdev
= to_scsi_device(dev
);
2548 struct MPT2SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
2550 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
2551 (unsigned long long)sas_device_priv_data
->sas_target
->sas_address
);
2553 static DEVICE_ATTR(sas_address
, S_IRUGO
, _ctl_device_sas_address_show
, NULL
);
2556 * _ctl_device_handle_show - device handle
2557 * @cdev - pointer to embedded class device
2558 * @buf - the buffer returned
2560 * This is the firmware assigned device handle
2562 * A sysfs 'read-only' shost attribute.
2565 _ctl_device_handle_show(struct device
*dev
, struct device_attribute
*attr
,
2568 struct scsi_device
*sdev
= to_scsi_device(dev
);
2569 struct MPT2SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
2571 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n",
2572 sas_device_priv_data
->sas_target
->handle
);
2574 static DEVICE_ATTR(sas_device_handle
, S_IRUGO
, _ctl_device_handle_show
, NULL
);
2576 struct device_attribute
*mpt2sas_dev_attrs
[] = {
2577 &dev_attr_sas_address
,
2578 &dev_attr_sas_device_handle
,
2582 static const struct file_operations ctl_fops
= {
2583 .owner
= THIS_MODULE
,
2584 .unlocked_ioctl
= _ctl_ioctl
,
2585 .release
= _ctl_release
,
2587 .fasync
= _ctl_fasync
,
2588 #ifdef CONFIG_COMPAT
2589 .compat_ioctl
= _ctl_ioctl_compat
,
2593 static struct miscdevice ctl_dev
= {
2594 .minor
= MPT2SAS_MINOR
,
2595 .name
= MPT2SAS_DEV_NAME
,
2600 * mpt2sas_ctl_init - main entry point for ctl.
2604 mpt2sas_ctl_init(void)
2607 if (misc_register(&ctl_dev
) < 0)
2608 printk(KERN_ERR
"%s can't register misc device [minor=%d]\n",
2609 MPT2SAS_DRIVER_NAME
, MPT2SAS_MINOR
);
2611 init_waitqueue_head(&ctl_poll_wait
);
2615 * mpt2sas_ctl_exit - exit point for ctl
2619 mpt2sas_ctl_exit(void)
2621 struct MPT2SAS_ADAPTER
*ioc
;
2624 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
2626 /* free memory associated to diag buffers */
2627 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
2628 if (!ioc
->diag_buffer
[i
])
2630 pci_free_consistent(ioc
->pdev
, ioc
->diag_buffer_sz
[i
],
2631 ioc
->diag_buffer
[i
], ioc
->diag_buffer_dma
[i
]);
2632 ioc
->diag_buffer
[i
] = NULL
;
2633 ioc
->diag_buffer_status
[i
] = 0;
2636 kfree(ioc
->event_log
);
2638 misc_deregister(&ctl_dev
);