1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Broadcom MPI3 Storage Controllers
5 * Copyright (C) 2017-2023 Broadcom Inc.
6 * (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
11 #include <linux/io-64-nonatomic-lo-hi.h>
14 mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type, u32 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;
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 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1208 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1209 ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1210 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1212 timeout = MPI3MR_MUR_TIMEOUT * 10;
1214 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1215 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)) {
1216 mpi3mr_clear_reset_history(mrioc);
1219 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1220 mpi3mr_print_fault_info(mrioc);
1224 } while (--timeout);
1226 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1227 if (timeout && !((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1228 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
1229 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1232 ioc_info(mrioc, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
1233 (!retval) ? "successful" : "failed", ioc_status, ioc_config);
1238 * mpi3mr_revalidate_factsdata - validate IOCFacts parameters
1239 * during reset/resume
1240 * @mrioc: Adapter instance reference
1242 * Return: zero if the new IOCFacts parameters value is compatible with
1243 * older values else return -EPERM
1246 mpi3mr_revalidate_factsdata(struct mpi3mr_ioc *mrioc)
1248 unsigned long *removepend_bitmap;
1250 if (mrioc->facts.reply_sz > mrioc->reply_sz) {
1252 "cannot increase reply size from %d to %d\n",
1253 mrioc->reply_sz, mrioc->facts.reply_sz);
1257 if (mrioc->facts.max_op_reply_q < mrioc->num_op_reply_q) {
1259 "cannot reduce number of operational reply queues from %d to %d\n",
1260 mrioc->num_op_reply_q,
1261 mrioc->facts.max_op_reply_q);
1265 if (mrioc->facts.max_op_req_q < mrioc->num_op_req_q) {
1267 "cannot reduce number of operational request queues from %d to %d\n",
1268 mrioc->num_op_req_q, mrioc->facts.max_op_req_q);
1272 if (mrioc->shost->max_sectors != (mrioc->facts.max_data_length / 512))
1273 ioc_err(mrioc, "Warning: The maximum data transfer length\n"
1274 "\tchanged after reset: previous(%d), new(%d),\n"
1275 "the driver cannot change this at run time\n",
1276 mrioc->shost->max_sectors * 512, mrioc->facts.max_data_length);
1278 if ((mrioc->sas_transport_enabled) && (mrioc->facts.ioc_capabilities &
1279 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED))
1281 "critical error: multipath capability is enabled at the\n"
1282 "\tcontroller while sas transport support is enabled at the\n"
1283 "\tdriver, please reboot the system or reload the driver\n");
1285 if (mrioc->facts.max_devhandle > mrioc->dev_handle_bitmap_bits) {
1286 removepend_bitmap = bitmap_zalloc(mrioc->facts.max_devhandle,
1288 if (!removepend_bitmap) {
1290 "failed to increase removepend_bitmap bits from %d to %d\n",
1291 mrioc->dev_handle_bitmap_bits,
1292 mrioc->facts.max_devhandle);
1295 bitmap_free(mrioc->removepend_bitmap);
1296 mrioc->removepend_bitmap = removepend_bitmap;
1298 "increased bits of dev_handle_bitmap from %d to %d\n",
1299 mrioc->dev_handle_bitmap_bits,
1300 mrioc->facts.max_devhandle);
1301 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
1308 * mpi3mr_bring_ioc_ready - Bring controller to ready state
1309 * @mrioc: Adapter instance reference
1311 * Set Enable IOC bit in IOC configuration register and wait for
1312 * the controller to become ready.
1314 * Return: 0 on success, appropriate error on failure.
1316 static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
1318 u32 ioc_config, ioc_status, timeout, host_diagnostic;
1320 enum mpi3mr_iocstate ioc_state;
1323 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1324 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1325 base_info = lo_hi_readq(&mrioc->sysif_regs->ioc_information);
1326 ioc_info(mrioc, "ioc_status(0x%08x), ioc_config(0x%08x), ioc_info(0x%016llx) at the bringup\n",
1327 ioc_status, ioc_config, base_info);
1329 /*The timeout value is in 2sec unit, changing it to seconds*/
1330 mrioc->ready_timeout =
1331 ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
1332 MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
1334 ioc_info(mrioc, "ready timeout: %d seconds\n", mrioc->ready_timeout);
1336 ioc_state = mpi3mr_get_iocstate(mrioc);
1337 ioc_info(mrioc, "controller is in %s state during detection\n",
1338 mpi3mr_iocstate_name(ioc_state));
1340 if (ioc_state == MRIOC_STATE_BECOMING_READY ||
1341 ioc_state == MRIOC_STATE_RESET_REQUESTED) {
1342 timeout = mrioc->ready_timeout * 10;
1345 } while (--timeout);
1347 if (!pci_device_is_present(mrioc->pdev)) {
1348 mrioc->unrecoverable = 1;
1350 "controller is not present while waiting to reset\n");
1352 goto out_device_not_present;
1355 ioc_state = mpi3mr_get_iocstate(mrioc);
1357 "controller is in %s state after waiting to reset\n",
1358 mpi3mr_iocstate_name(ioc_state));
1361 if (ioc_state == MRIOC_STATE_READY) {
1362 ioc_info(mrioc, "issuing message unit reset (MUR) to bring to reset state\n");
1363 retval = mpi3mr_issue_and_process_mur(mrioc,
1364 MPI3MR_RESET_FROM_BRINGUP);
1365 ioc_state = mpi3mr_get_iocstate(mrioc);
1368 "message unit reset failed with error %d current state %s\n",
1369 retval, mpi3mr_iocstate_name(ioc_state));
1371 if (ioc_state != MRIOC_STATE_RESET) {
1372 if (ioc_state == MRIOC_STATE_FAULT) {
1373 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
1374 mpi3mr_print_fault_info(mrioc);
1377 readl(&mrioc->sysif_regs->host_diagnostic);
1378 if (!(host_diagnostic &
1379 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
1381 if (!pci_device_is_present(mrioc->pdev)) {
1382 mrioc->unrecoverable = 1;
1383 ioc_err(mrioc, "controller is not present at the bringup\n");
1384 goto out_device_not_present;
1387 } while (--timeout);
1389 mpi3mr_print_fault_info(mrioc);
1390 ioc_info(mrioc, "issuing soft reset to bring to reset state\n");
1391 retval = mpi3mr_issue_reset(mrioc,
1392 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
1393 MPI3MR_RESET_FROM_BRINGUP);
1396 "soft reset failed with error %d\n", retval);
1400 ioc_state = mpi3mr_get_iocstate(mrioc);
1401 if (ioc_state != MRIOC_STATE_RESET) {
1403 "cannot bring controller to reset state, current state: %s\n",
1404 mpi3mr_iocstate_name(ioc_state));
1407 mpi3mr_clear_reset_history(mrioc);
1408 retval = mpi3mr_setup_admin_qpair(mrioc);
1410 ioc_err(mrioc, "failed to setup admin queues: error %d\n",
1415 ioc_info(mrioc, "bringing controller to ready state\n");
1416 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1417 ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1418 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1420 timeout = mrioc->ready_timeout * 10;
1422 ioc_state = mpi3mr_get_iocstate(mrioc);
1423 if (ioc_state == MRIOC_STATE_READY) {
1425 "successfully transitioned to %s state\n",
1426 mpi3mr_iocstate_name(ioc_state));
1429 if (!pci_device_is_present(mrioc->pdev)) {
1430 mrioc->unrecoverable = 1;
1432 "controller is not present at the bringup\n");
1434 goto out_device_not_present;
1437 } while (--timeout);
1440 ioc_state = mpi3mr_get_iocstate(mrioc);
1442 "failed to bring to ready state, current state: %s\n",
1443 mpi3mr_iocstate_name(ioc_state));
1444 out_device_not_present:
1449 * mpi3mr_soft_reset_success - Check softreset is success or not
1450 * @ioc_status: IOC status register value
1451 * @ioc_config: IOC config register value
1453 * Check whether the soft reset is successful or not based on
1454 * IOC status and IOC config register values.
1456 * Return: True when the soft reset is success, false otherwise.
1459 mpi3mr_soft_reset_success(u32 ioc_status, u32 ioc_config)
1461 if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1462 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1468 * mpi3mr_diagfault_success - Check diag fault is success or not
1469 * @mrioc: Adapter reference
1470 * @ioc_status: IOC status register value
1472 * Check whether the controller hit diag reset fault code.
1474 * Return: True when there is diag fault, false otherwise.
1476 static inline bool mpi3mr_diagfault_success(struct mpi3mr_ioc *mrioc,
1481 if (!(ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT))
1483 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
1484 if (fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET) {
1485 mpi3mr_print_fault_info(mrioc);
1492 * mpi3mr_set_diagsave - Set diag save bit for snapdump
1493 * @mrioc: Adapter reference
1495 * Set diag save bit in IOC configuration register to enable
1500 static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
1504 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1505 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE;
1506 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1510 * mpi3mr_issue_reset - Issue reset to the controller
1511 * @mrioc: Adapter reference
1512 * @reset_type: Reset type
1513 * @reset_reason: Reset reason code
1515 * Unlock the host diagnostic registers and write the specific
1516 * reset type to that, wait for reset acknowledgment from the
1517 * controller, if the reset is not successful retry for the
1518 * predefined number of times.
1520 * Return: 0 on success, non-zero on failure.
1522 static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
1526 u8 unlock_retry_count = 0;
1527 u32 host_diagnostic, ioc_status, ioc_config;
1528 u32 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
1530 if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
1531 (reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT))
1533 if (mrioc->unrecoverable)
1535 if (reset_reason == MPI3MR_RESET_FROM_FIRMWARE) {
1540 ioc_info(mrioc, "%s reset due to %s(0x%x)\n",
1541 mpi3mr_reset_type_name(reset_type),
1542 mpi3mr_reset_rc_name(reset_reason), reset_reason);
1544 mpi3mr_clear_reset_history(mrioc);
1547 "Write magic sequence to unlock host diag register (retry=%d)\n",
1548 ++unlock_retry_count);
1549 if (unlock_retry_count >= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT) {
1551 "%s reset failed due to unlock failure, host_diagnostic(0x%08x)\n",
1552 mpi3mr_reset_type_name(reset_type),
1554 mrioc->unrecoverable = 1;
1558 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH,
1559 &mrioc->sysif_regs->write_sequence);
1560 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST,
1561 &mrioc->sysif_regs->write_sequence);
1562 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1563 &mrioc->sysif_regs->write_sequence);
1564 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD,
1565 &mrioc->sysif_regs->write_sequence);
1566 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH,
1567 &mrioc->sysif_regs->write_sequence);
1568 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH,
1569 &mrioc->sysif_regs->write_sequence);
1570 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH,
1571 &mrioc->sysif_regs->write_sequence);
1572 usleep_range(1000, 1100);
1573 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
1575 "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
1576 unlock_retry_count, host_diagnostic);
1577 } while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
1579 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1580 writel(host_diagnostic | reset_type,
1581 &mrioc->sysif_regs->host_diagnostic);
1582 switch (reset_type) {
1583 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET:
1585 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1587 readl(&mrioc->sysif_regs->ioc_configuration);
1588 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1589 && mpi3mr_soft_reset_success(ioc_status, ioc_config)
1591 mpi3mr_clear_reset_history(mrioc);
1596 } while (--timeout);
1597 mpi3mr_print_fault_info(mrioc);
1599 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT:
1601 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1602 if (mpi3mr_diagfault_success(mrioc, ioc_status)) {
1607 } while (--timeout);
1613 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1614 &mrioc->sysif_regs->write_sequence);
1616 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1617 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1619 "ioc_status/ioc_onfig after %s reset is (0x%x)/(0x%x)\n",
1620 (!retval)?"successful":"failed", ioc_status,
1623 mrioc->unrecoverable = 1;
1628 * mpi3mr_admin_request_post - Post request to admin queue
1629 * @mrioc: Adapter reference
1630 * @admin_req: MPI3 request
1631 * @admin_req_sz: Request size
1632 * @ignore_reset: Ignore reset in process
1634 * Post the MPI3 request into admin request queue and
1635 * inform the controller, if the queue is full return
1636 * appropriate error.
1638 * Return: 0 on success, non-zero on failure.
1640 int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
1641 u16 admin_req_sz, u8 ignore_reset)
1643 u16 areq_pi = 0, areq_ci = 0, max_entries = 0;
1645 unsigned long flags;
1648 if (mrioc->unrecoverable) {
1649 ioc_err(mrioc, "%s : Unrecoverable controller\n", __func__);
1653 spin_lock_irqsave(&mrioc->admin_req_lock, flags);
1654 areq_pi = mrioc->admin_req_pi;
1655 areq_ci = mrioc->admin_req_ci;
1656 max_entries = mrioc->num_admin_req;
1657 if ((areq_ci == (areq_pi + 1)) || ((!areq_ci) &&
1658 (areq_pi == (max_entries - 1)))) {
1659 ioc_err(mrioc, "AdminReqQ full condition detected\n");
1663 if (!ignore_reset && mrioc->reset_in_progress) {
1664 ioc_err(mrioc, "AdminReqQ submit reset in progress\n");
1668 areq_entry = (u8 *)mrioc->admin_req_base +
1669 (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
1670 memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
1671 memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
1673 if (++areq_pi == max_entries)
1675 mrioc->admin_req_pi = areq_pi;
1677 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
1680 spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
1686 * mpi3mr_free_op_req_q_segments - free request memory segments
1687 * @mrioc: Adapter instance reference
1688 * @q_idx: operational request queue index
1690 * Free memory segments allocated for operational request queue
1694 static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1698 struct segments *segments;
1700 segments = mrioc->req_qinfo[q_idx].q_segments;
1704 if (mrioc->enable_segqueue) {
1705 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1706 if (mrioc->req_qinfo[q_idx].q_segment_list) {
1707 dma_free_coherent(&mrioc->pdev->dev,
1708 MPI3MR_MAX_SEG_LIST_SIZE,
1709 mrioc->req_qinfo[q_idx].q_segment_list,
1710 mrioc->req_qinfo[q_idx].q_segment_list_dma);
1711 mrioc->req_qinfo[q_idx].q_segment_list = NULL;
1714 size = mrioc->req_qinfo[q_idx].segment_qd *
1715 mrioc->facts.op_req_sz;
1717 for (j = 0; j < mrioc->req_qinfo[q_idx].num_segments; j++) {
1718 if (!segments[j].segment)
1720 dma_free_coherent(&mrioc->pdev->dev,
1721 size, segments[j].segment, segments[j].segment_dma);
1722 segments[j].segment = NULL;
1724 kfree(mrioc->req_qinfo[q_idx].q_segments);
1725 mrioc->req_qinfo[q_idx].q_segments = NULL;
1726 mrioc->req_qinfo[q_idx].qid = 0;
1730 * mpi3mr_free_op_reply_q_segments - free reply memory segments
1731 * @mrioc: Adapter instance reference
1732 * @q_idx: operational reply queue index
1734 * Free memory segments allocated for operational reply queue
1738 static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1742 struct segments *segments;
1744 segments = mrioc->op_reply_qinfo[q_idx].q_segments;
1748 if (mrioc->enable_segqueue) {
1749 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1750 if (mrioc->op_reply_qinfo[q_idx].q_segment_list) {
1751 dma_free_coherent(&mrioc->pdev->dev,
1752 MPI3MR_MAX_SEG_LIST_SIZE,
1753 mrioc->op_reply_qinfo[q_idx].q_segment_list,
1754 mrioc->op_reply_qinfo[q_idx].q_segment_list_dma);
1755 mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
1758 size = mrioc->op_reply_qinfo[q_idx].segment_qd *
1759 mrioc->op_reply_desc_sz;
1761 for (j = 0; j < mrioc->op_reply_qinfo[q_idx].num_segments; j++) {
1762 if (!segments[j].segment)
1764 dma_free_coherent(&mrioc->pdev->dev,
1765 size, segments[j].segment, segments[j].segment_dma);
1766 segments[j].segment = NULL;
1769 kfree(mrioc->op_reply_qinfo[q_idx].q_segments);
1770 mrioc->op_reply_qinfo[q_idx].q_segments = NULL;
1771 mrioc->op_reply_qinfo[q_idx].qid = 0;
1775 * mpi3mr_delete_op_reply_q - delete operational reply queue
1776 * @mrioc: Adapter instance reference
1777 * @qidx: operational reply queue index
1779 * Delete operatinal reply queue by issuing MPI request
1780 * through admin queue.
1782 * Return: 0 on success, non-zero on failure.
1784 static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1786 struct mpi3_delete_reply_queue_request delq_req;
1787 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1789 u16 reply_qid = 0, midx;
1791 reply_qid = op_reply_q->qid;
1793 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1797 ioc_err(mrioc, "Issue DelRepQ: called with invalid ReqQID\n");
1801 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount-- :
1802 mrioc->active_poll_qcount--;
1804 memset(&delq_req, 0, sizeof(delq_req));
1805 mutex_lock(&mrioc->init_cmds.mutex);
1806 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1808 ioc_err(mrioc, "Issue DelRepQ: Init command is in use\n");
1809 mutex_unlock(&mrioc->init_cmds.mutex);
1812 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1813 mrioc->init_cmds.is_waiting = 1;
1814 mrioc->init_cmds.callback = NULL;
1815 delq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1816 delq_req.function = MPI3_FUNCTION_DELETE_REPLY_QUEUE;
1817 delq_req.queue_id = cpu_to_le16(reply_qid);
1819 init_completion(&mrioc->init_cmds.done);
1820 retval = mpi3mr_admin_request_post(mrioc, &delq_req, sizeof(delq_req),
1823 ioc_err(mrioc, "Issue DelRepQ: Admin Post failed\n");
1826 wait_for_completion_timeout(&mrioc->init_cmds.done,
1827 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1828 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1829 ioc_err(mrioc, "delete reply queue timed out\n");
1830 mpi3mr_check_rh_fault_ioc(mrioc,
1831 MPI3MR_RESET_FROM_DELREPQ_TIMEOUT);
1835 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1836 != MPI3_IOCSTATUS_SUCCESS) {
1838 "Issue DelRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1839 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1840 mrioc->init_cmds.ioc_loginfo);
1844 mrioc->intr_info[midx].op_reply_q = NULL;
1846 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1848 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1849 mutex_unlock(&mrioc->init_cmds.mutex);
1856 * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
1857 * @mrioc: Adapter instance reference
1858 * @qidx: request queue index
1860 * Allocate segmented memory pools for operational reply
1863 * Return: 0 on success, non-zero on failure.
1865 static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1867 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1869 u64 *q_segment_list_entry = NULL;
1870 struct segments *segments;
1872 if (mrioc->enable_segqueue) {
1873 op_reply_q->segment_qd =
1874 MPI3MR_OP_REP_Q_SEG_SIZE / mrioc->op_reply_desc_sz;
1876 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1878 op_reply_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1879 MPI3MR_MAX_SEG_LIST_SIZE, &op_reply_q->q_segment_list_dma,
1881 if (!op_reply_q->q_segment_list)
1883 q_segment_list_entry = (u64 *)op_reply_q->q_segment_list;
1885 op_reply_q->segment_qd = op_reply_q->num_replies;
1886 size = op_reply_q->num_replies * mrioc->op_reply_desc_sz;
1889 op_reply_q->num_segments = DIV_ROUND_UP(op_reply_q->num_replies,
1890 op_reply_q->segment_qd);
1892 op_reply_q->q_segments = kcalloc(op_reply_q->num_segments,
1893 sizeof(struct segments), GFP_KERNEL);
1894 if (!op_reply_q->q_segments)
1897 segments = op_reply_q->q_segments;
1898 for (i = 0; i < op_reply_q->num_segments; i++) {
1899 segments[i].segment =
1900 dma_alloc_coherent(&mrioc->pdev->dev,
1901 size, &segments[i].segment_dma, GFP_KERNEL);
1902 if (!segments[i].segment)
1904 if (mrioc->enable_segqueue)
1905 q_segment_list_entry[i] =
1906 (unsigned long)segments[i].segment_dma;
1913 * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
1914 * @mrioc: Adapter instance reference
1915 * @qidx: request queue index
1917 * Allocate segmented memory pools for operational request
1920 * Return: 0 on success, non-zero on failure.
1922 static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1924 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
1926 u64 *q_segment_list_entry = NULL;
1927 struct segments *segments;
1929 if (mrioc->enable_segqueue) {
1930 op_req_q->segment_qd =
1931 MPI3MR_OP_REQ_Q_SEG_SIZE / mrioc->facts.op_req_sz;
1933 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1935 op_req_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1936 MPI3MR_MAX_SEG_LIST_SIZE, &op_req_q->q_segment_list_dma,
1938 if (!op_req_q->q_segment_list)
1940 q_segment_list_entry = (u64 *)op_req_q->q_segment_list;
1943 op_req_q->segment_qd = op_req_q->num_requests;
1944 size = op_req_q->num_requests * mrioc->facts.op_req_sz;
1947 op_req_q->num_segments = DIV_ROUND_UP(op_req_q->num_requests,
1948 op_req_q->segment_qd);
1950 op_req_q->q_segments = kcalloc(op_req_q->num_segments,
1951 sizeof(struct segments), GFP_KERNEL);
1952 if (!op_req_q->q_segments)
1955 segments = op_req_q->q_segments;
1956 for (i = 0; i < op_req_q->num_segments; i++) {
1957 segments[i].segment =
1958 dma_alloc_coherent(&mrioc->pdev->dev,
1959 size, &segments[i].segment_dma, GFP_KERNEL);
1960 if (!segments[i].segment)
1962 if (mrioc->enable_segqueue)
1963 q_segment_list_entry[i] =
1964 (unsigned long)segments[i].segment_dma;
1971 * mpi3mr_create_op_reply_q - create operational reply queue
1972 * @mrioc: Adapter instance reference
1973 * @qidx: operational reply queue index
1975 * Create operatinal reply queue by issuing MPI request
1976 * through admin queue.
1978 * Return: 0 on success, non-zero on failure.
1980 static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1982 struct mpi3_create_reply_queue_request create_req;
1983 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1985 u16 reply_qid = 0, midx;
1987 reply_qid = op_reply_q->qid;
1989 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1993 ioc_err(mrioc, "CreateRepQ: called for duplicate qid %d\n",
1999 reply_qid = qidx + 1;
2000 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
2001 if ((mrioc->pdev->device == MPI3_MFGPAGE_DEVID_SAS4116) &&
2002 !mrioc->pdev->revision)
2003 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD4K;
2005 op_reply_q->ephase = 1;
2006 atomic_set(&op_reply_q->pend_ios, 0);
2007 atomic_set(&op_reply_q->in_use, 0);
2008 op_reply_q->enable_irq_poll = false;
2010 if (!op_reply_q->q_segments) {
2011 retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
2013 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
2018 memset(&create_req, 0, sizeof(create_req));
2019 mutex_lock(&mrioc->init_cmds.mutex);
2020 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2022 ioc_err(mrioc, "CreateRepQ: Init command is in use\n");
2025 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2026 mrioc->init_cmds.is_waiting = 1;
2027 mrioc->init_cmds.callback = NULL;
2028 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2029 create_req.function = MPI3_FUNCTION_CREATE_REPLY_QUEUE;
2030 create_req.queue_id = cpu_to_le16(reply_qid);
2032 if (midx < (mrioc->intr_info_count - mrioc->requested_poll_qcount))
2033 op_reply_q->qtype = MPI3MR_DEFAULT_QUEUE;
2035 op_reply_q->qtype = MPI3MR_POLL_QUEUE;
2037 if (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) {
2039 MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE;
2040 create_req.msix_index =
2041 cpu_to_le16(mrioc->intr_info[midx].msix_index);
2043 create_req.msix_index = cpu_to_le16(mrioc->intr_info_count - 1);
2044 ioc_info(mrioc, "create reply queue(polled): for qid(%d), midx(%d)\n",
2046 if (!mrioc->active_poll_qcount)
2047 disable_irq_nosync(pci_irq_vector(mrioc->pdev,
2048 mrioc->intr_info_count - 1));
2051 if (mrioc->enable_segqueue) {
2053 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
2054 create_req.base_address = cpu_to_le64(
2055 op_reply_q->q_segment_list_dma);
2057 create_req.base_address = cpu_to_le64(
2058 op_reply_q->q_segments[0].segment_dma);
2060 create_req.size = cpu_to_le16(op_reply_q->num_replies);
2062 init_completion(&mrioc->init_cmds.done);
2063 retval = mpi3mr_admin_request_post(mrioc, &create_req,
2064 sizeof(create_req), 1);
2066 ioc_err(mrioc, "CreateRepQ: Admin Post failed\n");
2069 wait_for_completion_timeout(&mrioc->init_cmds.done,
2070 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2071 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2072 ioc_err(mrioc, "create reply queue timed out\n");
2073 mpi3mr_check_rh_fault_ioc(mrioc,
2074 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT);
2078 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2079 != MPI3_IOCSTATUS_SUCCESS) {
2081 "CreateRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2082 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2083 mrioc->init_cmds.ioc_loginfo);
2087 op_reply_q->qid = reply_qid;
2088 if (midx < mrioc->intr_info_count)
2089 mrioc->intr_info[midx].op_reply_q = op_reply_q;
2091 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount++ :
2092 mrioc->active_poll_qcount++;
2095 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2096 mutex_unlock(&mrioc->init_cmds.mutex);
2103 * mpi3mr_create_op_req_q - create operational request queue
2104 * @mrioc: Adapter instance reference
2105 * @idx: operational request queue index
2106 * @reply_qid: Reply queue ID
2108 * Create operatinal request queue by issuing MPI request
2109 * through admin queue.
2111 * Return: 0 on success, non-zero on failure.
2113 static int mpi3mr_create_op_req_q(struct mpi3mr_ioc *mrioc, u16 idx,
2116 struct mpi3_create_request_queue_request create_req;
2117 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + idx;
2121 req_qid = op_req_q->qid;
2125 ioc_err(mrioc, "CreateReqQ: called for duplicate qid %d\n",
2132 op_req_q->num_requests = MPI3MR_OP_REQ_Q_QD;
2135 op_req_q->reply_qid = reply_qid;
2136 spin_lock_init(&op_req_q->q_lock);
2138 if (!op_req_q->q_segments) {
2139 retval = mpi3mr_alloc_op_req_q_segments(mrioc, idx);
2141 mpi3mr_free_op_req_q_segments(mrioc, idx);
2146 memset(&create_req, 0, sizeof(create_req));
2147 mutex_lock(&mrioc->init_cmds.mutex);
2148 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2150 ioc_err(mrioc, "CreateReqQ: Init command is in use\n");
2153 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2154 mrioc->init_cmds.is_waiting = 1;
2155 mrioc->init_cmds.callback = NULL;
2156 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2157 create_req.function = MPI3_FUNCTION_CREATE_REQUEST_QUEUE;
2158 create_req.queue_id = cpu_to_le16(req_qid);
2159 if (mrioc->enable_segqueue) {
2161 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
2162 create_req.base_address = cpu_to_le64(
2163 op_req_q->q_segment_list_dma);
2165 create_req.base_address = cpu_to_le64(
2166 op_req_q->q_segments[0].segment_dma);
2167 create_req.reply_queue_id = cpu_to_le16(reply_qid);
2168 create_req.size = cpu_to_le16(op_req_q->num_requests);
2170 init_completion(&mrioc->init_cmds.done);
2171 retval = mpi3mr_admin_request_post(mrioc, &create_req,
2172 sizeof(create_req), 1);
2174 ioc_err(mrioc, "CreateReqQ: Admin Post failed\n");
2177 wait_for_completion_timeout(&mrioc->init_cmds.done,
2178 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2179 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2180 ioc_err(mrioc, "create request queue timed out\n");
2181 mpi3mr_check_rh_fault_ioc(mrioc,
2182 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT);
2186 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2187 != MPI3_IOCSTATUS_SUCCESS) {
2189 "CreateReqQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2190 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2191 mrioc->init_cmds.ioc_loginfo);
2195 op_req_q->qid = req_qid;
2198 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2199 mutex_unlock(&mrioc->init_cmds.mutex);
2206 * mpi3mr_create_op_queues - create operational queue pairs
2207 * @mrioc: Adapter instance reference
2209 * Allocate memory for operational queue meta data and call
2210 * create request and reply queue functions.
2212 * Return: 0 on success, non-zero on failures.
2214 static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
2217 u16 num_queues = 0, i = 0, msix_count_op_q = 1;
2219 num_queues = min_t(int, mrioc->facts.max_op_reply_q,
2220 mrioc->facts.max_op_req_q);
2223 mrioc->intr_info_count - mrioc->op_reply_q_offset;
2224 if (!mrioc->num_queues)
2225 mrioc->num_queues = min_t(int, num_queues, msix_count_op_q);
2227 * During reset set the num_queues to the number of queues
2228 * that was set before the reset.
2230 num_queues = mrioc->num_op_reply_q ?
2231 mrioc->num_op_reply_q : mrioc->num_queues;
2232 ioc_info(mrioc, "trying to create %d operational queue pairs\n",
2235 if (!mrioc->req_qinfo) {
2236 mrioc->req_qinfo = kcalloc(num_queues,
2237 sizeof(struct op_req_qinfo), GFP_KERNEL);
2238 if (!mrioc->req_qinfo) {
2243 mrioc->op_reply_qinfo = kzalloc(sizeof(struct op_reply_qinfo) *
2244 num_queues, GFP_KERNEL);
2245 if (!mrioc->op_reply_qinfo) {
2251 if (mrioc->enable_segqueue)
2253 "allocating operational queues through segmented queues\n");
2255 for (i = 0; i < num_queues; i++) {
2256 if (mpi3mr_create_op_reply_q(mrioc, i)) {
2257 ioc_err(mrioc, "Cannot create OP RepQ %d\n", i);
2260 if (mpi3mr_create_op_req_q(mrioc, i,
2261 mrioc->op_reply_qinfo[i].qid)) {
2262 ioc_err(mrioc, "Cannot create OP ReqQ %d\n", i);
2263 mpi3mr_delete_op_reply_q(mrioc, i);
2269 /* Not even one queue is created successfully*/
2273 mrioc->num_op_reply_q = mrioc->num_op_req_q = i;
2275 "successfully created %d operational queue pairs(default/polled) queue = (%d/%d)\n",
2276 mrioc->num_op_reply_q, mrioc->default_qcount,
2277 mrioc->active_poll_qcount);
2281 kfree(mrioc->req_qinfo);
2282 mrioc->req_qinfo = NULL;
2284 kfree(mrioc->op_reply_qinfo);
2285 mrioc->op_reply_qinfo = NULL;
2291 * mpi3mr_op_request_post - Post request to operational queue
2292 * @mrioc: Adapter reference
2293 * @op_req_q: Operational request queue info
2294 * @req: MPI3 request
2296 * Post the MPI3 request into operational request queue and
2297 * inform the controller, if the queue is full return
2298 * appropriate error.
2300 * Return: 0 on success, non-zero on failure.
2302 int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
2303 struct op_req_qinfo *op_req_q, u8 *req)
2305 u16 pi = 0, max_entries, reply_qidx = 0, midx;
2307 unsigned long flags;
2309 void *segment_base_addr;
2310 u16 req_sz = mrioc->facts.op_req_sz;
2311 struct segments *segments = op_req_q->q_segments;
2313 reply_qidx = op_req_q->reply_qid - 1;
2315 if (mrioc->unrecoverable)
2318 spin_lock_irqsave(&op_req_q->q_lock, flags);
2320 max_entries = op_req_q->num_requests;
2322 if (mpi3mr_check_req_qfull(op_req_q)) {
2323 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
2324 reply_qidx, mrioc->op_reply_q_offset);
2325 mpi3mr_process_op_reply_q(mrioc, mrioc->intr_info[midx].op_reply_q);
2327 if (mpi3mr_check_req_qfull(op_req_q)) {
2333 if (mrioc->reset_in_progress) {
2334 ioc_err(mrioc, "OpReqQ submit reset in progress\n");
2339 segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
2340 req_entry = (u8 *)segment_base_addr +
2341 ((pi % op_req_q->segment_qd) * req_sz);
2343 memset(req_entry, 0, req_sz);
2344 memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
2346 if (++pi == max_entries)
2350 #ifndef CONFIG_PREEMPT_RT
2351 if (atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios)
2352 > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT)
2353 mrioc->op_reply_qinfo[reply_qidx].enable_irq_poll = true;
2355 atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios);
2358 writel(op_req_q->pi,
2359 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].producer_index);
2362 spin_unlock_irqrestore(&op_req_q->q_lock, flags);
2367 * mpi3mr_check_rh_fault_ioc - check reset history and fault
2369 * @mrioc: Adapter instance reference
2370 * @reason_code: reason code for the fault.
2372 * This routine will save snapdump and fault the controller with
2373 * the given reason code if it is not already in the fault or
2374 * not asynchronosuly reset. This will be used to handle
2375 * initilaization time faults/resets/timeout as in those cases
2376 * immediate soft reset invocation is not required.
2380 void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code)
2382 u32 ioc_status, host_diagnostic, timeout;
2384 if (mrioc->unrecoverable) {
2385 ioc_err(mrioc, "controller is unrecoverable\n");
2389 if (!pci_device_is_present(mrioc->pdev)) {
2390 mrioc->unrecoverable = 1;
2391 ioc_err(mrioc, "controller is not present\n");
2395 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2396 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
2397 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
2398 mpi3mr_print_fault_info(mrioc);
2401 mpi3mr_set_diagsave(mrioc);
2402 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
2404 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
2406 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2407 if (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
2410 } while (--timeout);
2414 * mpi3mr_sync_timestamp - Issue time stamp sync request
2415 * @mrioc: Adapter reference
2417 * Issue IO unit control MPI request to synchornize firmware
2418 * timestamp with host time.
2420 * Return: 0 on success, non-zero on failure.
2422 static int mpi3mr_sync_timestamp(struct mpi3mr_ioc *mrioc)
2424 ktime_t current_time;
2425 struct mpi3_iounit_control_request iou_ctrl;
2428 memset(&iou_ctrl, 0, sizeof(iou_ctrl));
2429 mutex_lock(&mrioc->init_cmds.mutex);
2430 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2432 ioc_err(mrioc, "Issue IOUCTL time_stamp: command is in use\n");
2433 mutex_unlock(&mrioc->init_cmds.mutex);
2436 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2437 mrioc->init_cmds.is_waiting = 1;
2438 mrioc->init_cmds.callback = NULL;
2439 iou_ctrl.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2440 iou_ctrl.function = MPI3_FUNCTION_IO_UNIT_CONTROL;
2441 iou_ctrl.operation = MPI3_CTRL_OP_UPDATE_TIMESTAMP;
2442 current_time = ktime_get_real();
2443 iou_ctrl.param64[0] = cpu_to_le64(ktime_to_ms(current_time));
2445 init_completion(&mrioc->init_cmds.done);
2446 retval = mpi3mr_admin_request_post(mrioc, &iou_ctrl,
2447 sizeof(iou_ctrl), 0);
2449 ioc_err(mrioc, "Issue IOUCTL time_stamp: Admin Post failed\n");
2453 wait_for_completion_timeout(&mrioc->init_cmds.done,
2454 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2455 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2456 ioc_err(mrioc, "Issue IOUCTL time_stamp: command timed out\n");
2457 mrioc->init_cmds.is_waiting = 0;
2458 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
2459 mpi3mr_check_rh_fault_ioc(mrioc,
2460 MPI3MR_RESET_FROM_TSU_TIMEOUT);
2464 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2465 != MPI3_IOCSTATUS_SUCCESS) {
2467 "Issue IOUCTL time_stamp: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2468 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2469 mrioc->init_cmds.ioc_loginfo);
2475 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2476 mutex_unlock(&mrioc->init_cmds.mutex);
2483 * mpi3mr_print_pkg_ver - display controller fw package version
2484 * @mrioc: Adapter reference
2486 * Retrieve firmware package version from the component image
2487 * header of the controller flash and display it.
2489 * Return: 0 on success and non-zero on failure.
2491 static int mpi3mr_print_pkg_ver(struct mpi3mr_ioc *mrioc)
2493 struct mpi3_ci_upload_request ci_upload;
2496 dma_addr_t data_dma;
2497 struct mpi3_ci_manifest_mpi *manifest;
2498 u32 data_len = sizeof(struct mpi3_ci_manifest_mpi);
2499 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2501 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2506 memset(&ci_upload, 0, sizeof(ci_upload));
2507 mutex_lock(&mrioc->init_cmds.mutex);
2508 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2509 ioc_err(mrioc, "sending get package version failed due to command in use\n");
2510 mutex_unlock(&mrioc->init_cmds.mutex);
2513 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2514 mrioc->init_cmds.is_waiting = 1;
2515 mrioc->init_cmds.callback = NULL;
2516 ci_upload.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2517 ci_upload.function = MPI3_FUNCTION_CI_UPLOAD;
2518 ci_upload.msg_flags = MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY;
2519 ci_upload.signature1 = cpu_to_le32(MPI3_IMAGE_HEADER_SIGNATURE1_MANIFEST);
2520 ci_upload.image_offset = cpu_to_le32(MPI3_IMAGE_HEADER_SIZE);
2521 ci_upload.segment_size = cpu_to_le32(data_len);
2523 mpi3mr_add_sg_single(&ci_upload.sgl, sgl_flags, data_len,
2525 init_completion(&mrioc->init_cmds.done);
2526 retval = mpi3mr_admin_request_post(mrioc, &ci_upload,
2527 sizeof(ci_upload), 1);
2529 ioc_err(mrioc, "posting get package version failed\n");
2532 wait_for_completion_timeout(&mrioc->init_cmds.done,
2533 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2534 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2535 ioc_err(mrioc, "get package version timed out\n");
2536 mpi3mr_check_rh_fault_ioc(mrioc,
2537 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT);
2541 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2542 == MPI3_IOCSTATUS_SUCCESS) {
2543 manifest = (struct mpi3_ci_manifest_mpi *) data;
2544 if (manifest->manifest_type == MPI3_CI_MANIFEST_TYPE_MPI) {
2546 "firmware package version(%d.%d.%d.%d.%05d-%05d)\n",
2547 manifest->package_version.gen_major,
2548 manifest->package_version.gen_minor,
2549 manifest->package_version.phase_major,
2550 manifest->package_version.phase_minor,
2551 manifest->package_version.customer_id,
2552 manifest->package_version.build_num);
2557 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2558 mutex_unlock(&mrioc->init_cmds.mutex);
2562 dma_free_coherent(&mrioc->pdev->dev, data_len, data,
2568 * mpi3mr_watchdog_work - watchdog thread to monitor faults
2569 * @work: work struct
2571 * Watch dog work periodically executed (1 second interval) to
2572 * monitor firmware fault and to issue periodic timer sync to
2577 static void mpi3mr_watchdog_work(struct work_struct *work)
2579 struct mpi3mr_ioc *mrioc =
2580 container_of(work, struct mpi3mr_ioc, watchdog_work.work);
2581 unsigned long flags;
2582 enum mpi3mr_iocstate ioc_state;
2583 u32 fault, host_diagnostic, ioc_status;
2584 u32 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
2586 if (mrioc->reset_in_progress)
2589 if (!mrioc->unrecoverable && !pci_device_is_present(mrioc->pdev)) {
2590 ioc_err(mrioc, "watchdog could not detect the controller\n");
2591 mrioc->unrecoverable = 1;
2594 if (mrioc->unrecoverable) {
2596 "flush pending commands for unrecoverable controller\n");
2597 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
2601 if (mrioc->ts_update_counter++ >= MPI3MR_TSUPDATE_INTERVAL) {
2602 mrioc->ts_update_counter = 0;
2603 mpi3mr_sync_timestamp(mrioc);
2606 if ((mrioc->prepare_for_reset) &&
2607 ((mrioc->prepare_for_reset_timeout_counter++) >=
2608 MPI3MR_PREPARE_FOR_RESET_TIMEOUT)) {
2609 mpi3mr_soft_reset_handler(mrioc,
2610 MPI3MR_RESET_FROM_CIACTVRST_TIMER, 1);
2614 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2615 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
2616 mpi3mr_soft_reset_handler(mrioc, MPI3MR_RESET_FROM_FIRMWARE, 0);
2620 /*Check for fault state every one second and issue Soft reset*/
2621 ioc_state = mpi3mr_get_iocstate(mrioc);
2622 if (ioc_state != MRIOC_STATE_FAULT)
2625 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
2626 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2627 if (host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS) {
2628 if (!mrioc->diagsave_timeout) {
2629 mpi3mr_print_fault_info(mrioc);
2630 ioc_warn(mrioc, "diag save in progress\n");
2632 if ((mrioc->diagsave_timeout++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT)
2636 mpi3mr_print_fault_info(mrioc);
2637 mrioc->diagsave_timeout = 0;
2640 case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED:
2641 case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED:
2643 "controller requires system power cycle, marking controller as unrecoverable\n");
2644 mrioc->unrecoverable = 1;
2646 case MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS:
2648 case MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET:
2649 reset_reason = MPI3MR_RESET_FROM_CIACTIV_FAULT;
2654 mpi3mr_soft_reset_handler(mrioc, reset_reason, 0);
2658 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2659 if (mrioc->watchdog_work_q)
2660 queue_delayed_work(mrioc->watchdog_work_q,
2661 &mrioc->watchdog_work,
2662 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2663 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2668 * mpi3mr_start_watchdog - Start watchdog
2669 * @mrioc: Adapter instance reference
2671 * Create and start the watchdog thread to monitor controller
2676 void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc)
2678 if (mrioc->watchdog_work_q)
2681 INIT_DELAYED_WORK(&mrioc->watchdog_work, mpi3mr_watchdog_work);
2682 snprintf(mrioc->watchdog_work_q_name,
2683 sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
2685 mrioc->watchdog_work_q =
2686 create_singlethread_workqueue(mrioc->watchdog_work_q_name);
2687 if (!mrioc->watchdog_work_q) {
2688 ioc_err(mrioc, "%s: failed (line=%d)\n", __func__, __LINE__);
2692 if (mrioc->watchdog_work_q)
2693 queue_delayed_work(mrioc->watchdog_work_q,
2694 &mrioc->watchdog_work,
2695 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2699 * mpi3mr_stop_watchdog - Stop watchdog
2700 * @mrioc: Adapter instance reference
2702 * Stop the watchdog thread created to monitor controller
2707 void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc)
2709 unsigned long flags;
2710 struct workqueue_struct *wq;
2712 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2713 wq = mrioc->watchdog_work_q;
2714 mrioc->watchdog_work_q = NULL;
2715 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2717 if (!cancel_delayed_work_sync(&mrioc->watchdog_work))
2718 flush_workqueue(wq);
2719 destroy_workqueue(wq);
2724 * mpi3mr_setup_admin_qpair - Setup admin queue pair
2725 * @mrioc: Adapter instance reference
2727 * Allocate memory for admin queue pair if required and register
2728 * the admin queue with the controller.
2730 * Return: 0 on success, non-zero on failures.
2732 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
2735 u32 num_admin_entries = 0;
2737 mrioc->admin_req_q_sz = MPI3MR_ADMIN_REQ_Q_SIZE;
2738 mrioc->num_admin_req = mrioc->admin_req_q_sz /
2739 MPI3MR_ADMIN_REQ_FRAME_SZ;
2740 mrioc->admin_req_ci = mrioc->admin_req_pi = 0;
2742 mrioc->admin_reply_q_sz = MPI3MR_ADMIN_REPLY_Q_SIZE;
2743 mrioc->num_admin_replies = mrioc->admin_reply_q_sz /
2744 MPI3MR_ADMIN_REPLY_FRAME_SZ;
2745 mrioc->admin_reply_ci = 0;
2746 mrioc->admin_reply_ephase = 1;
2747 atomic_set(&mrioc->admin_reply_q_in_use, 0);
2749 if (!mrioc->admin_req_base) {
2750 mrioc->admin_req_base = dma_alloc_coherent(&mrioc->pdev->dev,
2751 mrioc->admin_req_q_sz, &mrioc->admin_req_dma, GFP_KERNEL);
2753 if (!mrioc->admin_req_base) {
2758 mrioc->admin_reply_base = dma_alloc_coherent(&mrioc->pdev->dev,
2759 mrioc->admin_reply_q_sz, &mrioc->admin_reply_dma,
2762 if (!mrioc->admin_reply_base) {
2768 num_admin_entries = (mrioc->num_admin_replies << 16) |
2769 (mrioc->num_admin_req);
2770 writel(num_admin_entries, &mrioc->sysif_regs->admin_queue_num_entries);
2771 mpi3mr_writeq(mrioc->admin_req_dma,
2772 &mrioc->sysif_regs->admin_request_queue_address);
2773 mpi3mr_writeq(mrioc->admin_reply_dma,
2774 &mrioc->sysif_regs->admin_reply_queue_address);
2775 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
2776 writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
2781 if (mrioc->admin_reply_base) {
2782 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
2783 mrioc->admin_reply_base, mrioc->admin_reply_dma);
2784 mrioc->admin_reply_base = NULL;
2786 if (mrioc->admin_req_base) {
2787 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
2788 mrioc->admin_req_base, mrioc->admin_req_dma);
2789 mrioc->admin_req_base = NULL;
2795 * mpi3mr_issue_iocfacts - Send IOC Facts
2796 * @mrioc: Adapter instance reference
2797 * @facts_data: Cached IOC facts data
2799 * Issue IOC Facts MPI request through admin queue and wait for
2800 * the completion of it or time out.
2802 * Return: 0 on success, non-zero on failures.
2804 static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc *mrioc,
2805 struct mpi3_ioc_facts_data *facts_data)
2807 struct mpi3_ioc_facts_request iocfacts_req;
2809 dma_addr_t data_dma;
2810 u32 data_len = sizeof(*facts_data);
2812 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2814 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2822 memset(&iocfacts_req, 0, sizeof(iocfacts_req));
2823 mutex_lock(&mrioc->init_cmds.mutex);
2824 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2826 ioc_err(mrioc, "Issue IOCFacts: Init command is in use\n");
2827 mutex_unlock(&mrioc->init_cmds.mutex);
2830 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2831 mrioc->init_cmds.is_waiting = 1;
2832 mrioc->init_cmds.callback = NULL;
2833 iocfacts_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2834 iocfacts_req.function = MPI3_FUNCTION_IOC_FACTS;
2836 mpi3mr_add_sg_single(&iocfacts_req.sgl, sgl_flags, data_len,
2839 init_completion(&mrioc->init_cmds.done);
2840 retval = mpi3mr_admin_request_post(mrioc, &iocfacts_req,
2841 sizeof(iocfacts_req), 1);
2843 ioc_err(mrioc, "Issue IOCFacts: Admin Post failed\n");
2846 wait_for_completion_timeout(&mrioc->init_cmds.done,
2847 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2848 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2849 ioc_err(mrioc, "ioc_facts timed out\n");
2850 mpi3mr_check_rh_fault_ioc(mrioc,
2851 MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT);
2855 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2856 != MPI3_IOCSTATUS_SUCCESS) {
2858 "Issue IOCFacts: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2859 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2860 mrioc->init_cmds.ioc_loginfo);
2864 memcpy(facts_data, (u8 *)data, data_len);
2865 mpi3mr_process_factsdata(mrioc, facts_data);
2867 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2868 mutex_unlock(&mrioc->init_cmds.mutex);
2872 dma_free_coherent(&mrioc->pdev->dev, data_len, data, data_dma);
2878 * mpi3mr_check_reset_dma_mask - Process IOC facts data
2879 * @mrioc: Adapter instance reference
2881 * Check whether the new DMA mask requested through IOCFacts by
2882 * firmware needs to be set, if so set it .
2884 * Return: 0 on success, non-zero on failure.
2886 static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc *mrioc)
2888 struct pci_dev *pdev = mrioc->pdev;
2890 u64 facts_dma_mask = DMA_BIT_MASK(mrioc->facts.dma_mask);
2892 if (!mrioc->facts.dma_mask || (mrioc->dma_mask <= facts_dma_mask))
2895 ioc_info(mrioc, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
2896 mrioc->dma_mask, facts_dma_mask);
2898 r = dma_set_mask_and_coherent(&pdev->dev, facts_dma_mask);
2900 ioc_err(mrioc, "Setting DMA mask to 0x%016llx failed: %d\n",
2904 mrioc->dma_mask = facts_dma_mask;
2909 * mpi3mr_process_factsdata - Process IOC facts data
2910 * @mrioc: Adapter instance reference
2911 * @facts_data: Cached IOC facts data
2913 * Convert IOC facts data into cpu endianness and cache it in
2918 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
2919 struct mpi3_ioc_facts_data *facts_data)
2921 u32 ioc_config, req_sz, facts_flags;
2923 if ((le16_to_cpu(facts_data->ioc_facts_data_length)) !=
2924 (sizeof(*facts_data) / 4)) {
2926 "IOCFactsdata length mismatch driver_sz(%zu) firmware_sz(%d)\n",
2927 sizeof(*facts_data),
2928 le16_to_cpu(facts_data->ioc_facts_data_length) * 4);
2931 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
2932 req_sz = 1 << ((ioc_config & MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ) >>
2933 MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT);
2934 if (le16_to_cpu(facts_data->ioc_request_frame_size) != (req_sz / 4)) {
2936 "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
2937 req_sz / 4, le16_to_cpu(facts_data->ioc_request_frame_size));
2940 memset(&mrioc->facts, 0, sizeof(mrioc->facts));
2942 facts_flags = le32_to_cpu(facts_data->flags);
2943 mrioc->facts.op_req_sz = req_sz;
2944 mrioc->op_reply_desc_sz = 1 << ((ioc_config &
2945 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ) >>
2946 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT);
2948 mrioc->facts.ioc_num = facts_data->ioc_number;
2949 mrioc->facts.who_init = facts_data->who_init;
2950 mrioc->facts.max_msix_vectors = le16_to_cpu(facts_data->max_msix_vectors);
2951 mrioc->facts.personality = (facts_flags &
2952 MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK);
2953 mrioc->facts.dma_mask = (facts_flags &
2954 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
2955 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
2956 mrioc->facts.protocol_flags = facts_data->protocol_flags;
2957 mrioc->facts.mpi_version = le32_to_cpu(facts_data->mpi_version.word);
2958 mrioc->facts.max_reqs = le16_to_cpu(facts_data->max_outstanding_requests);
2959 mrioc->facts.product_id = le16_to_cpu(facts_data->product_id);
2960 mrioc->facts.reply_sz = le16_to_cpu(facts_data->reply_frame_size) * 4;
2961 mrioc->facts.exceptions = le16_to_cpu(facts_data->ioc_exceptions);
2962 mrioc->facts.max_perids = le16_to_cpu(facts_data->max_persistent_id);
2963 mrioc->facts.max_vds = le16_to_cpu(facts_data->max_vds);
2964 mrioc->facts.max_hpds = le16_to_cpu(facts_data->max_host_pds);
2965 mrioc->facts.max_advhpds = le16_to_cpu(facts_data->max_adv_host_pds);
2966 mrioc->facts.max_raid_pds = le16_to_cpu(facts_data->max_raid_pds);
2967 mrioc->facts.max_nvme = le16_to_cpu(facts_data->max_nvme);
2968 mrioc->facts.max_pcie_switches =
2969 le16_to_cpu(facts_data->max_pcie_switches);
2970 mrioc->facts.max_sasexpanders =
2971 le16_to_cpu(facts_data->max_sas_expanders);
2972 mrioc->facts.max_data_length = le16_to_cpu(facts_data->max_data_length);
2973 mrioc->facts.max_sasinitiators =
2974 le16_to_cpu(facts_data->max_sas_initiators);
2975 mrioc->facts.max_enclosures = le16_to_cpu(facts_data->max_enclosures);
2976 mrioc->facts.min_devhandle = le16_to_cpu(facts_data->min_dev_handle);
2977 mrioc->facts.max_devhandle = le16_to_cpu(facts_data->max_dev_handle);
2978 mrioc->facts.max_op_req_q =
2979 le16_to_cpu(facts_data->max_operational_request_queues);
2980 mrioc->facts.max_op_reply_q =
2981 le16_to_cpu(facts_data->max_operational_reply_queues);
2982 mrioc->facts.ioc_capabilities =
2983 le32_to_cpu(facts_data->ioc_capabilities);
2984 mrioc->facts.fw_ver.build_num =
2985 le16_to_cpu(facts_data->fw_version.build_num);
2986 mrioc->facts.fw_ver.cust_id =
2987 le16_to_cpu(facts_data->fw_version.customer_id);
2988 mrioc->facts.fw_ver.ph_minor = facts_data->fw_version.phase_minor;
2989 mrioc->facts.fw_ver.ph_major = facts_data->fw_version.phase_major;
2990 mrioc->facts.fw_ver.gen_minor = facts_data->fw_version.gen_minor;
2991 mrioc->facts.fw_ver.gen_major = facts_data->fw_version.gen_major;
2992 mrioc->msix_count = min_t(int, mrioc->msix_count,
2993 mrioc->facts.max_msix_vectors);
2994 mrioc->facts.sge_mod_mask = facts_data->sge_modifier_mask;
2995 mrioc->facts.sge_mod_value = facts_data->sge_modifier_value;
2996 mrioc->facts.sge_mod_shift = facts_data->sge_modifier_shift;
2997 mrioc->facts.shutdown_timeout =
2998 le16_to_cpu(facts_data->shutdown_timeout);
3000 mrioc->facts.max_dev_per_tg =
3001 facts_data->max_devices_per_throttle_group;
3002 mrioc->facts.io_throttle_data_length =
3003 le16_to_cpu(facts_data->io_throttle_data_length);
3004 mrioc->facts.max_io_throttle_group =
3005 le16_to_cpu(facts_data->max_io_throttle_group);
3006 mrioc->facts.io_throttle_low = le16_to_cpu(facts_data->io_throttle_low);
3007 mrioc->facts.io_throttle_high =
3008 le16_to_cpu(facts_data->io_throttle_high);
3010 if (mrioc->facts.max_data_length ==
3011 MPI3_IOCFACTS_MAX_DATA_LENGTH_NOT_REPORTED)
3012 mrioc->facts.max_data_length = MPI3MR_DEFAULT_MAX_IO_SIZE;
3014 mrioc->facts.max_data_length *= MPI3MR_PAGE_SIZE_4K;
3015 /* Store in 512b block count */
3016 if (mrioc->facts.io_throttle_data_length)
3017 mrioc->io_throttle_data_length =
3018 (mrioc->facts.io_throttle_data_length * 2 * 4);
3020 /* set the length to 1MB + 1K to disable throttle */
3021 mrioc->io_throttle_data_length = (mrioc->facts.max_data_length / 512) + 2;
3023 mrioc->io_throttle_high = (mrioc->facts.io_throttle_high * 2 * 1024);
3024 mrioc->io_throttle_low = (mrioc->facts.io_throttle_low * 2 * 1024);
3026 ioc_info(mrioc, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
3027 mrioc->facts.ioc_num, mrioc->facts.max_op_req_q,
3028 mrioc->facts.max_op_reply_q, mrioc->facts.max_devhandle);
3030 "maxreqs(%d), mindh(%d) maxvectors(%d) maxperids(%d)\n",
3031 mrioc->facts.max_reqs, mrioc->facts.min_devhandle,
3032 mrioc->facts.max_msix_vectors, mrioc->facts.max_perids);
3033 ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
3034 mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value,
3035 mrioc->facts.sge_mod_shift);
3036 ioc_info(mrioc, "DMA mask %d InitialPE status 0x%x max_data_len (%d)\n",
3037 mrioc->facts.dma_mask, (facts_flags &
3038 MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK), mrioc->facts.max_data_length);
3040 "max_dev_per_throttle_group(%d), max_throttle_groups(%d)\n",
3041 mrioc->facts.max_dev_per_tg, mrioc->facts.max_io_throttle_group);
3043 "io_throttle_data_len(%dKiB), io_throttle_high(%dMiB), io_throttle_low(%dMiB)\n",
3044 mrioc->facts.io_throttle_data_length * 4,
3045 mrioc->facts.io_throttle_high, mrioc->facts.io_throttle_low);
3049 * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
3050 * @mrioc: Adapter instance reference
3052 * Allocate and initialize the reply free buffers, sense
3053 * buffers, reply free queue and sense buffer queue.
3055 * Return: 0 on success, non-zero on failures.
3057 static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
3062 if (mrioc->init_cmds.reply)
3065 mrioc->init_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3066 if (!mrioc->init_cmds.reply)
3069 mrioc->bsg_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3070 if (!mrioc->bsg_cmds.reply)
3073 mrioc->transport_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3074 if (!mrioc->transport_cmds.reply)
3077 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
3078 mrioc->dev_rmhs_cmds[i].reply = kzalloc(mrioc->reply_sz,
3080 if (!mrioc->dev_rmhs_cmds[i].reply)
3084 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
3085 mrioc->evtack_cmds[i].reply = kzalloc(mrioc->reply_sz,
3087 if (!mrioc->evtack_cmds[i].reply)
3091 mrioc->host_tm_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3092 if (!mrioc->host_tm_cmds.reply)
3095 mrioc->pel_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3096 if (!mrioc->pel_cmds.reply)
3099 mrioc->pel_abort_cmd.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
3100 if (!mrioc->pel_abort_cmd.reply)
3103 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
3104 mrioc->removepend_bitmap = bitmap_zalloc(mrioc->dev_handle_bitmap_bits,
3106 if (!mrioc->removepend_bitmap)
3109 mrioc->devrem_bitmap = bitmap_zalloc(MPI3MR_NUM_DEVRMCMD, GFP_KERNEL);
3110 if (!mrioc->devrem_bitmap)
3113 mrioc->evtack_cmds_bitmap = bitmap_zalloc(MPI3MR_NUM_EVTACKCMD,
3115 if (!mrioc->evtack_cmds_bitmap)
3118 mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
3119 mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
3120 mrioc->num_sense_bufs = mrioc->facts.max_reqs / MPI3MR_SENSEBUF_FACTOR;
3121 mrioc->sense_buf_q_sz = mrioc->num_sense_bufs + 1;
3123 /* reply buffer pool, 16 byte align */
3124 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3125 mrioc->reply_buf_pool = dma_pool_create("reply_buf pool",
3126 &mrioc->pdev->dev, sz, 16, 0);
3127 if (!mrioc->reply_buf_pool) {
3128 ioc_err(mrioc, "reply buf pool: dma_pool_create failed\n");
3132 mrioc->reply_buf = dma_pool_zalloc(mrioc->reply_buf_pool, GFP_KERNEL,
3133 &mrioc->reply_buf_dma);
3134 if (!mrioc->reply_buf)
3137 mrioc->reply_buf_dma_max_address = mrioc->reply_buf_dma + sz;
3139 /* reply free queue, 8 byte align */
3140 sz = mrioc->reply_free_qsz * 8;
3141 mrioc->reply_free_q_pool = dma_pool_create("reply_free_q pool",
3142 &mrioc->pdev->dev, sz, 8, 0);
3143 if (!mrioc->reply_free_q_pool) {
3144 ioc_err(mrioc, "reply_free_q pool: dma_pool_create failed\n");
3147 mrioc->reply_free_q = dma_pool_zalloc(mrioc->reply_free_q_pool,
3148 GFP_KERNEL, &mrioc->reply_free_q_dma);
3149 if (!mrioc->reply_free_q)
3152 /* sense buffer pool, 4 byte align */
3153 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3154 mrioc->sense_buf_pool = dma_pool_create("sense_buf pool",
3155 &mrioc->pdev->dev, sz, 4, 0);
3156 if (!mrioc->sense_buf_pool) {
3157 ioc_err(mrioc, "sense_buf pool: dma_pool_create failed\n");
3160 mrioc->sense_buf = dma_pool_zalloc(mrioc->sense_buf_pool, GFP_KERNEL,
3161 &mrioc->sense_buf_dma);
3162 if (!mrioc->sense_buf)
3165 /* sense buffer queue, 8 byte align */
3166 sz = mrioc->sense_buf_q_sz * 8;
3167 mrioc->sense_buf_q_pool = dma_pool_create("sense_buf_q pool",
3168 &mrioc->pdev->dev, sz, 8, 0);
3169 if (!mrioc->sense_buf_q_pool) {
3170 ioc_err(mrioc, "sense_buf_q pool: dma_pool_create failed\n");
3173 mrioc->sense_buf_q = dma_pool_zalloc(mrioc->sense_buf_q_pool,
3174 GFP_KERNEL, &mrioc->sense_buf_q_dma);
3175 if (!mrioc->sense_buf_q)
3186 * mpimr_initialize_reply_sbuf_queues - initialize reply sense
3188 * @mrioc: Adapter instance reference
3190 * Helper function to initialize reply and sense buffers along
3191 * with some debug prints.
3195 static void mpimr_initialize_reply_sbuf_queues(struct mpi3mr_ioc *mrioc)
3198 dma_addr_t phy_addr;
3200 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3202 "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3203 mrioc->reply_buf, mrioc->num_reply_bufs, mrioc->reply_sz,
3204 (sz / 1024), (unsigned long long)mrioc->reply_buf_dma);
3205 sz = mrioc->reply_free_qsz * 8;
3207 "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3208 mrioc->reply_free_q, mrioc->reply_free_qsz, 8, (sz / 1024),
3209 (unsigned long long)mrioc->reply_free_q_dma);
3210 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3212 "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3213 mrioc->sense_buf, mrioc->num_sense_bufs, MPI3MR_SENSE_BUF_SZ,
3214 (sz / 1024), (unsigned long long)mrioc->sense_buf_dma);
3215 sz = mrioc->sense_buf_q_sz * 8;
3217 "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3218 mrioc->sense_buf_q, mrioc->sense_buf_q_sz, 8, (sz / 1024),
3219 (unsigned long long)mrioc->sense_buf_q_dma);
3221 /* initialize Reply buffer Queue */
3222 for (i = 0, phy_addr = mrioc->reply_buf_dma;
3223 i < mrioc->num_reply_bufs; i++, phy_addr += mrioc->reply_sz)
3224 mrioc->reply_free_q[i] = cpu_to_le64(phy_addr);
3225 mrioc->reply_free_q[i] = cpu_to_le64(0);
3227 /* initialize Sense Buffer Queue */
3228 for (i = 0, phy_addr = mrioc->sense_buf_dma;
3229 i < mrioc->num_sense_bufs; i++, phy_addr += MPI3MR_SENSE_BUF_SZ)
3230 mrioc->sense_buf_q[i] = cpu_to_le64(phy_addr);
3231 mrioc->sense_buf_q[i] = cpu_to_le64(0);
3235 * mpi3mr_issue_iocinit - Send IOC Init
3236 * @mrioc: Adapter instance reference
3238 * Issue IOC Init MPI request through admin queue and wait for
3239 * the completion of it or time out.
3241 * Return: 0 on success, non-zero on failures.
3243 static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
3245 struct mpi3_ioc_init_request iocinit_req;
3246 struct mpi3_driver_info_layout *drv_info;
3247 dma_addr_t data_dma;
3248 u32 data_len = sizeof(*drv_info);
3250 ktime_t current_time;
3252 drv_info = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
3258 mpimr_initialize_reply_sbuf_queues(mrioc);
3260 drv_info->information_length = cpu_to_le32(data_len);
3261 strscpy(drv_info->driver_signature, "Broadcom", sizeof(drv_info->driver_signature));
3262 strscpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));
3263 strscpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));
3264 strscpy(drv_info->driver_name, MPI3MR_DRIVER_NAME, sizeof(drv_info->driver_name));
3265 strscpy(drv_info->driver_version, MPI3MR_DRIVER_VERSION, sizeof(drv_info->driver_version));
3266 strscpy(drv_info->driver_release_date, MPI3MR_DRIVER_RELDATE,
3267 sizeof(drv_info->driver_release_date));
3268 drv_info->driver_capabilities = 0;
3269 memcpy((u8 *)&mrioc->driver_info, (u8 *)drv_info,
3270 sizeof(mrioc->driver_info));
3272 memset(&iocinit_req, 0, sizeof(iocinit_req));
3273 mutex_lock(&mrioc->init_cmds.mutex);
3274 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3276 ioc_err(mrioc, "Issue IOCInit: Init command is in use\n");
3277 mutex_unlock(&mrioc->init_cmds.mutex);
3280 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3281 mrioc->init_cmds.is_waiting = 1;
3282 mrioc->init_cmds.callback = NULL;
3283 iocinit_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3284 iocinit_req.function = MPI3_FUNCTION_IOC_INIT;
3285 iocinit_req.mpi_version.mpi3_version.dev = MPI3_VERSION_DEV;
3286 iocinit_req.mpi_version.mpi3_version.unit = MPI3_VERSION_UNIT;
3287 iocinit_req.mpi_version.mpi3_version.major = MPI3_VERSION_MAJOR;
3288 iocinit_req.mpi_version.mpi3_version.minor = MPI3_VERSION_MINOR;
3289 iocinit_req.who_init = MPI3_WHOINIT_HOST_DRIVER;
3290 iocinit_req.reply_free_queue_depth = cpu_to_le16(mrioc->reply_free_qsz);
3291 iocinit_req.reply_free_queue_address =
3292 cpu_to_le64(mrioc->reply_free_q_dma);
3293 iocinit_req.sense_buffer_length = cpu_to_le16(MPI3MR_SENSE_BUF_SZ);
3294 iocinit_req.sense_buffer_free_queue_depth =
3295 cpu_to_le16(mrioc->sense_buf_q_sz);
3296 iocinit_req.sense_buffer_free_queue_address =
3297 cpu_to_le64(mrioc->sense_buf_q_dma);
3298 iocinit_req.driver_information_address = cpu_to_le64(data_dma);
3300 current_time = ktime_get_real();
3301 iocinit_req.time_stamp = cpu_to_le64(ktime_to_ms(current_time));
3303 iocinit_req.msg_flags |=
3304 MPI3_IOCINIT_MSGFLAGS_SCSIIOSTATUSREPLY_SUPPORTED;
3306 init_completion(&mrioc->init_cmds.done);
3307 retval = mpi3mr_admin_request_post(mrioc, &iocinit_req,
3308 sizeof(iocinit_req), 1);
3310 ioc_err(mrioc, "Issue IOCInit: Admin Post failed\n");
3313 wait_for_completion_timeout(&mrioc->init_cmds.done,
3314 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3315 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3316 mpi3mr_check_rh_fault_ioc(mrioc,
3317 MPI3MR_RESET_FROM_IOCINIT_TIMEOUT);
3318 ioc_err(mrioc, "ioc_init timed out\n");
3322 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3323 != MPI3_IOCSTATUS_SUCCESS) {
3325 "Issue IOCInit: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3326 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3327 mrioc->init_cmds.ioc_loginfo);
3332 mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
3333 writel(mrioc->reply_free_queue_host_index,
3334 &mrioc->sysif_regs->reply_free_host_index);
3336 mrioc->sbq_host_index = mrioc->num_sense_bufs;
3337 writel(mrioc->sbq_host_index,
3338 &mrioc->sysif_regs->sense_buffer_free_host_index);
3340 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3341 mutex_unlock(&mrioc->init_cmds.mutex);
3345 dma_free_coherent(&mrioc->pdev->dev, data_len, drv_info,
3352 * mpi3mr_unmask_events - Unmask events in event mask bitmap
3353 * @mrioc: Adapter instance reference
3354 * @event: MPI event ID
3356 * Un mask the specific event by resetting the event_mask
3359 * Return: 0 on success, non-zero on failures.
3361 static void mpi3mr_unmask_events(struct mpi3mr_ioc *mrioc, u16 event)
3369 desired_event = (1 << (event % 32));
3372 mrioc->event_masks[word] &= ~desired_event;
3376 * mpi3mr_issue_event_notification - Send event notification
3377 * @mrioc: Adapter instance reference
3379 * Issue event notification MPI request through admin queue and
3380 * wait for the completion of it or time out.
3382 * Return: 0 on success, non-zero on failures.
3384 static int mpi3mr_issue_event_notification(struct mpi3mr_ioc *mrioc)
3386 struct mpi3_event_notification_request evtnotify_req;
3390 memset(&evtnotify_req, 0, sizeof(evtnotify_req));
3391 mutex_lock(&mrioc->init_cmds.mutex);
3392 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3394 ioc_err(mrioc, "Issue EvtNotify: Init command is in use\n");
3395 mutex_unlock(&mrioc->init_cmds.mutex);
3398 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3399 mrioc->init_cmds.is_waiting = 1;
3400 mrioc->init_cmds.callback = NULL;
3401 evtnotify_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3402 evtnotify_req.function = MPI3_FUNCTION_EVENT_NOTIFICATION;
3403 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3404 evtnotify_req.event_masks[i] =
3405 cpu_to_le32(mrioc->event_masks[i]);
3406 init_completion(&mrioc->init_cmds.done);
3407 retval = mpi3mr_admin_request_post(mrioc, &evtnotify_req,
3408 sizeof(evtnotify_req), 1);
3410 ioc_err(mrioc, "Issue EvtNotify: Admin Post failed\n");
3413 wait_for_completion_timeout(&mrioc->init_cmds.done,
3414 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3415 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3416 ioc_err(mrioc, "event notification timed out\n");
3417 mpi3mr_check_rh_fault_ioc(mrioc,
3418 MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT);
3422 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3423 != MPI3_IOCSTATUS_SUCCESS) {
3425 "Issue EvtNotify: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3426 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3427 mrioc->init_cmds.ioc_loginfo);
3433 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3434 mutex_unlock(&mrioc->init_cmds.mutex);
3440 * mpi3mr_process_event_ack - Process event acknowledgment
3441 * @mrioc: Adapter instance reference
3442 * @event: MPI3 event ID
3443 * @event_ctx: event context
3445 * Send event acknowledgment through admin queue and wait for
3448 * Return: 0 on success, non-zero on failures.
3450 int mpi3mr_process_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
3453 struct mpi3_event_ack_request evtack_req;
3456 memset(&evtack_req, 0, sizeof(evtack_req));
3457 mutex_lock(&mrioc->init_cmds.mutex);
3458 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3460 ioc_err(mrioc, "Send EvtAck: Init command is in use\n");
3461 mutex_unlock(&mrioc->init_cmds.mutex);
3464 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3465 mrioc->init_cmds.is_waiting = 1;
3466 mrioc->init_cmds.callback = NULL;
3467 evtack_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3468 evtack_req.function = MPI3_FUNCTION_EVENT_ACK;
3469 evtack_req.event = event;
3470 evtack_req.event_context = cpu_to_le32(event_ctx);
3472 init_completion(&mrioc->init_cmds.done);
3473 retval = mpi3mr_admin_request_post(mrioc, &evtack_req,
3474 sizeof(evtack_req), 1);
3476 ioc_err(mrioc, "Send EvtAck: Admin Post failed\n");
3479 wait_for_completion_timeout(&mrioc->init_cmds.done,
3480 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3481 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3482 ioc_err(mrioc, "Issue EvtNotify: command timed out\n");
3483 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
3484 mpi3mr_check_rh_fault_ioc(mrioc,
3485 MPI3MR_RESET_FROM_EVTACK_TIMEOUT);
3489 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3490 != MPI3_IOCSTATUS_SUCCESS) {
3492 "Send EvtAck: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3493 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3494 mrioc->init_cmds.ioc_loginfo);
3500 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3501 mutex_unlock(&mrioc->init_cmds.mutex);
3507 * mpi3mr_alloc_chain_bufs - Allocate chain buffers
3508 * @mrioc: Adapter instance reference
3510 * Allocate chain buffers and set a bitmap to indicate free
3511 * chain buffers. Chain buffers are used to pass the SGE
3512 * information along with MPI3 SCSI IO requests for host I/O.
3514 * Return: 0 on success, non-zero on failure
3516 static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
3522 if (mrioc->chain_sgl_list)
3525 num_chains = mrioc->max_host_ios / MPI3MR_CHAINBUF_FACTOR;
3527 if (prot_mask & (SHOST_DIX_TYPE0_PROTECTION
3528 | SHOST_DIX_TYPE1_PROTECTION
3529 | SHOST_DIX_TYPE2_PROTECTION
3530 | SHOST_DIX_TYPE3_PROTECTION))
3531 num_chains += (num_chains / MPI3MR_CHAINBUFDIX_FACTOR);
3533 mrioc->chain_buf_count = num_chains;
3534 sz = sizeof(struct chain_element) * num_chains;
3535 mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
3536 if (!mrioc->chain_sgl_list)
3539 if (mrioc->max_sgl_entries > (mrioc->facts.max_data_length /
3540 MPI3MR_PAGE_SIZE_4K))
3541 mrioc->max_sgl_entries = mrioc->facts.max_data_length /
3542 MPI3MR_PAGE_SIZE_4K;
3543 sz = mrioc->max_sgl_entries * sizeof(struct mpi3_sge_common);
3544 ioc_info(mrioc, "number of sgl entries=%d chain buffer size=%dKB\n",
3545 mrioc->max_sgl_entries, sz/1024);
3547 mrioc->chain_buf_pool = dma_pool_create("chain_buf pool",
3548 &mrioc->pdev->dev, sz, 16, 0);
3549 if (!mrioc->chain_buf_pool) {
3550 ioc_err(mrioc, "chain buf pool: dma_pool_create failed\n");
3554 for (i = 0; i < num_chains; i++) {
3555 mrioc->chain_sgl_list[i].addr =
3556 dma_pool_zalloc(mrioc->chain_buf_pool, GFP_KERNEL,
3557 &mrioc->chain_sgl_list[i].dma_addr);
3559 if (!mrioc->chain_sgl_list[i].addr)
3562 mrioc->chain_bitmap = bitmap_zalloc(num_chains, GFP_KERNEL);
3563 if (!mrioc->chain_bitmap)
3572 * mpi3mr_port_enable_complete - Mark port enable complete
3573 * @mrioc: Adapter instance reference
3574 * @drv_cmd: Internal command tracker
3576 * Call back for asynchronous port enable request sets the
3577 * driver command to indicate port enable request is complete.
3581 static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
3582 struct mpi3mr_drv_cmd *drv_cmd)
3584 drv_cmd->callback = NULL;
3585 mrioc->scan_started = 0;
3586 if (drv_cmd->state & MPI3MR_CMD_RESET)
3587 mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
3589 mrioc->scan_failed = drv_cmd->ioc_status;
3590 drv_cmd->state = MPI3MR_CMD_NOTUSED;
3594 * mpi3mr_issue_port_enable - Issue Port Enable
3595 * @mrioc: Adapter instance reference
3596 * @async: Flag to wait for completion or not
3598 * Issue Port Enable MPI request through admin queue and if the
3599 * async flag is not set wait for the completion of the port
3600 * enable or time out.
3602 * Return: 0 on success, non-zero on failures.
3604 int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
3606 struct mpi3_port_enable_request pe_req;
3608 u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
3610 memset(&pe_req, 0, sizeof(pe_req));
3611 mutex_lock(&mrioc->init_cmds.mutex);
3612 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3614 ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
3615 mutex_unlock(&mrioc->init_cmds.mutex);
3618 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3620 mrioc->init_cmds.is_waiting = 0;
3621 mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
3623 mrioc->init_cmds.is_waiting = 1;
3624 mrioc->init_cmds.callback = NULL;
3625 init_completion(&mrioc->init_cmds.done);
3627 pe_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3628 pe_req.function = MPI3_FUNCTION_PORT_ENABLE;
3630 retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
3632 ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
3636 mutex_unlock(&mrioc->init_cmds.mutex);
3640 wait_for_completion_timeout(&mrioc->init_cmds.done, (pe_timeout * HZ));
3641 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3642 ioc_err(mrioc, "port enable timed out\n");
3644 mpi3mr_check_rh_fault_ioc(mrioc, MPI3MR_RESET_FROM_PE_TIMEOUT);
3647 mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
3650 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3651 mutex_unlock(&mrioc->init_cmds.mutex);
3656 /* Protocol type to name mapper structure */
3657 static const struct {
3660 } mpi3mr_protocols[] = {
3661 { MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR, "Initiator" },
3662 { MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET, "Target" },
3663 { MPI3_IOCFACTS_PROTOCOL_NVME, "NVMe attachment" },
3666 /* Capability to name mapper structure*/
3667 static const struct {
3670 } mpi3mr_capabilities[] = {
3671 { MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE, "RAID" },
3672 { MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED, "MultiPath" },
3676 * mpi3mr_print_ioc_info - Display controller information
3677 * @mrioc: Adapter instance reference
3679 * Display controller personalit, capability, supported
3685 mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
3687 int i = 0, bytes_written = 0;
3688 char personality[16];
3689 char protocol[50] = {0};
3690 char capabilities[100] = {0};
3691 struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
3693 switch (mrioc->facts.personality) {
3694 case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
3695 strncpy(personality, "Enhanced HBA", sizeof(personality));
3697 case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
3698 strncpy(personality, "RAID", sizeof(personality));
3701 strncpy(personality, "Unknown", sizeof(personality));
3705 ioc_info(mrioc, "Running in %s Personality", personality);
3707 ioc_info(mrioc, "FW version(%d.%d.%d.%d.%d.%d)\n",
3708 fwver->gen_major, fwver->gen_minor, fwver->ph_major,
3709 fwver->ph_minor, fwver->cust_id, fwver->build_num);
3711 for (i = 0; i < ARRAY_SIZE(mpi3mr_protocols); i++) {
3712 if (mrioc->facts.protocol_flags &
3713 mpi3mr_protocols[i].protocol) {
3714 bytes_written += scnprintf(protocol + bytes_written,
3715 sizeof(protocol) - bytes_written, "%s%s",
3716 bytes_written ? "," : "",
3717 mpi3mr_protocols[i].name);
3722 for (i = 0; i < ARRAY_SIZE(mpi3mr_capabilities); i++) {
3723 if (mrioc->facts.protocol_flags &
3724 mpi3mr_capabilities[i].capability) {
3725 bytes_written += scnprintf(capabilities + bytes_written,
3726 sizeof(capabilities) - bytes_written, "%s%s",
3727 bytes_written ? "," : "",
3728 mpi3mr_capabilities[i].name);
3732 ioc_info(mrioc, "Protocol=(%s), Capabilities=(%s)\n",
3733 protocol, capabilities);
3737 * mpi3mr_cleanup_resources - Free PCI resources
3738 * @mrioc: Adapter instance reference
3740 * Unmap PCI device memory and disable PCI device.
3742 * Return: 0 on success and non-zero on failure.
3744 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
3746 struct pci_dev *pdev = mrioc->pdev;
3748 mpi3mr_cleanup_isr(mrioc);
3750 if (mrioc->sysif_regs) {
3751 iounmap((void __iomem *)mrioc->sysif_regs);
3752 mrioc->sysif_regs = NULL;
3755 if (pci_is_enabled(pdev)) {
3757 pci_release_selected_regions(pdev, mrioc->bars);
3758 pci_disable_device(pdev);
3763 * mpi3mr_setup_resources - Enable PCI resources
3764 * @mrioc: Adapter instance reference
3766 * Enable PCI device memory, MSI-x registers and set DMA mask.
3768 * Return: 0 on success and non-zero on failure.
3770 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
3772 struct pci_dev *pdev = mrioc->pdev;
3774 int i, retval = 0, capb = 0;
3775 u16 message_control;
3776 u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
3777 ((sizeof(dma_addr_t) > 4) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
3779 if (pci_enable_device_mem(pdev)) {
3780 ioc_err(mrioc, "pci_enable_device_mem: failed\n");
3785 capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3787 ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
3791 mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
3793 if (pci_request_selected_regions(pdev, mrioc->bars,
3794 mrioc->driver_name)) {
3795 ioc_err(mrioc, "pci_request_selected_regions: failed\n");
3800 for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
3801 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
3802 mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
3803 memap_sz = pci_resource_len(pdev, i);
3805 ioremap(mrioc->sysif_regs_phys, memap_sz);
3810 pci_set_master(pdev);
3812 retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
3814 if (dma_mask != DMA_BIT_MASK(32)) {
3815 ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
3816 dma_mask = DMA_BIT_MASK(32);
3817 retval = dma_set_mask_and_coherent(&pdev->dev,
3821 mrioc->dma_mask = 0;
3822 ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
3826 mrioc->dma_mask = dma_mask;
3828 if (!mrioc->sysif_regs) {
3830 "Unable to map adapter memory or resource not found\n");
3835 pci_read_config_word(pdev, capb + 2, &message_control);
3836 mrioc->msix_count = (message_control & 0x3FF) + 1;
3838 pci_save_state(pdev);
3840 pci_set_drvdata(pdev, mrioc->shost);
3842 mpi3mr_ioc_disable_intr(mrioc);
3844 ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
3845 (unsigned long long)mrioc->sysif_regs_phys,
3846 mrioc->sysif_regs, memap_sz);
3847 ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
3850 if (!reset_devices && poll_queues > 0)
3851 mrioc->requested_poll_qcount = min_t(int, poll_queues,
3852 mrioc->msix_count - 2);
3856 mpi3mr_cleanup_resources(mrioc);
3861 * mpi3mr_enable_events - Enable required events
3862 * @mrioc: Adapter instance reference
3864 * This routine unmasks the events required by the driver by
3865 * sennding appropriate event mask bitmapt through an event
3866 * notification request.
3868 * Return: 0 on success and non-zero on failure.
3870 static int mpi3mr_enable_events(struct mpi3mr_ioc *mrioc)
3875 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3876 mrioc->event_masks[i] = -1;
3878 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_ADDED);
3879 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_INFO_CHANGED);
3880 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_STATUS_CHANGE);
3881 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE);
3882 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_ADDED);
3883 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
3884 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
3885 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
3886 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_BROADCAST_PRIMITIVE);
3887 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST);
3888 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_ENUMERATION);
3889 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PREPARE_FOR_RESET);
3890 mpi3mr_unmask_events(mrioc, MPI3_EVENT_CABLE_MGMT);
3891 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENERGY_PACK_CHANGE);
3893 retval = mpi3mr_issue_event_notification(mrioc);
3895 ioc_err(mrioc, "failed to issue event notification %d\n",
3901 * mpi3mr_init_ioc - Initialize the controller
3902 * @mrioc: Adapter instance reference
3904 * This the controller initialization routine, executed either
3905 * after soft reset or from pci probe callback.
3906 * Setup the required resources, memory map the controller
3907 * registers, create admin and operational reply queue pairs,
3908 * allocate required memory for reply pool, sense buffer pool,
3909 * issue IOC init request to the firmware, unmask the events and
3910 * issue port enable to discover SAS/SATA/NVMe devies and RAID
3913 * Return: 0 on success and non-zero on failure.
3915 int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
3919 struct mpi3_ioc_facts_data facts_data;
3923 retval = mpi3mr_bring_ioc_ready(mrioc);
3925 ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
3927 goto out_failed_noretry;
3930 retval = mpi3mr_setup_isr(mrioc, 1);
3932 ioc_err(mrioc, "Failed to setup ISR error %d\n",
3934 goto out_failed_noretry;
3937 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
3939 ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
3944 mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD;
3945 mrioc->shost->max_sectors = mrioc->facts.max_data_length / 512;
3946 mrioc->num_io_throttle_group = mrioc->facts.max_io_throttle_group;
3947 atomic_set(&mrioc->pend_large_data_sz, 0);
3950 mrioc->max_host_ios = min_t(int, mrioc->max_host_ios,
3951 MPI3MR_HOST_IOS_KDUMP);
3953 if (!(mrioc->facts.ioc_capabilities &
3954 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED)) {
3955 mrioc->sas_transport_enabled = 1;
3956 mrioc->scsi_device_channel = 1;
3957 mrioc->shost->max_channel = 1;
3958 mrioc->shost->transportt = mpi3mr_transport_template;
3961 mrioc->reply_sz = mrioc->facts.reply_sz;
3963 retval = mpi3mr_check_reset_dma_mask(mrioc);
3965 ioc_err(mrioc, "Resetting dma mask failed %d\n",
3967 goto out_failed_noretry;
3970 mpi3mr_print_ioc_info(mrioc);
3972 if (!mrioc->cfg_page) {
3973 dprint_init(mrioc, "allocating config page buffers\n");
3974 mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ;
3975 mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev,
3976 mrioc->cfg_page_sz, &mrioc->cfg_page_dma, GFP_KERNEL);
3977 if (!mrioc->cfg_page) {
3979 goto out_failed_noretry;
3983 dprint_init(mrioc, "allocating ioctl dma buffers\n");
3984 mpi3mr_alloc_ioctl_dma_memory(mrioc);
3986 if (!mrioc->init_cmds.reply) {
3987 retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
3990 "%s :Failed to allocated reply sense buffers %d\n",
3992 goto out_failed_noretry;
3996 if (!mrioc->chain_sgl_list) {
3997 retval = mpi3mr_alloc_chain_bufs(mrioc);
3999 ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
4001 goto out_failed_noretry;
4005 retval = mpi3mr_issue_iocinit(mrioc);
4007 ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
4012 retval = mpi3mr_print_pkg_ver(mrioc);
4014 ioc_err(mrioc, "failed to get package version\n");
4018 retval = mpi3mr_setup_isr(mrioc, 0);
4020 ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
4022 goto out_failed_noretry;
4025 retval = mpi3mr_create_op_queues(mrioc);
4027 ioc_err(mrioc, "Failed to create OpQueues error %d\n",
4032 if (!mrioc->pel_seqnum_virt) {
4033 dprint_init(mrioc, "allocating memory for pel_seqnum_virt\n");
4034 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
4035 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
4036 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
4038 if (!mrioc->pel_seqnum_virt) {
4040 goto out_failed_noretry;
4044 if (!mrioc->throttle_groups && mrioc->num_io_throttle_group) {
4045 dprint_init(mrioc, "allocating memory for throttle groups\n");
4046 sz = sizeof(struct mpi3mr_throttle_group_info);
4047 mrioc->throttle_groups = kcalloc(mrioc->num_io_throttle_group, sz, GFP_KERNEL);
4048 if (!mrioc->throttle_groups) {
4050 goto out_failed_noretry;
4054 retval = mpi3mr_enable_events(mrioc);
4056 ioc_err(mrioc, "failed to enable events %d\n",
4061 ioc_info(mrioc, "controller initialization completed successfully\n");
4066 ioc_warn(mrioc, "retrying controller initialization, retry_count:%d\n",
4068 mpi3mr_memset_buffers(mrioc);
4073 ioc_err(mrioc, "controller initialization failed\n");
4074 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
4075 MPI3MR_RESET_FROM_CTLR_CLEANUP);
4076 mrioc->unrecoverable = 1;
4081 * mpi3mr_reinit_ioc - Re-Initialize the controller
4082 * @mrioc: Adapter instance reference
4083 * @is_resume: Called from resume or reset path
4085 * This the controller re-initialization routine, executed from
4086 * the soft reset handler or resume callback. Creates
4087 * operational reply queue pairs, allocate required memory for
4088 * reply pool, sense buffer pool, issue IOC init request to the
4089 * firmware, unmask the events and issue port enable to discover
4090 * SAS/SATA/NVMe devices and RAID volumes.
4092 * Return: 0 on success and non-zero on failure.
4094 int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
4098 struct mpi3_ioc_facts_data facts_data;
4099 u32 pe_timeout, ioc_status;
4103 (MPI3MR_PORTENABLE_TIMEOUT / MPI3MR_PORTENABLE_POLL_INTERVAL);
4105 dprint_reset(mrioc, "bringing up the controller to ready state\n");
4106 retval = mpi3mr_bring_ioc_ready(mrioc);
4108 ioc_err(mrioc, "failed to bring to ready state\n");
4109 goto out_failed_noretry;
4113 dprint_reset(mrioc, "setting up single ISR\n");
4114 retval = mpi3mr_setup_isr(mrioc, 1);
4116 ioc_err(mrioc, "failed to setup ISR\n");
4117 goto out_failed_noretry;
4120 mpi3mr_ioc_enable_intr(mrioc);
4122 dprint_reset(mrioc, "getting ioc_facts\n");
4123 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
4125 ioc_err(mrioc, "failed to get ioc_facts\n");
4129 dprint_reset(mrioc, "validating ioc_facts\n");
4130 retval = mpi3mr_revalidate_factsdata(mrioc);
4132 ioc_err(mrioc, "failed to revalidate ioc_facts data\n");
4133 goto out_failed_noretry;
4136 mpi3mr_print_ioc_info(mrioc);
4138 dprint_reset(mrioc, "sending ioc_init\n");
4139 retval = mpi3mr_issue_iocinit(mrioc);
4141 ioc_err(mrioc, "failed to send ioc_init\n");
4145 dprint_reset(mrioc, "getting package version\n");
4146 retval = mpi3mr_print_pkg_ver(mrioc);
4148 ioc_err(mrioc, "failed to get package version\n");
4153 dprint_reset(mrioc, "setting up multiple ISR\n");
4154 retval = mpi3mr_setup_isr(mrioc, 0);
4156 ioc_err(mrioc, "failed to re-setup ISR\n");
4157 goto out_failed_noretry;
4161 dprint_reset(mrioc, "creating operational queue pairs\n");
4162 retval = mpi3mr_create_op_queues(mrioc);
4164 ioc_err(mrioc, "failed to create operational queue pairs\n");
4168 if (!mrioc->pel_seqnum_virt) {
4169 dprint_reset(mrioc, "allocating memory for pel_seqnum_virt\n");
4170 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
4171 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
4172 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
4174 if (!mrioc->pel_seqnum_virt) {
4176 goto out_failed_noretry;
4180 if (mrioc->shost->nr_hw_queues > mrioc->num_op_reply_q) {
4182 "cannot create minimum number of operational queues expected:%d created:%d\n",
4183 mrioc->shost->nr_hw_queues, mrioc->num_op_reply_q);
4185 goto out_failed_noretry;
4188 dprint_reset(mrioc, "enabling events\n");
4189 retval = mpi3mr_enable_events(mrioc);
4191 ioc_err(mrioc, "failed to enable events\n");
4195 mrioc->device_refresh_on = 1;
4196 mpi3mr_add_event_wait_for_device_refresh(mrioc);
4198 ioc_info(mrioc, "sending port enable\n");
4199 retval = mpi3mr_issue_port_enable(mrioc, 1);
4201 ioc_err(mrioc, "failed to issue port enable\n");
4205 ssleep(MPI3MR_PORTENABLE_POLL_INTERVAL);
4206 if (mrioc->init_cmds.state == MPI3MR_CMD_NOTUSED)
4208 if (!pci_device_is_present(mrioc->pdev))
4209 mrioc->unrecoverable = 1;
4210 if (mrioc->unrecoverable) {
4212 goto out_failed_noretry;
4214 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4215 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
4216 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
4217 mpi3mr_print_fault_info(mrioc);
4218 mrioc->init_cmds.is_waiting = 0;
4219 mrioc->init_cmds.callback = NULL;
4220 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4223 } while (--pe_timeout);
4226 ioc_err(mrioc, "port enable timed out\n");
4227 mpi3mr_check_rh_fault_ioc(mrioc,
4228 MPI3MR_RESET_FROM_PE_TIMEOUT);
4229 mrioc->init_cmds.is_waiting = 0;
4230 mrioc->init_cmds.callback = NULL;
4231 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4233 } else if (mrioc->scan_failed) {
4235 "port enable failed with status=0x%04x\n",
4236 mrioc->scan_failed);
4238 ioc_info(mrioc, "port enable completed successfully\n");
4240 ioc_info(mrioc, "controller %s completed successfully\n",
4241 (is_resume)?"resume":"re-initialization");
4246 ioc_warn(mrioc, "retrying controller %s, retry_count:%d\n",
4247 (is_resume)?"resume":"re-initialization", retry);
4248 mpi3mr_memset_buffers(mrioc);
4253 ioc_err(mrioc, "controller %s is failed\n",
4254 (is_resume)?"resume":"re-initialization");
4255 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
4256 MPI3MR_RESET_FROM_CTLR_CLEANUP);
4257 mrioc->unrecoverable = 1;
4262 * mpi3mr_memset_op_reply_q_buffers - memset the operational reply queue's
4264 * @mrioc: Adapter instance reference
4265 * @qidx: Operational reply queue index
4269 static void mpi3mr_memset_op_reply_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4271 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
4272 struct segments *segments;
4275 if (!op_reply_q->q_segments)
4278 size = op_reply_q->segment_qd * mrioc->op_reply_desc_sz;
4279 segments = op_reply_q->q_segments;
4280 for (i = 0; i < op_reply_q->num_segments; i++)
4281 memset(segments[i].segment, 0, size);
4285 * mpi3mr_memset_op_req_q_buffers - memset the operational request queue's
4287 * @mrioc: Adapter instance reference
4288 * @qidx: Operational request queue index
4292 static void mpi3mr_memset_op_req_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4294 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
4295 struct segments *segments;
4298 if (!op_req_q->q_segments)
4301 size = op_req_q->segment_qd * mrioc->facts.op_req_sz;
4302 segments = op_req_q->q_segments;
4303 for (i = 0; i < op_req_q->num_segments; i++)
4304 memset(segments[i].segment, 0, size);
4308 * mpi3mr_memset_buffers - memset memory for a controller
4309 * @mrioc: Adapter instance reference
4311 * clear all the memory allocated for a controller, typically
4312 * called post reset to reuse the memory allocated during the
4317 void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
4320 struct mpi3mr_throttle_group_info *tg;
4322 mrioc->change_count = 0;
4323 mrioc->active_poll_qcount = 0;
4324 mrioc->default_qcount = 0;
4325 if (mrioc->admin_req_base)
4326 memset(mrioc->admin_req_base, 0, mrioc->admin_req_q_sz);
4327 if (mrioc->admin_reply_base)
4328 memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
4329 atomic_set(&mrioc->admin_reply_q_in_use, 0);
4331 if (mrioc->init_cmds.reply) {
4332 memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
4333 memset(mrioc->bsg_cmds.reply, 0,
4334 sizeof(*mrioc->bsg_cmds.reply));
4335 memset(mrioc->host_tm_cmds.reply, 0,
4336 sizeof(*mrioc->host_tm_cmds.reply));
4337 memset(mrioc->pel_cmds.reply, 0,
4338 sizeof(*mrioc->pel_cmds.reply));
4339 memset(mrioc->pel_abort_cmd.reply, 0,
4340 sizeof(*mrioc->pel_abort_cmd.reply));
4341 memset(mrioc->transport_cmds.reply, 0,
4342 sizeof(*mrioc->transport_cmds.reply));
4343 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
4344 memset(mrioc->dev_rmhs_cmds[i].reply, 0,
4345 sizeof(*mrioc->dev_rmhs_cmds[i].reply));
4346 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++)
4347 memset(mrioc->evtack_cmds[i].reply, 0,
4348 sizeof(*mrioc->evtack_cmds[i].reply));
4349 bitmap_clear(mrioc->removepend_bitmap, 0,
4350 mrioc->dev_handle_bitmap_bits);
4351 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
4352 bitmap_clear(mrioc->evtack_cmds_bitmap, 0,
4353 MPI3MR_NUM_EVTACKCMD);
4356 for (i = 0; i < mrioc->num_queues; i++) {
4357 mrioc->op_reply_qinfo[i].qid = 0;
4358 mrioc->op_reply_qinfo[i].ci = 0;
4359 mrioc->op_reply_qinfo[i].num_replies = 0;
4360 mrioc->op_reply_qinfo[i].ephase = 0;
4361 atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
4362 atomic_set(&mrioc->op_reply_qinfo[i].in_use, 0);
4363 mpi3mr_memset_op_reply_q_buffers(mrioc, i);
4365 mrioc->req_qinfo[i].ci = 0;
4366 mrioc->req_qinfo[i].pi = 0;
4367 mrioc->req_qinfo[i].num_requests = 0;
4368 mrioc->req_qinfo[i].qid = 0;
4369 mrioc->req_qinfo[i].reply_qid = 0;
4370 spin_lock_init(&mrioc->req_qinfo[i].q_lock);
4371 mpi3mr_memset_op_req_q_buffers(mrioc, i);
4374 atomic_set(&mrioc->pend_large_data_sz, 0);
4375 if (mrioc->throttle_groups) {
4376 tg = mrioc->throttle_groups;
4377 for (i = 0; i < mrioc->num_io_throttle_group; i++, tg++) {
4380 tg->modified_qd = 0;
4382 tg->need_qd_reduction = 0;
4385 tg->qd_reduction = 0;
4386 atomic_set(&tg->pend_large_data_sz, 0);
4392 * mpi3mr_free_mem - Free memory allocated for a controller
4393 * @mrioc: Adapter instance reference
4395 * Free all the memory allocated for a controller.
4399 void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
4402 struct mpi3mr_intr_info *intr_info;
4404 mpi3mr_free_enclosure_list(mrioc);
4405 mpi3mr_free_ioctl_dma_memory(mrioc);
4407 if (mrioc->sense_buf_pool) {
4408 if (mrioc->sense_buf)
4409 dma_pool_free(mrioc->sense_buf_pool, mrioc->sense_buf,
4410 mrioc->sense_buf_dma);
4411 dma_pool_destroy(mrioc->sense_buf_pool);
4412 mrioc->sense_buf = NULL;
4413 mrioc->sense_buf_pool = NULL;
4415 if (mrioc->sense_buf_q_pool) {
4416 if (mrioc->sense_buf_q)
4417 dma_pool_free(mrioc->sense_buf_q_pool,
4418 mrioc->sense_buf_q, mrioc->sense_buf_q_dma);
4419 dma_pool_destroy(mrioc->sense_buf_q_pool);
4420 mrioc->sense_buf_q = NULL;
4421 mrioc->sense_buf_q_pool = NULL;
4424 if (mrioc->reply_buf_pool) {
4425 if (mrioc->reply_buf)
4426 dma_pool_free(mrioc->reply_buf_pool, mrioc->reply_buf,
4427 mrioc->reply_buf_dma);
4428 dma_pool_destroy(mrioc->reply_buf_pool);
4429 mrioc->reply_buf = NULL;
4430 mrioc->reply_buf_pool = NULL;
4432 if (mrioc->reply_free_q_pool) {
4433 if (mrioc->reply_free_q)
4434 dma_pool_free(mrioc->reply_free_q_pool,
4435 mrioc->reply_free_q, mrioc->reply_free_q_dma);
4436 dma_pool_destroy(mrioc->reply_free_q_pool);
4437 mrioc->reply_free_q = NULL;
4438 mrioc->reply_free_q_pool = NULL;
4441 for (i = 0; i < mrioc->num_op_req_q; i++)
4442 mpi3mr_free_op_req_q_segments(mrioc, i);
4444 for (i = 0; i < mrioc->num_op_reply_q; i++)
4445 mpi3mr_free_op_reply_q_segments(mrioc, i);
4447 for (i = 0; i < mrioc->intr_info_count; i++) {
4448 intr_info = mrioc->intr_info + i;
4449 intr_info->op_reply_q = NULL;
4452 kfree(mrioc->req_qinfo);
4453 mrioc->req_qinfo = NULL;
4454 mrioc->num_op_req_q = 0;
4456 kfree(mrioc->op_reply_qinfo);
4457 mrioc->op_reply_qinfo = NULL;
4458 mrioc->num_op_reply_q = 0;
4460 kfree(mrioc->init_cmds.reply);
4461 mrioc->init_cmds.reply = NULL;
4463 kfree(mrioc->bsg_cmds.reply);
4464 mrioc->bsg_cmds.reply = NULL;
4466 kfree(mrioc->host_tm_cmds.reply);
4467 mrioc->host_tm_cmds.reply = NULL;
4469 kfree(mrioc->pel_cmds.reply);
4470 mrioc->pel_cmds.reply = NULL;
4472 kfree(mrioc->pel_abort_cmd.reply);
4473 mrioc->pel_abort_cmd.reply = NULL;
4475 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4476 kfree(mrioc->evtack_cmds[i].reply);
4477 mrioc->evtack_cmds[i].reply = NULL;
4480 bitmap_free(mrioc->removepend_bitmap);
4481 mrioc->removepend_bitmap = NULL;
4483 bitmap_free(mrioc->devrem_bitmap);
4484 mrioc->devrem_bitmap = NULL;
4486 bitmap_free(mrioc->evtack_cmds_bitmap);
4487 mrioc->evtack_cmds_bitmap = NULL;
4489 bitmap_free(mrioc->chain_bitmap);
4490 mrioc->chain_bitmap = NULL;
4492 kfree(mrioc->transport_cmds.reply);
4493 mrioc->transport_cmds.reply = NULL;
4495 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4496 kfree(mrioc->dev_rmhs_cmds[i].reply);
4497 mrioc->dev_rmhs_cmds[i].reply = NULL;
4500 if (mrioc->chain_buf_pool) {
4501 for (i = 0; i < mrioc->chain_buf_count; i++) {
4502 if (mrioc->chain_sgl_list[i].addr) {
4503 dma_pool_free(mrioc->chain_buf_pool,
4504 mrioc->chain_sgl_list[i].addr,
4505 mrioc->chain_sgl_list[i].dma_addr);
4506 mrioc->chain_sgl_list[i].addr = NULL;
4509 dma_pool_destroy(mrioc->chain_buf_pool);
4510 mrioc->chain_buf_pool = NULL;
4513 kfree(mrioc->chain_sgl_list);
4514 mrioc->chain_sgl_list = NULL;
4516 if (mrioc->admin_reply_base) {
4517 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
4518 mrioc->admin_reply_base, mrioc->admin_reply_dma);
4519 mrioc->admin_reply_base = NULL;
4521 if (mrioc->admin_req_base) {
4522 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
4523 mrioc->admin_req_base, mrioc->admin_req_dma);
4524 mrioc->admin_req_base = NULL;
4526 if (mrioc->cfg_page) {
4527 dma_free_coherent(&mrioc->pdev->dev, mrioc->cfg_page_sz,
4528 mrioc->cfg_page, mrioc->cfg_page_dma);
4529 mrioc->cfg_page = NULL;
4531 if (mrioc->pel_seqnum_virt) {
4532 dma_free_coherent(&mrioc->pdev->dev, mrioc->pel_seqnum_sz,
4533 mrioc->pel_seqnum_virt, mrioc->pel_seqnum_dma);
4534 mrioc->pel_seqnum_virt = NULL;
4537 kfree(mrioc->throttle_groups);
4538 mrioc->throttle_groups = NULL;
4540 kfree(mrioc->logdata_buf);
4541 mrioc->logdata_buf = NULL;
4546 * mpi3mr_issue_ioc_shutdown - shutdown controller
4547 * @mrioc: Adapter instance reference
4549 * Send shutodwn notification to the controller and wait for the
4550 * shutdown_timeout for it to be completed.
4554 static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
4556 u32 ioc_config, ioc_status;
4558 u32 timeout = MPI3MR_DEFAULT_SHUTDOWN_TIME * 10;
4560 ioc_info(mrioc, "Issuing shutdown Notification\n");
4561 if (mrioc->unrecoverable) {
4563 "IOC is unrecoverable shutdown is not issued\n");
4566 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4567 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4568 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS) {
4569 ioc_info(mrioc, "shutdown already in progress\n");
4573 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4574 ioc_config |= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL;
4575 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN_SEND_REQ;
4577 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
4579 if (mrioc->facts.shutdown_timeout)
4580 timeout = mrioc->facts.shutdown_timeout * 10;
4583 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4584 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4585 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE) {
4590 } while (--timeout);
4592 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4593 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4596 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4597 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS)
4599 "shutdown still in progress after timeout\n");
4603 "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
4604 (!retval) ? "successful" : "failed", ioc_status,
4609 * mpi3mr_cleanup_ioc - Cleanup controller
4610 * @mrioc: Adapter instance reference
4612 * controller cleanup handler, Message unit reset or soft reset
4613 * and shutdown notification is issued to the controller.
4617 void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
4619 enum mpi3mr_iocstate ioc_state;
4621 dprint_exit(mrioc, "cleaning up the controller\n");
4622 mpi3mr_ioc_disable_intr(mrioc);
4624 ioc_state = mpi3mr_get_iocstate(mrioc);
4626 if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
4627 (ioc_state == MRIOC_STATE_READY)) {
4628 if (mpi3mr_issue_and_process_mur(mrioc,
4629 MPI3MR_RESET_FROM_CTLR_CLEANUP))
4630 mpi3mr_issue_reset(mrioc,
4631 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
4632 MPI3MR_RESET_FROM_MUR_FAILURE);
4633 mpi3mr_issue_ioc_shutdown(mrioc);
4635 dprint_exit(mrioc, "controller cleanup completed\n");
4639 * mpi3mr_drv_cmd_comp_reset - Flush a internal driver command
4640 * @mrioc: Adapter instance reference
4641 * @cmdptr: Internal command tracker
4643 * Complete an internal driver commands with state indicating it
4644 * is completed due to reset.
4648 static inline void mpi3mr_drv_cmd_comp_reset(struct mpi3mr_ioc *mrioc,
4649 struct mpi3mr_drv_cmd *cmdptr)
4651 if (cmdptr->state & MPI3MR_CMD_PENDING) {
4652 cmdptr->state |= MPI3MR_CMD_RESET;
4653 cmdptr->state &= ~MPI3MR_CMD_PENDING;
4654 if (cmdptr->is_waiting) {
4655 complete(&cmdptr->done);
4656 cmdptr->is_waiting = 0;
4657 } else if (cmdptr->callback)
4658 cmdptr->callback(mrioc, cmdptr);
4663 * mpi3mr_flush_drv_cmds - Flush internaldriver commands
4664 * @mrioc: Adapter instance reference
4666 * Flush all internal driver commands post reset
4670 void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
4672 struct mpi3mr_drv_cmd *cmdptr;
4675 cmdptr = &mrioc->init_cmds;
4676 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4678 cmdptr = &mrioc->cfg_cmds;
4679 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4681 cmdptr = &mrioc->bsg_cmds;
4682 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4683 cmdptr = &mrioc->host_tm_cmds;
4684 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4686 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4687 cmdptr = &mrioc->dev_rmhs_cmds[i];
4688 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4691 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4692 cmdptr = &mrioc->evtack_cmds[i];
4693 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4696 cmdptr = &mrioc->pel_cmds;
4697 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4699 cmdptr = &mrioc->pel_abort_cmd;
4700 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4702 cmdptr = &mrioc->transport_cmds;
4703 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4707 * mpi3mr_pel_wait_post - Issue PEL Wait
4708 * @mrioc: Adapter instance reference
4709 * @drv_cmd: Internal command tracker
4711 * Issue PEL Wait MPI request through admin queue and return.
4715 static void mpi3mr_pel_wait_post(struct mpi3mr_ioc *mrioc,
4716 struct mpi3mr_drv_cmd *drv_cmd)
4718 struct mpi3_pel_req_action_wait pel_wait;
4720 mrioc->pel_abort_requested = false;
4722 memset(&pel_wait, 0, sizeof(pel_wait));
4723 drv_cmd->state = MPI3MR_CMD_PENDING;
4724 drv_cmd->is_waiting = 0;
4725 drv_cmd->callback = mpi3mr_pel_wait_complete;
4726 drv_cmd->ioc_status = 0;
4727 drv_cmd->ioc_loginfo = 0;
4728 pel_wait.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4729 pel_wait.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4730 pel_wait.action = MPI3_PEL_ACTION_WAIT;
4731 pel_wait.starting_sequence_number = cpu_to_le32(mrioc->pel_newest_seqnum);
4732 pel_wait.locale = cpu_to_le16(mrioc->pel_locale);
4733 pel_wait.class = cpu_to_le16(mrioc->pel_class);
4734 pel_wait.wait_time = MPI3_PEL_WAITTIME_INFINITE_WAIT;
4735 dprint_bsg_info(mrioc, "sending pel_wait seqnum(%d), class(%d), locale(0x%08x)\n",
4736 mrioc->pel_newest_seqnum, mrioc->pel_class, mrioc->pel_locale);
4738 if (mpi3mr_admin_request_post(mrioc, &pel_wait, sizeof(pel_wait), 0)) {
4739 dprint_bsg_err(mrioc,
4740 "Issuing PELWait: Admin post failed\n");
4741 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4742 drv_cmd->callback = NULL;
4743 drv_cmd->retry_count = 0;
4744 mrioc->pel_enabled = false;
4749 * mpi3mr_pel_get_seqnum_post - Issue PEL Get Sequence number
4750 * @mrioc: Adapter instance reference
4751 * @drv_cmd: Internal command tracker
4753 * Issue PEL get sequence number MPI request through admin queue
4756 * Return: 0 on success, non-zero on failure.
4758 int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc,
4759 struct mpi3mr_drv_cmd *drv_cmd)
4761 struct mpi3_pel_req_action_get_sequence_numbers pel_getseq_req;
4762 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
4765 memset(&pel_getseq_req, 0, sizeof(pel_getseq_req));
4766 mrioc->pel_cmds.state = MPI3MR_CMD_PENDING;
4767 mrioc->pel_cmds.is_waiting = 0;
4768 mrioc->pel_cmds.ioc_status = 0;
4769 mrioc->pel_cmds.ioc_loginfo = 0;
4770 mrioc->pel_cmds.callback = mpi3mr_pel_get_seqnum_complete;
4771 pel_getseq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4772 pel_getseq_req.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4773 pel_getseq_req.action = MPI3_PEL_ACTION_GET_SEQNUM;
4774 mpi3mr_add_sg_single(&pel_getseq_req.sgl, sgl_flags,
4775 mrioc->pel_seqnum_sz, mrioc->pel_seqnum_dma);
4777 retval = mpi3mr_admin_request_post(mrioc, &pel_getseq_req,
4778 sizeof(pel_getseq_req), 0);
4781 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4782 drv_cmd->callback = NULL;
4783 drv_cmd->retry_count = 0;
4785 mrioc->pel_enabled = false;
4792 * mpi3mr_pel_wait_complete - PELWait Completion callback
4793 * @mrioc: Adapter instance reference
4794 * @drv_cmd: Internal command tracker
4796 * This is a callback handler for the PELWait request and
4797 * firmware completes a PELWait request when it is aborted or a
4798 * new PEL entry is available. This sends AEN to the application
4799 * and if the PELwait completion is not due to PELAbort then
4800 * this will send a request for new PEL Sequence number
4804 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc *mrioc,
4805 struct mpi3mr_drv_cmd *drv_cmd)
4807 struct mpi3_pel_reply *pel_reply = NULL;
4808 u16 ioc_status, pe_log_status;
4809 bool do_retry = false;
4811 if (drv_cmd->state & MPI3MR_CMD_RESET)
4812 goto cleanup_drv_cmd;
4814 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4815 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4816 ioc_err(mrioc, "%s: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
4817 __func__, ioc_status, drv_cmd->ioc_loginfo);
4818 dprint_bsg_err(mrioc,
4819 "pel_wait: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4820 ioc_status, drv_cmd->ioc_loginfo);
4824 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4825 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4828 dprint_bsg_err(mrioc,
4829 "pel_wait: failed due to no reply\n");
4833 pe_log_status = le16_to_cpu(pel_reply->pe_log_status);
4834 if ((pe_log_status != MPI3_PEL_STATUS_SUCCESS) &&
4835 (pe_log_status != MPI3_PEL_STATUS_ABORTED)) {
4836 ioc_err(mrioc, "%s: Failed pe_log_status(0x%04x)\n",
4837 __func__, pe_log_status);
4838 dprint_bsg_err(mrioc,
4839 "pel_wait: failed due to pel_log_status(0x%04x)\n",
4845 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4846 drv_cmd->retry_count++;
4847 dprint_bsg_err(mrioc, "pel_wait: retrying(%d)\n",
4848 drv_cmd->retry_count);
4849 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4852 dprint_bsg_err(mrioc,
4853 "pel_wait: failed after all retries(%d)\n",
4854 drv_cmd->retry_count);
4857 atomic64_inc(&event_counter);
4858 if (!mrioc->pel_abort_requested) {
4859 mrioc->pel_cmds.retry_count = 0;
4860 mpi3mr_pel_get_seqnum_post(mrioc, &mrioc->pel_cmds);
4865 mrioc->pel_enabled = false;
4867 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4868 drv_cmd->callback = NULL;
4869 drv_cmd->retry_count = 0;
4873 * mpi3mr_pel_get_seqnum_complete - PELGetSeqNum Completion callback
4874 * @mrioc: Adapter instance reference
4875 * @drv_cmd: Internal command tracker
4877 * This is a callback handler for the PEL get sequence number
4878 * request and a new PEL wait request will be issued to the
4879 * firmware from this
4883 void mpi3mr_pel_get_seqnum_complete(struct mpi3mr_ioc *mrioc,
4884 struct mpi3mr_drv_cmd *drv_cmd)
4886 struct mpi3_pel_reply *pel_reply = NULL;
4887 struct mpi3_pel_seq *pel_seqnum_virt;
4889 bool do_retry = false;
4891 pel_seqnum_virt = (struct mpi3_pel_seq *)mrioc->pel_seqnum_virt;
4893 if (drv_cmd->state & MPI3MR_CMD_RESET)
4894 goto cleanup_drv_cmd;
4896 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4897 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4898 dprint_bsg_err(mrioc,
4899 "pel_get_seqnum: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4900 ioc_status, drv_cmd->ioc_loginfo);
4904 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4905 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4907 dprint_bsg_err(mrioc,
4908 "pel_get_seqnum: failed due to no reply\n");
4912 if (le16_to_cpu(pel_reply->pe_log_status) != MPI3_PEL_STATUS_SUCCESS) {
4913 dprint_bsg_err(mrioc,
4914 "pel_get_seqnum: failed due to pel_log_status(0x%04x)\n",
4915 le16_to_cpu(pel_reply->pe_log_status));
4920 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4921 drv_cmd->retry_count++;
4922 dprint_bsg_err(mrioc,
4923 "pel_get_seqnum: retrying(%d)\n",
4924 drv_cmd->retry_count);
4925 mpi3mr_pel_get_seqnum_post(mrioc, drv_cmd);
4929 dprint_bsg_err(mrioc,
4930 "pel_get_seqnum: failed after all retries(%d)\n",
4931 drv_cmd->retry_count);
4934 mrioc->pel_newest_seqnum = le32_to_cpu(pel_seqnum_virt->newest) + 1;
4935 drv_cmd->retry_count = 0;
4936 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4940 mrioc->pel_enabled = false;
4942 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4943 drv_cmd->callback = NULL;
4944 drv_cmd->retry_count = 0;
4948 * mpi3mr_soft_reset_handler - Reset the controller
4949 * @mrioc: Adapter instance reference
4950 * @reset_reason: Reset reason code
4951 * @snapdump: Flag to generate snapdump in firmware or not
4953 * This is an handler for recovering controller by issuing soft
4954 * reset are diag fault reset. This is a blocking function and
4955 * when one reset is executed if any other resets they will be
4956 * blocked. All BSG requests will be blocked during the reset. If
4957 * controller reset is successful then the controller will be
4958 * reinitalized, otherwise the controller will be marked as not
4961 * In snapdump bit is set, the controller is issued with diag
4962 * fault reset so that the firmware can create a snap dump and
4963 * post that the firmware will result in F000 fault and the
4964 * driver will issue soft reset to recover from that.
4966 * Return: 0 on success, non-zero on failure.
4968 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
4969 u32 reset_reason, u8 snapdump)
4972 unsigned long flags;
4973 u32 host_diagnostic, timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
4975 /* Block the reset handler until diag save in progress*/
4977 "soft_reset_handler: check and block on diagsave_timeout(%d)\n",
4978 mrioc->diagsave_timeout);
4979 while (mrioc->diagsave_timeout)
4982 * Block new resets until the currently executing one is finished and
4983 * return the status of the existing reset for all blocked resets
4985 dprint_reset(mrioc, "soft_reset_handler: acquiring reset_mutex\n");
4986 if (!mutex_trylock(&mrioc->reset_mutex)) {
4988 "controller reset triggered by %s is blocked due to another reset in progress\n",
4989 mpi3mr_reset_rc_name(reset_reason));
4992 } while (mrioc->reset_in_progress == 1);
4994 "returning previous reset result(%d) for the reset triggered by %s\n",
4995 mrioc->prev_reset_result,
4996 mpi3mr_reset_rc_name(reset_reason));
4997 return mrioc->prev_reset_result;
4999 ioc_info(mrioc, "controller reset is triggered by %s\n",
5000 mpi3mr_reset_rc_name(reset_reason));
5002 mrioc->device_refresh_on = 0;
5003 mrioc->reset_in_progress = 1;
5004 mrioc->stop_bsgs = 1;
5005 mrioc->prev_reset_result = -1;
5007 if ((!snapdump) && (reset_reason != MPI3MR_RESET_FROM_FAULT_WATCH) &&
5008 (reset_reason != MPI3MR_RESET_FROM_FIRMWARE) &&
5009 (reset_reason != MPI3MR_RESET_FROM_CIACTIV_FAULT)) {
5010 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
5011 mrioc->event_masks[i] = -1;
5013 dprint_reset(mrioc, "soft_reset_handler: masking events\n");
5014 mpi3mr_issue_event_notification(mrioc);
5017 mpi3mr_wait_for_host_io(mrioc, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT);
5019 mpi3mr_ioc_disable_intr(mrioc);
5022 mpi3mr_set_diagsave(mrioc);
5023 retval = mpi3mr_issue_reset(mrioc,
5024 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
5028 readl(&mrioc->sysif_regs->host_diagnostic);
5029 if (!(host_diagnostic &
5030 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
5033 } while (--timeout);
5037 retval = mpi3mr_issue_reset(mrioc,
5038 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, reset_reason);
5040 ioc_err(mrioc, "Failed to issue soft reset to the ioc\n");
5043 if (mrioc->num_io_throttle_group !=
5044 mrioc->facts.max_io_throttle_group) {
5046 "max io throttle group doesn't match old(%d), new(%d)\n",
5047 mrioc->num_io_throttle_group,
5048 mrioc->facts.max_io_throttle_group);
5053 mpi3mr_flush_delayed_cmd_lists(mrioc);
5054 mpi3mr_flush_drv_cmds(mrioc);
5055 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
5056 bitmap_clear(mrioc->removepend_bitmap, 0,
5057 mrioc->dev_handle_bitmap_bits);
5058 bitmap_clear(mrioc->evtack_cmds_bitmap, 0, MPI3MR_NUM_EVTACKCMD);
5059 mpi3mr_flush_host_io(mrioc);
5060 mpi3mr_cleanup_fwevt_list(mrioc);
5061 mpi3mr_invalidate_devhandles(mrioc);
5062 mpi3mr_free_enclosure_list(mrioc);
5064 if (mrioc->prepare_for_reset) {
5065 mrioc->prepare_for_reset = 0;
5066 mrioc->prepare_for_reset_timeout_counter = 0;
5068 mpi3mr_memset_buffers(mrioc);
5069 retval = mpi3mr_reinit_ioc(mrioc, 0);
5071 pr_err(IOCNAME "reinit after soft reset failed: reason %d\n",
5072 mrioc->name, reset_reason);
5075 ssleep(MPI3MR_RESET_TOPOLOGY_SETTLE_TIME);
5079 mrioc->diagsave_timeout = 0;
5080 mrioc->reset_in_progress = 0;
5081 mrioc->pel_abort_requested = 0;
5082 if (mrioc->pel_enabled) {
5083 mrioc->pel_cmds.retry_count = 0;
5084 mpi3mr_pel_wait_post(mrioc, &mrioc->pel_cmds);
5087 mrioc->device_refresh_on = 0;
5089 mrioc->ts_update_counter = 0;
5090 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
5091 if (mrioc->watchdog_work_q)
5092 queue_delayed_work(mrioc->watchdog_work_q,
5093 &mrioc->watchdog_work,
5094 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
5095 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
5096 mrioc->stop_bsgs = 0;
5097 if (mrioc->pel_enabled)
5098 atomic64_inc(&event_counter);
5100 mpi3mr_issue_reset(mrioc,
5101 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
5102 mrioc->device_refresh_on = 0;
5103 mrioc->unrecoverable = 1;
5104 mrioc->reset_in_progress = 0;
5106 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
5108 mrioc->prev_reset_result = retval;
5109 mutex_unlock(&mrioc->reset_mutex);
5110 ioc_info(mrioc, "controller reset is %s\n",
5111 ((retval == 0) ? "successful" : "failed"));
5117 * mpi3mr_free_config_dma_memory - free memory for config page
5118 * @mrioc: Adapter instance reference
5119 * @mem_desc: memory descriptor structure
5121 * Check whether the size of the buffer specified by the memory
5122 * descriptor is greater than the default page size if so then
5123 * free the memory pointed by the descriptor.
5127 static void mpi3mr_free_config_dma_memory(struct mpi3mr_ioc *mrioc,
5128 struct dma_memory_desc *mem_desc)
5130 if ((mem_desc->size > mrioc->cfg_page_sz) && mem_desc->addr) {
5131 dma_free_coherent(&mrioc->pdev->dev, mem_desc->size,
5132 mem_desc->addr, mem_desc->dma_addr);
5133 mem_desc->addr = NULL;
5138 * mpi3mr_alloc_config_dma_memory - Alloc memory for config page
5139 * @mrioc: Adapter instance reference
5140 * @mem_desc: Memory descriptor to hold dma memory info
5142 * This function allocates new dmaable memory or provides the
5143 * default config page dmaable memory based on the memory size
5144 * described by the descriptor.
5146 * Return: 0 on success, non-zero on failure.
5148 static int mpi3mr_alloc_config_dma_memory(struct mpi3mr_ioc *mrioc,
5149 struct dma_memory_desc *mem_desc)
5151 if (mem_desc->size > mrioc->cfg_page_sz) {
5152 mem_desc->addr = dma_alloc_coherent(&mrioc->pdev->dev,
5153 mem_desc->size, &mem_desc->dma_addr, GFP_KERNEL);
5154 if (!mem_desc->addr)
5157 mem_desc->addr = mrioc->cfg_page;
5158 mem_desc->dma_addr = mrioc->cfg_page_dma;
5159 memset(mem_desc->addr, 0, mrioc->cfg_page_sz);
5165 * mpi3mr_post_cfg_req - Issue config requests and wait
5166 * @mrioc: Adapter instance reference
5167 * @cfg_req: Configuration request
5168 * @timeout: Timeout in seconds
5169 * @ioc_status: Pointer to return ioc status
5171 * A generic function for posting MPI3 configuration request to
5172 * the firmware. This blocks for the completion of request for
5173 * timeout seconds and if the request times out this function
5174 * faults the controller with proper reason code.
5176 * On successful completion of the request this function returns
5177 * appropriate ioc status from the firmware back to the caller.
5179 * Return: 0 on success, non-zero on failure.
5181 static int mpi3mr_post_cfg_req(struct mpi3mr_ioc *mrioc,
5182 struct mpi3_config_request *cfg_req, int timeout, u16 *ioc_status)
5186 mutex_lock(&mrioc->cfg_cmds.mutex);
5187 if (mrioc->cfg_cmds.state & MPI3MR_CMD_PENDING) {
5189 ioc_err(mrioc, "sending config request failed due to command in use\n");
5190 mutex_unlock(&mrioc->cfg_cmds.mutex);
5193 mrioc->cfg_cmds.state = MPI3MR_CMD_PENDING;
5194 mrioc->cfg_cmds.is_waiting = 1;
5195 mrioc->cfg_cmds.callback = NULL;
5196 mrioc->cfg_cmds.ioc_status = 0;
5197 mrioc->cfg_cmds.ioc_loginfo = 0;
5199 cfg_req->host_tag = cpu_to_le16(MPI3MR_HOSTTAG_CFG_CMDS);
5200 cfg_req->function = MPI3_FUNCTION_CONFIG;
5202 init_completion(&mrioc->cfg_cmds.done);
5203 dprint_cfg_info(mrioc, "posting config request\n");
5204 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5205 dprint_dump(cfg_req, sizeof(struct mpi3_config_request),
5207 retval = mpi3mr_admin_request_post(mrioc, cfg_req, sizeof(*cfg_req), 1);
5209 ioc_err(mrioc, "posting config request failed\n");
5212 wait_for_completion_timeout(&mrioc->cfg_cmds.done, (timeout * HZ));
5213 if (!(mrioc->cfg_cmds.state & MPI3MR_CMD_COMPLETE)) {
5214 mpi3mr_check_rh_fault_ioc(mrioc,
5215 MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT);
5216 ioc_err(mrioc, "config request timed out\n");
5220 *ioc_status = mrioc->cfg_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
5221 if ((*ioc_status) != MPI3_IOCSTATUS_SUCCESS)
5222 dprint_cfg_err(mrioc,
5223 "cfg_page request returned with ioc_status(0x%04x), log_info(0x%08x)\n",
5224 *ioc_status, mrioc->cfg_cmds.ioc_loginfo);
5227 mrioc->cfg_cmds.state = MPI3MR_CMD_NOTUSED;
5228 mutex_unlock(&mrioc->cfg_cmds.mutex);
5235 * mpi3mr_process_cfg_req - config page request processor
5236 * @mrioc: Adapter instance reference
5237 * @cfg_req: Configuration request
5238 * @cfg_hdr: Configuration page header
5239 * @timeout: Timeout in seconds
5240 * @ioc_status: Pointer to return ioc status
5241 * @cfg_buf: Memory pointer to copy config page or header
5242 * @cfg_buf_sz: Size of the memory to get config page or header
5244 * This is handler for config page read, write and config page
5245 * header read operations.
5247 * This function expects the cfg_req to be populated with page
5248 * type, page number, action for the header read and with page
5249 * address for all other operations.
5251 * The cfg_hdr can be passed as null for reading required header
5252 * details for read/write pages the cfg_hdr should point valid
5253 * configuration page header.
5255 * This allocates dmaable memory based on the size of the config
5256 * buffer and set the SGE of the cfg_req.
5258 * For write actions, the config page data has to be passed in
5259 * the cfg_buf and size of the data has to be mentioned in the
5262 * For read/header actions, on successful completion of the
5263 * request with successful ioc_status the data will be copied
5264 * into the cfg_buf limited to a minimum of actual page size and
5268 * Return: 0 on success, non-zero on failure.
5270 static int mpi3mr_process_cfg_req(struct mpi3mr_ioc *mrioc,
5271 struct mpi3_config_request *cfg_req,
5272 struct mpi3_config_page_header *cfg_hdr, int timeout, u16 *ioc_status,
5273 void *cfg_buf, u32 cfg_buf_sz)
5275 struct dma_memory_desc mem_desc;
5277 u8 invalid_action = 0;
5278 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
5280 memset(&mem_desc, 0, sizeof(struct dma_memory_desc));
5282 if (cfg_req->action == MPI3_CONFIG_ACTION_PAGE_HEADER)
5283 mem_desc.size = sizeof(struct mpi3_config_page_header);
5286 ioc_err(mrioc, "null config header passed for config action(%d), page_type(0x%02x), page_num(%d)\n",
5287 cfg_req->action, cfg_req->page_type,
5288 cfg_req->page_number);
5291 switch (cfg_hdr->page_attribute & MPI3_CONFIG_PAGEATTR_MASK) {
5292 case MPI3_CONFIG_PAGEATTR_READ_ONLY:
5294 != MPI3_CONFIG_ACTION_READ_CURRENT)
5297 case MPI3_CONFIG_PAGEATTR_CHANGEABLE:
5298 if ((cfg_req->action ==
5299 MPI3_CONFIG_ACTION_READ_PERSISTENT) ||
5301 MPI3_CONFIG_ACTION_WRITE_PERSISTENT))
5304 case MPI3_CONFIG_PAGEATTR_PERSISTENT:
5308 if (invalid_action) {
5310 "config action(%d) is not allowed for page_type(0x%02x), page_num(%d) with page_attribute(0x%02x)\n",
5311 cfg_req->action, cfg_req->page_type,
5312 cfg_req->page_number, cfg_hdr->page_attribute);
5315 mem_desc.size = le16_to_cpu(cfg_hdr->page_length) * 4;
5316 cfg_req->page_length = cfg_hdr->page_length;
5317 cfg_req->page_version = cfg_hdr->page_version;
5319 if (mpi3mr_alloc_config_dma_memory(mrioc, &mem_desc))
5322 mpi3mr_add_sg_single(&cfg_req->sgl, sgl_flags, mem_desc.size,
5325 if ((cfg_req->action == MPI3_CONFIG_ACTION_WRITE_PERSISTENT) ||
5326 (cfg_req->action == MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5327 memcpy(mem_desc.addr, cfg_buf, min_t(u16, mem_desc.size,
5329 dprint_cfg_info(mrioc, "config buffer to be written\n");
5330 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5331 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5334 if (mpi3mr_post_cfg_req(mrioc, cfg_req, timeout, ioc_status))
5338 if ((*ioc_status == MPI3_IOCSTATUS_SUCCESS) &&
5339 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_PERSISTENT) &&
5340 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5341 memcpy(cfg_buf, mem_desc.addr, min_t(u16, mem_desc.size,
5343 dprint_cfg_info(mrioc, "config buffer read\n");
5344 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5345 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5349 mpi3mr_free_config_dma_memory(mrioc, &mem_desc);
5354 * mpi3mr_cfg_get_dev_pg0 - Read current device page0
5355 * @mrioc: Adapter instance reference
5356 * @ioc_status: Pointer to return ioc status
5357 * @dev_pg0: Pointer to return device page 0
5358 * @pg_sz: Size of the memory allocated to the page pointer
5359 * @form: The form to be used for addressing the page
5360 * @form_spec: Form specific information like device handle
5362 * This is handler for config page read for a specific device
5363 * page0. The ioc_status has the controller returned ioc_status.
5364 * This routine doesn't check ioc_status to decide whether the
5365 * page read is success or not and it is the callers
5368 * Return: 0 on success, non-zero on failure.
5370 int mpi3mr_cfg_get_dev_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5371 struct mpi3_device_page0 *dev_pg0, u16 pg_sz, u32 form, u32 form_spec)
5373 struct mpi3_config_page_header cfg_hdr;
5374 struct mpi3_config_request cfg_req;
5377 memset(dev_pg0, 0, pg_sz);
5378 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5379 memset(&cfg_req, 0, sizeof(cfg_req));
5381 cfg_req.function = MPI3_FUNCTION_CONFIG;
5382 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5383 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DEVICE;
5384 cfg_req.page_number = 0;
5385 cfg_req.page_address = 0;
5387 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5388 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5389 ioc_err(mrioc, "device page0 header read failed\n");
5392 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5393 ioc_err(mrioc, "device page0 header read failed with ioc_status(0x%04x)\n",
5397 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5398 page_address = ((form & MPI3_DEVICE_PGAD_FORM_MASK) |
5399 (form_spec & MPI3_DEVICE_PGAD_HANDLE_MASK));
5400 cfg_req.page_address = cpu_to_le32(page_address);
5401 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5402 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, dev_pg0, pg_sz)) {
5403 ioc_err(mrioc, "device page0 read failed\n");
5413 * mpi3mr_cfg_get_sas_phy_pg0 - Read current SAS Phy page0
5414 * @mrioc: Adapter instance reference
5415 * @ioc_status: Pointer to return ioc status
5416 * @phy_pg0: Pointer to return SAS Phy page 0
5417 * @pg_sz: Size of the memory allocated to the page pointer
5418 * @form: The form to be used for addressing the page
5419 * @form_spec: Form specific information like phy number
5421 * This is handler for config page read for a specific SAS Phy
5422 * page0. The ioc_status has the controller returned ioc_status.
5423 * This routine doesn't check ioc_status to decide whether the
5424 * page read is success or not and it is the callers
5427 * Return: 0 on success, non-zero on failure.
5429 int mpi3mr_cfg_get_sas_phy_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5430 struct mpi3_sas_phy_page0 *phy_pg0, u16 pg_sz, u32 form,
5433 struct mpi3_config_page_header cfg_hdr;
5434 struct mpi3_config_request cfg_req;
5437 memset(phy_pg0, 0, pg_sz);
5438 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5439 memset(&cfg_req, 0, sizeof(cfg_req));
5441 cfg_req.function = MPI3_FUNCTION_CONFIG;
5442 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5443 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5444 cfg_req.page_number = 0;
5445 cfg_req.page_address = 0;
5447 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5448 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5449 ioc_err(mrioc, "sas phy page0 header read failed\n");
5452 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5453 ioc_err(mrioc, "sas phy page0 header read failed with ioc_status(0x%04x)\n",
5457 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5458 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5459 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5460 cfg_req.page_address = cpu_to_le32(page_address);
5461 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5462 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg0, pg_sz)) {
5463 ioc_err(mrioc, "sas phy page0 read failed\n");
5472 * mpi3mr_cfg_get_sas_phy_pg1 - Read current SAS Phy page1
5473 * @mrioc: Adapter instance reference
5474 * @ioc_status: Pointer to return ioc status
5475 * @phy_pg1: Pointer to return SAS Phy page 1
5476 * @pg_sz: Size of the memory allocated to the page pointer
5477 * @form: The form to be used for addressing the page
5478 * @form_spec: Form specific information like phy number
5480 * This is handler for config page read for a specific SAS Phy
5481 * page1. The ioc_status has the controller returned ioc_status.
5482 * This routine doesn't check ioc_status to decide whether the
5483 * page read is success or not and it is the callers
5486 * Return: 0 on success, non-zero on failure.
5488 int mpi3mr_cfg_get_sas_phy_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5489 struct mpi3_sas_phy_page1 *phy_pg1, u16 pg_sz, u32 form,
5492 struct mpi3_config_page_header cfg_hdr;
5493 struct mpi3_config_request cfg_req;
5496 memset(phy_pg1, 0, pg_sz);
5497 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5498 memset(&cfg_req, 0, sizeof(cfg_req));
5500 cfg_req.function = MPI3_FUNCTION_CONFIG;
5501 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5502 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5503 cfg_req.page_number = 1;
5504 cfg_req.page_address = 0;
5506 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5507 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5508 ioc_err(mrioc, "sas phy page1 header read failed\n");
5511 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5512 ioc_err(mrioc, "sas phy page1 header read failed with ioc_status(0x%04x)\n",
5516 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5517 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5518 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5519 cfg_req.page_address = cpu_to_le32(page_address);
5520 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5521 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg1, pg_sz)) {
5522 ioc_err(mrioc, "sas phy page1 read failed\n");
5532 * mpi3mr_cfg_get_sas_exp_pg0 - Read current SAS Expander page0
5533 * @mrioc: Adapter instance reference
5534 * @ioc_status: Pointer to return ioc status
5535 * @exp_pg0: Pointer to return SAS Expander page 0
5536 * @pg_sz: Size of the memory allocated to the page pointer
5537 * @form: The form to be used for addressing the page
5538 * @form_spec: Form specific information like device handle
5540 * This is handler for config page read for a specific SAS
5541 * Expander page0. The ioc_status has the controller returned
5542 * ioc_status. This routine doesn't check ioc_status to decide
5543 * whether the page read is success or not and it is the callers
5546 * Return: 0 on success, non-zero on failure.
5548 int mpi3mr_cfg_get_sas_exp_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5549 struct mpi3_sas_expander_page0 *exp_pg0, u16 pg_sz, u32 form,
5552 struct mpi3_config_page_header cfg_hdr;
5553 struct mpi3_config_request cfg_req;
5556 memset(exp_pg0, 0, pg_sz);
5557 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5558 memset(&cfg_req, 0, sizeof(cfg_req));
5560 cfg_req.function = MPI3_FUNCTION_CONFIG;
5561 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5562 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5563 cfg_req.page_number = 0;
5564 cfg_req.page_address = 0;
5566 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5567 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5568 ioc_err(mrioc, "expander page0 header read failed\n");
5571 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5572 ioc_err(mrioc, "expander page0 header read failed with ioc_status(0x%04x)\n",
5576 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5577 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5578 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5579 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5580 cfg_req.page_address = cpu_to_le32(page_address);
5581 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5582 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg0, pg_sz)) {
5583 ioc_err(mrioc, "expander page0 read failed\n");
5592 * mpi3mr_cfg_get_sas_exp_pg1 - Read current SAS Expander page1
5593 * @mrioc: Adapter instance reference
5594 * @ioc_status: Pointer to return ioc status
5595 * @exp_pg1: Pointer to return SAS Expander page 1
5596 * @pg_sz: Size of the memory allocated to the page pointer
5597 * @form: The form to be used for addressing the page
5598 * @form_spec: Form specific information like phy number
5600 * This is handler for config page read for a specific SAS
5601 * Expander page1. The ioc_status has the controller returned
5602 * ioc_status. This routine doesn't check ioc_status to decide
5603 * whether the page read is success or not and it is the callers
5606 * Return: 0 on success, non-zero on failure.
5608 int mpi3mr_cfg_get_sas_exp_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5609 struct mpi3_sas_expander_page1 *exp_pg1, u16 pg_sz, u32 form,
5612 struct mpi3_config_page_header cfg_hdr;
5613 struct mpi3_config_request cfg_req;
5616 memset(exp_pg1, 0, pg_sz);
5617 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5618 memset(&cfg_req, 0, sizeof(cfg_req));
5620 cfg_req.function = MPI3_FUNCTION_CONFIG;
5621 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5622 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5623 cfg_req.page_number = 1;
5624 cfg_req.page_address = 0;
5626 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5627 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5628 ioc_err(mrioc, "expander page1 header read failed\n");
5631 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5632 ioc_err(mrioc, "expander page1 header read failed with ioc_status(0x%04x)\n",
5636 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5637 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5638 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5639 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5640 cfg_req.page_address = cpu_to_le32(page_address);
5641 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5642 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg1, pg_sz)) {
5643 ioc_err(mrioc, "expander page1 read failed\n");
5652 * mpi3mr_cfg_get_enclosure_pg0 - Read current Enclosure page0
5653 * @mrioc: Adapter instance reference
5654 * @ioc_status: Pointer to return ioc status
5655 * @encl_pg0: Pointer to return Enclosure page 0
5656 * @pg_sz: Size of the memory allocated to the page pointer
5657 * @form: The form to be used for addressing the page
5658 * @form_spec: Form specific information like device handle
5660 * This is handler for config page read for a specific Enclosure
5661 * page0. The ioc_status has the controller returned ioc_status.
5662 * This routine doesn't check ioc_status to decide whether the
5663 * page read is success or not and it is the callers
5666 * Return: 0 on success, non-zero on failure.
5668 int mpi3mr_cfg_get_enclosure_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5669 struct mpi3_enclosure_page0 *encl_pg0, u16 pg_sz, u32 form,
5672 struct mpi3_config_page_header cfg_hdr;
5673 struct mpi3_config_request cfg_req;
5676 memset(encl_pg0, 0, pg_sz);
5677 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5678 memset(&cfg_req, 0, sizeof(cfg_req));
5680 cfg_req.function = MPI3_FUNCTION_CONFIG;
5681 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5682 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_ENCLOSURE;
5683 cfg_req.page_number = 0;
5684 cfg_req.page_address = 0;
5686 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5687 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5688 ioc_err(mrioc, "enclosure page0 header read failed\n");
5691 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5692 ioc_err(mrioc, "enclosure page0 header read failed with ioc_status(0x%04x)\n",
5696 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5697 page_address = ((form & MPI3_ENCLOS_PGAD_FORM_MASK) |
5698 (form_spec & MPI3_ENCLOS_PGAD_HANDLE_MASK));
5699 cfg_req.page_address = cpu_to_le32(page_address);
5700 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5701 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, encl_pg0, pg_sz)) {
5702 ioc_err(mrioc, "enclosure page0 read failed\n");
5712 * mpi3mr_cfg_get_sas_io_unit_pg0 - Read current SASIOUnit page0
5713 * @mrioc: Adapter instance reference
5714 * @sas_io_unit_pg0: Pointer to return SAS IO Unit page 0
5715 * @pg_sz: Size of the memory allocated to the page pointer
5717 * This is handler for config page read for the SAS IO Unit
5718 * page0. This routine checks ioc_status to decide whether the
5719 * page read is success or not.
5721 * Return: 0 on success, non-zero on failure.
5723 int mpi3mr_cfg_get_sas_io_unit_pg0(struct mpi3mr_ioc *mrioc,
5724 struct mpi3_sas_io_unit_page0 *sas_io_unit_pg0, u16 pg_sz)
5726 struct mpi3_config_page_header cfg_hdr;
5727 struct mpi3_config_request cfg_req;
5730 memset(sas_io_unit_pg0, 0, pg_sz);
5731 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5732 memset(&cfg_req, 0, sizeof(cfg_req));
5734 cfg_req.function = MPI3_FUNCTION_CONFIG;
5735 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5736 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5737 cfg_req.page_number = 0;
5738 cfg_req.page_address = 0;
5740 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5741 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5742 ioc_err(mrioc, "sas io unit page0 header read failed\n");
5745 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5746 ioc_err(mrioc, "sas io unit page0 header read failed with ioc_status(0x%04x)\n",
5750 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5752 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5753 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg0, pg_sz)) {
5754 ioc_err(mrioc, "sas io unit page0 read failed\n");
5757 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5758 ioc_err(mrioc, "sas io unit page0 read failed with ioc_status(0x%04x)\n",
5768 * mpi3mr_cfg_get_sas_io_unit_pg1 - Read current SASIOUnit page1
5769 * @mrioc: Adapter instance reference
5770 * @sas_io_unit_pg1: Pointer to return SAS IO Unit page 1
5771 * @pg_sz: Size of the memory allocated to the page pointer
5773 * This is handler for config page read for the SAS IO Unit
5774 * page1. This routine checks ioc_status to decide whether the
5775 * page read is success or not.
5777 * Return: 0 on success, non-zero on failure.
5779 int mpi3mr_cfg_get_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5780 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5782 struct mpi3_config_page_header cfg_hdr;
5783 struct mpi3_config_request cfg_req;
5786 memset(sas_io_unit_pg1, 0, pg_sz);
5787 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5788 memset(&cfg_req, 0, sizeof(cfg_req));
5790 cfg_req.function = MPI3_FUNCTION_CONFIG;
5791 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5792 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5793 cfg_req.page_number = 1;
5794 cfg_req.page_address = 0;
5796 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5797 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5798 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5801 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5802 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5806 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5808 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5809 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5810 ioc_err(mrioc, "sas io unit page1 read failed\n");
5813 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5814 ioc_err(mrioc, "sas io unit page1 read failed with ioc_status(0x%04x)\n",
5824 * mpi3mr_cfg_set_sas_io_unit_pg1 - Write SASIOUnit page1
5825 * @mrioc: Adapter instance reference
5826 * @sas_io_unit_pg1: Pointer to the SAS IO Unit page 1 to write
5827 * @pg_sz: Size of the memory allocated to the page pointer
5829 * This is handler for config page write for the SAS IO Unit
5830 * page1. This routine checks ioc_status to decide whether the
5831 * page read is success or not. This will modify both current
5832 * and persistent page.
5834 * Return: 0 on success, non-zero on failure.
5836 int mpi3mr_cfg_set_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5837 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5839 struct mpi3_config_page_header cfg_hdr;
5840 struct mpi3_config_request cfg_req;
5843 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5844 memset(&cfg_req, 0, sizeof(cfg_req));
5846 cfg_req.function = MPI3_FUNCTION_CONFIG;
5847 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5848 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5849 cfg_req.page_number = 1;
5850 cfg_req.page_address = 0;
5852 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5853 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5854 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5857 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5858 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5862 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_CURRENT;
5864 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5865 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5866 ioc_err(mrioc, "sas io unit page1 write current failed\n");
5869 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5870 ioc_err(mrioc, "sas io unit page1 write current failed with ioc_status(0x%04x)\n",
5875 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_PERSISTENT;
5877 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5878 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5879 ioc_err(mrioc, "sas io unit page1 write persistent failed\n");
5882 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5883 ioc_err(mrioc, "sas io unit page1 write persistent failed with ioc_status(0x%04x)\n",
5893 * mpi3mr_cfg_get_driver_pg1 - Read current Driver page1
5894 * @mrioc: Adapter instance reference
5895 * @driver_pg1: Pointer to return Driver page 1
5896 * @pg_sz: Size of the memory allocated to the page pointer
5898 * This is handler for config page read for the Driver page1.
5899 * This routine checks ioc_status to decide whether the page
5900 * read is success or not.
5902 * Return: 0 on success, non-zero on failure.
5904 int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc *mrioc,
5905 struct mpi3_driver_page1 *driver_pg1, u16 pg_sz)
5907 struct mpi3_config_page_header cfg_hdr;
5908 struct mpi3_config_request cfg_req;
5911 memset(driver_pg1, 0, pg_sz);
5912 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5913 memset(&cfg_req, 0, sizeof(cfg_req));
5915 cfg_req.function = MPI3_FUNCTION_CONFIG;
5916 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5917 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DRIVER;
5918 cfg_req.page_number = 1;
5919 cfg_req.page_address = 0;
5921 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5922 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5923 ioc_err(mrioc, "driver page1 header read failed\n");
5926 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5927 ioc_err(mrioc, "driver page1 header read failed with ioc_status(0x%04x)\n",
5931 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5933 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5934 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, driver_pg1, pg_sz)) {
5935 ioc_err(mrioc, "driver page1 read failed\n");
5938 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5939 ioc_err(mrioc, "driver page1 read failed with ioc_status(0x%04x)\n",