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