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-2008 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
);
68 * enum block_state - blocking state
69 * @NON_BLOCKING: non blocking
72 * These states are for ioctls that need to wait for a response
73 * from firmware, so they probably require sleep.
80 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
82 * _ctl_display_some_debug - debug routine
83 * @ioc: per adapter object
84 * @smid: system request message index
85 * @calling_function_name: string pass from calling function
86 * @mpi_reply: reply message frame
89 * Function for displaying debug info helpfull when debugging issues
93 _ctl_display_some_debug(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
94 char *calling_function_name
, MPI2DefaultReply_t
*mpi_reply
)
96 Mpi2ConfigRequest_t
*mpi_request
;
99 if (!(ioc
->logging_level
& MPT_DEBUG_IOCTL
))
102 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
103 switch (mpi_request
->Function
) {
104 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
106 Mpi2SCSIIORequest_t
*scsi_request
=
107 (Mpi2SCSIIORequest_t
*)mpi_request
;
109 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
110 "scsi_io, cmd(0x%02x), cdb_len(%d)",
111 scsi_request
->CDB
.CDB32
[0],
112 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
113 desc
= ioc
->tmp_string
;
116 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
119 case MPI2_FUNCTION_IOC_INIT
:
122 case MPI2_FUNCTION_IOC_FACTS
:
125 case MPI2_FUNCTION_CONFIG
:
127 Mpi2ConfigRequest_t
*config_request
=
128 (Mpi2ConfigRequest_t
*)mpi_request
;
130 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
131 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
132 (config_request
->Header
.PageType
&
133 MPI2_CONFIG_PAGETYPE_MASK
), config_request
->ExtPageType
,
134 config_request
->Header
.PageNumber
);
135 desc
= ioc
->tmp_string
;
138 case MPI2_FUNCTION_PORT_FACTS
:
141 case MPI2_FUNCTION_PORT_ENABLE
:
142 desc
= "port_enable";
144 case MPI2_FUNCTION_EVENT_NOTIFICATION
:
145 desc
= "event_notification";
147 case MPI2_FUNCTION_FW_DOWNLOAD
:
148 desc
= "fw_download";
150 case MPI2_FUNCTION_FW_UPLOAD
:
153 case MPI2_FUNCTION_RAID_ACTION
:
154 desc
= "raid_action";
156 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
158 Mpi2SCSIIORequest_t
*scsi_request
=
159 (Mpi2SCSIIORequest_t
*)mpi_request
;
161 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
162 "raid_pass, cmd(0x%02x), cdb_len(%d)",
163 scsi_request
->CDB
.CDB32
[0],
164 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
165 desc
= ioc
->tmp_string
;
168 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
169 desc
= "sas_iounit_cntl";
171 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
174 case MPI2_FUNCTION_DIAG_BUFFER_POST
:
175 desc
= "diag_buffer_post";
177 case MPI2_FUNCTION_DIAG_RELEASE
:
178 desc
= "diag_release";
180 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
181 desc
= "smp_passthrough";
188 printk(MPT2SAS_DEBUG_FMT
"%s: %s, smid(%d)\n",
189 ioc
->name
, calling_function_name
, desc
, smid
);
194 if (mpi_reply
->IOCStatus
|| mpi_reply
->IOCLogInfo
)
195 printk(MPT2SAS_DEBUG_FMT
196 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
197 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
198 le32_to_cpu(mpi_reply
->IOCLogInfo
));
200 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
201 mpi_request
->Function
==
202 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
203 Mpi2SCSIIOReply_t
*scsi_reply
=
204 (Mpi2SCSIIOReply_t
*)mpi_reply
;
205 if (scsi_reply
->SCSIState
|| scsi_reply
->SCSIStatus
)
206 printk(MPT2SAS_DEBUG_FMT
207 "\tscsi_state(0x%02x), scsi_status"
208 "(0x%02x)\n", ioc
->name
,
209 scsi_reply
->SCSIState
,
210 scsi_reply
->SCSIStatus
);
216 * mpt2sas_ctl_done - ctl module completion routine
217 * @ioc: per adapter object
218 * @smid: system request message index
219 * @VF_ID: virtual function id
220 * @reply: reply message frame(lower 32bit addr)
223 * The callback handler when using ioc->ctl_cb_idx.
228 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 VF_ID
, u32 reply
)
230 MPI2DefaultReply_t
*mpi_reply
;
232 if (ioc
->ctl_cmds
.status
== MPT2_CMD_NOT_USED
)
234 if (ioc
->ctl_cmds
.smid
!= smid
)
236 ioc
->ctl_cmds
.status
|= MPT2_CMD_COMPLETE
;
237 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
239 memcpy(ioc
->ctl_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
240 ioc
->ctl_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
242 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
243 _ctl_display_some_debug(ioc
, smid
, "ctl_done", mpi_reply
);
245 ioc
->ctl_cmds
.status
&= ~MPT2_CMD_PENDING
;
246 complete(&ioc
->ctl_cmds
.done
);
250 * _ctl_check_event_type - determines when an event needs logging
251 * @ioc: per adapter object
252 * @event: firmware event
254 * The bitmask in ioc->event_type[] indicates which events should be
255 * be saved in the driver event_log. This bitmask is set by application.
257 * Returns 1 when event should be captured, or zero means no match.
260 _ctl_check_event_type(struct MPT2SAS_ADAPTER
*ioc
, u16 event
)
265 if (event
>= 128 || !event
|| !ioc
->event_log
)
268 desired_event
= (1 << (event
% 32));
272 return desired_event
& ioc
->event_type
[i
];
276 * mpt2sas_ctl_add_to_event_log - add event
277 * @ioc: per adapter object
278 * @mpi_reply: reply message frame
283 mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER
*ioc
,
284 Mpi2EventNotificationReply_t
*mpi_reply
)
286 struct MPT2_IOCTL_EVENTS
*event_log
;
289 u32 sz
, event_data_sz
;
295 event
= le16_to_cpu(mpi_reply
->Event
);
297 if (_ctl_check_event_type(ioc
, event
)) {
299 /* insert entry into circular event_log */
300 i
= ioc
->event_context
% MPT2SAS_CTL_EVENT_LOG_SIZE
;
301 event_log
= ioc
->event_log
;
302 event_log
[i
].event
= event
;
303 event_log
[i
].context
= ioc
->event_context
++;
305 event_data_sz
= le16_to_cpu(mpi_reply
->EventDataLength
)*4;
306 sz
= min_t(u32
, event_data_sz
, MPT2_EVENT_DATA_SIZE
);
307 memset(event_log
[i
].data
, 0, MPT2_EVENT_DATA_SIZE
);
308 memcpy(event_log
[i
].data
, mpi_reply
->EventData
, sz
);
312 /* This aen_event_read_flag flag is set until the
313 * application has read the event log.
314 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
316 if (event
== MPI2_EVENT_LOG_ENTRY_ADDED
||
317 (send_aen
&& !ioc
->aen_event_read_flag
)) {
318 ioc
->aen_event_read_flag
= 1;
319 wake_up_interruptible(&ctl_poll_wait
);
321 kill_fasync(&async_queue
, SIGIO
, POLL_IN
);
326 * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time)
327 * @ioc: per adapter object
328 * @VF_ID: virtual function id
329 * @reply: reply message frame(lower 32bit addr)
330 * Context: interrupt.
332 * This function merely adds a new work task into ioc->firmware_event_thread.
333 * The tasks are worked from _firmware_event_work in user context.
338 mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 VF_ID
, u32 reply
)
340 Mpi2EventNotificationReply_t
*mpi_reply
;
342 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
343 mpt2sas_ctl_add_to_event_log(ioc
, mpi_reply
);
347 * _ctl_verify_adapter - validates ioc_number passed from application
348 * @ioc: per adapter object
349 * @iocpp: The ioc pointer is returned in this.
351 * Return (-1) means error, else ioc_number.
354 _ctl_verify_adapter(int ioc_number
, struct MPT2SAS_ADAPTER
**iocpp
)
356 struct MPT2SAS_ADAPTER
*ioc
;
358 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
359 if (ioc
->id
!= ioc_number
)
369 * mpt2sas_ctl_reset_handler - reset callback handler (for ctl)
370 * @ioc: per adapter object
371 * @reset_phase: phase
373 * The handler for doing any required cleanup or initialization.
375 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
376 * MPT2_IOC_DONE_RESET
379 mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
381 switch (reset_phase
) {
382 case MPT2_IOC_PRE_RESET
:
383 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
384 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
386 case MPT2_IOC_AFTER_RESET
:
387 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
388 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
389 if (ioc
->ctl_cmds
.status
& MPT2_CMD_PENDING
) {
390 ioc
->ctl_cmds
.status
|= MPT2_CMD_RESET
;
391 mpt2sas_base_free_smid(ioc
, ioc
->ctl_cmds
.smid
);
392 complete(&ioc
->ctl_cmds
.done
);
395 case MPT2_IOC_DONE_RESET
:
396 dtmprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
397 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
408 * Called when application request fasyn callback handler.
411 _ctl_fasync(int fd
, struct file
*filep
, int mode
)
413 return fasync_helper(fd
, filep
, mode
, &async_queue
);
421 * Called when application releases the fasyn callback handler.
424 _ctl_release(struct inode
*inode
, struct file
*filep
)
426 return fasync_helper(-1, filep
, 0, &async_queue
);
436 _ctl_poll(struct file
*filep
, poll_table
*wait
)
438 struct MPT2SAS_ADAPTER
*ioc
;
440 poll_wait(filep
, &ctl_poll_wait
, wait
);
442 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
443 if (ioc
->aen_event_read_flag
)
444 return POLLIN
| POLLRDNORM
;
450 * _ctl_do_task_abort - assign an active smid to the abort_task
451 * @ioc: per adapter object
452 * @karg - (struct mpt2_ioctl_command)
453 * @tm_request - pointer to mf from user space
455 * Returns 0 when an smid if found, else fail.
456 * during failure, the reply frame is filled.
459 _ctl_do_task_abort(struct MPT2SAS_ADAPTER
*ioc
, struct mpt2_ioctl_command
*karg
,
460 Mpi2SCSITaskManagementRequest_t
*tm_request
)
465 struct scsi_cmnd
*scmd
;
466 struct MPT2SAS_DEVICE
*priv_data
;
468 Mpi2SCSITaskManagementReply_t
*tm_reply
;
472 lun
= scsilun_to_int((struct scsi_lun
*)tm_request
->LUN
);
474 handle
= le16_to_cpu(tm_request
->DevHandle
);
475 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
476 for (i
= ioc
->request_depth
; i
&& !found
; i
--) {
477 scmd
= ioc
->scsi_lookup
[i
- 1].scmd
;
478 if (scmd
== NULL
|| scmd
->device
== NULL
||
479 scmd
->device
->hostdata
== NULL
)
481 if (lun
!= scmd
->device
->lun
)
483 priv_data
= scmd
->device
->hostdata
;
484 if (priv_data
->sas_target
== NULL
)
486 if (priv_data
->sas_target
->handle
!= handle
)
488 tm_request
->TaskMID
= cpu_to_le16(ioc
->scsi_lookup
[i
- 1].smid
);
491 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
494 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ABORT_TASK: "
495 "DevHandle(0x%04x), lun(%d), no active mid!!\n", ioc
->name
,
496 tm_request
->DevHandle
, lun
));
497 tm_reply
= ioc
->ctl_cmds
.reply
;
498 tm_reply
->DevHandle
= tm_request
->DevHandle
;
499 tm_reply
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
500 tm_reply
->TaskType
= MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
;
501 tm_reply
->MsgLength
= sizeof(Mpi2SCSITaskManagementReply_t
)/4;
502 tm_reply
->VP_ID
= tm_request
->VP_ID
;
503 tm_reply
->VF_ID
= tm_request
->VF_ID
;
504 sz
= min_t(u32
, karg
->max_reply_bytes
, ioc
->reply_sz
);
505 if (copy_to_user(karg
->reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
507 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
512 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"ABORT_TASK: "
513 "DevHandle(0x%04x), lun(%d), smid(%d)\n", ioc
->name
,
514 tm_request
->DevHandle
, lun
, tm_request
->TaskMID
));
519 * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode
520 * @ioc: per adapter object
521 * @karg - (struct mpt2_ioctl_command)
522 * @mf - pointer to mf in user space
523 * @state - NON_BLOCKING or BLOCKING
526 _ctl_do_mpt_command(struct MPT2SAS_ADAPTER
*ioc
,
527 struct mpt2_ioctl_command karg
, void __user
*mf
, enum block_state state
)
529 MPI2RequestHeader_t
*mpi_request
;
530 MPI2DefaultReply_t
*mpi_reply
;
534 unsigned long timeout
, timeleft
;
538 void *priv_sense
= NULL
;
539 void *data_out
= NULL
;
540 dma_addr_t data_out_dma
;
541 size_t data_out_sz
= 0;
542 void *data_in
= NULL
;
543 dma_addr_t data_in_dma
;
544 size_t data_in_sz
= 0;
547 u16 wait_state_count
;
551 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
553 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
556 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
557 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
558 ioc
->name
, __func__
);
563 wait_state_count
= 0;
564 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
565 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
566 if (wait_state_count
++ == 10) {
567 printk(MPT2SAS_ERR_FMT
568 "%s: failed due to ioc not operational\n",
569 ioc
->name
, __func__
);
574 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
575 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
576 "operational state(count=%d)\n", ioc
->name
,
577 __func__
, wait_state_count
);
579 if (wait_state_count
)
580 printk(MPT2SAS_INFO_FMT
"%s: ioc is operational\n",
581 ioc
->name
, __func__
);
583 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
585 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
586 ioc
->name
, __func__
);
592 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
593 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
594 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
595 ioc
->ctl_cmds
.smid
= smid
;
596 data_out_sz
= karg
.data_out_size
;
597 data_in_sz
= karg
.data_in_size
;
599 /* copy in request message frame from user */
600 if (copy_from_user(mpi_request
, mf
, karg
.data_sge_offset
*4)) {
601 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
, __LINE__
,
604 mpt2sas_base_free_smid(ioc
, smid
);
608 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
609 mpi_request
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
610 if (!mpi_request
->FunctionDependent1
||
611 mpi_request
->FunctionDependent1
>
612 cpu_to_le16(ioc
->facts
.MaxDevHandle
)) {
614 mpt2sas_base_free_smid(ioc
, smid
);
619 /* obtain dma-able memory for data transfer */
620 if (data_out_sz
) /* WRITE */ {
621 data_out
= pci_alloc_consistent(ioc
->pdev
, data_out_sz
,
624 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
627 mpt2sas_base_free_smid(ioc
, smid
);
630 if (copy_from_user(data_out
, karg
.data_out_buf_ptr
,
632 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
635 mpt2sas_base_free_smid(ioc
, smid
);
640 if (data_in_sz
) /* READ */ {
641 data_in
= pci_alloc_consistent(ioc
->pdev
, data_in_sz
,
644 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
647 mpt2sas_base_free_smid(ioc
, smid
);
652 /* add scatter gather elements */
653 psge
= (void *)mpi_request
+ (karg
.data_sge_offset
*4);
655 if (!data_out_sz
&& !data_in_sz
) {
656 mpt2sas_base_build_zero_len_sge(ioc
, psge
);
657 } else if (data_out_sz
&& data_in_sz
) {
658 /* WRITE sgel first */
659 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
660 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
661 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
662 ioc
->base_add_sg_single(psge
, sgl_flags
|
663 data_out_sz
, data_out_dma
);
666 psge
+= ioc
->sge_size
;
669 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
670 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
671 MPI2_SGE_FLAGS_END_OF_LIST
);
672 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
673 ioc
->base_add_sg_single(psge
, sgl_flags
|
674 data_in_sz
, data_in_dma
);
675 } else if (data_out_sz
) /* WRITE */ {
676 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
677 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
678 MPI2_SGE_FLAGS_END_OF_LIST
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
679 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
680 ioc
->base_add_sg_single(psge
, sgl_flags
|
681 data_out_sz
, data_out_dma
);
682 } else if (data_in_sz
) /* READ */ {
683 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
684 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
685 MPI2_SGE_FLAGS_END_OF_LIST
);
686 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
687 ioc
->base_add_sg_single(psge
, sgl_flags
|
688 data_in_sz
, data_in_dma
);
691 /* send command to firmware */
692 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
693 _ctl_display_some_debug(ioc
, smid
, "ctl_request", NULL
);
696 switch (mpi_request
->Function
) {
697 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
698 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
700 Mpi2SCSIIORequest_t
*scsiio_request
=
701 (Mpi2SCSIIORequest_t
*)mpi_request
;
702 scsiio_request
->SenseBufferLowAddress
=
703 (u32
)mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
704 priv_sense
= mpt2sas_base_get_sense_buffer(ioc
, smid
);
705 memset(priv_sense
, 0, SCSI_SENSE_BUFFERSIZE
);
706 mpt2sas_base_put_smid_scsi_io(ioc
, smid
, 0,
707 le16_to_cpu(mpi_request
->FunctionDependent1
));
710 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
712 Mpi2SCSITaskManagementRequest_t
*tm_request
=
713 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
715 if (tm_request
->TaskType
==
716 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
) {
717 if (_ctl_do_task_abort(ioc
, &karg
, tm_request
)) {
718 mpt2sas_base_free_smid(ioc
, smid
);
723 mutex_lock(&ioc
->tm_cmds
.mutex
);
724 mpt2sas_scsih_set_tm_flag(ioc
, le16_to_cpu(
725 tm_request
->DevHandle
));
726 mpt2sas_base_put_smid_hi_priority(ioc
, smid
,
730 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
732 Mpi2SmpPassthroughRequest_t
*smp_request
=
733 (Mpi2SmpPassthroughRequest_t
*)mpi_request
;
736 /* ioc determines which port to use */
737 smp_request
->PhysicalPort
= 0xFF;
738 if (smp_request
->PassthroughFlags
&
739 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE
)
740 data
= (u8
*)&smp_request
->SGL
;
744 if (data
[1] == 0x91 && (data
[10] == 1 || data
[10] == 2)) {
745 ioc
->ioc_link_reset_in_progress
= 1;
746 ioc
->ignore_loginfos
= 1;
748 mpt2sas_base_put_smid_default(ioc
, smid
, mpi_request
->VF_ID
);
751 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
753 Mpi2SasIoUnitControlRequest_t
*sasiounit_request
=
754 (Mpi2SasIoUnitControlRequest_t
*)mpi_request
;
756 if (sasiounit_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
757 || sasiounit_request
->Operation
==
758 MPI2_SAS_OP_PHY_LINK_RESET
) {
759 ioc
->ioc_link_reset_in_progress
= 1;
760 ioc
->ignore_loginfos
= 1;
762 mpt2sas_base_put_smid_default(ioc
, smid
, mpi_request
->VF_ID
);
766 mpt2sas_base_put_smid_default(ioc
, smid
, mpi_request
->VF_ID
);
770 if (karg
.timeout
< MPT2_IOCTL_DEFAULT_TIMEOUT
)
771 timeout
= MPT2_IOCTL_DEFAULT_TIMEOUT
;
773 timeout
= karg
.timeout
;
774 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
776 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
777 Mpi2SCSITaskManagementRequest_t
*tm_request
=
778 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
779 mutex_unlock(&ioc
->tm_cmds
.mutex
);
780 mpt2sas_scsih_clear_tm_flag(ioc
, le16_to_cpu(
781 tm_request
->DevHandle
));
782 } else if ((mpi_request
->Function
== MPI2_FUNCTION_SMP_PASSTHROUGH
||
783 mpi_request
->Function
== MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
) &&
784 ioc
->ioc_link_reset_in_progress
) {
785 ioc
->ioc_link_reset_in_progress
= 0;
786 ioc
->ignore_loginfos
= 0;
788 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
789 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
791 _debug_dump_mf(mpi_request
, karg
.data_sge_offset
);
792 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
794 goto issue_host_reset
;
797 mpi_reply
= ioc
->ctl_cmds
.reply
;
798 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
800 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
801 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
&&
802 (ioc
->logging_level
& MPT_DEBUG_TM
)) {
803 Mpi2SCSITaskManagementReply_t
*tm_reply
=
804 (Mpi2SCSITaskManagementReply_t
*)mpi_reply
;
806 printk(MPT2SAS_DEBUG_FMT
"TASK_MGMT: "
807 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
808 "TerminationCount(0x%08x)\n", ioc
->name
,
809 tm_reply
->IOCStatus
, tm_reply
->IOCLogInfo
,
810 tm_reply
->TerminationCount
);
813 /* copy out xdata to user */
815 if (copy_to_user(karg
.data_in_buf_ptr
, data_in
,
817 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
824 /* copy out reply message frame to user */
825 if (karg
.max_reply_bytes
) {
826 sz
= min_t(u32
, karg
.max_reply_bytes
, ioc
->reply_sz
);
827 if (copy_to_user(karg
.reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
829 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
836 /* copy out sense to user */
837 if (karg
.max_sense_bytes
&& (mpi_request
->Function
==
838 MPI2_FUNCTION_SCSI_IO_REQUEST
|| mpi_request
->Function
==
839 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
840 sz
= min_t(u32
, karg
.max_sense_bytes
, SCSI_SENSE_BUFFERSIZE
);
841 if (copy_to_user(karg
.sense_data_ptr
, priv_sense
, sz
)) {
842 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
851 if ((mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
852 mpi_request
->Function
==
853 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
854 printk(MPT2SAS_INFO_FMT
"issue target reset: handle "
855 "= (0x%04x)\n", ioc
->name
,
856 mpi_request
->FunctionDependent1
);
857 mutex_lock(&ioc
->tm_cmds
.mutex
);
858 mpt2sas_scsih_issue_tm(ioc
,
859 mpi_request
->FunctionDependent1
, 0,
860 MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10);
861 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
862 mutex_unlock(&ioc
->tm_cmds
.mutex
);
864 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
870 /* free memory associated with sg buffers */
872 pci_free_consistent(ioc
->pdev
, data_in_sz
, data_in
,
876 pci_free_consistent(ioc
->pdev
, data_out_sz
, data_out
,
879 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
880 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
885 * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode
886 * @arg - user space buffer containing ioctl content
889 _ctl_getiocinfo(void __user
*arg
)
891 struct mpt2_ioctl_iocinfo karg
;
892 struct MPT2SAS_ADAPTER
*ioc
;
895 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
896 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
897 __FILE__
, __LINE__
, __func__
);
900 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
903 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
906 memset(&karg
, 0 , sizeof(karg
));
907 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2
;
909 karg
.port_number
= ioc
->pfacts
[0].PortNumber
;
910 pci_read_config_byte(ioc
->pdev
, PCI_CLASS_REVISION
, &revision
);
911 karg
.hw_rev
= revision
;
912 karg
.pci_id
= ioc
->pdev
->device
;
913 karg
.subsystem_device
= ioc
->pdev
->subsystem_device
;
914 karg
.subsystem_vendor
= ioc
->pdev
->subsystem_vendor
;
915 karg
.pci_information
.u
.bits
.bus
= ioc
->pdev
->bus
->number
;
916 karg
.pci_information
.u
.bits
.device
= PCI_SLOT(ioc
->pdev
->devfn
);
917 karg
.pci_information
.u
.bits
.function
= PCI_FUNC(ioc
->pdev
->devfn
);
918 karg
.pci_information
.segment_id
= pci_domain_nr(ioc
->pdev
->bus
);
919 karg
.firmware_version
= ioc
->facts
.FWVersion
.Word
;
920 strcpy(karg
.driver_version
, MPT2SAS_DRIVER_NAME
);
921 strcat(karg
.driver_version
, "-");
922 strcat(karg
.driver_version
, MPT2SAS_DRIVER_VERSION
);
923 karg
.bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
925 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
926 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
927 __FILE__
, __LINE__
, __func__
);
934 * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode
935 * @arg - user space buffer containing ioctl content
938 _ctl_eventquery(void __user
*arg
)
940 struct mpt2_ioctl_eventquery karg
;
941 struct MPT2SAS_ADAPTER
*ioc
;
943 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
944 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
945 __FILE__
, __LINE__
, __func__
);
948 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
951 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
954 karg
.event_entries
= MPT2SAS_CTL_EVENT_LOG_SIZE
;
955 memcpy(karg
.event_types
, ioc
->event_type
,
956 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
958 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
959 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
960 __FILE__
, __LINE__
, __func__
);
967 * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode
968 * @arg - user space buffer containing ioctl content
971 _ctl_eventenable(void __user
*arg
)
973 struct mpt2_ioctl_eventenable karg
;
974 struct MPT2SAS_ADAPTER
*ioc
;
976 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
977 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
978 __FILE__
, __LINE__
, __func__
);
981 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
984 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
989 memcpy(ioc
->event_type
, karg
.event_types
,
990 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
991 mpt2sas_base_validate_event_type(ioc
, ioc
->event_type
);
993 /* initialize event_log */
994 ioc
->event_context
= 0;
995 ioc
->aen_event_read_flag
= 0;
996 ioc
->event_log
= kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE
,
997 sizeof(struct MPT2_IOCTL_EVENTS
), GFP_KERNEL
);
998 if (!ioc
->event_log
) {
999 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1000 __FILE__
, __LINE__
, __func__
);
1007 * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode
1008 * @arg - user space buffer containing ioctl content
1011 _ctl_eventreport(void __user
*arg
)
1013 struct mpt2_ioctl_eventreport karg
;
1014 struct MPT2SAS_ADAPTER
*ioc
;
1015 u32 number_bytes
, max_events
, max
;
1016 struct mpt2_ioctl_eventreport __user
*uarg
= arg
;
1018 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1019 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1020 __FILE__
, __LINE__
, __func__
);
1023 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1026 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
1029 number_bytes
= karg
.hdr
.max_data_size
-
1030 sizeof(struct mpt2_ioctl_header
);
1031 max_events
= number_bytes
/sizeof(struct MPT2_IOCTL_EVENTS
);
1032 max
= min_t(u32
, MPT2SAS_CTL_EVENT_LOG_SIZE
, max_events
);
1034 /* If fewer than 1 event is requested, there must have
1035 * been some type of error.
1037 if (!max
|| !ioc
->event_log
)
1040 number_bytes
= max
* sizeof(struct MPT2_IOCTL_EVENTS
);
1041 if (copy_to_user(uarg
->event_data
, ioc
->event_log
, number_bytes
)) {
1042 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1043 __FILE__
, __LINE__
, __func__
);
1047 /* reset flag so SIGIO can restart */
1048 ioc
->aen_event_read_flag
= 0;
1053 * _ctl_do_reset - main handler for MPT2HARDRESET opcode
1054 * @arg - user space buffer containing ioctl content
1057 _ctl_do_reset(void __user
*arg
)
1059 struct mpt2_ioctl_diag_reset karg
;
1060 struct MPT2SAS_ADAPTER
*ioc
;
1063 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1064 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1065 __FILE__
, __LINE__
, __func__
);
1068 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1071 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: enter\n", ioc
->name
,
1074 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1076 printk(MPT2SAS_INFO_FMT
"host reset: %s\n",
1077 ioc
->name
, ((!retval
) ? "SUCCESS" : "FAILED"));
1082 * _ctl_btdh_search_sas_device - searching for sas device
1083 * @ioc: per adapter object
1084 * @btdh: btdh ioctl payload
1087 _ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER
*ioc
,
1088 struct mpt2_ioctl_btdh_mapping
*btdh
)
1090 struct _sas_device
*sas_device
;
1091 unsigned long flags
;
1094 if (list_empty(&ioc
->sas_device_list
))
1097 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1098 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
1099 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1100 btdh
->handle
== sas_device
->handle
) {
1101 btdh
->bus
= sas_device
->channel
;
1102 btdh
->id
= sas_device
->id
;
1105 } else if (btdh
->bus
== sas_device
->channel
&& btdh
->id
==
1106 sas_device
->id
&& btdh
->handle
== 0xFFFF) {
1107 btdh
->handle
= sas_device
->handle
;
1113 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1118 * _ctl_btdh_search_raid_device - searching for raid device
1119 * @ioc: per adapter object
1120 * @btdh: btdh ioctl payload
1123 _ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER
*ioc
,
1124 struct mpt2_ioctl_btdh_mapping
*btdh
)
1126 struct _raid_device
*raid_device
;
1127 unsigned long flags
;
1130 if (list_empty(&ioc
->raid_device_list
))
1133 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1134 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1135 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1136 btdh
->handle
== raid_device
->handle
) {
1137 btdh
->bus
= raid_device
->channel
;
1138 btdh
->id
= raid_device
->id
;
1141 } else if (btdh
->bus
== raid_device
->channel
&& btdh
->id
==
1142 raid_device
->id
&& btdh
->handle
== 0xFFFF) {
1143 btdh
->handle
= raid_device
->handle
;
1149 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1154 * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode
1155 * @arg - user space buffer containing ioctl content
1158 _ctl_btdh_mapping(void __user
*arg
)
1160 struct mpt2_ioctl_btdh_mapping karg
;
1161 struct MPT2SAS_ADAPTER
*ioc
;
1164 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1165 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1166 __FILE__
, __LINE__
, __func__
);
1169 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1172 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1175 rc
= _ctl_btdh_search_sas_device(ioc
, &karg
);
1177 _ctl_btdh_search_raid_device(ioc
, &karg
);
1179 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1180 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1181 __FILE__
, __LINE__
, __func__
);
1188 * _ctl_diag_capability - return diag buffer capability
1189 * @ioc: per adapter object
1190 * @buffer_type: specifies either TRACE or SNAPSHOT
1192 * returns 1 when diag buffer support is enabled in firmware
1195 _ctl_diag_capability(struct MPT2SAS_ADAPTER
*ioc
, u8 buffer_type
)
1199 switch (buffer_type
) {
1200 case MPI2_DIAG_BUF_TYPE_TRACE
:
1201 if (ioc
->facts
.IOCCapabilities
&
1202 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
)
1205 case MPI2_DIAG_BUF_TYPE_SNAPSHOT
:
1206 if (ioc
->facts
.IOCCapabilities
&
1207 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
)
1216 * _ctl_diag_register - application register with driver
1217 * @arg - user space buffer containing ioctl content
1218 * @state - NON_BLOCKING or BLOCKING
1220 * This will allow the driver to setup any required buffers that will be
1221 * needed by firmware to communicate with the driver.
1224 _ctl_diag_register(void __user
*arg
, enum block_state state
)
1226 struct mpt2_diag_register karg
;
1227 struct MPT2SAS_ADAPTER
*ioc
;
1229 void *request_data
= NULL
;
1230 dma_addr_t request_data_dma
;
1231 u32 request_data_sz
= 0;
1232 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1233 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1235 unsigned long timeleft
;
1240 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1241 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1242 __FILE__
, __LINE__
, __func__
);
1245 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1248 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1251 buffer_type
= karg
.buffer_type
;
1252 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1253 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1254 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1258 if (ioc
->diag_buffer_status
[buffer_type
] &
1259 MPT2_DIAG_BUFFER_IS_REGISTERED
) {
1260 printk(MPT2SAS_ERR_FMT
"%s: already has a registered "
1261 "buffer for buffer_type(0x%02x)\n", ioc
->name
, __func__
,
1266 if (karg
.requested_buffer_size
% 4) {
1267 printk(MPT2SAS_ERR_FMT
"%s: the requested_buffer_size "
1268 "is not 4 byte aligned\n", ioc
->name
, __func__
);
1272 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
1274 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
1275 return -ERESTARTSYS
;
1277 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1278 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1279 ioc
->name
, __func__
);
1284 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1286 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1287 ioc
->name
, __func__
);
1293 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1294 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1295 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1296 ioc
->ctl_cmds
.smid
= smid
;
1298 request_data
= ioc
->diag_buffer
[buffer_type
];
1299 request_data_sz
= karg
.requested_buffer_size
;
1300 ioc
->unique_id
[buffer_type
] = karg
.unique_id
;
1301 ioc
->diag_buffer_status
[buffer_type
] = 0;
1302 memcpy(ioc
->product_specific
[buffer_type
], karg
.product_specific
,
1303 MPT2_PRODUCT_SPECIFIC_DWORDS
);
1304 ioc
->diagnostic_flags
[buffer_type
] = karg
.diagnostic_flags
;
1307 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1308 if (request_data_sz
!= ioc
->diag_buffer_sz
[buffer_type
]) {
1309 pci_free_consistent(ioc
->pdev
,
1310 ioc
->diag_buffer_sz
[buffer_type
],
1311 request_data
, request_data_dma
);
1312 request_data
= NULL
;
1316 if (request_data
== NULL
) {
1317 ioc
->diag_buffer_sz
[buffer_type
] = 0;
1318 ioc
->diag_buffer_dma
[buffer_type
] = 0;
1319 request_data
= pci_alloc_consistent(
1320 ioc
->pdev
, request_data_sz
, &request_data_dma
);
1321 if (request_data
== NULL
) {
1322 printk(MPT2SAS_ERR_FMT
"%s: failed allocating memory"
1323 " for diag buffers, requested size(%d)\n",
1324 ioc
->name
, __func__
, request_data_sz
);
1325 mpt2sas_base_free_smid(ioc
, smid
);
1328 ioc
->diag_buffer
[buffer_type
] = request_data
;
1329 ioc
->diag_buffer_sz
[buffer_type
] = request_data_sz
;
1330 ioc
->diag_buffer_dma
[buffer_type
] = request_data_dma
;
1333 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1334 mpi_request
->BufferType
= karg
.buffer_type
;
1335 mpi_request
->Flags
= cpu_to_le32(karg
.diagnostic_flags
);
1336 mpi_request
->BufferAddress
= cpu_to_le64(request_data_dma
);
1337 mpi_request
->BufferLength
= cpu_to_le32(request_data_sz
);
1339 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: diag_buffer(0x%p), "
1340 "dma(0x%llx), sz(%d)\n", ioc
->name
, __func__
, request_data
,
1341 (unsigned long long)request_data_dma
, mpi_request
->BufferLength
));
1343 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1344 mpi_request
->ProductSpecific
[i
] =
1345 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1347 mpt2sas_base_put_smid_default(ioc
, smid
, mpi_request
->VF_ID
);
1348 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1349 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1351 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1352 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1354 _debug_dump_mf(mpi_request
,
1355 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
1356 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1358 goto issue_host_reset
;
1361 /* process the completed Reply Message Frame */
1362 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1363 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1364 ioc
->name
, __func__
);
1369 mpi_reply
= ioc
->ctl_cmds
.reply
;
1370 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1372 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1373 ioc
->diag_buffer_status
[buffer_type
] |=
1374 MPT2_DIAG_BUFFER_IS_REGISTERED
;
1375 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: success\n",
1376 ioc
->name
, __func__
));
1378 printk(MPT2SAS_DEBUG_FMT
"%s: ioc_status(0x%04x) "
1379 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1380 ioc_status
, mpi_reply
->IOCLogInfo
);
1386 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1391 if (rc
&& request_data
)
1392 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1393 request_data
, request_data_dma
);
1395 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1396 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
1401 * _ctl_diag_unregister - application unregister with driver
1402 * @arg - user space buffer containing ioctl content
1404 * This will allow the driver to cleanup any memory allocated for diag
1405 * messages and to free up any resources.
1408 _ctl_diag_unregister(void __user
*arg
)
1410 struct mpt2_diag_unregister karg
;
1411 struct MPT2SAS_ADAPTER
*ioc
;
1413 dma_addr_t request_data_dma
;
1414 u32 request_data_sz
;
1417 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1418 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1419 __FILE__
, __LINE__
, __func__
);
1422 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1425 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1428 buffer_type
= karg
.unique_id
& 0x000000ff;
1429 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1430 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1431 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1435 if ((ioc
->diag_buffer_status
[buffer_type
] &
1436 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1437 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1438 "registered\n", ioc
->name
, __func__
, buffer_type
);
1441 if ((ioc
->diag_buffer_status
[buffer_type
] &
1442 MPT2_DIAG_BUFFER_IS_RELEASED
) == 0) {
1443 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) has not been "
1444 "released\n", ioc
->name
, __func__
, buffer_type
);
1448 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1449 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1450 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1454 request_data
= ioc
->diag_buffer
[buffer_type
];
1455 if (!request_data
) {
1456 printk(MPT2SAS_ERR_FMT
"%s: doesn't have memory allocated for "
1457 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1461 request_data_sz
= ioc
->diag_buffer_sz
[buffer_type
];
1462 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1463 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1464 request_data
, request_data_dma
);
1465 ioc
->diag_buffer
[buffer_type
] = NULL
;
1466 ioc
->diag_buffer_status
[buffer_type
] = 0;
1471 * _ctl_diag_query - query relevant info associated with diag buffers
1472 * @arg - user space buffer containing ioctl content
1474 * The application will send only buffer_type and unique_id. Driver will
1475 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1476 * 0x00, the driver will return info specified by Buffer Type.
1479 _ctl_diag_query(void __user
*arg
)
1481 struct mpt2_diag_query karg
;
1482 struct MPT2SAS_ADAPTER
*ioc
;
1487 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1488 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1489 __FILE__
, __LINE__
, __func__
);
1492 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1495 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1498 karg
.application_flags
= 0;
1499 buffer_type
= karg
.buffer_type
;
1501 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1502 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1503 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1507 if ((ioc
->diag_buffer_status
[buffer_type
] &
1508 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1509 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1510 "registered\n", ioc
->name
, __func__
, buffer_type
);
1514 if (karg
.unique_id
& 0xffffff00) {
1515 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1516 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1517 "registered\n", ioc
->name
, __func__
,
1523 request_data
= ioc
->diag_buffer
[buffer_type
];
1524 if (!request_data
) {
1525 printk(MPT2SAS_ERR_FMT
"%s: doesn't have buffer for "
1526 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1530 if (ioc
->diag_buffer_status
[buffer_type
] & MPT2_DIAG_BUFFER_IS_RELEASED
)
1531 karg
.application_flags
= (MPT2_APP_FLAGS_APP_OWNED
|
1532 MPT2_APP_FLAGS_BUFFER_VALID
);
1534 karg
.application_flags
= (MPT2_APP_FLAGS_APP_OWNED
|
1535 MPT2_APP_FLAGS_BUFFER_VALID
|
1536 MPT2_APP_FLAGS_FW_BUFFER_ACCESS
);
1538 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1539 karg
.product_specific
[i
] =
1540 ioc
->product_specific
[buffer_type
][i
];
1542 karg
.total_buffer_size
= ioc
->diag_buffer_sz
[buffer_type
];
1543 karg
.driver_added_buffer_size
= 0;
1544 karg
.unique_id
= ioc
->unique_id
[buffer_type
];
1545 karg
.diagnostic_flags
= ioc
->diagnostic_flags
[buffer_type
];
1547 if (copy_to_user(arg
, &karg
, sizeof(struct mpt2_diag_query
))) {
1548 printk(MPT2SAS_ERR_FMT
"%s: unable to write mpt2_diag_query "
1549 "data @ %p\n", ioc
->name
, __func__
, arg
);
1556 * _ctl_diag_release - request to send Diag Release Message to firmware
1557 * @arg - user space buffer containing ioctl content
1558 * @state - NON_BLOCKING or BLOCKING
1560 * This allows ownership of the specified buffer to returned to the driver,
1561 * allowing an application to read the buffer without fear that firmware is
1562 * overwritting information in the buffer.
1565 _ctl_diag_release(void __user
*arg
, enum block_state state
)
1567 struct mpt2_diag_release karg
;
1568 struct MPT2SAS_ADAPTER
*ioc
;
1571 Mpi2DiagReleaseRequest_t
*mpi_request
;
1572 Mpi2DiagReleaseReply_t
*mpi_reply
;
1574 unsigned long timeleft
;
1579 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1580 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1581 __FILE__
, __LINE__
, __func__
);
1584 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1587 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1590 buffer_type
= karg
.unique_id
& 0x000000ff;
1591 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1592 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1593 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1597 if ((ioc
->diag_buffer_status
[buffer_type
] &
1598 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1599 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1600 "registered\n", ioc
->name
, __func__
, buffer_type
);
1604 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1605 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1606 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1610 if (ioc
->diag_buffer_status
[buffer_type
] &
1611 MPT2_DIAG_BUFFER_IS_RELEASED
) {
1612 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) "
1613 "is already released\n", ioc
->name
, __func__
,
1618 request_data
= ioc
->diag_buffer
[buffer_type
];
1620 if (!request_data
) {
1621 printk(MPT2SAS_ERR_FMT
"%s: doesn't have memory allocated for "
1622 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1626 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
1628 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
1629 return -ERESTARTSYS
;
1631 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1632 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1633 ioc
->name
, __func__
);
1638 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1640 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1641 ioc
->name
, __func__
);
1647 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1648 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1649 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1650 ioc
->ctl_cmds
.smid
= smid
;
1652 mpi_request
->Function
= MPI2_FUNCTION_DIAG_RELEASE
;
1653 mpi_request
->BufferType
= buffer_type
;
1655 mpt2sas_base_put_smid_default(ioc
, smid
, mpi_request
->VF_ID
);
1656 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1657 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1659 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1660 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1662 _debug_dump_mf(mpi_request
,
1663 sizeof(Mpi2DiagReleaseRequest_t
)/4);
1664 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1666 goto issue_host_reset
;
1669 /* process the completed Reply Message Frame */
1670 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1671 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1672 ioc
->name
, __func__
);
1677 mpi_reply
= ioc
->ctl_cmds
.reply
;
1678 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1680 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1681 ioc
->diag_buffer_status
[buffer_type
] |=
1682 MPT2_DIAG_BUFFER_IS_RELEASED
;
1683 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: success\n",
1684 ioc
->name
, __func__
));
1686 printk(MPT2SAS_DEBUG_FMT
"%s: ioc_status(0x%04x) "
1687 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1688 ioc_status
, mpi_reply
->IOCLogInfo
);
1694 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1699 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1700 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
1705 * _ctl_diag_read_buffer - request for copy of the diag buffer
1706 * @arg - user space buffer containing ioctl content
1707 * @state - NON_BLOCKING or BLOCKING
1710 _ctl_diag_read_buffer(void __user
*arg
, enum block_state state
)
1712 struct mpt2_diag_read_buffer karg
;
1713 struct mpt2_diag_read_buffer __user
*uarg
= arg
;
1714 struct MPT2SAS_ADAPTER
*ioc
;
1715 void *request_data
, *diag_data
;
1716 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1717 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1720 unsigned long timeleft
;
1725 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1726 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1727 __FILE__
, __LINE__
, __func__
);
1730 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
1733 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s\n", ioc
->name
,
1736 buffer_type
= karg
.unique_id
& 0x000000ff;
1737 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1738 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1739 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1743 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1744 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1745 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1749 request_data
= ioc
->diag_buffer
[buffer_type
];
1750 if (!request_data
) {
1751 printk(MPT2SAS_ERR_FMT
"%s: doesn't have buffer for "
1752 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1756 if ((karg
.starting_offset
% 4) || (karg
.bytes_to_read
% 4)) {
1757 printk(MPT2SAS_ERR_FMT
"%s: either the starting_offset "
1758 "or bytes_to_read are not 4 byte aligned\n", ioc
->name
,
1763 diag_data
= (void *)(request_data
+ karg
.starting_offset
);
1764 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: diag_buffer(%p), "
1765 "offset(%d), sz(%d)\n", ioc
->name
, __func__
,
1766 diag_data
, karg
.starting_offset
, karg
.bytes_to_read
));
1768 if (copy_to_user((void __user
*)uarg
->diagnostic_data
,
1769 diag_data
, karg
.bytes_to_read
)) {
1770 printk(MPT2SAS_ERR_FMT
"%s: Unable to write "
1771 "mpt_diag_read_buffer_t data @ %p\n", ioc
->name
,
1772 __func__
, diag_data
);
1776 if ((karg
.flags
& MPT2_FLAGS_REREGISTER
) == 0)
1779 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: Reregister "
1780 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
));
1781 if ((ioc
->diag_buffer_status
[buffer_type
] &
1782 MPT2_DIAG_BUFFER_IS_RELEASED
) == 0) {
1783 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: "
1784 "buffer_type(0x%02x) is still registered\n", ioc
->name
,
1785 __func__
, buffer_type
));
1788 /* Get a free request frame and save the message context.
1790 if (state
== NON_BLOCKING
&& !mutex_trylock(&ioc
->ctl_cmds
.mutex
))
1792 else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
))
1793 return -ERESTARTSYS
;
1795 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1796 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1797 ioc
->name
, __func__
);
1802 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1804 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1805 ioc
->name
, __func__
);
1811 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1812 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1813 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1814 ioc
->ctl_cmds
.smid
= smid
;
1816 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1817 mpi_request
->BufferType
= buffer_type
;
1818 mpi_request
->BufferLength
=
1819 cpu_to_le32(ioc
->diag_buffer_sz
[buffer_type
]);
1820 mpi_request
->BufferAddress
=
1821 cpu_to_le64(ioc
->diag_buffer_dma
[buffer_type
]);
1822 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1823 mpi_request
->ProductSpecific
[i
] =
1824 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1826 mpt2sas_base_put_smid_default(ioc
, smid
, mpi_request
->VF_ID
);
1827 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1828 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1830 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1831 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1833 _debug_dump_mf(mpi_request
,
1834 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
1835 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1837 goto issue_host_reset
;
1840 /* process the completed Reply Message Frame */
1841 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1842 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1843 ioc
->name
, __func__
);
1848 mpi_reply
= ioc
->ctl_cmds
.reply
;
1849 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1851 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1852 ioc
->diag_buffer_status
[buffer_type
] |=
1853 MPT2_DIAG_BUFFER_IS_REGISTERED
;
1854 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
"%s: success\n",
1855 ioc
->name
, __func__
));
1857 printk(MPT2SAS_DEBUG_FMT
"%s: ioc_status(0x%04x) "
1858 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1859 ioc_status
, mpi_reply
->IOCLogInfo
);
1865 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1870 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1871 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
1876 * _ctl_ioctl_main - main ioctl entry point
1877 * @file - (struct file)
1878 * @cmd - ioctl opcode
1882 _ctl_ioctl_main(struct file
*file
, unsigned int cmd
, void __user
*arg
)
1884 enum block_state state
;
1886 unsigned long flags
;
1888 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
:
1893 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_iocinfo
))
1894 ret
= _ctl_getiocinfo(arg
);
1898 struct mpt2_ioctl_command karg
;
1899 struct mpt2_ioctl_command __user
*uarg
;
1900 struct MPT2SAS_ADAPTER
*ioc
;
1902 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1903 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1904 __FILE__
, __LINE__
, __func__
);
1908 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 ||
1912 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
1913 if (ioc
->shost_recovery
) {
1914 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
1918 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
1920 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_command
)) {
1922 ret
= _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
, state
);
1926 case MPT2EVENTQUERY
:
1927 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_eventquery
))
1928 ret
= _ctl_eventquery(arg
);
1930 case MPT2EVENTENABLE
:
1931 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_eventenable
))
1932 ret
= _ctl_eventenable(arg
);
1934 case MPT2EVENTREPORT
:
1935 ret
= _ctl_eventreport(arg
);
1938 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_diag_reset
))
1939 ret
= _ctl_do_reset(arg
);
1941 case MPT2BTDHMAPPING
:
1942 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_btdh_mapping
))
1943 ret
= _ctl_btdh_mapping(arg
);
1945 case MPT2DIAGREGISTER
:
1946 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_register
))
1947 ret
= _ctl_diag_register(arg
, state
);
1949 case MPT2DIAGUNREGISTER
:
1950 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_unregister
))
1951 ret
= _ctl_diag_unregister(arg
);
1954 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_query
))
1955 ret
= _ctl_diag_query(arg
);
1957 case MPT2DIAGRELEASE
:
1958 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_release
))
1959 ret
= _ctl_diag_release(arg
, state
);
1961 case MPT2DIAGREADBUFFER
:
1962 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_read_buffer
))
1963 ret
= _ctl_diag_read_buffer(arg
, state
);
1967 struct mpt2_ioctl_command karg
;
1968 struct MPT2SAS_ADAPTER
*ioc
;
1970 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1971 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1972 __FILE__
, __LINE__
, __func__
);
1976 if (_ctl_verify_adapter(karg
.hdr
.ioc_number
, &ioc
) == -1 ||
1980 dctlprintk(ioc
, printk(MPT2SAS_DEBUG_FMT
1981 "unsupported ioctl opcode(0x%08x)\n", ioc
->name
, cmd
));
1989 * _ctl_ioctl - main ioctl entry point (unlocked)
1990 * @file - (struct file)
1991 * @cmd - ioctl opcode
1995 _ctl_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
1999 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
);
2004 #ifdef CONFIG_COMPAT
2006 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2007 * @file - (struct file)
2008 * @cmd - ioctl opcode
2009 * @arg - (struct mpt2_ioctl_command32)
2011 * MPT2COMMAND32 - Handle 32bit applications running on 64bit os.
2014 _ctl_compat_mpt_command(struct file
*file
, unsigned cmd
, unsigned long arg
)
2016 struct mpt2_ioctl_command32 karg32
;
2017 struct mpt2_ioctl_command32 __user
*uarg
;
2018 struct mpt2_ioctl_command karg
;
2019 struct MPT2SAS_ADAPTER
*ioc
;
2020 enum block_state state
;
2021 unsigned long flags
;
2023 if (_IOC_SIZE(cmd
) != sizeof(struct mpt2_ioctl_command32
))
2026 uarg
= (struct mpt2_ioctl_command32 __user
*) arg
;
2028 if (copy_from_user(&karg32
, (char __user
*)arg
, sizeof(karg32
))) {
2029 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
2030 __FILE__
, __LINE__
, __func__
);
2033 if (_ctl_verify_adapter(karg32
.hdr
.ioc_number
, &ioc
) == -1 || !ioc
)
2036 spin_lock_irqsave(&ioc
->ioc_reset_in_progress_lock
, flags
);
2037 if (ioc
->shost_recovery
) {
2038 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
,
2042 spin_unlock_irqrestore(&ioc
->ioc_reset_in_progress_lock
, flags
);
2044 memset(&karg
, 0, sizeof(struct mpt2_ioctl_command
));
2045 karg
.hdr
.ioc_number
= karg32
.hdr
.ioc_number
;
2046 karg
.hdr
.port_number
= karg32
.hdr
.port_number
;
2047 karg
.hdr
.max_data_size
= karg32
.hdr
.max_data_size
;
2048 karg
.timeout
= karg32
.timeout
;
2049 karg
.max_reply_bytes
= karg32
.max_reply_bytes
;
2050 karg
.data_in_size
= karg32
.data_in_size
;
2051 karg
.data_out_size
= karg32
.data_out_size
;
2052 karg
.max_sense_bytes
= karg32
.max_sense_bytes
;
2053 karg
.data_sge_offset
= karg32
.data_sge_offset
;
2054 memcpy(&karg
.reply_frame_buf_ptr
, &karg32
.reply_frame_buf_ptr
,
2056 memcpy(&karg
.data_in_buf_ptr
, &karg32
.data_in_buf_ptr
,
2058 memcpy(&karg
.data_out_buf_ptr
, &karg32
.data_out_buf_ptr
,
2060 memcpy(&karg
.sense_data_ptr
, &karg32
.sense_data_ptr
,
2062 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
: BLOCKING
;
2063 return _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
, state
);
2067 * _ctl_ioctl_compat - main ioctl entry point (compat)
2072 * This routine handles 32 bit applications in 64bit os.
2075 _ctl_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2079 if (cmd
== MPT2COMMAND32
)
2080 ret
= _ctl_compat_mpt_command(file
, cmd
, arg
);
2082 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
);
2088 /* scsi host attributes */
2091 * _ctl_version_fw_show - firmware version
2092 * @cdev - pointer to embedded class device
2093 * @buf - the buffer returned
2095 * A sysfs 'read-only' shost attribute.
2098 _ctl_version_fw_show(struct device
*cdev
, struct device_attribute
*attr
,
2101 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2102 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2104 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2105 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2106 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2107 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2108 ioc
->facts
.FWVersion
.Word
& 0x000000FF);
2110 static DEVICE_ATTR(version_fw
, S_IRUGO
, _ctl_version_fw_show
, NULL
);
2113 * _ctl_version_bios_show - bios version
2114 * @cdev - pointer to embedded class device
2115 * @buf - the buffer returned
2117 * A sysfs 'read-only' shost attribute.
2120 _ctl_version_bios_show(struct device
*cdev
, struct device_attribute
*attr
,
2123 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2124 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2126 u32 version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2128 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2129 (version
& 0xFF000000) >> 24,
2130 (version
& 0x00FF0000) >> 16,
2131 (version
& 0x0000FF00) >> 8,
2132 version
& 0x000000FF);
2134 static DEVICE_ATTR(version_bios
, S_IRUGO
, _ctl_version_bios_show
, NULL
);
2137 * _ctl_version_mpi_show - MPI (message passing interface) version
2138 * @cdev - pointer to embedded class device
2139 * @buf - the buffer returned
2141 * A sysfs 'read-only' shost attribute.
2144 _ctl_version_mpi_show(struct device
*cdev
, struct device_attribute
*attr
,
2147 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2148 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2150 return snprintf(buf
, PAGE_SIZE
, "%03x.%02x\n",
2151 ioc
->facts
.MsgVersion
, ioc
->facts
.HeaderVersion
>> 8);
2153 static DEVICE_ATTR(version_mpi
, S_IRUGO
, _ctl_version_mpi_show
, NULL
);
2156 * _ctl_version_product_show - product name
2157 * @cdev - pointer to embedded class device
2158 * @buf - the buffer returned
2160 * A sysfs 'read-only' shost attribute.
2163 _ctl_version_product_show(struct device
*cdev
, struct device_attribute
*attr
,
2166 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2167 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2169 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.ChipName
);
2171 static DEVICE_ATTR(version_product
, S_IRUGO
,
2172 _ctl_version_product_show
, NULL
);
2175 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2176 * @cdev - pointer to embedded class device
2177 * @buf - the buffer returned
2179 * A sysfs 'read-only' shost attribute.
2182 _ctl_version_nvdata_persistent_show(struct device
*cdev
,
2183 struct device_attribute
*attr
, char *buf
)
2185 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2186 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2188 return snprintf(buf
, PAGE_SIZE
, "%02xh\n",
2189 le16_to_cpu(ioc
->iounit_pg0
.NvdataVersionPersistent
.Word
));
2191 static DEVICE_ATTR(version_nvdata_persistent
, S_IRUGO
,
2192 _ctl_version_nvdata_persistent_show
, NULL
);
2195 * _ctl_version_nvdata_default_show - nvdata default version
2196 * @cdev - pointer to embedded class device
2197 * @buf - the buffer returned
2199 * A sysfs 'read-only' shost attribute.
2202 _ctl_version_nvdata_default_show(struct device
*cdev
,
2203 struct device_attribute
*attr
, char *buf
)
2205 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2206 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2208 return snprintf(buf
, PAGE_SIZE
, "%02xh\n",
2209 le16_to_cpu(ioc
->iounit_pg0
.NvdataVersionDefault
.Word
));
2211 static DEVICE_ATTR(version_nvdata_default
, S_IRUGO
,
2212 _ctl_version_nvdata_default_show
, NULL
);
2215 * _ctl_board_name_show - board name
2216 * @cdev - pointer to embedded class device
2217 * @buf - the buffer returned
2219 * A sysfs 'read-only' shost attribute.
2222 _ctl_board_name_show(struct device
*cdev
, struct device_attribute
*attr
,
2225 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2226 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2228 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardName
);
2230 static DEVICE_ATTR(board_name
, S_IRUGO
, _ctl_board_name_show
, NULL
);
2233 * _ctl_board_assembly_show - board assembly name
2234 * @cdev - pointer to embedded class device
2235 * @buf - the buffer returned
2237 * A sysfs 'read-only' shost attribute.
2240 _ctl_board_assembly_show(struct device
*cdev
, struct device_attribute
*attr
,
2243 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2244 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2246 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardAssembly
);
2248 static DEVICE_ATTR(board_assembly
, S_IRUGO
,
2249 _ctl_board_assembly_show
, NULL
);
2252 * _ctl_board_tracer_show - board tracer number
2253 * @cdev - pointer to embedded class device
2254 * @buf - the buffer returned
2256 * A sysfs 'read-only' shost attribute.
2259 _ctl_board_tracer_show(struct device
*cdev
, struct device_attribute
*attr
,
2262 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2263 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2265 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardTracerNumber
);
2267 static DEVICE_ATTR(board_tracer
, S_IRUGO
,
2268 _ctl_board_tracer_show
, NULL
);
2271 * _ctl_io_delay_show - io missing delay
2272 * @cdev - pointer to embedded class device
2273 * @buf - the buffer returned
2275 * This is for firmware implemention for deboucing device
2278 * A sysfs 'read-only' shost attribute.
2281 _ctl_io_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2284 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2285 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2287 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->io_missing_delay
);
2289 static DEVICE_ATTR(io_delay
, S_IRUGO
,
2290 _ctl_io_delay_show
, NULL
);
2293 * _ctl_device_delay_show - device missing delay
2294 * @cdev - pointer to embedded class device
2295 * @buf - the buffer returned
2297 * This is for firmware implemention for deboucing device
2300 * A sysfs 'read-only' shost attribute.
2303 _ctl_device_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2306 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2307 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2309 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->device_missing_delay
);
2311 static DEVICE_ATTR(device_delay
, S_IRUGO
,
2312 _ctl_device_delay_show
, NULL
);
2315 * _ctl_fw_queue_depth_show - global credits
2316 * @cdev - pointer to embedded class device
2317 * @buf - the buffer returned
2319 * This is firmware queue depth limit
2321 * A sysfs 'read-only' shost attribute.
2324 _ctl_fw_queue_depth_show(struct device
*cdev
, struct device_attribute
*attr
,
2327 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2328 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2330 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->facts
.RequestCredit
);
2332 static DEVICE_ATTR(fw_queue_depth
, S_IRUGO
,
2333 _ctl_fw_queue_depth_show
, NULL
);
2336 * _ctl_sas_address_show - sas address
2337 * @cdev - pointer to embedded class device
2338 * @buf - the buffer returned
2340 * This is the controller sas address
2342 * A sysfs 'read-only' shost attribute.
2345 _ctl_host_sas_address_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
, PAGE_SIZE
, "0x%016llx\n",
2352 (unsigned long long)ioc
->sas_hba
.sas_address
);
2354 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
2355 _ctl_host_sas_address_show
, NULL
);
2358 * _ctl_logging_level_show - logging level
2359 * @cdev - pointer to embedded class device
2360 * @buf - the buffer returned
2362 * A sysfs 'read/write' shost attribute.
2365 _ctl_logging_level_show(struct device
*cdev
, struct device_attribute
*attr
,
2368 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2369 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2371 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", ioc
->logging_level
);
2374 _ctl_logging_level_store(struct device
*cdev
, struct device_attribute
*attr
,
2375 const char *buf
, size_t count
)
2377 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2378 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2381 if (sscanf(buf
, "%x", &val
) != 1)
2384 ioc
->logging_level
= val
;
2385 printk(MPT2SAS_INFO_FMT
"logging_level=%08xh\n", ioc
->name
,
2386 ioc
->logging_level
);
2389 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
,
2390 _ctl_logging_level_show
, _ctl_logging_level_store
);
2392 struct device_attribute
*mpt2sas_host_attrs
[] = {
2393 &dev_attr_version_fw
,
2394 &dev_attr_version_bios
,
2395 &dev_attr_version_mpi
,
2396 &dev_attr_version_product
,
2397 &dev_attr_version_nvdata_persistent
,
2398 &dev_attr_version_nvdata_default
,
2399 &dev_attr_board_name
,
2400 &dev_attr_board_assembly
,
2401 &dev_attr_board_tracer
,
2403 &dev_attr_device_delay
,
2404 &dev_attr_logging_level
,
2405 &dev_attr_fw_queue_depth
,
2406 &dev_attr_host_sas_address
,
2410 /* device attributes */
2413 * _ctl_device_sas_address_show - sas address
2414 * @cdev - pointer to embedded class device
2415 * @buf - the buffer returned
2417 * This is the sas address for the target
2419 * A sysfs 'read-only' shost attribute.
2422 _ctl_device_sas_address_show(struct device
*dev
, struct device_attribute
*attr
,
2425 struct scsi_device
*sdev
= to_scsi_device(dev
);
2426 struct MPT2SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
2428 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
2429 (unsigned long long)sas_device_priv_data
->sas_target
->sas_address
);
2431 static DEVICE_ATTR(sas_address
, S_IRUGO
, _ctl_device_sas_address_show
, NULL
);
2434 * _ctl_device_handle_show - device handle
2435 * @cdev - pointer to embedded class device
2436 * @buf - the buffer returned
2438 * This is the firmware assigned device handle
2440 * A sysfs 'read-only' shost attribute.
2443 _ctl_device_handle_show(struct device
*dev
, struct device_attribute
*attr
,
2446 struct scsi_device
*sdev
= to_scsi_device(dev
);
2447 struct MPT2SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
2449 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n",
2450 sas_device_priv_data
->sas_target
->handle
);
2452 static DEVICE_ATTR(sas_device_handle
, S_IRUGO
, _ctl_device_handle_show
, NULL
);
2454 struct device_attribute
*mpt2sas_dev_attrs
[] = {
2455 &dev_attr_sas_address
,
2456 &dev_attr_sas_device_handle
,
2460 static const struct file_operations ctl_fops
= {
2461 .owner
= THIS_MODULE
,
2462 .unlocked_ioctl
= _ctl_ioctl
,
2463 .release
= _ctl_release
,
2465 .fasync
= _ctl_fasync
,
2466 #ifdef CONFIG_COMPAT
2467 .compat_ioctl
= _ctl_ioctl_compat
,
2471 static struct miscdevice ctl_dev
= {
2472 .minor
= MPT2SAS_MINOR
,
2473 .name
= MPT2SAS_DEV_NAME
,
2478 * mpt2sas_ctl_init - main entry point for ctl.
2482 mpt2sas_ctl_init(void)
2485 if (misc_register(&ctl_dev
) < 0)
2486 printk(KERN_ERR
"%s can't register misc device [minor=%d]\n",
2487 MPT2SAS_DRIVER_NAME
, MPT2SAS_MINOR
);
2489 init_waitqueue_head(&ctl_poll_wait
);
2493 * mpt2sas_ctl_exit - exit point for ctl
2497 mpt2sas_ctl_exit(void)
2499 struct MPT2SAS_ADAPTER
*ioc
;
2502 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
2504 /* free memory associated to diag buffers */
2505 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
2506 if (!ioc
->diag_buffer
[i
])
2508 pci_free_consistent(ioc
->pdev
, ioc
->diag_buffer_sz
[i
],
2509 ioc
->diag_buffer
[i
], ioc
->diag_buffer_dma
[i
]);
2510 ioc
->diag_buffer
[i
] = NULL
;
2511 ioc
->diag_buffer_status
[i
] = 0;
2514 kfree(ioc
->event_log
);
2516 misc_deregister(&ctl_dev
);