Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [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/mpt3sas/mpt3sas_base.c |
Sreekanth Reddy | a4ffce0 | 2014-09-12 15:35:29 +0530 | [diff] [blame] | 6 | * Copyright (C) 2012-2014 LSI Corporation |
Sreekanth Reddy | a03bd15 | 2015-01-12 11:39:02 +0530 | [diff] [blame] | 7 | * Copyright (C) 2013-2014 Avago Technologies |
| 8 | * (mailto: MPT-FusionLinux.pdl@avagotech.com) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * NO WARRANTY |
| 21 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 22 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 23 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 24 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 25 | * solely responsible for determining the appropriateness of using and |
| 26 | * distributing the Program and assumes all risks associated with its |
| 27 | * exercise of rights under this Agreement, including but not limited to |
| 28 | * the risks and costs of program errors, damage to or loss of data, |
| 29 | * programs or equipment, and unavailability or interruption of operations. |
| 30 | |
| 31 | * DISCLAIMER OF LIABILITY |
| 32 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 33 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 34 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 35 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 36 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 37 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 38 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 39 | |
| 40 | * You should have received a copy of the GNU General Public License |
| 41 | * along with this program; if not, write to the Free Software |
| 42 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 43 | * USA. |
| 44 | */ |
| 45 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 46 | #include <linux/kernel.h> |
| 47 | #include <linux/module.h> |
| 48 | #include <linux/errno.h> |
| 49 | #include <linux/init.h> |
| 50 | #include <linux/slab.h> |
| 51 | #include <linux/types.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/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/io.h> |
| 59 | #include <linux/time.h> |
Tina Ruchandani | 23409bd | 2016-04-13 00:01:40 -0700 | [diff] [blame] | 60 | #include <linux/ktime.h> |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 61 | #include <linux/kthread.h> |
| 62 | #include <linux/aer.h> |
| 63 | |
| 64 | |
| 65 | #include "mpt3sas_base.h" |
| 66 | |
| 67 | static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS]; |
| 68 | |
| 69 | |
| 70 | #define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */ |
| 71 | |
| 72 | /* maximum controller queue depth */ |
| 73 | #define MAX_HBA_QUEUE_DEPTH 30000 |
| 74 | #define MAX_CHAIN_DEPTH 100000 |
| 75 | static int max_queue_depth = -1; |
| 76 | module_param(max_queue_depth, int, 0); |
| 77 | MODULE_PARM_DESC(max_queue_depth, " max controller queue depth "); |
| 78 | |
| 79 | static int max_sgl_entries = -1; |
| 80 | module_param(max_sgl_entries, int, 0); |
| 81 | MODULE_PARM_DESC(max_sgl_entries, " max sg entries "); |
| 82 | |
| 83 | static int msix_disable = -1; |
| 84 | module_param(msix_disable, int, 0); |
| 85 | MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)"); |
| 86 | |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 87 | static int smp_affinity_enable = 1; |
| 88 | module_param(smp_affinity_enable, int, S_IRUGO); |
| 89 | MODULE_PARM_DESC(smp_affinity_enable, "SMP affinity feature enable/disbale Default: enable(1)"); |
| 90 | |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 91 | static int max_msix_vectors = -1; |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 92 | module_param(max_msix_vectors, int, 0); |
| 93 | MODULE_PARM_DESC(max_msix_vectors, |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 94 | " max msix vectors"); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 95 | |
| 96 | static int mpt3sas_fwfault_debug; |
| 97 | MODULE_PARM_DESC(mpt3sas_fwfault_debug, |
| 98 | " enable detection of firmware fault and halt firmware - (default=0)"); |
| 99 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 100 | static int |
| 101 | _base_get_ioc_facts(struct MPT3SAS_ADAPTER *ioc, int sleep_flag); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug. |
| 105 | * |
| 106 | */ |
| 107 | static int |
| 108 | _scsih_set_fwfault_debug(const char *val, struct kernel_param *kp) |
| 109 | { |
| 110 | int ret = param_set_int(val, kp); |
| 111 | struct MPT3SAS_ADAPTER *ioc; |
| 112 | |
| 113 | if (ret) |
| 114 | return ret; |
| 115 | |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 116 | /* global ioc spinlock to protect controller list on list operations */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 117 | pr_info("setting fwfault_debug(%d)\n", mpt3sas_fwfault_debug); |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 118 | spin_lock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 119 | list_for_each_entry(ioc, &mpt3sas_ioc_list, list) |
| 120 | ioc->fwfault_debug = mpt3sas_fwfault_debug; |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 121 | spin_unlock(&gioc_lock); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | module_param_call(mpt3sas_fwfault_debug, _scsih_set_fwfault_debug, |
| 125 | param_get_int, &mpt3sas_fwfault_debug, 0644); |
| 126 | |
| 127 | /** |
| 128 | * mpt3sas_remove_dead_ioc_func - kthread context to remove dead ioc |
| 129 | * @arg: input argument, used to derive ioc |
| 130 | * |
| 131 | * Return 0 if controller is removed from pci subsystem. |
| 132 | * Return -1 for other case. |
| 133 | */ |
| 134 | static int mpt3sas_remove_dead_ioc_func(void *arg) |
| 135 | { |
| 136 | struct MPT3SAS_ADAPTER *ioc = (struct MPT3SAS_ADAPTER *)arg; |
| 137 | struct pci_dev *pdev; |
| 138 | |
| 139 | if ((ioc == NULL)) |
| 140 | return -1; |
| 141 | |
| 142 | pdev = ioc->pdev; |
| 143 | if ((pdev == NULL)) |
| 144 | return -1; |
Rafael J. Wysocki | 64cdb41 | 2014-01-10 15:27:56 +0100 | [diff] [blame] | 145 | pci_stop_and_remove_bus_device_locked(pdev); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * _base_fault_reset_work - workq handling ioc fault conditions |
| 151 | * @work: input argument, used to derive ioc |
| 152 | * Context: sleep. |
| 153 | * |
| 154 | * Return nothing. |
| 155 | */ |
| 156 | static void |
| 157 | _base_fault_reset_work(struct work_struct *work) |
| 158 | { |
| 159 | struct MPT3SAS_ADAPTER *ioc = |
| 160 | container_of(work, struct MPT3SAS_ADAPTER, fault_reset_work.work); |
| 161 | unsigned long flags; |
| 162 | u32 doorbell; |
| 163 | int rc; |
| 164 | struct task_struct *p; |
| 165 | |
| 166 | |
| 167 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 168 | if (ioc->shost_recovery || ioc->pci_error_recovery) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 169 | goto rearm_timer; |
| 170 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 171 | |
| 172 | doorbell = mpt3sas_base_get_iocstate(ioc, 0); |
| 173 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) { |
| 174 | pr_err(MPT3SAS_FMT "SAS host is non-operational !!!!\n", |
| 175 | ioc->name); |
| 176 | |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 177 | /* It may be possible that EEH recovery can resolve some of |
| 178 | * pci bus failure issues rather removing the dead ioc function |
| 179 | * by considering controller is in a non-operational state. So |
| 180 | * here priority is given to the EEH recovery. If it doesn't |
| 181 | * not resolve this issue, mpt3sas driver will consider this |
| 182 | * controller to non-operational state and remove the dead ioc |
| 183 | * function. |
| 184 | */ |
| 185 | if (ioc->non_operational_loop++ < 5) { |
| 186 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, |
| 187 | flags); |
| 188 | goto rearm_timer; |
| 189 | } |
| 190 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 191 | /* |
| 192 | * Call _scsih_flush_pending_cmds callback so that we flush all |
| 193 | * pending commands back to OS. This call is required to aovid |
| 194 | * deadlock at block layer. Dead IOC will fail to do diag reset, |
| 195 | * and this call is safe since dead ioc will never return any |
| 196 | * command back from HW. |
| 197 | */ |
| 198 | ioc->schedule_dead_ioc_flush_running_cmds(ioc); |
| 199 | /* |
| 200 | * Set remove_host flag early since kernel thread will |
| 201 | * take some time to execute. |
| 202 | */ |
| 203 | ioc->remove_host = 1; |
| 204 | /*Remove the Dead Host */ |
| 205 | p = kthread_run(mpt3sas_remove_dead_ioc_func, ioc, |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 206 | "%s_dead_ioc_%d", ioc->driver_name, ioc->id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 207 | if (IS_ERR(p)) |
| 208 | pr_err(MPT3SAS_FMT |
| 209 | "%s: Running mpt3sas_dead_ioc thread failed !!!!\n", |
| 210 | ioc->name, __func__); |
| 211 | else |
| 212 | pr_err(MPT3SAS_FMT |
| 213 | "%s: Running mpt3sas_dead_ioc thread success !!!!\n", |
| 214 | ioc->name, __func__); |
| 215 | return; /* don't rearm timer */ |
| 216 | } |
| 217 | |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 218 | ioc->non_operational_loop = 0; |
| 219 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 220 | if ((doorbell & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) { |
| 221 | rc = mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 222 | FORCE_BIG_HAMMER); |
| 223 | pr_warn(MPT3SAS_FMT "%s: hard reset: %s\n", ioc->name, |
| 224 | __func__, (rc == 0) ? "success" : "failed"); |
| 225 | doorbell = mpt3sas_base_get_iocstate(ioc, 0); |
| 226 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 227 | mpt3sas_base_fault_info(ioc, doorbell & |
| 228 | MPI2_DOORBELL_DATA_MASK); |
| 229 | if (rc && (doorbell & MPI2_IOC_STATE_MASK) != |
| 230 | MPI2_IOC_STATE_OPERATIONAL) |
| 231 | return; /* don't rearm timer */ |
| 232 | } |
| 233 | |
| 234 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 235 | rearm_timer: |
| 236 | if (ioc->fault_reset_work_q) |
| 237 | queue_delayed_work(ioc->fault_reset_work_q, |
| 238 | &ioc->fault_reset_work, |
| 239 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); |
| 240 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * mpt3sas_base_start_watchdog - start the fault_reset_work_q |
| 245 | * @ioc: per adapter object |
| 246 | * Context: sleep. |
| 247 | * |
| 248 | * Return nothing. |
| 249 | */ |
| 250 | void |
| 251 | mpt3sas_base_start_watchdog(struct MPT3SAS_ADAPTER *ioc) |
| 252 | { |
| 253 | unsigned long flags; |
| 254 | |
| 255 | if (ioc->fault_reset_work_q) |
| 256 | return; |
| 257 | |
| 258 | /* initialize fault polling */ |
| 259 | |
| 260 | INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work); |
| 261 | snprintf(ioc->fault_reset_work_q_name, |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 262 | sizeof(ioc->fault_reset_work_q_name), "poll_%s%d_status", |
| 263 | ioc->driver_name, ioc->id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 264 | ioc->fault_reset_work_q = |
| 265 | create_singlethread_workqueue(ioc->fault_reset_work_q_name); |
| 266 | if (!ioc->fault_reset_work_q) { |
| 267 | pr_err(MPT3SAS_FMT "%s: failed (line=%d)\n", |
| 268 | ioc->name, __func__, __LINE__); |
| 269 | return; |
| 270 | } |
| 271 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 272 | if (ioc->fault_reset_work_q) |
| 273 | queue_delayed_work(ioc->fault_reset_work_q, |
| 274 | &ioc->fault_reset_work, |
| 275 | msecs_to_jiffies(FAULT_POLLING_INTERVAL)); |
| 276 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * mpt3sas_base_stop_watchdog - stop the fault_reset_work_q |
| 281 | * @ioc: per adapter object |
| 282 | * Context: sleep. |
| 283 | * |
| 284 | * Return nothing. |
| 285 | */ |
| 286 | void |
| 287 | mpt3sas_base_stop_watchdog(struct MPT3SAS_ADAPTER *ioc) |
| 288 | { |
| 289 | unsigned long flags; |
| 290 | struct workqueue_struct *wq; |
| 291 | |
| 292 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 293 | wq = ioc->fault_reset_work_q; |
| 294 | ioc->fault_reset_work_q = NULL; |
| 295 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 296 | if (wq) { |
Reddy, Sreekanth | 4dc06fd | 2014-07-14 12:01:35 +0530 | [diff] [blame] | 297 | if (!cancel_delayed_work_sync(&ioc->fault_reset_work)) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 298 | flush_workqueue(wq); |
| 299 | destroy_workqueue(wq); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * mpt3sas_base_fault_info - verbose translation of firmware FAULT code |
| 305 | * @ioc: per adapter object |
| 306 | * @fault_code: fault code |
| 307 | * |
| 308 | * Return nothing. |
| 309 | */ |
| 310 | void |
| 311 | mpt3sas_base_fault_info(struct MPT3SAS_ADAPTER *ioc , u16 fault_code) |
| 312 | { |
| 313 | pr_err(MPT3SAS_FMT "fault_state(0x%04x)!\n", |
| 314 | ioc->name, fault_code); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * mpt3sas_halt_firmware - halt's mpt controller firmware |
| 319 | * @ioc: per adapter object |
| 320 | * |
| 321 | * For debugging timeout related issues. Writing 0xCOFFEE00 |
| 322 | * to the doorbell register will halt controller firmware. With |
| 323 | * the purpose to stop both driver and firmware, the enduser can |
| 324 | * obtain a ring buffer from controller UART. |
| 325 | */ |
| 326 | void |
| 327 | mpt3sas_halt_firmware(struct MPT3SAS_ADAPTER *ioc) |
| 328 | { |
| 329 | u32 doorbell; |
| 330 | |
| 331 | if (!ioc->fwfault_debug) |
| 332 | return; |
| 333 | |
| 334 | dump_stack(); |
| 335 | |
| 336 | doorbell = readl(&ioc->chip->Doorbell); |
| 337 | if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 338 | mpt3sas_base_fault_info(ioc , doorbell); |
| 339 | else { |
| 340 | writel(0xC0FFEE00, &ioc->chip->Doorbell); |
| 341 | pr_err(MPT3SAS_FMT "Firmware is halted due to command timeout\n", |
| 342 | ioc->name); |
| 343 | } |
| 344 | |
| 345 | if (ioc->fwfault_debug == 2) |
| 346 | for (;;) |
| 347 | ; |
| 348 | else |
| 349 | panic("panic in %s\n", __func__); |
| 350 | } |
| 351 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 352 | /** |
| 353 | * _base_sas_ioc_info - verbose translation of the ioc status |
| 354 | * @ioc: per adapter object |
| 355 | * @mpi_reply: reply mf payload returned from firmware |
| 356 | * @request_hdr: request mf |
| 357 | * |
| 358 | * Return nothing. |
| 359 | */ |
| 360 | static void |
| 361 | _base_sas_ioc_info(struct MPT3SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply, |
| 362 | MPI2RequestHeader_t *request_hdr) |
| 363 | { |
| 364 | u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & |
| 365 | MPI2_IOCSTATUS_MASK; |
| 366 | char *desc = NULL; |
| 367 | u16 frame_sz; |
| 368 | char *func_str = NULL; |
| 369 | |
| 370 | /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */ |
| 371 | if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST || |
| 372 | request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH || |
| 373 | request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION) |
| 374 | return; |
| 375 | |
| 376 | if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) |
| 377 | return; |
| 378 | |
| 379 | switch (ioc_status) { |
| 380 | |
| 381 | /**************************************************************************** |
| 382 | * Common IOCStatus values for all replies |
| 383 | ****************************************************************************/ |
| 384 | |
| 385 | case MPI2_IOCSTATUS_INVALID_FUNCTION: |
| 386 | desc = "invalid function"; |
| 387 | break; |
| 388 | case MPI2_IOCSTATUS_BUSY: |
| 389 | desc = "busy"; |
| 390 | break; |
| 391 | case MPI2_IOCSTATUS_INVALID_SGL: |
| 392 | desc = "invalid sgl"; |
| 393 | break; |
| 394 | case MPI2_IOCSTATUS_INTERNAL_ERROR: |
| 395 | desc = "internal error"; |
| 396 | break; |
| 397 | case MPI2_IOCSTATUS_INVALID_VPID: |
| 398 | desc = "invalid vpid"; |
| 399 | break; |
| 400 | case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES: |
| 401 | desc = "insufficient resources"; |
| 402 | break; |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 403 | case MPI2_IOCSTATUS_INSUFFICIENT_POWER: |
| 404 | desc = "insufficient power"; |
| 405 | break; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 406 | case MPI2_IOCSTATUS_INVALID_FIELD: |
| 407 | desc = "invalid field"; |
| 408 | break; |
| 409 | case MPI2_IOCSTATUS_INVALID_STATE: |
| 410 | desc = "invalid state"; |
| 411 | break; |
| 412 | case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED: |
| 413 | desc = "op state not supported"; |
| 414 | break; |
| 415 | |
| 416 | /**************************************************************************** |
| 417 | * Config IOCStatus values |
| 418 | ****************************************************************************/ |
| 419 | |
| 420 | case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION: |
| 421 | desc = "config invalid action"; |
| 422 | break; |
| 423 | case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE: |
| 424 | desc = "config invalid type"; |
| 425 | break; |
| 426 | case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE: |
| 427 | desc = "config invalid page"; |
| 428 | break; |
| 429 | case MPI2_IOCSTATUS_CONFIG_INVALID_DATA: |
| 430 | desc = "config invalid data"; |
| 431 | break; |
| 432 | case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS: |
| 433 | desc = "config no defaults"; |
| 434 | break; |
| 435 | case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT: |
| 436 | desc = "config cant commit"; |
| 437 | break; |
| 438 | |
| 439 | /**************************************************************************** |
| 440 | * SCSI IO Reply |
| 441 | ****************************************************************************/ |
| 442 | |
| 443 | case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR: |
| 444 | case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE: |
| 445 | case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE: |
| 446 | case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN: |
| 447 | case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN: |
| 448 | case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR: |
| 449 | case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR: |
| 450 | case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED: |
| 451 | case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: |
| 452 | case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED: |
| 453 | case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED: |
| 454 | case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED: |
| 455 | break; |
| 456 | |
| 457 | /**************************************************************************** |
| 458 | * For use by SCSI Initiator and SCSI Target end-to-end data protection |
| 459 | ****************************************************************************/ |
| 460 | |
| 461 | case MPI2_IOCSTATUS_EEDP_GUARD_ERROR: |
| 462 | desc = "eedp guard error"; |
| 463 | break; |
| 464 | case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR: |
| 465 | desc = "eedp ref tag error"; |
| 466 | break; |
| 467 | case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR: |
| 468 | desc = "eedp app tag error"; |
| 469 | break; |
| 470 | |
| 471 | /**************************************************************************** |
| 472 | * SCSI Target values |
| 473 | ****************************************************************************/ |
| 474 | |
| 475 | case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX: |
| 476 | desc = "target invalid io index"; |
| 477 | break; |
| 478 | case MPI2_IOCSTATUS_TARGET_ABORTED: |
| 479 | desc = "target aborted"; |
| 480 | break; |
| 481 | case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: |
| 482 | desc = "target no conn retryable"; |
| 483 | break; |
| 484 | case MPI2_IOCSTATUS_TARGET_NO_CONNECTION: |
| 485 | desc = "target no connection"; |
| 486 | break; |
| 487 | case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: |
| 488 | desc = "target xfer count mismatch"; |
| 489 | break; |
| 490 | case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: |
| 491 | desc = "target data offset error"; |
| 492 | break; |
| 493 | case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: |
| 494 | desc = "target too much write data"; |
| 495 | break; |
| 496 | case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT: |
| 497 | desc = "target iu too short"; |
| 498 | break; |
| 499 | case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: |
| 500 | desc = "target ack nak timeout"; |
| 501 | break; |
| 502 | case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED: |
| 503 | desc = "target nak received"; |
| 504 | break; |
| 505 | |
| 506 | /**************************************************************************** |
| 507 | * Serial Attached SCSI values |
| 508 | ****************************************************************************/ |
| 509 | |
| 510 | case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED: |
| 511 | desc = "smp request failed"; |
| 512 | break; |
| 513 | case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN: |
| 514 | desc = "smp data overrun"; |
| 515 | break; |
| 516 | |
| 517 | /**************************************************************************** |
| 518 | * Diagnostic Buffer Post / Diagnostic Release values |
| 519 | ****************************************************************************/ |
| 520 | |
| 521 | case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED: |
| 522 | desc = "diagnostic released"; |
| 523 | break; |
| 524 | default: |
| 525 | break; |
| 526 | } |
| 527 | |
| 528 | if (!desc) |
| 529 | return; |
| 530 | |
| 531 | switch (request_hdr->Function) { |
| 532 | case MPI2_FUNCTION_CONFIG: |
| 533 | frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size; |
| 534 | func_str = "config_page"; |
| 535 | break; |
| 536 | case MPI2_FUNCTION_SCSI_TASK_MGMT: |
| 537 | frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t); |
| 538 | func_str = "task_mgmt"; |
| 539 | break; |
| 540 | case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL: |
| 541 | frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t); |
| 542 | func_str = "sas_iounit_ctl"; |
| 543 | break; |
| 544 | case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR: |
| 545 | frame_sz = sizeof(Mpi2SepRequest_t); |
| 546 | func_str = "enclosure"; |
| 547 | break; |
| 548 | case MPI2_FUNCTION_IOC_INIT: |
| 549 | frame_sz = sizeof(Mpi2IOCInitRequest_t); |
| 550 | func_str = "ioc_init"; |
| 551 | break; |
| 552 | case MPI2_FUNCTION_PORT_ENABLE: |
| 553 | frame_sz = sizeof(Mpi2PortEnableRequest_t); |
| 554 | func_str = "port_enable"; |
| 555 | break; |
| 556 | case MPI2_FUNCTION_SMP_PASSTHROUGH: |
| 557 | frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size; |
| 558 | func_str = "smp_passthru"; |
| 559 | break; |
| 560 | default: |
| 561 | frame_sz = 32; |
| 562 | func_str = "unknown"; |
| 563 | break; |
| 564 | } |
| 565 | |
| 566 | pr_warn(MPT3SAS_FMT "ioc_status: %s(0x%04x), request(0x%p),(%s)\n", |
| 567 | ioc->name, desc, ioc_status, request_hdr, func_str); |
| 568 | |
| 569 | _debug_dump_mf(request_hdr, frame_sz/4); |
| 570 | } |
| 571 | |
| 572 | /** |
| 573 | * _base_display_event_data - verbose translation of firmware asyn events |
| 574 | * @ioc: per adapter object |
| 575 | * @mpi_reply: reply mf payload returned from firmware |
| 576 | * |
| 577 | * Return nothing. |
| 578 | */ |
| 579 | static void |
| 580 | _base_display_event_data(struct MPT3SAS_ADAPTER *ioc, |
| 581 | Mpi2EventNotificationReply_t *mpi_reply) |
| 582 | { |
| 583 | char *desc = NULL; |
| 584 | u16 event; |
| 585 | |
| 586 | if (!(ioc->logging_level & MPT_DEBUG_EVENTS)) |
| 587 | return; |
| 588 | |
| 589 | event = le16_to_cpu(mpi_reply->Event); |
| 590 | |
| 591 | switch (event) { |
| 592 | case MPI2_EVENT_LOG_DATA: |
| 593 | desc = "Log Data"; |
| 594 | break; |
| 595 | case MPI2_EVENT_STATE_CHANGE: |
| 596 | desc = "Status Change"; |
| 597 | break; |
| 598 | case MPI2_EVENT_HARD_RESET_RECEIVED: |
| 599 | desc = "Hard Reset Received"; |
| 600 | break; |
| 601 | case MPI2_EVENT_EVENT_CHANGE: |
| 602 | desc = "Event Change"; |
| 603 | break; |
| 604 | case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE: |
| 605 | desc = "Device Status Change"; |
| 606 | break; |
| 607 | case MPI2_EVENT_IR_OPERATION_STATUS: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 608 | if (!ioc->hide_ir_msg) |
| 609 | desc = "IR Operation Status"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 610 | break; |
| 611 | case MPI2_EVENT_SAS_DISCOVERY: |
| 612 | { |
| 613 | Mpi2EventDataSasDiscovery_t *event_data = |
| 614 | (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData; |
| 615 | pr_info(MPT3SAS_FMT "Discovery: (%s)", ioc->name, |
| 616 | (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ? |
| 617 | "start" : "stop"); |
| 618 | if (event_data->DiscoveryStatus) |
| 619 | pr_info("discovery_status(0x%08x)", |
| 620 | le32_to_cpu(event_data->DiscoveryStatus)); |
| 621 | pr_info("\n"); |
| 622 | return; |
| 623 | } |
| 624 | case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE: |
| 625 | desc = "SAS Broadcast Primitive"; |
| 626 | break; |
| 627 | case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE: |
| 628 | desc = "SAS Init Device Status Change"; |
| 629 | break; |
| 630 | case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW: |
| 631 | desc = "SAS Init Table Overflow"; |
| 632 | break; |
| 633 | case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST: |
| 634 | desc = "SAS Topology Change List"; |
| 635 | break; |
| 636 | case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE: |
| 637 | desc = "SAS Enclosure Device Status Change"; |
| 638 | break; |
| 639 | case MPI2_EVENT_IR_VOLUME: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 640 | if (!ioc->hide_ir_msg) |
| 641 | desc = "IR Volume"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 642 | break; |
| 643 | case MPI2_EVENT_IR_PHYSICAL_DISK: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 644 | if (!ioc->hide_ir_msg) |
| 645 | desc = "IR Physical Disk"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 646 | break; |
| 647 | case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 648 | if (!ioc->hide_ir_msg) |
| 649 | desc = "IR Configuration Change List"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 650 | break; |
| 651 | case MPI2_EVENT_LOG_ENTRY_ADDED: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 652 | if (!ioc->hide_ir_msg) |
| 653 | desc = "Log Entry Added"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 654 | break; |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 655 | case MPI2_EVENT_TEMP_THRESHOLD: |
| 656 | desc = "Temperature Threshold"; |
| 657 | break; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | if (!desc) |
| 661 | return; |
| 662 | |
| 663 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, desc); |
| 664 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 665 | |
| 666 | /** |
| 667 | * _base_sas_log_info - verbose translation of firmware log info |
| 668 | * @ioc: per adapter object |
| 669 | * @log_info: log info |
| 670 | * |
| 671 | * Return nothing. |
| 672 | */ |
| 673 | static void |
| 674 | _base_sas_log_info(struct MPT3SAS_ADAPTER *ioc , u32 log_info) |
| 675 | { |
| 676 | union loginfo_type { |
| 677 | u32 loginfo; |
| 678 | struct { |
| 679 | u32 subcode:16; |
| 680 | u32 code:8; |
| 681 | u32 originator:4; |
| 682 | u32 bus_type:4; |
| 683 | } dw; |
| 684 | }; |
| 685 | union loginfo_type sas_loginfo; |
| 686 | char *originator_str = NULL; |
| 687 | |
| 688 | sas_loginfo.loginfo = log_info; |
| 689 | if (sas_loginfo.dw.bus_type != 3 /*SAS*/) |
| 690 | return; |
| 691 | |
| 692 | /* each nexus loss loginfo */ |
| 693 | if (log_info == 0x31170000) |
| 694 | return; |
| 695 | |
| 696 | /* eat the loginfos associated with task aborts */ |
| 697 | if (ioc->ignore_loginfos && (log_info == 0x30050000 || log_info == |
| 698 | 0x31140000 || log_info == 0x31130000)) |
| 699 | return; |
| 700 | |
| 701 | switch (sas_loginfo.dw.originator) { |
| 702 | case 0: |
| 703 | originator_str = "IOP"; |
| 704 | break; |
| 705 | case 1: |
| 706 | originator_str = "PL"; |
| 707 | break; |
| 708 | case 2: |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 709 | if (!ioc->hide_ir_msg) |
| 710 | originator_str = "IR"; |
| 711 | else |
| 712 | originator_str = "WarpDrive"; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 713 | break; |
| 714 | } |
| 715 | |
| 716 | pr_warn(MPT3SAS_FMT |
| 717 | "log_info(0x%08x): originator(%s), code(0x%02x), sub_code(0x%04x)\n", |
| 718 | ioc->name, log_info, |
| 719 | originator_str, sas_loginfo.dw.code, |
| 720 | sas_loginfo.dw.subcode); |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * _base_display_reply_info - |
| 725 | * @ioc: per adapter object |
| 726 | * @smid: system request message index |
| 727 | * @msix_index: MSIX table index supplied by the OS |
| 728 | * @reply: reply message frame(lower 32bit addr) |
| 729 | * |
| 730 | * Return nothing. |
| 731 | */ |
| 732 | static void |
| 733 | _base_display_reply_info(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 734 | u32 reply) |
| 735 | { |
| 736 | MPI2DefaultReply_t *mpi_reply; |
| 737 | u16 ioc_status; |
| 738 | u32 loginfo = 0; |
| 739 | |
| 740 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 741 | if (unlikely(!mpi_reply)) { |
| 742 | pr_err(MPT3SAS_FMT "mpi_reply not valid at %s:%d/%s()!\n", |
| 743 | ioc->name, __FILE__, __LINE__, __func__); |
| 744 | return; |
| 745 | } |
| 746 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus); |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 747 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 748 | if ((ioc_status & MPI2_IOCSTATUS_MASK) && |
| 749 | (ioc->logging_level & MPT_DEBUG_REPLY)) { |
| 750 | _base_sas_ioc_info(ioc , mpi_reply, |
| 751 | mpt3sas_base_get_msg_frame(ioc, smid)); |
| 752 | } |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 753 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 754 | if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) { |
| 755 | loginfo = le32_to_cpu(mpi_reply->IOCLogInfo); |
| 756 | _base_sas_log_info(ioc, loginfo); |
| 757 | } |
| 758 | |
| 759 | if (ioc_status || loginfo) { |
| 760 | ioc_status &= MPI2_IOCSTATUS_MASK; |
| 761 | mpt3sas_trigger_mpi(ioc, ioc_status, loginfo); |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | /** |
| 766 | * mpt3sas_base_done - base internal command completion routine |
| 767 | * @ioc: per adapter object |
| 768 | * @smid: system request message index |
| 769 | * @msix_index: MSIX table index supplied by the OS |
| 770 | * @reply: reply message frame(lower 32bit addr) |
| 771 | * |
| 772 | * Return 1 meaning mf should be freed from _base_interrupt |
| 773 | * 0 means the mf is freed from this function. |
| 774 | */ |
| 775 | u8 |
| 776 | mpt3sas_base_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 777 | u32 reply) |
| 778 | { |
| 779 | MPI2DefaultReply_t *mpi_reply; |
| 780 | |
| 781 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 782 | if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK) |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 783 | return mpt3sas_check_for_pending_internal_cmds(ioc, smid); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 784 | |
| 785 | if (ioc->base_cmds.status == MPT3_CMD_NOT_USED) |
| 786 | return 1; |
| 787 | |
| 788 | ioc->base_cmds.status |= MPT3_CMD_COMPLETE; |
| 789 | if (mpi_reply) { |
| 790 | ioc->base_cmds.status |= MPT3_CMD_REPLY_VALID; |
| 791 | memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 792 | } |
| 793 | ioc->base_cmds.status &= ~MPT3_CMD_PENDING; |
| 794 | |
| 795 | complete(&ioc->base_cmds.done); |
| 796 | return 1; |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * _base_async_event - main callback handler for firmware asyn events |
| 801 | * @ioc: per adapter object |
| 802 | * @msix_index: MSIX table index supplied by the OS |
| 803 | * @reply: reply message frame(lower 32bit addr) |
| 804 | * |
| 805 | * Return 1 meaning mf should be freed from _base_interrupt |
| 806 | * 0 means the mf is freed from this function. |
| 807 | */ |
| 808 | static u8 |
| 809 | _base_async_event(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, u32 reply) |
| 810 | { |
| 811 | Mpi2EventNotificationReply_t *mpi_reply; |
| 812 | Mpi2EventAckRequest_t *ack_request; |
| 813 | u16 smid; |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 814 | struct _event_ack_list *delayed_event_ack; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 815 | |
| 816 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 817 | if (!mpi_reply) |
| 818 | return 1; |
| 819 | if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION) |
| 820 | return 1; |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 821 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 822 | _base_display_event_data(ioc, mpi_reply); |
Sreekanth Reddy | af00941 | 2015-11-11 17:30:23 +0530 | [diff] [blame] | 823 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 824 | if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED)) |
| 825 | goto out; |
| 826 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 827 | if (!smid) { |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 828 | delayed_event_ack = kzalloc(sizeof(*delayed_event_ack), |
| 829 | GFP_ATOMIC); |
| 830 | if (!delayed_event_ack) |
| 831 | goto out; |
| 832 | INIT_LIST_HEAD(&delayed_event_ack->list); |
| 833 | delayed_event_ack->Event = mpi_reply->Event; |
| 834 | delayed_event_ack->EventContext = mpi_reply->EventContext; |
| 835 | list_add_tail(&delayed_event_ack->list, |
| 836 | &ioc->delayed_event_ack_list); |
| 837 | dewtprintk(ioc, pr_info(MPT3SAS_FMT |
| 838 | "DELAYED: EVENT ACK: event (0x%04x)\n", |
| 839 | ioc->name, le16_to_cpu(mpi_reply->Event))); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 840 | goto out; |
| 841 | } |
| 842 | |
| 843 | ack_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 844 | memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t)); |
| 845 | ack_request->Function = MPI2_FUNCTION_EVENT_ACK; |
| 846 | ack_request->Event = mpi_reply->Event; |
| 847 | ack_request->EventContext = mpi_reply->EventContext; |
| 848 | ack_request->VF_ID = 0; /* TODO */ |
| 849 | ack_request->VP_ID = 0; |
| 850 | mpt3sas_base_put_smid_default(ioc, smid); |
| 851 | |
| 852 | out: |
| 853 | |
| 854 | /* scsih callback handler */ |
| 855 | mpt3sas_scsih_event_callback(ioc, msix_index, reply); |
| 856 | |
| 857 | /* ctl callback handler */ |
| 858 | mpt3sas_ctl_event_callback(ioc, msix_index, reply); |
| 859 | |
| 860 | return 1; |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * _base_get_cb_idx - obtain the callback index |
| 865 | * @ioc: per adapter object |
| 866 | * @smid: system request message index |
| 867 | * |
| 868 | * Return callback index. |
| 869 | */ |
| 870 | static u8 |
| 871 | _base_get_cb_idx(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 872 | { |
| 873 | int i; |
| 874 | u8 cb_idx; |
| 875 | |
| 876 | if (smid < ioc->hi_priority_smid) { |
| 877 | i = smid - 1; |
| 878 | cb_idx = ioc->scsi_lookup[i].cb_idx; |
| 879 | } else if (smid < ioc->internal_smid) { |
| 880 | i = smid - ioc->hi_priority_smid; |
| 881 | cb_idx = ioc->hpr_lookup[i].cb_idx; |
| 882 | } else if (smid <= ioc->hba_queue_depth) { |
| 883 | i = smid - ioc->internal_smid; |
| 884 | cb_idx = ioc->internal_lookup[i].cb_idx; |
| 885 | } else |
| 886 | cb_idx = 0xFF; |
| 887 | return cb_idx; |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * _base_mask_interrupts - disable interrupts |
| 892 | * @ioc: per adapter object |
| 893 | * |
| 894 | * Disabling ResetIRQ, Reply and Doorbell Interrupts |
| 895 | * |
| 896 | * Return nothing. |
| 897 | */ |
| 898 | static void |
| 899 | _base_mask_interrupts(struct MPT3SAS_ADAPTER *ioc) |
| 900 | { |
| 901 | u32 him_register; |
| 902 | |
| 903 | ioc->mask_interrupts = 1; |
| 904 | him_register = readl(&ioc->chip->HostInterruptMask); |
| 905 | him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK; |
| 906 | writel(him_register, &ioc->chip->HostInterruptMask); |
| 907 | readl(&ioc->chip->HostInterruptMask); |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * _base_unmask_interrupts - enable interrupts |
| 912 | * @ioc: per adapter object |
| 913 | * |
| 914 | * Enabling only Reply Interrupts |
| 915 | * |
| 916 | * Return nothing. |
| 917 | */ |
| 918 | static void |
| 919 | _base_unmask_interrupts(struct MPT3SAS_ADAPTER *ioc) |
| 920 | { |
| 921 | u32 him_register; |
| 922 | |
| 923 | him_register = readl(&ioc->chip->HostInterruptMask); |
| 924 | him_register &= ~MPI2_HIM_RIM; |
| 925 | writel(him_register, &ioc->chip->HostInterruptMask); |
| 926 | ioc->mask_interrupts = 0; |
| 927 | } |
| 928 | |
| 929 | union reply_descriptor { |
| 930 | u64 word; |
| 931 | struct { |
| 932 | u32 low; |
| 933 | u32 high; |
| 934 | } u; |
| 935 | }; |
| 936 | |
| 937 | /** |
| 938 | * _base_interrupt - MPT adapter (IOC) specific interrupt handler. |
| 939 | * @irq: irq number (not used) |
| 940 | * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure |
| 941 | * @r: pt_regs pointer (not used) |
| 942 | * |
| 943 | * Return IRQ_HANDLE if processed, else IRQ_NONE. |
| 944 | */ |
| 945 | static irqreturn_t |
| 946 | _base_interrupt(int irq, void *bus_id) |
| 947 | { |
| 948 | struct adapter_reply_queue *reply_q = bus_id; |
| 949 | union reply_descriptor rd; |
| 950 | u32 completed_cmds; |
| 951 | u8 request_desript_type; |
| 952 | u16 smid; |
| 953 | u8 cb_idx; |
| 954 | u32 reply; |
| 955 | u8 msix_index = reply_q->msix_index; |
| 956 | struct MPT3SAS_ADAPTER *ioc = reply_q->ioc; |
| 957 | Mpi2ReplyDescriptorsUnion_t *rpf; |
| 958 | u8 rc; |
| 959 | |
| 960 | if (ioc->mask_interrupts) |
| 961 | return IRQ_NONE; |
| 962 | |
| 963 | if (!atomic_add_unless(&reply_q->busy, 1, 1)) |
| 964 | return IRQ_NONE; |
| 965 | |
| 966 | rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index]; |
| 967 | request_desript_type = rpf->Default.ReplyFlags |
| 968 | & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 969 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) { |
| 970 | atomic_dec(&reply_q->busy); |
| 971 | return IRQ_NONE; |
| 972 | } |
| 973 | |
| 974 | completed_cmds = 0; |
| 975 | cb_idx = 0xFF; |
| 976 | do { |
| 977 | rd.word = le64_to_cpu(rpf->Words); |
| 978 | if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX) |
| 979 | goto out; |
| 980 | reply = 0; |
| 981 | smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1); |
| 982 | if (request_desript_type == |
| 983 | MPI25_RPY_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO_SUCCESS || |
| 984 | request_desript_type == |
| 985 | MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS) { |
| 986 | cb_idx = _base_get_cb_idx(ioc, smid); |
| 987 | if ((likely(cb_idx < MPT_MAX_CALLBACKS)) && |
| 988 | (likely(mpt_callbacks[cb_idx] != NULL))) { |
| 989 | rc = mpt_callbacks[cb_idx](ioc, smid, |
| 990 | msix_index, 0); |
| 991 | if (rc) |
| 992 | mpt3sas_base_free_smid(ioc, smid); |
| 993 | } |
| 994 | } else if (request_desript_type == |
| 995 | MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) { |
| 996 | reply = le32_to_cpu( |
| 997 | rpf->AddressReply.ReplyFrameAddress); |
| 998 | if (reply > ioc->reply_dma_max_address || |
| 999 | reply < ioc->reply_dma_min_address) |
| 1000 | reply = 0; |
| 1001 | if (smid) { |
| 1002 | cb_idx = _base_get_cb_idx(ioc, smid); |
| 1003 | if ((likely(cb_idx < MPT_MAX_CALLBACKS)) && |
| 1004 | (likely(mpt_callbacks[cb_idx] != NULL))) { |
| 1005 | rc = mpt_callbacks[cb_idx](ioc, smid, |
| 1006 | msix_index, reply); |
| 1007 | if (reply) |
| 1008 | _base_display_reply_info(ioc, |
| 1009 | smid, msix_index, reply); |
| 1010 | if (rc) |
| 1011 | mpt3sas_base_free_smid(ioc, |
| 1012 | smid); |
| 1013 | } |
| 1014 | } else { |
| 1015 | _base_async_event(ioc, msix_index, reply); |
| 1016 | } |
| 1017 | |
| 1018 | /* reply free queue handling */ |
| 1019 | if (reply) { |
| 1020 | ioc->reply_free_host_index = |
| 1021 | (ioc->reply_free_host_index == |
| 1022 | (ioc->reply_free_queue_depth - 1)) ? |
| 1023 | 0 : ioc->reply_free_host_index + 1; |
| 1024 | ioc->reply_free[ioc->reply_free_host_index] = |
| 1025 | cpu_to_le32(reply); |
| 1026 | wmb(); |
| 1027 | writel(ioc->reply_free_host_index, |
| 1028 | &ioc->chip->ReplyFreeHostIndex); |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | rpf->Words = cpu_to_le64(ULLONG_MAX); |
| 1033 | reply_q->reply_post_host_index = |
| 1034 | (reply_q->reply_post_host_index == |
| 1035 | (ioc->reply_post_queue_depth - 1)) ? 0 : |
| 1036 | reply_q->reply_post_host_index + 1; |
| 1037 | request_desript_type = |
| 1038 | reply_q->reply_post_free[reply_q->reply_post_host_index]. |
| 1039 | Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK; |
| 1040 | completed_cmds++; |
| 1041 | if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) |
| 1042 | goto out; |
| 1043 | if (!reply_q->reply_post_host_index) |
| 1044 | rpf = reply_q->reply_post_free; |
| 1045 | else |
| 1046 | rpf++; |
| 1047 | } while (1); |
| 1048 | |
| 1049 | out: |
| 1050 | |
| 1051 | if (!completed_cmds) { |
| 1052 | atomic_dec(&reply_q->busy); |
| 1053 | return IRQ_NONE; |
| 1054 | } |
| 1055 | |
| 1056 | wmb(); |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 1057 | if (ioc->is_warpdrive) { |
| 1058 | writel(reply_q->reply_post_host_index, |
| 1059 | ioc->reply_post_host_index[msix_index]); |
| 1060 | atomic_dec(&reply_q->busy); |
| 1061 | return IRQ_HANDLED; |
| 1062 | } |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 1063 | |
| 1064 | /* Update Reply Post Host Index. |
| 1065 | * For those HBA's which support combined reply queue feature |
| 1066 | * 1. Get the correct Supplemental Reply Post Host Index Register. |
| 1067 | * i.e. (msix_index / 8)th entry from Supplemental Reply Post Host |
| 1068 | * Index Register address bank i.e replyPostRegisterIndex[], |
| 1069 | * 2. Then update this register with new reply host index value |
| 1070 | * in ReplyPostIndex field and the MSIxIndex field with |
| 1071 | * msix_index value reduced to a value between 0 and 7, |
| 1072 | * using a modulo 8 operation. Since each Supplemental Reply Post |
| 1073 | * Host Index Register supports 8 MSI-X vectors. |
| 1074 | * |
| 1075 | * For other HBA's just update the Reply Post Host Index register with |
| 1076 | * new reply host index value in ReplyPostIndex Field and msix_index |
| 1077 | * value in MSIxIndex field. |
| 1078 | */ |
| 1079 | if (ioc->msix96_vector) |
| 1080 | writel(reply_q->reply_post_host_index | ((msix_index & 7) << |
| 1081 | MPI2_RPHI_MSIX_INDEX_SHIFT), |
| 1082 | ioc->replyPostRegisterIndex[msix_index/8]); |
| 1083 | else |
| 1084 | writel(reply_q->reply_post_host_index | (msix_index << |
| 1085 | MPI2_RPHI_MSIX_INDEX_SHIFT), |
| 1086 | &ioc->chip->ReplyPostHostIndex); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1087 | atomic_dec(&reply_q->busy); |
| 1088 | return IRQ_HANDLED; |
| 1089 | } |
| 1090 | |
| 1091 | /** |
| 1092 | * _base_is_controller_msix_enabled - is controller support muli-reply queues |
| 1093 | * @ioc: per adapter object |
| 1094 | * |
| 1095 | */ |
| 1096 | static inline int |
| 1097 | _base_is_controller_msix_enabled(struct MPT3SAS_ADAPTER *ioc) |
| 1098 | { |
| 1099 | return (ioc->facts.IOCCapabilities & |
| 1100 | MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable; |
| 1101 | } |
| 1102 | |
| 1103 | /** |
| 1104 | * mpt3sas_base_flush_reply_queues - flushing the MSIX reply queues |
| 1105 | * @ioc: per adapter object |
| 1106 | * Context: ISR conext |
| 1107 | * |
| 1108 | * Called when a Task Management request has completed. We want |
| 1109 | * to flush the other reply queues so all the outstanding IO has been |
| 1110 | * completed back to OS before we process the TM completetion. |
| 1111 | * |
| 1112 | * Return nothing. |
| 1113 | */ |
| 1114 | void |
| 1115 | mpt3sas_base_flush_reply_queues(struct MPT3SAS_ADAPTER *ioc) |
| 1116 | { |
| 1117 | struct adapter_reply_queue *reply_q; |
| 1118 | |
| 1119 | /* If MSIX capability is turned off |
| 1120 | * then multi-queues are not enabled |
| 1121 | */ |
| 1122 | if (!_base_is_controller_msix_enabled(ioc)) |
| 1123 | return; |
| 1124 | |
| 1125 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
| 1126 | if (ioc->shost_recovery) |
| 1127 | return; |
| 1128 | /* TMs are on msix_index == 0 */ |
| 1129 | if (reply_q->msix_index == 0) |
| 1130 | continue; |
| 1131 | _base_interrupt(reply_q->vector, (void *)reply_q); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | /** |
| 1136 | * mpt3sas_base_release_callback_handler - clear interrupt callback handler |
| 1137 | * @cb_idx: callback index |
| 1138 | * |
| 1139 | * Return nothing. |
| 1140 | */ |
| 1141 | void |
| 1142 | mpt3sas_base_release_callback_handler(u8 cb_idx) |
| 1143 | { |
| 1144 | mpt_callbacks[cb_idx] = NULL; |
| 1145 | } |
| 1146 | |
| 1147 | /** |
| 1148 | * mpt3sas_base_register_callback_handler - obtain index for the interrupt callback handler |
| 1149 | * @cb_func: callback function |
| 1150 | * |
| 1151 | * Returns cb_func. |
| 1152 | */ |
| 1153 | u8 |
| 1154 | mpt3sas_base_register_callback_handler(MPT_CALLBACK cb_func) |
| 1155 | { |
| 1156 | u8 cb_idx; |
| 1157 | |
| 1158 | for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--) |
| 1159 | if (mpt_callbacks[cb_idx] == NULL) |
| 1160 | break; |
| 1161 | |
| 1162 | mpt_callbacks[cb_idx] = cb_func; |
| 1163 | return cb_idx; |
| 1164 | } |
| 1165 | |
| 1166 | /** |
| 1167 | * mpt3sas_base_initialize_callback_handler - initialize the interrupt callback handler |
| 1168 | * |
| 1169 | * Return nothing. |
| 1170 | */ |
| 1171 | void |
| 1172 | mpt3sas_base_initialize_callback_handler(void) |
| 1173 | { |
| 1174 | u8 cb_idx; |
| 1175 | |
| 1176 | for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++) |
| 1177 | mpt3sas_base_release_callback_handler(cb_idx); |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | /** |
| 1182 | * _base_build_zero_len_sge - build zero length sg entry |
| 1183 | * @ioc: per adapter object |
| 1184 | * @paddr: virtual address for SGE |
| 1185 | * |
| 1186 | * Create a zero length scatter gather entry to insure the IOCs hardware has |
| 1187 | * something to use if the target device goes brain dead and tries |
| 1188 | * to send data even when none is asked for. |
| 1189 | * |
| 1190 | * Return nothing. |
| 1191 | */ |
| 1192 | static void |
| 1193 | _base_build_zero_len_sge(struct MPT3SAS_ADAPTER *ioc, void *paddr) |
| 1194 | { |
| 1195 | u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1196 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST | |
| 1197 | MPI2_SGE_FLAGS_SIMPLE_ELEMENT) << |
| 1198 | MPI2_SGE_FLAGS_SHIFT); |
| 1199 | ioc->base_add_sg_single(paddr, flags_length, -1); |
| 1200 | } |
| 1201 | |
| 1202 | /** |
| 1203 | * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr. |
| 1204 | * @paddr: virtual address for SGE |
| 1205 | * @flags_length: SGE flags and data transfer length |
| 1206 | * @dma_addr: Physical address |
| 1207 | * |
| 1208 | * Return nothing. |
| 1209 | */ |
| 1210 | static void |
| 1211 | _base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr) |
| 1212 | { |
| 1213 | Mpi2SGESimple32_t *sgel = paddr; |
| 1214 | |
| 1215 | flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING | |
| 1216 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; |
| 1217 | sgel->FlagsLength = cpu_to_le32(flags_length); |
| 1218 | sgel->Address = cpu_to_le32(dma_addr); |
| 1219 | } |
| 1220 | |
| 1221 | |
| 1222 | /** |
| 1223 | * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr. |
| 1224 | * @paddr: virtual address for SGE |
| 1225 | * @flags_length: SGE flags and data transfer length |
| 1226 | * @dma_addr: Physical address |
| 1227 | * |
| 1228 | * Return nothing. |
| 1229 | */ |
| 1230 | static void |
| 1231 | _base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr) |
| 1232 | { |
| 1233 | Mpi2SGESimple64_t *sgel = paddr; |
| 1234 | |
| 1235 | flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING | |
| 1236 | MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT; |
| 1237 | sgel->FlagsLength = cpu_to_le32(flags_length); |
| 1238 | sgel->Address = cpu_to_le64(dma_addr); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * _base_get_chain_buffer_tracker - obtain chain tracker |
| 1243 | * @ioc: per adapter object |
| 1244 | * @smid: smid associated to an IO request |
| 1245 | * |
| 1246 | * Returns chain tracker(from ioc->free_chain_list) |
| 1247 | */ |
| 1248 | static struct chain_tracker * |
| 1249 | _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 1250 | { |
| 1251 | struct chain_tracker *chain_req; |
| 1252 | unsigned long flags; |
| 1253 | |
| 1254 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 1255 | if (list_empty(&ioc->free_chain_list)) { |
| 1256 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1257 | dfailprintk(ioc, pr_warn(MPT3SAS_FMT |
| 1258 | "chain buffers not available\n", ioc->name)); |
| 1259 | return NULL; |
| 1260 | } |
| 1261 | chain_req = list_entry(ioc->free_chain_list.next, |
| 1262 | struct chain_tracker, tracker_list); |
| 1263 | list_del_init(&chain_req->tracker_list); |
| 1264 | list_add_tail(&chain_req->tracker_list, |
| 1265 | &ioc->scsi_lookup[smid - 1].chain_list); |
| 1266 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 1267 | return chain_req; |
| 1268 | } |
| 1269 | |
| 1270 | |
| 1271 | /** |
| 1272 | * _base_build_sg - build generic sg |
| 1273 | * @ioc: per adapter object |
| 1274 | * @psge: virtual address for SGE |
| 1275 | * @data_out_dma: physical address for WRITES |
| 1276 | * @data_out_sz: data xfer size for WRITES |
| 1277 | * @data_in_dma: physical address for READS |
| 1278 | * @data_in_sz: data xfer size for READS |
| 1279 | * |
| 1280 | * Return nothing. |
| 1281 | */ |
| 1282 | static void |
| 1283 | _base_build_sg(struct MPT3SAS_ADAPTER *ioc, void *psge, |
| 1284 | dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, |
| 1285 | size_t data_in_sz) |
| 1286 | { |
| 1287 | u32 sgl_flags; |
| 1288 | |
| 1289 | if (!data_out_sz && !data_in_sz) { |
| 1290 | _base_build_zero_len_sge(ioc, psge); |
| 1291 | return; |
| 1292 | } |
| 1293 | |
| 1294 | if (data_out_sz && data_in_sz) { |
| 1295 | /* WRITE sgel first */ |
| 1296 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1297 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 1298 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1299 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1300 | data_out_sz, data_out_dma); |
| 1301 | |
| 1302 | /* incr sgel */ |
| 1303 | psge += ioc->sge_size; |
| 1304 | |
| 1305 | /* READ sgel last */ |
| 1306 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1307 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1308 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 1309 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1310 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1311 | data_in_sz, data_in_dma); |
| 1312 | } else if (data_out_sz) /* WRITE */ { |
| 1313 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1314 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1315 | MPI2_SGE_FLAGS_END_OF_LIST | MPI2_SGE_FLAGS_HOST_TO_IOC); |
| 1316 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1317 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1318 | data_out_sz, data_out_dma); |
| 1319 | } else if (data_in_sz) /* READ */ { |
| 1320 | sgl_flags = (MPI2_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1321 | MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | |
| 1322 | MPI2_SGE_FLAGS_END_OF_LIST); |
| 1323 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1324 | ioc->base_add_sg_single(psge, sgl_flags | |
| 1325 | data_in_sz, data_in_dma); |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | /* IEEE format sgls */ |
| 1330 | |
| 1331 | /** |
| 1332 | * _base_add_sg_single_ieee - add sg element for IEEE format |
| 1333 | * @paddr: virtual address for SGE |
| 1334 | * @flags: SGE flags |
| 1335 | * @chain_offset: number of 128 byte elements from start of segment |
| 1336 | * @length: data transfer length |
| 1337 | * @dma_addr: Physical address |
| 1338 | * |
| 1339 | * Return nothing. |
| 1340 | */ |
| 1341 | static void |
| 1342 | _base_add_sg_single_ieee(void *paddr, u8 flags, u8 chain_offset, u32 length, |
| 1343 | dma_addr_t dma_addr) |
| 1344 | { |
| 1345 | Mpi25IeeeSgeChain64_t *sgel = paddr; |
| 1346 | |
| 1347 | sgel->Flags = flags; |
| 1348 | sgel->NextChainOffset = chain_offset; |
| 1349 | sgel->Length = cpu_to_le32(length); |
| 1350 | sgel->Address = cpu_to_le64(dma_addr); |
| 1351 | } |
| 1352 | |
| 1353 | /** |
| 1354 | * _base_build_zero_len_sge_ieee - build zero length sg entry for IEEE format |
| 1355 | * @ioc: per adapter object |
| 1356 | * @paddr: virtual address for SGE |
| 1357 | * |
| 1358 | * Create a zero length scatter gather entry to insure the IOCs hardware has |
| 1359 | * something to use if the target device goes brain dead and tries |
| 1360 | * to send data even when none is asked for. |
| 1361 | * |
| 1362 | * Return nothing. |
| 1363 | */ |
| 1364 | static void |
| 1365 | _base_build_zero_len_sge_ieee(struct MPT3SAS_ADAPTER *ioc, void *paddr) |
| 1366 | { |
| 1367 | u8 sgl_flags = (MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1368 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR | |
| 1369 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST); |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 1370 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1371 | _base_add_sg_single_ieee(paddr, sgl_flags, 0, 0, -1); |
| 1372 | } |
| 1373 | |
| 1374 | /** |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 1375 | * _base_build_sg_scmd - main sg creation routine |
| 1376 | * @ioc: per adapter object |
| 1377 | * @scmd: scsi command |
| 1378 | * @smid: system request message index |
| 1379 | * Context: none. |
| 1380 | * |
| 1381 | * The main routine that builds scatter gather table from a given |
| 1382 | * scsi request sent via the .queuecommand main handler. |
| 1383 | * |
| 1384 | * Returns 0 success, anything else error |
| 1385 | */ |
| 1386 | static int |
| 1387 | _base_build_sg_scmd(struct MPT3SAS_ADAPTER *ioc, |
| 1388 | struct scsi_cmnd *scmd, u16 smid) |
| 1389 | { |
| 1390 | Mpi2SCSIIORequest_t *mpi_request; |
| 1391 | dma_addr_t chain_dma; |
| 1392 | struct scatterlist *sg_scmd; |
| 1393 | void *sg_local, *chain; |
| 1394 | u32 chain_offset; |
| 1395 | u32 chain_length; |
| 1396 | u32 chain_flags; |
| 1397 | int sges_left; |
| 1398 | u32 sges_in_segment; |
| 1399 | u32 sgl_flags; |
| 1400 | u32 sgl_flags_last_element; |
| 1401 | u32 sgl_flags_end_buffer; |
| 1402 | struct chain_tracker *chain_req; |
| 1403 | |
| 1404 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 1405 | |
| 1406 | /* init scatter gather flags */ |
| 1407 | sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT; |
| 1408 | if (scmd->sc_data_direction == DMA_TO_DEVICE) |
| 1409 | sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC; |
| 1410 | sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT) |
| 1411 | << MPI2_SGE_FLAGS_SHIFT; |
| 1412 | sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT | |
| 1413 | MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST) |
| 1414 | << MPI2_SGE_FLAGS_SHIFT; |
| 1415 | sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; |
| 1416 | |
| 1417 | sg_scmd = scsi_sglist(scmd); |
| 1418 | sges_left = scsi_dma_map(scmd); |
| 1419 | if (sges_left < 0) { |
| 1420 | sdev_printk(KERN_ERR, scmd->device, |
| 1421 | "pci_map_sg failed: request for %d bytes!\n", |
| 1422 | scsi_bufflen(scmd)); |
| 1423 | return -ENOMEM; |
| 1424 | } |
| 1425 | |
| 1426 | sg_local = &mpi_request->SGL; |
| 1427 | sges_in_segment = ioc->max_sges_in_main_message; |
| 1428 | if (sges_left <= sges_in_segment) |
| 1429 | goto fill_in_last_segment; |
| 1430 | |
| 1431 | mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) + |
| 1432 | (sges_in_segment * ioc->sge_size))/4; |
| 1433 | |
| 1434 | /* fill in main message segment when there is a chain following */ |
| 1435 | while (sges_in_segment) { |
| 1436 | if (sges_in_segment == 1) |
| 1437 | ioc->base_add_sg_single(sg_local, |
| 1438 | sgl_flags_last_element | sg_dma_len(sg_scmd), |
| 1439 | sg_dma_address(sg_scmd)); |
| 1440 | else |
| 1441 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1442 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1443 | sg_scmd = sg_next(sg_scmd); |
| 1444 | sg_local += ioc->sge_size; |
| 1445 | sges_left--; |
| 1446 | sges_in_segment--; |
| 1447 | } |
| 1448 | |
| 1449 | /* initializing the chain flags and pointers */ |
| 1450 | chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT; |
| 1451 | chain_req = _base_get_chain_buffer_tracker(ioc, smid); |
| 1452 | if (!chain_req) |
| 1453 | return -1; |
| 1454 | chain = chain_req->chain_buffer; |
| 1455 | chain_dma = chain_req->chain_buffer_dma; |
| 1456 | do { |
| 1457 | sges_in_segment = (sges_left <= |
| 1458 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1459 | ioc->max_sges_in_chain_message; |
| 1460 | chain_offset = (sges_left == sges_in_segment) ? |
| 1461 | 0 : (sges_in_segment * ioc->sge_size)/4; |
| 1462 | chain_length = sges_in_segment * ioc->sge_size; |
| 1463 | if (chain_offset) { |
| 1464 | chain_offset = chain_offset << |
| 1465 | MPI2_SGE_CHAIN_OFFSET_SHIFT; |
| 1466 | chain_length += ioc->sge_size; |
| 1467 | } |
| 1468 | ioc->base_add_sg_single(sg_local, chain_flags | chain_offset | |
| 1469 | chain_length, chain_dma); |
| 1470 | sg_local = chain; |
| 1471 | if (!chain_offset) |
| 1472 | goto fill_in_last_segment; |
| 1473 | |
| 1474 | /* fill in chain segments */ |
| 1475 | while (sges_in_segment) { |
| 1476 | if (sges_in_segment == 1) |
| 1477 | ioc->base_add_sg_single(sg_local, |
| 1478 | sgl_flags_last_element | |
| 1479 | sg_dma_len(sg_scmd), |
| 1480 | sg_dma_address(sg_scmd)); |
| 1481 | else |
| 1482 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1483 | sg_dma_len(sg_scmd), |
| 1484 | sg_dma_address(sg_scmd)); |
| 1485 | sg_scmd = sg_next(sg_scmd); |
| 1486 | sg_local += ioc->sge_size; |
| 1487 | sges_left--; |
| 1488 | sges_in_segment--; |
| 1489 | } |
| 1490 | |
| 1491 | chain_req = _base_get_chain_buffer_tracker(ioc, smid); |
| 1492 | if (!chain_req) |
| 1493 | return -1; |
| 1494 | chain = chain_req->chain_buffer; |
| 1495 | chain_dma = chain_req->chain_buffer_dma; |
| 1496 | } while (1); |
| 1497 | |
| 1498 | |
| 1499 | fill_in_last_segment: |
| 1500 | |
| 1501 | /* fill the last segment */ |
| 1502 | while (sges_left) { |
| 1503 | if (sges_left == 1) |
| 1504 | ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer | |
| 1505 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1506 | else |
| 1507 | ioc->base_add_sg_single(sg_local, sgl_flags | |
| 1508 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1509 | sg_scmd = sg_next(sg_scmd); |
| 1510 | sg_local += ioc->sge_size; |
| 1511 | sges_left--; |
| 1512 | } |
| 1513 | |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1518 | * _base_build_sg_scmd_ieee - main sg creation routine for IEEE format |
| 1519 | * @ioc: per adapter object |
| 1520 | * @scmd: scsi command |
| 1521 | * @smid: system request message index |
| 1522 | * Context: none. |
| 1523 | * |
| 1524 | * The main routine that builds scatter gather table from a given |
| 1525 | * scsi request sent via the .queuecommand main handler. |
| 1526 | * |
| 1527 | * Returns 0 success, anything else error |
| 1528 | */ |
| 1529 | static int |
| 1530 | _base_build_sg_scmd_ieee(struct MPT3SAS_ADAPTER *ioc, |
| 1531 | struct scsi_cmnd *scmd, u16 smid) |
| 1532 | { |
| 1533 | Mpi2SCSIIORequest_t *mpi_request; |
| 1534 | dma_addr_t chain_dma; |
| 1535 | struct scatterlist *sg_scmd; |
| 1536 | void *sg_local, *chain; |
| 1537 | u32 chain_offset; |
| 1538 | u32 chain_length; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1539 | int sges_left; |
| 1540 | u32 sges_in_segment; |
| 1541 | u8 simple_sgl_flags; |
| 1542 | u8 simple_sgl_flags_last; |
| 1543 | u8 chain_sgl_flags; |
| 1544 | struct chain_tracker *chain_req; |
| 1545 | |
| 1546 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 1547 | |
| 1548 | /* init scatter gather flags */ |
| 1549 | simple_sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1550 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 1551 | simple_sgl_flags_last = simple_sgl_flags | |
| 1552 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST; |
| 1553 | chain_sgl_flags = MPI2_IEEE_SGE_FLAGS_CHAIN_ELEMENT | |
| 1554 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 1555 | |
| 1556 | sg_scmd = scsi_sglist(scmd); |
| 1557 | sges_left = scsi_dma_map(scmd); |
Sreekanth Reddy | 62f5c74 | 2015-06-30 12:25:01 +0530 | [diff] [blame] | 1558 | if (sges_left < 0) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1559 | sdev_printk(KERN_ERR, scmd->device, |
| 1560 | "pci_map_sg failed: request for %d bytes!\n", |
| 1561 | scsi_bufflen(scmd)); |
| 1562 | return -ENOMEM; |
| 1563 | } |
| 1564 | |
| 1565 | sg_local = &mpi_request->SGL; |
| 1566 | sges_in_segment = (ioc->request_sz - |
| 1567 | offsetof(Mpi2SCSIIORequest_t, SGL))/ioc->sge_size_ieee; |
| 1568 | if (sges_left <= sges_in_segment) |
| 1569 | goto fill_in_last_segment; |
| 1570 | |
| 1571 | mpi_request->ChainOffset = (sges_in_segment - 1 /* chain element */) + |
| 1572 | (offsetof(Mpi2SCSIIORequest_t, SGL)/ioc->sge_size_ieee); |
| 1573 | |
| 1574 | /* fill in main message segment when there is a chain following */ |
| 1575 | while (sges_in_segment > 1) { |
| 1576 | _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, |
| 1577 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1578 | sg_scmd = sg_next(sg_scmd); |
| 1579 | sg_local += ioc->sge_size_ieee; |
| 1580 | sges_left--; |
| 1581 | sges_in_segment--; |
| 1582 | } |
| 1583 | |
Wei Yongjun | 25ef16d | 2012-12-12 02:26:51 +0530 | [diff] [blame] | 1584 | /* initializing the pointers */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1585 | chain_req = _base_get_chain_buffer_tracker(ioc, smid); |
| 1586 | if (!chain_req) |
| 1587 | return -1; |
| 1588 | chain = chain_req->chain_buffer; |
| 1589 | chain_dma = chain_req->chain_buffer_dma; |
| 1590 | do { |
| 1591 | sges_in_segment = (sges_left <= |
| 1592 | ioc->max_sges_in_chain_message) ? sges_left : |
| 1593 | ioc->max_sges_in_chain_message; |
| 1594 | chain_offset = (sges_left == sges_in_segment) ? |
| 1595 | 0 : sges_in_segment; |
| 1596 | chain_length = sges_in_segment * ioc->sge_size_ieee; |
| 1597 | if (chain_offset) |
| 1598 | chain_length += ioc->sge_size_ieee; |
| 1599 | _base_add_sg_single_ieee(sg_local, chain_sgl_flags, |
| 1600 | chain_offset, chain_length, chain_dma); |
| 1601 | |
| 1602 | sg_local = chain; |
| 1603 | if (!chain_offset) |
| 1604 | goto fill_in_last_segment; |
| 1605 | |
| 1606 | /* fill in chain segments */ |
| 1607 | while (sges_in_segment) { |
| 1608 | _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, |
| 1609 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1610 | sg_scmd = sg_next(sg_scmd); |
| 1611 | sg_local += ioc->sge_size_ieee; |
| 1612 | sges_left--; |
| 1613 | sges_in_segment--; |
| 1614 | } |
| 1615 | |
| 1616 | chain_req = _base_get_chain_buffer_tracker(ioc, smid); |
| 1617 | if (!chain_req) |
| 1618 | return -1; |
| 1619 | chain = chain_req->chain_buffer; |
| 1620 | chain_dma = chain_req->chain_buffer_dma; |
| 1621 | } while (1); |
| 1622 | |
| 1623 | |
| 1624 | fill_in_last_segment: |
| 1625 | |
| 1626 | /* fill the last segment */ |
Sreekanth Reddy | 62f5c74 | 2015-06-30 12:25:01 +0530 | [diff] [blame] | 1627 | while (sges_left > 0) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1628 | if (sges_left == 1) |
| 1629 | _base_add_sg_single_ieee(sg_local, |
| 1630 | simple_sgl_flags_last, 0, sg_dma_len(sg_scmd), |
| 1631 | sg_dma_address(sg_scmd)); |
| 1632 | else |
| 1633 | _base_add_sg_single_ieee(sg_local, simple_sgl_flags, 0, |
| 1634 | sg_dma_len(sg_scmd), sg_dma_address(sg_scmd)); |
| 1635 | sg_scmd = sg_next(sg_scmd); |
| 1636 | sg_local += ioc->sge_size_ieee; |
| 1637 | sges_left--; |
| 1638 | } |
| 1639 | |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
| 1643 | /** |
| 1644 | * _base_build_sg_ieee - build generic sg for IEEE format |
| 1645 | * @ioc: per adapter object |
| 1646 | * @psge: virtual address for SGE |
| 1647 | * @data_out_dma: physical address for WRITES |
| 1648 | * @data_out_sz: data xfer size for WRITES |
| 1649 | * @data_in_dma: physical address for READS |
| 1650 | * @data_in_sz: data xfer size for READS |
| 1651 | * |
| 1652 | * Return nothing. |
| 1653 | */ |
| 1654 | static void |
| 1655 | _base_build_sg_ieee(struct MPT3SAS_ADAPTER *ioc, void *psge, |
| 1656 | dma_addr_t data_out_dma, size_t data_out_sz, dma_addr_t data_in_dma, |
| 1657 | size_t data_in_sz) |
| 1658 | { |
| 1659 | u8 sgl_flags; |
| 1660 | |
| 1661 | if (!data_out_sz && !data_in_sz) { |
| 1662 | _base_build_zero_len_sge_ieee(ioc, psge); |
| 1663 | return; |
| 1664 | } |
| 1665 | |
| 1666 | if (data_out_sz && data_in_sz) { |
| 1667 | /* WRITE sgel first */ |
| 1668 | sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1669 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 1670 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_out_sz, |
| 1671 | data_out_dma); |
| 1672 | |
| 1673 | /* incr sgel */ |
| 1674 | psge += ioc->sge_size_ieee; |
| 1675 | |
| 1676 | /* READ sgel last */ |
| 1677 | sgl_flags |= MPI25_IEEE_SGE_FLAGS_END_OF_LIST; |
| 1678 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_in_sz, |
| 1679 | data_in_dma); |
| 1680 | } else if (data_out_sz) /* WRITE */ { |
| 1681 | sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1682 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST | |
| 1683 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 1684 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_out_sz, |
| 1685 | data_out_dma); |
| 1686 | } else if (data_in_sz) /* READ */ { |
| 1687 | sgl_flags = MPI2_IEEE_SGE_FLAGS_SIMPLE_ELEMENT | |
| 1688 | MPI25_IEEE_SGE_FLAGS_END_OF_LIST | |
| 1689 | MPI2_IEEE_SGE_FLAGS_SYSTEM_ADDR; |
| 1690 | _base_add_sg_single_ieee(psge, sgl_flags, 0, data_in_sz, |
| 1691 | data_in_dma); |
| 1692 | } |
| 1693 | } |
| 1694 | |
| 1695 | #define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10)) |
| 1696 | |
| 1697 | /** |
| 1698 | * _base_config_dma_addressing - set dma addressing |
| 1699 | * @ioc: per adapter object |
| 1700 | * @pdev: PCI device struct |
| 1701 | * |
| 1702 | * Returns 0 for success, non-zero for failure. |
| 1703 | */ |
| 1704 | static int |
| 1705 | _base_config_dma_addressing(struct MPT3SAS_ADAPTER *ioc, struct pci_dev *pdev) |
| 1706 | { |
| 1707 | struct sysinfo s; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1708 | u64 consistent_dma_mask; |
| 1709 | |
| 1710 | if (ioc->dma_mask) |
| 1711 | consistent_dma_mask = DMA_BIT_MASK(64); |
| 1712 | else |
| 1713 | consistent_dma_mask = DMA_BIT_MASK(32); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1714 | |
| 1715 | if (sizeof(dma_addr_t) > 4) { |
| 1716 | const uint64_t required_mask = |
| 1717 | dma_get_required_mask(&pdev->dev); |
| 1718 | if ((required_mask > DMA_BIT_MASK(32)) && |
| 1719 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1720 | !pci_set_consistent_dma_mask(pdev, consistent_dma_mask)) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1721 | ioc->base_add_sg_single = &_base_add_sg_single_64; |
| 1722 | ioc->sge_size = sizeof(Mpi2SGESimple64_t); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1723 | ioc->dma_mask = 64; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1724 | goto out; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) |
| 1729 | && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) { |
| 1730 | ioc->base_add_sg_single = &_base_add_sg_single_32; |
| 1731 | ioc->sge_size = sizeof(Mpi2SGESimple32_t); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1732 | ioc->dma_mask = 32; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1733 | } else |
| 1734 | return -ENODEV; |
| 1735 | |
| 1736 | out: |
| 1737 | si_meminfo(&s); |
| 1738 | pr_info(MPT3SAS_FMT |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1739 | "%d BIT PCI BUS DMA ADDRESSING SUPPORTED, total mem (%ld kB)\n", |
| 1740 | ioc->name, ioc->dma_mask, convert_to_kb(s.totalram)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1741 | |
| 1742 | return 0; |
| 1743 | } |
| 1744 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1745 | static int |
| 1746 | _base_change_consistent_dma_mask(struct MPT3SAS_ADAPTER *ioc, |
| 1747 | struct pci_dev *pdev) |
| 1748 | { |
| 1749 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
| 1750 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) |
| 1751 | return -ENODEV; |
| 1752 | } |
| 1753 | return 0; |
| 1754 | } |
| 1755 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1756 | /** |
| 1757 | * _base_check_enable_msix - checks MSIX capabable. |
| 1758 | * @ioc: per adapter object |
| 1759 | * |
| 1760 | * Check to see if card is capable of MSIX, and set number |
| 1761 | * of available msix vectors |
| 1762 | */ |
| 1763 | static int |
| 1764 | _base_check_enable_msix(struct MPT3SAS_ADAPTER *ioc) |
| 1765 | { |
| 1766 | int base; |
| 1767 | u16 message_control; |
| 1768 | |
Sreekanth Reddy | 4208117 | 2015-11-11 17:30:26 +0530 | [diff] [blame] | 1769 | /* Check whether controller SAS2008 B0 controller, |
| 1770 | * if it is SAS2008 B0 controller use IO-APIC instead of MSIX |
| 1771 | */ |
| 1772 | if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 && |
| 1773 | ioc->pdev->revision == SAS2_PCI_DEVICE_B0_REVISION) { |
| 1774 | return -EINVAL; |
| 1775 | } |
| 1776 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1777 | base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX); |
| 1778 | if (!base) { |
| 1779 | dfailprintk(ioc, pr_info(MPT3SAS_FMT "msix not supported\n", |
| 1780 | ioc->name)); |
| 1781 | return -EINVAL; |
| 1782 | } |
| 1783 | |
| 1784 | /* get msix vector count */ |
Sreekanth Reddy | 4208117 | 2015-11-11 17:30:26 +0530 | [diff] [blame] | 1785 | /* NUMA_IO not supported for older controllers */ |
| 1786 | if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 || |
| 1787 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 || |
| 1788 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 || |
| 1789 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 || |
| 1790 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 || |
| 1791 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 || |
| 1792 | ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2) |
| 1793 | ioc->msix_vector_count = 1; |
| 1794 | else { |
| 1795 | pci_read_config_word(ioc->pdev, base + 2, &message_control); |
| 1796 | ioc->msix_vector_count = (message_control & 0x3FF) + 1; |
| 1797 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1798 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 1799 | "msix is supported, vector_count(%d)\n", |
| 1800 | ioc->name, ioc->msix_vector_count)); |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
| 1804 | /** |
| 1805 | * _base_free_irq - free irq |
| 1806 | * @ioc: per adapter object |
| 1807 | * |
| 1808 | * Freeing respective reply_queue from the list. |
| 1809 | */ |
| 1810 | static void |
| 1811 | _base_free_irq(struct MPT3SAS_ADAPTER *ioc) |
| 1812 | { |
| 1813 | struct adapter_reply_queue *reply_q, *next; |
| 1814 | |
| 1815 | if (list_empty(&ioc->reply_queue_list)) |
| 1816 | return; |
| 1817 | |
| 1818 | list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) { |
| 1819 | list_del(&reply_q->list); |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1820 | if (smp_affinity_enable) { |
| 1821 | irq_set_affinity_hint(reply_q->vector, NULL); |
| 1822 | free_cpumask_var(reply_q->affinity_hint); |
| 1823 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1824 | free_irq(reply_q->vector, reply_q); |
| 1825 | kfree(reply_q); |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * _base_request_irq - request irq |
| 1831 | * @ioc: per adapter object |
| 1832 | * @index: msix index into vector table |
| 1833 | * @vector: irq vector |
| 1834 | * |
| 1835 | * Inserting respective reply_queue into the list. |
| 1836 | */ |
| 1837 | static int |
| 1838 | _base_request_irq(struct MPT3SAS_ADAPTER *ioc, u8 index, u32 vector) |
| 1839 | { |
| 1840 | struct adapter_reply_queue *reply_q; |
| 1841 | int r; |
| 1842 | |
| 1843 | reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL); |
| 1844 | if (!reply_q) { |
| 1845 | pr_err(MPT3SAS_FMT "unable to allocate memory %d!\n", |
| 1846 | ioc->name, (int)sizeof(struct adapter_reply_queue)); |
| 1847 | return -ENOMEM; |
| 1848 | } |
| 1849 | reply_q->ioc = ioc; |
| 1850 | reply_q->msix_index = index; |
| 1851 | reply_q->vector = vector; |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1852 | |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1853 | if (smp_affinity_enable) { |
| 1854 | if (!zalloc_cpumask_var(&reply_q->affinity_hint, GFP_KERNEL)) { |
| 1855 | kfree(reply_q); |
| 1856 | return -ENOMEM; |
| 1857 | } |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1858 | } |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1859 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1860 | atomic_set(&reply_q->busy, 0); |
| 1861 | if (ioc->msix_enable) |
| 1862 | snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d", |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 1863 | ioc->driver_name, ioc->id, index); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1864 | else |
| 1865 | snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d", |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 1866 | ioc->driver_name, ioc->id); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1867 | r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name, |
| 1868 | reply_q); |
| 1869 | if (r) { |
| 1870 | pr_err(MPT3SAS_FMT "unable to allocate interrupt %d!\n", |
| 1871 | reply_q->name, vector); |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1872 | free_cpumask_var(reply_q->affinity_hint); |
Suganath prabu Subramani | da3cec2 | 2016-02-11 15:02:55 +0530 | [diff] [blame] | 1873 | kfree(reply_q); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1874 | return -EBUSY; |
| 1875 | } |
| 1876 | |
| 1877 | INIT_LIST_HEAD(&reply_q->list); |
| 1878 | list_add_tail(&reply_q->list, &ioc->reply_queue_list); |
| 1879 | return 0; |
| 1880 | } |
| 1881 | |
| 1882 | /** |
| 1883 | * _base_assign_reply_queues - assigning msix index for each cpu |
| 1884 | * @ioc: per adapter object |
| 1885 | * |
| 1886 | * The enduser would need to set the affinity via /proc/irq/#/smp_affinity |
| 1887 | * |
| 1888 | * It would nice if we could call irq_set_affinity, however it is not |
| 1889 | * an exported symbol |
| 1890 | */ |
| 1891 | static void |
| 1892 | _base_assign_reply_queues(struct MPT3SAS_ADAPTER *ioc) |
| 1893 | { |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 1894 | unsigned int cpu, nr_cpus, nr_msix, index = 0; |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1895 | struct adapter_reply_queue *reply_q; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1896 | |
| 1897 | if (!_base_is_controller_msix_enabled(ioc)) |
| 1898 | return; |
| 1899 | |
| 1900 | memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz); |
| 1901 | |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 1902 | nr_cpus = num_online_cpus(); |
| 1903 | nr_msix = ioc->reply_queue_count = min(ioc->reply_queue_count, |
| 1904 | ioc->facts.MaxMSIxVectors); |
| 1905 | if (!nr_msix) |
| 1906 | return; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1907 | |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 1908 | cpu = cpumask_first(cpu_online_mask); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1909 | |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1910 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
| 1911 | |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 1912 | unsigned int i, group = nr_cpus / nr_msix; |
| 1913 | |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1914 | if (cpu >= nr_cpus) |
| 1915 | break; |
| 1916 | |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 1917 | if (index < nr_cpus % nr_msix) |
| 1918 | group++; |
| 1919 | |
| 1920 | for (i = 0 ; i < group ; i++) { |
| 1921 | ioc->cpu_msix_table[cpu] = index; |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1922 | if (smp_affinity_enable) |
| 1923 | cpumask_or(reply_q->affinity_hint, |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1924 | reply_q->affinity_hint, get_cpu_mask(cpu)); |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 1925 | cpu = cpumask_next(cpu, cpu_online_mask); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1926 | } |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1927 | if (smp_affinity_enable) |
| 1928 | if (irq_set_affinity_hint(reply_q->vector, |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1929 | reply_q->affinity_hint)) |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1930 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 1931 | "Err setting affinity hint to irq vector %d\n", |
| 1932 | ioc->name, reply_q->vector)); |
Martin K. Petersen | 91b265b | 2014-01-03 19:16:56 -0500 | [diff] [blame] | 1933 | index++; |
Sreekanth Reddy | 14b3114 | 2015-01-12 11:39:03 +0530 | [diff] [blame] | 1934 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | /** |
| 1938 | * _base_disable_msix - disables msix |
| 1939 | * @ioc: per adapter object |
| 1940 | * |
| 1941 | */ |
| 1942 | static void |
| 1943 | _base_disable_msix(struct MPT3SAS_ADAPTER *ioc) |
| 1944 | { |
| 1945 | if (!ioc->msix_enable) |
| 1946 | return; |
| 1947 | pci_disable_msix(ioc->pdev); |
| 1948 | ioc->msix_enable = 0; |
| 1949 | } |
| 1950 | |
| 1951 | /** |
| 1952 | * _base_enable_msix - enables msix, failback to io_apic |
| 1953 | * @ioc: per adapter object |
| 1954 | * |
| 1955 | */ |
| 1956 | static int |
| 1957 | _base_enable_msix(struct MPT3SAS_ADAPTER *ioc) |
| 1958 | { |
| 1959 | struct msix_entry *entries, *a; |
| 1960 | int r; |
| 1961 | int i; |
| 1962 | u8 try_msix = 0; |
| 1963 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1964 | if (msix_disable == -1 || msix_disable == 0) |
| 1965 | try_msix = 1; |
| 1966 | |
| 1967 | if (!try_msix) |
| 1968 | goto try_ioapic; |
| 1969 | |
| 1970 | if (_base_check_enable_msix(ioc) != 0) |
| 1971 | goto try_ioapic; |
| 1972 | |
| 1973 | ioc->reply_queue_count = min_t(int, ioc->cpu_count, |
| 1974 | ioc->msix_vector_count); |
| 1975 | |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 1976 | printk(MPT3SAS_FMT "MSI-X vectors supported: %d, no of cores" |
| 1977 | ": %d, max_msix_vectors: %d\n", ioc->name, ioc->msix_vector_count, |
| 1978 | ioc->cpu_count, max_msix_vectors); |
| 1979 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1980 | if (!ioc->rdpq_array_enable && max_msix_vectors == -1) |
| 1981 | max_msix_vectors = 8; |
| 1982 | |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 1983 | if (max_msix_vectors > 0) { |
| 1984 | ioc->reply_queue_count = min_t(int, max_msix_vectors, |
| 1985 | ioc->reply_queue_count); |
| 1986 | ioc->msix_vector_count = ioc->reply_queue_count; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 1987 | } else if (max_msix_vectors == 0) |
| 1988 | goto try_ioapic; |
Sreekanth Reddy | 9c50006 | 2013-08-14 18:23:20 +0530 | [diff] [blame] | 1989 | |
Suganath Prabu Subramani | 6403830 | 2016-02-08 22:13:39 +0530 | [diff] [blame] | 1990 | if (ioc->msix_vector_count < ioc->cpu_count) |
| 1991 | smp_affinity_enable = 0; |
| 1992 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 1993 | entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry), |
| 1994 | GFP_KERNEL); |
| 1995 | if (!entries) { |
| 1996 | dfailprintk(ioc, pr_info(MPT3SAS_FMT |
| 1997 | "kcalloc failed @ at %s:%d/%s() !!!\n", |
| 1998 | ioc->name, __FILE__, __LINE__, __func__)); |
| 1999 | goto try_ioapic; |
| 2000 | } |
| 2001 | |
| 2002 | for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) |
| 2003 | a->entry = i; |
| 2004 | |
Alexander Gordeev | 6bfa690 | 2014-08-18 08:01:46 +0200 | [diff] [blame] | 2005 | r = pci_enable_msix_exact(ioc->pdev, entries, ioc->reply_queue_count); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2006 | if (r) { |
| 2007 | dfailprintk(ioc, pr_info(MPT3SAS_FMT |
Alexander Gordeev | 6bfa690 | 2014-08-18 08:01:46 +0200 | [diff] [blame] | 2008 | "pci_enable_msix_exact failed (r=%d) !!!\n", |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2009 | ioc->name, r)); |
| 2010 | kfree(entries); |
| 2011 | goto try_ioapic; |
| 2012 | } |
| 2013 | |
| 2014 | ioc->msix_enable = 1; |
| 2015 | for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) { |
| 2016 | r = _base_request_irq(ioc, i, a->vector); |
| 2017 | if (r) { |
| 2018 | _base_free_irq(ioc); |
| 2019 | _base_disable_msix(ioc); |
| 2020 | kfree(entries); |
| 2021 | goto try_ioapic; |
| 2022 | } |
| 2023 | } |
| 2024 | |
| 2025 | kfree(entries); |
| 2026 | return 0; |
| 2027 | |
| 2028 | /* failback to io_apic interrupt routing */ |
| 2029 | try_ioapic: |
| 2030 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2031 | ioc->reply_queue_count = 1; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2032 | r = _base_request_irq(ioc, 0, ioc->pdev->irq); |
| 2033 | |
| 2034 | return r; |
| 2035 | } |
| 2036 | |
| 2037 | /** |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2038 | * mpt3sas_base_unmap_resources - free controller resources |
| 2039 | * @ioc: per adapter object |
| 2040 | */ |
| 2041 | void |
| 2042 | mpt3sas_base_unmap_resources(struct MPT3SAS_ADAPTER *ioc) |
| 2043 | { |
| 2044 | struct pci_dev *pdev = ioc->pdev; |
| 2045 | |
| 2046 | dexitprintk(ioc, printk(MPT3SAS_FMT "%s\n", |
| 2047 | ioc->name, __func__)); |
| 2048 | |
| 2049 | _base_free_irq(ioc); |
| 2050 | _base_disable_msix(ioc); |
| 2051 | |
Tomas Henzl | 5f985d8 | 2015-12-23 14:21:47 +0100 | [diff] [blame] | 2052 | if (ioc->msix96_vector) { |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2053 | kfree(ioc->replyPostRegisterIndex); |
Tomas Henzl | 5f985d8 | 2015-12-23 14:21:47 +0100 | [diff] [blame] | 2054 | ioc->replyPostRegisterIndex = NULL; |
| 2055 | } |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2056 | |
| 2057 | if (ioc->chip_phys) { |
| 2058 | iounmap(ioc->chip); |
| 2059 | ioc->chip_phys = 0; |
| 2060 | } |
| 2061 | |
| 2062 | if (pci_is_enabled(pdev)) { |
| 2063 | pci_release_selected_regions(ioc->pdev, ioc->bars); |
| 2064 | pci_disable_pcie_error_reporting(pdev); |
| 2065 | pci_disable_device(pdev); |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2070 | * mpt3sas_base_map_resources - map in controller resources (io/irq/memap) |
| 2071 | * @ioc: per adapter object |
| 2072 | * |
| 2073 | * Returns 0 for success, non-zero for failure. |
| 2074 | */ |
| 2075 | int |
| 2076 | mpt3sas_base_map_resources(struct MPT3SAS_ADAPTER *ioc) |
| 2077 | { |
| 2078 | struct pci_dev *pdev = ioc->pdev; |
| 2079 | u32 memap_sz; |
| 2080 | u32 pio_sz; |
| 2081 | int i, r = 0; |
| 2082 | u64 pio_chip = 0; |
| 2083 | u64 chip_phys = 0; |
| 2084 | struct adapter_reply_queue *reply_q; |
| 2085 | |
| 2086 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", |
| 2087 | ioc->name, __func__)); |
| 2088 | |
| 2089 | ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 2090 | if (pci_enable_device_mem(pdev)) { |
| 2091 | pr_warn(MPT3SAS_FMT "pci_enable_device_mem: failed\n", |
| 2092 | ioc->name); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 2093 | ioc->bars = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2094 | return -ENODEV; |
| 2095 | } |
| 2096 | |
| 2097 | |
| 2098 | if (pci_request_selected_regions(pdev, ioc->bars, |
Sreekanth Reddy | c84b06a | 2015-11-11 17:30:35 +0530 | [diff] [blame] | 2099 | ioc->driver_name)) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2100 | pr_warn(MPT3SAS_FMT "pci_request_selected_regions: failed\n", |
| 2101 | ioc->name); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 2102 | ioc->bars = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2103 | r = -ENODEV; |
| 2104 | goto out_fail; |
| 2105 | } |
| 2106 | |
| 2107 | /* AER (Advanced Error Reporting) hooks */ |
| 2108 | pci_enable_pcie_error_reporting(pdev); |
| 2109 | |
| 2110 | pci_set_master(pdev); |
| 2111 | |
| 2112 | |
| 2113 | if (_base_config_dma_addressing(ioc, pdev) != 0) { |
| 2114 | pr_warn(MPT3SAS_FMT "no suitable DMA mask for %s\n", |
| 2115 | ioc->name, pci_name(pdev)); |
| 2116 | r = -ENODEV; |
| 2117 | goto out_fail; |
| 2118 | } |
| 2119 | |
Sreekanth Reddy | 5aeeb78 | 2015-07-15 10:19:56 +0530 | [diff] [blame] | 2120 | for (i = 0, memap_sz = 0, pio_sz = 0; (i < DEVICE_COUNT_RESOURCE) && |
| 2121 | (!memap_sz || !pio_sz); i++) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2122 | if (pci_resource_flags(pdev, i) & IORESOURCE_IO) { |
| 2123 | if (pio_sz) |
| 2124 | continue; |
| 2125 | pio_chip = (u64)pci_resource_start(pdev, i); |
| 2126 | pio_sz = pci_resource_len(pdev, i); |
| 2127 | } else if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { |
| 2128 | if (memap_sz) |
| 2129 | continue; |
| 2130 | ioc->chip_phys = pci_resource_start(pdev, i); |
| 2131 | chip_phys = (u64)ioc->chip_phys; |
| 2132 | memap_sz = pci_resource_len(pdev, i); |
| 2133 | ioc->chip = ioremap(ioc->chip_phys, memap_sz); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | |
Sreekanth Reddy | 5aeeb78 | 2015-07-15 10:19:56 +0530 | [diff] [blame] | 2137 | if (ioc->chip == NULL) { |
| 2138 | pr_err(MPT3SAS_FMT "unable to map adapter memory! " |
| 2139 | " or resource not found\n", ioc->name); |
| 2140 | r = -EINVAL; |
| 2141 | goto out_fail; |
| 2142 | } |
| 2143 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2144 | _base_mask_interrupts(ioc); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 2145 | |
| 2146 | r = _base_get_ioc_facts(ioc, CAN_SLEEP); |
| 2147 | if (r) |
| 2148 | goto out_fail; |
| 2149 | |
| 2150 | if (!ioc->rdpq_array_enable_assigned) { |
| 2151 | ioc->rdpq_array_enable = ioc->rdpq_array_capable; |
| 2152 | ioc->rdpq_array_enable_assigned = 1; |
| 2153 | } |
| 2154 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2155 | r = _base_enable_msix(ioc); |
| 2156 | if (r) |
| 2157 | goto out_fail; |
| 2158 | |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 2159 | /* Use the Combined reply queue feature only for SAS3 C0 & higher |
| 2160 | * revision HBAs and also only when reply queue count is greater than 8 |
| 2161 | */ |
| 2162 | if (ioc->msix96_vector && ioc->reply_queue_count > 8) { |
| 2163 | /* Determine the Supplemental Reply Post Host Index Registers |
| 2164 | * Addresse. Supplemental Reply Post Host Index Registers |
| 2165 | * starts at offset MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET and |
| 2166 | * each register is at offset bytes of |
| 2167 | * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET from previous one. |
| 2168 | */ |
| 2169 | ioc->replyPostRegisterIndex = kcalloc( |
| 2170 | MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT, |
| 2171 | sizeof(resource_size_t *), GFP_KERNEL); |
| 2172 | if (!ioc->replyPostRegisterIndex) { |
| 2173 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 2174 | "allocation for reply Post Register Index failed!!!\n", |
| 2175 | ioc->name)); |
| 2176 | r = -ENOMEM; |
| 2177 | goto out_fail; |
| 2178 | } |
| 2179 | |
| 2180 | for (i = 0; i < MPT3_SUP_REPLY_POST_HOST_INDEX_REG_COUNT; i++) { |
| 2181 | ioc->replyPostRegisterIndex[i] = (resource_size_t *) |
| 2182 | ((u8 *)&ioc->chip->Doorbell + |
| 2183 | MPI25_SUP_REPLY_POST_HOST_INDEX_OFFSET + |
| 2184 | (i * MPT3_SUP_REPLY_POST_HOST_INDEX_REG_OFFSET)); |
| 2185 | } |
| 2186 | } else |
| 2187 | ioc->msix96_vector = 0; |
| 2188 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2189 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) |
| 2190 | pr_info(MPT3SAS_FMT "%s: IRQ %d\n", |
| 2191 | reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" : |
| 2192 | "IO-APIC enabled"), reply_q->vector); |
| 2193 | |
| 2194 | pr_info(MPT3SAS_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n", |
| 2195 | ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz); |
| 2196 | pr_info(MPT3SAS_FMT "ioport(0x%016llx), size(%d)\n", |
| 2197 | ioc->name, (unsigned long long)pio_chip, pio_sz); |
| 2198 | |
| 2199 | /* Save PCI configuration state for recovery from PCI AER/EEH errors */ |
| 2200 | pci_save_state(pdev); |
| 2201 | return 0; |
| 2202 | |
| 2203 | out_fail: |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 2204 | mpt3sas_base_unmap_resources(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2205 | return r; |
| 2206 | } |
| 2207 | |
| 2208 | /** |
| 2209 | * mpt3sas_base_get_msg_frame - obtain request mf pointer |
| 2210 | * @ioc: per adapter object |
| 2211 | * @smid: system request message index(smid zero is invalid) |
| 2212 | * |
| 2213 | * Returns virt pointer to message frame. |
| 2214 | */ |
| 2215 | void * |
| 2216 | mpt3sas_base_get_msg_frame(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 2217 | { |
| 2218 | return (void *)(ioc->request + (smid * ioc->request_sz)); |
| 2219 | } |
| 2220 | |
| 2221 | /** |
| 2222 | * mpt3sas_base_get_sense_buffer - obtain a sense buffer virt addr |
| 2223 | * @ioc: per adapter object |
| 2224 | * @smid: system request message index |
| 2225 | * |
| 2226 | * Returns virt pointer to sense buffer. |
| 2227 | */ |
| 2228 | void * |
| 2229 | mpt3sas_base_get_sense_buffer(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 2230 | { |
| 2231 | return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE)); |
| 2232 | } |
| 2233 | |
| 2234 | /** |
| 2235 | * mpt3sas_base_get_sense_buffer_dma - obtain a sense buffer dma addr |
| 2236 | * @ioc: per adapter object |
| 2237 | * @smid: system request message index |
| 2238 | * |
| 2239 | * Returns phys pointer to the low 32bit address of the sense buffer. |
| 2240 | */ |
| 2241 | __le32 |
| 2242 | mpt3sas_base_get_sense_buffer_dma(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 2243 | { |
| 2244 | return cpu_to_le32(ioc->sense_dma + ((smid - 1) * |
| 2245 | SCSI_SENSE_BUFFERSIZE)); |
| 2246 | } |
| 2247 | |
| 2248 | /** |
| 2249 | * mpt3sas_base_get_reply_virt_addr - obtain reply frames virt address |
| 2250 | * @ioc: per adapter object |
| 2251 | * @phys_addr: lower 32 physical addr of the reply |
| 2252 | * |
| 2253 | * Converts 32bit lower physical addr into a virt address. |
| 2254 | */ |
| 2255 | void * |
| 2256 | mpt3sas_base_get_reply_virt_addr(struct MPT3SAS_ADAPTER *ioc, u32 phys_addr) |
| 2257 | { |
| 2258 | if (!phys_addr) |
| 2259 | return NULL; |
| 2260 | return ioc->reply + (phys_addr - (u32)ioc->reply_dma); |
| 2261 | } |
| 2262 | |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 2263 | static inline u8 |
| 2264 | _base_get_msix_index(struct MPT3SAS_ADAPTER *ioc) |
| 2265 | { |
| 2266 | return ioc->cpu_msix_table[raw_smp_processor_id()]; |
| 2267 | } |
| 2268 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2269 | /** |
| 2270 | * mpt3sas_base_get_smid - obtain a free smid from internal queue |
| 2271 | * @ioc: per adapter object |
| 2272 | * @cb_idx: callback index |
| 2273 | * |
| 2274 | * Returns smid (zero is invalid) |
| 2275 | */ |
| 2276 | u16 |
| 2277 | mpt3sas_base_get_smid(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx) |
| 2278 | { |
| 2279 | unsigned long flags; |
| 2280 | struct request_tracker *request; |
| 2281 | u16 smid; |
| 2282 | |
| 2283 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 2284 | if (list_empty(&ioc->internal_free_list)) { |
| 2285 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2286 | pr_err(MPT3SAS_FMT "%s: smid not available\n", |
| 2287 | ioc->name, __func__); |
| 2288 | return 0; |
| 2289 | } |
| 2290 | |
| 2291 | request = list_entry(ioc->internal_free_list.next, |
| 2292 | struct request_tracker, tracker_list); |
| 2293 | request->cb_idx = cb_idx; |
| 2294 | smid = request->smid; |
| 2295 | list_del(&request->tracker_list); |
| 2296 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2297 | return smid; |
| 2298 | } |
| 2299 | |
| 2300 | /** |
| 2301 | * mpt3sas_base_get_smid_scsiio - obtain a free smid from scsiio queue |
| 2302 | * @ioc: per adapter object |
| 2303 | * @cb_idx: callback index |
| 2304 | * @scmd: pointer to scsi command object |
| 2305 | * |
| 2306 | * Returns smid (zero is invalid) |
| 2307 | */ |
| 2308 | u16 |
| 2309 | mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx, |
| 2310 | struct scsi_cmnd *scmd) |
| 2311 | { |
| 2312 | unsigned long flags; |
| 2313 | struct scsiio_tracker *request; |
| 2314 | u16 smid; |
| 2315 | |
| 2316 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 2317 | if (list_empty(&ioc->free_list)) { |
| 2318 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2319 | pr_err(MPT3SAS_FMT "%s: smid not available\n", |
| 2320 | ioc->name, __func__); |
| 2321 | return 0; |
| 2322 | } |
| 2323 | |
| 2324 | request = list_entry(ioc->free_list.next, |
| 2325 | struct scsiio_tracker, tracker_list); |
| 2326 | request->scmd = scmd; |
| 2327 | request->cb_idx = cb_idx; |
| 2328 | smid = request->smid; |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 2329 | request->msix_io = _base_get_msix_index(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2330 | list_del(&request->tracker_list); |
| 2331 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2332 | return smid; |
| 2333 | } |
| 2334 | |
| 2335 | /** |
| 2336 | * mpt3sas_base_get_smid_hpr - obtain a free smid from hi-priority queue |
| 2337 | * @ioc: per adapter object |
| 2338 | * @cb_idx: callback index |
| 2339 | * |
| 2340 | * Returns smid (zero is invalid) |
| 2341 | */ |
| 2342 | u16 |
| 2343 | mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx) |
| 2344 | { |
| 2345 | unsigned long flags; |
| 2346 | struct request_tracker *request; |
| 2347 | u16 smid; |
| 2348 | |
| 2349 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 2350 | if (list_empty(&ioc->hpr_free_list)) { |
| 2351 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2352 | return 0; |
| 2353 | } |
| 2354 | |
| 2355 | request = list_entry(ioc->hpr_free_list.next, |
| 2356 | struct request_tracker, tracker_list); |
| 2357 | request->cb_idx = cb_idx; |
| 2358 | smid = request->smid; |
| 2359 | list_del(&request->tracker_list); |
| 2360 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2361 | return smid; |
| 2362 | } |
| 2363 | |
| 2364 | /** |
| 2365 | * mpt3sas_base_free_smid - put smid back on free_list |
| 2366 | * @ioc: per adapter object |
| 2367 | * @smid: system request message index |
| 2368 | * |
| 2369 | * Return nothing. |
| 2370 | */ |
| 2371 | void |
| 2372 | mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 2373 | { |
| 2374 | unsigned long flags; |
| 2375 | int i; |
| 2376 | struct chain_tracker *chain_req, *next; |
| 2377 | |
| 2378 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 2379 | if (smid < ioc->hi_priority_smid) { |
| 2380 | /* scsiio queue */ |
| 2381 | i = smid - 1; |
| 2382 | if (!list_empty(&ioc->scsi_lookup[i].chain_list)) { |
| 2383 | list_for_each_entry_safe(chain_req, next, |
| 2384 | &ioc->scsi_lookup[i].chain_list, tracker_list) { |
| 2385 | list_del_init(&chain_req->tracker_list); |
| 2386 | list_add(&chain_req->tracker_list, |
| 2387 | &ioc->free_chain_list); |
| 2388 | } |
| 2389 | } |
| 2390 | ioc->scsi_lookup[i].cb_idx = 0xFF; |
| 2391 | ioc->scsi_lookup[i].scmd = NULL; |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 2392 | ioc->scsi_lookup[i].direct_io = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2393 | list_add(&ioc->scsi_lookup[i].tracker_list, &ioc->free_list); |
| 2394 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2395 | |
| 2396 | /* |
| 2397 | * See _wait_for_commands_to_complete() call with regards |
| 2398 | * to this code. |
| 2399 | */ |
| 2400 | if (ioc->shost_recovery && ioc->pending_io_count) { |
| 2401 | if (ioc->pending_io_count == 1) |
| 2402 | wake_up(&ioc->reset_wq); |
| 2403 | ioc->pending_io_count--; |
| 2404 | } |
| 2405 | return; |
| 2406 | } else if (smid < ioc->internal_smid) { |
| 2407 | /* hi-priority */ |
| 2408 | i = smid - ioc->hi_priority_smid; |
| 2409 | ioc->hpr_lookup[i].cb_idx = 0xFF; |
| 2410 | list_add(&ioc->hpr_lookup[i].tracker_list, &ioc->hpr_free_list); |
| 2411 | } else if (smid <= ioc->hba_queue_depth) { |
| 2412 | /* internal queue */ |
| 2413 | i = smid - ioc->internal_smid; |
| 2414 | ioc->internal_lookup[i].cb_idx = 0xFF; |
| 2415 | list_add(&ioc->internal_lookup[i].tracker_list, |
| 2416 | &ioc->internal_free_list); |
| 2417 | } |
| 2418 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 2419 | } |
| 2420 | |
| 2421 | /** |
| 2422 | * _base_writeq - 64 bit write to MMIO |
| 2423 | * @ioc: per adapter object |
| 2424 | * @b: data payload |
| 2425 | * @addr: address in MMIO space |
| 2426 | * @writeq_lock: spin lock |
| 2427 | * |
| 2428 | * Glue for handling an atomic 64 bit word to MMIO. This special handling takes |
| 2429 | * care of 32 bit environment where its not quarenteed to send the entire word |
| 2430 | * in one transfer. |
| 2431 | */ |
| 2432 | #if defined(writeq) && defined(CONFIG_64BIT) |
| 2433 | static inline void |
| 2434 | _base_writeq(__u64 b, volatile void __iomem *addr, spinlock_t *writeq_lock) |
| 2435 | { |
| 2436 | writeq(cpu_to_le64(b), addr); |
| 2437 | } |
| 2438 | #else |
| 2439 | static inline void |
| 2440 | _base_writeq(__u64 b, volatile void __iomem *addr, spinlock_t *writeq_lock) |
| 2441 | { |
| 2442 | unsigned long flags; |
| 2443 | __u64 data_out = cpu_to_le64(b); |
| 2444 | |
| 2445 | spin_lock_irqsave(writeq_lock, flags); |
| 2446 | writel((u32)(data_out), addr); |
| 2447 | writel((u32)(data_out >> 32), (addr + 4)); |
| 2448 | spin_unlock_irqrestore(writeq_lock, flags); |
| 2449 | } |
| 2450 | #endif |
| 2451 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2452 | /** |
| 2453 | * mpt3sas_base_put_smid_scsi_io - send SCSI_IO request to firmware |
| 2454 | * @ioc: per adapter object |
| 2455 | * @smid: system request message index |
| 2456 | * @handle: device handle |
| 2457 | * |
| 2458 | * Return nothing. |
| 2459 | */ |
| 2460 | void |
| 2461 | mpt3sas_base_put_smid_scsi_io(struct MPT3SAS_ADAPTER *ioc, u16 smid, u16 handle) |
| 2462 | { |
| 2463 | Mpi2RequestDescriptorUnion_t descriptor; |
| 2464 | u64 *request = (u64 *)&descriptor; |
| 2465 | |
| 2466 | |
| 2467 | descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO; |
| 2468 | descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc); |
| 2469 | descriptor.SCSIIO.SMID = cpu_to_le16(smid); |
| 2470 | descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); |
| 2471 | descriptor.SCSIIO.LMID = 0; |
| 2472 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 2473 | &ioc->scsi_lookup_lock); |
| 2474 | } |
| 2475 | |
| 2476 | /** |
| 2477 | * mpt3sas_base_put_smid_fast_path - send fast path request to firmware |
| 2478 | * @ioc: per adapter object |
| 2479 | * @smid: system request message index |
| 2480 | * @handle: device handle |
| 2481 | * |
| 2482 | * Return nothing. |
| 2483 | */ |
| 2484 | void |
| 2485 | mpt3sas_base_put_smid_fast_path(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 2486 | u16 handle) |
| 2487 | { |
| 2488 | Mpi2RequestDescriptorUnion_t descriptor; |
| 2489 | u64 *request = (u64 *)&descriptor; |
| 2490 | |
| 2491 | descriptor.SCSIIO.RequestFlags = |
| 2492 | MPI25_REQ_DESCRIPT_FLAGS_FAST_PATH_SCSI_IO; |
| 2493 | descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc); |
| 2494 | descriptor.SCSIIO.SMID = cpu_to_le16(smid); |
| 2495 | descriptor.SCSIIO.DevHandle = cpu_to_le16(handle); |
| 2496 | descriptor.SCSIIO.LMID = 0; |
| 2497 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 2498 | &ioc->scsi_lookup_lock); |
| 2499 | } |
| 2500 | |
| 2501 | /** |
| 2502 | * mpt3sas_base_put_smid_hi_priority - send Task Managment request to firmware |
| 2503 | * @ioc: per adapter object |
| 2504 | * @smid: system request message index |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 2505 | * @msix_task: msix_task will be same as msix of IO incase of task abort else 0. |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2506 | * Return nothing. |
| 2507 | */ |
| 2508 | void |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 2509 | mpt3sas_base_put_smid_hi_priority(struct MPT3SAS_ADAPTER *ioc, u16 smid, |
| 2510 | u16 msix_task) |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2511 | { |
| 2512 | Mpi2RequestDescriptorUnion_t descriptor; |
| 2513 | u64 *request = (u64 *)&descriptor; |
| 2514 | |
| 2515 | descriptor.HighPriority.RequestFlags = |
| 2516 | MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY; |
Suganath prabu Subramani | 03d1fb3 | 2016-01-28 12:07:06 +0530 | [diff] [blame] | 2517 | descriptor.HighPriority.MSIxIndex = msix_task; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2518 | descriptor.HighPriority.SMID = cpu_to_le16(smid); |
| 2519 | descriptor.HighPriority.LMID = 0; |
| 2520 | descriptor.HighPriority.Reserved1 = 0; |
| 2521 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 2522 | &ioc->scsi_lookup_lock); |
| 2523 | } |
| 2524 | |
| 2525 | /** |
| 2526 | * mpt3sas_base_put_smid_default - Default, primarily used for config pages |
| 2527 | * @ioc: per adapter object |
| 2528 | * @smid: system request message index |
| 2529 | * |
| 2530 | * Return nothing. |
| 2531 | */ |
| 2532 | void |
| 2533 | mpt3sas_base_put_smid_default(struct MPT3SAS_ADAPTER *ioc, u16 smid) |
| 2534 | { |
| 2535 | Mpi2RequestDescriptorUnion_t descriptor; |
| 2536 | u64 *request = (u64 *)&descriptor; |
| 2537 | |
| 2538 | descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE; |
| 2539 | descriptor.Default.MSIxIndex = _base_get_msix_index(ioc); |
| 2540 | descriptor.Default.SMID = cpu_to_le16(smid); |
| 2541 | descriptor.Default.LMID = 0; |
| 2542 | descriptor.Default.DescriptorTypeDependent = 0; |
| 2543 | _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow, |
| 2544 | &ioc->scsi_lookup_lock); |
| 2545 | } |
| 2546 | |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 2547 | /** |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 2548 | * _base_display_OEMs_branding - Display branding string |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 2549 | * @ioc: per adapter object |
| 2550 | * |
| 2551 | * Return nothing. |
| 2552 | */ |
| 2553 | static void |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 2554 | _base_display_OEMs_branding(struct MPT3SAS_ADAPTER *ioc) |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 2555 | { |
| 2556 | if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL) |
| 2557 | return; |
| 2558 | |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 2559 | switch (ioc->pdev->subsystem_vendor) { |
| 2560 | case PCI_VENDOR_ID_INTEL: |
| 2561 | switch (ioc->pdev->device) { |
| 2562 | case MPI2_MFGPAGE_DEVID_SAS2008: |
| 2563 | switch (ioc->pdev->subsystem_device) { |
| 2564 | case MPT2SAS_INTEL_RMS2LL080_SSDID: |
| 2565 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2566 | MPT2SAS_INTEL_RMS2LL080_BRANDING); |
| 2567 | break; |
| 2568 | case MPT2SAS_INTEL_RMS2LL040_SSDID: |
| 2569 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2570 | MPT2SAS_INTEL_RMS2LL040_BRANDING); |
| 2571 | break; |
| 2572 | case MPT2SAS_INTEL_SSD910_SSDID: |
| 2573 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2574 | MPT2SAS_INTEL_SSD910_BRANDING); |
| 2575 | break; |
| 2576 | default: |
| 2577 | pr_info(MPT3SAS_FMT |
| 2578 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
| 2579 | ioc->name, ioc->pdev->subsystem_device); |
| 2580 | break; |
| 2581 | } |
| 2582 | case MPI2_MFGPAGE_DEVID_SAS2308_2: |
| 2583 | switch (ioc->pdev->subsystem_device) { |
| 2584 | case MPT2SAS_INTEL_RS25GB008_SSDID: |
| 2585 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2586 | MPT2SAS_INTEL_RS25GB008_BRANDING); |
| 2587 | break; |
| 2588 | case MPT2SAS_INTEL_RMS25JB080_SSDID: |
| 2589 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2590 | MPT2SAS_INTEL_RMS25JB080_BRANDING); |
| 2591 | break; |
| 2592 | case MPT2SAS_INTEL_RMS25JB040_SSDID: |
| 2593 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2594 | MPT2SAS_INTEL_RMS25JB040_BRANDING); |
| 2595 | break; |
| 2596 | case MPT2SAS_INTEL_RMS25KB080_SSDID: |
| 2597 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2598 | MPT2SAS_INTEL_RMS25KB080_BRANDING); |
| 2599 | break; |
| 2600 | case MPT2SAS_INTEL_RMS25KB040_SSDID: |
| 2601 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2602 | MPT2SAS_INTEL_RMS25KB040_BRANDING); |
| 2603 | break; |
| 2604 | case MPT2SAS_INTEL_RMS25LB040_SSDID: |
| 2605 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2606 | MPT2SAS_INTEL_RMS25LB040_BRANDING); |
| 2607 | break; |
| 2608 | case MPT2SAS_INTEL_RMS25LB080_SSDID: |
| 2609 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2610 | MPT2SAS_INTEL_RMS25LB080_BRANDING); |
| 2611 | break; |
| 2612 | default: |
| 2613 | pr_info(MPT3SAS_FMT |
| 2614 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
| 2615 | ioc->name, ioc->pdev->subsystem_device); |
| 2616 | break; |
| 2617 | } |
| 2618 | case MPI25_MFGPAGE_DEVID_SAS3008: |
| 2619 | switch (ioc->pdev->subsystem_device) { |
| 2620 | case MPT3SAS_INTEL_RMS3JC080_SSDID: |
| 2621 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2622 | MPT3SAS_INTEL_RMS3JC080_BRANDING); |
| 2623 | break; |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 2624 | |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 2625 | case MPT3SAS_INTEL_RS3GC008_SSDID: |
| 2626 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2627 | MPT3SAS_INTEL_RS3GC008_BRANDING); |
| 2628 | break; |
| 2629 | case MPT3SAS_INTEL_RS3FC044_SSDID: |
| 2630 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2631 | MPT3SAS_INTEL_RS3FC044_BRANDING); |
| 2632 | break; |
| 2633 | case MPT3SAS_INTEL_RS3UC080_SSDID: |
| 2634 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2635 | MPT3SAS_INTEL_RS3UC080_BRANDING); |
| 2636 | break; |
| 2637 | default: |
| 2638 | pr_info(MPT3SAS_FMT |
| 2639 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
| 2640 | ioc->name, ioc->pdev->subsystem_device); |
| 2641 | break; |
| 2642 | } |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 2643 | break; |
| 2644 | default: |
| 2645 | pr_info(MPT3SAS_FMT |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 2646 | "Intel(R) Controller: Subsystem ID: 0x%X\n", |
Sreekanth Reddy | d8eb4a4 | 2015-06-30 12:25:02 +0530 | [diff] [blame] | 2647 | ioc->name, ioc->pdev->subsystem_device); |
| 2648 | break; |
| 2649 | } |
| 2650 | break; |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 2651 | case PCI_VENDOR_ID_DELL: |
| 2652 | switch (ioc->pdev->device) { |
| 2653 | case MPI2_MFGPAGE_DEVID_SAS2008: |
| 2654 | switch (ioc->pdev->subsystem_device) { |
| 2655 | case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID: |
| 2656 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2657 | MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING); |
| 2658 | break; |
| 2659 | case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID: |
| 2660 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2661 | MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING); |
| 2662 | break; |
| 2663 | case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID: |
| 2664 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2665 | MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING); |
| 2666 | break; |
| 2667 | case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID: |
| 2668 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2669 | MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING); |
| 2670 | break; |
| 2671 | case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID: |
| 2672 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2673 | MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING); |
| 2674 | break; |
| 2675 | case MPT2SAS_DELL_PERC_H200_SSDID: |
| 2676 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2677 | MPT2SAS_DELL_PERC_H200_BRANDING); |
| 2678 | break; |
| 2679 | case MPT2SAS_DELL_6GBPS_SAS_SSDID: |
| 2680 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2681 | MPT2SAS_DELL_6GBPS_SAS_BRANDING); |
| 2682 | break; |
| 2683 | default: |
| 2684 | pr_info(MPT3SAS_FMT |
| 2685 | "Dell 6Gbps HBA: Subsystem ID: 0x%X\n", |
| 2686 | ioc->name, ioc->pdev->subsystem_device); |
| 2687 | break; |
| 2688 | } |
| 2689 | break; |
| 2690 | case MPI25_MFGPAGE_DEVID_SAS3008: |
| 2691 | switch (ioc->pdev->subsystem_device) { |
| 2692 | case MPT3SAS_DELL_12G_HBA_SSDID: |
| 2693 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2694 | MPT3SAS_DELL_12G_HBA_BRANDING); |
| 2695 | break; |
| 2696 | default: |
| 2697 | pr_info(MPT3SAS_FMT |
| 2698 | "Dell 12Gbps HBA: Subsystem ID: 0x%X\n", |
| 2699 | ioc->name, ioc->pdev->subsystem_device); |
| 2700 | break; |
| 2701 | } |
| 2702 | break; |
| 2703 | default: |
| 2704 | pr_info(MPT3SAS_FMT |
| 2705 | "Dell HBA: Subsystem ID: 0x%X\n", ioc->name, |
| 2706 | ioc->pdev->subsystem_device); |
| 2707 | break; |
| 2708 | } |
| 2709 | break; |
| 2710 | case PCI_VENDOR_ID_CISCO: |
| 2711 | switch (ioc->pdev->device) { |
| 2712 | case MPI25_MFGPAGE_DEVID_SAS3008: |
| 2713 | switch (ioc->pdev->subsystem_device) { |
| 2714 | case MPT3SAS_CISCO_12G_8E_HBA_SSDID: |
| 2715 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2716 | MPT3SAS_CISCO_12G_8E_HBA_BRANDING); |
| 2717 | break; |
| 2718 | case MPT3SAS_CISCO_12G_8I_HBA_SSDID: |
| 2719 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2720 | MPT3SAS_CISCO_12G_8I_HBA_BRANDING); |
| 2721 | break; |
| 2722 | case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: |
| 2723 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2724 | MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); |
| 2725 | break; |
| 2726 | default: |
| 2727 | pr_info(MPT3SAS_FMT |
| 2728 | "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 2729 | ioc->name, ioc->pdev->subsystem_device); |
| 2730 | break; |
| 2731 | } |
| 2732 | break; |
| 2733 | case MPI25_MFGPAGE_DEVID_SAS3108_1: |
| 2734 | switch (ioc->pdev->subsystem_device) { |
| 2735 | case MPT3SAS_CISCO_12G_AVILA_HBA_SSDID: |
| 2736 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2737 | MPT3SAS_CISCO_12G_AVILA_HBA_BRANDING); |
| 2738 | break; |
| 2739 | case MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_SSDID: |
| 2740 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2741 | MPT3SAS_CISCO_12G_COLUSA_MEZZANINE_HBA_BRANDING |
| 2742 | ); |
| 2743 | break; |
| 2744 | default: |
| 2745 | pr_info(MPT3SAS_FMT |
| 2746 | "Cisco 12Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 2747 | ioc->name, ioc->pdev->subsystem_device); |
| 2748 | break; |
| 2749 | } |
| 2750 | break; |
| 2751 | default: |
| 2752 | pr_info(MPT3SAS_FMT |
| 2753 | "Cisco SAS HBA: Subsystem ID: 0x%X\n", |
| 2754 | ioc->name, ioc->pdev->subsystem_device); |
| 2755 | break; |
| 2756 | } |
| 2757 | break; |
| 2758 | case MPT2SAS_HP_3PAR_SSVID: |
| 2759 | switch (ioc->pdev->device) { |
| 2760 | case MPI2_MFGPAGE_DEVID_SAS2004: |
| 2761 | switch (ioc->pdev->subsystem_device) { |
| 2762 | case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID: |
| 2763 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2764 | MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING); |
| 2765 | break; |
| 2766 | default: |
| 2767 | pr_info(MPT3SAS_FMT |
| 2768 | "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 2769 | ioc->name, ioc->pdev->subsystem_device); |
| 2770 | break; |
| 2771 | } |
| 2772 | case MPI2_MFGPAGE_DEVID_SAS2308_2: |
| 2773 | switch (ioc->pdev->subsystem_device) { |
| 2774 | case MPT2SAS_HP_2_4_INTERNAL_SSDID: |
| 2775 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2776 | MPT2SAS_HP_2_4_INTERNAL_BRANDING); |
| 2777 | break; |
| 2778 | case MPT2SAS_HP_2_4_EXTERNAL_SSDID: |
| 2779 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2780 | MPT2SAS_HP_2_4_EXTERNAL_BRANDING); |
| 2781 | break; |
| 2782 | case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID: |
| 2783 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2784 | MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING); |
| 2785 | break; |
| 2786 | case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID: |
| 2787 | pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 2788 | MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING); |
| 2789 | break; |
| 2790 | default: |
| 2791 | pr_info(MPT3SAS_FMT |
| 2792 | "HP 6Gbps SAS HBA: Subsystem ID: 0x%X\n", |
| 2793 | ioc->name, ioc->pdev->subsystem_device); |
| 2794 | break; |
| 2795 | } |
| 2796 | default: |
| 2797 | pr_info(MPT3SAS_FMT |
| 2798 | "HP SAS HBA: Subsystem ID: 0x%X\n", |
| 2799 | ioc->name, ioc->pdev->subsystem_device); |
| 2800 | break; |
| 2801 | } |
Sreekanth Reddy | 38e4141 | 2015-06-30 12:24:57 +0530 | [diff] [blame] | 2802 | default: |
Sreekanth Reddy | 38e4141 | 2015-06-30 12:24:57 +0530 | [diff] [blame] | 2803 | break; |
| 2804 | } |
| 2805 | } |
Sreekanth Reddy | fb84dfc | 2015-06-30 12:24:56 +0530 | [diff] [blame] | 2806 | |
| 2807 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2808 | * _base_display_ioc_capabilities - Disply IOC's capabilities. |
| 2809 | * @ioc: per adapter object |
| 2810 | * |
| 2811 | * Return nothing. |
| 2812 | */ |
| 2813 | static void |
| 2814 | _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER *ioc) |
| 2815 | { |
| 2816 | int i = 0; |
| 2817 | char desc[16]; |
| 2818 | u32 iounit_pg1_flags; |
| 2819 | u32 bios_version; |
| 2820 | |
| 2821 | bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion); |
| 2822 | strncpy(desc, ioc->manu_pg0.ChipName, 16); |
| 2823 | pr_info(MPT3SAS_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "\ |
| 2824 | "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n", |
| 2825 | ioc->name, desc, |
| 2826 | (ioc->facts.FWVersion.Word & 0xFF000000) >> 24, |
| 2827 | (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16, |
| 2828 | (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8, |
| 2829 | ioc->facts.FWVersion.Word & 0x000000FF, |
| 2830 | ioc->pdev->revision, |
| 2831 | (bios_version & 0xFF000000) >> 24, |
| 2832 | (bios_version & 0x00FF0000) >> 16, |
| 2833 | (bios_version & 0x0000FF00) >> 8, |
| 2834 | bios_version & 0x000000FF); |
| 2835 | |
Sreekanth Reddy | 989e43c | 2015-11-11 17:30:32 +0530 | [diff] [blame] | 2836 | _base_display_OEMs_branding(ioc); |
Sreekanth Reddy | 1117b31 | 2014-09-12 15:35:30 +0530 | [diff] [blame] | 2837 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2838 | pr_info(MPT3SAS_FMT "Protocol=(", ioc->name); |
| 2839 | |
| 2840 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) { |
| 2841 | pr_info("Initiator"); |
| 2842 | i++; |
| 2843 | } |
| 2844 | |
| 2845 | if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) { |
| 2846 | pr_info("%sTarget", i ? "," : ""); |
| 2847 | i++; |
| 2848 | } |
| 2849 | |
| 2850 | i = 0; |
| 2851 | pr_info("), "); |
| 2852 | pr_info("Capabilities=("); |
| 2853 | |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 2854 | if (!ioc->hide_ir_msg) { |
| 2855 | if (ioc->facts.IOCCapabilities & |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2856 | MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) { |
| 2857 | pr_info("Raid"); |
| 2858 | i++; |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 2859 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) { |
| 2863 | pr_info("%sTLR", i ? "," : ""); |
| 2864 | i++; |
| 2865 | } |
| 2866 | |
| 2867 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) { |
| 2868 | pr_info("%sMulticast", i ? "," : ""); |
| 2869 | i++; |
| 2870 | } |
| 2871 | |
| 2872 | if (ioc->facts.IOCCapabilities & |
| 2873 | MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) { |
| 2874 | pr_info("%sBIDI Target", i ? "," : ""); |
| 2875 | i++; |
| 2876 | } |
| 2877 | |
| 2878 | if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) { |
| 2879 | pr_info("%sEEDP", i ? "," : ""); |
| 2880 | i++; |
| 2881 | } |
| 2882 | |
| 2883 | if (ioc->facts.IOCCapabilities & |
| 2884 | MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) { |
| 2885 | pr_info("%sSnapshot Buffer", i ? "," : ""); |
| 2886 | i++; |
| 2887 | } |
| 2888 | |
| 2889 | if (ioc->facts.IOCCapabilities & |
| 2890 | MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) { |
| 2891 | pr_info("%sDiag Trace Buffer", i ? "," : ""); |
| 2892 | i++; |
| 2893 | } |
| 2894 | |
| 2895 | if (ioc->facts.IOCCapabilities & |
| 2896 | MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) { |
| 2897 | pr_info("%sDiag Extended Buffer", i ? "," : ""); |
| 2898 | i++; |
| 2899 | } |
| 2900 | |
| 2901 | if (ioc->facts.IOCCapabilities & |
| 2902 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) { |
| 2903 | pr_info("%sTask Set Full", i ? "," : ""); |
| 2904 | i++; |
| 2905 | } |
| 2906 | |
| 2907 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); |
| 2908 | if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) { |
| 2909 | pr_info("%sNCQ", i ? "," : ""); |
| 2910 | i++; |
| 2911 | } |
| 2912 | |
| 2913 | pr_info(")\n"); |
| 2914 | } |
| 2915 | |
| 2916 | /** |
| 2917 | * mpt3sas_base_update_missing_delay - change the missing delay timers |
| 2918 | * @ioc: per adapter object |
| 2919 | * @device_missing_delay: amount of time till device is reported missing |
| 2920 | * @io_missing_delay: interval IO is returned when there is a missing device |
| 2921 | * |
| 2922 | * Return nothing. |
| 2923 | * |
| 2924 | * Passed on the command line, this function will modify the device missing |
| 2925 | * delay, as well as the io missing delay. This should be called at driver |
| 2926 | * load time. |
| 2927 | */ |
| 2928 | void |
| 2929 | mpt3sas_base_update_missing_delay(struct MPT3SAS_ADAPTER *ioc, |
| 2930 | u16 device_missing_delay, u8 io_missing_delay) |
| 2931 | { |
| 2932 | u16 dmd, dmd_new, dmd_orignal; |
| 2933 | u8 io_missing_delay_original; |
| 2934 | u16 sz; |
| 2935 | Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL; |
| 2936 | Mpi2ConfigReply_t mpi_reply; |
| 2937 | u8 num_phys = 0; |
| 2938 | u16 ioc_status; |
| 2939 | |
| 2940 | mpt3sas_config_get_number_hba_phys(ioc, &num_phys); |
| 2941 | if (!num_phys) |
| 2942 | return; |
| 2943 | |
| 2944 | sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys * |
| 2945 | sizeof(Mpi2SasIOUnit1PhyData_t)); |
| 2946 | sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL); |
| 2947 | if (!sas_iounit_pg1) { |
| 2948 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 2949 | ioc->name, __FILE__, __LINE__, __func__); |
| 2950 | goto out; |
| 2951 | } |
| 2952 | if ((mpt3sas_config_get_sas_iounit_pg1(ioc, &mpi_reply, |
| 2953 | sas_iounit_pg1, sz))) { |
| 2954 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 2955 | ioc->name, __FILE__, __LINE__, __func__); |
| 2956 | goto out; |
| 2957 | } |
| 2958 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & |
| 2959 | MPI2_IOCSTATUS_MASK; |
| 2960 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 2961 | pr_err(MPT3SAS_FMT "failure at %s:%d/%s()!\n", |
| 2962 | ioc->name, __FILE__, __LINE__, __func__); |
| 2963 | goto out; |
| 2964 | } |
| 2965 | |
| 2966 | /* device missing delay */ |
| 2967 | dmd = sas_iounit_pg1->ReportDeviceMissingDelay; |
| 2968 | if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 2969 | dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 2970 | else |
| 2971 | dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 2972 | dmd_orignal = dmd; |
| 2973 | if (device_missing_delay > 0x7F) { |
| 2974 | dmd = (device_missing_delay > 0x7F0) ? 0x7F0 : |
| 2975 | device_missing_delay; |
| 2976 | dmd = dmd / 16; |
| 2977 | dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16; |
| 2978 | } else |
| 2979 | dmd = device_missing_delay; |
| 2980 | sas_iounit_pg1->ReportDeviceMissingDelay = dmd; |
| 2981 | |
| 2982 | /* io missing delay */ |
| 2983 | io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay; |
| 2984 | sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay; |
| 2985 | |
| 2986 | if (!mpt3sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1, |
| 2987 | sz)) { |
| 2988 | if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16) |
| 2989 | dmd_new = (dmd & |
| 2990 | MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16; |
| 2991 | else |
| 2992 | dmd_new = |
| 2993 | dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK; |
| 2994 | pr_info(MPT3SAS_FMT "device_missing_delay: old(%d), new(%d)\n", |
| 2995 | ioc->name, dmd_orignal, dmd_new); |
| 2996 | pr_info(MPT3SAS_FMT "ioc_missing_delay: old(%d), new(%d)\n", |
| 2997 | ioc->name, io_missing_delay_original, |
| 2998 | io_missing_delay); |
| 2999 | ioc->device_missing_delay = dmd_new; |
| 3000 | ioc->io_missing_delay = io_missing_delay; |
| 3001 | } |
| 3002 | |
| 3003 | out: |
| 3004 | kfree(sas_iounit_pg1); |
| 3005 | } |
| 3006 | /** |
| 3007 | * _base_static_config_pages - static start of day config pages |
| 3008 | * @ioc: per adapter object |
| 3009 | * |
| 3010 | * Return nothing. |
| 3011 | */ |
| 3012 | static void |
| 3013 | _base_static_config_pages(struct MPT3SAS_ADAPTER *ioc) |
| 3014 | { |
| 3015 | Mpi2ConfigReply_t mpi_reply; |
| 3016 | u32 iounit_pg1_flags; |
| 3017 | |
| 3018 | mpt3sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0); |
| 3019 | if (ioc->ir_firmware) |
| 3020 | mpt3sas_config_get_manufacturing_pg10(ioc, &mpi_reply, |
| 3021 | &ioc->manu_pg10); |
| 3022 | |
| 3023 | /* |
| 3024 | * Ensure correct T10 PI operation if vendor left EEDPTagMode |
| 3025 | * flag unset in NVDATA. |
| 3026 | */ |
| 3027 | mpt3sas_config_get_manufacturing_pg11(ioc, &mpi_reply, &ioc->manu_pg11); |
| 3028 | if (ioc->manu_pg11.EEDPTagMode == 0) { |
| 3029 | pr_err("%s: overriding NVDATA EEDPTagMode setting\n", |
| 3030 | ioc->name); |
| 3031 | ioc->manu_pg11.EEDPTagMode &= ~0x3; |
| 3032 | ioc->manu_pg11.EEDPTagMode |= 0x1; |
| 3033 | mpt3sas_config_set_manufacturing_pg11(ioc, &mpi_reply, |
| 3034 | &ioc->manu_pg11); |
| 3035 | } |
| 3036 | |
| 3037 | mpt3sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2); |
| 3038 | mpt3sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3); |
| 3039 | mpt3sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8); |
| 3040 | mpt3sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0); |
| 3041 | mpt3sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 3042 | mpt3sas_config_get_iounit_pg8(ioc, &mpi_reply, &ioc->iounit_pg8); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3043 | _base_display_ioc_capabilities(ioc); |
| 3044 | |
| 3045 | /* |
| 3046 | * Enable task_set_full handling in iounit_pg1 when the |
| 3047 | * facts capabilities indicate that its supported. |
| 3048 | */ |
| 3049 | iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags); |
| 3050 | if ((ioc->facts.IOCCapabilities & |
| 3051 | MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING)) |
| 3052 | iounit_pg1_flags &= |
| 3053 | ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; |
| 3054 | else |
| 3055 | iounit_pg1_flags |= |
| 3056 | MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING; |
| 3057 | ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags); |
| 3058 | mpt3sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1); |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 3059 | |
| 3060 | if (ioc->iounit_pg8.NumSensors) |
| 3061 | ioc->temp_sensors_count = ioc->iounit_pg8.NumSensors; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | /** |
| 3065 | * _base_release_memory_pools - release memory |
| 3066 | * @ioc: per adapter object |
| 3067 | * |
| 3068 | * Free memory allocated from _base_allocate_memory_pools. |
| 3069 | * |
| 3070 | * Return nothing. |
| 3071 | */ |
| 3072 | static void |
| 3073 | _base_release_memory_pools(struct MPT3SAS_ADAPTER *ioc) |
| 3074 | { |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 3075 | int i = 0; |
| 3076 | struct reply_post_struct *rps; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3077 | |
| 3078 | dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3079 | __func__)); |
| 3080 | |
| 3081 | if (ioc->request) { |
| 3082 | pci_free_consistent(ioc->pdev, ioc->request_dma_sz, |
| 3083 | ioc->request, ioc->request_dma); |
| 3084 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3085 | "request_pool(0x%p): free\n", |
| 3086 | ioc->name, ioc->request)); |
| 3087 | ioc->request = NULL; |
| 3088 | } |
| 3089 | |
| 3090 | if (ioc->sense) { |
| 3091 | pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma); |
| 3092 | if (ioc->sense_dma_pool) |
| 3093 | pci_pool_destroy(ioc->sense_dma_pool); |
| 3094 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3095 | "sense_pool(0x%p): free\n", |
| 3096 | ioc->name, ioc->sense)); |
| 3097 | ioc->sense = NULL; |
| 3098 | } |
| 3099 | |
| 3100 | if (ioc->reply) { |
| 3101 | pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma); |
| 3102 | if (ioc->reply_dma_pool) |
| 3103 | pci_pool_destroy(ioc->reply_dma_pool); |
| 3104 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3105 | "reply_pool(0x%p): free\n", |
| 3106 | ioc->name, ioc->reply)); |
| 3107 | ioc->reply = NULL; |
| 3108 | } |
| 3109 | |
| 3110 | if (ioc->reply_free) { |
| 3111 | pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free, |
| 3112 | ioc->reply_free_dma); |
| 3113 | if (ioc->reply_free_dma_pool) |
| 3114 | pci_pool_destroy(ioc->reply_free_dma_pool); |
| 3115 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3116 | "reply_free_pool(0x%p): free\n", |
| 3117 | ioc->name, ioc->reply_free)); |
| 3118 | ioc->reply_free = NULL; |
| 3119 | } |
| 3120 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 3121 | if (ioc->reply_post) { |
| 3122 | do { |
| 3123 | rps = &ioc->reply_post[i]; |
| 3124 | if (rps->reply_post_free) { |
| 3125 | pci_pool_free( |
| 3126 | ioc->reply_post_free_dma_pool, |
| 3127 | rps->reply_post_free, |
| 3128 | rps->reply_post_free_dma); |
| 3129 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3130 | "reply_post_free_pool(0x%p): free\n", |
| 3131 | ioc->name, rps->reply_post_free)); |
| 3132 | rps->reply_post_free = NULL; |
| 3133 | } |
| 3134 | } while (ioc->rdpq_array_enable && |
| 3135 | (++i < ioc->reply_queue_count)); |
| 3136 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3137 | if (ioc->reply_post_free_dma_pool) |
| 3138 | pci_pool_destroy(ioc->reply_post_free_dma_pool); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 3139 | kfree(ioc->reply_post); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | if (ioc->config_page) { |
| 3143 | dexitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3144 | "config_page(0x%p): free\n", ioc->name, |
| 3145 | ioc->config_page)); |
| 3146 | pci_free_consistent(ioc->pdev, ioc->config_page_sz, |
| 3147 | ioc->config_page, ioc->config_page_dma); |
| 3148 | } |
| 3149 | |
| 3150 | if (ioc->scsi_lookup) { |
| 3151 | free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages); |
| 3152 | ioc->scsi_lookup = NULL; |
| 3153 | } |
| 3154 | kfree(ioc->hpr_lookup); |
| 3155 | kfree(ioc->internal_lookup); |
| 3156 | if (ioc->chain_lookup) { |
| 3157 | for (i = 0; i < ioc->chain_depth; i++) { |
| 3158 | if (ioc->chain_lookup[i].chain_buffer) |
| 3159 | pci_pool_free(ioc->chain_dma_pool, |
| 3160 | ioc->chain_lookup[i].chain_buffer, |
| 3161 | ioc->chain_lookup[i].chain_buffer_dma); |
| 3162 | } |
| 3163 | if (ioc->chain_dma_pool) |
| 3164 | pci_pool_destroy(ioc->chain_dma_pool); |
| 3165 | free_pages((ulong)ioc->chain_lookup, ioc->chain_pages); |
| 3166 | ioc->chain_lookup = NULL; |
| 3167 | } |
| 3168 | } |
| 3169 | |
| 3170 | /** |
| 3171 | * _base_allocate_memory_pools - allocate start of day memory pools |
| 3172 | * @ioc: per adapter object |
| 3173 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3174 | * |
| 3175 | * Returns 0 success, anything else error |
| 3176 | */ |
| 3177 | static int |
| 3178 | _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 3179 | { |
| 3180 | struct mpt3sas_facts *facts; |
| 3181 | u16 max_sge_elements; |
| 3182 | u16 chains_needed_per_io; |
| 3183 | u32 sz, total_sz, reply_post_free_sz; |
| 3184 | u32 retry_sz; |
| 3185 | u16 max_request_credit; |
| 3186 | unsigned short sg_tablesize; |
| 3187 | u16 sge_size; |
| 3188 | int i; |
| 3189 | |
| 3190 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 3191 | __func__)); |
| 3192 | |
| 3193 | |
| 3194 | retry_sz = 0; |
| 3195 | facts = &ioc->facts; |
| 3196 | |
| 3197 | /* command line tunables for max sgl entries */ |
| 3198 | if (max_sgl_entries != -1) |
| 3199 | sg_tablesize = max_sgl_entries; |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 3200 | else { |
| 3201 | if (ioc->hba_mpi_version_belonged == MPI2_VERSION) |
| 3202 | sg_tablesize = MPT2SAS_SG_DEPTH; |
| 3203 | else |
| 3204 | sg_tablesize = MPT3SAS_SG_DEPTH; |
| 3205 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3206 | |
Sreekanth Reddy | 8a7e4c2 | 2015-11-11 17:30:18 +0530 | [diff] [blame] | 3207 | if (sg_tablesize < MPT_MIN_PHYS_SEGMENTS) |
| 3208 | sg_tablesize = MPT_MIN_PHYS_SEGMENTS; |
| 3209 | else if (sg_tablesize > MPT_MAX_PHYS_SEGMENTS) { |
Sreekanth Reddy | ad666a0 | 2015-01-12 11:39:00 +0530 | [diff] [blame] | 3210 | sg_tablesize = min_t(unsigned short, sg_tablesize, |
Ming Lin | 65e8617 | 2016-04-04 14:48:10 -0700 | [diff] [blame] | 3211 | SG_MAX_SEGMENTS); |
Sreekanth Reddy | ad666a0 | 2015-01-12 11:39:00 +0530 | [diff] [blame] | 3212 | pr_warn(MPT3SAS_FMT |
| 3213 | "sg_tablesize(%u) is bigger than kernel" |
Ming Lin | 65e8617 | 2016-04-04 14:48:10 -0700 | [diff] [blame] | 3214 | " defined SG_CHUNK_SIZE(%u)\n", ioc->name, |
Sreekanth Reddy | 8a7e4c2 | 2015-11-11 17:30:18 +0530 | [diff] [blame] | 3215 | sg_tablesize, MPT_MAX_PHYS_SEGMENTS); |
Sreekanth Reddy | ad666a0 | 2015-01-12 11:39:00 +0530 | [diff] [blame] | 3216 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3217 | ioc->shost->sg_tablesize = sg_tablesize; |
| 3218 | |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 3219 | ioc->internal_depth = min_t(int, (facts->HighPriorityCredit + (5)), |
| 3220 | (facts->RequestCredit / 4)); |
| 3221 | if (ioc->internal_depth < INTERNAL_CMDS_COUNT) { |
| 3222 | if (facts->RequestCredit <= (INTERNAL_CMDS_COUNT + |
| 3223 | INTERNAL_SCSIIO_CMDS_COUNT)) { |
| 3224 | pr_err(MPT3SAS_FMT "IOC doesn't have enough Request \ |
| 3225 | Credits, it has just %d number of credits\n", |
| 3226 | ioc->name, facts->RequestCredit); |
| 3227 | return -ENOMEM; |
| 3228 | } |
| 3229 | ioc->internal_depth = 10; |
| 3230 | } |
| 3231 | |
| 3232 | ioc->hi_priority_depth = ioc->internal_depth - (5); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3233 | /* command line tunables for max controller queue depth */ |
| 3234 | if (max_queue_depth != -1 && max_queue_depth != 0) { |
| 3235 | max_request_credit = min_t(u16, max_queue_depth + |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 3236 | ioc->internal_depth, facts->RequestCredit); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3237 | if (max_request_credit > MAX_HBA_QUEUE_DEPTH) |
| 3238 | max_request_credit = MAX_HBA_QUEUE_DEPTH; |
| 3239 | } else |
| 3240 | max_request_credit = min_t(u16, facts->RequestCredit, |
| 3241 | MAX_HBA_QUEUE_DEPTH); |
| 3242 | |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 3243 | /* Firmware maintains additional facts->HighPriorityCredit number of |
| 3244 | * credits for HiPriprity Request messages, so hba queue depth will be |
| 3245 | * sum of max_request_credit and high priority queue depth. |
| 3246 | */ |
| 3247 | ioc->hba_queue_depth = max_request_credit + ioc->hi_priority_depth; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3248 | |
| 3249 | /* request frame size */ |
| 3250 | ioc->request_sz = facts->IOCRequestFrameSize * 4; |
| 3251 | |
| 3252 | /* reply frame size */ |
| 3253 | ioc->reply_sz = facts->ReplyFrameSize * 4; |
| 3254 | |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 3255 | /* chain segment size */ |
| 3256 | if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { |
| 3257 | if (facts->IOCMaxChainSegmentSize) |
| 3258 | ioc->chain_segment_sz = |
| 3259 | facts->IOCMaxChainSegmentSize * |
| 3260 | MAX_CHAIN_ELEMT_SZ; |
| 3261 | else |
| 3262 | /* set to 128 bytes size if IOCMaxChainSegmentSize is zero */ |
| 3263 | ioc->chain_segment_sz = DEFAULT_NUM_FWCHAIN_ELEMTS * |
| 3264 | MAX_CHAIN_ELEMT_SZ; |
| 3265 | } else |
| 3266 | ioc->chain_segment_sz = ioc->request_sz; |
| 3267 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3268 | /* calculate the max scatter element size */ |
| 3269 | sge_size = max_t(u16, ioc->sge_size, ioc->sge_size_ieee); |
| 3270 | |
| 3271 | retry_allocation: |
| 3272 | total_sz = 0; |
| 3273 | /* calculate number of sg elements left over in the 1st frame */ |
| 3274 | max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) - |
| 3275 | sizeof(Mpi2SGEIOUnion_t)) + sge_size); |
| 3276 | ioc->max_sges_in_main_message = max_sge_elements/sge_size; |
| 3277 | |
| 3278 | /* now do the same for a chain buffer */ |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 3279 | max_sge_elements = ioc->chain_segment_sz - sge_size; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3280 | ioc->max_sges_in_chain_message = max_sge_elements/sge_size; |
| 3281 | |
| 3282 | /* |
| 3283 | * MPT3SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE |
| 3284 | */ |
| 3285 | chains_needed_per_io = ((ioc->shost->sg_tablesize - |
| 3286 | ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message) |
| 3287 | + 1; |
| 3288 | if (chains_needed_per_io > facts->MaxChainDepth) { |
| 3289 | chains_needed_per_io = facts->MaxChainDepth; |
| 3290 | ioc->shost->sg_tablesize = min_t(u16, |
| 3291 | ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message |
| 3292 | * chains_needed_per_io), ioc->shost->sg_tablesize); |
| 3293 | } |
| 3294 | ioc->chains_needed_per_io = chains_needed_per_io; |
| 3295 | |
| 3296 | /* reply free queue sizing - taking into account for 64 FW events */ |
| 3297 | ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; |
| 3298 | |
| 3299 | /* calculate reply descriptor post queue depth */ |
| 3300 | ioc->reply_post_queue_depth = ioc->hba_queue_depth + |
| 3301 | ioc->reply_free_queue_depth + 1 ; |
| 3302 | /* align the reply post queue on the next 16 count boundary */ |
| 3303 | if (ioc->reply_post_queue_depth % 16) |
| 3304 | ioc->reply_post_queue_depth += 16 - |
| 3305 | (ioc->reply_post_queue_depth % 16); |
| 3306 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3307 | if (ioc->reply_post_queue_depth > |
| 3308 | facts->MaxReplyDescriptorPostQueueDepth) { |
| 3309 | ioc->reply_post_queue_depth = |
| 3310 | facts->MaxReplyDescriptorPostQueueDepth - |
| 3311 | (facts->MaxReplyDescriptorPostQueueDepth % 16); |
| 3312 | ioc->hba_queue_depth = |
| 3313 | ((ioc->reply_post_queue_depth - 64) / 2) - 1; |
| 3314 | ioc->reply_free_queue_depth = ioc->hba_queue_depth + 64; |
| 3315 | } |
| 3316 | |
| 3317 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "scatter gather: " \ |
| 3318 | "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), " |
| 3319 | "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message, |
| 3320 | ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize, |
| 3321 | ioc->chains_needed_per_io)); |
| 3322 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 3323 | /* reply post queue, 16 byte align */ |
| 3324 | reply_post_free_sz = ioc->reply_post_queue_depth * |
| 3325 | sizeof(Mpi2DefaultReplyDescriptor_t); |
| 3326 | |
| 3327 | sz = reply_post_free_sz; |
| 3328 | if (_base_is_controller_msix_enabled(ioc) && !ioc->rdpq_array_enable) |
| 3329 | sz *= ioc->reply_queue_count; |
| 3330 | |
| 3331 | ioc->reply_post = kcalloc((ioc->rdpq_array_enable) ? |
| 3332 | (ioc->reply_queue_count):1, |
| 3333 | sizeof(struct reply_post_struct), GFP_KERNEL); |
| 3334 | |
| 3335 | if (!ioc->reply_post) { |
| 3336 | pr_err(MPT3SAS_FMT "reply_post_free pool: kcalloc failed\n", |
| 3337 | ioc->name); |
| 3338 | goto out; |
| 3339 | } |
| 3340 | ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool", |
| 3341 | ioc->pdev, sz, 16, 0); |
| 3342 | if (!ioc->reply_post_free_dma_pool) { |
| 3343 | pr_err(MPT3SAS_FMT |
| 3344 | "reply_post_free pool: pci_pool_create failed\n", |
| 3345 | ioc->name); |
| 3346 | goto out; |
| 3347 | } |
| 3348 | i = 0; |
| 3349 | do { |
| 3350 | ioc->reply_post[i].reply_post_free = |
| 3351 | pci_pool_alloc(ioc->reply_post_free_dma_pool, |
| 3352 | GFP_KERNEL, |
| 3353 | &ioc->reply_post[i].reply_post_free_dma); |
| 3354 | if (!ioc->reply_post[i].reply_post_free) { |
| 3355 | pr_err(MPT3SAS_FMT |
| 3356 | "reply_post_free pool: pci_pool_alloc failed\n", |
| 3357 | ioc->name); |
| 3358 | goto out; |
| 3359 | } |
| 3360 | memset(ioc->reply_post[i].reply_post_free, 0, sz); |
| 3361 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3362 | "reply post free pool (0x%p): depth(%d)," |
| 3363 | "element_size(%d), pool_size(%d kB)\n", ioc->name, |
| 3364 | ioc->reply_post[i].reply_post_free, |
| 3365 | ioc->reply_post_queue_depth, 8, sz/1024)); |
| 3366 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3367 | "reply_post_free_dma = (0x%llx)\n", ioc->name, |
| 3368 | (unsigned long long) |
| 3369 | ioc->reply_post[i].reply_post_free_dma)); |
| 3370 | total_sz += sz; |
| 3371 | } while (ioc->rdpq_array_enable && (++i < ioc->reply_queue_count)); |
| 3372 | |
| 3373 | if (ioc->dma_mask == 64) { |
| 3374 | if (_base_change_consistent_dma_mask(ioc, ioc->pdev) != 0) { |
| 3375 | pr_warn(MPT3SAS_FMT |
| 3376 | "no suitable consistent DMA mask for %s\n", |
| 3377 | ioc->name, pci_name(ioc->pdev)); |
| 3378 | goto out; |
| 3379 | } |
| 3380 | } |
| 3381 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3382 | ioc->scsiio_depth = ioc->hba_queue_depth - |
| 3383 | ioc->hi_priority_depth - ioc->internal_depth; |
| 3384 | |
| 3385 | /* set the scsi host can_queue depth |
| 3386 | * with some internal commands that could be outstanding |
| 3387 | */ |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 3388 | ioc->shost->can_queue = ioc->scsiio_depth - INTERNAL_SCSIIO_CMDS_COUNT; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3389 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3390 | "scsi host: can_queue depth (%d)\n", |
| 3391 | ioc->name, ioc->shost->can_queue)); |
| 3392 | |
| 3393 | |
| 3394 | /* contiguous pool for request and chains, 16 byte align, one extra " |
| 3395 | * "frame for smid=0 |
| 3396 | */ |
| 3397 | ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth; |
| 3398 | sz = ((ioc->scsiio_depth + 1) * ioc->request_sz); |
| 3399 | |
| 3400 | /* hi-priority queue */ |
| 3401 | sz += (ioc->hi_priority_depth * ioc->request_sz); |
| 3402 | |
| 3403 | /* internal queue */ |
| 3404 | sz += (ioc->internal_depth * ioc->request_sz); |
| 3405 | |
| 3406 | ioc->request_dma_sz = sz; |
| 3407 | ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma); |
| 3408 | if (!ioc->request) { |
| 3409 | pr_err(MPT3SAS_FMT "request pool: pci_alloc_consistent " \ |
| 3410 | "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " |
| 3411 | "total(%d kB)\n", ioc->name, ioc->hba_queue_depth, |
| 3412 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); |
| 3413 | if (ioc->scsiio_depth < MPT3SAS_SAS_QUEUE_DEPTH) |
| 3414 | goto out; |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 3415 | retry_sz = 64; |
| 3416 | ioc->hba_queue_depth -= retry_sz; |
Suganath prabu Subramani | 8ff045c | 2016-02-18 14:09:45 +0530 | [diff] [blame] | 3417 | _base_release_memory_pools(ioc); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3418 | goto retry_allocation; |
| 3419 | } |
| 3420 | |
| 3421 | if (retry_sz) |
| 3422 | pr_err(MPT3SAS_FMT "request pool: pci_alloc_consistent " \ |
| 3423 | "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), " |
| 3424 | "total(%d kb)\n", ioc->name, ioc->hba_queue_depth, |
| 3425 | ioc->chains_needed_per_io, ioc->request_sz, sz/1024); |
| 3426 | |
| 3427 | /* hi-priority queue */ |
| 3428 | ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) * |
| 3429 | ioc->request_sz); |
| 3430 | ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) * |
| 3431 | ioc->request_sz); |
| 3432 | |
| 3433 | /* internal queue */ |
| 3434 | ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth * |
| 3435 | ioc->request_sz); |
| 3436 | ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth * |
| 3437 | ioc->request_sz); |
| 3438 | |
| 3439 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3440 | "request pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n", |
| 3441 | ioc->name, ioc->request, ioc->hba_queue_depth, ioc->request_sz, |
| 3442 | (ioc->hba_queue_depth * ioc->request_sz)/1024)); |
| 3443 | |
| 3444 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "request pool: dma(0x%llx)\n", |
| 3445 | ioc->name, (unsigned long long) ioc->request_dma)); |
| 3446 | total_sz += sz; |
| 3447 | |
| 3448 | sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker); |
| 3449 | ioc->scsi_lookup_pages = get_order(sz); |
| 3450 | ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages( |
| 3451 | GFP_KERNEL, ioc->scsi_lookup_pages); |
| 3452 | if (!ioc->scsi_lookup) { |
| 3453 | pr_err(MPT3SAS_FMT "scsi_lookup: get_free_pages failed, sz(%d)\n", |
| 3454 | ioc->name, (int)sz); |
| 3455 | goto out; |
| 3456 | } |
| 3457 | |
| 3458 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "scsiio(0x%p): depth(%d)\n", |
| 3459 | ioc->name, ioc->request, ioc->scsiio_depth)); |
| 3460 | |
| 3461 | ioc->chain_depth = min_t(u32, ioc->chain_depth, MAX_CHAIN_DEPTH); |
| 3462 | sz = ioc->chain_depth * sizeof(struct chain_tracker); |
| 3463 | ioc->chain_pages = get_order(sz); |
| 3464 | ioc->chain_lookup = (struct chain_tracker *)__get_free_pages( |
| 3465 | GFP_KERNEL, ioc->chain_pages); |
| 3466 | if (!ioc->chain_lookup) { |
| 3467 | pr_err(MPT3SAS_FMT "chain_lookup: __get_free_pages failed\n", |
| 3468 | ioc->name); |
| 3469 | goto out; |
| 3470 | } |
| 3471 | ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev, |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 3472 | ioc->chain_segment_sz, 16, 0); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3473 | if (!ioc->chain_dma_pool) { |
| 3474 | pr_err(MPT3SAS_FMT "chain_dma_pool: pci_pool_create failed\n", |
| 3475 | ioc->name); |
| 3476 | goto out; |
| 3477 | } |
| 3478 | for (i = 0; i < ioc->chain_depth; i++) { |
| 3479 | ioc->chain_lookup[i].chain_buffer = pci_pool_alloc( |
| 3480 | ioc->chain_dma_pool , GFP_KERNEL, |
| 3481 | &ioc->chain_lookup[i].chain_buffer_dma); |
| 3482 | if (!ioc->chain_lookup[i].chain_buffer) { |
| 3483 | ioc->chain_depth = i; |
| 3484 | goto chain_done; |
| 3485 | } |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 3486 | total_sz += ioc->chain_segment_sz; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3487 | } |
| 3488 | chain_done: |
| 3489 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3490 | "chain pool depth(%d), frame_size(%d), pool_size(%d kB)\n", |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 3491 | ioc->name, ioc->chain_depth, ioc->chain_segment_sz, |
| 3492 | ((ioc->chain_depth * ioc->chain_segment_sz))/1024)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3493 | |
| 3494 | /* initialize hi-priority queue smid's */ |
| 3495 | ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth, |
| 3496 | sizeof(struct request_tracker), GFP_KERNEL); |
| 3497 | if (!ioc->hpr_lookup) { |
| 3498 | pr_err(MPT3SAS_FMT "hpr_lookup: kcalloc failed\n", |
| 3499 | ioc->name); |
| 3500 | goto out; |
| 3501 | } |
| 3502 | ioc->hi_priority_smid = ioc->scsiio_depth + 1; |
| 3503 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3504 | "hi_priority(0x%p): depth(%d), start smid(%d)\n", |
| 3505 | ioc->name, ioc->hi_priority, |
| 3506 | ioc->hi_priority_depth, ioc->hi_priority_smid)); |
| 3507 | |
| 3508 | /* initialize internal queue smid's */ |
| 3509 | ioc->internal_lookup = kcalloc(ioc->internal_depth, |
| 3510 | sizeof(struct request_tracker), GFP_KERNEL); |
| 3511 | if (!ioc->internal_lookup) { |
| 3512 | pr_err(MPT3SAS_FMT "internal_lookup: kcalloc failed\n", |
| 3513 | ioc->name); |
| 3514 | goto out; |
| 3515 | } |
| 3516 | ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth; |
| 3517 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3518 | "internal(0x%p): depth(%d), start smid(%d)\n", |
| 3519 | ioc->name, ioc->internal, |
| 3520 | ioc->internal_depth, ioc->internal_smid)); |
| 3521 | |
| 3522 | /* sense buffers, 4 byte align */ |
| 3523 | sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE; |
| 3524 | ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4, |
| 3525 | 0); |
| 3526 | if (!ioc->sense_dma_pool) { |
| 3527 | pr_err(MPT3SAS_FMT "sense pool: pci_pool_create failed\n", |
| 3528 | ioc->name); |
| 3529 | goto out; |
| 3530 | } |
| 3531 | ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL, |
| 3532 | &ioc->sense_dma); |
| 3533 | if (!ioc->sense) { |
| 3534 | pr_err(MPT3SAS_FMT "sense pool: pci_pool_alloc failed\n", |
| 3535 | ioc->name); |
| 3536 | goto out; |
| 3537 | } |
| 3538 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3539 | "sense pool(0x%p): depth(%d), element_size(%d), pool_size" |
| 3540 | "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth, |
| 3541 | SCSI_SENSE_BUFFERSIZE, sz/1024)); |
| 3542 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "sense_dma(0x%llx)\n", |
| 3543 | ioc->name, (unsigned long long)ioc->sense_dma)); |
| 3544 | total_sz += sz; |
| 3545 | |
| 3546 | /* reply pool, 4 byte align */ |
| 3547 | sz = ioc->reply_free_queue_depth * ioc->reply_sz; |
| 3548 | ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4, |
| 3549 | 0); |
| 3550 | if (!ioc->reply_dma_pool) { |
| 3551 | pr_err(MPT3SAS_FMT "reply pool: pci_pool_create failed\n", |
| 3552 | ioc->name); |
| 3553 | goto out; |
| 3554 | } |
| 3555 | ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL, |
| 3556 | &ioc->reply_dma); |
| 3557 | if (!ioc->reply) { |
| 3558 | pr_err(MPT3SAS_FMT "reply pool: pci_pool_alloc failed\n", |
| 3559 | ioc->name); |
| 3560 | goto out; |
| 3561 | } |
| 3562 | ioc->reply_dma_min_address = (u32)(ioc->reply_dma); |
| 3563 | ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz; |
| 3564 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3565 | "reply pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB)\n", |
| 3566 | ioc->name, ioc->reply, |
| 3567 | ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024)); |
| 3568 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "reply_dma(0x%llx)\n", |
| 3569 | ioc->name, (unsigned long long)ioc->reply_dma)); |
| 3570 | total_sz += sz; |
| 3571 | |
| 3572 | /* reply free queue, 16 byte align */ |
| 3573 | sz = ioc->reply_free_queue_depth * 4; |
| 3574 | ioc->reply_free_dma_pool = pci_pool_create("reply_free pool", |
| 3575 | ioc->pdev, sz, 16, 0); |
| 3576 | if (!ioc->reply_free_dma_pool) { |
| 3577 | pr_err(MPT3SAS_FMT "reply_free pool: pci_pool_create failed\n", |
| 3578 | ioc->name); |
| 3579 | goto out; |
| 3580 | } |
| 3581 | ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL, |
| 3582 | &ioc->reply_free_dma); |
| 3583 | if (!ioc->reply_free) { |
| 3584 | pr_err(MPT3SAS_FMT "reply_free pool: pci_pool_alloc failed\n", |
| 3585 | ioc->name); |
| 3586 | goto out; |
| 3587 | } |
| 3588 | memset(ioc->reply_free, 0, sz); |
| 3589 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "reply_free pool(0x%p): " \ |
| 3590 | "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name, |
| 3591 | ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024)); |
| 3592 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3593 | "reply_free_dma (0x%llx)\n", |
| 3594 | ioc->name, (unsigned long long)ioc->reply_free_dma)); |
| 3595 | total_sz += sz; |
| 3596 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3597 | ioc->config_page_sz = 512; |
| 3598 | ioc->config_page = pci_alloc_consistent(ioc->pdev, |
| 3599 | ioc->config_page_sz, &ioc->config_page_dma); |
| 3600 | if (!ioc->config_page) { |
| 3601 | pr_err(MPT3SAS_FMT |
| 3602 | "config page: pci_pool_alloc failed\n", |
| 3603 | ioc->name); |
| 3604 | goto out; |
| 3605 | } |
| 3606 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 3607 | "config page(0x%p): size(%d)\n", |
| 3608 | ioc->name, ioc->config_page, ioc->config_page_sz)); |
| 3609 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "config_page_dma(0x%llx)\n", |
| 3610 | ioc->name, (unsigned long long)ioc->config_page_dma)); |
| 3611 | total_sz += ioc->config_page_sz; |
| 3612 | |
| 3613 | pr_info(MPT3SAS_FMT "Allocated physical memory: size(%d kB)\n", |
| 3614 | ioc->name, total_sz/1024); |
| 3615 | pr_info(MPT3SAS_FMT |
| 3616 | "Current Controller Queue Depth(%d),Max Controller Queue Depth(%d)\n", |
| 3617 | ioc->name, ioc->shost->can_queue, facts->RequestCredit); |
| 3618 | pr_info(MPT3SAS_FMT "Scatter Gather Elements per IO(%d)\n", |
| 3619 | ioc->name, ioc->shost->sg_tablesize); |
| 3620 | return 0; |
| 3621 | |
| 3622 | out: |
| 3623 | return -ENOMEM; |
| 3624 | } |
| 3625 | |
| 3626 | /** |
| 3627 | * mpt3sas_base_get_iocstate - Get the current state of a MPT adapter. |
| 3628 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3629 | * @cooked: Request raw or cooked IOC state |
| 3630 | * |
| 3631 | * Returns all IOC Doorbell register bits if cooked==0, else just the |
| 3632 | * Doorbell bits in MPI_IOC_STATE_MASK. |
| 3633 | */ |
| 3634 | u32 |
| 3635 | mpt3sas_base_get_iocstate(struct MPT3SAS_ADAPTER *ioc, int cooked) |
| 3636 | { |
| 3637 | u32 s, sc; |
| 3638 | |
| 3639 | s = readl(&ioc->chip->Doorbell); |
| 3640 | sc = s & MPI2_IOC_STATE_MASK; |
| 3641 | return cooked ? sc : s; |
| 3642 | } |
| 3643 | |
| 3644 | /** |
| 3645 | * _base_wait_on_iocstate - waiting on a particular ioc state |
| 3646 | * @ioc_state: controller state { READY, OPERATIONAL, or RESET } |
| 3647 | * @timeout: timeout in second |
| 3648 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3649 | * |
| 3650 | * Returns 0 for success, non-zero for failure. |
| 3651 | */ |
| 3652 | static int |
| 3653 | _base_wait_on_iocstate(struct MPT3SAS_ADAPTER *ioc, u32 ioc_state, int timeout, |
| 3654 | int sleep_flag) |
| 3655 | { |
| 3656 | u32 count, cntdn; |
| 3657 | u32 current_state; |
| 3658 | |
| 3659 | count = 0; |
| 3660 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 3661 | do { |
| 3662 | current_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 3663 | if (current_state == ioc_state) |
| 3664 | return 0; |
| 3665 | if (count && current_state == MPI2_IOC_STATE_FAULT) |
| 3666 | break; |
| 3667 | if (sleep_flag == CAN_SLEEP) |
| 3668 | usleep_range(1000, 1500); |
| 3669 | else |
| 3670 | udelay(500); |
| 3671 | count++; |
| 3672 | } while (--cntdn); |
| 3673 | |
| 3674 | return current_state; |
| 3675 | } |
| 3676 | |
| 3677 | /** |
| 3678 | * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by |
| 3679 | * a write to the doorbell) |
| 3680 | * @ioc: per adapter object |
| 3681 | * @timeout: timeout in second |
| 3682 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3683 | * |
| 3684 | * Returns 0 for success, non-zero for failure. |
| 3685 | * |
| 3686 | * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell. |
| 3687 | */ |
| 3688 | static int |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 3689 | _base_diag_reset(struct MPT3SAS_ADAPTER *ioc, int sleep_flag); |
| 3690 | |
| 3691 | static int |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 3692 | _base_wait_for_doorbell_int(struct MPT3SAS_ADAPTER *ioc, int timeout, |
| 3693 | int sleep_flag) |
| 3694 | { |
| 3695 | u32 cntdn, count; |
| 3696 | u32 int_status; |
| 3697 | |
| 3698 | count = 0; |
| 3699 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 3700 | do { |
| 3701 | int_status = readl(&ioc->chip->HostInterruptStatus); |
| 3702 | if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { |
| 3703 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 3704 | "%s: successful count(%d), timeout(%d)\n", |
| 3705 | ioc->name, __func__, count, timeout)); |
| 3706 | return 0; |
| 3707 | } |
| 3708 | if (sleep_flag == CAN_SLEEP) |
| 3709 | usleep_range(1000, 1500); |
| 3710 | else |
| 3711 | udelay(500); |
| 3712 | count++; |
| 3713 | } while (--cntdn); |
| 3714 | |
| 3715 | pr_err(MPT3SAS_FMT |
| 3716 | "%s: failed due to timeout count(%d), int_status(%x)!\n", |
| 3717 | ioc->name, __func__, count, int_status); |
| 3718 | return -EFAULT; |
| 3719 | } |
| 3720 | |
| 3721 | /** |
| 3722 | * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell. |
| 3723 | * @ioc: per adapter object |
| 3724 | * @timeout: timeout in second |
| 3725 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3726 | * |
| 3727 | * Returns 0 for success, non-zero for failure. |
| 3728 | * |
| 3729 | * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to |
| 3730 | * doorbell. |
| 3731 | */ |
| 3732 | static int |
| 3733 | _base_wait_for_doorbell_ack(struct MPT3SAS_ADAPTER *ioc, int timeout, |
| 3734 | int sleep_flag) |
| 3735 | { |
| 3736 | u32 cntdn, count; |
| 3737 | u32 int_status; |
| 3738 | u32 doorbell; |
| 3739 | |
| 3740 | count = 0; |
| 3741 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 3742 | do { |
| 3743 | int_status = readl(&ioc->chip->HostInterruptStatus); |
| 3744 | if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) { |
| 3745 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 3746 | "%s: successful count(%d), timeout(%d)\n", |
| 3747 | ioc->name, __func__, count, timeout)); |
| 3748 | return 0; |
| 3749 | } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) { |
| 3750 | doorbell = readl(&ioc->chip->Doorbell); |
| 3751 | if ((doorbell & MPI2_IOC_STATE_MASK) == |
| 3752 | MPI2_IOC_STATE_FAULT) { |
| 3753 | mpt3sas_base_fault_info(ioc , doorbell); |
| 3754 | return -EFAULT; |
| 3755 | } |
| 3756 | } else if (int_status == 0xFFFFFFFF) |
| 3757 | goto out; |
| 3758 | |
| 3759 | if (sleep_flag == CAN_SLEEP) |
| 3760 | usleep_range(1000, 1500); |
| 3761 | else |
| 3762 | udelay(500); |
| 3763 | count++; |
| 3764 | } while (--cntdn); |
| 3765 | |
| 3766 | out: |
| 3767 | pr_err(MPT3SAS_FMT |
| 3768 | "%s: failed due to timeout count(%d), int_status(%x)!\n", |
| 3769 | ioc->name, __func__, count, int_status); |
| 3770 | return -EFAULT; |
| 3771 | } |
| 3772 | |
| 3773 | /** |
| 3774 | * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use |
| 3775 | * @ioc: per adapter object |
| 3776 | * @timeout: timeout in second |
| 3777 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3778 | * |
| 3779 | * Returns 0 for success, non-zero for failure. |
| 3780 | * |
| 3781 | */ |
| 3782 | static int |
| 3783 | _base_wait_for_doorbell_not_used(struct MPT3SAS_ADAPTER *ioc, int timeout, |
| 3784 | int sleep_flag) |
| 3785 | { |
| 3786 | u32 cntdn, count; |
| 3787 | u32 doorbell_reg; |
| 3788 | |
| 3789 | count = 0; |
| 3790 | cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout; |
| 3791 | do { |
| 3792 | doorbell_reg = readl(&ioc->chip->Doorbell); |
| 3793 | if (!(doorbell_reg & MPI2_DOORBELL_USED)) { |
| 3794 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 3795 | "%s: successful count(%d), timeout(%d)\n", |
| 3796 | ioc->name, __func__, count, timeout)); |
| 3797 | return 0; |
| 3798 | } |
| 3799 | if (sleep_flag == CAN_SLEEP) |
| 3800 | usleep_range(1000, 1500); |
| 3801 | else |
| 3802 | udelay(500); |
| 3803 | count++; |
| 3804 | } while (--cntdn); |
| 3805 | |
| 3806 | pr_err(MPT3SAS_FMT |
| 3807 | "%s: failed due to timeout count(%d), doorbell_reg(%x)!\n", |
| 3808 | ioc->name, __func__, count, doorbell_reg); |
| 3809 | return -EFAULT; |
| 3810 | } |
| 3811 | |
| 3812 | /** |
| 3813 | * _base_send_ioc_reset - send doorbell reset |
| 3814 | * @ioc: per adapter object |
| 3815 | * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET |
| 3816 | * @timeout: timeout in second |
| 3817 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3818 | * |
| 3819 | * Returns 0 for success, non-zero for failure. |
| 3820 | */ |
| 3821 | static int |
| 3822 | _base_send_ioc_reset(struct MPT3SAS_ADAPTER *ioc, u8 reset_type, int timeout, |
| 3823 | int sleep_flag) |
| 3824 | { |
| 3825 | u32 ioc_state; |
| 3826 | int r = 0; |
| 3827 | |
| 3828 | if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) { |
| 3829 | pr_err(MPT3SAS_FMT "%s: unknown reset_type\n", |
| 3830 | ioc->name, __func__); |
| 3831 | return -EFAULT; |
| 3832 | } |
| 3833 | |
| 3834 | if (!(ioc->facts.IOCCapabilities & |
| 3835 | MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY)) |
| 3836 | return -EFAULT; |
| 3837 | |
| 3838 | pr_info(MPT3SAS_FMT "sending message unit reset !!\n", ioc->name); |
| 3839 | |
| 3840 | writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT, |
| 3841 | &ioc->chip->Doorbell); |
| 3842 | if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) { |
| 3843 | r = -EFAULT; |
| 3844 | goto out; |
| 3845 | } |
| 3846 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, |
| 3847 | timeout, sleep_flag); |
| 3848 | if (ioc_state) { |
| 3849 | pr_err(MPT3SAS_FMT |
| 3850 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 3851 | ioc->name, __func__, ioc_state); |
| 3852 | r = -EFAULT; |
| 3853 | goto out; |
| 3854 | } |
| 3855 | out: |
| 3856 | pr_info(MPT3SAS_FMT "message unit reset: %s\n", |
| 3857 | ioc->name, ((r == 0) ? "SUCCESS" : "FAILED")); |
| 3858 | return r; |
| 3859 | } |
| 3860 | |
| 3861 | /** |
| 3862 | * _base_handshake_req_reply_wait - send request thru doorbell interface |
| 3863 | * @ioc: per adapter object |
| 3864 | * @request_bytes: request length |
| 3865 | * @request: pointer having request payload |
| 3866 | * @reply_bytes: reply length |
| 3867 | * @reply: pointer to reply payload |
| 3868 | * @timeout: timeout in second |
| 3869 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 3870 | * |
| 3871 | * Returns 0 for success, non-zero for failure. |
| 3872 | */ |
| 3873 | static int |
| 3874 | _base_handshake_req_reply_wait(struct MPT3SAS_ADAPTER *ioc, int request_bytes, |
| 3875 | u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag) |
| 3876 | { |
| 3877 | MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply; |
| 3878 | int i; |
| 3879 | u8 failed; |
| 3880 | u16 dummy; |
| 3881 | __le32 *mfp; |
| 3882 | |
| 3883 | /* make sure doorbell is not in use */ |
| 3884 | if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) { |
| 3885 | pr_err(MPT3SAS_FMT |
| 3886 | "doorbell is in use (line=%d)\n", |
| 3887 | ioc->name, __LINE__); |
| 3888 | return -EFAULT; |
| 3889 | } |
| 3890 | |
| 3891 | /* clear pending doorbell interrupts from previous state changes */ |
| 3892 | if (readl(&ioc->chip->HostInterruptStatus) & |
| 3893 | MPI2_HIS_IOC2SYS_DB_STATUS) |
| 3894 | writel(0, &ioc->chip->HostInterruptStatus); |
| 3895 | |
| 3896 | /* send message to ioc */ |
| 3897 | writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) | |
| 3898 | ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)), |
| 3899 | &ioc->chip->Doorbell); |
| 3900 | |
| 3901 | if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) { |
| 3902 | pr_err(MPT3SAS_FMT |
| 3903 | "doorbell handshake int failed (line=%d)\n", |
| 3904 | ioc->name, __LINE__); |
| 3905 | return -EFAULT; |
| 3906 | } |
| 3907 | writel(0, &ioc->chip->HostInterruptStatus); |
| 3908 | |
| 3909 | if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) { |
| 3910 | pr_err(MPT3SAS_FMT |
| 3911 | "doorbell handshake ack failed (line=%d)\n", |
| 3912 | ioc->name, __LINE__); |
| 3913 | return -EFAULT; |
| 3914 | } |
| 3915 | |
| 3916 | /* send message 32-bits at a time */ |
| 3917 | for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) { |
| 3918 | writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell); |
| 3919 | if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) |
| 3920 | failed = 1; |
| 3921 | } |
| 3922 | |
| 3923 | if (failed) { |
| 3924 | pr_err(MPT3SAS_FMT |
| 3925 | "doorbell handshake sending request failed (line=%d)\n", |
| 3926 | ioc->name, __LINE__); |
| 3927 | return -EFAULT; |
| 3928 | } |
| 3929 | |
| 3930 | /* now wait for the reply */ |
| 3931 | if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) { |
| 3932 | pr_err(MPT3SAS_FMT |
| 3933 | "doorbell handshake int failed (line=%d)\n", |
| 3934 | ioc->name, __LINE__); |
| 3935 | return -EFAULT; |
| 3936 | } |
| 3937 | |
| 3938 | /* read the first two 16-bits, it gives the total length of the reply */ |
| 3939 | reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell) |
| 3940 | & MPI2_DOORBELL_DATA_MASK); |
| 3941 | writel(0, &ioc->chip->HostInterruptStatus); |
| 3942 | if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) { |
| 3943 | pr_err(MPT3SAS_FMT |
| 3944 | "doorbell handshake int failed (line=%d)\n", |
| 3945 | ioc->name, __LINE__); |
| 3946 | return -EFAULT; |
| 3947 | } |
| 3948 | reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell) |
| 3949 | & MPI2_DOORBELL_DATA_MASK); |
| 3950 | writel(0, &ioc->chip->HostInterruptStatus); |
| 3951 | |
| 3952 | for (i = 2; i < default_reply->MsgLength * 2; i++) { |
| 3953 | if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) { |
| 3954 | pr_err(MPT3SAS_FMT |
| 3955 | "doorbell handshake int failed (line=%d)\n", |
| 3956 | ioc->name, __LINE__); |
| 3957 | return -EFAULT; |
| 3958 | } |
| 3959 | if (i >= reply_bytes/2) /* overflow case */ |
| 3960 | dummy = readl(&ioc->chip->Doorbell); |
| 3961 | else |
| 3962 | reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell) |
| 3963 | & MPI2_DOORBELL_DATA_MASK); |
| 3964 | writel(0, &ioc->chip->HostInterruptStatus); |
| 3965 | } |
| 3966 | |
| 3967 | _base_wait_for_doorbell_int(ioc, 5, sleep_flag); |
| 3968 | if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) { |
| 3969 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 3970 | "doorbell is in use (line=%d)\n", ioc->name, __LINE__)); |
| 3971 | } |
| 3972 | writel(0, &ioc->chip->HostInterruptStatus); |
| 3973 | |
| 3974 | if (ioc->logging_level & MPT_DEBUG_INIT) { |
| 3975 | mfp = (__le32 *)reply; |
| 3976 | pr_info("\toffset:data\n"); |
| 3977 | for (i = 0; i < reply_bytes/4; i++) |
| 3978 | pr_info("\t[0x%02x]:%08x\n", i*4, |
| 3979 | le32_to_cpu(mfp[i])); |
| 3980 | } |
| 3981 | return 0; |
| 3982 | } |
| 3983 | |
| 3984 | /** |
| 3985 | * mpt3sas_base_sas_iounit_control - send sas iounit control to FW |
| 3986 | * @ioc: per adapter object |
| 3987 | * @mpi_reply: the reply payload from FW |
| 3988 | * @mpi_request: the request payload sent to FW |
| 3989 | * |
| 3990 | * The SAS IO Unit Control Request message allows the host to perform low-level |
| 3991 | * operations, such as resets on the PHYs of the IO Unit, also allows the host |
| 3992 | * to obtain the IOC assigned device handles for a device if it has other |
| 3993 | * identifying information about the device, in addition allows the host to |
| 3994 | * remove IOC resources associated with the device. |
| 3995 | * |
| 3996 | * Returns 0 for success, non-zero for failure. |
| 3997 | */ |
| 3998 | int |
| 3999 | mpt3sas_base_sas_iounit_control(struct MPT3SAS_ADAPTER *ioc, |
| 4000 | Mpi2SasIoUnitControlReply_t *mpi_reply, |
| 4001 | Mpi2SasIoUnitControlRequest_t *mpi_request) |
| 4002 | { |
| 4003 | u16 smid; |
| 4004 | u32 ioc_state; |
| 4005 | unsigned long timeleft; |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 4006 | bool issue_reset = false; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4007 | int rc; |
| 4008 | void *request; |
| 4009 | u16 wait_state_count; |
| 4010 | |
| 4011 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4012 | __func__)); |
| 4013 | |
| 4014 | mutex_lock(&ioc->base_cmds.mutex); |
| 4015 | |
| 4016 | if (ioc->base_cmds.status != MPT3_CMD_NOT_USED) { |
| 4017 | pr_err(MPT3SAS_FMT "%s: base_cmd in use\n", |
| 4018 | ioc->name, __func__); |
| 4019 | rc = -EAGAIN; |
| 4020 | goto out; |
| 4021 | } |
| 4022 | |
| 4023 | wait_state_count = 0; |
| 4024 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 4025 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 4026 | if (wait_state_count++ == 10) { |
| 4027 | pr_err(MPT3SAS_FMT |
| 4028 | "%s: failed due to ioc not operational\n", |
| 4029 | ioc->name, __func__); |
| 4030 | rc = -EFAULT; |
| 4031 | goto out; |
| 4032 | } |
| 4033 | ssleep(1); |
| 4034 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 4035 | pr_info(MPT3SAS_FMT |
| 4036 | "%s: waiting for operational state(count=%d)\n", |
| 4037 | ioc->name, __func__, wait_state_count); |
| 4038 | } |
| 4039 | |
| 4040 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 4041 | if (!smid) { |
| 4042 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 4043 | ioc->name, __func__); |
| 4044 | rc = -EAGAIN; |
| 4045 | goto out; |
| 4046 | } |
| 4047 | |
| 4048 | rc = 0; |
| 4049 | ioc->base_cmds.status = MPT3_CMD_PENDING; |
| 4050 | request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 4051 | ioc->base_cmds.smid = smid; |
| 4052 | memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t)); |
| 4053 | if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || |
| 4054 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) |
| 4055 | ioc->ioc_link_reset_in_progress = 1; |
| 4056 | init_completion(&ioc->base_cmds.done); |
| 4057 | mpt3sas_base_put_smid_default(ioc, smid); |
| 4058 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, |
| 4059 | msecs_to_jiffies(10000)); |
| 4060 | if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET || |
| 4061 | mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) && |
| 4062 | ioc->ioc_link_reset_in_progress) |
| 4063 | ioc->ioc_link_reset_in_progress = 0; |
| 4064 | if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { |
| 4065 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 4066 | ioc->name, __func__); |
| 4067 | _debug_dump_mf(mpi_request, |
| 4068 | sizeof(Mpi2SasIoUnitControlRequest_t)/4); |
| 4069 | if (!(ioc->base_cmds.status & MPT3_CMD_RESET)) |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 4070 | issue_reset = true; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4071 | goto issue_host_reset; |
| 4072 | } |
| 4073 | if (ioc->base_cmds.status & MPT3_CMD_REPLY_VALID) |
| 4074 | memcpy(mpi_reply, ioc->base_cmds.reply, |
| 4075 | sizeof(Mpi2SasIoUnitControlReply_t)); |
| 4076 | else |
| 4077 | memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t)); |
| 4078 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 4079 | goto out; |
| 4080 | |
| 4081 | issue_host_reset: |
| 4082 | if (issue_reset) |
| 4083 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 4084 | FORCE_BIG_HAMMER); |
| 4085 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 4086 | rc = -EFAULT; |
| 4087 | out: |
| 4088 | mutex_unlock(&ioc->base_cmds.mutex); |
| 4089 | return rc; |
| 4090 | } |
| 4091 | |
| 4092 | /** |
| 4093 | * mpt3sas_base_scsi_enclosure_processor - sending request to sep device |
| 4094 | * @ioc: per adapter object |
| 4095 | * @mpi_reply: the reply payload from FW |
| 4096 | * @mpi_request: the request payload sent to FW |
| 4097 | * |
| 4098 | * The SCSI Enclosure Processor request message causes the IOC to |
| 4099 | * communicate with SES devices to control LED status signals. |
| 4100 | * |
| 4101 | * Returns 0 for success, non-zero for failure. |
| 4102 | */ |
| 4103 | int |
| 4104 | mpt3sas_base_scsi_enclosure_processor(struct MPT3SAS_ADAPTER *ioc, |
| 4105 | Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request) |
| 4106 | { |
| 4107 | u16 smid; |
| 4108 | u32 ioc_state; |
| 4109 | unsigned long timeleft; |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 4110 | bool issue_reset = false; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4111 | int rc; |
| 4112 | void *request; |
| 4113 | u16 wait_state_count; |
| 4114 | |
| 4115 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4116 | __func__)); |
| 4117 | |
| 4118 | mutex_lock(&ioc->base_cmds.mutex); |
| 4119 | |
| 4120 | if (ioc->base_cmds.status != MPT3_CMD_NOT_USED) { |
| 4121 | pr_err(MPT3SAS_FMT "%s: base_cmd in use\n", |
| 4122 | ioc->name, __func__); |
| 4123 | rc = -EAGAIN; |
| 4124 | goto out; |
| 4125 | } |
| 4126 | |
| 4127 | wait_state_count = 0; |
| 4128 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 4129 | while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) { |
| 4130 | if (wait_state_count++ == 10) { |
| 4131 | pr_err(MPT3SAS_FMT |
| 4132 | "%s: failed due to ioc not operational\n", |
| 4133 | ioc->name, __func__); |
| 4134 | rc = -EFAULT; |
| 4135 | goto out; |
| 4136 | } |
| 4137 | ssleep(1); |
| 4138 | ioc_state = mpt3sas_base_get_iocstate(ioc, 1); |
| 4139 | pr_info(MPT3SAS_FMT |
| 4140 | "%s: waiting for operational state(count=%d)\n", |
| 4141 | ioc->name, |
| 4142 | __func__, wait_state_count); |
| 4143 | } |
| 4144 | |
| 4145 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 4146 | if (!smid) { |
| 4147 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 4148 | ioc->name, __func__); |
| 4149 | rc = -EAGAIN; |
| 4150 | goto out; |
| 4151 | } |
| 4152 | |
| 4153 | rc = 0; |
| 4154 | ioc->base_cmds.status = MPT3_CMD_PENDING; |
| 4155 | request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 4156 | ioc->base_cmds.smid = smid; |
| 4157 | memcpy(request, mpi_request, sizeof(Mpi2SepReply_t)); |
| 4158 | init_completion(&ioc->base_cmds.done); |
| 4159 | mpt3sas_base_put_smid_default(ioc, smid); |
| 4160 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, |
| 4161 | msecs_to_jiffies(10000)); |
| 4162 | if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { |
| 4163 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 4164 | ioc->name, __func__); |
| 4165 | _debug_dump_mf(mpi_request, |
| 4166 | sizeof(Mpi2SepRequest_t)/4); |
| 4167 | if (!(ioc->base_cmds.status & MPT3_CMD_RESET)) |
Dan Carpenter | eb44552 | 2014-12-04 13:57:05 +0300 | [diff] [blame] | 4168 | issue_reset = false; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4169 | goto issue_host_reset; |
| 4170 | } |
| 4171 | if (ioc->base_cmds.status & MPT3_CMD_REPLY_VALID) |
| 4172 | memcpy(mpi_reply, ioc->base_cmds.reply, |
| 4173 | sizeof(Mpi2SepReply_t)); |
| 4174 | else |
| 4175 | memset(mpi_reply, 0, sizeof(Mpi2SepReply_t)); |
| 4176 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 4177 | goto out; |
| 4178 | |
| 4179 | issue_host_reset: |
| 4180 | if (issue_reset) |
| 4181 | mpt3sas_base_hard_reset_handler(ioc, CAN_SLEEP, |
| 4182 | FORCE_BIG_HAMMER); |
| 4183 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 4184 | rc = -EFAULT; |
| 4185 | out: |
| 4186 | mutex_unlock(&ioc->base_cmds.mutex); |
| 4187 | return rc; |
| 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * _base_get_port_facts - obtain port facts reply and save in ioc |
| 4192 | * @ioc: per adapter object |
| 4193 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4194 | * |
| 4195 | * Returns 0 for success, non-zero for failure. |
| 4196 | */ |
| 4197 | static int |
| 4198 | _base_get_port_facts(struct MPT3SAS_ADAPTER *ioc, int port, int sleep_flag) |
| 4199 | { |
| 4200 | Mpi2PortFactsRequest_t mpi_request; |
| 4201 | Mpi2PortFactsReply_t mpi_reply; |
| 4202 | struct mpt3sas_port_facts *pfacts; |
| 4203 | int mpi_reply_sz, mpi_request_sz, r; |
| 4204 | |
| 4205 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4206 | __func__)); |
| 4207 | |
| 4208 | mpi_reply_sz = sizeof(Mpi2PortFactsReply_t); |
| 4209 | mpi_request_sz = sizeof(Mpi2PortFactsRequest_t); |
| 4210 | memset(&mpi_request, 0, mpi_request_sz); |
| 4211 | mpi_request.Function = MPI2_FUNCTION_PORT_FACTS; |
| 4212 | mpi_request.PortNumber = port; |
| 4213 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, |
| 4214 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP); |
| 4215 | |
| 4216 | if (r != 0) { |
| 4217 | pr_err(MPT3SAS_FMT "%s: handshake failed (r=%d)\n", |
| 4218 | ioc->name, __func__, r); |
| 4219 | return r; |
| 4220 | } |
| 4221 | |
| 4222 | pfacts = &ioc->pfacts[port]; |
| 4223 | memset(pfacts, 0, sizeof(struct mpt3sas_port_facts)); |
| 4224 | pfacts->PortNumber = mpi_reply.PortNumber; |
| 4225 | pfacts->VP_ID = mpi_reply.VP_ID; |
| 4226 | pfacts->VF_ID = mpi_reply.VF_ID; |
| 4227 | pfacts->MaxPostedCmdBuffers = |
| 4228 | le16_to_cpu(mpi_reply.MaxPostedCmdBuffers); |
| 4229 | |
| 4230 | return 0; |
| 4231 | } |
| 4232 | |
| 4233 | /** |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 4234 | * _base_wait_for_iocstate - Wait until the card is in READY or OPERATIONAL |
| 4235 | * @ioc: per adapter object |
| 4236 | * @timeout: |
| 4237 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4238 | * |
| 4239 | * Returns 0 for success, non-zero for failure. |
| 4240 | */ |
| 4241 | static int |
| 4242 | _base_wait_for_iocstate(struct MPT3SAS_ADAPTER *ioc, int timeout, |
| 4243 | int sleep_flag) |
| 4244 | { |
| 4245 | u32 ioc_state; |
| 4246 | int rc; |
| 4247 | |
| 4248 | dinitprintk(ioc, printk(MPT3SAS_FMT "%s\n", ioc->name, |
| 4249 | __func__)); |
| 4250 | |
| 4251 | if (ioc->pci_error_recovery) { |
| 4252 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 4253 | "%s: host in pci error recovery\n", ioc->name, __func__)); |
| 4254 | return -EFAULT; |
| 4255 | } |
| 4256 | |
| 4257 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 4258 | dhsprintk(ioc, printk(MPT3SAS_FMT "%s: ioc_state(0x%08x)\n", |
| 4259 | ioc->name, __func__, ioc_state)); |
| 4260 | |
| 4261 | if (((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) || |
| 4262 | (ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) |
| 4263 | return 0; |
| 4264 | |
| 4265 | if (ioc_state & MPI2_DOORBELL_USED) { |
| 4266 | dhsprintk(ioc, printk(MPT3SAS_FMT |
| 4267 | "unexpected doorbell active!\n", ioc->name)); |
| 4268 | goto issue_diag_reset; |
| 4269 | } |
| 4270 | |
| 4271 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 4272 | mpt3sas_base_fault_info(ioc, ioc_state & |
| 4273 | MPI2_DOORBELL_DATA_MASK); |
| 4274 | goto issue_diag_reset; |
| 4275 | } |
| 4276 | |
| 4277 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, |
| 4278 | timeout, sleep_flag); |
| 4279 | if (ioc_state) { |
| 4280 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 4281 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 4282 | ioc->name, __func__, ioc_state)); |
| 4283 | return -EFAULT; |
| 4284 | } |
| 4285 | |
| 4286 | issue_diag_reset: |
| 4287 | rc = _base_diag_reset(ioc, sleep_flag); |
| 4288 | return rc; |
| 4289 | } |
| 4290 | |
| 4291 | /** |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4292 | * _base_get_ioc_facts - obtain ioc facts reply and save in ioc |
| 4293 | * @ioc: per adapter object |
| 4294 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4295 | * |
| 4296 | * Returns 0 for success, non-zero for failure. |
| 4297 | */ |
| 4298 | static int |
| 4299 | _base_get_ioc_facts(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 4300 | { |
| 4301 | Mpi2IOCFactsRequest_t mpi_request; |
| 4302 | Mpi2IOCFactsReply_t mpi_reply; |
| 4303 | struct mpt3sas_facts *facts; |
| 4304 | int mpi_reply_sz, mpi_request_sz, r; |
| 4305 | |
| 4306 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4307 | __func__)); |
| 4308 | |
Sreekanth Reddy | 4dc8c80 | 2015-06-30 12:24:48 +0530 | [diff] [blame] | 4309 | r = _base_wait_for_iocstate(ioc, 10, sleep_flag); |
| 4310 | if (r) { |
| 4311 | dfailprintk(ioc, printk(MPT3SAS_FMT |
| 4312 | "%s: failed getting to correct state\n", |
| 4313 | ioc->name, __func__)); |
| 4314 | return r; |
| 4315 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4316 | mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t); |
| 4317 | mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t); |
| 4318 | memset(&mpi_request, 0, mpi_request_sz); |
| 4319 | mpi_request.Function = MPI2_FUNCTION_IOC_FACTS; |
| 4320 | r = _base_handshake_req_reply_wait(ioc, mpi_request_sz, |
| 4321 | (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP); |
| 4322 | |
| 4323 | if (r != 0) { |
| 4324 | pr_err(MPT3SAS_FMT "%s: handshake failed (r=%d)\n", |
| 4325 | ioc->name, __func__, r); |
| 4326 | return r; |
| 4327 | } |
| 4328 | |
| 4329 | facts = &ioc->facts; |
| 4330 | memset(facts, 0, sizeof(struct mpt3sas_facts)); |
| 4331 | facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion); |
| 4332 | facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion); |
| 4333 | facts->VP_ID = mpi_reply.VP_ID; |
| 4334 | facts->VF_ID = mpi_reply.VF_ID; |
| 4335 | facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions); |
| 4336 | facts->MaxChainDepth = mpi_reply.MaxChainDepth; |
| 4337 | facts->WhoInit = mpi_reply.WhoInit; |
| 4338 | facts->NumberOfPorts = mpi_reply.NumberOfPorts; |
| 4339 | facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors; |
| 4340 | facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit); |
| 4341 | facts->MaxReplyDescriptorPostQueueDepth = |
| 4342 | le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth); |
| 4343 | facts->ProductID = le16_to_cpu(mpi_reply.ProductID); |
| 4344 | facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities); |
| 4345 | if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID)) |
| 4346 | ioc->ir_firmware = 1; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4347 | if ((facts->IOCCapabilities & |
| 4348 | MPI2_IOCFACTS_CAPABILITY_RDPQ_ARRAY_CAPABLE)) |
| 4349 | ioc->rdpq_array_capable = 1; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4350 | facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word); |
| 4351 | facts->IOCRequestFrameSize = |
| 4352 | le16_to_cpu(mpi_reply.IOCRequestFrameSize); |
Suganath prabu Subramani | ebb3024 | 2016-01-28 12:07:04 +0530 | [diff] [blame] | 4353 | if (ioc->hba_mpi_version_belonged != MPI2_VERSION) { |
| 4354 | facts->IOCMaxChainSegmentSize = |
| 4355 | le16_to_cpu(mpi_reply.IOCMaxChainSegmentSize); |
| 4356 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4357 | facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators); |
| 4358 | facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets); |
| 4359 | ioc->shost->max_id = -1; |
| 4360 | facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders); |
| 4361 | facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures); |
| 4362 | facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags); |
| 4363 | facts->HighPriorityCredit = |
| 4364 | le16_to_cpu(mpi_reply.HighPriorityCredit); |
| 4365 | facts->ReplyFrameSize = mpi_reply.ReplyFrameSize; |
| 4366 | facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle); |
| 4367 | |
| 4368 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4369 | "hba queue depth(%d), max chains per io(%d)\n", |
| 4370 | ioc->name, facts->RequestCredit, |
| 4371 | facts->MaxChainDepth)); |
| 4372 | dinitprintk(ioc, pr_info(MPT3SAS_FMT |
| 4373 | "request frame size(%d), reply frame size(%d)\n", ioc->name, |
| 4374 | facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4)); |
| 4375 | return 0; |
| 4376 | } |
| 4377 | |
| 4378 | /** |
| 4379 | * _base_send_ioc_init - send ioc_init to firmware |
| 4380 | * @ioc: per adapter object |
| 4381 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4382 | * |
| 4383 | * Returns 0 for success, non-zero for failure. |
| 4384 | */ |
| 4385 | static int |
| 4386 | _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 4387 | { |
| 4388 | Mpi2IOCInitRequest_t mpi_request; |
| 4389 | Mpi2IOCInitReply_t mpi_reply; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4390 | int i, r = 0; |
Tina Ruchandani | 23409bd | 2016-04-13 00:01:40 -0700 | [diff] [blame] | 4391 | ktime_t current_time; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4392 | u16 ioc_status; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4393 | u32 reply_post_free_array_sz = 0; |
| 4394 | Mpi2IOCInitRDPQArrayEntry *reply_post_free_array = NULL; |
| 4395 | dma_addr_t reply_post_free_array_dma; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4396 | |
| 4397 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4398 | __func__)); |
| 4399 | |
| 4400 | memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t)); |
| 4401 | mpi_request.Function = MPI2_FUNCTION_IOC_INIT; |
| 4402 | mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER; |
| 4403 | mpi_request.VF_ID = 0; /* TODO */ |
| 4404 | mpi_request.VP_ID = 0; |
Sreekanth Reddy | d357e84 | 2015-11-11 17:30:22 +0530 | [diff] [blame] | 4405 | mpi_request.MsgVersion = cpu_to_le16(ioc->hba_mpi_version_belonged); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4406 | mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION); |
| 4407 | |
| 4408 | if (_base_is_controller_msix_enabled(ioc)) |
| 4409 | mpi_request.HostMSIxVectors = ioc->reply_queue_count; |
| 4410 | mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4); |
| 4411 | mpi_request.ReplyDescriptorPostQueueDepth = |
| 4412 | cpu_to_le16(ioc->reply_post_queue_depth); |
| 4413 | mpi_request.ReplyFreeQueueDepth = |
| 4414 | cpu_to_le16(ioc->reply_free_queue_depth); |
| 4415 | |
| 4416 | mpi_request.SenseBufferAddressHigh = |
| 4417 | cpu_to_le32((u64)ioc->sense_dma >> 32); |
| 4418 | mpi_request.SystemReplyAddressHigh = |
| 4419 | cpu_to_le32((u64)ioc->reply_dma >> 32); |
| 4420 | mpi_request.SystemRequestFrameBaseAddress = |
| 4421 | cpu_to_le64((u64)ioc->request_dma); |
| 4422 | mpi_request.ReplyFreeQueueAddress = |
| 4423 | cpu_to_le64((u64)ioc->reply_free_dma); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4424 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4425 | if (ioc->rdpq_array_enable) { |
| 4426 | reply_post_free_array_sz = ioc->reply_queue_count * |
| 4427 | sizeof(Mpi2IOCInitRDPQArrayEntry); |
| 4428 | reply_post_free_array = pci_alloc_consistent(ioc->pdev, |
| 4429 | reply_post_free_array_sz, &reply_post_free_array_dma); |
| 4430 | if (!reply_post_free_array) { |
| 4431 | pr_err(MPT3SAS_FMT |
| 4432 | "reply_post_free_array: pci_alloc_consistent failed\n", |
| 4433 | ioc->name); |
| 4434 | r = -ENOMEM; |
| 4435 | goto out; |
| 4436 | } |
| 4437 | memset(reply_post_free_array, 0, reply_post_free_array_sz); |
| 4438 | for (i = 0; i < ioc->reply_queue_count; i++) |
| 4439 | reply_post_free_array[i].RDPQBaseAddress = |
| 4440 | cpu_to_le64( |
| 4441 | (u64)ioc->reply_post[i].reply_post_free_dma); |
| 4442 | mpi_request.MsgFlags = MPI2_IOCINIT_MSGFLAG_RDPQ_ARRAY_MODE; |
| 4443 | mpi_request.ReplyDescriptorPostQueueAddress = |
| 4444 | cpu_to_le64((u64)reply_post_free_array_dma); |
| 4445 | } else { |
| 4446 | mpi_request.ReplyDescriptorPostQueueAddress = |
| 4447 | cpu_to_le64((u64)ioc->reply_post[0].reply_post_free_dma); |
| 4448 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4449 | |
| 4450 | /* This time stamp specifies number of milliseconds |
| 4451 | * since epoch ~ midnight January 1, 1970. |
| 4452 | */ |
Tina Ruchandani | 23409bd | 2016-04-13 00:01:40 -0700 | [diff] [blame] | 4453 | current_time = ktime_get_real(); |
| 4454 | mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time)); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4455 | |
| 4456 | if (ioc->logging_level & MPT_DEBUG_INIT) { |
| 4457 | __le32 *mfp; |
| 4458 | int i; |
| 4459 | |
| 4460 | mfp = (__le32 *)&mpi_request; |
| 4461 | pr_info("\toffset:data\n"); |
| 4462 | for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++) |
| 4463 | pr_info("\t[0x%02x]:%08x\n", i*4, |
| 4464 | le32_to_cpu(mfp[i])); |
| 4465 | } |
| 4466 | |
| 4467 | r = _base_handshake_req_reply_wait(ioc, |
| 4468 | sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request, |
| 4469 | sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10, |
| 4470 | sleep_flag); |
| 4471 | |
| 4472 | if (r != 0) { |
| 4473 | pr_err(MPT3SAS_FMT "%s: handshake failed (r=%d)\n", |
| 4474 | ioc->name, __func__, r); |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4475 | goto out; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4479 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS || |
| 4480 | mpi_reply.IOCLogInfo) { |
| 4481 | pr_err(MPT3SAS_FMT "%s: failed\n", ioc->name, __func__); |
| 4482 | r = -EIO; |
| 4483 | } |
| 4484 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 4485 | out: |
| 4486 | if (reply_post_free_array) |
| 4487 | pci_free_consistent(ioc->pdev, reply_post_free_array_sz, |
| 4488 | reply_post_free_array, |
| 4489 | reply_post_free_array_dma); |
| 4490 | return r; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4491 | } |
| 4492 | |
| 4493 | /** |
| 4494 | * mpt3sas_port_enable_done - command completion routine for port enable |
| 4495 | * @ioc: per adapter object |
| 4496 | * @smid: system request message index |
| 4497 | * @msix_index: MSIX table index supplied by the OS |
| 4498 | * @reply: reply message frame(lower 32bit addr) |
| 4499 | * |
| 4500 | * Return 1 meaning mf should be freed from _base_interrupt |
| 4501 | * 0 means the mf is freed from this function. |
| 4502 | */ |
| 4503 | u8 |
| 4504 | mpt3sas_port_enable_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, |
| 4505 | u32 reply) |
| 4506 | { |
| 4507 | MPI2DefaultReply_t *mpi_reply; |
| 4508 | u16 ioc_status; |
| 4509 | |
| 4510 | if (ioc->port_enable_cmds.status == MPT3_CMD_NOT_USED) |
| 4511 | return 1; |
| 4512 | |
| 4513 | mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); |
| 4514 | if (!mpi_reply) |
| 4515 | return 1; |
| 4516 | |
| 4517 | if (mpi_reply->Function != MPI2_FUNCTION_PORT_ENABLE) |
| 4518 | return 1; |
| 4519 | |
| 4520 | ioc->port_enable_cmds.status &= ~MPT3_CMD_PENDING; |
| 4521 | ioc->port_enable_cmds.status |= MPT3_CMD_COMPLETE; |
| 4522 | ioc->port_enable_cmds.status |= MPT3_CMD_REPLY_VALID; |
| 4523 | memcpy(ioc->port_enable_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); |
| 4524 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4525 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) |
| 4526 | ioc->port_enable_failed = 1; |
| 4527 | |
| 4528 | if (ioc->is_driver_loading) { |
| 4529 | if (ioc_status == MPI2_IOCSTATUS_SUCCESS) { |
| 4530 | mpt3sas_port_enable_complete(ioc); |
| 4531 | return 1; |
| 4532 | } else { |
| 4533 | ioc->start_scan_failed = ioc_status; |
| 4534 | ioc->start_scan = 0; |
| 4535 | return 1; |
| 4536 | } |
| 4537 | } |
| 4538 | complete(&ioc->port_enable_cmds.done); |
| 4539 | return 1; |
| 4540 | } |
| 4541 | |
| 4542 | /** |
| 4543 | * _base_send_port_enable - send port_enable(discovery stuff) to firmware |
| 4544 | * @ioc: per adapter object |
| 4545 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4546 | * |
| 4547 | * Returns 0 for success, non-zero for failure. |
| 4548 | */ |
| 4549 | static int |
| 4550 | _base_send_port_enable(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 4551 | { |
| 4552 | Mpi2PortEnableRequest_t *mpi_request; |
| 4553 | Mpi2PortEnableReply_t *mpi_reply; |
| 4554 | unsigned long timeleft; |
| 4555 | int r = 0; |
| 4556 | u16 smid; |
| 4557 | u16 ioc_status; |
| 4558 | |
| 4559 | pr_info(MPT3SAS_FMT "sending port enable !!\n", ioc->name); |
| 4560 | |
| 4561 | if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { |
| 4562 | pr_err(MPT3SAS_FMT "%s: internal command already in use\n", |
| 4563 | ioc->name, __func__); |
| 4564 | return -EAGAIN; |
| 4565 | } |
| 4566 | |
| 4567 | smid = mpt3sas_base_get_smid(ioc, ioc->port_enable_cb_idx); |
| 4568 | if (!smid) { |
| 4569 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 4570 | ioc->name, __func__); |
| 4571 | return -EAGAIN; |
| 4572 | } |
| 4573 | |
| 4574 | ioc->port_enable_cmds.status = MPT3_CMD_PENDING; |
| 4575 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 4576 | ioc->port_enable_cmds.smid = smid; |
| 4577 | memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); |
| 4578 | mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; |
| 4579 | |
| 4580 | init_completion(&ioc->port_enable_cmds.done); |
| 4581 | mpt3sas_base_put_smid_default(ioc, smid); |
| 4582 | timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done, |
| 4583 | 300*HZ); |
| 4584 | if (!(ioc->port_enable_cmds.status & MPT3_CMD_COMPLETE)) { |
| 4585 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 4586 | ioc->name, __func__); |
| 4587 | _debug_dump_mf(mpi_request, |
| 4588 | sizeof(Mpi2PortEnableRequest_t)/4); |
| 4589 | if (ioc->port_enable_cmds.status & MPT3_CMD_RESET) |
| 4590 | r = -EFAULT; |
| 4591 | else |
| 4592 | r = -ETIME; |
| 4593 | goto out; |
| 4594 | } |
| 4595 | |
| 4596 | mpi_reply = ioc->port_enable_cmds.reply; |
| 4597 | ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK; |
| 4598 | if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { |
| 4599 | pr_err(MPT3SAS_FMT "%s: failed with (ioc_status=0x%08x)\n", |
| 4600 | ioc->name, __func__, ioc_status); |
| 4601 | r = -EFAULT; |
| 4602 | goto out; |
| 4603 | } |
| 4604 | |
| 4605 | out: |
| 4606 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
| 4607 | pr_info(MPT3SAS_FMT "port enable: %s\n", ioc->name, ((r == 0) ? |
| 4608 | "SUCCESS" : "FAILED")); |
| 4609 | return r; |
| 4610 | } |
| 4611 | |
| 4612 | /** |
| 4613 | * mpt3sas_port_enable - initiate firmware discovery (don't wait for reply) |
| 4614 | * @ioc: per adapter object |
| 4615 | * |
| 4616 | * Returns 0 for success, non-zero for failure. |
| 4617 | */ |
| 4618 | int |
| 4619 | mpt3sas_port_enable(struct MPT3SAS_ADAPTER *ioc) |
| 4620 | { |
| 4621 | Mpi2PortEnableRequest_t *mpi_request; |
| 4622 | u16 smid; |
| 4623 | |
| 4624 | pr_info(MPT3SAS_FMT "sending port enable !!\n", ioc->name); |
| 4625 | |
| 4626 | if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { |
| 4627 | pr_err(MPT3SAS_FMT "%s: internal command already in use\n", |
| 4628 | ioc->name, __func__); |
| 4629 | return -EAGAIN; |
| 4630 | } |
| 4631 | |
| 4632 | smid = mpt3sas_base_get_smid(ioc, ioc->port_enable_cb_idx); |
| 4633 | if (!smid) { |
| 4634 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 4635 | ioc->name, __func__); |
| 4636 | return -EAGAIN; |
| 4637 | } |
| 4638 | |
| 4639 | ioc->port_enable_cmds.status = MPT3_CMD_PENDING; |
| 4640 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 4641 | ioc->port_enable_cmds.smid = smid; |
| 4642 | memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); |
| 4643 | mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; |
| 4644 | |
| 4645 | mpt3sas_base_put_smid_default(ioc, smid); |
| 4646 | return 0; |
| 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * _base_determine_wait_on_discovery - desposition |
| 4651 | * @ioc: per adapter object |
| 4652 | * |
| 4653 | * Decide whether to wait on discovery to complete. Used to either |
| 4654 | * locate boot device, or report volumes ahead of physical devices. |
| 4655 | * |
| 4656 | * Returns 1 for wait, 0 for don't wait |
| 4657 | */ |
| 4658 | static int |
| 4659 | _base_determine_wait_on_discovery(struct MPT3SAS_ADAPTER *ioc) |
| 4660 | { |
| 4661 | /* We wait for discovery to complete if IR firmware is loaded. |
| 4662 | * The sas topology events arrive before PD events, so we need time to |
| 4663 | * turn on the bit in ioc->pd_handles to indicate PD |
| 4664 | * Also, it maybe required to report Volumes ahead of physical |
| 4665 | * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set. |
| 4666 | */ |
| 4667 | if (ioc->ir_firmware) |
| 4668 | return 1; |
| 4669 | |
| 4670 | /* if no Bios, then we don't need to wait */ |
| 4671 | if (!ioc->bios_pg3.BiosVersion) |
| 4672 | return 0; |
| 4673 | |
| 4674 | /* Bios is present, then we drop down here. |
| 4675 | * |
| 4676 | * If there any entries in the Bios Page 2, then we wait |
| 4677 | * for discovery to complete. |
| 4678 | */ |
| 4679 | |
| 4680 | /* Current Boot Device */ |
| 4681 | if ((ioc->bios_pg2.CurrentBootDeviceForm & |
| 4682 | MPI2_BIOSPAGE2_FORM_MASK) == |
| 4683 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && |
| 4684 | /* Request Boot Device */ |
| 4685 | (ioc->bios_pg2.ReqBootDeviceForm & |
| 4686 | MPI2_BIOSPAGE2_FORM_MASK) == |
| 4687 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED && |
| 4688 | /* Alternate Request Boot Device */ |
| 4689 | (ioc->bios_pg2.ReqAltBootDeviceForm & |
| 4690 | MPI2_BIOSPAGE2_FORM_MASK) == |
| 4691 | MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED) |
| 4692 | return 0; |
| 4693 | |
| 4694 | return 1; |
| 4695 | } |
| 4696 | |
| 4697 | /** |
| 4698 | * _base_unmask_events - turn on notification for this event |
| 4699 | * @ioc: per adapter object |
| 4700 | * @event: firmware event |
| 4701 | * |
| 4702 | * The mask is stored in ioc->event_masks. |
| 4703 | */ |
| 4704 | static void |
| 4705 | _base_unmask_events(struct MPT3SAS_ADAPTER *ioc, u16 event) |
| 4706 | { |
| 4707 | u32 desired_event; |
| 4708 | |
| 4709 | if (event >= 128) |
| 4710 | return; |
| 4711 | |
| 4712 | desired_event = (1 << (event % 32)); |
| 4713 | |
| 4714 | if (event < 32) |
| 4715 | ioc->event_masks[0] &= ~desired_event; |
| 4716 | else if (event < 64) |
| 4717 | ioc->event_masks[1] &= ~desired_event; |
| 4718 | else if (event < 96) |
| 4719 | ioc->event_masks[2] &= ~desired_event; |
| 4720 | else if (event < 128) |
| 4721 | ioc->event_masks[3] &= ~desired_event; |
| 4722 | } |
| 4723 | |
| 4724 | /** |
| 4725 | * _base_event_notification - send event notification |
| 4726 | * @ioc: per adapter object |
| 4727 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4728 | * |
| 4729 | * Returns 0 for success, non-zero for failure. |
| 4730 | */ |
| 4731 | static int |
| 4732 | _base_event_notification(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 4733 | { |
| 4734 | Mpi2EventNotificationRequest_t *mpi_request; |
| 4735 | unsigned long timeleft; |
| 4736 | u16 smid; |
| 4737 | int r = 0; |
| 4738 | int i; |
| 4739 | |
| 4740 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4741 | __func__)); |
| 4742 | |
| 4743 | if (ioc->base_cmds.status & MPT3_CMD_PENDING) { |
| 4744 | pr_err(MPT3SAS_FMT "%s: internal command already in use\n", |
| 4745 | ioc->name, __func__); |
| 4746 | return -EAGAIN; |
| 4747 | } |
| 4748 | |
| 4749 | smid = mpt3sas_base_get_smid(ioc, ioc->base_cb_idx); |
| 4750 | if (!smid) { |
| 4751 | pr_err(MPT3SAS_FMT "%s: failed obtaining a smid\n", |
| 4752 | ioc->name, __func__); |
| 4753 | return -EAGAIN; |
| 4754 | } |
| 4755 | ioc->base_cmds.status = MPT3_CMD_PENDING; |
| 4756 | mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); |
| 4757 | ioc->base_cmds.smid = smid; |
| 4758 | memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t)); |
| 4759 | mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION; |
| 4760 | mpi_request->VF_ID = 0; /* TODO */ |
| 4761 | mpi_request->VP_ID = 0; |
| 4762 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) |
| 4763 | mpi_request->EventMasks[i] = |
| 4764 | cpu_to_le32(ioc->event_masks[i]); |
| 4765 | init_completion(&ioc->base_cmds.done); |
| 4766 | mpt3sas_base_put_smid_default(ioc, smid); |
| 4767 | timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ); |
| 4768 | if (!(ioc->base_cmds.status & MPT3_CMD_COMPLETE)) { |
| 4769 | pr_err(MPT3SAS_FMT "%s: timeout\n", |
| 4770 | ioc->name, __func__); |
| 4771 | _debug_dump_mf(mpi_request, |
| 4772 | sizeof(Mpi2EventNotificationRequest_t)/4); |
| 4773 | if (ioc->base_cmds.status & MPT3_CMD_RESET) |
| 4774 | r = -EFAULT; |
| 4775 | else |
| 4776 | r = -ETIME; |
| 4777 | } else |
| 4778 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s: complete\n", |
| 4779 | ioc->name, __func__)); |
| 4780 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 4781 | return r; |
| 4782 | } |
| 4783 | |
| 4784 | /** |
| 4785 | * mpt3sas_base_validate_event_type - validating event types |
| 4786 | * @ioc: per adapter object |
| 4787 | * @event: firmware event |
| 4788 | * |
| 4789 | * This will turn on firmware event notification when application |
| 4790 | * ask for that event. We don't mask events that are already enabled. |
| 4791 | */ |
| 4792 | void |
| 4793 | mpt3sas_base_validate_event_type(struct MPT3SAS_ADAPTER *ioc, u32 *event_type) |
| 4794 | { |
| 4795 | int i, j; |
| 4796 | u32 event_mask, desired_event; |
| 4797 | u8 send_update_to_fw; |
| 4798 | |
| 4799 | for (i = 0, send_update_to_fw = 0; i < |
| 4800 | MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) { |
| 4801 | event_mask = ~event_type[i]; |
| 4802 | desired_event = 1; |
| 4803 | for (j = 0; j < 32; j++) { |
| 4804 | if (!(event_mask & desired_event) && |
| 4805 | (ioc->event_masks[i] & desired_event)) { |
| 4806 | ioc->event_masks[i] &= ~desired_event; |
| 4807 | send_update_to_fw = 1; |
| 4808 | } |
| 4809 | desired_event = (desired_event << 1); |
| 4810 | } |
| 4811 | } |
| 4812 | |
| 4813 | if (!send_update_to_fw) |
| 4814 | return; |
| 4815 | |
| 4816 | mutex_lock(&ioc->base_cmds.mutex); |
| 4817 | _base_event_notification(ioc, CAN_SLEEP); |
| 4818 | mutex_unlock(&ioc->base_cmds.mutex); |
| 4819 | } |
| 4820 | |
| 4821 | /** |
| 4822 | * _base_diag_reset - the "big hammer" start of day reset |
| 4823 | * @ioc: per adapter object |
| 4824 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4825 | * |
| 4826 | * Returns 0 for success, non-zero for failure. |
| 4827 | */ |
| 4828 | static int |
| 4829 | _base_diag_reset(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 4830 | { |
| 4831 | u32 host_diagnostic; |
| 4832 | u32 ioc_state; |
| 4833 | u32 count; |
| 4834 | u32 hcb_size; |
| 4835 | |
| 4836 | pr_info(MPT3SAS_FMT "sending diag reset !!\n", ioc->name); |
| 4837 | |
| 4838 | drsprintk(ioc, pr_info(MPT3SAS_FMT "clear interrupts\n", |
| 4839 | ioc->name)); |
| 4840 | |
| 4841 | count = 0; |
| 4842 | do { |
| 4843 | /* Write magic sequence to WriteSequence register |
| 4844 | * Loop until in diagnostic mode |
| 4845 | */ |
| 4846 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4847 | "write magic sequence\n", ioc->name)); |
| 4848 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4849 | writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4850 | writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4851 | writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4852 | writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4853 | writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4854 | writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4855 | |
| 4856 | /* wait 100 msec */ |
| 4857 | if (sleep_flag == CAN_SLEEP) |
| 4858 | msleep(100); |
| 4859 | else |
| 4860 | mdelay(100); |
| 4861 | |
| 4862 | if (count++ > 20) |
| 4863 | goto out; |
| 4864 | |
| 4865 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); |
| 4866 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4867 | "wrote magic sequence: count(%d), host_diagnostic(0x%08x)\n", |
| 4868 | ioc->name, count, host_diagnostic)); |
| 4869 | |
| 4870 | } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0); |
| 4871 | |
| 4872 | hcb_size = readl(&ioc->chip->HCBSize); |
| 4873 | |
| 4874 | drsprintk(ioc, pr_info(MPT3SAS_FMT "diag reset: issued\n", |
| 4875 | ioc->name)); |
| 4876 | writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER, |
| 4877 | &ioc->chip->HostDiagnostic); |
| 4878 | |
Sreekanth Reddy | b453ff8 | 2013-06-29 03:51:19 +0530 | [diff] [blame] | 4879 | /*This delay allows the chip PCIe hardware time to finish reset tasks*/ |
| 4880 | if (sleep_flag == CAN_SLEEP) |
| 4881 | msleep(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000); |
| 4882 | else |
| 4883 | mdelay(MPI2_HARD_RESET_PCIE_FIRST_READ_DELAY_MICRO_SEC/1000); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4884 | |
Sreekanth Reddy | b453ff8 | 2013-06-29 03:51:19 +0530 | [diff] [blame] | 4885 | /* Approximately 300 second max wait */ |
| 4886 | for (count = 0; count < (300000000 / |
| 4887 | MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC); count++) { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4888 | |
| 4889 | host_diagnostic = readl(&ioc->chip->HostDiagnostic); |
| 4890 | |
| 4891 | if (host_diagnostic == 0xFFFFFFFF) |
| 4892 | goto out; |
| 4893 | if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER)) |
| 4894 | break; |
| 4895 | |
Sreekanth Reddy | b453ff8 | 2013-06-29 03:51:19 +0530 | [diff] [blame] | 4896 | /* Wait to pass the second read delay window */ |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4897 | if (sleep_flag == CAN_SLEEP) |
Sreekanth Reddy | b453ff8 | 2013-06-29 03:51:19 +0530 | [diff] [blame] | 4898 | msleep(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC |
| 4899 | / 1000); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4900 | else |
Sreekanth Reddy | b453ff8 | 2013-06-29 03:51:19 +0530 | [diff] [blame] | 4901 | mdelay(MPI2_HARD_RESET_PCIE_SECOND_READ_DELAY_MICRO_SEC |
| 4902 | / 1000); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | if (host_diagnostic & MPI2_DIAG_HCB_MODE) { |
| 4906 | |
| 4907 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4908 | "restart the adapter assuming the HCB Address points to good F/W\n", |
| 4909 | ioc->name)); |
| 4910 | host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK; |
| 4911 | host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW; |
| 4912 | writel(host_diagnostic, &ioc->chip->HostDiagnostic); |
| 4913 | |
| 4914 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4915 | "re-enable the HCDW\n", ioc->name)); |
| 4916 | writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE, |
| 4917 | &ioc->chip->HCBSize); |
| 4918 | } |
| 4919 | |
| 4920 | drsprintk(ioc, pr_info(MPT3SAS_FMT "restart the adapter\n", |
| 4921 | ioc->name)); |
| 4922 | writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET, |
| 4923 | &ioc->chip->HostDiagnostic); |
| 4924 | |
| 4925 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4926 | "disable writes to the diagnostic register\n", ioc->name)); |
| 4927 | writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence); |
| 4928 | |
| 4929 | drsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4930 | "Wait for FW to go to the READY state\n", ioc->name)); |
| 4931 | ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20, |
| 4932 | sleep_flag); |
| 4933 | if (ioc_state) { |
| 4934 | pr_err(MPT3SAS_FMT |
| 4935 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 4936 | ioc->name, __func__, ioc_state); |
| 4937 | goto out; |
| 4938 | } |
| 4939 | |
| 4940 | pr_info(MPT3SAS_FMT "diag reset: SUCCESS\n", ioc->name); |
| 4941 | return 0; |
| 4942 | |
| 4943 | out: |
| 4944 | pr_err(MPT3SAS_FMT "diag reset: FAILED\n", ioc->name); |
| 4945 | return -EFAULT; |
| 4946 | } |
| 4947 | |
| 4948 | /** |
| 4949 | * _base_make_ioc_ready - put controller in READY state |
| 4950 | * @ioc: per adapter object |
| 4951 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 4952 | * @type: FORCE_BIG_HAMMER or SOFT_RESET |
| 4953 | * |
| 4954 | * Returns 0 for success, non-zero for failure. |
| 4955 | */ |
| 4956 | static int |
| 4957 | _base_make_ioc_ready(struct MPT3SAS_ADAPTER *ioc, int sleep_flag, |
| 4958 | enum reset_type type) |
| 4959 | { |
| 4960 | u32 ioc_state; |
| 4961 | int rc; |
| 4962 | int count; |
| 4963 | |
| 4964 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 4965 | __func__)); |
| 4966 | |
| 4967 | if (ioc->pci_error_recovery) |
| 4968 | return 0; |
| 4969 | |
| 4970 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 4971 | dhsprintk(ioc, pr_info(MPT3SAS_FMT "%s: ioc_state(0x%08x)\n", |
| 4972 | ioc->name, __func__, ioc_state)); |
| 4973 | |
| 4974 | /* if in RESET state, it should move to READY state shortly */ |
| 4975 | count = 0; |
| 4976 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_RESET) { |
| 4977 | while ((ioc_state & MPI2_IOC_STATE_MASK) != |
| 4978 | MPI2_IOC_STATE_READY) { |
| 4979 | if (count++ == 10) { |
| 4980 | pr_err(MPT3SAS_FMT |
| 4981 | "%s: failed going to ready state (ioc_state=0x%x)\n", |
| 4982 | ioc->name, __func__, ioc_state); |
| 4983 | return -EFAULT; |
| 4984 | } |
| 4985 | if (sleep_flag == CAN_SLEEP) |
| 4986 | ssleep(1); |
| 4987 | else |
| 4988 | mdelay(1000); |
| 4989 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 4990 | } |
| 4991 | } |
| 4992 | |
| 4993 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY) |
| 4994 | return 0; |
| 4995 | |
| 4996 | if (ioc_state & MPI2_DOORBELL_USED) { |
| 4997 | dhsprintk(ioc, pr_info(MPT3SAS_FMT |
| 4998 | "unexpected doorbell active!\n", |
| 4999 | ioc->name)); |
| 5000 | goto issue_diag_reset; |
| 5001 | } |
| 5002 | |
| 5003 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) { |
| 5004 | mpt3sas_base_fault_info(ioc, ioc_state & |
| 5005 | MPI2_DOORBELL_DATA_MASK); |
| 5006 | goto issue_diag_reset; |
| 5007 | } |
| 5008 | |
| 5009 | if (type == FORCE_BIG_HAMMER) |
| 5010 | goto issue_diag_reset; |
| 5011 | |
| 5012 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL) |
| 5013 | if (!(_base_send_ioc_reset(ioc, |
| 5014 | MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) { |
| 5015 | return 0; |
| 5016 | } |
| 5017 | |
| 5018 | issue_diag_reset: |
| 5019 | rc = _base_diag_reset(ioc, CAN_SLEEP); |
| 5020 | return rc; |
| 5021 | } |
| 5022 | |
| 5023 | /** |
| 5024 | * _base_make_ioc_operational - put controller in OPERATIONAL state |
| 5025 | * @ioc: per adapter object |
| 5026 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 5027 | * |
| 5028 | * Returns 0 for success, non-zero for failure. |
| 5029 | */ |
| 5030 | static int |
| 5031 | _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 5032 | { |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 5033 | int r, i, index; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5034 | unsigned long flags; |
| 5035 | u32 reply_address; |
| 5036 | u16 smid; |
| 5037 | struct _tr_list *delayed_tr, *delayed_tr_next; |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 5038 | struct _sc_list *delayed_sc, *delayed_sc_next; |
| 5039 | struct _event_ack_list *delayed_event_ack, *delayed_event_ack_next; |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 5040 | u8 hide_flag; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5041 | struct adapter_reply_queue *reply_q; |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 5042 | Mpi2ReplyDescriptorsUnion_t *reply_post_free_contig; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5043 | |
| 5044 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5045 | __func__)); |
| 5046 | |
| 5047 | /* clean the delayed target reset list */ |
| 5048 | list_for_each_entry_safe(delayed_tr, delayed_tr_next, |
| 5049 | &ioc->delayed_tr_list, list) { |
| 5050 | list_del(&delayed_tr->list); |
| 5051 | kfree(delayed_tr); |
| 5052 | } |
| 5053 | |
| 5054 | |
| 5055 | list_for_each_entry_safe(delayed_tr, delayed_tr_next, |
| 5056 | &ioc->delayed_tr_volume_list, list) { |
| 5057 | list_del(&delayed_tr->list); |
| 5058 | kfree(delayed_tr); |
| 5059 | } |
| 5060 | |
Suganath prabu Subramani | fd0331b | 2016-01-28 12:07:02 +0530 | [diff] [blame] | 5061 | list_for_each_entry_safe(delayed_sc, delayed_sc_next, |
| 5062 | &ioc->delayed_sc_list, list) { |
| 5063 | list_del(&delayed_sc->list); |
| 5064 | kfree(delayed_sc); |
| 5065 | } |
| 5066 | |
| 5067 | list_for_each_entry_safe(delayed_event_ack, delayed_event_ack_next, |
| 5068 | &ioc->delayed_event_ack_list, list) { |
| 5069 | list_del(&delayed_event_ack->list); |
| 5070 | kfree(delayed_event_ack); |
| 5071 | } |
| 5072 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5073 | /* initialize the scsi lookup free list */ |
| 5074 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5075 | INIT_LIST_HEAD(&ioc->free_list); |
| 5076 | smid = 1; |
| 5077 | for (i = 0; i < ioc->scsiio_depth; i++, smid++) { |
| 5078 | INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list); |
| 5079 | ioc->scsi_lookup[i].cb_idx = 0xFF; |
| 5080 | ioc->scsi_lookup[i].smid = smid; |
| 5081 | ioc->scsi_lookup[i].scmd = NULL; |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 5082 | ioc->scsi_lookup[i].direct_io = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5083 | list_add_tail(&ioc->scsi_lookup[i].tracker_list, |
| 5084 | &ioc->free_list); |
| 5085 | } |
| 5086 | |
| 5087 | /* hi-priority queue */ |
| 5088 | INIT_LIST_HEAD(&ioc->hpr_free_list); |
| 5089 | smid = ioc->hi_priority_smid; |
| 5090 | for (i = 0; i < ioc->hi_priority_depth; i++, smid++) { |
| 5091 | ioc->hpr_lookup[i].cb_idx = 0xFF; |
| 5092 | ioc->hpr_lookup[i].smid = smid; |
| 5093 | list_add_tail(&ioc->hpr_lookup[i].tracker_list, |
| 5094 | &ioc->hpr_free_list); |
| 5095 | } |
| 5096 | |
| 5097 | /* internal queue */ |
| 5098 | INIT_LIST_HEAD(&ioc->internal_free_list); |
| 5099 | smid = ioc->internal_smid; |
| 5100 | for (i = 0; i < ioc->internal_depth; i++, smid++) { |
| 5101 | ioc->internal_lookup[i].cb_idx = 0xFF; |
| 5102 | ioc->internal_lookup[i].smid = smid; |
| 5103 | list_add_tail(&ioc->internal_lookup[i].tracker_list, |
| 5104 | &ioc->internal_free_list); |
| 5105 | } |
| 5106 | |
| 5107 | /* chain pool */ |
| 5108 | INIT_LIST_HEAD(&ioc->free_chain_list); |
| 5109 | for (i = 0; i < ioc->chain_depth; i++) |
| 5110 | list_add_tail(&ioc->chain_lookup[i].tracker_list, |
| 5111 | &ioc->free_chain_list); |
| 5112 | |
| 5113 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5114 | |
| 5115 | /* initialize Reply Free Queue */ |
| 5116 | for (i = 0, reply_address = (u32)ioc->reply_dma ; |
| 5117 | i < ioc->reply_free_queue_depth ; i++, reply_address += |
| 5118 | ioc->reply_sz) |
| 5119 | ioc->reply_free[i] = cpu_to_le32(reply_address); |
| 5120 | |
| 5121 | /* initialize reply queues */ |
| 5122 | if (ioc->is_driver_loading) |
| 5123 | _base_assign_reply_queues(ioc); |
| 5124 | |
| 5125 | /* initialize Reply Post Free Queue */ |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 5126 | index = 0; |
| 5127 | reply_post_free_contig = ioc->reply_post[0].reply_post_free; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5128 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
Calvin Owens | 5ec8a17 | 2016-03-18 12:45:42 -0700 | [diff] [blame] | 5129 | /* |
| 5130 | * If RDPQ is enabled, switch to the next allocation. |
| 5131 | * Otherwise advance within the contiguous region. |
| 5132 | */ |
| 5133 | if (ioc->rdpq_array_enable) { |
| 5134 | reply_q->reply_post_free = |
| 5135 | ioc->reply_post[index++].reply_post_free; |
| 5136 | } else { |
| 5137 | reply_q->reply_post_free = reply_post_free_contig; |
| 5138 | reply_post_free_contig += ioc->reply_post_queue_depth; |
| 5139 | } |
| 5140 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5141 | reply_q->reply_post_host_index = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5142 | for (i = 0; i < ioc->reply_post_queue_depth; i++) |
| 5143 | reply_q->reply_post_free[i].Words = |
| 5144 | cpu_to_le64(ULLONG_MAX); |
| 5145 | if (!_base_is_controller_msix_enabled(ioc)) |
| 5146 | goto skip_init_reply_post_free_queue; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5147 | } |
| 5148 | skip_init_reply_post_free_queue: |
| 5149 | |
| 5150 | r = _base_send_ioc_init(ioc, sleep_flag); |
| 5151 | if (r) |
| 5152 | return r; |
| 5153 | |
| 5154 | /* initialize reply free host index */ |
| 5155 | ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1; |
| 5156 | writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex); |
| 5157 | |
| 5158 | /* initialize reply post host index */ |
| 5159 | list_for_each_entry(reply_q, &ioc->reply_queue_list, list) { |
Sreekanth Reddy | fb77bb5 | 2015-06-30 12:24:47 +0530 | [diff] [blame] | 5160 | if (ioc->msix96_vector) |
| 5161 | writel((reply_q->msix_index & 7)<< |
| 5162 | MPI2_RPHI_MSIX_INDEX_SHIFT, |
| 5163 | ioc->replyPostRegisterIndex[reply_q->msix_index/8]); |
| 5164 | else |
| 5165 | writel(reply_q->msix_index << |
| 5166 | MPI2_RPHI_MSIX_INDEX_SHIFT, |
| 5167 | &ioc->chip->ReplyPostHostIndex); |
| 5168 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5169 | if (!_base_is_controller_msix_enabled(ioc)) |
| 5170 | goto skip_init_reply_post_host_index; |
| 5171 | } |
| 5172 | |
| 5173 | skip_init_reply_post_host_index: |
| 5174 | |
| 5175 | _base_unmask_interrupts(ioc); |
| 5176 | r = _base_event_notification(ioc, sleep_flag); |
| 5177 | if (r) |
| 5178 | return r; |
| 5179 | |
| 5180 | if (sleep_flag == CAN_SLEEP) |
| 5181 | _base_static_config_pages(ioc); |
| 5182 | |
| 5183 | |
| 5184 | if (ioc->is_driver_loading) { |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 5185 | |
| 5186 | if (ioc->is_warpdrive && ioc->manu_pg10.OEMIdentifier |
| 5187 | == 0x80) { |
| 5188 | hide_flag = (u8) ( |
| 5189 | le32_to_cpu(ioc->manu_pg10.OEMSpecificFlags0) & |
| 5190 | MFG_PAGE10_HIDE_SSDS_MASK); |
| 5191 | if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK) |
| 5192 | ioc->mfg_pg10_hide_flag = hide_flag; |
| 5193 | } |
| 5194 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5195 | ioc->wait_for_discovery_to_complete = |
| 5196 | _base_determine_wait_on_discovery(ioc); |
| 5197 | |
| 5198 | return r; /* scan_start and scan_finished support */ |
| 5199 | } |
| 5200 | |
| 5201 | r = _base_send_port_enable(ioc, sleep_flag); |
| 5202 | if (r) |
| 5203 | return r; |
| 5204 | |
| 5205 | return r; |
| 5206 | } |
| 5207 | |
| 5208 | /** |
| 5209 | * mpt3sas_base_free_resources - free resources controller resources |
| 5210 | * @ioc: per adapter object |
| 5211 | * |
| 5212 | * Return nothing. |
| 5213 | */ |
| 5214 | void |
| 5215 | mpt3sas_base_free_resources(struct MPT3SAS_ADAPTER *ioc) |
| 5216 | { |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5217 | dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5218 | __func__)); |
| 5219 | |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 5220 | /* synchronizing freeing resource with pci_access_mutex lock */ |
| 5221 | mutex_lock(&ioc->pci_access_mutex); |
Joe Lawrence | cf9bd21a | 2013-08-08 16:45:39 -0400 | [diff] [blame] | 5222 | if (ioc->chip_phys && ioc->chip) { |
| 5223 | _base_mask_interrupts(ioc); |
| 5224 | ioc->shost_recovery = 1; |
| 5225 | _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET); |
| 5226 | ioc->shost_recovery = 0; |
| 5227 | } |
| 5228 | |
Sreekanth Reddy | 580d4e3 | 2015-06-30 12:24:50 +0530 | [diff] [blame] | 5229 | mpt3sas_base_unmap_resources(ioc); |
Sreekanth Reddy | 08c4d55 | 2015-11-11 17:30:33 +0530 | [diff] [blame] | 5230 | mutex_unlock(&ioc->pci_access_mutex); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5231 | return; |
| 5232 | } |
| 5233 | |
| 5234 | /** |
| 5235 | * mpt3sas_base_attach - attach controller instance |
| 5236 | * @ioc: per adapter object |
| 5237 | * |
| 5238 | * Returns 0 for success, non-zero for failure. |
| 5239 | */ |
| 5240 | int |
| 5241 | mpt3sas_base_attach(struct MPT3SAS_ADAPTER *ioc) |
| 5242 | { |
| 5243 | int r, i; |
| 5244 | int cpu_id, last_cpu_id = 0; |
| 5245 | |
| 5246 | dinitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5247 | __func__)); |
| 5248 | |
| 5249 | /* setup cpu_msix_table */ |
| 5250 | ioc->cpu_count = num_online_cpus(); |
| 5251 | for_each_online_cpu(cpu_id) |
| 5252 | last_cpu_id = cpu_id; |
| 5253 | ioc->cpu_msix_table_sz = last_cpu_id + 1; |
| 5254 | ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL); |
| 5255 | ioc->reply_queue_count = 1; |
| 5256 | if (!ioc->cpu_msix_table) { |
| 5257 | dfailprintk(ioc, pr_info(MPT3SAS_FMT |
| 5258 | "allocation for cpu_msix_table failed!!!\n", |
| 5259 | ioc->name)); |
| 5260 | r = -ENOMEM; |
| 5261 | goto out_free_resources; |
| 5262 | } |
| 5263 | |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 5264 | if (ioc->is_warpdrive) { |
| 5265 | ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz, |
| 5266 | sizeof(resource_size_t *), GFP_KERNEL); |
| 5267 | if (!ioc->reply_post_host_index) { |
| 5268 | dfailprintk(ioc, pr_info(MPT3SAS_FMT "allocation " |
| 5269 | "for cpu_msix_table failed!!!\n", ioc->name)); |
| 5270 | r = -ENOMEM; |
| 5271 | goto out_free_resources; |
| 5272 | } |
| 5273 | } |
| 5274 | |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5275 | ioc->rdpq_array_enable_assigned = 0; |
| 5276 | ioc->dma_mask = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5277 | r = mpt3sas_base_map_resources(ioc); |
| 5278 | if (r) |
| 5279 | goto out_free_resources; |
| 5280 | |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 5281 | if (ioc->is_warpdrive) { |
| 5282 | ioc->reply_post_host_index[0] = (resource_size_t __iomem *) |
| 5283 | &ioc->chip->ReplyPostHostIndex; |
| 5284 | |
| 5285 | for (i = 1; i < ioc->cpu_msix_table_sz; i++) |
| 5286 | ioc->reply_post_host_index[i] = |
| 5287 | (resource_size_t __iomem *) |
| 5288 | ((u8 __iomem *)&ioc->chip->Doorbell + (0x4000 + ((i - 1) |
| 5289 | * 4))); |
| 5290 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5291 | |
| 5292 | pci_set_drvdata(ioc->pdev, ioc->shost); |
| 5293 | r = _base_get_ioc_facts(ioc, CAN_SLEEP); |
| 5294 | if (r) |
| 5295 | goto out_free_resources; |
| 5296 | |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 5297 | switch (ioc->hba_mpi_version_belonged) { |
| 5298 | case MPI2_VERSION: |
| 5299 | ioc->build_sg_scmd = &_base_build_sg_scmd; |
| 5300 | ioc->build_sg = &_base_build_sg; |
| 5301 | ioc->build_zero_len_sge = &_base_build_zero_len_sge; |
| 5302 | break; |
| 5303 | case MPI25_VERSION: |
Suganath prabu Subramani | b130b0d | 2016-01-28 12:06:58 +0530 | [diff] [blame] | 5304 | case MPI26_VERSION: |
Sreekanth Reddy | 471ef9d | 2015-11-11 17:30:24 +0530 | [diff] [blame] | 5305 | /* |
| 5306 | * In SAS3.0, |
| 5307 | * SCSI_IO, SMP_PASSTHRU, SATA_PASSTHRU, Target Assist, and |
| 5308 | * Target Status - all require the IEEE formated scatter gather |
| 5309 | * elements. |
| 5310 | */ |
| 5311 | ioc->build_sg_scmd = &_base_build_sg_scmd_ieee; |
| 5312 | ioc->build_sg = &_base_build_sg_ieee; |
| 5313 | ioc->build_zero_len_sge = &_base_build_zero_len_sge_ieee; |
| 5314 | ioc->sge_size_ieee = sizeof(Mpi2IeeeSgeSimple64_t); |
| 5315 | break; |
| 5316 | } |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5317 | |
| 5318 | /* |
| 5319 | * These function pointers for other requests that don't |
| 5320 | * the require IEEE scatter gather elements. |
| 5321 | * |
| 5322 | * For example Configuration Pages and SAS IOUNIT Control don't. |
| 5323 | */ |
| 5324 | ioc->build_sg_mpi = &_base_build_sg; |
| 5325 | ioc->build_zero_len_sge_mpi = &_base_build_zero_len_sge; |
| 5326 | |
| 5327 | r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET); |
| 5328 | if (r) |
| 5329 | goto out_free_resources; |
| 5330 | |
| 5331 | ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts, |
| 5332 | sizeof(struct mpt3sas_port_facts), GFP_KERNEL); |
| 5333 | if (!ioc->pfacts) { |
| 5334 | r = -ENOMEM; |
| 5335 | goto out_free_resources; |
| 5336 | } |
| 5337 | |
| 5338 | for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) { |
| 5339 | r = _base_get_port_facts(ioc, i, CAN_SLEEP); |
| 5340 | if (r) |
| 5341 | goto out_free_resources; |
| 5342 | } |
| 5343 | |
| 5344 | r = _base_allocate_memory_pools(ioc, CAN_SLEEP); |
| 5345 | if (r) |
| 5346 | goto out_free_resources; |
| 5347 | |
| 5348 | init_waitqueue_head(&ioc->reset_wq); |
| 5349 | |
| 5350 | /* allocate memory pd handle bitmask list */ |
| 5351 | ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8); |
| 5352 | if (ioc->facts.MaxDevHandle % 8) |
| 5353 | ioc->pd_handles_sz++; |
| 5354 | ioc->pd_handles = kzalloc(ioc->pd_handles_sz, |
| 5355 | GFP_KERNEL); |
| 5356 | if (!ioc->pd_handles) { |
| 5357 | r = -ENOMEM; |
| 5358 | goto out_free_resources; |
| 5359 | } |
| 5360 | ioc->blocking_handles = kzalloc(ioc->pd_handles_sz, |
| 5361 | GFP_KERNEL); |
| 5362 | if (!ioc->blocking_handles) { |
| 5363 | r = -ENOMEM; |
| 5364 | goto out_free_resources; |
| 5365 | } |
| 5366 | |
| 5367 | ioc->fwfault_debug = mpt3sas_fwfault_debug; |
| 5368 | |
| 5369 | /* base internal command bits */ |
| 5370 | mutex_init(&ioc->base_cmds.mutex); |
| 5371 | ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 5372 | ioc->base_cmds.status = MPT3_CMD_NOT_USED; |
| 5373 | |
| 5374 | /* port_enable command bits */ |
| 5375 | ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 5376 | ioc->port_enable_cmds.status = MPT3_CMD_NOT_USED; |
| 5377 | |
| 5378 | /* transport internal command bits */ |
| 5379 | ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 5380 | ioc->transport_cmds.status = MPT3_CMD_NOT_USED; |
| 5381 | mutex_init(&ioc->transport_cmds.mutex); |
| 5382 | |
| 5383 | /* scsih internal command bits */ |
| 5384 | ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 5385 | ioc->scsih_cmds.status = MPT3_CMD_NOT_USED; |
| 5386 | mutex_init(&ioc->scsih_cmds.mutex); |
| 5387 | |
| 5388 | /* task management internal command bits */ |
| 5389 | ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 5390 | ioc->tm_cmds.status = MPT3_CMD_NOT_USED; |
| 5391 | mutex_init(&ioc->tm_cmds.mutex); |
| 5392 | |
| 5393 | /* config page internal command bits */ |
| 5394 | ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 5395 | ioc->config_cmds.status = MPT3_CMD_NOT_USED; |
| 5396 | mutex_init(&ioc->config_cmds.mutex); |
| 5397 | |
| 5398 | /* ctl module internal command bits */ |
| 5399 | ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); |
| 5400 | ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); |
| 5401 | ioc->ctl_cmds.status = MPT3_CMD_NOT_USED; |
| 5402 | mutex_init(&ioc->ctl_cmds.mutex); |
| 5403 | |
| 5404 | if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply || |
| 5405 | !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply || |
| 5406 | !ioc->config_cmds.reply || !ioc->ctl_cmds.reply || |
| 5407 | !ioc->ctl_cmds.sense) { |
| 5408 | r = -ENOMEM; |
| 5409 | goto out_free_resources; |
| 5410 | } |
| 5411 | |
| 5412 | for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) |
| 5413 | ioc->event_masks[i] = -1; |
| 5414 | |
| 5415 | /* here we enable the events we care about */ |
| 5416 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY); |
| 5417 | _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE); |
| 5418 | _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST); |
| 5419 | _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE); |
| 5420 | _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE); |
| 5421 | _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST); |
| 5422 | _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME); |
| 5423 | _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK); |
| 5424 | _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS); |
| 5425 | _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED); |
Sreekanth Reddy | 2d8ce8c | 2015-01-12 11:38:56 +0530 | [diff] [blame] | 5426 | _base_unmask_events(ioc, MPI2_EVENT_TEMP_THRESHOLD); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5427 | |
| 5428 | r = _base_make_ioc_operational(ioc, CAN_SLEEP); |
| 5429 | if (r) |
| 5430 | goto out_free_resources; |
| 5431 | |
Sreekanth Reddy | 16e179b | 2015-11-11 17:30:27 +0530 | [diff] [blame] | 5432 | ioc->non_operational_loop = 0; |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5433 | return 0; |
| 5434 | |
| 5435 | out_free_resources: |
| 5436 | |
| 5437 | ioc->remove_host = 1; |
| 5438 | |
| 5439 | mpt3sas_base_free_resources(ioc); |
| 5440 | _base_release_memory_pools(ioc); |
| 5441 | pci_set_drvdata(ioc->pdev, NULL); |
| 5442 | kfree(ioc->cpu_msix_table); |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 5443 | if (ioc->is_warpdrive) |
| 5444 | kfree(ioc->reply_post_host_index); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5445 | kfree(ioc->pd_handles); |
| 5446 | kfree(ioc->blocking_handles); |
| 5447 | kfree(ioc->tm_cmds.reply); |
| 5448 | kfree(ioc->transport_cmds.reply); |
| 5449 | kfree(ioc->scsih_cmds.reply); |
| 5450 | kfree(ioc->config_cmds.reply); |
| 5451 | kfree(ioc->base_cmds.reply); |
| 5452 | kfree(ioc->port_enable_cmds.reply); |
| 5453 | kfree(ioc->ctl_cmds.reply); |
| 5454 | kfree(ioc->ctl_cmds.sense); |
| 5455 | kfree(ioc->pfacts); |
| 5456 | ioc->ctl_cmds.reply = NULL; |
| 5457 | ioc->base_cmds.reply = NULL; |
| 5458 | ioc->tm_cmds.reply = NULL; |
| 5459 | ioc->scsih_cmds.reply = NULL; |
| 5460 | ioc->transport_cmds.reply = NULL; |
| 5461 | ioc->config_cmds.reply = NULL; |
| 5462 | ioc->pfacts = NULL; |
| 5463 | return r; |
| 5464 | } |
| 5465 | |
| 5466 | |
| 5467 | /** |
| 5468 | * mpt3sas_base_detach - remove controller instance |
| 5469 | * @ioc: per adapter object |
| 5470 | * |
| 5471 | * Return nothing. |
| 5472 | */ |
| 5473 | void |
| 5474 | mpt3sas_base_detach(struct MPT3SAS_ADAPTER *ioc) |
| 5475 | { |
| 5476 | dexitprintk(ioc, pr_info(MPT3SAS_FMT "%s\n", ioc->name, |
| 5477 | __func__)); |
| 5478 | |
| 5479 | mpt3sas_base_stop_watchdog(ioc); |
| 5480 | mpt3sas_base_free_resources(ioc); |
| 5481 | _base_release_memory_pools(ioc); |
| 5482 | pci_set_drvdata(ioc->pdev, NULL); |
| 5483 | kfree(ioc->cpu_msix_table); |
Sreekanth Reddy | 7786ab6 | 2015-11-11 17:30:28 +0530 | [diff] [blame] | 5484 | if (ioc->is_warpdrive) |
| 5485 | kfree(ioc->reply_post_host_index); |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5486 | kfree(ioc->pd_handles); |
| 5487 | kfree(ioc->blocking_handles); |
| 5488 | kfree(ioc->pfacts); |
| 5489 | kfree(ioc->ctl_cmds.reply); |
| 5490 | kfree(ioc->ctl_cmds.sense); |
| 5491 | kfree(ioc->base_cmds.reply); |
| 5492 | kfree(ioc->port_enable_cmds.reply); |
| 5493 | kfree(ioc->tm_cmds.reply); |
| 5494 | kfree(ioc->transport_cmds.reply); |
| 5495 | kfree(ioc->scsih_cmds.reply); |
| 5496 | kfree(ioc->config_cmds.reply); |
| 5497 | } |
| 5498 | |
| 5499 | /** |
| 5500 | * _base_reset_handler - reset callback handler (for base) |
| 5501 | * @ioc: per adapter object |
| 5502 | * @reset_phase: phase |
| 5503 | * |
| 5504 | * The handler for doing any required cleanup or initialization. |
| 5505 | * |
| 5506 | * The reset phase can be MPT3_IOC_PRE_RESET, MPT3_IOC_AFTER_RESET, |
| 5507 | * MPT3_IOC_DONE_RESET |
| 5508 | * |
| 5509 | * Return nothing. |
| 5510 | */ |
| 5511 | static void |
| 5512 | _base_reset_handler(struct MPT3SAS_ADAPTER *ioc, int reset_phase) |
| 5513 | { |
| 5514 | mpt3sas_scsih_reset_handler(ioc, reset_phase); |
| 5515 | mpt3sas_ctl_reset_handler(ioc, reset_phase); |
| 5516 | switch (reset_phase) { |
| 5517 | case MPT3_IOC_PRE_RESET: |
| 5518 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 5519 | "%s: MPT3_IOC_PRE_RESET\n", ioc->name, __func__)); |
| 5520 | break; |
| 5521 | case MPT3_IOC_AFTER_RESET: |
| 5522 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 5523 | "%s: MPT3_IOC_AFTER_RESET\n", ioc->name, __func__)); |
| 5524 | if (ioc->transport_cmds.status & MPT3_CMD_PENDING) { |
| 5525 | ioc->transport_cmds.status |= MPT3_CMD_RESET; |
| 5526 | mpt3sas_base_free_smid(ioc, ioc->transport_cmds.smid); |
| 5527 | complete(&ioc->transport_cmds.done); |
| 5528 | } |
| 5529 | if (ioc->base_cmds.status & MPT3_CMD_PENDING) { |
| 5530 | ioc->base_cmds.status |= MPT3_CMD_RESET; |
| 5531 | mpt3sas_base_free_smid(ioc, ioc->base_cmds.smid); |
| 5532 | complete(&ioc->base_cmds.done); |
| 5533 | } |
| 5534 | if (ioc->port_enable_cmds.status & MPT3_CMD_PENDING) { |
| 5535 | ioc->port_enable_failed = 1; |
| 5536 | ioc->port_enable_cmds.status |= MPT3_CMD_RESET; |
| 5537 | mpt3sas_base_free_smid(ioc, ioc->port_enable_cmds.smid); |
| 5538 | if (ioc->is_driver_loading) { |
| 5539 | ioc->start_scan_failed = |
| 5540 | MPI2_IOCSTATUS_INTERNAL_ERROR; |
| 5541 | ioc->start_scan = 0; |
| 5542 | ioc->port_enable_cmds.status = |
| 5543 | MPT3_CMD_NOT_USED; |
| 5544 | } else |
| 5545 | complete(&ioc->port_enable_cmds.done); |
| 5546 | } |
| 5547 | if (ioc->config_cmds.status & MPT3_CMD_PENDING) { |
| 5548 | ioc->config_cmds.status |= MPT3_CMD_RESET; |
| 5549 | mpt3sas_base_free_smid(ioc, ioc->config_cmds.smid); |
| 5550 | ioc->config_cmds.smid = USHRT_MAX; |
| 5551 | complete(&ioc->config_cmds.done); |
| 5552 | } |
| 5553 | break; |
| 5554 | case MPT3_IOC_DONE_RESET: |
| 5555 | dtmprintk(ioc, pr_info(MPT3SAS_FMT |
| 5556 | "%s: MPT3_IOC_DONE_RESET\n", ioc->name, __func__)); |
| 5557 | break; |
| 5558 | } |
| 5559 | } |
| 5560 | |
| 5561 | /** |
| 5562 | * _wait_for_commands_to_complete - reset controller |
| 5563 | * @ioc: Pointer to MPT_ADAPTER structure |
| 5564 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 5565 | * |
| 5566 | * This function waiting(3s) for all pending commands to complete |
| 5567 | * prior to putting controller in reset. |
| 5568 | */ |
| 5569 | static void |
| 5570 | _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) |
| 5571 | { |
| 5572 | u32 ioc_state; |
| 5573 | unsigned long flags; |
| 5574 | u16 i; |
| 5575 | |
| 5576 | ioc->pending_io_count = 0; |
| 5577 | if (sleep_flag != CAN_SLEEP) |
| 5578 | return; |
| 5579 | |
| 5580 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 5581 | if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL) |
| 5582 | return; |
| 5583 | |
| 5584 | /* pending command count */ |
| 5585 | spin_lock_irqsave(&ioc->scsi_lookup_lock, flags); |
| 5586 | for (i = 0; i < ioc->scsiio_depth; i++) |
| 5587 | if (ioc->scsi_lookup[i].cb_idx != 0xFF) |
| 5588 | ioc->pending_io_count++; |
| 5589 | spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); |
| 5590 | |
| 5591 | if (!ioc->pending_io_count) |
| 5592 | return; |
| 5593 | |
| 5594 | /* wait for pending commands to complete */ |
| 5595 | wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ); |
| 5596 | } |
| 5597 | |
| 5598 | /** |
| 5599 | * mpt3sas_base_hard_reset_handler - reset controller |
| 5600 | * @ioc: Pointer to MPT_ADAPTER structure |
| 5601 | * @sleep_flag: CAN_SLEEP or NO_SLEEP |
| 5602 | * @type: FORCE_BIG_HAMMER or SOFT_RESET |
| 5603 | * |
| 5604 | * Returns 0 for success, non-zero for failure. |
| 5605 | */ |
| 5606 | int |
| 5607 | mpt3sas_base_hard_reset_handler(struct MPT3SAS_ADAPTER *ioc, int sleep_flag, |
| 5608 | enum reset_type type) |
| 5609 | { |
| 5610 | int r; |
| 5611 | unsigned long flags; |
| 5612 | u32 ioc_state; |
| 5613 | u8 is_fault = 0, is_trigger = 0; |
| 5614 | |
| 5615 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n", ioc->name, |
| 5616 | __func__)); |
| 5617 | |
| 5618 | if (ioc->pci_error_recovery) { |
| 5619 | pr_err(MPT3SAS_FMT "%s: pci error recovery reset\n", |
| 5620 | ioc->name, __func__); |
| 5621 | r = 0; |
| 5622 | goto out_unlocked; |
| 5623 | } |
| 5624 | |
| 5625 | if (mpt3sas_fwfault_debug) |
| 5626 | mpt3sas_halt_firmware(ioc); |
| 5627 | |
| 5628 | /* TODO - What we really should be doing is pulling |
| 5629 | * out all the code associated with NO_SLEEP; its never used. |
| 5630 | * That is legacy code from mpt fusion driver, ported over. |
| 5631 | * I will leave this BUG_ON here for now till its been resolved. |
| 5632 | */ |
| 5633 | BUG_ON(sleep_flag == NO_SLEEP); |
| 5634 | |
| 5635 | /* wait for an active reset in progress to complete */ |
| 5636 | if (!mutex_trylock(&ioc->reset_in_progress_mutex)) { |
| 5637 | do { |
| 5638 | ssleep(1); |
| 5639 | } while (ioc->shost_recovery == 1); |
| 5640 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name, |
| 5641 | __func__)); |
| 5642 | return ioc->ioc_reset_in_progress_status; |
| 5643 | } |
| 5644 | |
| 5645 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 5646 | ioc->shost_recovery = 1; |
| 5647 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 5648 | |
| 5649 | if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 5650 | MPT3_DIAG_BUFFER_IS_REGISTERED) && |
| 5651 | (!(ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & |
| 5652 | MPT3_DIAG_BUFFER_IS_RELEASED))) { |
| 5653 | is_trigger = 1; |
| 5654 | ioc_state = mpt3sas_base_get_iocstate(ioc, 0); |
| 5655 | if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) |
| 5656 | is_fault = 1; |
| 5657 | } |
| 5658 | _base_reset_handler(ioc, MPT3_IOC_PRE_RESET); |
| 5659 | _wait_for_commands_to_complete(ioc, sleep_flag); |
| 5660 | _base_mask_interrupts(ioc); |
| 5661 | r = _base_make_ioc_ready(ioc, sleep_flag, type); |
| 5662 | if (r) |
| 5663 | goto out; |
| 5664 | _base_reset_handler(ioc, MPT3_IOC_AFTER_RESET); |
| 5665 | |
| 5666 | /* If this hard reset is called while port enable is active, then |
| 5667 | * there is no reason to call make_ioc_operational |
| 5668 | */ |
| 5669 | if (ioc->is_driver_loading && ioc->port_enable_failed) { |
| 5670 | ioc->remove_host = 1; |
| 5671 | r = -EFAULT; |
| 5672 | goto out; |
| 5673 | } |
| 5674 | r = _base_get_ioc_facts(ioc, CAN_SLEEP); |
| 5675 | if (r) |
| 5676 | goto out; |
Sreekanth Reddy | 9b05c91 | 2014-09-12 15:35:31 +0530 | [diff] [blame] | 5677 | |
| 5678 | if (ioc->rdpq_array_enable && !ioc->rdpq_array_capable) |
| 5679 | panic("%s: Issue occurred with flashing controller firmware." |
| 5680 | "Please reboot the system and ensure that the correct" |
| 5681 | " firmware version is running\n", ioc->name); |
| 5682 | |
Sreekanth Reddy | f92363d | 2012-11-30 07:44:21 +0530 | [diff] [blame] | 5683 | r = _base_make_ioc_operational(ioc, sleep_flag); |
| 5684 | if (!r) |
| 5685 | _base_reset_handler(ioc, MPT3_IOC_DONE_RESET); |
| 5686 | |
| 5687 | out: |
| 5688 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: %s\n", |
| 5689 | ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED"))); |
| 5690 | |
| 5691 | spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); |
| 5692 | ioc->ioc_reset_in_progress_status = r; |
| 5693 | ioc->shost_recovery = 0; |
| 5694 | spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); |
| 5695 | ioc->ioc_reset_count++; |
| 5696 | mutex_unlock(&ioc->reset_in_progress_mutex); |
| 5697 | |
| 5698 | out_unlocked: |
| 5699 | if ((r == 0) && is_trigger) { |
| 5700 | if (is_fault) |
| 5701 | mpt3sas_trigger_master(ioc, MASTER_TRIGGER_FW_FAULT); |
| 5702 | else |
| 5703 | mpt3sas_trigger_master(ioc, |
| 5704 | MASTER_TRIGGER_ADAPTER_RESET); |
| 5705 | } |
| 5706 | dtmprintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name, |
| 5707 | __func__)); |
| 5708 | return r; |
| 5709 | } |