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-2013 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/kernel.h>
46 #include <linux/module.h>
47 #include <linux/errno.h>
48 #include <linux/init.h>
49 #include <linux/slab.h>
50 #include <linux/types.h>
51 #include <linux/pci.h>
52 #include <linux/delay.h>
53 #include <linux/mutex.h>
54 #include <linux/compat.h>
55 #include <linux/poll.h>
58 #include <linux/uaccess.h>
60 #include "mpt2sas_base.h"
61 #include "mpt2sas_ctl.h"
63 static DEFINE_MUTEX(_ctl_mutex
);
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_sas_device_find_by_handle - sas device search
86 * @ioc: per adapter object
87 * @handle: sas device handle (assigned by firmware)
88 * Context: Calling function should acquire ioc->sas_device_lock
90 * This searches for sas_device based on sas_address, then return sas_device
93 static struct _sas_device
*
94 _ctl_sas_device_find_by_handle(struct MPT2SAS_ADAPTER
*ioc
, u16 handle
)
96 struct _sas_device
*sas_device
, *r
;
99 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
100 if (sas_device
->handle
!= handle
)
111 * _ctl_display_some_debug - debug routine
112 * @ioc: per adapter object
113 * @smid: system request message index
114 * @calling_function_name: string pass from calling function
115 * @mpi_reply: reply message frame
118 * Function for displaying debug info helpful when debugging issues
122 _ctl_display_some_debug(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
,
123 char *calling_function_name
, MPI2DefaultReply_t
*mpi_reply
)
125 Mpi2ConfigRequest_t
*mpi_request
;
128 if (!(ioc
->logging_level
& MPT_DEBUG_IOCTL
))
131 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
132 switch (mpi_request
->Function
) {
133 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
135 Mpi2SCSIIORequest_t
*scsi_request
=
136 (Mpi2SCSIIORequest_t
*)mpi_request
;
138 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
139 "scsi_io, cmd(0x%02x), cdb_len(%d)",
140 scsi_request
->CDB
.CDB32
[0],
141 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
142 desc
= ioc
->tmp_string
;
145 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
148 case MPI2_FUNCTION_IOC_INIT
:
151 case MPI2_FUNCTION_IOC_FACTS
:
154 case MPI2_FUNCTION_CONFIG
:
156 Mpi2ConfigRequest_t
*config_request
=
157 (Mpi2ConfigRequest_t
*)mpi_request
;
159 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
160 "config, type(0x%02x), ext_type(0x%02x), number(%d)",
161 (config_request
->Header
.PageType
&
162 MPI2_CONFIG_PAGETYPE_MASK
), config_request
->ExtPageType
,
163 config_request
->Header
.PageNumber
);
164 desc
= ioc
->tmp_string
;
167 case MPI2_FUNCTION_PORT_FACTS
:
170 case MPI2_FUNCTION_PORT_ENABLE
:
171 desc
= "port_enable";
173 case MPI2_FUNCTION_EVENT_NOTIFICATION
:
174 desc
= "event_notification";
176 case MPI2_FUNCTION_FW_DOWNLOAD
:
177 desc
= "fw_download";
179 case MPI2_FUNCTION_FW_UPLOAD
:
182 case MPI2_FUNCTION_RAID_ACTION
:
183 desc
= "raid_action";
185 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
187 Mpi2SCSIIORequest_t
*scsi_request
=
188 (Mpi2SCSIIORequest_t
*)mpi_request
;
190 snprintf(ioc
->tmp_string
, MPT_STRING_LENGTH
,
191 "raid_pass, cmd(0x%02x), cdb_len(%d)",
192 scsi_request
->CDB
.CDB32
[0],
193 le16_to_cpu(scsi_request
->IoFlags
) & 0xF);
194 desc
= ioc
->tmp_string
;
197 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
198 desc
= "sas_iounit_cntl";
200 case MPI2_FUNCTION_SATA_PASSTHROUGH
:
203 case MPI2_FUNCTION_DIAG_BUFFER_POST
:
204 desc
= "diag_buffer_post";
206 case MPI2_FUNCTION_DIAG_RELEASE
:
207 desc
= "diag_release";
209 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
210 desc
= "smp_passthrough";
217 printk(MPT2SAS_INFO_FMT
"%s: %s, smid(%d)\n",
218 ioc
->name
, calling_function_name
, desc
, smid
);
223 if (mpi_reply
->IOCStatus
|| mpi_reply
->IOCLogInfo
)
224 printk(MPT2SAS_INFO_FMT
225 "\tiocstatus(0x%04x), loginfo(0x%08x)\n",
226 ioc
->name
, le16_to_cpu(mpi_reply
->IOCStatus
),
227 le32_to_cpu(mpi_reply
->IOCLogInfo
));
229 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
230 mpi_request
->Function
==
231 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
232 Mpi2SCSIIOReply_t
*scsi_reply
=
233 (Mpi2SCSIIOReply_t
*)mpi_reply
;
234 struct _sas_device
*sas_device
= NULL
;
237 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
238 sas_device
= _ctl_sas_device_find_by_handle(ioc
,
239 le16_to_cpu(scsi_reply
->DevHandle
));
241 printk(MPT2SAS_WARN_FMT
"\tsas_address(0x%016llx), "
242 "phy(%d)\n", ioc
->name
, (unsigned long long)
243 sas_device
->sas_address
, sas_device
->phy
);
244 printk(MPT2SAS_WARN_FMT
245 "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
246 ioc
->name
, sas_device
->enclosure_logical_id
,
249 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
250 if (scsi_reply
->SCSIState
|| scsi_reply
->SCSIStatus
)
251 printk(MPT2SAS_INFO_FMT
252 "\tscsi_state(0x%02x), scsi_status"
253 "(0x%02x)\n", ioc
->name
,
254 scsi_reply
->SCSIState
,
255 scsi_reply
->SCSIStatus
);
261 * mpt2sas_ctl_done - ctl module completion routine
262 * @ioc: per adapter object
263 * @smid: system request message index
264 * @msix_index: MSIX table index supplied by the OS
265 * @reply: reply message frame(lower 32bit addr)
268 * The callback handler when using ioc->ctl_cb_idx.
270 * Return 1 meaning mf should be freed from _base_interrupt
271 * 0 means the mf is freed from this function.
274 mpt2sas_ctl_done(struct MPT2SAS_ADAPTER
*ioc
, u16 smid
, u8 msix_index
,
277 MPI2DefaultReply_t
*mpi_reply
;
278 Mpi2SCSIIOReply_t
*scsiio_reply
;
279 const void *sense_data
;
282 if (ioc
->ctl_cmds
.status
== MPT2_CMD_NOT_USED
)
284 if (ioc
->ctl_cmds
.smid
!= smid
)
286 ioc
->ctl_cmds
.status
|= MPT2_CMD_COMPLETE
;
287 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
289 memcpy(ioc
->ctl_cmds
.reply
, mpi_reply
, mpi_reply
->MsgLength
*4);
290 ioc
->ctl_cmds
.status
|= MPT2_CMD_REPLY_VALID
;
292 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
293 mpi_reply
->Function
==
294 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
295 scsiio_reply
= (Mpi2SCSIIOReply_t
*)mpi_reply
;
296 if (scsiio_reply
->SCSIState
&
297 MPI2_SCSI_STATE_AUTOSENSE_VALID
) {
298 sz
= min_t(u32
, SCSI_SENSE_BUFFERSIZE
,
299 le32_to_cpu(scsiio_reply
->SenseCount
));
300 sense_data
= mpt2sas_base_get_sense_buffer(ioc
,
302 memcpy(ioc
->ctl_cmds
.sense
, sense_data
, sz
);
306 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
307 _ctl_display_some_debug(ioc
, smid
, "ctl_done", mpi_reply
);
309 ioc
->ctl_cmds
.status
&= ~MPT2_CMD_PENDING
;
310 complete(&ioc
->ctl_cmds
.done
);
315 * _ctl_check_event_type - determines when an event needs logging
316 * @ioc: per adapter object
317 * @event: firmware event
319 * The bitmask in ioc->event_type[] indicates which events should be
320 * be saved in the driver event_log. This bitmask is set by application.
322 * Returns 1 when event should be captured, or zero means no match.
325 _ctl_check_event_type(struct MPT2SAS_ADAPTER
*ioc
, u16 event
)
330 if (event
>= 128 || !event
|| !ioc
->event_log
)
333 desired_event
= (1 << (event
% 32));
337 return desired_event
& ioc
->event_type
[i
];
341 * mpt2sas_ctl_add_to_event_log - add event
342 * @ioc: per adapter object
343 * @mpi_reply: reply message frame
348 mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER
*ioc
,
349 Mpi2EventNotificationReply_t
*mpi_reply
)
351 struct MPT2_IOCTL_EVENTS
*event_log
;
354 u32 sz
, event_data_sz
;
360 event
= le16_to_cpu(mpi_reply
->Event
);
362 if (_ctl_check_event_type(ioc
, event
)) {
364 /* insert entry into circular event_log */
365 i
= ioc
->event_context
% MPT2SAS_CTL_EVENT_LOG_SIZE
;
366 event_log
= ioc
->event_log
;
367 event_log
[i
].event
= event
;
368 event_log
[i
].context
= ioc
->event_context
++;
370 event_data_sz
= le16_to_cpu(mpi_reply
->EventDataLength
)*4;
371 sz
= min_t(u32
, event_data_sz
, MPT2_EVENT_DATA_SIZE
);
372 memset(event_log
[i
].data
, 0, MPT2_EVENT_DATA_SIZE
);
373 memcpy(event_log
[i
].data
, mpi_reply
->EventData
, sz
);
377 /* This aen_event_read_flag flag is set until the
378 * application has read the event log.
379 * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
381 if (event
== MPI2_EVENT_LOG_ENTRY_ADDED
||
382 (send_aen
&& !ioc
->aen_event_read_flag
)) {
383 ioc
->aen_event_read_flag
= 1;
384 wake_up_interruptible(&ctl_poll_wait
);
386 kill_fasync(&async_queue
, SIGIO
, POLL_IN
);
391 * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time)
392 * @ioc: per adapter object
393 * @msix_index: MSIX table index supplied by the OS
394 * @reply: reply message frame(lower 32bit addr)
395 * Context: interrupt.
397 * This function merely adds a new work task into ioc->firmware_event_thread.
398 * The tasks are worked from _firmware_event_work in user context.
403 mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER
*ioc
, u8 msix_index
,
406 Mpi2EventNotificationReply_t
*mpi_reply
;
408 mpi_reply
= mpt2sas_base_get_reply_virt_addr(ioc
, reply
);
409 if (unlikely(!mpi_reply
)) {
410 printk(MPT2SAS_ERR_FMT
"mpi_reply not valid at %s:%d/%s()!\n",
411 ioc
->name
, __FILE__
, __LINE__
, __func__
);
414 mpt2sas_ctl_add_to_event_log(ioc
, mpi_reply
);
419 * _ctl_verify_adapter - validates ioc_number passed from application
420 * @ioc: per adapter object
421 * @iocpp: The ioc pointer is returned in this.
423 * Return (-1) means error, else ioc_number.
426 _ctl_verify_adapter(int ioc_number
, struct MPT2SAS_ADAPTER
**iocpp
)
428 struct MPT2SAS_ADAPTER
*ioc
;
430 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
431 if (ioc
->id
!= ioc_number
)
441 * mpt2sas_ctl_reset_handler - reset callback handler (for ctl)
442 * @ioc: per adapter object
443 * @reset_phase: phase
445 * The handler for doing any required cleanup or initialization.
447 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
448 * MPT2_IOC_DONE_RESET
451 mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER
*ioc
, int reset_phase
)
456 switch (reset_phase
) {
457 case MPT2_IOC_PRE_RESET
:
458 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
459 "MPT2_IOC_PRE_RESET\n", ioc
->name
, __func__
));
460 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
461 if (!(ioc
->diag_buffer_status
[i
] &
462 MPT2_DIAG_BUFFER_IS_REGISTERED
))
464 if ((ioc
->diag_buffer_status
[i
] &
465 MPT2_DIAG_BUFFER_IS_RELEASED
))
467 _ctl_send_release(ioc
, i
, &issue_reset
);
470 case MPT2_IOC_AFTER_RESET
:
471 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
472 "MPT2_IOC_AFTER_RESET\n", ioc
->name
, __func__
));
473 if (ioc
->ctl_cmds
.status
& MPT2_CMD_PENDING
) {
474 ioc
->ctl_cmds
.status
|= MPT2_CMD_RESET
;
475 mpt2sas_base_free_smid(ioc
, ioc
->ctl_cmds
.smid
);
476 complete(&ioc
->ctl_cmds
.done
);
479 case MPT2_IOC_DONE_RESET
:
480 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
481 "MPT2_IOC_DONE_RESET\n", ioc
->name
, __func__
));
483 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
484 if (!(ioc
->diag_buffer_status
[i
] &
485 MPT2_DIAG_BUFFER_IS_REGISTERED
))
487 if ((ioc
->diag_buffer_status
[i
] &
488 MPT2_DIAG_BUFFER_IS_RELEASED
))
490 ioc
->diag_buffer_status
[i
] |=
491 MPT2_DIAG_BUFFER_IS_DIAG_RESET
;
503 * Called when application request fasyn callback handler.
506 _ctl_fasync(int fd
, struct file
*filep
, int mode
)
508 return fasync_helper(fd
, filep
, mode
, &async_queue
);
518 _ctl_poll(struct file
*filep
, poll_table
*wait
)
520 struct MPT2SAS_ADAPTER
*ioc
;
522 poll_wait(filep
, &ctl_poll_wait
, wait
);
524 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
525 if (ioc
->aen_event_read_flag
)
526 return POLLIN
| POLLRDNORM
;
532 * _ctl_set_task_mid - assign an active smid to tm request
533 * @ioc: per adapter object
534 * @karg - (struct mpt2_ioctl_command)
535 * @tm_request - pointer to mf from user space
537 * Returns 0 when an smid if found, else fail.
538 * during failure, the reply frame is filled.
541 _ctl_set_task_mid(struct MPT2SAS_ADAPTER
*ioc
, struct mpt2_ioctl_command
*karg
,
542 Mpi2SCSITaskManagementRequest_t
*tm_request
)
547 struct scsi_cmnd
*scmd
;
548 struct MPT2SAS_DEVICE
*priv_data
;
550 Mpi2SCSITaskManagementReply_t
*tm_reply
;
555 if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
)
557 else if (tm_request
->TaskType
== MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
)
562 lun
= scsilun_to_int((struct scsi_lun
*)tm_request
->LUN
);
564 handle
= le16_to_cpu(tm_request
->DevHandle
);
565 spin_lock_irqsave(&ioc
->scsi_lookup_lock
, flags
);
566 for (i
= ioc
->scsiio_depth
; i
&& !found
; i
--) {
567 scmd
= ioc
->scsi_lookup
[i
- 1].scmd
;
568 if (scmd
== NULL
|| scmd
->device
== NULL
||
569 scmd
->device
->hostdata
== NULL
)
571 if (lun
!= scmd
->device
->lun
)
573 priv_data
= scmd
->device
->hostdata
;
574 if (priv_data
->sas_target
== NULL
)
576 if (priv_data
->sas_target
->handle
!= handle
)
578 tm_request
->TaskMID
= cpu_to_le16(ioc
->scsi_lookup
[i
- 1].smid
);
581 spin_unlock_irqrestore(&ioc
->scsi_lookup_lock
, flags
);
584 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
585 "handle(0x%04x), lun(%d), no active mid!!\n", ioc
->name
,
586 desc
, le16_to_cpu(tm_request
->DevHandle
), lun
));
587 tm_reply
= ioc
->ctl_cmds
.reply
;
588 tm_reply
->DevHandle
= tm_request
->DevHandle
;
589 tm_reply
->Function
= MPI2_FUNCTION_SCSI_TASK_MGMT
;
590 tm_reply
->TaskType
= tm_request
->TaskType
;
591 tm_reply
->MsgLength
= sizeof(Mpi2SCSITaskManagementReply_t
)/4;
592 tm_reply
->VP_ID
= tm_request
->VP_ID
;
593 tm_reply
->VF_ID
= tm_request
->VF_ID
;
594 sz
= min_t(u32
, karg
->max_reply_bytes
, ioc
->reply_sz
);
595 if (copy_to_user(karg
->reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
597 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
602 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
603 "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc
->name
,
604 desc
, le16_to_cpu(tm_request
->DevHandle
), lun
,
605 le16_to_cpu(tm_request
->TaskMID
)));
610 * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode
611 * @ioc: per adapter object
612 * @karg - (struct mpt2_ioctl_command)
613 * @mf - pointer to mf in user space
616 _ctl_do_mpt_command(struct MPT2SAS_ADAPTER
*ioc
, struct mpt2_ioctl_command karg
,
619 MPI2RequestHeader_t
*mpi_request
= NULL
, *request
;
620 MPI2DefaultReply_t
*mpi_reply
;
624 unsigned long timeout
, timeleft
;
628 void *data_out
= NULL
;
629 dma_addr_t data_out_dma
;
630 size_t data_out_sz
= 0;
631 void *data_in
= NULL
;
632 dma_addr_t data_in_dma
;
633 size_t data_in_sz
= 0;
636 u16 wait_state_count
;
640 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
641 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
642 ioc
->name
, __func__
);
647 wait_state_count
= 0;
648 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
649 while (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
650 if (wait_state_count
++ == 10) {
651 printk(MPT2SAS_ERR_FMT
652 "%s: failed due to ioc not operational\n",
653 ioc
->name
, __func__
);
658 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
659 printk(MPT2SAS_INFO_FMT
"%s: waiting for "
660 "operational state(count=%d)\n", ioc
->name
,
661 __func__
, wait_state_count
);
663 if (wait_state_count
)
664 printk(MPT2SAS_INFO_FMT
"%s: ioc is operational\n",
665 ioc
->name
, __func__
);
667 mpi_request
= kzalloc(ioc
->request_sz
, GFP_KERNEL
);
669 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a memory for "
670 "mpi_request\n", ioc
->name
, __func__
);
675 /* Check for overflow and wraparound */
676 if (karg
.data_sge_offset
* 4 > ioc
->request_sz
||
677 karg
.data_sge_offset
> (UINT_MAX
/ 4)) {
682 /* copy in request message frame from user */
683 if (copy_from_user(mpi_request
, mf
, karg
.data_sge_offset
*4)) {
684 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
, __LINE__
,
690 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
691 smid
= mpt2sas_base_get_smid_hpr(ioc
, ioc
->ctl_cb_idx
);
693 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
694 ioc
->name
, __func__
);
700 smid
= mpt2sas_base_get_smid_scsiio(ioc
, ioc
->ctl_cb_idx
, NULL
);
702 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
703 ioc
->name
, __func__
);
710 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
711 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
712 request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
713 memcpy(request
, mpi_request
, karg
.data_sge_offset
*4);
714 ioc
->ctl_cmds
.smid
= smid
;
715 data_out_sz
= karg
.data_out_size
;
716 data_in_sz
= karg
.data_in_size
;
718 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
719 mpi_request
->Function
== MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
) {
720 if (!le16_to_cpu(mpi_request
->FunctionDependent1
) ||
721 le16_to_cpu(mpi_request
->FunctionDependent1
) >
722 ioc
->facts
.MaxDevHandle
) {
724 mpt2sas_base_free_smid(ioc
, smid
);
729 /* obtain dma-able memory for data transfer */
730 if (data_out_sz
) /* WRITE */ {
731 data_out
= pci_alloc_consistent(ioc
->pdev
, data_out_sz
,
734 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
737 mpt2sas_base_free_smid(ioc
, smid
);
740 if (copy_from_user(data_out
, karg
.data_out_buf_ptr
,
742 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
745 mpt2sas_base_free_smid(ioc
, smid
);
750 if (data_in_sz
) /* READ */ {
751 data_in
= pci_alloc_consistent(ioc
->pdev
, data_in_sz
,
754 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
757 mpt2sas_base_free_smid(ioc
, smid
);
762 /* add scatter gather elements */
763 psge
= (void *)request
+ (karg
.data_sge_offset
*4);
765 if (!data_out_sz
&& !data_in_sz
) {
766 mpt2sas_base_build_zero_len_sge(ioc
, psge
);
767 } else if (data_out_sz
&& data_in_sz
) {
768 /* WRITE sgel first */
769 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
770 MPI2_SGE_FLAGS_END_OF_BUFFER
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
771 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
772 ioc
->base_add_sg_single(psge
, sgl_flags
|
773 data_out_sz
, data_out_dma
);
776 psge
+= ioc
->sge_size
;
779 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
780 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
781 MPI2_SGE_FLAGS_END_OF_LIST
);
782 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
783 ioc
->base_add_sg_single(psge
, sgl_flags
|
784 data_in_sz
, data_in_dma
);
785 } else if (data_out_sz
) /* WRITE */ {
786 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
787 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
788 MPI2_SGE_FLAGS_END_OF_LIST
| MPI2_SGE_FLAGS_HOST_TO_IOC
);
789 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
790 ioc
->base_add_sg_single(psge
, sgl_flags
|
791 data_out_sz
, data_out_dma
);
792 } else if (data_in_sz
) /* READ */ {
793 sgl_flags
= (MPI2_SGE_FLAGS_SIMPLE_ELEMENT
|
794 MPI2_SGE_FLAGS_LAST_ELEMENT
| MPI2_SGE_FLAGS_END_OF_BUFFER
|
795 MPI2_SGE_FLAGS_END_OF_LIST
);
796 sgl_flags
= sgl_flags
<< MPI2_SGE_FLAGS_SHIFT
;
797 ioc
->base_add_sg_single(psge
, sgl_flags
|
798 data_in_sz
, data_in_dma
);
801 /* send command to firmware */
802 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
803 _ctl_display_some_debug(ioc
, smid
, "ctl_request", NULL
);
806 init_completion(&ioc
->ctl_cmds
.done
);
807 switch (mpi_request
->Function
) {
808 case MPI2_FUNCTION_SCSI_IO_REQUEST
:
809 case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
:
811 Mpi2SCSIIORequest_t
*scsiio_request
=
812 (Mpi2SCSIIORequest_t
*)request
;
813 scsiio_request
->SenseBufferLength
= SCSI_SENSE_BUFFERSIZE
;
814 scsiio_request
->SenseBufferLowAddress
=
815 mpt2sas_base_get_sense_buffer_dma(ioc
, smid
);
816 memset(ioc
->ctl_cmds
.sense
, 0, SCSI_SENSE_BUFFERSIZE
);
817 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
)
818 mpt2sas_base_put_smid_scsi_io(ioc
, smid
,
819 le16_to_cpu(mpi_request
->FunctionDependent1
));
821 mpt2sas_base_put_smid_default(ioc
, smid
);
824 case MPI2_FUNCTION_SCSI_TASK_MGMT
:
826 Mpi2SCSITaskManagementRequest_t
*tm_request
=
827 (Mpi2SCSITaskManagementRequest_t
*)request
;
829 dtmprintk(ioc
, printk(MPT2SAS_INFO_FMT
"TASK_MGMT: "
830 "handle(0x%04x), task_type(0x%02x)\n", ioc
->name
,
831 le16_to_cpu(tm_request
->DevHandle
), tm_request
->TaskType
));
833 if (tm_request
->TaskType
==
834 MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK
||
835 tm_request
->TaskType
==
836 MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK
) {
837 if (_ctl_set_task_mid(ioc
, &karg
, tm_request
)) {
838 mpt2sas_base_free_smid(ioc
, smid
);
843 mpt2sas_scsih_set_tm_flag(ioc
, le16_to_cpu(
844 tm_request
->DevHandle
));
845 mpt2sas_base_put_smid_hi_priority(ioc
, smid
);
848 case MPI2_FUNCTION_SMP_PASSTHROUGH
:
850 Mpi2SmpPassthroughRequest_t
*smp_request
=
851 (Mpi2SmpPassthroughRequest_t
*)mpi_request
;
854 /* ioc determines which port to use */
855 smp_request
->PhysicalPort
= 0xFF;
856 if (smp_request
->PassthroughFlags
&
857 MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE
)
858 data
= (u8
*)&smp_request
->SGL
;
860 if (unlikely(data_out
== NULL
)) {
861 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
862 __FILE__
, __LINE__
, __func__
);
863 mpt2sas_base_free_smid(ioc
, smid
);
870 if (data
[1] == 0x91 && (data
[10] == 1 || data
[10] == 2)) {
871 ioc
->ioc_link_reset_in_progress
= 1;
872 ioc
->ignore_loginfos
= 1;
874 mpt2sas_base_put_smid_default(ioc
, smid
);
877 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
:
879 Mpi2SasIoUnitControlRequest_t
*sasiounit_request
=
880 (Mpi2SasIoUnitControlRequest_t
*)mpi_request
;
882 if (sasiounit_request
->Operation
== MPI2_SAS_OP_PHY_HARD_RESET
883 || sasiounit_request
->Operation
==
884 MPI2_SAS_OP_PHY_LINK_RESET
) {
885 ioc
->ioc_link_reset_in_progress
= 1;
886 ioc
->ignore_loginfos
= 1;
888 mpt2sas_base_put_smid_default(ioc
, smid
);
892 mpt2sas_base_put_smid_default(ioc
, smid
);
896 if (karg
.timeout
< MPT2_IOCTL_DEFAULT_TIMEOUT
)
897 timeout
= MPT2_IOCTL_DEFAULT_TIMEOUT
;
899 timeout
= karg
.timeout
;
900 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
902 if (mpi_request
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
) {
903 Mpi2SCSITaskManagementRequest_t
*tm_request
=
904 (Mpi2SCSITaskManagementRequest_t
*)mpi_request
;
905 mpt2sas_scsih_clear_tm_flag(ioc
, le16_to_cpu(
906 tm_request
->DevHandle
));
907 } else if ((mpi_request
->Function
== MPI2_FUNCTION_SMP_PASSTHROUGH
||
908 mpi_request
->Function
== MPI2_FUNCTION_SAS_IO_UNIT_CONTROL
) &&
909 ioc
->ioc_link_reset_in_progress
) {
910 ioc
->ioc_link_reset_in_progress
= 0;
911 ioc
->ignore_loginfos
= 0;
913 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
914 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
916 _debug_dump_mf(mpi_request
, karg
.data_sge_offset
);
917 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
919 goto issue_host_reset
;
922 mpi_reply
= ioc
->ctl_cmds
.reply
;
923 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
925 #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
926 if (mpi_reply
->Function
== MPI2_FUNCTION_SCSI_TASK_MGMT
&&
927 (ioc
->logging_level
& MPT_DEBUG_TM
)) {
928 Mpi2SCSITaskManagementReply_t
*tm_reply
=
929 (Mpi2SCSITaskManagementReply_t
*)mpi_reply
;
931 printk(MPT2SAS_INFO_FMT
"TASK_MGMT: "
932 "IOCStatus(0x%04x), IOCLogInfo(0x%08x), "
933 "TerminationCount(0x%08x)\n", ioc
->name
,
934 le16_to_cpu(tm_reply
->IOCStatus
),
935 le32_to_cpu(tm_reply
->IOCLogInfo
),
936 le32_to_cpu(tm_reply
->TerminationCount
));
939 /* copy out xdata to user */
941 if (copy_to_user(karg
.data_in_buf_ptr
, data_in
,
943 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
950 /* copy out reply message frame to user */
951 if (karg
.max_reply_bytes
) {
952 sz
= min_t(u32
, karg
.max_reply_bytes
, ioc
->reply_sz
);
953 if (copy_to_user(karg
.reply_frame_buf_ptr
, ioc
->ctl_cmds
.reply
,
955 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
962 /* copy out sense to user */
963 if (karg
.max_sense_bytes
&& (mpi_request
->Function
==
964 MPI2_FUNCTION_SCSI_IO_REQUEST
|| mpi_request
->Function
==
965 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
)) {
966 sz
= min_t(u32
, karg
.max_sense_bytes
, SCSI_SENSE_BUFFERSIZE
);
967 if (copy_to_user(karg
.sense_data_ptr
,
968 ioc
->ctl_cmds
.sense
, sz
)) {
969 printk(KERN_ERR
"failure at %s:%d/%s()!\n", __FILE__
,
979 if ((mpi_request
->Function
== MPI2_FUNCTION_SCSI_IO_REQUEST
||
980 mpi_request
->Function
==
981 MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH
||
982 mpi_request
->Function
== MPI2_FUNCTION_SATA_PASSTHROUGH
)) {
983 printk(MPT2SAS_INFO_FMT
"issue target reset: handle "
984 "= (0x%04x)\n", ioc
->name
,
985 le16_to_cpu(mpi_request
->FunctionDependent1
));
986 mpt2sas_halt_firmware(ioc
);
987 mpt2sas_scsih_issue_tm(ioc
,
988 le16_to_cpu(mpi_request
->FunctionDependent1
), 0, 0,
989 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET
, 0, 10,
991 ioc
->tm_cmds
.status
= MPT2_CMD_NOT_USED
;
993 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
999 /* free memory associated with sg buffers */
1001 pci_free_consistent(ioc
->pdev
, data_in_sz
, data_in
,
1005 pci_free_consistent(ioc
->pdev
, data_out_sz
, data_out
,
1009 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1014 * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode
1015 * @ioc: per adapter object
1016 * @arg - user space buffer containing ioctl content
1019 _ctl_getiocinfo(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1021 struct mpt2_ioctl_iocinfo karg
;
1023 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1024 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1025 __FILE__
, __LINE__
, __func__
);
1029 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
1032 memset(&karg
, 0 , sizeof(karg
));
1033 if (ioc
->is_warpdrive
)
1034 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2_SSS6200
;
1036 karg
.adapter_type
= MPT2_IOCTL_INTERFACE_SAS2
;
1038 karg
.port_number
= ioc
->pfacts
[0].PortNumber
;
1039 karg
.hw_rev
= ioc
->pdev
->revision
;
1040 karg
.pci_id
= ioc
->pdev
->device
;
1041 karg
.subsystem_device
= ioc
->pdev
->subsystem_device
;
1042 karg
.subsystem_vendor
= ioc
->pdev
->subsystem_vendor
;
1043 karg
.pci_information
.u
.bits
.bus
= ioc
->pdev
->bus
->number
;
1044 karg
.pci_information
.u
.bits
.device
= PCI_SLOT(ioc
->pdev
->devfn
);
1045 karg
.pci_information
.u
.bits
.function
= PCI_FUNC(ioc
->pdev
->devfn
);
1046 karg
.pci_information
.segment_id
= pci_domain_nr(ioc
->pdev
->bus
);
1047 karg
.firmware_version
= ioc
->facts
.FWVersion
.Word
;
1048 strcpy(karg
.driver_version
, MPT2SAS_DRIVER_NAME
);
1049 strcat(karg
.driver_version
, "-");
1050 strcat(karg
.driver_version
, MPT2SAS_DRIVER_VERSION
);
1051 karg
.bios_version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
1053 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1054 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1055 __FILE__
, __LINE__
, __func__
);
1062 * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode
1063 * @ioc: per adapter object
1064 * @arg - user space buffer containing ioctl content
1067 _ctl_eventquery(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1069 struct mpt2_ioctl_eventquery karg
;
1071 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1072 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1073 __FILE__
, __LINE__
, __func__
);
1077 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
1080 karg
.event_entries
= MPT2SAS_CTL_EVENT_LOG_SIZE
;
1081 memcpy(karg
.event_types
, ioc
->event_type
,
1082 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1084 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1085 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1086 __FILE__
, __LINE__
, __func__
);
1093 * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode
1094 * @ioc: per adapter object
1095 * @arg - user space buffer containing ioctl content
1098 _ctl_eventenable(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1100 struct mpt2_ioctl_eventenable karg
;
1102 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1103 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1104 __FILE__
, __LINE__
, __func__
);
1108 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
1113 memcpy(ioc
->event_type
, karg
.event_types
,
1114 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS
* sizeof(u32
));
1115 mpt2sas_base_validate_event_type(ioc
, ioc
->event_type
);
1117 /* initialize event_log */
1118 ioc
->event_context
= 0;
1119 ioc
->aen_event_read_flag
= 0;
1120 ioc
->event_log
= kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE
,
1121 sizeof(struct MPT2_IOCTL_EVENTS
), GFP_KERNEL
);
1122 if (!ioc
->event_log
) {
1123 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1124 __FILE__
, __LINE__
, __func__
);
1131 * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode
1132 * @ioc: per adapter object
1133 * @arg - user space buffer containing ioctl content
1136 _ctl_eventreport(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1138 struct mpt2_ioctl_eventreport karg
;
1139 u32 number_bytes
, max_events
, max
;
1140 struct mpt2_ioctl_eventreport __user
*uarg
= arg
;
1142 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1143 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1144 __FILE__
, __LINE__
, __func__
);
1148 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
1151 number_bytes
= karg
.hdr
.max_data_size
-
1152 sizeof(struct mpt2_ioctl_header
);
1153 max_events
= number_bytes
/sizeof(struct MPT2_IOCTL_EVENTS
);
1154 max
= min_t(u32
, MPT2SAS_CTL_EVENT_LOG_SIZE
, max_events
);
1156 /* If fewer than 1 event is requested, there must have
1157 * been some type of error.
1159 if (!max
|| !ioc
->event_log
)
1162 number_bytes
= max
* sizeof(struct MPT2_IOCTL_EVENTS
);
1163 if (copy_to_user(uarg
->event_data
, ioc
->event_log
, number_bytes
)) {
1164 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1165 __FILE__
, __LINE__
, __func__
);
1169 /* reset flag so SIGIO can restart */
1170 ioc
->aen_event_read_flag
= 0;
1175 * _ctl_do_reset - main handler for MPT2HARDRESET opcode
1176 * @ioc: per adapter object
1177 * @arg - user space buffer containing ioctl content
1180 _ctl_do_reset(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1182 struct mpt2_ioctl_diag_reset karg
;
1185 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1186 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1187 __FILE__
, __LINE__
, __func__
);
1191 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
1192 ioc
->is_driver_loading
)
1194 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: enter\n", ioc
->name
,
1197 retval
= mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1199 printk(MPT2SAS_INFO_FMT
"host reset: %s\n",
1200 ioc
->name
, ((!retval
) ? "SUCCESS" : "FAILED"));
1205 * _ctl_btdh_search_sas_device - searching for sas device
1206 * @ioc: per adapter object
1207 * @btdh: btdh ioctl payload
1210 _ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER
*ioc
,
1211 struct mpt2_ioctl_btdh_mapping
*btdh
)
1213 struct _sas_device
*sas_device
;
1214 unsigned long flags
;
1217 if (list_empty(&ioc
->sas_device_list
))
1220 spin_lock_irqsave(&ioc
->sas_device_lock
, flags
);
1221 list_for_each_entry(sas_device
, &ioc
->sas_device_list
, list
) {
1222 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1223 btdh
->handle
== sas_device
->handle
) {
1224 btdh
->bus
= sas_device
->channel
;
1225 btdh
->id
= sas_device
->id
;
1228 } else if (btdh
->bus
== sas_device
->channel
&& btdh
->id
==
1229 sas_device
->id
&& btdh
->handle
== 0xFFFF) {
1230 btdh
->handle
= sas_device
->handle
;
1236 spin_unlock_irqrestore(&ioc
->sas_device_lock
, flags
);
1241 * _ctl_btdh_search_raid_device - searching for raid device
1242 * @ioc: per adapter object
1243 * @btdh: btdh ioctl payload
1246 _ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER
*ioc
,
1247 struct mpt2_ioctl_btdh_mapping
*btdh
)
1249 struct _raid_device
*raid_device
;
1250 unsigned long flags
;
1253 if (list_empty(&ioc
->raid_device_list
))
1256 spin_lock_irqsave(&ioc
->raid_device_lock
, flags
);
1257 list_for_each_entry(raid_device
, &ioc
->raid_device_list
, list
) {
1258 if (btdh
->bus
== 0xFFFFFFFF && btdh
->id
== 0xFFFFFFFF &&
1259 btdh
->handle
== raid_device
->handle
) {
1260 btdh
->bus
= raid_device
->channel
;
1261 btdh
->id
= raid_device
->id
;
1264 } else if (btdh
->bus
== raid_device
->channel
&& btdh
->id
==
1265 raid_device
->id
&& btdh
->handle
== 0xFFFF) {
1266 btdh
->handle
= raid_device
->handle
;
1272 spin_unlock_irqrestore(&ioc
->raid_device_lock
, flags
);
1277 * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode
1278 * @ioc: per adapter object
1279 * @arg - user space buffer containing ioctl content
1282 _ctl_btdh_mapping(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1284 struct mpt2_ioctl_btdh_mapping karg
;
1287 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1288 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1289 __FILE__
, __LINE__
, __func__
);
1293 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1296 rc
= _ctl_btdh_search_sas_device(ioc
, &karg
);
1298 _ctl_btdh_search_raid_device(ioc
, &karg
);
1300 if (copy_to_user(arg
, &karg
, sizeof(karg
))) {
1301 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1302 __FILE__
, __LINE__
, __func__
);
1309 * _ctl_diag_capability - return diag buffer capability
1310 * @ioc: per adapter object
1311 * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED
1313 * returns 1 when diag buffer support is enabled in firmware
1316 _ctl_diag_capability(struct MPT2SAS_ADAPTER
*ioc
, u8 buffer_type
)
1320 switch (buffer_type
) {
1321 case MPI2_DIAG_BUF_TYPE_TRACE
:
1322 if (ioc
->facts
.IOCCapabilities
&
1323 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER
)
1326 case MPI2_DIAG_BUF_TYPE_SNAPSHOT
:
1327 if (ioc
->facts
.IOCCapabilities
&
1328 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER
)
1331 case MPI2_DIAG_BUF_TYPE_EXTENDED
:
1332 if (ioc
->facts
.IOCCapabilities
&
1333 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER
)
1341 * _ctl_diag_register_2 - wrapper for registering diag buffer support
1342 * @ioc: per adapter object
1343 * @diag_register: the diag_register struct passed in from user space
1347 _ctl_diag_register_2(struct MPT2SAS_ADAPTER
*ioc
,
1348 struct mpt2_diag_register
*diag_register
)
1351 void *request_data
= NULL
;
1352 dma_addr_t request_data_dma
;
1353 u32 request_data_sz
= 0;
1354 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1355 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1357 unsigned long timeleft
;
1362 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1365 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1366 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1367 ioc
->name
, __func__
);
1372 buffer_type
= diag_register
->buffer_type
;
1373 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1374 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1375 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1379 if (ioc
->diag_buffer_status
[buffer_type
] &
1380 MPT2_DIAG_BUFFER_IS_REGISTERED
) {
1381 printk(MPT2SAS_ERR_FMT
"%s: already has a registered "
1382 "buffer for buffer_type(0x%02x)\n", ioc
->name
, __func__
,
1387 if (diag_register
->requested_buffer_size
% 4) {
1388 printk(MPT2SAS_ERR_FMT
"%s: the requested_buffer_size "
1389 "is not 4 byte aligned\n", ioc
->name
, __func__
);
1393 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1395 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1396 ioc
->name
, __func__
);
1402 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1403 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1404 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1405 ioc
->ctl_cmds
.smid
= smid
;
1407 request_data
= ioc
->diag_buffer
[buffer_type
];
1408 request_data_sz
= diag_register
->requested_buffer_size
;
1409 ioc
->unique_id
[buffer_type
] = diag_register
->unique_id
;
1410 ioc
->diag_buffer_status
[buffer_type
] = 0;
1411 memcpy(ioc
->product_specific
[buffer_type
],
1412 diag_register
->product_specific
, MPT2_PRODUCT_SPECIFIC_DWORDS
);
1413 ioc
->diagnostic_flags
[buffer_type
] = diag_register
->diagnostic_flags
;
1416 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1417 if (request_data_sz
!= ioc
->diag_buffer_sz
[buffer_type
]) {
1418 pci_free_consistent(ioc
->pdev
,
1419 ioc
->diag_buffer_sz
[buffer_type
],
1420 request_data
, request_data_dma
);
1421 request_data
= NULL
;
1425 if (request_data
== NULL
) {
1426 ioc
->diag_buffer_sz
[buffer_type
] = 0;
1427 ioc
->diag_buffer_dma
[buffer_type
] = 0;
1428 request_data
= pci_alloc_consistent(
1429 ioc
->pdev
, request_data_sz
, &request_data_dma
);
1430 if (request_data
== NULL
) {
1431 printk(MPT2SAS_ERR_FMT
"%s: failed allocating memory"
1432 " for diag buffers, requested size(%d)\n",
1433 ioc
->name
, __func__
, request_data_sz
);
1434 mpt2sas_base_free_smid(ioc
, smid
);
1437 ioc
->diag_buffer
[buffer_type
] = request_data
;
1438 ioc
->diag_buffer_sz
[buffer_type
] = request_data_sz
;
1439 ioc
->diag_buffer_dma
[buffer_type
] = request_data_dma
;
1442 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
1443 mpi_request
->BufferType
= diag_register
->buffer_type
;
1444 mpi_request
->Flags
= cpu_to_le32(diag_register
->diagnostic_flags
);
1445 mpi_request
->BufferAddress
= cpu_to_le64(request_data_dma
);
1446 mpi_request
->BufferLength
= cpu_to_le32(request_data_sz
);
1447 mpi_request
->VF_ID
= 0; /* TODO */
1448 mpi_request
->VP_ID
= 0;
1450 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: diag_buffer(0x%p), "
1451 "dma(0x%llx), sz(%d)\n", ioc
->name
, __func__
, request_data
,
1452 (unsigned long long)request_data_dma
,
1453 le32_to_cpu(mpi_request
->BufferLength
)));
1455 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1456 mpi_request
->ProductSpecific
[i
] =
1457 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
1459 init_completion(&ioc
->ctl_cmds
.done
);
1460 mpt2sas_base_put_smid_default(ioc
, smid
);
1461 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1462 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1464 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1465 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1467 _debug_dump_mf(mpi_request
,
1468 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
1469 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1471 goto issue_host_reset
;
1474 /* process the completed Reply Message Frame */
1475 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1476 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1477 ioc
->name
, __func__
);
1482 mpi_reply
= ioc
->ctl_cmds
.reply
;
1483 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1485 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1486 ioc
->diag_buffer_status
[buffer_type
] |=
1487 MPT2_DIAG_BUFFER_IS_REGISTERED
;
1488 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: success\n",
1489 ioc
->name
, __func__
));
1491 printk(MPT2SAS_INFO_FMT
"%s: ioc_status(0x%04x) "
1492 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1493 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
1499 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1504 if (rc
&& request_data
)
1505 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1506 request_data
, request_data_dma
);
1508 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1513 * mpt2sas_enable_diag_buffer - enabling diag_buffers support driver load time
1514 * @ioc: per adapter object
1515 * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1
1517 * This is called when command line option diag_buffer_enable is enabled
1518 * at driver load time.
1521 mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER
*ioc
, u8 bits_to_register
)
1523 struct mpt2_diag_register diag_register
;
1525 memset(&diag_register
, 0, sizeof(struct mpt2_diag_register
));
1527 if (bits_to_register
& 1) {
1528 printk(MPT2SAS_INFO_FMT
"registering trace buffer support\n",
1530 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
1531 /* register for 1MB buffers */
1532 diag_register
.requested_buffer_size
= (1024 * 1024);
1533 diag_register
.unique_id
= 0x7075900;
1534 _ctl_diag_register_2(ioc
, &diag_register
);
1537 if (bits_to_register
& 2) {
1538 printk(MPT2SAS_INFO_FMT
"registering snapshot buffer support\n",
1540 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_SNAPSHOT
;
1541 /* register for 2MB buffers */
1542 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1543 diag_register
.unique_id
= 0x7075901;
1544 _ctl_diag_register_2(ioc
, &diag_register
);
1547 if (bits_to_register
& 4) {
1548 printk(MPT2SAS_INFO_FMT
"registering extended buffer support\n",
1550 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_EXTENDED
;
1551 /* register for 2MB buffers */
1552 diag_register
.requested_buffer_size
= 2 * (1024 * 1024);
1553 diag_register
.unique_id
= 0x7075901;
1554 _ctl_diag_register_2(ioc
, &diag_register
);
1559 * _ctl_diag_register - application register with driver
1560 * @ioc: per adapter object
1561 * @arg - user space buffer containing ioctl content
1563 * This will allow the driver to setup any required buffers that will be
1564 * needed by firmware to communicate with the driver.
1567 _ctl_diag_register(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1569 struct mpt2_diag_register karg
;
1572 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1573 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1574 __FILE__
, __LINE__
, __func__
);
1578 rc
= _ctl_diag_register_2(ioc
, &karg
);
1583 * _ctl_diag_unregister - application unregister with driver
1584 * @ioc: per adapter object
1585 * @arg - user space buffer containing ioctl content
1587 * This will allow the driver to cleanup any memory allocated for diag
1588 * messages and to free up any resources.
1591 _ctl_diag_unregister(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1593 struct mpt2_diag_unregister karg
;
1595 dma_addr_t request_data_dma
;
1596 u32 request_data_sz
;
1599 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1600 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1601 __FILE__
, __LINE__
, __func__
);
1605 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1608 buffer_type
= karg
.unique_id
& 0x000000ff;
1609 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1610 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1611 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1615 if ((ioc
->diag_buffer_status
[buffer_type
] &
1616 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1617 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1618 "registered\n", ioc
->name
, __func__
, buffer_type
);
1621 if ((ioc
->diag_buffer_status
[buffer_type
] &
1622 MPT2_DIAG_BUFFER_IS_RELEASED
) == 0) {
1623 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) has not been "
1624 "released\n", ioc
->name
, __func__
, buffer_type
);
1628 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1629 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1630 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1634 request_data
= ioc
->diag_buffer
[buffer_type
];
1635 if (!request_data
) {
1636 printk(MPT2SAS_ERR_FMT
"%s: doesn't have memory allocated for "
1637 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1641 request_data_sz
= ioc
->diag_buffer_sz
[buffer_type
];
1642 request_data_dma
= ioc
->diag_buffer_dma
[buffer_type
];
1643 pci_free_consistent(ioc
->pdev
, request_data_sz
,
1644 request_data
, request_data_dma
);
1645 ioc
->diag_buffer
[buffer_type
] = NULL
;
1646 ioc
->diag_buffer_status
[buffer_type
] = 0;
1651 * _ctl_diag_query - query relevant info associated with diag buffers
1652 * @ioc: per adapter object
1653 * @arg - user space buffer containing ioctl content
1655 * The application will send only buffer_type and unique_id. Driver will
1656 * inspect unique_id first, if valid, fill in all the info. If unique_id is
1657 * 0x00, the driver will return info specified by Buffer Type.
1660 _ctl_diag_query(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1662 struct mpt2_diag_query karg
;
1667 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1668 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1669 __FILE__
, __LINE__
, __func__
);
1673 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1676 karg
.application_flags
= 0;
1677 buffer_type
= karg
.buffer_type
;
1679 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1680 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1681 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1685 if ((ioc
->diag_buffer_status
[buffer_type
] &
1686 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1687 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1688 "registered\n", ioc
->name
, __func__
, buffer_type
);
1692 if (karg
.unique_id
& 0xffffff00) {
1693 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1694 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1695 "registered\n", ioc
->name
, __func__
,
1701 request_data
= ioc
->diag_buffer
[buffer_type
];
1702 if (!request_data
) {
1703 printk(MPT2SAS_ERR_FMT
"%s: doesn't have buffer for "
1704 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1708 if (ioc
->diag_buffer_status
[buffer_type
] & MPT2_DIAG_BUFFER_IS_RELEASED
)
1709 karg
.application_flags
= (MPT2_APP_FLAGS_APP_OWNED
|
1710 MPT2_APP_FLAGS_BUFFER_VALID
);
1712 karg
.application_flags
= (MPT2_APP_FLAGS_APP_OWNED
|
1713 MPT2_APP_FLAGS_BUFFER_VALID
|
1714 MPT2_APP_FLAGS_FW_BUFFER_ACCESS
);
1716 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
1717 karg
.product_specific
[i
] =
1718 ioc
->product_specific
[buffer_type
][i
];
1720 karg
.total_buffer_size
= ioc
->diag_buffer_sz
[buffer_type
];
1721 karg
.driver_added_buffer_size
= 0;
1722 karg
.unique_id
= ioc
->unique_id
[buffer_type
];
1723 karg
.diagnostic_flags
= ioc
->diagnostic_flags
[buffer_type
];
1725 if (copy_to_user(arg
, &karg
, sizeof(struct mpt2_diag_query
))) {
1726 printk(MPT2SAS_ERR_FMT
"%s: unable to write mpt2_diag_query "
1727 "data @ %p\n", ioc
->name
, __func__
, arg
);
1734 * _ctl_send_release - Diag Release Message
1735 * @ioc: per adapter object
1736 * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED
1737 * @issue_reset - specifies whether host reset is required.
1741 _ctl_send_release(struct MPT2SAS_ADAPTER
*ioc
, u8 buffer_type
, u8
*issue_reset
)
1743 Mpi2DiagReleaseRequest_t
*mpi_request
;
1744 Mpi2DiagReleaseReply_t
*mpi_reply
;
1749 unsigned long timeleft
;
1751 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1757 ioc_state
= mpt2sas_base_get_iocstate(ioc
, 1);
1758 if (ioc_state
!= MPI2_IOC_STATE_OPERATIONAL
) {
1759 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
1760 "skipping due to FAULT state\n", ioc
->name
,
1766 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
1767 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
1768 ioc
->name
, __func__
);
1773 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
1775 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
1776 ioc
->name
, __func__
);
1781 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
1782 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
1783 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
1784 ioc
->ctl_cmds
.smid
= smid
;
1786 mpi_request
->Function
= MPI2_FUNCTION_DIAG_RELEASE
;
1787 mpi_request
->BufferType
= buffer_type
;
1788 mpi_request
->VF_ID
= 0; /* TODO */
1789 mpi_request
->VP_ID
= 0;
1791 init_completion(&ioc
->ctl_cmds
.done
);
1792 mpt2sas_base_put_smid_default(ioc
, smid
);
1793 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
1794 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
1796 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
1797 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
1799 _debug_dump_mf(mpi_request
,
1800 sizeof(Mpi2DiagReleaseRequest_t
)/4);
1801 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
1807 /* process the completed Reply Message Frame */
1808 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
1809 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
1810 ioc
->name
, __func__
);
1815 mpi_reply
= ioc
->ctl_cmds
.reply
;
1816 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
1818 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
1819 ioc
->diag_buffer_status
[buffer_type
] |=
1820 MPT2_DIAG_BUFFER_IS_RELEASED
;
1821 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: success\n",
1822 ioc
->name
, __func__
));
1824 printk(MPT2SAS_INFO_FMT
"%s: ioc_status(0x%04x) "
1825 "log_info(0x%08x)\n", ioc
->name
, __func__
,
1826 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
1831 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
1836 * _ctl_diag_release - request to send Diag Release Message to firmware
1837 * @arg - user space buffer containing ioctl content
1839 * This allows ownership of the specified buffer to returned to the driver,
1840 * allowing an application to read the buffer without fear that firmware is
1841 * overwritting information in the buffer.
1844 _ctl_diag_release(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1846 struct mpt2_diag_release karg
;
1852 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1853 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1854 __FILE__
, __LINE__
, __func__
);
1858 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1861 buffer_type
= karg
.unique_id
& 0x000000ff;
1862 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1863 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1864 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1868 if ((ioc
->diag_buffer_status
[buffer_type
] &
1869 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
1870 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) is not "
1871 "registered\n", ioc
->name
, __func__
, buffer_type
);
1875 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1876 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1877 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1881 if (ioc
->diag_buffer_status
[buffer_type
] &
1882 MPT2_DIAG_BUFFER_IS_RELEASED
) {
1883 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) "
1884 "is already released\n", ioc
->name
, __func__
,
1889 request_data
= ioc
->diag_buffer
[buffer_type
];
1891 if (!request_data
) {
1892 printk(MPT2SAS_ERR_FMT
"%s: doesn't have memory allocated for "
1893 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1897 /* buffers were released by due to host reset */
1898 if ((ioc
->diag_buffer_status
[buffer_type
] &
1899 MPT2_DIAG_BUFFER_IS_DIAG_RESET
)) {
1900 ioc
->diag_buffer_status
[buffer_type
] |=
1901 MPT2_DIAG_BUFFER_IS_RELEASED
;
1902 ioc
->diag_buffer_status
[buffer_type
] &=
1903 ~MPT2_DIAG_BUFFER_IS_DIAG_RESET
;
1904 printk(MPT2SAS_ERR_FMT
"%s: buffer_type(0x%02x) "
1905 "was released due to host reset\n", ioc
->name
, __func__
,
1910 rc
= _ctl_send_release(ioc
, buffer_type
, &issue_reset
);
1913 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
1920 * _ctl_diag_read_buffer - request for copy of the diag buffer
1921 * @ioc: per adapter object
1922 * @arg - user space buffer containing ioctl content
1925 _ctl_diag_read_buffer(struct MPT2SAS_ADAPTER
*ioc
, void __user
*arg
)
1927 struct mpt2_diag_read_buffer karg
;
1928 struct mpt2_diag_read_buffer __user
*uarg
= arg
;
1929 void *request_data
, *diag_data
;
1930 Mpi2DiagBufferPostRequest_t
*mpi_request
;
1931 Mpi2DiagBufferPostReply_t
*mpi_reply
;
1934 unsigned long timeleft
, request_size
, copy_size
;
1939 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
1940 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
1941 __FILE__
, __LINE__
, __func__
);
1945 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s\n", ioc
->name
,
1948 buffer_type
= karg
.unique_id
& 0x000000ff;
1949 if (!_ctl_diag_capability(ioc
, buffer_type
)) {
1950 printk(MPT2SAS_ERR_FMT
"%s: doesn't have capability for "
1951 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1955 if (karg
.unique_id
!= ioc
->unique_id
[buffer_type
]) {
1956 printk(MPT2SAS_ERR_FMT
"%s: unique_id(0x%08x) is not "
1957 "registered\n", ioc
->name
, __func__
, karg
.unique_id
);
1961 request_data
= ioc
->diag_buffer
[buffer_type
];
1962 if (!request_data
) {
1963 printk(MPT2SAS_ERR_FMT
"%s: doesn't have buffer for "
1964 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
);
1968 request_size
= ioc
->diag_buffer_sz
[buffer_type
];
1970 if ((karg
.starting_offset
% 4) || (karg
.bytes_to_read
% 4)) {
1971 printk(MPT2SAS_ERR_FMT
"%s: either the starting_offset "
1972 "or bytes_to_read are not 4 byte aligned\n", ioc
->name
,
1977 if (karg
.starting_offset
> request_size
)
1980 diag_data
= (void *)(request_data
+ karg
.starting_offset
);
1981 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: diag_buffer(%p), "
1982 "offset(%d), sz(%d)\n", ioc
->name
, __func__
,
1983 diag_data
, karg
.starting_offset
, karg
.bytes_to_read
));
1985 /* Truncate data on requests that are too large */
1986 if ((diag_data
+ karg
.bytes_to_read
< diag_data
) ||
1987 (diag_data
+ karg
.bytes_to_read
> request_data
+ request_size
))
1988 copy_size
= request_size
- karg
.starting_offset
;
1990 copy_size
= karg
.bytes_to_read
;
1992 if (copy_to_user((void __user
*)uarg
->diagnostic_data
,
1993 diag_data
, copy_size
)) {
1994 printk(MPT2SAS_ERR_FMT
"%s: Unable to write "
1995 "mpt_diag_read_buffer_t data @ %p\n", ioc
->name
,
1996 __func__
, diag_data
);
2000 if ((karg
.flags
& MPT2_FLAGS_REREGISTER
) == 0)
2003 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: Reregister "
2004 "buffer_type(0x%02x)\n", ioc
->name
, __func__
, buffer_type
));
2005 if ((ioc
->diag_buffer_status
[buffer_type
] &
2006 MPT2_DIAG_BUFFER_IS_RELEASED
) == 0) {
2007 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: "
2008 "buffer_type(0x%02x) is still registered\n", ioc
->name
,
2009 __func__
, buffer_type
));
2012 /* Get a free request frame and save the message context.
2015 if (ioc
->ctl_cmds
.status
!= MPT2_CMD_NOT_USED
) {
2016 printk(MPT2SAS_ERR_FMT
"%s: ctl_cmd in use\n",
2017 ioc
->name
, __func__
);
2022 smid
= mpt2sas_base_get_smid(ioc
, ioc
->ctl_cb_idx
);
2024 printk(MPT2SAS_ERR_FMT
"%s: failed obtaining a smid\n",
2025 ioc
->name
, __func__
);
2031 ioc
->ctl_cmds
.status
= MPT2_CMD_PENDING
;
2032 memset(ioc
->ctl_cmds
.reply
, 0, ioc
->reply_sz
);
2033 mpi_request
= mpt2sas_base_get_msg_frame(ioc
, smid
);
2034 ioc
->ctl_cmds
.smid
= smid
;
2036 mpi_request
->Function
= MPI2_FUNCTION_DIAG_BUFFER_POST
;
2037 mpi_request
->BufferType
= buffer_type
;
2038 mpi_request
->BufferLength
=
2039 cpu_to_le32(ioc
->diag_buffer_sz
[buffer_type
]);
2040 mpi_request
->BufferAddress
=
2041 cpu_to_le64(ioc
->diag_buffer_dma
[buffer_type
]);
2042 for (i
= 0; i
< MPT2_PRODUCT_SPECIFIC_DWORDS
; i
++)
2043 mpi_request
->ProductSpecific
[i
] =
2044 cpu_to_le32(ioc
->product_specific
[buffer_type
][i
]);
2045 mpi_request
->VF_ID
= 0; /* TODO */
2046 mpi_request
->VP_ID
= 0;
2048 init_completion(&ioc
->ctl_cmds
.done
);
2049 mpt2sas_base_put_smid_default(ioc
, smid
);
2050 timeleft
= wait_for_completion_timeout(&ioc
->ctl_cmds
.done
,
2051 MPT2_IOCTL_DEFAULT_TIMEOUT
*HZ
);
2053 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_COMPLETE
)) {
2054 printk(MPT2SAS_ERR_FMT
"%s: timeout\n", ioc
->name
,
2056 _debug_dump_mf(mpi_request
,
2057 sizeof(Mpi2DiagBufferPostRequest_t
)/4);
2058 if (!(ioc
->ctl_cmds
.status
& MPT2_CMD_RESET
))
2060 goto issue_host_reset
;
2063 /* process the completed Reply Message Frame */
2064 if ((ioc
->ctl_cmds
.status
& MPT2_CMD_REPLY_VALID
) == 0) {
2065 printk(MPT2SAS_ERR_FMT
"%s: no reply message\n",
2066 ioc
->name
, __func__
);
2071 mpi_reply
= ioc
->ctl_cmds
.reply
;
2072 ioc_status
= le16_to_cpu(mpi_reply
->IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2074 if (ioc_status
== MPI2_IOCSTATUS_SUCCESS
) {
2075 ioc
->diag_buffer_status
[buffer_type
] |=
2076 MPT2_DIAG_BUFFER_IS_REGISTERED
;
2077 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
"%s: success\n",
2078 ioc
->name
, __func__
));
2080 printk(MPT2SAS_INFO_FMT
"%s: ioc_status(0x%04x) "
2081 "log_info(0x%08x)\n", ioc
->name
, __func__
,
2082 ioc_status
, le32_to_cpu(mpi_reply
->IOCLogInfo
));
2088 mpt2sas_base_hard_reset_handler(ioc
, CAN_SLEEP
,
2093 ioc
->ctl_cmds
.status
= MPT2_CMD_NOT_USED
;
2098 #ifdef CONFIG_COMPAT
2100 * _ctl_compat_mpt_command - convert 32bit pointers to 64bit.
2101 * @ioc: per adapter object
2102 * @cmd - ioctl opcode
2103 * @arg - (struct mpt2_ioctl_command32)
2105 * MPT2COMMAND32 - Handle 32bit applications running on 64bit os.
2108 _ctl_compat_mpt_command(struct MPT2SAS_ADAPTER
*ioc
, unsigned cmd
,
2111 struct mpt2_ioctl_command32 karg32
;
2112 struct mpt2_ioctl_command32 __user
*uarg
;
2113 struct mpt2_ioctl_command karg
;
2115 if (_IOC_SIZE(cmd
) != sizeof(struct mpt2_ioctl_command32
))
2118 uarg
= (struct mpt2_ioctl_command32 __user
*) arg
;
2120 if (copy_from_user(&karg32
, (char __user
*)arg
, sizeof(karg32
))) {
2121 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
2122 __FILE__
, __LINE__
, __func__
);
2126 memset(&karg
, 0, sizeof(struct mpt2_ioctl_command
));
2127 karg
.hdr
.ioc_number
= karg32
.hdr
.ioc_number
;
2128 karg
.hdr
.port_number
= karg32
.hdr
.port_number
;
2129 karg
.hdr
.max_data_size
= karg32
.hdr
.max_data_size
;
2130 karg
.timeout
= karg32
.timeout
;
2131 karg
.max_reply_bytes
= karg32
.max_reply_bytes
;
2132 karg
.data_in_size
= karg32
.data_in_size
;
2133 karg
.data_out_size
= karg32
.data_out_size
;
2134 karg
.max_sense_bytes
= karg32
.max_sense_bytes
;
2135 karg
.data_sge_offset
= karg32
.data_sge_offset
;
2136 karg
.reply_frame_buf_ptr
= compat_ptr(karg32
.reply_frame_buf_ptr
);
2137 karg
.data_in_buf_ptr
= compat_ptr(karg32
.data_in_buf_ptr
);
2138 karg
.data_out_buf_ptr
= compat_ptr(karg32
.data_out_buf_ptr
);
2139 karg
.sense_data_ptr
= compat_ptr(karg32
.sense_data_ptr
);
2140 return _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2145 * _ctl_ioctl_main - main ioctl entry point
2146 * @file - (struct file)
2147 * @cmd - ioctl opcode
2149 * compat - handles 32 bit applications in 64bit os
2152 _ctl_ioctl_main(struct file
*file
, unsigned int cmd
, void __user
*arg
,
2155 struct MPT2SAS_ADAPTER
*ioc
;
2156 struct mpt2_ioctl_header ioctl_header
;
2157 enum block_state state
;
2160 /* get IOCTL header */
2161 if (copy_from_user(&ioctl_header
, (char __user
*)arg
,
2162 sizeof(struct mpt2_ioctl_header
))) {
2163 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
2164 __FILE__
, __LINE__
, __func__
);
2168 if (_ctl_verify_adapter(ioctl_header
.ioc_number
, &ioc
) == -1 || !ioc
)
2170 if (ioc
->shost_recovery
|| ioc
->pci_error_recovery
||
2171 ioc
->is_driver_loading
)
2174 state
= (file
->f_flags
& O_NONBLOCK
) ? NON_BLOCKING
: BLOCKING
;
2175 if (state
== NON_BLOCKING
) {
2176 if (!mutex_trylock(&ioc
->ctl_cmds
.mutex
))
2178 } else if (mutex_lock_interruptible(&ioc
->ctl_cmds
.mutex
)) {
2179 return -ERESTARTSYS
;
2184 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_iocinfo
))
2185 ret
= _ctl_getiocinfo(ioc
, arg
);
2187 #ifdef CONFIG_COMPAT
2192 struct mpt2_ioctl_command __user
*uarg
;
2193 struct mpt2_ioctl_command karg
;
2194 #ifdef CONFIG_COMPAT
2196 ret
= _ctl_compat_mpt_command(ioc
, cmd
, arg
);
2200 if (copy_from_user(&karg
, arg
, sizeof(karg
))) {
2201 printk(KERN_ERR
"failure at %s:%d/%s()!\n",
2202 __FILE__
, __LINE__
, __func__
);
2207 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_command
)) {
2209 ret
= _ctl_do_mpt_command(ioc
, karg
, &uarg
->mf
);
2213 case MPT2EVENTQUERY
:
2214 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_eventquery
))
2215 ret
= _ctl_eventquery(ioc
, arg
);
2217 case MPT2EVENTENABLE
:
2218 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_eventenable
))
2219 ret
= _ctl_eventenable(ioc
, arg
);
2221 case MPT2EVENTREPORT
:
2222 ret
= _ctl_eventreport(ioc
, arg
);
2225 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_diag_reset
))
2226 ret
= _ctl_do_reset(ioc
, arg
);
2228 case MPT2BTDHMAPPING
:
2229 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_ioctl_btdh_mapping
))
2230 ret
= _ctl_btdh_mapping(ioc
, arg
);
2232 case MPT2DIAGREGISTER
:
2233 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_register
))
2234 ret
= _ctl_diag_register(ioc
, arg
);
2236 case MPT2DIAGUNREGISTER
:
2237 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_unregister
))
2238 ret
= _ctl_diag_unregister(ioc
, arg
);
2241 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_query
))
2242 ret
= _ctl_diag_query(ioc
, arg
);
2244 case MPT2DIAGRELEASE
:
2245 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_release
))
2246 ret
= _ctl_diag_release(ioc
, arg
);
2248 case MPT2DIAGREADBUFFER
:
2249 if (_IOC_SIZE(cmd
) == sizeof(struct mpt2_diag_read_buffer
))
2250 ret
= _ctl_diag_read_buffer(ioc
, arg
);
2254 dctlprintk(ioc
, printk(MPT2SAS_INFO_FMT
2255 "unsupported ioctl opcode(0x%08x)\n", ioc
->name
, cmd
));
2259 mutex_unlock(&ioc
->ctl_cmds
.mutex
);
2264 * _ctl_ioctl - main ioctl entry point (unlocked)
2265 * @file - (struct file)
2266 * @cmd - ioctl opcode
2270 _ctl_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
2274 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 0);
2277 #ifdef CONFIG_COMPAT
2279 * _ctl_ioctl_compat - main ioctl entry point (compat)
2284 * This routine handles 32 bit applications in 64bit os.
2287 _ctl_ioctl_compat(struct file
*file
, unsigned cmd
, unsigned long arg
)
2291 ret
= _ctl_ioctl_main(file
, cmd
, (void __user
*)arg
, 1);
2296 /* scsi host attributes */
2299 * _ctl_version_fw_show - firmware version
2300 * @cdev - pointer to embedded class device
2301 * @buf - the buffer returned
2303 * A sysfs 'read-only' shost attribute.
2306 _ctl_version_fw_show(struct device
*cdev
, struct device_attribute
*attr
,
2309 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2310 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2312 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2313 (ioc
->facts
.FWVersion
.Word
& 0xFF000000) >> 24,
2314 (ioc
->facts
.FWVersion
.Word
& 0x00FF0000) >> 16,
2315 (ioc
->facts
.FWVersion
.Word
& 0x0000FF00) >> 8,
2316 ioc
->facts
.FWVersion
.Word
& 0x000000FF);
2318 static DEVICE_ATTR(version_fw
, S_IRUGO
, _ctl_version_fw_show
, NULL
);
2321 * _ctl_version_bios_show - bios version
2322 * @cdev - pointer to embedded class device
2323 * @buf - the buffer returned
2325 * A sysfs 'read-only' shost attribute.
2328 _ctl_version_bios_show(struct device
*cdev
, struct device_attribute
*attr
,
2331 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2332 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2334 u32 version
= le32_to_cpu(ioc
->bios_pg3
.BiosVersion
);
2336 return snprintf(buf
, PAGE_SIZE
, "%02d.%02d.%02d.%02d\n",
2337 (version
& 0xFF000000) >> 24,
2338 (version
& 0x00FF0000) >> 16,
2339 (version
& 0x0000FF00) >> 8,
2340 version
& 0x000000FF);
2342 static DEVICE_ATTR(version_bios
, S_IRUGO
, _ctl_version_bios_show
, NULL
);
2345 * _ctl_version_mpi_show - MPI (message passing interface) version
2346 * @cdev - pointer to embedded class device
2347 * @buf - the buffer returned
2349 * A sysfs 'read-only' shost attribute.
2352 _ctl_version_mpi_show(struct device
*cdev
, struct device_attribute
*attr
,
2355 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2356 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2358 return snprintf(buf
, PAGE_SIZE
, "%03x.%02x\n",
2359 ioc
->facts
.MsgVersion
, ioc
->facts
.HeaderVersion
>> 8);
2361 static DEVICE_ATTR(version_mpi
, S_IRUGO
, _ctl_version_mpi_show
, NULL
);
2364 * _ctl_version_product_show - product name
2365 * @cdev - pointer to embedded class device
2366 * @buf - the buffer returned
2368 * A sysfs 'read-only' shost attribute.
2371 _ctl_version_product_show(struct device
*cdev
, struct device_attribute
*attr
,
2374 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2375 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2377 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.ChipName
);
2379 static DEVICE_ATTR(version_product
, S_IRUGO
,
2380 _ctl_version_product_show
, NULL
);
2383 * _ctl_version_nvdata_persistent_show - ndvata persistent version
2384 * @cdev - pointer to embedded class device
2385 * @buf - the buffer returned
2387 * A sysfs 'read-only' shost attribute.
2390 _ctl_version_nvdata_persistent_show(struct device
*cdev
,
2391 struct device_attribute
*attr
, char *buf
)
2393 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2394 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2396 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2397 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionPersistent
.Word
));
2399 static DEVICE_ATTR(version_nvdata_persistent
, S_IRUGO
,
2400 _ctl_version_nvdata_persistent_show
, NULL
);
2403 * _ctl_version_nvdata_default_show - nvdata default version
2404 * @cdev - pointer to embedded class device
2405 * @buf - the buffer returned
2407 * A sysfs 'read-only' shost attribute.
2410 _ctl_version_nvdata_default_show(struct device
*cdev
,
2411 struct device_attribute
*attr
, char *buf
)
2413 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2414 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2416 return snprintf(buf
, PAGE_SIZE
, "%08xh\n",
2417 le32_to_cpu(ioc
->iounit_pg0
.NvdataVersionDefault
.Word
));
2419 static DEVICE_ATTR(version_nvdata_default
, S_IRUGO
,
2420 _ctl_version_nvdata_default_show
, NULL
);
2423 * _ctl_board_name_show - board name
2424 * @cdev - pointer to embedded class device
2425 * @buf - the buffer returned
2427 * A sysfs 'read-only' shost attribute.
2430 _ctl_board_name_show(struct device
*cdev
, struct device_attribute
*attr
,
2433 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2434 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2436 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardName
);
2438 static DEVICE_ATTR(board_name
, S_IRUGO
, _ctl_board_name_show
, NULL
);
2441 * _ctl_board_assembly_show - board assembly name
2442 * @cdev - pointer to embedded class device
2443 * @buf - the buffer returned
2445 * A sysfs 'read-only' shost attribute.
2448 _ctl_board_assembly_show(struct device
*cdev
, struct device_attribute
*attr
,
2451 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2452 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2454 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardAssembly
);
2456 static DEVICE_ATTR(board_assembly
, S_IRUGO
,
2457 _ctl_board_assembly_show
, NULL
);
2460 * _ctl_board_tracer_show - board tracer number
2461 * @cdev - pointer to embedded class device
2462 * @buf - the buffer returned
2464 * A sysfs 'read-only' shost attribute.
2467 _ctl_board_tracer_show(struct device
*cdev
, struct device_attribute
*attr
,
2470 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2471 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2473 return snprintf(buf
, 16, "%s\n", ioc
->manu_pg0
.BoardTracerNumber
);
2475 static DEVICE_ATTR(board_tracer
, S_IRUGO
,
2476 _ctl_board_tracer_show
, NULL
);
2479 * _ctl_io_delay_show - io missing delay
2480 * @cdev - pointer to embedded class device
2481 * @buf - the buffer returned
2483 * This is for firmware implemention for deboucing device
2486 * A sysfs 'read-only' shost attribute.
2489 _ctl_io_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2492 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2493 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2495 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->io_missing_delay
);
2497 static DEVICE_ATTR(io_delay
, S_IRUGO
,
2498 _ctl_io_delay_show
, NULL
);
2501 * _ctl_device_delay_show - device missing delay
2502 * @cdev - pointer to embedded class device
2503 * @buf - the buffer returned
2505 * This is for firmware implemention for deboucing device
2508 * A sysfs 'read-only' shost attribute.
2511 _ctl_device_delay_show(struct device
*cdev
, struct device_attribute
*attr
,
2514 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2515 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2517 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->device_missing_delay
);
2519 static DEVICE_ATTR(device_delay
, S_IRUGO
,
2520 _ctl_device_delay_show
, NULL
);
2523 * _ctl_fw_queue_depth_show - global credits
2524 * @cdev - pointer to embedded class device
2525 * @buf - the buffer returned
2527 * This is firmware queue depth limit
2529 * A sysfs 'read-only' shost attribute.
2532 _ctl_fw_queue_depth_show(struct device
*cdev
, struct device_attribute
*attr
,
2535 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2536 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2538 return snprintf(buf
, PAGE_SIZE
, "%02d\n", ioc
->facts
.RequestCredit
);
2540 static DEVICE_ATTR(fw_queue_depth
, S_IRUGO
,
2541 _ctl_fw_queue_depth_show
, NULL
);
2544 * _ctl_sas_address_show - sas address
2545 * @cdev - pointer to embedded class device
2546 * @buf - the buffer returned
2548 * This is the controller sas address
2550 * A sysfs 'read-only' shost attribute.
2553 _ctl_host_sas_address_show(struct device
*cdev
, struct device_attribute
*attr
,
2556 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2557 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2559 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
2560 (unsigned long long)ioc
->sas_hba
.sas_address
);
2562 static DEVICE_ATTR(host_sas_address
, S_IRUGO
,
2563 _ctl_host_sas_address_show
, NULL
);
2566 * _ctl_logging_level_show - logging level
2567 * @cdev - pointer to embedded class device
2568 * @buf - the buffer returned
2570 * A sysfs 'read/write' shost attribute.
2573 _ctl_logging_level_show(struct device
*cdev
, struct device_attribute
*attr
,
2576 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2577 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2579 return snprintf(buf
, PAGE_SIZE
, "%08xh\n", ioc
->logging_level
);
2582 _ctl_logging_level_store(struct device
*cdev
, struct device_attribute
*attr
,
2583 const char *buf
, size_t count
)
2585 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2586 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2589 if (sscanf(buf
, "%x", &val
) != 1)
2592 ioc
->logging_level
= val
;
2593 printk(MPT2SAS_INFO_FMT
"logging_level=%08xh\n", ioc
->name
,
2594 ioc
->logging_level
);
2597 static DEVICE_ATTR(logging_level
, S_IRUGO
| S_IWUSR
,
2598 _ctl_logging_level_show
, _ctl_logging_level_store
);
2600 /* device attributes */
2602 * _ctl_fwfault_debug_show - show/store fwfault_debug
2603 * @cdev - pointer to embedded class device
2604 * @buf - the buffer returned
2606 * mpt2sas_fwfault_debug is command line option
2607 * A sysfs 'read/write' shost attribute.
2610 _ctl_fwfault_debug_show(struct device
*cdev
,
2611 struct device_attribute
*attr
, char *buf
)
2613 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2614 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2616 return snprintf(buf
, PAGE_SIZE
, "%d\n", ioc
->fwfault_debug
);
2619 _ctl_fwfault_debug_store(struct device
*cdev
,
2620 struct device_attribute
*attr
, const char *buf
, size_t count
)
2622 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2623 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2626 if (sscanf(buf
, "%d", &val
) != 1)
2629 ioc
->fwfault_debug
= val
;
2630 printk(MPT2SAS_INFO_FMT
"fwfault_debug=%d\n", ioc
->name
,
2631 ioc
->fwfault_debug
);
2634 static DEVICE_ATTR(fwfault_debug
, S_IRUGO
| S_IWUSR
,
2635 _ctl_fwfault_debug_show
, _ctl_fwfault_debug_store
);
2639 * _ctl_ioc_reset_count_show - ioc reset count
2640 * @cdev - pointer to embedded class device
2641 * @buf - the buffer returned
2643 * This is firmware queue depth limit
2645 * A sysfs 'read-only' shost attribute.
2648 _ctl_ioc_reset_count_show(struct device
*cdev
, struct device_attribute
*attr
,
2651 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2652 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2654 return snprintf(buf
, PAGE_SIZE
, "%08d\n", ioc
->ioc_reset_count
);
2656 static DEVICE_ATTR(ioc_reset_count
, S_IRUGO
,
2657 _ctl_ioc_reset_count_show
, NULL
);
2660 * _ctl_ioc_reply_queue_count_show - number of reply queues
2661 * @cdev - pointer to embedded class device
2662 * @buf - the buffer returned
2664 * This is number of reply queues
2666 * A sysfs 'read-only' shost attribute.
2669 _ctl_ioc_reply_queue_count_show(struct device
*cdev
,
2670 struct device_attribute
*attr
, char *buf
)
2672 u8 reply_queue_count
;
2673 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2674 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2676 if ((ioc
->facts
.IOCCapabilities
&
2677 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX
) && ioc
->msix_enable
)
2678 reply_queue_count
= ioc
->reply_queue_count
;
2680 reply_queue_count
= 1;
2681 return snprintf(buf
, PAGE_SIZE
, "%d\n", reply_queue_count
);
2683 static DEVICE_ATTR(reply_queue_count
, S_IRUGO
,
2684 _ctl_ioc_reply_queue_count_show
, NULL
);
2687 * _ctl_BRM_status_show - Backup Rail Monitor Status
2688 * @cdev - pointer to embedded class device
2689 * @buf - the buffer returned
2691 * This is number of reply queues
2693 * A sysfs 'read-only' shost attribute.
2696 _ctl_BRM_status_show(struct device
*cdev
, struct device_attribute
*attr
,
2699 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2700 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2701 Mpi2IOUnitPage3_t
*io_unit_pg3
= NULL
;
2702 Mpi2ConfigReply_t mpi_reply
;
2703 u16 backup_rail_monitor_status
= 0;
2708 if (!ioc
->is_warpdrive
) {
2709 printk(MPT2SAS_ERR_FMT
"%s: BRM attribute is only for"\
2710 "warpdrive\n", ioc
->name
, __func__
);
2714 /* allocate upto GPIOVal 36 entries */
2715 sz
= offsetof(Mpi2IOUnitPage3_t
, GPIOVal
) + (sizeof(u16
) * 36);
2716 io_unit_pg3
= kzalloc(sz
, GFP_KERNEL
);
2718 printk(MPT2SAS_ERR_FMT
"%s: failed allocating memory"\
2719 "for iounit_pg3: (%d) bytes\n", ioc
->name
, __func__
, sz
);
2723 if (mpt2sas_config_get_iounit_pg3(ioc
, &mpi_reply
, io_unit_pg3
, sz
) !=
2725 printk(MPT2SAS_ERR_FMT
2726 "%s: failed reading iounit_pg3\n", ioc
->name
,
2731 ioc_status
= le16_to_cpu(mpi_reply
.IOCStatus
) & MPI2_IOCSTATUS_MASK
;
2732 if (ioc_status
!= MPI2_IOCSTATUS_SUCCESS
) {
2733 printk(MPT2SAS_ERR_FMT
"%s: iounit_pg3 failed with"\
2734 "ioc_status(0x%04x)\n", ioc
->name
, __func__
, ioc_status
);
2738 if (io_unit_pg3
->GPIOCount
< 25) {
2739 printk(MPT2SAS_ERR_FMT
"%s: iounit_pg3->GPIOCount less than"\
2740 "25 entries, detected (%d) entries\n", ioc
->name
, __func__
,
2741 io_unit_pg3
->GPIOCount
);
2745 /* BRM status is in bit zero of GPIOVal[24] */
2746 backup_rail_monitor_status
= le16_to_cpu(io_unit_pg3
->GPIOVal
[24]);
2747 rc
= snprintf(buf
, PAGE_SIZE
, "%d\n", (backup_rail_monitor_status
& 1));
2753 static DEVICE_ATTR(BRM_status
, S_IRUGO
, _ctl_BRM_status_show
, NULL
);
2755 struct DIAG_BUFFER_START
{
2765 * _ctl_host_trace_buffer_size_show - host buffer size (trace only)
2766 * @cdev - pointer to embedded class device
2767 * @buf - the buffer returned
2769 * A sysfs 'read-only' shost attribute.
2772 _ctl_host_trace_buffer_size_show(struct device
*cdev
,
2773 struct device_attribute
*attr
, char *buf
)
2775 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2776 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2778 struct DIAG_BUFFER_START
*request_data
;
2780 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
2781 printk(MPT2SAS_ERR_FMT
"%s: host_trace_buffer is not "
2782 "registered\n", ioc
->name
, __func__
);
2786 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2787 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2788 printk(MPT2SAS_ERR_FMT
"%s: host_trace_buffer is not "
2789 "registered\n", ioc
->name
, __func__
);
2793 request_data
= (struct DIAG_BUFFER_START
*)
2794 ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
];
2795 if ((le32_to_cpu(request_data
->DiagVersion
) == 0x00000000 ||
2796 le32_to_cpu(request_data
->DiagVersion
) == 0x01000000) &&
2797 le32_to_cpu(request_data
->Reserved3
) == 0x4742444c)
2798 size
= le32_to_cpu(request_data
->Size
);
2800 ioc
->ring_buffer_sz
= size
;
2801 return snprintf(buf
, PAGE_SIZE
, "%d\n", size
);
2803 static DEVICE_ATTR(host_trace_buffer_size
, S_IRUGO
,
2804 _ctl_host_trace_buffer_size_show
, NULL
);
2807 * _ctl_host_trace_buffer_show - firmware ring buffer (trace only)
2808 * @cdev - pointer to embedded class device
2809 * @buf - the buffer returned
2811 * A sysfs 'read/write' shost attribute.
2813 * You will only be able to read 4k bytes of ring buffer at a time.
2814 * In order to read beyond 4k bytes, you will have to write out the
2815 * offset to the same attribute, it will move the pointer.
2818 _ctl_host_trace_buffer_show(struct device
*cdev
, struct device_attribute
*attr
,
2821 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2822 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2826 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) {
2827 printk(MPT2SAS_ERR_FMT
"%s: host_trace_buffer is not "
2828 "registered\n", ioc
->name
, __func__
);
2832 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2833 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0) {
2834 printk(MPT2SAS_ERR_FMT
"%s: host_trace_buffer is not "
2835 "registered\n", ioc
->name
, __func__
);
2839 if (ioc
->ring_buffer_offset
> ioc
->ring_buffer_sz
)
2842 size
= ioc
->ring_buffer_sz
- ioc
->ring_buffer_offset
;
2843 size
= (size
> PAGE_SIZE
) ? PAGE_SIZE
: size
;
2844 request_data
= ioc
->diag_buffer
[0] + ioc
->ring_buffer_offset
;
2845 memcpy(buf
, request_data
, size
);
2850 _ctl_host_trace_buffer_store(struct device
*cdev
, struct device_attribute
*attr
,
2851 const char *buf
, size_t count
)
2853 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2854 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2857 if (sscanf(buf
, "%d", &val
) != 1)
2860 ioc
->ring_buffer_offset
= val
;
2863 static DEVICE_ATTR(host_trace_buffer
, S_IRUGO
| S_IWUSR
,
2864 _ctl_host_trace_buffer_show
, _ctl_host_trace_buffer_store
);
2866 /*****************************************/
2869 * _ctl_host_trace_buffer_enable_show - firmware ring buffer (trace only)
2870 * @cdev - pointer to embedded class device
2871 * @buf - the buffer returned
2873 * A sysfs 'read/write' shost attribute.
2875 * This is a mechnism to post/release host_trace_buffers
2878 _ctl_host_trace_buffer_enable_show(struct device
*cdev
,
2879 struct device_attribute
*attr
, char *buf
)
2881 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2882 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2884 if ((!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) ||
2885 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2886 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0))
2887 return snprintf(buf
, PAGE_SIZE
, "off\n");
2888 else if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2889 MPT2_DIAG_BUFFER_IS_RELEASED
))
2890 return snprintf(buf
, PAGE_SIZE
, "release\n");
2892 return snprintf(buf
, PAGE_SIZE
, "post\n");
2896 _ctl_host_trace_buffer_enable_store(struct device
*cdev
,
2897 struct device_attribute
*attr
, const char *buf
, size_t count
)
2899 struct Scsi_Host
*shost
= class_to_shost(cdev
);
2900 struct MPT2SAS_ADAPTER
*ioc
= shost_priv(shost
);
2902 struct mpt2_diag_register diag_register
;
2905 if (sscanf(buf
, "%9s", str
) != 1)
2908 if (!strcmp(str
, "post")) {
2909 /* exit out if host buffers are already posted */
2910 if ((ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
]) &&
2911 (ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2912 MPT2_DIAG_BUFFER_IS_REGISTERED
) &&
2913 ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2914 MPT2_DIAG_BUFFER_IS_RELEASED
) == 0))
2916 memset(&diag_register
, 0, sizeof(struct mpt2_diag_register
));
2917 printk(MPT2SAS_INFO_FMT
"posting host trace buffers\n",
2919 diag_register
.buffer_type
= MPI2_DIAG_BUF_TYPE_TRACE
;
2920 diag_register
.requested_buffer_size
= (1024 * 1024);
2921 diag_register
.unique_id
= 0x7075900;
2922 ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] = 0;
2923 _ctl_diag_register_2(ioc
, &diag_register
);
2924 } else if (!strcmp(str
, "release")) {
2925 /* exit out if host buffers are already released */
2926 if (!ioc
->diag_buffer
[MPI2_DIAG_BUF_TYPE_TRACE
])
2928 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2929 MPT2_DIAG_BUFFER_IS_REGISTERED
) == 0)
2931 if ((ioc
->diag_buffer_status
[MPI2_DIAG_BUF_TYPE_TRACE
] &
2932 MPT2_DIAG_BUFFER_IS_RELEASED
))
2934 printk(MPT2SAS_INFO_FMT
"releasing host trace buffer\n",
2936 _ctl_send_release(ioc
, MPI2_DIAG_BUF_TYPE_TRACE
, &issue_reset
);
2942 static DEVICE_ATTR(host_trace_buffer_enable
, S_IRUGO
| S_IWUSR
,
2943 _ctl_host_trace_buffer_enable_show
, _ctl_host_trace_buffer_enable_store
);
2945 struct device_attribute
*mpt2sas_host_attrs
[] = {
2946 &dev_attr_version_fw
,
2947 &dev_attr_version_bios
,
2948 &dev_attr_version_mpi
,
2949 &dev_attr_version_product
,
2950 &dev_attr_version_nvdata_persistent
,
2951 &dev_attr_version_nvdata_default
,
2952 &dev_attr_board_name
,
2953 &dev_attr_board_assembly
,
2954 &dev_attr_board_tracer
,
2956 &dev_attr_device_delay
,
2957 &dev_attr_logging_level
,
2958 &dev_attr_fwfault_debug
,
2959 &dev_attr_fw_queue_depth
,
2960 &dev_attr_host_sas_address
,
2961 &dev_attr_ioc_reset_count
,
2962 &dev_attr_host_trace_buffer_size
,
2963 &dev_attr_host_trace_buffer
,
2964 &dev_attr_host_trace_buffer_enable
,
2965 &dev_attr_reply_queue_count
,
2966 &dev_attr_BRM_status
,
2971 * _ctl_device_sas_address_show - sas address
2972 * @cdev - pointer to embedded class device
2973 * @buf - the buffer returned
2975 * This is the sas address for the target
2977 * A sysfs 'read-only' shost attribute.
2980 _ctl_device_sas_address_show(struct device
*dev
, struct device_attribute
*attr
,
2983 struct scsi_device
*sdev
= to_scsi_device(dev
);
2984 struct MPT2SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
2986 return snprintf(buf
, PAGE_SIZE
, "0x%016llx\n",
2987 (unsigned long long)sas_device_priv_data
->sas_target
->sas_address
);
2989 static DEVICE_ATTR(sas_address
, S_IRUGO
, _ctl_device_sas_address_show
, NULL
);
2992 * _ctl_device_handle_show - device handle
2993 * @cdev - pointer to embedded class device
2994 * @buf - the buffer returned
2996 * This is the firmware assigned device handle
2998 * A sysfs 'read-only' shost attribute.
3001 _ctl_device_handle_show(struct device
*dev
, struct device_attribute
*attr
,
3004 struct scsi_device
*sdev
= to_scsi_device(dev
);
3005 struct MPT2SAS_DEVICE
*sas_device_priv_data
= sdev
->hostdata
;
3007 return snprintf(buf
, PAGE_SIZE
, "0x%04x\n",
3008 sas_device_priv_data
->sas_target
->handle
);
3010 static DEVICE_ATTR(sas_device_handle
, S_IRUGO
, _ctl_device_handle_show
, NULL
);
3012 struct device_attribute
*mpt2sas_dev_attrs
[] = {
3013 &dev_attr_sas_address
,
3014 &dev_attr_sas_device_handle
,
3018 static const struct file_operations ctl_fops
= {
3019 .owner
= THIS_MODULE
,
3020 .unlocked_ioctl
= _ctl_ioctl
,
3022 .fasync
= _ctl_fasync
,
3023 #ifdef CONFIG_COMPAT
3024 .compat_ioctl
= _ctl_ioctl_compat
,
3026 .llseek
= noop_llseek
,
3029 static struct miscdevice ctl_dev
= {
3030 .minor
= MPT2SAS_MINOR
,
3031 .name
= MPT2SAS_DEV_NAME
,
3036 * mpt2sas_ctl_init - main entry point for ctl.
3040 mpt2sas_ctl_init(void)
3043 if (misc_register(&ctl_dev
) < 0)
3044 printk(KERN_ERR
"%s can't register misc device [minor=%d]\n",
3045 MPT2SAS_DRIVER_NAME
, MPT2SAS_MINOR
);
3047 init_waitqueue_head(&ctl_poll_wait
);
3051 * mpt2sas_ctl_exit - exit point for ctl
3055 mpt2sas_ctl_exit(void)
3057 struct MPT2SAS_ADAPTER
*ioc
;
3060 list_for_each_entry(ioc
, &mpt2sas_ioc_list
, list
) {
3062 /* free memory associated to diag buffers */
3063 for (i
= 0; i
< MPI2_DIAG_BUF_TYPE_COUNT
; i
++) {
3064 if (!ioc
->diag_buffer
[i
])
3066 pci_free_consistent(ioc
->pdev
, ioc
->diag_buffer_sz
[i
],
3067 ioc
->diag_buffer
[i
], ioc
->diag_buffer_dma
[i
]);
3068 ioc
->diag_buffer
[i
] = NULL
;
3069 ioc
->diag_buffer_status
[i
] = 0;
3072 kfree(ioc
->event_log
);
3074 misc_deregister(&ctl_dev
);