1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Broadcom MPI3 Storage Controllers
5 * Copyright (C) 2017-2022 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 (cmdptr->is_waiting) {
406 complete(&cmdptr->done);
407 cmdptr->is_waiting = 0;
408 } else if (cmdptr->callback)
409 cmdptr->callback(mrioc, cmdptr);
414 mpi3mr_repost_sense_buf(mrioc,
415 le64_to_cpu(scsi_reply->sense_data_buffer_address));
418 static int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
420 u32 exp_phase = mrioc->admin_reply_ephase;
421 u32 admin_reply_ci = mrioc->admin_reply_ci;
422 u32 num_admin_replies = 0;
424 struct mpi3_default_reply_descriptor *reply_desc;
426 reply_desc = (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
429 if ((le16_to_cpu(reply_desc->reply_flags) &
430 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
434 if (mrioc->unrecoverable)
437 mrioc->admin_req_ci = le16_to_cpu(reply_desc->request_queue_ci);
438 mpi3mr_process_admin_reply_desc(mrioc, reply_desc, &reply_dma);
440 mpi3mr_repost_reply_buf(mrioc, reply_dma);
442 if (++admin_reply_ci == mrioc->num_admin_replies) {
447 (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
449 if ((le16_to_cpu(reply_desc->reply_flags) &
450 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
454 writel(admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
455 mrioc->admin_reply_ci = admin_reply_ci;
456 mrioc->admin_reply_ephase = exp_phase;
458 return num_admin_replies;
462 * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
463 * queue's consumer index from operational reply descriptor queue.
464 * @op_reply_q: op_reply_qinfo object
465 * @reply_ci: operational reply descriptor's queue consumer index
467 * Returns reply descriptor frame address
469 static inline struct mpi3_default_reply_descriptor *
470 mpi3mr_get_reply_desc(struct op_reply_qinfo *op_reply_q, u32 reply_ci)
472 void *segment_base_addr;
473 struct segments *segments = op_reply_q->q_segments;
474 struct mpi3_default_reply_descriptor *reply_desc = NULL;
477 segments[reply_ci / op_reply_q->segment_qd].segment;
478 reply_desc = (struct mpi3_default_reply_descriptor *)segment_base_addr +
479 (reply_ci % op_reply_q->segment_qd);
484 * mpi3mr_process_op_reply_q - Operational reply queue handler
485 * @mrioc: Adapter instance reference
486 * @op_reply_q: Operational reply queue info
488 * Checks the specific operational reply queue and drains the
489 * reply queue entries until the queue is empty and process the
490 * individual reply descriptors.
492 * Return: 0 if queue is already processed,or number of reply
493 * descriptors processed.
495 int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
496 struct op_reply_qinfo *op_reply_q)
498 struct op_req_qinfo *op_req_q;
501 u32 num_op_reply = 0;
503 struct mpi3_default_reply_descriptor *reply_desc;
504 u16 req_q_idx = 0, reply_qidx;
506 reply_qidx = op_reply_q->qid - 1;
508 if (!atomic_add_unless(&op_reply_q->in_use, 1, 1))
511 exp_phase = op_reply_q->ephase;
512 reply_ci = op_reply_q->ci;
514 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
515 if ((le16_to_cpu(reply_desc->reply_flags) &
516 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
517 atomic_dec(&op_reply_q->in_use);
522 if (mrioc->unrecoverable)
525 req_q_idx = le16_to_cpu(reply_desc->request_queue_id) - 1;
526 op_req_q = &mrioc->req_qinfo[req_q_idx];
528 WRITE_ONCE(op_req_q->ci, le16_to_cpu(reply_desc->request_queue_ci));
529 mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
531 atomic_dec(&op_reply_q->pend_ios);
533 mpi3mr_repost_reply_buf(mrioc, reply_dma);
536 if (++reply_ci == op_reply_q->num_replies) {
541 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
543 if ((le16_to_cpu(reply_desc->reply_flags) &
544 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
546 #ifndef CONFIG_PREEMPT_RT
548 * Exit completion loop to avoid CPU lockup
549 * Ensure remaining completion happens from threaded ISR.
551 if (num_op_reply > mrioc->max_host_ios) {
552 op_reply_q->enable_irq_poll = true;
559 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].consumer_index);
560 op_reply_q->ci = reply_ci;
561 op_reply_q->ephase = exp_phase;
563 atomic_dec(&op_reply_q->in_use);
568 * mpi3mr_blk_mq_poll - Operational reply queue handler
569 * @shost: SCSI Host reference
570 * @queue_num: Request queue number (w.r.t OS it is hardware context number)
572 * Checks the specific operational reply queue and drains the
573 * reply queue entries until the queue is empty and process the
574 * individual reply descriptors.
576 * Return: 0 if queue is already processed,or number of reply
577 * descriptors processed.
579 int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
582 struct mpi3mr_ioc *mrioc;
584 mrioc = (struct mpi3mr_ioc *)shost->hostdata;
586 if ((mrioc->reset_in_progress || mrioc->prepare_for_reset ||
587 mrioc->unrecoverable))
590 num_entries = mpi3mr_process_op_reply_q(mrioc,
591 &mrioc->op_reply_qinfo[queue_num]);
596 static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
598 struct mpi3mr_intr_info *intr_info = privdata;
599 struct mpi3mr_ioc *mrioc;
601 u32 num_admin_replies = 0, num_op_reply = 0;
606 mrioc = intr_info->mrioc;
608 if (!mrioc->intr_enabled)
611 midx = intr_info->msix_index;
614 num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
615 if (intr_info->op_reply_q)
616 num_op_reply = mpi3mr_process_op_reply_q(mrioc,
617 intr_info->op_reply_q);
619 if (num_admin_replies || num_op_reply)
625 #ifndef CONFIG_PREEMPT_RT
627 static irqreturn_t mpi3mr_isr(int irq, void *privdata)
629 struct mpi3mr_intr_info *intr_info = privdata;
630 struct mpi3mr_ioc *mrioc;
637 mrioc = intr_info->mrioc;
638 midx = intr_info->msix_index;
639 /* Call primary ISR routine */
640 ret = mpi3mr_isr_primary(irq, privdata);
643 * If more IOs are expected, schedule IRQ polling thread.
644 * Otherwise exit from ISR.
646 if (!intr_info->op_reply_q)
649 if (!intr_info->op_reply_q->enable_irq_poll ||
650 !atomic_read(&intr_info->op_reply_q->pend_ios))
653 disable_irq_nosync(pci_irq_vector(mrioc->pdev, midx));
655 return IRQ_WAKE_THREAD;
659 * mpi3mr_isr_poll - Reply queue polling routine
661 * @privdata: Interrupt info
663 * poll for pending I/O completions in a loop until pending I/Os
664 * present or controller queue depth I/Os are processed.
666 * Return: IRQ_NONE or IRQ_HANDLED
668 static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
670 struct mpi3mr_intr_info *intr_info = privdata;
671 struct mpi3mr_ioc *mrioc;
673 u32 num_op_reply = 0;
675 if (!intr_info || !intr_info->op_reply_q)
678 mrioc = intr_info->mrioc;
679 midx = intr_info->msix_index;
681 /* Poll for pending IOs completions */
683 if (!mrioc->intr_enabled || mrioc->unrecoverable)
687 mpi3mr_process_admin_reply_q(mrioc);
688 if (intr_info->op_reply_q)
690 mpi3mr_process_op_reply_q(mrioc,
691 intr_info->op_reply_q);
693 usleep_range(MPI3MR_IRQ_POLL_SLEEP, 10 * MPI3MR_IRQ_POLL_SLEEP);
695 } while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
696 (num_op_reply < mrioc->max_host_ios));
698 intr_info->op_reply_q->enable_irq_poll = false;
699 enable_irq(pci_irq_vector(mrioc->pdev, midx));
707 * mpi3mr_request_irq - Request IRQ and register ISR
708 * @mrioc: Adapter instance reference
709 * @index: IRQ vector index
711 * Request threaded ISR with primary ISR and secondary
713 * Return: 0 on success and non zero on failures.
715 static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index)
717 struct pci_dev *pdev = mrioc->pdev;
718 struct mpi3mr_intr_info *intr_info = mrioc->intr_info + index;
721 intr_info->mrioc = mrioc;
722 intr_info->msix_index = index;
723 intr_info->op_reply_q = NULL;
725 snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
726 mrioc->driver_name, mrioc->id, index);
728 #ifndef CONFIG_PREEMPT_RT
729 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr,
730 mpi3mr_isr_poll, IRQF_SHARED, intr_info->name, intr_info);
732 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr_primary,
733 NULL, IRQF_SHARED, intr_info->name, intr_info);
736 ioc_err(mrioc, "%s: Unable to allocate interrupt %d!\n",
737 intr_info->name, pci_irq_vector(pdev, index));
744 static void mpi3mr_calc_poll_queues(struct mpi3mr_ioc *mrioc, u16 max_vectors)
746 if (!mrioc->requested_poll_qcount)
749 /* Reserved for Admin and Default Queue */
750 if (max_vectors > 2 &&
751 (mrioc->requested_poll_qcount < max_vectors - 2)) {
753 "enabled polled queues (%d) msix (%d)\n",
754 mrioc->requested_poll_qcount, max_vectors);
757 "disabled polled queues (%d) msix (%d) because of no resources for default queue\n",
758 mrioc->requested_poll_qcount, max_vectors);
759 mrioc->requested_poll_qcount = 0;
764 * mpi3mr_setup_isr - Setup ISR for the controller
765 * @mrioc: Adapter instance reference
766 * @setup_one: Request one IRQ or more
768 * Allocate IRQ vectors and call mpi3mr_request_irq to setup ISR
770 * Return: 0 on success and non zero on failures.
772 static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
774 unsigned int irq_flags = PCI_IRQ_MSIX;
775 int max_vectors, min_vec;
778 struct irq_affinity desc = { .pre_vectors = 1, .post_vectors = 1 };
780 if (mrioc->is_intr_info_set)
783 mpi3mr_cleanup_isr(mrioc);
785 if (setup_one || reset_devices) {
787 retval = pci_alloc_irq_vectors(mrioc->pdev,
788 1, max_vectors, irq_flags);
790 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
796 min_t(int, mrioc->cpu_count + 1 +
797 mrioc->requested_poll_qcount, mrioc->msix_count);
799 mpi3mr_calc_poll_queues(mrioc, max_vectors);
802 "MSI-X vectors supported: %d, no of cores: %d,",
803 mrioc->msix_count, mrioc->cpu_count);
805 "MSI-x vectors requested: %d poll_queues %d\n",
806 max_vectors, mrioc->requested_poll_qcount);
808 desc.post_vectors = mrioc->requested_poll_qcount;
809 min_vec = desc.pre_vectors + desc.post_vectors;
810 irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
812 retval = pci_alloc_irq_vectors_affinity(mrioc->pdev,
813 min_vec, max_vectors, irq_flags, &desc);
816 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
823 * If only one MSI-x is allocated, then MSI-x 0 will be shared
824 * between Admin queue and operational queue
826 if (retval == min_vec)
827 mrioc->op_reply_q_offset = 0;
828 else if (retval != (max_vectors)) {
830 "allocated vectors (%d) are less than configured (%d)\n",
831 retval, max_vectors);
834 max_vectors = retval;
835 mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
837 mpi3mr_calc_poll_queues(mrioc, max_vectors);
841 mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info) * max_vectors,
843 if (!mrioc->intr_info) {
845 pci_free_irq_vectors(mrioc->pdev);
848 for (i = 0; i < max_vectors; i++) {
849 retval = mpi3mr_request_irq(mrioc, i);
851 mrioc->intr_info_count = i;
855 if (reset_devices || !setup_one)
856 mrioc->is_intr_info_set = true;
857 mrioc->intr_info_count = max_vectors;
858 mpi3mr_ioc_enable_intr(mrioc);
862 mpi3mr_cleanup_isr(mrioc);
867 static const struct {
868 enum mpi3mr_iocstate value;
871 { MRIOC_STATE_READY, "ready" },
872 { MRIOC_STATE_FAULT, "fault" },
873 { MRIOC_STATE_RESET, "reset" },
874 { MRIOC_STATE_BECOMING_READY, "becoming ready" },
875 { MRIOC_STATE_RESET_REQUESTED, "reset requested" },
876 { MRIOC_STATE_UNRECOVERABLE, "unrecoverable error" },
879 static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state)
884 for (i = 0; i < ARRAY_SIZE(mrioc_states); i++) {
885 if (mrioc_states[i].value == mrioc_state) {
886 name = mrioc_states[i].name;
893 /* Reset reason to name mapper structure*/
894 static const struct {
895 enum mpi3mr_reset_reason value;
897 } mpi3mr_reset_reason_codes[] = {
898 { MPI3MR_RESET_FROM_BRINGUP, "timeout in bringup" },
899 { MPI3MR_RESET_FROM_FAULT_WATCH, "fault" },
900 { MPI3MR_RESET_FROM_APP, "application invocation" },
901 { MPI3MR_RESET_FROM_EH_HOS, "error handling" },
902 { MPI3MR_RESET_FROM_TM_TIMEOUT, "TM timeout" },
903 { MPI3MR_RESET_FROM_APP_TIMEOUT, "application command timeout" },
904 { MPI3MR_RESET_FROM_MUR_FAILURE, "MUR failure" },
905 { MPI3MR_RESET_FROM_CTLR_CLEANUP, "timeout in controller cleanup" },
906 { MPI3MR_RESET_FROM_CIACTIV_FAULT, "component image activation fault" },
907 { MPI3MR_RESET_FROM_PE_TIMEOUT, "port enable timeout" },
908 { MPI3MR_RESET_FROM_TSU_TIMEOUT, "time stamp update timeout" },
909 { MPI3MR_RESET_FROM_DELREQQ_TIMEOUT, "delete request queue timeout" },
910 { MPI3MR_RESET_FROM_DELREPQ_TIMEOUT, "delete reply queue timeout" },
912 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT,
913 "create request queue timeout"
916 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT,
917 "create reply queue timeout"
919 { MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT, "IOC facts timeout" },
920 { MPI3MR_RESET_FROM_IOCINIT_TIMEOUT, "IOC init timeout" },
921 { MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT, "event notify timeout" },
922 { MPI3MR_RESET_FROM_EVTACK_TIMEOUT, "event acknowledgment timeout" },
924 MPI3MR_RESET_FROM_CIACTVRST_TIMER,
925 "component image activation timeout"
928 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT,
929 "get package version timeout"
931 { MPI3MR_RESET_FROM_SYSFS, "sysfs invocation" },
932 { MPI3MR_RESET_FROM_SYSFS_TIMEOUT, "sysfs TM timeout" },
933 { MPI3MR_RESET_FROM_FIRMWARE, "firmware asynchronous reset" },
934 { MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT, "configuration request timeout"},
935 { MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT, "timeout of a SAS transport layer request" },
939 * mpi3mr_reset_rc_name - get reset reason code name
940 * @reason_code: reset reason code value
942 * Map reset reason to an NULL terminated ASCII string
944 * Return: name corresponding to reset reason value or NULL.
946 static const char *mpi3mr_reset_rc_name(enum mpi3mr_reset_reason reason_code)
951 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_reason_codes); i++) {
952 if (mpi3mr_reset_reason_codes[i].value == reason_code) {
953 name = mpi3mr_reset_reason_codes[i].name;
960 /* Reset type to name mapper structure*/
961 static const struct {
964 } mpi3mr_reset_types[] = {
965 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, "soft" },
966 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, "diag fault" },
970 * mpi3mr_reset_type_name - get reset type name
971 * @reset_type: reset type value
973 * Map reset type to an NULL terminated ASCII string
975 * Return: name corresponding to reset type value or NULL.
977 static const char *mpi3mr_reset_type_name(u16 reset_type)
982 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_types); i++) {
983 if (mpi3mr_reset_types[i].reset_type == reset_type) {
984 name = mpi3mr_reset_types[i].name;
992 * mpi3mr_print_fault_info - Display fault information
993 * @mrioc: Adapter instance reference
995 * Display the controller fault information if there is a
1000 void mpi3mr_print_fault_info(struct mpi3mr_ioc *mrioc)
1002 u32 ioc_status, code, code1, code2, code3;
1004 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1006 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1007 code = readl(&mrioc->sysif_regs->fault);
1008 code1 = readl(&mrioc->sysif_regs->fault_info[0]);
1009 code2 = readl(&mrioc->sysif_regs->fault_info[1]);
1010 code3 = readl(&mrioc->sysif_regs->fault_info[2]);
1013 "fault code(0x%08X): Additional code: (0x%08X:0x%08X:0x%08X)\n",
1014 code, code1, code2, code3);
1019 * mpi3mr_get_iocstate - Get IOC State
1020 * @mrioc: Adapter instance reference
1022 * Return a proper IOC state enum based on the IOC status and
1023 * IOC configuration and unrcoverable state of the controller.
1025 * Return: Current IOC state.
1027 enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc)
1029 u32 ioc_status, ioc_config;
1032 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1033 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1035 if (mrioc->unrecoverable)
1036 return MRIOC_STATE_UNRECOVERABLE;
1037 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)
1038 return MRIOC_STATE_FAULT;
1040 ready = (ioc_status & MPI3_SYSIF_IOC_STATUS_READY);
1041 enabled = (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC);
1043 if (ready && enabled)
1044 return MRIOC_STATE_READY;
1045 if ((!ready) && (!enabled))
1046 return MRIOC_STATE_RESET;
1047 if ((!ready) && (enabled))
1048 return MRIOC_STATE_BECOMING_READY;
1050 return MRIOC_STATE_RESET_REQUESTED;
1054 * mpi3mr_clear_reset_history - clear reset history
1055 * @mrioc: Adapter instance reference
1057 * Write the reset history bit in IOC status to clear the bit,
1058 * if it is already set.
1062 static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc *mrioc)
1066 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1067 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1068 writel(ioc_status, &mrioc->sysif_regs->ioc_status);
1072 * mpi3mr_issue_and_process_mur - Message unit Reset handler
1073 * @mrioc: Adapter instance reference
1074 * @reset_reason: Reset reason code
1076 * Issue Message unit Reset to the controller and wait for it to
1079 * Return: 0 on success, -1 on failure.
1081 static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
1084 u32 ioc_config, timeout, ioc_status;
1087 ioc_info(mrioc, "Issuing Message unit Reset(MUR)\n");
1088 if (mrioc->unrecoverable) {
1089 ioc_info(mrioc, "IOC is unrecoverable MUR not issued\n");
1092 mpi3mr_clear_reset_history(mrioc);
1093 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1094 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1095 ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1096 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1098 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
1100 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1101 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)) {
1102 mpi3mr_clear_reset_history(mrioc);
1105 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1106 mpi3mr_print_fault_info(mrioc);
1110 } while (--timeout);
1112 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1113 if (timeout && !((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1114 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
1115 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1118 ioc_info(mrioc, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
1119 (!retval) ? "successful" : "failed", ioc_status, ioc_config);
1124 * mpi3mr_revalidate_factsdata - validate IOCFacts parameters
1125 * during reset/resume
1126 * @mrioc: Adapter instance reference
1128 * Return zero if the new IOCFacts parameters value is compatible with
1129 * older values else return -EPERM
1132 mpi3mr_revalidate_factsdata(struct mpi3mr_ioc *mrioc)
1134 u16 dev_handle_bitmap_sz;
1135 void *removepend_bitmap;
1137 if (mrioc->facts.reply_sz > mrioc->reply_sz) {
1139 "cannot increase reply size from %d to %d\n",
1140 mrioc->reply_sz, mrioc->facts.reply_sz);
1144 if (mrioc->facts.max_op_reply_q < mrioc->num_op_reply_q) {
1146 "cannot reduce number of operational reply queues from %d to %d\n",
1147 mrioc->num_op_reply_q,
1148 mrioc->facts.max_op_reply_q);
1152 if (mrioc->facts.max_op_req_q < mrioc->num_op_req_q) {
1154 "cannot reduce number of operational request queues from %d to %d\n",
1155 mrioc->num_op_req_q, mrioc->facts.max_op_req_q);
1159 if ((mrioc->sas_transport_enabled) && (mrioc->facts.ioc_capabilities &
1160 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED))
1162 "critical error: multipath capability is enabled at the\n"
1163 "\tcontroller while sas transport support is enabled at the\n"
1164 "\tdriver, please reboot the system or reload the driver\n");
1166 dev_handle_bitmap_sz = mrioc->facts.max_devhandle / 8;
1167 if (mrioc->facts.max_devhandle % 8)
1168 dev_handle_bitmap_sz++;
1169 if (dev_handle_bitmap_sz > mrioc->dev_handle_bitmap_sz) {
1170 removepend_bitmap = krealloc(mrioc->removepend_bitmap,
1171 dev_handle_bitmap_sz, GFP_KERNEL);
1172 if (!removepend_bitmap) {
1174 "failed to increase removepend_bitmap sz from: %d to %d\n",
1175 mrioc->dev_handle_bitmap_sz, dev_handle_bitmap_sz);
1178 memset(removepend_bitmap + mrioc->dev_handle_bitmap_sz, 0,
1179 dev_handle_bitmap_sz - mrioc->dev_handle_bitmap_sz);
1180 mrioc->removepend_bitmap = removepend_bitmap;
1182 "increased dev_handle_bitmap_sz from %d to %d\n",
1183 mrioc->dev_handle_bitmap_sz, dev_handle_bitmap_sz);
1184 mrioc->dev_handle_bitmap_sz = dev_handle_bitmap_sz;
1191 * mpi3mr_bring_ioc_ready - Bring controller to ready state
1192 * @mrioc: Adapter instance reference
1194 * Set Enable IOC bit in IOC configuration register and wait for
1195 * the controller to become ready.
1197 * Return: 0 on success, appropriate error on failure.
1199 static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
1201 u32 ioc_config, ioc_status, timeout;
1203 enum mpi3mr_iocstate ioc_state;
1206 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1207 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1208 base_info = lo_hi_readq(&mrioc->sysif_regs->ioc_information);
1209 ioc_info(mrioc, "ioc_status(0x%08x), ioc_config(0x%08x), ioc_info(0x%016llx) at the bringup\n",
1210 ioc_status, ioc_config, base_info);
1212 /*The timeout value is in 2sec unit, changing it to seconds*/
1213 mrioc->ready_timeout =
1214 ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
1215 MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
1217 ioc_info(mrioc, "ready timeout: %d seconds\n", mrioc->ready_timeout);
1219 ioc_state = mpi3mr_get_iocstate(mrioc);
1220 ioc_info(mrioc, "controller is in %s state during detection\n",
1221 mpi3mr_iocstate_name(ioc_state));
1223 if (ioc_state == MRIOC_STATE_BECOMING_READY ||
1224 ioc_state == MRIOC_STATE_RESET_REQUESTED) {
1225 timeout = mrioc->ready_timeout * 10;
1228 } while (--timeout);
1230 if (!pci_device_is_present(mrioc->pdev)) {
1231 mrioc->unrecoverable = 1;
1233 "controller is not present while waiting to reset\n");
1235 goto out_device_not_present;
1238 ioc_state = mpi3mr_get_iocstate(mrioc);
1240 "controller is in %s state after waiting to reset\n",
1241 mpi3mr_iocstate_name(ioc_state));
1244 if (ioc_state == MRIOC_STATE_READY) {
1245 ioc_info(mrioc, "issuing message unit reset (MUR) to bring to reset state\n");
1246 retval = mpi3mr_issue_and_process_mur(mrioc,
1247 MPI3MR_RESET_FROM_BRINGUP);
1248 ioc_state = mpi3mr_get_iocstate(mrioc);
1251 "message unit reset failed with error %d current state %s\n",
1252 retval, mpi3mr_iocstate_name(ioc_state));
1254 if (ioc_state != MRIOC_STATE_RESET) {
1255 mpi3mr_print_fault_info(mrioc);
1256 ioc_info(mrioc, "issuing soft reset to bring to reset state\n");
1257 retval = mpi3mr_issue_reset(mrioc,
1258 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
1259 MPI3MR_RESET_FROM_BRINGUP);
1262 "soft reset failed with error %d\n", retval);
1266 ioc_state = mpi3mr_get_iocstate(mrioc);
1267 if (ioc_state != MRIOC_STATE_RESET) {
1269 "cannot bring controller to reset state, current state: %s\n",
1270 mpi3mr_iocstate_name(ioc_state));
1273 mpi3mr_clear_reset_history(mrioc);
1274 retval = mpi3mr_setup_admin_qpair(mrioc);
1276 ioc_err(mrioc, "failed to setup admin queues: error %d\n",
1281 ioc_info(mrioc, "bringing controller to ready state\n");
1282 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1283 ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1284 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1286 timeout = mrioc->ready_timeout * 10;
1288 ioc_state = mpi3mr_get_iocstate(mrioc);
1289 if (ioc_state == MRIOC_STATE_READY) {
1291 "successfully transitioned to %s state\n",
1292 mpi3mr_iocstate_name(ioc_state));
1295 if (!pci_device_is_present(mrioc->pdev)) {
1296 mrioc->unrecoverable = 1;
1298 "controller is not present at the bringup\n");
1300 goto out_device_not_present;
1303 } while (--timeout);
1306 ioc_state = mpi3mr_get_iocstate(mrioc);
1308 "failed to bring to ready state, current state: %s\n",
1309 mpi3mr_iocstate_name(ioc_state));
1310 out_device_not_present:
1315 * mpi3mr_soft_reset_success - Check softreset is success or not
1316 * @ioc_status: IOC status register value
1317 * @ioc_config: IOC config register value
1319 * Check whether the soft reset is successful or not based on
1320 * IOC status and IOC config register values.
1322 * Return: True when the soft reset is success, false otherwise.
1325 mpi3mr_soft_reset_success(u32 ioc_status, u32 ioc_config)
1327 if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1328 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1334 * mpi3mr_diagfault_success - Check diag fault is success or not
1335 * @mrioc: Adapter reference
1336 * @ioc_status: IOC status register value
1338 * Check whether the controller hit diag reset fault code.
1340 * Return: True when there is diag fault, false otherwise.
1342 static inline bool mpi3mr_diagfault_success(struct mpi3mr_ioc *mrioc,
1347 if (!(ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT))
1349 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
1350 if (fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET) {
1351 mpi3mr_print_fault_info(mrioc);
1358 * mpi3mr_set_diagsave - Set diag save bit for snapdump
1359 * @mrioc: Adapter reference
1361 * Set diag save bit in IOC configuration register to enable
1366 static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
1370 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1371 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE;
1372 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1376 * mpi3mr_issue_reset - Issue reset to the controller
1377 * @mrioc: Adapter reference
1378 * @reset_type: Reset type
1379 * @reset_reason: Reset reason code
1381 * Unlock the host diagnostic registers and write the specific
1382 * reset type to that, wait for reset acknowledgment from the
1383 * controller, if the reset is not successful retry for the
1384 * predefined number of times.
1386 * Return: 0 on success, non-zero on failure.
1388 static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
1392 u8 unlock_retry_count = 0;
1393 u32 host_diagnostic, ioc_status, ioc_config;
1394 u32 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
1396 if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
1397 (reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT))
1399 if (mrioc->unrecoverable)
1401 if (reset_reason == MPI3MR_RESET_FROM_FIRMWARE) {
1406 ioc_info(mrioc, "%s reset due to %s(0x%x)\n",
1407 mpi3mr_reset_type_name(reset_type),
1408 mpi3mr_reset_rc_name(reset_reason), reset_reason);
1410 mpi3mr_clear_reset_history(mrioc);
1413 "Write magic sequence to unlock host diag register (retry=%d)\n",
1414 ++unlock_retry_count);
1415 if (unlock_retry_count >= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT) {
1417 "%s reset failed due to unlock failure, host_diagnostic(0x%08x)\n",
1418 mpi3mr_reset_type_name(reset_type),
1420 mrioc->unrecoverable = 1;
1424 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH,
1425 &mrioc->sysif_regs->write_sequence);
1426 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST,
1427 &mrioc->sysif_regs->write_sequence);
1428 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1429 &mrioc->sysif_regs->write_sequence);
1430 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD,
1431 &mrioc->sysif_regs->write_sequence);
1432 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH,
1433 &mrioc->sysif_regs->write_sequence);
1434 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH,
1435 &mrioc->sysif_regs->write_sequence);
1436 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH,
1437 &mrioc->sysif_regs->write_sequence);
1438 usleep_range(1000, 1100);
1439 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
1441 "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
1442 unlock_retry_count, host_diagnostic);
1443 } while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
1445 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1446 writel(host_diagnostic | reset_type,
1447 &mrioc->sysif_regs->host_diagnostic);
1448 switch (reset_type) {
1449 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET:
1451 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1453 readl(&mrioc->sysif_regs->ioc_configuration);
1454 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1455 && mpi3mr_soft_reset_success(ioc_status, ioc_config)
1457 mpi3mr_clear_reset_history(mrioc);
1462 } while (--timeout);
1463 mpi3mr_print_fault_info(mrioc);
1465 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT:
1467 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1468 if (mpi3mr_diagfault_success(mrioc, ioc_status)) {
1473 } while (--timeout);
1479 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1480 &mrioc->sysif_regs->write_sequence);
1482 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1483 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1485 "ioc_status/ioc_onfig after %s reset is (0x%x)/(0x%x)\n",
1486 (!retval)?"successful":"failed", ioc_status,
1489 mrioc->unrecoverable = 1;
1494 * mpi3mr_admin_request_post - Post request to admin queue
1495 * @mrioc: Adapter reference
1496 * @admin_req: MPI3 request
1497 * @admin_req_sz: Request size
1498 * @ignore_reset: Ignore reset in process
1500 * Post the MPI3 request into admin request queue and
1501 * inform the controller, if the queue is full return
1502 * appropriate error.
1504 * Return: 0 on success, non-zero on failure.
1506 int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
1507 u16 admin_req_sz, u8 ignore_reset)
1509 u16 areq_pi = 0, areq_ci = 0, max_entries = 0;
1511 unsigned long flags;
1514 if (mrioc->unrecoverable) {
1515 ioc_err(mrioc, "%s : Unrecoverable controller\n", __func__);
1519 spin_lock_irqsave(&mrioc->admin_req_lock, flags);
1520 areq_pi = mrioc->admin_req_pi;
1521 areq_ci = mrioc->admin_req_ci;
1522 max_entries = mrioc->num_admin_req;
1523 if ((areq_ci == (areq_pi + 1)) || ((!areq_ci) &&
1524 (areq_pi == (max_entries - 1)))) {
1525 ioc_err(mrioc, "AdminReqQ full condition detected\n");
1529 if (!ignore_reset && mrioc->reset_in_progress) {
1530 ioc_err(mrioc, "AdminReqQ submit reset in progress\n");
1534 areq_entry = (u8 *)mrioc->admin_req_base +
1535 (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
1536 memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
1537 memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
1539 if (++areq_pi == max_entries)
1541 mrioc->admin_req_pi = areq_pi;
1543 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
1546 spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
1552 * mpi3mr_free_op_req_q_segments - free request memory segments
1553 * @mrioc: Adapter instance reference
1554 * @q_idx: operational request queue index
1556 * Free memory segments allocated for operational request queue
1560 static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1564 struct segments *segments;
1566 segments = mrioc->req_qinfo[q_idx].q_segments;
1570 if (mrioc->enable_segqueue) {
1571 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1572 if (mrioc->req_qinfo[q_idx].q_segment_list) {
1573 dma_free_coherent(&mrioc->pdev->dev,
1574 MPI3MR_MAX_SEG_LIST_SIZE,
1575 mrioc->req_qinfo[q_idx].q_segment_list,
1576 mrioc->req_qinfo[q_idx].q_segment_list_dma);
1577 mrioc->req_qinfo[q_idx].q_segment_list = NULL;
1580 size = mrioc->req_qinfo[q_idx].segment_qd *
1581 mrioc->facts.op_req_sz;
1583 for (j = 0; j < mrioc->req_qinfo[q_idx].num_segments; j++) {
1584 if (!segments[j].segment)
1586 dma_free_coherent(&mrioc->pdev->dev,
1587 size, segments[j].segment, segments[j].segment_dma);
1588 segments[j].segment = NULL;
1590 kfree(mrioc->req_qinfo[q_idx].q_segments);
1591 mrioc->req_qinfo[q_idx].q_segments = NULL;
1592 mrioc->req_qinfo[q_idx].qid = 0;
1596 * mpi3mr_free_op_reply_q_segments - free reply memory segments
1597 * @mrioc: Adapter instance reference
1598 * @q_idx: operational reply queue index
1600 * Free memory segments allocated for operational reply queue
1604 static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1608 struct segments *segments;
1610 segments = mrioc->op_reply_qinfo[q_idx].q_segments;
1614 if (mrioc->enable_segqueue) {
1615 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1616 if (mrioc->op_reply_qinfo[q_idx].q_segment_list) {
1617 dma_free_coherent(&mrioc->pdev->dev,
1618 MPI3MR_MAX_SEG_LIST_SIZE,
1619 mrioc->op_reply_qinfo[q_idx].q_segment_list,
1620 mrioc->op_reply_qinfo[q_idx].q_segment_list_dma);
1621 mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
1624 size = mrioc->op_reply_qinfo[q_idx].segment_qd *
1625 mrioc->op_reply_desc_sz;
1627 for (j = 0; j < mrioc->op_reply_qinfo[q_idx].num_segments; j++) {
1628 if (!segments[j].segment)
1630 dma_free_coherent(&mrioc->pdev->dev,
1631 size, segments[j].segment, segments[j].segment_dma);
1632 segments[j].segment = NULL;
1635 kfree(mrioc->op_reply_qinfo[q_idx].q_segments);
1636 mrioc->op_reply_qinfo[q_idx].q_segments = NULL;
1637 mrioc->op_reply_qinfo[q_idx].qid = 0;
1641 * mpi3mr_delete_op_reply_q - delete operational reply queue
1642 * @mrioc: Adapter instance reference
1643 * @qidx: operational reply queue index
1645 * Delete operatinal reply queue by issuing MPI request
1646 * through admin queue.
1648 * Return: 0 on success, non-zero on failure.
1650 static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1652 struct mpi3_delete_reply_queue_request delq_req;
1653 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1655 u16 reply_qid = 0, midx;
1657 reply_qid = op_reply_q->qid;
1659 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1663 ioc_err(mrioc, "Issue DelRepQ: called with invalid ReqQID\n");
1667 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount-- :
1668 mrioc->active_poll_qcount--;
1670 memset(&delq_req, 0, sizeof(delq_req));
1671 mutex_lock(&mrioc->init_cmds.mutex);
1672 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1674 ioc_err(mrioc, "Issue DelRepQ: Init command is in use\n");
1675 mutex_unlock(&mrioc->init_cmds.mutex);
1678 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1679 mrioc->init_cmds.is_waiting = 1;
1680 mrioc->init_cmds.callback = NULL;
1681 delq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1682 delq_req.function = MPI3_FUNCTION_DELETE_REPLY_QUEUE;
1683 delq_req.queue_id = cpu_to_le16(reply_qid);
1685 init_completion(&mrioc->init_cmds.done);
1686 retval = mpi3mr_admin_request_post(mrioc, &delq_req, sizeof(delq_req),
1689 ioc_err(mrioc, "Issue DelRepQ: Admin Post failed\n");
1692 wait_for_completion_timeout(&mrioc->init_cmds.done,
1693 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1694 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1695 ioc_err(mrioc, "delete reply queue timed out\n");
1696 mpi3mr_check_rh_fault_ioc(mrioc,
1697 MPI3MR_RESET_FROM_DELREPQ_TIMEOUT);
1701 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1702 != MPI3_IOCSTATUS_SUCCESS) {
1704 "Issue DelRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1705 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1706 mrioc->init_cmds.ioc_loginfo);
1710 mrioc->intr_info[midx].op_reply_q = NULL;
1712 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1714 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1715 mutex_unlock(&mrioc->init_cmds.mutex);
1722 * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
1723 * @mrioc: Adapter instance reference
1724 * @qidx: request queue index
1726 * Allocate segmented memory pools for operational reply
1729 * Return: 0 on success, non-zero on failure.
1731 static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1733 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1735 u64 *q_segment_list_entry = NULL;
1736 struct segments *segments;
1738 if (mrioc->enable_segqueue) {
1739 op_reply_q->segment_qd =
1740 MPI3MR_OP_REP_Q_SEG_SIZE / mrioc->op_reply_desc_sz;
1742 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1744 op_reply_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1745 MPI3MR_MAX_SEG_LIST_SIZE, &op_reply_q->q_segment_list_dma,
1747 if (!op_reply_q->q_segment_list)
1749 q_segment_list_entry = (u64 *)op_reply_q->q_segment_list;
1751 op_reply_q->segment_qd = op_reply_q->num_replies;
1752 size = op_reply_q->num_replies * mrioc->op_reply_desc_sz;
1755 op_reply_q->num_segments = DIV_ROUND_UP(op_reply_q->num_replies,
1756 op_reply_q->segment_qd);
1758 op_reply_q->q_segments = kcalloc(op_reply_q->num_segments,
1759 sizeof(struct segments), GFP_KERNEL);
1760 if (!op_reply_q->q_segments)
1763 segments = op_reply_q->q_segments;
1764 for (i = 0; i < op_reply_q->num_segments; i++) {
1765 segments[i].segment =
1766 dma_alloc_coherent(&mrioc->pdev->dev,
1767 size, &segments[i].segment_dma, GFP_KERNEL);
1768 if (!segments[i].segment)
1770 if (mrioc->enable_segqueue)
1771 q_segment_list_entry[i] =
1772 (unsigned long)segments[i].segment_dma;
1779 * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
1780 * @mrioc: Adapter instance reference
1781 * @qidx: request queue index
1783 * Allocate segmented memory pools for operational request
1786 * Return: 0 on success, non-zero on failure.
1788 static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1790 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
1792 u64 *q_segment_list_entry = NULL;
1793 struct segments *segments;
1795 if (mrioc->enable_segqueue) {
1796 op_req_q->segment_qd =
1797 MPI3MR_OP_REQ_Q_SEG_SIZE / mrioc->facts.op_req_sz;
1799 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1801 op_req_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1802 MPI3MR_MAX_SEG_LIST_SIZE, &op_req_q->q_segment_list_dma,
1804 if (!op_req_q->q_segment_list)
1806 q_segment_list_entry = (u64 *)op_req_q->q_segment_list;
1809 op_req_q->segment_qd = op_req_q->num_requests;
1810 size = op_req_q->num_requests * mrioc->facts.op_req_sz;
1813 op_req_q->num_segments = DIV_ROUND_UP(op_req_q->num_requests,
1814 op_req_q->segment_qd);
1816 op_req_q->q_segments = kcalloc(op_req_q->num_segments,
1817 sizeof(struct segments), GFP_KERNEL);
1818 if (!op_req_q->q_segments)
1821 segments = op_req_q->q_segments;
1822 for (i = 0; i < op_req_q->num_segments; i++) {
1823 segments[i].segment =
1824 dma_alloc_coherent(&mrioc->pdev->dev,
1825 size, &segments[i].segment_dma, GFP_KERNEL);
1826 if (!segments[i].segment)
1828 if (mrioc->enable_segqueue)
1829 q_segment_list_entry[i] =
1830 (unsigned long)segments[i].segment_dma;
1837 * mpi3mr_create_op_reply_q - create operational reply queue
1838 * @mrioc: Adapter instance reference
1839 * @qidx: operational reply queue index
1841 * Create operatinal reply queue by issuing MPI request
1842 * through admin queue.
1844 * Return: 0 on success, non-zero on failure.
1846 static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1848 struct mpi3_create_reply_queue_request create_req;
1849 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1851 u16 reply_qid = 0, midx;
1853 reply_qid = op_reply_q->qid;
1855 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1859 ioc_err(mrioc, "CreateRepQ: called for duplicate qid %d\n",
1865 reply_qid = qidx + 1;
1866 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
1867 if (!mrioc->pdev->revision)
1868 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD4K;
1870 op_reply_q->ephase = 1;
1871 atomic_set(&op_reply_q->pend_ios, 0);
1872 atomic_set(&op_reply_q->in_use, 0);
1873 op_reply_q->enable_irq_poll = false;
1875 if (!op_reply_q->q_segments) {
1876 retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
1878 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1883 memset(&create_req, 0, sizeof(create_req));
1884 mutex_lock(&mrioc->init_cmds.mutex);
1885 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1887 ioc_err(mrioc, "CreateRepQ: Init command is in use\n");
1890 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1891 mrioc->init_cmds.is_waiting = 1;
1892 mrioc->init_cmds.callback = NULL;
1893 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1894 create_req.function = MPI3_FUNCTION_CREATE_REPLY_QUEUE;
1895 create_req.queue_id = cpu_to_le16(reply_qid);
1897 if (midx < (mrioc->intr_info_count - mrioc->requested_poll_qcount))
1898 op_reply_q->qtype = MPI3MR_DEFAULT_QUEUE;
1900 op_reply_q->qtype = MPI3MR_POLL_QUEUE;
1902 if (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) {
1904 MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE;
1905 create_req.msix_index =
1906 cpu_to_le16(mrioc->intr_info[midx].msix_index);
1908 create_req.msix_index = cpu_to_le16(mrioc->intr_info_count - 1);
1909 ioc_info(mrioc, "create reply queue(polled): for qid(%d), midx(%d)\n",
1911 if (!mrioc->active_poll_qcount)
1912 disable_irq_nosync(pci_irq_vector(mrioc->pdev,
1913 mrioc->intr_info_count - 1));
1916 if (mrioc->enable_segqueue) {
1918 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
1919 create_req.base_address = cpu_to_le64(
1920 op_reply_q->q_segment_list_dma);
1922 create_req.base_address = cpu_to_le64(
1923 op_reply_q->q_segments[0].segment_dma);
1925 create_req.size = cpu_to_le16(op_reply_q->num_replies);
1927 init_completion(&mrioc->init_cmds.done);
1928 retval = mpi3mr_admin_request_post(mrioc, &create_req,
1929 sizeof(create_req), 1);
1931 ioc_err(mrioc, "CreateRepQ: Admin Post failed\n");
1934 wait_for_completion_timeout(&mrioc->init_cmds.done,
1935 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1936 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1937 ioc_err(mrioc, "create reply queue timed out\n");
1938 mpi3mr_check_rh_fault_ioc(mrioc,
1939 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT);
1943 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1944 != MPI3_IOCSTATUS_SUCCESS) {
1946 "CreateRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1947 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1948 mrioc->init_cmds.ioc_loginfo);
1952 op_reply_q->qid = reply_qid;
1953 if (midx < mrioc->intr_info_count)
1954 mrioc->intr_info[midx].op_reply_q = op_reply_q;
1956 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount++ :
1957 mrioc->active_poll_qcount++;
1960 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1961 mutex_unlock(&mrioc->init_cmds.mutex);
1968 * mpi3mr_create_op_req_q - create operational request queue
1969 * @mrioc: Adapter instance reference
1970 * @idx: operational request queue index
1971 * @reply_qid: Reply queue ID
1973 * Create operatinal request queue by issuing MPI request
1974 * through admin queue.
1976 * Return: 0 on success, non-zero on failure.
1978 static int mpi3mr_create_op_req_q(struct mpi3mr_ioc *mrioc, u16 idx,
1981 struct mpi3_create_request_queue_request create_req;
1982 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + idx;
1986 req_qid = op_req_q->qid;
1990 ioc_err(mrioc, "CreateReqQ: called for duplicate qid %d\n",
1997 op_req_q->num_requests = MPI3MR_OP_REQ_Q_QD;
2000 op_req_q->reply_qid = reply_qid;
2001 spin_lock_init(&op_req_q->q_lock);
2003 if (!op_req_q->q_segments) {
2004 retval = mpi3mr_alloc_op_req_q_segments(mrioc, idx);
2006 mpi3mr_free_op_req_q_segments(mrioc, idx);
2011 memset(&create_req, 0, sizeof(create_req));
2012 mutex_lock(&mrioc->init_cmds.mutex);
2013 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2015 ioc_err(mrioc, "CreateReqQ: Init command is in use\n");
2018 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2019 mrioc->init_cmds.is_waiting = 1;
2020 mrioc->init_cmds.callback = NULL;
2021 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2022 create_req.function = MPI3_FUNCTION_CREATE_REQUEST_QUEUE;
2023 create_req.queue_id = cpu_to_le16(req_qid);
2024 if (mrioc->enable_segqueue) {
2026 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
2027 create_req.base_address = cpu_to_le64(
2028 op_req_q->q_segment_list_dma);
2030 create_req.base_address = cpu_to_le64(
2031 op_req_q->q_segments[0].segment_dma);
2032 create_req.reply_queue_id = cpu_to_le16(reply_qid);
2033 create_req.size = cpu_to_le16(op_req_q->num_requests);
2035 init_completion(&mrioc->init_cmds.done);
2036 retval = mpi3mr_admin_request_post(mrioc, &create_req,
2037 sizeof(create_req), 1);
2039 ioc_err(mrioc, "CreateReqQ: Admin Post failed\n");
2042 wait_for_completion_timeout(&mrioc->init_cmds.done,
2043 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2044 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2045 ioc_err(mrioc, "create request queue timed out\n");
2046 mpi3mr_check_rh_fault_ioc(mrioc,
2047 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT);
2051 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2052 != MPI3_IOCSTATUS_SUCCESS) {
2054 "CreateReqQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2055 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2056 mrioc->init_cmds.ioc_loginfo);
2060 op_req_q->qid = req_qid;
2063 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2064 mutex_unlock(&mrioc->init_cmds.mutex);
2071 * mpi3mr_create_op_queues - create operational queue pairs
2072 * @mrioc: Adapter instance reference
2074 * Allocate memory for operational queue meta data and call
2075 * create request and reply queue functions.
2077 * Return: 0 on success, non-zero on failures.
2079 static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
2082 u16 num_queues = 0, i = 0, msix_count_op_q = 1;
2084 num_queues = min_t(int, mrioc->facts.max_op_reply_q,
2085 mrioc->facts.max_op_req_q);
2088 mrioc->intr_info_count - mrioc->op_reply_q_offset;
2089 if (!mrioc->num_queues)
2090 mrioc->num_queues = min_t(int, num_queues, msix_count_op_q);
2092 * During reset set the num_queues to the number of queues
2093 * that was set before the reset.
2095 num_queues = mrioc->num_op_reply_q ?
2096 mrioc->num_op_reply_q : mrioc->num_queues;
2097 ioc_info(mrioc, "trying to create %d operational queue pairs\n",
2100 if (!mrioc->req_qinfo) {
2101 mrioc->req_qinfo = kcalloc(num_queues,
2102 sizeof(struct op_req_qinfo), GFP_KERNEL);
2103 if (!mrioc->req_qinfo) {
2108 mrioc->op_reply_qinfo = kzalloc(sizeof(struct op_reply_qinfo) *
2109 num_queues, GFP_KERNEL);
2110 if (!mrioc->op_reply_qinfo) {
2116 if (mrioc->enable_segqueue)
2118 "allocating operational queues through segmented queues\n");
2120 for (i = 0; i < num_queues; i++) {
2121 if (mpi3mr_create_op_reply_q(mrioc, i)) {
2122 ioc_err(mrioc, "Cannot create OP RepQ %d\n", i);
2125 if (mpi3mr_create_op_req_q(mrioc, i,
2126 mrioc->op_reply_qinfo[i].qid)) {
2127 ioc_err(mrioc, "Cannot create OP ReqQ %d\n", i);
2128 mpi3mr_delete_op_reply_q(mrioc, i);
2134 /* Not even one queue is created successfully*/
2138 mrioc->num_op_reply_q = mrioc->num_op_req_q = i;
2140 "successfully created %d operational queue pairs(default/polled) queue = (%d/%d)\n",
2141 mrioc->num_op_reply_q, mrioc->default_qcount,
2142 mrioc->active_poll_qcount);
2146 kfree(mrioc->req_qinfo);
2147 mrioc->req_qinfo = NULL;
2149 kfree(mrioc->op_reply_qinfo);
2150 mrioc->op_reply_qinfo = NULL;
2156 * mpi3mr_op_request_post - Post request to operational queue
2157 * @mrioc: Adapter reference
2158 * @op_req_q: Operational request queue info
2159 * @req: MPI3 request
2161 * Post the MPI3 request into operational request queue and
2162 * inform the controller, if the queue is full return
2163 * appropriate error.
2165 * Return: 0 on success, non-zero on failure.
2167 int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
2168 struct op_req_qinfo *op_req_q, u8 *req)
2170 u16 pi = 0, max_entries, reply_qidx = 0, midx;
2172 unsigned long flags;
2174 void *segment_base_addr;
2175 u16 req_sz = mrioc->facts.op_req_sz;
2176 struct segments *segments = op_req_q->q_segments;
2178 reply_qidx = op_req_q->reply_qid - 1;
2180 if (mrioc->unrecoverable)
2183 spin_lock_irqsave(&op_req_q->q_lock, flags);
2185 max_entries = op_req_q->num_requests;
2187 if (mpi3mr_check_req_qfull(op_req_q)) {
2188 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
2189 reply_qidx, mrioc->op_reply_q_offset);
2190 mpi3mr_process_op_reply_q(mrioc, mrioc->intr_info[midx].op_reply_q);
2192 if (mpi3mr_check_req_qfull(op_req_q)) {
2198 if (mrioc->reset_in_progress) {
2199 ioc_err(mrioc, "OpReqQ submit reset in progress\n");
2204 segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
2205 req_entry = (u8 *)segment_base_addr +
2206 ((pi % op_req_q->segment_qd) * req_sz);
2208 memset(req_entry, 0, req_sz);
2209 memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
2211 if (++pi == max_entries)
2215 #ifndef CONFIG_PREEMPT_RT
2216 if (atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios)
2217 > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT)
2218 mrioc->op_reply_qinfo[reply_qidx].enable_irq_poll = true;
2220 atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios);
2223 writel(op_req_q->pi,
2224 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].producer_index);
2227 spin_unlock_irqrestore(&op_req_q->q_lock, flags);
2232 * mpi3mr_check_rh_fault_ioc - check reset history and fault
2234 * @mrioc: Adapter instance reference
2235 * @reason_code: reason code for the fault.
2237 * This routine will save snapdump and fault the controller with
2238 * the given reason code if it is not already in the fault or
2239 * not asynchronosuly reset. This will be used to handle
2240 * initilaization time faults/resets/timeout as in those cases
2241 * immediate soft reset invocation is not required.
2245 void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code)
2247 u32 ioc_status, host_diagnostic, timeout;
2249 if (mrioc->unrecoverable) {
2250 ioc_err(mrioc, "controller is unrecoverable\n");
2254 if (!pci_device_is_present(mrioc->pdev)) {
2255 mrioc->unrecoverable = 1;
2256 ioc_err(mrioc, "controller is not present\n");
2260 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2261 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
2262 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
2263 mpi3mr_print_fault_info(mrioc);
2266 mpi3mr_set_diagsave(mrioc);
2267 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
2269 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
2271 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2272 if (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
2275 } while (--timeout);
2279 * mpi3mr_sync_timestamp - Issue time stamp sync request
2280 * @mrioc: Adapter reference
2282 * Issue IO unit control MPI request to synchornize firmware
2283 * timestamp with host time.
2285 * Return: 0 on success, non-zero on failure.
2287 static int mpi3mr_sync_timestamp(struct mpi3mr_ioc *mrioc)
2289 ktime_t current_time;
2290 struct mpi3_iounit_control_request iou_ctrl;
2293 memset(&iou_ctrl, 0, sizeof(iou_ctrl));
2294 mutex_lock(&mrioc->init_cmds.mutex);
2295 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2297 ioc_err(mrioc, "Issue IOUCTL time_stamp: command is in use\n");
2298 mutex_unlock(&mrioc->init_cmds.mutex);
2301 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2302 mrioc->init_cmds.is_waiting = 1;
2303 mrioc->init_cmds.callback = NULL;
2304 iou_ctrl.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2305 iou_ctrl.function = MPI3_FUNCTION_IO_UNIT_CONTROL;
2306 iou_ctrl.operation = MPI3_CTRL_OP_UPDATE_TIMESTAMP;
2307 current_time = ktime_get_real();
2308 iou_ctrl.param64[0] = cpu_to_le64(ktime_to_ms(current_time));
2310 init_completion(&mrioc->init_cmds.done);
2311 retval = mpi3mr_admin_request_post(mrioc, &iou_ctrl,
2312 sizeof(iou_ctrl), 0);
2314 ioc_err(mrioc, "Issue IOUCTL time_stamp: Admin Post failed\n");
2318 wait_for_completion_timeout(&mrioc->init_cmds.done,
2319 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2320 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2321 ioc_err(mrioc, "Issue IOUCTL time_stamp: command timed out\n");
2322 mrioc->init_cmds.is_waiting = 0;
2323 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
2324 mpi3mr_soft_reset_handler(mrioc,
2325 MPI3MR_RESET_FROM_TSU_TIMEOUT, 1);
2329 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2330 != MPI3_IOCSTATUS_SUCCESS) {
2332 "Issue IOUCTL time_stamp: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2333 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2334 mrioc->init_cmds.ioc_loginfo);
2340 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2341 mutex_unlock(&mrioc->init_cmds.mutex);
2348 * mpi3mr_print_pkg_ver - display controller fw package version
2349 * @mrioc: Adapter reference
2351 * Retrieve firmware package version from the component image
2352 * header of the controller flash and display it.
2354 * Return: 0 on success and non-zero on failure.
2356 static int mpi3mr_print_pkg_ver(struct mpi3mr_ioc *mrioc)
2358 struct mpi3_ci_upload_request ci_upload;
2361 dma_addr_t data_dma;
2362 struct mpi3_ci_manifest_mpi *manifest;
2363 u32 data_len = sizeof(struct mpi3_ci_manifest_mpi);
2364 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2366 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2371 memset(&ci_upload, 0, sizeof(ci_upload));
2372 mutex_lock(&mrioc->init_cmds.mutex);
2373 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2374 ioc_err(mrioc, "sending get package version failed due to command in use\n");
2375 mutex_unlock(&mrioc->init_cmds.mutex);
2378 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2379 mrioc->init_cmds.is_waiting = 1;
2380 mrioc->init_cmds.callback = NULL;
2381 ci_upload.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2382 ci_upload.function = MPI3_FUNCTION_CI_UPLOAD;
2383 ci_upload.msg_flags = MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY;
2384 ci_upload.signature1 = cpu_to_le32(MPI3_IMAGE_HEADER_SIGNATURE1_MANIFEST);
2385 ci_upload.image_offset = cpu_to_le32(MPI3_IMAGE_HEADER_SIZE);
2386 ci_upload.segment_size = cpu_to_le32(data_len);
2388 mpi3mr_add_sg_single(&ci_upload.sgl, sgl_flags, data_len,
2390 init_completion(&mrioc->init_cmds.done);
2391 retval = mpi3mr_admin_request_post(mrioc, &ci_upload,
2392 sizeof(ci_upload), 1);
2394 ioc_err(mrioc, "posting get package version failed\n");
2397 wait_for_completion_timeout(&mrioc->init_cmds.done,
2398 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2399 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2400 ioc_err(mrioc, "get package version timed out\n");
2401 mpi3mr_check_rh_fault_ioc(mrioc,
2402 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT);
2406 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2407 == MPI3_IOCSTATUS_SUCCESS) {
2408 manifest = (struct mpi3_ci_manifest_mpi *) data;
2409 if (manifest->manifest_type == MPI3_CI_MANIFEST_TYPE_MPI) {
2411 "firmware package version(%d.%d.%d.%d.%05d-%05d)\n",
2412 manifest->package_version.gen_major,
2413 manifest->package_version.gen_minor,
2414 manifest->package_version.phase_major,
2415 manifest->package_version.phase_minor,
2416 manifest->package_version.customer_id,
2417 manifest->package_version.build_num);
2422 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2423 mutex_unlock(&mrioc->init_cmds.mutex);
2427 dma_free_coherent(&mrioc->pdev->dev, data_len, data,
2433 * mpi3mr_watchdog_work - watchdog thread to monitor faults
2434 * @work: work struct
2436 * Watch dog work periodically executed (1 second interval) to
2437 * monitor firmware fault and to issue periodic timer sync to
2442 static void mpi3mr_watchdog_work(struct work_struct *work)
2444 struct mpi3mr_ioc *mrioc =
2445 container_of(work, struct mpi3mr_ioc, watchdog_work.work);
2446 unsigned long flags;
2447 enum mpi3mr_iocstate ioc_state;
2448 u32 fault, host_diagnostic, ioc_status;
2449 u32 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
2451 if (mrioc->reset_in_progress)
2454 if (!mrioc->unrecoverable && !pci_device_is_present(mrioc->pdev)) {
2455 ioc_err(mrioc, "watchdog could not detect the controller\n");
2456 mrioc->unrecoverable = 1;
2459 if (mrioc->unrecoverable) {
2461 "flush pending commands for unrecoverable controller\n");
2462 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
2466 if (mrioc->ts_update_counter++ >= MPI3MR_TSUPDATE_INTERVAL) {
2467 mrioc->ts_update_counter = 0;
2468 mpi3mr_sync_timestamp(mrioc);
2471 if ((mrioc->prepare_for_reset) &&
2472 ((mrioc->prepare_for_reset_timeout_counter++) >=
2473 MPI3MR_PREPARE_FOR_RESET_TIMEOUT)) {
2474 mpi3mr_soft_reset_handler(mrioc,
2475 MPI3MR_RESET_FROM_CIACTVRST_TIMER, 1);
2479 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2480 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
2481 mpi3mr_soft_reset_handler(mrioc, MPI3MR_RESET_FROM_FIRMWARE, 0);
2485 /*Check for fault state every one second and issue Soft reset*/
2486 ioc_state = mpi3mr_get_iocstate(mrioc);
2487 if (ioc_state != MRIOC_STATE_FAULT)
2490 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
2491 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2492 if (host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS) {
2493 if (!mrioc->diagsave_timeout) {
2494 mpi3mr_print_fault_info(mrioc);
2495 ioc_warn(mrioc, "diag save in progress\n");
2497 if ((mrioc->diagsave_timeout++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT)
2501 mpi3mr_print_fault_info(mrioc);
2502 mrioc->diagsave_timeout = 0;
2505 case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED:
2506 case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED:
2508 "controller requires system power cycle, marking controller as unrecoverable\n");
2509 mrioc->unrecoverable = 1;
2511 case MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS:
2513 case MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET:
2514 reset_reason = MPI3MR_RESET_FROM_CIACTIV_FAULT;
2519 mpi3mr_soft_reset_handler(mrioc, reset_reason, 0);
2523 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2524 if (mrioc->watchdog_work_q)
2525 queue_delayed_work(mrioc->watchdog_work_q,
2526 &mrioc->watchdog_work,
2527 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2528 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2533 * mpi3mr_start_watchdog - Start watchdog
2534 * @mrioc: Adapter instance reference
2536 * Create and start the watchdog thread to monitor controller
2541 void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc)
2543 if (mrioc->watchdog_work_q)
2546 INIT_DELAYED_WORK(&mrioc->watchdog_work, mpi3mr_watchdog_work);
2547 snprintf(mrioc->watchdog_work_q_name,
2548 sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
2550 mrioc->watchdog_work_q =
2551 create_singlethread_workqueue(mrioc->watchdog_work_q_name);
2552 if (!mrioc->watchdog_work_q) {
2553 ioc_err(mrioc, "%s: failed (line=%d)\n", __func__, __LINE__);
2557 if (mrioc->watchdog_work_q)
2558 queue_delayed_work(mrioc->watchdog_work_q,
2559 &mrioc->watchdog_work,
2560 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2564 * mpi3mr_stop_watchdog - Stop watchdog
2565 * @mrioc: Adapter instance reference
2567 * Stop the watchdog thread created to monitor controller
2572 void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc)
2574 unsigned long flags;
2575 struct workqueue_struct *wq;
2577 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2578 wq = mrioc->watchdog_work_q;
2579 mrioc->watchdog_work_q = NULL;
2580 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2582 if (!cancel_delayed_work_sync(&mrioc->watchdog_work))
2583 flush_workqueue(wq);
2584 destroy_workqueue(wq);
2589 * mpi3mr_setup_admin_qpair - Setup admin queue pair
2590 * @mrioc: Adapter instance reference
2592 * Allocate memory for admin queue pair if required and register
2593 * the admin queue with the controller.
2595 * Return: 0 on success, non-zero on failures.
2597 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
2600 u32 num_admin_entries = 0;
2602 mrioc->admin_req_q_sz = MPI3MR_ADMIN_REQ_Q_SIZE;
2603 mrioc->num_admin_req = mrioc->admin_req_q_sz /
2604 MPI3MR_ADMIN_REQ_FRAME_SZ;
2605 mrioc->admin_req_ci = mrioc->admin_req_pi = 0;
2606 mrioc->admin_req_base = NULL;
2608 mrioc->admin_reply_q_sz = MPI3MR_ADMIN_REPLY_Q_SIZE;
2609 mrioc->num_admin_replies = mrioc->admin_reply_q_sz /
2610 MPI3MR_ADMIN_REPLY_FRAME_SZ;
2611 mrioc->admin_reply_ci = 0;
2612 mrioc->admin_reply_ephase = 1;
2613 mrioc->admin_reply_base = NULL;
2615 if (!mrioc->admin_req_base) {
2616 mrioc->admin_req_base = dma_alloc_coherent(&mrioc->pdev->dev,
2617 mrioc->admin_req_q_sz, &mrioc->admin_req_dma, GFP_KERNEL);
2619 if (!mrioc->admin_req_base) {
2624 mrioc->admin_reply_base = dma_alloc_coherent(&mrioc->pdev->dev,
2625 mrioc->admin_reply_q_sz, &mrioc->admin_reply_dma,
2628 if (!mrioc->admin_reply_base) {
2634 num_admin_entries = (mrioc->num_admin_replies << 16) |
2635 (mrioc->num_admin_req);
2636 writel(num_admin_entries, &mrioc->sysif_regs->admin_queue_num_entries);
2637 mpi3mr_writeq(mrioc->admin_req_dma,
2638 &mrioc->sysif_regs->admin_request_queue_address);
2639 mpi3mr_writeq(mrioc->admin_reply_dma,
2640 &mrioc->sysif_regs->admin_reply_queue_address);
2641 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
2642 writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
2647 if (mrioc->admin_reply_base) {
2648 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
2649 mrioc->admin_reply_base, mrioc->admin_reply_dma);
2650 mrioc->admin_reply_base = NULL;
2652 if (mrioc->admin_req_base) {
2653 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
2654 mrioc->admin_req_base, mrioc->admin_req_dma);
2655 mrioc->admin_req_base = NULL;
2661 * mpi3mr_issue_iocfacts - Send IOC Facts
2662 * @mrioc: Adapter instance reference
2663 * @facts_data: Cached IOC facts data
2665 * Issue IOC Facts MPI request through admin queue and wait for
2666 * the completion of it or time out.
2668 * Return: 0 on success, non-zero on failures.
2670 static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc *mrioc,
2671 struct mpi3_ioc_facts_data *facts_data)
2673 struct mpi3_ioc_facts_request iocfacts_req;
2675 dma_addr_t data_dma;
2676 u32 data_len = sizeof(*facts_data);
2678 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2680 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2688 memset(&iocfacts_req, 0, sizeof(iocfacts_req));
2689 mutex_lock(&mrioc->init_cmds.mutex);
2690 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2692 ioc_err(mrioc, "Issue IOCFacts: Init command is in use\n");
2693 mutex_unlock(&mrioc->init_cmds.mutex);
2696 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2697 mrioc->init_cmds.is_waiting = 1;
2698 mrioc->init_cmds.callback = NULL;
2699 iocfacts_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2700 iocfacts_req.function = MPI3_FUNCTION_IOC_FACTS;
2702 mpi3mr_add_sg_single(&iocfacts_req.sgl, sgl_flags, data_len,
2705 init_completion(&mrioc->init_cmds.done);
2706 retval = mpi3mr_admin_request_post(mrioc, &iocfacts_req,
2707 sizeof(iocfacts_req), 1);
2709 ioc_err(mrioc, "Issue IOCFacts: Admin Post failed\n");
2712 wait_for_completion_timeout(&mrioc->init_cmds.done,
2713 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2714 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2715 ioc_err(mrioc, "ioc_facts timed out\n");
2716 mpi3mr_check_rh_fault_ioc(mrioc,
2717 MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT);
2721 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2722 != MPI3_IOCSTATUS_SUCCESS) {
2724 "Issue IOCFacts: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2725 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2726 mrioc->init_cmds.ioc_loginfo);
2730 memcpy(facts_data, (u8 *)data, data_len);
2731 mpi3mr_process_factsdata(mrioc, facts_data);
2733 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2734 mutex_unlock(&mrioc->init_cmds.mutex);
2738 dma_free_coherent(&mrioc->pdev->dev, data_len, data, data_dma);
2744 * mpi3mr_check_reset_dma_mask - Process IOC facts data
2745 * @mrioc: Adapter instance reference
2747 * Check whether the new DMA mask requested through IOCFacts by
2748 * firmware needs to be set, if so set it .
2750 * Return: 0 on success, non-zero on failure.
2752 static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc *mrioc)
2754 struct pci_dev *pdev = mrioc->pdev;
2756 u64 facts_dma_mask = DMA_BIT_MASK(mrioc->facts.dma_mask);
2758 if (!mrioc->facts.dma_mask || (mrioc->dma_mask <= facts_dma_mask))
2761 ioc_info(mrioc, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
2762 mrioc->dma_mask, facts_dma_mask);
2764 r = dma_set_mask_and_coherent(&pdev->dev, facts_dma_mask);
2766 ioc_err(mrioc, "Setting DMA mask to 0x%016llx failed: %d\n",
2770 mrioc->dma_mask = facts_dma_mask;
2775 * mpi3mr_process_factsdata - Process IOC facts data
2776 * @mrioc: Adapter instance reference
2777 * @facts_data: Cached IOC facts data
2779 * Convert IOC facts data into cpu endianness and cache it in
2784 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
2785 struct mpi3_ioc_facts_data *facts_data)
2787 u32 ioc_config, req_sz, facts_flags;
2789 if ((le16_to_cpu(facts_data->ioc_facts_data_length)) !=
2790 (sizeof(*facts_data) / 4)) {
2792 "IOCFactsdata length mismatch driver_sz(%zu) firmware_sz(%d)\n",
2793 sizeof(*facts_data),
2794 le16_to_cpu(facts_data->ioc_facts_data_length) * 4);
2797 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
2798 req_sz = 1 << ((ioc_config & MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ) >>
2799 MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT);
2800 if (le16_to_cpu(facts_data->ioc_request_frame_size) != (req_sz / 4)) {
2802 "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
2803 req_sz / 4, le16_to_cpu(facts_data->ioc_request_frame_size));
2806 memset(&mrioc->facts, 0, sizeof(mrioc->facts));
2808 facts_flags = le32_to_cpu(facts_data->flags);
2809 mrioc->facts.op_req_sz = req_sz;
2810 mrioc->op_reply_desc_sz = 1 << ((ioc_config &
2811 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ) >>
2812 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT);
2814 mrioc->facts.ioc_num = facts_data->ioc_number;
2815 mrioc->facts.who_init = facts_data->who_init;
2816 mrioc->facts.max_msix_vectors = le16_to_cpu(facts_data->max_msix_vectors);
2817 mrioc->facts.personality = (facts_flags &
2818 MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK);
2819 mrioc->facts.dma_mask = (facts_flags &
2820 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
2821 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
2822 mrioc->facts.protocol_flags = facts_data->protocol_flags;
2823 mrioc->facts.mpi_version = le32_to_cpu(facts_data->mpi_version.word);
2824 mrioc->facts.max_reqs = le16_to_cpu(facts_data->max_outstanding_requests);
2825 mrioc->facts.product_id = le16_to_cpu(facts_data->product_id);
2826 mrioc->facts.reply_sz = le16_to_cpu(facts_data->reply_frame_size) * 4;
2827 mrioc->facts.exceptions = le16_to_cpu(facts_data->ioc_exceptions);
2828 mrioc->facts.max_perids = le16_to_cpu(facts_data->max_persistent_id);
2829 mrioc->facts.max_vds = le16_to_cpu(facts_data->max_vds);
2830 mrioc->facts.max_hpds = le16_to_cpu(facts_data->max_host_pds);
2831 mrioc->facts.max_advhpds = le16_to_cpu(facts_data->max_adv_host_pds);
2832 mrioc->facts.max_raid_pds = le16_to_cpu(facts_data->max_raid_pds);
2833 mrioc->facts.max_nvme = le16_to_cpu(facts_data->max_nvme);
2834 mrioc->facts.max_pcie_switches =
2835 le16_to_cpu(facts_data->max_pcie_switches);
2836 mrioc->facts.max_sasexpanders =
2837 le16_to_cpu(facts_data->max_sas_expanders);
2838 mrioc->facts.max_sasinitiators =
2839 le16_to_cpu(facts_data->max_sas_initiators);
2840 mrioc->facts.max_enclosures = le16_to_cpu(facts_data->max_enclosures);
2841 mrioc->facts.min_devhandle = le16_to_cpu(facts_data->min_dev_handle);
2842 mrioc->facts.max_devhandle = le16_to_cpu(facts_data->max_dev_handle);
2843 mrioc->facts.max_op_req_q =
2844 le16_to_cpu(facts_data->max_operational_request_queues);
2845 mrioc->facts.max_op_reply_q =
2846 le16_to_cpu(facts_data->max_operational_reply_queues);
2847 mrioc->facts.ioc_capabilities =
2848 le32_to_cpu(facts_data->ioc_capabilities);
2849 mrioc->facts.fw_ver.build_num =
2850 le16_to_cpu(facts_data->fw_version.build_num);
2851 mrioc->facts.fw_ver.cust_id =
2852 le16_to_cpu(facts_data->fw_version.customer_id);
2853 mrioc->facts.fw_ver.ph_minor = facts_data->fw_version.phase_minor;
2854 mrioc->facts.fw_ver.ph_major = facts_data->fw_version.phase_major;
2855 mrioc->facts.fw_ver.gen_minor = facts_data->fw_version.gen_minor;
2856 mrioc->facts.fw_ver.gen_major = facts_data->fw_version.gen_major;
2857 mrioc->msix_count = min_t(int, mrioc->msix_count,
2858 mrioc->facts.max_msix_vectors);
2859 mrioc->facts.sge_mod_mask = facts_data->sge_modifier_mask;
2860 mrioc->facts.sge_mod_value = facts_data->sge_modifier_value;
2861 mrioc->facts.sge_mod_shift = facts_data->sge_modifier_shift;
2862 mrioc->facts.shutdown_timeout =
2863 le16_to_cpu(facts_data->shutdown_timeout);
2865 mrioc->facts.max_dev_per_tg =
2866 facts_data->max_devices_per_throttle_group;
2867 mrioc->facts.io_throttle_data_length =
2868 le16_to_cpu(facts_data->io_throttle_data_length);
2869 mrioc->facts.max_io_throttle_group =
2870 le16_to_cpu(facts_data->max_io_throttle_group);
2871 mrioc->facts.io_throttle_low = le16_to_cpu(facts_data->io_throttle_low);
2872 mrioc->facts.io_throttle_high =
2873 le16_to_cpu(facts_data->io_throttle_high);
2875 /* Store in 512b block count */
2876 if (mrioc->facts.io_throttle_data_length)
2877 mrioc->io_throttle_data_length =
2878 (mrioc->facts.io_throttle_data_length * 2 * 4);
2880 /* set the length to 1MB + 1K to disable throttle */
2881 mrioc->io_throttle_data_length = MPI3MR_MAX_SECTORS + 2;
2883 mrioc->io_throttle_high = (mrioc->facts.io_throttle_high * 2 * 1024);
2884 mrioc->io_throttle_low = (mrioc->facts.io_throttle_low * 2 * 1024);
2886 ioc_info(mrioc, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
2887 mrioc->facts.ioc_num, mrioc->facts.max_op_req_q,
2888 mrioc->facts.max_op_reply_q, mrioc->facts.max_devhandle);
2890 "maxreqs(%d), mindh(%d) maxvectors(%d) maxperids(%d)\n",
2891 mrioc->facts.max_reqs, mrioc->facts.min_devhandle,
2892 mrioc->facts.max_msix_vectors, mrioc->facts.max_perids);
2893 ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
2894 mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value,
2895 mrioc->facts.sge_mod_shift);
2896 ioc_info(mrioc, "DMA mask %d InitialPE status 0x%x\n",
2897 mrioc->facts.dma_mask, (facts_flags &
2898 MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK));
2900 "max_dev_per_throttle_group(%d), max_throttle_groups(%d)\n",
2901 mrioc->facts.max_dev_per_tg, mrioc->facts.max_io_throttle_group);
2903 "io_throttle_data_len(%dKiB), io_throttle_high(%dMiB), io_throttle_low(%dMiB)\n",
2904 mrioc->facts.io_throttle_data_length * 4,
2905 mrioc->facts.io_throttle_high, mrioc->facts.io_throttle_low);
2909 * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
2910 * @mrioc: Adapter instance reference
2912 * Allocate and initialize the reply free buffers, sense
2913 * buffers, reply free queue and sense buffer queue.
2915 * Return: 0 on success, non-zero on failures.
2917 static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
2922 if (mrioc->init_cmds.reply)
2925 mrioc->init_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2926 if (!mrioc->init_cmds.reply)
2929 mrioc->bsg_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2930 if (!mrioc->bsg_cmds.reply)
2933 mrioc->transport_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2934 if (!mrioc->transport_cmds.reply)
2937 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
2938 mrioc->dev_rmhs_cmds[i].reply = kzalloc(mrioc->reply_sz,
2940 if (!mrioc->dev_rmhs_cmds[i].reply)
2944 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
2945 mrioc->evtack_cmds[i].reply = kzalloc(mrioc->reply_sz,
2947 if (!mrioc->evtack_cmds[i].reply)
2951 mrioc->host_tm_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2952 if (!mrioc->host_tm_cmds.reply)
2955 mrioc->pel_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2956 if (!mrioc->pel_cmds.reply)
2959 mrioc->pel_abort_cmd.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2960 if (!mrioc->pel_abort_cmd.reply)
2963 mrioc->dev_handle_bitmap_sz = mrioc->facts.max_devhandle / 8;
2964 if (mrioc->facts.max_devhandle % 8)
2965 mrioc->dev_handle_bitmap_sz++;
2966 mrioc->removepend_bitmap = kzalloc(mrioc->dev_handle_bitmap_sz,
2968 if (!mrioc->removepend_bitmap)
2971 mrioc->devrem_bitmap_sz = MPI3MR_NUM_DEVRMCMD / 8;
2972 if (MPI3MR_NUM_DEVRMCMD % 8)
2973 mrioc->devrem_bitmap_sz++;
2974 mrioc->devrem_bitmap = kzalloc(mrioc->devrem_bitmap_sz,
2976 if (!mrioc->devrem_bitmap)
2979 mrioc->evtack_cmds_bitmap_sz = MPI3MR_NUM_EVTACKCMD / 8;
2980 if (MPI3MR_NUM_EVTACKCMD % 8)
2981 mrioc->evtack_cmds_bitmap_sz++;
2982 mrioc->evtack_cmds_bitmap = kzalloc(mrioc->evtack_cmds_bitmap_sz,
2984 if (!mrioc->evtack_cmds_bitmap)
2987 mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
2988 mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
2989 mrioc->num_sense_bufs = mrioc->facts.max_reqs / MPI3MR_SENSEBUF_FACTOR;
2990 mrioc->sense_buf_q_sz = mrioc->num_sense_bufs + 1;
2992 /* reply buffer pool, 16 byte align */
2993 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
2994 mrioc->reply_buf_pool = dma_pool_create("reply_buf pool",
2995 &mrioc->pdev->dev, sz, 16, 0);
2996 if (!mrioc->reply_buf_pool) {
2997 ioc_err(mrioc, "reply buf pool: dma_pool_create failed\n");
3001 mrioc->reply_buf = dma_pool_zalloc(mrioc->reply_buf_pool, GFP_KERNEL,
3002 &mrioc->reply_buf_dma);
3003 if (!mrioc->reply_buf)
3006 mrioc->reply_buf_dma_max_address = mrioc->reply_buf_dma + sz;
3008 /* reply free queue, 8 byte align */
3009 sz = mrioc->reply_free_qsz * 8;
3010 mrioc->reply_free_q_pool = dma_pool_create("reply_free_q pool",
3011 &mrioc->pdev->dev, sz, 8, 0);
3012 if (!mrioc->reply_free_q_pool) {
3013 ioc_err(mrioc, "reply_free_q pool: dma_pool_create failed\n");
3016 mrioc->reply_free_q = dma_pool_zalloc(mrioc->reply_free_q_pool,
3017 GFP_KERNEL, &mrioc->reply_free_q_dma);
3018 if (!mrioc->reply_free_q)
3021 /* sense buffer pool, 4 byte align */
3022 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3023 mrioc->sense_buf_pool = dma_pool_create("sense_buf pool",
3024 &mrioc->pdev->dev, sz, 4, 0);
3025 if (!mrioc->sense_buf_pool) {
3026 ioc_err(mrioc, "sense_buf pool: dma_pool_create failed\n");
3029 mrioc->sense_buf = dma_pool_zalloc(mrioc->sense_buf_pool, GFP_KERNEL,
3030 &mrioc->sense_buf_dma);
3031 if (!mrioc->sense_buf)
3034 /* sense buffer queue, 8 byte align */
3035 sz = mrioc->sense_buf_q_sz * 8;
3036 mrioc->sense_buf_q_pool = dma_pool_create("sense_buf_q pool",
3037 &mrioc->pdev->dev, sz, 8, 0);
3038 if (!mrioc->sense_buf_q_pool) {
3039 ioc_err(mrioc, "sense_buf_q pool: dma_pool_create failed\n");
3042 mrioc->sense_buf_q = dma_pool_zalloc(mrioc->sense_buf_q_pool,
3043 GFP_KERNEL, &mrioc->sense_buf_q_dma);
3044 if (!mrioc->sense_buf_q)
3055 * mpimr_initialize_reply_sbuf_queues - initialize reply sense
3057 * @mrioc: Adapter instance reference
3059 * Helper function to initialize reply and sense buffers along
3060 * with some debug prints.
3064 static void mpimr_initialize_reply_sbuf_queues(struct mpi3mr_ioc *mrioc)
3067 dma_addr_t phy_addr;
3069 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3071 "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3072 mrioc->reply_buf, mrioc->num_reply_bufs, mrioc->reply_sz,
3073 (sz / 1024), (unsigned long long)mrioc->reply_buf_dma);
3074 sz = mrioc->reply_free_qsz * 8;
3076 "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3077 mrioc->reply_free_q, mrioc->reply_free_qsz, 8, (sz / 1024),
3078 (unsigned long long)mrioc->reply_free_q_dma);
3079 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3081 "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3082 mrioc->sense_buf, mrioc->num_sense_bufs, MPI3MR_SENSE_BUF_SZ,
3083 (sz / 1024), (unsigned long long)mrioc->sense_buf_dma);
3084 sz = mrioc->sense_buf_q_sz * 8;
3086 "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3087 mrioc->sense_buf_q, mrioc->sense_buf_q_sz, 8, (sz / 1024),
3088 (unsigned long long)mrioc->sense_buf_q_dma);
3090 /* initialize Reply buffer Queue */
3091 for (i = 0, phy_addr = mrioc->reply_buf_dma;
3092 i < mrioc->num_reply_bufs; i++, phy_addr += mrioc->reply_sz)
3093 mrioc->reply_free_q[i] = cpu_to_le64(phy_addr);
3094 mrioc->reply_free_q[i] = cpu_to_le64(0);
3096 /* initialize Sense Buffer Queue */
3097 for (i = 0, phy_addr = mrioc->sense_buf_dma;
3098 i < mrioc->num_sense_bufs; i++, phy_addr += MPI3MR_SENSE_BUF_SZ)
3099 mrioc->sense_buf_q[i] = cpu_to_le64(phy_addr);
3100 mrioc->sense_buf_q[i] = cpu_to_le64(0);
3104 * mpi3mr_issue_iocinit - Send IOC Init
3105 * @mrioc: Adapter instance reference
3107 * Issue IOC Init MPI request through admin queue and wait for
3108 * the completion of it or time out.
3110 * Return: 0 on success, non-zero on failures.
3112 static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
3114 struct mpi3_ioc_init_request iocinit_req;
3115 struct mpi3_driver_info_layout *drv_info;
3116 dma_addr_t data_dma;
3117 u32 data_len = sizeof(*drv_info);
3119 ktime_t current_time;
3121 drv_info = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
3127 mpimr_initialize_reply_sbuf_queues(mrioc);
3129 drv_info->information_length = cpu_to_le32(data_len);
3130 strscpy(drv_info->driver_signature, "Broadcom", sizeof(drv_info->driver_signature));
3131 strscpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));
3132 strscpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));
3133 strscpy(drv_info->driver_name, MPI3MR_DRIVER_NAME, sizeof(drv_info->driver_name));
3134 strscpy(drv_info->driver_version, MPI3MR_DRIVER_VERSION, sizeof(drv_info->driver_version));
3135 strscpy(drv_info->driver_release_date, MPI3MR_DRIVER_RELDATE,
3136 sizeof(drv_info->driver_release_date));
3137 drv_info->driver_capabilities = 0;
3138 memcpy((u8 *)&mrioc->driver_info, (u8 *)drv_info,
3139 sizeof(mrioc->driver_info));
3141 memset(&iocinit_req, 0, sizeof(iocinit_req));
3142 mutex_lock(&mrioc->init_cmds.mutex);
3143 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3145 ioc_err(mrioc, "Issue IOCInit: Init command is in use\n");
3146 mutex_unlock(&mrioc->init_cmds.mutex);
3149 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3150 mrioc->init_cmds.is_waiting = 1;
3151 mrioc->init_cmds.callback = NULL;
3152 iocinit_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3153 iocinit_req.function = MPI3_FUNCTION_IOC_INIT;
3154 iocinit_req.mpi_version.mpi3_version.dev = MPI3_VERSION_DEV;
3155 iocinit_req.mpi_version.mpi3_version.unit = MPI3_VERSION_UNIT;
3156 iocinit_req.mpi_version.mpi3_version.major = MPI3_VERSION_MAJOR;
3157 iocinit_req.mpi_version.mpi3_version.minor = MPI3_VERSION_MINOR;
3158 iocinit_req.who_init = MPI3_WHOINIT_HOST_DRIVER;
3159 iocinit_req.reply_free_queue_depth = cpu_to_le16(mrioc->reply_free_qsz);
3160 iocinit_req.reply_free_queue_address =
3161 cpu_to_le64(mrioc->reply_free_q_dma);
3162 iocinit_req.sense_buffer_length = cpu_to_le16(MPI3MR_SENSE_BUF_SZ);
3163 iocinit_req.sense_buffer_free_queue_depth =
3164 cpu_to_le16(mrioc->sense_buf_q_sz);
3165 iocinit_req.sense_buffer_free_queue_address =
3166 cpu_to_le64(mrioc->sense_buf_q_dma);
3167 iocinit_req.driver_information_address = cpu_to_le64(data_dma);
3169 current_time = ktime_get_real();
3170 iocinit_req.time_stamp = cpu_to_le64(ktime_to_ms(current_time));
3172 init_completion(&mrioc->init_cmds.done);
3173 retval = mpi3mr_admin_request_post(mrioc, &iocinit_req,
3174 sizeof(iocinit_req), 1);
3176 ioc_err(mrioc, "Issue IOCInit: Admin Post failed\n");
3179 wait_for_completion_timeout(&mrioc->init_cmds.done,
3180 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3181 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3182 mpi3mr_check_rh_fault_ioc(mrioc,
3183 MPI3MR_RESET_FROM_IOCINIT_TIMEOUT);
3184 ioc_err(mrioc, "ioc_init timed out\n");
3188 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3189 != MPI3_IOCSTATUS_SUCCESS) {
3191 "Issue IOCInit: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3192 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3193 mrioc->init_cmds.ioc_loginfo);
3198 mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
3199 writel(mrioc->reply_free_queue_host_index,
3200 &mrioc->sysif_regs->reply_free_host_index);
3202 mrioc->sbq_host_index = mrioc->num_sense_bufs;
3203 writel(mrioc->sbq_host_index,
3204 &mrioc->sysif_regs->sense_buffer_free_host_index);
3206 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3207 mutex_unlock(&mrioc->init_cmds.mutex);
3211 dma_free_coherent(&mrioc->pdev->dev, data_len, drv_info,
3218 * mpi3mr_unmask_events - Unmask events in event mask bitmap
3219 * @mrioc: Adapter instance reference
3220 * @event: MPI event ID
3222 * Un mask the specific event by resetting the event_mask
3225 * Return: 0 on success, non-zero on failures.
3227 static void mpi3mr_unmask_events(struct mpi3mr_ioc *mrioc, u16 event)
3235 desired_event = (1 << (event % 32));
3238 mrioc->event_masks[word] &= ~desired_event;
3242 * mpi3mr_issue_event_notification - Send event notification
3243 * @mrioc: Adapter instance reference
3245 * Issue event notification MPI request through admin queue and
3246 * wait for the completion of it or time out.
3248 * Return: 0 on success, non-zero on failures.
3250 static int mpi3mr_issue_event_notification(struct mpi3mr_ioc *mrioc)
3252 struct mpi3_event_notification_request evtnotify_req;
3256 memset(&evtnotify_req, 0, sizeof(evtnotify_req));
3257 mutex_lock(&mrioc->init_cmds.mutex);
3258 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3260 ioc_err(mrioc, "Issue EvtNotify: Init command is in use\n");
3261 mutex_unlock(&mrioc->init_cmds.mutex);
3264 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3265 mrioc->init_cmds.is_waiting = 1;
3266 mrioc->init_cmds.callback = NULL;
3267 evtnotify_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3268 evtnotify_req.function = MPI3_FUNCTION_EVENT_NOTIFICATION;
3269 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3270 evtnotify_req.event_masks[i] =
3271 cpu_to_le32(mrioc->event_masks[i]);
3272 init_completion(&mrioc->init_cmds.done);
3273 retval = mpi3mr_admin_request_post(mrioc, &evtnotify_req,
3274 sizeof(evtnotify_req), 1);
3276 ioc_err(mrioc, "Issue EvtNotify: Admin Post failed\n");
3279 wait_for_completion_timeout(&mrioc->init_cmds.done,
3280 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3281 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3282 ioc_err(mrioc, "event notification timed out\n");
3283 mpi3mr_check_rh_fault_ioc(mrioc,
3284 MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT);
3288 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3289 != MPI3_IOCSTATUS_SUCCESS) {
3291 "Issue EvtNotify: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3292 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3293 mrioc->init_cmds.ioc_loginfo);
3299 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3300 mutex_unlock(&mrioc->init_cmds.mutex);
3306 * mpi3mr_process_event_ack - Process event acknowledgment
3307 * @mrioc: Adapter instance reference
3308 * @event: MPI3 event ID
3309 * @event_ctx: event context
3311 * Send event acknowledgment through admin queue and wait for
3314 * Return: 0 on success, non-zero on failures.
3316 int mpi3mr_process_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
3319 struct mpi3_event_ack_request evtack_req;
3322 memset(&evtack_req, 0, sizeof(evtack_req));
3323 mutex_lock(&mrioc->init_cmds.mutex);
3324 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3326 ioc_err(mrioc, "Send EvtAck: Init command is in use\n");
3327 mutex_unlock(&mrioc->init_cmds.mutex);
3330 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3331 mrioc->init_cmds.is_waiting = 1;
3332 mrioc->init_cmds.callback = NULL;
3333 evtack_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3334 evtack_req.function = MPI3_FUNCTION_EVENT_ACK;
3335 evtack_req.event = event;
3336 evtack_req.event_context = cpu_to_le32(event_ctx);
3338 init_completion(&mrioc->init_cmds.done);
3339 retval = mpi3mr_admin_request_post(mrioc, &evtack_req,
3340 sizeof(evtack_req), 1);
3342 ioc_err(mrioc, "Send EvtAck: Admin Post failed\n");
3345 wait_for_completion_timeout(&mrioc->init_cmds.done,
3346 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3347 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3348 ioc_err(mrioc, "Issue EvtNotify: command timed out\n");
3349 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
3350 mpi3mr_soft_reset_handler(mrioc,
3351 MPI3MR_RESET_FROM_EVTACK_TIMEOUT, 1);
3355 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3356 != MPI3_IOCSTATUS_SUCCESS) {
3358 "Send EvtAck: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3359 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3360 mrioc->init_cmds.ioc_loginfo);
3366 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3367 mutex_unlock(&mrioc->init_cmds.mutex);
3373 * mpi3mr_alloc_chain_bufs - Allocate chain buffers
3374 * @mrioc: Adapter instance reference
3376 * Allocate chain buffers and set a bitmap to indicate free
3377 * chain buffers. Chain buffers are used to pass the SGE
3378 * information along with MPI3 SCSI IO requests for host I/O.
3380 * Return: 0 on success, non-zero on failure
3382 static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
3388 if (mrioc->chain_sgl_list)
3391 num_chains = mrioc->max_host_ios / MPI3MR_CHAINBUF_FACTOR;
3393 if (prot_mask & (SHOST_DIX_TYPE0_PROTECTION
3394 | SHOST_DIX_TYPE1_PROTECTION
3395 | SHOST_DIX_TYPE2_PROTECTION
3396 | SHOST_DIX_TYPE3_PROTECTION))
3397 num_chains += (num_chains / MPI3MR_CHAINBUFDIX_FACTOR);
3399 mrioc->chain_buf_count = num_chains;
3400 sz = sizeof(struct chain_element) * num_chains;
3401 mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
3402 if (!mrioc->chain_sgl_list)
3405 sz = MPI3MR_PAGE_SIZE_4K;
3406 mrioc->chain_buf_pool = dma_pool_create("chain_buf pool",
3407 &mrioc->pdev->dev, sz, 16, 0);
3408 if (!mrioc->chain_buf_pool) {
3409 ioc_err(mrioc, "chain buf pool: dma_pool_create failed\n");
3413 for (i = 0; i < num_chains; i++) {
3414 mrioc->chain_sgl_list[i].addr =
3415 dma_pool_zalloc(mrioc->chain_buf_pool, GFP_KERNEL,
3416 &mrioc->chain_sgl_list[i].dma_addr);
3418 if (!mrioc->chain_sgl_list[i].addr)
3421 mrioc->chain_bitmap_sz = num_chains / 8;
3423 mrioc->chain_bitmap_sz++;
3424 mrioc->chain_bitmap = kzalloc(mrioc->chain_bitmap_sz, GFP_KERNEL);
3425 if (!mrioc->chain_bitmap)
3434 * mpi3mr_port_enable_complete - Mark port enable complete
3435 * @mrioc: Adapter instance reference
3436 * @drv_cmd: Internal command tracker
3438 * Call back for asynchronous port enable request sets the
3439 * driver command to indicate port enable request is complete.
3443 static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
3444 struct mpi3mr_drv_cmd *drv_cmd)
3446 drv_cmd->callback = NULL;
3447 mrioc->scan_started = 0;
3448 if (drv_cmd->state & MPI3MR_CMD_RESET)
3449 mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
3451 mrioc->scan_failed = drv_cmd->ioc_status;
3452 drv_cmd->state = MPI3MR_CMD_NOTUSED;
3456 * mpi3mr_issue_port_enable - Issue Port Enable
3457 * @mrioc: Adapter instance reference
3458 * @async: Flag to wait for completion or not
3460 * Issue Port Enable MPI request through admin queue and if the
3461 * async flag is not set wait for the completion of the port
3462 * enable or time out.
3464 * Return: 0 on success, non-zero on failures.
3466 int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
3468 struct mpi3_port_enable_request pe_req;
3470 u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
3472 memset(&pe_req, 0, sizeof(pe_req));
3473 mutex_lock(&mrioc->init_cmds.mutex);
3474 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3476 ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
3477 mutex_unlock(&mrioc->init_cmds.mutex);
3480 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3482 mrioc->init_cmds.is_waiting = 0;
3483 mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
3485 mrioc->init_cmds.is_waiting = 1;
3486 mrioc->init_cmds.callback = NULL;
3487 init_completion(&mrioc->init_cmds.done);
3489 pe_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3490 pe_req.function = MPI3_FUNCTION_PORT_ENABLE;
3492 retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
3494 ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
3498 mutex_unlock(&mrioc->init_cmds.mutex);
3502 wait_for_completion_timeout(&mrioc->init_cmds.done, (pe_timeout * HZ));
3503 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3504 ioc_err(mrioc, "port enable timed out\n");
3506 mpi3mr_check_rh_fault_ioc(mrioc, MPI3MR_RESET_FROM_PE_TIMEOUT);
3509 mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
3512 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3513 mutex_unlock(&mrioc->init_cmds.mutex);
3518 /* Protocol type to name mapper structure */
3519 static const struct {
3522 } mpi3mr_protocols[] = {
3523 { MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR, "Initiator" },
3524 { MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET, "Target" },
3525 { MPI3_IOCFACTS_PROTOCOL_NVME, "NVMe attachment" },
3528 /* Capability to name mapper structure*/
3529 static const struct {
3532 } mpi3mr_capabilities[] = {
3533 { MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE, "RAID" },
3534 { MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED, "MultiPath" },
3538 * mpi3mr_print_ioc_info - Display controller information
3539 * @mrioc: Adapter instance reference
3541 * Display controller personalit, capability, supported
3547 mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
3549 int i = 0, bytes_written = 0;
3550 char personality[16];
3551 char protocol[50] = {0};
3552 char capabilities[100] = {0};
3553 struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
3555 switch (mrioc->facts.personality) {
3556 case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
3557 strncpy(personality, "Enhanced HBA", sizeof(personality));
3559 case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
3560 strncpy(personality, "RAID", sizeof(personality));
3563 strncpy(personality, "Unknown", sizeof(personality));
3567 ioc_info(mrioc, "Running in %s Personality", personality);
3569 ioc_info(mrioc, "FW version(%d.%d.%d.%d.%d.%d)\n",
3570 fwver->gen_major, fwver->gen_minor, fwver->ph_major,
3571 fwver->ph_minor, fwver->cust_id, fwver->build_num);
3573 for (i = 0; i < ARRAY_SIZE(mpi3mr_protocols); i++) {
3574 if (mrioc->facts.protocol_flags &
3575 mpi3mr_protocols[i].protocol) {
3576 bytes_written += scnprintf(protocol + bytes_written,
3577 sizeof(protocol) - bytes_written, "%s%s",
3578 bytes_written ? "," : "",
3579 mpi3mr_protocols[i].name);
3584 for (i = 0; i < ARRAY_SIZE(mpi3mr_capabilities); i++) {
3585 if (mrioc->facts.protocol_flags &
3586 mpi3mr_capabilities[i].capability) {
3587 bytes_written += scnprintf(capabilities + bytes_written,
3588 sizeof(capabilities) - bytes_written, "%s%s",
3589 bytes_written ? "," : "",
3590 mpi3mr_capabilities[i].name);
3594 ioc_info(mrioc, "Protocol=(%s), Capabilities=(%s)\n",
3595 protocol, capabilities);
3599 * mpi3mr_cleanup_resources - Free PCI resources
3600 * @mrioc: Adapter instance reference
3602 * Unmap PCI device memory and disable PCI device.
3604 * Return: 0 on success and non-zero on failure.
3606 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
3608 struct pci_dev *pdev = mrioc->pdev;
3610 mpi3mr_cleanup_isr(mrioc);
3612 if (mrioc->sysif_regs) {
3613 iounmap((void __iomem *)mrioc->sysif_regs);
3614 mrioc->sysif_regs = NULL;
3617 if (pci_is_enabled(pdev)) {
3619 pci_release_selected_regions(pdev, mrioc->bars);
3620 pci_disable_device(pdev);
3625 * mpi3mr_setup_resources - Enable PCI resources
3626 * @mrioc: Adapter instance reference
3628 * Enable PCI device memory, MSI-x registers and set DMA mask.
3630 * Return: 0 on success and non-zero on failure.
3632 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
3634 struct pci_dev *pdev = mrioc->pdev;
3636 int i, retval = 0, capb = 0;
3637 u16 message_control;
3638 u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
3639 (((dma_get_required_mask(&pdev->dev) > DMA_BIT_MASK(32)) &&
3640 (sizeof(dma_addr_t) > 4)) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
3642 if (pci_enable_device_mem(pdev)) {
3643 ioc_err(mrioc, "pci_enable_device_mem: failed\n");
3648 capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3650 ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
3654 mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
3656 if (pci_request_selected_regions(pdev, mrioc->bars,
3657 mrioc->driver_name)) {
3658 ioc_err(mrioc, "pci_request_selected_regions: failed\n");
3663 for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
3664 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
3665 mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
3666 memap_sz = pci_resource_len(pdev, i);
3668 ioremap(mrioc->sysif_regs_phys, memap_sz);
3673 pci_set_master(pdev);
3675 retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
3677 if (dma_mask != DMA_BIT_MASK(32)) {
3678 ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
3679 dma_mask = DMA_BIT_MASK(32);
3680 retval = dma_set_mask_and_coherent(&pdev->dev,
3684 mrioc->dma_mask = 0;
3685 ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
3689 mrioc->dma_mask = dma_mask;
3691 if (!mrioc->sysif_regs) {
3693 "Unable to map adapter memory or resource not found\n");
3698 pci_read_config_word(pdev, capb + 2, &message_control);
3699 mrioc->msix_count = (message_control & 0x3FF) + 1;
3701 pci_save_state(pdev);
3703 pci_set_drvdata(pdev, mrioc->shost);
3705 mpi3mr_ioc_disable_intr(mrioc);
3707 ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
3708 (unsigned long long)mrioc->sysif_regs_phys,
3709 mrioc->sysif_regs, memap_sz);
3710 ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
3713 if (!reset_devices && poll_queues > 0)
3714 mrioc->requested_poll_qcount = min_t(int, poll_queues,
3715 mrioc->msix_count - 2);
3719 mpi3mr_cleanup_resources(mrioc);
3724 * mpi3mr_enable_events - Enable required events
3725 * @mrioc: Adapter instance reference
3727 * This routine unmasks the events required by the driver by
3728 * sennding appropriate event mask bitmapt through an event
3729 * notification request.
3731 * Return: 0 on success and non-zero on failure.
3733 static int mpi3mr_enable_events(struct mpi3mr_ioc *mrioc)
3738 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3739 mrioc->event_masks[i] = -1;
3741 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_ADDED);
3742 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_INFO_CHANGED);
3743 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_STATUS_CHANGE);
3744 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE);
3745 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_ADDED);
3746 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
3747 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
3748 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
3749 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_BROADCAST_PRIMITIVE);
3750 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST);
3751 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_ENUMERATION);
3752 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PREPARE_FOR_RESET);
3753 mpi3mr_unmask_events(mrioc, MPI3_EVENT_CABLE_MGMT);
3754 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENERGY_PACK_CHANGE);
3756 retval = mpi3mr_issue_event_notification(mrioc);
3758 ioc_err(mrioc, "failed to issue event notification %d\n",
3764 * mpi3mr_init_ioc - Initialize the controller
3765 * @mrioc: Adapter instance reference
3767 * This the controller initialization routine, executed either
3768 * after soft reset or from pci probe callback.
3769 * Setup the required resources, memory map the controller
3770 * registers, create admin and operational reply queue pairs,
3771 * allocate required memory for reply pool, sense buffer pool,
3772 * issue IOC init request to the firmware, unmask the events and
3773 * issue port enable to discover SAS/SATA/NVMe devies and RAID
3776 * Return: 0 on success and non-zero on failure.
3778 int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
3782 struct mpi3_ioc_facts_data facts_data;
3786 retval = mpi3mr_bring_ioc_ready(mrioc);
3788 ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
3790 goto out_failed_noretry;
3793 retval = mpi3mr_setup_isr(mrioc, 1);
3795 ioc_err(mrioc, "Failed to setup ISR error %d\n",
3797 goto out_failed_noretry;
3800 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
3802 ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
3807 mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD;
3809 mrioc->num_io_throttle_group = mrioc->facts.max_io_throttle_group;
3810 atomic_set(&mrioc->pend_large_data_sz, 0);
3813 mrioc->max_host_ios = min_t(int, mrioc->max_host_ios,
3814 MPI3MR_HOST_IOS_KDUMP);
3816 if (!(mrioc->facts.ioc_capabilities &
3817 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED)) {
3818 mrioc->sas_transport_enabled = 1;
3819 mrioc->scsi_device_channel = 1;
3820 mrioc->shost->max_channel = 1;
3821 mrioc->shost->transportt = mpi3mr_transport_template;
3824 mrioc->reply_sz = mrioc->facts.reply_sz;
3826 retval = mpi3mr_check_reset_dma_mask(mrioc);
3828 ioc_err(mrioc, "Resetting dma mask failed %d\n",
3830 goto out_failed_noretry;
3833 mpi3mr_print_ioc_info(mrioc);
3835 dprint_init(mrioc, "allocating config page buffers\n");
3836 mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev,
3837 MPI3MR_DEFAULT_CFG_PAGE_SZ, &mrioc->cfg_page_dma, GFP_KERNEL);
3838 if (!mrioc->cfg_page)
3839 goto out_failed_noretry;
3841 mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ;
3843 retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
3846 "%s :Failed to allocated reply sense buffers %d\n",
3848 goto out_failed_noretry;
3851 retval = mpi3mr_alloc_chain_bufs(mrioc);
3853 ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
3855 goto out_failed_noretry;
3858 retval = mpi3mr_issue_iocinit(mrioc);
3860 ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
3865 retval = mpi3mr_print_pkg_ver(mrioc);
3867 ioc_err(mrioc, "failed to get package version\n");
3871 retval = mpi3mr_setup_isr(mrioc, 0);
3873 ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
3875 goto out_failed_noretry;
3878 retval = mpi3mr_create_op_queues(mrioc);
3880 ioc_err(mrioc, "Failed to create OpQueues error %d\n",
3885 if (!mrioc->pel_seqnum_virt) {
3886 dprint_init(mrioc, "allocating memory for pel_seqnum_virt\n");
3887 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
3888 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
3889 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
3891 if (!mrioc->pel_seqnum_virt) {
3893 goto out_failed_noretry;
3897 if (!mrioc->throttle_groups && mrioc->num_io_throttle_group) {
3898 dprint_init(mrioc, "allocating memory for throttle groups\n");
3899 sz = sizeof(struct mpi3mr_throttle_group_info);
3900 mrioc->throttle_groups = (struct mpi3mr_throttle_group_info *)
3901 kcalloc(mrioc->num_io_throttle_group, sz, GFP_KERNEL);
3902 if (!mrioc->throttle_groups)
3903 goto out_failed_noretry;
3906 retval = mpi3mr_enable_events(mrioc);
3908 ioc_err(mrioc, "failed to enable events %d\n",
3913 ioc_info(mrioc, "controller initialization completed successfully\n");
3918 ioc_warn(mrioc, "retrying controller initialization, retry_count:%d\n",
3920 mpi3mr_memset_buffers(mrioc);
3924 ioc_err(mrioc, "controller initialization failed\n");
3925 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
3926 MPI3MR_RESET_FROM_CTLR_CLEANUP);
3927 mrioc->unrecoverable = 1;
3932 * mpi3mr_reinit_ioc - Re-Initialize the controller
3933 * @mrioc: Adapter instance reference
3934 * @is_resume: Called from resume or reset path
3936 * This the controller re-initialization routine, executed from
3937 * the soft reset handler or resume callback. Creates
3938 * operational reply queue pairs, allocate required memory for
3939 * reply pool, sense buffer pool, issue IOC init request to the
3940 * firmware, unmask the events and issue port enable to discover
3941 * SAS/SATA/NVMe devices and RAID volumes.
3943 * Return: 0 on success and non-zero on failure.
3945 int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
3949 struct mpi3_ioc_facts_data facts_data;
3950 u32 pe_timeout, ioc_status;
3954 (MPI3MR_PORTENABLE_TIMEOUT / MPI3MR_PORTENABLE_POLL_INTERVAL);
3956 dprint_reset(mrioc, "bringing up the controller to ready state\n");
3957 retval = mpi3mr_bring_ioc_ready(mrioc);
3959 ioc_err(mrioc, "failed to bring to ready state\n");
3960 goto out_failed_noretry;
3964 dprint_reset(mrioc, "setting up single ISR\n");
3965 retval = mpi3mr_setup_isr(mrioc, 1);
3967 ioc_err(mrioc, "failed to setup ISR\n");
3968 goto out_failed_noretry;
3971 mpi3mr_ioc_enable_intr(mrioc);
3973 dprint_reset(mrioc, "getting ioc_facts\n");
3974 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
3976 ioc_err(mrioc, "failed to get ioc_facts\n");
3980 dprint_reset(mrioc, "validating ioc_facts\n");
3981 retval = mpi3mr_revalidate_factsdata(mrioc);
3983 ioc_err(mrioc, "failed to revalidate ioc_facts data\n");
3984 goto out_failed_noretry;
3987 mpi3mr_print_ioc_info(mrioc);
3989 dprint_reset(mrioc, "sending ioc_init\n");
3990 retval = mpi3mr_issue_iocinit(mrioc);
3992 ioc_err(mrioc, "failed to send ioc_init\n");
3996 dprint_reset(mrioc, "getting package version\n");
3997 retval = mpi3mr_print_pkg_ver(mrioc);
3999 ioc_err(mrioc, "failed to get package version\n");
4004 dprint_reset(mrioc, "setting up multiple ISR\n");
4005 retval = mpi3mr_setup_isr(mrioc, 0);
4007 ioc_err(mrioc, "failed to re-setup ISR\n");
4008 goto out_failed_noretry;
4012 dprint_reset(mrioc, "creating operational queue pairs\n");
4013 retval = mpi3mr_create_op_queues(mrioc);
4015 ioc_err(mrioc, "failed to create operational queue pairs\n");
4019 if (!mrioc->pel_seqnum_virt) {
4020 dprint_reset(mrioc, "allocating memory for pel_seqnum_virt\n");
4021 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
4022 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
4023 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
4025 if (!mrioc->pel_seqnum_virt) {
4027 goto out_failed_noretry;
4031 if (mrioc->shost->nr_hw_queues > mrioc->num_op_reply_q) {
4033 "cannot create minimum number of operational queues expected:%d created:%d\n",
4034 mrioc->shost->nr_hw_queues, mrioc->num_op_reply_q);
4035 goto out_failed_noretry;
4038 dprint_reset(mrioc, "enabling events\n");
4039 retval = mpi3mr_enable_events(mrioc);
4041 ioc_err(mrioc, "failed to enable events\n");
4046 mrioc->device_refresh_on = 1;
4047 mpi3mr_add_event_wait_for_device_refresh(mrioc);
4050 ioc_info(mrioc, "sending port enable\n");
4051 retval = mpi3mr_issue_port_enable(mrioc, 1);
4053 ioc_err(mrioc, "failed to issue port enable\n");
4057 ssleep(MPI3MR_PORTENABLE_POLL_INTERVAL);
4058 if (mrioc->init_cmds.state == MPI3MR_CMD_NOTUSED)
4060 if (!pci_device_is_present(mrioc->pdev))
4061 mrioc->unrecoverable = 1;
4062 if (mrioc->unrecoverable) {
4064 goto out_failed_noretry;
4066 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4067 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
4068 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
4069 mpi3mr_print_fault_info(mrioc);
4070 mrioc->init_cmds.is_waiting = 0;
4071 mrioc->init_cmds.callback = NULL;
4072 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4075 } while (--pe_timeout);
4078 ioc_err(mrioc, "port enable timed out\n");
4079 mpi3mr_check_rh_fault_ioc(mrioc,
4080 MPI3MR_RESET_FROM_PE_TIMEOUT);
4081 mrioc->init_cmds.is_waiting = 0;
4082 mrioc->init_cmds.callback = NULL;
4083 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4085 } else if (mrioc->scan_failed) {
4087 "port enable failed with status=0x%04x\n",
4088 mrioc->scan_failed);
4090 ioc_info(mrioc, "port enable completed successfully\n");
4092 ioc_info(mrioc, "controller %s completed successfully\n",
4093 (is_resume)?"resume":"re-initialization");
4098 ioc_warn(mrioc, "retrying controller %s, retry_count:%d\n",
4099 (is_resume)?"resume":"re-initialization", retry);
4100 mpi3mr_memset_buffers(mrioc);
4104 ioc_err(mrioc, "controller %s is failed\n",
4105 (is_resume)?"resume":"re-initialization");
4106 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
4107 MPI3MR_RESET_FROM_CTLR_CLEANUP);
4108 mrioc->unrecoverable = 1;
4113 * mpi3mr_memset_op_reply_q_buffers - memset the operational reply queue's
4115 * @mrioc: Adapter instance reference
4116 * @qidx: Operational reply queue index
4120 static void mpi3mr_memset_op_reply_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4122 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
4123 struct segments *segments;
4126 if (!op_reply_q->q_segments)
4129 size = op_reply_q->segment_qd * mrioc->op_reply_desc_sz;
4130 segments = op_reply_q->q_segments;
4131 for (i = 0; i < op_reply_q->num_segments; i++)
4132 memset(segments[i].segment, 0, size);
4136 * mpi3mr_memset_op_req_q_buffers - memset the operational request queue's
4138 * @mrioc: Adapter instance reference
4139 * @qidx: Operational request queue index
4143 static void mpi3mr_memset_op_req_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4145 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
4146 struct segments *segments;
4149 if (!op_req_q->q_segments)
4152 size = op_req_q->segment_qd * mrioc->facts.op_req_sz;
4153 segments = op_req_q->q_segments;
4154 for (i = 0; i < op_req_q->num_segments; i++)
4155 memset(segments[i].segment, 0, size);
4159 * mpi3mr_memset_buffers - memset memory for a controller
4160 * @mrioc: Adapter instance reference
4162 * clear all the memory allocated for a controller, typically
4163 * called post reset to reuse the memory allocated during the
4168 void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
4171 struct mpi3mr_throttle_group_info *tg;
4173 mrioc->change_count = 0;
4174 mrioc->active_poll_qcount = 0;
4175 mrioc->default_qcount = 0;
4176 if (mrioc->admin_req_base)
4177 memset(mrioc->admin_req_base, 0, mrioc->admin_req_q_sz);
4178 if (mrioc->admin_reply_base)
4179 memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
4181 if (mrioc->init_cmds.reply) {
4182 memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
4183 memset(mrioc->bsg_cmds.reply, 0,
4184 sizeof(*mrioc->bsg_cmds.reply));
4185 memset(mrioc->host_tm_cmds.reply, 0,
4186 sizeof(*mrioc->host_tm_cmds.reply));
4187 memset(mrioc->pel_cmds.reply, 0,
4188 sizeof(*mrioc->pel_cmds.reply));
4189 memset(mrioc->pel_abort_cmd.reply, 0,
4190 sizeof(*mrioc->pel_abort_cmd.reply));
4191 memset(mrioc->transport_cmds.reply, 0,
4192 sizeof(*mrioc->transport_cmds.reply));
4193 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
4194 memset(mrioc->dev_rmhs_cmds[i].reply, 0,
4195 sizeof(*mrioc->dev_rmhs_cmds[i].reply));
4196 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++)
4197 memset(mrioc->evtack_cmds[i].reply, 0,
4198 sizeof(*mrioc->evtack_cmds[i].reply));
4199 memset(mrioc->removepend_bitmap, 0, mrioc->dev_handle_bitmap_sz);
4200 memset(mrioc->devrem_bitmap, 0, mrioc->devrem_bitmap_sz);
4201 memset(mrioc->evtack_cmds_bitmap, 0,
4202 mrioc->evtack_cmds_bitmap_sz);
4205 for (i = 0; i < mrioc->num_queues; i++) {
4206 mrioc->op_reply_qinfo[i].qid = 0;
4207 mrioc->op_reply_qinfo[i].ci = 0;
4208 mrioc->op_reply_qinfo[i].num_replies = 0;
4209 mrioc->op_reply_qinfo[i].ephase = 0;
4210 atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
4211 atomic_set(&mrioc->op_reply_qinfo[i].in_use, 0);
4212 mpi3mr_memset_op_reply_q_buffers(mrioc, i);
4214 mrioc->req_qinfo[i].ci = 0;
4215 mrioc->req_qinfo[i].pi = 0;
4216 mrioc->req_qinfo[i].num_requests = 0;
4217 mrioc->req_qinfo[i].qid = 0;
4218 mrioc->req_qinfo[i].reply_qid = 0;
4219 spin_lock_init(&mrioc->req_qinfo[i].q_lock);
4220 mpi3mr_memset_op_req_q_buffers(mrioc, i);
4223 atomic_set(&mrioc->pend_large_data_sz, 0);
4224 if (mrioc->throttle_groups) {
4225 tg = mrioc->throttle_groups;
4226 for (i = 0; i < mrioc->num_io_throttle_group; i++, tg++) {
4229 tg->modified_qd = 0;
4231 tg->need_qd_reduction = 0;
4234 tg->qd_reduction = 0;
4235 atomic_set(&tg->pend_large_data_sz, 0);
4241 * mpi3mr_free_mem - Free memory allocated for a controller
4242 * @mrioc: Adapter instance reference
4244 * Free all the memory allocated for a controller.
4248 void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
4251 struct mpi3mr_intr_info *intr_info;
4253 mpi3mr_free_enclosure_list(mrioc);
4255 if (mrioc->sense_buf_pool) {
4256 if (mrioc->sense_buf)
4257 dma_pool_free(mrioc->sense_buf_pool, mrioc->sense_buf,
4258 mrioc->sense_buf_dma);
4259 dma_pool_destroy(mrioc->sense_buf_pool);
4260 mrioc->sense_buf = NULL;
4261 mrioc->sense_buf_pool = NULL;
4263 if (mrioc->sense_buf_q_pool) {
4264 if (mrioc->sense_buf_q)
4265 dma_pool_free(mrioc->sense_buf_q_pool,
4266 mrioc->sense_buf_q, mrioc->sense_buf_q_dma);
4267 dma_pool_destroy(mrioc->sense_buf_q_pool);
4268 mrioc->sense_buf_q = NULL;
4269 mrioc->sense_buf_q_pool = NULL;
4272 if (mrioc->reply_buf_pool) {
4273 if (mrioc->reply_buf)
4274 dma_pool_free(mrioc->reply_buf_pool, mrioc->reply_buf,
4275 mrioc->reply_buf_dma);
4276 dma_pool_destroy(mrioc->reply_buf_pool);
4277 mrioc->reply_buf = NULL;
4278 mrioc->reply_buf_pool = NULL;
4280 if (mrioc->reply_free_q_pool) {
4281 if (mrioc->reply_free_q)
4282 dma_pool_free(mrioc->reply_free_q_pool,
4283 mrioc->reply_free_q, mrioc->reply_free_q_dma);
4284 dma_pool_destroy(mrioc->reply_free_q_pool);
4285 mrioc->reply_free_q = NULL;
4286 mrioc->reply_free_q_pool = NULL;
4289 for (i = 0; i < mrioc->num_op_req_q; i++)
4290 mpi3mr_free_op_req_q_segments(mrioc, i);
4292 for (i = 0; i < mrioc->num_op_reply_q; i++)
4293 mpi3mr_free_op_reply_q_segments(mrioc, i);
4295 for (i = 0; i < mrioc->intr_info_count; i++) {
4296 intr_info = mrioc->intr_info + i;
4297 intr_info->op_reply_q = NULL;
4300 kfree(mrioc->req_qinfo);
4301 mrioc->req_qinfo = NULL;
4302 mrioc->num_op_req_q = 0;
4304 kfree(mrioc->op_reply_qinfo);
4305 mrioc->op_reply_qinfo = NULL;
4306 mrioc->num_op_reply_q = 0;
4308 kfree(mrioc->init_cmds.reply);
4309 mrioc->init_cmds.reply = NULL;
4311 kfree(mrioc->bsg_cmds.reply);
4312 mrioc->bsg_cmds.reply = NULL;
4314 kfree(mrioc->host_tm_cmds.reply);
4315 mrioc->host_tm_cmds.reply = NULL;
4317 kfree(mrioc->pel_cmds.reply);
4318 mrioc->pel_cmds.reply = NULL;
4320 kfree(mrioc->pel_abort_cmd.reply);
4321 mrioc->pel_abort_cmd.reply = NULL;
4323 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4324 kfree(mrioc->evtack_cmds[i].reply);
4325 mrioc->evtack_cmds[i].reply = NULL;
4328 kfree(mrioc->removepend_bitmap);
4329 mrioc->removepend_bitmap = NULL;
4331 kfree(mrioc->devrem_bitmap);
4332 mrioc->devrem_bitmap = NULL;
4334 kfree(mrioc->evtack_cmds_bitmap);
4335 mrioc->evtack_cmds_bitmap = NULL;
4337 kfree(mrioc->chain_bitmap);
4338 mrioc->chain_bitmap = NULL;
4340 kfree(mrioc->transport_cmds.reply);
4341 mrioc->transport_cmds.reply = NULL;
4343 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4344 kfree(mrioc->dev_rmhs_cmds[i].reply);
4345 mrioc->dev_rmhs_cmds[i].reply = NULL;
4348 if (mrioc->chain_buf_pool) {
4349 for (i = 0; i < mrioc->chain_buf_count; i++) {
4350 if (mrioc->chain_sgl_list[i].addr) {
4351 dma_pool_free(mrioc->chain_buf_pool,
4352 mrioc->chain_sgl_list[i].addr,
4353 mrioc->chain_sgl_list[i].dma_addr);
4354 mrioc->chain_sgl_list[i].addr = NULL;
4357 dma_pool_destroy(mrioc->chain_buf_pool);
4358 mrioc->chain_buf_pool = NULL;
4361 kfree(mrioc->chain_sgl_list);
4362 mrioc->chain_sgl_list = NULL;
4364 if (mrioc->admin_reply_base) {
4365 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
4366 mrioc->admin_reply_base, mrioc->admin_reply_dma);
4367 mrioc->admin_reply_base = NULL;
4369 if (mrioc->admin_req_base) {
4370 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
4371 mrioc->admin_req_base, mrioc->admin_req_dma);
4372 mrioc->admin_req_base = NULL;
4375 if (mrioc->pel_seqnum_virt) {
4376 dma_free_coherent(&mrioc->pdev->dev, mrioc->pel_seqnum_sz,
4377 mrioc->pel_seqnum_virt, mrioc->pel_seqnum_dma);
4378 mrioc->pel_seqnum_virt = NULL;
4381 kfree(mrioc->logdata_buf);
4382 mrioc->logdata_buf = NULL;
4387 * mpi3mr_issue_ioc_shutdown - shutdown controller
4388 * @mrioc: Adapter instance reference
4390 * Send shutodwn notification to the controller and wait for the
4391 * shutdown_timeout for it to be completed.
4395 static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
4397 u32 ioc_config, ioc_status;
4399 u32 timeout = MPI3MR_DEFAULT_SHUTDOWN_TIME * 10;
4401 ioc_info(mrioc, "Issuing shutdown Notification\n");
4402 if (mrioc->unrecoverable) {
4404 "IOC is unrecoverable shutdown is not issued\n");
4407 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4408 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4409 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS) {
4410 ioc_info(mrioc, "shutdown already in progress\n");
4414 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4415 ioc_config |= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL;
4416 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN_SEND_REQ;
4418 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
4420 if (mrioc->facts.shutdown_timeout)
4421 timeout = mrioc->facts.shutdown_timeout * 10;
4424 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4425 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4426 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE) {
4431 } while (--timeout);
4433 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4434 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4437 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4438 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS)
4440 "shutdown still in progress after timeout\n");
4444 "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
4445 (!retval) ? "successful" : "failed", ioc_status,
4450 * mpi3mr_cleanup_ioc - Cleanup controller
4451 * @mrioc: Adapter instance reference
4453 * controller cleanup handler, Message unit reset or soft reset
4454 * and shutdown notification is issued to the controller.
4458 void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
4460 enum mpi3mr_iocstate ioc_state;
4462 dprint_exit(mrioc, "cleaning up the controller\n");
4463 mpi3mr_ioc_disable_intr(mrioc);
4465 ioc_state = mpi3mr_get_iocstate(mrioc);
4467 if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
4468 (ioc_state == MRIOC_STATE_READY)) {
4469 if (mpi3mr_issue_and_process_mur(mrioc,
4470 MPI3MR_RESET_FROM_CTLR_CLEANUP))
4471 mpi3mr_issue_reset(mrioc,
4472 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
4473 MPI3MR_RESET_FROM_MUR_FAILURE);
4474 mpi3mr_issue_ioc_shutdown(mrioc);
4476 dprint_exit(mrioc, "controller cleanup completed\n");
4480 * mpi3mr_drv_cmd_comp_reset - Flush a internal driver command
4481 * @mrioc: Adapter instance reference
4482 * @cmdptr: Internal command tracker
4484 * Complete an internal driver commands with state indicating it
4485 * is completed due to reset.
4489 static inline void mpi3mr_drv_cmd_comp_reset(struct mpi3mr_ioc *mrioc,
4490 struct mpi3mr_drv_cmd *cmdptr)
4492 if (cmdptr->state & MPI3MR_CMD_PENDING) {
4493 cmdptr->state |= MPI3MR_CMD_RESET;
4494 cmdptr->state &= ~MPI3MR_CMD_PENDING;
4495 if (cmdptr->is_waiting) {
4496 complete(&cmdptr->done);
4497 cmdptr->is_waiting = 0;
4498 } else if (cmdptr->callback)
4499 cmdptr->callback(mrioc, cmdptr);
4504 * mpi3mr_flush_drv_cmds - Flush internaldriver commands
4505 * @mrioc: Adapter instance reference
4507 * Flush all internal driver commands post reset
4511 void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
4513 struct mpi3mr_drv_cmd *cmdptr;
4516 cmdptr = &mrioc->init_cmds;
4517 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4519 cmdptr = &mrioc->cfg_cmds;
4520 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4522 cmdptr = &mrioc->bsg_cmds;
4523 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4524 cmdptr = &mrioc->host_tm_cmds;
4525 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4527 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4528 cmdptr = &mrioc->dev_rmhs_cmds[i];
4529 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4532 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4533 cmdptr = &mrioc->evtack_cmds[i];
4534 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4537 cmdptr = &mrioc->pel_cmds;
4538 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4540 cmdptr = &mrioc->pel_abort_cmd;
4541 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4543 cmdptr = &mrioc->transport_cmds;
4544 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4548 * mpi3mr_pel_wait_post - Issue PEL Wait
4549 * @mrioc: Adapter instance reference
4550 * @drv_cmd: Internal command tracker
4552 * Issue PEL Wait MPI request through admin queue and return.
4556 static void mpi3mr_pel_wait_post(struct mpi3mr_ioc *mrioc,
4557 struct mpi3mr_drv_cmd *drv_cmd)
4559 struct mpi3_pel_req_action_wait pel_wait;
4561 mrioc->pel_abort_requested = false;
4563 memset(&pel_wait, 0, sizeof(pel_wait));
4564 drv_cmd->state = MPI3MR_CMD_PENDING;
4565 drv_cmd->is_waiting = 0;
4566 drv_cmd->callback = mpi3mr_pel_wait_complete;
4567 drv_cmd->ioc_status = 0;
4568 drv_cmd->ioc_loginfo = 0;
4569 pel_wait.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4570 pel_wait.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4571 pel_wait.action = MPI3_PEL_ACTION_WAIT;
4572 pel_wait.starting_sequence_number = cpu_to_le32(mrioc->pel_newest_seqnum);
4573 pel_wait.locale = cpu_to_le16(mrioc->pel_locale);
4574 pel_wait.class = cpu_to_le16(mrioc->pel_class);
4575 pel_wait.wait_time = MPI3_PEL_WAITTIME_INFINITE_WAIT;
4576 dprint_bsg_info(mrioc, "sending pel_wait seqnum(%d), class(%d), locale(0x%08x)\n",
4577 mrioc->pel_newest_seqnum, mrioc->pel_class, mrioc->pel_locale);
4579 if (mpi3mr_admin_request_post(mrioc, &pel_wait, sizeof(pel_wait), 0)) {
4580 dprint_bsg_err(mrioc,
4581 "Issuing PELWait: Admin post failed\n");
4582 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4583 drv_cmd->callback = NULL;
4584 drv_cmd->retry_count = 0;
4585 mrioc->pel_enabled = false;
4590 * mpi3mr_pel_get_seqnum_post - Issue PEL Get Sequence number
4591 * @mrioc: Adapter instance reference
4592 * @drv_cmd: Internal command tracker
4594 * Issue PEL get sequence number MPI request through admin queue
4597 * Return: 0 on success, non-zero on failure.
4599 int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc,
4600 struct mpi3mr_drv_cmd *drv_cmd)
4602 struct mpi3_pel_req_action_get_sequence_numbers pel_getseq_req;
4603 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
4606 memset(&pel_getseq_req, 0, sizeof(pel_getseq_req));
4607 mrioc->pel_cmds.state = MPI3MR_CMD_PENDING;
4608 mrioc->pel_cmds.is_waiting = 0;
4609 mrioc->pel_cmds.ioc_status = 0;
4610 mrioc->pel_cmds.ioc_loginfo = 0;
4611 mrioc->pel_cmds.callback = mpi3mr_pel_get_seqnum_complete;
4612 pel_getseq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4613 pel_getseq_req.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4614 pel_getseq_req.action = MPI3_PEL_ACTION_GET_SEQNUM;
4615 mpi3mr_add_sg_single(&pel_getseq_req.sgl, sgl_flags,
4616 mrioc->pel_seqnum_sz, mrioc->pel_seqnum_dma);
4618 retval = mpi3mr_admin_request_post(mrioc, &pel_getseq_req,
4619 sizeof(pel_getseq_req), 0);
4622 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4623 drv_cmd->callback = NULL;
4624 drv_cmd->retry_count = 0;
4626 mrioc->pel_enabled = false;
4633 * mpi3mr_pel_wait_complete - PELWait Completion callback
4634 * @mrioc: Adapter instance reference
4635 * @drv_cmd: Internal command tracker
4637 * This is a callback handler for the PELWait request and
4638 * firmware completes a PELWait request when it is aborted or a
4639 * new PEL entry is available. This sends AEN to the application
4640 * and if the PELwait completion is not due to PELAbort then
4641 * this will send a request for new PEL Sequence number
4645 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc *mrioc,
4646 struct mpi3mr_drv_cmd *drv_cmd)
4648 struct mpi3_pel_reply *pel_reply = NULL;
4649 u16 ioc_status, pe_log_status;
4650 bool do_retry = false;
4652 if (drv_cmd->state & MPI3MR_CMD_RESET)
4653 goto cleanup_drv_cmd;
4655 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4656 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4657 ioc_err(mrioc, "%s: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
4658 __func__, ioc_status, drv_cmd->ioc_loginfo);
4659 dprint_bsg_err(mrioc,
4660 "pel_wait: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4661 ioc_status, drv_cmd->ioc_loginfo);
4665 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4666 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4669 dprint_bsg_err(mrioc,
4670 "pel_wait: failed due to no reply\n");
4674 pe_log_status = le16_to_cpu(pel_reply->pe_log_status);
4675 if ((pe_log_status != MPI3_PEL_STATUS_SUCCESS) &&
4676 (pe_log_status != MPI3_PEL_STATUS_ABORTED)) {
4677 ioc_err(mrioc, "%s: Failed pe_log_status(0x%04x)\n",
4678 __func__, pe_log_status);
4679 dprint_bsg_err(mrioc,
4680 "pel_wait: failed due to pel_log_status(0x%04x)\n",
4686 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4687 drv_cmd->retry_count++;
4688 dprint_bsg_err(mrioc, "pel_wait: retrying(%d)\n",
4689 drv_cmd->retry_count);
4690 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4693 dprint_bsg_err(mrioc,
4694 "pel_wait: failed after all retries(%d)\n",
4695 drv_cmd->retry_count);
4698 atomic64_inc(&event_counter);
4699 if (!mrioc->pel_abort_requested) {
4700 mrioc->pel_cmds.retry_count = 0;
4701 mpi3mr_pel_get_seqnum_post(mrioc, &mrioc->pel_cmds);
4706 mrioc->pel_enabled = false;
4708 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4709 drv_cmd->callback = NULL;
4710 drv_cmd->retry_count = 0;
4714 * mpi3mr_pel_get_seqnum_complete - PELGetSeqNum Completion callback
4715 * @mrioc: Adapter instance reference
4716 * @drv_cmd: Internal command tracker
4718 * This is a callback handler for the PEL get sequence number
4719 * request and a new PEL wait request will be issued to the
4720 * firmware from this
4724 void mpi3mr_pel_get_seqnum_complete(struct mpi3mr_ioc *mrioc,
4725 struct mpi3mr_drv_cmd *drv_cmd)
4727 struct mpi3_pel_reply *pel_reply = NULL;
4728 struct mpi3_pel_seq *pel_seqnum_virt;
4730 bool do_retry = false;
4732 pel_seqnum_virt = (struct mpi3_pel_seq *)mrioc->pel_seqnum_virt;
4734 if (drv_cmd->state & MPI3MR_CMD_RESET)
4735 goto cleanup_drv_cmd;
4737 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4738 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4739 dprint_bsg_err(mrioc,
4740 "pel_get_seqnum: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4741 ioc_status, drv_cmd->ioc_loginfo);
4745 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4746 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4748 dprint_bsg_err(mrioc,
4749 "pel_get_seqnum: failed due to no reply\n");
4753 if (le16_to_cpu(pel_reply->pe_log_status) != MPI3_PEL_STATUS_SUCCESS) {
4754 dprint_bsg_err(mrioc,
4755 "pel_get_seqnum: failed due to pel_log_status(0x%04x)\n",
4756 le16_to_cpu(pel_reply->pe_log_status));
4761 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4762 drv_cmd->retry_count++;
4763 dprint_bsg_err(mrioc,
4764 "pel_get_seqnum: retrying(%d)\n",
4765 drv_cmd->retry_count);
4766 mpi3mr_pel_get_seqnum_post(mrioc, drv_cmd);
4770 dprint_bsg_err(mrioc,
4771 "pel_get_seqnum: failed after all retries(%d)\n",
4772 drv_cmd->retry_count);
4775 mrioc->pel_newest_seqnum = le32_to_cpu(pel_seqnum_virt->newest) + 1;
4776 drv_cmd->retry_count = 0;
4777 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4781 mrioc->pel_enabled = false;
4783 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4784 drv_cmd->callback = NULL;
4785 drv_cmd->retry_count = 0;
4789 * mpi3mr_soft_reset_handler - Reset the controller
4790 * @mrioc: Adapter instance reference
4791 * @reset_reason: Reset reason code
4792 * @snapdump: Flag to generate snapdump in firmware or not
4794 * This is an handler for recovering controller by issuing soft
4795 * reset are diag fault reset. This is a blocking function and
4796 * when one reset is executed if any other resets they will be
4797 * blocked. All BSG requests will be blocked during the reset. If
4798 * controller reset is successful then the controller will be
4799 * reinitalized, otherwise the controller will be marked as not
4802 * In snapdump bit is set, the controller is issued with diag
4803 * fault reset so that the firmware can create a snap dump and
4804 * post that the firmware will result in F000 fault and the
4805 * driver will issue soft reset to recover from that.
4807 * Return: 0 on success, non-zero on failure.
4809 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
4810 u32 reset_reason, u8 snapdump)
4813 unsigned long flags;
4814 u32 host_diagnostic, timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
4816 /* Block the reset handler until diag save in progress*/
4818 "soft_reset_handler: check and block on diagsave_timeout(%d)\n",
4819 mrioc->diagsave_timeout);
4820 while (mrioc->diagsave_timeout)
4823 * Block new resets until the currently executing one is finished and
4824 * return the status of the existing reset for all blocked resets
4826 dprint_reset(mrioc, "soft_reset_handler: acquiring reset_mutex\n");
4827 if (!mutex_trylock(&mrioc->reset_mutex)) {
4829 "controller reset triggered by %s is blocked due to another reset in progress\n",
4830 mpi3mr_reset_rc_name(reset_reason));
4833 } while (mrioc->reset_in_progress == 1);
4835 "returning previous reset result(%d) for the reset triggered by %s\n",
4836 mrioc->prev_reset_result,
4837 mpi3mr_reset_rc_name(reset_reason));
4838 return mrioc->prev_reset_result;
4840 ioc_info(mrioc, "controller reset is triggered by %s\n",
4841 mpi3mr_reset_rc_name(reset_reason));
4843 mrioc->device_refresh_on = 0;
4844 mrioc->reset_in_progress = 1;
4845 mrioc->stop_bsgs = 1;
4846 mrioc->prev_reset_result = -1;
4848 if ((!snapdump) && (reset_reason != MPI3MR_RESET_FROM_FAULT_WATCH) &&
4849 (reset_reason != MPI3MR_RESET_FROM_FIRMWARE) &&
4850 (reset_reason != MPI3MR_RESET_FROM_CIACTIV_FAULT)) {
4851 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4852 mrioc->event_masks[i] = -1;
4854 dprint_reset(mrioc, "soft_reset_handler: masking events\n");
4855 mpi3mr_issue_event_notification(mrioc);
4858 mpi3mr_wait_for_host_io(mrioc, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT);
4860 mpi3mr_ioc_disable_intr(mrioc);
4863 mpi3mr_set_diagsave(mrioc);
4864 retval = mpi3mr_issue_reset(mrioc,
4865 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
4869 readl(&mrioc->sysif_regs->host_diagnostic);
4870 if (!(host_diagnostic &
4871 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
4874 } while (--timeout);
4878 retval = mpi3mr_issue_reset(mrioc,
4879 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, reset_reason);
4881 ioc_err(mrioc, "Failed to issue soft reset to the ioc\n");
4884 if (mrioc->num_io_throttle_group !=
4885 mrioc->facts.max_io_throttle_group) {
4887 "max io throttle group doesn't match old(%d), new(%d)\n",
4888 mrioc->num_io_throttle_group,
4889 mrioc->facts.max_io_throttle_group);
4894 mpi3mr_flush_delayed_cmd_lists(mrioc);
4895 mpi3mr_flush_drv_cmds(mrioc);
4896 memset(mrioc->devrem_bitmap, 0, mrioc->devrem_bitmap_sz);
4897 memset(mrioc->removepend_bitmap, 0, mrioc->dev_handle_bitmap_sz);
4898 memset(mrioc->evtack_cmds_bitmap, 0, mrioc->evtack_cmds_bitmap_sz);
4899 mpi3mr_flush_host_io(mrioc);
4900 mpi3mr_cleanup_fwevt_list(mrioc);
4901 mpi3mr_invalidate_devhandles(mrioc);
4902 mpi3mr_free_enclosure_list(mrioc);
4904 if (mrioc->prepare_for_reset) {
4905 mrioc->prepare_for_reset = 0;
4906 mrioc->prepare_for_reset_timeout_counter = 0;
4908 mpi3mr_memset_buffers(mrioc);
4909 retval = mpi3mr_reinit_ioc(mrioc, 0);
4911 pr_err(IOCNAME "reinit after soft reset failed: reason %d\n",
4912 mrioc->name, reset_reason);
4919 mrioc->diagsave_timeout = 0;
4920 mrioc->reset_in_progress = 0;
4921 mrioc->pel_abort_requested = 0;
4922 if (mrioc->pel_enabled) {
4923 mrioc->pel_cmds.retry_count = 0;
4924 mpi3mr_pel_wait_post(mrioc, &mrioc->pel_cmds);
4927 mrioc->device_refresh_on = 0;
4929 mrioc->ts_update_counter = 0;
4930 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
4931 if (mrioc->watchdog_work_q)
4932 queue_delayed_work(mrioc->watchdog_work_q,
4933 &mrioc->watchdog_work,
4934 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
4935 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
4936 mrioc->stop_bsgs = 0;
4937 if (mrioc->pel_enabled)
4938 atomic64_inc(&event_counter);
4940 mpi3mr_issue_reset(mrioc,
4941 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
4942 mrioc->device_refresh_on = 0;
4943 mrioc->unrecoverable = 1;
4944 mrioc->reset_in_progress = 0;
4946 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
4948 mrioc->prev_reset_result = retval;
4949 mutex_unlock(&mrioc->reset_mutex);
4950 ioc_info(mrioc, "controller reset is %s\n",
4951 ((retval == 0) ? "successful" : "failed"));
4957 * mpi3mr_free_config_dma_memory - free memory for config page
4958 * @mrioc: Adapter instance reference
4959 * @mem_desc: memory descriptor structure
4961 * Check whether the size of the buffer specified by the memory
4962 * descriptor is greater than the default page size if so then
4963 * free the memory pointed by the descriptor.
4967 static void mpi3mr_free_config_dma_memory(struct mpi3mr_ioc *mrioc,
4968 struct dma_memory_desc *mem_desc)
4970 if ((mem_desc->size > mrioc->cfg_page_sz) && mem_desc->addr) {
4971 dma_free_coherent(&mrioc->pdev->dev, mem_desc->size,
4972 mem_desc->addr, mem_desc->dma_addr);
4973 mem_desc->addr = NULL;
4978 * mpi3mr_alloc_config_dma_memory - Alloc memory for config page
4979 * @mrioc: Adapter instance reference
4980 * @mem_desc: Memory descriptor to hold dma memory info
4982 * This function allocates new dmaable memory or provides the
4983 * default config page dmaable memory based on the memory size
4984 * described by the descriptor.
4986 * Return: 0 on success, non-zero on failure.
4988 static int mpi3mr_alloc_config_dma_memory(struct mpi3mr_ioc *mrioc,
4989 struct dma_memory_desc *mem_desc)
4991 if (mem_desc->size > mrioc->cfg_page_sz) {
4992 mem_desc->addr = dma_alloc_coherent(&mrioc->pdev->dev,
4993 mem_desc->size, &mem_desc->dma_addr, GFP_KERNEL);
4994 if (!mem_desc->addr)
4997 mem_desc->addr = mrioc->cfg_page;
4998 mem_desc->dma_addr = mrioc->cfg_page_dma;
4999 memset(mem_desc->addr, 0, mrioc->cfg_page_sz);
5005 * mpi3mr_post_cfg_req - Issue config requests and wait
5006 * @mrioc: Adapter instance reference
5007 * @cfg_req: Configuration request
5008 * @timeout: Timeout in seconds
5009 * @ioc_status: Pointer to return ioc status
5011 * A generic function for posting MPI3 configuration request to
5012 * the firmware. This blocks for the completion of request for
5013 * timeout seconds and if the request times out this function
5014 * faults the controller with proper reason code.
5016 * On successful completion of the request this function returns
5017 * appropriate ioc status from the firmware back to the caller.
5019 * Return: 0 on success, non-zero on failure.
5021 static int mpi3mr_post_cfg_req(struct mpi3mr_ioc *mrioc,
5022 struct mpi3_config_request *cfg_req, int timeout, u16 *ioc_status)
5026 mutex_lock(&mrioc->cfg_cmds.mutex);
5027 if (mrioc->cfg_cmds.state & MPI3MR_CMD_PENDING) {
5029 ioc_err(mrioc, "sending config request failed due to command in use\n");
5030 mutex_unlock(&mrioc->cfg_cmds.mutex);
5033 mrioc->cfg_cmds.state = MPI3MR_CMD_PENDING;
5034 mrioc->cfg_cmds.is_waiting = 1;
5035 mrioc->cfg_cmds.callback = NULL;
5036 mrioc->cfg_cmds.ioc_status = 0;
5037 mrioc->cfg_cmds.ioc_loginfo = 0;
5039 cfg_req->host_tag = cpu_to_le16(MPI3MR_HOSTTAG_CFG_CMDS);
5040 cfg_req->function = MPI3_FUNCTION_CONFIG;
5042 init_completion(&mrioc->cfg_cmds.done);
5043 dprint_cfg_info(mrioc, "posting config request\n");
5044 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5045 dprint_dump(cfg_req, sizeof(struct mpi3_config_request),
5047 retval = mpi3mr_admin_request_post(mrioc, cfg_req, sizeof(*cfg_req), 1);
5049 ioc_err(mrioc, "posting config request failed\n");
5052 wait_for_completion_timeout(&mrioc->cfg_cmds.done, (timeout * HZ));
5053 if (!(mrioc->cfg_cmds.state & MPI3MR_CMD_COMPLETE)) {
5054 mpi3mr_check_rh_fault_ioc(mrioc,
5055 MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT);
5056 ioc_err(mrioc, "config request timed out\n");
5060 *ioc_status = mrioc->cfg_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
5061 if ((*ioc_status) != MPI3_IOCSTATUS_SUCCESS)
5062 dprint_cfg_err(mrioc,
5063 "cfg_page request returned with ioc_status(0x%04x), log_info(0x%08x)\n",
5064 *ioc_status, mrioc->cfg_cmds.ioc_loginfo);
5067 mrioc->cfg_cmds.state = MPI3MR_CMD_NOTUSED;
5068 mutex_unlock(&mrioc->cfg_cmds.mutex);
5075 * mpi3mr_process_cfg_req - config page request processor
5076 * @mrioc: Adapter instance reference
5077 * @cfg_req: Configuration request
5078 * @cfg_hdr: Configuration page header
5079 * @timeout: Timeout in seconds
5080 * @ioc_status: Pointer to return ioc status
5081 * @cfg_buf: Memory pointer to copy config page or header
5082 * @cfg_buf_sz: Size of the memory to get config page or header
5084 * This is handler for config page read, write and config page
5085 * header read operations.
5087 * This function expects the cfg_req to be populated with page
5088 * type, page number, action for the header read and with page
5089 * address for all other operations.
5091 * The cfg_hdr can be passed as null for reading required header
5092 * details for read/write pages the cfg_hdr should point valid
5093 * configuration page header.
5095 * This allocates dmaable memory based on the size of the config
5096 * buffer and set the SGE of the cfg_req.
5098 * For write actions, the config page data has to be passed in
5099 * the cfg_buf and size of the data has to be mentioned in the
5102 * For read/header actions, on successful completion of the
5103 * request with successful ioc_status the data will be copied
5104 * into the cfg_buf limited to a minimum of actual page size and
5108 * Return: 0 on success, non-zero on failure.
5110 static int mpi3mr_process_cfg_req(struct mpi3mr_ioc *mrioc,
5111 struct mpi3_config_request *cfg_req,
5112 struct mpi3_config_page_header *cfg_hdr, int timeout, u16 *ioc_status,
5113 void *cfg_buf, u32 cfg_buf_sz)
5115 struct dma_memory_desc mem_desc;
5117 u8 invalid_action = 0;
5118 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
5120 memset(&mem_desc, 0, sizeof(struct dma_memory_desc));
5122 if (cfg_req->action == MPI3_CONFIG_ACTION_PAGE_HEADER)
5123 mem_desc.size = sizeof(struct mpi3_config_page_header);
5126 ioc_err(mrioc, "null config header passed for config action(%d), page_type(0x%02x), page_num(%d)\n",
5127 cfg_req->action, cfg_req->page_type,
5128 cfg_req->page_number);
5131 switch (cfg_hdr->page_attribute & MPI3_CONFIG_PAGEATTR_MASK) {
5132 case MPI3_CONFIG_PAGEATTR_READ_ONLY:
5134 != MPI3_CONFIG_ACTION_READ_CURRENT)
5137 case MPI3_CONFIG_PAGEATTR_CHANGEABLE:
5138 if ((cfg_req->action ==
5139 MPI3_CONFIG_ACTION_READ_PERSISTENT) ||
5141 MPI3_CONFIG_ACTION_WRITE_PERSISTENT))
5144 case MPI3_CONFIG_PAGEATTR_PERSISTENT:
5148 if (invalid_action) {
5150 "config action(%d) is not allowed for page_type(0x%02x), page_num(%d) with page_attribute(0x%02x)\n",
5151 cfg_req->action, cfg_req->page_type,
5152 cfg_req->page_number, cfg_hdr->page_attribute);
5155 mem_desc.size = le16_to_cpu(cfg_hdr->page_length) * 4;
5156 cfg_req->page_length = cfg_hdr->page_length;
5157 cfg_req->page_version = cfg_hdr->page_version;
5159 if (mpi3mr_alloc_config_dma_memory(mrioc, &mem_desc))
5162 mpi3mr_add_sg_single(&cfg_req->sgl, sgl_flags, mem_desc.size,
5165 if ((cfg_req->action == MPI3_CONFIG_ACTION_WRITE_PERSISTENT) ||
5166 (cfg_req->action == MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5167 memcpy(mem_desc.addr, cfg_buf, min_t(u16, mem_desc.size,
5169 dprint_cfg_info(mrioc, "config buffer to be written\n");
5170 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5171 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5174 if (mpi3mr_post_cfg_req(mrioc, cfg_req, timeout, ioc_status))
5178 if ((*ioc_status == MPI3_IOCSTATUS_SUCCESS) &&
5179 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_PERSISTENT) &&
5180 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5181 memcpy(cfg_buf, mem_desc.addr, min_t(u16, mem_desc.size,
5183 dprint_cfg_info(mrioc, "config buffer read\n");
5184 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5185 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5189 mpi3mr_free_config_dma_memory(mrioc, &mem_desc);
5194 * mpi3mr_cfg_get_dev_pg0 - Read current device page0
5195 * @mrioc: Adapter instance reference
5196 * @ioc_status: Pointer to return ioc status
5197 * @dev_pg0: Pointer to return device page 0
5198 * @pg_sz: Size of the memory allocated to the page pointer
5199 * @form: The form to be used for addressing the page
5200 * @form_spec: Form specific information like device handle
5202 * This is handler for config page read for a specific device
5203 * page0. The ioc_status has the controller returned ioc_status.
5204 * This routine doesn't check ioc_status to decide whether the
5205 * page read is success or not and it is the callers
5208 * Return: 0 on success, non-zero on failure.
5210 int mpi3mr_cfg_get_dev_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5211 struct mpi3_device_page0 *dev_pg0, u16 pg_sz, u32 form, u32 form_spec)
5213 struct mpi3_config_page_header cfg_hdr;
5214 struct mpi3_config_request cfg_req;
5217 memset(dev_pg0, 0, pg_sz);
5218 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5219 memset(&cfg_req, 0, sizeof(cfg_req));
5221 cfg_req.function = MPI3_FUNCTION_CONFIG;
5222 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5223 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DEVICE;
5224 cfg_req.page_number = 0;
5225 cfg_req.page_address = 0;
5227 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5228 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5229 ioc_err(mrioc, "device page0 header read failed\n");
5232 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5233 ioc_err(mrioc, "device page0 header read failed with ioc_status(0x%04x)\n",
5237 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5238 page_address = ((form & MPI3_DEVICE_PGAD_FORM_MASK) |
5239 (form_spec & MPI3_DEVICE_PGAD_HANDLE_MASK));
5240 cfg_req.page_address = cpu_to_le32(page_address);
5241 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5242 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, dev_pg0, pg_sz)) {
5243 ioc_err(mrioc, "device page0 read failed\n");
5253 * mpi3mr_cfg_get_sas_phy_pg0 - Read current SAS Phy page0
5254 * @mrioc: Adapter instance reference
5255 * @ioc_status: Pointer to return ioc status
5256 * @phy_pg0: Pointer to return SAS Phy page 0
5257 * @pg_sz: Size of the memory allocated to the page pointer
5258 * @form: The form to be used for addressing the page
5259 * @form_spec: Form specific information like phy number
5261 * This is handler for config page read for a specific SAS Phy
5262 * page0. The ioc_status has the controller returned ioc_status.
5263 * This routine doesn't check ioc_status to decide whether the
5264 * page read is success or not and it is the callers
5267 * Return: 0 on success, non-zero on failure.
5269 int mpi3mr_cfg_get_sas_phy_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5270 struct mpi3_sas_phy_page0 *phy_pg0, u16 pg_sz, u32 form,
5273 struct mpi3_config_page_header cfg_hdr;
5274 struct mpi3_config_request cfg_req;
5277 memset(phy_pg0, 0, pg_sz);
5278 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5279 memset(&cfg_req, 0, sizeof(cfg_req));
5281 cfg_req.function = MPI3_FUNCTION_CONFIG;
5282 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5283 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5284 cfg_req.page_number = 0;
5285 cfg_req.page_address = 0;
5287 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5288 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5289 ioc_err(mrioc, "sas phy page0 header read failed\n");
5292 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5293 ioc_err(mrioc, "sas phy page0 header read failed with ioc_status(0x%04x)\n",
5297 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5298 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5299 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5300 cfg_req.page_address = cpu_to_le32(page_address);
5301 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5302 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg0, pg_sz)) {
5303 ioc_err(mrioc, "sas phy page0 read failed\n");
5312 * mpi3mr_cfg_get_sas_phy_pg1 - Read current SAS Phy page1
5313 * @mrioc: Adapter instance reference
5314 * @ioc_status: Pointer to return ioc status
5315 * @phy_pg1: Pointer to return SAS Phy page 1
5316 * @pg_sz: Size of the memory allocated to the page pointer
5317 * @form: The form to be used for addressing the page
5318 * @form_spec: Form specific information like phy number
5320 * This is handler for config page read for a specific SAS Phy
5321 * page1. The ioc_status has the controller returned ioc_status.
5322 * This routine doesn't check ioc_status to decide whether the
5323 * page read is success or not and it is the callers
5326 * Return: 0 on success, non-zero on failure.
5328 int mpi3mr_cfg_get_sas_phy_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5329 struct mpi3_sas_phy_page1 *phy_pg1, u16 pg_sz, u32 form,
5332 struct mpi3_config_page_header cfg_hdr;
5333 struct mpi3_config_request cfg_req;
5336 memset(phy_pg1, 0, pg_sz);
5337 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5338 memset(&cfg_req, 0, sizeof(cfg_req));
5340 cfg_req.function = MPI3_FUNCTION_CONFIG;
5341 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5342 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5343 cfg_req.page_number = 1;
5344 cfg_req.page_address = 0;
5346 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5347 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5348 ioc_err(mrioc, "sas phy page1 header read failed\n");
5351 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5352 ioc_err(mrioc, "sas phy page1 header read failed with ioc_status(0x%04x)\n",
5356 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5357 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5358 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5359 cfg_req.page_address = cpu_to_le32(page_address);
5360 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5361 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg1, pg_sz)) {
5362 ioc_err(mrioc, "sas phy page1 read failed\n");
5372 * mpi3mr_cfg_get_sas_exp_pg0 - Read current SAS Expander page0
5373 * @mrioc: Adapter instance reference
5374 * @ioc_status: Pointer to return ioc status
5375 * @exp_pg0: Pointer to return SAS Expander page 0
5376 * @pg_sz: Size of the memory allocated to the page pointer
5377 * @form: The form to be used for addressing the page
5378 * @form_spec: Form specific information like device handle
5380 * This is handler for config page read for a specific SAS
5381 * Expander page0. The ioc_status has the controller returned
5382 * ioc_status. This routine doesn't check ioc_status to decide
5383 * whether the page read is success or not and it is the callers
5386 * Return: 0 on success, non-zero on failure.
5388 int mpi3mr_cfg_get_sas_exp_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5389 struct mpi3_sas_expander_page0 *exp_pg0, u16 pg_sz, u32 form,
5392 struct mpi3_config_page_header cfg_hdr;
5393 struct mpi3_config_request cfg_req;
5396 memset(exp_pg0, 0, pg_sz);
5397 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5398 memset(&cfg_req, 0, sizeof(cfg_req));
5400 cfg_req.function = MPI3_FUNCTION_CONFIG;
5401 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5402 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5403 cfg_req.page_number = 0;
5404 cfg_req.page_address = 0;
5406 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5407 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5408 ioc_err(mrioc, "expander page0 header read failed\n");
5411 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5412 ioc_err(mrioc, "expander page0 header read failed with ioc_status(0x%04x)\n",
5416 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5417 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5418 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5419 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5420 cfg_req.page_address = cpu_to_le32(page_address);
5421 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5422 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg0, pg_sz)) {
5423 ioc_err(mrioc, "expander page0 read failed\n");
5432 * mpi3mr_cfg_get_sas_exp_pg1 - Read current SAS Expander page1
5433 * @mrioc: Adapter instance reference
5434 * @ioc_status: Pointer to return ioc status
5435 * @exp_pg1: Pointer to return SAS Expander page 1
5436 * @pg_sz: Size of the memory allocated to the page pointer
5437 * @form: The form to be used for addressing the page
5438 * @form_spec: Form specific information like phy number
5440 * This is handler for config page read for a specific SAS
5441 * Expander page1. The ioc_status has the controller returned
5442 * ioc_status. This routine doesn't check ioc_status to decide
5443 * whether the page read is success or not and it is the callers
5446 * Return: 0 on success, non-zero on failure.
5448 int mpi3mr_cfg_get_sas_exp_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5449 struct mpi3_sas_expander_page1 *exp_pg1, u16 pg_sz, u32 form,
5452 struct mpi3_config_page_header cfg_hdr;
5453 struct mpi3_config_request cfg_req;
5456 memset(exp_pg1, 0, pg_sz);
5457 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5458 memset(&cfg_req, 0, sizeof(cfg_req));
5460 cfg_req.function = MPI3_FUNCTION_CONFIG;
5461 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5462 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5463 cfg_req.page_number = 1;
5464 cfg_req.page_address = 0;
5466 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5467 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5468 ioc_err(mrioc, "expander page1 header read failed\n");
5471 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5472 ioc_err(mrioc, "expander page1 header read failed with ioc_status(0x%04x)\n",
5476 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5477 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5478 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5479 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5480 cfg_req.page_address = cpu_to_le32(page_address);
5481 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5482 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg1, pg_sz)) {
5483 ioc_err(mrioc, "expander page1 read failed\n");
5492 * mpi3mr_cfg_get_enclosure_pg0 - Read current Enclosure page0
5493 * @mrioc: Adapter instance reference
5494 * @ioc_status: Pointer to return ioc status
5495 * @encl_pg0: Pointer to return Enclosure page 0
5496 * @pg_sz: Size of the memory allocated to the page pointer
5497 * @form: The form to be used for addressing the page
5498 * @form_spec: Form specific information like device handle
5500 * This is handler for config page read for a specific Enclosure
5501 * page0. The ioc_status has the controller returned ioc_status.
5502 * This routine doesn't check ioc_status to decide whether the
5503 * page read is success or not and it is the callers
5506 * Return: 0 on success, non-zero on failure.
5508 int mpi3mr_cfg_get_enclosure_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5509 struct mpi3_enclosure_page0 *encl_pg0, u16 pg_sz, u32 form,
5512 struct mpi3_config_page_header cfg_hdr;
5513 struct mpi3_config_request cfg_req;
5516 memset(encl_pg0, 0, pg_sz);
5517 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5518 memset(&cfg_req, 0, sizeof(cfg_req));
5520 cfg_req.function = MPI3_FUNCTION_CONFIG;
5521 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5522 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_ENCLOSURE;
5523 cfg_req.page_number = 0;
5524 cfg_req.page_address = 0;
5526 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5527 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5528 ioc_err(mrioc, "enclosure page0 header read failed\n");
5531 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5532 ioc_err(mrioc, "enclosure page0 header read failed with ioc_status(0x%04x)\n",
5536 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5537 page_address = ((form & MPI3_ENCLOS_PGAD_FORM_MASK) |
5538 (form_spec & MPI3_ENCLOS_PGAD_HANDLE_MASK));
5539 cfg_req.page_address = cpu_to_le32(page_address);
5540 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5541 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, encl_pg0, pg_sz)) {
5542 ioc_err(mrioc, "enclosure page0 read failed\n");
5552 * mpi3mr_cfg_get_sas_io_unit_pg0 - Read current SASIOUnit page0
5553 * @mrioc: Adapter instance reference
5554 * @sas_io_unit_pg0: Pointer to return SAS IO Unit page 0
5555 * @pg_sz: Size of the memory allocated to the page pointer
5557 * This is handler for config page read for the SAS IO Unit
5558 * page0. This routine checks ioc_status to decide whether the
5559 * page read is success or not.
5561 * Return: 0 on success, non-zero on failure.
5563 int mpi3mr_cfg_get_sas_io_unit_pg0(struct mpi3mr_ioc *mrioc,
5564 struct mpi3_sas_io_unit_page0 *sas_io_unit_pg0, u16 pg_sz)
5566 struct mpi3_config_page_header cfg_hdr;
5567 struct mpi3_config_request cfg_req;
5570 memset(sas_io_unit_pg0, 0, pg_sz);
5571 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5572 memset(&cfg_req, 0, sizeof(cfg_req));
5574 cfg_req.function = MPI3_FUNCTION_CONFIG;
5575 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5576 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5577 cfg_req.page_number = 0;
5578 cfg_req.page_address = 0;
5580 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5581 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5582 ioc_err(mrioc, "sas io unit page0 header read failed\n");
5585 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5586 ioc_err(mrioc, "sas io unit page0 header read failed with ioc_status(0x%04x)\n",
5590 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5592 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5593 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg0, pg_sz)) {
5594 ioc_err(mrioc, "sas io unit page0 read failed\n");
5597 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5598 ioc_err(mrioc, "sas io unit page0 read failed with ioc_status(0x%04x)\n",
5608 * mpi3mr_cfg_get_sas_io_unit_pg1 - Read current SASIOUnit page1
5609 * @mrioc: Adapter instance reference
5610 * @sas_io_unit_pg1: Pointer to return SAS IO Unit page 1
5611 * @pg_sz: Size of the memory allocated to the page pointer
5613 * This is handler for config page read for the SAS IO Unit
5614 * page1. This routine checks ioc_status to decide whether the
5615 * page read is success or not.
5617 * Return: 0 on success, non-zero on failure.
5619 int mpi3mr_cfg_get_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5620 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5622 struct mpi3_config_page_header cfg_hdr;
5623 struct mpi3_config_request cfg_req;
5626 memset(sas_io_unit_pg1, 0, pg_sz);
5627 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5628 memset(&cfg_req, 0, sizeof(cfg_req));
5630 cfg_req.function = MPI3_FUNCTION_CONFIG;
5631 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5632 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5633 cfg_req.page_number = 1;
5634 cfg_req.page_address = 0;
5636 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5637 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5638 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5641 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5642 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5646 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5648 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5649 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5650 ioc_err(mrioc, "sas io unit page1 read failed\n");
5653 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5654 ioc_err(mrioc, "sas io unit page1 read failed with ioc_status(0x%04x)\n",
5664 * mpi3mr_cfg_set_sas_io_unit_pg1 - Write SASIOUnit page1
5665 * @mrioc: Adapter instance reference
5666 * @sas_io_unit_pg1: Pointer to the SAS IO Unit page 1 to write
5667 * @pg_sz: Size of the memory allocated to the page pointer
5669 * This is handler for config page write for the SAS IO Unit
5670 * page1. This routine checks ioc_status to decide whether the
5671 * page read is success or not. This will modify both current
5672 * and persistent page.
5674 * Return: 0 on success, non-zero on failure.
5676 int mpi3mr_cfg_set_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5677 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5679 struct mpi3_config_page_header cfg_hdr;
5680 struct mpi3_config_request cfg_req;
5683 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5684 memset(&cfg_req, 0, sizeof(cfg_req));
5686 cfg_req.function = MPI3_FUNCTION_CONFIG;
5687 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5688 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5689 cfg_req.page_number = 1;
5690 cfg_req.page_address = 0;
5692 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5693 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5694 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5697 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5698 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5702 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_CURRENT;
5704 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5705 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5706 ioc_err(mrioc, "sas io unit page1 write current failed\n");
5709 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5710 ioc_err(mrioc, "sas io unit page1 write current failed with ioc_status(0x%04x)\n",
5715 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_PERSISTENT;
5717 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5718 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5719 ioc_err(mrioc, "sas io unit page1 write persistent failed\n");
5722 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5723 ioc_err(mrioc, "sas io unit page1 write persistent failed with ioc_status(0x%04x)\n",
5733 * mpi3mr_cfg_get_driver_pg1 - Read current Driver page1
5734 * @mrioc: Adapter instance reference
5735 * @driver_pg1: Pointer to return Driver page 1
5736 * @pg_sz: Size of the memory allocated to the page pointer
5738 * This is handler for config page read for the Driver page1.
5739 * This routine checks ioc_status to decide whether the page
5740 * read is success or not.
5742 * Return: 0 on success, non-zero on failure.
5744 int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc *mrioc,
5745 struct mpi3_driver_page1 *driver_pg1, u16 pg_sz)
5747 struct mpi3_config_page_header cfg_hdr;
5748 struct mpi3_config_request cfg_req;
5751 memset(driver_pg1, 0, pg_sz);
5752 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5753 memset(&cfg_req, 0, sizeof(cfg_req));
5755 cfg_req.function = MPI3_FUNCTION_CONFIG;
5756 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5757 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DRIVER;
5758 cfg_req.page_number = 1;
5759 cfg_req.page_address = 0;
5761 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5762 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5763 ioc_err(mrioc, "driver page1 header read failed\n");
5766 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5767 ioc_err(mrioc, "driver page1 header read failed with ioc_status(0x%04x)\n",
5771 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5773 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5774 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, driver_pg1, pg_sz)) {
5775 ioc_err(mrioc, "driver page1 read failed\n");
5778 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5779 ioc_err(mrioc, "driver page1 read failed with ioc_status(0x%04x)\n",