1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Broadcom MPI3 Storage Controllers
5 * Copyright (C) 2017-2023 Broadcom Inc.
6 * (mailto: mpi3mr-linuxdrv.pdl@broadcom.com)
11 #include <linux/io-64-nonatomic-lo-hi.h>
14 mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type, u32 reset_reason);
15 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc);
16 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
17 struct mpi3_ioc_facts_data *facts_data);
18 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc *mrioc,
19 struct mpi3mr_drv_cmd *drv_cmd);
21 static int poll_queues;
22 module_param(poll_queues, int, 0444);
23 MODULE_PARM_DESC(poll_queues, "Number of queues for io_uring poll mode. (Range 1 - 126)");
25 #if defined(writeq) && defined(CONFIG_64BIT)
26 static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
31 static inline void mpi3mr_writeq(__u64 b, volatile void __iomem *addr)
35 writel((u32)(data_out), addr);
36 writel((u32)(data_out >> 32), (addr + 4));
41 mpi3mr_check_req_qfull(struct op_req_qinfo *op_req_q)
43 u16 pi, ci, max_entries;
44 bool is_qfull = false;
47 ci = READ_ONCE(op_req_q->ci);
48 max_entries = op_req_q->num_requests;
50 if ((ci == (pi + 1)) || ((!ci) && (pi == (max_entries - 1))))
56 static void mpi3mr_sync_irqs(struct mpi3mr_ioc *mrioc)
60 max_vectors = mrioc->intr_info_count;
62 for (i = 0; i < max_vectors; i++)
63 synchronize_irq(pci_irq_vector(mrioc->pdev, i));
66 void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc *mrioc)
68 mrioc->intr_enabled = 0;
69 mpi3mr_sync_irqs(mrioc);
72 void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc *mrioc)
74 mrioc->intr_enabled = 1;
77 static void mpi3mr_cleanup_isr(struct mpi3mr_ioc *mrioc)
81 mpi3mr_ioc_disable_intr(mrioc);
83 if (!mrioc->intr_info)
86 for (i = 0; i < mrioc->intr_info_count; i++)
87 free_irq(pci_irq_vector(mrioc->pdev, i),
88 (mrioc->intr_info + i));
90 kfree(mrioc->intr_info);
91 mrioc->intr_info = NULL;
92 mrioc->intr_info_count = 0;
93 mrioc->is_intr_info_set = false;
94 pci_free_irq_vectors(mrioc->pdev);
97 void mpi3mr_add_sg_single(void *paddr, u8 flags, u32 length,
100 struct mpi3_sge_common *sgel = paddr;
103 sgel->length = cpu_to_le32(length);
104 sgel->address = cpu_to_le64(dma_addr);
107 void mpi3mr_build_zero_len_sge(void *paddr)
109 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
111 mpi3mr_add_sg_single(paddr, sgl_flags, 0, -1);
114 void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc *mrioc,
115 dma_addr_t phys_addr)
120 if ((phys_addr < mrioc->reply_buf_dma) ||
121 (phys_addr > mrioc->reply_buf_dma_max_address))
124 return mrioc->reply_buf + (phys_addr - mrioc->reply_buf_dma);
127 void *mpi3mr_get_sensebuf_virt_addr(struct mpi3mr_ioc *mrioc,
128 dma_addr_t phys_addr)
133 return mrioc->sense_buf + (phys_addr - mrioc->sense_buf_dma);
136 static void mpi3mr_repost_reply_buf(struct mpi3mr_ioc *mrioc,
142 spin_lock_irqsave(&mrioc->reply_free_queue_lock, flags);
143 old_idx = mrioc->reply_free_queue_host_index;
144 mrioc->reply_free_queue_host_index = (
145 (mrioc->reply_free_queue_host_index ==
146 (mrioc->reply_free_qsz - 1)) ? 0 :
147 (mrioc->reply_free_queue_host_index + 1));
148 mrioc->reply_free_q[old_idx] = cpu_to_le64(reply_dma);
149 writel(mrioc->reply_free_queue_host_index,
150 &mrioc->sysif_regs->reply_free_host_index);
151 spin_unlock_irqrestore(&mrioc->reply_free_queue_lock, flags);
154 void mpi3mr_repost_sense_buf(struct mpi3mr_ioc *mrioc,
160 spin_lock_irqsave(&mrioc->sbq_lock, flags);
161 old_idx = mrioc->sbq_host_index;
162 mrioc->sbq_host_index = ((mrioc->sbq_host_index ==
163 (mrioc->sense_buf_q_sz - 1)) ? 0 :
164 (mrioc->sbq_host_index + 1));
165 mrioc->sense_buf_q[old_idx] = cpu_to_le64(sense_buf_dma);
166 writel(mrioc->sbq_host_index,
167 &mrioc->sysif_regs->sense_buffer_free_host_index);
168 spin_unlock_irqrestore(&mrioc->sbq_lock, flags);
171 static void mpi3mr_print_event_data(struct mpi3mr_ioc *mrioc,
172 struct mpi3_event_notification_reply *event_reply)
177 event = event_reply->event;
180 case MPI3_EVENT_LOG_DATA:
183 case MPI3_EVENT_CHANGE:
184 desc = "Event Change";
186 case MPI3_EVENT_GPIO_INTERRUPT:
187 desc = "GPIO Interrupt";
189 case MPI3_EVENT_CABLE_MGMT:
190 desc = "Cable Management";
192 case MPI3_EVENT_ENERGY_PACK_CHANGE:
193 desc = "Energy Pack Change";
195 case MPI3_EVENT_DEVICE_ADDED:
197 struct mpi3_device_page0 *event_data =
198 (struct mpi3_device_page0 *)event_reply->event_data;
199 ioc_info(mrioc, "Device Added: dev=0x%04x Form=0x%x\n",
200 event_data->dev_handle, event_data->device_form);
203 case MPI3_EVENT_DEVICE_INFO_CHANGED:
205 struct mpi3_device_page0 *event_data =
206 (struct mpi3_device_page0 *)event_reply->event_data;
207 ioc_info(mrioc, "Device Info Changed: dev=0x%04x Form=0x%x\n",
208 event_data->dev_handle, event_data->device_form);
211 case MPI3_EVENT_DEVICE_STATUS_CHANGE:
213 struct mpi3_event_data_device_status_change *event_data =
214 (struct mpi3_event_data_device_status_change *)event_reply->event_data;
215 ioc_info(mrioc, "Device status Change: dev=0x%04x RC=0x%x\n",
216 event_data->dev_handle, event_data->reason_code);
219 case MPI3_EVENT_SAS_DISCOVERY:
221 struct mpi3_event_data_sas_discovery *event_data =
222 (struct mpi3_event_data_sas_discovery *)event_reply->event_data;
223 ioc_info(mrioc, "SAS Discovery: (%s) status (0x%08x)\n",
224 (event_data->reason_code == MPI3_EVENT_SAS_DISC_RC_STARTED) ?
226 le32_to_cpu(event_data->discovery_status));
229 case MPI3_EVENT_SAS_BROADCAST_PRIMITIVE:
230 desc = "SAS Broadcast Primitive";
232 case MPI3_EVENT_SAS_NOTIFY_PRIMITIVE:
233 desc = "SAS Notify Primitive";
235 case MPI3_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
236 desc = "SAS Init Device Status Change";
238 case MPI3_EVENT_SAS_INIT_TABLE_OVERFLOW:
239 desc = "SAS Init Table Overflow";
241 case MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
242 desc = "SAS Topology Change List";
244 case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE:
245 desc = "Enclosure Device Status Change";
247 case MPI3_EVENT_ENCL_DEVICE_ADDED:
248 desc = "Enclosure Added";
250 case MPI3_EVENT_HARD_RESET_RECEIVED:
251 desc = "Hard Reset Received";
253 case MPI3_EVENT_SAS_PHY_COUNTER:
254 desc = "SAS PHY Counter";
256 case MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR:
257 desc = "SAS Device Discovery Error";
259 case MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST:
260 desc = "PCIE Topology Change List";
262 case MPI3_EVENT_PCIE_ENUMERATION:
264 struct mpi3_event_data_pcie_enumeration *event_data =
265 (struct mpi3_event_data_pcie_enumeration *)event_reply->event_data;
266 ioc_info(mrioc, "PCIE Enumeration: (%s)",
267 (event_data->reason_code ==
268 MPI3_EVENT_PCIE_ENUM_RC_STARTED) ? "start" : "stop");
269 if (event_data->enumeration_status)
270 ioc_info(mrioc, "enumeration_status(0x%08x)\n",
271 le32_to_cpu(event_data->enumeration_status));
274 case MPI3_EVENT_PREPARE_FOR_RESET:
275 desc = "Prepare For Reset";
282 ioc_info(mrioc, "%s\n", desc);
285 static void mpi3mr_handle_events(struct mpi3mr_ioc *mrioc,
286 struct mpi3_default_reply *def_reply)
288 struct mpi3_event_notification_reply *event_reply =
289 (struct mpi3_event_notification_reply *)def_reply;
291 mrioc->change_count = le16_to_cpu(event_reply->ioc_change_count);
292 mpi3mr_print_event_data(mrioc, event_reply);
293 mpi3mr_os_handle_events(mrioc, event_reply);
296 static struct mpi3mr_drv_cmd *
297 mpi3mr_get_drv_cmd(struct mpi3mr_ioc *mrioc, u16 host_tag,
298 struct mpi3_default_reply *def_reply)
303 case MPI3MR_HOSTTAG_INITCMDS:
304 return &mrioc->init_cmds;
305 case MPI3MR_HOSTTAG_CFG_CMDS:
306 return &mrioc->cfg_cmds;
307 case MPI3MR_HOSTTAG_BSG_CMDS:
308 return &mrioc->bsg_cmds;
309 case MPI3MR_HOSTTAG_BLK_TMS:
310 return &mrioc->host_tm_cmds;
311 case MPI3MR_HOSTTAG_PEL_ABORT:
312 return &mrioc->pel_abort_cmd;
313 case MPI3MR_HOSTTAG_PEL_WAIT:
314 return &mrioc->pel_cmds;
315 case MPI3MR_HOSTTAG_TRANSPORT_CMDS:
316 return &mrioc->transport_cmds;
317 case MPI3MR_HOSTTAG_INVALID:
318 if (def_reply && def_reply->function ==
319 MPI3_FUNCTION_EVENT_NOTIFICATION)
320 mpi3mr_handle_events(mrioc, def_reply);
325 if (host_tag >= MPI3MR_HOSTTAG_DEVRMCMD_MIN &&
326 host_tag <= MPI3MR_HOSTTAG_DEVRMCMD_MAX) {
327 idx = host_tag - MPI3MR_HOSTTAG_DEVRMCMD_MIN;
328 return &mrioc->dev_rmhs_cmds[idx];
331 if (host_tag >= MPI3MR_HOSTTAG_EVTACKCMD_MIN &&
332 host_tag <= MPI3MR_HOSTTAG_EVTACKCMD_MAX) {
333 idx = host_tag - MPI3MR_HOSTTAG_EVTACKCMD_MIN;
334 return &mrioc->evtack_cmds[idx];
340 static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc *mrioc,
341 struct mpi3_default_reply_descriptor *reply_desc, u64 *reply_dma)
343 u16 reply_desc_type, host_tag = 0;
344 u16 ioc_status = MPI3_IOCSTATUS_SUCCESS;
346 struct mpi3_status_reply_descriptor *status_desc;
347 struct mpi3_address_reply_descriptor *addr_desc;
348 struct mpi3_success_reply_descriptor *success_desc;
349 struct mpi3_default_reply *def_reply = NULL;
350 struct mpi3mr_drv_cmd *cmdptr = NULL;
351 struct mpi3_scsi_io_reply *scsi_reply;
352 u8 *sense_buf = NULL;
355 reply_desc_type = le16_to_cpu(reply_desc->reply_flags) &
356 MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK;
357 switch (reply_desc_type) {
358 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS:
359 status_desc = (struct mpi3_status_reply_descriptor *)reply_desc;
360 host_tag = le16_to_cpu(status_desc->host_tag);
361 ioc_status = le16_to_cpu(status_desc->ioc_status);
363 MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
364 ioc_loginfo = le32_to_cpu(status_desc->ioc_log_info);
365 ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
367 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY:
368 addr_desc = (struct mpi3_address_reply_descriptor *)reply_desc;
369 *reply_dma = le64_to_cpu(addr_desc->reply_frame_address);
370 def_reply = mpi3mr_get_reply_virt_addr(mrioc, *reply_dma);
373 host_tag = le16_to_cpu(def_reply->host_tag);
374 ioc_status = le16_to_cpu(def_reply->ioc_status);
376 MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL)
377 ioc_loginfo = le32_to_cpu(def_reply->ioc_log_info);
378 ioc_status &= MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_STATUS_MASK;
379 if (def_reply->function == MPI3_FUNCTION_SCSI_IO) {
380 scsi_reply = (struct mpi3_scsi_io_reply *)def_reply;
381 sense_buf = mpi3mr_get_sensebuf_virt_addr(mrioc,
382 le64_to_cpu(scsi_reply->sense_data_buffer_address));
385 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS:
386 success_desc = (struct mpi3_success_reply_descriptor *)reply_desc;
387 host_tag = le16_to_cpu(success_desc->host_tag);
393 cmdptr = mpi3mr_get_drv_cmd(mrioc, host_tag, def_reply);
395 if (cmdptr->state & MPI3MR_CMD_PENDING) {
396 cmdptr->state |= MPI3MR_CMD_COMPLETE;
397 cmdptr->ioc_loginfo = ioc_loginfo;
398 cmdptr->ioc_status = ioc_status;
399 cmdptr->state &= ~MPI3MR_CMD_PENDING;
401 cmdptr->state |= MPI3MR_CMD_REPLY_VALID;
402 memcpy((u8 *)cmdptr->reply, (u8 *)def_reply,
405 if (sense_buf && cmdptr->sensebuf) {
406 cmdptr->is_sense = 1;
407 memcpy(cmdptr->sensebuf, sense_buf,
408 MPI3MR_SENSE_BUF_SZ);
410 if (cmdptr->is_waiting) {
411 complete(&cmdptr->done);
412 cmdptr->is_waiting = 0;
413 } else if (cmdptr->callback)
414 cmdptr->callback(mrioc, cmdptr);
419 mpi3mr_repost_sense_buf(mrioc,
420 le64_to_cpu(scsi_reply->sense_data_buffer_address));
423 int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc *mrioc)
425 u32 exp_phase = mrioc->admin_reply_ephase;
426 u32 admin_reply_ci = mrioc->admin_reply_ci;
427 u32 num_admin_replies = 0;
429 struct mpi3_default_reply_descriptor *reply_desc;
431 if (!atomic_add_unless(&mrioc->admin_reply_q_in_use, 1, 1))
434 reply_desc = (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
437 if ((le16_to_cpu(reply_desc->reply_flags) &
438 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
439 atomic_dec(&mrioc->admin_reply_q_in_use);
444 if (mrioc->unrecoverable)
447 mrioc->admin_req_ci = le16_to_cpu(reply_desc->request_queue_ci);
448 mpi3mr_process_admin_reply_desc(mrioc, reply_desc, &reply_dma);
450 mpi3mr_repost_reply_buf(mrioc, reply_dma);
452 if (++admin_reply_ci == mrioc->num_admin_replies) {
457 (struct mpi3_default_reply_descriptor *)mrioc->admin_reply_base +
459 if ((le16_to_cpu(reply_desc->reply_flags) &
460 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
464 writel(admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
465 mrioc->admin_reply_ci = admin_reply_ci;
466 mrioc->admin_reply_ephase = exp_phase;
467 atomic_dec(&mrioc->admin_reply_q_in_use);
469 return num_admin_replies;
473 * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
474 * queue's consumer index from operational reply descriptor queue.
475 * @op_reply_q: op_reply_qinfo object
476 * @reply_ci: operational reply descriptor's queue consumer index
478 * Returns reply descriptor frame address
480 static inline struct mpi3_default_reply_descriptor *
481 mpi3mr_get_reply_desc(struct op_reply_qinfo *op_reply_q, u32 reply_ci)
483 void *segment_base_addr;
484 struct segments *segments = op_reply_q->q_segments;
485 struct mpi3_default_reply_descriptor *reply_desc = NULL;
488 segments[reply_ci / op_reply_q->segment_qd].segment;
489 reply_desc = (struct mpi3_default_reply_descriptor *)segment_base_addr +
490 (reply_ci % op_reply_q->segment_qd);
495 * mpi3mr_process_op_reply_q - Operational reply queue handler
496 * @mrioc: Adapter instance reference
497 * @op_reply_q: Operational reply queue info
499 * Checks the specific operational reply queue and drains the
500 * reply queue entries until the queue is empty and process the
501 * individual reply descriptors.
503 * Return: 0 if queue is already processed,or number of reply
504 * descriptors processed.
506 int mpi3mr_process_op_reply_q(struct mpi3mr_ioc *mrioc,
507 struct op_reply_qinfo *op_reply_q)
509 struct op_req_qinfo *op_req_q;
512 u32 num_op_reply = 0;
514 struct mpi3_default_reply_descriptor *reply_desc;
515 u16 req_q_idx = 0, reply_qidx;
517 reply_qidx = op_reply_q->qid - 1;
519 if (!atomic_add_unless(&op_reply_q->in_use, 1, 1))
522 exp_phase = op_reply_q->ephase;
523 reply_ci = op_reply_q->ci;
525 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
526 if ((le16_to_cpu(reply_desc->reply_flags) &
527 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase) {
528 atomic_dec(&op_reply_q->in_use);
533 if (mrioc->unrecoverable)
536 req_q_idx = le16_to_cpu(reply_desc->request_queue_id) - 1;
537 op_req_q = &mrioc->req_qinfo[req_q_idx];
539 WRITE_ONCE(op_req_q->ci, le16_to_cpu(reply_desc->request_queue_ci));
540 mpi3mr_process_op_reply_desc(mrioc, reply_desc, &reply_dma,
542 atomic_dec(&op_reply_q->pend_ios);
544 mpi3mr_repost_reply_buf(mrioc, reply_dma);
547 if (++reply_ci == op_reply_q->num_replies) {
552 reply_desc = mpi3mr_get_reply_desc(op_reply_q, reply_ci);
554 if ((le16_to_cpu(reply_desc->reply_flags) &
555 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK) != exp_phase)
557 #ifndef CONFIG_PREEMPT_RT
559 * Exit completion loop to avoid CPU lockup
560 * Ensure remaining completion happens from threaded ISR.
562 if (num_op_reply > mrioc->max_host_ios) {
563 op_reply_q->enable_irq_poll = true;
570 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].consumer_index);
571 op_reply_q->ci = reply_ci;
572 op_reply_q->ephase = exp_phase;
574 atomic_dec(&op_reply_q->in_use);
579 * mpi3mr_blk_mq_poll - Operational reply queue handler
580 * @shost: SCSI Host reference
581 * @queue_num: Request queue number (w.r.t OS it is hardware context number)
583 * Checks the specific operational reply queue and drains the
584 * reply queue entries until the queue is empty and process the
585 * individual reply descriptors.
587 * Return: 0 if queue is already processed,or number of reply
588 * descriptors processed.
590 int mpi3mr_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
593 struct mpi3mr_ioc *mrioc;
595 mrioc = (struct mpi3mr_ioc *)shost->hostdata;
597 if ((mrioc->reset_in_progress || mrioc->prepare_for_reset ||
598 mrioc->unrecoverable))
601 num_entries = mpi3mr_process_op_reply_q(mrioc,
602 &mrioc->op_reply_qinfo[queue_num]);
607 static irqreturn_t mpi3mr_isr_primary(int irq, void *privdata)
609 struct mpi3mr_intr_info *intr_info = privdata;
610 struct mpi3mr_ioc *mrioc;
612 u32 num_admin_replies = 0, num_op_reply = 0;
617 mrioc = intr_info->mrioc;
619 if (!mrioc->intr_enabled)
622 midx = intr_info->msix_index;
625 num_admin_replies = mpi3mr_process_admin_reply_q(mrioc);
626 if (intr_info->op_reply_q)
627 num_op_reply = mpi3mr_process_op_reply_q(mrioc,
628 intr_info->op_reply_q);
630 if (num_admin_replies || num_op_reply)
636 #ifndef CONFIG_PREEMPT_RT
638 static irqreturn_t mpi3mr_isr(int irq, void *privdata)
640 struct mpi3mr_intr_info *intr_info = privdata;
646 /* Call primary ISR routine */
647 ret = mpi3mr_isr_primary(irq, privdata);
650 * If more IOs are expected, schedule IRQ polling thread.
651 * Otherwise exit from ISR.
653 if (!intr_info->op_reply_q)
656 if (!intr_info->op_reply_q->enable_irq_poll ||
657 !atomic_read(&intr_info->op_reply_q->pend_ios))
660 disable_irq_nosync(intr_info->os_irq);
662 return IRQ_WAKE_THREAD;
666 * mpi3mr_isr_poll - Reply queue polling routine
668 * @privdata: Interrupt info
670 * poll for pending I/O completions in a loop until pending I/Os
671 * present or controller queue depth I/Os are processed.
673 * Return: IRQ_NONE or IRQ_HANDLED
675 static irqreturn_t mpi3mr_isr_poll(int irq, void *privdata)
677 struct mpi3mr_intr_info *intr_info = privdata;
678 struct mpi3mr_ioc *mrioc;
680 u32 num_op_reply = 0;
682 if (!intr_info || !intr_info->op_reply_q)
685 mrioc = intr_info->mrioc;
686 midx = intr_info->msix_index;
688 /* Poll for pending IOs completions */
690 if (!mrioc->intr_enabled || mrioc->unrecoverable)
694 mpi3mr_process_admin_reply_q(mrioc);
695 if (intr_info->op_reply_q)
697 mpi3mr_process_op_reply_q(mrioc,
698 intr_info->op_reply_q);
700 usleep_range(MPI3MR_IRQ_POLL_SLEEP, 10 * MPI3MR_IRQ_POLL_SLEEP);
702 } while (atomic_read(&intr_info->op_reply_q->pend_ios) &&
703 (num_op_reply < mrioc->max_host_ios));
705 intr_info->op_reply_q->enable_irq_poll = false;
706 enable_irq(intr_info->os_irq);
714 * mpi3mr_request_irq - Request IRQ and register ISR
715 * @mrioc: Adapter instance reference
716 * @index: IRQ vector index
718 * Request threaded ISR with primary ISR and secondary
720 * Return: 0 on success and non zero on failures.
722 static inline int mpi3mr_request_irq(struct mpi3mr_ioc *mrioc, u16 index)
724 struct pci_dev *pdev = mrioc->pdev;
725 struct mpi3mr_intr_info *intr_info = mrioc->intr_info + index;
728 intr_info->mrioc = mrioc;
729 intr_info->msix_index = index;
730 intr_info->op_reply_q = NULL;
732 snprintf(intr_info->name, MPI3MR_NAME_LENGTH, "%s%d-msix%d",
733 mrioc->driver_name, mrioc->id, index);
735 #ifndef CONFIG_PREEMPT_RT
736 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr,
737 mpi3mr_isr_poll, IRQF_SHARED, intr_info->name, intr_info);
739 retval = request_threaded_irq(pci_irq_vector(pdev, index), mpi3mr_isr_primary,
740 NULL, IRQF_SHARED, intr_info->name, intr_info);
743 ioc_err(mrioc, "%s: Unable to allocate interrupt %d!\n",
744 intr_info->name, pci_irq_vector(pdev, index));
748 intr_info->os_irq = pci_irq_vector(pdev, index);
752 static void mpi3mr_calc_poll_queues(struct mpi3mr_ioc *mrioc, u16 max_vectors)
754 if (!mrioc->requested_poll_qcount)
757 /* Reserved for Admin and Default Queue */
758 if (max_vectors > 2 &&
759 (mrioc->requested_poll_qcount < max_vectors - 2)) {
761 "enabled polled queues (%d) msix (%d)\n",
762 mrioc->requested_poll_qcount, max_vectors);
765 "disabled polled queues (%d) msix (%d) because of no resources for default queue\n",
766 mrioc->requested_poll_qcount, max_vectors);
767 mrioc->requested_poll_qcount = 0;
772 * mpi3mr_setup_isr - Setup ISR for the controller
773 * @mrioc: Adapter instance reference
774 * @setup_one: Request one IRQ or more
776 * Allocate IRQ vectors and call mpi3mr_request_irq to setup ISR
778 * Return: 0 on success and non zero on failures.
780 static int mpi3mr_setup_isr(struct mpi3mr_ioc *mrioc, u8 setup_one)
782 unsigned int irq_flags = PCI_IRQ_MSIX;
783 int max_vectors, min_vec;
786 struct irq_affinity desc = { .pre_vectors = 1, .post_vectors = 1 };
788 if (mrioc->is_intr_info_set)
791 mpi3mr_cleanup_isr(mrioc);
793 if (setup_one || reset_devices) {
795 retval = pci_alloc_irq_vectors(mrioc->pdev,
796 1, max_vectors, irq_flags);
798 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
804 min_t(int, mrioc->cpu_count + 1 +
805 mrioc->requested_poll_qcount, mrioc->msix_count);
807 mpi3mr_calc_poll_queues(mrioc, max_vectors);
810 "MSI-X vectors supported: %d, no of cores: %d,",
811 mrioc->msix_count, mrioc->cpu_count);
813 "MSI-x vectors requested: %d poll_queues %d\n",
814 max_vectors, mrioc->requested_poll_qcount);
816 desc.post_vectors = mrioc->requested_poll_qcount;
817 min_vec = desc.pre_vectors + desc.post_vectors;
818 irq_flags |= PCI_IRQ_AFFINITY | PCI_IRQ_ALL_TYPES;
820 retval = pci_alloc_irq_vectors_affinity(mrioc->pdev,
821 min_vec, max_vectors, irq_flags, &desc);
824 ioc_err(mrioc, "cannot allocate irq vectors, ret %d\n",
831 * If only one MSI-x is allocated, then MSI-x 0 will be shared
832 * between Admin queue and operational queue
834 if (retval == min_vec)
835 mrioc->op_reply_q_offset = 0;
836 else if (retval != (max_vectors)) {
838 "allocated vectors (%d) are less than configured (%d)\n",
839 retval, max_vectors);
842 max_vectors = retval;
843 mrioc->op_reply_q_offset = (max_vectors > 1) ? 1 : 0;
845 mpi3mr_calc_poll_queues(mrioc, max_vectors);
849 mrioc->intr_info = kzalloc(sizeof(struct mpi3mr_intr_info) * max_vectors,
851 if (!mrioc->intr_info) {
853 pci_free_irq_vectors(mrioc->pdev);
856 for (i = 0; i < max_vectors; i++) {
857 retval = mpi3mr_request_irq(mrioc, i);
859 mrioc->intr_info_count = i;
863 if (reset_devices || !setup_one)
864 mrioc->is_intr_info_set = true;
865 mrioc->intr_info_count = max_vectors;
866 mpi3mr_ioc_enable_intr(mrioc);
870 mpi3mr_cleanup_isr(mrioc);
875 static const struct {
876 enum mpi3mr_iocstate value;
879 { MRIOC_STATE_READY, "ready" },
880 { MRIOC_STATE_FAULT, "fault" },
881 { MRIOC_STATE_RESET, "reset" },
882 { MRIOC_STATE_BECOMING_READY, "becoming ready" },
883 { MRIOC_STATE_RESET_REQUESTED, "reset requested" },
884 { MRIOC_STATE_UNRECOVERABLE, "unrecoverable error" },
887 static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state)
892 for (i = 0; i < ARRAY_SIZE(mrioc_states); i++) {
893 if (mrioc_states[i].value == mrioc_state) {
894 name = mrioc_states[i].name;
901 /* Reset reason to name mapper structure*/
902 static const struct {
903 enum mpi3mr_reset_reason value;
905 } mpi3mr_reset_reason_codes[] = {
906 { MPI3MR_RESET_FROM_BRINGUP, "timeout in bringup" },
907 { MPI3MR_RESET_FROM_FAULT_WATCH, "fault" },
908 { MPI3MR_RESET_FROM_APP, "application invocation" },
909 { MPI3MR_RESET_FROM_EH_HOS, "error handling" },
910 { MPI3MR_RESET_FROM_TM_TIMEOUT, "TM timeout" },
911 { MPI3MR_RESET_FROM_APP_TIMEOUT, "application command timeout" },
912 { MPI3MR_RESET_FROM_MUR_FAILURE, "MUR failure" },
913 { MPI3MR_RESET_FROM_CTLR_CLEANUP, "timeout in controller cleanup" },
914 { MPI3MR_RESET_FROM_CIACTIV_FAULT, "component image activation fault" },
915 { MPI3MR_RESET_FROM_PE_TIMEOUT, "port enable timeout" },
916 { MPI3MR_RESET_FROM_TSU_TIMEOUT, "time stamp update timeout" },
917 { MPI3MR_RESET_FROM_DELREQQ_TIMEOUT, "delete request queue timeout" },
918 { MPI3MR_RESET_FROM_DELREPQ_TIMEOUT, "delete reply queue timeout" },
920 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT,
921 "create request queue timeout"
924 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT,
925 "create reply queue timeout"
927 { MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT, "IOC facts timeout" },
928 { MPI3MR_RESET_FROM_IOCINIT_TIMEOUT, "IOC init timeout" },
929 { MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT, "event notify timeout" },
930 { MPI3MR_RESET_FROM_EVTACK_TIMEOUT, "event acknowledgment timeout" },
932 MPI3MR_RESET_FROM_CIACTVRST_TIMER,
933 "component image activation timeout"
936 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT,
937 "get package version timeout"
939 { MPI3MR_RESET_FROM_SYSFS, "sysfs invocation" },
940 { MPI3MR_RESET_FROM_SYSFS_TIMEOUT, "sysfs TM timeout" },
941 { MPI3MR_RESET_FROM_FIRMWARE, "firmware asynchronous reset" },
942 { MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT, "configuration request timeout"},
943 { MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT, "timeout of a SAS transport layer request" },
947 * mpi3mr_reset_rc_name - get reset reason code name
948 * @reason_code: reset reason code value
950 * Map reset reason to an NULL terminated ASCII string
952 * Return: name corresponding to reset reason value or NULL.
954 static const char *mpi3mr_reset_rc_name(enum mpi3mr_reset_reason reason_code)
959 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_reason_codes); i++) {
960 if (mpi3mr_reset_reason_codes[i].value == reason_code) {
961 name = mpi3mr_reset_reason_codes[i].name;
968 /* Reset type to name mapper structure*/
969 static const struct {
972 } mpi3mr_reset_types[] = {
973 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, "soft" },
974 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, "diag fault" },
978 * mpi3mr_reset_type_name - get reset type name
979 * @reset_type: reset type value
981 * Map reset type to an NULL terminated ASCII string
983 * Return: name corresponding to reset type value or NULL.
985 static const char *mpi3mr_reset_type_name(u16 reset_type)
990 for (i = 0; i < ARRAY_SIZE(mpi3mr_reset_types); i++) {
991 if (mpi3mr_reset_types[i].reset_type == reset_type) {
992 name = mpi3mr_reset_types[i].name;
1000 * mpi3mr_print_fault_info - Display fault information
1001 * @mrioc: Adapter instance reference
1003 * Display the controller fault information if there is a
1008 void mpi3mr_print_fault_info(struct mpi3mr_ioc *mrioc)
1010 u32 ioc_status, code, code1, code2, code3;
1012 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1014 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1015 code = readl(&mrioc->sysif_regs->fault);
1016 code1 = readl(&mrioc->sysif_regs->fault_info[0]);
1017 code2 = readl(&mrioc->sysif_regs->fault_info[1]);
1018 code3 = readl(&mrioc->sysif_regs->fault_info[2]);
1021 "fault code(0x%08X): Additional code: (0x%08X:0x%08X:0x%08X)\n",
1022 code, code1, code2, code3);
1027 * mpi3mr_get_iocstate - Get IOC State
1028 * @mrioc: Adapter instance reference
1030 * Return a proper IOC state enum based on the IOC status and
1031 * IOC configuration and unrcoverable state of the controller.
1033 * Return: Current IOC state.
1035 enum mpi3mr_iocstate mpi3mr_get_iocstate(struct mpi3mr_ioc *mrioc)
1037 u32 ioc_status, ioc_config;
1040 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1041 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1043 if (mrioc->unrecoverable)
1044 return MRIOC_STATE_UNRECOVERABLE;
1045 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)
1046 return MRIOC_STATE_FAULT;
1048 ready = (ioc_status & MPI3_SYSIF_IOC_STATUS_READY);
1049 enabled = (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC);
1051 if (ready && enabled)
1052 return MRIOC_STATE_READY;
1053 if ((!ready) && (!enabled))
1054 return MRIOC_STATE_RESET;
1055 if ((!ready) && (enabled))
1056 return MRIOC_STATE_BECOMING_READY;
1058 return MRIOC_STATE_RESET_REQUESTED;
1062 * mpi3mr_clear_reset_history - clear reset history
1063 * @mrioc: Adapter instance reference
1065 * Write the reset history bit in IOC status to clear the bit,
1066 * if it is already set.
1070 static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc *mrioc)
1074 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1075 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1076 writel(ioc_status, &mrioc->sysif_regs->ioc_status);
1080 * mpi3mr_issue_and_process_mur - Message unit Reset handler
1081 * @mrioc: Adapter instance reference
1082 * @reset_reason: Reset reason code
1084 * Issue Message unit Reset to the controller and wait for it to
1087 * Return: 0 on success, -1 on failure.
1089 static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc *mrioc,
1092 u32 ioc_config, timeout, ioc_status;
1095 ioc_info(mrioc, "Issuing Message unit Reset(MUR)\n");
1096 if (mrioc->unrecoverable) {
1097 ioc_info(mrioc, "IOC is unrecoverable MUR not issued\n");
1100 mpi3mr_clear_reset_history(mrioc);
1101 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1102 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1103 ioc_config &= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1104 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1106 timeout = MPI3MR_MUR_TIMEOUT * 10;
1108 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1109 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)) {
1110 mpi3mr_clear_reset_history(mrioc);
1113 if (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) {
1114 mpi3mr_print_fault_info(mrioc);
1118 } while (--timeout);
1120 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1121 if (timeout && !((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1122 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT) ||
1123 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1126 ioc_info(mrioc, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
1127 (!retval) ? "successful" : "failed", ioc_status, ioc_config);
1132 * mpi3mr_revalidate_factsdata - validate IOCFacts parameters
1133 * during reset/resume
1134 * @mrioc: Adapter instance reference
1136 * Return zero if the new IOCFacts parameters value is compatible with
1137 * older values else return -EPERM
1140 mpi3mr_revalidate_factsdata(struct mpi3mr_ioc *mrioc)
1142 unsigned long *removepend_bitmap;
1144 if (mrioc->facts.reply_sz > mrioc->reply_sz) {
1146 "cannot increase reply size from %d to %d\n",
1147 mrioc->reply_sz, mrioc->facts.reply_sz);
1151 if (mrioc->facts.max_op_reply_q < mrioc->num_op_reply_q) {
1153 "cannot reduce number of operational reply queues from %d to %d\n",
1154 mrioc->num_op_reply_q,
1155 mrioc->facts.max_op_reply_q);
1159 if (mrioc->facts.max_op_req_q < mrioc->num_op_req_q) {
1161 "cannot reduce number of operational request queues from %d to %d\n",
1162 mrioc->num_op_req_q, mrioc->facts.max_op_req_q);
1166 if (mrioc->shost->max_sectors != (mrioc->facts.max_data_length / 512))
1167 ioc_err(mrioc, "Warning: The maximum data transfer length\n"
1168 "\tchanged after reset: previous(%d), new(%d),\n"
1169 "the driver cannot change this at run time\n",
1170 mrioc->shost->max_sectors * 512, mrioc->facts.max_data_length);
1172 if ((mrioc->sas_transport_enabled) && (mrioc->facts.ioc_capabilities &
1173 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED))
1175 "critical error: multipath capability is enabled at the\n"
1176 "\tcontroller while sas transport support is enabled at the\n"
1177 "\tdriver, please reboot the system or reload the driver\n");
1179 if (mrioc->facts.max_devhandle > mrioc->dev_handle_bitmap_bits) {
1180 removepend_bitmap = bitmap_zalloc(mrioc->facts.max_devhandle,
1182 if (!removepend_bitmap) {
1184 "failed to increase removepend_bitmap bits from %d to %d\n",
1185 mrioc->dev_handle_bitmap_bits,
1186 mrioc->facts.max_devhandle);
1189 bitmap_free(mrioc->removepend_bitmap);
1190 mrioc->removepend_bitmap = removepend_bitmap;
1192 "increased bits of dev_handle_bitmap from %d to %d\n",
1193 mrioc->dev_handle_bitmap_bits,
1194 mrioc->facts.max_devhandle);
1195 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
1202 * mpi3mr_bring_ioc_ready - Bring controller to ready state
1203 * @mrioc: Adapter instance reference
1205 * Set Enable IOC bit in IOC configuration register and wait for
1206 * the controller to become ready.
1208 * Return: 0 on success, appropriate error on failure.
1210 static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc *mrioc)
1212 u32 ioc_config, ioc_status, timeout, host_diagnostic;
1214 enum mpi3mr_iocstate ioc_state;
1217 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1218 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1219 base_info = lo_hi_readq(&mrioc->sysif_regs->ioc_information);
1220 ioc_info(mrioc, "ioc_status(0x%08x), ioc_config(0x%08x), ioc_info(0x%016llx) at the bringup\n",
1221 ioc_status, ioc_config, base_info);
1223 /*The timeout value is in 2sec unit, changing it to seconds*/
1224 mrioc->ready_timeout =
1225 ((base_info & MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK) >>
1226 MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT) * 2;
1228 ioc_info(mrioc, "ready timeout: %d seconds\n", mrioc->ready_timeout);
1230 ioc_state = mpi3mr_get_iocstate(mrioc);
1231 ioc_info(mrioc, "controller is in %s state during detection\n",
1232 mpi3mr_iocstate_name(ioc_state));
1234 if (ioc_state == MRIOC_STATE_BECOMING_READY ||
1235 ioc_state == MRIOC_STATE_RESET_REQUESTED) {
1236 timeout = mrioc->ready_timeout * 10;
1239 } while (--timeout);
1241 if (!pci_device_is_present(mrioc->pdev)) {
1242 mrioc->unrecoverable = 1;
1244 "controller is not present while waiting to reset\n");
1246 goto out_device_not_present;
1249 ioc_state = mpi3mr_get_iocstate(mrioc);
1251 "controller is in %s state after waiting to reset\n",
1252 mpi3mr_iocstate_name(ioc_state));
1255 if (ioc_state == MRIOC_STATE_READY) {
1256 ioc_info(mrioc, "issuing message unit reset (MUR) to bring to reset state\n");
1257 retval = mpi3mr_issue_and_process_mur(mrioc,
1258 MPI3MR_RESET_FROM_BRINGUP);
1259 ioc_state = mpi3mr_get_iocstate(mrioc);
1262 "message unit reset failed with error %d current state %s\n",
1263 retval, mpi3mr_iocstate_name(ioc_state));
1265 if (ioc_state != MRIOC_STATE_RESET) {
1266 if (ioc_state == MRIOC_STATE_FAULT) {
1267 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
1268 mpi3mr_print_fault_info(mrioc);
1271 readl(&mrioc->sysif_regs->host_diagnostic);
1272 if (!(host_diagnostic &
1273 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
1275 if (!pci_device_is_present(mrioc->pdev)) {
1276 mrioc->unrecoverable = 1;
1277 ioc_err(mrioc, "controller is not present at the bringup\n");
1278 goto out_device_not_present;
1281 } while (--timeout);
1283 mpi3mr_print_fault_info(mrioc);
1284 ioc_info(mrioc, "issuing soft reset to bring to reset state\n");
1285 retval = mpi3mr_issue_reset(mrioc,
1286 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
1287 MPI3MR_RESET_FROM_BRINGUP);
1290 "soft reset failed with error %d\n", retval);
1294 ioc_state = mpi3mr_get_iocstate(mrioc);
1295 if (ioc_state != MRIOC_STATE_RESET) {
1297 "cannot bring controller to reset state, current state: %s\n",
1298 mpi3mr_iocstate_name(ioc_state));
1301 mpi3mr_clear_reset_history(mrioc);
1302 retval = mpi3mr_setup_admin_qpair(mrioc);
1304 ioc_err(mrioc, "failed to setup admin queues: error %d\n",
1309 ioc_info(mrioc, "bringing controller to ready state\n");
1310 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1311 ioc_config |= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC;
1312 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1314 timeout = mrioc->ready_timeout * 10;
1316 ioc_state = mpi3mr_get_iocstate(mrioc);
1317 if (ioc_state == MRIOC_STATE_READY) {
1319 "successfully transitioned to %s state\n",
1320 mpi3mr_iocstate_name(ioc_state));
1323 if (!pci_device_is_present(mrioc->pdev)) {
1324 mrioc->unrecoverable = 1;
1326 "controller is not present at the bringup\n");
1328 goto out_device_not_present;
1331 } while (--timeout);
1334 ioc_state = mpi3mr_get_iocstate(mrioc);
1336 "failed to bring to ready state, current state: %s\n",
1337 mpi3mr_iocstate_name(ioc_state));
1338 out_device_not_present:
1343 * mpi3mr_soft_reset_success - Check softreset is success or not
1344 * @ioc_status: IOC status register value
1345 * @ioc_config: IOC config register value
1347 * Check whether the soft reset is successful or not based on
1348 * IOC status and IOC config register values.
1350 * Return: True when the soft reset is success, false otherwise.
1353 mpi3mr_soft_reset_success(u32 ioc_status, u32 ioc_config)
1355 if (!((ioc_status & MPI3_SYSIF_IOC_STATUS_READY) ||
1356 (ioc_config & MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC)))
1362 * mpi3mr_diagfault_success - Check diag fault is success or not
1363 * @mrioc: Adapter reference
1364 * @ioc_status: IOC status register value
1366 * Check whether the controller hit diag reset fault code.
1368 * Return: True when there is diag fault, false otherwise.
1370 static inline bool mpi3mr_diagfault_success(struct mpi3mr_ioc *mrioc,
1375 if (!(ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT))
1377 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
1378 if (fault == MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET) {
1379 mpi3mr_print_fault_info(mrioc);
1386 * mpi3mr_set_diagsave - Set diag save bit for snapdump
1387 * @mrioc: Adapter reference
1389 * Set diag save bit in IOC configuration register to enable
1394 static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc *mrioc)
1398 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1399 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE;
1400 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
1404 * mpi3mr_issue_reset - Issue reset to the controller
1405 * @mrioc: Adapter reference
1406 * @reset_type: Reset type
1407 * @reset_reason: Reset reason code
1409 * Unlock the host diagnostic registers and write the specific
1410 * reset type to that, wait for reset acknowledgment from the
1411 * controller, if the reset is not successful retry for the
1412 * predefined number of times.
1414 * Return: 0 on success, non-zero on failure.
1416 static int mpi3mr_issue_reset(struct mpi3mr_ioc *mrioc, u16 reset_type,
1420 u8 unlock_retry_count = 0;
1421 u32 host_diagnostic, ioc_status, ioc_config;
1422 u32 timeout = MPI3MR_RESET_ACK_TIMEOUT * 10;
1424 if ((reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET) &&
1425 (reset_type != MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT))
1427 if (mrioc->unrecoverable)
1429 if (reset_reason == MPI3MR_RESET_FROM_FIRMWARE) {
1434 ioc_info(mrioc, "%s reset due to %s(0x%x)\n",
1435 mpi3mr_reset_type_name(reset_type),
1436 mpi3mr_reset_rc_name(reset_reason), reset_reason);
1438 mpi3mr_clear_reset_history(mrioc);
1441 "Write magic sequence to unlock host diag register (retry=%d)\n",
1442 ++unlock_retry_count);
1443 if (unlock_retry_count >= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT) {
1445 "%s reset failed due to unlock failure, host_diagnostic(0x%08x)\n",
1446 mpi3mr_reset_type_name(reset_type),
1448 mrioc->unrecoverable = 1;
1452 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH,
1453 &mrioc->sysif_regs->write_sequence);
1454 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST,
1455 &mrioc->sysif_regs->write_sequence);
1456 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1457 &mrioc->sysif_regs->write_sequence);
1458 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD,
1459 &mrioc->sysif_regs->write_sequence);
1460 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH,
1461 &mrioc->sysif_regs->write_sequence);
1462 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH,
1463 &mrioc->sysif_regs->write_sequence);
1464 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH,
1465 &mrioc->sysif_regs->write_sequence);
1466 usleep_range(1000, 1100);
1467 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
1469 "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
1470 unlock_retry_count, host_diagnostic);
1471 } while (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE));
1473 writel(reset_reason, &mrioc->sysif_regs->scratchpad[0]);
1474 writel(host_diagnostic | reset_type,
1475 &mrioc->sysif_regs->host_diagnostic);
1476 switch (reset_type) {
1477 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET:
1479 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1481 readl(&mrioc->sysif_regs->ioc_configuration);
1482 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY)
1483 && mpi3mr_soft_reset_success(ioc_status, ioc_config)
1485 mpi3mr_clear_reset_history(mrioc);
1490 } while (--timeout);
1491 mpi3mr_print_fault_info(mrioc);
1493 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT:
1495 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1496 if (mpi3mr_diagfault_success(mrioc, ioc_status)) {
1501 } while (--timeout);
1507 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND,
1508 &mrioc->sysif_regs->write_sequence);
1510 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
1511 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
1513 "ioc_status/ioc_onfig after %s reset is (0x%x)/(0x%x)\n",
1514 (!retval)?"successful":"failed", ioc_status,
1517 mrioc->unrecoverable = 1;
1522 * mpi3mr_admin_request_post - Post request to admin queue
1523 * @mrioc: Adapter reference
1524 * @admin_req: MPI3 request
1525 * @admin_req_sz: Request size
1526 * @ignore_reset: Ignore reset in process
1528 * Post the MPI3 request into admin request queue and
1529 * inform the controller, if the queue is full return
1530 * appropriate error.
1532 * Return: 0 on success, non-zero on failure.
1534 int mpi3mr_admin_request_post(struct mpi3mr_ioc *mrioc, void *admin_req,
1535 u16 admin_req_sz, u8 ignore_reset)
1537 u16 areq_pi = 0, areq_ci = 0, max_entries = 0;
1539 unsigned long flags;
1542 if (mrioc->unrecoverable) {
1543 ioc_err(mrioc, "%s : Unrecoverable controller\n", __func__);
1547 spin_lock_irqsave(&mrioc->admin_req_lock, flags);
1548 areq_pi = mrioc->admin_req_pi;
1549 areq_ci = mrioc->admin_req_ci;
1550 max_entries = mrioc->num_admin_req;
1551 if ((areq_ci == (areq_pi + 1)) || ((!areq_ci) &&
1552 (areq_pi == (max_entries - 1)))) {
1553 ioc_err(mrioc, "AdminReqQ full condition detected\n");
1557 if (!ignore_reset && mrioc->reset_in_progress) {
1558 ioc_err(mrioc, "AdminReqQ submit reset in progress\n");
1562 areq_entry = (u8 *)mrioc->admin_req_base +
1563 (areq_pi * MPI3MR_ADMIN_REQ_FRAME_SZ);
1564 memset(areq_entry, 0, MPI3MR_ADMIN_REQ_FRAME_SZ);
1565 memcpy(areq_entry, (u8 *)admin_req, admin_req_sz);
1567 if (++areq_pi == max_entries)
1569 mrioc->admin_req_pi = areq_pi;
1571 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
1574 spin_unlock_irqrestore(&mrioc->admin_req_lock, flags);
1580 * mpi3mr_free_op_req_q_segments - free request memory segments
1581 * @mrioc: Adapter instance reference
1582 * @q_idx: operational request queue index
1584 * Free memory segments allocated for operational request queue
1588 static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1592 struct segments *segments;
1594 segments = mrioc->req_qinfo[q_idx].q_segments;
1598 if (mrioc->enable_segqueue) {
1599 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1600 if (mrioc->req_qinfo[q_idx].q_segment_list) {
1601 dma_free_coherent(&mrioc->pdev->dev,
1602 MPI3MR_MAX_SEG_LIST_SIZE,
1603 mrioc->req_qinfo[q_idx].q_segment_list,
1604 mrioc->req_qinfo[q_idx].q_segment_list_dma);
1605 mrioc->req_qinfo[q_idx].q_segment_list = NULL;
1608 size = mrioc->req_qinfo[q_idx].segment_qd *
1609 mrioc->facts.op_req_sz;
1611 for (j = 0; j < mrioc->req_qinfo[q_idx].num_segments; j++) {
1612 if (!segments[j].segment)
1614 dma_free_coherent(&mrioc->pdev->dev,
1615 size, segments[j].segment, segments[j].segment_dma);
1616 segments[j].segment = NULL;
1618 kfree(mrioc->req_qinfo[q_idx].q_segments);
1619 mrioc->req_qinfo[q_idx].q_segments = NULL;
1620 mrioc->req_qinfo[q_idx].qid = 0;
1624 * mpi3mr_free_op_reply_q_segments - free reply memory segments
1625 * @mrioc: Adapter instance reference
1626 * @q_idx: operational reply queue index
1628 * Free memory segments allocated for operational reply queue
1632 static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 q_idx)
1636 struct segments *segments;
1638 segments = mrioc->op_reply_qinfo[q_idx].q_segments;
1642 if (mrioc->enable_segqueue) {
1643 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1644 if (mrioc->op_reply_qinfo[q_idx].q_segment_list) {
1645 dma_free_coherent(&mrioc->pdev->dev,
1646 MPI3MR_MAX_SEG_LIST_SIZE,
1647 mrioc->op_reply_qinfo[q_idx].q_segment_list,
1648 mrioc->op_reply_qinfo[q_idx].q_segment_list_dma);
1649 mrioc->op_reply_qinfo[q_idx].q_segment_list = NULL;
1652 size = mrioc->op_reply_qinfo[q_idx].segment_qd *
1653 mrioc->op_reply_desc_sz;
1655 for (j = 0; j < mrioc->op_reply_qinfo[q_idx].num_segments; j++) {
1656 if (!segments[j].segment)
1658 dma_free_coherent(&mrioc->pdev->dev,
1659 size, segments[j].segment, segments[j].segment_dma);
1660 segments[j].segment = NULL;
1663 kfree(mrioc->op_reply_qinfo[q_idx].q_segments);
1664 mrioc->op_reply_qinfo[q_idx].q_segments = NULL;
1665 mrioc->op_reply_qinfo[q_idx].qid = 0;
1669 * mpi3mr_delete_op_reply_q - delete operational reply queue
1670 * @mrioc: Adapter instance reference
1671 * @qidx: operational reply queue index
1673 * Delete operatinal reply queue by issuing MPI request
1674 * through admin queue.
1676 * Return: 0 on success, non-zero on failure.
1678 static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1680 struct mpi3_delete_reply_queue_request delq_req;
1681 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1683 u16 reply_qid = 0, midx;
1685 reply_qid = op_reply_q->qid;
1687 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1691 ioc_err(mrioc, "Issue DelRepQ: called with invalid ReqQID\n");
1695 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount-- :
1696 mrioc->active_poll_qcount--;
1698 memset(&delq_req, 0, sizeof(delq_req));
1699 mutex_lock(&mrioc->init_cmds.mutex);
1700 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1702 ioc_err(mrioc, "Issue DelRepQ: Init command is in use\n");
1703 mutex_unlock(&mrioc->init_cmds.mutex);
1706 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1707 mrioc->init_cmds.is_waiting = 1;
1708 mrioc->init_cmds.callback = NULL;
1709 delq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1710 delq_req.function = MPI3_FUNCTION_DELETE_REPLY_QUEUE;
1711 delq_req.queue_id = cpu_to_le16(reply_qid);
1713 init_completion(&mrioc->init_cmds.done);
1714 retval = mpi3mr_admin_request_post(mrioc, &delq_req, sizeof(delq_req),
1717 ioc_err(mrioc, "Issue DelRepQ: Admin Post failed\n");
1720 wait_for_completion_timeout(&mrioc->init_cmds.done,
1721 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1722 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1723 ioc_err(mrioc, "delete reply queue timed out\n");
1724 mpi3mr_check_rh_fault_ioc(mrioc,
1725 MPI3MR_RESET_FROM_DELREPQ_TIMEOUT);
1729 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1730 != MPI3_IOCSTATUS_SUCCESS) {
1732 "Issue DelRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1733 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1734 mrioc->init_cmds.ioc_loginfo);
1738 mrioc->intr_info[midx].op_reply_q = NULL;
1740 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1742 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1743 mutex_unlock(&mrioc->init_cmds.mutex);
1750 * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
1751 * @mrioc: Adapter instance reference
1752 * @qidx: request queue index
1754 * Allocate segmented memory pools for operational reply
1757 * Return: 0 on success, non-zero on failure.
1759 static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1761 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1763 u64 *q_segment_list_entry = NULL;
1764 struct segments *segments;
1766 if (mrioc->enable_segqueue) {
1767 op_reply_q->segment_qd =
1768 MPI3MR_OP_REP_Q_SEG_SIZE / mrioc->op_reply_desc_sz;
1770 size = MPI3MR_OP_REP_Q_SEG_SIZE;
1772 op_reply_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1773 MPI3MR_MAX_SEG_LIST_SIZE, &op_reply_q->q_segment_list_dma,
1775 if (!op_reply_q->q_segment_list)
1777 q_segment_list_entry = (u64 *)op_reply_q->q_segment_list;
1779 op_reply_q->segment_qd = op_reply_q->num_replies;
1780 size = op_reply_q->num_replies * mrioc->op_reply_desc_sz;
1783 op_reply_q->num_segments = DIV_ROUND_UP(op_reply_q->num_replies,
1784 op_reply_q->segment_qd);
1786 op_reply_q->q_segments = kcalloc(op_reply_q->num_segments,
1787 sizeof(struct segments), GFP_KERNEL);
1788 if (!op_reply_q->q_segments)
1791 segments = op_reply_q->q_segments;
1792 for (i = 0; i < op_reply_q->num_segments; i++) {
1793 segments[i].segment =
1794 dma_alloc_coherent(&mrioc->pdev->dev,
1795 size, &segments[i].segment_dma, GFP_KERNEL);
1796 if (!segments[i].segment)
1798 if (mrioc->enable_segqueue)
1799 q_segment_list_entry[i] =
1800 (unsigned long)segments[i].segment_dma;
1807 * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
1808 * @mrioc: Adapter instance reference
1809 * @qidx: request queue index
1811 * Allocate segmented memory pools for operational request
1814 * Return: 0 on success, non-zero on failure.
1816 static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc *mrioc, u16 qidx)
1818 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
1820 u64 *q_segment_list_entry = NULL;
1821 struct segments *segments;
1823 if (mrioc->enable_segqueue) {
1824 op_req_q->segment_qd =
1825 MPI3MR_OP_REQ_Q_SEG_SIZE / mrioc->facts.op_req_sz;
1827 size = MPI3MR_OP_REQ_Q_SEG_SIZE;
1829 op_req_q->q_segment_list = dma_alloc_coherent(&mrioc->pdev->dev,
1830 MPI3MR_MAX_SEG_LIST_SIZE, &op_req_q->q_segment_list_dma,
1832 if (!op_req_q->q_segment_list)
1834 q_segment_list_entry = (u64 *)op_req_q->q_segment_list;
1837 op_req_q->segment_qd = op_req_q->num_requests;
1838 size = op_req_q->num_requests * mrioc->facts.op_req_sz;
1841 op_req_q->num_segments = DIV_ROUND_UP(op_req_q->num_requests,
1842 op_req_q->segment_qd);
1844 op_req_q->q_segments = kcalloc(op_req_q->num_segments,
1845 sizeof(struct segments), GFP_KERNEL);
1846 if (!op_req_q->q_segments)
1849 segments = op_req_q->q_segments;
1850 for (i = 0; i < op_req_q->num_segments; i++) {
1851 segments[i].segment =
1852 dma_alloc_coherent(&mrioc->pdev->dev,
1853 size, &segments[i].segment_dma, GFP_KERNEL);
1854 if (!segments[i].segment)
1856 if (mrioc->enable_segqueue)
1857 q_segment_list_entry[i] =
1858 (unsigned long)segments[i].segment_dma;
1865 * mpi3mr_create_op_reply_q - create operational reply queue
1866 * @mrioc: Adapter instance reference
1867 * @qidx: operational reply queue index
1869 * Create operatinal reply queue by issuing MPI request
1870 * through admin queue.
1872 * Return: 0 on success, non-zero on failure.
1874 static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc *mrioc, u16 qidx)
1876 struct mpi3_create_reply_queue_request create_req;
1877 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
1879 u16 reply_qid = 0, midx;
1881 reply_qid = op_reply_q->qid;
1883 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx, mrioc->op_reply_q_offset);
1887 ioc_err(mrioc, "CreateRepQ: called for duplicate qid %d\n",
1893 reply_qid = qidx + 1;
1894 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD;
1895 if ((mrioc->pdev->device == MPI3_MFGPAGE_DEVID_SAS4116) &&
1896 !mrioc->pdev->revision)
1897 op_reply_q->num_replies = MPI3MR_OP_REP_Q_QD4K;
1899 op_reply_q->ephase = 1;
1900 atomic_set(&op_reply_q->pend_ios, 0);
1901 atomic_set(&op_reply_q->in_use, 0);
1902 op_reply_q->enable_irq_poll = false;
1904 if (!op_reply_q->q_segments) {
1905 retval = mpi3mr_alloc_op_reply_q_segments(mrioc, qidx);
1907 mpi3mr_free_op_reply_q_segments(mrioc, qidx);
1912 memset(&create_req, 0, sizeof(create_req));
1913 mutex_lock(&mrioc->init_cmds.mutex);
1914 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
1916 ioc_err(mrioc, "CreateRepQ: Init command is in use\n");
1919 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
1920 mrioc->init_cmds.is_waiting = 1;
1921 mrioc->init_cmds.callback = NULL;
1922 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
1923 create_req.function = MPI3_FUNCTION_CREATE_REPLY_QUEUE;
1924 create_req.queue_id = cpu_to_le16(reply_qid);
1926 if (midx < (mrioc->intr_info_count - mrioc->requested_poll_qcount))
1927 op_reply_q->qtype = MPI3MR_DEFAULT_QUEUE;
1929 op_reply_q->qtype = MPI3MR_POLL_QUEUE;
1931 if (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) {
1933 MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE;
1934 create_req.msix_index =
1935 cpu_to_le16(mrioc->intr_info[midx].msix_index);
1937 create_req.msix_index = cpu_to_le16(mrioc->intr_info_count - 1);
1938 ioc_info(mrioc, "create reply queue(polled): for qid(%d), midx(%d)\n",
1940 if (!mrioc->active_poll_qcount)
1941 disable_irq_nosync(pci_irq_vector(mrioc->pdev,
1942 mrioc->intr_info_count - 1));
1945 if (mrioc->enable_segqueue) {
1947 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
1948 create_req.base_address = cpu_to_le64(
1949 op_reply_q->q_segment_list_dma);
1951 create_req.base_address = cpu_to_le64(
1952 op_reply_q->q_segments[0].segment_dma);
1954 create_req.size = cpu_to_le16(op_reply_q->num_replies);
1956 init_completion(&mrioc->init_cmds.done);
1957 retval = mpi3mr_admin_request_post(mrioc, &create_req,
1958 sizeof(create_req), 1);
1960 ioc_err(mrioc, "CreateRepQ: Admin Post failed\n");
1963 wait_for_completion_timeout(&mrioc->init_cmds.done,
1964 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
1965 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
1966 ioc_err(mrioc, "create reply queue timed out\n");
1967 mpi3mr_check_rh_fault_ioc(mrioc,
1968 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT);
1972 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
1973 != MPI3_IOCSTATUS_SUCCESS) {
1975 "CreateRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1976 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
1977 mrioc->init_cmds.ioc_loginfo);
1981 op_reply_q->qid = reply_qid;
1982 if (midx < mrioc->intr_info_count)
1983 mrioc->intr_info[midx].op_reply_q = op_reply_q;
1985 (op_reply_q->qtype == MPI3MR_DEFAULT_QUEUE) ? mrioc->default_qcount++ :
1986 mrioc->active_poll_qcount++;
1989 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
1990 mutex_unlock(&mrioc->init_cmds.mutex);
1997 * mpi3mr_create_op_req_q - create operational request queue
1998 * @mrioc: Adapter instance reference
1999 * @idx: operational request queue index
2000 * @reply_qid: Reply queue ID
2002 * Create operatinal request queue by issuing MPI request
2003 * through admin queue.
2005 * Return: 0 on success, non-zero on failure.
2007 static int mpi3mr_create_op_req_q(struct mpi3mr_ioc *mrioc, u16 idx,
2010 struct mpi3_create_request_queue_request create_req;
2011 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + idx;
2015 req_qid = op_req_q->qid;
2019 ioc_err(mrioc, "CreateReqQ: called for duplicate qid %d\n",
2026 op_req_q->num_requests = MPI3MR_OP_REQ_Q_QD;
2029 op_req_q->reply_qid = reply_qid;
2030 spin_lock_init(&op_req_q->q_lock);
2032 if (!op_req_q->q_segments) {
2033 retval = mpi3mr_alloc_op_req_q_segments(mrioc, idx);
2035 mpi3mr_free_op_req_q_segments(mrioc, idx);
2040 memset(&create_req, 0, sizeof(create_req));
2041 mutex_lock(&mrioc->init_cmds.mutex);
2042 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2044 ioc_err(mrioc, "CreateReqQ: Init command is in use\n");
2047 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2048 mrioc->init_cmds.is_waiting = 1;
2049 mrioc->init_cmds.callback = NULL;
2050 create_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2051 create_req.function = MPI3_FUNCTION_CREATE_REQUEST_QUEUE;
2052 create_req.queue_id = cpu_to_le16(req_qid);
2053 if (mrioc->enable_segqueue) {
2055 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED;
2056 create_req.base_address = cpu_to_le64(
2057 op_req_q->q_segment_list_dma);
2059 create_req.base_address = cpu_to_le64(
2060 op_req_q->q_segments[0].segment_dma);
2061 create_req.reply_queue_id = cpu_to_le16(reply_qid);
2062 create_req.size = cpu_to_le16(op_req_q->num_requests);
2064 init_completion(&mrioc->init_cmds.done);
2065 retval = mpi3mr_admin_request_post(mrioc, &create_req,
2066 sizeof(create_req), 1);
2068 ioc_err(mrioc, "CreateReqQ: Admin Post failed\n");
2071 wait_for_completion_timeout(&mrioc->init_cmds.done,
2072 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2073 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2074 ioc_err(mrioc, "create request queue timed out\n");
2075 mpi3mr_check_rh_fault_ioc(mrioc,
2076 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT);
2080 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2081 != MPI3_IOCSTATUS_SUCCESS) {
2083 "CreateReqQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2084 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2085 mrioc->init_cmds.ioc_loginfo);
2089 op_req_q->qid = req_qid;
2092 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2093 mutex_unlock(&mrioc->init_cmds.mutex);
2100 * mpi3mr_create_op_queues - create operational queue pairs
2101 * @mrioc: Adapter instance reference
2103 * Allocate memory for operational queue meta data and call
2104 * create request and reply queue functions.
2106 * Return: 0 on success, non-zero on failures.
2108 static int mpi3mr_create_op_queues(struct mpi3mr_ioc *mrioc)
2111 u16 num_queues = 0, i = 0, msix_count_op_q = 1;
2113 num_queues = min_t(int, mrioc->facts.max_op_reply_q,
2114 mrioc->facts.max_op_req_q);
2117 mrioc->intr_info_count - mrioc->op_reply_q_offset;
2118 if (!mrioc->num_queues)
2119 mrioc->num_queues = min_t(int, num_queues, msix_count_op_q);
2121 * During reset set the num_queues to the number of queues
2122 * that was set before the reset.
2124 num_queues = mrioc->num_op_reply_q ?
2125 mrioc->num_op_reply_q : mrioc->num_queues;
2126 ioc_info(mrioc, "trying to create %d operational queue pairs\n",
2129 if (!mrioc->req_qinfo) {
2130 mrioc->req_qinfo = kcalloc(num_queues,
2131 sizeof(struct op_req_qinfo), GFP_KERNEL);
2132 if (!mrioc->req_qinfo) {
2137 mrioc->op_reply_qinfo = kzalloc(sizeof(struct op_reply_qinfo) *
2138 num_queues, GFP_KERNEL);
2139 if (!mrioc->op_reply_qinfo) {
2145 if (mrioc->enable_segqueue)
2147 "allocating operational queues through segmented queues\n");
2149 for (i = 0; i < num_queues; i++) {
2150 if (mpi3mr_create_op_reply_q(mrioc, i)) {
2151 ioc_err(mrioc, "Cannot create OP RepQ %d\n", i);
2154 if (mpi3mr_create_op_req_q(mrioc, i,
2155 mrioc->op_reply_qinfo[i].qid)) {
2156 ioc_err(mrioc, "Cannot create OP ReqQ %d\n", i);
2157 mpi3mr_delete_op_reply_q(mrioc, i);
2163 /* Not even one queue is created successfully*/
2167 mrioc->num_op_reply_q = mrioc->num_op_req_q = i;
2169 "successfully created %d operational queue pairs(default/polled) queue = (%d/%d)\n",
2170 mrioc->num_op_reply_q, mrioc->default_qcount,
2171 mrioc->active_poll_qcount);
2175 kfree(mrioc->req_qinfo);
2176 mrioc->req_qinfo = NULL;
2178 kfree(mrioc->op_reply_qinfo);
2179 mrioc->op_reply_qinfo = NULL;
2185 * mpi3mr_op_request_post - Post request to operational queue
2186 * @mrioc: Adapter reference
2187 * @op_req_q: Operational request queue info
2188 * @req: MPI3 request
2190 * Post the MPI3 request into operational request queue and
2191 * inform the controller, if the queue is full return
2192 * appropriate error.
2194 * Return: 0 on success, non-zero on failure.
2196 int mpi3mr_op_request_post(struct mpi3mr_ioc *mrioc,
2197 struct op_req_qinfo *op_req_q, u8 *req)
2199 u16 pi = 0, max_entries, reply_qidx = 0, midx;
2201 unsigned long flags;
2203 void *segment_base_addr;
2204 u16 req_sz = mrioc->facts.op_req_sz;
2205 struct segments *segments = op_req_q->q_segments;
2207 reply_qidx = op_req_q->reply_qid - 1;
2209 if (mrioc->unrecoverable)
2212 spin_lock_irqsave(&op_req_q->q_lock, flags);
2214 max_entries = op_req_q->num_requests;
2216 if (mpi3mr_check_req_qfull(op_req_q)) {
2217 midx = REPLY_QUEUE_IDX_TO_MSIX_IDX(
2218 reply_qidx, mrioc->op_reply_q_offset);
2219 mpi3mr_process_op_reply_q(mrioc, mrioc->intr_info[midx].op_reply_q);
2221 if (mpi3mr_check_req_qfull(op_req_q)) {
2227 if (mrioc->reset_in_progress) {
2228 ioc_err(mrioc, "OpReqQ submit reset in progress\n");
2233 segment_base_addr = segments[pi / op_req_q->segment_qd].segment;
2234 req_entry = (u8 *)segment_base_addr +
2235 ((pi % op_req_q->segment_qd) * req_sz);
2237 memset(req_entry, 0, req_sz);
2238 memcpy(req_entry, req, MPI3MR_ADMIN_REQ_FRAME_SZ);
2240 if (++pi == max_entries)
2244 #ifndef CONFIG_PREEMPT_RT
2245 if (atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios)
2246 > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT)
2247 mrioc->op_reply_qinfo[reply_qidx].enable_irq_poll = true;
2249 atomic_inc_return(&mrioc->op_reply_qinfo[reply_qidx].pend_ios);
2252 writel(op_req_q->pi,
2253 &mrioc->sysif_regs->oper_queue_indexes[reply_qidx].producer_index);
2256 spin_unlock_irqrestore(&op_req_q->q_lock, flags);
2261 * mpi3mr_check_rh_fault_ioc - check reset history and fault
2263 * @mrioc: Adapter instance reference
2264 * @reason_code: reason code for the fault.
2266 * This routine will save snapdump and fault the controller with
2267 * the given reason code if it is not already in the fault or
2268 * not asynchronosuly reset. This will be used to handle
2269 * initilaization time faults/resets/timeout as in those cases
2270 * immediate soft reset invocation is not required.
2274 void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc *mrioc, u32 reason_code)
2276 u32 ioc_status, host_diagnostic, timeout;
2278 if (mrioc->unrecoverable) {
2279 ioc_err(mrioc, "controller is unrecoverable\n");
2283 if (!pci_device_is_present(mrioc->pdev)) {
2284 mrioc->unrecoverable = 1;
2285 ioc_err(mrioc, "controller is not present\n");
2289 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2290 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
2291 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
2292 mpi3mr_print_fault_info(mrioc);
2295 mpi3mr_set_diagsave(mrioc);
2296 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
2298 timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
2300 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2301 if (!(host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
2304 } while (--timeout);
2308 * mpi3mr_sync_timestamp - Issue time stamp sync request
2309 * @mrioc: Adapter reference
2311 * Issue IO unit control MPI request to synchornize firmware
2312 * timestamp with host time.
2314 * Return: 0 on success, non-zero on failure.
2316 static int mpi3mr_sync_timestamp(struct mpi3mr_ioc *mrioc)
2318 ktime_t current_time;
2319 struct mpi3_iounit_control_request iou_ctrl;
2322 memset(&iou_ctrl, 0, sizeof(iou_ctrl));
2323 mutex_lock(&mrioc->init_cmds.mutex);
2324 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2326 ioc_err(mrioc, "Issue IOUCTL time_stamp: command is in use\n");
2327 mutex_unlock(&mrioc->init_cmds.mutex);
2330 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2331 mrioc->init_cmds.is_waiting = 1;
2332 mrioc->init_cmds.callback = NULL;
2333 iou_ctrl.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2334 iou_ctrl.function = MPI3_FUNCTION_IO_UNIT_CONTROL;
2335 iou_ctrl.operation = MPI3_CTRL_OP_UPDATE_TIMESTAMP;
2336 current_time = ktime_get_real();
2337 iou_ctrl.param64[0] = cpu_to_le64(ktime_to_ms(current_time));
2339 init_completion(&mrioc->init_cmds.done);
2340 retval = mpi3mr_admin_request_post(mrioc, &iou_ctrl,
2341 sizeof(iou_ctrl), 0);
2343 ioc_err(mrioc, "Issue IOUCTL time_stamp: Admin Post failed\n");
2347 wait_for_completion_timeout(&mrioc->init_cmds.done,
2348 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2349 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2350 ioc_err(mrioc, "Issue IOUCTL time_stamp: command timed out\n");
2351 mrioc->init_cmds.is_waiting = 0;
2352 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
2353 mpi3mr_check_rh_fault_ioc(mrioc,
2354 MPI3MR_RESET_FROM_TSU_TIMEOUT);
2358 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2359 != MPI3_IOCSTATUS_SUCCESS) {
2361 "Issue IOUCTL time_stamp: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2362 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2363 mrioc->init_cmds.ioc_loginfo);
2369 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2370 mutex_unlock(&mrioc->init_cmds.mutex);
2377 * mpi3mr_print_pkg_ver - display controller fw package version
2378 * @mrioc: Adapter reference
2380 * Retrieve firmware package version from the component image
2381 * header of the controller flash and display it.
2383 * Return: 0 on success and non-zero on failure.
2385 static int mpi3mr_print_pkg_ver(struct mpi3mr_ioc *mrioc)
2387 struct mpi3_ci_upload_request ci_upload;
2390 dma_addr_t data_dma;
2391 struct mpi3_ci_manifest_mpi *manifest;
2392 u32 data_len = sizeof(struct mpi3_ci_manifest_mpi);
2393 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2395 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2400 memset(&ci_upload, 0, sizeof(ci_upload));
2401 mutex_lock(&mrioc->init_cmds.mutex);
2402 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2403 ioc_err(mrioc, "sending get package version failed due to command in use\n");
2404 mutex_unlock(&mrioc->init_cmds.mutex);
2407 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2408 mrioc->init_cmds.is_waiting = 1;
2409 mrioc->init_cmds.callback = NULL;
2410 ci_upload.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2411 ci_upload.function = MPI3_FUNCTION_CI_UPLOAD;
2412 ci_upload.msg_flags = MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY;
2413 ci_upload.signature1 = cpu_to_le32(MPI3_IMAGE_HEADER_SIGNATURE1_MANIFEST);
2414 ci_upload.image_offset = cpu_to_le32(MPI3_IMAGE_HEADER_SIZE);
2415 ci_upload.segment_size = cpu_to_le32(data_len);
2417 mpi3mr_add_sg_single(&ci_upload.sgl, sgl_flags, data_len,
2419 init_completion(&mrioc->init_cmds.done);
2420 retval = mpi3mr_admin_request_post(mrioc, &ci_upload,
2421 sizeof(ci_upload), 1);
2423 ioc_err(mrioc, "posting get package version failed\n");
2426 wait_for_completion_timeout(&mrioc->init_cmds.done,
2427 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2428 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2429 ioc_err(mrioc, "get package version timed out\n");
2430 mpi3mr_check_rh_fault_ioc(mrioc,
2431 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT);
2435 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2436 == MPI3_IOCSTATUS_SUCCESS) {
2437 manifest = (struct mpi3_ci_manifest_mpi *) data;
2438 if (manifest->manifest_type == MPI3_CI_MANIFEST_TYPE_MPI) {
2440 "firmware package version(%d.%d.%d.%d.%05d-%05d)\n",
2441 manifest->package_version.gen_major,
2442 manifest->package_version.gen_minor,
2443 manifest->package_version.phase_major,
2444 manifest->package_version.phase_minor,
2445 manifest->package_version.customer_id,
2446 manifest->package_version.build_num);
2451 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2452 mutex_unlock(&mrioc->init_cmds.mutex);
2456 dma_free_coherent(&mrioc->pdev->dev, data_len, data,
2462 * mpi3mr_watchdog_work - watchdog thread to monitor faults
2463 * @work: work struct
2465 * Watch dog work periodically executed (1 second interval) to
2466 * monitor firmware fault and to issue periodic timer sync to
2471 static void mpi3mr_watchdog_work(struct work_struct *work)
2473 struct mpi3mr_ioc *mrioc =
2474 container_of(work, struct mpi3mr_ioc, watchdog_work.work);
2475 unsigned long flags;
2476 enum mpi3mr_iocstate ioc_state;
2477 u32 fault, host_diagnostic, ioc_status;
2478 u32 reset_reason = MPI3MR_RESET_FROM_FAULT_WATCH;
2480 if (mrioc->reset_in_progress)
2483 if (!mrioc->unrecoverable && !pci_device_is_present(mrioc->pdev)) {
2484 ioc_err(mrioc, "watchdog could not detect the controller\n");
2485 mrioc->unrecoverable = 1;
2488 if (mrioc->unrecoverable) {
2490 "flush pending commands for unrecoverable controller\n");
2491 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
2495 if (mrioc->ts_update_counter++ >= MPI3MR_TSUPDATE_INTERVAL) {
2496 mrioc->ts_update_counter = 0;
2497 mpi3mr_sync_timestamp(mrioc);
2500 if ((mrioc->prepare_for_reset) &&
2501 ((mrioc->prepare_for_reset_timeout_counter++) >=
2502 MPI3MR_PREPARE_FOR_RESET_TIMEOUT)) {
2503 mpi3mr_soft_reset_handler(mrioc,
2504 MPI3MR_RESET_FROM_CIACTVRST_TIMER, 1);
2508 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
2509 if (ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) {
2510 mpi3mr_soft_reset_handler(mrioc, MPI3MR_RESET_FROM_FIRMWARE, 0);
2514 /*Check for fault state every one second and issue Soft reset*/
2515 ioc_state = mpi3mr_get_iocstate(mrioc);
2516 if (ioc_state != MRIOC_STATE_FAULT)
2519 fault = readl(&mrioc->sysif_regs->fault) & MPI3_SYSIF_FAULT_CODE_MASK;
2520 host_diagnostic = readl(&mrioc->sysif_regs->host_diagnostic);
2521 if (host_diagnostic & MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS) {
2522 if (!mrioc->diagsave_timeout) {
2523 mpi3mr_print_fault_info(mrioc);
2524 ioc_warn(mrioc, "diag save in progress\n");
2526 if ((mrioc->diagsave_timeout++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT)
2530 mpi3mr_print_fault_info(mrioc);
2531 mrioc->diagsave_timeout = 0;
2534 case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED:
2535 case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED:
2537 "controller requires system power cycle, marking controller as unrecoverable\n");
2538 mrioc->unrecoverable = 1;
2540 case MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS:
2542 case MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET:
2543 reset_reason = MPI3MR_RESET_FROM_CIACTIV_FAULT;
2548 mpi3mr_soft_reset_handler(mrioc, reset_reason, 0);
2552 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2553 if (mrioc->watchdog_work_q)
2554 queue_delayed_work(mrioc->watchdog_work_q,
2555 &mrioc->watchdog_work,
2556 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2557 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2562 * mpi3mr_start_watchdog - Start watchdog
2563 * @mrioc: Adapter instance reference
2565 * Create and start the watchdog thread to monitor controller
2570 void mpi3mr_start_watchdog(struct mpi3mr_ioc *mrioc)
2572 if (mrioc->watchdog_work_q)
2575 INIT_DELAYED_WORK(&mrioc->watchdog_work, mpi3mr_watchdog_work);
2576 snprintf(mrioc->watchdog_work_q_name,
2577 sizeof(mrioc->watchdog_work_q_name), "watchdog_%s%d", mrioc->name,
2579 mrioc->watchdog_work_q =
2580 create_singlethread_workqueue(mrioc->watchdog_work_q_name);
2581 if (!mrioc->watchdog_work_q) {
2582 ioc_err(mrioc, "%s: failed (line=%d)\n", __func__, __LINE__);
2586 if (mrioc->watchdog_work_q)
2587 queue_delayed_work(mrioc->watchdog_work_q,
2588 &mrioc->watchdog_work,
2589 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
2593 * mpi3mr_stop_watchdog - Stop watchdog
2594 * @mrioc: Adapter instance reference
2596 * Stop the watchdog thread created to monitor controller
2601 void mpi3mr_stop_watchdog(struct mpi3mr_ioc *mrioc)
2603 unsigned long flags;
2604 struct workqueue_struct *wq;
2606 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
2607 wq = mrioc->watchdog_work_q;
2608 mrioc->watchdog_work_q = NULL;
2609 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
2611 if (!cancel_delayed_work_sync(&mrioc->watchdog_work))
2612 flush_workqueue(wq);
2613 destroy_workqueue(wq);
2618 * mpi3mr_setup_admin_qpair - Setup admin queue pair
2619 * @mrioc: Adapter instance reference
2621 * Allocate memory for admin queue pair if required and register
2622 * the admin queue with the controller.
2624 * Return: 0 on success, non-zero on failures.
2626 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc *mrioc)
2629 u32 num_admin_entries = 0;
2631 mrioc->admin_req_q_sz = MPI3MR_ADMIN_REQ_Q_SIZE;
2632 mrioc->num_admin_req = mrioc->admin_req_q_sz /
2633 MPI3MR_ADMIN_REQ_FRAME_SZ;
2634 mrioc->admin_req_ci = mrioc->admin_req_pi = 0;
2636 mrioc->admin_reply_q_sz = MPI3MR_ADMIN_REPLY_Q_SIZE;
2637 mrioc->num_admin_replies = mrioc->admin_reply_q_sz /
2638 MPI3MR_ADMIN_REPLY_FRAME_SZ;
2639 mrioc->admin_reply_ci = 0;
2640 mrioc->admin_reply_ephase = 1;
2641 atomic_set(&mrioc->admin_reply_q_in_use, 0);
2643 if (!mrioc->admin_req_base) {
2644 mrioc->admin_req_base = dma_alloc_coherent(&mrioc->pdev->dev,
2645 mrioc->admin_req_q_sz, &mrioc->admin_req_dma, GFP_KERNEL);
2647 if (!mrioc->admin_req_base) {
2652 mrioc->admin_reply_base = dma_alloc_coherent(&mrioc->pdev->dev,
2653 mrioc->admin_reply_q_sz, &mrioc->admin_reply_dma,
2656 if (!mrioc->admin_reply_base) {
2662 num_admin_entries = (mrioc->num_admin_replies << 16) |
2663 (mrioc->num_admin_req);
2664 writel(num_admin_entries, &mrioc->sysif_regs->admin_queue_num_entries);
2665 mpi3mr_writeq(mrioc->admin_req_dma,
2666 &mrioc->sysif_regs->admin_request_queue_address);
2667 mpi3mr_writeq(mrioc->admin_reply_dma,
2668 &mrioc->sysif_regs->admin_reply_queue_address);
2669 writel(mrioc->admin_req_pi, &mrioc->sysif_regs->admin_request_queue_pi);
2670 writel(mrioc->admin_reply_ci, &mrioc->sysif_regs->admin_reply_queue_ci);
2675 if (mrioc->admin_reply_base) {
2676 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
2677 mrioc->admin_reply_base, mrioc->admin_reply_dma);
2678 mrioc->admin_reply_base = NULL;
2680 if (mrioc->admin_req_base) {
2681 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
2682 mrioc->admin_req_base, mrioc->admin_req_dma);
2683 mrioc->admin_req_base = NULL;
2689 * mpi3mr_issue_iocfacts - Send IOC Facts
2690 * @mrioc: Adapter instance reference
2691 * @facts_data: Cached IOC facts data
2693 * Issue IOC Facts MPI request through admin queue and wait for
2694 * the completion of it or time out.
2696 * Return: 0 on success, non-zero on failures.
2698 static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc *mrioc,
2699 struct mpi3_ioc_facts_data *facts_data)
2701 struct mpi3_ioc_facts_request iocfacts_req;
2703 dma_addr_t data_dma;
2704 u32 data_len = sizeof(*facts_data);
2706 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
2708 data = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
2716 memset(&iocfacts_req, 0, sizeof(iocfacts_req));
2717 mutex_lock(&mrioc->init_cmds.mutex);
2718 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
2720 ioc_err(mrioc, "Issue IOCFacts: Init command is in use\n");
2721 mutex_unlock(&mrioc->init_cmds.mutex);
2724 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
2725 mrioc->init_cmds.is_waiting = 1;
2726 mrioc->init_cmds.callback = NULL;
2727 iocfacts_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
2728 iocfacts_req.function = MPI3_FUNCTION_IOC_FACTS;
2730 mpi3mr_add_sg_single(&iocfacts_req.sgl, sgl_flags, data_len,
2733 init_completion(&mrioc->init_cmds.done);
2734 retval = mpi3mr_admin_request_post(mrioc, &iocfacts_req,
2735 sizeof(iocfacts_req), 1);
2737 ioc_err(mrioc, "Issue IOCFacts: Admin Post failed\n");
2740 wait_for_completion_timeout(&mrioc->init_cmds.done,
2741 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
2742 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
2743 ioc_err(mrioc, "ioc_facts timed out\n");
2744 mpi3mr_check_rh_fault_ioc(mrioc,
2745 MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT);
2749 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
2750 != MPI3_IOCSTATUS_SUCCESS) {
2752 "Issue IOCFacts: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2753 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
2754 mrioc->init_cmds.ioc_loginfo);
2758 memcpy(facts_data, (u8 *)data, data_len);
2759 mpi3mr_process_factsdata(mrioc, facts_data);
2761 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
2762 mutex_unlock(&mrioc->init_cmds.mutex);
2766 dma_free_coherent(&mrioc->pdev->dev, data_len, data, data_dma);
2772 * mpi3mr_check_reset_dma_mask - Process IOC facts data
2773 * @mrioc: Adapter instance reference
2775 * Check whether the new DMA mask requested through IOCFacts by
2776 * firmware needs to be set, if so set it .
2778 * Return: 0 on success, non-zero on failure.
2780 static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc *mrioc)
2782 struct pci_dev *pdev = mrioc->pdev;
2784 u64 facts_dma_mask = DMA_BIT_MASK(mrioc->facts.dma_mask);
2786 if (!mrioc->facts.dma_mask || (mrioc->dma_mask <= facts_dma_mask))
2789 ioc_info(mrioc, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
2790 mrioc->dma_mask, facts_dma_mask);
2792 r = dma_set_mask_and_coherent(&pdev->dev, facts_dma_mask);
2794 ioc_err(mrioc, "Setting DMA mask to 0x%016llx failed: %d\n",
2798 mrioc->dma_mask = facts_dma_mask;
2803 * mpi3mr_process_factsdata - Process IOC facts data
2804 * @mrioc: Adapter instance reference
2805 * @facts_data: Cached IOC facts data
2807 * Convert IOC facts data into cpu endianness and cache it in
2812 static void mpi3mr_process_factsdata(struct mpi3mr_ioc *mrioc,
2813 struct mpi3_ioc_facts_data *facts_data)
2815 u32 ioc_config, req_sz, facts_flags;
2817 if ((le16_to_cpu(facts_data->ioc_facts_data_length)) !=
2818 (sizeof(*facts_data) / 4)) {
2820 "IOCFactsdata length mismatch driver_sz(%zu) firmware_sz(%d)\n",
2821 sizeof(*facts_data),
2822 le16_to_cpu(facts_data->ioc_facts_data_length) * 4);
2825 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
2826 req_sz = 1 << ((ioc_config & MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ) >>
2827 MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT);
2828 if (le16_to_cpu(facts_data->ioc_request_frame_size) != (req_sz / 4)) {
2830 "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
2831 req_sz / 4, le16_to_cpu(facts_data->ioc_request_frame_size));
2834 memset(&mrioc->facts, 0, sizeof(mrioc->facts));
2836 facts_flags = le32_to_cpu(facts_data->flags);
2837 mrioc->facts.op_req_sz = req_sz;
2838 mrioc->op_reply_desc_sz = 1 << ((ioc_config &
2839 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ) >>
2840 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT);
2842 mrioc->facts.ioc_num = facts_data->ioc_number;
2843 mrioc->facts.who_init = facts_data->who_init;
2844 mrioc->facts.max_msix_vectors = le16_to_cpu(facts_data->max_msix_vectors);
2845 mrioc->facts.personality = (facts_flags &
2846 MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK);
2847 mrioc->facts.dma_mask = (facts_flags &
2848 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK) >>
2849 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT;
2850 mrioc->facts.protocol_flags = facts_data->protocol_flags;
2851 mrioc->facts.mpi_version = le32_to_cpu(facts_data->mpi_version.word);
2852 mrioc->facts.max_reqs = le16_to_cpu(facts_data->max_outstanding_requests);
2853 mrioc->facts.product_id = le16_to_cpu(facts_data->product_id);
2854 mrioc->facts.reply_sz = le16_to_cpu(facts_data->reply_frame_size) * 4;
2855 mrioc->facts.exceptions = le16_to_cpu(facts_data->ioc_exceptions);
2856 mrioc->facts.max_perids = le16_to_cpu(facts_data->max_persistent_id);
2857 mrioc->facts.max_vds = le16_to_cpu(facts_data->max_vds);
2858 mrioc->facts.max_hpds = le16_to_cpu(facts_data->max_host_pds);
2859 mrioc->facts.max_advhpds = le16_to_cpu(facts_data->max_adv_host_pds);
2860 mrioc->facts.max_raid_pds = le16_to_cpu(facts_data->max_raid_pds);
2861 mrioc->facts.max_nvme = le16_to_cpu(facts_data->max_nvme);
2862 mrioc->facts.max_pcie_switches =
2863 le16_to_cpu(facts_data->max_pcie_switches);
2864 mrioc->facts.max_sasexpanders =
2865 le16_to_cpu(facts_data->max_sas_expanders);
2866 mrioc->facts.max_data_length = le16_to_cpu(facts_data->max_data_length);
2867 mrioc->facts.max_sasinitiators =
2868 le16_to_cpu(facts_data->max_sas_initiators);
2869 mrioc->facts.max_enclosures = le16_to_cpu(facts_data->max_enclosures);
2870 mrioc->facts.min_devhandle = le16_to_cpu(facts_data->min_dev_handle);
2871 mrioc->facts.max_devhandle = le16_to_cpu(facts_data->max_dev_handle);
2872 mrioc->facts.max_op_req_q =
2873 le16_to_cpu(facts_data->max_operational_request_queues);
2874 mrioc->facts.max_op_reply_q =
2875 le16_to_cpu(facts_data->max_operational_reply_queues);
2876 mrioc->facts.ioc_capabilities =
2877 le32_to_cpu(facts_data->ioc_capabilities);
2878 mrioc->facts.fw_ver.build_num =
2879 le16_to_cpu(facts_data->fw_version.build_num);
2880 mrioc->facts.fw_ver.cust_id =
2881 le16_to_cpu(facts_data->fw_version.customer_id);
2882 mrioc->facts.fw_ver.ph_minor = facts_data->fw_version.phase_minor;
2883 mrioc->facts.fw_ver.ph_major = facts_data->fw_version.phase_major;
2884 mrioc->facts.fw_ver.gen_minor = facts_data->fw_version.gen_minor;
2885 mrioc->facts.fw_ver.gen_major = facts_data->fw_version.gen_major;
2886 mrioc->msix_count = min_t(int, mrioc->msix_count,
2887 mrioc->facts.max_msix_vectors);
2888 mrioc->facts.sge_mod_mask = facts_data->sge_modifier_mask;
2889 mrioc->facts.sge_mod_value = facts_data->sge_modifier_value;
2890 mrioc->facts.sge_mod_shift = facts_data->sge_modifier_shift;
2891 mrioc->facts.shutdown_timeout =
2892 le16_to_cpu(facts_data->shutdown_timeout);
2894 mrioc->facts.max_dev_per_tg =
2895 facts_data->max_devices_per_throttle_group;
2896 mrioc->facts.io_throttle_data_length =
2897 le16_to_cpu(facts_data->io_throttle_data_length);
2898 mrioc->facts.max_io_throttle_group =
2899 le16_to_cpu(facts_data->max_io_throttle_group);
2900 mrioc->facts.io_throttle_low = le16_to_cpu(facts_data->io_throttle_low);
2901 mrioc->facts.io_throttle_high =
2902 le16_to_cpu(facts_data->io_throttle_high);
2904 if (mrioc->facts.max_data_length ==
2905 MPI3_IOCFACTS_MAX_DATA_LENGTH_NOT_REPORTED)
2906 mrioc->facts.max_data_length = MPI3MR_DEFAULT_MAX_IO_SIZE;
2908 mrioc->facts.max_data_length *= MPI3MR_PAGE_SIZE_4K;
2909 /* Store in 512b block count */
2910 if (mrioc->facts.io_throttle_data_length)
2911 mrioc->io_throttle_data_length =
2912 (mrioc->facts.io_throttle_data_length * 2 * 4);
2914 /* set the length to 1MB + 1K to disable throttle */
2915 mrioc->io_throttle_data_length = (mrioc->facts.max_data_length / 512) + 2;
2917 mrioc->io_throttle_high = (mrioc->facts.io_throttle_high * 2 * 1024);
2918 mrioc->io_throttle_low = (mrioc->facts.io_throttle_low * 2 * 1024);
2920 ioc_info(mrioc, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
2921 mrioc->facts.ioc_num, mrioc->facts.max_op_req_q,
2922 mrioc->facts.max_op_reply_q, mrioc->facts.max_devhandle);
2924 "maxreqs(%d), mindh(%d) maxvectors(%d) maxperids(%d)\n",
2925 mrioc->facts.max_reqs, mrioc->facts.min_devhandle,
2926 mrioc->facts.max_msix_vectors, mrioc->facts.max_perids);
2927 ioc_info(mrioc, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
2928 mrioc->facts.sge_mod_mask, mrioc->facts.sge_mod_value,
2929 mrioc->facts.sge_mod_shift);
2930 ioc_info(mrioc, "DMA mask %d InitialPE status 0x%x max_data_len (%d)\n",
2931 mrioc->facts.dma_mask, (facts_flags &
2932 MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK), mrioc->facts.max_data_length);
2934 "max_dev_per_throttle_group(%d), max_throttle_groups(%d)\n",
2935 mrioc->facts.max_dev_per_tg, mrioc->facts.max_io_throttle_group);
2937 "io_throttle_data_len(%dKiB), io_throttle_high(%dMiB), io_throttle_low(%dMiB)\n",
2938 mrioc->facts.io_throttle_data_length * 4,
2939 mrioc->facts.io_throttle_high, mrioc->facts.io_throttle_low);
2943 * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
2944 * @mrioc: Adapter instance reference
2946 * Allocate and initialize the reply free buffers, sense
2947 * buffers, reply free queue and sense buffer queue.
2949 * Return: 0 on success, non-zero on failures.
2951 static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc *mrioc)
2956 if (mrioc->init_cmds.reply)
2959 mrioc->init_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2960 if (!mrioc->init_cmds.reply)
2963 mrioc->bsg_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2964 if (!mrioc->bsg_cmds.reply)
2967 mrioc->transport_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2968 if (!mrioc->transport_cmds.reply)
2971 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
2972 mrioc->dev_rmhs_cmds[i].reply = kzalloc(mrioc->reply_sz,
2974 if (!mrioc->dev_rmhs_cmds[i].reply)
2978 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
2979 mrioc->evtack_cmds[i].reply = kzalloc(mrioc->reply_sz,
2981 if (!mrioc->evtack_cmds[i].reply)
2985 mrioc->host_tm_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2986 if (!mrioc->host_tm_cmds.reply)
2989 mrioc->pel_cmds.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2990 if (!mrioc->pel_cmds.reply)
2993 mrioc->pel_abort_cmd.reply = kzalloc(mrioc->reply_sz, GFP_KERNEL);
2994 if (!mrioc->pel_abort_cmd.reply)
2997 mrioc->dev_handle_bitmap_bits = mrioc->facts.max_devhandle;
2998 mrioc->removepend_bitmap = bitmap_zalloc(mrioc->dev_handle_bitmap_bits,
3000 if (!mrioc->removepend_bitmap)
3003 mrioc->devrem_bitmap = bitmap_zalloc(MPI3MR_NUM_DEVRMCMD, GFP_KERNEL);
3004 if (!mrioc->devrem_bitmap)
3007 mrioc->evtack_cmds_bitmap = bitmap_zalloc(MPI3MR_NUM_EVTACKCMD,
3009 if (!mrioc->evtack_cmds_bitmap)
3012 mrioc->num_reply_bufs = mrioc->facts.max_reqs + MPI3MR_NUM_EVT_REPLIES;
3013 mrioc->reply_free_qsz = mrioc->num_reply_bufs + 1;
3014 mrioc->num_sense_bufs = mrioc->facts.max_reqs / MPI3MR_SENSEBUF_FACTOR;
3015 mrioc->sense_buf_q_sz = mrioc->num_sense_bufs + 1;
3017 /* reply buffer pool, 16 byte align */
3018 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3019 mrioc->reply_buf_pool = dma_pool_create("reply_buf pool",
3020 &mrioc->pdev->dev, sz, 16, 0);
3021 if (!mrioc->reply_buf_pool) {
3022 ioc_err(mrioc, "reply buf pool: dma_pool_create failed\n");
3026 mrioc->reply_buf = dma_pool_zalloc(mrioc->reply_buf_pool, GFP_KERNEL,
3027 &mrioc->reply_buf_dma);
3028 if (!mrioc->reply_buf)
3031 mrioc->reply_buf_dma_max_address = mrioc->reply_buf_dma + sz;
3033 /* reply free queue, 8 byte align */
3034 sz = mrioc->reply_free_qsz * 8;
3035 mrioc->reply_free_q_pool = dma_pool_create("reply_free_q pool",
3036 &mrioc->pdev->dev, sz, 8, 0);
3037 if (!mrioc->reply_free_q_pool) {
3038 ioc_err(mrioc, "reply_free_q pool: dma_pool_create failed\n");
3041 mrioc->reply_free_q = dma_pool_zalloc(mrioc->reply_free_q_pool,
3042 GFP_KERNEL, &mrioc->reply_free_q_dma);
3043 if (!mrioc->reply_free_q)
3046 /* sense buffer pool, 4 byte align */
3047 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3048 mrioc->sense_buf_pool = dma_pool_create("sense_buf pool",
3049 &mrioc->pdev->dev, sz, 4, 0);
3050 if (!mrioc->sense_buf_pool) {
3051 ioc_err(mrioc, "sense_buf pool: dma_pool_create failed\n");
3054 mrioc->sense_buf = dma_pool_zalloc(mrioc->sense_buf_pool, GFP_KERNEL,
3055 &mrioc->sense_buf_dma);
3056 if (!mrioc->sense_buf)
3059 /* sense buffer queue, 8 byte align */
3060 sz = mrioc->sense_buf_q_sz * 8;
3061 mrioc->sense_buf_q_pool = dma_pool_create("sense_buf_q pool",
3062 &mrioc->pdev->dev, sz, 8, 0);
3063 if (!mrioc->sense_buf_q_pool) {
3064 ioc_err(mrioc, "sense_buf_q pool: dma_pool_create failed\n");
3067 mrioc->sense_buf_q = dma_pool_zalloc(mrioc->sense_buf_q_pool,
3068 GFP_KERNEL, &mrioc->sense_buf_q_dma);
3069 if (!mrioc->sense_buf_q)
3080 * mpimr_initialize_reply_sbuf_queues - initialize reply sense
3082 * @mrioc: Adapter instance reference
3084 * Helper function to initialize reply and sense buffers along
3085 * with some debug prints.
3089 static void mpimr_initialize_reply_sbuf_queues(struct mpi3mr_ioc *mrioc)
3092 dma_addr_t phy_addr;
3094 sz = mrioc->num_reply_bufs * mrioc->reply_sz;
3096 "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3097 mrioc->reply_buf, mrioc->num_reply_bufs, mrioc->reply_sz,
3098 (sz / 1024), (unsigned long long)mrioc->reply_buf_dma);
3099 sz = mrioc->reply_free_qsz * 8;
3101 "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3102 mrioc->reply_free_q, mrioc->reply_free_qsz, 8, (sz / 1024),
3103 (unsigned long long)mrioc->reply_free_q_dma);
3104 sz = mrioc->num_sense_bufs * MPI3MR_SENSE_BUF_SZ;
3106 "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3107 mrioc->sense_buf, mrioc->num_sense_bufs, MPI3MR_SENSE_BUF_SZ,
3108 (sz / 1024), (unsigned long long)mrioc->sense_buf_dma);
3109 sz = mrioc->sense_buf_q_sz * 8;
3111 "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3112 mrioc->sense_buf_q, mrioc->sense_buf_q_sz, 8, (sz / 1024),
3113 (unsigned long long)mrioc->sense_buf_q_dma);
3115 /* initialize Reply buffer Queue */
3116 for (i = 0, phy_addr = mrioc->reply_buf_dma;
3117 i < mrioc->num_reply_bufs; i++, phy_addr += mrioc->reply_sz)
3118 mrioc->reply_free_q[i] = cpu_to_le64(phy_addr);
3119 mrioc->reply_free_q[i] = cpu_to_le64(0);
3121 /* initialize Sense Buffer Queue */
3122 for (i = 0, phy_addr = mrioc->sense_buf_dma;
3123 i < mrioc->num_sense_bufs; i++, phy_addr += MPI3MR_SENSE_BUF_SZ)
3124 mrioc->sense_buf_q[i] = cpu_to_le64(phy_addr);
3125 mrioc->sense_buf_q[i] = cpu_to_le64(0);
3129 * mpi3mr_issue_iocinit - Send IOC Init
3130 * @mrioc: Adapter instance reference
3132 * Issue IOC Init MPI request through admin queue and wait for
3133 * the completion of it or time out.
3135 * Return: 0 on success, non-zero on failures.
3137 static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
3139 struct mpi3_ioc_init_request iocinit_req;
3140 struct mpi3_driver_info_layout *drv_info;
3141 dma_addr_t data_dma;
3142 u32 data_len = sizeof(*drv_info);
3144 ktime_t current_time;
3146 drv_info = dma_alloc_coherent(&mrioc->pdev->dev, data_len, &data_dma,
3152 mpimr_initialize_reply_sbuf_queues(mrioc);
3154 drv_info->information_length = cpu_to_le32(data_len);
3155 strscpy(drv_info->driver_signature, "Broadcom", sizeof(drv_info->driver_signature));
3156 strscpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));
3157 strscpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));
3158 strscpy(drv_info->driver_name, MPI3MR_DRIVER_NAME, sizeof(drv_info->driver_name));
3159 strscpy(drv_info->driver_version, MPI3MR_DRIVER_VERSION, sizeof(drv_info->driver_version));
3160 strscpy(drv_info->driver_release_date, MPI3MR_DRIVER_RELDATE,
3161 sizeof(drv_info->driver_release_date));
3162 drv_info->driver_capabilities = 0;
3163 memcpy((u8 *)&mrioc->driver_info, (u8 *)drv_info,
3164 sizeof(mrioc->driver_info));
3166 memset(&iocinit_req, 0, sizeof(iocinit_req));
3167 mutex_lock(&mrioc->init_cmds.mutex);
3168 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3170 ioc_err(mrioc, "Issue IOCInit: Init command is in use\n");
3171 mutex_unlock(&mrioc->init_cmds.mutex);
3174 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3175 mrioc->init_cmds.is_waiting = 1;
3176 mrioc->init_cmds.callback = NULL;
3177 iocinit_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3178 iocinit_req.function = MPI3_FUNCTION_IOC_INIT;
3179 iocinit_req.mpi_version.mpi3_version.dev = MPI3_VERSION_DEV;
3180 iocinit_req.mpi_version.mpi3_version.unit = MPI3_VERSION_UNIT;
3181 iocinit_req.mpi_version.mpi3_version.major = MPI3_VERSION_MAJOR;
3182 iocinit_req.mpi_version.mpi3_version.minor = MPI3_VERSION_MINOR;
3183 iocinit_req.who_init = MPI3_WHOINIT_HOST_DRIVER;
3184 iocinit_req.reply_free_queue_depth = cpu_to_le16(mrioc->reply_free_qsz);
3185 iocinit_req.reply_free_queue_address =
3186 cpu_to_le64(mrioc->reply_free_q_dma);
3187 iocinit_req.sense_buffer_length = cpu_to_le16(MPI3MR_SENSE_BUF_SZ);
3188 iocinit_req.sense_buffer_free_queue_depth =
3189 cpu_to_le16(mrioc->sense_buf_q_sz);
3190 iocinit_req.sense_buffer_free_queue_address =
3191 cpu_to_le64(mrioc->sense_buf_q_dma);
3192 iocinit_req.driver_information_address = cpu_to_le64(data_dma);
3194 current_time = ktime_get_real();
3195 iocinit_req.time_stamp = cpu_to_le64(ktime_to_ms(current_time));
3197 init_completion(&mrioc->init_cmds.done);
3198 retval = mpi3mr_admin_request_post(mrioc, &iocinit_req,
3199 sizeof(iocinit_req), 1);
3201 ioc_err(mrioc, "Issue IOCInit: Admin Post failed\n");
3204 wait_for_completion_timeout(&mrioc->init_cmds.done,
3205 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3206 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3207 mpi3mr_check_rh_fault_ioc(mrioc,
3208 MPI3MR_RESET_FROM_IOCINIT_TIMEOUT);
3209 ioc_err(mrioc, "ioc_init timed out\n");
3213 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3214 != MPI3_IOCSTATUS_SUCCESS) {
3216 "Issue IOCInit: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3217 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3218 mrioc->init_cmds.ioc_loginfo);
3223 mrioc->reply_free_queue_host_index = mrioc->num_reply_bufs;
3224 writel(mrioc->reply_free_queue_host_index,
3225 &mrioc->sysif_regs->reply_free_host_index);
3227 mrioc->sbq_host_index = mrioc->num_sense_bufs;
3228 writel(mrioc->sbq_host_index,
3229 &mrioc->sysif_regs->sense_buffer_free_host_index);
3231 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3232 mutex_unlock(&mrioc->init_cmds.mutex);
3236 dma_free_coherent(&mrioc->pdev->dev, data_len, drv_info,
3243 * mpi3mr_unmask_events - Unmask events in event mask bitmap
3244 * @mrioc: Adapter instance reference
3245 * @event: MPI event ID
3247 * Un mask the specific event by resetting the event_mask
3250 * Return: 0 on success, non-zero on failures.
3252 static void mpi3mr_unmask_events(struct mpi3mr_ioc *mrioc, u16 event)
3260 desired_event = (1 << (event % 32));
3263 mrioc->event_masks[word] &= ~desired_event;
3267 * mpi3mr_issue_event_notification - Send event notification
3268 * @mrioc: Adapter instance reference
3270 * Issue event notification MPI request through admin queue and
3271 * wait for the completion of it or time out.
3273 * Return: 0 on success, non-zero on failures.
3275 static int mpi3mr_issue_event_notification(struct mpi3mr_ioc *mrioc)
3277 struct mpi3_event_notification_request evtnotify_req;
3281 memset(&evtnotify_req, 0, sizeof(evtnotify_req));
3282 mutex_lock(&mrioc->init_cmds.mutex);
3283 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3285 ioc_err(mrioc, "Issue EvtNotify: Init command is in use\n");
3286 mutex_unlock(&mrioc->init_cmds.mutex);
3289 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3290 mrioc->init_cmds.is_waiting = 1;
3291 mrioc->init_cmds.callback = NULL;
3292 evtnotify_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3293 evtnotify_req.function = MPI3_FUNCTION_EVENT_NOTIFICATION;
3294 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3295 evtnotify_req.event_masks[i] =
3296 cpu_to_le32(mrioc->event_masks[i]);
3297 init_completion(&mrioc->init_cmds.done);
3298 retval = mpi3mr_admin_request_post(mrioc, &evtnotify_req,
3299 sizeof(evtnotify_req), 1);
3301 ioc_err(mrioc, "Issue EvtNotify: Admin Post failed\n");
3304 wait_for_completion_timeout(&mrioc->init_cmds.done,
3305 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3306 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3307 ioc_err(mrioc, "event notification timed out\n");
3308 mpi3mr_check_rh_fault_ioc(mrioc,
3309 MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT);
3313 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3314 != MPI3_IOCSTATUS_SUCCESS) {
3316 "Issue EvtNotify: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3317 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3318 mrioc->init_cmds.ioc_loginfo);
3324 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3325 mutex_unlock(&mrioc->init_cmds.mutex);
3331 * mpi3mr_process_event_ack - Process event acknowledgment
3332 * @mrioc: Adapter instance reference
3333 * @event: MPI3 event ID
3334 * @event_ctx: event context
3336 * Send event acknowledgment through admin queue and wait for
3339 * Return: 0 on success, non-zero on failures.
3341 int mpi3mr_process_event_ack(struct mpi3mr_ioc *mrioc, u8 event,
3344 struct mpi3_event_ack_request evtack_req;
3347 memset(&evtack_req, 0, sizeof(evtack_req));
3348 mutex_lock(&mrioc->init_cmds.mutex);
3349 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3351 ioc_err(mrioc, "Send EvtAck: Init command is in use\n");
3352 mutex_unlock(&mrioc->init_cmds.mutex);
3355 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3356 mrioc->init_cmds.is_waiting = 1;
3357 mrioc->init_cmds.callback = NULL;
3358 evtack_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3359 evtack_req.function = MPI3_FUNCTION_EVENT_ACK;
3360 evtack_req.event = event;
3361 evtack_req.event_context = cpu_to_le32(event_ctx);
3363 init_completion(&mrioc->init_cmds.done);
3364 retval = mpi3mr_admin_request_post(mrioc, &evtack_req,
3365 sizeof(evtack_req), 1);
3367 ioc_err(mrioc, "Send EvtAck: Admin Post failed\n");
3370 wait_for_completion_timeout(&mrioc->init_cmds.done,
3371 (MPI3MR_INTADMCMD_TIMEOUT * HZ));
3372 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3373 ioc_err(mrioc, "Issue EvtNotify: command timed out\n");
3374 if (!(mrioc->init_cmds.state & MPI3MR_CMD_RESET))
3375 mpi3mr_check_rh_fault_ioc(mrioc,
3376 MPI3MR_RESET_FROM_EVTACK_TIMEOUT);
3380 if ((mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK)
3381 != MPI3_IOCSTATUS_SUCCESS) {
3383 "Send EvtAck: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3384 (mrioc->init_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK),
3385 mrioc->init_cmds.ioc_loginfo);
3391 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3392 mutex_unlock(&mrioc->init_cmds.mutex);
3398 * mpi3mr_alloc_chain_bufs - Allocate chain buffers
3399 * @mrioc: Adapter instance reference
3401 * Allocate chain buffers and set a bitmap to indicate free
3402 * chain buffers. Chain buffers are used to pass the SGE
3403 * information along with MPI3 SCSI IO requests for host I/O.
3405 * Return: 0 on success, non-zero on failure
3407 static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc *mrioc)
3413 if (mrioc->chain_sgl_list)
3416 num_chains = mrioc->max_host_ios / MPI3MR_CHAINBUF_FACTOR;
3418 if (prot_mask & (SHOST_DIX_TYPE0_PROTECTION
3419 | SHOST_DIX_TYPE1_PROTECTION
3420 | SHOST_DIX_TYPE2_PROTECTION
3421 | SHOST_DIX_TYPE3_PROTECTION))
3422 num_chains += (num_chains / MPI3MR_CHAINBUFDIX_FACTOR);
3424 mrioc->chain_buf_count = num_chains;
3425 sz = sizeof(struct chain_element) * num_chains;
3426 mrioc->chain_sgl_list = kzalloc(sz, GFP_KERNEL);
3427 if (!mrioc->chain_sgl_list)
3430 if (mrioc->max_sgl_entries > (mrioc->facts.max_data_length /
3431 MPI3MR_PAGE_SIZE_4K))
3432 mrioc->max_sgl_entries = mrioc->facts.max_data_length /
3433 MPI3MR_PAGE_SIZE_4K;
3434 sz = mrioc->max_sgl_entries * sizeof(struct mpi3_sge_common);
3435 ioc_info(mrioc, "number of sgl entries=%d chain buffer size=%dKB\n",
3436 mrioc->max_sgl_entries, sz/1024);
3438 mrioc->chain_buf_pool = dma_pool_create("chain_buf pool",
3439 &mrioc->pdev->dev, sz, 16, 0);
3440 if (!mrioc->chain_buf_pool) {
3441 ioc_err(mrioc, "chain buf pool: dma_pool_create failed\n");
3445 for (i = 0; i < num_chains; i++) {
3446 mrioc->chain_sgl_list[i].addr =
3447 dma_pool_zalloc(mrioc->chain_buf_pool, GFP_KERNEL,
3448 &mrioc->chain_sgl_list[i].dma_addr);
3450 if (!mrioc->chain_sgl_list[i].addr)
3453 mrioc->chain_bitmap = bitmap_zalloc(num_chains, GFP_KERNEL);
3454 if (!mrioc->chain_bitmap)
3463 * mpi3mr_port_enable_complete - Mark port enable complete
3464 * @mrioc: Adapter instance reference
3465 * @drv_cmd: Internal command tracker
3467 * Call back for asynchronous port enable request sets the
3468 * driver command to indicate port enable request is complete.
3472 static void mpi3mr_port_enable_complete(struct mpi3mr_ioc *mrioc,
3473 struct mpi3mr_drv_cmd *drv_cmd)
3475 drv_cmd->callback = NULL;
3476 mrioc->scan_started = 0;
3477 if (drv_cmd->state & MPI3MR_CMD_RESET)
3478 mrioc->scan_failed = MPI3_IOCSTATUS_INTERNAL_ERROR;
3480 mrioc->scan_failed = drv_cmd->ioc_status;
3481 drv_cmd->state = MPI3MR_CMD_NOTUSED;
3485 * mpi3mr_issue_port_enable - Issue Port Enable
3486 * @mrioc: Adapter instance reference
3487 * @async: Flag to wait for completion or not
3489 * Issue Port Enable MPI request through admin queue and if the
3490 * async flag is not set wait for the completion of the port
3491 * enable or time out.
3493 * Return: 0 on success, non-zero on failures.
3495 int mpi3mr_issue_port_enable(struct mpi3mr_ioc *mrioc, u8 async)
3497 struct mpi3_port_enable_request pe_req;
3499 u32 pe_timeout = MPI3MR_PORTENABLE_TIMEOUT;
3501 memset(&pe_req, 0, sizeof(pe_req));
3502 mutex_lock(&mrioc->init_cmds.mutex);
3503 if (mrioc->init_cmds.state & MPI3MR_CMD_PENDING) {
3505 ioc_err(mrioc, "Issue PortEnable: Init command is in use\n");
3506 mutex_unlock(&mrioc->init_cmds.mutex);
3509 mrioc->init_cmds.state = MPI3MR_CMD_PENDING;
3511 mrioc->init_cmds.is_waiting = 0;
3512 mrioc->init_cmds.callback = mpi3mr_port_enable_complete;
3514 mrioc->init_cmds.is_waiting = 1;
3515 mrioc->init_cmds.callback = NULL;
3516 init_completion(&mrioc->init_cmds.done);
3518 pe_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS);
3519 pe_req.function = MPI3_FUNCTION_PORT_ENABLE;
3521 retval = mpi3mr_admin_request_post(mrioc, &pe_req, sizeof(pe_req), 1);
3523 ioc_err(mrioc, "Issue PortEnable: Admin Post failed\n");
3527 mutex_unlock(&mrioc->init_cmds.mutex);
3531 wait_for_completion_timeout(&mrioc->init_cmds.done, (pe_timeout * HZ));
3532 if (!(mrioc->init_cmds.state & MPI3MR_CMD_COMPLETE)) {
3533 ioc_err(mrioc, "port enable timed out\n");
3535 mpi3mr_check_rh_fault_ioc(mrioc, MPI3MR_RESET_FROM_PE_TIMEOUT);
3538 mpi3mr_port_enable_complete(mrioc, &mrioc->init_cmds);
3541 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
3542 mutex_unlock(&mrioc->init_cmds.mutex);
3547 /* Protocol type to name mapper structure */
3548 static const struct {
3551 } mpi3mr_protocols[] = {
3552 { MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR, "Initiator" },
3553 { MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET, "Target" },
3554 { MPI3_IOCFACTS_PROTOCOL_NVME, "NVMe attachment" },
3557 /* Capability to name mapper structure*/
3558 static const struct {
3561 } mpi3mr_capabilities[] = {
3562 { MPI3_IOCFACTS_CAPABILITY_RAID_CAPABLE, "RAID" },
3563 { MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED, "MultiPath" },
3567 * mpi3mr_print_ioc_info - Display controller information
3568 * @mrioc: Adapter instance reference
3570 * Display controller personalit, capability, supported
3576 mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
3578 int i = 0, bytes_written = 0;
3579 char personality[16];
3580 char protocol[50] = {0};
3581 char capabilities[100] = {0};
3582 struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
3584 switch (mrioc->facts.personality) {
3585 case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
3586 strncpy(personality, "Enhanced HBA", sizeof(personality));
3588 case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
3589 strncpy(personality, "RAID", sizeof(personality));
3592 strncpy(personality, "Unknown", sizeof(personality));
3596 ioc_info(mrioc, "Running in %s Personality", personality);
3598 ioc_info(mrioc, "FW version(%d.%d.%d.%d.%d.%d)\n",
3599 fwver->gen_major, fwver->gen_minor, fwver->ph_major,
3600 fwver->ph_minor, fwver->cust_id, fwver->build_num);
3602 for (i = 0; i < ARRAY_SIZE(mpi3mr_protocols); i++) {
3603 if (mrioc->facts.protocol_flags &
3604 mpi3mr_protocols[i].protocol) {
3605 bytes_written += scnprintf(protocol + bytes_written,
3606 sizeof(protocol) - bytes_written, "%s%s",
3607 bytes_written ? "," : "",
3608 mpi3mr_protocols[i].name);
3613 for (i = 0; i < ARRAY_SIZE(mpi3mr_capabilities); i++) {
3614 if (mrioc->facts.protocol_flags &
3615 mpi3mr_capabilities[i].capability) {
3616 bytes_written += scnprintf(capabilities + bytes_written,
3617 sizeof(capabilities) - bytes_written, "%s%s",
3618 bytes_written ? "," : "",
3619 mpi3mr_capabilities[i].name);
3623 ioc_info(mrioc, "Protocol=(%s), Capabilities=(%s)\n",
3624 protocol, capabilities);
3628 * mpi3mr_cleanup_resources - Free PCI resources
3629 * @mrioc: Adapter instance reference
3631 * Unmap PCI device memory and disable PCI device.
3633 * Return: 0 on success and non-zero on failure.
3635 void mpi3mr_cleanup_resources(struct mpi3mr_ioc *mrioc)
3637 struct pci_dev *pdev = mrioc->pdev;
3639 mpi3mr_cleanup_isr(mrioc);
3641 if (mrioc->sysif_regs) {
3642 iounmap((void __iomem *)mrioc->sysif_regs);
3643 mrioc->sysif_regs = NULL;
3646 if (pci_is_enabled(pdev)) {
3648 pci_release_selected_regions(pdev, mrioc->bars);
3649 pci_disable_device(pdev);
3654 * mpi3mr_setup_resources - Enable PCI resources
3655 * @mrioc: Adapter instance reference
3657 * Enable PCI device memory, MSI-x registers and set DMA mask.
3659 * Return: 0 on success and non-zero on failure.
3661 int mpi3mr_setup_resources(struct mpi3mr_ioc *mrioc)
3663 struct pci_dev *pdev = mrioc->pdev;
3665 int i, retval = 0, capb = 0;
3666 u16 message_control;
3667 u64 dma_mask = mrioc->dma_mask ? mrioc->dma_mask :
3668 ((sizeof(dma_addr_t) > 4) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
3670 if (pci_enable_device_mem(pdev)) {
3671 ioc_err(mrioc, "pci_enable_device_mem: failed\n");
3676 capb = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
3678 ioc_err(mrioc, "Unable to find MSI-X Capabilities\n");
3682 mrioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
3684 if (pci_request_selected_regions(pdev, mrioc->bars,
3685 mrioc->driver_name)) {
3686 ioc_err(mrioc, "pci_request_selected_regions: failed\n");
3691 for (i = 0; (i < DEVICE_COUNT_RESOURCE); i++) {
3692 if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) {
3693 mrioc->sysif_regs_phys = pci_resource_start(pdev, i);
3694 memap_sz = pci_resource_len(pdev, i);
3696 ioremap(mrioc->sysif_regs_phys, memap_sz);
3701 pci_set_master(pdev);
3703 retval = dma_set_mask_and_coherent(&pdev->dev, dma_mask);
3705 if (dma_mask != DMA_BIT_MASK(32)) {
3706 ioc_warn(mrioc, "Setting 64 bit DMA mask failed\n");
3707 dma_mask = DMA_BIT_MASK(32);
3708 retval = dma_set_mask_and_coherent(&pdev->dev,
3712 mrioc->dma_mask = 0;
3713 ioc_err(mrioc, "Setting 32 bit DMA mask also failed\n");
3717 mrioc->dma_mask = dma_mask;
3719 if (!mrioc->sysif_regs) {
3721 "Unable to map adapter memory or resource not found\n");
3726 pci_read_config_word(pdev, capb + 2, &message_control);
3727 mrioc->msix_count = (message_control & 0x3FF) + 1;
3729 pci_save_state(pdev);
3731 pci_set_drvdata(pdev, mrioc->shost);
3733 mpi3mr_ioc_disable_intr(mrioc);
3735 ioc_info(mrioc, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
3736 (unsigned long long)mrioc->sysif_regs_phys,
3737 mrioc->sysif_regs, memap_sz);
3738 ioc_info(mrioc, "Number of MSI-X vectors found in capabilities: (%d)\n",
3741 if (!reset_devices && poll_queues > 0)
3742 mrioc->requested_poll_qcount = min_t(int, poll_queues,
3743 mrioc->msix_count - 2);
3747 mpi3mr_cleanup_resources(mrioc);
3752 * mpi3mr_enable_events - Enable required events
3753 * @mrioc: Adapter instance reference
3755 * This routine unmasks the events required by the driver by
3756 * sennding appropriate event mask bitmapt through an event
3757 * notification request.
3759 * Return: 0 on success and non-zero on failure.
3761 static int mpi3mr_enable_events(struct mpi3mr_ioc *mrioc)
3766 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
3767 mrioc->event_masks[i] = -1;
3769 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_ADDED);
3770 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_INFO_CHANGED);
3771 mpi3mr_unmask_events(mrioc, MPI3_EVENT_DEVICE_STATUS_CHANGE);
3772 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE);
3773 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENCL_DEVICE_ADDED);
3774 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST);
3775 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DISCOVERY);
3776 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR);
3777 mpi3mr_unmask_events(mrioc, MPI3_EVENT_SAS_BROADCAST_PRIMITIVE);
3778 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST);
3779 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PCIE_ENUMERATION);
3780 mpi3mr_unmask_events(mrioc, MPI3_EVENT_PREPARE_FOR_RESET);
3781 mpi3mr_unmask_events(mrioc, MPI3_EVENT_CABLE_MGMT);
3782 mpi3mr_unmask_events(mrioc, MPI3_EVENT_ENERGY_PACK_CHANGE);
3784 retval = mpi3mr_issue_event_notification(mrioc);
3786 ioc_err(mrioc, "failed to issue event notification %d\n",
3792 * mpi3mr_init_ioc - Initialize the controller
3793 * @mrioc: Adapter instance reference
3795 * This the controller initialization routine, executed either
3796 * after soft reset or from pci probe callback.
3797 * Setup the required resources, memory map the controller
3798 * registers, create admin and operational reply queue pairs,
3799 * allocate required memory for reply pool, sense buffer pool,
3800 * issue IOC init request to the firmware, unmask the events and
3801 * issue port enable to discover SAS/SATA/NVMe devies and RAID
3804 * Return: 0 on success and non-zero on failure.
3806 int mpi3mr_init_ioc(struct mpi3mr_ioc *mrioc)
3810 struct mpi3_ioc_facts_data facts_data;
3814 retval = mpi3mr_bring_ioc_ready(mrioc);
3816 ioc_err(mrioc, "Failed to bring ioc ready: error %d\n",
3818 goto out_failed_noretry;
3821 retval = mpi3mr_setup_isr(mrioc, 1);
3823 ioc_err(mrioc, "Failed to setup ISR error %d\n",
3825 goto out_failed_noretry;
3828 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
3830 ioc_err(mrioc, "Failed to Issue IOC Facts %d\n",
3835 mrioc->max_host_ios = mrioc->facts.max_reqs - MPI3MR_INTERNAL_CMDS_RESVD;
3836 mrioc->shost->max_sectors = mrioc->facts.max_data_length / 512;
3837 mrioc->num_io_throttle_group = mrioc->facts.max_io_throttle_group;
3838 atomic_set(&mrioc->pend_large_data_sz, 0);
3841 mrioc->max_host_ios = min_t(int, mrioc->max_host_ios,
3842 MPI3MR_HOST_IOS_KDUMP);
3844 if (!(mrioc->facts.ioc_capabilities &
3845 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_ENABLED)) {
3846 mrioc->sas_transport_enabled = 1;
3847 mrioc->scsi_device_channel = 1;
3848 mrioc->shost->max_channel = 1;
3849 mrioc->shost->transportt = mpi3mr_transport_template;
3852 mrioc->reply_sz = mrioc->facts.reply_sz;
3854 retval = mpi3mr_check_reset_dma_mask(mrioc);
3856 ioc_err(mrioc, "Resetting dma mask failed %d\n",
3858 goto out_failed_noretry;
3861 mpi3mr_print_ioc_info(mrioc);
3863 if (!mrioc->cfg_page) {
3864 dprint_init(mrioc, "allocating config page buffers\n");
3865 mrioc->cfg_page_sz = MPI3MR_DEFAULT_CFG_PAGE_SZ;
3866 mrioc->cfg_page = dma_alloc_coherent(&mrioc->pdev->dev,
3867 mrioc->cfg_page_sz, &mrioc->cfg_page_dma, GFP_KERNEL);
3868 if (!mrioc->cfg_page) {
3870 goto out_failed_noretry;
3874 if (!mrioc->init_cmds.reply) {
3875 retval = mpi3mr_alloc_reply_sense_bufs(mrioc);
3878 "%s :Failed to allocated reply sense buffers %d\n",
3880 goto out_failed_noretry;
3884 if (!mrioc->chain_sgl_list) {
3885 retval = mpi3mr_alloc_chain_bufs(mrioc);
3887 ioc_err(mrioc, "Failed to allocated chain buffers %d\n",
3889 goto out_failed_noretry;
3893 retval = mpi3mr_issue_iocinit(mrioc);
3895 ioc_err(mrioc, "Failed to Issue IOC Init %d\n",
3900 retval = mpi3mr_print_pkg_ver(mrioc);
3902 ioc_err(mrioc, "failed to get package version\n");
3906 retval = mpi3mr_setup_isr(mrioc, 0);
3908 ioc_err(mrioc, "Failed to re-setup ISR, error %d\n",
3910 goto out_failed_noretry;
3913 retval = mpi3mr_create_op_queues(mrioc);
3915 ioc_err(mrioc, "Failed to create OpQueues error %d\n",
3920 if (!mrioc->pel_seqnum_virt) {
3921 dprint_init(mrioc, "allocating memory for pel_seqnum_virt\n");
3922 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
3923 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
3924 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
3926 if (!mrioc->pel_seqnum_virt) {
3928 goto out_failed_noretry;
3932 if (!mrioc->throttle_groups && mrioc->num_io_throttle_group) {
3933 dprint_init(mrioc, "allocating memory for throttle groups\n");
3934 sz = sizeof(struct mpi3mr_throttle_group_info);
3935 mrioc->throttle_groups = kcalloc(mrioc->num_io_throttle_group, sz, GFP_KERNEL);
3936 if (!mrioc->throttle_groups) {
3938 goto out_failed_noretry;
3942 retval = mpi3mr_enable_events(mrioc);
3944 ioc_err(mrioc, "failed to enable events %d\n",
3949 ioc_info(mrioc, "controller initialization completed successfully\n");
3954 ioc_warn(mrioc, "retrying controller initialization, retry_count:%d\n",
3956 mpi3mr_memset_buffers(mrioc);
3961 ioc_err(mrioc, "controller initialization failed\n");
3962 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
3963 MPI3MR_RESET_FROM_CTLR_CLEANUP);
3964 mrioc->unrecoverable = 1;
3969 * mpi3mr_reinit_ioc - Re-Initialize the controller
3970 * @mrioc: Adapter instance reference
3971 * @is_resume: Called from resume or reset path
3973 * This the controller re-initialization routine, executed from
3974 * the soft reset handler or resume callback. Creates
3975 * operational reply queue pairs, allocate required memory for
3976 * reply pool, sense buffer pool, issue IOC init request to the
3977 * firmware, unmask the events and issue port enable to discover
3978 * SAS/SATA/NVMe devices and RAID volumes.
3980 * Return: 0 on success and non-zero on failure.
3982 int mpi3mr_reinit_ioc(struct mpi3mr_ioc *mrioc, u8 is_resume)
3986 struct mpi3_ioc_facts_data facts_data;
3987 u32 pe_timeout, ioc_status;
3991 (MPI3MR_PORTENABLE_TIMEOUT / MPI3MR_PORTENABLE_POLL_INTERVAL);
3993 dprint_reset(mrioc, "bringing up the controller to ready state\n");
3994 retval = mpi3mr_bring_ioc_ready(mrioc);
3996 ioc_err(mrioc, "failed to bring to ready state\n");
3997 goto out_failed_noretry;
4001 dprint_reset(mrioc, "setting up single ISR\n");
4002 retval = mpi3mr_setup_isr(mrioc, 1);
4004 ioc_err(mrioc, "failed to setup ISR\n");
4005 goto out_failed_noretry;
4008 mpi3mr_ioc_enable_intr(mrioc);
4010 dprint_reset(mrioc, "getting ioc_facts\n");
4011 retval = mpi3mr_issue_iocfacts(mrioc, &facts_data);
4013 ioc_err(mrioc, "failed to get ioc_facts\n");
4017 dprint_reset(mrioc, "validating ioc_facts\n");
4018 retval = mpi3mr_revalidate_factsdata(mrioc);
4020 ioc_err(mrioc, "failed to revalidate ioc_facts data\n");
4021 goto out_failed_noretry;
4024 mpi3mr_print_ioc_info(mrioc);
4026 dprint_reset(mrioc, "sending ioc_init\n");
4027 retval = mpi3mr_issue_iocinit(mrioc);
4029 ioc_err(mrioc, "failed to send ioc_init\n");
4033 dprint_reset(mrioc, "getting package version\n");
4034 retval = mpi3mr_print_pkg_ver(mrioc);
4036 ioc_err(mrioc, "failed to get package version\n");
4041 dprint_reset(mrioc, "setting up multiple ISR\n");
4042 retval = mpi3mr_setup_isr(mrioc, 0);
4044 ioc_err(mrioc, "failed to re-setup ISR\n");
4045 goto out_failed_noretry;
4049 dprint_reset(mrioc, "creating operational queue pairs\n");
4050 retval = mpi3mr_create_op_queues(mrioc);
4052 ioc_err(mrioc, "failed to create operational queue pairs\n");
4056 if (!mrioc->pel_seqnum_virt) {
4057 dprint_reset(mrioc, "allocating memory for pel_seqnum_virt\n");
4058 mrioc->pel_seqnum_sz = sizeof(struct mpi3_pel_seq);
4059 mrioc->pel_seqnum_virt = dma_alloc_coherent(&mrioc->pdev->dev,
4060 mrioc->pel_seqnum_sz, &mrioc->pel_seqnum_dma,
4062 if (!mrioc->pel_seqnum_virt) {
4064 goto out_failed_noretry;
4068 if (mrioc->shost->nr_hw_queues > mrioc->num_op_reply_q) {
4070 "cannot create minimum number of operational queues expected:%d created:%d\n",
4071 mrioc->shost->nr_hw_queues, mrioc->num_op_reply_q);
4073 goto out_failed_noretry;
4076 dprint_reset(mrioc, "enabling events\n");
4077 retval = mpi3mr_enable_events(mrioc);
4079 ioc_err(mrioc, "failed to enable events\n");
4083 mrioc->device_refresh_on = 1;
4084 mpi3mr_add_event_wait_for_device_refresh(mrioc);
4086 ioc_info(mrioc, "sending port enable\n");
4087 retval = mpi3mr_issue_port_enable(mrioc, 1);
4089 ioc_err(mrioc, "failed to issue port enable\n");
4093 ssleep(MPI3MR_PORTENABLE_POLL_INTERVAL);
4094 if (mrioc->init_cmds.state == MPI3MR_CMD_NOTUSED)
4096 if (!pci_device_is_present(mrioc->pdev))
4097 mrioc->unrecoverable = 1;
4098 if (mrioc->unrecoverable) {
4100 goto out_failed_noretry;
4102 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4103 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_RESET_HISTORY) ||
4104 (ioc_status & MPI3_SYSIF_IOC_STATUS_FAULT)) {
4105 mpi3mr_print_fault_info(mrioc);
4106 mrioc->init_cmds.is_waiting = 0;
4107 mrioc->init_cmds.callback = NULL;
4108 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4111 } while (--pe_timeout);
4114 ioc_err(mrioc, "port enable timed out\n");
4115 mpi3mr_check_rh_fault_ioc(mrioc,
4116 MPI3MR_RESET_FROM_PE_TIMEOUT);
4117 mrioc->init_cmds.is_waiting = 0;
4118 mrioc->init_cmds.callback = NULL;
4119 mrioc->init_cmds.state = MPI3MR_CMD_NOTUSED;
4121 } else if (mrioc->scan_failed) {
4123 "port enable failed with status=0x%04x\n",
4124 mrioc->scan_failed);
4126 ioc_info(mrioc, "port enable completed successfully\n");
4128 ioc_info(mrioc, "controller %s completed successfully\n",
4129 (is_resume)?"resume":"re-initialization");
4134 ioc_warn(mrioc, "retrying controller %s, retry_count:%d\n",
4135 (is_resume)?"resume":"re-initialization", retry);
4136 mpi3mr_memset_buffers(mrioc);
4141 ioc_err(mrioc, "controller %s is failed\n",
4142 (is_resume)?"resume":"re-initialization");
4143 mpi3mr_issue_reset(mrioc, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT,
4144 MPI3MR_RESET_FROM_CTLR_CLEANUP);
4145 mrioc->unrecoverable = 1;
4150 * mpi3mr_memset_op_reply_q_buffers - memset the operational reply queue's
4152 * @mrioc: Adapter instance reference
4153 * @qidx: Operational reply queue index
4157 static void mpi3mr_memset_op_reply_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4159 struct op_reply_qinfo *op_reply_q = mrioc->op_reply_qinfo + qidx;
4160 struct segments *segments;
4163 if (!op_reply_q->q_segments)
4166 size = op_reply_q->segment_qd * mrioc->op_reply_desc_sz;
4167 segments = op_reply_q->q_segments;
4168 for (i = 0; i < op_reply_q->num_segments; i++)
4169 memset(segments[i].segment, 0, size);
4173 * mpi3mr_memset_op_req_q_buffers - memset the operational request queue's
4175 * @mrioc: Adapter instance reference
4176 * @qidx: Operational request queue index
4180 static void mpi3mr_memset_op_req_q_buffers(struct mpi3mr_ioc *mrioc, u16 qidx)
4182 struct op_req_qinfo *op_req_q = mrioc->req_qinfo + qidx;
4183 struct segments *segments;
4186 if (!op_req_q->q_segments)
4189 size = op_req_q->segment_qd * mrioc->facts.op_req_sz;
4190 segments = op_req_q->q_segments;
4191 for (i = 0; i < op_req_q->num_segments; i++)
4192 memset(segments[i].segment, 0, size);
4196 * mpi3mr_memset_buffers - memset memory for a controller
4197 * @mrioc: Adapter instance reference
4199 * clear all the memory allocated for a controller, typically
4200 * called post reset to reuse the memory allocated during the
4205 void mpi3mr_memset_buffers(struct mpi3mr_ioc *mrioc)
4208 struct mpi3mr_throttle_group_info *tg;
4210 mrioc->change_count = 0;
4211 mrioc->active_poll_qcount = 0;
4212 mrioc->default_qcount = 0;
4213 if (mrioc->admin_req_base)
4214 memset(mrioc->admin_req_base, 0, mrioc->admin_req_q_sz);
4215 if (mrioc->admin_reply_base)
4216 memset(mrioc->admin_reply_base, 0, mrioc->admin_reply_q_sz);
4217 atomic_set(&mrioc->admin_reply_q_in_use, 0);
4219 if (mrioc->init_cmds.reply) {
4220 memset(mrioc->init_cmds.reply, 0, sizeof(*mrioc->init_cmds.reply));
4221 memset(mrioc->bsg_cmds.reply, 0,
4222 sizeof(*mrioc->bsg_cmds.reply));
4223 memset(mrioc->host_tm_cmds.reply, 0,
4224 sizeof(*mrioc->host_tm_cmds.reply));
4225 memset(mrioc->pel_cmds.reply, 0,
4226 sizeof(*mrioc->pel_cmds.reply));
4227 memset(mrioc->pel_abort_cmd.reply, 0,
4228 sizeof(*mrioc->pel_abort_cmd.reply));
4229 memset(mrioc->transport_cmds.reply, 0,
4230 sizeof(*mrioc->transport_cmds.reply));
4231 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++)
4232 memset(mrioc->dev_rmhs_cmds[i].reply, 0,
4233 sizeof(*mrioc->dev_rmhs_cmds[i].reply));
4234 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++)
4235 memset(mrioc->evtack_cmds[i].reply, 0,
4236 sizeof(*mrioc->evtack_cmds[i].reply));
4237 bitmap_clear(mrioc->removepend_bitmap, 0,
4238 mrioc->dev_handle_bitmap_bits);
4239 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
4240 bitmap_clear(mrioc->evtack_cmds_bitmap, 0,
4241 MPI3MR_NUM_EVTACKCMD);
4244 for (i = 0; i < mrioc->num_queues; i++) {
4245 mrioc->op_reply_qinfo[i].qid = 0;
4246 mrioc->op_reply_qinfo[i].ci = 0;
4247 mrioc->op_reply_qinfo[i].num_replies = 0;
4248 mrioc->op_reply_qinfo[i].ephase = 0;
4249 atomic_set(&mrioc->op_reply_qinfo[i].pend_ios, 0);
4250 atomic_set(&mrioc->op_reply_qinfo[i].in_use, 0);
4251 mpi3mr_memset_op_reply_q_buffers(mrioc, i);
4253 mrioc->req_qinfo[i].ci = 0;
4254 mrioc->req_qinfo[i].pi = 0;
4255 mrioc->req_qinfo[i].num_requests = 0;
4256 mrioc->req_qinfo[i].qid = 0;
4257 mrioc->req_qinfo[i].reply_qid = 0;
4258 spin_lock_init(&mrioc->req_qinfo[i].q_lock);
4259 mpi3mr_memset_op_req_q_buffers(mrioc, i);
4262 atomic_set(&mrioc->pend_large_data_sz, 0);
4263 if (mrioc->throttle_groups) {
4264 tg = mrioc->throttle_groups;
4265 for (i = 0; i < mrioc->num_io_throttle_group; i++, tg++) {
4268 tg->modified_qd = 0;
4270 tg->need_qd_reduction = 0;
4273 tg->qd_reduction = 0;
4274 atomic_set(&tg->pend_large_data_sz, 0);
4280 * mpi3mr_free_mem - Free memory allocated for a controller
4281 * @mrioc: Adapter instance reference
4283 * Free all the memory allocated for a controller.
4287 void mpi3mr_free_mem(struct mpi3mr_ioc *mrioc)
4290 struct mpi3mr_intr_info *intr_info;
4292 mpi3mr_free_enclosure_list(mrioc);
4294 if (mrioc->sense_buf_pool) {
4295 if (mrioc->sense_buf)
4296 dma_pool_free(mrioc->sense_buf_pool, mrioc->sense_buf,
4297 mrioc->sense_buf_dma);
4298 dma_pool_destroy(mrioc->sense_buf_pool);
4299 mrioc->sense_buf = NULL;
4300 mrioc->sense_buf_pool = NULL;
4302 if (mrioc->sense_buf_q_pool) {
4303 if (mrioc->sense_buf_q)
4304 dma_pool_free(mrioc->sense_buf_q_pool,
4305 mrioc->sense_buf_q, mrioc->sense_buf_q_dma);
4306 dma_pool_destroy(mrioc->sense_buf_q_pool);
4307 mrioc->sense_buf_q = NULL;
4308 mrioc->sense_buf_q_pool = NULL;
4311 if (mrioc->reply_buf_pool) {
4312 if (mrioc->reply_buf)
4313 dma_pool_free(mrioc->reply_buf_pool, mrioc->reply_buf,
4314 mrioc->reply_buf_dma);
4315 dma_pool_destroy(mrioc->reply_buf_pool);
4316 mrioc->reply_buf = NULL;
4317 mrioc->reply_buf_pool = NULL;
4319 if (mrioc->reply_free_q_pool) {
4320 if (mrioc->reply_free_q)
4321 dma_pool_free(mrioc->reply_free_q_pool,
4322 mrioc->reply_free_q, mrioc->reply_free_q_dma);
4323 dma_pool_destroy(mrioc->reply_free_q_pool);
4324 mrioc->reply_free_q = NULL;
4325 mrioc->reply_free_q_pool = NULL;
4328 for (i = 0; i < mrioc->num_op_req_q; i++)
4329 mpi3mr_free_op_req_q_segments(mrioc, i);
4331 for (i = 0; i < mrioc->num_op_reply_q; i++)
4332 mpi3mr_free_op_reply_q_segments(mrioc, i);
4334 for (i = 0; i < mrioc->intr_info_count; i++) {
4335 intr_info = mrioc->intr_info + i;
4336 intr_info->op_reply_q = NULL;
4339 kfree(mrioc->req_qinfo);
4340 mrioc->req_qinfo = NULL;
4341 mrioc->num_op_req_q = 0;
4343 kfree(mrioc->op_reply_qinfo);
4344 mrioc->op_reply_qinfo = NULL;
4345 mrioc->num_op_reply_q = 0;
4347 kfree(mrioc->init_cmds.reply);
4348 mrioc->init_cmds.reply = NULL;
4350 kfree(mrioc->bsg_cmds.reply);
4351 mrioc->bsg_cmds.reply = NULL;
4353 kfree(mrioc->host_tm_cmds.reply);
4354 mrioc->host_tm_cmds.reply = NULL;
4356 kfree(mrioc->pel_cmds.reply);
4357 mrioc->pel_cmds.reply = NULL;
4359 kfree(mrioc->pel_abort_cmd.reply);
4360 mrioc->pel_abort_cmd.reply = NULL;
4362 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4363 kfree(mrioc->evtack_cmds[i].reply);
4364 mrioc->evtack_cmds[i].reply = NULL;
4367 bitmap_free(mrioc->removepend_bitmap);
4368 mrioc->removepend_bitmap = NULL;
4370 bitmap_free(mrioc->devrem_bitmap);
4371 mrioc->devrem_bitmap = NULL;
4373 bitmap_free(mrioc->evtack_cmds_bitmap);
4374 mrioc->evtack_cmds_bitmap = NULL;
4376 bitmap_free(mrioc->chain_bitmap);
4377 mrioc->chain_bitmap = NULL;
4379 kfree(mrioc->transport_cmds.reply);
4380 mrioc->transport_cmds.reply = NULL;
4382 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4383 kfree(mrioc->dev_rmhs_cmds[i].reply);
4384 mrioc->dev_rmhs_cmds[i].reply = NULL;
4387 if (mrioc->chain_buf_pool) {
4388 for (i = 0; i < mrioc->chain_buf_count; i++) {
4389 if (mrioc->chain_sgl_list[i].addr) {
4390 dma_pool_free(mrioc->chain_buf_pool,
4391 mrioc->chain_sgl_list[i].addr,
4392 mrioc->chain_sgl_list[i].dma_addr);
4393 mrioc->chain_sgl_list[i].addr = NULL;
4396 dma_pool_destroy(mrioc->chain_buf_pool);
4397 mrioc->chain_buf_pool = NULL;
4400 kfree(mrioc->chain_sgl_list);
4401 mrioc->chain_sgl_list = NULL;
4403 if (mrioc->admin_reply_base) {
4404 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_reply_q_sz,
4405 mrioc->admin_reply_base, mrioc->admin_reply_dma);
4406 mrioc->admin_reply_base = NULL;
4408 if (mrioc->admin_req_base) {
4409 dma_free_coherent(&mrioc->pdev->dev, mrioc->admin_req_q_sz,
4410 mrioc->admin_req_base, mrioc->admin_req_dma);
4411 mrioc->admin_req_base = NULL;
4413 if (mrioc->cfg_page) {
4414 dma_free_coherent(&mrioc->pdev->dev, mrioc->cfg_page_sz,
4415 mrioc->cfg_page, mrioc->cfg_page_dma);
4416 mrioc->cfg_page = NULL;
4418 if (mrioc->pel_seqnum_virt) {
4419 dma_free_coherent(&mrioc->pdev->dev, mrioc->pel_seqnum_sz,
4420 mrioc->pel_seqnum_virt, mrioc->pel_seqnum_dma);
4421 mrioc->pel_seqnum_virt = NULL;
4424 kfree(mrioc->throttle_groups);
4425 mrioc->throttle_groups = NULL;
4427 kfree(mrioc->logdata_buf);
4428 mrioc->logdata_buf = NULL;
4433 * mpi3mr_issue_ioc_shutdown - shutdown controller
4434 * @mrioc: Adapter instance reference
4436 * Send shutodwn notification to the controller and wait for the
4437 * shutdown_timeout for it to be completed.
4441 static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc *mrioc)
4443 u32 ioc_config, ioc_status;
4445 u32 timeout = MPI3MR_DEFAULT_SHUTDOWN_TIME * 10;
4447 ioc_info(mrioc, "Issuing shutdown Notification\n");
4448 if (mrioc->unrecoverable) {
4450 "IOC is unrecoverable shutdown is not issued\n");
4453 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4454 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4455 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS) {
4456 ioc_info(mrioc, "shutdown already in progress\n");
4460 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4461 ioc_config |= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL;
4462 ioc_config |= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN_SEND_REQ;
4464 writel(ioc_config, &mrioc->sysif_regs->ioc_configuration);
4466 if (mrioc->facts.shutdown_timeout)
4467 timeout = mrioc->facts.shutdown_timeout * 10;
4470 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4471 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4472 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE) {
4477 } while (--timeout);
4479 ioc_status = readl(&mrioc->sysif_regs->ioc_status);
4480 ioc_config = readl(&mrioc->sysif_regs->ioc_configuration);
4483 if ((ioc_status & MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK)
4484 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS)
4486 "shutdown still in progress after timeout\n");
4490 "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
4491 (!retval) ? "successful" : "failed", ioc_status,
4496 * mpi3mr_cleanup_ioc - Cleanup controller
4497 * @mrioc: Adapter instance reference
4499 * controller cleanup handler, Message unit reset or soft reset
4500 * and shutdown notification is issued to the controller.
4504 void mpi3mr_cleanup_ioc(struct mpi3mr_ioc *mrioc)
4506 enum mpi3mr_iocstate ioc_state;
4508 dprint_exit(mrioc, "cleaning up the controller\n");
4509 mpi3mr_ioc_disable_intr(mrioc);
4511 ioc_state = mpi3mr_get_iocstate(mrioc);
4513 if ((!mrioc->unrecoverable) && (!mrioc->reset_in_progress) &&
4514 (ioc_state == MRIOC_STATE_READY)) {
4515 if (mpi3mr_issue_and_process_mur(mrioc,
4516 MPI3MR_RESET_FROM_CTLR_CLEANUP))
4517 mpi3mr_issue_reset(mrioc,
4518 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET,
4519 MPI3MR_RESET_FROM_MUR_FAILURE);
4520 mpi3mr_issue_ioc_shutdown(mrioc);
4522 dprint_exit(mrioc, "controller cleanup completed\n");
4526 * mpi3mr_drv_cmd_comp_reset - Flush a internal driver command
4527 * @mrioc: Adapter instance reference
4528 * @cmdptr: Internal command tracker
4530 * Complete an internal driver commands with state indicating it
4531 * is completed due to reset.
4535 static inline void mpi3mr_drv_cmd_comp_reset(struct mpi3mr_ioc *mrioc,
4536 struct mpi3mr_drv_cmd *cmdptr)
4538 if (cmdptr->state & MPI3MR_CMD_PENDING) {
4539 cmdptr->state |= MPI3MR_CMD_RESET;
4540 cmdptr->state &= ~MPI3MR_CMD_PENDING;
4541 if (cmdptr->is_waiting) {
4542 complete(&cmdptr->done);
4543 cmdptr->is_waiting = 0;
4544 } else if (cmdptr->callback)
4545 cmdptr->callback(mrioc, cmdptr);
4550 * mpi3mr_flush_drv_cmds - Flush internaldriver commands
4551 * @mrioc: Adapter instance reference
4553 * Flush all internal driver commands post reset
4557 void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc *mrioc)
4559 struct mpi3mr_drv_cmd *cmdptr;
4562 cmdptr = &mrioc->init_cmds;
4563 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4565 cmdptr = &mrioc->cfg_cmds;
4566 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4568 cmdptr = &mrioc->bsg_cmds;
4569 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4570 cmdptr = &mrioc->host_tm_cmds;
4571 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4573 for (i = 0; i < MPI3MR_NUM_DEVRMCMD; i++) {
4574 cmdptr = &mrioc->dev_rmhs_cmds[i];
4575 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4578 for (i = 0; i < MPI3MR_NUM_EVTACKCMD; i++) {
4579 cmdptr = &mrioc->evtack_cmds[i];
4580 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4583 cmdptr = &mrioc->pel_cmds;
4584 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4586 cmdptr = &mrioc->pel_abort_cmd;
4587 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4589 cmdptr = &mrioc->transport_cmds;
4590 mpi3mr_drv_cmd_comp_reset(mrioc, cmdptr);
4594 * mpi3mr_pel_wait_post - Issue PEL Wait
4595 * @mrioc: Adapter instance reference
4596 * @drv_cmd: Internal command tracker
4598 * Issue PEL Wait MPI request through admin queue and return.
4602 static void mpi3mr_pel_wait_post(struct mpi3mr_ioc *mrioc,
4603 struct mpi3mr_drv_cmd *drv_cmd)
4605 struct mpi3_pel_req_action_wait pel_wait;
4607 mrioc->pel_abort_requested = false;
4609 memset(&pel_wait, 0, sizeof(pel_wait));
4610 drv_cmd->state = MPI3MR_CMD_PENDING;
4611 drv_cmd->is_waiting = 0;
4612 drv_cmd->callback = mpi3mr_pel_wait_complete;
4613 drv_cmd->ioc_status = 0;
4614 drv_cmd->ioc_loginfo = 0;
4615 pel_wait.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4616 pel_wait.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4617 pel_wait.action = MPI3_PEL_ACTION_WAIT;
4618 pel_wait.starting_sequence_number = cpu_to_le32(mrioc->pel_newest_seqnum);
4619 pel_wait.locale = cpu_to_le16(mrioc->pel_locale);
4620 pel_wait.class = cpu_to_le16(mrioc->pel_class);
4621 pel_wait.wait_time = MPI3_PEL_WAITTIME_INFINITE_WAIT;
4622 dprint_bsg_info(mrioc, "sending pel_wait seqnum(%d), class(%d), locale(0x%08x)\n",
4623 mrioc->pel_newest_seqnum, mrioc->pel_class, mrioc->pel_locale);
4625 if (mpi3mr_admin_request_post(mrioc, &pel_wait, sizeof(pel_wait), 0)) {
4626 dprint_bsg_err(mrioc,
4627 "Issuing PELWait: Admin post failed\n");
4628 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4629 drv_cmd->callback = NULL;
4630 drv_cmd->retry_count = 0;
4631 mrioc->pel_enabled = false;
4636 * mpi3mr_pel_get_seqnum_post - Issue PEL Get Sequence number
4637 * @mrioc: Adapter instance reference
4638 * @drv_cmd: Internal command tracker
4640 * Issue PEL get sequence number MPI request through admin queue
4643 * Return: 0 on success, non-zero on failure.
4645 int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc *mrioc,
4646 struct mpi3mr_drv_cmd *drv_cmd)
4648 struct mpi3_pel_req_action_get_sequence_numbers pel_getseq_req;
4649 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
4652 memset(&pel_getseq_req, 0, sizeof(pel_getseq_req));
4653 mrioc->pel_cmds.state = MPI3MR_CMD_PENDING;
4654 mrioc->pel_cmds.is_waiting = 0;
4655 mrioc->pel_cmds.ioc_status = 0;
4656 mrioc->pel_cmds.ioc_loginfo = 0;
4657 mrioc->pel_cmds.callback = mpi3mr_pel_get_seqnum_complete;
4658 pel_getseq_req.host_tag = cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT);
4659 pel_getseq_req.function = MPI3_FUNCTION_PERSISTENT_EVENT_LOG;
4660 pel_getseq_req.action = MPI3_PEL_ACTION_GET_SEQNUM;
4661 mpi3mr_add_sg_single(&pel_getseq_req.sgl, sgl_flags,
4662 mrioc->pel_seqnum_sz, mrioc->pel_seqnum_dma);
4664 retval = mpi3mr_admin_request_post(mrioc, &pel_getseq_req,
4665 sizeof(pel_getseq_req), 0);
4668 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4669 drv_cmd->callback = NULL;
4670 drv_cmd->retry_count = 0;
4672 mrioc->pel_enabled = false;
4679 * mpi3mr_pel_wait_complete - PELWait Completion callback
4680 * @mrioc: Adapter instance reference
4681 * @drv_cmd: Internal command tracker
4683 * This is a callback handler for the PELWait request and
4684 * firmware completes a PELWait request when it is aborted or a
4685 * new PEL entry is available. This sends AEN to the application
4686 * and if the PELwait completion is not due to PELAbort then
4687 * this will send a request for new PEL Sequence number
4691 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc *mrioc,
4692 struct mpi3mr_drv_cmd *drv_cmd)
4694 struct mpi3_pel_reply *pel_reply = NULL;
4695 u16 ioc_status, pe_log_status;
4696 bool do_retry = false;
4698 if (drv_cmd->state & MPI3MR_CMD_RESET)
4699 goto cleanup_drv_cmd;
4701 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4702 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4703 ioc_err(mrioc, "%s: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
4704 __func__, ioc_status, drv_cmd->ioc_loginfo);
4705 dprint_bsg_err(mrioc,
4706 "pel_wait: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4707 ioc_status, drv_cmd->ioc_loginfo);
4711 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4712 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4715 dprint_bsg_err(mrioc,
4716 "pel_wait: failed due to no reply\n");
4720 pe_log_status = le16_to_cpu(pel_reply->pe_log_status);
4721 if ((pe_log_status != MPI3_PEL_STATUS_SUCCESS) &&
4722 (pe_log_status != MPI3_PEL_STATUS_ABORTED)) {
4723 ioc_err(mrioc, "%s: Failed pe_log_status(0x%04x)\n",
4724 __func__, pe_log_status);
4725 dprint_bsg_err(mrioc,
4726 "pel_wait: failed due to pel_log_status(0x%04x)\n",
4732 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4733 drv_cmd->retry_count++;
4734 dprint_bsg_err(mrioc, "pel_wait: retrying(%d)\n",
4735 drv_cmd->retry_count);
4736 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4739 dprint_bsg_err(mrioc,
4740 "pel_wait: failed after all retries(%d)\n",
4741 drv_cmd->retry_count);
4744 atomic64_inc(&event_counter);
4745 if (!mrioc->pel_abort_requested) {
4746 mrioc->pel_cmds.retry_count = 0;
4747 mpi3mr_pel_get_seqnum_post(mrioc, &mrioc->pel_cmds);
4752 mrioc->pel_enabled = false;
4754 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4755 drv_cmd->callback = NULL;
4756 drv_cmd->retry_count = 0;
4760 * mpi3mr_pel_get_seqnum_complete - PELGetSeqNum Completion callback
4761 * @mrioc: Adapter instance reference
4762 * @drv_cmd: Internal command tracker
4764 * This is a callback handler for the PEL get sequence number
4765 * request and a new PEL wait request will be issued to the
4766 * firmware from this
4770 void mpi3mr_pel_get_seqnum_complete(struct mpi3mr_ioc *mrioc,
4771 struct mpi3mr_drv_cmd *drv_cmd)
4773 struct mpi3_pel_reply *pel_reply = NULL;
4774 struct mpi3_pel_seq *pel_seqnum_virt;
4776 bool do_retry = false;
4778 pel_seqnum_virt = (struct mpi3_pel_seq *)mrioc->pel_seqnum_virt;
4780 if (drv_cmd->state & MPI3MR_CMD_RESET)
4781 goto cleanup_drv_cmd;
4783 ioc_status = drv_cmd->ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
4784 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
4785 dprint_bsg_err(mrioc,
4786 "pel_get_seqnum: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
4787 ioc_status, drv_cmd->ioc_loginfo);
4791 if (drv_cmd->state & MPI3MR_CMD_REPLY_VALID)
4792 pel_reply = (struct mpi3_pel_reply *)drv_cmd->reply;
4794 dprint_bsg_err(mrioc,
4795 "pel_get_seqnum: failed due to no reply\n");
4799 if (le16_to_cpu(pel_reply->pe_log_status) != MPI3_PEL_STATUS_SUCCESS) {
4800 dprint_bsg_err(mrioc,
4801 "pel_get_seqnum: failed due to pel_log_status(0x%04x)\n",
4802 le16_to_cpu(pel_reply->pe_log_status));
4807 if (drv_cmd->retry_count < MPI3MR_PEL_RETRY_COUNT) {
4808 drv_cmd->retry_count++;
4809 dprint_bsg_err(mrioc,
4810 "pel_get_seqnum: retrying(%d)\n",
4811 drv_cmd->retry_count);
4812 mpi3mr_pel_get_seqnum_post(mrioc, drv_cmd);
4816 dprint_bsg_err(mrioc,
4817 "pel_get_seqnum: failed after all retries(%d)\n",
4818 drv_cmd->retry_count);
4821 mrioc->pel_newest_seqnum = le32_to_cpu(pel_seqnum_virt->newest) + 1;
4822 drv_cmd->retry_count = 0;
4823 mpi3mr_pel_wait_post(mrioc, drv_cmd);
4827 mrioc->pel_enabled = false;
4829 drv_cmd->state = MPI3MR_CMD_NOTUSED;
4830 drv_cmd->callback = NULL;
4831 drv_cmd->retry_count = 0;
4835 * mpi3mr_soft_reset_handler - Reset the controller
4836 * @mrioc: Adapter instance reference
4837 * @reset_reason: Reset reason code
4838 * @snapdump: Flag to generate snapdump in firmware or not
4840 * This is an handler for recovering controller by issuing soft
4841 * reset are diag fault reset. This is a blocking function and
4842 * when one reset is executed if any other resets they will be
4843 * blocked. All BSG requests will be blocked during the reset. If
4844 * controller reset is successful then the controller will be
4845 * reinitalized, otherwise the controller will be marked as not
4848 * In snapdump bit is set, the controller is issued with diag
4849 * fault reset so that the firmware can create a snap dump and
4850 * post that the firmware will result in F000 fault and the
4851 * driver will issue soft reset to recover from that.
4853 * Return: 0 on success, non-zero on failure.
4855 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc *mrioc,
4856 u32 reset_reason, u8 snapdump)
4859 unsigned long flags;
4860 u32 host_diagnostic, timeout = MPI3_SYSIF_DIAG_SAVE_TIMEOUT * 10;
4862 /* Block the reset handler until diag save in progress*/
4864 "soft_reset_handler: check and block on diagsave_timeout(%d)\n",
4865 mrioc->diagsave_timeout);
4866 while (mrioc->diagsave_timeout)
4869 * Block new resets until the currently executing one is finished and
4870 * return the status of the existing reset for all blocked resets
4872 dprint_reset(mrioc, "soft_reset_handler: acquiring reset_mutex\n");
4873 if (!mutex_trylock(&mrioc->reset_mutex)) {
4875 "controller reset triggered by %s is blocked due to another reset in progress\n",
4876 mpi3mr_reset_rc_name(reset_reason));
4879 } while (mrioc->reset_in_progress == 1);
4881 "returning previous reset result(%d) for the reset triggered by %s\n",
4882 mrioc->prev_reset_result,
4883 mpi3mr_reset_rc_name(reset_reason));
4884 return mrioc->prev_reset_result;
4886 ioc_info(mrioc, "controller reset is triggered by %s\n",
4887 mpi3mr_reset_rc_name(reset_reason));
4889 mrioc->device_refresh_on = 0;
4890 mrioc->reset_in_progress = 1;
4891 mrioc->stop_bsgs = 1;
4892 mrioc->prev_reset_result = -1;
4894 if ((!snapdump) && (reset_reason != MPI3MR_RESET_FROM_FAULT_WATCH) &&
4895 (reset_reason != MPI3MR_RESET_FROM_FIRMWARE) &&
4896 (reset_reason != MPI3MR_RESET_FROM_CIACTIV_FAULT)) {
4897 for (i = 0; i < MPI3_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4898 mrioc->event_masks[i] = -1;
4900 dprint_reset(mrioc, "soft_reset_handler: masking events\n");
4901 mpi3mr_issue_event_notification(mrioc);
4904 mpi3mr_wait_for_host_io(mrioc, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT);
4906 mpi3mr_ioc_disable_intr(mrioc);
4909 mpi3mr_set_diagsave(mrioc);
4910 retval = mpi3mr_issue_reset(mrioc,
4911 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
4915 readl(&mrioc->sysif_regs->host_diagnostic);
4916 if (!(host_diagnostic &
4917 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS))
4920 } while (--timeout);
4924 retval = mpi3mr_issue_reset(mrioc,
4925 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET, reset_reason);
4927 ioc_err(mrioc, "Failed to issue soft reset to the ioc\n");
4930 if (mrioc->num_io_throttle_group !=
4931 mrioc->facts.max_io_throttle_group) {
4933 "max io throttle group doesn't match old(%d), new(%d)\n",
4934 mrioc->num_io_throttle_group,
4935 mrioc->facts.max_io_throttle_group);
4940 mpi3mr_flush_delayed_cmd_lists(mrioc);
4941 mpi3mr_flush_drv_cmds(mrioc);
4942 bitmap_clear(mrioc->devrem_bitmap, 0, MPI3MR_NUM_DEVRMCMD);
4943 bitmap_clear(mrioc->removepend_bitmap, 0,
4944 mrioc->dev_handle_bitmap_bits);
4945 bitmap_clear(mrioc->evtack_cmds_bitmap, 0, MPI3MR_NUM_EVTACKCMD);
4946 mpi3mr_flush_host_io(mrioc);
4947 mpi3mr_cleanup_fwevt_list(mrioc);
4948 mpi3mr_invalidate_devhandles(mrioc);
4949 mpi3mr_free_enclosure_list(mrioc);
4951 if (mrioc->prepare_for_reset) {
4952 mrioc->prepare_for_reset = 0;
4953 mrioc->prepare_for_reset_timeout_counter = 0;
4955 mpi3mr_memset_buffers(mrioc);
4956 retval = mpi3mr_reinit_ioc(mrioc, 0);
4958 pr_err(IOCNAME "reinit after soft reset failed: reason %d\n",
4959 mrioc->name, reset_reason);
4962 ssleep(MPI3MR_RESET_TOPOLOGY_SETTLE_TIME);
4966 mrioc->diagsave_timeout = 0;
4967 mrioc->reset_in_progress = 0;
4968 mrioc->pel_abort_requested = 0;
4969 if (mrioc->pel_enabled) {
4970 mrioc->pel_cmds.retry_count = 0;
4971 mpi3mr_pel_wait_post(mrioc, &mrioc->pel_cmds);
4974 mrioc->device_refresh_on = 0;
4976 mrioc->ts_update_counter = 0;
4977 spin_lock_irqsave(&mrioc->watchdog_lock, flags);
4978 if (mrioc->watchdog_work_q)
4979 queue_delayed_work(mrioc->watchdog_work_q,
4980 &mrioc->watchdog_work,
4981 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL));
4982 spin_unlock_irqrestore(&mrioc->watchdog_lock, flags);
4983 mrioc->stop_bsgs = 0;
4984 if (mrioc->pel_enabled)
4985 atomic64_inc(&event_counter);
4987 mpi3mr_issue_reset(mrioc,
4988 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT, reset_reason);
4989 mrioc->device_refresh_on = 0;
4990 mrioc->unrecoverable = 1;
4991 mrioc->reset_in_progress = 0;
4993 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc);
4995 mrioc->prev_reset_result = retval;
4996 mutex_unlock(&mrioc->reset_mutex);
4997 ioc_info(mrioc, "controller reset is %s\n",
4998 ((retval == 0) ? "successful" : "failed"));
5004 * mpi3mr_free_config_dma_memory - free memory for config page
5005 * @mrioc: Adapter instance reference
5006 * @mem_desc: memory descriptor structure
5008 * Check whether the size of the buffer specified by the memory
5009 * descriptor is greater than the default page size if so then
5010 * free the memory pointed by the descriptor.
5014 static void mpi3mr_free_config_dma_memory(struct mpi3mr_ioc *mrioc,
5015 struct dma_memory_desc *mem_desc)
5017 if ((mem_desc->size > mrioc->cfg_page_sz) && mem_desc->addr) {
5018 dma_free_coherent(&mrioc->pdev->dev, mem_desc->size,
5019 mem_desc->addr, mem_desc->dma_addr);
5020 mem_desc->addr = NULL;
5025 * mpi3mr_alloc_config_dma_memory - Alloc memory for config page
5026 * @mrioc: Adapter instance reference
5027 * @mem_desc: Memory descriptor to hold dma memory info
5029 * This function allocates new dmaable memory or provides the
5030 * default config page dmaable memory based on the memory size
5031 * described by the descriptor.
5033 * Return: 0 on success, non-zero on failure.
5035 static int mpi3mr_alloc_config_dma_memory(struct mpi3mr_ioc *mrioc,
5036 struct dma_memory_desc *mem_desc)
5038 if (mem_desc->size > mrioc->cfg_page_sz) {
5039 mem_desc->addr = dma_alloc_coherent(&mrioc->pdev->dev,
5040 mem_desc->size, &mem_desc->dma_addr, GFP_KERNEL);
5041 if (!mem_desc->addr)
5044 mem_desc->addr = mrioc->cfg_page;
5045 mem_desc->dma_addr = mrioc->cfg_page_dma;
5046 memset(mem_desc->addr, 0, mrioc->cfg_page_sz);
5052 * mpi3mr_post_cfg_req - Issue config requests and wait
5053 * @mrioc: Adapter instance reference
5054 * @cfg_req: Configuration request
5055 * @timeout: Timeout in seconds
5056 * @ioc_status: Pointer to return ioc status
5058 * A generic function for posting MPI3 configuration request to
5059 * the firmware. This blocks for the completion of request for
5060 * timeout seconds and if the request times out this function
5061 * faults the controller with proper reason code.
5063 * On successful completion of the request this function returns
5064 * appropriate ioc status from the firmware back to the caller.
5066 * Return: 0 on success, non-zero on failure.
5068 static int mpi3mr_post_cfg_req(struct mpi3mr_ioc *mrioc,
5069 struct mpi3_config_request *cfg_req, int timeout, u16 *ioc_status)
5073 mutex_lock(&mrioc->cfg_cmds.mutex);
5074 if (mrioc->cfg_cmds.state & MPI3MR_CMD_PENDING) {
5076 ioc_err(mrioc, "sending config request failed due to command in use\n");
5077 mutex_unlock(&mrioc->cfg_cmds.mutex);
5080 mrioc->cfg_cmds.state = MPI3MR_CMD_PENDING;
5081 mrioc->cfg_cmds.is_waiting = 1;
5082 mrioc->cfg_cmds.callback = NULL;
5083 mrioc->cfg_cmds.ioc_status = 0;
5084 mrioc->cfg_cmds.ioc_loginfo = 0;
5086 cfg_req->host_tag = cpu_to_le16(MPI3MR_HOSTTAG_CFG_CMDS);
5087 cfg_req->function = MPI3_FUNCTION_CONFIG;
5089 init_completion(&mrioc->cfg_cmds.done);
5090 dprint_cfg_info(mrioc, "posting config request\n");
5091 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5092 dprint_dump(cfg_req, sizeof(struct mpi3_config_request),
5094 retval = mpi3mr_admin_request_post(mrioc, cfg_req, sizeof(*cfg_req), 1);
5096 ioc_err(mrioc, "posting config request failed\n");
5099 wait_for_completion_timeout(&mrioc->cfg_cmds.done, (timeout * HZ));
5100 if (!(mrioc->cfg_cmds.state & MPI3MR_CMD_COMPLETE)) {
5101 mpi3mr_check_rh_fault_ioc(mrioc,
5102 MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT);
5103 ioc_err(mrioc, "config request timed out\n");
5107 *ioc_status = mrioc->cfg_cmds.ioc_status & MPI3_IOCSTATUS_STATUS_MASK;
5108 if ((*ioc_status) != MPI3_IOCSTATUS_SUCCESS)
5109 dprint_cfg_err(mrioc,
5110 "cfg_page request returned with ioc_status(0x%04x), log_info(0x%08x)\n",
5111 *ioc_status, mrioc->cfg_cmds.ioc_loginfo);
5114 mrioc->cfg_cmds.state = MPI3MR_CMD_NOTUSED;
5115 mutex_unlock(&mrioc->cfg_cmds.mutex);
5122 * mpi3mr_process_cfg_req - config page request processor
5123 * @mrioc: Adapter instance reference
5124 * @cfg_req: Configuration request
5125 * @cfg_hdr: Configuration page header
5126 * @timeout: Timeout in seconds
5127 * @ioc_status: Pointer to return ioc status
5128 * @cfg_buf: Memory pointer to copy config page or header
5129 * @cfg_buf_sz: Size of the memory to get config page or header
5131 * This is handler for config page read, write and config page
5132 * header read operations.
5134 * This function expects the cfg_req to be populated with page
5135 * type, page number, action for the header read and with page
5136 * address for all other operations.
5138 * The cfg_hdr can be passed as null for reading required header
5139 * details for read/write pages the cfg_hdr should point valid
5140 * configuration page header.
5142 * This allocates dmaable memory based on the size of the config
5143 * buffer and set the SGE of the cfg_req.
5145 * For write actions, the config page data has to be passed in
5146 * the cfg_buf and size of the data has to be mentioned in the
5149 * For read/header actions, on successful completion of the
5150 * request with successful ioc_status the data will be copied
5151 * into the cfg_buf limited to a minimum of actual page size and
5155 * Return: 0 on success, non-zero on failure.
5157 static int mpi3mr_process_cfg_req(struct mpi3mr_ioc *mrioc,
5158 struct mpi3_config_request *cfg_req,
5159 struct mpi3_config_page_header *cfg_hdr, int timeout, u16 *ioc_status,
5160 void *cfg_buf, u32 cfg_buf_sz)
5162 struct dma_memory_desc mem_desc;
5164 u8 invalid_action = 0;
5165 u8 sgl_flags = MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST;
5167 memset(&mem_desc, 0, sizeof(struct dma_memory_desc));
5169 if (cfg_req->action == MPI3_CONFIG_ACTION_PAGE_HEADER)
5170 mem_desc.size = sizeof(struct mpi3_config_page_header);
5173 ioc_err(mrioc, "null config header passed for config action(%d), page_type(0x%02x), page_num(%d)\n",
5174 cfg_req->action, cfg_req->page_type,
5175 cfg_req->page_number);
5178 switch (cfg_hdr->page_attribute & MPI3_CONFIG_PAGEATTR_MASK) {
5179 case MPI3_CONFIG_PAGEATTR_READ_ONLY:
5181 != MPI3_CONFIG_ACTION_READ_CURRENT)
5184 case MPI3_CONFIG_PAGEATTR_CHANGEABLE:
5185 if ((cfg_req->action ==
5186 MPI3_CONFIG_ACTION_READ_PERSISTENT) ||
5188 MPI3_CONFIG_ACTION_WRITE_PERSISTENT))
5191 case MPI3_CONFIG_PAGEATTR_PERSISTENT:
5195 if (invalid_action) {
5197 "config action(%d) is not allowed for page_type(0x%02x), page_num(%d) with page_attribute(0x%02x)\n",
5198 cfg_req->action, cfg_req->page_type,
5199 cfg_req->page_number, cfg_hdr->page_attribute);
5202 mem_desc.size = le16_to_cpu(cfg_hdr->page_length) * 4;
5203 cfg_req->page_length = cfg_hdr->page_length;
5204 cfg_req->page_version = cfg_hdr->page_version;
5206 if (mpi3mr_alloc_config_dma_memory(mrioc, &mem_desc))
5209 mpi3mr_add_sg_single(&cfg_req->sgl, sgl_flags, mem_desc.size,
5212 if ((cfg_req->action == MPI3_CONFIG_ACTION_WRITE_PERSISTENT) ||
5213 (cfg_req->action == MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5214 memcpy(mem_desc.addr, cfg_buf, min_t(u16, mem_desc.size,
5216 dprint_cfg_info(mrioc, "config buffer to be written\n");
5217 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5218 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5221 if (mpi3mr_post_cfg_req(mrioc, cfg_req, timeout, ioc_status))
5225 if ((*ioc_status == MPI3_IOCSTATUS_SUCCESS) &&
5226 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_PERSISTENT) &&
5227 (cfg_req->action != MPI3_CONFIG_ACTION_WRITE_CURRENT)) {
5228 memcpy(cfg_buf, mem_desc.addr, min_t(u16, mem_desc.size,
5230 dprint_cfg_info(mrioc, "config buffer read\n");
5231 if (mrioc->logging_level & MPI3_DEBUG_CFG_INFO)
5232 dprint_dump(mem_desc.addr, mem_desc.size, "cfg_buf");
5236 mpi3mr_free_config_dma_memory(mrioc, &mem_desc);
5241 * mpi3mr_cfg_get_dev_pg0 - Read current device page0
5242 * @mrioc: Adapter instance reference
5243 * @ioc_status: Pointer to return ioc status
5244 * @dev_pg0: Pointer to return device page 0
5245 * @pg_sz: Size of the memory allocated to the page pointer
5246 * @form: The form to be used for addressing the page
5247 * @form_spec: Form specific information like device handle
5249 * This is handler for config page read for a specific device
5250 * page0. The ioc_status has the controller returned ioc_status.
5251 * This routine doesn't check ioc_status to decide whether the
5252 * page read is success or not and it is the callers
5255 * Return: 0 on success, non-zero on failure.
5257 int mpi3mr_cfg_get_dev_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5258 struct mpi3_device_page0 *dev_pg0, u16 pg_sz, u32 form, u32 form_spec)
5260 struct mpi3_config_page_header cfg_hdr;
5261 struct mpi3_config_request cfg_req;
5264 memset(dev_pg0, 0, pg_sz);
5265 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5266 memset(&cfg_req, 0, sizeof(cfg_req));
5268 cfg_req.function = MPI3_FUNCTION_CONFIG;
5269 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5270 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DEVICE;
5271 cfg_req.page_number = 0;
5272 cfg_req.page_address = 0;
5274 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5275 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5276 ioc_err(mrioc, "device page0 header read failed\n");
5279 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5280 ioc_err(mrioc, "device page0 header read failed with ioc_status(0x%04x)\n",
5284 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5285 page_address = ((form & MPI3_DEVICE_PGAD_FORM_MASK) |
5286 (form_spec & MPI3_DEVICE_PGAD_HANDLE_MASK));
5287 cfg_req.page_address = cpu_to_le32(page_address);
5288 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5289 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, dev_pg0, pg_sz)) {
5290 ioc_err(mrioc, "device page0 read failed\n");
5300 * mpi3mr_cfg_get_sas_phy_pg0 - Read current SAS Phy page0
5301 * @mrioc: Adapter instance reference
5302 * @ioc_status: Pointer to return ioc status
5303 * @phy_pg0: Pointer to return SAS Phy page 0
5304 * @pg_sz: Size of the memory allocated to the page pointer
5305 * @form: The form to be used for addressing the page
5306 * @form_spec: Form specific information like phy number
5308 * This is handler for config page read for a specific SAS Phy
5309 * page0. The ioc_status has the controller returned ioc_status.
5310 * This routine doesn't check ioc_status to decide whether the
5311 * page read is success or not and it is the callers
5314 * Return: 0 on success, non-zero on failure.
5316 int mpi3mr_cfg_get_sas_phy_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5317 struct mpi3_sas_phy_page0 *phy_pg0, u16 pg_sz, u32 form,
5320 struct mpi3_config_page_header cfg_hdr;
5321 struct mpi3_config_request cfg_req;
5324 memset(phy_pg0, 0, pg_sz);
5325 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5326 memset(&cfg_req, 0, sizeof(cfg_req));
5328 cfg_req.function = MPI3_FUNCTION_CONFIG;
5329 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5330 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5331 cfg_req.page_number = 0;
5332 cfg_req.page_address = 0;
5334 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5335 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5336 ioc_err(mrioc, "sas phy page0 header read failed\n");
5339 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5340 ioc_err(mrioc, "sas phy page0 header read failed with ioc_status(0x%04x)\n",
5344 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5345 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5346 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5347 cfg_req.page_address = cpu_to_le32(page_address);
5348 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5349 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg0, pg_sz)) {
5350 ioc_err(mrioc, "sas phy page0 read failed\n");
5359 * mpi3mr_cfg_get_sas_phy_pg1 - Read current SAS Phy page1
5360 * @mrioc: Adapter instance reference
5361 * @ioc_status: Pointer to return ioc status
5362 * @phy_pg1: Pointer to return SAS Phy page 1
5363 * @pg_sz: Size of the memory allocated to the page pointer
5364 * @form: The form to be used for addressing the page
5365 * @form_spec: Form specific information like phy number
5367 * This is handler for config page read for a specific SAS Phy
5368 * page1. The ioc_status has the controller returned ioc_status.
5369 * This routine doesn't check ioc_status to decide whether the
5370 * page read is success or not and it is the callers
5373 * Return: 0 on success, non-zero on failure.
5375 int mpi3mr_cfg_get_sas_phy_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5376 struct mpi3_sas_phy_page1 *phy_pg1, u16 pg_sz, u32 form,
5379 struct mpi3_config_page_header cfg_hdr;
5380 struct mpi3_config_request cfg_req;
5383 memset(phy_pg1, 0, pg_sz);
5384 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5385 memset(&cfg_req, 0, sizeof(cfg_req));
5387 cfg_req.function = MPI3_FUNCTION_CONFIG;
5388 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5389 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_PHY;
5390 cfg_req.page_number = 1;
5391 cfg_req.page_address = 0;
5393 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5394 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5395 ioc_err(mrioc, "sas phy page1 header read failed\n");
5398 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5399 ioc_err(mrioc, "sas phy page1 header read failed with ioc_status(0x%04x)\n",
5403 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5404 page_address = ((form & MPI3_SAS_PHY_PGAD_FORM_MASK) |
5405 (form_spec & MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK));
5406 cfg_req.page_address = cpu_to_le32(page_address);
5407 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5408 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, phy_pg1, pg_sz)) {
5409 ioc_err(mrioc, "sas phy page1 read failed\n");
5419 * mpi3mr_cfg_get_sas_exp_pg0 - Read current SAS Expander page0
5420 * @mrioc: Adapter instance reference
5421 * @ioc_status: Pointer to return ioc status
5422 * @exp_pg0: Pointer to return SAS Expander page 0
5423 * @pg_sz: Size of the memory allocated to the page pointer
5424 * @form: The form to be used for addressing the page
5425 * @form_spec: Form specific information like device handle
5427 * This is handler for config page read for a specific SAS
5428 * Expander page0. The ioc_status has the controller returned
5429 * ioc_status. This routine doesn't check ioc_status to decide
5430 * whether the page read is success or not and it is the callers
5433 * Return: 0 on success, non-zero on failure.
5435 int mpi3mr_cfg_get_sas_exp_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5436 struct mpi3_sas_expander_page0 *exp_pg0, u16 pg_sz, u32 form,
5439 struct mpi3_config_page_header cfg_hdr;
5440 struct mpi3_config_request cfg_req;
5443 memset(exp_pg0, 0, pg_sz);
5444 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5445 memset(&cfg_req, 0, sizeof(cfg_req));
5447 cfg_req.function = MPI3_FUNCTION_CONFIG;
5448 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5449 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5450 cfg_req.page_number = 0;
5451 cfg_req.page_address = 0;
5453 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5454 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5455 ioc_err(mrioc, "expander page0 header read failed\n");
5458 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5459 ioc_err(mrioc, "expander page0 header read failed with ioc_status(0x%04x)\n",
5463 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5464 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5465 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5466 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5467 cfg_req.page_address = cpu_to_le32(page_address);
5468 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5469 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg0, pg_sz)) {
5470 ioc_err(mrioc, "expander page0 read failed\n");
5479 * mpi3mr_cfg_get_sas_exp_pg1 - Read current SAS Expander page1
5480 * @mrioc: Adapter instance reference
5481 * @ioc_status: Pointer to return ioc status
5482 * @exp_pg1: Pointer to return SAS Expander page 1
5483 * @pg_sz: Size of the memory allocated to the page pointer
5484 * @form: The form to be used for addressing the page
5485 * @form_spec: Form specific information like phy number
5487 * This is handler for config page read for a specific SAS
5488 * Expander page1. The ioc_status has the controller returned
5489 * ioc_status. This routine doesn't check ioc_status to decide
5490 * whether the page read is success or not and it is the callers
5493 * Return: 0 on success, non-zero on failure.
5495 int mpi3mr_cfg_get_sas_exp_pg1(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5496 struct mpi3_sas_expander_page1 *exp_pg1, u16 pg_sz, u32 form,
5499 struct mpi3_config_page_header cfg_hdr;
5500 struct mpi3_config_request cfg_req;
5503 memset(exp_pg1, 0, pg_sz);
5504 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5505 memset(&cfg_req, 0, sizeof(cfg_req));
5507 cfg_req.function = MPI3_FUNCTION_CONFIG;
5508 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5509 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_EXPANDER;
5510 cfg_req.page_number = 1;
5511 cfg_req.page_address = 0;
5513 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5514 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5515 ioc_err(mrioc, "expander page1 header read failed\n");
5518 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5519 ioc_err(mrioc, "expander page1 header read failed with ioc_status(0x%04x)\n",
5523 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5524 page_address = ((form & MPI3_SAS_EXPAND_PGAD_FORM_MASK) |
5525 (form_spec & (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK |
5526 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK)));
5527 cfg_req.page_address = cpu_to_le32(page_address);
5528 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5529 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, exp_pg1, pg_sz)) {
5530 ioc_err(mrioc, "expander page1 read failed\n");
5539 * mpi3mr_cfg_get_enclosure_pg0 - Read current Enclosure page0
5540 * @mrioc: Adapter instance reference
5541 * @ioc_status: Pointer to return ioc status
5542 * @encl_pg0: Pointer to return Enclosure page 0
5543 * @pg_sz: Size of the memory allocated to the page pointer
5544 * @form: The form to be used for addressing the page
5545 * @form_spec: Form specific information like device handle
5547 * This is handler for config page read for a specific Enclosure
5548 * page0. The ioc_status has the controller returned ioc_status.
5549 * This routine doesn't check ioc_status to decide whether the
5550 * page read is success or not and it is the callers
5553 * Return: 0 on success, non-zero on failure.
5555 int mpi3mr_cfg_get_enclosure_pg0(struct mpi3mr_ioc *mrioc, u16 *ioc_status,
5556 struct mpi3_enclosure_page0 *encl_pg0, u16 pg_sz, u32 form,
5559 struct mpi3_config_page_header cfg_hdr;
5560 struct mpi3_config_request cfg_req;
5563 memset(encl_pg0, 0, pg_sz);
5564 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5565 memset(&cfg_req, 0, sizeof(cfg_req));
5567 cfg_req.function = MPI3_FUNCTION_CONFIG;
5568 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5569 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_ENCLOSURE;
5570 cfg_req.page_number = 0;
5571 cfg_req.page_address = 0;
5573 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5574 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5575 ioc_err(mrioc, "enclosure page0 header read failed\n");
5578 if (*ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5579 ioc_err(mrioc, "enclosure page0 header read failed with ioc_status(0x%04x)\n",
5583 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5584 page_address = ((form & MPI3_ENCLOS_PGAD_FORM_MASK) |
5585 (form_spec & MPI3_ENCLOS_PGAD_HANDLE_MASK));
5586 cfg_req.page_address = cpu_to_le32(page_address);
5587 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5588 MPI3MR_INTADMCMD_TIMEOUT, ioc_status, encl_pg0, pg_sz)) {
5589 ioc_err(mrioc, "enclosure page0 read failed\n");
5599 * mpi3mr_cfg_get_sas_io_unit_pg0 - Read current SASIOUnit page0
5600 * @mrioc: Adapter instance reference
5601 * @sas_io_unit_pg0: Pointer to return SAS IO Unit page 0
5602 * @pg_sz: Size of the memory allocated to the page pointer
5604 * This is handler for config page read for the SAS IO Unit
5605 * page0. This routine checks ioc_status to decide whether the
5606 * page read is success or not.
5608 * Return: 0 on success, non-zero on failure.
5610 int mpi3mr_cfg_get_sas_io_unit_pg0(struct mpi3mr_ioc *mrioc,
5611 struct mpi3_sas_io_unit_page0 *sas_io_unit_pg0, u16 pg_sz)
5613 struct mpi3_config_page_header cfg_hdr;
5614 struct mpi3_config_request cfg_req;
5617 memset(sas_io_unit_pg0, 0, pg_sz);
5618 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5619 memset(&cfg_req, 0, sizeof(cfg_req));
5621 cfg_req.function = MPI3_FUNCTION_CONFIG;
5622 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5623 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5624 cfg_req.page_number = 0;
5625 cfg_req.page_address = 0;
5627 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5628 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5629 ioc_err(mrioc, "sas io unit page0 header read failed\n");
5632 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5633 ioc_err(mrioc, "sas io unit page0 header read failed with ioc_status(0x%04x)\n",
5637 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5639 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5640 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg0, pg_sz)) {
5641 ioc_err(mrioc, "sas io unit page0 read failed\n");
5644 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5645 ioc_err(mrioc, "sas io unit page0 read failed with ioc_status(0x%04x)\n",
5655 * mpi3mr_cfg_get_sas_io_unit_pg1 - Read current SASIOUnit page1
5656 * @mrioc: Adapter instance reference
5657 * @sas_io_unit_pg1: Pointer to return SAS IO Unit page 1
5658 * @pg_sz: Size of the memory allocated to the page pointer
5660 * This is handler for config page read for the SAS IO Unit
5661 * page1. This routine checks ioc_status to decide whether the
5662 * page read is success or not.
5664 * Return: 0 on success, non-zero on failure.
5666 int mpi3mr_cfg_get_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5667 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5669 struct mpi3_config_page_header cfg_hdr;
5670 struct mpi3_config_request cfg_req;
5673 memset(sas_io_unit_pg1, 0, pg_sz);
5674 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5675 memset(&cfg_req, 0, sizeof(cfg_req));
5677 cfg_req.function = MPI3_FUNCTION_CONFIG;
5678 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5679 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5680 cfg_req.page_number = 1;
5681 cfg_req.page_address = 0;
5683 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5684 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5685 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5688 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5689 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5693 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5695 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5696 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5697 ioc_err(mrioc, "sas io unit page1 read failed\n");
5700 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5701 ioc_err(mrioc, "sas io unit page1 read failed with ioc_status(0x%04x)\n",
5711 * mpi3mr_cfg_set_sas_io_unit_pg1 - Write SASIOUnit page1
5712 * @mrioc: Adapter instance reference
5713 * @sas_io_unit_pg1: Pointer to the SAS IO Unit page 1 to write
5714 * @pg_sz: Size of the memory allocated to the page pointer
5716 * This is handler for config page write for the SAS IO Unit
5717 * page1. This routine checks ioc_status to decide whether the
5718 * page read is success or not. This will modify both current
5719 * and persistent page.
5721 * Return: 0 on success, non-zero on failure.
5723 int mpi3mr_cfg_set_sas_io_unit_pg1(struct mpi3mr_ioc *mrioc,
5724 struct mpi3_sas_io_unit_page1 *sas_io_unit_pg1, u16 pg_sz)
5726 struct mpi3_config_page_header cfg_hdr;
5727 struct mpi3_config_request cfg_req;
5730 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5731 memset(&cfg_req, 0, sizeof(cfg_req));
5733 cfg_req.function = MPI3_FUNCTION_CONFIG;
5734 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5735 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT;
5736 cfg_req.page_number = 1;
5737 cfg_req.page_address = 0;
5739 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5740 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5741 ioc_err(mrioc, "sas io unit page1 header read failed\n");
5744 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5745 ioc_err(mrioc, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
5749 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_CURRENT;
5751 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5752 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5753 ioc_err(mrioc, "sas io unit page1 write current failed\n");
5756 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5757 ioc_err(mrioc, "sas io unit page1 write current failed with ioc_status(0x%04x)\n",
5762 cfg_req.action = MPI3_CONFIG_ACTION_WRITE_PERSISTENT;
5764 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5765 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, sas_io_unit_pg1, pg_sz)) {
5766 ioc_err(mrioc, "sas io unit page1 write persistent failed\n");
5769 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5770 ioc_err(mrioc, "sas io unit page1 write persistent failed with ioc_status(0x%04x)\n",
5780 * mpi3mr_cfg_get_driver_pg1 - Read current Driver page1
5781 * @mrioc: Adapter instance reference
5782 * @driver_pg1: Pointer to return Driver page 1
5783 * @pg_sz: Size of the memory allocated to the page pointer
5785 * This is handler for config page read for the Driver page1.
5786 * This routine checks ioc_status to decide whether the page
5787 * read is success or not.
5789 * Return: 0 on success, non-zero on failure.
5791 int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc *mrioc,
5792 struct mpi3_driver_page1 *driver_pg1, u16 pg_sz)
5794 struct mpi3_config_page_header cfg_hdr;
5795 struct mpi3_config_request cfg_req;
5798 memset(driver_pg1, 0, pg_sz);
5799 memset(&cfg_hdr, 0, sizeof(cfg_hdr));
5800 memset(&cfg_req, 0, sizeof(cfg_req));
5802 cfg_req.function = MPI3_FUNCTION_CONFIG;
5803 cfg_req.action = MPI3_CONFIG_ACTION_PAGE_HEADER;
5804 cfg_req.page_type = MPI3_CONFIG_PAGETYPE_DRIVER;
5805 cfg_req.page_number = 1;
5806 cfg_req.page_address = 0;
5808 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, NULL,
5809 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, &cfg_hdr, sizeof(cfg_hdr))) {
5810 ioc_err(mrioc, "driver page1 header read failed\n");
5813 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5814 ioc_err(mrioc, "driver page1 header read failed with ioc_status(0x%04x)\n",
5818 cfg_req.action = MPI3_CONFIG_ACTION_READ_CURRENT;
5820 if (mpi3mr_process_cfg_req(mrioc, &cfg_req, &cfg_hdr,
5821 MPI3MR_INTADMCMD_TIMEOUT, &ioc_status, driver_pg1, pg_sz)) {
5822 ioc_err(mrioc, "driver page1 read failed\n");
5825 if (ioc_status != MPI3_IOCSTATUS_SUCCESS) {
5826 ioc_err(mrioc, "driver page1 read failed with ioc_status(0x%04x)\n",