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