Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This is the Fusion MPT base driver providing common API layer interface |
| 3 | * for access to MPT (Message Passing Technology) firmware. |
| 4 | * |
| 5 | * This code is based on drivers/scsi/mpt2sas/mpt2_base.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/kdev_t.h> |
| 54 | #include <linux/blkdev.h> |
| 55 | #include <linux/delay.h> |
| 56 | #include <linux/interrupt.h> |
| 57 | #include <linux/dma-mapping.h> |
| 58 | #include <linux/sort.h> |
| 59 | #include <linux/io.h> |
| 60 | |
| 61 | #include "mpt2sas_base.h" |
| 62 | |
| 63 | static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS]; |
| 64 | |
| 65 | #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */ |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 66 | #define MPT2SAS_MAX_REQUEST_QUEUE 600 /* maximum controller queue depth */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 67 | |
| 68 | static int max_queue_depth = -1; |
| 69 | module_param(max_queue_depth, int, 0); |
| 70 | MODULE_PARM_DESC(max_queue_depth, " max controller queue depth "); |
| 71 | |
| 72 | static int max_sgl_entries = -1; |
| 73 | module_param(max_sgl_entries, int, 0); |
| 74 | MODULE_PARM_DESC(max_sgl_entries, " max sg entries "); |
| 75 | |
| 76 | static int msix_disable = -1; |
| 77 | module_param(msix_disable, int, 0); |
| 78 | MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)"); |
| 79 | |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 80 | /* diag_buffer_enable is bitwise |
Kashyap, Desai | 1b01fe3 | 2009-09-23 17:28:59 +0530 | [diff] [blame^] | 81 | * bit 0 set = TRACE |
| 82 | * bit 1 set = SNAPSHOT |
| 83 | * bit 2 set = EXTENDED |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 84 | * |
| 85 | * Either bit can be set, or both |
| 86 | */ |
| 87 | static int diag_buffer_enable; |
| 88 | module_param(diag_buffer_enable, int, 0); |
Kashyap, Desai | 1b01fe3 | 2009-09-23 17:28:59 +0530 | [diff] [blame^] | 89 | MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers " |
| 90 | "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 91 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 92 | int mpt2sas_fwfault_debug; |
| 93 | MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault " |
| 94 | "and halt firmware - (default=0)"); |
| 95 | |
| 96 | /** |
| 97 | * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug. |
| 98 | * |
| 99 | */ |
| 100 | static int |
| 101 | _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp) |
| 102 | { |
| 103 | int ret = param_set_int(val, kp); |
| 104 | struct MPT2SAS_ADAPTER *ioc; |
| 105 | |
| 106 | if (ret) |
| 107 | return ret; |
| 108 | |
| 109 | printk(KERN_INFO "setting logging_level(0x%08x)\n", |
| 110 | mpt2sas_fwfault_debug); |
| 111 | list_for_each_entry(ioc, &mpt2sas_ioc_list, list) |
| 112 | ioc->fwfault_debug = mpt2sas_fwfault_debug; |
| 113 | return 0; |
| 114 | } |
| 115 | module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug, |
| 116 | param_get_int, &mpt2sas_fwfault_debug, 0644); |
| 117 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 118 | /** |
| 119 | * _base_fault_reset_work - workq handling ioc fault conditions |
| 120 | * @work: input argument, used to derive ioc |
| 121 | * Context: sleep. |
| 122 | * |
| 123 | * Return nothing. |
| 124 | */ |
| 125 | static void |
| 126 | _base_fault_reset_work(struct work_struct *work) |
| 127 | { |
| 128 | struct MPT2SAS_ADAPTER *ioc = |
| 129 | container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work); |
| 130 | unsigned long flags; |
| 131 | u32 doorbell; |
| 132 | int rc; |
| 133 | |
| 134 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 135 | if (ioc->shost_recovery) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 136 | goto rearm_timer; |
| 137 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 138 | |
| 139 | doorbell = mpt2sas_base_get_iocstate(ioc, 0); |
| 140 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 141 | rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 142 | FORCE_BIG_HAMMER); |
| 143 | printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name, |
| 144 | __func__, (rc == 0) ? "success" : "failed"); |
| 145 | doorbell = mpt2sas_base_get_iocstate(ioc, 0); |
| 146 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 147 | mpt2sas_base_fault_info(ioc, doorbell & |
| 148 | MPI2_DOORBELL_DATA_MASK); |
| 149 | } |
| 150 | |
| 151 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 152 | rearm_timer: |
| 153 | if (ioc->fault_reset_work_q) |
| 154 | queue_delayed_work(ioc->fault_reset_work_q, |
| 155 | &ioc->fault_reset_work, |
| 156 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); |
| 157 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 158 | } |
| 159 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 160 | /** |
| 161 | * mpt2sas_base_start_watchdog - start the fault_reset_work_q |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 162 | * @ioc: per adapter object |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 163 | * Context: sleep. |
| 164 | * |
| 165 | * Return nothing. |
| 166 | */ |
| 167 | void |
| 168 | mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc) |
| 169 | { |
| 170 | unsigned long flags; |
| 171 | |
| 172 | if (ioc->fault_reset_work_q) |
| 173 | return; |
| 174 | |
| 175 | /* initialize fault polling */ |
| 176 | INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work); |
| 177 | snprintf(ioc->fault_reset_work_q_name, |
| 178 | sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id); |
| 179 | ioc->fault_reset_work_q = |
| 180 | create_singlethread_workqueue(ioc->fault_reset_work_q_name); |
| 181 | if (!ioc->fault_reset_work_q) { |
| 182 | printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n", |
| 183 | ioc->name, __func__, __LINE__); |
| 184 | return; |
| 185 | } |
| 186 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 187 | if (ioc->fault_reset_work_q) |
| 188 | queue_delayed_work(ioc->fault_reset_work_q, |
| 189 | &ioc->fault_reset_work, |
| 190 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); |
| 191 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 196 | * @ioc: per adapter object |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 197 | * Context: sleep. |
| 198 | * |
| 199 | * Return nothing. |
| 200 | */ |
| 201 | void |
| 202 | mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc) |
| 203 | { |
| 204 | unsigned long flags; |
| 205 | struct workqueue_struct *wq; |
| 206 | |
| 207 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 208 | wq = ioc->fault_reset_work_q; |
| 209 | ioc->fault_reset_work_q = NULL; |
| 210 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 211 | if (wq) { |
| 212 | if (!cancel_delayed_work(&ioc->fault_reset_work)) |
| 213 | flush_workqueue(wq); |
| 214 | destroy_workqueue(wq); |
| 215 | } |
| 216 | } |
| 217 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 218 | /** |
| 219 | * mpt2sas_base_fault_info - verbose translation of firmware FAULT code |
| 220 | * @ioc: per adapter object |
| 221 | * @fault_code: fault code |
| 222 | * |
| 223 | * Return nothing. |
| 224 | */ |
| 225 | void |
| 226 | mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code) |
| 227 | { |
| 228 | printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n", |
| 229 | ioc->name, fault_code); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * mpt2sas_halt_firmware - halt's mpt controller firmware |
| 234 | * @ioc: per adapter object |
| 235 | * |
| 236 | * For debugging timeout related issues. Writing 0xCOFFEE00 |
| 237 | * to the doorbell register will halt controller firmware. With |
| 238 | * the purpose to stop both driver and firmware, the enduser can |
| 239 | * obtain a ring buffer from controller UART. |
| 240 | */ |
| 241 | void |
| 242 | mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc) |
| 243 | { |
| 244 | u32 doorbell; |
| 245 | |
| 246 | if (!ioc->fwfault_debug) |
| 247 | return; |
| 248 | |
| 249 | dump_stack(); |
| 250 | |
| 251 | doorbell = readl(&ioc->chip->Doorbell); |
| 252 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 253 | mpt2sas_base_fault_info(ioc , doorbell); |
| 254 | else { |
| 255 | writel(0xC0FFEE00, &ioc->chip->Doorbell); |
| 256 | printk(MPT2SAS_ERR_FMT "Firmware is halted due to command " |
| 257 | "timeout\n", ioc->name); |
| 258 | } |
| 259 | |
| 260 | panic("panic in %s\n", __func__); |
| 261 | } |
| 262 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 263 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 264 | /** |
| 265 | * _base_sas_ioc_info - verbose translation of the ioc status |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 266 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 267 | * @mpi_reply: reply mf payload returned from firmware |
| 268 | * @request_hdr: request mf |
| 269 | * |
| 270 | * Return nothing. |
| 271 | */ |
| 272 | static void |
| 273 | _base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply, |
| 274 | MPI2RequestHeader_t *request_hdr) |
| 275 | { |
| 276 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 277 | MPI2_IOCSTATUS_MASK; |
| 278 | char *desc = NULL; |
| 279 | u16 frame_sz; |
| 280 | char *func_str = NULL; |
| 281 | |
| 282 | /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */ |
| 283 | if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 284 | request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || |
| 285 | request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION) |
| 286 | return; |
| 287 | |
| 288 | switch (ioc_status) { |
| 289 | |
| 290 | /**************************************************************************** |
| 291 | * Common IOCStatus values for all replies |
| 292 | ****************************************************************************/ |
| 293 | |
| 294 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 295 | desc = "invalid function"; |
| 296 | break; |
| 297 | case MPI2_IOCSTATUS_BUSY: |
| 298 | desc = "busy"; |
| 299 | break; |
| 300 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 301 | desc = "invalid sgl"; |
| 302 | break; |
| 303 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 304 | desc = "internal error"; |
| 305 | break; |
| 306 | case MPI2_IOCSTATUS_INVALID_VPID: |
| 307 | desc = "invalid vpid"; |
| 308 | break; |
| 309 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 310 | desc = "insufficient resources"; |
| 311 | break; |
| 312 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 313 | desc = "invalid field"; |
| 314 | break; |
| 315 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 316 | desc = "invalid state"; |
| 317 | break; |
| 318 | case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED: |
| 319 | desc = "op state not supported"; |
| 320 | break; |
| 321 | |
| 322 | /**************************************************************************** |
| 323 | * Config IOCStatus values |
| 324 | ****************************************************************************/ |
| 325 | |
| 326 | case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION: |
| 327 | desc = "config invalid action"; |
| 328 | break; |
| 329 | case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE: |
| 330 | desc = "config invalid type"; |
| 331 | break; |
| 332 | case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE: |
| 333 | desc = "config invalid page"; |
| 334 | break; |
| 335 | case MPI2_IOCSTATUS_CONFIG_INVALID_DATA: |
| 336 | desc = "config invalid data"; |
| 337 | break; |
| 338 | case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS: |
| 339 | desc = "config no defaults"; |
| 340 | break; |
| 341 | case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT: |
| 342 | desc = "config cant commit"; |
| 343 | break; |
| 344 | |
| 345 | /**************************************************************************** |
| 346 | * SCSI IO Reply |
| 347 | ****************************************************************************/ |
| 348 | |
| 349 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 350 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 351 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 352 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 353 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 354 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 355 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 356 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 357 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 358 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 359 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 360 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 361 | break; |
| 362 | |
| 363 | /**************************************************************************** |
| 364 | * For use by SCSI Initiator and SCSI Target end-to-end data protection |
| 365 | ****************************************************************************/ |
| 366 | |
| 367 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 368 | desc = "eedp guard error"; |
| 369 | break; |
| 370 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 371 | desc = "eedp ref tag error"; |
| 372 | break; |
| 373 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 374 | desc = "eedp app tag error"; |
| 375 | break; |
| 376 | |
| 377 | /**************************************************************************** |
| 378 | * SCSI Target values |
| 379 | ****************************************************************************/ |
| 380 | |
| 381 | case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX: |
| 382 | desc = "target invalid io index"; |
| 383 | break; |
| 384 | case MPI2_IOCSTATUS_TARGET_ABORTED: |
| 385 | desc = "target aborted"; |
| 386 | break; |
| 387 | case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: |
| 388 | desc = "target no conn retryable"; |
| 389 | break; |
| 390 | case MPI2_IOCSTATUS_TARGET_NO_CONNECTION: |
| 391 | desc = "target no connection"; |
| 392 | break; |
| 393 | case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: |
| 394 | desc = "target xfer count mismatch"; |
| 395 | break; |
| 396 | case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: |
| 397 | desc = "target data offset error"; |
| 398 | break; |
| 399 | case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: |
| 400 | desc = "target too much write data"; |
| 401 | break; |
| 402 | case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT: |
| 403 | desc = "target iu too short"; |
| 404 | break; |
| 405 | case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: |
| 406 | desc = "target ack nak timeout"; |
| 407 | break; |
| 408 | case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED: |
| 409 | desc = "target nak received"; |
| 410 | break; |
| 411 | |
| 412 | /**************************************************************************** |
| 413 | * Serial Attached SCSI values |
| 414 | ****************************************************************************/ |
| 415 | |
| 416 | case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED: |
| 417 | desc = "smp request failed"; |
| 418 | break; |
| 419 | case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN: |
| 420 | desc = "smp data overrun"; |
| 421 | break; |
| 422 | |
| 423 | /**************************************************************************** |
| 424 | * Diagnostic Buffer Post / Diagnostic Release values |
| 425 | ****************************************************************************/ |
| 426 | |
| 427 | case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED: |
| 428 | desc = "diagnostic released"; |
| 429 | break; |
| 430 | default: |
| 431 | break; |
| 432 | } |
| 433 | |
| 434 | if (!desc) |
| 435 | return; |
| 436 | |
| 437 | switch (request_hdr->Function) { |
| 438 | case MPI2_FUNCTION_CONFIG: |
| 439 | frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size; |
| 440 | func_str = "config_page"; |
| 441 | break; |
| 442 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 443 | frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t); |
| 444 | func_str = "task_mgmt"; |
| 445 | break; |
| 446 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: |
| 447 | frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t); |
| 448 | func_str = "sas_iounit_ctl"; |
| 449 | break; |
| 450 | case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR: |
| 451 | frame_sz = sizeof(Mpi2SepRequest_t); |
| 452 | func_str = "enclosure"; |
| 453 | break; |
| 454 | case MPI2_FUNCTION_IOC_INIT: |
| 455 | frame_sz = sizeof(Mpi2IOCInitRequest_t); |
| 456 | func_str = "ioc_init"; |
| 457 | break; |
| 458 | case MPI2_FUNCTION_PORT_ENABLE: |
| 459 | frame_sz = sizeof(Mpi2PortEnableRequest_t); |
| 460 | func_str = "port_enable"; |
| 461 | break; |
| 462 | case MPI2_FUNCTION_SMP_PASSTHROUGH: |
| 463 | frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size; |
| 464 | func_str = "smp_passthru"; |
| 465 | break; |
| 466 | default: |
| 467 | frame_sz = 32; |
| 468 | func_str = "unknown"; |
| 469 | break; |
| 470 | } |
| 471 | |
| 472 | printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p)," |
| 473 | " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str); |
| 474 | |
| 475 | _debug_dump_mf(request_hdr, frame_sz/4); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * _base_display_event_data - verbose translation of firmware asyn events |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 480 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 481 | * @mpi_reply: reply mf payload returned from firmware |
| 482 | * |
| 483 | * Return nothing. |
| 484 | */ |
| 485 | static void |
| 486 | _base_display_event_data(struct MPT2SAS_ADAPTER *ioc, |
| 487 | Mpi2EventNotificationReply_t *mpi_reply) |
| 488 | { |
| 489 | char *desc = NULL; |
| 490 | u16 event; |
| 491 | |
| 492 | if (!(ioc->logging_level & MPT_DEBUG_EVENTS)) |
| 493 | return; |
| 494 | |
| 495 | event = le16_to_cpu(mpi_reply->Event); |
| 496 | |
| 497 | switch (event) { |
| 498 | case MPI2_EVENT_LOG_DATA: |
| 499 | desc = "Log Data"; |
| 500 | break; |
| 501 | case MPI2_EVENT_STATE_CHANGE: |
| 502 | desc = "Status Change"; |
| 503 | break; |
| 504 | case MPI2_EVENT_HARD_RESET_RECEIVED: |
| 505 | desc = "Hard Reset Received"; |
| 506 | break; |
| 507 | case MPI2_EVENT_EVENT_CHANGE: |
| 508 | desc = "Event Change"; |
| 509 | break; |
| 510 | case MPI2_EVENT_TASK_SET_FULL: |
| 511 | desc = "Task Set Full"; |
| 512 | break; |
| 513 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 514 | desc = "Device Status Change"; |
| 515 | break; |
| 516 | case MPI2_EVENT_IR_OPERATION_STATUS: |
| 517 | desc = "IR Operation Status"; |
| 518 | break; |
| 519 | case MPI2_EVENT_SAS_DISCOVERY: |
| 520 | desc = "Discovery"; |
| 521 | break; |
| 522 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 523 | desc = "SAS Broadcast Primitive"; |
| 524 | break; |
| 525 | case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE: |
| 526 | desc = "SAS Init Device Status Change"; |
| 527 | break; |
| 528 | case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW: |
| 529 | desc = "SAS Init Table Overflow"; |
| 530 | break; |
| 531 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 532 | desc = "SAS Topology Change List"; |
| 533 | break; |
| 534 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 535 | desc = "SAS Enclosure Device Status Change"; |
| 536 | break; |
| 537 | case MPI2_EVENT_IR_VOLUME: |
| 538 | desc = "IR Volume"; |
| 539 | break; |
| 540 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
| 541 | desc = "IR Physical Disk"; |
| 542 | break; |
| 543 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
| 544 | desc = "IR Configuration Change List"; |
| 545 | break; |
| 546 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
| 547 | desc = "Log Entry Added"; |
| 548 | break; |
| 549 | } |
| 550 | |
| 551 | if (!desc) |
| 552 | return; |
| 553 | |
| 554 | printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc); |
| 555 | } |
| 556 | #endif |
| 557 | |
| 558 | /** |
| 559 | * _base_sas_log_info - verbose translation of firmware log info |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 560 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 561 | * @log_info: log info |
| 562 | * |
| 563 | * Return nothing. |
| 564 | */ |
| 565 | static void |
| 566 | _base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info) |
| 567 | { |
| 568 | union loginfo_type { |
| 569 | u32 loginfo; |
| 570 | struct { |
| 571 | u32 subcode:16; |
| 572 | u32 code:8; |
| 573 | u32 originator:4; |
| 574 | u32 bus_type:4; |
| 575 | } dw; |
| 576 | }; |
| 577 | union loginfo_type sas_loginfo; |
| 578 | char *originator_str = NULL; |
| 579 | |
| 580 | sas_loginfo.loginfo = log_info; |
| 581 | if (sas_loginfo.dw.bus_type != 3 /*SAS*/) |
| 582 | return; |
| 583 | |
Kashyap, Desai | be9e8cd7 | 2009-08-07 19:36:43 +0530 | [diff] [blame] | 584 | /* each nexus loss loginfo */ |
| 585 | if (log_info == 0x31170000) |
| 586 | return; |
| 587 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 588 | /* eat the loginfos associated with task aborts */ |
| 589 | if (ioc->ignore_loginfos && (log_info == 30050000 || log_info == |
| 590 | 0x31140000 || log_info == 0x31130000)) |
| 591 | return; |
| 592 | |
| 593 | switch (sas_loginfo.dw.originator) { |
| 594 | case 0: |
| 595 | originator_str = "IOP"; |
| 596 | break; |
| 597 | case 1: |
| 598 | originator_str = "PL"; |
| 599 | break; |
| 600 | case 2: |
| 601 | originator_str = "IR"; |
| 602 | break; |
| 603 | } |
| 604 | |
| 605 | printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), " |
| 606 | "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info, |
| 607 | originator_str, sas_loginfo.dw.code, |
| 608 | sas_loginfo.dw.subcode); |
| 609 | } |
| 610 | |
| 611 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 612 | * _base_display_reply_info - |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 613 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 614 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 615 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 616 | * @reply: reply message frame(lower 32bit addr) |
| 617 | * |
| 618 | * Return nothing. |
| 619 | */ |
| 620 | static void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 621 | _base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 622 | u32 reply) |
| 623 | { |
| 624 | MPI2DefaultReply_t *mpi_reply; |
| 625 | u16 ioc_status; |
| 626 | |
| 627 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 628 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
| 629 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 630 | if ((ioc_status & MPI2_IOCSTATUS_MASK) && |
| 631 | (ioc->logging_level & MPT_DEBUG_REPLY)) { |
| 632 | _base_sas_ioc_info(ioc , mpi_reply, |
| 633 | mpt2sas_base_get_msg_frame(ioc, smid)); |
| 634 | } |
| 635 | #endif |
| 636 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) |
| 637 | _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo)); |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * mpt2sas_base_done - base internal command completion routine |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 642 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 643 | * @smid: system request message index |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 644 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 645 | * @reply: reply message frame(lower 32bit addr) |
| 646 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 647 | * Return 1 meaning mf should be freed from _base_interrupt |
| 648 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 649 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 650 | u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 651 | mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 652 | u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 653 | { |
| 654 | MPI2DefaultReply_t *mpi_reply; |
| 655 | |
| 656 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 657 | if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 658 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 659 | |
| 660 | if (ioc->base_cmds.status == MPT2_CMD_NOT_USED) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 661 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 662 | |
| 663 | ioc->base_cmds.status |= MPT2_CMD_COMPLETE; |
| 664 | if (mpi_reply) { |
| 665 | ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID; |
| 666 | memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 667 | } |
| 668 | ioc->base_cmds.status &= ~MPT2_CMD_PENDING; |
| 669 | complete(&ioc->base_cmds.done); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 670 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /** |
| 674 | * _base_async_event - main callback handler for firmware asyn events |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 675 | * @ioc: per adapter object |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 676 | * @msix_index: MSIX table index supplied by the OS |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 677 | * @reply: reply message frame(lower 32bit addr) |
| 678 | * |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 679 | * Return 1 meaning mf should be freed from _base_interrupt |
| 680 | * 0 means the mf is freed from this function. |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 681 | */ |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 682 | static u8 |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 683 | _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 684 | { |
| 685 | Mpi2EventNotificationReply_t *mpi_reply; |
| 686 | Mpi2EventAckRequest_t *ack_request; |
| 687 | u16 smid; |
| 688 | |
| 689 | mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply); |
| 690 | if (!mpi_reply) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 691 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 692 | if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION) |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 693 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 694 | #ifdef CONFIG_SCSI_MPT2SAS_LOGGING |
| 695 | _base_display_event_data(ioc, mpi_reply); |
| 696 | #endif |
| 697 | if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED)) |
| 698 | goto out; |
| 699 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 700 | if (!smid) { |
| 701 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 702 | ioc->name, __func__); |
| 703 | goto out; |
| 704 | } |
| 705 | |
| 706 | ack_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 707 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); |
| 708 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; |
| 709 | ack_request->Event = mpi_reply->Event; |
| 710 | ack_request->EventContext = mpi_reply->EventContext; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 711 | ack_request->VF_ID = 0; /* TODO */ |
| 712 | ack_request->VP_ID = 0; |
| 713 | mpt2sas_base_put_smid_default(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 714 | |
| 715 | out: |
| 716 | |
| 717 | /* scsih callback handler */ |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 718 | mpt2sas_scsih_event_callback(ioc, msix_index, reply); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 719 | |
| 720 | /* ctl callback handler */ |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 721 | mpt2sas_ctl_event_callback(ioc, msix_index, reply); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 722 | |
| 723 | return 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 727 | * _base_get_cb_idx - obtain the callback index |
| 728 | * @ioc: per adapter object |
| 729 | * @smid: system request message index |
| 730 | * |
| 731 | * Return callback index. |
| 732 | */ |
| 733 | static u8 |
| 734 | _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 735 | { |
| 736 | int i; |
| 737 | u8 cb_idx = 0xFF; |
| 738 | |
| 739 | if (smid >= ioc->hi_priority_smid) { |
| 740 | if (smid < ioc->internal_smid) { |
| 741 | i = smid - ioc->hi_priority_smid; |
| 742 | cb_idx = ioc->hpr_lookup[i].cb_idx; |
| 743 | } else { |
| 744 | i = smid - ioc->internal_smid; |
| 745 | cb_idx = ioc->internal_lookup[i].cb_idx; |
| 746 | } |
| 747 | } else { |
| 748 | i = smid - 1; |
| 749 | cb_idx = ioc->scsi_lookup[i].cb_idx; |
| 750 | } |
| 751 | return cb_idx; |
| 752 | } |
| 753 | |
| 754 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 755 | * _base_mask_interrupts - disable interrupts |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 756 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 757 | * |
| 758 | * Disabling ResetIRQ, Reply and Doorbell Interrupts |
| 759 | * |
| 760 | * Return nothing. |
| 761 | */ |
| 762 | static void |
| 763 | _base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc) |
| 764 | { |
| 765 | u32 him_register; |
| 766 | |
| 767 | ioc->mask_interrupts = 1; |
| 768 | him_register = readl(&ioc->chip->HostInterruptMask); |
| 769 | him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK; |
| 770 | writel(him_register, &ioc->chip->HostInterruptMask); |
| 771 | readl(&ioc->chip->HostInterruptMask); |
| 772 | } |
| 773 | |
| 774 | /** |
| 775 | * _base_unmask_interrupts - enable interrupts |
Kashyap, Desai | cef7a12 | 2009-09-23 17:27:41 +0530 | [diff] [blame] | 776 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 777 | * |
| 778 | * Enabling only Reply Interrupts |
| 779 | * |
| 780 | * Return nothing. |
| 781 | */ |
| 782 | static void |
| 783 | _base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc) |
| 784 | { |
| 785 | u32 him_register; |
| 786 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 787 | him_register = readl(&ioc->chip->HostInterruptMask); |
| 788 | him_register &= ~MPI2_HIM_RIM; |
| 789 | writel(him_register, &ioc->chip->HostInterruptMask); |
| 790 | ioc->mask_interrupts = 0; |
| 791 | } |
| 792 | |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 793 | union reply_descriptor { |
| 794 | u64 word; |
| 795 | struct { |
| 796 | u32 low; |
| 797 | u32 high; |
| 798 | } u; |
| 799 | }; |
| 800 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 801 | /** |
| 802 | * _base_interrupt - MPT adapter (IOC) specific interrupt handler. |
| 803 | * @irq: irq number (not used) |
| 804 | * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure |
| 805 | * @r: pt_regs pointer (not used) |
| 806 | * |
| 807 | * Return IRQ_HANDLE if processed, else IRQ_NONE. |
| 808 | */ |
| 809 | static irqreturn_t |
| 810 | _base_interrupt(int irq, void *bus_id) |
| 811 | { |
Eric Moore | 03ea111 | 2009-04-21 15:37:57 -0600 | [diff] [blame] | 812 | union reply_descriptor rd; |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 813 | u32 completed_cmds; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 814 | u8 request_desript_type; |
| 815 | u16 smid; |
| 816 | u8 cb_idx; |
| 817 | u32 reply; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 818 | u8 msix_index; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 819 | struct MPT2SAS_ADAPTER *ioc = bus_id; |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 820 | Mpi2ReplyDescriptorsUnion_t *rpf; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 821 | u8 rc; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 822 | |
| 823 | if (ioc->mask_interrupts) |
| 824 | return IRQ_NONE; |
| 825 | |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 826 | rpf = &ioc->reply_post_free[ioc->reply_post_host_index]; |
| 827 | request_desript_type = rpf->Default.ReplyFlags |
| 828 | & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 829 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 830 | return IRQ_NONE; |
| 831 | |
| 832 | completed_cmds = 0; |
| 833 | do { |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 834 | rd.word = rpf->Words; |
Eric Moore | 03ea111 | 2009-04-21 15:37:57 -0600 | [diff] [blame] | 835 | if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 836 | goto out; |
| 837 | reply = 0; |
| 838 | cb_idx = 0xFF; |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 839 | smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 840 | msix_index = rpf->Default.MSIxIndex; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 841 | if (request_desript_type == |
| 842 | MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) { |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 843 | reply = le32_to_cpu |
| 844 | (rpf->AddressReply.ReplyFrameAddress); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 845 | } else if (request_desript_type == |
| 846 | MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER) |
| 847 | goto next; |
| 848 | else if (request_desript_type == |
| 849 | MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS) |
| 850 | goto next; |
| 851 | if (smid) |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 852 | cb_idx = _base_get_cb_idx(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 853 | if (smid && cb_idx != 0xFF) { |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 854 | rc = mpt_callbacks[cb_idx](ioc, smid, msix_index, |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 855 | reply); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 856 | if (reply) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 857 | _base_display_reply_info(ioc, smid, msix_index, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 858 | reply); |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 859 | if (rc) |
| 860 | mpt2sas_base_free_smid(ioc, smid); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 861 | } |
| 862 | if (!smid) |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 863 | _base_async_event(ioc, msix_index, reply); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 864 | |
| 865 | /* reply free queue handling */ |
| 866 | if (reply) { |
| 867 | ioc->reply_free_host_index = |
| 868 | (ioc->reply_free_host_index == |
| 869 | (ioc->reply_free_queue_depth - 1)) ? |
| 870 | 0 : ioc->reply_free_host_index + 1; |
| 871 | ioc->reply_free[ioc->reply_free_host_index] = |
| 872 | cpu_to_le32(reply); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 873 | wmb(); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 874 | writel(ioc->reply_free_host_index, |
| 875 | &ioc->chip->ReplyFreeHostIndex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | next: |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 879 | |
| 880 | rpf->Words = ULLONG_MAX; |
| 881 | ioc->reply_post_host_index = (ioc->reply_post_host_index == |
| 882 | (ioc->reply_post_queue_depth - 1)) ? 0 : |
| 883 | ioc->reply_post_host_index + 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 884 | request_desript_type = |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 885 | ioc->reply_post_free[ioc->reply_post_host_index].Default. |
| 886 | ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 887 | completed_cmds++; |
| 888 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 889 | goto out; |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 890 | if (!ioc->reply_post_host_index) |
| 891 | rpf = ioc->reply_post_free; |
| 892 | else |
| 893 | rpf++; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 894 | } while (1); |
| 895 | |
| 896 | out: |
| 897 | |
| 898 | if (!completed_cmds) |
| 899 | return IRQ_NONE; |
| 900 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 901 | wmb(); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 902 | writel(ioc->reply_post_host_index, &ioc->chip->ReplyPostHostIndex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 903 | return IRQ_HANDLED; |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * mpt2sas_base_release_callback_handler - clear interupt callback handler |
| 908 | * @cb_idx: callback index |
| 909 | * |
| 910 | * Return nothing. |
| 911 | */ |
| 912 | void |
| 913 | mpt2sas_base_release_callback_handler(u8 cb_idx) |
| 914 | { |
| 915 | mpt_callbacks[cb_idx] = NULL; |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler |
| 920 | * @cb_func: callback function |
| 921 | * |
| 922 | * Returns cb_func. |
| 923 | */ |
| 924 | u8 |
| 925 | mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func) |
| 926 | { |
| 927 | u8 cb_idx; |
| 928 | |
| 929 | for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--) |
| 930 | if (mpt_callbacks[cb_idx] == NULL) |
| 931 | break; |
| 932 | |
| 933 | mpt_callbacks[cb_idx] = cb_func; |
| 934 | return cb_idx; |
| 935 | } |
| 936 | |
| 937 | /** |
| 938 | * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler |
| 939 | * |
| 940 | * Return nothing. |
| 941 | */ |
| 942 | void |
| 943 | mpt2sas_base_initialize_callback_handler(void) |
| 944 | { |
| 945 | u8 cb_idx; |
| 946 | |
| 947 | for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++) |
| 948 | mpt2sas_base_release_callback_handler(cb_idx); |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * mpt2sas_base_build_zero_len_sge - build zero length sg entry |
| 953 | * @ioc: per adapter object |
| 954 | * @paddr: virtual address for SGE |
| 955 | * |
| 956 | * Create a zero length scatter gather entry to insure the IOCs hardware has |
| 957 | * something to use if the target device goes brain dead and tries |
| 958 | * to send data even when none is asked for. |
| 959 | * |
| 960 | * Return nothing. |
| 961 | */ |
| 962 | void |
| 963 | mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr) |
| 964 | { |
| 965 | u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 966 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST | |
| 967 | MPI2_SGE_FLAGS_SIMPLE_ELEMENT) << |
| 968 | MPI2_SGE_FLAGS_SHIFT); |
| 969 | ioc->base_add_sg_single(paddr, flags_length, -1); |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr. |
| 974 | * @paddr: virtual address for SGE |
| 975 | * @flags_length: SGE flags and data transfer length |
| 976 | * @dma_addr: Physical address |
| 977 | * |
| 978 | * Return nothing. |
| 979 | */ |
| 980 | static void |
| 981 | _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr) |
| 982 | { |
| 983 | Mpi2SGESimple32_t *sgel = paddr; |
| 984 | |
| 985 | flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING | |
| 986 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; |
| 987 | sgel->FlagsLength = cpu_to_le32(flags_length); |
| 988 | sgel->Address = cpu_to_le32(dma_addr); |
| 989 | } |
| 990 | |
| 991 | |
| 992 | /** |
| 993 | * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr. |
| 994 | * @paddr: virtual address for SGE |
| 995 | * @flags_length: SGE flags and data transfer length |
| 996 | * @dma_addr: Physical address |
| 997 | * |
| 998 | * Return nothing. |
| 999 | */ |
| 1000 | static void |
| 1001 | _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr) |
| 1002 | { |
| 1003 | Mpi2SGESimple64_t *sgel = paddr; |
| 1004 | |
| 1005 | flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING | |
| 1006 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; |
| 1007 | sgel->FlagsLength = cpu_to_le32(flags_length); |
| 1008 | sgel->Address = cpu_to_le64(dma_addr); |
| 1009 | } |
| 1010 | |
| 1011 | #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10)) |
| 1012 | |
| 1013 | /** |
| 1014 | * _base_config_dma_addressing - set dma addressing |
| 1015 | * @ioc: per adapter object |
| 1016 | * @pdev: PCI device struct |
| 1017 | * |
| 1018 | * Returns 0 for success, non-zero for failure. |
| 1019 | */ |
| 1020 | static int |
| 1021 | _base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev) |
| 1022 | { |
| 1023 | struct sysinfo s; |
| 1024 | char *desc = NULL; |
| 1025 | |
| 1026 | if (sizeof(dma_addr_t) > 4) { |
| 1027 | const uint64_t required_mask = |
| 1028 | dma_get_required_mask(&pdev->dev); |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 1029 | if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev, |
| 1030 | DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev, |
| 1031 | DMA_BIT_MASK(64))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1032 | ioc->base_add_sg_single = &_base_add_sg_single_64; |
| 1033 | ioc->sge_size = sizeof(Mpi2SGESimple64_t); |
| 1034 | desc = "64"; |
| 1035 | goto out; |
| 1036 | } |
| 1037 | } |
| 1038 | |
Yang Hongyang | e930438 | 2009-04-13 14:40:14 -0700 | [diff] [blame] | 1039 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 1040 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1041 | ioc->base_add_sg_single = &_base_add_sg_single_32; |
| 1042 | ioc->sge_size = sizeof(Mpi2SGESimple32_t); |
| 1043 | desc = "32"; |
| 1044 | } else |
| 1045 | return -ENODEV; |
| 1046 | |
| 1047 | out: |
| 1048 | si_meminfo(&s); |
| 1049 | printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, " |
| 1050 | "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram)); |
| 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | /** |
| 1056 | * _base_save_msix_table - backup msix vector table |
| 1057 | * @ioc: per adapter object |
| 1058 | * |
| 1059 | * This address an errata where diag reset clears out the table |
| 1060 | */ |
| 1061 | static void |
| 1062 | _base_save_msix_table(struct MPT2SAS_ADAPTER *ioc) |
| 1063 | { |
| 1064 | int i; |
| 1065 | |
| 1066 | if (!ioc->msix_enable || ioc->msix_table_backup == NULL) |
| 1067 | return; |
| 1068 | |
| 1069 | for (i = 0; i < ioc->msix_vector_count; i++) |
| 1070 | ioc->msix_table_backup[i] = ioc->msix_table[i]; |
| 1071 | } |
| 1072 | |
| 1073 | /** |
| 1074 | * _base_restore_msix_table - this restores the msix vector table |
| 1075 | * @ioc: per adapter object |
| 1076 | * |
| 1077 | */ |
| 1078 | static void |
| 1079 | _base_restore_msix_table(struct MPT2SAS_ADAPTER *ioc) |
| 1080 | { |
| 1081 | int i; |
| 1082 | |
| 1083 | if (!ioc->msix_enable || ioc->msix_table_backup == NULL) |
| 1084 | return; |
| 1085 | |
| 1086 | for (i = 0; i < ioc->msix_vector_count; i++) |
| 1087 | ioc->msix_table[i] = ioc->msix_table_backup[i]; |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * _base_check_enable_msix - checks MSIX capabable. |
| 1092 | * @ioc: per adapter object |
| 1093 | * |
| 1094 | * Check to see if card is capable of MSIX, and set number |
| 1095 | * of avaliable msix vectors |
| 1096 | */ |
| 1097 | static int |
| 1098 | _base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc) |
| 1099 | { |
| 1100 | int base; |
| 1101 | u16 message_control; |
| 1102 | u32 msix_table_offset; |
| 1103 | |
| 1104 | base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); |
| 1105 | if (!base) { |
| 1106 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not " |
| 1107 | "supported\n", ioc->name)); |
| 1108 | return -EINVAL; |
| 1109 | } |
| 1110 | |
| 1111 | /* get msix vector count */ |
| 1112 | pci_read_config_word(ioc->pdev, base + 2, &message_control); |
| 1113 | ioc->msix_vector_count = (message_control & 0x3FF) + 1; |
| 1114 | |
| 1115 | /* get msix table */ |
| 1116 | pci_read_config_dword(ioc->pdev, base + 4, &msix_table_offset); |
| 1117 | msix_table_offset &= 0xFFFFFFF8; |
| 1118 | ioc->msix_table = (u32 *)((void *)ioc->chip + msix_table_offset); |
| 1119 | |
| 1120 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, " |
| 1121 | "vector_count(%d), table_offset(0x%08x), table(%p)\n", ioc->name, |
| 1122 | ioc->msix_vector_count, msix_table_offset, ioc->msix_table)); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
| 1127 | * _base_disable_msix - disables msix |
| 1128 | * @ioc: per adapter object |
| 1129 | * |
| 1130 | */ |
| 1131 | static void |
| 1132 | _base_disable_msix(struct MPT2SAS_ADAPTER *ioc) |
| 1133 | { |
| 1134 | if (ioc->msix_enable) { |
| 1135 | pci_disable_msix(ioc->pdev); |
| 1136 | kfree(ioc->msix_table_backup); |
| 1137 | ioc->msix_table_backup = NULL; |
| 1138 | ioc->msix_enable = 0; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | /** |
| 1143 | * _base_enable_msix - enables msix, failback to io_apic |
| 1144 | * @ioc: per adapter object |
| 1145 | * |
| 1146 | */ |
| 1147 | static int |
| 1148 | _base_enable_msix(struct MPT2SAS_ADAPTER *ioc) |
| 1149 | { |
| 1150 | struct msix_entry entries; |
| 1151 | int r; |
| 1152 | u8 try_msix = 0; |
| 1153 | |
| 1154 | if (msix_disable == -1 || msix_disable == 0) |
| 1155 | try_msix = 1; |
| 1156 | |
| 1157 | if (!try_msix) |
| 1158 | goto try_ioapic; |
| 1159 | |
| 1160 | if (_base_check_enable_msix(ioc) != 0) |
| 1161 | goto try_ioapic; |
| 1162 | |
| 1163 | ioc->msix_table_backup = kcalloc(ioc->msix_vector_count, |
| 1164 | sizeof(u32), GFP_KERNEL); |
| 1165 | if (!ioc->msix_table_backup) { |
| 1166 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for " |
| 1167 | "msix_table_backup failed!!!\n", ioc->name)); |
| 1168 | goto try_ioapic; |
| 1169 | } |
| 1170 | |
| 1171 | memset(&entries, 0, sizeof(struct msix_entry)); |
| 1172 | r = pci_enable_msix(ioc->pdev, &entries, 1); |
| 1173 | if (r) { |
| 1174 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix " |
| 1175 | "failed (r=%d) !!!\n", ioc->name, r)); |
| 1176 | goto try_ioapic; |
| 1177 | } |
| 1178 | |
| 1179 | r = request_irq(entries.vector, _base_interrupt, IRQF_SHARED, |
| 1180 | ioc->name, ioc); |
| 1181 | if (r) { |
| 1182 | dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "unable to allocate " |
| 1183 | "interrupt %d !!!\n", ioc->name, entries.vector)); |
| 1184 | pci_disable_msix(ioc->pdev); |
| 1185 | goto try_ioapic; |
| 1186 | } |
| 1187 | |
| 1188 | ioc->pci_irq = entries.vector; |
| 1189 | ioc->msix_enable = 1; |
| 1190 | return 0; |
| 1191 | |
| 1192 | /* failback to io_apic interrupt routing */ |
| 1193 | try_ioapic: |
| 1194 | |
| 1195 | r = request_irq(ioc->pdev->irq, _base_interrupt, IRQF_SHARED, |
| 1196 | ioc->name, ioc); |
| 1197 | if (r) { |
| 1198 | printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n", |
| 1199 | ioc->name, ioc->pdev->irq); |
| 1200 | r = -EBUSY; |
| 1201 | goto out_fail; |
| 1202 | } |
| 1203 | |
| 1204 | ioc->pci_irq = ioc->pdev->irq; |
| 1205 | return 0; |
| 1206 | |
| 1207 | out_fail: |
| 1208 | return r; |
| 1209 | } |
| 1210 | |
| 1211 | /** |
| 1212 | * mpt2sas_base_map_resources - map in controller resources (io/irq/memap) |
| 1213 | * @ioc: per adapter object |
| 1214 | * |
| 1215 | * Returns 0 for success, non-zero for failure. |
| 1216 | */ |
| 1217 | int |
| 1218 | mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc) |
| 1219 | { |
| 1220 | struct pci_dev *pdev = ioc->pdev; |
| 1221 | u32 memap_sz; |
| 1222 | u32 pio_sz; |
| 1223 | int i, r = 0; |
| 1224 | |
| 1225 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", |
| 1226 | ioc->name, __func__)); |
| 1227 | |
| 1228 | ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 1229 | if (pci_enable_device_mem(pdev)) { |
| 1230 | printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: " |
| 1231 | "failed\n", ioc->name); |
| 1232 | return -ENODEV; |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | if (pci_request_selected_regions(pdev, ioc->bars, |
| 1237 | MPT2SAS_DRIVER_NAME)) { |
| 1238 | printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: " |
| 1239 | "failed\n", ioc->name); |
| 1240 | r = -ENODEV; |
| 1241 | goto out_fail; |
| 1242 | } |
| 1243 | |
| 1244 | pci_set_master(pdev); |
| 1245 | |
| 1246 | if (_base_config_dma_addressing(ioc, pdev) != 0) { |
| 1247 | printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n", |
| 1248 | ioc->name, pci_name(pdev)); |
| 1249 | r = -ENODEV; |
| 1250 | goto out_fail; |
| 1251 | } |
| 1252 | |
| 1253 | for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) { |
| 1254 | if (pci_resource_flags(pdev, i) & PCI_BASE_ADDRESS_SPACE_IO) { |
| 1255 | if (pio_sz) |
| 1256 | continue; |
| 1257 | ioc->pio_chip = pci_resource_start(pdev, i); |
| 1258 | pio_sz = pci_resource_len(pdev, i); |
| 1259 | } else { |
| 1260 | if (memap_sz) |
| 1261 | continue; |
| 1262 | ioc->chip_phys = pci_resource_start(pdev, i); |
| 1263 | memap_sz = pci_resource_len(pdev, i); |
| 1264 | ioc->chip = ioremap(ioc->chip_phys, memap_sz); |
| 1265 | if (ioc->chip == NULL) { |
| 1266 | printk(MPT2SAS_ERR_FMT "unable to map adapter " |
| 1267 | "memory!\n", ioc->name); |
| 1268 | r = -EINVAL; |
| 1269 | goto out_fail; |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1274 | _base_mask_interrupts(ioc); |
| 1275 | r = _base_enable_msix(ioc); |
| 1276 | if (r) |
| 1277 | goto out_fail; |
| 1278 | |
| 1279 | printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n", |
| 1280 | ioc->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" : |
| 1281 | "IO-APIC enabled"), ioc->pci_irq); |
| 1282 | printk(MPT2SAS_INFO_FMT "iomem(0x%lx), mapped(0x%p), size(%d)\n", |
| 1283 | ioc->name, ioc->chip_phys, ioc->chip, memap_sz); |
| 1284 | printk(MPT2SAS_INFO_FMT "ioport(0x%lx), size(%d)\n", |
| 1285 | ioc->name, ioc->pio_chip, pio_sz); |
| 1286 | |
| 1287 | return 0; |
| 1288 | |
| 1289 | out_fail: |
| 1290 | if (ioc->chip_phys) |
| 1291 | iounmap(ioc->chip); |
| 1292 | ioc->chip_phys = 0; |
| 1293 | ioc->pci_irq = -1; |
| 1294 | pci_release_selected_regions(ioc->pdev, ioc->bars); |
| 1295 | pci_disable_device(pdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1296 | return r; |
| 1297 | } |
| 1298 | |
| 1299 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1300 | * mpt2sas_base_get_msg_frame - obtain request mf pointer |
| 1301 | * @ioc: per adapter object |
| 1302 | * @smid: system request message index(smid zero is invalid) |
| 1303 | * |
| 1304 | * Returns virt pointer to message frame. |
| 1305 | */ |
| 1306 | void * |
| 1307 | mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 1308 | { |
| 1309 | return (void *)(ioc->request + (smid * ioc->request_sz)); |
| 1310 | } |
| 1311 | |
| 1312 | /** |
| 1313 | * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request |
| 1314 | * @ioc: per adapter object |
| 1315 | * @smid: system request message index |
| 1316 | * |
| 1317 | * Returns virt pointer to sense buffer. |
| 1318 | */ |
| 1319 | void * |
| 1320 | mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 1321 | { |
| 1322 | return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE)); |
| 1323 | } |
| 1324 | |
| 1325 | /** |
| 1326 | * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request |
| 1327 | * @ioc: per adapter object |
| 1328 | * @smid: system request message index |
| 1329 | * |
| 1330 | * Returns phys pointer to sense buffer. |
| 1331 | */ |
| 1332 | dma_addr_t |
| 1333 | mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 1334 | { |
| 1335 | return ioc->sense_dma + ((smid - 1) * SCSI_SENSE_BUFFERSIZE); |
| 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address |
| 1340 | * @ioc: per adapter object |
| 1341 | * @phys_addr: lower 32 physical addr of the reply |
| 1342 | * |
| 1343 | * Converts 32bit lower physical addr into a virt address. |
| 1344 | */ |
| 1345 | void * |
| 1346 | mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr) |
| 1347 | { |
| 1348 | if (!phys_addr) |
| 1349 | return NULL; |
| 1350 | return ioc->reply + (phys_addr - (u32)ioc->reply_dma); |
| 1351 | } |
| 1352 | |
| 1353 | /** |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1354 | * mpt2sas_base_get_smid - obtain a free smid from internal queue |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1355 | * @ioc: per adapter object |
| 1356 | * @cb_idx: callback index |
| 1357 | * |
| 1358 | * Returns smid (zero is invalid) |
| 1359 | */ |
| 1360 | u16 |
| 1361 | mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx) |
| 1362 | { |
| 1363 | unsigned long flags; |
| 1364 | struct request_tracker *request; |
| 1365 | u16 smid; |
| 1366 | |
| 1367 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1368 | if (list_empty(&ioc->internal_free_list)) { |
| 1369 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1370 | printk(MPT2SAS_ERR_FMT "%s: smid not available\n", |
| 1371 | ioc->name, __func__); |
| 1372 | return 0; |
| 1373 | } |
| 1374 | |
| 1375 | request = list_entry(ioc->internal_free_list.next, |
| 1376 | struct request_tracker, tracker_list); |
| 1377 | request->cb_idx = cb_idx; |
| 1378 | smid = request->smid; |
| 1379 | list_del(&request->tracker_list); |
| 1380 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1381 | return smid; |
| 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue |
| 1386 | * @ioc: per adapter object |
| 1387 | * @cb_idx: callback index |
| 1388 | * @scmd: pointer to scsi command object |
| 1389 | * |
| 1390 | * Returns smid (zero is invalid) |
| 1391 | */ |
| 1392 | u16 |
| 1393 | mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx, |
| 1394 | struct scsi_cmnd *scmd) |
| 1395 | { |
| 1396 | unsigned long flags; |
| 1397 | struct request_tracker *request; |
| 1398 | u16 smid; |
| 1399 | |
| 1400 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1401 | if (list_empty(&ioc->free_list)) { |
| 1402 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1403 | printk(MPT2SAS_ERR_FMT "%s: smid not available\n", |
| 1404 | ioc->name, __func__); |
| 1405 | return 0; |
| 1406 | } |
| 1407 | |
| 1408 | request = list_entry(ioc->free_list.next, |
| 1409 | struct request_tracker, tracker_list); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1410 | request->scmd = scmd; |
| 1411 | request->cb_idx = cb_idx; |
| 1412 | smid = request->smid; |
| 1413 | list_del(&request->tracker_list); |
| 1414 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1415 | return smid; |
| 1416 | } |
| 1417 | |
| 1418 | /** |
| 1419 | * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue |
| 1420 | * @ioc: per adapter object |
| 1421 | * @cb_idx: callback index |
| 1422 | * |
| 1423 | * Returns smid (zero is invalid) |
| 1424 | */ |
| 1425 | u16 |
| 1426 | mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx) |
| 1427 | { |
| 1428 | unsigned long flags; |
| 1429 | struct request_tracker *request; |
| 1430 | u16 smid; |
| 1431 | |
| 1432 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1433 | if (list_empty(&ioc->hpr_free_list)) { |
| 1434 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | request = list_entry(ioc->hpr_free_list.next, |
| 1439 | struct request_tracker, tracker_list); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1440 | request->cb_idx = cb_idx; |
| 1441 | smid = request->smid; |
| 1442 | list_del(&request->tracker_list); |
| 1443 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1444 | return smid; |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | /** |
| 1449 | * mpt2sas_base_free_smid - put smid back on free_list |
| 1450 | * @ioc: per adapter object |
| 1451 | * @smid: system request message index |
| 1452 | * |
| 1453 | * Return nothing. |
| 1454 | */ |
| 1455 | void |
| 1456 | mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
| 1457 | { |
| 1458 | unsigned long flags; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1459 | int i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1460 | |
| 1461 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1462 | if (smid >= ioc->hi_priority_smid) { |
| 1463 | if (smid < ioc->internal_smid) { |
| 1464 | /* hi-priority */ |
| 1465 | i = smid - ioc->hi_priority_smid; |
| 1466 | ioc->hpr_lookup[i].cb_idx = 0xFF; |
| 1467 | list_add_tail(&ioc->hpr_lookup[i].tracker_list, |
| 1468 | &ioc->hpr_free_list); |
| 1469 | } else { |
| 1470 | /* internal queue */ |
| 1471 | i = smid - ioc->internal_smid; |
| 1472 | ioc->internal_lookup[i].cb_idx = 0xFF; |
| 1473 | list_add_tail(&ioc->internal_lookup[i].tracker_list, |
| 1474 | &ioc->internal_free_list); |
| 1475 | } |
| 1476 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1477 | return; |
| 1478 | } |
| 1479 | |
| 1480 | /* scsiio queue */ |
| 1481 | i = smid - 1; |
| 1482 | ioc->scsi_lookup[i].cb_idx = 0xFF; |
| 1483 | ioc->scsi_lookup[i].scmd = NULL; |
| 1484 | list_add_tail(&ioc->scsi_lookup[i].tracker_list, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1485 | &ioc->free_list); |
| 1486 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1487 | |
| 1488 | /* |
| 1489 | * See _wait_for_commands_to_complete() call with regards to this code. |
| 1490 | */ |
| 1491 | if (ioc->shost_recovery && ioc->pending_io_count) { |
| 1492 | if (ioc->pending_io_count == 1) |
| 1493 | wake_up(&ioc->reset_wq); |
| 1494 | ioc->pending_io_count--; |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | /** |
| 1499 | * _base_writeq - 64 bit write to MMIO |
| 1500 | * @ioc: per adapter object |
| 1501 | * @b: data payload |
| 1502 | * @addr: address in MMIO space |
| 1503 | * @writeq_lock: spin lock |
| 1504 | * |
| 1505 | * Glue for handling an atomic 64 bit word to MMIO. This special handling takes |
| 1506 | * care of 32 bit environment where its not quarenteed to send the entire word |
| 1507 | * in one transfer. |
| 1508 | */ |
| 1509 | #ifndef writeq |
| 1510 | static inline void _base_writeq(__u64 b, volatile void __iomem *addr, |
| 1511 | spinlock_t *writeq_lock) |
| 1512 | { |
| 1513 | unsigned long flags; |
| 1514 | __u64 data_out = cpu_to_le64(b); |
| 1515 | |
| 1516 | spin_lock_irqsave(writeq_lock, flags); |
| 1517 | writel((u32)(data_out), addr); |
| 1518 | writel((u32)(data_out >> 32), (addr + 4)); |
| 1519 | spin_unlock_irqrestore(writeq_lock, flags); |
| 1520 | } |
| 1521 | #else |
| 1522 | static inline void _base_writeq(__u64 b, volatile void __iomem *addr, |
| 1523 | spinlock_t *writeq_lock) |
| 1524 | { |
| 1525 | writeq(cpu_to_le64(b), addr); |
| 1526 | } |
| 1527 | #endif |
| 1528 | |
| 1529 | /** |
| 1530 | * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware |
| 1531 | * @ioc: per adapter object |
| 1532 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1533 | * @handle: device handle |
| 1534 | * |
| 1535 | * Return nothing. |
| 1536 | */ |
| 1537 | void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1538 | mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1539 | { |
| 1540 | Mpi2RequestDescriptorUnion_t descriptor; |
| 1541 | u64 *request = (u64 *)&descriptor; |
| 1542 | |
| 1543 | |
| 1544 | descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1545 | descriptor.SCSIIO.MSIxIndex = 0; /* TODO */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1546 | descriptor.SCSIIO.SMID = cpu_to_le16(smid); |
| 1547 | descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); |
| 1548 | descriptor.SCSIIO.LMID = 0; |
| 1549 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 1550 | &ioc->scsi_lookup_lock); |
| 1551 | } |
| 1552 | |
| 1553 | |
| 1554 | /** |
| 1555 | * mpt2sas_base_put_smid_hi_priority - send Task Managment request to firmware |
| 1556 | * @ioc: per adapter object |
| 1557 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1558 | * |
| 1559 | * Return nothing. |
| 1560 | */ |
| 1561 | void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1562 | mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1563 | { |
| 1564 | Mpi2RequestDescriptorUnion_t descriptor; |
| 1565 | u64 *request = (u64 *)&descriptor; |
| 1566 | |
| 1567 | descriptor.HighPriority.RequestFlags = |
| 1568 | MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1569 | descriptor.HighPriority.MSIxIndex = 0; /* TODO */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1570 | descriptor.HighPriority.SMID = cpu_to_le16(smid); |
| 1571 | descriptor.HighPriority.LMID = 0; |
| 1572 | descriptor.HighPriority.Reserved1 = 0; |
| 1573 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 1574 | &ioc->scsi_lookup_lock); |
| 1575 | } |
| 1576 | |
| 1577 | /** |
| 1578 | * mpt2sas_base_put_smid_default - Default, primarily used for config pages |
| 1579 | * @ioc: per adapter object |
| 1580 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1581 | * |
| 1582 | * Return nothing. |
| 1583 | */ |
| 1584 | void |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1585 | mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1586 | { |
| 1587 | Mpi2RequestDescriptorUnion_t descriptor; |
| 1588 | u64 *request = (u64 *)&descriptor; |
| 1589 | |
| 1590 | descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1591 | descriptor.Default.MSIxIndex = 0; /* TODO */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1592 | descriptor.Default.SMID = cpu_to_le16(smid); |
| 1593 | descriptor.Default.LMID = 0; |
| 1594 | descriptor.Default.DescriptorTypeDependent = 0; |
| 1595 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 1596 | &ioc->scsi_lookup_lock); |
| 1597 | } |
| 1598 | |
| 1599 | /** |
| 1600 | * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware |
| 1601 | * @ioc: per adapter object |
| 1602 | * @smid: system request message index |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1603 | * @io_index: value used to track the IO |
| 1604 | * |
| 1605 | * Return nothing. |
| 1606 | */ |
| 1607 | void |
| 1608 | mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid, |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1609 | u16 io_index) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1610 | { |
| 1611 | Mpi2RequestDescriptorUnion_t descriptor; |
| 1612 | u64 *request = (u64 *)&descriptor; |
| 1613 | |
| 1614 | descriptor.SCSITarget.RequestFlags = |
| 1615 | MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 1616 | descriptor.SCSITarget.MSIxIndex = 0; /* TODO */ |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1617 | descriptor.SCSITarget.SMID = cpu_to_le16(smid); |
| 1618 | descriptor.SCSITarget.LMID = 0; |
| 1619 | descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index); |
| 1620 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 1621 | &ioc->scsi_lookup_lock); |
| 1622 | } |
| 1623 | |
| 1624 | /** |
Eric Moore | f0f9cc1 | 2009-04-21 15:40:48 -0600 | [diff] [blame] | 1625 | * _base_display_dell_branding - Disply branding string |
| 1626 | * @ioc: per adapter object |
| 1627 | * |
| 1628 | * Return nothing. |
| 1629 | */ |
| 1630 | static void |
| 1631 | _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc) |
| 1632 | { |
| 1633 | char dell_branding[MPT2SAS_DELL_BRANDING_SIZE]; |
| 1634 | |
| 1635 | if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL) |
| 1636 | return; |
| 1637 | |
| 1638 | memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE); |
| 1639 | switch (ioc->pdev->subsystem_device) { |
| 1640 | case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID: |
| 1641 | strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING, |
| 1642 | MPT2SAS_DELL_BRANDING_SIZE - 1); |
| 1643 | break; |
| 1644 | case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID: |
| 1645 | strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING, |
| 1646 | MPT2SAS_DELL_BRANDING_SIZE - 1); |
| 1647 | break; |
| 1648 | case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID: |
| 1649 | strncpy(dell_branding, |
| 1650 | MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING, |
| 1651 | MPT2SAS_DELL_BRANDING_SIZE - 1); |
| 1652 | break; |
| 1653 | case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID: |
| 1654 | strncpy(dell_branding, |
| 1655 | MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING, |
| 1656 | MPT2SAS_DELL_BRANDING_SIZE - 1); |
| 1657 | break; |
| 1658 | case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID: |
| 1659 | strncpy(dell_branding, |
| 1660 | MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING, |
| 1661 | MPT2SAS_DELL_BRANDING_SIZE - 1); |
| 1662 | break; |
| 1663 | case MPT2SAS_DELL_PERC_H200_SSDID: |
| 1664 | strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING, |
| 1665 | MPT2SAS_DELL_BRANDING_SIZE - 1); |
| 1666 | break; |
| 1667 | case MPT2SAS_DELL_6GBPS_SAS_SSDID: |
| 1668 | strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING, |
| 1669 | MPT2SAS_DELL_BRANDING_SIZE - 1); |
| 1670 | break; |
| 1671 | default: |
| 1672 | sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device); |
| 1673 | break; |
| 1674 | } |
| 1675 | |
| 1676 | printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X)," |
| 1677 | " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding, |
| 1678 | ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor, |
| 1679 | ioc->pdev->subsystem_device); |
| 1680 | } |
| 1681 | |
| 1682 | /** |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1683 | * _base_display_ioc_capabilities - Disply IOC's capabilities. |
| 1684 | * @ioc: per adapter object |
| 1685 | * |
| 1686 | * Return nothing. |
| 1687 | */ |
| 1688 | static void |
| 1689 | _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc) |
| 1690 | { |
| 1691 | int i = 0; |
| 1692 | char desc[16]; |
| 1693 | u8 revision; |
| 1694 | u32 iounit_pg1_flags; |
| 1695 | |
| 1696 | pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision); |
| 1697 | strncpy(desc, ioc->manu_pg0.ChipName, 16); |
| 1698 | printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), " |
| 1699 | "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n", |
| 1700 | ioc->name, desc, |
| 1701 | (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, |
| 1702 | (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, |
| 1703 | (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, |
| 1704 | ioc->facts.FWVersion.Word & 0x000000FF, |
| 1705 | revision, |
| 1706 | (ioc->bios_pg3.BiosVersion & 0xFF000000) >> 24, |
| 1707 | (ioc->bios_pg3.BiosVersion & 0x00FF0000) >> 16, |
| 1708 | (ioc->bios_pg3.BiosVersion & 0x0000FF00) >> 8, |
| 1709 | ioc->bios_pg3.BiosVersion & 0x000000FF); |
| 1710 | |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 1711 | _base_display_dell_branding(ioc); |
| 1712 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1713 | printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name); |
| 1714 | |
| 1715 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) { |
| 1716 | printk("Initiator"); |
| 1717 | i++; |
| 1718 | } |
| 1719 | |
| 1720 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) { |
| 1721 | printk("%sTarget", i ? "," : ""); |
| 1722 | i++; |
| 1723 | } |
| 1724 | |
| 1725 | i = 0; |
| 1726 | printk("), "); |
| 1727 | printk("Capabilities=("); |
| 1728 | |
| 1729 | if (ioc->facts.IOCCapabilities & |
| 1730 | MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) { |
| 1731 | printk("Raid"); |
| 1732 | i++; |
| 1733 | } |
| 1734 | |
| 1735 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) { |
| 1736 | printk("%sTLR", i ? "," : ""); |
| 1737 | i++; |
| 1738 | } |
| 1739 | |
| 1740 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) { |
| 1741 | printk("%sMulticast", i ? "," : ""); |
| 1742 | i++; |
| 1743 | } |
| 1744 | |
| 1745 | if (ioc->facts.IOCCapabilities & |
| 1746 | MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) { |
| 1747 | printk("%sBIDI Target", i ? "," : ""); |
| 1748 | i++; |
| 1749 | } |
| 1750 | |
| 1751 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) { |
| 1752 | printk("%sEEDP", i ? "," : ""); |
| 1753 | i++; |
| 1754 | } |
| 1755 | |
| 1756 | if (ioc->facts.IOCCapabilities & |
| 1757 | MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) { |
| 1758 | printk("%sSnapshot Buffer", i ? "," : ""); |
| 1759 | i++; |
| 1760 | } |
| 1761 | |
| 1762 | if (ioc->facts.IOCCapabilities & |
| 1763 | MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) { |
| 1764 | printk("%sDiag Trace Buffer", i ? "," : ""); |
| 1765 | i++; |
| 1766 | } |
| 1767 | |
| 1768 | if (ioc->facts.IOCCapabilities & |
Kashyap, Desai | 1b01fe3 | 2009-09-23 17:28:59 +0530 | [diff] [blame^] | 1769 | MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) { |
| 1770 | printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : ""); |
| 1771 | i++; |
| 1772 | } |
| 1773 | |
| 1774 | if (ioc->facts.IOCCapabilities & |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1775 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) { |
| 1776 | printk("%sTask Set Full", i ? "," : ""); |
| 1777 | i++; |
| 1778 | } |
| 1779 | |
| 1780 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); |
| 1781 | if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) { |
| 1782 | printk("%sNCQ", i ? "," : ""); |
| 1783 | i++; |
| 1784 | } |
| 1785 | |
| 1786 | printk(")\n"); |
| 1787 | } |
| 1788 | |
| 1789 | /** |
| 1790 | * _base_static_config_pages - static start of day config pages |
| 1791 | * @ioc: per adapter object |
| 1792 | * |
| 1793 | * Return nothing. |
| 1794 | */ |
| 1795 | static void |
| 1796 | _base_static_config_pages(struct MPT2SAS_ADAPTER *ioc) |
| 1797 | { |
| 1798 | Mpi2ConfigReply_t mpi_reply; |
| 1799 | u32 iounit_pg1_flags; |
| 1800 | |
| 1801 | mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0); |
Kashyap, Desai | ed79f12 | 2009-08-20 13:23:49 +0530 | [diff] [blame] | 1802 | if (ioc->ir_firmware) |
| 1803 | mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply, |
| 1804 | &ioc->manu_pg10); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1805 | mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2); |
| 1806 | mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3); |
| 1807 | mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8); |
| 1808 | mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0); |
| 1809 | mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); |
| 1810 | _base_display_ioc_capabilities(ioc); |
| 1811 | |
| 1812 | /* |
| 1813 | * Enable task_set_full handling in iounit_pg1 when the |
| 1814 | * facts capabilities indicate that its supported. |
| 1815 | */ |
| 1816 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); |
| 1817 | if ((ioc->facts.IOCCapabilities & |
| 1818 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING)) |
| 1819 | iounit_pg1_flags &= |
| 1820 | ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; |
| 1821 | else |
| 1822 | iounit_pg1_flags |= |
| 1823 | MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; |
| 1824 | ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 1825 | mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | /** |
| 1829 | * _base_release_memory_pools - release memory |
| 1830 | * @ioc: per adapter object |
| 1831 | * |
| 1832 | * Free memory allocated from _base_allocate_memory_pools. |
| 1833 | * |
| 1834 | * Return nothing. |
| 1835 | */ |
| 1836 | static void |
| 1837 | _base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc) |
| 1838 | { |
| 1839 | dexitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1840 | __func__)); |
| 1841 | |
| 1842 | if (ioc->request) { |
| 1843 | pci_free_consistent(ioc->pdev, ioc->request_dma_sz, |
| 1844 | ioc->request, ioc->request_dma); |
| 1845 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)" |
| 1846 | ": free\n", ioc->name, ioc->request)); |
| 1847 | ioc->request = NULL; |
| 1848 | } |
| 1849 | |
| 1850 | if (ioc->sense) { |
| 1851 | pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma); |
| 1852 | if (ioc->sense_dma_pool) |
| 1853 | pci_pool_destroy(ioc->sense_dma_pool); |
| 1854 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)" |
| 1855 | ": free\n", ioc->name, ioc->sense)); |
| 1856 | ioc->sense = NULL; |
| 1857 | } |
| 1858 | |
| 1859 | if (ioc->reply) { |
| 1860 | pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma); |
| 1861 | if (ioc->reply_dma_pool) |
| 1862 | pci_pool_destroy(ioc->reply_dma_pool); |
| 1863 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)" |
| 1864 | ": free\n", ioc->name, ioc->reply)); |
| 1865 | ioc->reply = NULL; |
| 1866 | } |
| 1867 | |
| 1868 | if (ioc->reply_free) { |
| 1869 | pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free, |
| 1870 | ioc->reply_free_dma); |
| 1871 | if (ioc->reply_free_dma_pool) |
| 1872 | pci_pool_destroy(ioc->reply_free_dma_pool); |
| 1873 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool" |
| 1874 | "(0x%p): free\n", ioc->name, ioc->reply_free)); |
| 1875 | ioc->reply_free = NULL; |
| 1876 | } |
| 1877 | |
| 1878 | if (ioc->reply_post_free) { |
| 1879 | pci_pool_free(ioc->reply_post_free_dma_pool, |
| 1880 | ioc->reply_post_free, ioc->reply_post_free_dma); |
| 1881 | if (ioc->reply_post_free_dma_pool) |
| 1882 | pci_pool_destroy(ioc->reply_post_free_dma_pool); |
| 1883 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1884 | "reply_post_free_pool(0x%p): free\n", ioc->name, |
| 1885 | ioc->reply_post_free)); |
| 1886 | ioc->reply_post_free = NULL; |
| 1887 | } |
| 1888 | |
| 1889 | if (ioc->config_page) { |
| 1890 | dexitprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 1891 | "config_page(0x%p): free\n", ioc->name, |
| 1892 | ioc->config_page)); |
| 1893 | pci_free_consistent(ioc->pdev, ioc->config_page_sz, |
| 1894 | ioc->config_page, ioc->config_page_dma); |
| 1895 | } |
| 1896 | |
| 1897 | kfree(ioc->scsi_lookup); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1898 | kfree(ioc->hpr_lookup); |
| 1899 | kfree(ioc->internal_lookup); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | |
| 1903 | /** |
| 1904 | * _base_allocate_memory_pools - allocate start of day memory pools |
| 1905 | * @ioc: per adapter object |
| 1906 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 1907 | * |
| 1908 | * Returns 0 success, anything else error |
| 1909 | */ |
| 1910 | static int |
| 1911 | _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
| 1912 | { |
| 1913 | Mpi2IOCFactsReply_t *facts; |
| 1914 | u32 queue_size, queue_diff; |
| 1915 | u16 max_sge_elements; |
| 1916 | u16 num_of_reply_frames; |
| 1917 | u16 chains_needed_per_io; |
| 1918 | u32 sz, total_sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1919 | u32 retry_sz; |
| 1920 | u16 max_request_credit; |
| 1921 | |
| 1922 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 1923 | __func__)); |
| 1924 | |
| 1925 | retry_sz = 0; |
| 1926 | facts = &ioc->facts; |
| 1927 | |
| 1928 | /* command line tunables for max sgl entries */ |
| 1929 | if (max_sgl_entries != -1) { |
| 1930 | ioc->shost->sg_tablesize = (max_sgl_entries < |
| 1931 | MPT2SAS_SG_DEPTH) ? max_sgl_entries : |
| 1932 | MPT2SAS_SG_DEPTH; |
| 1933 | } else { |
| 1934 | ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH; |
| 1935 | } |
| 1936 | |
| 1937 | /* command line tunables for max controller queue depth */ |
| 1938 | if (max_queue_depth != -1) { |
| 1939 | max_request_credit = (max_queue_depth < facts->RequestCredit) |
| 1940 | ? max_queue_depth : facts->RequestCredit; |
| 1941 | } else { |
| 1942 | max_request_credit = (facts->RequestCredit > |
| 1943 | MPT2SAS_MAX_REQUEST_QUEUE) ? MPT2SAS_MAX_REQUEST_QUEUE : |
| 1944 | facts->RequestCredit; |
| 1945 | } |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1946 | |
| 1947 | ioc->hba_queue_depth = max_request_credit; |
| 1948 | ioc->hi_priority_depth = facts->HighPriorityCredit; |
| 1949 | ioc->internal_depth = ioc->hi_priority_depth + 5; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1950 | |
| 1951 | /* request frame size */ |
| 1952 | ioc->request_sz = facts->IOCRequestFrameSize * 4; |
| 1953 | |
| 1954 | /* reply frame size */ |
| 1955 | ioc->reply_sz = facts->ReplyFrameSize * 4; |
| 1956 | |
| 1957 | retry_allocation: |
| 1958 | total_sz = 0; |
| 1959 | /* calculate number of sg elements left over in the 1st frame */ |
| 1960 | max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) - |
| 1961 | sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size); |
| 1962 | ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size; |
| 1963 | |
| 1964 | /* now do the same for a chain buffer */ |
| 1965 | max_sge_elements = ioc->request_sz - ioc->sge_size; |
| 1966 | ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size; |
| 1967 | |
| 1968 | ioc->chain_offset_value_for_main_message = |
| 1969 | ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) + |
| 1970 | (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4; |
| 1971 | |
| 1972 | /* |
| 1973 | * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE |
| 1974 | */ |
| 1975 | chains_needed_per_io = ((ioc->shost->sg_tablesize - |
| 1976 | ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message) |
| 1977 | + 1; |
| 1978 | if (chains_needed_per_io > facts->MaxChainDepth) { |
| 1979 | chains_needed_per_io = facts->MaxChainDepth; |
| 1980 | ioc->shost->sg_tablesize = min_t(u16, |
| 1981 | ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message |
| 1982 | * chains_needed_per_io), ioc->shost->sg_tablesize); |
| 1983 | } |
| 1984 | ioc->chains_needed_per_io = chains_needed_per_io; |
| 1985 | |
| 1986 | /* reply free queue sizing - taking into account for events */ |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 1987 | num_of_reply_frames = ioc->hba_queue_depth + 32; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 1988 | |
| 1989 | /* number of replies frames can't be a multiple of 16 */ |
| 1990 | /* decrease number of reply frames by 1 */ |
| 1991 | if (!(num_of_reply_frames % 16)) |
| 1992 | num_of_reply_frames--; |
| 1993 | |
| 1994 | /* calculate number of reply free queue entries |
| 1995 | * (must be multiple of 16) |
| 1996 | */ |
| 1997 | |
| 1998 | /* (we know reply_free_queue_depth is not a multiple of 16) */ |
| 1999 | queue_size = num_of_reply_frames; |
| 2000 | queue_size += 16 - (queue_size % 16); |
| 2001 | ioc->reply_free_queue_depth = queue_size; |
| 2002 | |
| 2003 | /* reply descriptor post queue sizing */ |
| 2004 | /* this size should be the number of request frames + number of reply |
| 2005 | * frames |
| 2006 | */ |
| 2007 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2008 | queue_size = ioc->hba_queue_depth + num_of_reply_frames + 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2009 | /* round up to 16 byte boundary */ |
| 2010 | if (queue_size % 16) |
| 2011 | queue_size += 16 - (queue_size % 16); |
| 2012 | |
| 2013 | /* check against IOC maximum reply post queue depth */ |
| 2014 | if (queue_size > facts->MaxReplyDescriptorPostQueueDepth) { |
| 2015 | queue_diff = queue_size - |
| 2016 | facts->MaxReplyDescriptorPostQueueDepth; |
| 2017 | |
| 2018 | /* round queue_diff up to multiple of 16 */ |
| 2019 | if (queue_diff % 16) |
| 2020 | queue_diff += 16 - (queue_diff % 16); |
| 2021 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2022 | /* adjust hba_queue_depth, reply_free_queue_depth, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2023 | * and queue_size |
| 2024 | */ |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2025 | ioc->hba_queue_depth -= queue_diff; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2026 | ioc->reply_free_queue_depth -= queue_diff; |
| 2027 | queue_size -= queue_diff; |
| 2028 | } |
| 2029 | ioc->reply_post_queue_depth = queue_size; |
| 2030 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2031 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: " |
| 2032 | "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), " |
| 2033 | "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message, |
| 2034 | ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize, |
| 2035 | ioc->chains_needed_per_io)); |
| 2036 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2037 | ioc->scsiio_depth = ioc->hba_queue_depth - |
| 2038 | ioc->hi_priority_depth - ioc->internal_depth; |
| 2039 | |
| 2040 | /* set the scsi host can_queue depth |
| 2041 | * with some internal commands that could be outstanding |
| 2042 | */ |
| 2043 | ioc->shost->can_queue = ioc->scsiio_depth - (2); |
| 2044 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: " |
| 2045 | "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue)); |
| 2046 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2047 | /* contiguous pool for request and chains, 16 byte align, one extra " |
| 2048 | * "frame for smid=0 |
| 2049 | */ |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2050 | ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth; |
| 2051 | sz = ((ioc->scsiio_depth + 1 + ioc->chain_depth) * ioc->request_sz); |
| 2052 | |
| 2053 | /* hi-priority queue */ |
| 2054 | sz += (ioc->hi_priority_depth * ioc->request_sz); |
| 2055 | |
| 2056 | /* internal queue */ |
| 2057 | sz += (ioc->internal_depth * ioc->request_sz); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2058 | |
| 2059 | ioc->request_dma_sz = sz; |
| 2060 | ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma); |
| 2061 | if (!ioc->request) { |
| 2062 | printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent " |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2063 | "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " |
| 2064 | "total(%d kB)\n", ioc->name, ioc->hba_queue_depth, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2065 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2066 | if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2067 | goto out; |
| 2068 | retry_sz += 64; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2069 | ioc->hba_queue_depth = max_request_credit - retry_sz; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2070 | goto retry_allocation; |
| 2071 | } |
| 2072 | |
| 2073 | if (retry_sz) |
| 2074 | printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent " |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2075 | "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " |
| 2076 | "total(%d kb)\n", ioc->name, ioc->hba_queue_depth, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2077 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); |
| 2078 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2079 | |
| 2080 | /* hi-priority queue */ |
| 2081 | ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2082 | ioc->request_sz); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2083 | ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) * |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2084 | ioc->request_sz); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2085 | |
| 2086 | /* internal queue */ |
| 2087 | ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth * |
| 2088 | ioc->request_sz); |
| 2089 | ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth * |
| 2090 | ioc->request_sz); |
| 2091 | |
| 2092 | ioc->chain = ioc->internal + (ioc->internal_depth * |
| 2093 | ioc->request_sz); |
| 2094 | ioc->chain_dma = ioc->internal_dma + (ioc->internal_depth * |
| 2095 | ioc->request_sz); |
| 2096 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2097 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): " |
| 2098 | "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2099 | ioc->request, ioc->hba_queue_depth, ioc->request_sz, |
| 2100 | (ioc->hba_queue_depth * ioc->request_sz)/1024)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2101 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool(0x%p): depth" |
| 2102 | "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->chain, |
| 2103 | ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth * |
| 2104 | ioc->request_sz))/1024)); |
| 2105 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n", |
| 2106 | ioc->name, (unsigned long long) ioc->request_dma)); |
| 2107 | total_sz += sz; |
| 2108 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2109 | ioc->scsi_lookup = kcalloc(ioc->scsiio_depth, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2110 | sizeof(struct request_tracker), GFP_KERNEL); |
| 2111 | if (!ioc->scsi_lookup) { |
| 2112 | printk(MPT2SAS_ERR_FMT "scsi_lookup: kcalloc failed\n", |
| 2113 | ioc->name); |
| 2114 | goto out; |
| 2115 | } |
| 2116 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2117 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): " |
| 2118 | "depth(%d)\n", ioc->name, ioc->request, |
| 2119 | ioc->scsiio_depth)); |
| 2120 | |
| 2121 | /* initialize hi-priority queue smid's */ |
| 2122 | ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth, |
| 2123 | sizeof(struct request_tracker), GFP_KERNEL); |
| 2124 | if (!ioc->hpr_lookup) { |
| 2125 | printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n", |
| 2126 | ioc->name); |
| 2127 | goto out; |
| 2128 | } |
| 2129 | ioc->hi_priority_smid = ioc->scsiio_depth + 1; |
| 2130 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): " |
| 2131 | "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority, |
| 2132 | ioc->hi_priority_depth, ioc->hi_priority_smid)); |
| 2133 | |
| 2134 | /* initialize internal queue smid's */ |
| 2135 | ioc->internal_lookup = kcalloc(ioc->internal_depth, |
| 2136 | sizeof(struct request_tracker), GFP_KERNEL); |
| 2137 | if (!ioc->internal_lookup) { |
| 2138 | printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n", |
| 2139 | ioc->name); |
| 2140 | goto out; |
| 2141 | } |
| 2142 | ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth; |
| 2143 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): " |
| 2144 | "depth(%d), start smid(%d)\n", ioc->name, ioc->internal, |
| 2145 | ioc->internal_depth, ioc->internal_smid)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2146 | |
| 2147 | /* sense buffers, 4 byte align */ |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2148 | sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2149 | ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4, |
| 2150 | 0); |
| 2151 | if (!ioc->sense_dma_pool) { |
| 2152 | printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n", |
| 2153 | ioc->name); |
| 2154 | goto out; |
| 2155 | } |
| 2156 | ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL, |
| 2157 | &ioc->sense_dma); |
| 2158 | if (!ioc->sense) { |
| 2159 | printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n", |
| 2160 | ioc->name); |
| 2161 | goto out; |
| 2162 | } |
| 2163 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT |
| 2164 | "sense pool(0x%p): depth(%d), element_size(%d), pool_size" |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 2165 | "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth, |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2166 | SCSI_SENSE_BUFFERSIZE, sz/1024)); |
| 2167 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n", |
| 2168 | ioc->name, (unsigned long long)ioc->sense_dma)); |
| 2169 | total_sz += sz; |
| 2170 | |
| 2171 | /* reply pool, 4 byte align */ |
| 2172 | sz = ioc->reply_free_queue_depth * ioc->reply_sz; |
| 2173 | ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4, |
| 2174 | 0); |
| 2175 | if (!ioc->reply_dma_pool) { |
| 2176 | printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n", |
| 2177 | ioc->name); |
| 2178 | goto out; |
| 2179 | } |
| 2180 | ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL, |
| 2181 | &ioc->reply_dma); |
| 2182 | if (!ioc->reply) { |
| 2183 | printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n", |
| 2184 | ioc->name); |
| 2185 | goto out; |
| 2186 | } |
| 2187 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth" |
| 2188 | "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply, |
| 2189 | ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024)); |
| 2190 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n", |
| 2191 | ioc->name, (unsigned long long)ioc->reply_dma)); |
| 2192 | total_sz += sz; |
| 2193 | |
| 2194 | /* reply free queue, 16 byte align */ |
| 2195 | sz = ioc->reply_free_queue_depth * 4; |
| 2196 | ioc->reply_free_dma_pool = pci_pool_create("reply_free pool", |
| 2197 | ioc->pdev, sz, 16, 0); |
| 2198 | if (!ioc->reply_free_dma_pool) { |
| 2199 | printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create " |
| 2200 | "failed\n", ioc->name); |
| 2201 | goto out; |
| 2202 | } |
| 2203 | ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL, |
| 2204 | &ioc->reply_free_dma); |
| 2205 | if (!ioc->reply_free) { |
| 2206 | printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc " |
| 2207 | "failed\n", ioc->name); |
| 2208 | goto out; |
| 2209 | } |
| 2210 | memset(ioc->reply_free, 0, sz); |
| 2211 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): " |
| 2212 | "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name, |
| 2213 | ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024)); |
| 2214 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma" |
| 2215 | "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma)); |
| 2216 | total_sz += sz; |
| 2217 | |
| 2218 | /* reply post queue, 16 byte align */ |
| 2219 | sz = ioc->reply_post_queue_depth * sizeof(Mpi2DefaultReplyDescriptor_t); |
| 2220 | ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool", |
| 2221 | ioc->pdev, sz, 16, 0); |
| 2222 | if (!ioc->reply_post_free_dma_pool) { |
| 2223 | printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create " |
| 2224 | "failed\n", ioc->name); |
| 2225 | goto out; |
| 2226 | } |
| 2227 | ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool , |
| 2228 | GFP_KERNEL, &ioc->reply_post_free_dma); |
| 2229 | if (!ioc->reply_post_free) { |
| 2230 | printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc " |
| 2231 | "failed\n", ioc->name); |
| 2232 | goto out; |
| 2233 | } |
| 2234 | memset(ioc->reply_post_free, 0, sz); |
| 2235 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool" |
| 2236 | "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n", |
| 2237 | ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8, |
| 2238 | sz/1024)); |
| 2239 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = " |
| 2240 | "(0x%llx)\n", ioc->name, (unsigned long long) |
| 2241 | ioc->reply_post_free_dma)); |
| 2242 | total_sz += sz; |
| 2243 | |
| 2244 | ioc->config_page_sz = 512; |
| 2245 | ioc->config_page = pci_alloc_consistent(ioc->pdev, |
| 2246 | ioc->config_page_sz, &ioc->config_page_dma); |
| 2247 | if (!ioc->config_page) { |
| 2248 | printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc " |
| 2249 | "failed\n", ioc->name); |
| 2250 | goto out; |
| 2251 | } |
| 2252 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size" |
| 2253 | "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz)); |
| 2254 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma" |
| 2255 | "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma)); |
| 2256 | total_sz += ioc->config_page_sz; |
| 2257 | |
| 2258 | printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n", |
| 2259 | ioc->name, total_sz/1024); |
| 2260 | printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), " |
| 2261 | "Max Controller Queue Depth(%d)\n", |
| 2262 | ioc->name, ioc->shost->can_queue, facts->RequestCredit); |
| 2263 | printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n", |
| 2264 | ioc->name, ioc->shost->sg_tablesize); |
| 2265 | return 0; |
| 2266 | |
| 2267 | out: |
| 2268 | _base_release_memory_pools(ioc); |
| 2269 | return -ENOMEM; |
| 2270 | } |
| 2271 | |
| 2272 | |
| 2273 | /** |
| 2274 | * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter. |
| 2275 | * @ioc: Pointer to MPT_ADAPTER structure |
| 2276 | * @cooked: Request raw or cooked IOC state |
| 2277 | * |
| 2278 | * Returns all IOC Doorbell register bits if cooked==0, else just the |
| 2279 | * Doorbell bits in MPI_IOC_STATE_MASK. |
| 2280 | */ |
| 2281 | u32 |
| 2282 | mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked) |
| 2283 | { |
| 2284 | u32 s, sc; |
| 2285 | |
| 2286 | s = readl(&ioc->chip->Doorbell); |
| 2287 | sc = s & MPI2_IOC_STATE_MASK; |
| 2288 | return cooked ? sc : s; |
| 2289 | } |
| 2290 | |
| 2291 | /** |
| 2292 | * _base_wait_on_iocstate - waiting on a particular ioc state |
| 2293 | * @ioc_state: controller state { READY, OPERATIONAL, or RESET } |
| 2294 | * @timeout: timeout in second |
| 2295 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2296 | * |
| 2297 | * Returns 0 for success, non-zero for failure. |
| 2298 | */ |
| 2299 | static int |
| 2300 | _base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout, |
| 2301 | int sleep_flag) |
| 2302 | { |
| 2303 | u32 count, cntdn; |
| 2304 | u32 current_state; |
| 2305 | |
| 2306 | count = 0; |
| 2307 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 2308 | do { |
| 2309 | current_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 2310 | if (current_state == ioc_state) |
| 2311 | return 0; |
| 2312 | if (count && current_state == MPI2_IOC_STATE_FAULT) |
| 2313 | break; |
| 2314 | if (sleep_flag == CAN_SLEEP) |
| 2315 | msleep(1); |
| 2316 | else |
| 2317 | udelay(500); |
| 2318 | count++; |
| 2319 | } while (--cntdn); |
| 2320 | |
| 2321 | return current_state; |
| 2322 | } |
| 2323 | |
| 2324 | /** |
| 2325 | * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by |
| 2326 | * a write to the doorbell) |
| 2327 | * @ioc: per adapter object |
| 2328 | * @timeout: timeout in second |
| 2329 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2330 | * |
| 2331 | * Returns 0 for success, non-zero for failure. |
| 2332 | * |
| 2333 | * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell. |
| 2334 | */ |
| 2335 | static int |
| 2336 | _base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout, |
| 2337 | int sleep_flag) |
| 2338 | { |
| 2339 | u32 cntdn, count; |
| 2340 | u32 int_status; |
| 2341 | |
| 2342 | count = 0; |
| 2343 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 2344 | do { |
| 2345 | int_status = readl(&ioc->chip->HostInterruptStatus); |
| 2346 | if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { |
| 2347 | dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 2348 | "successfull count(%d), timeout(%d)\n", ioc->name, |
| 2349 | __func__, count, timeout)); |
| 2350 | return 0; |
| 2351 | } |
| 2352 | if (sleep_flag == CAN_SLEEP) |
| 2353 | msleep(1); |
| 2354 | else |
| 2355 | udelay(500); |
| 2356 | count++; |
| 2357 | } while (--cntdn); |
| 2358 | |
| 2359 | printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), " |
| 2360 | "int_status(%x)!\n", ioc->name, __func__, count, int_status); |
| 2361 | return -EFAULT; |
| 2362 | } |
| 2363 | |
| 2364 | /** |
| 2365 | * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell. |
| 2366 | * @ioc: per adapter object |
| 2367 | * @timeout: timeout in second |
| 2368 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2369 | * |
| 2370 | * Returns 0 for success, non-zero for failure. |
| 2371 | * |
| 2372 | * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to |
| 2373 | * doorbell. |
| 2374 | */ |
| 2375 | static int |
| 2376 | _base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout, |
| 2377 | int sleep_flag) |
| 2378 | { |
| 2379 | u32 cntdn, count; |
| 2380 | u32 int_status; |
| 2381 | u32 doorbell; |
| 2382 | |
| 2383 | count = 0; |
| 2384 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 2385 | do { |
| 2386 | int_status = readl(&ioc->chip->HostInterruptStatus); |
| 2387 | if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) { |
| 2388 | dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 2389 | "successfull count(%d), timeout(%d)\n", ioc->name, |
| 2390 | __func__, count, timeout)); |
| 2391 | return 0; |
| 2392 | } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { |
| 2393 | doorbell = readl(&ioc->chip->Doorbell); |
| 2394 | if ((doorbell & MPI2_IOC_STATE_MASK) == |
| 2395 | MPI2_IOC_STATE_FAULT) { |
| 2396 | mpt2sas_base_fault_info(ioc , doorbell); |
| 2397 | return -EFAULT; |
| 2398 | } |
| 2399 | } else if (int_status == 0xFFFFFFFF) |
| 2400 | goto out; |
| 2401 | |
| 2402 | if (sleep_flag == CAN_SLEEP) |
| 2403 | msleep(1); |
| 2404 | else |
| 2405 | udelay(500); |
| 2406 | count++; |
| 2407 | } while (--cntdn); |
| 2408 | |
| 2409 | out: |
| 2410 | printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), " |
| 2411 | "int_status(%x)!\n", ioc->name, __func__, count, int_status); |
| 2412 | return -EFAULT; |
| 2413 | } |
| 2414 | |
| 2415 | /** |
| 2416 | * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use |
| 2417 | * @ioc: per adapter object |
| 2418 | * @timeout: timeout in second |
| 2419 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2420 | * |
| 2421 | * Returns 0 for success, non-zero for failure. |
| 2422 | * |
| 2423 | */ |
| 2424 | static int |
| 2425 | _base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout, |
| 2426 | int sleep_flag) |
| 2427 | { |
| 2428 | u32 cntdn, count; |
| 2429 | u32 doorbell_reg; |
| 2430 | |
| 2431 | count = 0; |
| 2432 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 2433 | do { |
| 2434 | doorbell_reg = readl(&ioc->chip->Doorbell); |
| 2435 | if (!(doorbell_reg & MPI2_DOORBELL_USED)) { |
| 2436 | dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 2437 | "successfull count(%d), timeout(%d)\n", ioc->name, |
| 2438 | __func__, count, timeout)); |
| 2439 | return 0; |
| 2440 | } |
| 2441 | if (sleep_flag == CAN_SLEEP) |
| 2442 | msleep(1); |
| 2443 | else |
| 2444 | udelay(500); |
| 2445 | count++; |
| 2446 | } while (--cntdn); |
| 2447 | |
| 2448 | printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), " |
| 2449 | "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg); |
| 2450 | return -EFAULT; |
| 2451 | } |
| 2452 | |
| 2453 | /** |
| 2454 | * _base_send_ioc_reset - send doorbell reset |
| 2455 | * @ioc: per adapter object |
| 2456 | * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET |
| 2457 | * @timeout: timeout in second |
| 2458 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2459 | * |
| 2460 | * Returns 0 for success, non-zero for failure. |
| 2461 | */ |
| 2462 | static int |
| 2463 | _base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout, |
| 2464 | int sleep_flag) |
| 2465 | { |
| 2466 | u32 ioc_state; |
| 2467 | int r = 0; |
| 2468 | |
| 2469 | if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) { |
| 2470 | printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n", |
| 2471 | ioc->name, __func__); |
| 2472 | return -EFAULT; |
| 2473 | } |
| 2474 | |
| 2475 | if (!(ioc->facts.IOCCapabilities & |
| 2476 | MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY)) |
| 2477 | return -EFAULT; |
| 2478 | |
| 2479 | printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name); |
| 2480 | |
| 2481 | writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT, |
| 2482 | &ioc->chip->Doorbell); |
| 2483 | if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) { |
| 2484 | r = -EFAULT; |
| 2485 | goto out; |
| 2486 | } |
| 2487 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, |
| 2488 | timeout, sleep_flag); |
| 2489 | if (ioc_state) { |
| 2490 | printk(MPT2SAS_ERR_FMT "%s: failed going to ready state " |
| 2491 | " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state); |
| 2492 | r = -EFAULT; |
| 2493 | goto out; |
| 2494 | } |
| 2495 | out: |
| 2496 | printk(MPT2SAS_INFO_FMT "message unit reset: %s\n", |
| 2497 | ioc->name, ((r == 0) ? "SUCCESS" : "FAILED")); |
| 2498 | return r; |
| 2499 | } |
| 2500 | |
| 2501 | /** |
| 2502 | * _base_handshake_req_reply_wait - send request thru doorbell interface |
| 2503 | * @ioc: per adapter object |
| 2504 | * @request_bytes: request length |
| 2505 | * @request: pointer having request payload |
| 2506 | * @reply_bytes: reply length |
| 2507 | * @reply: pointer to reply payload |
| 2508 | * @timeout: timeout in second |
| 2509 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2510 | * |
| 2511 | * Returns 0 for success, non-zero for failure. |
| 2512 | */ |
| 2513 | static int |
| 2514 | _base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes, |
| 2515 | u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag) |
| 2516 | { |
| 2517 | MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply; |
| 2518 | int i; |
| 2519 | u8 failed; |
| 2520 | u16 dummy; |
| 2521 | u32 *mfp; |
| 2522 | |
| 2523 | /* make sure doorbell is not in use */ |
| 2524 | if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) { |
| 2525 | printk(MPT2SAS_ERR_FMT "doorbell is in use " |
| 2526 | " (line=%d)\n", ioc->name, __LINE__); |
| 2527 | return -EFAULT; |
| 2528 | } |
| 2529 | |
| 2530 | /* clear pending doorbell interrupts from previous state changes */ |
| 2531 | if (readl(&ioc->chip->HostInterruptStatus) & |
| 2532 | MPI2_HIS_IOC2SYS_DB_STATUS) |
| 2533 | writel(0, &ioc->chip->HostInterruptStatus); |
| 2534 | |
| 2535 | /* send message to ioc */ |
| 2536 | writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) | |
| 2537 | ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)), |
| 2538 | &ioc->chip->Doorbell); |
| 2539 | |
Kashyap, Desai | 29786e1 | 2009-09-14 11:06:21 +0530 | [diff] [blame] | 2540 | if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2541 | printk(MPT2SAS_ERR_FMT "doorbell handshake " |
| 2542 | "int failed (line=%d)\n", ioc->name, __LINE__); |
| 2543 | return -EFAULT; |
| 2544 | } |
| 2545 | writel(0, &ioc->chip->HostInterruptStatus); |
| 2546 | |
| 2547 | if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) { |
| 2548 | printk(MPT2SAS_ERR_FMT "doorbell handshake " |
| 2549 | "ack failed (line=%d)\n", ioc->name, __LINE__); |
| 2550 | return -EFAULT; |
| 2551 | } |
| 2552 | |
| 2553 | /* send message 32-bits at a time */ |
| 2554 | for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) { |
| 2555 | writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell); |
| 2556 | if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) |
| 2557 | failed = 1; |
| 2558 | } |
| 2559 | |
| 2560 | if (failed) { |
| 2561 | printk(MPT2SAS_ERR_FMT "doorbell handshake " |
| 2562 | "sending request failed (line=%d)\n", ioc->name, __LINE__); |
| 2563 | return -EFAULT; |
| 2564 | } |
| 2565 | |
| 2566 | /* now wait for the reply */ |
| 2567 | if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) { |
| 2568 | printk(MPT2SAS_ERR_FMT "doorbell handshake " |
| 2569 | "int failed (line=%d)\n", ioc->name, __LINE__); |
| 2570 | return -EFAULT; |
| 2571 | } |
| 2572 | |
| 2573 | /* read the first two 16-bits, it gives the total length of the reply */ |
| 2574 | reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell) |
| 2575 | & MPI2_DOORBELL_DATA_MASK); |
| 2576 | writel(0, &ioc->chip->HostInterruptStatus); |
| 2577 | if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) { |
| 2578 | printk(MPT2SAS_ERR_FMT "doorbell handshake " |
| 2579 | "int failed (line=%d)\n", ioc->name, __LINE__); |
| 2580 | return -EFAULT; |
| 2581 | } |
| 2582 | reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell) |
| 2583 | & MPI2_DOORBELL_DATA_MASK); |
| 2584 | writel(0, &ioc->chip->HostInterruptStatus); |
| 2585 | |
| 2586 | for (i = 2; i < default_reply->MsgLength * 2; i++) { |
| 2587 | if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) { |
| 2588 | printk(MPT2SAS_ERR_FMT "doorbell " |
| 2589 | "handshake int failed (line=%d)\n", ioc->name, |
| 2590 | __LINE__); |
| 2591 | return -EFAULT; |
| 2592 | } |
| 2593 | if (i >= reply_bytes/2) /* overflow case */ |
| 2594 | dummy = readl(&ioc->chip->Doorbell); |
| 2595 | else |
| 2596 | reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell) |
| 2597 | & MPI2_DOORBELL_DATA_MASK); |
| 2598 | writel(0, &ioc->chip->HostInterruptStatus); |
| 2599 | } |
| 2600 | |
| 2601 | _base_wait_for_doorbell_int(ioc, 5, sleep_flag); |
| 2602 | if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) { |
| 2603 | dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use " |
| 2604 | " (line=%d)\n", ioc->name, __LINE__)); |
| 2605 | } |
| 2606 | writel(0, &ioc->chip->HostInterruptStatus); |
| 2607 | |
| 2608 | if (ioc->logging_level & MPT_DEBUG_INIT) { |
| 2609 | mfp = (u32 *)reply; |
| 2610 | printk(KERN_DEBUG "\toffset:data\n"); |
| 2611 | for (i = 0; i < reply_bytes/4; i++) |
| 2612 | printk(KERN_DEBUG "\t[0x%02x]:%08x\n", i*4, |
| 2613 | le32_to_cpu(mfp[i])); |
| 2614 | } |
| 2615 | return 0; |
| 2616 | } |
| 2617 | |
| 2618 | /** |
| 2619 | * mpt2sas_base_sas_iounit_control - send sas iounit control to FW |
| 2620 | * @ioc: per adapter object |
| 2621 | * @mpi_reply: the reply payload from FW |
| 2622 | * @mpi_request: the request payload sent to FW |
| 2623 | * |
| 2624 | * The SAS IO Unit Control Request message allows the host to perform low-level |
| 2625 | * operations, such as resets on the PHYs of the IO Unit, also allows the host |
| 2626 | * to obtain the IOC assigned device handles for a device if it has other |
| 2627 | * identifying information about the device, in addition allows the host to |
| 2628 | * remove IOC resources associated with the device. |
| 2629 | * |
| 2630 | * Returns 0 for success, non-zero for failure. |
| 2631 | */ |
| 2632 | int |
| 2633 | mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc, |
| 2634 | Mpi2SasIoUnitControlReply_t *mpi_reply, |
| 2635 | Mpi2SasIoUnitControlRequest_t *mpi_request) |
| 2636 | { |
| 2637 | u16 smid; |
| 2638 | u32 ioc_state; |
| 2639 | unsigned long timeleft; |
| 2640 | u8 issue_reset; |
| 2641 | int rc; |
| 2642 | void *request; |
| 2643 | u16 wait_state_count; |
| 2644 | |
| 2645 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 2646 | __func__)); |
| 2647 | |
| 2648 | mutex_lock(&ioc->base_cmds.mutex); |
| 2649 | |
| 2650 | if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) { |
| 2651 | printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n", |
| 2652 | ioc->name, __func__); |
| 2653 | rc = -EAGAIN; |
| 2654 | goto out; |
| 2655 | } |
| 2656 | |
| 2657 | wait_state_count = 0; |
| 2658 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 2659 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 2660 | if (wait_state_count++ == 10) { |
| 2661 | printk(MPT2SAS_ERR_FMT |
| 2662 | "%s: failed due to ioc not operational\n", |
| 2663 | ioc->name, __func__); |
| 2664 | rc = -EFAULT; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | ssleep(1); |
| 2668 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 2669 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 2670 | "operational state(count=%d)\n", ioc->name, |
| 2671 | __func__, wait_state_count); |
| 2672 | } |
| 2673 | |
| 2674 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 2675 | if (!smid) { |
| 2676 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2677 | ioc->name, __func__); |
| 2678 | rc = -EAGAIN; |
| 2679 | goto out; |
| 2680 | } |
| 2681 | |
| 2682 | rc = 0; |
| 2683 | ioc->base_cmds.status = MPT2_CMD_PENDING; |
| 2684 | request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2685 | ioc->base_cmds.smid = smid; |
| 2686 | memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 2687 | if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || |
| 2688 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) |
| 2689 | ioc->ioc_link_reset_in_progress = 1; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2690 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 2691 | init_completion(&ioc->base_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2692 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, |
| 2693 | msecs_to_jiffies(10000)); |
| 2694 | if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || |
| 2695 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) && |
| 2696 | ioc->ioc_link_reset_in_progress) |
| 2697 | ioc->ioc_link_reset_in_progress = 0; |
| 2698 | if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2699 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2700 | ioc->name, __func__); |
| 2701 | _debug_dump_mf(mpi_request, |
| 2702 | sizeof(Mpi2SasIoUnitControlRequest_t)/4); |
| 2703 | if (!(ioc->base_cmds.status & MPT2_CMD_RESET)) |
| 2704 | issue_reset = 1; |
| 2705 | goto issue_host_reset; |
| 2706 | } |
| 2707 | if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID) |
| 2708 | memcpy(mpi_reply, ioc->base_cmds.reply, |
| 2709 | sizeof(Mpi2SasIoUnitControlReply_t)); |
| 2710 | else |
| 2711 | memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t)); |
| 2712 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 2713 | goto out; |
| 2714 | |
| 2715 | issue_host_reset: |
| 2716 | if (issue_reset) |
| 2717 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2718 | FORCE_BIG_HAMMER); |
| 2719 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 2720 | rc = -EFAULT; |
| 2721 | out: |
| 2722 | mutex_unlock(&ioc->base_cmds.mutex); |
| 2723 | return rc; |
| 2724 | } |
| 2725 | |
| 2726 | |
| 2727 | /** |
| 2728 | * mpt2sas_base_scsi_enclosure_processor - sending request to sep device |
| 2729 | * @ioc: per adapter object |
| 2730 | * @mpi_reply: the reply payload from FW |
| 2731 | * @mpi_request: the request payload sent to FW |
| 2732 | * |
| 2733 | * The SCSI Enclosure Processor request message causes the IOC to |
| 2734 | * communicate with SES devices to control LED status signals. |
| 2735 | * |
| 2736 | * Returns 0 for success, non-zero for failure. |
| 2737 | */ |
| 2738 | int |
| 2739 | mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc, |
| 2740 | Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request) |
| 2741 | { |
| 2742 | u16 smid; |
| 2743 | u32 ioc_state; |
| 2744 | unsigned long timeleft; |
| 2745 | u8 issue_reset; |
| 2746 | int rc; |
| 2747 | void *request; |
| 2748 | u16 wait_state_count; |
| 2749 | |
| 2750 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 2751 | __func__)); |
| 2752 | |
| 2753 | mutex_lock(&ioc->base_cmds.mutex); |
| 2754 | |
| 2755 | if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) { |
| 2756 | printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n", |
| 2757 | ioc->name, __func__); |
| 2758 | rc = -EAGAIN; |
| 2759 | goto out; |
| 2760 | } |
| 2761 | |
| 2762 | wait_state_count = 0; |
| 2763 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 2764 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 2765 | if (wait_state_count++ == 10) { |
| 2766 | printk(MPT2SAS_ERR_FMT |
| 2767 | "%s: failed due to ioc not operational\n", |
| 2768 | ioc->name, __func__); |
| 2769 | rc = -EFAULT; |
| 2770 | goto out; |
| 2771 | } |
| 2772 | ssleep(1); |
| 2773 | ioc_state = mpt2sas_base_get_iocstate(ioc, 1); |
| 2774 | printk(MPT2SAS_INFO_FMT "%s: waiting for " |
| 2775 | "operational state(count=%d)\n", ioc->name, |
| 2776 | __func__, wait_state_count); |
| 2777 | } |
| 2778 | |
| 2779 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 2780 | if (!smid) { |
| 2781 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 2782 | ioc->name, __func__); |
| 2783 | rc = -EAGAIN; |
| 2784 | goto out; |
| 2785 | } |
| 2786 | |
| 2787 | rc = 0; |
| 2788 | ioc->base_cmds.status = MPT2_CMD_PENDING; |
| 2789 | request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 2790 | ioc->base_cmds.smid = smid; |
| 2791 | memcpy(request, mpi_request, sizeof(Mpi2SepReply_t)); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2792 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 2793 | init_completion(&ioc->base_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2794 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, |
| 2795 | msecs_to_jiffies(10000)); |
| 2796 | if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { |
| 2797 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 2798 | ioc->name, __func__); |
| 2799 | _debug_dump_mf(mpi_request, |
| 2800 | sizeof(Mpi2SepRequest_t)/4); |
| 2801 | if (!(ioc->base_cmds.status & MPT2_CMD_RESET)) |
| 2802 | issue_reset = 1; |
| 2803 | goto issue_host_reset; |
| 2804 | } |
| 2805 | if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID) |
| 2806 | memcpy(mpi_reply, ioc->base_cmds.reply, |
| 2807 | sizeof(Mpi2SepReply_t)); |
| 2808 | else |
| 2809 | memset(mpi_reply, 0, sizeof(Mpi2SepReply_t)); |
| 2810 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 2811 | goto out; |
| 2812 | |
| 2813 | issue_host_reset: |
| 2814 | if (issue_reset) |
| 2815 | mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 2816 | FORCE_BIG_HAMMER); |
| 2817 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 2818 | rc = -EFAULT; |
| 2819 | out: |
| 2820 | mutex_unlock(&ioc->base_cmds.mutex); |
| 2821 | return rc; |
| 2822 | } |
| 2823 | |
| 2824 | /** |
| 2825 | * _base_get_port_facts - obtain port facts reply and save in ioc |
| 2826 | * @ioc: per adapter object |
| 2827 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2828 | * |
| 2829 | * Returns 0 for success, non-zero for failure. |
| 2830 | */ |
| 2831 | static int |
| 2832 | _base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag) |
| 2833 | { |
| 2834 | Mpi2PortFactsRequest_t mpi_request; |
| 2835 | Mpi2PortFactsReply_t mpi_reply, *pfacts; |
| 2836 | int mpi_reply_sz, mpi_request_sz, r; |
| 2837 | |
| 2838 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 2839 | __func__)); |
| 2840 | |
| 2841 | mpi_reply_sz = sizeof(Mpi2PortFactsReply_t); |
| 2842 | mpi_request_sz = sizeof(Mpi2PortFactsRequest_t); |
| 2843 | memset(&mpi_request, 0, mpi_request_sz); |
| 2844 | mpi_request.Function = MPI2_FUNCTION_PORT_FACTS; |
| 2845 | mpi_request.PortNumber = port; |
| 2846 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, |
| 2847 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP); |
| 2848 | |
| 2849 | if (r != 0) { |
| 2850 | printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n", |
| 2851 | ioc->name, __func__, r); |
| 2852 | return r; |
| 2853 | } |
| 2854 | |
| 2855 | pfacts = &ioc->pfacts[port]; |
| 2856 | memset(pfacts, 0, sizeof(Mpi2PortFactsReply_t)); |
| 2857 | pfacts->PortNumber = mpi_reply.PortNumber; |
| 2858 | pfacts->VP_ID = mpi_reply.VP_ID; |
| 2859 | pfacts->VF_ID = mpi_reply.VF_ID; |
| 2860 | pfacts->MaxPostedCmdBuffers = |
| 2861 | le16_to_cpu(mpi_reply.MaxPostedCmdBuffers); |
| 2862 | |
| 2863 | return 0; |
| 2864 | } |
| 2865 | |
| 2866 | /** |
| 2867 | * _base_get_ioc_facts - obtain ioc facts reply and save in ioc |
| 2868 | * @ioc: per adapter object |
| 2869 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2870 | * |
| 2871 | * Returns 0 for success, non-zero for failure. |
| 2872 | */ |
| 2873 | static int |
| 2874 | _base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
| 2875 | { |
| 2876 | Mpi2IOCFactsRequest_t mpi_request; |
| 2877 | Mpi2IOCFactsReply_t mpi_reply, *facts; |
| 2878 | int mpi_reply_sz, mpi_request_sz, r; |
| 2879 | |
| 2880 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 2881 | __func__)); |
| 2882 | |
| 2883 | mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t); |
| 2884 | mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t); |
| 2885 | memset(&mpi_request, 0, mpi_request_sz); |
| 2886 | mpi_request.Function = MPI2_FUNCTION_IOC_FACTS; |
| 2887 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, |
| 2888 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP); |
| 2889 | |
| 2890 | if (r != 0) { |
| 2891 | printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n", |
| 2892 | ioc->name, __func__, r); |
| 2893 | return r; |
| 2894 | } |
| 2895 | |
| 2896 | facts = &ioc->facts; |
| 2897 | memset(facts, 0, sizeof(Mpi2IOCFactsReply_t)); |
| 2898 | facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion); |
| 2899 | facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion); |
| 2900 | facts->VP_ID = mpi_reply.VP_ID; |
| 2901 | facts->VF_ID = mpi_reply.VF_ID; |
| 2902 | facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions); |
| 2903 | facts->MaxChainDepth = mpi_reply.MaxChainDepth; |
| 2904 | facts->WhoInit = mpi_reply.WhoInit; |
| 2905 | facts->NumberOfPorts = mpi_reply.NumberOfPorts; |
| 2906 | facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit); |
| 2907 | facts->MaxReplyDescriptorPostQueueDepth = |
| 2908 | le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth); |
| 2909 | facts->ProductID = le16_to_cpu(mpi_reply.ProductID); |
| 2910 | facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities); |
| 2911 | if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID)) |
| 2912 | ioc->ir_firmware = 1; |
| 2913 | facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word); |
| 2914 | facts->IOCRequestFrameSize = |
| 2915 | le16_to_cpu(mpi_reply.IOCRequestFrameSize); |
| 2916 | facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators); |
| 2917 | facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets); |
| 2918 | ioc->shost->max_id = -1; |
| 2919 | facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders); |
| 2920 | facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures); |
| 2921 | facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags); |
| 2922 | facts->HighPriorityCredit = |
| 2923 | le16_to_cpu(mpi_reply.HighPriorityCredit); |
| 2924 | facts->ReplyFrameSize = mpi_reply.ReplyFrameSize; |
| 2925 | facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle); |
| 2926 | |
| 2927 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), " |
| 2928 | "max chains per io(%d)\n", ioc->name, facts->RequestCredit, |
| 2929 | facts->MaxChainDepth)); |
| 2930 | dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), " |
| 2931 | "reply frame size(%d)\n", ioc->name, |
| 2932 | facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4)); |
| 2933 | return 0; |
| 2934 | } |
| 2935 | |
| 2936 | /** |
| 2937 | * _base_send_ioc_init - send ioc_init to firmware |
| 2938 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2939 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 2940 | * |
| 2941 | * Returns 0 for success, non-zero for failure. |
| 2942 | */ |
| 2943 | static int |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2944 | _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2945 | { |
| 2946 | Mpi2IOCInitRequest_t mpi_request; |
| 2947 | Mpi2IOCInitReply_t mpi_reply; |
| 2948 | int r; |
| 2949 | |
| 2950 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 2951 | __func__)); |
| 2952 | |
| 2953 | memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t)); |
| 2954 | mpi_request.Function = MPI2_FUNCTION_IOC_INIT; |
| 2955 | mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 2956 | mpi_request.VF_ID = 0; /* TODO */ |
| 2957 | mpi_request.VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 2958 | mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION); |
| 2959 | mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); |
| 2960 | |
| 2961 | /* In MPI Revision I (0xA), the SystemReplyFrameSize(offset 0x18) was |
| 2962 | * removed and made reserved. For those with older firmware will need |
| 2963 | * this fix. It was decided that the Reply and Request frame sizes are |
| 2964 | * the same. |
| 2965 | */ |
| 2966 | if ((ioc->facts.HeaderVersion >> 8) < 0xA) { |
| 2967 | mpi_request.Reserved7 = cpu_to_le16(ioc->reply_sz); |
| 2968 | /* mpi_request.SystemReplyFrameSize = |
| 2969 | * cpu_to_le16(ioc->reply_sz); |
| 2970 | */ |
| 2971 | } |
| 2972 | |
| 2973 | mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4); |
| 2974 | mpi_request.ReplyDescriptorPostQueueDepth = |
| 2975 | cpu_to_le16(ioc->reply_post_queue_depth); |
| 2976 | mpi_request.ReplyFreeQueueDepth = |
| 2977 | cpu_to_le16(ioc->reply_free_queue_depth); |
| 2978 | |
| 2979 | #if BITS_PER_LONG > 32 |
| 2980 | mpi_request.SenseBufferAddressHigh = |
| 2981 | cpu_to_le32(ioc->sense_dma >> 32); |
| 2982 | mpi_request.SystemReplyAddressHigh = |
| 2983 | cpu_to_le32(ioc->reply_dma >> 32); |
| 2984 | mpi_request.SystemRequestFrameBaseAddress = |
| 2985 | cpu_to_le64(ioc->request_dma); |
| 2986 | mpi_request.ReplyFreeQueueAddress = |
| 2987 | cpu_to_le64(ioc->reply_free_dma); |
| 2988 | mpi_request.ReplyDescriptorPostQueueAddress = |
| 2989 | cpu_to_le64(ioc->reply_post_free_dma); |
| 2990 | #else |
| 2991 | mpi_request.SystemRequestFrameBaseAddress = |
| 2992 | cpu_to_le32(ioc->request_dma); |
| 2993 | mpi_request.ReplyFreeQueueAddress = |
| 2994 | cpu_to_le32(ioc->reply_free_dma); |
| 2995 | mpi_request.ReplyDescriptorPostQueueAddress = |
| 2996 | cpu_to_le32(ioc->reply_post_free_dma); |
| 2997 | #endif |
| 2998 | |
| 2999 | if (ioc->logging_level & MPT_DEBUG_INIT) { |
| 3000 | u32 *mfp; |
| 3001 | int i; |
| 3002 | |
| 3003 | mfp = (u32 *)&mpi_request; |
| 3004 | printk(KERN_DEBUG "\toffset:data\n"); |
| 3005 | for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++) |
| 3006 | printk(KERN_DEBUG "\t[0x%02x]:%08x\n", i*4, |
| 3007 | le32_to_cpu(mfp[i])); |
| 3008 | } |
| 3009 | |
| 3010 | r = _base_handshake_req_reply_wait(ioc, |
| 3011 | sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request, |
| 3012 | sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10, |
| 3013 | sleep_flag); |
| 3014 | |
| 3015 | if (r != 0) { |
| 3016 | printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n", |
| 3017 | ioc->name, __func__, r); |
| 3018 | return r; |
| 3019 | } |
| 3020 | |
| 3021 | if (mpi_reply.IOCStatus != MPI2_IOCSTATUS_SUCCESS || |
| 3022 | mpi_reply.IOCLogInfo) { |
| 3023 | printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__); |
| 3024 | r = -EIO; |
| 3025 | } |
| 3026 | |
| 3027 | return 0; |
| 3028 | } |
| 3029 | |
| 3030 | /** |
| 3031 | * _base_send_port_enable - send port_enable(discovery stuff) to firmware |
| 3032 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3033 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3034 | * |
| 3035 | * Returns 0 for success, non-zero for failure. |
| 3036 | */ |
| 3037 | static int |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3038 | _base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3039 | { |
| 3040 | Mpi2PortEnableRequest_t *mpi_request; |
| 3041 | u32 ioc_state; |
| 3042 | unsigned long timeleft; |
| 3043 | int r = 0; |
| 3044 | u16 smid; |
| 3045 | |
| 3046 | printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name); |
| 3047 | |
| 3048 | if (ioc->base_cmds.status & MPT2_CMD_PENDING) { |
| 3049 | printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n", |
| 3050 | ioc->name, __func__); |
| 3051 | return -EAGAIN; |
| 3052 | } |
| 3053 | |
| 3054 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 3055 | if (!smid) { |
| 3056 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3057 | ioc->name, __func__); |
| 3058 | return -EAGAIN; |
| 3059 | } |
| 3060 | |
| 3061 | ioc->base_cmds.status = MPT2_CMD_PENDING; |
| 3062 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3063 | ioc->base_cmds.smid = smid; |
| 3064 | memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); |
| 3065 | mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3066 | mpi_request->VF_ID = 0; /* TODO */ |
| 3067 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3068 | |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3069 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 3070 | init_completion(&ioc->base_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3071 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, |
| 3072 | 300*HZ); |
| 3073 | if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { |
| 3074 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 3075 | ioc->name, __func__); |
| 3076 | _debug_dump_mf(mpi_request, |
| 3077 | sizeof(Mpi2PortEnableRequest_t)/4); |
| 3078 | if (ioc->base_cmds.status & MPT2_CMD_RESET) |
| 3079 | r = -EFAULT; |
| 3080 | else |
| 3081 | r = -ETIME; |
| 3082 | goto out; |
| 3083 | } else |
| 3084 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: complete\n", |
| 3085 | ioc->name, __func__)); |
| 3086 | |
| 3087 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_OPERATIONAL, |
| 3088 | 60, sleep_flag); |
| 3089 | if (ioc_state) { |
| 3090 | printk(MPT2SAS_ERR_FMT "%s: failed going to operational state " |
| 3091 | " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state); |
| 3092 | r = -EFAULT; |
| 3093 | } |
| 3094 | out: |
| 3095 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 3096 | printk(MPT2SAS_INFO_FMT "port enable: %s\n", |
| 3097 | ioc->name, ((r == 0) ? "SUCCESS" : "FAILED")); |
| 3098 | return r; |
| 3099 | } |
| 3100 | |
| 3101 | /** |
| 3102 | * _base_unmask_events - turn on notification for this event |
| 3103 | * @ioc: per adapter object |
| 3104 | * @event: firmware event |
| 3105 | * |
| 3106 | * The mask is stored in ioc->event_masks. |
| 3107 | */ |
| 3108 | static void |
| 3109 | _base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event) |
| 3110 | { |
| 3111 | u32 desired_event; |
| 3112 | |
| 3113 | if (event >= 128) |
| 3114 | return; |
| 3115 | |
| 3116 | desired_event = (1 << (event % 32)); |
| 3117 | |
| 3118 | if (event < 32) |
| 3119 | ioc->event_masks[0] &= ~desired_event; |
| 3120 | else if (event < 64) |
| 3121 | ioc->event_masks[1] &= ~desired_event; |
| 3122 | else if (event < 96) |
| 3123 | ioc->event_masks[2] &= ~desired_event; |
| 3124 | else if (event < 128) |
| 3125 | ioc->event_masks[3] &= ~desired_event; |
| 3126 | } |
| 3127 | |
| 3128 | /** |
| 3129 | * _base_event_notification - send event notification |
| 3130 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3131 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3132 | * |
| 3133 | * Returns 0 for success, non-zero for failure. |
| 3134 | */ |
| 3135 | static int |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3136 | _base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3137 | { |
| 3138 | Mpi2EventNotificationRequest_t *mpi_request; |
| 3139 | unsigned long timeleft; |
| 3140 | u16 smid; |
| 3141 | int r = 0; |
| 3142 | int i; |
| 3143 | |
| 3144 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 3145 | __func__)); |
| 3146 | |
| 3147 | if (ioc->base_cmds.status & MPT2_CMD_PENDING) { |
| 3148 | printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n", |
| 3149 | ioc->name, __func__); |
| 3150 | return -EAGAIN; |
| 3151 | } |
| 3152 | |
| 3153 | smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 3154 | if (!smid) { |
| 3155 | printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", |
| 3156 | ioc->name, __func__); |
| 3157 | return -EAGAIN; |
| 3158 | } |
| 3159 | ioc->base_cmds.status = MPT2_CMD_PENDING; |
| 3160 | mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); |
| 3161 | ioc->base_cmds.smid = smid; |
| 3162 | memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t)); |
| 3163 | mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3164 | mpi_request->VF_ID = 0; /* TODO */ |
| 3165 | mpi_request->VP_ID = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3166 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) |
| 3167 | mpi_request->EventMasks[i] = |
| 3168 | le32_to_cpu(ioc->event_masks[i]); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3169 | mpt2sas_base_put_smid_default(ioc, smid); |
Kashyap, Desai | bcfb6e6 | 2009-09-14 11:05:24 +0530 | [diff] [blame] | 3170 | init_completion(&ioc->base_cmds.done); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3171 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ); |
| 3172 | if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { |
| 3173 | printk(MPT2SAS_ERR_FMT "%s: timeout\n", |
| 3174 | ioc->name, __func__); |
| 3175 | _debug_dump_mf(mpi_request, |
| 3176 | sizeof(Mpi2EventNotificationRequest_t)/4); |
| 3177 | if (ioc->base_cmds.status & MPT2_CMD_RESET) |
| 3178 | r = -EFAULT; |
| 3179 | else |
| 3180 | r = -ETIME; |
| 3181 | } else |
| 3182 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: complete\n", |
| 3183 | ioc->name, __func__)); |
| 3184 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 3185 | return r; |
| 3186 | } |
| 3187 | |
| 3188 | /** |
| 3189 | * mpt2sas_base_validate_event_type - validating event types |
| 3190 | * @ioc: per adapter object |
| 3191 | * @event: firmware event |
| 3192 | * |
| 3193 | * This will turn on firmware event notification when application |
| 3194 | * ask for that event. We don't mask events that are already enabled. |
| 3195 | */ |
| 3196 | void |
| 3197 | mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type) |
| 3198 | { |
| 3199 | int i, j; |
| 3200 | u32 event_mask, desired_event; |
| 3201 | u8 send_update_to_fw; |
| 3202 | |
| 3203 | for (i = 0, send_update_to_fw = 0; i < |
| 3204 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) { |
| 3205 | event_mask = ~event_type[i]; |
| 3206 | desired_event = 1; |
| 3207 | for (j = 0; j < 32; j++) { |
| 3208 | if (!(event_mask & desired_event) && |
| 3209 | (ioc->event_masks[i] & desired_event)) { |
| 3210 | ioc->event_masks[i] &= ~desired_event; |
| 3211 | send_update_to_fw = 1; |
| 3212 | } |
| 3213 | desired_event = (desired_event << 1); |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | if (!send_update_to_fw) |
| 3218 | return; |
| 3219 | |
| 3220 | mutex_lock(&ioc->base_cmds.mutex); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3221 | _base_event_notification(ioc, CAN_SLEEP); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3222 | mutex_unlock(&ioc->base_cmds.mutex); |
| 3223 | } |
| 3224 | |
| 3225 | /** |
| 3226 | * _base_diag_reset - the "big hammer" start of day reset |
| 3227 | * @ioc: per adapter object |
| 3228 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3229 | * |
| 3230 | * Returns 0 for success, non-zero for failure. |
| 3231 | */ |
| 3232 | static int |
| 3233 | _base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
| 3234 | { |
| 3235 | u32 host_diagnostic; |
| 3236 | u32 ioc_state; |
| 3237 | u32 count; |
| 3238 | u32 hcb_size; |
| 3239 | |
| 3240 | printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name); |
| 3241 | |
| 3242 | _base_save_msix_table(ioc); |
| 3243 | |
| 3244 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "clear interrupts\n", |
| 3245 | ioc->name)); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3246 | |
| 3247 | count = 0; |
| 3248 | do { |
| 3249 | /* Write magic sequence to WriteSequence register |
| 3250 | * Loop until in diagnostic mode |
| 3251 | */ |
| 3252 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "write magic " |
| 3253 | "sequence\n", ioc->name)); |
| 3254 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3255 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3256 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3257 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3258 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3259 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3260 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3261 | |
| 3262 | /* wait 100 msec */ |
| 3263 | if (sleep_flag == CAN_SLEEP) |
| 3264 | msleep(100); |
| 3265 | else |
| 3266 | mdelay(100); |
| 3267 | |
| 3268 | if (count++ > 20) |
| 3269 | goto out; |
| 3270 | |
| 3271 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); |
| 3272 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "wrote magic " |
| 3273 | "sequence: count(%d), host_diagnostic(0x%08x)\n", |
| 3274 | ioc->name, count, host_diagnostic)); |
| 3275 | |
| 3276 | } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0); |
| 3277 | |
| 3278 | hcb_size = readl(&ioc->chip->HCBSize); |
| 3279 | |
| 3280 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "diag reset: issued\n", |
| 3281 | ioc->name)); |
| 3282 | writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER, |
| 3283 | &ioc->chip->HostDiagnostic); |
| 3284 | |
| 3285 | /* don't access any registers for 50 milliseconds */ |
| 3286 | msleep(50); |
| 3287 | |
| 3288 | /* 300 second max wait */ |
| 3289 | for (count = 0; count < 3000000 ; count++) { |
| 3290 | |
| 3291 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); |
| 3292 | |
| 3293 | if (host_diagnostic == 0xFFFFFFFF) |
| 3294 | goto out; |
| 3295 | if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER)) |
| 3296 | break; |
| 3297 | |
| 3298 | /* wait 100 msec */ |
| 3299 | if (sleep_flag == CAN_SLEEP) |
| 3300 | msleep(1); |
| 3301 | else |
| 3302 | mdelay(1); |
| 3303 | } |
| 3304 | |
| 3305 | if (host_diagnostic & MPI2_DIAG_HCB_MODE) { |
| 3306 | |
| 3307 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "restart the adapter " |
| 3308 | "assuming the HCB Address points to good F/W\n", |
| 3309 | ioc->name)); |
| 3310 | host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK; |
| 3311 | host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW; |
| 3312 | writel(host_diagnostic, &ioc->chip->HostDiagnostic); |
| 3313 | |
| 3314 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT |
| 3315 | "re-enable the HCDW\n", ioc->name)); |
| 3316 | writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE, |
| 3317 | &ioc->chip->HCBSize); |
| 3318 | } |
| 3319 | |
| 3320 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "restart the adapter\n", |
| 3321 | ioc->name)); |
| 3322 | writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET, |
| 3323 | &ioc->chip->HostDiagnostic); |
| 3324 | |
| 3325 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "disable writes to the " |
| 3326 | "diagnostic register\n", ioc->name)); |
| 3327 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 3328 | |
| 3329 | drsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "Wait for FW to go to the " |
| 3330 | "READY state\n", ioc->name)); |
| 3331 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20, |
| 3332 | sleep_flag); |
| 3333 | if (ioc_state) { |
| 3334 | printk(MPT2SAS_ERR_FMT "%s: failed going to ready state " |
| 3335 | " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state); |
| 3336 | goto out; |
| 3337 | } |
| 3338 | |
| 3339 | _base_restore_msix_table(ioc); |
| 3340 | printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name); |
| 3341 | return 0; |
| 3342 | |
| 3343 | out: |
| 3344 | printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name); |
| 3345 | return -EFAULT; |
| 3346 | } |
| 3347 | |
| 3348 | /** |
| 3349 | * _base_make_ioc_ready - put controller in READY state |
| 3350 | * @ioc: per adapter object |
| 3351 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3352 | * @type: FORCE_BIG_HAMMER or SOFT_RESET |
| 3353 | * |
| 3354 | * Returns 0 for success, non-zero for failure. |
| 3355 | */ |
| 3356 | static int |
| 3357 | _base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag, |
| 3358 | enum reset_type type) |
| 3359 | { |
| 3360 | u32 ioc_state; |
| 3361 | |
| 3362 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 3363 | __func__)); |
| 3364 | |
| 3365 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 3366 | dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: ioc_state(0x%08x)\n", |
| 3367 | ioc->name, __func__, ioc_state)); |
| 3368 | |
| 3369 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) |
| 3370 | return 0; |
| 3371 | |
| 3372 | if (ioc_state & MPI2_DOORBELL_USED) { |
| 3373 | dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell " |
| 3374 | "active!\n", ioc->name)); |
| 3375 | goto issue_diag_reset; |
| 3376 | } |
| 3377 | |
| 3378 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 3379 | mpt2sas_base_fault_info(ioc, ioc_state & |
| 3380 | MPI2_DOORBELL_DATA_MASK); |
| 3381 | goto issue_diag_reset; |
| 3382 | } |
| 3383 | |
| 3384 | if (type == FORCE_BIG_HAMMER) |
| 3385 | goto issue_diag_reset; |
| 3386 | |
| 3387 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) |
| 3388 | if (!(_base_send_ioc_reset(ioc, |
| 3389 | MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) |
| 3390 | return 0; |
| 3391 | |
| 3392 | issue_diag_reset: |
| 3393 | return _base_diag_reset(ioc, CAN_SLEEP); |
| 3394 | } |
| 3395 | |
| 3396 | /** |
| 3397 | * _base_make_ioc_operational - put controller in OPERATIONAL state |
| 3398 | * @ioc: per adapter object |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3399 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3400 | * |
| 3401 | * Returns 0 for success, non-zero for failure. |
| 3402 | */ |
| 3403 | static int |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3404 | _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3405 | { |
| 3406 | int r, i; |
| 3407 | unsigned long flags; |
| 3408 | u32 reply_address; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3409 | u16 smid; |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3410 | struct _tr_list *delayed_tr, *delayed_tr_next; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3411 | |
| 3412 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 3413 | __func__)); |
| 3414 | |
Kashyap, Desai | 77e63ed | 2009-09-14 11:04:23 +0530 | [diff] [blame] | 3415 | /* clean the delayed target reset list */ |
| 3416 | list_for_each_entry_safe(delayed_tr, delayed_tr_next, |
| 3417 | &ioc->delayed_tr_list, list) { |
| 3418 | list_del(&delayed_tr->list); |
| 3419 | kfree(delayed_tr); |
| 3420 | } |
| 3421 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3422 | /* initialize the scsi lookup free list */ |
| 3423 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 3424 | INIT_LIST_HEAD(&ioc->free_list); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3425 | smid = 1; |
| 3426 | for (i = 0; i < ioc->scsiio_depth; i++, smid++) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3427 | ioc->scsi_lookup[i].cb_idx = 0xFF; |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3428 | ioc->scsi_lookup[i].smid = smid; |
| 3429 | ioc->scsi_lookup[i].scmd = NULL; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3430 | list_add_tail(&ioc->scsi_lookup[i].tracker_list, |
| 3431 | &ioc->free_list); |
| 3432 | } |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3433 | |
| 3434 | /* hi-priority queue */ |
| 3435 | INIT_LIST_HEAD(&ioc->hpr_free_list); |
| 3436 | smid = ioc->hi_priority_smid; |
| 3437 | for (i = 0; i < ioc->hi_priority_depth; i++, smid++) { |
| 3438 | ioc->hpr_lookup[i].cb_idx = 0xFF; |
| 3439 | ioc->hpr_lookup[i].smid = smid; |
| 3440 | list_add_tail(&ioc->hpr_lookup[i].tracker_list, |
| 3441 | &ioc->hpr_free_list); |
| 3442 | } |
| 3443 | |
| 3444 | /* internal queue */ |
| 3445 | INIT_LIST_HEAD(&ioc->internal_free_list); |
| 3446 | smid = ioc->internal_smid; |
| 3447 | for (i = 0; i < ioc->internal_depth; i++, smid++) { |
| 3448 | ioc->internal_lookup[i].cb_idx = 0xFF; |
| 3449 | ioc->internal_lookup[i].smid = smid; |
| 3450 | list_add_tail(&ioc->internal_lookup[i].tracker_list, |
| 3451 | &ioc->internal_free_list); |
| 3452 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3453 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 3454 | |
| 3455 | /* initialize Reply Free Queue */ |
| 3456 | for (i = 0, reply_address = (u32)ioc->reply_dma ; |
| 3457 | i < ioc->reply_free_queue_depth ; i++, reply_address += |
| 3458 | ioc->reply_sz) |
| 3459 | ioc->reply_free[i] = cpu_to_le32(reply_address); |
| 3460 | |
| 3461 | /* initialize Reply Post Free Queue */ |
| 3462 | for (i = 0; i < ioc->reply_post_queue_depth; i++) |
Eric Moore | 03ea111 | 2009-04-21 15:37:57 -0600 | [diff] [blame] | 3463 | ioc->reply_post_free[i].Words = ULLONG_MAX; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3464 | |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3465 | r = _base_send_ioc_init(ioc, sleep_flag); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3466 | if (r) |
| 3467 | return r; |
| 3468 | |
| 3469 | /* initialize the index's */ |
| 3470 | ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1; |
| 3471 | ioc->reply_post_host_index = 0; |
| 3472 | writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex); |
| 3473 | writel(0, &ioc->chip->ReplyPostHostIndex); |
| 3474 | |
| 3475 | _base_unmask_interrupts(ioc); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3476 | r = _base_event_notification(ioc, sleep_flag); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3477 | if (r) |
| 3478 | return r; |
| 3479 | |
| 3480 | if (sleep_flag == CAN_SLEEP) |
| 3481 | _base_static_config_pages(ioc); |
| 3482 | |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3483 | r = _base_send_port_enable(ioc, sleep_flag); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3484 | if (r) |
| 3485 | return r; |
| 3486 | |
| 3487 | return r; |
| 3488 | } |
| 3489 | |
| 3490 | /** |
| 3491 | * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap) |
| 3492 | * @ioc: per adapter object |
| 3493 | * |
| 3494 | * Return nothing. |
| 3495 | */ |
| 3496 | void |
| 3497 | mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc) |
| 3498 | { |
| 3499 | struct pci_dev *pdev = ioc->pdev; |
| 3500 | |
| 3501 | dexitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 3502 | __func__)); |
| 3503 | |
| 3504 | _base_mask_interrupts(ioc); |
| 3505 | _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET); |
| 3506 | if (ioc->pci_irq) { |
| 3507 | synchronize_irq(pdev->irq); |
| 3508 | free_irq(ioc->pci_irq, ioc); |
| 3509 | } |
| 3510 | _base_disable_msix(ioc); |
| 3511 | if (ioc->chip_phys) |
| 3512 | iounmap(ioc->chip); |
| 3513 | ioc->pci_irq = -1; |
| 3514 | ioc->chip_phys = 0; |
| 3515 | pci_release_selected_regions(ioc->pdev, ioc->bars); |
| 3516 | pci_disable_device(pdev); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3517 | return; |
| 3518 | } |
| 3519 | |
| 3520 | /** |
| 3521 | * mpt2sas_base_attach - attach controller instance |
| 3522 | * @ioc: per adapter object |
| 3523 | * |
| 3524 | * Returns 0 for success, non-zero for failure. |
| 3525 | */ |
| 3526 | int |
| 3527 | mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc) |
| 3528 | { |
| 3529 | int r, i; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3530 | |
| 3531 | dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 3532 | __func__)); |
| 3533 | |
| 3534 | r = mpt2sas_base_map_resources(ioc); |
| 3535 | if (r) |
| 3536 | return r; |
| 3537 | |
Kashyap, Desai | fcfe639 | 2009-08-07 19:38:48 +0530 | [diff] [blame] | 3538 | pci_set_drvdata(ioc->pdev, ioc->shost); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3539 | r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET); |
| 3540 | if (r) |
| 3541 | goto out_free_resources; |
| 3542 | |
| 3543 | r = _base_get_ioc_facts(ioc, CAN_SLEEP); |
| 3544 | if (r) |
| 3545 | goto out_free_resources; |
| 3546 | |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3547 | ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts, |
| 3548 | sizeof(Mpi2PortFactsReply_t), GFP_KERNEL); |
| 3549 | if (!ioc->pfacts) |
| 3550 | goto out_free_resources; |
| 3551 | |
| 3552 | for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) { |
| 3553 | r = _base_get_port_facts(ioc, i, CAN_SLEEP); |
| 3554 | if (r) |
| 3555 | goto out_free_resources; |
| 3556 | } |
| 3557 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3558 | r = _base_allocate_memory_pools(ioc, CAN_SLEEP); |
| 3559 | if (r) |
| 3560 | goto out_free_resources; |
| 3561 | |
| 3562 | init_waitqueue_head(&ioc->reset_wq); |
| 3563 | |
| 3564 | /* base internal command bits */ |
| 3565 | mutex_init(&ioc->base_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3566 | ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 3567 | ioc->base_cmds.status = MPT2_CMD_NOT_USED; |
| 3568 | |
| 3569 | /* transport internal command bits */ |
| 3570 | ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 3571 | ioc->transport_cmds.status = MPT2_CMD_NOT_USED; |
| 3572 | mutex_init(&ioc->transport_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3573 | |
| 3574 | /* task management internal command bits */ |
| 3575 | ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 3576 | ioc->tm_cmds.status = MPT2_CMD_NOT_USED; |
| 3577 | mutex_init(&ioc->tm_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3578 | |
| 3579 | /* config page internal command bits */ |
| 3580 | ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 3581 | ioc->config_cmds.status = MPT2_CMD_NOT_USED; |
| 3582 | mutex_init(&ioc->config_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3583 | |
| 3584 | /* ctl module internal command bits */ |
| 3585 | ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 3586 | ioc->ctl_cmds.status = MPT2_CMD_NOT_USED; |
| 3587 | mutex_init(&ioc->ctl_cmds.mutex); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3588 | |
| 3589 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) |
| 3590 | ioc->event_masks[i] = -1; |
| 3591 | |
| 3592 | /* here we enable the events we care about */ |
| 3593 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY); |
| 3594 | _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE); |
| 3595 | _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST); |
| 3596 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 3597 | _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE); |
| 3598 | _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST); |
| 3599 | _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME); |
| 3600 | _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK); |
| 3601 | _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS); |
| 3602 | _base_unmask_events(ioc, MPI2_EVENT_TASK_SET_FULL); |
| 3603 | _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3604 | r = _base_make_ioc_operational(ioc, CAN_SLEEP); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3605 | if (r) |
| 3606 | goto out_free_resources; |
| 3607 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 3608 | mpt2sas_base_start_watchdog(ioc); |
Kashyap, Desai | 32e0eb5 | 2009-09-23 17:28:09 +0530 | [diff] [blame] | 3609 | if (diag_buffer_enable != 0) |
| 3610 | mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3611 | return 0; |
| 3612 | |
| 3613 | out_free_resources: |
| 3614 | |
| 3615 | ioc->remove_host = 1; |
| 3616 | mpt2sas_base_free_resources(ioc); |
| 3617 | _base_release_memory_pools(ioc); |
Kashyap, Desai | fcfe639 | 2009-08-07 19:38:48 +0530 | [diff] [blame] | 3618 | pci_set_drvdata(ioc->pdev, NULL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3619 | kfree(ioc->tm_cmds.reply); |
| 3620 | kfree(ioc->transport_cmds.reply); |
| 3621 | kfree(ioc->config_cmds.reply); |
| 3622 | kfree(ioc->base_cmds.reply); |
| 3623 | kfree(ioc->ctl_cmds.reply); |
| 3624 | kfree(ioc->pfacts); |
| 3625 | ioc->ctl_cmds.reply = NULL; |
| 3626 | ioc->base_cmds.reply = NULL; |
| 3627 | ioc->tm_cmds.reply = NULL; |
| 3628 | ioc->transport_cmds.reply = NULL; |
| 3629 | ioc->config_cmds.reply = NULL; |
| 3630 | ioc->pfacts = NULL; |
| 3631 | return r; |
| 3632 | } |
| 3633 | |
| 3634 | |
| 3635 | /** |
| 3636 | * mpt2sas_base_detach - remove controller instance |
| 3637 | * @ioc: per adapter object |
| 3638 | * |
| 3639 | * Return nothing. |
| 3640 | */ |
| 3641 | void |
| 3642 | mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc) |
| 3643 | { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3644 | |
| 3645 | dexitprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s\n", ioc->name, |
| 3646 | __func__)); |
| 3647 | |
Kashyap, Desai | e4750c9 | 2009-08-07 19:37:59 +0530 | [diff] [blame] | 3648 | mpt2sas_base_stop_watchdog(ioc); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3649 | mpt2sas_base_free_resources(ioc); |
| 3650 | _base_release_memory_pools(ioc); |
Kashyap, Desai | fcfe639 | 2009-08-07 19:38:48 +0530 | [diff] [blame] | 3651 | pci_set_drvdata(ioc->pdev, NULL); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3652 | kfree(ioc->pfacts); |
| 3653 | kfree(ioc->ctl_cmds.reply); |
| 3654 | kfree(ioc->base_cmds.reply); |
| 3655 | kfree(ioc->tm_cmds.reply); |
| 3656 | kfree(ioc->transport_cmds.reply); |
| 3657 | kfree(ioc->config_cmds.reply); |
| 3658 | } |
| 3659 | |
| 3660 | /** |
| 3661 | * _base_reset_handler - reset callback handler (for base) |
| 3662 | * @ioc: per adapter object |
| 3663 | * @reset_phase: phase |
| 3664 | * |
| 3665 | * The handler for doing any required cleanup or initialization. |
| 3666 | * |
| 3667 | * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET, |
| 3668 | * MPT2_IOC_DONE_RESET |
| 3669 | * |
| 3670 | * Return nothing. |
| 3671 | */ |
| 3672 | static void |
| 3673 | _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase) |
| 3674 | { |
| 3675 | switch (reset_phase) { |
| 3676 | case MPT2_IOC_PRE_RESET: |
| 3677 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 3678 | "MPT2_IOC_PRE_RESET\n", ioc->name, __func__)); |
| 3679 | break; |
| 3680 | case MPT2_IOC_AFTER_RESET: |
| 3681 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 3682 | "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__)); |
| 3683 | if (ioc->transport_cmds.status & MPT2_CMD_PENDING) { |
| 3684 | ioc->transport_cmds.status |= MPT2_CMD_RESET; |
| 3685 | mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid); |
| 3686 | complete(&ioc->transport_cmds.done); |
| 3687 | } |
| 3688 | if (ioc->base_cmds.status & MPT2_CMD_PENDING) { |
| 3689 | ioc->base_cmds.status |= MPT2_CMD_RESET; |
| 3690 | mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid); |
| 3691 | complete(&ioc->base_cmds.done); |
| 3692 | } |
| 3693 | if (ioc->config_cmds.status & MPT2_CMD_PENDING) { |
| 3694 | ioc->config_cmds.status |= MPT2_CMD_RESET; |
| 3695 | mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid); |
Kashyap, Desai | 5b76858 | 2009-08-20 13:24:31 +0530 | [diff] [blame] | 3696 | ioc->config_cmds.smid = USHORT_MAX; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3697 | complete(&ioc->config_cmds.done); |
| 3698 | } |
| 3699 | break; |
| 3700 | case MPT2_IOC_DONE_RESET: |
| 3701 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: " |
| 3702 | "MPT2_IOC_DONE_RESET\n", ioc->name, __func__)); |
| 3703 | break; |
| 3704 | } |
| 3705 | mpt2sas_scsih_reset_handler(ioc, reset_phase); |
| 3706 | mpt2sas_ctl_reset_handler(ioc, reset_phase); |
| 3707 | } |
| 3708 | |
| 3709 | /** |
| 3710 | * _wait_for_commands_to_complete - reset controller |
| 3711 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3712 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3713 | * |
| 3714 | * This function waiting(3s) for all pending commands to complete |
| 3715 | * prior to putting controller in reset. |
| 3716 | */ |
| 3717 | static void |
| 3718 | _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) |
| 3719 | { |
| 3720 | u32 ioc_state; |
| 3721 | unsigned long flags; |
| 3722 | u16 i; |
| 3723 | |
| 3724 | ioc->pending_io_count = 0; |
| 3725 | if (sleep_flag != CAN_SLEEP) |
| 3726 | return; |
| 3727 | |
| 3728 | ioc_state = mpt2sas_base_get_iocstate(ioc, 0); |
| 3729 | if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) |
| 3730 | return; |
| 3731 | |
| 3732 | /* pending command count */ |
| 3733 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
Kashyap, Desai | 595bb0b | 2009-09-14 11:02:48 +0530 | [diff] [blame] | 3734 | for (i = 0; i < ioc->scsiio_depth; i++) |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3735 | if (ioc->scsi_lookup[i].cb_idx != 0xFF) |
| 3736 | ioc->pending_io_count++; |
| 3737 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 3738 | |
| 3739 | if (!ioc->pending_io_count) |
| 3740 | return; |
| 3741 | |
| 3742 | /* wait for pending commands to complete */ |
| 3743 | wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 3 * HZ); |
| 3744 | } |
| 3745 | |
| 3746 | /** |
| 3747 | * mpt2sas_base_hard_reset_handler - reset controller |
| 3748 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3749 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3750 | * @type: FORCE_BIG_HAMMER or SOFT_RESET |
| 3751 | * |
| 3752 | * Returns 0 for success, non-zero for failure. |
| 3753 | */ |
| 3754 | int |
| 3755 | mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag, |
| 3756 | enum reset_type type) |
| 3757 | { |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3758 | int r; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3759 | unsigned long flags; |
| 3760 | |
| 3761 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name, |
| 3762 | __func__)); |
| 3763 | |
Kashyap, Desai | fa7f316 | 2009-09-23 17:26:58 +0530 | [diff] [blame] | 3764 | if (mpt2sas_fwfault_debug) |
| 3765 | mpt2sas_halt_firmware(ioc); |
| 3766 | |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3767 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 3768 | if (ioc->shost_recovery) { |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3769 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 3770 | printk(MPT2SAS_ERR_FMT "%s: busy\n", |
| 3771 | ioc->name, __func__); |
| 3772 | return -EBUSY; |
| 3773 | } |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3774 | ioc->shost_recovery = 1; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3775 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 3776 | |
| 3777 | _base_reset_handler(ioc, MPT2_IOC_PRE_RESET); |
| 3778 | _wait_for_commands_to_complete(ioc, sleep_flag); |
| 3779 | _base_mask_interrupts(ioc); |
| 3780 | r = _base_make_ioc_ready(ioc, sleep_flag, type); |
| 3781 | if (r) |
| 3782 | goto out; |
| 3783 | _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET); |
Kashyap, Desai | 7b936b0 | 2009-09-25 11:44:41 +0530 | [diff] [blame] | 3784 | r = _base_make_ioc_operational(ioc, sleep_flag); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3785 | if (!r) |
| 3786 | _base_reset_handler(ioc, MPT2_IOC_DONE_RESET); |
| 3787 | out: |
| 3788 | dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: %s\n", |
| 3789 | ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED"))); |
| 3790 | |
| 3791 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
Kashyap, Desai | 155dd4c | 2009-08-20 13:22:00 +0530 | [diff] [blame] | 3792 | ioc->shost_recovery = 0; |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3793 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
Kashyap, Desai | cd4e12e | 2009-08-20 13:20:54 +0530 | [diff] [blame] | 3794 | |
| 3795 | if (!r) |
| 3796 | _base_reset_handler(ioc, MPT2_IOC_RUNNING); |
Eric Moore | 635374e | 2009-03-09 01:21:12 -0600 | [diff] [blame] | 3797 | return r; |
| 3798 | } |