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 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 if (!atomic_add_unless(&mrioc->admin_reply_q_in_use, 1, 1))
429 reply_desc = (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
432 if ((le16_to_cpu(reply_desc->reply_flags) &
433 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
434 atomic_dec(&mrioc->admin_reply_q_in_use);
439 if (mrioc->unrecoverable)
442 mrioc->admin_req_ci = le16_to_cpu(reply_desc->request_queue_ci);
443 mpi3mr_process_admin_reply_desc(mrioc, reply_desc, &reply_dma);
445 mpi3mr_repost_reply_buf(mrioc, reply_dma);
447 if (++admin_reply_ci == mrioc->num_admin_replies) {
452 (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
454 if ((le16_to_cpu(reply_desc->reply_flags) &
455 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
459 writel(admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
460 mrioc->admin_reply_ci = admin_reply_ci;
461 mrioc->admin_reply_ephase = exp_phase;
462 atomic_dec(&mrioc->admin_reply_q_in_use);
464 return num_admin_replies;
468 * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
469 * queue's consumer index from operational reply descriptor queue.
470 * @op_reply_q: op_reply_qinfo object
471 * @reply_ci: operational reply descriptor's queue consumer index
473 * Returns reply descriptor frame address
475 static inline struct mpi3_default_reply_descriptor *
476 mpi3mr_get_reply_desc(struct op_reply_qinfo *op_reply_q, u32 reply_ci)
478 void *segment_base_addr;
479 struct segments *segments = op_reply_q->q_segments;
480 struct mpi3_default_reply_descriptor *reply_desc = NULL;
483 segments[reply_ci / op_reply_q->segment_qd].segment;
484 reply_desc = (struct mpi3_default_reply_descriptor *)segment_base_addr +
485 (reply_ci % op_reply_q->segment_qd);
490 * mpi3mr_process_op_reply_q - Operational reply queue handler
491 * @mrioc: Adapter instance reference
492 * @op_reply_q: Operational reply queue info
494 * Checks the specific operational reply queue and drains the
495 * reply queue entries until the queue is empty and process the
496 * individual reply descriptors.
498 * Return: 0 if queue is already processed,or number of reply
499 * descriptors processed.
501 int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
502 struct op_reply_qinfo *op_reply_q)
504 struct op_req_qinfo *op_req_q;
507 u32 num_op_reply = 0;
509 struct mpi3_default_reply_descriptor *reply_desc;
510 u16 req_q_idx = 0, reply_qidx;
512 reply_qidx = op_reply_q->qid - 1;
514 if (!atomic_add_unless(&op_reply_q->in_use, 1, 1))
517 exp_phase = op_reply_q->ephase;
518 reply_ci = op_reply_q->ci;
520 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
521 if ((le16_to_cpu(reply_desc->reply_flags) &
522 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
523 atomic_dec(&op_reply_q->in_use);
528 if (mrioc->unrecoverable)
531 req_q_idx = le16_to_cpu(reply_desc->request_queue_id) - 1;
532 op_req_q = &mrioc->req_qinfo[req_q_idx];
534 WRITE_ONCE(op_req_q->ci, le16_to_cpu(reply_desc->request_queue_ci));
535 mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
537 atomic_dec(&op_reply_q->pend_ios);
539 mpi3mr_repost_reply_buf(mrioc, reply_dma);
542 if (++reply_ci == op_reply_q->num_replies) {
547 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
549 if ((le16_to_cpu(reply_desc->reply_flags) &
550 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
552 #ifndef CONFIG_PREEMPT_RT
554 * Exit completion loop to avoid CPU lockup
555 * Ensure remaining completion happens from threaded ISR.
557 if (num_op_reply > mrioc->max_host_ios) {
558 op_reply_q->enable_irq_poll = true;
565 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].consumer_index);
566 op_reply_q->ci = reply_ci;
567 op_reply_q->ephase = exp_phase;
569 atomic_dec(&op_reply_q->in_use);
574 * mpi3mr_blk_mq_poll - Operational reply queue handler
575 * @shost: SCSI Host reference
576 * @queue_num: Request queue number (w.r.t OS it is hardware context number)
578 * Checks the specific operational reply queue and drains the
579 * reply queue entries until the queue is empty and process the
580 * individual reply descriptors.
582 * Return: 0 if queue is already processed,or number of reply
583 * descriptors processed.
585 int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
588 struct mpi3mr_ioc *mrioc;
590 mrioc = (struct mpi3mr_ioc *)shost->hostdata;
592 if ((mrioc->reset_in_progress || mrioc->prepare_for_reset ||
593 mrioc->unrecoverable))
596 num_entries = mpi3mr_process_op_reply_q(mrioc,
597 &mrioc->op_reply_qinfo[queue_num]);
602 static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
604 struct mpi3mr_intr_info *intr_info = privdata;
605 struct mpi3mr_ioc *mrioc;
607 u32 num_admin_replies = 0, num_op_reply = 0;
612 mrioc = intr_info->mrioc;
614 if (!mrioc->intr_enabled)
617 midx = intr_info->msix_index;
620 num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
621 if (intr_info->op_reply_q)
622 num_op_reply = mpi3mr_process_op_reply_q(mrioc,
623 intr_info->op_reply_q);
625 if (num_admin_replies || num_op_reply)
631 #ifndef CONFIG_PREEMPT_RT
633 static irqreturn_t mpi3mr_isr(int irq, void *privdata)
635 struct mpi3mr_intr_info *intr_info = privdata;
641 /* Call primary ISR routine */
642 ret = mpi3mr_isr_primary(irq, privdata);
645 * If more IOs are expected, schedule IRQ polling thread.
646 * Otherwise exit from ISR.
648 if (!intr_info->op_reply_q)
651 if (!intr_info->op_reply_q->enable_irq_poll ||
652 !atomic_read(&intr_info->op_reply_q->pend_ios))
655 disable_irq_nosync(intr_info->os_irq);
657 return IRQ_WAKE_THREAD;
661 * mpi3mr_isr_poll - Reply queue polling routine
663 * @privdata: Interrupt info
665 * poll for pending I/O completions in a loop until pending I/Os
666 * present or controller queue depth I/Os are processed.
668 * Return: IRQ_NONE or IRQ_HANDLED
670 static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
672 struct mpi3mr_intr_info *intr_info = privdata;
673 struct mpi3mr_ioc *mrioc;
675 u32 num_op_reply = 0;
677 if (!intr_info || !intr_info->op_reply_q)
680 mrioc = intr_info->mrioc;
681 midx = intr_info->msix_index;
683 /* Poll for pending IOs completions */
685 if (!mrioc->intr_enabled || mrioc->unrecoverable)
689 mpi3mr_process_admin_reply_q(mrioc);
690 if (intr_info->op_reply_q)
692 mpi3mr_process_op_reply_q(mrioc,
693 intr_info->op_reply_q);
695 usleep_range(MPI3MR_IRQ_POLL_SLEEP, 10 * MPI3MR_IRQ_POLL_SLEEP);
697 } while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
698 (num_op_reply < mrioc->max_host_ios));
700 intr_info->op_reply_q->enable_irq_poll = false;
701 enable_irq(intr_info->os_irq);
709 * mpi3mr_request_irq - Request IRQ and register ISR
710 * @mrioc: Adapter instance reference
711 * @index: IRQ vector index
713 * Request threaded ISR with primary ISR and secondary
715 * Return: 0 on success and non zero on failures.
717 static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index)
719 struct pci_dev *pdev = mrioc->pdev;
720 struct mpi3mr_intr_info *intr_info = mrioc->intr_info + index;
723 intr_info->mrioc = mrioc;
724 intr_info->msix_index = index;
725 intr_info->op_reply_q = NULL;
727 snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
728 mrioc->driver_name, mrioc->id, index);
730 #ifndef CONFIG_PREEMPT_RT
731 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr,
732 mpi3mr_isr_poll, IRQF_SHARED, intr_info->name, intr_info);
734 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr_primary,
735 NULL, IRQF_SHARED, intr_info->name, intr_info);
738 ioc_err(mrioc, "%s: Unable to allocate interrupt %d!\n",
739 intr_info->name, pci_irq_vector(pdev, index));
743 intr_info->os_irq = pci_irq_vector(pdev, index);
747 static void mpi3mr_calc_poll_queues(struct mpi3mr_ioc *mrioc, u16 max_vectors)
749 if (!mrioc->requested_poll_qcount)
752 /* Reserved for Admin and Default Queue */
753 if (max_vectors > 2 &&
754 (mrioc->requested_poll_qcount < max_vectors - 2)) {
756 "enabled polled queues (%d) msix (%d)\n",
757 mrioc->requested_poll_qcount, max_vectors);
760 "disabled polled queues (%d) msix (%d) because of no resources for default queue\n",
761 mrioc->requested_poll_qcount, max_vectors);
762 mrioc->requested_poll_qcount = 0;
767 * mpi3mr_setup_isr - Setup ISR for the controller
768 * @mrioc: Adapter instance reference
769 * @setup_one: Request one IRQ or more
771 * Allocate IRQ vectors and call mpi3mr_request_irq to setup ISR
773 * Return: 0 on success and non zero on failures.
775 static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
777 unsigned int irq_flags = PCI_IRQ_MSIX;
778 int max_vectors, min_vec;
781 struct irq_affinity desc = { .pre_vectors = 1, .post_vectors = 1 };
783 if (mrioc->is_intr_info_set)
786 mpi3mr_cleanup_isr(mrioc);
788 if (setup_one || reset_devices) {
790 retval = pci_alloc_irq_vectors(mrioc->pdev,
791 1, max_vectors, irq_flags);
793 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
799 min_t(int, mrioc->cpu_count + 1 +
800 mrioc->requested_poll_qcount, mrioc->msix_count);
802 mpi3mr_calc_poll_queues(mrioc, max_vectors);
805 "MSI-X vectors supported: %d, no of cores: %d,",
806 mrioc->msix_count, mrioc->cpu_count);
808 "MSI-x vectors requested: %d poll_queues %d\n",
809 max_vectors, mrioc->requested_poll_qcount);
811 desc.post_vectors = mrioc->requested_poll_qcount;
812 min_vec = desc.pre_vectors + desc.post_vectors;
813 irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
815 retval = pci_alloc_irq_vectors_affinity(mrioc->pdev,
816 min_vec, max_vectors, irq_flags, &desc);
819 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
826 * If only one MSI-x is allocated, then MSI-x 0 will be shared
827 * between Admin queue and operational queue
829 if (retval == min_vec)
830 mrioc->op_reply_q_offset = 0;
831 else if (retval != (max_vectors)) {
833 "allocated vectors (%d) are less than configured (%d)\n",
834 retval, max_vectors);
837 max_vectors = retval;
838 mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
840 mpi3mr_calc_poll_queues(mrioc, max_vectors);
844 mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info) * max_vectors,
846 if (!mrioc->intr_info) {
848 pci_free_irq_vectors(mrioc->pdev);
851 for (i = 0; i < max_vectors; i++) {
852 retval = mpi3mr_request_irq(mrioc, i);
854 mrioc->intr_info_count = i;
858 if (reset_devices || !setup_one)
859 mrioc->is_intr_info_set = true;
860 mrioc->intr_info_count = max_vectors;
861 mpi3mr_ioc_enable_intr(mrioc);
865 mpi3mr_cleanup_isr(mrioc);
870 static const struct {
871 enum mpi3mr_iocstate value;
874 { MRIOC_STATE_READY, "ready" },
875 { MRIOC_STATE_FAULT, "fault" },
876 { MRIOC_STATE_RESET, "reset" },
877 { MRIOC_STATE_BECOMING_READY, "becoming ready" },
878 { MRIOC_STATE_RESET_REQUESTED, "reset requested" },
879 { MRIOC_STATE_UNRECOVERABLE, "unrecoverable error" },
882 static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state)
887 for (i = 0; i < ARRAY_SIZE(mrioc_states); i++) {
888 if (mrioc_states[i].value == mrioc_state) {
889 name = mrioc_states[i].name;
896 /* Reset reason to name mapper structure*/
897 static const struct {
898 enum mpi3mr_reset_reason value;
900 } mpi3mr_reset_reason_codes[] = {
901 { MPI3MR_RESET_FROM_BRINGUP, "timeout in bringup" },
902 { MPI3MR_RESET_FROM_FAULT_WATCH, "fault" },
903 { MPI3MR_RESET_FROM_APP, "application invocation" },
904 { MPI3MR_RESET_FROM_EH_HOS, "error handling" },
905 { MPI3MR_RESET_FROM_TM_TIMEOUT, "TM timeout" },
906 { MPI3MR_RESET_FROM_APP_TIMEOUT, "application command timeout" },
907 { MPI3MR_RESET_FROM_MUR_FAILURE, "MUR failure" },
908 { MPI3MR_RESET_FROM_CTLR_CLEANUP, "timeout in controller cleanup" },
909 { MPI3MR_RESET_FROM_CIACTIV_FAULT, "component image activation fault" },
910 { MPI3MR_RESET_FROM_PE_TIMEOUT, "port enable timeout" },
911 { MPI3MR_RESET_FROM_TSU_TIMEOUT, "time stamp update timeout" },
912 { MPI3MR_RESET_FROM_DELREQQ_TIMEOUT, "delete request queue timeout" },
913 { MPI3MR_RESET_FROM_DELREPQ_TIMEOUT, "delete reply queue timeout" },
915 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT,
916 "create request queue timeout"
919 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT,
920 "create reply queue timeout"
922 { MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT, "IOC facts timeout" },
923 { MPI3MR_RESET_FROM_IOCINIT_TIMEOUT, "IOC init timeout" },
924 { MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT, "event notify timeout" },
925 { MPI3MR_RESET_FROM_EVTACK_TIMEOUT, "event acknowledgment timeout" },
927 MPI3MR_RESET_FROM_CIACTVRST_TIMER,
928 "component image activation timeout"
931 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT,
932 "get package version timeout"
934 { MPI3MR_RESET_FROM_SYSFS, "sysfs invocation" },
935 { MPI3MR_RESET_FROM_SYSFS_TIMEOUT, "sysfs TM timeout" },
936 { MPI3MR_RESET_FROM_FIRMWARE, "firmware asynchronous reset" },
937 { MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT, "configuration request timeout"},
938 { MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT, "timeout of a SAS transport layer request" },
942 * mpi3mr_reset_rc_name - get reset reason code name
943 * @reason_code: reset reason code value
945 * Map reset reason to an NULL terminated ASCII string
947 * Return: name corresponding to reset reason value or NULL.
949 static const char *mpi3mr_reset_rc_name(enum mpi3mr_reset_reason reason_code)
954 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_reason_codes); i++) {
955 if (mpi3mr_reset_reason_codes[i].value == reason_code) {
956 name = mpi3mr_reset_reason_codes[i].name;
963 /* Reset type to name mapper structure*/
964 static const struct {
967 } mpi3mr_reset_types[] = {
968 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, "soft" },
969 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, "diag fault" },
973 * mpi3mr_reset_type_name - get reset type name
974 * @reset_type: reset type value
976 * Map reset type to an NULL terminated ASCII string
978 * Return: name corresponding to reset type value or NULL.
980 static const char *mpi3mr_reset_type_name(u16 reset_type)
985 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_types); i++) {
986 if (mpi3mr_reset_types[i].reset_type == reset_type) {
987 name = mpi3mr_reset_types[i].name;
995 * mpi3mr_print_fault_info - Display fault information
996 * @mrioc: Adapter instance reference
998 * Display the controller fault information if there is a
1003 void mpi3mr_print_fault_info(struct mpi3mr_ioc *mrioc)
1005 u32 ioc_status, code, code1, code2, code3;
1007 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1009 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1010 code = readl(&mrioc->sysif_regs->fault);
1011 code1 = readl(&mrioc->sysif_regs->fault_info[0]);
1012 code2 = readl(&mrioc->sysif_regs->fault_info[1]);
1013 code3 = readl(&mrioc->sysif_regs->fault_info[2]);
1016 "fault code(0x%08X): Additional code: (0x%08X:0x%08X:0x%08X)\n",
1017 code, code1, code2, code3);
1022 * mpi3mr_get_iocstate - Get IOC State
1023 * @mrioc: Adapter instance reference
1025 * Return a proper IOC state enum based on the IOC status and
1026 * IOC configuration and unrcoverable state of the controller.
1028 * Return: Current IOC state.
1030 enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc)
1032 u32 ioc_status, ioc_config;
1035 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1036 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1038 if (mrioc->unrecoverable)
1039 return MRIOC_STATE_UNRECOVERABLE;
1040 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)
1041 return MRIOC_STATE_FAULT;
1043 ready = (ioc_status & MPI3_SYSIF_IOC_STATUS_READY);
1044 enabled = (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC);
1046 if (ready && enabled)
1047 return MRIOC_STATE_READY;
1048 if ((!ready) && (!enabled))
1049 return MRIOC_STATE_RESET;
1050 if ((!ready) && (enabled))
1051 return MRIOC_STATE_BECOMING_READY;
1053 return MRIOC_STATE_RESET_REQUESTED;
1057 * mpi3mr_clear_reset_history - clear reset history
1058 * @mrioc: Adapter instance reference
1060 * Write the reset history bit in IOC status to clear the bit,
1061 * if it is already set.
1065 static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc *mrioc)
1069 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1070 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1071 writel(ioc_status, &mrioc->sysif_regs->ioc_status);
1075 * mpi3mr_issue_and_process_mur - Message unit Reset handler
1076 * @mrioc: Adapter instance reference
1077 * @reset_reason: Reset reason code
1079 * Issue Message unit Reset to the controller and wait for it to
1082 * Return: 0 on success, -1 on failure.
1084 static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
1087 u32 ioc_config, timeout, ioc_status;
1090 ioc_info(mrioc, "Issuing Message unit Reset(MUR)\n");
1091 if (mrioc->unrecoverable) {
1092 ioc_info(mrioc, "IOC is unrecoverable MUR not issued\n");
1095 mpi3mr_clear_reset_history(mrioc);
1096 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1097 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1098 ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1099 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1101 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
1103 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1104 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)) {
1105 mpi3mr_clear_reset_history(mrioc);
1108 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1109 mpi3mr_print_fault_info(mrioc);
1113 } while (--timeout);
1115 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1116 if (timeout && !((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1117 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
1118 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1121 ioc_info(mrioc, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
1122 (!retval) ? "successful" : "failed", ioc_status, ioc_config);
1127 * mpi3mr_revalidate_factsdata - validate IOCFacts parameters
1128 * during reset/resume
1129 * @mrioc: Adapter instance reference
1131 * Return zero if the new IOCFacts parameters value is compatible with
1132 * older values else return -EPERM
1135 mpi3mr_revalidate_factsdata(struct mpi3mr_ioc *mrioc)
1137 void *removepend_bitmap;
1139 if (mrioc->facts.reply_sz > mrioc->reply_sz) {
1141 "cannot increase reply size from %d to %d\n",
1142 mrioc->reply_sz, mrioc->facts.reply_sz);
1146 if (mrioc->facts.max_op_reply_q < mrioc->num_op_reply_q) {
1148 "cannot reduce number of operational reply queues from %d to %d\n",
1149 mrioc->num_op_reply_q,
1150 mrioc->facts.max_op_reply_q);
1154 if (mrioc->facts.max_op_req_q < mrioc->num_op_req_q) {
1156 "cannot reduce number of operational request queues from %d to %d\n",
1157 mrioc->num_op_req_q, mrioc->facts.max_op_req_q);
1161 if ((mrioc->sas_transport_enabled) && (mrioc->facts.ioc_capabilities &
1162 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED))
1164 "critical error: multipath capability is enabled at the\n"
1165 "\tcontroller while sas transport support is enabled at the\n"
1166 "\tdriver, please reboot the system or reload the driver\n");
1168 if (mrioc->facts.max_devhandle > mrioc->dev_handle_bitmap_bits) {
1169 removepend_bitmap = bitmap_zalloc(mrioc->facts.max_devhandle,
1171 if (!removepend_bitmap) {
1173 "failed to increase removepend_bitmap bits from %d to %d\n",
1174 mrioc->dev_handle_bitmap_bits,
1175 mrioc->facts.max_devhandle);
1178 bitmap_free(mrioc->removepend_bitmap);
1179 mrioc->removepend_bitmap = removepend_bitmap;
1181 "increased bits of dev_handle_bitmap from %d to %d\n",
1182 mrioc->dev_handle_bitmap_bits,
1183 mrioc->facts.max_devhandle);
1184 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
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, host_diagnostic;
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 if (ioc_state == MRIOC_STATE_FAULT) {
1256 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
1257 mpi3mr_print_fault_info(mrioc);
1260 readl(&mrioc->sysif_regs->host_diagnostic);
1261 if (!(host_diagnostic &
1262 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
1264 if (!pci_device_is_present(mrioc->pdev)) {
1265 mrioc->unrecoverable = 1;
1266 ioc_err(mrioc, "controller is not present at the bringup\n");
1267 goto out_device_not_present;
1270 } while (--timeout);
1272 mpi3mr_print_fault_info(mrioc);
1273 ioc_info(mrioc, "issuing soft reset to bring to reset state\n");
1274 retval = mpi3mr_issue_reset(mrioc,
1275 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
1276 MPI3MR_RESET_FROM_BRINGUP);
1279 "soft reset failed with error %d\n", retval);
1283 ioc_state = mpi3mr_get_iocstate(mrioc);
1284 if (ioc_state != MRIOC_STATE_RESET) {
1286 "cannot bring controller to reset state, current state: %s\n",
1287 mpi3mr_iocstate_name(ioc_state));
1290 mpi3mr_clear_reset_history(mrioc);
1291 retval = mpi3mr_setup_admin_qpair(mrioc);
1293 ioc_err(mrioc, "failed to setup admin queues: error %d\n",
1298 ioc_info(mrioc, "bringing controller to ready state\n");
1299 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1300 ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1301 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1303 timeout = mrioc->ready_timeout * 10;
1305 ioc_state = mpi3mr_get_iocstate(mrioc);
1306 if (ioc_state == MRIOC_STATE_READY) {
1308 "successfully transitioned to %s state\n",
1309 mpi3mr_iocstate_name(ioc_state));
1312 if (!pci_device_is_present(mrioc->pdev)) {
1313 mrioc->unrecoverable = 1;
1315 "controller is not present at the bringup\n");
1317 goto out_device_not_present;
1320 } while (--timeout);
1323 ioc_state = mpi3mr_get_iocstate(mrioc);
1325 "failed to bring to ready state, current state: %s\n",
1326 mpi3mr_iocstate_name(ioc_state));
1327 out_device_not_present:
1332 * mpi3mr_soft_reset_success - Check softreset is success or not
1333 * @ioc_status: IOC status register value
1334 * @ioc_config: IOC config register value
1336 * Check whether the soft reset is successful or not based on
1337 * IOC status and IOC config register values.
1339 * Return: True when the soft reset is success, false otherwise.
1342 mpi3mr_soft_reset_success(u32 ioc_status, u32 ioc_config)
1344 if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1345 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1351 * mpi3mr_diagfault_success - Check diag fault is success or not
1352 * @mrioc: Adapter reference
1353 * @ioc_status: IOC status register value
1355 * Check whether the controller hit diag reset fault code.
1357 * Return: True when there is diag fault, false otherwise.
1359 static inline bool mpi3mr_diagfault_success(struct mpi3mr_ioc *mrioc,
1364 if (!(ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT))
1366 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
1367 if (fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET) {
1368 mpi3mr_print_fault_info(mrioc);
1375 * mpi3mr_set_diagsave - Set diag save bit for snapdump
1376 * @mrioc: Adapter reference
1378 * Set diag save bit in IOC configuration register to enable
1383 static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
1387 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1388 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE;
1389 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1393 * mpi3mr_issue_reset - Issue reset to the controller
1394 * @mrioc: Adapter reference
1395 * @reset_type: Reset type
1396 * @reset_reason: Reset reason code
1398 * Unlock the host diagnostic registers and write the specific
1399 * reset type to that, wait for reset acknowledgment from the
1400 * controller, if the reset is not successful retry for the
1401 * predefined number of times.
1403 * Return: 0 on success, non-zero on failure.
1405 static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
1409 u8 unlock_retry_count = 0;
1410 u32 host_diagnostic, ioc_status, ioc_config;
1411 u32 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
1413 if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
1414 (reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT))
1416 if (mrioc->unrecoverable)
1418 if (reset_reason == MPI3MR_RESET_FROM_FIRMWARE) {
1423 ioc_info(mrioc, "%s reset due to %s(0x%x)\n",
1424 mpi3mr_reset_type_name(reset_type),
1425 mpi3mr_reset_rc_name(reset_reason), reset_reason);
1427 mpi3mr_clear_reset_history(mrioc);
1430 "Write magic sequence to unlock host diag register (retry=%d)\n",
1431 ++unlock_retry_count);
1432 if (unlock_retry_count >= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT) {
1434 "%s reset failed due to unlock failure, host_diagnostic(0x%08x)\n",
1435 mpi3mr_reset_type_name(reset_type),
1437 mrioc->unrecoverable = 1;
1441 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH,
1442 &mrioc->sysif_regs->write_sequence);
1443 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST,
1444 &mrioc->sysif_regs->write_sequence);
1445 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1446 &mrioc->sysif_regs->write_sequence);
1447 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD,
1448 &mrioc->sysif_regs->write_sequence);
1449 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH,
1450 &mrioc->sysif_regs->write_sequence);
1451 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH,
1452 &mrioc->sysif_regs->write_sequence);
1453 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH,
1454 &mrioc->sysif_regs->write_sequence);
1455 usleep_range(1000, 1100);
1456 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
1458 "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
1459 unlock_retry_count, host_diagnostic);
1460 } while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
1462 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1463 writel(host_diagnostic | reset_type,
1464 &mrioc->sysif_regs->host_diagnostic);
1465 switch (reset_type) {
1466 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET:
1468 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1470 readl(&mrioc->sysif_regs->ioc_configuration);
1471 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1472 && mpi3mr_soft_reset_success(ioc_status, ioc_config)
1474 mpi3mr_clear_reset_history(mrioc);
1479 } while (--timeout);
1480 mpi3mr_print_fault_info(mrioc);
1482 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT:
1484 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1485 if (mpi3mr_diagfault_success(mrioc, ioc_status)) {
1490 } while (--timeout);
1496 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1497 &mrioc->sysif_regs->write_sequence);
1499 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1500 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1502 "ioc_status/ioc_onfig after %s reset is (0x%x)/(0x%x)\n",
1503 (!retval)?"successful":"failed", ioc_status,
1506 mrioc->unrecoverable = 1;
1511 * mpi3mr_admin_request_post - Post request to admin queue
1512 * @mrioc: Adapter reference
1513 * @admin_req: MPI3 request
1514 * @admin_req_sz: Request size
1515 * @ignore_reset: Ignore reset in process
1517 * Post the MPI3 request into admin request queue and
1518 * inform the controller, if the queue is full return
1519 * appropriate error.
1521 * Return: 0 on success, non-zero on failure.
1523 int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
1524 u16 admin_req_sz, u8 ignore_reset)
1526 u16 areq_pi = 0, areq_ci = 0, max_entries = 0;
1528 unsigned long flags;
1531 if (mrioc->unrecoverable) {
1532 ioc_err(mrioc, "%s : Unrecoverable controller\n", __func__);
1536 spin_lock_irqsave(&mrioc->admin_req_lock, flags);
1537 areq_pi = mrioc->admin_req_pi;
1538 areq_ci = mrioc->admin_req_ci;
1539 max_entries = mrioc->num_admin_req;
1540 if ((areq_ci == (areq_pi + 1)) || ((!areq_ci) &&
1541 (areq_pi == (max_entries - 1)))) {
1542 ioc_err(mrioc, "AdminReqQ full condition detected\n");
1546 if (!ignore_reset && mrioc->reset_in_progress) {
1547 ioc_err(mrioc, "AdminReqQ submit reset in progress\n");
1551 areq_entry = (u8 *)mrioc->admin_req_base +
1552 (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
1553 memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
1554 memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
1556 if (++areq_pi == max_entries)
1558 mrioc->admin_req_pi = areq_pi;
1560 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
1563 spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
1569 * mpi3mr_free_op_req_q_segments - free request memory segments
1570 * @mrioc: Adapter instance reference
1571 * @q_idx: operational request queue index
1573 * Free memory segments allocated for operational request queue
1577 static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1581 struct segments *segments;
1583 segments = mrioc->req_qinfo[q_idx].q_segments;
1587 if (mrioc->enable_segqueue) {
1588 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1589 if (mrioc->req_qinfo[q_idx].q_segment_list) {
1590 dma_free_coherent(&mrioc->pdev->dev,
1591 MPI3MR_MAX_SEG_LIST_SIZE,
1592 mrioc->req_qinfo[q_idx].q_segment_list,
1593 mrioc->req_qinfo[q_idx].q_segment_list_dma);
1594 mrioc->req_qinfo[q_idx].q_segment_list = NULL;
1597 size = mrioc->req_qinfo[q_idx].segment_qd *
1598 mrioc->facts.op_req_sz;
1600 for (j = 0; j < mrioc->req_qinfo[q_idx].num_segments; j++) {
1601 if (!segments[j].segment)
1603 dma_free_coherent(&mrioc->pdev->dev,
1604 size, segments[j].segment, segments[j].segment_dma);
1605 segments[j].segment = NULL;
1607 kfree(mrioc->req_qinfo[q_idx].q_segments);
1608 mrioc->req_qinfo[q_idx].q_segments = NULL;
1609 mrioc->req_qinfo[q_idx].qid = 0;
1613 * mpi3mr_free_op_reply_q_segments - free reply memory segments
1614 * @mrioc: Adapter instance reference
1615 * @q_idx: operational reply queue index
1617 * Free memory segments allocated for operational reply queue
1621 static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1625 struct segments *segments;
1627 segments = mrioc->op_reply_qinfo[q_idx].q_segments;
1631 if (mrioc->enable_segqueue) {
1632 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1633 if (mrioc->op_reply_qinfo[q_idx].q_segment_list) {
1634 dma_free_coherent(&mrioc->pdev->dev,
1635 MPI3MR_MAX_SEG_LIST_SIZE,
1636 mrioc->op_reply_qinfo[q_idx].q_segment_list,
1637 mrioc->op_reply_qinfo[q_idx].q_segment_list_dma);
1638 mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
1641 size = mrioc->op_reply_qinfo[q_idx].segment_qd *
1642 mrioc->op_reply_desc_sz;
1644 for (j = 0; j < mrioc->op_reply_qinfo[q_idx].num_segments; j++) {
1645 if (!segments[j].segment)
1647 dma_free_coherent(&mrioc->pdev->dev,
1648 size, segments[j].segment, segments[j].segment_dma);
1649 segments[j].segment = NULL;
1652 kfree(mrioc->op_reply_qinfo[q_idx].q_segments);
1653 mrioc->op_reply_qinfo[q_idx].q_segments = NULL;
1654 mrioc->op_reply_qinfo[q_idx].qid = 0;
1658 * mpi3mr_delete_op_reply_q - delete operational reply queue
1659 * @mrioc: Adapter instance reference
1660 * @qidx: operational reply queue index
1662 * Delete operatinal reply queue by issuing MPI request
1663 * through admin queue.
1665 * Return: 0 on success, non-zero on failure.
1667 static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1669 struct mpi3_delete_reply_queue_request delq_req;
1670 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1672 u16 reply_qid = 0, midx;
1674 reply_qid = op_reply_q->qid;
1676 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1680 ioc_err(mrioc, "Issue DelRepQ: called with invalid ReqQID\n");
1684 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount-- :
1685 mrioc->active_poll_qcount--;
1687 memset(&delq_req, 0, sizeof(delq_req));
1688 mutex_lock(&mrioc->init_cmds.mutex);
1689 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1691 ioc_err(mrioc, "Issue DelRepQ: Init command is in use\n");
1692 mutex_unlock(&mrioc->init_cmds.mutex);
1695 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1696 mrioc->init_cmds.is_waiting = 1;
1697 mrioc->init_cmds.callback = NULL;
1698 delq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1699 delq_req.function = MPI3_FUNCTION_DELETE_REPLY_QUEUE;
1700 delq_req.queue_id = cpu_to_le16(reply_qid);
1702 init_completion(&mrioc->init_cmds.done);
1703 retval = mpi3mr_admin_request_post(mrioc, &delq_req, sizeof(delq_req),
1706 ioc_err(mrioc, "Issue DelRepQ: Admin Post failed\n");
1709 wait_for_completion_timeout(&mrioc->init_cmds.done,
1710 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1711 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1712 ioc_err(mrioc, "delete reply queue timed out\n");
1713 mpi3mr_check_rh_fault_ioc(mrioc,
1714 MPI3MR_RESET_FROM_DELREPQ_TIMEOUT);
1718 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1719 != MPI3_IOCSTATUS_SUCCESS) {
1721 "Issue DelRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1722 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1723 mrioc->init_cmds.ioc_loginfo);
1727 mrioc->intr_info[midx].op_reply_q = NULL;
1729 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1731 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1732 mutex_unlock(&mrioc->init_cmds.mutex);
1739 * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
1740 * @mrioc: Adapter instance reference
1741 * @qidx: request queue index
1743 * Allocate segmented memory pools for operational reply
1746 * Return: 0 on success, non-zero on failure.
1748 static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1750 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1752 u64 *q_segment_list_entry = NULL;
1753 struct segments *segments;
1755 if (mrioc->enable_segqueue) {
1756 op_reply_q->segment_qd =
1757 MPI3MR_OP_REP_Q_SEG_SIZE / mrioc->op_reply_desc_sz;
1759 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1761 op_reply_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1762 MPI3MR_MAX_SEG_LIST_SIZE, &op_reply_q->q_segment_list_dma,
1764 if (!op_reply_q->q_segment_list)
1766 q_segment_list_entry = (u64 *)op_reply_q->q_segment_list;
1768 op_reply_q->segment_qd = op_reply_q->num_replies;
1769 size = op_reply_q->num_replies * mrioc->op_reply_desc_sz;
1772 op_reply_q->num_segments = DIV_ROUND_UP(op_reply_q->num_replies,
1773 op_reply_q->segment_qd);
1775 op_reply_q->q_segments = kcalloc(op_reply_q->num_segments,
1776 sizeof(struct segments), GFP_KERNEL);
1777 if (!op_reply_q->q_segments)
1780 segments = op_reply_q->q_segments;
1781 for (i = 0; i < op_reply_q->num_segments; i++) {
1782 segments[i].segment =
1783 dma_alloc_coherent(&mrioc->pdev->dev,
1784 size, &segments[i].segment_dma, GFP_KERNEL);
1785 if (!segments[i].segment)
1787 if (mrioc->enable_segqueue)
1788 q_segment_list_entry[i] =
1789 (unsigned long)segments[i].segment_dma;
1796 * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
1797 * @mrioc: Adapter instance reference
1798 * @qidx: request queue index
1800 * Allocate segmented memory pools for operational request
1803 * Return: 0 on success, non-zero on failure.
1805 static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1807 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
1809 u64 *q_segment_list_entry = NULL;
1810 struct segments *segments;
1812 if (mrioc->enable_segqueue) {
1813 op_req_q->segment_qd =
1814 MPI3MR_OP_REQ_Q_SEG_SIZE / mrioc->facts.op_req_sz;
1816 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1818 op_req_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1819 MPI3MR_MAX_SEG_LIST_SIZE, &op_req_q->q_segment_list_dma,
1821 if (!op_req_q->q_segment_list)
1823 q_segment_list_entry = (u64 *)op_req_q->q_segment_list;
1826 op_req_q->segment_qd = op_req_q->num_requests;
1827 size = op_req_q->num_requests * mrioc->facts.op_req_sz;
1830 op_req_q->num_segments = DIV_ROUND_UP(op_req_q->num_requests,
1831 op_req_q->segment_qd);
1833 op_req_q->q_segments = kcalloc(op_req_q->num_segments,
1834 sizeof(struct segments), GFP_KERNEL);
1835 if (!op_req_q->q_segments)
1838 segments = op_req_q->q_segments;
1839 for (i = 0; i < op_req_q->num_segments; i++) {
1840 segments[i].segment =
1841 dma_alloc_coherent(&mrioc->pdev->dev,
1842 size, &segments[i].segment_dma, GFP_KERNEL);
1843 if (!segments[i].segment)
1845 if (mrioc->enable_segqueue)
1846 q_segment_list_entry[i] =
1847 (unsigned long)segments[i].segment_dma;
1854 * mpi3mr_create_op_reply_q - create operational reply queue
1855 * @mrioc: Adapter instance reference
1856 * @qidx: operational reply queue index
1858 * Create operatinal reply queue by issuing MPI request
1859 * through admin queue.
1861 * Return: 0 on success, non-zero on failure.
1863 static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1865 struct mpi3_create_reply_queue_request create_req;
1866 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1868 u16 reply_qid = 0, midx;
1870 reply_qid = op_reply_q->qid;
1872 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1876 ioc_err(mrioc, "CreateRepQ: called for duplicate qid %d\n",
1882 reply_qid = qidx + 1;
1883 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
1884 if (!mrioc->pdev->revision)
1885 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD4K;
1887 op_reply_q->ephase = 1;
1888 atomic_set(&op_reply_q->pend_ios, 0);
1889 atomic_set(&op_reply_q->in_use, 0);
1890 op_reply_q->enable_irq_poll = false;
1892 if (!op_reply_q->q_segments) {
1893 retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
1895 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1900 memset(&create_req, 0, sizeof(create_req));
1901 mutex_lock(&mrioc->init_cmds.mutex);
1902 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1904 ioc_err(mrioc, "CreateRepQ: Init command is in use\n");
1907 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1908 mrioc->init_cmds.is_waiting = 1;
1909 mrioc->init_cmds.callback = NULL;
1910 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1911 create_req.function = MPI3_FUNCTION_CREATE_REPLY_QUEUE;
1912 create_req.queue_id = cpu_to_le16(reply_qid);
1914 if (midx < (mrioc->intr_info_count - mrioc->requested_poll_qcount))
1915 op_reply_q->qtype = MPI3MR_DEFAULT_QUEUE;
1917 op_reply_q->qtype = MPI3MR_POLL_QUEUE;
1919 if (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) {
1921 MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE;
1922 create_req.msix_index =
1923 cpu_to_le16(mrioc->intr_info[midx].msix_index);
1925 create_req.msix_index = cpu_to_le16(mrioc->intr_info_count - 1);
1926 ioc_info(mrioc, "create reply queue(polled): for qid(%d), midx(%d)\n",
1928 if (!mrioc->active_poll_qcount)
1929 disable_irq_nosync(pci_irq_vector(mrioc->pdev,
1930 mrioc->intr_info_count - 1));
1933 if (mrioc->enable_segqueue) {
1935 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
1936 create_req.base_address = cpu_to_le64(
1937 op_reply_q->q_segment_list_dma);
1939 create_req.base_address = cpu_to_le64(
1940 op_reply_q->q_segments[0].segment_dma);
1942 create_req.size = cpu_to_le16(op_reply_q->num_replies);
1944 init_completion(&mrioc->init_cmds.done);
1945 retval = mpi3mr_admin_request_post(mrioc, &create_req,
1946 sizeof(create_req), 1);
1948 ioc_err(mrioc, "CreateRepQ: Admin Post failed\n");
1951 wait_for_completion_timeout(&mrioc->init_cmds.done,
1952 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1953 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1954 ioc_err(mrioc, "create reply queue timed out\n");
1955 mpi3mr_check_rh_fault_ioc(mrioc,
1956 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT);
1960 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1961 != MPI3_IOCSTATUS_SUCCESS) {
1963 "CreateRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1964 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1965 mrioc->init_cmds.ioc_loginfo);
1969 op_reply_q->qid = reply_qid;
1970 if (midx < mrioc->intr_info_count)
1971 mrioc->intr_info[midx].op_reply_q = op_reply_q;
1973 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount++ :
1974 mrioc->active_poll_qcount++;
1977 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1978 mutex_unlock(&mrioc->init_cmds.mutex);
1985 * mpi3mr_create_op_req_q - create operational request queue
1986 * @mrioc: Adapter instance reference
1987 * @idx: operational request queue index
1988 * @reply_qid: Reply queue ID
1990 * Create operatinal request queue by issuing MPI request
1991 * through admin queue.
1993 * Return: 0 on success, non-zero on failure.
1995 static int mpi3mr_create_op_req_q(struct mpi3mr_ioc *mrioc, u16 idx,
1998 struct mpi3_create_request_queue_request create_req;
1999 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + idx;
2003 req_qid = op_req_q->qid;
2007 ioc_err(mrioc, "CreateReqQ: called for duplicate qid %d\n",
2014 op_req_q->num_requests = MPI3MR_OP_REQ_Q_QD;
2017 op_req_q->reply_qid = reply_qid;
2018 spin_lock_init(&op_req_q->q_lock);
2020 if (!op_req_q->q_segments) {
2021 retval = mpi3mr_alloc_op_req_q_segments(mrioc, idx);
2023 mpi3mr_free_op_req_q_segments(mrioc, idx);
2028 memset(&create_req, 0, sizeof(create_req));
2029 mutex_lock(&mrioc->init_cmds.mutex);
2030 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2032 ioc_err(mrioc, "CreateReqQ: Init command is in use\n");
2035 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2036 mrioc->init_cmds.is_waiting = 1;
2037 mrioc->init_cmds.callback = NULL;
2038 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2039 create_req.function = MPI3_FUNCTION_CREATE_REQUEST_QUEUE;
2040 create_req.queue_id = cpu_to_le16(req_qid);
2041 if (mrioc->enable_segqueue) {
2043 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
2044 create_req.base_address = cpu_to_le64(
2045 op_req_q->q_segment_list_dma);
2047 create_req.base_address = cpu_to_le64(
2048 op_req_q->q_segments[0].segment_dma);
2049 create_req.reply_queue_id = cpu_to_le16(reply_qid);
2050 create_req.size = cpu_to_le16(op_req_q->num_requests);
2052 init_completion(&mrioc->init_cmds.done);
2053 retval = mpi3mr_admin_request_post(mrioc, &create_req,
2054 sizeof(create_req), 1);
2056 ioc_err(mrioc, "CreateReqQ: Admin Post failed\n");
2059 wait_for_completion_timeout(&mrioc->init_cmds.done,
2060 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2061 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2062 ioc_err(mrioc, "create request queue timed out\n");
2063 mpi3mr_check_rh_fault_ioc(mrioc,
2064 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT);
2068 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2069 != MPI3_IOCSTATUS_SUCCESS) {
2071 "CreateReqQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2072 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2073 mrioc->init_cmds.ioc_loginfo);
2077 op_req_q->qid = req_qid;
2080 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2081 mutex_unlock(&mrioc->init_cmds.mutex);
2088 * mpi3mr_create_op_queues - create operational queue pairs
2089 * @mrioc: Adapter instance reference
2091 * Allocate memory for operational queue meta data and call
2092 * create request and reply queue functions.
2094 * Return: 0 on success, non-zero on failures.
2096 static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
2099 u16 num_queues = 0, i = 0, msix_count_op_q = 1;
2101 num_queues = min_t(int, mrioc->facts.max_op_reply_q,
2102 mrioc->facts.max_op_req_q);
2105 mrioc->intr_info_count - mrioc->op_reply_q_offset;
2106 if (!mrioc->num_queues)
2107 mrioc->num_queues = min_t(int, num_queues, msix_count_op_q);
2109 * During reset set the num_queues to the number of queues
2110 * that was set before the reset.
2112 num_queues = mrioc->num_op_reply_q ?
2113 mrioc->num_op_reply_q : mrioc->num_queues;
2114 ioc_info(mrioc, "trying to create %d operational queue pairs\n",
2117 if (!mrioc->req_qinfo) {
2118 mrioc->req_qinfo = kcalloc(num_queues,
2119 sizeof(struct op_req_qinfo), GFP_KERNEL);
2120 if (!mrioc->req_qinfo) {
2125 mrioc->op_reply_qinfo = kzalloc(sizeof(struct op_reply_qinfo) *
2126 num_queues, GFP_KERNEL);
2127 if (!mrioc->op_reply_qinfo) {
2133 if (mrioc->enable_segqueue)
2135 "allocating operational queues through segmented queues\n");
2137 for (i = 0; i < num_queues; i++) {
2138 if (mpi3mr_create_op_reply_q(mrioc, i)) {
2139 ioc_err(mrioc, "Cannot create OP RepQ %d\n", i);
2142 if (mpi3mr_create_op_req_q(mrioc, i,
2143 mrioc->op_reply_qinfo[i].qid)) {
2144 ioc_err(mrioc, "Cannot create OP ReqQ %d\n", i);
2145 mpi3mr_delete_op_reply_q(mrioc, i);
2151 /* Not even one queue is created successfully*/
2155 mrioc->num_op_reply_q = mrioc->num_op_req_q = i;
2157 "successfully created %d operational queue pairs(default/polled) queue = (%d/%d)\n",
2158 mrioc->num_op_reply_q, mrioc->default_qcount,
2159 mrioc->active_poll_qcount);
2163 kfree(mrioc->req_qinfo);
2164 mrioc->req_qinfo = NULL;
2166 kfree(mrioc->op_reply_qinfo);
2167 mrioc->op_reply_qinfo = NULL;
2173 * mpi3mr_op_request_post - Post request to operational queue
2174 * @mrioc: Adapter reference
2175 * @op_req_q: Operational request queue info
2176 * @req: MPI3 request
2178 * Post the MPI3 request into operational request queue and
2179 * inform the controller, if the queue is full return
2180 * appropriate error.
2182 * Return: 0 on success, non-zero on failure.
2184 int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
2185 struct op_req_qinfo *op_req_q, u8 *req)
2187 u16 pi = 0, max_entries, reply_qidx = 0, midx;
2189 unsigned long flags;
2191 void *segment_base_addr;
2192 u16 req_sz = mrioc->facts.op_req_sz;
2193 struct segments *segments = op_req_q->q_segments;
2195 reply_qidx = op_req_q->reply_qid - 1;
2197 if (mrioc->unrecoverable)
2200 spin_lock_irqsave(&op_req_q->q_lock, flags);
2202 max_entries = op_req_q->num_requests;
2204 if (mpi3mr_check_req_qfull(op_req_q)) {
2205 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
2206 reply_qidx, mrioc->op_reply_q_offset);
2207 mpi3mr_process_op_reply_q(mrioc, mrioc->intr_info[midx].op_reply_q);
2209 if (mpi3mr_check_req_qfull(op_req_q)) {
2215 if (mrioc->reset_in_progress) {
2216 ioc_err(mrioc, "OpReqQ submit reset in progress\n");
2221 segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
2222 req_entry = (u8 *)segment_base_addr +
2223 ((pi % op_req_q->segment_qd) * req_sz);
2225 memset(req_entry, 0, req_sz);
2226 memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
2228 if (++pi == max_entries)
2232 #ifndef CONFIG_PREEMPT_RT
2233 if (atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios)
2234 > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT)
2235 mrioc->op_reply_qinfo[reply_qidx].enable_irq_poll = true;
2237 atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios);
2240 writel(op_req_q->pi,
2241 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].producer_index);
2244 spin_unlock_irqrestore(&op_req_q->q_lock, flags);
2249 * mpi3mr_check_rh_fault_ioc - check reset history and fault
2251 * @mrioc: Adapter instance reference
2252 * @reason_code: reason code for the fault.
2254 * This routine will save snapdump and fault the controller with
2255 * the given reason code if it is not already in the fault or
2256 * not asynchronosuly reset. This will be used to handle
2257 * initilaization time faults/resets/timeout as in those cases
2258 * immediate soft reset invocation is not required.
2262 void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code)
2264 u32 ioc_status, host_diagnostic, timeout;
2266 if (mrioc->unrecoverable) {
2267 ioc_err(mrioc, "controller is unrecoverable\n");
2271 if (!pci_device_is_present(mrioc->pdev)) {
2272 mrioc->unrecoverable = 1;
2273 ioc_err(mrioc, "controller is not present\n");
2277 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2278 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
2279 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
2280 mpi3mr_print_fault_info(mrioc);
2283 mpi3mr_set_diagsave(mrioc);
2284 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
2286 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
2288 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2289 if (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
2292 } while (--timeout);
2296 * mpi3mr_sync_timestamp - Issue time stamp sync request
2297 * @mrioc: Adapter reference
2299 * Issue IO unit control MPI request to synchornize firmware
2300 * timestamp with host time.
2302 * Return: 0 on success, non-zero on failure.
2304 static int mpi3mr_sync_timestamp(struct mpi3mr_ioc *mrioc)
2306 ktime_t current_time;
2307 struct mpi3_iounit_control_request iou_ctrl;
2310 memset(&iou_ctrl, 0, sizeof(iou_ctrl));
2311 mutex_lock(&mrioc->init_cmds.mutex);
2312 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2314 ioc_err(mrioc, "Issue IOUCTL time_stamp: command is in use\n");
2315 mutex_unlock(&mrioc->init_cmds.mutex);
2318 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2319 mrioc->init_cmds.is_waiting = 1;
2320 mrioc->init_cmds.callback = NULL;
2321 iou_ctrl.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2322 iou_ctrl.function = MPI3_FUNCTION_IO_UNIT_CONTROL;
2323 iou_ctrl.operation = MPI3_CTRL_OP_UPDATE_TIMESTAMP;
2324 current_time = ktime_get_real();
2325 iou_ctrl.param64[0] = cpu_to_le64(ktime_to_ms(current_time));
2327 init_completion(&mrioc->init_cmds.done);
2328 retval = mpi3mr_admin_request_post(mrioc, &iou_ctrl,
2329 sizeof(iou_ctrl), 0);
2331 ioc_err(mrioc, "Issue IOUCTL time_stamp: Admin Post failed\n");
2335 wait_for_completion_timeout(&mrioc->init_cmds.done,
2336 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2337 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2338 ioc_err(mrioc, "Issue IOUCTL time_stamp: command timed out\n");
2339 mrioc->init_cmds.is_waiting = 0;
2340 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
2341 mpi3mr_soft_reset_handler(mrioc,
2342 MPI3MR_RESET_FROM_TSU_TIMEOUT, 1);
2346 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2347 != MPI3_IOCSTATUS_SUCCESS) {
2349 "Issue IOUCTL time_stamp: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2350 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2351 mrioc->init_cmds.ioc_loginfo);
2357 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2358 mutex_unlock(&mrioc->init_cmds.mutex);
2365 * mpi3mr_print_pkg_ver - display controller fw package version
2366 * @mrioc: Adapter reference
2368 * Retrieve firmware package version from the component image
2369 * header of the controller flash and display it.
2371 * Return: 0 on success and non-zero on failure.
2373 static int mpi3mr_print_pkg_ver(struct mpi3mr_ioc *mrioc)
2375 struct mpi3_ci_upload_request ci_upload;
2378 dma_addr_t data_dma;
2379 struct mpi3_ci_manifest_mpi *manifest;
2380 u32 data_len = sizeof(struct mpi3_ci_manifest_mpi);
2381 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2383 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2388 memset(&ci_upload, 0, sizeof(ci_upload));
2389 mutex_lock(&mrioc->init_cmds.mutex);
2390 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2391 ioc_err(mrioc, "sending get package version failed due to command in use\n");
2392 mutex_unlock(&mrioc->init_cmds.mutex);
2395 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2396 mrioc->init_cmds.is_waiting = 1;
2397 mrioc->init_cmds.callback = NULL;
2398 ci_upload.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2399 ci_upload.function = MPI3_FUNCTION_CI_UPLOAD;
2400 ci_upload.msg_flags = MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY;
2401 ci_upload.signature1 = cpu_to_le32(MPI3_IMAGE_HEADER_SIGNATURE1_MANIFEST);
2402 ci_upload.image_offset = cpu_to_le32(MPI3_IMAGE_HEADER_SIZE);
2403 ci_upload.segment_size = cpu_to_le32(data_len);
2405 mpi3mr_add_sg_single(&ci_upload.sgl, sgl_flags, data_len,
2407 init_completion(&mrioc->init_cmds.done);
2408 retval = mpi3mr_admin_request_post(mrioc, &ci_upload,
2409 sizeof(ci_upload), 1);
2411 ioc_err(mrioc, "posting get package version failed\n");
2414 wait_for_completion_timeout(&mrioc->init_cmds.done,
2415 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2416 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2417 ioc_err(mrioc, "get package version timed out\n");
2418 mpi3mr_check_rh_fault_ioc(mrioc,
2419 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT);
2423 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2424 == MPI3_IOCSTATUS_SUCCESS) {
2425 manifest = (struct mpi3_ci_manifest_mpi *) data;
2426 if (manifest->manifest_type == MPI3_CI_MANIFEST_TYPE_MPI) {
2428 "firmware package version(%d.%d.%d.%d.%05d-%05d)\n",
2429 manifest->package_version.gen_major,
2430 manifest->package_version.gen_minor,
2431 manifest->package_version.phase_major,
2432 manifest->package_version.phase_minor,
2433 manifest->package_version.customer_id,
2434 manifest->package_version.build_num);
2439 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2440 mutex_unlock(&mrioc->init_cmds.mutex);
2444 dma_free_coherent(&mrioc->pdev->dev, data_len, data,
2450 * mpi3mr_watchdog_work - watchdog thread to monitor faults
2451 * @work: work struct
2453 * Watch dog work periodically executed (1 second interval) to
2454 * monitor firmware fault and to issue periodic timer sync to
2459 static void mpi3mr_watchdog_work(struct work_struct *work)
2461 struct mpi3mr_ioc *mrioc =
2462 container_of(work, struct mpi3mr_ioc, watchdog_work.work);
2463 unsigned long flags;
2464 enum mpi3mr_iocstate ioc_state;
2465 u32 fault, host_diagnostic, ioc_status;
2466 u32 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
2468 if (mrioc->reset_in_progress)
2471 if (!mrioc->unrecoverable && !pci_device_is_present(mrioc->pdev)) {
2472 ioc_err(mrioc, "watchdog could not detect the controller\n");
2473 mrioc->unrecoverable = 1;
2476 if (mrioc->unrecoverable) {
2478 "flush pending commands for unrecoverable controller\n");
2479 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
2483 if (mrioc->ts_update_counter++ >= MPI3MR_TSUPDATE_INTERVAL) {
2484 mrioc->ts_update_counter = 0;
2485 mpi3mr_sync_timestamp(mrioc);
2488 if ((mrioc->prepare_for_reset) &&
2489 ((mrioc->prepare_for_reset_timeout_counter++) >=
2490 MPI3MR_PREPARE_FOR_RESET_TIMEOUT)) {
2491 mpi3mr_soft_reset_handler(mrioc,
2492 MPI3MR_RESET_FROM_CIACTVRST_TIMER, 1);
2496 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2497 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
2498 mpi3mr_soft_reset_handler(mrioc, MPI3MR_RESET_FROM_FIRMWARE, 0);
2502 /*Check for fault state every one second and issue Soft reset*/
2503 ioc_state = mpi3mr_get_iocstate(mrioc);
2504 if (ioc_state != MRIOC_STATE_FAULT)
2507 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
2508 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2509 if (host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS) {
2510 if (!mrioc->diagsave_timeout) {
2511 mpi3mr_print_fault_info(mrioc);
2512 ioc_warn(mrioc, "diag save in progress\n");
2514 if ((mrioc->diagsave_timeout++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT)
2518 mpi3mr_print_fault_info(mrioc);
2519 mrioc->diagsave_timeout = 0;
2522 case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED:
2523 case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED:
2525 "controller requires system power cycle, marking controller as unrecoverable\n");
2526 mrioc->unrecoverable = 1;
2528 case MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS:
2530 case MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET:
2531 reset_reason = MPI3MR_RESET_FROM_CIACTIV_FAULT;
2536 mpi3mr_soft_reset_handler(mrioc, reset_reason, 0);
2540 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2541 if (mrioc->watchdog_work_q)
2542 queue_delayed_work(mrioc->watchdog_work_q,
2543 &mrioc->watchdog_work,
2544 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2545 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2550 * mpi3mr_start_watchdog - Start watchdog
2551 * @mrioc: Adapter instance reference
2553 * Create and start the watchdog thread to monitor controller
2558 void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc)
2560 if (mrioc->watchdog_work_q)
2563 INIT_DELAYED_WORK(&mrioc->watchdog_work, mpi3mr_watchdog_work);
2564 snprintf(mrioc->watchdog_work_q_name,
2565 sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
2567 mrioc->watchdog_work_q =
2568 create_singlethread_workqueue(mrioc->watchdog_work_q_name);
2569 if (!mrioc->watchdog_work_q) {
2570 ioc_err(mrioc, "%s: failed (line=%d)\n", __func__, __LINE__);
2574 if (mrioc->watchdog_work_q)
2575 queue_delayed_work(mrioc->watchdog_work_q,
2576 &mrioc->watchdog_work,
2577 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2581 * mpi3mr_stop_watchdog - Stop watchdog
2582 * @mrioc: Adapter instance reference
2584 * Stop the watchdog thread created to monitor controller
2589 void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc)
2591 unsigned long flags;
2592 struct workqueue_struct *wq;
2594 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2595 wq = mrioc->watchdog_work_q;
2596 mrioc->watchdog_work_q = NULL;
2597 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2599 if (!cancel_delayed_work_sync(&mrioc->watchdog_work))
2600 flush_workqueue(wq);
2601 destroy_workqueue(wq);
2606 * mpi3mr_setup_admin_qpair - Setup admin queue pair
2607 * @mrioc: Adapter instance reference
2609 * Allocate memory for admin queue pair if required and register
2610 * the admin queue with the controller.
2612 * Return: 0 on success, non-zero on failures.
2614 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
2617 u32 num_admin_entries = 0;
2619 mrioc->admin_req_q_sz = MPI3MR_ADMIN_REQ_Q_SIZE;
2620 mrioc->num_admin_req = mrioc->admin_req_q_sz /
2621 MPI3MR_ADMIN_REQ_FRAME_SZ;
2622 mrioc->admin_req_ci = mrioc->admin_req_pi = 0;
2623 mrioc->admin_req_base = NULL;
2625 mrioc->admin_reply_q_sz = MPI3MR_ADMIN_REPLY_Q_SIZE;
2626 mrioc->num_admin_replies = mrioc->admin_reply_q_sz /
2627 MPI3MR_ADMIN_REPLY_FRAME_SZ;
2628 mrioc->admin_reply_ci = 0;
2629 mrioc->admin_reply_ephase = 1;
2630 mrioc->admin_reply_base = NULL;
2631 atomic_set(&mrioc->admin_reply_q_in_use, 0);
2633 if (!mrioc->admin_req_base) {
2634 mrioc->admin_req_base = dma_alloc_coherent(&mrioc->pdev->dev,
2635 mrioc->admin_req_q_sz, &mrioc->admin_req_dma, GFP_KERNEL);
2637 if (!mrioc->admin_req_base) {
2642 mrioc->admin_reply_base = dma_alloc_coherent(&mrioc->pdev->dev,
2643 mrioc->admin_reply_q_sz, &mrioc->admin_reply_dma,
2646 if (!mrioc->admin_reply_base) {
2652 num_admin_entries = (mrioc->num_admin_replies << 16) |
2653 (mrioc->num_admin_req);
2654 writel(num_admin_entries, &mrioc->sysif_regs->admin_queue_num_entries);
2655 mpi3mr_writeq(mrioc->admin_req_dma,
2656 &mrioc->sysif_regs->admin_request_queue_address);
2657 mpi3mr_writeq(mrioc->admin_reply_dma,
2658 &mrioc->sysif_regs->admin_reply_queue_address);
2659 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
2660 writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
2665 if (mrioc->admin_reply_base) {
2666 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
2667 mrioc->admin_reply_base, mrioc->admin_reply_dma);
2668 mrioc->admin_reply_base = NULL;
2670 if (mrioc->admin_req_base) {
2671 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
2672 mrioc->admin_req_base, mrioc->admin_req_dma);
2673 mrioc->admin_req_base = NULL;
2679 * mpi3mr_issue_iocfacts - Send IOC Facts
2680 * @mrioc: Adapter instance reference
2681 * @facts_data: Cached IOC facts data
2683 * Issue IOC Facts MPI request through admin queue and wait for
2684 * the completion of it or time out.
2686 * Return: 0 on success, non-zero on failures.
2688 static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc *mrioc,
2689 struct mpi3_ioc_facts_data *facts_data)
2691 struct mpi3_ioc_facts_request iocfacts_req;
2693 dma_addr_t data_dma;
2694 u32 data_len = sizeof(*facts_data);
2696 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2698 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2706 memset(&iocfacts_req, 0, sizeof(iocfacts_req));
2707 mutex_lock(&mrioc->init_cmds.mutex);
2708 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2710 ioc_err(mrioc, "Issue IOCFacts: Init command is in use\n");
2711 mutex_unlock(&mrioc->init_cmds.mutex);
2714 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2715 mrioc->init_cmds.is_waiting = 1;
2716 mrioc->init_cmds.callback = NULL;
2717 iocfacts_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2718 iocfacts_req.function = MPI3_FUNCTION_IOC_FACTS;
2720 mpi3mr_add_sg_single(&iocfacts_req.sgl, sgl_flags, data_len,
2723 init_completion(&mrioc->init_cmds.done);
2724 retval = mpi3mr_admin_request_post(mrioc, &iocfacts_req,
2725 sizeof(iocfacts_req), 1);
2727 ioc_err(mrioc, "Issue IOCFacts: Admin Post failed\n");
2730 wait_for_completion_timeout(&mrioc->init_cmds.done,
2731 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2732 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2733 ioc_err(mrioc, "ioc_facts timed out\n");
2734 mpi3mr_check_rh_fault_ioc(mrioc,
2735 MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT);
2739 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2740 != MPI3_IOCSTATUS_SUCCESS) {
2742 "Issue IOCFacts: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2743 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2744 mrioc->init_cmds.ioc_loginfo);
2748 memcpy(facts_data, (u8 *)data, data_len);
2749 mpi3mr_process_factsdata(mrioc, facts_data);
2751 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2752 mutex_unlock(&mrioc->init_cmds.mutex);
2756 dma_free_coherent(&mrioc->pdev->dev, data_len, data, data_dma);
2762 * mpi3mr_check_reset_dma_mask - Process IOC facts data
2763 * @mrioc: Adapter instance reference
2765 * Check whether the new DMA mask requested through IOCFacts by
2766 * firmware needs to be set, if so set it .
2768 * Return: 0 on success, non-zero on failure.
2770 static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc *mrioc)
2772 struct pci_dev *pdev = mrioc->pdev;
2774 u64 facts_dma_mask = DMA_BIT_MASK(mrioc->facts.dma_mask);
2776 if (!mrioc->facts.dma_mask || (mrioc->dma_mask <= facts_dma_mask))
2779 ioc_info(mrioc, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
2780 mrioc->dma_mask, facts_dma_mask);
2782 r = dma_set_mask_and_coherent(&pdev->dev, facts_dma_mask);
2784 ioc_err(mrioc, "Setting DMA mask to 0x%016llx failed: %d\n",
2788 mrioc->dma_mask = facts_dma_mask;
2793 * mpi3mr_process_factsdata - Process IOC facts data
2794 * @mrioc: Adapter instance reference
2795 * @facts_data: Cached IOC facts data
2797 * Convert IOC facts data into cpu endianness and cache it in
2802 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
2803 struct mpi3_ioc_facts_data *facts_data)
2805 u32 ioc_config, req_sz, facts_flags;
2807 if ((le16_to_cpu(facts_data->ioc_facts_data_length)) !=
2808 (sizeof(*facts_data) / 4)) {
2810 "IOCFactsdata length mismatch driver_sz(%zu) firmware_sz(%d)\n",
2811 sizeof(*facts_data),
2812 le16_to_cpu(facts_data->ioc_facts_data_length) * 4);
2815 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
2816 req_sz = 1 << ((ioc_config & MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ) >>
2817 MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT);
2818 if (le16_to_cpu(facts_data->ioc_request_frame_size) != (req_sz / 4)) {
2820 "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
2821 req_sz / 4, le16_to_cpu(facts_data->ioc_request_frame_size));
2824 memset(&mrioc->facts, 0, sizeof(mrioc->facts));
2826 facts_flags = le32_to_cpu(facts_data->flags);
2827 mrioc->facts.op_req_sz = req_sz;
2828 mrioc->op_reply_desc_sz = 1 << ((ioc_config &
2829 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ) >>
2830 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT);
2832 mrioc->facts.ioc_num = facts_data->ioc_number;
2833 mrioc->facts.who_init = facts_data->who_init;
2834 mrioc->facts.max_msix_vectors = le16_to_cpu(facts_data->max_msix_vectors);
2835 mrioc->facts.personality = (facts_flags &
2836 MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK);
2837 mrioc->facts.dma_mask = (facts_flags &
2838 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
2839 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
2840 mrioc->facts.protocol_flags = facts_data->protocol_flags;
2841 mrioc->facts.mpi_version = le32_to_cpu(facts_data->mpi_version.word);
2842 mrioc->facts.max_reqs = le16_to_cpu(facts_data->max_outstanding_requests);
2843 mrioc->facts.product_id = le16_to_cpu(facts_data->product_id);
2844 mrioc->facts.reply_sz = le16_to_cpu(facts_data->reply_frame_size) * 4;
2845 mrioc->facts.exceptions = le16_to_cpu(facts_data->ioc_exceptions);
2846 mrioc->facts.max_perids = le16_to_cpu(facts_data->max_persistent_id);
2847 mrioc->facts.max_vds = le16_to_cpu(facts_data->max_vds);
2848 mrioc->facts.max_hpds = le16_to_cpu(facts_data->max_host_pds);
2849 mrioc->facts.max_advhpds = le16_to_cpu(facts_data->max_adv_host_pds);
2850 mrioc->facts.max_raid_pds = le16_to_cpu(facts_data->max_raid_pds);
2851 mrioc->facts.max_nvme = le16_to_cpu(facts_data->max_nvme);
2852 mrioc->facts.max_pcie_switches =
2853 le16_to_cpu(facts_data->max_pcie_switches);
2854 mrioc->facts.max_sasexpanders =
2855 le16_to_cpu(facts_data->max_sas_expanders);
2856 mrioc->facts.max_sasinitiators =
2857 le16_to_cpu(facts_data->max_sas_initiators);
2858 mrioc->facts.max_enclosures = le16_to_cpu(facts_data->max_enclosures);
2859 mrioc->facts.min_devhandle = le16_to_cpu(facts_data->min_dev_handle);
2860 mrioc->facts.max_devhandle = le16_to_cpu(facts_data->max_dev_handle);
2861 mrioc->facts.max_op_req_q =
2862 le16_to_cpu(facts_data->max_operational_request_queues);
2863 mrioc->facts.max_op_reply_q =
2864 le16_to_cpu(facts_data->max_operational_reply_queues);
2865 mrioc->facts.ioc_capabilities =
2866 le32_to_cpu(facts_data->ioc_capabilities);
2867 mrioc->facts.fw_ver.build_num =
2868 le16_to_cpu(facts_data->fw_version.build_num);
2869 mrioc->facts.fw_ver.cust_id =
2870 le16_to_cpu(facts_data->fw_version.customer_id);
2871 mrioc->facts.fw_ver.ph_minor = facts_data->fw_version.phase_minor;
2872 mrioc->facts.fw_ver.ph_major = facts_data->fw_version.phase_major;
2873 mrioc->facts.fw_ver.gen_minor = facts_data->fw_version.gen_minor;
2874 mrioc->facts.fw_ver.gen_major = facts_data->fw_version.gen_major;
2875 mrioc->msix_count = min_t(int, mrioc->msix_count,
2876 mrioc->facts.max_msix_vectors);
2877 mrioc->facts.sge_mod_mask = facts_data->sge_modifier_mask;
2878 mrioc->facts.sge_mod_value = facts_data->sge_modifier_value;
2879 mrioc->facts.sge_mod_shift = facts_data->sge_modifier_shift;
2880 mrioc->facts.shutdown_timeout =
2881 le16_to_cpu(facts_data->shutdown_timeout);
2883 mrioc->facts.max_dev_per_tg =
2884 facts_data->max_devices_per_throttle_group;
2885 mrioc->facts.io_throttle_data_length =
2886 le16_to_cpu(facts_data->io_throttle_data_length);
2887 mrioc->facts.max_io_throttle_group =
2888 le16_to_cpu(facts_data->max_io_throttle_group);
2889 mrioc->facts.io_throttle_low = le16_to_cpu(facts_data->io_throttle_low);
2890 mrioc->facts.io_throttle_high =
2891 le16_to_cpu(facts_data->io_throttle_high);
2893 /* Store in 512b block count */
2894 if (mrioc->facts.io_throttle_data_length)
2895 mrioc->io_throttle_data_length =
2896 (mrioc->facts.io_throttle_data_length * 2 * 4);
2898 /* set the length to 1MB + 1K to disable throttle */
2899 mrioc->io_throttle_data_length = MPI3MR_MAX_SECTORS + 2;
2901 mrioc->io_throttle_high = (mrioc->facts.io_throttle_high * 2 * 1024);
2902 mrioc->io_throttle_low = (mrioc->facts.io_throttle_low * 2 * 1024);
2904 ioc_info(mrioc, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
2905 mrioc->facts.ioc_num, mrioc->facts.max_op_req_q,
2906 mrioc->facts.max_op_reply_q, mrioc->facts.max_devhandle);
2908 "maxreqs(%d), mindh(%d) maxvectors(%d) maxperids(%d)\n",
2909 mrioc->facts.max_reqs, mrioc->facts.min_devhandle,
2910 mrioc->facts.max_msix_vectors, mrioc->facts.max_perids);
2911 ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
2912 mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value,
2913 mrioc->facts.sge_mod_shift);
2914 ioc_info(mrioc, "DMA mask %d InitialPE status 0x%x\n",
2915 mrioc->facts.dma_mask, (facts_flags &
2916 MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK));
2918 "max_dev_per_throttle_group(%d), max_throttle_groups(%d)\n",
2919 mrioc->facts.max_dev_per_tg, mrioc->facts.max_io_throttle_group);
2921 "io_throttle_data_len(%dKiB), io_throttle_high(%dMiB), io_throttle_low(%dMiB)\n",
2922 mrioc->facts.io_throttle_data_length * 4,
2923 mrioc->facts.io_throttle_high, mrioc->facts.io_throttle_low);
2927 * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
2928 * @mrioc: Adapter instance reference
2930 * Allocate and initialize the reply free buffers, sense
2931 * buffers, reply free queue and sense buffer queue.
2933 * Return: 0 on success, non-zero on failures.
2935 static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
2940 if (mrioc->init_cmds.reply)
2943 mrioc->init_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2944 if (!mrioc->init_cmds.reply)
2947 mrioc->bsg_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2948 if (!mrioc->bsg_cmds.reply)
2951 mrioc->transport_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2952 if (!mrioc->transport_cmds.reply)
2955 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
2956 mrioc->dev_rmhs_cmds[i].reply = kzalloc(mrioc->reply_sz,
2958 if (!mrioc->dev_rmhs_cmds[i].reply)
2962 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
2963 mrioc->evtack_cmds[i].reply = kzalloc(mrioc->reply_sz,
2965 if (!mrioc->evtack_cmds[i].reply)
2969 mrioc->host_tm_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2970 if (!mrioc->host_tm_cmds.reply)
2973 mrioc->pel_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2974 if (!mrioc->pel_cmds.reply)
2977 mrioc->pel_abort_cmd.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2978 if (!mrioc->pel_abort_cmd.reply)
2981 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
2982 mrioc->removepend_bitmap = bitmap_zalloc(mrioc->dev_handle_bitmap_bits,
2984 if (!mrioc->removepend_bitmap)
2987 mrioc->devrem_bitmap = bitmap_zalloc(MPI3MR_NUM_DEVRMCMD, GFP_KERNEL);
2988 if (!mrioc->devrem_bitmap)
2991 mrioc->evtack_cmds_bitmap = bitmap_zalloc(MPI3MR_NUM_EVTACKCMD,
2993 if (!mrioc->evtack_cmds_bitmap)
2996 mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
2997 mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
2998 mrioc->num_sense_bufs = mrioc->facts.max_reqs / MPI3MR_SENSEBUF_FACTOR;
2999 mrioc->sense_buf_q_sz = mrioc->num_sense_bufs + 1;
3001 /* reply buffer pool, 16 byte align */
3002 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3003 mrioc->reply_buf_pool = dma_pool_create("reply_buf pool",
3004 &mrioc->pdev->dev, sz, 16, 0);
3005 if (!mrioc->reply_buf_pool) {
3006 ioc_err(mrioc, "reply buf pool: dma_pool_create failed\n");
3010 mrioc->reply_buf = dma_pool_zalloc(mrioc->reply_buf_pool, GFP_KERNEL,
3011 &mrioc->reply_buf_dma);
3012 if (!mrioc->reply_buf)
3015 mrioc->reply_buf_dma_max_address = mrioc->reply_buf_dma + sz;
3017 /* reply free queue, 8 byte align */
3018 sz = mrioc->reply_free_qsz * 8;
3019 mrioc->reply_free_q_pool = dma_pool_create("reply_free_q pool",
3020 &mrioc->pdev->dev, sz, 8, 0);
3021 if (!mrioc->reply_free_q_pool) {
3022 ioc_err(mrioc, "reply_free_q pool: dma_pool_create failed\n");
3025 mrioc->reply_free_q = dma_pool_zalloc(mrioc->reply_free_q_pool,
3026 GFP_KERNEL, &mrioc->reply_free_q_dma);
3027 if (!mrioc->reply_free_q)
3030 /* sense buffer pool, 4 byte align */
3031 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3032 mrioc->sense_buf_pool = dma_pool_create("sense_buf pool",
3033 &mrioc->pdev->dev, sz, 4, 0);
3034 if (!mrioc->sense_buf_pool) {
3035 ioc_err(mrioc, "sense_buf pool: dma_pool_create failed\n");
3038 mrioc->sense_buf = dma_pool_zalloc(mrioc->sense_buf_pool, GFP_KERNEL,
3039 &mrioc->sense_buf_dma);
3040 if (!mrioc->sense_buf)
3043 /* sense buffer queue, 8 byte align */
3044 sz = mrioc->sense_buf_q_sz * 8;
3045 mrioc->sense_buf_q_pool = dma_pool_create("sense_buf_q pool",
3046 &mrioc->pdev->dev, sz, 8, 0);
3047 if (!mrioc->sense_buf_q_pool) {
3048 ioc_err(mrioc, "sense_buf_q pool: dma_pool_create failed\n");
3051 mrioc->sense_buf_q = dma_pool_zalloc(mrioc->sense_buf_q_pool,
3052 GFP_KERNEL, &mrioc->sense_buf_q_dma);
3053 if (!mrioc->sense_buf_q)
3064 * mpimr_initialize_reply_sbuf_queues - initialize reply sense
3066 * @mrioc: Adapter instance reference
3068 * Helper function to initialize reply and sense buffers along
3069 * with some debug prints.
3073 static void mpimr_initialize_reply_sbuf_queues(struct mpi3mr_ioc *mrioc)
3076 dma_addr_t phy_addr;
3078 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3080 "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3081 mrioc->reply_buf, mrioc->num_reply_bufs, mrioc->reply_sz,
3082 (sz / 1024), (unsigned long long)mrioc->reply_buf_dma);
3083 sz = mrioc->reply_free_qsz * 8;
3085 "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3086 mrioc->reply_free_q, mrioc->reply_free_qsz, 8, (sz / 1024),
3087 (unsigned long long)mrioc->reply_free_q_dma);
3088 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3090 "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3091 mrioc->sense_buf, mrioc->num_sense_bufs, MPI3MR_SENSE_BUF_SZ,
3092 (sz / 1024), (unsigned long long)mrioc->sense_buf_dma);
3093 sz = mrioc->sense_buf_q_sz * 8;
3095 "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3096 mrioc->sense_buf_q, mrioc->sense_buf_q_sz, 8, (sz / 1024),
3097 (unsigned long long)mrioc->sense_buf_q_dma);
3099 /* initialize Reply buffer Queue */
3100 for (i = 0, phy_addr = mrioc->reply_buf_dma;
3101 i < mrioc->num_reply_bufs; i++, phy_addr += mrioc->reply_sz)
3102 mrioc->reply_free_q[i] = cpu_to_le64(phy_addr);
3103 mrioc->reply_free_q[i] = cpu_to_le64(0);
3105 /* initialize Sense Buffer Queue */
3106 for (i = 0, phy_addr = mrioc->sense_buf_dma;
3107 i < mrioc->num_sense_bufs; i++, phy_addr += MPI3MR_SENSE_BUF_SZ)
3108 mrioc->sense_buf_q[i] = cpu_to_le64(phy_addr);
3109 mrioc->sense_buf_q[i] = cpu_to_le64(0);
3113 * mpi3mr_issue_iocinit - Send IOC Init
3114 * @mrioc: Adapter instance reference
3116 * Issue IOC Init MPI request through admin queue and wait for
3117 * the completion of it or time out.
3119 * Return: 0 on success, non-zero on failures.
3121 static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
3123 struct mpi3_ioc_init_request iocinit_req;
3124 struct mpi3_driver_info_layout *drv_info;
3125 dma_addr_t data_dma;
3126 u32 data_len = sizeof(*drv_info);
3128 ktime_t current_time;
3130 drv_info = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
3136 mpimr_initialize_reply_sbuf_queues(mrioc);
3138 drv_info->information_length = cpu_to_le32(data_len);
3139 strscpy(drv_info->driver_signature, "Broadcom", sizeof(drv_info->driver_signature));
3140 strscpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));
3141 strscpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));
3142 strscpy(drv_info->driver_name, MPI3MR_DRIVER_NAME, sizeof(drv_info->driver_name));
3143 strscpy(drv_info->driver_version, MPI3MR_DRIVER_VERSION, sizeof(drv_info->driver_version));
3144 strscpy(drv_info->driver_release_date, MPI3MR_DRIVER_RELDATE,
3145 sizeof(drv_info->driver_release_date));
3146 drv_info->driver_capabilities = 0;
3147 memcpy((u8 *)&mrioc->driver_info, (u8 *)drv_info,
3148 sizeof(mrioc->driver_info));
3150 memset(&iocinit_req, 0, sizeof(iocinit_req));
3151 mutex_lock(&mrioc->init_cmds.mutex);
3152 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3154 ioc_err(mrioc, "Issue IOCInit: Init command is in use\n");
3155 mutex_unlock(&mrioc->init_cmds.mutex);
3158 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3159 mrioc->init_cmds.is_waiting = 1;
3160 mrioc->init_cmds.callback = NULL;
3161 iocinit_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3162 iocinit_req.function = MPI3_FUNCTION_IOC_INIT;
3163 iocinit_req.mpi_version.mpi3_version.dev = MPI3_VERSION_DEV;
3164 iocinit_req.mpi_version.mpi3_version.unit = MPI3_VERSION_UNIT;
3165 iocinit_req.mpi_version.mpi3_version.major = MPI3_VERSION_MAJOR;
3166 iocinit_req.mpi_version.mpi3_version.minor = MPI3_VERSION_MINOR;
3167 iocinit_req.who_init = MPI3_WHOINIT_HOST_DRIVER;
3168 iocinit_req.reply_free_queue_depth = cpu_to_le16(mrioc->reply_free_qsz);
3169 iocinit_req.reply_free_queue_address =
3170 cpu_to_le64(mrioc->reply_free_q_dma);
3171 iocinit_req.sense_buffer_length = cpu_to_le16(MPI3MR_SENSE_BUF_SZ);
3172 iocinit_req.sense_buffer_free_queue_depth =
3173 cpu_to_le16(mrioc->sense_buf_q_sz);
3174 iocinit_req.sense_buffer_free_queue_address =
3175 cpu_to_le64(mrioc->sense_buf_q_dma);
3176 iocinit_req.driver_information_address = cpu_to_le64(data_dma);
3178 current_time = ktime_get_real();
3179 iocinit_req.time_stamp = cpu_to_le64(ktime_to_ms(current_time));
3181 init_completion(&mrioc->init_cmds.done);
3182 retval = mpi3mr_admin_request_post(mrioc, &iocinit_req,
3183 sizeof(iocinit_req), 1);
3185 ioc_err(mrioc, "Issue IOCInit: Admin Post failed\n");
3188 wait_for_completion_timeout(&mrioc->init_cmds.done,
3189 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3190 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3191 mpi3mr_check_rh_fault_ioc(mrioc,
3192 MPI3MR_RESET_FROM_IOCINIT_TIMEOUT);
3193 ioc_err(mrioc, "ioc_init timed out\n");
3197 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3198 != MPI3_IOCSTATUS_SUCCESS) {
3200 "Issue IOCInit: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3201 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3202 mrioc->init_cmds.ioc_loginfo);
3207 mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
3208 writel(mrioc->reply_free_queue_host_index,
3209 &mrioc->sysif_regs->reply_free_host_index);
3211 mrioc->sbq_host_index = mrioc->num_sense_bufs;
3212 writel(mrioc->sbq_host_index,
3213 &mrioc->sysif_regs->sense_buffer_free_host_index);
3215 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3216 mutex_unlock(&mrioc->init_cmds.mutex);
3220 dma_free_coherent(&mrioc->pdev->dev, data_len, drv_info,
3227 * mpi3mr_unmask_events - Unmask events in event mask bitmap
3228 * @mrioc: Adapter instance reference
3229 * @event: MPI event ID
3231 * Un mask the specific event by resetting the event_mask
3234 * Return: 0 on success, non-zero on failures.
3236 static void mpi3mr_unmask_events(struct mpi3mr_ioc *mrioc, u16 event)
3244 desired_event = (1 << (event % 32));
3247 mrioc->event_masks[word] &= ~desired_event;
3251 * mpi3mr_issue_event_notification - Send event notification
3252 * @mrioc: Adapter instance reference
3254 * Issue event notification MPI request through admin queue and
3255 * wait for the completion of it or time out.
3257 * Return: 0 on success, non-zero on failures.
3259 static int mpi3mr_issue_event_notification(struct mpi3mr_ioc *mrioc)
3261 struct mpi3_event_notification_request evtnotify_req;
3265 memset(&evtnotify_req, 0, sizeof(evtnotify_req));
3266 mutex_lock(&mrioc->init_cmds.mutex);
3267 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3269 ioc_err(mrioc, "Issue EvtNotify: Init command is in use\n");
3270 mutex_unlock(&mrioc->init_cmds.mutex);
3273 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3274 mrioc->init_cmds.is_waiting = 1;
3275 mrioc->init_cmds.callback = NULL;
3276 evtnotify_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3277 evtnotify_req.function = MPI3_FUNCTION_EVENT_NOTIFICATION;
3278 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3279 evtnotify_req.event_masks[i] =
3280 cpu_to_le32(mrioc->event_masks[i]);
3281 init_completion(&mrioc->init_cmds.done);
3282 retval = mpi3mr_admin_request_post(mrioc, &evtnotify_req,
3283 sizeof(evtnotify_req), 1);
3285 ioc_err(mrioc, "Issue EvtNotify: Admin Post failed\n");
3288 wait_for_completion_timeout(&mrioc->init_cmds.done,
3289 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3290 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3291 ioc_err(mrioc, "event notification timed out\n");
3292 mpi3mr_check_rh_fault_ioc(mrioc,
3293 MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT);
3297 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3298 != MPI3_IOCSTATUS_SUCCESS) {
3300 "Issue EvtNotify: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3301 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3302 mrioc->init_cmds.ioc_loginfo);
3308 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3309 mutex_unlock(&mrioc->init_cmds.mutex);
3315 * mpi3mr_process_event_ack - Process event acknowledgment
3316 * @mrioc: Adapter instance reference
3317 * @event: MPI3 event ID
3318 * @event_ctx: event context
3320 * Send event acknowledgment through admin queue and wait for
3323 * Return: 0 on success, non-zero on failures.
3325 int mpi3mr_process_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
3328 struct mpi3_event_ack_request evtack_req;
3331 memset(&evtack_req, 0, sizeof(evtack_req));
3332 mutex_lock(&mrioc->init_cmds.mutex);
3333 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3335 ioc_err(mrioc, "Send EvtAck: Init command is in use\n");
3336 mutex_unlock(&mrioc->init_cmds.mutex);
3339 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3340 mrioc->init_cmds.is_waiting = 1;
3341 mrioc->init_cmds.callback = NULL;
3342 evtack_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3343 evtack_req.function = MPI3_FUNCTION_EVENT_ACK;
3344 evtack_req.event = event;
3345 evtack_req.event_context = cpu_to_le32(event_ctx);
3347 init_completion(&mrioc->init_cmds.done);
3348 retval = mpi3mr_admin_request_post(mrioc, &evtack_req,
3349 sizeof(evtack_req), 1);
3351 ioc_err(mrioc, "Send EvtAck: Admin Post failed\n");
3354 wait_for_completion_timeout(&mrioc->init_cmds.done,
3355 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3356 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3357 ioc_err(mrioc, "Issue EvtNotify: command timed out\n");
3358 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
3359 mpi3mr_soft_reset_handler(mrioc,
3360 MPI3MR_RESET_FROM_EVTACK_TIMEOUT, 1);
3364 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3365 != MPI3_IOCSTATUS_SUCCESS) {
3367 "Send EvtAck: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3368 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3369 mrioc->init_cmds.ioc_loginfo);
3375 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3376 mutex_unlock(&mrioc->init_cmds.mutex);
3382 * mpi3mr_alloc_chain_bufs - Allocate chain buffers
3383 * @mrioc: Adapter instance reference
3385 * Allocate chain buffers and set a bitmap to indicate free
3386 * chain buffers. Chain buffers are used to pass the SGE
3387 * information along with MPI3 SCSI IO requests for host I/O.
3389 * Return: 0 on success, non-zero on failure
3391 static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
3397 if (mrioc->chain_sgl_list)
3400 num_chains = mrioc->max_host_ios / MPI3MR_CHAINBUF_FACTOR;
3402 if (prot_mask & (SHOST_DIX_TYPE0_PROTECTION
3403 | SHOST_DIX_TYPE1_PROTECTION
3404 | SHOST_DIX_TYPE2_PROTECTION
3405 | SHOST_DIX_TYPE3_PROTECTION))
3406 num_chains += (num_chains / MPI3MR_CHAINBUFDIX_FACTOR);
3408 mrioc->chain_buf_count = num_chains;
3409 sz = sizeof(struct chain_element) * num_chains;
3410 mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
3411 if (!mrioc->chain_sgl_list)
3414 sz = MPI3MR_PAGE_SIZE_4K;
3415 mrioc->chain_buf_pool = dma_pool_create("chain_buf pool",
3416 &mrioc->pdev->dev, sz, 16, 0);
3417 if (!mrioc->chain_buf_pool) {
3418 ioc_err(mrioc, "chain buf pool: dma_pool_create failed\n");
3422 for (i = 0; i < num_chains; i++) {
3423 mrioc->chain_sgl_list[i].addr =
3424 dma_pool_zalloc(mrioc->chain_buf_pool, GFP_KERNEL,
3425 &mrioc->chain_sgl_list[i].dma_addr);
3427 if (!mrioc->chain_sgl_list[i].addr)
3430 mrioc->chain_bitmap = bitmap_zalloc(num_chains, GFP_KERNEL);
3431 if (!mrioc->chain_bitmap)
3440 * mpi3mr_port_enable_complete - Mark port enable complete
3441 * @mrioc: Adapter instance reference
3442 * @drv_cmd: Internal command tracker
3444 * Call back for asynchronous port enable request sets the
3445 * driver command to indicate port enable request is complete.
3449 static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
3450 struct mpi3mr_drv_cmd *drv_cmd)
3452 drv_cmd->callback = NULL;
3453 mrioc->scan_started = 0;
3454 if (drv_cmd->state & MPI3MR_CMD_RESET)
3455 mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
3457 mrioc->scan_failed = drv_cmd->ioc_status;
3458 drv_cmd->state = MPI3MR_CMD_NOTUSED;
3462 * mpi3mr_issue_port_enable - Issue Port Enable
3463 * @mrioc: Adapter instance reference
3464 * @async: Flag to wait for completion or not
3466 * Issue Port Enable MPI request through admin queue and if the
3467 * async flag is not set wait for the completion of the port
3468 * enable or time out.
3470 * Return: 0 on success, non-zero on failures.
3472 int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
3474 struct mpi3_port_enable_request pe_req;
3476 u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
3478 memset(&pe_req, 0, sizeof(pe_req));
3479 mutex_lock(&mrioc->init_cmds.mutex);
3480 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3482 ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
3483 mutex_unlock(&mrioc->init_cmds.mutex);
3486 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3488 mrioc->init_cmds.is_waiting = 0;
3489 mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
3491 mrioc->init_cmds.is_waiting = 1;
3492 mrioc->init_cmds.callback = NULL;
3493 init_completion(&mrioc->init_cmds.done);
3495 pe_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3496 pe_req.function = MPI3_FUNCTION_PORT_ENABLE;
3498 retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
3500 ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
3504 mutex_unlock(&mrioc->init_cmds.mutex);
3508 wait_for_completion_timeout(&mrioc->init_cmds.done, (pe_timeout * HZ));
3509 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3510 ioc_err(mrioc, "port enable timed out\n");
3512 mpi3mr_check_rh_fault_ioc(mrioc, MPI3MR_RESET_FROM_PE_TIMEOUT);
3515 mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
3518 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3519 mutex_unlock(&mrioc->init_cmds.mutex);
3524 /* Protocol type to name mapper structure */
3525 static const struct {
3528 } mpi3mr_protocols[] = {
3529 { MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR, "Initiator" },
3530 { MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET, "Target" },
3531 { MPI3_IOCFACTS_PROTOCOL_NVME, "NVMe attachment" },
3534 /* Capability to name mapper structure*/
3535 static const struct {
3538 } mpi3mr_capabilities[] = {
3539 { MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE, "RAID" },
3540 { MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED, "MultiPath" },
3544 * mpi3mr_print_ioc_info - Display controller information
3545 * @mrioc: Adapter instance reference
3547 * Display controller personalit, capability, supported
3553 mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
3555 int i = 0, bytes_written = 0;
3556 char personality[16];
3557 char protocol[50] = {0};
3558 char capabilities[100] = {0};
3559 struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
3561 switch (mrioc->facts.personality) {
3562 case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
3563 strncpy(personality, "Enhanced HBA", sizeof(personality));
3565 case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
3566 strncpy(personality, "RAID", sizeof(personality));
3569 strncpy(personality, "Unknown", sizeof(personality));
3573 ioc_info(mrioc, "Running in %s Personality", personality);
3575 ioc_info(mrioc, "FW version(%d.%d.%d.%d.%d.%d)\n",
3576 fwver->gen_major, fwver->gen_minor, fwver->ph_major,
3577 fwver->ph_minor, fwver->cust_id, fwver->build_num);
3579 for (i = 0; i < ARRAY_SIZE(mpi3mr_protocols); i++) {
3580 if (mrioc->facts.protocol_flags &
3581 mpi3mr_protocols[i].protocol) {
3582 bytes_written += scnprintf(protocol + bytes_written,
3583 sizeof(protocol) - bytes_written, "%s%s",
3584 bytes_written ? "," : "",
3585 mpi3mr_protocols[i].name);
3590 for (i = 0; i < ARRAY_SIZE(mpi3mr_capabilities); i++) {
3591 if (mrioc->facts.protocol_flags &
3592 mpi3mr_capabilities[i].capability) {
3593 bytes_written += scnprintf(capabilities + bytes_written,
3594 sizeof(capabilities) - bytes_written, "%s%s",
3595 bytes_written ? "," : "",
3596 mpi3mr_capabilities[i].name);
3600 ioc_info(mrioc, "Protocol=(%s), Capabilities=(%s)\n",
3601 protocol, capabilities);
3605 * mpi3mr_cleanup_resources - Free PCI resources
3606 * @mrioc: Adapter instance reference
3608 * Unmap PCI device memory and disable PCI device.
3610 * Return: 0 on success and non-zero on failure.
3612 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
3614 struct pci_dev *pdev = mrioc->pdev;
3616 mpi3mr_cleanup_isr(mrioc);
3618 if (mrioc->sysif_regs) {
3619 iounmap((void __iomem *)mrioc->sysif_regs);
3620 mrioc->sysif_regs = NULL;
3623 if (pci_is_enabled(pdev)) {
3625 pci_release_selected_regions(pdev, mrioc->bars);
3626 pci_disable_device(pdev);
3631 * mpi3mr_setup_resources - Enable PCI resources
3632 * @mrioc: Adapter instance reference
3634 * Enable PCI device memory, MSI-x registers and set DMA mask.
3636 * Return: 0 on success and non-zero on failure.
3638 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
3640 struct pci_dev *pdev = mrioc->pdev;
3642 int i, retval = 0, capb = 0;
3643 u16 message_control;
3644 u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
3645 ((sizeof(dma_addr_t) > 4) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
3647 if (pci_enable_device_mem(pdev)) {
3648 ioc_err(mrioc, "pci_enable_device_mem: failed\n");
3653 capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3655 ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
3659 mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
3661 if (pci_request_selected_regions(pdev, mrioc->bars,
3662 mrioc->driver_name)) {
3663 ioc_err(mrioc, "pci_request_selected_regions: failed\n");
3668 for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
3669 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
3670 mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
3671 memap_sz = pci_resource_len(pdev, i);
3673 ioremap(mrioc->sysif_regs_phys, memap_sz);
3678 pci_set_master(pdev);
3680 retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
3682 if (dma_mask != DMA_BIT_MASK(32)) {
3683 ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
3684 dma_mask = DMA_BIT_MASK(32);
3685 retval = dma_set_mask_and_coherent(&pdev->dev,
3689 mrioc->dma_mask = 0;
3690 ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
3694 mrioc->dma_mask = dma_mask;
3696 if (!mrioc->sysif_regs) {
3698 "Unable to map adapter memory or resource not found\n");
3703 pci_read_config_word(pdev, capb + 2, &message_control);
3704 mrioc->msix_count = (message_control & 0x3FF) + 1;
3706 pci_save_state(pdev);
3708 pci_set_drvdata(pdev, mrioc->shost);
3710 mpi3mr_ioc_disable_intr(mrioc);
3712 ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
3713 (unsigned long long)mrioc->sysif_regs_phys,
3714 mrioc->sysif_regs, memap_sz);
3715 ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
3718 if (!reset_devices && poll_queues > 0)
3719 mrioc->requested_poll_qcount = min_t(int, poll_queues,
3720 mrioc->msix_count - 2);
3724 mpi3mr_cleanup_resources(mrioc);
3729 * mpi3mr_enable_events - Enable required events
3730 * @mrioc: Adapter instance reference
3732 * This routine unmasks the events required by the driver by
3733 * sennding appropriate event mask bitmapt through an event
3734 * notification request.
3736 * Return: 0 on success and non-zero on failure.
3738 static int mpi3mr_enable_events(struct mpi3mr_ioc *mrioc)
3743 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3744 mrioc->event_masks[i] = -1;
3746 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_ADDED);
3747 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_INFO_CHANGED);
3748 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_STATUS_CHANGE);
3749 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE);
3750 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_ADDED);
3751 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
3752 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
3753 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
3754 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_BROADCAST_PRIMITIVE);
3755 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST);
3756 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_ENUMERATION);
3757 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PREPARE_FOR_RESET);
3758 mpi3mr_unmask_events(mrioc, MPI3_EVENT_CABLE_MGMT);
3759 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENERGY_PACK_CHANGE);
3761 retval = mpi3mr_issue_event_notification(mrioc);
3763 ioc_err(mrioc, "failed to issue event notification %d\n",
3769 * mpi3mr_init_ioc - Initialize the controller
3770 * @mrioc: Adapter instance reference
3772 * This the controller initialization routine, executed either
3773 * after soft reset or from pci probe callback.
3774 * Setup the required resources, memory map the controller
3775 * registers, create admin and operational reply queue pairs,
3776 * allocate required memory for reply pool, sense buffer pool,
3777 * issue IOC init request to the firmware, unmask the events and
3778 * issue port enable to discover SAS/SATA/NVMe devies and RAID
3781 * Return: 0 on success and non-zero on failure.
3783 int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
3787 struct mpi3_ioc_facts_data facts_data;
3791 retval = mpi3mr_bring_ioc_ready(mrioc);
3793 ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
3795 goto out_failed_noretry;
3798 retval = mpi3mr_setup_isr(mrioc, 1);
3800 ioc_err(mrioc, "Failed to setup ISR error %d\n",
3802 goto out_failed_noretry;
3805 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
3807 ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
3812 mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD;
3814 mrioc->num_io_throttle_group = mrioc->facts.max_io_throttle_group;
3815 atomic_set(&mrioc->pend_large_data_sz, 0);
3818 mrioc->max_host_ios = min_t(int, mrioc->max_host_ios,
3819 MPI3MR_HOST_IOS_KDUMP);
3821 if (!(mrioc->facts.ioc_capabilities &
3822 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED)) {
3823 mrioc->sas_transport_enabled = 1;
3824 mrioc->scsi_device_channel = 1;
3825 mrioc->shost->max_channel = 1;
3826 mrioc->shost->transportt = mpi3mr_transport_template;
3829 mrioc->reply_sz = mrioc->facts.reply_sz;
3831 retval = mpi3mr_check_reset_dma_mask(mrioc);
3833 ioc_err(mrioc, "Resetting dma mask failed %d\n",
3835 goto out_failed_noretry;
3838 mpi3mr_print_ioc_info(mrioc);
3840 if (!mrioc->cfg_page) {
3841 dprint_init(mrioc, "allocating config page buffers\n");
3842 mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ;
3843 mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev,
3844 mrioc->cfg_page_sz, &mrioc->cfg_page_dma, GFP_KERNEL);
3845 if (!mrioc->cfg_page) {
3847 goto out_failed_noretry;
3851 if (!mrioc->init_cmds.reply) {
3852 retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
3855 "%s :Failed to allocated reply sense buffers %d\n",
3857 goto out_failed_noretry;
3861 if (!mrioc->chain_sgl_list) {
3862 retval = mpi3mr_alloc_chain_bufs(mrioc);
3864 ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
3866 goto out_failed_noretry;
3870 retval = mpi3mr_issue_iocinit(mrioc);
3872 ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
3877 retval = mpi3mr_print_pkg_ver(mrioc);
3879 ioc_err(mrioc, "failed to get package version\n");
3883 retval = mpi3mr_setup_isr(mrioc, 0);
3885 ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
3887 goto out_failed_noretry;
3890 retval = mpi3mr_create_op_queues(mrioc);
3892 ioc_err(mrioc, "Failed to create OpQueues error %d\n",
3897 if (!mrioc->pel_seqnum_virt) {
3898 dprint_init(mrioc, "allocating memory for pel_seqnum_virt\n");
3899 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
3900 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
3901 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
3903 if (!mrioc->pel_seqnum_virt) {
3905 goto out_failed_noretry;
3909 if (!mrioc->throttle_groups && mrioc->num_io_throttle_group) {
3910 dprint_init(mrioc, "allocating memory for throttle groups\n");
3911 sz = sizeof(struct mpi3mr_throttle_group_info);
3912 mrioc->throttle_groups = kcalloc(mrioc->num_io_throttle_group, sz, GFP_KERNEL);
3913 if (!mrioc->throttle_groups) {
3915 goto out_failed_noretry;
3919 retval = mpi3mr_enable_events(mrioc);
3921 ioc_err(mrioc, "failed to enable events %d\n",
3926 ioc_info(mrioc, "controller initialization completed successfully\n");
3931 ioc_warn(mrioc, "retrying controller initialization, retry_count:%d\n",
3933 mpi3mr_memset_buffers(mrioc);
3938 ioc_err(mrioc, "controller initialization failed\n");
3939 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
3940 MPI3MR_RESET_FROM_CTLR_CLEANUP);
3941 mrioc->unrecoverable = 1;
3946 * mpi3mr_reinit_ioc - Re-Initialize the controller
3947 * @mrioc: Adapter instance reference
3948 * @is_resume: Called from resume or reset path
3950 * This the controller re-initialization routine, executed from
3951 * the soft reset handler or resume callback. Creates
3952 * operational reply queue pairs, allocate required memory for
3953 * reply pool, sense buffer pool, issue IOC init request to the
3954 * firmware, unmask the events and issue port enable to discover
3955 * SAS/SATA/NVMe devices and RAID volumes.
3957 * Return: 0 on success and non-zero on failure.
3959 int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
3963 struct mpi3_ioc_facts_data facts_data;
3964 u32 pe_timeout, ioc_status;
3968 (MPI3MR_PORTENABLE_TIMEOUT / MPI3MR_PORTENABLE_POLL_INTERVAL);
3970 dprint_reset(mrioc, "bringing up the controller to ready state\n");
3971 retval = mpi3mr_bring_ioc_ready(mrioc);
3973 ioc_err(mrioc, "failed to bring to ready state\n");
3974 goto out_failed_noretry;
3978 dprint_reset(mrioc, "setting up single ISR\n");
3979 retval = mpi3mr_setup_isr(mrioc, 1);
3981 ioc_err(mrioc, "failed to setup ISR\n");
3982 goto out_failed_noretry;
3985 mpi3mr_ioc_enable_intr(mrioc);
3987 dprint_reset(mrioc, "getting ioc_facts\n");
3988 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
3990 ioc_err(mrioc, "failed to get ioc_facts\n");
3994 dprint_reset(mrioc, "validating ioc_facts\n");
3995 retval = mpi3mr_revalidate_factsdata(mrioc);
3997 ioc_err(mrioc, "failed to revalidate ioc_facts data\n");
3998 goto out_failed_noretry;
4001 mpi3mr_print_ioc_info(mrioc);
4003 dprint_reset(mrioc, "sending ioc_init\n");
4004 retval = mpi3mr_issue_iocinit(mrioc);
4006 ioc_err(mrioc, "failed to send ioc_init\n");
4010 dprint_reset(mrioc, "getting package version\n");
4011 retval = mpi3mr_print_pkg_ver(mrioc);
4013 ioc_err(mrioc, "failed to get package version\n");
4018 dprint_reset(mrioc, "setting up multiple ISR\n");
4019 retval = mpi3mr_setup_isr(mrioc, 0);
4021 ioc_err(mrioc, "failed to re-setup ISR\n");
4022 goto out_failed_noretry;
4026 dprint_reset(mrioc, "creating operational queue pairs\n");
4027 retval = mpi3mr_create_op_queues(mrioc);
4029 ioc_err(mrioc, "failed to create operational queue pairs\n");
4033 if (!mrioc->pel_seqnum_virt) {
4034 dprint_reset(mrioc, "allocating memory for pel_seqnum_virt\n");
4035 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
4036 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
4037 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
4039 if (!mrioc->pel_seqnum_virt) {
4041 goto out_failed_noretry;
4045 if (mrioc->shost->nr_hw_queues > mrioc->num_op_reply_q) {
4047 "cannot create minimum number of operational queues expected:%d created:%d\n",
4048 mrioc->shost->nr_hw_queues, mrioc->num_op_reply_q);
4050 goto out_failed_noretry;
4053 dprint_reset(mrioc, "enabling events\n");
4054 retval = mpi3mr_enable_events(mrioc);
4056 ioc_err(mrioc, "failed to enable events\n");
4060 mrioc->device_refresh_on = 1;
4061 mpi3mr_add_event_wait_for_device_refresh(mrioc);
4063 ioc_info(mrioc, "sending port enable\n");
4064 retval = mpi3mr_issue_port_enable(mrioc, 1);
4066 ioc_err(mrioc, "failed to issue port enable\n");
4070 ssleep(MPI3MR_PORTENABLE_POLL_INTERVAL);
4071 if (mrioc->init_cmds.state == MPI3MR_CMD_NOTUSED)
4073 if (!pci_device_is_present(mrioc->pdev))
4074 mrioc->unrecoverable = 1;
4075 if (mrioc->unrecoverable) {
4077 goto out_failed_noretry;
4079 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4080 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
4081 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
4082 mpi3mr_print_fault_info(mrioc);
4083 mrioc->init_cmds.is_waiting = 0;
4084 mrioc->init_cmds.callback = NULL;
4085 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4088 } while (--pe_timeout);
4091 ioc_err(mrioc, "port enable timed out\n");
4092 mpi3mr_check_rh_fault_ioc(mrioc,
4093 MPI3MR_RESET_FROM_PE_TIMEOUT);
4094 mrioc->init_cmds.is_waiting = 0;
4095 mrioc->init_cmds.callback = NULL;
4096 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4098 } else if (mrioc->scan_failed) {
4100 "port enable failed with status=0x%04x\n",
4101 mrioc->scan_failed);
4103 ioc_info(mrioc, "port enable completed successfully\n");
4105 ioc_info(mrioc, "controller %s completed successfully\n",
4106 (is_resume)?"resume":"re-initialization");
4111 ioc_warn(mrioc, "retrying controller %s, retry_count:%d\n",
4112 (is_resume)?"resume":"re-initialization", retry);
4113 mpi3mr_memset_buffers(mrioc);
4118 ioc_err(mrioc, "controller %s is failed\n",
4119 (is_resume)?"resume":"re-initialization");
4120 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
4121 MPI3MR_RESET_FROM_CTLR_CLEANUP);
4122 mrioc->unrecoverable = 1;
4127 * mpi3mr_memset_op_reply_q_buffers - memset the operational reply queue's
4129 * @mrioc: Adapter instance reference
4130 * @qidx: Operational reply queue index
4134 static void mpi3mr_memset_op_reply_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4136 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
4137 struct segments *segments;
4140 if (!op_reply_q->q_segments)
4143 size = op_reply_q->segment_qd * mrioc->op_reply_desc_sz;
4144 segments = op_reply_q->q_segments;
4145 for (i = 0; i < op_reply_q->num_segments; i++)
4146 memset(segments[i].segment, 0, size);
4150 * mpi3mr_memset_op_req_q_buffers - memset the operational request queue's
4152 * @mrioc: Adapter instance reference
4153 * @qidx: Operational request queue index
4157 static void mpi3mr_memset_op_req_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4159 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
4160 struct segments *segments;
4163 if (!op_req_q->q_segments)
4166 size = op_req_q->segment_qd * mrioc->facts.op_req_sz;
4167 segments = op_req_q->q_segments;
4168 for (i = 0; i < op_req_q->num_segments; i++)
4169 memset(segments[i].segment, 0, size);
4173 * mpi3mr_memset_buffers - memset memory for a controller
4174 * @mrioc: Adapter instance reference
4176 * clear all the memory allocated for a controller, typically
4177 * called post reset to reuse the memory allocated during the
4182 void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
4185 struct mpi3mr_throttle_group_info *tg;
4187 mrioc->change_count = 0;
4188 mrioc->active_poll_qcount = 0;
4189 mrioc->default_qcount = 0;
4190 if (mrioc->admin_req_base)
4191 memset(mrioc->admin_req_base, 0, mrioc->admin_req_q_sz);
4192 if (mrioc->admin_reply_base)
4193 memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
4194 atomic_set(&mrioc->admin_reply_q_in_use, 0);
4196 if (mrioc->init_cmds.reply) {
4197 memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
4198 memset(mrioc->bsg_cmds.reply, 0,
4199 sizeof(*mrioc->bsg_cmds.reply));
4200 memset(mrioc->host_tm_cmds.reply, 0,
4201 sizeof(*mrioc->host_tm_cmds.reply));
4202 memset(mrioc->pel_cmds.reply, 0,
4203 sizeof(*mrioc->pel_cmds.reply));
4204 memset(mrioc->pel_abort_cmd.reply, 0,
4205 sizeof(*mrioc->pel_abort_cmd.reply));
4206 memset(mrioc->transport_cmds.reply, 0,
4207 sizeof(*mrioc->transport_cmds.reply));
4208 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
4209 memset(mrioc->dev_rmhs_cmds[i].reply, 0,
4210 sizeof(*mrioc->dev_rmhs_cmds[i].reply));
4211 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++)
4212 memset(mrioc->evtack_cmds[i].reply, 0,
4213 sizeof(*mrioc->evtack_cmds[i].reply));
4214 bitmap_clear(mrioc->removepend_bitmap, 0,
4215 mrioc->dev_handle_bitmap_bits);
4216 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
4217 bitmap_clear(mrioc->evtack_cmds_bitmap, 0,
4218 MPI3MR_NUM_EVTACKCMD);
4221 for (i = 0; i < mrioc->num_queues; i++) {
4222 mrioc->op_reply_qinfo[i].qid = 0;
4223 mrioc->op_reply_qinfo[i].ci = 0;
4224 mrioc->op_reply_qinfo[i].num_replies = 0;
4225 mrioc->op_reply_qinfo[i].ephase = 0;
4226 atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
4227 atomic_set(&mrioc->op_reply_qinfo[i].in_use, 0);
4228 mpi3mr_memset_op_reply_q_buffers(mrioc, i);
4230 mrioc->req_qinfo[i].ci = 0;
4231 mrioc->req_qinfo[i].pi = 0;
4232 mrioc->req_qinfo[i].num_requests = 0;
4233 mrioc->req_qinfo[i].qid = 0;
4234 mrioc->req_qinfo[i].reply_qid = 0;
4235 spin_lock_init(&mrioc->req_qinfo[i].q_lock);
4236 mpi3mr_memset_op_req_q_buffers(mrioc, i);
4239 atomic_set(&mrioc->pend_large_data_sz, 0);
4240 if (mrioc->throttle_groups) {
4241 tg = mrioc->throttle_groups;
4242 for (i = 0; i < mrioc->num_io_throttle_group; i++, tg++) {
4245 tg->modified_qd = 0;
4247 tg->need_qd_reduction = 0;
4250 tg->qd_reduction = 0;
4251 atomic_set(&tg->pend_large_data_sz, 0);
4257 * mpi3mr_free_mem - Free memory allocated for a controller
4258 * @mrioc: Adapter instance reference
4260 * Free all the memory allocated for a controller.
4264 void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
4267 struct mpi3mr_intr_info *intr_info;
4269 mpi3mr_free_enclosure_list(mrioc);
4271 if (mrioc->sense_buf_pool) {
4272 if (mrioc->sense_buf)
4273 dma_pool_free(mrioc->sense_buf_pool, mrioc->sense_buf,
4274 mrioc->sense_buf_dma);
4275 dma_pool_destroy(mrioc->sense_buf_pool);
4276 mrioc->sense_buf = NULL;
4277 mrioc->sense_buf_pool = NULL;
4279 if (mrioc->sense_buf_q_pool) {
4280 if (mrioc->sense_buf_q)
4281 dma_pool_free(mrioc->sense_buf_q_pool,
4282 mrioc->sense_buf_q, mrioc->sense_buf_q_dma);
4283 dma_pool_destroy(mrioc->sense_buf_q_pool);
4284 mrioc->sense_buf_q = NULL;
4285 mrioc->sense_buf_q_pool = NULL;
4288 if (mrioc->reply_buf_pool) {
4289 if (mrioc->reply_buf)
4290 dma_pool_free(mrioc->reply_buf_pool, mrioc->reply_buf,
4291 mrioc->reply_buf_dma);
4292 dma_pool_destroy(mrioc->reply_buf_pool);
4293 mrioc->reply_buf = NULL;
4294 mrioc->reply_buf_pool = NULL;
4296 if (mrioc->reply_free_q_pool) {
4297 if (mrioc->reply_free_q)
4298 dma_pool_free(mrioc->reply_free_q_pool,
4299 mrioc->reply_free_q, mrioc->reply_free_q_dma);
4300 dma_pool_destroy(mrioc->reply_free_q_pool);
4301 mrioc->reply_free_q = NULL;
4302 mrioc->reply_free_q_pool = NULL;
4305 for (i = 0; i < mrioc->num_op_req_q; i++)
4306 mpi3mr_free_op_req_q_segments(mrioc, i);
4308 for (i = 0; i < mrioc->num_op_reply_q; i++)
4309 mpi3mr_free_op_reply_q_segments(mrioc, i);
4311 for (i = 0; i < mrioc->intr_info_count; i++) {
4312 intr_info = mrioc->intr_info + i;
4313 intr_info->op_reply_q = NULL;
4316 kfree(mrioc->req_qinfo);
4317 mrioc->req_qinfo = NULL;
4318 mrioc->num_op_req_q = 0;
4320 kfree(mrioc->op_reply_qinfo);
4321 mrioc->op_reply_qinfo = NULL;
4322 mrioc->num_op_reply_q = 0;
4324 kfree(mrioc->init_cmds.reply);
4325 mrioc->init_cmds.reply = NULL;
4327 kfree(mrioc->bsg_cmds.reply);
4328 mrioc->bsg_cmds.reply = NULL;
4330 kfree(mrioc->host_tm_cmds.reply);
4331 mrioc->host_tm_cmds.reply = NULL;
4333 kfree(mrioc->pel_cmds.reply);
4334 mrioc->pel_cmds.reply = NULL;
4336 kfree(mrioc->pel_abort_cmd.reply);
4337 mrioc->pel_abort_cmd.reply = NULL;
4339 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4340 kfree(mrioc->evtack_cmds[i].reply);
4341 mrioc->evtack_cmds[i].reply = NULL;
4344 bitmap_free(mrioc->removepend_bitmap);
4345 mrioc->removepend_bitmap = NULL;
4347 bitmap_free(mrioc->devrem_bitmap);
4348 mrioc->devrem_bitmap = NULL;
4350 bitmap_free(mrioc->evtack_cmds_bitmap);
4351 mrioc->evtack_cmds_bitmap = NULL;
4353 bitmap_free(mrioc->chain_bitmap);
4354 mrioc->chain_bitmap = NULL;
4356 kfree(mrioc->transport_cmds.reply);
4357 mrioc->transport_cmds.reply = NULL;
4359 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4360 kfree(mrioc->dev_rmhs_cmds[i].reply);
4361 mrioc->dev_rmhs_cmds[i].reply = NULL;
4364 if (mrioc->chain_buf_pool) {
4365 for (i = 0; i < mrioc->chain_buf_count; i++) {
4366 if (mrioc->chain_sgl_list[i].addr) {
4367 dma_pool_free(mrioc->chain_buf_pool,
4368 mrioc->chain_sgl_list[i].addr,
4369 mrioc->chain_sgl_list[i].dma_addr);
4370 mrioc->chain_sgl_list[i].addr = NULL;
4373 dma_pool_destroy(mrioc->chain_buf_pool);
4374 mrioc->chain_buf_pool = NULL;
4377 kfree(mrioc->chain_sgl_list);
4378 mrioc->chain_sgl_list = NULL;
4380 if (mrioc->admin_reply_base) {
4381 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
4382 mrioc->admin_reply_base, mrioc->admin_reply_dma);
4383 mrioc->admin_reply_base = NULL;
4385 if (mrioc->admin_req_base) {
4386 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
4387 mrioc->admin_req_base, mrioc->admin_req_dma);
4388 mrioc->admin_req_base = NULL;
4390 if (mrioc->cfg_page) {
4391 dma_free_coherent(&mrioc->pdev->dev, mrioc->cfg_page_sz,
4392 mrioc->cfg_page, mrioc->cfg_page_dma);
4393 mrioc->cfg_page = NULL;
4395 if (mrioc->pel_seqnum_virt) {
4396 dma_free_coherent(&mrioc->pdev->dev, mrioc->pel_seqnum_sz,
4397 mrioc->pel_seqnum_virt, mrioc->pel_seqnum_dma);
4398 mrioc->pel_seqnum_virt = NULL;
4401 kfree(mrioc->throttle_groups);
4402 mrioc->throttle_groups = NULL;
4404 kfree(mrioc->logdata_buf);
4405 mrioc->logdata_buf = NULL;
4410 * mpi3mr_issue_ioc_shutdown - shutdown controller
4411 * @mrioc: Adapter instance reference
4413 * Send shutodwn notification to the controller and wait for the
4414 * shutdown_timeout for it to be completed.
4418 static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
4420 u32 ioc_config, ioc_status;
4422 u32 timeout = MPI3MR_DEFAULT_SHUTDOWN_TIME * 10;
4424 ioc_info(mrioc, "Issuing shutdown Notification\n");
4425 if (mrioc->unrecoverable) {
4427 "IOC is unrecoverable shutdown is not issued\n");
4430 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4431 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4432 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS) {
4433 ioc_info(mrioc, "shutdown already in progress\n");
4437 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4438 ioc_config |= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL;
4439 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN_SEND_REQ;
4441 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
4443 if (mrioc->facts.shutdown_timeout)
4444 timeout = mrioc->facts.shutdown_timeout * 10;
4447 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4448 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4449 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE) {
4454 } while (--timeout);
4456 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4457 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4460 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4461 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS)
4463 "shutdown still in progress after timeout\n");
4467 "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
4468 (!retval) ? "successful" : "failed", ioc_status,
4473 * mpi3mr_cleanup_ioc - Cleanup controller
4474 * @mrioc: Adapter instance reference
4476 * controller cleanup handler, Message unit reset or soft reset
4477 * and shutdown notification is issued to the controller.
4481 void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
4483 enum mpi3mr_iocstate ioc_state;
4485 dprint_exit(mrioc, "cleaning up the controller\n");
4486 mpi3mr_ioc_disable_intr(mrioc);
4488 ioc_state = mpi3mr_get_iocstate(mrioc);
4490 if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
4491 (ioc_state == MRIOC_STATE_READY)) {
4492 if (mpi3mr_issue_and_process_mur(mrioc,
4493 MPI3MR_RESET_FROM_CTLR_CLEANUP))
4494 mpi3mr_issue_reset(mrioc,
4495 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
4496 MPI3MR_RESET_FROM_MUR_FAILURE);
4497 mpi3mr_issue_ioc_shutdown(mrioc);
4499 dprint_exit(mrioc, "controller cleanup completed\n");
4503 * mpi3mr_drv_cmd_comp_reset - Flush a internal driver command
4504 * @mrioc: Adapter instance reference
4505 * @cmdptr: Internal command tracker
4507 * Complete an internal driver commands with state indicating it
4508 * is completed due to reset.
4512 static inline void mpi3mr_drv_cmd_comp_reset(struct mpi3mr_ioc *mrioc,
4513 struct mpi3mr_drv_cmd *cmdptr)
4515 if (cmdptr->state & MPI3MR_CMD_PENDING) {
4516 cmdptr->state |= MPI3MR_CMD_RESET;
4517 cmdptr->state &= ~MPI3MR_CMD_PENDING;
4518 if (cmdptr->is_waiting) {
4519 complete(&cmdptr->done);
4520 cmdptr->is_waiting = 0;
4521 } else if (cmdptr->callback)
4522 cmdptr->callback(mrioc, cmdptr);
4527 * mpi3mr_flush_drv_cmds - Flush internaldriver commands
4528 * @mrioc: Adapter instance reference
4530 * Flush all internal driver commands post reset
4534 void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
4536 struct mpi3mr_drv_cmd *cmdptr;
4539 cmdptr = &mrioc->init_cmds;
4540 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4542 cmdptr = &mrioc->cfg_cmds;
4543 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4545 cmdptr = &mrioc->bsg_cmds;
4546 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4547 cmdptr = &mrioc->host_tm_cmds;
4548 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4550 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4551 cmdptr = &mrioc->dev_rmhs_cmds[i];
4552 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4555 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4556 cmdptr = &mrioc->evtack_cmds[i];
4557 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4560 cmdptr = &mrioc->pel_cmds;
4561 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4563 cmdptr = &mrioc->pel_abort_cmd;
4564 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4566 cmdptr = &mrioc->transport_cmds;
4567 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4571 * mpi3mr_pel_wait_post - Issue PEL Wait
4572 * @mrioc: Adapter instance reference
4573 * @drv_cmd: Internal command tracker
4575 * Issue PEL Wait MPI request through admin queue and return.
4579 static void mpi3mr_pel_wait_post(struct mpi3mr_ioc *mrioc,
4580 struct mpi3mr_drv_cmd *drv_cmd)
4582 struct mpi3_pel_req_action_wait pel_wait;
4584 mrioc->pel_abort_requested = false;
4586 memset(&pel_wait, 0, sizeof(pel_wait));
4587 drv_cmd->state = MPI3MR_CMD_PENDING;
4588 drv_cmd->is_waiting = 0;
4589 drv_cmd->callback = mpi3mr_pel_wait_complete;
4590 drv_cmd->ioc_status = 0;
4591 drv_cmd->ioc_loginfo = 0;
4592 pel_wait.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4593 pel_wait.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4594 pel_wait.action = MPI3_PEL_ACTION_WAIT;
4595 pel_wait.starting_sequence_number = cpu_to_le32(mrioc->pel_newest_seqnum);
4596 pel_wait.locale = cpu_to_le16(mrioc->pel_locale);
4597 pel_wait.class = cpu_to_le16(mrioc->pel_class);
4598 pel_wait.wait_time = MPI3_PEL_WAITTIME_INFINITE_WAIT;
4599 dprint_bsg_info(mrioc, "sending pel_wait seqnum(%d), class(%d), locale(0x%08x)\n",
4600 mrioc->pel_newest_seqnum, mrioc->pel_class, mrioc->pel_locale);
4602 if (mpi3mr_admin_request_post(mrioc, &pel_wait, sizeof(pel_wait), 0)) {
4603 dprint_bsg_err(mrioc,
4604 "Issuing PELWait: Admin post failed\n");
4605 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4606 drv_cmd->callback = NULL;
4607 drv_cmd->retry_count = 0;
4608 mrioc->pel_enabled = false;
4613 * mpi3mr_pel_get_seqnum_post - Issue PEL Get Sequence number
4614 * @mrioc: Adapter instance reference
4615 * @drv_cmd: Internal command tracker
4617 * Issue PEL get sequence number MPI request through admin queue
4620 * Return: 0 on success, non-zero on failure.
4622 int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc,
4623 struct mpi3mr_drv_cmd *drv_cmd)
4625 struct mpi3_pel_req_action_get_sequence_numbers pel_getseq_req;
4626 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
4629 memset(&pel_getseq_req, 0, sizeof(pel_getseq_req));
4630 mrioc->pel_cmds.state = MPI3MR_CMD_PENDING;
4631 mrioc->pel_cmds.is_waiting = 0;
4632 mrioc->pel_cmds.ioc_status = 0;
4633 mrioc->pel_cmds.ioc_loginfo = 0;
4634 mrioc->pel_cmds.callback = mpi3mr_pel_get_seqnum_complete;
4635 pel_getseq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4636 pel_getseq_req.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4637 pel_getseq_req.action = MPI3_PEL_ACTION_GET_SEQNUM;
4638 mpi3mr_add_sg_single(&pel_getseq_req.sgl, sgl_flags,
4639 mrioc->pel_seqnum_sz, mrioc->pel_seqnum_dma);
4641 retval = mpi3mr_admin_request_post(mrioc, &pel_getseq_req,
4642 sizeof(pel_getseq_req), 0);
4645 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4646 drv_cmd->callback = NULL;
4647 drv_cmd->retry_count = 0;
4649 mrioc->pel_enabled = false;
4656 * mpi3mr_pel_wait_complete - PELWait Completion callback
4657 * @mrioc: Adapter instance reference
4658 * @drv_cmd: Internal command tracker
4660 * This is a callback handler for the PELWait request and
4661 * firmware completes a PELWait request when it is aborted or a
4662 * new PEL entry is available. This sends AEN to the application
4663 * and if the PELwait completion is not due to PELAbort then
4664 * this will send a request for new PEL Sequence number
4668 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc *mrioc,
4669 struct mpi3mr_drv_cmd *drv_cmd)
4671 struct mpi3_pel_reply *pel_reply = NULL;
4672 u16 ioc_status, pe_log_status;
4673 bool do_retry = false;
4675 if (drv_cmd->state & MPI3MR_CMD_RESET)
4676 goto cleanup_drv_cmd;
4678 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4679 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4680 ioc_err(mrioc, "%s: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
4681 __func__, ioc_status, drv_cmd->ioc_loginfo);
4682 dprint_bsg_err(mrioc,
4683 "pel_wait: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4684 ioc_status, drv_cmd->ioc_loginfo);
4688 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4689 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4692 dprint_bsg_err(mrioc,
4693 "pel_wait: failed due to no reply\n");
4697 pe_log_status = le16_to_cpu(pel_reply->pe_log_status);
4698 if ((pe_log_status != MPI3_PEL_STATUS_SUCCESS) &&
4699 (pe_log_status != MPI3_PEL_STATUS_ABORTED)) {
4700 ioc_err(mrioc, "%s: Failed pe_log_status(0x%04x)\n",
4701 __func__, pe_log_status);
4702 dprint_bsg_err(mrioc,
4703 "pel_wait: failed due to pel_log_status(0x%04x)\n",
4709 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4710 drv_cmd->retry_count++;
4711 dprint_bsg_err(mrioc, "pel_wait: retrying(%d)\n",
4712 drv_cmd->retry_count);
4713 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4716 dprint_bsg_err(mrioc,
4717 "pel_wait: failed after all retries(%d)\n",
4718 drv_cmd->retry_count);
4721 atomic64_inc(&event_counter);
4722 if (!mrioc->pel_abort_requested) {
4723 mrioc->pel_cmds.retry_count = 0;
4724 mpi3mr_pel_get_seqnum_post(mrioc, &mrioc->pel_cmds);
4729 mrioc->pel_enabled = false;
4731 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4732 drv_cmd->callback = NULL;
4733 drv_cmd->retry_count = 0;
4737 * mpi3mr_pel_get_seqnum_complete - PELGetSeqNum Completion callback
4738 * @mrioc: Adapter instance reference
4739 * @drv_cmd: Internal command tracker
4741 * This is a callback handler for the PEL get sequence number
4742 * request and a new PEL wait request will be issued to the
4743 * firmware from this
4747 void mpi3mr_pel_get_seqnum_complete(struct mpi3mr_ioc *mrioc,
4748 struct mpi3mr_drv_cmd *drv_cmd)
4750 struct mpi3_pel_reply *pel_reply = NULL;
4751 struct mpi3_pel_seq *pel_seqnum_virt;
4753 bool do_retry = false;
4755 pel_seqnum_virt = (struct mpi3_pel_seq *)mrioc->pel_seqnum_virt;
4757 if (drv_cmd->state & MPI3MR_CMD_RESET)
4758 goto cleanup_drv_cmd;
4760 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4761 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4762 dprint_bsg_err(mrioc,
4763 "pel_get_seqnum: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4764 ioc_status, drv_cmd->ioc_loginfo);
4768 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4769 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4771 dprint_bsg_err(mrioc,
4772 "pel_get_seqnum: failed due to no reply\n");
4776 if (le16_to_cpu(pel_reply->pe_log_status) != MPI3_PEL_STATUS_SUCCESS) {
4777 dprint_bsg_err(mrioc,
4778 "pel_get_seqnum: failed due to pel_log_status(0x%04x)\n",
4779 le16_to_cpu(pel_reply->pe_log_status));
4784 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4785 drv_cmd->retry_count++;
4786 dprint_bsg_err(mrioc,
4787 "pel_get_seqnum: retrying(%d)\n",
4788 drv_cmd->retry_count);
4789 mpi3mr_pel_get_seqnum_post(mrioc, drv_cmd);
4793 dprint_bsg_err(mrioc,
4794 "pel_get_seqnum: failed after all retries(%d)\n",
4795 drv_cmd->retry_count);
4798 mrioc->pel_newest_seqnum = le32_to_cpu(pel_seqnum_virt->newest) + 1;
4799 drv_cmd->retry_count = 0;
4800 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4804 mrioc->pel_enabled = false;
4806 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4807 drv_cmd->callback = NULL;
4808 drv_cmd->retry_count = 0;
4812 * mpi3mr_soft_reset_handler - Reset the controller
4813 * @mrioc: Adapter instance reference
4814 * @reset_reason: Reset reason code
4815 * @snapdump: Flag to generate snapdump in firmware or not
4817 * This is an handler for recovering controller by issuing soft
4818 * reset are diag fault reset. This is a blocking function and
4819 * when one reset is executed if any other resets they will be
4820 * blocked. All BSG requests will be blocked during the reset. If
4821 * controller reset is successful then the controller will be
4822 * reinitalized, otherwise the controller will be marked as not
4825 * In snapdump bit is set, the controller is issued with diag
4826 * fault reset so that the firmware can create a snap dump and
4827 * post that the firmware will result in F000 fault and the
4828 * driver will issue soft reset to recover from that.
4830 * Return: 0 on success, non-zero on failure.
4832 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
4833 u32 reset_reason, u8 snapdump)
4836 unsigned long flags;
4837 u32 host_diagnostic, timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
4839 /* Block the reset handler until diag save in progress*/
4841 "soft_reset_handler: check and block on diagsave_timeout(%d)\n",
4842 mrioc->diagsave_timeout);
4843 while (mrioc->diagsave_timeout)
4846 * Block new resets until the currently executing one is finished and
4847 * return the status of the existing reset for all blocked resets
4849 dprint_reset(mrioc, "soft_reset_handler: acquiring reset_mutex\n");
4850 if (!mutex_trylock(&mrioc->reset_mutex)) {
4852 "controller reset triggered by %s is blocked due to another reset in progress\n",
4853 mpi3mr_reset_rc_name(reset_reason));
4856 } while (mrioc->reset_in_progress == 1);
4858 "returning previous reset result(%d) for the reset triggered by %s\n",
4859 mrioc->prev_reset_result,
4860 mpi3mr_reset_rc_name(reset_reason));
4861 return mrioc->prev_reset_result;
4863 ioc_info(mrioc, "controller reset is triggered by %s\n",
4864 mpi3mr_reset_rc_name(reset_reason));
4866 mrioc->device_refresh_on = 0;
4867 mrioc->reset_in_progress = 1;
4868 mrioc->stop_bsgs = 1;
4869 mrioc->prev_reset_result = -1;
4871 if ((!snapdump) && (reset_reason != MPI3MR_RESET_FROM_FAULT_WATCH) &&
4872 (reset_reason != MPI3MR_RESET_FROM_FIRMWARE) &&
4873 (reset_reason != MPI3MR_RESET_FROM_CIACTIV_FAULT)) {
4874 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4875 mrioc->event_masks[i] = -1;
4877 dprint_reset(mrioc, "soft_reset_handler: masking events\n");
4878 mpi3mr_issue_event_notification(mrioc);
4881 mpi3mr_wait_for_host_io(mrioc, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT);
4883 mpi3mr_ioc_disable_intr(mrioc);
4886 mpi3mr_set_diagsave(mrioc);
4887 retval = mpi3mr_issue_reset(mrioc,
4888 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
4892 readl(&mrioc->sysif_regs->host_diagnostic);
4893 if (!(host_diagnostic &
4894 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
4897 } while (--timeout);
4901 retval = mpi3mr_issue_reset(mrioc,
4902 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, reset_reason);
4904 ioc_err(mrioc, "Failed to issue soft reset to the ioc\n");
4907 if (mrioc->num_io_throttle_group !=
4908 mrioc->facts.max_io_throttle_group) {
4910 "max io throttle group doesn't match old(%d), new(%d)\n",
4911 mrioc->num_io_throttle_group,
4912 mrioc->facts.max_io_throttle_group);
4917 mpi3mr_flush_delayed_cmd_lists(mrioc);
4918 mpi3mr_flush_drv_cmds(mrioc);
4919 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
4920 bitmap_clear(mrioc->removepend_bitmap, 0,
4921 mrioc->dev_handle_bitmap_bits);
4922 bitmap_clear(mrioc->evtack_cmds_bitmap, 0, MPI3MR_NUM_EVTACKCMD);
4923 mpi3mr_flush_host_io(mrioc);
4924 mpi3mr_cleanup_fwevt_list(mrioc);
4925 mpi3mr_invalidate_devhandles(mrioc);
4926 mpi3mr_free_enclosure_list(mrioc);
4928 if (mrioc->prepare_for_reset) {
4929 mrioc->prepare_for_reset = 0;
4930 mrioc->prepare_for_reset_timeout_counter = 0;
4932 mpi3mr_memset_buffers(mrioc);
4933 retval = mpi3mr_reinit_ioc(mrioc, 0);
4935 pr_err(IOCNAME "reinit after soft reset failed: reason %d\n",
4936 mrioc->name, reset_reason);
4939 ssleep(MPI3MR_RESET_TOPOLOGY_SETTLE_TIME);
4943 mrioc->diagsave_timeout = 0;
4944 mrioc->reset_in_progress = 0;
4945 mrioc->pel_abort_requested = 0;
4946 if (mrioc->pel_enabled) {
4947 mrioc->pel_cmds.retry_count = 0;
4948 mpi3mr_pel_wait_post(mrioc, &mrioc->pel_cmds);
4951 mrioc->device_refresh_on = 0;
4953 mrioc->ts_update_counter = 0;
4954 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
4955 if (mrioc->watchdog_work_q)
4956 queue_delayed_work(mrioc->watchdog_work_q,
4957 &mrioc->watchdog_work,
4958 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
4959 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
4960 mrioc->stop_bsgs = 0;
4961 if (mrioc->pel_enabled)
4962 atomic64_inc(&event_counter);
4964 mpi3mr_issue_reset(mrioc,
4965 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
4966 mrioc->device_refresh_on = 0;
4967 mrioc->unrecoverable = 1;
4968 mrioc->reset_in_progress = 0;
4970 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
4972 mrioc->prev_reset_result = retval;
4973 mutex_unlock(&mrioc->reset_mutex);
4974 ioc_info(mrioc, "controller reset is %s\n",
4975 ((retval == 0) ? "successful" : "failed"));
4981 * mpi3mr_free_config_dma_memory - free memory for config page
4982 * @mrioc: Adapter instance reference
4983 * @mem_desc: memory descriptor structure
4985 * Check whether the size of the buffer specified by the memory
4986 * descriptor is greater than the default page size if so then
4987 * free the memory pointed by the descriptor.
4991 static void mpi3mr_free_config_dma_memory(struct mpi3mr_ioc *mrioc,
4992 struct dma_memory_desc *mem_desc)
4994 if ((mem_desc->size > mrioc->cfg_page_sz) && mem_desc->addr) {
4995 dma_free_coherent(&mrioc->pdev->dev, mem_desc->size,
4996 mem_desc->addr, mem_desc->dma_addr);
4997 mem_desc->addr = NULL;
5002 * mpi3mr_alloc_config_dma_memory - Alloc memory for config page
5003 * @mrioc: Adapter instance reference
5004 * @mem_desc: Memory descriptor to hold dma memory info
5006 * This function allocates new dmaable memory or provides the
5007 * default config page dmaable memory based on the memory size
5008 * described by the descriptor.
5010 * Return: 0 on success, non-zero on failure.
5012 static int mpi3mr_alloc_config_dma_memory(struct mpi3mr_ioc *mrioc,
5013 struct dma_memory_desc *mem_desc)
5015 if (mem_desc->size > mrioc->cfg_page_sz) {
5016 mem_desc->addr = dma_alloc_coherent(&mrioc->pdev->dev,
5017 mem_desc->size, &mem_desc->dma_addr, GFP_KERNEL);
5018 if (!mem_desc->addr)
5021 mem_desc->addr = mrioc->cfg_page;
5022 mem_desc->dma_addr = mrioc->cfg_page_dma;
5023 memset(mem_desc->addr, 0, mrioc->cfg_page_sz);
5029 * mpi3mr_post_cfg_req - Issue config requests and wait
5030 * @mrioc: Adapter instance reference
5031 * @cfg_req: Configuration request
5032 * @timeout: Timeout in seconds
5033 * @ioc_status: Pointer to return ioc status
5035 * A generic function for posting MPI3 configuration request to
5036 * the firmware. This blocks for the completion of request for
5037 * timeout seconds and if the request times out this function
5038 * faults the controller with proper reason code.
5040 * On successful completion of the request this function returns
5041 * appropriate ioc status from the firmware back to the caller.
5043 * Return: 0 on success, non-zero on failure.
5045 static int mpi3mr_post_cfg_req(struct mpi3mr_ioc *mrioc,
5046 struct mpi3_config_request *cfg_req, int timeout, u16 *ioc_status)
5050 mutex_lock(&mrioc->cfg_cmds.mutex);
5051 if (mrioc->cfg_cmds.state & MPI3MR_CMD_PENDING) {
5053 ioc_err(mrioc, "sending config request failed due to command in use\n");
5054 mutex_unlock(&mrioc->cfg_cmds.mutex);
5057 mrioc->cfg_cmds.state = MPI3MR_CMD_PENDING;
5058 mrioc->cfg_cmds.is_waiting = 1;
5059 mrioc->cfg_cmds.callback = NULL;
5060 mrioc->cfg_cmds.ioc_status = 0;
5061 mrioc->cfg_cmds.ioc_loginfo = 0;
5063 cfg_req->host_tag = cpu_to_le16(MPI3MR_HOSTTAG_CFG_CMDS);
5064 cfg_req->function = MPI3_FUNCTION_CONFIG;
5066 init_completion(&mrioc->cfg_cmds.done);
5067 dprint_cfg_info(mrioc, "posting config request\n");
5068 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5069 dprint_dump(cfg_req, sizeof(struct mpi3_config_request),
5071 retval = mpi3mr_admin_request_post(mrioc, cfg_req, sizeof(*cfg_req), 1);
5073 ioc_err(mrioc, "posting config request failed\n");
5076 wait_for_completion_timeout(&mrioc->cfg_cmds.done, (timeout * HZ));
5077 if (!(mrioc->cfg_cmds.state & MPI3MR_CMD_COMPLETE)) {
5078 mpi3mr_check_rh_fault_ioc(mrioc,
5079 MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT);
5080 ioc_err(mrioc, "config request timed out\n");
5084 *ioc_status = mrioc->cfg_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
5085 if ((*ioc_status) != MPI3_IOCSTATUS_SUCCESS)
5086 dprint_cfg_err(mrioc,
5087 "cfg_page request returned with ioc_status(0x%04x), log_info(0x%08x)\n",
5088 *ioc_status, mrioc->cfg_cmds.ioc_loginfo);
5091 mrioc->cfg_cmds.state = MPI3MR_CMD_NOTUSED;
5092 mutex_unlock(&mrioc->cfg_cmds.mutex);
5099 * mpi3mr_process_cfg_req - config page request processor
5100 * @mrioc: Adapter instance reference
5101 * @cfg_req: Configuration request
5102 * @cfg_hdr: Configuration page header
5103 * @timeout: Timeout in seconds
5104 * @ioc_status: Pointer to return ioc status
5105 * @cfg_buf: Memory pointer to copy config page or header
5106 * @cfg_buf_sz: Size of the memory to get config page or header
5108 * This is handler for config page read, write and config page
5109 * header read operations.
5111 * This function expects the cfg_req to be populated with page
5112 * type, page number, action for the header read and with page
5113 * address for all other operations.
5115 * The cfg_hdr can be passed as null for reading required header
5116 * details for read/write pages the cfg_hdr should point valid
5117 * configuration page header.
5119 * This allocates dmaable memory based on the size of the config
5120 * buffer and set the SGE of the cfg_req.
5122 * For write actions, the config page data has to be passed in
5123 * the cfg_buf and size of the data has to be mentioned in the
5126 * For read/header actions, on successful completion of the
5127 * request with successful ioc_status the data will be copied
5128 * into the cfg_buf limited to a minimum of actual page size and
5132 * Return: 0 on success, non-zero on failure.
5134 static int mpi3mr_process_cfg_req(struct mpi3mr_ioc *mrioc,
5135 struct mpi3_config_request *cfg_req,
5136 struct mpi3_config_page_header *cfg_hdr, int timeout, u16 *ioc_status,
5137 void *cfg_buf, u32 cfg_buf_sz)
5139 struct dma_memory_desc mem_desc;
5141 u8 invalid_action = 0;
5142 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
5144 memset(&mem_desc, 0, sizeof(struct dma_memory_desc));
5146 if (cfg_req->action == MPI3_CONFIG_ACTION_PAGE_HEADER)
5147 mem_desc.size = sizeof(struct mpi3_config_page_header);
5150 ioc_err(mrioc, "null config header passed for config action(%d), page_type(0x%02x), page_num(%d)\n",
5151 cfg_req->action, cfg_req->page_type,
5152 cfg_req->page_number);
5155 switch (cfg_hdr->page_attribute & MPI3_CONFIG_PAGEATTR_MASK) {
5156 case MPI3_CONFIG_PAGEATTR_READ_ONLY:
5158 != MPI3_CONFIG_ACTION_READ_CURRENT)
5161 case MPI3_CONFIG_PAGEATTR_CHANGEABLE:
5162 if ((cfg_req->action ==
5163 MPI3_CONFIG_ACTION_READ_PERSISTENT) ||
5165 MPI3_CONFIG_ACTION_WRITE_PERSISTENT))
5168 case MPI3_CONFIG_PAGEATTR_PERSISTENT:
5172 if (invalid_action) {
5174 "config action(%d) is not allowed for page_type(0x%02x), page_num(%d) with page_attribute(0x%02x)\n",
5175 cfg_req->action, cfg_req->page_type,
5176 cfg_req->page_number, cfg_hdr->page_attribute);
5179 mem_desc.size = le16_to_cpu(cfg_hdr->page_length) * 4;
5180 cfg_req->page_length = cfg_hdr->page_length;
5181 cfg_req->page_version = cfg_hdr->page_version;
5183 if (mpi3mr_alloc_config_dma_memory(mrioc, &mem_desc))
5186 mpi3mr_add_sg_single(&cfg_req->sgl, sgl_flags, mem_desc.size,
5189 if ((cfg_req->action == MPI3_CONFIG_ACTION_WRITE_PERSISTENT) ||
5190 (cfg_req->action == MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5191 memcpy(mem_desc.addr, cfg_buf, min_t(u16, mem_desc.size,
5193 dprint_cfg_info(mrioc, "config buffer to be written\n");
5194 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5195 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5198 if (mpi3mr_post_cfg_req(mrioc, cfg_req, timeout, ioc_status))
5202 if ((*ioc_status == MPI3_IOCSTATUS_SUCCESS) &&
5203 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_PERSISTENT) &&
5204 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5205 memcpy(cfg_buf, mem_desc.addr, min_t(u16, mem_desc.size,
5207 dprint_cfg_info(mrioc, "config buffer read\n");
5208 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5209 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5213 mpi3mr_free_config_dma_memory(mrioc, &mem_desc);
5218 * mpi3mr_cfg_get_dev_pg0 - Read current device page0
5219 * @mrioc: Adapter instance reference
5220 * @ioc_status: Pointer to return ioc status
5221 * @dev_pg0: Pointer to return device page 0
5222 * @pg_sz: Size of the memory allocated to the page pointer
5223 * @form: The form to be used for addressing the page
5224 * @form_spec: Form specific information like device handle
5226 * This is handler for config page read for a specific device
5227 * page0. The ioc_status has the controller returned ioc_status.
5228 * This routine doesn't check ioc_status to decide whether the
5229 * page read is success or not and it is the callers
5232 * Return: 0 on success, non-zero on failure.
5234 int mpi3mr_cfg_get_dev_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5235 struct mpi3_device_page0 *dev_pg0, u16 pg_sz, u32 form, u32 form_spec)
5237 struct mpi3_config_page_header cfg_hdr;
5238 struct mpi3_config_request cfg_req;
5241 memset(dev_pg0, 0, pg_sz);
5242 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5243 memset(&cfg_req, 0, sizeof(cfg_req));
5245 cfg_req.function = MPI3_FUNCTION_CONFIG;
5246 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5247 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DEVICE;
5248 cfg_req.page_number = 0;
5249 cfg_req.page_address = 0;
5251 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5252 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5253 ioc_err(mrioc, "device page0 header read failed\n");
5256 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5257 ioc_err(mrioc, "device page0 header read failed with ioc_status(0x%04x)\n",
5261 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5262 page_address = ((form & MPI3_DEVICE_PGAD_FORM_MASK) |
5263 (form_spec & MPI3_DEVICE_PGAD_HANDLE_MASK));
5264 cfg_req.page_address = cpu_to_le32(page_address);
5265 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5266 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, dev_pg0, pg_sz)) {
5267 ioc_err(mrioc, "device page0 read failed\n");
5277 * mpi3mr_cfg_get_sas_phy_pg0 - Read current SAS Phy page0
5278 * @mrioc: Adapter instance reference
5279 * @ioc_status: Pointer to return ioc status
5280 * @phy_pg0: Pointer to return SAS Phy page 0
5281 * @pg_sz: Size of the memory allocated to the page pointer
5282 * @form: The form to be used for addressing the page
5283 * @form_spec: Form specific information like phy number
5285 * This is handler for config page read for a specific SAS Phy
5286 * page0. The ioc_status has the controller returned ioc_status.
5287 * This routine doesn't check ioc_status to decide whether the
5288 * page read is success or not and it is the callers
5291 * Return: 0 on success, non-zero on failure.
5293 int mpi3mr_cfg_get_sas_phy_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5294 struct mpi3_sas_phy_page0 *phy_pg0, u16 pg_sz, u32 form,
5297 struct mpi3_config_page_header cfg_hdr;
5298 struct mpi3_config_request cfg_req;
5301 memset(phy_pg0, 0, pg_sz);
5302 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5303 memset(&cfg_req, 0, sizeof(cfg_req));
5305 cfg_req.function = MPI3_FUNCTION_CONFIG;
5306 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5307 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5308 cfg_req.page_number = 0;
5309 cfg_req.page_address = 0;
5311 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5312 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5313 ioc_err(mrioc, "sas phy page0 header read failed\n");
5316 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5317 ioc_err(mrioc, "sas phy page0 header read failed with ioc_status(0x%04x)\n",
5321 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5322 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5323 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5324 cfg_req.page_address = cpu_to_le32(page_address);
5325 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5326 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg0, pg_sz)) {
5327 ioc_err(mrioc, "sas phy page0 read failed\n");
5336 * mpi3mr_cfg_get_sas_phy_pg1 - Read current SAS Phy page1
5337 * @mrioc: Adapter instance reference
5338 * @ioc_status: Pointer to return ioc status
5339 * @phy_pg1: Pointer to return SAS Phy page 1
5340 * @pg_sz: Size of the memory allocated to the page pointer
5341 * @form: The form to be used for addressing the page
5342 * @form_spec: Form specific information like phy number
5344 * This is handler for config page read for a specific SAS Phy
5345 * page1. The ioc_status has the controller returned ioc_status.
5346 * This routine doesn't check ioc_status to decide whether the
5347 * page read is success or not and it is the callers
5350 * Return: 0 on success, non-zero on failure.
5352 int mpi3mr_cfg_get_sas_phy_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5353 struct mpi3_sas_phy_page1 *phy_pg1, u16 pg_sz, u32 form,
5356 struct mpi3_config_page_header cfg_hdr;
5357 struct mpi3_config_request cfg_req;
5360 memset(phy_pg1, 0, pg_sz);
5361 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5362 memset(&cfg_req, 0, sizeof(cfg_req));
5364 cfg_req.function = MPI3_FUNCTION_CONFIG;
5365 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5366 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5367 cfg_req.page_number = 1;
5368 cfg_req.page_address = 0;
5370 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5371 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5372 ioc_err(mrioc, "sas phy page1 header read failed\n");
5375 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5376 ioc_err(mrioc, "sas phy page1 header read failed with ioc_status(0x%04x)\n",
5380 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5381 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5382 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5383 cfg_req.page_address = cpu_to_le32(page_address);
5384 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5385 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg1, pg_sz)) {
5386 ioc_err(mrioc, "sas phy page1 read failed\n");
5396 * mpi3mr_cfg_get_sas_exp_pg0 - Read current SAS Expander page0
5397 * @mrioc: Adapter instance reference
5398 * @ioc_status: Pointer to return ioc status
5399 * @exp_pg0: Pointer to return SAS Expander page 0
5400 * @pg_sz: Size of the memory allocated to the page pointer
5401 * @form: The form to be used for addressing the page
5402 * @form_spec: Form specific information like device handle
5404 * This is handler for config page read for a specific SAS
5405 * Expander page0. The ioc_status has the controller returned
5406 * ioc_status. This routine doesn't check ioc_status to decide
5407 * whether the page read is success or not and it is the callers
5410 * Return: 0 on success, non-zero on failure.
5412 int mpi3mr_cfg_get_sas_exp_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5413 struct mpi3_sas_expander_page0 *exp_pg0, u16 pg_sz, u32 form,
5416 struct mpi3_config_page_header cfg_hdr;
5417 struct mpi3_config_request cfg_req;
5420 memset(exp_pg0, 0, pg_sz);
5421 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5422 memset(&cfg_req, 0, sizeof(cfg_req));
5424 cfg_req.function = MPI3_FUNCTION_CONFIG;
5425 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5426 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5427 cfg_req.page_number = 0;
5428 cfg_req.page_address = 0;
5430 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5431 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5432 ioc_err(mrioc, "expander page0 header read failed\n");
5435 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5436 ioc_err(mrioc, "expander page0 header read failed with ioc_status(0x%04x)\n",
5440 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5441 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5442 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5443 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5444 cfg_req.page_address = cpu_to_le32(page_address);
5445 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5446 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg0, pg_sz)) {
5447 ioc_err(mrioc, "expander page0 read failed\n");
5456 * mpi3mr_cfg_get_sas_exp_pg1 - Read current SAS Expander page1
5457 * @mrioc: Adapter instance reference
5458 * @ioc_status: Pointer to return ioc status
5459 * @exp_pg1: Pointer to return SAS Expander page 1
5460 * @pg_sz: Size of the memory allocated to the page pointer
5461 * @form: The form to be used for addressing the page
5462 * @form_spec: Form specific information like phy number
5464 * This is handler for config page read for a specific SAS
5465 * Expander page1. The ioc_status has the controller returned
5466 * ioc_status. This routine doesn't check ioc_status to decide
5467 * whether the page read is success or not and it is the callers
5470 * Return: 0 on success, non-zero on failure.
5472 int mpi3mr_cfg_get_sas_exp_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5473 struct mpi3_sas_expander_page1 *exp_pg1, u16 pg_sz, u32 form,
5476 struct mpi3_config_page_header cfg_hdr;
5477 struct mpi3_config_request cfg_req;
5480 memset(exp_pg1, 0, pg_sz);
5481 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5482 memset(&cfg_req, 0, sizeof(cfg_req));
5484 cfg_req.function = MPI3_FUNCTION_CONFIG;
5485 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5486 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5487 cfg_req.page_number = 1;
5488 cfg_req.page_address = 0;
5490 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5491 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5492 ioc_err(mrioc, "expander page1 header read failed\n");
5495 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5496 ioc_err(mrioc, "expander page1 header read failed with ioc_status(0x%04x)\n",
5500 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5501 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5502 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5503 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5504 cfg_req.page_address = cpu_to_le32(page_address);
5505 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5506 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg1, pg_sz)) {
5507 ioc_err(mrioc, "expander page1 read failed\n");
5516 * mpi3mr_cfg_get_enclosure_pg0 - Read current Enclosure page0
5517 * @mrioc: Adapter instance reference
5518 * @ioc_status: Pointer to return ioc status
5519 * @encl_pg0: Pointer to return Enclosure page 0
5520 * @pg_sz: Size of the memory allocated to the page pointer
5521 * @form: The form to be used for addressing the page
5522 * @form_spec: Form specific information like device handle
5524 * This is handler for config page read for a specific Enclosure
5525 * page0. The ioc_status has the controller returned ioc_status.
5526 * This routine doesn't check ioc_status to decide whether the
5527 * page read is success or not and it is the callers
5530 * Return: 0 on success, non-zero on failure.
5532 int mpi3mr_cfg_get_enclosure_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5533 struct mpi3_enclosure_page0 *encl_pg0, u16 pg_sz, u32 form,
5536 struct mpi3_config_page_header cfg_hdr;
5537 struct mpi3_config_request cfg_req;
5540 memset(encl_pg0, 0, pg_sz);
5541 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5542 memset(&cfg_req, 0, sizeof(cfg_req));
5544 cfg_req.function = MPI3_FUNCTION_CONFIG;
5545 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5546 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_ENCLOSURE;
5547 cfg_req.page_number = 0;
5548 cfg_req.page_address = 0;
5550 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5551 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5552 ioc_err(mrioc, "enclosure page0 header read failed\n");
5555 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5556 ioc_err(mrioc, "enclosure page0 header read failed with ioc_status(0x%04x)\n",
5560 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5561 page_address = ((form & MPI3_ENCLOS_PGAD_FORM_MASK) |
5562 (form_spec & MPI3_ENCLOS_PGAD_HANDLE_MASK));
5563 cfg_req.page_address = cpu_to_le32(page_address);
5564 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5565 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, encl_pg0, pg_sz)) {
5566 ioc_err(mrioc, "enclosure page0 read failed\n");
5576 * mpi3mr_cfg_get_sas_io_unit_pg0 - Read current SASIOUnit page0
5577 * @mrioc: Adapter instance reference
5578 * @sas_io_unit_pg0: Pointer to return SAS IO Unit page 0
5579 * @pg_sz: Size of the memory allocated to the page pointer
5581 * This is handler for config page read for the SAS IO Unit
5582 * page0. This routine checks ioc_status to decide whether the
5583 * page read is success or not.
5585 * Return: 0 on success, non-zero on failure.
5587 int mpi3mr_cfg_get_sas_io_unit_pg0(struct mpi3mr_ioc *mrioc,
5588 struct mpi3_sas_io_unit_page0 *sas_io_unit_pg0, u16 pg_sz)
5590 struct mpi3_config_page_header cfg_hdr;
5591 struct mpi3_config_request cfg_req;
5594 memset(sas_io_unit_pg0, 0, pg_sz);
5595 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5596 memset(&cfg_req, 0, sizeof(cfg_req));
5598 cfg_req.function = MPI3_FUNCTION_CONFIG;
5599 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5600 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5601 cfg_req.page_number = 0;
5602 cfg_req.page_address = 0;
5604 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5605 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5606 ioc_err(mrioc, "sas io unit page0 header read failed\n");
5609 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5610 ioc_err(mrioc, "sas io unit page0 header read failed with ioc_status(0x%04x)\n",
5614 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5616 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5617 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg0, pg_sz)) {
5618 ioc_err(mrioc, "sas io unit page0 read failed\n");
5621 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5622 ioc_err(mrioc, "sas io unit page0 read failed with ioc_status(0x%04x)\n",
5632 * mpi3mr_cfg_get_sas_io_unit_pg1 - Read current SASIOUnit page1
5633 * @mrioc: Adapter instance reference
5634 * @sas_io_unit_pg1: Pointer to return SAS IO Unit page 1
5635 * @pg_sz: Size of the memory allocated to the page pointer
5637 * This is handler for config page read for the SAS IO Unit
5638 * page1. This routine checks ioc_status to decide whether the
5639 * page read is success or not.
5641 * Return: 0 on success, non-zero on failure.
5643 int mpi3mr_cfg_get_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5644 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5646 struct mpi3_config_page_header cfg_hdr;
5647 struct mpi3_config_request cfg_req;
5650 memset(sas_io_unit_pg1, 0, pg_sz);
5651 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5652 memset(&cfg_req, 0, sizeof(cfg_req));
5654 cfg_req.function = MPI3_FUNCTION_CONFIG;
5655 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5656 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5657 cfg_req.page_number = 1;
5658 cfg_req.page_address = 0;
5660 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5661 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5662 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5665 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5666 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5670 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5672 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5673 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5674 ioc_err(mrioc, "sas io unit page1 read failed\n");
5677 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5678 ioc_err(mrioc, "sas io unit page1 read failed with ioc_status(0x%04x)\n",
5688 * mpi3mr_cfg_set_sas_io_unit_pg1 - Write SASIOUnit page1
5689 * @mrioc: Adapter instance reference
5690 * @sas_io_unit_pg1: Pointer to the SAS IO Unit page 1 to write
5691 * @pg_sz: Size of the memory allocated to the page pointer
5693 * This is handler for config page write for the SAS IO Unit
5694 * page1. This routine checks ioc_status to decide whether the
5695 * page read is success or not. This will modify both current
5696 * and persistent page.
5698 * Return: 0 on success, non-zero on failure.
5700 int mpi3mr_cfg_set_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5701 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5703 struct mpi3_config_page_header cfg_hdr;
5704 struct mpi3_config_request cfg_req;
5707 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5708 memset(&cfg_req, 0, sizeof(cfg_req));
5710 cfg_req.function = MPI3_FUNCTION_CONFIG;
5711 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5712 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5713 cfg_req.page_number = 1;
5714 cfg_req.page_address = 0;
5716 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5717 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5718 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5721 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5722 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5726 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_CURRENT;
5728 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5729 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5730 ioc_err(mrioc, "sas io unit page1 write current failed\n");
5733 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5734 ioc_err(mrioc, "sas io unit page1 write current failed with ioc_status(0x%04x)\n",
5739 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_PERSISTENT;
5741 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5742 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5743 ioc_err(mrioc, "sas io unit page1 write persistent failed\n");
5746 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5747 ioc_err(mrioc, "sas io unit page1 write persistent failed with ioc_status(0x%04x)\n",
5757 * mpi3mr_cfg_get_driver_pg1 - Read current Driver page1
5758 * @mrioc: Adapter instance reference
5759 * @driver_pg1: Pointer to return Driver page 1
5760 * @pg_sz: Size of the memory allocated to the page pointer
5762 * This is handler for config page read for the Driver page1.
5763 * This routine checks ioc_status to decide whether the page
5764 * read is success or not.
5766 * Return: 0 on success, non-zero on failure.
5768 int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc *mrioc,
5769 struct mpi3_driver_page1 *driver_pg1, u16 pg_sz)
5771 struct mpi3_config_page_header cfg_hdr;
5772 struct mpi3_config_request cfg_req;
5775 memset(driver_pg1, 0, pg_sz);
5776 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5777 memset(&cfg_req, 0, sizeof(cfg_req));
5779 cfg_req.function = MPI3_FUNCTION_CONFIG;
5780 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5781 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DRIVER;
5782 cfg_req.page_number = 1;
5783 cfg_req.page_address = 0;
5785 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5786 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5787 ioc_err(mrioc, "driver page1 header read failed\n");
5790 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5791 ioc_err(mrioc, "driver page1 header read failed with ioc_status(0x%04x)\n",
5795 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5797 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5798 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, driver_pg1, pg_sz)) {
5799 ioc_err(mrioc, "driver page1 read failed\n");
5802 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5803 ioc_err(mrioc, "driver page1 read failed with ioc_status(0x%04x)\n",