/* * Management Module Support for MPT (Message Passing Technology) based * controllers * * This code is based on drivers/scsi/mpt3sas/mpt3sas_ctl.c * Copyright (C) 2012-2014 LSI Corporation * Copyright (C) 2013-2014 Avago Technologies * (mailto: MPT-FusionLinux.pdl@avagotech.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * NO WARRANTY * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is * solely responsible for determining the appropriateness of using and * distributing the Program and assumes all risks associated with its * exercise of rights under this Agreement, including but not limited to * the risks and costs of program errors, damage to or loss of data, * programs or equipment, and unavailability or interruption of operations.
* DISCLAIMER OF LIABILITY * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
* You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA.
*/
/** * enum block_state - blocking state * @NON_BLOCKING: non blocking * @BLOCKING: blocking * * These states are for ioctls that need to wait for a response * from firmware, so they probably require sleep.
*/ enum block_state {
NON_BLOCKING,
BLOCKING,
};
/** * _ctl_display_some_debug - debug routine * @ioc: per adapter object * @smid: system request message index * @calling_function_name: string pass from calling function * @mpi_reply: reply message frame * Context: none. * * Function for displaying debug info helpful when debugging issues * in this module.
*/ staticvoid
_ctl_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid, char *calling_function_name, MPI2DefaultReply_t *mpi_reply)
{
Mpi2ConfigRequest_t *mpi_request; char *desc = NULL;
if (!(ioc->logging_level & MPT_DEBUG_IOCTL)) return;
/** * mpt3sas_ctl_done - ctl module completion routine * @ioc: per adapter object * @smid: system request message index * @msix_index: MSIX table index supplied by the OS * @reply: reply message frame(lower 32bit addr) * Context: none. * * The callback handler when using ioc->ctl_cb_idx. * * Return: 1 meaning mf should be freed from _base_interrupt * 0 means the mf is freed from this function.
*/
u8
mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
u32 reply)
{
MPI2DefaultReply_t *mpi_reply;
Mpi2SCSIIOReply_t *scsiio_reply;
Mpi26NVMeEncapsulatedErrorReply_t *nvme_error_reply; constvoid *sense_data;
u32 sz;
if (ioc->ctl_cmds.status == MPT3_CMD_NOT_USED) return 1; if (ioc->ctl_cmds.smid != smid) return 1;
ioc->ctl_cmds.status |= MPT3_CMD_COMPLETE;
mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); if (mpi_reply) {
memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
ioc->ctl_cmds.status |= MPT3_CMD_REPLY_VALID; /* get sense data */ if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
mpi_reply->Function ==
MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) {
scsiio_reply = (Mpi2SCSIIOReply_t *)mpi_reply; if (scsiio_reply->SCSIState &
MPI2_SCSI_STATE_AUTOSENSE_VALID) {
sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
le32_to_cpu(scsiio_reply->SenseCount));
sense_data = mpt3sas_base_get_sense_buffer(ioc,
smid);
memcpy(ioc->ctl_cmds.sense, sense_data, sz);
}
} /* * Get Error Response data for NVMe device. The ctl_cmds.sense * buffer is used to store the Error Response data.
*/ if (mpi_reply->Function == MPI2_FUNCTION_NVME_ENCAPSULATED) {
nvme_error_reply =
(Mpi26NVMeEncapsulatedErrorReply_t *)mpi_reply;
sz = min_t(u32, NVME_ERROR_RESPONSE_SIZE,
le16_to_cpu(nvme_error_reply->ErrorResponseCount));
sense_data = mpt3sas_base_get_sense_buffer(ioc, smid);
memcpy(ioc->ctl_cmds.sense, sense_data, sz);
}
}
/** * _ctl_check_event_type - determines when an event needs logging * @ioc: per adapter object * @event: firmware event * * The bitmask in ioc->event_type[] indicates which events should be * be saved in the driver event_log. This bitmask is set by application. * * Return: 1 when event should be captured, or zero means no match.
*/ staticint
_ctl_check_event_type(struct MPT3SAS_ADAPTER *ioc, u16 event)
{
u16 i;
u32 desired_event;
if (event >= 128 || !event || !ioc->event_log) return 0;
/* This aen_event_read_flag flag is set until the * application has read the event log. * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify.
*/ if (event == MPI2_EVENT_LOG_ENTRY_ADDED ||
(send_aen && !ioc->aen_event_read_flag)) {
ioc->aen_event_read_flag = 1;
wake_up_interruptible(&ctl_poll_wait); if (async_queue)
kill_fasync(&async_queue, SIGIO, POLL_IN);
}
}
/** * mpt3sas_ctl_event_callback - firmware event handler (called at ISR time) * @ioc: per adapter object * @msix_index: MSIX table index supplied by the OS * @reply: reply message frame(lower 32bit addr) * Context: interrupt. * * This function merely adds a new work task into ioc->firmware_event_thread. * The tasks are worked from _firmware_event_work in user context. * * Return: 1 meaning mf should be freed from _base_interrupt * 0 means the mf is freed from this function.
*/
u8
mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index,
u32 reply)
{
Mpi2EventNotificationReply_t *mpi_reply;
/** * _ctl_verify_adapter - validates ioc_number passed from application * @ioc_number: ? * @iocpp: The ioc pointer is returned in this. * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device & * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device. * * Return: (-1) means error, else ioc_number.
*/ staticint
_ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp, int mpi_version)
{ struct MPT3SAS_ADAPTER *ioc; int version = 0; /* global ioc lock to protect controller on list operations */
spin_lock(&gioc_lock);
list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { if (ioc->id != ioc_number) continue; /* Check whether this ioctl command is from right * ioctl device or not, if not continue the search.
*/
version = ioc->hba_mpi_version_belonged; /* MPI25_VERSION and MPI26_VERSION uses same ioctl * device.
*/ if (mpi_version == (MPI25_VERSION | MPI26_VERSION)) { if ((version == MPI25_VERSION) ||
(version == MPI26_VERSION)) goto out; else continue;
} else { if (version != mpi_version) continue;
}
out:
spin_unlock(&gioc_lock);
*iocpp = ioc; return ioc_number;
}
spin_unlock(&gioc_lock);
*iocpp = NULL; return -1;
}
/** * mpt3sas_ctl_pre_reset_handler - reset callback handler (for ctl) * @ioc: per adapter object * * The handler for doing any required cleanup or initialization.
*/ void mpt3sas_ctl_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc)
{ int i;
u8 issue_reset;
dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__)); for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { if (!(ioc->diag_buffer_status[i] &
MPT3_DIAG_BUFFER_IS_REGISTERED)) continue; if ((ioc->diag_buffer_status[i] &
MPT3_DIAG_BUFFER_IS_RELEASED)) continue;
/* * add a log message to indicate the release
*/
ioc_info(ioc, "%s: Releasing the trace buffer due to adapter reset.",
__func__);
ioc->htb_rel.buffer_rel_condition =
MPT3_DIAG_BUFFER_REL_TRIGGER;
mpt3sas_send_diag_release(ioc, i, &issue_reset);
}
}
/** * mpt3sas_ctl_clear_outstanding_ioctls - clears outstanding ioctl cmd. * @ioc: per adapter object * * The handler for doing any required cleanup or initialization.
*/ void mpt3sas_ctl_clear_outstanding_ioctls(struct MPT3SAS_ADAPTER *ioc)
{
dtmprintk(ioc,
ioc_info(ioc, "%s: clear outstanding ioctl cmd\n", __func__)); if (ioc->ctl_cmds.status & MPT3_CMD_PENDING) {
ioc->ctl_cmds.status |= MPT3_CMD_RESET;
mpt3sas_base_free_smid(ioc, ioc->ctl_cmds.smid);
complete(&ioc->ctl_cmds.done);
}
}
/** * mpt3sas_ctl_reset_done_handler - reset callback handler (for ctl) * @ioc: per adapter object * * The handler for doing any required cleanup or initialization.
*/ void mpt3sas_ctl_reset_done_handler(struct MPT3SAS_ADAPTER *ioc)
{ int i;
for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { if (!(ioc->diag_buffer_status[i] &
MPT3_DIAG_BUFFER_IS_REGISTERED)) continue; if ((ioc->diag_buffer_status[i] &
MPT3_DIAG_BUFFER_IS_RELEASED)) continue;
ioc->diag_buffer_status[i] |=
MPT3_DIAG_BUFFER_IS_DIAG_RESET;
}
}
/* global ioc lock to protect controller on list operations */
spin_lock(&gioc_lock);
list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { if (ioc->aen_event_read_flag) {
spin_unlock(&gioc_lock); return EPOLLIN | EPOLLRDNORM;
}
}
spin_unlock(&gioc_lock); return 0;
}
/** * _ctl_set_task_mid - assign an active smid to tm request * @ioc: per adapter object * @karg: (struct mpt3_ioctl_command) * @tm_request: pointer to mf from user space * * Return: 0 when an smid if found, else fail. * during failure, the reply frame is filled.
*/ staticint
_ctl_set_task_mid(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command *karg,
Mpi2SCSITaskManagementRequest_t *tm_request)
{ bool found = false;
u16 smid;
u16 handle; struct scsi_cmnd *scmd; struct MPT3SAS_DEVICE *priv_data;
Mpi2SCSITaskManagementReply_t *tm_reply;
u32 sz;
u32 lun; char *desc = NULL;
scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); if (!scmd) continue; if (lun != scmd->device->lun) continue;
priv_data = scmd->device->hostdata; if (priv_data->sas_target == NULL) continue; if (priv_data->sas_target->handle != handle) continue;
st = scsi_cmd_priv(scmd);
/* * If the given TaskMID from the user space is zero, then the * first outstanding smid will be picked up. Otherwise, * targeted smid will be the one.
*/
task_mid = cpu_to_le16(st->smid); if (!tm_request->TaskMID)
tm_request->TaskMID = task_mid;
found = tm_request->TaskMID == task_mid;
}
if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
ret = -EAGAIN; goto out;
}
ret = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT); if (ret) goto out;
mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL); if (!mpi_request) {
ioc_err(ioc, "%s: failed obtaining a memory for mpi_request\n",
__func__);
ret = -ENOMEM; goto out;
}
/* Check for overflow and wraparound */ if (karg.data_sge_offset * 4 > ioc->request_sz ||
karg.data_sge_offset > (UINT_MAX / 4)) {
ret = -EINVAL; goto out;
}
/* copy in request message frame from user */ if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) {
pr_err("failure at %s:%d/%s()!\n", __FILE__, __LINE__,
__func__);
ret = -EFAULT; goto out;
}
if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) {
smid = mpt3sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx); if (!smid) {
ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
ret = -EAGAIN; goto out;
}
} else { /* Use first reserved smid for passthrough ioctls */
smid = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT + 1;
}
if (ioc->logging_level & MPT_DEBUG_TM)
_debug_dump_mf(nvme_encap_request,
ioc->request_sz/4);
mpt3sas_base_free_smid(ioc, smid);
ret = -EINVAL; goto out;
} /* * Get the Physical Address of the sense buffer. * Use Error Response buffer address field to hold the sense * buffer address. * Clear the internal sense buffer, which will potentially hold * the Completion Queue Entry on return, or 0 if no Entry. * Build the PRPs and set direction bits. * Send the request.
*/
nvme_encap_request->ErrorResponseBaseAddress =
cpu_to_le64(ioc->sense_dma & 0xFFFFFFFF00000000UL);
nvme_encap_request->ErrorResponseBaseAddress |=
cpu_to_le64(le32_to_cpu(
mpt3sas_base_get_sense_buffer_dma(ioc, smid)));
nvme_encap_request->ErrorResponseAllocationLength =
cpu_to_le16(NVME_ERROR_RESPONSE_SIZE);
memset(ioc->ctl_cmds.sense, 0, NVME_ERROR_RESPONSE_SIZE);
ioc->build_nvme_prp(ioc, smid, nvme_encap_request,
data_out_dma, data_out_sz, data_in_dma, data_in_sz); if (test_bit(device_handle, ioc->device_remove_in_progress)) {
dtmprintk(ioc,
ioc_info(ioc, "handle(0x%04x): ioctl failed due to device removal in progress\n",
device_handle));
mpt3sas_base_free_smid(ioc, smid);
ret = -EINVAL; goto out;
}
mpt3sas_base_put_smid_nvme_encap(ioc, smid); break;
} case MPI2_FUNCTION_SCSI_IO_REQUEST: case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH:
{
Mpi2SCSIIORequest_t *scsiio_request =
(Mpi2SCSIIORequest_t *)request;
scsiio_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
scsiio_request->SenseBufferLowAddress =
mpt3sas_base_get_sense_buffer_dma(ioc, smid);
memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE); if (test_bit(device_handle, ioc->device_remove_in_progress)) {
dtmprintk(ioc,
ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
device_handle));
mpt3sas_base_free_smid(ioc, smid);
ret = -EINVAL; goto out;
}
ioc->build_sg(ioc, psge, data_out_dma, data_out_sz,
data_in_dma, data_in_sz); if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST)
ioc->put_smid_scsi_io(ioc, smid, device_handle); else
ioc->put_smid_default(ioc, smid); break;
} case MPI2_FUNCTION_SCSI_TASK_MGMT:
{
Mpi2SCSITaskManagementRequest_t *tm_request =
(Mpi2SCSITaskManagementRequest_t *)request;
if (test_bit(device_handle, ioc->device_remove_in_progress)) {
dtmprintk(ioc,
ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
device_handle));
mpt3sas_base_free_smid(ioc, smid);
ret = -EINVAL; goto out;
}
mpt3sas_scsih_set_tm_flag(ioc, le16_to_cpu(
tm_request->DevHandle));
ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz,
data_in_dma, data_in_sz);
ioc->put_smid_hi_priority(ioc, smid, 0); break;
} case MPI2_FUNCTION_SMP_PASSTHROUGH:
{
Mpi2SmpPassthroughRequest_t *smp_request =
(Mpi2SmpPassthroughRequest_t *)mpi_request;
u8 *data;
if (!ioc->multipath_on_hba) { /* ioc determines which port to use */
smp_request->PhysicalPort = 0xFF;
} if (smp_request->PassthroughFlags &
MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE)
data = (u8 *)&smp_request->SGL; else { if (unlikely(data_out == NULL)) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__);
mpt3sas_base_free_smid(ioc, smid);
ret = -EINVAL; goto out;
}
data = data_out;
}
if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) {
ioc->ioc_link_reset_in_progress = 1;
ioc->ignore_loginfos = 1;
}
ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
data_in_sz);
ioc->put_smid_default(ioc, smid); break;
} case MPI2_FUNCTION_SATA_PASSTHROUGH:
{ if (test_bit(device_handle, ioc->device_remove_in_progress)) {
dtmprintk(ioc,
ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n",
device_handle));
mpt3sas_base_free_smid(ioc, smid);
ret = -EINVAL; goto out;
}
ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
data_in_sz);
ioc->put_smid_default(ioc, smid); break;
} case MPI2_FUNCTION_FW_DOWNLOAD:
{ if (ioc->pdev->vendor == MPI2_MFGPAGE_VENDORID_ATTO) {
ioc_info(ioc, "Firmware download not supported for ATTO HBA.\n");
ret = -EPERM; break;
}
fallthrough;
} case MPI2_FUNCTION_FW_UPLOAD:
{
ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma,
data_in_sz);
ioc->put_smid_default(ioc, smid); break;
} case MPI2_FUNCTION_TOOLBOX:
{
Mpi2ToolboxCleanRequest_t *toolbox_request =
(Mpi2ToolboxCleanRequest_t *)mpi_request;
/* copy out xdata to user */ if (data_in_sz) { if (copy_to_user(karg.data_in_buf_ptr, data_in,
data_in_sz)) {
pr_err("failure at %s:%d/%s()!\n", __FILE__,
__LINE__, __func__);
ret = -ENODATA; goto out;
}
}
/* copy out reply message frame to user */ if (karg.max_reply_bytes) {
sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz); if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply,
sz)) {
pr_err("failure at %s:%d/%s()!\n", __FILE__,
__LINE__, __func__);
ret = -ENODATA; goto out;
}
}
/* copy out sense/NVMe Error Response to user */ if (karg.max_sense_bytes && (mpi_request->Function ==
MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function ==
MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || mpi_request->Function ==
MPI2_FUNCTION_NVME_ENCAPSULATED)) { if (karg.sense_data_ptr == NULL) {
ioc_info(ioc, "Response buffer provided by application is NULL; Response data will not be returned\n"); goto out;
}
sz_arg = (mpi_request->Function ==
MPI2_FUNCTION_NVME_ENCAPSULATED) ? NVME_ERROR_RESPONSE_SIZE :
SCSI_SENSE_BUFFERSIZE;
sz = min_t(u32, karg.max_sense_bytes, sz_arg); if (copy_to_user(karg.sense_data_ptr, ioc->ctl_cmds.sense,
sz)) {
pr_err("failure at %s:%d/%s()!\n", __FILE__,
__LINE__, __func__);
ret = -ENODATA; goto out;
}
}
/** * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode * @ioc: per adapter object * @arg: user space buffer containing ioctl content
*/ staticlong
_ctl_btdh_mapping(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{ struct mpt3_ioctl_btdh_mapping karg; int rc;
if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
}
dctlprintk(ioc, ioc_info(ioc, "%s\n",
__func__));
rc = _ctl_btdh_search_sas_device(ioc, &karg); if (!rc)
rc = _ctl_btdh_search_pcie_device(ioc, &karg); if (!rc)
_ctl_btdh_search_raid_device(ioc, &karg);
if (copy_to_user(arg, &karg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
} return 0;
}
/** * _ctl_diag_capability - return diag buffer capability * @ioc: per adapter object * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED * * returns 1 when diag buffer support is enabled in firmware
*/ static u8
_ctl_diag_capability(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type)
{
u8 rc = 0;
switch (buffer_type) { case MPI2_DIAG_BUF_TYPE_TRACE: if (ioc->facts.IOCCapabilities &
MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER)
rc = 1; break; case MPI2_DIAG_BUF_TYPE_SNAPSHOT: if (ioc->facts.IOCCapabilities &
MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER)
rc = 1; break; case MPI2_DIAG_BUF_TYPE_EXTENDED: if (ioc->facts.IOCCapabilities &
MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER)
rc = 1;
}
return rc;
}
/** * _ctl_diag_get_bufftype - return diag buffer type * either TRACE, SNAPSHOT, or EXTENDED * @ioc: per adapter object * @unique_id: specifies the unique_id for the buffer * * returns MPT3_DIAG_UID_NOT_FOUND if the id not found
*/ static u8
_ctl_diag_get_bufftype(struct MPT3SAS_ADAPTER *ioc, u32 unique_id)
{
u8 index;
for (index = 0; index < MPI2_DIAG_BUF_TYPE_COUNT; index++) { if (ioc->unique_id[index] == unique_id) return index;
}
return MPT3_DIAG_UID_NOT_FOUND;
}
/** * _ctl_diag_register_2 - wrapper for registering diag buffer support * @ioc: per adapter object * @diag_register: the diag_register struct passed in from user space *
*/ staticlong
_ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc, struct mpt3_diag_register *diag_register)
{ int rc, i; void *request_data = NULL;
dma_addr_t request_data_dma;
u32 request_data_sz = 0;
Mpi2DiagBufferPostRequest_t *mpi_request;
Mpi2DiagBufferPostReply_t *mpi_reply;
u8 buffer_type;
u16 smid;
u16 ioc_status;
u32 ioc_state;
u8 issue_reset = 0;
dctlprintk(ioc, ioc_info(ioc, "%s\n",
__func__));
ioc_state = mpt3sas_base_get_iocstate(ioc, 1); if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
ioc_err(ioc, "%s: failed due to ioc not operational\n",
__func__);
rc = -EAGAIN; goto out;
}
if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
rc = -EAGAIN; goto out;
}
buffer_type = diag_register->buffer_type; if (!_ctl_diag_capability(ioc, buffer_type)) {
ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
__func__, buffer_type); return -EPERM;
}
if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_APP_OWNED) &&
!(ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_RELEASED)) {
ioc_err(ioc, "%s: buffer_type(0x%02x) is already registered by application with UID(0x%08x)\n",
__func__, buffer_type, ioc->unique_id[buffer_type]); return -EINVAL;
}
if (ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_REGISTERED) { /* * If driver posts buffer initially, then an application wants * to Register that buffer (own it) without Releasing first, * the application Register command MUST have the same buffer * type and size in the Register command (obtained from the * Query command). Otherwise that Register command will be * failed. If the application has released the buffer but wants * to re-register it, it should be allowed as long as the * Unique-Id/Size match.
*/
if (ioc->unique_id[buffer_type] == MPT3DIAGBUFFUNIQUEID &&
ioc->diag_buffer_sz[buffer_type] ==
diag_register->requested_buffer_size) {
/* * Application wants to own the buffer with * the same size.
*/
ioc->unique_id[buffer_type] =
diag_register->unique_id;
rc = 0; /* success */ goto out;
}
} elseif (ioc->unique_id[buffer_type] !=
MPT3DIAGBUFFUNIQUEID) { if (ioc->unique_id[buffer_type] !=
diag_register->unique_id ||
ioc->diag_buffer_sz[buffer_type] !=
diag_register->requested_buffer_size ||
!(ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_RELEASED)) {
ioc_err(ioc, "%s: already has a registered buffer for buffer_type(0x%02x)\n",
__func__, buffer_type); return -EINVAL;
}
} else {
ioc_err(ioc, "%s: already has a registered buffer for buffer_type(0x%02x)\n",
__func__, buffer_type); return -EINVAL;
}
} elseif (ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED) {
if (ioc->unique_id[buffer_type] != MPT3DIAGBUFFUNIQUEID ||
ioc->diag_buffer_sz[buffer_type] !=
diag_register->requested_buffer_size) {
ioc_err(ioc, "%s: already a buffer is allocated for buffer_type(0x%02x) of size %d bytes, so please try registering again with same size\n",
__func__, buffer_type,
ioc->diag_buffer_sz[buffer_type]); return -EINVAL;
}
}
if (diag_register->requested_buffer_size % 4) {
ioc_err(ioc, "%s: the requested_buffer_size is not 4 byte aligned\n",
__func__); return -EINVAL;
}
smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx); if (!smid) {
ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
rc = -EAGAIN; goto out;
}
/** * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time * @ioc: per adapter object * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1 * * This is called when command line option diag_buffer_enable is enabled * at driver load time.
*/ void
mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER *ioc, u8 bits_to_register)
{ struct mpt3_diag_register diag_register;
u32 ret_val;
u32 trace_buff_size = ioc->manu_pg11.HostTraceBufferMaxSizeKB<<10;
u32 min_trace_buff_size = 0;
u32 decr_trace_buff_size = 0;
if (min_trace_buff_size > trace_buff_size) { /* The buff size is not set correctly */
ioc_err(ioc, "Min Trace Buff size (%d KB) greater than Max Trace Buff size (%d KB)\n",
min_trace_buff_size>>10,
trace_buff_size>>10);
ioc_err(ioc, "Using zero Min Trace Buff Size\n");
min_trace_buff_size = 0;
}
if (decr_trace_buff_size == 0) { /* * retry the min size if decrement * is not available.
*/
decr_trace_buff_size =
trace_buff_size - min_trace_buff_size;
}
} else { /* register for 2MB buffers */
diag_register.requested_buffer_size = 2 * (1024 * 1024);
}
do {
ret_val = _ctl_diag_register_2(ioc, &diag_register);
/** * _ctl_diag_register - application register with driver * @ioc: per adapter object * @arg: user space buffer containing ioctl content * * This will allow the driver to setup any required buffers that will be * needed by firmware to communicate with the driver.
*/ staticlong
_ctl_diag_register(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{ struct mpt3_diag_register karg; long rc;
if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
}
rc = _ctl_diag_register_2(ioc, &karg);
if (!rc && (ioc->diag_buffer_status[karg.buffer_type] &
MPT3_DIAG_BUFFER_IS_REGISTERED))
ioc->diag_buffer_status[karg.buffer_type] |=
MPT3_DIAG_BUFFER_IS_APP_OWNED;
return rc;
}
/** * _ctl_diag_unregister - application unregister with driver * @ioc: per adapter object * @arg: user space buffer containing ioctl content * * This will allow the driver to cleanup any memory allocated for diag * messages and to free up any resources.
*/ staticlong
_ctl_diag_unregister(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{ struct mpt3_diag_unregister karg; void *request_data;
dma_addr_t request_data_dma;
u32 request_data_sz;
u8 buffer_type;
if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
}
dctlprintk(ioc, ioc_info(ioc, "%s\n",
__func__));
buffer_type = _ctl_diag_get_bufftype(ioc, karg.unique_id); if (buffer_type == MPT3_DIAG_UID_NOT_FOUND) {
ioc_err(ioc, "%s: buffer with unique_id(0x%08x) not found\n",
__func__, karg.unique_id); return -EINVAL;
}
if (!_ctl_diag_capability(ioc, buffer_type)) {
ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
__func__, buffer_type); return -EPERM;
}
if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
__func__, buffer_type); return -EINVAL;
} if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
ioc_err(ioc, "%s: buffer_type(0x%02x) has not been released\n",
__func__, buffer_type); return -EINVAL;
}
if (karg.unique_id != ioc->unique_id[buffer_type]) {
ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
__func__, karg.unique_id); return -EINVAL;
}
request_data = ioc->diag_buffer[buffer_type]; if (!request_data) {
ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
__func__, buffer_type); return -ENOMEM;
}
/** * _ctl_diag_query - query relevant info associated with diag buffers * @ioc: per adapter object * @arg: user space buffer containing ioctl content * * The application will send only buffer_type and unique_id. Driver will * inspect unique_id first, if valid, fill in all the info. If unique_id is * 0x00, the driver will return info specified by Buffer Type.
*/ staticlong
_ctl_diag_query(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{ struct mpt3_diag_query karg; void *request_data; int i;
u8 buffer_type;
if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
}
if (!_ctl_diag_capability(ioc, buffer_type)) {
ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
__func__, buffer_type); return -EPERM;
}
if (!(ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED)) { if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
__func__, buffer_type); return -EINVAL;
}
}
if (karg.unique_id) { if (karg.unique_id != ioc->unique_id[buffer_type]) {
ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
__func__, karg.unique_id); return -EINVAL;
}
}
request_data = ioc->diag_buffer[buffer_type]; if (!request_data) {
ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
__func__, buffer_type); return -ENOMEM;
}
if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_REGISTERED))
karg.application_flags |= MPT3_APP_FLAGS_BUFFER_VALID;
if (!(ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_RELEASED))
karg.application_flags |= MPT3_APP_FLAGS_FW_BUFFER_ACCESS;
if (!(ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_DRIVER_ALLOCATED))
karg.application_flags |= MPT3_APP_FLAGS_DYNAMIC_BUFFER_ALLOC;
if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_APP_OWNED))
karg.application_flags |= MPT3_APP_FLAGS_APP_OWNED;
for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++)
karg.product_specific[i] =
ioc->product_specific[buffer_type][i];
/** * _ctl_diag_release - request to send Diag Release Message to firmware * @ioc: ? * @arg: user space buffer containing ioctl content * * This allows ownership of the specified buffer to returned to the driver, * allowing an application to read the buffer without fear that firmware is * overwriting information in the buffer.
*/ staticlong
_ctl_diag_release(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{ struct mpt3_diag_release karg; void *request_data; int rc;
u8 buffer_type;
u8 issue_reset = 0;
if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
}
dctlprintk(ioc, ioc_info(ioc, "%s\n",
__func__));
buffer_type = _ctl_diag_get_bufftype(ioc, karg.unique_id); if (buffer_type == MPT3_DIAG_UID_NOT_FOUND) {
ioc_err(ioc, "%s: buffer with unique_id(0x%08x) not found\n",
__func__, karg.unique_id); return -EINVAL;
}
if (!_ctl_diag_capability(ioc, buffer_type)) {
ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
__func__, buffer_type); return -EPERM;
}
if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n",
__func__, buffer_type); return -EINVAL;
}
if (karg.unique_id != ioc->unique_id[buffer_type]) {
ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
__func__, karg.unique_id); return -EINVAL;
}
if (ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_RELEASED) {
ioc_err(ioc, "%s: buffer_type(0x%02x) is already released\n",
__func__, buffer_type); return -EINVAL;
}
request_data = ioc->diag_buffer[buffer_type];
if (!request_data) {
ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n",
__func__, buffer_type); return -ENOMEM;
}
/* buffers were released by due to host reset */ if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_DIAG_RESET)) {
ioc->diag_buffer_status[buffer_type] |=
MPT3_DIAG_BUFFER_IS_RELEASED;
ioc->diag_buffer_status[buffer_type] &=
~MPT3_DIAG_BUFFER_IS_DIAG_RESET;
ioc_err(ioc, "%s: buffer_type(0x%02x) was released due to host reset\n",
__func__, buffer_type); return 0;
}
if (issue_reset)
mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER);
return rc;
}
/** * _ctl_diag_read_buffer - request for copy of the diag buffer * @ioc: per adapter object * @arg: user space buffer containing ioctl content
*/ staticlong
_ctl_diag_read_buffer(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{ struct mpt3_diag_read_buffer karg; struct mpt3_diag_read_buffer __user *uarg = arg; void *request_data, *diag_data;
Mpi2DiagBufferPostRequest_t *mpi_request;
Mpi2DiagBufferPostReply_t *mpi_reply; int rc, i;
u8 buffer_type; unsignedlong request_size, copy_size;
u16 smid;
u16 ioc_status;
u8 issue_reset = 0;
if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
}
dctlprintk(ioc, ioc_info(ioc, "%s\n",
__func__));
buffer_type = _ctl_diag_get_bufftype(ioc, karg.unique_id); if (buffer_type == MPT3_DIAG_UID_NOT_FOUND) {
ioc_err(ioc, "%s: buffer with unique_id(0x%08x) not found\n",
__func__, karg.unique_id); return -EINVAL;
}
if (!_ctl_diag_capability(ioc, buffer_type)) {
ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n",
__func__, buffer_type); return -EPERM;
}
if (karg.unique_id != ioc->unique_id[buffer_type]) {
ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n",
__func__, karg.unique_id); return -EINVAL;
}
request_data = ioc->diag_buffer[buffer_type]; if (!request_data) {
ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n",
__func__, buffer_type); return -ENOMEM;
}
request_size = ioc->diag_buffer_sz[buffer_type];
if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) {
ioc_err(ioc, "%s: either the starting_offset or bytes_to_read are not 4 byte aligned\n",
__func__); return -EINVAL;
}
if (karg.starting_offset > request_size) return -EINVAL;
/* Truncate data on requests that are too large */ if ((diag_data + karg.bytes_to_read < diag_data) ||
(diag_data + karg.bytes_to_read > request_data + request_size))
copy_size = request_size - karg.starting_offset; else
copy_size = karg.bytes_to_read;
if (copy_to_user((void __user *)uarg->diagnostic_data,
diag_data, copy_size)) {
ioc_err(ioc, "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n",
__func__, diag_data); return -EFAULT;
}
if ((karg.flags & MPT3_FLAGS_REREGISTER) == 0) return 0;
dctlprintk(ioc,
ioc_info(ioc, "%s: Reregister buffer_type(0x%02x)\n",
__func__, buffer_type)); if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
dctlprintk(ioc,
ioc_info(ioc, "%s: buffer_type(0x%02x) is still registered\n",
__func__, buffer_type)); return 0;
} /* Get a free request frame and save the message context.
*/
if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
rc = -EAGAIN; goto out;
}
smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx); if (!smid) {
ioc_err(ioc, "%s: failed obtaining a smid\n", __func__);
rc = -EAGAIN; goto out;
}
/** * _ctl_addnl_diag_query - query relevant info associated with diag buffers * @ioc: per adapter object * @arg: user space buffer containing ioctl content * * The application will send only unique_id. Driver will * inspect unique_id first, if valid, fill the details related to cause * for diag buffer release.
*/ staticlong
_ctl_addnl_diag_query(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{ struct mpt3_addnl_diag_query karg;
u32 buffer_type = 0;
if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("%s: failure at %s:%d/%s()!\n",
ioc->name, __FILE__, __LINE__, __func__); return -EFAULT;
}
dctlprintk(ioc, ioc_info(ioc, "%s\n", __func__)); if (karg.unique_id == 0) {
ioc_err(ioc, "%s: unique_id is(0x%08x)\n",
__func__, karg.unique_id); return -EPERM;
}
buffer_type = _ctl_diag_get_bufftype(ioc, karg.unique_id); if (buffer_type == MPT3_DIAG_UID_NOT_FOUND) {
ioc_err(ioc, "%s: buffer with unique_id(0x%08x) not found\n",
__func__, karg.unique_id); return -EPERM;
}
memset(&karg.rel_query, 0, sizeof(karg.rel_query)); if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
ioc_info(ioc, "%s: buffer_type(0x%02x) is not registered\n",
__func__, buffer_type); goto out;
} if ((ioc->diag_buffer_status[buffer_type] &
MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
ioc_err(ioc, "%s: buffer_type(0x%02x) is not released\n",
__func__, buffer_type); return -EPERM;
}
memcpy(&karg.rel_query, &ioc->htb_rel, sizeof(karg.rel_query));
out: if (copy_to_user(arg, &karg, sizeof(struct mpt3_addnl_diag_query))) {
ioc_err(ioc, "%s: unable to write mpt3_addnl_diag_query data @ %p\n",
__func__, arg); return -EFAULT;
} return 0;
}
/** * _ctl_enable_diag_sbr_reload - enable sbr reload bit * @ioc: per adapter object * @arg: user space buffer containing ioctl content * * Enable the SBR reload bit
*/ staticint
_ctl_enable_diag_sbr_reload(struct MPT3SAS_ADAPTER *ioc, void __user *arg)
{
u32 ioc_state, host_diagnostic;
if (ioc->shost_recovery ||
ioc->pci_error_recovery || ioc->is_driver_loading ||
ioc->remove_host) return -EAGAIN;
ioc_state = mpt3sas_base_get_iocstate(ioc, 1);
if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) return -EFAULT;
/** * _ctl_ioctl_main - main ioctl entry point * @file: (struct file) * @cmd: ioctl opcode * @arg: user space data buffer * @compat: handles 32 bit applications in 64bit os * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device & * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device.
*/ staticlong
_ctl_ioctl_main(struct file *file, unsignedint cmd, void __user *arg,
u8 compat, u16 mpi_version)
{ struct MPT3SAS_ADAPTER *ioc; struct mpt3_ioctl_header ioctl_header; enum block_state state; long ret = -ENOIOCTLCMD;
/* get IOCTL header */ if (copy_from_user(&ioctl_header, (char __user *)arg, sizeof(struct mpt3_ioctl_header))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__); return -EFAULT;
}
if (_ctl_verify_adapter(ioctl_header.ioc_number,
&ioc, mpi_version) == -1 || !ioc) return -ENODEV;
/* pci_access_mutex lock acquired by ioctl path */
mutex_lock(&ioc->pci_access_mutex);
if (ioc->shost_recovery || ioc->pci_error_recovery ||
ioc->is_driver_loading || ioc->remove_host) {
ret = -EAGAIN; goto out_unlock_pciaccess;
}
state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING; if (state == NON_BLOCKING) { if (!mutex_trylock(&ioc->ctl_cmds.mutex)) {
ret = -EAGAIN; goto out_unlock_pciaccess;
}
} elseif (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) {
ret = -ERESTARTSYS; goto out_unlock_pciaccess;
}
switch (cmd) { case MPT3IOCINFO: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_iocinfo))
ret = _ctl_getiocinfo(ioc, arg); break; #ifdef CONFIG_COMPAT case MPT3COMMAND32: #endif case MPT3COMMAND:
{ struct mpt3_ioctl_command __user *uarg; struct mpt3_ioctl_command karg;
#ifdef CONFIG_COMPAT if (compat) {
ret = _ctl_compat_mpt_command(ioc, cmd, arg); break;
} #endif if (copy_from_user(&karg, arg, sizeof(karg))) {
pr_err("failure at %s:%d/%s()!\n",
__FILE__, __LINE__, __func__);
ret = -EFAULT; break;
}
if (karg.hdr.ioc_number != ioctl_header.ioc_number) {
ret = -EINVAL; break;
} if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_command)) {
uarg = arg;
ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf);
} break;
} case MPT3EVENTQUERY: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventquery))
ret = _ctl_eventquery(ioc, arg); break; case MPT3EVENTENABLE: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventenable))
ret = _ctl_eventenable(ioc, arg); break; case MPT3EVENTREPORT:
ret = _ctl_eventreport(ioc, arg); break; case MPT3HARDRESET: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_diag_reset))
ret = _ctl_do_reset(ioc, arg); break; case MPT3BTDHMAPPING: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_btdh_mapping))
ret = _ctl_btdh_mapping(ioc, arg); break; case MPT3DIAGREGISTER: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_register))
ret = _ctl_diag_register(ioc, arg); break; case MPT3DIAGUNREGISTER: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_unregister))
ret = _ctl_diag_unregister(ioc, arg); break; case MPT3DIAGQUERY: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_query))
ret = _ctl_diag_query(ioc, arg); break; case MPT3DIAGRELEASE: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_release))
ret = _ctl_diag_release(ioc, arg); break; case MPT3DIAGREADBUFFER: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_read_buffer))
ret = _ctl_diag_read_buffer(ioc, arg); break; case MPT3ADDNLDIAGQUERY: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_addnl_diag_query))
ret = _ctl_addnl_diag_query(ioc, arg); break; case MPT3ENABLEDIAGSBRRELOAD: if (_IOC_SIZE(cmd) == sizeof(struct mpt3_enable_diag_sbr_reload))
ret = _ctl_enable_diag_sbr_reload(ioc, arg); break; default:
dctlprintk(ioc,
ioc_info(ioc, "unsupported ioctl opcode(0x%08x)\n",
cmd)); break;
}
/** * _ctl_get_mpt_mctp_passthru_adapter - Traverse the IOC list and return the IOC at * dev_index positionthat support MCTP passhtru * @dev_index: position in the mpt3sas_ioc_list to search for * Return pointer to the IOC on success * NULL if device not found error
*/ staticstruct MPT3SAS_ADAPTER *
_ctl_get_mpt_mctp_passthru_adapter(int dev_index)
{ struct MPT3SAS_ADAPTER *ioc = NULL; int count = 0;
spin_lock(&gioc_lock); /* Traverse ioc list and return number of IOC that support MCTP passthru */
list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { if (ioc->facts.IOCCapabilities & MPI26_IOCFACTS_CAPABILITY_MCTP_PASSTHRU) { if (count == dev_index) {
spin_unlock(&gioc_lock); return ioc;
}
count++;
}
}
spin_unlock(&gioc_lock);
return NULL;
}
/** * mpt3sas_get_device_count - Retrieve the count of MCTP passthrough * capable devices managed by the driver. * * Returns number of devices that support MCTP passthrough.
*/ int
mpt3sas_get_device_count(void)
{ int count = 0; struct MPT3SAS_ADAPTER *ioc = NULL;
spin_lock(&gioc_lock); /* Traverse ioc list and return number of IOC that support MCTP passthru */
list_for_each_entry(ioc, &mpt3sas_ioc_list, list) if (ioc->facts.IOCCapabilities & MPI26_IOCFACTS_CAPABILITY_MCTP_PASSTHRU)
count++;
/** * mpt3sas_send_passthru_cmd - Send an MPI MCTP passthrough command to * firmware * @command: The MPI MCTP passthrough command to send to firmware * * Returns 0 on success, anything else is error.
*/ int mpt3sas_send_mctp_passthru_req(struct mpt3_passthru_command *command)
{ struct MPT3SAS_ADAPTER *ioc;
MPI2RequestHeader_t *mpi_request = NULL, *request;
Mpi26MctpPassthroughRequest_t *mctp_passthru_req;
u16 smid; unsignedlong timeout;
u8 issue_reset = 0;
u32 sz; void *psge; void *data_out = NULL;
dma_addr_t data_out_dma = 0;
size_t data_out_sz = 0; void *data_in = NULL;
dma_addr_t data_in_dma = 0;
size_t data_in_sz = 0; long ret;
/* Retrieve ioc from dev_index */
ioc = _ctl_get_mpt_mctp_passthru_adapter(command->dev_index); if (!ioc) return -ENODEV;
mutex_lock(&ioc->pci_access_mutex); if (ioc->shost_recovery ||
ioc->pci_error_recovery || ioc->is_driver_loading ||
ioc->remove_host) {
ret = -EAGAIN; goto unlock_pci_access;
}
/* Lock the ctl_cmds mutex to ensure a single ctl cmd is pending */ if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) {
ret = -ERESTARTSYS; goto unlock_pci_access;
}
if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) {
ioc_err(ioc, "%s: ctl_cmd in use\n", __func__);
ret = -EAGAIN; goto unlock_ctl_cmds;
}
ret = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT); if (ret) goto unlock_ctl_cmds;
mpi_request = (MPI2RequestHeader_t *)command->mpi_request; if (mpi_request->Function != MPI2_FUNCTION_MCTP_PASSTHROUGH) {
ioc_err(ioc, "%s: Invalid request received, Function 0x%x\n",
__func__, mpi_request->Function);
ret = -EINVAL; goto unlock_ctl_cmds;
}
/** * host_sas_address_show - sas address * @cdev: pointer to embedded class device * @attr: ? * @buf: the buffer returned * * This is the controller sas address * * A sysfs 'read-only' shost attribute.
*/ static ssize_t
host_sas_address_show(struct device *cdev, struct device_attribute *attr, char *buf)
/** * BRM_status_show - Backup Rail Monitor Status * @cdev: pointer to embedded class device * @attr: ? * @buf: the buffer returned * * This is number of reply queues * * A sysfs 'read-only' shost attribute.
*/ static ssize_t
BRM_status_show(struct device *cdev, struct device_attribute *attr, char *buf)
{ struct Scsi_Host *shost = class_to_shost(cdev); struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
Mpi2IOUnitPage3_t io_unit_pg3;
Mpi2ConfigReply_t mpi_reply;
u16 backup_rail_monitor_status = 0;
u16 ioc_status; int sz;
ssize_t rc = 0;
if (!ioc->is_warpdrive) {
ioc_err(ioc, "%s: BRM attribute is only for warpdrive\n",
__func__); return 0;
} /* pci_access_mutex lock acquired by sysfs show path */
mutex_lock(&ioc->pci_access_mutex); if (ioc->pci_error_recovery || ioc->remove_host) goto out;
if (io_unit_pg3.GPIOCount < 25) {
ioc_err(ioc, "%s: iounit_pg3.GPIOCount less than 25 entries, detected (%d) entries\n",
__func__, io_unit_pg3.GPIOCount);
rc = -EINVAL; goto out;
}
/* BRM status is in bit zero of GPIOVal[24] */
backup_rail_monitor_status = le16_to_cpu(io_unit_pg3.GPIOVal[24]);
rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1));
/** * host_trace_buffer_show - firmware ring buffer (trace only) * @cdev: pointer to embedded class device * @attr: ? * @buf: the buffer returned * * A sysfs 'read/write' shost attribute. * * You will only be able to read 4k bytes of ring buffer at a time. * In order to read beyond 4k bytes, you will have to write out the * offset to the same attribute, it will move the pointer.
*/ static ssize_t
host_trace_buffer_show(struct device *cdev, struct device_attribute *attr, char *buf)
{ struct Scsi_Host *shost = class_to_shost(cdev); struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); void *request_data;
u32 size;
if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) {
ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
__func__); return 0;
}
if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
ioc_err(ioc, "%s: host_trace_buffer is not registered\n",
__func__); return 0;
}
if (ioc->ring_buffer_offset > ioc->ring_buffer_sz) return 0;
/* don't allow post/release occurr while recovery is active */ if (ioc->shost_recovery || ioc->remove_host ||
ioc->pci_error_recovery || ioc->is_driver_loading) return -EBUSY;
if (sscanf(buf, "%9s", str) != 1) return -EINVAL;
if (!strcmp(str, "post")) { /* exit out if host buffers are already posted */ if ((ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) &&
(ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) &&
((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED) == 0)) goto out;
memset(&diag_register, 0, sizeof(struct mpt3_diag_register));
ioc_info(ioc, "posting host trace buffers\n");
diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE;
if (ioc->manu_pg11.HostTraceBufferMaxSizeKB != 0 &&
ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE] != 0) { /* post the same buffer allocated previously */
diag_register.requested_buffer_size =
ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE];
} else { /* * Free the diag buffer memory which was previously * allocated by an application.
*/ if ((ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE] != 0)
&&
(ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_APP_OWNED)) {
dma_free_coherent(&ioc->pdev->dev,
ioc->diag_buffer_sz[MPI2_DIAG_BUF_TYPE_TRACE],
ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE],
ioc->diag_buffer_dma[MPI2_DIAG_BUF_TYPE_TRACE]);
ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE] =
NULL;
}
/** * enable_sdev_max_qd_show - display whether sdev max qd is enabled/disabled * @cdev: pointer to embedded class device * @attr: unused * @buf: the buffer returned * * A sysfs read/write shost attribute. This attribute is used to set the * targets queue depth to HBA IO queue depth if this attribute is enabled.
*/ static ssize_t
enable_sdev_max_qd_show(struct device *cdev, struct device_attribute *attr, char *buf)
{ struct Scsi_Host *shost = class_to_shost(cdev); struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
/** * enable_sdev_max_qd_store - Enable/disable sdev max qd * @cdev: pointer to embedded class device * @attr: unused * @buf: the buffer returned * @count: unused * * A sysfs read/write shost attribute. This attribute is used to set the * targets queue depth to HBA IO queue depth if this attribute is enabled. * If this attribute is disabled then targets will have corresponding default * queue depth.
*/ static ssize_t
enable_sdev_max_qd_store(struct device *cdev, struct device_attribute *attr, constchar *buf, size_t count)
{ struct Scsi_Host *shost = class_to_shost(cdev); struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); struct MPT3SAS_DEVICE *sas_device_priv_data; struct MPT3SAS_TARGET *sas_target_priv_data; int val = 0; struct scsi_device *sdev; struct _raid_device *raid_device; int qdepth;
if (kstrtoint(buf, 0, &val) != 0) return -EINVAL;
switch (val) { case 0:
ioc->enable_sdev_max_qd = 0;
shost_for_each_device(sdev, ioc->shost) {
sas_device_priv_data = sdev->hostdata; if (!sas_device_priv_data) continue;
sas_target_priv_data = sas_device_priv_data->sas_target; if (!sas_target_priv_data) continue;
if (sas_target_priv_data->flags &
MPT_TARGET_FLAGS_VOLUME) {
raid_device =
mpt3sas_raid_device_find_by_handle(ioc,
sas_target_priv_data->handle);
switch (raid_device->volume_type) { case MPI2_RAID_VOL_TYPE_RAID0: if (raid_device->device_info &
MPI2_SAS_DEVICE_INFO_SSP_TARGET)
qdepth =
MPT3SAS_SAS_QUEUE_DEPTH; else
qdepth =
MPT3SAS_SATA_QUEUE_DEPTH; break; case MPI2_RAID_VOL_TYPE_RAID1E: case MPI2_RAID_VOL_TYPE_RAID1: case MPI2_RAID_VOL_TYPE_RAID10: case MPI2_RAID_VOL_TYPE_UNKNOWN: default:
qdepth = MPT3SAS_RAID_QUEUE_DEPTH;
}
} elseif (sas_target_priv_data->flags &
MPT_TARGET_FLAGS_PCIE_DEVICE)
qdepth = ioc->max_nvme_qd; else
qdepth = (sas_target_priv_data->sas_dev->port_type > 1) ?
ioc->max_wideport_qd : ioc->max_narrowport_qd;
/** * sas_address_show - sas address * @dev: pointer to embedded class device * @attr: ? * @buf: the buffer returned * * This is the sas address for the target * * A sysfs 'read-only' shost attribute.
*/ static ssize_t
sas_address_show(struct device *dev, struct device_attribute *attr, char *buf)
{ struct scsi_device *sdev = to_scsi_device(dev); struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.