Lines Matching +full:diag +full:- +full:version

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2017-2023 Broadcom Inc.
6 * (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
11 #include <linux/bsg-lib.h>
20 * Return: 0 on success, non-zero on failure.
24 struct diag_buffer_desc *diag_buffer = &mrioc->diag_buffers[0]; in mpi3mr_alloc_trace_buffer()
26 diag_buffer->addr = dma_alloc_coherent(&mrioc->pdev->dev, in mpi3mr_alloc_trace_buffer()
27 trace_size, &diag_buffer->dma_addr, GFP_KERNEL); in mpi3mr_alloc_trace_buffer()
28 if (diag_buffer->addr) { in mpi3mr_alloc_trace_buffer()
29 dprint_init(mrioc, "trace diag buffer is allocated successfully\n"); in mpi3mr_alloc_trace_buffer()
32 return -1; in mpi3mr_alloc_trace_buffer()
36 * mpi3mr_alloc_diag_bufs - Allocate memory for diag buffers
56 if (mrioc->diag_buffers[0].addr || mrioc->diag_buffers[1].addr) in mpi3mr_alloc_diag_bufs()
63 "and firmware diag buffers of default size\n", __func__); in mpi3mr_alloc_diag_bufs()
77 "%s:trace diag buffer sizes read from driver\n" in mpi3mr_alloc_diag_bufs()
83 "%s:firmware diag buffer sizes read from driver\n" in mpi3mr_alloc_diag_bufs()
94 diag_buffer = &mrioc->diag_buffers[0]; in mpi3mr_alloc_diag_bufs()
95 diag_buffer->type = MPI3_DIAG_BUFFER_TYPE_TRACE; in mpi3mr_alloc_diag_bufs()
96 diag_buffer->status = MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED; in mpi3mr_alloc_diag_bufs()
97 if ((mrioc->facts.diag_trace_sz < trace_size) && (trace_size >= in mpi3mr_alloc_diag_bufs()
101 "trying to allocate trace diag buffer of size = %dKB\n", in mpi3mr_alloc_diag_bufs()
106 trace_size -= trace_dec_size; in mpi3mr_alloc_diag_bufs()
107 dprint_init(mrioc, "trace diag buffer allocation failed\n" in mpi3mr_alloc_diag_bufs()
111 diag_buffer->size = trace_size; in mpi3mr_alloc_diag_bufs()
117 diag_buffer = &mrioc->diag_buffers[1]; in mpi3mr_alloc_diag_bufs()
119 diag_buffer->type = MPI3_DIAG_BUFFER_TYPE_FW; in mpi3mr_alloc_diag_bufs()
120 diag_buffer->status = MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED; in mpi3mr_alloc_diag_bufs()
121 if ((mrioc->facts.diag_fw_sz < fw_size) && (fw_size >= fw_min_size)) { in mpi3mr_alloc_diag_bufs()
123 diag_buffer->addr in mpi3mr_alloc_diag_bufs()
124 = dma_alloc_coherent(&mrioc->pdev->dev, fw_size, in mpi3mr_alloc_diag_bufs()
125 &diag_buffer->dma_addr, in mpi3mr_alloc_diag_bufs()
130 "%s:trying to allocate firmware diag buffer of size = %dKB\n", in mpi3mr_alloc_diag_bufs()
132 if (diag_buffer->addr) { in mpi3mr_alloc_diag_bufs()
133 dprint_init(mrioc, "%s:firmware diag buffer allocated successfully\n", in mpi3mr_alloc_diag_bufs()
135 diag_buffer->size = fw_size; in mpi3mr_alloc_diag_bufs()
138 fw_size -= fw_dec_size; in mpi3mr_alloc_diag_bufs()
139 dprint_init(mrioc, "%s:trace diag buffer allocation failed,\n" in mpi3mr_alloc_diag_bufs()
148 * mpi3mr_issue_diag_buf_post - Send diag buffer post req
155 * Return: 0 on success, non-zero on failures.
165 mutex_lock(&mrioc->init_cmds.mutex); in mpi3mr_issue_diag_buf_post()
166 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) { in mpi3mr_issue_diag_buf_post()
168 mutex_unlock(&mrioc->init_cmds.mutex); in mpi3mr_issue_diag_buf_post()
169 return -1; in mpi3mr_issue_diag_buf_post()
171 mrioc->init_cmds.state = MPI3MR_CMD_PENDING; in mpi3mr_issue_diag_buf_post()
172 mrioc->init_cmds.is_waiting = 1; in mpi3mr_issue_diag_buf_post()
173 mrioc->init_cmds.callback = NULL; in mpi3mr_issue_diag_buf_post()
176 diag_buf_post_req.type = diag_buffer->type; in mpi3mr_issue_diag_buf_post()
177 diag_buf_post_req.address = le64_to_cpu(diag_buffer->dma_addr); in mpi3mr_issue_diag_buf_post()
178 diag_buf_post_req.length = le32_to_cpu(diag_buffer->size); in mpi3mr_issue_diag_buf_post()
180 dprint_bsg_info(mrioc, "%s: posting diag buffer type %d\n", __func__, in mpi3mr_issue_diag_buf_post()
181 diag_buffer->type); in mpi3mr_issue_diag_buf_post()
182 prev_status = diag_buffer->status; in mpi3mr_issue_diag_buf_post()
183 diag_buffer->status = MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED; in mpi3mr_issue_diag_buf_post()
184 init_completion(&mrioc->init_cmds.done); in mpi3mr_issue_diag_buf_post()
192 wait_for_completion_timeout(&mrioc->init_cmds.done, in mpi3mr_issue_diag_buf_post()
194 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) { in mpi3mr_issue_diag_buf_post()
195 mrioc->init_cmds.is_waiting = 0; in mpi3mr_issue_diag_buf_post()
199 retval = -1; in mpi3mr_issue_diag_buf_post()
202 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK) in mpi3mr_issue_diag_buf_post()
206 __func__, diag_buffer->type, in mpi3mr_issue_diag_buf_post()
207 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK), in mpi3mr_issue_diag_buf_post()
208 mrioc->init_cmds.ioc_loginfo); in mpi3mr_issue_diag_buf_post()
209 retval = -1; in mpi3mr_issue_diag_buf_post()
212 dprint_bsg_info(mrioc, "%s: diag buffer type %d posted successfully\n", in mpi3mr_issue_diag_buf_post()
213 __func__, diag_buffer->type); in mpi3mr_issue_diag_buf_post()
217 diag_buffer->status = prev_status; in mpi3mr_issue_diag_buf_post()
218 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED; in mpi3mr_issue_diag_buf_post()
219 mutex_unlock(&mrioc->init_cmds.mutex); in mpi3mr_issue_diag_buf_post()
224 * mpi3mr_post_diag_bufs - Post diag buffers to the controller
238 diag_buffer = &mrioc->diag_buffers[i]; in mpi3mr_post_diag_bufs()
239 if (!(diag_buffer->addr)) in mpi3mr_post_diag_bufs()
242 return -1; in mpi3mr_post_diag_bufs()
248 * mpi3mr_issue_diag_buf_release - Send diag buffer release req
256 * Return: 0 on success, non-zero on failures.
264 if ((diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) && in mpi3mr_issue_diag_buf_release()
265 (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED)) in mpi3mr_issue_diag_buf_release()
269 mutex_lock(&mrioc->init_cmds.mutex); in mpi3mr_issue_diag_buf_release()
270 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) { in mpi3mr_issue_diag_buf_release()
272 mutex_unlock(&mrioc->init_cmds.mutex); in mpi3mr_issue_diag_buf_release()
273 return -1; in mpi3mr_issue_diag_buf_release()
275 mrioc->init_cmds.state = MPI3MR_CMD_PENDING; in mpi3mr_issue_diag_buf_release()
276 mrioc->init_cmds.is_waiting = 1; in mpi3mr_issue_diag_buf_release()
277 mrioc->init_cmds.callback = NULL; in mpi3mr_issue_diag_buf_release()
280 diag_buf_manage_req.type = diag_buffer->type; in mpi3mr_issue_diag_buf_release()
284 dprint_reset(mrioc, "%s: releasing diag buffer type %d\n", __func__, in mpi3mr_issue_diag_buf_release()
285 diag_buffer->type); in mpi3mr_issue_diag_buf_release()
286 init_completion(&mrioc->init_cmds.done); in mpi3mr_issue_diag_buf_release()
295 wait_for_completion_timeout(&mrioc->init_cmds.done, in mpi3mr_issue_diag_buf_release()
297 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) { in mpi3mr_issue_diag_buf_release()
298 mrioc->init_cmds.is_waiting = 0; in mpi3mr_issue_diag_buf_release()
302 retval = -1; in mpi3mr_issue_diag_buf_release()
305 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK) in mpi3mr_issue_diag_buf_release()
309 __func__, diag_buffer->type, in mpi3mr_issue_diag_buf_release()
310 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK), in mpi3mr_issue_diag_buf_release()
311 mrioc->init_cmds.ioc_loginfo); in mpi3mr_issue_diag_buf_release()
312 retval = -1; in mpi3mr_issue_diag_buf_release()
315 dprint_reset(mrioc, "%s: diag buffer type %d released successfully\n", in mpi3mr_issue_diag_buf_release()
316 __func__, diag_buffer->type); in mpi3mr_issue_diag_buf_release()
319 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED; in mpi3mr_issue_diag_buf_release()
320 mutex_unlock(&mrioc->init_cmds.mutex); in mpi3mr_issue_diag_buf_release()
325 * mpi3mr_process_trigger - Generic HDB Trigger handler
350 (trace_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) && in mpi3mr_process_trigger()
351 (trace_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED)) in mpi3mr_process_trigger()
357 (fw_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) && in mpi3mr_process_trigger()
358 (fw_hdb->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED)) in mpi3mr_process_trigger()
361 if (mrioc->snapdump_trigger_active || (mrioc->fw_release_trigger_active in mpi3mr_process_trigger()
362 && mrioc->trace_release_trigger_active) || in mpi3mr_process_trigger()
363 (!trace_hdb && !fw_hdb) || (!mrioc->driver_pg2) || in mpi3mr_process_trigger()
365 && (!mrioc->driver_pg2->num_triggers))) in mpi3mr_process_trigger()
372 global_trigger = le64_to_cpu(mrioc->driver_pg2->global_trigger); in mpi3mr_process_trigger()
378 mrioc->snapdump_trigger_active = true; in mpi3mr_process_trigger()
382 (!mrioc->trace_release_trigger_active)) { in mpi3mr_process_trigger()
384 mrioc->trace_release_trigger_active = true; in mpi3mr_process_trigger()
388 (!mrioc->fw_release_trigger_active)) { in mpi3mr_process_trigger()
390 mrioc->fw_release_trigger_active = true; in mpi3mr_process_trigger()
395 (!mrioc->trace_release_trigger_active)) { in mpi3mr_process_trigger()
397 mrioc->trace_release_trigger_active = true; in mpi3mr_process_trigger()
401 (!mrioc->fw_release_trigger_active)) { in mpi3mr_process_trigger()
403 mrioc->fw_release_trigger_active = true; in mpi3mr_process_trigger()
412 * mpi3mr_global_trigger - Global HDB trigger handler
427 spin_lock_irqsave(&mrioc->trigger_lock, flags); in mpi3mr_global_trigger()
428 if (le64_to_cpu(mrioc->driver_pg2->global_trigger) & trigger_data) { in mpi3mr_global_trigger()
435 spin_unlock_irqrestore(&mrioc->trigger_lock, flags); in mpi3mr_global_trigger()
439 * mpi3mr_scsisense_trigger - SCSI sense HDB trigger handler
459 if (mrioc->scsisense_trigger_present) { in mpi3mr_scsisense_trigger()
460 spin_lock_irqsave(&mrioc->trigger_lock, flags); in mpi3mr_scsisense_trigger()
462 mrioc->driver_pg2->trigger; in mpi3mr_scsisense_trigger()
463 num_triggers = mrioc->driver_pg2->num_triggers; in mpi3mr_scsisense_trigger()
465 if (scsi_sense_trigger->type != in mpi3mr_scsisense_trigger()
468 if (!(scsi_sense_trigger->sense_key == in mpi3mr_scsisense_trigger()
470 || scsi_sense_trigger->sense_key == sensekey)) in mpi3mr_scsisense_trigger()
472 if (!(scsi_sense_trigger->asc == in mpi3mr_scsisense_trigger()
474 scsi_sense_trigger->asc == asc)) in mpi3mr_scsisense_trigger()
476 if (!(scsi_sense_trigger->ascq == in mpi3mr_scsisense_trigger()
478 scsi_sense_trigger->ascq == ascq)) in mpi3mr_scsisense_trigger()
480 trigger_flags = scsi_sense_trigger->flags; in mpi3mr_scsisense_trigger()
487 spin_unlock_irqrestore(&mrioc->trigger_lock, flags); in mpi3mr_scsisense_trigger()
492 * mpi3mr_event_trigger - MPI event HDB trigger handler
509 if (mrioc->event_trigger_present) { in mpi3mr_event_trigger()
510 spin_lock_irqsave(&mrioc->trigger_lock, flags); in mpi3mr_event_trigger()
512 mrioc->driver_pg2->trigger; in mpi3mr_event_trigger()
513 num_triggers = mrioc->driver_pg2->num_triggers; in mpi3mr_event_trigger()
516 if (event_trigger->type != in mpi3mr_event_trigger()
519 if (event_trigger->event != event) in mpi3mr_event_trigger()
521 trigger_flags = event_trigger->flags; in mpi3mr_event_trigger()
528 spin_unlock_irqrestore(&mrioc->trigger_lock, flags); in mpi3mr_event_trigger()
533 * mpi3mr_reply_trigger - MPI Reply HDB trigger handler
552 if (mrioc->reply_trigger_present) { in mpi3mr_reply_trigger()
553 spin_lock_irqsave(&mrioc->trigger_lock, flags); in mpi3mr_reply_trigger()
555 mrioc->driver_pg2->trigger; in mpi3mr_reply_trigger()
556 num_triggers = mrioc->driver_pg2->num_triggers; in mpi3mr_reply_trigger()
558 if (reply_trigger->type != in mpi3mr_reply_trigger()
561 if ((le16_to_cpu(reply_trigger->ioc_status) != in mpi3mr_reply_trigger()
563 && (le16_to_cpu(reply_trigger->ioc_status) != in mpi3mr_reply_trigger()
566 if ((le32_to_cpu(reply_trigger->ioc_log_info) != in mpi3mr_reply_trigger()
567 (le32_to_cpu(reply_trigger->ioc_log_info_mask) & in mpi3mr_reply_trigger()
570 trigger_flags = reply_trigger->flags; in mpi3mr_reply_trigger()
577 spin_unlock_irqrestore(&mrioc->trigger_lock, flags); in mpi3mr_reply_trigger()
582 * mpi3mr_get_num_trigger - Gets number of HDB triggers
612 * mpi3mr_refresh_trigger - Handler for Refresh trigger BSG
640 retval = -ENOMEM; in mpi3mr_refresh_trigger()
650 spin_lock_irqsave(&mrioc->trigger_lock, flags); in mpi3mr_refresh_trigger()
651 kfree(mrioc->driver_pg2); in mpi3mr_refresh_trigger()
652 mrioc->driver_pg2 = drvr_page2; in mpi3mr_refresh_trigger()
653 mrioc->reply_trigger_present = false; in mpi3mr_refresh_trigger()
654 mrioc->event_trigger_present = false; in mpi3mr_refresh_trigger()
655 mrioc->scsisense_trigger_present = false; in mpi3mr_refresh_trigger()
657 for (i = 0; (i < mrioc->driver_pg2->num_triggers); i++) { in mpi3mr_refresh_trigger()
658 trigger_type = mrioc->driver_pg2->trigger[i].event.type; in mpi3mr_refresh_trigger()
661 mrioc->reply_trigger_present = true; in mpi3mr_refresh_trigger()
664 mrioc->event_trigger_present = true; in mpi3mr_refresh_trigger()
667 mrioc->scsisense_trigger_present = true; in mpi3mr_refresh_trigger()
673 spin_unlock_irqrestore(&mrioc->trigger_lock, flags); in mpi3mr_refresh_trigger()
679 * mpi3mr_release_diag_bufs - Release diag buffers
694 diag_buffer = &mrioc->diag_buffers[i]; in mpi3mr_release_diag_bufs()
695 if (!(diag_buffer->addr)) in mpi3mr_release_diag_bufs()
697 if (diag_buffer->status == MPI3MR_HDB_BUFSTATUS_RELEASED) in mpi3mr_release_diag_bufs()
701 diag_buffer->status = MPI3MR_HDB_BUFSTATUS_RELEASED; in mpi3mr_release_diag_bufs()
707 * mpi3mr_set_trigger_data_in_hdb - Updates HDB trigger type and
724 if ((!force) && (hdb->trigger_type != MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN)) in mpi3mr_set_trigger_data_in_hdb()
726 hdb->trigger_type = type; in mpi3mr_set_trigger_data_in_hdb()
728 memset(&hdb->trigger_data, 0, sizeof(*trigger_data)); in mpi3mr_set_trigger_data_in_hdb()
730 memcpy(&hdb->trigger_data, trigger_data, sizeof(*trigger_data)); in mpi3mr_set_trigger_data_in_hdb()
734 * mpi3mr_set_trigger_data_in_all_hdb - Updates HDB trigger type
762 * mpi3mr_hdbstatuschg_evt_th - HDB status change evt tophalf
766 * Modifies the status of the applicable diag buffer descriptors
777 event_reply->event_data; in mpi3mr_hdbstatuschg_evt_th()
779 diag_buffer = mpi3mr_diag_buffer_for_type(mrioc, evtdata->type); in mpi3mr_hdbstatuschg_evt_th()
782 if ((diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED) && in mpi3mr_hdbstatuschg_evt_th()
783 (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED)) in mpi3mr_hdbstatuschg_evt_th()
785 switch (evtdata->reason_code) { in mpi3mr_hdbstatuschg_evt_th()
788 diag_buffer->status = MPI3MR_HDB_BUFSTATUS_RELEASED; in mpi3mr_hdbstatuschg_evt_th()
796 diag_buffer->status = MPI3MR_HDB_BUFSTATUS_POSTED_UNPAUSED; in mpi3mr_hdbstatuschg_evt_th()
801 diag_buffer->status = MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED; in mpi3mr_hdbstatuschg_evt_th()
806 __func__, evtdata->reason_code); in mpi3mr_hdbstatuschg_evt_th()
812 * mpi3mr_diag_buffer_for_type - returns buffer desc for type
816 * Identifies matching diag descriptor from mrioc for given diag
819 * Return: diag buffer descriptor on success, NULL on failures.
828 if (mrioc->diag_buffers[i].type == buf_type) in mpi3mr_diag_buffer_for_type()
829 return &mrioc->diag_buffers[i]; in mpi3mr_diag_buffer_for_type()
835 * mpi3mr_bsg_pel_abort - sends PEL abort request
841 * Return: 0 on success, -1 on failure
850 if (mrioc->reset_in_progress) { in mpi3mr_bsg_pel_abort()
852 return -1; in mpi3mr_bsg_pel_abort()
854 if (mrioc->stop_bsgs || mrioc->block_on_pci_err) { in mpi3mr_bsg_pel_abort()
856 return -1; in mpi3mr_bsg_pel_abort()
860 mutex_lock(&mrioc->pel_abort_cmd.mutex); in mpi3mr_bsg_pel_abort()
861 if (mrioc->pel_abort_cmd.state & MPI3MR_CMD_PENDING) { in mpi3mr_bsg_pel_abort()
863 mutex_unlock(&mrioc->pel_abort_cmd.mutex); in mpi3mr_bsg_pel_abort()
864 return -1; in mpi3mr_bsg_pel_abort()
866 mrioc->pel_abort_cmd.state = MPI3MR_CMD_PENDING; in mpi3mr_bsg_pel_abort()
867 mrioc->pel_abort_cmd.is_waiting = 1; in mpi3mr_bsg_pel_abort()
868 mrioc->pel_abort_cmd.callback = NULL; in mpi3mr_bsg_pel_abort()
874 mrioc->pel_abort_requested = 1; in mpi3mr_bsg_pel_abort()
875 init_completion(&mrioc->pel_abort_cmd.done); in mpi3mr_bsg_pel_abort()
879 retval = -1; in mpi3mr_bsg_pel_abort()
882 mrioc->pel_abort_requested = 0; in mpi3mr_bsg_pel_abort()
886 wait_for_completion_timeout(&mrioc->pel_abort_cmd.done, in mpi3mr_bsg_pel_abort()
888 if (!(mrioc->pel_abort_cmd.state & MPI3MR_CMD_COMPLETE)) { in mpi3mr_bsg_pel_abort()
889 mrioc->pel_abort_cmd.is_waiting = 0; in mpi3mr_bsg_pel_abort()
891 if (!(mrioc->pel_abort_cmd.state & MPI3MR_CMD_RESET)) in mpi3mr_bsg_pel_abort()
894 retval = -1; in mpi3mr_bsg_pel_abort()
897 if ((mrioc->pel_abort_cmd.ioc_status & MPI3_IOCSTATUS_STATUS_MASK) in mpi3mr_bsg_pel_abort()
901 __func__, (mrioc->pel_abort_cmd.ioc_status & in mpi3mr_bsg_pel_abort()
903 mrioc->pel_abort_cmd.ioc_loginfo); in mpi3mr_bsg_pel_abort()
904 retval = -1; in mpi3mr_bsg_pel_abort()
907 if (mrioc->pel_abort_cmd.state & MPI3MR_CMD_REPLY_VALID) { in mpi3mr_bsg_pel_abort()
908 pel_reply = (struct mpi3_pel_reply *)mrioc->pel_abort_cmd.reply; in mpi3mr_bsg_pel_abort()
909 pe_log_status = le16_to_cpu(pel_reply->pe_log_status); in mpi3mr_bsg_pel_abort()
914 retval = -1; in mpi3mr_bsg_pel_abort()
919 mrioc->pel_abort_cmd.state = MPI3MR_CMD_NOTUSED; in mpi3mr_bsg_pel_abort()
920 mutex_unlock(&mrioc->pel_abort_cmd.mutex); in mpi3mr_bsg_pel_abort()
924 * mpi3mr_bsg_verify_adapter - verify adapter number is valid
939 if (mrioc->id == ioc_number) { in mpi3mr_bsg_verify_adapter()
949 * mpi3mr_bsg_refresh_hdb_triggers - Refresh HDB trigger data
967 long rval = -EINVAL; in mpi3mr_bsg_refresh_hdb_triggers()
969 data_out_sz = job->request_payload.payload_len; in mpi3mr_bsg_refresh_hdb_triggers()
977 if (mrioc->unrecoverable) { in mpi3mr_bsg_refresh_hdb_triggers()
980 return -EFAULT; in mpi3mr_bsg_refresh_hdb_triggers()
982 if (mrioc->reset_in_progress) { in mpi3mr_bsg_refresh_hdb_triggers()
984 return -EAGAIN; in mpi3mr_bsg_refresh_hdb_triggers()
987 sg_copy_to_buffer(job->request_payload.sg_list, in mpi3mr_bsg_refresh_hdb_triggers()
988 job->request_payload.sg_cnt, in mpi3mr_bsg_refresh_hdb_triggers()
1013 * mpi3mr_bsg_upload_hdb - Upload a specific HDB to user space
1027 data_out_size = job->request_payload.payload_len; in mpi3mr_bsg_upload_hdb()
1028 data_in_size = job->reply_payload.payload_len; in mpi3mr_bsg_upload_hdb()
1033 return -EINVAL; in mpi3mr_bsg_upload_hdb()
1036 sg_copy_to_buffer(job->request_payload.sg_list, in mpi3mr_bsg_upload_hdb()
1037 job->request_payload.sg_cnt, in mpi3mr_bsg_upload_hdb()
1043 return -EINVAL; in mpi3mr_bsg_upload_hdb()
1046 if ((!diag_buffer) || (!diag_buffer->addr)) { in mpi3mr_bsg_upload_hdb()
1049 return -EINVAL; in mpi3mr_bsg_upload_hdb()
1052 if ((diag_buffer->status != MPI3MR_HDB_BUFSTATUS_RELEASED) && in mpi3mr_bsg_upload_hdb()
1053 (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_POSTED_PAUSED)) { in mpi3mr_bsg_upload_hdb()
1056 __func__, diag_buffer->status, upload_hdb.buf_type); in mpi3mr_bsg_upload_hdb()
1057 return -EINVAL; in mpi3mr_bsg_upload_hdb()
1060 if ((upload_hdb.start_offset + upload_hdb.length) > diag_buffer->size) { in mpi3mr_bsg_upload_hdb()
1065 return -EINVAL; in mpi3mr_bsg_upload_hdb()
1067 sg_copy_from_buffer(job->reply_payload.sg_list, in mpi3mr_bsg_upload_hdb()
1068 job->reply_payload.sg_cnt, in mpi3mr_bsg_upload_hdb()
1069 (diag_buffer->addr + upload_hdb.start_offset), in mpi3mr_bsg_upload_hdb()
1075 * mpi3mr_bsg_repost_hdb - Re-post HDB
1092 data_out_sz = job->request_payload.payload_len; in mpi3mr_bsg_repost_hdb()
1097 return -EINVAL; in mpi3mr_bsg_repost_hdb()
1099 if (mrioc->unrecoverable) { in mpi3mr_bsg_repost_hdb()
1102 return -EFAULT; in mpi3mr_bsg_repost_hdb()
1104 if (mrioc->reset_in_progress) { in mpi3mr_bsg_repost_hdb()
1106 return -EAGAIN; in mpi3mr_bsg_repost_hdb()
1109 sg_copy_to_buffer(job->request_payload.sg_list, in mpi3mr_bsg_repost_hdb()
1110 job->request_payload.sg_cnt, in mpi3mr_bsg_repost_hdb()
1114 if ((!diag_buffer) || (!diag_buffer->addr)) { in mpi3mr_bsg_repost_hdb()
1117 return -EINVAL; in mpi3mr_bsg_repost_hdb()
1120 if (diag_buffer->status != MPI3MR_HDB_BUFSTATUS_RELEASED) { in mpi3mr_bsg_repost_hdb()
1123 __func__, diag_buffer->status, repost_hdb.buf_type); in mpi3mr_bsg_repost_hdb()
1124 return -EINVAL; in mpi3mr_bsg_repost_hdb()
1130 return -EFAULT; in mpi3mr_bsg_repost_hdb()
1139 * mpi3mr_bsg_query_hdb - Handler for query HDB command
1159 data_in_sz = job->request_payload.payload_len; in mpi3mr_bsg_query_hdb()
1161 length = (sizeof(*hbd_status) + ((MPI3MR_MAX_NUM_HDB - 1) * in mpi3mr_bsg_query_hdb()
1165 return -ENOMEM; in mpi3mr_bsg_query_hdb()
1166 hbd_status_entry = &hbd_status->entry[0]; in mpi3mr_bsg_query_hdb()
1168 hbd_status->num_hdb_types = MPI3MR_MAX_NUM_HDB; in mpi3mr_bsg_query_hdb()
1170 diag_buffer = &mrioc->diag_buffers[i]; in mpi3mr_bsg_query_hdb()
1171 hbd_status_entry->buf_type = diag_buffer->type; in mpi3mr_bsg_query_hdb()
1172 hbd_status_entry->status = diag_buffer->status; in mpi3mr_bsg_query_hdb()
1173 hbd_status_entry->trigger_type = diag_buffer->trigger_type; in mpi3mr_bsg_query_hdb()
1174 memcpy(&hbd_status_entry->trigger_data, in mpi3mr_bsg_query_hdb()
1175 &diag_buffer->trigger_data, in mpi3mr_bsg_query_hdb()
1176 sizeof(hbd_status_entry->trigger_data)); in mpi3mr_bsg_query_hdb()
1177 hbd_status_entry->size = (diag_buffer->size / 1024); in mpi3mr_bsg_query_hdb()
1180 hbd_status->element_trigger_format = in mpi3mr_bsg_query_hdb()
1185 rval = -EINVAL; in mpi3mr_bsg_query_hdb()
1189 if (job->request_payload.payload_len >= min_length) { in mpi3mr_bsg_query_hdb()
1190 sg_copy_from_buffer(job->request_payload.sg_list, in mpi3mr_bsg_query_hdb()
1191 job->request_payload.sg_cnt, in mpi3mr_bsg_query_hdb()
1202 * mpi3mr_enable_logdata - Handler for log data enable
1217 if (!mrioc->logdata_buf) { in mpi3mr_enable_logdata()
1218 mrioc->logdata_entry_sz = in mpi3mr_enable_logdata()
1219 (mrioc->reply_sz - (sizeof(struct mpi3_event_notification_reply) - 4)) in mpi3mr_enable_logdata()
1221 mrioc->logdata_buf_idx = 0; in mpi3mr_enable_logdata()
1222 mrioc->logdata_buf = kcalloc(MPI3MR_BSG_LOGDATA_MAX_ENTRIES, in mpi3mr_enable_logdata()
1223 mrioc->logdata_entry_sz, GFP_KERNEL); in mpi3mr_enable_logdata()
1225 if (!mrioc->logdata_buf) in mpi3mr_enable_logdata()
1226 return -ENOMEM; in mpi3mr_enable_logdata()
1232 if (job->request_payload.payload_len >= sizeof(logdata_enable)) { in mpi3mr_enable_logdata()
1233 sg_copy_from_buffer(job->request_payload.sg_list, in mpi3mr_enable_logdata()
1234 job->request_payload.sg_cnt, in mpi3mr_enable_logdata()
1239 return -EINVAL; in mpi3mr_enable_logdata()
1242 * mpi3mr_get_logdata - Handler for get log data
1253 u16 num_entries, sz, entry_sz = mrioc->logdata_entry_sz; in mpi3mr_get_logdata()
1255 if ((!mrioc->logdata_buf) || (job->request_payload.payload_len < entry_sz)) in mpi3mr_get_logdata()
1256 return -EINVAL; in mpi3mr_get_logdata()
1258 num_entries = job->request_payload.payload_len / entry_sz; in mpi3mr_get_logdata()
1263 if (job->request_payload.payload_len >= sz) { in mpi3mr_get_logdata()
1264 sg_copy_from_buffer(job->request_payload.sg_list, in mpi3mr_get_logdata()
1265 job->request_payload.sg_cnt, in mpi3mr_get_logdata()
1266 mrioc->logdata_buf, sz); in mpi3mr_get_logdata()
1269 return -EINVAL; in mpi3mr_get_logdata()
1273 * mpi3mr_bsg_pel_enable - Handler for PEL enable driver
1287 long rval = -EINVAL; in mpi3mr_bsg_pel_enable()
1293 if (job->request_payload.payload_len != sizeof(pel_enable)) { in mpi3mr_bsg_pel_enable()
1299 if (mrioc->unrecoverable) { in mpi3mr_bsg_pel_enable()
1302 return -EFAULT; in mpi3mr_bsg_pel_enable()
1305 if (mrioc->reset_in_progress) { in mpi3mr_bsg_pel_enable()
1307 return -EAGAIN; in mpi3mr_bsg_pel_enable()
1310 if (mrioc->stop_bsgs) { in mpi3mr_bsg_pel_enable()
1312 return -EAGAIN; in mpi3mr_bsg_pel_enable()
1315 sg_copy_to_buffer(job->request_payload.sg_list, in mpi3mr_bsg_pel_enable()
1316 job->request_payload.sg_cnt, in mpi3mr_bsg_pel_enable()
1325 if (!mrioc->pel_enabled) in mpi3mr_bsg_pel_enable()
1328 if ((mrioc->pel_class <= pel_enable.pel_class) && in mpi3mr_bsg_pel_enable()
1329 !((mrioc->pel_locale & pel_enable.pel_locale) ^ in mpi3mr_bsg_pel_enable()
1334 pel_enable.pel_locale |= mrioc->pel_locale; in mpi3mr_bsg_pel_enable()
1336 if (mrioc->pel_class < pel_enable.pel_class) in mpi3mr_bsg_pel_enable()
1337 pel_enable.pel_class = mrioc->pel_class; in mpi3mr_bsg_pel_enable()
1350 tmp_class = mrioc->pel_class; in mpi3mr_bsg_pel_enable()
1351 tmp_locale = mrioc->pel_locale; in mpi3mr_bsg_pel_enable()
1352 mrioc->pel_class = pel_enable.pel_class; in mpi3mr_bsg_pel_enable()
1353 mrioc->pel_locale = pel_enable.pel_locale; in mpi3mr_bsg_pel_enable()
1354 mrioc->pel_enabled = 1; in mpi3mr_bsg_pel_enable()
1357 mrioc->pel_class = tmp_class; in mpi3mr_bsg_pel_enable()
1358 mrioc->pel_locale = tmp_locale; in mpi3mr_bsg_pel_enable()
1359 mrioc->pel_enabled = 0; in mpi3mr_bsg_pel_enable()
1370 * mpi3mr_get_all_tgt_info - Get all target information
1392 if (job->request_payload.payload_len < sizeof(u32)) { in mpi3mr_get_all_tgt_info()
1395 return -EINVAL; in mpi3mr_get_all_tgt_info()
1398 spin_lock_irqsave(&mrioc->tgtdev_lock, flags); in mpi3mr_get_all_tgt_info()
1399 list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list) in mpi3mr_get_all_tgt_info()
1401 spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags); in mpi3mr_get_all_tgt_info()
1403 if ((job->request_payload.payload_len <= sizeof(u64)) || in mpi3mr_get_all_tgt_info()
1404 list_empty(&mrioc->tgtdev_list)) { in mpi3mr_get_all_tgt_info()
1405 sg_copy_from_buffer(job->request_payload.sg_list, in mpi3mr_get_all_tgt_info()
1406 job->request_payload.sg_cnt, in mpi3mr_get_all_tgt_info()
1415 return -ENOMEM; in mpi3mr_get_all_tgt_info()
1417 devmap_info = alltgt_info->dmi; in mpi3mr_get_all_tgt_info()
1419 spin_lock_irqsave(&mrioc->tgtdev_lock, flags); in mpi3mr_get_all_tgt_info()
1420 list_for_each_entry(tgtdev, &mrioc->tgtdev_list, list) { in mpi3mr_get_all_tgt_info()
1422 devmap_info[i].handle = tgtdev->dev_handle; in mpi3mr_get_all_tgt_info()
1423 devmap_info[i].perst_id = tgtdev->perst_id; in mpi3mr_get_all_tgt_info()
1424 if (tgtdev->host_exposed && tgtdev->starget) { in mpi3mr_get_all_tgt_info()
1425 devmap_info[i].target_id = tgtdev->starget->id; in mpi3mr_get_all_tgt_info()
1427 tgtdev->starget->channel; in mpi3mr_get_all_tgt_info()
1433 spin_unlock_irqrestore(&mrioc->tgtdev_lock, flags); in mpi3mr_get_all_tgt_info()
1435 alltgt_info->num_devices = num_devices; in mpi3mr_get_all_tgt_info()
1437 usr_entrylen = (job->request_payload.payload_len - sizeof(u64)) / in mpi3mr_get_all_tgt_info()
1442 sg_copy_from_buffer(job->request_payload.sg_list, in mpi3mr_get_all_tgt_info()
1443 job->request_payload.sg_cnt, in mpi3mr_get_all_tgt_info()
1449 * mpi3mr_get_change_count - Get topology change count
1465 chgcnt.change_count = mrioc->change_count; in mpi3mr_get_change_count()
1466 if (job->request_payload.payload_len >= sizeof(chgcnt)) { in mpi3mr_get_change_count()
1467 sg_copy_from_buffer(job->request_payload.sg_list, in mpi3mr_get_change_count()
1468 job->request_payload.sg_cnt, in mpi3mr_get_change_count()
1472 return -EINVAL; in mpi3mr_get_change_count()
1476 * mpi3mr_bsg_adp_reset - Issue controller reset
1489 long rval = -EINVAL; in mpi3mr_bsg_adp_reset()
1493 if (job->request_payload.payload_len != in mpi3mr_bsg_adp_reset()
1500 if (mrioc->unrecoverable || mrioc->block_on_pci_err) in mpi3mr_bsg_adp_reset()
1501 return -EINVAL; in mpi3mr_bsg_adp_reset()
1503 sg_copy_to_buffer(job->request_payload.sg_list, in mpi3mr_bsg_adp_reset()
1504 job->request_payload.sg_cnt, in mpi3mr_bsg_adp_reset()
1532 * mpi3mr_bsg_populate_adpinfo - Get adapter info command handler
1549 adpinfo.pci_dev_id = mrioc->pdev->device; in mpi3mr_bsg_populate_adpinfo()
1550 adpinfo.pci_dev_hw_rev = mrioc->pdev->revision; in mpi3mr_bsg_populate_adpinfo()
1551 adpinfo.pci_subsys_dev_id = mrioc->pdev->subsystem_device; in mpi3mr_bsg_populate_adpinfo()
1552 adpinfo.pci_subsys_ven_id = mrioc->pdev->subsystem_vendor; in mpi3mr_bsg_populate_adpinfo()
1553 adpinfo.pci_bus = mrioc->pdev->bus->number; in mpi3mr_bsg_populate_adpinfo()
1554 adpinfo.pci_dev = PCI_SLOT(mrioc->pdev->devfn); in mpi3mr_bsg_populate_adpinfo()
1555 adpinfo.pci_func = PCI_FUNC(mrioc->pdev->devfn); in mpi3mr_bsg_populate_adpinfo()
1556 adpinfo.pci_seg_id = pci_domain_nr(mrioc->pdev->bus); in mpi3mr_bsg_populate_adpinfo()
1562 else if ((mrioc->reset_in_progress) || (mrioc->stop_bsgs)) in mpi3mr_bsg_populate_adpinfo()
1569 memcpy((u8 *)&adpinfo.driver_info, (u8 *)&mrioc->driver_info, in mpi3mr_bsg_populate_adpinfo()
1572 if (job->request_payload.payload_len >= sizeof(adpinfo)) { in mpi3mr_bsg_populate_adpinfo()
1573 sg_copy_from_buffer(job->request_payload.sg_list, in mpi3mr_bsg_populate_adpinfo()
1574 job->request_payload.sg_cnt, in mpi3mr_bsg_populate_adpinfo()
1578 return -EINVAL; in mpi3mr_bsg_populate_adpinfo()
1582 * mpi3mr_bsg_process_drv_cmds - Driver Command handler
1593 long rval = -EINVAL; in mpi3mr_bsg_process_drv_cmds()
1598 bsg_req = job->request; in mpi3mr_bsg_process_drv_cmds()
1599 drvrcmd = &bsg_req->cmd.drvrcmd; in mpi3mr_bsg_process_drv_cmds()
1601 mrioc = mpi3mr_bsg_verify_adapter(drvrcmd->mrioc_id); in mpi3mr_bsg_process_drv_cmds()
1603 return -ENODEV; in mpi3mr_bsg_process_drv_cmds()
1605 if (drvrcmd->opcode == MPI3MR_DRVBSG_OPCODE_ADPINFO) { in mpi3mr_bsg_process_drv_cmds()
1610 if (mutex_lock_interruptible(&mrioc->bsg_cmds.mutex)) in mpi3mr_bsg_process_drv_cmds()
1611 return -ERESTARTSYS; in mpi3mr_bsg_process_drv_cmds()
1613 switch (drvrcmd->opcode) { in mpi3mr_bsg_process_drv_cmds()
1647 MPI3MR_DRIVER_NAME, drvrcmd->opcode); in mpi3mr_bsg_process_drv_cmds()
1650 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_drv_cmds()
1655 * mpi3mr_total_num_ioctl_sges - Count number of SGEs required
1672 if (drv_bufs->data_dir == DMA_NONE || in mpi3mr_total_num_ioctl_sges()
1673 drv_bufs->kern_buf) in mpi3mr_total_num_ioctl_sges()
1675 sge_count += drv_bufs->num_dma_desc; in mpi3mr_total_num_ioctl_sges()
1676 if (!drv_bufs->num_dma_desc) in mpi3mr_total_num_ioctl_sges()
1683 * mpi3mr_bsg_build_sgl - SGL construction for MPI commands
1696 * Return: 0 on success,-1 on failure
1723 mpi3mr_add_sg_single(&rmgmt_req->command_sgl, in mpi3mr_bsg_build_sgl()
1724 sgl_flags_last, drv_buf_iter->kern_buf_len, in mpi3mr_bsg_build_sgl()
1725 drv_buf_iter->kern_buf_dma); in mpi3mr_bsg_build_sgl()
1726 sgl = (u8 *)drv_buf_iter->kern_buf + in mpi3mr_bsg_build_sgl()
1727 drv_buf_iter->bsg_buf_len; in mpi3mr_bsg_build_sgl()
1728 available_sges = (drv_buf_iter->kern_buf_len - in mpi3mr_bsg_build_sgl()
1729 drv_buf_iter->bsg_buf_len) / sge_element_size; in mpi3mr_bsg_build_sgl()
1732 return -1; in mpi3mr_bsg_build_sgl()
1738 mpi3mr_add_sg_single(&rmgmt_req->response_sgl, in mpi3mr_bsg_build_sgl()
1739 sgl_flags_last, drv_buf_iter->kern_buf_len, in mpi3mr_bsg_build_sgl()
1740 drv_buf_iter->kern_buf_dma); in mpi3mr_bsg_build_sgl()
1745 &rmgmt_req->response_sgl); in mpi3mr_bsg_build_sgl()
1752 return -1; in mpi3mr_bsg_build_sgl()
1753 available_sges = (MPI3MR_ADMIN_REQ_FRAME_SZ - sgl_offset) / in mpi3mr_bsg_build_sgl()
1756 return -1; in mpi3mr_bsg_build_sgl()
1762 if (mpi_header->function == MPI3_BSG_FUNCTION_SMP_PASSTHROUGH) { in mpi3mr_bsg_build_sgl()
1764 return -1; in mpi3mr_bsg_build_sgl()
1766 if (drv_buf_iter->data_dir == DMA_NONE || in mpi3mr_bsg_build_sgl()
1767 !drv_buf_iter->num_dma_desc) in mpi3mr_bsg_build_sgl()
1770 drv_buf_iter->dma_desc[0].size, in mpi3mr_bsg_build_sgl()
1771 drv_buf_iter->dma_desc[0].dma_addr); in mpi3mr_bsg_build_sgl()
1780 if (drv_buf_iter->data_dir == DMA_NONE) in mpi3mr_bsg_build_sgl()
1782 if (!drv_buf_iter->num_dma_desc) { in mpi3mr_bsg_build_sgl()
1784 return -1; in mpi3mr_bsg_build_sgl()
1793 sges_needed--; in mpi3mr_bsg_build_sgl()
1794 available_sges--; in mpi3mr_bsg_build_sgl()
1795 num_datasges--; in mpi3mr_bsg_build_sgl()
1798 for (; i < drv_buf_iter->num_dma_desc; i++) { in mpi3mr_bsg_build_sgl()
1800 return -1; in mpi3mr_bsg_build_sgl()
1805 if (i == (drv_buf_iter->num_dma_desc - 1)) { in mpi3mr_bsg_build_sgl()
1813 drv_buf_iter->dma_desc[i].size, in mpi3mr_bsg_build_sgl()
1814 drv_buf_iter->dma_desc[i].dma_addr); in mpi3mr_bsg_build_sgl()
1816 available_sges--; in mpi3mr_bsg_build_sgl()
1817 sges_needed--; in mpi3mr_bsg_build_sgl()
1819 num_datasges--; in mpi3mr_bsg_build_sgl()
1825 available_sges = mrioc->ioctl_chain_sge.size / sge_element_size; in mpi3mr_bsg_build_sgl()
1827 return -1; in mpi3mr_bsg_build_sgl()
1830 mrioc->ioctl_chain_sge.dma_addr); in mpi3mr_bsg_build_sgl()
1831 memset(mrioc->ioctl_chain_sge.addr, 0, mrioc->ioctl_chain_sge.size); in mpi3mr_bsg_build_sgl()
1832 sgl = (u8 *)mrioc->ioctl_chain_sge.addr; in mpi3mr_bsg_build_sgl()
1838 * mpi3mr_get_nvme_data_fmt - returns the NVMe data format
1851 format = ((nvme_encap_request->command[0] & 0xc000) >> 14); in mpi3mr_get_nvme_data_fmt()
1857 * mpi3mr_build_nvme_sgl - SGL constructor for NVME
1867 * Return: 0 on success, -1 on failure
1880 u64 sgemod_mask = ((u64)((mrioc->facts.sge_mod_mask) << in mpi3mr_build_nvme_sgl()
1881 mrioc->facts.sge_mod_shift) << 32); in mpi3mr_build_nvme_sgl()
1882 u64 sgemod_val = ((u64)(mrioc->facts.sge_mod_value) << in mpi3mr_build_nvme_sgl()
1883 mrioc->facts.sge_mod_shift) << 32; in mpi3mr_build_nvme_sgl()
1887 ((u8 *)(nvme_encap_request->command) + MPI3MR_NVME_CMD_SGL_OFFSET); in mpi3mr_build_nvme_sgl()
1894 if (drv_buf_iter->data_dir == DMA_NONE) in mpi3mr_build_nvme_sgl()
1896 length = drv_buf_iter->kern_buf_len; in mpi3mr_build_nvme_sgl()
1899 if (!length || !drv_buf_iter->num_dma_desc) in mpi3mr_build_nvme_sgl()
1902 if (drv_buf_iter->num_dma_desc == 1) { in mpi3mr_build_nvme_sgl()
1907 sgl_dma = cpu_to_le64(mrioc->ioctl_chain_sge.dma_addr); in mpi3mr_build_nvme_sgl()
1912 return -1; in mpi3mr_build_nvme_sgl()
1918 memset(mrioc->ioctl_chain_sge.addr, 0, mrioc->ioctl_chain_sge.size); in mpi3mr_build_nvme_sgl()
1919 available_sges = mrioc->ioctl_chain_sge.size / sge_element_size; in mpi3mr_build_nvme_sgl()
1920 if (available_sges < drv_buf_iter->num_dma_desc) in mpi3mr_build_nvme_sgl()
1921 return -1; in mpi3mr_build_nvme_sgl()
1923 nvme_sgl->base_addr = sgl_dma; in mpi3mr_build_nvme_sgl()
1924 size = drv_buf_iter->num_dma_desc * sizeof(struct mpi3mr_nvme_pt_sge); in mpi3mr_build_nvme_sgl()
1925 nvme_sgl->length = cpu_to_le32(size); in mpi3mr_build_nvme_sgl()
1926 nvme_sgl->type = MPI3MR_NVMESGL_LAST_SEGMENT; in mpi3mr_build_nvme_sgl()
1927 nvme_sgl = (struct mpi3mr_nvme_pt_sge *)mrioc->ioctl_chain_sge.addr; in mpi3mr_build_nvme_sgl()
1930 for (i = 0; i < drv_buf_iter->num_dma_desc; i++) { in mpi3mr_build_nvme_sgl()
1931 sgl_dma = cpu_to_le64(drv_buf_iter->dma_desc[i].dma_addr); in mpi3mr_build_nvme_sgl()
1936 return -1; in mpi3mr_build_nvme_sgl()
1942 nvme_sgl->base_addr = sgl_dma; in mpi3mr_build_nvme_sgl()
1943 nvme_sgl->length = cpu_to_le32(drv_buf_iter->dma_desc[i].size); in mpi3mr_build_nvme_sgl()
1944 nvme_sgl->type = MPI3MR_NVMESGL_DATA_SEGMENT; in mpi3mr_build_nvme_sgl()
1946 available_sges--; in mpi3mr_build_nvme_sgl()
1953 * mpi3mr_build_nvme_prp - PRP constructor for NVME
1964 * Return: 0 on success, -1 on failure
1979 u64 sgemod_mask = ((u64)((mrioc->facts.sge_mod_mask) << in mpi3mr_build_nvme_prp()
1980 mrioc->facts.sge_mod_shift) << 32); in mpi3mr_build_nvme_prp()
1981 u64 sgemod_val = ((u64)(mrioc->facts.sge_mod_value) << in mpi3mr_build_nvme_prp()
1982 mrioc->facts.sge_mod_shift) << 32; in mpi3mr_build_nvme_prp()
1983 u16 dev_handle = nvme_encap_request->dev_handle; in mpi3mr_build_nvme_prp()
1991 return -1; in mpi3mr_build_nvme_prp()
1994 if (tgtdev->dev_spec.pcie_inf.pgsz == 0) { in mpi3mr_build_nvme_prp()
1999 return -1; in mpi3mr_build_nvme_prp()
2002 dev_pgsz = 1 << (tgtdev->dev_spec.pcie_inf.pgsz); in mpi3mr_build_nvme_prp()
2004 page_mask = dev_pgsz - 1; in mpi3mr_build_nvme_prp()
2010 return -1; in mpi3mr_build_nvme_prp()
2017 return -1; in mpi3mr_build_nvme_prp()
2025 if (drv_buf_iter->data_dir == DMA_NONE) in mpi3mr_build_nvme_prp()
2027 length = drv_buf_iter->kern_buf_len; in mpi3mr_build_nvme_prp()
2031 if (!length || !drv_buf_iter->num_dma_desc) in mpi3mr_build_nvme_prp()
2034 for (count = 0; count < drv_buf_iter->num_dma_desc; count++) { in mpi3mr_build_nvme_prp()
2035 dma_addr = drv_buf_iter->dma_desc[count].dma_addr; in mpi3mr_build_nvme_prp()
2040 return -1; in mpi3mr_build_nvme_prp()
2044 dma_addr = drv_buf_iter->dma_desc[0].dma_addr; in mpi3mr_build_nvme_prp()
2045 desc_len = drv_buf_iter->dma_desc[0].size; in mpi3mr_build_nvme_prp()
2047 mrioc->prp_sz = 0; in mpi3mr_build_nvme_prp()
2048 mrioc->prp_list_virt = dma_alloc_coherent(&mrioc->pdev->dev, in mpi3mr_build_nvme_prp()
2049 dev_pgsz, &mrioc->prp_list_dma, GFP_KERNEL); in mpi3mr_build_nvme_prp()
2051 if (!mrioc->prp_list_virt) in mpi3mr_build_nvme_prp()
2052 return -1; in mpi3mr_build_nvme_prp()
2053 mrioc->prp_sz = dev_pgsz; in mpi3mr_build_nvme_prp()
2060 prp1_entry = (__le64 *)((u8 *)(nvme_encap_request->command) + in mpi3mr_build_nvme_prp()
2062 prp2_entry = (__le64 *)((u8 *)(nvme_encap_request->command) + in mpi3mr_build_nvme_prp()
2069 prp_page = (__le64 *)mrioc->prp_list_virt; in mpi3mr_build_nvme_prp()
2070 prp_page_dma = mrioc->prp_list_dma; in mpi3mr_build_nvme_prp()
2102 entry_len = dev_pgsz - offset; in mpi3mr_build_nvme_prp()
2195 desc_len -= entry_len; in mpi3mr_build_nvme_prp()
2199 drv_buf_iter->num_dma_desc) { in mpi3mr_build_nvme_prp()
2206 drv_buf_iter->dma_desc[desc_count].dma_addr; in mpi3mr_build_nvme_prp()
2208 drv_buf_iter->dma_desc[desc_count].size; in mpi3mr_build_nvme_prp()
2210 length -= entry_len; in mpi3mr_build_nvme_prp()
2216 if (mrioc->prp_list_virt) { in mpi3mr_build_nvme_prp()
2217 dma_free_coherent(&mrioc->pdev->dev, mrioc->prp_sz, in mpi3mr_build_nvme_prp()
2218 mrioc->prp_list_virt, mrioc->prp_list_dma); in mpi3mr_build_nvme_prp()
2219 mrioc->prp_list_virt = NULL; in mpi3mr_build_nvme_prp()
2221 return -1; in mpi3mr_build_nvme_prp()
2225 * mpi3mr_map_data_buffer_dma - build dma descriptors for data
2231 * This function computes how many pre-allocated DMA descriptors
2238 * Return: 0 on success, -1 on failure
2244 u16 i, needed_desc = drv_buf->kern_buf_len / MPI3MR_IOCTL_SGE_SIZE; in mpi3mr_map_data_buffer_dma()
2245 u32 buf_len = drv_buf->kern_buf_len, copied_len = 0; in mpi3mr_map_data_buffer_dma()
2247 if (drv_buf->kern_buf_len % MPI3MR_IOCTL_SGE_SIZE) in mpi3mr_map_data_buffer_dma()
2252 return -1; in mpi3mr_map_data_buffer_dma()
2254 drv_buf->dma_desc = kzalloc(sizeof(*drv_buf->dma_desc) * needed_desc, in mpi3mr_map_data_buffer_dma()
2256 if (!drv_buf->dma_desc) in mpi3mr_map_data_buffer_dma()
2257 return -1; in mpi3mr_map_data_buffer_dma()
2259 drv_buf->dma_desc[i].addr = mrioc->ioctl_sge[desc_count].addr; in mpi3mr_map_data_buffer_dma()
2260 drv_buf->dma_desc[i].dma_addr = in mpi3mr_map_data_buffer_dma()
2261 mrioc->ioctl_sge[desc_count].dma_addr; in mpi3mr_map_data_buffer_dma()
2262 if (buf_len < mrioc->ioctl_sge[desc_count].size) in mpi3mr_map_data_buffer_dma()
2263 drv_buf->dma_desc[i].size = buf_len; in mpi3mr_map_data_buffer_dma()
2265 drv_buf->dma_desc[i].size = in mpi3mr_map_data_buffer_dma()
2266 mrioc->ioctl_sge[desc_count].size; in mpi3mr_map_data_buffer_dma()
2267 buf_len -= drv_buf->dma_desc[i].size; in mpi3mr_map_data_buffer_dma()
2268 memset(drv_buf->dma_desc[i].addr, 0, in mpi3mr_map_data_buffer_dma()
2269 mrioc->ioctl_sge[desc_count].size); in mpi3mr_map_data_buffer_dma()
2270 if (drv_buf->data_dir == DMA_TO_DEVICE) { in mpi3mr_map_data_buffer_dma()
2271 memcpy(drv_buf->dma_desc[i].addr, in mpi3mr_map_data_buffer_dma()
2272 drv_buf->bsg_buf + copied_len, in mpi3mr_map_data_buffer_dma()
2273 drv_buf->dma_desc[i].size); in mpi3mr_map_data_buffer_dma()
2274 copied_len += drv_buf->dma_desc[i].size; in mpi3mr_map_data_buffer_dma()
2277 drv_buf->num_dma_desc = needed_desc; in mpi3mr_map_data_buffer_dma()
2281 * mpi3mr_bsg_process_mpt_cmds - MPI Pass through BSG handler
2300 long rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2325 bsg_req = job->request; in mpi3mr_bsg_process_mpt_cmds()
2326 karg = (struct mpi3mr_bsg_mptcmd *)&bsg_req->cmd.mptcmd; in mpi3mr_bsg_process_mpt_cmds()
2328 mrioc = mpi3mr_bsg_verify_adapter(karg->mrioc_id); in mpi3mr_bsg_process_mpt_cmds()
2330 return -ENODEV; in mpi3mr_bsg_process_mpt_cmds()
2332 if (mutex_lock_interruptible(&mrioc->bsg_cmds.mutex)) in mpi3mr_bsg_process_mpt_cmds()
2333 return -ERESTARTSYS; in mpi3mr_bsg_process_mpt_cmds()
2335 if (mrioc->bsg_cmds.state & MPI3MR_CMD_PENDING) { in mpi3mr_bsg_process_mpt_cmds()
2337 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2338 return -EAGAIN; in mpi3mr_bsg_process_mpt_cmds()
2341 if (!mrioc->ioctl_sges_allocated) { in mpi3mr_bsg_process_mpt_cmds()
2344 return -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2347 if (karg->timeout < MPI3MR_APP_DEFAULT_TIMEOUT) in mpi3mr_bsg_process_mpt_cmds()
2348 karg->timeout = MPI3MR_APP_DEFAULT_TIMEOUT; in mpi3mr_bsg_process_mpt_cmds()
2352 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2353 return -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2357 bufcnt = karg->buf_entry_list.num_of_entries; in mpi3mr_bsg_process_mpt_cmds()
2360 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2361 rval = -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2365 dout_buf = kzalloc(job->request_payload.payload_len, in mpi3mr_bsg_process_mpt_cmds()
2368 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2369 rval = -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2373 din_buf = kzalloc(job->reply_payload.payload_len, in mpi3mr_bsg_process_mpt_cmds()
2376 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2377 rval = -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2381 sg_copy_to_buffer(job->request_payload.sg_list, in mpi3mr_bsg_process_mpt_cmds()
2382 job->request_payload.sg_cnt, in mpi3mr_bsg_process_mpt_cmds()
2383 dout_buf, job->request_payload.payload_len); in mpi3mr_bsg_process_mpt_cmds()
2385 buf_entries = karg->buf_entry_list.buf_entry; in mpi3mr_bsg_process_mpt_cmds()
2392 switch (buf_entries->buf_type) { in mpi3mr_bsg_process_mpt_cmds()
2395 sgl_dout_iter += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2396 drv_buf_iter->data_dir = DMA_TO_DEVICE; in mpi3mr_bsg_process_mpt_cmds()
2398 if ((count != 0) || !buf_entries->buf_len) in mpi3mr_bsg_process_mpt_cmds()
2403 sgl_din_iter += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2404 drv_buf_iter->data_dir = DMA_FROM_DEVICE; in mpi3mr_bsg_process_mpt_cmds()
2406 if (count != 1 || !is_rmcb || !buf_entries->buf_len) in mpi3mr_bsg_process_mpt_cmds()
2411 sgl_din_iter += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2412 drv_buf_iter->data_dir = DMA_FROM_DEVICE; in mpi3mr_bsg_process_mpt_cmds()
2414 din_size += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2420 sgl_dout_iter += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2421 drv_buf_iter->data_dir = DMA_TO_DEVICE; in mpi3mr_bsg_process_mpt_cmds()
2423 dout_size += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2429 sgl_din_iter += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2430 drv_buf_iter->data_dir = DMA_NONE; in mpi3mr_bsg_process_mpt_cmds()
2432 if (!buf_entries->buf_len) in mpi3mr_bsg_process_mpt_cmds()
2437 sgl_din_iter += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2438 drv_buf_iter->data_dir = DMA_NONE; in mpi3mr_bsg_process_mpt_cmds()
2440 if (!buf_entries->buf_len) in mpi3mr_bsg_process_mpt_cmds()
2445 sgl_dout_iter += buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2446 drv_buf_iter->data_dir = DMA_NONE; in mpi3mr_bsg_process_mpt_cmds()
2447 mpi_msg_size = buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2452 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2453 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2456 memcpy(mpi_req, sgl_iter, buf_entries->buf_len); in mpi3mr_bsg_process_mpt_cmds()
2465 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2466 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2470 if (sgl_dout_iter > (dout_buf + job->request_payload.payload_len)) { in mpi3mr_bsg_process_mpt_cmds()
2473 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2474 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2477 if (sgl_din_iter > (din_buf + job->reply_payload.payload_len)) { in mpi3mr_bsg_process_mpt_cmds()
2480 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2481 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2485 drv_buf_iter->bsg_buf = sgl_iter; in mpi3mr_bsg_process_mpt_cmds()
2486 drv_buf_iter->bsg_buf_len = buf_entries->buf_len; in mpi3mr_bsg_process_mpt_cmds()
2491 __func__, __LINE__, mpi_header->function, din_size, in mpi3mr_bsg_process_mpt_cmds()
2493 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2494 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2501 __func__, __LINE__, mpi_header->function, din_size); in mpi3mr_bsg_process_mpt_cmds()
2502 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2503 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2509 __func__, __LINE__, mpi_header->function, dout_size); in mpi3mr_bsg_process_mpt_cmds()
2510 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2511 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2515 if (mpi_header->function == MPI3_BSG_FUNCTION_SMP_PASSTHROUGH) { in mpi3mr_bsg_process_mpt_cmds()
2521 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2522 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2529 if (drv_buf_iter->data_dir == DMA_NONE) in mpi3mr_bsg_process_mpt_cmds()
2532 drv_buf_iter->kern_buf_len = drv_buf_iter->bsg_buf_len; in mpi3mr_bsg_process_mpt_cmds()
2534 drv_buf_iter->kern_buf_len = in mpi3mr_bsg_process_mpt_cmds()
2535 mrioc->ioctl_chain_sge.size; in mpi3mr_bsg_process_mpt_cmds()
2536 drv_buf_iter->kern_buf = in mpi3mr_bsg_process_mpt_cmds()
2537 mrioc->ioctl_chain_sge.addr; in mpi3mr_bsg_process_mpt_cmds()
2538 drv_buf_iter->kern_buf_dma = in mpi3mr_bsg_process_mpt_cmds()
2539 mrioc->ioctl_chain_sge.dma_addr; in mpi3mr_bsg_process_mpt_cmds()
2540 drv_buf_iter->dma_desc = NULL; in mpi3mr_bsg_process_mpt_cmds()
2541 drv_buf_iter->num_dma_desc = 0; in mpi3mr_bsg_process_mpt_cmds()
2542 memset(drv_buf_iter->kern_buf, 0, in mpi3mr_bsg_process_mpt_cmds()
2543 drv_buf_iter->kern_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2544 tmplen = min(drv_buf_iter->kern_buf_len, in mpi3mr_bsg_process_mpt_cmds()
2545 drv_buf_iter->bsg_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2547 memcpy(drv_buf_iter->kern_buf, drv_buf_iter->bsg_buf, tmplen); in mpi3mr_bsg_process_mpt_cmds()
2549 drv_buf_iter->kern_buf_len = in mpi3mr_bsg_process_mpt_cmds()
2550 mrioc->ioctl_resp_sge.size; in mpi3mr_bsg_process_mpt_cmds()
2551 drv_buf_iter->kern_buf = in mpi3mr_bsg_process_mpt_cmds()
2552 mrioc->ioctl_resp_sge.addr; in mpi3mr_bsg_process_mpt_cmds()
2553 drv_buf_iter->kern_buf_dma = in mpi3mr_bsg_process_mpt_cmds()
2554 mrioc->ioctl_resp_sge.dma_addr; in mpi3mr_bsg_process_mpt_cmds()
2555 drv_buf_iter->dma_desc = NULL; in mpi3mr_bsg_process_mpt_cmds()
2556 drv_buf_iter->num_dma_desc = 0; in mpi3mr_bsg_process_mpt_cmds()
2557 memset(drv_buf_iter->kern_buf, 0, in mpi3mr_bsg_process_mpt_cmds()
2558 drv_buf_iter->kern_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2559 tmplen = min(drv_buf_iter->kern_buf_len, in mpi3mr_bsg_process_mpt_cmds()
2560 drv_buf_iter->bsg_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2561 drv_buf_iter->kern_buf_len = tmplen; in mpi3mr_bsg_process_mpt_cmds()
2562 memset(drv_buf_iter->bsg_buf, 0, in mpi3mr_bsg_process_mpt_cmds()
2563 drv_buf_iter->bsg_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2565 if (!drv_buf_iter->kern_buf_len) in mpi3mr_bsg_process_mpt_cmds()
2568 rval = -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2569 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2574 desc_count += drv_buf_iter->num_dma_desc; in mpi3mr_bsg_process_mpt_cmds()
2581 rval = -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2582 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2587 if (mrioc->unrecoverable) { in mpi3mr_bsg_process_mpt_cmds()
2590 rval = -EFAULT; in mpi3mr_bsg_process_mpt_cmds()
2591 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2594 if (mrioc->reset_in_progress) { in mpi3mr_bsg_process_mpt_cmds()
2596 rval = -EAGAIN; in mpi3mr_bsg_process_mpt_cmds()
2597 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2600 if (mrioc->stop_bsgs || mrioc->block_on_pci_err) { in mpi3mr_bsg_process_mpt_cmds()
2602 rval = -EAGAIN; in mpi3mr_bsg_process_mpt_cmds()
2603 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2607 if (mpi_header->function == MPI3_BSG_FUNCTION_NVME_ENCAPSULATED) { in mpi3mr_bsg_process_mpt_cmds()
2614 rval = -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2615 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2623 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2624 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2630 rval = -EINVAL; in mpi3mr_bsg_process_mpt_cmds()
2631 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2639 rval = -EAGAIN; in mpi3mr_bsg_process_mpt_cmds()
2640 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2645 if (mpi_header->function == MPI3_BSG_FUNCTION_SCSI_TASK_MGMT) { in mpi3mr_bsg_process_mpt_cmds()
2647 if (tm_req->task_type != in mpi3mr_bsg_process_mpt_cmds()
2649 dev_handle = tm_req->dev_handle; in mpi3mr_bsg_process_mpt_cmds()
2655 if (tgtdev && tgtdev->starget && tgtdev->starget->hostdata) { in mpi3mr_bsg_process_mpt_cmds()
2657 tgtdev->starget->hostdata; in mpi3mr_bsg_process_mpt_cmds()
2658 atomic_inc(&stgt_priv->block_io); in mpi3mr_bsg_process_mpt_cmds()
2663 mrioc->bsg_cmds.state = MPI3MR_CMD_PENDING; in mpi3mr_bsg_process_mpt_cmds()
2664 mrioc->bsg_cmds.is_waiting = 1; in mpi3mr_bsg_process_mpt_cmds()
2665 mrioc->bsg_cmds.callback = NULL; in mpi3mr_bsg_process_mpt_cmds()
2666 mrioc->bsg_cmds.is_sense = 0; in mpi3mr_bsg_process_mpt_cmds()
2667 mrioc->bsg_cmds.sensebuf = sense_buff_k; in mpi3mr_bsg_process_mpt_cmds()
2668 memset(mrioc->bsg_cmds.reply, 0, mrioc->reply_sz); in mpi3mr_bsg_process_mpt_cmds()
2669 mpi_header->host_tag = cpu_to_le16(MPI3MR_HOSTTAG_BSG_CMDS); in mpi3mr_bsg_process_mpt_cmds()
2670 if (mrioc->logging_level & MPI3_DEBUG_BSG_INFO) { in mpi3mr_bsg_process_mpt_cmds()
2675 if (mpi_header->function == MPI3_BSG_FUNCTION_MGMT_PASSTHROUGH) { in mpi3mr_bsg_process_mpt_cmds()
2677 dprint_dump(drv_buf_iter->kern_buf, in mpi3mr_bsg_process_mpt_cmds()
2682 init_completion(&mrioc->bsg_cmds.done); in mpi3mr_bsg_process_mpt_cmds()
2688 mrioc->bsg_cmds.is_waiting = 0; in mpi3mr_bsg_process_mpt_cmds()
2691 rval = -EAGAIN; in mpi3mr_bsg_process_mpt_cmds()
2694 wait_for_completion_timeout(&mrioc->bsg_cmds.done, in mpi3mr_bsg_process_mpt_cmds()
2695 (karg->timeout * HZ)); in mpi3mr_bsg_process_mpt_cmds()
2697 atomic_dec(&stgt_priv->block_io); in mpi3mr_bsg_process_mpt_cmds()
2698 if (!(mrioc->bsg_cmds.state & MPI3MR_CMD_COMPLETE)) { in mpi3mr_bsg_process_mpt_cmds()
2699 mrioc->bsg_cmds.is_waiting = 0; in mpi3mr_bsg_process_mpt_cmds()
2700 rval = -EAGAIN; in mpi3mr_bsg_process_mpt_cmds()
2701 if (mrioc->bsg_cmds.state & MPI3MR_CMD_RESET) in mpi3mr_bsg_process_mpt_cmds()
2703 if (((mpi_header->function != MPI3_FUNCTION_SCSI_IO) && in mpi3mr_bsg_process_mpt_cmds()
2704 (mpi_header->function != MPI3_FUNCTION_NVME_ENCAPSULATED)) in mpi3mr_bsg_process_mpt_cmds()
2705 || (mrioc->logging_level & MPI3_DEBUG_BSG_ERROR)) { in mpi3mr_bsg_process_mpt_cmds()
2707 __func__, karg->timeout); in mpi3mr_bsg_process_mpt_cmds()
2708 if (!(mrioc->logging_level & MPI3_DEBUG_BSG_INFO)) { in mpi3mr_bsg_process_mpt_cmds()
2711 if (mpi_header->function == in mpi3mr_bsg_process_mpt_cmds()
2714 dprint_dump(drv_buf_iter->kern_buf, in mpi3mr_bsg_process_mpt_cmds()
2719 if ((mpi_header->function == MPI3_BSG_FUNCTION_NVME_ENCAPSULATED) || in mpi3mr_bsg_process_mpt_cmds()
2720 (mpi_header->function == MPI3_BSG_FUNCTION_SCSI_IO)) { in mpi3mr_bsg_process_mpt_cmds()
2723 karg->timeout, mpi_header->function_dependent); in mpi3mr_bsg_process_mpt_cmds()
2726 mpi_header->function_dependent, 0, in mpi3mr_bsg_process_mpt_cmds()
2728 &mrioc->host_tm_cmds, &resp_code, NULL); in mpi3mr_bsg_process_mpt_cmds()
2730 if (!(mrioc->bsg_cmds.state & MPI3MR_CMD_COMPLETE) && in mpi3mr_bsg_process_mpt_cmds()
2731 !(mrioc->bsg_cmds.state & MPI3MR_CMD_RESET)) in mpi3mr_bsg_process_mpt_cmds()
2738 if (mrioc->prp_list_virt) { in mpi3mr_bsg_process_mpt_cmds()
2739 dma_free_coherent(&mrioc->pdev->dev, mrioc->prp_sz, in mpi3mr_bsg_process_mpt_cmds()
2740 mrioc->prp_list_virt, mrioc->prp_list_dma); in mpi3mr_bsg_process_mpt_cmds()
2741 mrioc->prp_list_virt = NULL; in mpi3mr_bsg_process_mpt_cmds()
2744 if ((mrioc->bsg_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK) in mpi3mr_bsg_process_mpt_cmds()
2749 (mrioc->bsg_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK), in mpi3mr_bsg_process_mpt_cmds()
2750 mrioc->bsg_cmds.ioc_loginfo); in mpi3mr_bsg_process_mpt_cmds()
2756 drv_buf_iter->kern_buf_len = (sizeof(*bsg_reply_buf) + in mpi3mr_bsg_process_mpt_cmds()
2757 mrioc->reply_sz); in mpi3mr_bsg_process_mpt_cmds()
2758 bsg_reply_buf = kzalloc(drv_buf_iter->kern_buf_len, GFP_KERNEL); in mpi3mr_bsg_process_mpt_cmds()
2761 rval = -ENOMEM; in mpi3mr_bsg_process_mpt_cmds()
2764 if (mrioc->bsg_cmds.state & MPI3MR_CMD_REPLY_VALID) { in mpi3mr_bsg_process_mpt_cmds()
2765 bsg_reply_buf->mpi_reply_type = in mpi3mr_bsg_process_mpt_cmds()
2767 memcpy(bsg_reply_buf->reply_buf, in mpi3mr_bsg_process_mpt_cmds()
2768 mrioc->bsg_cmds.reply, mrioc->reply_sz); in mpi3mr_bsg_process_mpt_cmds()
2770 bsg_reply_buf->mpi_reply_type = in mpi3mr_bsg_process_mpt_cmds()
2773 bsg_reply_buf->reply_buf; in mpi3mr_bsg_process_mpt_cmds()
2774 status_desc->ioc_status = mrioc->bsg_cmds.ioc_status; in mpi3mr_bsg_process_mpt_cmds()
2775 status_desc->ioc_log_info = mrioc->bsg_cmds.ioc_loginfo; in mpi3mr_bsg_process_mpt_cmds()
2777 tmplen = min(drv_buf_iter->kern_buf_len, in mpi3mr_bsg_process_mpt_cmds()
2778 drv_buf_iter->bsg_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2779 memcpy(drv_buf_iter->bsg_buf, bsg_reply_buf, tmplen); in mpi3mr_bsg_process_mpt_cmds()
2782 if (erb_offset != 0xFF && mrioc->bsg_cmds.sensebuf && in mpi3mr_bsg_process_mpt_cmds()
2783 mrioc->bsg_cmds.is_sense) { in mpi3mr_bsg_process_mpt_cmds()
2785 tmplen = min(erbsz, drv_buf_iter->bsg_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2786 memcpy(drv_buf_iter->bsg_buf, sense_buff_k, tmplen); in mpi3mr_bsg_process_mpt_cmds()
2791 if (drv_buf_iter->data_dir == DMA_NONE) in mpi3mr_bsg_process_mpt_cmds()
2794 memcpy(drv_buf_iter->bsg_buf, in mpi3mr_bsg_process_mpt_cmds()
2795 drv_buf_iter->kern_buf, in mpi3mr_bsg_process_mpt_cmds()
2796 drv_buf_iter->kern_buf_len); in mpi3mr_bsg_process_mpt_cmds()
2797 } else if (drv_buf_iter->data_dir == DMA_FROM_DEVICE) { in mpi3mr_bsg_process_mpt_cmds()
2800 desc_count < drv_buf_iter->num_dma_desc; in mpi3mr_bsg_process_mpt_cmds()
2802 memcpy(((u8 *)drv_buf_iter->bsg_buf + tmplen), in mpi3mr_bsg_process_mpt_cmds()
2803 drv_buf_iter->dma_desc[desc_count].addr, in mpi3mr_bsg_process_mpt_cmds()
2804 drv_buf_iter->dma_desc[desc_count].size); in mpi3mr_bsg_process_mpt_cmds()
2806 drv_buf_iter->dma_desc[desc_count].size; in mpi3mr_bsg_process_mpt_cmds()
2813 job->reply_payload_rcv_len = in mpi3mr_bsg_process_mpt_cmds()
2814 sg_copy_from_buffer(job->reply_payload.sg_list, in mpi3mr_bsg_process_mpt_cmds()
2815 job->reply_payload.sg_cnt, in mpi3mr_bsg_process_mpt_cmds()
2816 din_buf, job->reply_payload.payload_len); in mpi3mr_bsg_process_mpt_cmds()
2818 mrioc->bsg_cmds.is_sense = 0; in mpi3mr_bsg_process_mpt_cmds()
2819 mrioc->bsg_cmds.sensebuf = NULL; in mpi3mr_bsg_process_mpt_cmds()
2820 mrioc->bsg_cmds.state = MPI3MR_CMD_NOTUSED; in mpi3mr_bsg_process_mpt_cmds()
2821 mutex_unlock(&mrioc->bsg_cmds.mutex); in mpi3mr_bsg_process_mpt_cmds()
2830 kfree(drv_buf_iter->dma_desc); in mpi3mr_bsg_process_mpt_cmds()
2838 * mpi3mr_app_save_logdata - Save Log Data events
2853 u32 index = mrioc->logdata_buf_idx, sz; in mpi3mr_app_save_logdata()
2856 if (!(mrioc->logdata_buf)) in mpi3mr_app_save_logdata()
2860 (mrioc->logdata_buf + (index * mrioc->logdata_entry_sz)); in mpi3mr_app_save_logdata()
2861 entry->valid_entry = 1; in mpi3mr_app_save_logdata()
2862 sz = min(mrioc->logdata_entry_sz, event_data_size); in mpi3mr_app_save_logdata()
2863 memcpy(entry->data, event_data, sz); in mpi3mr_app_save_logdata()
2864 mrioc->logdata_buf_idx = in mpi3mr_app_save_logdata()
2870 * mpi3mr_bsg_request - bsg request entry point
2879 long rval = -EINVAL; in mpi3mr_bsg_request()
2882 struct mpi3mr_bsg_packet *bsg_req = job->request; in mpi3mr_bsg_request()
2884 switch (bsg_req->cmd_type) { in mpi3mr_bsg_request()
2893 MPI3MR_DRIVER_NAME, bsg_req->cmd_type); in mpi3mr_bsg_request()
2903 * mpi3mr_bsg_exit - de-registration from bsg layer
2913 struct device *bsg_dev = &mrioc->bsg_dev; in mpi3mr_bsg_exit()
2914 if (!mrioc->bsg_queue) in mpi3mr_bsg_exit()
2917 bsg_remove_queue(mrioc->bsg_queue); in mpi3mr_bsg_exit()
2918 mrioc->bsg_queue = NULL; in mpi3mr_bsg_exit()
2925 * mpi3mr_bsg_node_release -release bsg device node
2934 put_device(dev->parent); in mpi3mr_bsg_node_release()
2938 * mpi3mr_bsg_init - registration with bsg layer
2948 struct device *bsg_dev = &mrioc->bsg_dev; in mpi3mr_bsg_init()
2949 struct device *parent = &mrioc->shost->shost_gendev; in mpi3mr_bsg_init()
2957 bsg_dev->parent = get_device(parent); in mpi3mr_bsg_init()
2958 bsg_dev->release = mpi3mr_bsg_node_release; in mpi3mr_bsg_init()
2960 dev_set_name(bsg_dev, "mpi3mrctl%u", mrioc->id); in mpi3mr_bsg_init()
2969 mrioc->bsg_queue = bsg_setup_queue(bsg_dev, dev_name(bsg_dev), &lim, in mpi3mr_bsg_init()
2971 if (IS_ERR(mrioc->bsg_queue)) { in mpi3mr_bsg_init()
2980 * version_fw_show - SysFS callback for firmware version read
2985 * Return: sysfs_emit() return after copying firmware version
2993 struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver; in version_fw_show()
2995 return sysfs_emit(buf, "%d.%d.%d.%d.%05d-%05d\n", in version_fw_show()
2996 fwver->gen_major, fwver->gen_minor, fwver->ph_major, in version_fw_show()
2997 fwver->ph_minor, fwver->cust_id, fwver->build_num); in version_fw_show()
3002 * fw_queue_depth_show - SysFS callback for firmware max cmds
3016 return sysfs_emit(buf, "%d\n", mrioc->facts.max_reqs); in fw_queue_depth_show()
3021 * op_req_q_count_show - SysFS callback for request queue count
3035 return sysfs_emit(buf, "%d\n", mrioc->num_op_req_q); in op_req_q_count_show()
3040 * reply_queue_count_show - SysFS callback for reply queue count
3054 return sysfs_emit(buf, "%d\n", mrioc->num_op_reply_q); in reply_queue_count_show()
3060 * logging_level_show - Show controller debug level
3079 return sysfs_emit(buf, "%08xh\n", mrioc->logging_level); in logging_level_show()
3083 * logging_level_store- Change controller debug level
3105 return -EINVAL; in logging_level_store()
3107 mrioc->logging_level = val; in logging_level_store()
3108 ioc_info(mrioc, "logging_level=%08xh\n", mrioc->logging_level); in logging_level_store()
3114 * adp_state_show() - SysFS callback for adapter state show
3133 else if (mrioc->reset_in_progress || mrioc->stop_bsgs || in adp_state_show()
3134 mrioc->block_on_pci_err) in adp_state_show()
3171 * sas_address_show - SysFS callback for dev SASaddress display
3188 sdev_priv_data = sdev->hostdata; in sas_address_show()
3192 tgt_priv_data = sdev_priv_data->tgt_priv_data; in sas_address_show()
3195 tgtdev = tgt_priv_data->tgt_dev; in sas_address_show()
3196 if (!tgtdev || tgtdev->dev_type != MPI3_DEVICE_DEVFORM_SAS_SATA) in sas_address_show()
3199 (unsigned long long)tgtdev->dev_spec.sas_sata_inf.sas_address); in sas_address_show()
3205 * device_handle_show - SysFS callback for device handle display
3222 sdev_priv_data = sdev->hostdata; in device_handle_show()
3226 tgt_priv_data = sdev_priv_data->tgt_priv_data; in device_handle_show()
3229 tgtdev = tgt_priv_data->tgt_dev; in device_handle_show()
3232 return sysfs_emit(buf, "0x%04x\n", tgtdev->dev_handle); in device_handle_show()
3238 * persistent_id_show - SysFS callback for persisten ID display
3255 sdev_priv_data = sdev->hostdata; in persistent_id_show()
3259 tgt_priv_data = sdev_priv_data->tgt_priv_data; in persistent_id_show()
3262 tgtdev = tgt_priv_data->tgt_dev; in persistent_id_show()
3265 return sysfs_emit(buf, "%d\n", tgtdev->perst_id); in persistent_id_show()
3270 * sas_ncq_prio_supported_show - Indicate if device supports NCQ priority
3275 * A sysfs 'read-only' sdev attribute, only works with SATA devices
3288 * sas_ncq_prio_enable_show - send prioritized io commands to device
3300 struct mpi3mr_sdev_priv_data *sdev_priv_data = sdev->hostdata; in sas_ncq_prio_enable_show()
3305 return sysfs_emit(buf, "%d\n", sdev_priv_data->ncq_prio_enable); in sas_ncq_prio_enable_show()
3314 struct mpi3mr_sdev_priv_data *sdev_priv_data = sdev->hostdata; in sas_ncq_prio_enable_store()
3318 return -EINVAL; in sas_ncq_prio_enable_store()
3321 return -EINVAL; in sas_ncq_prio_enable_store()
3323 sdev_priv_data->ncq_prio_enable = ncq_prio_enable; in sas_ncq_prio_enable_store()