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