blob: 4a8706867700aa0014d7a5ffd9e89b6c41900aaa [file] [log] [blame]
Eric Moore635374e2009-03-09 01:21:12 -06001/*
2 * This is the Fusion MPT base driver providing common API layer interface
3 * for access to MPT (Message Passing Technology) firmware.
4 *
5 * This code is based on drivers/scsi/mpt2sas/mpt2_base.c
Kashyap, Desai31b7f2e2010-03-17 16:28:04 +05306 * Copyright (C) 2007-2010 LSI Corporation
Eric Moore635374e2009-03-09 01:21:12 -06007 * (mailto:DL-MPTFusionLinux@lsi.com)
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * NO WARRANTY
20 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
21 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
22 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
23 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
24 * solely responsible for determining the appropriateness of using and
25 * distributing the Program and assumes all risks associated with its
26 * exercise of rights under this Agreement, including but not limited to
27 * the risks and costs of program errors, damage to or loss of data,
28 * programs or equipment, and unavailability or interruption of operations.
29
30 * DISCLAIMER OF LIABILITY
31 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
34 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
35 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
36 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
37 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
38
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
42 * USA.
43 */
44
Eric Moore635374e2009-03-09 01:21:12 -060045#include <linux/kernel.h>
46#include <linux/module.h>
47#include <linux/errno.h>
48#include <linux/init.h>
49#include <linux/slab.h>
50#include <linux/types.h>
51#include <linux/pci.h>
52#include <linux/kdev_t.h>
53#include <linux/blkdev.h>
54#include <linux/delay.h>
55#include <linux/interrupt.h>
56#include <linux/dma-mapping.h>
57#include <linux/sort.h>
58#include <linux/io.h>
Kashyap, Desaia8ebd762009-09-23 17:29:29 +053059#include <linux/time.h>
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +053060#include <linux/kthread.h>
Kashyap, Desaief7c80c2010-04-05 14:20:07 +053061#include <linux/aer.h>
Eric Moore635374e2009-03-09 01:21:12 -060062
63#include "mpt2sas_base.h"
64
65static MPT_CALLBACK mpt_callbacks[MPT_MAX_CALLBACKS];
66
67#define FAULT_POLLING_INTERVAL 1000 /* in milliseconds */
Eric Moore635374e2009-03-09 01:21:12 -060068
69static int max_queue_depth = -1;
70module_param(max_queue_depth, int, 0);
71MODULE_PARM_DESC(max_queue_depth, " max controller queue depth ");
72
73static int max_sgl_entries = -1;
74module_param(max_sgl_entries, int, 0);
75MODULE_PARM_DESC(max_sgl_entries, " max sg entries ");
76
77static int msix_disable = -1;
78module_param(msix_disable, int, 0);
79MODULE_PARM_DESC(msix_disable, " disable msix routed interrupts (default=0)");
80
Kashyap, Desai6cb8ef52010-11-13 04:32:18 +053081static int missing_delay[2] = {-1, -1};
82module_param_array(missing_delay, int, NULL, 0);
83MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
84
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +053085static int mpt2sas_fwfault_debug;
86MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
87 "and halt firmware - (default=0)");
88
89static int disable_discovery = -1;
90module_param(disable_discovery, int, 0);
91MODULE_PARM_DESC(disable_discovery, " disable discovery ");
92
93
Kashyap, Desai32e0eb52009-09-23 17:28:09 +053094/* diag_buffer_enable is bitwise
Kashyap, Desai1b01fe32009-09-23 17:28:59 +053095 * bit 0 set = TRACE
96 * bit 1 set = SNAPSHOT
97 * bit 2 set = EXTENDED
Kashyap, Desai32e0eb52009-09-23 17:28:09 +053098 *
99 * Either bit can be set, or both
100 */
101static int diag_buffer_enable;
102module_param(diag_buffer_enable, int, 0);
Kashyap, Desai1b01fe32009-09-23 17:28:59 +0530103MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
104 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
Kashyap, Desai32e0eb52009-09-23 17:28:09 +0530105
Kashyap, Desaifa7f3162009-09-23 17:26:58 +0530106/**
107 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
108 *
109 */
110static int
111_scsih_set_fwfault_debug(const char *val, struct kernel_param *kp)
112{
113 int ret = param_set_int(val, kp);
114 struct MPT2SAS_ADAPTER *ioc;
115
116 if (ret)
117 return ret;
118
Kashyap, Desaie75b9b62009-12-16 18:52:39 +0530119 printk(KERN_INFO "setting fwfault_debug(%d)\n", mpt2sas_fwfault_debug);
Kashyap, Desaifa7f3162009-09-23 17:26:58 +0530120 list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
121 ioc->fwfault_debug = mpt2sas_fwfault_debug;
122 return 0;
123}
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +0530124
Kashyap, Desaifa7f3162009-09-23 17:26:58 +0530125module_param_call(mpt2sas_fwfault_debug, _scsih_set_fwfault_debug,
126 param_get_int, &mpt2sas_fwfault_debug, 0644);
127
Eric Moore635374e2009-03-09 01:21:12 -0600128/**
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +0530129 * mpt2sas_remove_dead_ioc_func - kthread context to remove dead ioc
130 * @arg: input argument, used to derive ioc
131 *
132 * Return 0 if controller is removed from pci subsystem.
133 * Return -1 for other case.
134 */
135static int mpt2sas_remove_dead_ioc_func(void *arg)
136{
137 struct MPT2SAS_ADAPTER *ioc = (struct MPT2SAS_ADAPTER *)arg;
138 struct pci_dev *pdev;
139
140 if ((ioc == NULL))
141 return -1;
142
143 pdev = ioc->pdev;
144 if ((pdev == NULL))
145 return -1;
146 pci_remove_bus_device(pdev);
147 return 0;
148}
149
150
151/**
Eric Moore635374e2009-03-09 01:21:12 -0600152 * _base_fault_reset_work - workq handling ioc fault conditions
153 * @work: input argument, used to derive ioc
154 * Context: sleep.
155 *
156 * Return nothing.
157 */
158static void
159_base_fault_reset_work(struct work_struct *work)
160{
161 struct MPT2SAS_ADAPTER *ioc =
162 container_of(work, struct MPT2SAS_ADAPTER, fault_reset_work.work);
163 unsigned long flags;
164 u32 doorbell;
165 int rc;
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +0530166 struct task_struct *p;
Eric Moore635374e2009-03-09 01:21:12 -0600167
168 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
Kashyap, Desai155dd4c2009-08-20 13:22:00 +0530169 if (ioc->shost_recovery)
Eric Moore635374e2009-03-09 01:21:12 -0600170 goto rearm_timer;
171 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
172
173 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
nagalakshmi.nandigama@lsi.com845a0e42011-12-01 07:42:04 +0530174 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_MASK) {
175 printk(MPT2SAS_INFO_FMT "%s : SAS host is non-operational !!!!\n",
176 ioc->name, __func__);
177
178 /*
179 * Call _scsih_flush_pending_cmds callback so that we flush all
180 * pending commands back to OS. This call is required to aovid
181 * deadlock at block layer. Dead IOC will fail to do diag reset,
182 * and this call is safe since dead ioc will never return any
183 * command back from HW.
184 */
185 ioc->schedule_dead_ioc_flush_running_cmds(ioc);
186 /*
187 * Set remove_host flag early since kernel thread will
188 * take some time to execute.
189 */
190 ioc->remove_host = 1;
191 /*Remove the Dead Host */
192 p = kthread_run(mpt2sas_remove_dead_ioc_func, ioc,
193 "mpt2sas_dead_ioc_%d", ioc->id);
194 if (IS_ERR(p)) {
195 printk(MPT2SAS_ERR_FMT
196 "%s: Running mpt2sas_dead_ioc thread failed !!!!\n",
197 ioc->name, __func__);
198 } else {
199 printk(MPT2SAS_ERR_FMT
200 "%s: Running mpt2sas_dead_ioc thread success !!!!\n",
201 ioc->name, __func__);
202 }
203
204 return; /* don't rearm timer */
205 }
206
Eric Moore635374e2009-03-09 01:21:12 -0600207 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
208 rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
209 FORCE_BIG_HAMMER);
210 printk(MPT2SAS_WARN_FMT "%s: hard reset: %s\n", ioc->name,
211 __func__, (rc == 0) ? "success" : "failed");
212 doorbell = mpt2sas_base_get_iocstate(ioc, 0);
213 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
214 mpt2sas_base_fault_info(ioc, doorbell &
215 MPI2_DOORBELL_DATA_MASK);
216 }
217
218 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
219 rearm_timer:
220 if (ioc->fault_reset_work_q)
221 queue_delayed_work(ioc->fault_reset_work_q,
222 &ioc->fault_reset_work,
223 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
224 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
225}
226
Kashyap, Desaie4750c92009-08-07 19:37:59 +0530227/**
228 * mpt2sas_base_start_watchdog - start the fault_reset_work_q
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530229 * @ioc: per adapter object
Kashyap, Desaie4750c92009-08-07 19:37:59 +0530230 * Context: sleep.
231 *
232 * Return nothing.
233 */
234void
235mpt2sas_base_start_watchdog(struct MPT2SAS_ADAPTER *ioc)
236{
237 unsigned long flags;
238
239 if (ioc->fault_reset_work_q)
240 return;
241
242 /* initialize fault polling */
243 INIT_DELAYED_WORK(&ioc->fault_reset_work, _base_fault_reset_work);
244 snprintf(ioc->fault_reset_work_q_name,
245 sizeof(ioc->fault_reset_work_q_name), "poll_%d_status", ioc->id);
246 ioc->fault_reset_work_q =
247 create_singlethread_workqueue(ioc->fault_reset_work_q_name);
248 if (!ioc->fault_reset_work_q) {
249 printk(MPT2SAS_ERR_FMT "%s: failed (line=%d)\n",
250 ioc->name, __func__, __LINE__);
251 return;
252 }
253 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
254 if (ioc->fault_reset_work_q)
255 queue_delayed_work(ioc->fault_reset_work_q,
256 &ioc->fault_reset_work,
257 msecs_to_jiffies(FAULT_POLLING_INTERVAL));
258 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
259}
260
261/**
262 * mpt2sas_base_stop_watchdog - stop the fault_reset_work_q
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530263 * @ioc: per adapter object
Kashyap, Desaie4750c92009-08-07 19:37:59 +0530264 * Context: sleep.
265 *
266 * Return nothing.
267 */
268void
269mpt2sas_base_stop_watchdog(struct MPT2SAS_ADAPTER *ioc)
270{
271 unsigned long flags;
272 struct workqueue_struct *wq;
273
274 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
275 wq = ioc->fault_reset_work_q;
276 ioc->fault_reset_work_q = NULL;
277 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
278 if (wq) {
279 if (!cancel_delayed_work(&ioc->fault_reset_work))
280 flush_workqueue(wq);
281 destroy_workqueue(wq);
282 }
283}
284
Kashyap, Desaifa7f3162009-09-23 17:26:58 +0530285/**
286 * mpt2sas_base_fault_info - verbose translation of firmware FAULT code
287 * @ioc: per adapter object
288 * @fault_code: fault code
289 *
290 * Return nothing.
291 */
292void
293mpt2sas_base_fault_info(struct MPT2SAS_ADAPTER *ioc , u16 fault_code)
294{
295 printk(MPT2SAS_ERR_FMT "fault_state(0x%04x)!\n",
296 ioc->name, fault_code);
297}
298
299/**
300 * mpt2sas_halt_firmware - halt's mpt controller firmware
301 * @ioc: per adapter object
302 *
303 * For debugging timeout related issues. Writing 0xCOFFEE00
304 * to the doorbell register will halt controller firmware. With
305 * the purpose to stop both driver and firmware, the enduser can
306 * obtain a ring buffer from controller UART.
307 */
308void
309mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc)
310{
311 u32 doorbell;
312
313 if (!ioc->fwfault_debug)
314 return;
315
316 dump_stack();
317
318 doorbell = readl(&ioc->chip->Doorbell);
319 if ((doorbell & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT)
320 mpt2sas_base_fault_info(ioc , doorbell);
321 else {
322 writel(0xC0FFEE00, &ioc->chip->Doorbell);
323 printk(MPT2SAS_ERR_FMT "Firmware is halted due to command "
324 "timeout\n", ioc->name);
325 }
326
327 panic("panic in %s\n", __func__);
328}
329
Eric Moore635374e2009-03-09 01:21:12 -0600330#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
331/**
332 * _base_sas_ioc_info - verbose translation of the ioc status
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530333 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -0600334 * @mpi_reply: reply mf payload returned from firmware
335 * @request_hdr: request mf
336 *
337 * Return nothing.
338 */
339static void
340_base_sas_ioc_info(struct MPT2SAS_ADAPTER *ioc, MPI2DefaultReply_t *mpi_reply,
341 MPI2RequestHeader_t *request_hdr)
342{
343 u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
344 MPI2_IOCSTATUS_MASK;
345 char *desc = NULL;
346 u16 frame_sz;
347 char *func_str = NULL;
348
349 /* SCSI_IO, RAID_PASS are handled from _scsih_scsi_ioc_info */
350 if (request_hdr->Function == MPI2_FUNCTION_SCSI_IO_REQUEST ||
351 request_hdr->Function == MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH ||
352 request_hdr->Function == MPI2_FUNCTION_EVENT_NOTIFICATION)
353 return;
354
Kashyap, Desaie94f6742010-03-17 16:24:52 +0530355 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
356 return;
357
Eric Moore635374e2009-03-09 01:21:12 -0600358 switch (ioc_status) {
359
360/****************************************************************************
361* Common IOCStatus values for all replies
362****************************************************************************/
363
364 case MPI2_IOCSTATUS_INVALID_FUNCTION:
365 desc = "invalid function";
366 break;
367 case MPI2_IOCSTATUS_BUSY:
368 desc = "busy";
369 break;
370 case MPI2_IOCSTATUS_INVALID_SGL:
371 desc = "invalid sgl";
372 break;
373 case MPI2_IOCSTATUS_INTERNAL_ERROR:
374 desc = "internal error";
375 break;
376 case MPI2_IOCSTATUS_INVALID_VPID:
377 desc = "invalid vpid";
378 break;
379 case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
380 desc = "insufficient resources";
381 break;
382 case MPI2_IOCSTATUS_INVALID_FIELD:
383 desc = "invalid field";
384 break;
385 case MPI2_IOCSTATUS_INVALID_STATE:
386 desc = "invalid state";
387 break;
388 case MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED:
389 desc = "op state not supported";
390 break;
391
392/****************************************************************************
393* Config IOCStatus values
394****************************************************************************/
395
396 case MPI2_IOCSTATUS_CONFIG_INVALID_ACTION:
397 desc = "config invalid action";
398 break;
399 case MPI2_IOCSTATUS_CONFIG_INVALID_TYPE:
400 desc = "config invalid type";
401 break;
402 case MPI2_IOCSTATUS_CONFIG_INVALID_PAGE:
403 desc = "config invalid page";
404 break;
405 case MPI2_IOCSTATUS_CONFIG_INVALID_DATA:
406 desc = "config invalid data";
407 break;
408 case MPI2_IOCSTATUS_CONFIG_NO_DEFAULTS:
409 desc = "config no defaults";
410 break;
411 case MPI2_IOCSTATUS_CONFIG_CANT_COMMIT:
412 desc = "config cant commit";
413 break;
414
415/****************************************************************************
416* SCSI IO Reply
417****************************************************************************/
418
419 case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
420 case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
421 case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
422 case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
423 case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
424 case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
425 case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
426 case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
427 case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
428 case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
429 case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
430 case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
431 break;
432
433/****************************************************************************
434* For use by SCSI Initiator and SCSI Target end-to-end data protection
435****************************************************************************/
436
437 case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
438 desc = "eedp guard error";
439 break;
440 case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
441 desc = "eedp ref tag error";
442 break;
443 case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
444 desc = "eedp app tag error";
445 break;
446
447/****************************************************************************
448* SCSI Target values
449****************************************************************************/
450
451 case MPI2_IOCSTATUS_TARGET_INVALID_IO_INDEX:
452 desc = "target invalid io index";
453 break;
454 case MPI2_IOCSTATUS_TARGET_ABORTED:
455 desc = "target aborted";
456 break;
457 case MPI2_IOCSTATUS_TARGET_NO_CONN_RETRYABLE:
458 desc = "target no conn retryable";
459 break;
460 case MPI2_IOCSTATUS_TARGET_NO_CONNECTION:
461 desc = "target no connection";
462 break;
463 case MPI2_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH:
464 desc = "target xfer count mismatch";
465 break;
466 case MPI2_IOCSTATUS_TARGET_DATA_OFFSET_ERROR:
467 desc = "target data offset error";
468 break;
469 case MPI2_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA:
470 desc = "target too much write data";
471 break;
472 case MPI2_IOCSTATUS_TARGET_IU_TOO_SHORT:
473 desc = "target iu too short";
474 break;
475 case MPI2_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT:
476 desc = "target ack nak timeout";
477 break;
478 case MPI2_IOCSTATUS_TARGET_NAK_RECEIVED:
479 desc = "target nak received";
480 break;
481
482/****************************************************************************
483* Serial Attached SCSI values
484****************************************************************************/
485
486 case MPI2_IOCSTATUS_SAS_SMP_REQUEST_FAILED:
487 desc = "smp request failed";
488 break;
489 case MPI2_IOCSTATUS_SAS_SMP_DATA_OVERRUN:
490 desc = "smp data overrun";
491 break;
492
493/****************************************************************************
494* Diagnostic Buffer Post / Diagnostic Release values
495****************************************************************************/
496
497 case MPI2_IOCSTATUS_DIAGNOSTIC_RELEASED:
498 desc = "diagnostic released";
499 break;
500 default:
501 break;
502 }
503
504 if (!desc)
505 return;
506
507 switch (request_hdr->Function) {
508 case MPI2_FUNCTION_CONFIG:
509 frame_sz = sizeof(Mpi2ConfigRequest_t) + ioc->sge_size;
510 func_str = "config_page";
511 break;
512 case MPI2_FUNCTION_SCSI_TASK_MGMT:
513 frame_sz = sizeof(Mpi2SCSITaskManagementRequest_t);
514 func_str = "task_mgmt";
515 break;
516 case MPI2_FUNCTION_SAS_IO_UNIT_CONTROL:
517 frame_sz = sizeof(Mpi2SasIoUnitControlRequest_t);
518 func_str = "sas_iounit_ctl";
519 break;
520 case MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR:
521 frame_sz = sizeof(Mpi2SepRequest_t);
522 func_str = "enclosure";
523 break;
524 case MPI2_FUNCTION_IOC_INIT:
525 frame_sz = sizeof(Mpi2IOCInitRequest_t);
526 func_str = "ioc_init";
527 break;
528 case MPI2_FUNCTION_PORT_ENABLE:
529 frame_sz = sizeof(Mpi2PortEnableRequest_t);
530 func_str = "port_enable";
531 break;
532 case MPI2_FUNCTION_SMP_PASSTHROUGH:
533 frame_sz = sizeof(Mpi2SmpPassthroughRequest_t) + ioc->sge_size;
534 func_str = "smp_passthru";
535 break;
536 default:
537 frame_sz = 32;
538 func_str = "unknown";
539 break;
540 }
541
542 printk(MPT2SAS_WARN_FMT "ioc_status: %s(0x%04x), request(0x%p),"
543 " (%s)\n", ioc->name, desc, ioc_status, request_hdr, func_str);
544
545 _debug_dump_mf(request_hdr, frame_sz/4);
546}
547
548/**
549 * _base_display_event_data - verbose translation of firmware asyn events
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530550 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -0600551 * @mpi_reply: reply mf payload returned from firmware
552 *
553 * Return nothing.
554 */
555static void
556_base_display_event_data(struct MPT2SAS_ADAPTER *ioc,
557 Mpi2EventNotificationReply_t *mpi_reply)
558{
559 char *desc = NULL;
560 u16 event;
561
562 if (!(ioc->logging_level & MPT_DEBUG_EVENTS))
563 return;
564
565 event = le16_to_cpu(mpi_reply->Event);
566
567 switch (event) {
568 case MPI2_EVENT_LOG_DATA:
569 desc = "Log Data";
570 break;
571 case MPI2_EVENT_STATE_CHANGE:
572 desc = "Status Change";
573 break;
574 case MPI2_EVENT_HARD_RESET_RECEIVED:
575 desc = "Hard Reset Received";
576 break;
577 case MPI2_EVENT_EVENT_CHANGE:
578 desc = "Event Change";
579 break;
Eric Moore635374e2009-03-09 01:21:12 -0600580 case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
581 desc = "Device Status Change";
582 break;
583 case MPI2_EVENT_IR_OPERATION_STATUS:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530584 if (!ioc->hide_ir_msg)
585 desc = "IR Operation Status";
Eric Moore635374e2009-03-09 01:21:12 -0600586 break;
587 case MPI2_EVENT_SAS_DISCOVERY:
Kashyap, Desaie94f6742010-03-17 16:24:52 +0530588 {
589 Mpi2EventDataSasDiscovery_t *event_data =
590 (Mpi2EventDataSasDiscovery_t *)mpi_reply->EventData;
591 printk(MPT2SAS_INFO_FMT "Discovery: (%s)", ioc->name,
592 (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
593 "start" : "stop");
594 if (event_data->DiscoveryStatus)
595 printk("discovery_status(0x%08x)",
596 le32_to_cpu(event_data->DiscoveryStatus));
Julia Lawall7968f192010-08-05 22:19:36 +0200597 printk("\n");
Kashyap, Desaie94f6742010-03-17 16:24:52 +0530598 return;
599 }
Eric Moore635374e2009-03-09 01:21:12 -0600600 case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
601 desc = "SAS Broadcast Primitive";
602 break;
603 case MPI2_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
604 desc = "SAS Init Device Status Change";
605 break;
606 case MPI2_EVENT_SAS_INIT_TABLE_OVERFLOW:
607 desc = "SAS Init Table Overflow";
608 break;
609 case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
610 desc = "SAS Topology Change List";
611 break;
612 case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
613 desc = "SAS Enclosure Device Status Change";
614 break;
615 case MPI2_EVENT_IR_VOLUME:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530616 if (!ioc->hide_ir_msg)
617 desc = "IR Volume";
Eric Moore635374e2009-03-09 01:21:12 -0600618 break;
619 case MPI2_EVENT_IR_PHYSICAL_DISK:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530620 if (!ioc->hide_ir_msg)
621 desc = "IR Physical Disk";
Eric Moore635374e2009-03-09 01:21:12 -0600622 break;
623 case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530624 if (!ioc->hide_ir_msg)
625 desc = "IR Configuration Change List";
Eric Moore635374e2009-03-09 01:21:12 -0600626 break;
627 case MPI2_EVENT_LOG_ENTRY_ADDED:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530628 if (!ioc->hide_ir_msg)
629 desc = "Log Entry Added";
Eric Moore635374e2009-03-09 01:21:12 -0600630 break;
631 }
632
633 if (!desc)
634 return;
635
636 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, desc);
637}
638#endif
639
640/**
641 * _base_sas_log_info - verbose translation of firmware log info
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530642 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -0600643 * @log_info: log info
644 *
645 * Return nothing.
646 */
647static void
648_base_sas_log_info(struct MPT2SAS_ADAPTER *ioc , u32 log_info)
649{
650 union loginfo_type {
651 u32 loginfo;
652 struct {
653 u32 subcode:16;
654 u32 code:8;
655 u32 originator:4;
656 u32 bus_type:4;
657 } dw;
658 };
659 union loginfo_type sas_loginfo;
660 char *originator_str = NULL;
661
662 sas_loginfo.loginfo = log_info;
663 if (sas_loginfo.dw.bus_type != 3 /*SAS*/)
664 return;
665
Kashyap, Desaibe9e8cd72009-08-07 19:36:43 +0530666 /* each nexus loss loginfo */
667 if (log_info == 0x31170000)
668 return;
669
Eric Moore635374e2009-03-09 01:21:12 -0600670 /* eat the loginfos associated with task aborts */
671 if (ioc->ignore_loginfos && (log_info == 30050000 || log_info ==
672 0x31140000 || log_info == 0x31130000))
673 return;
674
675 switch (sas_loginfo.dw.originator) {
676 case 0:
677 originator_str = "IOP";
678 break;
679 case 1:
680 originator_str = "PL";
681 break;
682 case 2:
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +0530683 if (!ioc->hide_ir_msg)
684 originator_str = "IR";
685 else
686 originator_str = "WarpDrive";
Eric Moore635374e2009-03-09 01:21:12 -0600687 break;
688 }
689
690 printk(MPT2SAS_WARN_FMT "log_info(0x%08x): originator(%s), "
691 "code(0x%02x), sub_code(0x%04x)\n", ioc->name, log_info,
692 originator_str, sas_loginfo.dw.code,
693 sas_loginfo.dw.subcode);
694}
695
696/**
Eric Moore635374e2009-03-09 01:21:12 -0600697 * _base_display_reply_info -
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530698 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -0600699 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530700 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -0600701 * @reply: reply message frame(lower 32bit addr)
702 *
703 * Return nothing.
704 */
705static void
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530706_base_display_reply_info(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
Eric Moore635374e2009-03-09 01:21:12 -0600707 u32 reply)
708{
709 MPI2DefaultReply_t *mpi_reply;
710 u16 ioc_status;
711
712 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
713 ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
714#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
715 if ((ioc_status & MPI2_IOCSTATUS_MASK) &&
716 (ioc->logging_level & MPT_DEBUG_REPLY)) {
717 _base_sas_ioc_info(ioc , mpi_reply,
718 mpt2sas_base_get_msg_frame(ioc, smid));
719 }
720#endif
721 if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
722 _base_sas_log_info(ioc, le32_to_cpu(mpi_reply->IOCLogInfo));
723}
724
725/**
726 * mpt2sas_base_done - base internal command completion routine
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530727 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -0600728 * @smid: system request message index
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530729 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -0600730 * @reply: reply message frame(lower 32bit addr)
731 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530732 * Return 1 meaning mf should be freed from _base_interrupt
733 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -0600734 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530735u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530736mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
737 u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -0600738{
739 MPI2DefaultReply_t *mpi_reply;
740
741 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
742 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530743 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600744
745 if (ioc->base_cmds.status == MPT2_CMD_NOT_USED)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530746 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600747
748 ioc->base_cmds.status |= MPT2_CMD_COMPLETE;
749 if (mpi_reply) {
750 ioc->base_cmds.status |= MPT2_CMD_REPLY_VALID;
751 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
752 }
753 ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +0530754
Eric Moore635374e2009-03-09 01:21:12 -0600755 complete(&ioc->base_cmds.done);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530756 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600757}
758
759/**
760 * _base_async_event - main callback handler for firmware asyn events
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530761 * @ioc: per adapter object
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530762 * @msix_index: MSIX table index supplied by the OS
Eric Moore635374e2009-03-09 01:21:12 -0600763 * @reply: reply message frame(lower 32bit addr)
764 *
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530765 * Return 1 meaning mf should be freed from _base_interrupt
766 * 0 means the mf is freed from this function.
Eric Moore635374e2009-03-09 01:21:12 -0600767 */
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530768static u8
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530769_base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)
Eric Moore635374e2009-03-09 01:21:12 -0600770{
771 Mpi2EventNotificationReply_t *mpi_reply;
772 Mpi2EventAckRequest_t *ack_request;
773 u16 smid;
774
775 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
776 if (!mpi_reply)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530777 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600778 if (mpi_reply->Function != MPI2_FUNCTION_EVENT_NOTIFICATION)
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530779 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600780#ifdef CONFIG_SCSI_MPT2SAS_LOGGING
781 _base_display_event_data(ioc, mpi_reply);
782#endif
783 if (!(mpi_reply->AckRequired & MPI2_EVENT_NOTIFICATION_ACK_REQUIRED))
784 goto out;
785 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
786 if (!smid) {
787 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
788 ioc->name, __func__);
789 goto out;
790 }
791
792 ack_request = mpt2sas_base_get_msg_frame(ioc, smid);
793 memset(ack_request, 0, sizeof(Mpi2EventAckRequest_t));
794 ack_request->Function = MPI2_FUNCTION_EVENT_ACK;
795 ack_request->Event = mpi_reply->Event;
796 ack_request->EventContext = mpi_reply->EventContext;
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530797 ack_request->VF_ID = 0; /* TODO */
798 ack_request->VP_ID = 0;
799 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600800
801 out:
802
803 /* scsih callback handler */
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530804 mpt2sas_scsih_event_callback(ioc, msix_index, reply);
Eric Moore635374e2009-03-09 01:21:12 -0600805
806 /* ctl callback handler */
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530807 mpt2sas_ctl_event_callback(ioc, msix_index, reply);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530808
809 return 1;
Eric Moore635374e2009-03-09 01:21:12 -0600810}
811
812/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530813 * _base_get_cb_idx - obtain the callback index
814 * @ioc: per adapter object
815 * @smid: system request message index
816 *
817 * Return callback index.
818 */
819static u8
820_base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)
821{
822 int i;
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +0530823 u8 cb_idx;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530824
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +0530825 if (smid < ioc->hi_priority_smid) {
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530826 i = smid - 1;
827 cb_idx = ioc->scsi_lookup[i].cb_idx;
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +0530828 } else if (smid < ioc->internal_smid) {
829 i = smid - ioc->hi_priority_smid;
830 cb_idx = ioc->hpr_lookup[i].cb_idx;
831 } else if (smid <= ioc->hba_queue_depth) {
832 i = smid - ioc->internal_smid;
833 cb_idx = ioc->internal_lookup[i].cb_idx;
834 } else
835 cb_idx = 0xFF;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530836 return cb_idx;
837}
838
839/**
Eric Moore635374e2009-03-09 01:21:12 -0600840 * _base_mask_interrupts - disable interrupts
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530841 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -0600842 *
843 * Disabling ResetIRQ, Reply and Doorbell Interrupts
844 *
845 * Return nothing.
846 */
847static void
848_base_mask_interrupts(struct MPT2SAS_ADAPTER *ioc)
849{
850 u32 him_register;
851
852 ioc->mask_interrupts = 1;
853 him_register = readl(&ioc->chip->HostInterruptMask);
854 him_register |= MPI2_HIM_DIM + MPI2_HIM_RIM + MPI2_HIM_RESET_IRQ_MASK;
855 writel(him_register, &ioc->chip->HostInterruptMask);
856 readl(&ioc->chip->HostInterruptMask);
857}
858
859/**
860 * _base_unmask_interrupts - enable interrupts
Kashyap, Desaicef7a122009-09-23 17:27:41 +0530861 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -0600862 *
863 * Enabling only Reply Interrupts
864 *
865 * Return nothing.
866 */
867static void
868_base_unmask_interrupts(struct MPT2SAS_ADAPTER *ioc)
869{
870 u32 him_register;
871
Eric Moore635374e2009-03-09 01:21:12 -0600872 him_register = readl(&ioc->chip->HostInterruptMask);
873 him_register &= ~MPI2_HIM_RIM;
874 writel(him_register, &ioc->chip->HostInterruptMask);
875 ioc->mask_interrupts = 0;
876}
877
Kashyap, Desai5b768582009-08-20 13:24:31 +0530878union reply_descriptor {
879 u64 word;
880 struct {
881 u32 low;
882 u32 high;
883 } u;
884};
885
Eric Moore635374e2009-03-09 01:21:12 -0600886/**
887 * _base_interrupt - MPT adapter (IOC) specific interrupt handler.
888 * @irq: irq number (not used)
889 * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
890 * @r: pt_regs pointer (not used)
891 *
892 * Return IRQ_HANDLE if processed, else IRQ_NONE.
893 */
894static irqreturn_t
895_base_interrupt(int irq, void *bus_id)
896{
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530897 struct adapter_reply_queue *reply_q = bus_id;
Eric Moore03ea1112009-04-21 15:37:57 -0600898 union reply_descriptor rd;
Kashyap, Desai5b768582009-08-20 13:24:31 +0530899 u32 completed_cmds;
Eric Moore635374e2009-03-09 01:21:12 -0600900 u8 request_desript_type;
901 u16 smid;
902 u8 cb_idx;
903 u32 reply;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530904 u8 msix_index = reply_q->msix_index;
905 struct MPT2SAS_ADAPTER *ioc = reply_q->ioc;
Kashyap, Desai5b768582009-08-20 13:24:31 +0530906 Mpi2ReplyDescriptorsUnion_t *rpf;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530907 u8 rc;
Eric Moore635374e2009-03-09 01:21:12 -0600908
909 if (ioc->mask_interrupts)
910 return IRQ_NONE;
911
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530912 if (!atomic_add_unless(&reply_q->busy, 1, 1))
913 return IRQ_NONE;
914
915 rpf = &reply_q->reply_post_free[reply_q->reply_post_host_index];
Kashyap, Desai5b768582009-08-20 13:24:31 +0530916 request_desript_type = rpf->Default.ReplyFlags
917 & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530918 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED) {
919 atomic_dec(&reply_q->busy);
Eric Moore635374e2009-03-09 01:21:12 -0600920 return IRQ_NONE;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530921 }
Eric Moore635374e2009-03-09 01:21:12 -0600922
923 completed_cmds = 0;
Kashyap, Desaidd3741d2010-11-13 04:31:14 +0530924 cb_idx = 0xFF;
Eric Moore635374e2009-03-09 01:21:12 -0600925 do {
Kashyap, Desaic97951e2011-06-14 10:54:56 +0530926 rd.word = le64_to_cpu(rpf->Words);
Eric Moore03ea1112009-04-21 15:37:57 -0600927 if (rd.u.low == UINT_MAX || rd.u.high == UINT_MAX)
Eric Moore635374e2009-03-09 01:21:12 -0600928 goto out;
929 reply = 0;
Kashyap, Desai5b768582009-08-20 13:24:31 +0530930 smid = le16_to_cpu(rpf->Default.DescriptorTypeDependent1);
Eric Moore635374e2009-03-09 01:21:12 -0600931 if (request_desript_type ==
932 MPI2_RPY_DESCRIPT_FLAGS_ADDRESS_REPLY) {
Kashyap, Desai5b768582009-08-20 13:24:31 +0530933 reply = le32_to_cpu
934 (rpf->AddressReply.ReplyFrameAddress);
Kashyap, Desaidd3741d2010-11-13 04:31:14 +0530935 if (reply > ioc->reply_dma_max_address ||
936 reply < ioc->reply_dma_min_address)
937 reply = 0;
Eric Moore635374e2009-03-09 01:21:12 -0600938 } else if (request_desript_type ==
939 MPI2_RPY_DESCRIPT_FLAGS_TARGET_COMMAND_BUFFER)
940 goto next;
941 else if (request_desript_type ==
942 MPI2_RPY_DESCRIPT_FLAGS_TARGETASSIST_SUCCESS)
943 goto next;
944 if (smid)
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530945 cb_idx = _base_get_cb_idx(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600946 if (smid && cb_idx != 0xFF) {
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530947 rc = mpt_callbacks[cb_idx](ioc, smid, msix_index,
Kashyap, Desai595bb0b2009-09-14 11:02:48 +0530948 reply);
Eric Moore635374e2009-03-09 01:21:12 -0600949 if (reply)
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530950 _base_display_reply_info(ioc, smid, msix_index,
Eric Moore635374e2009-03-09 01:21:12 -0600951 reply);
Kashyap, Desai77e63ed2009-09-14 11:04:23 +0530952 if (rc)
953 mpt2sas_base_free_smid(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -0600954 }
955 if (!smid)
Kashyap, Desai7b936b02009-09-25 11:44:41 +0530956 _base_async_event(ioc, msix_index, reply);
Eric Moore635374e2009-03-09 01:21:12 -0600957
958 /* reply free queue handling */
959 if (reply) {
960 ioc->reply_free_host_index =
961 (ioc->reply_free_host_index ==
962 (ioc->reply_free_queue_depth - 1)) ?
963 0 : ioc->reply_free_host_index + 1;
964 ioc->reply_free[ioc->reply_free_host_index] =
965 cpu_to_le32(reply);
Kashyap, Desai5b768582009-08-20 13:24:31 +0530966 wmb();
Eric Moore635374e2009-03-09 01:21:12 -0600967 writel(ioc->reply_free_host_index,
968 &ioc->chip->ReplyFreeHostIndex);
Eric Moore635374e2009-03-09 01:21:12 -0600969 }
970
971 next:
Kashyap, Desai5b768582009-08-20 13:24:31 +0530972
Kashyap, Desaic97951e2011-06-14 10:54:56 +0530973 rpf->Words = cpu_to_le64(ULLONG_MAX);
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530974 reply_q->reply_post_host_index =
975 (reply_q->reply_post_host_index ==
Kashyap, Desai5b768582009-08-20 13:24:31 +0530976 (ioc->reply_post_queue_depth - 1)) ? 0 :
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530977 reply_q->reply_post_host_index + 1;
Eric Moore635374e2009-03-09 01:21:12 -0600978 request_desript_type =
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530979 reply_q->reply_post_free[reply_q->reply_post_host_index].
980 Default.ReplyFlags & MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
Eric Moore635374e2009-03-09 01:21:12 -0600981 completed_cmds++;
982 if (request_desript_type == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
983 goto out;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530984 if (!reply_q->reply_post_host_index)
985 rpf = reply_q->reply_post_free;
Kashyap, Desai5b768582009-08-20 13:24:31 +0530986 else
987 rpf++;
Eric Moore635374e2009-03-09 01:21:12 -0600988 } while (1);
989
990 out:
991
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530992 if (!completed_cmds) {
993 atomic_dec(&reply_q->busy);
Eric Moore635374e2009-03-09 01:21:12 -0600994 return IRQ_NONE;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530995 }
Eric Moore635374e2009-03-09 01:21:12 -0600996 wmb();
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +0530997 if (ioc->is_warpdrive) {
998 writel(reply_q->reply_post_host_index,
999 ioc->reply_post_host_index[msix_index]);
1000 atomic_dec(&reply_q->busy);
1001 return IRQ_HANDLED;
1002 }
1003 writel(reply_q->reply_post_host_index | (msix_index <<
1004 MPI2_RPHI_MSIX_INDEX_SHIFT), &ioc->chip->ReplyPostHostIndex);
1005 atomic_dec(&reply_q->busy);
Eric Moore635374e2009-03-09 01:21:12 -06001006 return IRQ_HANDLED;
1007}
1008
1009/**
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301010 * _base_is_controller_msix_enabled - is controller support muli-reply queues
1011 * @ioc: per adapter object
1012 *
1013 */
1014static inline int
1015_base_is_controller_msix_enabled(struct MPT2SAS_ADAPTER *ioc)
1016{
1017 return (ioc->facts.IOCCapabilities &
1018 MPI2_IOCFACTS_CAPABILITY_MSI_X_INDEX) && ioc->msix_enable;
1019}
1020
1021/**
1022 * mpt2sas_base_flush_reply_queues - flushing the MSIX reply queues
1023 * @ioc: per adapter object
1024 * Context: ISR conext
1025 *
1026 * Called when a Task Management request has completed. We want
1027 * to flush the other reply queues so all the outstanding IO has been
1028 * completed back to OS before we process the TM completetion.
1029 *
1030 * Return nothing.
1031 */
1032void
1033mpt2sas_base_flush_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1034{
1035 struct adapter_reply_queue *reply_q;
1036
1037 /* If MSIX capability is turned off
1038 * then multi-queues are not enabled
1039 */
1040 if (!_base_is_controller_msix_enabled(ioc))
1041 return;
1042
1043 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
1044 if (ioc->shost_recovery)
1045 return;
1046 /* TMs are on msix_index == 0 */
1047 if (reply_q->msix_index == 0)
1048 continue;
1049 _base_interrupt(reply_q->vector, (void *)reply_q);
1050 }
1051}
1052
1053/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001054 * mpt2sas_base_release_callback_handler - clear interrupt callback handler
Eric Moore635374e2009-03-09 01:21:12 -06001055 * @cb_idx: callback index
1056 *
1057 * Return nothing.
1058 */
1059void
1060mpt2sas_base_release_callback_handler(u8 cb_idx)
1061{
1062 mpt_callbacks[cb_idx] = NULL;
1063}
1064
1065/**
1066 * mpt2sas_base_register_callback_handler - obtain index for the interrupt callback handler
1067 * @cb_func: callback function
1068 *
1069 * Returns cb_func.
1070 */
1071u8
1072mpt2sas_base_register_callback_handler(MPT_CALLBACK cb_func)
1073{
1074 u8 cb_idx;
1075
1076 for (cb_idx = MPT_MAX_CALLBACKS-1; cb_idx; cb_idx--)
1077 if (mpt_callbacks[cb_idx] == NULL)
1078 break;
1079
1080 mpt_callbacks[cb_idx] = cb_func;
1081 return cb_idx;
1082}
1083
1084/**
1085 * mpt2sas_base_initialize_callback_handler - initialize the interrupt callback handler
1086 *
1087 * Return nothing.
1088 */
1089void
1090mpt2sas_base_initialize_callback_handler(void)
1091{
1092 u8 cb_idx;
1093
1094 for (cb_idx = 0; cb_idx < MPT_MAX_CALLBACKS; cb_idx++)
1095 mpt2sas_base_release_callback_handler(cb_idx);
1096}
1097
1098/**
1099 * mpt2sas_base_build_zero_len_sge - build zero length sg entry
1100 * @ioc: per adapter object
1101 * @paddr: virtual address for SGE
1102 *
1103 * Create a zero length scatter gather entry to insure the IOCs hardware has
1104 * something to use if the target device goes brain dead and tries
1105 * to send data even when none is asked for.
1106 *
1107 * Return nothing.
1108 */
1109void
1110mpt2sas_base_build_zero_len_sge(struct MPT2SAS_ADAPTER *ioc, void *paddr)
1111{
1112 u32 flags_length = (u32)((MPI2_SGE_FLAGS_LAST_ELEMENT |
1113 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST |
1114 MPI2_SGE_FLAGS_SIMPLE_ELEMENT) <<
1115 MPI2_SGE_FLAGS_SHIFT);
1116 ioc->base_add_sg_single(paddr, flags_length, -1);
1117}
1118
1119/**
1120 * _base_add_sg_single_32 - Place a simple 32 bit SGE at address pAddr.
1121 * @paddr: virtual address for SGE
1122 * @flags_length: SGE flags and data transfer length
1123 * @dma_addr: Physical address
1124 *
1125 * Return nothing.
1126 */
1127static void
1128_base_add_sg_single_32(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1129{
1130 Mpi2SGESimple32_t *sgel = paddr;
1131
1132 flags_length |= (MPI2_SGE_FLAGS_32_BIT_ADDRESSING |
1133 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1134 sgel->FlagsLength = cpu_to_le32(flags_length);
1135 sgel->Address = cpu_to_le32(dma_addr);
1136}
1137
1138
1139/**
1140 * _base_add_sg_single_64 - Place a simple 64 bit SGE at address pAddr.
1141 * @paddr: virtual address for SGE
1142 * @flags_length: SGE flags and data transfer length
1143 * @dma_addr: Physical address
1144 *
1145 * Return nothing.
1146 */
1147static void
1148_base_add_sg_single_64(void *paddr, u32 flags_length, dma_addr_t dma_addr)
1149{
1150 Mpi2SGESimple64_t *sgel = paddr;
1151
1152 flags_length |= (MPI2_SGE_FLAGS_64_BIT_ADDRESSING |
1153 MPI2_SGE_FLAGS_SYSTEM_ADDRESS) << MPI2_SGE_FLAGS_SHIFT;
1154 sgel->FlagsLength = cpu_to_le32(flags_length);
1155 sgel->Address = cpu_to_le64(dma_addr);
1156}
1157
1158#define convert_to_kb(x) ((x) << (PAGE_SHIFT - 10))
1159
1160/**
1161 * _base_config_dma_addressing - set dma addressing
1162 * @ioc: per adapter object
1163 * @pdev: PCI device struct
1164 *
1165 * Returns 0 for success, non-zero for failure.
1166 */
1167static int
1168_base_config_dma_addressing(struct MPT2SAS_ADAPTER *ioc, struct pci_dev *pdev)
1169{
1170 struct sysinfo s;
1171 char *desc = NULL;
1172
1173 if (sizeof(dma_addr_t) > 4) {
1174 const uint64_t required_mask =
1175 dma_get_required_mask(&pdev->dev);
Yang Hongyange9304382009-04-13 14:40:14 -07001176 if ((required_mask > DMA_BIT_MASK(32)) && !pci_set_dma_mask(pdev,
1177 DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(pdev,
1178 DMA_BIT_MASK(64))) {
Eric Moore635374e2009-03-09 01:21:12 -06001179 ioc->base_add_sg_single = &_base_add_sg_single_64;
1180 ioc->sge_size = sizeof(Mpi2SGESimple64_t);
1181 desc = "64";
1182 goto out;
1183 }
1184 }
1185
Yang Hongyange9304382009-04-13 14:40:14 -07001186 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
1187 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
Eric Moore635374e2009-03-09 01:21:12 -06001188 ioc->base_add_sg_single = &_base_add_sg_single_32;
1189 ioc->sge_size = sizeof(Mpi2SGESimple32_t);
1190 desc = "32";
1191 } else
1192 return -ENODEV;
1193
1194 out:
1195 si_meminfo(&s);
1196 printk(MPT2SAS_INFO_FMT "%s BIT PCI BUS DMA ADDRESSING SUPPORTED, "
1197 "total mem (%ld kB)\n", ioc->name, desc, convert_to_kb(s.totalram));
1198
1199 return 0;
1200}
1201
1202/**
Eric Moore635374e2009-03-09 01:21:12 -06001203 * _base_check_enable_msix - checks MSIX capabable.
1204 * @ioc: per adapter object
1205 *
1206 * Check to see if card is capable of MSIX, and set number
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001207 * of available msix vectors
Eric Moore635374e2009-03-09 01:21:12 -06001208 */
1209static int
1210_base_check_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1211{
1212 int base;
1213 u16 message_control;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301214
Eric Moore635374e2009-03-09 01:21:12 -06001215
1216 base = pci_find_capability(ioc->pdev, PCI_CAP_ID_MSIX);
1217 if (!base) {
1218 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "msix not "
1219 "supported\n", ioc->name));
1220 return -EINVAL;
1221 }
1222
1223 /* get msix vector count */
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301224 /* NUMA_IO not supported for older controllers */
1225 if (ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2004 ||
1226 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2008 ||
1227 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_1 ||
1228 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_2 ||
1229 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2108_3 ||
1230 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_1 ||
1231 ioc->pdev->device == MPI2_MFGPAGE_DEVID_SAS2116_2)
1232 ioc->msix_vector_count = 1;
1233 else {
1234 pci_read_config_word(ioc->pdev, base + 2, &message_control);
1235 ioc->msix_vector_count = (message_control & 0x3FF) + 1;
1236 }
Eric Moore635374e2009-03-09 01:21:12 -06001237 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "msix is supported, "
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301238 "vector_count(%d)\n", ioc->name, ioc->msix_vector_count));
1239
Eric Moore635374e2009-03-09 01:21:12 -06001240 return 0;
1241}
1242
1243/**
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301244 * _base_free_irq - free irq
1245 * @ioc: per adapter object
1246 *
1247 * Freeing respective reply_queue from the list.
1248 */
1249static void
1250_base_free_irq(struct MPT2SAS_ADAPTER *ioc)
1251{
1252 struct adapter_reply_queue *reply_q, *next;
1253
1254 if (list_empty(&ioc->reply_queue_list))
1255 return;
1256
1257 list_for_each_entry_safe(reply_q, next, &ioc->reply_queue_list, list) {
1258 list_del(&reply_q->list);
1259 synchronize_irq(reply_q->vector);
1260 free_irq(reply_q->vector, reply_q);
1261 kfree(reply_q);
1262 }
1263}
1264
1265/**
1266 * _base_request_irq - request irq
1267 * @ioc: per adapter object
1268 * @index: msix index into vector table
1269 * @vector: irq vector
1270 *
1271 * Inserting respective reply_queue into the list.
1272 */
1273static int
1274_base_request_irq(struct MPT2SAS_ADAPTER *ioc, u8 index, u32 vector)
1275{
1276 struct adapter_reply_queue *reply_q;
1277 int r;
1278
1279 reply_q = kzalloc(sizeof(struct adapter_reply_queue), GFP_KERNEL);
1280 if (!reply_q) {
1281 printk(MPT2SAS_ERR_FMT "unable to allocate memory %d!\n",
1282 ioc->name, (int)sizeof(struct adapter_reply_queue));
1283 return -ENOMEM;
1284 }
1285 reply_q->ioc = ioc;
1286 reply_q->msix_index = index;
1287 reply_q->vector = vector;
1288 atomic_set(&reply_q->busy, 0);
1289 if (ioc->msix_enable)
1290 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d-msix%d",
1291 MPT2SAS_DRIVER_NAME, ioc->id, index);
1292 else
1293 snprintf(reply_q->name, MPT_NAME_LENGTH, "%s%d",
1294 MPT2SAS_DRIVER_NAME, ioc->id);
1295 r = request_irq(vector, _base_interrupt, IRQF_SHARED, reply_q->name,
1296 reply_q);
1297 if (r) {
1298 printk(MPT2SAS_ERR_FMT "unable to allocate interrupt %d!\n",
1299 reply_q->name, vector);
1300 kfree(reply_q);
1301 return -EBUSY;
1302 }
1303
1304 INIT_LIST_HEAD(&reply_q->list);
1305 list_add_tail(&reply_q->list, &ioc->reply_queue_list);
1306 return 0;
1307}
1308
1309/**
1310 * _base_assign_reply_queues - assigning msix index for each cpu
1311 * @ioc: per adapter object
1312 *
1313 * The enduser would need to set the affinity via /proc/irq/#/smp_affinity
1314 *
1315 * It would nice if we could call irq_set_affinity, however it is not
1316 * an exported symbol
1317 */
1318static void
1319_base_assign_reply_queues(struct MPT2SAS_ADAPTER *ioc)
1320{
1321 struct adapter_reply_queue *reply_q;
1322 int cpu_id;
1323 int cpu_grouping, loop, grouping, grouping_mod;
1324
1325 if (!_base_is_controller_msix_enabled(ioc))
1326 return;
1327
1328 memset(ioc->cpu_msix_table, 0, ioc->cpu_msix_table_sz);
1329 /* when there are more cpus than available msix vectors,
1330 * then group cpus togeather on same irq
1331 */
1332 if (ioc->cpu_count > ioc->msix_vector_count) {
1333 grouping = ioc->cpu_count / ioc->msix_vector_count;
1334 grouping_mod = ioc->cpu_count % ioc->msix_vector_count;
1335 if (grouping < 2 || (grouping == 2 && !grouping_mod))
1336 cpu_grouping = 2;
1337 else if (grouping < 4 || (grouping == 4 && !grouping_mod))
1338 cpu_grouping = 4;
1339 else if (grouping < 8 || (grouping == 8 && !grouping_mod))
1340 cpu_grouping = 8;
1341 else
1342 cpu_grouping = 16;
1343 } else
1344 cpu_grouping = 0;
1345
1346 loop = 0;
1347 reply_q = list_entry(ioc->reply_queue_list.next,
1348 struct adapter_reply_queue, list);
1349 for_each_online_cpu(cpu_id) {
1350 if (!cpu_grouping) {
1351 ioc->cpu_msix_table[cpu_id] = reply_q->msix_index;
1352 reply_q = list_entry(reply_q->list.next,
1353 struct adapter_reply_queue, list);
1354 } else {
1355 if (loop < cpu_grouping) {
1356 ioc->cpu_msix_table[cpu_id] =
1357 reply_q->msix_index;
1358 loop++;
1359 } else {
1360 reply_q = list_entry(reply_q->list.next,
1361 struct adapter_reply_queue, list);
1362 ioc->cpu_msix_table[cpu_id] =
1363 reply_q->msix_index;
1364 loop = 1;
1365 }
1366 }
1367 }
1368}
1369
1370/**
Eric Moore635374e2009-03-09 01:21:12 -06001371 * _base_disable_msix - disables msix
1372 * @ioc: per adapter object
1373 *
1374 */
1375static void
1376_base_disable_msix(struct MPT2SAS_ADAPTER *ioc)
1377{
1378 if (ioc->msix_enable) {
1379 pci_disable_msix(ioc->pdev);
Eric Moore635374e2009-03-09 01:21:12 -06001380 ioc->msix_enable = 0;
1381 }
1382}
1383
1384/**
1385 * _base_enable_msix - enables msix, failback to io_apic
1386 * @ioc: per adapter object
1387 *
1388 */
1389static int
1390_base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
1391{
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301392 struct msix_entry *entries, *a;
Eric Moore635374e2009-03-09 01:21:12 -06001393 int r;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301394 int i;
Eric Moore635374e2009-03-09 01:21:12 -06001395 u8 try_msix = 0;
1396
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301397 INIT_LIST_HEAD(&ioc->reply_queue_list);
1398
Eric Moore635374e2009-03-09 01:21:12 -06001399 if (msix_disable == -1 || msix_disable == 0)
1400 try_msix = 1;
1401
1402 if (!try_msix)
1403 goto try_ioapic;
1404
1405 if (_base_check_enable_msix(ioc) != 0)
1406 goto try_ioapic;
1407
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301408 ioc->reply_queue_count = min_t(u8, ioc->cpu_count,
1409 ioc->msix_vector_count);
1410
1411 entries = kcalloc(ioc->reply_queue_count, sizeof(struct msix_entry),
1412 GFP_KERNEL);
1413 if (!entries) {
1414 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "kcalloc "
1415 "failed @ at %s:%d/%s() !!!\n", ioc->name, __FILE__,
1416 __LINE__, __func__));
Eric Moore635374e2009-03-09 01:21:12 -06001417 goto try_ioapic;
1418 }
1419
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301420 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++)
1421 a->entry = i;
1422
1423 r = pci_enable_msix(ioc->pdev, entries, ioc->reply_queue_count);
Eric Moore635374e2009-03-09 01:21:12 -06001424 if (r) {
1425 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "pci_enable_msix "
1426 "failed (r=%d) !!!\n", ioc->name, r));
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301427 kfree(entries);
Eric Moore635374e2009-03-09 01:21:12 -06001428 goto try_ioapic;
1429 }
1430
Eric Moore635374e2009-03-09 01:21:12 -06001431 ioc->msix_enable = 1;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301432 for (i = 0, a = entries; i < ioc->reply_queue_count; i++, a++) {
1433 r = _base_request_irq(ioc, i, a->vector);
1434 if (r) {
1435 _base_free_irq(ioc);
1436 _base_disable_msix(ioc);
1437 kfree(entries);
1438 goto try_ioapic;
1439 }
1440 }
1441
1442 kfree(entries);
Eric Moore635374e2009-03-09 01:21:12 -06001443 return 0;
1444
1445/* failback to io_apic interrupt routing */
1446 try_ioapic:
1447
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301448 r = _base_request_irq(ioc, 0, ioc->pdev->irq);
Eric Moore635374e2009-03-09 01:21:12 -06001449
Eric Moore635374e2009-03-09 01:21:12 -06001450 return r;
1451}
1452
1453/**
1454 * mpt2sas_base_map_resources - map in controller resources (io/irq/memap)
1455 * @ioc: per adapter object
1456 *
1457 * Returns 0 for success, non-zero for failure.
1458 */
1459int
1460mpt2sas_base_map_resources(struct MPT2SAS_ADAPTER *ioc)
1461{
1462 struct pci_dev *pdev = ioc->pdev;
1463 u32 memap_sz;
1464 u32 pio_sz;
1465 int i, r = 0;
Kashyap, Desai6846e752009-12-16 18:51:45 +05301466 u64 pio_chip = 0;
1467 u64 chip_phys = 0;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301468 struct adapter_reply_queue *reply_q;
Eric Moore635374e2009-03-09 01:21:12 -06001469
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05301470 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n",
Eric Moore635374e2009-03-09 01:21:12 -06001471 ioc->name, __func__));
1472
1473 ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
1474 if (pci_enable_device_mem(pdev)) {
1475 printk(MPT2SAS_WARN_FMT "pci_enable_device_mem: "
1476 "failed\n", ioc->name);
1477 return -ENODEV;
1478 }
1479
1480
1481 if (pci_request_selected_regions(pdev, ioc->bars,
1482 MPT2SAS_DRIVER_NAME)) {
1483 printk(MPT2SAS_WARN_FMT "pci_request_selected_regions: "
1484 "failed\n", ioc->name);
1485 r = -ENODEV;
1486 goto out_fail;
1487 }
1488
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05301489 /* AER (Advanced Error Reporting) hooks */
1490 pci_enable_pcie_error_reporting(pdev);
1491
Eric Moore635374e2009-03-09 01:21:12 -06001492 pci_set_master(pdev);
1493
1494 if (_base_config_dma_addressing(ioc, pdev) != 0) {
1495 printk(MPT2SAS_WARN_FMT "no suitable DMA mask for %s\n",
1496 ioc->name, pci_name(pdev));
1497 r = -ENODEV;
1498 goto out_fail;
1499 }
1500
1501 for (i = 0, memap_sz = 0, pio_sz = 0 ; i < DEVICE_COUNT_RESOURCE; i++) {
Richard A Laryfc193172010-03-12 15:27:06 -08001502 if (pci_resource_flags(pdev, i) & IORESOURCE_IO) {
Eric Moore635374e2009-03-09 01:21:12 -06001503 if (pio_sz)
1504 continue;
Kashyap, Desai6846e752009-12-16 18:51:45 +05301505 pio_chip = (u64)pci_resource_start(pdev, i);
Eric Moore635374e2009-03-09 01:21:12 -06001506 pio_sz = pci_resource_len(pdev, i);
1507 } else {
1508 if (memap_sz)
1509 continue;
Richard A Laryfc193172010-03-12 15:27:06 -08001510 /* verify memory resource is valid before using */
1511 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
1512 ioc->chip_phys = pci_resource_start(pdev, i);
1513 chip_phys = (u64)ioc->chip_phys;
1514 memap_sz = pci_resource_len(pdev, i);
1515 ioc->chip = ioremap(ioc->chip_phys, memap_sz);
1516 if (ioc->chip == NULL) {
1517 printk(MPT2SAS_ERR_FMT "unable to map "
1518 "adapter memory!\n", ioc->name);
1519 r = -EINVAL;
1520 goto out_fail;
1521 }
Eric Moore635374e2009-03-09 01:21:12 -06001522 }
1523 }
1524 }
1525
Eric Moore635374e2009-03-09 01:21:12 -06001526 _base_mask_interrupts(ioc);
1527 r = _base_enable_msix(ioc);
1528 if (r)
1529 goto out_fail;
1530
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301531 list_for_each_entry(reply_q, &ioc->reply_queue_list, list)
1532 printk(MPT2SAS_INFO_FMT "%s: IRQ %d\n",
1533 reply_q->name, ((ioc->msix_enable) ? "PCI-MSI-X enabled" :
1534 "IO-APIC enabled"), reply_q->vector);
1535
Kashyap, Desai6846e752009-12-16 18:51:45 +05301536 printk(MPT2SAS_INFO_FMT "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
1537 ioc->name, (unsigned long long)chip_phys, ioc->chip, memap_sz);
1538 printk(MPT2SAS_INFO_FMT "ioport(0x%016llx), size(%d)\n",
1539 ioc->name, (unsigned long long)pio_chip, pio_sz);
Eric Moore635374e2009-03-09 01:21:12 -06001540
Eric Moore3cb54692010-07-08 14:44:34 -06001541 /* Save PCI configuration state for recovery from PCI AER/EEH errors */
1542 pci_save_state(pdev);
1543
Eric Moore635374e2009-03-09 01:21:12 -06001544 return 0;
1545
1546 out_fail:
1547 if (ioc->chip_phys)
1548 iounmap(ioc->chip);
1549 ioc->chip_phys = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001550 pci_release_selected_regions(ioc->pdev, ioc->bars);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05301551 pci_disable_pcie_error_reporting(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06001552 pci_disable_device(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06001553 return r;
1554}
1555
1556/**
Eric Moore635374e2009-03-09 01:21:12 -06001557 * mpt2sas_base_get_msg_frame - obtain request mf pointer
1558 * @ioc: per adapter object
1559 * @smid: system request message index(smid zero is invalid)
1560 *
1561 * Returns virt pointer to message frame.
1562 */
1563void *
1564mpt2sas_base_get_msg_frame(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1565{
1566 return (void *)(ioc->request + (smid * ioc->request_sz));
1567}
1568
1569/**
1570 * mpt2sas_base_get_sense_buffer - obtain a sense buffer assigned to a mf request
1571 * @ioc: per adapter object
1572 * @smid: system request message index
1573 *
1574 * Returns virt pointer to sense buffer.
1575 */
1576void *
1577mpt2sas_base_get_sense_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1578{
1579 return (void *)(ioc->sense + ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
1580}
1581
1582/**
1583 * mpt2sas_base_get_sense_buffer_dma - obtain a sense buffer assigned to a mf request
1584 * @ioc: per adapter object
1585 * @smid: system request message index
1586 *
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05301587 * Returns phys pointer to the low 32bit address of the sense buffer.
Eric Moore635374e2009-03-09 01:21:12 -06001588 */
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05301589__le32
Eric Moore635374e2009-03-09 01:21:12 -06001590mpt2sas_base_get_sense_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1591{
Kashyap, Desaiec9472c2009-09-23 17:34:13 +05301592 return cpu_to_le32(ioc->sense_dma +
1593 ((smid - 1) * SCSI_SENSE_BUFFERSIZE));
Eric Moore635374e2009-03-09 01:21:12 -06001594}
1595
1596/**
1597 * mpt2sas_base_get_reply_virt_addr - obtain reply frames virt address
1598 * @ioc: per adapter object
1599 * @phys_addr: lower 32 physical addr of the reply
1600 *
1601 * Converts 32bit lower physical addr into a virt address.
1602 */
1603void *
1604mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr)
1605{
1606 if (!phys_addr)
1607 return NULL;
1608 return ioc->reply + (phys_addr - (u32)ioc->reply_dma);
1609}
1610
1611/**
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301612 * mpt2sas_base_get_smid - obtain a free smid from internal queue
Eric Moore635374e2009-03-09 01:21:12 -06001613 * @ioc: per adapter object
1614 * @cb_idx: callback index
1615 *
1616 * Returns smid (zero is invalid)
1617 */
1618u16
1619mpt2sas_base_get_smid(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1620{
1621 unsigned long flags;
1622 struct request_tracker *request;
1623 u16 smid;
1624
1625 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301626 if (list_empty(&ioc->internal_free_list)) {
1627 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1628 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1629 ioc->name, __func__);
1630 return 0;
1631 }
1632
1633 request = list_entry(ioc->internal_free_list.next,
1634 struct request_tracker, tracker_list);
1635 request->cb_idx = cb_idx;
1636 smid = request->smid;
1637 list_del(&request->tracker_list);
1638 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1639 return smid;
1640}
1641
1642/**
1643 * mpt2sas_base_get_smid_scsiio - obtain a free smid from scsiio queue
1644 * @ioc: per adapter object
1645 * @cb_idx: callback index
1646 * @scmd: pointer to scsi command object
1647 *
1648 * Returns smid (zero is invalid)
1649 */
1650u16
1651mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,
1652 struct scsi_cmnd *scmd)
1653{
1654 unsigned long flags;
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05301655 struct scsiio_tracker *request;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301656 u16 smid;
1657
1658 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001659 if (list_empty(&ioc->free_list)) {
1660 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1661 printk(MPT2SAS_ERR_FMT "%s: smid not available\n",
1662 ioc->name, __func__);
1663 return 0;
1664 }
1665
1666 request = list_entry(ioc->free_list.next,
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05301667 struct scsiio_tracker, tracker_list);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301668 request->scmd = scmd;
1669 request->cb_idx = cb_idx;
1670 smid = request->smid;
1671 list_del(&request->tracker_list);
1672 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1673 return smid;
1674}
1675
1676/**
1677 * mpt2sas_base_get_smid_hpr - obtain a free smid from hi-priority queue
1678 * @ioc: per adapter object
1679 * @cb_idx: callback index
1680 *
1681 * Returns smid (zero is invalid)
1682 */
1683u16
1684mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)
1685{
1686 unsigned long flags;
1687 struct request_tracker *request;
1688 u16 smid;
1689
1690 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
1691 if (list_empty(&ioc->hpr_free_list)) {
1692 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1693 return 0;
1694 }
1695
1696 request = list_entry(ioc->hpr_free_list.next,
1697 struct request_tracker, tracker_list);
Eric Moore635374e2009-03-09 01:21:12 -06001698 request->cb_idx = cb_idx;
1699 smid = request->smid;
1700 list_del(&request->tracker_list);
1701 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
1702 return smid;
1703}
1704
1705
1706/**
1707 * mpt2sas_base_free_smid - put smid back on free_list
1708 * @ioc: per adapter object
1709 * @smid: system request message index
1710 *
1711 * Return nothing.
1712 */
1713void
1714mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid)
1715{
1716 unsigned long flags;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301717 int i;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301718 struct chain_tracker *chain_req, *next;
Eric Moore635374e2009-03-09 01:21:12 -06001719
1720 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05301721 if (smid < ioc->hi_priority_smid) {
1722 /* scsiio queue */
1723 i = smid - 1;
1724 if (!list_empty(&ioc->scsi_lookup[i].chain_list)) {
1725 list_for_each_entry_safe(chain_req, next,
1726 &ioc->scsi_lookup[i].chain_list, tracker_list) {
1727 list_del_init(&chain_req->tracker_list);
1728 list_add_tail(&chain_req->tracker_list,
1729 &ioc->free_chain_list);
1730 }
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301731 }
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05301732 ioc->scsi_lookup[i].cb_idx = 0xFF;
1733 ioc->scsi_lookup[i].scmd = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05301734 ioc->scsi_lookup[i].direct_io = 0;
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05301735 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
1736 &ioc->free_list);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301737 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05301738
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05301739 /*
1740 * See _wait_for_commands_to_complete() call with regards
1741 * to this code.
1742 */
1743 if (ioc->shost_recovery && ioc->pending_io_count) {
1744 if (ioc->pending_io_count == 1)
1745 wake_up(&ioc->reset_wq);
1746 ioc->pending_io_count--;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301747 }
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05301748 return;
1749 } else if (smid < ioc->internal_smid) {
1750 /* hi-priority */
1751 i = smid - ioc->hi_priority_smid;
1752 ioc->hpr_lookup[i].cb_idx = 0xFF;
1753 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
1754 &ioc->hpr_free_list);
1755 } else if (smid <= ioc->hba_queue_depth) {
1756 /* internal queue */
1757 i = smid - ioc->internal_smid;
1758 ioc->internal_lookup[i].cb_idx = 0xFF;
1759 list_add_tail(&ioc->internal_lookup[i].tracker_list,
1760 &ioc->internal_free_list);
Kashyap, Desai35f805b2010-11-13 04:34:06 +05301761 }
Eric Moore635374e2009-03-09 01:21:12 -06001762 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06001763}
1764
1765/**
1766 * _base_writeq - 64 bit write to MMIO
1767 * @ioc: per adapter object
1768 * @b: data payload
1769 * @addr: address in MMIO space
1770 * @writeq_lock: spin lock
1771 *
1772 * Glue for handling an atomic 64 bit word to MMIO. This special handling takes
1773 * care of 32 bit environment where its not quarenteed to send the entire word
1774 * in one transfer.
1775 */
1776#ifndef writeq
1777static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1778 spinlock_t *writeq_lock)
1779{
1780 unsigned long flags;
1781 __u64 data_out = cpu_to_le64(b);
1782
1783 spin_lock_irqsave(writeq_lock, flags);
1784 writel((u32)(data_out), addr);
1785 writel((u32)(data_out >> 32), (addr + 4));
1786 spin_unlock_irqrestore(writeq_lock, flags);
1787}
1788#else
1789static inline void _base_writeq(__u64 b, volatile void __iomem *addr,
1790 spinlock_t *writeq_lock)
1791{
1792 writeq(cpu_to_le64(b), addr);
1793}
1794#endif
1795
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301796static inline u8
1797_base_get_msix_index(struct MPT2SAS_ADAPTER *ioc)
1798{
1799 return ioc->cpu_msix_table[smp_processor_id()];
1800}
1801
Eric Moore635374e2009-03-09 01:21:12 -06001802/**
1803 * mpt2sas_base_put_smid_scsi_io - send SCSI_IO request to firmware
1804 * @ioc: per adapter object
1805 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -06001806 * @handle: device handle
1807 *
1808 * Return nothing.
1809 */
1810void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301811mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid, u16 handle)
Eric Moore635374e2009-03-09 01:21:12 -06001812{
1813 Mpi2RequestDescriptorUnion_t descriptor;
1814 u64 *request = (u64 *)&descriptor;
1815
1816
1817 descriptor.SCSIIO.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301818 descriptor.SCSIIO.MSIxIndex = _base_get_msix_index(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06001819 descriptor.SCSIIO.SMID = cpu_to_le16(smid);
1820 descriptor.SCSIIO.DevHandle = cpu_to_le16(handle);
1821 descriptor.SCSIIO.LMID = 0;
1822 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1823 &ioc->scsi_lookup_lock);
1824}
1825
1826
1827/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001828 * mpt2sas_base_put_smid_hi_priority - send Task Management request to firmware
Eric Moore635374e2009-03-09 01:21:12 -06001829 * @ioc: per adapter object
1830 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -06001831 *
1832 * Return nothing.
1833 */
1834void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301835mpt2sas_base_put_smid_hi_priority(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001836{
1837 Mpi2RequestDescriptorUnion_t descriptor;
1838 u64 *request = (u64 *)&descriptor;
1839
1840 descriptor.HighPriority.RequestFlags =
1841 MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301842 descriptor.HighPriority.MSIxIndex = 0;
Eric Moore635374e2009-03-09 01:21:12 -06001843 descriptor.HighPriority.SMID = cpu_to_le16(smid);
1844 descriptor.HighPriority.LMID = 0;
1845 descriptor.HighPriority.Reserved1 = 0;
1846 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1847 &ioc->scsi_lookup_lock);
1848}
1849
1850/**
1851 * mpt2sas_base_put_smid_default - Default, primarily used for config pages
1852 * @ioc: per adapter object
1853 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -06001854 *
1855 * Return nothing.
1856 */
1857void
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301858mpt2sas_base_put_smid_default(struct MPT2SAS_ADAPTER *ioc, u16 smid)
Eric Moore635374e2009-03-09 01:21:12 -06001859{
1860 Mpi2RequestDescriptorUnion_t descriptor;
1861 u64 *request = (u64 *)&descriptor;
1862
1863 descriptor.Default.RequestFlags = MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301864 descriptor.Default.MSIxIndex = _base_get_msix_index(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06001865 descriptor.Default.SMID = cpu_to_le16(smid);
1866 descriptor.Default.LMID = 0;
1867 descriptor.Default.DescriptorTypeDependent = 0;
1868 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1869 &ioc->scsi_lookup_lock);
1870}
1871
1872/**
1873 * mpt2sas_base_put_smid_target_assist - send Target Assist/Status to firmware
1874 * @ioc: per adapter object
1875 * @smid: system request message index
Eric Moore635374e2009-03-09 01:21:12 -06001876 * @io_index: value used to track the IO
1877 *
1878 * Return nothing.
1879 */
1880void
1881mpt2sas_base_put_smid_target_assist(struct MPT2SAS_ADAPTER *ioc, u16 smid,
Kashyap, Desai7b936b02009-09-25 11:44:41 +05301882 u16 io_index)
Eric Moore635374e2009-03-09 01:21:12 -06001883{
1884 Mpi2RequestDescriptorUnion_t descriptor;
1885 u64 *request = (u64 *)&descriptor;
1886
1887 descriptor.SCSITarget.RequestFlags =
1888 MPI2_REQ_DESCRIPT_FLAGS_SCSI_TARGET;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05301889 descriptor.SCSITarget.MSIxIndex = _base_get_msix_index(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06001890 descriptor.SCSITarget.SMID = cpu_to_le16(smid);
1891 descriptor.SCSITarget.LMID = 0;
1892 descriptor.SCSITarget.IoIndex = cpu_to_le16(io_index);
1893 _base_writeq(*request, &ioc->chip->RequestDescriptorPostLow,
1894 &ioc->scsi_lookup_lock);
1895}
1896
1897/**
Eric Mooref0f9cc12009-04-21 15:40:48 -06001898 * _base_display_dell_branding - Disply branding string
1899 * @ioc: per adapter object
1900 *
1901 * Return nothing.
1902 */
1903static void
1904_base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
1905{
1906 char dell_branding[MPT2SAS_DELL_BRANDING_SIZE];
1907
1908 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_DELL)
1909 return;
1910
1911 memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
1912 switch (ioc->pdev->subsystem_device) {
1913 case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
1914 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
1915 MPT2SAS_DELL_BRANDING_SIZE - 1);
1916 break;
1917 case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
1918 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
1919 MPT2SAS_DELL_BRANDING_SIZE - 1);
1920 break;
1921 case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
1922 strncpy(dell_branding,
1923 MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
1924 MPT2SAS_DELL_BRANDING_SIZE - 1);
1925 break;
1926 case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
1927 strncpy(dell_branding,
1928 MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
1929 MPT2SAS_DELL_BRANDING_SIZE - 1);
1930 break;
1931 case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
1932 strncpy(dell_branding,
1933 MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
1934 MPT2SAS_DELL_BRANDING_SIZE - 1);
1935 break;
1936 case MPT2SAS_DELL_PERC_H200_SSDID:
1937 strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
1938 MPT2SAS_DELL_BRANDING_SIZE - 1);
1939 break;
1940 case MPT2SAS_DELL_6GBPS_SAS_SSDID:
1941 strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
1942 MPT2SAS_DELL_BRANDING_SIZE - 1);
1943 break;
1944 default:
1945 sprintf(dell_branding, "0x%4X", ioc->pdev->subsystem_device);
1946 break;
1947 }
1948
1949 printk(MPT2SAS_INFO_FMT "%s: Vendor(0x%04X), Device(0x%04X),"
1950 " SSVID(0x%04X), SSDID(0x%04X)\n", ioc->name, dell_branding,
1951 ioc->pdev->vendor, ioc->pdev->device, ioc->pdev->subsystem_vendor,
1952 ioc->pdev->subsystem_device);
1953}
1954
1955/**
Kashyap, Desaifb396be2011-01-04 11:36:37 +05301956 * _base_display_intel_branding - Display branding string
1957 * @ioc: per adapter object
1958 *
1959 * Return nothing.
1960 */
1961static void
1962_base_display_intel_branding(struct MPT2SAS_ADAPTER *ioc)
1963{
Kashyap, Desaiab3e5f62011-06-14 10:57:31 +05301964 if (ioc->pdev->subsystem_vendor != PCI_VENDOR_ID_INTEL)
1965 return;
Kashyap, Desaifb396be2011-01-04 11:36:37 +05301966
Kashyap, Desaiab3e5f62011-06-14 10:57:31 +05301967 switch (ioc->pdev->device) {
1968 case MPI2_MFGPAGE_DEVID_SAS2008:
Kashyap, Desaifb396be2011-01-04 11:36:37 +05301969 switch (ioc->pdev->subsystem_device) {
1970 case MPT2SAS_INTEL_RMS2LL080_SSDID:
1971 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1972 MPT2SAS_INTEL_RMS2LL080_BRANDING);
1973 break;
1974 case MPT2SAS_INTEL_RMS2LL040_SSDID:
1975 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1976 MPT2SAS_INTEL_RMS2LL040_BRANDING);
1977 break;
nagalakshmi.nandigama@lsi.com70e73f92011-12-01 07:43:00 +05301978 case MPT2SAS_INTEL_RAMSDALE_SSDID:
1979 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1980 MPT2SAS_INTEL_RAMSDALE_BRANDING);
1981 break;
Kashyap, Desaiab3e5f62011-06-14 10:57:31 +05301982 default:
1983 break;
Kashyap, Desaifb396be2011-01-04 11:36:37 +05301984 }
Kashyap, Desaiab3e5f62011-06-14 10:57:31 +05301985 case MPI2_MFGPAGE_DEVID_SAS2308_2:
1986 switch (ioc->pdev->subsystem_device) {
1987 case MPT2SAS_INTEL_RS25GB008_SSDID:
1988 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
1989 MPT2SAS_INTEL_RS25GB008_BRANDING);
1990 break;
1991 default:
1992 break;
1993 }
1994 default:
1995 break;
Kashyap, Desaifb396be2011-01-04 11:36:37 +05301996 }
1997}
1998
1999/**
Kashyap, Desai0a2385c2011-03-15 20:04:26 +05302000 * _base_display_hp_branding - Display branding string
2001 * @ioc: per adapter object
2002 *
2003 * Return nothing.
2004 */
2005static void
2006_base_display_hp_branding(struct MPT2SAS_ADAPTER *ioc)
2007{
2008 if (ioc->pdev->subsystem_vendor != MPT2SAS_HP_3PAR_SSVID)
2009 return;
2010
2011 switch (ioc->pdev->device) {
2012 case MPI2_MFGPAGE_DEVID_SAS2004:
2013 switch (ioc->pdev->subsystem_device) {
2014 case MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_SSDID:
2015 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2016 MPT2SAS_HP_DAUGHTER_2_4_INTERNAL_BRANDING);
2017 break;
2018 default:
2019 break;
2020 }
2021 case MPI2_MFGPAGE_DEVID_SAS2308_2:
2022 switch (ioc->pdev->subsystem_device) {
2023 case MPT2SAS_HP_2_4_INTERNAL_SSDID:
2024 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2025 MPT2SAS_HP_2_4_INTERNAL_BRANDING);
2026 break;
2027 case MPT2SAS_HP_2_4_EXTERNAL_SSDID:
2028 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2029 MPT2SAS_HP_2_4_EXTERNAL_BRANDING);
2030 break;
2031 case MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_SSDID:
2032 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2033 MPT2SAS_HP_1_4_INTERNAL_1_4_EXTERNAL_BRANDING);
2034 break;
2035 case MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_SSDID:
2036 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
2037 MPT2SAS_HP_EMBEDDED_2_4_INTERNAL_BRANDING);
2038 break;
2039 default:
2040 break;
2041 }
2042 default:
2043 break;
2044 }
2045}
2046
2047/**
Eric Moore635374e2009-03-09 01:21:12 -06002048 * _base_display_ioc_capabilities - Disply IOC's capabilities.
2049 * @ioc: per adapter object
2050 *
2051 * Return nothing.
2052 */
2053static void
2054_base_display_ioc_capabilities(struct MPT2SAS_ADAPTER *ioc)
2055{
2056 int i = 0;
2057 char desc[16];
2058 u8 revision;
2059 u32 iounit_pg1_flags;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302060 u32 bios_version;
Eric Moore635374e2009-03-09 01:21:12 -06002061
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302062 bios_version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
Eric Moore635374e2009-03-09 01:21:12 -06002063 pci_read_config_byte(ioc->pdev, PCI_CLASS_REVISION, &revision);
2064 strncpy(desc, ioc->manu_pg0.ChipName, 16);
2065 printk(MPT2SAS_INFO_FMT "%s: FWVersion(%02d.%02d.%02d.%02d), "
2066 "ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n",
2067 ioc->name, desc,
2068 (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
2069 (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
2070 (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
2071 ioc->facts.FWVersion.Word & 0x000000FF,
2072 revision,
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302073 (bios_version & 0xFF000000) >> 24,
2074 (bios_version & 0x00FF0000) >> 16,
2075 (bios_version & 0x0000FF00) >> 8,
2076 bios_version & 0x000000FF);
Eric Moore635374e2009-03-09 01:21:12 -06002077
Kashyap, Desaied79f122009-08-20 13:23:49 +05302078 _base_display_dell_branding(ioc);
Kashyap, Desaifb396be2011-01-04 11:36:37 +05302079 _base_display_intel_branding(ioc);
Kashyap, Desai0a2385c2011-03-15 20:04:26 +05302080 _base_display_hp_branding(ioc);
Kashyap, Desaied79f122009-08-20 13:23:49 +05302081
Eric Moore635374e2009-03-09 01:21:12 -06002082 printk(MPT2SAS_INFO_FMT "Protocol=(", ioc->name);
2083
2084 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR) {
2085 printk("Initiator");
2086 i++;
2087 }
2088
2089 if (ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_TARGET) {
2090 printk("%sTarget", i ? "," : "");
2091 i++;
2092 }
2093
2094 i = 0;
2095 printk("), ");
2096 printk("Capabilities=(");
2097
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05302098 if (!ioc->hide_ir_msg) {
2099 if (ioc->facts.IOCCapabilities &
2100 MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) {
2101 printk("Raid");
2102 i++;
2103 }
Eric Moore635374e2009-03-09 01:21:12 -06002104 }
2105
2106 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR) {
2107 printk("%sTLR", i ? "," : "");
2108 i++;
2109 }
2110
2111 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_MULTICAST) {
2112 printk("%sMulticast", i ? "," : "");
2113 i++;
2114 }
2115
2116 if (ioc->facts.IOCCapabilities &
2117 MPI2_IOCFACTS_CAPABILITY_BIDIRECTIONAL_TARGET) {
2118 printk("%sBIDI Target", i ? "," : "");
2119 i++;
2120 }
2121
2122 if (ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_EEDP) {
2123 printk("%sEEDP", i ? "," : "");
2124 i++;
2125 }
2126
2127 if (ioc->facts.IOCCapabilities &
2128 MPI2_IOCFACTS_CAPABILITY_SNAPSHOT_BUFFER) {
2129 printk("%sSnapshot Buffer", i ? "," : "");
2130 i++;
2131 }
2132
2133 if (ioc->facts.IOCCapabilities &
2134 MPI2_IOCFACTS_CAPABILITY_DIAG_TRACE_BUFFER) {
2135 printk("%sDiag Trace Buffer", i ? "," : "");
2136 i++;
2137 }
2138
2139 if (ioc->facts.IOCCapabilities &
Kashyap, Desai1b01fe32009-09-23 17:28:59 +05302140 MPI2_IOCFACTS_CAPABILITY_EXTENDED_BUFFER) {
2141 printk(KERN_INFO "%sDiag Extended Buffer", i ? "," : "");
2142 i++;
2143 }
2144
2145 if (ioc->facts.IOCCapabilities &
Eric Moore635374e2009-03-09 01:21:12 -06002146 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING) {
2147 printk("%sTask Set Full", i ? "," : "");
2148 i++;
2149 }
2150
2151 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2152 if (!(iounit_pg1_flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE)) {
2153 printk("%sNCQ", i ? "," : "");
2154 i++;
2155 }
2156
2157 printk(")\n");
2158}
2159
2160/**
Kashyap, Desai6cb8ef52010-11-13 04:32:18 +05302161 * _base_update_missing_delay - change the missing delay timers
2162 * @ioc: per adapter object
2163 * @device_missing_delay: amount of time till device is reported missing
2164 * @io_missing_delay: interval IO is returned when there is a missing device
2165 *
2166 * Return nothing.
2167 *
2168 * Passed on the command line, this function will modify the device missing
2169 * delay, as well as the io missing delay. This should be called at driver
2170 * load time.
2171 */
2172static void
2173_base_update_missing_delay(struct MPT2SAS_ADAPTER *ioc,
2174 u16 device_missing_delay, u8 io_missing_delay)
2175{
2176 u16 dmd, dmd_new, dmd_orignal;
2177 u8 io_missing_delay_original;
2178 u16 sz;
2179 Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
2180 Mpi2ConfigReply_t mpi_reply;
2181 u8 num_phys = 0;
2182 u16 ioc_status;
2183
2184 mpt2sas_config_get_number_hba_phys(ioc, &num_phys);
2185 if (!num_phys)
2186 return;
2187
2188 sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (num_phys *
2189 sizeof(Mpi2SasIOUnit1PhyData_t));
2190 sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
2191 if (!sas_iounit_pg1) {
2192 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2193 ioc->name, __FILE__, __LINE__, __func__);
2194 goto out;
2195 }
2196 if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
2197 sas_iounit_pg1, sz))) {
2198 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2199 ioc->name, __FILE__, __LINE__, __func__);
2200 goto out;
2201 }
2202 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
2203 MPI2_IOCSTATUS_MASK;
2204 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
2205 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
2206 ioc->name, __FILE__, __LINE__, __func__);
2207 goto out;
2208 }
2209
2210 /* device missing delay */
2211 dmd = sas_iounit_pg1->ReportDeviceMissingDelay;
2212 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2213 dmd = (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2214 else
2215 dmd = dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2216 dmd_orignal = dmd;
2217 if (device_missing_delay > 0x7F) {
2218 dmd = (device_missing_delay > 0x7F0) ? 0x7F0 :
2219 device_missing_delay;
2220 dmd = dmd / 16;
2221 dmd |= MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16;
2222 } else
2223 dmd = device_missing_delay;
2224 sas_iounit_pg1->ReportDeviceMissingDelay = dmd;
2225
2226 /* io missing delay */
2227 io_missing_delay_original = sas_iounit_pg1->IODeviceMissingDelay;
2228 sas_iounit_pg1->IODeviceMissingDelay = io_missing_delay;
2229
2230 if (!mpt2sas_config_set_sas_iounit_pg1(ioc, &mpi_reply, sas_iounit_pg1,
2231 sz)) {
2232 if (dmd & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
2233 dmd_new = (dmd &
2234 MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
2235 else
2236 dmd_new =
2237 dmd & MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
2238 printk(MPT2SAS_INFO_FMT "device_missing_delay: old(%d), "
2239 "new(%d)\n", ioc->name, dmd_orignal, dmd_new);
2240 printk(MPT2SAS_INFO_FMT "ioc_missing_delay: old(%d), "
2241 "new(%d)\n", ioc->name, io_missing_delay_original,
2242 io_missing_delay);
2243 ioc->device_missing_delay = dmd_new;
2244 ioc->io_missing_delay = io_missing_delay;
2245 }
2246
2247out:
2248 kfree(sas_iounit_pg1);
2249}
2250
2251/**
Eric Moore635374e2009-03-09 01:21:12 -06002252 * _base_static_config_pages - static start of day config pages
2253 * @ioc: per adapter object
2254 *
2255 * Return nothing.
2256 */
2257static void
2258_base_static_config_pages(struct MPT2SAS_ADAPTER *ioc)
2259{
2260 Mpi2ConfigReply_t mpi_reply;
2261 u32 iounit_pg1_flags;
2262
2263 mpt2sas_config_get_manufacturing_pg0(ioc, &mpi_reply, &ioc->manu_pg0);
Kashyap, Desaied79f122009-08-20 13:23:49 +05302264 if (ioc->ir_firmware)
2265 mpt2sas_config_get_manufacturing_pg10(ioc, &mpi_reply,
2266 &ioc->manu_pg10);
Eric Moore635374e2009-03-09 01:21:12 -06002267 mpt2sas_config_get_bios_pg2(ioc, &mpi_reply, &ioc->bios_pg2);
2268 mpt2sas_config_get_bios_pg3(ioc, &mpi_reply, &ioc->bios_pg3);
2269 mpt2sas_config_get_ioc_pg8(ioc, &mpi_reply, &ioc->ioc_pg8);
2270 mpt2sas_config_get_iounit_pg0(ioc, &mpi_reply, &ioc->iounit_pg0);
2271 mpt2sas_config_get_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
2272 _base_display_ioc_capabilities(ioc);
2273
2274 /*
2275 * Enable task_set_full handling in iounit_pg1 when the
2276 * facts capabilities indicate that its supported.
2277 */
2278 iounit_pg1_flags = le32_to_cpu(ioc->iounit_pg1.Flags);
2279 if ((ioc->facts.IOCCapabilities &
2280 MPI2_IOCFACTS_CAPABILITY_TASK_SET_FULL_HANDLING))
2281 iounit_pg1_flags &=
2282 ~MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2283 else
2284 iounit_pg1_flags |=
2285 MPI2_IOUNITPAGE1_DISABLE_TASK_SET_FULL_HANDLING;
2286 ioc->iounit_pg1.Flags = cpu_to_le32(iounit_pg1_flags);
Kashyap, Desai5b768582009-08-20 13:24:31 +05302287 mpt2sas_config_set_iounit_pg1(ioc, &mpi_reply, &ioc->iounit_pg1);
Kashyap, Desai6cb8ef52010-11-13 04:32:18 +05302288
Eric Moore635374e2009-03-09 01:21:12 -06002289}
2290
2291/**
2292 * _base_release_memory_pools - release memory
2293 * @ioc: per adapter object
2294 *
2295 * Free memory allocated from _base_allocate_memory_pools.
2296 *
2297 * Return nothing.
2298 */
2299static void
2300_base_release_memory_pools(struct MPT2SAS_ADAPTER *ioc)
2301{
Kashyap, Desai35f805b2010-11-13 04:34:06 +05302302 int i;
2303
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302304 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06002305 __func__));
2306
2307 if (ioc->request) {
2308 pci_free_consistent(ioc->pdev, ioc->request_dma_sz,
2309 ioc->request, ioc->request_dma);
2310 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "request_pool(0x%p)"
2311 ": free\n", ioc->name, ioc->request));
2312 ioc->request = NULL;
2313 }
2314
2315 if (ioc->sense) {
2316 pci_pool_free(ioc->sense_dma_pool, ioc->sense, ioc->sense_dma);
2317 if (ioc->sense_dma_pool)
2318 pci_pool_destroy(ioc->sense_dma_pool);
2319 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_pool(0x%p)"
2320 ": free\n", ioc->name, ioc->sense));
2321 ioc->sense = NULL;
2322 }
2323
2324 if (ioc->reply) {
2325 pci_pool_free(ioc->reply_dma_pool, ioc->reply, ioc->reply_dma);
2326 if (ioc->reply_dma_pool)
2327 pci_pool_destroy(ioc->reply_dma_pool);
2328 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_pool(0x%p)"
2329 ": free\n", ioc->name, ioc->reply));
2330 ioc->reply = NULL;
2331 }
2332
2333 if (ioc->reply_free) {
2334 pci_pool_free(ioc->reply_free_dma_pool, ioc->reply_free,
2335 ioc->reply_free_dma);
2336 if (ioc->reply_free_dma_pool)
2337 pci_pool_destroy(ioc->reply_free_dma_pool);
2338 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_pool"
2339 "(0x%p): free\n", ioc->name, ioc->reply_free));
2340 ioc->reply_free = NULL;
2341 }
2342
2343 if (ioc->reply_post_free) {
2344 pci_pool_free(ioc->reply_post_free_dma_pool,
2345 ioc->reply_post_free, ioc->reply_post_free_dma);
2346 if (ioc->reply_post_free_dma_pool)
2347 pci_pool_destroy(ioc->reply_post_free_dma_pool);
2348 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2349 "reply_post_free_pool(0x%p): free\n", ioc->name,
2350 ioc->reply_post_free));
2351 ioc->reply_post_free = NULL;
2352 }
2353
2354 if (ioc->config_page) {
2355 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT
2356 "config_page(0x%p): free\n", ioc->name,
2357 ioc->config_page));
2358 pci_free_consistent(ioc->pdev, ioc->config_page_sz,
2359 ioc->config_page, ioc->config_page_dma);
2360 }
2361
Kashyap, Desai66a67932010-04-05 14:21:07 +05302362 if (ioc->scsi_lookup) {
2363 free_pages((ulong)ioc->scsi_lookup, ioc->scsi_lookup_pages);
2364 ioc->scsi_lookup = NULL;
2365 }
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302366 kfree(ioc->hpr_lookup);
2367 kfree(ioc->internal_lookup);
Kashyap, Desai35f805b2010-11-13 04:34:06 +05302368 if (ioc->chain_lookup) {
2369 for (i = 0; i < ioc->chain_depth; i++) {
2370 if (ioc->chain_lookup[i].chain_buffer)
2371 pci_pool_free(ioc->chain_dma_pool,
2372 ioc->chain_lookup[i].chain_buffer,
2373 ioc->chain_lookup[i].chain_buffer_dma);
2374 }
2375 if (ioc->chain_dma_pool)
2376 pci_pool_destroy(ioc->chain_dma_pool);
2377 }
2378 if (ioc->chain_lookup) {
2379 free_pages((ulong)ioc->chain_lookup, ioc->chain_pages);
2380 ioc->chain_lookup = NULL;
2381 }
Eric Moore635374e2009-03-09 01:21:12 -06002382}
2383
2384
2385/**
2386 * _base_allocate_memory_pools - allocate start of day memory pools
2387 * @ioc: per adapter object
2388 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2389 *
2390 * Returns 0 success, anything else error
2391 */
2392static int
2393_base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
2394{
Kashyap, Desaic97951e2011-06-14 10:54:56 +05302395 struct mpt2sas_facts *facts;
Eric Moore635374e2009-03-09 01:21:12 -06002396 u32 queue_size, queue_diff;
2397 u16 max_sge_elements;
2398 u16 num_of_reply_frames;
2399 u16 chains_needed_per_io;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302400 u32 sz, total_sz, reply_post_free_sz;
Eric Moore635374e2009-03-09 01:21:12 -06002401 u32 retry_sz;
2402 u16 max_request_credit;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05302403 int i;
Eric Moore635374e2009-03-09 01:21:12 -06002404
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302405 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06002406 __func__));
2407
2408 retry_sz = 0;
2409 facts = &ioc->facts;
2410
2411 /* command line tunables for max sgl entries */
2412 if (max_sgl_entries != -1) {
2413 ioc->shost->sg_tablesize = (max_sgl_entries <
2414 MPT2SAS_SG_DEPTH) ? max_sgl_entries :
2415 MPT2SAS_SG_DEPTH;
2416 } else {
2417 ioc->shost->sg_tablesize = MPT2SAS_SG_DEPTH;
2418 }
2419
2420 /* command line tunables for max controller queue depth */
Kashyap, Desai35f805b2010-11-13 04:34:06 +05302421 if (max_queue_depth != -1)
Eric Moore635374e2009-03-09 01:21:12 -06002422 max_request_credit = (max_queue_depth < facts->RequestCredit)
2423 ? max_queue_depth : facts->RequestCredit;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05302424 else
2425 max_request_credit = facts->RequestCredit;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302426
2427 ioc->hba_queue_depth = max_request_credit;
2428 ioc->hi_priority_depth = facts->HighPriorityCredit;
2429 ioc->internal_depth = ioc->hi_priority_depth + 5;
Eric Moore635374e2009-03-09 01:21:12 -06002430
2431 /* request frame size */
2432 ioc->request_sz = facts->IOCRequestFrameSize * 4;
2433
2434 /* reply frame size */
2435 ioc->reply_sz = facts->ReplyFrameSize * 4;
2436
2437 retry_allocation:
2438 total_sz = 0;
2439 /* calculate number of sg elements left over in the 1st frame */
2440 max_sge_elements = ioc->request_sz - ((sizeof(Mpi2SCSIIORequest_t) -
2441 sizeof(Mpi2SGEIOUnion_t)) + ioc->sge_size);
2442 ioc->max_sges_in_main_message = max_sge_elements/ioc->sge_size;
2443
2444 /* now do the same for a chain buffer */
2445 max_sge_elements = ioc->request_sz - ioc->sge_size;
2446 ioc->max_sges_in_chain_message = max_sge_elements/ioc->sge_size;
2447
2448 ioc->chain_offset_value_for_main_message =
2449 ((sizeof(Mpi2SCSIIORequest_t) - sizeof(Mpi2SGEIOUnion_t)) +
2450 (ioc->max_sges_in_chain_message * ioc->sge_size)) / 4;
2451
2452 /*
2453 * MPT2SAS_SG_DEPTH = CONFIG_FUSION_MAX_SGE
2454 */
2455 chains_needed_per_io = ((ioc->shost->sg_tablesize -
2456 ioc->max_sges_in_main_message)/ioc->max_sges_in_chain_message)
2457 + 1;
2458 if (chains_needed_per_io > facts->MaxChainDepth) {
2459 chains_needed_per_io = facts->MaxChainDepth;
2460 ioc->shost->sg_tablesize = min_t(u16,
2461 ioc->max_sges_in_main_message + (ioc->max_sges_in_chain_message
2462 * chains_needed_per_io), ioc->shost->sg_tablesize);
2463 }
2464 ioc->chains_needed_per_io = chains_needed_per_io;
2465
2466 /* reply free queue sizing - taking into account for events */
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302467 num_of_reply_frames = ioc->hba_queue_depth + 32;
Eric Moore635374e2009-03-09 01:21:12 -06002468
2469 /* number of replies frames can't be a multiple of 16 */
2470 /* decrease number of reply frames by 1 */
2471 if (!(num_of_reply_frames % 16))
2472 num_of_reply_frames--;
2473
2474 /* calculate number of reply free queue entries
2475 * (must be multiple of 16)
2476 */
2477
2478 /* (we know reply_free_queue_depth is not a multiple of 16) */
2479 queue_size = num_of_reply_frames;
2480 queue_size += 16 - (queue_size % 16);
2481 ioc->reply_free_queue_depth = queue_size;
2482
2483 /* reply descriptor post queue sizing */
2484 /* this size should be the number of request frames + number of reply
2485 * frames
2486 */
2487
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302488 queue_size = ioc->hba_queue_depth + num_of_reply_frames + 1;
Eric Moore635374e2009-03-09 01:21:12 -06002489 /* round up to 16 byte boundary */
2490 if (queue_size % 16)
2491 queue_size += 16 - (queue_size % 16);
2492
2493 /* check against IOC maximum reply post queue depth */
2494 if (queue_size > facts->MaxReplyDescriptorPostQueueDepth) {
2495 queue_diff = queue_size -
2496 facts->MaxReplyDescriptorPostQueueDepth;
2497
2498 /* round queue_diff up to multiple of 16 */
2499 if (queue_diff % 16)
2500 queue_diff += 16 - (queue_diff % 16);
2501
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302502 /* adjust hba_queue_depth, reply_free_queue_depth,
Eric Moore635374e2009-03-09 01:21:12 -06002503 * and queue_size
2504 */
Kashyap, Desai11e1b962011-01-04 11:34:57 +05302505 ioc->hba_queue_depth -= (queue_diff / 2);
2506 ioc->reply_free_queue_depth -= (queue_diff / 2);
2507 queue_size = facts->MaxReplyDescriptorPostQueueDepth;
Eric Moore635374e2009-03-09 01:21:12 -06002508 }
2509 ioc->reply_post_queue_depth = queue_size;
2510
Eric Moore635374e2009-03-09 01:21:12 -06002511 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scatter gather: "
2512 "sge_in_main_msg(%d), sge_per_chain(%d), sge_per_io(%d), "
2513 "chains_per_io(%d)\n", ioc->name, ioc->max_sges_in_main_message,
2514 ioc->max_sges_in_chain_message, ioc->shost->sg_tablesize,
2515 ioc->chains_needed_per_io));
2516
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302517 ioc->scsiio_depth = ioc->hba_queue_depth -
2518 ioc->hi_priority_depth - ioc->internal_depth;
2519
2520 /* set the scsi host can_queue depth
2521 * with some internal commands that could be outstanding
2522 */
2523 ioc->shost->can_queue = ioc->scsiio_depth - (2);
2524 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsi host: "
2525 "can_queue depth (%d)\n", ioc->name, ioc->shost->can_queue));
2526
Eric Moore635374e2009-03-09 01:21:12 -06002527 /* contiguous pool for request and chains, 16 byte align, one extra "
2528 * "frame for smid=0
2529 */
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302530 ioc->chain_depth = ioc->chains_needed_per_io * ioc->scsiio_depth;
Kashyap, Desai35f805b2010-11-13 04:34:06 +05302531 sz = ((ioc->scsiio_depth + 1) * ioc->request_sz);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302532
2533 /* hi-priority queue */
2534 sz += (ioc->hi_priority_depth * ioc->request_sz);
2535
2536 /* internal queue */
2537 sz += (ioc->internal_depth * ioc->request_sz);
Eric Moore635374e2009-03-09 01:21:12 -06002538
2539 ioc->request_dma_sz = sz;
2540 ioc->request = pci_alloc_consistent(ioc->pdev, sz, &ioc->request_dma);
2541 if (!ioc->request) {
2542 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302543 "failed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2544 "total(%d kB)\n", ioc->name, ioc->hba_queue_depth,
Eric Moore635374e2009-03-09 01:21:12 -06002545 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302546 if (ioc->scsiio_depth < MPT2SAS_SAS_QUEUE_DEPTH)
Eric Moore635374e2009-03-09 01:21:12 -06002547 goto out;
2548 retry_sz += 64;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302549 ioc->hba_queue_depth = max_request_credit - retry_sz;
Eric Moore635374e2009-03-09 01:21:12 -06002550 goto retry_allocation;
2551 }
2552
2553 if (retry_sz)
2554 printk(MPT2SAS_ERR_FMT "request pool: pci_alloc_consistent "
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302555 "succeed: hba_depth(%d), chains_per_io(%d), frame_sz(%d), "
2556 "total(%d kb)\n", ioc->name, ioc->hba_queue_depth,
Eric Moore635374e2009-03-09 01:21:12 -06002557 ioc->chains_needed_per_io, ioc->request_sz, sz/1024);
2558
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302559
2560 /* hi-priority queue */
2561 ioc->hi_priority = ioc->request + ((ioc->scsiio_depth + 1) *
Eric Moore635374e2009-03-09 01:21:12 -06002562 ioc->request_sz);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302563 ioc->hi_priority_dma = ioc->request_dma + ((ioc->scsiio_depth + 1) *
Eric Moore635374e2009-03-09 01:21:12 -06002564 ioc->request_sz);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302565
2566 /* internal queue */
2567 ioc->internal = ioc->hi_priority + (ioc->hi_priority_depth *
2568 ioc->request_sz);
2569 ioc->internal_dma = ioc->hi_priority_dma + (ioc->hi_priority_depth *
2570 ioc->request_sz);
2571
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302572
Eric Moore635374e2009-03-09 01:21:12 -06002573 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool(0x%p): "
2574 "depth(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302575 ioc->request, ioc->hba_queue_depth, ioc->request_sz,
2576 (ioc->hba_queue_depth * ioc->request_sz)/1024));
Eric Moore635374e2009-03-09 01:21:12 -06002577 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request pool: dma(0x%llx)\n",
2578 ioc->name, (unsigned long long) ioc->request_dma));
2579 total_sz += sz;
2580
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05302581 sz = ioc->scsiio_depth * sizeof(struct scsiio_tracker);
Kashyap, Desai89009fb2010-03-17 16:22:52 +05302582 ioc->scsi_lookup_pages = get_order(sz);
Kashyap, Desaid5bd3491c2011-01-04 11:39:20 +05302583 ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages(
Kashyap, Desai89009fb2010-03-17 16:22:52 +05302584 GFP_KERNEL, ioc->scsi_lookup_pages);
Eric Moore635374e2009-03-09 01:21:12 -06002585 if (!ioc->scsi_lookup) {
Kashyap, Desai89009fb2010-03-17 16:22:52 +05302586 printk(MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, "
2587 "sz(%d)\n", ioc->name, (int)sz);
Eric Moore635374e2009-03-09 01:21:12 -06002588 goto out;
2589 }
2590
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302591 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
2592 "depth(%d)\n", ioc->name, ioc->request,
2593 ioc->scsiio_depth));
2594
Kashyap, Desai35f805b2010-11-13 04:34:06 +05302595 /* loop till the allocation succeeds */
2596 do {
2597 sz = ioc->chain_depth * sizeof(struct chain_tracker);
2598 ioc->chain_pages = get_order(sz);
2599 ioc->chain_lookup = (struct chain_tracker *)__get_free_pages(
2600 GFP_KERNEL, ioc->chain_pages);
2601 if (ioc->chain_lookup == NULL)
2602 ioc->chain_depth -= 100;
2603 } while (ioc->chain_lookup == NULL);
2604 ioc->chain_dma_pool = pci_pool_create("chain pool", ioc->pdev,
2605 ioc->request_sz, 16, 0);
2606 if (!ioc->chain_dma_pool) {
2607 printk(MPT2SAS_ERR_FMT "chain_dma_pool: pci_pool_create "
2608 "failed\n", ioc->name);
2609 goto out;
2610 }
2611 for (i = 0; i < ioc->chain_depth; i++) {
2612 ioc->chain_lookup[i].chain_buffer = pci_pool_alloc(
2613 ioc->chain_dma_pool , GFP_KERNEL,
2614 &ioc->chain_lookup[i].chain_buffer_dma);
2615 if (!ioc->chain_lookup[i].chain_buffer) {
2616 ioc->chain_depth = i;
2617 goto chain_done;
2618 }
2619 total_sz += ioc->request_sz;
2620 }
2621chain_done:
2622 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "chain pool depth"
2623 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name,
2624 ioc->chain_depth, ioc->request_sz, ((ioc->chain_depth *
2625 ioc->request_sz))/1024));
2626
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302627 /* initialize hi-priority queue smid's */
2628 ioc->hpr_lookup = kcalloc(ioc->hi_priority_depth,
2629 sizeof(struct request_tracker), GFP_KERNEL);
2630 if (!ioc->hpr_lookup) {
2631 printk(MPT2SAS_ERR_FMT "hpr_lookup: kcalloc failed\n",
2632 ioc->name);
2633 goto out;
2634 }
2635 ioc->hi_priority_smid = ioc->scsiio_depth + 1;
2636 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hi_priority(0x%p): "
2637 "depth(%d), start smid(%d)\n", ioc->name, ioc->hi_priority,
2638 ioc->hi_priority_depth, ioc->hi_priority_smid));
2639
2640 /* initialize internal queue smid's */
2641 ioc->internal_lookup = kcalloc(ioc->internal_depth,
2642 sizeof(struct request_tracker), GFP_KERNEL);
2643 if (!ioc->internal_lookup) {
2644 printk(MPT2SAS_ERR_FMT "internal_lookup: kcalloc failed\n",
2645 ioc->name);
2646 goto out;
2647 }
2648 ioc->internal_smid = ioc->hi_priority_smid + ioc->hi_priority_depth;
2649 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "internal(0x%p): "
2650 "depth(%d), start smid(%d)\n", ioc->name, ioc->internal,
2651 ioc->internal_depth, ioc->internal_smid));
Eric Moore635374e2009-03-09 01:21:12 -06002652
2653 /* sense buffers, 4 byte align */
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302654 sz = ioc->scsiio_depth * SCSI_SENSE_BUFFERSIZE;
Eric Moore635374e2009-03-09 01:21:12 -06002655 ioc->sense_dma_pool = pci_pool_create("sense pool", ioc->pdev, sz, 4,
2656 0);
2657 if (!ioc->sense_dma_pool) {
2658 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_create failed\n",
2659 ioc->name);
2660 goto out;
2661 }
2662 ioc->sense = pci_pool_alloc(ioc->sense_dma_pool , GFP_KERNEL,
2663 &ioc->sense_dma);
2664 if (!ioc->sense) {
2665 printk(MPT2SAS_ERR_FMT "sense pool: pci_pool_alloc failed\n",
2666 ioc->name);
2667 goto out;
2668 }
2669 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
2670 "sense pool(0x%p): depth(%d), element_size(%d), pool_size"
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05302671 "(%d kB)\n", ioc->name, ioc->sense, ioc->scsiio_depth,
Eric Moore635374e2009-03-09 01:21:12 -06002672 SCSI_SENSE_BUFFERSIZE, sz/1024));
2673 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "sense_dma(0x%llx)\n",
2674 ioc->name, (unsigned long long)ioc->sense_dma));
2675 total_sz += sz;
2676
2677 /* reply pool, 4 byte align */
2678 sz = ioc->reply_free_queue_depth * ioc->reply_sz;
2679 ioc->reply_dma_pool = pci_pool_create("reply pool", ioc->pdev, sz, 4,
2680 0);
2681 if (!ioc->reply_dma_pool) {
2682 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_create failed\n",
2683 ioc->name);
2684 goto out;
2685 }
2686 ioc->reply = pci_pool_alloc(ioc->reply_dma_pool , GFP_KERNEL,
2687 &ioc->reply_dma);
2688 if (!ioc->reply) {
2689 printk(MPT2SAS_ERR_FMT "reply pool: pci_pool_alloc failed\n",
2690 ioc->name);
2691 goto out;
2692 }
Kashyap, Desaidd3741d2010-11-13 04:31:14 +05302693 ioc->reply_dma_min_address = (u32)(ioc->reply_dma);
2694 ioc->reply_dma_max_address = (u32)(ioc->reply_dma) + sz;
Eric Moore635374e2009-03-09 01:21:12 -06002695 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply pool(0x%p): depth"
2696 "(%d), frame_size(%d), pool_size(%d kB)\n", ioc->name, ioc->reply,
2697 ioc->reply_free_queue_depth, ioc->reply_sz, sz/1024));
2698 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_dma(0x%llx)\n",
2699 ioc->name, (unsigned long long)ioc->reply_dma));
2700 total_sz += sz;
2701
2702 /* reply free queue, 16 byte align */
2703 sz = ioc->reply_free_queue_depth * 4;
2704 ioc->reply_free_dma_pool = pci_pool_create("reply_free pool",
2705 ioc->pdev, sz, 16, 0);
2706 if (!ioc->reply_free_dma_pool) {
2707 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_create "
2708 "failed\n", ioc->name);
2709 goto out;
2710 }
2711 ioc->reply_free = pci_pool_alloc(ioc->reply_free_dma_pool , GFP_KERNEL,
2712 &ioc->reply_free_dma);
2713 if (!ioc->reply_free) {
2714 printk(MPT2SAS_ERR_FMT "reply_free pool: pci_pool_alloc "
2715 "failed\n", ioc->name);
2716 goto out;
2717 }
2718 memset(ioc->reply_free, 0, sz);
2719 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free pool(0x%p): "
2720 "depth(%d), element_size(%d), pool_size(%d kB)\n", ioc->name,
2721 ioc->reply_free, ioc->reply_free_queue_depth, 4, sz/1024));
2722 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_free_dma"
2723 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->reply_free_dma));
2724 total_sz += sz;
2725
2726 /* reply post queue, 16 byte align */
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05302727 reply_post_free_sz = ioc->reply_post_queue_depth *
2728 sizeof(Mpi2DefaultReplyDescriptor_t);
2729 if (_base_is_controller_msix_enabled(ioc))
2730 sz = reply_post_free_sz * ioc->reply_queue_count;
2731 else
2732 sz = reply_post_free_sz;
Eric Moore635374e2009-03-09 01:21:12 -06002733 ioc->reply_post_free_dma_pool = pci_pool_create("reply_post_free pool",
2734 ioc->pdev, sz, 16, 0);
2735 if (!ioc->reply_post_free_dma_pool) {
2736 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_create "
2737 "failed\n", ioc->name);
2738 goto out;
2739 }
2740 ioc->reply_post_free = pci_pool_alloc(ioc->reply_post_free_dma_pool ,
2741 GFP_KERNEL, &ioc->reply_post_free_dma);
2742 if (!ioc->reply_post_free) {
2743 printk(MPT2SAS_ERR_FMT "reply_post_free pool: pci_pool_alloc "
2744 "failed\n", ioc->name);
2745 goto out;
2746 }
2747 memset(ioc->reply_post_free, 0, sz);
2748 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply post free pool"
2749 "(0x%p): depth(%d), element_size(%d), pool_size(%d kB)\n",
2750 ioc->name, ioc->reply_post_free, ioc->reply_post_queue_depth, 8,
2751 sz/1024));
2752 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "reply_post_free_dma = "
2753 "(0x%llx)\n", ioc->name, (unsigned long long)
2754 ioc->reply_post_free_dma));
2755 total_sz += sz;
2756
2757 ioc->config_page_sz = 512;
2758 ioc->config_page = pci_alloc_consistent(ioc->pdev,
2759 ioc->config_page_sz, &ioc->config_page_dma);
2760 if (!ioc->config_page) {
2761 printk(MPT2SAS_ERR_FMT "config page: pci_pool_alloc "
2762 "failed\n", ioc->name);
2763 goto out;
2764 }
2765 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config page(0x%p): size"
2766 "(%d)\n", ioc->name, ioc->config_page, ioc->config_page_sz));
2767 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "config_page_dma"
2768 "(0x%llx)\n", ioc->name, (unsigned long long)ioc->config_page_dma));
2769 total_sz += ioc->config_page_sz;
2770
2771 printk(MPT2SAS_INFO_FMT "Allocated physical memory: size(%d kB)\n",
2772 ioc->name, total_sz/1024);
2773 printk(MPT2SAS_INFO_FMT "Current Controller Queue Depth(%d), "
2774 "Max Controller Queue Depth(%d)\n",
2775 ioc->name, ioc->shost->can_queue, facts->RequestCredit);
2776 printk(MPT2SAS_INFO_FMT "Scatter Gather Elements per IO(%d)\n",
2777 ioc->name, ioc->shost->sg_tablesize);
2778 return 0;
2779
2780 out:
Eric Moore635374e2009-03-09 01:21:12 -06002781 return -ENOMEM;
2782}
2783
2784
2785/**
2786 * mpt2sas_base_get_iocstate - Get the current state of a MPT adapter.
2787 * @ioc: Pointer to MPT_ADAPTER structure
2788 * @cooked: Request raw or cooked IOC state
2789 *
2790 * Returns all IOC Doorbell register bits if cooked==0, else just the
2791 * Doorbell bits in MPI_IOC_STATE_MASK.
2792 */
2793u32
2794mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked)
2795{
2796 u32 s, sc;
2797
2798 s = readl(&ioc->chip->Doorbell);
2799 sc = s & MPI2_IOC_STATE_MASK;
2800 return cooked ? sc : s;
2801}
2802
2803/**
2804 * _base_wait_on_iocstate - waiting on a particular ioc state
2805 * @ioc_state: controller state { READY, OPERATIONAL, or RESET }
2806 * @timeout: timeout in second
2807 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2808 *
2809 * Returns 0 for success, non-zero for failure.
2810 */
2811static int
2812_base_wait_on_iocstate(struct MPT2SAS_ADAPTER *ioc, u32 ioc_state, int timeout,
2813 int sleep_flag)
2814{
2815 u32 count, cntdn;
2816 u32 current_state;
2817
2818 count = 0;
2819 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2820 do {
2821 current_state = mpt2sas_base_get_iocstate(ioc, 1);
2822 if (current_state == ioc_state)
2823 return 0;
2824 if (count && current_state == MPI2_IOC_STATE_FAULT)
2825 break;
2826 if (sleep_flag == CAN_SLEEP)
2827 msleep(1);
2828 else
2829 udelay(500);
2830 count++;
2831 } while (--cntdn);
2832
2833 return current_state;
2834}
2835
2836/**
2837 * _base_wait_for_doorbell_int - waiting for controller interrupt(generated by
2838 * a write to the doorbell)
2839 * @ioc: per adapter object
2840 * @timeout: timeout in second
2841 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2842 *
2843 * Returns 0 for success, non-zero for failure.
2844 *
2845 * Notes: MPI2_HIS_IOC2SYS_DB_STATUS - set to one when IOC writes to doorbell.
2846 */
2847static int
2848_base_wait_for_doorbell_int(struct MPT2SAS_ADAPTER *ioc, int timeout,
2849 int sleep_flag)
2850{
2851 u32 cntdn, count;
2852 u32 int_status;
2853
2854 count = 0;
2855 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2856 do {
2857 int_status = readl(&ioc->chip->HostInterruptStatus);
2858 if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302859 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002860 "successful count(%d), timeout(%d)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06002861 __func__, count, timeout));
2862 return 0;
2863 }
2864 if (sleep_flag == CAN_SLEEP)
2865 msleep(1);
2866 else
2867 udelay(500);
2868 count++;
2869 } while (--cntdn);
2870
2871 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2872 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2873 return -EFAULT;
2874}
2875
2876/**
2877 * _base_wait_for_doorbell_ack - waiting for controller to read the doorbell.
2878 * @ioc: per adapter object
2879 * @timeout: timeout in second
2880 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2881 *
2882 * Returns 0 for success, non-zero for failure.
2883 *
2884 * Notes: MPI2_HIS_SYS2IOC_DB_STATUS - set to one when host writes to
2885 * doorbell.
2886 */
2887static int
2888_base_wait_for_doorbell_ack(struct MPT2SAS_ADAPTER *ioc, int timeout,
2889 int sleep_flag)
2890{
2891 u32 cntdn, count;
2892 u32 int_status;
2893 u32 doorbell;
2894
2895 count = 0;
2896 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2897 do {
2898 int_status = readl(&ioc->chip->HostInterruptStatus);
2899 if (!(int_status & MPI2_HIS_SYS2IOC_DB_STATUS)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302900 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002901 "successful count(%d), timeout(%d)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06002902 __func__, count, timeout));
2903 return 0;
2904 } else if (int_status & MPI2_HIS_IOC2SYS_DB_STATUS) {
2905 doorbell = readl(&ioc->chip->Doorbell);
2906 if ((doorbell & MPI2_IOC_STATE_MASK) ==
2907 MPI2_IOC_STATE_FAULT) {
2908 mpt2sas_base_fault_info(ioc , doorbell);
2909 return -EFAULT;
2910 }
2911 } else if (int_status == 0xFFFFFFFF)
2912 goto out;
2913
2914 if (sleep_flag == CAN_SLEEP)
2915 msleep(1);
2916 else
2917 udelay(500);
2918 count++;
2919 } while (--cntdn);
2920
2921 out:
2922 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2923 "int_status(%x)!\n", ioc->name, __func__, count, int_status);
2924 return -EFAULT;
2925}
2926
2927/**
2928 * _base_wait_for_doorbell_not_used - waiting for doorbell to not be in use
2929 * @ioc: per adapter object
2930 * @timeout: timeout in second
2931 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2932 *
2933 * Returns 0 for success, non-zero for failure.
2934 *
2935 */
2936static int
2937_base_wait_for_doorbell_not_used(struct MPT2SAS_ADAPTER *ioc, int timeout,
2938 int sleep_flag)
2939{
2940 u32 cntdn, count;
2941 u32 doorbell_reg;
2942
2943 count = 0;
2944 cntdn = (sleep_flag == CAN_SLEEP) ? 1000*timeout : 2000*timeout;
2945 do {
2946 doorbell_reg = readl(&ioc->chip->Doorbell);
2947 if (!(doorbell_reg & MPI2_DOORBELL_USED)) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05302948 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002949 "successful count(%d), timeout(%d)\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06002950 __func__, count, timeout));
2951 return 0;
2952 }
2953 if (sleep_flag == CAN_SLEEP)
2954 msleep(1);
2955 else
2956 udelay(500);
2957 count++;
2958 } while (--cntdn);
2959
2960 printk(MPT2SAS_ERR_FMT "%s: failed due to timeout count(%d), "
2961 "doorbell_reg(%x)!\n", ioc->name, __func__, count, doorbell_reg);
2962 return -EFAULT;
2963}
2964
2965/**
2966 * _base_send_ioc_reset - send doorbell reset
2967 * @ioc: per adapter object
2968 * @reset_type: currently only supports: MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET
2969 * @timeout: timeout in second
2970 * @sleep_flag: CAN_SLEEP or NO_SLEEP
2971 *
2972 * Returns 0 for success, non-zero for failure.
2973 */
2974static int
2975_base_send_ioc_reset(struct MPT2SAS_ADAPTER *ioc, u8 reset_type, int timeout,
2976 int sleep_flag)
2977{
2978 u32 ioc_state;
2979 int r = 0;
2980
2981 if (reset_type != MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET) {
2982 printk(MPT2SAS_ERR_FMT "%s: unknown reset_type\n",
2983 ioc->name, __func__);
2984 return -EFAULT;
2985 }
2986
2987 if (!(ioc->facts.IOCCapabilities &
2988 MPI2_IOCFACTS_CAPABILITY_EVENT_REPLAY))
2989 return -EFAULT;
2990
2991 printk(MPT2SAS_INFO_FMT "sending message unit reset !!\n", ioc->name);
2992
2993 writel(reset_type << MPI2_DOORBELL_FUNCTION_SHIFT,
2994 &ioc->chip->Doorbell);
2995 if ((_base_wait_for_doorbell_ack(ioc, 15, sleep_flag))) {
2996 r = -EFAULT;
2997 goto out;
2998 }
2999 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY,
3000 timeout, sleep_flag);
3001 if (ioc_state) {
3002 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3003 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3004 r = -EFAULT;
3005 goto out;
3006 }
3007 out:
3008 printk(MPT2SAS_INFO_FMT "message unit reset: %s\n",
3009 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED"));
3010 return r;
3011}
3012
3013/**
3014 * _base_handshake_req_reply_wait - send request thru doorbell interface
3015 * @ioc: per adapter object
3016 * @request_bytes: request length
3017 * @request: pointer having request payload
3018 * @reply_bytes: reply length
3019 * @reply: pointer to reply payload
3020 * @timeout: timeout in second
3021 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3022 *
3023 * Returns 0 for success, non-zero for failure.
3024 */
3025static int
3026_base_handshake_req_reply_wait(struct MPT2SAS_ADAPTER *ioc, int request_bytes,
3027 u32 *request, int reply_bytes, u16 *reply, int timeout, int sleep_flag)
3028{
3029 MPI2DefaultReply_t *default_reply = (MPI2DefaultReply_t *)reply;
3030 int i;
3031 u8 failed;
3032 u16 dummy;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303033 __le32 *mfp;
Eric Moore635374e2009-03-09 01:21:12 -06003034
3035 /* make sure doorbell is not in use */
3036 if ((readl(&ioc->chip->Doorbell) & MPI2_DOORBELL_USED)) {
3037 printk(MPT2SAS_ERR_FMT "doorbell is in use "
3038 " (line=%d)\n", ioc->name, __LINE__);
3039 return -EFAULT;
3040 }
3041
3042 /* clear pending doorbell interrupts from previous state changes */
3043 if (readl(&ioc->chip->HostInterruptStatus) &
3044 MPI2_HIS_IOC2SYS_DB_STATUS)
3045 writel(0, &ioc->chip->HostInterruptStatus);
3046
3047 /* send message to ioc */
3048 writel(((MPI2_FUNCTION_HANDSHAKE<<MPI2_DOORBELL_FUNCTION_SHIFT) |
3049 ((request_bytes/4)<<MPI2_DOORBELL_ADD_DWORDS_SHIFT)),
3050 &ioc->chip->Doorbell);
3051
Kashyap, Desai29786e12009-09-14 11:06:21 +05303052 if ((_base_wait_for_doorbell_int(ioc, 5, NO_SLEEP))) {
Eric Moore635374e2009-03-09 01:21:12 -06003053 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3054 "int failed (line=%d)\n", ioc->name, __LINE__);
3055 return -EFAULT;
3056 }
3057 writel(0, &ioc->chip->HostInterruptStatus);
3058
3059 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag))) {
3060 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3061 "ack failed (line=%d)\n", ioc->name, __LINE__);
3062 return -EFAULT;
3063 }
3064
3065 /* send message 32-bits at a time */
3066 for (i = 0, failed = 0; i < request_bytes/4 && !failed; i++) {
3067 writel(cpu_to_le32(request[i]), &ioc->chip->Doorbell);
3068 if ((_base_wait_for_doorbell_ack(ioc, 5, sleep_flag)))
3069 failed = 1;
3070 }
3071
3072 if (failed) {
3073 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3074 "sending request failed (line=%d)\n", ioc->name, __LINE__);
3075 return -EFAULT;
3076 }
3077
3078 /* now wait for the reply */
3079 if ((_base_wait_for_doorbell_int(ioc, timeout, sleep_flag))) {
3080 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3081 "int failed (line=%d)\n", ioc->name, __LINE__);
3082 return -EFAULT;
3083 }
3084
3085 /* read the first two 16-bits, it gives the total length of the reply */
3086 reply[0] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3087 & MPI2_DOORBELL_DATA_MASK);
3088 writel(0, &ioc->chip->HostInterruptStatus);
3089 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3090 printk(MPT2SAS_ERR_FMT "doorbell handshake "
3091 "int failed (line=%d)\n", ioc->name, __LINE__);
3092 return -EFAULT;
3093 }
3094 reply[1] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3095 & MPI2_DOORBELL_DATA_MASK);
3096 writel(0, &ioc->chip->HostInterruptStatus);
3097
3098 for (i = 2; i < default_reply->MsgLength * 2; i++) {
3099 if ((_base_wait_for_doorbell_int(ioc, 5, sleep_flag))) {
3100 printk(MPT2SAS_ERR_FMT "doorbell "
3101 "handshake int failed (line=%d)\n", ioc->name,
3102 __LINE__);
3103 return -EFAULT;
3104 }
3105 if (i >= reply_bytes/2) /* overflow case */
3106 dummy = readl(&ioc->chip->Doorbell);
3107 else
3108 reply[i] = le16_to_cpu(readl(&ioc->chip->Doorbell)
3109 & MPI2_DOORBELL_DATA_MASK);
3110 writel(0, &ioc->chip->HostInterruptStatus);
3111 }
3112
3113 _base_wait_for_doorbell_int(ioc, 5, sleep_flag);
3114 if (_base_wait_for_doorbell_not_used(ioc, 5, sleep_flag) != 0) {
3115 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "doorbell is in use "
3116 " (line=%d)\n", ioc->name, __LINE__));
3117 }
3118 writel(0, &ioc->chip->HostInterruptStatus);
3119
3120 if (ioc->logging_level & MPT_DEBUG_INIT) {
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303121 mfp = (__le32 *)reply;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303122 printk(KERN_INFO "\toffset:data\n");
Eric Moore635374e2009-03-09 01:21:12 -06003123 for (i = 0; i < reply_bytes/4; i++)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303124 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
Eric Moore635374e2009-03-09 01:21:12 -06003125 le32_to_cpu(mfp[i]));
3126 }
3127 return 0;
3128}
3129
3130/**
3131 * mpt2sas_base_sas_iounit_control - send sas iounit control to FW
3132 * @ioc: per adapter object
3133 * @mpi_reply: the reply payload from FW
3134 * @mpi_request: the request payload sent to FW
3135 *
3136 * The SAS IO Unit Control Request message allows the host to perform low-level
3137 * operations, such as resets on the PHYs of the IO Unit, also allows the host
3138 * to obtain the IOC assigned device handles for a device if it has other
3139 * identifying information about the device, in addition allows the host to
3140 * remove IOC resources associated with the device.
3141 *
3142 * Returns 0 for success, non-zero for failure.
3143 */
3144int
3145mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
3146 Mpi2SasIoUnitControlReply_t *mpi_reply,
3147 Mpi2SasIoUnitControlRequest_t *mpi_request)
3148{
3149 u16 smid;
3150 u32 ioc_state;
3151 unsigned long timeleft;
3152 u8 issue_reset;
3153 int rc;
3154 void *request;
3155 u16 wait_state_count;
3156
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303157 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06003158 __func__));
3159
3160 mutex_lock(&ioc->base_cmds.mutex);
3161
3162 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3163 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3164 ioc->name, __func__);
3165 rc = -EAGAIN;
3166 goto out;
3167 }
3168
3169 wait_state_count = 0;
3170 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3171 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3172 if (wait_state_count++ == 10) {
3173 printk(MPT2SAS_ERR_FMT
3174 "%s: failed due to ioc not operational\n",
3175 ioc->name, __func__);
3176 rc = -EFAULT;
3177 goto out;
3178 }
3179 ssleep(1);
3180 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3181 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3182 "operational state(count=%d)\n", ioc->name,
3183 __func__, wait_state_count);
3184 }
3185
3186 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3187 if (!smid) {
3188 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3189 ioc->name, __func__);
3190 rc = -EAGAIN;
3191 goto out;
3192 }
3193
3194 rc = 0;
3195 ioc->base_cmds.status = MPT2_CMD_PENDING;
3196 request = mpt2sas_base_get_msg_frame(ioc, smid);
3197 ioc->base_cmds.smid = smid;
3198 memcpy(request, mpi_request, sizeof(Mpi2SasIoUnitControlRequest_t));
3199 if (mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3200 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET)
3201 ioc->ioc_link_reset_in_progress = 1;
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05303202 init_completion(&ioc->base_cmds.done);
nagalakshmi.nandigama@lsi.comf01690d2011-12-01 07:43:58 +05303203 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003204 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3205 msecs_to_jiffies(10000));
3206 if ((mpi_request->Operation == MPI2_SAS_OP_PHY_HARD_RESET ||
3207 mpi_request->Operation == MPI2_SAS_OP_PHY_LINK_RESET) &&
3208 ioc->ioc_link_reset_in_progress)
3209 ioc->ioc_link_reset_in_progress = 0;
3210 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3211 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3212 ioc->name, __func__);
3213 _debug_dump_mf(mpi_request,
3214 sizeof(Mpi2SasIoUnitControlRequest_t)/4);
3215 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3216 issue_reset = 1;
3217 goto issue_host_reset;
3218 }
3219 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3220 memcpy(mpi_reply, ioc->base_cmds.reply,
3221 sizeof(Mpi2SasIoUnitControlReply_t));
3222 else
3223 memset(mpi_reply, 0, sizeof(Mpi2SasIoUnitControlReply_t));
3224 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3225 goto out;
3226
3227 issue_host_reset:
3228 if (issue_reset)
3229 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3230 FORCE_BIG_HAMMER);
3231 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3232 rc = -EFAULT;
3233 out:
3234 mutex_unlock(&ioc->base_cmds.mutex);
3235 return rc;
3236}
3237
3238
3239/**
3240 * mpt2sas_base_scsi_enclosure_processor - sending request to sep device
3241 * @ioc: per adapter object
3242 * @mpi_reply: the reply payload from FW
3243 * @mpi_request: the request payload sent to FW
3244 *
3245 * The SCSI Enclosure Processor request message causes the IOC to
3246 * communicate with SES devices to control LED status signals.
3247 *
3248 * Returns 0 for success, non-zero for failure.
3249 */
3250int
3251mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
3252 Mpi2SepReply_t *mpi_reply, Mpi2SepRequest_t *mpi_request)
3253{
3254 u16 smid;
3255 u32 ioc_state;
3256 unsigned long timeleft;
3257 u8 issue_reset;
3258 int rc;
3259 void *request;
3260 u16 wait_state_count;
3261
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303262 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06003263 __func__));
3264
3265 mutex_lock(&ioc->base_cmds.mutex);
3266
3267 if (ioc->base_cmds.status != MPT2_CMD_NOT_USED) {
3268 printk(MPT2SAS_ERR_FMT "%s: base_cmd in use\n",
3269 ioc->name, __func__);
3270 rc = -EAGAIN;
3271 goto out;
3272 }
3273
3274 wait_state_count = 0;
3275 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3276 while (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3277 if (wait_state_count++ == 10) {
3278 printk(MPT2SAS_ERR_FMT
3279 "%s: failed due to ioc not operational\n",
3280 ioc->name, __func__);
3281 rc = -EFAULT;
3282 goto out;
3283 }
3284 ssleep(1);
3285 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3286 printk(MPT2SAS_INFO_FMT "%s: waiting for "
3287 "operational state(count=%d)\n", ioc->name,
3288 __func__, wait_state_count);
3289 }
3290
3291 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3292 if (!smid) {
3293 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3294 ioc->name, __func__);
3295 rc = -EAGAIN;
3296 goto out;
3297 }
3298
3299 rc = 0;
3300 ioc->base_cmds.status = MPT2_CMD_PENDING;
3301 request = mpt2sas_base_get_msg_frame(ioc, smid);
3302 ioc->base_cmds.smid = smid;
3303 memcpy(request, mpi_request, sizeof(Mpi2SepReply_t));
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05303304 init_completion(&ioc->base_cmds.done);
nagalakshmi.nandigama@lsi.comf01690d2011-12-01 07:43:58 +05303305 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003306 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3307 msecs_to_jiffies(10000));
3308 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3309 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3310 ioc->name, __func__);
3311 _debug_dump_mf(mpi_request,
3312 sizeof(Mpi2SepRequest_t)/4);
3313 if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
3314 issue_reset = 1;
3315 goto issue_host_reset;
3316 }
3317 if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)
3318 memcpy(mpi_reply, ioc->base_cmds.reply,
3319 sizeof(Mpi2SepReply_t));
3320 else
3321 memset(mpi_reply, 0, sizeof(Mpi2SepReply_t));
3322 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3323 goto out;
3324
3325 issue_host_reset:
3326 if (issue_reset)
3327 mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
3328 FORCE_BIG_HAMMER);
3329 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3330 rc = -EFAULT;
3331 out:
3332 mutex_unlock(&ioc->base_cmds.mutex);
3333 return rc;
3334}
3335
3336/**
3337 * _base_get_port_facts - obtain port facts reply and save in ioc
3338 * @ioc: per adapter object
3339 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3340 *
3341 * Returns 0 for success, non-zero for failure.
3342 */
3343static int
3344_base_get_port_facts(struct MPT2SAS_ADAPTER *ioc, int port, int sleep_flag)
3345{
3346 Mpi2PortFactsRequest_t mpi_request;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303347 Mpi2PortFactsReply_t mpi_reply;
3348 struct mpt2sas_port_facts *pfacts;
Eric Moore635374e2009-03-09 01:21:12 -06003349 int mpi_reply_sz, mpi_request_sz, r;
3350
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303351 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06003352 __func__));
3353
3354 mpi_reply_sz = sizeof(Mpi2PortFactsReply_t);
3355 mpi_request_sz = sizeof(Mpi2PortFactsRequest_t);
3356 memset(&mpi_request, 0, mpi_request_sz);
3357 mpi_request.Function = MPI2_FUNCTION_PORT_FACTS;
3358 mpi_request.PortNumber = port;
3359 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3360 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3361
3362 if (r != 0) {
3363 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3364 ioc->name, __func__, r);
3365 return r;
3366 }
3367
3368 pfacts = &ioc->pfacts[port];
3369 memset(pfacts, 0, sizeof(Mpi2PortFactsReply_t));
3370 pfacts->PortNumber = mpi_reply.PortNumber;
3371 pfacts->VP_ID = mpi_reply.VP_ID;
3372 pfacts->VF_ID = mpi_reply.VF_ID;
3373 pfacts->MaxPostedCmdBuffers =
3374 le16_to_cpu(mpi_reply.MaxPostedCmdBuffers);
3375
3376 return 0;
3377}
3378
3379/**
3380 * _base_get_ioc_facts - obtain ioc facts reply and save in ioc
3381 * @ioc: per adapter object
3382 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3383 *
3384 * Returns 0 for success, non-zero for failure.
3385 */
3386static int
3387_base_get_ioc_facts(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3388{
3389 Mpi2IOCFactsRequest_t mpi_request;
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303390 Mpi2IOCFactsReply_t mpi_reply;
3391 struct mpt2sas_facts *facts;
Eric Moore635374e2009-03-09 01:21:12 -06003392 int mpi_reply_sz, mpi_request_sz, r;
3393
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303394 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06003395 __func__));
3396
3397 mpi_reply_sz = sizeof(Mpi2IOCFactsReply_t);
3398 mpi_request_sz = sizeof(Mpi2IOCFactsRequest_t);
3399 memset(&mpi_request, 0, mpi_request_sz);
3400 mpi_request.Function = MPI2_FUNCTION_IOC_FACTS;
3401 r = _base_handshake_req_reply_wait(ioc, mpi_request_sz,
3402 (u32 *)&mpi_request, mpi_reply_sz, (u16 *)&mpi_reply, 5, CAN_SLEEP);
3403
3404 if (r != 0) {
3405 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3406 ioc->name, __func__, r);
3407 return r;
3408 }
3409
3410 facts = &ioc->facts;
3411 memset(facts, 0, sizeof(Mpi2IOCFactsReply_t));
3412 facts->MsgVersion = le16_to_cpu(mpi_reply.MsgVersion);
3413 facts->HeaderVersion = le16_to_cpu(mpi_reply.HeaderVersion);
3414 facts->VP_ID = mpi_reply.VP_ID;
3415 facts->VF_ID = mpi_reply.VF_ID;
3416 facts->IOCExceptions = le16_to_cpu(mpi_reply.IOCExceptions);
3417 facts->MaxChainDepth = mpi_reply.MaxChainDepth;
3418 facts->WhoInit = mpi_reply.WhoInit;
3419 facts->NumberOfPorts = mpi_reply.NumberOfPorts;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05303420 facts->MaxMSIxVectors = mpi_reply.MaxMSIxVectors;
Eric Moore635374e2009-03-09 01:21:12 -06003421 facts->RequestCredit = le16_to_cpu(mpi_reply.RequestCredit);
3422 facts->MaxReplyDescriptorPostQueueDepth =
3423 le16_to_cpu(mpi_reply.MaxReplyDescriptorPostQueueDepth);
3424 facts->ProductID = le16_to_cpu(mpi_reply.ProductID);
3425 facts->IOCCapabilities = le32_to_cpu(mpi_reply.IOCCapabilities);
3426 if ((facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID))
3427 ioc->ir_firmware = 1;
3428 facts->FWVersion.Word = le32_to_cpu(mpi_reply.FWVersion.Word);
3429 facts->IOCRequestFrameSize =
3430 le16_to_cpu(mpi_reply.IOCRequestFrameSize);
3431 facts->MaxInitiators = le16_to_cpu(mpi_reply.MaxInitiators);
3432 facts->MaxTargets = le16_to_cpu(mpi_reply.MaxTargets);
3433 ioc->shost->max_id = -1;
3434 facts->MaxSasExpanders = le16_to_cpu(mpi_reply.MaxSasExpanders);
3435 facts->MaxEnclosures = le16_to_cpu(mpi_reply.MaxEnclosures);
3436 facts->ProtocolFlags = le16_to_cpu(mpi_reply.ProtocolFlags);
3437 facts->HighPriorityCredit =
3438 le16_to_cpu(mpi_reply.HighPriorityCredit);
3439 facts->ReplyFrameSize = mpi_reply.ReplyFrameSize;
3440 facts->MaxDevHandle = le16_to_cpu(mpi_reply.MaxDevHandle);
3441
3442 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "hba queue depth(%d), "
3443 "max chains per io(%d)\n", ioc->name, facts->RequestCredit,
3444 facts->MaxChainDepth));
3445 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "request frame size(%d), "
3446 "reply frame size(%d)\n", ioc->name,
3447 facts->IOCRequestFrameSize * 4, facts->ReplyFrameSize * 4));
3448 return 0;
3449}
3450
3451/**
3452 * _base_send_ioc_init - send ioc_init to firmware
3453 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06003454 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3455 *
3456 * Returns 0 for success, non-zero for failure.
3457 */
3458static int
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303459_base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
Eric Moore635374e2009-03-09 01:21:12 -06003460{
3461 Mpi2IOCInitRequest_t mpi_request;
3462 Mpi2IOCInitReply_t mpi_reply;
3463 int r;
Kashyap, Desaia8ebd762009-09-23 17:29:29 +05303464 struct timeval current_time;
Kashyap, Desai463217b2009-10-05 15:53:06 +05303465 u16 ioc_status;
Eric Moore635374e2009-03-09 01:21:12 -06003466
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303467 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06003468 __func__));
3469
3470 memset(&mpi_request, 0, sizeof(Mpi2IOCInitRequest_t));
3471 mpi_request.Function = MPI2_FUNCTION_IOC_INIT;
3472 mpi_request.WhoInit = MPI2_WHOINIT_HOST_DRIVER;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303473 mpi_request.VF_ID = 0; /* TODO */
3474 mpi_request.VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003475 mpi_request.MsgVersion = cpu_to_le16(MPI2_VERSION);
3476 mpi_request.HeaderVersion = cpu_to_le16(MPI2_HEADER_VERSION);
3477
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05303478 if (_base_is_controller_msix_enabled(ioc))
3479 mpi_request.HostMSIxVectors = ioc->reply_queue_count;
Eric Moore635374e2009-03-09 01:21:12 -06003480 mpi_request.SystemRequestFrameSize = cpu_to_le16(ioc->request_sz/4);
3481 mpi_request.ReplyDescriptorPostQueueDepth =
3482 cpu_to_le16(ioc->reply_post_queue_depth);
3483 mpi_request.ReplyFreeQueueDepth =
3484 cpu_to_le16(ioc->reply_free_queue_depth);
3485
Eric Moore635374e2009-03-09 01:21:12 -06003486 mpi_request.SenseBufferAddressHigh =
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303487 cpu_to_le32((u64)ioc->sense_dma >> 32);
Eric Moore635374e2009-03-09 01:21:12 -06003488 mpi_request.SystemReplyAddressHigh =
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303489 cpu_to_le32((u64)ioc->reply_dma >> 32);
Eric Moore635374e2009-03-09 01:21:12 -06003490 mpi_request.SystemRequestFrameBaseAddress =
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303491 cpu_to_le64((u64)ioc->request_dma);
Eric Moore635374e2009-03-09 01:21:12 -06003492 mpi_request.ReplyFreeQueueAddress =
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303493 cpu_to_le64((u64)ioc->reply_free_dma);
Eric Moore635374e2009-03-09 01:21:12 -06003494 mpi_request.ReplyDescriptorPostQueueAddress =
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303495 cpu_to_le64((u64)ioc->reply_post_free_dma);
3496
Eric Moore635374e2009-03-09 01:21:12 -06003497
Kashyap, Desaia8ebd762009-09-23 17:29:29 +05303498 /* This time stamp specifies number of milliseconds
3499 * since epoch ~ midnight January 1, 1970.
3500 */
3501 do_gettimeofday(&current_time);
Kashyap, Desai7921b35c2010-03-17 16:21:33 +05303502 mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
3503 (current_time.tv_usec / 1000));
Kashyap, Desaia8ebd762009-09-23 17:29:29 +05303504
Eric Moore635374e2009-03-09 01:21:12 -06003505 if (ioc->logging_level & MPT_DEBUG_INIT) {
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303506 __le32 *mfp;
Eric Moore635374e2009-03-09 01:21:12 -06003507 int i;
3508
Kashyap, Desaic97951e2011-06-14 10:54:56 +05303509 mfp = (__le32 *)&mpi_request;
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303510 printk(KERN_INFO "\toffset:data\n");
Eric Moore635374e2009-03-09 01:21:12 -06003511 for (i = 0; i < sizeof(Mpi2IOCInitRequest_t)/4; i++)
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303512 printk(KERN_INFO "\t[0x%02x]:%08x\n", i*4,
Eric Moore635374e2009-03-09 01:21:12 -06003513 le32_to_cpu(mfp[i]));
3514 }
3515
3516 r = _base_handshake_req_reply_wait(ioc,
3517 sizeof(Mpi2IOCInitRequest_t), (u32 *)&mpi_request,
3518 sizeof(Mpi2IOCInitReply_t), (u16 *)&mpi_reply, 10,
3519 sleep_flag);
3520
3521 if (r != 0) {
3522 printk(MPT2SAS_ERR_FMT "%s: handshake failed (r=%d)\n",
3523 ioc->name, __func__, r);
3524 return r;
3525 }
3526
Kashyap, Desai463217b2009-10-05 15:53:06 +05303527 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
3528 if (ioc_status != MPI2_IOCSTATUS_SUCCESS ||
Eric Moore635374e2009-03-09 01:21:12 -06003529 mpi_reply.IOCLogInfo) {
3530 printk(MPT2SAS_ERR_FMT "%s: failed\n", ioc->name, __func__);
3531 r = -EIO;
3532 }
3533
3534 return 0;
3535}
3536
3537/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303538 * mpt2sas_port_enable_done - command completion routine for port enable
3539 * @ioc: per adapter object
3540 * @smid: system request message index
3541 * @msix_index: MSIX table index supplied by the OS
3542 * @reply: reply message frame(lower 32bit addr)
3543 *
3544 * Return 1 meaning mf should be freed from _base_interrupt
3545 * 0 means the mf is freed from this function.
3546 */
3547u8
3548mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3549 u32 reply)
3550{
3551 MPI2DefaultReply_t *mpi_reply;
3552 u16 ioc_status;
3553
3554 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3555 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3556 return 1;
3557
3558 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3559 return 1;
3560
3561 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3562 if (mpi_reply) {
3563 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3564 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3565 mpi_reply->MsgLength*4);
3566 }
3567 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3568
3569 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3570
3571 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3572 ioc->port_enable_failed = 1;
3573
3574 if (ioc->is_driver_loading) {
3575 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3576 mpt2sas_port_enable_complete(ioc);
3577 return 1;
3578 } else {
3579 ioc->start_scan_failed = ioc_status;
3580 ioc->start_scan = 0;
3581 return 1;
3582 }
3583 }
3584 complete(&ioc->port_enable_cmds.done);
3585 return 1;
3586}
3587
3588
3589/**
Eric Moore635374e2009-03-09 01:21:12 -06003590 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3591 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06003592 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3593 *
3594 * Returns 0 for success, non-zero for failure.
3595 */
3596static int
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303597_base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
Eric Moore635374e2009-03-09 01:21:12 -06003598{
3599 Mpi2PortEnableRequest_t *mpi_request;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303600 Mpi2PortEnableReply_t *mpi_reply;
Eric Moore635374e2009-03-09 01:21:12 -06003601 unsigned long timeleft;
3602 int r = 0;
3603 u16 smid;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303604 u16 ioc_status;
Eric Moore635374e2009-03-09 01:21:12 -06003605
3606 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3607
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303608 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
Eric Moore635374e2009-03-09 01:21:12 -06003609 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3610 ioc->name, __func__);
3611 return -EAGAIN;
3612 }
3613
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303614 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
Eric Moore635374e2009-03-09 01:21:12 -06003615 if (!smid) {
3616 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3617 ioc->name, __func__);
3618 return -EAGAIN;
3619 }
3620
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303621 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
Eric Moore635374e2009-03-09 01:21:12 -06003622 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303623 ioc->port_enable_cmds.smid = smid;
Eric Moore635374e2009-03-09 01:21:12 -06003624 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3625 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
Eric Moore635374e2009-03-09 01:21:12 -06003626
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303627 init_completion(&ioc->port_enable_cmds.done);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303628 mpt2sas_base_put_smid_default(ioc, smid);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303629 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
Eric Moore635374e2009-03-09 01:21:12 -06003630 300*HZ);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303631 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
Eric Moore635374e2009-03-09 01:21:12 -06003632 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3633 ioc->name, __func__);
3634 _debug_dump_mf(mpi_request,
3635 sizeof(Mpi2PortEnableRequest_t)/4);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303636 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
Eric Moore635374e2009-03-09 01:21:12 -06003637 r = -EFAULT;
3638 else
3639 r = -ETIME;
3640 goto out;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303641 }
3642 mpi_reply = ioc->port_enable_cmds.reply;
Eric Moore635374e2009-03-09 01:21:12 -06003643
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303644 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3645 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3646 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3647 ioc->name, __func__, ioc_status);
Eric Moore635374e2009-03-09 01:21:12 -06003648 r = -EFAULT;
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303649 goto out;
Eric Moore635374e2009-03-09 01:21:12 -06003650 }
3651 out:
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303652 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3653 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3654 "SUCCESS" : "FAILED"));
Eric Moore635374e2009-03-09 01:21:12 -06003655 return r;
3656}
3657
3658/**
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05303659 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3660 * @ioc: per adapter object
3661 *
3662 * Returns 0 for success, non-zero for failure.
3663 */
3664int
3665mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3666{
3667 Mpi2PortEnableRequest_t *mpi_request;
3668 u16 smid;
3669
3670 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3671
3672 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3673 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3674 ioc->name, __func__);
3675 return -EAGAIN;
3676 }
3677
3678 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3679 if (!smid) {
3680 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3681 ioc->name, __func__);
3682 return -EAGAIN;
3683 }
3684
3685 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3686 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3687 ioc->port_enable_cmds.smid = smid;
3688 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3689 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3690
3691 mpt2sas_base_put_smid_default(ioc, smid);
3692 return 0;
3693}
3694
3695/**
3696 * _base_determine_wait_on_discovery - desposition
3697 * @ioc: per adapter object
3698 *
3699 * Decide whether to wait on discovery to complete. Used to either
3700 * locate boot device, or report volumes ahead of physical devices.
3701 *
3702 * Returns 1 for wait, 0 for don't wait
3703 */
3704static int
3705_base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3706{
3707 /* We wait for discovery to complete if IR firmware is loaded.
3708 * The sas topology events arrive before PD events, so we need time to
3709 * turn on the bit in ioc->pd_handles to indicate PD
3710 * Also, it maybe required to report Volumes ahead of physical
3711 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3712 */
3713 if (ioc->ir_firmware)
3714 return 1;
3715
3716 /* if no Bios, then we don't need to wait */
3717 if (!ioc->bios_pg3.BiosVersion)
3718 return 0;
3719
3720 /* Bios is present, then we drop down here.
3721 *
3722 * If there any entries in the Bios Page 2, then we wait
3723 * for discovery to complete.
3724 */
3725
3726 /* Current Boot Device */
3727 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3728 MPI2_BIOSPAGE2_FORM_MASK) ==
3729 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3730 /* Request Boot Device */
3731 (ioc->bios_pg2.ReqBootDeviceForm &
3732 MPI2_BIOSPAGE2_FORM_MASK) ==
3733 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3734 /* Alternate Request Boot Device */
3735 (ioc->bios_pg2.ReqAltBootDeviceForm &
3736 MPI2_BIOSPAGE2_FORM_MASK) ==
3737 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3738 return 0;
3739
3740 return 1;
3741}
3742
3743
3744/**
Eric Moore635374e2009-03-09 01:21:12 -06003745 * _base_unmask_events - turn on notification for this event
3746 * @ioc: per adapter object
3747 * @event: firmware event
3748 *
3749 * The mask is stored in ioc->event_masks.
3750 */
3751static void
3752_base_unmask_events(struct MPT2SAS_ADAPTER *ioc, u16 event)
3753{
3754 u32 desired_event;
3755
3756 if (event >= 128)
3757 return;
3758
3759 desired_event = (1 << (event % 32));
3760
3761 if (event < 32)
3762 ioc->event_masks[0] &= ~desired_event;
3763 else if (event < 64)
3764 ioc->event_masks[1] &= ~desired_event;
3765 else if (event < 96)
3766 ioc->event_masks[2] &= ~desired_event;
3767 else if (event < 128)
3768 ioc->event_masks[3] &= ~desired_event;
3769}
3770
3771/**
3772 * _base_event_notification - send event notification
3773 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06003774 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3775 *
3776 * Returns 0 for success, non-zero for failure.
3777 */
3778static int
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303779_base_event_notification(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
Eric Moore635374e2009-03-09 01:21:12 -06003780{
3781 Mpi2EventNotificationRequest_t *mpi_request;
3782 unsigned long timeleft;
3783 u16 smid;
3784 int r = 0;
3785 int i;
3786
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303787 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06003788 __func__));
3789
3790 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
3791 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3792 ioc->name, __func__);
3793 return -EAGAIN;
3794 }
3795
3796 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx);
3797 if (!smid) {
3798 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3799 ioc->name, __func__);
3800 return -EAGAIN;
3801 }
3802 ioc->base_cmds.status = MPT2_CMD_PENDING;
3803 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3804 ioc->base_cmds.smid = smid;
3805 memset(mpi_request, 0, sizeof(Mpi2EventNotificationRequest_t));
3806 mpi_request->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303807 mpi_request->VF_ID = 0; /* TODO */
3808 mpi_request->VP_ID = 0;
Eric Moore635374e2009-03-09 01:21:12 -06003809 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3810 mpi_request->EventMasks[i] =
Kashyap, Desaie94f6742010-03-17 16:24:52 +05303811 cpu_to_le32(ioc->event_masks[i]);
Kashyap, Desaibcfb6e62009-09-14 11:05:24 +05303812 init_completion(&ioc->base_cmds.done);
nagalakshmi.nandigama@lsi.comf01690d2011-12-01 07:43:58 +05303813 mpt2sas_base_put_smid_default(ioc, smid);
Eric Moore635374e2009-03-09 01:21:12 -06003814 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done, 30*HZ);
3815 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) {
3816 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3817 ioc->name, __func__);
3818 _debug_dump_mf(mpi_request,
3819 sizeof(Mpi2EventNotificationRequest_t)/4);
3820 if (ioc->base_cmds.status & MPT2_CMD_RESET)
3821 r = -EFAULT;
3822 else
3823 r = -ETIME;
3824 } else
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303825 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n",
Eric Moore635374e2009-03-09 01:21:12 -06003826 ioc->name, __func__));
3827 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
3828 return r;
3829}
3830
3831/**
3832 * mpt2sas_base_validate_event_type - validating event types
3833 * @ioc: per adapter object
3834 * @event: firmware event
3835 *
3836 * This will turn on firmware event notification when application
3837 * ask for that event. We don't mask events that are already enabled.
3838 */
3839void
3840mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_type)
3841{
3842 int i, j;
3843 u32 event_mask, desired_event;
3844 u8 send_update_to_fw;
3845
3846 for (i = 0, send_update_to_fw = 0; i <
3847 MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) {
3848 event_mask = ~event_type[i];
3849 desired_event = 1;
3850 for (j = 0; j < 32; j++) {
3851 if (!(event_mask & desired_event) &&
3852 (ioc->event_masks[i] & desired_event)) {
3853 ioc->event_masks[i] &= ~desired_event;
3854 send_update_to_fw = 1;
3855 }
3856 desired_event = (desired_event << 1);
3857 }
3858 }
3859
3860 if (!send_update_to_fw)
3861 return;
3862
3863 mutex_lock(&ioc->base_cmds.mutex);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05303864 _base_event_notification(ioc, CAN_SLEEP);
Eric Moore635374e2009-03-09 01:21:12 -06003865 mutex_unlock(&ioc->base_cmds.mutex);
3866}
3867
3868/**
3869 * _base_diag_reset - the "big hammer" start of day reset
3870 * @ioc: per adapter object
3871 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3872 *
3873 * Returns 0 for success, non-zero for failure.
3874 */
3875static int
3876_base_diag_reset(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3877{
3878 u32 host_diagnostic;
3879 u32 ioc_state;
3880 u32 count;
3881 u32 hcb_size;
3882
3883 printk(MPT2SAS_INFO_FMT "sending diag reset !!\n", ioc->name);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303884 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "clear interrupts\n",
Eric Moore635374e2009-03-09 01:21:12 -06003885 ioc->name));
Eric Moore635374e2009-03-09 01:21:12 -06003886
3887 count = 0;
3888 do {
3889 /* Write magic sequence to WriteSequence register
3890 * Loop until in diagnostic mode
3891 */
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303892 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "write magic "
Eric Moore635374e2009-03-09 01:21:12 -06003893 "sequence\n", ioc->name));
3894 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3895 writel(MPI2_WRSEQ_1ST_KEY_VALUE, &ioc->chip->WriteSequence);
3896 writel(MPI2_WRSEQ_2ND_KEY_VALUE, &ioc->chip->WriteSequence);
3897 writel(MPI2_WRSEQ_3RD_KEY_VALUE, &ioc->chip->WriteSequence);
3898 writel(MPI2_WRSEQ_4TH_KEY_VALUE, &ioc->chip->WriteSequence);
3899 writel(MPI2_WRSEQ_5TH_KEY_VALUE, &ioc->chip->WriteSequence);
3900 writel(MPI2_WRSEQ_6TH_KEY_VALUE, &ioc->chip->WriteSequence);
3901
3902 /* wait 100 msec */
3903 if (sleep_flag == CAN_SLEEP)
3904 msleep(100);
3905 else
3906 mdelay(100);
3907
3908 if (count++ > 20)
3909 goto out;
3910
3911 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303912 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "wrote magic "
Eric Moore635374e2009-03-09 01:21:12 -06003913 "sequence: count(%d), host_diagnostic(0x%08x)\n",
3914 ioc->name, count, host_diagnostic));
3915
3916 } while ((host_diagnostic & MPI2_DIAG_DIAG_WRITE_ENABLE) == 0);
3917
3918 hcb_size = readl(&ioc->chip->HCBSize);
3919
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303920 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "diag reset: issued\n",
Eric Moore635374e2009-03-09 01:21:12 -06003921 ioc->name));
3922 writel(host_diagnostic | MPI2_DIAG_RESET_ADAPTER,
3923 &ioc->chip->HostDiagnostic);
3924
3925 /* don't access any registers for 50 milliseconds */
3926 msleep(50);
3927
3928 /* 300 second max wait */
3929 for (count = 0; count < 3000000 ; count++) {
3930
3931 host_diagnostic = readl(&ioc->chip->HostDiagnostic);
3932
3933 if (host_diagnostic == 0xFFFFFFFF)
3934 goto out;
3935 if (!(host_diagnostic & MPI2_DIAG_RESET_ADAPTER))
3936 break;
3937
3938 /* wait 100 msec */
3939 if (sleep_flag == CAN_SLEEP)
3940 msleep(1);
3941 else
3942 mdelay(1);
3943 }
3944
3945 if (host_diagnostic & MPI2_DIAG_HCB_MODE) {
3946
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303947 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter "
Eric Moore635374e2009-03-09 01:21:12 -06003948 "assuming the HCB Address points to good F/W\n",
3949 ioc->name));
3950 host_diagnostic &= ~MPI2_DIAG_BOOT_DEVICE_SELECT_MASK;
3951 host_diagnostic |= MPI2_DIAG_BOOT_DEVICE_SELECT_HCDW;
3952 writel(host_diagnostic, &ioc->chip->HostDiagnostic);
3953
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303954 drsprintk(ioc, printk(MPT2SAS_INFO_FMT
Eric Moore635374e2009-03-09 01:21:12 -06003955 "re-enable the HCDW\n", ioc->name));
3956 writel(hcb_size | MPI2_HCB_SIZE_HCB_ENABLE,
3957 &ioc->chip->HCBSize);
3958 }
3959
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303960 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "restart the adapter\n",
Eric Moore635374e2009-03-09 01:21:12 -06003961 ioc->name));
3962 writel(host_diagnostic & ~MPI2_DIAG_HOLD_IOC_RESET,
3963 &ioc->chip->HostDiagnostic);
3964
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303965 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "disable writes to the "
Eric Moore635374e2009-03-09 01:21:12 -06003966 "diagnostic register\n", ioc->name));
3967 writel(MPI2_WRSEQ_FLUSH_KEY_VALUE, &ioc->chip->WriteSequence);
3968
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05303969 drsprintk(ioc, printk(MPT2SAS_INFO_FMT "Wait for FW to go to the "
Eric Moore635374e2009-03-09 01:21:12 -06003970 "READY state\n", ioc->name));
3971 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_READY, 20,
3972 sleep_flag);
3973 if (ioc_state) {
3974 printk(MPT2SAS_ERR_FMT "%s: failed going to ready state "
3975 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3976 goto out;
3977 }
3978
Eric Moore635374e2009-03-09 01:21:12 -06003979 printk(MPT2SAS_INFO_FMT "diag reset: SUCCESS\n", ioc->name);
3980 return 0;
3981
3982 out:
3983 printk(MPT2SAS_ERR_FMT "diag reset: FAILED\n", ioc->name);
3984 return -EFAULT;
3985}
3986
3987/**
3988 * _base_make_ioc_ready - put controller in READY state
3989 * @ioc: per adapter object
3990 * @sleep_flag: CAN_SLEEP or NO_SLEEP
3991 * @type: FORCE_BIG_HAMMER or SOFT_RESET
3992 *
3993 * Returns 0 for success, non-zero for failure.
3994 */
3995static int
3996_base_make_ioc_ready(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
3997 enum reset_type type)
3998{
3999 u32 ioc_state;
Kashyap, Desaid32a8c12010-06-17 13:36:53 +05304000 int rc;
Eric Moore635374e2009-03-09 01:21:12 -06004001
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304002 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06004003 __func__));
4004
Eric Moore3cb54692010-07-08 14:44:34 -06004005 if (ioc->pci_error_recovery)
4006 return 0;
4007
Eric Moore635374e2009-03-09 01:21:12 -06004008 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304009 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: ioc_state(0x%08x)\n",
Eric Moore635374e2009-03-09 01:21:12 -06004010 ioc->name, __func__, ioc_state));
4011
4012 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_READY)
4013 return 0;
4014
4015 if (ioc_state & MPI2_DOORBELL_USED) {
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304016 dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
Eric Moore635374e2009-03-09 01:21:12 -06004017 "active!\n", ioc->name));
4018 goto issue_diag_reset;
4019 }
4020
4021 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
4022 mpt2sas_base_fault_info(ioc, ioc_state &
4023 MPI2_DOORBELL_DATA_MASK);
4024 goto issue_diag_reset;
4025 }
4026
4027 if (type == FORCE_BIG_HAMMER)
4028 goto issue_diag_reset;
4029
4030 if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_OPERATIONAL)
4031 if (!(_base_send_ioc_reset(ioc,
Kashyap, Desaid32a8c12010-06-17 13:36:53 +05304032 MPI2_FUNCTION_IOC_MESSAGE_UNIT_RESET, 15, CAN_SLEEP))) {
4033 ioc->ioc_reset_count++;
Eric Moore635374e2009-03-09 01:21:12 -06004034 return 0;
Kashyap, Desaid32a8c12010-06-17 13:36:53 +05304035 }
Eric Moore635374e2009-03-09 01:21:12 -06004036
4037 issue_diag_reset:
Kashyap, Desaid32a8c12010-06-17 13:36:53 +05304038 rc = _base_diag_reset(ioc, CAN_SLEEP);
4039 ioc->ioc_reset_count++;
4040 return rc;
Eric Moore635374e2009-03-09 01:21:12 -06004041}
4042
4043/**
4044 * _base_make_ioc_operational - put controller in OPERATIONAL state
4045 * @ioc: per adapter object
Eric Moore635374e2009-03-09 01:21:12 -06004046 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4047 *
4048 * Returns 0 for success, non-zero for failure.
4049 */
4050static int
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304051_base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
Eric Moore635374e2009-03-09 01:21:12 -06004052{
4053 int r, i;
4054 unsigned long flags;
4055 u32 reply_address;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304056 u16 smid;
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304057 struct _tr_list *delayed_tr, *delayed_tr_next;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304058 u8 hide_flag;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304059 struct adapter_reply_queue *reply_q;
4060 long reply_post_free;
4061 u32 reply_post_free_sz;
Eric Moore635374e2009-03-09 01:21:12 -06004062
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304063 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06004064 __func__));
4065
Kashyap, Desai77e63ed2009-09-14 11:04:23 +05304066 /* clean the delayed target reset list */
4067 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4068 &ioc->delayed_tr_list, list) {
4069 list_del(&delayed_tr->list);
4070 kfree(delayed_tr);
4071 }
4072
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05304073 list_for_each_entry_safe(delayed_tr, delayed_tr_next,
4074 &ioc->delayed_tr_volume_list, list) {
4075 list_del(&delayed_tr->list);
4076 kfree(delayed_tr);
4077 }
4078
Eric Moore635374e2009-03-09 01:21:12 -06004079 /* initialize the scsi lookup free list */
4080 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
4081 INIT_LIST_HEAD(&ioc->free_list);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304082 smid = 1;
4083 for (i = 0; i < ioc->scsiio_depth; i++, smid++) {
Kashyap, Desai35f805b2010-11-13 04:34:06 +05304084 INIT_LIST_HEAD(&ioc->scsi_lookup[i].chain_list);
Eric Moore635374e2009-03-09 01:21:12 -06004085 ioc->scsi_lookup[i].cb_idx = 0xFF;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304086 ioc->scsi_lookup[i].smid = smid;
4087 ioc->scsi_lookup[i].scmd = NULL;
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304088 ioc->scsi_lookup[i].direct_io = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004089 list_add_tail(&ioc->scsi_lookup[i].tracker_list,
4090 &ioc->free_list);
4091 }
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304092
4093 /* hi-priority queue */
4094 INIT_LIST_HEAD(&ioc->hpr_free_list);
4095 smid = ioc->hi_priority_smid;
4096 for (i = 0; i < ioc->hi_priority_depth; i++, smid++) {
4097 ioc->hpr_lookup[i].cb_idx = 0xFF;
4098 ioc->hpr_lookup[i].smid = smid;
4099 list_add_tail(&ioc->hpr_lookup[i].tracker_list,
4100 &ioc->hpr_free_list);
4101 }
4102
4103 /* internal queue */
4104 INIT_LIST_HEAD(&ioc->internal_free_list);
4105 smid = ioc->internal_smid;
4106 for (i = 0; i < ioc->internal_depth; i++, smid++) {
4107 ioc->internal_lookup[i].cb_idx = 0xFF;
4108 ioc->internal_lookup[i].smid = smid;
4109 list_add_tail(&ioc->internal_lookup[i].tracker_list,
4110 &ioc->internal_free_list);
4111 }
Kashyap, Desai35f805b2010-11-13 04:34:06 +05304112
4113 /* chain pool */
4114 INIT_LIST_HEAD(&ioc->free_chain_list);
4115 for (i = 0; i < ioc->chain_depth; i++)
4116 list_add_tail(&ioc->chain_lookup[i].tracker_list,
4117 &ioc->free_chain_list);
4118
Eric Moore635374e2009-03-09 01:21:12 -06004119 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4120
4121 /* initialize Reply Free Queue */
4122 for (i = 0, reply_address = (u32)ioc->reply_dma ;
4123 i < ioc->reply_free_queue_depth ; i++, reply_address +=
4124 ioc->reply_sz)
4125 ioc->reply_free[i] = cpu_to_le32(reply_address);
4126
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304127 /* initialize reply queues */
4128 _base_assign_reply_queues(ioc);
4129
Eric Moore635374e2009-03-09 01:21:12 -06004130 /* initialize Reply Post Free Queue */
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304131 reply_post_free = (long)ioc->reply_post_free;
4132 reply_post_free_sz = ioc->reply_post_queue_depth *
4133 sizeof(Mpi2DefaultReplyDescriptor_t);
4134 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4135 reply_q->reply_post_host_index = 0;
4136 reply_q->reply_post_free = (Mpi2ReplyDescriptorsUnion_t *)
4137 reply_post_free;
4138 for (i = 0; i < ioc->reply_post_queue_depth; i++)
4139 reply_q->reply_post_free[i].Words =
4140 cpu_to_le64(ULLONG_MAX);
4141 if (!_base_is_controller_msix_enabled(ioc))
4142 goto skip_init_reply_post_free_queue;
4143 reply_post_free += reply_post_free_sz;
4144 }
4145 skip_init_reply_post_free_queue:
Eric Moore635374e2009-03-09 01:21:12 -06004146
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304147 r = _base_send_ioc_init(ioc, sleep_flag);
Eric Moore635374e2009-03-09 01:21:12 -06004148 if (r)
4149 return r;
4150
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304151 /* initialize reply free host index */
Eric Moore635374e2009-03-09 01:21:12 -06004152 ioc->reply_free_host_index = ioc->reply_free_queue_depth - 1;
Eric Moore635374e2009-03-09 01:21:12 -06004153 writel(ioc->reply_free_host_index, &ioc->chip->ReplyFreeHostIndex);
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304154
4155 /* initialize reply post host index */
4156 list_for_each_entry(reply_q, &ioc->reply_queue_list, list) {
4157 writel(reply_q->msix_index << MPI2_RPHI_MSIX_INDEX_SHIFT,
4158 &ioc->chip->ReplyPostHostIndex);
4159 if (!_base_is_controller_msix_enabled(ioc))
4160 goto skip_init_reply_post_host_index;
4161 }
4162
4163 skip_init_reply_post_host_index:
Eric Moore635374e2009-03-09 01:21:12 -06004164
4165 _base_unmask_interrupts(ioc);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05304166
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304167 r = _base_event_notification(ioc, sleep_flag);
Eric Moore635374e2009-03-09 01:21:12 -06004168 if (r)
4169 return r;
4170
4171 if (sleep_flag == CAN_SLEEP)
4172 _base_static_config_pages(ioc);
4173
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05304174
4175 if (ioc->is_driver_loading) {
4176
4177
4178
4179 ioc->wait_for_discovery_to_complete =
4180 _base_determine_wait_on_discovery(ioc);
4181 return r; /* scan_start and scan_finished support */
4182 }
4183
4184
4185 if (ioc->wait_for_discovery_to_complete && ioc->is_warpdrive) {
Kashyap, Desai0bdccdb2011-04-07 12:32:49 +05304186 if (ioc->manu_pg10.OEMIdentifier == 0x80) {
4187 hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 &
4188 MFG_PAGE10_HIDE_SSDS_MASK);
4189 if (hide_flag != MFG_PAGE10_HIDE_SSDS_MASK)
4190 ioc->mfg_pg10_hide_flag = hide_flag;
4191 }
4192 }
4193
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304194 r = _base_send_port_enable(ioc, sleep_flag);
Eric Moore635374e2009-03-09 01:21:12 -06004195 if (r)
4196 return r;
4197
4198 return r;
4199}
4200
4201/**
4202 * mpt2sas_base_free_resources - free resources controller resources (io/irq/memap)
4203 * @ioc: per adapter object
4204 *
4205 * Return nothing.
4206 */
4207void
4208mpt2sas_base_free_resources(struct MPT2SAS_ADAPTER *ioc)
4209{
4210 struct pci_dev *pdev = ioc->pdev;
4211
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304212 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06004213 __func__));
4214
4215 _base_mask_interrupts(ioc);
Kashyap, Desai6558bbb2010-03-17 16:23:36 +05304216 ioc->shost_recovery = 1;
Eric Moore635374e2009-03-09 01:21:12 -06004217 _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
Kashyap, Desai6558bbb2010-03-17 16:23:36 +05304218 ioc->shost_recovery = 0;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304219 _base_free_irq(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06004220 _base_disable_msix(ioc);
4221 if (ioc->chip_phys)
4222 iounmap(ioc->chip);
Eric Moore635374e2009-03-09 01:21:12 -06004223 ioc->chip_phys = 0;
4224 pci_release_selected_regions(ioc->pdev, ioc->bars);
Kashyap, Desaief7c80c2010-04-05 14:20:07 +05304225 pci_disable_pcie_error_reporting(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06004226 pci_disable_device(pdev);
Eric Moore635374e2009-03-09 01:21:12 -06004227 return;
4228}
4229
4230/**
4231 * mpt2sas_base_attach - attach controller instance
4232 * @ioc: per adapter object
4233 *
4234 * Returns 0 for success, non-zero for failure.
4235 */
4236int
4237mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4238{
4239 int r, i;
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304240 int cpu_id, last_cpu_id = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004241
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304242 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06004243 __func__));
4244
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304245 /* setup cpu_msix_table */
4246 ioc->cpu_count = num_online_cpus();
4247 for_each_online_cpu(cpu_id)
4248 last_cpu_id = cpu_id;
4249 ioc->cpu_msix_table_sz = last_cpu_id + 1;
4250 ioc->cpu_msix_table = kzalloc(ioc->cpu_msix_table_sz, GFP_KERNEL);
4251 ioc->reply_queue_count = 1;
4252 if (!ioc->cpu_msix_table) {
4253 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation for "
4254 "cpu_msix_table failed!!!\n", ioc->name));
4255 r = -ENOMEM;
4256 goto out_free_resources;
4257 }
4258
4259 if (ioc->is_warpdrive) {
4260 ioc->reply_post_host_index = kcalloc(ioc->cpu_msix_table_sz,
4261 sizeof(resource_size_t *), GFP_KERNEL);
4262 if (!ioc->reply_post_host_index) {
4263 dfailprintk(ioc, printk(MPT2SAS_INFO_FMT "allocation "
4264 "for cpu_msix_table failed!!!\n", ioc->name));
4265 r = -ENOMEM;
4266 goto out_free_resources;
4267 }
4268 }
4269
Eric Moore635374e2009-03-09 01:21:12 -06004270 r = mpt2sas_base_map_resources(ioc);
4271 if (r)
4272 return r;
4273
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304274 if (ioc->is_warpdrive) {
4275 ioc->reply_post_host_index[0] =
4276 (resource_size_t *)&ioc->chip->ReplyPostHostIndex;
4277
4278 for (i = 1; i < ioc->cpu_msix_table_sz; i++)
4279 ioc->reply_post_host_index[i] = (resource_size_t *)
4280 ((u8 *)&ioc->chip->Doorbell + (0x4000 + ((i - 1)
4281 * 4)));
4282 }
4283
Kashyap, Desaifcfe6392009-08-07 19:38:48 +05304284 pci_set_drvdata(ioc->pdev, ioc->shost);
Kashyap, Desai96b681c2009-09-23 17:32:06 +05304285 r = _base_get_ioc_facts(ioc, CAN_SLEEP);
Eric Moore635374e2009-03-09 01:21:12 -06004286 if (r)
4287 goto out_free_resources;
4288
Kashyap, Desai96b681c2009-09-23 17:32:06 +05304289 r = _base_make_ioc_ready(ioc, CAN_SLEEP, SOFT_RESET);
Eric Moore635374e2009-03-09 01:21:12 -06004290 if (r)
4291 goto out_free_resources;
4292
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304293 ioc->pfacts = kcalloc(ioc->facts.NumberOfPorts,
4294 sizeof(Mpi2PortFactsReply_t), GFP_KERNEL);
Kashyap, Desaif6aee7b2010-03-17 16:26:48 +05304295 if (!ioc->pfacts) {
4296 r = -ENOMEM;
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304297 goto out_free_resources;
Kashyap, Desaif6aee7b2010-03-17 16:26:48 +05304298 }
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304299
4300 for (i = 0 ; i < ioc->facts.NumberOfPorts; i++) {
4301 r = _base_get_port_facts(ioc, i, CAN_SLEEP);
4302 if (r)
4303 goto out_free_resources;
4304 }
4305
Eric Moore635374e2009-03-09 01:21:12 -06004306 r = _base_allocate_memory_pools(ioc, CAN_SLEEP);
4307 if (r)
4308 goto out_free_resources;
4309
4310 init_waitqueue_head(&ioc->reset_wq);
4311
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05304312 /* allocate memory pd handle bitmask list */
4313 ioc->pd_handles_sz = (ioc->facts.MaxDevHandle / 8);
4314 if (ioc->facts.MaxDevHandle % 8)
4315 ioc->pd_handles_sz++;
4316 ioc->pd_handles = kzalloc(ioc->pd_handles_sz,
4317 GFP_KERNEL);
Kashyap, Desai3e2e8332010-06-17 13:47:29 +05304318 if (!ioc->pd_handles) {
4319 r = -ENOMEM;
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05304320 goto out_free_resources;
Kashyap, Desai3e2e8332010-06-17 13:47:29 +05304321 }
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05304322
Kashyap, Desaie75b9b62009-12-16 18:52:39 +05304323 ioc->fwfault_debug = mpt2sas_fwfault_debug;
4324
Eric Moore635374e2009-03-09 01:21:12 -06004325 /* base internal command bits */
4326 mutex_init(&ioc->base_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06004327 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4328 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4329
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05304330 /* port_enable command bits */
4331 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4332 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4333
Eric Moore635374e2009-03-09 01:21:12 -06004334 /* transport internal command bits */
4335 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4336 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
4337 mutex_init(&ioc->transport_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06004338
Kashyap, Desaid685c262009-11-17 13:16:37 +05304339 /* scsih internal command bits */
4340 ioc->scsih_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4341 ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
4342 mutex_init(&ioc->scsih_cmds.mutex);
4343
Eric Moore635374e2009-03-09 01:21:12 -06004344 /* task management internal command bits */
4345 ioc->tm_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4346 ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
4347 mutex_init(&ioc->tm_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06004348
4349 /* config page internal command bits */
4350 ioc->config_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4351 ioc->config_cmds.status = MPT2_CMD_NOT_USED;
4352 mutex_init(&ioc->config_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06004353
4354 /* ctl module internal command bits */
4355 ioc->ctl_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
Kashyap, Desai769578f2010-06-17 13:49:28 +05304356 ioc->ctl_cmds.sense = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
Eric Moore635374e2009-03-09 01:21:12 -06004357 ioc->ctl_cmds.status = MPT2_CMD_NOT_USED;
4358 mutex_init(&ioc->ctl_cmds.mutex);
Eric Moore635374e2009-03-09 01:21:12 -06004359
Kashyap, Desaif6aee7b2010-03-17 16:26:48 +05304360 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4361 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
Kashyap, Desai769578f2010-06-17 13:49:28 +05304362 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply ||
4363 !ioc->ctl_cmds.sense) {
Kashyap, Desaif6aee7b2010-03-17 16:26:48 +05304364 r = -ENOMEM;
4365 goto out_free_resources;
4366 }
4367
Kashyap, Desai3e2e8332010-06-17 13:47:29 +05304368 if (!ioc->base_cmds.reply || !ioc->transport_cmds.reply ||
4369 !ioc->scsih_cmds.reply || !ioc->tm_cmds.reply ||
4370 !ioc->config_cmds.reply || !ioc->ctl_cmds.reply) {
4371 r = -ENOMEM;
4372 goto out_free_resources;
4373 }
4374
Eric Moore635374e2009-03-09 01:21:12 -06004375 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4376 ioc->event_masks[i] = -1;
4377
4378 /* here we enable the events we care about */
4379 _base_unmask_events(ioc, MPI2_EVENT_SAS_DISCOVERY);
4380 _base_unmask_events(ioc, MPI2_EVENT_SAS_BROADCAST_PRIMITIVE);
4381 _base_unmask_events(ioc, MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
4382 _base_unmask_events(ioc, MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
4383 _base_unmask_events(ioc, MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE);
4384 _base_unmask_events(ioc, MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST);
4385 _base_unmask_events(ioc, MPI2_EVENT_IR_VOLUME);
4386 _base_unmask_events(ioc, MPI2_EVENT_IR_PHYSICAL_DISK);
4387 _base_unmask_events(ioc, MPI2_EVENT_IR_OPERATION_STATUS);
Eric Moore635374e2009-03-09 01:21:12 -06004388 _base_unmask_events(ioc, MPI2_EVENT_LOG_ENTRY_ADDED);
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304389 r = _base_make_ioc_operational(ioc, CAN_SLEEP);
Eric Moore635374e2009-03-09 01:21:12 -06004390 if (r)
4391 goto out_free_resources;
4392
Kashyap, Desai6cb8ef52010-11-13 04:32:18 +05304393 if (missing_delay[0] != -1 && missing_delay[1] != -1)
4394 _base_update_missing_delay(ioc, missing_delay[0],
4395 missing_delay[1]);
4396
Eric Moore635374e2009-03-09 01:21:12 -06004397 return 0;
4398
4399 out_free_resources:
4400
4401 ioc->remove_host = 1;
4402 mpt2sas_base_free_resources(ioc);
4403 _base_release_memory_pools(ioc);
Kashyap, Desaifcfe6392009-08-07 19:38:48 +05304404 pci_set_drvdata(ioc->pdev, NULL);
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304405 kfree(ioc->cpu_msix_table);
4406 if (ioc->is_warpdrive)
4407 kfree(ioc->reply_post_host_index);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05304408 kfree(ioc->pd_handles);
Eric Moore635374e2009-03-09 01:21:12 -06004409 kfree(ioc->tm_cmds.reply);
4410 kfree(ioc->transport_cmds.reply);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304411 kfree(ioc->scsih_cmds.reply);
Eric Moore635374e2009-03-09 01:21:12 -06004412 kfree(ioc->config_cmds.reply);
4413 kfree(ioc->base_cmds.reply);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05304414 kfree(ioc->port_enable_cmds.reply);
Eric Moore635374e2009-03-09 01:21:12 -06004415 kfree(ioc->ctl_cmds.reply);
Kashyap, Desai769578f2010-06-17 13:49:28 +05304416 kfree(ioc->ctl_cmds.sense);
Eric Moore635374e2009-03-09 01:21:12 -06004417 kfree(ioc->pfacts);
4418 ioc->ctl_cmds.reply = NULL;
4419 ioc->base_cmds.reply = NULL;
4420 ioc->tm_cmds.reply = NULL;
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304421 ioc->scsih_cmds.reply = NULL;
Eric Moore635374e2009-03-09 01:21:12 -06004422 ioc->transport_cmds.reply = NULL;
4423 ioc->config_cmds.reply = NULL;
4424 ioc->pfacts = NULL;
4425 return r;
4426}
4427
4428
4429/**
4430 * mpt2sas_base_detach - remove controller instance
4431 * @ioc: per adapter object
4432 *
4433 * Return nothing.
4434 */
4435void
4436mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4437{
Eric Moore635374e2009-03-09 01:21:12 -06004438
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304439 dexitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06004440 __func__));
4441
Kashyap, Desaie4750c92009-08-07 19:37:59 +05304442 mpt2sas_base_stop_watchdog(ioc);
Eric Moore635374e2009-03-09 01:21:12 -06004443 mpt2sas_base_free_resources(ioc);
4444 _base_release_memory_pools(ioc);
Kashyap, Desaifcfe6392009-08-07 19:38:48 +05304445 pci_set_drvdata(ioc->pdev, NULL);
nagalakshmi.nandigama@lsi.com911ae942011-09-08 06:18:50 +05304446 kfree(ioc->cpu_msix_table);
4447 if (ioc->is_warpdrive)
4448 kfree(ioc->reply_post_host_index);
Kashyap, Desaif3eedd62010-06-17 13:46:13 +05304449 kfree(ioc->pd_handles);
Eric Moore635374e2009-03-09 01:21:12 -06004450 kfree(ioc->pfacts);
4451 kfree(ioc->ctl_cmds.reply);
Kashyap, Desai769578f2010-06-17 13:49:28 +05304452 kfree(ioc->ctl_cmds.sense);
Eric Moore635374e2009-03-09 01:21:12 -06004453 kfree(ioc->base_cmds.reply);
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05304454 kfree(ioc->port_enable_cmds.reply);
Eric Moore635374e2009-03-09 01:21:12 -06004455 kfree(ioc->tm_cmds.reply);
4456 kfree(ioc->transport_cmds.reply);
Kashyap, Desaie94f6742010-03-17 16:24:52 +05304457 kfree(ioc->scsih_cmds.reply);
Eric Moore635374e2009-03-09 01:21:12 -06004458 kfree(ioc->config_cmds.reply);
4459}
4460
4461/**
4462 * _base_reset_handler - reset callback handler (for base)
4463 * @ioc: per adapter object
4464 * @reset_phase: phase
4465 *
4466 * The handler for doing any required cleanup or initialization.
4467 *
4468 * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
4469 * MPT2_IOC_DONE_RESET
4470 *
4471 * Return nothing.
4472 */
4473static void
4474_base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4475{
Kashyap, Desai42244892011-01-04 11:38:39 +05304476 mpt2sas_scsih_reset_handler(ioc, reset_phase);
4477 mpt2sas_ctl_reset_handler(ioc, reset_phase);
Eric Moore635374e2009-03-09 01:21:12 -06004478 switch (reset_phase) {
4479 case MPT2_IOC_PRE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304480 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore635374e2009-03-09 01:21:12 -06004481 "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
4482 break;
4483 case MPT2_IOC_AFTER_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304484 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore635374e2009-03-09 01:21:12 -06004485 "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
4486 if (ioc->transport_cmds.status & MPT2_CMD_PENDING) {
4487 ioc->transport_cmds.status |= MPT2_CMD_RESET;
4488 mpt2sas_base_free_smid(ioc, ioc->transport_cmds.smid);
4489 complete(&ioc->transport_cmds.done);
4490 }
4491 if (ioc->base_cmds.status & MPT2_CMD_PENDING) {
4492 ioc->base_cmds.status |= MPT2_CMD_RESET;
4493 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4494 complete(&ioc->base_cmds.done);
4495 }
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05304496 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4497 ioc->port_enable_failed = 1;
4498 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4499 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4500 if (ioc->is_driver_loading) {
4501 ioc->start_scan_failed =
4502 MPI2_IOCSTATUS_INTERNAL_ERROR;
4503 ioc->start_scan = 0;
4504 ioc->port_enable_cmds.status =
4505 MPT2_CMD_NOT_USED;
4506 } else
4507 complete(&ioc->port_enable_cmds.done);
4508
4509 }
Eric Moore635374e2009-03-09 01:21:12 -06004510 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4511 ioc->config_cmds.status |= MPT2_CMD_RESET;
4512 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07004513 ioc->config_cmds.smid = USHRT_MAX;
Eric Moore635374e2009-03-09 01:21:12 -06004514 complete(&ioc->config_cmds.done);
4515 }
4516 break;
4517 case MPT2_IOC_DONE_RESET:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304518 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
Eric Moore635374e2009-03-09 01:21:12 -06004519 "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
4520 break;
4521 }
Eric Moore635374e2009-03-09 01:21:12 -06004522}
4523
4524/**
4525 * _wait_for_commands_to_complete - reset controller
4526 * @ioc: Pointer to MPT_ADAPTER structure
4527 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4528 *
4529 * This function waiting(3s) for all pending commands to complete
4530 * prior to putting controller in reset.
4531 */
4532static void
4533_wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
4534{
4535 u32 ioc_state;
4536 unsigned long flags;
4537 u16 i;
4538
4539 ioc->pending_io_count = 0;
4540 if (sleep_flag != CAN_SLEEP)
4541 return;
4542
4543 ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
4544 if ((ioc_state & MPI2_IOC_STATE_MASK) != MPI2_IOC_STATE_OPERATIONAL)
4545 return;
4546
4547 /* pending command count */
4548 spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
Kashyap, Desai595bb0b2009-09-14 11:02:48 +05304549 for (i = 0; i < ioc->scsiio_depth; i++)
Eric Moore635374e2009-03-09 01:21:12 -06004550 if (ioc->scsi_lookup[i].cb_idx != 0xFF)
4551 ioc->pending_io_count++;
4552 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
4553
4554 if (!ioc->pending_io_count)
4555 return;
4556
4557 /* wait for pending commands to complete */
Kashyap, Desaid2742132010-06-17 13:28:55 +05304558 wait_event_timeout(ioc->reset_wq, ioc->pending_io_count == 0, 10 * HZ);
Eric Moore635374e2009-03-09 01:21:12 -06004559}
4560
4561/**
4562 * mpt2sas_base_hard_reset_handler - reset controller
4563 * @ioc: Pointer to MPT_ADAPTER structure
4564 * @sleep_flag: CAN_SLEEP or NO_SLEEP
4565 * @type: FORCE_BIG_HAMMER or SOFT_RESET
4566 *
4567 * Returns 0 for success, non-zero for failure.
4568 */
4569int
4570mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4571 enum reset_type type)
4572{
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304573 int r;
Eric Moore635374e2009-03-09 01:21:12 -06004574 unsigned long flags;
4575
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304576 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
Eric Moore635374e2009-03-09 01:21:12 -06004577 __func__));
4578
Eric Moore3cb54692010-07-08 14:44:34 -06004579 if (ioc->pci_error_recovery) {
4580 printk(MPT2SAS_ERR_FMT "%s: pci error recovery reset\n",
4581 ioc->name, __func__);
4582 r = 0;
4583 goto out;
4584 }
4585
Kashyap, Desaifa7f3162009-09-23 17:26:58 +05304586 if (mpt2sas_fwfault_debug)
4587 mpt2sas_halt_firmware(ioc);
4588
Kashyap, Desaid2742132010-06-17 13:28:55 +05304589 /* TODO - What we really should be doing is pulling
4590 * out all the code associated with NO_SLEEP; its never used.
4591 * That is legacy code from mpt fusion driver, ported over.
4592 * I will leave this BUG_ON here for now till its been resolved.
4593 */
4594 BUG_ON(sleep_flag == NO_SLEEP);
4595
4596 /* wait for an active reset in progress to complete */
4597 if (!mutex_trylock(&ioc->reset_in_progress_mutex)) {
4598 do {
4599 ssleep(1);
4600 } while (ioc->shost_recovery == 1);
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304601 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
Kashyap, Desaid2742132010-06-17 13:28:55 +05304602 __func__));
4603 return ioc->ioc_reset_in_progress_status;
Eric Moore635374e2009-03-09 01:21:12 -06004604 }
Kashyap, Desaid2742132010-06-17 13:28:55 +05304605
4606 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
Eric Moore635374e2009-03-09 01:21:12 -06004607 ioc->shost_recovery = 1;
Eric Moore635374e2009-03-09 01:21:12 -06004608 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4609
4610 _base_reset_handler(ioc, MPT2_IOC_PRE_RESET);
4611 _wait_for_commands_to_complete(ioc, sleep_flag);
4612 _base_mask_interrupts(ioc);
4613 r = _base_make_ioc_ready(ioc, sleep_flag, type);
4614 if (r)
4615 goto out;
4616 _base_reset_handler(ioc, MPT2_IOC_AFTER_RESET);
Kashyap, Desai42244892011-01-04 11:38:39 +05304617
4618 /* If this hard reset is called while port enable is active, then
4619 * there is no reason to call make_ioc_operational
4620 */
nagalakshmi.nandigama@lsi.com921cd802011-10-19 15:36:26 +05304621 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4622 ioc->remove_host = 1;
Kashyap, Desai42244892011-01-04 11:38:39 +05304623 r = -EFAULT;
4624 goto out;
4625 }
Kashyap, Desai7b936b02009-09-25 11:44:41 +05304626 r = _base_make_ioc_operational(ioc, sleep_flag);
Eric Moore635374e2009-03-09 01:21:12 -06004627 if (!r)
4628 _base_reset_handler(ioc, MPT2_IOC_DONE_RESET);
4629 out:
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304630 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %s\n",
Eric Moore635374e2009-03-09 01:21:12 -06004631 ioc->name, __func__, ((r == 0) ? "SUCCESS" : "FAILED")));
4632
4633 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
Kashyap, Desaid2742132010-06-17 13:28:55 +05304634 ioc->ioc_reset_in_progress_status = r;
Kashyap, Desai155dd4c2009-08-20 13:22:00 +05304635 ioc->shost_recovery = 0;
Eric Moore635374e2009-03-09 01:21:12 -06004636 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
Kashyap, Desaid2742132010-06-17 13:28:55 +05304637 mutex_unlock(&ioc->reset_in_progress_mutex);
Kashyap, Desaicd4e12e2009-08-20 13:20:54 +05304638
Kashyap, Desaieabb08a2010-06-17 13:43:57 +05304639 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit\n", ioc->name,
Kashyap, Desaid2742132010-06-17 13:28:55 +05304640 __func__));
Eric Moore635374e2009-03-09 01:21:12 -06004641 return r;
4642}