Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Management Module Support for MPT (Message Passing Technology) based |
| 3 | * controllers |
| 4 | * |
| 5 | * This code is based on drivers/scsi/mpt3sas/mpt3sas_ctl.c |
Sreekanth Reddy | a4ffce0 | 2014-09-12 15:35:29 +0530 | [diff] [blame] | 6 | * Copyright (C) 2012-2014 LSI Corporation |
Sreekanth Reddy | a03bd15 | 2015-01-12 11:39:02 +0530 | [diff] [blame] | 7 | * Copyright (C) 2013-2014 Avago Technologies |
| 8 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * NO WARRANTY |
| 21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 25 | * solely responsible for determining the appropriateness of using and |
| 26 | * distributing the Program and assumes all risks associated with its |
| 27 | * exercise of rights under this Agreement, including but not limited to |
| 28 | * the risks and costs of program errors, damage to or loss of data, |
| 29 | * programs or equipment, and unavailability or interruption of operations. |
| 30 | |
| 31 | * DISCLAIMER OF LIABILITY |
| 32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 39 | |
| 40 | * You should have received a copy of the GNU General Public License |
| 41 | * along with this program; if not, write to the Free Software |
| 42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 43 | * USA. |
| 44 | */ |
| 45 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 46 | #include <linux/kernel.h> |
| 47 | #include <linux/module.h> |
| 48 | #include <linux/errno.h> |
| 49 | #include <linux/init.h> |
| 50 | #include <linux/slab.h> |
| 51 | #include <linux/types.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/delay.h> |
| 54 | #include <linux/compat.h> |
| 55 | #include <linux/poll.h> |
| 56 | |
| 57 | #include <linux/io.h> |
| 58 | #include <linux/uaccess.h> |
| 59 | |
| 60 | #include "mpt3sas_base.h" |
| 61 | #include "mpt3sas_ctl.h" |
| 62 | |
| 63 | |
| 64 | static struct fasync_struct *async_queue; |
| 65 | static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait); |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * enum block_state - blocking state |
| 70 | * @NON_BLOCKING: non blocking |
| 71 | * @BLOCKING: blocking |
| 72 | * |
| 73 | * These states are for ioctls that need to wait for a response |
| 74 | * from firmware, so they probably require sleep. |
| 75 | */ |
| 76 | enum block_state { |
| 77 | NON_BLOCKING, |
| 78 | BLOCKING, |
| 79 | }; |
| 80 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 81 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 82 | * _ctl_display_some_debug - debug routine |
| 83 | * @ioc: per adapter object |
| 84 | * @smid: system request message index |
| 85 | * @calling_function_name: string pass from calling function |
| 86 | * @mpi_reply: reply message frame |
| 87 | * Context: none. |
| 88 | * |
| 89 | * Function for displaying debug info helpful when debugging issues |
| 90 | * in this module. |
| 91 | */ |
| 92 | static void |
| 93 | _ctl_display_some_debug(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 94 | char *calling_function_name, MPI2DefaultReply_t *mpi_reply) |
| 95 | { |
| 96 | Mpi2ConfigRequest_t *mpi_request; |
| 97 | char *desc = NULL; |
| 98 | |
| 99 | if (!(ioc->logging_level & MPT_DEBUG_IOCTL)) |
| 100 | return; |
| 101 | |
| 102 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 103 | switch (mpi_request->Function) { |
| 104 | case MPI2_FUNCTION_SCSI_IO_REQUEST: |
| 105 | { |
| 106 | Mpi2SCSIIORequest_t *scsi_request = |
| 107 | (Mpi2SCSIIORequest_t *)mpi_request; |
| 108 | |
| 109 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, |
| 110 | "scsi_io, cmd(0x%02x), cdb_len(%d)", |
| 111 | scsi_request->CDB.CDB32[0], |
| 112 | le16_to_cpu(scsi_request->IoFlags) & 0xF); |
| 113 | desc = ioc->tmp_string; |
| 114 | break; |
| 115 | } |
| 116 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 117 | desc = "task_mgmt"; |
| 118 | break; |
| 119 | case MPI2_FUNCTION_IOC_INIT: |
| 120 | desc = "ioc_init"; |
| 121 | break; |
| 122 | case MPI2_FUNCTION_IOC_FACTS: |
| 123 | desc = "ioc_facts"; |
| 124 | break; |
| 125 | case MPI2_FUNCTION_CONFIG: |
| 126 | { |
| 127 | Mpi2ConfigRequest_t *config_request = |
| 128 | (Mpi2ConfigRequest_t *)mpi_request; |
| 129 | |
| 130 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, |
| 131 | "config, type(0x%02x), ext_type(0x%02x), number(%d)", |
| 132 | (config_request->Header.PageType & |
| 133 | MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType, |
| 134 | config_request->Header.PageNumber); |
| 135 | desc = ioc->tmp_string; |
| 136 | break; |
| 137 | } |
| 138 | case MPI2_FUNCTION_PORT_FACTS: |
| 139 | desc = "port_facts"; |
| 140 | break; |
| 141 | case MPI2_FUNCTION_PORT_ENABLE: |
| 142 | desc = "port_enable"; |
| 143 | break; |
| 144 | case MPI2_FUNCTION_EVENT_NOTIFICATION: |
| 145 | desc = "event_notification"; |
| 146 | break; |
| 147 | case MPI2_FUNCTION_FW_DOWNLOAD: |
| 148 | desc = "fw_download"; |
| 149 | break; |
| 150 | case MPI2_FUNCTION_FW_UPLOAD: |
| 151 | desc = "fw_upload"; |
| 152 | break; |
| 153 | case MPI2_FUNCTION_RAID_ACTION: |
| 154 | desc = "raid_action"; |
| 155 | break; |
| 156 | case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: |
| 157 | { |
| 158 | Mpi2SCSIIORequest_t *scsi_request = |
| 159 | (Mpi2SCSIIORequest_t *)mpi_request; |
| 160 | |
| 161 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, |
| 162 | "raid_pass, cmd(0x%02x), cdb_len(%d)", |
| 163 | scsi_request->CDB.CDB32[0], |
| 164 | le16_to_cpu(scsi_request->IoFlags) & 0xF); |
| 165 | desc = ioc->tmp_string; |
| 166 | break; |
| 167 | } |
| 168 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: |
| 169 | desc = "sas_iounit_cntl"; |
| 170 | break; |
| 171 | case MPI2_FUNCTION_SATA_PASSTHROUGH: |
| 172 | desc = "sata_pass"; |
| 173 | break; |
| 174 | case MPI2_FUNCTION_DIAG_BUFFER_POST: |
| 175 | desc = "diag_buffer_post"; |
| 176 | break; |
| 177 | case MPI2_FUNCTION_DIAG_RELEASE: |
| 178 | desc = "diag_release"; |
| 179 | break; |
| 180 | case MPI2_FUNCTION_SMP_PASSTHROUGH: |
| 181 | desc = "smp_passthrough"; |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | if (!desc) |
| 186 | return; |
| 187 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 188 | ioc_info(ioc, "%s: %s, smid(%d)\n", calling_function_name, desc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 189 | |
| 190 | if (!mpi_reply) |
| 191 | return; |
| 192 | |
| 193 | if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo) |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 194 | ioc_info(ioc, "\tiocstatus(0x%04x), loginfo(0x%08x)\n", |
| 195 | le16_to_cpu(mpi_reply->IOCStatus), |
| 196 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 197 | |
| 198 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 199 | mpi_request->Function == |
| 200 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) { |
| 201 | Mpi2SCSIIOReply_t *scsi_reply = |
| 202 | (Mpi2SCSIIOReply_t *)mpi_reply; |
| 203 | struct _sas_device *sas_device = NULL; |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 204 | struct _pcie_device *pcie_device = NULL; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 205 | |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 206 | sas_device = mpt3sas_get_sdev_by_handle(ioc, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 207 | le16_to_cpu(scsi_reply->DevHandle)); |
| 208 | if (sas_device) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 209 | ioc_warn(ioc, "\tsas_address(0x%016llx), phy(%d)\n", |
| 210 | (u64)sas_device->sas_address, |
| 211 | sas_device->phy); |
| 212 | ioc_warn(ioc, "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 213 | (u64)sas_device->enclosure_logical_id, |
| 214 | sas_device->slot); |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 215 | sas_device_put(sas_device); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 216 | } |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 217 | if (!sas_device) { |
| 218 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, |
| 219 | le16_to_cpu(scsi_reply->DevHandle)); |
| 220 | if (pcie_device) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 221 | ioc_warn(ioc, "\tWWID(0x%016llx), port(%d)\n", |
| 222 | (unsigned long long)pcie_device->wwid, |
| 223 | pcie_device->port_num); |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 224 | if (pcie_device->enclosure_handle != 0) |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 225 | ioc_warn(ioc, "\tenclosure_logical_id(0x%016llx), slot(%d)\n", |
| 226 | (u64)pcie_device->enclosure_logical_id, |
| 227 | pcie_device->slot); |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 228 | pcie_device_put(pcie_device); |
| 229 | } |
| 230 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 231 | if (scsi_reply->SCSIState || scsi_reply->SCSIStatus) |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 232 | ioc_info(ioc, "\tscsi_state(0x%02x), scsi_status(0x%02x)\n", |
| 233 | scsi_reply->SCSIState, |
| 234 | scsi_reply->SCSIStatus); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 238 | /** |
| 239 | * mpt3sas_ctl_done - ctl module completion routine |
| 240 | * @ioc: per adapter object |
| 241 | * @smid: system request message index |
| 242 | * @msix_index: MSIX table index supplied by the OS |
| 243 | * @reply: reply message frame(lower 32bit addr) |
| 244 | * Context: none. |
| 245 | * |
| 246 | * The callback handler when using ioc->ctl_cb_idx. |
| 247 | * |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 248 | * Return: 1 meaning mf should be freed from _base_interrupt |
| 249 | * 0 means the mf is freed from this function. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 250 | */ |
| 251 | u8 |
| 252 | mpt3sas_ctl_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 253 | u32 reply) |
| 254 | { |
| 255 | MPI2DefaultReply_t *mpi_reply; |
| 256 | Mpi2SCSIIOReply_t *scsiio_reply; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 257 | Mpi26NVMeEncapsulatedErrorReply_t *nvme_error_reply; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 258 | const void *sense_data; |
| 259 | u32 sz; |
| 260 | |
| 261 | if (ioc->ctl_cmds.status == MPT3_CMD_NOT_USED) |
| 262 | return 1; |
| 263 | if (ioc->ctl_cmds.smid != smid) |
| 264 | return 1; |
| 265 | ioc->ctl_cmds.status |= MPT3_CMD_COMPLETE; |
| 266 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 267 | if (mpi_reply) { |
| 268 | memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 269 | ioc->ctl_cmds.status |= MPT3_CMD_REPLY_VALID; |
| 270 | /* get sense data */ |
| 271 | if (mpi_reply->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 272 | mpi_reply->Function == |
| 273 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) { |
| 274 | scsiio_reply = (Mpi2SCSIIOReply_t *)mpi_reply; |
| 275 | if (scsiio_reply->SCSIState & |
| 276 | MPI2_SCSI_STATE_AUTOSENSE_VALID) { |
| 277 | sz = min_t(u32, SCSI_SENSE_BUFFERSIZE, |
| 278 | le32_to_cpu(scsiio_reply->SenseCount)); |
| 279 | sense_data = mpt3sas_base_get_sense_buffer(ioc, |
| 280 | smid); |
| 281 | memcpy(ioc->ctl_cmds.sense, sense_data, sz); |
| 282 | } |
| 283 | } |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 284 | /* |
| 285 | * Get Error Response data for NVMe device. The ctl_cmds.sense |
| 286 | * buffer is used to store the Error Response data. |
| 287 | */ |
| 288 | if (mpi_reply->Function == MPI2_FUNCTION_NVME_ENCAPSULATED) { |
| 289 | nvme_error_reply = |
| 290 | (Mpi26NVMeEncapsulatedErrorReply_t *)mpi_reply; |
| 291 | sz = min_t(u32, NVME_ERROR_RESPONSE_SIZE, |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 292 | le16_to_cpu(nvme_error_reply->ErrorResponseCount)); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 293 | sense_data = mpt3sas_base_get_sense_buffer(ioc, smid); |
| 294 | memcpy(ioc->ctl_cmds.sense, sense_data, sz); |
| 295 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 296 | } |
Suganath Prabu Subramani | 016d5c3 | 2017-10-31 18:02:28 +0530 | [diff] [blame] | 297 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 298 | _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 299 | ioc->ctl_cmds.status &= ~MPT3_CMD_PENDING; |
| 300 | complete(&ioc->ctl_cmds.done); |
| 301 | return 1; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * _ctl_check_event_type - determines when an event needs logging |
| 306 | * @ioc: per adapter object |
| 307 | * @event: firmware event |
| 308 | * |
| 309 | * The bitmask in ioc->event_type[] indicates which events should be |
| 310 | * be saved in the driver event_log. This bitmask is set by application. |
| 311 | * |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 312 | * Return: 1 when event should be captured, or zero means no match. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 313 | */ |
| 314 | static int |
| 315 | _ctl_check_event_type(struct MPT3SAS_ADAPTER *ioc, u16 event) |
| 316 | { |
| 317 | u16 i; |
| 318 | u32 desired_event; |
| 319 | |
| 320 | if (event >= 128 || !event || !ioc->event_log) |
| 321 | return 0; |
| 322 | |
| 323 | desired_event = (1 << (event % 32)); |
| 324 | if (!desired_event) |
| 325 | desired_event = 1; |
| 326 | i = event / 32; |
| 327 | return desired_event & ioc->event_type[i]; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * mpt3sas_ctl_add_to_event_log - add event |
| 332 | * @ioc: per adapter object |
| 333 | * @mpi_reply: reply message frame |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 334 | */ |
| 335 | void |
| 336 | mpt3sas_ctl_add_to_event_log(struct MPT3SAS_ADAPTER *ioc, |
| 337 | Mpi2EventNotificationReply_t *mpi_reply) |
| 338 | { |
| 339 | struct MPT3_IOCTL_EVENTS *event_log; |
| 340 | u16 event; |
| 341 | int i; |
| 342 | u32 sz, event_data_sz; |
| 343 | u8 send_aen = 0; |
| 344 | |
| 345 | if (!ioc->event_log) |
| 346 | return; |
| 347 | |
| 348 | event = le16_to_cpu(mpi_reply->Event); |
| 349 | |
| 350 | if (_ctl_check_event_type(ioc, event)) { |
| 351 | |
| 352 | /* insert entry into circular event_log */ |
| 353 | i = ioc->event_context % MPT3SAS_CTL_EVENT_LOG_SIZE; |
| 354 | event_log = ioc->event_log; |
| 355 | event_log[i].event = event; |
| 356 | event_log[i].context = ioc->event_context++; |
| 357 | |
| 358 | event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4; |
| 359 | sz = min_t(u32, event_data_sz, MPT3_EVENT_DATA_SIZE); |
| 360 | memset(event_log[i].data, 0, MPT3_EVENT_DATA_SIZE); |
| 361 | memcpy(event_log[i].data, mpi_reply->EventData, sz); |
| 362 | send_aen = 1; |
| 363 | } |
| 364 | |
| 365 | /* This aen_event_read_flag flag is set until the |
| 366 | * application has read the event log. |
| 367 | * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify. |
| 368 | */ |
| 369 | if (event == MPI2_EVENT_LOG_ENTRY_ADDED || |
| 370 | (send_aen && !ioc->aen_event_read_flag)) { |
| 371 | ioc->aen_event_read_flag = 1; |
| 372 | wake_up_interruptible(&ctl_poll_wait); |
| 373 | if (async_queue) |
| 374 | kill_fasync(&async_queue, SIGIO, POLL_IN); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * mpt3sas_ctl_event_callback - firmware event handler (called at ISR time) |
| 380 | * @ioc: per adapter object |
| 381 | * @msix_index: MSIX table index supplied by the OS |
| 382 | * @reply: reply message frame(lower 32bit addr) |
| 383 | * Context: interrupt. |
| 384 | * |
| 385 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 386 | * The tasks are worked from _firmware_event_work in user context. |
| 387 | * |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 388 | * Return: 1 meaning mf should be freed from _base_interrupt |
| 389 | * 0 means the mf is freed from this function. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 390 | */ |
| 391 | u8 |
| 392 | mpt3sas_ctl_event_callback(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, |
| 393 | u32 reply) |
| 394 | { |
| 395 | Mpi2EventNotificationReply_t *mpi_reply; |
| 396 | |
| 397 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
Suganath prabu Subramani | 869817f | 2016-01-28 12:07:00 +0530 | [diff] [blame] | 398 | if (mpi_reply) |
| 399 | mpt3sas_ctl_add_to_event_log(ioc, mpi_reply); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 400 | return 1; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * _ctl_verify_adapter - validates ioc_number passed from application |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 405 | * @ioc_number: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 406 | * @iocpp: The ioc pointer is returned in this. |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 407 | * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device & |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 408 | * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 409 | * |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 410 | * Return: (-1) means error, else ioc_number. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 411 | */ |
| 412 | static int |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 413 | _ctl_verify_adapter(int ioc_number, struct MPT3SAS_ADAPTER **iocpp, |
| 414 | int mpi_version) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 415 | { |
| 416 | struct MPT3SAS_ADAPTER *ioc; |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 417 | int version = 0; |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 418 | /* global ioc lock to protect controller on list operations */ |
| 419 | spin_lock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 420 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { |
| 421 | if (ioc->id != ioc_number) |
| 422 | continue; |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 423 | /* Check whether this ioctl command is from right |
| 424 | * ioctl device or not, if not continue the search. |
| 425 | */ |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 426 | version = ioc->hba_mpi_version_belonged; |
| 427 | /* MPI25_VERSION and MPI26_VERSION uses same ioctl |
| 428 | * device. |
| 429 | */ |
| 430 | if (mpi_version == (MPI25_VERSION | MPI26_VERSION)) { |
| 431 | if ((version == MPI25_VERSION) || |
| 432 | (version == MPI26_VERSION)) |
| 433 | goto out; |
| 434 | else |
| 435 | continue; |
| 436 | } else { |
| 437 | if (version != mpi_version) |
| 438 | continue; |
| 439 | } |
| 440 | out: |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 441 | spin_unlock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 442 | *iocpp = ioc; |
| 443 | return ioc_number; |
| 444 | } |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 445 | spin_unlock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 446 | *iocpp = NULL; |
| 447 | return -1; |
| 448 | } |
| 449 | |
| 450 | /** |
| 451 | * mpt3sas_ctl_reset_handler - reset callback handler (for ctl) |
| 452 | * @ioc: per adapter object |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 453 | * |
| 454 | * The handler for doing any required cleanup or initialization. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 455 | */ |
Bart Van Assche | c7a3570 | 2018-06-15 14:42:00 -0700 | [diff] [blame] | 456 | void mpt3sas_ctl_pre_reset_handler(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 457 | { |
| 458 | int i; |
| 459 | u8 issue_reset; |
| 460 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 461 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_PRE_RESET\n", __func__)); |
Bart Van Assche | c7a3570 | 2018-06-15 14:42:00 -0700 | [diff] [blame] | 462 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { |
| 463 | if (!(ioc->diag_buffer_status[i] & |
| 464 | MPT3_DIAG_BUFFER_IS_REGISTERED)) |
| 465 | continue; |
| 466 | if ((ioc->diag_buffer_status[i] & |
| 467 | MPT3_DIAG_BUFFER_IS_RELEASED)) |
| 468 | continue; |
| 469 | mpt3sas_send_diag_release(ioc, i, &issue_reset); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * mpt3sas_ctl_reset_handler - reset callback handler (for ctl) |
| 475 | * @ioc: per adapter object |
| 476 | * |
| 477 | * The handler for doing any required cleanup or initialization. |
| 478 | */ |
| 479 | void mpt3sas_ctl_after_reset_handler(struct MPT3SAS_ADAPTER *ioc) |
| 480 | { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 481 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_AFTER_RESET\n", __func__)); |
Bart Van Assche | c7a3570 | 2018-06-15 14:42:00 -0700 | [diff] [blame] | 482 | if (ioc->ctl_cmds.status & MPT3_CMD_PENDING) { |
| 483 | ioc->ctl_cmds.status |= MPT3_CMD_RESET; |
| 484 | mpt3sas_base_free_smid(ioc, ioc->ctl_cmds.smid); |
| 485 | complete(&ioc->ctl_cmds.done); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * mpt3sas_ctl_reset_handler - reset callback handler (for ctl) |
| 491 | * @ioc: per adapter object |
| 492 | * |
| 493 | * The handler for doing any required cleanup or initialization. |
| 494 | */ |
| 495 | void mpt3sas_ctl_reset_done_handler(struct MPT3SAS_ADAPTER *ioc) |
| 496 | { |
| 497 | int i; |
| 498 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 499 | dtmprintk(ioc, ioc_info(ioc, "%s: MPT3_IOC_DONE_RESET\n", __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 500 | |
Bart Van Assche | c7a3570 | 2018-06-15 14:42:00 -0700 | [diff] [blame] | 501 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { |
| 502 | if (!(ioc->diag_buffer_status[i] & |
| 503 | MPT3_DIAG_BUFFER_IS_REGISTERED)) |
| 504 | continue; |
| 505 | if ((ioc->diag_buffer_status[i] & |
| 506 | MPT3_DIAG_BUFFER_IS_RELEASED)) |
| 507 | continue; |
| 508 | ioc->diag_buffer_status[i] |= |
| 509 | MPT3_DIAG_BUFFER_IS_DIAG_RESET; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | /** |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 514 | * _ctl_fasync - |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 515 | * @fd: ? |
| 516 | * @filep: ? |
| 517 | * @mode: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 518 | * |
| 519 | * Called when application request fasyn callback handler. |
| 520 | */ |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 521 | static int |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 522 | _ctl_fasync(int fd, struct file *filep, int mode) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 523 | { |
| 524 | return fasync_helper(fd, filep, mode, &async_queue); |
| 525 | } |
| 526 | |
| 527 | /** |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 528 | * _ctl_poll - |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 529 | * @filep: ? |
| 530 | * @wait: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 531 | * |
| 532 | */ |
Al Viro | afc9a42 | 2017-07-03 06:39:46 -0400 | [diff] [blame] | 533 | static __poll_t |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 534 | _ctl_poll(struct file *filep, poll_table *wait) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 535 | { |
| 536 | struct MPT3SAS_ADAPTER *ioc; |
| 537 | |
| 538 | poll_wait(filep, &ctl_poll_wait, wait); |
| 539 | |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 540 | /* global ioc lock to protect controller on list operations */ |
| 541 | spin_lock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 542 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 543 | if (ioc->aen_event_read_flag) { |
| 544 | spin_unlock(&gioc_lock); |
Linus Torvalds | a9a0884 | 2018-02-11 14:34:03 -0800 | [diff] [blame] | 545 | return EPOLLIN | EPOLLRDNORM; |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 546 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 547 | } |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 548 | spin_unlock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * _ctl_set_task_mid - assign an active smid to tm request |
| 554 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 555 | * @karg: (struct mpt3_ioctl_command) |
| 556 | * @tm_request: pointer to mf from user space |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 557 | * |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 558 | * Return: 0 when an smid if found, else fail. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 559 | * during failure, the reply frame is filled. |
| 560 | */ |
| 561 | static int |
| 562 | _ctl_set_task_mid(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command *karg, |
| 563 | Mpi2SCSITaskManagementRequest_t *tm_request) |
| 564 | { |
| 565 | u8 found = 0; |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 566 | u16 smid; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 567 | u16 handle; |
| 568 | struct scsi_cmnd *scmd; |
| 569 | struct MPT3SAS_DEVICE *priv_data; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 570 | Mpi2SCSITaskManagementReply_t *tm_reply; |
| 571 | u32 sz; |
| 572 | u32 lun; |
| 573 | char *desc = NULL; |
| 574 | |
| 575 | if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 576 | desc = "abort_task"; |
| 577 | else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) |
| 578 | desc = "query_task"; |
| 579 | else |
| 580 | return 0; |
| 581 | |
| 582 | lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN); |
| 583 | |
| 584 | handle = le16_to_cpu(tm_request->DevHandle); |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 585 | for (smid = ioc->scsiio_depth; smid && !found; smid--) { |
| 586 | struct scsiio_tracker *st; |
| 587 | |
| 588 | scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); |
| 589 | if (!scmd) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 590 | continue; |
| 591 | if (lun != scmd->device->lun) |
| 592 | continue; |
| 593 | priv_data = scmd->device->hostdata; |
| 594 | if (priv_data->sas_target == NULL) |
| 595 | continue; |
| 596 | if (priv_data->sas_target->handle != handle) |
| 597 | continue; |
Suganath Prabu Subramani | dbec4c90 | 2018-01-04 04:57:11 -0800 | [diff] [blame] | 598 | st = scsi_cmd_priv(scmd); |
| 599 | tm_request->TaskMID = cpu_to_le16(st->smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 600 | found = 1; |
| 601 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 602 | |
| 603 | if (!found) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 604 | dctlprintk(ioc, |
| 605 | ioc_info(ioc, "%s: handle(0x%04x), lun(%d), no active mid!!\n", |
| 606 | desc, le16_to_cpu(tm_request->DevHandle), |
| 607 | lun)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 608 | tm_reply = ioc->ctl_cmds.reply; |
| 609 | tm_reply->DevHandle = tm_request->DevHandle; |
| 610 | tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
| 611 | tm_reply->TaskType = tm_request->TaskType; |
| 612 | tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4; |
| 613 | tm_reply->VP_ID = tm_request->VP_ID; |
| 614 | tm_reply->VF_ID = tm_request->VF_ID; |
| 615 | sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz); |
| 616 | if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply, |
| 617 | sz)) |
| 618 | pr_err("failure at %s:%d/%s()!\n", __FILE__, |
| 619 | __LINE__, __func__); |
| 620 | return 1; |
| 621 | } |
| 622 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 623 | dctlprintk(ioc, |
| 624 | ioc_info(ioc, "%s: handle(0x%04x), lun(%d), task_mid(%d)\n", |
| 625 | desc, le16_to_cpu(tm_request->DevHandle), lun, |
| 626 | le16_to_cpu(tm_request->TaskMID))); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode |
| 632 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 633 | * @karg: (struct mpt3_ioctl_command) |
| 634 | * @mf: pointer to mf in user space |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 635 | */ |
| 636 | static long |
| 637 | _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg, |
| 638 | void __user *mf) |
| 639 | { |
| 640 | MPI2RequestHeader_t *mpi_request = NULL, *request; |
| 641 | MPI2DefaultReply_t *mpi_reply; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 642 | Mpi26NVMeEncapsulatedRequest_t *nvme_encap_request = NULL; |
Chaitra P B | c1a6c5a | 2018-04-24 05:28:41 -0400 | [diff] [blame] | 643 | struct _pcie_device *pcie_device = NULL; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 644 | u16 smid; |
Chaitra P B | c1a6c5a | 2018-04-24 05:28:41 -0400 | [diff] [blame] | 645 | u8 timeout; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 646 | u8 issue_reset; |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 647 | u32 sz, sz_arg; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 648 | void *psge; |
| 649 | void *data_out = NULL; |
| 650 | dma_addr_t data_out_dma = 0; |
| 651 | size_t data_out_sz = 0; |
| 652 | void *data_in = NULL; |
| 653 | dma_addr_t data_in_dma = 0; |
| 654 | size_t data_in_sz = 0; |
| 655 | long ret; |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 656 | u16 device_handle = MPT3SAS_INVALID_DEVICE_HANDLE; |
Chaitra P B | c1a6c5a | 2018-04-24 05:28:41 -0400 | [diff] [blame] | 657 | u8 tr_method = MPI26_SCSITASKMGMT_MSGFLAGS_PROTOCOL_LVL_RST_PCIE; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 658 | |
| 659 | issue_reset = 0; |
| 660 | |
| 661 | if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 662 | ioc_err(ioc, "%s: ctl_cmd in use\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 663 | ret = -EAGAIN; |
| 664 | goto out; |
| 665 | } |
| 666 | |
Suganath Prabu | f430574 | 2018-10-31 18:53:33 +0530 | [diff] [blame] | 667 | ret = mpt3sas_wait_for_ioc(ioc, IOC_OPERATIONAL_WAIT_COUNT); |
| 668 | if (ret) |
| 669 | goto out; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 670 | |
| 671 | mpi_request = kzalloc(ioc->request_sz, GFP_KERNEL); |
| 672 | if (!mpi_request) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 673 | ioc_err(ioc, "%s: failed obtaining a memory for mpi_request\n", |
| 674 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 675 | ret = -ENOMEM; |
| 676 | goto out; |
| 677 | } |
| 678 | |
| 679 | /* Check for overflow and wraparound */ |
| 680 | if (karg.data_sge_offset * 4 > ioc->request_sz || |
| 681 | karg.data_sge_offset > (UINT_MAX / 4)) { |
| 682 | ret = -EINVAL; |
| 683 | goto out; |
| 684 | } |
| 685 | |
| 686 | /* copy in request message frame from user */ |
| 687 | if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) { |
| 688 | pr_err("failure at %s:%d/%s()!\n", __FILE__, __LINE__, |
| 689 | __func__); |
| 690 | ret = -EFAULT; |
| 691 | goto out; |
| 692 | } |
| 693 | |
| 694 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) { |
| 695 | smid = mpt3sas_base_get_smid_hpr(ioc, ioc->ctl_cb_idx); |
| 696 | if (!smid) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 697 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 698 | ret = -EAGAIN; |
| 699 | goto out; |
| 700 | } |
| 701 | } else { |
Hannes Reinecke | b0cd285e | 2018-01-04 04:57:07 -0800 | [diff] [blame] | 702 | /* Use first reserved smid for passthrough ioctls */ |
| 703 | smid = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT + 1; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | ret = 0; |
| 707 | ioc->ctl_cmds.status = MPT3_CMD_PENDING; |
| 708 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 709 | request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 710 | memcpy(request, mpi_request, karg.data_sge_offset*4); |
| 711 | ioc->ctl_cmds.smid = smid; |
| 712 | data_out_sz = karg.data_out_size; |
| 713 | data_in_sz = karg.data_in_size; |
| 714 | |
| 715 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 716 | mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || |
| 717 | mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT || |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 718 | mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH || |
| 719 | mpi_request->Function == MPI2_FUNCTION_NVME_ENCAPSULATED) { |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 720 | |
| 721 | device_handle = le16_to_cpu(mpi_request->FunctionDependent1); |
| 722 | if (!device_handle || (device_handle > |
| 723 | ioc->facts.MaxDevHandle)) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 724 | ret = -EINVAL; |
| 725 | mpt3sas_base_free_smid(ioc, smid); |
| 726 | goto out; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | /* obtain dma-able memory for data transfer */ |
| 731 | if (data_out_sz) /* WRITE */ { |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 732 | data_out = dma_alloc_coherent(&ioc->pdev->dev, data_out_sz, |
| 733 | &data_out_dma, GFP_KERNEL); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 734 | if (!data_out) { |
| 735 | pr_err("failure at %s:%d/%s()!\n", __FILE__, |
| 736 | __LINE__, __func__); |
| 737 | ret = -ENOMEM; |
| 738 | mpt3sas_base_free_smid(ioc, smid); |
| 739 | goto out; |
| 740 | } |
| 741 | if (copy_from_user(data_out, karg.data_out_buf_ptr, |
| 742 | data_out_sz)) { |
| 743 | pr_err("failure at %s:%d/%s()!\n", __FILE__, |
| 744 | __LINE__, __func__); |
| 745 | ret = -EFAULT; |
| 746 | mpt3sas_base_free_smid(ioc, smid); |
| 747 | goto out; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | if (data_in_sz) /* READ */ { |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 752 | data_in = dma_alloc_coherent(&ioc->pdev->dev, data_in_sz, |
| 753 | &data_in_dma, GFP_KERNEL); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 754 | if (!data_in) { |
| 755 | pr_err("failure at %s:%d/%s()!\n", __FILE__, |
| 756 | __LINE__, __func__); |
| 757 | ret = -ENOMEM; |
| 758 | mpt3sas_base_free_smid(ioc, smid); |
| 759 | goto out; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | psge = (void *)request + (karg.data_sge_offset*4); |
| 764 | |
| 765 | /* send command to firmware */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 766 | _ctl_display_some_debug(ioc, smid, "ctl_request", NULL); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 767 | |
| 768 | init_completion(&ioc->ctl_cmds.done); |
| 769 | switch (mpi_request->Function) { |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 770 | case MPI2_FUNCTION_NVME_ENCAPSULATED: |
| 771 | { |
| 772 | nvme_encap_request = (Mpi26NVMeEncapsulatedRequest_t *)request; |
| 773 | /* |
| 774 | * Get the Physical Address of the sense buffer. |
| 775 | * Use Error Response buffer address field to hold the sense |
| 776 | * buffer address. |
| 777 | * Clear the internal sense buffer, which will potentially hold |
| 778 | * the Completion Queue Entry on return, or 0 if no Entry. |
| 779 | * Build the PRPs and set direction bits. |
| 780 | * Send the request. |
| 781 | */ |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 782 | nvme_encap_request->ErrorResponseBaseAddress = |
| 783 | cpu_to_le64(ioc->sense_dma & 0xFFFFFFFF00000000UL); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 784 | nvme_encap_request->ErrorResponseBaseAddress |= |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 785 | cpu_to_le64(le32_to_cpu( |
| 786 | mpt3sas_base_get_sense_buffer_dma(ioc, smid))); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 787 | nvme_encap_request->ErrorResponseAllocationLength = |
Chaitra P B | cf6bf97 | 2018-04-24 05:28:30 -0400 | [diff] [blame] | 788 | cpu_to_le16(NVME_ERROR_RESPONSE_SIZE); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 789 | memset(ioc->ctl_cmds.sense, 0, NVME_ERROR_RESPONSE_SIZE); |
| 790 | ioc->build_nvme_prp(ioc, smid, nvme_encap_request, |
| 791 | data_out_dma, data_out_sz, data_in_dma, data_in_sz); |
| 792 | if (test_bit(device_handle, ioc->device_remove_in_progress)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 793 | dtmprintk(ioc, |
| 794 | ioc_info(ioc, "handle(0x%04x): ioctl failed due to device removal in progress\n", |
| 795 | device_handle)); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 796 | mpt3sas_base_free_smid(ioc, smid); |
| 797 | ret = -EINVAL; |
| 798 | goto out; |
| 799 | } |
Suganath Prabu S | 40114bd | 2018-02-14 02:16:37 -0800 | [diff] [blame] | 800 | mpt3sas_base_put_smid_nvme_encap(ioc, smid); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 801 | break; |
| 802 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 803 | case MPI2_FUNCTION_SCSI_IO_REQUEST: |
| 804 | case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: |
| 805 | { |
| 806 | Mpi2SCSIIORequest_t *scsiio_request = |
| 807 | (Mpi2SCSIIORequest_t *)request; |
| 808 | scsiio_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE; |
| 809 | scsiio_request->SenseBufferLowAddress = |
| 810 | mpt3sas_base_get_sense_buffer_dma(ioc, smid); |
| 811 | memset(ioc->ctl_cmds.sense, 0, SCSI_SENSE_BUFFERSIZE); |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 812 | if (test_bit(device_handle, ioc->device_remove_in_progress)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 813 | dtmprintk(ioc, |
| 814 | ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n", |
| 815 | device_handle)); |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 816 | mpt3sas_base_free_smid(ioc, smid); |
| 817 | ret = -EINVAL; |
| 818 | goto out; |
| 819 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 820 | ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, |
| 821 | data_in_dma, data_in_sz); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 822 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST) |
Suganath Prabu Subramani | 81c16f8 | 2016-10-26 13:34:40 +0530 | [diff] [blame] | 823 | ioc->put_smid_scsi_io(ioc, smid, device_handle); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 824 | else |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 825 | ioc->put_smid_default(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 826 | break; |
| 827 | } |
| 828 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 829 | { |
| 830 | Mpi2SCSITaskManagementRequest_t *tm_request = |
| 831 | (Mpi2SCSITaskManagementRequest_t *)request; |
| 832 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 833 | dtmprintk(ioc, |
| 834 | ioc_info(ioc, "TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n", |
| 835 | le16_to_cpu(tm_request->DevHandle), |
| 836 | tm_request->TaskType)); |
Chaitra P B | 459325c | 2017-01-23 15:26:08 +0530 | [diff] [blame] | 837 | ioc->got_task_abort_from_ioctl = 1; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 838 | if (tm_request->TaskType == |
| 839 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK || |
| 840 | tm_request->TaskType == |
| 841 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) { |
| 842 | if (_ctl_set_task_mid(ioc, &karg, tm_request)) { |
| 843 | mpt3sas_base_free_smid(ioc, smid); |
Chaitra P B | 459325c | 2017-01-23 15:26:08 +0530 | [diff] [blame] | 844 | ioc->got_task_abort_from_ioctl = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 845 | goto out; |
| 846 | } |
| 847 | } |
Chaitra P B | 459325c | 2017-01-23 15:26:08 +0530 | [diff] [blame] | 848 | ioc->got_task_abort_from_ioctl = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 849 | |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 850 | if (test_bit(device_handle, ioc->device_remove_in_progress)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 851 | dtmprintk(ioc, |
| 852 | ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n", |
| 853 | device_handle)); |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 854 | mpt3sas_base_free_smid(ioc, smid); |
| 855 | ret = -EINVAL; |
| 856 | goto out; |
| 857 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 858 | mpt3sas_scsih_set_tm_flag(ioc, le16_to_cpu( |
| 859 | tm_request->DevHandle)); |
| 860 | ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz, |
| 861 | data_in_dma, data_in_sz); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 862 | ioc->put_smid_hi_priority(ioc, smid, 0); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 863 | break; |
| 864 | } |
| 865 | case MPI2_FUNCTION_SMP_PASSTHROUGH: |
| 866 | { |
| 867 | Mpi2SmpPassthroughRequest_t *smp_request = |
| 868 | (Mpi2SmpPassthroughRequest_t *)mpi_request; |
| 869 | u8 *data; |
| 870 | |
| 871 | /* ioc determines which port to use */ |
| 872 | smp_request->PhysicalPort = 0xFF; |
| 873 | if (smp_request->PassthroughFlags & |
| 874 | MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE) |
| 875 | data = (u8 *)&smp_request->SGL; |
| 876 | else { |
| 877 | if (unlikely(data_out == NULL)) { |
| 878 | pr_err("failure at %s:%d/%s()!\n", |
| 879 | __FILE__, __LINE__, __func__); |
| 880 | mpt3sas_base_free_smid(ioc, smid); |
| 881 | ret = -EINVAL; |
| 882 | goto out; |
| 883 | } |
| 884 | data = data_out; |
| 885 | } |
| 886 | |
| 887 | if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) { |
| 888 | ioc->ioc_link_reset_in_progress = 1; |
| 889 | ioc->ignore_loginfos = 1; |
| 890 | } |
| 891 | ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma, |
| 892 | data_in_sz); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 893 | ioc->put_smid_default(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 894 | break; |
| 895 | } |
| 896 | case MPI2_FUNCTION_SATA_PASSTHROUGH: |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 897 | { |
| 898 | if (test_bit(device_handle, ioc->device_remove_in_progress)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 899 | dtmprintk(ioc, |
| 900 | ioc_info(ioc, "handle(0x%04x) :ioctl failed due to device removal in progress\n", |
| 901 | device_handle)); |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 902 | mpt3sas_base_free_smid(ioc, smid); |
| 903 | ret = -EINVAL; |
| 904 | goto out; |
| 905 | } |
| 906 | ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma, |
| 907 | data_in_sz); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 908 | ioc->put_smid_default(ioc, smid); |
Suganath Prabu Subramani | c696f7b | 2016-10-26 13:34:34 +0530 | [diff] [blame] | 909 | break; |
| 910 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 911 | case MPI2_FUNCTION_FW_DOWNLOAD: |
| 912 | case MPI2_FUNCTION_FW_UPLOAD: |
| 913 | { |
| 914 | ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, data_in_dma, |
| 915 | data_in_sz); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 916 | ioc->put_smid_default(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 917 | break; |
| 918 | } |
| 919 | case MPI2_FUNCTION_TOOLBOX: |
| 920 | { |
| 921 | Mpi2ToolboxCleanRequest_t *toolbox_request = |
| 922 | (Mpi2ToolboxCleanRequest_t *)mpi_request; |
| 923 | |
| 924 | if (toolbox_request->Tool == MPI2_TOOLBOX_DIAGNOSTIC_CLI_TOOL) { |
| 925 | ioc->build_sg(ioc, psge, data_out_dma, data_out_sz, |
| 926 | data_in_dma, data_in_sz); |
| 927 | } else { |
| 928 | ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz, |
| 929 | data_in_dma, data_in_sz); |
| 930 | } |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 931 | ioc->put_smid_default(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 932 | break; |
| 933 | } |
| 934 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: |
| 935 | { |
| 936 | Mpi2SasIoUnitControlRequest_t *sasiounit_request = |
| 937 | (Mpi2SasIoUnitControlRequest_t *)mpi_request; |
| 938 | |
| 939 | if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET |
| 940 | || sasiounit_request->Operation == |
| 941 | MPI2_SAS_OP_PHY_LINK_RESET) { |
| 942 | ioc->ioc_link_reset_in_progress = 1; |
| 943 | ioc->ignore_loginfos = 1; |
| 944 | } |
| 945 | /* drop to default case for posting the request */ |
| 946 | } |
Bart Van Assche | eb0c7af | 2018-06-15 14:41:56 -0700 | [diff] [blame] | 947 | /* fall through */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 948 | default: |
| 949 | ioc->build_sg_mpi(ioc, psge, data_out_dma, data_out_sz, |
| 950 | data_in_dma, data_in_sz); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 951 | ioc->put_smid_default(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 952 | break; |
| 953 | } |
| 954 | |
| 955 | if (karg.timeout < MPT3_IOCTL_DEFAULT_TIMEOUT) |
| 956 | timeout = MPT3_IOCTL_DEFAULT_TIMEOUT; |
| 957 | else |
| 958 | timeout = karg.timeout; |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 959 | wait_for_completion_timeout(&ioc->ctl_cmds.done, timeout*HZ); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 960 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) { |
| 961 | Mpi2SCSITaskManagementRequest_t *tm_request = |
| 962 | (Mpi2SCSITaskManagementRequest_t *)mpi_request; |
| 963 | mpt3sas_scsih_clear_tm_flag(ioc, le16_to_cpu( |
| 964 | tm_request->DevHandle)); |
| 965 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_TASK_MANAGMENT); |
| 966 | } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH || |
| 967 | mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) && |
| 968 | ioc->ioc_link_reset_in_progress) { |
| 969 | ioc->ioc_link_reset_in_progress = 0; |
| 970 | ioc->ignore_loginfos = 0; |
| 971 | } |
| 972 | if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) { |
Chaitra P B | d37306c | 2018-05-31 06:34:50 -0400 | [diff] [blame] | 973 | issue_reset = |
| 974 | mpt3sas_base_check_cmd_timeout(ioc, |
| 975 | ioc->ctl_cmds.status, mpi_request, |
| 976 | karg.data_sge_offset); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 977 | goto issue_host_reset; |
| 978 | } |
| 979 | |
| 980 | mpi_reply = ioc->ctl_cmds.reply; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 981 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 982 | if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT && |
| 983 | (ioc->logging_level & MPT_DEBUG_TM)) { |
| 984 | Mpi2SCSITaskManagementReply_t *tm_reply = |
| 985 | (Mpi2SCSITaskManagementReply_t *)mpi_reply; |
| 986 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 987 | ioc_info(ioc, "TASK_MGMT: IOCStatus(0x%04x), IOCLogInfo(0x%08x), TerminationCount(0x%08x)\n", |
| 988 | le16_to_cpu(tm_reply->IOCStatus), |
| 989 | le32_to_cpu(tm_reply->IOCLogInfo), |
| 990 | le32_to_cpu(tm_reply->TerminationCount)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 991 | } |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 992 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 993 | /* copy out xdata to user */ |
| 994 | if (data_in_sz) { |
| 995 | if (copy_to_user(karg.data_in_buf_ptr, data_in, |
| 996 | data_in_sz)) { |
| 997 | pr_err("failure at %s:%d/%s()!\n", __FILE__, |
| 998 | __LINE__, __func__); |
| 999 | ret = -ENODATA; |
| 1000 | goto out; |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | /* copy out reply message frame to user */ |
| 1005 | if (karg.max_reply_bytes) { |
| 1006 | sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz); |
| 1007 | if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply, |
| 1008 | sz)) { |
| 1009 | pr_err("failure at %s:%d/%s()!\n", __FILE__, |
| 1010 | __LINE__, __func__); |
| 1011 | ret = -ENODATA; |
| 1012 | goto out; |
| 1013 | } |
| 1014 | } |
| 1015 | |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1016 | /* copy out sense/NVMe Error Response to user */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1017 | if (karg.max_sense_bytes && (mpi_request->Function == |
| 1018 | MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function == |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1019 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || mpi_request->Function == |
| 1020 | MPI2_FUNCTION_NVME_ENCAPSULATED)) { |
| 1021 | if (karg.sense_data_ptr == NULL) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1022 | ioc_info(ioc, "Response buffer provided by application is NULL; Response data will not be returned\n"); |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1023 | goto out; |
| 1024 | } |
| 1025 | sz_arg = (mpi_request->Function == |
| 1026 | MPI2_FUNCTION_NVME_ENCAPSULATED) ? NVME_ERROR_RESPONSE_SIZE : |
| 1027 | SCSI_SENSE_BUFFERSIZE; |
| 1028 | sz = min_t(u32, karg.max_sense_bytes, sz_arg); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1029 | if (copy_to_user(karg.sense_data_ptr, ioc->ctl_cmds.sense, |
| 1030 | sz)) { |
| 1031 | pr_err("failure at %s:%d/%s()!\n", __FILE__, |
Suganath Prabu Subramani | aff39e6 | 2017-10-31 18:02:29 +0530 | [diff] [blame] | 1032 | __LINE__, __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1033 | ret = -ENODATA; |
| 1034 | goto out; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | issue_host_reset: |
| 1039 | if (issue_reset) { |
| 1040 | ret = -ENODATA; |
| 1041 | if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 1042 | mpi_request->Function == |
| 1043 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || |
| 1044 | mpi_request->Function == MPI2_FUNCTION_SATA_PASSTHROUGH)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1045 | ioc_info(ioc, "issue target reset: handle = (0x%04x)\n", |
| 1046 | le16_to_cpu(mpi_request->FunctionDependent1)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1047 | mpt3sas_halt_firmware(ioc); |
Chaitra P B | c1a6c5a | 2018-04-24 05:28:41 -0400 | [diff] [blame] | 1048 | pcie_device = mpt3sas_get_pdev_by_handle(ioc, |
| 1049 | le16_to_cpu(mpi_request->FunctionDependent1)); |
| 1050 | if (pcie_device && (!ioc->tm_custom_handling)) |
| 1051 | mpt3sas_scsih_issue_locked_tm(ioc, |
| 1052 | le16_to_cpu(mpi_request->FunctionDependent1), |
| 1053 | 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
| 1054 | 0, pcie_device->reset_timeout, |
| 1055 | tr_method); |
| 1056 | else |
| 1057 | mpt3sas_scsih_issue_locked_tm(ioc, |
| 1058 | le16_to_cpu(mpi_request->FunctionDependent1), |
| 1059 | 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, |
| 1060 | 0, 30, MPI2_SCSITASKMGMT_MSGFLAGS_LINK_RESET); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1061 | } else |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 1062 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | out: |
Chaitra P B | c1a6c5a | 2018-04-24 05:28:41 -0400 | [diff] [blame] | 1066 | if (pcie_device) |
| 1067 | pcie_device_put(pcie_device); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1068 | |
| 1069 | /* free memory associated with sg buffers */ |
| 1070 | if (data_in) |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 1071 | dma_free_coherent(&ioc->pdev->dev, data_in_sz, data_in, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1072 | data_in_dma); |
| 1073 | |
| 1074 | if (data_out) |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 1075 | dma_free_coherent(&ioc->pdev->dev, data_out_sz, data_out, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1076 | data_out_dma); |
| 1077 | |
| 1078 | kfree(mpi_request); |
| 1079 | ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; |
| 1080 | return ret; |
| 1081 | } |
| 1082 | |
| 1083 | /** |
| 1084 | * _ctl_getiocinfo - main handler for MPT3IOCINFO opcode |
| 1085 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1086 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1087 | */ |
| 1088 | static long |
| 1089 | _ctl_getiocinfo(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1090 | { |
| 1091 | struct mpt3_ioctl_iocinfo karg; |
| 1092 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1093 | dctlprintk(ioc, ioc_info(ioc, "%s: enter\n", |
| 1094 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1095 | |
| 1096 | memset(&karg, 0 , sizeof(karg)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1097 | if (ioc->pfacts) |
| 1098 | karg.port_number = ioc->pfacts[0].PortNumber; |
| 1099 | karg.hw_rev = ioc->pdev->revision; |
| 1100 | karg.pci_id = ioc->pdev->device; |
| 1101 | karg.subsystem_device = ioc->pdev->subsystem_device; |
| 1102 | karg.subsystem_vendor = ioc->pdev->subsystem_vendor; |
| 1103 | karg.pci_information.u.bits.bus = ioc->pdev->bus->number; |
| 1104 | karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn); |
| 1105 | karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn); |
| 1106 | karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus); |
| 1107 | karg.firmware_version = ioc->facts.FWVersion.Word; |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 1108 | strcpy(karg.driver_version, ioc->driver_name); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1109 | strcat(karg.driver_version, "-"); |
Sreekanth Reddy | d357e84 | 2015-11-11 17:30:22 +0530 | [diff] [blame] | 1110 | switch (ioc->hba_mpi_version_belonged) { |
| 1111 | case MPI2_VERSION: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1112 | if (ioc->is_warpdrive) |
| 1113 | karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2_SSS6200; |
| 1114 | else |
| 1115 | karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2; |
Sreekanth Reddy | d357e84 | 2015-11-11 17:30:22 +0530 | [diff] [blame] | 1116 | strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION); |
| 1117 | break; |
| 1118 | case MPI25_VERSION: |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 1119 | case MPI26_VERSION: |
Suganath Prabu Subramani | 998f26a | 2016-10-26 13:34:37 +0530 | [diff] [blame] | 1120 | if (ioc->is_gen35_ioc) |
| 1121 | karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS35; |
| 1122 | else |
| 1123 | karg.adapter_type = MPT3_IOCTL_INTERFACE_SAS3; |
Sreekanth Reddy | d357e84 | 2015-11-11 17:30:22 +0530 | [diff] [blame] | 1124 | strcat(karg.driver_version, MPT3SAS_DRIVER_VERSION); |
| 1125 | break; |
| 1126 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1127 | karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); |
| 1128 | |
| 1129 | if (copy_to_user(arg, &karg, sizeof(karg))) { |
| 1130 | pr_err("failure at %s:%d/%s()!\n", |
| 1131 | __FILE__, __LINE__, __func__); |
| 1132 | return -EFAULT; |
| 1133 | } |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
| 1137 | /** |
| 1138 | * _ctl_eventquery - main handler for MPT3EVENTQUERY opcode |
| 1139 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1140 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1141 | */ |
| 1142 | static long |
| 1143 | _ctl_eventquery(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1144 | { |
| 1145 | struct mpt3_ioctl_eventquery karg; |
| 1146 | |
| 1147 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1148 | pr_err("failure at %s:%d/%s()!\n", |
| 1149 | __FILE__, __LINE__, __func__); |
| 1150 | return -EFAULT; |
| 1151 | } |
| 1152 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1153 | dctlprintk(ioc, ioc_info(ioc, "%s: enter\n", |
| 1154 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1155 | |
| 1156 | karg.event_entries = MPT3SAS_CTL_EVENT_LOG_SIZE; |
| 1157 | memcpy(karg.event_types, ioc->event_type, |
| 1158 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32)); |
| 1159 | |
| 1160 | if (copy_to_user(arg, &karg, sizeof(karg))) { |
| 1161 | pr_err("failure at %s:%d/%s()!\n", |
| 1162 | __FILE__, __LINE__, __func__); |
| 1163 | return -EFAULT; |
| 1164 | } |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * _ctl_eventenable - main handler for MPT3EVENTENABLE opcode |
| 1170 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1171 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1172 | */ |
| 1173 | static long |
| 1174 | _ctl_eventenable(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1175 | { |
| 1176 | struct mpt3_ioctl_eventenable karg; |
| 1177 | |
| 1178 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1179 | pr_err("failure at %s:%d/%s()!\n", |
| 1180 | __FILE__, __LINE__, __func__); |
| 1181 | return -EFAULT; |
| 1182 | } |
| 1183 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1184 | dctlprintk(ioc, ioc_info(ioc, "%s: enter\n", |
| 1185 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1186 | |
| 1187 | memcpy(ioc->event_type, karg.event_types, |
| 1188 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32)); |
| 1189 | mpt3sas_base_validate_event_type(ioc, ioc->event_type); |
| 1190 | |
| 1191 | if (ioc->event_log) |
| 1192 | return 0; |
| 1193 | /* initialize event_log */ |
| 1194 | ioc->event_context = 0; |
| 1195 | ioc->aen_event_read_flag = 0; |
| 1196 | ioc->event_log = kcalloc(MPT3SAS_CTL_EVENT_LOG_SIZE, |
| 1197 | sizeof(struct MPT3_IOCTL_EVENTS), GFP_KERNEL); |
| 1198 | if (!ioc->event_log) { |
| 1199 | pr_err("failure at %s:%d/%s()!\n", |
| 1200 | __FILE__, __LINE__, __func__); |
| 1201 | return -ENOMEM; |
| 1202 | } |
| 1203 | return 0; |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * _ctl_eventreport - main handler for MPT3EVENTREPORT opcode |
| 1208 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1209 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1210 | */ |
| 1211 | static long |
| 1212 | _ctl_eventreport(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1213 | { |
| 1214 | struct mpt3_ioctl_eventreport karg; |
| 1215 | u32 number_bytes, max_events, max; |
| 1216 | struct mpt3_ioctl_eventreport __user *uarg = arg; |
| 1217 | |
| 1218 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1219 | pr_err("failure at %s:%d/%s()!\n", |
| 1220 | __FILE__, __LINE__, __func__); |
| 1221 | return -EFAULT; |
| 1222 | } |
| 1223 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1224 | dctlprintk(ioc, ioc_info(ioc, "%s: enter\n", |
| 1225 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1226 | |
| 1227 | number_bytes = karg.hdr.max_data_size - |
| 1228 | sizeof(struct mpt3_ioctl_header); |
| 1229 | max_events = number_bytes/sizeof(struct MPT3_IOCTL_EVENTS); |
| 1230 | max = min_t(u32, MPT3SAS_CTL_EVENT_LOG_SIZE, max_events); |
| 1231 | |
| 1232 | /* If fewer than 1 event is requested, there must have |
| 1233 | * been some type of error. |
| 1234 | */ |
| 1235 | if (!max || !ioc->event_log) |
| 1236 | return -ENODATA; |
| 1237 | |
| 1238 | number_bytes = max * sizeof(struct MPT3_IOCTL_EVENTS); |
| 1239 | if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) { |
| 1240 | pr_err("failure at %s:%d/%s()!\n", |
| 1241 | __FILE__, __LINE__, __func__); |
| 1242 | return -EFAULT; |
| 1243 | } |
| 1244 | |
| 1245 | /* reset flag so SIGIO can restart */ |
| 1246 | ioc->aen_event_read_flag = 0; |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
| 1250 | /** |
| 1251 | * _ctl_do_reset - main handler for MPT3HARDRESET opcode |
| 1252 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1253 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1254 | */ |
| 1255 | static long |
| 1256 | _ctl_do_reset(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1257 | { |
| 1258 | struct mpt3_ioctl_diag_reset karg; |
| 1259 | int retval; |
| 1260 | |
| 1261 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1262 | pr_err("failure at %s:%d/%s()!\n", |
| 1263 | __FILE__, __LINE__, __func__); |
| 1264 | return -EFAULT; |
| 1265 | } |
| 1266 | |
| 1267 | if (ioc->shost_recovery || ioc->pci_error_recovery || |
| 1268 | ioc->is_driver_loading) |
| 1269 | return -EAGAIN; |
| 1270 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1271 | dctlprintk(ioc, ioc_info(ioc, "%s: enter\n", |
| 1272 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1273 | |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 1274 | retval = mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1275 | ioc_info(ioc, "host reset: %s\n", ((!retval) ? "SUCCESS" : "FAILED")); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1276 | return 0; |
| 1277 | } |
| 1278 | |
| 1279 | /** |
| 1280 | * _ctl_btdh_search_sas_device - searching for sas device |
| 1281 | * @ioc: per adapter object |
| 1282 | * @btdh: btdh ioctl payload |
| 1283 | */ |
| 1284 | static int |
| 1285 | _ctl_btdh_search_sas_device(struct MPT3SAS_ADAPTER *ioc, |
| 1286 | struct mpt3_ioctl_btdh_mapping *btdh) |
| 1287 | { |
| 1288 | struct _sas_device *sas_device; |
| 1289 | unsigned long flags; |
| 1290 | int rc = 0; |
| 1291 | |
| 1292 | if (list_empty(&ioc->sas_device_list)) |
| 1293 | return rc; |
| 1294 | |
| 1295 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1296 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 1297 | if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF && |
| 1298 | btdh->handle == sas_device->handle) { |
| 1299 | btdh->bus = sas_device->channel; |
| 1300 | btdh->id = sas_device->id; |
| 1301 | rc = 1; |
| 1302 | goto out; |
| 1303 | } else if (btdh->bus == sas_device->channel && btdh->id == |
| 1304 | sas_device->id && btdh->handle == 0xFFFF) { |
| 1305 | btdh->handle = sas_device->handle; |
| 1306 | rc = 1; |
| 1307 | goto out; |
| 1308 | } |
| 1309 | } |
| 1310 | out: |
| 1311 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1312 | return rc; |
| 1313 | } |
| 1314 | |
| 1315 | /** |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 1316 | * _ctl_btdh_search_pcie_device - searching for pcie device |
| 1317 | * @ioc: per adapter object |
| 1318 | * @btdh: btdh ioctl payload |
| 1319 | */ |
| 1320 | static int |
| 1321 | _ctl_btdh_search_pcie_device(struct MPT3SAS_ADAPTER *ioc, |
| 1322 | struct mpt3_ioctl_btdh_mapping *btdh) |
| 1323 | { |
| 1324 | struct _pcie_device *pcie_device; |
| 1325 | unsigned long flags; |
| 1326 | int rc = 0; |
| 1327 | |
| 1328 | if (list_empty(&ioc->pcie_device_list)) |
| 1329 | return rc; |
| 1330 | |
| 1331 | spin_lock_irqsave(&ioc->pcie_device_lock, flags); |
| 1332 | list_for_each_entry(pcie_device, &ioc->pcie_device_list, list) { |
| 1333 | if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF && |
| 1334 | btdh->handle == pcie_device->handle) { |
| 1335 | btdh->bus = pcie_device->channel; |
| 1336 | btdh->id = pcie_device->id; |
| 1337 | rc = 1; |
| 1338 | goto out; |
| 1339 | } else if (btdh->bus == pcie_device->channel && btdh->id == |
| 1340 | pcie_device->id && btdh->handle == 0xFFFF) { |
| 1341 | btdh->handle = pcie_device->handle; |
| 1342 | rc = 1; |
| 1343 | goto out; |
| 1344 | } |
| 1345 | } |
| 1346 | out: |
| 1347 | spin_unlock_irqrestore(&ioc->pcie_device_lock, flags); |
| 1348 | return rc; |
| 1349 | } |
| 1350 | |
| 1351 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1352 | * _ctl_btdh_search_raid_device - searching for raid device |
| 1353 | * @ioc: per adapter object |
| 1354 | * @btdh: btdh ioctl payload |
| 1355 | */ |
| 1356 | static int |
| 1357 | _ctl_btdh_search_raid_device(struct MPT3SAS_ADAPTER *ioc, |
| 1358 | struct mpt3_ioctl_btdh_mapping *btdh) |
| 1359 | { |
| 1360 | struct _raid_device *raid_device; |
| 1361 | unsigned long flags; |
| 1362 | int rc = 0; |
| 1363 | |
| 1364 | if (list_empty(&ioc->raid_device_list)) |
| 1365 | return rc; |
| 1366 | |
| 1367 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1368 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 1369 | if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF && |
| 1370 | btdh->handle == raid_device->handle) { |
| 1371 | btdh->bus = raid_device->channel; |
| 1372 | btdh->id = raid_device->id; |
| 1373 | rc = 1; |
| 1374 | goto out; |
| 1375 | } else if (btdh->bus == raid_device->channel && btdh->id == |
| 1376 | raid_device->id && btdh->handle == 0xFFFF) { |
| 1377 | btdh->handle = raid_device->handle; |
| 1378 | rc = 1; |
| 1379 | goto out; |
| 1380 | } |
| 1381 | } |
| 1382 | out: |
| 1383 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1384 | return rc; |
| 1385 | } |
| 1386 | |
| 1387 | /** |
| 1388 | * _ctl_btdh_mapping - main handler for MPT3BTDHMAPPING opcode |
| 1389 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1390 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1391 | */ |
| 1392 | static long |
| 1393 | _ctl_btdh_mapping(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1394 | { |
| 1395 | struct mpt3_ioctl_btdh_mapping karg; |
| 1396 | int rc; |
| 1397 | |
| 1398 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1399 | pr_err("failure at %s:%d/%s()!\n", |
| 1400 | __FILE__, __LINE__, __func__); |
| 1401 | return -EFAULT; |
| 1402 | } |
| 1403 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1404 | dctlprintk(ioc, ioc_info(ioc, "%s\n", |
| 1405 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1406 | |
| 1407 | rc = _ctl_btdh_search_sas_device(ioc, &karg); |
| 1408 | if (!rc) |
Suganath Prabu Subramani | 45aa6a1 | 2017-10-31 18:02:36 +0530 | [diff] [blame] | 1409 | rc = _ctl_btdh_search_pcie_device(ioc, &karg); |
| 1410 | if (!rc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1411 | _ctl_btdh_search_raid_device(ioc, &karg); |
| 1412 | |
| 1413 | if (copy_to_user(arg, &karg, sizeof(karg))) { |
| 1414 | pr_err("failure at %s:%d/%s()!\n", |
| 1415 | __FILE__, __LINE__, __func__); |
| 1416 | return -EFAULT; |
| 1417 | } |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | /** |
| 1422 | * _ctl_diag_capability - return diag buffer capability |
| 1423 | * @ioc: per adapter object |
| 1424 | * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED |
| 1425 | * |
| 1426 | * returns 1 when diag buffer support is enabled in firmware |
| 1427 | */ |
| 1428 | static u8 |
| 1429 | _ctl_diag_capability(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type) |
| 1430 | { |
| 1431 | u8 rc = 0; |
| 1432 | |
| 1433 | switch (buffer_type) { |
| 1434 | case MPI2_DIAG_BUF_TYPE_TRACE: |
| 1435 | if (ioc->facts.IOCCapabilities & |
| 1436 | MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) |
| 1437 | rc = 1; |
| 1438 | break; |
| 1439 | case MPI2_DIAG_BUF_TYPE_SNAPSHOT: |
| 1440 | if (ioc->facts.IOCCapabilities & |
| 1441 | MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) |
| 1442 | rc = 1; |
| 1443 | break; |
| 1444 | case MPI2_DIAG_BUF_TYPE_EXTENDED: |
| 1445 | if (ioc->facts.IOCCapabilities & |
| 1446 | MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) |
| 1447 | rc = 1; |
| 1448 | } |
| 1449 | |
| 1450 | return rc; |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | /** |
| 1455 | * _ctl_diag_register_2 - wrapper for registering diag buffer support |
| 1456 | * @ioc: per adapter object |
| 1457 | * @diag_register: the diag_register struct passed in from user space |
| 1458 | * |
| 1459 | */ |
| 1460 | static long |
| 1461 | _ctl_diag_register_2(struct MPT3SAS_ADAPTER *ioc, |
| 1462 | struct mpt3_diag_register *diag_register) |
| 1463 | { |
| 1464 | int rc, i; |
| 1465 | void *request_data = NULL; |
| 1466 | dma_addr_t request_data_dma; |
| 1467 | u32 request_data_sz = 0; |
| 1468 | Mpi2DiagBufferPostRequest_t *mpi_request; |
| 1469 | Mpi2DiagBufferPostReply_t *mpi_reply; |
| 1470 | u8 buffer_type; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1471 | u16 smid; |
| 1472 | u16 ioc_status; |
| 1473 | u32 ioc_state; |
| 1474 | u8 issue_reset = 0; |
| 1475 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1476 | dctlprintk(ioc, ioc_info(ioc, "%s\n", |
| 1477 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1478 | |
| 1479 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 1480 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1481 | ioc_err(ioc, "%s: failed due to ioc not operational\n", |
| 1482 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1483 | rc = -EAGAIN; |
| 1484 | goto out; |
| 1485 | } |
| 1486 | |
| 1487 | if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1488 | ioc_err(ioc, "%s: ctl_cmd in use\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1489 | rc = -EAGAIN; |
| 1490 | goto out; |
| 1491 | } |
| 1492 | |
| 1493 | buffer_type = diag_register->buffer_type; |
| 1494 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1495 | ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n", |
| 1496 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1497 | return -EPERM; |
| 1498 | } |
| 1499 | |
| 1500 | if (ioc->diag_buffer_status[buffer_type] & |
| 1501 | MPT3_DIAG_BUFFER_IS_REGISTERED) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1502 | ioc_err(ioc, "%s: already has a registered buffer for buffer_type(0x%02x)\n", |
| 1503 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1504 | return -EINVAL; |
| 1505 | } |
| 1506 | |
| 1507 | if (diag_register->requested_buffer_size % 4) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1508 | ioc_err(ioc, "%s: the requested_buffer_size is not 4 byte aligned\n", |
| 1509 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1510 | return -EINVAL; |
| 1511 | } |
| 1512 | |
| 1513 | smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx); |
| 1514 | if (!smid) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1515 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1516 | rc = -EAGAIN; |
| 1517 | goto out; |
| 1518 | } |
| 1519 | |
| 1520 | rc = 0; |
| 1521 | ioc->ctl_cmds.status = MPT3_CMD_PENDING; |
| 1522 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 1523 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 1524 | ioc->ctl_cmds.smid = smid; |
| 1525 | |
| 1526 | request_data = ioc->diag_buffer[buffer_type]; |
| 1527 | request_data_sz = diag_register->requested_buffer_size; |
| 1528 | ioc->unique_id[buffer_type] = diag_register->unique_id; |
| 1529 | ioc->diag_buffer_status[buffer_type] = 0; |
| 1530 | memcpy(ioc->product_specific[buffer_type], |
| 1531 | diag_register->product_specific, MPT3_PRODUCT_SPECIFIC_DWORDS); |
| 1532 | ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags; |
| 1533 | |
| 1534 | if (request_data) { |
| 1535 | request_data_dma = ioc->diag_buffer_dma[buffer_type]; |
| 1536 | if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) { |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 1537 | dma_free_coherent(&ioc->pdev->dev, |
| 1538 | ioc->diag_buffer_sz[buffer_type], |
| 1539 | request_data, request_data_dma); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1540 | request_data = NULL; |
| 1541 | } |
| 1542 | } |
| 1543 | |
| 1544 | if (request_data == NULL) { |
| 1545 | ioc->diag_buffer_sz[buffer_type] = 0; |
| 1546 | ioc->diag_buffer_dma[buffer_type] = 0; |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 1547 | request_data = dma_alloc_coherent(&ioc->pdev->dev, |
| 1548 | request_data_sz, &request_data_dma, GFP_KERNEL); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1549 | if (request_data == NULL) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1550 | ioc_err(ioc, "%s: failed allocating memory for diag buffers, requested size(%d)\n", |
| 1551 | __func__, request_data_sz); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1552 | mpt3sas_base_free_smid(ioc, smid); |
| 1553 | return -ENOMEM; |
| 1554 | } |
| 1555 | ioc->diag_buffer[buffer_type] = request_data; |
| 1556 | ioc->diag_buffer_sz[buffer_type] = request_data_sz; |
| 1557 | ioc->diag_buffer_dma[buffer_type] = request_data_dma; |
| 1558 | } |
| 1559 | |
| 1560 | mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST; |
| 1561 | mpi_request->BufferType = diag_register->buffer_type; |
| 1562 | mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags); |
| 1563 | mpi_request->BufferAddress = cpu_to_le64(request_data_dma); |
| 1564 | mpi_request->BufferLength = cpu_to_le32(request_data_sz); |
| 1565 | mpi_request->VF_ID = 0; /* TODO */ |
| 1566 | mpi_request->VP_ID = 0; |
| 1567 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1568 | dctlprintk(ioc, |
| 1569 | ioc_info(ioc, "%s: diag_buffer(0x%p), dma(0x%llx), sz(%d)\n", |
| 1570 | __func__, request_data, |
| 1571 | (unsigned long long)request_data_dma, |
| 1572 | le32_to_cpu(mpi_request->BufferLength))); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1573 | |
| 1574 | for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++) |
| 1575 | mpi_request->ProductSpecific[i] = |
| 1576 | cpu_to_le32(ioc->product_specific[buffer_type][i]); |
| 1577 | |
| 1578 | init_completion(&ioc->ctl_cmds.done); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 1579 | ioc->put_smid_default(ioc, smid); |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 1580 | wait_for_completion_timeout(&ioc->ctl_cmds.done, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1581 | MPT3_IOCTL_DEFAULT_TIMEOUT*HZ); |
| 1582 | |
| 1583 | if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) { |
Chaitra P B | d37306c | 2018-05-31 06:34:50 -0400 | [diff] [blame] | 1584 | issue_reset = |
| 1585 | mpt3sas_base_check_cmd_timeout(ioc, |
| 1586 | ioc->ctl_cmds.status, mpi_request, |
| 1587 | sizeof(Mpi2DiagBufferPostRequest_t)/4); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1588 | goto issue_host_reset; |
| 1589 | } |
| 1590 | |
| 1591 | /* process the completed Reply Message Frame */ |
| 1592 | if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1593 | ioc_err(ioc, "%s: no reply message\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1594 | rc = -EFAULT; |
| 1595 | goto out; |
| 1596 | } |
| 1597 | |
| 1598 | mpi_reply = ioc->ctl_cmds.reply; |
| 1599 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 1600 | |
| 1601 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 1602 | ioc->diag_buffer_status[buffer_type] |= |
| 1603 | MPT3_DIAG_BUFFER_IS_REGISTERED; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1604 | dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1605 | } else { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1606 | ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n", |
| 1607 | __func__, |
| 1608 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1609 | rc = -EFAULT; |
| 1610 | } |
| 1611 | |
| 1612 | issue_host_reset: |
| 1613 | if (issue_reset) |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 1614 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1615 | |
| 1616 | out: |
| 1617 | |
| 1618 | if (rc && request_data) |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 1619 | dma_free_coherent(&ioc->pdev->dev, request_data_sz, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1620 | request_data, request_data_dma); |
| 1621 | |
| 1622 | ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; |
| 1623 | return rc; |
| 1624 | } |
| 1625 | |
| 1626 | /** |
| 1627 | * mpt3sas_enable_diag_buffer - enabling diag_buffers support driver load time |
| 1628 | * @ioc: per adapter object |
| 1629 | * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1 |
| 1630 | * |
| 1631 | * This is called when command line option diag_buffer_enable is enabled |
| 1632 | * at driver load time. |
| 1633 | */ |
| 1634 | void |
| 1635 | mpt3sas_enable_diag_buffer(struct MPT3SAS_ADAPTER *ioc, u8 bits_to_register) |
| 1636 | { |
| 1637 | struct mpt3_diag_register diag_register; |
| 1638 | |
| 1639 | memset(&diag_register, 0, sizeof(struct mpt3_diag_register)); |
| 1640 | |
| 1641 | if (bits_to_register & 1) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1642 | ioc_info(ioc, "registering trace buffer support\n"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1643 | ioc->diag_trigger_master.MasterData = |
| 1644 | (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET); |
| 1645 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE; |
| 1646 | /* register for 2MB buffers */ |
| 1647 | diag_register.requested_buffer_size = 2 * (1024 * 1024); |
| 1648 | diag_register.unique_id = 0x7075900; |
| 1649 | _ctl_diag_register_2(ioc, &diag_register); |
| 1650 | } |
| 1651 | |
| 1652 | if (bits_to_register & 2) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1653 | ioc_info(ioc, "registering snapshot buffer support\n"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1654 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT; |
| 1655 | /* register for 2MB buffers */ |
| 1656 | diag_register.requested_buffer_size = 2 * (1024 * 1024); |
| 1657 | diag_register.unique_id = 0x7075901; |
| 1658 | _ctl_diag_register_2(ioc, &diag_register); |
| 1659 | } |
| 1660 | |
| 1661 | if (bits_to_register & 4) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1662 | ioc_info(ioc, "registering extended buffer support\n"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1663 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED; |
| 1664 | /* register for 2MB buffers */ |
| 1665 | diag_register.requested_buffer_size = 2 * (1024 * 1024); |
| 1666 | diag_register.unique_id = 0x7075901; |
| 1667 | _ctl_diag_register_2(ioc, &diag_register); |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * _ctl_diag_register - application register with driver |
| 1673 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1674 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1675 | * |
| 1676 | * This will allow the driver to setup any required buffers that will be |
| 1677 | * needed by firmware to communicate with the driver. |
| 1678 | */ |
| 1679 | static long |
| 1680 | _ctl_diag_register(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1681 | { |
| 1682 | struct mpt3_diag_register karg; |
| 1683 | long rc; |
| 1684 | |
| 1685 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1686 | pr_err("failure at %s:%d/%s()!\n", |
| 1687 | __FILE__, __LINE__, __func__); |
| 1688 | return -EFAULT; |
| 1689 | } |
| 1690 | |
| 1691 | rc = _ctl_diag_register_2(ioc, &karg); |
| 1692 | return rc; |
| 1693 | } |
| 1694 | |
| 1695 | /** |
| 1696 | * _ctl_diag_unregister - application unregister with driver |
| 1697 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1698 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1699 | * |
| 1700 | * This will allow the driver to cleanup any memory allocated for diag |
| 1701 | * messages and to free up any resources. |
| 1702 | */ |
| 1703 | static long |
| 1704 | _ctl_diag_unregister(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1705 | { |
| 1706 | struct mpt3_diag_unregister karg; |
| 1707 | void *request_data; |
| 1708 | dma_addr_t request_data_dma; |
| 1709 | u32 request_data_sz; |
| 1710 | u8 buffer_type; |
| 1711 | |
| 1712 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1713 | pr_err("failure at %s:%d/%s()!\n", |
| 1714 | __FILE__, __LINE__, __func__); |
| 1715 | return -EFAULT; |
| 1716 | } |
| 1717 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1718 | dctlprintk(ioc, ioc_info(ioc, "%s\n", |
| 1719 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1720 | |
| 1721 | buffer_type = karg.unique_id & 0x000000ff; |
| 1722 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1723 | ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n", |
| 1724 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1725 | return -EPERM; |
| 1726 | } |
| 1727 | |
| 1728 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1729 | MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1730 | ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n", |
| 1731 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1732 | return -EINVAL; |
| 1733 | } |
| 1734 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1735 | MPT3_DIAG_BUFFER_IS_RELEASED) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1736 | ioc_err(ioc, "%s: buffer_type(0x%02x) has not been released\n", |
| 1737 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1738 | return -EINVAL; |
| 1739 | } |
| 1740 | |
| 1741 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1742 | ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n", |
| 1743 | __func__, karg.unique_id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1744 | return -EINVAL; |
| 1745 | } |
| 1746 | |
| 1747 | request_data = ioc->diag_buffer[buffer_type]; |
| 1748 | if (!request_data) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1749 | ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n", |
| 1750 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1751 | return -ENOMEM; |
| 1752 | } |
| 1753 | |
| 1754 | request_data_sz = ioc->diag_buffer_sz[buffer_type]; |
| 1755 | request_data_dma = ioc->diag_buffer_dma[buffer_type]; |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 1756 | dma_free_coherent(&ioc->pdev->dev, request_data_sz, |
| 1757 | request_data, request_data_dma); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1758 | ioc->diag_buffer[buffer_type] = NULL; |
| 1759 | ioc->diag_buffer_status[buffer_type] = 0; |
| 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | /** |
| 1764 | * _ctl_diag_query - query relevant info associated with diag buffers |
| 1765 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1766 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1767 | * |
| 1768 | * The application will send only buffer_type and unique_id. Driver will |
| 1769 | * inspect unique_id first, if valid, fill in all the info. If unique_id is |
| 1770 | * 0x00, the driver will return info specified by Buffer Type. |
| 1771 | */ |
| 1772 | static long |
| 1773 | _ctl_diag_query(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1774 | { |
| 1775 | struct mpt3_diag_query karg; |
| 1776 | void *request_data; |
| 1777 | int i; |
| 1778 | u8 buffer_type; |
| 1779 | |
| 1780 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1781 | pr_err("failure at %s:%d/%s()!\n", |
| 1782 | __FILE__, __LINE__, __func__); |
| 1783 | return -EFAULT; |
| 1784 | } |
| 1785 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1786 | dctlprintk(ioc, ioc_info(ioc, "%s\n", |
| 1787 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1788 | |
| 1789 | karg.application_flags = 0; |
| 1790 | buffer_type = karg.buffer_type; |
| 1791 | |
| 1792 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1793 | ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n", |
| 1794 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1795 | return -EPERM; |
| 1796 | } |
| 1797 | |
| 1798 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1799 | MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1800 | ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n", |
| 1801 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1802 | return -EINVAL; |
| 1803 | } |
| 1804 | |
| 1805 | if (karg.unique_id & 0xffffff00) { |
| 1806 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1807 | ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n", |
| 1808 | __func__, karg.unique_id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1809 | return -EINVAL; |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | request_data = ioc->diag_buffer[buffer_type]; |
| 1814 | if (!request_data) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1815 | ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n", |
| 1816 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1817 | return -ENOMEM; |
| 1818 | } |
| 1819 | |
| 1820 | if (ioc->diag_buffer_status[buffer_type] & MPT3_DIAG_BUFFER_IS_RELEASED) |
| 1821 | karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED | |
| 1822 | MPT3_APP_FLAGS_BUFFER_VALID); |
| 1823 | else |
| 1824 | karg.application_flags = (MPT3_APP_FLAGS_APP_OWNED | |
| 1825 | MPT3_APP_FLAGS_BUFFER_VALID | |
| 1826 | MPT3_APP_FLAGS_FW_BUFFER_ACCESS); |
| 1827 | |
| 1828 | for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++) |
| 1829 | karg.product_specific[i] = |
| 1830 | ioc->product_specific[buffer_type][i]; |
| 1831 | |
| 1832 | karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type]; |
| 1833 | karg.driver_added_buffer_size = 0; |
| 1834 | karg.unique_id = ioc->unique_id[buffer_type]; |
| 1835 | karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type]; |
| 1836 | |
| 1837 | if (copy_to_user(arg, &karg, sizeof(struct mpt3_diag_query))) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1838 | ioc_err(ioc, "%s: unable to write mpt3_diag_query data @ %p\n", |
| 1839 | __func__, arg); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1840 | return -EFAULT; |
| 1841 | } |
| 1842 | return 0; |
| 1843 | } |
| 1844 | |
| 1845 | /** |
| 1846 | * mpt3sas_send_diag_release - Diag Release Message |
| 1847 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1848 | * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED |
| 1849 | * @issue_reset: specifies whether host reset is required. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1850 | * |
| 1851 | */ |
| 1852 | int |
| 1853 | mpt3sas_send_diag_release(struct MPT3SAS_ADAPTER *ioc, u8 buffer_type, |
| 1854 | u8 *issue_reset) |
| 1855 | { |
| 1856 | Mpi2DiagReleaseRequest_t *mpi_request; |
| 1857 | Mpi2DiagReleaseReply_t *mpi_reply; |
| 1858 | u16 smid; |
| 1859 | u16 ioc_status; |
| 1860 | u32 ioc_state; |
| 1861 | int rc; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1862 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1863 | dctlprintk(ioc, ioc_info(ioc, "%s\n", |
| 1864 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1865 | |
| 1866 | rc = 0; |
| 1867 | *issue_reset = 0; |
| 1868 | |
| 1869 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 1870 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 1871 | if (ioc->diag_buffer_status[buffer_type] & |
| 1872 | MPT3_DIAG_BUFFER_IS_REGISTERED) |
| 1873 | ioc->diag_buffer_status[buffer_type] |= |
| 1874 | MPT3_DIAG_BUFFER_IS_RELEASED; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1875 | dctlprintk(ioc, |
| 1876 | ioc_info(ioc, "%s: skipping due to FAULT state\n", |
| 1877 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1878 | rc = -EAGAIN; |
| 1879 | goto out; |
| 1880 | } |
| 1881 | |
| 1882 | if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1883 | ioc_err(ioc, "%s: ctl_cmd in use\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1884 | rc = -EAGAIN; |
| 1885 | goto out; |
| 1886 | } |
| 1887 | |
| 1888 | smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx); |
| 1889 | if (!smid) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1890 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1891 | rc = -EAGAIN; |
| 1892 | goto out; |
| 1893 | } |
| 1894 | |
| 1895 | ioc->ctl_cmds.status = MPT3_CMD_PENDING; |
| 1896 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 1897 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 1898 | ioc->ctl_cmds.smid = smid; |
| 1899 | |
| 1900 | mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE; |
| 1901 | mpi_request->BufferType = buffer_type; |
| 1902 | mpi_request->VF_ID = 0; /* TODO */ |
| 1903 | mpi_request->VP_ID = 0; |
| 1904 | |
| 1905 | init_completion(&ioc->ctl_cmds.done); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 1906 | ioc->put_smid_default(ioc, smid); |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 1907 | wait_for_completion_timeout(&ioc->ctl_cmds.done, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1908 | MPT3_IOCTL_DEFAULT_TIMEOUT*HZ); |
| 1909 | |
| 1910 | if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) { |
Chaitra P B | d37306c | 2018-05-31 06:34:50 -0400 | [diff] [blame] | 1911 | *issue_reset = mpt3sas_base_check_cmd_timeout(ioc, |
| 1912 | ioc->ctl_cmds.status, mpi_request, |
| 1913 | sizeof(Mpi2DiagReleaseRequest_t)/4); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1914 | rc = -EFAULT; |
| 1915 | goto out; |
| 1916 | } |
| 1917 | |
| 1918 | /* process the completed Reply Message Frame */ |
| 1919 | if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1920 | ioc_err(ioc, "%s: no reply message\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1921 | rc = -EFAULT; |
| 1922 | goto out; |
| 1923 | } |
| 1924 | |
| 1925 | mpi_reply = ioc->ctl_cmds.reply; |
| 1926 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 1927 | |
| 1928 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 1929 | ioc->diag_buffer_status[buffer_type] |= |
| 1930 | MPT3_DIAG_BUFFER_IS_RELEASED; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1931 | dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1932 | } else { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1933 | ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n", |
| 1934 | __func__, |
| 1935 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1936 | rc = -EFAULT; |
| 1937 | } |
| 1938 | |
| 1939 | out: |
| 1940 | ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; |
| 1941 | return rc; |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * _ctl_diag_release - request to send Diag Release Message to firmware |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 1946 | * @ioc: ? |
| 1947 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1948 | * |
| 1949 | * This allows ownership of the specified buffer to returned to the driver, |
| 1950 | * allowing an application to read the buffer without fear that firmware is |
Masahiro Yamada | 9a284e5 | 2017-02-27 14:29:48 -0800 | [diff] [blame] | 1951 | * overwriting information in the buffer. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1952 | */ |
| 1953 | static long |
| 1954 | _ctl_diag_release(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 1955 | { |
| 1956 | struct mpt3_diag_release karg; |
| 1957 | void *request_data; |
| 1958 | int rc; |
| 1959 | u8 buffer_type; |
| 1960 | u8 issue_reset = 0; |
| 1961 | |
| 1962 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1963 | pr_err("failure at %s:%d/%s()!\n", |
| 1964 | __FILE__, __LINE__, __func__); |
| 1965 | return -EFAULT; |
| 1966 | } |
| 1967 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1968 | dctlprintk(ioc, ioc_info(ioc, "%s\n", |
| 1969 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1970 | |
| 1971 | buffer_type = karg.unique_id & 0x000000ff; |
| 1972 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1973 | ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n", |
| 1974 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1975 | return -EPERM; |
| 1976 | } |
| 1977 | |
| 1978 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1979 | MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1980 | ioc_err(ioc, "%s: buffer_type(0x%02x) is not registered\n", |
| 1981 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1982 | return -EINVAL; |
| 1983 | } |
| 1984 | |
| 1985 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1986 | ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n", |
| 1987 | __func__, karg.unique_id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1988 | return -EINVAL; |
| 1989 | } |
| 1990 | |
| 1991 | if (ioc->diag_buffer_status[buffer_type] & |
| 1992 | MPT3_DIAG_BUFFER_IS_RELEASED) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 1993 | ioc_err(ioc, "%s: buffer_type(0x%02x) is already released\n", |
| 1994 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | request_data = ioc->diag_buffer[buffer_type]; |
| 1999 | |
| 2000 | if (!request_data) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2001 | ioc_err(ioc, "%s: doesn't have memory allocated for buffer_type(0x%02x)\n", |
| 2002 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2003 | return -ENOMEM; |
| 2004 | } |
| 2005 | |
| 2006 | /* buffers were released by due to host reset */ |
| 2007 | if ((ioc->diag_buffer_status[buffer_type] & |
| 2008 | MPT3_DIAG_BUFFER_IS_DIAG_RESET)) { |
| 2009 | ioc->diag_buffer_status[buffer_type] |= |
| 2010 | MPT3_DIAG_BUFFER_IS_RELEASED; |
| 2011 | ioc->diag_buffer_status[buffer_type] &= |
| 2012 | ~MPT3_DIAG_BUFFER_IS_DIAG_RESET; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2013 | ioc_err(ioc, "%s: buffer_type(0x%02x) was released due to host reset\n", |
| 2014 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2015 | return 0; |
| 2016 | } |
| 2017 | |
| 2018 | rc = mpt3sas_send_diag_release(ioc, buffer_type, &issue_reset); |
| 2019 | |
| 2020 | if (issue_reset) |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 2021 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2022 | |
| 2023 | return rc; |
| 2024 | } |
| 2025 | |
| 2026 | /** |
| 2027 | * _ctl_diag_read_buffer - request for copy of the diag buffer |
| 2028 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2029 | * @arg: user space buffer containing ioctl content |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2030 | */ |
| 2031 | static long |
| 2032 | _ctl_diag_read_buffer(struct MPT3SAS_ADAPTER *ioc, void __user *arg) |
| 2033 | { |
| 2034 | struct mpt3_diag_read_buffer karg; |
| 2035 | struct mpt3_diag_read_buffer __user *uarg = arg; |
| 2036 | void *request_data, *diag_data; |
| 2037 | Mpi2DiagBufferPostRequest_t *mpi_request; |
| 2038 | Mpi2DiagBufferPostReply_t *mpi_reply; |
| 2039 | int rc, i; |
| 2040 | u8 buffer_type; |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 2041 | unsigned long request_size, copy_size; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2042 | u16 smid; |
| 2043 | u16 ioc_status; |
| 2044 | u8 issue_reset = 0; |
| 2045 | |
| 2046 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 2047 | pr_err("failure at %s:%d/%s()!\n", |
| 2048 | __FILE__, __LINE__, __func__); |
| 2049 | return -EFAULT; |
| 2050 | } |
| 2051 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2052 | dctlprintk(ioc, ioc_info(ioc, "%s\n", |
| 2053 | __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2054 | |
| 2055 | buffer_type = karg.unique_id & 0x000000ff; |
| 2056 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2057 | ioc_err(ioc, "%s: doesn't have capability for buffer_type(0x%02x)\n", |
| 2058 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2059 | return -EPERM; |
| 2060 | } |
| 2061 | |
| 2062 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2063 | ioc_err(ioc, "%s: unique_id(0x%08x) is not registered\n", |
| 2064 | __func__, karg.unique_id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2065 | return -EINVAL; |
| 2066 | } |
| 2067 | |
| 2068 | request_data = ioc->diag_buffer[buffer_type]; |
| 2069 | if (!request_data) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2070 | ioc_err(ioc, "%s: doesn't have buffer for buffer_type(0x%02x)\n", |
| 2071 | __func__, buffer_type); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2072 | return -ENOMEM; |
| 2073 | } |
| 2074 | |
| 2075 | request_size = ioc->diag_buffer_sz[buffer_type]; |
| 2076 | |
| 2077 | if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2078 | ioc_err(ioc, "%s: either the starting_offset or bytes_to_read are not 4 byte aligned\n", |
| 2079 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2080 | return -EINVAL; |
| 2081 | } |
| 2082 | |
| 2083 | if (karg.starting_offset > request_size) |
| 2084 | return -EINVAL; |
| 2085 | |
| 2086 | diag_data = (void *)(request_data + karg.starting_offset); |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2087 | dctlprintk(ioc, |
| 2088 | ioc_info(ioc, "%s: diag_buffer(%p), offset(%d), sz(%d)\n", |
| 2089 | __func__, diag_data, karg.starting_offset, |
| 2090 | karg.bytes_to_read)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2091 | |
| 2092 | /* Truncate data on requests that are too large */ |
| 2093 | if ((diag_data + karg.bytes_to_read < diag_data) || |
| 2094 | (diag_data + karg.bytes_to_read > request_data + request_size)) |
| 2095 | copy_size = request_size - karg.starting_offset; |
| 2096 | else |
| 2097 | copy_size = karg.bytes_to_read; |
| 2098 | |
| 2099 | if (copy_to_user((void __user *)uarg->diagnostic_data, |
| 2100 | diag_data, copy_size)) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2101 | ioc_err(ioc, "%s: Unable to write mpt_diag_read_buffer_t data @ %p\n", |
| 2102 | __func__, diag_data); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2103 | return -EFAULT; |
| 2104 | } |
| 2105 | |
| 2106 | if ((karg.flags & MPT3_FLAGS_REREGISTER) == 0) |
| 2107 | return 0; |
| 2108 | |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2109 | dctlprintk(ioc, |
| 2110 | ioc_info(ioc, "%s: Reregister buffer_type(0x%02x)\n", |
| 2111 | __func__, buffer_type)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2112 | if ((ioc->diag_buffer_status[buffer_type] & |
| 2113 | MPT3_DIAG_BUFFER_IS_RELEASED) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2114 | dctlprintk(ioc, |
| 2115 | ioc_info(ioc, "%s: buffer_type(0x%02x) is still registered\n", |
| 2116 | __func__, buffer_type)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2117 | return 0; |
| 2118 | } |
| 2119 | /* Get a free request frame and save the message context. |
| 2120 | */ |
| 2121 | |
| 2122 | if (ioc->ctl_cmds.status != MPT3_CMD_NOT_USED) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2123 | ioc_err(ioc, "%s: ctl_cmd in use\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2124 | rc = -EAGAIN; |
| 2125 | goto out; |
| 2126 | } |
| 2127 | |
| 2128 | smid = mpt3sas_base_get_smid(ioc, ioc->ctl_cb_idx); |
| 2129 | if (!smid) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2130 | ioc_err(ioc, "%s: failed obtaining a smid\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2131 | rc = -EAGAIN; |
| 2132 | goto out; |
| 2133 | } |
| 2134 | |
| 2135 | rc = 0; |
| 2136 | ioc->ctl_cmds.status = MPT3_CMD_PENDING; |
| 2137 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 2138 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 2139 | ioc->ctl_cmds.smid = smid; |
| 2140 | |
| 2141 | mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST; |
| 2142 | mpi_request->BufferType = buffer_type; |
| 2143 | mpi_request->BufferLength = |
| 2144 | cpu_to_le32(ioc->diag_buffer_sz[buffer_type]); |
| 2145 | mpi_request->BufferAddress = |
| 2146 | cpu_to_le64(ioc->diag_buffer_dma[buffer_type]); |
| 2147 | for (i = 0; i < MPT3_PRODUCT_SPECIFIC_DWORDS; i++) |
| 2148 | mpi_request->ProductSpecific[i] = |
| 2149 | cpu_to_le32(ioc->product_specific[buffer_type][i]); |
| 2150 | mpi_request->VF_ID = 0; /* TODO */ |
| 2151 | mpi_request->VP_ID = 0; |
| 2152 | |
| 2153 | init_completion(&ioc->ctl_cmds.done); |
Suganath Prabu S | 078a4cc | 2019-05-31 08:14:34 -0400 | [diff] [blame] | 2154 | ioc->put_smid_default(ioc, smid); |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 2155 | wait_for_completion_timeout(&ioc->ctl_cmds.done, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2156 | MPT3_IOCTL_DEFAULT_TIMEOUT*HZ); |
| 2157 | |
| 2158 | if (!(ioc->ctl_cmds.status & MPT3_CMD_COMPLETE)) { |
Chaitra P B | d37306c | 2018-05-31 06:34:50 -0400 | [diff] [blame] | 2159 | issue_reset = |
| 2160 | mpt3sas_base_check_cmd_timeout(ioc, |
| 2161 | ioc->ctl_cmds.status, mpi_request, |
| 2162 | sizeof(Mpi2DiagBufferPostRequest_t)/4); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2163 | goto issue_host_reset; |
| 2164 | } |
| 2165 | |
| 2166 | /* process the completed Reply Message Frame */ |
| 2167 | if ((ioc->ctl_cmds.status & MPT3_CMD_REPLY_VALID) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2168 | ioc_err(ioc, "%s: no reply message\n", __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2169 | rc = -EFAULT; |
| 2170 | goto out; |
| 2171 | } |
| 2172 | |
| 2173 | mpi_reply = ioc->ctl_cmds.reply; |
| 2174 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 2175 | |
| 2176 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 2177 | ioc->diag_buffer_status[buffer_type] |= |
| 2178 | MPT3_DIAG_BUFFER_IS_REGISTERED; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2179 | dctlprintk(ioc, ioc_info(ioc, "%s: success\n", __func__)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2180 | } else { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2181 | ioc_info(ioc, "%s: ioc_status(0x%04x) log_info(0x%08x)\n", |
| 2182 | __func__, ioc_status, |
| 2183 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2184 | rc = -EFAULT; |
| 2185 | } |
| 2186 | |
| 2187 | issue_host_reset: |
| 2188 | if (issue_reset) |
Calvin Owens | 98c56ad | 2016-07-28 21:38:21 -0700 | [diff] [blame] | 2189 | mpt3sas_base_hard_reset_handler(ioc, FORCE_BIG_HAMMER); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2190 | |
| 2191 | out: |
| 2192 | |
| 2193 | ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; |
| 2194 | return rc; |
| 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | #ifdef CONFIG_COMPAT |
| 2200 | /** |
| 2201 | * _ctl_compat_mpt_command - convert 32bit pointers to 64bit. |
| 2202 | * @ioc: per adapter object |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2203 | * @cmd: ioctl opcode |
| 2204 | * @arg: (struct mpt3_ioctl_command32) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2205 | * |
| 2206 | * MPT3COMMAND32 - Handle 32bit applications running on 64bit os. |
| 2207 | */ |
| 2208 | static long |
| 2209 | _ctl_compat_mpt_command(struct MPT3SAS_ADAPTER *ioc, unsigned cmd, |
| 2210 | void __user *arg) |
| 2211 | { |
| 2212 | struct mpt3_ioctl_command32 karg32; |
| 2213 | struct mpt3_ioctl_command32 __user *uarg; |
| 2214 | struct mpt3_ioctl_command karg; |
| 2215 | |
| 2216 | if (_IOC_SIZE(cmd) != sizeof(struct mpt3_ioctl_command32)) |
| 2217 | return -EINVAL; |
| 2218 | |
| 2219 | uarg = (struct mpt3_ioctl_command32 __user *) arg; |
| 2220 | |
| 2221 | if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) { |
| 2222 | pr_err("failure at %s:%d/%s()!\n", |
| 2223 | __FILE__, __LINE__, __func__); |
| 2224 | return -EFAULT; |
| 2225 | } |
| 2226 | |
| 2227 | memset(&karg, 0, sizeof(struct mpt3_ioctl_command)); |
| 2228 | karg.hdr.ioc_number = karg32.hdr.ioc_number; |
| 2229 | karg.hdr.port_number = karg32.hdr.port_number; |
| 2230 | karg.hdr.max_data_size = karg32.hdr.max_data_size; |
| 2231 | karg.timeout = karg32.timeout; |
| 2232 | karg.max_reply_bytes = karg32.max_reply_bytes; |
| 2233 | karg.data_in_size = karg32.data_in_size; |
| 2234 | karg.data_out_size = karg32.data_out_size; |
| 2235 | karg.max_sense_bytes = karg32.max_sense_bytes; |
| 2236 | karg.data_sge_offset = karg32.data_sge_offset; |
| 2237 | karg.reply_frame_buf_ptr = compat_ptr(karg32.reply_frame_buf_ptr); |
| 2238 | karg.data_in_buf_ptr = compat_ptr(karg32.data_in_buf_ptr); |
| 2239 | karg.data_out_buf_ptr = compat_ptr(karg32.data_out_buf_ptr); |
| 2240 | karg.sense_data_ptr = compat_ptr(karg32.sense_data_ptr); |
| 2241 | return _ctl_do_mpt_command(ioc, karg, &uarg->mf); |
| 2242 | } |
| 2243 | #endif |
| 2244 | |
| 2245 | /** |
| 2246 | * _ctl_ioctl_main - main ioctl entry point |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2247 | * @file: (struct file) |
| 2248 | * @cmd: ioctl opcode |
| 2249 | * @arg: user space data buffer |
| 2250 | * @compat: handles 32 bit applications in 64bit os |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2251 | * @mpi_version: will be MPI2_VERSION for mpt2ctl ioctl device & |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 2252 | * MPI25_VERSION | MPI26_VERSION for mpt3ctl ioctl device. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2253 | */ |
| 2254 | static long |
| 2255 | _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg, |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2256 | u8 compat, u16 mpi_version) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2257 | { |
| 2258 | struct MPT3SAS_ADAPTER *ioc; |
| 2259 | struct mpt3_ioctl_header ioctl_header; |
| 2260 | enum block_state state; |
| 2261 | long ret = -EINVAL; |
| 2262 | |
| 2263 | /* get IOCTL header */ |
| 2264 | if (copy_from_user(&ioctl_header, (char __user *)arg, |
| 2265 | sizeof(struct mpt3_ioctl_header))) { |
| 2266 | pr_err("failure at %s:%d/%s()!\n", |
| 2267 | __FILE__, __LINE__, __func__); |
| 2268 | return -EFAULT; |
| 2269 | } |
| 2270 | |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2271 | if (_ctl_verify_adapter(ioctl_header.ioc_number, |
| 2272 | &ioc, mpi_version) == -1 || !ioc) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2273 | return -ENODEV; |
| 2274 | |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 2275 | /* pci_access_mutex lock acquired by ioctl path */ |
| 2276 | mutex_lock(&ioc->pci_access_mutex); |
| 2277 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2278 | if (ioc->shost_recovery || ioc->pci_error_recovery || |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 2279 | ioc->is_driver_loading || ioc->remove_host) { |
| 2280 | ret = -EAGAIN; |
| 2281 | goto out_unlock_pciaccess; |
| 2282 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2283 | |
| 2284 | state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING; |
| 2285 | if (state == NON_BLOCKING) { |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 2286 | if (!mutex_trylock(&ioc->ctl_cmds.mutex)) { |
| 2287 | ret = -EAGAIN; |
| 2288 | goto out_unlock_pciaccess; |
| 2289 | } |
| 2290 | } else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) { |
| 2291 | ret = -ERESTARTSYS; |
| 2292 | goto out_unlock_pciaccess; |
| 2293 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2294 | |
| 2295 | |
| 2296 | switch (cmd) { |
| 2297 | case MPT3IOCINFO: |
| 2298 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_iocinfo)) |
| 2299 | ret = _ctl_getiocinfo(ioc, arg); |
| 2300 | break; |
| 2301 | #ifdef CONFIG_COMPAT |
| 2302 | case MPT3COMMAND32: |
| 2303 | #endif |
| 2304 | case MPT3COMMAND: |
| 2305 | { |
| 2306 | struct mpt3_ioctl_command __user *uarg; |
| 2307 | struct mpt3_ioctl_command karg; |
| 2308 | |
| 2309 | #ifdef CONFIG_COMPAT |
| 2310 | if (compat) { |
| 2311 | ret = _ctl_compat_mpt_command(ioc, cmd, arg); |
| 2312 | break; |
| 2313 | } |
| 2314 | #endif |
| 2315 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 2316 | pr_err("failure at %s:%d/%s()!\n", |
| 2317 | __FILE__, __LINE__, __func__); |
| 2318 | ret = -EFAULT; |
| 2319 | break; |
| 2320 | } |
| 2321 | |
Gen Zhang | f9e3ebe | 2019-05-30 09:10:30 +0800 | [diff] [blame] | 2322 | if (karg.hdr.ioc_number != ioctl_header.ioc_number) { |
| 2323 | ret = -EINVAL; |
| 2324 | break; |
| 2325 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2326 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_command)) { |
| 2327 | uarg = arg; |
| 2328 | ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf); |
| 2329 | } |
| 2330 | break; |
| 2331 | } |
| 2332 | case MPT3EVENTQUERY: |
| 2333 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventquery)) |
| 2334 | ret = _ctl_eventquery(ioc, arg); |
| 2335 | break; |
| 2336 | case MPT3EVENTENABLE: |
| 2337 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_eventenable)) |
| 2338 | ret = _ctl_eventenable(ioc, arg); |
| 2339 | break; |
| 2340 | case MPT3EVENTREPORT: |
| 2341 | ret = _ctl_eventreport(ioc, arg); |
| 2342 | break; |
| 2343 | case MPT3HARDRESET: |
| 2344 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_diag_reset)) |
| 2345 | ret = _ctl_do_reset(ioc, arg); |
| 2346 | break; |
| 2347 | case MPT3BTDHMAPPING: |
| 2348 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_ioctl_btdh_mapping)) |
| 2349 | ret = _ctl_btdh_mapping(ioc, arg); |
| 2350 | break; |
| 2351 | case MPT3DIAGREGISTER: |
| 2352 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_register)) |
| 2353 | ret = _ctl_diag_register(ioc, arg); |
| 2354 | break; |
| 2355 | case MPT3DIAGUNREGISTER: |
| 2356 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_unregister)) |
| 2357 | ret = _ctl_diag_unregister(ioc, arg); |
| 2358 | break; |
| 2359 | case MPT3DIAGQUERY: |
| 2360 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_query)) |
| 2361 | ret = _ctl_diag_query(ioc, arg); |
| 2362 | break; |
| 2363 | case MPT3DIAGRELEASE: |
| 2364 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_release)) |
| 2365 | ret = _ctl_diag_release(ioc, arg); |
| 2366 | break; |
| 2367 | case MPT3DIAGREADBUFFER: |
| 2368 | if (_IOC_SIZE(cmd) == sizeof(struct mpt3_diag_read_buffer)) |
| 2369 | ret = _ctl_diag_read_buffer(ioc, arg); |
| 2370 | break; |
| 2371 | default: |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2372 | dctlprintk(ioc, |
| 2373 | ioc_info(ioc, "unsupported ioctl opcode(0x%08x)\n", |
| 2374 | cmd)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2375 | break; |
| 2376 | } |
| 2377 | |
| 2378 | mutex_unlock(&ioc->ctl_cmds.mutex); |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 2379 | out_unlock_pciaccess: |
| 2380 | mutex_unlock(&ioc->pci_access_mutex); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2381 | return ret; |
| 2382 | } |
| 2383 | |
| 2384 | /** |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2385 | * _ctl_ioctl - mpt3ctl main ioctl entry point (unlocked) |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2386 | * @file: (struct file) |
| 2387 | * @cmd: ioctl opcode |
| 2388 | * @arg: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2389 | */ |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 2390 | static long |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2391 | _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2392 | { |
| 2393 | long ret; |
| 2394 | |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 2395 | /* pass MPI25_VERSION | MPI26_VERSION value, |
| 2396 | * to indicate that this ioctl cmd |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2397 | * came from mpt3ctl ioctl device. |
| 2398 | */ |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 2399 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0, |
| 2400 | MPI25_VERSION | MPI26_VERSION); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2401 | return ret; |
| 2402 | } |
| 2403 | |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2404 | /** |
| 2405 | * _ctl_mpt2_ioctl - mpt2ctl main ioctl entry point (unlocked) |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2406 | * @file: (struct file) |
| 2407 | * @cmd: ioctl opcode |
| 2408 | * @arg: ? |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2409 | */ |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 2410 | static long |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2411 | _ctl_mpt2_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 2412 | { |
| 2413 | long ret; |
| 2414 | |
| 2415 | /* pass MPI2_VERSION value, to indicate that this ioctl cmd |
| 2416 | * came from mpt2ctl ioctl device. |
| 2417 | */ |
| 2418 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 0, MPI2_VERSION); |
| 2419 | return ret; |
| 2420 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2421 | #ifdef CONFIG_COMPAT |
| 2422 | /** |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2423 | *_ ctl_ioctl_compat - main ioctl entry point (compat) |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2424 | * @file: ? |
| 2425 | * @cmd: ? |
| 2426 | * @arg: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2427 | * |
| 2428 | * This routine handles 32 bit applications in 64bit os. |
| 2429 | */ |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 2430 | static long |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2431 | _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2432 | { |
| 2433 | long ret; |
| 2434 | |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 2435 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1, |
| 2436 | MPI25_VERSION | MPI26_VERSION); |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2437 | return ret; |
| 2438 | } |
| 2439 | |
| 2440 | /** |
| 2441 | *_ ctl_mpt2_ioctl_compat - main ioctl entry point (compat) |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2442 | * @file: ? |
| 2443 | * @cmd: ? |
| 2444 | * @arg: ? |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2445 | * |
| 2446 | * This routine handles 32 bit applications in 64bit os. |
| 2447 | */ |
Calvin Owens | 8bbb1cf | 2016-07-28 21:38:22 -0700 | [diff] [blame] | 2448 | static long |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2449 | _ctl_mpt2_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg) |
| 2450 | { |
| 2451 | long ret; |
| 2452 | |
| 2453 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg, 1, MPI2_VERSION); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2454 | return ret; |
| 2455 | } |
| 2456 | #endif |
| 2457 | |
| 2458 | /* scsi host attributes */ |
| 2459 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2460 | * version_fw_show - firmware version |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2461 | * @cdev: pointer to embedded class device |
| 2462 | * @attr: ? |
| 2463 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2464 | * |
| 2465 | * A sysfs 'read-only' shost attribute. |
| 2466 | */ |
| 2467 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2468 | version_fw_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2469 | char *buf) |
| 2470 | { |
| 2471 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2472 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2473 | |
| 2474 | return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n", |
| 2475 | (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, |
| 2476 | (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, |
| 2477 | (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, |
| 2478 | ioc->facts.FWVersion.Word & 0x000000FF); |
| 2479 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2480 | static DEVICE_ATTR_RO(version_fw); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2481 | |
| 2482 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2483 | * version_bios_show - bios version |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2484 | * @cdev: pointer to embedded class device |
| 2485 | * @attr: ? |
| 2486 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2487 | * |
| 2488 | * A sysfs 'read-only' shost attribute. |
| 2489 | */ |
| 2490 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2491 | version_bios_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2492 | char *buf) |
| 2493 | { |
| 2494 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2495 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2496 | |
| 2497 | u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion); |
| 2498 | |
| 2499 | return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n", |
| 2500 | (version & 0xFF000000) >> 24, |
| 2501 | (version & 0x00FF0000) >> 16, |
| 2502 | (version & 0x0000FF00) >> 8, |
| 2503 | version & 0x000000FF); |
| 2504 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2505 | static DEVICE_ATTR_RO(version_bios); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2506 | |
| 2507 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2508 | * version_mpi_show - MPI (message passing interface) version |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2509 | * @cdev: pointer to embedded class device |
| 2510 | * @attr: ? |
| 2511 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2512 | * |
| 2513 | * A sysfs 'read-only' shost attribute. |
| 2514 | */ |
| 2515 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2516 | version_mpi_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2517 | char *buf) |
| 2518 | { |
| 2519 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2520 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2521 | |
| 2522 | return snprintf(buf, PAGE_SIZE, "%03x.%02x\n", |
| 2523 | ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8); |
| 2524 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2525 | static DEVICE_ATTR_RO(version_mpi); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2526 | |
| 2527 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2528 | * version_product_show - product name |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2529 | * @cdev: pointer to embedded class device |
| 2530 | * @attr: ? |
| 2531 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2532 | * |
| 2533 | * A sysfs 'read-only' shost attribute. |
| 2534 | */ |
| 2535 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2536 | version_product_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2537 | char *buf) |
| 2538 | { |
| 2539 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2540 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2541 | |
| 2542 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName); |
| 2543 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2544 | static DEVICE_ATTR_RO(version_product); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2545 | |
| 2546 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2547 | * version_nvdata_persistent_show - ndvata persistent version |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2548 | * @cdev: pointer to embedded class device |
| 2549 | * @attr: ? |
| 2550 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2551 | * |
| 2552 | * A sysfs 'read-only' shost attribute. |
| 2553 | */ |
| 2554 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2555 | version_nvdata_persistent_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2556 | struct device_attribute *attr, char *buf) |
| 2557 | { |
| 2558 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2559 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2560 | |
| 2561 | return snprintf(buf, PAGE_SIZE, "%08xh\n", |
| 2562 | le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word)); |
| 2563 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2564 | static DEVICE_ATTR_RO(version_nvdata_persistent); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2565 | |
| 2566 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2567 | * version_nvdata_default_show - nvdata default version |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2568 | * @cdev: pointer to embedded class device |
| 2569 | * @attr: ? |
| 2570 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2571 | * |
| 2572 | * A sysfs 'read-only' shost attribute. |
| 2573 | */ |
| 2574 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2575 | version_nvdata_default_show(struct device *cdev, struct device_attribute |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2576 | *attr, char *buf) |
| 2577 | { |
| 2578 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2579 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2580 | |
| 2581 | return snprintf(buf, PAGE_SIZE, "%08xh\n", |
| 2582 | le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word)); |
| 2583 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2584 | static DEVICE_ATTR_RO(version_nvdata_default); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2585 | |
| 2586 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2587 | * board_name_show - board name |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2588 | * @cdev: pointer to embedded class device |
| 2589 | * @attr: ? |
| 2590 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2591 | * |
| 2592 | * A sysfs 'read-only' shost attribute. |
| 2593 | */ |
| 2594 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2595 | board_name_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2596 | char *buf) |
| 2597 | { |
| 2598 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2599 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2600 | |
| 2601 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName); |
| 2602 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2603 | static DEVICE_ATTR_RO(board_name); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2604 | |
| 2605 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2606 | * board_assembly_show - board assembly name |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2607 | * @cdev: pointer to embedded class device |
| 2608 | * @attr: ? |
| 2609 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2610 | * |
| 2611 | * A sysfs 'read-only' shost attribute. |
| 2612 | */ |
| 2613 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2614 | board_assembly_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2615 | char *buf) |
| 2616 | { |
| 2617 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2618 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2619 | |
| 2620 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly); |
| 2621 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2622 | static DEVICE_ATTR_RO(board_assembly); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2623 | |
| 2624 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2625 | * board_tracer_show - board tracer number |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2626 | * @cdev: pointer to embedded class device |
| 2627 | * @attr: ? |
| 2628 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2629 | * |
| 2630 | * A sysfs 'read-only' shost attribute. |
| 2631 | */ |
| 2632 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2633 | board_tracer_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2634 | char *buf) |
| 2635 | { |
| 2636 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2637 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2638 | |
| 2639 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber); |
| 2640 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2641 | static DEVICE_ATTR_RO(board_tracer); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2642 | |
| 2643 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2644 | * io_delay_show - io missing delay |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2645 | * @cdev: pointer to embedded class device |
| 2646 | * @attr: ? |
| 2647 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2648 | * |
| 2649 | * This is for firmware implemention for deboucing device |
| 2650 | * removal events. |
| 2651 | * |
| 2652 | * A sysfs 'read-only' shost attribute. |
| 2653 | */ |
| 2654 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2655 | io_delay_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2656 | char *buf) |
| 2657 | { |
| 2658 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2659 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2660 | |
| 2661 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay); |
| 2662 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2663 | static DEVICE_ATTR_RO(io_delay); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2664 | |
| 2665 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2666 | * device_delay_show - device missing delay |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2667 | * @cdev: pointer to embedded class device |
| 2668 | * @attr: ? |
| 2669 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2670 | * |
| 2671 | * This is for firmware implemention for deboucing device |
| 2672 | * removal events. |
| 2673 | * |
| 2674 | * A sysfs 'read-only' shost attribute. |
| 2675 | */ |
| 2676 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2677 | device_delay_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2678 | char *buf) |
| 2679 | { |
| 2680 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2681 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2682 | |
| 2683 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay); |
| 2684 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2685 | static DEVICE_ATTR_RO(device_delay); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2686 | |
| 2687 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2688 | * fw_queue_depth_show - global credits |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2689 | * @cdev: pointer to embedded class device |
| 2690 | * @attr: ? |
| 2691 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2692 | * |
| 2693 | * This is firmware queue depth limit |
| 2694 | * |
| 2695 | * A sysfs 'read-only' shost attribute. |
| 2696 | */ |
| 2697 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2698 | fw_queue_depth_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2699 | char *buf) |
| 2700 | { |
| 2701 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2702 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2703 | |
| 2704 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit); |
| 2705 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2706 | static DEVICE_ATTR_RO(fw_queue_depth); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2707 | |
| 2708 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2709 | * sas_address_show - sas address |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2710 | * @cdev: pointer to embedded class device |
| 2711 | * @attr: ? |
| 2712 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2713 | * |
| 2714 | * This is the controller sas address |
| 2715 | * |
| 2716 | * A sysfs 'read-only' shost attribute. |
| 2717 | */ |
| 2718 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2719 | host_sas_address_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2720 | char *buf) |
| 2721 | |
| 2722 | { |
| 2723 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2724 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2725 | |
| 2726 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", |
| 2727 | (unsigned long long)ioc->sas_hba.sas_address); |
| 2728 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2729 | static DEVICE_ATTR_RO(host_sas_address); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2730 | |
| 2731 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2732 | * logging_level_show - logging level |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2733 | * @cdev: pointer to embedded class device |
| 2734 | * @attr: ? |
| 2735 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2736 | * |
| 2737 | * A sysfs 'read/write' shost attribute. |
| 2738 | */ |
| 2739 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2740 | logging_level_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2741 | char *buf) |
| 2742 | { |
| 2743 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2744 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2745 | |
| 2746 | return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level); |
| 2747 | } |
| 2748 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2749 | logging_level_store(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2750 | const char *buf, size_t count) |
| 2751 | { |
| 2752 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2753 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2754 | int val = 0; |
| 2755 | |
| 2756 | if (sscanf(buf, "%x", &val) != 1) |
| 2757 | return -EINVAL; |
| 2758 | |
| 2759 | ioc->logging_level = val; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2760 | ioc_info(ioc, "logging_level=%08xh\n", |
| 2761 | ioc->logging_level); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2762 | return strlen(buf); |
| 2763 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2764 | static DEVICE_ATTR_RW(logging_level); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2765 | |
| 2766 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2767 | * fwfault_debug_show - show/store fwfault_debug |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2768 | * @cdev: pointer to embedded class device |
| 2769 | * @attr: ? |
| 2770 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2771 | * |
| 2772 | * mpt3sas_fwfault_debug is command line option |
| 2773 | * A sysfs 'read/write' shost attribute. |
| 2774 | */ |
| 2775 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2776 | fwfault_debug_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2777 | char *buf) |
| 2778 | { |
| 2779 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2780 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2781 | |
| 2782 | return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug); |
| 2783 | } |
| 2784 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2785 | fwfault_debug_store(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2786 | const char *buf, size_t count) |
| 2787 | { |
| 2788 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2789 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2790 | int val = 0; |
| 2791 | |
| 2792 | if (sscanf(buf, "%d", &val) != 1) |
| 2793 | return -EINVAL; |
| 2794 | |
| 2795 | ioc->fwfault_debug = val; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2796 | ioc_info(ioc, "fwfault_debug=%d\n", |
| 2797 | ioc->fwfault_debug); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2798 | return strlen(buf); |
| 2799 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2800 | static DEVICE_ATTR_RW(fwfault_debug); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2801 | |
| 2802 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2803 | * ioc_reset_count_show - ioc reset count |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2804 | * @cdev: pointer to embedded class device |
| 2805 | * @attr: ? |
| 2806 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2807 | * |
| 2808 | * This is firmware queue depth limit |
| 2809 | * |
| 2810 | * A sysfs 'read-only' shost attribute. |
| 2811 | */ |
| 2812 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2813 | ioc_reset_count_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2814 | char *buf) |
| 2815 | { |
| 2816 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2817 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2818 | |
| 2819 | return snprintf(buf, PAGE_SIZE, "%d\n", ioc->ioc_reset_count); |
| 2820 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2821 | static DEVICE_ATTR_RO(ioc_reset_count); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2822 | |
| 2823 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2824 | * reply_queue_count_show - number of reply queues |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2825 | * @cdev: pointer to embedded class device |
| 2826 | * @attr: ? |
| 2827 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2828 | * |
| 2829 | * This is number of reply queues |
| 2830 | * |
| 2831 | * A sysfs 'read-only' shost attribute. |
| 2832 | */ |
| 2833 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2834 | reply_queue_count_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2835 | struct device_attribute *attr, char *buf) |
| 2836 | { |
| 2837 | u8 reply_queue_count; |
| 2838 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2839 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2840 | |
| 2841 | if ((ioc->facts.IOCCapabilities & |
| 2842 | MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable) |
| 2843 | reply_queue_count = ioc->reply_queue_count; |
| 2844 | else |
| 2845 | reply_queue_count = 1; |
| 2846 | |
| 2847 | return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count); |
| 2848 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2849 | static DEVICE_ATTR_RO(reply_queue_count); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2850 | |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2851 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2852 | * BRM_status_show - Backup Rail Monitor Status |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2853 | * @cdev: pointer to embedded class device |
| 2854 | * @attr: ? |
| 2855 | * @buf: the buffer returned |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2856 | * |
| 2857 | * This is number of reply queues |
| 2858 | * |
| 2859 | * A sysfs 'read-only' shost attribute. |
| 2860 | */ |
| 2861 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2862 | BRM_status_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2863 | char *buf) |
| 2864 | { |
| 2865 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2866 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2867 | Mpi2IOUnitPage3_t *io_unit_pg3 = NULL; |
| 2868 | Mpi2ConfigReply_t mpi_reply; |
| 2869 | u16 backup_rail_monitor_status = 0; |
| 2870 | u16 ioc_status; |
| 2871 | int sz; |
| 2872 | ssize_t rc = 0; |
| 2873 | |
| 2874 | if (!ioc->is_warpdrive) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2875 | ioc_err(ioc, "%s: BRM attribute is only for warpdrive\n", |
| 2876 | __func__); |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2877 | goto out; |
| 2878 | } |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 2879 | /* pci_access_mutex lock acquired by sysfs show path */ |
| 2880 | mutex_lock(&ioc->pci_access_mutex); |
| 2881 | if (ioc->pci_error_recovery || ioc->remove_host) { |
| 2882 | mutex_unlock(&ioc->pci_access_mutex); |
| 2883 | return 0; |
| 2884 | } |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2885 | |
| 2886 | /* allocate upto GPIOVal 36 entries */ |
| 2887 | sz = offsetof(Mpi2IOUnitPage3_t, GPIOVal) + (sizeof(u16) * 36); |
| 2888 | io_unit_pg3 = kzalloc(sz, GFP_KERNEL); |
| 2889 | if (!io_unit_pg3) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2890 | ioc_err(ioc, "%s: failed allocating memory for iounit_pg3: (%d) bytes\n", |
| 2891 | __func__, sz); |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2892 | goto out; |
| 2893 | } |
| 2894 | |
| 2895 | if (mpt3sas_config_get_iounit_pg3(ioc, &mpi_reply, io_unit_pg3, sz) != |
| 2896 | 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2897 | ioc_err(ioc, "%s: failed reading iounit_pg3\n", |
| 2898 | __func__); |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2899 | goto out; |
| 2900 | } |
| 2901 | |
| 2902 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 2903 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2904 | ioc_err(ioc, "%s: iounit_pg3 failed with ioc_status(0x%04x)\n", |
| 2905 | __func__, ioc_status); |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2906 | goto out; |
| 2907 | } |
| 2908 | |
| 2909 | if (io_unit_pg3->GPIOCount < 25) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2910 | ioc_err(ioc, "%s: iounit_pg3->GPIOCount less than 25 entries, detected (%d) entries\n", |
| 2911 | __func__, io_unit_pg3->GPIOCount); |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2912 | goto out; |
| 2913 | } |
| 2914 | |
| 2915 | /* BRM status is in bit zero of GPIOVal[24] */ |
| 2916 | backup_rail_monitor_status = le16_to_cpu(io_unit_pg3->GPIOVal[24]); |
| 2917 | rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1)); |
| 2918 | |
| 2919 | out: |
| 2920 | kfree(io_unit_pg3); |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 2921 | mutex_unlock(&ioc->pci_access_mutex); |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2922 | return rc; |
| 2923 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2924 | static DEVICE_ATTR_RO(BRM_status); |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 2925 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2926 | struct DIAG_BUFFER_START { |
| 2927 | __le32 Size; |
| 2928 | __le32 DiagVersion; |
| 2929 | u8 BufferType; |
| 2930 | u8 Reserved[3]; |
| 2931 | __le32 Reserved1; |
| 2932 | __le32 Reserved2; |
| 2933 | __le32 Reserved3; |
| 2934 | }; |
| 2935 | |
| 2936 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2937 | * host_trace_buffer_size_show - host buffer size (trace only) |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2938 | * @cdev: pointer to embedded class device |
| 2939 | * @attr: ? |
| 2940 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2941 | * |
| 2942 | * A sysfs 'read-only' shost attribute. |
| 2943 | */ |
| 2944 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2945 | host_trace_buffer_size_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2946 | struct device_attribute *attr, char *buf) |
| 2947 | { |
| 2948 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2949 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2950 | u32 size = 0; |
| 2951 | struct DIAG_BUFFER_START *request_data; |
| 2952 | |
| 2953 | if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2954 | ioc_err(ioc, "%s: host_trace_buffer is not registered\n", |
| 2955 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2956 | return 0; |
| 2957 | } |
| 2958 | |
| 2959 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 2960 | MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 2961 | ioc_err(ioc, "%s: host_trace_buffer is not registered\n", |
| 2962 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2963 | return 0; |
| 2964 | } |
| 2965 | |
| 2966 | request_data = (struct DIAG_BUFFER_START *) |
| 2967 | ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]; |
| 2968 | if ((le32_to_cpu(request_data->DiagVersion) == 0x00000000 || |
| 2969 | le32_to_cpu(request_data->DiagVersion) == 0x01000000 || |
| 2970 | le32_to_cpu(request_data->DiagVersion) == 0x01010000) && |
| 2971 | le32_to_cpu(request_data->Reserved3) == 0x4742444c) |
| 2972 | size = le32_to_cpu(request_data->Size); |
| 2973 | |
| 2974 | ioc->ring_buffer_sz = size; |
| 2975 | return snprintf(buf, PAGE_SIZE, "%d\n", size); |
| 2976 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2977 | static DEVICE_ATTR_RO(host_trace_buffer_size); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2978 | |
| 2979 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2980 | * host_trace_buffer_show - firmware ring buffer (trace only) |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 2981 | * @cdev: pointer to embedded class device |
| 2982 | * @attr: ? |
| 2983 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2984 | * |
| 2985 | * A sysfs 'read/write' shost attribute. |
| 2986 | * |
| 2987 | * You will only be able to read 4k bytes of ring buffer at a time. |
| 2988 | * In order to read beyond 4k bytes, you will have to write out the |
| 2989 | * offset to the same attribute, it will move the pointer. |
| 2990 | */ |
| 2991 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 2992 | host_trace_buffer_show(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2993 | char *buf) |
| 2994 | { |
| 2995 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2996 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 2997 | void *request_data; |
| 2998 | u32 size; |
| 2999 | |
| 3000 | if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 3001 | ioc_err(ioc, "%s: host_trace_buffer is not registered\n", |
| 3002 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3003 | return 0; |
| 3004 | } |
| 3005 | |
| 3006 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 3007 | MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 3008 | ioc_err(ioc, "%s: host_trace_buffer is not registered\n", |
| 3009 | __func__); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3010 | return 0; |
| 3011 | } |
| 3012 | |
| 3013 | if (ioc->ring_buffer_offset > ioc->ring_buffer_sz) |
| 3014 | return 0; |
| 3015 | |
| 3016 | size = ioc->ring_buffer_sz - ioc->ring_buffer_offset; |
| 3017 | size = (size >= PAGE_SIZE) ? (PAGE_SIZE - 1) : size; |
| 3018 | request_data = ioc->diag_buffer[0] + ioc->ring_buffer_offset; |
| 3019 | memcpy(buf, request_data, size); |
| 3020 | return size; |
| 3021 | } |
| 3022 | |
| 3023 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3024 | host_trace_buffer_store(struct device *cdev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3025 | const char *buf, size_t count) |
| 3026 | { |
| 3027 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3028 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3029 | int val = 0; |
| 3030 | |
| 3031 | if (sscanf(buf, "%d", &val) != 1) |
| 3032 | return -EINVAL; |
| 3033 | |
| 3034 | ioc->ring_buffer_offset = val; |
| 3035 | return strlen(buf); |
| 3036 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3037 | static DEVICE_ATTR_RW(host_trace_buffer); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3038 | |
| 3039 | |
| 3040 | /*****************************************/ |
| 3041 | |
| 3042 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3043 | * host_trace_buffer_enable_show - firmware ring buffer (trace only) |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3044 | * @cdev: pointer to embedded class device |
| 3045 | * @attr: ? |
| 3046 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3047 | * |
| 3048 | * A sysfs 'read/write' shost attribute. |
| 3049 | * |
| 3050 | * This is a mechnism to post/release host_trace_buffers |
| 3051 | */ |
| 3052 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3053 | host_trace_buffer_enable_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3054 | struct device_attribute *attr, char *buf) |
| 3055 | { |
| 3056 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3057 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3058 | |
| 3059 | if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) || |
| 3060 | ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 3061 | MPT3_DIAG_BUFFER_IS_REGISTERED) == 0)) |
| 3062 | return snprintf(buf, PAGE_SIZE, "off\n"); |
| 3063 | else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 3064 | MPT3_DIAG_BUFFER_IS_RELEASED)) |
| 3065 | return snprintf(buf, PAGE_SIZE, "release\n"); |
| 3066 | else |
| 3067 | return snprintf(buf, PAGE_SIZE, "post\n"); |
| 3068 | } |
| 3069 | |
| 3070 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3071 | host_trace_buffer_enable_store(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3072 | struct device_attribute *attr, const char *buf, size_t count) |
| 3073 | { |
| 3074 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3075 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3076 | char str[10] = ""; |
| 3077 | struct mpt3_diag_register diag_register; |
| 3078 | u8 issue_reset = 0; |
| 3079 | |
| 3080 | /* don't allow post/release occurr while recovery is active */ |
| 3081 | if (ioc->shost_recovery || ioc->remove_host || |
| 3082 | ioc->pci_error_recovery || ioc->is_driver_loading) |
| 3083 | return -EBUSY; |
| 3084 | |
| 3085 | if (sscanf(buf, "%9s", str) != 1) |
| 3086 | return -EINVAL; |
| 3087 | |
| 3088 | if (!strcmp(str, "post")) { |
| 3089 | /* exit out if host buffers are already posted */ |
| 3090 | if ((ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) && |
| 3091 | (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 3092 | MPT3_DIAG_BUFFER_IS_REGISTERED) && |
| 3093 | ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 3094 | MPT3_DIAG_BUFFER_IS_RELEASED) == 0)) |
| 3095 | goto out; |
| 3096 | memset(&diag_register, 0, sizeof(struct mpt3_diag_register)); |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 3097 | ioc_info(ioc, "posting host trace buffers\n"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3098 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE; |
| 3099 | diag_register.requested_buffer_size = (1024 * 1024); |
| 3100 | diag_register.unique_id = 0x7075900; |
| 3101 | ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] = 0; |
| 3102 | _ctl_diag_register_2(ioc, &diag_register); |
| 3103 | } else if (!strcmp(str, "release")) { |
| 3104 | /* exit out if host buffers are already released */ |
| 3105 | if (!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) |
| 3106 | goto out; |
| 3107 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 3108 | MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) |
| 3109 | goto out; |
| 3110 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 3111 | MPT3_DIAG_BUFFER_IS_RELEASED)) |
| 3112 | goto out; |
Joe Perches | 919d8a3 | 2018-09-17 08:01:09 -0700 | [diff] [blame] | 3113 | ioc_info(ioc, "releasing host trace buffer\n"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3114 | mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE, |
| 3115 | &issue_reset); |
| 3116 | } |
| 3117 | |
| 3118 | out: |
| 3119 | return strlen(buf); |
| 3120 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3121 | static DEVICE_ATTR_RW(host_trace_buffer_enable); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3122 | |
| 3123 | /*********** diagnostic trigger suppport *********************************/ |
| 3124 | |
| 3125 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3126 | * diag_trigger_master_show - show the diag_trigger_master attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3127 | * @cdev: pointer to embedded class device |
| 3128 | * @attr: ? |
| 3129 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3130 | * |
| 3131 | * A sysfs 'read/write' shost attribute. |
| 3132 | */ |
| 3133 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3134 | diag_trigger_master_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3135 | struct device_attribute *attr, char *buf) |
| 3136 | |
| 3137 | { |
| 3138 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3139 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3140 | unsigned long flags; |
| 3141 | ssize_t rc; |
| 3142 | |
| 3143 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
| 3144 | rc = sizeof(struct SL_WH_MASTER_TRIGGER_T); |
| 3145 | memcpy(buf, &ioc->diag_trigger_master, rc); |
| 3146 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3147 | return rc; |
| 3148 | } |
| 3149 | |
| 3150 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3151 | * diag_trigger_master_store - store the diag_trigger_master attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3152 | * @cdev: pointer to embedded class device |
| 3153 | * @attr: ? |
| 3154 | * @buf: the buffer returned |
| 3155 | * @count: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3156 | * |
| 3157 | * A sysfs 'read/write' shost attribute. |
| 3158 | */ |
| 3159 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3160 | diag_trigger_master_store(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3161 | struct device_attribute *attr, const char *buf, size_t count) |
| 3162 | |
| 3163 | { |
| 3164 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3165 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3166 | unsigned long flags; |
| 3167 | ssize_t rc; |
| 3168 | |
| 3169 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
| 3170 | rc = min(sizeof(struct SL_WH_MASTER_TRIGGER_T), count); |
| 3171 | memset(&ioc->diag_trigger_master, 0, |
| 3172 | sizeof(struct SL_WH_MASTER_TRIGGER_T)); |
| 3173 | memcpy(&ioc->diag_trigger_master, buf, rc); |
| 3174 | ioc->diag_trigger_master.MasterData |= |
| 3175 | (MASTER_TRIGGER_FW_FAULT + MASTER_TRIGGER_ADAPTER_RESET); |
| 3176 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3177 | return rc; |
| 3178 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3179 | static DEVICE_ATTR_RW(diag_trigger_master); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3180 | |
| 3181 | |
| 3182 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3183 | * diag_trigger_event_show - show the diag_trigger_event attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3184 | * @cdev: pointer to embedded class device |
| 3185 | * @attr: ? |
| 3186 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3187 | * |
| 3188 | * A sysfs 'read/write' shost attribute. |
| 3189 | */ |
| 3190 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3191 | diag_trigger_event_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3192 | struct device_attribute *attr, char *buf) |
| 3193 | { |
| 3194 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3195 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3196 | unsigned long flags; |
| 3197 | ssize_t rc; |
| 3198 | |
| 3199 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
| 3200 | rc = sizeof(struct SL_WH_EVENT_TRIGGERS_T); |
| 3201 | memcpy(buf, &ioc->diag_trigger_event, rc); |
| 3202 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3203 | return rc; |
| 3204 | } |
| 3205 | |
| 3206 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3207 | * diag_trigger_event_store - store the diag_trigger_event attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3208 | * @cdev: pointer to embedded class device |
| 3209 | * @attr: ? |
| 3210 | * @buf: the buffer returned |
| 3211 | * @count: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3212 | * |
| 3213 | * A sysfs 'read/write' shost attribute. |
| 3214 | */ |
| 3215 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3216 | diag_trigger_event_store(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3217 | struct device_attribute *attr, const char *buf, size_t count) |
| 3218 | |
| 3219 | { |
| 3220 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3221 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3222 | unsigned long flags; |
| 3223 | ssize_t sz; |
| 3224 | |
| 3225 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
| 3226 | sz = min(sizeof(struct SL_WH_EVENT_TRIGGERS_T), count); |
| 3227 | memset(&ioc->diag_trigger_event, 0, |
| 3228 | sizeof(struct SL_WH_EVENT_TRIGGERS_T)); |
| 3229 | memcpy(&ioc->diag_trigger_event, buf, sz); |
| 3230 | if (ioc->diag_trigger_event.ValidEntries > NUM_VALID_ENTRIES) |
| 3231 | ioc->diag_trigger_event.ValidEntries = NUM_VALID_ENTRIES; |
| 3232 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3233 | return sz; |
| 3234 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3235 | static DEVICE_ATTR_RW(diag_trigger_event); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3236 | |
| 3237 | |
| 3238 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3239 | * diag_trigger_scsi_show - show the diag_trigger_scsi attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3240 | * @cdev: pointer to embedded class device |
| 3241 | * @attr: ? |
| 3242 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3243 | * |
| 3244 | * A sysfs 'read/write' shost attribute. |
| 3245 | */ |
| 3246 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3247 | diag_trigger_scsi_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3248 | struct device_attribute *attr, char *buf) |
| 3249 | { |
| 3250 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3251 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3252 | unsigned long flags; |
| 3253 | ssize_t rc; |
| 3254 | |
| 3255 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
| 3256 | rc = sizeof(struct SL_WH_SCSI_TRIGGERS_T); |
| 3257 | memcpy(buf, &ioc->diag_trigger_scsi, rc); |
| 3258 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3259 | return rc; |
| 3260 | } |
| 3261 | |
| 3262 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3263 | * diag_trigger_scsi_store - store the diag_trigger_scsi attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3264 | * @cdev: pointer to embedded class device |
| 3265 | * @attr: ? |
| 3266 | * @buf: the buffer returned |
| 3267 | * @count: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3268 | * |
| 3269 | * A sysfs 'read/write' shost attribute. |
| 3270 | */ |
| 3271 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3272 | diag_trigger_scsi_store(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3273 | struct device_attribute *attr, const char *buf, size_t count) |
| 3274 | { |
| 3275 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3276 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3277 | unsigned long flags; |
| 3278 | ssize_t sz; |
| 3279 | |
| 3280 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
Dan Carpenter | 1de540a | 2019-07-26 09:52:05 +0300 | [diff] [blame] | 3281 | sz = min(sizeof(ioc->diag_trigger_scsi), count); |
| 3282 | memset(&ioc->diag_trigger_scsi, 0, sizeof(ioc->diag_trigger_scsi)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3283 | memcpy(&ioc->diag_trigger_scsi, buf, sz); |
| 3284 | if (ioc->diag_trigger_scsi.ValidEntries > NUM_VALID_ENTRIES) |
| 3285 | ioc->diag_trigger_scsi.ValidEntries = NUM_VALID_ENTRIES; |
| 3286 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3287 | return sz; |
| 3288 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3289 | static DEVICE_ATTR_RW(diag_trigger_scsi); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3290 | |
| 3291 | |
| 3292 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3293 | * diag_trigger_scsi_show - show the diag_trigger_mpi attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3294 | * @cdev: pointer to embedded class device |
| 3295 | * @attr: ? |
| 3296 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3297 | * |
| 3298 | * A sysfs 'read/write' shost attribute. |
| 3299 | */ |
| 3300 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3301 | diag_trigger_mpi_show(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3302 | struct device_attribute *attr, char *buf) |
| 3303 | { |
| 3304 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3305 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3306 | unsigned long flags; |
| 3307 | ssize_t rc; |
| 3308 | |
| 3309 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
| 3310 | rc = sizeof(struct SL_WH_MPI_TRIGGERS_T); |
| 3311 | memcpy(buf, &ioc->diag_trigger_mpi, rc); |
| 3312 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3313 | return rc; |
| 3314 | } |
| 3315 | |
| 3316 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3317 | * diag_trigger_mpi_store - store the diag_trigger_mpi attribute |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3318 | * @cdev: pointer to embedded class device |
| 3319 | * @attr: ? |
| 3320 | * @buf: the buffer returned |
| 3321 | * @count: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3322 | * |
| 3323 | * A sysfs 'read/write' shost attribute. |
| 3324 | */ |
| 3325 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3326 | diag_trigger_mpi_store(struct device *cdev, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3327 | struct device_attribute *attr, const char *buf, size_t count) |
| 3328 | { |
| 3329 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 3330 | struct MPT3SAS_ADAPTER *ioc = shost_priv(shost); |
| 3331 | unsigned long flags; |
| 3332 | ssize_t sz; |
| 3333 | |
| 3334 | spin_lock_irqsave(&ioc->diag_trigger_lock, flags); |
| 3335 | sz = min(sizeof(struct SL_WH_MPI_TRIGGERS_T), count); |
| 3336 | memset(&ioc->diag_trigger_mpi, 0, |
Dan Carpenter | 66331e8 | 2012-12-07 13:56:22 +0300 | [diff] [blame] | 3337 | sizeof(ioc->diag_trigger_mpi)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3338 | memcpy(&ioc->diag_trigger_mpi, buf, sz); |
| 3339 | if (ioc->diag_trigger_mpi.ValidEntries > NUM_VALID_ENTRIES) |
| 3340 | ioc->diag_trigger_mpi.ValidEntries = NUM_VALID_ENTRIES; |
| 3341 | spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); |
| 3342 | return sz; |
| 3343 | } |
| 3344 | |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3345 | static DEVICE_ATTR_RW(diag_trigger_mpi); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3346 | |
| 3347 | /*********** diagnostic trigger suppport *** END ****************************/ |
| 3348 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3349 | /*****************************************/ |
| 3350 | |
| 3351 | struct device_attribute *mpt3sas_host_attrs[] = { |
| 3352 | &dev_attr_version_fw, |
| 3353 | &dev_attr_version_bios, |
| 3354 | &dev_attr_version_mpi, |
| 3355 | &dev_attr_version_product, |
| 3356 | &dev_attr_version_nvdata_persistent, |
| 3357 | &dev_attr_version_nvdata_default, |
| 3358 | &dev_attr_board_name, |
| 3359 | &dev_attr_board_assembly, |
| 3360 | &dev_attr_board_tracer, |
| 3361 | &dev_attr_io_delay, |
| 3362 | &dev_attr_device_delay, |
| 3363 | &dev_attr_logging_level, |
| 3364 | &dev_attr_fwfault_debug, |
| 3365 | &dev_attr_fw_queue_depth, |
| 3366 | &dev_attr_host_sas_address, |
| 3367 | &dev_attr_ioc_reset_count, |
| 3368 | &dev_attr_host_trace_buffer_size, |
| 3369 | &dev_attr_host_trace_buffer, |
| 3370 | &dev_attr_host_trace_buffer_enable, |
| 3371 | &dev_attr_reply_queue_count, |
| 3372 | &dev_attr_diag_trigger_master, |
| 3373 | &dev_attr_diag_trigger_event, |
| 3374 | &dev_attr_diag_trigger_scsi, |
| 3375 | &dev_attr_diag_trigger_mpi, |
Sreekanth Reddy | 4226309 | 2015-11-11 17:30:29 +0530 | [diff] [blame] | 3376 | &dev_attr_BRM_status, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3377 | NULL, |
| 3378 | }; |
| 3379 | |
| 3380 | /* device attributes */ |
| 3381 | |
| 3382 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3383 | * sas_address_show - sas address |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3384 | * @dev: pointer to embedded class device |
| 3385 | * @attr: ? |
| 3386 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3387 | * |
| 3388 | * This is the sas address for the target |
| 3389 | * |
| 3390 | * A sysfs 'read-only' shost attribute. |
| 3391 | */ |
| 3392 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3393 | sas_address_show(struct device *dev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3394 | char *buf) |
| 3395 | { |
| 3396 | struct scsi_device *sdev = to_scsi_device(dev); |
| 3397 | struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata; |
| 3398 | |
| 3399 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", |
| 3400 | (unsigned long long)sas_device_priv_data->sas_target->sas_address); |
| 3401 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3402 | static DEVICE_ATTR_RO(sas_address); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3403 | |
| 3404 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3405 | * sas_device_handle_show - device handle |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3406 | * @dev: pointer to embedded class device |
| 3407 | * @attr: ? |
| 3408 | * @buf: the buffer returned |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3409 | * |
| 3410 | * This is the firmware assigned device handle |
| 3411 | * |
| 3412 | * A sysfs 'read-only' shost attribute. |
| 3413 | */ |
| 3414 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3415 | sas_device_handle_show(struct device *dev, struct device_attribute *attr, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3416 | char *buf) |
| 3417 | { |
| 3418 | struct scsi_device *sdev = to_scsi_device(dev); |
| 3419 | struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata; |
| 3420 | |
| 3421 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", |
| 3422 | sas_device_priv_data->sas_target->handle); |
| 3423 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3424 | static DEVICE_ATTR_RO(sas_device_handle); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3425 | |
Adam Manzanares | 307d907 | 2016-12-12 16:31:40 -0800 | [diff] [blame] | 3426 | /** |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3427 | * sas_ncq_io_prio_show - send prioritized io commands to device |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3428 | * @dev: pointer to embedded device |
| 3429 | * @attr: ? |
| 3430 | * @buf: the buffer returned |
Adam Manzanares | 307d907 | 2016-12-12 16:31:40 -0800 | [diff] [blame] | 3431 | * |
| 3432 | * A sysfs 'read/write' sdev attribute, only works with SATA |
| 3433 | */ |
| 3434 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3435 | sas_ncq_prio_enable_show(struct device *dev, |
Adam Manzanares | 307d907 | 2016-12-12 16:31:40 -0800 | [diff] [blame] | 3436 | struct device_attribute *attr, char *buf) |
| 3437 | { |
| 3438 | struct scsi_device *sdev = to_scsi_device(dev); |
| 3439 | struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata; |
| 3440 | |
| 3441 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 3442 | sas_device_priv_data->ncq_prio_enable); |
| 3443 | } |
| 3444 | |
| 3445 | static ssize_t |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3446 | sas_ncq_prio_enable_store(struct device *dev, |
Adam Manzanares | 307d907 | 2016-12-12 16:31:40 -0800 | [diff] [blame] | 3447 | struct device_attribute *attr, |
| 3448 | const char *buf, size_t count) |
| 3449 | { |
| 3450 | struct scsi_device *sdev = to_scsi_device(dev); |
| 3451 | struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata; |
| 3452 | bool ncq_prio_enable = 0; |
| 3453 | |
| 3454 | if (kstrtobool(buf, &ncq_prio_enable)) |
| 3455 | return -EINVAL; |
| 3456 | |
| 3457 | if (!scsih_ncq_prio_supp(sdev)) |
| 3458 | return -EINVAL; |
| 3459 | |
| 3460 | sas_device_priv_data->ncq_prio_enable = ncq_prio_enable; |
| 3461 | return strlen(buf); |
| 3462 | } |
Tomas Henzl | c9df144 | 2019-06-14 16:41:44 +0200 | [diff] [blame] | 3463 | static DEVICE_ATTR_RW(sas_ncq_prio_enable); |
Adam Manzanares | 307d907 | 2016-12-12 16:31:40 -0800 | [diff] [blame] | 3464 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3465 | struct device_attribute *mpt3sas_dev_attrs[] = { |
| 3466 | &dev_attr_sas_address, |
| 3467 | &dev_attr_sas_device_handle, |
Adam Manzanares | 307d907 | 2016-12-12 16:31:40 -0800 | [diff] [blame] | 3468 | &dev_attr_sas_ncq_prio_enable, |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3469 | NULL, |
| 3470 | }; |
| 3471 | |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 3472 | /* file operations table for mpt3ctl device */ |
| 3473 | static const struct file_operations ctl_fops = { |
| 3474 | .owner = THIS_MODULE, |
| 3475 | .unlocked_ioctl = _ctl_ioctl, |
| 3476 | .poll = _ctl_poll, |
| 3477 | .fasync = _ctl_fasync, |
| 3478 | #ifdef CONFIG_COMPAT |
| 3479 | .compat_ioctl = _ctl_ioctl_compat, |
| 3480 | #endif |
| 3481 | }; |
| 3482 | |
| 3483 | /* file operations table for mpt2ctl device */ |
| 3484 | static const struct file_operations ctl_gen2_fops = { |
| 3485 | .owner = THIS_MODULE, |
| 3486 | .unlocked_ioctl = _ctl_mpt2_ioctl, |
| 3487 | .poll = _ctl_poll, |
| 3488 | .fasync = _ctl_fasync, |
| 3489 | #ifdef CONFIG_COMPAT |
| 3490 | .compat_ioctl = _ctl_mpt2_ioctl_compat, |
| 3491 | #endif |
| 3492 | }; |
| 3493 | |
| 3494 | static struct miscdevice ctl_dev = { |
| 3495 | .minor = MPT3SAS_MINOR, |
| 3496 | .name = MPT3SAS_DEV_NAME, |
| 3497 | .fops = &ctl_fops, |
| 3498 | }; |
| 3499 | |
| 3500 | static struct miscdevice gen2_ctl_dev = { |
| 3501 | .minor = MPT2SAS_MINOR, |
| 3502 | .name = MPT2SAS_DEV_NAME, |
| 3503 | .fops = &ctl_gen2_fops, |
| 3504 | }; |
| 3505 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3506 | /** |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 3507 | * mpt3sas_ctl_init - main entry point for ctl. |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3508 | * @hbas_to_enumerate: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3509 | */ |
| 3510 | void |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 3511 | mpt3sas_ctl_init(ushort hbas_to_enumerate) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3512 | { |
| 3513 | async_queue = NULL; |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 3514 | |
| 3515 | /* Don't register mpt3ctl ioctl device if |
| 3516 | * hbas_to_enumarate is one. |
| 3517 | */ |
| 3518 | if (hbas_to_enumerate != 1) |
| 3519 | if (misc_register(&ctl_dev) < 0) |
| 3520 | pr_err("%s can't register misc device [minor=%d]\n", |
| 3521 | MPT3SAS_DRIVER_NAME, MPT3SAS_MINOR); |
| 3522 | |
| 3523 | /* Don't register mpt3ctl ioctl device if |
| 3524 | * hbas_to_enumarate is two. |
| 3525 | */ |
| 3526 | if (hbas_to_enumerate != 2) |
| 3527 | if (misc_register(&gen2_ctl_dev) < 0) |
| 3528 | pr_err("%s can't register misc device [minor=%d]\n", |
| 3529 | MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR); |
| 3530 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3531 | init_waitqueue_head(&ctl_poll_wait); |
| 3532 | } |
| 3533 | |
| 3534 | /** |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 3535 | * mpt3sas_ctl_exit - exit point for ctl |
Bart Van Assche | 4beb486 | 2018-06-15 14:42:01 -0700 | [diff] [blame] | 3536 | * @hbas_to_enumerate: ? |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3537 | */ |
| 3538 | void |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 3539 | mpt3sas_ctl_exit(ushort hbas_to_enumerate) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3540 | { |
| 3541 | struct MPT3SAS_ADAPTER *ioc; |
| 3542 | int i; |
| 3543 | |
| 3544 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) { |
| 3545 | |
| 3546 | /* free memory associated to diag buffers */ |
| 3547 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { |
| 3548 | if (!ioc->diag_buffer[i]) |
| 3549 | continue; |
| 3550 | if (!(ioc->diag_buffer_status[i] & |
| 3551 | MPT3_DIAG_BUFFER_IS_REGISTERED)) |
| 3552 | continue; |
| 3553 | if ((ioc->diag_buffer_status[i] & |
| 3554 | MPT3_DIAG_BUFFER_IS_RELEASED)) |
| 3555 | continue; |
Christoph Hellwig | 1c2048b | 2018-10-11 09:35:25 +0200 | [diff] [blame] | 3556 | dma_free_coherent(&ioc->pdev->dev, |
| 3557 | ioc->diag_buffer_sz[i], |
| 3558 | ioc->diag_buffer[i], |
| 3559 | ioc->diag_buffer_dma[i]); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3560 | ioc->diag_buffer[i] = NULL; |
| 3561 | ioc->diag_buffer_status[i] = 0; |
| 3562 | } |
| 3563 | |
| 3564 | kfree(ioc->event_log); |
| 3565 | } |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 3566 | if (hbas_to_enumerate != 1) |
| 3567 | misc_deregister(&ctl_dev); |
| 3568 | if (hbas_to_enumerate != 2) |
| 3569 | misc_deregister(&gen2_ctl_dev); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3570 | } |