Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Management Module Support for MPT (Message Passing Technology) based |
| 3 | * controllers |
| 4 | * |
| 5 | * This code is based on drivers/scsi/mpt2sas/mpt2_ctl.c |
Kashyap, Desai | 19d3ebe | 2009-09-14 11:01:36 +0530 | [diff] [blame] | 6 | * Copyright (C) 2007-2009 LSI Corporation |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 7 | * (mailto:DL-MPTFusionLinux@lsi.com) |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version 2 |
| 12 | * of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * NO WARRANTY |
| 20 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 21 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 22 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 23 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 24 | * solely responsible for determining the appropriateness of using and |
| 25 | * distributing the Program and assumes all risks associated with its |
| 26 | * exercise of rights under this Agreement, including but not limited to |
| 27 | * the risks and costs of program errors, damage to or loss of data, |
| 28 | * programs or equipment, and unavailability or interruption of operations. |
| 29 | |
| 30 | * DISCLAIMER OF LIABILITY |
| 31 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 32 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 33 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 34 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 35 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 36 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 37 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 38 | |
| 39 | * You should have received a copy of the GNU General Public License |
| 40 | * along with this program; if not, write to the Free Software |
| 41 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 42 | * USA. |
| 43 | */ |
| 44 | |
| 45 | #include <linux/version.h> |
| 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/smp_lock.h> |
| 55 | #include <linux/compat.h> |
| 56 | #include <linux/poll.h> |
| 57 | |
| 58 | #include <linux/io.h> |
| 59 | #include <linux/uaccess.h> |
| 60 | |
| 61 | #include "mpt2sas_base.h" |
| 62 | #include "mpt2sas_ctl.h" |
| 63 | |
| 64 | static struct fasync_struct *async_queue; |
| 65 | static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait); |
| 66 | |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 67 | static int _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, |
| 68 | u8 *issue_reset); |
| 69 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 70 | /** |
| 71 | * enum block_state - blocking state |
| 72 | * @NON_BLOCKING: non blocking |
| 73 | * @BLOCKING: blocking |
| 74 | * |
| 75 | * These states are for ioctls that need to wait for a response |
| 76 | * from firmware, so they probably require sleep. |
| 77 | */ |
| 78 | enum block_state { |
| 79 | NON_BLOCKING, |
| 80 | BLOCKING, |
| 81 | }; |
| 82 | |
| 83 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 84 | /** |
| 85 | * _ctl_display_some_debug - debug routine |
| 86 | * @ioc: per adapter object |
| 87 | * @smid: system request message index |
| 88 | * @calling_function_name: string pass from calling function |
| 89 | * @mpi_reply: reply message frame |
| 90 | * Context: none. |
| 91 | * |
| 92 | * Function for displaying debug info helpfull when debugging issues |
| 93 | * in this module. |
| 94 | */ |
| 95 | static void |
| 96 | _ctl_display_some_debug(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
| 97 | char *calling_function_name, MPI2DefaultReply_t *mpi_reply) |
| 98 | { |
| 99 | Mpi2ConfigRequest_t *mpi_request; |
| 100 | char *desc = NULL; |
| 101 | |
| 102 | if (!(ioc->logging_level & MPT_DEBUG_IOCTL)) |
| 103 | return; |
| 104 | |
| 105 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 106 | switch (mpi_request->Function) { |
| 107 | case MPI2_FUNCTION_SCSI_IO_REQUEST: |
| 108 | { |
| 109 | Mpi2SCSIIORequest_t *scsi_request = |
| 110 | (Mpi2SCSIIORequest_t *)mpi_request; |
| 111 | |
| 112 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, |
| 113 | "scsi_io, cmd(0x%02x), cdb_len(%d)", |
| 114 | scsi_request->CDB.CDB32[0], |
| 115 | le16_to_cpu(scsi_request->IoFlags) & 0xF); |
| 116 | desc = ioc->tmp_string; |
| 117 | break; |
| 118 | } |
| 119 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 120 | desc = "task_mgmt"; |
| 121 | break; |
| 122 | case MPI2_FUNCTION_IOC_INIT: |
| 123 | desc = "ioc_init"; |
| 124 | break; |
| 125 | case MPI2_FUNCTION_IOC_FACTS: |
| 126 | desc = "ioc_facts"; |
| 127 | break; |
| 128 | case MPI2_FUNCTION_CONFIG: |
| 129 | { |
| 130 | Mpi2ConfigRequest_t *config_request = |
| 131 | (Mpi2ConfigRequest_t *)mpi_request; |
| 132 | |
| 133 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, |
| 134 | "config, type(0x%02x), ext_type(0x%02x), number(%d)", |
| 135 | (config_request->Header.PageType & |
| 136 | MPI2_CONFIG_PAGETYPE_MASK), config_request->ExtPageType, |
| 137 | config_request->Header.PageNumber); |
| 138 | desc = ioc->tmp_string; |
| 139 | break; |
| 140 | } |
| 141 | case MPI2_FUNCTION_PORT_FACTS: |
| 142 | desc = "port_facts"; |
| 143 | break; |
| 144 | case MPI2_FUNCTION_PORT_ENABLE: |
| 145 | desc = "port_enable"; |
| 146 | break; |
| 147 | case MPI2_FUNCTION_EVENT_NOTIFICATION: |
| 148 | desc = "event_notification"; |
| 149 | break; |
| 150 | case MPI2_FUNCTION_FW_DOWNLOAD: |
| 151 | desc = "fw_download"; |
| 152 | break; |
| 153 | case MPI2_FUNCTION_FW_UPLOAD: |
| 154 | desc = "fw_upload"; |
| 155 | break; |
| 156 | case MPI2_FUNCTION_RAID_ACTION: |
| 157 | desc = "raid_action"; |
| 158 | break; |
| 159 | case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: |
| 160 | { |
| 161 | Mpi2SCSIIORequest_t *scsi_request = |
| 162 | (Mpi2SCSIIORequest_t *)mpi_request; |
| 163 | |
| 164 | snprintf(ioc->tmp_string, MPT_STRING_LENGTH, |
| 165 | "raid_pass, cmd(0x%02x), cdb_len(%d)", |
| 166 | scsi_request->CDB.CDB32[0], |
| 167 | le16_to_cpu(scsi_request->IoFlags) & 0xF); |
| 168 | desc = ioc->tmp_string; |
| 169 | break; |
| 170 | } |
| 171 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: |
| 172 | desc = "sas_iounit_cntl"; |
| 173 | break; |
| 174 | case MPI2_FUNCTION_SATA_PASSTHROUGH: |
| 175 | desc = "sata_pass"; |
| 176 | break; |
| 177 | case MPI2_FUNCTION_DIAG_BUFFER_POST: |
| 178 | desc = "diag_buffer_post"; |
| 179 | break; |
| 180 | case MPI2_FUNCTION_DIAG_RELEASE: |
| 181 | desc = "diag_release"; |
| 182 | break; |
| 183 | case MPI2_FUNCTION_SMP_PASSTHROUGH: |
| 184 | desc = "smp_passthrough"; |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | if (!desc) |
| 189 | return; |
| 190 | |
| 191 | printk(MPT2SAS_DEBUG_FMT "%s: %s, smid(%d)\n", |
| 192 | ioc->name, calling_function_name, desc, smid); |
| 193 | |
| 194 | if (!mpi_reply) |
| 195 | return; |
| 196 | |
| 197 | if (mpi_reply->IOCStatus || mpi_reply->IOCLogInfo) |
| 198 | printk(MPT2SAS_DEBUG_FMT |
| 199 | "\tiocstatus(0x%04x), loginfo(0x%08x)\n", |
| 200 | ioc->name, le16_to_cpu(mpi_reply->IOCStatus), |
| 201 | le32_to_cpu(mpi_reply->IOCLogInfo)); |
| 202 | |
| 203 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 204 | mpi_request->Function == |
| 205 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) { |
| 206 | Mpi2SCSIIOReply_t *scsi_reply = |
| 207 | (Mpi2SCSIIOReply_t *)mpi_reply; |
| 208 | if (scsi_reply->SCSIState || scsi_reply->SCSIStatus) |
| 209 | printk(MPT2SAS_DEBUG_FMT |
| 210 | "\tscsi_state(0x%02x), scsi_status" |
| 211 | "(0x%02x)\n", ioc->name, |
| 212 | scsi_reply->SCSIState, |
| 213 | scsi_reply->SCSIStatus); |
| 214 | } |
| 215 | } |
| 216 | #endif |
| 217 | |
| 218 | /** |
| 219 | * mpt2sas_ctl_done - ctl module completion routine |
| 220 | * @ioc: per adapter object |
| 221 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 222 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 223 | * @reply: reply message frame(lower 32bit addr) |
| 224 | * Context: none. |
| 225 | * |
| 226 | * The callback handler when using ioc->ctl_cb_idx. |
| 227 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 228 | * Return 1 meaning mf should be freed from _base_interrupt |
| 229 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 230 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 231 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 232 | mpt2sas_ctl_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 233 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 234 | { |
| 235 | MPI2DefaultReply_t *mpi_reply; |
| 236 | |
| 237 | if (ioc->ctl_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 238 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 239 | if (ioc->ctl_cmds.smid != smid) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 240 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 241 | ioc->ctl_cmds.status |= MPT2_CMD_COMPLETE; |
| 242 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 243 | if (mpi_reply) { |
| 244 | memcpy(ioc->ctl_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 245 | ioc->ctl_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 246 | } |
| 247 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 248 | _ctl_display_some_debug(ioc, smid, "ctl_done", mpi_reply); |
| 249 | #endif |
| 250 | ioc->ctl_cmds.status &= ~MPT2_CMD_PENDING; |
| 251 | complete(&ioc->ctl_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 252 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * _ctl_check_event_type - determines when an event needs logging |
| 257 | * @ioc: per adapter object |
| 258 | * @event: firmware event |
| 259 | * |
| 260 | * The bitmask in ioc->event_type[] indicates which events should be |
| 261 | * be saved in the driver event_log. This bitmask is set by application. |
| 262 | * |
| 263 | * Returns 1 when event should be captured, or zero means no match. |
| 264 | */ |
| 265 | static int |
| 266 | _ctl_check_event_type(struct MPT2SAS_ADAPTER *ioc, u16 event) |
| 267 | { |
| 268 | u16 i; |
| 269 | u32 desired_event; |
| 270 | |
| 271 | if (event >= 128 || !event || !ioc->event_log) |
| 272 | return 0; |
| 273 | |
| 274 | desired_event = (1 << (event % 32)); |
| 275 | if (!desired_event) |
| 276 | desired_event = 1; |
| 277 | i = event / 32; |
| 278 | return desired_event & ioc->event_type[i]; |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * mpt2sas_ctl_add_to_event_log - add event |
| 283 | * @ioc: per adapter object |
| 284 | * @mpi_reply: reply message frame |
| 285 | * |
| 286 | * Return nothing. |
| 287 | */ |
| 288 | void |
| 289 | mpt2sas_ctl_add_to_event_log(struct MPT2SAS_ADAPTER *ioc, |
| 290 | Mpi2EventNotificationReply_t *mpi_reply) |
| 291 | { |
| 292 | struct MPT2_IOCTL_EVENTS *event_log; |
| 293 | u16 event; |
| 294 | int i; |
| 295 | u32 sz, event_data_sz; |
| 296 | u8 send_aen = 0; |
| 297 | |
| 298 | if (!ioc->event_log) |
| 299 | return; |
| 300 | |
| 301 | event = le16_to_cpu(mpi_reply->Event); |
| 302 | |
| 303 | if (_ctl_check_event_type(ioc, event)) { |
| 304 | |
| 305 | /* insert entry into circular event_log */ |
| 306 | i = ioc->event_context % MPT2SAS_CTL_EVENT_LOG_SIZE; |
| 307 | event_log = ioc->event_log; |
| 308 | event_log[i].event = event; |
| 309 | event_log[i].context = ioc->event_context++; |
| 310 | |
| 311 | event_data_sz = le16_to_cpu(mpi_reply->EventDataLength)*4; |
| 312 | sz = min_t(u32, event_data_sz, MPT2_EVENT_DATA_SIZE); |
| 313 | memset(event_log[i].data, 0, MPT2_EVENT_DATA_SIZE); |
| 314 | memcpy(event_log[i].data, mpi_reply->EventData, sz); |
| 315 | send_aen = 1; |
| 316 | } |
| 317 | |
| 318 | /* This aen_event_read_flag flag is set until the |
| 319 | * application has read the event log. |
| 320 | * For MPI2_EVENT_LOG_ENTRY_ADDED, we always notify. |
| 321 | */ |
| 322 | if (event == MPI2_EVENT_LOG_ENTRY_ADDED || |
| 323 | (send_aen && !ioc->aen_event_read_flag)) { |
| 324 | ioc->aen_event_read_flag = 1; |
| 325 | wake_up_interruptible(&ctl_poll_wait); |
| 326 | if (async_queue) |
| 327 | kill_fasync(&async_queue, SIGIO, POLL_IN); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * mpt2sas_ctl_event_callback - firmware event handler (called at ISR time) |
| 333 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 334 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 335 | * @reply: reply message frame(lower 32bit addr) |
| 336 | * Context: interrupt. |
| 337 | * |
| 338 | * This function merely adds a new work task into ioc->firmware_event_thread. |
| 339 | * The tasks are worked from _firmware_event_work in user context. |
| 340 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 341 | * Return 1 meaning mf should be freed from _base_interrupt |
| 342 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 343 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 344 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 345 | mpt2sas_ctl_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, |
| 346 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 347 | { |
| 348 | Mpi2EventNotificationReply_t *mpi_reply; |
| 349 | |
| 350 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 351 | mpt2sas_ctl_add_to_event_log(ioc, mpi_reply); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 352 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /** |
| 356 | * _ctl_verify_adapter - validates ioc_number passed from application |
| 357 | * @ioc: per adapter object |
| 358 | * @iocpp: The ioc pointer is returned in this. |
| 359 | * |
| 360 | * Return (-1) means error, else ioc_number. |
| 361 | */ |
| 362 | static int |
| 363 | _ctl_verify_adapter(int ioc_number, struct MPT2SAS_ADAPTER **iocpp) |
| 364 | { |
| 365 | struct MPT2SAS_ADAPTER *ioc; |
| 366 | |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 367 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 368 | if (ioc->id != ioc_number) |
| 369 | continue; |
| 370 | *iocpp = ioc; |
| 371 | return ioc_number; |
| 372 | } |
| 373 | *iocpp = NULL; |
| 374 | return -1; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * mpt2sas_ctl_reset_handler - reset callback handler (for ctl) |
| 379 | * @ioc: per adapter object |
| 380 | * @reset_phase: phase |
| 381 | * |
| 382 | * The handler for doing any required cleanup or initialization. |
| 383 | * |
| 384 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 385 | * MPT2_IOC_DONE_RESET |
| 386 | */ |
| 387 | void |
| 388 | mpt2sas_ctl_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 389 | { |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 390 | int i; |
| 391 | u8 issue_reset; |
| 392 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 393 | switch (reset_phase) { |
| 394 | case MPT2_IOC_PRE_RESET: |
| 395 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 396 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 397 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { |
| 398 | if (!(ioc->diag_buffer_status[i] & |
| 399 | MPT2_DIAG_BUFFER_IS_REGISTERED)) |
| 400 | continue; |
| 401 | if ((ioc->diag_buffer_status[i] & |
| 402 | MPT2_DIAG_BUFFER_IS_RELEASED)) |
| 403 | continue; |
| 404 | _ctl_send_release(ioc, i, &issue_reset); |
| 405 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 406 | break; |
| 407 | case MPT2_IOC_AFTER_RESET: |
| 408 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 409 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
| 410 | if (ioc->ctl_cmds.status & MPT2_CMD_PENDING) { |
| 411 | ioc->ctl_cmds.status |= MPT2_CMD_RESET; |
| 412 | mpt2sas_base_free_smid(ioc, ioc->ctl_cmds.smid); |
| 413 | complete(&ioc->ctl_cmds.done); |
| 414 | } |
| 415 | break; |
| 416 | case MPT2_IOC_DONE_RESET: |
| 417 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 418 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 419 | |
| 420 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { |
| 421 | if (!(ioc->diag_buffer_status[i] & |
| 422 | MPT2_DIAG_BUFFER_IS_REGISTERED)) |
| 423 | continue; |
| 424 | if ((ioc->diag_buffer_status[i] & |
| 425 | MPT2_DIAG_BUFFER_IS_RELEASED)) |
| 426 | continue; |
| 427 | ioc->diag_buffer_status[i] |= |
| 428 | MPT2_DIAG_BUFFER_IS_DIAG_RESET; |
| 429 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 430 | break; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * _ctl_fasync - |
| 436 | * @fd - |
| 437 | * @filep - |
| 438 | * @mode - |
| 439 | * |
| 440 | * Called when application request fasyn callback handler. |
| 441 | */ |
| 442 | static int |
| 443 | _ctl_fasync(int fd, struct file *filep, int mode) |
| 444 | { |
| 445 | return fasync_helper(fd, filep, mode, &async_queue); |
| 446 | } |
| 447 | |
| 448 | /** |
| 449 | * _ctl_release - |
| 450 | * @inode - |
| 451 | * @filep - |
| 452 | * |
| 453 | * Called when application releases the fasyn callback handler. |
| 454 | */ |
| 455 | static int |
| 456 | _ctl_release(struct inode *inode, struct file *filep) |
| 457 | { |
| 458 | return fasync_helper(-1, filep, 0, &async_queue); |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * _ctl_poll - |
| 463 | * @file - |
| 464 | * @wait - |
| 465 | * |
| 466 | */ |
| 467 | static unsigned int |
| 468 | _ctl_poll(struct file *filep, poll_table *wait) |
| 469 | { |
| 470 | struct MPT2SAS_ADAPTER *ioc; |
| 471 | |
| 472 | poll_wait(filep, &ctl_poll_wait, wait); |
| 473 | |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 474 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 475 | if (ioc->aen_event_read_flag) |
| 476 | return POLLIN | POLLRDNORM; |
| 477 | } |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | /** |
Eric Moore | ddf59a3 | 2009-05-18 13:01:29 -0600 | [diff] [blame] | 482 | * _ctl_set_task_mid - assign an active smid to tm request |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 483 | * @ioc: per adapter object |
| 484 | * @karg - (struct mpt2_ioctl_command) |
| 485 | * @tm_request - pointer to mf from user space |
| 486 | * |
| 487 | * Returns 0 when an smid if found, else fail. |
| 488 | * during failure, the reply frame is filled. |
| 489 | */ |
| 490 | static int |
Eric Moore | ddf59a3 | 2009-05-18 13:01:29 -0600 | [diff] [blame] | 491 | _ctl_set_task_mid(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command *karg, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 492 | Mpi2SCSITaskManagementRequest_t *tm_request) |
| 493 | { |
| 494 | u8 found = 0; |
| 495 | u16 i; |
| 496 | u16 handle; |
| 497 | struct scsi_cmnd *scmd; |
| 498 | struct MPT2SAS_DEVICE *priv_data; |
| 499 | unsigned long flags; |
| 500 | Mpi2SCSITaskManagementReply_t *tm_reply; |
| 501 | u32 sz; |
| 502 | u32 lun; |
Eric Moore | ddf59a3 | 2009-05-18 13:01:29 -0600 | [diff] [blame] | 503 | char *desc = NULL; |
| 504 | |
| 505 | if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK) |
| 506 | desc = "abort_task"; |
| 507 | else if (tm_request->TaskType == MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) |
| 508 | desc = "query_task"; |
| 509 | else |
| 510 | return 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 511 | |
| 512 | lun = scsilun_to_int((struct scsi_lun *)tm_request->LUN); |
| 513 | |
| 514 | handle = le16_to_cpu(tm_request->DevHandle); |
| 515 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 516 | for (i = ioc->scsiio_depth; i && !found; i--) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 517 | scmd = ioc->scsi_lookup[i - 1].scmd; |
| 518 | if (scmd == NULL || scmd->device == NULL || |
| 519 | scmd->device->hostdata == NULL) |
| 520 | continue; |
| 521 | if (lun != scmd->device->lun) |
| 522 | continue; |
| 523 | priv_data = scmd->device->hostdata; |
| 524 | if (priv_data->sas_target == NULL) |
| 525 | continue; |
| 526 | if (priv_data->sas_target->handle != handle) |
| 527 | continue; |
| 528 | tm_request->TaskMID = cpu_to_le16(ioc->scsi_lookup[i - 1].smid); |
| 529 | found = 1; |
| 530 | } |
| 531 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 532 | |
| 533 | if (!found) { |
Eric Moore | ddf59a3 | 2009-05-18 13:01:29 -0600 | [diff] [blame] | 534 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 535 | "handle(0x%04x), lun(%d), no active mid!!\n", ioc->name, |
| 536 | desc, tm_request->DevHandle, lun)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 537 | tm_reply = ioc->ctl_cmds.reply; |
| 538 | tm_reply->DevHandle = tm_request->DevHandle; |
| 539 | tm_reply->Function = MPI2_FUNCTION_SCSI_TASK_MGMT; |
Eric Moore | ddf59a3 | 2009-05-18 13:01:29 -0600 | [diff] [blame] | 540 | tm_reply->TaskType = tm_request->TaskType; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 541 | tm_reply->MsgLength = sizeof(Mpi2SCSITaskManagementReply_t)/4; |
| 542 | tm_reply->VP_ID = tm_request->VP_ID; |
| 543 | tm_reply->VF_ID = tm_request->VF_ID; |
| 544 | sz = min_t(u32, karg->max_reply_bytes, ioc->reply_sz); |
| 545 | if (copy_to_user(karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply, |
| 546 | sz)) |
| 547 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 548 | __LINE__, __func__); |
| 549 | return 1; |
| 550 | } |
| 551 | |
Eric Moore | ddf59a3 | 2009-05-18 13:01:29 -0600 | [diff] [blame] | 552 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 553 | "handle(0x%04x), lun(%d), task_mid(%d)\n", ioc->name, |
| 554 | desc, tm_request->DevHandle, lun, tm_request->TaskMID)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode |
| 560 | * @ioc: per adapter object |
| 561 | * @karg - (struct mpt2_ioctl_command) |
| 562 | * @mf - pointer to mf in user space |
| 563 | * @state - NON_BLOCKING or BLOCKING |
| 564 | */ |
| 565 | static long |
| 566 | _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc, |
| 567 | struct mpt2_ioctl_command karg, void __user *mf, enum block_state state) |
| 568 | { |
| 569 | MPI2RequestHeader_t *mpi_request; |
| 570 | MPI2DefaultReply_t *mpi_reply; |
| 571 | u32 ioc_state; |
| 572 | u16 ioc_status; |
| 573 | u16 smid; |
| 574 | unsigned long timeout, timeleft; |
| 575 | u8 issue_reset; |
| 576 | u32 sz; |
| 577 | void *psge; |
| 578 | void *priv_sense = NULL; |
| 579 | void *data_out = NULL; |
| 580 | dma_addr_t data_out_dma; |
| 581 | size_t data_out_sz = 0; |
| 582 | void *data_in = NULL; |
| 583 | dma_addr_t data_in_dma; |
| 584 | size_t data_in_sz = 0; |
| 585 | u32 sgl_flags; |
| 586 | long ret; |
| 587 | u16 wait_state_count; |
| 588 | |
| 589 | issue_reset = 0; |
| 590 | |
| 591 | if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) |
| 592 | return -EAGAIN; |
| 593 | else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) |
| 594 | return -ERESTARTSYS; |
| 595 | |
| 596 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { |
| 597 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", |
| 598 | ioc->name, __func__); |
| 599 | ret = -EAGAIN; |
| 600 | goto out; |
| 601 | } |
| 602 | |
| 603 | wait_state_count = 0; |
| 604 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 605 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 606 | if (wait_state_count++ == 10) { |
| 607 | printk(MPT2SAS_ERR_FMT |
| 608 | "%s: failed due to ioc not operational\n", |
| 609 | ioc->name, __func__); |
| 610 | ret = -EFAULT; |
| 611 | goto out; |
| 612 | } |
| 613 | ssleep(1); |
| 614 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 615 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 616 | "operational state(count=%d)\n", ioc->name, |
| 617 | __func__, wait_state_count); |
| 618 | } |
| 619 | if (wait_state_count) |
| 620 | printk(MPT2SAS_INFO_FMT "%s: ioc is operational\n", |
| 621 | ioc->name, __func__); |
| 622 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 623 | smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->ctl_cb_idx, NULL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 624 | if (!smid) { |
| 625 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 626 | ioc->name, __func__); |
| 627 | ret = -EAGAIN; |
| 628 | goto out; |
| 629 | } |
| 630 | |
| 631 | ret = 0; |
| 632 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; |
| 633 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 634 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 635 | ioc->ctl_cmds.smid = smid; |
| 636 | data_out_sz = karg.data_out_size; |
| 637 | data_in_sz = karg.data_in_size; |
| 638 | |
| 639 | /* copy in request message frame from user */ |
| 640 | if (copy_from_user(mpi_request, mf, karg.data_sge_offset*4)) { |
| 641 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, __LINE__, |
| 642 | __func__); |
| 643 | ret = -EFAULT; |
| 644 | mpt2sas_base_free_smid(ioc, smid); |
| 645 | goto out; |
| 646 | } |
| 647 | |
| 648 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 649 | mpi_request->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH) { |
| 650 | if (!mpi_request->FunctionDependent1 || |
| 651 | mpi_request->FunctionDependent1 > |
| 652 | cpu_to_le16(ioc->facts.MaxDevHandle)) { |
| 653 | ret = -EINVAL; |
| 654 | mpt2sas_base_free_smid(ioc, smid); |
| 655 | goto out; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | /* obtain dma-able memory for data transfer */ |
| 660 | if (data_out_sz) /* WRITE */ { |
| 661 | data_out = pci_alloc_consistent(ioc->pdev, data_out_sz, |
| 662 | &data_out_dma); |
| 663 | if (!data_out) { |
| 664 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 665 | __LINE__, __func__); |
| 666 | ret = -ENOMEM; |
| 667 | mpt2sas_base_free_smid(ioc, smid); |
| 668 | goto out; |
| 669 | } |
| 670 | if (copy_from_user(data_out, karg.data_out_buf_ptr, |
| 671 | data_out_sz)) { |
| 672 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 673 | __LINE__, __func__); |
| 674 | ret = -EFAULT; |
| 675 | mpt2sas_base_free_smid(ioc, smid); |
| 676 | goto out; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | if (data_in_sz) /* READ */ { |
| 681 | data_in = pci_alloc_consistent(ioc->pdev, data_in_sz, |
| 682 | &data_in_dma); |
| 683 | if (!data_in) { |
| 684 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 685 | __LINE__, __func__); |
| 686 | ret = -ENOMEM; |
| 687 | mpt2sas_base_free_smid(ioc, smid); |
| 688 | goto out; |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | /* add scatter gather elements */ |
| 693 | psge = (void *)mpi_request + (karg.data_sge_offset*4); |
| 694 | |
| 695 | if (!data_out_sz && !data_in_sz) { |
| 696 | mpt2sas_base_build_zero_len_sge(ioc, psge); |
| 697 | } else if (data_out_sz && data_in_sz) { |
| 698 | /* WRITE sgel first */ |
| 699 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 700 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 701 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 702 | ioc->base_add_sg_single(psge, sgl_flags | |
| 703 | data_out_sz, data_out_dma); |
| 704 | |
| 705 | /* incr sgel */ |
| 706 | psge += ioc->sge_size; |
| 707 | |
| 708 | /* READ sgel last */ |
| 709 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 710 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 711 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 712 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 713 | ioc->base_add_sg_single(psge, sgl_flags | |
| 714 | data_in_sz, data_in_dma); |
| 715 | } else if (data_out_sz) /* WRITE */ { |
| 716 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 717 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 718 | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 719 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 720 | ioc->base_add_sg_single(psge, sgl_flags | |
| 721 | data_out_sz, data_out_dma); |
| 722 | } else if (data_in_sz) /* READ */ { |
| 723 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 724 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 725 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 726 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 727 | ioc->base_add_sg_single(psge, sgl_flags | |
| 728 | data_in_sz, data_in_dma); |
| 729 | } |
| 730 | |
| 731 | /* send command to firmware */ |
| 732 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 733 | _ctl_display_some_debug(ioc, smid, "ctl_request", NULL); |
| 734 | #endif |
| 735 | |
| 736 | switch (mpi_request->Function) { |
| 737 | case MPI2_FUNCTION_SCSI_IO_REQUEST: |
| 738 | case MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH: |
| 739 | { |
| 740 | Mpi2SCSIIORequest_t *scsiio_request = |
| 741 | (Mpi2SCSIIORequest_t *)mpi_request; |
| 742 | scsiio_request->SenseBufferLowAddress = |
Kashyap, Desai | ec9472c | 2009-09-23 17:34:13 +0530 | [diff] [blame] | 743 | mpt2sas_base_get_sense_buffer_dma(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 744 | priv_sense = mpt2sas_base_get_sense_buffer(ioc, smid); |
| 745 | memset(priv_sense, 0, SCSI_SENSE_BUFFERSIZE); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 746 | mpt2sas_base_put_smid_scsi_io(ioc, smid, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 747 | le16_to_cpu(mpi_request->FunctionDependent1)); |
| 748 | break; |
| 749 | } |
| 750 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 751 | { |
| 752 | Mpi2SCSITaskManagementRequest_t *tm_request = |
| 753 | (Mpi2SCSITaskManagementRequest_t *)mpi_request; |
| 754 | |
| 755 | if (tm_request->TaskType == |
Eric Moore | ddf59a3 | 2009-05-18 13:01:29 -0600 | [diff] [blame] | 756 | MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK || |
| 757 | tm_request->TaskType == |
| 758 | MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK) { |
| 759 | if (_ctl_set_task_mid(ioc, &karg, tm_request)) { |
Eric Moore | 77bdd9e | 2009-04-21 15:39:24 -0600 | [diff] [blame] | 760 | mpt2sas_base_free_smid(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 761 | goto out; |
Eric Moore | 77bdd9e | 2009-04-21 15:39:24 -0600 | [diff] [blame] | 762 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | mutex_lock(&ioc->tm_cmds.mutex); |
| 766 | mpt2sas_scsih_set_tm_flag(ioc, le16_to_cpu( |
| 767 | tm_request->DevHandle)); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 768 | mpt2sas_base_put_smid_hi_priority(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 769 | break; |
| 770 | } |
| 771 | case MPI2_FUNCTION_SMP_PASSTHROUGH: |
| 772 | { |
| 773 | Mpi2SmpPassthroughRequest_t *smp_request = |
| 774 | (Mpi2SmpPassthroughRequest_t *)mpi_request; |
| 775 | u8 *data; |
| 776 | |
| 777 | /* ioc determines which port to use */ |
| 778 | smp_request->PhysicalPort = 0xFF; |
| 779 | if (smp_request->PassthroughFlags & |
| 780 | MPI2_SMP_PT_REQ_PT_FLAGS_IMMEDIATE) |
| 781 | data = (u8 *)&smp_request->SGL; |
| 782 | else |
| 783 | data = data_out; |
| 784 | |
| 785 | if (data[1] == 0x91 && (data[10] == 1 || data[10] == 2)) { |
| 786 | ioc->ioc_link_reset_in_progress = 1; |
| 787 | ioc->ignore_loginfos = 1; |
| 788 | } |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 789 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 790 | break; |
| 791 | } |
| 792 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: |
| 793 | { |
| 794 | Mpi2SasIoUnitControlRequest_t *sasiounit_request = |
| 795 | (Mpi2SasIoUnitControlRequest_t *)mpi_request; |
| 796 | |
| 797 | if (sasiounit_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET |
| 798 | || sasiounit_request->Operation == |
| 799 | MPI2_SAS_OP_PHY_LINK_RESET) { |
| 800 | ioc->ioc_link_reset_in_progress = 1; |
| 801 | ioc->ignore_loginfos = 1; |
| 802 | } |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 803 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 804 | break; |
| 805 | } |
| 806 | default: |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 807 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 808 | break; |
| 809 | } |
| 810 | |
| 811 | if (karg.timeout < MPT2_IOCTL_DEFAULT_TIMEOUT) |
| 812 | timeout = MPT2_IOCTL_DEFAULT_TIMEOUT; |
| 813 | else |
| 814 | timeout = karg.timeout; |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 815 | init_completion(&ioc->ctl_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 816 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, |
| 817 | timeout*HZ); |
| 818 | if (mpi_request->Function == MPI2_FUNCTION_SCSI_TASK_MGMT) { |
| 819 | Mpi2SCSITaskManagementRequest_t *tm_request = |
| 820 | (Mpi2SCSITaskManagementRequest_t *)mpi_request; |
| 821 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 822 | mpt2sas_scsih_clear_tm_flag(ioc, le16_to_cpu( |
| 823 | tm_request->DevHandle)); |
| 824 | } else if ((mpi_request->Function == MPI2_FUNCTION_SMP_PASSTHROUGH || |
| 825 | mpi_request->Function == MPI2_FUNCTION_SAS_IO_UNIT_CONTROL) && |
| 826 | ioc->ioc_link_reset_in_progress) { |
| 827 | ioc->ioc_link_reset_in_progress = 0; |
| 828 | ioc->ignore_loginfos = 0; |
| 829 | } |
| 830 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { |
| 831 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, |
| 832 | __func__); |
| 833 | _debug_dump_mf(mpi_request, karg.data_sge_offset); |
| 834 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) |
| 835 | issue_reset = 1; |
| 836 | goto issue_host_reset; |
| 837 | } |
| 838 | |
| 839 | mpi_reply = ioc->ctl_cmds.reply; |
| 840 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 841 | |
| 842 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 843 | if (mpi_reply->Function == MPI2_FUNCTION_SCSI_TASK_MGMT && |
| 844 | (ioc->logging_level & MPT_DEBUG_TM)) { |
| 845 | Mpi2SCSITaskManagementReply_t *tm_reply = |
| 846 | (Mpi2SCSITaskManagementReply_t *)mpi_reply; |
| 847 | |
| 848 | printk(MPT2SAS_DEBUG_FMT "TASK_MGMT: " |
| 849 | "IOCStatus(0x%04x), IOCLogInfo(0x%08x), " |
| 850 | "TerminationCount(0x%08x)\n", ioc->name, |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 851 | le16_to_cpu(tm_reply->IOCStatus), |
| 852 | le32_to_cpu(tm_reply->IOCLogInfo), |
| 853 | le32_to_cpu(tm_reply->TerminationCount)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 854 | } |
| 855 | #endif |
| 856 | /* copy out xdata to user */ |
| 857 | if (data_in_sz) { |
| 858 | if (copy_to_user(karg.data_in_buf_ptr, data_in, |
| 859 | data_in_sz)) { |
| 860 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 861 | __LINE__, __func__); |
| 862 | ret = -ENODATA; |
| 863 | goto out; |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | /* copy out reply message frame to user */ |
| 868 | if (karg.max_reply_bytes) { |
| 869 | sz = min_t(u32, karg.max_reply_bytes, ioc->reply_sz); |
| 870 | if (copy_to_user(karg.reply_frame_buf_ptr, ioc->ctl_cmds.reply, |
| 871 | sz)) { |
| 872 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 873 | __LINE__, __func__); |
| 874 | ret = -ENODATA; |
| 875 | goto out; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | /* copy out sense to user */ |
| 880 | if (karg.max_sense_bytes && (mpi_request->Function == |
| 881 | MPI2_FUNCTION_SCSI_IO_REQUEST || mpi_request->Function == |
| 882 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { |
| 883 | sz = min_t(u32, karg.max_sense_bytes, SCSI_SENSE_BUFFERSIZE); |
| 884 | if (copy_to_user(karg.sense_data_ptr, priv_sense, sz)) { |
| 885 | printk(KERN_ERR "failure at %s:%d/%s()!\n", __FILE__, |
| 886 | __LINE__, __func__); |
| 887 | ret = -ENODATA; |
| 888 | goto out; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | issue_host_reset: |
| 893 | if (issue_reset) { |
Kashyap, Desai | b2ff36b | 2009-12-16 18:51:05 +0530 | [diff] [blame^] | 894 | ret = -ENODATA; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 895 | if ((mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 896 | mpi_request->Function == |
| 897 | MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)) { |
| 898 | printk(MPT2SAS_INFO_FMT "issue target reset: handle " |
| 899 | "= (0x%04x)\n", ioc->name, |
| 900 | mpi_request->FunctionDependent1); |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 901 | mpt2sas_halt_firmware(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 902 | mutex_lock(&ioc->tm_cmds.mutex); |
| 903 | mpt2sas_scsih_issue_tm(ioc, |
| 904 | mpi_request->FunctionDependent1, 0, |
| 905 | MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10); |
| 906 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 907 | mutex_unlock(&ioc->tm_cmds.mutex); |
| 908 | } else |
| 909 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 910 | FORCE_BIG_HAMMER); |
| 911 | } |
| 912 | |
| 913 | out: |
| 914 | |
| 915 | /* free memory associated with sg buffers */ |
| 916 | if (data_in) |
| 917 | pci_free_consistent(ioc->pdev, data_in_sz, data_in, |
| 918 | data_in_dma); |
| 919 | |
| 920 | if (data_out) |
| 921 | pci_free_consistent(ioc->pdev, data_out_sz, data_out, |
| 922 | data_out_dma); |
| 923 | |
| 924 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; |
| 925 | mutex_unlock(&ioc->ctl_cmds.mutex); |
| 926 | return ret; |
| 927 | } |
| 928 | |
| 929 | /** |
| 930 | * _ctl_getiocinfo - main handler for MPT2IOCINFO opcode |
| 931 | * @arg - user space buffer containing ioctl content |
| 932 | */ |
| 933 | static long |
| 934 | _ctl_getiocinfo(void __user *arg) |
| 935 | { |
| 936 | struct mpt2_ioctl_iocinfo karg; |
| 937 | struct MPT2SAS_ADAPTER *ioc; |
| 938 | u8 revision; |
| 939 | |
| 940 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 941 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 942 | __FILE__, __LINE__, __func__); |
| 943 | return -EFAULT; |
| 944 | } |
| 945 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 946 | return -ENODEV; |
| 947 | |
| 948 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name, |
| 949 | __func__)); |
| 950 | |
| 951 | memset(&karg, 0 , sizeof(karg)); |
| 952 | karg.adapter_type = MPT2_IOCTL_INTERFACE_SAS2; |
| 953 | if (ioc->pfacts) |
| 954 | karg.port_number = ioc->pfacts[0].PortNumber; |
| 955 | pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision); |
| 956 | karg.hw_rev = revision; |
| 957 | karg.pci_id = ioc->pdev->device; |
| 958 | karg.subsystem_device = ioc->pdev->subsystem_device; |
| 959 | karg.subsystem_vendor = ioc->pdev->subsystem_vendor; |
| 960 | karg.pci_information.u.bits.bus = ioc->pdev->bus->number; |
| 961 | karg.pci_information.u.bits.device = PCI_SLOT(ioc->pdev->devfn); |
| 962 | karg.pci_information.u.bits.function = PCI_FUNC(ioc->pdev->devfn); |
| 963 | karg.pci_information.segment_id = pci_domain_nr(ioc->pdev->bus); |
| 964 | karg.firmware_version = ioc->facts.FWVersion.Word; |
Eric Moore | e5f9bb1 | 2009-04-21 15:40:01 -0600 | [diff] [blame] | 965 | strcpy(karg.driver_version, MPT2SAS_DRIVER_NAME); |
| 966 | strcat(karg.driver_version, "-"); |
| 967 | strcat(karg.driver_version, MPT2SAS_DRIVER_VERSION); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 968 | karg.bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); |
| 969 | |
| 970 | if (copy_to_user(arg, &karg, sizeof(karg))) { |
| 971 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 972 | __FILE__, __LINE__, __func__); |
| 973 | return -EFAULT; |
| 974 | } |
| 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * _ctl_eventquery - main handler for MPT2EVENTQUERY opcode |
| 980 | * @arg - user space buffer containing ioctl content |
| 981 | */ |
| 982 | static long |
| 983 | _ctl_eventquery(void __user *arg) |
| 984 | { |
| 985 | struct mpt2_ioctl_eventquery karg; |
| 986 | struct MPT2SAS_ADAPTER *ioc; |
| 987 | |
| 988 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 989 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 990 | __FILE__, __LINE__, __func__); |
| 991 | return -EFAULT; |
| 992 | } |
| 993 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 994 | return -ENODEV; |
| 995 | |
| 996 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name, |
| 997 | __func__)); |
| 998 | |
| 999 | karg.event_entries = MPT2SAS_CTL_EVENT_LOG_SIZE; |
| 1000 | memcpy(karg.event_types, ioc->event_type, |
| 1001 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32)); |
| 1002 | |
| 1003 | if (copy_to_user(arg, &karg, sizeof(karg))) { |
| 1004 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1005 | __FILE__, __LINE__, __func__); |
| 1006 | return -EFAULT; |
| 1007 | } |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | /** |
| 1012 | * _ctl_eventenable - main handler for MPT2EVENTENABLE opcode |
| 1013 | * @arg - user space buffer containing ioctl content |
| 1014 | */ |
| 1015 | static long |
| 1016 | _ctl_eventenable(void __user *arg) |
| 1017 | { |
| 1018 | struct mpt2_ioctl_eventenable karg; |
| 1019 | struct MPT2SAS_ADAPTER *ioc; |
| 1020 | |
| 1021 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1022 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1023 | __FILE__, __LINE__, __func__); |
| 1024 | return -EFAULT; |
| 1025 | } |
| 1026 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1027 | return -ENODEV; |
| 1028 | |
| 1029 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name, |
| 1030 | __func__)); |
| 1031 | |
| 1032 | if (ioc->event_log) |
| 1033 | return 0; |
| 1034 | memcpy(ioc->event_type, karg.event_types, |
| 1035 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS * sizeof(u32)); |
| 1036 | mpt2sas_base_validate_event_type(ioc, ioc->event_type); |
| 1037 | |
| 1038 | /* initialize event_log */ |
| 1039 | ioc->event_context = 0; |
| 1040 | ioc->aen_event_read_flag = 0; |
| 1041 | ioc->event_log = kcalloc(MPT2SAS_CTL_EVENT_LOG_SIZE, |
| 1042 | sizeof(struct MPT2_IOCTL_EVENTS), GFP_KERNEL); |
| 1043 | if (!ioc->event_log) { |
| 1044 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1045 | __FILE__, __LINE__, __func__); |
| 1046 | return -ENOMEM; |
| 1047 | } |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * _ctl_eventreport - main handler for MPT2EVENTREPORT opcode |
| 1053 | * @arg - user space buffer containing ioctl content |
| 1054 | */ |
| 1055 | static long |
| 1056 | _ctl_eventreport(void __user *arg) |
| 1057 | { |
| 1058 | struct mpt2_ioctl_eventreport karg; |
| 1059 | struct MPT2SAS_ADAPTER *ioc; |
| 1060 | u32 number_bytes, max_events, max; |
| 1061 | struct mpt2_ioctl_eventreport __user *uarg = arg; |
| 1062 | |
| 1063 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1064 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1065 | __FILE__, __LINE__, __func__); |
| 1066 | return -EFAULT; |
| 1067 | } |
| 1068 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1069 | return -ENODEV; |
| 1070 | |
| 1071 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name, |
| 1072 | __func__)); |
| 1073 | |
| 1074 | number_bytes = karg.hdr.max_data_size - |
| 1075 | sizeof(struct mpt2_ioctl_header); |
| 1076 | max_events = number_bytes/sizeof(struct MPT2_IOCTL_EVENTS); |
| 1077 | max = min_t(u32, MPT2SAS_CTL_EVENT_LOG_SIZE, max_events); |
| 1078 | |
| 1079 | /* If fewer than 1 event is requested, there must have |
| 1080 | * been some type of error. |
| 1081 | */ |
| 1082 | if (!max || !ioc->event_log) |
| 1083 | return -ENODATA; |
| 1084 | |
| 1085 | number_bytes = max * sizeof(struct MPT2_IOCTL_EVENTS); |
| 1086 | if (copy_to_user(uarg->event_data, ioc->event_log, number_bytes)) { |
| 1087 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1088 | __FILE__, __LINE__, __func__); |
| 1089 | return -EFAULT; |
| 1090 | } |
| 1091 | |
| 1092 | /* reset flag so SIGIO can restart */ |
| 1093 | ioc->aen_event_read_flag = 0; |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * _ctl_do_reset - main handler for MPT2HARDRESET opcode |
| 1099 | * @arg - user space buffer containing ioctl content |
| 1100 | */ |
| 1101 | static long |
| 1102 | _ctl_do_reset(void __user *arg) |
| 1103 | { |
| 1104 | struct mpt2_ioctl_diag_reset karg; |
| 1105 | struct MPT2SAS_ADAPTER *ioc; |
| 1106 | int retval; |
| 1107 | |
| 1108 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1109 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1110 | __FILE__, __LINE__, __func__); |
| 1111 | return -EFAULT; |
| 1112 | } |
| 1113 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1114 | return -ENODEV; |
| 1115 | |
| 1116 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name, |
| 1117 | __func__)); |
| 1118 | |
| 1119 | retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 1120 | FORCE_BIG_HAMMER); |
| 1121 | printk(MPT2SAS_INFO_FMT "host reset: %s\n", |
| 1122 | ioc->name, ((!retval) ? "SUCCESS" : "FAILED")); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * _ctl_btdh_search_sas_device - searching for sas device |
| 1128 | * @ioc: per adapter object |
| 1129 | * @btdh: btdh ioctl payload |
| 1130 | */ |
| 1131 | static int |
| 1132 | _ctl_btdh_search_sas_device(struct MPT2SAS_ADAPTER *ioc, |
| 1133 | struct mpt2_ioctl_btdh_mapping *btdh) |
| 1134 | { |
| 1135 | struct _sas_device *sas_device; |
| 1136 | unsigned long flags; |
| 1137 | int rc = 0; |
| 1138 | |
| 1139 | if (list_empty(&ioc->sas_device_list)) |
| 1140 | return rc; |
| 1141 | |
| 1142 | spin_lock_irqsave(&ioc->sas_device_lock, flags); |
| 1143 | list_for_each_entry(sas_device, &ioc->sas_device_list, list) { |
| 1144 | if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF && |
| 1145 | btdh->handle == sas_device->handle) { |
| 1146 | btdh->bus = sas_device->channel; |
| 1147 | btdh->id = sas_device->id; |
| 1148 | rc = 1; |
| 1149 | goto out; |
| 1150 | } else if (btdh->bus == sas_device->channel && btdh->id == |
| 1151 | sas_device->id && btdh->handle == 0xFFFF) { |
| 1152 | btdh->handle = sas_device->handle; |
| 1153 | rc = 1; |
| 1154 | goto out; |
| 1155 | } |
| 1156 | } |
| 1157 | out: |
| 1158 | spin_unlock_irqrestore(&ioc->sas_device_lock, flags); |
| 1159 | return rc; |
| 1160 | } |
| 1161 | |
| 1162 | /** |
| 1163 | * _ctl_btdh_search_raid_device - searching for raid device |
| 1164 | * @ioc: per adapter object |
| 1165 | * @btdh: btdh ioctl payload |
| 1166 | */ |
| 1167 | static int |
| 1168 | _ctl_btdh_search_raid_device(struct MPT2SAS_ADAPTER *ioc, |
| 1169 | struct mpt2_ioctl_btdh_mapping *btdh) |
| 1170 | { |
| 1171 | struct _raid_device *raid_device; |
| 1172 | unsigned long flags; |
| 1173 | int rc = 0; |
| 1174 | |
| 1175 | if (list_empty(&ioc->raid_device_list)) |
| 1176 | return rc; |
| 1177 | |
| 1178 | spin_lock_irqsave(&ioc->raid_device_lock, flags); |
| 1179 | list_for_each_entry(raid_device, &ioc->raid_device_list, list) { |
| 1180 | if (btdh->bus == 0xFFFFFFFF && btdh->id == 0xFFFFFFFF && |
| 1181 | btdh->handle == raid_device->handle) { |
| 1182 | btdh->bus = raid_device->channel; |
| 1183 | btdh->id = raid_device->id; |
| 1184 | rc = 1; |
| 1185 | goto out; |
| 1186 | } else if (btdh->bus == raid_device->channel && btdh->id == |
| 1187 | raid_device->id && btdh->handle == 0xFFFF) { |
| 1188 | btdh->handle = raid_device->handle; |
| 1189 | rc = 1; |
| 1190 | goto out; |
| 1191 | } |
| 1192 | } |
| 1193 | out: |
| 1194 | spin_unlock_irqrestore(&ioc->raid_device_lock, flags); |
| 1195 | return rc; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * _ctl_btdh_mapping - main handler for MPT2BTDHMAPPING opcode |
| 1200 | * @arg - user space buffer containing ioctl content |
| 1201 | */ |
| 1202 | static long |
| 1203 | _ctl_btdh_mapping(void __user *arg) |
| 1204 | { |
| 1205 | struct mpt2_ioctl_btdh_mapping karg; |
| 1206 | struct MPT2SAS_ADAPTER *ioc; |
| 1207 | int rc; |
| 1208 | |
| 1209 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1210 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1211 | __FILE__, __LINE__, __func__); |
| 1212 | return -EFAULT; |
| 1213 | } |
| 1214 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1215 | return -ENODEV; |
| 1216 | |
| 1217 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1218 | __func__)); |
| 1219 | |
| 1220 | rc = _ctl_btdh_search_sas_device(ioc, &karg); |
| 1221 | if (!rc) |
| 1222 | _ctl_btdh_search_raid_device(ioc, &karg); |
| 1223 | |
| 1224 | if (copy_to_user(arg, &karg, sizeof(karg))) { |
| 1225 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1226 | __FILE__, __LINE__, __func__); |
| 1227 | return -EFAULT; |
| 1228 | } |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * _ctl_diag_capability - return diag buffer capability |
| 1234 | * @ioc: per adapter object |
Kashyap, Desai | 1b01fe3 | 2009-09-23 17:28:59 +0530 | [diff] [blame] | 1235 | * @buffer_type: specifies either TRACE, SNAPSHOT, or EXTENDED |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1236 | * |
| 1237 | * returns 1 when diag buffer support is enabled in firmware |
| 1238 | */ |
| 1239 | static u8 |
| 1240 | _ctl_diag_capability(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type) |
| 1241 | { |
| 1242 | u8 rc = 0; |
| 1243 | |
| 1244 | switch (buffer_type) { |
| 1245 | case MPI2_DIAG_BUF_TYPE_TRACE: |
| 1246 | if (ioc->facts.IOCCapabilities & |
| 1247 | MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) |
| 1248 | rc = 1; |
| 1249 | break; |
| 1250 | case MPI2_DIAG_BUF_TYPE_SNAPSHOT: |
| 1251 | if (ioc->facts.IOCCapabilities & |
| 1252 | MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) |
| 1253 | rc = 1; |
| 1254 | break; |
Kashyap, Desai | 1b01fe3 | 2009-09-23 17:28:59 +0530 | [diff] [blame] | 1255 | case MPI2_DIAG_BUF_TYPE_EXTENDED: |
| 1256 | if (ioc->facts.IOCCapabilities & |
| 1257 | MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) |
| 1258 | rc = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | return rc; |
| 1262 | } |
| 1263 | |
| 1264 | /** |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1265 | * _ctl_diag_register_2 - wrapper for registering diag buffer support |
| 1266 | * @ioc: per adapter object |
| 1267 | * @diag_register: the diag_register struct passed in from user space |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1268 | * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1269 | */ |
| 1270 | static long |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1271 | _ctl_diag_register_2(struct MPT2SAS_ADAPTER *ioc, |
| 1272 | struct mpt2_diag_register *diag_register) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1273 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1274 | int rc, i; |
| 1275 | void *request_data = NULL; |
| 1276 | dma_addr_t request_data_dma; |
| 1277 | u32 request_data_sz = 0; |
| 1278 | Mpi2DiagBufferPostRequest_t *mpi_request; |
| 1279 | Mpi2DiagBufferPostReply_t *mpi_reply; |
| 1280 | u8 buffer_type; |
| 1281 | unsigned long timeleft; |
| 1282 | u16 smid; |
| 1283 | u16 ioc_status; |
| 1284 | u8 issue_reset = 0; |
| 1285 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1286 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1287 | __func__)); |
| 1288 | |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1289 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { |
| 1290 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", |
| 1291 | ioc->name, __func__); |
| 1292 | rc = -EAGAIN; |
| 1293 | goto out; |
| 1294 | } |
| 1295 | |
| 1296 | buffer_type = diag_register->buffer_type; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1297 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
| 1298 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " |
| 1299 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1300 | return -EPERM; |
| 1301 | } |
| 1302 | |
| 1303 | if (ioc->diag_buffer_status[buffer_type] & |
| 1304 | MPT2_DIAG_BUFFER_IS_REGISTERED) { |
| 1305 | printk(MPT2SAS_ERR_FMT "%s: already has a registered " |
| 1306 | "buffer for buffer_type(0x%02x)\n", ioc->name, __func__, |
| 1307 | buffer_type); |
| 1308 | return -EINVAL; |
| 1309 | } |
| 1310 | |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1311 | if (diag_register->requested_buffer_size % 4) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1312 | printk(MPT2SAS_ERR_FMT "%s: the requested_buffer_size " |
| 1313 | "is not 4 byte aligned\n", ioc->name, __func__); |
| 1314 | return -EINVAL; |
| 1315 | } |
| 1316 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1317 | smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx); |
| 1318 | if (!smid) { |
| 1319 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 1320 | ioc->name, __func__); |
| 1321 | rc = -EAGAIN; |
| 1322 | goto out; |
| 1323 | } |
| 1324 | |
| 1325 | rc = 0; |
| 1326 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; |
| 1327 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 1328 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1329 | ioc->ctl_cmds.smid = smid; |
| 1330 | |
| 1331 | request_data = ioc->diag_buffer[buffer_type]; |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1332 | request_data_sz = diag_register->requested_buffer_size; |
| 1333 | ioc->unique_id[buffer_type] = diag_register->unique_id; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1334 | ioc->diag_buffer_status[buffer_type] = 0; |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1335 | memcpy(ioc->product_specific[buffer_type], |
| 1336 | diag_register->product_specific, MPT2_PRODUCT_SPECIFIC_DWORDS); |
| 1337 | ioc->diagnostic_flags[buffer_type] = diag_register->diagnostic_flags; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1338 | |
| 1339 | if (request_data) { |
| 1340 | request_data_dma = ioc->diag_buffer_dma[buffer_type]; |
| 1341 | if (request_data_sz != ioc->diag_buffer_sz[buffer_type]) { |
| 1342 | pci_free_consistent(ioc->pdev, |
| 1343 | ioc->diag_buffer_sz[buffer_type], |
| 1344 | request_data, request_data_dma); |
| 1345 | request_data = NULL; |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | if (request_data == NULL) { |
| 1350 | ioc->diag_buffer_sz[buffer_type] = 0; |
| 1351 | ioc->diag_buffer_dma[buffer_type] = 0; |
| 1352 | request_data = pci_alloc_consistent( |
| 1353 | ioc->pdev, request_data_sz, &request_data_dma); |
| 1354 | if (request_data == NULL) { |
| 1355 | printk(MPT2SAS_ERR_FMT "%s: failed allocating memory" |
| 1356 | " for diag buffers, requested size(%d)\n", |
| 1357 | ioc->name, __func__, request_data_sz); |
| 1358 | mpt2sas_base_free_smid(ioc, smid); |
| 1359 | return -ENOMEM; |
| 1360 | } |
| 1361 | ioc->diag_buffer[buffer_type] = request_data; |
| 1362 | ioc->diag_buffer_sz[buffer_type] = request_data_sz; |
| 1363 | ioc->diag_buffer_dma[buffer_type] = request_data_dma; |
| 1364 | } |
| 1365 | |
| 1366 | mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST; |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1367 | mpi_request->BufferType = diag_register->buffer_type; |
| 1368 | mpi_request->Flags = cpu_to_le32(diag_register->diagnostic_flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1369 | mpi_request->BufferAddress = cpu_to_le64(request_data_dma); |
| 1370 | mpi_request->BufferLength = cpu_to_le32(request_data_sz); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1371 | mpi_request->VF_ID = 0; /* TODO */ |
| 1372 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1373 | |
| 1374 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: diag_buffer(0x%p), " |
| 1375 | "dma(0x%llx), sz(%d)\n", ioc->name, __func__, request_data, |
| 1376 | (unsigned long long)request_data_dma, mpi_request->BufferLength)); |
| 1377 | |
| 1378 | for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++) |
| 1379 | mpi_request->ProductSpecific[i] = |
| 1380 | cpu_to_le32(ioc->product_specific[buffer_type][i]); |
| 1381 | |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1382 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 1383 | init_completion(&ioc->ctl_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1384 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, |
| 1385 | MPT2_IOCTL_DEFAULT_TIMEOUT*HZ); |
| 1386 | |
| 1387 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { |
| 1388 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, |
| 1389 | __func__); |
| 1390 | _debug_dump_mf(mpi_request, |
| 1391 | sizeof(Mpi2DiagBufferPostRequest_t)/4); |
| 1392 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) |
| 1393 | issue_reset = 1; |
| 1394 | goto issue_host_reset; |
| 1395 | } |
| 1396 | |
| 1397 | /* process the completed Reply Message Frame */ |
| 1398 | if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) { |
| 1399 | printk(MPT2SAS_ERR_FMT "%s: no reply message\n", |
| 1400 | ioc->name, __func__); |
| 1401 | rc = -EFAULT; |
| 1402 | goto out; |
| 1403 | } |
| 1404 | |
| 1405 | mpi_reply = ioc->ctl_cmds.reply; |
| 1406 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 1407 | |
| 1408 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 1409 | ioc->diag_buffer_status[buffer_type] |= |
| 1410 | MPT2_DIAG_BUFFER_IS_REGISTERED; |
| 1411 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n", |
| 1412 | ioc->name, __func__)); |
| 1413 | } else { |
| 1414 | printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) " |
| 1415 | "log_info(0x%08x)\n", ioc->name, __func__, |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 1416 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1417 | rc = -EFAULT; |
| 1418 | } |
| 1419 | |
| 1420 | issue_host_reset: |
| 1421 | if (issue_reset) |
| 1422 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 1423 | FORCE_BIG_HAMMER); |
| 1424 | |
| 1425 | out: |
| 1426 | |
| 1427 | if (rc && request_data) |
| 1428 | pci_free_consistent(ioc->pdev, request_data_sz, |
| 1429 | request_data, request_data_dma); |
| 1430 | |
| 1431 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1432 | return rc; |
| 1433 | } |
| 1434 | |
| 1435 | /** |
| 1436 | * mpt2sas_enable_diag_buffer - enabling diag_buffers support driver load time |
| 1437 | * @ioc: per adapter object |
| 1438 | * @bits_to_register: bitwise field where trace is bit 0, and snapshot is bit 1 |
| 1439 | * |
| 1440 | * This is called when command line option diag_buffer_enable is enabled |
| 1441 | * at driver load time. |
| 1442 | */ |
| 1443 | void |
| 1444 | mpt2sas_enable_diag_buffer(struct MPT2SAS_ADAPTER *ioc, u8 bits_to_register) |
| 1445 | { |
| 1446 | struct mpt2_diag_register diag_register; |
| 1447 | |
| 1448 | memset(&diag_register, 0, sizeof(struct mpt2_diag_register)); |
| 1449 | |
| 1450 | if (bits_to_register & 1) { |
| 1451 | printk(MPT2SAS_INFO_FMT "registering trace buffer support\n", |
| 1452 | ioc->name); |
| 1453 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_TRACE; |
| 1454 | /* register for 1MB buffers */ |
| 1455 | diag_register.requested_buffer_size = (1024 * 1024); |
| 1456 | diag_register.unique_id = 0x7075900; |
| 1457 | _ctl_diag_register_2(ioc, &diag_register); |
| 1458 | } |
| 1459 | |
| 1460 | if (bits_to_register & 2) { |
| 1461 | printk(MPT2SAS_INFO_FMT "registering snapshot buffer support\n", |
| 1462 | ioc->name); |
| 1463 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_SNAPSHOT; |
| 1464 | /* register for 2MB buffers */ |
| 1465 | diag_register.requested_buffer_size = 2 * (1024 * 1024); |
| 1466 | diag_register.unique_id = 0x7075901; |
| 1467 | _ctl_diag_register_2(ioc, &diag_register); |
| 1468 | } |
Kashyap, Desai | 1b01fe3 | 2009-09-23 17:28:59 +0530 | [diff] [blame] | 1469 | |
| 1470 | if (bits_to_register & 4) { |
| 1471 | printk(MPT2SAS_INFO_FMT "registering extended buffer support\n", |
| 1472 | ioc->name); |
| 1473 | diag_register.buffer_type = MPI2_DIAG_BUF_TYPE_EXTENDED; |
| 1474 | /* register for 2MB buffers */ |
| 1475 | diag_register.requested_buffer_size = 2 * (1024 * 1024); |
| 1476 | diag_register.unique_id = 0x7075901; |
| 1477 | _ctl_diag_register_2(ioc, &diag_register); |
| 1478 | } |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | /** |
| 1482 | * _ctl_diag_register - application register with driver |
| 1483 | * @arg - user space buffer containing ioctl content |
| 1484 | * @state - NON_BLOCKING or BLOCKING |
| 1485 | * |
| 1486 | * This will allow the driver to setup any required buffers that will be |
| 1487 | * needed by firmware to communicate with the driver. |
| 1488 | */ |
| 1489 | static long |
| 1490 | _ctl_diag_register(void __user *arg, enum block_state state) |
| 1491 | { |
| 1492 | struct mpt2_diag_register karg; |
| 1493 | struct MPT2SAS_ADAPTER *ioc; |
| 1494 | long rc; |
| 1495 | |
| 1496 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1497 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1498 | __FILE__, __LINE__, __func__); |
| 1499 | return -EFAULT; |
| 1500 | } |
| 1501 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1502 | return -ENODEV; |
| 1503 | |
| 1504 | if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) |
| 1505 | return -EAGAIN; |
| 1506 | else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) |
| 1507 | return -ERESTARTSYS; |
| 1508 | rc = _ctl_diag_register_2(ioc, &karg); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1509 | mutex_unlock(&ioc->ctl_cmds.mutex); |
| 1510 | return rc; |
| 1511 | } |
| 1512 | |
| 1513 | /** |
| 1514 | * _ctl_diag_unregister - application unregister with driver |
| 1515 | * @arg - user space buffer containing ioctl content |
| 1516 | * |
| 1517 | * This will allow the driver to cleanup any memory allocated for diag |
| 1518 | * messages and to free up any resources. |
| 1519 | */ |
| 1520 | static long |
| 1521 | _ctl_diag_unregister(void __user *arg) |
| 1522 | { |
| 1523 | struct mpt2_diag_unregister karg; |
| 1524 | struct MPT2SAS_ADAPTER *ioc; |
| 1525 | void *request_data; |
| 1526 | dma_addr_t request_data_dma; |
| 1527 | u32 request_data_sz; |
| 1528 | u8 buffer_type; |
| 1529 | |
| 1530 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1531 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1532 | __FILE__, __LINE__, __func__); |
| 1533 | return -EFAULT; |
| 1534 | } |
| 1535 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1536 | return -ENODEV; |
| 1537 | |
| 1538 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1539 | __func__)); |
| 1540 | |
| 1541 | buffer_type = karg.unique_id & 0x000000ff; |
| 1542 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
| 1543 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " |
| 1544 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1545 | return -EPERM; |
| 1546 | } |
| 1547 | |
| 1548 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1549 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { |
| 1550 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not " |
| 1551 | "registered\n", ioc->name, __func__, buffer_type); |
| 1552 | return -EINVAL; |
| 1553 | } |
| 1554 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1555 | MPT2_DIAG_BUFFER_IS_RELEASED) == 0) { |
| 1556 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) has not been " |
| 1557 | "released\n", ioc->name, __func__, buffer_type); |
| 1558 | return -EINVAL; |
| 1559 | } |
| 1560 | |
| 1561 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
| 1562 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " |
| 1563 | "registered\n", ioc->name, __func__, karg.unique_id); |
| 1564 | return -EINVAL; |
| 1565 | } |
| 1566 | |
| 1567 | request_data = ioc->diag_buffer[buffer_type]; |
| 1568 | if (!request_data) { |
| 1569 | printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for " |
| 1570 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1571 | return -ENOMEM; |
| 1572 | } |
| 1573 | |
| 1574 | request_data_sz = ioc->diag_buffer_sz[buffer_type]; |
| 1575 | request_data_dma = ioc->diag_buffer_dma[buffer_type]; |
| 1576 | pci_free_consistent(ioc->pdev, request_data_sz, |
| 1577 | request_data, request_data_dma); |
| 1578 | ioc->diag_buffer[buffer_type] = NULL; |
| 1579 | ioc->diag_buffer_status[buffer_type] = 0; |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
| 1583 | /** |
| 1584 | * _ctl_diag_query - query relevant info associated with diag buffers |
| 1585 | * @arg - user space buffer containing ioctl content |
| 1586 | * |
| 1587 | * The application will send only buffer_type and unique_id. Driver will |
| 1588 | * inspect unique_id first, if valid, fill in all the info. If unique_id is |
| 1589 | * 0x00, the driver will return info specified by Buffer Type. |
| 1590 | */ |
| 1591 | static long |
| 1592 | _ctl_diag_query(void __user *arg) |
| 1593 | { |
| 1594 | struct mpt2_diag_query karg; |
| 1595 | struct MPT2SAS_ADAPTER *ioc; |
| 1596 | void *request_data; |
| 1597 | int i; |
| 1598 | u8 buffer_type; |
| 1599 | |
| 1600 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1601 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1602 | __FILE__, __LINE__, __func__); |
| 1603 | return -EFAULT; |
| 1604 | } |
| 1605 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1606 | return -ENODEV; |
| 1607 | |
| 1608 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1609 | __func__)); |
| 1610 | |
| 1611 | karg.application_flags = 0; |
| 1612 | buffer_type = karg.buffer_type; |
| 1613 | |
| 1614 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
| 1615 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " |
| 1616 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1617 | return -EPERM; |
| 1618 | } |
| 1619 | |
| 1620 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1621 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { |
| 1622 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not " |
| 1623 | "registered\n", ioc->name, __func__, buffer_type); |
| 1624 | return -EINVAL; |
| 1625 | } |
| 1626 | |
| 1627 | if (karg.unique_id & 0xffffff00) { |
| 1628 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
| 1629 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " |
| 1630 | "registered\n", ioc->name, __func__, |
| 1631 | karg.unique_id); |
| 1632 | return -EINVAL; |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | request_data = ioc->diag_buffer[buffer_type]; |
| 1637 | if (!request_data) { |
| 1638 | printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for " |
| 1639 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1640 | return -ENOMEM; |
| 1641 | } |
| 1642 | |
| 1643 | if (ioc->diag_buffer_status[buffer_type] & MPT2_DIAG_BUFFER_IS_RELEASED) |
| 1644 | karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED | |
| 1645 | MPT2_APP_FLAGS_BUFFER_VALID); |
| 1646 | else |
| 1647 | karg.application_flags = (MPT2_APP_FLAGS_APP_OWNED | |
| 1648 | MPT2_APP_FLAGS_BUFFER_VALID | |
| 1649 | MPT2_APP_FLAGS_FW_BUFFER_ACCESS); |
| 1650 | |
| 1651 | for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++) |
| 1652 | karg.product_specific[i] = |
| 1653 | ioc->product_specific[buffer_type][i]; |
| 1654 | |
| 1655 | karg.total_buffer_size = ioc->diag_buffer_sz[buffer_type]; |
| 1656 | karg.driver_added_buffer_size = 0; |
| 1657 | karg.unique_id = ioc->unique_id[buffer_type]; |
| 1658 | karg.diagnostic_flags = ioc->diagnostic_flags[buffer_type]; |
| 1659 | |
| 1660 | if (copy_to_user(arg, &karg, sizeof(struct mpt2_diag_query))) { |
| 1661 | printk(MPT2SAS_ERR_FMT "%s: unable to write mpt2_diag_query " |
| 1662 | "data @ %p\n", ioc->name, __func__, arg); |
| 1663 | return -EFAULT; |
| 1664 | } |
| 1665 | return 0; |
| 1666 | } |
| 1667 | |
| 1668 | /** |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 1669 | * _ctl_send_release - Diag Release Message |
| 1670 | * @ioc: per adapter object |
Kashyap, Desai | 1b01fe3 | 2009-09-23 17:28:59 +0530 | [diff] [blame] | 1671 | * @buffer_type - specifies either TRACE, SNAPSHOT, or EXTENDED |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 1672 | * @issue_reset - specifies whether host reset is required. |
| 1673 | * |
| 1674 | */ |
| 1675 | static int |
| 1676 | _ctl_send_release(struct MPT2SAS_ADAPTER *ioc, u8 buffer_type, u8 *issue_reset) |
| 1677 | { |
| 1678 | Mpi2DiagReleaseRequest_t *mpi_request; |
| 1679 | Mpi2DiagReleaseReply_t *mpi_reply; |
| 1680 | u16 smid; |
| 1681 | u16 ioc_status; |
| 1682 | u32 ioc_state; |
| 1683 | int rc; |
| 1684 | unsigned long timeleft; |
| 1685 | |
| 1686 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1687 | __func__)); |
| 1688 | |
| 1689 | rc = 0; |
| 1690 | *issue_reset = 0; |
| 1691 | |
| 1692 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 1693 | if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 1694 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 1695 | "skipping due to FAULT state\n", ioc->name, |
| 1696 | __func__)); |
| 1697 | rc = -EAGAIN; |
| 1698 | goto out; |
| 1699 | } |
| 1700 | |
| 1701 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { |
| 1702 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", |
| 1703 | ioc->name, __func__); |
| 1704 | rc = -EAGAIN; |
| 1705 | goto out; |
| 1706 | } |
| 1707 | |
| 1708 | smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx); |
| 1709 | if (!smid) { |
| 1710 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 1711 | ioc->name, __func__); |
| 1712 | rc = -EAGAIN; |
| 1713 | goto out; |
| 1714 | } |
| 1715 | |
| 1716 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; |
| 1717 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 1718 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1719 | ioc->ctl_cmds.smid = smid; |
| 1720 | |
| 1721 | mpi_request->Function = MPI2_FUNCTION_DIAG_RELEASE; |
| 1722 | mpi_request->BufferType = buffer_type; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1723 | mpi_request->VF_ID = 0; /* TODO */ |
| 1724 | mpi_request->VP_ID = 0; |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 1725 | |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1726 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 1727 | init_completion(&ioc->ctl_cmds.done); |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 1728 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, |
| 1729 | MPT2_IOCTL_DEFAULT_TIMEOUT*HZ); |
| 1730 | |
| 1731 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { |
| 1732 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, |
| 1733 | __func__); |
| 1734 | _debug_dump_mf(mpi_request, |
| 1735 | sizeof(Mpi2DiagReleaseRequest_t)/4); |
| 1736 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) |
| 1737 | *issue_reset = 1; |
| 1738 | rc = -EFAULT; |
| 1739 | goto out; |
| 1740 | } |
| 1741 | |
| 1742 | /* process the completed Reply Message Frame */ |
| 1743 | if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) { |
| 1744 | printk(MPT2SAS_ERR_FMT "%s: no reply message\n", |
| 1745 | ioc->name, __func__); |
| 1746 | rc = -EFAULT; |
| 1747 | goto out; |
| 1748 | } |
| 1749 | |
| 1750 | mpi_reply = ioc->ctl_cmds.reply; |
| 1751 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 1752 | |
| 1753 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 1754 | ioc->diag_buffer_status[buffer_type] |= |
| 1755 | MPT2_DIAG_BUFFER_IS_RELEASED; |
| 1756 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n", |
| 1757 | ioc->name, __func__)); |
| 1758 | } else { |
| 1759 | printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) " |
| 1760 | "log_info(0x%08x)\n", ioc->name, __func__, |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 1761 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 1762 | rc = -EFAULT; |
| 1763 | } |
| 1764 | |
| 1765 | out: |
| 1766 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; |
| 1767 | return rc; |
| 1768 | } |
| 1769 | |
| 1770 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1771 | * _ctl_diag_release - request to send Diag Release Message to firmware |
| 1772 | * @arg - user space buffer containing ioctl content |
| 1773 | * @state - NON_BLOCKING or BLOCKING |
| 1774 | * |
| 1775 | * This allows ownership of the specified buffer to returned to the driver, |
| 1776 | * allowing an application to read the buffer without fear that firmware is |
| 1777 | * overwritting information in the buffer. |
| 1778 | */ |
| 1779 | static long |
| 1780 | _ctl_diag_release(void __user *arg, enum block_state state) |
| 1781 | { |
| 1782 | struct mpt2_diag_release karg; |
| 1783 | struct MPT2SAS_ADAPTER *ioc; |
| 1784 | void *request_data; |
| 1785 | int rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1786 | u8 buffer_type; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1787 | u8 issue_reset = 0; |
| 1788 | |
| 1789 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1790 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1791 | __FILE__, __LINE__, __func__); |
| 1792 | return -EFAULT; |
| 1793 | } |
| 1794 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1795 | return -ENODEV; |
| 1796 | |
| 1797 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1798 | __func__)); |
| 1799 | |
| 1800 | buffer_type = karg.unique_id & 0x000000ff; |
| 1801 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
| 1802 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " |
| 1803 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1804 | return -EPERM; |
| 1805 | } |
| 1806 | |
| 1807 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1808 | MPT2_DIAG_BUFFER_IS_REGISTERED) == 0) { |
| 1809 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) is not " |
| 1810 | "registered\n", ioc->name, __func__, buffer_type); |
| 1811 | return -EINVAL; |
| 1812 | } |
| 1813 | |
| 1814 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
| 1815 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " |
| 1816 | "registered\n", ioc->name, __func__, karg.unique_id); |
| 1817 | return -EINVAL; |
| 1818 | } |
| 1819 | |
| 1820 | if (ioc->diag_buffer_status[buffer_type] & |
| 1821 | MPT2_DIAG_BUFFER_IS_RELEASED) { |
| 1822 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) " |
| 1823 | "is already released\n", ioc->name, __func__, |
| 1824 | buffer_type); |
| 1825 | return 0; |
| 1826 | } |
| 1827 | |
| 1828 | request_data = ioc->diag_buffer[buffer_type]; |
| 1829 | |
| 1830 | if (!request_data) { |
| 1831 | printk(MPT2SAS_ERR_FMT "%s: doesn't have memory allocated for " |
| 1832 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1833 | return -ENOMEM; |
| 1834 | } |
| 1835 | |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 1836 | /* buffers were released by due to host reset */ |
| 1837 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1838 | MPT2_DIAG_BUFFER_IS_DIAG_RESET)) { |
| 1839 | ioc->diag_buffer_status[buffer_type] |= |
| 1840 | MPT2_DIAG_BUFFER_IS_RELEASED; |
| 1841 | ioc->diag_buffer_status[buffer_type] &= |
| 1842 | ~MPT2_DIAG_BUFFER_IS_DIAG_RESET; |
| 1843 | printk(MPT2SAS_ERR_FMT "%s: buffer_type(0x%02x) " |
| 1844 | "was released due to host reset\n", ioc->name, __func__, |
| 1845 | buffer_type); |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1849 | if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) |
| 1850 | return -EAGAIN; |
| 1851 | else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) |
| 1852 | return -ERESTARTSYS; |
| 1853 | |
Eric Moore | 99bb214 | 2009-04-21 15:42:13 -0600 | [diff] [blame] | 1854 | rc = _ctl_send_release(ioc, buffer_type, &issue_reset); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1855 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1856 | if (issue_reset) |
| 1857 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 1858 | FORCE_BIG_HAMMER); |
| 1859 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1860 | mutex_unlock(&ioc->ctl_cmds.mutex); |
| 1861 | return rc; |
| 1862 | } |
| 1863 | |
| 1864 | /** |
| 1865 | * _ctl_diag_read_buffer - request for copy of the diag buffer |
| 1866 | * @arg - user space buffer containing ioctl content |
| 1867 | * @state - NON_BLOCKING or BLOCKING |
| 1868 | */ |
| 1869 | static long |
| 1870 | _ctl_diag_read_buffer(void __user *arg, enum block_state state) |
| 1871 | { |
| 1872 | struct mpt2_diag_read_buffer karg; |
| 1873 | struct mpt2_diag_read_buffer __user *uarg = arg; |
| 1874 | struct MPT2SAS_ADAPTER *ioc; |
| 1875 | void *request_data, *diag_data; |
| 1876 | Mpi2DiagBufferPostRequest_t *mpi_request; |
| 1877 | Mpi2DiagBufferPostReply_t *mpi_reply; |
| 1878 | int rc, i; |
| 1879 | u8 buffer_type; |
| 1880 | unsigned long timeleft; |
| 1881 | u16 smid; |
| 1882 | u16 ioc_status; |
| 1883 | u8 issue_reset = 0; |
| 1884 | |
| 1885 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 1886 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 1887 | __FILE__, __LINE__, __func__); |
| 1888 | return -EFAULT; |
| 1889 | } |
| 1890 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 1891 | return -ENODEV; |
| 1892 | |
| 1893 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1894 | __func__)); |
| 1895 | |
| 1896 | buffer_type = karg.unique_id & 0x000000ff; |
| 1897 | if (!_ctl_diag_capability(ioc, buffer_type)) { |
| 1898 | printk(MPT2SAS_ERR_FMT "%s: doesn't have capability for " |
| 1899 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1900 | return -EPERM; |
| 1901 | } |
| 1902 | |
| 1903 | if (karg.unique_id != ioc->unique_id[buffer_type]) { |
| 1904 | printk(MPT2SAS_ERR_FMT "%s: unique_id(0x%08x) is not " |
| 1905 | "registered\n", ioc->name, __func__, karg.unique_id); |
| 1906 | return -EINVAL; |
| 1907 | } |
| 1908 | |
| 1909 | request_data = ioc->diag_buffer[buffer_type]; |
| 1910 | if (!request_data) { |
| 1911 | printk(MPT2SAS_ERR_FMT "%s: doesn't have buffer for " |
| 1912 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type); |
| 1913 | return -ENOMEM; |
| 1914 | } |
| 1915 | |
| 1916 | if ((karg.starting_offset % 4) || (karg.bytes_to_read % 4)) { |
| 1917 | printk(MPT2SAS_ERR_FMT "%s: either the starting_offset " |
| 1918 | "or bytes_to_read are not 4 byte aligned\n", ioc->name, |
| 1919 | __func__); |
| 1920 | return -EINVAL; |
| 1921 | } |
| 1922 | |
| 1923 | diag_data = (void *)(request_data + karg.starting_offset); |
| 1924 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: diag_buffer(%p), " |
| 1925 | "offset(%d), sz(%d)\n", ioc->name, __func__, |
| 1926 | diag_data, karg.starting_offset, karg.bytes_to_read)); |
| 1927 | |
| 1928 | if (copy_to_user((void __user *)uarg->diagnostic_data, |
| 1929 | diag_data, karg.bytes_to_read)) { |
| 1930 | printk(MPT2SAS_ERR_FMT "%s: Unable to write " |
| 1931 | "mpt_diag_read_buffer_t data @ %p\n", ioc->name, |
| 1932 | __func__, diag_data); |
| 1933 | return -EFAULT; |
| 1934 | } |
| 1935 | |
| 1936 | if ((karg.flags & MPT2_FLAGS_REREGISTER) == 0) |
| 1937 | return 0; |
| 1938 | |
| 1939 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: Reregister " |
| 1940 | "buffer_type(0x%02x)\n", ioc->name, __func__, buffer_type)); |
| 1941 | if ((ioc->diag_buffer_status[buffer_type] & |
| 1942 | MPT2_DIAG_BUFFER_IS_RELEASED) == 0) { |
| 1943 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 1944 | "buffer_type(0x%02x) is still registered\n", ioc->name, |
| 1945 | __func__, buffer_type)); |
| 1946 | return 0; |
| 1947 | } |
| 1948 | /* Get a free request frame and save the message context. |
| 1949 | */ |
| 1950 | if (state == NON_BLOCKING && !mutex_trylock(&ioc->ctl_cmds.mutex)) |
| 1951 | return -EAGAIN; |
| 1952 | else if (mutex_lock_interruptible(&ioc->ctl_cmds.mutex)) |
| 1953 | return -ERESTARTSYS; |
| 1954 | |
| 1955 | if (ioc->ctl_cmds.status != MPT2_CMD_NOT_USED) { |
| 1956 | printk(MPT2SAS_ERR_FMT "%s: ctl_cmd in use\n", |
| 1957 | ioc->name, __func__); |
| 1958 | rc = -EAGAIN; |
| 1959 | goto out; |
| 1960 | } |
| 1961 | |
| 1962 | smid = mpt2sas_base_get_smid(ioc, ioc->ctl_cb_idx); |
| 1963 | if (!smid) { |
| 1964 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 1965 | ioc->name, __func__); |
| 1966 | rc = -EAGAIN; |
| 1967 | goto out; |
| 1968 | } |
| 1969 | |
| 1970 | rc = 0; |
| 1971 | ioc->ctl_cmds.status = MPT2_CMD_PENDING; |
| 1972 | memset(ioc->ctl_cmds.reply, 0, ioc->reply_sz); |
| 1973 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 1974 | ioc->ctl_cmds.smid = smid; |
| 1975 | |
| 1976 | mpi_request->Function = MPI2_FUNCTION_DIAG_BUFFER_POST; |
| 1977 | mpi_request->BufferType = buffer_type; |
| 1978 | mpi_request->BufferLength = |
| 1979 | cpu_to_le32(ioc->diag_buffer_sz[buffer_type]); |
| 1980 | mpi_request->BufferAddress = |
| 1981 | cpu_to_le64(ioc->diag_buffer_dma[buffer_type]); |
| 1982 | for (i = 0; i < MPT2_PRODUCT_SPECIFIC_DWORDS; i++) |
| 1983 | mpi_request->ProductSpecific[i] = |
| 1984 | cpu_to_le32(ioc->product_specific[buffer_type][i]); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1985 | mpi_request->VF_ID = 0; /* TODO */ |
| 1986 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1987 | |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1988 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 1989 | init_completion(&ioc->ctl_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1990 | timeleft = wait_for_completion_timeout(&ioc->ctl_cmds.done, |
| 1991 | MPT2_IOCTL_DEFAULT_TIMEOUT*HZ); |
| 1992 | |
| 1993 | if (!(ioc->ctl_cmds.status & MPT2_CMD_COMPLETE)) { |
| 1994 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", ioc->name, |
| 1995 | __func__); |
| 1996 | _debug_dump_mf(mpi_request, |
| 1997 | sizeof(Mpi2DiagBufferPostRequest_t)/4); |
| 1998 | if (!(ioc->ctl_cmds.status & MPT2_CMD_RESET)) |
| 1999 | issue_reset = 1; |
| 2000 | goto issue_host_reset; |
| 2001 | } |
| 2002 | |
| 2003 | /* process the completed Reply Message Frame */ |
| 2004 | if ((ioc->ctl_cmds.status & MPT2_CMD_REPLY_VALID) == 0) { |
| 2005 | printk(MPT2SAS_ERR_FMT "%s: no reply message\n", |
| 2006 | ioc->name, __func__); |
| 2007 | rc = -EFAULT; |
| 2008 | goto out; |
| 2009 | } |
| 2010 | |
| 2011 | mpi_reply = ioc->ctl_cmds.reply; |
| 2012 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 2013 | |
| 2014 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 2015 | ioc->diag_buffer_status[buffer_type] |= |
| 2016 | MPT2_DIAG_BUFFER_IS_REGISTERED; |
| 2017 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: success\n", |
| 2018 | ioc->name, __func__)); |
| 2019 | } else { |
| 2020 | printk(MPT2SAS_DEBUG_FMT "%s: ioc_status(0x%04x) " |
| 2021 | "log_info(0x%08x)\n", ioc->name, __func__, |
Kashyap, Desai | 463217b | 2009-10-05 15:53:06 +0530 | [diff] [blame] | 2022 | ioc_status, le32_to_cpu(mpi_reply->IOCLogInfo)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2023 | rc = -EFAULT; |
| 2024 | } |
| 2025 | |
| 2026 | issue_host_reset: |
| 2027 | if (issue_reset) |
| 2028 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2029 | FORCE_BIG_HAMMER); |
| 2030 | |
| 2031 | out: |
| 2032 | |
| 2033 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; |
| 2034 | mutex_unlock(&ioc->ctl_cmds.mutex); |
| 2035 | return rc; |
| 2036 | } |
| 2037 | |
| 2038 | /** |
| 2039 | * _ctl_ioctl_main - main ioctl entry point |
| 2040 | * @file - (struct file) |
| 2041 | * @cmd - ioctl opcode |
| 2042 | * @arg - |
| 2043 | */ |
| 2044 | static long |
| 2045 | _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg) |
| 2046 | { |
| 2047 | enum block_state state; |
| 2048 | long ret = -EINVAL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2049 | |
| 2050 | state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : |
| 2051 | BLOCKING; |
| 2052 | |
| 2053 | switch (cmd) { |
| 2054 | case MPT2IOCINFO: |
| 2055 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_iocinfo)) |
| 2056 | ret = _ctl_getiocinfo(arg); |
| 2057 | break; |
| 2058 | case MPT2COMMAND: |
| 2059 | { |
| 2060 | struct mpt2_ioctl_command karg; |
| 2061 | struct mpt2_ioctl_command __user *uarg; |
| 2062 | struct MPT2SAS_ADAPTER *ioc; |
| 2063 | |
| 2064 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 2065 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 2066 | __FILE__, __LINE__, __func__); |
| 2067 | return -EFAULT; |
| 2068 | } |
| 2069 | |
| 2070 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || |
| 2071 | !ioc) |
| 2072 | return -ENODEV; |
| 2073 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2074 | if (ioc->shost_recovery) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2075 | return -EAGAIN; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2076 | |
| 2077 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) { |
| 2078 | uarg = arg; |
| 2079 | ret = _ctl_do_mpt_command(ioc, karg, &uarg->mf, state); |
| 2080 | } |
| 2081 | break; |
| 2082 | } |
| 2083 | case MPT2EVENTQUERY: |
| 2084 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventquery)) |
| 2085 | ret = _ctl_eventquery(arg); |
| 2086 | break; |
| 2087 | case MPT2EVENTENABLE: |
| 2088 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_eventenable)) |
| 2089 | ret = _ctl_eventenable(arg); |
| 2090 | break; |
| 2091 | case MPT2EVENTREPORT: |
| 2092 | ret = _ctl_eventreport(arg); |
| 2093 | break; |
| 2094 | case MPT2HARDRESET: |
| 2095 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_diag_reset)) |
| 2096 | ret = _ctl_do_reset(arg); |
| 2097 | break; |
| 2098 | case MPT2BTDHMAPPING: |
| 2099 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_btdh_mapping)) |
| 2100 | ret = _ctl_btdh_mapping(arg); |
| 2101 | break; |
| 2102 | case MPT2DIAGREGISTER: |
| 2103 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_register)) |
| 2104 | ret = _ctl_diag_register(arg, state); |
| 2105 | break; |
| 2106 | case MPT2DIAGUNREGISTER: |
| 2107 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_unregister)) |
| 2108 | ret = _ctl_diag_unregister(arg); |
| 2109 | break; |
| 2110 | case MPT2DIAGQUERY: |
| 2111 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_query)) |
| 2112 | ret = _ctl_diag_query(arg); |
| 2113 | break; |
| 2114 | case MPT2DIAGRELEASE: |
| 2115 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_release)) |
| 2116 | ret = _ctl_diag_release(arg, state); |
| 2117 | break; |
| 2118 | case MPT2DIAGREADBUFFER: |
| 2119 | if (_IOC_SIZE(cmd) == sizeof(struct mpt2_diag_read_buffer)) |
| 2120 | ret = _ctl_diag_read_buffer(arg, state); |
| 2121 | break; |
| 2122 | default: |
| 2123 | { |
| 2124 | struct mpt2_ioctl_command karg; |
| 2125 | struct MPT2SAS_ADAPTER *ioc; |
| 2126 | |
| 2127 | if (copy_from_user(&karg, arg, sizeof(karg))) { |
| 2128 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 2129 | __FILE__, __LINE__, __func__); |
| 2130 | return -EFAULT; |
| 2131 | } |
| 2132 | |
| 2133 | if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || |
| 2134 | !ioc) |
| 2135 | return -ENODEV; |
| 2136 | |
| 2137 | dctlprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 2138 | "unsupported ioctl opcode(0x%08x)\n", ioc->name, cmd)); |
| 2139 | break; |
| 2140 | } |
| 2141 | } |
| 2142 | return ret; |
| 2143 | } |
| 2144 | |
| 2145 | /** |
| 2146 | * _ctl_ioctl - main ioctl entry point (unlocked) |
| 2147 | * @file - (struct file) |
| 2148 | * @cmd - ioctl opcode |
| 2149 | * @arg - |
| 2150 | */ |
| 2151 | static long |
| 2152 | _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 2153 | { |
| 2154 | long ret; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2155 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2156 | lock_kernel(); |
| 2157 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); |
| 2158 | unlock_kernel(); |
| 2159 | return ret; |
| 2160 | } |
| 2161 | |
| 2162 | #ifdef CONFIG_COMPAT |
| 2163 | /** |
| 2164 | * _ctl_compat_mpt_command - convert 32bit pointers to 64bit. |
| 2165 | * @file - (struct file) |
| 2166 | * @cmd - ioctl opcode |
| 2167 | * @arg - (struct mpt2_ioctl_command32) |
| 2168 | * |
| 2169 | * MPT2COMMAND32 - Handle 32bit applications running on 64bit os. |
| 2170 | */ |
| 2171 | static long |
| 2172 | _ctl_compat_mpt_command(struct file *file, unsigned cmd, unsigned long arg) |
| 2173 | { |
| 2174 | struct mpt2_ioctl_command32 karg32; |
| 2175 | struct mpt2_ioctl_command32 __user *uarg; |
| 2176 | struct mpt2_ioctl_command karg; |
| 2177 | struct MPT2SAS_ADAPTER *ioc; |
| 2178 | enum block_state state; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2179 | |
| 2180 | if (_IOC_SIZE(cmd) != sizeof(struct mpt2_ioctl_command32)) |
| 2181 | return -EINVAL; |
| 2182 | |
| 2183 | uarg = (struct mpt2_ioctl_command32 __user *) arg; |
| 2184 | |
| 2185 | if (copy_from_user(&karg32, (char __user *)arg, sizeof(karg32))) { |
| 2186 | printk(KERN_ERR "failure at %s:%d/%s()!\n", |
| 2187 | __FILE__, __LINE__, __func__); |
| 2188 | return -EFAULT; |
| 2189 | } |
| 2190 | if (_ctl_verify_adapter(karg32.hdr.ioc_number, &ioc) == -1 || !ioc) |
| 2191 | return -ENODEV; |
| 2192 | |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 2193 | if (ioc->shost_recovery) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2194 | return -EAGAIN; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2195 | |
| 2196 | memset(&karg, 0, sizeof(struct mpt2_ioctl_command)); |
| 2197 | karg.hdr.ioc_number = karg32.hdr.ioc_number; |
| 2198 | karg.hdr.port_number = karg32.hdr.port_number; |
| 2199 | karg.hdr.max_data_size = karg32.hdr.max_data_size; |
| 2200 | karg.timeout = karg32.timeout; |
| 2201 | karg.max_reply_bytes = karg32.max_reply_bytes; |
| 2202 | karg.data_in_size = karg32.data_in_size; |
| 2203 | karg.data_out_size = karg32.data_out_size; |
| 2204 | karg.max_sense_bytes = karg32.max_sense_bytes; |
| 2205 | karg.data_sge_offset = karg32.data_sge_offset; |
| 2206 | memcpy(&karg.reply_frame_buf_ptr, &karg32.reply_frame_buf_ptr, |
| 2207 | sizeof(uint32_t)); |
| 2208 | memcpy(&karg.data_in_buf_ptr, &karg32.data_in_buf_ptr, |
| 2209 | sizeof(uint32_t)); |
| 2210 | memcpy(&karg.data_out_buf_ptr, &karg32.data_out_buf_ptr, |
| 2211 | sizeof(uint32_t)); |
| 2212 | memcpy(&karg.sense_data_ptr, &karg32.sense_data_ptr, |
| 2213 | sizeof(uint32_t)); |
| 2214 | state = (file->f_flags & O_NONBLOCK) ? NON_BLOCKING : BLOCKING; |
| 2215 | return _ctl_do_mpt_command(ioc, karg, &uarg->mf, state); |
| 2216 | } |
| 2217 | |
| 2218 | /** |
| 2219 | * _ctl_ioctl_compat - main ioctl entry point (compat) |
| 2220 | * @file - |
| 2221 | * @cmd - |
| 2222 | * @arg - |
| 2223 | * |
| 2224 | * This routine handles 32 bit applications in 64bit os. |
| 2225 | */ |
| 2226 | static long |
| 2227 | _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg) |
| 2228 | { |
| 2229 | long ret; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2230 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2231 | lock_kernel(); |
| 2232 | if (cmd == MPT2COMMAND32) |
| 2233 | ret = _ctl_compat_mpt_command(file, cmd, arg); |
| 2234 | else |
| 2235 | ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); |
| 2236 | unlock_kernel(); |
| 2237 | return ret; |
| 2238 | } |
| 2239 | #endif |
| 2240 | |
| 2241 | /* scsi host attributes */ |
| 2242 | |
| 2243 | /** |
| 2244 | * _ctl_version_fw_show - firmware version |
| 2245 | * @cdev - pointer to embedded class device |
| 2246 | * @buf - the buffer returned |
| 2247 | * |
| 2248 | * A sysfs 'read-only' shost attribute. |
| 2249 | */ |
| 2250 | static ssize_t |
| 2251 | _ctl_version_fw_show(struct device *cdev, struct device_attribute *attr, |
| 2252 | char *buf) |
| 2253 | { |
| 2254 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2255 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2256 | |
| 2257 | return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n", |
| 2258 | (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, |
| 2259 | (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, |
| 2260 | (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, |
| 2261 | ioc->facts.FWVersion.Word & 0x000000FF); |
| 2262 | } |
| 2263 | static DEVICE_ATTR(version_fw, S_IRUGO, _ctl_version_fw_show, NULL); |
| 2264 | |
| 2265 | /** |
| 2266 | * _ctl_version_bios_show - bios version |
| 2267 | * @cdev - pointer to embedded class device |
| 2268 | * @buf - the buffer returned |
| 2269 | * |
| 2270 | * A sysfs 'read-only' shost attribute. |
| 2271 | */ |
| 2272 | static ssize_t |
| 2273 | _ctl_version_bios_show(struct device *cdev, struct device_attribute *attr, |
| 2274 | char *buf) |
| 2275 | { |
| 2276 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2277 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2278 | |
| 2279 | u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion); |
| 2280 | |
| 2281 | return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n", |
| 2282 | (version & 0xFF000000) >> 24, |
| 2283 | (version & 0x00FF0000) >> 16, |
| 2284 | (version & 0x0000FF00) >> 8, |
| 2285 | version & 0x000000FF); |
| 2286 | } |
| 2287 | static DEVICE_ATTR(version_bios, S_IRUGO, _ctl_version_bios_show, NULL); |
| 2288 | |
| 2289 | /** |
| 2290 | * _ctl_version_mpi_show - MPI (message passing interface) version |
| 2291 | * @cdev - pointer to embedded class device |
| 2292 | * @buf - the buffer returned |
| 2293 | * |
| 2294 | * A sysfs 'read-only' shost attribute. |
| 2295 | */ |
| 2296 | static ssize_t |
| 2297 | _ctl_version_mpi_show(struct device *cdev, struct device_attribute *attr, |
| 2298 | char *buf) |
| 2299 | { |
| 2300 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2301 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2302 | |
| 2303 | return snprintf(buf, PAGE_SIZE, "%03x.%02x\n", |
| 2304 | ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8); |
| 2305 | } |
| 2306 | static DEVICE_ATTR(version_mpi, S_IRUGO, _ctl_version_mpi_show, NULL); |
| 2307 | |
| 2308 | /** |
| 2309 | * _ctl_version_product_show - product name |
| 2310 | * @cdev - pointer to embedded class device |
| 2311 | * @buf - the buffer returned |
| 2312 | * |
| 2313 | * A sysfs 'read-only' shost attribute. |
| 2314 | */ |
| 2315 | static ssize_t |
| 2316 | _ctl_version_product_show(struct device *cdev, struct device_attribute *attr, |
| 2317 | char *buf) |
| 2318 | { |
| 2319 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2320 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2321 | |
| 2322 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName); |
| 2323 | } |
| 2324 | static DEVICE_ATTR(version_product, S_IRUGO, |
| 2325 | _ctl_version_product_show, NULL); |
| 2326 | |
| 2327 | /** |
| 2328 | * _ctl_version_nvdata_persistent_show - ndvata persistent version |
| 2329 | * @cdev - pointer to embedded class device |
| 2330 | * @buf - the buffer returned |
| 2331 | * |
| 2332 | * A sysfs 'read-only' shost attribute. |
| 2333 | */ |
| 2334 | static ssize_t |
| 2335 | _ctl_version_nvdata_persistent_show(struct device *cdev, |
| 2336 | struct device_attribute *attr, char *buf) |
| 2337 | { |
| 2338 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2339 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2340 | |
| 2341 | return snprintf(buf, PAGE_SIZE, "%02xh\n", |
| 2342 | le16_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word)); |
| 2343 | } |
| 2344 | static DEVICE_ATTR(version_nvdata_persistent, S_IRUGO, |
| 2345 | _ctl_version_nvdata_persistent_show, NULL); |
| 2346 | |
| 2347 | /** |
| 2348 | * _ctl_version_nvdata_default_show - nvdata default version |
| 2349 | * @cdev - pointer to embedded class device |
| 2350 | * @buf - the buffer returned |
| 2351 | * |
| 2352 | * A sysfs 'read-only' shost attribute. |
| 2353 | */ |
| 2354 | static ssize_t |
| 2355 | _ctl_version_nvdata_default_show(struct device *cdev, |
| 2356 | struct device_attribute *attr, char *buf) |
| 2357 | { |
| 2358 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2359 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2360 | |
| 2361 | return snprintf(buf, PAGE_SIZE, "%02xh\n", |
| 2362 | le16_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word)); |
| 2363 | } |
| 2364 | static DEVICE_ATTR(version_nvdata_default, S_IRUGO, |
| 2365 | _ctl_version_nvdata_default_show, NULL); |
| 2366 | |
| 2367 | /** |
| 2368 | * _ctl_board_name_show - board name |
| 2369 | * @cdev - pointer to embedded class device |
| 2370 | * @buf - the buffer returned |
| 2371 | * |
| 2372 | * A sysfs 'read-only' shost attribute. |
| 2373 | */ |
| 2374 | static ssize_t |
| 2375 | _ctl_board_name_show(struct device *cdev, struct device_attribute *attr, |
| 2376 | char *buf) |
| 2377 | { |
| 2378 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2379 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2380 | |
| 2381 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName); |
| 2382 | } |
| 2383 | static DEVICE_ATTR(board_name, S_IRUGO, _ctl_board_name_show, NULL); |
| 2384 | |
| 2385 | /** |
| 2386 | * _ctl_board_assembly_show - board assembly name |
| 2387 | * @cdev - pointer to embedded class device |
| 2388 | * @buf - the buffer returned |
| 2389 | * |
| 2390 | * A sysfs 'read-only' shost attribute. |
| 2391 | */ |
| 2392 | static ssize_t |
| 2393 | _ctl_board_assembly_show(struct device *cdev, struct device_attribute *attr, |
| 2394 | char *buf) |
| 2395 | { |
| 2396 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2397 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2398 | |
| 2399 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly); |
| 2400 | } |
| 2401 | static DEVICE_ATTR(board_assembly, S_IRUGO, |
| 2402 | _ctl_board_assembly_show, NULL); |
| 2403 | |
| 2404 | /** |
| 2405 | * _ctl_board_tracer_show - board tracer number |
| 2406 | * @cdev - pointer to embedded class device |
| 2407 | * @buf - the buffer returned |
| 2408 | * |
| 2409 | * A sysfs 'read-only' shost attribute. |
| 2410 | */ |
| 2411 | static ssize_t |
| 2412 | _ctl_board_tracer_show(struct device *cdev, struct device_attribute *attr, |
| 2413 | char *buf) |
| 2414 | { |
| 2415 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2416 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2417 | |
| 2418 | return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber); |
| 2419 | } |
| 2420 | static DEVICE_ATTR(board_tracer, S_IRUGO, |
| 2421 | _ctl_board_tracer_show, NULL); |
| 2422 | |
| 2423 | /** |
| 2424 | * _ctl_io_delay_show - io missing delay |
| 2425 | * @cdev - pointer to embedded class device |
| 2426 | * @buf - the buffer returned |
| 2427 | * |
| 2428 | * This is for firmware implemention for deboucing device |
| 2429 | * removal events. |
| 2430 | * |
| 2431 | * A sysfs 'read-only' shost attribute. |
| 2432 | */ |
| 2433 | static ssize_t |
| 2434 | _ctl_io_delay_show(struct device *cdev, struct device_attribute *attr, |
| 2435 | char *buf) |
| 2436 | { |
| 2437 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2438 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2439 | |
| 2440 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay); |
| 2441 | } |
| 2442 | static DEVICE_ATTR(io_delay, S_IRUGO, |
| 2443 | _ctl_io_delay_show, NULL); |
| 2444 | |
| 2445 | /** |
| 2446 | * _ctl_device_delay_show - device missing delay |
| 2447 | * @cdev - pointer to embedded class device |
| 2448 | * @buf - the buffer returned |
| 2449 | * |
| 2450 | * This is for firmware implemention for deboucing device |
| 2451 | * removal events. |
| 2452 | * |
| 2453 | * A sysfs 'read-only' shost attribute. |
| 2454 | */ |
| 2455 | static ssize_t |
| 2456 | _ctl_device_delay_show(struct device *cdev, struct device_attribute *attr, |
| 2457 | char *buf) |
| 2458 | { |
| 2459 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2460 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2461 | |
| 2462 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay); |
| 2463 | } |
| 2464 | static DEVICE_ATTR(device_delay, S_IRUGO, |
| 2465 | _ctl_device_delay_show, NULL); |
| 2466 | |
| 2467 | /** |
| 2468 | * _ctl_fw_queue_depth_show - global credits |
| 2469 | * @cdev - pointer to embedded class device |
| 2470 | * @buf - the buffer returned |
| 2471 | * |
| 2472 | * This is firmware queue depth limit |
| 2473 | * |
| 2474 | * A sysfs 'read-only' shost attribute. |
| 2475 | */ |
| 2476 | static ssize_t |
| 2477 | _ctl_fw_queue_depth_show(struct device *cdev, struct device_attribute *attr, |
| 2478 | char *buf) |
| 2479 | { |
| 2480 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2481 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2482 | |
| 2483 | return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit); |
| 2484 | } |
| 2485 | static DEVICE_ATTR(fw_queue_depth, S_IRUGO, |
| 2486 | _ctl_fw_queue_depth_show, NULL); |
| 2487 | |
| 2488 | /** |
| 2489 | * _ctl_sas_address_show - sas address |
| 2490 | * @cdev - pointer to embedded class device |
| 2491 | * @buf - the buffer returned |
| 2492 | * |
| 2493 | * This is the controller sas address |
| 2494 | * |
| 2495 | * A sysfs 'read-only' shost attribute. |
| 2496 | */ |
| 2497 | static ssize_t |
| 2498 | _ctl_host_sas_address_show(struct device *cdev, struct device_attribute *attr, |
| 2499 | char *buf) |
| 2500 | { |
| 2501 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2502 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2503 | |
| 2504 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", |
| 2505 | (unsigned long long)ioc->sas_hba.sas_address); |
| 2506 | } |
| 2507 | static DEVICE_ATTR(host_sas_address, S_IRUGO, |
| 2508 | _ctl_host_sas_address_show, NULL); |
| 2509 | |
| 2510 | /** |
| 2511 | * _ctl_logging_level_show - logging level |
| 2512 | * @cdev - pointer to embedded class device |
| 2513 | * @buf - the buffer returned |
| 2514 | * |
| 2515 | * A sysfs 'read/write' shost attribute. |
| 2516 | */ |
| 2517 | static ssize_t |
| 2518 | _ctl_logging_level_show(struct device *cdev, struct device_attribute *attr, |
| 2519 | char *buf) |
| 2520 | { |
| 2521 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2522 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2523 | |
| 2524 | return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level); |
| 2525 | } |
| 2526 | static ssize_t |
| 2527 | _ctl_logging_level_store(struct device *cdev, struct device_attribute *attr, |
| 2528 | const char *buf, size_t count) |
| 2529 | { |
| 2530 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2531 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2532 | int val = 0; |
| 2533 | |
| 2534 | if (sscanf(buf, "%x", &val) != 1) |
| 2535 | return -EINVAL; |
| 2536 | |
| 2537 | ioc->logging_level = val; |
| 2538 | printk(MPT2SAS_INFO_FMT "logging_level=%08xh\n", ioc->name, |
| 2539 | ioc->logging_level); |
| 2540 | return strlen(buf); |
| 2541 | } |
| 2542 | static DEVICE_ATTR(logging_level, S_IRUGO | S_IWUSR, |
| 2543 | _ctl_logging_level_show, _ctl_logging_level_store); |
| 2544 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2545 | /* device attributes */ |
| 2546 | /* |
| 2547 | * _ctl_fwfault_debug_show - show/store fwfault_debug |
| 2548 | * @cdev - pointer to embedded class device |
| 2549 | * @buf - the buffer returned |
| 2550 | * |
| 2551 | * mpt2sas_fwfault_debug is command line option |
| 2552 | * A sysfs 'read/write' shost attribute. |
| 2553 | */ |
| 2554 | static ssize_t |
| 2555 | _ctl_fwfault_debug_show(struct device *cdev, |
| 2556 | struct device_attribute *attr, char *buf) |
| 2557 | { |
| 2558 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2559 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2560 | |
| 2561 | return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug); |
| 2562 | } |
| 2563 | static ssize_t |
| 2564 | _ctl_fwfault_debug_store(struct device *cdev, |
| 2565 | struct device_attribute *attr, const char *buf, size_t count) |
| 2566 | { |
| 2567 | struct Scsi_Host *shost = class_to_shost(cdev); |
| 2568 | struct MPT2SAS_ADAPTER *ioc = shost_priv(shost); |
| 2569 | int val = 0; |
| 2570 | |
| 2571 | if (sscanf(buf, "%d", &val) != 1) |
| 2572 | return -EINVAL; |
| 2573 | |
| 2574 | ioc->fwfault_debug = val; |
| 2575 | printk(MPT2SAS_INFO_FMT "fwfault_debug=%d\n", ioc->name, |
| 2576 | ioc->fwfault_debug); |
| 2577 | return strlen(buf); |
| 2578 | } |
| 2579 | static DEVICE_ATTR(fwfault_debug, S_IRUGO | S_IWUSR, |
| 2580 | _ctl_fwfault_debug_show, _ctl_fwfault_debug_store); |
| 2581 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2582 | struct device_attribute *mpt2sas_host_attrs[] = { |
| 2583 | &dev_attr_version_fw, |
| 2584 | &dev_attr_version_bios, |
| 2585 | &dev_attr_version_mpi, |
| 2586 | &dev_attr_version_product, |
| 2587 | &dev_attr_version_nvdata_persistent, |
| 2588 | &dev_attr_version_nvdata_default, |
| 2589 | &dev_attr_board_name, |
| 2590 | &dev_attr_board_assembly, |
| 2591 | &dev_attr_board_tracer, |
| 2592 | &dev_attr_io_delay, |
| 2593 | &dev_attr_device_delay, |
| 2594 | &dev_attr_logging_level, |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 2595 | &dev_attr_fwfault_debug, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2596 | &dev_attr_fw_queue_depth, |
| 2597 | &dev_attr_host_sas_address, |
| 2598 | NULL, |
| 2599 | }; |
| 2600 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2601 | /** |
| 2602 | * _ctl_device_sas_address_show - sas address |
| 2603 | * @cdev - pointer to embedded class device |
| 2604 | * @buf - the buffer returned |
| 2605 | * |
| 2606 | * This is the sas address for the target |
| 2607 | * |
| 2608 | * A sysfs 'read-only' shost attribute. |
| 2609 | */ |
| 2610 | static ssize_t |
| 2611 | _ctl_device_sas_address_show(struct device *dev, struct device_attribute *attr, |
| 2612 | char *buf) |
| 2613 | { |
| 2614 | struct scsi_device *sdev = to_scsi_device(dev); |
| 2615 | struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata; |
| 2616 | |
| 2617 | return snprintf(buf, PAGE_SIZE, "0x%016llx\n", |
| 2618 | (unsigned long long)sas_device_priv_data->sas_target->sas_address); |
| 2619 | } |
| 2620 | static DEVICE_ATTR(sas_address, S_IRUGO, _ctl_device_sas_address_show, NULL); |
| 2621 | |
| 2622 | /** |
| 2623 | * _ctl_device_handle_show - device handle |
| 2624 | * @cdev - pointer to embedded class device |
| 2625 | * @buf - the buffer returned |
| 2626 | * |
| 2627 | * This is the firmware assigned device handle |
| 2628 | * |
| 2629 | * A sysfs 'read-only' shost attribute. |
| 2630 | */ |
| 2631 | static ssize_t |
| 2632 | _ctl_device_handle_show(struct device *dev, struct device_attribute *attr, |
| 2633 | char *buf) |
| 2634 | { |
| 2635 | struct scsi_device *sdev = to_scsi_device(dev); |
| 2636 | struct MPT2SAS_DEVICE *sas_device_priv_data = sdev->hostdata; |
| 2637 | |
| 2638 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", |
| 2639 | sas_device_priv_data->sas_target->handle); |
| 2640 | } |
| 2641 | static DEVICE_ATTR(sas_device_handle, S_IRUGO, _ctl_device_handle_show, NULL); |
| 2642 | |
| 2643 | struct device_attribute *mpt2sas_dev_attrs[] = { |
| 2644 | &dev_attr_sas_address, |
| 2645 | &dev_attr_sas_device_handle, |
| 2646 | NULL, |
| 2647 | }; |
| 2648 | |
| 2649 | static const struct file_operations ctl_fops = { |
| 2650 | .owner = THIS_MODULE, |
| 2651 | .unlocked_ioctl = _ctl_ioctl, |
| 2652 | .release = _ctl_release, |
| 2653 | .poll = _ctl_poll, |
| 2654 | .fasync = _ctl_fasync, |
| 2655 | #ifdef CONFIG_COMPAT |
| 2656 | .compat_ioctl = _ctl_ioctl_compat, |
| 2657 | #endif |
| 2658 | }; |
| 2659 | |
| 2660 | static struct miscdevice ctl_dev = { |
| 2661 | .minor = MPT2SAS_MINOR, |
| 2662 | .name = MPT2SAS_DEV_NAME, |
| 2663 | .fops = &ctl_fops, |
| 2664 | }; |
| 2665 | |
| 2666 | /** |
| 2667 | * mpt2sas_ctl_init - main entry point for ctl. |
| 2668 | * |
| 2669 | */ |
| 2670 | void |
| 2671 | mpt2sas_ctl_init(void) |
| 2672 | { |
| 2673 | async_queue = NULL; |
| 2674 | if (misc_register(&ctl_dev) < 0) |
| 2675 | printk(KERN_ERR "%s can't register misc device [minor=%d]\n", |
| 2676 | MPT2SAS_DRIVER_NAME, MPT2SAS_MINOR); |
| 2677 | |
| 2678 | init_waitqueue_head(&ctl_poll_wait); |
| 2679 | } |
| 2680 | |
| 2681 | /** |
| 2682 | * mpt2sas_ctl_exit - exit point for ctl |
| 2683 | * |
| 2684 | */ |
| 2685 | void |
| 2686 | mpt2sas_ctl_exit(void) |
| 2687 | { |
| 2688 | struct MPT2SAS_ADAPTER *ioc; |
| 2689 | int i; |
| 2690 | |
Eric Moore | ba33fad | 2009-03-15 21:37:18 -0600 | [diff] [blame] | 2691 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2692 | |
| 2693 | /* free memory associated to diag buffers */ |
| 2694 | for (i = 0; i < MPI2_DIAG_BUF_TYPE_COUNT; i++) { |
| 2695 | if (!ioc->diag_buffer[i]) |
| 2696 | continue; |
| 2697 | pci_free_consistent(ioc->pdev, ioc->diag_buffer_sz[i], |
| 2698 | ioc->diag_buffer[i], ioc->diag_buffer_dma[i]); |
| 2699 | ioc->diag_buffer[i] = NULL; |
| 2700 | ioc->diag_buffer_status[i] = 0; |
| 2701 | } |
| 2702 | |
| 2703 | kfree(ioc->event_log); |
| 2704 | } |
| 2705 | misc_deregister(&ctl_dev); |
| 2706 | } |
| 2707 | |