1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Broadcom MPI3 Storage Controllers
5 * Copyright (C) 2017-2023 Broadcom Inc.
11 #include <linux/io-64-nonatomic-lo-hi.h>
14 mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type, u16 reset_reason);
15 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc);
16 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
17 struct mpi3_ioc_facts_data *facts_data);
18 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc *mrioc,
19 struct mpi3mr_drv_cmd *drv_cmd);
21 static int poll_queues;
22 module_param(poll_queues, int, 0444);
23 MODULE_PARM_DESC(poll_queues, "Number of queues for io_uring poll mode. (Range 1 - 126)");
25 #if defined(writeq) && defined(CONFIG_64BIT)
26 static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
31 static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
35 writel((u32)(data_out), addr);
36 writel((u32)(data_out >> 32), (addr + 4));
41 mpi3mr_check_req_qfull(struct op_req_qinfo *op_req_q)
43 u16 pi, ci, max_entries;
44 bool is_qfull = false;
47 ci = READ_ONCE(op_req_q->ci);
48 max_entries = op_req_q->num_requests;
50 if ((ci == (pi + 1)) || ((!ci) && (pi == (max_entries - 1))))
56 static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
60 max_vectors = mrioc->intr_info_count;
62 for (i = 0; i < max_vectors; i++)
63 synchronize_irq(pci_irq_vector(mrioc->pdev, i));
66 void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc)
68 mrioc->intr_enabled = 0;
69 mpi3mr_sync_irqs(mrioc);
72 void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc)
74 mrioc->intr_enabled = 1;
77 static void mpi3mr_cleanup_isr(struct mpi3mr_ioc *mrioc)
81 mpi3mr_ioc_disable_intr(mrioc);
83 if (!mrioc->intr_info)
86 for (i = 0; i < mrioc->intr_info_count; i++)
87 free_irq(pci_irq_vector(mrioc->pdev, i),
88 (mrioc->intr_info + i));
90 kfree(mrioc->intr_info);
91 mrioc->intr_info = NULL;
92 mrioc->intr_info_count = 0;
93 mrioc->is_intr_info_set = false;
94 pci_free_irq_vectors(mrioc->pdev);
97 void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
100 struct mpi3_sge_common *sgel = paddr;
103 sgel->length = cpu_to_le32(length);
104 sgel->address = cpu_to_le64(dma_addr);
107 void mpi3mr_build_zero_len_sge(void *paddr)
109 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
111 mpi3mr_add_sg_single(paddr, sgl_flags, 0, -1);
114 void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
115 dma_addr_t phys_addr)
120 if ((phys_addr < mrioc->reply_buf_dma) ||
121 (phys_addr > mrioc->reply_buf_dma_max_address))
124 return mrioc->reply_buf + (phys_addr - mrioc->reply_buf_dma);
127 void *mpi3mr_get_sensebuf_virt_addr(struct mpi3mr_ioc *mrioc,
128 dma_addr_t phys_addr)
133 return mrioc->sense_buf + (phys_addr - mrioc->sense_buf_dma);
136 static void mpi3mr_repost_reply_buf(struct mpi3mr_ioc *mrioc,
142 spin_lock_irqsave(&mrioc->reply_free_queue_lock, flags);
143 old_idx = mrioc->reply_free_queue_host_index;
144 mrioc->reply_free_queue_host_index = (
145 (mrioc->reply_free_queue_host_index ==
146 (mrioc->reply_free_qsz - 1)) ? 0 :
147 (mrioc->reply_free_queue_host_index + 1));
148 mrioc->reply_free_q[old_idx] = cpu_to_le64(reply_dma);
149 writel(mrioc->reply_free_queue_host_index,
150 &mrioc->sysif_regs->reply_free_host_index);
151 spin_unlock_irqrestore(&mrioc->reply_free_queue_lock, flags);
154 void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
160 spin_lock_irqsave(&mrioc->sbq_lock, flags);
161 old_idx = mrioc->sbq_host_index;
162 mrioc->sbq_host_index = ((mrioc->sbq_host_index ==
163 (mrioc->sense_buf_q_sz - 1)) ? 0 :
164 (mrioc->sbq_host_index + 1));
165 mrioc->sense_buf_q[old_idx] = cpu_to_le64(sense_buf_dma);
166 writel(mrioc->sbq_host_index,
167 &mrioc->sysif_regs->sense_buffer_free_host_index);
168 spin_unlock_irqrestore(&mrioc->sbq_lock, flags);
171 static void mpi3mr_print_event_data(struct mpi3mr_ioc *mrioc,
172 struct mpi3_event_notification_reply *event_reply)
177 event = event_reply->event;
180 case MPI3_EVENT_LOG_DATA:
183 case MPI3_EVENT_CHANGE:
184 desc = "Event Change";
186 case MPI3_EVENT_GPIO_INTERRUPT:
187 desc = "GPIO Interrupt";
189 case MPI3_EVENT_CABLE_MGMT:
190 desc = "Cable Management";
192 case MPI3_EVENT_ENERGY_PACK_CHANGE:
193 desc = "Energy Pack Change";
195 case MPI3_EVENT_DEVICE_ADDED:
197 struct mpi3_device_page0 *event_data =
198 (struct mpi3_device_page0 *)event_reply->event_data;
199 ioc_info(mrioc, "Device Added: dev=0x%04x Form=0x%x\n",
200 event_data->dev_handle, event_data->device_form);
203 case MPI3_EVENT_DEVICE_INFO_CHANGED:
205 struct mpi3_device_page0 *event_data =
206 (struct mpi3_device_page0 *)event_reply->event_data;
207 ioc_info(mrioc, "Device Info Changed: dev=0x%04x Form=0x%x\n",
208 event_data->dev_handle, event_data->device_form);
211 case MPI3_EVENT_DEVICE_STATUS_CHANGE:
213 struct mpi3_event_data_device_status_change *event_data =
214 (struct mpi3_event_data_device_status_change *)event_reply->event_data;
215 ioc_info(mrioc, "Device status Change: dev=0x%04x RC=0x%x\n",
216 event_data->dev_handle, event_data->reason_code);
219 case MPI3_EVENT_SAS_DISCOVERY:
221 struct mpi3_event_data_sas_discovery *event_data =
222 (struct mpi3_event_data_sas_discovery *)event_reply->event_data;
223 ioc_info(mrioc, "SAS Discovery: (%s) status (0x%08x)\n",
224 (event_data->reason_code == MPI3_EVENT_SAS_DISC_RC_STARTED) ?
226 le32_to_cpu(event_data->discovery_status));
229 case MPI3_EVENT_SAS_BROADCAST_PRIMITIVE:
230 desc = "SAS Broadcast Primitive";
232 case MPI3_EVENT_SAS_NOTIFY_PRIMITIVE:
233 desc = "SAS Notify Primitive";
235 case MPI3_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
236 desc = "SAS Init Device Status Change";
238 case MPI3_EVENT_SAS_INIT_TABLE_OVERFLOW:
239 desc = "SAS Init Table Overflow";
241 case MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
242 desc = "SAS Topology Change List";
244 case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE:
245 desc = "Enclosure Device Status Change";
247 case MPI3_EVENT_ENCL_DEVICE_ADDED:
248 desc = "Enclosure Added";
250 case MPI3_EVENT_HARD_RESET_RECEIVED:
251 desc = "Hard Reset Received";
253 case MPI3_EVENT_SAS_PHY_COUNTER:
254 desc = "SAS PHY Counter";
256 case MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
257 desc = "SAS Device Discovery Error";
259 case MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
260 desc = "PCIE Topology Change List";
262 case MPI3_EVENT_PCIE_ENUMERATION:
264 struct mpi3_event_data_pcie_enumeration *event_data =
265 (struct mpi3_event_data_pcie_enumeration *)event_reply->event_data;
266 ioc_info(mrioc, "PCIE Enumeration: (%s)",
267 (event_data->reason_code ==
268 MPI3_EVENT_PCIE_ENUM_RC_STARTED) ? "start" : "stop");
269 if (event_data->enumeration_status)
270 ioc_info(mrioc, "enumeration_status(0x%08x)\n",
271 le32_to_cpu(event_data->enumeration_status));
274 case MPI3_EVENT_PREPARE_FOR_RESET:
275 desc = "Prepare For Reset";
282 ioc_info(mrioc, "%s\n", desc);
285 static void mpi3mr_handle_events(struct mpi3mr_ioc *mrioc,
286 struct mpi3_default_reply *def_reply)
288 struct mpi3_event_notification_reply *event_reply =
289 (struct mpi3_event_notification_reply *)def_reply;
291 mrioc->change_count = le16_to_cpu(event_reply->ioc_change_count);
292 mpi3mr_print_event_data(mrioc, event_reply);
293 mpi3mr_os_handle_events(mrioc, event_reply);
296 static struct mpi3mr_drv_cmd *
297 mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
298 struct mpi3_default_reply *def_reply)
303 case MPI3MR_HOSTTAG_INITCMDS:
304 return &mrioc->init_cmds;
305 case MPI3MR_HOSTTAG_CFG_CMDS:
306 return &mrioc->cfg_cmds;
307 case MPI3MR_HOSTTAG_BSG_CMDS:
308 return &mrioc->bsg_cmds;
309 case MPI3MR_HOSTTAG_BLK_TMS:
310 return &mrioc->host_tm_cmds;
311 case MPI3MR_HOSTTAG_PEL_ABORT:
312 return &mrioc->pel_abort_cmd;
313 case MPI3MR_HOSTTAG_PEL_WAIT:
314 return &mrioc->pel_cmds;
315 case MPI3MR_HOSTTAG_TRANSPORT_CMDS:
316 return &mrioc->transport_cmds;
317 case MPI3MR_HOSTTAG_INVALID:
318 if (def_reply && def_reply->function ==
319 MPI3_FUNCTION_EVENT_NOTIFICATION)
320 mpi3mr_handle_events(mrioc, def_reply);
325 if (host_tag >= MPI3MR_HOSTTAG_DEVRMCMD_MIN &&
326 host_tag <= MPI3MR_HOSTTAG_DEVRMCMD_MAX) {
327 idx = host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
328 return &mrioc->dev_rmhs_cmds[idx];
331 if (host_tag >= MPI3MR_HOSTTAG_EVTACKCMD_MIN &&
332 host_tag <= MPI3MR_HOSTTAG_EVTACKCMD_MAX) {
333 idx = host_tag - MPI3MR_HOSTTAG_EVTACKCMD_MIN;
334 return &mrioc->evtack_cmds[idx];
340 static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc *mrioc,
341 struct mpi3_default_reply_descriptor *reply_desc, u64 *reply_dma)
343 u16 reply_desc_type, host_tag = 0;
344 u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
346 struct mpi3_status_reply_descriptor *status_desc;
347 struct mpi3_address_reply_descriptor *addr_desc;
348 struct mpi3_success_reply_descriptor *success_desc;
349 struct mpi3_default_reply *def_reply = NULL;
350 struct mpi3mr_drv_cmd *cmdptr = NULL;
351 struct mpi3_scsi_io_reply *scsi_reply;
352 u8 *sense_buf = NULL;
355 reply_desc_type = le16_to_cpu(reply_desc->reply_flags) &
356 MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK;
357 switch (reply_desc_type) {
358 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS:
359 status_desc = (struct mpi3_status_reply_descriptor *)reply_desc;
360 host_tag = le16_to_cpu(status_desc->host_tag);
361 ioc_status = le16_to_cpu(status_desc->ioc_status);
363 MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
364 ioc_loginfo = le32_to_cpu(status_desc->ioc_log_info);
365 ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
367 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
368 addr_desc = (struct mpi3_address_reply_descriptor *)reply_desc;
369 *reply_dma = le64_to_cpu(addr_desc->reply_frame_address);
370 def_reply = mpi3mr_get_reply_virt_addr(mrioc, *reply_dma);
373 host_tag = le16_to_cpu(def_reply->host_tag);
374 ioc_status = le16_to_cpu(def_reply->ioc_status);
376 MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
377 ioc_loginfo = le32_to_cpu(def_reply->ioc_log_info);
378 ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
379 if (def_reply->function == MPI3_FUNCTION_SCSI_IO) {
380 scsi_reply = (struct mpi3_scsi_io_reply *)def_reply;
381 sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
382 le64_to_cpu(scsi_reply->sense_data_buffer_address));
385 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
386 success_desc = (struct mpi3_success_reply_descriptor *)reply_desc;
387 host_tag = le16_to_cpu(success_desc->host_tag);
393 cmdptr = mpi3mr_get_drv_cmd(mrioc, host_tag, def_reply);
395 if (cmdptr->state & MPI3MR_CMD_PENDING) {
396 cmdptr->state |= MPI3MR_CMD_COMPLETE;
397 cmdptr->ioc_loginfo = ioc_loginfo;
398 cmdptr->ioc_status = ioc_status;
399 cmdptr->state &= ~MPI3MR_CMD_PENDING;
401 cmdptr->state |= MPI3MR_CMD_REPLY_VALID;
402 memcpy((u8 *)cmdptr->reply, (u8 *)def_reply,
405 if (sense_buf && cmdptr->sensebuf) {
406 cmdptr->is_sense = 1;
407 memcpy(cmdptr->sensebuf, sense_buf,
408 MPI3MR_SENSE_BUF_SZ);
410 if (cmdptr->is_waiting) {
411 complete(&cmdptr->done);
412 cmdptr->is_waiting = 0;
413 } else if (cmdptr->callback)
414 cmdptr->callback(mrioc, cmdptr);
419 mpi3mr_repost_sense_buf(mrioc,
420 le64_to_cpu(scsi_reply->sense_data_buffer_address));
423 int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
425 u32 exp_phase = mrioc->admin_reply_ephase;
426 u32 admin_reply_ci = mrioc->admin_reply_ci;
427 u32 num_admin_replies = 0;
429 struct mpi3_default_reply_descriptor *reply_desc;
431 if (!atomic_add_unless(&mrioc->admin_reply_q_in_use, 1, 1))
434 reply_desc = (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
437 if ((le16_to_cpu(reply_desc->reply_flags) &
438 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
439 atomic_dec(&mrioc->admin_reply_q_in_use);
444 if (mrioc->unrecoverable)
447 mrioc->admin_req_ci = le16_to_cpu(reply_desc->request_queue_ci);
448 mpi3mr_process_admin_reply_desc(mrioc, reply_desc, &reply_dma);
450 mpi3mr_repost_reply_buf(mrioc, reply_dma);
452 if (++admin_reply_ci == mrioc->num_admin_replies) {
457 (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
459 if ((le16_to_cpu(reply_desc->reply_flags) &
460 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
464 writel(admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
465 mrioc->admin_reply_ci = admin_reply_ci;
466 mrioc->admin_reply_ephase = exp_phase;
467 atomic_dec(&mrioc->admin_reply_q_in_use);
469 return num_admin_replies;
473 * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
474 * queue's consumer index from operational reply descriptor queue.
475 * @op_reply_q: op_reply_qinfo object
476 * @reply_ci: operational reply descriptor's queue consumer index
478 * Returns: reply descriptor frame address
480 static inline struct mpi3_default_reply_descriptor *
481 mpi3mr_get_reply_desc(struct op_reply_qinfo *op_reply_q, u32 reply_ci)
483 void *segment_base_addr;
484 struct segments *segments = op_reply_q->q_segments;
485 struct mpi3_default_reply_descriptor *reply_desc = NULL;
488 segments[reply_ci / op_reply_q->segment_qd].segment;
489 reply_desc = (struct mpi3_default_reply_descriptor *)segment_base_addr +
490 (reply_ci % op_reply_q->segment_qd);
495 * mpi3mr_process_op_reply_q - Operational reply queue handler
496 * @mrioc: Adapter instance reference
497 * @op_reply_q: Operational reply queue info
499 * Checks the specific operational reply queue and drains the
500 * reply queue entries until the queue is empty and process the
501 * individual reply descriptors.
503 * Return: 0 if queue is already processed,or number of reply
504 * descriptors processed.
506 int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
507 struct op_reply_qinfo *op_reply_q)
509 struct op_req_qinfo *op_req_q;
512 u32 num_op_reply = 0;
514 struct mpi3_default_reply_descriptor *reply_desc;
515 u16 req_q_idx = 0, reply_qidx;
517 reply_qidx = op_reply_q->qid - 1;
519 if (!atomic_add_unless(&op_reply_q->in_use, 1, 1))
522 exp_phase = op_reply_q->ephase;
523 reply_ci = op_reply_q->ci;
525 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
526 if ((le16_to_cpu(reply_desc->reply_flags) &
527 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
528 atomic_dec(&op_reply_q->in_use);
533 if (mrioc->unrecoverable)
536 req_q_idx = le16_to_cpu(reply_desc->request_queue_id) - 1;
537 op_req_q = &mrioc->req_qinfo[req_q_idx];
539 WRITE_ONCE(op_req_q->ci, le16_to_cpu(reply_desc->request_queue_ci));
540 mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
542 atomic_dec(&op_reply_q->pend_ios);
544 mpi3mr_repost_reply_buf(mrioc, reply_dma);
547 if (++reply_ci == op_reply_q->num_replies) {
552 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
554 if ((le16_to_cpu(reply_desc->reply_flags) &
555 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
557 #ifndef CONFIG_PREEMPT_RT
559 * Exit completion loop to avoid CPU lockup
560 * Ensure remaining completion happens from threaded ISR.
562 if (num_op_reply > mrioc->max_host_ios) {
563 op_reply_q->enable_irq_poll = true;
570 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].consumer_index);
571 op_reply_q->ci = reply_ci;
572 op_reply_q->ephase = exp_phase;
574 atomic_dec(&op_reply_q->in_use);
579 * mpi3mr_blk_mq_poll - Operational reply queue handler
580 * @shost: SCSI Host reference
581 * @queue_num: Request queue number (w.r.t OS it is hardware context number)
583 * Checks the specific operational reply queue and drains the
584 * reply queue entries until the queue is empty and process the
585 * individual reply descriptors.
587 * Return: 0 if queue is already processed,or number of reply
588 * descriptors processed.
590 int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
593 struct mpi3mr_ioc *mrioc;
595 mrioc = (struct mpi3mr_ioc *)shost->hostdata;
597 if ((mrioc->reset_in_progress || mrioc->prepare_for_reset ||
598 mrioc->unrecoverable))
601 num_entries = mpi3mr_process_op_reply_q(mrioc,
602 &mrioc->op_reply_qinfo[queue_num]);
607 static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
609 struct mpi3mr_intr_info *intr_info = privdata;
610 struct mpi3mr_ioc *mrioc;
612 u32 num_admin_replies = 0, num_op_reply = 0;
617 mrioc = intr_info->mrioc;
619 if (!mrioc->intr_enabled)
622 midx = intr_info->msix_index;
625 num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
626 if (intr_info->op_reply_q)
627 num_op_reply = mpi3mr_process_op_reply_q(mrioc,
628 intr_info->op_reply_q);
630 if (num_admin_replies || num_op_reply)
636 #ifndef CONFIG_PREEMPT_RT
638 static irqreturn_t mpi3mr_isr(int irq, void *privdata)
640 struct mpi3mr_intr_info *intr_info = privdata;
646 /* Call primary ISR routine */
647 ret = mpi3mr_isr_primary(irq, privdata);
650 * If more IOs are expected, schedule IRQ polling thread.
651 * Otherwise exit from ISR.
653 if (!intr_info->op_reply_q)
656 if (!intr_info->op_reply_q->enable_irq_poll ||
657 !atomic_read(&intr_info->op_reply_q->pend_ios))
660 disable_irq_nosync(intr_info->os_irq);
662 return IRQ_WAKE_THREAD;
666 * mpi3mr_isr_poll - Reply queue polling routine
668 * @privdata: Interrupt info
670 * poll for pending I/O completions in a loop until pending I/Os
671 * present or controller queue depth I/Os are processed.
673 * Return: IRQ_NONE or IRQ_HANDLED
675 static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
677 struct mpi3mr_intr_info *intr_info = privdata;
678 struct mpi3mr_ioc *mrioc;
680 u32 num_op_reply = 0;
682 if (!intr_info || !intr_info->op_reply_q)
685 mrioc = intr_info->mrioc;
686 midx = intr_info->msix_index;
688 /* Poll for pending IOs completions */
690 if (!mrioc->intr_enabled || mrioc->unrecoverable)
694 mpi3mr_process_admin_reply_q(mrioc);
695 if (intr_info->op_reply_q)
697 mpi3mr_process_op_reply_q(mrioc,
698 intr_info->op_reply_q);
700 usleep_range(MPI3MR_IRQ_POLL_SLEEP, 10 * MPI3MR_IRQ_POLL_SLEEP);
702 } while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
703 (num_op_reply < mrioc->max_host_ios));
705 intr_info->op_reply_q->enable_irq_poll = false;
706 enable_irq(intr_info->os_irq);
714 * mpi3mr_request_irq - Request IRQ and register ISR
715 * @mrioc: Adapter instance reference
716 * @index: IRQ vector index
718 * Request threaded ISR with primary ISR and secondary
720 * Return: 0 on success and non zero on failures.
722 static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index)
724 struct pci_dev *pdev = mrioc->pdev;
725 struct mpi3mr_intr_info *intr_info = mrioc->intr_info + index;
728 intr_info->mrioc = mrioc;
729 intr_info->msix_index = index;
730 intr_info->op_reply_q = NULL;
732 snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
733 mrioc->driver_name, mrioc->id, index);
735 #ifndef CONFIG_PREEMPT_RT
736 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr,
737 mpi3mr_isr_poll, IRQF_SHARED, intr_info->name, intr_info);
739 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr_primary,
740 NULL, IRQF_SHARED, intr_info->name, intr_info);
743 ioc_err(mrioc, "%s: Unable to allocate interrupt %d!\n",
744 intr_info->name, pci_irq_vector(pdev, index));
748 intr_info->os_irq = pci_irq_vector(pdev, index);
752 static void mpi3mr_calc_poll_queues(struct mpi3mr_ioc *mrioc, u16 max_vectors)
754 if (!mrioc->requested_poll_qcount)
757 /* Reserved for Admin and Default Queue */
758 if (max_vectors > 2 &&
759 (mrioc->requested_poll_qcount < max_vectors - 2)) {
761 "enabled polled queues (%d) msix (%d)\n",
762 mrioc->requested_poll_qcount, max_vectors);
765 "disabled polled queues (%d) msix (%d) because of no resources for default queue\n",
766 mrioc->requested_poll_qcount, max_vectors);
767 mrioc->requested_poll_qcount = 0;
772 * mpi3mr_setup_isr - Setup ISR for the controller
773 * @mrioc: Adapter instance reference
774 * @setup_one: Request one IRQ or more
776 * Allocate IRQ vectors and call mpi3mr_request_irq to setup ISR
778 * Return: 0 on success and non zero on failures.
780 static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
782 unsigned int irq_flags = PCI_IRQ_MSIX;
783 int max_vectors, min_vec;
786 struct irq_affinity desc = { .pre_vectors = 1, .post_vectors = 1 };
788 if (mrioc->is_intr_info_set)
791 mpi3mr_cleanup_isr(mrioc);
793 if (setup_one || reset_devices) {
795 retval = pci_alloc_irq_vectors(mrioc->pdev,
796 1, max_vectors, irq_flags);
798 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
804 min_t(int, mrioc->cpu_count + 1 +
805 mrioc->requested_poll_qcount, mrioc->msix_count);
807 mpi3mr_calc_poll_queues(mrioc, max_vectors);
810 "MSI-X vectors supported: %d, no of cores: %d,",
811 mrioc->msix_count, mrioc->cpu_count);
813 "MSI-x vectors requested: %d poll_queues %d\n",
814 max_vectors, mrioc->requested_poll_qcount);
816 desc.post_vectors = mrioc->requested_poll_qcount;
817 min_vec = desc.pre_vectors + desc.post_vectors;
818 irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
820 retval = pci_alloc_irq_vectors_affinity(mrioc->pdev,
821 min_vec, max_vectors, irq_flags, &desc);
824 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
831 * If only one MSI-x is allocated, then MSI-x 0 will be shared
832 * between Admin queue and operational queue
834 if (retval == min_vec)
835 mrioc->op_reply_q_offset = 0;
836 else if (retval != (max_vectors)) {
838 "allocated vectors (%d) are less than configured (%d)\n",
839 retval, max_vectors);
842 max_vectors = retval;
843 mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
845 mpi3mr_calc_poll_queues(mrioc, max_vectors);
849 mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info) * max_vectors,
851 if (!mrioc->intr_info) {
853 pci_free_irq_vectors(mrioc->pdev);
856 for (i = 0; i < max_vectors; i++) {
857 retval = mpi3mr_request_irq(mrioc, i);
859 mrioc->intr_info_count = i;
863 if (reset_devices || !setup_one)
864 mrioc->is_intr_info_set = true;
865 mrioc->intr_info_count = max_vectors;
866 mpi3mr_ioc_enable_intr(mrioc);
870 mpi3mr_cleanup_isr(mrioc);
875 static const struct {
876 enum mpi3mr_iocstate value;
879 { MRIOC_STATE_READY, "ready" },
880 { MRIOC_STATE_FAULT, "fault" },
881 { MRIOC_STATE_RESET, "reset" },
882 { MRIOC_STATE_BECOMING_READY, "becoming ready" },
883 { MRIOC_STATE_RESET_REQUESTED, "reset requested" },
884 { MRIOC_STATE_UNRECOVERABLE, "unrecoverable error" },
887 static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state)
892 for (i = 0; i < ARRAY_SIZE(mrioc_states); i++) {
893 if (mrioc_states[i].value == mrioc_state) {
894 name = mrioc_states[i].name;
901 /* Reset reason to name mapper structure*/
902 static const struct {
903 enum mpi3mr_reset_reason value;
905 } mpi3mr_reset_reason_codes[] = {
906 { MPI3MR_RESET_FROM_BRINGUP, "timeout in bringup" },
907 { MPI3MR_RESET_FROM_FAULT_WATCH, "fault" },
908 { MPI3MR_RESET_FROM_APP, "application invocation" },
909 { MPI3MR_RESET_FROM_EH_HOS, "error handling" },
910 { MPI3MR_RESET_FROM_TM_TIMEOUT, "TM timeout" },
911 { MPI3MR_RESET_FROM_APP_TIMEOUT, "application command timeout" },
912 { MPI3MR_RESET_FROM_MUR_FAILURE, "MUR failure" },
913 { MPI3MR_RESET_FROM_CTLR_CLEANUP, "timeout in controller cleanup" },
914 { MPI3MR_RESET_FROM_CIACTIV_FAULT, "component image activation fault" },
915 { MPI3MR_RESET_FROM_PE_TIMEOUT, "port enable timeout" },
916 { MPI3MR_RESET_FROM_TSU_TIMEOUT, "time stamp update timeout" },
917 { MPI3MR_RESET_FROM_DELREQQ_TIMEOUT, "delete request queue timeout" },
918 { MPI3MR_RESET_FROM_DELREPQ_TIMEOUT, "delete reply queue timeout" },
920 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT,
921 "create request queue timeout"
924 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT,
925 "create reply queue timeout"
927 { MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT, "IOC facts timeout" },
928 { MPI3MR_RESET_FROM_IOCINIT_TIMEOUT, "IOC init timeout" },
929 { MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT, "event notify timeout" },
930 { MPI3MR_RESET_FROM_EVTACK_TIMEOUT, "event acknowledgment timeout" },
932 MPI3MR_RESET_FROM_CIACTVRST_TIMER,
933 "component image activation timeout"
936 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT,
937 "get package version timeout"
939 { MPI3MR_RESET_FROM_SYSFS, "sysfs invocation" },
940 { MPI3MR_RESET_FROM_SYSFS_TIMEOUT, "sysfs TM timeout" },
941 { MPI3MR_RESET_FROM_FIRMWARE, "firmware asynchronous reset" },
942 { MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT, "configuration request timeout"},
943 { MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT, "timeout of a SAS transport layer request" },
947 * mpi3mr_reset_rc_name - get reset reason code name
948 * @reason_code: reset reason code value
950 * Map reset reason to an NULL terminated ASCII string
952 * Return: name corresponding to reset reason value or NULL.
954 static const char *mpi3mr_reset_rc_name(enum mpi3mr_reset_reason reason_code)
959 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_reason_codes); i++) {
960 if (mpi3mr_reset_reason_codes[i].value == reason_code) {
961 name = mpi3mr_reset_reason_codes[i].name;
968 /* Reset type to name mapper structure*/
969 static const struct {
972 } mpi3mr_reset_types[] = {
973 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, "soft" },
974 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, "diag fault" },
978 * mpi3mr_reset_type_name - get reset type name
979 * @reset_type: reset type value
981 * Map reset type to an NULL terminated ASCII string
983 * Return: name corresponding to reset type value or NULL.
985 static const char *mpi3mr_reset_type_name(u16 reset_type)
990 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_types); i++) {
991 if (mpi3mr_reset_types[i].reset_type == reset_type) {
992 name = mpi3mr_reset_types[i].name;
1000 * mpi3mr_print_fault_info - Display fault information
1001 * @mrioc: Adapter instance reference
1003 * Display the controller fault information if there is a
1008 void mpi3mr_print_fault_info(struct mpi3mr_ioc *mrioc)
1010 u32 ioc_status, code, code1, code2, code3;
1012 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1014 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1015 code = readl(&mrioc->sysif_regs->fault);
1016 code1 = readl(&mrioc->sysif_regs->fault_info[0]);
1017 code2 = readl(&mrioc->sysif_regs->fault_info[1]);
1018 code3 = readl(&mrioc->sysif_regs->fault_info[2]);
1021 "fault code(0x%08X): Additional code: (0x%08X:0x%08X:0x%08X)\n",
1022 code, code1, code2, code3);
1027 * mpi3mr_get_iocstate - Get IOC State
1028 * @mrioc: Adapter instance reference
1030 * Return a proper IOC state enum based on the IOC status and
1031 * IOC configuration and unrcoverable state of the controller.
1033 * Return: Current IOC state.
1035 enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc)
1037 u32 ioc_status, ioc_config;
1040 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1041 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1043 if (mrioc->unrecoverable)
1044 return MRIOC_STATE_UNRECOVERABLE;
1045 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)
1046 return MRIOC_STATE_FAULT;
1048 ready = (ioc_status & MPI3_SYSIF_IOC_STATUS_READY);
1049 enabled = (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC);
1051 if (ready && enabled)
1052 return MRIOC_STATE_READY;
1053 if ((!ready) && (!enabled))
1054 return MRIOC_STATE_RESET;
1055 if ((!ready) && (enabled))
1056 return MRIOC_STATE_BECOMING_READY;
1058 return MRIOC_STATE_RESET_REQUESTED;
1062 * mpi3mr_free_ioctl_dma_memory - free memory for ioctl dma
1063 * @mrioc: Adapter instance reference
1065 * Free the DMA memory allocated for IOCTL handling purpose.
1069 static void mpi3mr_free_ioctl_dma_memory(struct mpi3mr_ioc *mrioc)
1071 struct dma_memory_desc *mem_desc;
1074 if (!mrioc->ioctl_dma_pool)
1077 for (i = 0; i < MPI3MR_NUM_IOCTL_SGE; i++) {
1078 mem_desc = &mrioc->ioctl_sge[i];
1079 if (mem_desc->addr) {
1080 dma_pool_free(mrioc->ioctl_dma_pool,
1082 mem_desc->dma_addr);
1083 mem_desc->addr = NULL;
1086 dma_pool_destroy(mrioc->ioctl_dma_pool);
1087 mrioc->ioctl_dma_pool = NULL;
1088 mem_desc = &mrioc->ioctl_chain_sge;
1090 if (mem_desc->addr) {
1091 dma_free_coherent(&mrioc->pdev->dev, mem_desc->size,
1092 mem_desc->addr, mem_desc->dma_addr);
1093 mem_desc->addr = NULL;
1095 mem_desc = &mrioc->ioctl_resp_sge;
1096 if (mem_desc->addr) {
1097 dma_free_coherent(&mrioc->pdev->dev, mem_desc->size,
1098 mem_desc->addr, mem_desc->dma_addr);
1099 mem_desc->addr = NULL;
1102 mrioc->ioctl_sges_allocated = false;
1106 * mpi3mr_alloc_ioctl_dma_memory - Alloc memory for ioctl dma
1107 * @mrioc: Adapter instance reference
1109 * This function allocates dmaable memory required to handle the
1110 * application issued MPI3 IOCTL requests.
1114 static void mpi3mr_alloc_ioctl_dma_memory(struct mpi3mr_ioc *mrioc)
1117 struct dma_memory_desc *mem_desc;
1120 mrioc->ioctl_dma_pool = dma_pool_create("ioctl dma pool",
1122 MPI3MR_IOCTL_SGE_SIZE,
1123 MPI3MR_PAGE_SIZE_4K, 0);
1125 if (!mrioc->ioctl_dma_pool) {
1126 ioc_err(mrioc, "ioctl_dma_pool: dma_pool_create failed\n");
1130 for (i = 0; i < MPI3MR_NUM_IOCTL_SGE; i++) {
1131 mem_desc = &mrioc->ioctl_sge[i];
1132 mem_desc->size = MPI3MR_IOCTL_SGE_SIZE;
1133 mem_desc->addr = dma_pool_zalloc(mrioc->ioctl_dma_pool,
1135 &mem_desc->dma_addr);
1136 if (!mem_desc->addr)
1140 mem_desc = &mrioc->ioctl_chain_sge;
1141 mem_desc->size = MPI3MR_PAGE_SIZE_4K;
1142 mem_desc->addr = dma_alloc_coherent(&mrioc->pdev->dev,
1144 &mem_desc->dma_addr,
1146 if (!mem_desc->addr)
1149 mem_desc = &mrioc->ioctl_resp_sge;
1150 mem_desc->size = MPI3MR_PAGE_SIZE_4K;
1151 mem_desc->addr = dma_alloc_coherent(&mrioc->pdev->dev,
1153 &mem_desc->dma_addr,
1155 if (!mem_desc->addr)
1158 mrioc->ioctl_sges_allocated = true;
1162 ioc_warn(mrioc, "cannot allocate DMA memory for the mpt commands\n"
1163 "from the applications, application interface for MPT command is disabled\n");
1164 mpi3mr_free_ioctl_dma_memory(mrioc);
1168 * mpi3mr_clear_reset_history - clear reset history
1169 * @mrioc: Adapter instance reference
1171 * Write the reset history bit in IOC status to clear the bit,
1172 * if it is already set.
1176 static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc *mrioc)
1180 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1181 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1182 writel(ioc_status, &mrioc->sysif_regs->ioc_status);
1186 * mpi3mr_issue_and_process_mur - Message unit Reset handler
1187 * @mrioc: Adapter instance reference
1188 * @reset_reason: Reset reason code
1190 * Issue Message unit Reset to the controller and wait for it to
1193 * Return: 0 on success, -1 on failure.
1195 static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
1198 u32 ioc_config, timeout, ioc_status, scratch_pad0;
1201 ioc_info(mrioc, "Issuing Message unit Reset(MUR)\n");
1202 if (mrioc->unrecoverable) {
1203 ioc_info(mrioc, "IOC is unrecoverable MUR not issued\n");
1206 mpi3mr_clear_reset_history(mrioc);
1207 scratch_pad0 = ((MPI3MR_RESET_REASON_OSTYPE_LINUX <<
1208 MPI3MR_RESET_REASON_OSTYPE_SHIFT) |
1209 (mrioc->facts.ioc_num <<
1210 MPI3MR_RESET_REASON_IOCNUM_SHIFT) | reset_reason);
1211 writel(scratch_pad0, &mrioc->sysif_regs->scratchpad[0]);
1212 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1213 ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1214 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1216 timeout = MPI3MR_MUR_TIMEOUT * 10;
1218 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1219 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)) {
1220 mpi3mr_clear_reset_history(mrioc);
1223 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1224 mpi3mr_print_fault_info(mrioc);
1228 } while (--timeout);
1230 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1231 if (timeout && !((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1232 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
1233 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1236 ioc_info(mrioc, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
1237 (!retval) ? "successful" : "failed", ioc_status, ioc_config);
1242 * mpi3mr_revalidate_factsdata - validate IOCFacts parameters
1243 * during reset/resume
1244 * @mrioc: Adapter instance reference
1246 * Return: zero if the new IOCFacts parameters value is compatible with
1247 * older values else return -EPERM
1250 mpi3mr_revalidate_factsdata(struct mpi3mr_ioc *mrioc)
1252 unsigned long *removepend_bitmap;
1254 if (mrioc->facts.reply_sz > mrioc->reply_sz) {
1256 "cannot increase reply size from %d to %d\n",
1257 mrioc->reply_sz, mrioc->facts.reply_sz);
1261 if (mrioc->facts.max_op_reply_q < mrioc->num_op_reply_q) {
1263 "cannot reduce number of operational reply queues from %d to %d\n",
1264 mrioc->num_op_reply_q,
1265 mrioc->facts.max_op_reply_q);
1269 if (mrioc->facts.max_op_req_q < mrioc->num_op_req_q) {
1271 "cannot reduce number of operational request queues from %d to %d\n",
1272 mrioc->num_op_req_q, mrioc->facts.max_op_req_q);
1276 if (mrioc->shost->max_sectors != (mrioc->facts.max_data_length / 512))
1277 ioc_err(mrioc, "Warning: The maximum data transfer length\n"
1278 "\tchanged after reset: previous(%d), new(%d),\n"
1279 "the driver cannot change this at run time\n",
1280 mrioc->shost->max_sectors * 512, mrioc->facts.max_data_length);
1282 if ((mrioc->sas_transport_enabled) && (mrioc->facts.ioc_capabilities &
1283 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_SUPPORTED))
1285 "critical error: multipath capability is enabled at the\n"
1286 "\tcontroller while sas transport support is enabled at the\n"
1287 "\tdriver, please reboot the system or reload the driver\n");
1289 if (mrioc->facts.max_devhandle > mrioc->dev_handle_bitmap_bits) {
1290 removepend_bitmap = bitmap_zalloc(mrioc->facts.max_devhandle,
1292 if (!removepend_bitmap) {
1294 "failed to increase removepend_bitmap bits from %d to %d\n",
1295 mrioc->dev_handle_bitmap_bits,
1296 mrioc->facts.max_devhandle);
1299 bitmap_free(mrioc->removepend_bitmap);
1300 mrioc->removepend_bitmap = removepend_bitmap;
1302 "increased bits of dev_handle_bitmap from %d to %d\n",
1303 mrioc->dev_handle_bitmap_bits,
1304 mrioc->facts.max_devhandle);
1305 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
1312 * mpi3mr_bring_ioc_ready - Bring controller to ready state
1313 * @mrioc: Adapter instance reference
1315 * Set Enable IOC bit in IOC configuration register and wait for
1316 * the controller to become ready.
1318 * Return: 0 on success, appropriate error on failure.
1320 static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
1322 u32 ioc_config, ioc_status, timeout, host_diagnostic;
1324 enum mpi3mr_iocstate ioc_state;
1327 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1328 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1329 base_info = lo_hi_readq(&mrioc->sysif_regs->ioc_information);
1330 ioc_info(mrioc, "ioc_status(0x%08x), ioc_config(0x%08x), ioc_info(0x%016llx) at the bringup\n",
1331 ioc_status, ioc_config, base_info);
1333 /*The timeout value is in 2sec unit, changing it to seconds*/
1334 mrioc->ready_timeout =
1335 ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
1336 MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
1338 ioc_info(mrioc, "ready timeout: %d seconds\n", mrioc->ready_timeout);
1340 ioc_state = mpi3mr_get_iocstate(mrioc);
1341 ioc_info(mrioc, "controller is in %s state during detection\n",
1342 mpi3mr_iocstate_name(ioc_state));
1344 if (ioc_state == MRIOC_STATE_BECOMING_READY ||
1345 ioc_state == MRIOC_STATE_RESET_REQUESTED) {
1346 timeout = mrioc->ready_timeout * 10;
1349 } while (--timeout);
1351 if (!pci_device_is_present(mrioc->pdev)) {
1352 mrioc->unrecoverable = 1;
1354 "controller is not present while waiting to reset\n");
1356 goto out_device_not_present;
1359 ioc_state = mpi3mr_get_iocstate(mrioc);
1361 "controller is in %s state after waiting to reset\n",
1362 mpi3mr_iocstate_name(ioc_state));
1365 if (ioc_state == MRIOC_STATE_READY) {
1366 ioc_info(mrioc, "issuing message unit reset (MUR) to bring to reset state\n");
1367 retval = mpi3mr_issue_and_process_mur(mrioc,
1368 MPI3MR_RESET_FROM_BRINGUP);
1369 ioc_state = mpi3mr_get_iocstate(mrioc);
1372 "message unit reset failed with error %d current state %s\n",
1373 retval, mpi3mr_iocstate_name(ioc_state));
1375 if (ioc_state != MRIOC_STATE_RESET) {
1376 if (ioc_state == MRIOC_STATE_FAULT) {
1377 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
1378 mpi3mr_print_fault_info(mrioc);
1381 readl(&mrioc->sysif_regs->host_diagnostic);
1382 if (!(host_diagnostic &
1383 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
1385 if (!pci_device_is_present(mrioc->pdev)) {
1386 mrioc->unrecoverable = 1;
1387 ioc_err(mrioc, "controller is not present at the bringup\n");
1388 goto out_device_not_present;
1391 } while (--timeout);
1393 mpi3mr_print_fault_info(mrioc);
1394 ioc_info(mrioc, "issuing soft reset to bring to reset state\n");
1395 retval = mpi3mr_issue_reset(mrioc,
1396 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
1397 MPI3MR_RESET_FROM_BRINGUP);
1400 "soft reset failed with error %d\n", retval);
1404 ioc_state = mpi3mr_get_iocstate(mrioc);
1405 if (ioc_state != MRIOC_STATE_RESET) {
1407 "cannot bring controller to reset state, current state: %s\n",
1408 mpi3mr_iocstate_name(ioc_state));
1411 mpi3mr_clear_reset_history(mrioc);
1412 retval = mpi3mr_setup_admin_qpair(mrioc);
1414 ioc_err(mrioc, "failed to setup admin queues: error %d\n",
1419 ioc_info(mrioc, "bringing controller to ready state\n");
1420 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1421 ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1422 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1424 timeout = mrioc->ready_timeout * 10;
1426 ioc_state = mpi3mr_get_iocstate(mrioc);
1427 if (ioc_state == MRIOC_STATE_READY) {
1429 "successfully transitioned to %s state\n",
1430 mpi3mr_iocstate_name(ioc_state));
1433 if (!pci_device_is_present(mrioc->pdev)) {
1434 mrioc->unrecoverable = 1;
1436 "controller is not present at the bringup\n");
1438 goto out_device_not_present;
1441 } while (--timeout);
1444 ioc_state = mpi3mr_get_iocstate(mrioc);
1446 "failed to bring to ready state, current state: %s\n",
1447 mpi3mr_iocstate_name(ioc_state));
1448 out_device_not_present:
1453 * mpi3mr_soft_reset_success - Check softreset is success or not
1454 * @ioc_status: IOC status register value
1455 * @ioc_config: IOC config register value
1457 * Check whether the soft reset is successful or not based on
1458 * IOC status and IOC config register values.
1460 * Return: True when the soft reset is success, false otherwise.
1463 mpi3mr_soft_reset_success(u32 ioc_status, u32 ioc_config)
1465 if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1466 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1472 * mpi3mr_diagfault_success - Check diag fault is success or not
1473 * @mrioc: Adapter reference
1474 * @ioc_status: IOC status register value
1476 * Check whether the controller hit diag reset fault code.
1478 * Return: True when there is diag fault, false otherwise.
1480 static inline bool mpi3mr_diagfault_success(struct mpi3mr_ioc *mrioc,
1485 if (!(ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT))
1487 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
1488 if (fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET) {
1489 mpi3mr_print_fault_info(mrioc);
1496 * mpi3mr_set_diagsave - Set diag save bit for snapdump
1497 * @mrioc: Adapter reference
1499 * Set diag save bit in IOC configuration register to enable
1504 static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
1508 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1509 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE;
1510 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1514 * mpi3mr_issue_reset - Issue reset to the controller
1515 * @mrioc: Adapter reference
1516 * @reset_type: Reset type
1517 * @reset_reason: Reset reason code
1519 * Unlock the host diagnostic registers and write the specific
1520 * reset type to that, wait for reset acknowledgment from the
1521 * controller, if the reset is not successful retry for the
1522 * predefined number of times.
1524 * Return: 0 on success, non-zero on failure.
1526 static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
1530 u8 unlock_retry_count = 0;
1531 u32 host_diagnostic, ioc_status, ioc_config, scratch_pad0;
1532 u32 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
1534 if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
1535 (reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT))
1537 if (mrioc->unrecoverable)
1539 if (reset_reason == MPI3MR_RESET_FROM_FIRMWARE) {
1544 ioc_info(mrioc, "%s reset due to %s(0x%x)\n",
1545 mpi3mr_reset_type_name(reset_type),
1546 mpi3mr_reset_rc_name(reset_reason), reset_reason);
1548 mpi3mr_clear_reset_history(mrioc);
1551 "Write magic sequence to unlock host diag register (retry=%d)\n",
1552 ++unlock_retry_count);
1553 if (unlock_retry_count >= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT) {
1555 "%s reset failed due to unlock failure, host_diagnostic(0x%08x)\n",
1556 mpi3mr_reset_type_name(reset_type),
1558 mrioc->unrecoverable = 1;
1562 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH,
1563 &mrioc->sysif_regs->write_sequence);
1564 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST,
1565 &mrioc->sysif_regs->write_sequence);
1566 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1567 &mrioc->sysif_regs->write_sequence);
1568 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD,
1569 &mrioc->sysif_regs->write_sequence);
1570 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH,
1571 &mrioc->sysif_regs->write_sequence);
1572 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH,
1573 &mrioc->sysif_regs->write_sequence);
1574 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH,
1575 &mrioc->sysif_regs->write_sequence);
1576 usleep_range(1000, 1100);
1577 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
1579 "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
1580 unlock_retry_count, host_diagnostic);
1581 } while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
1583 scratch_pad0 = ((MPI3MR_RESET_REASON_OSTYPE_LINUX <<
1584 MPI3MR_RESET_REASON_OSTYPE_SHIFT) | (mrioc->facts.ioc_num <<
1585 MPI3MR_RESET_REASON_IOCNUM_SHIFT) | reset_reason);
1586 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1587 writel(host_diagnostic | reset_type,
1588 &mrioc->sysif_regs->host_diagnostic);
1589 switch (reset_type) {
1590 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET:
1592 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1594 readl(&mrioc->sysif_regs->ioc_configuration);
1595 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1596 && mpi3mr_soft_reset_success(ioc_status, ioc_config)
1598 mpi3mr_clear_reset_history(mrioc);
1603 } while (--timeout);
1604 mpi3mr_print_fault_info(mrioc);
1606 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT:
1608 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1609 if (mpi3mr_diagfault_success(mrioc, ioc_status)) {
1614 } while (--timeout);
1620 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1621 &mrioc->sysif_regs->write_sequence);
1623 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1624 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1626 "ioc_status/ioc_onfig after %s reset is (0x%x)/(0x%x)\n",
1627 (!retval)?"successful":"failed", ioc_status,
1630 mrioc->unrecoverable = 1;
1635 * mpi3mr_admin_request_post - Post request to admin queue
1636 * @mrioc: Adapter reference
1637 * @admin_req: MPI3 request
1638 * @admin_req_sz: Request size
1639 * @ignore_reset: Ignore reset in process
1641 * Post the MPI3 request into admin request queue and
1642 * inform the controller, if the queue is full return
1643 * appropriate error.
1645 * Return: 0 on success, non-zero on failure.
1647 int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
1648 u16 admin_req_sz, u8 ignore_reset)
1650 u16 areq_pi = 0, areq_ci = 0, max_entries = 0;
1652 unsigned long flags;
1655 if (mrioc->unrecoverable) {
1656 ioc_err(mrioc, "%s : Unrecoverable controller\n", __func__);
1660 spin_lock_irqsave(&mrioc->admin_req_lock, flags);
1661 areq_pi = mrioc->admin_req_pi;
1662 areq_ci = mrioc->admin_req_ci;
1663 max_entries = mrioc->num_admin_req;
1664 if ((areq_ci == (areq_pi + 1)) || ((!areq_ci) &&
1665 (areq_pi == (max_entries - 1)))) {
1666 ioc_err(mrioc, "AdminReqQ full condition detected\n");
1670 if (!ignore_reset && mrioc->reset_in_progress) {
1671 ioc_err(mrioc, "AdminReqQ submit reset in progress\n");
1675 areq_entry = (u8 *)mrioc->admin_req_base +
1676 (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
1677 memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
1678 memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
1680 if (++areq_pi == max_entries)
1682 mrioc->admin_req_pi = areq_pi;
1684 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
1687 spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
1693 * mpi3mr_free_op_req_q_segments - free request memory segments
1694 * @mrioc: Adapter instance reference
1695 * @q_idx: operational request queue index
1697 * Free memory segments allocated for operational request queue
1701 static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1705 struct segments *segments;
1707 segments = mrioc->req_qinfo[q_idx].q_segments;
1711 if (mrioc->enable_segqueue) {
1712 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1713 if (mrioc->req_qinfo[q_idx].q_segment_list) {
1714 dma_free_coherent(&mrioc->pdev->dev,
1715 MPI3MR_MAX_SEG_LIST_SIZE,
1716 mrioc->req_qinfo[q_idx].q_segment_list,
1717 mrioc->req_qinfo[q_idx].q_segment_list_dma);
1718 mrioc->req_qinfo[q_idx].q_segment_list = NULL;
1721 size = mrioc->req_qinfo[q_idx].segment_qd *
1722 mrioc->facts.op_req_sz;
1724 for (j = 0; j < mrioc->req_qinfo[q_idx].num_segments; j++) {
1725 if (!segments[j].segment)
1727 dma_free_coherent(&mrioc->pdev->dev,
1728 size, segments[j].segment, segments[j].segment_dma);
1729 segments[j].segment = NULL;
1731 kfree(mrioc->req_qinfo[q_idx].q_segments);
1732 mrioc->req_qinfo[q_idx].q_segments = NULL;
1733 mrioc->req_qinfo[q_idx].qid = 0;
1737 * mpi3mr_free_op_reply_q_segments - free reply memory segments
1738 * @mrioc: Adapter instance reference
1739 * @q_idx: operational reply queue index
1741 * Free memory segments allocated for operational reply queue
1745 static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1749 struct segments *segments;
1751 segments = mrioc->op_reply_qinfo[q_idx].q_segments;
1755 if (mrioc->enable_segqueue) {
1756 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1757 if (mrioc->op_reply_qinfo[q_idx].q_segment_list) {
1758 dma_free_coherent(&mrioc->pdev->dev,
1759 MPI3MR_MAX_SEG_LIST_SIZE,
1760 mrioc->op_reply_qinfo[q_idx].q_segment_list,
1761 mrioc->op_reply_qinfo[q_idx].q_segment_list_dma);
1762 mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
1765 size = mrioc->op_reply_qinfo[q_idx].segment_qd *
1766 mrioc->op_reply_desc_sz;
1768 for (j = 0; j < mrioc->op_reply_qinfo[q_idx].num_segments; j++) {
1769 if (!segments[j].segment)
1771 dma_free_coherent(&mrioc->pdev->dev,
1772 size, segments[j].segment, segments[j].segment_dma);
1773 segments[j].segment = NULL;
1776 kfree(mrioc->op_reply_qinfo[q_idx].q_segments);
1777 mrioc->op_reply_qinfo[q_idx].q_segments = NULL;
1778 mrioc->op_reply_qinfo[q_idx].qid = 0;
1782 * mpi3mr_delete_op_reply_q - delete operational reply queue
1783 * @mrioc: Adapter instance reference
1784 * @qidx: operational reply queue index
1786 * Delete operatinal reply queue by issuing MPI request
1787 * through admin queue.
1789 * Return: 0 on success, non-zero on failure.
1791 static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1793 struct mpi3_delete_reply_queue_request delq_req;
1794 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1796 u16 reply_qid = 0, midx;
1798 reply_qid = op_reply_q->qid;
1800 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1804 ioc_err(mrioc, "Issue DelRepQ: called with invalid ReqQID\n");
1808 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount-- :
1809 mrioc->active_poll_qcount--;
1811 memset(&delq_req, 0, sizeof(delq_req));
1812 mutex_lock(&mrioc->init_cmds.mutex);
1813 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1815 ioc_err(mrioc, "Issue DelRepQ: Init command is in use\n");
1816 mutex_unlock(&mrioc->init_cmds.mutex);
1819 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1820 mrioc->init_cmds.is_waiting = 1;
1821 mrioc->init_cmds.callback = NULL;
1822 delq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1823 delq_req.function = MPI3_FUNCTION_DELETE_REPLY_QUEUE;
1824 delq_req.queue_id = cpu_to_le16(reply_qid);
1826 init_completion(&mrioc->init_cmds.done);
1827 retval = mpi3mr_admin_request_post(mrioc, &delq_req, sizeof(delq_req),
1830 ioc_err(mrioc, "Issue DelRepQ: Admin Post failed\n");
1833 wait_for_completion_timeout(&mrioc->init_cmds.done,
1834 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1835 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1836 ioc_err(mrioc, "delete reply queue timed out\n");
1837 mpi3mr_check_rh_fault_ioc(mrioc,
1838 MPI3MR_RESET_FROM_DELREPQ_TIMEOUT);
1842 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1843 != MPI3_IOCSTATUS_SUCCESS) {
1845 "Issue DelRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1846 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1847 mrioc->init_cmds.ioc_loginfo);
1851 mrioc->intr_info[midx].op_reply_q = NULL;
1853 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1855 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1856 mutex_unlock(&mrioc->init_cmds.mutex);
1863 * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
1864 * @mrioc: Adapter instance reference
1865 * @qidx: request queue index
1867 * Allocate segmented memory pools for operational reply
1870 * Return: 0 on success, non-zero on failure.
1872 static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1874 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1876 u64 *q_segment_list_entry = NULL;
1877 struct segments *segments;
1879 if (mrioc->enable_segqueue) {
1880 op_reply_q->segment_qd =
1881 MPI3MR_OP_REP_Q_SEG_SIZE / mrioc->op_reply_desc_sz;
1883 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1885 op_reply_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1886 MPI3MR_MAX_SEG_LIST_SIZE, &op_reply_q->q_segment_list_dma,
1888 if (!op_reply_q->q_segment_list)
1890 q_segment_list_entry = (u64 *)op_reply_q->q_segment_list;
1892 op_reply_q->segment_qd = op_reply_q->num_replies;
1893 size = op_reply_q->num_replies * mrioc->op_reply_desc_sz;
1896 op_reply_q->num_segments = DIV_ROUND_UP(op_reply_q->num_replies,
1897 op_reply_q->segment_qd);
1899 op_reply_q->q_segments = kcalloc(op_reply_q->num_segments,
1900 sizeof(struct segments), GFP_KERNEL);
1901 if (!op_reply_q->q_segments)
1904 segments = op_reply_q->q_segments;
1905 for (i = 0; i < op_reply_q->num_segments; i++) {
1906 segments[i].segment =
1907 dma_alloc_coherent(&mrioc->pdev->dev,
1908 size, &segments[i].segment_dma, GFP_KERNEL);
1909 if (!segments[i].segment)
1911 if (mrioc->enable_segqueue)
1912 q_segment_list_entry[i] =
1913 (unsigned long)segments[i].segment_dma;
1920 * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
1921 * @mrioc: Adapter instance reference
1922 * @qidx: request queue index
1924 * Allocate segmented memory pools for operational request
1927 * Return: 0 on success, non-zero on failure.
1929 static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1931 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
1933 u64 *q_segment_list_entry = NULL;
1934 struct segments *segments;
1936 if (mrioc->enable_segqueue) {
1937 op_req_q->segment_qd =
1938 MPI3MR_OP_REQ_Q_SEG_SIZE / mrioc->facts.op_req_sz;
1940 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1942 op_req_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1943 MPI3MR_MAX_SEG_LIST_SIZE, &op_req_q->q_segment_list_dma,
1945 if (!op_req_q->q_segment_list)
1947 q_segment_list_entry = (u64 *)op_req_q->q_segment_list;
1950 op_req_q->segment_qd = op_req_q->num_requests;
1951 size = op_req_q->num_requests * mrioc->facts.op_req_sz;
1954 op_req_q->num_segments = DIV_ROUND_UP(op_req_q->num_requests,
1955 op_req_q->segment_qd);
1957 op_req_q->q_segments = kcalloc(op_req_q->num_segments,
1958 sizeof(struct segments), GFP_KERNEL);
1959 if (!op_req_q->q_segments)
1962 segments = op_req_q->q_segments;
1963 for (i = 0; i < op_req_q->num_segments; i++) {
1964 segments[i].segment =
1965 dma_alloc_coherent(&mrioc->pdev->dev,
1966 size, &segments[i].segment_dma, GFP_KERNEL);
1967 if (!segments[i].segment)
1969 if (mrioc->enable_segqueue)
1970 q_segment_list_entry[i] =
1971 (unsigned long)segments[i].segment_dma;
1978 * mpi3mr_create_op_reply_q - create operational reply queue
1979 * @mrioc: Adapter instance reference
1980 * @qidx: operational reply queue index
1982 * Create operatinal reply queue by issuing MPI request
1983 * through admin queue.
1985 * Return: 0 on success, non-zero on failure.
1987 static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1989 struct mpi3_create_reply_queue_request create_req;
1990 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1992 u16 reply_qid = 0, midx;
1994 reply_qid = op_reply_q->qid;
1996 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
2000 ioc_err(mrioc, "CreateRepQ: called for duplicate qid %d\n",
2006 reply_qid = qidx + 1;
2007 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
2008 if ((mrioc->pdev->device == MPI3_MFGPAGE_DEVID_SAS4116) &&
2009 !mrioc->pdev->revision)
2010 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD4K;
2012 op_reply_q->ephase = 1;
2013 atomic_set(&op_reply_q->pend_ios, 0);
2014 atomic_set(&op_reply_q->in_use, 0);
2015 op_reply_q->enable_irq_poll = false;
2017 if (!op_reply_q->q_segments) {
2018 retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
2020 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
2025 memset(&create_req, 0, sizeof(create_req));
2026 mutex_lock(&mrioc->init_cmds.mutex);
2027 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2029 ioc_err(mrioc, "CreateRepQ: Init command is in use\n");
2032 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2033 mrioc->init_cmds.is_waiting = 1;
2034 mrioc->init_cmds.callback = NULL;
2035 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2036 create_req.function = MPI3_FUNCTION_CREATE_REPLY_QUEUE;
2037 create_req.queue_id = cpu_to_le16(reply_qid);
2039 if (midx < (mrioc->intr_info_count - mrioc->requested_poll_qcount))
2040 op_reply_q->qtype = MPI3MR_DEFAULT_QUEUE;
2042 op_reply_q->qtype = MPI3MR_POLL_QUEUE;
2044 if (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) {
2046 MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE;
2047 create_req.msix_index =
2048 cpu_to_le16(mrioc->intr_info[midx].msix_index);
2050 create_req.msix_index = cpu_to_le16(mrioc->intr_info_count - 1);
2051 ioc_info(mrioc, "create reply queue(polled): for qid(%d), midx(%d)\n",
2053 if (!mrioc->active_poll_qcount)
2054 disable_irq_nosync(pci_irq_vector(mrioc->pdev,
2055 mrioc->intr_info_count - 1));
2058 if (mrioc->enable_segqueue) {
2060 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
2061 create_req.base_address = cpu_to_le64(
2062 op_reply_q->q_segment_list_dma);
2064 create_req.base_address = cpu_to_le64(
2065 op_reply_q->q_segments[0].segment_dma);
2067 create_req.size = cpu_to_le16(op_reply_q->num_replies);
2069 init_completion(&mrioc->init_cmds.done);
2070 retval = mpi3mr_admin_request_post(mrioc, &create_req,
2071 sizeof(create_req), 1);
2073 ioc_err(mrioc, "CreateRepQ: Admin Post failed\n");
2076 wait_for_completion_timeout(&mrioc->init_cmds.done,
2077 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2078 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2079 ioc_err(mrioc, "create reply queue timed out\n");
2080 mpi3mr_check_rh_fault_ioc(mrioc,
2081 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT);
2085 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2086 != MPI3_IOCSTATUS_SUCCESS) {
2088 "CreateRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2089 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2090 mrioc->init_cmds.ioc_loginfo);
2094 op_reply_q->qid = reply_qid;
2095 if (midx < mrioc->intr_info_count)
2096 mrioc->intr_info[midx].op_reply_q = op_reply_q;
2098 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount++ :
2099 mrioc->active_poll_qcount++;
2102 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2103 mutex_unlock(&mrioc->init_cmds.mutex);
2110 * mpi3mr_create_op_req_q - create operational request queue
2111 * @mrioc: Adapter instance reference
2112 * @idx: operational request queue index
2113 * @reply_qid: Reply queue ID
2115 * Create operatinal request queue by issuing MPI request
2116 * through admin queue.
2118 * Return: 0 on success, non-zero on failure.
2120 static int mpi3mr_create_op_req_q(struct mpi3mr_ioc *mrioc, u16 idx,
2123 struct mpi3_create_request_queue_request create_req;
2124 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + idx;
2128 req_qid = op_req_q->qid;
2132 ioc_err(mrioc, "CreateReqQ: called for duplicate qid %d\n",
2139 op_req_q->num_requests = MPI3MR_OP_REQ_Q_QD;
2142 op_req_q->reply_qid = reply_qid;
2143 spin_lock_init(&op_req_q->q_lock);
2145 if (!op_req_q->q_segments) {
2146 retval = mpi3mr_alloc_op_req_q_segments(mrioc, idx);
2148 mpi3mr_free_op_req_q_segments(mrioc, idx);
2153 memset(&create_req, 0, sizeof(create_req));
2154 mutex_lock(&mrioc->init_cmds.mutex);
2155 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2157 ioc_err(mrioc, "CreateReqQ: Init command is in use\n");
2160 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2161 mrioc->init_cmds.is_waiting = 1;
2162 mrioc->init_cmds.callback = NULL;
2163 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2164 create_req.function = MPI3_FUNCTION_CREATE_REQUEST_QUEUE;
2165 create_req.queue_id = cpu_to_le16(req_qid);
2166 if (mrioc->enable_segqueue) {
2168 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
2169 create_req.base_address = cpu_to_le64(
2170 op_req_q->q_segment_list_dma);
2172 create_req.base_address = cpu_to_le64(
2173 op_req_q->q_segments[0].segment_dma);
2174 create_req.reply_queue_id = cpu_to_le16(reply_qid);
2175 create_req.size = cpu_to_le16(op_req_q->num_requests);
2177 init_completion(&mrioc->init_cmds.done);
2178 retval = mpi3mr_admin_request_post(mrioc, &create_req,
2179 sizeof(create_req), 1);
2181 ioc_err(mrioc, "CreateReqQ: Admin Post failed\n");
2184 wait_for_completion_timeout(&mrioc->init_cmds.done,
2185 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2186 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2187 ioc_err(mrioc, "create request queue timed out\n");
2188 mpi3mr_check_rh_fault_ioc(mrioc,
2189 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT);
2193 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2194 != MPI3_IOCSTATUS_SUCCESS) {
2196 "CreateReqQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2197 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2198 mrioc->init_cmds.ioc_loginfo);
2202 op_req_q->qid = req_qid;
2205 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2206 mutex_unlock(&mrioc->init_cmds.mutex);
2213 * mpi3mr_create_op_queues - create operational queue pairs
2214 * @mrioc: Adapter instance reference
2216 * Allocate memory for operational queue meta data and call
2217 * create request and reply queue functions.
2219 * Return: 0 on success, non-zero on failures.
2221 static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
2224 u16 num_queues = 0, i = 0, msix_count_op_q = 1;
2226 num_queues = min_t(int, mrioc->facts.max_op_reply_q,
2227 mrioc->facts.max_op_req_q);
2230 mrioc->intr_info_count - mrioc->op_reply_q_offset;
2231 if (!mrioc->num_queues)
2232 mrioc->num_queues = min_t(int, num_queues, msix_count_op_q);
2234 * During reset set the num_queues to the number of queues
2235 * that was set before the reset.
2237 num_queues = mrioc->num_op_reply_q ?
2238 mrioc->num_op_reply_q : mrioc->num_queues;
2239 ioc_info(mrioc, "trying to create %d operational queue pairs\n",
2242 if (!mrioc->req_qinfo) {
2243 mrioc->req_qinfo = kcalloc(num_queues,
2244 sizeof(struct op_req_qinfo), GFP_KERNEL);
2245 if (!mrioc->req_qinfo) {
2250 mrioc->op_reply_qinfo = kzalloc(sizeof(struct op_reply_qinfo) *
2251 num_queues, GFP_KERNEL);
2252 if (!mrioc->op_reply_qinfo) {
2258 if (mrioc->enable_segqueue)
2260 "allocating operational queues through segmented queues\n");
2262 for (i = 0; i < num_queues; i++) {
2263 if (mpi3mr_create_op_reply_q(mrioc, i)) {
2264 ioc_err(mrioc, "Cannot create OP RepQ %d\n", i);
2267 if (mpi3mr_create_op_req_q(mrioc, i,
2268 mrioc->op_reply_qinfo[i].qid)) {
2269 ioc_err(mrioc, "Cannot create OP ReqQ %d\n", i);
2270 mpi3mr_delete_op_reply_q(mrioc, i);
2276 /* Not even one queue is created successfully*/
2280 mrioc->num_op_reply_q = mrioc->num_op_req_q = i;
2282 "successfully created %d operational queue pairs(default/polled) queue = (%d/%d)\n",
2283 mrioc->num_op_reply_q, mrioc->default_qcount,
2284 mrioc->active_poll_qcount);
2288 kfree(mrioc->req_qinfo);
2289 mrioc->req_qinfo = NULL;
2291 kfree(mrioc->op_reply_qinfo);
2292 mrioc->op_reply_qinfo = NULL;
2298 * mpi3mr_op_request_post - Post request to operational queue
2299 * @mrioc: Adapter reference
2300 * @op_req_q: Operational request queue info
2301 * @req: MPI3 request
2303 * Post the MPI3 request into operational request queue and
2304 * inform the controller, if the queue is full return
2305 * appropriate error.
2307 * Return: 0 on success, non-zero on failure.
2309 int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
2310 struct op_req_qinfo *op_req_q, u8 *req)
2312 u16 pi = 0, max_entries, reply_qidx = 0, midx;
2314 unsigned long flags;
2316 void *segment_base_addr;
2317 u16 req_sz = mrioc->facts.op_req_sz;
2318 struct segments *segments = op_req_q->q_segments;
2320 reply_qidx = op_req_q->reply_qid - 1;
2322 if (mrioc->unrecoverable)
2325 spin_lock_irqsave(&op_req_q->q_lock, flags);
2327 max_entries = op_req_q->num_requests;
2329 if (mpi3mr_check_req_qfull(op_req_q)) {
2330 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
2331 reply_qidx, mrioc->op_reply_q_offset);
2332 mpi3mr_process_op_reply_q(mrioc, mrioc->intr_info[midx].op_reply_q);
2334 if (mpi3mr_check_req_qfull(op_req_q)) {
2340 if (mrioc->reset_in_progress) {
2341 ioc_err(mrioc, "OpReqQ submit reset in progress\n");
2346 segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
2347 req_entry = (u8 *)segment_base_addr +
2348 ((pi % op_req_q->segment_qd) * req_sz);
2350 memset(req_entry, 0, req_sz);
2351 memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
2353 if (++pi == max_entries)
2357 #ifndef CONFIG_PREEMPT_RT
2358 if (atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios)
2359 > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT)
2360 mrioc->op_reply_qinfo[reply_qidx].enable_irq_poll = true;
2362 atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios);
2365 writel(op_req_q->pi,
2366 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].producer_index);
2369 spin_unlock_irqrestore(&op_req_q->q_lock, flags);
2374 * mpi3mr_check_rh_fault_ioc - check reset history and fault
2376 * @mrioc: Adapter instance reference
2377 * @reason_code: reason code for the fault.
2379 * This routine will save snapdump and fault the controller with
2380 * the given reason code if it is not already in the fault or
2381 * not asynchronosuly reset. This will be used to handle
2382 * initilaization time faults/resets/timeout as in those cases
2383 * immediate soft reset invocation is not required.
2387 void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code)
2389 u32 ioc_status, host_diagnostic, timeout;
2391 if (mrioc->unrecoverable) {
2392 ioc_err(mrioc, "controller is unrecoverable\n");
2396 if (!pci_device_is_present(mrioc->pdev)) {
2397 mrioc->unrecoverable = 1;
2398 ioc_err(mrioc, "controller is not present\n");
2402 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2403 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
2404 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
2405 mpi3mr_print_fault_info(mrioc);
2408 mpi3mr_set_diagsave(mrioc);
2409 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
2411 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
2413 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2414 if (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
2417 } while (--timeout);
2421 * mpi3mr_sync_timestamp - Issue time stamp sync request
2422 * @mrioc: Adapter reference
2424 * Issue IO unit control MPI request to synchornize firmware
2425 * timestamp with host time.
2427 * Return: 0 on success, non-zero on failure.
2429 static int mpi3mr_sync_timestamp(struct mpi3mr_ioc *mrioc)
2431 ktime_t current_time;
2432 struct mpi3_iounit_control_request iou_ctrl;
2435 memset(&iou_ctrl, 0, sizeof(iou_ctrl));
2436 mutex_lock(&mrioc->init_cmds.mutex);
2437 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2439 ioc_err(mrioc, "Issue IOUCTL time_stamp: command is in use\n");
2440 mutex_unlock(&mrioc->init_cmds.mutex);
2443 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2444 mrioc->init_cmds.is_waiting = 1;
2445 mrioc->init_cmds.callback = NULL;
2446 iou_ctrl.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2447 iou_ctrl.function = MPI3_FUNCTION_IO_UNIT_CONTROL;
2448 iou_ctrl.operation = MPI3_CTRL_OP_UPDATE_TIMESTAMP;
2449 current_time = ktime_get_real();
2450 iou_ctrl.param64[0] = cpu_to_le64(ktime_to_ms(current_time));
2452 init_completion(&mrioc->init_cmds.done);
2453 retval = mpi3mr_admin_request_post(mrioc, &iou_ctrl,
2454 sizeof(iou_ctrl), 0);
2456 ioc_err(mrioc, "Issue IOUCTL time_stamp: Admin Post failed\n");
2460 wait_for_completion_timeout(&mrioc->init_cmds.done,
2461 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2462 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2463 ioc_err(mrioc, "Issue IOUCTL time_stamp: command timed out\n");
2464 mrioc->init_cmds.is_waiting = 0;
2465 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
2466 mpi3mr_check_rh_fault_ioc(mrioc,
2467 MPI3MR_RESET_FROM_TSU_TIMEOUT);
2471 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2472 != MPI3_IOCSTATUS_SUCCESS) {
2474 "Issue IOUCTL time_stamp: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2475 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2476 mrioc->init_cmds.ioc_loginfo);
2482 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2483 mutex_unlock(&mrioc->init_cmds.mutex);
2490 * mpi3mr_print_pkg_ver - display controller fw package version
2491 * @mrioc: Adapter reference
2493 * Retrieve firmware package version from the component image
2494 * header of the controller flash and display it.
2496 * Return: 0 on success and non-zero on failure.
2498 static int mpi3mr_print_pkg_ver(struct mpi3mr_ioc *mrioc)
2500 struct mpi3_ci_upload_request ci_upload;
2503 dma_addr_t data_dma;
2504 struct mpi3_ci_manifest_mpi *manifest;
2505 u32 data_len = sizeof(struct mpi3_ci_manifest_mpi);
2506 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2508 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2513 memset(&ci_upload, 0, sizeof(ci_upload));
2514 mutex_lock(&mrioc->init_cmds.mutex);
2515 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2516 ioc_err(mrioc, "sending get package version failed due to command in use\n");
2517 mutex_unlock(&mrioc->init_cmds.mutex);
2520 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2521 mrioc->init_cmds.is_waiting = 1;
2522 mrioc->init_cmds.callback = NULL;
2523 ci_upload.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2524 ci_upload.function = MPI3_FUNCTION_CI_UPLOAD;
2525 ci_upload.msg_flags = MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY;
2526 ci_upload.signature1 = cpu_to_le32(MPI3_IMAGE_HEADER_SIGNATURE1_MANIFEST);
2527 ci_upload.image_offset = cpu_to_le32(MPI3_IMAGE_HEADER_SIZE);
2528 ci_upload.segment_size = cpu_to_le32(data_len);
2530 mpi3mr_add_sg_single(&ci_upload.sgl, sgl_flags, data_len,
2532 init_completion(&mrioc->init_cmds.done);
2533 retval = mpi3mr_admin_request_post(mrioc, &ci_upload,
2534 sizeof(ci_upload), 1);
2536 ioc_err(mrioc, "posting get package version failed\n");
2539 wait_for_completion_timeout(&mrioc->init_cmds.done,
2540 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2541 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2542 ioc_err(mrioc, "get package version timed out\n");
2543 mpi3mr_check_rh_fault_ioc(mrioc,
2544 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT);
2548 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2549 == MPI3_IOCSTATUS_SUCCESS) {
2550 manifest = (struct mpi3_ci_manifest_mpi *) data;
2551 if (manifest->manifest_type == MPI3_CI_MANIFEST_TYPE_MPI) {
2553 "firmware package version(%d.%d.%d.%d.%05d-%05d)\n",
2554 manifest->package_version.gen_major,
2555 manifest->package_version.gen_minor,
2556 manifest->package_version.phase_major,
2557 manifest->package_version.phase_minor,
2558 manifest->package_version.customer_id,
2559 manifest->package_version.build_num);
2564 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2565 mutex_unlock(&mrioc->init_cmds.mutex);
2569 dma_free_coherent(&mrioc->pdev->dev, data_len, data,
2575 * mpi3mr_watchdog_work - watchdog thread to monitor faults
2576 * @work: work struct
2578 * Watch dog work periodically executed (1 second interval) to
2579 * monitor firmware fault and to issue periodic timer sync to
2584 static void mpi3mr_watchdog_work(struct work_struct *work)
2586 struct mpi3mr_ioc *mrioc =
2587 container_of(work, struct mpi3mr_ioc, watchdog_work.work);
2588 unsigned long flags;
2589 enum mpi3mr_iocstate ioc_state;
2590 u32 fault, host_diagnostic, ioc_status;
2591 u16 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
2593 if (mrioc->reset_in_progress)
2596 if (!mrioc->unrecoverable && !pci_device_is_present(mrioc->pdev)) {
2597 ioc_err(mrioc, "watchdog could not detect the controller\n");
2598 mrioc->unrecoverable = 1;
2601 if (mrioc->unrecoverable) {
2603 "flush pending commands for unrecoverable controller\n");
2604 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
2608 if (mrioc->ts_update_counter++ >= MPI3MR_TSUPDATE_INTERVAL) {
2609 mrioc->ts_update_counter = 0;
2610 mpi3mr_sync_timestamp(mrioc);
2613 if ((mrioc->prepare_for_reset) &&
2614 ((mrioc->prepare_for_reset_timeout_counter++) >=
2615 MPI3MR_PREPARE_FOR_RESET_TIMEOUT)) {
2616 mpi3mr_soft_reset_handler(mrioc,
2617 MPI3MR_RESET_FROM_CIACTVRST_TIMER, 1);
2621 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2622 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
2623 mpi3mr_soft_reset_handler(mrioc, MPI3MR_RESET_FROM_FIRMWARE, 0);
2627 /*Check for fault state every one second and issue Soft reset*/
2628 ioc_state = mpi3mr_get_iocstate(mrioc);
2629 if (ioc_state != MRIOC_STATE_FAULT)
2632 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
2633 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2634 if (host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS) {
2635 if (!mrioc->diagsave_timeout) {
2636 mpi3mr_print_fault_info(mrioc);
2637 ioc_warn(mrioc, "diag save in progress\n");
2639 if ((mrioc->diagsave_timeout++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT)
2643 mpi3mr_print_fault_info(mrioc);
2644 mrioc->diagsave_timeout = 0;
2647 case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED:
2648 case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED:
2650 "controller requires system power cycle, marking controller as unrecoverable\n");
2651 mrioc->unrecoverable = 1;
2653 case MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS:
2655 case MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET:
2656 reset_reason = MPI3MR_RESET_FROM_CIACTIV_FAULT;
2661 mpi3mr_soft_reset_handler(mrioc, reset_reason, 0);
2665 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2666 if (mrioc->watchdog_work_q)
2667 queue_delayed_work(mrioc->watchdog_work_q,
2668 &mrioc->watchdog_work,
2669 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2670 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2675 * mpi3mr_start_watchdog - Start watchdog
2676 * @mrioc: Adapter instance reference
2678 * Create and start the watchdog thread to monitor controller
2683 void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc)
2685 if (mrioc->watchdog_work_q)
2688 INIT_DELAYED_WORK(&mrioc->watchdog_work, mpi3mr_watchdog_work);
2689 snprintf(mrioc->watchdog_work_q_name,
2690 sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
2692 mrioc->watchdog_work_q =
2693 create_singlethread_workqueue(mrioc->watchdog_work_q_name);
2694 if (!mrioc->watchdog_work_q) {
2695 ioc_err(mrioc, "%s: failed (line=%d)\n", __func__, __LINE__);
2699 if (mrioc->watchdog_work_q)
2700 queue_delayed_work(mrioc->watchdog_work_q,
2701 &mrioc->watchdog_work,
2702 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2706 * mpi3mr_stop_watchdog - Stop watchdog
2707 * @mrioc: Adapter instance reference
2709 * Stop the watchdog thread created to monitor controller
2714 void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc)
2716 unsigned long flags;
2717 struct workqueue_struct *wq;
2719 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2720 wq = mrioc->watchdog_work_q;
2721 mrioc->watchdog_work_q = NULL;
2722 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2724 if (!cancel_delayed_work_sync(&mrioc->watchdog_work))
2725 flush_workqueue(wq);
2726 destroy_workqueue(wq);
2731 * mpi3mr_setup_admin_qpair - Setup admin queue pair
2732 * @mrioc: Adapter instance reference
2734 * Allocate memory for admin queue pair if required and register
2735 * the admin queue with the controller.
2737 * Return: 0 on success, non-zero on failures.
2739 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
2742 u32 num_admin_entries = 0;
2744 mrioc->admin_req_q_sz = MPI3MR_ADMIN_REQ_Q_SIZE;
2745 mrioc->num_admin_req = mrioc->admin_req_q_sz /
2746 MPI3MR_ADMIN_REQ_FRAME_SZ;
2747 mrioc->admin_req_ci = mrioc->admin_req_pi = 0;
2749 mrioc->admin_reply_q_sz = MPI3MR_ADMIN_REPLY_Q_SIZE;
2750 mrioc->num_admin_replies = mrioc->admin_reply_q_sz /
2751 MPI3MR_ADMIN_REPLY_FRAME_SZ;
2752 mrioc->admin_reply_ci = 0;
2753 mrioc->admin_reply_ephase = 1;
2754 atomic_set(&mrioc->admin_reply_q_in_use, 0);
2756 if (!mrioc->admin_req_base) {
2757 mrioc->admin_req_base = dma_alloc_coherent(&mrioc->pdev->dev,
2758 mrioc->admin_req_q_sz, &mrioc->admin_req_dma, GFP_KERNEL);
2760 if (!mrioc->admin_req_base) {
2765 mrioc->admin_reply_base = dma_alloc_coherent(&mrioc->pdev->dev,
2766 mrioc->admin_reply_q_sz, &mrioc->admin_reply_dma,
2769 if (!mrioc->admin_reply_base) {
2775 num_admin_entries = (mrioc->num_admin_replies << 16) |
2776 (mrioc->num_admin_req);
2777 writel(num_admin_entries, &mrioc->sysif_regs->admin_queue_num_entries);
2778 mpi3mr_writeq(mrioc->admin_req_dma,
2779 &mrioc->sysif_regs->admin_request_queue_address);
2780 mpi3mr_writeq(mrioc->admin_reply_dma,
2781 &mrioc->sysif_regs->admin_reply_queue_address);
2782 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
2783 writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
2788 if (mrioc->admin_reply_base) {
2789 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
2790 mrioc->admin_reply_base, mrioc->admin_reply_dma);
2791 mrioc->admin_reply_base = NULL;
2793 if (mrioc->admin_req_base) {
2794 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
2795 mrioc->admin_req_base, mrioc->admin_req_dma);
2796 mrioc->admin_req_base = NULL;
2802 * mpi3mr_issue_iocfacts - Send IOC Facts
2803 * @mrioc: Adapter instance reference
2804 * @facts_data: Cached IOC facts data
2806 * Issue IOC Facts MPI request through admin queue and wait for
2807 * the completion of it or time out.
2809 * Return: 0 on success, non-zero on failures.
2811 static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc *mrioc,
2812 struct mpi3_ioc_facts_data *facts_data)
2814 struct mpi3_ioc_facts_request iocfacts_req;
2816 dma_addr_t data_dma;
2817 u32 data_len = sizeof(*facts_data);
2819 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2821 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2829 memset(&iocfacts_req, 0, sizeof(iocfacts_req));
2830 mutex_lock(&mrioc->init_cmds.mutex);
2831 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2833 ioc_err(mrioc, "Issue IOCFacts: Init command is in use\n");
2834 mutex_unlock(&mrioc->init_cmds.mutex);
2837 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2838 mrioc->init_cmds.is_waiting = 1;
2839 mrioc->init_cmds.callback = NULL;
2840 iocfacts_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2841 iocfacts_req.function = MPI3_FUNCTION_IOC_FACTS;
2843 mpi3mr_add_sg_single(&iocfacts_req.sgl, sgl_flags, data_len,
2846 init_completion(&mrioc->init_cmds.done);
2847 retval = mpi3mr_admin_request_post(mrioc, &iocfacts_req,
2848 sizeof(iocfacts_req), 1);
2850 ioc_err(mrioc, "Issue IOCFacts: Admin Post failed\n");
2853 wait_for_completion_timeout(&mrioc->init_cmds.done,
2854 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2855 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2856 ioc_err(mrioc, "ioc_facts timed out\n");
2857 mpi3mr_check_rh_fault_ioc(mrioc,
2858 MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT);
2862 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2863 != MPI3_IOCSTATUS_SUCCESS) {
2865 "Issue IOCFacts: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2866 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2867 mrioc->init_cmds.ioc_loginfo);
2871 memcpy(facts_data, (u8 *)data, data_len);
2872 mpi3mr_process_factsdata(mrioc, facts_data);
2874 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2875 mutex_unlock(&mrioc->init_cmds.mutex);
2879 dma_free_coherent(&mrioc->pdev->dev, data_len, data, data_dma);
2885 * mpi3mr_check_reset_dma_mask - Process IOC facts data
2886 * @mrioc: Adapter instance reference
2888 * Check whether the new DMA mask requested through IOCFacts by
2889 * firmware needs to be set, if so set it .
2891 * Return: 0 on success, non-zero on failure.
2893 static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc *mrioc)
2895 struct pci_dev *pdev = mrioc->pdev;
2897 u64 facts_dma_mask = DMA_BIT_MASK(mrioc->facts.dma_mask);
2899 if (!mrioc->facts.dma_mask || (mrioc->dma_mask <= facts_dma_mask))
2902 ioc_info(mrioc, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
2903 mrioc->dma_mask, facts_dma_mask);
2905 r = dma_set_mask_and_coherent(&pdev->dev, facts_dma_mask);
2907 ioc_err(mrioc, "Setting DMA mask to 0x%016llx failed: %d\n",
2911 mrioc->dma_mask = facts_dma_mask;
2916 * mpi3mr_process_factsdata - Process IOC facts data
2917 * @mrioc: Adapter instance reference
2918 * @facts_data: Cached IOC facts data
2920 * Convert IOC facts data into cpu endianness and cache it in
2925 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
2926 struct mpi3_ioc_facts_data *facts_data)
2928 u32 ioc_config, req_sz, facts_flags;
2930 if ((le16_to_cpu(facts_data->ioc_facts_data_length)) !=
2931 (sizeof(*facts_data) / 4)) {
2933 "IOCFactsdata length mismatch driver_sz(%zu) firmware_sz(%d)\n",
2934 sizeof(*facts_data),
2935 le16_to_cpu(facts_data->ioc_facts_data_length) * 4);
2938 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
2939 req_sz = 1 << ((ioc_config & MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ) >>
2940 MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT);
2941 if (le16_to_cpu(facts_data->ioc_request_frame_size) != (req_sz / 4)) {
2943 "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
2944 req_sz / 4, le16_to_cpu(facts_data->ioc_request_frame_size));
2947 memset(&mrioc->facts, 0, sizeof(mrioc->facts));
2949 facts_flags = le32_to_cpu(facts_data->flags);
2950 mrioc->facts.op_req_sz = req_sz;
2951 mrioc->op_reply_desc_sz = 1 << ((ioc_config &
2952 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ) >>
2953 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT);
2955 mrioc->facts.ioc_num = facts_data->ioc_number;
2956 mrioc->facts.who_init = facts_data->who_init;
2957 mrioc->facts.max_msix_vectors = le16_to_cpu(facts_data->max_msix_vectors);
2958 mrioc->facts.personality = (facts_flags &
2959 MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK);
2960 mrioc->facts.dma_mask = (facts_flags &
2961 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
2962 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
2963 mrioc->facts.protocol_flags = facts_data->protocol_flags;
2964 mrioc->facts.mpi_version = le32_to_cpu(facts_data->mpi_version.word);
2965 mrioc->facts.max_reqs = le16_to_cpu(facts_data->max_outstanding_requests);
2966 mrioc->facts.product_id = le16_to_cpu(facts_data->product_id);
2967 mrioc->facts.reply_sz = le16_to_cpu(facts_data->reply_frame_size) * 4;
2968 mrioc->facts.exceptions = le16_to_cpu(facts_data->ioc_exceptions);
2969 mrioc->facts.max_perids = le16_to_cpu(facts_data->max_persistent_id);
2970 mrioc->facts.max_vds = le16_to_cpu(facts_data->max_vds);
2971 mrioc->facts.max_hpds = le16_to_cpu(facts_data->max_host_pds);
2972 mrioc->facts.max_advhpds = le16_to_cpu(facts_data->max_adv_host_pds);
2973 mrioc->facts.max_raid_pds = le16_to_cpu(facts_data->max_raid_pds);
2974 mrioc->facts.max_nvme = le16_to_cpu(facts_data->max_nvme);
2975 mrioc->facts.max_pcie_switches =
2976 le16_to_cpu(facts_data->max_pcie_switches);
2977 mrioc->facts.max_sasexpanders =
2978 le16_to_cpu(facts_data->max_sas_expanders);
2979 mrioc->facts.max_data_length = le16_to_cpu(facts_data->max_data_length);
2980 mrioc->facts.max_sasinitiators =
2981 le16_to_cpu(facts_data->max_sas_initiators);
2982 mrioc->facts.max_enclosures = le16_to_cpu(facts_data->max_enclosures);
2983 mrioc->facts.min_devhandle = le16_to_cpu(facts_data->min_dev_handle);
2984 mrioc->facts.max_devhandle = le16_to_cpu(facts_data->max_dev_handle);
2985 mrioc->facts.max_op_req_q =
2986 le16_to_cpu(facts_data->max_operational_request_queues);
2987 mrioc->facts.max_op_reply_q =
2988 le16_to_cpu(facts_data->max_operational_reply_queues);
2989 mrioc->facts.ioc_capabilities =
2990 le32_to_cpu(facts_data->ioc_capabilities);
2991 mrioc->facts.fw_ver.build_num =
2992 le16_to_cpu(facts_data->fw_version.build_num);
2993 mrioc->facts.fw_ver.cust_id =
2994 le16_to_cpu(facts_data->fw_version.customer_id);
2995 mrioc->facts.fw_ver.ph_minor = facts_data->fw_version.phase_minor;
2996 mrioc->facts.fw_ver.ph_major = facts_data->fw_version.phase_major;
2997 mrioc->facts.fw_ver.gen_minor = facts_data->fw_version.gen_minor;
2998 mrioc->facts.fw_ver.gen_major = facts_data->fw_version.gen_major;
2999 mrioc->msix_count = min_t(int, mrioc->msix_count,
3000 mrioc->facts.max_msix_vectors);
3001 mrioc->facts.sge_mod_mask = facts_data->sge_modifier_mask;
3002 mrioc->facts.sge_mod_value = facts_data->sge_modifier_value;
3003 mrioc->facts.sge_mod_shift = facts_data->sge_modifier_shift;
3004 mrioc->facts.shutdown_timeout =
3005 le16_to_cpu(facts_data->shutdown_timeout);
3007 mrioc->facts.max_dev_per_tg =
3008 facts_data->max_devices_per_throttle_group;
3009 mrioc->facts.io_throttle_data_length =
3010 le16_to_cpu(facts_data->io_throttle_data_length);
3011 mrioc->facts.max_io_throttle_group =
3012 le16_to_cpu(facts_data->max_io_throttle_group);
3013 mrioc->facts.io_throttle_low = le16_to_cpu(facts_data->io_throttle_low);
3014 mrioc->facts.io_throttle_high =
3015 le16_to_cpu(facts_data->io_throttle_high);
3017 if (mrioc->facts.max_data_length ==
3018 MPI3_IOCFACTS_MAX_DATA_LENGTH_NOT_REPORTED)
3019 mrioc->facts.max_data_length = MPI3MR_DEFAULT_MAX_IO_SIZE;
3021 mrioc->facts.max_data_length *= MPI3MR_PAGE_SIZE_4K;
3022 /* Store in 512b block count */
3023 if (mrioc->facts.io_throttle_data_length)
3024 mrioc->io_throttle_data_length =
3025 (mrioc->facts.io_throttle_data_length * 2 * 4);
3027 /* set the length to 1MB + 1K to disable throttle */
3028 mrioc->io_throttle_data_length = (mrioc->facts.max_data_length / 512) + 2;
3030 mrioc->io_throttle_high = (mrioc->facts.io_throttle_high * 2 * 1024);
3031 mrioc->io_throttle_low = (mrioc->facts.io_throttle_low * 2 * 1024);
3033 ioc_info(mrioc, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
3034 mrioc->facts.ioc_num, mrioc->facts.max_op_req_q,
3035 mrioc->facts.max_op_reply_q, mrioc->facts.max_devhandle);
3037 "maxreqs(%d), mindh(%d) maxvectors(%d) maxperids(%d)\n",
3038 mrioc->facts.max_reqs, mrioc->facts.min_devhandle,
3039 mrioc->facts.max_msix_vectors, mrioc->facts.max_perids);
3040 ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
3041 mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value,
3042 mrioc->facts.sge_mod_shift);
3043 ioc_info(mrioc, "DMA mask %d InitialPE status 0x%x max_data_len (%d)\n",
3044 mrioc->facts.dma_mask, (facts_flags &
3045 MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK), mrioc->facts.max_data_length);
3047 "max_dev_per_throttle_group(%d), max_throttle_groups(%d)\n",
3048 mrioc->facts.max_dev_per_tg, mrioc->facts.max_io_throttle_group);
3050 "io_throttle_data_len(%dKiB), io_throttle_high(%dMiB), io_throttle_low(%dMiB)\n",
3051 mrioc->facts.io_throttle_data_length * 4,
3052 mrioc->facts.io_throttle_high, mrioc->facts.io_throttle_low);
3056 * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
3057 * @mrioc: Adapter instance reference
3059 * Allocate and initialize the reply free buffers, sense
3060 * buffers, reply free queue and sense buffer queue.
3062 * Return: 0 on success, non-zero on failures.
3064 static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
3069 if (mrioc->init_cmds.reply)
3072 mrioc->init_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3073 if (!mrioc->init_cmds.reply)
3076 mrioc->bsg_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3077 if (!mrioc->bsg_cmds.reply)
3080 mrioc->transport_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3081 if (!mrioc->transport_cmds.reply)
3084 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
3085 mrioc->dev_rmhs_cmds[i].reply = kzalloc(mrioc->reply_sz,
3087 if (!mrioc->dev_rmhs_cmds[i].reply)
3091 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
3092 mrioc->evtack_cmds[i].reply = kzalloc(mrioc->reply_sz,
3094 if (!mrioc->evtack_cmds[i].reply)
3098 mrioc->host_tm_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3099 if (!mrioc->host_tm_cmds.reply)
3102 mrioc->pel_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3103 if (!mrioc->pel_cmds.reply)
3106 mrioc->pel_abort_cmd.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3107 if (!mrioc->pel_abort_cmd.reply)
3110 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
3111 mrioc->removepend_bitmap = bitmap_zalloc(mrioc->dev_handle_bitmap_bits,
3113 if (!mrioc->removepend_bitmap)
3116 mrioc->devrem_bitmap = bitmap_zalloc(MPI3MR_NUM_DEVRMCMD, GFP_KERNEL);
3117 if (!mrioc->devrem_bitmap)
3120 mrioc->evtack_cmds_bitmap = bitmap_zalloc(MPI3MR_NUM_EVTACKCMD,
3122 if (!mrioc->evtack_cmds_bitmap)
3125 mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
3126 mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
3127 mrioc->num_sense_bufs = mrioc->facts.max_reqs / MPI3MR_SENSEBUF_FACTOR;
3128 mrioc->sense_buf_q_sz = mrioc->num_sense_bufs + 1;
3130 /* reply buffer pool, 16 byte align */
3131 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3132 mrioc->reply_buf_pool = dma_pool_create("reply_buf pool",
3133 &mrioc->pdev->dev, sz, 16, 0);
3134 if (!mrioc->reply_buf_pool) {
3135 ioc_err(mrioc, "reply buf pool: dma_pool_create failed\n");
3139 mrioc->reply_buf = dma_pool_zalloc(mrioc->reply_buf_pool, GFP_KERNEL,
3140 &mrioc->reply_buf_dma);
3141 if (!mrioc->reply_buf)
3144 mrioc->reply_buf_dma_max_address = mrioc->reply_buf_dma + sz;
3146 /* reply free queue, 8 byte align */
3147 sz = mrioc->reply_free_qsz * 8;
3148 mrioc->reply_free_q_pool = dma_pool_create("reply_free_q pool",
3149 &mrioc->pdev->dev, sz, 8, 0);
3150 if (!mrioc->reply_free_q_pool) {
3151 ioc_err(mrioc, "reply_free_q pool: dma_pool_create failed\n");
3154 mrioc->reply_free_q = dma_pool_zalloc(mrioc->reply_free_q_pool,
3155 GFP_KERNEL, &mrioc->reply_free_q_dma);
3156 if (!mrioc->reply_free_q)
3159 /* sense buffer pool, 4 byte align */
3160 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3161 mrioc->sense_buf_pool = dma_pool_create("sense_buf pool",
3162 &mrioc->pdev->dev, sz, 4, 0);
3163 if (!mrioc->sense_buf_pool) {
3164 ioc_err(mrioc, "sense_buf pool: dma_pool_create failed\n");
3167 mrioc->sense_buf = dma_pool_zalloc(mrioc->sense_buf_pool, GFP_KERNEL,
3168 &mrioc->sense_buf_dma);
3169 if (!mrioc->sense_buf)
3172 /* sense buffer queue, 8 byte align */
3173 sz = mrioc->sense_buf_q_sz * 8;
3174 mrioc->sense_buf_q_pool = dma_pool_create("sense_buf_q pool",
3175 &mrioc->pdev->dev, sz, 8, 0);
3176 if (!mrioc->sense_buf_q_pool) {
3177 ioc_err(mrioc, "sense_buf_q pool: dma_pool_create failed\n");
3180 mrioc->sense_buf_q = dma_pool_zalloc(mrioc->sense_buf_q_pool,
3181 GFP_KERNEL, &mrioc->sense_buf_q_dma);
3182 if (!mrioc->sense_buf_q)
3193 * mpimr_initialize_reply_sbuf_queues - initialize reply sense
3195 * @mrioc: Adapter instance reference
3197 * Helper function to initialize reply and sense buffers along
3198 * with some debug prints.
3202 static void mpimr_initialize_reply_sbuf_queues(struct mpi3mr_ioc *mrioc)
3205 dma_addr_t phy_addr;
3207 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3209 "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3210 mrioc->reply_buf, mrioc->num_reply_bufs, mrioc->reply_sz,
3211 (sz / 1024), (unsigned long long)mrioc->reply_buf_dma);
3212 sz = mrioc->reply_free_qsz * 8;
3214 "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3215 mrioc->reply_free_q, mrioc->reply_free_qsz, 8, (sz / 1024),
3216 (unsigned long long)mrioc->reply_free_q_dma);
3217 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3219 "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3220 mrioc->sense_buf, mrioc->num_sense_bufs, MPI3MR_SENSE_BUF_SZ,
3221 (sz / 1024), (unsigned long long)mrioc->sense_buf_dma);
3222 sz = mrioc->sense_buf_q_sz * 8;
3224 "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3225 mrioc->sense_buf_q, mrioc->sense_buf_q_sz, 8, (sz / 1024),
3226 (unsigned long long)mrioc->sense_buf_q_dma);
3228 /* initialize Reply buffer Queue */
3229 for (i = 0, phy_addr = mrioc->reply_buf_dma;
3230 i < mrioc->num_reply_bufs; i++, phy_addr += mrioc->reply_sz)
3231 mrioc->reply_free_q[i] = cpu_to_le64(phy_addr);
3232 mrioc->reply_free_q[i] = cpu_to_le64(0);
3234 /* initialize Sense Buffer Queue */
3235 for (i = 0, phy_addr = mrioc->sense_buf_dma;
3236 i < mrioc->num_sense_bufs; i++, phy_addr += MPI3MR_SENSE_BUF_SZ)
3237 mrioc->sense_buf_q[i] = cpu_to_le64(phy_addr);
3238 mrioc->sense_buf_q[i] = cpu_to_le64(0);
3242 * mpi3mr_issue_iocinit - Send IOC Init
3243 * @mrioc: Adapter instance reference
3245 * Issue IOC Init MPI request through admin queue and wait for
3246 * the completion of it or time out.
3248 * Return: 0 on success, non-zero on failures.
3250 static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
3252 struct mpi3_ioc_init_request iocinit_req;
3253 struct mpi3_driver_info_layout *drv_info;
3254 dma_addr_t data_dma;
3255 u32 data_len = sizeof(*drv_info);
3257 ktime_t current_time;
3259 drv_info = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
3265 mpimr_initialize_reply_sbuf_queues(mrioc);
3267 drv_info->information_length = cpu_to_le32(data_len);
3268 strscpy(drv_info->driver_signature, "Broadcom", sizeof(drv_info->driver_signature));
3269 strscpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));
3270 strscpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));
3271 strscpy(drv_info->driver_name, MPI3MR_DRIVER_NAME, sizeof(drv_info->driver_name));
3272 strscpy(drv_info->driver_version, MPI3MR_DRIVER_VERSION, sizeof(drv_info->driver_version));
3273 strscpy(drv_info->driver_release_date, MPI3MR_DRIVER_RELDATE,
3274 sizeof(drv_info->driver_release_date));
3275 drv_info->driver_capabilities = 0;
3276 memcpy((u8 *)&mrioc->driver_info, (u8 *)drv_info,
3277 sizeof(mrioc->driver_info));
3279 memset(&iocinit_req, 0, sizeof(iocinit_req));
3280 mutex_lock(&mrioc->init_cmds.mutex);
3281 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3283 ioc_err(mrioc, "Issue IOCInit: Init command is in use\n");
3284 mutex_unlock(&mrioc->init_cmds.mutex);
3287 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3288 mrioc->init_cmds.is_waiting = 1;
3289 mrioc->init_cmds.callback = NULL;
3290 iocinit_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3291 iocinit_req.function = MPI3_FUNCTION_IOC_INIT;
3292 iocinit_req.mpi_version.mpi3_version.dev = MPI3_VERSION_DEV;
3293 iocinit_req.mpi_version.mpi3_version.unit = MPI3_VERSION_UNIT;
3294 iocinit_req.mpi_version.mpi3_version.major = MPI3_VERSION_MAJOR;
3295 iocinit_req.mpi_version.mpi3_version.minor = MPI3_VERSION_MINOR;
3296 iocinit_req.who_init = MPI3_WHOINIT_HOST_DRIVER;
3297 iocinit_req.reply_free_queue_depth = cpu_to_le16(mrioc->reply_free_qsz);
3298 iocinit_req.reply_free_queue_address =
3299 cpu_to_le64(mrioc->reply_free_q_dma);
3300 iocinit_req.sense_buffer_length = cpu_to_le16(MPI3MR_SENSE_BUF_SZ);
3301 iocinit_req.sense_buffer_free_queue_depth =
3302 cpu_to_le16(mrioc->sense_buf_q_sz);
3303 iocinit_req.sense_buffer_free_queue_address =
3304 cpu_to_le64(mrioc->sense_buf_q_dma);
3305 iocinit_req.driver_information_address = cpu_to_le64(data_dma);
3307 current_time = ktime_get_real();
3308 iocinit_req.time_stamp = cpu_to_le64(ktime_to_ms(current_time));
3310 iocinit_req.msg_flags |=
3311 MPI3_IOCINIT_MSGFLAGS_SCSIIOSTATUSREPLY_SUPPORTED;
3312 iocinit_req.msg_flags |=
3313 MPI3_IOCINIT_MSGFLAGS_WRITESAMEDIVERT_SUPPORTED;
3315 init_completion(&mrioc->init_cmds.done);
3316 retval = mpi3mr_admin_request_post(mrioc, &iocinit_req,
3317 sizeof(iocinit_req), 1);
3319 ioc_err(mrioc, "Issue IOCInit: Admin Post failed\n");
3322 wait_for_completion_timeout(&mrioc->init_cmds.done,
3323 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3324 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3325 mpi3mr_check_rh_fault_ioc(mrioc,
3326 MPI3MR_RESET_FROM_IOCINIT_TIMEOUT);
3327 ioc_err(mrioc, "ioc_init timed out\n");
3331 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3332 != MPI3_IOCSTATUS_SUCCESS) {
3334 "Issue IOCInit: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3335 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3336 mrioc->init_cmds.ioc_loginfo);
3341 mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
3342 writel(mrioc->reply_free_queue_host_index,
3343 &mrioc->sysif_regs->reply_free_host_index);
3345 mrioc->sbq_host_index = mrioc->num_sense_bufs;
3346 writel(mrioc->sbq_host_index,
3347 &mrioc->sysif_regs->sense_buffer_free_host_index);
3349 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3350 mutex_unlock(&mrioc->init_cmds.mutex);
3354 dma_free_coherent(&mrioc->pdev->dev, data_len, drv_info,
3361 * mpi3mr_unmask_events - Unmask events in event mask bitmap
3362 * @mrioc: Adapter instance reference
3363 * @event: MPI event ID
3365 * Un mask the specific event by resetting the event_mask
3368 * Return: 0 on success, non-zero on failures.
3370 static void mpi3mr_unmask_events(struct mpi3mr_ioc *mrioc, u16 event)
3378 desired_event = (1 << (event % 32));
3381 mrioc->event_masks[word] &= ~desired_event;
3385 * mpi3mr_issue_event_notification - Send event notification
3386 * @mrioc: Adapter instance reference
3388 * Issue event notification MPI request through admin queue and
3389 * wait for the completion of it or time out.
3391 * Return: 0 on success, non-zero on failures.
3393 static int mpi3mr_issue_event_notification(struct mpi3mr_ioc *mrioc)
3395 struct mpi3_event_notification_request evtnotify_req;
3399 memset(&evtnotify_req, 0, sizeof(evtnotify_req));
3400 mutex_lock(&mrioc->init_cmds.mutex);
3401 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3403 ioc_err(mrioc, "Issue EvtNotify: Init command is in use\n");
3404 mutex_unlock(&mrioc->init_cmds.mutex);
3407 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3408 mrioc->init_cmds.is_waiting = 1;
3409 mrioc->init_cmds.callback = NULL;
3410 evtnotify_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3411 evtnotify_req.function = MPI3_FUNCTION_EVENT_NOTIFICATION;
3412 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3413 evtnotify_req.event_masks[i] =
3414 cpu_to_le32(mrioc->event_masks[i]);
3415 init_completion(&mrioc->init_cmds.done);
3416 retval = mpi3mr_admin_request_post(mrioc, &evtnotify_req,
3417 sizeof(evtnotify_req), 1);
3419 ioc_err(mrioc, "Issue EvtNotify: Admin Post failed\n");
3422 wait_for_completion_timeout(&mrioc->init_cmds.done,
3423 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3424 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3425 ioc_err(mrioc, "event notification timed out\n");
3426 mpi3mr_check_rh_fault_ioc(mrioc,
3427 MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT);
3431 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3432 != MPI3_IOCSTATUS_SUCCESS) {
3434 "Issue EvtNotify: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3435 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3436 mrioc->init_cmds.ioc_loginfo);
3442 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3443 mutex_unlock(&mrioc->init_cmds.mutex);
3449 * mpi3mr_process_event_ack - Process event acknowledgment
3450 * @mrioc: Adapter instance reference
3451 * @event: MPI3 event ID
3452 * @event_ctx: event context
3454 * Send event acknowledgment through admin queue and wait for
3457 * Return: 0 on success, non-zero on failures.
3459 int mpi3mr_process_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
3462 struct mpi3_event_ack_request evtack_req;
3465 memset(&evtack_req, 0, sizeof(evtack_req));
3466 mutex_lock(&mrioc->init_cmds.mutex);
3467 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3469 ioc_err(mrioc, "Send EvtAck: Init command is in use\n");
3470 mutex_unlock(&mrioc->init_cmds.mutex);
3473 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3474 mrioc->init_cmds.is_waiting = 1;
3475 mrioc->init_cmds.callback = NULL;
3476 evtack_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3477 evtack_req.function = MPI3_FUNCTION_EVENT_ACK;
3478 evtack_req.event = event;
3479 evtack_req.event_context = cpu_to_le32(event_ctx);
3481 init_completion(&mrioc->init_cmds.done);
3482 retval = mpi3mr_admin_request_post(mrioc, &evtack_req,
3483 sizeof(evtack_req), 1);
3485 ioc_err(mrioc, "Send EvtAck: Admin Post failed\n");
3488 wait_for_completion_timeout(&mrioc->init_cmds.done,
3489 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3490 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3491 ioc_err(mrioc, "Issue EvtNotify: command timed out\n");
3492 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
3493 mpi3mr_check_rh_fault_ioc(mrioc,
3494 MPI3MR_RESET_FROM_EVTACK_TIMEOUT);
3498 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3499 != MPI3_IOCSTATUS_SUCCESS) {
3501 "Send EvtAck: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3502 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3503 mrioc->init_cmds.ioc_loginfo);
3509 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3510 mutex_unlock(&mrioc->init_cmds.mutex);
3516 * mpi3mr_alloc_chain_bufs - Allocate chain buffers
3517 * @mrioc: Adapter instance reference
3519 * Allocate chain buffers and set a bitmap to indicate free
3520 * chain buffers. Chain buffers are used to pass the SGE
3521 * information along with MPI3 SCSI IO requests for host I/O.
3523 * Return: 0 on success, non-zero on failure
3525 static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
3531 if (mrioc->chain_sgl_list)
3534 num_chains = mrioc->max_host_ios / MPI3MR_CHAINBUF_FACTOR;
3536 if (prot_mask & (SHOST_DIX_TYPE0_PROTECTION
3537 | SHOST_DIX_TYPE1_PROTECTION
3538 | SHOST_DIX_TYPE2_PROTECTION
3539 | SHOST_DIX_TYPE3_PROTECTION))
3540 num_chains += (num_chains / MPI3MR_CHAINBUFDIX_FACTOR);
3542 mrioc->chain_buf_count = num_chains;
3543 sz = sizeof(struct chain_element) * num_chains;
3544 mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
3545 if (!mrioc->chain_sgl_list)
3548 if (mrioc->max_sgl_entries > (mrioc->facts.max_data_length /
3549 MPI3MR_PAGE_SIZE_4K))
3550 mrioc->max_sgl_entries = mrioc->facts.max_data_length /
3551 MPI3MR_PAGE_SIZE_4K;
3552 sz = mrioc->max_sgl_entries * sizeof(struct mpi3_sge_common);
3553 ioc_info(mrioc, "number of sgl entries=%d chain buffer size=%dKB\n",
3554 mrioc->max_sgl_entries, sz/1024);
3556 mrioc->chain_buf_pool = dma_pool_create("chain_buf pool",
3557 &mrioc->pdev->dev, sz, 16, 0);
3558 if (!mrioc->chain_buf_pool) {
3559 ioc_err(mrioc, "chain buf pool: dma_pool_create failed\n");
3563 for (i = 0; i < num_chains; i++) {
3564 mrioc->chain_sgl_list[i].addr =
3565 dma_pool_zalloc(mrioc->chain_buf_pool, GFP_KERNEL,
3566 &mrioc->chain_sgl_list[i].dma_addr);
3568 if (!mrioc->chain_sgl_list[i].addr)
3571 mrioc->chain_bitmap = bitmap_zalloc(num_chains, GFP_KERNEL);
3572 if (!mrioc->chain_bitmap)
3581 * mpi3mr_port_enable_complete - Mark port enable complete
3582 * @mrioc: Adapter instance reference
3583 * @drv_cmd: Internal command tracker
3585 * Call back for asynchronous port enable request sets the
3586 * driver command to indicate port enable request is complete.
3590 static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
3591 struct mpi3mr_drv_cmd *drv_cmd)
3593 drv_cmd->callback = NULL;
3594 mrioc->scan_started = 0;
3595 if (drv_cmd->state & MPI3MR_CMD_RESET)
3596 mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
3598 mrioc->scan_failed = drv_cmd->ioc_status;
3599 drv_cmd->state = MPI3MR_CMD_NOTUSED;
3603 * mpi3mr_issue_port_enable - Issue Port Enable
3604 * @mrioc: Adapter instance reference
3605 * @async: Flag to wait for completion or not
3607 * Issue Port Enable MPI request through admin queue and if the
3608 * async flag is not set wait for the completion of the port
3609 * enable or time out.
3611 * Return: 0 on success, non-zero on failures.
3613 int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
3615 struct mpi3_port_enable_request pe_req;
3617 u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
3619 memset(&pe_req, 0, sizeof(pe_req));
3620 mutex_lock(&mrioc->init_cmds.mutex);
3621 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3623 ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
3624 mutex_unlock(&mrioc->init_cmds.mutex);
3627 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3629 mrioc->init_cmds.is_waiting = 0;
3630 mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
3632 mrioc->init_cmds.is_waiting = 1;
3633 mrioc->init_cmds.callback = NULL;
3634 init_completion(&mrioc->init_cmds.done);
3636 pe_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3637 pe_req.function = MPI3_FUNCTION_PORT_ENABLE;
3639 retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
3641 ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
3645 mutex_unlock(&mrioc->init_cmds.mutex);
3649 wait_for_completion_timeout(&mrioc->init_cmds.done, (pe_timeout * HZ));
3650 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3651 ioc_err(mrioc, "port enable timed out\n");
3653 mpi3mr_check_rh_fault_ioc(mrioc, MPI3MR_RESET_FROM_PE_TIMEOUT);
3656 mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
3659 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3660 mutex_unlock(&mrioc->init_cmds.mutex);
3665 /* Protocol type to name mapper structure */
3666 static const struct {
3669 } mpi3mr_protocols[] = {
3670 { MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR, "Initiator" },
3671 { MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET, "Target" },
3672 { MPI3_IOCFACTS_PROTOCOL_NVME, "NVMe attachment" },
3675 /* Capability to name mapper structure*/
3676 static const struct {
3679 } mpi3mr_capabilities[] = {
3680 { MPI3_IOCFACTS_CAPABILITY_RAID_SUPPORTED, "RAID" },
3681 { MPI3_IOCFACTS_CAPABILITY_MULTIPATH_SUPPORTED, "MultiPath" },
3685 * mpi3mr_print_ioc_info - Display controller information
3686 * @mrioc: Adapter instance reference
3688 * Display controller personality, capability, supported
3694 mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
3696 int i = 0, bytes_written = 0;
3697 const char *personality;
3698 char protocol[50] = {0};
3699 char capabilities[100] = {0};
3700 struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
3702 switch (mrioc->facts.personality) {
3703 case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
3704 personality = "Enhanced HBA";
3706 case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
3707 personality = "RAID";
3710 personality = "Unknown";
3714 ioc_info(mrioc, "Running in %s Personality", personality);
3716 ioc_info(mrioc, "FW version(%d.%d.%d.%d.%d.%d)\n",
3717 fwver->gen_major, fwver->gen_minor, fwver->ph_major,
3718 fwver->ph_minor, fwver->cust_id, fwver->build_num);
3720 for (i = 0; i < ARRAY_SIZE(mpi3mr_protocols); i++) {
3721 if (mrioc->facts.protocol_flags &
3722 mpi3mr_protocols[i].protocol) {
3723 bytes_written += scnprintf(protocol + bytes_written,
3724 sizeof(protocol) - bytes_written, "%s%s",
3725 bytes_written ? "," : "",
3726 mpi3mr_protocols[i].name);
3731 for (i = 0; i < ARRAY_SIZE(mpi3mr_capabilities); i++) {
3732 if (mrioc->facts.protocol_flags &
3733 mpi3mr_capabilities[i].capability) {
3734 bytes_written += scnprintf(capabilities + bytes_written,
3735 sizeof(capabilities) - bytes_written, "%s%s",
3736 bytes_written ? "," : "",
3737 mpi3mr_capabilities[i].name);
3741 ioc_info(mrioc, "Protocol=(%s), Capabilities=(%s)\n",
3742 protocol, capabilities);
3746 * mpi3mr_cleanup_resources - Free PCI resources
3747 * @mrioc: Adapter instance reference
3749 * Unmap PCI device memory and disable PCI device.
3751 * Return: 0 on success and non-zero on failure.
3753 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
3755 struct pci_dev *pdev = mrioc->pdev;
3757 mpi3mr_cleanup_isr(mrioc);
3759 if (mrioc->sysif_regs) {
3760 iounmap((void __iomem *)mrioc->sysif_regs);
3761 mrioc->sysif_regs = NULL;
3764 if (pci_is_enabled(pdev)) {
3766 pci_release_selected_regions(pdev, mrioc->bars);
3767 pci_disable_device(pdev);
3772 * mpi3mr_setup_resources - Enable PCI resources
3773 * @mrioc: Adapter instance reference
3775 * Enable PCI device memory, MSI-x registers and set DMA mask.
3777 * Return: 0 on success and non-zero on failure.
3779 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
3781 struct pci_dev *pdev = mrioc->pdev;
3783 int i, retval = 0, capb = 0;
3784 u16 message_control;
3785 u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
3786 ((sizeof(dma_addr_t) > 4) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
3788 if (pci_enable_device_mem(pdev)) {
3789 ioc_err(mrioc, "pci_enable_device_mem: failed\n");
3794 capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3796 ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
3800 mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
3802 if (pci_request_selected_regions(pdev, mrioc->bars,
3803 mrioc->driver_name)) {
3804 ioc_err(mrioc, "pci_request_selected_regions: failed\n");
3809 for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
3810 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
3811 mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
3812 memap_sz = pci_resource_len(pdev, i);
3814 ioremap(mrioc->sysif_regs_phys, memap_sz);
3819 pci_set_master(pdev);
3821 retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
3823 if (dma_mask != DMA_BIT_MASK(32)) {
3824 ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
3825 dma_mask = DMA_BIT_MASK(32);
3826 retval = dma_set_mask_and_coherent(&pdev->dev,
3830 mrioc->dma_mask = 0;
3831 ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
3835 mrioc->dma_mask = dma_mask;
3837 if (!mrioc->sysif_regs) {
3839 "Unable to map adapter memory or resource not found\n");
3844 pci_read_config_word(pdev, capb + 2, &message_control);
3845 mrioc->msix_count = (message_control & 0x3FF) + 1;
3847 pci_save_state(pdev);
3849 pci_set_drvdata(pdev, mrioc->shost);
3851 mpi3mr_ioc_disable_intr(mrioc);
3853 ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
3854 (unsigned long long)mrioc->sysif_regs_phys,
3855 mrioc->sysif_regs, memap_sz);
3856 ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
3859 if (!reset_devices && poll_queues > 0)
3860 mrioc->requested_poll_qcount = min_t(int, poll_queues,
3861 mrioc->msix_count - 2);
3865 mpi3mr_cleanup_resources(mrioc);
3870 * mpi3mr_enable_events - Enable required events
3871 * @mrioc: Adapter instance reference
3873 * This routine unmasks the events required by the driver by
3874 * sennding appropriate event mask bitmapt through an event
3875 * notification request.
3877 * Return: 0 on success and non-zero on failure.
3879 static int mpi3mr_enable_events(struct mpi3mr_ioc *mrioc)
3884 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3885 mrioc->event_masks[i] = -1;
3887 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_ADDED);
3888 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_INFO_CHANGED);
3889 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_STATUS_CHANGE);
3890 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE);
3891 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_ADDED);
3892 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
3893 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
3894 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
3895 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_BROADCAST_PRIMITIVE);
3896 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST);
3897 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_ENUMERATION);
3898 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PREPARE_FOR_RESET);
3899 mpi3mr_unmask_events(mrioc, MPI3_EVENT_CABLE_MGMT);
3900 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENERGY_PACK_CHANGE);
3902 retval = mpi3mr_issue_event_notification(mrioc);
3904 ioc_err(mrioc, "failed to issue event notification %d\n",
3910 * mpi3mr_init_ioc - Initialize the controller
3911 * @mrioc: Adapter instance reference
3913 * This the controller initialization routine, executed either
3914 * after soft reset or from pci probe callback.
3915 * Setup the required resources, memory map the controller
3916 * registers, create admin and operational reply queue pairs,
3917 * allocate required memory for reply pool, sense buffer pool,
3918 * issue IOC init request to the firmware, unmask the events and
3919 * issue port enable to discover SAS/SATA/NVMe devies and RAID
3922 * Return: 0 on success and non-zero on failure.
3924 int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
3928 struct mpi3_ioc_facts_data facts_data;
3932 retval = mpi3mr_bring_ioc_ready(mrioc);
3934 ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
3936 goto out_failed_noretry;
3939 retval = mpi3mr_setup_isr(mrioc, 1);
3941 ioc_err(mrioc, "Failed to setup ISR error %d\n",
3943 goto out_failed_noretry;
3946 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
3948 ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
3953 mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD;
3954 mrioc->shost->max_sectors = mrioc->facts.max_data_length / 512;
3955 mrioc->num_io_throttle_group = mrioc->facts.max_io_throttle_group;
3956 atomic_set(&mrioc->pend_large_data_sz, 0);
3959 mrioc->max_host_ios = min_t(int, mrioc->max_host_ios,
3960 MPI3MR_HOST_IOS_KDUMP);
3962 if (!(mrioc->facts.ioc_capabilities &
3963 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_SUPPORTED)) {
3964 mrioc->sas_transport_enabled = 1;
3965 mrioc->scsi_device_channel = 1;
3966 mrioc->shost->max_channel = 1;
3967 mrioc->shost->transportt = mpi3mr_transport_template;
3970 mrioc->reply_sz = mrioc->facts.reply_sz;
3972 retval = mpi3mr_check_reset_dma_mask(mrioc);
3974 ioc_err(mrioc, "Resetting dma mask failed %d\n",
3976 goto out_failed_noretry;
3979 mpi3mr_print_ioc_info(mrioc);
3981 if (!mrioc->cfg_page) {
3982 dprint_init(mrioc, "allocating config page buffers\n");
3983 mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ;
3984 mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev,
3985 mrioc->cfg_page_sz, &mrioc->cfg_page_dma, GFP_KERNEL);
3986 if (!mrioc->cfg_page) {
3988 goto out_failed_noretry;
3992 dprint_init(mrioc, "allocating ioctl dma buffers\n");
3993 mpi3mr_alloc_ioctl_dma_memory(mrioc);
3995 if (!mrioc->init_cmds.reply) {
3996 retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
3999 "%s :Failed to allocated reply sense buffers %d\n",
4001 goto out_failed_noretry;
4005 if (!mrioc->chain_sgl_list) {
4006 retval = mpi3mr_alloc_chain_bufs(mrioc);
4008 ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
4010 goto out_failed_noretry;
4014 retval = mpi3mr_issue_iocinit(mrioc);
4016 ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
4021 retval = mpi3mr_print_pkg_ver(mrioc);
4023 ioc_err(mrioc, "failed to get package version\n");
4027 retval = mpi3mr_setup_isr(mrioc, 0);
4029 ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
4031 goto out_failed_noretry;
4034 retval = mpi3mr_create_op_queues(mrioc);
4036 ioc_err(mrioc, "Failed to create OpQueues error %d\n",
4041 if (!mrioc->pel_seqnum_virt) {
4042 dprint_init(mrioc, "allocating memory for pel_seqnum_virt\n");
4043 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
4044 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
4045 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
4047 if (!mrioc->pel_seqnum_virt) {
4049 goto out_failed_noretry;
4053 if (!mrioc->throttle_groups && mrioc->num_io_throttle_group) {
4054 dprint_init(mrioc, "allocating memory for throttle groups\n");
4055 sz = sizeof(struct mpi3mr_throttle_group_info);
4056 mrioc->throttle_groups = kcalloc(mrioc->num_io_throttle_group, sz, GFP_KERNEL);
4057 if (!mrioc->throttle_groups) {
4059 goto out_failed_noretry;
4063 retval = mpi3mr_enable_events(mrioc);
4065 ioc_err(mrioc, "failed to enable events %d\n",
4070 ioc_info(mrioc, "controller initialization completed successfully\n");
4075 ioc_warn(mrioc, "retrying controller initialization, retry_count:%d\n",
4077 mpi3mr_memset_buffers(mrioc);
4082 ioc_err(mrioc, "controller initialization failed\n");
4083 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
4084 MPI3MR_RESET_FROM_CTLR_CLEANUP);
4085 mrioc->unrecoverable = 1;
4090 * mpi3mr_reinit_ioc - Re-Initialize the controller
4091 * @mrioc: Adapter instance reference
4092 * @is_resume: Called from resume or reset path
4094 * This the controller re-initialization routine, executed from
4095 * the soft reset handler or resume callback. Creates
4096 * operational reply queue pairs, allocate required memory for
4097 * reply pool, sense buffer pool, issue IOC init request to the
4098 * firmware, unmask the events and issue port enable to discover
4099 * SAS/SATA/NVMe devices and RAID volumes.
4101 * Return: 0 on success and non-zero on failure.
4103 int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
4107 struct mpi3_ioc_facts_data facts_data;
4108 u32 pe_timeout, ioc_status;
4112 (MPI3MR_PORTENABLE_TIMEOUT / MPI3MR_PORTENABLE_POLL_INTERVAL);
4114 dprint_reset(mrioc, "bringing up the controller to ready state\n");
4115 retval = mpi3mr_bring_ioc_ready(mrioc);
4117 ioc_err(mrioc, "failed to bring to ready state\n");
4118 goto out_failed_noretry;
4122 dprint_reset(mrioc, "setting up single ISR\n");
4123 retval = mpi3mr_setup_isr(mrioc, 1);
4125 ioc_err(mrioc, "failed to setup ISR\n");
4126 goto out_failed_noretry;
4129 mpi3mr_ioc_enable_intr(mrioc);
4131 dprint_reset(mrioc, "getting ioc_facts\n");
4132 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
4134 ioc_err(mrioc, "failed to get ioc_facts\n");
4138 dprint_reset(mrioc, "validating ioc_facts\n");
4139 retval = mpi3mr_revalidate_factsdata(mrioc);
4141 ioc_err(mrioc, "failed to revalidate ioc_facts data\n");
4142 goto out_failed_noretry;
4145 mpi3mr_print_ioc_info(mrioc);
4147 dprint_reset(mrioc, "sending ioc_init\n");
4148 retval = mpi3mr_issue_iocinit(mrioc);
4150 ioc_err(mrioc, "failed to send ioc_init\n");
4154 dprint_reset(mrioc, "getting package version\n");
4155 retval = mpi3mr_print_pkg_ver(mrioc);
4157 ioc_err(mrioc, "failed to get package version\n");
4162 dprint_reset(mrioc, "setting up multiple ISR\n");
4163 retval = mpi3mr_setup_isr(mrioc, 0);
4165 ioc_err(mrioc, "failed to re-setup ISR\n");
4166 goto out_failed_noretry;
4170 dprint_reset(mrioc, "creating operational queue pairs\n");
4171 retval = mpi3mr_create_op_queues(mrioc);
4173 ioc_err(mrioc, "failed to create operational queue pairs\n");
4177 if (!mrioc->pel_seqnum_virt) {
4178 dprint_reset(mrioc, "allocating memory for pel_seqnum_virt\n");
4179 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
4180 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
4181 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
4183 if (!mrioc->pel_seqnum_virt) {
4185 goto out_failed_noretry;
4189 if (mrioc->shost->nr_hw_queues > mrioc->num_op_reply_q) {
4191 "cannot create minimum number of operational queues expected:%d created:%d\n",
4192 mrioc->shost->nr_hw_queues, mrioc->num_op_reply_q);
4194 goto out_failed_noretry;
4197 dprint_reset(mrioc, "enabling events\n");
4198 retval = mpi3mr_enable_events(mrioc);
4200 ioc_err(mrioc, "failed to enable events\n");
4204 mrioc->device_refresh_on = 1;
4205 mpi3mr_add_event_wait_for_device_refresh(mrioc);
4207 ioc_info(mrioc, "sending port enable\n");
4208 retval = mpi3mr_issue_port_enable(mrioc, 1);
4210 ioc_err(mrioc, "failed to issue port enable\n");
4214 ssleep(MPI3MR_PORTENABLE_POLL_INTERVAL);
4215 if (mrioc->init_cmds.state == MPI3MR_CMD_NOTUSED)
4217 if (!pci_device_is_present(mrioc->pdev))
4218 mrioc->unrecoverable = 1;
4219 if (mrioc->unrecoverable) {
4221 goto out_failed_noretry;
4223 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4224 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
4225 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
4226 mpi3mr_print_fault_info(mrioc);
4227 mrioc->init_cmds.is_waiting = 0;
4228 mrioc->init_cmds.callback = NULL;
4229 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4232 } while (--pe_timeout);
4235 ioc_err(mrioc, "port enable timed out\n");
4236 mpi3mr_check_rh_fault_ioc(mrioc,
4237 MPI3MR_RESET_FROM_PE_TIMEOUT);
4238 mrioc->init_cmds.is_waiting = 0;
4239 mrioc->init_cmds.callback = NULL;
4240 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4242 } else if (mrioc->scan_failed) {
4244 "port enable failed with status=0x%04x\n",
4245 mrioc->scan_failed);
4247 ioc_info(mrioc, "port enable completed successfully\n");
4249 ioc_info(mrioc, "controller %s completed successfully\n",
4250 (is_resume)?"resume":"re-initialization");
4255 ioc_warn(mrioc, "retrying controller %s, retry_count:%d\n",
4256 (is_resume)?"resume":"re-initialization", retry);
4257 mpi3mr_memset_buffers(mrioc);
4262 ioc_err(mrioc, "controller %s is failed\n",
4263 (is_resume)?"resume":"re-initialization");
4264 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
4265 MPI3MR_RESET_FROM_CTLR_CLEANUP);
4266 mrioc->unrecoverable = 1;
4271 * mpi3mr_memset_op_reply_q_buffers - memset the operational reply queue's
4273 * @mrioc: Adapter instance reference
4274 * @qidx: Operational reply queue index
4278 static void mpi3mr_memset_op_reply_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4280 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
4281 struct segments *segments;
4284 if (!op_reply_q->q_segments)
4287 size = op_reply_q->segment_qd * mrioc->op_reply_desc_sz;
4288 segments = op_reply_q->q_segments;
4289 for (i = 0; i < op_reply_q->num_segments; i++)
4290 memset(segments[i].segment, 0, size);
4294 * mpi3mr_memset_op_req_q_buffers - memset the operational request queue's
4296 * @mrioc: Adapter instance reference
4297 * @qidx: Operational request queue index
4301 static void mpi3mr_memset_op_req_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4303 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
4304 struct segments *segments;
4307 if (!op_req_q->q_segments)
4310 size = op_req_q->segment_qd * mrioc->facts.op_req_sz;
4311 segments = op_req_q->q_segments;
4312 for (i = 0; i < op_req_q->num_segments; i++)
4313 memset(segments[i].segment, 0, size);
4317 * mpi3mr_memset_buffers - memset memory for a controller
4318 * @mrioc: Adapter instance reference
4320 * clear all the memory allocated for a controller, typically
4321 * called post reset to reuse the memory allocated during the
4326 void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
4329 struct mpi3mr_throttle_group_info *tg;
4331 mrioc->change_count = 0;
4332 mrioc->active_poll_qcount = 0;
4333 mrioc->default_qcount = 0;
4334 if (mrioc->admin_req_base)
4335 memset(mrioc->admin_req_base, 0, mrioc->admin_req_q_sz);
4336 if (mrioc->admin_reply_base)
4337 memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
4338 atomic_set(&mrioc->admin_reply_q_in_use, 0);
4340 if (mrioc->init_cmds.reply) {
4341 memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
4342 memset(mrioc->bsg_cmds.reply, 0,
4343 sizeof(*mrioc->bsg_cmds.reply));
4344 memset(mrioc->host_tm_cmds.reply, 0,
4345 sizeof(*mrioc->host_tm_cmds.reply));
4346 memset(mrioc->pel_cmds.reply, 0,
4347 sizeof(*mrioc->pel_cmds.reply));
4348 memset(mrioc->pel_abort_cmd.reply, 0,
4349 sizeof(*mrioc->pel_abort_cmd.reply));
4350 memset(mrioc->transport_cmds.reply, 0,
4351 sizeof(*mrioc->transport_cmds.reply));
4352 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
4353 memset(mrioc->dev_rmhs_cmds[i].reply, 0,
4354 sizeof(*mrioc->dev_rmhs_cmds[i].reply));
4355 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++)
4356 memset(mrioc->evtack_cmds[i].reply, 0,
4357 sizeof(*mrioc->evtack_cmds[i].reply));
4358 bitmap_clear(mrioc->removepend_bitmap, 0,
4359 mrioc->dev_handle_bitmap_bits);
4360 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
4361 bitmap_clear(mrioc->evtack_cmds_bitmap, 0,
4362 MPI3MR_NUM_EVTACKCMD);
4365 for (i = 0; i < mrioc->num_queues; i++) {
4366 mrioc->op_reply_qinfo[i].qid = 0;
4367 mrioc->op_reply_qinfo[i].ci = 0;
4368 mrioc->op_reply_qinfo[i].num_replies = 0;
4369 mrioc->op_reply_qinfo[i].ephase = 0;
4370 atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
4371 atomic_set(&mrioc->op_reply_qinfo[i].in_use, 0);
4372 mpi3mr_memset_op_reply_q_buffers(mrioc, i);
4374 mrioc->req_qinfo[i].ci = 0;
4375 mrioc->req_qinfo[i].pi = 0;
4376 mrioc->req_qinfo[i].num_requests = 0;
4377 mrioc->req_qinfo[i].qid = 0;
4378 mrioc->req_qinfo[i].reply_qid = 0;
4379 spin_lock_init(&mrioc->req_qinfo[i].q_lock);
4380 mpi3mr_memset_op_req_q_buffers(mrioc, i);
4383 atomic_set(&mrioc->pend_large_data_sz, 0);
4384 if (mrioc->throttle_groups) {
4385 tg = mrioc->throttle_groups;
4386 for (i = 0; i < mrioc->num_io_throttle_group; i++, tg++) {
4389 tg->modified_qd = 0;
4391 tg->need_qd_reduction = 0;
4394 tg->qd_reduction = 0;
4395 atomic_set(&tg->pend_large_data_sz, 0);
4401 * mpi3mr_free_mem - Free memory allocated for a controller
4402 * @mrioc: Adapter instance reference
4404 * Free all the memory allocated for a controller.
4408 void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
4411 struct mpi3mr_intr_info *intr_info;
4413 mpi3mr_free_enclosure_list(mrioc);
4414 mpi3mr_free_ioctl_dma_memory(mrioc);
4416 if (mrioc->sense_buf_pool) {
4417 if (mrioc->sense_buf)
4418 dma_pool_free(mrioc->sense_buf_pool, mrioc->sense_buf,
4419 mrioc->sense_buf_dma);
4420 dma_pool_destroy(mrioc->sense_buf_pool);
4421 mrioc->sense_buf = NULL;
4422 mrioc->sense_buf_pool = NULL;
4424 if (mrioc->sense_buf_q_pool) {
4425 if (mrioc->sense_buf_q)
4426 dma_pool_free(mrioc->sense_buf_q_pool,
4427 mrioc->sense_buf_q, mrioc->sense_buf_q_dma);
4428 dma_pool_destroy(mrioc->sense_buf_q_pool);
4429 mrioc->sense_buf_q = NULL;
4430 mrioc->sense_buf_q_pool = NULL;
4433 if (mrioc->reply_buf_pool) {
4434 if (mrioc->reply_buf)
4435 dma_pool_free(mrioc->reply_buf_pool, mrioc->reply_buf,
4436 mrioc->reply_buf_dma);
4437 dma_pool_destroy(mrioc->reply_buf_pool);
4438 mrioc->reply_buf = NULL;
4439 mrioc->reply_buf_pool = NULL;
4441 if (mrioc->reply_free_q_pool) {
4442 if (mrioc->reply_free_q)
4443 dma_pool_free(mrioc->reply_free_q_pool,
4444 mrioc->reply_free_q, mrioc->reply_free_q_dma);
4445 dma_pool_destroy(mrioc->reply_free_q_pool);
4446 mrioc->reply_free_q = NULL;
4447 mrioc->reply_free_q_pool = NULL;
4450 for (i = 0; i < mrioc->num_op_req_q; i++)
4451 mpi3mr_free_op_req_q_segments(mrioc, i);
4453 for (i = 0; i < mrioc->num_op_reply_q; i++)
4454 mpi3mr_free_op_reply_q_segments(mrioc, i);
4456 for (i = 0; i < mrioc->intr_info_count; i++) {
4457 intr_info = mrioc->intr_info + i;
4458 intr_info->op_reply_q = NULL;
4461 kfree(mrioc->req_qinfo);
4462 mrioc->req_qinfo = NULL;
4463 mrioc->num_op_req_q = 0;
4465 kfree(mrioc->op_reply_qinfo);
4466 mrioc->op_reply_qinfo = NULL;
4467 mrioc->num_op_reply_q = 0;
4469 kfree(mrioc->init_cmds.reply);
4470 mrioc->init_cmds.reply = NULL;
4472 kfree(mrioc->bsg_cmds.reply);
4473 mrioc->bsg_cmds.reply = NULL;
4475 kfree(mrioc->host_tm_cmds.reply);
4476 mrioc->host_tm_cmds.reply = NULL;
4478 kfree(mrioc->pel_cmds.reply);
4479 mrioc->pel_cmds.reply = NULL;
4481 kfree(mrioc->pel_abort_cmd.reply);
4482 mrioc->pel_abort_cmd.reply = NULL;
4484 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4485 kfree(mrioc->evtack_cmds[i].reply);
4486 mrioc->evtack_cmds[i].reply = NULL;
4489 bitmap_free(mrioc->removepend_bitmap);
4490 mrioc->removepend_bitmap = NULL;
4492 bitmap_free(mrioc->devrem_bitmap);
4493 mrioc->devrem_bitmap = NULL;
4495 bitmap_free(mrioc->evtack_cmds_bitmap);
4496 mrioc->evtack_cmds_bitmap = NULL;
4498 bitmap_free(mrioc->chain_bitmap);
4499 mrioc->chain_bitmap = NULL;
4501 kfree(mrioc->transport_cmds.reply);
4502 mrioc->transport_cmds.reply = NULL;
4504 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4505 kfree(mrioc->dev_rmhs_cmds[i].reply);
4506 mrioc->dev_rmhs_cmds[i].reply = NULL;
4509 if (mrioc->chain_buf_pool) {
4510 for (i = 0; i < mrioc->chain_buf_count; i++) {
4511 if (mrioc->chain_sgl_list[i].addr) {
4512 dma_pool_free(mrioc->chain_buf_pool,
4513 mrioc->chain_sgl_list[i].addr,
4514 mrioc->chain_sgl_list[i].dma_addr);
4515 mrioc->chain_sgl_list[i].addr = NULL;
4518 dma_pool_destroy(mrioc->chain_buf_pool);
4519 mrioc->chain_buf_pool = NULL;
4522 kfree(mrioc->chain_sgl_list);
4523 mrioc->chain_sgl_list = NULL;
4525 if (mrioc->admin_reply_base) {
4526 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
4527 mrioc->admin_reply_base, mrioc->admin_reply_dma);
4528 mrioc->admin_reply_base = NULL;
4530 if (mrioc->admin_req_base) {
4531 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
4532 mrioc->admin_req_base, mrioc->admin_req_dma);
4533 mrioc->admin_req_base = NULL;
4535 if (mrioc->cfg_page) {
4536 dma_free_coherent(&mrioc->pdev->dev, mrioc->cfg_page_sz,
4537 mrioc->cfg_page, mrioc->cfg_page_dma);
4538 mrioc->cfg_page = NULL;
4540 if (mrioc->pel_seqnum_virt) {
4541 dma_free_coherent(&mrioc->pdev->dev, mrioc->pel_seqnum_sz,
4542 mrioc->pel_seqnum_virt, mrioc->pel_seqnum_dma);
4543 mrioc->pel_seqnum_virt = NULL;
4546 kfree(mrioc->throttle_groups);
4547 mrioc->throttle_groups = NULL;
4549 kfree(mrioc->logdata_buf);
4550 mrioc->logdata_buf = NULL;
4555 * mpi3mr_issue_ioc_shutdown - shutdown controller
4556 * @mrioc: Adapter instance reference
4558 * Send shutodwn notification to the controller and wait for the
4559 * shutdown_timeout for it to be completed.
4563 static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
4565 u32 ioc_config, ioc_status;
4567 u32 timeout = MPI3MR_DEFAULT_SHUTDOWN_TIME * 10;
4569 ioc_info(mrioc, "Issuing shutdown Notification\n");
4570 if (mrioc->unrecoverable) {
4572 "IOC is unrecoverable shutdown is not issued\n");
4575 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4576 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4577 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS) {
4578 ioc_info(mrioc, "shutdown already in progress\n");
4582 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4583 ioc_config |= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL;
4584 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN_SEND_REQ;
4586 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
4588 if (mrioc->facts.shutdown_timeout)
4589 timeout = mrioc->facts.shutdown_timeout * 10;
4592 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4593 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4594 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE) {
4599 } while (--timeout);
4601 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4602 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4605 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4606 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS)
4608 "shutdown still in progress after timeout\n");
4612 "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
4613 (!retval) ? "successful" : "failed", ioc_status,
4618 * mpi3mr_cleanup_ioc - Cleanup controller
4619 * @mrioc: Adapter instance reference
4621 * controller cleanup handler, Message unit reset or soft reset
4622 * and shutdown notification is issued to the controller.
4626 void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
4628 enum mpi3mr_iocstate ioc_state;
4630 dprint_exit(mrioc, "cleaning up the controller\n");
4631 mpi3mr_ioc_disable_intr(mrioc);
4633 ioc_state = mpi3mr_get_iocstate(mrioc);
4635 if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
4636 (ioc_state == MRIOC_STATE_READY)) {
4637 if (mpi3mr_issue_and_process_mur(mrioc,
4638 MPI3MR_RESET_FROM_CTLR_CLEANUP))
4639 mpi3mr_issue_reset(mrioc,
4640 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
4641 MPI3MR_RESET_FROM_MUR_FAILURE);
4642 mpi3mr_issue_ioc_shutdown(mrioc);
4644 dprint_exit(mrioc, "controller cleanup completed\n");
4648 * mpi3mr_drv_cmd_comp_reset - Flush a internal driver command
4649 * @mrioc: Adapter instance reference
4650 * @cmdptr: Internal command tracker
4652 * Complete an internal driver commands with state indicating it
4653 * is completed due to reset.
4657 static inline void mpi3mr_drv_cmd_comp_reset(struct mpi3mr_ioc *mrioc,
4658 struct mpi3mr_drv_cmd *cmdptr)
4660 if (cmdptr->state & MPI3MR_CMD_PENDING) {
4661 cmdptr->state |= MPI3MR_CMD_RESET;
4662 cmdptr->state &= ~MPI3MR_CMD_PENDING;
4663 if (cmdptr->is_waiting) {
4664 complete(&cmdptr->done);
4665 cmdptr->is_waiting = 0;
4666 } else if (cmdptr->callback)
4667 cmdptr->callback(mrioc, cmdptr);
4672 * mpi3mr_flush_drv_cmds - Flush internaldriver commands
4673 * @mrioc: Adapter instance reference
4675 * Flush all internal driver commands post reset
4679 void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
4681 struct mpi3mr_drv_cmd *cmdptr;
4684 cmdptr = &mrioc->init_cmds;
4685 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4687 cmdptr = &mrioc->cfg_cmds;
4688 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4690 cmdptr = &mrioc->bsg_cmds;
4691 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4692 cmdptr = &mrioc->host_tm_cmds;
4693 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4695 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4696 cmdptr = &mrioc->dev_rmhs_cmds[i];
4697 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4700 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4701 cmdptr = &mrioc->evtack_cmds[i];
4702 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4705 cmdptr = &mrioc->pel_cmds;
4706 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4708 cmdptr = &mrioc->pel_abort_cmd;
4709 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4711 cmdptr = &mrioc->transport_cmds;
4712 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4716 * mpi3mr_pel_wait_post - Issue PEL Wait
4717 * @mrioc: Adapter instance reference
4718 * @drv_cmd: Internal command tracker
4720 * Issue PEL Wait MPI request through admin queue and return.
4724 static void mpi3mr_pel_wait_post(struct mpi3mr_ioc *mrioc,
4725 struct mpi3mr_drv_cmd *drv_cmd)
4727 struct mpi3_pel_req_action_wait pel_wait;
4729 mrioc->pel_abort_requested = false;
4731 memset(&pel_wait, 0, sizeof(pel_wait));
4732 drv_cmd->state = MPI3MR_CMD_PENDING;
4733 drv_cmd->is_waiting = 0;
4734 drv_cmd->callback = mpi3mr_pel_wait_complete;
4735 drv_cmd->ioc_status = 0;
4736 drv_cmd->ioc_loginfo = 0;
4737 pel_wait.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4738 pel_wait.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4739 pel_wait.action = MPI3_PEL_ACTION_WAIT;
4740 pel_wait.starting_sequence_number = cpu_to_le32(mrioc->pel_newest_seqnum);
4741 pel_wait.locale = cpu_to_le16(mrioc->pel_locale);
4742 pel_wait.class = cpu_to_le16(mrioc->pel_class);
4743 pel_wait.wait_time = MPI3_PEL_WAITTIME_INFINITE_WAIT;
4744 dprint_bsg_info(mrioc, "sending pel_wait seqnum(%d), class(%d), locale(0x%08x)\n",
4745 mrioc->pel_newest_seqnum, mrioc->pel_class, mrioc->pel_locale);
4747 if (mpi3mr_admin_request_post(mrioc, &pel_wait, sizeof(pel_wait), 0)) {
4748 dprint_bsg_err(mrioc,
4749 "Issuing PELWait: Admin post failed\n");
4750 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4751 drv_cmd->callback = NULL;
4752 drv_cmd->retry_count = 0;
4753 mrioc->pel_enabled = false;
4758 * mpi3mr_pel_get_seqnum_post - Issue PEL Get Sequence number
4759 * @mrioc: Adapter instance reference
4760 * @drv_cmd: Internal command tracker
4762 * Issue PEL get sequence number MPI request through admin queue
4765 * Return: 0 on success, non-zero on failure.
4767 int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc,
4768 struct mpi3mr_drv_cmd *drv_cmd)
4770 struct mpi3_pel_req_action_get_sequence_numbers pel_getseq_req;
4771 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
4774 memset(&pel_getseq_req, 0, sizeof(pel_getseq_req));
4775 mrioc->pel_cmds.state = MPI3MR_CMD_PENDING;
4776 mrioc->pel_cmds.is_waiting = 0;
4777 mrioc->pel_cmds.ioc_status = 0;
4778 mrioc->pel_cmds.ioc_loginfo = 0;
4779 mrioc->pel_cmds.callback = mpi3mr_pel_get_seqnum_complete;
4780 pel_getseq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4781 pel_getseq_req.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4782 pel_getseq_req.action = MPI3_PEL_ACTION_GET_SEQNUM;
4783 mpi3mr_add_sg_single(&pel_getseq_req.sgl, sgl_flags,
4784 mrioc->pel_seqnum_sz, mrioc->pel_seqnum_dma);
4786 retval = mpi3mr_admin_request_post(mrioc, &pel_getseq_req,
4787 sizeof(pel_getseq_req), 0);
4790 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4791 drv_cmd->callback = NULL;
4792 drv_cmd->retry_count = 0;
4794 mrioc->pel_enabled = false;
4801 * mpi3mr_pel_wait_complete - PELWait Completion callback
4802 * @mrioc: Adapter instance reference
4803 * @drv_cmd: Internal command tracker
4805 * This is a callback handler for the PELWait request and
4806 * firmware completes a PELWait request when it is aborted or a
4807 * new PEL entry is available. This sends AEN to the application
4808 * and if the PELwait completion is not due to PELAbort then
4809 * this will send a request for new PEL Sequence number
4813 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc *mrioc,
4814 struct mpi3mr_drv_cmd *drv_cmd)
4816 struct mpi3_pel_reply *pel_reply = NULL;
4817 u16 ioc_status, pe_log_status;
4818 bool do_retry = false;
4820 if (drv_cmd->state & MPI3MR_CMD_RESET)
4821 goto cleanup_drv_cmd;
4823 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4824 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4825 ioc_err(mrioc, "%s: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
4826 __func__, ioc_status, drv_cmd->ioc_loginfo);
4827 dprint_bsg_err(mrioc,
4828 "pel_wait: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4829 ioc_status, drv_cmd->ioc_loginfo);
4833 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4834 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4837 dprint_bsg_err(mrioc,
4838 "pel_wait: failed due to no reply\n");
4842 pe_log_status = le16_to_cpu(pel_reply->pe_log_status);
4843 if ((pe_log_status != MPI3_PEL_STATUS_SUCCESS) &&
4844 (pe_log_status != MPI3_PEL_STATUS_ABORTED)) {
4845 ioc_err(mrioc, "%s: Failed pe_log_status(0x%04x)\n",
4846 __func__, pe_log_status);
4847 dprint_bsg_err(mrioc,
4848 "pel_wait: failed due to pel_log_status(0x%04x)\n",
4854 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4855 drv_cmd->retry_count++;
4856 dprint_bsg_err(mrioc, "pel_wait: retrying(%d)\n",
4857 drv_cmd->retry_count);
4858 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4861 dprint_bsg_err(mrioc,
4862 "pel_wait: failed after all retries(%d)\n",
4863 drv_cmd->retry_count);
4866 atomic64_inc(&event_counter);
4867 if (!mrioc->pel_abort_requested) {
4868 mrioc->pel_cmds.retry_count = 0;
4869 mpi3mr_pel_get_seqnum_post(mrioc, &mrioc->pel_cmds);
4874 mrioc->pel_enabled = false;
4876 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4877 drv_cmd->callback = NULL;
4878 drv_cmd->retry_count = 0;
4882 * mpi3mr_pel_get_seqnum_complete - PELGetSeqNum Completion callback
4883 * @mrioc: Adapter instance reference
4884 * @drv_cmd: Internal command tracker
4886 * This is a callback handler for the PEL get sequence number
4887 * request and a new PEL wait request will be issued to the
4888 * firmware from this
4892 void mpi3mr_pel_get_seqnum_complete(struct mpi3mr_ioc *mrioc,
4893 struct mpi3mr_drv_cmd *drv_cmd)
4895 struct mpi3_pel_reply *pel_reply = NULL;
4896 struct mpi3_pel_seq *pel_seqnum_virt;
4898 bool do_retry = false;
4900 pel_seqnum_virt = (struct mpi3_pel_seq *)mrioc->pel_seqnum_virt;
4902 if (drv_cmd->state & MPI3MR_CMD_RESET)
4903 goto cleanup_drv_cmd;
4905 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4906 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4907 dprint_bsg_err(mrioc,
4908 "pel_get_seqnum: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4909 ioc_status, drv_cmd->ioc_loginfo);
4913 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4914 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4916 dprint_bsg_err(mrioc,
4917 "pel_get_seqnum: failed due to no reply\n");
4921 if (le16_to_cpu(pel_reply->pe_log_status) != MPI3_PEL_STATUS_SUCCESS) {
4922 dprint_bsg_err(mrioc,
4923 "pel_get_seqnum: failed due to pel_log_status(0x%04x)\n",
4924 le16_to_cpu(pel_reply->pe_log_status));
4929 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4930 drv_cmd->retry_count++;
4931 dprint_bsg_err(mrioc,
4932 "pel_get_seqnum: retrying(%d)\n",
4933 drv_cmd->retry_count);
4934 mpi3mr_pel_get_seqnum_post(mrioc, drv_cmd);
4938 dprint_bsg_err(mrioc,
4939 "pel_get_seqnum: failed after all retries(%d)\n",
4940 drv_cmd->retry_count);
4943 mrioc->pel_newest_seqnum = le32_to_cpu(pel_seqnum_virt->newest) + 1;
4944 drv_cmd->retry_count = 0;
4945 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4949 mrioc->pel_enabled = false;
4951 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4952 drv_cmd->callback = NULL;
4953 drv_cmd->retry_count = 0;
4957 * mpi3mr_soft_reset_handler - Reset the controller
4958 * @mrioc: Adapter instance reference
4959 * @reset_reason: Reset reason code
4960 * @snapdump: Flag to generate snapdump in firmware or not
4962 * This is an handler for recovering controller by issuing soft
4963 * reset are diag fault reset. This is a blocking function and
4964 * when one reset is executed if any other resets they will be
4965 * blocked. All BSG requests will be blocked during the reset. If
4966 * controller reset is successful then the controller will be
4967 * reinitalized, otherwise the controller will be marked as not
4970 * In snapdump bit is set, the controller is issued with diag
4971 * fault reset so that the firmware can create a snap dump and
4972 * post that the firmware will result in F000 fault and the
4973 * driver will issue soft reset to recover from that.
4975 * Return: 0 on success, non-zero on failure.
4977 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
4978 u16 reset_reason, u8 snapdump)
4981 unsigned long flags;
4982 u32 host_diagnostic, timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
4984 /* Block the reset handler until diag save in progress*/
4986 "soft_reset_handler: check and block on diagsave_timeout(%d)\n",
4987 mrioc->diagsave_timeout);
4988 while (mrioc->diagsave_timeout)
4991 * Block new resets until the currently executing one is finished and
4992 * return the status of the existing reset for all blocked resets
4994 dprint_reset(mrioc, "soft_reset_handler: acquiring reset_mutex\n");
4995 if (!mutex_trylock(&mrioc->reset_mutex)) {
4997 "controller reset triggered by %s is blocked due to another reset in progress\n",
4998 mpi3mr_reset_rc_name(reset_reason));
5001 } while (mrioc->reset_in_progress == 1);
5003 "returning previous reset result(%d) for the reset triggered by %s\n",
5004 mrioc->prev_reset_result,
5005 mpi3mr_reset_rc_name(reset_reason));
5006 return mrioc->prev_reset_result;
5008 ioc_info(mrioc, "controller reset is triggered by %s\n",
5009 mpi3mr_reset_rc_name(reset_reason));
5011 mrioc->device_refresh_on = 0;
5012 mrioc->reset_in_progress = 1;
5013 mrioc->stop_bsgs = 1;
5014 mrioc->prev_reset_result = -1;
5016 if ((!snapdump) && (reset_reason != MPI3MR_RESET_FROM_FAULT_WATCH) &&
5017 (reset_reason != MPI3MR_RESET_FROM_FIRMWARE) &&
5018 (reset_reason != MPI3MR_RESET_FROM_CIACTIV_FAULT)) {
5019 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
5020 mrioc->event_masks[i] = -1;
5022 dprint_reset(mrioc, "soft_reset_handler: masking events\n");
5023 mpi3mr_issue_event_notification(mrioc);
5026 mpi3mr_wait_for_host_io(mrioc, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT);
5028 mpi3mr_ioc_disable_intr(mrioc);
5031 mpi3mr_set_diagsave(mrioc);
5032 retval = mpi3mr_issue_reset(mrioc,
5033 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
5037 readl(&mrioc->sysif_regs->host_diagnostic);
5038 if (!(host_diagnostic &
5039 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
5042 } while (--timeout);
5046 retval = mpi3mr_issue_reset(mrioc,
5047 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, reset_reason);
5049 ioc_err(mrioc, "Failed to issue soft reset to the ioc\n");
5052 if (mrioc->num_io_throttle_group !=
5053 mrioc->facts.max_io_throttle_group) {
5055 "max io throttle group doesn't match old(%d), new(%d)\n",
5056 mrioc->num_io_throttle_group,
5057 mrioc->facts.max_io_throttle_group);
5062 mpi3mr_flush_delayed_cmd_lists(mrioc);
5063 mpi3mr_flush_drv_cmds(mrioc);
5064 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
5065 bitmap_clear(mrioc->removepend_bitmap, 0,
5066 mrioc->dev_handle_bitmap_bits);
5067 bitmap_clear(mrioc->evtack_cmds_bitmap, 0, MPI3MR_NUM_EVTACKCMD);
5068 mpi3mr_flush_host_io(mrioc);
5069 mpi3mr_cleanup_fwevt_list(mrioc);
5070 mpi3mr_invalidate_devhandles(mrioc);
5071 mpi3mr_free_enclosure_list(mrioc);
5073 if (mrioc->prepare_for_reset) {
5074 mrioc->prepare_for_reset = 0;
5075 mrioc->prepare_for_reset_timeout_counter = 0;
5077 mpi3mr_memset_buffers(mrioc);
5078 retval = mpi3mr_reinit_ioc(mrioc, 0);
5080 pr_err(IOCNAME "reinit after soft reset failed: reason %d\n",
5081 mrioc->name, reset_reason);
5084 ssleep(MPI3MR_RESET_TOPOLOGY_SETTLE_TIME);
5088 mrioc->diagsave_timeout = 0;
5089 mrioc->reset_in_progress = 0;
5090 mrioc->pel_abort_requested = 0;
5091 if (mrioc->pel_enabled) {
5092 mrioc->pel_cmds.retry_count = 0;
5093 mpi3mr_pel_wait_post(mrioc, &mrioc->pel_cmds);
5096 mrioc->device_refresh_on = 0;
5098 mrioc->ts_update_counter = 0;
5099 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
5100 if (mrioc->watchdog_work_q)
5101 queue_delayed_work(mrioc->watchdog_work_q,
5102 &mrioc->watchdog_work,
5103 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
5104 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
5105 mrioc->stop_bsgs = 0;
5106 if (mrioc->pel_enabled)
5107 atomic64_inc(&event_counter);
5109 mpi3mr_issue_reset(mrioc,
5110 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
5111 mrioc->device_refresh_on = 0;
5112 mrioc->unrecoverable = 1;
5113 mrioc->reset_in_progress = 0;
5114 mrioc->stop_bsgs = 0;
5116 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
5118 mrioc->prev_reset_result = retval;
5119 mutex_unlock(&mrioc->reset_mutex);
5120 ioc_info(mrioc, "controller reset is %s\n",
5121 ((retval == 0) ? "successful" : "failed"));
5127 * mpi3mr_free_config_dma_memory - free memory for config page
5128 * @mrioc: Adapter instance reference
5129 * @mem_desc: memory descriptor structure
5131 * Check whether the size of the buffer specified by the memory
5132 * descriptor is greater than the default page size if so then
5133 * free the memory pointed by the descriptor.
5137 static void mpi3mr_free_config_dma_memory(struct mpi3mr_ioc *mrioc,
5138 struct dma_memory_desc *mem_desc)
5140 if ((mem_desc->size > mrioc->cfg_page_sz) && mem_desc->addr) {
5141 dma_free_coherent(&mrioc->pdev->dev, mem_desc->size,
5142 mem_desc->addr, mem_desc->dma_addr);
5143 mem_desc->addr = NULL;
5148 * mpi3mr_alloc_config_dma_memory - Alloc memory for config page
5149 * @mrioc: Adapter instance reference
5150 * @mem_desc: Memory descriptor to hold dma memory info
5152 * This function allocates new dmaable memory or provides the
5153 * default config page dmaable memory based on the memory size
5154 * described by the descriptor.
5156 * Return: 0 on success, non-zero on failure.
5158 static int mpi3mr_alloc_config_dma_memory(struct mpi3mr_ioc *mrioc,
5159 struct dma_memory_desc *mem_desc)
5161 if (mem_desc->size > mrioc->cfg_page_sz) {
5162 mem_desc->addr = dma_alloc_coherent(&mrioc->pdev->dev,
5163 mem_desc->size, &mem_desc->dma_addr, GFP_KERNEL);
5164 if (!mem_desc->addr)
5167 mem_desc->addr = mrioc->cfg_page;
5168 mem_desc->dma_addr = mrioc->cfg_page_dma;
5169 memset(mem_desc->addr, 0, mrioc->cfg_page_sz);
5175 * mpi3mr_post_cfg_req - Issue config requests and wait
5176 * @mrioc: Adapter instance reference
5177 * @cfg_req: Configuration request
5178 * @timeout: Timeout in seconds
5179 * @ioc_status: Pointer to return ioc status
5181 * A generic function for posting MPI3 configuration request to
5182 * the firmware. This blocks for the completion of request for
5183 * timeout seconds and if the request times out this function
5184 * faults the controller with proper reason code.
5186 * On successful completion of the request this function returns
5187 * appropriate ioc status from the firmware back to the caller.
5189 * Return: 0 on success, non-zero on failure.
5191 static int mpi3mr_post_cfg_req(struct mpi3mr_ioc *mrioc,
5192 struct mpi3_config_request *cfg_req, int timeout, u16 *ioc_status)
5196 mutex_lock(&mrioc->cfg_cmds.mutex);
5197 if (mrioc->cfg_cmds.state & MPI3MR_CMD_PENDING) {
5199 ioc_err(mrioc, "sending config request failed due to command in use\n");
5200 mutex_unlock(&mrioc->cfg_cmds.mutex);
5203 mrioc->cfg_cmds.state = MPI3MR_CMD_PENDING;
5204 mrioc->cfg_cmds.is_waiting = 1;
5205 mrioc->cfg_cmds.callback = NULL;
5206 mrioc->cfg_cmds.ioc_status = 0;
5207 mrioc->cfg_cmds.ioc_loginfo = 0;
5209 cfg_req->host_tag = cpu_to_le16(MPI3MR_HOSTTAG_CFG_CMDS);
5210 cfg_req->function = MPI3_FUNCTION_CONFIG;
5212 init_completion(&mrioc->cfg_cmds.done);
5213 dprint_cfg_info(mrioc, "posting config request\n");
5214 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5215 dprint_dump(cfg_req, sizeof(struct mpi3_config_request),
5217 retval = mpi3mr_admin_request_post(mrioc, cfg_req, sizeof(*cfg_req), 1);
5219 ioc_err(mrioc, "posting config request failed\n");
5222 wait_for_completion_timeout(&mrioc->cfg_cmds.done, (timeout * HZ));
5223 if (!(mrioc->cfg_cmds.state & MPI3MR_CMD_COMPLETE)) {
5224 mpi3mr_check_rh_fault_ioc(mrioc,
5225 MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT);
5226 ioc_err(mrioc, "config request timed out\n");
5230 *ioc_status = mrioc->cfg_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
5231 if ((*ioc_status) != MPI3_IOCSTATUS_SUCCESS)
5232 dprint_cfg_err(mrioc,
5233 "cfg_page request returned with ioc_status(0x%04x), log_info(0x%08x)\n",
5234 *ioc_status, mrioc->cfg_cmds.ioc_loginfo);
5237 mrioc->cfg_cmds.state = MPI3MR_CMD_NOTUSED;
5238 mutex_unlock(&mrioc->cfg_cmds.mutex);
5245 * mpi3mr_process_cfg_req - config page request processor
5246 * @mrioc: Adapter instance reference
5247 * @cfg_req: Configuration request
5248 * @cfg_hdr: Configuration page header
5249 * @timeout: Timeout in seconds
5250 * @ioc_status: Pointer to return ioc status
5251 * @cfg_buf: Memory pointer to copy config page or header
5252 * @cfg_buf_sz: Size of the memory to get config page or header
5254 * This is handler for config page read, write and config page
5255 * header read operations.
5257 * This function expects the cfg_req to be populated with page
5258 * type, page number, action for the header read and with page
5259 * address for all other operations.
5261 * The cfg_hdr can be passed as null for reading required header
5262 * details for read/write pages the cfg_hdr should point valid
5263 * configuration page header.
5265 * This allocates dmaable memory based on the size of the config
5266 * buffer and set the SGE of the cfg_req.
5268 * For write actions, the config page data has to be passed in
5269 * the cfg_buf and size of the data has to be mentioned in the
5272 * For read/header actions, on successful completion of the
5273 * request with successful ioc_status the data will be copied
5274 * into the cfg_buf limited to a minimum of actual page size and
5278 * Return: 0 on success, non-zero on failure.
5280 static int mpi3mr_process_cfg_req(struct mpi3mr_ioc *mrioc,
5281 struct mpi3_config_request *cfg_req,
5282 struct mpi3_config_page_header *cfg_hdr, int timeout, u16 *ioc_status,
5283 void *cfg_buf, u32 cfg_buf_sz)
5285 struct dma_memory_desc mem_desc;
5287 u8 invalid_action = 0;
5288 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
5290 memset(&mem_desc, 0, sizeof(struct dma_memory_desc));
5292 if (cfg_req->action == MPI3_CONFIG_ACTION_PAGE_HEADER)
5293 mem_desc.size = sizeof(struct mpi3_config_page_header);
5296 ioc_err(mrioc, "null config header passed for config action(%d), page_type(0x%02x), page_num(%d)\n",
5297 cfg_req->action, cfg_req->page_type,
5298 cfg_req->page_number);
5301 switch (cfg_hdr->page_attribute & MPI3_CONFIG_PAGEATTR_MASK) {
5302 case MPI3_CONFIG_PAGEATTR_READ_ONLY:
5304 != MPI3_CONFIG_ACTION_READ_CURRENT)
5307 case MPI3_CONFIG_PAGEATTR_CHANGEABLE:
5308 if ((cfg_req->action ==
5309 MPI3_CONFIG_ACTION_READ_PERSISTENT) ||
5311 MPI3_CONFIG_ACTION_WRITE_PERSISTENT))
5314 case MPI3_CONFIG_PAGEATTR_PERSISTENT:
5318 if (invalid_action) {
5320 "config action(%d) is not allowed for page_type(0x%02x), page_num(%d) with page_attribute(0x%02x)\n",
5321 cfg_req->action, cfg_req->page_type,
5322 cfg_req->page_number, cfg_hdr->page_attribute);
5325 mem_desc.size = le16_to_cpu(cfg_hdr->page_length) * 4;
5326 cfg_req->page_length = cfg_hdr->page_length;
5327 cfg_req->page_version = cfg_hdr->page_version;
5329 if (mpi3mr_alloc_config_dma_memory(mrioc, &mem_desc))
5332 mpi3mr_add_sg_single(&cfg_req->sgl, sgl_flags, mem_desc.size,
5335 if ((cfg_req->action == MPI3_CONFIG_ACTION_WRITE_PERSISTENT) ||
5336 (cfg_req->action == MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5337 memcpy(mem_desc.addr, cfg_buf, min_t(u16, mem_desc.size,
5339 dprint_cfg_info(mrioc, "config buffer to be written\n");
5340 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5341 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5344 if (mpi3mr_post_cfg_req(mrioc, cfg_req, timeout, ioc_status))
5348 if ((*ioc_status == MPI3_IOCSTATUS_SUCCESS) &&
5349 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_PERSISTENT) &&
5350 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5351 memcpy(cfg_buf, mem_desc.addr, min_t(u16, mem_desc.size,
5353 dprint_cfg_info(mrioc, "config buffer read\n");
5354 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5355 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5359 mpi3mr_free_config_dma_memory(mrioc, &mem_desc);
5364 * mpi3mr_cfg_get_dev_pg0 - Read current device page0
5365 * @mrioc: Adapter instance reference
5366 * @ioc_status: Pointer to return ioc status
5367 * @dev_pg0: Pointer to return device page 0
5368 * @pg_sz: Size of the memory allocated to the page pointer
5369 * @form: The form to be used for addressing the page
5370 * @form_spec: Form specific information like device handle
5372 * This is handler for config page read for a specific device
5373 * page0. The ioc_status has the controller returned ioc_status.
5374 * This routine doesn't check ioc_status to decide whether the
5375 * page read is success or not and it is the callers
5378 * Return: 0 on success, non-zero on failure.
5380 int mpi3mr_cfg_get_dev_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5381 struct mpi3_device_page0 *dev_pg0, u16 pg_sz, u32 form, u32 form_spec)
5383 struct mpi3_config_page_header cfg_hdr;
5384 struct mpi3_config_request cfg_req;
5387 memset(dev_pg0, 0, pg_sz);
5388 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5389 memset(&cfg_req, 0, sizeof(cfg_req));
5391 cfg_req.function = MPI3_FUNCTION_CONFIG;
5392 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5393 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DEVICE;
5394 cfg_req.page_number = 0;
5395 cfg_req.page_address = 0;
5397 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5398 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5399 ioc_err(mrioc, "device page0 header read failed\n");
5402 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5403 ioc_err(mrioc, "device page0 header read failed with ioc_status(0x%04x)\n",
5407 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5408 page_address = ((form & MPI3_DEVICE_PGAD_FORM_MASK) |
5409 (form_spec & MPI3_DEVICE_PGAD_HANDLE_MASK));
5410 cfg_req.page_address = cpu_to_le32(page_address);
5411 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5412 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, dev_pg0, pg_sz)) {
5413 ioc_err(mrioc, "device page0 read failed\n");
5423 * mpi3mr_cfg_get_sas_phy_pg0 - Read current SAS Phy page0
5424 * @mrioc: Adapter instance reference
5425 * @ioc_status: Pointer to return ioc status
5426 * @phy_pg0: Pointer to return SAS Phy page 0
5427 * @pg_sz: Size of the memory allocated to the page pointer
5428 * @form: The form to be used for addressing the page
5429 * @form_spec: Form specific information like phy number
5431 * This is handler for config page read for a specific SAS Phy
5432 * page0. The ioc_status has the controller returned ioc_status.
5433 * This routine doesn't check ioc_status to decide whether the
5434 * page read is success or not and it is the callers
5437 * Return: 0 on success, non-zero on failure.
5439 int mpi3mr_cfg_get_sas_phy_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5440 struct mpi3_sas_phy_page0 *phy_pg0, u16 pg_sz, u32 form,
5443 struct mpi3_config_page_header cfg_hdr;
5444 struct mpi3_config_request cfg_req;
5447 memset(phy_pg0, 0, pg_sz);
5448 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5449 memset(&cfg_req, 0, sizeof(cfg_req));
5451 cfg_req.function = MPI3_FUNCTION_CONFIG;
5452 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5453 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5454 cfg_req.page_number = 0;
5455 cfg_req.page_address = 0;
5457 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5458 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5459 ioc_err(mrioc, "sas phy page0 header read failed\n");
5462 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5463 ioc_err(mrioc, "sas phy page0 header read failed with ioc_status(0x%04x)\n",
5467 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5468 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5469 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5470 cfg_req.page_address = cpu_to_le32(page_address);
5471 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5472 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg0, pg_sz)) {
5473 ioc_err(mrioc, "sas phy page0 read failed\n");
5482 * mpi3mr_cfg_get_sas_phy_pg1 - Read current SAS Phy page1
5483 * @mrioc: Adapter instance reference
5484 * @ioc_status: Pointer to return ioc status
5485 * @phy_pg1: Pointer to return SAS Phy page 1
5486 * @pg_sz: Size of the memory allocated to the page pointer
5487 * @form: The form to be used for addressing the page
5488 * @form_spec: Form specific information like phy number
5490 * This is handler for config page read for a specific SAS Phy
5491 * page1. The ioc_status has the controller returned ioc_status.
5492 * This routine doesn't check ioc_status to decide whether the
5493 * page read is success or not and it is the callers
5496 * Return: 0 on success, non-zero on failure.
5498 int mpi3mr_cfg_get_sas_phy_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5499 struct mpi3_sas_phy_page1 *phy_pg1, u16 pg_sz, u32 form,
5502 struct mpi3_config_page_header cfg_hdr;
5503 struct mpi3_config_request cfg_req;
5506 memset(phy_pg1, 0, pg_sz);
5507 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5508 memset(&cfg_req, 0, sizeof(cfg_req));
5510 cfg_req.function = MPI3_FUNCTION_CONFIG;
5511 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5512 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5513 cfg_req.page_number = 1;
5514 cfg_req.page_address = 0;
5516 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5517 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5518 ioc_err(mrioc, "sas phy page1 header read failed\n");
5521 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5522 ioc_err(mrioc, "sas phy page1 header read failed with ioc_status(0x%04x)\n",
5526 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5527 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5528 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5529 cfg_req.page_address = cpu_to_le32(page_address);
5530 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5531 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg1, pg_sz)) {
5532 ioc_err(mrioc, "sas phy page1 read failed\n");
5542 * mpi3mr_cfg_get_sas_exp_pg0 - Read current SAS Expander page0
5543 * @mrioc: Adapter instance reference
5544 * @ioc_status: Pointer to return ioc status
5545 * @exp_pg0: Pointer to return SAS Expander page 0
5546 * @pg_sz: Size of the memory allocated to the page pointer
5547 * @form: The form to be used for addressing the page
5548 * @form_spec: Form specific information like device handle
5550 * This is handler for config page read for a specific SAS
5551 * Expander page0. The ioc_status has the controller returned
5552 * ioc_status. This routine doesn't check ioc_status to decide
5553 * whether the page read is success or not and it is the callers
5556 * Return: 0 on success, non-zero on failure.
5558 int mpi3mr_cfg_get_sas_exp_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5559 struct mpi3_sas_expander_page0 *exp_pg0, u16 pg_sz, u32 form,
5562 struct mpi3_config_page_header cfg_hdr;
5563 struct mpi3_config_request cfg_req;
5566 memset(exp_pg0, 0, pg_sz);
5567 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5568 memset(&cfg_req, 0, sizeof(cfg_req));
5570 cfg_req.function = MPI3_FUNCTION_CONFIG;
5571 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5572 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5573 cfg_req.page_number = 0;
5574 cfg_req.page_address = 0;
5576 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5577 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5578 ioc_err(mrioc, "expander page0 header read failed\n");
5581 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5582 ioc_err(mrioc, "expander page0 header read failed with ioc_status(0x%04x)\n",
5586 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5587 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5588 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5589 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5590 cfg_req.page_address = cpu_to_le32(page_address);
5591 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5592 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg0, pg_sz)) {
5593 ioc_err(mrioc, "expander page0 read failed\n");
5602 * mpi3mr_cfg_get_sas_exp_pg1 - Read current SAS Expander page1
5603 * @mrioc: Adapter instance reference
5604 * @ioc_status: Pointer to return ioc status
5605 * @exp_pg1: Pointer to return SAS Expander page 1
5606 * @pg_sz: Size of the memory allocated to the page pointer
5607 * @form: The form to be used for addressing the page
5608 * @form_spec: Form specific information like phy number
5610 * This is handler for config page read for a specific SAS
5611 * Expander page1. The ioc_status has the controller returned
5612 * ioc_status. This routine doesn't check ioc_status to decide
5613 * whether the page read is success or not and it is the callers
5616 * Return: 0 on success, non-zero on failure.
5618 int mpi3mr_cfg_get_sas_exp_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5619 struct mpi3_sas_expander_page1 *exp_pg1, u16 pg_sz, u32 form,
5622 struct mpi3_config_page_header cfg_hdr;
5623 struct mpi3_config_request cfg_req;
5626 memset(exp_pg1, 0, pg_sz);
5627 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5628 memset(&cfg_req, 0, sizeof(cfg_req));
5630 cfg_req.function = MPI3_FUNCTION_CONFIG;
5631 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5632 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5633 cfg_req.page_number = 1;
5634 cfg_req.page_address = 0;
5636 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5637 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5638 ioc_err(mrioc, "expander page1 header read failed\n");
5641 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5642 ioc_err(mrioc, "expander page1 header read failed with ioc_status(0x%04x)\n",
5646 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5647 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5648 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5649 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5650 cfg_req.page_address = cpu_to_le32(page_address);
5651 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5652 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg1, pg_sz)) {
5653 ioc_err(mrioc, "expander page1 read failed\n");
5662 * mpi3mr_cfg_get_enclosure_pg0 - Read current Enclosure page0
5663 * @mrioc: Adapter instance reference
5664 * @ioc_status: Pointer to return ioc status
5665 * @encl_pg0: Pointer to return Enclosure page 0
5666 * @pg_sz: Size of the memory allocated to the page pointer
5667 * @form: The form to be used for addressing the page
5668 * @form_spec: Form specific information like device handle
5670 * This is handler for config page read for a specific Enclosure
5671 * page0. The ioc_status has the controller returned ioc_status.
5672 * This routine doesn't check ioc_status to decide whether the
5673 * page read is success or not and it is the callers
5676 * Return: 0 on success, non-zero on failure.
5678 int mpi3mr_cfg_get_enclosure_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5679 struct mpi3_enclosure_page0 *encl_pg0, u16 pg_sz, u32 form,
5682 struct mpi3_config_page_header cfg_hdr;
5683 struct mpi3_config_request cfg_req;
5686 memset(encl_pg0, 0, pg_sz);
5687 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5688 memset(&cfg_req, 0, sizeof(cfg_req));
5690 cfg_req.function = MPI3_FUNCTION_CONFIG;
5691 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5692 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_ENCLOSURE;
5693 cfg_req.page_number = 0;
5694 cfg_req.page_address = 0;
5696 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5697 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5698 ioc_err(mrioc, "enclosure page0 header read failed\n");
5701 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5702 ioc_err(mrioc, "enclosure page0 header read failed with ioc_status(0x%04x)\n",
5706 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5707 page_address = ((form & MPI3_ENCLOS_PGAD_FORM_MASK) |
5708 (form_spec & MPI3_ENCLOS_PGAD_HANDLE_MASK));
5709 cfg_req.page_address = cpu_to_le32(page_address);
5710 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5711 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, encl_pg0, pg_sz)) {
5712 ioc_err(mrioc, "enclosure page0 read failed\n");
5722 * mpi3mr_cfg_get_sas_io_unit_pg0 - Read current SASIOUnit page0
5723 * @mrioc: Adapter instance reference
5724 * @sas_io_unit_pg0: Pointer to return SAS IO Unit page 0
5725 * @pg_sz: Size of the memory allocated to the page pointer
5727 * This is handler for config page read for the SAS IO Unit
5728 * page0. This routine checks ioc_status to decide whether the
5729 * page read is success or not.
5731 * Return: 0 on success, non-zero on failure.
5733 int mpi3mr_cfg_get_sas_io_unit_pg0(struct mpi3mr_ioc *mrioc,
5734 struct mpi3_sas_io_unit_page0 *sas_io_unit_pg0, u16 pg_sz)
5736 struct mpi3_config_page_header cfg_hdr;
5737 struct mpi3_config_request cfg_req;
5740 memset(sas_io_unit_pg0, 0, pg_sz);
5741 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5742 memset(&cfg_req, 0, sizeof(cfg_req));
5744 cfg_req.function = MPI3_FUNCTION_CONFIG;
5745 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5746 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5747 cfg_req.page_number = 0;
5748 cfg_req.page_address = 0;
5750 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5751 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5752 ioc_err(mrioc, "sas io unit page0 header read failed\n");
5755 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5756 ioc_err(mrioc, "sas io unit page0 header read failed with ioc_status(0x%04x)\n",
5760 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5762 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5763 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg0, pg_sz)) {
5764 ioc_err(mrioc, "sas io unit page0 read failed\n");
5767 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5768 ioc_err(mrioc, "sas io unit page0 read failed with ioc_status(0x%04x)\n",
5778 * mpi3mr_cfg_get_sas_io_unit_pg1 - Read current SASIOUnit page1
5779 * @mrioc: Adapter instance reference
5780 * @sas_io_unit_pg1: Pointer to return SAS IO Unit page 1
5781 * @pg_sz: Size of the memory allocated to the page pointer
5783 * This is handler for config page read for the SAS IO Unit
5784 * page1. This routine checks ioc_status to decide whether the
5785 * page read is success or not.
5787 * Return: 0 on success, non-zero on failure.
5789 int mpi3mr_cfg_get_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5790 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5792 struct mpi3_config_page_header cfg_hdr;
5793 struct mpi3_config_request cfg_req;
5796 memset(sas_io_unit_pg1, 0, pg_sz);
5797 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5798 memset(&cfg_req, 0, sizeof(cfg_req));
5800 cfg_req.function = MPI3_FUNCTION_CONFIG;
5801 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5802 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5803 cfg_req.page_number = 1;
5804 cfg_req.page_address = 0;
5806 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5807 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5808 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5811 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5812 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5816 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5818 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5819 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5820 ioc_err(mrioc, "sas io unit page1 read failed\n");
5823 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5824 ioc_err(mrioc, "sas io unit page1 read failed with ioc_status(0x%04x)\n",
5834 * mpi3mr_cfg_set_sas_io_unit_pg1 - Write SASIOUnit page1
5835 * @mrioc: Adapter instance reference
5836 * @sas_io_unit_pg1: Pointer to the SAS IO Unit page 1 to write
5837 * @pg_sz: Size of the memory allocated to the page pointer
5839 * This is handler for config page write for the SAS IO Unit
5840 * page1. This routine checks ioc_status to decide whether the
5841 * page read is success or not. This will modify both current
5842 * and persistent page.
5844 * Return: 0 on success, non-zero on failure.
5846 int mpi3mr_cfg_set_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5847 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5849 struct mpi3_config_page_header cfg_hdr;
5850 struct mpi3_config_request cfg_req;
5853 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5854 memset(&cfg_req, 0, sizeof(cfg_req));
5856 cfg_req.function = MPI3_FUNCTION_CONFIG;
5857 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5858 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5859 cfg_req.page_number = 1;
5860 cfg_req.page_address = 0;
5862 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5863 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5864 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5867 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5868 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5872 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_CURRENT;
5874 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5875 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5876 ioc_err(mrioc, "sas io unit page1 write current failed\n");
5879 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5880 ioc_err(mrioc, "sas io unit page1 write current failed with ioc_status(0x%04x)\n",
5885 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_PERSISTENT;
5887 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5888 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5889 ioc_err(mrioc, "sas io unit page1 write persistent failed\n");
5892 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5893 ioc_err(mrioc, "sas io unit page1 write persistent failed with ioc_status(0x%04x)\n",
5903 * mpi3mr_cfg_get_driver_pg1 - Read current Driver page1
5904 * @mrioc: Adapter instance reference
5905 * @driver_pg1: Pointer to return Driver page 1
5906 * @pg_sz: Size of the memory allocated to the page pointer
5908 * This is handler for config page read for the Driver page1.
5909 * This routine checks ioc_status to decide whether the page
5910 * read is success or not.
5912 * Return: 0 on success, non-zero on failure.
5914 int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc *mrioc,
5915 struct mpi3_driver_page1 *driver_pg1, u16 pg_sz)
5917 struct mpi3_config_page_header cfg_hdr;
5918 struct mpi3_config_request cfg_req;
5921 memset(driver_pg1, 0, pg_sz);
5922 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5923 memset(&cfg_req, 0, sizeof(cfg_req));
5925 cfg_req.function = MPI3_FUNCTION_CONFIG;
5926 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5927 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DRIVER;
5928 cfg_req.page_number = 1;
5929 cfg_req.page_address = 0;
5931 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5932 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5933 ioc_err(mrioc, "driver page1 header read failed\n");
5936 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5937 ioc_err(mrioc, "driver page1 header read failed with ioc_status(0x%04x)\n",
5941 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5943 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5944 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, driver_pg1, pg_sz)) {
5945 ioc_err(mrioc, "driver page1 read failed\n");
5948 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5949 ioc_err(mrioc, "driver page1 read failed with ioc_status(0x%04x)\n",