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
, u16 reset_reason
);
15 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc
*mrioc
);
16 static void mpi3mr_process_factsdata(struct mpi3mr_ioc
*mrioc
,
17 struct mpi3_ioc_facts_data
*facts_data
);
18 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc
*mrioc
,
19 struct mpi3mr_drv_cmd
*drv_cmd
);
21 static int poll_queues
;
22 module_param(poll_queues
, int, 0444);
23 MODULE_PARM_DESC(poll_queues
, "Number of queues for io_uring poll mode. (Range 1 - 126)");
25 #if defined(writeq) && defined(CONFIG_64BIT)
26 static inline void mpi3mr_writeq(__u64 b
, volatile void __iomem
*addr
)
31 static inline void mpi3mr_writeq(__u64 b
, volatile void __iomem
*addr
)
35 writel((u32
)(data_out
), addr
);
36 writel((u32
)(data_out
>> 32), (addr
+ 4));
41 mpi3mr_check_req_qfull(struct op_req_qinfo
*op_req_q
)
43 u16 pi
, ci
, max_entries
;
44 bool is_qfull
= false;
47 ci
= READ_ONCE(op_req_q
->ci
);
48 max_entries
= op_req_q
->num_requests
;
50 if ((ci
== (pi
+ 1)) || ((!ci
) && (pi
== (max_entries
- 1))))
56 static void mpi3mr_sync_irqs(struct mpi3mr_ioc
*mrioc
)
60 max_vectors
= mrioc
->intr_info_count
;
62 for (i
= 0; i
< max_vectors
; i
++)
63 synchronize_irq(pci_irq_vector(mrioc
->pdev
, i
));
66 void mpi3mr_ioc_disable_intr(struct mpi3mr_ioc
*mrioc
)
68 mrioc
->intr_enabled
= 0;
69 mpi3mr_sync_irqs(mrioc
);
72 void mpi3mr_ioc_enable_intr(struct mpi3mr_ioc
*mrioc
)
74 mrioc
->intr_enabled
= 1;
77 static void mpi3mr_cleanup_isr(struct mpi3mr_ioc
*mrioc
)
81 mpi3mr_ioc_disable_intr(mrioc
);
83 if (!mrioc
->intr_info
)
86 for (i
= 0; i
< mrioc
->intr_info_count
; i
++)
87 free_irq(pci_irq_vector(mrioc
->pdev
, i
),
88 (mrioc
->intr_info
+ i
));
90 kfree(mrioc
->intr_info
);
91 mrioc
->intr_info
= NULL
;
92 mrioc
->intr_info_count
= 0;
93 mrioc
->is_intr_info_set
= false;
94 pci_free_irq_vectors(mrioc
->pdev
);
97 void mpi3mr_add_sg_single(void *paddr
, u8 flags
, u32 length
,
100 struct mpi3_sge_common
*sgel
= paddr
;
103 sgel
->length
= cpu_to_le32(length
);
104 sgel
->address
= cpu_to_le64(dma_addr
);
107 void mpi3mr_build_zero_len_sge(void *paddr
)
109 u8 sgl_flags
= MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST
;
111 mpi3mr_add_sg_single(paddr
, sgl_flags
, 0, -1);
114 void *mpi3mr_get_reply_virt_addr(struct mpi3mr_ioc
*mrioc
,
115 dma_addr_t phys_addr
)
120 if ((phys_addr
< mrioc
->reply_buf_dma
) ||
121 (phys_addr
> mrioc
->reply_buf_dma_max_address
))
124 return mrioc
->reply_buf
+ (phys_addr
- mrioc
->reply_buf_dma
);
127 void *mpi3mr_get_sensebuf_virt_addr(struct mpi3mr_ioc
*mrioc
,
128 dma_addr_t phys_addr
)
133 return mrioc
->sense_buf
+ (phys_addr
- mrioc
->sense_buf_dma
);
136 static void mpi3mr_repost_reply_buf(struct mpi3mr_ioc
*mrioc
,
142 spin_lock_irqsave(&mrioc
->reply_free_queue_lock
, flags
);
143 old_idx
= mrioc
->reply_free_queue_host_index
;
144 mrioc
->reply_free_queue_host_index
= (
145 (mrioc
->reply_free_queue_host_index
==
146 (mrioc
->reply_free_qsz
- 1)) ? 0 :
147 (mrioc
->reply_free_queue_host_index
+ 1));
148 mrioc
->reply_free_q
[old_idx
] = cpu_to_le64(reply_dma
);
149 writel(mrioc
->reply_free_queue_host_index
,
150 &mrioc
->sysif_regs
->reply_free_host_index
);
151 spin_unlock_irqrestore(&mrioc
->reply_free_queue_lock
, flags
);
154 void mpi3mr_repost_sense_buf(struct mpi3mr_ioc
*mrioc
,
160 spin_lock_irqsave(&mrioc
->sbq_lock
, flags
);
161 old_idx
= mrioc
->sbq_host_index
;
162 mrioc
->sbq_host_index
= ((mrioc
->sbq_host_index
==
163 (mrioc
->sense_buf_q_sz
- 1)) ? 0 :
164 (mrioc
->sbq_host_index
+ 1));
165 mrioc
->sense_buf_q
[old_idx
] = cpu_to_le64(sense_buf_dma
);
166 writel(mrioc
->sbq_host_index
,
167 &mrioc
->sysif_regs
->sense_buffer_free_host_index
);
168 spin_unlock_irqrestore(&mrioc
->sbq_lock
, flags
);
171 static void mpi3mr_print_event_data(struct mpi3mr_ioc
*mrioc
,
172 struct mpi3_event_notification_reply
*event_reply
)
177 event
= event_reply
->event
;
180 case MPI3_EVENT_LOG_DATA
:
183 case MPI3_EVENT_CHANGE
:
184 desc
= "Event Change";
186 case MPI3_EVENT_GPIO_INTERRUPT
:
187 desc
= "GPIO Interrupt";
189 case MPI3_EVENT_CABLE_MGMT
:
190 desc
= "Cable Management";
192 case MPI3_EVENT_ENERGY_PACK_CHANGE
:
193 desc
= "Energy Pack Change";
195 case MPI3_EVENT_DEVICE_ADDED
:
197 struct mpi3_device_page0
*event_data
=
198 (struct mpi3_device_page0
*)event_reply
->event_data
;
199 ioc_info(mrioc
, "Device Added: dev=0x%04x Form=0x%x\n",
200 event_data
->dev_handle
, event_data
->device_form
);
203 case MPI3_EVENT_DEVICE_INFO_CHANGED
:
205 struct mpi3_device_page0
*event_data
=
206 (struct mpi3_device_page0
*)event_reply
->event_data
;
207 ioc_info(mrioc
, "Device Info Changed: dev=0x%04x Form=0x%x\n",
208 event_data
->dev_handle
, event_data
->device_form
);
211 case MPI3_EVENT_DEVICE_STATUS_CHANGE
:
213 struct mpi3_event_data_device_status_change
*event_data
=
214 (struct mpi3_event_data_device_status_change
*)event_reply
->event_data
;
215 ioc_info(mrioc
, "Device status Change: dev=0x%04x RC=0x%x\n",
216 event_data
->dev_handle
, event_data
->reason_code
);
219 case MPI3_EVENT_SAS_DISCOVERY
:
221 struct mpi3_event_data_sas_discovery
*event_data
=
222 (struct mpi3_event_data_sas_discovery
*)event_reply
->event_data
;
223 ioc_info(mrioc
, "SAS Discovery: (%s) status (0x%08x)\n",
224 (event_data
->reason_code
== MPI3_EVENT_SAS_DISC_RC_STARTED
) ?
226 le32_to_cpu(event_data
->discovery_status
));
229 case MPI3_EVENT_SAS_BROADCAST_PRIMITIVE
:
230 desc
= "SAS Broadcast Primitive";
232 case MPI3_EVENT_SAS_NOTIFY_PRIMITIVE
:
233 desc
= "SAS Notify Primitive";
235 case MPI3_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE
:
236 desc
= "SAS Init Device Status Change";
238 case MPI3_EVENT_SAS_INIT_TABLE_OVERFLOW
:
239 desc
= "SAS Init Table Overflow";
241 case MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST
:
242 desc
= "SAS Topology Change List";
244 case MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE
:
245 desc
= "Enclosure Device Status Change";
247 case MPI3_EVENT_ENCL_DEVICE_ADDED
:
248 desc
= "Enclosure Added";
250 case MPI3_EVENT_HARD_RESET_RECEIVED
:
251 desc
= "Hard Reset Received";
253 case MPI3_EVENT_SAS_PHY_COUNTER
:
254 desc
= "SAS PHY Counter";
256 case MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR
:
257 desc
= "SAS Device Discovery Error";
259 case MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
:
260 desc
= "PCIE Topology Change List";
262 case MPI3_EVENT_PCIE_ENUMERATION
:
264 struct mpi3_event_data_pcie_enumeration
*event_data
=
265 (struct mpi3_event_data_pcie_enumeration
*)event_reply
->event_data
;
266 ioc_info(mrioc
, "PCIE Enumeration: (%s)",
267 (event_data
->reason_code
==
268 MPI3_EVENT_PCIE_ENUM_RC_STARTED
) ? "start" : "stop");
269 if (event_data
->enumeration_status
)
270 ioc_info(mrioc
, "enumeration_status(0x%08x)\n",
271 le32_to_cpu(event_data
->enumeration_status
));
274 case MPI3_EVENT_PREPARE_FOR_RESET
:
275 desc
= "Prepare For Reset";
277 case MPI3_EVENT_DIAGNOSTIC_BUFFER_STATUS_CHANGE
:
278 desc
= "Diagnostic Buffer Status Change";
285 ioc_info(mrioc
, "%s\n", desc
);
288 static void mpi3mr_handle_events(struct mpi3mr_ioc
*mrioc
,
289 struct mpi3_default_reply
*def_reply
)
291 struct mpi3_event_notification_reply
*event_reply
=
292 (struct mpi3_event_notification_reply
*)def_reply
;
294 mrioc
->change_count
= le16_to_cpu(event_reply
->ioc_change_count
);
295 mpi3mr_print_event_data(mrioc
, event_reply
);
296 mpi3mr_os_handle_events(mrioc
, event_reply
);
299 static struct mpi3mr_drv_cmd
*
300 mpi3mr_get_drv_cmd(struct mpi3mr_ioc
*mrioc
, u16 host_tag
,
301 struct mpi3_default_reply
*def_reply
)
306 case MPI3MR_HOSTTAG_INITCMDS
:
307 return &mrioc
->init_cmds
;
308 case MPI3MR_HOSTTAG_CFG_CMDS
:
309 return &mrioc
->cfg_cmds
;
310 case MPI3MR_HOSTTAG_BSG_CMDS
:
311 return &mrioc
->bsg_cmds
;
312 case MPI3MR_HOSTTAG_BLK_TMS
:
313 return &mrioc
->host_tm_cmds
;
314 case MPI3MR_HOSTTAG_PEL_ABORT
:
315 return &mrioc
->pel_abort_cmd
;
316 case MPI3MR_HOSTTAG_PEL_WAIT
:
317 return &mrioc
->pel_cmds
;
318 case MPI3MR_HOSTTAG_TRANSPORT_CMDS
:
319 return &mrioc
->transport_cmds
;
320 case MPI3MR_HOSTTAG_INVALID
:
321 if (def_reply
&& def_reply
->function
==
322 MPI3_FUNCTION_EVENT_NOTIFICATION
)
323 mpi3mr_handle_events(mrioc
, def_reply
);
328 if (host_tag
>= MPI3MR_HOSTTAG_DEVRMCMD_MIN
&&
329 host_tag
<= MPI3MR_HOSTTAG_DEVRMCMD_MAX
) {
330 idx
= host_tag
- MPI3MR_HOSTTAG_DEVRMCMD_MIN
;
331 return &mrioc
->dev_rmhs_cmds
[idx
];
334 if (host_tag
>= MPI3MR_HOSTTAG_EVTACKCMD_MIN
&&
335 host_tag
<= MPI3MR_HOSTTAG_EVTACKCMD_MAX
) {
336 idx
= host_tag
- MPI3MR_HOSTTAG_EVTACKCMD_MIN
;
337 return &mrioc
->evtack_cmds
[idx
];
343 static void mpi3mr_process_admin_reply_desc(struct mpi3mr_ioc
*mrioc
,
344 struct mpi3_default_reply_descriptor
*reply_desc
, u64
*reply_dma
)
346 u16 reply_desc_type
, host_tag
= 0;
347 u16 ioc_status
= MPI3_IOCSTATUS_SUCCESS
;
348 u16 masked_ioc_status
= MPI3_IOCSTATUS_SUCCESS
;
349 u32 ioc_loginfo
= 0, sense_count
= 0;
350 struct mpi3_status_reply_descriptor
*status_desc
;
351 struct mpi3_address_reply_descriptor
*addr_desc
;
352 struct mpi3_success_reply_descriptor
*success_desc
;
353 struct mpi3_default_reply
*def_reply
= NULL
;
354 struct mpi3mr_drv_cmd
*cmdptr
= NULL
;
355 struct mpi3_scsi_io_reply
*scsi_reply
;
356 struct scsi_sense_hdr sshdr
;
357 u8
*sense_buf
= NULL
;
360 reply_desc_type
= le16_to_cpu(reply_desc
->reply_flags
) &
361 MPI3_REPLY_DESCRIPT_FLAGS_TYPE_MASK
;
362 switch (reply_desc_type
) {
363 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_STATUS
:
364 status_desc
= (struct mpi3_status_reply_descriptor
*)reply_desc
;
365 host_tag
= le16_to_cpu(status_desc
->host_tag
);
366 ioc_status
= le16_to_cpu(status_desc
->ioc_status
);
368 MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL
)
369 ioc_loginfo
= le32_to_cpu(status_desc
->ioc_log_info
);
370 masked_ioc_status
= ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
;
371 mpi3mr_reply_trigger(mrioc
, masked_ioc_status
, ioc_loginfo
);
373 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_ADDRESS_REPLY
:
374 addr_desc
= (struct mpi3_address_reply_descriptor
*)reply_desc
;
375 *reply_dma
= le64_to_cpu(addr_desc
->reply_frame_address
);
376 def_reply
= mpi3mr_get_reply_virt_addr(mrioc
, *reply_dma
);
379 host_tag
= le16_to_cpu(def_reply
->host_tag
);
380 ioc_status
= le16_to_cpu(def_reply
->ioc_status
);
382 MPI3_REPLY_DESCRIPT_STATUS_IOCSTATUS_LOGINFOAVAIL
)
383 ioc_loginfo
= le32_to_cpu(def_reply
->ioc_log_info
);
384 masked_ioc_status
= ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
;
385 if (def_reply
->function
== MPI3_FUNCTION_SCSI_IO
) {
386 scsi_reply
= (struct mpi3_scsi_io_reply
*)def_reply
;
387 sense_buf
= mpi3mr_get_sensebuf_virt_addr(mrioc
,
388 le64_to_cpu(scsi_reply
->sense_data_buffer_address
));
389 sense_count
= le32_to_cpu(scsi_reply
->sense_count
);
391 scsi_normalize_sense(sense_buf
, sense_count
,
393 mpi3mr_scsisense_trigger(mrioc
, sshdr
.sense_key
,
394 sshdr
.asc
, sshdr
.ascq
);
397 mpi3mr_reply_trigger(mrioc
, masked_ioc_status
, ioc_loginfo
);
399 case MPI3_REPLY_DESCRIPT_FLAGS_TYPE_SUCCESS
:
400 success_desc
= (struct mpi3_success_reply_descriptor
*)reply_desc
;
401 host_tag
= le16_to_cpu(success_desc
->host_tag
);
407 cmdptr
= mpi3mr_get_drv_cmd(mrioc
, host_tag
, def_reply
);
409 if (cmdptr
->state
& MPI3MR_CMD_PENDING
) {
410 cmdptr
->state
|= MPI3MR_CMD_COMPLETE
;
411 cmdptr
->ioc_loginfo
= ioc_loginfo
;
412 if (host_tag
== MPI3MR_HOSTTAG_BSG_CMDS
)
413 cmdptr
->ioc_status
= ioc_status
;
415 cmdptr
->ioc_status
= masked_ioc_status
;
416 cmdptr
->state
&= ~MPI3MR_CMD_PENDING
;
418 cmdptr
->state
|= MPI3MR_CMD_REPLY_VALID
;
419 memcpy((u8
*)cmdptr
->reply
, (u8
*)def_reply
,
422 if (sense_buf
&& cmdptr
->sensebuf
) {
423 cmdptr
->is_sense
= 1;
424 memcpy(cmdptr
->sensebuf
, sense_buf
,
425 MPI3MR_SENSE_BUF_SZ
);
427 if (cmdptr
->is_waiting
) {
428 complete(&cmdptr
->done
);
429 cmdptr
->is_waiting
= 0;
430 } else if (cmdptr
->callback
)
431 cmdptr
->callback(mrioc
, cmdptr
);
436 mpi3mr_repost_sense_buf(mrioc
,
437 le64_to_cpu(scsi_reply
->sense_data_buffer_address
));
440 int mpi3mr_process_admin_reply_q(struct mpi3mr_ioc
*mrioc
)
442 u32 exp_phase
= mrioc
->admin_reply_ephase
;
443 u32 admin_reply_ci
= mrioc
->admin_reply_ci
;
444 u32 num_admin_replies
= 0;
446 u16 threshold_comps
= 0;
447 struct mpi3_default_reply_descriptor
*reply_desc
;
449 if (!atomic_add_unless(&mrioc
->admin_reply_q_in_use
, 1, 1))
452 reply_desc
= (struct mpi3_default_reply_descriptor
*)mrioc
->admin_reply_base
+
455 if ((le16_to_cpu(reply_desc
->reply_flags
) &
456 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK
) != exp_phase
) {
457 atomic_dec(&mrioc
->admin_reply_q_in_use
);
462 if (mrioc
->unrecoverable
)
465 mrioc
->admin_req_ci
= le16_to_cpu(reply_desc
->request_queue_ci
);
466 mpi3mr_process_admin_reply_desc(mrioc
, reply_desc
, &reply_dma
);
468 mpi3mr_repost_reply_buf(mrioc
, reply_dma
);
471 if (++admin_reply_ci
== mrioc
->num_admin_replies
) {
476 (struct mpi3_default_reply_descriptor
*)mrioc
->admin_reply_base
+
478 if ((le16_to_cpu(reply_desc
->reply_flags
) &
479 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK
) != exp_phase
)
481 if (threshold_comps
== MPI3MR_THRESHOLD_REPLY_COUNT
) {
482 writel(admin_reply_ci
,
483 &mrioc
->sysif_regs
->admin_reply_queue_ci
);
488 writel(admin_reply_ci
, &mrioc
->sysif_regs
->admin_reply_queue_ci
);
489 mrioc
->admin_reply_ci
= admin_reply_ci
;
490 mrioc
->admin_reply_ephase
= exp_phase
;
491 atomic_dec(&mrioc
->admin_reply_q_in_use
);
493 return num_admin_replies
;
497 * mpi3mr_get_reply_desc - get reply descriptor frame corresponding to
498 * queue's consumer index from operational reply descriptor queue.
499 * @op_reply_q: op_reply_qinfo object
500 * @reply_ci: operational reply descriptor's queue consumer index
502 * Returns: reply descriptor frame address
504 static inline struct mpi3_default_reply_descriptor
*
505 mpi3mr_get_reply_desc(struct op_reply_qinfo
*op_reply_q
, u32 reply_ci
)
507 void *segment_base_addr
;
508 struct segments
*segments
= op_reply_q
->q_segments
;
509 struct mpi3_default_reply_descriptor
*reply_desc
= NULL
;
512 segments
[reply_ci
/ op_reply_q
->segment_qd
].segment
;
513 reply_desc
= (struct mpi3_default_reply_descriptor
*)segment_base_addr
+
514 (reply_ci
% op_reply_q
->segment_qd
);
519 * mpi3mr_process_op_reply_q - Operational reply queue handler
520 * @mrioc: Adapter instance reference
521 * @op_reply_q: Operational reply queue info
523 * Checks the specific operational reply queue and drains the
524 * reply queue entries until the queue is empty and process the
525 * individual reply descriptors.
527 * Return: 0 if queue is already processed,or number of reply
528 * descriptors processed.
530 int mpi3mr_process_op_reply_q(struct mpi3mr_ioc
*mrioc
,
531 struct op_reply_qinfo
*op_reply_q
)
533 struct op_req_qinfo
*op_req_q
;
536 u32 num_op_reply
= 0;
538 struct mpi3_default_reply_descriptor
*reply_desc
;
539 u16 req_q_idx
= 0, reply_qidx
, threshold_comps
= 0;
541 reply_qidx
= op_reply_q
->qid
- 1;
543 if (!atomic_add_unless(&op_reply_q
->in_use
, 1, 1))
546 exp_phase
= op_reply_q
->ephase
;
547 reply_ci
= op_reply_q
->ci
;
549 reply_desc
= mpi3mr_get_reply_desc(op_reply_q
, reply_ci
);
550 if ((le16_to_cpu(reply_desc
->reply_flags
) &
551 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK
) != exp_phase
) {
552 atomic_dec(&op_reply_q
->in_use
);
557 if (mrioc
->unrecoverable
)
560 req_q_idx
= le16_to_cpu(reply_desc
->request_queue_id
) - 1;
561 op_req_q
= &mrioc
->req_qinfo
[req_q_idx
];
563 WRITE_ONCE(op_req_q
->ci
, le16_to_cpu(reply_desc
->request_queue_ci
));
564 mpi3mr_process_op_reply_desc(mrioc
, reply_desc
, &reply_dma
,
566 atomic_dec(&op_reply_q
->pend_ios
);
568 mpi3mr_repost_reply_buf(mrioc
, reply_dma
);
572 if (++reply_ci
== op_reply_q
->num_replies
) {
577 reply_desc
= mpi3mr_get_reply_desc(op_reply_q
, reply_ci
);
579 if ((le16_to_cpu(reply_desc
->reply_flags
) &
580 MPI3_REPLY_DESCRIPT_FLAGS_PHASE_MASK
) != exp_phase
)
582 #ifndef CONFIG_PREEMPT_RT
584 * Exit completion loop to avoid CPU lockup
585 * Ensure remaining completion happens from threaded ISR.
587 if (num_op_reply
> mrioc
->max_host_ios
) {
588 op_reply_q
->enable_irq_poll
= true;
592 if (threshold_comps
== MPI3MR_THRESHOLD_REPLY_COUNT
) {
594 &mrioc
->sysif_regs
->oper_queue_indexes
[reply_qidx
].consumer_index
);
595 atomic_sub(threshold_comps
, &op_reply_q
->pend_ios
);
601 &mrioc
->sysif_regs
->oper_queue_indexes
[reply_qidx
].consumer_index
);
602 op_reply_q
->ci
= reply_ci
;
603 op_reply_q
->ephase
= exp_phase
;
604 atomic_sub(threshold_comps
, &op_reply_q
->pend_ios
);
605 atomic_dec(&op_reply_q
->in_use
);
610 * mpi3mr_blk_mq_poll - Operational reply queue handler
611 * @shost: SCSI Host reference
612 * @queue_num: Request queue number (w.r.t OS it is hardware context number)
614 * Checks the specific operational reply queue and drains the
615 * reply queue entries until the queue is empty and process the
616 * individual reply descriptors.
618 * Return: 0 if queue is already processed,or number of reply
619 * descriptors processed.
621 int mpi3mr_blk_mq_poll(struct Scsi_Host
*shost
, unsigned int queue_num
)
624 struct mpi3mr_ioc
*mrioc
;
626 mrioc
= (struct mpi3mr_ioc
*)shost
->hostdata
;
628 if ((mrioc
->reset_in_progress
|| mrioc
->prepare_for_reset
||
629 mrioc
->unrecoverable
|| mrioc
->pci_err_recovery
))
632 num_entries
= mpi3mr_process_op_reply_q(mrioc
,
633 &mrioc
->op_reply_qinfo
[queue_num
]);
638 static irqreturn_t
mpi3mr_isr_primary(int irq
, void *privdata
)
640 struct mpi3mr_intr_info
*intr_info
= privdata
;
641 struct mpi3mr_ioc
*mrioc
;
643 u32 num_admin_replies
= 0, num_op_reply
= 0;
648 mrioc
= intr_info
->mrioc
;
650 if (!mrioc
->intr_enabled
)
653 midx
= intr_info
->msix_index
;
656 num_admin_replies
= mpi3mr_process_admin_reply_q(mrioc
);
657 if (intr_info
->op_reply_q
)
658 num_op_reply
= mpi3mr_process_op_reply_q(mrioc
,
659 intr_info
->op_reply_q
);
661 if (num_admin_replies
|| num_op_reply
)
667 #ifndef CONFIG_PREEMPT_RT
669 static irqreturn_t
mpi3mr_isr(int irq
, void *privdata
)
671 struct mpi3mr_intr_info
*intr_info
= privdata
;
677 /* Call primary ISR routine */
678 ret
= mpi3mr_isr_primary(irq
, privdata
);
681 * If more IOs are expected, schedule IRQ polling thread.
682 * Otherwise exit from ISR.
684 if (!intr_info
->op_reply_q
)
687 if (!intr_info
->op_reply_q
->enable_irq_poll
||
688 !atomic_read(&intr_info
->op_reply_q
->pend_ios
))
691 disable_irq_nosync(intr_info
->os_irq
);
693 return IRQ_WAKE_THREAD
;
697 * mpi3mr_isr_poll - Reply queue polling routine
699 * @privdata: Interrupt info
701 * poll for pending I/O completions in a loop until pending I/Os
702 * present or controller queue depth I/Os are processed.
704 * Return: IRQ_NONE or IRQ_HANDLED
706 static irqreturn_t
mpi3mr_isr_poll(int irq
, void *privdata
)
708 struct mpi3mr_intr_info
*intr_info
= privdata
;
709 struct mpi3mr_ioc
*mrioc
;
711 u32 num_op_reply
= 0;
713 if (!intr_info
|| !intr_info
->op_reply_q
)
716 mrioc
= intr_info
->mrioc
;
717 midx
= intr_info
->msix_index
;
719 /* Poll for pending IOs completions */
721 if (!mrioc
->intr_enabled
|| mrioc
->unrecoverable
)
725 mpi3mr_process_admin_reply_q(mrioc
);
726 if (intr_info
->op_reply_q
)
728 mpi3mr_process_op_reply_q(mrioc
,
729 intr_info
->op_reply_q
);
731 usleep_range(MPI3MR_IRQ_POLL_SLEEP
, MPI3MR_IRQ_POLL_SLEEP
+ 1);
733 } while (atomic_read(&intr_info
->op_reply_q
->pend_ios
) &&
734 (num_op_reply
< mrioc
->max_host_ios
));
736 intr_info
->op_reply_q
->enable_irq_poll
= false;
737 enable_irq(intr_info
->os_irq
);
745 * mpi3mr_request_irq - Request IRQ and register ISR
746 * @mrioc: Adapter instance reference
747 * @index: IRQ vector index
749 * Request threaded ISR with primary ISR and secondary
751 * Return: 0 on success and non zero on failures.
753 static inline int mpi3mr_request_irq(struct mpi3mr_ioc
*mrioc
, u16 index
)
755 struct pci_dev
*pdev
= mrioc
->pdev
;
756 struct mpi3mr_intr_info
*intr_info
= mrioc
->intr_info
+ index
;
759 intr_info
->mrioc
= mrioc
;
760 intr_info
->msix_index
= index
;
761 intr_info
->op_reply_q
= NULL
;
763 snprintf(intr_info
->name
, MPI3MR_NAME_LENGTH
, "%s%d-msix%d",
764 mrioc
->driver_name
, mrioc
->id
, index
);
766 #ifndef CONFIG_PREEMPT_RT
767 retval
= request_threaded_irq(pci_irq_vector(pdev
, index
), mpi3mr_isr
,
768 mpi3mr_isr_poll
, IRQF_SHARED
, intr_info
->name
, intr_info
);
770 retval
= request_threaded_irq(pci_irq_vector(pdev
, index
), mpi3mr_isr_primary
,
771 NULL
, IRQF_SHARED
, intr_info
->name
, intr_info
);
774 ioc_err(mrioc
, "%s: Unable to allocate interrupt %d!\n",
775 intr_info
->name
, pci_irq_vector(pdev
, index
));
779 intr_info
->os_irq
= pci_irq_vector(pdev
, index
);
783 static void mpi3mr_calc_poll_queues(struct mpi3mr_ioc
*mrioc
, u16 max_vectors
)
785 if (!mrioc
->requested_poll_qcount
)
788 /* Reserved for Admin and Default Queue */
789 if (max_vectors
> 2 &&
790 (mrioc
->requested_poll_qcount
< max_vectors
- 2)) {
792 "enabled polled queues (%d) msix (%d)\n",
793 mrioc
->requested_poll_qcount
, max_vectors
);
796 "disabled polled queues (%d) msix (%d) because of no resources for default queue\n",
797 mrioc
->requested_poll_qcount
, max_vectors
);
798 mrioc
->requested_poll_qcount
= 0;
803 * mpi3mr_setup_isr - Setup ISR for the controller
804 * @mrioc: Adapter instance reference
805 * @setup_one: Request one IRQ or more
807 * Allocate IRQ vectors and call mpi3mr_request_irq to setup ISR
809 * Return: 0 on success and non zero on failures.
811 static int mpi3mr_setup_isr(struct mpi3mr_ioc
*mrioc
, u8 setup_one
)
813 unsigned int irq_flags
= PCI_IRQ_MSIX
;
814 int max_vectors
, min_vec
;
817 struct irq_affinity desc
= { .pre_vectors
= 1, .post_vectors
= 1 };
819 if (mrioc
->is_intr_info_set
)
822 mpi3mr_cleanup_isr(mrioc
);
824 if (setup_one
|| reset_devices
) {
826 retval
= pci_alloc_irq_vectors(mrioc
->pdev
,
827 1, max_vectors
, irq_flags
);
829 ioc_err(mrioc
, "cannot allocate irq vectors, ret %d\n",
835 min_t(int, mrioc
->cpu_count
+ 1 +
836 mrioc
->requested_poll_qcount
, mrioc
->msix_count
);
838 mpi3mr_calc_poll_queues(mrioc
, max_vectors
);
841 "MSI-X vectors supported: %d, no of cores: %d,",
842 mrioc
->msix_count
, mrioc
->cpu_count
);
844 "MSI-x vectors requested: %d poll_queues %d\n",
845 max_vectors
, mrioc
->requested_poll_qcount
);
847 desc
.post_vectors
= mrioc
->requested_poll_qcount
;
848 min_vec
= desc
.pre_vectors
+ desc
.post_vectors
;
849 irq_flags
|= PCI_IRQ_AFFINITY
| PCI_IRQ_ALL_TYPES
;
851 retval
= pci_alloc_irq_vectors_affinity(mrioc
->pdev
,
852 min_vec
, max_vectors
, irq_flags
, &desc
);
855 ioc_err(mrioc
, "cannot allocate irq vectors, ret %d\n",
862 * If only one MSI-x is allocated, then MSI-x 0 will be shared
863 * between Admin queue and operational queue
865 if (retval
== min_vec
)
866 mrioc
->op_reply_q_offset
= 0;
867 else if (retval
!= (max_vectors
)) {
869 "allocated vectors (%d) are less than configured (%d)\n",
870 retval
, max_vectors
);
873 max_vectors
= retval
;
874 mrioc
->op_reply_q_offset
= (max_vectors
> 1) ? 1 : 0;
876 mpi3mr_calc_poll_queues(mrioc
, max_vectors
);
880 mrioc
->intr_info
= kzalloc(sizeof(struct mpi3mr_intr_info
) * max_vectors
,
882 if (!mrioc
->intr_info
) {
884 pci_free_irq_vectors(mrioc
->pdev
);
887 for (i
= 0; i
< max_vectors
; i
++) {
888 retval
= mpi3mr_request_irq(mrioc
, i
);
890 mrioc
->intr_info_count
= i
;
894 if (reset_devices
|| !setup_one
)
895 mrioc
->is_intr_info_set
= true;
896 mrioc
->intr_info_count
= max_vectors
;
897 mpi3mr_ioc_enable_intr(mrioc
);
901 mpi3mr_cleanup_isr(mrioc
);
906 static const struct {
907 enum mpi3mr_iocstate value
;
910 { MRIOC_STATE_READY
, "ready" },
911 { MRIOC_STATE_FAULT
, "fault" },
912 { MRIOC_STATE_RESET
, "reset" },
913 { MRIOC_STATE_BECOMING_READY
, "becoming ready" },
914 { MRIOC_STATE_RESET_REQUESTED
, "reset requested" },
915 { MRIOC_STATE_UNRECOVERABLE
, "unrecoverable error" },
918 static const char *mpi3mr_iocstate_name(enum mpi3mr_iocstate mrioc_state
)
923 for (i
= 0; i
< ARRAY_SIZE(mrioc_states
); i
++) {
924 if (mrioc_states
[i
].value
== mrioc_state
) {
925 name
= mrioc_states
[i
].name
;
932 /* Reset reason to name mapper structure*/
933 static const struct {
934 enum mpi3mr_reset_reason value
;
936 } mpi3mr_reset_reason_codes
[] = {
937 { MPI3MR_RESET_FROM_BRINGUP
, "timeout in bringup" },
938 { MPI3MR_RESET_FROM_FAULT_WATCH
, "fault" },
939 { MPI3MR_RESET_FROM_APP
, "application invocation" },
940 { MPI3MR_RESET_FROM_EH_HOS
, "error handling" },
941 { MPI3MR_RESET_FROM_TM_TIMEOUT
, "TM timeout" },
942 { MPI3MR_RESET_FROM_APP_TIMEOUT
, "application command timeout" },
943 { MPI3MR_RESET_FROM_MUR_FAILURE
, "MUR failure" },
944 { MPI3MR_RESET_FROM_CTLR_CLEANUP
, "timeout in controller cleanup" },
945 { MPI3MR_RESET_FROM_CIACTIV_FAULT
, "component image activation fault" },
946 { MPI3MR_RESET_FROM_PE_TIMEOUT
, "port enable timeout" },
947 { MPI3MR_RESET_FROM_TSU_TIMEOUT
, "time stamp update timeout" },
948 { MPI3MR_RESET_FROM_DELREQQ_TIMEOUT
, "delete request queue timeout" },
949 { MPI3MR_RESET_FROM_DELREPQ_TIMEOUT
, "delete reply queue timeout" },
951 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT
,
952 "create request queue timeout"
955 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT
,
956 "create reply queue timeout"
958 { MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT
, "IOC facts timeout" },
959 { MPI3MR_RESET_FROM_IOCINIT_TIMEOUT
, "IOC init timeout" },
960 { MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT
, "event notify timeout" },
961 { MPI3MR_RESET_FROM_EVTACK_TIMEOUT
, "event acknowledgment timeout" },
963 MPI3MR_RESET_FROM_CIACTVRST_TIMER
,
964 "component image activation timeout"
967 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT
,
968 "get package version timeout"
970 { MPI3MR_RESET_FROM_SYSFS
, "sysfs invocation" },
971 { MPI3MR_RESET_FROM_SYSFS_TIMEOUT
, "sysfs TM timeout" },
973 MPI3MR_RESET_FROM_DIAG_BUFFER_POST_TIMEOUT
,
974 "diagnostic buffer post timeout"
977 MPI3MR_RESET_FROM_DIAG_BUFFER_RELEASE_TIMEOUT
,
978 "diagnostic buffer release timeout"
980 { MPI3MR_RESET_FROM_FIRMWARE
, "firmware asynchronous reset" },
981 { MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT
, "configuration request timeout"},
982 { MPI3MR_RESET_FROM_SAS_TRANSPORT_TIMEOUT
, "timeout of a SAS transport layer request" },
986 * mpi3mr_reset_rc_name - get reset reason code name
987 * @reason_code: reset reason code value
989 * Map reset reason to an NULL terminated ASCII string
991 * Return: name corresponding to reset reason value or NULL.
993 static const char *mpi3mr_reset_rc_name(enum mpi3mr_reset_reason reason_code
)
998 for (i
= 0; i
< ARRAY_SIZE(mpi3mr_reset_reason_codes
); i
++) {
999 if (mpi3mr_reset_reason_codes
[i
].value
== reason_code
) {
1000 name
= mpi3mr_reset_reason_codes
[i
].name
;
1007 /* Reset type to name mapper structure*/
1008 static const struct {
1011 } mpi3mr_reset_types
[] = {
1012 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET
, "soft" },
1013 { MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
, "diag fault" },
1017 * mpi3mr_reset_type_name - get reset type name
1018 * @reset_type: reset type value
1020 * Map reset type to an NULL terminated ASCII string
1022 * Return: name corresponding to reset type value or NULL.
1024 static const char *mpi3mr_reset_type_name(u16 reset_type
)
1029 for (i
= 0; i
< ARRAY_SIZE(mpi3mr_reset_types
); i
++) {
1030 if (mpi3mr_reset_types
[i
].reset_type
== reset_type
) {
1031 name
= mpi3mr_reset_types
[i
].name
;
1039 * mpi3mr_is_fault_recoverable - Read fault code and decide
1040 * whether the controller can be recoverable
1041 * @mrioc: Adapter instance reference
1042 * Return: true if fault is recoverable, false otherwise.
1044 static inline bool mpi3mr_is_fault_recoverable(struct mpi3mr_ioc
*mrioc
)
1048 fault
= (readl(&mrioc
->sysif_regs
->fault
) &
1049 MPI3_SYSIF_FAULT_CODE_MASK
);
1052 case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED
:
1053 case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED
:
1055 "controller requires system power cycle, marking controller as unrecoverable\n");
1057 case MPI3_SYSIF_FAULT_CODE_INSUFFICIENT_PCI_SLOT_POWER
:
1059 "controller faulted due to insufficient power,\n"
1060 " try by connecting it to a different slot\n");
1069 * mpi3mr_print_fault_info - Display fault information
1070 * @mrioc: Adapter instance reference
1072 * Display the controller fault information if there is a
1077 void mpi3mr_print_fault_info(struct mpi3mr_ioc
*mrioc
)
1079 u32 ioc_status
, code
, code1
, code2
, code3
;
1081 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1083 if (ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
) {
1084 code
= readl(&mrioc
->sysif_regs
->fault
);
1085 code1
= readl(&mrioc
->sysif_regs
->fault_info
[0]);
1086 code2
= readl(&mrioc
->sysif_regs
->fault_info
[1]);
1087 code3
= readl(&mrioc
->sysif_regs
->fault_info
[2]);
1090 "fault code(0x%08X): Additional code: (0x%08X:0x%08X:0x%08X)\n",
1091 code
, code1
, code2
, code3
);
1096 * mpi3mr_get_iocstate - Get IOC State
1097 * @mrioc: Adapter instance reference
1099 * Return a proper IOC state enum based on the IOC status and
1100 * IOC configuration and unrcoverable state of the controller.
1102 * Return: Current IOC state.
1104 enum mpi3mr_iocstate
mpi3mr_get_iocstate(struct mpi3mr_ioc
*mrioc
)
1106 u32 ioc_status
, ioc_config
;
1109 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1110 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
1112 if (mrioc
->unrecoverable
)
1113 return MRIOC_STATE_UNRECOVERABLE
;
1114 if (ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
)
1115 return MRIOC_STATE_FAULT
;
1117 ready
= (ioc_status
& MPI3_SYSIF_IOC_STATUS_READY
);
1118 enabled
= (ioc_config
& MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC
);
1120 if (ready
&& enabled
)
1121 return MRIOC_STATE_READY
;
1122 if ((!ready
) && (!enabled
))
1123 return MRIOC_STATE_RESET
;
1124 if ((!ready
) && (enabled
))
1125 return MRIOC_STATE_BECOMING_READY
;
1127 return MRIOC_STATE_RESET_REQUESTED
;
1131 * mpi3mr_free_ioctl_dma_memory - free memory for ioctl dma
1132 * @mrioc: Adapter instance reference
1134 * Free the DMA memory allocated for IOCTL handling purpose.
1138 static void mpi3mr_free_ioctl_dma_memory(struct mpi3mr_ioc
*mrioc
)
1140 struct dma_memory_desc
*mem_desc
;
1143 if (!mrioc
->ioctl_dma_pool
)
1146 for (i
= 0; i
< MPI3MR_NUM_IOCTL_SGE
; i
++) {
1147 mem_desc
= &mrioc
->ioctl_sge
[i
];
1148 if (mem_desc
->addr
) {
1149 dma_pool_free(mrioc
->ioctl_dma_pool
,
1151 mem_desc
->dma_addr
);
1152 mem_desc
->addr
= NULL
;
1155 dma_pool_destroy(mrioc
->ioctl_dma_pool
);
1156 mrioc
->ioctl_dma_pool
= NULL
;
1157 mem_desc
= &mrioc
->ioctl_chain_sge
;
1159 if (mem_desc
->addr
) {
1160 dma_free_coherent(&mrioc
->pdev
->dev
, mem_desc
->size
,
1161 mem_desc
->addr
, mem_desc
->dma_addr
);
1162 mem_desc
->addr
= NULL
;
1164 mem_desc
= &mrioc
->ioctl_resp_sge
;
1165 if (mem_desc
->addr
) {
1166 dma_free_coherent(&mrioc
->pdev
->dev
, mem_desc
->size
,
1167 mem_desc
->addr
, mem_desc
->dma_addr
);
1168 mem_desc
->addr
= NULL
;
1171 mrioc
->ioctl_sges_allocated
= false;
1175 * mpi3mr_alloc_ioctl_dma_memory - Alloc memory for ioctl dma
1176 * @mrioc: Adapter instance reference
1178 * This function allocates dmaable memory required to handle the
1179 * application issued MPI3 IOCTL requests.
1183 static void mpi3mr_alloc_ioctl_dma_memory(struct mpi3mr_ioc
*mrioc
)
1186 struct dma_memory_desc
*mem_desc
;
1189 mrioc
->ioctl_dma_pool
= dma_pool_create("ioctl dma pool",
1191 MPI3MR_IOCTL_SGE_SIZE
,
1192 MPI3MR_PAGE_SIZE_4K
, 0);
1194 if (!mrioc
->ioctl_dma_pool
) {
1195 ioc_err(mrioc
, "ioctl_dma_pool: dma_pool_create failed\n");
1199 for (i
= 0; i
< MPI3MR_NUM_IOCTL_SGE
; i
++) {
1200 mem_desc
= &mrioc
->ioctl_sge
[i
];
1201 mem_desc
->size
= MPI3MR_IOCTL_SGE_SIZE
;
1202 mem_desc
->addr
= dma_pool_zalloc(mrioc
->ioctl_dma_pool
,
1204 &mem_desc
->dma_addr
);
1205 if (!mem_desc
->addr
)
1209 mem_desc
= &mrioc
->ioctl_chain_sge
;
1210 mem_desc
->size
= MPI3MR_PAGE_SIZE_4K
;
1211 mem_desc
->addr
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
1213 &mem_desc
->dma_addr
,
1215 if (!mem_desc
->addr
)
1218 mem_desc
= &mrioc
->ioctl_resp_sge
;
1219 mem_desc
->size
= MPI3MR_PAGE_SIZE_4K
;
1220 mem_desc
->addr
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
1222 &mem_desc
->dma_addr
,
1224 if (!mem_desc
->addr
)
1227 mrioc
->ioctl_sges_allocated
= true;
1231 ioc_warn(mrioc
, "cannot allocate DMA memory for the mpt commands\n"
1232 "from the applications, application interface for MPT command is disabled\n");
1233 mpi3mr_free_ioctl_dma_memory(mrioc
);
1237 * mpi3mr_clear_reset_history - clear reset history
1238 * @mrioc: Adapter instance reference
1240 * Write the reset history bit in IOC status to clear the bit,
1241 * if it is already set.
1245 static inline void mpi3mr_clear_reset_history(struct mpi3mr_ioc
*mrioc
)
1249 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1250 if (ioc_status
& MPI3_SYSIF_IOC_STATUS_RESET_HISTORY
)
1251 writel(ioc_status
, &mrioc
->sysif_regs
->ioc_status
);
1255 * mpi3mr_issue_and_process_mur - Message unit Reset handler
1256 * @mrioc: Adapter instance reference
1257 * @reset_reason: Reset reason code
1259 * Issue Message unit Reset to the controller and wait for it to
1262 * Return: 0 on success, -1 on failure.
1264 static int mpi3mr_issue_and_process_mur(struct mpi3mr_ioc
*mrioc
,
1267 u32 ioc_config
, timeout
, ioc_status
, scratch_pad0
;
1270 ioc_info(mrioc
, "Issuing Message unit Reset(MUR)\n");
1271 if (mrioc
->unrecoverable
) {
1272 ioc_info(mrioc
, "IOC is unrecoverable MUR not issued\n");
1275 mpi3mr_clear_reset_history(mrioc
);
1276 scratch_pad0
= ((MPI3MR_RESET_REASON_OSTYPE_LINUX
<<
1277 MPI3MR_RESET_REASON_OSTYPE_SHIFT
) |
1278 (mrioc
->facts
.ioc_num
<<
1279 MPI3MR_RESET_REASON_IOCNUM_SHIFT
) | reset_reason
);
1280 writel(scratch_pad0
, &mrioc
->sysif_regs
->scratchpad
[0]);
1281 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
1282 ioc_config
&= ~MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC
;
1283 writel(ioc_config
, &mrioc
->sysif_regs
->ioc_configuration
);
1285 timeout
= MPI3MR_MUR_TIMEOUT
* 10;
1287 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1288 if ((ioc_status
& MPI3_SYSIF_IOC_STATUS_RESET_HISTORY
)) {
1289 mpi3mr_clear_reset_history(mrioc
);
1292 if (ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
) {
1293 mpi3mr_print_fault_info(mrioc
);
1297 } while (--timeout
);
1299 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
1300 if (timeout
&& !((ioc_status
& MPI3_SYSIF_IOC_STATUS_READY
) ||
1301 (ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
) ||
1302 (ioc_config
& MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC
)))
1305 ioc_info(mrioc
, "Base IOC Sts/Config after %s MUR is (0x%x)/(0x%x)\n",
1306 (!retval
) ? "successful" : "failed", ioc_status
, ioc_config
);
1311 * mpi3mr_revalidate_factsdata - validate IOCFacts parameters
1312 * during reset/resume
1313 * @mrioc: Adapter instance reference
1315 * Return: zero if the new IOCFacts parameters value is compatible with
1316 * older values else return -EPERM
1319 mpi3mr_revalidate_factsdata(struct mpi3mr_ioc
*mrioc
)
1321 unsigned long *removepend_bitmap
;
1323 if (mrioc
->facts
.reply_sz
> mrioc
->reply_sz
) {
1325 "cannot increase reply size from %d to %d\n",
1326 mrioc
->reply_sz
, mrioc
->facts
.reply_sz
);
1330 if (mrioc
->facts
.max_op_reply_q
< mrioc
->num_op_reply_q
) {
1332 "cannot reduce number of operational reply queues from %d to %d\n",
1333 mrioc
->num_op_reply_q
,
1334 mrioc
->facts
.max_op_reply_q
);
1338 if (mrioc
->facts
.max_op_req_q
< mrioc
->num_op_req_q
) {
1340 "cannot reduce number of operational request queues from %d to %d\n",
1341 mrioc
->num_op_req_q
, mrioc
->facts
.max_op_req_q
);
1345 if (mrioc
->shost
->max_sectors
!= (mrioc
->facts
.max_data_length
/ 512))
1346 ioc_err(mrioc
, "Warning: The maximum data transfer length\n"
1347 "\tchanged after reset: previous(%d), new(%d),\n"
1348 "the driver cannot change this at run time\n",
1349 mrioc
->shost
->max_sectors
* 512, mrioc
->facts
.max_data_length
);
1351 if ((mrioc
->sas_transport_enabled
) && (mrioc
->facts
.ioc_capabilities
&
1352 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_SUPPORTED
))
1354 "critical error: multipath capability is enabled at the\n"
1355 "\tcontroller while sas transport support is enabled at the\n"
1356 "\tdriver, please reboot the system or reload the driver\n");
1358 if (mrioc
->facts
.max_devhandle
> mrioc
->dev_handle_bitmap_bits
) {
1359 removepend_bitmap
= bitmap_zalloc(mrioc
->facts
.max_devhandle
,
1361 if (!removepend_bitmap
) {
1363 "failed to increase removepend_bitmap bits from %d to %d\n",
1364 mrioc
->dev_handle_bitmap_bits
,
1365 mrioc
->facts
.max_devhandle
);
1368 bitmap_free(mrioc
->removepend_bitmap
);
1369 mrioc
->removepend_bitmap
= removepend_bitmap
;
1371 "increased bits of dev_handle_bitmap from %d to %d\n",
1372 mrioc
->dev_handle_bitmap_bits
,
1373 mrioc
->facts
.max_devhandle
);
1374 mrioc
->dev_handle_bitmap_bits
= mrioc
->facts
.max_devhandle
;
1381 * mpi3mr_bring_ioc_ready - Bring controller to ready state
1382 * @mrioc: Adapter instance reference
1384 * Set Enable IOC bit in IOC configuration register and wait for
1385 * the controller to become ready.
1387 * Return: 0 on success, appropriate error on failure.
1389 static int mpi3mr_bring_ioc_ready(struct mpi3mr_ioc
*mrioc
)
1391 u32 ioc_config
, ioc_status
, timeout
, host_diagnostic
;
1393 enum mpi3mr_iocstate ioc_state
;
1396 u64 start_time
, elapsed_time_sec
;
1398 retry_bring_ioc_ready
:
1400 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1401 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
1402 base_info
= lo_hi_readq(&mrioc
->sysif_regs
->ioc_information
);
1403 ioc_info(mrioc
, "ioc_status(0x%08x), ioc_config(0x%08x), ioc_info(0x%016llx) at the bringup\n",
1404 ioc_status
, ioc_config
, base_info
);
1406 if (!mpi3mr_is_fault_recoverable(mrioc
)) {
1407 mrioc
->unrecoverable
= 1;
1408 goto out_device_not_present
;
1411 /*The timeout value is in 2sec unit, changing it to seconds*/
1412 mrioc
->ready_timeout
=
1413 ((base_info
& MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_MASK
) >>
1414 MPI3_SYSIF_IOC_INFO_LOW_TIMEOUT_SHIFT
) * 2;
1416 ioc_info(mrioc
, "ready timeout: %d seconds\n", mrioc
->ready_timeout
);
1418 ioc_state
= mpi3mr_get_iocstate(mrioc
);
1419 ioc_info(mrioc
, "controller is in %s state during detection\n",
1420 mpi3mr_iocstate_name(ioc_state
));
1422 timeout
= mrioc
->ready_timeout
* 10;
1425 ioc_state
= mpi3mr_get_iocstate(mrioc
);
1427 if (ioc_state
!= MRIOC_STATE_BECOMING_READY
&&
1428 ioc_state
!= MRIOC_STATE_RESET_REQUESTED
)
1431 if (!pci_device_is_present(mrioc
->pdev
)) {
1432 mrioc
->unrecoverable
= 1;
1433 ioc_err(mrioc
, "controller is not present while waiting to reset\n");
1434 goto out_device_not_present
;
1438 } while (--timeout
);
1440 if (ioc_state
== MRIOC_STATE_READY
) {
1441 ioc_info(mrioc
, "issuing message unit reset (MUR) to bring to reset state\n");
1442 retval
= mpi3mr_issue_and_process_mur(mrioc
,
1443 MPI3MR_RESET_FROM_BRINGUP
);
1444 ioc_state
= mpi3mr_get_iocstate(mrioc
);
1447 "message unit reset failed with error %d current state %s\n",
1448 retval
, mpi3mr_iocstate_name(ioc_state
));
1450 if (ioc_state
!= MRIOC_STATE_RESET
) {
1451 if (ioc_state
== MRIOC_STATE_FAULT
) {
1452 timeout
= MPI3_SYSIF_DIAG_SAVE_TIMEOUT
* 10;
1453 mpi3mr_print_fault_info(mrioc
);
1456 readl(&mrioc
->sysif_regs
->host_diagnostic
);
1457 if (!(host_diagnostic
&
1458 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS
))
1460 if (!pci_device_is_present(mrioc
->pdev
)) {
1461 mrioc
->unrecoverable
= 1;
1462 ioc_err(mrioc
, "controller is not present at the bringup\n");
1463 goto out_device_not_present
;
1466 } while (--timeout
);
1468 mpi3mr_print_fault_info(mrioc
);
1469 ioc_info(mrioc
, "issuing soft reset to bring to reset state\n");
1470 retval
= mpi3mr_issue_reset(mrioc
,
1471 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET
,
1472 MPI3MR_RESET_FROM_BRINGUP
);
1475 "soft reset failed with error %d\n", retval
);
1479 ioc_state
= mpi3mr_get_iocstate(mrioc
);
1480 if (ioc_state
!= MRIOC_STATE_RESET
) {
1482 "cannot bring controller to reset state, current state: %s\n",
1483 mpi3mr_iocstate_name(ioc_state
));
1486 mpi3mr_clear_reset_history(mrioc
);
1487 retval
= mpi3mr_setup_admin_qpair(mrioc
);
1489 ioc_err(mrioc
, "failed to setup admin queues: error %d\n",
1494 ioc_info(mrioc
, "bringing controller to ready state\n");
1495 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
1496 ioc_config
|= MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC
;
1497 writel(ioc_config
, &mrioc
->sysif_regs
->ioc_configuration
);
1500 start_time
= jiffies
;
1502 timeout
= mrioc
->ready_timeout
* 10;
1504 ioc_state
= mpi3mr_get_iocstate(mrioc
);
1505 if (ioc_state
== MRIOC_STATE_READY
) {
1507 "successfully transitioned to %s state\n",
1508 mpi3mr_iocstate_name(ioc_state
));
1511 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1512 if ((ioc_status
& MPI3_SYSIF_IOC_STATUS_RESET_HISTORY
) ||
1513 (ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
)) {
1514 mpi3mr_print_fault_info(mrioc
);
1517 if (!pci_device_is_present(mrioc
->pdev
)) {
1518 mrioc
->unrecoverable
= 1;
1520 "controller is not present at the bringup\n");
1522 goto out_device_not_present
;
1525 elapsed_time_sec
= jiffies_to_msecs(jiffies
- start_time
)/1000;
1526 } while (elapsed_time_sec
< mrioc
->ready_timeout
);
1529 elapsed_time_sec
= jiffies_to_msecs(jiffies
- start_time
)/1000;
1530 if ((retry
< 2) && (elapsed_time_sec
< (mrioc
->ready_timeout
- 60))) {
1533 ioc_warn(mrioc
, "retrying to bring IOC ready, retry_count:%d\n"
1534 " elapsed time =%llu\n", retry
, elapsed_time_sec
);
1536 goto retry_bring_ioc_ready
;
1538 ioc_state
= mpi3mr_get_iocstate(mrioc
);
1540 "failed to bring to ready state, current state: %s\n",
1541 mpi3mr_iocstate_name(ioc_state
));
1542 out_device_not_present
:
1547 * mpi3mr_soft_reset_success - Check softreset is success or not
1548 * @ioc_status: IOC status register value
1549 * @ioc_config: IOC config register value
1551 * Check whether the soft reset is successful or not based on
1552 * IOC status and IOC config register values.
1554 * Return: True when the soft reset is success, false otherwise.
1557 mpi3mr_soft_reset_success(u32 ioc_status
, u32 ioc_config
)
1559 if (!((ioc_status
& MPI3_SYSIF_IOC_STATUS_READY
) ||
1560 (ioc_config
& MPI3_SYSIF_IOC_CONFIG_ENABLE_IOC
)))
1566 * mpi3mr_diagfault_success - Check diag fault is success or not
1567 * @mrioc: Adapter reference
1568 * @ioc_status: IOC status register value
1570 * Check whether the controller hit diag reset fault code.
1572 * Return: True when there is diag fault, false otherwise.
1574 static inline bool mpi3mr_diagfault_success(struct mpi3mr_ioc
*mrioc
,
1579 if (!(ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
))
1581 fault
= readl(&mrioc
->sysif_regs
->fault
) & MPI3_SYSIF_FAULT_CODE_MASK
;
1582 if (fault
== MPI3_SYSIF_FAULT_CODE_DIAG_FAULT_RESET
) {
1583 mpi3mr_print_fault_info(mrioc
);
1590 * mpi3mr_set_diagsave - Set diag save bit for snapdump
1591 * @mrioc: Adapter reference
1593 * Set diag save bit in IOC configuration register to enable
1598 static inline void mpi3mr_set_diagsave(struct mpi3mr_ioc
*mrioc
)
1602 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
1603 ioc_config
|= MPI3_SYSIF_IOC_CONFIG_DIAG_SAVE
;
1604 writel(ioc_config
, &mrioc
->sysif_regs
->ioc_configuration
);
1608 * mpi3mr_issue_reset - Issue reset to the controller
1609 * @mrioc: Adapter reference
1610 * @reset_type: Reset type
1611 * @reset_reason: Reset reason code
1613 * Unlock the host diagnostic registers and write the specific
1614 * reset type to that, wait for reset acknowledgment from the
1615 * controller, if the reset is not successful retry for the
1616 * predefined number of times.
1618 * Return: 0 on success, non-zero on failure.
1620 static int mpi3mr_issue_reset(struct mpi3mr_ioc
*mrioc
, u16 reset_type
,
1624 u8 unlock_retry_count
= 0;
1625 u32 host_diagnostic
, ioc_status
, ioc_config
, scratch_pad0
;
1626 u32 timeout
= MPI3MR_RESET_ACK_TIMEOUT
* 10;
1628 if ((reset_type
!= MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET
) &&
1629 (reset_type
!= MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
))
1631 if (mrioc
->unrecoverable
)
1633 if (reset_reason
== MPI3MR_RESET_FROM_FIRMWARE
) {
1638 ioc_info(mrioc
, "%s reset due to %s(0x%x)\n",
1639 mpi3mr_reset_type_name(reset_type
),
1640 mpi3mr_reset_rc_name(reset_reason
), reset_reason
);
1642 mpi3mr_clear_reset_history(mrioc
);
1645 "Write magic sequence to unlock host diag register (retry=%d)\n",
1646 ++unlock_retry_count
);
1647 if (unlock_retry_count
>= MPI3MR_HOSTDIAG_UNLOCK_RETRY_COUNT
) {
1649 "%s reset failed due to unlock failure, host_diagnostic(0x%08x)\n",
1650 mpi3mr_reset_type_name(reset_type
),
1652 mrioc
->unrecoverable
= 1;
1656 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_FLUSH
,
1657 &mrioc
->sysif_regs
->write_sequence
);
1658 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_1ST
,
1659 &mrioc
->sysif_regs
->write_sequence
);
1660 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND
,
1661 &mrioc
->sysif_regs
->write_sequence
);
1662 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_3RD
,
1663 &mrioc
->sysif_regs
->write_sequence
);
1664 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_4TH
,
1665 &mrioc
->sysif_regs
->write_sequence
);
1666 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_5TH
,
1667 &mrioc
->sysif_regs
->write_sequence
);
1668 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_6TH
,
1669 &mrioc
->sysif_regs
->write_sequence
);
1670 usleep_range(1000, 1100);
1671 host_diagnostic
= readl(&mrioc
->sysif_regs
->host_diagnostic
);
1673 "wrote magic sequence: retry_count(%d), host_diagnostic(0x%08x)\n",
1674 unlock_retry_count
, host_diagnostic
);
1675 } while (!(host_diagnostic
& MPI3_SYSIF_HOST_DIAG_DIAG_WRITE_ENABLE
));
1677 scratch_pad0
= ((MPI3MR_RESET_REASON_OSTYPE_LINUX
<<
1678 MPI3MR_RESET_REASON_OSTYPE_SHIFT
) | (mrioc
->facts
.ioc_num
<<
1679 MPI3MR_RESET_REASON_IOCNUM_SHIFT
) | reset_reason
);
1680 writel(reset_reason
, &mrioc
->sysif_regs
->scratchpad
[0]);
1681 writel(host_diagnostic
| reset_type
,
1682 &mrioc
->sysif_regs
->host_diagnostic
);
1683 switch (reset_type
) {
1684 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET
:
1686 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1688 readl(&mrioc
->sysif_regs
->ioc_configuration
);
1689 if ((ioc_status
& MPI3_SYSIF_IOC_STATUS_RESET_HISTORY
)
1690 && mpi3mr_soft_reset_success(ioc_status
, ioc_config
)
1692 mpi3mr_clear_reset_history(mrioc
);
1697 } while (--timeout
);
1698 mpi3mr_print_fault_info(mrioc
);
1700 case MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
:
1702 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1703 if (mpi3mr_diagfault_success(mrioc
, ioc_status
)) {
1708 } while (--timeout
);
1714 writel(MPI3_SYSIF_WRITE_SEQUENCE_KEY_VALUE_2ND
,
1715 &mrioc
->sysif_regs
->write_sequence
);
1717 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
1718 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
1720 "ioc_status/ioc_onfig after %s reset is (0x%x)/(0x%x)\n",
1721 (!retval
)?"successful":"failed", ioc_status
,
1724 mrioc
->unrecoverable
= 1;
1729 * mpi3mr_admin_request_post - Post request to admin queue
1730 * @mrioc: Adapter reference
1731 * @admin_req: MPI3 request
1732 * @admin_req_sz: Request size
1733 * @ignore_reset: Ignore reset in process
1735 * Post the MPI3 request into admin request queue and
1736 * inform the controller, if the queue is full return
1737 * appropriate error.
1739 * Return: 0 on success, non-zero on failure.
1741 int mpi3mr_admin_request_post(struct mpi3mr_ioc
*mrioc
, void *admin_req
,
1742 u16 admin_req_sz
, u8 ignore_reset
)
1744 u16 areq_pi
= 0, areq_ci
= 0, max_entries
= 0;
1746 unsigned long flags
;
1749 if (mrioc
->unrecoverable
) {
1750 ioc_err(mrioc
, "%s : Unrecoverable controller\n", __func__
);
1754 spin_lock_irqsave(&mrioc
->admin_req_lock
, flags
);
1755 areq_pi
= mrioc
->admin_req_pi
;
1756 areq_ci
= mrioc
->admin_req_ci
;
1757 max_entries
= mrioc
->num_admin_req
;
1758 if ((areq_ci
== (areq_pi
+ 1)) || ((!areq_ci
) &&
1759 (areq_pi
== (max_entries
- 1)))) {
1760 ioc_err(mrioc
, "AdminReqQ full condition detected\n");
1764 if (!ignore_reset
&& mrioc
->reset_in_progress
) {
1765 ioc_err(mrioc
, "AdminReqQ submit reset in progress\n");
1769 if (mrioc
->pci_err_recovery
) {
1770 ioc_err(mrioc
, "admin request queue submission failed due to pci error recovery in progress\n");
1775 areq_entry
= (u8
*)mrioc
->admin_req_base
+
1776 (areq_pi
* MPI3MR_ADMIN_REQ_FRAME_SZ
);
1777 memset(areq_entry
, 0, MPI3MR_ADMIN_REQ_FRAME_SZ
);
1778 memcpy(areq_entry
, (u8
*)admin_req
, admin_req_sz
);
1780 if (++areq_pi
== max_entries
)
1782 mrioc
->admin_req_pi
= areq_pi
;
1784 writel(mrioc
->admin_req_pi
, &mrioc
->sysif_regs
->admin_request_queue_pi
);
1787 spin_unlock_irqrestore(&mrioc
->admin_req_lock
, flags
);
1793 * mpi3mr_free_op_req_q_segments - free request memory segments
1794 * @mrioc: Adapter instance reference
1795 * @q_idx: operational request queue index
1797 * Free memory segments allocated for operational request queue
1801 static void mpi3mr_free_op_req_q_segments(struct mpi3mr_ioc
*mrioc
, u16 q_idx
)
1805 struct segments
*segments
;
1807 segments
= mrioc
->req_qinfo
[q_idx
].q_segments
;
1811 if (mrioc
->enable_segqueue
) {
1812 size
= MPI3MR_OP_REQ_Q_SEG_SIZE
;
1813 if (mrioc
->req_qinfo
[q_idx
].q_segment_list
) {
1814 dma_free_coherent(&mrioc
->pdev
->dev
,
1815 MPI3MR_MAX_SEG_LIST_SIZE
,
1816 mrioc
->req_qinfo
[q_idx
].q_segment_list
,
1817 mrioc
->req_qinfo
[q_idx
].q_segment_list_dma
);
1818 mrioc
->req_qinfo
[q_idx
].q_segment_list
= NULL
;
1821 size
= mrioc
->req_qinfo
[q_idx
].segment_qd
*
1822 mrioc
->facts
.op_req_sz
;
1824 for (j
= 0; j
< mrioc
->req_qinfo
[q_idx
].num_segments
; j
++) {
1825 if (!segments
[j
].segment
)
1827 dma_free_coherent(&mrioc
->pdev
->dev
,
1828 size
, segments
[j
].segment
, segments
[j
].segment_dma
);
1829 segments
[j
].segment
= NULL
;
1831 kfree(mrioc
->req_qinfo
[q_idx
].q_segments
);
1832 mrioc
->req_qinfo
[q_idx
].q_segments
= NULL
;
1833 mrioc
->req_qinfo
[q_idx
].qid
= 0;
1837 * mpi3mr_free_op_reply_q_segments - free reply memory segments
1838 * @mrioc: Adapter instance reference
1839 * @q_idx: operational reply queue index
1841 * Free memory segments allocated for operational reply queue
1845 static void mpi3mr_free_op_reply_q_segments(struct mpi3mr_ioc
*mrioc
, u16 q_idx
)
1849 struct segments
*segments
;
1851 segments
= mrioc
->op_reply_qinfo
[q_idx
].q_segments
;
1855 if (mrioc
->enable_segqueue
) {
1856 size
= MPI3MR_OP_REP_Q_SEG_SIZE
;
1857 if (mrioc
->op_reply_qinfo
[q_idx
].q_segment_list
) {
1858 dma_free_coherent(&mrioc
->pdev
->dev
,
1859 MPI3MR_MAX_SEG_LIST_SIZE
,
1860 mrioc
->op_reply_qinfo
[q_idx
].q_segment_list
,
1861 mrioc
->op_reply_qinfo
[q_idx
].q_segment_list_dma
);
1862 mrioc
->op_reply_qinfo
[q_idx
].q_segment_list
= NULL
;
1865 size
= mrioc
->op_reply_qinfo
[q_idx
].segment_qd
*
1866 mrioc
->op_reply_desc_sz
;
1868 for (j
= 0; j
< mrioc
->op_reply_qinfo
[q_idx
].num_segments
; j
++) {
1869 if (!segments
[j
].segment
)
1871 dma_free_coherent(&mrioc
->pdev
->dev
,
1872 size
, segments
[j
].segment
, segments
[j
].segment_dma
);
1873 segments
[j
].segment
= NULL
;
1876 kfree(mrioc
->op_reply_qinfo
[q_idx
].q_segments
);
1877 mrioc
->op_reply_qinfo
[q_idx
].q_segments
= NULL
;
1878 mrioc
->op_reply_qinfo
[q_idx
].qid
= 0;
1882 * mpi3mr_delete_op_reply_q - delete operational reply queue
1883 * @mrioc: Adapter instance reference
1884 * @qidx: operational reply queue index
1886 * Delete operatinal reply queue by issuing MPI request
1887 * through admin queue.
1889 * Return: 0 on success, non-zero on failure.
1891 static int mpi3mr_delete_op_reply_q(struct mpi3mr_ioc
*mrioc
, u16 qidx
)
1893 struct mpi3_delete_reply_queue_request delq_req
;
1894 struct op_reply_qinfo
*op_reply_q
= mrioc
->op_reply_qinfo
+ qidx
;
1896 u16 reply_qid
= 0, midx
;
1898 reply_qid
= op_reply_q
->qid
;
1900 midx
= REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx
, mrioc
->op_reply_q_offset
);
1904 ioc_err(mrioc
, "Issue DelRepQ: called with invalid ReqQID\n");
1908 (op_reply_q
->qtype
== MPI3MR_DEFAULT_QUEUE
) ? mrioc
->default_qcount
-- :
1909 mrioc
->active_poll_qcount
--;
1911 memset(&delq_req
, 0, sizeof(delq_req
));
1912 mutex_lock(&mrioc
->init_cmds
.mutex
);
1913 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
1915 ioc_err(mrioc
, "Issue DelRepQ: Init command is in use\n");
1916 mutex_unlock(&mrioc
->init_cmds
.mutex
);
1919 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
1920 mrioc
->init_cmds
.is_waiting
= 1;
1921 mrioc
->init_cmds
.callback
= NULL
;
1922 delq_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
1923 delq_req
.function
= MPI3_FUNCTION_DELETE_REPLY_QUEUE
;
1924 delq_req
.queue_id
= cpu_to_le16(reply_qid
);
1926 init_completion(&mrioc
->init_cmds
.done
);
1927 retval
= mpi3mr_admin_request_post(mrioc
, &delq_req
, sizeof(delq_req
),
1930 ioc_err(mrioc
, "Issue DelRepQ: Admin Post failed\n");
1933 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
1934 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
1935 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
1936 ioc_err(mrioc
, "delete reply queue timed out\n");
1937 mpi3mr_check_rh_fault_ioc(mrioc
,
1938 MPI3MR_RESET_FROM_DELREPQ_TIMEOUT
);
1942 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
1943 != MPI3_IOCSTATUS_SUCCESS
) {
1945 "Issue DelRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
1946 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
1947 mrioc
->init_cmds
.ioc_loginfo
);
1951 mrioc
->intr_info
[midx
].op_reply_q
= NULL
;
1953 mpi3mr_free_op_reply_q_segments(mrioc
, qidx
);
1955 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
1956 mutex_unlock(&mrioc
->init_cmds
.mutex
);
1963 * mpi3mr_alloc_op_reply_q_segments -Alloc segmented reply pool
1964 * @mrioc: Adapter instance reference
1965 * @qidx: request queue index
1967 * Allocate segmented memory pools for operational reply
1970 * Return: 0 on success, non-zero on failure.
1972 static int mpi3mr_alloc_op_reply_q_segments(struct mpi3mr_ioc
*mrioc
, u16 qidx
)
1974 struct op_reply_qinfo
*op_reply_q
= mrioc
->op_reply_qinfo
+ qidx
;
1976 u64
*q_segment_list_entry
= NULL
;
1977 struct segments
*segments
;
1979 if (mrioc
->enable_segqueue
) {
1980 op_reply_q
->segment_qd
=
1981 MPI3MR_OP_REP_Q_SEG_SIZE
/ mrioc
->op_reply_desc_sz
;
1983 size
= MPI3MR_OP_REP_Q_SEG_SIZE
;
1985 op_reply_q
->q_segment_list
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
1986 MPI3MR_MAX_SEG_LIST_SIZE
, &op_reply_q
->q_segment_list_dma
,
1988 if (!op_reply_q
->q_segment_list
)
1990 q_segment_list_entry
= (u64
*)op_reply_q
->q_segment_list
;
1992 op_reply_q
->segment_qd
= op_reply_q
->num_replies
;
1993 size
= op_reply_q
->num_replies
* mrioc
->op_reply_desc_sz
;
1996 op_reply_q
->num_segments
= DIV_ROUND_UP(op_reply_q
->num_replies
,
1997 op_reply_q
->segment_qd
);
1999 op_reply_q
->q_segments
= kcalloc(op_reply_q
->num_segments
,
2000 sizeof(struct segments
), GFP_KERNEL
);
2001 if (!op_reply_q
->q_segments
)
2004 segments
= op_reply_q
->q_segments
;
2005 for (i
= 0; i
< op_reply_q
->num_segments
; i
++) {
2006 segments
[i
].segment
=
2007 dma_alloc_coherent(&mrioc
->pdev
->dev
,
2008 size
, &segments
[i
].segment_dma
, GFP_KERNEL
);
2009 if (!segments
[i
].segment
)
2011 if (mrioc
->enable_segqueue
)
2012 q_segment_list_entry
[i
] =
2013 (unsigned long)segments
[i
].segment_dma
;
2020 * mpi3mr_alloc_op_req_q_segments - Alloc segmented req pool.
2021 * @mrioc: Adapter instance reference
2022 * @qidx: request queue index
2024 * Allocate segmented memory pools for operational request
2027 * Return: 0 on success, non-zero on failure.
2029 static int mpi3mr_alloc_op_req_q_segments(struct mpi3mr_ioc
*mrioc
, u16 qidx
)
2031 struct op_req_qinfo
*op_req_q
= mrioc
->req_qinfo
+ qidx
;
2033 u64
*q_segment_list_entry
= NULL
;
2034 struct segments
*segments
;
2036 if (mrioc
->enable_segqueue
) {
2037 op_req_q
->segment_qd
=
2038 MPI3MR_OP_REQ_Q_SEG_SIZE
/ mrioc
->facts
.op_req_sz
;
2040 size
= MPI3MR_OP_REQ_Q_SEG_SIZE
;
2042 op_req_q
->q_segment_list
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
2043 MPI3MR_MAX_SEG_LIST_SIZE
, &op_req_q
->q_segment_list_dma
,
2045 if (!op_req_q
->q_segment_list
)
2047 q_segment_list_entry
= (u64
*)op_req_q
->q_segment_list
;
2050 op_req_q
->segment_qd
= op_req_q
->num_requests
;
2051 size
= op_req_q
->num_requests
* mrioc
->facts
.op_req_sz
;
2054 op_req_q
->num_segments
= DIV_ROUND_UP(op_req_q
->num_requests
,
2055 op_req_q
->segment_qd
);
2057 op_req_q
->q_segments
= kcalloc(op_req_q
->num_segments
,
2058 sizeof(struct segments
), GFP_KERNEL
);
2059 if (!op_req_q
->q_segments
)
2062 segments
= op_req_q
->q_segments
;
2063 for (i
= 0; i
< op_req_q
->num_segments
; i
++) {
2064 segments
[i
].segment
=
2065 dma_alloc_coherent(&mrioc
->pdev
->dev
,
2066 size
, &segments
[i
].segment_dma
, GFP_KERNEL
);
2067 if (!segments
[i
].segment
)
2069 if (mrioc
->enable_segqueue
)
2070 q_segment_list_entry
[i
] =
2071 (unsigned long)segments
[i
].segment_dma
;
2078 * mpi3mr_create_op_reply_q - create operational reply queue
2079 * @mrioc: Adapter instance reference
2080 * @qidx: operational reply queue index
2082 * Create operatinal reply queue by issuing MPI request
2083 * through admin queue.
2085 * Return: 0 on success, non-zero on failure.
2087 static int mpi3mr_create_op_reply_q(struct mpi3mr_ioc
*mrioc
, u16 qidx
)
2089 struct mpi3_create_reply_queue_request create_req
;
2090 struct op_reply_qinfo
*op_reply_q
= mrioc
->op_reply_qinfo
+ qidx
;
2092 u16 reply_qid
= 0, midx
;
2094 reply_qid
= op_reply_q
->qid
;
2096 midx
= REPLY_QUEUE_IDX_TO_MSIX_IDX(qidx
, mrioc
->op_reply_q_offset
);
2100 ioc_err(mrioc
, "CreateRepQ: called for duplicate qid %d\n",
2106 reply_qid
= qidx
+ 1;
2107 op_reply_q
->num_replies
= MPI3MR_OP_REP_Q_QD
;
2108 if ((mrioc
->pdev
->device
== MPI3_MFGPAGE_DEVID_SAS4116
) &&
2109 !mrioc
->pdev
->revision
)
2110 op_reply_q
->num_replies
= MPI3MR_OP_REP_Q_QD4K
;
2112 op_reply_q
->ephase
= 1;
2113 atomic_set(&op_reply_q
->pend_ios
, 0);
2114 atomic_set(&op_reply_q
->in_use
, 0);
2115 op_reply_q
->enable_irq_poll
= false;
2117 if (!op_reply_q
->q_segments
) {
2118 retval
= mpi3mr_alloc_op_reply_q_segments(mrioc
, qidx
);
2120 mpi3mr_free_op_reply_q_segments(mrioc
, qidx
);
2125 memset(&create_req
, 0, sizeof(create_req
));
2126 mutex_lock(&mrioc
->init_cmds
.mutex
);
2127 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
2129 ioc_err(mrioc
, "CreateRepQ: Init command is in use\n");
2132 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
2133 mrioc
->init_cmds
.is_waiting
= 1;
2134 mrioc
->init_cmds
.callback
= NULL
;
2135 create_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
2136 create_req
.function
= MPI3_FUNCTION_CREATE_REPLY_QUEUE
;
2137 create_req
.queue_id
= cpu_to_le16(reply_qid
);
2139 if (midx
< (mrioc
->intr_info_count
- mrioc
->requested_poll_qcount
))
2140 op_reply_q
->qtype
= MPI3MR_DEFAULT_QUEUE
;
2142 op_reply_q
->qtype
= MPI3MR_POLL_QUEUE
;
2144 if (op_reply_q
->qtype
== MPI3MR_DEFAULT_QUEUE
) {
2146 MPI3_CREATE_REPLY_QUEUE_FLAGS_INT_ENABLE_ENABLE
;
2147 create_req
.msix_index
=
2148 cpu_to_le16(mrioc
->intr_info
[midx
].msix_index
);
2150 create_req
.msix_index
= cpu_to_le16(mrioc
->intr_info_count
- 1);
2151 ioc_info(mrioc
, "create reply queue(polled): for qid(%d), midx(%d)\n",
2153 if (!mrioc
->active_poll_qcount
)
2154 disable_irq_nosync(pci_irq_vector(mrioc
->pdev
,
2155 mrioc
->intr_info_count
- 1));
2158 if (mrioc
->enable_segqueue
) {
2160 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED
;
2161 create_req
.base_address
= cpu_to_le64(
2162 op_reply_q
->q_segment_list_dma
);
2164 create_req
.base_address
= cpu_to_le64(
2165 op_reply_q
->q_segments
[0].segment_dma
);
2167 create_req
.size
= cpu_to_le16(op_reply_q
->num_replies
);
2169 init_completion(&mrioc
->init_cmds
.done
);
2170 retval
= mpi3mr_admin_request_post(mrioc
, &create_req
,
2171 sizeof(create_req
), 1);
2173 ioc_err(mrioc
, "CreateRepQ: Admin Post failed\n");
2176 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
2177 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
2178 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
2179 ioc_err(mrioc
, "create reply queue timed out\n");
2180 mpi3mr_check_rh_fault_ioc(mrioc
,
2181 MPI3MR_RESET_FROM_CREATEREPQ_TIMEOUT
);
2185 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
2186 != MPI3_IOCSTATUS_SUCCESS
) {
2188 "CreateRepQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2189 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
2190 mrioc
->init_cmds
.ioc_loginfo
);
2194 op_reply_q
->qid
= reply_qid
;
2195 if (midx
< mrioc
->intr_info_count
)
2196 mrioc
->intr_info
[midx
].op_reply_q
= op_reply_q
;
2198 (op_reply_q
->qtype
== MPI3MR_DEFAULT_QUEUE
) ? mrioc
->default_qcount
++ :
2199 mrioc
->active_poll_qcount
++;
2202 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
2203 mutex_unlock(&mrioc
->init_cmds
.mutex
);
2210 * mpi3mr_create_op_req_q - create operational request queue
2211 * @mrioc: Adapter instance reference
2212 * @idx: operational request queue index
2213 * @reply_qid: Reply queue ID
2215 * Create operatinal request queue by issuing MPI request
2216 * through admin queue.
2218 * Return: 0 on success, non-zero on failure.
2220 static int mpi3mr_create_op_req_q(struct mpi3mr_ioc
*mrioc
, u16 idx
,
2223 struct mpi3_create_request_queue_request create_req
;
2224 struct op_req_qinfo
*op_req_q
= mrioc
->req_qinfo
+ idx
;
2228 req_qid
= op_req_q
->qid
;
2232 ioc_err(mrioc
, "CreateReqQ: called for duplicate qid %d\n",
2239 op_req_q
->num_requests
= MPI3MR_OP_REQ_Q_QD
;
2242 op_req_q
->reply_qid
= reply_qid
;
2243 spin_lock_init(&op_req_q
->q_lock
);
2245 if (!op_req_q
->q_segments
) {
2246 retval
= mpi3mr_alloc_op_req_q_segments(mrioc
, idx
);
2248 mpi3mr_free_op_req_q_segments(mrioc
, idx
);
2253 memset(&create_req
, 0, sizeof(create_req
));
2254 mutex_lock(&mrioc
->init_cmds
.mutex
);
2255 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
2257 ioc_err(mrioc
, "CreateReqQ: Init command is in use\n");
2260 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
2261 mrioc
->init_cmds
.is_waiting
= 1;
2262 mrioc
->init_cmds
.callback
= NULL
;
2263 create_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
2264 create_req
.function
= MPI3_FUNCTION_CREATE_REQUEST_QUEUE
;
2265 create_req
.queue_id
= cpu_to_le16(req_qid
);
2266 if (mrioc
->enable_segqueue
) {
2268 MPI3_CREATE_REQUEST_QUEUE_FLAGS_SEGMENTED_SEGMENTED
;
2269 create_req
.base_address
= cpu_to_le64(
2270 op_req_q
->q_segment_list_dma
);
2272 create_req
.base_address
= cpu_to_le64(
2273 op_req_q
->q_segments
[0].segment_dma
);
2274 create_req
.reply_queue_id
= cpu_to_le16(reply_qid
);
2275 create_req
.size
= cpu_to_le16(op_req_q
->num_requests
);
2277 init_completion(&mrioc
->init_cmds
.done
);
2278 retval
= mpi3mr_admin_request_post(mrioc
, &create_req
,
2279 sizeof(create_req
), 1);
2281 ioc_err(mrioc
, "CreateReqQ: Admin Post failed\n");
2284 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
2285 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
2286 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
2287 ioc_err(mrioc
, "create request queue timed out\n");
2288 mpi3mr_check_rh_fault_ioc(mrioc
,
2289 MPI3MR_RESET_FROM_CREATEREQQ_TIMEOUT
);
2293 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
2294 != MPI3_IOCSTATUS_SUCCESS
) {
2296 "CreateReqQ: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2297 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
2298 mrioc
->init_cmds
.ioc_loginfo
);
2302 op_req_q
->qid
= req_qid
;
2305 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
2306 mutex_unlock(&mrioc
->init_cmds
.mutex
);
2313 * mpi3mr_create_op_queues - create operational queue pairs
2314 * @mrioc: Adapter instance reference
2316 * Allocate memory for operational queue meta data and call
2317 * create request and reply queue functions.
2319 * Return: 0 on success, non-zero on failures.
2321 static int mpi3mr_create_op_queues(struct mpi3mr_ioc
*mrioc
)
2324 u16 num_queues
= 0, i
= 0, msix_count_op_q
= 1;
2326 num_queues
= min_t(int, mrioc
->facts
.max_op_reply_q
,
2327 mrioc
->facts
.max_op_req_q
);
2330 mrioc
->intr_info_count
- mrioc
->op_reply_q_offset
;
2331 if (!mrioc
->num_queues
)
2332 mrioc
->num_queues
= min_t(int, num_queues
, msix_count_op_q
);
2334 * During reset set the num_queues to the number of queues
2335 * that was set before the reset.
2337 num_queues
= mrioc
->num_op_reply_q
?
2338 mrioc
->num_op_reply_q
: mrioc
->num_queues
;
2339 ioc_info(mrioc
, "trying to create %d operational queue pairs\n",
2342 if (!mrioc
->req_qinfo
) {
2343 mrioc
->req_qinfo
= kcalloc(num_queues
,
2344 sizeof(struct op_req_qinfo
), GFP_KERNEL
);
2345 if (!mrioc
->req_qinfo
) {
2350 mrioc
->op_reply_qinfo
= kzalloc(sizeof(struct op_reply_qinfo
) *
2351 num_queues
, GFP_KERNEL
);
2352 if (!mrioc
->op_reply_qinfo
) {
2358 if (mrioc
->enable_segqueue
)
2360 "allocating operational queues through segmented queues\n");
2362 for (i
= 0; i
< num_queues
; i
++) {
2363 if (mpi3mr_create_op_reply_q(mrioc
, i
)) {
2364 ioc_err(mrioc
, "Cannot create OP RepQ %d\n", i
);
2367 if (mpi3mr_create_op_req_q(mrioc
, i
,
2368 mrioc
->op_reply_qinfo
[i
].qid
)) {
2369 ioc_err(mrioc
, "Cannot create OP ReqQ %d\n", i
);
2370 mpi3mr_delete_op_reply_q(mrioc
, i
);
2376 /* Not even one queue is created successfully*/
2380 mrioc
->num_op_reply_q
= mrioc
->num_op_req_q
= i
;
2382 "successfully created %d operational queue pairs(default/polled) queue = (%d/%d)\n",
2383 mrioc
->num_op_reply_q
, mrioc
->default_qcount
,
2384 mrioc
->active_poll_qcount
);
2388 kfree(mrioc
->req_qinfo
);
2389 mrioc
->req_qinfo
= NULL
;
2391 kfree(mrioc
->op_reply_qinfo
);
2392 mrioc
->op_reply_qinfo
= NULL
;
2398 * mpi3mr_op_request_post - Post request to operational queue
2399 * @mrioc: Adapter reference
2400 * @op_req_q: Operational request queue info
2401 * @req: MPI3 request
2403 * Post the MPI3 request into operational request queue and
2404 * inform the controller, if the queue is full return
2405 * appropriate error.
2407 * Return: 0 on success, non-zero on failure.
2409 int mpi3mr_op_request_post(struct mpi3mr_ioc
*mrioc
,
2410 struct op_req_qinfo
*op_req_q
, u8
*req
)
2412 u16 pi
= 0, max_entries
, reply_qidx
= 0, midx
;
2414 unsigned long flags
;
2416 void *segment_base_addr
;
2417 u16 req_sz
= mrioc
->facts
.op_req_sz
;
2418 struct segments
*segments
= op_req_q
->q_segments
;
2420 reply_qidx
= op_req_q
->reply_qid
- 1;
2422 if (mrioc
->unrecoverable
)
2425 spin_lock_irqsave(&op_req_q
->q_lock
, flags
);
2427 max_entries
= op_req_q
->num_requests
;
2429 if (mpi3mr_check_req_qfull(op_req_q
)) {
2430 midx
= REPLY_QUEUE_IDX_TO_MSIX_IDX(
2431 reply_qidx
, mrioc
->op_reply_q_offset
);
2432 mpi3mr_process_op_reply_q(mrioc
, mrioc
->intr_info
[midx
].op_reply_q
);
2434 if (mpi3mr_check_req_qfull(op_req_q
)) {
2440 if (mrioc
->reset_in_progress
) {
2441 ioc_err(mrioc
, "OpReqQ submit reset in progress\n");
2445 if (mrioc
->pci_err_recovery
) {
2446 ioc_err(mrioc
, "operational request queue submission failed due to pci error recovery in progress\n");
2451 segment_base_addr
= segments
[pi
/ op_req_q
->segment_qd
].segment
;
2452 req_entry
= (u8
*)segment_base_addr
+
2453 ((pi
% op_req_q
->segment_qd
) * req_sz
);
2455 memset(req_entry
, 0, req_sz
);
2456 memcpy(req_entry
, req
, MPI3MR_ADMIN_REQ_FRAME_SZ
);
2458 if (++pi
== max_entries
)
2462 #ifndef CONFIG_PREEMPT_RT
2463 if (atomic_inc_return(&mrioc
->op_reply_qinfo
[reply_qidx
].pend_ios
)
2464 > MPI3MR_IRQ_POLL_TRIGGER_IOCOUNT
)
2465 mrioc
->op_reply_qinfo
[reply_qidx
].enable_irq_poll
= true;
2467 atomic_inc_return(&mrioc
->op_reply_qinfo
[reply_qidx
].pend_ios
);
2470 writel(op_req_q
->pi
,
2471 &mrioc
->sysif_regs
->oper_queue_indexes
[reply_qidx
].producer_index
);
2474 spin_unlock_irqrestore(&op_req_q
->q_lock
, flags
);
2479 * mpi3mr_check_rh_fault_ioc - check reset history and fault
2481 * @mrioc: Adapter instance reference
2482 * @reason_code: reason code for the fault.
2484 * This routine will save snapdump and fault the controller with
2485 * the given reason code if it is not already in the fault or
2486 * not asynchronosuly reset. This will be used to handle
2487 * initilaization time faults/resets/timeout as in those cases
2488 * immediate soft reset invocation is not required.
2492 void mpi3mr_check_rh_fault_ioc(struct mpi3mr_ioc
*mrioc
, u32 reason_code
)
2494 u32 ioc_status
, host_diagnostic
, timeout
;
2495 union mpi3mr_trigger_data trigger_data
;
2497 if (mrioc
->unrecoverable
) {
2498 ioc_err(mrioc
, "controller is unrecoverable\n");
2502 if (!pci_device_is_present(mrioc
->pdev
)) {
2503 mrioc
->unrecoverable
= 1;
2504 ioc_err(mrioc
, "controller is not present\n");
2507 memset(&trigger_data
, 0, sizeof(trigger_data
));
2508 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
2510 if (ioc_status
& MPI3_SYSIF_IOC_STATUS_RESET_HISTORY
) {
2511 mpi3mr_set_trigger_data_in_all_hdb(mrioc
,
2512 MPI3MR_HDB_TRIGGER_TYPE_FW_RELEASED
, NULL
, 0);
2514 } else if (ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
) {
2515 trigger_data
.fault
= (readl(&mrioc
->sysif_regs
->fault
) &
2516 MPI3_SYSIF_FAULT_CODE_MASK
);
2518 mpi3mr_set_trigger_data_in_all_hdb(mrioc
,
2519 MPI3MR_HDB_TRIGGER_TYPE_FAULT
, &trigger_data
, 0);
2520 mpi3mr_print_fault_info(mrioc
);
2524 mpi3mr_set_diagsave(mrioc
);
2525 mpi3mr_issue_reset(mrioc
, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
,
2527 trigger_data
.fault
= (readl(&mrioc
->sysif_regs
->fault
) &
2528 MPI3_SYSIF_FAULT_CODE_MASK
);
2529 mpi3mr_set_trigger_data_in_all_hdb(mrioc
, MPI3MR_HDB_TRIGGER_TYPE_FAULT
,
2531 timeout
= MPI3_SYSIF_DIAG_SAVE_TIMEOUT
* 10;
2533 host_diagnostic
= readl(&mrioc
->sysif_regs
->host_diagnostic
);
2534 if (!(host_diagnostic
& MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS
))
2537 } while (--timeout
);
2541 * mpi3mr_sync_timestamp - Issue time stamp sync request
2542 * @mrioc: Adapter reference
2544 * Issue IO unit control MPI request to synchornize firmware
2545 * timestamp with host time.
2547 * Return: 0 on success, non-zero on failure.
2549 static int mpi3mr_sync_timestamp(struct mpi3mr_ioc
*mrioc
)
2551 ktime_t current_time
;
2552 struct mpi3_iounit_control_request iou_ctrl
;
2555 memset(&iou_ctrl
, 0, sizeof(iou_ctrl
));
2556 mutex_lock(&mrioc
->init_cmds
.mutex
);
2557 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
2559 ioc_err(mrioc
, "Issue IOUCTL time_stamp: command is in use\n");
2560 mutex_unlock(&mrioc
->init_cmds
.mutex
);
2563 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
2564 mrioc
->init_cmds
.is_waiting
= 1;
2565 mrioc
->init_cmds
.callback
= NULL
;
2566 iou_ctrl
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
2567 iou_ctrl
.function
= MPI3_FUNCTION_IO_UNIT_CONTROL
;
2568 iou_ctrl
.operation
= MPI3_CTRL_OP_UPDATE_TIMESTAMP
;
2569 current_time
= ktime_get_real();
2570 iou_ctrl
.param64
[0] = cpu_to_le64(ktime_to_ms(current_time
));
2572 init_completion(&mrioc
->init_cmds
.done
);
2573 retval
= mpi3mr_admin_request_post(mrioc
, &iou_ctrl
,
2574 sizeof(iou_ctrl
), 0);
2576 ioc_err(mrioc
, "Issue IOUCTL time_stamp: Admin Post failed\n");
2580 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
2581 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
2582 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
2583 ioc_err(mrioc
, "Issue IOUCTL time_stamp: command timed out\n");
2584 mrioc
->init_cmds
.is_waiting
= 0;
2585 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_RESET
))
2586 mpi3mr_check_rh_fault_ioc(mrioc
,
2587 MPI3MR_RESET_FROM_TSU_TIMEOUT
);
2591 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
2592 != MPI3_IOCSTATUS_SUCCESS
) {
2594 "Issue IOUCTL time_stamp: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2595 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
2596 mrioc
->init_cmds
.ioc_loginfo
);
2602 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
2603 mutex_unlock(&mrioc
->init_cmds
.mutex
);
2610 * mpi3mr_print_pkg_ver - display controller fw package version
2611 * @mrioc: Adapter reference
2613 * Retrieve firmware package version from the component image
2614 * header of the controller flash and display it.
2616 * Return: 0 on success and non-zero on failure.
2618 static int mpi3mr_print_pkg_ver(struct mpi3mr_ioc
*mrioc
)
2620 struct mpi3_ci_upload_request ci_upload
;
2623 dma_addr_t data_dma
;
2624 struct mpi3_ci_manifest_mpi
*manifest
;
2625 u32 data_len
= sizeof(struct mpi3_ci_manifest_mpi
);
2626 u8 sgl_flags
= MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST
;
2628 data
= dma_alloc_coherent(&mrioc
->pdev
->dev
, data_len
, &data_dma
,
2633 memset(&ci_upload
, 0, sizeof(ci_upload
));
2634 mutex_lock(&mrioc
->init_cmds
.mutex
);
2635 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
2636 ioc_err(mrioc
, "sending get package version failed due to command in use\n");
2637 mutex_unlock(&mrioc
->init_cmds
.mutex
);
2640 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
2641 mrioc
->init_cmds
.is_waiting
= 1;
2642 mrioc
->init_cmds
.callback
= NULL
;
2643 ci_upload
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
2644 ci_upload
.function
= MPI3_FUNCTION_CI_UPLOAD
;
2645 ci_upload
.msg_flags
= MPI3_CI_UPLOAD_MSGFLAGS_LOCATION_PRIMARY
;
2646 ci_upload
.signature1
= cpu_to_le32(MPI3_IMAGE_HEADER_SIGNATURE1_MANIFEST
);
2647 ci_upload
.image_offset
= cpu_to_le32(MPI3_IMAGE_HEADER_SIZE
);
2648 ci_upload
.segment_size
= cpu_to_le32(data_len
);
2650 mpi3mr_add_sg_single(&ci_upload
.sgl
, sgl_flags
, data_len
,
2652 init_completion(&mrioc
->init_cmds
.done
);
2653 retval
= mpi3mr_admin_request_post(mrioc
, &ci_upload
,
2654 sizeof(ci_upload
), 1);
2656 ioc_err(mrioc
, "posting get package version failed\n");
2659 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
2660 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
2661 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
2662 ioc_err(mrioc
, "get package version timed out\n");
2663 mpi3mr_check_rh_fault_ioc(mrioc
,
2664 MPI3MR_RESET_FROM_GETPKGVER_TIMEOUT
);
2668 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
2669 == MPI3_IOCSTATUS_SUCCESS
) {
2670 manifest
= (struct mpi3_ci_manifest_mpi
*) data
;
2671 if (manifest
->manifest_type
== MPI3_CI_MANIFEST_TYPE_MPI
) {
2673 "firmware package version(%d.%d.%d.%d.%05d-%05d)\n",
2674 manifest
->package_version
.gen_major
,
2675 manifest
->package_version
.gen_minor
,
2676 manifest
->package_version
.phase_major
,
2677 manifest
->package_version
.phase_minor
,
2678 manifest
->package_version
.customer_id
,
2679 manifest
->package_version
.build_num
);
2684 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
2685 mutex_unlock(&mrioc
->init_cmds
.mutex
);
2689 dma_free_coherent(&mrioc
->pdev
->dev
, data_len
, data
,
2695 * mpi3mr_watchdog_work - watchdog thread to monitor faults
2696 * @work: work struct
2698 * Watch dog work periodically executed (1 second interval) to
2699 * monitor firmware fault and to issue periodic timer sync to
2704 static void mpi3mr_watchdog_work(struct work_struct
*work
)
2706 struct mpi3mr_ioc
*mrioc
=
2707 container_of(work
, struct mpi3mr_ioc
, watchdog_work
.work
);
2708 unsigned long flags
;
2709 enum mpi3mr_iocstate ioc_state
;
2710 u32 host_diagnostic
, ioc_status
;
2711 union mpi3mr_trigger_data trigger_data
;
2712 u16 reset_reason
= MPI3MR_RESET_FROM_FAULT_WATCH
;
2714 if (mrioc
->reset_in_progress
|| mrioc
->pci_err_recovery
)
2717 if (!mrioc
->unrecoverable
&& !pci_device_is_present(mrioc
->pdev
)) {
2718 ioc_err(mrioc
, "watchdog could not detect the controller\n");
2719 mrioc
->unrecoverable
= 1;
2722 if (mrioc
->unrecoverable
) {
2724 "flush pending commands for unrecoverable controller\n");
2725 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc
);
2729 if (mrioc
->ts_update_counter
++ >= mrioc
->ts_update_interval
) {
2730 mrioc
->ts_update_counter
= 0;
2731 mpi3mr_sync_timestamp(mrioc
);
2734 if ((mrioc
->prepare_for_reset
) &&
2735 ((mrioc
->prepare_for_reset_timeout_counter
++) >=
2736 MPI3MR_PREPARE_FOR_RESET_TIMEOUT
)) {
2737 mpi3mr_soft_reset_handler(mrioc
,
2738 MPI3MR_RESET_FROM_CIACTVRST_TIMER
, 1);
2742 memset(&trigger_data
, 0, sizeof(trigger_data
));
2743 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
2744 if (ioc_status
& MPI3_SYSIF_IOC_STATUS_RESET_HISTORY
) {
2745 mpi3mr_set_trigger_data_in_all_hdb(mrioc
,
2746 MPI3MR_HDB_TRIGGER_TYPE_FW_RELEASED
, NULL
, 0);
2747 mpi3mr_soft_reset_handler(mrioc
, MPI3MR_RESET_FROM_FIRMWARE
, 0);
2751 /*Check for fault state every one second and issue Soft reset*/
2752 ioc_state
= mpi3mr_get_iocstate(mrioc
);
2753 if (ioc_state
!= MRIOC_STATE_FAULT
)
2756 trigger_data
.fault
= readl(&mrioc
->sysif_regs
->fault
) & MPI3_SYSIF_FAULT_CODE_MASK
;
2757 mpi3mr_set_trigger_data_in_all_hdb(mrioc
,
2758 MPI3MR_HDB_TRIGGER_TYPE_FAULT
, &trigger_data
, 0);
2759 host_diagnostic
= readl(&mrioc
->sysif_regs
->host_diagnostic
);
2760 if (host_diagnostic
& MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS
) {
2761 if (!mrioc
->diagsave_timeout
) {
2762 mpi3mr_print_fault_info(mrioc
);
2763 ioc_warn(mrioc
, "diag save in progress\n");
2765 if ((mrioc
->diagsave_timeout
++) <= MPI3_SYSIF_DIAG_SAVE_TIMEOUT
)
2769 mpi3mr_print_fault_info(mrioc
);
2770 mrioc
->diagsave_timeout
= 0;
2772 if (!mpi3mr_is_fault_recoverable(mrioc
)) {
2773 mrioc
->unrecoverable
= 1;
2777 switch (trigger_data
.fault
) {
2778 case MPI3_SYSIF_FAULT_CODE_COMPLETE_RESET_NEEDED
:
2779 case MPI3_SYSIF_FAULT_CODE_POWER_CYCLE_REQUIRED
:
2781 "controller requires system power cycle, marking controller as unrecoverable\n");
2782 mrioc
->unrecoverable
= 1;
2784 case MPI3_SYSIF_FAULT_CODE_SOFT_RESET_IN_PROGRESS
:
2786 case MPI3_SYSIF_FAULT_CODE_CI_ACTIVATION_RESET
:
2787 reset_reason
= MPI3MR_RESET_FROM_CIACTIV_FAULT
;
2792 mpi3mr_soft_reset_handler(mrioc
, reset_reason
, 0);
2796 spin_lock_irqsave(&mrioc
->watchdog_lock
, flags
);
2797 if (mrioc
->watchdog_work_q
)
2798 queue_delayed_work(mrioc
->watchdog_work_q
,
2799 &mrioc
->watchdog_work
,
2800 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL
));
2801 spin_unlock_irqrestore(&mrioc
->watchdog_lock
, flags
);
2806 * mpi3mr_start_watchdog - Start watchdog
2807 * @mrioc: Adapter instance reference
2809 * Create and start the watchdog thread to monitor controller
2814 void mpi3mr_start_watchdog(struct mpi3mr_ioc
*mrioc
)
2816 if (mrioc
->watchdog_work_q
)
2819 INIT_DELAYED_WORK(&mrioc
->watchdog_work
, mpi3mr_watchdog_work
);
2820 snprintf(mrioc
->watchdog_work_q_name
,
2821 sizeof(mrioc
->watchdog_work_q_name
), "watchdog_%s%d", mrioc
->name
,
2823 mrioc
->watchdog_work_q
= alloc_ordered_workqueue(
2824 "%s", WQ_MEM_RECLAIM
, mrioc
->watchdog_work_q_name
);
2825 if (!mrioc
->watchdog_work_q
) {
2826 ioc_err(mrioc
, "%s: failed (line=%d)\n", __func__
, __LINE__
);
2830 if (mrioc
->watchdog_work_q
)
2831 queue_delayed_work(mrioc
->watchdog_work_q
,
2832 &mrioc
->watchdog_work
,
2833 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL
));
2837 * mpi3mr_stop_watchdog - Stop watchdog
2838 * @mrioc: Adapter instance reference
2840 * Stop the watchdog thread created to monitor controller
2845 void mpi3mr_stop_watchdog(struct mpi3mr_ioc
*mrioc
)
2847 unsigned long flags
;
2848 struct workqueue_struct
*wq
;
2850 spin_lock_irqsave(&mrioc
->watchdog_lock
, flags
);
2851 wq
= mrioc
->watchdog_work_q
;
2852 mrioc
->watchdog_work_q
= NULL
;
2853 spin_unlock_irqrestore(&mrioc
->watchdog_lock
, flags
);
2855 if (!cancel_delayed_work_sync(&mrioc
->watchdog_work
))
2856 flush_workqueue(wq
);
2857 destroy_workqueue(wq
);
2862 * mpi3mr_setup_admin_qpair - Setup admin queue pair
2863 * @mrioc: Adapter instance reference
2865 * Allocate memory for admin queue pair if required and register
2866 * the admin queue with the controller.
2868 * Return: 0 on success, non-zero on failures.
2870 static int mpi3mr_setup_admin_qpair(struct mpi3mr_ioc
*mrioc
)
2873 u32 num_admin_entries
= 0;
2875 mrioc
->admin_req_q_sz
= MPI3MR_ADMIN_REQ_Q_SIZE
;
2876 mrioc
->num_admin_req
= mrioc
->admin_req_q_sz
/
2877 MPI3MR_ADMIN_REQ_FRAME_SZ
;
2878 mrioc
->admin_req_ci
= mrioc
->admin_req_pi
= 0;
2880 mrioc
->admin_reply_q_sz
= MPI3MR_ADMIN_REPLY_Q_SIZE
;
2881 mrioc
->num_admin_replies
= mrioc
->admin_reply_q_sz
/
2882 MPI3MR_ADMIN_REPLY_FRAME_SZ
;
2883 mrioc
->admin_reply_ci
= 0;
2884 mrioc
->admin_reply_ephase
= 1;
2885 atomic_set(&mrioc
->admin_reply_q_in_use
, 0);
2887 if (!mrioc
->admin_req_base
) {
2888 mrioc
->admin_req_base
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
2889 mrioc
->admin_req_q_sz
, &mrioc
->admin_req_dma
, GFP_KERNEL
);
2891 if (!mrioc
->admin_req_base
) {
2896 mrioc
->admin_reply_base
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
2897 mrioc
->admin_reply_q_sz
, &mrioc
->admin_reply_dma
,
2900 if (!mrioc
->admin_reply_base
) {
2906 num_admin_entries
= (mrioc
->num_admin_replies
<< 16) |
2907 (mrioc
->num_admin_req
);
2908 writel(num_admin_entries
, &mrioc
->sysif_regs
->admin_queue_num_entries
);
2909 mpi3mr_writeq(mrioc
->admin_req_dma
,
2910 &mrioc
->sysif_regs
->admin_request_queue_address
);
2911 mpi3mr_writeq(mrioc
->admin_reply_dma
,
2912 &mrioc
->sysif_regs
->admin_reply_queue_address
);
2913 writel(mrioc
->admin_req_pi
, &mrioc
->sysif_regs
->admin_request_queue_pi
);
2914 writel(mrioc
->admin_reply_ci
, &mrioc
->sysif_regs
->admin_reply_queue_ci
);
2919 if (mrioc
->admin_reply_base
) {
2920 dma_free_coherent(&mrioc
->pdev
->dev
, mrioc
->admin_reply_q_sz
,
2921 mrioc
->admin_reply_base
, mrioc
->admin_reply_dma
);
2922 mrioc
->admin_reply_base
= NULL
;
2924 if (mrioc
->admin_req_base
) {
2925 dma_free_coherent(&mrioc
->pdev
->dev
, mrioc
->admin_req_q_sz
,
2926 mrioc
->admin_req_base
, mrioc
->admin_req_dma
);
2927 mrioc
->admin_req_base
= NULL
;
2933 * mpi3mr_issue_iocfacts - Send IOC Facts
2934 * @mrioc: Adapter instance reference
2935 * @facts_data: Cached IOC facts data
2937 * Issue IOC Facts MPI request through admin queue and wait for
2938 * the completion of it or time out.
2940 * Return: 0 on success, non-zero on failures.
2942 static int mpi3mr_issue_iocfacts(struct mpi3mr_ioc
*mrioc
,
2943 struct mpi3_ioc_facts_data
*facts_data
)
2945 struct mpi3_ioc_facts_request iocfacts_req
;
2947 dma_addr_t data_dma
;
2948 u32 data_len
= sizeof(*facts_data
);
2950 u8 sgl_flags
= MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST
;
2952 data
= dma_alloc_coherent(&mrioc
->pdev
->dev
, data_len
, &data_dma
,
2960 memset(&iocfacts_req
, 0, sizeof(iocfacts_req
));
2961 mutex_lock(&mrioc
->init_cmds
.mutex
);
2962 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
2964 ioc_err(mrioc
, "Issue IOCFacts: Init command is in use\n");
2965 mutex_unlock(&mrioc
->init_cmds
.mutex
);
2968 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
2969 mrioc
->init_cmds
.is_waiting
= 1;
2970 mrioc
->init_cmds
.callback
= NULL
;
2971 iocfacts_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
2972 iocfacts_req
.function
= MPI3_FUNCTION_IOC_FACTS
;
2974 mpi3mr_add_sg_single(&iocfacts_req
.sgl
, sgl_flags
, data_len
,
2977 init_completion(&mrioc
->init_cmds
.done
);
2978 retval
= mpi3mr_admin_request_post(mrioc
, &iocfacts_req
,
2979 sizeof(iocfacts_req
), 1);
2981 ioc_err(mrioc
, "Issue IOCFacts: Admin Post failed\n");
2984 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
2985 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
2986 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
2987 ioc_err(mrioc
, "ioc_facts timed out\n");
2988 mpi3mr_check_rh_fault_ioc(mrioc
,
2989 MPI3MR_RESET_FROM_IOCFACTS_TIMEOUT
);
2993 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
2994 != MPI3_IOCSTATUS_SUCCESS
) {
2996 "Issue IOCFacts: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
2997 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
2998 mrioc
->init_cmds
.ioc_loginfo
);
3002 memcpy(facts_data
, (u8
*)data
, data_len
);
3003 mpi3mr_process_factsdata(mrioc
, facts_data
);
3005 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
3006 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3010 dma_free_coherent(&mrioc
->pdev
->dev
, data_len
, data
, data_dma
);
3016 * mpi3mr_check_reset_dma_mask - Process IOC facts data
3017 * @mrioc: Adapter instance reference
3019 * Check whether the new DMA mask requested through IOCFacts by
3020 * firmware needs to be set, if so set it .
3022 * Return: 0 on success, non-zero on failure.
3024 static inline int mpi3mr_check_reset_dma_mask(struct mpi3mr_ioc
*mrioc
)
3026 struct pci_dev
*pdev
= mrioc
->pdev
;
3028 u64 facts_dma_mask
= DMA_BIT_MASK(mrioc
->facts
.dma_mask
);
3030 if (!mrioc
->facts
.dma_mask
|| (mrioc
->dma_mask
<= facts_dma_mask
))
3033 ioc_info(mrioc
, "Changing DMA mask from 0x%016llx to 0x%016llx\n",
3034 mrioc
->dma_mask
, facts_dma_mask
);
3036 r
= dma_set_mask_and_coherent(&pdev
->dev
, facts_dma_mask
);
3038 ioc_err(mrioc
, "Setting DMA mask to 0x%016llx failed: %d\n",
3042 mrioc
->dma_mask
= facts_dma_mask
;
3047 * mpi3mr_process_factsdata - Process IOC facts data
3048 * @mrioc: Adapter instance reference
3049 * @facts_data: Cached IOC facts data
3051 * Convert IOC facts data into cpu endianness and cache it in
3056 static void mpi3mr_process_factsdata(struct mpi3mr_ioc
*mrioc
,
3057 struct mpi3_ioc_facts_data
*facts_data
)
3059 u32 ioc_config
, req_sz
, facts_flags
;
3061 if ((le16_to_cpu(facts_data
->ioc_facts_data_length
)) !=
3062 (sizeof(*facts_data
) / 4)) {
3064 "IOCFactsdata length mismatch driver_sz(%zu) firmware_sz(%d)\n",
3065 sizeof(*facts_data
),
3066 le16_to_cpu(facts_data
->ioc_facts_data_length
) * 4);
3069 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
3070 req_sz
= 1 << ((ioc_config
& MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ
) >>
3071 MPI3_SYSIF_IOC_CONFIG_OPER_REQ_ENT_SZ_SHIFT
);
3072 if (le16_to_cpu(facts_data
->ioc_request_frame_size
) != (req_sz
/ 4)) {
3074 "IOCFacts data reqFrameSize mismatch hw_size(%d) firmware_sz(%d)\n",
3075 req_sz
/ 4, le16_to_cpu(facts_data
->ioc_request_frame_size
));
3078 memset(&mrioc
->facts
, 0, sizeof(mrioc
->facts
));
3080 facts_flags
= le32_to_cpu(facts_data
->flags
);
3081 mrioc
->facts
.op_req_sz
= req_sz
;
3082 mrioc
->op_reply_desc_sz
= 1 << ((ioc_config
&
3083 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ
) >>
3084 MPI3_SYSIF_IOC_CONFIG_OPER_RPY_ENT_SZ_SHIFT
);
3086 mrioc
->facts
.ioc_num
= facts_data
->ioc_number
;
3087 mrioc
->facts
.who_init
= facts_data
->who_init
;
3088 mrioc
->facts
.max_msix_vectors
= le16_to_cpu(facts_data
->max_msix_vectors
);
3089 mrioc
->facts
.personality
= (facts_flags
&
3090 MPI3_IOCFACTS_FLAGS_PERSONALITY_MASK
);
3091 mrioc
->facts
.dma_mask
= (facts_flags
&
3092 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_MASK
) >>
3093 MPI3_IOCFACTS_FLAGS_DMA_ADDRESS_WIDTH_SHIFT
;
3094 mrioc
->facts
.protocol_flags
= facts_data
->protocol_flags
;
3095 mrioc
->facts
.mpi_version
= le32_to_cpu(facts_data
->mpi_version
.word
);
3096 mrioc
->facts
.max_reqs
= le16_to_cpu(facts_data
->max_outstanding_requests
);
3097 mrioc
->facts
.product_id
= le16_to_cpu(facts_data
->product_id
);
3098 mrioc
->facts
.reply_sz
= le16_to_cpu(facts_data
->reply_frame_size
) * 4;
3099 mrioc
->facts
.exceptions
= le16_to_cpu(facts_data
->ioc_exceptions
);
3100 mrioc
->facts
.max_perids
= le16_to_cpu(facts_data
->max_persistent_id
);
3101 mrioc
->facts
.max_vds
= le16_to_cpu(facts_data
->max_vds
);
3102 mrioc
->facts
.max_hpds
= le16_to_cpu(facts_data
->max_host_pds
);
3103 mrioc
->facts
.max_advhpds
= le16_to_cpu(facts_data
->max_adv_host_pds
);
3104 mrioc
->facts
.max_raid_pds
= le16_to_cpu(facts_data
->max_raid_pds
);
3105 mrioc
->facts
.max_nvme
= le16_to_cpu(facts_data
->max_nvme
);
3106 mrioc
->facts
.max_pcie_switches
=
3107 le16_to_cpu(facts_data
->max_pcie_switches
);
3108 mrioc
->facts
.max_sasexpanders
=
3109 le16_to_cpu(facts_data
->max_sas_expanders
);
3110 mrioc
->facts
.max_data_length
= le16_to_cpu(facts_data
->max_data_length
);
3111 mrioc
->facts
.max_sasinitiators
=
3112 le16_to_cpu(facts_data
->max_sas_initiators
);
3113 mrioc
->facts
.max_enclosures
= le16_to_cpu(facts_data
->max_enclosures
);
3114 mrioc
->facts
.min_devhandle
= le16_to_cpu(facts_data
->min_dev_handle
);
3115 mrioc
->facts
.max_devhandle
= le16_to_cpu(facts_data
->max_dev_handle
);
3116 mrioc
->facts
.max_op_req_q
=
3117 le16_to_cpu(facts_data
->max_operational_request_queues
);
3118 mrioc
->facts
.max_op_reply_q
=
3119 le16_to_cpu(facts_data
->max_operational_reply_queues
);
3120 mrioc
->facts
.ioc_capabilities
=
3121 le32_to_cpu(facts_data
->ioc_capabilities
);
3122 mrioc
->facts
.fw_ver
.build_num
=
3123 le16_to_cpu(facts_data
->fw_version
.build_num
);
3124 mrioc
->facts
.fw_ver
.cust_id
=
3125 le16_to_cpu(facts_data
->fw_version
.customer_id
);
3126 mrioc
->facts
.fw_ver
.ph_minor
= facts_data
->fw_version
.phase_minor
;
3127 mrioc
->facts
.fw_ver
.ph_major
= facts_data
->fw_version
.phase_major
;
3128 mrioc
->facts
.fw_ver
.gen_minor
= facts_data
->fw_version
.gen_minor
;
3129 mrioc
->facts
.fw_ver
.gen_major
= facts_data
->fw_version
.gen_major
;
3130 mrioc
->msix_count
= min_t(int, mrioc
->msix_count
,
3131 mrioc
->facts
.max_msix_vectors
);
3132 mrioc
->facts
.sge_mod_mask
= facts_data
->sge_modifier_mask
;
3133 mrioc
->facts
.sge_mod_value
= facts_data
->sge_modifier_value
;
3134 mrioc
->facts
.sge_mod_shift
= facts_data
->sge_modifier_shift
;
3135 mrioc
->facts
.shutdown_timeout
=
3136 le16_to_cpu(facts_data
->shutdown_timeout
);
3137 mrioc
->facts
.diag_trace_sz
=
3138 le32_to_cpu(facts_data
->diag_trace_size
);
3139 mrioc
->facts
.diag_fw_sz
=
3140 le32_to_cpu(facts_data
->diag_fw_size
);
3141 mrioc
->facts
.diag_drvr_sz
= le32_to_cpu(facts_data
->diag_driver_size
);
3142 mrioc
->facts
.max_dev_per_tg
=
3143 facts_data
->max_devices_per_throttle_group
;
3144 mrioc
->facts
.io_throttle_data_length
=
3145 le16_to_cpu(facts_data
->io_throttle_data_length
);
3146 mrioc
->facts
.max_io_throttle_group
=
3147 le16_to_cpu(facts_data
->max_io_throttle_group
);
3148 mrioc
->facts
.io_throttle_low
= le16_to_cpu(facts_data
->io_throttle_low
);
3149 mrioc
->facts
.io_throttle_high
=
3150 le16_to_cpu(facts_data
->io_throttle_high
);
3152 if (mrioc
->facts
.max_data_length
==
3153 MPI3_IOCFACTS_MAX_DATA_LENGTH_NOT_REPORTED
)
3154 mrioc
->facts
.max_data_length
= MPI3MR_DEFAULT_MAX_IO_SIZE
;
3156 mrioc
->facts
.max_data_length
*= MPI3MR_PAGE_SIZE_4K
;
3157 /* Store in 512b block count */
3158 if (mrioc
->facts
.io_throttle_data_length
)
3159 mrioc
->io_throttle_data_length
=
3160 (mrioc
->facts
.io_throttle_data_length
* 2 * 4);
3162 /* set the length to 1MB + 1K to disable throttle */
3163 mrioc
->io_throttle_data_length
= (mrioc
->facts
.max_data_length
/ 512) + 2;
3165 mrioc
->io_throttle_high
= (mrioc
->facts
.io_throttle_high
* 2 * 1024);
3166 mrioc
->io_throttle_low
= (mrioc
->facts
.io_throttle_low
* 2 * 1024);
3168 ioc_info(mrioc
, "ioc_num(%d), maxopQ(%d), maxopRepQ(%d), maxdh(%d),",
3169 mrioc
->facts
.ioc_num
, mrioc
->facts
.max_op_req_q
,
3170 mrioc
->facts
.max_op_reply_q
, mrioc
->facts
.max_devhandle
);
3172 "maxreqs(%d), mindh(%d) maxvectors(%d) maxperids(%d)\n",
3173 mrioc
->facts
.max_reqs
, mrioc
->facts
.min_devhandle
,
3174 mrioc
->facts
.max_msix_vectors
, mrioc
->facts
.max_perids
);
3175 ioc_info(mrioc
, "SGEModMask 0x%x SGEModVal 0x%x SGEModShift 0x%x ",
3176 mrioc
->facts
.sge_mod_mask
, mrioc
->facts
.sge_mod_value
,
3177 mrioc
->facts
.sge_mod_shift
);
3178 ioc_info(mrioc
, "DMA mask %d InitialPE status 0x%x max_data_len (%d)\n",
3179 mrioc
->facts
.dma_mask
, (facts_flags
&
3180 MPI3_IOCFACTS_FLAGS_INITIAL_PORT_ENABLE_MASK
), mrioc
->facts
.max_data_length
);
3182 "max_dev_per_throttle_group(%d), max_throttle_groups(%d)\n",
3183 mrioc
->facts
.max_dev_per_tg
, mrioc
->facts
.max_io_throttle_group
);
3185 "io_throttle_data_len(%dKiB), io_throttle_high(%dMiB), io_throttle_low(%dMiB)\n",
3186 mrioc
->facts
.io_throttle_data_length
* 4,
3187 mrioc
->facts
.io_throttle_high
, mrioc
->facts
.io_throttle_low
);
3191 * mpi3mr_alloc_reply_sense_bufs - Send IOC Init
3192 * @mrioc: Adapter instance reference
3194 * Allocate and initialize the reply free buffers, sense
3195 * buffers, reply free queue and sense buffer queue.
3197 * Return: 0 on success, non-zero on failures.
3199 static int mpi3mr_alloc_reply_sense_bufs(struct mpi3mr_ioc
*mrioc
)
3204 if (mrioc
->init_cmds
.reply
)
3207 mrioc
->init_cmds
.reply
= kzalloc(mrioc
->reply_sz
, GFP_KERNEL
);
3208 if (!mrioc
->init_cmds
.reply
)
3211 mrioc
->bsg_cmds
.reply
= kzalloc(mrioc
->reply_sz
, GFP_KERNEL
);
3212 if (!mrioc
->bsg_cmds
.reply
)
3215 mrioc
->transport_cmds
.reply
= kzalloc(mrioc
->reply_sz
, GFP_KERNEL
);
3216 if (!mrioc
->transport_cmds
.reply
)
3219 for (i
= 0; i
< MPI3MR_NUM_DEVRMCMD
; i
++) {
3220 mrioc
->dev_rmhs_cmds
[i
].reply
= kzalloc(mrioc
->reply_sz
,
3222 if (!mrioc
->dev_rmhs_cmds
[i
].reply
)
3226 for (i
= 0; i
< MPI3MR_NUM_EVTACKCMD
; i
++) {
3227 mrioc
->evtack_cmds
[i
].reply
= kzalloc(mrioc
->reply_sz
,
3229 if (!mrioc
->evtack_cmds
[i
].reply
)
3233 mrioc
->host_tm_cmds
.reply
= kzalloc(mrioc
->reply_sz
, GFP_KERNEL
);
3234 if (!mrioc
->host_tm_cmds
.reply
)
3237 mrioc
->pel_cmds
.reply
= kzalloc(mrioc
->reply_sz
, GFP_KERNEL
);
3238 if (!mrioc
->pel_cmds
.reply
)
3241 mrioc
->pel_abort_cmd
.reply
= kzalloc(mrioc
->reply_sz
, GFP_KERNEL
);
3242 if (!mrioc
->pel_abort_cmd
.reply
)
3245 mrioc
->dev_handle_bitmap_bits
= mrioc
->facts
.max_devhandle
;
3246 mrioc
->removepend_bitmap
= bitmap_zalloc(mrioc
->dev_handle_bitmap_bits
,
3248 if (!mrioc
->removepend_bitmap
)
3251 mrioc
->devrem_bitmap
= bitmap_zalloc(MPI3MR_NUM_DEVRMCMD
, GFP_KERNEL
);
3252 if (!mrioc
->devrem_bitmap
)
3255 mrioc
->evtack_cmds_bitmap
= bitmap_zalloc(MPI3MR_NUM_EVTACKCMD
,
3257 if (!mrioc
->evtack_cmds_bitmap
)
3260 mrioc
->num_reply_bufs
= mrioc
->facts
.max_reqs
+ MPI3MR_NUM_EVT_REPLIES
;
3261 mrioc
->reply_free_qsz
= mrioc
->num_reply_bufs
+ 1;
3262 mrioc
->num_sense_bufs
= mrioc
->facts
.max_reqs
/ MPI3MR_SENSEBUF_FACTOR
;
3263 mrioc
->sense_buf_q_sz
= mrioc
->num_sense_bufs
+ 1;
3265 /* reply buffer pool, 16 byte align */
3266 sz
= mrioc
->num_reply_bufs
* mrioc
->reply_sz
;
3267 mrioc
->reply_buf_pool
= dma_pool_create("reply_buf pool",
3268 &mrioc
->pdev
->dev
, sz
, 16, 0);
3269 if (!mrioc
->reply_buf_pool
) {
3270 ioc_err(mrioc
, "reply buf pool: dma_pool_create failed\n");
3274 mrioc
->reply_buf
= dma_pool_zalloc(mrioc
->reply_buf_pool
, GFP_KERNEL
,
3275 &mrioc
->reply_buf_dma
);
3276 if (!mrioc
->reply_buf
)
3279 mrioc
->reply_buf_dma_max_address
= mrioc
->reply_buf_dma
+ sz
;
3281 /* reply free queue, 8 byte align */
3282 sz
= mrioc
->reply_free_qsz
* 8;
3283 mrioc
->reply_free_q_pool
= dma_pool_create("reply_free_q pool",
3284 &mrioc
->pdev
->dev
, sz
, 8, 0);
3285 if (!mrioc
->reply_free_q_pool
) {
3286 ioc_err(mrioc
, "reply_free_q pool: dma_pool_create failed\n");
3289 mrioc
->reply_free_q
= dma_pool_zalloc(mrioc
->reply_free_q_pool
,
3290 GFP_KERNEL
, &mrioc
->reply_free_q_dma
);
3291 if (!mrioc
->reply_free_q
)
3294 /* sense buffer pool, 4 byte align */
3295 sz
= mrioc
->num_sense_bufs
* MPI3MR_SENSE_BUF_SZ
;
3296 mrioc
->sense_buf_pool
= dma_pool_create("sense_buf pool",
3297 &mrioc
->pdev
->dev
, sz
, 4, 0);
3298 if (!mrioc
->sense_buf_pool
) {
3299 ioc_err(mrioc
, "sense_buf pool: dma_pool_create failed\n");
3302 mrioc
->sense_buf
= dma_pool_zalloc(mrioc
->sense_buf_pool
, GFP_KERNEL
,
3303 &mrioc
->sense_buf_dma
);
3304 if (!mrioc
->sense_buf
)
3307 /* sense buffer queue, 8 byte align */
3308 sz
= mrioc
->sense_buf_q_sz
* 8;
3309 mrioc
->sense_buf_q_pool
= dma_pool_create("sense_buf_q pool",
3310 &mrioc
->pdev
->dev
, sz
, 8, 0);
3311 if (!mrioc
->sense_buf_q_pool
) {
3312 ioc_err(mrioc
, "sense_buf_q pool: dma_pool_create failed\n");
3315 mrioc
->sense_buf_q
= dma_pool_zalloc(mrioc
->sense_buf_q_pool
,
3316 GFP_KERNEL
, &mrioc
->sense_buf_q_dma
);
3317 if (!mrioc
->sense_buf_q
)
3328 * mpimr_initialize_reply_sbuf_queues - initialize reply sense
3330 * @mrioc: Adapter instance reference
3332 * Helper function to initialize reply and sense buffers along
3333 * with some debug prints.
3337 static void mpimr_initialize_reply_sbuf_queues(struct mpi3mr_ioc
*mrioc
)
3340 dma_addr_t phy_addr
;
3342 sz
= mrioc
->num_reply_bufs
* mrioc
->reply_sz
;
3344 "reply buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3345 mrioc
->reply_buf
, mrioc
->num_reply_bufs
, mrioc
->reply_sz
,
3346 (sz
/ 1024), (unsigned long long)mrioc
->reply_buf_dma
);
3347 sz
= mrioc
->reply_free_qsz
* 8;
3349 "reply_free_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), reply_dma(0x%llx)\n",
3350 mrioc
->reply_free_q
, mrioc
->reply_free_qsz
, 8, (sz
/ 1024),
3351 (unsigned long long)mrioc
->reply_free_q_dma
);
3352 sz
= mrioc
->num_sense_bufs
* MPI3MR_SENSE_BUF_SZ
;
3354 "sense_buf pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3355 mrioc
->sense_buf
, mrioc
->num_sense_bufs
, MPI3MR_SENSE_BUF_SZ
,
3356 (sz
/ 1024), (unsigned long long)mrioc
->sense_buf_dma
);
3357 sz
= mrioc
->sense_buf_q_sz
* 8;
3359 "sense_buf_q pool(0x%p): depth(%d), frame_size(%d), pool_size(%d kB), sense_dma(0x%llx)\n",
3360 mrioc
->sense_buf_q
, mrioc
->sense_buf_q_sz
, 8, (sz
/ 1024),
3361 (unsigned long long)mrioc
->sense_buf_q_dma
);
3363 /* initialize Reply buffer Queue */
3364 for (i
= 0, phy_addr
= mrioc
->reply_buf_dma
;
3365 i
< mrioc
->num_reply_bufs
; i
++, phy_addr
+= mrioc
->reply_sz
)
3366 mrioc
->reply_free_q
[i
] = cpu_to_le64(phy_addr
);
3367 mrioc
->reply_free_q
[i
] = cpu_to_le64(0);
3369 /* initialize Sense Buffer Queue */
3370 for (i
= 0, phy_addr
= mrioc
->sense_buf_dma
;
3371 i
< mrioc
->num_sense_bufs
; i
++, phy_addr
+= MPI3MR_SENSE_BUF_SZ
)
3372 mrioc
->sense_buf_q
[i
] = cpu_to_le64(phy_addr
);
3373 mrioc
->sense_buf_q
[i
] = cpu_to_le64(0);
3377 * mpi3mr_issue_iocinit - Send IOC Init
3378 * @mrioc: Adapter instance reference
3380 * Issue IOC Init MPI request through admin queue and wait for
3381 * the completion of it or time out.
3383 * Return: 0 on success, non-zero on failures.
3385 static int mpi3mr_issue_iocinit(struct mpi3mr_ioc
*mrioc
)
3387 struct mpi3_ioc_init_request iocinit_req
;
3388 struct mpi3_driver_info_layout
*drv_info
;
3389 dma_addr_t data_dma
;
3390 u32 data_len
= sizeof(*drv_info
);
3392 ktime_t current_time
;
3394 drv_info
= dma_alloc_coherent(&mrioc
->pdev
->dev
, data_len
, &data_dma
,
3400 mpimr_initialize_reply_sbuf_queues(mrioc
);
3402 drv_info
->information_length
= cpu_to_le32(data_len
);
3403 strscpy(drv_info
->driver_signature
, "Broadcom", sizeof(drv_info
->driver_signature
));
3404 strscpy(drv_info
->os_name
, utsname()->sysname
, sizeof(drv_info
->os_name
));
3405 strscpy(drv_info
->os_version
, utsname()->release
, sizeof(drv_info
->os_version
));
3406 strscpy(drv_info
->driver_name
, MPI3MR_DRIVER_NAME
, sizeof(drv_info
->driver_name
));
3407 strscpy(drv_info
->driver_version
, MPI3MR_DRIVER_VERSION
, sizeof(drv_info
->driver_version
));
3408 strscpy(drv_info
->driver_release_date
, MPI3MR_DRIVER_RELDATE
,
3409 sizeof(drv_info
->driver_release_date
));
3410 drv_info
->driver_capabilities
= 0;
3411 memcpy((u8
*)&mrioc
->driver_info
, (u8
*)drv_info
,
3412 sizeof(mrioc
->driver_info
));
3414 memset(&iocinit_req
, 0, sizeof(iocinit_req
));
3415 mutex_lock(&mrioc
->init_cmds
.mutex
);
3416 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
3418 ioc_err(mrioc
, "Issue IOCInit: Init command is in use\n");
3419 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3422 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
3423 mrioc
->init_cmds
.is_waiting
= 1;
3424 mrioc
->init_cmds
.callback
= NULL
;
3425 iocinit_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
3426 iocinit_req
.function
= MPI3_FUNCTION_IOC_INIT
;
3427 iocinit_req
.mpi_version
.mpi3_version
.dev
= MPI3_VERSION_DEV
;
3428 iocinit_req
.mpi_version
.mpi3_version
.unit
= MPI3_VERSION_UNIT
;
3429 iocinit_req
.mpi_version
.mpi3_version
.major
= MPI3_VERSION_MAJOR
;
3430 iocinit_req
.mpi_version
.mpi3_version
.minor
= MPI3_VERSION_MINOR
;
3431 iocinit_req
.who_init
= MPI3_WHOINIT_HOST_DRIVER
;
3432 iocinit_req
.reply_free_queue_depth
= cpu_to_le16(mrioc
->reply_free_qsz
);
3433 iocinit_req
.reply_free_queue_address
=
3434 cpu_to_le64(mrioc
->reply_free_q_dma
);
3435 iocinit_req
.sense_buffer_length
= cpu_to_le16(MPI3MR_SENSE_BUF_SZ
);
3436 iocinit_req
.sense_buffer_free_queue_depth
=
3437 cpu_to_le16(mrioc
->sense_buf_q_sz
);
3438 iocinit_req
.sense_buffer_free_queue_address
=
3439 cpu_to_le64(mrioc
->sense_buf_q_dma
);
3440 iocinit_req
.driver_information_address
= cpu_to_le64(data_dma
);
3442 current_time
= ktime_get_real();
3443 iocinit_req
.time_stamp
= cpu_to_le64(ktime_to_ms(current_time
));
3445 iocinit_req
.msg_flags
|=
3446 MPI3_IOCINIT_MSGFLAGS_SCSIIOSTATUSREPLY_SUPPORTED
;
3447 iocinit_req
.msg_flags
|=
3448 MPI3_IOCINIT_MSGFLAGS_WRITESAMEDIVERT_SUPPORTED
;
3450 init_completion(&mrioc
->init_cmds
.done
);
3451 retval
= mpi3mr_admin_request_post(mrioc
, &iocinit_req
,
3452 sizeof(iocinit_req
), 1);
3454 ioc_err(mrioc
, "Issue IOCInit: Admin Post failed\n");
3457 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
3458 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
3459 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
3460 mpi3mr_check_rh_fault_ioc(mrioc
,
3461 MPI3MR_RESET_FROM_IOCINIT_TIMEOUT
);
3462 ioc_err(mrioc
, "ioc_init timed out\n");
3466 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
3467 != MPI3_IOCSTATUS_SUCCESS
) {
3469 "Issue IOCInit: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3470 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
3471 mrioc
->init_cmds
.ioc_loginfo
);
3476 mrioc
->reply_free_queue_host_index
= mrioc
->num_reply_bufs
;
3477 writel(mrioc
->reply_free_queue_host_index
,
3478 &mrioc
->sysif_regs
->reply_free_host_index
);
3480 mrioc
->sbq_host_index
= mrioc
->num_sense_bufs
;
3481 writel(mrioc
->sbq_host_index
,
3482 &mrioc
->sysif_regs
->sense_buffer_free_host_index
);
3484 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
3485 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3489 dma_free_coherent(&mrioc
->pdev
->dev
, data_len
, drv_info
,
3496 * mpi3mr_unmask_events - Unmask events in event mask bitmap
3497 * @mrioc: Adapter instance reference
3498 * @event: MPI event ID
3500 * Un mask the specific event by resetting the event_mask
3503 * Return: 0 on success, non-zero on failures.
3505 static void mpi3mr_unmask_events(struct mpi3mr_ioc
*mrioc
, u16 event
)
3513 desired_event
= (1 << (event
% 32));
3516 mrioc
->event_masks
[word
] &= ~desired_event
;
3520 * mpi3mr_issue_event_notification - Send event notification
3521 * @mrioc: Adapter instance reference
3523 * Issue event notification MPI request through admin queue and
3524 * wait for the completion of it or time out.
3526 * Return: 0 on success, non-zero on failures.
3528 static int mpi3mr_issue_event_notification(struct mpi3mr_ioc
*mrioc
)
3530 struct mpi3_event_notification_request evtnotify_req
;
3534 memset(&evtnotify_req
, 0, sizeof(evtnotify_req
));
3535 mutex_lock(&mrioc
->init_cmds
.mutex
);
3536 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
3538 ioc_err(mrioc
, "Issue EvtNotify: Init command is in use\n");
3539 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3542 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
3543 mrioc
->init_cmds
.is_waiting
= 1;
3544 mrioc
->init_cmds
.callback
= NULL
;
3545 evtnotify_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
3546 evtnotify_req
.function
= MPI3_FUNCTION_EVENT_NOTIFICATION
;
3547 for (i
= 0; i
< MPI3_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
3548 evtnotify_req
.event_masks
[i
] =
3549 cpu_to_le32(mrioc
->event_masks
[i
]);
3550 init_completion(&mrioc
->init_cmds
.done
);
3551 retval
= mpi3mr_admin_request_post(mrioc
, &evtnotify_req
,
3552 sizeof(evtnotify_req
), 1);
3554 ioc_err(mrioc
, "Issue EvtNotify: Admin Post failed\n");
3557 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
3558 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
3559 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
3560 ioc_err(mrioc
, "event notification timed out\n");
3561 mpi3mr_check_rh_fault_ioc(mrioc
,
3562 MPI3MR_RESET_FROM_EVTNOTIFY_TIMEOUT
);
3566 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
3567 != MPI3_IOCSTATUS_SUCCESS
) {
3569 "Issue EvtNotify: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3570 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
3571 mrioc
->init_cmds
.ioc_loginfo
);
3577 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
3578 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3584 * mpi3mr_process_event_ack - Process event acknowledgment
3585 * @mrioc: Adapter instance reference
3586 * @event: MPI3 event ID
3587 * @event_ctx: event context
3589 * Send event acknowledgment through admin queue and wait for
3592 * Return: 0 on success, non-zero on failures.
3594 int mpi3mr_process_event_ack(struct mpi3mr_ioc
*mrioc
, u8 event
,
3597 struct mpi3_event_ack_request evtack_req
;
3600 memset(&evtack_req
, 0, sizeof(evtack_req
));
3601 mutex_lock(&mrioc
->init_cmds
.mutex
);
3602 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
3604 ioc_err(mrioc
, "Send EvtAck: Init command is in use\n");
3605 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3608 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
3609 mrioc
->init_cmds
.is_waiting
= 1;
3610 mrioc
->init_cmds
.callback
= NULL
;
3611 evtack_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
3612 evtack_req
.function
= MPI3_FUNCTION_EVENT_ACK
;
3613 evtack_req
.event
= event
;
3614 evtack_req
.event_context
= cpu_to_le32(event_ctx
);
3616 init_completion(&mrioc
->init_cmds
.done
);
3617 retval
= mpi3mr_admin_request_post(mrioc
, &evtack_req
,
3618 sizeof(evtack_req
), 1);
3620 ioc_err(mrioc
, "Send EvtAck: Admin Post failed\n");
3623 wait_for_completion_timeout(&mrioc
->init_cmds
.done
,
3624 (MPI3MR_INTADMCMD_TIMEOUT
* HZ
));
3625 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
3626 ioc_err(mrioc
, "Issue EvtNotify: command timed out\n");
3627 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_RESET
))
3628 mpi3mr_check_rh_fault_ioc(mrioc
,
3629 MPI3MR_RESET_FROM_EVTACK_TIMEOUT
);
3633 if ((mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
)
3634 != MPI3_IOCSTATUS_SUCCESS
) {
3636 "Send EvtAck: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
3637 (mrioc
->init_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
),
3638 mrioc
->init_cmds
.ioc_loginfo
);
3644 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
3645 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3651 * mpi3mr_alloc_chain_bufs - Allocate chain buffers
3652 * @mrioc: Adapter instance reference
3654 * Allocate chain buffers and set a bitmap to indicate free
3655 * chain buffers. Chain buffers are used to pass the SGE
3656 * information along with MPI3 SCSI IO requests for host I/O.
3658 * Return: 0 on success, non-zero on failure
3660 static int mpi3mr_alloc_chain_bufs(struct mpi3mr_ioc
*mrioc
)
3666 if (mrioc
->chain_sgl_list
)
3669 num_chains
= mrioc
->max_host_ios
/ MPI3MR_CHAINBUF_FACTOR
;
3671 if (prot_mask
& (SHOST_DIX_TYPE0_PROTECTION
3672 | SHOST_DIX_TYPE1_PROTECTION
3673 | SHOST_DIX_TYPE2_PROTECTION
3674 | SHOST_DIX_TYPE3_PROTECTION
))
3675 num_chains
+= (num_chains
/ MPI3MR_CHAINBUFDIX_FACTOR
);
3677 mrioc
->chain_buf_count
= num_chains
;
3678 sz
= sizeof(struct chain_element
) * num_chains
;
3679 mrioc
->chain_sgl_list
= kzalloc(sz
, GFP_KERNEL
);
3680 if (!mrioc
->chain_sgl_list
)
3683 if (mrioc
->max_sgl_entries
> (mrioc
->facts
.max_data_length
/
3684 MPI3MR_PAGE_SIZE_4K
))
3685 mrioc
->max_sgl_entries
= mrioc
->facts
.max_data_length
/
3686 MPI3MR_PAGE_SIZE_4K
;
3687 sz
= mrioc
->max_sgl_entries
* sizeof(struct mpi3_sge_common
);
3688 ioc_info(mrioc
, "number of sgl entries=%d chain buffer size=%dKB\n",
3689 mrioc
->max_sgl_entries
, sz
/1024);
3691 mrioc
->chain_buf_pool
= dma_pool_create("chain_buf pool",
3692 &mrioc
->pdev
->dev
, sz
, 16, 0);
3693 if (!mrioc
->chain_buf_pool
) {
3694 ioc_err(mrioc
, "chain buf pool: dma_pool_create failed\n");
3698 for (i
= 0; i
< num_chains
; i
++) {
3699 mrioc
->chain_sgl_list
[i
].addr
=
3700 dma_pool_zalloc(mrioc
->chain_buf_pool
, GFP_KERNEL
,
3701 &mrioc
->chain_sgl_list
[i
].dma_addr
);
3703 if (!mrioc
->chain_sgl_list
[i
].addr
)
3706 mrioc
->chain_bitmap
= bitmap_zalloc(num_chains
, GFP_KERNEL
);
3707 if (!mrioc
->chain_bitmap
)
3716 * mpi3mr_port_enable_complete - Mark port enable complete
3717 * @mrioc: Adapter instance reference
3718 * @drv_cmd: Internal command tracker
3720 * Call back for asynchronous port enable request sets the
3721 * driver command to indicate port enable request is complete.
3725 static void mpi3mr_port_enable_complete(struct mpi3mr_ioc
*mrioc
,
3726 struct mpi3mr_drv_cmd
*drv_cmd
)
3728 drv_cmd
->callback
= NULL
;
3729 mrioc
->scan_started
= 0;
3730 if (drv_cmd
->state
& MPI3MR_CMD_RESET
)
3731 mrioc
->scan_failed
= MPI3_IOCSTATUS_INTERNAL_ERROR
;
3733 mrioc
->scan_failed
= drv_cmd
->ioc_status
;
3734 drv_cmd
->state
= MPI3MR_CMD_NOTUSED
;
3738 * mpi3mr_issue_port_enable - Issue Port Enable
3739 * @mrioc: Adapter instance reference
3740 * @async: Flag to wait for completion or not
3742 * Issue Port Enable MPI request through admin queue and if the
3743 * async flag is not set wait for the completion of the port
3744 * enable or time out.
3746 * Return: 0 on success, non-zero on failures.
3748 int mpi3mr_issue_port_enable(struct mpi3mr_ioc
*mrioc
, u8 async
)
3750 struct mpi3_port_enable_request pe_req
;
3752 u32 pe_timeout
= MPI3MR_PORTENABLE_TIMEOUT
;
3754 memset(&pe_req
, 0, sizeof(pe_req
));
3755 mutex_lock(&mrioc
->init_cmds
.mutex
);
3756 if (mrioc
->init_cmds
.state
& MPI3MR_CMD_PENDING
) {
3758 ioc_err(mrioc
, "Issue PortEnable: Init command is in use\n");
3759 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3762 mrioc
->init_cmds
.state
= MPI3MR_CMD_PENDING
;
3764 mrioc
->init_cmds
.is_waiting
= 0;
3765 mrioc
->init_cmds
.callback
= mpi3mr_port_enable_complete
;
3767 mrioc
->init_cmds
.is_waiting
= 1;
3768 mrioc
->init_cmds
.callback
= NULL
;
3769 init_completion(&mrioc
->init_cmds
.done
);
3771 pe_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_INITCMDS
);
3772 pe_req
.function
= MPI3_FUNCTION_PORT_ENABLE
;
3774 retval
= mpi3mr_admin_request_post(mrioc
, &pe_req
, sizeof(pe_req
), 1);
3776 ioc_err(mrioc
, "Issue PortEnable: Admin Post failed\n");
3780 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3784 wait_for_completion_timeout(&mrioc
->init_cmds
.done
, (pe_timeout
* HZ
));
3785 if (!(mrioc
->init_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
3786 ioc_err(mrioc
, "port enable timed out\n");
3788 mpi3mr_check_rh_fault_ioc(mrioc
, MPI3MR_RESET_FROM_PE_TIMEOUT
);
3791 mpi3mr_port_enable_complete(mrioc
, &mrioc
->init_cmds
);
3794 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
3795 mutex_unlock(&mrioc
->init_cmds
.mutex
);
3800 /* Protocol type to name mapper structure */
3801 static const struct {
3804 } mpi3mr_protocols
[] = {
3805 { MPI3_IOCFACTS_PROTOCOL_SCSI_INITIATOR
, "Initiator" },
3806 { MPI3_IOCFACTS_PROTOCOL_SCSI_TARGET
, "Target" },
3807 { MPI3_IOCFACTS_PROTOCOL_NVME
, "NVMe attachment" },
3810 /* Capability to name mapper structure*/
3811 static const struct {
3814 } mpi3mr_capabilities
[] = {
3815 { MPI3_IOCFACTS_CAPABILITY_RAID_SUPPORTED
, "RAID" },
3816 { MPI3_IOCFACTS_CAPABILITY_MULTIPATH_SUPPORTED
, "MultiPath" },
3820 * mpi3mr_repost_diag_bufs - repost host diag buffers
3821 * @mrioc: Adapter instance reference
3823 * repost firmware and trace diag buffers based on global
3824 * trigger flag from driver page 2
3826 * Return: 0 on success, non-zero on failures.
3828 static int mpi3mr_repost_diag_bufs(struct mpi3mr_ioc
*mrioc
)
3831 union mpi3mr_trigger_data prev_trigger_data
;
3832 struct diag_buffer_desc
*trace_hdb
= NULL
;
3833 struct diag_buffer_desc
*fw_hdb
= NULL
;
3835 bool trace_repost_needed
= false;
3836 bool fw_repost_needed
= false;
3837 u8 prev_trigger_type
;
3839 retval
= mpi3mr_refresh_trigger(mrioc
, MPI3_CONFIG_ACTION_READ_CURRENT
);
3843 trace_hdb
= mpi3mr_diag_buffer_for_type(mrioc
,
3844 MPI3_DIAG_BUFFER_TYPE_TRACE
);
3847 trace_hdb
->status
!= MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED
&&
3848 trace_hdb
->trigger_type
!= MPI3MR_HDB_TRIGGER_TYPE_GLOBAL
&&
3849 trace_hdb
->trigger_type
!= MPI3MR_HDB_TRIGGER_TYPE_ELEMENT
)
3850 trace_repost_needed
= true;
3852 fw_hdb
= mpi3mr_diag_buffer_for_type(mrioc
, MPI3_DIAG_BUFFER_TYPE_FW
);
3854 if (fw_hdb
&& fw_hdb
->status
!= MPI3MR_HDB_BUFSTATUS_NOT_ALLOCATED
&&
3855 fw_hdb
->trigger_type
!= MPI3MR_HDB_TRIGGER_TYPE_GLOBAL
&&
3856 fw_hdb
->trigger_type
!= MPI3MR_HDB_TRIGGER_TYPE_ELEMENT
)
3857 fw_repost_needed
= true;
3859 if (trace_repost_needed
|| fw_repost_needed
) {
3860 global_trigger
= le64_to_cpu(mrioc
->driver_pg2
->global_trigger
);
3861 if (global_trigger
&
3862 MPI3_DRIVER2_GLOBALTRIGGER_POST_DIAG_TRACE_DISABLED
)
3863 trace_repost_needed
= false;
3864 if (global_trigger
&
3865 MPI3_DRIVER2_GLOBALTRIGGER_POST_DIAG_FW_DISABLED
)
3866 fw_repost_needed
= false;
3869 if (trace_repost_needed
) {
3870 prev_trigger_type
= trace_hdb
->trigger_type
;
3871 memcpy(&prev_trigger_data
, &trace_hdb
->trigger_data
,
3872 sizeof(trace_hdb
->trigger_data
));
3873 retval
= mpi3mr_issue_diag_buf_post(mrioc
, trace_hdb
);
3875 dprint_init(mrioc
, "trace diag buffer reposted");
3876 mpi3mr_set_trigger_data_in_hdb(trace_hdb
,
3877 MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN
, NULL
, 1);
3879 trace_hdb
->trigger_type
= prev_trigger_type
;
3880 memcpy(&trace_hdb
->trigger_data
, &prev_trigger_data
,
3881 sizeof(prev_trigger_data
));
3882 ioc_err(mrioc
, "trace diag buffer repost failed");
3887 if (fw_repost_needed
) {
3888 prev_trigger_type
= fw_hdb
->trigger_type
;
3889 memcpy(&prev_trigger_data
, &fw_hdb
->trigger_data
,
3890 sizeof(fw_hdb
->trigger_data
));
3891 retval
= mpi3mr_issue_diag_buf_post(mrioc
, fw_hdb
);
3893 dprint_init(mrioc
, "firmware diag buffer reposted");
3894 mpi3mr_set_trigger_data_in_hdb(fw_hdb
,
3895 MPI3MR_HDB_TRIGGER_TYPE_UNKNOWN
, NULL
, 1);
3897 fw_hdb
->trigger_type
= prev_trigger_type
;
3898 memcpy(&fw_hdb
->trigger_data
, &prev_trigger_data
,
3899 sizeof(prev_trigger_data
));
3900 ioc_err(mrioc
, "firmware diag buffer repost failed");
3908 * mpi3mr_read_tsu_interval - Update time stamp interval
3909 * @mrioc: Adapter instance reference
3911 * Update time stamp interval if its defined in driver page 1,
3912 * otherwise use default value.
3917 mpi3mr_read_tsu_interval(struct mpi3mr_ioc
*mrioc
)
3919 struct mpi3_driver_page1 driver_pg1
;
3920 u16 pg_sz
= sizeof(driver_pg1
);
3923 mrioc
->ts_update_interval
= MPI3MR_TSUPDATE_INTERVAL
;
3925 retval
= mpi3mr_cfg_get_driver_pg1(mrioc
, &driver_pg1
, pg_sz
);
3926 if (!retval
&& driver_pg1
.time_stamp_update
)
3927 mrioc
->ts_update_interval
= (driver_pg1
.time_stamp_update
* 60);
3931 * mpi3mr_print_ioc_info - Display controller information
3932 * @mrioc: Adapter instance reference
3934 * Display controller personality, capability, supported
3940 mpi3mr_print_ioc_info(struct mpi3mr_ioc
*mrioc
)
3942 int i
= 0, bytes_written
= 0;
3943 const char *personality
;
3944 char protocol
[50] = {0};
3945 char capabilities
[100] = {0};
3946 struct mpi3mr_compimg_ver
*fwver
= &mrioc
->facts
.fw_ver
;
3948 switch (mrioc
->facts
.personality
) {
3949 case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA
:
3950 personality
= "Enhanced HBA";
3952 case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR
:
3953 personality
= "RAID";
3956 personality
= "Unknown";
3960 ioc_info(mrioc
, "Running in %s Personality", personality
);
3962 ioc_info(mrioc
, "FW version(%d.%d.%d.%d.%d.%d)\n",
3963 fwver
->gen_major
, fwver
->gen_minor
, fwver
->ph_major
,
3964 fwver
->ph_minor
, fwver
->cust_id
, fwver
->build_num
);
3966 for (i
= 0; i
< ARRAY_SIZE(mpi3mr_protocols
); i
++) {
3967 if (mrioc
->facts
.protocol_flags
&
3968 mpi3mr_protocols
[i
].protocol
) {
3969 bytes_written
+= scnprintf(protocol
+ bytes_written
,
3970 sizeof(protocol
) - bytes_written
, "%s%s",
3971 bytes_written
? "," : "",
3972 mpi3mr_protocols
[i
].name
);
3977 for (i
= 0; i
< ARRAY_SIZE(mpi3mr_capabilities
); i
++) {
3978 if (mrioc
->facts
.protocol_flags
&
3979 mpi3mr_capabilities
[i
].capability
) {
3980 bytes_written
+= scnprintf(capabilities
+ bytes_written
,
3981 sizeof(capabilities
) - bytes_written
, "%s%s",
3982 bytes_written
? "," : "",
3983 mpi3mr_capabilities
[i
].name
);
3987 ioc_info(mrioc
, "Protocol=(%s), Capabilities=(%s)\n",
3988 protocol
, capabilities
);
3992 * mpi3mr_cleanup_resources - Free PCI resources
3993 * @mrioc: Adapter instance reference
3995 * Unmap PCI device memory and disable PCI device.
3997 * Return: 0 on success and non-zero on failure.
3999 void mpi3mr_cleanup_resources(struct mpi3mr_ioc
*mrioc
)
4001 struct pci_dev
*pdev
= mrioc
->pdev
;
4003 mpi3mr_cleanup_isr(mrioc
);
4005 if (mrioc
->sysif_regs
) {
4006 iounmap((void __iomem
*)mrioc
->sysif_regs
);
4007 mrioc
->sysif_regs
= NULL
;
4010 if (pci_is_enabled(pdev
)) {
4012 pci_release_selected_regions(pdev
, mrioc
->bars
);
4013 pci_disable_device(pdev
);
4018 * mpi3mr_setup_resources - Enable PCI resources
4019 * @mrioc: Adapter instance reference
4021 * Enable PCI device memory, MSI-x registers and set DMA mask.
4023 * Return: 0 on success and non-zero on failure.
4025 int mpi3mr_setup_resources(struct mpi3mr_ioc
*mrioc
)
4027 struct pci_dev
*pdev
= mrioc
->pdev
;
4029 int i
, retval
= 0, capb
= 0;
4030 u16 message_control
;
4031 u64 dma_mask
= mrioc
->dma_mask
? mrioc
->dma_mask
:
4032 ((sizeof(dma_addr_t
) > 4) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
4034 if (pci_enable_device_mem(pdev
)) {
4035 ioc_err(mrioc
, "pci_enable_device_mem: failed\n");
4040 capb
= pci_find_capability(pdev
, PCI_CAP_ID_MSIX
);
4042 ioc_err(mrioc
, "Unable to find MSI-X Capabilities\n");
4046 mrioc
->bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4048 if (pci_request_selected_regions(pdev
, mrioc
->bars
,
4049 mrioc
->driver_name
)) {
4050 ioc_err(mrioc
, "pci_request_selected_regions: failed\n");
4055 for (i
= 0; (i
< DEVICE_COUNT_RESOURCE
); i
++) {
4056 if (pci_resource_flags(pdev
, i
) & IORESOURCE_MEM
) {
4057 mrioc
->sysif_regs_phys
= pci_resource_start(pdev
, i
);
4058 memap_sz
= pci_resource_len(pdev
, i
);
4060 ioremap(mrioc
->sysif_regs_phys
, memap_sz
);
4065 pci_set_master(pdev
);
4067 retval
= dma_set_mask_and_coherent(&pdev
->dev
, dma_mask
);
4069 if (dma_mask
!= DMA_BIT_MASK(32)) {
4070 ioc_warn(mrioc
, "Setting 64 bit DMA mask failed\n");
4071 dma_mask
= DMA_BIT_MASK(32);
4072 retval
= dma_set_mask_and_coherent(&pdev
->dev
,
4076 mrioc
->dma_mask
= 0;
4077 ioc_err(mrioc
, "Setting 32 bit DMA mask also failed\n");
4081 mrioc
->dma_mask
= dma_mask
;
4083 if (!mrioc
->sysif_regs
) {
4085 "Unable to map adapter memory or resource not found\n");
4090 pci_read_config_word(pdev
, capb
+ 2, &message_control
);
4091 mrioc
->msix_count
= (message_control
& 0x3FF) + 1;
4093 pci_save_state(pdev
);
4095 pci_set_drvdata(pdev
, mrioc
->shost
);
4097 mpi3mr_ioc_disable_intr(mrioc
);
4099 ioc_info(mrioc
, "iomem(0x%016llx), mapped(0x%p), size(%d)\n",
4100 (unsigned long long)mrioc
->sysif_regs_phys
,
4101 mrioc
->sysif_regs
, memap_sz
);
4102 ioc_info(mrioc
, "Number of MSI-X vectors found in capabilities: (%d)\n",
4105 if (!reset_devices
&& poll_queues
> 0)
4106 mrioc
->requested_poll_qcount
= min_t(int, poll_queues
,
4107 mrioc
->msix_count
- 2);
4111 mpi3mr_cleanup_resources(mrioc
);
4116 * mpi3mr_enable_events - Enable required events
4117 * @mrioc: Adapter instance reference
4119 * This routine unmasks the events required by the driver by
4120 * sennding appropriate event mask bitmapt through an event
4121 * notification request.
4123 * Return: 0 on success and non-zero on failure.
4125 static int mpi3mr_enable_events(struct mpi3mr_ioc
*mrioc
)
4130 for (i
= 0; i
< MPI3_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
4131 mrioc
->event_masks
[i
] = -1;
4133 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_DEVICE_ADDED
);
4134 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_DEVICE_INFO_CHANGED
);
4135 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_DEVICE_STATUS_CHANGE
);
4136 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_ENCL_DEVICE_STATUS_CHANGE
);
4137 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_ENCL_DEVICE_ADDED
);
4138 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_SAS_TOPOLOGY_CHANGE_LIST
);
4139 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_SAS_DISCOVERY
);
4140 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_SAS_DEVICE_DISCOVERY_ERROR
);
4141 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_SAS_BROADCAST_PRIMITIVE
);
4142 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_PCIE_TOPOLOGY_CHANGE_LIST
);
4143 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_PCIE_ENUMERATION
);
4144 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_PREPARE_FOR_RESET
);
4145 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_CABLE_MGMT
);
4146 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_ENERGY_PACK_CHANGE
);
4147 mpi3mr_unmask_events(mrioc
, MPI3_EVENT_DIAGNOSTIC_BUFFER_STATUS_CHANGE
);
4149 retval
= mpi3mr_issue_event_notification(mrioc
);
4151 ioc_err(mrioc
, "failed to issue event notification %d\n",
4157 * mpi3mr_init_ioc - Initialize the controller
4158 * @mrioc: Adapter instance reference
4160 * This the controller initialization routine, executed either
4161 * after soft reset or from pci probe callback.
4162 * Setup the required resources, memory map the controller
4163 * registers, create admin and operational reply queue pairs,
4164 * allocate required memory for reply pool, sense buffer pool,
4165 * issue IOC init request to the firmware, unmask the events and
4166 * issue port enable to discover SAS/SATA/NVMe devies and RAID
4169 * Return: 0 on success and non-zero on failure.
4171 int mpi3mr_init_ioc(struct mpi3mr_ioc
*mrioc
)
4175 struct mpi3_ioc_facts_data facts_data
;
4179 retval
= mpi3mr_bring_ioc_ready(mrioc
);
4181 ioc_err(mrioc
, "Failed to bring ioc ready: error %d\n",
4183 goto out_failed_noretry
;
4186 retval
= mpi3mr_setup_isr(mrioc
, 1);
4188 ioc_err(mrioc
, "Failed to setup ISR error %d\n",
4190 goto out_failed_noretry
;
4193 retval
= mpi3mr_issue_iocfacts(mrioc
, &facts_data
);
4195 ioc_err(mrioc
, "Failed to Issue IOC Facts %d\n",
4200 mrioc
->max_host_ios
= mrioc
->facts
.max_reqs
- MPI3MR_INTERNAL_CMDS_RESVD
;
4201 mrioc
->shost
->max_sectors
= mrioc
->facts
.max_data_length
/ 512;
4202 mrioc
->num_io_throttle_group
= mrioc
->facts
.max_io_throttle_group
;
4203 atomic_set(&mrioc
->pend_large_data_sz
, 0);
4206 mrioc
->max_host_ios
= min_t(int, mrioc
->max_host_ios
,
4207 MPI3MR_HOST_IOS_KDUMP
);
4209 if (!(mrioc
->facts
.ioc_capabilities
&
4210 MPI3_IOCFACTS_CAPABILITY_MULTIPATH_SUPPORTED
)) {
4211 mrioc
->sas_transport_enabled
= 1;
4212 mrioc
->scsi_device_channel
= 1;
4213 mrioc
->shost
->max_channel
= 1;
4214 mrioc
->shost
->transportt
= mpi3mr_transport_template
;
4217 mrioc
->reply_sz
= mrioc
->facts
.reply_sz
;
4219 retval
= mpi3mr_check_reset_dma_mask(mrioc
);
4221 ioc_err(mrioc
, "Resetting dma mask failed %d\n",
4223 goto out_failed_noretry
;
4226 mpi3mr_read_tsu_interval(mrioc
);
4227 mpi3mr_print_ioc_info(mrioc
);
4229 dprint_init(mrioc
, "allocating host diag buffers\n");
4230 mpi3mr_alloc_diag_bufs(mrioc
);
4232 dprint_init(mrioc
, "allocating ioctl dma buffers\n");
4233 mpi3mr_alloc_ioctl_dma_memory(mrioc
);
4235 dprint_init(mrioc
, "posting host diag buffers\n");
4236 retval
= mpi3mr_post_diag_bufs(mrioc
);
4239 ioc_warn(mrioc
, "failed to post host diag buffers\n");
4241 if (!mrioc
->init_cmds
.reply
) {
4242 retval
= mpi3mr_alloc_reply_sense_bufs(mrioc
);
4245 "%s :Failed to allocated reply sense buffers %d\n",
4247 goto out_failed_noretry
;
4251 if (!mrioc
->chain_sgl_list
) {
4252 retval
= mpi3mr_alloc_chain_bufs(mrioc
);
4254 ioc_err(mrioc
, "Failed to allocated chain buffers %d\n",
4256 goto out_failed_noretry
;
4260 retval
= mpi3mr_issue_iocinit(mrioc
);
4262 ioc_err(mrioc
, "Failed to Issue IOC Init %d\n",
4267 retval
= mpi3mr_print_pkg_ver(mrioc
);
4269 ioc_err(mrioc
, "failed to get package version\n");
4273 retval
= mpi3mr_setup_isr(mrioc
, 0);
4275 ioc_err(mrioc
, "Failed to re-setup ISR, error %d\n",
4277 goto out_failed_noretry
;
4280 retval
= mpi3mr_create_op_queues(mrioc
);
4282 ioc_err(mrioc
, "Failed to create OpQueues error %d\n",
4287 if (!mrioc
->pel_seqnum_virt
) {
4288 dprint_init(mrioc
, "allocating memory for pel_seqnum_virt\n");
4289 mrioc
->pel_seqnum_sz
= sizeof(struct mpi3_pel_seq
);
4290 mrioc
->pel_seqnum_virt
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
4291 mrioc
->pel_seqnum_sz
, &mrioc
->pel_seqnum_dma
,
4293 if (!mrioc
->pel_seqnum_virt
) {
4295 goto out_failed_noretry
;
4299 if (!mrioc
->throttle_groups
&& mrioc
->num_io_throttle_group
) {
4300 dprint_init(mrioc
, "allocating memory for throttle groups\n");
4301 sz
= sizeof(struct mpi3mr_throttle_group_info
);
4302 mrioc
->throttle_groups
= kcalloc(mrioc
->num_io_throttle_group
, sz
, GFP_KERNEL
);
4303 if (!mrioc
->throttle_groups
) {
4305 goto out_failed_noretry
;
4309 retval
= mpi3mr_enable_events(mrioc
);
4311 ioc_err(mrioc
, "failed to enable events %d\n",
4316 retval
= mpi3mr_refresh_trigger(mrioc
, MPI3_CONFIG_ACTION_READ_CURRENT
);
4318 ioc_err(mrioc
, "failed to refresh triggers\n");
4322 ioc_info(mrioc
, "controller initialization completed successfully\n");
4327 ioc_warn(mrioc
, "retrying controller initialization, retry_count:%d\n",
4329 mpi3mr_memset_buffers(mrioc
);
4334 ioc_err(mrioc
, "controller initialization failed\n");
4335 mpi3mr_issue_reset(mrioc
, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
,
4336 MPI3MR_RESET_FROM_CTLR_CLEANUP
);
4337 mrioc
->unrecoverable
= 1;
4342 * mpi3mr_reinit_ioc - Re-Initialize the controller
4343 * @mrioc: Adapter instance reference
4344 * @is_resume: Called from resume or reset path
4346 * This the controller re-initialization routine, executed from
4347 * the soft reset handler or resume callback. Creates
4348 * operational reply queue pairs, allocate required memory for
4349 * reply pool, sense buffer pool, issue IOC init request to the
4350 * firmware, unmask the events and issue port enable to discover
4351 * SAS/SATA/NVMe devices and RAID volumes.
4353 * Return: 0 on success and non-zero on failure.
4355 int mpi3mr_reinit_ioc(struct mpi3mr_ioc
*mrioc
, u8 is_resume
)
4359 struct mpi3_ioc_facts_data facts_data
;
4360 u32 pe_timeout
, ioc_status
;
4364 (MPI3MR_PORTENABLE_TIMEOUT
/ MPI3MR_PORTENABLE_POLL_INTERVAL
);
4366 dprint_reset(mrioc
, "bringing up the controller to ready state\n");
4367 retval
= mpi3mr_bring_ioc_ready(mrioc
);
4369 ioc_err(mrioc
, "failed to bring to ready state\n");
4370 goto out_failed_noretry
;
4373 if (is_resume
|| mrioc
->block_on_pci_err
) {
4374 dprint_reset(mrioc
, "setting up single ISR\n");
4375 retval
= mpi3mr_setup_isr(mrioc
, 1);
4377 ioc_err(mrioc
, "failed to setup ISR\n");
4378 goto out_failed_noretry
;
4381 mpi3mr_ioc_enable_intr(mrioc
);
4383 dprint_reset(mrioc
, "getting ioc_facts\n");
4384 retval
= mpi3mr_issue_iocfacts(mrioc
, &facts_data
);
4386 ioc_err(mrioc
, "failed to get ioc_facts\n");
4390 dprint_reset(mrioc
, "validating ioc_facts\n");
4391 retval
= mpi3mr_revalidate_factsdata(mrioc
);
4393 ioc_err(mrioc
, "failed to revalidate ioc_facts data\n");
4394 goto out_failed_noretry
;
4397 mpi3mr_read_tsu_interval(mrioc
);
4398 mpi3mr_print_ioc_info(mrioc
);
4401 dprint_reset(mrioc
, "posting host diag buffers\n");
4402 retval
= mpi3mr_post_diag_bufs(mrioc
);
4404 ioc_warn(mrioc
, "failed to post host diag buffers\n");
4406 retval
= mpi3mr_repost_diag_bufs(mrioc
);
4408 ioc_warn(mrioc
, "failed to re post host diag buffers\n");
4411 dprint_reset(mrioc
, "sending ioc_init\n");
4412 retval
= mpi3mr_issue_iocinit(mrioc
);
4414 ioc_err(mrioc
, "failed to send ioc_init\n");
4418 dprint_reset(mrioc
, "getting package version\n");
4419 retval
= mpi3mr_print_pkg_ver(mrioc
);
4421 ioc_err(mrioc
, "failed to get package version\n");
4425 if (is_resume
|| mrioc
->block_on_pci_err
) {
4426 dprint_reset(mrioc
, "setting up multiple ISR\n");
4427 retval
= mpi3mr_setup_isr(mrioc
, 0);
4429 ioc_err(mrioc
, "failed to re-setup ISR\n");
4430 goto out_failed_noretry
;
4434 dprint_reset(mrioc
, "creating operational queue pairs\n");
4435 retval
= mpi3mr_create_op_queues(mrioc
);
4437 ioc_err(mrioc
, "failed to create operational queue pairs\n");
4441 if (!mrioc
->pel_seqnum_virt
) {
4442 dprint_reset(mrioc
, "allocating memory for pel_seqnum_virt\n");
4443 mrioc
->pel_seqnum_sz
= sizeof(struct mpi3_pel_seq
);
4444 mrioc
->pel_seqnum_virt
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
4445 mrioc
->pel_seqnum_sz
, &mrioc
->pel_seqnum_dma
,
4447 if (!mrioc
->pel_seqnum_virt
) {
4449 goto out_failed_noretry
;
4453 if (mrioc
->shost
->nr_hw_queues
> mrioc
->num_op_reply_q
) {
4455 "cannot create minimum number of operational queues expected:%d created:%d\n",
4456 mrioc
->shost
->nr_hw_queues
, mrioc
->num_op_reply_q
);
4458 goto out_failed_noretry
;
4461 dprint_reset(mrioc
, "enabling events\n");
4462 retval
= mpi3mr_enable_events(mrioc
);
4464 ioc_err(mrioc
, "failed to enable events\n");
4468 mrioc
->device_refresh_on
= 1;
4469 mpi3mr_add_event_wait_for_device_refresh(mrioc
);
4471 ioc_info(mrioc
, "sending port enable\n");
4472 retval
= mpi3mr_issue_port_enable(mrioc
, 1);
4474 ioc_err(mrioc
, "failed to issue port enable\n");
4478 ssleep(MPI3MR_PORTENABLE_POLL_INTERVAL
);
4479 if (mrioc
->init_cmds
.state
== MPI3MR_CMD_NOTUSED
)
4481 if (!pci_device_is_present(mrioc
->pdev
))
4482 mrioc
->unrecoverable
= 1;
4483 if (mrioc
->unrecoverable
) {
4485 goto out_failed_noretry
;
4487 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
4488 if ((ioc_status
& MPI3_SYSIF_IOC_STATUS_RESET_HISTORY
) ||
4489 (ioc_status
& MPI3_SYSIF_IOC_STATUS_FAULT
)) {
4490 mpi3mr_print_fault_info(mrioc
);
4491 mrioc
->init_cmds
.is_waiting
= 0;
4492 mrioc
->init_cmds
.callback
= NULL
;
4493 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
4496 } while (--pe_timeout
);
4499 ioc_err(mrioc
, "port enable timed out\n");
4500 mpi3mr_check_rh_fault_ioc(mrioc
,
4501 MPI3MR_RESET_FROM_PE_TIMEOUT
);
4502 mrioc
->init_cmds
.is_waiting
= 0;
4503 mrioc
->init_cmds
.callback
= NULL
;
4504 mrioc
->init_cmds
.state
= MPI3MR_CMD_NOTUSED
;
4506 } else if (mrioc
->scan_failed
) {
4508 "port enable failed with status=0x%04x\n",
4509 mrioc
->scan_failed
);
4511 ioc_info(mrioc
, "port enable completed successfully\n");
4513 ioc_info(mrioc
, "controller %s completed successfully\n",
4514 (is_resume
)?"resume":"re-initialization");
4519 ioc_warn(mrioc
, "retrying controller %s, retry_count:%d\n",
4520 (is_resume
)?"resume":"re-initialization", retry
);
4521 mpi3mr_memset_buffers(mrioc
);
4526 ioc_err(mrioc
, "controller %s is failed\n",
4527 (is_resume
)?"resume":"re-initialization");
4528 mpi3mr_issue_reset(mrioc
, MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
,
4529 MPI3MR_RESET_FROM_CTLR_CLEANUP
);
4530 mrioc
->unrecoverable
= 1;
4535 * mpi3mr_memset_op_reply_q_buffers - memset the operational reply queue's
4537 * @mrioc: Adapter instance reference
4538 * @qidx: Operational reply queue index
4542 static void mpi3mr_memset_op_reply_q_buffers(struct mpi3mr_ioc
*mrioc
, u16 qidx
)
4544 struct op_reply_qinfo
*op_reply_q
= mrioc
->op_reply_qinfo
+ qidx
;
4545 struct segments
*segments
;
4548 if (!op_reply_q
->q_segments
)
4551 size
= op_reply_q
->segment_qd
* mrioc
->op_reply_desc_sz
;
4552 segments
= op_reply_q
->q_segments
;
4553 for (i
= 0; i
< op_reply_q
->num_segments
; i
++)
4554 memset(segments
[i
].segment
, 0, size
);
4558 * mpi3mr_memset_op_req_q_buffers - memset the operational request queue's
4560 * @mrioc: Adapter instance reference
4561 * @qidx: Operational request queue index
4565 static void mpi3mr_memset_op_req_q_buffers(struct mpi3mr_ioc
*mrioc
, u16 qidx
)
4567 struct op_req_qinfo
*op_req_q
= mrioc
->req_qinfo
+ qidx
;
4568 struct segments
*segments
;
4571 if (!op_req_q
->q_segments
)
4574 size
= op_req_q
->segment_qd
* mrioc
->facts
.op_req_sz
;
4575 segments
= op_req_q
->q_segments
;
4576 for (i
= 0; i
< op_req_q
->num_segments
; i
++)
4577 memset(segments
[i
].segment
, 0, size
);
4581 * mpi3mr_memset_buffers - memset memory for a controller
4582 * @mrioc: Adapter instance reference
4584 * clear all the memory allocated for a controller, typically
4585 * called post reset to reuse the memory allocated during the
4590 void mpi3mr_memset_buffers(struct mpi3mr_ioc
*mrioc
)
4593 struct mpi3mr_throttle_group_info
*tg
;
4595 mrioc
->change_count
= 0;
4596 mrioc
->active_poll_qcount
= 0;
4597 mrioc
->default_qcount
= 0;
4598 if (mrioc
->admin_req_base
)
4599 memset(mrioc
->admin_req_base
, 0, mrioc
->admin_req_q_sz
);
4600 if (mrioc
->admin_reply_base
)
4601 memset(mrioc
->admin_reply_base
, 0, mrioc
->admin_reply_q_sz
);
4602 atomic_set(&mrioc
->admin_reply_q_in_use
, 0);
4604 if (mrioc
->init_cmds
.reply
) {
4605 memset(mrioc
->init_cmds
.reply
, 0, sizeof(*mrioc
->init_cmds
.reply
));
4606 memset(mrioc
->bsg_cmds
.reply
, 0,
4607 sizeof(*mrioc
->bsg_cmds
.reply
));
4608 memset(mrioc
->host_tm_cmds
.reply
, 0,
4609 sizeof(*mrioc
->host_tm_cmds
.reply
));
4610 memset(mrioc
->pel_cmds
.reply
, 0,
4611 sizeof(*mrioc
->pel_cmds
.reply
));
4612 memset(mrioc
->pel_abort_cmd
.reply
, 0,
4613 sizeof(*mrioc
->pel_abort_cmd
.reply
));
4614 memset(mrioc
->transport_cmds
.reply
, 0,
4615 sizeof(*mrioc
->transport_cmds
.reply
));
4616 for (i
= 0; i
< MPI3MR_NUM_DEVRMCMD
; i
++)
4617 memset(mrioc
->dev_rmhs_cmds
[i
].reply
, 0,
4618 sizeof(*mrioc
->dev_rmhs_cmds
[i
].reply
));
4619 for (i
= 0; i
< MPI3MR_NUM_EVTACKCMD
; i
++)
4620 memset(mrioc
->evtack_cmds
[i
].reply
, 0,
4621 sizeof(*mrioc
->evtack_cmds
[i
].reply
));
4622 bitmap_clear(mrioc
->removepend_bitmap
, 0,
4623 mrioc
->dev_handle_bitmap_bits
);
4624 bitmap_clear(mrioc
->devrem_bitmap
, 0, MPI3MR_NUM_DEVRMCMD
);
4625 bitmap_clear(mrioc
->evtack_cmds_bitmap
, 0,
4626 MPI3MR_NUM_EVTACKCMD
);
4629 for (i
= 0; i
< mrioc
->num_queues
; i
++) {
4630 mrioc
->op_reply_qinfo
[i
].qid
= 0;
4631 mrioc
->op_reply_qinfo
[i
].ci
= 0;
4632 mrioc
->op_reply_qinfo
[i
].num_replies
= 0;
4633 mrioc
->op_reply_qinfo
[i
].ephase
= 0;
4634 atomic_set(&mrioc
->op_reply_qinfo
[i
].pend_ios
, 0);
4635 atomic_set(&mrioc
->op_reply_qinfo
[i
].in_use
, 0);
4636 mpi3mr_memset_op_reply_q_buffers(mrioc
, i
);
4638 mrioc
->req_qinfo
[i
].ci
= 0;
4639 mrioc
->req_qinfo
[i
].pi
= 0;
4640 mrioc
->req_qinfo
[i
].num_requests
= 0;
4641 mrioc
->req_qinfo
[i
].qid
= 0;
4642 mrioc
->req_qinfo
[i
].reply_qid
= 0;
4643 spin_lock_init(&mrioc
->req_qinfo
[i
].q_lock
);
4644 mpi3mr_memset_op_req_q_buffers(mrioc
, i
);
4647 atomic_set(&mrioc
->pend_large_data_sz
, 0);
4648 if (mrioc
->throttle_groups
) {
4649 tg
= mrioc
->throttle_groups
;
4650 for (i
= 0; i
< mrioc
->num_io_throttle_group
; i
++, tg
++) {
4653 tg
->modified_qd
= 0;
4655 tg
->need_qd_reduction
= 0;
4658 tg
->qd_reduction
= 0;
4659 atomic_set(&tg
->pend_large_data_sz
, 0);
4665 * mpi3mr_free_mem - Free memory allocated for a controller
4666 * @mrioc: Adapter instance reference
4668 * Free all the memory allocated for a controller.
4672 void mpi3mr_free_mem(struct mpi3mr_ioc
*mrioc
)
4675 struct mpi3mr_intr_info
*intr_info
;
4676 struct diag_buffer_desc
*diag_buffer
;
4678 mpi3mr_free_enclosure_list(mrioc
);
4679 mpi3mr_free_ioctl_dma_memory(mrioc
);
4681 if (mrioc
->sense_buf_pool
) {
4682 if (mrioc
->sense_buf
)
4683 dma_pool_free(mrioc
->sense_buf_pool
, mrioc
->sense_buf
,
4684 mrioc
->sense_buf_dma
);
4685 dma_pool_destroy(mrioc
->sense_buf_pool
);
4686 mrioc
->sense_buf
= NULL
;
4687 mrioc
->sense_buf_pool
= NULL
;
4689 if (mrioc
->sense_buf_q_pool
) {
4690 if (mrioc
->sense_buf_q
)
4691 dma_pool_free(mrioc
->sense_buf_q_pool
,
4692 mrioc
->sense_buf_q
, mrioc
->sense_buf_q_dma
);
4693 dma_pool_destroy(mrioc
->sense_buf_q_pool
);
4694 mrioc
->sense_buf_q
= NULL
;
4695 mrioc
->sense_buf_q_pool
= NULL
;
4698 if (mrioc
->reply_buf_pool
) {
4699 if (mrioc
->reply_buf
)
4700 dma_pool_free(mrioc
->reply_buf_pool
, mrioc
->reply_buf
,
4701 mrioc
->reply_buf_dma
);
4702 dma_pool_destroy(mrioc
->reply_buf_pool
);
4703 mrioc
->reply_buf
= NULL
;
4704 mrioc
->reply_buf_pool
= NULL
;
4706 if (mrioc
->reply_free_q_pool
) {
4707 if (mrioc
->reply_free_q
)
4708 dma_pool_free(mrioc
->reply_free_q_pool
,
4709 mrioc
->reply_free_q
, mrioc
->reply_free_q_dma
);
4710 dma_pool_destroy(mrioc
->reply_free_q_pool
);
4711 mrioc
->reply_free_q
= NULL
;
4712 mrioc
->reply_free_q_pool
= NULL
;
4715 for (i
= 0; i
< mrioc
->num_op_req_q
; i
++)
4716 mpi3mr_free_op_req_q_segments(mrioc
, i
);
4718 for (i
= 0; i
< mrioc
->num_op_reply_q
; i
++)
4719 mpi3mr_free_op_reply_q_segments(mrioc
, i
);
4721 for (i
= 0; i
< mrioc
->intr_info_count
; i
++) {
4722 intr_info
= mrioc
->intr_info
+ i
;
4723 intr_info
->op_reply_q
= NULL
;
4726 kfree(mrioc
->req_qinfo
);
4727 mrioc
->req_qinfo
= NULL
;
4728 mrioc
->num_op_req_q
= 0;
4730 kfree(mrioc
->op_reply_qinfo
);
4731 mrioc
->op_reply_qinfo
= NULL
;
4732 mrioc
->num_op_reply_q
= 0;
4734 kfree(mrioc
->init_cmds
.reply
);
4735 mrioc
->init_cmds
.reply
= NULL
;
4737 kfree(mrioc
->bsg_cmds
.reply
);
4738 mrioc
->bsg_cmds
.reply
= NULL
;
4740 kfree(mrioc
->host_tm_cmds
.reply
);
4741 mrioc
->host_tm_cmds
.reply
= NULL
;
4743 kfree(mrioc
->pel_cmds
.reply
);
4744 mrioc
->pel_cmds
.reply
= NULL
;
4746 kfree(mrioc
->pel_abort_cmd
.reply
);
4747 mrioc
->pel_abort_cmd
.reply
= NULL
;
4749 for (i
= 0; i
< MPI3MR_NUM_EVTACKCMD
; i
++) {
4750 kfree(mrioc
->evtack_cmds
[i
].reply
);
4751 mrioc
->evtack_cmds
[i
].reply
= NULL
;
4754 bitmap_free(mrioc
->removepend_bitmap
);
4755 mrioc
->removepend_bitmap
= NULL
;
4757 bitmap_free(mrioc
->devrem_bitmap
);
4758 mrioc
->devrem_bitmap
= NULL
;
4760 bitmap_free(mrioc
->evtack_cmds_bitmap
);
4761 mrioc
->evtack_cmds_bitmap
= NULL
;
4763 bitmap_free(mrioc
->chain_bitmap
);
4764 mrioc
->chain_bitmap
= NULL
;
4766 kfree(mrioc
->transport_cmds
.reply
);
4767 mrioc
->transport_cmds
.reply
= NULL
;
4769 for (i
= 0; i
< MPI3MR_NUM_DEVRMCMD
; i
++) {
4770 kfree(mrioc
->dev_rmhs_cmds
[i
].reply
);
4771 mrioc
->dev_rmhs_cmds
[i
].reply
= NULL
;
4774 if (mrioc
->chain_buf_pool
) {
4775 for (i
= 0; i
< mrioc
->chain_buf_count
; i
++) {
4776 if (mrioc
->chain_sgl_list
[i
].addr
) {
4777 dma_pool_free(mrioc
->chain_buf_pool
,
4778 mrioc
->chain_sgl_list
[i
].addr
,
4779 mrioc
->chain_sgl_list
[i
].dma_addr
);
4780 mrioc
->chain_sgl_list
[i
].addr
= NULL
;
4783 dma_pool_destroy(mrioc
->chain_buf_pool
);
4784 mrioc
->chain_buf_pool
= NULL
;
4787 kfree(mrioc
->chain_sgl_list
);
4788 mrioc
->chain_sgl_list
= NULL
;
4790 if (mrioc
->admin_reply_base
) {
4791 dma_free_coherent(&mrioc
->pdev
->dev
, mrioc
->admin_reply_q_sz
,
4792 mrioc
->admin_reply_base
, mrioc
->admin_reply_dma
);
4793 mrioc
->admin_reply_base
= NULL
;
4795 if (mrioc
->admin_req_base
) {
4796 dma_free_coherent(&mrioc
->pdev
->dev
, mrioc
->admin_req_q_sz
,
4797 mrioc
->admin_req_base
, mrioc
->admin_req_dma
);
4798 mrioc
->admin_req_base
= NULL
;
4801 if (mrioc
->pel_seqnum_virt
) {
4802 dma_free_coherent(&mrioc
->pdev
->dev
, mrioc
->pel_seqnum_sz
,
4803 mrioc
->pel_seqnum_virt
, mrioc
->pel_seqnum_dma
);
4804 mrioc
->pel_seqnum_virt
= NULL
;
4807 for (i
= 0; i
< MPI3MR_MAX_NUM_HDB
; i
++) {
4808 diag_buffer
= &mrioc
->diag_buffers
[i
];
4809 if (diag_buffer
->addr
) {
4810 dma_free_coherent(&mrioc
->pdev
->dev
,
4811 diag_buffer
->size
, diag_buffer
->addr
,
4812 diag_buffer
->dma_addr
);
4813 diag_buffer
->addr
= NULL
;
4814 diag_buffer
->size
= 0;
4815 diag_buffer
->type
= 0;
4816 diag_buffer
->status
= 0;
4820 kfree(mrioc
->throttle_groups
);
4821 mrioc
->throttle_groups
= NULL
;
4823 kfree(mrioc
->logdata_buf
);
4824 mrioc
->logdata_buf
= NULL
;
4829 * mpi3mr_issue_ioc_shutdown - shutdown controller
4830 * @mrioc: Adapter instance reference
4832 * Send shutodwn notification to the controller and wait for the
4833 * shutdown_timeout for it to be completed.
4837 static void mpi3mr_issue_ioc_shutdown(struct mpi3mr_ioc
*mrioc
)
4839 u32 ioc_config
, ioc_status
;
4841 u32 timeout
= MPI3MR_DEFAULT_SHUTDOWN_TIME
* 10;
4843 ioc_info(mrioc
, "Issuing shutdown Notification\n");
4844 if (mrioc
->unrecoverable
) {
4846 "IOC is unrecoverable shutdown is not issued\n");
4849 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
4850 if ((ioc_status
& MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK
)
4851 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS
) {
4852 ioc_info(mrioc
, "shutdown already in progress\n");
4856 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
4857 ioc_config
|= MPI3_SYSIF_IOC_CONFIG_SHUTDOWN_NORMAL
;
4858 ioc_config
|= MPI3_SYSIF_IOC_CONFIG_DEVICE_SHUTDOWN_SEND_REQ
;
4860 writel(ioc_config
, &mrioc
->sysif_regs
->ioc_configuration
);
4862 if (mrioc
->facts
.shutdown_timeout
)
4863 timeout
= mrioc
->facts
.shutdown_timeout
* 10;
4866 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
4867 if ((ioc_status
& MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK
)
4868 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_COMPLETE
) {
4873 } while (--timeout
);
4875 ioc_status
= readl(&mrioc
->sysif_regs
->ioc_status
);
4876 ioc_config
= readl(&mrioc
->sysif_regs
->ioc_configuration
);
4879 if ((ioc_status
& MPI3_SYSIF_IOC_STATUS_SHUTDOWN_MASK
)
4880 == MPI3_SYSIF_IOC_STATUS_SHUTDOWN_IN_PROGRESS
)
4882 "shutdown still in progress after timeout\n");
4886 "Base IOC Sts/Config after %s shutdown is (0x%x)/(0x%x)\n",
4887 (!retval
) ? "successful" : "failed", ioc_status
,
4892 * mpi3mr_cleanup_ioc - Cleanup controller
4893 * @mrioc: Adapter instance reference
4895 * controller cleanup handler, Message unit reset or soft reset
4896 * and shutdown notification is issued to the controller.
4900 void mpi3mr_cleanup_ioc(struct mpi3mr_ioc
*mrioc
)
4902 enum mpi3mr_iocstate ioc_state
;
4904 dprint_exit(mrioc
, "cleaning up the controller\n");
4905 mpi3mr_ioc_disable_intr(mrioc
);
4907 ioc_state
= mpi3mr_get_iocstate(mrioc
);
4909 if (!mrioc
->unrecoverable
&& !mrioc
->reset_in_progress
&&
4910 !mrioc
->pci_err_recovery
&&
4911 (ioc_state
== MRIOC_STATE_READY
)) {
4912 if (mpi3mr_issue_and_process_mur(mrioc
,
4913 MPI3MR_RESET_FROM_CTLR_CLEANUP
))
4914 mpi3mr_issue_reset(mrioc
,
4915 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET
,
4916 MPI3MR_RESET_FROM_MUR_FAILURE
);
4917 mpi3mr_issue_ioc_shutdown(mrioc
);
4919 dprint_exit(mrioc
, "controller cleanup completed\n");
4923 * mpi3mr_drv_cmd_comp_reset - Flush a internal driver command
4924 * @mrioc: Adapter instance reference
4925 * @cmdptr: Internal command tracker
4927 * Complete an internal driver commands with state indicating it
4928 * is completed due to reset.
4932 static inline void mpi3mr_drv_cmd_comp_reset(struct mpi3mr_ioc
*mrioc
,
4933 struct mpi3mr_drv_cmd
*cmdptr
)
4935 if (cmdptr
->state
& MPI3MR_CMD_PENDING
) {
4936 cmdptr
->state
|= MPI3MR_CMD_RESET
;
4937 cmdptr
->state
&= ~MPI3MR_CMD_PENDING
;
4938 if (cmdptr
->is_waiting
) {
4939 complete(&cmdptr
->done
);
4940 cmdptr
->is_waiting
= 0;
4941 } else if (cmdptr
->callback
)
4942 cmdptr
->callback(mrioc
, cmdptr
);
4947 * mpi3mr_flush_drv_cmds - Flush internaldriver commands
4948 * @mrioc: Adapter instance reference
4950 * Flush all internal driver commands post reset
4954 void mpi3mr_flush_drv_cmds(struct mpi3mr_ioc
*mrioc
)
4956 struct mpi3mr_drv_cmd
*cmdptr
;
4959 cmdptr
= &mrioc
->init_cmds
;
4960 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4962 cmdptr
= &mrioc
->cfg_cmds
;
4963 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4965 cmdptr
= &mrioc
->bsg_cmds
;
4966 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4967 cmdptr
= &mrioc
->host_tm_cmds
;
4968 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4970 for (i
= 0; i
< MPI3MR_NUM_DEVRMCMD
; i
++) {
4971 cmdptr
= &mrioc
->dev_rmhs_cmds
[i
];
4972 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4975 for (i
= 0; i
< MPI3MR_NUM_EVTACKCMD
; i
++) {
4976 cmdptr
= &mrioc
->evtack_cmds
[i
];
4977 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4980 cmdptr
= &mrioc
->pel_cmds
;
4981 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4983 cmdptr
= &mrioc
->pel_abort_cmd
;
4984 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4986 cmdptr
= &mrioc
->transport_cmds
;
4987 mpi3mr_drv_cmd_comp_reset(mrioc
, cmdptr
);
4991 * mpi3mr_pel_wait_post - Issue PEL Wait
4992 * @mrioc: Adapter instance reference
4993 * @drv_cmd: Internal command tracker
4995 * Issue PEL Wait MPI request through admin queue and return.
4999 static void mpi3mr_pel_wait_post(struct mpi3mr_ioc
*mrioc
,
5000 struct mpi3mr_drv_cmd
*drv_cmd
)
5002 struct mpi3_pel_req_action_wait pel_wait
;
5004 mrioc
->pel_abort_requested
= false;
5006 memset(&pel_wait
, 0, sizeof(pel_wait
));
5007 drv_cmd
->state
= MPI3MR_CMD_PENDING
;
5008 drv_cmd
->is_waiting
= 0;
5009 drv_cmd
->callback
= mpi3mr_pel_wait_complete
;
5010 drv_cmd
->ioc_status
= 0;
5011 drv_cmd
->ioc_loginfo
= 0;
5012 pel_wait
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT
);
5013 pel_wait
.function
= MPI3_FUNCTION_PERSISTENT_EVENT_LOG
;
5014 pel_wait
.action
= MPI3_PEL_ACTION_WAIT
;
5015 pel_wait
.starting_sequence_number
= cpu_to_le32(mrioc
->pel_newest_seqnum
);
5016 pel_wait
.locale
= cpu_to_le16(mrioc
->pel_locale
);
5017 pel_wait
.class = cpu_to_le16(mrioc
->pel_class
);
5018 pel_wait
.wait_time
= MPI3_PEL_WAITTIME_INFINITE_WAIT
;
5019 dprint_bsg_info(mrioc
, "sending pel_wait seqnum(%d), class(%d), locale(0x%08x)\n",
5020 mrioc
->pel_newest_seqnum
, mrioc
->pel_class
, mrioc
->pel_locale
);
5022 if (mpi3mr_admin_request_post(mrioc
, &pel_wait
, sizeof(pel_wait
), 0)) {
5023 dprint_bsg_err(mrioc
,
5024 "Issuing PELWait: Admin post failed\n");
5025 drv_cmd
->state
= MPI3MR_CMD_NOTUSED
;
5026 drv_cmd
->callback
= NULL
;
5027 drv_cmd
->retry_count
= 0;
5028 mrioc
->pel_enabled
= false;
5033 * mpi3mr_pel_get_seqnum_post - Issue PEL Get Sequence number
5034 * @mrioc: Adapter instance reference
5035 * @drv_cmd: Internal command tracker
5037 * Issue PEL get sequence number MPI request through admin queue
5040 * Return: 0 on success, non-zero on failure.
5042 int mpi3mr_pel_get_seqnum_post(struct mpi3mr_ioc
*mrioc
,
5043 struct mpi3mr_drv_cmd
*drv_cmd
)
5045 struct mpi3_pel_req_action_get_sequence_numbers pel_getseq_req
;
5046 u8 sgl_flags
= MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST
;
5049 memset(&pel_getseq_req
, 0, sizeof(pel_getseq_req
));
5050 mrioc
->pel_cmds
.state
= MPI3MR_CMD_PENDING
;
5051 mrioc
->pel_cmds
.is_waiting
= 0;
5052 mrioc
->pel_cmds
.ioc_status
= 0;
5053 mrioc
->pel_cmds
.ioc_loginfo
= 0;
5054 mrioc
->pel_cmds
.callback
= mpi3mr_pel_get_seqnum_complete
;
5055 pel_getseq_req
.host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_PEL_WAIT
);
5056 pel_getseq_req
.function
= MPI3_FUNCTION_PERSISTENT_EVENT_LOG
;
5057 pel_getseq_req
.action
= MPI3_PEL_ACTION_GET_SEQNUM
;
5058 mpi3mr_add_sg_single(&pel_getseq_req
.sgl
, sgl_flags
,
5059 mrioc
->pel_seqnum_sz
, mrioc
->pel_seqnum_dma
);
5061 retval
= mpi3mr_admin_request_post(mrioc
, &pel_getseq_req
,
5062 sizeof(pel_getseq_req
), 0);
5065 drv_cmd
->state
= MPI3MR_CMD_NOTUSED
;
5066 drv_cmd
->callback
= NULL
;
5067 drv_cmd
->retry_count
= 0;
5069 mrioc
->pel_enabled
= false;
5076 * mpi3mr_pel_wait_complete - PELWait Completion callback
5077 * @mrioc: Adapter instance reference
5078 * @drv_cmd: Internal command tracker
5080 * This is a callback handler for the PELWait request and
5081 * firmware completes a PELWait request when it is aborted or a
5082 * new PEL entry is available. This sends AEN to the application
5083 * and if the PELwait completion is not due to PELAbort then
5084 * this will send a request for new PEL Sequence number
5088 static void mpi3mr_pel_wait_complete(struct mpi3mr_ioc
*mrioc
,
5089 struct mpi3mr_drv_cmd
*drv_cmd
)
5091 struct mpi3_pel_reply
*pel_reply
= NULL
;
5092 u16 ioc_status
, pe_log_status
;
5093 bool do_retry
= false;
5095 if (drv_cmd
->state
& MPI3MR_CMD_RESET
)
5096 goto cleanup_drv_cmd
;
5098 ioc_status
= drv_cmd
->ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
;
5099 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5100 ioc_err(mrioc
, "%s: Failed ioc_status(0x%04x) Loginfo(0x%08x)\n",
5101 __func__
, ioc_status
, drv_cmd
->ioc_loginfo
);
5102 dprint_bsg_err(mrioc
,
5103 "pel_wait: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
5104 ioc_status
, drv_cmd
->ioc_loginfo
);
5108 if (drv_cmd
->state
& MPI3MR_CMD_REPLY_VALID
)
5109 pel_reply
= (struct mpi3_pel_reply
*)drv_cmd
->reply
;
5112 dprint_bsg_err(mrioc
,
5113 "pel_wait: failed due to no reply\n");
5117 pe_log_status
= le16_to_cpu(pel_reply
->pe_log_status
);
5118 if ((pe_log_status
!= MPI3_PEL_STATUS_SUCCESS
) &&
5119 (pe_log_status
!= MPI3_PEL_STATUS_ABORTED
)) {
5120 ioc_err(mrioc
, "%s: Failed pe_log_status(0x%04x)\n",
5121 __func__
, pe_log_status
);
5122 dprint_bsg_err(mrioc
,
5123 "pel_wait: failed due to pel_log_status(0x%04x)\n",
5129 if (drv_cmd
->retry_count
< MPI3MR_PEL_RETRY_COUNT
) {
5130 drv_cmd
->retry_count
++;
5131 dprint_bsg_err(mrioc
, "pel_wait: retrying(%d)\n",
5132 drv_cmd
->retry_count
);
5133 mpi3mr_pel_wait_post(mrioc
, drv_cmd
);
5136 dprint_bsg_err(mrioc
,
5137 "pel_wait: failed after all retries(%d)\n",
5138 drv_cmd
->retry_count
);
5141 atomic64_inc(&event_counter
);
5142 if (!mrioc
->pel_abort_requested
) {
5143 mrioc
->pel_cmds
.retry_count
= 0;
5144 mpi3mr_pel_get_seqnum_post(mrioc
, &mrioc
->pel_cmds
);
5149 mrioc
->pel_enabled
= false;
5151 drv_cmd
->state
= MPI3MR_CMD_NOTUSED
;
5152 drv_cmd
->callback
= NULL
;
5153 drv_cmd
->retry_count
= 0;
5157 * mpi3mr_pel_get_seqnum_complete - PELGetSeqNum Completion callback
5158 * @mrioc: Adapter instance reference
5159 * @drv_cmd: Internal command tracker
5161 * This is a callback handler for the PEL get sequence number
5162 * request and a new PEL wait request will be issued to the
5163 * firmware from this
5167 void mpi3mr_pel_get_seqnum_complete(struct mpi3mr_ioc
*mrioc
,
5168 struct mpi3mr_drv_cmd
*drv_cmd
)
5170 struct mpi3_pel_reply
*pel_reply
= NULL
;
5171 struct mpi3_pel_seq
*pel_seqnum_virt
;
5173 bool do_retry
= false;
5175 pel_seqnum_virt
= (struct mpi3_pel_seq
*)mrioc
->pel_seqnum_virt
;
5177 if (drv_cmd
->state
& MPI3MR_CMD_RESET
)
5178 goto cleanup_drv_cmd
;
5180 ioc_status
= drv_cmd
->ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
;
5181 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5182 dprint_bsg_err(mrioc
,
5183 "pel_get_seqnum: failed with ioc_status(0x%04x), log_info(0x%08x)\n",
5184 ioc_status
, drv_cmd
->ioc_loginfo
);
5188 if (drv_cmd
->state
& MPI3MR_CMD_REPLY_VALID
)
5189 pel_reply
= (struct mpi3_pel_reply
*)drv_cmd
->reply
;
5191 dprint_bsg_err(mrioc
,
5192 "pel_get_seqnum: failed due to no reply\n");
5196 if (le16_to_cpu(pel_reply
->pe_log_status
) != MPI3_PEL_STATUS_SUCCESS
) {
5197 dprint_bsg_err(mrioc
,
5198 "pel_get_seqnum: failed due to pel_log_status(0x%04x)\n",
5199 le16_to_cpu(pel_reply
->pe_log_status
));
5204 if (drv_cmd
->retry_count
< MPI3MR_PEL_RETRY_COUNT
) {
5205 drv_cmd
->retry_count
++;
5206 dprint_bsg_err(mrioc
,
5207 "pel_get_seqnum: retrying(%d)\n",
5208 drv_cmd
->retry_count
);
5209 mpi3mr_pel_get_seqnum_post(mrioc
, drv_cmd
);
5213 dprint_bsg_err(mrioc
,
5214 "pel_get_seqnum: failed after all retries(%d)\n",
5215 drv_cmd
->retry_count
);
5218 mrioc
->pel_newest_seqnum
= le32_to_cpu(pel_seqnum_virt
->newest
) + 1;
5219 drv_cmd
->retry_count
= 0;
5220 mpi3mr_pel_wait_post(mrioc
, drv_cmd
);
5224 mrioc
->pel_enabled
= false;
5226 drv_cmd
->state
= MPI3MR_CMD_NOTUSED
;
5227 drv_cmd
->callback
= NULL
;
5228 drv_cmd
->retry_count
= 0;
5232 * mpi3mr_soft_reset_handler - Reset the controller
5233 * @mrioc: Adapter instance reference
5234 * @reset_reason: Reset reason code
5235 * @snapdump: Flag to generate snapdump in firmware or not
5237 * This is an handler for recovering controller by issuing soft
5238 * reset are diag fault reset. This is a blocking function and
5239 * when one reset is executed if any other resets they will be
5240 * blocked. All BSG requests will be blocked during the reset. If
5241 * controller reset is successful then the controller will be
5242 * reinitalized, otherwise the controller will be marked as not
5245 * In snapdump bit is set, the controller is issued with diag
5246 * fault reset so that the firmware can create a snap dump and
5247 * post that the firmware will result in F000 fault and the
5248 * driver will issue soft reset to recover from that.
5250 * Return: 0 on success, non-zero on failure.
5252 int mpi3mr_soft_reset_handler(struct mpi3mr_ioc
*mrioc
,
5253 u16 reset_reason
, u8 snapdump
)
5256 unsigned long flags
;
5257 u32 host_diagnostic
, timeout
= MPI3_SYSIF_DIAG_SAVE_TIMEOUT
* 10;
5258 union mpi3mr_trigger_data trigger_data
;
5260 /* Block the reset handler until diag save in progress*/
5262 "soft_reset_handler: check and block on diagsave_timeout(%d)\n",
5263 mrioc
->diagsave_timeout
);
5264 while (mrioc
->diagsave_timeout
)
5267 * Block new resets until the currently executing one is finished and
5268 * return the status of the existing reset for all blocked resets
5270 dprint_reset(mrioc
, "soft_reset_handler: acquiring reset_mutex\n");
5271 if (!mutex_trylock(&mrioc
->reset_mutex
)) {
5273 "controller reset triggered by %s is blocked due to another reset in progress\n",
5274 mpi3mr_reset_rc_name(reset_reason
));
5277 } while (mrioc
->reset_in_progress
== 1);
5279 "returning previous reset result(%d) for the reset triggered by %s\n",
5280 mrioc
->prev_reset_result
,
5281 mpi3mr_reset_rc_name(reset_reason
));
5282 return mrioc
->prev_reset_result
;
5284 ioc_info(mrioc
, "controller reset is triggered by %s\n",
5285 mpi3mr_reset_rc_name(reset_reason
));
5287 mrioc
->device_refresh_on
= 0;
5288 mrioc
->reset_in_progress
= 1;
5289 mrioc
->stop_bsgs
= 1;
5290 mrioc
->prev_reset_result
= -1;
5291 memset(&trigger_data
, 0, sizeof(trigger_data
));
5293 if ((!snapdump
) && (reset_reason
!= MPI3MR_RESET_FROM_FAULT_WATCH
) &&
5294 (reset_reason
!= MPI3MR_RESET_FROM_FIRMWARE
) &&
5295 (reset_reason
!= MPI3MR_RESET_FROM_CIACTIV_FAULT
)) {
5296 mpi3mr_set_trigger_data_in_all_hdb(mrioc
,
5297 MPI3MR_HDB_TRIGGER_TYPE_SOFT_RESET
, NULL
, 0);
5299 "soft_reset_handler: releasing host diagnostic buffers\n");
5300 mpi3mr_release_diag_bufs(mrioc
, 0);
5301 for (i
= 0; i
< MPI3_EVENT_NOTIFY_EVENTMASK_WORDS
; i
++)
5302 mrioc
->event_masks
[i
] = -1;
5304 dprint_reset(mrioc
, "soft_reset_handler: masking events\n");
5305 mpi3mr_issue_event_notification(mrioc
);
5308 mpi3mr_wait_for_host_io(mrioc
, MPI3MR_RESET_HOST_IOWAIT_TIMEOUT
);
5310 mpi3mr_ioc_disable_intr(mrioc
);
5313 mpi3mr_set_diagsave(mrioc
);
5314 retval
= mpi3mr_issue_reset(mrioc
,
5315 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
, reset_reason
);
5317 trigger_data
.fault
= (readl(&mrioc
->sysif_regs
->fault
) &
5318 MPI3_SYSIF_FAULT_CODE_MASK
);
5321 readl(&mrioc
->sysif_regs
->host_diagnostic
);
5322 if (!(host_diagnostic
&
5323 MPI3_SYSIF_HOST_DIAG_SAVE_IN_PROGRESS
))
5326 } while (--timeout
);
5327 mpi3mr_set_trigger_data_in_all_hdb(mrioc
,
5328 MPI3MR_HDB_TRIGGER_TYPE_FAULT
, &trigger_data
, 0);
5332 retval
= mpi3mr_issue_reset(mrioc
,
5333 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_SOFT_RESET
, reset_reason
);
5335 ioc_err(mrioc
, "Failed to issue soft reset to the ioc\n");
5338 if (mrioc
->num_io_throttle_group
!=
5339 mrioc
->facts
.max_io_throttle_group
) {
5341 "max io throttle group doesn't match old(%d), new(%d)\n",
5342 mrioc
->num_io_throttle_group
,
5343 mrioc
->facts
.max_io_throttle_group
);
5348 mpi3mr_flush_delayed_cmd_lists(mrioc
);
5349 mpi3mr_flush_drv_cmds(mrioc
);
5350 bitmap_clear(mrioc
->devrem_bitmap
, 0, MPI3MR_NUM_DEVRMCMD
);
5351 bitmap_clear(mrioc
->removepend_bitmap
, 0,
5352 mrioc
->dev_handle_bitmap_bits
);
5353 bitmap_clear(mrioc
->evtack_cmds_bitmap
, 0, MPI3MR_NUM_EVTACKCMD
);
5354 mpi3mr_flush_host_io(mrioc
);
5355 mpi3mr_cleanup_fwevt_list(mrioc
);
5356 mpi3mr_invalidate_devhandles(mrioc
);
5357 mpi3mr_free_enclosure_list(mrioc
);
5359 if (mrioc
->prepare_for_reset
) {
5360 mrioc
->prepare_for_reset
= 0;
5361 mrioc
->prepare_for_reset_timeout_counter
= 0;
5363 mpi3mr_memset_buffers(mrioc
);
5364 mpi3mr_release_diag_bufs(mrioc
, 1);
5365 mrioc
->fw_release_trigger_active
= false;
5366 mrioc
->trace_release_trigger_active
= false;
5367 mrioc
->snapdump_trigger_active
= false;
5368 mpi3mr_set_trigger_data_in_all_hdb(mrioc
,
5369 MPI3MR_HDB_TRIGGER_TYPE_SOFT_RESET
, NULL
, 0);
5372 "soft_reset_handler: reinitializing the controller\n");
5373 retval
= mpi3mr_reinit_ioc(mrioc
, 0);
5375 pr_err(IOCNAME
"reinit after soft reset failed: reason %d\n",
5376 mrioc
->name
, reset_reason
);
5379 ssleep(MPI3MR_RESET_TOPOLOGY_SETTLE_TIME
);
5383 mrioc
->diagsave_timeout
= 0;
5384 mrioc
->reset_in_progress
= 0;
5385 mrioc
->pel_abort_requested
= 0;
5386 if (mrioc
->pel_enabled
) {
5387 mrioc
->pel_cmds
.retry_count
= 0;
5388 mpi3mr_pel_wait_post(mrioc
, &mrioc
->pel_cmds
);
5391 mrioc
->device_refresh_on
= 0;
5393 mrioc
->ts_update_counter
= 0;
5394 spin_lock_irqsave(&mrioc
->watchdog_lock
, flags
);
5395 if (mrioc
->watchdog_work_q
)
5396 queue_delayed_work(mrioc
->watchdog_work_q
,
5397 &mrioc
->watchdog_work
,
5398 msecs_to_jiffies(MPI3MR_WATCHDOG_INTERVAL
));
5399 spin_unlock_irqrestore(&mrioc
->watchdog_lock
, flags
);
5400 mrioc
->stop_bsgs
= 0;
5401 if (mrioc
->pel_enabled
)
5402 atomic64_inc(&event_counter
);
5404 mpi3mr_issue_reset(mrioc
,
5405 MPI3_SYSIF_HOST_DIAG_RESET_ACTION_DIAG_FAULT
, reset_reason
);
5406 mrioc
->device_refresh_on
= 0;
5407 mrioc
->unrecoverable
= 1;
5408 mrioc
->reset_in_progress
= 0;
5409 mrioc
->stop_bsgs
= 0;
5411 mpi3mr_flush_cmds_for_unrecovered_controller(mrioc
);
5413 mrioc
->prev_reset_result
= retval
;
5414 mutex_unlock(&mrioc
->reset_mutex
);
5415 ioc_info(mrioc
, "controller reset is %s\n",
5416 ((retval
== 0) ? "successful" : "failed"));
5421 * mpi3mr_post_cfg_req - Issue config requests and wait
5422 * @mrioc: Adapter instance reference
5423 * @cfg_req: Configuration request
5424 * @timeout: Timeout in seconds
5425 * @ioc_status: Pointer to return ioc status
5427 * A generic function for posting MPI3 configuration request to
5428 * the firmware. This blocks for the completion of request for
5429 * timeout seconds and if the request times out this function
5430 * faults the controller with proper reason code.
5432 * On successful completion of the request this function returns
5433 * appropriate ioc status from the firmware back to the caller.
5435 * Return: 0 on success, non-zero on failure.
5437 static int mpi3mr_post_cfg_req(struct mpi3mr_ioc
*mrioc
,
5438 struct mpi3_config_request
*cfg_req
, int timeout
, u16
*ioc_status
)
5442 mutex_lock(&mrioc
->cfg_cmds
.mutex
);
5443 if (mrioc
->cfg_cmds
.state
& MPI3MR_CMD_PENDING
) {
5445 ioc_err(mrioc
, "sending config request failed due to command in use\n");
5446 mutex_unlock(&mrioc
->cfg_cmds
.mutex
);
5449 mrioc
->cfg_cmds
.state
= MPI3MR_CMD_PENDING
;
5450 mrioc
->cfg_cmds
.is_waiting
= 1;
5451 mrioc
->cfg_cmds
.callback
= NULL
;
5452 mrioc
->cfg_cmds
.ioc_status
= 0;
5453 mrioc
->cfg_cmds
.ioc_loginfo
= 0;
5455 cfg_req
->host_tag
= cpu_to_le16(MPI3MR_HOSTTAG_CFG_CMDS
);
5456 cfg_req
->function
= MPI3_FUNCTION_CONFIG
;
5458 init_completion(&mrioc
->cfg_cmds
.done
);
5459 dprint_cfg_info(mrioc
, "posting config request\n");
5460 if (mrioc
->logging_level
& MPI3_DEBUG_CFG_INFO
)
5461 dprint_dump(cfg_req
, sizeof(struct mpi3_config_request
),
5463 retval
= mpi3mr_admin_request_post(mrioc
, cfg_req
, sizeof(*cfg_req
), 1);
5465 ioc_err(mrioc
, "posting config request failed\n");
5468 wait_for_completion_timeout(&mrioc
->cfg_cmds
.done
, (timeout
* HZ
));
5469 if (!(mrioc
->cfg_cmds
.state
& MPI3MR_CMD_COMPLETE
)) {
5470 mpi3mr_check_rh_fault_ioc(mrioc
,
5471 MPI3MR_RESET_FROM_CFG_REQ_TIMEOUT
);
5472 ioc_err(mrioc
, "config request timed out\n");
5476 *ioc_status
= mrioc
->cfg_cmds
.ioc_status
& MPI3_IOCSTATUS_STATUS_MASK
;
5477 if ((*ioc_status
) != MPI3_IOCSTATUS_SUCCESS
)
5478 dprint_cfg_err(mrioc
,
5479 "cfg_page request returned with ioc_status(0x%04x), log_info(0x%08x)\n",
5480 *ioc_status
, mrioc
->cfg_cmds
.ioc_loginfo
);
5483 mrioc
->cfg_cmds
.state
= MPI3MR_CMD_NOTUSED
;
5484 mutex_unlock(&mrioc
->cfg_cmds
.mutex
);
5491 * mpi3mr_process_cfg_req - config page request processor
5492 * @mrioc: Adapter instance reference
5493 * @cfg_req: Configuration request
5494 * @cfg_hdr: Configuration page header
5495 * @timeout: Timeout in seconds
5496 * @ioc_status: Pointer to return ioc status
5497 * @cfg_buf: Memory pointer to copy config page or header
5498 * @cfg_buf_sz: Size of the memory to get config page or header
5500 * This is handler for config page read, write and config page
5501 * header read operations.
5503 * This function expects the cfg_req to be populated with page
5504 * type, page number, action for the header read and with page
5505 * address for all other operations.
5507 * The cfg_hdr can be passed as null for reading required header
5508 * details for read/write pages the cfg_hdr should point valid
5509 * configuration page header.
5511 * This allocates dmaable memory based on the size of the config
5512 * buffer and set the SGE of the cfg_req.
5514 * For write actions, the config page data has to be passed in
5515 * the cfg_buf and size of the data has to be mentioned in the
5518 * For read/header actions, on successful completion of the
5519 * request with successful ioc_status the data will be copied
5520 * into the cfg_buf limited to a minimum of actual page size and
5524 * Return: 0 on success, non-zero on failure.
5526 static int mpi3mr_process_cfg_req(struct mpi3mr_ioc
*mrioc
,
5527 struct mpi3_config_request
*cfg_req
,
5528 struct mpi3_config_page_header
*cfg_hdr
, int timeout
, u16
*ioc_status
,
5529 void *cfg_buf
, u32 cfg_buf_sz
)
5531 struct dma_memory_desc mem_desc
;
5533 u8 invalid_action
= 0;
5534 u8 sgl_flags
= MPI3MR_SGEFLAGS_SYSTEM_SIMPLE_END_OF_LIST
;
5536 memset(&mem_desc
, 0, sizeof(struct dma_memory_desc
));
5538 if (cfg_req
->action
== MPI3_CONFIG_ACTION_PAGE_HEADER
)
5539 mem_desc
.size
= sizeof(struct mpi3_config_page_header
);
5542 ioc_err(mrioc
, "null config header passed for config action(%d), page_type(0x%02x), page_num(%d)\n",
5543 cfg_req
->action
, cfg_req
->page_type
,
5544 cfg_req
->page_number
);
5547 switch (cfg_hdr
->page_attribute
& MPI3_CONFIG_PAGEATTR_MASK
) {
5548 case MPI3_CONFIG_PAGEATTR_READ_ONLY
:
5550 != MPI3_CONFIG_ACTION_READ_CURRENT
)
5553 case MPI3_CONFIG_PAGEATTR_CHANGEABLE
:
5554 if ((cfg_req
->action
==
5555 MPI3_CONFIG_ACTION_READ_PERSISTENT
) ||
5557 MPI3_CONFIG_ACTION_WRITE_PERSISTENT
))
5560 case MPI3_CONFIG_PAGEATTR_PERSISTENT
:
5564 if (invalid_action
) {
5566 "config action(%d) is not allowed for page_type(0x%02x), page_num(%d) with page_attribute(0x%02x)\n",
5567 cfg_req
->action
, cfg_req
->page_type
,
5568 cfg_req
->page_number
, cfg_hdr
->page_attribute
);
5571 mem_desc
.size
= le16_to_cpu(cfg_hdr
->page_length
) * 4;
5572 cfg_req
->page_length
= cfg_hdr
->page_length
;
5573 cfg_req
->page_version
= cfg_hdr
->page_version
;
5576 mem_desc
.addr
= dma_alloc_coherent(&mrioc
->pdev
->dev
,
5577 mem_desc
.size
, &mem_desc
.dma_addr
, GFP_KERNEL
);
5582 mpi3mr_add_sg_single(&cfg_req
->sgl
, sgl_flags
, mem_desc
.size
,
5585 if ((cfg_req
->action
== MPI3_CONFIG_ACTION_WRITE_PERSISTENT
) ||
5586 (cfg_req
->action
== MPI3_CONFIG_ACTION_WRITE_CURRENT
)) {
5587 memcpy(mem_desc
.addr
, cfg_buf
, min_t(u16
, mem_desc
.size
,
5589 dprint_cfg_info(mrioc
, "config buffer to be written\n");
5590 if (mrioc
->logging_level
& MPI3_DEBUG_CFG_INFO
)
5591 dprint_dump(mem_desc
.addr
, mem_desc
.size
, "cfg_buf");
5594 if (mpi3mr_post_cfg_req(mrioc
, cfg_req
, timeout
, ioc_status
))
5598 if ((*ioc_status
== MPI3_IOCSTATUS_SUCCESS
) &&
5599 (cfg_req
->action
!= MPI3_CONFIG_ACTION_WRITE_PERSISTENT
) &&
5600 (cfg_req
->action
!= MPI3_CONFIG_ACTION_WRITE_CURRENT
)) {
5601 memcpy(cfg_buf
, mem_desc
.addr
, min_t(u16
, mem_desc
.size
,
5603 dprint_cfg_info(mrioc
, "config buffer read\n");
5604 if (mrioc
->logging_level
& MPI3_DEBUG_CFG_INFO
)
5605 dprint_dump(mem_desc
.addr
, mem_desc
.size
, "cfg_buf");
5609 if (mem_desc
.addr
) {
5610 dma_free_coherent(&mrioc
->pdev
->dev
, mem_desc
.size
,
5611 mem_desc
.addr
, mem_desc
.dma_addr
);
5612 mem_desc
.addr
= NULL
;
5619 * mpi3mr_cfg_get_dev_pg0 - Read current device page0
5620 * @mrioc: Adapter instance reference
5621 * @ioc_status: Pointer to return ioc status
5622 * @dev_pg0: Pointer to return device page 0
5623 * @pg_sz: Size of the memory allocated to the page pointer
5624 * @form: The form to be used for addressing the page
5625 * @form_spec: Form specific information like device handle
5627 * This is handler for config page read for a specific device
5628 * page0. The ioc_status has the controller returned ioc_status.
5629 * This routine doesn't check ioc_status to decide whether the
5630 * page read is success or not and it is the callers
5633 * Return: 0 on success, non-zero on failure.
5635 int mpi3mr_cfg_get_dev_pg0(struct mpi3mr_ioc
*mrioc
, u16
*ioc_status
,
5636 struct mpi3_device_page0
*dev_pg0
, u16 pg_sz
, u32 form
, u32 form_spec
)
5638 struct mpi3_config_page_header cfg_hdr
;
5639 struct mpi3_config_request cfg_req
;
5642 memset(dev_pg0
, 0, pg_sz
);
5643 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
5644 memset(&cfg_req
, 0, sizeof(cfg_req
));
5646 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
5647 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
5648 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_DEVICE
;
5649 cfg_req
.page_number
= 0;
5650 cfg_req
.page_address
= 0;
5652 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
5653 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
5654 ioc_err(mrioc
, "device page0 header read failed\n");
5657 if (*ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5658 ioc_err(mrioc
, "device page0 header read failed with ioc_status(0x%04x)\n",
5662 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
5663 page_address
= ((form
& MPI3_DEVICE_PGAD_FORM_MASK
) |
5664 (form_spec
& MPI3_DEVICE_PGAD_HANDLE_MASK
));
5665 cfg_req
.page_address
= cpu_to_le32(page_address
);
5666 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
5667 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, dev_pg0
, pg_sz
)) {
5668 ioc_err(mrioc
, "device page0 read failed\n");
5678 * mpi3mr_cfg_get_sas_phy_pg0 - Read current SAS Phy page0
5679 * @mrioc: Adapter instance reference
5680 * @ioc_status: Pointer to return ioc status
5681 * @phy_pg0: Pointer to return SAS Phy page 0
5682 * @pg_sz: Size of the memory allocated to the page pointer
5683 * @form: The form to be used for addressing the page
5684 * @form_spec: Form specific information like phy number
5686 * This is handler for config page read for a specific SAS Phy
5687 * page0. The ioc_status has the controller returned ioc_status.
5688 * This routine doesn't check ioc_status to decide whether the
5689 * page read is success or not and it is the callers
5692 * Return: 0 on success, non-zero on failure.
5694 int mpi3mr_cfg_get_sas_phy_pg0(struct mpi3mr_ioc
*mrioc
, u16
*ioc_status
,
5695 struct mpi3_sas_phy_page0
*phy_pg0
, u16 pg_sz
, u32 form
,
5698 struct mpi3_config_page_header cfg_hdr
;
5699 struct mpi3_config_request cfg_req
;
5702 memset(phy_pg0
, 0, pg_sz
);
5703 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
5704 memset(&cfg_req
, 0, sizeof(cfg_req
));
5706 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
5707 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
5708 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_SAS_PHY
;
5709 cfg_req
.page_number
= 0;
5710 cfg_req
.page_address
= 0;
5712 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
5713 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
5714 ioc_err(mrioc
, "sas phy page0 header read failed\n");
5717 if (*ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5718 ioc_err(mrioc
, "sas phy page0 header read failed with ioc_status(0x%04x)\n",
5722 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
5723 page_address
= ((form
& MPI3_SAS_PHY_PGAD_FORM_MASK
) |
5724 (form_spec
& MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK
));
5725 cfg_req
.page_address
= cpu_to_le32(page_address
);
5726 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
5727 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, phy_pg0
, pg_sz
)) {
5728 ioc_err(mrioc
, "sas phy page0 read failed\n");
5737 * mpi3mr_cfg_get_sas_phy_pg1 - Read current SAS Phy page1
5738 * @mrioc: Adapter instance reference
5739 * @ioc_status: Pointer to return ioc status
5740 * @phy_pg1: Pointer to return SAS Phy page 1
5741 * @pg_sz: Size of the memory allocated to the page pointer
5742 * @form: The form to be used for addressing the page
5743 * @form_spec: Form specific information like phy number
5745 * This is handler for config page read for a specific SAS Phy
5746 * page1. The ioc_status has the controller returned ioc_status.
5747 * This routine doesn't check ioc_status to decide whether the
5748 * page read is success or not and it is the callers
5751 * Return: 0 on success, non-zero on failure.
5753 int mpi3mr_cfg_get_sas_phy_pg1(struct mpi3mr_ioc
*mrioc
, u16
*ioc_status
,
5754 struct mpi3_sas_phy_page1
*phy_pg1
, u16 pg_sz
, u32 form
,
5757 struct mpi3_config_page_header cfg_hdr
;
5758 struct mpi3_config_request cfg_req
;
5761 memset(phy_pg1
, 0, pg_sz
);
5762 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
5763 memset(&cfg_req
, 0, sizeof(cfg_req
));
5765 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
5766 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
5767 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_SAS_PHY
;
5768 cfg_req
.page_number
= 1;
5769 cfg_req
.page_address
= 0;
5771 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
5772 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
5773 ioc_err(mrioc
, "sas phy page1 header read failed\n");
5776 if (*ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5777 ioc_err(mrioc
, "sas phy page1 header read failed with ioc_status(0x%04x)\n",
5781 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
5782 page_address
= ((form
& MPI3_SAS_PHY_PGAD_FORM_MASK
) |
5783 (form_spec
& MPI3_SAS_PHY_PGAD_PHY_NUMBER_MASK
));
5784 cfg_req
.page_address
= cpu_to_le32(page_address
);
5785 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
5786 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, phy_pg1
, pg_sz
)) {
5787 ioc_err(mrioc
, "sas phy page1 read failed\n");
5797 * mpi3mr_cfg_get_sas_exp_pg0 - Read current SAS Expander page0
5798 * @mrioc: Adapter instance reference
5799 * @ioc_status: Pointer to return ioc status
5800 * @exp_pg0: Pointer to return SAS Expander page 0
5801 * @pg_sz: Size of the memory allocated to the page pointer
5802 * @form: The form to be used for addressing the page
5803 * @form_spec: Form specific information like device handle
5805 * This is handler for config page read for a specific SAS
5806 * Expander page0. The ioc_status has the controller returned
5807 * ioc_status. This routine doesn't check ioc_status to decide
5808 * whether the page read is success or not and it is the callers
5811 * Return: 0 on success, non-zero on failure.
5813 int mpi3mr_cfg_get_sas_exp_pg0(struct mpi3mr_ioc
*mrioc
, u16
*ioc_status
,
5814 struct mpi3_sas_expander_page0
*exp_pg0
, u16 pg_sz
, u32 form
,
5817 struct mpi3_config_page_header cfg_hdr
;
5818 struct mpi3_config_request cfg_req
;
5821 memset(exp_pg0
, 0, pg_sz
);
5822 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
5823 memset(&cfg_req
, 0, sizeof(cfg_req
));
5825 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
5826 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
5827 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_SAS_EXPANDER
;
5828 cfg_req
.page_number
= 0;
5829 cfg_req
.page_address
= 0;
5831 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
5832 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
5833 ioc_err(mrioc
, "expander page0 header read failed\n");
5836 if (*ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5837 ioc_err(mrioc
, "expander page0 header read failed with ioc_status(0x%04x)\n",
5841 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
5842 page_address
= ((form
& MPI3_SAS_EXPAND_PGAD_FORM_MASK
) |
5843 (form_spec
& (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK
|
5844 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK
)));
5845 cfg_req
.page_address
= cpu_to_le32(page_address
);
5846 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
5847 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, exp_pg0
, pg_sz
)) {
5848 ioc_err(mrioc
, "expander page0 read failed\n");
5857 * mpi3mr_cfg_get_sas_exp_pg1 - Read current SAS Expander page1
5858 * @mrioc: Adapter instance reference
5859 * @ioc_status: Pointer to return ioc status
5860 * @exp_pg1: Pointer to return SAS Expander page 1
5861 * @pg_sz: Size of the memory allocated to the page pointer
5862 * @form: The form to be used for addressing the page
5863 * @form_spec: Form specific information like phy number
5865 * This is handler for config page read for a specific SAS
5866 * Expander page1. The ioc_status has the controller returned
5867 * ioc_status. This routine doesn't check ioc_status to decide
5868 * whether the page read is success or not and it is the callers
5871 * Return: 0 on success, non-zero on failure.
5873 int mpi3mr_cfg_get_sas_exp_pg1(struct mpi3mr_ioc
*mrioc
, u16
*ioc_status
,
5874 struct mpi3_sas_expander_page1
*exp_pg1
, u16 pg_sz
, u32 form
,
5877 struct mpi3_config_page_header cfg_hdr
;
5878 struct mpi3_config_request cfg_req
;
5881 memset(exp_pg1
, 0, pg_sz
);
5882 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
5883 memset(&cfg_req
, 0, sizeof(cfg_req
));
5885 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
5886 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
5887 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_SAS_EXPANDER
;
5888 cfg_req
.page_number
= 1;
5889 cfg_req
.page_address
= 0;
5891 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
5892 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
5893 ioc_err(mrioc
, "expander page1 header read failed\n");
5896 if (*ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5897 ioc_err(mrioc
, "expander page1 header read failed with ioc_status(0x%04x)\n",
5901 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
5902 page_address
= ((form
& MPI3_SAS_EXPAND_PGAD_FORM_MASK
) |
5903 (form_spec
& (MPI3_SAS_EXPAND_PGAD_PHYNUM_MASK
|
5904 MPI3_SAS_EXPAND_PGAD_HANDLE_MASK
)));
5905 cfg_req
.page_address
= cpu_to_le32(page_address
);
5906 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
5907 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, exp_pg1
, pg_sz
)) {
5908 ioc_err(mrioc
, "expander page1 read failed\n");
5917 * mpi3mr_cfg_get_enclosure_pg0 - Read current Enclosure page0
5918 * @mrioc: Adapter instance reference
5919 * @ioc_status: Pointer to return ioc status
5920 * @encl_pg0: Pointer to return Enclosure page 0
5921 * @pg_sz: Size of the memory allocated to the page pointer
5922 * @form: The form to be used for addressing the page
5923 * @form_spec: Form specific information like device handle
5925 * This is handler for config page read for a specific Enclosure
5926 * page0. The ioc_status has the controller returned ioc_status.
5927 * This routine doesn't check ioc_status to decide whether the
5928 * page read is success or not and it is the callers
5931 * Return: 0 on success, non-zero on failure.
5933 int mpi3mr_cfg_get_enclosure_pg0(struct mpi3mr_ioc
*mrioc
, u16
*ioc_status
,
5934 struct mpi3_enclosure_page0
*encl_pg0
, u16 pg_sz
, u32 form
,
5937 struct mpi3_config_page_header cfg_hdr
;
5938 struct mpi3_config_request cfg_req
;
5941 memset(encl_pg0
, 0, pg_sz
);
5942 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
5943 memset(&cfg_req
, 0, sizeof(cfg_req
));
5945 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
5946 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
5947 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_ENCLOSURE
;
5948 cfg_req
.page_number
= 0;
5949 cfg_req
.page_address
= 0;
5951 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
5952 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
5953 ioc_err(mrioc
, "enclosure page0 header read failed\n");
5956 if (*ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
5957 ioc_err(mrioc
, "enclosure page0 header read failed with ioc_status(0x%04x)\n",
5961 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
5962 page_address
= ((form
& MPI3_ENCLOS_PGAD_FORM_MASK
) |
5963 (form_spec
& MPI3_ENCLOS_PGAD_HANDLE_MASK
));
5964 cfg_req
.page_address
= cpu_to_le32(page_address
);
5965 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
5966 MPI3MR_INTADMCMD_TIMEOUT
, ioc_status
, encl_pg0
, pg_sz
)) {
5967 ioc_err(mrioc
, "enclosure page0 read failed\n");
5977 * mpi3mr_cfg_get_sas_io_unit_pg0 - Read current SASIOUnit page0
5978 * @mrioc: Adapter instance reference
5979 * @sas_io_unit_pg0: Pointer to return SAS IO Unit page 0
5980 * @pg_sz: Size of the memory allocated to the page pointer
5982 * This is handler for config page read for the SAS IO Unit
5983 * page0. This routine checks ioc_status to decide whether the
5984 * page read is success or not.
5986 * Return: 0 on success, non-zero on failure.
5988 int mpi3mr_cfg_get_sas_io_unit_pg0(struct mpi3mr_ioc
*mrioc
,
5989 struct mpi3_sas_io_unit_page0
*sas_io_unit_pg0
, u16 pg_sz
)
5991 struct mpi3_config_page_header cfg_hdr
;
5992 struct mpi3_config_request cfg_req
;
5995 memset(sas_io_unit_pg0
, 0, pg_sz
);
5996 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
5997 memset(&cfg_req
, 0, sizeof(cfg_req
));
5999 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
6000 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
6001 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT
;
6002 cfg_req
.page_number
= 0;
6003 cfg_req
.page_address
= 0;
6005 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
6006 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
6007 ioc_err(mrioc
, "sas io unit page0 header read failed\n");
6010 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6011 ioc_err(mrioc
, "sas io unit page0 header read failed with ioc_status(0x%04x)\n",
6015 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
6017 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
6018 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, sas_io_unit_pg0
, pg_sz
)) {
6019 ioc_err(mrioc
, "sas io unit page0 read failed\n");
6022 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6023 ioc_err(mrioc
, "sas io unit page0 read failed with ioc_status(0x%04x)\n",
6033 * mpi3mr_cfg_get_sas_io_unit_pg1 - Read current SASIOUnit page1
6034 * @mrioc: Adapter instance reference
6035 * @sas_io_unit_pg1: Pointer to return SAS IO Unit page 1
6036 * @pg_sz: Size of the memory allocated to the page pointer
6038 * This is handler for config page read for the SAS IO Unit
6039 * page1. This routine checks ioc_status to decide whether the
6040 * page read is success or not.
6042 * Return: 0 on success, non-zero on failure.
6044 int mpi3mr_cfg_get_sas_io_unit_pg1(struct mpi3mr_ioc
*mrioc
,
6045 struct mpi3_sas_io_unit_page1
*sas_io_unit_pg1
, u16 pg_sz
)
6047 struct mpi3_config_page_header cfg_hdr
;
6048 struct mpi3_config_request cfg_req
;
6051 memset(sas_io_unit_pg1
, 0, pg_sz
);
6052 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
6053 memset(&cfg_req
, 0, sizeof(cfg_req
));
6055 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
6056 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
6057 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT
;
6058 cfg_req
.page_number
= 1;
6059 cfg_req
.page_address
= 0;
6061 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
6062 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
6063 ioc_err(mrioc
, "sas io unit page1 header read failed\n");
6066 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6067 ioc_err(mrioc
, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
6071 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
6073 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
6074 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, sas_io_unit_pg1
, pg_sz
)) {
6075 ioc_err(mrioc
, "sas io unit page1 read failed\n");
6078 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6079 ioc_err(mrioc
, "sas io unit page1 read failed with ioc_status(0x%04x)\n",
6089 * mpi3mr_cfg_set_sas_io_unit_pg1 - Write SASIOUnit page1
6090 * @mrioc: Adapter instance reference
6091 * @sas_io_unit_pg1: Pointer to the SAS IO Unit page 1 to write
6092 * @pg_sz: Size of the memory allocated to the page pointer
6094 * This is handler for config page write for the SAS IO Unit
6095 * page1. This routine checks ioc_status to decide whether the
6096 * page read is success or not. This will modify both current
6097 * and persistent page.
6099 * Return: 0 on success, non-zero on failure.
6101 int mpi3mr_cfg_set_sas_io_unit_pg1(struct mpi3mr_ioc
*mrioc
,
6102 struct mpi3_sas_io_unit_page1
*sas_io_unit_pg1
, u16 pg_sz
)
6104 struct mpi3_config_page_header cfg_hdr
;
6105 struct mpi3_config_request cfg_req
;
6108 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
6109 memset(&cfg_req
, 0, sizeof(cfg_req
));
6111 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
6112 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
6113 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_SAS_IO_UNIT
;
6114 cfg_req
.page_number
= 1;
6115 cfg_req
.page_address
= 0;
6117 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
6118 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
6119 ioc_err(mrioc
, "sas io unit page1 header read failed\n");
6122 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6123 ioc_err(mrioc
, "sas io unit page1 header read failed with ioc_status(0x%04x)\n",
6127 cfg_req
.action
= MPI3_CONFIG_ACTION_WRITE_CURRENT
;
6129 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
6130 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, sas_io_unit_pg1
, pg_sz
)) {
6131 ioc_err(mrioc
, "sas io unit page1 write current failed\n");
6134 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6135 ioc_err(mrioc
, "sas io unit page1 write current failed with ioc_status(0x%04x)\n",
6140 cfg_req
.action
= MPI3_CONFIG_ACTION_WRITE_PERSISTENT
;
6142 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
6143 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, sas_io_unit_pg1
, pg_sz
)) {
6144 ioc_err(mrioc
, "sas io unit page1 write persistent failed\n");
6147 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6148 ioc_err(mrioc
, "sas io unit page1 write persistent failed with ioc_status(0x%04x)\n",
6158 * mpi3mr_cfg_get_driver_pg1 - Read current Driver page1
6159 * @mrioc: Adapter instance reference
6160 * @driver_pg1: Pointer to return Driver page 1
6161 * @pg_sz: Size of the memory allocated to the page pointer
6163 * This is handler for config page read for the Driver page1.
6164 * This routine checks ioc_status to decide whether the page
6165 * read is success or not.
6167 * Return: 0 on success, non-zero on failure.
6169 int mpi3mr_cfg_get_driver_pg1(struct mpi3mr_ioc
*mrioc
,
6170 struct mpi3_driver_page1
*driver_pg1
, u16 pg_sz
)
6172 struct mpi3_config_page_header cfg_hdr
;
6173 struct mpi3_config_request cfg_req
;
6176 memset(driver_pg1
, 0, pg_sz
);
6177 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
6178 memset(&cfg_req
, 0, sizeof(cfg_req
));
6180 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
6181 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
6182 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_DRIVER
;
6183 cfg_req
.page_number
= 1;
6184 cfg_req
.page_address
= 0;
6186 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
6187 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
6188 ioc_err(mrioc
, "driver page1 header read failed\n");
6191 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6192 ioc_err(mrioc
, "driver page1 header read failed with ioc_status(0x%04x)\n",
6196 cfg_req
.action
= MPI3_CONFIG_ACTION_READ_CURRENT
;
6198 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
6199 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, driver_pg1
, pg_sz
)) {
6200 ioc_err(mrioc
, "driver page1 read failed\n");
6203 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6204 ioc_err(mrioc
, "driver page1 read failed with ioc_status(0x%04x)\n",
6214 * mpi3mr_cfg_get_driver_pg2 - Read current driver page2
6215 * @mrioc: Adapter instance reference
6216 * @driver_pg2: Pointer to return driver page 2
6217 * @pg_sz: Size of the memory allocated to the page pointer
6218 * @page_action: Page action
6220 * This is handler for config page read for the driver page2.
6221 * This routine checks ioc_status to decide whether the page
6222 * read is success or not.
6224 * Return: 0 on success, non-zero on failure.
6226 int mpi3mr_cfg_get_driver_pg2(struct mpi3mr_ioc
*mrioc
,
6227 struct mpi3_driver_page2
*driver_pg2
, u16 pg_sz
, u8 page_action
)
6229 struct mpi3_config_page_header cfg_hdr
;
6230 struct mpi3_config_request cfg_req
;
6233 memset(driver_pg2
, 0, pg_sz
);
6234 memset(&cfg_hdr
, 0, sizeof(cfg_hdr
));
6235 memset(&cfg_req
, 0, sizeof(cfg_req
));
6237 cfg_req
.function
= MPI3_FUNCTION_CONFIG
;
6238 cfg_req
.action
= MPI3_CONFIG_ACTION_PAGE_HEADER
;
6239 cfg_req
.page_type
= MPI3_CONFIG_PAGETYPE_DRIVER
;
6240 cfg_req
.page_number
= 2;
6241 cfg_req
.page_address
= 0;
6242 cfg_req
.page_version
= MPI3_DRIVER2_PAGEVERSION
;
6244 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, NULL
,
6245 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, &cfg_hdr
, sizeof(cfg_hdr
))) {
6246 ioc_err(mrioc
, "driver page2 header read failed\n");
6249 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6250 ioc_err(mrioc
, "driver page2 header read failed with\n"
6251 "ioc_status(0x%04x)\n",
6255 cfg_req
.action
= page_action
;
6257 if (mpi3mr_process_cfg_req(mrioc
, &cfg_req
, &cfg_hdr
,
6258 MPI3MR_INTADMCMD_TIMEOUT
, &ioc_status
, driver_pg2
, pg_sz
)) {
6259 ioc_err(mrioc
, "driver page2 read failed\n");
6262 if (ioc_status
!= MPI3_IOCSTATUS_SUCCESS
) {
6263 ioc_err(mrioc
, "driver page2 read failed with\n"
6264 "ioc_status(0x%04x)\n",